Search in sources :

Example 1 with CcwCodebookVariable

use of gov.cms.bfd.model.codebook.data.CcwCodebookVariable in project beneficiary-fhir-data by CMSgov.

the class R4PatientResourceProvider method fetchBeneficiaries.

/**
 * Fetch beneficiaries for the PartD coverage parameter. If includeIdentiers are present then the
 * entity mappings are fetched as well
 *
 * @param coverageId coverage type
 * @param requestHeader {@link RequestHeaders} the holder that contains all supported resource
 *     request headers
 * @param paging specified
 * @return the beneficiaries
 */
private List<Beneficiary> fetchBeneficiaries(TokenParam coverageId, RequestHeaders requestHeader, PatientLinkBuilder paging) {
    String contractMonth = coverageId.getSystem().substring(coverageId.getSystem().lastIndexOf('/') + 1);
    CcwCodebookVariable partDContractMonth = partDCwVariableFor(contractMonth);
    String contractMonthField = partDFieldFor(partDContractMonth);
    String contractCode = coverageId.getValueNotNull();
    // Fetching with joins is not compatible with setMaxResults as explained in this post:
    // https://stackoverflow.com/questions/53569908/jpa-eager-fetching-and-pagination-best-practices
    // So, in cases where there are joins and paging, we query in two steps: first fetch bene-ids
    // with paging and then fetch full benes with joins.
    boolean useTwoSteps = (requestHeader.isMBIinIncludeIdentifiers() && paging.isPagingRequested());
    if (useTwoSteps) {
        // Fetch ids
        List<String> ids = queryBeneficiaryIds(contractMonthField, contractCode, paging).setMaxResults(paging.getQueryMaxSize()).getResultList();
        // Fetch the benes using the ids
        return queryBeneficiariesByIds(ids, requestHeader).getResultList();
    } else {
        // Fetch benes and their histories in one query
        return queryBeneficiariesBy(contractMonthField, contractCode, paging, requestHeader).setMaxResults(paging.getQueryMaxSize()).getResultList();
    }
}
Also used : CcwCodebookVariable(gov.cms.bfd.model.codebook.data.CcwCodebookVariable)

Example 2 with CcwCodebookVariable

use of gov.cms.bfd.model.codebook.data.CcwCodebookVariable in project beneficiary-fhir-data by CMSgov.

the class TransformerTestUtils method assertInformationPeriodEquals.

/**
 * @param expectedCategorySystem the expected value for {@link
 *     SupportingInformationComponent#getCategory()}'s {@link Coding#getSystem()}
 * @param expectedCategoryCodeVariable the expected {@link CcwCodebookVariable} for {@link
 *     SupportingInformationComponent#getCategory()}'s {@link Coding#getCode()}
 * @param expectedFromDate the expected {@link
 *     SupportingInformationComponent#getTimingPeriod().getStartElement()}
 * @param expectedThruDate the expected {@link
 *     SupportingInformationComponent#getTimingPeriod().getEndElement()}
 * @param actuals the actual {@link SupportingInformationComponent}s to verify
 */
