Search in sources :

Example 1 with ReferenceAndListParam

use of ca.uhn.fhir.rest.param.ReferenceAndListParam in project ipf by oehf.

the class Iti67ResourceProvider method documentReferenceSearch.

@SuppressWarnings("unused")
@Search(type = DocumentReference.class)
public IBundleProvider documentReferenceSearch(@RequiredParam(name = DocumentReference.SP_PATIENT, chainWhitelist = { "", Patient.SP_IDENTIFIER }) ReferenceParam patient, @OptionalParam(name = DocumentReference.SP_STATUS) TokenOrListParam status, @OptionalParam(name = DocumentReference.SP_IDENTIFIER) TokenParam identifier, @OptionalParam(name = DocumentReference.SP_DATE) DateRangeParam date, @OptionalParam(name = STU3_INDEXED) DateRangeParam indexed, @OptionalParam(name = DocumentReference.SP_AUTHOR, chainWhitelist = { Practitioner.SP_FAMILY, Practitioner.SP_GIVEN }) ReferenceAndListParam author, @OptionalParam(name = DocumentReference.SP_CATEGORY) TokenOrListParam category, @OptionalParam(name = STU3_CLASS) TokenOrListParam class_, @OptionalParam(name = DocumentReference.SP_TYPE) TokenOrListParam type, @OptionalParam(name = DocumentReference.SP_SETTING) TokenOrListParam setting, @OptionalParam(name = DocumentReference.SP_PERIOD) DateRangeParam period, @OptionalParam(name = DocumentReference.SP_FACILITY) TokenOrListParam facility, @OptionalParam(name = DocumentReference.SP_EVENT) TokenOrListParam event, @OptionalParam(name = DocumentReference.SP_SECURITY_LABEL) TokenOrListParam securityLabel, @OptionalParam(name = STU3_SECURITY_LABEL) TokenOrListParam label, @OptionalParam(name = DocumentReference.SP_FORMAT) TokenOrListParam format, @OptionalParam(name = DocumentReference.SP_RELATED, chainWhitelist = { "", DocumentReference.SP_IDENTIFIER }) ReferenceOrListParam related, // -> related.identifier
@OptionalParam(name = STU3_RELATED_ID) TokenOrListParam relatedId, // -> related
@OptionalParam(name = STU3_RELATED_REF) ReferenceOrListParam relatedRef, // Extension to ITI-67
@OptionalParam(name = IAnyResource.SP_RES_ID) TokenParam resourceId, @Sort SortSpec sortSpec, @IncludeParam Set<Include> includeSpec, RequestDetails requestDetails, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {
    // Be graceful and accept STU3 parameters as well
    var dateParam = date != null ? date : indexed;
    var categoryParam = category != null ? category : class_;
    var securityLabelParam = securityLabel != null ? securityLabel : label;
    // Handle "related" parameters
    ReferenceOrListParam relatedParam = new ReferenceOrListParam();
    TokenOrListParam relatedIdParam = new TokenOrListParam();
    if (relatedRef != null) {
        relatedParam = relatedRef;
    } else if (relatedId != null) {
        relatedIdParam = relatedId;
    } else if (related != null) {
        related.getValuesAsQueryTokens().stream().filter(referenceParam -> !DocumentReference.SP_IDENTIFIER.equals(referenceParam.getChain())).forEach(relatedParam::addOr);
        related.getValuesAsQueryTokens().stream().filter(referenceParam -> DocumentReference.SP_IDENTIFIER.equals(referenceParam.getChain())).map(referenceParam -> referenceParam.toTokenParam(getFhirContext())).forEach(relatedIdParam::addOr);
    }
    var searchParameters = Iti67SearchParameters.builder().status(status).identifier(identifier).date(dateParam).category(categoryParam).type(type).setting(setting).period(period).facility(facility).event(event).securityLabel(securityLabelParam).format(format).related(relatedParam).relatedId(relatedIdParam)._id(resourceId).sortSpec(sortSpec).includeSpec(includeSpec).fhirContext(getFhirContext()).build();
    searchParameters.setAuthor(author);
    var patientChain = patient.getChain();
    if (Patient.SP_IDENTIFIER.equals(patientChain)) {
        searchParameters.setPatientIdentifier(patient.toTokenParam(getFhirContext()));
    } else if (patientChain == null || patientChain.isEmpty()) {
        searchParameters.setPatientReference(patient);
    }
    // Run down the route
    return requestBundleProvider(null, searchParameters, ResourceType.DocumentReference.name(), httpServletRequest, httpServletResponse, requestDetails);
}
Also used : IdParam(ca.uhn.fhir.rest.annotation.IdParam) IncludeParam(ca.uhn.fhir.rest.annotation.IncludeParam) AbstractPlainProvider(org.openehealth.ipf.commons.ihe.fhir.AbstractPlainProvider) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) IAnyResource(org.hl7.fhir.instance.model.api.IAnyResource) RequiredParam(ca.uhn.fhir.rest.annotation.RequiredParam) HttpServletRequest(javax.servlet.http.HttpServletRequest) RequestDetails(ca.uhn.fhir.rest.api.server.RequestDetails) DateRangeParam(ca.uhn.fhir.rest.param.DateRangeParam) Search(ca.uhn.fhir.rest.annotation.Search) ReferenceParam(ca.uhn.fhir.rest.param.ReferenceParam) Patient(org.hl7.fhir.r4.model.Patient) Read(ca.uhn.fhir.rest.annotation.Read) Practitioner(org.hl7.fhir.r4.model.Practitioner) ReferenceOrListParam(ca.uhn.fhir.rest.param.ReferenceOrListParam) DocumentReference(org.hl7.fhir.r4.model.DocumentReference) Sort(ca.uhn.fhir.rest.annotation.Sort) InvalidRequestException(ca.uhn.fhir.rest.server.exceptions.InvalidRequestException) HttpServletResponse(javax.servlet.http.HttpServletResponse) Set(java.util.Set) ReferenceAndListParam(ca.uhn.fhir.rest.param.ReferenceAndListParam) Include(ca.uhn.fhir.model.api.Include) IdType(org.hl7.fhir.r4.model.IdType) TokenParam(ca.uhn.fhir.rest.param.TokenParam) ResourceType(org.hl7.fhir.r4.model.ResourceType) SortSpec(ca.uhn.fhir.rest.api.SortSpec) TokenOrListParam(ca.uhn.fhir.rest.param.TokenOrListParam) OptionalParam(ca.uhn.fhir.rest.annotation.OptionalParam) TokenOrListParam(ca.uhn.fhir.rest.param.TokenOrListParam) ReferenceOrListParam(ca.uhn.fhir.rest.param.ReferenceOrListParam) Search(ca.uhn.fhir.rest.annotation.Search)

