Skip to content

Commit

Permalink
EA-198: Add support for configuring (and fetching) Mother Child relat…
Browse files Browse the repository at this point in the history
…ionships within the EMR API module
  • Loading branch information
mogoodrich committed Aug 9, 2024
1 parent 81bf287 commit 2e23aea
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -216,5 +216,5 @@ public class EmrApiConstants {

public static final String GP_USE_LEGACY_DIAGNOSIS_SERVICE = "emrapi.useLegacyDiagnosisService";

public static final String METADATA_MAPPING_MOTHER_CHILD_RELATIONSHIP_TYPE = "emrapi.motherChildRelationshipType";
public static final String METADATA_MAPPING_MOTHER_CHILD_RELATIONSHIP_TYPE = "emr.motherChildRelationshipType";
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ public List<MotherAndChild> getMothersAndChildren(MothersAndChildrenSearchCriter

Map<String, Object> parameters = new HashMap<>();
parameters.put("motherUuids", criteria.getMotherUuids());
parameters.put("restrictByMothers", criteria.getMotherUuids() != null);
parameters.put("childUuids", criteria.getChildUuids());
parameters.put("restrictByChildren", criteria.getChildUuids() != null);
parameters.put("motherChildRelationshipType", motherChildRelationshipType);
parameters.put("motherRequiredToHaveActiveVisit", criteria.isMotherRequiredToHaveActiveVisit());
parameters.put("childRequiredToHaveActiveVisit", criteria.isChildRequiredToHaveActiveVisit());
Expand Down
4 changes: 2 additions & 2 deletions api/src/main/resources/hql/mother_child.hql
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ from
inner join motherChildRelationship.personA as mother
inner join motherChildRelationship.personB as child
where
((:motherUuids) is null or mother.uuid in (:motherUuids))
and ((:childUuids) is null or child.uuid in (:childUuids))
(:restrictByMothers = false or mother.uuid in (:motherUuids))
and (:restrictByChildren = false or child.uuid in (:childUuids))
and motherChildRelationship.relationshipType = :motherChildRelationshipType
and (:motherRequiredToHaveActiveVisit = false or (select count(motherVisit) from Visit as motherVisit where motherVisit.patient = mother and motherVisit.stopDatetime is null and motherVisit.voided = false) > 0)
and (:childRequiredToHaveActiveVisit = false or (select count(childVisit) from Visit as childVisit where childVisit.patient = child and childVisit.stopDatetime is null and childVisit.voided = false) > 0)
Expand Down
2 changes: 1 addition & 1 deletion api/src/test/resources/baseTestDataset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@
<relationship_type relationship_type_id="1001" a_is_to_b="Mother" b_is_to_a="Child" preferred="0" weight="0" description="mother and child" creator="1" date_created="2008-08-15 15:55:18.0" retired="false" uuid="39f1bd38-2056-434c-874a-368b13c7265f"/>
<metadatamapping_metadata_term_mapping metadata_term_mapping_id = "4001" metadata_source_id = "2134"
creator = "1" date_created="2008-08-18 12:38:58.0" uuid="7126c900-85dc-4756-98a2-1f0595824600"
retired = "false" code = "emrapi.motherChildRelationshipType" name = "emr.motherChildRelationshipType"
retired = "false" code = "emr.motherChildRelationshipType" name = "emr.motherChildRelationshipType"
metadata_uuid = "39f1bd38-2056-434c-874a-368b13c7265f" metadata_class = "org.openmrs.RelationshipType"/>

</dataset>
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package org.openmrs.module.emrapi.web.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import java.util.Arrays;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.openmrs.module.emrapi.maternal.MaternalService;
import org.openmrs.module.emrapi.maternal.MotherAndChild;
import org.openmrs.module.emrapi.maternal.MothersAndChildrenSearchCriteria;
import org.openmrs.module.emrapi.rest.converter.SimpleBeanConverter;
import org.openmrs.module.webservices.rest.SimpleObject;
import org.openmrs.module.webservices.rest.web.RequestContext;
import org.openmrs.module.webservices.rest.web.RestUtil;
import org.openmrs.module.webservices.rest.web.representation.Representation;
import org.openmrs.module.webservices.rest.web.resource.impl.NeedsPaging;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class MothersAndChildrenController {

@Autowired
private MaternalService maternalService;

@RequestMapping(method = RequestMethod.GET, value = "/rest/**/emrapi/maternal/mothersAndChildren")
@ResponseBody
public SimpleObject getMothersAndChildren(
HttpServletRequest request,
HttpServletResponse response,
@RequestParam(required = false, value = "motherUuids") String motherUuids,
@RequestParam(required = false, value = "childUuids") String childUuids,
@RequestParam(required = false, value = "requireMotherHasActiveVisit") boolean requireMotherHasActiveVisit,
@RequestParam(required = false, value = "requireChildHasActiveVisit") boolean requireChildHasActiveVisit,
@RequestParam(required = false, value = "requireChildBornDuringMothersActiveVisit") boolean requireChildBornDuringMothersActiveVisit
) {
RequestContext context = RestUtil.getRequestContext(request, response, Representation.DEFAULT);
MothersAndChildrenSearchCriteria criteria = new MothersAndChildrenSearchCriteria();
criteria.setMotherUuids(StringUtils.isNotBlank(motherUuids) ? Arrays.asList(motherUuids.split(",")) : null);
criteria.setChildUuids(StringUtils.isNotBlank(childUuids) ? Arrays.asList(childUuids.split(",")) : null);
criteria.setMotherRequiredToHaveActiveVisit(requireMotherHasActiveVisit);
criteria.setChildRequiredToHaveActiveVisit(requireChildHasActiveVisit);
criteria.setChildRequiredToBeBornDuringMothersActiveVisit(requireChildBornDuringMothersActiveVisit);
List<MotherAndChild> motherAndChildList = maternalService.getMothersAndChildren(criteria);
return new NeedsPaging<>(motherAndChildList, context).toSimpleObject(new SimpleBeanConverter<MotherAndChild>());
}

}

0 comments on commit 2e23aea

Please sign in to comment.