static void assertInformationPeriodEquals(String expectedCategorySystem, CcwCodebookVariable expectedCategoryCodeVariable, LocalDate expectedFromDate, LocalDate expectedThruDate, List<SupportingInformationComponent> actuals) {
    String expectedCategoryCode = CCWUtils.calculateVariableReferenceUrl(expectedCategoryCodeVariable);
    Optional<SupportingInformationComponent> supportingInformationComponent = actuals.stream().filter(a -> isCodeInConcept(a.getCategory(), expectedCategorySystem, expectedCategoryCode)).findAny();
    assertTrue(supportingInformationComponent.isPresent());
    try {
        assertDateEquals(expectedFromDate, supportingInformationComponent.get().getTimingPeriod().getStartElement());
        assertDateEquals(expectedThruDate, supportingInformationComponent.get().getTimingPeriod().getEndElement());
    } catch (FHIRException e) {
        throw new BadCodeMonkeyException(e);
    }
}
Also used : IBaseHasExtensions(org.hl7.fhir.instance.model.api.IBaseHasExtensions) Arrays(java.util.Arrays) CarrierClaimColumn(gov.cms.bfd.model.rif.CarrierClaimColumn) CcwCodebookInterface(gov.cms.bfd.model.codebook.model.CcwCodebookInterface) Identifier(org.hl7.fhir.dstu3.model.Identifier) Coding(org.hl7.fhir.dstu3.model.Coding) InpatientClaim(gov.cms.bfd.model.rif.InpatientClaim) CodeableConcept(org.hl7.fhir.dstu3.model.CodeableConcept) Extension(org.hl7.fhir.dstu3.model.Extension) IBaseExtension(org.hl7.fhir.instance.model.api.IBaseExtension) ClaimCareteamrole(org.hl7.fhir.dstu3.model.codesystems.ClaimCareteamrole) SNFClaimColumn(gov.cms.bfd.model.rif.SNFClaimColumn) BigDecimal(java.math.BigDecimal) FhirContext(ca.uhn.fhir.context.FhirContext) SNFClaim(gov.cms.bfd.model.rif.SNFClaim) SNFClaimLine(gov.cms.bfd.model.rif.SNFClaimLine) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) HHAClaimColumn(gov.cms.bfd.model.rif.HHAClaimColumn) CarrierClaimLine(gov.cms.bfd.model.rif.CarrierClaimLine) Duration(java.time.Duration) BenefitBalanceComponent(org.hl7.fhir.dstu3.model.ExplanationOfBenefit.BenefitBalanceComponent) TemporalPrecisionEnum(ca.uhn.fhir.model.api.TemporalPrecisionEnum) Method(java.lang.reflect.Method) Diagnosis(gov.cms.bfd.server.war.commons.Diagnosis) OutpatientClaim(gov.cms.bfd.model.rif.OutpatientClaim) ExplanationOfBenefit(org.hl7.fhir.dstu3.model.ExplanationOfBenefit) MedicareSegment(gov.cms.bfd.server.war.commons.MedicareSegment) Reference(org.hl7.fhir.dstu3.model.Reference) DiagnosisComponent(org.hl7.fhir.dstu3.model.ExplanationOfBenefit.DiagnosisComponent) ItemComponent(org.hl7.fhir.dstu3.model.ExplanationOfBenefit.ItemComponent) InpatientClaimColumn(gov.cms.bfd.model.rif.InpatientClaimColumn) Instant(java.time.Instant) InvocationTargetException(java.lang.reflect.InvocationTargetException) Quantity(org.hl7.fhir.dstu3.model.Quantity) List(java.util.List) CareTeamComponent(org.hl7.fhir.dstu3.model.ExplanationOfBenefit.CareTeamComponent) TransformerConstants(gov.cms.bfd.server.war.commons.TransformerConstants) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) CarrierClaim(gov.cms.bfd.model.rif.CarrierClaim) LocalDate(java.time.LocalDate) Optional(java.util.Optional) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) OutpatientClaimColumn(gov.cms.bfd.model.rif.OutpatientClaimColumn) HospiceClaimLine(gov.cms.bfd.model.rif.HospiceClaimLine) HHAClaimLine(gov.cms.bfd.model.rif.HHAClaimLine) HospiceClaimColumn(gov.cms.bfd.model.rif.HospiceClaimColumn) Money(org.hl7.fhir.dstu3.model.Money) InpatientClaimLine(gov.cms.bfd.model.rif.InpatientClaimLine) ReferralRequest(org.hl7.fhir.dstu3.model.ReferralRequest) OutpatientClaimLine(gov.cms.bfd.model.rif.OutpatientClaimLine) BenefitComponent(org.hl7.fhir.dstu3.model.ExplanationOfBenefit.BenefitComponent) IAnyResource(org.hl7.fhir.instance.model.api.IAnyResource) CCWUtils(gov.cms.bfd.server.war.commons.CCWUtils) HHAClaim(gov.cms.bfd.model.rif.HHAClaim) CcwCodebookVariable(gov.cms.bfd.model.codebook.data.CcwCodebookVariable) Period(org.hl7.fhir.dstu3.model.Period) DMEClaim(gov.cms.bfd.model.rif.DMEClaim) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) DMEClaimLine(gov.cms.bfd.model.rif.DMEClaimLine) AdjudicationComponent(org.hl7.fhir.dstu3.model.ExplanationOfBenefit.AdjudicationComponent) BenefitCategory(org.hl7.fhir.dstu3.model.codesystems.BenefitCategory) BadCodeMonkeyException(gov.cms.bfd.sharedutils.exceptions.BadCodeMonkeyException) DateTimeType(org.hl7.fhir.dstu3.model.DateTimeType) Resource(org.hl7.fhir.dstu3.model.Resource) HospiceClaim(gov.cms.bfd.model.rif.HospiceClaim) IOException(java.io.IOException) Observation(org.hl7.fhir.dstu3.model.Observation) BaseDateTimeType(org.hl7.fhir.dstu3.model.BaseDateTimeType) SupportingInformationComponent(org.hl7.fhir.dstu3.model.ExplanationOfBenefit.SupportingInformationComponent) DMEClaimColumn(gov.cms.bfd.model.rif.DMEClaimColumn) FHIRException(org.hl7.fhir.exceptions.FHIRException) IdentifierType(gov.cms.bfd.server.war.commons.IdentifierType) SupportingInformationComponent(org.hl7.fhir.dstu3.model.ExplanationOfBenefit.SupportingInformationComponent) BadCodeMonkeyException(gov.cms.bfd.sharedutils.exceptions.BadCodeMonkeyException) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 3 with CcwCodebookVariable

