Search in sources :

Example 1 with HHA

use of org.mitre.synthea.export.BB2RIFStructure.HHA in project synthea by synthetichealth.

the class BB2RIFExporter method exportHome.

/**
 * Export Home Health Agency visits for a single person.
 * @param person the person to export
 * @param startTime earliest claim date to export
 * @param stopTime end time of simulation
 * @throws IOException if something goes wrong
 */
private void exportHome(Person person, long startTime, long stopTime) throws IOException {
    HashMap<HHA, String> fieldValues = new HashMap<>();
    int homeVisits = 0;
    for (HealthRecord.Encounter encounter : person.record.encounters) {
        if (encounter.stop < startTime) {
            continue;
        }
        boolean isVA = (ProviderType.VETERAN == encounter.provider.type);
        boolean isHome = encounter.type.equals(EncounterType.HOME.toString());
        // IHS facilities have valid 6 digit id, IHS centers don't
        boolean isIHSCenter = (ProviderType.IHS == encounter.provider.type) && encounter.provider.id.length() != 6;
        if (isVA || isIHSCenter || !isHome) {
            continue;
        }
        homeVisits += 1;
        long claimId = BB2RIFExporter.claimId.getAndDecrement();
        int claimGroupId = BB2RIFExporter.claimGroupId.getAndDecrement();
        long fiDocId = BB2RIFExporter.fiDocCntlNum.getAndDecrement();
        fieldValues.clear();
        staticFieldConfig.setValues(fieldValues, HHA.class, person);
        // The REQUIRED fields
        fieldValues.put(HHA.BENE_ID, (String) person.attributes.get(BB2_BENE_ID));
        fieldValues.put(HHA.CLM_ID, "" + claimId);
        fieldValues.put(HHA.CLM_GRP_ID, "" + claimGroupId);
        fieldValues.put(HHA.FI_DOC_CLM_CNTL_NUM, "" + fiDocId);
        fieldValues.put(HHA.CLM_FROM_DT, bb2DateFromTimestamp(encounter.start));
        fieldValues.put(HHA.CLM_ADMSN_DT, bb2DateFromTimestamp(encounter.start));
        fieldValues.put(HHA.CLM_THRU_DT, bb2DateFromTimestamp(encounter.stop));
        fieldValues.put(HHA.NCH_WKLY_PROC_DT, bb2DateFromTimestamp(ExportHelper.nextFriday(encounter.stop)));
        fieldValues.put(HHA.PRVDR_NUM, encounter.provider.id);
        fieldValues.put(HHA.ORG_NPI_NUM, encounter.provider.npi);
        fieldValues.put(HHA.AT_PHYSN_NPI, encounter.clinician.npi);
        fieldValues.put(HHA.RNDRNG_PHYSN_NPI, encounter.clinician.npi);
        fieldValues.put(HHA.CLM_PMT_AMT, String.format("%.2f", encounter.claim.getCoveredCost()));
        if (encounter.claim.payer == Payer.getGovernmentPayer(HealthInsuranceModule.MEDICARE)) {
            fieldValues.put(HHA.NCH_PRMRY_PYR_CLM_PD_AMT, "0");
        } else {
            fieldValues.put(HHA.NCH_PRMRY_PYR_CLM_PD_AMT, String.format("%.2f", encounter.claim.getCoveredCost()));
        }
        fieldValues.put(HHA.PRVDR_STATE_CD, locationMapper.getStateCode(encounter.provider.state));
        fieldValues.put(HHA.CLM_TOT_CHRG_AMT, String.format("%.2f", encounter.claim.getTotalClaimCost()));
        fieldValues.put(HHA.CLM_HHA_TOT_VISIT_CNT, "" + homeVisits);
        int days = (int) ((encounter.stop - encounter.start) / (1000 * 60 * 60 * 24));
        if (days <= 0) {
            days = 1;
        }
        fieldValues.put(HHA.REV_CNTR_UNIT_CNT, "" + days);
        fieldValues.put(HHA.REV_CNTR_RATE_AMT, String.format("%.2f", (encounter.claim.getTotalClaimCost() / days)));
        fieldValues.put(HHA.REV_CNTR_PMT_AMT_AMT, String.format("%.2f", encounter.claim.getCoveredCost()));
        fieldValues.put(HHA.REV_CNTR_TOT_CHRG_AMT, String.format("%.2f", encounter.claim.getTotalClaimCost()));
        fieldValues.put(HHA.REV_CNTR_NCVRD_CHRG_AMT, String.format("%.2f", encounter.claim.getPatientCost()));
        if (encounter.reason != null) {
            // values into the principle diagnoses code.
            if (conditionCodeMapper.canMap(encounter.reason.code)) {
                String icdCode = conditionCodeMapper.map(encounter.reason.code, person, true);
                fieldValues.put(HHA.PRNCPAL_DGNS_CD, icdCode);
            }
        }
        // PTNT_DSCHRG_STUS_CD: 1=home, 2=transfer, 3=SNF, 20=died, 30=still here
        String dischargeStatus = null;
        if (encounter.ended) {
            // TODO 2=transfer if the next encounter is also inpatient
            dischargeStatus = "1";
        } else {
            // the patient is still here
            dischargeStatus = "30";
        }
        if (!person.alive(encounter.stop)) {
            // the patient died before the encounter ended
            dischargeStatus = "20";
        }
        fieldValues.put(HHA.PTNT_DSCHRG_STUS_CD, dischargeStatus);
        // Use the active condition diagnoses to enter mapped values
        // into the diagnoses codes.
        List<String> mappedDiagnosisCodes = getDiagnosesCodes(person, encounter.stop);
        if (mappedDiagnosisCodes.isEmpty()) {
            // skip this encounter
            continue;
        }
        int smallest = Math.min(mappedDiagnosisCodes.size(), BB2RIFStructure.homeDxFields.length);
        for (int i = 0; i < smallest; i++) {
            HHA[] dxField = BB2RIFStructure.homeDxFields[i];
            fieldValues.put(dxField[0], mappedDiagnosisCodes.get(i));
            // 0=ICD10
            fieldValues.put(dxField[1], "0");
        }
        if (!fieldValues.containsKey(HHA.PRNCPAL_DGNS_CD)) {
            fieldValues.put(HHA.PRNCPAL_DGNS_CD, mappedDiagnosisCodes.get(0));
        }
        // Check for external code...
        setExternalCode(person, fieldValues, HHA.PRNCPAL_DGNS_CD, HHA.ICD_DGNS_E_CD1, HHA.ICD_DGNS_E_VRSN_CD1);
        setExternalCode(person, fieldValues, HHA.PRNCPAL_DGNS_CD, HHA.FST_DGNS_E_CD, HHA.FST_DGNS_E_VRSN_CD);
        synchronized (rifWriters.getOrCreateWriter(HHA.class)) {
            int claimLine = 1;
            for (ClaimEntry lineItem : encounter.claim.items) {
                String hcpcsCode = null;
                if (lineItem.entry instanceof HealthRecord.Procedure) {
                    for (HealthRecord.Code code : lineItem.entry.codes) {
                        if (hcpcsCodeMapper.canMap(code.code)) {
                            hcpcsCode = hcpcsCodeMapper.map(code.code, person, true);
                            // take the first mappable code for each procedure
                            break;
                        }
                    }
                    fieldValues.remove(HHA.REV_CNTR_NDC_QTY);
                    fieldValues.remove(HHA.REV_CNTR_NDC_QTY_QLFR_CD);
                } else if (lineItem.entry instanceof HealthRecord.Medication) {
                    HealthRecord.Medication med = (HealthRecord.Medication) lineItem.entry;
                    if (med.administration) {
                        // Administration of medication
                        hcpcsCode = "T1502";
                        // 1 Unit
                        fieldValues.put(HHA.REV_CNTR_NDC_QTY, "1");
                        // Unit
                        fieldValues.put(HHA.REV_CNTR_NDC_QTY_QLFR_CD, "UN");
                    }
                }
                if (hcpcsCode == null) {
                    continue;
                }
                fieldValues.put(HHA.CLM_LINE_NUM, Integer.toString(claimLine++));
                fieldValues.put(HHA.REV_CNTR_DT, bb2DateFromTimestamp(lineItem.entry.start));
                fieldValues.put(HHA.HCPCS_CD, hcpcsCode);
                fieldValues.put(HHA.REV_CNTR_RATE_AMT, String.format("%.2f", (lineItem.cost / Integer.max(1, days))));
                fieldValues.put(HHA.REV_CNTR_PMT_AMT_AMT, String.format("%.2f", lineItem.coinsurance + lineItem.payer));
                fieldValues.put(HHA.REV_CNTR_TOT_CHRG_AMT, String.format("%.2f", lineItem.cost));
                fieldValues.put(HHA.REV_CNTR_NCVRD_CHRG_AMT, String.format("%.2f", lineItem.copay + lineItem.deductible + lineItem.pocket));
                if (lineItem.pocket == 0 && lineItem.deductible == 0) {
                    // Not subject to deductible or coinsurance
                    fieldValues.put(HHA.REV_CNTR_DDCTBL_COINSRNC_CD, "3");
                } else if (lineItem.pocket > 0 && lineItem.deductible > 0) {
                    // Subject to deductible and coinsurance
                    fieldValues.put(HHA.REV_CNTR_DDCTBL_COINSRNC_CD, "0");
                } else if (lineItem.pocket == 0) {
                    // Not subject to deductible
                    fieldValues.put(HHA.REV_CNTR_DDCTBL_COINSRNC_CD, "1");
                } else {
                    // Not subject to coinsurance
                    fieldValues.put(HHA.REV_CNTR_DDCTBL_COINSRNC_CD, "2");
                }
                rifWriters.writeValues(HHA.class, fieldValues);
            }
            if (claimLine == 1) {
                // If claimLine still equals 1, then no line items were successfully added.
                // Add a single top-level entry.
                fieldValues.put(HHA.CLM_LINE_NUM, Integer.toString(claimLine));
                fieldValues.put(HHA.REV_CNTR_DT, bb2DateFromTimestamp(encounter.start));
                // home health visit
                fieldValues.put(HHA.HCPCS_CD, "T1021");
                rifWriters.writeValues(HHA.class, fieldValues);
            }
        }
    }
}
Also used : HHA(org.mitre.synthea.export.BB2RIFStructure.HHA) Medication(org.mitre.synthea.world.concepts.HealthRecord.Medication) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ClaimEntry(org.mitre.synthea.world.concepts.Claim.ClaimEntry) HealthRecord(org.mitre.synthea.world.concepts.HealthRecord) Code(org.mitre.synthea.world.concepts.HealthRecord.Code) Medication(org.mitre.synthea.world.concepts.HealthRecord.Medication)

Aggregations

HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 HHA (org.mitre.synthea.export.BB2RIFStructure.HHA)1 ClaimEntry (org.mitre.synthea.world.concepts.Claim.ClaimEntry)1 HealthRecord (org.mitre.synthea.world.concepts.HealthRecord)1 Code (org.mitre.synthea.world.concepts.HealthRecord.Code)1 Medication (org.mitre.synthea.world.concepts.HealthRecord.Medication)1