From 0a0804b6b5261bd4145037467f585b81fa4ca861 Mon Sep 17 00:00:00 2001 From: Michael Seaton Date: Mon, 22 Jul 2024 17:55:41 -0400 Subject: [PATCH] EA-190 Add REST API for Inpatient Admissions --- .../module/emrapi/adt/InpatientAdmission.java | 2 +- .../InpatientAdmissionConverter.java | 44 +++++++++++++++++ .../InpatientAdmissionController.java | 47 +++++++++++++++++++ .../controller/InpatientVisitsController.java | 1 + 4 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 omod/src/main/java/org/openmrs/module/emrapi/rest/converter/InpatientAdmissionConverter.java create mode 100644 omod/src/main/java/org/openmrs/module/emrapi/web/controller/InpatientAdmissionController.java diff --git a/api/src/main/java/org/openmrs/module/emrapi/adt/InpatientAdmission.java b/api/src/main/java/org/openmrs/module/emrapi/adt/InpatientAdmission.java index cf678d77..30276241 100644 --- a/api/src/main/java/org/openmrs/module/emrapi/adt/InpatientAdmission.java +++ b/api/src/main/java/org/openmrs/module/emrapi/adt/InpatientAdmission.java @@ -87,7 +87,7 @@ public Encounter getEncounterAssigningToCurrentInpatientLocation() { return ret; } } - return null; + return ret; } public boolean isDischarged() { diff --git a/omod/src/main/java/org/openmrs/module/emrapi/rest/converter/InpatientAdmissionConverter.java b/omod/src/main/java/org/openmrs/module/emrapi/rest/converter/InpatientAdmissionConverter.java new file mode 100644 index 00000000..ef0db2af --- /dev/null +++ b/omod/src/main/java/org/openmrs/module/emrapi/rest/converter/InpatientAdmissionConverter.java @@ -0,0 +1,44 @@ +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; +import org.openmrs.module.webservices.rest.web.representation.DefaultRepresentation; +import org.openmrs.module.webservices.rest.web.representation.FullRepresentation; +import org.openmrs.module.webservices.rest.web.representation.Representation; +import org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceDescription; + +@Handler(supports = InpatientAdmission.class, order = 0) +public class InpatientAdmissionConverter extends SimpleBeanConverter { + + private final Log log = LogFactory.getLog(getClass()); + + @Override + public DelegatingResourceDescription getResourceDescription(InpatientAdmission req, Representation representation) { + DelegatingResourceDescription ret = super.getResourceDescription(req, representation); + if (representation instanceof DefaultRepresentation) { + DelegatingResourceDescription rep = new DelegatingResourceDescription(); + rep.addProperty("visit", Representation.DEFAULT); + rep.addProperty("currentInpatientLocation", Representation.REF); + rep.addProperty("firstAdmissionOrTransferEncounter", getEncounterRepresentation()); + rep.addProperty("latestAdmissionOrTransferEncounter", getEncounterRepresentation()); + rep.addProperty("encounterAssigningToCurrentInpatientLocation", getEncounterRepresentation()); + rep.addProperty("discharged"); + return rep; + } + else if (representation instanceof FullRepresentation) { + for (String property : ret.getProperties().keySet()) { + if (!property.equals("visit")) { + ret.addProperty(property, Representation.DEFAULT); + } + } + } + return ret; + } + + public Representation getEncounterRepresentation() { + return new CustomRepresentation("uuid,display,encounterDatetime,location:ref,encounterType:ref"); + } +} diff --git a/omod/src/main/java/org/openmrs/module/emrapi/web/controller/InpatientAdmissionController.java b/omod/src/main/java/org/openmrs/module/emrapi/web/controller/InpatientAdmissionController.java new file mode 100644 index 00000000..a8106c1d --- /dev/null +++ b/omod/src/main/java/org/openmrs/module/emrapi/web/controller/InpatientAdmissionController.java @@ -0,0 +1,47 @@ +package org.openmrs.module.emrapi.web.controller; + +import org.openmrs.Location; +import org.openmrs.module.emrapi.adt.AdtService; +import org.openmrs.module.emrapi.adt.InpatientAdmission; +import org.openmrs.module.emrapi.adt.InpatientAdmissionSearchCriteria; +import org.openmrs.module.emrapi.rest.converter.InpatientAdmissionConverter; +import org.openmrs.module.webservices.rest.SimpleObject; +import org.openmrs.module.webservices.rest.web.RequestContext; +import org.openmrs.module.webservices.rest.web.RestUtil; +import org.openmrs.module.webservices.rest.web.representation.Representation; +import org.openmrs.module.webservices.rest.web.resource.impl.NeedsPaging; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.util.List; + +@Controller +public class InpatientAdmissionController { + + @Autowired + private AdtService adtService; + + @RequestMapping(method = RequestMethod.GET, value = "/rest/**/emrapi/inpatient/admission") + @ResponseBody + public SimpleObject getInpatientAdmissions( + HttpServletRequest request, + HttpServletResponse response, + @RequestParam(required = false, value = "visitLocation") Location visitLocation, + @RequestParam(required = false, value = "currentInpatientLocation") List currentInpatientLocations, + @RequestParam(required = false, value = "includeDischarged") boolean includeDischarged + ) { + RequestContext context = RestUtil.getRequestContext(request, response, Representation.DEFAULT); + InpatientAdmissionSearchCriteria criteria = new InpatientAdmissionSearchCriteria(); + criteria.setVisitLocation(visitLocation); + criteria.setCurrentInpatientLocations(currentInpatientLocations); + criteria.setIncludeDischarged(includeDischarged); + List requests = adtService.getInpatientAdmissions(criteria); + return new NeedsPaging<>(requests, context).toSimpleObject(new InpatientAdmissionConverter()); + } +} diff --git a/omod/src/main/java/org/openmrs/module/emrapi/web/controller/InpatientVisitsController.java b/omod/src/main/java/org/openmrs/module/emrapi/web/controller/InpatientVisitsController.java index d4ddd4ce..7361560f 100644 --- a/omod/src/main/java/org/openmrs/module/emrapi/web/controller/InpatientVisitsController.java +++ b/omod/src/main/java/org/openmrs/module/emrapi/web/controller/InpatientVisitsController.java @@ -18,6 +18,7 @@ @Controller @RequestMapping(value = "/rest/**/emrapi/inpatient") +@Deprecated public class InpatientVisitsController { @Autowired