Search in sources :

Example 21 with ItemComponent

use of org.hl7.fhir.r4.model.ExplanationOfBenefit.ItemComponent in project synthea by synthetichealth.

the class FhirR4 method explanationOfBenefit.

/**
 * Create an explanation of benefit resource for each claim, detailing insurance
 * information.
 *
 * @param personEntry Entry for the person
 * @param bundle The Bundle to add to
 * @param encounterEntry The current Encounter
 * @param claimEntry the Claim object
 * @param person the person the health record belongs to
 * @param encounter the current Encounter as an object
 * @return the added entry
 */
private static BundleEntryComponent explanationOfBenefit(BundleEntryComponent personEntry, Bundle bundle, BundleEntryComponent encounterEntry, Person person, BundleEntryComponent claimEntry, Encounter encounter) {
    ExplanationOfBenefit eob = new ExplanationOfBenefit();
    eob.setStatus(org.hl7.fhir.r4.model.ExplanationOfBenefit.ExplanationOfBenefitStatus.ACTIVE);
    eob.setType(new CodeableConcept().addCoding(new Coding().setSystem("http://terminology.hl7.org/CodeSystem/claim-type").setCode("professional").setDisplay("Professional")));
    eob.setUse(Use.CLAIM);
    eob.setOutcome(RemittanceOutcome.COMPLETE);
    org.hl7.fhir.r4.model.Encounter encounterResource = (org.hl7.fhir.r4.model.Encounter) encounterEntry.getResource();
    // according to CMS guidelines claims have 12 months to be
    // billed, so we set the billable period to 1 year after
    // services have ended (the encounter ends).
    Calendar cal = Calendar.getInstance();
    cal.setTime(encounterResource.getPeriod().getEnd());
    cal.add(Calendar.YEAR, 1);
    Period billablePeriod = new Period().setStart(encounterResource.getPeriod().getEnd()).setEnd(cal.getTime());
    eob.setBillablePeriod(billablePeriod);
    // cost is hardcoded to be USD in claim so this should be fine as well
    Money totalCost = new Money();
    totalCost.setCurrency("USD");
    totalCost.setValue(encounter.claim.getTotalClaimCost());
    TotalComponent total = eob.addTotal();
    total.setAmount(totalCost);
    Code submitted = new Code("http://terminology.hl7.org/CodeSystem/adjudication", "submitted", "Submitted Amount");
    total.setCategory(mapCodeToCodeableConcept(submitted, "http://terminology.hl7.org/CodeSystem/adjudication"));
    // Set References
    eob.setPatient(new Reference(personEntry.getFullUrl()));
    if (USE_US_CORE_IG) {
        eob.setFacility(encounterResource.getLocationFirstRep().getLocation());
    }
    ServiceRequest referral = (ServiceRequest) new ServiceRequest().setStatus(ServiceRequest.ServiceRequestStatus.COMPLETED).setIntent(ServiceRequest.ServiceRequestIntent.ORDER).setSubject(new Reference(personEntry.getFullUrl())).setId("referral");
    CodeableConcept primaryCareRole = new CodeableConcept().addCoding(new Coding().setCode("primary").setSystem("http://terminology.hl7.org/CodeSystem/claimcareteamrole").setDisplay("Primary Care Practitioner"));
    Reference providerReference = new Reference().setDisplay("Unknown");
    if (encounter.clinician != null) {
        String practitionerFullUrl = TRANSACTION_BUNDLE ? ExportHelper.buildFhirNpiSearchUrl(encounter.clinician) : findPractitioner(encounter.clinician, bundle);
        if (practitionerFullUrl != null) {
            providerReference = new Reference(practitionerFullUrl);
        }
    } else if (encounter.provider != null) {
        String providerUrl = TRANSACTION_BUNDLE ? ExportHelper.buildFhirSearchUrl("Location", encounter.provider.getResourceLocationID()) : findProviderUrl(encounter.provider, bundle);
        if (providerUrl != null) {
            providerReference = new Reference(providerUrl);
        }
    }
    eob.setProvider(providerReference);
    eob.addCareTeam(new ExplanationOfBenefit.CareTeamComponent().setSequence(1).setProvider(providerReference).setRole(primaryCareRole));
    referral.setRequester(providerReference);
    referral.addPerformer(providerReference);
    eob.addContained(referral);
    eob.setReferral(new Reference().setReference("#referral"));
    // Get the insurance info at the time that the encounter occurred.
    Payer payer = encounter.claim.payer;
    Coverage coverage = new Coverage();
    coverage.setId("coverage");
    coverage.setStatus(CoverageStatus.ACTIVE);
    coverage.setType(new CodeableConcept().setText(payer.getName()));
    coverage.setBeneficiary(new Reference(personEntry.getFullUrl()));
    coverage.addPayor(new Reference().setDisplay(payer.getName()));
    eob.addContained(coverage);
    ExplanationOfBenefit.InsuranceComponent insuranceComponent = new ExplanationOfBenefit.InsuranceComponent();
    insuranceComponent.setFocal(true);
    insuranceComponent.setCoverage(new Reference("#coverage").setDisplay(payer.getName()));
    eob.addInsurance(insuranceComponent);
    eob.setInsurer(new Reference().setDisplay(payer.getName()));
    org.hl7.fhir.r4.model.Claim claim = (org.hl7.fhir.r4.model.Claim) claimEntry.getResource();
    eob.addIdentifier().setSystem("https://bluebutton.cms.gov/resources/variables/clm_id").setValue(claim.getId());
    // Hardcoded group id
    eob.addIdentifier().setSystem("https://bluebutton.cms.gov/resources/identifier/claim-group").setValue("99999999999");
    eob.setClaim(new Reference().setReference(claimEntry.getFullUrl()));
    eob.setCreated(encounterResource.getPeriod().getEnd());
    eob.setType(claim.getType());
    List<ExplanationOfBenefit.DiagnosisComponent> eobDiag = new ArrayList<>();
    for (org.hl7.fhir.r4.model.Claim.DiagnosisComponent claimDiagnosis : claim.getDiagnosis()) {
        ExplanationOfBenefit.DiagnosisComponent diagnosisComponent = new ExplanationOfBenefit.DiagnosisComponent();
        diagnosisComponent.setDiagnosis(claimDiagnosis.getDiagnosis());
        diagnosisComponent.getType().add(new CodeableConcept().addCoding(new Coding().setCode("principal").setSystem("http://terminology.hl7.org/CodeSystem/ex-diagnosistype")));
        diagnosisComponent.setSequence(claimDiagnosis.getSequence());
        diagnosisComponent.setPackageCode(claimDiagnosis.getPackageCode());
        eobDiag.add(diagnosisComponent);
    }
    eob.setDiagnosis(eobDiag);
    List<ExplanationOfBenefit.ProcedureComponent> eobProc = new ArrayList<>();
    for (ProcedureComponent proc : claim.getProcedure()) {
        ExplanationOfBenefit.ProcedureComponent p = new ExplanationOfBenefit.ProcedureComponent();
        p.setDate(proc.getDate());
        p.setSequence(proc.getSequence());
        p.setProcedure(proc.getProcedure());
    }
    eob.setProcedure(eobProc);
    List<ExplanationOfBenefit.ItemComponent> eobItem = new ArrayList<>();
    double totalPayment = 0;
    // Get all the items info from the claim
    for (ItemComponent item : claim.getItem()) {
        ExplanationOfBenefit.ItemComponent itemComponent = new ExplanationOfBenefit.ItemComponent();
        itemComponent.setSequence(item.getSequence());
        itemComponent.setQuantity(item.getQuantity());
        itemComponent.setUnitPrice(item.getUnitPrice());
        itemComponent.setCareTeamSequence(item.getCareTeamSequence());
        itemComponent.setDiagnosisSequence(item.getDiagnosisSequence());
        itemComponent.setInformationSequence(item.getInformationSequence());
        itemComponent.setNet(item.getNet());
        itemComponent.setEncounter(item.getEncounter());
        itemComponent.setServiced(encounterResource.getPeriod());
        itemComponent.setCategory(new CodeableConcept().addCoding(new Coding().setSystem("https://bluebutton.cms.gov/resources/variables/line_cms_type_srvc_cd").setCode("1").setDisplay("Medical care")));
        itemComponent.setProductOrService(item.getProductOrService());
        // Location of service, can use switch statement based on
        // encounter type
        String code;
        String display;
        CodeableConcept location = new CodeableConcept();
        EncounterType encounterType = EncounterType.fromString(encounter.type);
        switch(encounterType) {
            case AMBULATORY:
                code = "21";
                display = "Inpatient Hospital";
                break;
            case EMERGENCY:
                code = "20";
                display = "Urgent Care Facility";
                break;
            case INPATIENT:
                code = "21";
                display = "Inpatient Hospital";
                break;
            case URGENTCARE:
                code = "20";
                display = "Urgent Care Facility";
                break;
            case WELLNESS:
                code = "19";
                display = "Off Campus-Outpatient Hospital";
                break;
            default:
                code = "21";
                display = "Inpatient Hospital";
        }
        location.addCoding().setCode(code).setSystem("http://terminology.hl7.org/CodeSystem/ex-serviceplace").setDisplay(display);
        itemComponent.setLocation(location);
        // Adjudication
        if (item.hasNet()) {
            // Assume that the patient has already paid deductible and
            // has 20/80 coinsurance
            ExplanationOfBenefit.AdjudicationComponent coinsuranceAmount = new ExplanationOfBenefit.AdjudicationComponent();
            coinsuranceAmount.getCategory().getCoding().add(new Coding().setCode("https://bluebutton.cms.gov/resources/variables/line_coinsrnc_amt").setSystem("https://bluebutton.cms.gov/resources/codesystem/adjudication").setDisplay("Line Beneficiary Coinsurance Amount"));
            coinsuranceAmount.getAmount().setValue(// 20% coinsurance
            0.2 * item.getNet().getValue().doubleValue()).setCurrency("USD");
            ExplanationOfBenefit.AdjudicationComponent lineProviderAmount = new ExplanationOfBenefit.AdjudicationComponent();
            lineProviderAmount.getCategory().getCoding().add(new Coding().setCode("https://bluebutton.cms.gov/resources/variables/line_prvdr_pmt_amt").setSystem("https://bluebutton.cms.gov/resources/codesystem/adjudication").setDisplay("Line Provider Payment Amount"));
            lineProviderAmount.getAmount().setValue(0.8 * item.getNet().getValue().doubleValue()).setCurrency("USD");
            // assume the allowed and submitted amounts are the same for now
            ExplanationOfBenefit.AdjudicationComponent submittedAmount = new ExplanationOfBenefit.AdjudicationComponent();
            submittedAmount.getCategory().getCoding().add(new Coding().setCode("https://bluebutton.cms.gov/resources/variables/line_sbmtd_chrg_amt").setSystem("https://bluebutton.cms.gov/resources/codesystem/adjudication").setDisplay("Line Submitted Charge Amount"));
            submittedAmount.getAmount().setValue(item.getNet().getValue()).setCurrency("USD");
            ExplanationOfBenefit.AdjudicationComponent allowedAmount = new ExplanationOfBenefit.AdjudicationComponent();
            allowedAmount.getCategory().getCoding().add(new Coding().setCode("https://bluebutton.cms.gov/resources/variables/line_alowd_chrg_amt").setSystem("https://bluebutton.cms.gov/resources/codesystem/adjudication").setDisplay("Line Allowed Charge Amount"));
            allowedAmount.getAmount().setValue(item.getNet().getValue()).setCurrency("USD");
            ExplanationOfBenefit.AdjudicationComponent indicatorCode = new ExplanationOfBenefit.AdjudicationComponent();
            indicatorCode.getCategory().getCoding().add(new Coding().setCode("https://bluebutton.cms.gov/resources/variables/line_prcsg_ind_cd").setSystem("https://bluebutton.cms.gov/resources/codesystem/adjudication").setDisplay("Line Processing Indicator Code"));
            // assume deductible is 0
            ExplanationOfBenefit.AdjudicationComponent deductibleAmount = new ExplanationOfBenefit.AdjudicationComponent();
            deductibleAmount.getCategory().getCoding().add(new Coding().setCode("https://bluebutton.cms.gov/resources/variables/line_bene_ptb_ddctbl_amt").setSystem("https://bluebutton.cms.gov/resources/codesystem/adjudication").setDisplay("Line Beneficiary Part B Deductible Amount"));
            deductibleAmount.getAmount().setValue(0).setCurrency("USD");
            List<ExplanationOfBenefit.AdjudicationComponent> adjudicationComponents = new ArrayList<>();
            adjudicationComponents.add(coinsuranceAmount);
            adjudicationComponents.add(lineProviderAmount);
            adjudicationComponents.add(submittedAmount);
            adjudicationComponents.add(allowedAmount);
            adjudicationComponents.add(deductibleAmount);
            adjudicationComponents.add(indicatorCode);
            itemComponent.setAdjudication(adjudicationComponents);
            // the total payment is what the insurance ends up paying
            totalPayment += 0.8 * item.getNet().getValue().doubleValue();
        }
        eobItem.add(itemComponent);
    }
    eob.setItem(eobItem);
    // This will throw a validation error no matter what.  The
    // payment section is required, and it requires a value.
    // The validator will complain that if there is a value, the payment
    // needs a code, but it will also complain if there is a code.
    // There is no way to resolve this error.
    Money payment = new Money();
    payment.setValue(totalPayment).setCurrency("USD");
    eob.setPayment(new ExplanationOfBenefit.PaymentComponent().setAmount(payment));
    return newEntry(person, bundle, eob);
}
Also used : TotalComponent(org.hl7.fhir.r4.model.ExplanationOfBenefit.TotalComponent) DiagnosisComponent(org.hl7.fhir.r4.model.Claim.DiagnosisComponent) ArrayList(java.util.ArrayList) ExplanationOfBenefit(org.hl7.fhir.r4.model.ExplanationOfBenefit) ProcedureComponent(org.hl7.fhir.r4.model.Claim.ProcedureComponent) Money(org.hl7.fhir.r4.model.Money) Coding(org.hl7.fhir.r4.model.Coding) SupplyDeliverySuppliedItemComponent(org.hl7.fhir.r4.model.SupplyDelivery.SupplyDeliverySuppliedItemComponent) ItemComponent(org.hl7.fhir.r4.model.Claim.ItemComponent) DiagnosisComponent(org.hl7.fhir.r4.model.Claim.DiagnosisComponent) Encounter(org.mitre.synthea.world.concepts.HealthRecord.Encounter) Payer(org.mitre.synthea.world.agents.Payer) Reference(org.hl7.fhir.r4.model.Reference) DocumentReference(org.hl7.fhir.r4.model.DocumentReference) Calendar(java.util.Calendar) Period(org.hl7.fhir.r4.model.Period) Coverage(org.hl7.fhir.r4.model.Coverage) InsuranceComponent(org.hl7.fhir.r4.model.Claim.InsuranceComponent) Code(org.mitre.synthea.world.concepts.HealthRecord.Code) ServiceRequest(org.hl7.fhir.r4.model.ServiceRequest) EncounterType(org.mitre.synthea.world.concepts.HealthRecord.EncounterType) Claim(org.mitre.synthea.world.concepts.Claim) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept)

