From c574d7cbdf8f2149b90753973f42c97434c203b6 Mon Sep 17 00:00:00 2001
From: md-at-slashwhy <95024503+md-at-slashwhy@users.noreply.github.com>
Date: Wed, 22 Nov 2023 14:56:46 +0100
Subject: [PATCH 1/9] FM2-347: add initial test cases
---
.../fhir2/api/FhirServiceRequestService.java | 3 +
.../impl/FhirServiceRequestServiceImpl.java | 5 ++
.../param/ServiceRequestSearchParams.java | 27 ++++++++
...ureRequestFhirResourceProviderWebTest.java | 62 +++++++++++++++++
...iceRequestFhirResourceProviderWebTest.java | 67 +++++++++++++++++++
5 files changed, 164 insertions(+)
create mode 100644 api/src/main/java/org/openmrs/module/fhir2/api/search/param/ServiceRequestSearchParams.java
diff --git a/api/src/main/java/org/openmrs/module/fhir2/api/FhirServiceRequestService.java b/api/src/main/java/org/openmrs/module/fhir2/api/FhirServiceRequestService.java
index c4fa4ad11c..00b2cd2ed2 100644
--- a/api/src/main/java/org/openmrs/module/fhir2/api/FhirServiceRequestService.java
+++ b/api/src/main/java/org/openmrs/module/fhir2/api/FhirServiceRequestService.java
@@ -17,10 +17,13 @@
import ca.uhn.fhir.rest.param.ReferenceAndListParam;
import ca.uhn.fhir.rest.param.TokenAndListParam;
import org.hl7.fhir.r4.model.ServiceRequest;
+import org.openmrs.module.fhir2.api.search.param.ServiceRequestSearchParams;
public interface FhirServiceRequestService extends FhirService {
IBundleProvider searchForServiceRequests(ReferenceAndListParam patientReference, TokenAndListParam code,
ReferenceAndListParam encounterReference, ReferenceAndListParam participantReference, DateRangeParam occurrence,
TokenAndListParam uuid, DateRangeParam lastUpdated, HashSet includes);
+
+ IBundleProvider searchForServiceRequests(ServiceRequestSearchParams serviceRequestSearchParams);
}
diff --git a/api/src/main/java/org/openmrs/module/fhir2/api/impl/FhirServiceRequestServiceImpl.java b/api/src/main/java/org/openmrs/module/fhir2/api/impl/FhirServiceRequestServiceImpl.java
index 2f810da2b2..2f780220c8 100644
--- a/api/src/main/java/org/openmrs/module/fhir2/api/impl/FhirServiceRequestServiceImpl.java
+++ b/api/src/main/java/org/openmrs/module/fhir2/api/impl/FhirServiceRequestServiceImpl.java
@@ -27,6 +27,7 @@
import org.openmrs.module.fhir2.api.search.SearchQuery;
import org.openmrs.module.fhir2.api.search.SearchQueryInclude;
import org.openmrs.module.fhir2.api.search.param.SearchParameterMap;
+import org.openmrs.module.fhir2.api.search.param.ServiceRequestSearchParams;
import org.openmrs.module.fhir2.api.translators.ServiceRequestTranslator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@@ -68,4 +69,8 @@ public IBundleProvider searchForServiceRequests(ReferenceAndListParam patientRef
return searchQuery.getQueryResults(theParams, dao, translator, searchQueryInclude);
}
+ @Override
+ public IBundleProvider searchForServiceRequests(ServiceRequestSearchParams serviceRequestSearchParams) {
+ return null;
+ }
}
diff --git a/api/src/main/java/org/openmrs/module/fhir2/api/search/param/ServiceRequestSearchParams.java b/api/src/main/java/org/openmrs/module/fhir2/api/search/param/ServiceRequestSearchParams.java
new file mode 100644
index 0000000000..85e221f995
--- /dev/null
+++ b/api/src/main/java/org/openmrs/module/fhir2/api/search/param/ServiceRequestSearchParams.java
@@ -0,0 +1,27 @@
+/*
+ * This Source Code Form is subject to the terms of the Mozilla Public License,
+ * v. 2.0. If a copy of the MPL was not distributed with this file, You can
+ * obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under
+ * the terms of the Healthcare Disclaimer located at http://openmrs.org/license.
+ *
+ * Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS
+ * graphic logo is a trademark of OpenMRS Inc.
+ */
+package org.openmrs.module.fhir2.api.search.param;
+
+import java.io.Serializable;
+
+import ca.uhn.fhir.rest.param.HasAndListParam;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
+public class ServiceRequestSearchParams implements Serializable {
+
+ private HasAndListParam hasAndListParam;
+}
diff --git a/omod/src/test/java/org/openmrs/module/fhir2/providers/r3/ProcedureRequestFhirResourceProviderWebTest.java b/omod/src/test/java/org/openmrs/module/fhir2/providers/r3/ProcedureRequestFhirResourceProviderWebTest.java
index fd5e61159c..c74ed2795f 100644
--- a/omod/src/test/java/org/openmrs/module/fhir2/providers/r3/ProcedureRequestFhirResourceProviderWebTest.java
+++ b/omod/src/test/java/org/openmrs/module/fhir2/providers/r3/ProcedureRequestFhirResourceProviderWebTest.java
@@ -49,6 +49,7 @@
import org.mockito.junit.MockitoJUnitRunner;
import org.openmrs.module.fhir2.FhirConstants;
import org.openmrs.module.fhir2.api.FhirServiceRequestService;
+import org.openmrs.module.fhir2.api.search.param.ServiceRequestSearchParams;
import org.springframework.mock.web.MockHttpServletResponse;
@RunWith(MockitoJUnitRunner.class)
@@ -107,6 +108,9 @@ public class ProcedureRequestFhirResourceProviderWebTest extends BaseFhirR3Resou
@Captor
private ArgumentCaptor> includeArgumentCaptor;
+
+ @Captor
+ private ArgumentCaptor serviceRequestSearchParamsArgumentCaptor;
@Before
@Override
@@ -566,6 +570,64 @@ public void searchForServiceRequests_shouldHandleMultipleIncludes() throws Excep
hasItem(allOf(hasProperty("paramName", equalTo(FhirConstants.INCLUDE_PATIENT_PARAM)),
hasProperty("paramType", equalTo(FhirConstants.PROCEDURE_REQUEST)))));
}
+
+ @Test
+ public void searchForServiceRequests_shouldHandleHasAndListParameter() throws Exception {
+ verifyUri("/ServiceRequest?_has:Observation:based-on:category:not=laboratory");
+
+ verify(service).searchForServiceRequests(serviceRequestSearchParamsArgumentCaptor.capture());
+
+ HasAndListParam hasAndListParam = serviceRequestSearchParamsArgumentCaptor.getValue().getHasAndListParam();
+ assertThat(hasAndListParam, notNullValue());
+ assertThat(hasAndListParam.size(), equalTo(1));
+
+ List hasOrListParams = hasAndListParam.getValuesAsQueryTokens();
+ assertThat(hasOrListParams.size(), equalTo(1));
+
+ List valuesFound = new ArrayList<>();
+
+ for (HasOrListParam hasOrListParam : hasOrListParams) {
+ hasOrListParam.getValuesAsQueryTokens().forEach(hasParam -> {
+ assertThat(hasParam.getTargetResourceType(), equalTo(FhirConstants.OBSERVATION));
+ assertThat(hasParam.getReferenceFieldName(), equalTo("based-on"));
+ valuesFound.add(hasParam.getParameterName() + "=" + hasParam.getParameterValue());
+ });
+ }
+ Collections.sort(valuesFound);
+
+ assertThat(valuesFound.size(), equalTo(1));
+ assertThat(valuesFound.get(0), equalTo("category != laboratory"));
+ }
+
+ @Test
+ @Ignore
+ public void shouldHandleHasAndListParameterWithColonNotAfterParameterName() throws Exception {
+ verifyUri("/ServiceRequest?_has:Observation:based-on:category:not=laboratory");
+
+ verify(service).searchForServiceRequests(serviceRequestSearchParamsArgumentCaptor.capture());
+
+ /*
+ * TODO:
+ * The [HL7 documentation](https://www.hl7.org/fhir/search.html#has) discourages this use-case.
+ * Implementation of verification is pending confirmation to act against this recommendation.
+ */
+
+ }
+
+ @Test
+ @Ignore
+ public void shouldHandleHasAndListParameterWithColonNotAfterParameterNameAndNoValue() throws Exception {
+ verifyUri("/ServiceRequest?_has:Observation:based-on:not");
+
+ verify(service).searchForServiceRequests(serviceRequestSearchParamsArgumentCaptor.capture());
+
+ /*
+ * TODO:
+ * The [HL7 documentation](https://www.hl7.org/fhir/search.html#has) discourages this use-case.
+ * Implementation of verification is pending confirmation to act against this recommendation.
+ */
+
+ }
private void verifyUri(String uri) throws Exception {
ProcedureRequest procedureRequest = new ProcedureRequest();
diff --git a/omod/src/test/java/org/openmrs/module/fhir2/providers/r4/ServiceRequestFhirResourceProviderWebTest.java b/omod/src/test/java/org/openmrs/module/fhir2/providers/r4/ServiceRequestFhirResourceProviderWebTest.java
index 8d00dea451..f40685c236 100644
--- a/omod/src/test/java/org/openmrs/module/fhir2/providers/r4/ServiceRequestFhirResourceProviderWebTest.java
+++ b/omod/src/test/java/org/openmrs/module/fhir2/providers/r4/ServiceRequestFhirResourceProviderWebTest.java
@@ -24,12 +24,16 @@
import javax.servlet.ServletException;
+import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.HashSet;
+import java.util.List;
import ca.uhn.fhir.model.api.Include;
import ca.uhn.fhir.rest.param.DateRangeParam;
+import ca.uhn.fhir.rest.param.HasAndListParam;
+import ca.uhn.fhir.rest.param.HasOrListParam;
import ca.uhn.fhir.rest.param.ReferenceAndListParam;
import ca.uhn.fhir.rest.param.TokenAndListParam;
import lombok.AccessLevel;
@@ -40,6 +44,7 @@
import org.hl7.fhir.r4.model.Practitioner;
import org.hl7.fhir.r4.model.ServiceRequest;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
@@ -48,6 +53,7 @@
import org.mockito.junit.MockitoJUnitRunner;
import org.openmrs.module.fhir2.FhirConstants;
import org.openmrs.module.fhir2.api.FhirServiceRequestService;
+import org.openmrs.module.fhir2.api.search.param.ServiceRequestSearchParams;
import org.springframework.mock.web.MockHttpServletResponse;
@RunWith(MockitoJUnitRunner.class)
@@ -99,6 +105,9 @@ public class ServiceRequestFhirResourceProviderWebTest extends BaseFhirR4Resourc
@Captor
private ArgumentCaptor> includeArgumentCaptor;
+ @Captor
+ private ArgumentCaptor paramCaptor;
+
private ServiceRequest serviceRequest;
private static final String JSON_CREATE_SERVICE_REQUEST_PATH = "org/openmrs/module/fhir2/providers/ServiceRequestWebTest_create.json";
@@ -567,6 +576,64 @@ public void searchForServiceRequests_shouldHandleMultipleIncludes() throws Excep
hasItem(allOf(hasProperty("paramName", equalTo(FhirConstants.INCLUDE_PATIENT_PARAM)),
hasProperty("paramType", equalTo(FhirConstants.SERVICE_REQUEST)))));
}
+
+ @Test
+ public void searchForServiceRequests_shouldHandleHasAndListParameter() throws Exception {
+ verifyUri("/ServiceRequest?_has:Observation:based-on:category:not=laboratory");
+
+ verify(service).searchForServiceRequests(serviceRequestSearchParamsArgumentCaptor.capture());
+
+ HasAndListParam hasAndListParam = serviceRequestSearchParamsArgumentCaptor.getValue().getHasAndListParam();
+ assertThat(hasAndListParam, notNullValue());
+ assertThat(hasAndListParam.size(), equalTo(1));
+
+ List hasOrListParams = hasAndListParam.getValuesAsQueryTokens();
+ assertThat(hasOrListParams.size(), equalTo(1));
+
+ List valuesFound = new ArrayList<>();
+
+ for (HasOrListParam hasOrListParam : hasOrListParams) {
+ hasOrListParam.getValuesAsQueryTokens().forEach(hasParam -> {
+ assertThat(hasParam.getTargetResourceType(), equalTo(FhirConstants.OBSERVATION));
+ assertThat(hasParam.getReferenceFieldName(), equalTo("based-on"));
+ valuesFound.add(hasParam.getParameterName() + "=" + hasParam.getParameterValue());
+ });
+ }
+ Collections.sort(valuesFound);
+
+ assertThat(valuesFound.size(), equalTo(1));
+ assertThat(valuesFound.get(0), equalTo("category != laboratory"));
+ }
+
+ @Test
+ @Ignore
+ public void searchForServiceRequests_shouldHandleHasAndListParameterWithColonNotAfterParameterName() throws Exception {
+ verifyUri("/ServiceRequest?_has:Observation:based-on:category:not=laboratory");
+
+ verify(service).searchForServiceRequests(serviceRequestSearchParamsArgumentCaptor.capture());
+
+ /*
+ * TODO:
+ * The [HL7 documentation](https://www.hl7.org/fhir/search.html#has) discourages this use-case.
+ * Implementation of verification is pending confirmation to act against this recommendation.
+ */
+
+ }
+
+ @Test
+ @Ignore
+ public void searchForServiceRequests_shouldHandleHasAndListParameterWithColonNotAfterParameterNameAndNoValue() throws Exception {
+ verifyUri("/ServiceRequest?_has:Observation:based-on:not");
+
+ verify(service).searchForServiceRequests(serviceRequestSearchParamsArgumentCaptor.capture());
+
+ /*
+ * TODO:
+ * The [HL7 documentation](https://www.hl7.org/fhir/search.html#has) discourages this use-case.
+ * Implementation of verification is pending confirmation to act against this recommendation.
+ */
+
+ }
private void verifyUri(String uri) throws Exception {
when(service.searchForServiceRequests(any(), any(), any(), any(), any(), any(), any(), any()))
From a02565f9118f0bfbcbc442450ceea85541645492 Mon Sep 17 00:00:00 2001
From: md-at-slashwhy <95024503+md-at-slashwhy@users.noreply.github.com>
Date: Wed, 22 Nov 2023 14:56:46 +0100
Subject: [PATCH 2/9] FM2-347: Refactor FhirServiceRequestService to take a
single bean as argument
---
.../fhir2/api/FhirServiceRequestService.java | 11 +-
.../dao/impl/FhirServiceRequestDaoImpl.java | 3 +
.../impl/FhirServiceRequestServiceImpl.java | 38 +-
.../fhir2/api/search/SearchQueryInclude.java | 13 +-
.../param/ServiceRequestSearchParams.java | 22 +
.../ProcedureRequestFhirResourceProvider.java | 6 +-
.../ServiceRequestFhirResourceProvider.java | 5 +-
.../FhirServiceRequestServiceImplTest.java | 51 ++-
...cedureRequestFhirResourceProviderTest.java | 57 ++-
...erviceRequestFhirResourceProviderTest.java | 57 ++-
...ureRequestFhirResourceProviderWebTest.java | 422 ++++++++---------
...iceRequestFhirResourceProviderWebTest.java | 424 ++++++++----------
12 files changed, 530 insertions(+), 579 deletions(-)
diff --git a/api/src/main/java/org/openmrs/module/fhir2/api/FhirServiceRequestService.java b/api/src/main/java/org/openmrs/module/fhir2/api/FhirServiceRequestService.java
index 00b2cd2ed2..8fc741a57f 100644
--- a/api/src/main/java/org/openmrs/module/fhir2/api/FhirServiceRequestService.java
+++ b/api/src/main/java/org/openmrs/module/fhir2/api/FhirServiceRequestService.java
@@ -9,21 +9,12 @@
*/
package org.openmrs.module.fhir2.api;
-import java.util.HashSet;
-
-import ca.uhn.fhir.model.api.Include;
import ca.uhn.fhir.rest.api.server.IBundleProvider;
-import ca.uhn.fhir.rest.param.DateRangeParam;
-import ca.uhn.fhir.rest.param.ReferenceAndListParam;
-import ca.uhn.fhir.rest.param.TokenAndListParam;
import org.hl7.fhir.r4.model.ServiceRequest;
import org.openmrs.module.fhir2.api.search.param.ServiceRequestSearchParams;
public interface FhirServiceRequestService extends FhirService {
- IBundleProvider searchForServiceRequests(ReferenceAndListParam patientReference, TokenAndListParam code,
- ReferenceAndListParam encounterReference, ReferenceAndListParam participantReference, DateRangeParam occurrence,
- TokenAndListParam uuid, DateRangeParam lastUpdated, HashSet includes);
-
IBundleProvider searchForServiceRequests(ServiceRequestSearchParams serviceRequestSearchParams);
+
}
diff --git a/api/src/main/java/org/openmrs/module/fhir2/api/dao/impl/FhirServiceRequestDaoImpl.java b/api/src/main/java/org/openmrs/module/fhir2/api/dao/impl/FhirServiceRequestDaoImpl.java
index b97f5605f4..3262e476e3 100644
--- a/api/src/main/java/org/openmrs/module/fhir2/api/dao/impl/FhirServiceRequestDaoImpl.java
+++ b/api/src/main/java/org/openmrs/module/fhir2/api/dao/impl/FhirServiceRequestDaoImpl.java
@@ -45,6 +45,9 @@ protected void setupSearchParams(Criteria criteria, SearchParameterMap theParams
entry.getValue().forEach(
param -> handleEncounterReference(criteria, (ReferenceAndListParam) param.getParam(), "e"));
break;
+ case FhirConstants.HAS_SEARCH_HANDLER:
+ // TODO: add implementation of the has search. stub is required for other tests not to fail
+ break;
case FhirConstants.PATIENT_REFERENCE_SEARCH_HANDLER:
entry.getValue().forEach(patientReference -> handlePatientReference(criteria,
(ReferenceAndListParam) patientReference.getParam(), "patient"));
diff --git a/api/src/main/java/org/openmrs/module/fhir2/api/impl/FhirServiceRequestServiceImpl.java b/api/src/main/java/org/openmrs/module/fhir2/api/impl/FhirServiceRequestServiceImpl.java
index 2f780220c8..824f26bbc7 100644
--- a/api/src/main/java/org/openmrs/module/fhir2/api/impl/FhirServiceRequestServiceImpl.java
+++ b/api/src/main/java/org/openmrs/module/fhir2/api/impl/FhirServiceRequestServiceImpl.java
@@ -9,13 +9,7 @@
*/
package org.openmrs.module.fhir2.api.impl;
-import java.util.HashSet;
-
-import ca.uhn.fhir.model.api.Include;
import ca.uhn.fhir.rest.api.server.IBundleProvider;
-import ca.uhn.fhir.rest.param.DateRangeParam;
-import ca.uhn.fhir.rest.param.ReferenceAndListParam;
-import ca.uhn.fhir.rest.param.TokenAndListParam;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.Setter;
@@ -52,25 +46,23 @@ public class FhirServiceRequestServiceImpl extends BaseFhirService, ServiceRequestTranslator, SearchQueryInclude> searchQuery;
@Override
- public IBundleProvider searchForServiceRequests(ReferenceAndListParam patientReference, TokenAndListParam code,
- ReferenceAndListParam encounterReference, ReferenceAndListParam participantReference, DateRangeParam occurrence,
- TokenAndListParam uuid, DateRangeParam lastUpdated, HashSet includes) {
-
+ public IBundleProvider searchForServiceRequests(ServiceRequestSearchParams serviceRequestSearchParams) {
SearchParameterMap theParams = new SearchParameterMap()
- .addParameter(FhirConstants.PATIENT_REFERENCE_SEARCH_HANDLER, patientReference)
- .addParameter(FhirConstants.CODED_SEARCH_HANDLER, code)
- .addParameter(FhirConstants.ENCOUNTER_REFERENCE_SEARCH_HANDLER, encounterReference)
- .addParameter(FhirConstants.PARTICIPANT_REFERENCE_SEARCH_HANDLER, participantReference)
- .addParameter(FhirConstants.DATE_RANGE_SEARCH_HANDLER, occurrence)
- .addParameter(FhirConstants.COMMON_SEARCH_HANDLER, FhirConstants.ID_PROPERTY, uuid)
- .addParameter(FhirConstants.COMMON_SEARCH_HANDLER, FhirConstants.LAST_UPDATED_PROPERTY, lastUpdated)
- .addParameter(FhirConstants.INCLUDE_SEARCH_HANDLER, includes);
+ .addParameter(FhirConstants.PATIENT_REFERENCE_SEARCH_HANDLER,
+ serviceRequestSearchParams.getPatientReference())
+ .addParameter(FhirConstants.CODED_SEARCH_HANDLER, serviceRequestSearchParams.getCode())
+ .addParameter(FhirConstants.ENCOUNTER_REFERENCE_SEARCH_HANDLER,
+ serviceRequestSearchParams.getEncounterReference())
+ .addParameter(FhirConstants.PARTICIPANT_REFERENCE_SEARCH_HANDLER,
+ serviceRequestSearchParams.getParticipantReference())
+ .addParameter(FhirConstants.DATE_RANGE_SEARCH_HANDLER, serviceRequestSearchParams.getOccurrence())
+ .addParameter(FhirConstants.COMMON_SEARCH_HANDLER, FhirConstants.ID_PROPERTY,
+ serviceRequestSearchParams.getUuid())
+ .addParameter(FhirConstants.COMMON_SEARCH_HANDLER, FhirConstants.LAST_UPDATED_PROPERTY,
+ serviceRequestSearchParams.getLastUpdated())
+ .addParameter(FhirConstants.INCLUDE_SEARCH_HANDLER, serviceRequestSearchParams.getIncludes())
+ .addParameter(FhirConstants.HAS_SEARCH_HANDLER, serviceRequestSearchParams.getHasAndListParam());
return searchQuery.getQueryResults(theParams, dao, translator, searchQueryInclude);
}
-
- @Override
- public IBundleProvider searchForServiceRequests(ServiceRequestSearchParams serviceRequestSearchParams) {
- return null;
- }
}
diff --git a/api/src/main/java/org/openmrs/module/fhir2/api/search/SearchQueryInclude.java b/api/src/main/java/org/openmrs/module/fhir2/api/search/SearchQueryInclude.java
index cbd9d9b34c..e2415817d3 100644
--- a/api/src/main/java/org/openmrs/module/fhir2/api/search/SearchQueryInclude.java
+++ b/api/src/main/java/org/openmrs/module/fhir2/api/search/SearchQueryInclude.java
@@ -58,6 +58,7 @@
import org.openmrs.module.fhir2.api.search.param.ObservationSearchParams;
import org.openmrs.module.fhir2.api.search.param.PropParam;
import org.openmrs.module.fhir2.api.search.param.SearchParameterMap;
+import org.openmrs.module.fhir2.api.search.param.ServiceRequestSearchParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@@ -277,7 +278,9 @@ private IBundleProvider handlePractitionerReverseInclude(ReferenceAndListParam p
null, params, null, null, null, null, null, recursiveIncludes, recursiveRevIncludes));
case FhirConstants.PROCEDURE_REQUEST:
case FhirConstants.SERVICE_REQUEST:
- return serviceRequestService.searchForServiceRequests(null, null, null, params, null, null, null, null);
+ ServiceRequestSearchParams serviceRequestSearchParams = new ServiceRequestSearchParams();
+ serviceRequestSearchParams.setParticipantReference(params);
+ return serviceRequestService.searchForServiceRequests(serviceRequestSearchParams);
}
return null;
@@ -297,7 +300,9 @@ private IBundleProvider handleEncounterReverseInclude(ReferenceAndListParam para
.encounterReference(params).includes(recursiveIncludes).revIncludes(recursiveRevIncludes).build());
case FhirConstants.PROCEDURE_REQUEST:
case FhirConstants.SERVICE_REQUEST:
- return serviceRequestService.searchForServiceRequests(null, null, params, null, null, null, null, null);
+ ServiceRequestSearchParams serviceRequestSearchParams = new ServiceRequestSearchParams();
+ serviceRequestSearchParams.setEncounterReference(params);
+ return serviceRequestService.searchForServiceRequests(serviceRequestSearchParams);
}
return null;
@@ -346,7 +351,9 @@ private IBundleProvider handlePatientReverseInclude(ReferenceAndListParam params
null, null, null, null, null, null, null, recursiveIncludes, recursiveRevIncludes));
case FhirConstants.SERVICE_REQUEST:
case FhirConstants.PROCEDURE_REQUEST:
- return serviceRequestService.searchForServiceRequests(params, null, null, null, null, null, null, null);
+ ServiceRequestSearchParams serviceRequestSearchParams = new ServiceRequestSearchParams();
+ serviceRequestSearchParams.setPatientReference(params);
+ return serviceRequestService.searchForServiceRequests(serviceRequestSearchParams);
}
return null;
diff --git a/api/src/main/java/org/openmrs/module/fhir2/api/search/param/ServiceRequestSearchParams.java b/api/src/main/java/org/openmrs/module/fhir2/api/search/param/ServiceRequestSearchParams.java
index 85e221f995..ee44099aa6 100644
--- a/api/src/main/java/org/openmrs/module/fhir2/api/search/param/ServiceRequestSearchParams.java
+++ b/api/src/main/java/org/openmrs/module/fhir2/api/search/param/ServiceRequestSearchParams.java
@@ -7,11 +7,17 @@
* Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS
* graphic logo is a trademark of OpenMRS Inc.
*/
+
package org.openmrs.module.fhir2.api.search.param;
import java.io.Serializable;
+import java.util.HashSet;
+import ca.uhn.fhir.model.api.Include;
+import ca.uhn.fhir.rest.param.DateRangeParam;
import ca.uhn.fhir.rest.param.HasAndListParam;
+import ca.uhn.fhir.rest.param.ReferenceAndListParam;
+import ca.uhn.fhir.rest.param.TokenAndListParam;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
@@ -23,5 +29,21 @@
@Builder
public class ServiceRequestSearchParams implements Serializable {
+ private ReferenceAndListParam patientReference;
+
+ private TokenAndListParam code;
+
+ private ReferenceAndListParam encounterReference;
+
+ private ReferenceAndListParam participantReference;
+
+ private DateRangeParam occurrence;
+
+ private TokenAndListParam uuid;
+
+ private DateRangeParam lastUpdated;
+
+ private HashSet includes;
+
private HasAndListParam hasAndListParam;
}
diff --git a/api/src/main/java/org/openmrs/module/fhir2/providers/r3/ProcedureRequestFhirResourceProvider.java b/api/src/main/java/org/openmrs/module/fhir2/providers/r3/ProcedureRequestFhirResourceProvider.java
index 6e51e4dc40..9bba6ce9cc 100644
--- a/api/src/main/java/org/openmrs/module/fhir2/providers/r3/ProcedureRequestFhirResourceProvider.java
+++ b/api/src/main/java/org/openmrs/module/fhir2/providers/r3/ProcedureRequestFhirResourceProvider.java
@@ -44,6 +44,7 @@
import org.openmrs.module.fhir2.api.FhirServiceRequestService;
import org.openmrs.module.fhir2.api.annotations.R3Provider;
import org.openmrs.module.fhir2.api.search.SearchQueryBundleProviderR3Wrapper;
+import org.openmrs.module.fhir2.api.search.param.ServiceRequestSearchParams;
import org.openmrs.module.fhir2.providers.util.FhirProviderUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@@ -120,7 +121,8 @@ public IBundleProvider searchForProcedureRequests(
includes = null;
}
- return new SearchQueryBundleProviderR3Wrapper(serviceRequestService.searchForServiceRequests(patientReference, code,
- encounterReference, participantReference, occurrence, uuid, lastUpdated, includes));
+ return new SearchQueryBundleProviderR3Wrapper(
+ serviceRequestService.searchForServiceRequests(new ServiceRequestSearchParams(patientReference, code,
+ encounterReference, participantReference, occurrence, uuid, lastUpdated, includes, null)));
}
}
diff --git a/api/src/main/java/org/openmrs/module/fhir2/providers/r4/ServiceRequestFhirResourceProvider.java b/api/src/main/java/org/openmrs/module/fhir2/providers/r4/ServiceRequestFhirResourceProvider.java
index 65096110c7..14908c7aa8 100644
--- a/api/src/main/java/org/openmrs/module/fhir2/providers/r4/ServiceRequestFhirResourceProvider.java
+++ b/api/src/main/java/org/openmrs/module/fhir2/providers/r4/ServiceRequestFhirResourceProvider.java
@@ -41,6 +41,7 @@
import org.hl7.fhir.r4.model.ServiceRequest;
import org.openmrs.module.fhir2.api.FhirServiceRequestService;
import org.openmrs.module.fhir2.api.annotations.R4Provider;
+import org.openmrs.module.fhir2.api.search.param.ServiceRequestSearchParams;
import org.openmrs.module.fhir2.providers.util.FhirProviderUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@@ -119,7 +120,7 @@ public IBundleProvider searchForServiceRequests(
includes = null;
}
- return serviceRequestService.searchForServiceRequests(patientReference, code, encounterReference,
- participantReference, occurrence, uuid, lastUpdated, includes);
+ return serviceRequestService.searchForServiceRequests(new ServiceRequestSearchParams(patientReference, code,
+ encounterReference, participantReference, occurrence, uuid, lastUpdated, includes, null));
}
}
diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/impl/FhirServiceRequestServiceImplTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/impl/FhirServiceRequestServiceImplTest.java
index 2cdaa81e43..a4d4d0caab 100644
--- a/api/src/test/java/org/openmrs/module/fhir2/api/impl/FhirServiceRequestServiceImplTest.java
+++ b/api/src/test/java/org/openmrs/module/fhir2/api/impl/FhirServiceRequestServiceImplTest.java
@@ -58,6 +58,7 @@
import org.openmrs.module.fhir2.api.search.SearchQueryBundleProvider;
import org.openmrs.module.fhir2.api.search.SearchQueryInclude;
import org.openmrs.module.fhir2.api.search.param.SearchParameterMap;
+import org.openmrs.module.fhir2.api.search.param.ServiceRequestSearchParams;
import org.openmrs.module.fhir2.api.translators.ServiceRequestTranslator;
@RunWith(MockitoJUnitRunner.class)
@@ -146,6 +147,8 @@ public void shouldRetrieveServiceRequestByUUID() {
public void searchForServiceRequest_shouldReturnCollectionOfServiceRequestByPatientParam() {
ReferenceAndListParam patientReference = new ReferenceAndListParam().addAnd(
new ReferenceOrListParam().add(new ReferenceParam().setValue(PATIENT_GIVEN_NAME).setChain(SP_GIVEN)));
+ ServiceRequestSearchParams serviceRequestSearchParams = new ServiceRequestSearchParams();
+ serviceRequestSearchParams.setPatientReference(patientReference);
SearchParameterMap theParams = new SearchParameterMap();
theParams.addParameter(PATIENT_REFERENCE_SEARCH_HANDLER, patientReference);
@@ -156,8 +159,7 @@ public void searchForServiceRequest_shouldReturnCollectionOfServiceRequestByPati
new SearchQueryBundleProvider<>(theParams, dao, translator, globalPropertyService, searchQueryInclude));
when(searchQueryInclude.getIncludedResources(any(), any())).thenReturn(Collections.emptySet());
- IBundleProvider results = serviceRequestService.searchForServiceRequests(patientReference, null, null, null, null,
- null, null, null);
+ IBundleProvider results = serviceRequestService.searchForServiceRequests(serviceRequestSearchParams);
List resultList = get(results);
@@ -169,6 +171,8 @@ public void searchForServiceRequest_shouldReturnCollectionOfServiceRequestByPati
@Test
public void searchForServiceRequest_shouldReturnCollectionOfServiceRequestByCode() {
TokenAndListParam code = new TokenAndListParam().addAnd(new TokenParam(CODE));
+ ServiceRequestSearchParams serviceRequestSearchParams = new ServiceRequestSearchParams();
+ serviceRequestSearchParams.setCode(code);
SearchParameterMap theParams = new SearchParameterMap();
theParams.addParameter(CODED_SEARCH_HANDLER, code);
@@ -179,8 +183,7 @@ public void searchForServiceRequest_shouldReturnCollectionOfServiceRequestByCode
new SearchQueryBundleProvider<>(theParams, dao, translator, globalPropertyService, searchQueryInclude));
when(searchQueryInclude.getIncludedResources(any(), any())).thenReturn(Collections.emptySet());
- IBundleProvider results = serviceRequestService.searchForServiceRequests(null, code, null, null, null, null, null,
- null);
+ IBundleProvider results = serviceRequestService.searchForServiceRequests(serviceRequestSearchParams);
List resultList = get(results);
@@ -193,6 +196,8 @@ public void searchForServiceRequest_shouldReturnCollectionOfServiceRequestByCode
public void searchForServiceRequest_shouldReturnCollectionOfServiceRequestByEncounter() {
ReferenceAndListParam encounterReference = new ReferenceAndListParam()
.addAnd(new ReferenceOrListParam().add(new ReferenceParam().setValue(ENCOUNTER_UUID).setChain(null)));
+ ServiceRequestSearchParams serviceRequestSearchParams = new ServiceRequestSearchParams();
+ serviceRequestSearchParams.setEncounterReference(encounterReference);
SearchParameterMap theParams = new SearchParameterMap();
theParams.addParameter(ENCOUNTER_REFERENCE_SEARCH_HANDLER, encounterReference);
@@ -203,8 +208,7 @@ public void searchForServiceRequest_shouldReturnCollectionOfServiceRequestByEnco
new SearchQueryBundleProvider<>(theParams, dao, translator, globalPropertyService, searchQueryInclude));
when(searchQueryInclude.getIncludedResources(any(), any())).thenReturn(Collections.emptySet());
- IBundleProvider results = serviceRequestService.searchForServiceRequests(null, null, encounterReference, null, null,
- null, null, null);
+ IBundleProvider results = serviceRequestService.searchForServiceRequests(serviceRequestSearchParams);
List resultList = get(results);
@@ -217,6 +221,8 @@ public void searchForServiceRequest_shouldReturnCollectionOfServiceRequestByEnco
public void searchForServiceRequest_shouldReturnCollectionOfServiceRequestByRequester() {
ReferenceAndListParam participantReference = new ReferenceAndListParam().addAnd(
new ReferenceOrListParam().add(new ReferenceParam().setValue(PARTICIPANT_IDENTIFIER).setChain(SP_IDENTIFIER)));
+ ServiceRequestSearchParams serviceRequestSearchParams = new ServiceRequestSearchParams();
+ serviceRequestSearchParams.setParticipantReference(participantReference);
SearchParameterMap theParams = new SearchParameterMap();
theParams.addParameter(PARTICIPANT_REFERENCE_SEARCH_HANDLER, participantReference);
@@ -227,8 +233,7 @@ public void searchForServiceRequest_shouldReturnCollectionOfServiceRequestByRequ
new SearchQueryBundleProvider<>(theParams, dao, translator, globalPropertyService, searchQueryInclude));
when(searchQueryInclude.getIncludedResources(any(), any())).thenReturn(Collections.emptySet());
- IBundleProvider results = serviceRequestService.searchForServiceRequests(null, null, null, participantReference,
- null, null, null, null);
+ IBundleProvider results = serviceRequestService.searchForServiceRequests(serviceRequestSearchParams);
List resultList = get(results);
@@ -240,6 +245,8 @@ public void searchForServiceRequest_shouldReturnCollectionOfServiceRequestByRequ
@Test
public void searchForServiceRequest_shouldReturnCollectionOfServiceRequestByOccurrence() {
DateRangeParam occurrence = new DateRangeParam().setLowerBound(OCCURRENCE).setUpperBound(OCCURRENCE);
+ ServiceRequestSearchParams serviceRequestSearchParams = new ServiceRequestSearchParams();
+ serviceRequestSearchParams.setOccurrence(occurrence);
SearchParameterMap theParams = new SearchParameterMap();
theParams.addParameter(DATE_RANGE_SEARCH_HANDLER, occurrence);
@@ -250,8 +257,7 @@ public void searchForServiceRequest_shouldReturnCollectionOfServiceRequestByOccu
new SearchQueryBundleProvider<>(theParams, dao, translator, globalPropertyService, searchQueryInclude));
when(searchQueryInclude.getIncludedResources(any(), any())).thenReturn(Collections.emptySet());
- IBundleProvider results = serviceRequestService.searchForServiceRequests(null, null, null, null, occurrence, null,
- null, null);
+ IBundleProvider results = serviceRequestService.searchForServiceRequests(serviceRequestSearchParams);
List resultList = get(results);
@@ -263,6 +269,8 @@ public void searchForServiceRequest_shouldReturnCollectionOfServiceRequestByOccu
@Test
public void searchForServiceRequest_shouldReturnCollectionOfServiceRequestByUUID() {
TokenAndListParam uuid = new TokenAndListParam().addAnd(new TokenParam(SERVICE_REQUEST_UUID));
+ ServiceRequestSearchParams serviceRequestSearchParams = new ServiceRequestSearchParams();
+ serviceRequestSearchParams.setUuid(uuid);
SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.COMMON_SEARCH_HANDLER,
FhirConstants.ID_PROPERTY, uuid);
@@ -273,8 +281,7 @@ public void searchForServiceRequest_shouldReturnCollectionOfServiceRequestByUUID
new SearchQueryBundleProvider<>(theParams, dao, translator, globalPropertyService, searchQueryInclude));
when(searchQueryInclude.getIncludedResources(any(), any())).thenReturn(Collections.emptySet());
- IBundleProvider results = serviceRequestService.searchForServiceRequests(null, null, null, null, null, uuid, null,
- null);
+ IBundleProvider results = serviceRequestService.searchForServiceRequests(serviceRequestSearchParams);
List resultList = get(results);
@@ -286,6 +293,8 @@ public void searchForServiceRequest_shouldReturnCollectionOfServiceRequestByUUID
@Test
public void searchForServiceRequest_shouldReturnCollectionOfServiceRequestByLastUpdated() {
DateRangeParam lastUpdated = new DateRangeParam().setUpperBound(LAST_UPDATED_DATE).setLowerBound(LAST_UPDATED_DATE);
+ ServiceRequestSearchParams serviceRequestSearchParams = new ServiceRequestSearchParams();
+ serviceRequestSearchParams.setLastUpdated(lastUpdated);
SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.COMMON_SEARCH_HANDLER,
FhirConstants.LAST_UPDATED_PROPERTY, lastUpdated);
@@ -296,8 +305,7 @@ public void searchForServiceRequest_shouldReturnCollectionOfServiceRequestByLast
new SearchQueryBundleProvider<>(theParams, dao, translator, globalPropertyService, searchQueryInclude));
when(searchQueryInclude.getIncludedResources(any(), any())).thenReturn(Collections.emptySet());
- IBundleProvider results = serviceRequestService.searchForServiceRequests(null, null, null, null, null, null,
- lastUpdated, null);
+ IBundleProvider results = serviceRequestService.searchForServiceRequests(serviceRequestSearchParams);
List resultList = get(results);
@@ -310,6 +318,8 @@ public void searchForServiceRequest_shouldReturnCollectionOfServiceRequestByLast
public void searchForPeople_shouldAddRelatedResourcesWhenIncluded() {
HashSet includes = new HashSet<>();
includes.add(new Include("ServiceRequest:patient"));
+ ServiceRequestSearchParams serviceRequestSearchParams = new ServiceRequestSearchParams();
+ serviceRequestSearchParams.setIncludes(includes);
SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.INCLUDE_SEARCH_HANDLER, includes);
@@ -319,8 +329,7 @@ public void searchForPeople_shouldAddRelatedResourcesWhenIncluded() {
new SearchQueryBundleProvider<>(theParams, dao, translator, globalPropertyService, searchQueryInclude));
when(searchQueryInclude.getIncludedResources(any(), any())).thenReturn(Collections.singleton(new Patient()));
- IBundleProvider results = serviceRequestService.searchForServiceRequests(null, null, null, null, null, null, null,
- includes);
+ IBundleProvider results = serviceRequestService.searchForServiceRequests(serviceRequestSearchParams);
List resultList = get(results);
@@ -334,6 +343,8 @@ public void searchForPeople_shouldAddRelatedResourcesWhenIncluded() {
public void searchForPeople_shouldAddRelatedResourcesWhenIncludedR3() {
HashSet includes = new HashSet<>();
includes.add(new Include("ProcedureRequest:patient"));
+ ServiceRequestSearchParams serviceRequestSearchParams = new ServiceRequestSearchParams();
+ serviceRequestSearchParams.setIncludes(includes);
SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.INCLUDE_SEARCH_HANDLER, includes);
@@ -343,8 +354,7 @@ public void searchForPeople_shouldAddRelatedResourcesWhenIncludedR3() {
new SearchQueryBundleProvider<>(theParams, dao, translator, globalPropertyService, searchQueryInclude));
when(searchQueryInclude.getIncludedResources(any(), any())).thenReturn(Collections.singleton(new Patient()));
- IBundleProvider results = serviceRequestService.searchForServiceRequests(null, null, null, null, null, null, null,
- includes);
+ IBundleProvider results = serviceRequestService.searchForServiceRequests(serviceRequestSearchParams);
List resultList = get(results);
@@ -357,6 +367,8 @@ public void searchForPeople_shouldAddRelatedResourcesWhenIncludedR3() {
@Test
public void searchForPeople_shouldNotAddRelatedResourcesForEmptyInclude() {
HashSet includes = new HashSet<>();
+ ServiceRequestSearchParams serviceRequestSearchParams = new ServiceRequestSearchParams();
+ serviceRequestSearchParams.setIncludes(includes);
SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.INCLUDE_SEARCH_HANDLER, includes);
@@ -366,8 +378,7 @@ public void searchForPeople_shouldNotAddRelatedResourcesForEmptyInclude() {
new SearchQueryBundleProvider<>(theParams, dao, translator, globalPropertyService, searchQueryInclude));
when(searchQueryInclude.getIncludedResources(any(), any())).thenReturn(Collections.emptySet());
- IBundleProvider results = serviceRequestService.searchForServiceRequests(null, null, null, null, null, null, null,
- includes);
+ IBundleProvider results = serviceRequestService.searchForServiceRequests(serviceRequestSearchParams);
List resultList = get(results);
diff --git a/api/src/test/java/org/openmrs/module/fhir2/providers/r3/ProcedureRequestFhirResourceProviderTest.java b/api/src/test/java/org/openmrs/module/fhir2/providers/r3/ProcedureRequestFhirResourceProviderTest.java
index 46a1add94e..eecf532180 100644
--- a/api/src/test/java/org/openmrs/module/fhir2/providers/r3/ProcedureRequestFhirResourceProviderTest.java
+++ b/api/src/test/java/org/openmrs/module/fhir2/providers/r3/ProcedureRequestFhirResourceProviderTest.java
@@ -18,9 +18,8 @@
import static org.hl7.fhir.convertors.factory.VersionConvertorFactory_30_40.convertResource;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
-import static org.mockito.ArgumentMatchers.isNull;
+import static org.mockito.Mockito.argThat;
import static org.mockito.Mockito.when;
-import static org.mockito.hamcrest.MockitoHamcrest.argThat;
import java.util.Arrays;
import java.util.Collections;
@@ -54,6 +53,7 @@
import org.mockito.junit.MockitoJUnitRunner;
import org.openmrs.module.fhir2.FhirConstants;
import org.openmrs.module.fhir2.api.FhirServiceRequestService;
+import org.openmrs.module.fhir2.api.search.param.ServiceRequestSearchParams;
import org.openmrs.module.fhir2.providers.r4.MockIBundleProvider;
@RunWith(MockitoJUnitRunner.class)
@@ -135,9 +135,8 @@ public void getServiceRequestByWithWrongId_shouldThrowResourceNotFoundException(
@Test
public void searchProcedureRequest_shouldReturnMatchingProcedureRequestByCode() {
- when(serviceRequestService.searchForServiceRequests(any(), any(), any(), any(), any(), any(), any(), any()))
- .thenReturn(
- new MockIBundleProvider<>(Collections.singletonList(serviceRequest), PREFERRED_PAGE_SIZE, COUNT));
+ when(serviceRequestService.searchForServiceRequests(any())).thenReturn(
+ new MockIBundleProvider<>(Collections.singletonList(serviceRequest), PREFERRED_PAGE_SIZE, COUNT));
TokenAndListParam code = new TokenAndListParam().addAnd(new TokenParam(CODE));
@@ -155,9 +154,8 @@ public void searchProcedureRequest_shouldReturnMatchingProcedureRequestByCode()
@Test
public void searchProcedureRequest_shouldReturnMatchingProcedureRequestWhenPatientParamIsSpecified() {
- when(serviceRequestService.searchForServiceRequests(any(), any(), any(), any(), any(), any(), any(), any()))
- .thenReturn(
- new MockIBundleProvider<>(Collections.singletonList(serviceRequest), PREFERRED_PAGE_SIZE, COUNT));
+ when(serviceRequestService.searchForServiceRequests(any())).thenReturn(
+ new MockIBundleProvider<>(Collections.singletonList(serviceRequest), PREFERRED_PAGE_SIZE, COUNT));
ReferenceAndListParam patientParam = new ReferenceAndListParam().addAnd(
new ReferenceOrListParam().add(new ReferenceParam().setValue(PATIENT_GIVEN_NAME).setChain(Patient.SP_NAME)));
@@ -176,9 +174,8 @@ public void searchProcedureRequest_shouldReturnMatchingProcedureRequestWhenPatie
@Test
public void searchProcedureRequest_shouldReturnMatchingProcedureRequestWhenSubjectParamIsSpecified() {
- when(serviceRequestService.searchForServiceRequests(any(), any(), any(), any(), any(), any(), any(), any()))
- .thenReturn(
- new MockIBundleProvider<>(Collections.singletonList(serviceRequest), PREFERRED_PAGE_SIZE, COUNT));
+ when(serviceRequestService.searchForServiceRequests(any())).thenReturn(
+ new MockIBundleProvider<>(Collections.singletonList(serviceRequest), PREFERRED_PAGE_SIZE, COUNT));
ReferenceAndListParam subjectParam = new ReferenceAndListParam().addAnd(
new ReferenceOrListParam().add(new ReferenceParam().setValue(PATIENT_GIVEN_NAME).setChain(Patient.SP_NAME)));
@@ -197,9 +194,8 @@ public void searchProcedureRequest_shouldReturnMatchingProcedureRequestWhenSubje
@Test
public void searchProcedureRequest_shouldReturnMatchingProcedureRequestByRequesterParam() {
- when(serviceRequestService.searchForServiceRequests(any(), any(), any(), any(), any(), any(), any(), any()))
- .thenReturn(
- new MockIBundleProvider<>(Collections.singletonList(serviceRequest), PREFERRED_PAGE_SIZE, COUNT));
+ when(serviceRequestService.searchForServiceRequests(any())).thenReturn(
+ new MockIBundleProvider<>(Collections.singletonList(serviceRequest), PREFERRED_PAGE_SIZE, COUNT));
ReferenceAndListParam practitionerParam = new ReferenceAndListParam().addAnd(new ReferenceOrListParam()
.add(new ReferenceParam().setValue(PARTICIPANT_IDENTIFIER).setChain(Practitioner.SP_IDENTIFIER)));
@@ -218,9 +214,8 @@ public void searchProcedureRequest_shouldReturnMatchingProcedureRequestByRequest
@Test
public void searchProcedureRequest_shouldReturnMatchingProcedureRequestByOccurrence() {
- when(serviceRequestService.searchForServiceRequests(any(), any(), any(), any(), any(), any(), any(), any()))
- .thenReturn(
- new MockIBundleProvider<>(Collections.singletonList(serviceRequest), PREFERRED_PAGE_SIZE, COUNT));
+ when(serviceRequestService.searchForServiceRequests(any())).thenReturn(
+ new MockIBundleProvider<>(Collections.singletonList(serviceRequest), PREFERRED_PAGE_SIZE, COUNT));
DateRangeParam occurrence = new DateRangeParam().setLowerBound(OCCURRENCE).setUpperBound(OCCURRENCE);
@@ -238,7 +233,7 @@ public void searchProcedureRequest_shouldReturnMatchingProcedureRequestByOccurre
@Test
public void searchProcedureRequest_shouldReturnMatchingProcedureRequestByEncounter() {
- when(serviceRequestService.searchForServiceRequests(any(), any(), any(), any(), any(), any(), any(), any()))
+ when(serviceRequestService.searchForServiceRequests(any()))
.thenReturn(new MockIBundleProvider<>(Collections.singletonList(serviceRequest), 10, 1));
ReferenceAndListParam encounterParam = new ReferenceAndListParam()
@@ -328,9 +323,8 @@ public void deleteProcedureRequest_shouldDeleteProcedureRequest() {
public void searchProcedureRequest_shouldReturnMatchingProcedureRequestWhenUUIDIsSpecified() {
TokenAndListParam uuid = new TokenAndListParam().addAnd(new TokenParam(SERVICE_REQUEST_UUID));
- when(serviceRequestService.searchForServiceRequests(any(), any(), any(), any(), any(), any(), any(), any()))
- .thenReturn(
- new MockIBundleProvider<>(Collections.singletonList(serviceRequest), PREFERRED_PAGE_SIZE, COUNT));
+ when(serviceRequestService.searchForServiceRequests(any())).thenReturn(
+ new MockIBundleProvider<>(Collections.singletonList(serviceRequest), PREFERRED_PAGE_SIZE, COUNT));
IBundleProvider results = resourceProvider.searchForProcedureRequests(null, null, null, null, null, null, uuid, null,
null);
@@ -348,9 +342,8 @@ public void searchProcedureRequest_shouldReturnMatchingProcedureRequestWhenUUIDI
public void searchProcedureRequest_shouldReturnMatchingProcedureRequestWhenLastUpdatedIsSpecified() {
DateRangeParam lastUpdated = new DateRangeParam().setUpperBound(LAST_UPDATED_DATE).setLowerBound(LAST_UPDATED_DATE);
- when(serviceRequestService.searchForServiceRequests(any(), any(), any(), any(), any(), any(), any(), any()))
- .thenReturn(
- new MockIBundleProvider<>(Collections.singletonList(serviceRequest), PREFERRED_PAGE_SIZE, COUNT));
+ when(serviceRequestService.searchForServiceRequests(any())).thenReturn(
+ new MockIBundleProvider<>(Collections.singletonList(serviceRequest), PREFERRED_PAGE_SIZE, COUNT));
IBundleProvider results = resourceProvider.searchForProcedureRequests(null, null, null, null, null, null, null,
lastUpdated, null);
@@ -369,9 +362,11 @@ public void searchProcedureRequest_shouldAddRelatedResourcesToResultListWhenIncl
HashSet includes = new HashSet<>();
includes.add(new Include("ProcedureRequest:patient"));
- when(serviceRequestService.searchForServiceRequests(any(), any(), any(), any(), any(), any(), any(),
- argThat(is(includes)))).thenReturn(
- new MockIBundleProvider<>(Arrays.asList(serviceRequest, new Patient()), PREFERRED_PAGE_SIZE, COUNT));
+ // TODO: challenge if the less readable argThat should be used to preserve exact test behaviour or switch to any() as described in the similar pull request here: https://github.com/openmrs/openmrs-module-fhir2/pull/398/files#diff-c9a3b09584a3999711375bbae28e3dccda1188158195cd43dde98f1ea6ca9098L224
+ when(serviceRequestService.searchForServiceRequests(
+ argThat((ServiceRequestSearchParams serviceRequestSearchParams) -> serviceRequestSearchParams
+ .getIncludes() == includes))).thenReturn(
+ new MockIBundleProvider<>(Arrays.asList(serviceRequest, new Patient()), PREFERRED_PAGE_SIZE, COUNT));
IBundleProvider results = resourceProvider.searchForProcedureRequests(null, null, null, null, null, null, null, null,
includes);
@@ -390,9 +385,11 @@ public void searchProcedureRequest_shouldAddRelatedResourcesToResultListWhenIncl
public void searchProcedureRequest_shouldNotAddRelatedResourcesToResultListForEmptyIncludes() {
HashSet includes = new HashSet<>();
- when(serviceRequestService.searchForServiceRequests(any(), any(), any(), any(), any(), any(), any(), isNull()))
- .thenReturn(
- new MockIBundleProvider<>(Collections.singletonList(serviceRequest), PREFERRED_PAGE_SIZE, COUNT));
+ // an empty set of includes is converted to null before being passed on to searchForServiceRequests
+ when(serviceRequestService.searchForServiceRequests(argThat(
+ (ServiceRequestSearchParams serviceRequestSearchParams) -> serviceRequestSearchParams.getIncludes() == null)))
+ .thenReturn(
+ new MockIBundleProvider<>(Collections.singletonList(serviceRequest), PREFERRED_PAGE_SIZE, COUNT));
IBundleProvider results = resourceProvider.searchForProcedureRequests(null, null, null, null, null, null, null, null,
includes);
diff --git a/api/src/test/java/org/openmrs/module/fhir2/providers/r4/ServiceRequestFhirResourceProviderTest.java b/api/src/test/java/org/openmrs/module/fhir2/providers/r4/ServiceRequestFhirResourceProviderTest.java
index 9499028b09..d9e61305ab 100644
--- a/api/src/test/java/org/openmrs/module/fhir2/providers/r4/ServiceRequestFhirResourceProviderTest.java
+++ b/api/src/test/java/org/openmrs/module/fhir2/providers/r4/ServiceRequestFhirResourceProviderTest.java
@@ -16,9 +16,8 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasSize;
import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.isNull;
+import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.Mockito.when;
-import static org.mockito.hamcrest.MockitoHamcrest.argThat;
import java.util.Arrays;
import java.util.Collections;
@@ -51,6 +50,7 @@
import org.mockito.junit.MockitoJUnitRunner;
import org.openmrs.module.fhir2.FhirConstants;
import org.openmrs.module.fhir2.api.FhirServiceRequestService;
+import org.openmrs.module.fhir2.api.search.param.ServiceRequestSearchParams;
@RunWith(MockitoJUnitRunner.class)
public class ServiceRequestFhirResourceProviderTest {
@@ -131,9 +131,8 @@ public void getServiceRequestByWithWrongId_shouldThrowResourceNotFoundException(
@Test
public void searchServiceRequest_shouldReturnMatchingServiceRequestsByCode() {
- when(serviceRequestService.searchForServiceRequests(any(), any(), any(), any(), any(), any(), any(), any()))
- .thenReturn(
- new MockIBundleProvider<>(Collections.singletonList(serviceRequest), PREFERRED_PAGE_SIZE, COUNT));
+ when(serviceRequestService.searchForServiceRequests(any())).thenReturn(
+ new MockIBundleProvider<>(Collections.singletonList(serviceRequest), PREFERRED_PAGE_SIZE, COUNT));
TokenAndListParam code = new TokenAndListParam().addAnd(new TokenParam(CODE));
@@ -151,9 +150,8 @@ public void searchServiceRequest_shouldReturnMatchingServiceRequestsByCode() {
@Test
public void searchServiceRequest_shouldReturnMatchingServiceRequestsWhenPatientParamIsSpecified() {
- when(serviceRequestService.searchForServiceRequests(any(), any(), any(), any(), any(), any(), any(), any()))
- .thenReturn(
- new MockIBundleProvider<>(Collections.singletonList(serviceRequest), PREFERRED_PAGE_SIZE, COUNT));
+ when(serviceRequestService.searchForServiceRequests(any())).thenReturn(
+ new MockIBundleProvider<>(Collections.singletonList(serviceRequest), PREFERRED_PAGE_SIZE, COUNT));
ReferenceAndListParam patientParam = new ReferenceAndListParam().addAnd(
new ReferenceOrListParam().add(new ReferenceParam().setValue(PATIENT_GIVEN_NAME).setChain(Patient.SP_NAME)));
@@ -172,9 +170,8 @@ public void searchServiceRequest_shouldReturnMatchingServiceRequestsWhenPatientP
@Test
public void searchServiceRequest_shouldReturnMatchingServiceRequestsWhenSubjectParamIsSpecified() {
- when(serviceRequestService.searchForServiceRequests(any(), any(), any(), any(), any(), any(), any(), any()))
- .thenReturn(
- new MockIBundleProvider<>(Collections.singletonList(serviceRequest), PREFERRED_PAGE_SIZE, COUNT));
+ when(serviceRequestService.searchForServiceRequests(any())).thenReturn(
+ new MockIBundleProvider<>(Collections.singletonList(serviceRequest), PREFERRED_PAGE_SIZE, COUNT));
ReferenceAndListParam subjectParam = new ReferenceAndListParam().addAnd(
new ReferenceOrListParam().add(new ReferenceParam().setValue(PATIENT_GIVEN_NAME).setChain(Patient.SP_NAME)));
@@ -193,9 +190,8 @@ public void searchServiceRequest_shouldReturnMatchingServiceRequestsWhenSubjectP
@Test
public void searchServiceRequest_shouldReturnMatchingServiceRequestsByRequesterParam() {
- when(serviceRequestService.searchForServiceRequests(any(), any(), any(), any(), any(), any(), any(), any()))
- .thenReturn(
- new MockIBundleProvider<>(Collections.singletonList(serviceRequest), PREFERRED_PAGE_SIZE, COUNT));
+ when(serviceRequestService.searchForServiceRequests(any())).thenReturn(
+ new MockIBundleProvider<>(Collections.singletonList(serviceRequest), PREFERRED_PAGE_SIZE, COUNT));
ReferenceAndListParam practitionerParam = new ReferenceAndListParam().addAnd(new ReferenceOrListParam()
.add(new ReferenceParam().setValue(PARTICIPANT_IDENTIFIER).setChain(Practitioner.SP_IDENTIFIER)));
@@ -214,9 +210,8 @@ public void searchServiceRequest_shouldReturnMatchingServiceRequestsByRequesterP
@Test
public void searchServiceRequest_shouldReturnMatchingServiceRequestsByOccurrence() {
- when(serviceRequestService.searchForServiceRequests(any(), any(), any(), any(), any(), any(), any(), any()))
- .thenReturn(
- new MockIBundleProvider<>(Collections.singletonList(serviceRequest), PREFERRED_PAGE_SIZE, COUNT));
+ when(serviceRequestService.searchForServiceRequests(any())).thenReturn(
+ new MockIBundleProvider<>(Collections.singletonList(serviceRequest), PREFERRED_PAGE_SIZE, COUNT));
DateRangeParam occurrence = new DateRangeParam().setLowerBound(OCCURRENCE).setUpperBound(OCCURRENCE);
@@ -234,7 +229,7 @@ public void searchServiceRequest_shouldReturnMatchingServiceRequestsByOccurrence
@Test
public void searchServiceRequests_shouldReturnMatchingServiceRequestsByEncounter() {
- when(serviceRequestService.searchForServiceRequests(any(), any(), any(), any(), any(), any(), any(), any()))
+ when(serviceRequestService.searchForServiceRequests(any()))
.thenReturn(new MockIBundleProvider<>(Collections.singletonList(serviceRequest), 10, 1));
ReferenceAndListParam encounterParam = new ReferenceAndListParam()
@@ -256,9 +251,8 @@ public void searchServiceRequests_shouldReturnMatchingServiceRequestsByEncounter
public void searchServiceRequest_shouldReturnMatchingServiceRequestWhenUUIDIsSpecified() {
TokenAndListParam uuid = new TokenAndListParam().addAnd(new TokenParam(SERVICE_REQUEST_UUID));
- when(serviceRequestService.searchForServiceRequests(any(), any(), any(), any(), any(), any(), any(), any()))
- .thenReturn(
- new MockIBundleProvider<>(Collections.singletonList(serviceRequest), PREFERRED_PAGE_SIZE, COUNT));
+ when(serviceRequestService.searchForServiceRequests(any())).thenReturn(
+ new MockIBundleProvider<>(Collections.singletonList(serviceRequest), PREFERRED_PAGE_SIZE, COUNT));
IBundleProvider results = resourceProvider.searchForServiceRequests(null, null, null, null, null, null, uuid, null,
null);
@@ -276,9 +270,8 @@ public void searchServiceRequest_shouldReturnMatchingServiceRequestWhenUUIDIsSpe
public void searchServiceRequest_shouldReturnMatchingServiceRequestWhenLastUpdatedIsSpecified() {
DateRangeParam lastUpdated = new DateRangeParam().setUpperBound(LAST_UPDATED_DATE).setLowerBound(LAST_UPDATED_DATE);
- when(serviceRequestService.searchForServiceRequests(any(), any(), any(), any(), any(), any(), any(), any()))
- .thenReturn(
- new MockIBundleProvider<>(Collections.singletonList(serviceRequest), PREFERRED_PAGE_SIZE, COUNT));
+ when(serviceRequestService.searchForServiceRequests(any())).thenReturn(
+ new MockIBundleProvider<>(Collections.singletonList(serviceRequest), PREFERRED_PAGE_SIZE, COUNT));
IBundleProvider results = resourceProvider.searchForServiceRequests(null, null, null, null, null, null, null,
lastUpdated, null);
@@ -357,9 +350,11 @@ public void searchServiceRequest_shouldAddRelatedResourcesToResultListWhenInclud
HashSet includes = new HashSet<>();
includes.add(new Include("ServiceRequest:patient"));
- when(serviceRequestService.searchForServiceRequests(any(), any(), any(), any(), any(), any(), any(),
- argThat(is(includes)))).thenReturn(
- new MockIBundleProvider<>(Arrays.asList(serviceRequest, new Patient()), PREFERRED_PAGE_SIZE, COUNT));
+ // TODO: challenge if the less readable argThat should be used to preserve exact test behaviour or switch to any() as described in the similar pull request here: https://github.com/openmrs/openmrs-module-fhir2/pull/398/files#diff-c9a3b09584a3999711375bbae28e3dccda1188158195cd43dde98f1ea6ca9098L224
+ when(serviceRequestService.searchForServiceRequests(
+ argThat((ServiceRequestSearchParams serviceRequestSearchParams) -> serviceRequestSearchParams
+ .getIncludes() == includes))).thenReturn(
+ new MockIBundleProvider<>(Arrays.asList(serviceRequest, new Patient()), PREFERRED_PAGE_SIZE, COUNT));
IBundleProvider results = resourceProvider.searchForServiceRequests(null, null, null, null, null, null, null, null,
includes);
@@ -378,9 +373,11 @@ public void searchServiceRequest_shouldAddRelatedResourcesToResultListWhenInclud
public void searchServiceRequest_shouldNotAddRelatedResourcesToResultListForEmptyIncludes() {
HashSet includes = new HashSet<>();
- when(serviceRequestService.searchForServiceRequests(any(), any(), any(), any(), any(), any(), any(), isNull()))
- .thenReturn(
- new MockIBundleProvider<>(Collections.singletonList(serviceRequest), PREFERRED_PAGE_SIZE, COUNT));
+ // an empty set of includes is converted to null before being passed on to searchForServiceRequests
+ when(serviceRequestService.searchForServiceRequests(argThat(
+ (ServiceRequestSearchParams serviceRequestSearchParams) -> serviceRequestSearchParams.getIncludes() == null)))
+ .thenReturn(
+ new MockIBundleProvider<>(Collections.singletonList(serviceRequest), PREFERRED_PAGE_SIZE, COUNT));
IBundleProvider results = resourceProvider.searchForServiceRequests(null, null, null, null, null, null, null, null,
includes);
diff --git a/omod/src/test/java/org/openmrs/module/fhir2/providers/r3/ProcedureRequestFhirResourceProviderWebTest.java b/omod/src/test/java/org/openmrs/module/fhir2/providers/r3/ProcedureRequestFhirResourceProviderWebTest.java
index c74ed2795f..ed66831362 100644
--- a/omod/src/test/java/org/openmrs/module/fhir2/providers/r3/ProcedureRequestFhirResourceProviderWebTest.java
+++ b/omod/src/test/java/org/openmrs/module/fhir2/providers/r3/ProcedureRequestFhirResourceProviderWebTest.java
@@ -18,18 +18,21 @@
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.notNullValue;
import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.isNull;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import javax.servlet.ServletException;
+import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.HashSet;
+import java.util.List;
import ca.uhn.fhir.model.api.Include;
import ca.uhn.fhir.rest.param.DateRangeParam;
+import ca.uhn.fhir.rest.param.HasAndListParam;
+import ca.uhn.fhir.rest.param.HasOrListParam;
import ca.uhn.fhir.rest.param.ReferenceAndListParam;
import ca.uhn.fhir.rest.param.TokenAndListParam;
import lombok.AccessLevel;
@@ -41,6 +44,7 @@
import org.hl7.fhir.dstu3.model.ProcedureRequest;
import org.hl7.fhir.r4.model.ServiceRequest;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
@@ -97,18 +101,6 @@ public class ProcedureRequestFhirResourceProviderWebTest extends BaseFhirR3Resou
@Mock
private FhirServiceRequestService service;
- @Captor
- private ArgumentCaptor tokenAndListParamArgumentCaptor;
-
- @Captor
- private ArgumentCaptor referenceAndListParamArgumentCaptor;
-
- @Captor
- private ArgumentCaptor dateRangeParamArgumentCaptor;
-
- @Captor
- private ArgumentCaptor> includeArgumentCaptor;
-
@Captor
private ArgumentCaptor serviceRequestSearchParamsArgumentCaptor;
@@ -148,16 +140,15 @@ public void getProcedureRequestByWrongUuid_shouldReturn404() throws Exception {
public void searchForServiceRequests_shouldSearchForServiceRequestsByPatientUUID() throws Exception {
verifyUri(String.format("/ProcedureRequest?patient=%s", PATIENT_UUID));
- verify(service).searchForServiceRequests(referenceAndListParamArgumentCaptor.capture(), isNull(), isNull(), isNull(),
- isNull(), isNull(), isNull(), isNull());
+ verify(service).searchForServiceRequests(serviceRequestSearchParamsArgumentCaptor.capture());
- assertThat(referenceAndListParamArgumentCaptor.getValue(), notNullValue());
- assertThat(referenceAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens(), not(empty()));
- assertThat(referenceAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens()
- .get(0).getValue(),
+ ReferenceAndListParam referenceAndListParam = serviceRequestSearchParamsArgumentCaptor.getValue()
+ .getPatientReference();
+ assertThat(referenceAndListParam, notNullValue());
+ assertThat(referenceAndListParam.getValuesAsQueryTokens(), not(empty()));
+ assertThat(referenceAndListParam.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getValue(),
equalTo(PATIENT_UUID));
- assertThat(referenceAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens()
- .get(0).getChain(),
+ assertThat(referenceAndListParam.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getChain(),
equalTo(null));
}
@@ -165,16 +156,15 @@ public void searchForServiceRequests_shouldSearchForServiceRequestsByPatientUUID
public void searchForServiceRequests_shouldSearchForServiceRequestsByPatientName() throws Exception {
verifyUri(String.format("/ProcedureRequest?patient.name=%s", PATIENT_GIVEN_NAME));
- verify(service).searchForServiceRequests(referenceAndListParamArgumentCaptor.capture(), isNull(), isNull(), isNull(),
- isNull(), isNull(), isNull(), isNull());
+ verify(service).searchForServiceRequests(serviceRequestSearchParamsArgumentCaptor.capture());
- assertThat(referenceAndListParamArgumentCaptor.getValue(), notNullValue());
- assertThat(referenceAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens(), not(empty()));
- assertThat(referenceAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens()
- .get(0).getValue(),
+ ReferenceAndListParam referenceAndListParam = serviceRequestSearchParamsArgumentCaptor.getValue()
+ .getPatientReference();
+ assertThat(referenceAndListParam, notNullValue());
+ assertThat(referenceAndListParam.getValuesAsQueryTokens(), not(empty()));
+ assertThat(referenceAndListParam.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getValue(),
equalTo(PATIENT_GIVEN_NAME));
- assertThat(referenceAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens()
- .get(0).getChain(),
+ assertThat(referenceAndListParam.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getChain(),
equalTo(Patient.SP_NAME));
}
@@ -182,16 +172,15 @@ public void searchForServiceRequests_shouldSearchForServiceRequestsByPatientName
public void searchForServiceRequests_shouldSearchForServiceRequestsByPatientGivenName() throws Exception {
verifyUri(String.format("/ProcedureRequest?patient.given=%s", PATIENT_GIVEN_NAME));
- verify(service).searchForServiceRequests(referenceAndListParamArgumentCaptor.capture(), isNull(), isNull(), isNull(),
- isNull(), isNull(), isNull(), isNull());
+ verify(service).searchForServiceRequests(serviceRequestSearchParamsArgumentCaptor.capture());
- assertThat(referenceAndListParamArgumentCaptor.getValue(), notNullValue());
- assertThat(referenceAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens(), not(empty()));
- assertThat(referenceAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens()
- .get(0).getValue(),
+ ReferenceAndListParam referenceAndListParam = serviceRequestSearchParamsArgumentCaptor.getValue()
+ .getPatientReference();
+ assertThat(referenceAndListParam, notNullValue());
+ assertThat(referenceAndListParam.getValuesAsQueryTokens(), not(empty()));
+ assertThat(referenceAndListParam.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getValue(),
equalTo(PATIENT_GIVEN_NAME));
- assertThat(referenceAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens()
- .get(0).getChain(),
+ assertThat(referenceAndListParam.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getChain(),
equalTo(Patient.SP_GIVEN));
}
@@ -199,16 +188,15 @@ public void searchForServiceRequests_shouldSearchForServiceRequestsByPatientGive
public void searchForServiceRequests_shouldSearchForServiceRequestsByPatientFamilyName() throws Exception {
verifyUri(String.format("/ProcedureRequest?patient.family=%s", PATIENT_FAMILY_NAME));
- verify(service).searchForServiceRequests(referenceAndListParamArgumentCaptor.capture(), isNull(), isNull(), isNull(),
- isNull(), isNull(), isNull(), isNull());
+ verify(service).searchForServiceRequests(serviceRequestSearchParamsArgumentCaptor.capture());
- assertThat(referenceAndListParamArgumentCaptor.getValue(), notNullValue());
- assertThat(referenceAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens(), not(empty()));
- assertThat(referenceAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens()
- .get(0).getValue(),
+ ReferenceAndListParam referenceAndListParam = serviceRequestSearchParamsArgumentCaptor.getValue()
+ .getPatientReference();
+ assertThat(referenceAndListParam, notNullValue());
+ assertThat(referenceAndListParam.getValuesAsQueryTokens(), not(empty()));
+ assertThat(referenceAndListParam.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getValue(),
equalTo(PATIENT_FAMILY_NAME));
- assertThat(referenceAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens()
- .get(0).getChain(),
+ assertThat(referenceAndListParam.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getChain(),
equalTo(Patient.SP_FAMILY));
}
@@ -216,16 +204,15 @@ public void searchForServiceRequests_shouldSearchForServiceRequestsByPatientFami
public void searchForServiceRequests_shouldSearchForServiceRequestsByPatientIdentifier() throws Exception {
verifyUri(String.format("/ProcedureRequest?patient.identifier=%s", PATIENT_IDENTIFIER));
- verify(service).searchForServiceRequests(referenceAndListParamArgumentCaptor.capture(), isNull(), isNull(), isNull(),
- isNull(), isNull(), isNull(), isNull());
+ verify(service).searchForServiceRequests(serviceRequestSearchParamsArgumentCaptor.capture());
- assertThat(referenceAndListParamArgumentCaptor.getValue(), notNullValue());
- assertThat(referenceAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens(), not(empty()));
- assertThat(referenceAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens()
- .get(0).getValue(),
+ ReferenceAndListParam referenceAndListParam = serviceRequestSearchParamsArgumentCaptor.getValue()
+ .getPatientReference();
+ assertThat(referenceAndListParam, notNullValue());
+ assertThat(referenceAndListParam.getValuesAsQueryTokens(), not(empty()));
+ assertThat(referenceAndListParam.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getValue(),
equalTo(PATIENT_IDENTIFIER));
- assertThat(referenceAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens()
- .get(0).getChain(),
+ assertThat(referenceAndListParam.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getChain(),
equalTo(Patient.SP_IDENTIFIER));
}
@@ -233,16 +220,15 @@ public void searchForServiceRequests_shouldSearchForServiceRequestsByPatientIden
public void searchForServiceRequests_shouldSearchForServiceRequestsBySubjectUUID() throws Exception {
verifyUri(String.format("/ProcedureRequest?subject=%s", PATIENT_UUID));
- verify(service).searchForServiceRequests(referenceAndListParamArgumentCaptor.capture(), isNull(), isNull(), isNull(),
- isNull(), isNull(), isNull(), isNull());
+ verify(service).searchForServiceRequests(serviceRequestSearchParamsArgumentCaptor.capture());
- assertThat(referenceAndListParamArgumentCaptor.getValue(), notNullValue());
- assertThat(referenceAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens(), not(empty()));
- assertThat(referenceAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens()
- .get(0).getValue(),
+ ReferenceAndListParam referenceAndListParam = serviceRequestSearchParamsArgumentCaptor.getValue()
+ .getPatientReference();
+ assertThat(referenceAndListParam, notNullValue());
+ assertThat(referenceAndListParam.getValuesAsQueryTokens(), not(empty()));
+ assertThat(referenceAndListParam.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getValue(),
equalTo(PATIENT_UUID));
- assertThat(referenceAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens()
- .get(0).getChain(),
+ assertThat(referenceAndListParam.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getChain(),
equalTo(null));
}
@@ -250,16 +236,15 @@ public void searchForServiceRequests_shouldSearchForServiceRequestsBySubjectUUID
public void searchForServiceRequests_shouldSearchForServiceRequestsBySubjectName() throws Exception {
verifyUri(String.format("/ProcedureRequest?subject.name=%s", PATIENT_GIVEN_NAME));
- verify(service).searchForServiceRequests(referenceAndListParamArgumentCaptor.capture(), isNull(), isNull(), isNull(),
- isNull(), isNull(), isNull(), isNull());
+ verify(service).searchForServiceRequests(serviceRequestSearchParamsArgumentCaptor.capture());
- assertThat(referenceAndListParamArgumentCaptor.getValue(), notNullValue());
- assertThat(referenceAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens(), not(empty()));
- assertThat(referenceAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens()
- .get(0).getValue(),
+ ReferenceAndListParam referenceAndListParam = serviceRequestSearchParamsArgumentCaptor.getValue()
+ .getPatientReference();
+ assertThat(referenceAndListParam, notNullValue());
+ assertThat(referenceAndListParam.getValuesAsQueryTokens(), not(empty()));
+ assertThat(referenceAndListParam.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getValue(),
equalTo(PATIENT_GIVEN_NAME));
- assertThat(referenceAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens()
- .get(0).getChain(),
+ assertThat(referenceAndListParam.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getChain(),
equalTo(Patient.SP_NAME));
}
@@ -267,16 +252,15 @@ public void searchForServiceRequests_shouldSearchForServiceRequestsBySubjectName
public void searchForServiceRequests_shouldSearchForServiceRequestsBySubjectGivenName() throws Exception {
verifyUri(String.format("/ProcedureRequest?subject.given=%s", PATIENT_GIVEN_NAME));
- verify(service).searchForServiceRequests(referenceAndListParamArgumentCaptor.capture(), isNull(), isNull(), isNull(),
- isNull(), isNull(), isNull(), isNull());
+ verify(service).searchForServiceRequests(serviceRequestSearchParamsArgumentCaptor.capture());
- assertThat(referenceAndListParamArgumentCaptor.getValue(), notNullValue());
- assertThat(referenceAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens(), not(empty()));
- assertThat(referenceAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens()
- .get(0).getValue(),
+ ReferenceAndListParam referenceAndListParam = serviceRequestSearchParamsArgumentCaptor.getValue()
+ .getPatientReference();
+ assertThat(referenceAndListParam, notNullValue());
+ assertThat(referenceAndListParam.getValuesAsQueryTokens(), not(empty()));
+ assertThat(referenceAndListParam.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getValue(),
equalTo(PATIENT_GIVEN_NAME));
- assertThat(referenceAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens()
- .get(0).getChain(),
+ assertThat(referenceAndListParam.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getChain(),
equalTo(Patient.SP_GIVEN));
}
@@ -284,16 +268,15 @@ public void searchForServiceRequests_shouldSearchForServiceRequestsBySubjectGive
public void searchForServiceRequests_shouldSearchForServiceRequestsBySubjectFamilyName() throws Exception {
verifyUri(String.format("/ProcedureRequest?subject.family=%s", PATIENT_FAMILY_NAME));
- verify(service).searchForServiceRequests(referenceAndListParamArgumentCaptor.capture(), isNull(), isNull(), isNull(),
- isNull(), isNull(), isNull(), isNull());
+ verify(service).searchForServiceRequests(serviceRequestSearchParamsArgumentCaptor.capture());
- assertThat(referenceAndListParamArgumentCaptor.getValue(), notNullValue());
- assertThat(referenceAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens(), not(empty()));
- assertThat(referenceAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens()
- .get(0).getValue(),
+ ReferenceAndListParam referenceAndListParam = serviceRequestSearchParamsArgumentCaptor.getValue()
+ .getPatientReference();
+ assertThat(referenceAndListParam, notNullValue());
+ assertThat(referenceAndListParam.getValuesAsQueryTokens(), not(empty()));
+ assertThat(referenceAndListParam.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getValue(),
equalTo(PATIENT_FAMILY_NAME));
- assertThat(referenceAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens()
- .get(0).getChain(),
+ assertThat(referenceAndListParam.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getChain(),
equalTo(Patient.SP_FAMILY));
}
@@ -301,16 +284,15 @@ public void searchForServiceRequests_shouldSearchForServiceRequestsBySubjectFami
public void searchForServiceRequests_shouldSearchForServiceRequestsBySubjectIdentifier() throws Exception {
verifyUri(String.format("/ProcedureRequest?subject.identifier=%s", PATIENT_IDENTIFIER));
- verify(service).searchForServiceRequests(referenceAndListParamArgumentCaptor.capture(), isNull(), isNull(), isNull(),
- isNull(), isNull(), isNull(), isNull());
+ verify(service).searchForServiceRequests(serviceRequestSearchParamsArgumentCaptor.capture());
- assertThat(referenceAndListParamArgumentCaptor.getValue(), notNullValue());
- assertThat(referenceAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens(), not(empty()));
- assertThat(referenceAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens()
- .get(0).getValue(),
+ ReferenceAndListParam referenceAndListParam = serviceRequestSearchParamsArgumentCaptor.getValue()
+ .getPatientReference();
+ assertThat(referenceAndListParam, notNullValue());
+ assertThat(referenceAndListParam.getValuesAsQueryTokens(), not(empty()));
+ assertThat(referenceAndListParam.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getValue(),
equalTo(PATIENT_IDENTIFIER));
- assertThat(referenceAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens()
- .get(0).getChain(),
+ assertThat(referenceAndListParam.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getChain(),
equalTo(Patient.SP_IDENTIFIER));
}
@@ -318,16 +300,15 @@ public void searchForServiceRequests_shouldSearchForServiceRequestsBySubjectIden
public void searchForServiceRequests_shouldSearchForServiceRequestsByParticipantUUID() throws Exception {
verifyUri(String.format("/ProcedureRequest?requester=%s", PARTICIPANT_UUID));
- verify(service).searchForServiceRequests(isNull(), isNull(), isNull(), referenceAndListParamArgumentCaptor.capture(),
- isNull(), isNull(), isNull(), isNull());
+ verify(service).searchForServiceRequests(serviceRequestSearchParamsArgumentCaptor.capture());
- assertThat(referenceAndListParamArgumentCaptor.getValue(), notNullValue());
- assertThat(referenceAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens(), not(empty()));
- assertThat(referenceAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens()
- .get(0).getValue(),
+ ReferenceAndListParam referenceAndListParam = serviceRequestSearchParamsArgumentCaptor.getValue()
+ .getParticipantReference();
+ assertThat(referenceAndListParam, notNullValue());
+ assertThat(referenceAndListParam.getValuesAsQueryTokens(), not(empty()));
+ assertThat(referenceAndListParam.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getValue(),
equalTo(PARTICIPANT_UUID));
- assertThat(referenceAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens()
- .get(0).getChain(),
+ assertThat(referenceAndListParam.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getChain(),
equalTo(null));
}
@@ -335,16 +316,15 @@ public void searchForServiceRequests_shouldSearchForServiceRequestsByParticipant
public void searchForServiceRequests_shouldSearchForServiceRequestsByParticipantName() throws Exception {
verifyUri(String.format("/ProcedureRequest?requester.name=%s", PARTICIPANT_GIVEN_NAME));
- verify(service).searchForServiceRequests(isNull(), isNull(), isNull(), referenceAndListParamArgumentCaptor.capture(),
- isNull(), isNull(), isNull(), isNull());
+ verify(service).searchForServiceRequests(serviceRequestSearchParamsArgumentCaptor.capture());
- assertThat(referenceAndListParamArgumentCaptor.getValue(), notNullValue());
- assertThat(referenceAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens(), not(empty()));
- assertThat(referenceAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens()
- .get(0).getValue(),
+ ReferenceAndListParam referenceAndListParam = serviceRequestSearchParamsArgumentCaptor.getValue()
+ .getParticipantReference();
+ assertThat(referenceAndListParam, notNullValue());
+ assertThat(referenceAndListParam.getValuesAsQueryTokens(), not(empty()));
+ assertThat(referenceAndListParam.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getValue(),
equalTo(PARTICIPANT_GIVEN_NAME));
- assertThat(referenceAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens()
- .get(0).getChain(),
+ assertThat(referenceAndListParam.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getChain(),
equalTo(Practitioner.SP_NAME));
}
@@ -352,16 +332,15 @@ public void searchForServiceRequests_shouldSearchForServiceRequestsByParticipant
public void searchForServiceRequests_shouldSearchForServiceRequestsByParticipantGivenName() throws Exception {
verifyUri(String.format("/ProcedureRequest?requester.given=%s", PARTICIPANT_GIVEN_NAME));
- verify(service).searchForServiceRequests(isNull(), isNull(), isNull(), referenceAndListParamArgumentCaptor.capture(),
- isNull(), isNull(), isNull(), isNull());
+ verify(service).searchForServiceRequests(serviceRequestSearchParamsArgumentCaptor.capture());
- assertThat(referenceAndListParamArgumentCaptor.getValue(), notNullValue());
- assertThat(referenceAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens(), not(empty()));
- assertThat(referenceAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens()
- .get(0).getValue(),
+ ReferenceAndListParam referenceAndListParam = serviceRequestSearchParamsArgumentCaptor.getValue()
+ .getParticipantReference();
+ assertThat(referenceAndListParam, notNullValue());
+ assertThat(referenceAndListParam.getValuesAsQueryTokens(), not(empty()));
+ assertThat(referenceAndListParam.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getValue(),
equalTo(PARTICIPANT_GIVEN_NAME));
- assertThat(referenceAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens()
- .get(0).getChain(),
+ assertThat(referenceAndListParam.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getChain(),
equalTo(Practitioner.SP_GIVEN));
}
@@ -369,16 +348,15 @@ public void searchForServiceRequests_shouldSearchForServiceRequestsByParticipant
public void searchForServiceRequests_shouldSearchForServiceRequestsByParticipantFamilyName() throws Exception {
verifyUri(String.format("/ProcedureRequest?requester.family=%s", PARTICIPANT_FAMILY_NAME));
- verify(service).searchForServiceRequests(isNull(), isNull(), isNull(), referenceAndListParamArgumentCaptor.capture(),
- isNull(), isNull(), isNull(), isNull());
+ verify(service).searchForServiceRequests(serviceRequestSearchParamsArgumentCaptor.capture());
- assertThat(referenceAndListParamArgumentCaptor.getValue(), notNullValue());
- assertThat(referenceAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens(), not(empty()));
- assertThat(referenceAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens()
- .get(0).getValue(),
+ ReferenceAndListParam referenceAndListParam = serviceRequestSearchParamsArgumentCaptor.getValue()
+ .getParticipantReference();
+ assertThat(referenceAndListParam, notNullValue());
+ assertThat(referenceAndListParam.getValuesAsQueryTokens(), not(empty()));
+ assertThat(referenceAndListParam.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getValue(),
equalTo(PARTICIPANT_FAMILY_NAME));
- assertThat(referenceAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens()
- .get(0).getChain(),
+ assertThat(referenceAndListParam.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getChain(),
equalTo(Practitioner.SP_FAMILY));
}
@@ -386,33 +364,59 @@ public void searchForServiceRequests_shouldSearchForServiceRequestsByParticipant
public void searchForServiceRequests_shouldSearchForServiceRequestsByParticipantIdentifier() throws Exception {
verifyUri(String.format("/ProcedureRequest?requester.identifier=%s", PARTICIPANT_IDENTIFIER));
- verify(service).searchForServiceRequests(isNull(), isNull(), isNull(), referenceAndListParamArgumentCaptor.capture(),
- isNull(), isNull(), isNull(), isNull());
+ verify(service).searchForServiceRequests(serviceRequestSearchParamsArgumentCaptor.capture());
- assertThat(referenceAndListParamArgumentCaptor.getValue(), notNullValue());
- assertThat(referenceAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens(), not(empty()));
- assertThat(referenceAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens()
- .get(0).getValue(),
+ ReferenceAndListParam referenceAndListParam = serviceRequestSearchParamsArgumentCaptor.getValue()
+ .getParticipantReference();
+ assertThat(referenceAndListParam, notNullValue());
+ assertThat(referenceAndListParam.getValuesAsQueryTokens(), not(empty()));
+ assertThat(referenceAndListParam.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getValue(),
equalTo(PARTICIPANT_IDENTIFIER));
- assertThat(referenceAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens()
- .get(0).getChain(),
+ assertThat(referenceAndListParam.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getChain(),
equalTo(Practitioner.SP_IDENTIFIER));
}
+ @Test
+ public void searchForServiceRequests_shouldHandleComplexQuery() throws Exception {
+ verifyUri(
+ String.format("/ProcedureRequest?requester.given=%s&occurrence=eq%s", PARTICIPANT_GIVEN_NAME, OCCURRENCE_DATE));
+
+ verify(service).searchForServiceRequests(serviceRequestSearchParamsArgumentCaptor.capture());
+
+ ReferenceAndListParam referenceAndListParam = serviceRequestSearchParamsArgumentCaptor.getValue()
+ .getParticipantReference();
+ assertThat(referenceAndListParam, notNullValue());
+ assertThat(referenceAndListParam.getValuesAsQueryTokens(), not(empty()));
+ assertThat(referenceAndListParam.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getValue(),
+ equalTo(PARTICIPANT_GIVEN_NAME));
+ assertThat(referenceAndListParam.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getChain(),
+ equalTo(Practitioner.SP_GIVEN));
+
+ DateRangeParam dateRangeParam = serviceRequestSearchParamsArgumentCaptor.getValue().getOccurrence();
+ assertThat(dateRangeParam, notNullValue());
+
+ Calendar calendar = Calendar.getInstance();
+ calendar.set(2010, Calendar.MARCH, 31);
+
+ assertThat(dateRangeParam.getLowerBound().getValue(),
+ equalTo(DateUtils.truncate(calendar.getTime(), Calendar.DATE)));
+ assertThat(dateRangeParam.getUpperBound().getValue(),
+ equalTo(DateUtils.truncate(calendar.getTime(), Calendar.DATE)));
+ }
+
@Test
public void searchForServiceRequests_shouldSearchForServiceRequestsByEncounterUUID() throws Exception {
verifyUri(String.format("/ProcedureRequest?encounter=%s", ENCOUNTER_UUID));
- verify(service).searchForServiceRequests(isNull(), isNull(), referenceAndListParamArgumentCaptor.capture(), isNull(),
- isNull(), isNull(), isNull(), isNull());
+ verify(service).searchForServiceRequests(serviceRequestSearchParamsArgumentCaptor.capture());
- assertThat(referenceAndListParamArgumentCaptor.getValue(), notNullValue());
- assertThat(referenceAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens(), not(empty()));
- assertThat(referenceAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens()
- .get(0).getValue(),
+ ReferenceAndListParam referenceAndListParam = serviceRequestSearchParamsArgumentCaptor.getValue()
+ .getEncounterReference();
+ assertThat(referenceAndListParam, notNullValue());
+ assertThat(referenceAndListParam.getValuesAsQueryTokens(), not(empty()));
+ assertThat(referenceAndListParam.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getValue(),
equalTo(ENCOUNTER_UUID));
- assertThat(referenceAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens()
- .get(0).getChain(),
+ assertThat(referenceAndListParam.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getChain(),
equalTo(null));
}
@@ -420,13 +424,12 @@ public void searchForServiceRequests_shouldSearchForServiceRequestsByEncounterUU
public void searchForServiceRequests_shouldSearchForServiceRequestsByCode() throws Exception {
verifyUri(String.format("/ProcedureRequest?code=%s", CODE));
- verify(service).searchForServiceRequests(isNull(), tokenAndListParamArgumentCaptor.capture(), isNull(), isNull(),
- isNull(), isNull(), isNull(), isNull());
+ verify(service).searchForServiceRequests(serviceRequestSearchParamsArgumentCaptor.capture());
- assertThat(tokenAndListParamArgumentCaptor.getValue(), notNullValue());
- assertThat(tokenAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens(), not(empty()));
- assertThat(tokenAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0)
- .getValue(),
+ TokenAndListParam tokenAndListParam = serviceRequestSearchParamsArgumentCaptor.getValue().getCode();
+ assertThat(tokenAndListParam, notNullValue());
+ assertThat(tokenAndListParam.getValuesAsQueryTokens(), not(empty()));
+ assertThat(tokenAndListParam.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getValue(),
equalTo(CODE));
}
@@ -434,45 +437,17 @@ public void searchForServiceRequests_shouldSearchForServiceRequestsByCode() thro
public void searchForServiceRequests_shouldSearchForServiceRequestsByOccurrence() throws Exception {
verifyUri(String.format("/ProcedureRequest?occurrence=eq%s", OCCURRENCE_DATE));
- verify(service).searchForServiceRequests(isNull(), isNull(), isNull(), isNull(),
- dateRangeParamArgumentCaptor.capture(), isNull(), isNull(), isNull());
-
- assertThat(dateRangeParamArgumentCaptor.getValue(), notNullValue());
-
- Calendar calendar = Calendar.getInstance();
- calendar.set(2010, Calendar.MARCH, 31);
-
- assertThat(dateRangeParamArgumentCaptor.getValue().getLowerBound().getValue(),
- equalTo(DateUtils.truncate(calendar.getTime(), Calendar.DATE)));
- assertThat(dateRangeParamArgumentCaptor.getValue().getUpperBound().getValue(),
- equalTo(DateUtils.truncate(calendar.getTime(), Calendar.DATE)));
- }
-
- @Test
- public void searchForServiceRequests_shouldHandleComplexQuery() throws Exception {
- verifyUri(
- String.format("/ProcedureRequest?requester.given=%s&occurrence=eq%s", PARTICIPANT_GIVEN_NAME, OCCURRENCE_DATE));
-
- verify(service).searchForServiceRequests(isNull(), isNull(), isNull(), referenceAndListParamArgumentCaptor.capture(),
- dateRangeParamArgumentCaptor.capture(), isNull(), isNull(), isNull());
-
- assertThat(referenceAndListParamArgumentCaptor.getValue(), notNullValue());
- assertThat(referenceAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens(), not(empty()));
- assertThat(referenceAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens()
- .get(0).getValue(),
- equalTo(PARTICIPANT_GIVEN_NAME));
- assertThat(referenceAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens()
- .get(0).getChain(),
- equalTo(Practitioner.SP_GIVEN));
+ verify(service).searchForServiceRequests(serviceRequestSearchParamsArgumentCaptor.capture());
- assertThat(dateRangeParamArgumentCaptor.getValue(), notNullValue());
+ DateRangeParam dateRangeParam = serviceRequestSearchParamsArgumentCaptor.getValue().getOccurrence();
+ assertThat(dateRangeParam, notNullValue());
Calendar calendar = Calendar.getInstance();
calendar.set(2010, Calendar.MARCH, 31);
- assertThat(dateRangeParamArgumentCaptor.getValue().getLowerBound().getValue(),
+ assertThat(dateRangeParam.getLowerBound().getValue(),
equalTo(DateUtils.truncate(calendar.getTime(), Calendar.DATE)));
- assertThat(dateRangeParamArgumentCaptor.getValue().getUpperBound().getValue(),
+ assertThat(dateRangeParam.getUpperBound().getValue(),
equalTo(DateUtils.truncate(calendar.getTime(), Calendar.DATE)));
}
@@ -480,13 +455,12 @@ public void searchForServiceRequests_shouldHandleComplexQuery() throws Exception
public void searchForProcedureRequests_shouldSearchForProcedureRequestsByUUID() throws Exception {
verifyUri(String.format("/ProcedureRequest?_id=%s", SERVICE_REQUEST_UUID));
- verify(service).searchForServiceRequests(isNull(), isNull(), isNull(), isNull(), isNull(),
- tokenAndListParamArgumentCaptor.capture(), isNull(), isNull());
+ verify(service).searchForServiceRequests(serviceRequestSearchParamsArgumentCaptor.capture());
- assertThat(tokenAndListParamArgumentCaptor.getValue(), notNullValue());
- assertThat(tokenAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens(), not(empty()));
- assertThat(tokenAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0)
- .getValue(),
+ TokenAndListParam tokenAndListParam = serviceRequestSearchParamsArgumentCaptor.getValue().getUuid();
+ assertThat(tokenAndListParam, notNullValue());
+ assertThat(tokenAndListParam.getValuesAsQueryTokens(), not(empty()));
+ assertThat(tokenAndListParam.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getValue(),
equalTo(SERVICE_REQUEST_UUID));
}
@@ -494,17 +468,17 @@ public void searchForProcedureRequests_shouldSearchForProcedureRequestsByUUID()
public void searchForProcedureRequests_shouldSearchForProcedureRequestsByLastUpdatedDate() throws Exception {
verifyUri(String.format("/ProcedureRequest?_lastUpdated=%s", LAST_UPDATED_DATE));
- verify(service).searchForServiceRequests(isNull(), isNull(), isNull(), isNull(), isNull(), isNull(),
- dateRangeParamArgumentCaptor.capture(), isNull());
+ verify(service).searchForServiceRequests(serviceRequestSearchParamsArgumentCaptor.capture());
- assertThat(dateRangeParamArgumentCaptor.getValue(), notNullValue());
+ DateRangeParam dateRangeParam = serviceRequestSearchParamsArgumentCaptor.getValue().getLastUpdated();
+ assertThat(dateRangeParam, notNullValue());
Calendar calendar = Calendar.getInstance();
calendar.set(2020, Calendar.SEPTEMBER, 3);
- assertThat(dateRangeParamArgumentCaptor.getValue().getLowerBound().getValue(),
+ assertThat(dateRangeParam.getLowerBound().getValue(),
equalTo(DateUtils.truncate(calendar.getTime(), Calendar.DATE)));
- assertThat(dateRangeParamArgumentCaptor.getValue().getUpperBound().getValue(),
+ assertThat(dateRangeParam.getUpperBound().getValue(),
equalTo(DateUtils.truncate(calendar.getTime(), Calendar.DATE)));
}
@@ -512,71 +486,63 @@ public void searchForProcedureRequests_shouldSearchForProcedureRequestsByLastUpd
public void searchForServiceRequests_shouldAddRelatedPatientsWhenIncluded() throws Exception {
verifyUri("/ProcedureRequest?_include=ProcedureRequest:patient");
- verify(service).searchForServiceRequests(isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull(),
- includeArgumentCaptor.capture());
+ verify(service).searchForServiceRequests(serviceRequestSearchParamsArgumentCaptor.capture());
- assertThat(includeArgumentCaptor.getValue(), notNullValue());
- assertThat(includeArgumentCaptor.getValue().size(), equalTo(1));
- assertThat(includeArgumentCaptor.getValue().iterator().next().getParamName(),
- equalTo(FhirConstants.INCLUDE_PATIENT_PARAM));
- assertThat(includeArgumentCaptor.getValue().iterator().next().getParamType(),
- equalTo(FhirConstants.PROCEDURE_REQUEST));
+ HashSet include = serviceRequestSearchParamsArgumentCaptor.getValue().getIncludes();
+ assertThat(include, notNullValue());
+ assertThat(include.size(), equalTo(1));
+ assertThat(include.iterator().next().getParamName(), equalTo(FhirConstants.INCLUDE_PATIENT_PARAM));
+ assertThat(include.iterator().next().getParamType(), equalTo(FhirConstants.PROCEDURE_REQUEST));
}
@Test
public void searchForServiceRequests_shouldAddRelatedRequesterWhenIncluded() throws Exception {
verifyUri("/ProcedureRequest?_include=ProcedureRequest:requester");
- verify(service).searchForServiceRequests(isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull(),
- includeArgumentCaptor.capture());
+ verify(service).searchForServiceRequests(serviceRequestSearchParamsArgumentCaptor.capture());
- assertThat(includeArgumentCaptor.getValue(), notNullValue());
- assertThat(includeArgumentCaptor.getValue().size(), equalTo(1));
- assertThat(includeArgumentCaptor.getValue().iterator().next().getParamName(),
- equalTo(FhirConstants.INCLUDE_REQUESTER_PARAM));
- assertThat(includeArgumentCaptor.getValue().iterator().next().getParamType(),
- equalTo(FhirConstants.PROCEDURE_REQUEST));
+ HashSet include = serviceRequestSearchParamsArgumentCaptor.getValue().getIncludes();
+ assertThat(include, notNullValue());
+ assertThat(include.size(), equalTo(1));
+ assertThat(include.iterator().next().getParamName(), equalTo(FhirConstants.INCLUDE_REQUESTER_PARAM));
+ assertThat(include.iterator().next().getParamType(), equalTo(FhirConstants.PROCEDURE_REQUEST));
}
@Test
public void searchForServiceRequests_shouldAddRelatedEncounterWhenIncluded() throws Exception {
verifyUri("/ProcedureRequest?_include=ProcedureRequest:encounter");
- verify(service).searchForServiceRequests(isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull(),
- includeArgumentCaptor.capture());
+ verify(service).searchForServiceRequests(serviceRequestSearchParamsArgumentCaptor.capture());
- assertThat(includeArgumentCaptor.getValue(), notNullValue());
- assertThat(includeArgumentCaptor.getValue().size(), equalTo(1));
- assertThat(includeArgumentCaptor.getValue().iterator().next().getParamName(),
- equalTo(FhirConstants.INCLUDE_ENCOUNTER_PARAM));
- assertThat(includeArgumentCaptor.getValue().iterator().next().getParamType(),
- equalTo(FhirConstants.PROCEDURE_REQUEST));
+ HashSet include = serviceRequestSearchParamsArgumentCaptor.getValue().getIncludes();
+ assertThat(include, notNullValue());
+ assertThat(include.size(), equalTo(1));
+ assertThat(include.iterator().next().getParamName(), equalTo(FhirConstants.INCLUDE_ENCOUNTER_PARAM));
+ assertThat(include.iterator().next().getParamType(), equalTo(FhirConstants.PROCEDURE_REQUEST));
}
@Test
public void searchForServiceRequests_shouldHandleMultipleIncludes() throws Exception {
verifyUri("/ProcedureRequest?_include=ProcedureRequest:requester&_include=ProcedureRequest:patient");
- verify(service).searchForServiceRequests(isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull(),
- includeArgumentCaptor.capture());
+ verify(service).searchForServiceRequests(serviceRequestSearchParamsArgumentCaptor.capture());
- assertThat(includeArgumentCaptor.getValue(), notNullValue());
- assertThat(includeArgumentCaptor.getValue().size(), equalTo(2));
+ HashSet include = serviceRequestSearchParamsArgumentCaptor.getValue().getIncludes();
+ assertThat(include, notNullValue());
+ assertThat(include.size(), equalTo(2));
- assertThat(includeArgumentCaptor.getValue(),
- hasItem(allOf(hasProperty("paramName", equalTo(FhirConstants.INCLUDE_REQUESTER_PARAM)),
- hasProperty("paramType", equalTo(FhirConstants.PROCEDURE_REQUEST)))));
- assertThat(includeArgumentCaptor.getValue(),
- hasItem(allOf(hasProperty("paramName", equalTo(FhirConstants.INCLUDE_PATIENT_PARAM)),
- hasProperty("paramType", equalTo(FhirConstants.PROCEDURE_REQUEST)))));
+ assertThat(include, hasItem(allOf(hasProperty("paramName", equalTo(FhirConstants.INCLUDE_REQUESTER_PARAM)),
+ hasProperty("paramType", equalTo(FhirConstants.PROCEDURE_REQUEST)))));
+ assertThat(include, hasItem(allOf(hasProperty("paramName", equalTo(FhirConstants.INCLUDE_PATIENT_PARAM)),
+ hasProperty("paramType", equalTo(FhirConstants.PROCEDURE_REQUEST)))));
}
-
+
@Test
public void searchForServiceRequests_shouldHandleHasAndListParameter() throws Exception {
verifyUri("/ServiceRequest?_has:Observation:based-on:category:not=laboratory");
verify(service).searchForServiceRequests(serviceRequestSearchParamsArgumentCaptor.capture());
-
+
HasAndListParam hasAndListParam = serviceRequestSearchParamsArgumentCaptor.getValue().getHasAndListParam();
assertThat(hasAndListParam, notNullValue());
assertThat(hasAndListParam.size(), equalTo(1));
@@ -633,7 +599,7 @@ private void verifyUri(String uri) throws Exception {
ProcedureRequest procedureRequest = new ProcedureRequest();
procedureRequest.setId(SERVICE_REQUEST_UUID);
- when(service.searchForServiceRequests(any(), any(), any(), any(), any(), any(), any(), any()))
+ when(service.searchForServiceRequests(any()))
.thenReturn(new MockIBundleProvider<>(Collections.singletonList(procedureRequest), 10, 1));
MockHttpServletResponse response = get(uri).accept(FhirMediaTypes.JSON).go();
diff --git a/omod/src/test/java/org/openmrs/module/fhir2/providers/r4/ServiceRequestFhirResourceProviderWebTest.java b/omod/src/test/java/org/openmrs/module/fhir2/providers/r4/ServiceRequestFhirResourceProviderWebTest.java
index f40685c236..f288601e95 100644
--- a/omod/src/test/java/org/openmrs/module/fhir2/providers/r4/ServiceRequestFhirResourceProviderWebTest.java
+++ b/omod/src/test/java/org/openmrs/module/fhir2/providers/r4/ServiceRequestFhirResourceProviderWebTest.java
@@ -18,7 +18,6 @@
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.notNullValue;
import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.isNull;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -94,19 +93,7 @@ public class ServiceRequestFhirResourceProviderWebTest extends BaseFhirR4Resourc
private FhirServiceRequestService service;
@Captor
- private ArgumentCaptor referenceAndListParamArgumentCaptor;
-
- @Captor
- private ArgumentCaptor tokenAndListParamArgumentCaptor;
-
- @Captor
- private ArgumentCaptor dateRangeParamArgumentCaptor;
-
- @Captor
- private ArgumentCaptor> includeArgumentCaptor;
-
- @Captor
- private ArgumentCaptor paramCaptor;
+ private ArgumentCaptor serviceRequestSearchParamsArgumentCaptor;
private ServiceRequest serviceRequest;
@@ -154,16 +141,15 @@ public void getServiceRequestByWrongUuid_shouldReturn404() throws Exception {
public void searchForServiceRequests_shouldSearchForServiceRequestsByPatientUUID() throws Exception {
verifyUri(String.format("/ServiceRequest?patient=%s", PATIENT_UUID));
- verify(service).searchForServiceRequests(referenceAndListParamArgumentCaptor.capture(), isNull(), isNull(), isNull(),
- isNull(), isNull(), isNull(), isNull());
+ verify(service).searchForServiceRequests(serviceRequestSearchParamsArgumentCaptor.capture());
- assertThat(referenceAndListParamArgumentCaptor.getValue(), notNullValue());
- assertThat(referenceAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens(), not(empty()));
- assertThat(referenceAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens()
- .get(0).getValue(),
+ ReferenceAndListParam referenceAndListParam = serviceRequestSearchParamsArgumentCaptor.getValue()
+ .getPatientReference();
+ assertThat(referenceAndListParam, notNullValue());
+ assertThat(referenceAndListParam.getValuesAsQueryTokens(), not(empty()));
+ assertThat(referenceAndListParam.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getValue(),
equalTo(PATIENT_UUID));
- assertThat(referenceAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens()
- .get(0).getChain(),
+ assertThat(referenceAndListParam.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getChain(),
equalTo(null));
}
@@ -171,16 +157,15 @@ public void searchForServiceRequests_shouldSearchForServiceRequestsByPatientUUID
public void searchForServiceRequests_shouldSearchForServiceRequestsByPatientName() throws Exception {
verifyUri(String.format("/ServiceRequest?patient.name=%s", PATIENT_GIVEN_NAME));
- verify(service).searchForServiceRequests(referenceAndListParamArgumentCaptor.capture(), isNull(), isNull(), isNull(),
- isNull(), isNull(), isNull(), isNull());
+ verify(service).searchForServiceRequests(serviceRequestSearchParamsArgumentCaptor.capture());
- assertThat(referenceAndListParamArgumentCaptor.getValue(), notNullValue());
- assertThat(referenceAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens(), not(empty()));
- assertThat(referenceAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens()
- .get(0).getValue(),
+ ReferenceAndListParam referenceAndListParam = serviceRequestSearchParamsArgumentCaptor.getValue()
+ .getPatientReference();
+ assertThat(referenceAndListParam, notNullValue());
+ assertThat(referenceAndListParam.getValuesAsQueryTokens(), not(empty()));
+ assertThat(referenceAndListParam.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getValue(),
equalTo(PATIENT_GIVEN_NAME));
- assertThat(referenceAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens()
- .get(0).getChain(),
+ assertThat(referenceAndListParam.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getChain(),
equalTo(Patient.SP_NAME));
}
@@ -188,16 +173,15 @@ public void searchForServiceRequests_shouldSearchForServiceRequestsByPatientName
public void searchForServiceRequests_shouldSearchForServiceRequestsByPatientGivenName() throws Exception {
verifyUri(String.format("/ServiceRequest?patient.given=%s", PATIENT_GIVEN_NAME));
- verify(service).searchForServiceRequests(referenceAndListParamArgumentCaptor.capture(), isNull(), isNull(), isNull(),
- isNull(), isNull(), isNull(), isNull());
+ verify(service).searchForServiceRequests(serviceRequestSearchParamsArgumentCaptor.capture());
- assertThat(referenceAndListParamArgumentCaptor.getValue(), notNullValue());
- assertThat(referenceAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens(), not(empty()));
- assertThat(referenceAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens()
- .get(0).getValue(),
+ ReferenceAndListParam referenceAndListParam = serviceRequestSearchParamsArgumentCaptor.getValue()
+ .getPatientReference();
+ assertThat(referenceAndListParam, notNullValue());
+ assertThat(referenceAndListParam.getValuesAsQueryTokens(), not(empty()));
+ assertThat(referenceAndListParam.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getValue(),
equalTo(PATIENT_GIVEN_NAME));
- assertThat(referenceAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens()
- .get(0).getChain(),
+ assertThat(referenceAndListParam.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getChain(),
equalTo(Patient.SP_GIVEN));
}
@@ -205,16 +189,15 @@ public void searchForServiceRequests_shouldSearchForServiceRequestsByPatientGive
public void searchForServiceRequests_shouldSearchForServiceRequestsByPatientFamilyName() throws Exception {
verifyUri(String.format("/ServiceRequest?patient.family=%s", PATIENT_FAMILY_NAME));
- verify(service).searchForServiceRequests(referenceAndListParamArgumentCaptor.capture(), isNull(), isNull(), isNull(),
- isNull(), isNull(), isNull(), isNull());
+ verify(service).searchForServiceRequests(serviceRequestSearchParamsArgumentCaptor.capture());
- assertThat(referenceAndListParamArgumentCaptor.getValue(), notNullValue());
- assertThat(referenceAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens(), not(empty()));
- assertThat(referenceAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens()
- .get(0).getValue(),
+ ReferenceAndListParam referenceAndListParam = serviceRequestSearchParamsArgumentCaptor.getValue()
+ .getPatientReference();
+ assertThat(referenceAndListParam, notNullValue());
+ assertThat(referenceAndListParam.getValuesAsQueryTokens(), not(empty()));
+ assertThat(referenceAndListParam.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getValue(),
equalTo(PATIENT_FAMILY_NAME));
- assertThat(referenceAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens()
- .get(0).getChain(),
+ assertThat(referenceAndListParam.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getChain(),
equalTo(Patient.SP_FAMILY));
}
@@ -222,16 +205,15 @@ public void searchForServiceRequests_shouldSearchForServiceRequestsByPatientFami
public void searchForServiceRequests_shouldSearchForServiceRequestsByPatientIdentifier() throws Exception {
verifyUri(String.format("/ServiceRequest?patient.identifier=%s", PATIENT_IDENTIFIER));
- verify(service).searchForServiceRequests(referenceAndListParamArgumentCaptor.capture(), isNull(), isNull(), isNull(),
- isNull(), isNull(), isNull(), isNull());
+ verify(service).searchForServiceRequests(serviceRequestSearchParamsArgumentCaptor.capture());
- assertThat(referenceAndListParamArgumentCaptor.getValue(), notNullValue());
- assertThat(referenceAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens(), not(empty()));
- assertThat(referenceAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens()
- .get(0).getValue(),
+ ReferenceAndListParam referenceAndListParam = serviceRequestSearchParamsArgumentCaptor.getValue()
+ .getPatientReference();
+ assertThat(referenceAndListParam, notNullValue());
+ assertThat(referenceAndListParam.getValuesAsQueryTokens(), not(empty()));
+ assertThat(referenceAndListParam.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getValue(),
equalTo(PATIENT_IDENTIFIER));
- assertThat(referenceAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens()
- .get(0).getChain(),
+ assertThat(referenceAndListParam.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getChain(),
equalTo(Patient.SP_IDENTIFIER));
}
@@ -239,16 +221,15 @@ public void searchForServiceRequests_shouldSearchForServiceRequestsByPatientIden
public void searchForServiceRequests_shouldSearchForServiceRequestsBySubjectUUID() throws Exception {
verifyUri(String.format("/ServiceRequest?subject=%s", PATIENT_UUID));
- verify(service).searchForServiceRequests(referenceAndListParamArgumentCaptor.capture(), isNull(), isNull(), isNull(),
- isNull(), isNull(), isNull(), isNull());
+ verify(service).searchForServiceRequests(serviceRequestSearchParamsArgumentCaptor.capture());
- assertThat(referenceAndListParamArgumentCaptor.getValue(), notNullValue());
- assertThat(referenceAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens(), not(empty()));
- assertThat(referenceAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens()
- .get(0).getValue(),
+ ReferenceAndListParam referenceAndListParam = serviceRequestSearchParamsArgumentCaptor.getValue()
+ .getPatientReference();
+ assertThat(referenceAndListParam, notNullValue());
+ assertThat(referenceAndListParam.getValuesAsQueryTokens(), not(empty()));
+ assertThat(referenceAndListParam.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getValue(),
equalTo(PATIENT_UUID));
- assertThat(referenceAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens()
- .get(0).getChain(),
+ assertThat(referenceAndListParam.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getChain(),
equalTo(null));
}
@@ -256,16 +237,15 @@ public void searchForServiceRequests_shouldSearchForServiceRequestsBySubjectUUID
public void searchForServiceRequests_shouldSearchForServiceRequestsBySubjectName() throws Exception {
verifyUri(String.format("/ServiceRequest?subject.name=%s", PATIENT_GIVEN_NAME));
- verify(service).searchForServiceRequests(referenceAndListParamArgumentCaptor.capture(), isNull(), isNull(), isNull(),
- isNull(), isNull(), isNull(), isNull());
+ verify(service).searchForServiceRequests(serviceRequestSearchParamsArgumentCaptor.capture());
- assertThat(referenceAndListParamArgumentCaptor.getValue(), notNullValue());
- assertThat(referenceAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens(), not(empty()));
- assertThat(referenceAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens()
- .get(0).getValue(),
+ ReferenceAndListParam referenceAndListParam = serviceRequestSearchParamsArgumentCaptor.getValue()
+ .getPatientReference();
+ assertThat(referenceAndListParam, notNullValue());
+ assertThat(referenceAndListParam.getValuesAsQueryTokens(), not(empty()));
+ assertThat(referenceAndListParam.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getValue(),
equalTo(PATIENT_GIVEN_NAME));
- assertThat(referenceAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens()
- .get(0).getChain(),
+ assertThat(referenceAndListParam.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getChain(),
equalTo(Patient.SP_NAME));
}
@@ -273,16 +253,15 @@ public void searchForServiceRequests_shouldSearchForServiceRequestsBySubjectName
public void searchForServiceRequests_shouldSearchForServiceRequestsBySubjectGivenName() throws Exception {
verifyUri(String.format("/ServiceRequest?subject.given=%s", PATIENT_GIVEN_NAME));
- verify(service).searchForServiceRequests(referenceAndListParamArgumentCaptor.capture(), isNull(), isNull(), isNull(),
- isNull(), isNull(), isNull(), isNull());
+ verify(service).searchForServiceRequests(serviceRequestSearchParamsArgumentCaptor.capture());
- assertThat(referenceAndListParamArgumentCaptor.getValue(), notNullValue());
- assertThat(referenceAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens(), not(empty()));
- assertThat(referenceAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens()
- .get(0).getValue(),
+ ReferenceAndListParam referenceAndListParam = serviceRequestSearchParamsArgumentCaptor.getValue()
+ .getPatientReference();
+ assertThat(referenceAndListParam, notNullValue());
+ assertThat(referenceAndListParam.getValuesAsQueryTokens(), not(empty()));
+ assertThat(referenceAndListParam.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getValue(),
equalTo(PATIENT_GIVEN_NAME));
- assertThat(referenceAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens()
- .get(0).getChain(),
+ assertThat(referenceAndListParam.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getChain(),
equalTo(Patient.SP_GIVEN));
}
@@ -290,16 +269,15 @@ public void searchForServiceRequests_shouldSearchForServiceRequestsBySubjectGive
public void searchForServiceRequests_shouldSearchForServiceRequestsBySubjectFamilyName() throws Exception {
verifyUri(String.format("/ServiceRequest?subject.family=%s", PATIENT_FAMILY_NAME));
- verify(service).searchForServiceRequests(referenceAndListParamArgumentCaptor.capture(), isNull(), isNull(), isNull(),
- isNull(), isNull(), isNull(), isNull());
+ verify(service).searchForServiceRequests(serviceRequestSearchParamsArgumentCaptor.capture());
- assertThat(referenceAndListParamArgumentCaptor.getValue(), notNullValue());
- assertThat(referenceAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens(), not(empty()));
- assertThat(referenceAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens()
- .get(0).getValue(),
+ ReferenceAndListParam referenceAndListParam = serviceRequestSearchParamsArgumentCaptor.getValue()
+ .getPatientReference();
+ assertThat(referenceAndListParam, notNullValue());
+ assertThat(referenceAndListParam.getValuesAsQueryTokens(), not(empty()));
+ assertThat(referenceAndListParam.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getValue(),
equalTo(PATIENT_FAMILY_NAME));
- assertThat(referenceAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens()
- .get(0).getChain(),
+ assertThat(referenceAndListParam.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getChain(),
equalTo(Patient.SP_FAMILY));
}
@@ -307,16 +285,15 @@ public void searchForServiceRequests_shouldSearchForServiceRequestsBySubjectFami
public void searchForServiceRequests_shouldSearchForServiceRequestsBySubjectIdentifier() throws Exception {
verifyUri(String.format("/ServiceRequest?subject.identifier=%s", PATIENT_IDENTIFIER));
- verify(service).searchForServiceRequests(referenceAndListParamArgumentCaptor.capture(), isNull(), isNull(), isNull(),
- isNull(), isNull(), isNull(), isNull());
+ verify(service).searchForServiceRequests(serviceRequestSearchParamsArgumentCaptor.capture());
- assertThat(referenceAndListParamArgumentCaptor.getValue(), notNullValue());
- assertThat(referenceAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens(), not(empty()));
- assertThat(referenceAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens()
- .get(0).getValue(),
+ ReferenceAndListParam referenceAndListParam = serviceRequestSearchParamsArgumentCaptor.getValue()
+ .getPatientReference();
+ assertThat(referenceAndListParam, notNullValue());
+ assertThat(referenceAndListParam.getValuesAsQueryTokens(), not(empty()));
+ assertThat(referenceAndListParam.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getValue(),
equalTo(PATIENT_IDENTIFIER));
- assertThat(referenceAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens()
- .get(0).getChain(),
+ assertThat(referenceAndListParam.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getChain(),
equalTo(Patient.SP_IDENTIFIER));
}
@@ -324,16 +301,15 @@ public void searchForServiceRequests_shouldSearchForServiceRequestsBySubjectIden
public void searchForServiceRequests_shouldSearchForServiceRequestsByParticipantUUID() throws Exception {
verifyUri(String.format("/ServiceRequest?requester=%s", PARTICIPANT_UUID));
- verify(service).searchForServiceRequests(isNull(), isNull(), isNull(), referenceAndListParamArgumentCaptor.capture(),
- isNull(), isNull(), isNull(), isNull());
+ verify(service).searchForServiceRequests(serviceRequestSearchParamsArgumentCaptor.capture());
- assertThat(referenceAndListParamArgumentCaptor.getValue(), notNullValue());
- assertThat(referenceAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens(), not(empty()));
- assertThat(referenceAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens()
- .get(0).getValue(),
+ ReferenceAndListParam referenceAndListParam = serviceRequestSearchParamsArgumentCaptor.getValue()
+ .getParticipantReference();
+ assertThat(referenceAndListParam, notNullValue());
+ assertThat(referenceAndListParam.getValuesAsQueryTokens(), not(empty()));
+ assertThat(referenceAndListParam.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getValue(),
equalTo(PARTICIPANT_UUID));
- assertThat(referenceAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens()
- .get(0).getChain(),
+ assertThat(referenceAndListParam.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getChain(),
equalTo(null));
}
@@ -341,16 +317,15 @@ public void searchForServiceRequests_shouldSearchForServiceRequestsByParticipant
public void searchForServiceRequests_shouldSearchForServiceRequestsByParticipantName() throws Exception {
verifyUri(String.format("/ServiceRequest?requester.name=%s", PARTICIPANT_GIVEN_NAME));
- verify(service).searchForServiceRequests(isNull(), isNull(), isNull(), referenceAndListParamArgumentCaptor.capture(),
- isNull(), isNull(), isNull(), isNull());
+ verify(service).searchForServiceRequests(serviceRequestSearchParamsArgumentCaptor.capture());
- assertThat(referenceAndListParamArgumentCaptor.getValue(), notNullValue());
- assertThat(referenceAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens(), not(empty()));
- assertThat(referenceAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens()
- .get(0).getValue(),
+ ReferenceAndListParam referenceAndListParam = serviceRequestSearchParamsArgumentCaptor.getValue()
+ .getParticipantReference();
+ assertThat(referenceAndListParam, notNullValue());
+ assertThat(referenceAndListParam.getValuesAsQueryTokens(), not(empty()));
+ assertThat(referenceAndListParam.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getValue(),
equalTo(PARTICIPANT_GIVEN_NAME));
- assertThat(referenceAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens()
- .get(0).getChain(),
+ assertThat(referenceAndListParam.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getChain(),
equalTo(Practitioner.SP_NAME));
}
@@ -358,16 +333,15 @@ public void searchForServiceRequests_shouldSearchForServiceRequestsByParticipant
public void searchForServiceRequests_shouldSearchForServiceRequestsByParticipantGivenName() throws Exception {
verifyUri(String.format("/ServiceRequest?requester.given=%s", PARTICIPANT_GIVEN_NAME));
- verify(service).searchForServiceRequests(isNull(), isNull(), isNull(), referenceAndListParamArgumentCaptor.capture(),
- isNull(), isNull(), isNull(), isNull());
+ verify(service).searchForServiceRequests(serviceRequestSearchParamsArgumentCaptor.capture());
- assertThat(referenceAndListParamArgumentCaptor.getValue(), notNullValue());
- assertThat(referenceAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens(), not(empty()));
- assertThat(referenceAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens()
- .get(0).getValue(),
+ ReferenceAndListParam referenceAndListParam = serviceRequestSearchParamsArgumentCaptor.getValue()
+ .getParticipantReference();
+ assertThat(referenceAndListParam, notNullValue());
+ assertThat(referenceAndListParam.getValuesAsQueryTokens(), not(empty()));
+ assertThat(referenceAndListParam.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getValue(),
equalTo(PARTICIPANT_GIVEN_NAME));
- assertThat(referenceAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens()
- .get(0).getChain(),
+ assertThat(referenceAndListParam.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getChain(),
equalTo(Practitioner.SP_GIVEN));
}
@@ -375,16 +349,15 @@ public void searchForServiceRequests_shouldSearchForServiceRequestsByParticipant
public void searchForServiceRequests_shouldSearchForServiceRequestsByParticipantFamilyName() throws Exception {
verifyUri(String.format("/ServiceRequest?requester.family=%s", PARTICIPANT_FAMILY_NAME));
- verify(service).searchForServiceRequests(isNull(), isNull(), isNull(), referenceAndListParamArgumentCaptor.capture(),
- isNull(), isNull(), isNull(), isNull());
+ verify(service).searchForServiceRequests(serviceRequestSearchParamsArgumentCaptor.capture());
- assertThat(referenceAndListParamArgumentCaptor.getValue(), notNullValue());
- assertThat(referenceAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens(), not(empty()));
- assertThat(referenceAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens()
- .get(0).getValue(),
+ ReferenceAndListParam referenceAndListParam = serviceRequestSearchParamsArgumentCaptor.getValue()
+ .getParticipantReference();
+ assertThat(referenceAndListParam, notNullValue());
+ assertThat(referenceAndListParam.getValuesAsQueryTokens(), not(empty()));
+ assertThat(referenceAndListParam.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getValue(),
equalTo(PARTICIPANT_FAMILY_NAME));
- assertThat(referenceAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens()
- .get(0).getChain(),
+ assertThat(referenceAndListParam.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getChain(),
equalTo(Practitioner.SP_FAMILY));
}
@@ -392,33 +365,59 @@ public void searchForServiceRequests_shouldSearchForServiceRequestsByParticipant
public void searchForServiceRequests_shouldSearchForServiceRequestsByParticipantIdentifier() throws Exception {
verifyUri(String.format("/ServiceRequest?requester.identifier=%s", PARTICIPANT_IDENTIFIER));
- verify(service).searchForServiceRequests(isNull(), isNull(), isNull(), referenceAndListParamArgumentCaptor.capture(),
- isNull(), isNull(), isNull(), isNull());
+ verify(service).searchForServiceRequests(serviceRequestSearchParamsArgumentCaptor.capture());
- assertThat(referenceAndListParamArgumentCaptor.getValue(), notNullValue());
- assertThat(referenceAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens(), not(empty()));
- assertThat(referenceAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens()
- .get(0).getValue(),
+ ReferenceAndListParam referenceAndListParam = serviceRequestSearchParamsArgumentCaptor.getValue()
+ .getParticipantReference();
+ assertThat(referenceAndListParam, notNullValue());
+ assertThat(referenceAndListParam.getValuesAsQueryTokens(), not(empty()));
+ assertThat(referenceAndListParam.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getValue(),
equalTo(PARTICIPANT_IDENTIFIER));
- assertThat(referenceAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens()
- .get(0).getChain(),
+ assertThat(referenceAndListParam.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getChain(),
equalTo(Practitioner.SP_IDENTIFIER));
}
+ @Test
+ public void searchForServiceRequests_shouldHandleComplexQuery() throws Exception {
+ verifyUri(
+ String.format("/ServiceRequest?requester.given=%s&occurrence=eq%s", PARTICIPANT_GIVEN_NAME, OCCURRENCE_DATE));
+
+ verify(service).searchForServiceRequests(serviceRequestSearchParamsArgumentCaptor.capture());
+
+ ReferenceAndListParam referenceAndListParam = serviceRequestSearchParamsArgumentCaptor.getValue()
+ .getParticipantReference();
+ assertThat(referenceAndListParam, notNullValue());
+ assertThat(referenceAndListParam.getValuesAsQueryTokens(), not(empty()));
+ assertThat(referenceAndListParam.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getValue(),
+ equalTo(PARTICIPANT_GIVEN_NAME));
+ assertThat(referenceAndListParam.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getChain(),
+ equalTo(Practitioner.SP_GIVEN));
+
+ DateRangeParam dateRangeParam = serviceRequestSearchParamsArgumentCaptor.getValue().getOccurrence();
+ assertThat(dateRangeParam, notNullValue());
+
+ Calendar calendar = Calendar.getInstance();
+ calendar.set(2010, Calendar.MARCH, 31);
+
+ assertThat(dateRangeParam.getLowerBound().getValue(),
+ equalTo(DateUtils.truncate(calendar.getTime(), Calendar.DATE)));
+ assertThat(dateRangeParam.getUpperBound().getValue(),
+ equalTo(DateUtils.truncate(calendar.getTime(), Calendar.DATE)));
+ }
+
@Test
public void searchForServiceRequests_shouldSearchForServiceRequestsByEncounterUUID() throws Exception {
verifyUri(String.format("/ServiceRequest?encounter=%s", ENCOUNTER_UUID));
- verify(service).searchForServiceRequests(isNull(), isNull(), referenceAndListParamArgumentCaptor.capture(), isNull(),
- isNull(), isNull(), isNull(), isNull());
+ verify(service).searchForServiceRequests(serviceRequestSearchParamsArgumentCaptor.capture());
- assertThat(referenceAndListParamArgumentCaptor.getValue(), notNullValue());
- assertThat(referenceAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens(), not(empty()));
- assertThat(referenceAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens()
- .get(0).getValue(),
+ ReferenceAndListParam referenceAndListParam = serviceRequestSearchParamsArgumentCaptor.getValue()
+ .getEncounterReference();
+ assertThat(referenceAndListParam, notNullValue());
+ assertThat(referenceAndListParam.getValuesAsQueryTokens(), not(empty()));
+ assertThat(referenceAndListParam.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getValue(),
equalTo(ENCOUNTER_UUID));
- assertThat(referenceAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens()
- .get(0).getChain(),
+ assertThat(referenceAndListParam.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getChain(),
equalTo(null));
}
@@ -426,13 +425,12 @@ public void searchForServiceRequests_shouldSearchForServiceRequestsByEncounterUU
public void searchForServiceRequests_shouldSearchForServiceRequestsByCode() throws Exception {
verifyUri(String.format("/ServiceRequest?code=%s", CODE));
- verify(service).searchForServiceRequests(isNull(), tokenAndListParamArgumentCaptor.capture(), isNull(), isNull(),
- isNull(), isNull(), isNull(), isNull());
+ verify(service).searchForServiceRequests(serviceRequestSearchParamsArgumentCaptor.capture());
- assertThat(tokenAndListParamArgumentCaptor.getValue(), notNullValue());
- assertThat(tokenAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens(), not(empty()));
- assertThat(tokenAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0)
- .getValue(),
+ TokenAndListParam tokenAndListParam = serviceRequestSearchParamsArgumentCaptor.getValue().getCode();
+ assertThat(tokenAndListParam, notNullValue());
+ assertThat(tokenAndListParam.getValuesAsQueryTokens(), not(empty()));
+ assertThat(tokenAndListParam.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getValue(),
equalTo(CODE));
}
@@ -440,45 +438,17 @@ public void searchForServiceRequests_shouldSearchForServiceRequestsByCode() thro
public void searchForServiceRequests_shouldSearchForServiceRequestsByOccurrence() throws Exception {
verifyUri(String.format("/ServiceRequest?occurrence=eq%s", OCCURRENCE_DATE));
- verify(service).searchForServiceRequests(isNull(), isNull(), isNull(), isNull(),
- dateRangeParamArgumentCaptor.capture(), isNull(), isNull(), isNull());
-
- assertThat(dateRangeParamArgumentCaptor.getValue(), notNullValue());
-
- Calendar calendar = Calendar.getInstance();
- calendar.set(2010, Calendar.MARCH, 31);
-
- assertThat(dateRangeParamArgumentCaptor.getValue().getLowerBound().getValue(),
- equalTo(DateUtils.truncate(calendar.getTime(), Calendar.DATE)));
- assertThat(dateRangeParamArgumentCaptor.getValue().getUpperBound().getValue(),
- equalTo(DateUtils.truncate(calendar.getTime(), Calendar.DATE)));
- }
-
- @Test
- public void searchForServiceRequests_shouldHandleComplexQuery() throws Exception {
- verifyUri(
- String.format("/ServiceRequest?requester.given=%s&occurrence=eq%s", PARTICIPANT_GIVEN_NAME, OCCURRENCE_DATE));
-
- verify(service).searchForServiceRequests(isNull(), isNull(), isNull(), referenceAndListParamArgumentCaptor.capture(),
- dateRangeParamArgumentCaptor.capture(), isNull(), isNull(), isNull());
-
- assertThat(referenceAndListParamArgumentCaptor.getValue(), notNullValue());
- assertThat(referenceAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens(), not(empty()));
- assertThat(referenceAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens()
- .get(0).getValue(),
- equalTo(PARTICIPANT_GIVEN_NAME));
- assertThat(referenceAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens()
- .get(0).getChain(),
- equalTo(Practitioner.SP_GIVEN));
+ verify(service).searchForServiceRequests(serviceRequestSearchParamsArgumentCaptor.capture());
- assertThat(dateRangeParamArgumentCaptor.getValue(), notNullValue());
+ DateRangeParam dateRangeParam = serviceRequestSearchParamsArgumentCaptor.getValue().getOccurrence();
+ assertThat(dateRangeParam, notNullValue());
Calendar calendar = Calendar.getInstance();
calendar.set(2010, Calendar.MARCH, 31);
- assertThat(dateRangeParamArgumentCaptor.getValue().getLowerBound().getValue(),
+ assertThat(dateRangeParam.getLowerBound().getValue(),
equalTo(DateUtils.truncate(calendar.getTime(), Calendar.DATE)));
- assertThat(dateRangeParamArgumentCaptor.getValue().getUpperBound().getValue(),
+ assertThat(dateRangeParam.getUpperBound().getValue(),
equalTo(DateUtils.truncate(calendar.getTime(), Calendar.DATE)));
}
@@ -486,13 +456,12 @@ public void searchForServiceRequests_shouldHandleComplexQuery() throws Exception
public void searchForServiceRequests_shouldSearchForServiceRequestsByUUID() throws Exception {
verifyUri(String.format("/ServiceRequest?_id=%s", SERVICE_REQUEST_UUID));
- verify(service).searchForServiceRequests(isNull(), isNull(), isNull(), isNull(), isNull(),
- tokenAndListParamArgumentCaptor.capture(), isNull(), isNull());
+ verify(service).searchForServiceRequests(serviceRequestSearchParamsArgumentCaptor.capture());
- assertThat(tokenAndListParamArgumentCaptor.getValue(), notNullValue());
- assertThat(tokenAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens(), not(empty()));
- assertThat(tokenAndListParamArgumentCaptor.getValue().getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0)
- .getValue(),
+ TokenAndListParam tokenAndListParam = serviceRequestSearchParamsArgumentCaptor.getValue().getUuid();
+ assertThat(tokenAndListParam, notNullValue());
+ assertThat(tokenAndListParam.getValuesAsQueryTokens(), not(empty()));
+ assertThat(tokenAndListParam.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getValue(),
equalTo(SERVICE_REQUEST_UUID));
}
@@ -500,17 +469,17 @@ public void searchForServiceRequests_shouldSearchForServiceRequestsByUUID() thro
public void searchForServiceRequests_shouldSearchForServiceRequestsByLastUpdatedDate() throws Exception {
verifyUri(String.format("/ServiceRequest?_lastUpdated=%s", LAST_UPDATED_DATE));
- verify(service).searchForServiceRequests(isNull(), isNull(), isNull(), isNull(), isNull(), isNull(),
- dateRangeParamArgumentCaptor.capture(), isNull());
+ verify(service).searchForServiceRequests(serviceRequestSearchParamsArgumentCaptor.capture());
- assertThat(dateRangeParamArgumentCaptor.getValue(), notNullValue());
+ DateRangeParam dateRangeParam = serviceRequestSearchParamsArgumentCaptor.getValue().getLastUpdated();
+ assertThat(dateRangeParam, notNullValue());
Calendar calendar = Calendar.getInstance();
calendar.set(2020, Calendar.SEPTEMBER, 3);
- assertThat(dateRangeParamArgumentCaptor.getValue().getLowerBound().getValue(),
+ assertThat(dateRangeParam.getLowerBound().getValue(),
equalTo(DateUtils.truncate(calendar.getTime(), Calendar.DATE)));
- assertThat(dateRangeParamArgumentCaptor.getValue().getUpperBound().getValue(),
+ assertThat(dateRangeParam.getUpperBound().getValue(),
equalTo(DateUtils.truncate(calendar.getTime(), Calendar.DATE)));
}
@@ -518,71 +487,64 @@ public void searchForServiceRequests_shouldSearchForServiceRequestsByLastUpdated
public void searchForServiceRequests_shouldAddRelatedPatientsWhenIncluded() throws Exception {
verifyUri("/ServiceRequest?_include=ServiceRequest:patient");
- verify(service).searchForServiceRequests(isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull(),
- includeArgumentCaptor.capture());
+ verify(service).searchForServiceRequests(serviceRequestSearchParamsArgumentCaptor.capture());
- assertThat(includeArgumentCaptor.getValue(), notNullValue());
- assertThat(includeArgumentCaptor.getValue().size(), equalTo(1));
- assertThat(includeArgumentCaptor.getValue().iterator().next().getParamName(),
- equalTo(FhirConstants.INCLUDE_PATIENT_PARAM));
- assertThat(includeArgumentCaptor.getValue().iterator().next().getParamType(),
- equalTo(FhirConstants.SERVICE_REQUEST));
+ HashSet include = serviceRequestSearchParamsArgumentCaptor.getValue().getIncludes();
+ assertThat(include, notNullValue());
+ assertThat(include.size(), equalTo(1));
+ assertThat(include.iterator().next().getParamName(), equalTo(FhirConstants.INCLUDE_PATIENT_PARAM));
+ assertThat(include.iterator().next().getParamType(), equalTo(FhirConstants.SERVICE_REQUEST));
}
@Test
public void searchForServiceRequests_shouldAddRelatedRequesterWhenIncluded() throws Exception {
verifyUri("/ServiceRequest?_include=ServiceRequest:requester");
- verify(service).searchForServiceRequests(isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull(),
- includeArgumentCaptor.capture());
+ verify(service).searchForServiceRequests(serviceRequestSearchParamsArgumentCaptor.capture());
- assertThat(includeArgumentCaptor.getValue(), notNullValue());
- assertThat(includeArgumentCaptor.getValue().size(), equalTo(1));
- assertThat(includeArgumentCaptor.getValue().iterator().next().getParamName(),
- equalTo(FhirConstants.INCLUDE_REQUESTER_PARAM));
- assertThat(includeArgumentCaptor.getValue().iterator().next().getParamType(),
- equalTo(FhirConstants.SERVICE_REQUEST));
+ HashSet include = serviceRequestSearchParamsArgumentCaptor.getValue().getIncludes();
+ assertThat(include, notNullValue());
+ assertThat(include.size(), equalTo(1));
+ assertThat(include.iterator().next().getParamName(), equalTo(FhirConstants.INCLUDE_REQUESTER_PARAM));
+ assertThat(include.iterator().next().getParamType(), equalTo(FhirConstants.SERVICE_REQUEST));
}
@Test
public void searchForServiceRequests_shouldAddRelatedEncounterWhenIncluded() throws Exception {
verifyUri("/ServiceRequest?_include=ServiceRequest:encounter");
- verify(service).searchForServiceRequests(isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull(),
- includeArgumentCaptor.capture());
+ verify(service).searchForServiceRequests(serviceRequestSearchParamsArgumentCaptor.capture());
- assertThat(includeArgumentCaptor.getValue(), notNullValue());
- assertThat(includeArgumentCaptor.getValue().size(), equalTo(1));
- assertThat(includeArgumentCaptor.getValue().iterator().next().getParamName(),
- equalTo(FhirConstants.INCLUDE_ENCOUNTER_PARAM));
- assertThat(includeArgumentCaptor.getValue().iterator().next().getParamType(),
- equalTo(FhirConstants.SERVICE_REQUEST));
+ HashSet include = serviceRequestSearchParamsArgumentCaptor.getValue().getIncludes();
+ assertThat(include, notNullValue());
+ assertThat(include.size(), equalTo(1));
+ assertThat(include.iterator().next().getParamName(), equalTo(FhirConstants.INCLUDE_ENCOUNTER_PARAM));
+ assertThat(include.iterator().next().getParamType(), equalTo(FhirConstants.SERVICE_REQUEST));
}
@Test
public void searchForServiceRequests_shouldHandleMultipleIncludes() throws Exception {
verifyUri("/ServiceRequest?_include=ServiceRequest:requester&_include=ServiceRequest:patient");
- verify(service).searchForServiceRequests(isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull(),
- includeArgumentCaptor.capture());
+ verify(service).searchForServiceRequests(serviceRequestSearchParamsArgumentCaptor.capture());
- assertThat(includeArgumentCaptor.getValue(), notNullValue());
- assertThat(includeArgumentCaptor.getValue().size(), equalTo(2));
+ HashSet include = serviceRequestSearchParamsArgumentCaptor.getValue().getIncludes();
+ assertThat(include, notNullValue());
+ assertThat(include.size(), equalTo(2));
- assertThat(includeArgumentCaptor.getValue(),
- hasItem(allOf(hasProperty("paramName", equalTo(FhirConstants.INCLUDE_REQUESTER_PARAM)),
- hasProperty("paramType", equalTo(FhirConstants.SERVICE_REQUEST)))));
- assertThat(includeArgumentCaptor.getValue(),
- hasItem(allOf(hasProperty("paramName", equalTo(FhirConstants.INCLUDE_PATIENT_PARAM)),
- hasProperty("paramType", equalTo(FhirConstants.SERVICE_REQUEST)))));
+ assertThat(include, hasItem(allOf(hasProperty("paramName", equalTo(FhirConstants.INCLUDE_REQUESTER_PARAM)),
+ hasProperty("paramType", equalTo(FhirConstants.SERVICE_REQUEST)))));
+ assertThat(include, hasItem(allOf(hasProperty("paramName", equalTo(FhirConstants.INCLUDE_PATIENT_PARAM)),
+ hasProperty("paramType", equalTo(FhirConstants.SERVICE_REQUEST)))));
}
-
+
@Test
+ @Ignore
public void searchForServiceRequests_shouldHandleHasAndListParameter() throws Exception {
verifyUri("/ServiceRequest?_has:Observation:based-on:category:not=laboratory");
verify(service).searchForServiceRequests(serviceRequestSearchParamsArgumentCaptor.capture());
-
+
HasAndListParam hasAndListParam = serviceRequestSearchParamsArgumentCaptor.getValue().getHasAndListParam();
assertThat(hasAndListParam, notNullValue());
assertThat(hasAndListParam.size(), equalTo(1));
@@ -606,7 +568,6 @@ public void searchForServiceRequests_shouldHandleHasAndListParameter() throws Ex
}
@Test
- @Ignore
public void searchForServiceRequests_shouldHandleHasAndListParameterWithColonNotAfterParameterName() throws Exception {
verifyUri("/ServiceRequest?_has:Observation:based-on:category:not=laboratory");
@@ -622,7 +583,8 @@ public void searchForServiceRequests_shouldHandleHasAndListParameterWithColonNot
@Test
@Ignore
- public void searchForServiceRequests_shouldHandleHasAndListParameterWithColonNotAfterParameterNameAndNoValue() throws Exception {
+ public void searchForServiceRequests_shouldHandleHasAndListParameterWithColonNotAfterParameterNameAndNoValue()
+ throws Exception {
verifyUri("/ServiceRequest?_has:Observation:based-on:not");
verify(service).searchForServiceRequests(serviceRequestSearchParamsArgumentCaptor.capture());
@@ -636,7 +598,7 @@ public void searchForServiceRequests_shouldHandleHasAndListParameterWithColonNot
}
private void verifyUri(String uri) throws Exception {
- when(service.searchForServiceRequests(any(), any(), any(), any(), any(), any(), any(), any()))
+ when(service.searchForServiceRequests(any()))
.thenReturn(new MockIBundleProvider<>(Collections.singletonList(serviceRequest), 10, 1));
MockHttpServletResponse response = get(uri).accept(FhirMediaTypes.JSON).go();
From e9539f31f88aabca673bdb6e0d8612d470d242cb Mon Sep 17 00:00:00 2001
From: md-at-slashwhy <95024503+md-at-slashwhy@users.noreply.github.com>
Date: Wed, 22 Nov 2023 14:56:46 +0100
Subject: [PATCH 3/9] FM2-347: fix tests using positive check (without not)
---
.../r3/ProcedureRequestFhirResourceProviderWebTest.java | 8 ++++----
.../r4/ServiceRequestFhirResourceProviderWebTest.java | 6 +++---
2 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/omod/src/test/java/org/openmrs/module/fhir2/providers/r3/ProcedureRequestFhirResourceProviderWebTest.java b/omod/src/test/java/org/openmrs/module/fhir2/providers/r3/ProcedureRequestFhirResourceProviderWebTest.java
index ed66831362..96d97ec289 100644
--- a/omod/src/test/java/org/openmrs/module/fhir2/providers/r3/ProcedureRequestFhirResourceProviderWebTest.java
+++ b/omod/src/test/java/org/openmrs/module/fhir2/providers/r3/ProcedureRequestFhirResourceProviderWebTest.java
@@ -539,7 +539,7 @@ public void searchForServiceRequests_shouldHandleMultipleIncludes() throws Excep
@Test
public void searchForServiceRequests_shouldHandleHasAndListParameter() throws Exception {
- verifyUri("/ServiceRequest?_has:Observation:based-on:category:not=laboratory");
+ verifyUri("/ProcedureRequest?_has:Observation:based-on:category=laboratory");
verify(service).searchForServiceRequests(serviceRequestSearchParamsArgumentCaptor.capture());
@@ -562,13 +562,13 @@ public void searchForServiceRequests_shouldHandleHasAndListParameter() throws Ex
Collections.sort(valuesFound);
assertThat(valuesFound.size(), equalTo(1));
- assertThat(valuesFound.get(0), equalTo("category != laboratory"));
+ assertThat(valuesFound.get(0), equalTo("category=laboratory"));
}
@Test
@Ignore
public void shouldHandleHasAndListParameterWithColonNotAfterParameterName() throws Exception {
- verifyUri("/ServiceRequest?_has:Observation:based-on:category:not=laboratory");
+ verifyUri("/ProcedureRequest?_has:Observation:based-on:category:not=laboratory");
verify(service).searchForServiceRequests(serviceRequestSearchParamsArgumentCaptor.capture());
@@ -583,7 +583,7 @@ public void shouldHandleHasAndListParameterWithColonNotAfterParameterName() thro
@Test
@Ignore
public void shouldHandleHasAndListParameterWithColonNotAfterParameterNameAndNoValue() throws Exception {
- verifyUri("/ServiceRequest?_has:Observation:based-on:not");
+ verifyUri("/ProcedureRequest?_has:Observation:based-on:not");
verify(service).searchForServiceRequests(serviceRequestSearchParamsArgumentCaptor.capture());
diff --git a/omod/src/test/java/org/openmrs/module/fhir2/providers/r4/ServiceRequestFhirResourceProviderWebTest.java b/omod/src/test/java/org/openmrs/module/fhir2/providers/r4/ServiceRequestFhirResourceProviderWebTest.java
index f288601e95..59f9a1047f 100644
--- a/omod/src/test/java/org/openmrs/module/fhir2/providers/r4/ServiceRequestFhirResourceProviderWebTest.java
+++ b/omod/src/test/java/org/openmrs/module/fhir2/providers/r4/ServiceRequestFhirResourceProviderWebTest.java
@@ -539,9 +539,8 @@ public void searchForServiceRequests_shouldHandleMultipleIncludes() throws Excep
}
@Test
- @Ignore
public void searchForServiceRequests_shouldHandleHasAndListParameter() throws Exception {
- verifyUri("/ServiceRequest?_has:Observation:based-on:category:not=laboratory");
+ verifyUri("/ServiceRequest?_has:Observation:based-on:category=laboratory");
verify(service).searchForServiceRequests(serviceRequestSearchParamsArgumentCaptor.capture());
@@ -564,10 +563,11 @@ public void searchForServiceRequests_shouldHandleHasAndListParameter() throws Ex
Collections.sort(valuesFound);
assertThat(valuesFound.size(), equalTo(1));
- assertThat(valuesFound.get(0), equalTo("category != laboratory"));
+ assertThat(valuesFound.get(0), equalTo("category=laboratory"));
}
@Test
+ @Ignore
public void searchForServiceRequests_shouldHandleHasAndListParameterWithColonNotAfterParameterName() throws Exception {
verifyUri("/ServiceRequest?_has:Observation:based-on:category:not=laboratory");
From cc50c1465fa112edf6ec60bca8bc8dedb1175d74 Mon Sep 17 00:00:00 2001
From: md-at-slashwhy <95024503+md-at-slashwhy@users.noreply.github.com>
Date: Wed, 22 Nov 2023 14:56:47 +0100
Subject: [PATCH 4/9] FM2-347: update tests to handle more search parameters
---
.../param/ServiceRequestSearchParams.java | 2 +
.../ProcedureRequestFhirResourceProvider.java | 9 +-
.../ServiceRequestFhirResourceProvider.java | 5 +-
.../dao/impl/FhirObservationDaoImplTest.java | 18 +
.../impl/FhirServiceRequestDaoImplTest.java | 320 +++++++++++++++++-
.../FhirServiceRequestServiceImplTest.java | 46 ++-
.../search/ServiceRequestSearchQueryTest.java | 101 +++---
.../param/ServiceRequestSearchParamsTest.java | 46 +++
...cedureRequestFhirResourceProviderTest.java | 48 ++-
...erviceRequestFhirResourceProviderTest.java | 48 ++-
.../FhirServiceRequestTest_initial_data.xml | 41 +++
11 files changed, 606 insertions(+), 78 deletions(-)
create mode 100644 api/src/test/java/org/openmrs/module/fhir2/api/search/param/ServiceRequestSearchParamsTest.java
diff --git a/api/src/main/java/org/openmrs/module/fhir2/api/search/param/ServiceRequestSearchParams.java b/api/src/main/java/org/openmrs/module/fhir2/api/search/param/ServiceRequestSearchParams.java
index ee44099aa6..e103500253 100644
--- a/api/src/main/java/org/openmrs/module/fhir2/api/search/param/ServiceRequestSearchParams.java
+++ b/api/src/main/java/org/openmrs/module/fhir2/api/search/param/ServiceRequestSearchParams.java
@@ -21,12 +21,14 @@
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
+import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
+@EqualsAndHashCode
public class ServiceRequestSearchParams implements Serializable {
private ReferenceAndListParam patientReference;
diff --git a/api/src/main/java/org/openmrs/module/fhir2/providers/r3/ProcedureRequestFhirResourceProvider.java b/api/src/main/java/org/openmrs/module/fhir2/providers/r3/ProcedureRequestFhirResourceProvider.java
index 9bba6ce9cc..f90f261ea1 100644
--- a/api/src/main/java/org/openmrs/module/fhir2/providers/r3/ProcedureRequestFhirResourceProvider.java
+++ b/api/src/main/java/org/openmrs/module/fhir2/providers/r3/ProcedureRequestFhirResourceProvider.java
@@ -25,6 +25,7 @@
import ca.uhn.fhir.rest.api.MethodOutcome;
import ca.uhn.fhir.rest.api.server.IBundleProvider;
import ca.uhn.fhir.rest.param.DateRangeParam;
+import ca.uhn.fhir.rest.param.HasAndListParam;
import ca.uhn.fhir.rest.param.ReferenceAndListParam;
import ca.uhn.fhir.rest.param.TokenAndListParam;
import ca.uhn.fhir.rest.server.IResourceProvider;
@@ -41,6 +42,7 @@
import org.hl7.fhir.dstu3.model.ProcedureRequest;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.r4.model.ServiceRequest;
+import org.openmrs.module.fhir2.FhirConstants;
import org.openmrs.module.fhir2.api.FhirServiceRequestService;
import org.openmrs.module.fhir2.api.annotations.R3Provider;
import org.openmrs.module.fhir2.api.search.SearchQueryBundleProviderR3Wrapper;
@@ -110,6 +112,7 @@ public IBundleProvider searchForProcedureRequests(
@OptionalParam(name = ProcedureRequest.SP_OCCURRENCE) DateRangeParam occurrence,
@OptionalParam(name = ProcedureRequest.SP_RES_ID) TokenAndListParam uuid,
@OptionalParam(name = "_lastUpdated") DateRangeParam lastUpdated,
+ @OptionalParam(name = FhirConstants.HAS_SEARCH_HANDLER) HasAndListParam hasAndListParam,
@IncludeParam(allow = { "ProcedureRequest:" + ProcedureRequest.SP_PATIENT,
"ProcedureRequest:" + ProcedureRequest.SP_REQUESTER,
"ProcedureRequest:" + ProcedureRequest.SP_ENCOUNTER }) HashSet includes) {
@@ -121,8 +124,8 @@ public IBundleProvider searchForProcedureRequests(
includes = null;
}
- return new SearchQueryBundleProviderR3Wrapper(
- serviceRequestService.searchForServiceRequests(new ServiceRequestSearchParams(patientReference, code,
- encounterReference, participantReference, occurrence, uuid, lastUpdated, includes, null)));
+ return new SearchQueryBundleProviderR3Wrapper(serviceRequestService
+ .searchForServiceRequests(new ServiceRequestSearchParams(patientReference, code, encounterReference,
+ participantReference, occurrence, uuid, lastUpdated, includes, hasAndListParam)));
}
}
diff --git a/api/src/main/java/org/openmrs/module/fhir2/providers/r4/ServiceRequestFhirResourceProvider.java b/api/src/main/java/org/openmrs/module/fhir2/providers/r4/ServiceRequestFhirResourceProvider.java
index 14908c7aa8..9146c796d7 100644
--- a/api/src/main/java/org/openmrs/module/fhir2/providers/r4/ServiceRequestFhirResourceProvider.java
+++ b/api/src/main/java/org/openmrs/module/fhir2/providers/r4/ServiceRequestFhirResourceProvider.java
@@ -25,6 +25,7 @@
import ca.uhn.fhir.rest.api.MethodOutcome;
import ca.uhn.fhir.rest.api.server.IBundleProvider;
import ca.uhn.fhir.rest.param.DateRangeParam;
+import ca.uhn.fhir.rest.param.HasAndListParam;
import ca.uhn.fhir.rest.param.ReferenceAndListParam;
import ca.uhn.fhir.rest.param.TokenAndListParam;
import ca.uhn.fhir.rest.server.IResourceProvider;
@@ -39,6 +40,7 @@
import org.hl7.fhir.r4.model.Patient;
import org.hl7.fhir.r4.model.Practitioner;
import org.hl7.fhir.r4.model.ServiceRequest;
+import org.openmrs.module.fhir2.FhirConstants;
import org.openmrs.module.fhir2.api.FhirServiceRequestService;
import org.openmrs.module.fhir2.api.annotations.R4Provider;
import org.openmrs.module.fhir2.api.search.param.ServiceRequestSearchParams;
@@ -109,6 +111,7 @@ public IBundleProvider searchForServiceRequests(
@OptionalParam(name = ServiceRequest.SP_OCCURRENCE) DateRangeParam occurrence,
@OptionalParam(name = ServiceRequest.SP_RES_ID) TokenAndListParam uuid,
@OptionalParam(name = "_lastUpdated") DateRangeParam lastUpdated,
+ @OptionalParam(name = FhirConstants.HAS_SEARCH_HANDLER) HasAndListParam hasAndListParam,
@IncludeParam(allow = { "ServiceRequest:" + ServiceRequest.SP_PATIENT,
"ServiceRequest:" + ServiceRequest.SP_REQUESTER,
"ServiceRequest:" + ServiceRequest.SP_ENCOUNTER }) HashSet includes) {
@@ -121,6 +124,6 @@ public IBundleProvider searchForServiceRequests(
}
return serviceRequestService.searchForServiceRequests(new ServiceRequestSearchParams(patientReference, code,
- encounterReference, participantReference, occurrence, uuid, lastUpdated, includes, null));
+ encounterReference, participantReference, occurrence, uuid, lastUpdated, includes, hasAndListParam));
}
}
diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirObservationDaoImplTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirObservationDaoImplTest.java
index ff96f9f0aa..5718cf33ae 100644
--- a/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirObservationDaoImplTest.java
+++ b/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirObservationDaoImplTest.java
@@ -16,6 +16,9 @@
import java.util.Collection;
+import ca.uhn.fhir.rest.param.HasAndListParam;
+import ca.uhn.fhir.rest.param.HasOrListParam;
+import ca.uhn.fhir.rest.param.HasParam;
import ca.uhn.fhir.rest.param.TokenAndListParam;
import ca.uhn.fhir.rest.param.TokenParam;
import org.junit.Before;
@@ -78,4 +81,19 @@ public void search_shouldReturnSearchQuery() {
assertThat(obs, notNullValue());
}
+ @Test
+ public void search_shouldFindObservationsBasedOnServiceRequestUuid() {
+ String id = "28b1e265-019d-4475-89a3-9f0cb5185d47";
+ HasOrListParam hasOrListParam = new HasOrListParam();
+ hasOrListParam.add(new HasParam("Observation", "based-on", "ServiceRequest", id));
+ HasAndListParam hasAndListParam = new HasAndListParam();
+ hasAndListParam.addAnd(hasOrListParam);
+ SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.HAS_SEARCH_HANDLER,
+ hasAndListParam);
+
+ Collection obs = dao.getSearchResults(theParams);
+
+ assertThat(obs, notNullValue());
+ }
+
}
diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirServiceRequestDaoImplTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirServiceRequestDaoImplTest.java
index 4132a482be..13838bf60a 100644
--- a/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirServiceRequestDaoImplTest.java
+++ b/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirServiceRequestDaoImplTest.java
@@ -15,12 +15,23 @@
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;
+import java.util.Collection;
+import java.util.List;
+
+import ca.uhn.fhir.rest.param.HasAndListParam;
+import ca.uhn.fhir.rest.param.HasOrListParam;
+import ca.uhn.fhir.rest.param.HasParam;
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.collections.Predicate;
import org.hibernate.SessionFactory;
import org.junit.Before;
import org.junit.Test;
+import org.openmrs.Obs;
import org.openmrs.OrderType;
import org.openmrs.TestOrder;
+import org.openmrs.module.fhir2.FhirConstants;
import org.openmrs.module.fhir2.TestFhirSpringConfiguration;
+import org.openmrs.module.fhir2.api.search.param.SearchParameterMap;
import org.openmrs.test.BaseModuleContextSensitiveTest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
@@ -33,7 +44,17 @@ public class FhirServiceRequestDaoImplTest extends BaseModuleContextSensitiveTes
private static final String OTHER_ORDER_UUID = "02b9d1e4-7619-453e-bd6b-c32286f861df";
- private static final String WRONG_UUID = "7d96f25c-4949-4f72-9931-d808fbc226dd";
+ private static final String ORDER_WITH_OBSERVATION_CATEGORY_LABORATORY_UUID = "4364996e-450c-42dc-84a7-1c205f34b10b";
+
+ private static final String ORDER_WITH_OBSERVATION_CATEGORY_PROCEDURE_UUID = "6233f0f9-17eb-471c-8131-440a20dc25c4";
+
+ private static final String ORDER_WITH_CODED_VALUE_UUID = "b5bb2ba7-b17d-473e-907b-de7ad5374804";
+
+ private static final String ORDER_WITH_DATETIME_VALUE_UUID = "a5a0f4a2-8d32-4527-ae8e-2be8cb76a899";
+
+ private static final String ORDER_WITH_TEXT_VALUE_UUID = "fb5e9e5f-1800-4c96-b18e-0d89cf20219";
+
+ private static final String WRONG_UUID = "38c53063-450a-47be-802c-e6270d2e6c69";
private static final String TEST_ORDER_INITIAL_DATA = "org/openmrs/module/fhir2/api/dao/impl/FhirServiceRequestTest_initial_data.xml";
@@ -72,4 +93,301 @@ public void shouldReturnNullIfUuidIsNotValidTestOrder() {
TestOrder result = dao.get(OTHER_ORDER_UUID);
assertThat(result, nullValue());
}
+
+ @Test
+ public void shouldApplyHasConstraintsForObservationsBasedOnAnyCorrectly() {
+ runHasObservationBasedOnTest(
+ null,
+ null,
+ new String[]{ ORDER_WITH_OBSERVATION_CATEGORY_LABORATORY_UUID, ORDER_WITH_OBSERVATION_CATEGORY_PROCEDURE_UUID, ORDER_WITH_TEXT_VALUE_UUID },
+ new String[]{WRONG_UUID}
+ );
+ }
+
+ @Test
+ public void shouldApplyHasConstraintsForObservationsBasedOnAnyCategoryCorrectly() {
+ runHasObservationBasedOnTest(
+ "category",
+ null,
+ new String[]{ ORDER_WITH_OBSERVATION_CATEGORY_LABORATORY_UUID, ORDER_WITH_OBSERVATION_CATEGORY_PROCEDURE_UUID },
+ new String[]{WRONG_UUID}
+ );
+ }
+
+ @Test
+ public void shouldApplyHasConstraintsForObservationsBasedOnLaboratoryCategoryCorrectly() {
+ runHasObservationBasedOnTest(
+ "category",
+ "laboratory",
+ new String[]{ ORDER_WITH_OBSERVATION_CATEGORY_LABORATORY_UUID },
+ new String[]{WRONG_UUID, ORDER_WITH_OBSERVATION_CATEGORY_PROCEDURE_UUID}
+ );
+ }
+
+ @Test
+ public void shouldApplyHasConstraintsForObservationsBasedOnAnyDateCorrectly() {
+ runHasObservationBasedOnTest(
+ "date",
+ null,
+ new String[]{ ORDER_WITH_OBSERVATION_CATEGORY_LABORATORY_UUID },
+ new String[]{WRONG_UUID}
+ );
+ }
+
+ @Test
+ public void shouldApplyHasConstraintsForObservationsBasedOnSpecificDateCorrectly() {
+ runHasObservationBasedOnTest(
+ "date",
+ "1998-07-01 00:00:00.0",
+ new String[]{ ORDER_WITH_OBSERVATION_CATEGORY_LABORATORY_UUID },
+ new String[]{WRONG_UUID}
+ );
+ }
+
+
+ @Test
+ public void shouldApplyHasConstraintsForObservationsBasedOnAnySubjectCorrectly() {
+ runHasObservationBasedOnTest(
+ "subject",
+ null,
+ new String[]{ ORDER_WITH_OBSERVATION_CATEGORY_LABORATORY_UUID },
+ new String[]{WRONG_UUID}
+ );
+ }
+
+ @Test
+ public void shouldApplyHasConstraintsForObservationsBasedOnSpecificSubjectCorrectly() {
+ runHasObservationBasedOnTest(
+ "subject",
+ // TODO: what would be a realistic value?
+ "a65c347e-1384-493a-a55b-d325924acd94",
+ new String[]{ ORDER_WITH_OBSERVATION_CATEGORY_LABORATORY_UUID },
+ new String[]{WRONG_UUID}
+ );
+ }
+
+
+ @Test
+ public void shouldApplyHasConstraintsForObservationsBasedOnAnyValueConceptCorrectly() {
+ runHasObservationBasedOnTest(
+ "value-concept",
+ null,
+ new String[]{ ORDER_WITH_CODED_VALUE_UUID },
+ new String[]{WRONG_UUID, ORDER_WITH_DATETIME_VALUE_UUID}
+ );
+ }
+
+ @Test
+ public void shouldApplyHasConstraintsForObservationsBasedOnSpecificValueConceptCorrectly() {
+ runHasObservationBasedOnTest(
+ "value-concept",
+ "8d492026-c2cc-11de-8d13-0010c6dffd0f",
+ new String[]{ ORDER_WITH_CODED_VALUE_UUID },
+ new String[]{WRONG_UUID, ORDER_WITH_DATETIME_VALUE_UUID}
+ );
+ }
+
+
+ @Test
+ public void shouldApplyHasConstraintsForObservationsBasedOnAnyValueDateCorrectly() {
+ runHasObservationBasedOnTest(
+ "value-date",
+ null,
+ new String[]{ ORDER_WITH_DATETIME_VALUE_UUID },
+ new String[]{WRONG_UUID, ORDER_WITH_CODED_VALUE_UUID}
+ );
+ }
+
+ @Test
+ public void shouldApplyHasConstraintsForObservationsBasedOnSpecificValueDateCorrectly() {
+ runHasObservationBasedOnTest(
+ "value-date",
+ // TODO: what would be a realistic value?
+ "1998-07-01 00:00:00",
+ new String[]{ ORDER_WITH_DATETIME_VALUE_UUID },
+ new String[]{WRONG_UUID, ORDER_WITH_CODED_VALUE_UUID}
+ );
+ }
+
+
+ @Test
+ public void shouldApplyHasConstraintsForObservationsBasedOnAnyHasMemberCorrectly() {
+ // TODO:
+ runHasObservationBasedOnTest(
+ "has-member",
+ null,
+ new String[]{ WRONG_UUID, ORDER_WITH_DATETIME_VALUE_UUID },
+ new String[]{WRONG_UUID, ORDER_WITH_CODED_VALUE_UUID}
+ );
+ }
+
+ @Test
+ public void shouldApplyHasConstraintsForObservationsBasedOnSpecificHasMemerCorrectly() {
+ // TODO:
+ runHasObservationBasedOnTest(
+ "has-member",
+ "TODO",
+ new String[]{ WRONG_UUID, ORDER_WITH_DATETIME_VALUE_UUID },
+ new String[]{WRONG_UUID, ORDER_WITH_CODED_VALUE_UUID}
+ );
+ }
+
+
+ @Test
+ public void shouldApplyHasConstraintsForObservationsBasedOnAnyValueStringCorrectly() {
+ runHasObservationBasedOnTest(
+ "value-string",
+ null,
+ new String[]{ ORDER_WITH_TEXT_VALUE_UUID },
+ new String[]{WRONG_UUID, ORDER_WITH_CODED_VALUE_UUID}
+ );
+ }
+
+ @Test
+ public void shouldApplyHasConstraintsForObservationsBasedOnSpecificValueStringCorrectly() {
+ runHasObservationBasedOnTest(
+ "value-string",
+ // TODO: what would be a realistic value here? Are spaces allowed?
+ "value_text",
+ new String[]{ ORDER_WITH_TEXT_VALUE_UUID },
+ new String[]{WRONG_UUID, ORDER_WITH_CODED_VALUE_UUID}
+ );
+ }
+
+
+ @Test
+ public void shouldApplyHasConstraintsForObservationsBasedOnAnyIdentifierCorrectly() {
+ // this test should return ALL observations (it basically checks obs.uuid != null)
+ runHasObservationBasedOnTest(
+ "identifier",
+ null,
+ new String[]{ ORDER_WITH_TEXT_VALUE_UUID },
+ new String[]{}
+ );
+ }
+
+ @Test
+ public void shouldApplyHasConstraintsForObservationsBasedOnSpecificIdentifierCorrectly() {
+ runHasObservationBasedOnTest(
+ "identifier",
+ ORDER_WITH_TEXT_VALUE_UUID,
+ new String[]{ ORDER_WITH_TEXT_VALUE_UUID },
+ new String[]{WRONG_UUID, ORDER_WITH_OBSERVATION_CATEGORY_LABORATORY_UUID }
+ );
+ }
+
+
+ @Test
+ public void shouldApplyHasConstraintsForObservationsBasedOnAnyEncounterCorrectly() {
+ // this test should return ALL observations (it basically checks obs.uuid != null)
+ runHasObservationBasedOnTest(
+ "encounter",
+ null,
+ new String[]{ ORDER_WITH_TEXT_VALUE_UUID, ORDER_WITH_OBSERVATION_CATEGORY_LABORATORY_UUID },
+ new String[]{ WRONG_UUID}
+ );
+ }
+
+ @Test
+ public void shouldApplyHasConstraintsForObservationsBasedOnSpecificEncounterCorrectly() {
+ runHasObservationBasedOnTest(
+ "encounter",
+ "8a706f20-d133-403a-aa7e-95318a03cf12",
+ new String[]{ ORDER_WITH_OBSERVATION_CATEGORY_LABORATORY_UUID },
+ new String[]{WRONG_UUID, ORDER_WITH_TEXT_VALUE_UUID }
+ );
+ }
+
+
+ @Test
+ public void shouldApplyHasConstraintsForObservationsBasedOnAnyStatusCorrectly() {
+ // this test should return ALL observations (it basically checks obs.uuid != null)
+ runHasObservationBasedOnTest(
+ "status",
+ null,
+ new String[]{ ORDER_WITH_TEXT_VALUE_UUID, ORDER_WITH_OBSERVATION_CATEGORY_LABORATORY_UUID },
+ new String[]{ WRONG_UUID}
+ );
+ }
+
+ @Test
+ public void shouldApplyHasConstraintsForObservationsBasedOnSpecificStatusCorrectly() {
+ runHasObservationBasedOnTest(
+ "status",
+ "TODO", //TODO: Obs.Status.FINAL can not be loaded here and is the only value status can have,
+ new String[]{ ORDER_WITH_OBSERVATION_CATEGORY_LABORATORY_UUID },
+ new String[]{WRONG_UUID, ORDER_WITH_TEXT_VALUE_UUID }
+ );
+ }
+
+
+ @Test
+ public void shouldReturnNoEntriesForUnsupportedSearchParameters() {
+ String[] unsupportedSearchParameters = {
+ "focus",
+ "derived-from",
+ "method",
+ "data-absent-reason",
+ "device",
+ "component-data-absent-reason",
+ "component-code-value-quantity",
+ "component-value-quantity",
+ "component-code-value-concept",
+ "component-value-concept",
+ "component-code",
+ "combo-data-absent-reason",
+ "combo-code",
+ "combo-code-value-quantity",
+ "combo-code-value-concept",
+ "combo-value-quantity",
+ "combo-value-concept",
+ };
+ for (String unsupportedSearchParameter : unsupportedSearchParameters) {
+ runHasObservationBasedOnTest(
+ unsupportedSearchParameter,
+ null,
+ new String[]{ },
+ new String[]{WRONG_UUID, ORDER_WITH_TEXT_VALUE_UUID }
+ );
+ }
+ }
+
+ private void runHasObservationBasedOnTest(String searchParameter, String value, String[] expectedUuids, String[] unexpectedUuids){
+ HasOrListParam hasOrListParam = new HasOrListParam();
+ hasOrListParam.add(new HasParam("Observation", "based-on", searchParameter, value));
+ HasAndListParam hasAndListParam = new HasAndListParam();
+ hasAndListParam.addAnd(hasOrListParam);
+ SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.HAS_SEARCH_HANDLER,
+ hasAndListParam);
+
+ List results = dao.getSearchResults(theParams);
+
+ assertThat(results, notNullValue());
+
+ if(expectedUuids.length > 0){
+ assertThat("No service requests returned", results.size() > 0);
+ }
+
+ for (String expectedUuid : expectedUuids) {
+ assertThat("Result did not contain expected entry",
+ containsUuid(results, expectedUuid));
+ }
+
+ for (String unexpectedUuid : unexpectedUuids) {
+ assertThat("Result did contain unexpected entry",
+ !containsUuid(results, unexpectedUuid));
+ }
+ }
+
+
+ private boolean containsUuid(Collection collection, String uuid) {
+ Predicate predicate = new Predicate() {
+
+ public boolean evaluate(Object sample) {
+ return ((TestOrder) sample).getUuid().equals(uuid);
+ }
+ };
+ return CollectionUtils.exists(collection, predicate);
+ }
+
}
diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/impl/FhirServiceRequestServiceImplTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/impl/FhirServiceRequestServiceImplTest.java
index a4d4d0caab..3399be8f34 100644
--- a/api/src/test/java/org/openmrs/module/fhir2/api/impl/FhirServiceRequestServiceImplTest.java
+++ b/api/src/test/java/org/openmrs/module/fhir2/api/impl/FhirServiceRequestServiceImplTest.java
@@ -36,6 +36,9 @@
import ca.uhn.fhir.model.api.Include;
import ca.uhn.fhir.rest.api.server.IBundleProvider;
import ca.uhn.fhir.rest.param.DateRangeParam;
+import ca.uhn.fhir.rest.param.HasAndListParam;
+import ca.uhn.fhir.rest.param.HasOrListParam;
+import ca.uhn.fhir.rest.param.HasParam;
import ca.uhn.fhir.rest.param.ReferenceAndListParam;
import ca.uhn.fhir.rest.param.ReferenceOrListParam;
import ca.uhn.fhir.rest.param.ReferenceParam;
@@ -43,6 +46,7 @@
import ca.uhn.fhir.rest.param.TokenParam;
import org.hamcrest.Matchers;
import org.hl7.fhir.instance.model.api.IBaseResource;
+import org.hl7.fhir.r4.model.Observation;
import org.hl7.fhir.r4.model.Patient;
import org.hl7.fhir.r4.model.ServiceRequest;
import org.junit.Before;
@@ -315,7 +319,7 @@ public void searchForServiceRequest_shouldReturnCollectionOfServiceRequestByLast
}
@Test
- public void searchForPeople_shouldAddRelatedResourcesWhenIncluded() {
+ public void searchForServiceRequest_shouldAddRelatedResourcesWhenIncluded() {
HashSet includes = new HashSet<>();
includes.add(new Include("ServiceRequest:patient"));
ServiceRequestSearchParams serviceRequestSearchParams = new ServiceRequestSearchParams();
@@ -340,7 +344,7 @@ public void searchForPeople_shouldAddRelatedResourcesWhenIncluded() {
}
@Test
- public void searchForPeople_shouldAddRelatedResourcesWhenIncludedR3() {
+ public void searchForServiceRequest_shouldAddRelatedResourcesWhenIncludedR3() {
HashSet includes = new HashSet<>();
includes.add(new Include("ProcedureRequest:patient"));
ServiceRequestSearchParams serviceRequestSearchParams = new ServiceRequestSearchParams();
@@ -365,7 +369,7 @@ public void searchForPeople_shouldAddRelatedResourcesWhenIncludedR3() {
}
@Test
- public void searchForPeople_shouldNotAddRelatedResourcesForEmptyInclude() {
+ public void searchForServiceRequest_shouldNotAddRelatedResourcesForEmptyInclude() {
HashSet includes = new HashSet<>();
ServiceRequestSearchParams serviceRequestSearchParams = new ServiceRequestSearchParams();
serviceRequestSearchParams.setIncludes(includes);
@@ -387,4 +391,40 @@ public void searchForPeople_shouldNotAddRelatedResourcesForEmptyInclude() {
assertThat(resultList.size(), equalTo(1));
}
+ @Test
+ public void searchForServiceRequest_shouldAddNotNullConstraintForHasParamsWithNoParameterValue() {
+ // Example request: /ServiceRequest?_has:Observation:based-on
+ HasAndListParam hasAndListParam = CreateHasAndListParam(FhirConstants.OBSERVATION, Observation.SP_BASED_ON, null,
+ null);
+ ServiceRequestSearchParams serviceRequestSearchParams = new ServiceRequestSearchParams();
+ serviceRequestSearchParams.setHasAndListParam(hasAndListParam);
+
+ SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.HAS_SEARCH_HANDLER,
+ hasAndListParam);
+
+ when(dao.getSearchResults(any())).thenReturn(Collections.singletonList(order));
+ when(translator.toFhirResource(order)).thenReturn(fhirServiceRequest);
+ when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn(
+ new SearchQueryBundleProvider<>(theParams, dao, translator, globalPropertyService, searchQueryInclude));
+ when(searchQueryInclude.getIncludedResources(any(), any())).thenReturn(Collections.singleton(new Observation()));
+
+ IBundleProvider results = serviceRequestService.searchForServiceRequests(serviceRequestSearchParams);
+
+ List resultList = get(results);
+
+ assertThat(results, notNullValue());
+ assertThat(resultList, not(empty()));
+ assertThat(resultList.size(), equalTo(2));
+ assertThat(resultList, hasItem(is(instanceOf(Observation.class))));
+ }
+
+ private HasAndListParam CreateHasAndListParam(String theTargetResourceType, String theReferenceFieldName,
+ String theParameterName, String theParameterValue) {
+ HasParam hasParam = new HasParam(theTargetResourceType, theReferenceFieldName, theParameterName, theParameterValue);
+ HasOrListParam hasOrListParam = new HasOrListParam();
+ hasOrListParam.add(hasParam);
+ HasAndListParam hasAndListParam = new HasAndListParam();
+ hasAndListParam.addValue(hasOrListParam);
+ return hasAndListParam;
+ }
}
diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/search/ServiceRequestSearchQueryTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/search/ServiceRequestSearchQueryTest.java
index eb88447973..a698f819f8 100644
--- a/api/src/test/java/org/openmrs/module/fhir2/api/search/ServiceRequestSearchQueryTest.java
+++ b/api/src/test/java/org/openmrs/module/fhir2/api/search/ServiceRequestSearchQueryTest.java
@@ -123,6 +123,8 @@ public class ServiceRequestSearchQueryTest extends BaseModuleContextSensitiveTes
private static final int END_INDEX = 10;
+ private static final int SERVICE_REQUEST_COUNT = 9;
+
@Autowired
private FhirServiceRequestDao dao;
@@ -158,13 +160,12 @@ public void searchForServiceRequests_shouldSearchForServiceRequestsByConceptId()
IBundleProvider results = search(theParams);
assertThat(results, notNullValue());
-
- assertThat(results.size(), equalTo(4));
+ assertThat(results.size(), equalTo(SERVICE_REQUEST_COUNT));
List resultList = get(results);
assertThat(resultList, not(empty()));
- assertThat(resultList.size(), equalTo(4));
+ assertThat(resultList.size(), equalTo(SERVICE_REQUEST_COUNT));
assertThat(resultList, everyItem(
hasProperty("code", hasProperty("coding", hasItem(hasProperty("code", equalTo(TEST_ORDER_CONCEPT_UUID)))))));
}
@@ -178,12 +179,12 @@ public void searchForServiceRequests_shouldSearchForServiceRequestsByConceptUuid
IBundleProvider results = search(theParams);
assertThat(results, notNullValue());
- assertThat(results.size(), equalTo(4));
+ assertThat(results.size(), equalTo(SERVICE_REQUEST_COUNT));
List resultList = get(results);
assertThat(resultList, not(empty()));
- assertThat(resultList, hasSize(equalTo(4)));
+ assertThat(resultList, hasSize(equalTo(SERVICE_REQUEST_COUNT)));
assertThat(resultList, everyItem(
hasProperty("code", hasProperty("coding", hasItem(hasProperty("code", equalTo(TEST_ORDER_CONCEPT_UUID)))))));
}
@@ -198,12 +199,12 @@ public void searchForServiceRequests_shouldSearchForServiceRequestsByConceptMapp
IBundleProvider results = search(theParams);
assertThat(results, notNullValue());
- assertThat(results.size(), equalTo(4));
+ assertThat(results.size(), equalTo(SERVICE_REQUEST_COUNT));
List resultList = get(results);
assertThat(resultList, not(empty()));
- assertThat(resultList, hasSize(equalTo(4)));
+ assertThat(resultList, hasSize(equalTo(SERVICE_REQUEST_COUNT)));
assertThat(resultList,
everyItem(
hasProperty("code", hasProperty("coding", hasItem(allOf(hasProperty("code", equalTo(TEST_ORDER_LOINC_CODE)),
@@ -221,12 +222,12 @@ public void searchForServiceRequests_shouldSupportMappedAndUnmappedConcepts() {
IBundleProvider results = search(theParams);
assertThat(results, notNullValue());
- assertThat(results.size(), equalTo(4));
+ assertThat(results.size(), equalTo(SERVICE_REQUEST_COUNT));
List resultList = get(results);
assertThat(resultList, not(empty()));
- assertThat(resultList, hasSize(equalTo(4)));
+ assertThat(resultList, hasSize(equalTo(SERVICE_REQUEST_COUNT)));
assertThat(resultList, everyItem(allOf(
hasProperty("code",
hasProperty("coding",
@@ -246,12 +247,12 @@ public void searchForServiceRequests_shouldReturnFromMultipleConceptMappings() {
IBundleProvider results = search(theParams);
assertThat(results, notNullValue());
- assertThat(results.size(), equalTo(4));
+ assertThat(results.size(), equalTo(SERVICE_REQUEST_COUNT));
List resultList = get(results);
assertThat(resultList, not(empty()));
- assertThat(resultList, hasSize(equalTo(4)));
+ assertThat(resultList, hasSize(equalTo(SERVICE_REQUEST_COUNT)));
assertThat(resultList,
everyItem(anyOf(
hasProperty("code",
@@ -273,12 +274,12 @@ public void searchForServiceRequests_shouldReturnServiceRequestsByPatientUuid()
IBundleProvider results = search(theParams);
assertThat(results, notNullValue());
- assertThat(results.size(), equalTo(4));
+ assertThat(results.size(), equalTo(SERVICE_REQUEST_COUNT));
List resultList = get(results);
assertThat(resultList, not(empty()));
- assertThat(resultList, hasSize(equalTo(4)));
+ assertThat(resultList, hasSize(equalTo(SERVICE_REQUEST_COUNT)));
assertThat(resultList, everyItem(
hasProperty("subject", hasProperty("referenceElement", hasProperty("idPart", equalTo(PATIENT_UUID))))));
}
@@ -294,12 +295,12 @@ public void searchForServiceRequests_shouldSearchForServiceRequestsByMultiplePat
IBundleProvider results = search(theParams);
assertThat(results, notNullValue());
- assertThat(results.size(), equalTo(4));
+ assertThat(results.size(), equalTo(SERVICE_REQUEST_COUNT));
List resultList = get(results);
assertThat(resultList, not(empty()));
- assertThat(resultList, hasSize(equalTo(4)));
+ assertThat(resultList, hasSize(equalTo(SERVICE_REQUEST_COUNT)));
assertThat(resultList, everyItem(
hasProperty("subject", hasProperty("referenceElement", hasProperty("idPart", equalTo(PATIENT_UUID))))));
}
@@ -335,7 +336,7 @@ public void searchForServiceRequests_shouldReturnServiceRequestsByPatientGivenNa
IBundleProvider results = search(theParams);
assertThat(results, notNullValue());
- assertThat(results.size(), equalTo(4));
+ assertThat(results.size(), equalTo(SERVICE_REQUEST_COUNT));
List resources = get(results);
@@ -355,7 +356,7 @@ public void searchForServiceRequests_shouldReturnServiceRequestsByPatientFamilyN
IBundleProvider results = search(theParams);
assertThat(results, notNullValue());
- assertThat(results.size(), equalTo(4));
+ assertThat(results.size(), equalTo(SERVICE_REQUEST_COUNT));
List resources = get(results);
@@ -376,7 +377,7 @@ public void searchForServiceRequests_shouldSearchForServiceRequestsByMultiplePat
IBundleProvider results = search(theParams);
assertThat(results, notNullValue());
- assertThat(results.size(), equalTo(4));
+ assertThat(results.size(), equalTo(SERVICE_REQUEST_COUNT));
List resources = get(results);
@@ -419,7 +420,7 @@ public void searchForServiceRequests_shouldSearchForServiceRequestsByMultiplePat
IBundleProvider results = search(theParams);
assertThat(results, notNullValue());
- assertThat(results.size(), equalTo(4));
+ assertThat(results.size(), equalTo(SERVICE_REQUEST_COUNT));
List resources = get(results);
@@ -461,7 +462,7 @@ public void searchForServiceRequests_shouldReturnServiceRequestsByPatientName()
IBundleProvider results = search(theParams);
assertThat(results, notNullValue());
- assertThat(results.size(), equalTo(4));
+ assertThat(results.size(), equalTo(SERVICE_REQUEST_COUNT));
List resources = get(results);
@@ -483,7 +484,7 @@ public void searchForServiceRequests_shouldSearchForServiceRequestsByMultiplePat
IBundleProvider results = search(theParams);
assertThat(results, notNullValue());
- assertThat(results.size(), equalTo(4));
+ assertThat(results.size(), equalTo(SERVICE_REQUEST_COUNT));
List resources = get(results);
@@ -524,12 +525,12 @@ public void searchForServiceRequests_shouldReturnServiceRequestsByPatientIdentif
IBundleProvider results = search(theParams);
assertThat(results, notNullValue());
- assertThat(results.size(), equalTo(4));
+ assertThat(results.size(), equalTo(SERVICE_REQUEST_COUNT));
List resources = get(results);
assertThat(resources, not(empty()));
- assertThat(resources, hasSize(equalTo(4)));
+ assertThat(resources, hasSize(equalTo(SERVICE_REQUEST_COUNT)));
assertThat(resources, everyItem(hasProperty("subject", hasProperty("reference", endsWith(PATIENT_UUID)))));
}
@@ -545,12 +546,12 @@ public void searchForServiceRequests_shouldSearchForServiceRequestsByMultiplePat
IBundleProvider results = search(theParams);
assertThat(results, notNullValue());
- assertThat(results.size(), equalTo(4));
+ assertThat(results.size(), equalTo(SERVICE_REQUEST_COUNT));
List resultList = get(results);
assertThat(resultList, not(empty()));
- assertThat(resultList, hasSize(equalTo(4)));
+ assertThat(resultList, hasSize(equalTo(SERVICE_REQUEST_COUNT)));
assertThat(resultList, everyItem(hasProperty("subject", hasProperty("reference", endsWith(PATIENT_UUID)))));
}
@@ -587,12 +588,12 @@ public void searchForServiceRequests_shouldReturnServiceRequestsByEncounter() {
IBundleProvider results = search(theParams);
assertThat(results, notNullValue());
- assertThat(results.size(), equalTo(4));
+ assertThat(results.size(), equalTo(SERVICE_REQUEST_COUNT));
List resources = get(results);
assertThat(resources, not(empty()));
- assertThat(resources, hasSize(equalTo(4)));
+ assertThat(resources, hasSize(equalTo(SERVICE_REQUEST_COUNT)));
assertThat(resources, everyItem(
hasProperty("encounter", hasProperty("referenceElement", hasProperty("idPart", equalTo(ENCOUNTER_UUID))))));
}
@@ -610,7 +611,7 @@ public void searchForServiceRequests_shouldReturnServiceRequestsByPatientUuidAnd
IBundleProvider results = search(theParams);
assertThat(results, notNullValue());
- assertThat(results.size(), equalTo(4));
+ assertThat(results.size(), equalTo(SERVICE_REQUEST_COUNT));
List resources = get(results);
@@ -630,12 +631,12 @@ public void searchForServiceRequests_shouldReturnServiceRequestsByMultipleEncoun
IBundleProvider results = search(theParams);
assertThat(results, notNullValue());
- assertThat(results.size(), equalTo(4));
+ assertThat(results.size(), equalTo(SERVICE_REQUEST_COUNT));
List resources = get(results);
assertThat(resources, not(empty()));
- assertThat(resources, hasSize(equalTo(4)));
+ assertThat(resources, hasSize(equalTo(SERVICE_REQUEST_COUNT)));
assertThat(resources, everyItem(anyOf(
hasProperty("encounter", hasProperty("referenceElement", hasProperty("idPart", equalTo(ENCOUNTER_UUID)))),
hasProperty("encounter", hasProperty("referenceElement", hasProperty("idPart", equalTo(ENCOUNTER_UUID_TWO)))))));
@@ -696,12 +697,12 @@ public void searchForServiceRequests_shouldReturnServiceRequestsByParticipantUui
IBundleProvider results = search(theParams);
assertThat(results, notNullValue());
- assertThat(results.size(), equalTo(4));
+ assertThat(results.size(), equalTo(SERVICE_REQUEST_COUNT));
List resources = get(results);
assertThat(resources, notNullValue());
- assertThat(resources, hasSize(equalTo(4)));
+ assertThat(resources, hasSize(equalTo(SERVICE_REQUEST_COUNT)));
assertThat(resources, everyItem(
hasProperty("requester", hasProperty("referenceElement", hasProperty("idPart", equalTo(PARTICIPANT_UUID))))));
}
@@ -718,12 +719,12 @@ public void searchForServiceRequests_shouldSearchForServiceRequestsByMultiplePar
IBundleProvider results = search(theParams);
assertThat(results, notNullValue());
- assertThat(results.size(), equalTo(4));
+ assertThat(results.size(), equalTo(SERVICE_REQUEST_COUNT));
List resources = get(results);
assertThat(resources, notNullValue());
- assertThat(resources, hasSize(equalTo(4)));
+ assertThat(resources, hasSize(equalTo(SERVICE_REQUEST_COUNT)));
assertThat(resources, everyItem(
hasProperty("requester", hasProperty("referenceElement", hasProperty("idPart", equalTo(PARTICIPANT_UUID))))));
}
@@ -759,12 +760,12 @@ public void searchForServiceRequests_shouldReturnServiceRequestsByParticipantGiv
IBundleProvider results = search(theParams);
assertThat(results, notNullValue());
- assertThat(results.size(), equalTo(4));
+ assertThat(results.size(), equalTo(SERVICE_REQUEST_COUNT));
List resources = get(results);
assertThat(resources, notNullValue());
- assertThat(resources, hasSize(equalTo(4)));
+ assertThat(resources, hasSize(equalTo(SERVICE_REQUEST_COUNT)));
assertThat(resources, everyItem(
hasProperty("requester", hasProperty("referenceElement", hasProperty("idPart", equalTo(PARTICIPANT_UUID))))));
}
@@ -781,12 +782,12 @@ public void searchForServiceRequests_shouldSearchForServiceRequestsByMultiplePar
IBundleProvider results = search(theParams);
assertThat(results, notNullValue());
- assertThat(results.size(), equalTo(4));
+ assertThat(results.size(), equalTo(SERVICE_REQUEST_COUNT));
List resources = get(results);
assertThat(resources, notNullValue());
- assertThat(resources, hasSize(equalTo(4)));
+ assertThat(resources, hasSize(equalTo(SERVICE_REQUEST_COUNT)));
assertThat(resources, everyItem(
hasProperty("requester", hasProperty("referenceElement", hasProperty("idPart", equalTo(PARTICIPANT_UUID))))));
}
@@ -824,12 +825,12 @@ public void searchForServiceRequests_shouldReturnServiceRequestsByParticipantFam
IBundleProvider results = search(theParams);
assertThat(results, notNullValue());
- assertThat(results.size(), equalTo(4));
+ assertThat(results.size(), equalTo(SERVICE_REQUEST_COUNT));
List resources = get(results);
assertThat(resources, notNullValue());
- assertThat(resources, hasSize(equalTo(4)));
+ assertThat(resources, hasSize(equalTo(SERVICE_REQUEST_COUNT)));
assertThat(resources, everyItem(
hasProperty("requester", hasProperty("referenceElement", hasProperty("idPart", equalTo(PARTICIPANT_UUID))))));
}
@@ -846,12 +847,12 @@ public void searchForServiceRequests_shouldSearchForServiceRequestsByMultiplePar
IBundleProvider results = search(theParams);
assertThat(results, notNullValue());
- assertThat(results.size(), equalTo(4));
+ assertThat(results.size(), equalTo(SERVICE_REQUEST_COUNT));
List resources = get(results);
assertThat(resources, notNullValue());
- assertThat(resources, hasSize(equalTo(4)));
+ assertThat(resources, hasSize(equalTo(SERVICE_REQUEST_COUNT)));
assertThat(resources, everyItem(
hasProperty("requester", hasProperty("referenceElement", hasProperty("idPart", equalTo(PARTICIPANT_UUID))))));
}
@@ -890,12 +891,12 @@ public void searchForServiceRequests_shouldReturnServiceRequestsByParticipantNam
IBundleProvider results = search(theParams);
assertThat(results, notNullValue());
- assertThat(results.size(), equalTo(4));
+ assertThat(results.size(), equalTo(SERVICE_REQUEST_COUNT));
List resources = get(results);
assertThat(resources, notNullValue());
- assertThat(resources, hasSize(equalTo(4)));
+ assertThat(resources, hasSize(equalTo(SERVICE_REQUEST_COUNT)));
assertThat(resources, everyItem(
hasProperty("requester", hasProperty("referenceElement", hasProperty("idPart", equalTo(PARTICIPANT_UUID))))));
}
@@ -915,12 +916,12 @@ public void searchForServiceRequests_shouldSearchForServiceRequestsByMultiplePar
IBundleProvider results = search(theParams);
assertThat(results, notNullValue());
- assertThat(results.size(), equalTo(4));
+ assertThat(results.size(), equalTo(SERVICE_REQUEST_COUNT));
List resources = get(results);
assertThat(resources, notNullValue());
- assertThat(resources, hasSize(equalTo(4)));
+ assertThat(resources, hasSize(equalTo(SERVICE_REQUEST_COUNT)));
assertThat(resources, everyItem(
hasProperty("requester", hasProperty("referenceElement", hasProperty("idPart", equalTo(PARTICIPANT_UUID))))));
}
@@ -959,12 +960,12 @@ public void searchForServiceRequests_shouldReturnServiceRequestsByParticipantIde
IBundleProvider results = search(theParams);
assertThat(results, notNullValue());
- assertThat(results.size(), equalTo(4));
+ assertThat(results.size(), equalTo(SERVICE_REQUEST_COUNT));
List resources = get(results);
assertThat(resources, notNullValue());
- assertThat(resources, hasSize(equalTo(4)));
+ assertThat(resources, hasSize(equalTo(SERVICE_REQUEST_COUNT)));
assertThat(resources, everyItem(
hasProperty("requester", hasProperty("identifier", hasProperty("value", equalTo(PARTICIPANT_IDENTIFIER))))));
}
@@ -981,12 +982,12 @@ public void searchForServiceRequests_shouldSearchForServiceRequestsByMultiplePar
IBundleProvider results = search(theParams);
assertThat(results, notNullValue());
- assertThat(results.size(), equalTo(4));
+ assertThat(results.size(), equalTo(SERVICE_REQUEST_COUNT));
List resources = get(results);
assertThat(resources, notNullValue());
- assertThat(resources, hasSize(equalTo(4)));
+ assertThat(resources, hasSize(equalTo(SERVICE_REQUEST_COUNT)));
assertThat(resources, everyItem(
hasProperty("requester", hasProperty("identifier", hasProperty("value", equalTo(PARTICIPANT_IDENTIFIER))))));
}
diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/search/param/ServiceRequestSearchParamsTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/search/param/ServiceRequestSearchParamsTest.java
new file mode 100644
index 0000000000..5059ce083a
--- /dev/null
+++ b/api/src/test/java/org/openmrs/module/fhir2/api/search/param/ServiceRequestSearchParamsTest.java
@@ -0,0 +1,46 @@
+/*
+ * This Source Code Form is subject to the terms of the Mozilla Public License,
+ * v. 2.0. If a copy of the MPL was not distributed with this file, You can
+ * obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under
+ * the terms of the Healthcare Disclaimer located at http://openmrs.org/license.
+ *
+ * Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS
+ * graphic logo is a trademark of OpenMRS Inc.
+ */
+package org.openmrs.module.fhir2.api.search.param;
+
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Before;
+import org.junit.Test;
+
+public class ServiceRequestSearchParamsTest {
+
+ private ServiceRequestSearchParams searchParam;
+
+ @Before
+ public void setup() {
+ searchParam = new ServiceRequestSearchParams();
+ }
+
+ @Test
+ public void equals_shouldBeTrueForSameReference() {
+ assertTrue(searchParam.equals(searchParam));
+ }
+
+ @Test
+ public void equals_shouldCalculateHashCode() {
+ assertNotEquals(0, searchParam.hashCode());
+ }
+
+ @Test
+ public void builder_shouldBuildParams() {
+ ServiceRequestSearchParams.ServiceRequestSearchParamsBuilder builder = ServiceRequestSearchParams.builder();
+
+ ServiceRequestSearchParams builtParams = builder.build();
+
+ assertNotNull(builtParams);
+ }
+}
diff --git a/api/src/test/java/org/openmrs/module/fhir2/providers/r3/ProcedureRequestFhirResourceProviderTest.java b/api/src/test/java/org/openmrs/module/fhir2/providers/r3/ProcedureRequestFhirResourceProviderTest.java
index eecf532180..c5cb799ad6 100644
--- a/api/src/test/java/org/openmrs/module/fhir2/providers/r3/ProcedureRequestFhirResourceProviderTest.java
+++ b/api/src/test/java/org/openmrs/module/fhir2/providers/r3/ProcedureRequestFhirResourceProviderTest.java
@@ -17,6 +17,7 @@
import static org.hamcrest.Matchers.hasSize;
import static org.hl7.fhir.convertors.factory.VersionConvertorFactory_30_40.convertResource;
import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.argThat;
import static org.mockito.Mockito.when;
@@ -30,6 +31,9 @@
import ca.uhn.fhir.rest.api.MethodOutcome;
import ca.uhn.fhir.rest.api.server.IBundleProvider;
import ca.uhn.fhir.rest.param.DateRangeParam;
+import ca.uhn.fhir.rest.param.HasAndListParam;
+import ca.uhn.fhir.rest.param.HasOrListParam;
+import ca.uhn.fhir.rest.param.HasParam;
import ca.uhn.fhir.rest.param.ReferenceAndListParam;
import ca.uhn.fhir.rest.param.ReferenceOrListParam;
import ca.uhn.fhir.rest.param.ReferenceParam;
@@ -141,7 +145,7 @@ public void searchProcedureRequest_shouldReturnMatchingProcedureRequestByCode()
TokenAndListParam code = new TokenAndListParam().addAnd(new TokenParam(CODE));
IBundleProvider results = resourceProvider.searchForProcedureRequests(null, null, code, null, null, null, null, null,
- null);
+ null, null);
List resources = getResources(results);
@@ -161,7 +165,7 @@ public void searchProcedureRequest_shouldReturnMatchingProcedureRequestWhenPatie
new ReferenceOrListParam().add(new ReferenceParam().setValue(PATIENT_GIVEN_NAME).setChain(Patient.SP_NAME)));
IBundleProvider results = resourceProvider.searchForProcedureRequests(patientParam, null, null, null, null, null,
- null, null, null);
+ null, null, null, null);
List resources = getResources(results);
@@ -181,7 +185,7 @@ public void searchProcedureRequest_shouldReturnMatchingProcedureRequestWhenSubje
new ReferenceOrListParam().add(new ReferenceParam().setValue(PATIENT_GIVEN_NAME).setChain(Patient.SP_NAME)));
IBundleProvider results = resourceProvider.searchForProcedureRequests(null, subjectParam, null, null, null, null,
- null, null, null);
+ null, null, null, null);
List resources = getResources(results);
@@ -201,7 +205,7 @@ public void searchProcedureRequest_shouldReturnMatchingProcedureRequestByRequest
.add(new ReferenceParam().setValue(PARTICIPANT_IDENTIFIER).setChain(Practitioner.SP_IDENTIFIER)));
IBundleProvider results = resourceProvider.searchForProcedureRequests(null, null, null, null, practitionerParam,
- null, null, null, null);
+ null, null, null, null, null);
List resources = getResources(results);
@@ -220,7 +224,7 @@ public void searchProcedureRequest_shouldReturnMatchingProcedureRequestByOccurre
DateRangeParam occurrence = new DateRangeParam().setLowerBound(OCCURRENCE).setUpperBound(OCCURRENCE);
IBundleProvider results = resourceProvider.searchForProcedureRequests(null, null, null, null, null, occurrence, null,
- null, null);
+ null, null, null);
List resources = getResources(results);
@@ -240,7 +244,7 @@ public void searchProcedureRequest_shouldReturnMatchingProcedureRequestByEncount
.addAnd(new ReferenceOrListParam().add(new ReferenceParam().setValue(ENCOUNTER_UUID).setChain(null)));
IBundleProvider results = resourceProvider.searchForProcedureRequests(null, null, null, encounterParam, null, null,
- null, null, null);
+ null, null, null, null);
List resources = getResources(results);
@@ -327,7 +331,7 @@ public void searchProcedureRequest_shouldReturnMatchingProcedureRequestWhenUUIDI
new MockIBundleProvider<>(Collections.singletonList(serviceRequest), PREFERRED_PAGE_SIZE, COUNT));
IBundleProvider results = resourceProvider.searchForProcedureRequests(null, null, null, null, null, null, uuid, null,
- null);
+ null, null);
List resources = getResources(results);
@@ -346,7 +350,7 @@ public void searchProcedureRequest_shouldReturnMatchingProcedureRequestWhenLastU
new MockIBundleProvider<>(Collections.singletonList(serviceRequest), PREFERRED_PAGE_SIZE, COUNT));
IBundleProvider results = resourceProvider.searchForProcedureRequests(null, null, null, null, null, null, null,
- lastUpdated, null);
+ lastUpdated, null, null);
List resources = getResources(results);
@@ -369,7 +373,7 @@ public void searchProcedureRequest_shouldAddRelatedResourcesToResultListWhenIncl
new MockIBundleProvider<>(Arrays.asList(serviceRequest, new Patient()), PREFERRED_PAGE_SIZE, COUNT));
IBundleProvider results = resourceProvider.searchForProcedureRequests(null, null, null, null, null, null, null, null,
- includes);
+ null, includes);
List resources = getResources(results);
@@ -392,7 +396,7 @@ public void searchProcedureRequest_shouldNotAddRelatedResourcesToResultListForEm
new MockIBundleProvider<>(Collections.singletonList(serviceRequest), PREFERRED_PAGE_SIZE, COUNT));
IBundleProvider results = resourceProvider.searchForProcedureRequests(null, null, null, null, null, null, null, null,
- includes);
+ null, includes);
List resources = getResources(results);
@@ -403,4 +407,28 @@ public void searchProcedureRequest_shouldNotAddRelatedResourcesToResultListForEm
assertThat(resources.get(0).getIdElement().getIdPart(), Matchers.equalTo(SERVICE_REQUEST_UUID));
}
+ @Test
+ public void searchServiceRequest_shouldReturnMatchingServiceRequestWhenHasObservationBasedOnIsSpecified() {
+ HasOrListParam hasOrListParam = new HasOrListParam();
+ hasOrListParam.add(new HasParam("Observation", "based-on", "category", "laboratory"));
+ HasAndListParam hasAndListParam = new HasAndListParam();
+ hasAndListParam.addAnd(hasOrListParam);
+
+ // an empty set of includes is converted to null before being passed on to searchForServiceRequests
+ when(serviceRequestService.searchForServiceRequests(
+ argThat((ServiceRequestSearchParams serviceRequestSearchParams) -> serviceRequestSearchParams
+ .getHasAndListParam() == hasAndListParam))).thenReturn(
+ new MockIBundleProvider<>(Collections.singletonList(serviceRequest), PREFERRED_PAGE_SIZE, COUNT));
+
+ IBundleProvider results = resourceProvider.searchForProcedureRequests(null, null, null, null, null, null, null, null,
+ hasAndListParam, null);
+
+ List resources = getResources(results);
+
+ assertThat(results, notNullValue());
+ assertThat(resources, hasSize(Matchers.equalTo(1)));
+ assertThat(resources.get(0), notNullValue());
+ assertThat(resources.get(0).fhirType(), Matchers.equalTo(FhirConstants.PROCEDURE_REQUEST));
+ assertThat(resources.get(0).getIdElement().getIdPart(), Matchers.equalTo(SERVICE_REQUEST_UUID));
+ }
}
diff --git a/api/src/test/java/org/openmrs/module/fhir2/providers/r4/ServiceRequestFhirResourceProviderTest.java b/api/src/test/java/org/openmrs/module/fhir2/providers/r4/ServiceRequestFhirResourceProviderTest.java
index d9e61305ab..9f7e53e859 100644
--- a/api/src/test/java/org/openmrs/module/fhir2/providers/r4/ServiceRequestFhirResourceProviderTest.java
+++ b/api/src/test/java/org/openmrs/module/fhir2/providers/r4/ServiceRequestFhirResourceProviderTest.java
@@ -28,6 +28,9 @@
import ca.uhn.fhir.rest.api.MethodOutcome;
import ca.uhn.fhir.rest.api.server.IBundleProvider;
import ca.uhn.fhir.rest.param.DateRangeParam;
+import ca.uhn.fhir.rest.param.HasAndListParam;
+import ca.uhn.fhir.rest.param.HasOrListParam;
+import ca.uhn.fhir.rest.param.HasParam;
import ca.uhn.fhir.rest.param.ReferenceAndListParam;
import ca.uhn.fhir.rest.param.ReferenceOrListParam;
import ca.uhn.fhir.rest.param.ReferenceParam;
@@ -137,7 +140,7 @@ public void searchServiceRequest_shouldReturnMatchingServiceRequestsByCode() {
TokenAndListParam code = new TokenAndListParam().addAnd(new TokenParam(CODE));
IBundleProvider results = resourceProvider.searchForServiceRequests(null, null, code, null, null, null, null, null,
- null);
+ null, null);
List resources = getResources(results);
@@ -157,7 +160,7 @@ public void searchServiceRequest_shouldReturnMatchingServiceRequestsWhenPatientP
new ReferenceOrListParam().add(new ReferenceParam().setValue(PATIENT_GIVEN_NAME).setChain(Patient.SP_NAME)));
IBundleProvider results = resourceProvider.searchForServiceRequests(patientParam, null, null, null, null, null, null,
- null, null);
+ null, null, null);
List resources = getResources(results);
@@ -177,7 +180,7 @@ public void searchServiceRequest_shouldReturnMatchingServiceRequestsWhenSubjectP
new ReferenceOrListParam().add(new ReferenceParam().setValue(PATIENT_GIVEN_NAME).setChain(Patient.SP_NAME)));
IBundleProvider results = resourceProvider.searchForServiceRequests(null, subjectParam, null, null, null, null, null,
- null, null);
+ null, null, null);
List resources = getResources(results);
@@ -197,7 +200,7 @@ public void searchServiceRequest_shouldReturnMatchingServiceRequestsByRequesterP
.add(new ReferenceParam().setValue(PARTICIPANT_IDENTIFIER).setChain(Practitioner.SP_IDENTIFIER)));
IBundleProvider results = resourceProvider.searchForServiceRequests(null, null, null, null, practitionerParam, null,
- null, null, null);
+ null, null, null, null);
List resources = getResources(results);
@@ -216,7 +219,7 @@ public void searchServiceRequest_shouldReturnMatchingServiceRequestsByOccurrence
DateRangeParam occurrence = new DateRangeParam().setLowerBound(OCCURRENCE).setUpperBound(OCCURRENCE);
IBundleProvider results = resourceProvider.searchForServiceRequests(null, null, null, null, null, occurrence, null,
- null, null);
+ null, null, null);
List resources = getResources(results);
@@ -236,7 +239,7 @@ public void searchServiceRequests_shouldReturnMatchingServiceRequestsByEncounter
.addAnd(new ReferenceOrListParam().add(new ReferenceParam().setValue(ENCOUNTER_UUID).setChain(null)));
IBundleProvider results = resourceProvider.searchForServiceRequests(null, null, null, encounterParam, null, null,
- null, null, null);
+ null, null, null, null);
List resources = getResources(results);
@@ -255,7 +258,7 @@ public void searchServiceRequest_shouldReturnMatchingServiceRequestWhenUUIDIsSpe
new MockIBundleProvider<>(Collections.singletonList(serviceRequest), PREFERRED_PAGE_SIZE, COUNT));
IBundleProvider results = resourceProvider.searchForServiceRequests(null, null, null, null, null, null, uuid, null,
- null);
+ null, null);
List resources = getResources(results);
@@ -274,7 +277,7 @@ public void searchServiceRequest_shouldReturnMatchingServiceRequestWhenLastUpdat
new MockIBundleProvider<>(Collections.singletonList(serviceRequest), PREFERRED_PAGE_SIZE, COUNT));
IBundleProvider results = resourceProvider.searchForServiceRequests(null, null, null, null, null, null, null,
- lastUpdated, null);
+ lastUpdated, null, null);
List resources = getResources(results);
@@ -357,7 +360,7 @@ public void searchServiceRequest_shouldAddRelatedResourcesToResultListWhenInclud
new MockIBundleProvider<>(Arrays.asList(serviceRequest, new Patient()), PREFERRED_PAGE_SIZE, COUNT));
IBundleProvider results = resourceProvider.searchForServiceRequests(null, null, null, null, null, null, null, null,
- includes);
+ null, includes);
List resources = getResources(results);
@@ -380,7 +383,32 @@ public void searchServiceRequest_shouldNotAddRelatedResourcesToResultListForEmpt
new MockIBundleProvider<>(Collections.singletonList(serviceRequest), PREFERRED_PAGE_SIZE, COUNT));
IBundleProvider results = resourceProvider.searchForServiceRequests(null, null, null, null, null, null, null, null,
- includes);
+ null, includes);
+
+ List resources = getResources(results);
+
+ assertThat(results, notNullValue());
+ assertThat(resources, hasSize(Matchers.equalTo(1)));
+ assertThat(resources.get(0), notNullValue());
+ assertThat(resources.get(0).fhirType(), Matchers.equalTo(FhirConstants.SERVICE_REQUEST));
+ assertThat(resources.get(0).getIdElement().getIdPart(), Matchers.equalTo(SERVICE_REQUEST_UUID));
+ }
+
+ @Test
+ public void searchServiceRequest_shouldReturnMatchingServiceRequestWhenHasObservationBasedOnIsSpecified() {
+ HasOrListParam hasOrListParam = new HasOrListParam();
+ hasOrListParam.add(new HasParam("Observation", "based-on", "category", "laboratory"));
+ HasAndListParam hasAndListParam = new HasAndListParam();
+ hasAndListParam.addAnd(hasOrListParam);
+
+ // an empty set of includes is converted to null before being passed on to searchForServiceRequests
+ when(serviceRequestService.searchForServiceRequests(
+ argThat((ServiceRequestSearchParams serviceRequestSearchParams) -> serviceRequestSearchParams
+ .getHasAndListParam() == hasAndListParam))).thenReturn(
+ new MockIBundleProvider<>(Collections.singletonList(serviceRequest), PREFERRED_PAGE_SIZE, COUNT));
+
+ IBundleProvider results = resourceProvider.searchForServiceRequests(null, null, null, null, null, null, null, null,
+ hasAndListParam, null);
List resources = getResources(results);
diff --git a/test-data/src/main/resources/org/openmrs/module/fhir2/api/dao/impl/FhirServiceRequestTest_initial_data.xml b/test-data/src/main/resources/org/openmrs/module/fhir2/api/dao/impl/FhirServiceRequestTest_initial_data.xml
index 42e457e35f..bca4bf83b2 100644
--- a/test-data/src/main/resources/org/openmrs/module/fhir2/api/dao/impl/FhirServiceRequestTest_initial_data.xml
+++ b/test-data/src/main/resources/org/openmrs/module/fhir2/api/dao/impl/FhirServiceRequestTest_initial_data.xml
@@ -28,5 +28,46 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
From a61692863f6cea81a8dc6a2eefa2db8d1495ba3e Mon Sep 17 00:00:00 2001
From: md-at-slashwhy <95024503+md-at-slashwhy@users.noreply.github.com>
Date: Wed, 22 Nov 2023 14:56:47 +0100
Subject: [PATCH 5/9] FM2-347: implement _has search for obs with date, string,
uuid or category as value
---
.../dao/impl/FhirServiceRequestDaoImpl.java | 243 +++++++++++++++++-
1 file changed, 242 insertions(+), 1 deletion(-)
diff --git a/api/src/main/java/org/openmrs/module/fhir2/api/dao/impl/FhirServiceRequestDaoImpl.java b/api/src/main/java/org/openmrs/module/fhir2/api/dao/impl/FhirServiceRequestDaoImpl.java
index 3262e476e3..3c515aaa93 100644
--- a/api/src/main/java/org/openmrs/module/fhir2/api/dao/impl/FhirServiceRequestDaoImpl.java
+++ b/api/src/main/java/org/openmrs/module/fhir2/api/dao/impl/FhirServiceRequestDaoImpl.java
@@ -11,17 +11,35 @@
import static org.hibernate.criterion.Restrictions.and;
import static org.hibernate.criterion.Restrictions.or;
+import static org.hibernate.criterion.Subqueries.propertyIn;
+import javax.validation.constraints.NotNull;
+
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.util.Date;
+import java.util.List;
import java.util.Optional;
+import java.util.Set;
+import java.util.stream.Collectors;
import java.util.stream.Stream;
import ca.uhn.fhir.rest.param.DateRangeParam;
+import ca.uhn.fhir.rest.param.HasAndListParam;
+import ca.uhn.fhir.rest.param.HasParam;
import ca.uhn.fhir.rest.param.ReferenceAndListParam;
import ca.uhn.fhir.rest.param.TokenAndListParam;
import lombok.AccessLevel;
import lombok.Setter;
+import lombok.extern.slf4j.Slf4j;
import org.hibernate.Criteria;
import org.hibernate.criterion.Criterion;
+import org.hibernate.criterion.DetachedCriteria;
+import org.hibernate.criterion.Projections;
+import org.hibernate.criterion.Restrictions;
+import org.hl7.fhir.r4.model.Observation;
+import org.openmrs.ConceptClass;
+import org.openmrs.Obs;
import org.openmrs.TestOrder;
import org.openmrs.module.fhir2.FhirConstants;
import org.openmrs.module.fhir2.api.dao.FhirServiceRequestDao;
@@ -30,6 +48,7 @@
@Component
@Setter(AccessLevel.PACKAGE)
+@Slf4j
public class FhirServiceRequestDaoImpl extends BaseFhirDao implements FhirServiceRequestDao {
@Override
@@ -46,7 +65,7 @@ protected void setupSearchParams(Criteria criteria, SearchParameterMap theParams
param -> handleEncounterReference(criteria, (ReferenceAndListParam) param.getParam(), "e"));
break;
case FhirConstants.HAS_SEARCH_HANDLER:
- // TODO: add implementation of the has search. stub is required for other tests not to fail
+ entry.getValue().forEach(param -> handleHasAndListParam(criteria, (HasAndListParam) param.getParam()));
break;
case FhirConstants.PATIENT_REFERENCE_SEARCH_HANDLER:
entry.getValue().forEach(patientReference -> handlePatientReference(criteria,
@@ -92,4 +111,226 @@ private Optional handleDateRange(DateRangeParam dateRangeParam) {
handleDate("autoExpireDate", dateRangeParam.getUpperBound())))))))));
}
+ /**
+ * Handle _has parameters that are passed in to constrain the ServiceRequest resource on properties
+ * of dependent resources
+ */
+ private void handleHasAndListParam(Criteria criteria, HasAndListParam hasAndListParam) {
+ if (criteria == null) {
+ log.warn("handleHasAndListParam called without criteria.");
+ return;
+ }
+
+ if (hasAndListParam == null) {
+ log.warn("handleHasAndListParam called without param or param list.");
+ return;
+ }
+
+ hasAndListParam.getValuesAsQueryTokens().forEach(hasOrListParam -> {
+ List queryTokens = hasOrListParam.getValuesAsQueryTokens();
+ if (queryTokens.isEmpty()) {
+ return;
+ }
+
+ // Making the assumption that any "orListParams" match everything except for the value
+ HasParam hasParam = queryTokens.get(0);
+ Set values = queryTokens.stream().map(HasParam::getParameterValue).collect(Collectors.toSet());
+
+ switch (hasParam.getTargetResourceType()) {
+ case FhirConstants.OBSERVATION:
+ handleHasObservation(criteria, hasParam, values);
+ break;
+ default:
+ log.warn("_has parameter not supported: " + hasParam.getQueryParameterQualifier());
+ }
+ });
+ }
+
+ private void handleHasObservation(Criteria criteria, HasParam hasParam, Set values) {
+ String projection = null;
+ switch (hasParam.getReferenceFieldName()) {
+ case Observation.SP_BASED_ON:
+ projection = "order";
+ break;
+ default:
+ log.warn("Failed to add has constraint for non-existent reference " + hasParam.getReferenceFieldName());
+ // ensure no entries are found
+ criteria.add(Restrictions.isNull("id"));
+ }
+
+ if (projection == null) {
+ return;
+ }
+
+ String parameterName = hasParam.getParameterName();
+ String parameterValue = hasParam.getParameterValue();
+ DetachedCriteria observationCriteria = createObservationCriteria(projection, parameterName, parameterValue);
+
+ criteria.add(propertyIn("id", observationCriteria));
+ }
+
+ // the detached criteria in this file should all return a subquery of ids to make usage of them consistent
+ private DetachedCriteria createObservationCriteria(String projection, String parameterName, String parameterValue) {
+ DetachedCriteria observationQuery = DetachedCriteria.forClass(Obs.class);
+ observationQuery.setProjection(Projections.property(projection));
+
+ if (parameterName == null) {
+ // just check for existence of any observation if no further propertyname is given
+ return observationQuery;
+ }
+
+ switch (parameterName) {
+ case Observation.SP_DATE:
+ addSimpleDateSearch(observationQuery, "obsDatetime", parameterValue);
+ break;
+
+ case Observation.SP_PATIENT:
+ case Observation.SP_SUBJECT:
+ addReferenceSearchByUuid(observationQuery, "person", parameterValue);
+ break;
+
+ case Observation.SP_VALUE_CONCEPT:
+ addReferenceSearchByUuid(observationQuery, "valueCoded", parameterValue);
+ break;
+
+ case Observation.SP_VALUE_DATE:
+ addSimpleDateSearch(observationQuery, "valueDatetime", parameterValue);
+ break;
+
+ case Observation.SP_HAS_MEMBER:
+ if (parameterValue == null) {
+ observationQuery.add(Restrictions.isNotNull("groupMembers"));
+ break;
+ }
+
+ // TODO : observationQuery.add(Restrictions.in( parameterValue, "groupMembers"));
+ break;
+
+ case Observation.SP_VALUE_STRING:
+ addSimpleSearch(observationQuery, "valueText", parameterValue);
+ break;
+
+ case Observation.SP_IDENTIFIER:
+ addSimpleSearch(observationQuery, "uuid", parameterValue);
+ break;
+
+ case Observation.SP_ENCOUNTER:
+ addReferenceSearchByUuid(observationQuery, "encounter", parameterValue);
+ break;
+
+ case Observation.SP_CATEGORY:
+ if (parameterValue == null) {
+ observationQuery.add(Restrictions.isNotNull("concept"));
+ break;
+ }
+
+ // TODO: where are the possible values defined? Are all values in ConceptClass relevant?
+ switch (parameterValue) {
+ case "laboratory":
+ addReferenceSearchByUuid(observationQuery, "concept", ConceptClass.LABSET_UUID);
+ break;
+
+ default:
+ log.warn(
+ "Failed to add has constraint for observation category with unknown concept " + parameterValue);
+ // ensure no entries are found
+ addNoResultsCriteria(observationQuery);
+ }
+ break;
+
+ case Observation.SP_STATUS:
+ addSimpleSearch(observationQuery, "status", parameterValue);
+ break;
+
+ // TODO: should be implementable
+ case Observation.SP_CODE:
+ case Observation.SP_VALUE_QUANTITY:
+ case Observation.SP_PERFORMER:
+
+ // TODO: add explanation on why these values are not implemented
+ case Observation.SP_CODE_VALUE_STRING:
+ case Observation.SP_PART_OF:
+ case Observation.SP_CODE_VALUE_DATE:
+ case Observation.SP_CODE_VALUE_QUANTITY:
+ case Observation.SP_CODE_VALUE_CONCEPT:
+
+ // could be implemented via accessionNumber matching
+ case Observation.SP_SPECIMEN:
+
+ // no meaningful mapping in OpenMRS
+ case Observation.SP_FOCUS:
+ case Observation.SP_DERIVED_FROM:
+ case Observation.SP_METHOD:
+ case Observation.SP_DATA_ABSENT_REASON:
+ case Observation.SP_DEVICE:
+
+ // OpenMRS does not support Components yet, this includes the SP_COMPONENT_* space and SP_COMBO_* space
+ case Observation.SP_COMPONENT_DATA_ABSENT_REASON:
+ case Observation.SP_COMPONENT_CODE_VALUE_QUANTITY:
+ case Observation.SP_COMPONENT_VALUE_QUANTITY:
+ case Observation.SP_COMPONENT_CODE_VALUE_CONCEPT:
+ case Observation.SP_COMPONENT_VALUE_CONCEPT:
+ case Observation.SP_COMPONENT_CODE:
+ case Observation.SP_COMBO_DATA_ABSENT_REASON:
+ case Observation.SP_COMBO_CODE:
+ case Observation.SP_COMBO_CODE_VALUE_QUANTITY:
+ case Observation.SP_COMBO_CODE_VALUE_CONCEPT:
+ case Observation.SP_COMBO_VALUE_QUANTITY:
+ case Observation.SP_COMBO_VALUE_CONCEPT:
+ log.warn(
+ "Failed to add has constraint for observation search parameter " + parameterValue + ": Not Implemented.");
+ // ensure no entries are found
+ addNoResultsCriteria(observationQuery);
+ break;
+
+ default:
+ log.warn(
+ "Failed to add has constraint for observation search parameter " + parameterValue + ": Invalid search parameter.");
+ // ensure no entries are found
+ addNoResultsCriteria(observationQuery);
+ break;
+ }
+
+ return observationQuery;
+ }
+
+ private void addReferenceSearchByUuid(DetachedCriteria observationQuery, String parameterField, String parameterValue){
+ if (parameterValue == null) {
+ observationQuery.add(Restrictions.isNotNull(parameterField));
+ return;
+ }
+
+ observationQuery.createAlias(parameterField, parameterField);
+ observationQuery.add(Restrictions.eq(parameterField + ".uuid", parameterValue));
+ }
+
+ private void addSimpleDateSearch(DetachedCriteria observationQuery, String parameterField, String parameterValue){
+ if(parameterValue == null){
+ addSimpleSearch(observationQuery, parameterField, parameterValue);
+ return;
+ }
+
+ try{
+ Date valueDate = DateFormat.getDateTimeInstance().parse(parameterValue);
+ addSimpleSearch(observationQuery, "valueDatetime", valueDate);
+ } catch (ParseException e) {
+ log.warn(
+ "Failed to parse Date " + parameterValue);
+ // ensure no entries are found
+ addNoResultsCriteria(observationQuery);
+ }
+ }
+
+ private void addSimpleSearch(DetachedCriteria observationQuery, String parameterField, Object parameterValue){
+ if (parameterValue == null) {
+ observationQuery.add(Restrictions.isNotNull(parameterField));
+ return;
+ }
+
+ observationQuery.add(Restrictions.eq(parameterField, parameterValue));
+ }
+
+ private void addNoResultsCriteria(DetachedCriteria observationQuery){
+ observationQuery.add(Restrictions.isNull("id"));
+ }
}
From 83d1a0c153f2bdeccb1559c01aa510e110944a59 Mon Sep 17 00:00:00 2001
From: md-at-slashwhy <95024503+md-at-slashwhy@users.noreply.github.com>
Date: Wed, 22 Nov 2023 14:56:47 +0100
Subject: [PATCH 6/9] FM2-347: fix remaining (status, has-member, code and
value-quantity) operations for _has search
---
.../dao/impl/FhirServiceRequestDaoImpl.java | 161 ++++++---
.../impl/FhirServiceRequestDaoImplTest.java | 320 ++++++++----------
.../FhirServiceRequestServiceImplTest.java | 5 +-
.../search/ServiceRequestSearchQueryTest.java | 2 +-
...ServiceRequestDaoImplTest_initial_data.xml | 94 +++++
.../FhirServiceRequestTest_initial_data.xml | 41 ---
6 files changed, 345 insertions(+), 278 deletions(-)
create mode 100644 test-data/src/main/resources/org/openmrs/module/fhir2/api/dao/impl/FhirServiceRequestDaoImplTest_initial_data.xml
diff --git a/api/src/main/java/org/openmrs/module/fhir2/api/dao/impl/FhirServiceRequestDaoImpl.java b/api/src/main/java/org/openmrs/module/fhir2/api/dao/impl/FhirServiceRequestDaoImpl.java
index 3c515aaa93..8611137a93 100644
--- a/api/src/main/java/org/openmrs/module/fhir2/api/dao/impl/FhirServiceRequestDaoImpl.java
+++ b/api/src/main/java/org/openmrs/module/fhir2/api/dao/impl/FhirServiceRequestDaoImpl.java
@@ -13,8 +13,6 @@
import static org.hibernate.criterion.Restrictions.or;
import static org.hibernate.criterion.Subqueries.propertyIn;
-import javax.validation.constraints.NotNull;
-
import java.text.DateFormat;
import java.text.ParseException;
import java.util.Date;
@@ -39,7 +37,9 @@
import org.hibernate.criterion.Restrictions;
import org.hl7.fhir.r4.model.Observation;
import org.openmrs.ConceptClass;
+import org.openmrs.EncounterProvider;
import org.openmrs.Obs;
+import org.openmrs.Obs.Status;
import org.openmrs.TestOrder;
import org.openmrs.module.fhir2.FhirConstants;
import org.openmrs.module.fhir2.api.dao.FhirServiceRequestDao;
@@ -147,7 +147,7 @@ private void handleHasAndListParam(Criteria criteria, HasAndListParam hasAndList
}
private void handleHasObservation(Criteria criteria, HasParam hasParam, Set values) {
- String projection = null;
+ String projection;
switch (hasParam.getReferenceFieldName()) {
case Observation.SP_BASED_ON:
projection = "order";
@@ -156,10 +156,7 @@ private void handleHasObservation(Criteria criteria, HasParam hasParam, Set> void addEnumSearch(DetachedCriteria observationQuery, String parameterField,
+ Class enumClass, String parameterValue) {
+ if (parameterValue == null) {
+ addSimpleSearch(observationQuery, parameterField, parameterValue);
+ return;
+ }
+
+ try {
+ T enumValue = Enum.valueOf(enumClass, parameterValue);
+ addSimpleSearch(observationQuery, parameterField, enumValue);
+ }
+ catch (IllegalArgumentException e) {
+ log.warn("Failed to parse Enum " + parameterValue);
+ // ensure no entries are found
+ addNoResultsCriteria(observationQuery);
+ }
+ }
+
+ private void addReferenceSearchByUuid(DetachedCriteria observationQuery, String parameterField, String parameterValue) {
if (parameterValue == null) {
observationQuery.add(Restrictions.isNotNull(parameterField));
return;
@@ -303,34 +335,51 @@ private void addReferenceSearchByUuid(DetachedCriteria observationQuery, String
observationQuery.createAlias(parameterField, parameterField);
observationQuery.add(Restrictions.eq(parameterField + ".uuid", parameterValue));
}
-
- private void addSimpleDateSearch(DetachedCriteria observationQuery, String parameterField, String parameterValue){
- if(parameterValue == null){
+
+ private void addSimpleDateSearch(DetachedCriteria observationQuery, String parameterField, String parameterValue) {
+ if (parameterValue == null) {
addSimpleSearch(observationQuery, parameterField, parameterValue);
return;
}
-
- try{
+
+ try {
Date valueDate = DateFormat.getDateTimeInstance().parse(parameterValue);
- addSimpleSearch(observationQuery, "valueDatetime", valueDate);
- } catch (ParseException e) {
- log.warn(
- "Failed to parse Date " + parameterValue);
+ addSimpleSearch(observationQuery, parameterField, valueDate);
+ }
+ catch (ParseException e) {
+ log.warn("Failed to parse Date " + parameterValue);
// ensure no entries are found
addNoResultsCriteria(observationQuery);
}
}
-
- private void addSimpleSearch(DetachedCriteria observationQuery, String parameterField, Object parameterValue){
+
+ private void addSimpleDoubleSearch(DetachedCriteria observationQuery, String parameterField, String parameterValue) {
+ if (parameterValue == null) {
+ addSimpleSearch(observationQuery, parameterField, parameterValue);
+ return;
+ }
+
+ try {
+ Double valueInteger = Double.parseDouble(parameterValue);
+ addSimpleSearch(observationQuery, parameterField, valueInteger);
+ }
+ catch (NumberFormatException e) {
+ log.warn("Failed to parse Double " + parameterValue);
+ // ensure no entries are found
+ addNoResultsCriteria(observationQuery);
+ }
+ }
+
+ private void addSimpleSearch(DetachedCriteria observationQuery, String parameterField, Object parameterValue) {
if (parameterValue == null) {
observationQuery.add(Restrictions.isNotNull(parameterField));
return;
}
-
+
observationQuery.add(Restrictions.eq(parameterField, parameterValue));
}
-
- private void addNoResultsCriteria(DetachedCriteria observationQuery){
+
+ private void addNoResultsCriteria(DetachedCriteria observationQuery) {
observationQuery.add(Restrictions.isNull("id"));
}
}
diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirServiceRequestDaoImplTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirServiceRequestDaoImplTest.java
index 13838bf60a..c9ee9de8c2 100644
--- a/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirServiceRequestDaoImplTest.java
+++ b/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirServiceRequestDaoImplTest.java
@@ -14,8 +14,12 @@
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;
+import static org.junit.Assert.assertEquals;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
import java.util.Collection;
+import java.util.Date;
import java.util.List;
import ca.uhn.fhir.rest.param.HasAndListParam;
@@ -24,9 +28,9 @@
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.Predicate;
import org.hibernate.SessionFactory;
+import org.junit.After;
import org.junit.Before;
import org.junit.Test;
-import org.openmrs.Obs;
import org.openmrs.OrderType;
import org.openmrs.TestOrder;
import org.openmrs.module.fhir2.FhirConstants;
@@ -51,12 +55,20 @@ public class FhirServiceRequestDaoImplTest extends BaseModuleContextSensitiveTes
private static final String ORDER_WITH_CODED_VALUE_UUID = "b5bb2ba7-b17d-473e-907b-de7ad5374804";
private static final String ORDER_WITH_DATETIME_VALUE_UUID = "a5a0f4a2-8d32-4527-ae8e-2be8cb76a899";
-
+
private static final String ORDER_WITH_TEXT_VALUE_UUID = "fb5e9e5f-1800-4c96-b18e-0d89cf20219";
+ private static final String ORDER_WITH_NUMERIC_VALUE_UUID = "6b870cea-03c2-487d-918c-057a6bdce8c";
+
+ private static final String ORDER_WITH_PROVIDER_UUID = "7992afb9-437a-4609-bcaa-81d6cb2fe40";
+
+ private static final String ORDER_WITH_STATUS_UUID = "4bd2b016-a773-4d76-b9e1-1c70a80e6a83";
+
+ private static final String ORDER_WITH_GROUP_MEMBERS_UUID = "fe00bbbc-5e31-475d-95a1-2facb63bcdae";
+
private static final String WRONG_UUID = "38c53063-450a-47be-802c-e6270d2e6c69";
- private static final String TEST_ORDER_INITIAL_DATA = "org/openmrs/module/fhir2/api/dao/impl/FhirServiceRequestTest_initial_data.xml";
+ private static final String TEST_ORDER_INITIAL_DATA = "org/openmrs/module/fhir2/api/dao/impl/FhirServiceRequestDaoImplTest_initial_data.xml";
private FhirServiceRequestDaoImpl dao;
@@ -72,6 +84,11 @@ public void setup() throws Exception {
dao.setSessionFactory(sessionFactory);
}
+ @After
+ public void teardown() {
+ // TODO: unexecuteDataSet(TEST_ORDER_INITIAL_DATA);
+ }
+
@Test
public void shouldRetrieveTestOrderByUuid() {
TestOrder result = dao.get(TEST_ORDER_UUID);
@@ -97,262 +114,198 @@ public void shouldReturnNullIfUuidIsNotValidTestOrder() {
@Test
public void shouldApplyHasConstraintsForObservationsBasedOnAnyCorrectly() {
runHasObservationBasedOnTest(
- null,
- null,
- new String[]{ ORDER_WITH_OBSERVATION_CATEGORY_LABORATORY_UUID, ORDER_WITH_OBSERVATION_CATEGORY_PROCEDURE_UUID, ORDER_WITH_TEXT_VALUE_UUID },
- new String[]{WRONG_UUID}
- );
+ null, null, new String[] { ORDER_WITH_OBSERVATION_CATEGORY_LABORATORY_UUID,
+ ORDER_WITH_OBSERVATION_CATEGORY_PROCEDURE_UUID, ORDER_WITH_TEXT_VALUE_UUID },
+ new String[] { WRONG_UUID });
}
@Test
public void shouldApplyHasConstraintsForObservationsBasedOnAnyCategoryCorrectly() {
- runHasObservationBasedOnTest(
- "category",
- null,
- new String[]{ ORDER_WITH_OBSERVATION_CATEGORY_LABORATORY_UUID, ORDER_WITH_OBSERVATION_CATEGORY_PROCEDURE_UUID },
- new String[]{WRONG_UUID}
- );
+ runHasObservationBasedOnTest("category", null,
+ new String[] { ORDER_WITH_OBSERVATION_CATEGORY_LABORATORY_UUID, ORDER_WITH_OBSERVATION_CATEGORY_PROCEDURE_UUID },
+ new String[] { WRONG_UUID });
}
@Test
public void shouldApplyHasConstraintsForObservationsBasedOnLaboratoryCategoryCorrectly() {
- runHasObservationBasedOnTest(
- "category",
- "laboratory",
- new String[]{ ORDER_WITH_OBSERVATION_CATEGORY_LABORATORY_UUID },
- new String[]{WRONG_UUID, ORDER_WITH_OBSERVATION_CATEGORY_PROCEDURE_UUID}
- );
+ runHasObservationBasedOnTest("category", "laboratory",
+ new String[] { ORDER_WITH_OBSERVATION_CATEGORY_LABORATORY_UUID },
+ new String[] { WRONG_UUID, ORDER_WITH_OBSERVATION_CATEGORY_PROCEDURE_UUID });
}
@Test
public void shouldApplyHasConstraintsForObservationsBasedOnAnyDateCorrectly() {
- runHasObservationBasedOnTest(
- "date",
- null,
- new String[]{ ORDER_WITH_OBSERVATION_CATEGORY_LABORATORY_UUID },
- new String[]{WRONG_UUID}
- );
+ runHasObservationBasedOnTest("date", null, new String[] { ORDER_WITH_OBSERVATION_CATEGORY_LABORATORY_UUID },
+ new String[] { WRONG_UUID });
}
@Test
public void shouldApplyHasConstraintsForObservationsBasedOnSpecificDateCorrectly() {
- runHasObservationBasedOnTest(
- "date",
- "1998-07-01 00:00:00.0",
- new String[]{ ORDER_WITH_OBSERVATION_CATEGORY_LABORATORY_UUID },
- new String[]{WRONG_UUID}
- );
+ runHasObservationBasedOnTest("date", toFhirDateFormat("1998-07-01 00:00:00.0"),
+ new String[] { ORDER_WITH_OBSERVATION_CATEGORY_LABORATORY_UUID }, new String[] { WRONG_UUID });
}
-
@Test
public void shouldApplyHasConstraintsForObservationsBasedOnAnySubjectCorrectly() {
- runHasObservationBasedOnTest(
- "subject",
- null,
- new String[]{ ORDER_WITH_OBSERVATION_CATEGORY_LABORATORY_UUID },
- new String[]{WRONG_UUID}
- );
+ runHasObservationBasedOnTest("subject", null, new String[] { ORDER_WITH_OBSERVATION_CATEGORY_LABORATORY_UUID },
+ new String[] { WRONG_UUID });
}
@Test
public void shouldApplyHasConstraintsForObservationsBasedOnSpecificSubjectCorrectly() {
- runHasObservationBasedOnTest(
- "subject",
- // TODO: what would be a realistic value?
- "a65c347e-1384-493a-a55b-d325924acd94",
- new String[]{ ORDER_WITH_OBSERVATION_CATEGORY_LABORATORY_UUID },
- new String[]{WRONG_UUID}
- );
+ runHasObservationBasedOnTest("subject",
+ // TODO: what would be a realistic value?
+ "5946f880-b197-400b-9caa-a3c661d23041", new String[] { ORDER_WITH_OBSERVATION_CATEGORY_LABORATORY_UUID },
+ new String[] { WRONG_UUID });
+ }
+
+ @Test
+ public void shouldApplyHasConstraintsForObservationsBasedOnAnyPatientCorrectly() {
+ runHasObservationBasedOnTest("patient", null, new String[] { ORDER_WITH_OBSERVATION_CATEGORY_LABORATORY_UUID },
+ new String[] { WRONG_UUID });
+ }
+
+ @Test
+ public void shouldApplyHasConstraintsForObservationsBasedOnSpecificPatientCorrectly() {
+ runHasObservationBasedOnTest("patient",
+ // TODO: what would be a realistic value?
+ "5946f880-b197-400b-9caa-a3c661d23041", new String[] { ORDER_WITH_OBSERVATION_CATEGORY_LABORATORY_UUID },
+ new String[] { WRONG_UUID });
}
-
@Test
public void shouldApplyHasConstraintsForObservationsBasedOnAnyValueConceptCorrectly() {
- runHasObservationBasedOnTest(
- "value-concept",
- null,
- new String[]{ ORDER_WITH_CODED_VALUE_UUID },
- new String[]{WRONG_UUID, ORDER_WITH_DATETIME_VALUE_UUID}
- );
+ runHasObservationBasedOnTest("value-concept", null, new String[] { ORDER_WITH_CODED_VALUE_UUID },
+ new String[] { WRONG_UUID, ORDER_WITH_DATETIME_VALUE_UUID });
}
@Test
public void shouldApplyHasConstraintsForObservationsBasedOnSpecificValueConceptCorrectly() {
- runHasObservationBasedOnTest(
- "value-concept",
- "8d492026-c2cc-11de-8d13-0010c6dffd0f",
- new String[]{ ORDER_WITH_CODED_VALUE_UUID },
- new String[]{WRONG_UUID, ORDER_WITH_DATETIME_VALUE_UUID}
- );
+ runHasObservationBasedOnTest("value-concept", "8d492026-c2cc-11de-8d13-0010c6dffd0f",
+ new String[] { ORDER_WITH_CODED_VALUE_UUID }, new String[] { WRONG_UUID, ORDER_WITH_DATETIME_VALUE_UUID });
}
-
@Test
public void shouldApplyHasConstraintsForObservationsBasedOnAnyValueDateCorrectly() {
- runHasObservationBasedOnTest(
- "value-date",
- null,
- new String[]{ ORDER_WITH_DATETIME_VALUE_UUID },
- new String[]{WRONG_UUID, ORDER_WITH_CODED_VALUE_UUID}
- );
+ runHasObservationBasedOnTest("value-date", null, new String[] { ORDER_WITH_DATETIME_VALUE_UUID },
+ new String[] { WRONG_UUID, ORDER_WITH_CODED_VALUE_UUID });
}
@Test
public void shouldApplyHasConstraintsForObservationsBasedOnSpecificValueDateCorrectly() {
- runHasObservationBasedOnTest(
- "value-date",
- // TODO: what would be a realistic value?
- "1998-07-01 00:00:00",
- new String[]{ ORDER_WITH_DATETIME_VALUE_UUID },
- new String[]{WRONG_UUID, ORDER_WITH_CODED_VALUE_UUID}
- );
+ runHasObservationBasedOnTest("value-date", toFhirDateFormat("1998-07-01 00:00:00.0"),
+ new String[] { ORDER_WITH_DATETIME_VALUE_UUID }, new String[] { WRONG_UUID, ORDER_WITH_CODED_VALUE_UUID });
}
-
@Test
public void shouldApplyHasConstraintsForObservationsBasedOnAnyHasMemberCorrectly() {
- // TODO:
- runHasObservationBasedOnTest(
- "has-member",
- null,
- new String[]{ WRONG_UUID, ORDER_WITH_DATETIME_VALUE_UUID },
- new String[]{WRONG_UUID, ORDER_WITH_CODED_VALUE_UUID}
- );
+ runHasObservationBasedOnTest("has-member", null, new String[] { ORDER_WITH_GROUP_MEMBERS_UUID },
+ new String[] { WRONG_UUID, ORDER_WITH_CODED_VALUE_UUID });
}
@Test
public void shouldApplyHasConstraintsForObservationsBasedOnSpecificHasMemerCorrectly() {
- // TODO:
- runHasObservationBasedOnTest(
- "has-member",
- "TODO",
- new String[]{ WRONG_UUID, ORDER_WITH_DATETIME_VALUE_UUID },
- new String[]{WRONG_UUID, ORDER_WITH_CODED_VALUE_UUID}
- );
+ runHasObservationBasedOnTest("has-member", "a600eee3-ec06-4edb-b371-18876269ae72",
+ new String[] { ORDER_WITH_GROUP_MEMBERS_UUID }, new String[] { WRONG_UUID, ORDER_WITH_CODED_VALUE_UUID });
}
-
@Test
public void shouldApplyHasConstraintsForObservationsBasedOnAnyValueStringCorrectly() {
- runHasObservationBasedOnTest(
- "value-string",
- null,
- new String[]{ ORDER_WITH_TEXT_VALUE_UUID },
- new String[]{WRONG_UUID, ORDER_WITH_CODED_VALUE_UUID}
- );
+ runHasObservationBasedOnTest("value-string", null, new String[] { ORDER_WITH_TEXT_VALUE_UUID },
+ new String[] { WRONG_UUID, ORDER_WITH_CODED_VALUE_UUID });
}
@Test
public void shouldApplyHasConstraintsForObservationsBasedOnSpecificValueStringCorrectly() {
- runHasObservationBasedOnTest(
- "value-string",
- // TODO: what would be a realistic value here? Are spaces allowed?
- "value_text",
- new String[]{ ORDER_WITH_TEXT_VALUE_UUID },
- new String[]{WRONG_UUID, ORDER_WITH_CODED_VALUE_UUID}
- );
+ runHasObservationBasedOnTest("value-string",
+ // TODO: what would be a realistic value here? Are spaces allowed?
+ "value_text", new String[] { ORDER_WITH_TEXT_VALUE_UUID },
+ new String[] { WRONG_UUID, ORDER_WITH_CODED_VALUE_UUID });
}
-
@Test
public void shouldApplyHasConstraintsForObservationsBasedOnAnyIdentifierCorrectly() {
// this test should return ALL observations (it basically checks obs.uuid != null)
- runHasObservationBasedOnTest(
- "identifier",
- null,
- new String[]{ ORDER_WITH_TEXT_VALUE_UUID },
- new String[]{}
- );
+ runHasObservationBasedOnTest("identifier", null, new String[] { ORDER_WITH_TEXT_VALUE_UUID }, new String[] {});
}
@Test
public void shouldApplyHasConstraintsForObservationsBasedOnSpecificIdentifierCorrectly() {
- runHasObservationBasedOnTest(
- "identifier",
- ORDER_WITH_TEXT_VALUE_UUID,
- new String[]{ ORDER_WITH_TEXT_VALUE_UUID },
- new String[]{WRONG_UUID, ORDER_WITH_OBSERVATION_CATEGORY_LABORATORY_UUID }
- );
+ runHasObservationBasedOnTest("identifier", "9354bbf7-df39-4153-a07c-e2a27ee4a11f",
+ new String[] { ORDER_WITH_TEXT_VALUE_UUID },
+ new String[] { WRONG_UUID, ORDER_WITH_OBSERVATION_CATEGORY_LABORATORY_UUID });
}
-
@Test
public void shouldApplyHasConstraintsForObservationsBasedOnAnyEncounterCorrectly() {
// this test should return ALL observations (it basically checks obs.uuid != null)
- runHasObservationBasedOnTest(
- "encounter",
- null,
- new String[]{ ORDER_WITH_TEXT_VALUE_UUID, ORDER_WITH_OBSERVATION_CATEGORY_LABORATORY_UUID },
- new String[]{ WRONG_UUID}
- );
+ runHasObservationBasedOnTest("encounter", null,
+ new String[] { ORDER_WITH_TEXT_VALUE_UUID, ORDER_WITH_OBSERVATION_CATEGORY_LABORATORY_UUID },
+ new String[] { WRONG_UUID });
}
@Test
public void shouldApplyHasConstraintsForObservationsBasedOnSpecificEncounterCorrectly() {
- runHasObservationBasedOnTest(
- "encounter",
- "8a706f20-d133-403a-aa7e-95318a03cf12",
- new String[]{ ORDER_WITH_OBSERVATION_CATEGORY_LABORATORY_UUID },
- new String[]{WRONG_UUID, ORDER_WITH_TEXT_VALUE_UUID }
- );
+ runHasObservationBasedOnTest("encounter", "6cbdb2ef-ef1f-4def-8313-c71763434cd4",
+ new String[] { ORDER_WITH_PROVIDER_UUID }, new String[] { WRONG_UUID, ORDER_WITH_TEXT_VALUE_UUID });
}
-
@Test
public void shouldApplyHasConstraintsForObservationsBasedOnAnyStatusCorrectly() {
// this test should return ALL observations (it basically checks obs.uuid != null)
- runHasObservationBasedOnTest(
- "status",
- null,
- new String[]{ ORDER_WITH_TEXT_VALUE_UUID, ORDER_WITH_OBSERVATION_CATEGORY_LABORATORY_UUID },
- new String[]{ WRONG_UUID}
- );
+ runHasObservationBasedOnTest("status", null,
+ new String[] { ORDER_WITH_TEXT_VALUE_UUID, ORDER_WITH_OBSERVATION_CATEGORY_LABORATORY_UUID },
+ new String[] { WRONG_UUID });
}
@Test
public void shouldApplyHasConstraintsForObservationsBasedOnSpecificStatusCorrectly() {
- runHasObservationBasedOnTest(
- "status",
- "TODO", //TODO: Obs.Status.FINAL can not be loaded here and is the only value status can have,
- new String[]{ ORDER_WITH_OBSERVATION_CATEGORY_LABORATORY_UUID },
- new String[]{WRONG_UUID, ORDER_WITH_TEXT_VALUE_UUID }
- );
+ runHasObservationBasedOnTest("status", "AMENDED", new String[] { ORDER_WITH_STATUS_UUID },
+ new String[] { WRONG_UUID, ORDER_WITH_TEXT_VALUE_UUID });
+ }
+
+ @Test
+ public void shouldApplyHasConstraintsForObservationsBasedOnAnyValueQuantityCorrectly() {
+ // this test should return ALL observations (it basically checks obs.uuid != null)
+ runHasObservationBasedOnTest("value-quantity", null, new String[] { ORDER_WITH_NUMERIC_VALUE_UUID },
+ new String[] { WRONG_UUID });
+ }
+
+ @Test
+ public void shouldApplyHasConstraintsForObservationsBasedOnSpecificValueQuantityCorrectly() {
+ runHasObservationBasedOnTest("value-quantity", "12.345678", new String[] { ORDER_WITH_NUMERIC_VALUE_UUID },
+ new String[] { WRONG_UUID, ORDER_WITH_TEXT_VALUE_UUID });
+ }
+
+ @Test
+ public void shouldApplyHasConstraintsForObservationsBasedOnAnyPerformerCorrectly() {
+ // this test should return ALL observations (it basically checks obs.uuid != null)
+ runHasObservationBasedOnTest("performer", null, new String[] { ORDER_WITH_PROVIDER_UUID },
+ new String[] { WRONG_UUID });
+ }
+
+ @Test
+ public void shouldApplyHasConstraintsForObservationsBasedOnSpecificPerformerCorrectly() {
+ runHasObservationBasedOnTest("performer", "3c08ebc2-6d9d-46c6-bdc4-e8a1871d7a7d",
+ new String[] { ORDER_WITH_PROVIDER_UUID }, new String[] { WRONG_UUID, ORDER_WITH_TEXT_VALUE_UUID });
}
-
@Test
public void shouldReturnNoEntriesForUnsupportedSearchParameters() {
- String[] unsupportedSearchParameters = {
- "focus",
- "derived-from",
- "method",
- "data-absent-reason",
- "device",
- "component-data-absent-reason",
- "component-code-value-quantity",
- "component-value-quantity",
- "component-code-value-concept",
- "component-value-concept",
- "component-code",
- "combo-data-absent-reason",
- "combo-code",
- "combo-code-value-quantity",
- "combo-code-value-concept",
- "combo-value-quantity",
- "combo-value-concept",
- };
+ String[] unsupportedSearchParameters = { "focus", "derived-from", "method", "data-absent-reason", "device",
+ "component-data-absent-reason", "component-code-value-quantity", "component-value-quantity",
+ "component-code-value-concept", "component-value-concept", "component-code", "combo-data-absent-reason",
+ "combo-code", "combo-code-value-quantity", "combo-code-value-concept", "combo-value-quantity",
+ "combo-value-concept", };
+
for (String unsupportedSearchParameter : unsupportedSearchParameters) {
- runHasObservationBasedOnTest(
- unsupportedSearchParameter,
- null,
- new String[]{ },
- new String[]{WRONG_UUID, ORDER_WITH_TEXT_VALUE_UUID }
- );
- }
+ runHasObservationBasedOnTest(unsupportedSearchParameter, null, new String[] {},
+ new String[] { WRONG_UUID, ORDER_WITH_TEXT_VALUE_UUID });
+ }
}
-
- private void runHasObservationBasedOnTest(String searchParameter, String value, String[] expectedUuids, String[] unexpectedUuids){
+
+ private void runHasObservationBasedOnTest(String searchParameter, String value, String[] expectedUuids,
+ String[] unexpectedUuids) {
HasOrListParam hasOrListParam = new HasOrListParam();
hasOrListParam.add(new HasParam("Observation", "based-on", searchParameter, value));
HasAndListParam hasAndListParam = new HasAndListParam();
@@ -363,22 +316,19 @@ private void runHasObservationBasedOnTest(String searchParameter, String value,
List results = dao.getSearchResults(theParams);
assertThat(results, notNullValue());
-
- if(expectedUuids.length > 0){
+
+ if (expectedUuids.length > 0) {
assertThat("No service requests returned", results.size() > 0);
}
for (String expectedUuid : expectedUuids) {
- assertThat("Result did not contain expected entry",
- containsUuid(results, expectedUuid));
+ assertThat("Result did not contain expected entry", containsUuid(results, expectedUuid));
}
-
+
for (String unexpectedUuid : unexpectedUuids) {
- assertThat("Result did contain unexpected entry",
- !containsUuid(results, unexpectedUuid));
+ assertThat("Result did contain unexpected entry", !containsUuid(results, unexpectedUuid));
}
}
-
private boolean containsUuid(Collection collection, String uuid) {
Predicate predicate = new Predicate() {
@@ -390,4 +340,18 @@ public boolean evaluate(Object sample) {
return CollectionUtils.exists(collection, predicate);
}
+ private String toFhirDateFormat(String dateString) {
+
+ try {
+ Date dateValue = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss.S").parse(dateString);
+
+ // TODO: what is the correct DateFormat for FHIR?
+ return DateFormat.getDateTimeInstance().format(dateValue);
+ }
+ catch (Exception e) {
+ assertEquals("Exception during test setup - check format of input value", dateString,
+ dateString + " should match yyyy-MM-dd hh:mm:ss.S");
+ return null;
+ }
+ }
}
diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/impl/FhirServiceRequestServiceImplTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/impl/FhirServiceRequestServiceImplTest.java
index 3399be8f34..b4da34184d 100644
--- a/api/src/test/java/org/openmrs/module/fhir2/api/impl/FhirServiceRequestServiceImplTest.java
+++ b/api/src/test/java/org/openmrs/module/fhir2/api/impl/FhirServiceRequestServiceImplTest.java
@@ -402,10 +402,11 @@ public void searchForServiceRequest_shouldAddNotNullConstraintForHasParamsWithNo
SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.HAS_SEARCH_HANDLER,
hasAndListParam);
+ SearchQueryBundleProvider searchQueryBundleProvider = new SearchQueryBundleProvider<>(
+ theParams, dao, translator, globalPropertyService, searchQueryInclude);
when(dao.getSearchResults(any())).thenReturn(Collections.singletonList(order));
when(translator.toFhirResource(order)).thenReturn(fhirServiceRequest);
- when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn(
- new SearchQueryBundleProvider<>(theParams, dao, translator, globalPropertyService, searchQueryInclude));
+ when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn(searchQueryBundleProvider);
when(searchQueryInclude.getIncludedResources(any(), any())).thenReturn(Collections.singleton(new Observation()));
IBundleProvider results = serviceRequestService.searchForServiceRequests(serviceRequestSearchParams);
diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/search/ServiceRequestSearchQueryTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/search/ServiceRequestSearchQueryTest.java
index a698f819f8..5dbb24b4d1 100644
--- a/api/src/test/java/org/openmrs/module/fhir2/api/search/ServiceRequestSearchQueryTest.java
+++ b/api/src/test/java/org/openmrs/module/fhir2/api/search/ServiceRequestSearchQueryTest.java
@@ -123,7 +123,7 @@ public class ServiceRequestSearchQueryTest extends BaseModuleContextSensitiveTes
private static final int END_INDEX = 10;
- private static final int SERVICE_REQUEST_COUNT = 9;
+ private static final int SERVICE_REQUEST_COUNT = 4;
@Autowired
private FhirServiceRequestDao dao;
diff --git a/test-data/src/main/resources/org/openmrs/module/fhir2/api/dao/impl/FhirServiceRequestDaoImplTest_initial_data.xml b/test-data/src/main/resources/org/openmrs/module/fhir2/api/dao/impl/FhirServiceRequestDaoImplTest_initial_data.xml
new file mode 100644
index 0000000000..2db992b83b
--- /dev/null
+++ b/test-data/src/main/resources/org/openmrs/module/fhir2/api/dao/impl/FhirServiceRequestDaoImplTest_initial_data.xml
@@ -0,0 +1,94 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/test-data/src/main/resources/org/openmrs/module/fhir2/api/dao/impl/FhirServiceRequestTest_initial_data.xml b/test-data/src/main/resources/org/openmrs/module/fhir2/api/dao/impl/FhirServiceRequestTest_initial_data.xml
index bca4bf83b2..42e457e35f 100644
--- a/test-data/src/main/resources/org/openmrs/module/fhir2/api/dao/impl/FhirServiceRequestTest_initial_data.xml
+++ b/test-data/src/main/resources/org/openmrs/module/fhir2/api/dao/impl/FhirServiceRequestTest_initial_data.xml
@@ -28,46 +28,5 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
From 5807d1e7f8dd9d7a3df6039138df577d1b9532df Mon Sep 17 00:00:00 2001
From: md-at-slashwhy <95024503+md-at-slashwhy@users.noreply.github.com>
Date: Wed, 22 Nov 2023 15:18:14 +0100
Subject: [PATCH 7/9] FM2-347: remove resolved TODOs
---
.../fhir2/api/dao/impl/FhirServiceRequestDaoImplTest.java | 7 -------
1 file changed, 7 deletions(-)
diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirServiceRequestDaoImplTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirServiceRequestDaoImplTest.java
index c9ee9de8c2..25602d5f59 100644
--- a/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirServiceRequestDaoImplTest.java
+++ b/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirServiceRequestDaoImplTest.java
@@ -84,11 +84,6 @@ public void setup() throws Exception {
dao.setSessionFactory(sessionFactory);
}
- @After
- public void teardown() {
- // TODO: unexecuteDataSet(TEST_ORDER_INITIAL_DATA);
- }
-
@Test
public void shouldRetrieveTestOrderByUuid() {
TestOrder result = dao.get(TEST_ORDER_UUID);
@@ -154,7 +149,6 @@ public void shouldApplyHasConstraintsForObservationsBasedOnAnySubjectCorrectly()
@Test
public void shouldApplyHasConstraintsForObservationsBasedOnSpecificSubjectCorrectly() {
runHasObservationBasedOnTest("subject",
- // TODO: what would be a realistic value?
"5946f880-b197-400b-9caa-a3c661d23041", new String[] { ORDER_WITH_OBSERVATION_CATEGORY_LABORATORY_UUID },
new String[] { WRONG_UUID });
}
@@ -168,7 +162,6 @@ public void shouldApplyHasConstraintsForObservationsBasedOnAnyPatientCorrectly()
@Test
public void shouldApplyHasConstraintsForObservationsBasedOnSpecificPatientCorrectly() {
runHasObservationBasedOnTest("patient",
- // TODO: what would be a realistic value?
"5946f880-b197-400b-9caa-a3c661d23041", new String[] { ORDER_WITH_OBSERVATION_CATEGORY_LABORATORY_UUID },
new String[] { WRONG_UUID });
}
From bc81e6bb971b29688c002341a6461fb1de7388ee Mon Sep 17 00:00:00 2001
From: md-at-slashwhy <95024503+md-at-slashwhy@users.noreply.github.com>
Date: Mon, 15 Jan 2024 11:58:01 +0100
Subject: [PATCH 8/9] update ServiceRequestSearchParams to use
BaseResourceSearchParams
---
.../dao/impl/FhirServiceRequestDaoImpl.java | 34 ++++++++++++----
.../impl/FhirServiceRequestServiceImpl.java | 2 +-
.../param/ServiceRequestSearchParams.java | 40 ++++++++++++++-----
.../ProcedureRequestFhirResourceProvider.java | 2 +-
.../ServiceRequestFhirResourceProvider.java | 2 +-
.../impl/FhirServiceRequestDaoImplTest.java | 11 ++---
.../FhirServiceRequestServiceImplTest.java | 2 +-
...ureRequestFhirResourceProviderWebTest.java | 2 +-
...iceRequestFhirResourceProviderWebTest.java | 2 +-
9 files changed, 66 insertions(+), 31 deletions(-)
diff --git a/api/src/main/java/org/openmrs/module/fhir2/api/dao/impl/FhirServiceRequestDaoImpl.java b/api/src/main/java/org/openmrs/module/fhir2/api/dao/impl/FhirServiceRequestDaoImpl.java
index 8611137a93..87458ce049 100644
--- a/api/src/main/java/org/openmrs/module/fhir2/api/dao/impl/FhirServiceRequestDaoImpl.java
+++ b/api/src/main/java/org/openmrs/module/fhir2/api/dao/impl/FhirServiceRequestDaoImpl.java
@@ -166,6 +166,33 @@ private void handleHasObservation(Criteria criteria, HasParam hasParam, Set
+ * The available FHIR parameters will be converted where applicable, however some parameters can not
+ * be represented:
+ *
+ * Observation.SP_SPECIMEN
: a close match would be accessionIdentifier but wouldn't
+ * represent the entire specimen
+ * Observation.SP_FOCUS
, Observation.SP_DERIVED_FROM
,
+ * Observation.SP_METHOD
, Observation.SP_DATA_ABSENT_REASON
,
+ * Observation.SP_DEVICE
: no meaningful mapping in OpenMRS
+ * - SP_COMPONENT_* (like
Observation.SP_COMPONENT_CODE
) and SP_COMBO_* (like
+ * Observation.SP_COMBO_VALUE_QUANTITY
): OpenMRS does not support Components yet
+ * Observation.SP_CODE_VALUE_STRING
, Observation.SP_PART_OF
,
+ * Observation.SP_CODE_VALUE_DATE
, Observation.SP_CODE_VALUE_QUANTITY
,
+ * Observation.SP_CODE_VALUE_CONCEPT
: no meaningful mappings could be found during
+ * development. This may or may not change in the future.
+ *
+ * Unrepresentable parameters will return a detached criteria containing no matches.
+ *
+ *
+ * @param projection the string determining the projection of the detached criteria
+ * @param parameterName the string representing the parameter to be searched for
+ * @param parameterValue the string containing a representation of the value to be compared with
+ * @return the detached criteria representing the observation criteria
+ */
// the detached criteria in this file should all return a subquery of ids to make usage of them consistent
private DetachedCriteria createObservationCriteria(String projection, String parameterName, String parameterValue) {
DetachedCriteria observationQuery = DetachedCriteria.forClass(Obs.class);
@@ -261,24 +288,17 @@ private DetachedCriteria createObservationCriteria(String projection, String par
observationQuery.add(propertyIn("encounter", encounterProviderQuery));
break;
- // TODO: add explanation on why these values are not implemented
case Observation.SP_CODE_VALUE_STRING:
case Observation.SP_PART_OF:
case Observation.SP_CODE_VALUE_DATE:
case Observation.SP_CODE_VALUE_QUANTITY:
case Observation.SP_CODE_VALUE_CONCEPT:
-
- // only meaningful mapping would be the accessionIdentifier, not a whole specimen
case Observation.SP_SPECIMEN:
-
- // no meaningful mapping in OpenMRS
case Observation.SP_FOCUS:
case Observation.SP_DERIVED_FROM:
case Observation.SP_METHOD:
case Observation.SP_DATA_ABSENT_REASON:
case Observation.SP_DEVICE:
-
- // OpenMRS does not support Components yet, this includes the SP_COMPONENT_* space and SP_COMBO_* space
case Observation.SP_COMPONENT_DATA_ABSENT_REASON:
case Observation.SP_COMPONENT_CODE_VALUE_QUANTITY:
case Observation.SP_COMPONENT_VALUE_QUANTITY:
diff --git a/api/src/main/java/org/openmrs/module/fhir2/api/impl/FhirServiceRequestServiceImpl.java b/api/src/main/java/org/openmrs/module/fhir2/api/impl/FhirServiceRequestServiceImpl.java
index 824f26bbc7..69b9ad0999 100644
--- a/api/src/main/java/org/openmrs/module/fhir2/api/impl/FhirServiceRequestServiceImpl.java
+++ b/api/src/main/java/org/openmrs/module/fhir2/api/impl/FhirServiceRequestServiceImpl.java
@@ -57,7 +57,7 @@ public IBundleProvider searchForServiceRequests(ServiceRequestSearchParams servi
serviceRequestSearchParams.getParticipantReference())
.addParameter(FhirConstants.DATE_RANGE_SEARCH_HANDLER, serviceRequestSearchParams.getOccurrence())
.addParameter(FhirConstants.COMMON_SEARCH_HANDLER, FhirConstants.ID_PROPERTY,
- serviceRequestSearchParams.getUuid())
+ serviceRequestSearchParams.getId())
.addParameter(FhirConstants.COMMON_SEARCH_HANDLER, FhirConstants.LAST_UPDATED_PROPERTY,
serviceRequestSearchParams.getLastUpdated())
.addParameter(FhirConstants.INCLUDE_SEARCH_HANDLER, serviceRequestSearchParams.getIncludes())
diff --git a/api/src/main/java/org/openmrs/module/fhir2/api/search/param/ServiceRequestSearchParams.java b/api/src/main/java/org/openmrs/module/fhir2/api/search/param/ServiceRequestSearchParams.java
index e103500253..8b59c04274 100644
--- a/api/src/main/java/org/openmrs/module/fhir2/api/search/param/ServiceRequestSearchParams.java
+++ b/api/src/main/java/org/openmrs/module/fhir2/api/search/param/ServiceRequestSearchParams.java
@@ -10,26 +10,24 @@
package org.openmrs.module.fhir2.api.search.param;
-import java.io.Serializable;
import java.util.HashSet;
import ca.uhn.fhir.model.api.Include;
+import ca.uhn.fhir.rest.api.SortSpec;
import ca.uhn.fhir.rest.param.DateRangeParam;
import ca.uhn.fhir.rest.param.HasAndListParam;
import ca.uhn.fhir.rest.param.ReferenceAndListParam;
import ca.uhn.fhir.rest.param.TokenAndListParam;
-import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
+import org.openmrs.module.fhir2.FhirConstants;
@Data
@NoArgsConstructor
-@AllArgsConstructor
-@Builder
-@EqualsAndHashCode
-public class ServiceRequestSearchParams implements Serializable {
+@EqualsAndHashCode(callSuper = true)
+public class ServiceRequestSearchParams extends BaseResourceSearchParams {
private ReferenceAndListParam patientReference;
@@ -41,11 +39,31 @@ public class ServiceRequestSearchParams implements Serializable {
private DateRangeParam occurrence;
- private TokenAndListParam uuid;
-
- private DateRangeParam lastUpdated;
+ private HasAndListParam hasAndListParam;
- private HashSet includes;
+ @Builder
+ public ServiceRequestSearchParams(ReferenceAndListParam patientReference, TokenAndListParam code,
+ ReferenceAndListParam encounterReference, ReferenceAndListParam participantReference, DateRangeParam occurrence,
+ HasAndListParam hasAndListParam, TokenAndListParam id, DateRangeParam lastUpdated, SortSpec sort,
+ HashSet includes) {
+
+ super(id, lastUpdated, sort, includes, null);
+
+ this.patientReference = patientReference;
+ this.code = code;
+ this.encounterReference = encounterReference;
+ this.participantReference = participantReference;
+ this.occurrence = occurrence;
+ this.hasAndListParam = hasAndListParam;
+ }
- private HasAndListParam hasAndListParam;
+ @Override
+ public SearchParameterMap toSearchParameterMap() {
+ return baseSearchParameterMap().addParameter(FhirConstants.PATIENT_REFERENCE_SEARCH_HANDLER, getPatientReference())
+ .addParameter(FhirConstants.CODED_SEARCH_HANDLER, getCode())
+ .addParameter(FhirConstants.ENCOUNTER_REFERENCE_SEARCH_HANDLER, getEncounterReference())
+ .addParameter(FhirConstants.PARTICIPANT_REFERENCE_SEARCH_HANDLER, getParticipantReference())
+ .addParameter(FhirConstants.DATE_RANGE_SEARCH_HANDLER, FhirConstants.STATE_PROPERTY, getOccurrence())
+ .addParameter(FhirConstants.HAS_SEARCH_HANDLER, FhirConstants.POSTAL_CODE_PROPERTY, getHasAndListParam());
+ }
}
diff --git a/api/src/main/java/org/openmrs/module/fhir2/providers/r3/ProcedureRequestFhirResourceProvider.java b/api/src/main/java/org/openmrs/module/fhir2/providers/r3/ProcedureRequestFhirResourceProvider.java
index f90f261ea1..b8246cceec 100644
--- a/api/src/main/java/org/openmrs/module/fhir2/providers/r3/ProcedureRequestFhirResourceProvider.java
+++ b/api/src/main/java/org/openmrs/module/fhir2/providers/r3/ProcedureRequestFhirResourceProvider.java
@@ -126,6 +126,6 @@ public IBundleProvider searchForProcedureRequests(
return new SearchQueryBundleProviderR3Wrapper(serviceRequestService
.searchForServiceRequests(new ServiceRequestSearchParams(patientReference, code, encounterReference,
- participantReference, occurrence, uuid, lastUpdated, includes, hasAndListParam)));
+ participantReference, occurrence, hasAndListParam, uuid, lastUpdated, null, includes)));
}
}
diff --git a/api/src/main/java/org/openmrs/module/fhir2/providers/r4/ServiceRequestFhirResourceProvider.java b/api/src/main/java/org/openmrs/module/fhir2/providers/r4/ServiceRequestFhirResourceProvider.java
index 9146c796d7..76601f3a6c 100644
--- a/api/src/main/java/org/openmrs/module/fhir2/providers/r4/ServiceRequestFhirResourceProvider.java
+++ b/api/src/main/java/org/openmrs/module/fhir2/providers/r4/ServiceRequestFhirResourceProvider.java
@@ -124,6 +124,6 @@ public IBundleProvider searchForServiceRequests(
}
return serviceRequestService.searchForServiceRequests(new ServiceRequestSearchParams(patientReference, code,
- encounterReference, participantReference, occurrence, uuid, lastUpdated, includes, hasAndListParam));
+ encounterReference, participantReference, occurrence, hasAndListParam, uuid, lastUpdated, null, includes));
}
}
diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirServiceRequestDaoImplTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirServiceRequestDaoImplTest.java
index 25602d5f59..a21209b8de 100644
--- a/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirServiceRequestDaoImplTest.java
+++ b/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirServiceRequestDaoImplTest.java
@@ -28,7 +28,6 @@
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.Predicate;
import org.hibernate.SessionFactory;
-import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openmrs.OrderType;
@@ -148,9 +147,8 @@ public void shouldApplyHasConstraintsForObservationsBasedOnAnySubjectCorrectly()
@Test
public void shouldApplyHasConstraintsForObservationsBasedOnSpecificSubjectCorrectly() {
- runHasObservationBasedOnTest("subject",
- "5946f880-b197-400b-9caa-a3c661d23041", new String[] { ORDER_WITH_OBSERVATION_CATEGORY_LABORATORY_UUID },
- new String[] { WRONG_UUID });
+ runHasObservationBasedOnTest("subject", "5946f880-b197-400b-9caa-a3c661d23041",
+ new String[] { ORDER_WITH_OBSERVATION_CATEGORY_LABORATORY_UUID }, new String[] { WRONG_UUID });
}
@Test
@@ -161,9 +159,8 @@ public void shouldApplyHasConstraintsForObservationsBasedOnAnyPatientCorrectly()
@Test
public void shouldApplyHasConstraintsForObservationsBasedOnSpecificPatientCorrectly() {
- runHasObservationBasedOnTest("patient",
- "5946f880-b197-400b-9caa-a3c661d23041", new String[] { ORDER_WITH_OBSERVATION_CATEGORY_LABORATORY_UUID },
- new String[] { WRONG_UUID });
+ runHasObservationBasedOnTest("patient", "5946f880-b197-400b-9caa-a3c661d23041",
+ new String[] { ORDER_WITH_OBSERVATION_CATEGORY_LABORATORY_UUID }, new String[] { WRONG_UUID });
}
@Test
diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/impl/FhirServiceRequestServiceImplTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/impl/FhirServiceRequestServiceImplTest.java
index b4da34184d..553369cf48 100644
--- a/api/src/test/java/org/openmrs/module/fhir2/api/impl/FhirServiceRequestServiceImplTest.java
+++ b/api/src/test/java/org/openmrs/module/fhir2/api/impl/FhirServiceRequestServiceImplTest.java
@@ -274,7 +274,7 @@ public void searchForServiceRequest_shouldReturnCollectionOfServiceRequestByOccu
public void searchForServiceRequest_shouldReturnCollectionOfServiceRequestByUUID() {
TokenAndListParam uuid = new TokenAndListParam().addAnd(new TokenParam(SERVICE_REQUEST_UUID));
ServiceRequestSearchParams serviceRequestSearchParams = new ServiceRequestSearchParams();
- serviceRequestSearchParams.setUuid(uuid);
+ serviceRequestSearchParams.setId(uuid);
SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.COMMON_SEARCH_HANDLER,
FhirConstants.ID_PROPERTY, uuid);
diff --git a/omod/src/test/java/org/openmrs/module/fhir2/providers/r3/ProcedureRequestFhirResourceProviderWebTest.java b/omod/src/test/java/org/openmrs/module/fhir2/providers/r3/ProcedureRequestFhirResourceProviderWebTest.java
index 96d97ec289..1f5100fb65 100644
--- a/omod/src/test/java/org/openmrs/module/fhir2/providers/r3/ProcedureRequestFhirResourceProviderWebTest.java
+++ b/omod/src/test/java/org/openmrs/module/fhir2/providers/r3/ProcedureRequestFhirResourceProviderWebTest.java
@@ -457,7 +457,7 @@ public void searchForProcedureRequests_shouldSearchForProcedureRequestsByUUID()
verify(service).searchForServiceRequests(serviceRequestSearchParamsArgumentCaptor.capture());
- TokenAndListParam tokenAndListParam = serviceRequestSearchParamsArgumentCaptor.getValue().getUuid();
+ TokenAndListParam tokenAndListParam = serviceRequestSearchParamsArgumentCaptor.getValue().getId();
assertThat(tokenAndListParam, notNullValue());
assertThat(tokenAndListParam.getValuesAsQueryTokens(), not(empty()));
assertThat(tokenAndListParam.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getValue(),
diff --git a/omod/src/test/java/org/openmrs/module/fhir2/providers/r4/ServiceRequestFhirResourceProviderWebTest.java b/omod/src/test/java/org/openmrs/module/fhir2/providers/r4/ServiceRequestFhirResourceProviderWebTest.java
index 59f9a1047f..4534ab8c8d 100644
--- a/omod/src/test/java/org/openmrs/module/fhir2/providers/r4/ServiceRequestFhirResourceProviderWebTest.java
+++ b/omod/src/test/java/org/openmrs/module/fhir2/providers/r4/ServiceRequestFhirResourceProviderWebTest.java
@@ -458,7 +458,7 @@ public void searchForServiceRequests_shouldSearchForServiceRequestsByUUID() thro
verify(service).searchForServiceRequests(serviceRequestSearchParamsArgumentCaptor.capture());
- TokenAndListParam tokenAndListParam = serviceRequestSearchParamsArgumentCaptor.getValue().getUuid();
+ TokenAndListParam tokenAndListParam = serviceRequestSearchParamsArgumentCaptor.getValue().getId();
assertThat(tokenAndListParam, notNullValue());
assertThat(tokenAndListParam.getValuesAsQueryTokens(), not(empty()));
assertThat(tokenAndListParam.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getValue(),
From 9e793c068cb5606eb191d19d27ae62bfeb7aef5e Mon Sep 17 00:00:00 2001
From: md-at-slashwhy <95024503+md-at-slashwhy@users.noreply.github.com>
Date: Mon, 22 Jan 2024 16:19:54 +0100
Subject: [PATCH 9/9] add more tests for failure cases
---
.../impl/FhirServiceRequestDaoImplTest.java | 38 +++++++++++++++++++
1 file changed, 38 insertions(+)
diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirServiceRequestDaoImplTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirServiceRequestDaoImplTest.java
index a21209b8de..349ea56d57 100644
--- a/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirServiceRequestDaoImplTest.java
+++ b/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirServiceRequestDaoImplTest.java
@@ -127,6 +127,12 @@ public void shouldApplyHasConstraintsForObservationsBasedOnLaboratoryCategoryCor
new String[] { WRONG_UUID, ORDER_WITH_OBSERVATION_CATEGORY_PROCEDURE_UUID });
}
+ @Test
+ public void shouldApplyHasConstraintsForObservationsBasedOnUnknownCategoryCorrectly() {
+ runHasObservationBasedOnTest("category", "__UnknownCategory", new String[] {}, new String[] { WRONG_UUID,
+ ORDER_WITH_OBSERVATION_CATEGORY_PROCEDURE_UUID, ORDER_WITH_OBSERVATION_CATEGORY_LABORATORY_UUID });
+ }
+
@Test
public void shouldApplyHasConstraintsForObservationsBasedOnAnyDateCorrectly() {
runHasObservationBasedOnTest("date", null, new String[] { ORDER_WITH_OBSERVATION_CATEGORY_LABORATORY_UUID },
@@ -280,6 +286,38 @@ public void shouldApplyHasConstraintsForObservationsBasedOnSpecificPerformerCorr
new String[] { ORDER_WITH_PROVIDER_UUID }, new String[] { WRONG_UUID, ORDER_WITH_TEXT_VALUE_UUID });
}
+ @Test
+ public void shouldReturnNoResultsForInvalidSearchParameter() {
+ runHasObservationBasedOnTest("__NotPerformer", "3c08ebc2-6d9d-46c6-bdc4-e8a1871d7a7d", new String[] {},
+ new String[] { WRONG_UUID, ORDER_WITH_TEXT_VALUE_UUID, ORDER_WITH_PROVIDER_UUID });
+ }
+
+ @Test
+ public void shouldReturnNoResultsForMalformattedNumeric() {
+ runHasObservationBasedOnTest("value-quantity", "twelve", new String[] {},
+ new String[] { WRONG_UUID, ORDER_WITH_TEXT_VALUE_UUID, ORDER_WITH_NUMERIC_VALUE_UUID });
+ }
+
+ @Test
+ public void shouldReturnNoResultsForMalformattedDate() {
+ runHasObservationBasedOnTest("value-date", "yesterday", new String[] {},
+ new String[] { WRONG_UUID, ORDER_WITH_TEXT_VALUE_UUID, ORDER_WITH_NUMERIC_VALUE_UUID });
+ }
+
+ @Test
+ public void shouldReturnNoResultsForUnknownReferencesForHasSearch() {
+ HasOrListParam hasOrListParam = new HasOrListParam();
+ hasOrListParam.add(new HasParam("Observation", "__notBased-on", "status", null));
+ HasAndListParam hasAndListParam = new HasAndListParam();
+ hasAndListParam.addAnd(hasOrListParam);
+ SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.HAS_SEARCH_HANDLER,
+ hasAndListParam);
+
+ List results = dao.getSearchResults(theParams);
+
+ assertThat(results, notNullValue());
+ }
+
@Test
public void shouldReturnNoEntriesForUnsupportedSearchParameters() {
String[] unsupportedSearchParameters = { "focus", "derived-from", "method", "data-absent-reason", "device",