Search in sources :

Example 71 with Money

use of org.hl7.fhir.r4b.model.Money in project synthea by synthetichealth.

the class FhirStu3 method createMoneyExtension.

/**
 * Create an extension in with a valueMoney in USD.
 * @param url The url of the extension.
 * @param value The value in USD.
 * @return the Extension
 */
private static Extension createMoneyExtension(String url, double value) {
    Money money = new Money();
    money.setValue(value);
    money.setSystem("urn:iso:std:iso:4217");
    money.setCode("USD");
    Extension extension = new Extension();
    extension.setUrl(url);
    extension.setValue(money);
    return extension;
}
Also used : Extension(org.hl7.fhir.dstu3.model.Extension) Money(org.hl7.fhir.dstu3.model.Money)

Example 72 with Money

use of org.hl7.fhir.r4b.model.Money in project synthea by synthetichealth.

the class FhirStu3 method encounterClaim.

/**
 * Create an entry for the given Claim, associated to an Encounter.
 *
 * @param rand Source of randomness to use when generating ids etc
 * @param personEntry Entry for the person
 * @param bundle The Bundle to add to
 * @param encounterEntry The current Encounter
 * @param claim the Claim object
 * @return the added Entry
 */
private static BundleEntryComponent encounterClaim(RandomNumberGenerator rand, BundleEntryComponent personEntry, Bundle bundle, BundleEntryComponent encounterEntry, Claim claim) {
    org.hl7.fhir.dstu3.model.Claim claimResource = new org.hl7.fhir.dstu3.model.Claim();
    org.hl7.fhir.dstu3.model.Encounter encounterResource = (org.hl7.fhir.dstu3.model.Encounter) encounterEntry.getResource();
    claimResource.setStatus(ClaimStatus.ACTIVE);
    claimResource.setUse(org.hl7.fhir.dstu3.model.Claim.Use.COMPLETE);
    // duration of encounter
    claimResource.setBillablePeriod(encounterResource.getPeriod());
    claimResource.setPatient(new Reference(personEntry.getFullUrl()));
    claimResource.setOrganization(encounterResource.getServiceProvider());
    // add item for encounter
    claimResource.addItem(new ItemComponent(new PositiveIntType(1)).addEncounter(new Reference(encounterEntry.getFullUrl())));
    int itemSequence = 2;
    int conditionSequence = 1;
    int procedureSequence = 1;
    int informationSequence = 1;
    for (Claim.ClaimEntry claimEntry : claim.items) {
        HealthRecord.Entry item = claimEntry.entry;
        if (Costs.hasCost(item)) {
            // update claimItems list
            ItemComponent claimItem = new ItemComponent(new PositiveIntType(itemSequence));
            Code primaryCode = item.codes.get(0);
            String system = ExportHelper.getSystemURI(primaryCode.system);
            CodeableConcept serviceProvided = new CodeableConcept().addCoding(new Coding().setCode(primaryCode.code).setVersion("v1").setSystem(system));
            claimItem.setService(serviceProvided);
            // calculate the cost of the procedure
            Money moneyResource = new Money();
            moneyResource.setCode("USD");
            moneyResource.setSystem("urn:iso:std:iso:4217");
            moneyResource.setValue(item.getCost());
            claimItem.setNet(moneyResource);
            if (item instanceof HealthRecord.Procedure) {
                Type procedureReference = new Reference(item.fullUrl);
                ProcedureComponent claimProcedure = new ProcedureComponent(new PositiveIntType(procedureSequence), procedureReference);
                claimResource.addProcedure(claimProcedure);
                claimItem.addProcedureLinkId(procedureSequence);
                procedureSequence++;
            } else {
                Reference informationReference = new Reference(item.fullUrl);
                SpecialConditionComponent informationComponent = new SpecialConditionComponent();
                informationComponent.setSequence(informationSequence);
                informationComponent.setValue(informationReference);
                CodeableConcept category = new CodeableConcept();
                category.getCodingFirstRep().setSystem("http://hl7.org/fhir/claiminformationcategory").setCode("info");
                informationComponent.setCategory(category);
                claimResource.addInformation(informationComponent);
                claimItem.addInformationLinkId(informationSequence);
                claimItem.setService(claimResource.getType());
                informationSequence++;
            }
            claimResource.addItem(claimItem);
        } else {
            // assume it's a Condition, we don't have a Condition class specifically
            // add diagnosisComponent to claim
            Reference diagnosisReference = new Reference(item.fullUrl);
            org.hl7.fhir.dstu3.model.Claim.DiagnosisComponent diagnosisComponent = new org.hl7.fhir.dstu3.model.Claim.DiagnosisComponent(new PositiveIntType(conditionSequence), diagnosisReference);
            claimResource.addDiagnosis(diagnosisComponent);
            // update claimItems with diagnosis
            ItemComponent diagnosisItem = new ItemComponent(new PositiveIntType(itemSequence));
            diagnosisItem.addDiagnosisLinkId(conditionSequence);
            claimResource.addItem(diagnosisItem);
            conditionSequence++;
        }
        itemSequence++;
    }
    Money moneyResource = new Money();
    moneyResource.setCode("USD");
    moneyResource.setSystem("urn:iso:std:iso:4217");
    moneyResource.setValue(claim.getTotalClaimCost());
    claimResource.setTotal(moneyResource);
    return newEntry(rand, bundle, claimResource);
}
Also used : ProcedureComponent(org.hl7.fhir.dstu3.model.Claim.ProcedureComponent) PositiveIntType(org.hl7.fhir.dstu3.model.PositiveIntType) Money(org.hl7.fhir.dstu3.model.Money) Coding(org.hl7.fhir.dstu3.model.Coding) ItemComponent(org.hl7.fhir.dstu3.model.Claim.ItemComponent) SupplyDeliverySuppliedItemComponent(org.hl7.fhir.dstu3.model.SupplyDelivery.SupplyDeliverySuppliedItemComponent) Encounter(org.mitre.synthea.world.concepts.HealthRecord.Encounter) Procedure(org.mitre.synthea.world.concepts.HealthRecord.Procedure) Reference(org.hl7.fhir.dstu3.model.Reference) Code(org.mitre.synthea.world.concepts.HealthRecord.Code) ContactPoint(org.hl7.fhir.dstu3.model.ContactPoint) SpecialConditionComponent(org.hl7.fhir.dstu3.model.Claim.SpecialConditionComponent) HealthRecord(org.mitre.synthea.world.concepts.HealthRecord) Type(org.hl7.fhir.dstu3.model.Type) DigitalMediaType(org.hl7.fhir.dstu3.model.Media.DigitalMediaType) EncounterType(org.mitre.synthea.world.concepts.HealthRecord.EncounterType) CodeType(org.hl7.fhir.dstu3.model.CodeType) IntegerType(org.hl7.fhir.dstu3.model.IntegerType) PositiveIntType(org.hl7.fhir.dstu3.model.PositiveIntType) NodeType(org.hl7.fhir.utilities.xhtml.NodeType) StringType(org.hl7.fhir.dstu3.model.StringType) BooleanType(org.hl7.fhir.dstu3.model.BooleanType) DateType(org.hl7.fhir.dstu3.model.DateType) DateTimeType(org.hl7.fhir.dstu3.model.DateTimeType) BundleType(org.hl7.fhir.dstu3.model.Bundle.BundleType) DecimalType(org.hl7.fhir.dstu3.model.DecimalType) AllergyIntoleranceType(org.hl7.fhir.dstu3.model.AllergyIntolerance.AllergyIntoleranceType) Claim(org.mitre.synthea.world.concepts.Claim) CodeableConcept(org.hl7.fhir.dstu3.model.CodeableConcept)

