Search in sources :

Example 1 with ReferenceParam

use of ca.uhn.fhir.rest.param.ReferenceParam in project beneficiary-fhir-data by CMSgov.

the class ExplanationOfBenefitResourceProviderIT method searchForEobsIncludeTaxNumbersHandling.

/**
 * Verifies that {@link ExplanationOfBenefitResourceProvider#findByPatient(ReferenceParam,
 * TokenAndListParam, String, String, DateRangeParam, DateRangeParam, RequestDetails)} handles the
 * {@link ExplanationOfBenefitResourceProvider#HEADER_NAME_INCLUDE_TAX_NUMBERS} header properly.
 *
 * @throws FHIRException (indicates test failure)
 */
@Test
public void searchForEobsIncludeTaxNumbersHandling() throws FHIRException {
    List<Object> loadedRecords = ServerTestUtils.get().loadData(Arrays.asList(StaticRifResourceGroup.SAMPLE_A.getResources()));
    IGenericClient fhirClient = ServerTestUtils.get().createFhirClient();
    Beneficiary beneficiary = loadedRecords.stream().filter(r -> r instanceof Beneficiary).map(r -> (Beneficiary) r).findFirst().get();
    CarrierClaim carrierClaim = loadedRecords.stream().filter(r -> r instanceof CarrierClaim).map(r -> (CarrierClaim) r).findFirst().get();
    DMEClaim dmeClaim = loadedRecords.stream().filter(r -> r instanceof DMEClaim).map(r -> (DMEClaim) r).findFirst().get();
    Bundle searchResults;
    ExplanationOfBenefit carrierEob;
    ExplanationOfBenefit dmeEob;
    // Run the search without requesting tax numbers.
    searchResults = fhirClient.search().forResource(ExplanationOfBenefit.class).where(ExplanationOfBenefit.PATIENT.hasId(TransformerUtils.buildPatientId(beneficiary))).returnBundle(Bundle.class).execute();
    assertNotNull(searchResults);
    // Verify that tax numbers aren't present for carrier claims.
    carrierEob = filterToClaimType(searchResults, ClaimType.CARRIER).get(0);
    assertNull(TransformerTestUtils.findCareTeamEntryForProviderTaxNumber(carrierClaim.getLines().get(0).getProviderTaxNumber(), carrierEob.getCareTeam()));
    // Verify that tax numbers aren't present for DME claims.
    dmeEob = filterToClaimType(searchResults, ClaimType.DME).get(0);
    assertNull(TransformerTestUtils.findCareTeamEntryForProviderTaxNumber(dmeClaim.getLines().get(0).getProviderTaxNumber(), dmeEob.getCareTeam()));
    RequestHeaders requestHeader = RequestHeaders.getHeaderWrapper(CommonHeaders.HEADER_NAME_INCLUDE_TAX_NUMBERS, "true");
    fhirClient = ServerTestUtils.get().createFhirClientWithHeaders(requestHeader);
    searchResults = fhirClient.search().forResource(ExplanationOfBenefit.class).where(ExplanationOfBenefit.PATIENT.hasId(TransformerUtils.buildPatientId(beneficiary))).returnBundle(Bundle.class).execute();
    assertNotNull(searchResults);
    // Verify that tax numbers are present for carrier claims.
    carrierEob = filterToClaimType(searchResults, ClaimType.CARRIER).get(0);
    assertNotNull(TransformerTestUtils.findCareTeamEntryForProviderTaxNumber(carrierClaim.getLines().get(0).getProviderTaxNumber(), carrierEob.getCareTeam()));
    // Verify that tax numbers are present for DME claims.
    dmeEob = filterToClaimType(searchResults, ClaimType.DME).get(0);
    assertNotNull(TransformerTestUtils.findCareTeamEntryForProviderTaxNumber(dmeClaim.getLines().get(0).getProviderTaxNumber(), dmeEob.getCareTeam()));
}
Also used : Arrays(java.util.Arrays) Bundle(org.hl7.fhir.dstu3.model.Bundle) Date(java.util.Date) Constants(ca.uhn.fhir.rest.api.Constants) InpatientClaim(gov.cms.bfd.model.rif.InpatientClaim) DateTimeDt(ca.uhn.fhir.model.primitive.DateTimeDt) PartDEvent(gov.cms.bfd.model.rif.PartDEvent) SNFClaim(gov.cms.bfd.model.rif.SNFClaim) DateRangeParam(ca.uhn.fhir.rest.param.DateRangeParam) BeforeAll(org.junit.jupiter.api.BeforeAll) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) BeneficiaryHistory(gov.cms.bfd.model.rif.BeneficiaryHistory) IGenericClient(ca.uhn.fhir.rest.client.api.IGenericClient) Triple(org.apache.commons.lang3.tuple.Triple) OutpatientClaim(gov.cms.bfd.model.rif.OutpatientClaim) IdDt(ca.uhn.fhir.model.primitive.IdDt) ExplanationOfBenefit(org.hl7.fhir.dstu3.model.ExplanationOfBenefit) InvalidRequestException(ca.uhn.fhir.rest.server.exceptions.InvalidRequestException) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) Beneficiary(gov.cms.bfd.model.rif.Beneficiary) List(java.util.List) TransformerConstants(gov.cms.bfd.server.war.commons.TransformerConstants) EntityManagerFactory(javax.persistence.EntityManagerFactory) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) CarrierClaim(gov.cms.bfd.model.rif.CarrierClaim) Optional(java.util.Optional) TokenAndListParam(ca.uhn.fhir.rest.param.TokenAndListParam) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) RequestHeaders(gov.cms.bfd.server.war.commons.RequestHeaders) IBaseBundle(org.hl7.fhir.instance.model.api.IBaseBundle) ArrayList(java.util.ArrayList) HHAClaim(gov.cms.bfd.model.rif.HHAClaim) PipelineTestUtils(gov.cms.bfd.pipeline.sharedutils.PipelineTestUtils) RequestDetails(ca.uhn.fhir.rest.api.server.RequestDetails) ImmutableList(com.google.common.collect.ImmutableList) ReferenceParam(ca.uhn.fhir.rest.param.ReferenceParam) DMEClaim(gov.cms.bfd.model.rif.DMEClaim) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ResourceNotFoundException(ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException) StaticRifResourceGroup(gov.cms.bfd.model.rif.samples.StaticRifResourceGroup) ServerTestUtils(gov.cms.bfd.server.war.ServerTestUtils) StringClientParam(ca.uhn.fhir.rest.gclient.StringClientParam) CommonHeaders(gov.cms.bfd.server.war.commons.CommonHeaders) ImmutableTriple(org.apache.commons.lang3.tuple.ImmutableTriple) TokenClientParam(ca.uhn.fhir.rest.gclient.TokenClientParam) HospiceClaim(gov.cms.bfd.model.rif.HospiceClaim) EntityManager(javax.persistence.EntityManager) MedicareBeneficiaryIdHistory(gov.cms.bfd.model.rif.MedicareBeneficiaryIdHistory) AfterEach(org.junit.jupiter.api.AfterEach) ChronoUnit(java.time.temporal.ChronoUnit) Patient(org.hl7.fhir.dstu3.model.Patient) FHIRException(org.hl7.fhir.exceptions.FHIRException) DMEClaim(gov.cms.bfd.model.rif.DMEClaim) IGenericClient(ca.uhn.fhir.rest.client.api.IGenericClient) Bundle(org.hl7.fhir.dstu3.model.Bundle) IBaseBundle(org.hl7.fhir.instance.model.api.IBaseBundle) CarrierClaim(gov.cms.bfd.model.rif.CarrierClaim) ExplanationOfBenefit(org.hl7.fhir.dstu3.model.ExplanationOfBenefit) RequestHeaders(gov.cms.bfd.server.war.commons.RequestHeaders) Beneficiary(gov.cms.bfd.model.rif.Beneficiary) Test(org.junit.jupiter.api.Test)