use of gov.cms.bfd.model.codebook.data.CcwCodebookVariable in project beneficiary-fhir-data by CMSgov.

the class TransformerTestUtils method assertBenefitBalanceUsedIntEquals.

/**
 * @param expectedBenefitCategory the {@link BenefitCategory} for the expected {@link
 *     BenefitBalanceComponent#getCategory()}
 * @param expectedFinancialType the {@link CcwCodebookVariable} for the expected {@link
 *     BenefitComponent#getType()}
 * @param expectedUsedInt the expected {@link BenefitComponent#getUsedUnsignedIntType()} value
 * @param eob the {@link ExplanationOfBenefit} to verify the actual {@link BenefitComponent}
 *     within
 */
static void assertBenefitBalanceUsedIntEquals(BenefitCategory expectedBenefitCategory, CcwCodebookVariable expectedFinancialType, Integer expectedUsedInt, ExplanationOfBenefit eob) {
    Optional<BenefitBalanceComponent> benefitBalanceComponent = eob.getBenefitBalance().stream().filter(bb -> isCodeInConcept(bb.getCategory(), expectedBenefitCategory.getSystem(), expectedBenefitCategory.toCode())).findAny();
    assertTrue(benefitBalanceComponent.isPresent());
    Optional<BenefitComponent> benefitBalanceFinancialEntry = benefitBalanceComponent.get().getFinancial().stream().filter(f -> isCodeInConcept(f.getType(), TransformerConstants.CODING_BBAPI_BENEFIT_BALANCE_TYPE, CCWUtils.calculateVariableReferenceUrl(expectedFinancialType))).findAny();
    assertTrue(benefitBalanceFinancialEntry.isPresent());
    try {
        assertEquals(expectedUsedInt, benefitBalanceFinancialEntry.get().getUsedUnsignedIntType().getValue());
    } catch (FHIRException e) {
        throw new BadCodeMonkeyException(e);
    }
}
Also used : IBaseHasExtensions(org.hl7.fhir.instance.model.api.IBaseHasExtensions) Arrays(java.util.Arrays) CarrierClaimColumn(gov.cms.bfd.model.rif.CarrierClaimColumn) CcwCodebookInterface(gov.cms.bfd.model.codebook.model.CcwCodebookInterface) Identifier(org.hl7.fhir.dstu3.model.Identifier) Coding(org.hl7.fhir.dstu3.model.Coding) InpatientClaim(gov.cms.bfd.model.rif.InpatientClaim) CodeableConcept(org.hl7.fhir.dstu3.model.CodeableConcept) Extension(org.hl7.fhir.dstu3.model.Extension) IBaseExtension(org.hl7.fhir.instance.model.api.IBaseExtension) ClaimCareteamrole(org.hl7.fhir.dstu3.model.codesystems.ClaimCareteamrole) SNFClaimColumn(gov.cms.bfd.model.rif.SNFClaimColumn) BigDecimal(java.math.BigDecimal) FhirContext(ca.uhn.fhir.context.FhirContext) SNFClaim(gov.cms.bfd.model.rif.SNFClaim) SNFClaimLine(gov.cms.bfd.model.rif.SNFClaimLine) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) HHAClaimColumn(gov.cms.bfd.model.rif.HHAClaimColumn) CarrierClaimLine(gov.cms.bfd.model.rif.CarrierClaimLine) Duration(java.time.Duration) BenefitBalanceComponent(org.hl7.fhir.dstu3.model.ExplanationOfBenefit.BenefitBalanceComponent) TemporalPrecisionEnum(ca.uhn.fhir.model.api.TemporalPrecisionEnum) Method(java.lang.reflect.Method) Diagnosis(gov.cms.bfd.server.war.commons.Diagnosis) OutpatientClaim(gov.cms.bfd.model.rif.OutpatientClaim) ExplanationOfBenefit(org.hl7.fhir.dstu3.model.ExplanationOfBenefit) MedicareSegment(gov.cms.bfd.server.war.commons.MedicareSegment) Reference(org.hl7.fhir.dstu3.model.Reference) DiagnosisComponent(org.hl7.fhir.dstu3.model.ExplanationOfBenefit.DiagnosisComponent) ItemComponent(org.hl7.fhir.dstu3.model.ExplanationOfBenefit.ItemComponent) InpatientClaimColumn(gov.cms.bfd.model.rif.InpatientClaimColumn) Instant(java.time.Instant) InvocationTargetException(java.lang.reflect.InvocationTargetException) Quantity(org.hl7.fhir.dstu3.model.Quantity) List(java.util.List) CareTeamComponent(org.hl7.fhir.dstu3.model.ExplanationOfBenefit.CareTeamComponent) TransformerConstants(gov.cms.bfd.server.war.commons.TransformerConstants) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) CarrierClaim(gov.cms.bfd.model.rif.CarrierClaim) LocalDate(java.time.LocalDate) Optional(java.util.Optional) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) OutpatientClaimColumn(gov.cms.bfd.model.rif.OutpatientClaimColumn) HospiceClaimLine(gov.cms.bfd.model.rif.HospiceClaimLine) HHAClaimLine(gov.cms.bfd.model.rif.HHAClaimLine) HospiceClaimColumn(gov.cms.bfd.model.rif.HospiceClaimColumn) Money(org.hl7.fhir.dstu3.model.Money) InpatientClaimLine(gov.cms.bfd.model.rif.InpatientClaimLine) ReferralRequest(org.hl7.fhir.dstu3.model.ReferralRequest) OutpatientClaimLine(gov.cms.bfd.model.rif.OutpatientClaimLine) BenefitComponent(org.hl7.fhir.dstu3.model.ExplanationOfBenefit.BenefitComponent) IAnyResource(org.hl7.fhir.instance.model.api.IAnyResource) CCWUtils(gov.cms.bfd.server.war.commons.CCWUtils) HHAClaim(gov.cms.bfd.model.rif.HHAClaim) CcwCodebookVariable(gov.cms.bfd.model.codebook.data.CcwCodebookVariable) Period(org.hl7.fhir.dstu3.model.Period) DMEClaim(gov.cms.bfd.model.rif.DMEClaim) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) DMEClaimLine(gov.cms.bfd.model.rif.DMEClaimLine) AdjudicationComponent(org.hl7.fhir.dstu3.model.ExplanationOfBenefit.AdjudicationComponent) BenefitCategory(org.hl7.fhir.dstu3.model.codesystems.BenefitCategory) BadCodeMonkeyException(gov.cms.bfd.sharedutils.exceptions.BadCodeMonkeyException) DateTimeType(org.hl7.fhir.dstu3.model.DateTimeType) Resource(org.hl7.fhir.dstu3.model.Resource) HospiceClaim(gov.cms.bfd.model.rif.HospiceClaim) IOException(java.io.IOException) Observation(org.hl7.fhir.dstu3.model.Observation) BaseDateTimeType(org.hl7.fhir.dstu3.model.BaseDateTimeType) SupportingInformationComponent(org.hl7.fhir.dstu3.model.ExplanationOfBenefit.SupportingInformationComponent) DMEClaimColumn(gov.cms.bfd.model.rif.DMEClaimColumn) FHIRException(org.hl7.fhir.exceptions.FHIRException) IdentifierType(gov.cms.bfd.server.war.commons.IdentifierType) BadCodeMonkeyException(gov.cms.bfd.sharedutils.exceptions.BadCodeMonkeyException) FHIRException(org.hl7.fhir.exceptions.FHIRException) BenefitBalanceComponent(org.hl7.fhir.dstu3.model.ExplanationOfBenefit.BenefitBalanceComponent) BenefitComponent(org.hl7.fhir.dstu3.model.ExplanationOfBenefit.BenefitComponent)

