Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EA-209 fix date comparison in getMothersAndChildren() to determine wh… #252

Merged
merged 1 commit into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)) >=
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like this manual concatenation, but I can't find a DATE() function in hql like in mysql.

(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
Loading