Search in sources :

Example 41 with DateType

use of org.hl7.fhir.r5.model.DateType in project beneficiary-fhir-data by CMSgov.

the class PartDEventTransformer method transformClaim.

/**
 * @param claimGroup the CCW {@link PartDEvent} to transform
 * @return a FHIR {@link ExplanationOfBenefit} resource that represents the specified {@link
 *     PartDEvent}
 */
private static ExplanationOfBenefit transformClaim(PartDEvent claimGroup) {
    ExplanationOfBenefit eob = new ExplanationOfBenefit();
    // Common group level fields between all claim types
    TransformerUtils.mapEobCommonClaimHeaderData(eob, claimGroup.getEventId(), claimGroup.getBeneficiaryId(), ClaimType.PDE, claimGroup.getClaimGroupId().toPlainString(), MedicareSegment.PART_D, Optional.of(claimGroup.getPrescriptionFillDate()), Optional.of(claimGroup.getPrescriptionFillDate()), Optional.empty(), claimGroup.getFinalAction());
    eob.addIdentifier(TransformerUtils.createIdentifier(CcwCodebookVariable.RX_SRVC_RFRNC_NUM, claimGroup.getPrescriptionReferenceNumber().toPlainString()));
    // map eob type codes into FHIR
    TransformerUtils.mapEobType(eob, ClaimType.PDE, Optional.empty(), Optional.empty());
    eob.getInsurance().getCoverage().addExtension(TransformerUtils.createExtensionIdentifier(CcwCodebookVariable.PLAN_CNTRCT_REC_ID, claimGroup.getPlanContractId()));
    eob.getInsurance().getCoverage().addExtension(TransformerUtils.createExtensionIdentifier(CcwCodebookVariable.PLAN_PBP_REC_NUM, claimGroup.getPlanBenefitPackageId()));
    if (claimGroup.getPaymentDate().isPresent()) {
        eob.getPayment().setDate(TransformerUtils.convertToDate(claimGroup.getPaymentDate().get()));
    }
    ItemComponent rxItem = eob.addItem();
    rxItem.setSequence(1);
    ExplanationOfBenefit.DetailComponent detail = new ExplanationOfBenefit.DetailComponent();
    switch(claimGroup.getCompoundCode()) {
        // COMPOUNDED
        case 2:
            /* Pharmacy dispense invoice for a compound */
            detail.getType().addCoding(new Coding().setSystem(V3ActCode.RXCINV.getSystem()).setCode(V3ActCode.RXCINV.toCode()).setDisplay(V3ActCode.RXCINV.getDisplay()));
            break;
        // NOT_COMPOUNDED
        case 1:
            /*
         * Pharmacy dispense invoice not involving a compound
         */
            detail.getType().addCoding(new Coding().setSystem(V3ActCode.RXCINV.getSystem()).setCode(V3ActCode.RXDINV.toCode()).setDisplay(V3ActCode.RXDINV.getDisplay()));
            break;
        // NOT_SPECIFIED
        case 0:
            /*
         * Pharmacy dispense invoice not specified - do not set a value
         */
            break;
        default:
            /*
         * Unexpected value encountered - compound code should be either
         * compounded or not compounded.
         */
            throw new InvalidRifValueException("Unexpected value encountered - compound code should be either compounded or not compounded: " + claimGroup.getCompoundCode());
    }
    rxItem.addDetail(detail);
    rxItem.setServiced(new DateType().setValue(TransformerUtils.convertToDate(claimGroup.getPrescriptionFillDate())));
    /*
     * Create an adjudication for either CVRD_D_PLAN_PD_AMT or NCVRD_PLAN_PD_AMT,
     * depending on the value of DRUG_CVRG_STUS_CD. Stick DRUG_CVRG_STUS_CD into the
     * adjudication.reason field.
     */
    CodeableConcept planPaidAmountAdjudicationCategory;
    BigDecimal planPaidAmountAdjudicationValue;
    if (claimGroup.getDrugCoverageStatusCode() == 'C') {
        planPaidAmountAdjudicationCategory = TransformerUtils.createAdjudicationCategory(CcwCodebookVariable.CVRD_D_PLAN_PD_AMT);
        planPaidAmountAdjudicationValue = claimGroup.getPartDPlanCoveredPaidAmount();
    } else {
        planPaidAmountAdjudicationCategory = TransformerUtils.createAdjudicationCategory(CcwCodebookVariable.NCVRD_PLAN_PD_AMT);
        planPaidAmountAdjudicationValue = claimGroup.getPartDPlanNonCoveredPaidAmount();
    }
    rxItem.addAdjudication().setCategory(planPaidAmountAdjudicationCategory).setReason(TransformerUtils.createCodeableConcept(eob, CcwCodebookVariable.DRUG_CVRG_STUS_CD, claimGroup.getDrugCoverageStatusCode())).setAmount(TransformerUtils.createMoney(planPaidAmountAdjudicationValue));
    rxItem.addAdjudication().setCategory(TransformerUtils.createAdjudicationCategory(CcwCodebookVariable.GDC_BLW_OOPT_AMT)).setAmount(TransformerUtils.createMoney(claimGroup.getGrossCostBelowOutOfPocketThreshold()));
    rxItem.addAdjudication().setCategory(TransformerUtils.createAdjudicationCategory(CcwCodebookVariable.GDC_ABV_OOPT_AMT)).setAmount(TransformerUtils.createMoney(claimGroup.getGrossCostAboveOutOfPocketThreshold()));
    rxItem.addAdjudication().setCategory(TransformerUtils.createAdjudicationCategory(CcwCodebookVariable.PTNT_PAY_AMT)).setAmount(TransformerUtils.createMoney(claimGroup.getPatientPaidAmount()));
    rxItem.addAdjudication().setCategory(TransformerUtils.createAdjudicationCategory(CcwCodebookVariable.OTHR_TROOP_AMT)).setAmount(TransformerUtils.createMoney(claimGroup.getOtherTrueOutOfPocketPaidAmount()));
    rxItem.addAdjudication().setCategory(TransformerUtils.createAdjudicationCategory(CcwCodebookVariable.LICS_AMT)).setAmount(TransformerUtils.createMoney(claimGroup.getLowIncomeSubsidyPaidAmount()));
    rxItem.addAdjudication().setCategory(TransformerUtils.createAdjudicationCategory(CcwCodebookVariable.PLRO_AMT)).setAmount(TransformerUtils.createMoney(claimGroup.getPatientLiabilityReductionOtherPaidAmount()));
    rxItem.addAdjudication().setCategory(TransformerUtils.createAdjudicationCategory(CcwCodebookVariable.TOT_RX_CST_AMT)).setAmount(TransformerUtils.createMoney(claimGroup.getTotalPrescriptionCost()));
    rxItem.addAdjudication().setCategory(TransformerUtils.createAdjudicationCategory(CcwCodebookVariable.RPTD_GAP_DSCNT_NUM)).setAmount(TransformerUtils.createMoney(claimGroup.getGapDiscountAmount()));
    if (claimGroup.getPrescriberIdQualifierCode() == null || !claimGroup.getPrescriberIdQualifierCode().equalsIgnoreCase("01"))
        throw new InvalidRifValueException("Prescriber ID Qualifier Code is invalid: " + claimGroup.getPrescriberIdQualifierCode());
    if (claimGroup.getPrescriberId() != null) {
        TransformerUtils.addCareTeamPractitioner(eob, rxItem, TransformerConstants.CODING_NPI_US, claimGroup.getPrescriberId(), ClaimCareteamrole.PRIMARY);
    }
    rxItem.setService(TransformerUtils.createCodeableConcept(TransformerConstants.CODING_NDC, null, TransformerUtils.retrieveFDADrugCodeDisplay(claimGroup.getNationalDrugCode()), claimGroup.getNationalDrugCode()));
    SimpleQuantity quantityDispensed = new SimpleQuantity();
    quantityDispensed.setValue(claimGroup.getQuantityDispensed());
    rxItem.setQuantity(quantityDispensed);
    rxItem.getQuantity().addExtension(TransformerUtils.createExtensionQuantity(CcwCodebookVariable.FILL_NUM, claimGroup.getFillNumber()));
    rxItem.getQuantity().addExtension(TransformerUtils.createExtensionQuantity(CcwCodebookVariable.DAYS_SUPLY_NUM, claimGroup.getDaysSupply()));
    /*
     * This chart is to dosplay the different code values for the different service provider id qualifer
     * codes below
     *   Code	    Code value
     *   01        National Provider Identifier (NPI)
     *   06        Unique Physician Identification Number (UPIN)
     *   07        National Council for Prescription Drug Programs (NCPDP) provider identifier
     *   08        State license number
     *   11        Federal tax number
     *   99        Other
     */
    IdentifierType identifierType;
    if (!claimGroup.getServiceProviderId().isEmpty()) {
        switch(claimGroup.getServiceProviderIdQualiferCode()) {
            case "01":
                identifierType = IdentifierType.NPI;
                break;
            case "06":
                identifierType = IdentifierType.UPIN;
                break;
            case "07":
                identifierType = IdentifierType.NCPDP;
                break;
            case "08":
                identifierType = IdentifierType.SL;
                break;
            case "11":
                identifierType = IdentifierType.TAX;
                break;
            default:
                identifierType = null;
                break;
        }
        if (identifierType != null) {
            eob.setOrganization(TransformerUtils.createIdentifierReference(identifierType, claimGroup.getServiceProviderId()));
            eob.setFacility(TransformerUtils.createIdentifierReference(identifierType, claimGroup.getServiceProviderId()));
        }
        eob.getFacility().addExtension(TransformerUtils.createExtensionCoding(eob, CcwCodebookVariable.PHRMCY_SRVC_TYPE_CD, claimGroup.getPharmacyTypeCode()));
    }
    /*
     * Storing code values in EOB.information below
     */
    TransformerUtils.addInformationWithCode(eob, CcwCodebookVariable.DAW_PROD_SLCTN_CD, CcwCodebookVariable.DAW_PROD_SLCTN_CD, claimGroup.getDispenseAsWrittenProductSelectionCode());
    if (claimGroup.getDispensingStatusCode().isPresent())
        TransformerUtils.addInformationWithCode(eob, CcwCodebookVariable.DSPNSNG_STUS_CD, CcwCodebookVariable.DSPNSNG_STUS_CD, claimGroup.getDispensingStatusCode());
    TransformerUtils.addInformationWithCode(eob, CcwCodebookVariable.DRUG_CVRG_STUS_CD, CcwCodebookVariable.DRUG_CVRG_STUS_CD, claimGroup.getDrugCoverageStatusCode());
    if (claimGroup.getAdjustmentDeletionCode().isPresent())
        TransformerUtils.addInformationWithCode(eob, CcwCodebookVariable.ADJSTMT_DLTN_CD, CcwCodebookVariable.ADJSTMT_DLTN_CD, claimGroup.getAdjustmentDeletionCode());
    if (claimGroup.getNonstandardFormatCode().isPresent())
        TransformerUtils.addInformationWithCode(eob, CcwCodebookVariable.NSTD_FRMT_CD, CcwCodebookVariable.NSTD_FRMT_CD, claimGroup.getNonstandardFormatCode());
    if (claimGroup.getPricingExceptionCode().isPresent())
        TransformerUtils.addInformationWithCode(eob, CcwCodebookVariable.PRCNG_EXCPTN_CD, CcwCodebookVariable.PRCNG_EXCPTN_CD, claimGroup.getPricingExceptionCode());
    if (claimGroup.getCatastrophicCoverageCode().isPresent())
        TransformerUtils.addInformationWithCode(eob, CcwCodebookVariable.CTSTRPHC_CVRG_CD, CcwCodebookVariable.CTSTRPHC_CVRG_CD, claimGroup.getCatastrophicCoverageCode());
    if (claimGroup.getPrescriptionOriginationCode().isPresent())
        TransformerUtils.addInformationWithCode(eob, CcwCodebookVariable.RX_ORGN_CD, CcwCodebookVariable.RX_ORGN_CD, claimGroup.getPrescriptionOriginationCode());
    if (claimGroup.getBrandGenericCode().isPresent())
        TransformerUtils.addInformationWithCode(eob, CcwCodebookVariable.BRND_GNRC_CD, CcwCodebookVariable.BRND_GNRC_CD, claimGroup.getBrandGenericCode());
    TransformerUtils.addInformationWithCode(eob, CcwCodebookVariable.PHRMCY_SRVC_TYPE_CD, CcwCodebookVariable.PHRMCY_SRVC_TYPE_CD, claimGroup.getPharmacyTypeCode());
    TransformerUtils.addInformationWithCode(eob, CcwCodebookVariable.PTNT_RSDNC_CD, CcwCodebookVariable.PTNT_RSDNC_CD, claimGroup.getPatientResidenceCode());
    if (claimGroup.getSubmissionClarificationCode().isPresent())
        TransformerUtils.addInformationWithCode(eob, CcwCodebookVariable.SUBMSN_CLR_CD, CcwCodebookVariable.SUBMSN_CLR_CD, claimGroup.getSubmissionClarificationCode());
    TransformerUtils.setLastUpdated(eob, claimGroup.getLastUpdated());
    return eob;
}
Also used : Coding(org.hl7.fhir.dstu3.model.Coding) InvalidRifValueException(gov.cms.bfd.model.rif.parse.InvalidRifValueException) ItemComponent(org.hl7.fhir.dstu3.model.ExplanationOfBenefit.ItemComponent) SimpleQuantity(org.hl7.fhir.dstu3.model.SimpleQuantity) ExplanationOfBenefit(org.hl7.fhir.dstu3.model.ExplanationOfBenefit) DateType(org.hl7.fhir.dstu3.model.DateType) IdentifierType(gov.cms.bfd.server.war.commons.IdentifierType) BigDecimal(java.math.BigDecimal) CodeableConcept(org.hl7.fhir.dstu3.model.CodeableConcept)