Example 4 with CcwCodebookVariable

use of gov.cms.bfd.model.codebook.data.CcwCodebookVariable in project beneficiary-fhir-data by CMSgov.

the class PatientResourceProvider method searchByCoverageContract.

@Search
@Trace
public Bundle searchByCoverageContract(// of relational search is more common.
@RequiredParam(name = "_has:Coverage.extension") @Description(shortDefinition = "Part D coverage type") TokenParam coverageId, @OptionalParam(name = "_has:Coverage.rfrncyr") @Description(shortDefinition = "Part D reference year") TokenParam referenceYear, @OptionalParam(name = "cursor") @Description(shortDefinition = "The cursor used for result pagination") String cursor, RequestDetails requestDetails) {
    // Figure out what month they're searching for.
    String contractMonth = coverageId.getSystem().substring(coverageId.getSystem().lastIndexOf('/') + 1);
    CcwCodebookVariable partDContractMonth = partDCwVariableFor(contractMonth);
    String contractMonthValue = partDFieldByMonth(partDContractMonth);
    // Figure out which year they're searching for.
    int year = Year.now().getValue();
    if (referenceYear != null && !StringUtils.isEmpty(referenceYear.getValueNotNull())) {
        /*
       * TODO Once AB2D has switched to always specifying the year, the implicit `else` on this
       * needs to become an invalid request.
       */
        try {
            year = Integer.parseInt(referenceYear.getValueNotNull());
        } catch (NumberFormatException e) {
            throw new InvalidRequestException("Invalid contract year specified", e);
        }
    }
    YearMonth ym = YearMonth.of(year, Integer.valueOf(contractMonthValue));
    return searchByCoverageContractAndYearMonth(coverageId, ym.atDay(1), requestDetails);
}
Also used : CcwCodebookVariable(gov.cms.bfd.model.codebook.data.CcwCodebookVariable) YearMonth(java.time.YearMonth) InvalidRequestException(ca.uhn.fhir.rest.server.exceptions.InvalidRequestException) Trace(com.newrelic.api.agent.Trace) Search(ca.uhn.fhir.rest.annotation.Search)