Example 73 with Money

use of org.hl7.fhir.r4b.model.Money in project synthea by synthetichealth.

the class FhirR4 method encounterClaim.

/**
 * Create an entry for the given Claim, associated to an Encounter.
 *
 * @param person         The patient having the encounter.
 * @param personEntry    Entry for the person
 * @param bundle         The Bundle to add to
 * @param encounterEntry The current Encounter
 * @param claim          the Claim object
 * @return the added Entry
 */
private static BundleEntryComponent encounterClaim(Person person, BundleEntryComponent personEntry, Bundle bundle, BundleEntryComponent encounterEntry, Claim claim) {
    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("institutional");
    claimResource.setType(type);
    claimResource.setUse(org.hl7.fhir.r4.model.Claim.Use.CLAIM);
    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().setReference(personEntry.getFullUrl()).setDisplay((String) person.attributes.get(Person.NAME)));
    claimResource.setProvider(encounterResource.getServiceProvider());
    if (USE_US_CORE_IG) {
        claimResource.setFacility(encounterResource.getLocationFirstRep().getLocation());
    }
    // 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())));
    int itemSequence = 2;
    int conditionSequence = 1;
    int procedureSequence = 1;
    int informationSequence = 1;
    for (Claim.ClaimEntry claimEntry : claim.items) {
        HealthRecord.Entry item = claimEntry.entry;
        if (Costs.hasCost(item)) {
            // update claimItems list
            Code primaryCode = item.codes.get(0);
            String system = ExportHelper.getSystemURI(primaryCode.system);
            ItemComponent claimItem = new ItemComponent(new PositiveIntType(itemSequence), mapCodeToCodeableConcept(primaryCode, system));
            // calculate the cost of the procedure
            Money moneyResource = new Money();
            moneyResource.setCurrency("USD");
            moneyResource.setValue(item.getCost());
            claimItem.setNet(moneyResource);
            claimResource.addItem(claimItem);
            if (item instanceof Procedure) {
                Type procedureReference = new Reference(item.fullUrl);
                ProcedureComponent claimProcedure = new ProcedureComponent(new PositiveIntType(procedureSequence), procedureReference);
                claimResource.addProcedure(claimProcedure);
                claimItem.addProcedureSequence(procedureSequence);
                procedureSequence++;
            } else {
                Reference informationReference = new Reference(item.fullUrl);
                SupportingInformationComponent informationComponent = new SupportingInformationComponent();
                informationComponent.setSequence(informationSequence);
                informationComponent.setValue(informationReference);
                CodeableConcept category = new CodeableConcept();
                category.getCodingFirstRep().setSystem("http://terminology.hl7.org/CodeSystem/claiminformationcategory").setCode("info");
                informationComponent.setCategory(category);
                claimResource.addSupportingInfo(informationComponent);
                claimItem.addInformationSequence(informationSequence);
                informationSequence++;
            }
        } else {
            // assume it's a Condition, we don't have a Condition class specifically
            // add diagnosisComponent to claim
            Reference diagnosisReference = new Reference(item.fullUrl);
            DiagnosisComponent diagnosisComponent = new DiagnosisComponent(new PositiveIntType(conditionSequence), diagnosisReference);
            claimResource.addDiagnosis(diagnosisComponent);
            // update claimItems with diagnosis
            ItemComponent diagnosisItem = new ItemComponent(new PositiveIntType(itemSequence), mapCodeToCodeableConcept(item.codes.get(0), SNOMED_URI));
            diagnosisItem.addDiagnosisSequence(conditionSequence);
            claimResource.addItem(diagnosisItem);
            conditionSequence++;
        }
        itemSequence++;
    }
    Money moneyResource = new Money();
    moneyResource.setCurrency("USD");
    moneyResource.setValue(claim.getTotalClaimCost());
    claimResource.setTotal(moneyResource);
    return newEntry(person, bundle, claimResource);
}
Also used : DiagnosisComponent(org.hl7.fhir.r4.model.Claim.DiagnosisComponent) ProcedureComponent(org.hl7.fhir.r4.model.Claim.ProcedureComponent) PositiveIntType(org.hl7.fhir.r4.model.PositiveIntType) Money(org.hl7.fhir.r4.model.Money) SupportingInformationComponent(org.hl7.fhir.r4.model.Claim.SupportingInformationComponent) SupplyDeliverySuppliedItemComponent(org.hl7.fhir.r4.model.SupplyDelivery.SupplyDeliverySuppliedItemComponent) ItemComponent(org.hl7.fhir.r4.model.Claim.ItemComponent) Encounter(org.mitre.synthea.world.concepts.HealthRecord.Encounter) Procedure(org.mitre.synthea.world.concepts.HealthRecord.Procedure) Reference(org.hl7.fhir.r4.model.Reference) DocumentReference(org.hl7.fhir.r4.model.DocumentReference) InsuranceComponent(org.hl7.fhir.r4.model.Claim.InsuranceComponent) Code(org.mitre.synthea.world.concepts.HealthRecord.Code) ContactPoint(org.hl7.fhir.r4.model.ContactPoint) HealthRecord(org.mitre.synthea.world.concepts.HealthRecord) IntegerType(org.hl7.fhir.r4.model.IntegerType) BooleanType(org.hl7.fhir.r4.model.BooleanType) BundleType(org.hl7.fhir.r4.model.Bundle.BundleType) EncounterType(org.mitre.synthea.world.concepts.HealthRecord.EncounterType) DeviceNameType(org.hl7.fhir.r4.model.Device.DeviceNameType) DateTimeType(org.hl7.fhir.r4.model.DateTimeType) AllergyIntoleranceType(org.hl7.fhir.r4.model.AllergyIntolerance.AllergyIntoleranceType) LocationPhysicalType(org.hl7.fhir.r4.model.codesystems.LocationPhysicalType) DecimalType(org.hl7.fhir.r4.model.DecimalType) CodeType(org.hl7.fhir.r4.model.CodeType) NodeType(org.hl7.fhir.utilities.xhtml.NodeType) StringType(org.hl7.fhir.r4.model.StringType) DateType(org.hl7.fhir.r4.model.DateType) PositiveIntType(org.hl7.fhir.r4.model.PositiveIntType) Type(org.hl7.fhir.r4.model.Type) DoseRateType(org.hl7.fhir.r4.model.codesystems.DoseRateType) Claim(org.mitre.synthea.world.concepts.Claim) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept)

