diff --git a/api/src/main/java/org/openmrs/module/fhir2/providers/r3/EncounterFhirResourceProvider.java b/api/src/main/java/org/openmrs/module/fhir2/providers/r3/EncounterFhirResourceProvider.java index 5ad5f13c4..1d325406e 100644 --- a/api/src/main/java/org/openmrs/module/fhir2/providers/r3/EncounterFhirResourceProvider.java +++ b/api/src/main/java/org/openmrs/module/fhir2/providers/r3/EncounterFhirResourceProvider.java @@ -32,6 +32,7 @@ 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.ReferenceOrListParam; import ca.uhn.fhir.rest.param.TokenAndListParam; import ca.uhn.fhir.rest.server.IResourceProvider; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; @@ -115,15 +116,15 @@ public OperationOutcome deleteEncounter(@IdParam @Nonnull IdType id) { public IBundleProvider searchEncounter(@OptionalParam(name = Encounter.SP_DATE) DateRangeParam date, @OptionalParam(name = Encounter.SP_LOCATION, chainWhitelist = { "", Location.SP_ADDRESS_CITY, Location.SP_ADDRESS_STATE, Location.SP_ADDRESS_COUNTRY, - Location.SP_ADDRESS_POSTALCODE }, targetTypes = Location.class) ReferenceAndListParam location, + Location.SP_ADDRESS_POSTALCODE }, targetTypes = Location.class) ReferenceOrListParam location, @OptionalParam(name = Encounter.SP_PARTICIPANT, chainWhitelist = { "", Practitioner.SP_IDENTIFIER, Practitioner.SP_GIVEN, Practitioner.SP_FAMILY, - Practitioner.SP_NAME }, targetTypes = Practitioner.class) ReferenceAndListParam participantReference, + Practitioner.SP_NAME }, targetTypes = Practitioner.class) ReferenceOrListParam participantReference, @OptionalParam(name = Encounter.SP_SUBJECT, chainWhitelist = { "", Patient.SP_IDENTIFIER, Patient.SP_GIVEN, Patient.SP_FAMILY, - Patient.SP_NAME }, targetTypes = Patient.class) ReferenceAndListParam subjectReference, + Patient.SP_NAME }, targetTypes = Patient.class) ReferenceOrListParam subjectReference, @OptionalParam(name = Encounter.SP_PATIENT, chainWhitelist = { "", Patient.SP_IDENTIFIER, Patient.SP_GIVEN, - Patient.SP_FAMILY, Patient.SP_NAME }, targetTypes = Patient.class) ReferenceAndListParam patientParam, + Patient.SP_FAMILY, Patient.SP_NAME }, targetTypes = Patient.class) ReferenceOrListParam patientParam, @OptionalParam(name = Encounter.SP_TYPE) TokenAndListParam encounterType, @OptionalParam(name = Encounter.SP_RES_ID) TokenAndListParam id, @OptionalParam(name = "_tag") TokenAndListParam tag, @@ -148,7 +149,7 @@ public IBundleProvider searchEncounter(@OptionalParam(name = Encounter.SP_DATE) } return new SearchQueryBundleProviderR3Wrapper(encounterService - .searchForEncounters(new EncounterSearchParams(date, location, participantReference, subjectReference, + .searchForEncounters(new EncounterSearchParams(date, new ReferenceAndListParam().addAnd(location), new ReferenceAndListParam().addAnd(participantReference), new ReferenceAndListParam().addAnd(subjectReference), encounterType, tag, hasAndListParam, id, lastUpdated, sort, includes, revIncludes))); } diff --git a/api/src/main/java/org/openmrs/module/fhir2/providers/r4/EncounterFhirResourceProvider.java b/api/src/main/java/org/openmrs/module/fhir2/providers/r4/EncounterFhirResourceProvider.java index 810bdbc61..2d0057919 100644 --- a/api/src/main/java/org/openmrs/module/fhir2/providers/r4/EncounterFhirResourceProvider.java +++ b/api/src/main/java/org/openmrs/module/fhir2/providers/r4/EncounterFhirResourceProvider.java @@ -34,6 +34,7 @@ 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.ReferenceOrListParam; import ca.uhn.fhir.rest.param.TokenAndListParam; import ca.uhn.fhir.rest.param.TokenParam; import ca.uhn.fhir.rest.server.IResourceProvider; @@ -110,15 +111,15 @@ public OperationOutcome deleteEncounter(@IdParam @Nonnull IdType id) { public IBundleProvider searchEncounter(@OptionalParam(name = Encounter.SP_DATE) DateRangeParam date, @OptionalParam(name = Encounter.SP_LOCATION, chainWhitelist = { "", Location.SP_ADDRESS_CITY, Location.SP_ADDRESS_STATE, Location.SP_ADDRESS_COUNTRY, - Location.SP_ADDRESS_POSTALCODE }, targetTypes = Location.class) ReferenceAndListParam location, + Location.SP_ADDRESS_POSTALCODE }, targetTypes = Location.class) ReferenceOrListParam location, @OptionalParam(name = Encounter.SP_PARTICIPANT, chainWhitelist = { "", Practitioner.SP_IDENTIFIER, Practitioner.SP_GIVEN, Practitioner.SP_FAMILY, - Practitioner.SP_NAME }, targetTypes = Practitioner.class) ReferenceAndListParam participantReference, + Practitioner.SP_NAME }, targetTypes = Practitioner.class) ReferenceOrListParam participantReference, @OptionalParam(name = Encounter.SP_SUBJECT, chainWhitelist = { "", Patient.SP_IDENTIFIER, Patient.SP_GIVEN, Patient.SP_FAMILY, - Patient.SP_NAME }, targetTypes = Patient.class) ReferenceAndListParam subjectReference, + Patient.SP_NAME }, targetTypes = Patient.class) ReferenceOrListParam subjectReference, @OptionalParam(name = Encounter.SP_PATIENT, chainWhitelist = { "", Patient.SP_IDENTIFIER, Patient.SP_GIVEN, - Patient.SP_FAMILY, Patient.SP_NAME }, targetTypes = Patient.class) ReferenceAndListParam patientParam, + Patient.SP_FAMILY, Patient.SP_NAME }, targetTypes = Patient.class) ReferenceOrListParam patientParam, @OptionalParam(name = Encounter.SP_TYPE) TokenAndListParam encounterType, @OptionalParam(name = Encounter.SP_RES_ID) TokenAndListParam id, @OptionalParam(name = "_tag") TokenAndListParam tag, @@ -142,8 +143,8 @@ public IBundleProvider searchEncounter(@OptionalParam(name = Encounter.SP_DATE) revIncludes = null; } - return encounterService.searchForEncounters(new EncounterSearchParams(date, location, participantReference, - subjectReference, encounterType, tag, hasAndListParam, id, lastUpdated, sort, includes, revIncludes)); + return encounterService.searchForEncounters(new EncounterSearchParams(date, new ReferenceAndListParam().addAnd(location), new ReferenceAndListParam() .addAnd(participantReference), + new ReferenceAndListParam().addAnd(subjectReference), encounterType, tag, hasAndListParam, id, lastUpdated, sort, includes, revIncludes)); } /** diff --git a/api/src/test/java/org/openmrs/module/fhir2/providers/r3/EncounterFhirResourceProviderTest.java b/api/src/test/java/org/openmrs/module/fhir2/providers/r3/EncounterFhirResourceProviderTest.java index 5983f65db..f618ed8e0 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/providers/r3/EncounterFhirResourceProviderTest.java +++ b/api/src/test/java/org/openmrs/module/fhir2/providers/r3/EncounterFhirResourceProviderTest.java @@ -137,8 +137,7 @@ public void searchEncounters_shouldReturnMatchingEncounters() { when(encounterService.searchForEncounters(any())) .thenReturn(new MockIBundleProvider<>(encounters, PREFERRED_SIZE, COUNT)); - ReferenceAndListParam subjectReference = new ReferenceAndListParam(); - subjectReference.addValue(new ReferenceOrListParam().add(new ReferenceParam().setChain(Patient.SP_NAME))); + ReferenceOrListParam subjectReference = new ReferenceOrListParam().add(new ReferenceParam().setChain(Patient.SP_NAME)); IBundleProvider results = resourceProvider.searchEncounter(null, null, null, subjectReference, null, null, null, null, null, null, null, null, null); @@ -158,8 +157,7 @@ public void searchEncounters_shouldReturnMatchingEncountersWhenPatientParamIsSpe when(encounterService.searchForEncounters(any())) .thenReturn(new MockIBundleProvider<>(encounters, PREFERRED_SIZE, COUNT)); - ReferenceAndListParam patientParam = new ReferenceAndListParam(); - patientParam.addValue(new ReferenceOrListParam().add(new ReferenceParam().setChain(Patient.SP_NAME))); + ReferenceOrListParam patientParam = new ReferenceOrListParam().add(new ReferenceParam().setChain(Patient.SP_NAME)); IBundleProvider results = resourceProvider.searchEncounter(null, null, null, null, patientParam, null, null, null, null, null, null, null, null); diff --git a/api/src/test/java/org/openmrs/module/fhir2/providers/r4/EncounterFhirResourceProviderTest.java b/api/src/test/java/org/openmrs/module/fhir2/providers/r4/EncounterFhirResourceProviderTest.java index 8df58fdb3..5c610baae 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/providers/r4/EncounterFhirResourceProviderTest.java +++ b/api/src/test/java/org/openmrs/module/fhir2/providers/r4/EncounterFhirResourceProviderTest.java @@ -32,7 +32,6 @@ 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; import ca.uhn.fhir.rest.param.TokenAndListParam; @@ -134,8 +133,7 @@ public void searchEncounters_shouldReturnMatchingEncounters() { when(encounterService.searchForEncounters(any())) .thenReturn(new MockIBundleProvider<>(encounters, PREFERRED_SIZE, COUNT)); - ReferenceAndListParam subjectReference = new ReferenceAndListParam(); - subjectReference.addValue(new ReferenceOrListParam().add(new ReferenceParam().setChain(Patient.SP_NAME))); + ReferenceOrListParam subjectReference = new ReferenceOrListParam().add(new ReferenceParam().setChain(Patient.SP_NAME)); IBundleProvider results = resourceProvider.searchEncounter(null, null, null, subjectReference, null, null, null, null, null, null, null, null, null); @@ -155,8 +153,7 @@ public void searchEncounters_shouldReturnMatchingEncountersWhenPatientParamIsSpe when(encounterService.searchForEncounters(any())) .thenReturn(new MockIBundleProvider<>(encounters, PREFERRED_SIZE, COUNT)); - ReferenceAndListParam patientParam = new ReferenceAndListParam(); - patientParam.addValue(new ReferenceOrListParam().add(new ReferenceParam().setChain(Patient.SP_NAME))); + ReferenceOrListParam patientParam = new ReferenceOrListParam().add(new ReferenceParam().setChain(Patient.SP_NAME)); IBundleProvider results = resourceProvider.searchEncounter(null, null, null, null, patientParam, null, null, null, null, null, null, null, null); diff --git a/integration-tests/src/test/java/org/openmrs/module/fhir2/providers/r4/EncounterFhirResourceProviderIntegrationTest.java b/integration-tests/src/test/java/org/openmrs/module/fhir2/providers/r4/EncounterFhirResourceProviderIntegrationTest.java index 4cc8fef7b..7c04227a7 100644 --- a/integration-tests/src/test/java/org/openmrs/module/fhir2/providers/r4/EncounterFhirResourceProviderIntegrationTest.java +++ b/integration-tests/src/test/java/org/openmrs/module/fhir2/providers/r4/EncounterFhirResourceProviderIntegrationTest.java @@ -818,4 +818,21 @@ public void shouldThrow404WhenUpdatingNonExistingVisitAsJson() throws Exception assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString())); assertThat(response.getContentAsString(), notNullValue()); } + + @Test + public void shouldSearchForEncountersByPatientIdentifiersOr() throws Exception { + String uri = String.format("/Encounter?subject.identifier=101-6&subject.name=Chebaskwony"); + MockHttpServletResponse response = get(uri).accept(FhirMediaTypes.XML).go(); + + Bundle results = readBundleResponse(response); + + assertThat(results, notNullValue()); + assertThat(results.getType(), equalTo(Bundle.BundleType.SEARCHSET)); + assertThat(results.hasEntry(), is(true)); + + // TODO add testing + } } + + +//6TS-4