Example 22 with ItemComponent

use of org.hl7.fhir.r4.model.ExplanationOfBenefit.ItemComponent in project synthea by synthetichealth.

the class FhirR4 method medicationClaim.

/**
 * Create an entry for the given Claim, which references a Medication.
 *
 * @param person         The person being prescribed medication
 * @param personEntry     Entry for the person
 * @param bundle          The Bundle to add to
 * @param encounterEntry  The current Encounter
 * @param claim           the Claim object
 * @param medicationEntry The Entry for the Medication object, previously created
 * @return the added Entry
 */
private static BundleEntryComponent medicationClaim(Person person, BundleEntryComponent personEntry, Bundle bundle, BundleEntryComponent encounterEntry, Claim claim, BundleEntryComponent medicationEntry) {
    org.hl7.fhir.r4.model.Claim claimResource = new org.hl7.fhir.r4.model.Claim();
    org.hl7.fhir.r4.model.Encounter encounterResource = (org.hl7.fhir.r4.model.Encounter) encounterEntry.getResource();
    claimResource.setStatus(ClaimStatus.ACTIVE);
    CodeableConcept type = new CodeableConcept();
    type.getCodingFirstRep().setSystem("http://terminology.hl7.org/CodeSystem/claim-type").setCode("pharmacy");
    claimResource.setType(type);
    claimResource.setUse(org.hl7.fhir.r4.model.Claim.Use.CLAIM);
    // Get the insurance info at the time that the encounter occurred.
    InsuranceComponent insuranceComponent = new InsuranceComponent();
    insuranceComponent.setSequence(1);
    insuranceComponent.setFocal(true);
    insuranceComponent.setCoverage(new Reference().setDisplay(claim.payer.getName()));
    claimResource.addInsurance(insuranceComponent);
    // duration of encounter
    claimResource.setBillablePeriod(encounterResource.getPeriod());
    claimResource.setCreated(encounterResource.getPeriod().getEnd());
    claimResource.setPatient(new Reference(personEntry.getFullUrl()));
    claimResource.setProvider(encounterResource.getServiceProvider());
    // set the required priority
    CodeableConcept priority = new CodeableConcept();
    priority.getCodingFirstRep().setSystem("http://terminology.hl7.org/CodeSystem/processpriority").setCode("normal");
    claimResource.setPriority(priority);
    // add item for encounter
    claimResource.addItem(new ItemComponent(new PositiveIntType(1), encounterResource.getTypeFirstRep()).addEncounter(new Reference(encounterEntry.getFullUrl())));
    // add prescription.
    claimResource.setPrescription(new Reference(medicationEntry.getFullUrl()));
    Money moneyResource = new Money();
    moneyResource.setValue(claim.getTotalClaimCost());
    moneyResource.setCurrency("USD");
    claimResource.setTotal(moneyResource);
    return newEntry(person, bundle, claimResource);
}
Also used : Reference(org.hl7.fhir.r4.model.Reference) DocumentReference(org.hl7.fhir.r4.model.DocumentReference) InsuranceComponent(org.hl7.fhir.r4.model.Claim.InsuranceComponent) PositiveIntType(org.hl7.fhir.r4.model.PositiveIntType) Money(org.hl7.fhir.r4.model.Money) SupplyDeliverySuppliedItemComponent(org.hl7.fhir.r4.model.SupplyDelivery.SupplyDeliverySuppliedItemComponent) ItemComponent(org.hl7.fhir.r4.model.Claim.ItemComponent) Encounter(org.mitre.synthea.world.concepts.HealthRecord.Encounter) Claim(org.mitre.synthea.world.concepts.Claim) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept)

