-
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-190 Add REST API for Inpatient Admissions
- Loading branch information
Showing
4 changed files
with
93 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
44 changes: 44 additions & 0 deletions
44
omod/src/main/java/org/openmrs/module/emrapi/rest/converter/InpatientAdmissionConverter.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,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"); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
.../src/main/java/org/openmrs/module/emrapi/web/controller/InpatientAdmissionController.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,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()); | ||
} | ||
} |
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