Example 2 with ReferenceParam

use of ca.uhn.fhir.rest.param.ReferenceParam in project beneficiary-fhir-data by CMSgov.

the class R4ClaimResponseResourceProviderIT method shouldGetCorrectClaimResponseResourcesByMbiHash.

@Test
void shouldGetCorrectClaimResponseResourcesByMbiHash() {
    IGenericClient fhirClient = ServerTestUtils.get().createFhirClientV2();
    Bundle claimResult = fhirClient.search().forResource(ClaimResponse.class).where(ImmutableMap.of("mbi", Collections.singletonList(new ReferenceParam(RDATestUtils.MBI_OLD_HASH)), "service-date", Arrays.asList(new DateParam("gt1970-07-18"), new DateParam("lt1970-07-30")))).returnBundle(Bundle.class).execute();
    // Sort entries for consistent testing results
    claimResult.getEntry().sort(Comparator.comparing(a -> a.getResource().getId()));
    String expected = testUtils.expectedResponseFor("claimResponseSearch");
    String actual = FhirContext.forR4().newJsonParser().encodeResourceToString(claimResult);
    Set<String> ignorePatterns = new HashSet<>(IGNORE_PATTERNS);
    ignorePatterns.add("\"/id\"");
    ignorePatterns.add("\"/entry/[0-9]+/resource/created\"");
    AssertUtils.assertJsonEquals(expected, actual, ignorePatterns);
}
Also used : RDATestUtils(gov.cms.bfd.server.war.utils.RDATestUtils) Arrays(java.util.Arrays) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) Set(java.util.Set) AssertUtils(gov.cms.bfd.server.war.utils.AssertUtils) ClaimResponse(org.hl7.fhir.r4.model.ClaimResponse) HashSet(java.util.HashSet) AfterAll(org.junit.jupiter.api.AfterAll) Test(org.junit.jupiter.api.Test) FhirContext(ca.uhn.fhir.context.FhirContext) BeforeAll(org.junit.jupiter.api.BeforeAll) ReferenceParam(ca.uhn.fhir.rest.param.ReferenceParam) Bundle(org.hl7.fhir.r4.model.Bundle) IGenericClient(ca.uhn.fhir.rest.client.api.IGenericClient) ServerTestUtils(gov.cms.bfd.server.war.ServerTestUtils) Comparator(java.util.Comparator) Collections(java.util.Collections) DateParam(ca.uhn.fhir.rest.param.DateParam) ClaimResponse(org.hl7.fhir.r4.model.ClaimResponse) IGenericClient(ca.uhn.fhir.rest.client.api.IGenericClient) Bundle(org.hl7.fhir.r4.model.Bundle) ReferenceParam(ca.uhn.fhir.rest.param.ReferenceParam) DateParam(ca.uhn.fhir.rest.param.DateParam) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 3 with ReferenceParam