Example 42 with DateType

use of org.hl7.fhir.r5.model.DateType in project beneficiary-fhir-data by CMSgov.

the class TransformerUtils method addCommonEobInformationInpatientSNF.

/**
 * Adds EOB information to fields that are common between the Inpatient and SNF claim types.
 *
 * @param eob the {@link ExplanationOfBenefit} that fields will be added to by this method
 * @param admissionTypeCd CLM_IP_ADMSN_TYPE_CD: a {@link Character} shared field representing the
 *     admission type cd for the claim
 * @param sourceAdmissionCd CLM_SRC_IP_ADMSN_CD: an {@link Optional}<{@link Character}>
 *     shared field representing the source admission cd for the claim
 * @param noncoveredStayFromDate NCH_VRFD_NCVRD_STAY_FROM_DT: an {@link Optional}<{@link
 *     LocalDate}> shared field representing the non-covered stay from date for the claim
 * @param noncoveredStayThroughDate NCH_VRFD_NCVRD_STAY_THRU_DT: an {@link Optional}<{@link
 *     LocalDate}> shared field representing the non-covered stay through date for the claim
 * @param coveredCareThroughDate NCH_ACTV_OR_CVRD_LVL_CARE_THRU: an {@link Optional}<{@link
 *     LocalDate}> shared field representing the covered stay through date for the claim
 * @param medicareBenefitsExhaustedDate NCH_BENE_MDCR_BNFTS_EXHTD_DT_I: an {@link
 *     Optional}<{@link LocalDate}> shared field representing the medicare benefits
 *     exhausted date for the claim
 * @param diagnosisRelatedGroupCd CLM_DRG_CD: an {@link Optional}<{@link String}> shared
 *     field representing the non-covered stay from date for the claim
 */