Example 23 with ItemComponent

use of org.hl7.fhir.r4.model.ExplanationOfBenefit.ItemComponent 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 24 with ItemComponent

use of org.hl7.fhir.r4.model.ExplanationOfBenefit.ItemComponent in project beneficiary-fhir-data by CMSgov.

the class SNFClaimTransformer method transformClaim.

/**
 * @param claimGroup the CCW {@link SNFClaim} to transform
 * @return a FHIR {@link ExplanationOfBenefit} resource that represents the specified {@link
 *     SNFClaim}
 */
private static ExplanationOfBenefit transformClaim(SNFClaim claimGroup) {
    ExplanationOfBenefit eob = new ExplanationOfBenefit();
    // Common group level fields between all claim types
    TransformerUtils.mapEobCommonClaimHeaderData(eob, claimGroup.getClaimId(), claimGroup.getBeneficiaryId(), ClaimType.SNF, claimGroup.getClaimGroupId().toPlainString(), MedicareSegment.PART_A, Optional.of(claimGroup.getDateFrom()), Optional.of(claimGroup.getDateThrough()), Optional.of(claimGroup.getPaymentAmount()), claimGroup.getFinalAction());
    TransformerUtils.mapEobWeeklyProcessDate(eob, claimGroup.getWeeklyProcessDate());
    // map eob type codes into FHIR
    TransformerUtils.mapEobType(eob, ClaimType.SNF, Optional.of(claimGroup.getNearLineRecordIdCode()), Optional.of(claimGroup.getClaimTypeCode()));
    // set the provider number which is common among several claim types
    TransformerUtils.setProviderNumber(eob, claimGroup.getProviderNumber());
    // add EOB information to fields that are common between the Inpatient and SNF claim types
    TransformerUtils.addCommonEobInformationInpatientSNF(eob, claimGroup.getAdmissionTypeCd(), claimGroup.getSourceAdmissionCd(), claimGroup.getNoncoveredStayFromDate(), claimGroup.getNoncoveredStayThroughDate(), claimGroup.getCoveredCareThroughDate(), claimGroup.getMedicareBenefitsExhaustedDate(), claimGroup.getDiagnosisRelatedGroupCd());
    if (claimGroup.getPatientStatusCd().isPresent()) {
        TransformerUtils.addInformationWithCode(eob, CcwCodebookVariable.NCH_PTNT_STUS_IND_CD, CcwCodebookVariable.NCH_PTNT_STUS_IND_CD, claimGroup.getPatientStatusCd().get());
    }
    // Common group level fields between Inpatient, HHA, Hospice and SNF
    TransformerUtils.mapEobCommonGroupInpHHAHospiceSNF(eob, claimGroup.getClaimAdmissionDate(), claimGroup.getBeneficiaryDischargeDate(), Optional.of(claimGroup.getUtilizationDayCount()));
    /*
     * add field values to the benefit balances that are common between the
     * Inpatient and SNF claim types
     */
    TransformerUtils.addCommonGroupInpatientSNF(eob, claimGroup.getCoinsuranceDayCount(), claimGroup.getNonUtilizationDayCount(), claimGroup.getDeductibleAmount(), claimGroup.getPartACoinsuranceLiabilityAmount(), claimGroup.getBloodPintsFurnishedQty(), claimGroup.getNoncoveredCharge(), claimGroup.getTotalDeductionAmount(), claimGroup.getClaimPPSCapitalDisproportionateShareAmt(), claimGroup.getClaimPPSCapitalExceptionAmount(), claimGroup.getClaimPPSCapitalFSPAmount(), claimGroup.getClaimPPSCapitalIMEAmount(), claimGroup.getClaimPPSCapitalOutlierAmount(), claimGroup.getClaimPPSOldCapitalHoldHarmlessAmount());
    if (claimGroup.getQualifiedStayFromDate().isPresent() || claimGroup.getQualifiedStayThroughDate().isPresent()) {
        TransformerUtils.validatePeriodDates(claimGroup.getQualifiedStayFromDate(), claimGroup.getQualifiedStayThroughDate());
        SupportingInformationComponent nchQlfydStayInfo = TransformerUtils.addInformation(eob, CcwCodebookVariable.NCH_QLFYD_STAY_FROM_DT);
        Period nchQlfydStayPeriod = new Period();
        if (claimGroup.getQualifiedStayFromDate().isPresent())
            nchQlfydStayPeriod.setStart(TransformerUtils.convertToDate((claimGroup.getQualifiedStayFromDate().get())), TemporalPrecisionEnum.DAY);
        if (claimGroup.getQualifiedStayThroughDate().isPresent())
            nchQlfydStayPeriod.setEnd(TransformerUtils.convertToDate((claimGroup.getQualifiedStayThroughDate().get())), TemporalPrecisionEnum.DAY);
        nchQlfydStayInfo.setTiming(nchQlfydStayPeriod);
    }
    // Common group level fields between Inpatient, Outpatient and SNF
    TransformerUtils.mapEobCommonGroupInpOutSNF(eob, claimGroup.getBloodDeductibleLiabilityAmount(), claimGroup.getOperatingPhysicianNpi(), claimGroup.getOtherPhysicianNpi(), claimGroup.getClaimQueryCode(), claimGroup.getMcoPaidSw());
    // Common group level fields between Inpatient, Outpatient Hospice, HHA and SNF
    TransformerUtils.mapEobCommonGroupInpOutHHAHospiceSNF(eob, claimGroup.getOrganizationNpi(), claimGroup.getClaimFacilityTypeCode(), claimGroup.getClaimFrequencyCode(), claimGroup.getClaimNonPaymentReasonCode(), claimGroup.getPatientDischargeStatusCode(), claimGroup.getClaimServiceClassificationTypeCode(), claimGroup.getClaimPrimaryPayerCode(), claimGroup.getAttendingPhysicianNpi(), claimGroup.getTotalChargeAmount(), claimGroup.getPrimaryPayerPaidAmount(), claimGroup.getFiscalIntermediaryNumber(), claimGroup.getFiDocumentClaimControlNumber(), claimGroup.getFiOriginalClaimControlNumber());
    for (Diagnosis diagnosis : TransformerUtils.extractDiagnoses1Thru12(claimGroup.getDiagnosisAdmittingCode(), claimGroup.getDiagnosisAdmittingCodeVersion(), claimGroup.getDiagnosisPrincipalCode(), claimGroup.getDiagnosisPrincipalCodeVersion(), claimGroup.getDiagnosis1Code(), claimGroup.getDiagnosis1CodeVersion(), claimGroup.getDiagnosis2Code(), claimGroup.getDiagnosis2CodeVersion(), claimGroup.getDiagnosis3Code(), claimGroup.getDiagnosis3CodeVersion(), claimGroup.getDiagnosis4Code(), claimGroup.getDiagnosis4CodeVersion(), claimGroup.getDiagnosis5Code(), claimGroup.getDiagnosis5CodeVersion(), claimGroup.getDiagnosis6Code(), claimGroup.getDiagnosis6CodeVersion(), claimGroup.getDiagnosis7Code(), claimGroup.getDiagnosis7CodeVersion(), claimGroup.getDiagnosis8Code(), claimGroup.getDiagnosis8CodeVersion(), claimGroup.getDiagnosis9Code(), claimGroup.getDiagnosis9CodeVersion(), claimGroup.getDiagnosis10Code(), claimGroup.getDiagnosis10CodeVersion(), claimGroup.getDiagnosis11Code(), claimGroup.getDiagnosis11CodeVersion(), claimGroup.getDiagnosis12Code(), claimGroup.getDiagnosis12CodeVersion())) TransformerUtils.addDiagnosisCode(eob, diagnosis);
    for (Diagnosis diagnosis : TransformerUtils.extractDiagnoses13Thru25(claimGroup.getDiagnosis13Code(), claimGroup.getDiagnosis13CodeVersion(), claimGroup.getDiagnosis14Code(), claimGroup.getDiagnosis14CodeVersion(), claimGroup.getDiagnosis15Code(), claimGroup.getDiagnosis15CodeVersion(), claimGroup.getDiagnosis16Code(), claimGroup.getDiagnosis16CodeVersion(), claimGroup.getDiagnosis17Code(), claimGroup.getDiagnosis17CodeVersion(), claimGroup.getDiagnosis18Code(), claimGroup.getDiagnosis18CodeVersion(), claimGroup.getDiagnosis19Code(), claimGroup.getDiagnosis19CodeVersion(), claimGroup.getDiagnosis20Code(), claimGroup.getDiagnosis20CodeVersion(), claimGroup.getDiagnosis21Code(), claimGroup.getDiagnosis21CodeVersion(), claimGroup.getDiagnosis22Code(), claimGroup.getDiagnosis22CodeVersion(), claimGroup.getDiagnosis23Code(), claimGroup.getDiagnosis23CodeVersion(), claimGroup.getDiagnosis24Code(), claimGroup.getDiagnosis24CodeVersion(), claimGroup.getDiagnosis25Code(), claimGroup.getDiagnosis25CodeVersion())) TransformerUtils.addDiagnosisCode(eob, diagnosis);
    for (Diagnosis diagnosis : TransformerUtils.extractExternalDiagnoses1Thru12(claimGroup.getDiagnosisExternalFirstCode(), claimGroup.getDiagnosisExternalFirstCodeVersion(), claimGroup.getDiagnosisExternal1Code(), claimGroup.getDiagnosisExternal1CodeVersion(), claimGroup.getDiagnosisExternal2Code(), claimGroup.getDiagnosisExternal2CodeVersion(), claimGroup.getDiagnosisExternal3Code(), claimGroup.getDiagnosisExternal3CodeVersion(), claimGroup.getDiagnosisExternal4Code(), claimGroup.getDiagnosisExternal4CodeVersion(), claimGroup.getDiagnosisExternal5Code(), claimGroup.getDiagnosisExternal5CodeVersion(), claimGroup.getDiagnosisExternal6Code(), claimGroup.getDiagnosisExternal6CodeVersion(), claimGroup.getDiagnosisExternal7Code(), claimGroup.getDiagnosisExternal7CodeVersion(), claimGroup.getDiagnosisExternal8Code(), claimGroup.getDiagnosisExternal8CodeVersion(), claimGroup.getDiagnosisExternal9Code(), claimGroup.getDiagnosisExternal9CodeVersion(), claimGroup.getDiagnosisExternal10Code(), claimGroup.getDiagnosisExternal10CodeVersion(), claimGroup.getDiagnosisExternal11Code(), claimGroup.getDiagnosisExternal11CodeVersion(), claimGroup.getDiagnosisExternal12Code(), claimGroup.getDiagnosisExternal12CodeVersion())) TransformerUtils.addDiagnosisCode(eob, diagnosis);
    for (CCWProcedure procedure : TransformerUtils.extractCCWProcedures(claimGroup.getProcedure1Code(), claimGroup.getProcedure1CodeVersion(), claimGroup.getProcedure1Date(), claimGroup.getProcedure2Code(), claimGroup.getProcedure2CodeVersion(), claimGroup.getProcedure2Date(), claimGroup.getProcedure3Code(), claimGroup.getProcedure3CodeVersion(), claimGroup.getProcedure3Date(), claimGroup.getProcedure4Code(), claimGroup.getProcedure4CodeVersion(), claimGroup.getProcedure4Date(), claimGroup.getProcedure5Code(), claimGroup.getProcedure5CodeVersion(), claimGroup.getProcedure5Date(), claimGroup.getProcedure6Code(), claimGroup.getProcedure6CodeVersion(), claimGroup.getProcedure6Date(), claimGroup.getProcedure7Code(), claimGroup.getProcedure7CodeVersion(), claimGroup.getProcedure7Date(), claimGroup.getProcedure8Code(), claimGroup.getProcedure8CodeVersion(), claimGroup.getProcedure8Date(), claimGroup.getProcedure9Code(), claimGroup.getProcedure9CodeVersion(), claimGroup.getProcedure9Date(), claimGroup.getProcedure10Code(), claimGroup.getProcedure10CodeVersion(), claimGroup.getProcedure10Date(), claimGroup.getProcedure11Code(), claimGroup.getProcedure11CodeVersion(), claimGroup.getProcedure11Date(), claimGroup.getProcedure12Code(), claimGroup.getProcedure12CodeVersion(), claimGroup.getProcedure12Date(), claimGroup.getProcedure13Code(), claimGroup.getProcedure13CodeVersion(), claimGroup.getProcedure13Date(), claimGroup.getProcedure14Code(), claimGroup.getProcedure14CodeVersion(), claimGroup.getProcedure14Date(), claimGroup.getProcedure15Code(), claimGroup.getProcedure15CodeVersion(), claimGroup.getProcedure15Date(), claimGroup.getProcedure16Code(), claimGroup.getProcedure16CodeVersion(), claimGroup.getProcedure16Date(), claimGroup.getProcedure17Code(), claimGroup.getProcedure17CodeVersion(), claimGroup.getProcedure17Date(), claimGroup.getProcedure18Code(), claimGroup.getProcedure18CodeVersion(), claimGroup.getProcedure18Date(), claimGroup.getProcedure19Code(), claimGroup.getProcedure19CodeVersion(), claimGroup.getProcedure19Date(), claimGroup.getProcedure20Code(), claimGroup.getProcedure20CodeVersion(), claimGroup.getProcedure20Date(), claimGroup.getProcedure21Code(), claimGroup.getProcedure21CodeVersion(), claimGroup.getProcedure21Date(), claimGroup.getProcedure22Code(), claimGroup.getProcedure22CodeVersion(), claimGroup.getProcedure22Date(), claimGroup.getProcedure23Code(), claimGroup.getProcedure23CodeVersion(), claimGroup.getProcedure23Date(), claimGroup.getProcedure24Code(), claimGroup.getProcedure24CodeVersion(), claimGroup.getProcedure24Date(), claimGroup.getProcedure25Code(), claimGroup.getProcedure25CodeVersion(), claimGroup.getProcedure25Date())) TransformerUtils.addProcedureCode(eob, procedure);
    for (SNFClaimLine claimLine : claimGroup.getLines()) {
        ItemComponent item = eob.addItem();
        item.setSequence(claimLine.getLineNumber().intValue());
        item.setLocation(new Address().setState((claimGroup.getProviderStateCode())));
        TransformerUtils.mapHcpcs(eob, item, Optional.empty(), claimLine.getHcpcsCode(), Collections.emptyList());
        // Common item level fields between Inpatient, Outpatient, HHA, Hospice and SNF
        TransformerUtils.mapEobCommonItemRevenue(item, eob, claimLine.getRevenueCenter(), claimLine.getRateAmount(), claimLine.getTotalChargeAmount(), claimLine.getNonCoveredChargeAmount(), BigDecimal.valueOf(claimLine.getUnitCount()), claimLine.getNationalDrugCodeQuantity(), claimLine.getNationalDrugCodeQualifierCode(), claimLine.getRevenueCenterRenderingPhysicianNPI());
        // Common group level field coinsurance between Inpatient, HHA, Hospice and SNF
        TransformerUtils.mapEobCommonGroupInpHHAHospiceSNFCoinsurance(eob, item, claimLine.getDeductibleCoinsuranceCd());
    }
    TransformerUtils.setLastUpdated(eob, claimGroup.getLastUpdated());
    return eob;
}
Also used : SupportingInformationComponent(org.hl7.fhir.dstu3.model.ExplanationOfBenefit.SupportingInformationComponent) SNFClaimLine(gov.cms.bfd.model.rif.SNFClaimLine) Address(org.hl7.fhir.dstu3.model.Address) CCWProcedure(gov.cms.bfd.server.war.commons.CCWProcedure) ItemComponent(org.hl7.fhir.dstu3.model.ExplanationOfBenefit.ItemComponent) Period(org.hl7.fhir.dstu3.model.Period) Diagnosis(gov.cms.bfd.server.war.commons.Diagnosis) ExplanationOfBenefit(org.hl7.fhir.dstu3.model.ExplanationOfBenefit)

