Search in sources :

Example 1 with TokenAndListParam

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

the class ExplanationOfBenefitResourceProvider method parseTypeParam.

/**
 * @param type a {@link TokenAndListParam} for the "type" field in a search
 * @return The {@link ClaimType}s to be searched, as computed from the specified "type" {@link
 *     TokenAndListParam} search param
 */
static Set<ClaimType> parseTypeParam(TokenAndListParam type) {
    if (type == null)
        type = new TokenAndListParam().addAnd(new TokenOrListParam().add(TransformerConstants.CODING_SYSTEM_BBAPI_EOB_TYPE, null));
    /*
     * This logic kinda' stinks, but HAPI forces us to handle some odd query
     * formulations, e.g. (in postfix notation):
     * "and(or(claimType==FOO, claimType==BAR), or(claimType==FOO))".
     */
    Set<ClaimType> claimTypes = new HashSet<ClaimType>(Arrays.asList(ClaimType.values()));
    for (TokenOrListParam typeToken : type.getValuesAsQueryTokens()) {
        /*
       * Each OR entry is additive: we start with an empty set and add every (valid)
       * ClaimType that's encountered.
       */
        Set<ClaimType> claimTypesInner = new HashSet<ClaimType>();
        for (TokenParam codingToken : typeToken.getValuesAsQueryTokens()) {
            if (codingToken.getModifier() != null)
                throw new IllegalArgumentException();
            /*
         * Per the FHIR spec (https://www.hl7.org/fhir/search.html), there are lots of
         * edge cases here: we could have null or wildcard or exact system, we can have
         * an exact or wildcard code. All of those need to be handled carefully -- see
         * the spec for details.
         */
            Optional<ClaimType> claimType = codingToken.getValue() != null ? ClaimType.parse(codingToken.getValue().toLowerCase()) : Optional.empty();
            if (codingToken.getSystem() != null && codingToken.getSystem().equals(TransformerConstants.CODING_SYSTEM_BBAPI_EOB_TYPE) && !claimType.isPresent()) {
                claimTypesInner.addAll(Arrays.asList(ClaimType.values()));
            } else if (codingToken.getSystem() == null || codingToken.getSystem().equals(TransformerConstants.CODING_SYSTEM_BBAPI_EOB_TYPE)) {
                if (claimType.isPresent())
                    claimTypesInner.add(claimType.get());
            }
        }
        /*
       * All multiple AND parameters will do is reduce the number of possible matches.
       */
        claimTypes.retainAll(claimTypesInner);
    }
    return claimTypes;
}
Also used : TokenOrListParam(ca.uhn.fhir.rest.param.TokenOrListParam) TokenParam(ca.uhn.fhir.rest.param.TokenParam) TokenAndListParam(ca.uhn.fhir.rest.param.TokenAndListParam) HashSet(java.util.HashSet)

Example 2 with TokenAndListParam

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

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

the class ConditionSearchQueryTest method searchForObsConditions_shouldReturnEmptyListByMismatchingUuidAndLastUpdated.

@Test
public void searchForObsConditions_shouldReturnEmptyListByMismatchingUuidAndLastUpdated() {
    TokenAndListParam uuid = new TokenAndListParam().addAnd(new TokenParam(EXISTING_OBS_CONDITION_UUID));
    DateRangeParam lastUpdated = new DateRangeParam().setUpperBound(DATE_VOIDED).setLowerBound(DATE_VOIDED);
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.COMMON_SEARCH_HANDLER, FhirConstants.ID_PROPERTY, uuid).addParameter(FhirConstants.COMMON_SEARCH_HANDLER, FhirConstants.LAST_UPDATED_PROPERTY, lastUpdated);
    IBundleProvider results = search(theParams);
    List<IBaseResource> resultList = get(results);
    assertThat(results, notNullValue());
    assertThat(resultList, empty());
}
Also used : DateRangeParam(ca.uhn.fhir.rest.param.DateRangeParam) TokenParam(ca.uhn.fhir.rest.param.TokenParam) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) TokenAndListParam(ca.uhn.fhir.rest.param.TokenAndListParam) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test)

Example 4 with TokenAndListParam

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