static void addCommonEobInformationInpatientSNF(ExplanationOfBenefit eob, Character admissionTypeCd, Optional<Character> sourceAdmissionCd, Optional<LocalDate> noncoveredStayFromDate, Optional<LocalDate> noncoveredStayThroughDate, Optional<LocalDate> coveredCareThroughDate, Optional<LocalDate> medicareBenefitsExhaustedDate, Optional<String> diagnosisRelatedGroupCd) {
    // admissionTypeCd
    addInformationWithCode(eob, CcwCodebookVariable.CLM_IP_ADMSN_TYPE_CD, CcwCodebookVariable.CLM_IP_ADMSN_TYPE_CD, admissionTypeCd);
    // sourceAdmissionCd
    if (sourceAdmissionCd.isPresent()) {
        addInformationWithCode(eob, CcwCodebookVariable.CLM_SRC_IP_ADMSN_CD, CcwCodebookVariable.CLM_SRC_IP_ADMSN_CD, sourceAdmissionCd);
    }
    // noncoveredStayFromDate & noncoveredStayThroughDate
    if (noncoveredStayFromDate.isPresent() || noncoveredStayThroughDate.isPresent()) {
        TransformerUtils.validatePeriodDates(noncoveredStayFromDate, noncoveredStayThroughDate);
        SupportingInformationComponent nchVrfdNcvrdStayInfo = TransformerUtils.addInformation(eob, CcwCodebookVariable.NCH_VRFD_NCVRD_STAY_FROM_DT);
        Period nchVrfdNcvrdStayPeriod = new Period();
        if (noncoveredStayFromDate.isPresent())
            nchVrfdNcvrdStayPeriod.setStart(TransformerUtils.convertToDate((noncoveredStayFromDate.get())), TemporalPrecisionEnum.DAY);
        if (noncoveredStayThroughDate.isPresent())
            nchVrfdNcvrdStayPeriod.setEnd(TransformerUtils.convertToDate((noncoveredStayThroughDate.get())), TemporalPrecisionEnum.DAY);
        nchVrfdNcvrdStayInfo.setTiming(nchVrfdNcvrdStayPeriod);
    }
    // coveredCareThroughDate
    if (coveredCareThroughDate.isPresent()) {
        SupportingInformationComponent nchActvOrCvrdLvlCareThruInfo = TransformerUtils.addInformation(eob, CcwCodebookVariable.NCH_ACTV_OR_CVRD_LVL_CARE_THRU);
        nchActvOrCvrdLvlCareThruInfo.setTiming(new DateType(TransformerUtils.convertToDate(coveredCareThroughDate.get())));
    }
    // medicareBenefitsExhaustedDate
    if (medicareBenefitsExhaustedDate.isPresent()) {
        SupportingInformationComponent nchBeneMdcrBnftsExhtdDtIInfo = TransformerUtils.addInformation(eob, CcwCodebookVariable.NCH_BENE_MDCR_BNFTS_EXHTD_DT_I);
        nchBeneMdcrBnftsExhtdDtIInfo.setTiming(new DateType(TransformerUtils.convertToDate(medicareBenefitsExhaustedDate.get())));
    }
    // diagnosisRelatedGroupCd
    if (diagnosisRelatedGroupCd.isPresent()) {
        /*
       * FIXME This is an invalid DiagnosisComponent, since it's missing a (required) ICD code.
       * Instead, stick the DRG on the claim's primary/first diagnosis. SamhsaMatcher uses this
       * field so if this is updated you'll need to update that as well.
       */
        eob.addDiagnosis().setPackageCode(createCodeableConcept(eob, CcwCodebookVariable.CLM_DRG_CD, diagnosisRelatedGroupCd));
    }
}
Also used : SupportingInformationComponent(org.hl7.fhir.dstu3.model.ExplanationOfBenefit.SupportingInformationComponent) Period(org.hl7.fhir.dstu3.model.Period) DateType(org.hl7.fhir.dstu3.model.DateType)

