Skip to content

Commit

Permalink
EA-209 fix date comparison in getMothersAndChildren() to determine wh…
Browse files Browse the repository at this point in the history
…ether child is born during mother's visit
  • Loading branch information
chibongho committed Nov 7, 2024
1 parent 097e9b2 commit c014424
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
5 changes: 2 additions & 3 deletions api/src/main/resources/hql/mother_child.hql
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ where
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)
and (year(child.birthdate)||'-'||month(child.birthdate)||'-'||day(child.birthdate)) >=
(year(motherVisit.startDatetime)||'-'||month(motherVisit.startDatetime)||'-'||day(motherVisit.startDatetime))) > 0)
and mother.voided = false and child.voided = false and motherChildRelationship.voided = false
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,32 @@ public void shouldGetChildByMotherIfChildBornBeforeVisitStartButSameDayAndChildB
assertThat(motherAndChildList.get(0).getMother(), equalTo(mother));
assertNull(motherAndChildList.get(0).getChildAdmission());
}

@Test
public void shouldGetChildByMotherIfChildBornInNextCalendarYearAfterVisitStart() {
DateTime lastDayOfYear = new DateTime(1980, 12, 31, 0, 0);
Date oneDayLater = lastDayOfYear.plusDays(1).toDate();

Location visitLocation = testDataManager.location().name("Visit Location").save();

Patient mother = testDataManager.randomPatient().birthdate("1980-01-01").gender("F").save();
Patient child = testDataManager.randomPatient().birthdate(oneDayLater).save();

Relationship motherChildRelationship = new Relationship();
motherChildRelationship.setRelationshipType(emrApiProperties.getMotherChildRelationshipType());
motherChildRelationship.setPersonA(mother);
motherChildRelationship.setPersonB(child);
personService.saveRelationship(motherChildRelationship);

Visit motherVisit = testDataManager.visit().visitType(emrApiProperties.getAtFacilityVisitType()).location(visitLocation).patient(mother).started(lastDayOfYear.toDate()).save();

List<MotherAndChild> motherAndChildList = maternalService.getMothersAndChildren(new MothersAndChildrenSearchCriteria(Collections.singletonList(mother.getUuid()), null, false, false, true));

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 shouldGetMultipleChildByMother() {
Expand Down

0 comments on commit c014424

Please sign in to comment.