Example 2 with ReferenceAndListParam

use of ca.uhn.fhir.rest.param.ReferenceAndListParam in project ipf by oehf.

the class Iti66SearchParametersTest method setAuthor.

@Test
public void setAuthor() {
    var searchParameters = Iti66SearchParameters.builder().build();
    var param = new ReferenceAndListParam().addAnd(new ReferenceOrListParam().addOr(new ReferenceParam(Practitioner.SP_FAMILY, "family"))).addAnd(new ReferenceOrListParam().addOr(new ReferenceParam(Practitioner.SP_GIVEN, "given")));
    searchParameters.setAuthor(param);
    assertEquals("family", searchParameters.getAuthorFamilyName().getValue());
    assertEquals("given", searchParameters.getAuthorGivenName().getValue());
}
Also used : ReferenceParam(ca.uhn.fhir.rest.param.ReferenceParam) ReferenceAndListParam(ca.uhn.fhir.rest.param.ReferenceAndListParam) ReferenceOrListParam(ca.uhn.fhir.rest.param.ReferenceOrListParam) Test(org.junit.jupiter.api.Test)

Example 3 with ReferenceAndListParam

use of ca.uhn.fhir.rest.param.ReferenceAndListParam in project ipf by oehf.

the class Iti67SearchParametersTest method setAuthor.

@Test
public void setAuthor() {
    var searchParameters = Iti67SearchParameters.builder().build();
    var param = new ReferenceAndListParam().addAnd(new ReferenceOrListParam().addOr(new ReferenceParam(Practitioner.SP_FAMILY, "family"))).addAnd(new ReferenceOrListParam().addOr(new ReferenceParam(Practitioner.SP_GIVEN, "given")));
    searchParameters.setAuthor(param);
    assertEquals("family", searchParameters.getAuthorFamilyName().getValue());
    assertEquals("given", searchParameters.getAuthorGivenName().getValue());
}
Also used : ReferenceParam(ca.uhn.fhir.rest.param.ReferenceParam) ReferenceAndListParam(ca.uhn.fhir.rest.param.ReferenceAndListParam) ReferenceOrListParam(ca.uhn.fhir.rest.param.ReferenceOrListParam) Test(org.junit.jupiter.api.Test)

Example 4 with ReferenceAndListParam