Example 43 with DateType

use of org.hl7.fhir.r5.model.DateType in project beneficiary-fhir-data by CMSgov.

the class HHAClaimTransformerV2Test method shouldHaveLineItemServicedDate.

@Test
public void shouldHaveLineItemServicedDate() {
    DateType servicedDate = eob.getItemFirstRep().getServicedDateType();
    DateType compare = new DateType("2015-06-23");
    assertEquals(servicedDate.toString(), compare.toString());
}
Also used : DateType(org.hl7.fhir.r4.model.DateType) Test(org.junit.jupiter.api.Test)

Example 44 with DateType

use of org.hl7.fhir.r5.model.DateType in project beneficiary-fhir-data by CMSgov.

the class CarrierClaimTransformerV2Test method shouldHaveClaimReceivedDateSupInfo.

@Test
public void shouldHaveClaimReceivedDateSupInfo() {
    SupportingInformationComponent sic = TransformerTestUtilsV2.findSupportingInfoByCode("clmrecvddate", eob.getSupportingInfo());
    SupportingInformationComponent compare = TransformerTestUtilsV2.createSupportingInfo(// We don't care what the sequence number is here
    sic.getSequence(), // Category
    Arrays.asList(new Coding("http://hl7.org/fhir/us/carin-bb/CodeSystem/C4BBSupportingInfoType", "clmrecvddate", "Claim Received Date"), new Coding("https://bluebutton.cms.gov/resources/codesystem/information", "https://bluebutton.cms.gov/resources/variables/nch_wkly_proc_dt", "NCH Weekly Claim Processing Date"))).setTiming(new DateType("1999-11-06"));
    assertTrue(compare.equalsDeep(sic));
}
Also used : SupportingInformationComponent(org.hl7.fhir.r4.model.ExplanationOfBenefit.SupportingInformationComponent) Coding(org.hl7.fhir.r4.model.Coding) DateType(org.hl7.fhir.r4.model.DateType) Test(org.junit.jupiter.api.Test)

