-
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-188 - Improve Java and Rest API for retrieving inpatient admission…
… requests (#233)
- Loading branch information
Showing
16 changed files
with
816 additions
and
69 deletions.
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
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
26 changes: 26 additions & 0 deletions
26
api/src/main/java/org/openmrs/module/emrapi/adt/InpatientRequest.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,26 @@ | ||
package org.openmrs.module.emrapi.adt; | ||
|
||
import lombok.Data; | ||
import org.openmrs.Concept; | ||
import org.openmrs.Encounter; | ||
import org.openmrs.Location; | ||
import org.openmrs.Obs; | ||
import org.openmrs.Patient; | ||
import org.openmrs.Visit; | ||
import org.openmrs.module.emrapi.disposition.DispositionType; | ||
|
||
import java.util.Date; | ||
|
||
/** | ||
* Represents and Admission, Discharge, or Transfer request | ||
*/ | ||
@Data | ||
public class InpatientRequest { | ||
private Visit visit; | ||
private Patient patient; | ||
private DispositionType dispositionType; | ||
private Encounter dispositionEncounter; | ||
private Obs dispositionObsGroup; | ||
private Concept disposition; | ||
private Location dispositionLocation; | ||
} |
50 changes: 50 additions & 0 deletions
50
api/src/main/java/org/openmrs/module/emrapi/adt/InpatientRequestSearchCriteria.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,50 @@ | ||
package org.openmrs.module.emrapi.adt; | ||
|
||
import lombok.Data; | ||
import org.openmrs.Location; | ||
import org.openmrs.module.emrapi.disposition.DispositionType; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* Represents criteria for searching for AdtRequests | ||
* Currently the assumption is that all requests returned are active, and this will be the default regardless | ||
*/ | ||
@Data | ||
public class InpatientRequestSearchCriteria { | ||
|
||
private Location visitLocation; | ||
private List<Location> dispositionLocations; | ||
private List<DispositionType> dispositionTypes; | ||
private List<Integer> patientIds; | ||
private List<Integer> visitIds; | ||
|
||
public void addDispositionLocation(Location location) { | ||
if (dispositionLocations == null) { | ||
dispositionLocations = new ArrayList<>(); | ||
} | ||
dispositionLocations.add(location); | ||
} | ||
|
||
public void addDispositionType(DispositionType dispositionType) { | ||
if (dispositionTypes == null) { | ||
dispositionTypes = new ArrayList<>(); | ||
} | ||
dispositionTypes.add(dispositionType); | ||
} | ||
|
||
public void addPatientId(Integer patientId) { | ||
if (patientIds == null) { | ||
patientIds = new ArrayList<>(); | ||
} | ||
patientIds.add(patientId); | ||
} | ||
|
||
public void addVisitId(Integer visitId) { | ||
if (visitIds == null) { | ||
visitIds = new ArrayList<>(); | ||
} | ||
visitIds.add(visitId); | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
api/src/main/resources/hql/inpatient_request_dispositions.hql
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,63 @@ | ||
select | ||
visit, | ||
dispoEncounter.patient, | ||
dispoEncounter, | ||
dispo.obsGroup, | ||
dispo, | ||
(select o from Obs o where o.obsGroup = dispo.obsGroup and o.voided = 0 and o.concept = :admitLocationConcept) as admitLocation, | ||
(select o from Obs o where o.obsGroup = dispo.obsGroup and o.voided = 0 and o.concept = :transferLocationConcept) as transferLocation | ||
from | ||
Obs as dispo | ||
inner join dispo.encounter as dispoEncounter | ||
inner join dispoEncounter.visit as visit | ||
inner join dispo.person as person | ||
where | ||
dispo.voided = false | ||
and dispoEncounter.voided = false | ||
and visit.voided = false | ||
and dispo.concept = :dispositionConcept | ||
and dispo.valueCoded in :dispositionValues | ||
and (:visitLocation is null or visit.location = :visitLocation) | ||
and person.dead = false | ||
and visit.stopDatetime is null | ||
and ( | ||
select count(*) | ||
from Obs as laterDispoObs | ||
where laterDispoObs.encounter.visit = visit | ||
and laterDispoObs.voided = false | ||
and laterDispoObs.concept = :dispositionConcept | ||
and ( | ||
laterDispoObs.obsDatetime > dispo.obsDatetime or | ||
(laterDispoObs.obsDatetime = dispo.obsDatetime and laterDispoObs.obsId > dispo.obsId) | ||
) | ||
) = 0 | ||
and ( | ||
select count(*) | ||
from Encounter as adtEncounter | ||
where adtEncounter.visit = visit | ||
and adtEncounter.voided = false | ||
and adtEncounter.encounterType in (:adtEncounterTypes) | ||
and adtEncounter.encounterDatetime >= dispo.obsDatetime | ||
) = 0 | ||
and ( | ||
select count(*) | ||
from Obs as adtDecision | ||
inner join adtDecision.encounter as encounterInVisit | ||
where encounterInVisit.visit = visit | ||
and encounterInVisit.voided = false | ||
and adtDecision.voided = false | ||
and adtDecision.concept = :adtDecisionConcept | ||
and adtDecision.valueCoded = :denyConcept | ||
and encounterInVisit.encounterDatetime > dispoEncounter.encounterDatetime | ||
) = 0 | ||
and ( | ||
:limitByDispositionLocation = false or ( | ||
select count(*) | ||
from Obs as locationObs | ||
where locationObs.obsGroup = dispo.obsGroup | ||
and locationObs.valueText in (:dispositionLocationIds) | ||
) > 0 | ||
) | ||
and (:limitByPatient is false or dispoEncounter.patient.patientId in (:patientIds)) | ||
and (:limitByVisit is false or visit.visitId in (:visitIds)) | ||
order by dispo.obsId |
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.