Example 25 with ItemComponent

use of org.hl7.fhir.r4.model.ExplanationOfBenefit.ItemComponent in project beneficiary-fhir-data by CMSgov.

the class TransformerUtils method mapEobCommonItemCarrierDME.

/**
 * Transforms the common item level data elements between the {@link CarrierClaimLine} and {@link
 * DMEClaimLine} claim types to FHIR. The method parameter fields from {@link CarrierClaimLine}
 * and {@link DMEClaimLine} are listed below and their corresponding RIF CCW fields (denoted in
 * all CAPS below from {@link CarrierClaimColumn} and {@link DMEClaimColumn}).
 *
 * @param item the {@ ItemComponent} to modify
 * @param eob the {@ ExplanationOfBenefit} to modify
 * @param claimId CLM_ID,
 * @param serviceCount LINE_SRVC_CNT,
 * @param placeOfServiceCode LINE_PLACE_OF_SRVC_CD,
 * @param firstExpenseDate LINE_1ST_EXPNS_DT,
 * @param lastExpenseDate LINE_LAST_EXPNS_DT,
 * @param beneficiaryPaymentAmount LINE_BENE_PMT_AMT,
 * @param providerPaymentAmount LINE_PRVDR_PMT_AMT,
 * @param beneficiaryPartBDeductAmount LINE_BENE_PTB_DDCTBL_AMT,
 * @param primaryPayerCode LINE_BENE_PRMRY_PYR_CD,
 * @param primaryPayerPaidAmount LINE_BENE_PRMRY_PYR_PD_AMT,
 * @param betosCode BETOS_CD,
 * @param paymentAmount LINE_NCH_PMT_AMT,
 * @param paymentCode LINE_PMT_80_100_CD,
 * @param coinsuranceAmount LINE_COINSRNC_AMT,
 * @param submittedChargeAmount LINE_SBMTD_CHRG_AMT,
 * @param allowedChargeAmount LINE_ALOWD_CHRG_AMT,
 * @param processingIndicatorCode LINE_PRCSG_IND_CD,
 * @param serviceDeductibleCode LINE_SERVICE_DEDUCTIBLE,
 * @param diagnosisCode LINE_ICD_DGNS_CD,
 * @param diagnosisCodeVersion LINE_ICD_DGNS_VRSN_CD,
 * @param hctHgbTestTypeCode LINE_HCT_HGB_TYPE_CD
 * @param hctHgbTestResult LINE_HCT_HGB_RSLT_NUM,
 * @param cmsServiceTypeCode LINE_CMS_TYPE_SRVC_CD,
 * @param nationalDrugCode LINE_NDC_CD,
 * @param beneficiaryId BENE_ID,
 * @param referringPhysicianNpi RFR_PHYSN_NPI
 * @return the {@link ItemComponent}
 */
