Skip to content

Commit

Permalink
EA-190 Add REST API for Inpatient Admissions
Browse files Browse the repository at this point in the history
  • Loading branch information
mseaton committed Jul 22, 2024
1 parent 54225c9 commit 0a0804b
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public Encounter getEncounterAssigningToCurrentInpatientLocation() {
return ret;
}
}
return null;
return ret;
}

public boolean isDischarged() {
Expand Down
Original file line number Diff line number Diff line change
@@ -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<InpatientAdmission> {

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");
}
}
Original file line number Diff line number Diff line change
@@ -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<Location> 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<InpatientAdmission> requests = adtService.getInpatientAdmissions(criteria);
return new NeedsPaging<>(requests, context).toSimpleObject(new InpatientAdmissionConverter());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

@Controller
@RequestMapping(value = "/rest/**/emrapi/inpatient")
@Deprecated
public class InpatientVisitsController {

@Autowired
Expand Down

0 comments on commit 0a0804b

Please sign in to comment.