the class ConditionSearchQueryTest method searchForObsConditions_shouldReturnMultipleConditionsByCodeListAndNoSystem.

@Test
public void searchForObsConditions_shouldReturnMultipleConditionsByCodeListAndNoSystem() {
    TokenAndListParam listParam = new TokenAndListParam();
    listParam.addValue(new TokenOrListParam().add(new TokenParam(CONCEPT_ID_1)).add(new TokenParam(CONCEPT_ID_2)));
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.CODED_SEARCH_HANDLER, listParam);
    IBundleProvider results = search(theParams);
    List<IBaseResource> resultList = get(results);
    assertThat(results, notNullValue());
    assertThat(resultList, not(empty()));
    assertThat(resultList.size(), equalTo(2));
}
Also used : TokenOrListParam(ca.uhn.fhir.rest.param.TokenOrListParam) TokenParam(ca.uhn.fhir.rest.param.TokenParam) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) TokenAndListParam(ca.uhn.fhir.rest.param.TokenAndListParam) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test)

Example 5 with TokenAndListParam

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

the class ConditionSearchQueryTest method searchForObsConditions_shouldSearchForConditionsByMatchingUuidAndLastUpdated.

@Test
public void searchForObsConditions_shouldSearchForConditionsByMatchingUuidAndLastUpdated() {
    TokenAndListParam uuid = new TokenAndListParam().addAnd(new TokenParam(EXISTING_OBS_CONDITION_UUID));
    DateRangeParam lastUpdated = new DateRangeParam().setUpperBound(DATE_CREATED).setLowerBound(DATE_CREATED);
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.COMMON_SEARCH_HANDLER, FhirConstants.ID_PROPERTY, uuid).addParameter(FhirConstants.COMMON_SEARCH_HANDLER, FhirConstants.LAST_UPDATED_PROPERTY, lastUpdated);
    IBundleProvider results = search(theParams);
    List<IBaseResource> resultList = get(results);
    assertThat(results, notNullValue());
    assertThat(resultList, not(empty()));
    assertThat(resultList, hasSize(equalTo(1)));
    assertThat(((org.hl7.fhir.r4.model.Condition) resultList.iterator().next()).getIdElement().getIdPart(), equalTo(EXISTING_OBS_CONDITION_UUID));
}
Also used : DateRangeParam(ca.uhn.fhir.rest.param.DateRangeParam) Condition(org.hl7.fhir.r4.model.Condition) TokenParam(ca.uhn.fhir.rest.param.TokenParam) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) TokenAndListParam(ca.uhn.fhir.rest.param.TokenAndListParam) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test)

Aggregations

TokenAndListParam (ca.uhn.fhir.rest.param.TokenAndListParam)357 Test (org.junit.Test)347 IBundleProvider (ca.uhn.fhir.rest.api.server.IBundleProvider)340 TokenParam (ca.uhn.fhir.rest.param.TokenParam)312 SearchParameterMap (org.openmrs.module.fhir2.api.search.param.SearchParameterMap)260 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)247 BaseModuleContextSensitiveTest (org.openmrs.test.BaseModuleContextSensitiveTest)211 TokenOrListParam (ca.uhn.fhir.rest.param.TokenOrListParam)119 HashSet (java.util.HashSet)79 Include (ca.uhn.fhir.model.api.Include)77 DateRangeParam (ca.uhn.fhir.rest.param.DateRangeParam)48 ReferenceParam (ca.uhn.fhir.rest.param.ReferenceParam)48 ReferenceAndListParam (ca.uhn.fhir.rest.param.ReferenceAndListParam)46 ReferenceOrListParam (ca.uhn.fhir.rest.param.ReferenceOrListParam)46 NumberParam (ca.uhn.fhir.rest.param.NumberParam)36 BaseFhirProvenanceResourceTest (org.openmrs.module.fhir2.providers.BaseFhirProvenanceResourceTest)36 Observation (org.hl7.fhir.r4.model.Observation)24 StringParam (ca.uhn.fhir.rest.param.StringParam)21 MockIBundleProvider (org.openmrs.module.fhir2.providers.r4.MockIBundleProvider)21 ServiceRequest (org.hl7.fhir.r4.model.ServiceRequest)19