Example 5 with CcwCodebookVariable

use of gov.cms.bfd.model.codebook.data.CcwCodebookVariable in project beneficiary-fhir-data by CMSgov.

the class R4PatientResourceProvider method searchByCoverageContract.

@Search
@Trace
public Bundle searchByCoverageContract(// of relational search is more common.
@RequiredParam(name = "_has:Coverage.extension") @Description(shortDefinition = "Part D coverage type") TokenParam coverageId, @OptionalParam(name = "_has:Coverage.rfrncyr") @Description(shortDefinition = "Part D reference year") TokenParam referenceYear, @OptionalParam(name = "cursor") @Description(shortDefinition = "The cursor used for result pagination") String cursor, RequestDetails requestDetails) {
    String contractMonth = coverageId.getSystem().substring(coverageId.getSystem().lastIndexOf('/') + 1);
    CcwCodebookVariable partDContractMonth = partDCwVariableFor(contractMonth);
    String contractMonthValue = partDFieldByMonth(partDContractMonth);
    // Figure out which year they're searching for.
    int year = Year.now().getValue();
    if (referenceYear != null && !StringUtils.isEmpty(referenceYear.getValueNotNull())) {
        /*
       * TODO Once AB2D has switched to always specifying the year, the implicit `else` on this
       * needs to become an invalid request.
       */
        try {
            year = Integer.parseInt(referenceYear.getValueNotNull());
        } catch (NumberFormatException e) {
            throw new InvalidRequestException("Invalid contract year specified", e);
        }
    }
    YearMonth ym = YearMonth.of(year, Integer.valueOf(contractMonthValue));
    return searchByCoverageContractAndYearMonth(coverageId, ym.atDay(1), requestDetails);
}
Also used : CcwCodebookVariable(gov.cms.bfd.model.codebook.data.CcwCodebookVariable) YearMonth(java.time.YearMonth) InvalidRequestException(ca.uhn.fhir.rest.server.exceptions.InvalidRequestException) Trace(com.newrelic.api.agent.Trace) Search(ca.uhn.fhir.rest.annotation.Search)