use of ca.uhn.fhir.rest.param.ReferenceAndListParam in project openmrs-module-fhir2 by openmrs.

the class ConditionSearchQueryTest method searchForObsConditions_shouldSearchForConditionsByMultiplePatientGivenNameOr.

@Test
public void searchForObsConditions_shouldSearchForConditionsByMultiplePatientGivenNameOr() {
    ReferenceAndListParam referenceParam = new ReferenceAndListParam();
    ReferenceParam patient = new ReferenceParam();
    patient.setValue(PATIENT_GIVEN_NAME);
    patient.setChain(Patient.SP_GIVEN);
    ReferenceParam badPatient = new ReferenceParam();
    badPatient.setValue(PATIENT_WRONG_GIVEN_NAME);
    badPatient.setChain(Patient.SP_GIVEN);
    referenceParam.addValue(new ReferenceOrListParam().add(patient).add(badPatient));
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.PATIENT_REFERENCE_SEARCH_HANDLER, referenceParam);
    IBundleProvider results = search(theParams);
    List<IBaseResource> resultList = get(results);
    assertThat(results, notNullValue());
    assertThat(resultList, not(empty()));
    assertEquals(resultList.size(), 2);
}
Also used : ReferenceParam(ca.uhn.fhir.rest.param.ReferenceParam) ReferenceAndListParam(ca.uhn.fhir.rest.param.ReferenceAndListParam) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) ReferenceOrListParam(ca.uhn.fhir.rest.param.ReferenceOrListParam) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test)

Example 5 with ReferenceAndListParam

use of ca.uhn.fhir.rest.param.ReferenceAndListParam in project openmrs-module-fhir2 by openmrs.

the class ConditionSearchQueryTest method searchForObsConditions_shouldReturnConditionByPatientIdentifier.

@Test
public void searchForObsConditions_shouldReturnConditionByPatientIdentifier() {
    ReferenceParam patientReference = new ReferenceParam(Patient.SP_IDENTIFIER, PATIENT_IDENTIFIER);
    ReferenceAndListParam patientList = new ReferenceAndListParam();
    patientList.addAnd(new ReferenceOrListParam().addOr(patientReference));
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.PATIENT_REFERENCE_SEARCH_HANDLER, patientList);
    IBundleProvider results = search(theParams);
    List<IBaseResource> resultList = get(results);
    assertThat(results, notNullValue());
    assertThat(resultList, not(empty()));
    assertEquals(resultList.size(), 2);
    assertThat(((org.hl7.fhir.r4.model.Condition) resultList.iterator().next()).getSubject().getReference(), endsWith(PATIENT_UUID));
}
Also used : Condition(org.hl7.fhir.r4.model.Condition) ReferenceParam(ca.uhn.fhir.rest.param.ReferenceParam) ReferenceAndListParam(ca.uhn.fhir.rest.param.ReferenceAndListParam) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) ReferenceOrListParam(ca.uhn.fhir.rest.param.ReferenceOrListParam) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test)

Aggregations

ReferenceAndListParam (ca.uhn.fhir.rest.param.ReferenceAndListParam)357 ReferenceOrListParam (ca.uhn.fhir.rest.param.ReferenceOrListParam)357 ReferenceParam (ca.uhn.fhir.rest.param.ReferenceParam)357 IBundleProvider (ca.uhn.fhir.rest.api.server.IBundleProvider)353 Test (org.junit.Test)348 SearchParameterMap (org.openmrs.module.fhir2.api.search.param.SearchParameterMap)275 BaseModuleContextSensitiveTest (org.openmrs.test.BaseModuleContextSensitiveTest)253 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)219 TokenParam (ca.uhn.fhir.rest.param.TokenParam)45 TokenAndListParam (ca.uhn.fhir.rest.param.TokenAndListParam)43 ServiceRequest (org.hl7.fhir.r4.model.ServiceRequest)37 NumberParam (ca.uhn.fhir.rest.param.NumberParam)33 MedicationRequest (org.hl7.fhir.r4.model.MedicationRequest)32 BaseFhirProvenanceResourceTest (org.openmrs.module.fhir2.providers.BaseFhirProvenanceResourceTest)28 DiagnosticReport (org.hl7.fhir.r4.model.DiagnosticReport)26 FhirDiagnosticReport (org.openmrs.module.fhir2.model.FhirDiagnosticReport)26 MockIBundleProvider (org.openmrs.module.fhir2.providers.r4.MockIBundleProvider)19 ArrayList (java.util.ArrayList)17 HashSet (java.util.HashSet)17 Observation (org.hl7.fhir.r4.model.Observation)15