From 81bf287ee842b33a1e52bb152a9de3d71fde5cca Mon Sep 17 00:00:00 2001 From: Mark Goodrich Date: Fri, 9 Aug 2024 12:38:56 -0400 Subject: [PATCH] =?UTF-8?q?EA-198-2:=20Add=20support=20for=20configuring?= =?UTF-8?q?=20(and=20fetching)=20Mother=20Child=20rel=E2=80=A6=20(#238)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../openmrs/module/emrapi/maternal/Child.java | 12 -- .../ChildrenByMothersSearchCriteria.java | 20 -- .../emrapi/maternal/MaternalService.java | 13 +- .../emrapi/maternal/MaternalServiceImpl.java | 72 ++----- .../{Mother.java => MotherAndChild.java} | 3 +- .../MothersAndChildrenSearchCriteria.java | 19 ++ .../MothersByChildrenSearchCriteria.java | 19 -- api/src/main/resources/hql/mother_child.hql | 6 +- .../maternal/MaternalServiceImplTest.java | 186 +++++++++--------- 9 files changed, 138 insertions(+), 212 deletions(-) delete mode 100644 api/src/main/java/org/openmrs/module/emrapi/maternal/Child.java delete mode 100644 api/src/main/java/org/openmrs/module/emrapi/maternal/ChildrenByMothersSearchCriteria.java rename api/src/main/java/org/openmrs/module/emrapi/maternal/{Mother.java => MotherAndChild.java} (77%) create mode 100644 api/src/main/java/org/openmrs/module/emrapi/maternal/MothersAndChildrenSearchCriteria.java delete mode 100644 api/src/main/java/org/openmrs/module/emrapi/maternal/MothersByChildrenSearchCriteria.java diff --git a/api/src/main/java/org/openmrs/module/emrapi/maternal/Child.java b/api/src/main/java/org/openmrs/module/emrapi/maternal/Child.java deleted file mode 100644 index 5ae0f25f..00000000 --- a/api/src/main/java/org/openmrs/module/emrapi/maternal/Child.java +++ /dev/null @@ -1,12 +0,0 @@ -package org.openmrs.module.emrapi.maternal; - -import lombok.Data; -import org.openmrs.Patient; -import org.openmrs.module.emrapi.adt.InpatientAdmission; - -@Data -public class Child { - private Patient child; - private Patient mother; - private InpatientAdmission childAdmission; -} diff --git a/api/src/main/java/org/openmrs/module/emrapi/maternal/ChildrenByMothersSearchCriteria.java b/api/src/main/java/org/openmrs/module/emrapi/maternal/ChildrenByMothersSearchCriteria.java deleted file mode 100644 index fb746430..00000000 --- a/api/src/main/java/org/openmrs/module/emrapi/maternal/ChildrenByMothersSearchCriteria.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.openmrs.module.emrapi.maternal; - -import java.util.List; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.experimental.Accessors; - -@Data -@NoArgsConstructor -@AllArgsConstructor -public class ChildrenByMothersSearchCriteria { - private List motherUuids; // restrict to children of these mothers - @Accessors(fluent = true) private boolean requireMotherHasActiveVisit = false; // restrict to children of mothers who have an active visit - @Accessors(fluent = true) private boolean requireChildHasActiveVisit = false; // restrict to children who have an active visit - @Accessors(fluent = true) private boolean requireChildBornDuringMothersActiveVisit = false; // restrict to children who were born during their mother's active visit -} - - diff --git a/api/src/main/java/org/openmrs/module/emrapi/maternal/MaternalService.java b/api/src/main/java/org/openmrs/module/emrapi/maternal/MaternalService.java index 92f90826..af2edf95 100644 --- a/api/src/main/java/org/openmrs/module/emrapi/maternal/MaternalService.java +++ b/api/src/main/java/org/openmrs/module/emrapi/maternal/MaternalService.java @@ -7,16 +7,11 @@ public interface MaternalService extends OpenmrsService { /** - * Fetches patients who are "children" (personB) of a Mother-Child relationship + * Fetches patients in a "Mother-to-Child" relationship, based on the given search criteria. + * * @param criteria search criteria (see class for details) - * @return a list of children, with their linked mothers (note this returns a "Child" per mother-child pair, so a child with multiple mothers will appear multiple times) + * @return a list of mothers and children that match the search criteria */ - List getChildrenByMothers(ChildrenByMothersSearchCriteria criteria); + List getMothersAndChildren(MothersAndChildrenSearchCriteria criteria); - /** - * Fetches patients who are "mothers" (personA) of a Mother-Child relationship - * @param criteria search criteria (see class for details) - * @return a list of mothers, with their linked children (note this returns a "Mother" per mother-child pair, so a mother with multiple children will appear multiple times) - */ - List getMothersByChildren(MothersByChildrenSearchCriteria criteria); } diff --git a/api/src/main/java/org/openmrs/module/emrapi/maternal/MaternalServiceImpl.java b/api/src/main/java/org/openmrs/module/emrapi/maternal/MaternalServiceImpl.java index 18003453..9d01c649 100644 --- a/api/src/main/java/org/openmrs/module/emrapi/maternal/MaternalServiceImpl.java +++ b/api/src/main/java/org/openmrs/module/emrapi/maternal/MaternalServiceImpl.java @@ -4,6 +4,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.stream.Collectors; import org.openmrs.Patient; @@ -36,7 +37,7 @@ public void setAdtService(AdtService adtService) { this.adtService = adtService; } - public List getChildrenByMothers(ChildrenByMothersSearchCriteria criteria) { + public List getMothersAndChildren(MothersAndChildrenSearchCriteria criteria) { RelationshipType motherChildRelationshipType = emrApiProperties.getMotherChildRelationshipType(); @@ -46,79 +47,40 @@ public List getChildrenByMothers(ChildrenByMothersSearchCriteria criteria Map parameters = new HashMap<>(); parameters.put("motherUuids", criteria.getMotherUuids()); - parameters.put("childUuids", null); + parameters.put("childUuids", criteria.getChildUuids()); parameters.put("motherChildRelationshipType", motherChildRelationshipType); - parameters.put("requireMotherHasActiveVisit", criteria.requireMotherHasActiveVisit()); - parameters.put("requireChildHasActiveVisit", criteria.requireChildHasActiveVisit()); - parameters.put("requireChildBornDuringMothersActiveVisit", criteria.requireChildBornDuringMothersActiveVisit()); + parameters.put("motherRequiredToHaveActiveVisit", criteria.isMotherRequiredToHaveActiveVisit()); + parameters.put("childRequiredToHaveActiveVisit", criteria.isChildRequiredToHaveActiveVisit()); + parameters.put("childRequiredToBeBornDuringMothersActiveVisit", criteria.isChildRequiredToBeBornDuringMothersActiveVisit()); List l = emrApiDAO.executeHqlFromResource("hql/mother_child.hql", parameters, List.class); - List ret = new ArrayList<>(); + List ret = new ArrayList<>(); for (Object req : l) { Object[] row = (Object[]) req; - Child child = new Child(); - child.setMother((Patient) row[0]); - child.setChild((Patient) row[1]); - ret.add(child); + MotherAndChild mothreAndChild = new MotherAndChild(); + mothreAndChild.setMother((Patient) row[0]); + mothreAndChild.setChild((Patient) row[1]); + ret.add(mothreAndChild); } // now fetch all the admissions for children in the result set InpatientAdmissionSearchCriteria inpatientAdmissionSearchCriteria = new InpatientAdmissionSearchCriteria(); - inpatientAdmissionSearchCriteria.setPatientIds(new ArrayList<>(ret.stream().map(Child::getChild).map(Patient::getId).collect(Collectors.toSet()))); + Set patientIds = ret.stream().map(MotherAndChild::getChild).map(Patient::getId).collect(Collectors.toSet()); + patientIds.addAll(ret.stream().map(MotherAndChild::getMother).map(Patient::getId).collect(Collectors.toSet())); + inpatientAdmissionSearchCriteria.setPatientIds(new ArrayList<>(patientIds)); List admissions = adtService.getInpatientAdmissions(inpatientAdmissionSearchCriteria); Map admissionsByPatient = new HashMap<>(); for (InpatientAdmission admission : admissions) { admissionsByPatient.put(admission.getVisit().getPatient(), admission); } - for (Child child : ret) { - child.setChildAdmission(admissionsByPatient.get(child.getChild())); + for (MotherAndChild motherAndChild : ret) { + motherAndChild.setMotherAdmission(admissionsByPatient.get(motherAndChild.getMother())); + motherAndChild.setChildAdmission(admissionsByPatient.get(motherAndChild.getChild())); } return ret; } - public List getMothersByChildren(MothersByChildrenSearchCriteria criteria) { - RelationshipType motherChildRelationshipType = emrApiProperties.getMotherChildRelationshipType(); - - if (motherChildRelationshipType == null) { - throw new APIException("Mother-Child relationship type has not been configured"); - } - - Map parameters = new HashMap<>(); - parameters.put("motherUuids", null); - parameters.put("childUuids", criteria.getChildUuids()); - parameters.put("motherChildRelationshipType", motherChildRelationshipType); - parameters.put("requireMotherHasActiveVisit", criteria.requireMotherHasActiveVisit()); - parameters.put("requireChildHasActiveVisit", criteria.requireChildHasActiveVisit()); - parameters.put("requireChildBornDuringMothersActiveVisit", criteria.requireChildBornDuringMothersActiveVisit()); - - List l = emrApiDAO.executeHqlFromResource("hql/mother_child.hql", parameters, List.class); - - List ret = new ArrayList<>(); - - for (Object req : l) { - Object[] row = (Object[]) req; - Mother mother = new Mother(); - mother.setMother((Patient) row[0]); - mother.setChild((Patient) row[1]); - ret.add(mother); - } - - // now fetch all the admissions for mothers in the result set - InpatientAdmissionSearchCriteria inpatientAdmissionSearchCriteria = new InpatientAdmissionSearchCriteria(); - inpatientAdmissionSearchCriteria.setPatientIds(new ArrayList<>(ret.stream().map(Mother::getMother).map(Patient::getId).collect(Collectors.toSet()))); - List admissions = adtService.getInpatientAdmissions(inpatientAdmissionSearchCriteria); - Map admissionsByPatient = new HashMap<>(); - for (InpatientAdmission admission : admissions) { - admissionsByPatient.put(admission.getVisit().getPatient(), admission); - } - for (Mother mother : ret) { - mother.setMotherAdmission(admissionsByPatient.get(mother.getMother())); - } - - - return ret; - } } diff --git a/api/src/main/java/org/openmrs/module/emrapi/maternal/Mother.java b/api/src/main/java/org/openmrs/module/emrapi/maternal/MotherAndChild.java similarity index 77% rename from api/src/main/java/org/openmrs/module/emrapi/maternal/Mother.java rename to api/src/main/java/org/openmrs/module/emrapi/maternal/MotherAndChild.java index 689bcabb..e41b883c 100644 --- a/api/src/main/java/org/openmrs/module/emrapi/maternal/Mother.java +++ b/api/src/main/java/org/openmrs/module/emrapi/maternal/MotherAndChild.java @@ -6,8 +6,9 @@ @Data -public class Mother { +public class MotherAndChild { private Patient mother; private Patient child; private InpatientAdmission motherAdmission; + private InpatientAdmission childAdmission; } diff --git a/api/src/main/java/org/openmrs/module/emrapi/maternal/MothersAndChildrenSearchCriteria.java b/api/src/main/java/org/openmrs/module/emrapi/maternal/MothersAndChildrenSearchCriteria.java new file mode 100644 index 00000000..5c6f2938 --- /dev/null +++ b/api/src/main/java/org/openmrs/module/emrapi/maternal/MothersAndChildrenSearchCriteria.java @@ -0,0 +1,19 @@ +package org.openmrs.module.emrapi.maternal; + +import java.util.List; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class MothersAndChildrenSearchCriteria { + private List motherUuids; // restrict to children of these mothers + private List childUuids; // restrict to mothers of these children + private boolean motherRequiredToHaveActiveVisit = false; // restrict to mothers who have an active visit + private boolean childRequiredToHaveActiveVisit = false; // restrict to mothers of children who have an active visit + private boolean childRequiredToBeBornDuringMothersActiveVisit = false; // restrict to mothers who had a child born during their active visit + +} diff --git a/api/src/main/java/org/openmrs/module/emrapi/maternal/MothersByChildrenSearchCriteria.java b/api/src/main/java/org/openmrs/module/emrapi/maternal/MothersByChildrenSearchCriteria.java deleted file mode 100644 index 210f600f..00000000 --- a/api/src/main/java/org/openmrs/module/emrapi/maternal/MothersByChildrenSearchCriteria.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.openmrs.module.emrapi.maternal; - -import java.util.List; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.experimental.Accessors; - -@Data -@NoArgsConstructor -@AllArgsConstructor -public class MothersByChildrenSearchCriteria { - private List childUuids; // restrict to mothers of these children - @Accessors(fluent = true) private Boolean requireMotherHasActiveVisit = false; // restrict to mothers who have an active visit - @Accessors(fluent = true) private Boolean requireChildHasActiveVisit = false; // restrict to mothers of children who have an active visit - @Accessors(fluent = true) private boolean requireChildBornDuringMothersActiveVisit = false; // restrict to mothers who had a child born during their active visit - -} diff --git a/api/src/main/resources/hql/mother_child.hql b/api/src/main/resources/hql/mother_child.hql index 05871a2a..2d53226d 100644 --- a/api/src/main/resources/hql/mother_child.hql +++ b/api/src/main/resources/hql/mother_child.hql @@ -9,9 +9,9 @@ where ((:motherUuids) is null or mother.uuid in (:motherUuids)) and ((:childUuids) is null or child.uuid in (:childUuids)) and motherChildRelationship.relationshipType = :motherChildRelationshipType - and (:requireMotherHasActiveVisit = false or (select count(motherVisit) from Visit as motherVisit where motherVisit.patient = mother and motherVisit.stopDatetime is null and motherVisit.voided = false) > 0) - and (:requireChildHasActiveVisit = false or (select count(childVisit) from Visit as childVisit where childVisit.patient = child and childVisit.stopDatetime is null and childVisit.voided = false) > 0) - and (:requireChildBornDuringMothersActiveVisit = false or (select count(motherVisit) from Visit as motherVisit where motherVisit.patient = mother and motherVisit.stopDatetime is null and motherVisit.voided = false + 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) + and (:childRequiredToBeBornDuringMothersActiveVisit = false or (select count(motherVisit) from Visit as motherVisit where motherVisit.patient = mother and motherVisit.stopDatetime is null and motherVisit.voided = false and year(child.birthdate) >= year(motherVisit.startDatetime) and month(child.birthdate) >= month(motherVisit.startDatetime) and day(child.birthdate) >= day(motherVisit.startDatetime)) > 0) diff --git a/api/src/test/java/org/openmrs/module/emrapi/maternal/MaternalServiceImplTest.java b/api/src/test/java/org/openmrs/module/emrapi/maternal/MaternalServiceImplTest.java index 035599d5..eeb50122 100644 --- a/api/src/test/java/org/openmrs/module/emrapi/maternal/MaternalServiceImplTest.java +++ b/api/src/test/java/org/openmrs/module/emrapi/maternal/MaternalServiceImplTest.java @@ -79,12 +79,12 @@ public void shouldGetChild() { motherChildRelationship.setPersonB(child); personService.saveRelationship(motherChildRelationship); - List children = maternalService.getChildrenByMothers(new ChildrenByMothersSearchCriteria(null, false, false, false)); + List motherAndChildList = maternalService.getMothersAndChildren(new MothersAndChildrenSearchCriteria(null, null, false, false, false)); - assertThat(children.size(), equalTo(1)); - assertThat(children.get(0).getChild(), equalTo(child)); - assertThat(children.get(0).getMother(), equalTo(mother)); - assertNull(children.get(0).getChildAdmission()); + assertThat(motherAndChildList.size(), equalTo(1)); + assertThat(motherAndChildList.get(0).getChild(), equalTo(child)); + assertThat(motherAndChildList.get(0).getMother(), equalTo(mother)); + assertNull(motherAndChildList.get(0).getChildAdmission()); } @Test public void shouldGetChildByMother() { @@ -99,12 +99,12 @@ public void shouldGetChildByMother() { motherChildRelationship.setPersonB(child); personService.saveRelationship(motherChildRelationship); - List children = maternalService.getChildrenByMothers(new ChildrenByMothersSearchCriteria(Collections.singletonList(mother.getUuid()), false, false, false)); + List motherAndChildList = maternalService.getMothersAndChildren(new MothersAndChildrenSearchCriteria(Collections.singletonList(mother.getUuid()), null, false, false, false)); - assertThat(children.size(), equalTo(1)); - assertThat(children.get(0).getChild(), equalTo(child)); - assertThat(children.get(0).getMother(), equalTo(mother)); - assertNull(children.get(0).getChildAdmission()); + assertThat(motherAndChildList.size(), equalTo(1)); + assertThat(motherAndChildList.get(0).getChild(), equalTo(child)); + assertThat(motherAndChildList.get(0).getMother(), equalTo(mother)); + assertNull(motherAndChildList.get(0).getChildAdmission()); } @Test @@ -126,9 +126,9 @@ public void shouldNotGetChildByMotherIfMotherDoesNotHaveActiveVisitAndMotherHasA Visit motherVisit = testDataManager.visit().visitType(emrApiProperties.getAtFacilityVisitType()).location(visitLocation).patient(mother).started(oneHourAgo).stopped(now).save(); Visit childVisit = testDataManager.visit().visitType(emrApiProperties.getAtFacilityVisitType()).location(visitLocation).patient(child).started(now).save(); - List children = maternalService.getChildrenByMothers(new ChildrenByMothersSearchCriteria(Collections.singletonList(mother.getUuid()), true, false, false)); + List motherAndChildList = maternalService.getMothersAndChildren(new MothersAndChildrenSearchCriteria(Collections.singletonList(mother.getUuid()), null, true, false, false)); - assertThat(children.size(), equalTo(0)); + assertThat(motherAndChildList.size(), equalTo(0)); } @Test @@ -150,9 +150,9 @@ public void shouldNotGetChildByMotherIfChildDoesNotHaveActiveVisitAndChildHasAct Visit motherVisit = testDataManager.visit().visitType(emrApiProperties.getAtFacilityVisitType()).location(visitLocation).patient(mother).started(oneHourAgo).save(); Visit childVisit = testDataManager.visit().visitType(emrApiProperties.getAtFacilityVisitType()).location(visitLocation).patient(child).started(now).stopped(now).save(); - List children = maternalService.getChildrenByMothers(new ChildrenByMothersSearchCriteria(Collections.singletonList(mother.getUuid()), false, true, false)); + List motherAndChildList = maternalService.getMothersAndChildren(new MothersAndChildrenSearchCriteria(Collections.singletonList(mother.getUuid()), null, false, true, false)); - assertThat(children.size(), equalTo(0)); + assertThat(motherAndChildList.size(), equalTo(0)); } @Test @@ -162,9 +162,9 @@ public void shouldNotGetChildByMotherIfChildNotLinkedByMotherChildRelationship() Patient mother = testDataManager.randomPatient().birthdate("1980-01-01").gender("F").save(); Patient child = testDataManager.randomPatient().birthdate(now).save(); - List children = maternalService.getChildrenByMothers(new ChildrenByMothersSearchCriteria(Collections.singletonList(mother.getUuid()), false, false, false)); + List motherAndChildList = maternalService.getMothersAndChildren(new MothersAndChildrenSearchCriteria(Collections.singletonList(mother.getUuid()), null, false, false, false)); - assertThat(children.size(), equalTo(0)); + assertThat(motherAndChildList.size(), equalTo(0)); } @Test @@ -185,9 +185,9 @@ public void shouldNotGetChildByMotherIfChildBornADayOrMoreBeforeVisitAndChildBor Visit motherVisit = testDataManager.visit().visitType(emrApiProperties.getAtFacilityVisitType()).location(visitLocation).patient(mother).started(oneHourAgo).save(); - List children = maternalService.getChildrenByMothers(new ChildrenByMothersSearchCriteria(Collections.singletonList(mother.getUuid()), false, false, true)); + List motherAndChildList = maternalService.getMothersAndChildren(new MothersAndChildrenSearchCriteria(Collections.singletonList(mother.getUuid()), null, false, false, true)); - assertThat(children.size(), equalTo(0)); + assertThat(motherAndChildList.size(), equalTo(0)); } // this test will fail when run *exactly* at midnight, on the second @@ -209,12 +209,12 @@ public void shouldGetChildByMotherIfChildBornBeforeVisitStartButSameDayAndChildB Visit motherVisit = testDataManager.visit().visitType(emrApiProperties.getAtFacilityVisitType()).location(visitLocation).patient(mother).started(now).save(); - List children = maternalService.getChildrenByMothers(new ChildrenByMothersSearchCriteria(Collections.singletonList(mother.getUuid()), false, false, true)); + List motherAndChildList = maternalService.getMothersAndChildren(new MothersAndChildrenSearchCriteria(Collections.singletonList(mother.getUuid()), null, false, false, true)); - assertThat(children.size(),equalTo(1)); - assertThat(children.get(0).getChild(),equalTo(child)); - assertThat(children.get(0).getMother(), equalTo(mother)); - assertNull(children.get(0).getChildAdmission()); + assertThat(motherAndChildList.size(),equalTo(1)); + assertThat(motherAndChildList.get(0).getChild(),equalTo(child)); + assertThat(motherAndChildList.get(0).getMother(), equalTo(mother)); + assertNull(motherAndChildList.get(0).getChildAdmission()); } @Test @@ -237,18 +237,18 @@ public void shouldGetMultipleChildByMother() { motherChildRelationship2.setPersonB(child2); personService.saveRelationship(motherChildRelationship2); - List children = maternalService.getChildrenByMothers(new ChildrenByMothersSearchCriteria(Collections.singletonList(mother.getUuid()), false, false, false)); + List motherAndChildList = maternalService.getMothersAndChildren(new MothersAndChildrenSearchCriteria(Collections.singletonList(mother.getUuid()), null, false, false, false)); - assertThat(children.size(), equalTo(2)); - List childList = children.stream().map(Child::getChild).collect(Collectors.toList()); + assertThat(motherAndChildList.size(), equalTo(2)); + List childList = motherAndChildList.stream().map(MotherAndChild::getChild).collect(Collectors.toList()); assertTrue(childList.contains(child1)); assertTrue(childList.contains(child2)); - assertThat(children.get(0).getMother(), equalTo(mother)); - assertThat(children.get(1).getMother(), equalTo(mother)); + assertThat(motherAndChildList.get(0).getMother(), equalTo(mother)); + assertThat(motherAndChildList.get(1).getMother(), equalTo(mother)); - assertNull(children.get(0).getChildAdmission()); - assertNull(children.get(1).getChildAdmission()); + assertNull(motherAndChildList.get(0).getChildAdmission()); + assertNull(motherAndChildList.get(1).getChildAdmission()); } @Test @@ -266,9 +266,9 @@ public void shouldNotGetChildByMotherIfMotherVoided() { motherChildRelationship.setPersonB(child); personService.saveRelationship(motherChildRelationship); - List children = maternalService.getChildrenByMothers(new ChildrenByMothersSearchCriteria(Collections.singletonList(mother.getUuid()), false, false, false)); + List motherAndChildList = maternalService.getMothersAndChildren(new MothersAndChildrenSearchCriteria(Collections.singletonList(mother.getUuid()), null, false, false, false)); - assertThat(children.size(), equalTo(0)); + assertThat(motherAndChildList.size(), equalTo(0)); } @Test @@ -285,9 +285,9 @@ public void shouldNotGetChildByMotherIfChildVoided() { motherChildRelationship.setPersonB(child); personService.saveRelationship(motherChildRelationship); - List children = maternalService.getChildrenByMothers(new ChildrenByMothersSearchCriteria(Collections.singletonList(mother.getUuid()), false, false, false)); + List motherAndChildList = maternalService.getMothersAndChildren(new MothersAndChildrenSearchCriteria(Collections.singletonList(mother.getUuid()), null, false, false, false)); - assertThat(children.size(), equalTo(0)); + assertThat(motherAndChildList.size(), equalTo(0)); } @Test @@ -304,9 +304,9 @@ public void shouldNotGetChildByMotherIfRelationshipVoided() { personService.saveRelationship(motherChildRelationship); personService.voidRelationship(motherChildRelationship, "test"); - List children = maternalService.getChildrenByMothers(new ChildrenByMothersSearchCriteria(Collections.singletonList(mother.getUuid()), false, false, false)); + List motherAndChildList = maternalService.getMothersAndChildren(new MothersAndChildrenSearchCriteria(Collections.singletonList(mother.getUuid()), null, false, false, false)); - assertThat(children.size(), equalTo(0)); + assertThat(motherAndChildList.size(), equalTo(0)); } @Test @@ -328,9 +328,9 @@ public void shouldNotGetChildByMotherIfMotherVisitVoidedAndMotherHasActiveVisitS Visit motherVisit = testDataManager.visit().visitType(emrApiProperties.getAtFacilityVisitType()).location(visitLocation).patient(mother).started(oneHourAgo).save(); visitService.voidVisit(motherVisit, "test"); - List children = maternalService.getChildrenByMothers(new ChildrenByMothersSearchCriteria(Collections.singletonList(mother.getUuid()), true, false, false)); + List motherAndChildList = maternalService.getMothersAndChildren(new MothersAndChildrenSearchCriteria(Collections.singletonList(mother.getUuid()), null, true, false, false)); - assertThat(children.size(), equalTo(0)); + assertThat(motherAndChildList.size(), equalTo(0)); } @Test @@ -351,9 +351,9 @@ public void shouldNotGetChildByMotherIfChildVisitVoidedAndChildHasActiveVisitSet Visit childVisit = testDataManager.visit().visitType(emrApiProperties.getAtFacilityVisitType()).location(visitLocation).patient(child).started(now).save(); visitService.voidVisit(childVisit, "test"); - List children = maternalService.getChildrenByMothers(new ChildrenByMothersSearchCriteria(Collections.singletonList(mother.getUuid()), false, true, false)); + List motherAndChildList = maternalService.getMothersAndChildren(new MothersAndChildrenSearchCriteria(Collections.singletonList(mother.getUuid()), null, false, true, false)); - assertThat(children.size(), equalTo(0)); + assertThat(motherAndChildList.size(), equalTo(0)); } @Test @@ -376,14 +376,14 @@ public void shouldGetChildrenForMultipleMothers() { otherMotherChildRelationship.setPersonB(otherChild); personService.saveRelationship(otherMotherChildRelationship); - List children = maternalService.getChildrenByMothers(new ChildrenByMothersSearchCriteria(Arrays.asList(mother.getUuid(),otherMother.getUuid()), false, false, false)); + List motherAndChildList = maternalService.getMothersAndChildren(new MothersAndChildrenSearchCriteria(Arrays.asList(mother.getUuid(),otherMother.getUuid()), null, false, false, false)); - assertThat(children.size(), equalTo(2)); - List childList = children.stream().map(Child::getChild).collect(Collectors.toList()); + assertThat(motherAndChildList.size(), equalTo(2)); + List childList = motherAndChildList.stream().map(MotherAndChild::getChild).collect(Collectors.toList()); assertTrue(childList.contains(child)); assertTrue(childList.contains(otherChild)); - List motherList = children.stream().map(Child::getMother).collect(Collectors.toList()); + List motherList = motherAndChildList.stream().map(MotherAndChild::getMother).collect(Collectors.toList()); assertTrue(motherList.contains(mother)); assertTrue(motherList.contains(otherMother)); } @@ -420,14 +420,14 @@ public void shouldGetChildrenForMultipleMothersMatchingByActiveVisitsAndChildBor Visit otherChildVisit = testDataManager.visit().visitType(emrApiProperties.getAtFacilityVisitType()).location(visitLocation).patient(otherChild).started(now).save(); - List children = maternalService.getChildrenByMothers(new ChildrenByMothersSearchCriteria(Arrays.asList(mother.getUuid(),otherMother.getUuid()), true, true, true)); + List motherAndChildList = maternalService.getMothersAndChildren(new MothersAndChildrenSearchCriteria(Arrays.asList(mother.getUuid(),otherMother.getUuid()), null, true, true, true)); - assertThat(children.size(), equalTo(2)); - List childList = children.stream().map(Child::getChild).collect(Collectors.toList()); + assertThat(motherAndChildList.size(), equalTo(2)); + List childList = motherAndChildList.stream().map(MotherAndChild::getChild).collect(Collectors.toList()); assertTrue(childList.contains(child)); assertTrue(childList.contains(otherChild)); - List motherList = children.stream().map(Child::getMother).collect(Collectors.toList()); + List motherList = motherAndChildList.stream().map(MotherAndChild::getMother).collect(Collectors.toList()); assertTrue(motherList.contains(mother)); assertTrue(motherList.contains(otherMother)); } @@ -451,11 +451,11 @@ public void shouldGetChildByMotherWithInpatientAdmission() { Encounter admission = testDataManager.encounter().encounterType(emrApiProperties.getAdmissionEncounterType()).encounterDatetime(now).patient(child).save(); Visit childVisit = testDataManager.visit().visitType(emrApiProperties.getAtFacilityVisitType()).location(visitLocation).patient(child).started(now).encounter(admission).save(); - List children = maternalService.getChildrenByMothers(new ChildrenByMothersSearchCriteria(Collections.singletonList(mother.getUuid()), false, false, false)); + List motherAndChildList = maternalService.getMothersAndChildren(new MothersAndChildrenSearchCriteria(Collections.singletonList(mother.getUuid()), null, false, false, false)); - assertThat(children.size(), equalTo(1)); - assertThat(children.get(0).getChildAdmission().getVisit(), equalTo(childVisit)); - assertThat(children.get(0).getChildAdmission().getFirstAdmissionOrTransferEncounter(), equalTo(admission)); + assertThat(motherAndChildList.size(), equalTo(1)); + assertThat(motherAndChildList.get(0).getChildAdmission().getVisit(), equalTo(childVisit)); + assertThat(motherAndChildList.get(0).getChildAdmission().getFirstAdmissionOrTransferEncounter(), equalTo(admission)); } @Test @@ -478,9 +478,9 @@ public void getChildByMotherDoesNotFailWhenChildHaveTwoActiveVisits() { Visit childVisit = testDataManager.visit().visitType(emrApiProperties.getAtFacilityVisitType()).location(visitLocation).patient(child).started(now).save(); Visit anotherChildVisit = testDataManager.visit().visitType(emrApiProperties.getAtFacilityVisitType()).location(visitLocation).patient(child).started(now).save(); - List children = maternalService.getChildrenByMothers(new ChildrenByMothersSearchCriteria(Collections.singletonList(mother.getUuid()), true, true, true)); + List motherAndChildList = maternalService.getMothersAndChildren(new MothersAndChildrenSearchCriteria(Collections.singletonList(mother.getUuid()), null, true, true, true)); - assertThat(children.size(), equalTo(1)); + assertThat(motherAndChildList.size(), equalTo(1)); } @Test @@ -496,12 +496,12 @@ public void shouldGetMother() { motherChildRelationship.setPersonB(child); personService.saveRelationship(motherChildRelationship); - List mothers = maternalService.getMothersByChildren(new MothersByChildrenSearchCriteria(null, false, false, false)); + List motherAndChildList = maternalService.getMothersAndChildren(new MothersAndChildrenSearchCriteria(null, null, false, false, false)); - assertThat(mothers.size(), equalTo(1)); - assertThat(mothers.get(0).getChild(), equalTo(child)); - assertThat(mothers.get(0).getMother(), equalTo(mother)); - assertNull(mothers.get(0).getMotherAdmission()); + assertThat(motherAndChildList.size(), equalTo(1)); + assertThat(motherAndChildList.get(0).getChild(), equalTo(child)); + assertThat(motherAndChildList.get(0).getMother(), equalTo(mother)); + assertNull(motherAndChildList.get(0).getMotherAdmission()); } @Test @@ -517,12 +517,12 @@ public void shouldGetMotherByChild() { motherChildRelationship.setPersonB(child); personService.saveRelationship(motherChildRelationship); - List mothers = maternalService.getMothersByChildren(new MothersByChildrenSearchCriteria(Collections.singletonList(child.getUuid()), false, false, false)); + List motherAndChildList = maternalService.getMothersAndChildren(new MothersAndChildrenSearchCriteria(null, Collections.singletonList(child.getUuid()), false, false, false)); - assertThat(mothers.size(), equalTo(1)); - assertThat(mothers.get(0).getChild(), equalTo(child)); - assertThat(mothers.get(0).getMother(), equalTo(mother)); - assertNull(mothers.get(0).getMotherAdmission()); + assertThat(motherAndChildList.size(), equalTo(1)); + assertThat(motherAndChildList.get(0).getChild(), equalTo(child)); + assertThat(motherAndChildList.get(0).getMother(), equalTo(mother)); + assertNull(motherAndChildList.get(0).getMotherAdmission()); } @Test @@ -543,9 +543,9 @@ public void shouldNotGetMotherByChildIfMotherDoesNotHaveActiveVisitAndMotherHasA Visit motherVisit = testDataManager.visit().visitType(emrApiProperties.getAtFacilityVisitType()).location(visitLocation).patient(mother).started(oneHourAgo).stopped(now).save(); - List mothers = maternalService.getMothersByChildren(new MothersByChildrenSearchCriteria(Collections.singletonList(child.getUuid()), true, false, false)); + List motherAndChildList = maternalService.getMothersAndChildren(new MothersAndChildrenSearchCriteria(null, Collections.singletonList(child.getUuid()), true, false, false)); - assertThat(mothers.size(), equalTo(0)); + assertThat(motherAndChildList.size(), equalTo(0)); } @Test @@ -565,9 +565,9 @@ public void shouldNotGetMotherByChildIfChildDoesNotHaveActiveVisitAndChildHasAct Visit childVisit = testDataManager.visit().visitType(emrApiProperties.getAtFacilityVisitType()).location(visitLocation).patient(child).started(now).stopped(now).save(); - List mothers = maternalService.getMothersByChildren(new MothersByChildrenSearchCriteria(Collections.singletonList(child.getUuid()), false, true,false)); + List motherAndChildList = maternalService.getMothersAndChildren(new MothersAndChildrenSearchCriteria(null, Collections.singletonList(child.getUuid()), false, true,false)); - assertThat(mothers.size(), equalTo(0)); + assertThat(motherAndChildList.size(), equalTo(0)); } @Test @@ -577,9 +577,9 @@ public void shouldNotGetMotherByChildIfChildNotLinkedByMotherChildRelationship() Patient mother = testDataManager.randomPatient().birthdate("1980-01-01").gender("F").save(); Patient child = testDataManager.randomPatient().birthdate(now).save(); - List mothers = maternalService.getMothersByChildren(new MothersByChildrenSearchCriteria(Collections.singletonList(child.getUuid()), false, false, false)); + List motherAndChildList = maternalService.getMothersAndChildren(new MothersAndChildrenSearchCriteria(null, Collections.singletonList(child.getUuid()), false, false, false)); - assertThat(mothers.size(), equalTo(0)); + assertThat(motherAndChildList.size(), equalTo(0)); } @Test @@ -597,9 +597,9 @@ public void shouldNotGetMotherByChildIfMotherVoided() { motherChildRelationship.setPersonB(child); personService.saveRelationship(motherChildRelationship); - List mothers = maternalService.getMothersByChildren(new MothersByChildrenSearchCriteria(Collections.singletonList(child.getUuid()), false, false, false)); + List motherAndChildList = maternalService.getMothersAndChildren(new MothersAndChildrenSearchCriteria(null, Collections.singletonList(child.getUuid()), false, false, false)); - assertThat(mothers.size(), equalTo(0)); + assertThat(motherAndChildList.size(), equalTo(0)); } @Test @@ -616,9 +616,9 @@ public void shouldNotGetMotherByChildIfChildVoided() { motherChildRelationship.setPersonB(child); personService.saveRelationship(motherChildRelationship); - List mothers = maternalService.getMothersByChildren(new MothersByChildrenSearchCriteria(Collections.singletonList(child.getUuid()), false, false, false)); + List motherAndChildList = maternalService.getMothersAndChildren(new MothersAndChildrenSearchCriteria(null, Collections.singletonList(child.getUuid()), false, false, false)); - assertThat(mothers.size(), equalTo(0)); + assertThat(motherAndChildList.size(), equalTo(0)); } @Test @@ -635,9 +635,9 @@ public void shouldNotGetMotherByChildIfRelationshipVoided() { personService.saveRelationship(motherChildRelationship); personService.voidRelationship(motherChildRelationship, "test"); - List mothers = maternalService.getMothersByChildren(new MothersByChildrenSearchCriteria(Collections.singletonList(child.getUuid()), false, false,false)); + List motherAndChildList = maternalService.getMothersAndChildren(new MothersAndChildrenSearchCriteria(null, Collections.singletonList(child.getUuid()), false, false,false)); - assertThat(mothers.size(), equalTo(0)); + assertThat(motherAndChildList.size(), equalTo(0)); } @Test @@ -659,9 +659,9 @@ public void shouldNotGetMotherByChildIfMotherVisitVoidedAndMotherHasActiveVisitS Visit motherVisit = testDataManager.visit().visitType(emrApiProperties.getAtFacilityVisitType()).location(visitLocation).patient(mother).started(oneHourAgo).save(); visitService.voidVisit(motherVisit, "test"); - List mothers = maternalService.getMothersByChildren(new MothersByChildrenSearchCriteria(Collections.singletonList(child.getUuid()), true, false, false)); + List motherAndChildList = maternalService.getMothersAndChildren(new MothersAndChildrenSearchCriteria(null, Collections.singletonList(child.getUuid()), true, false, false)); - assertThat(mothers.size(), equalTo(0)); + assertThat(motherAndChildList.size(), equalTo(0)); } @Test @@ -682,9 +682,9 @@ public void shouldNotGetMotherByChildIfChildVisitVoidedAndChildHasActiveVisitSet Visit childVisit = testDataManager.visit().visitType(emrApiProperties.getAtFacilityVisitType()).location(visitLocation).patient(child).started(now).save(); visitService.voidVisit(childVisit, "test"); - List mothers = maternalService.getMothersByChildren(new MothersByChildrenSearchCriteria(Collections.singletonList(child.getUuid()), false, true, false)); + List motherAndChildList = maternalService.getMothersAndChildren(new MothersAndChildrenSearchCriteria(null, Collections.singletonList(child.getUuid()), false, true, false)); - assertThat(mothers.size(), equalTo(0)); + assertThat(motherAndChildList.size(), equalTo(0)); } @Test @@ -709,14 +709,14 @@ public void shouldGetMothersForMultipleChildren() { otherMotherChildRelationship.setPersonB(otherChild); personService.saveRelationship(otherMotherChildRelationship); - List mothers = maternalService.getMothersByChildren(new MothersByChildrenSearchCriteria(Arrays.asList(child.getUuid(),otherChild.getUuid()), false, false, false)); + List motherAndChildList = maternalService.getMothersAndChildren(new MothersAndChildrenSearchCriteria(null, Arrays.asList(child.getUuid(),otherChild.getUuid()), false, false, false)); - assertThat(mothers.size(), equalTo(2)); - List childList = mothers.stream().map(Mother::getChild).collect(Collectors.toList()); + assertThat(motherAndChildList.size(), equalTo(2)); + List childList = motherAndChildList.stream().map(MotherAndChild::getChild).collect(Collectors.toList()); assertTrue(childList.contains(child)); assertTrue(childList.contains(otherChild)); - List motherList = mothers.stream().map(Mother::getMother).collect(Collectors.toList()); + List motherList = motherAndChildList.stream().map(MotherAndChild::getMother).collect(Collectors.toList()); assertTrue(motherList.contains(mother)); assertTrue(motherList.contains(otherMother)); } @@ -742,11 +742,11 @@ public void shouldGetMotherByChildWithInpatientAdmission() { Visit motherVisit = testDataManager.visit().visitType(emrApiProperties.getAtFacilityVisitType()).location(visitLocation).patient(mother).started(oneHourAgo).encounter(admission).save(); - List mothers = maternalService.getMothersByChildren(new MothersByChildrenSearchCriteria(Collections.singletonList(child.getUuid()), false, false, false)); + List motherAndChildList = maternalService.getMothersAndChildren(new MothersAndChildrenSearchCriteria(null, Collections.singletonList(child.getUuid()), false, false, false)); - assertThat(mothers.size(), equalTo(1)); - assertThat(mothers.get(0).getMotherAdmission().getVisit(), equalTo(motherVisit)); - assertThat(mothers.get(0).getMotherAdmission().getFirstAdmissionOrTransferEncounter(), equalTo(admission)); + assertThat(motherAndChildList.size(), equalTo(1)); + assertThat(motherAndChildList.get(0).getMotherAdmission().getVisit(), equalTo(motherVisit)); + assertThat(motherAndChildList.get(0).getMotherAdmission().getFirstAdmissionOrTransferEncounter(), equalTo(admission)); } @Test @@ -777,12 +777,12 @@ public void shouldOnlyGetMothersWithChildrenBornDuringActiveVisit() { Visit motherVisit = testDataManager.visit().visitType(emrApiProperties.getAtFacilityVisitType()).location(visitLocation).patient(mother).started(oneHourAgo).save(); Visit otherMotherVisit = testDataManager.visit().visitType(emrApiProperties.getAtFacilityVisitType()).location(visitLocation).patient(otherMother).started(oneHourAgo).save(); - List mothers = maternalService.getMothersByChildren(new MothersByChildrenSearchCriteria(null, false, false, true)); + List motherAndChildList = maternalService.getMothersAndChildren(new MothersAndChildrenSearchCriteria(null, null, false, false, true)); - assertThat(mothers.size(), equalTo(1)); - assertThat(mothers.get(0).getChild(), equalTo(child)); - assertThat(mothers.get(0).getMother(), equalTo(mother)); - assertNull(mothers.get(0).getMotherAdmission()); + assertThat(motherAndChildList.size(), equalTo(1)); + assertThat(motherAndChildList.get(0).getChild(), equalTo(child)); + assertThat(motherAndChildList.get(0).getMother(), equalTo(mother)); + assertNull(motherAndChildList.get(0).getMotherAdmission()); } }