Aggregations

CcwCodebookVariable (gov.cms.bfd.model.codebook.data.CcwCodebookVariable)11 FhirContext (ca.uhn.fhir.context.FhirContext)6 TemporalPrecisionEnum (ca.uhn.fhir.model.api.TemporalPrecisionEnum)6 CcwCodebookInterface (gov.cms.bfd.model.codebook.model.CcwCodebookInterface)6 CarrierClaim (gov.cms.bfd.model.rif.CarrierClaim)6 CarrierClaimColumn (gov.cms.bfd.model.rif.CarrierClaimColumn)6 CarrierClaimLine (gov.cms.bfd.model.rif.CarrierClaimLine)6 DMEClaim (gov.cms.bfd.model.rif.DMEClaim)6 DMEClaimColumn (gov.cms.bfd.model.rif.DMEClaimColumn)6 DMEClaimLine (gov.cms.bfd.model.rif.DMEClaimLine)6 HHAClaim (gov.cms.bfd.model.rif.HHAClaim)6 HHAClaimColumn (gov.cms.bfd.model.rif.HHAClaimColumn)6 HHAClaimLine (gov.cms.bfd.model.rif.HHAClaimLine)6 HospiceClaim (gov.cms.bfd.model.rif.HospiceClaim)6 HospiceClaimColumn (gov.cms.bfd.model.rif.HospiceClaimColumn)6 HospiceClaimLine (gov.cms.bfd.model.rif.HospiceClaimLine)6 InpatientClaim (gov.cms.bfd.model.rif.InpatientClaim)6 InpatientClaimColumn (gov.cms.bfd.model.rif.InpatientClaimColumn)6 InpatientClaimLine (gov.cms.bfd.model.rif.InpatientClaimLine)6 OutpatientClaim (gov.cms.bfd.model.rif.OutpatientClaim)6