use of ca.uhn.fhir.rest.param.ReferenceParam in project cqf-ruler by DBCG.

the class ReportProvider method patientReport.

private Parameters.ParametersParameterComponent patientReport(Patient thePatient, Period thePeriod, String serverBase) {
    String patientId = thePatient.getIdElement().getIdPart();
    final Map<IIdType, IAnyResource> bundleEntries = new HashMap<>();
    bundleEntries.put(thePatient.getIdElement(), thePatient);
    ReferenceParam subjectParam = new ReferenceParam(patientId);
    search(MeasureReport.class, Searches.byParam("subject", subjectParam)).getAllResourcesTyped().forEach(measureReport -> {
        if (measureReport.getPeriod().getEnd().before(thePeriod.getStart()) || measureReport.getPeriod().getStart().after(thePeriod.getEnd())) {
            return;
        }
        bundleEntries.putIfAbsent(measureReport.getIdElement(), measureReport);
        getEvaluatedResources(measureReport).values().forEach(resource -> bundleEntries.putIfAbsent(resource.getIdElement(), resource));
    });
    Bundle patientReportBundle = new Bundle();
    patientReportBundle.setMeta(new Meta().addProfile(PATIENT_REPORT_PROFILE_URL));
    patientReportBundle.setType(Bundle.BundleType.COLLECTION);
    patientReportBundle.setTimestamp(new Date());
    patientReportBundle.setId(patientId + "-report");
    patientReportBundle.setIdentifier(new Identifier().setSystem("urn:ietf:rfc:3986").setValue("urn:uuid:" + UUID.randomUUID().toString()));
    bundleEntries.entrySet().forEach(resource -> patientReportBundle.addEntry(new Bundle.BundleEntryComponent().setResource((Resource) resource.getValue()).setFullUrl(Operations.getFullUrl(serverBase, resource.getValue().fhirType(), resource.getValue().getIdElement().getIdPart()))));
    Parameters.ParametersParameterComponent patientParameter = new Parameters.ParametersParameterComponent();
    patientParameter.setResource(patientReportBundle);
    patientParameter.setId(thePatient.getIdElement().getIdPart() + "-report");
    patientParameter.setName("return");
    return patientParameter;
}
Also used : Meta(org.hl7.fhir.r4.model.Meta) Parameters(org.hl7.fhir.r4.model.Parameters) HashMap(java.util.HashMap) Bundle(org.hl7.fhir.r4.model.Bundle) IAnyResource(org.hl7.fhir.instance.model.api.IAnyResource) Resource(org.hl7.fhir.r4.model.Resource) ReferenceParam(ca.uhn.fhir.rest.param.ReferenceParam) Date(java.util.Date) Identifier(org.hl7.fhir.r4.model.Identifier) IAnyResource(org.hl7.fhir.instance.model.api.IAnyResource) IIdType(org.hl7.fhir.instance.model.api.IIdType)

Example 4 with ReferenceParam

use of ca.uhn.fhir.rest.param.ReferenceParam 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 5 with ReferenceParam

use of ca.uhn.fhir.rest.param.ReferenceParam 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)

Aggregations

ReferenceParam (ca.uhn.fhir.rest.param.ReferenceParam)468 ReferenceOrListParam (ca.uhn.fhir.rest.param.ReferenceOrListParam)459 Test (org.junit.Test)452 ReferenceAndListParam (ca.uhn.fhir.rest.param.ReferenceAndListParam)357 IBundleProvider (ca.uhn.fhir.rest.api.server.IBundleProvider)353 SearchParameterMap (org.openmrs.module.fhir2.api.search.param.SearchParameterMap)275 BaseModuleContextSensitiveTest (org.openmrs.test.BaseModuleContextSensitiveTest)253 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)221 TokenParam (ca.uhn.fhir.rest.param.TokenParam)47 TokenAndListParam (ca.uhn.fhir.rest.param.TokenAndListParam)45 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 ArrayList (java.util.ArrayList)21 TokenOrListParam (ca.uhn.fhir.rest.param.TokenOrListParam)20 HashSet (java.util.HashSet)19 MockIBundleProvider (org.openmrs.module.fhir2.providers.r4.MockIBundleProvider)19