Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FM2-534: Searching should provide method to ensure consistent sort order #453

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I changed all these from And to Or...

@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,
Expand All @@ -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),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And the created a new And from the Or here, so that the other methods could remain the same...

encounterType, tag, hasAndListParam, id, lastUpdated, sort, includes, revIncludes)));
}

Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand All @@ -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));
}

/**
Expand Down
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
Expand Up @@ -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);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is now failing and returning a "Multiple values detected for non-repeatable parameter 'subject'. This server is not configured to allow multiple (AND/OR) values for this param" message


assertThat(results, notNullValue());
assertThat(results.getType(), equalTo(Bundle.BundleType.SEARCHSET));
assertThat(results.hasEntry(), is(true));

// TODO add testing
}
}


//6TS-4