Example 74 with Money

use of org.hl7.fhir.r4b.model.Money 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 75 with Money

use of org.hl7.fhir.r4b.model.Money 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)

Aggregations

Money (org.hl7.fhir.r4.model.Money)129 Test (org.junit.jupiter.api.Test)122 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)117 Coding (org.hl7.fhir.r4.model.Coding)115 AdjudicationComponent (org.hl7.fhir.r4.model.ExplanationOfBenefit.AdjudicationComponent)61 BenefitComponent (org.hl7.fhir.r4.model.ExplanationOfBenefit.BenefitComponent)48 DecimalType (org.hl7.fhir.r4.model.DecimalType)42 BigDecimal (java.math.BigDecimal)18 TotalComponent (org.hl7.fhir.r4.model.ExplanationOfBenefit.TotalComponent)9 Money (org.hl7.fhir.dstu3.model.Money)6 Extension (org.hl7.fhir.r4.model.Extension)6 Claim (org.mitre.synthea.world.concepts.Claim)6 Encounter (org.mitre.synthea.world.concepts.HealthRecord.Encounter)6 NotImplementedException (org.apache.commons.lang3.NotImplementedException)5 PaymentComponent (org.hl7.fhir.r4.model.ExplanationOfBenefit.PaymentComponent)5 EncounterType (org.mitre.synthea.world.concepts.HealthRecord.EncounterType)4 ItemComponent (org.hl7.fhir.dstu3.model.Claim.ItemComponent)3 Extension (org.hl7.fhir.dstu3.model.Extension)3 Reference (org.hl7.fhir.dstu3.model.Reference)3 SupplyDeliverySuppliedItemComponent (org.hl7.fhir.dstu3.model.SupplyDelivery.SupplyDeliverySuppliedItemComponent)3