static ItemComponent mapEobCommonItemCarrierDME(ItemComponent item, ExplanationOfBenefit eob, String claimId, BigDecimal serviceCount, String placeOfServiceCode, Optional<LocalDate> firstExpenseDate, Optional<LocalDate> lastExpenseDate, BigDecimal beneficiaryPaymentAmount, BigDecimal providerPaymentAmount, BigDecimal beneficiaryPartBDeductAmount, Optional<Character> primaryPayerCode, BigDecimal primaryPayerPaidAmount, Optional<String> betosCode, BigDecimal paymentAmount, Optional<Character> paymentCode, BigDecimal coinsuranceAmount, BigDecimal submittedChargeAmount, BigDecimal allowedChargeAmount, Optional<String> processingIndicatorCode, Optional<Character> serviceDeductibleCode, Optional<String> diagnosisCode, Optional<Character> diagnosisCodeVersion, Optional<String> hctHgbTestTypeCode, BigDecimal hctHgbTestResult, char cmsServiceTypeCode, Optional<String> nationalDrugCode) {
    SimpleQuantity serviceCnt = new SimpleQuantity();
    serviceCnt.setValue(serviceCount);
    item.setQuantity(serviceCnt);
    item.setCategory(createCodeableConcept(eob, CcwCodebookVariable.LINE_CMS_TYPE_SRVC_CD, cmsServiceTypeCode));
    item.setLocation(createCodeableConcept(eob, CcwCodebookVariable.LINE_PLACE_OF_SRVC_CD, placeOfServiceCode));
    if (betosCode.isPresent()) {
        item.addExtension(createExtensionCoding(eob, CcwCodebookVariable.BETOS_CD, betosCode));
    }
    if (firstExpenseDate.isPresent() && lastExpenseDate.isPresent()) {
        validatePeriodDates(firstExpenseDate, lastExpenseDate);
        item.setServiced(new Period().setStart((convertToDate(firstExpenseDate.get())), TemporalPrecisionEnum.DAY).setEnd((convertToDate(lastExpenseDate.get())), TemporalPrecisionEnum.DAY));
    }
    AdjudicationComponent adjudicationForPayment = item.addAdjudication();
    adjudicationForPayment.setCategory(createAdjudicationCategory(CcwCodebookVariable.LINE_NCH_PMT_AMT)).setAmount(createMoney(paymentAmount));
    if (paymentCode.isPresent())
        adjudicationForPayment.addExtension(createExtensionCoding(eob, CcwCodebookVariable.LINE_PMT_80_100_CD, paymentCode));
    item.addAdjudication().setCategory(createAdjudicationCategory(CcwCodebookVariable.LINE_BENE_PMT_AMT)).setAmount(createMoney(beneficiaryPaymentAmount));
    item.addAdjudication().setCategory(createAdjudicationCategory(CcwCodebookVariable.LINE_PRVDR_PMT_AMT)).setAmount(createMoney(providerPaymentAmount));
    item.addAdjudication().setCategory(TransformerUtils.createAdjudicationCategory(CcwCodebookVariable.LINE_BENE_PTB_DDCTBL_AMT)).setAmount(createMoney(beneficiaryPartBDeductAmount));
    if (primaryPayerCode.isPresent()) {
        item.addExtension(createExtensionCoding(eob, CcwCodebookVariable.LINE_BENE_PRMRY_PYR_CD, primaryPayerCode));
    }
    item.addAdjudication().setCategory(createAdjudicationCategory(CcwCodebookVariable.LINE_BENE_PRMRY_PYR_PD_AMT)).setAmount(createMoney(primaryPayerPaidAmount));
    item.addAdjudication().setCategory(TransformerUtils.createAdjudicationCategory(CcwCodebookVariable.LINE_COINSRNC_AMT)).setAmount(createMoney(coinsuranceAmount));
    item.addAdjudication().setCategory(createAdjudicationCategory(CcwCodebookVariable.LINE_SBMTD_CHRG_AMT)).setAmount(createMoney(submittedChargeAmount));
    item.addAdjudication().setCategory(TransformerUtils.createAdjudicationCategory(CcwCodebookVariable.LINE_ALOWD_CHRG_AMT)).setAmount(createMoney(allowedChargeAmount));
    if (processingIndicatorCode.isPresent())
        item.addAdjudication(createAdjudicationWithReason(eob, CcwCodebookVariable.LINE_PRCSG_IND_CD, processingIndicatorCode));
    if (serviceDeductibleCode.isPresent())
        item.addExtension(createExtensionCoding(eob, CcwCodebookVariable.LINE_SERVICE_DEDUCTIBLE, serviceDeductibleCode));
    Optional<Diagnosis> lineDiagnosis = Diagnosis.from(diagnosisCode, diagnosisCodeVersion);
    if (lineDiagnosis.isPresent())
        addDiagnosisLink(eob, item, lineDiagnosis.get());
    if (hctHgbTestTypeCode.isPresent()) {
        Observation hctHgbObservation = new Observation();
        hctHgbObservation.setStatus(ObservationStatus.UNKNOWN);
        hctHgbObservation.setCode(createCodeableConcept(eob, CcwCodebookVariable.LINE_HCT_HGB_TYPE_CD, hctHgbTestTypeCode));
        hctHgbObservation.setValue(new Quantity().setValue(hctHgbTestResult));
        Extension hctHgbObservationReference = new Extension(CCWUtils.calculateVariableReferenceUrl(CcwCodebookVariable.LINE_HCT_HGB_RSLT_NUM), new Reference(hctHgbObservation));
        item.addExtension(hctHgbObservationReference);
    }
    if (nationalDrugCode.isPresent()) {
        addExtensionCoding(item, TransformerConstants.CODING_NDC, TransformerConstants.CODING_NDC, TransformerUtils.retrieveFDADrugCodeDisplay(nationalDrugCode.get()), nationalDrugCode.get());
    }
    return item;
}
Also used : IBaseExtension(org.hl7.fhir.instance.model.api.IBaseExtension) Extension(org.hl7.fhir.dstu3.model.Extension) AdjudicationComponent(org.hl7.fhir.dstu3.model.ExplanationOfBenefit.AdjudicationComponent) Reference(org.hl7.fhir.dstu3.model.Reference) SimpleQuantity(org.hl7.fhir.dstu3.model.SimpleQuantity) Observation(org.hl7.fhir.dstu3.model.Observation) Period(org.hl7.fhir.dstu3.model.Period) SimpleQuantity(org.hl7.fhir.dstu3.model.SimpleQuantity) Quantity(org.hl7.fhir.dstu3.model.Quantity) Diagnosis(gov.cms.bfd.server.war.commons.Diagnosis)

