Skip to content

Commit

Permalink
EA-200 - add InpatientRequest to EMR API Inpatient Admission (#236)
Browse files Browse the repository at this point in the history
  • Loading branch information
mseaton authored Aug 5, 2024
1 parent 238b854 commit 348d202
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1061,14 +1061,32 @@ else if (encounter.getEncounterType().equals(dischargeEncounterType)) {
}
}

List<InpatientAdmission> ret = new ArrayList<>();
for (InpatientAdmission admission : m.values()) {
if (criteria.getCurrentInpatientLocations() == null || criteria.getCurrentInpatientLocations().contains(admission.getCurrentInpatientLocation())) {
if (criteria.isIncludeDischarged() || !admission.isDischarged()) {
ret.add(admission);
}
// Filter out any admissions that do not match the search criteria
List<Integer> visitIds = new ArrayList<>();
for (Iterator<Map.Entry<Visit, InpatientAdmission>> i = m.entrySet().iterator(); i.hasNext(); ) {
InpatientAdmission admission = i.next().getValue();
if (criteria.getCurrentInpatientLocations() != null && !criteria.getCurrentInpatientLocations().contains(admission.getCurrentInpatientLocation())) {
i.remove();
}
else if (!criteria.isIncludeDischarged() && admission.isDischarged()) {
i.remove();
}
else {
visitIds.add(admission.getVisit().getVisitId());
}
}
return ret;

// Retrieve InpatientRequests associated with these admissions prior to returning them
InpatientRequestSearchCriteria requestCriteria = new InpatientRequestSearchCriteria();
requestCriteria.setVisitIds(visitIds);
List<InpatientRequest> requests = getInpatientRequests(requestCriteria);
for (InpatientRequest r : requests) {
InpatientAdmission admission = m.get(r.getVisit());
if (admission != null) {
admission.setCurrentInpatientRequest(r);
}
}

return new ArrayList<>(m.values());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class InpatientAdmission {

private Visit visit;
private Patient patient;
private InpatientRequest currentInpatientRequest;
private Set<Encounter> admissionEncounters = new TreeSet<>(getEncounterComparator());
private Set<Encounter> transferEncounters = new TreeSet<>(getEncounterComparator());
private Set<Encounter> dischargeEncounters = new TreeSet<>(getEncounterComparator());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import java.util.List;

import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;

public class AdtServiceImplTest extends EmrApiContextSensitiveTest {
Expand Down Expand Up @@ -595,4 +597,24 @@ public void shouldNotGetAdmissionsForEndedVisits() {
assertNumAdmissions(admissionCriteria, 0);
}

@Test
public void shouldGetInpatientRequestsAssociatedWithAdmission() {
assertNumAdmissions(admissionCriteria, 0);
createAdmissionRequest(DateUtils.addHours(visitDate, 2));
createAdmissionEncounter(DateUtils.addHours(visitDate, 3));
List<InpatientAdmission> l = assertNumAdmissions(admissionCriteria, 1);
assertNull(l.get(0).getCurrentInpatientRequest());
Obs transferRequest = createTransferRequest(DateUtils.addHours(visitDate, 4));
l = assertNumAdmissions(admissionCriteria, 1);
assertNotNull(l.get(0).getCurrentInpatientRequest());
assertThat(l.get(0).getCurrentInpatientRequest().getDispositionObsGroup(), equalTo(transferRequest));
Obs dischargeRequest = createDischargeRequest(DateUtils.addHours(visitDate, 5), admissionLocation);
l = assertNumAdmissions(admissionCriteria, 1);
assertNotNull(l.get(0).getCurrentInpatientRequest());
assertThat(l.get(0).getCurrentInpatientRequest().getDispositionObsGroup(), equalTo(dischargeRequest));
createTransferEncounter(DateUtils.addHours(visitDate, 6));
l = assertNumAdmissions(admissionCriteria, 1);
assertNull(l.get(0).getCurrentInpatientRequest());
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package org.openmrs.module.emrapi.rest.converter;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.openmrs.annotation.Handler;
import org.openmrs.module.emrapi.adt.InpatientAdmission;
import org.openmrs.module.webservices.rest.web.representation.CustomRepresentation;
Expand All @@ -13,8 +11,6 @@
@Handler(supports = InpatientAdmission.class, order = 0)
public class InpatientAdmissionConverter extends SimpleBeanConverter<InpatientAdmission> {

private final Log log = LogFactory.getLog(getClass());

@Override
public DelegatingResourceDescription getResourceDescription(InpatientAdmission req, Representation representation) {
DelegatingResourceDescription ret = super.getResourceDescription(req, representation);
Expand All @@ -25,6 +21,7 @@ public DelegatingResourceDescription getResourceDescription(InpatientAdmission r
rep.addProperty("firstAdmissionOrTransferEncounter", getEncounterRepresentation());
rep.addProperty("latestAdmissionOrTransferEncounter", getEncounterRepresentation());
rep.addProperty("encounterAssigningToCurrentInpatientLocation", getEncounterRepresentation());
rep.addProperty("currentInpatientRequest", getInpatientRequestRepresentation());
rep.addProperty("discharged");
return rep;
}
Expand All @@ -41,4 +38,8 @@ else if (representation instanceof FullRepresentation) {
public Representation getEncounterRepresentation() {
return new CustomRepresentation("uuid,display,encounterDatetime,location:ref,encounterType:ref");
}

public Representation getInpatientRequestRepresentation() {
return new CustomRepresentation("dispositionType,dispositionEncounter:(uuid,display,encounterDatetime),dispositionLocation:ref");
}
}

0 comments on commit 348d202

Please sign in to comment.