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

(update with code review comments)
  • Loading branch information
mogoodrich committed Aug 9, 2024
1 parent 1777a93 commit 7495bcd
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,20 @@ public List<MotherAndChild> getMothersAndChildren(MothersAndChildrenSearchCriter
parameters.put("motherUuids", criteria.getMotherUuids());
parameters.put("childUuids", criteria.getChildUuids());
parameters.put("motherChildRelationshipType", motherChildRelationshipType);
parameters.put("requireMotherHasActiveVisit", criteria.isRequireMotherHasActiveVisit());
parameters.put("requireChildHasActiveVisit", criteria.isRequireChildHasActiveVisit());
parameters.put("requireChildBornDuringMothersActiveVisit", criteria.isRequireChildBornDuringMothersActiveVisit());
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<MotherAndChild> ret = new ArrayList<>();

for (Object req : l) {
Object[] row = (Object[]) req;
MotherAndChild child = new MotherAndChild();
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
public class MothersAndChildrenSearchCriteria {
private List<String> motherUuids; // restrict to children of these mothers
private List<String> childUuids; // restrict to mothers of these children
private boolean requireMotherHasActiveVisit = false; // restrict to mothers who have an active visit
private boolean requireChildHasActiveVisit = false; // restrict to mothers of children who have an active visit
private boolean requireChildBornDuringMothersActiveVisit = false; // restrict to mothers who had a child born during their active visit
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

}
6 changes: 3 additions & 3 deletions api/src/main/resources/hql/mother_child.hql
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 7495bcd

Please sign in to comment.