Skip to content

Commit

Permalink
RESTWS-950:Encounter Search Handler should support a visits parameter
Browse files Browse the repository at this point in the history
(post-merge fixes)
  • Loading branch information
mogoodrich committed Aug 8, 2024
1 parent a0c09b2 commit 1390386
Showing 1 changed file with 13 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
*/
package org.openmrs.module.webservices.rest.web.v1_0.search.openmrs2_0;

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

import org.openmrs.Encounter;
import org.openmrs.EncounterType;
Expand All @@ -29,7 +33,6 @@
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 All @@ -45,7 +48,7 @@ public class EncounterSearchHandler2_0 implements SearchHandler {
Collections.singletonList("2.0.* - 9.*"),
Collections.singletonList(new SearchQuery.Builder(
"Allows you to find Encounter by patient and encounterType (and optionally by from and to date range)")
.withRequiredParameters("patient").withOptionalParameters("encounterType", DATE_FROM, DATE_TO, "order")
.withRequiredParameters("patient").withOptionalParameters("visit", "encounterType", DATE_FROM, DATE_TO, "order")
.build()));

@Override
Expand All @@ -57,7 +60,7 @@ 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[] visitUuids = context.getRequest().getParameterValues("visit");

String dateFrom = context.getRequest().getParameter(DATE_FROM);
String dateTo = context.getRequest().getParameter(DATE_TO);
Expand All @@ -70,23 +73,20 @@ public PageableResult search(RequestContext context) throws ResponseException {
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()){
if (visitUuids != null && visitUuids.length > 0) {
List<Visit> visits = new ArrayList<>();
for (String visitUuid : visitUuids) {
visits.add(Context.getVisitService().getVisitByUuid(visitUuid));
}
encounterSearchCriteriaBuilder.setVisits(visits);
}

EncounterSearchCriteria encounterSearchCriteria = encounterSearchCriteriaBuilder.createEncounterSearchCriteria();

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

0 comments on commit 1390386

Please sign in to comment.