Aggregations

ItemComponent (org.hl7.fhir.dstu3.model.ExplanationOfBenefit.ItemComponent)17 Diagnosis (gov.cms.bfd.server.war.commons.Diagnosis)16 ExplanationOfBenefit (org.hl7.fhir.dstu3.model.ExplanationOfBenefit)10 BigDecimal (java.math.BigDecimal)9 ExplanationOfBenefit (org.hl7.fhir.r4.model.ExplanationOfBenefit)9 CCWProcedure (gov.cms.bfd.server.war.commons.CCWProcedure)8 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)8 ItemComponent (org.hl7.fhir.r4.model.ExplanationOfBenefit.ItemComponent)8 Reference (org.hl7.fhir.r4.model.Reference)6 CcwCodebookVariable (gov.cms.bfd.model.codebook.data.CcwCodebookVariable)5 MedicareSegment (gov.cms.bfd.server.war.commons.MedicareSegment)5 C4BBOrganizationIdentifierType (gov.cms.bfd.server.war.commons.carin.C4BBOrganizationIdentifierType)5 BadCodeMonkeyException (gov.cms.bfd.sharedutils.exceptions.BadCodeMonkeyException)5 Address (org.hl7.fhir.dstu3.model.Address)5 DMEClaimLine (gov.cms.bfd.model.rif.DMEClaimLine)4 HospiceClaimLine (gov.cms.bfd.model.rif.HospiceClaimLine)4 InvalidRifValueException (gov.cms.bfd.model.rif.parse.InvalidRifValueException)4 ProfileConstants (gov.cms.bfd.server.war.commons.ProfileConstants)4 C4BBClaimInstitutionalCareTeamRole (gov.cms.bfd.server.war.commons.carin.C4BBClaimInstitutionalCareTeamRole)4 C4BBPractitionerIdentifierType (gov.cms.bfd.server.war.commons.carin.C4BBPractitionerIdentifierType)4