From 02ffea878464b32775157f0119aa523cb0b63b05 Mon Sep 17 00:00:00 2001 From: cliff Date: Thu, 20 May 2021 10:51:50 +0300 Subject: [PATCH] fm2-347:new changes --- .../openmrs/module/fhir2/FhirConstants.java | 2 + .../api/dao/impl/FhirObservationDaoImpl.java | 33 +-- .../dao/impl/FhirServiceRequestDaoImpl.java | 84 +++++--- .../impl/FhirServiceRequestServiceImpl.java | 3 +- .../ServiceRequestFhirResourceProvider.java | 3 +- .../FhirServiceRequestServiceImplTest.java | 26 --- .../search/ObservationSearchQueryTest.java | 50 +++-- .../search/ServiceRequestSearchQueryTest.java | 102 ++++----- ...onFhirResourceProviderIntegrationTest.java | 53 ++++- ...stFhirResourceProviderIntegrationTest.java | 201 +++++++++++++++++- ...ervationDaoImplTest_initial_data_suppl.xml | 1 + .../FhirServiceRequestTest_initial_data.xml | 13 ++ 12 files changed, 414 insertions(+), 157 deletions(-) diff --git a/api/src/main/java/org/openmrs/module/fhir2/FhirConstants.java b/api/src/main/java/org/openmrs/module/fhir2/FhirConstants.java index fedcf8cf3a..06841255c6 100644 --- a/api/src/main/java/org/openmrs/module/fhir2/FhirConstants.java +++ b/api/src/main/java/org/openmrs/module/fhir2/FhirConstants.java @@ -296,4 +296,6 @@ public class FhirConstants { public static final String REVERSE_INCLUDE_SEARCH_HANDLER = "_revinclude.search.handler"; public static final String CONDITION_OBSERVATION_CONCEPT_UUID = "1284AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"; + + public static final Object PARAMQUALIFIER_STRING_NOT = ":not"; } diff --git a/api/src/main/java/org/openmrs/module/fhir2/api/dao/impl/FhirObservationDaoImpl.java b/api/src/main/java/org/openmrs/module/fhir2/api/dao/impl/FhirObservationDaoImpl.java index 80c8be778e..11d3c1b445 100644 --- a/api/src/main/java/org/openmrs/module/fhir2/api/dao/impl/FhirObservationDaoImpl.java +++ b/api/src/main/java/org/openmrs/module/fhir2/api/dao/impl/FhirObservationDaoImpl.java @@ -9,19 +9,15 @@ */ package org.openmrs.module.fhir2.api.dao.impl; -import static org.hibernate.criterion.Restrictions.and; import static org.hibernate.criterion.Restrictions.eq; import javax.annotation.Nonnull; -import java.util.ArrayList; -import java.util.List; import java.util.Optional; import ca.uhn.fhir.rest.param.DateRangeParam; import ca.uhn.fhir.rest.param.QuantityAndListParam; import ca.uhn.fhir.rest.param.ReferenceAndListParam; -import ca.uhn.fhir.rest.param.ReferenceParam; import ca.uhn.fhir.rest.param.StringAndListParam; import ca.uhn.fhir.rest.param.TokenAndListParam; import ca.uhn.fhir.rest.param.TokenParam; @@ -64,8 +60,8 @@ protected void setupSearchParams(Criteria criteria, SearchParameterMap theParams .forEach(category -> handleConceptClass(criteria, (TokenAndListParam) category.getParam())); break; case FhirConstants.BASED_ON_REFERENCE_SEARCH_HANDLER: - entry.getValue().forEach(param -> handleReference(criteria, (ReferenceAndListParam) param.getParam(), - "basedOnReferences", "bo")); + entry.getValue().forEach(param -> handleReference("ord", (ReferenceAndListParam) param.getParam()) + .ifPresent(c -> criteria.createAlias("order", "ord").add(c))); break; case FhirConstants.VALUE_CODED_SEARCH_HANDLER: entry.getValue().forEach( @@ -169,25 +165,12 @@ private void handleValueCodedConcept(Criteria criteria, TokenAndListParam valueC } } - private Boolean validReferenceParam(ReferenceParam ref) { - return (ref != null && ref.getIdPart() != null && ref.getResourceType() != null); - } - - private void handleReference(Criteria criteria, ReferenceAndListParam reference, String property, String alias) { - handleAndListParam(reference, param -> { - if (validReferenceParam(param)) { - if (lacksAlias(criteria, alias)) { - criteria.createAlias(property, alias); - } - - List> criterionList = new ArrayList<>(); - criterionList.add(Optional.of(eq(String.format("%s.reference", alias), param.getIdPart()))); - criterionList.add(Optional.of(eq(String.format("%s.type", alias), param.getResourceType()))); - return Optional.of(and(toCriteriaArray(criterionList))); - } - + private Optional handleReference(@Nonnull String orderAlias, ReferenceAndListParam orderReference) { + if (orderReference == null) { return Optional.empty(); - }).ifPresent(criteria::add); + } + return handleAndListParam(orderReference, + param -> Optional.of(eq(String.format("%s.uuid", orderAlias), param.getIdPart()))); } @Override @@ -204,5 +187,5 @@ protected Obs deproxyResult(Obs result) { Obs obs = super.deproxyResult(result); obs.setConcept(deproxyObject(obs.getConcept())); return obs; - } + } } 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 1a833b488d..1214010ecf 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,7 +11,6 @@ import static org.hibernate.criterion.Restrictions.and; import static org.hibernate.criterion.Restrictions.or; -import static org.hibernate.criterion.Restrictions.eq; import java.util.Optional; import java.util.stream.Stream; @@ -23,12 +22,14 @@ import ca.uhn.fhir.rest.param.HasParam; import ca.uhn.fhir.rest.param.ReferenceAndListParam; import ca.uhn.fhir.rest.param.TokenAndListParam; -import org.hibernate.criterion.Subqueries; import lombok.AccessLevel; import lombok.Setter; 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.hibernate.criterion.Subqueries; import org.openmrs.Obs; import org.openmrs.TestOrder; import org.openmrs.module.fhir2.FhirConstants; @@ -66,8 +67,8 @@ protected void setupSearchParams(Criteria criteria, SearchParameterMap theParams (ReferenceAndListParam) participantReference.getParam())); break; case FhirConstants.HAS_PROPERTY: - entry.getValue().forEach(hasParameter -> handleHasAndParam(criteria, - (HasAndListParam) hasParameter.getParam())); + entry.getValue() + .forEach(hasParameter -> handleHasAndParam(criteria, (HasAndListParam) hasParameter.getParam())); break; case FhirConstants.DATE_RANGE_SEARCH_HANDLER: entry.getValue().forEach(dateRangeParam -> handleDateRange((DateRangeParam) dateRangeParam.getParam()) @@ -101,54 +102,71 @@ private Optional handleDateRange(DateRangeParam dateRangeParam) { Optional.of(or(toCriteriaArray(Stream.of(handleDate("dateStopped", dateRangeParam.getUpperBound()), handleDate("autoExpireDate", dateRangeParam.getUpperBound()))))))))); } - + private void handleHasAndParam(Criteria criteria, HasAndListParam hasAndListParam) { - if (hasAndListParam != null) { + if (hasAndListParam == null) { + return; + } + + HasParam param = hasAndListParam.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0); + + DetachedCriteria criteria2 = DetachedCriteria.forClass(Obs.class, "obs"); + if (!FhirConstants.OBSERVATION.equals(param.getTargetResourceType())) { + return; + } + if (param.getParameterName().equals("encounter")) { + criteria2.createCriteria("encounter").add(Restrictions.eq("uuid", param.getParameterValue().toString())); + criteria2.setProjection(Projections.property("obs.order")); + criteria.add(Subqueries.propertyIn("id", criteria2)); + } else if (param.getParameterName().equals("person")) { + criteria2.createCriteria("person").add(Restrictions.eq("uuid", param.getParameterValue().toString())); + criteria2.setProjection(Projections.property("obs.order")); + criteria.add(Subqueries.propertyIn("id", criteria2)); + } else if (param.getParameterName().equals("category")) { + criteria2.createCriteria("concept").createCriteria("conceptClass") + .add(Restrictions.eq("name", param.getParameterValue().toString())); + criteria2.setProjection(Projections.property("obs.order")); + criteria.add(Subqueries.propertyIn("id", criteria2)); + } else if (param.getParameterName().equals("code")) { + criteria2.createCriteria("concept") + .add(Restrictions.eq("id", Integer.parseInt(param.getParameterValue().toString()))); + criteria2.setProjection(Projections.property("obs.order")); + criteria.add(Subqueries.propertyIn("id", criteria2)); + } else { + return; + } - if (lacksAlias(criteria, "obss")) { - criteria.createAlias("obs", "aliasObss"); - } - - DetachedCriteria detachedCriteria = DetachedCriteria.forClass(Obs.class); - - handleAndListParam(hasAndListParam, param -> { - if ( param.getValueAsQueryToken(fhirContext) != null) { - if (lacksAlias(criteria, "o")) { - criteria.createAlias("aliasObss.category", "o"); - } - } - - return Optional.of(eq("o.category", param.getValueAsQueryToken(fhirContext))); - }).ifPresent(criteria::add); - hasAndListParam.getValuesAsQueryTokens().stream().map(this::handleHasOrParam).filter(Optional::isPresent) - .flatMap(Optional::get).forEach(detachedCriteria::add); - - - criteria.add(Subqueries.exists(detachedCriteria)); - } + .flatMap(Optional::get).forEach(criteria2::add); + + criteria.add(Subqueries.exists(criteria2)); + } private Optional> handleHasOrParam(HasOrListParam hasOrListParam) { if (hasOrListParam == null) { return Optional.empty(); } - - return Optional.of(hasOrListParam.getValuesAsQueryTokens().stream().map(this::handleHasParam).filter( - Optional::isPresent).map(Optional::get)); + + return Optional.of(hasOrListParam.getValuesAsQueryTokens().stream().map(this::handleHasParam) + .filter(Optional::isPresent).map(Optional::get)); } private Optional handleHasParam(HasParam hasParam) { if (hasParam == null) { return Optional.empty(); } - + if (!FhirConstants.OBSERVATION.equals(hasParam.getTargetResourceType())) { return Optional.empty(); } - if(!(hasParam.getQueryParameterQualifier().equals(":not"))){ + if (!(hasParam.getQueryParameterQualifier().equals(FhirConstants.PARAMQUALIFIER_STRING_NOT))) { return Optional.empty(); + } else { + hasParam.setValueAsQueryToken(fhirContext, hasParam.getParameterName(), hasParam.getQueryParameterQualifier(), + hasParam.getParameterValue()); } return Optional.empty(); - } + } + } 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 a2dd8a1596..81537f67ba 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 @@ -58,8 +58,7 @@ public IBundleProvider searchForServiceRequests(ReferenceAndListParam patientRef SearchParameterMap theParams = new SearchParameterMap() .addParameter(FhirConstants.PATIENT_REFERENCE_SEARCH_HANDLER, patientReference) - .addParameter(FhirConstants.CODED_SEARCH_HANDLER, code) - .addParameter(FhirConstants.HAS_PROPERTY, has) + .addParameter(FhirConstants.CODED_SEARCH_HANDLER, code).addParameter(FhirConstants.HAS_PROPERTY, has) .addParameter(FhirConstants.ENCOUNTER_REFERENCE_SEARCH_HANDLER, encounterReference) .addParameter(FhirConstants.PARTICIPANT_REFERENCE_SEARCH_HANDLER, participantReference) .addParameter(FhirConstants.DATE_RANGE_SEARCH_HANDLER, occurrence) 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 29a179707e..79032f6390 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 @@ -108,8 +108,7 @@ public IBundleProvider searchForServiceRequests( @OptionalParam(name = ServiceRequest.SP_REQUESTER, chainWhitelist = { "", Practitioner.SP_IDENTIFIER, Practitioner.SP_GIVEN, Practitioner.SP_FAMILY, Practitioner.SP_NAME }, targetTypes = Practitioner.class) ReferenceAndListParam participantReference, - @OptionalParam(name = ServiceRequest.SP_OCCURRENCE) DateRangeParam occurrence, - + @OptionalParam(name = ServiceRequest.SP_OCCURRENCE) DateRangeParam occurrence, @OptionalParam(name = ServiceRequest.SP_RES_ID) TokenAndListParam uuid, @OptionalParam(name = "_lastUpdated") DateRangeParam lastUpdated, @OptionalParam(name = "_has") HasAndListParam has, 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 04c468d4a9..747da2e844 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,9 +36,6 @@ 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; @@ -339,29 +336,6 @@ public void searchForPeople_shouldAddRelatedResourcesWhenIncluded() { assertThat(resultList, hasItem(is(instanceOf(Patient.class)))); } - @Test - public void searchForServiceRequest_shouldReturnCollectionOfServiceRequestByHasParameter() { - HasParam hasParam = new HasParam("Observation", "based-on", "category", ":not=laboratory"); - HasOrListParam hasOrListParam = new HasOrListParam(); - HasAndListParam uuid = new HasAndListParam().addAnd(hasOrListParam.add(hasParam)); - SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.HAS_PROPERTY, hasParam); - - when(dao.getSearchResults(any(), any())).thenReturn(Collections.singletonList(order)); - when(dao.getSearchResultUuids(any())).thenReturn(Collections.singletonList(SERVICE_REQUEST_UUID)); - 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.emptySet()); - - IBundleProvider results = serviceRequestService.searchForServiceRequests(null, null, null, null, null, null, null, - uuid, null); - List resultList = get(results); - - assertThat(results, notNullValue()); - assertThat(resultList, not(empty())); - assertThat(resultList.size(), equalTo(1)); - } - @Test public void searchForPeople_shouldAddRelatedResourcesWhenIncludedR3() { HashSet includes = new HashSet<>(); diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/search/ObservationSearchQueryTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/search/ObservationSearchQueryTest.java index 120d3bba70..494083412b 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/api/search/ObservationSearchQueryTest.java +++ b/api/src/test/java/org/openmrs/module/fhir2/api/search/ObservationSearchQueryTest.java @@ -104,7 +104,9 @@ public class ObservationSearchQueryTest extends BaseModuleContextSensitiveTest { private static final String PATIENT_UUID = "5946f880-b197-400b-9caa-a3c661d23041"; - private static final String SERVICE_REQUEST_UUID = "7d96f25c-4949-4f72-9931-d808fbc226de"; + private static final String SERVICE_REQUEST_UUID = "1c96f25c-4949-4f72-9931-d808fbc226de"; + + private static final String WRONG_SERVICE_REQUEST_UUID = "2e59f25c-4949-4f72-9931-d808fbc226df"; private static final String PATIENT_WRONG_UUID = "c2299800-cca9-11e0-9572-abcdef0c9a66"; @@ -174,7 +176,7 @@ public void searchForObs_shouldSearchForObsByConceptId() { IBundleProvider results = search(theParams); assertThat(results, notNullValue()); - assertThat(results.size(), equalTo(3)); + assertThat(results.size(), equalTo(4)); List resultList = get(results); @@ -194,7 +196,7 @@ public void searchForObs_shouldSearchForObsByConceptUuid() { IBundleProvider results = search(theParams); assertThat(results, notNullValue()); - assertThat(results.size(), equalTo(3)); + assertThat(results.size(), equalTo(4)); List resultList = get(results); @@ -216,7 +218,7 @@ public void searchForObs_shouldReturnObsByConceptMapping() { IBundleProvider results = search(theParams); assertThat(results, notNullValue()); - assertThat(results.size(), equalTo(3)); + assertThat(results.size(), equalTo(4)); List resultList = get(results); @@ -243,7 +245,7 @@ public void searchForObs_shouldReturnMultipleObsByConceptMapping() { IBundleProvider results = search(theParams); assertThat(results, notNullValue()); - assertThat(results.size(), equalTo(15)); + assertThat(results.size(), equalTo(16)); List resultList = get(results); @@ -312,21 +314,41 @@ public void searchForObs_shouldReturnObsByPatientUuid() { @Test public void searchForObs_shouldReturnObsBasedOnServiceRequestUuid() { - ReferenceAndListParam serviceRequestReference = new ReferenceAndListParam() + + ReferenceAndListParam ref = new ReferenceAndListParam() .addAnd(new ReferenceOrListParam().add(new ReferenceParam().setValue(SERVICE_REQUEST_UUID))); - SearchParameterMap theParams = new SearchParameterMap(); - theParams.addParameter(FhirConstants.BASED_ON_REFERENCE_SEARCH_HANDLER, serviceRequestReference); + SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.BASED_ON_REFERENCE_SEARCH_HANDLER, + ref); IBundleProvider results = search(theParams); - assertThat(results.size(), equalTo(21)); + assertThat(results.size(), equalTo(1)); assertThat(results, notNullValue()); List resultList = get(results); assertThat(resultList, not(empty())); - assertThat(resultList.size(), equalTo(10)); + assertThat(resultList.size(), equalTo(1)); + } + + @Test + public void searchForObs_shouldReturnObsBasedOnWrongServiceRequestUuid() { + + ReferenceAndListParam ref = new ReferenceAndListParam() + .addAnd(new ReferenceOrListParam().add(new ReferenceParam().setValue(WRONG_SERVICE_REQUEST_UUID))); + + SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.BASED_ON_REFERENCE_SEARCH_HANDLER, + ref); + + IBundleProvider results = search(theParams); + + assertThat(results.size(), equalTo(0)); + + List resultList = get(results); + + assertThat(resultList, empty()); + assertThat(resultList.size(), equalTo(0)); } @Test @@ -688,7 +710,7 @@ public void searchForObs_shouldReturnObsByCategory() { IBundleProvider results = search(theParams); assertThat(results, notNullValue()); - assertThat(results.size(), equalTo(17)); + assertThat(results.size(), equalTo(18)); List resultList = get(results); @@ -1071,7 +1093,7 @@ public void searchForObs_shouldSearchForObsByValueQuantityWithPrefixNe() { IBundleProvider results = search(theParams); assertThat(results, notNullValue()); - assertThat(results.size(), equalTo(16)); + assertThat(results.size(), equalTo(17)); List resultList = get(results); @@ -1090,7 +1112,7 @@ public void searchForObs_shouldSearchForObsByValueQuantityWithPrefixLe() { IBundleProvider results = search(theParams); assertThat(results, notNullValue()); - assertThat(results.size(), equalTo(11)); + assertThat(results.size(), equalTo(12)); List resultList = get(results); @@ -1109,7 +1131,7 @@ public void searchForObs_shouldSearchForObsByValueQuantityWithPrefixLt() { IBundleProvider results = search(theParams); assertThat(results, notNullValue()); - assertThat(results.size(), equalTo(10)); + assertThat(results.size(), equalTo(11)); List resultList = get(results); 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 e5effbc4ef..aaabe733c4 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 @@ -158,12 +158,12 @@ public void searchForServiceRequests_shouldSearchForServiceRequestsByConceptId() IBundleProvider results = search(theParams); assertThat(results, notNullValue()); - assertThat(results.size(), equalTo(4)); + assertThat(results.size(), equalTo(6)); List resultList = get(results); assertThat(resultList, not(empty())); - assertThat(resultList.size(), equalTo(4)); + assertThat(resultList.size(), equalTo(6)); assertThat(resultList, everyItem( hasProperty("code", hasProperty("coding", hasItem(hasProperty("code", equalTo(TEST_ORDER_CONCEPT_UUID))))))); } @@ -177,12 +177,12 @@ public void searchForServiceRequests_shouldSearchForServiceRequestsByConceptUuid IBundleProvider results = search(theParams); assertThat(results, notNullValue()); - assertThat(results.size(), equalTo(4)); + assertThat(results.size(), equalTo(6)); List resultList = get(results); assertThat(resultList, not(empty())); - assertThat(resultList, hasSize(equalTo(4))); + assertThat(resultList, hasSize(equalTo(6))); assertThat(resultList, everyItem( hasProperty("code", hasProperty("coding", hasItem(hasProperty("code", equalTo(TEST_ORDER_CONCEPT_UUID))))))); } @@ -197,12 +197,12 @@ public void searchForServiceRequests_shouldSearchForServiceRequestsByConceptMapp IBundleProvider results = search(theParams); assertThat(results, notNullValue()); - assertThat(results.size(), equalTo(4)); + assertThat(results.size(), equalTo(6)); List resultList = get(results); assertThat(resultList, not(empty())); - assertThat(resultList, hasSize(equalTo(4))); + assertThat(resultList, hasSize(equalTo(6))); assertThat(resultList, everyItem( hasProperty("code", hasProperty("coding", hasItem(allOf(hasProperty("code", equalTo(TEST_ORDER_LOINC_CODE)), @@ -220,12 +220,12 @@ public void searchForServiceRequests_shouldSupportMappedAndUnmappedConcepts() { IBundleProvider results = search(theParams); assertThat(results, notNullValue()); - assertThat(results.size(), equalTo(4)); + assertThat(results.size(), equalTo(6)); List resultList = get(results); assertThat(resultList, not(empty())); - assertThat(resultList, hasSize(equalTo(4))); + assertThat(resultList, hasSize(equalTo(6))); assertThat(resultList, everyItem(allOf( hasProperty("code", hasProperty("coding", @@ -245,12 +245,12 @@ public void searchForServiceRequests_shouldReturnFromMultipleConceptMappings() { IBundleProvider results = search(theParams); assertThat(results, notNullValue()); - assertThat(results.size(), equalTo(4)); + assertThat(results.size(), equalTo(6)); List resultList = get(results); assertThat(resultList, not(empty())); - assertThat(resultList, hasSize(equalTo(4))); + assertThat(resultList, hasSize(equalTo(6))); assertThat(resultList, everyItem(anyOf( hasProperty("code", @@ -272,12 +272,12 @@ public void searchForServiceRequests_shouldReturnServiceRequestsByPatientUuid() IBundleProvider results = search(theParams); assertThat(results, notNullValue()); - assertThat(results.size(), equalTo(4)); + assertThat(results.size(), equalTo(6)); List resultList = get(results); assertThat(resultList, not(empty())); - assertThat(resultList, hasSize(equalTo(4))); + assertThat(resultList, hasSize(equalTo(6))); assertThat(resultList, everyItem( hasProperty("subject", hasProperty("referenceElement", hasProperty("idPart", equalTo(PATIENT_UUID)))))); } @@ -293,12 +293,12 @@ public void searchForServiceRequests_shouldSearchForServiceRequestsByMultiplePat IBundleProvider results = search(theParams); assertThat(results, notNullValue()); - assertThat(results.size(), equalTo(4)); + assertThat(results.size(), equalTo(6)); List resultList = get(results); assertThat(resultList, not(empty())); - assertThat(resultList, hasSize(equalTo(4))); + assertThat(resultList, hasSize(equalTo(6))); assertThat(resultList, everyItem( hasProperty("subject", hasProperty("referenceElement", hasProperty("idPart", equalTo(PATIENT_UUID)))))); } @@ -334,7 +334,7 @@ public void searchForServiceRequests_shouldReturnServiceRequestsByPatientGivenNa IBundleProvider results = search(theParams); assertThat(results, notNullValue()); - assertThat(results.size(), equalTo(4)); + assertThat(results.size(), equalTo(6)); List resources = get(results); @@ -354,7 +354,7 @@ public void searchForServiceRequests_shouldReturnServiceRequestsByPatientFamilyN IBundleProvider results = search(theParams); assertThat(results, notNullValue()); - assertThat(results.size(), equalTo(4)); + assertThat(results.size(), equalTo(6)); List resources = get(results); @@ -375,7 +375,7 @@ public void searchForServiceRequests_shouldSearchForServiceRequestsByMultiplePat IBundleProvider results = search(theParams); assertThat(results, notNullValue()); - assertThat(results.size(), equalTo(4)); + assertThat(results.size(), equalTo(6)); List resources = get(results); @@ -418,7 +418,7 @@ public void searchForServiceRequests_shouldSearchForServiceRequestsByMultiplePat IBundleProvider results = search(theParams); assertThat(results, notNullValue()); - assertThat(results.size(), equalTo(4)); + assertThat(results.size(), equalTo(6)); List resources = get(results); @@ -460,7 +460,7 @@ public void searchForServiceRequests_shouldReturnServiceRequestsByPatientName() IBundleProvider results = search(theParams); assertThat(results, notNullValue()); - assertThat(results.size(), equalTo(4)); + assertThat(results.size(), equalTo(6)); List resources = get(results); @@ -482,7 +482,7 @@ public void searchForServiceRequests_shouldSearchForServiceRequestsByMultiplePat IBundleProvider results = search(theParams); assertThat(results, notNullValue()); - assertThat(results.size(), equalTo(4)); + assertThat(results.size(), equalTo(6)); List resources = get(results); @@ -523,12 +523,12 @@ public void searchForServiceRequests_shouldReturnServiceRequestsByPatientIdentif IBundleProvider results = search(theParams); assertThat(results, notNullValue()); - assertThat(results.size(), equalTo(4)); + assertThat(results.size(), equalTo(6)); List resources = get(results); assertThat(resources, not(empty())); - assertThat(resources, hasSize(equalTo(4))); + assertThat(resources, hasSize(equalTo(6))); assertThat(resources, everyItem(hasProperty("subject", hasProperty("reference", endsWith(PATIENT_UUID))))); } @@ -544,12 +544,12 @@ public void searchForServiceRequests_shouldSearchForServiceRequestsByMultiplePat IBundleProvider results = search(theParams); assertThat(results, notNullValue()); - assertThat(results.size(), equalTo(4)); + assertThat(results.size(), equalTo(6)); List resultList = get(results); assertThat(resultList, not(empty())); - assertThat(resultList, hasSize(equalTo(4))); + assertThat(resultList, hasSize(equalTo(6))); assertThat(resultList, everyItem(hasProperty("subject", hasProperty("reference", endsWith(PATIENT_UUID))))); } @@ -609,7 +609,7 @@ public void searchForServiceRequests_shouldReturnServiceRequestsByPatientUuidAnd IBundleProvider results = search(theParams); assertThat(results, notNullValue()); - assertThat(results.size(), equalTo(4)); + assertThat(results.size(), equalTo(6)); List resources = get(results); @@ -648,12 +648,12 @@ public void searchForServiceRequests_shouldSearchByServiceRequestsDate() { IBundleProvider results = search(theParams); assertThat(results, notNullValue()); - assertThat(results.size(), equalTo(2)); + assertThat(results.size(), equalTo(3)); List resultList = get(results); assertThat(resultList, not(empty())); - assertThat(resultList.size(), equalTo(2)); + assertThat(resultList.size(), equalTo(3)); assertThat(resultList, everyItem(allOf( hasProperty("occurrencePeriod", @@ -670,12 +670,12 @@ public void searchForServiceRequests_shouldSearchByServiceRequestsDateAndTime() IBundleProvider results = search(theParams); assertThat(results, notNullValue()); - assertThat(results.size(), equalTo(2)); + assertThat(results.size(), equalTo(3)); List resultList = get(results); assertThat(resultList, not(empty())); - assertThat(resultList.size(), equalTo(2)); + assertThat(resultList.size(), equalTo(3)); assertThat(resultList, everyItem(allOf( hasProperty("occurrencePeriod", @@ -695,12 +695,12 @@ public void searchForServiceRequests_shouldReturnServiceRequestsByParticipantUui IBundleProvider results = search(theParams); assertThat(results, notNullValue()); - assertThat(results.size(), equalTo(4)); + assertThat(results.size(), equalTo(6)); List resources = get(results); assertThat(resources, notNullValue()); - assertThat(resources, hasSize(equalTo(4))); + assertThat(resources, hasSize(equalTo(6))); assertThat(resources, everyItem( hasProperty("requester", hasProperty("referenceElement", hasProperty("idPart", equalTo(PARTICIPANT_UUID)))))); } @@ -717,12 +717,12 @@ public void searchForServiceRequests_shouldSearchForServiceRequestsByMultiplePar IBundleProvider results = search(theParams); assertThat(results, notNullValue()); - assertThat(results.size(), equalTo(4)); + assertThat(results.size(), equalTo(6)); List resources = get(results); assertThat(resources, notNullValue()); - assertThat(resources, hasSize(equalTo(4))); + assertThat(resources, hasSize(equalTo(6))); assertThat(resources, everyItem( hasProperty("requester", hasProperty("referenceElement", hasProperty("idPart", equalTo(PARTICIPANT_UUID)))))); } @@ -758,12 +758,12 @@ public void searchForServiceRequests_shouldReturnServiceRequestsByParticipantGiv IBundleProvider results = search(theParams); assertThat(results, notNullValue()); - assertThat(results.size(), equalTo(4)); + assertThat(results.size(), equalTo(6)); List resources = get(results); assertThat(resources, notNullValue()); - assertThat(resources, hasSize(equalTo(4))); + assertThat(resources, hasSize(equalTo(6))); assertThat(resources, everyItem( hasProperty("requester", hasProperty("referenceElement", hasProperty("idPart", equalTo(PARTICIPANT_UUID)))))); } @@ -780,12 +780,12 @@ public void searchForServiceRequests_shouldSearchForServiceRequestsByMultiplePar IBundleProvider results = search(theParams); assertThat(results, notNullValue()); - assertThat(results.size(), equalTo(4)); + assertThat(results.size(), equalTo(6)); List resources = get(results); assertThat(resources, notNullValue()); - assertThat(resources, hasSize(equalTo(4))); + assertThat(resources, hasSize(equalTo(6))); assertThat(resources, everyItem( hasProperty("requester", hasProperty("referenceElement", hasProperty("idPart", equalTo(PARTICIPANT_UUID)))))); } @@ -823,12 +823,12 @@ public void searchForServiceRequests_shouldReturnServiceRequestsByParticipantFam IBundleProvider results = search(theParams); assertThat(results, notNullValue()); - assertThat(results.size(), equalTo(4)); + assertThat(results.size(), equalTo(6)); List resources = get(results); assertThat(resources, notNullValue()); - assertThat(resources, hasSize(equalTo(4))); + assertThat(resources, hasSize(equalTo(6))); assertThat(resources, everyItem( hasProperty("requester", hasProperty("referenceElement", hasProperty("idPart", equalTo(PARTICIPANT_UUID)))))); } @@ -845,12 +845,12 @@ public void searchForServiceRequests_shouldSearchForServiceRequestsByMultiplePar IBundleProvider results = search(theParams); assertThat(results, notNullValue()); - assertThat(results.size(), equalTo(4)); + assertThat(results.size(), equalTo(6)); List resources = get(results); assertThat(resources, notNullValue()); - assertThat(resources, hasSize(equalTo(4))); + assertThat(resources, hasSize(equalTo(6))); assertThat(resources, everyItem( hasProperty("requester", hasProperty("referenceElement", hasProperty("idPart", equalTo(PARTICIPANT_UUID)))))); } @@ -889,12 +889,12 @@ public void searchForServiceRequests_shouldReturnServiceRequestsByParticipantNam IBundleProvider results = search(theParams); assertThat(results, notNullValue()); - assertThat(results.size(), equalTo(4)); + assertThat(results.size(), equalTo(6)); List resources = get(results); assertThat(resources, notNullValue()); - assertThat(resources, hasSize(equalTo(4))); + assertThat(resources, hasSize(equalTo(6))); assertThat(resources, everyItem( hasProperty("requester", hasProperty("referenceElement", hasProperty("idPart", equalTo(PARTICIPANT_UUID)))))); } @@ -914,12 +914,12 @@ public void searchForServiceRequests_shouldSearchForServiceRequestsByMultiplePar IBundleProvider results = search(theParams); assertThat(results, notNullValue()); - assertThat(results.size(), equalTo(4)); + assertThat(results.size(), equalTo(6)); List resources = get(results); assertThat(resources, notNullValue()); - assertThat(resources, hasSize(equalTo(4))); + assertThat(resources, hasSize(equalTo(6))); assertThat(resources, everyItem( hasProperty("requester", hasProperty("referenceElement", hasProperty("idPart", equalTo(PARTICIPANT_UUID)))))); } @@ -958,12 +958,12 @@ public void searchForServiceRequests_shouldReturnServiceRequestsByParticipantIde IBundleProvider results = search(theParams); assertThat(results, notNullValue()); - assertThat(results.size(), equalTo(4)); + assertThat(results.size(), equalTo(6)); List resources = get(results); assertThat(resources, notNullValue()); - assertThat(resources, hasSize(equalTo(4))); + assertThat(resources, hasSize(equalTo(6))); assertThat(resources, everyItem( hasProperty("requester", hasProperty("identifier", hasProperty("value", equalTo(PARTICIPANT_IDENTIFIER)))))); } @@ -980,12 +980,12 @@ public void searchForServiceRequests_shouldSearchForServiceRequestsByMultiplePar IBundleProvider results = search(theParams); assertThat(results, notNullValue()); - assertThat(results.size(), equalTo(4)); + assertThat(results.size(), equalTo(6)); List resources = get(results); assertThat(resources, notNullValue()); - assertThat(resources, hasSize(equalTo(4))); + assertThat(resources, hasSize(equalTo(6))); assertThat(resources, everyItem( hasProperty("requester", hasProperty("identifier", hasProperty("value", equalTo(PARTICIPANT_IDENTIFIER)))))); } @@ -1040,11 +1040,11 @@ public void searchForServiceRequests_shouldSearchForServiceRequestsByLastUpdated IBundleProvider results = search(theParams); assertThat(results, notNullValue()); - assertThat(results.size(), equalTo(1)); + assertThat(results.size(), equalTo(2)); List resultList = get(results); - assertThat(resultList, hasSize(equalTo(1))); + assertThat(resultList, hasSize(equalTo(2))); } @Test diff --git a/integration-tests/src/test/java/org/openmrs/module/fhir2/providers/r4/ObservationFhirResourceProviderIntegrationTest.java b/integration-tests/src/test/java/org/openmrs/module/fhir2/providers/r4/ObservationFhirResourceProviderIntegrationTest.java index 7f1867b2f6..6be4e07b78 100644 --- a/integration-tests/src/test/java/org/openmrs/module/fhir2/providers/r4/ObservationFhirResourceProviderIntegrationTest.java +++ b/integration-tests/src/test/java/org/openmrs/module/fhir2/providers/r4/ObservationFhirResourceProviderIntegrationTest.java @@ -86,7 +86,7 @@ public class ObservationFhirResourceProviderIntegrationTest extends BaseFhirR4In public void setup() throws Exception { super.setup(); - executeDataSet(OBS_DATA_XML); + executeDataSet(OBS_DATA_XML); } @Test @@ -129,7 +129,6 @@ public void shouldReturnExistingObservationAsJson() throws Exception { //verify expected encounter assertThat(observation.getEncounter(), notNullValue()); assertThat(observation.getEncounter().getReference(), endsWith("/" + OBS_ENCOUNTER_UUID)); - assertThat(observation, validResource()); } @@ -411,6 +410,56 @@ public void shouldSearchForFilteredObservationsAsXML() throws Exception { everyItem(hasResource(hasProperty("subject", hasProperty("reference", endsWith(OBS_PATIENT_UUID)))))); assertThat(entries, everyItem(hasResource(validResource()))); } + + @Test + public void shouldSearchForFilteredObservationsBasedOnServiceRequestAsJson() throws Exception { + + MockHttpServletResponse response = get("/Observation?based-on:ServiceRequest=1c96f25c-4949-4f72-9931-d808fbc226de") + .accept(FhirMediaTypes.JSON).go(); + System.out.println(response); + + assertThat(response, isOk()); + assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString())); + assertThat(response.getContentAsString(), notNullValue()); + + Bundle results = readBundleResponse(response); + + assertThat(results, notNullValue()); + assertThat(results.getEntry().size(), equalTo(1)); + assertThat(results.getType(), equalTo(Bundle.BundleType.SEARCHSET)); + assertThat(results.hasEntry(), is(true)); + + List entries = results.getEntry(); + + assertThat(entries, everyItem(hasProperty("fullUrl", startsWith("http://localhost/ws/fhir2/R4/Observation/")))); + assertThat(entries, everyItem(hasResource(instanceOf(Observation.class)))); + assertThat(entries, everyItem(hasResource(validResource()))); + + } + + @Test + public void shouldSearchForFilteredObservationsBasedOnServiceRequestAsXML() throws Exception { + MockHttpServletResponse response = get("/Observation?based-on:ServiceRequest=1c96f25c-4949-4f72-9931-d808fbc226de") + .accept(FhirMediaTypes.XML).go(); + + assertThat(response, isOk()); + assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString())); + assertThat(response.getContentAsString(), notNullValue()); + + Bundle results = readBundleResponse(response); + + assertThat(results, notNullValue()); + assertThat(results.getEntry().size(), equalTo(1)); + assertThat(results.getType(), equalTo(Bundle.BundleType.SEARCHSET)); + assertThat(results.hasEntry(), is(true)); + + List entries = results.getEntry(); + + assertThat(entries, everyItem(hasProperty("fullUrl", startsWith("http://localhost/ws/fhir2/R4/Observation/")))); + assertThat(entries, everyItem(hasResource(instanceOf(Observation.class)))); + assertThat(entries, everyItem(hasResource(validResource()))); + + } @Test public void shouldSupportMultiplePagesAsJson() throws Exception { diff --git a/integration-tests/src/test/java/org/openmrs/module/fhir2/providers/r4/ServiceRequestFhirResourceProviderIntegrationTest.java b/integration-tests/src/test/java/org/openmrs/module/fhir2/providers/r4/ServiceRequestFhirResourceProviderIntegrationTest.java index 4f481e434b..77ab54dcd9 100644 --- a/integration-tests/src/test/java/org/openmrs/module/fhir2/providers/r4/ServiceRequestFhirResourceProviderIntegrationTest.java +++ b/integration-tests/src/test/java/org/openmrs/module/fhir2/providers/r4/ServiceRequestFhirResourceProviderIntegrationTest.java @@ -14,6 +14,7 @@ import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.everyItem; import static org.hamcrest.Matchers.hasProperty; +import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.notNullValue; @@ -50,8 +51,7 @@ public class ServiceRequestFhirResourceProviderIntegrationTest extends BaseFhirR @Override public void setup() throws Exception { super.setup(); - executeDataSet(TEST_ORDER_INITIAL_DATA); - + executeDataSet(TEST_ORDER_INITIAL_DATA); } @Test @@ -188,6 +188,203 @@ public void shouldSearchForExistingServiceRequestsAsXML() throws Exception { assertThat(entries, everyItem(hasResource(validResource()))); } + @Test + public void shouldSearchForExistingServiceRequestsWithHasAsJsonForCodeConcept() throws Exception { + MockHttpServletResponse response = get("/ServiceRequest?_has:Observation:based-on:code=5497" + ) + .accept(FhirMediaTypes.JSON).go(); + + assertThat(response, isOk()); + assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString())); + assertThat(response.getContentAsString(), notNullValue()); + System.out.println(response.getContentAsString()); + + Bundle results = readBundleResponse(response); + + assertThat(results, notNullValue()); + assertThat(results.getType(), equalTo(Bundle.BundleType.SEARCHSET)); + assertThat(results.hasEntry(), is(true)); + + List entries = results.getEntry(); + + + assertThat(entries, everyItem(hasResource(instanceOf(ServiceRequest.class)))); + assertThat(entries, everyItem(hasResource(validResource()))); + assertThat(entries, hasSize(2)); + + } + @Test + public void shouldSearchForExistingServiceRequestsWithHasAsXmlForCodeConcept() throws Exception { + MockHttpServletResponse response = get("/ServiceRequest?_has:Observation:based-on:code=5497" + ) + .accept(FhirMediaTypes.XML).go(); + + assertThat(response, isOk()); + assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString())); + assertThat(response.getContentAsString(), notNullValue()); + System.out.println(response.getContentAsString()); + + Bundle results = readBundleResponse(response); + + assertThat(results, notNullValue()); + assertThat(results.getType(), equalTo(Bundle.BundleType.SEARCHSET)); + assertThat(results.hasEntry(), is(true)); + + List entries = results.getEntry(); + + + assertThat(entries, everyItem(hasResource(instanceOf(ServiceRequest.class)))); + assertThat(entries, everyItem(hasResource(validResource()))); + assertThat(entries, hasSize(2)); + + } + @Test + public void shouldSearchForExistingServiceRequestsWithHasAsJsonForEncounter() throws Exception { + MockHttpServletResponse response = get("/ServiceRequest?_has:Observation:based-on:encounter=6382158d-401e-4190-a75d-347b5f04a893" + ) + .accept(FhirMediaTypes.JSON).go(); + + assertThat(response, isOk()); + assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString())); + assertThat(response.getContentAsString(), notNullValue()); + System.out.println(response.getContentAsString()); + + Bundle results = readBundleResponse(response); + + assertThat(results, notNullValue()); + assertThat(results.getType(), equalTo(Bundle.BundleType.SEARCHSET)); + assertThat(results.hasEntry(), is(true)); + + List entries = results.getEntry(); + + + assertThat(entries, everyItem(hasResource(instanceOf(ServiceRequest.class)))); + assertThat(entries, everyItem(hasResource(validResource()))); + assertThat(entries, hasSize(2)); + + } + @Test + public void shouldSearchForExistingServiceRequestsWithHasAsXmlForEncounter() throws Exception { + MockHttpServletResponse response = get("/ServiceRequest?_has:Observation:based-on:encounter=6382158d-401e-4190-a75d-347b5f04a893" + ) + .accept(FhirMediaTypes.XML).go(); + + assertThat(response, isOk()); + assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString())); + assertThat(response.getContentAsString(), notNullValue()); + System.out.println(response.getContentAsString()); + + Bundle results = readBundleResponse(response); + + assertThat(results, notNullValue()); + assertThat(results.getType(), equalTo(Bundle.BundleType.SEARCHSET)); + assertThat(results.hasEntry(), is(true)); + + List entries = results.getEntry(); + + + assertThat(entries, everyItem(hasResource(instanceOf(ServiceRequest.class)))); + assertThat(entries, everyItem(hasResource(validResource()))); + assertThat(entries, hasSize(2)); + + } + @Test + public void shouldSearchForExistingServiceRequestsWithHasAsJsonForPerson() throws Exception { + MockHttpServletResponse response = get("/ServiceRequest?_has:Observation:based-on:person=da7f524f-27ce-4bb2-86d6-6d1d05312bd5" + ) + .accept(FhirMediaTypes.JSON).go(); + + assertThat(response, isOk()); + assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString())); + assertThat(response.getContentAsString(), notNullValue()); + System.out.println(response.getContentAsString()); + + Bundle results = readBundleResponse(response); + + assertThat(results, notNullValue()); + assertThat(results.getType(), equalTo(Bundle.BundleType.SEARCHSET)); + assertThat(results.hasEntry(), is(true)); + + List entries = results.getEntry(); + + + assertThat(entries, everyItem(hasResource(instanceOf(ServiceRequest.class)))); + assertThat(entries, everyItem(hasResource(validResource()))); + assertThat(entries, hasSize(2)); + + } + @Test + public void shouldSearchForExistingServiceRequestsWithHasAsXmlForPerson() throws Exception { + MockHttpServletResponse response = get("/ServiceRequest?_has:Observation:based-on:person=da7f524f-27ce-4bb2-86d6-6d1d05312bd5" + ) + .accept(FhirMediaTypes.XML).go(); + + assertThat(response, isOk()); + assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString())); + assertThat(response.getContentAsString(), notNullValue()); + System.out.println(response.getContentAsString()); + + Bundle results = readBundleResponse(response); + + assertThat(results, notNullValue()); + assertThat(results.getType(), equalTo(Bundle.BundleType.SEARCHSET)); + assertThat(results.hasEntry(), is(true)); + + List entries = results.getEntry(); + + + assertThat(entries, everyItem(hasResource(instanceOf(ServiceRequest.class)))); + assertThat(entries, everyItem(hasResource(validResource()))); + assertThat(entries, hasSize(2)); + + } + @Test + public void shouldSearchForExistingServiceRequestsWithHasAsXlmForCategory() throws Exception { + MockHttpServletResponse response = get("/ServiceRequest?_has:Observation:based-on:category=Test") + .accept(FhirMediaTypes.XML).go(); + + assertThat(response, isOk()); + assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString())); + assertThat(response.getContentAsString(), notNullValue()); + + Bundle results = readBundleResponse(response); + System.out.println(response); + + assertThat(results, notNullValue()); + assertThat(results.getType(), equalTo(Bundle.BundleType.SEARCHSET)); + assertThat(results.hasEntry(), is(true)); + + List entries = results.getEntry(); + + + assertThat(entries, everyItem(hasResource(instanceOf(ServiceRequest.class)))); + assertThat(entries, everyItem(hasResource(validResource()))); + assertThat(entries, hasSize(2)); + } + @Test + public void shouldSearchForExistingServiceRequestsWithHasAsJsonForCategory() throws Exception { + MockHttpServletResponse response = get("/ServiceRequest?_has:Observation:based-on:category=Test") + .accept(FhirMediaTypes.XML).go(); + + assertThat(response, isOk()); + assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString())); + assertThat(response.getContentAsString(), notNullValue()); + + Bundle results = readBundleResponse(response); + System.out.println(response); + + assertThat(results, notNullValue()); + assertThat(results.getType(), equalTo(Bundle.BundleType.SEARCHSET)); + assertThat(results.hasEntry(), is(true)); + + List entries = results.getEntry(); + + + assertThat(entries, everyItem(hasResource(instanceOf(ServiceRequest.class)))); + assertThat(entries, everyItem(hasResource(validResource()))); + assertThat(entries, hasSize(2)); + } + @Test public void shouldReturnCountForServiceRequestAsJson() throws Exception { MockHttpServletResponse response = get("/ServiceRequest?_summary=count").accept(FhirMediaTypes.JSON).go(); diff --git a/test-data/src/test/resources/org/openmrs/module/fhir2/api/dao/impl/FhirObservationDaoImplTest_initial_data_suppl.xml b/test-data/src/test/resources/org/openmrs/module/fhir2/api/dao/impl/FhirObservationDaoImplTest_initial_data_suppl.xml index 5fb38a3b54..9d082a80a2 100644 --- a/test-data/src/test/resources/org/openmrs/module/fhir2/api/dao/impl/FhirObservationDaoImplTest_initial_data_suppl.xml +++ b/test-data/src/test/resources/org/openmrs/module/fhir2/api/dao/impl/FhirObservationDaoImplTest_initial_data_suppl.xml @@ -72,6 +72,7 @@ + diff --git a/test-data/src/test/resources/org/openmrs/module/fhir2/api/dao/impl/FhirServiceRequestTest_initial_data.xml b/test-data/src/test/resources/org/openmrs/module/fhir2/api/dao/impl/FhirServiceRequestTest_initial_data.xml index 7cedbf9335..4b69f50dc5 100644 --- a/test-data/src/test/resources/org/openmrs/module/fhir2/api/dao/impl/FhirServiceRequestTest_initial_data.xml +++ b/test-data/src/test/resources/org/openmrs/module/fhir2/api/dao/impl/FhirServiceRequestTest_initial_data.xml @@ -22,11 +22,24 @@ + + + + + + + + + + + + +