Skip to content

Commit

Permalink
RESTWS-950:Encounter search handler supporting visits parameter (#616)
Browse files Browse the repository at this point in the history
  • Loading branch information
sadamhussain-m authored Aug 8, 2024
1 parent a788bfa commit a0c09b2
Showing 1 changed file with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,12 @@
*/
package org.openmrs.module.webservices.rest.web.v1_0.search.openmrs2_0;

import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.*;

import org.openmrs.Encounter;
import org.openmrs.EncounterType;
import org.openmrs.Patient;
import org.openmrs.Visit;
import org.openmrs.api.context.Context;
import org.openmrs.module.webservices.rest.web.ConversionUtil;
import org.openmrs.module.webservices.rest.web.RequestContext;
Expand All @@ -31,6 +29,7 @@
import org.openmrs.module.webservices.rest.web.response.ResponseException;
import org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8.EncounterTypeResource1_8;
import org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8.PatientResource1_8;
import org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_9.VisitResource1_9;
import org.openmrs.parameter.EncounterSearchCriteria;
import org.openmrs.parameter.EncounterSearchCriteriaBuilder;
import org.springframework.stereotype.Component;
Expand Down Expand Up @@ -58,7 +57,8 @@ public SearchConfig getSearchConfig() {
public PageableResult search(RequestContext context) throws ResponseException {
String patientUuid = context.getRequest().getParameter("patient");
String encounterTypeUuid = context.getRequest().getParameter("encounterType");

String[] visitsUuid=context.getRequest().getParameter("visits").split(",");

String dateFrom = context.getRequest().getParameter(DATE_FROM);
String dateTo = context.getRequest().getParameter(DATE_TO);

Expand All @@ -69,13 +69,24 @@ public PageableResult search(RequestContext context) throws ResponseException {
Patient.class)).getByUniqueId(patientUuid);
EncounterType encounterType = ((EncounterTypeResource1_8) Context.getService(RestService.class)
.getResourceBySupportedClass(EncounterType.class)).getByUniqueId(encounterTypeUuid);

Collection<Visit> visits = new ArrayList<>();
if(visitsUuid.length>0) {

for (String uuid : visitsUuid) {
Visit visit = ((VisitResource1_9) Context.getService(RestService.class).getResourceBySupportedClass(Visit.class)).getByUniqueId(uuid);
visits.add(visit);
}
}
if (patient != null) {
EncounterSearchCriteriaBuilder encounterSearchCriteriaBuilder = new EncounterSearchCriteriaBuilder()
.setPatient(patient).setFromDate(fromDate).setToDate(toDate).setIncludeVoided(false);
if (encounterType != null) {
encounterSearchCriteriaBuilder.setEncounterTypes(Arrays.asList(encounterType));
}

if (!visits.isEmpty()){
encounterSearchCriteriaBuilder.setVisits(visits);
}
EncounterSearchCriteria encounterSearchCriteria = encounterSearchCriteriaBuilder.createEncounterSearchCriteria();

List<Encounter> encounters = Context.getEncounterService().getEncounters(encounterSearchCriteria);
Expand Down

0 comments on commit a0c09b2

Please sign in to comment.