Skip to content

Commit

Permalink
Merge pull request #251 from openmrs/EA-208
Browse files Browse the repository at this point in the history
EA-208: Change Inpatient Admission and Inaptient Request endpoints to…
  • Loading branch information
chibongho authored Nov 2, 2024
2 parents 8b657bf + 44081cf commit 097e9b2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.openmrs.module.emrapi.web.controller;

import org.openmrs.Location;
import org.openmrs.Patient;
import org.openmrs.Visit;
import org.openmrs.module.emrapi.adt.AdtService;
import org.openmrs.module.emrapi.adt.InpatientAdmission;
import org.openmrs.module.emrapi.adt.InpatientAdmissionSearchCriteria;
Expand All @@ -20,6 +22,7 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.stream.Collectors;

@Controller
public class InpatientAdmissionController {
Expand All @@ -34,13 +37,23 @@ public SimpleObject getInpatientAdmissions(
HttpServletResponse response,
@RequestParam(required = false, value = "visitLocation") Location visitLocation,
@RequestParam(required = false, value = "currentInpatientLocation") List<Location> currentInpatientLocations,
@RequestParam(required = false, value = "includeDischarged") boolean includeDischarged
@RequestParam(required = false, value = "includeDischarged") boolean includeDischarged,
@RequestParam(required = false, value = "patients") List<Patient> patients,
@RequestParam(required = false, value = "visits") List<Visit> visits
) {
RequestContext context = RestUtil.getRequestContext(request, response, Representation.DEFAULT);
InpatientAdmissionSearchCriteria criteria = new InpatientAdmissionSearchCriteria();
criteria.setVisitLocation(visitLocation);
criteria.setCurrentInpatientLocations(currentInpatientLocations);
criteria.setIncludeDischarged(includeDischarged);

if(patients != null) {
criteria.setPatientIds(patients.stream().map(Patient::getId).collect(Collectors.toList()));
}

if(visits != null) {
criteria.setVisitIds(visits.stream().map(Visit::getId).collect(Collectors.toList()));
}
List<InpatientAdmission> requests = adtService.getInpatientAdmissions(criteria);
return new NeedsPaging<>(requests, context).toSimpleObject(new InpatientAdmissionConverter());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.openmrs.module.emrapi.web.controller;

import org.openmrs.Location;
import org.openmrs.Patient;
import org.openmrs.Visit;
import org.openmrs.module.emrapi.adt.AdtService;
import org.openmrs.module.emrapi.adt.InpatientRequest;
import org.openmrs.module.emrapi.adt.InpatientRequestSearchCriteria;
Expand All @@ -21,6 +23,7 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.stream.Collectors;

@Controller
public class InpatientRequestController {
Expand All @@ -35,13 +38,22 @@ public SimpleObject getInpatientRequests(
HttpServletResponse response,
@RequestParam(required = false, value = "visitLocation") Location visitLocation,
@RequestParam(required = false, value = "dispositionLocation") List<Location> dispositionLocations,
@RequestParam(required = false, value = "dispositionType") List<DispositionType> dispositionTypes
@RequestParam(required = false, value = "dispositionType") List<DispositionType> dispositionTypes,
@RequestParam(required = false, value = "patients") List<Patient> patients,
@RequestParam(required = false, value = "visits") List<Visit> visits
) {
RequestContext context = RestUtil.getRequestContext(request, response, Representation.DEFAULT);
InpatientRequestSearchCriteria criteria = new InpatientRequestSearchCriteria();
criteria.setVisitLocation(visitLocation);
criteria.setDispositionLocations(dispositionLocations);
criteria.setDispositionTypes(dispositionTypes);

if(patients != null) {
criteria.setPatientIds(patients.stream().map(Patient::getId).collect(Collectors.toList()));
}
if(visits != null) {
criteria.setVisitIds(visits.stream().map(Visit::getId).collect(Collectors.toList()));
}
List<InpatientRequest> requests = adtService.getInpatientRequests(criteria);
return new NeedsPaging<>(requests, context).toSimpleObject(new InpatientRequestConverter());
}
Expand Down

0 comments on commit 097e9b2

Please sign in to comment.