Example 45 with DateType

use of org.hl7.fhir.r5.model.DateType in project beneficiary-fhir-data by CMSgov.

the class CoverageTransformerV2Test method verifyCommonExtensions.

private static void verifyCommonExtensions() {
    // ms_cd
    verifyCodedExtension("https://bluebutton.cms.gov/resources/variables/ms_cd", "20", "Disabled without ESRD");
    // rfrnc_yr
    Extension ex = TransformerTestUtilsV2.findExtensionByUrl("https://bluebutton.cms.gov/resources/variables/rfrnc_yr", coverage.getExtension());
    Extension compare = new Extension("https://bluebutton.cms.gov/resources/variables/rfrnc_yr", new DateType("2018"));
    assertTrue(compare.equalsDeep(ex));
    // dual_01 thru dual_12
    for (int i = 1; i < 13; i++) {
        String url = String.format("https://bluebutton.cms.gov/resources/variables/dual_%02d", i);
        verifyCodedExtension(url, "**", "Enrolled in Medicare A and/or B, but no Part D enrollment data for the beneficiary. (This status was indicated as 'XX' for 2006-2009)");
    }
}
Also used : Extension(org.hl7.fhir.r4.model.Extension) DateType(org.hl7.fhir.r4.model.DateType)

Aggregations

DateType (org.hl7.fhir.r4.model.DateType)36 Test (org.junit.jupiter.api.Test)21 Date (java.util.Date)17 Coding (org.hl7.fhir.r4.model.Coding)15 Test (org.junit.Test)11 SupportingInformationComponent (org.hl7.fhir.r4.model.ExplanationOfBenefit.SupportingInformationComponent)10 DateType (org.hl7.fhir.r4b.model.DateType)10 FHIRException (org.hl7.fhir.exceptions.FHIRException)9 ArrayList (java.util.ArrayList)8 DateType (org.hl7.fhir.r5.model.DateType)8 DateType (org.hl7.fhir.dstu3.model.DateType)7 Extension (org.hl7.fhir.r4.model.Extension)6 Calendar (java.util.Calendar)5 DisplayName (org.junit.jupiter.api.DisplayName)5 InvalidRifValueException (gov.cms.bfd.model.rif.parse.InvalidRifValueException)4 DateType (org.hl7.fhir.dstu2016may.model.DateType)4 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)4 DateTimeType (org.hl7.fhir.r4.model.DateTimeType)4 Patient (org.hl7.fhir.r4.model.Patient)4 Reference (org.hl7.fhir.r4.model.Reference)4