-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EA-198: Add support for configuring Mother Child relationships within…
… the EMR API module
- Loading branch information
1 parent
238b854
commit a1367c7
Showing
9 changed files
with
570 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
api/src/main/java/org/openmrs/module/emrapi/maternal/MaternalService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package org.openmrs.module.emrapi.maternal; | ||
|
||
import java.util.List; | ||
|
||
import org.openmrs.Location; | ||
import org.openmrs.Patient; | ||
import org.openmrs.api.OpenmrsService; | ||
|
||
public interface MaternalService extends OpenmrsService { | ||
|
||
/** | ||
* Returns all "newborns" of the specified patient, where "newborn" is defined as a patient who is: | ||
* - linked to the specified patient by a relationship of type emrapi.motherChildRelationshipType | ||
* - has as an active visit (at the visitLocation, if specified) | ||
* - has a birthdate that is on or after the start date of the mother's active visit (at the visitLocation, if specified) (note matches on date, not datetime to account for retrospective data entry or only have a date component of birthdate) | ||
* | ||
* @param mother | ||
* @param visitLocation if not null, restrict matching visits to only those at the specified location | ||
* @return | ||
*/ | ||
public List<Newborn> getNewbornsByMother(Patient mother, Location visitLocation); | ||
|
||
} |
62 changes: 62 additions & 0 deletions
62
api/src/main/java/org/openmrs/module/emrapi/maternal/MaternalServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package org.openmrs.module.emrapi.maternal; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import org.openmrs.Location; | ||
import org.openmrs.Patient; | ||
import org.openmrs.RelationshipType; | ||
import org.openmrs.Visit; | ||
import org.openmrs.api.APIException; | ||
import org.openmrs.api.impl.BaseOpenmrsService; | ||
import org.openmrs.module.emrapi.EmrApiProperties; | ||
import org.openmrs.module.emrapi.db.EmrApiDAO; | ||
|
||
public class MaternalServiceImpl extends BaseOpenmrsService implements MaternalService { | ||
|
||
private EmrApiProperties emrApiProperties; | ||
|
||
private EmrApiDAO emrApiDAO; | ||
|
||
public void setEmrApiProperties(EmrApiProperties emrApiProperties) { | ||
this.emrApiProperties = emrApiProperties; | ||
} | ||
|
||
public void setEmrApiDAO(EmrApiDAO emrApiDAO) { | ||
this.emrApiDAO = emrApiDAO; | ||
} | ||
|
||
public List<Newborn> getNewbornsByMother(Patient mother, Location visitLocation) { | ||
|
||
RelationshipType motherChildRelationshipType = emrApiProperties.getMotherChildRelationshipType(); | ||
|
||
if (motherChildRelationshipType == null) { | ||
throw new APIException("Mother-Child relationship type has not been configured"); | ||
} | ||
|
||
if (mother == null) { | ||
throw new APIException("Mother cannot be null"); | ||
} | ||
|
||
Map<String, Object> parameters = new HashMap<>(); | ||
parameters.put("mother", mother); | ||
parameters.put("motherChildRelationshipType", motherChildRelationshipType); | ||
parameters.put("visitLocation", visitLocation); | ||
|
||
List<?> l = emrApiDAO.executeHqlFromResource("hql/newborns_by_mother.hql", parameters, List.class); | ||
|
||
List<Newborn> ret = new ArrayList<>(); | ||
|
||
for (Object req : l) { | ||
Object[] row = (Object[]) req; | ||
Newborn newborn = new Newborn(); | ||
newborn.setNewborn((Patient) row[0]); | ||
newborn.setNewbornVisit((Visit) row[1]); | ||
ret.add(newborn); | ||
} | ||
|
||
return ret; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
api/src/main/java/org/openmrs/module/emrapi/maternal/Newborn.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package org.openmrs.module.emrapi.maternal; | ||
|
||
import lombok.Data; | ||
import org.openmrs.Patient; | ||
import org.openmrs.Visit; | ||
|
||
@Data | ||
public class Newborn { | ||
private Patient newborn; | ||
private Visit newbornVisit; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
select | ||
baby, | ||
babyVisit | ||
from | ||
Person as mother, | ||
Person as baby, | ||
Relationship as motherChildRelationship, | ||
Visit as motherVisit, | ||
Visit as babyVisit | ||
where | ||
mother = :mother | ||
and motherChildRelationship.personA = mother | ||
and motherChildRelationship.personB = baby | ||
and motherChildRelationship.relationshipType = :motherChildRelationshipType | ||
and motherVisit.patient = mother and motherVisit.stopDatetime is null | ||
and babyVisit.patient = baby and babyVisit.stopDatetime is null | ||
and year(baby.birthdate) >= year(motherVisit.startDatetime) | ||
and month(baby.birthdate) >= month(motherVisit.startDatetime) | ||
and day(baby.birthdate) >= day(motherVisit.startDatetime) | ||
and (:visitLocation is null or (motherVisit.location = :visitLocation and babyVisit.location = :visitLocation)) | ||
and mother.voided = false and baby.voided = false and motherChildRelationship.voided = false and motherVisit.voided = false and babyVisit.voided = false | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.