Search in sources :

Example 1 with DME

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

the class BB2RIFExporterTest method testStaticFieldConfig.

@Test
public void testStaticFieldConfig() throws IOException, NoSuchMethodException {
    RandomNumberGenerator rand = new Person(System.currentTimeMillis());
    assertEquals("foo", StaticFieldConfig.processCell("foo", rand));
    String randomVal = StaticFieldConfig.processCell("1, 2, 3", rand);
    assertTrue(randomVal.equalsIgnoreCase("1") || randomVal.equalsIgnoreCase("2") || randomVal.equalsIgnoreCase("3"));
    StaticFieldConfig config = new StaticFieldConfig();
    assertEquals("INSERT", config.getValue("DML_IND", INPATIENT.class));
    assertEquals("82 (DMEPOS)", config.getValue("NCH_CLM_TYPE_CD", DME.class));
    assertEquals("71 (local carrier, non-DME)", config.getValue("NCH_CLM_TYPE_CD", CARRIER.class));
    HashMap<BENEFICIARY, String> values = new HashMap<>();
    config.setValues(values, BENEFICIARY.class, rand);
    assertEquals("INSERT", values.get(BENEFICIARY.DML_IND));
    String sexIdent = values.get(BENEFICIARY.BENE_SEX_IDENT_CD);
    assertTrue(sexIdent.equals("1") || sexIdent.equals("2"));
}
Also used : BENEFICIARY(org.mitre.synthea.export.BB2RIFStructure.BENEFICIARY) RandomNumberGenerator(org.mitre.synthea.helpers.RandomNumberGenerator) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) StaticFieldConfig(org.mitre.synthea.export.BB2RIFExporter.StaticFieldConfig) Person(org.mitre.synthea.world.agents.Person) DME(org.mitre.synthea.export.BB2RIFStructure.DME) INPATIENT(org.mitre.synthea.export.BB2RIFStructure.INPATIENT) CARRIER(org.mitre.synthea.export.BB2RIFStructure.CARRIER) Test(org.junit.Test)

Example 2 with DME

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

the class BB2RIFExporter method exportDME.

/**
 * Export DME details 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 exportDME(Person person, long startTime, long stopTime) throws IOException {
    HashMap<DME, String> fieldValues = new HashMap<>();
    for (HealthRecord.Encounter encounter : person.record.encounters) {
        if (encounter.stop < startTime) {
            continue;
        }
        boolean isVA = (ProviderType.VETERAN == encounter.provider.type);
        // 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) {
            continue;
        }
        long claimId = BB2RIFExporter.claimId.getAndDecrement();
        int claimGroupId = BB2RIFExporter.claimGroupId.getAndDecrement();
        long carrClmId = BB2RIFExporter.carrClmCntlNum.getAndDecrement();
        double latestHemoglobin = 0;
        for (HealthRecord.Observation observation : encounter.observations) {
            if (observation.containsCode("718-7", "http://loinc.org")) {
                latestHemoglobin = (double) observation.value;
            }
        }
        fieldValues.clear();
        staticFieldConfig.setValues(fieldValues, DME.class, person);
        // complex fields that could not easily be set using cms_field_values.tsv
        fieldValues.put(DME.CLM_ID, "" + claimId);
        fieldValues.put(DME.CLM_GRP_ID, "" + claimGroupId);
        fieldValues.put(DME.CARR_CLM_CNTL_NUM, "" + carrClmId);
        fieldValues.put(DME.BENE_ID, (String) person.attributes.get(BB2_BENE_ID));
        fieldValues.put(DME.LINE_HCT_HGB_RSLT_NUM, "" + latestHemoglobin);
        fieldValues.put(DME.CARR_NUM, getCarrier(encounter.provider.state, CARRIER.CARR_NUM));
        fieldValues.put(DME.NCH_WKLY_PROC_DT, bb2DateFromTimestamp(ExportHelper.nextFriday(encounter.stop)));
        fieldValues.put(DME.PRVDR_NUM, encounter.provider.id);
        fieldValues.put(DME.PRVDR_NPI, encounter.provider.npi);
        fieldValues.put(DME.RFR_PHYSN_NPI, encounter.clinician.npi);
        fieldValues.put(DME.PRVDR_SPCLTY, ClinicianSpecialty.getCMSProviderSpecialtyCode((String) encounter.clinician.attributes.get(Clinician.SPECIALTY)));
        fieldValues.put(DME.PRVDR_STATE_CD, locationMapper.getStateCode(encounter.provider.state));
        fieldValues.put(DME.TAX_NUM, bb2TaxId((String) encounter.clinician.attributes.get(Person.IDENTIFIER_SSN)));
        fieldValues.put(DME.DMERC_LINE_PRCNG_STATE_CD, locationMapper.getStateCode((String) person.attributes.get(Person.STATE)));
        fieldValues.put(DME.LINE_1ST_EXPNS_DT, bb2DateFromTimestamp(encounter.start));
        fieldValues.put(DME.LINE_LAST_EXPNS_DT, bb2DateFromTimestamp(encounter.stop));
        fieldValues.put(DME.LINE_SRVC_CNT, "" + encounter.claim.items.size());
        // OPTIONAL
        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(DME.PRNCPAL_DGNS_CD, icdCode);
                fieldValues.put(DME.LINE_ICD_DGNS_CD, icdCode);
            }
        }
        // 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.dmeDxFields.length);
        for (int i = 0; i < smallest; i++) {
            DME[] dxField = BB2RIFStructure.dmeDxFields[i];
            fieldValues.put(dxField[0], mappedDiagnosisCodes.get(i));
            // 0=ICD10
            fieldValues.put(dxField[1], "0");
        }
        if (!fieldValues.containsKey(DME.PRNCPAL_DGNS_CD)) {
            fieldValues.put(DME.PRNCPAL_DGNS_CD, mappedDiagnosisCodes.get(0));
            fieldValues.put(DME.LINE_ICD_DGNS_CD, mappedDiagnosisCodes.get(0));
        }
        // preprocess some subtotals...
        ClaimEntry subTotals = (encounter.claim).new ClaimEntry(null);
        for (ClaimEntry lineItem : encounter.claim.items) {
            if (lineItem.entry instanceof Device || lineItem.entry instanceof Supply) {
                subTotals.addCosts(lineItem);
            }
        }
        fieldValues.put(DME.CARR_CLM_CASH_DDCTBL_APLD_AMT, String.format("%.2f", subTotals.deductible));
        fieldValues.put(DME.CARR_CLM_PRMRY_PYR_PD_AMT, String.format("%.2f", subTotals.coinsurance + subTotals.payer));
        fieldValues.put(DME.NCH_CARR_CLM_ALOWD_AMT, String.format("%.2f", subTotals.cost - subTotals.adjustment));
        fieldValues.put(DME.NCH_CARR_CLM_SBMTD_CHRG_AMT, String.format("%.2f", subTotals.cost));
        fieldValues.put(DME.NCH_CLM_PRVDR_PMT_AMT, String.format("%.2f", subTotals.coinsurance + subTotals.payer));
        fieldValues.put(DME.CLM_PMT_AMT, String.format("%.2f", subTotals.coinsurance + subTotals.payer));
        synchronized (rifWriters.getOrCreateWriter(DME.class)) {
            int lineNum = 1;
            // Now generate the line items...
            for (ClaimEntry lineItem : encounter.claim.items) {
                if (!(lineItem.entry instanceof Device || lineItem.entry instanceof Supply)) {
                    continue;
                }
                if (lineItem.entry instanceof Supply) {
                    Supply supply = (Supply) lineItem.entry;
                    fieldValues.put(DME.DMERC_LINE_MTUS_CNT, "" + supply.quantity);
                } else {
                    fieldValues.put(DME.DMERC_LINE_MTUS_CNT, "");
                }
                if (!dmeCodeMapper.canMap(lineItem.entry.codes.get(0).code)) {
                    System.err.println(" *** Possibly Missing DME Code: " + lineItem.entry.codes.get(0).code + " " + lineItem.entry.codes.get(0).display);
                    continue;
                }
                fieldValues.put(DME.CLM_FROM_DT, bb2DateFromTimestamp(lineItem.entry.start));
                fieldValues.put(DME.CLM_THRU_DT, bb2DateFromTimestamp(lineItem.entry.start));
                String hcpcsCode = dmeCodeMapper.map(lineItem.entry.codes.get(0).code, person);
                fieldValues.put(DME.HCPCS_CD, hcpcsCode);
                if (betosCodeMapper.canMap(hcpcsCode)) {
                    fieldValues.put(DME.BETOS_CD, betosCodeMapper.map(hcpcsCode, person));
                } else {
                    fieldValues.put(DME.BETOS_CD, "");
                }
                fieldValues.put(DME.LINE_CMS_TYPE_SRVC_CD, dmeCodeMapper.map(lineItem.entry.codes.get(0).code, DME.LINE_CMS_TYPE_SRVC_CD.toString().toLowerCase(), person));
                fieldValues.put(DME.LINE_BENE_PTB_DDCTBL_AMT, String.format("%.2f", lineItem.deductible));
                fieldValues.put(DME.LINE_COINSRNC_AMT, String.format("%.2f", lineItem.getCoinsurancePaid()));
                fieldValues.put(DME.LINE_BENE_PMT_AMT, String.format("%.2f", lineItem.copay + lineItem.deductible + lineItem.pocket));
                fieldValues.put(DME.LINE_PRVDR_PMT_AMT, String.format("%.2f", lineItem.coinsurance + lineItem.payer));
                fieldValues.put(DME.LINE_SBMTD_CHRG_AMT, String.format("%.2f", lineItem.cost));
                fieldValues.put(DME.LINE_ALOWD_CHRG_AMT, String.format("%.2f", lineItem.cost - lineItem.adjustment));
                fieldValues.put(DME.LINE_PRMRY_ALOWD_CHRG_AMT, String.format("%.2f", lineItem.cost - lineItem.adjustment));
                fieldValues.put(DME.LINE_NCH_PMT_AMT, String.format("%.2f", lineItem.coinsurance + lineItem.payer));
                // set the line number and write out field values
                fieldValues.put(DME.LINE_NUM, Integer.toString(lineNum++));
                rifWriters.writeValues(DME.class, fieldValues);
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Device(org.mitre.synthea.world.concepts.HealthRecord.Device) Supply(org.mitre.synthea.world.concepts.HealthRecord.Supply) ClaimEntry(org.mitre.synthea.world.concepts.Claim.ClaimEntry) HealthRecord(org.mitre.synthea.world.concepts.HealthRecord) DME(org.mitre.synthea.export.BB2RIFStructure.DME)

Aggregations

HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 DME (org.mitre.synthea.export.BB2RIFStructure.DME)2 Test (org.junit.Test)1 StaticFieldConfig (org.mitre.synthea.export.BB2RIFExporter.StaticFieldConfig)1 BENEFICIARY (org.mitre.synthea.export.BB2RIFStructure.BENEFICIARY)1 CARRIER (org.mitre.synthea.export.BB2RIFStructure.CARRIER)1 INPATIENT (org.mitre.synthea.export.BB2RIFStructure.INPATIENT)1 RandomNumberGenerator (org.mitre.synthea.helpers.RandomNumberGenerator)1 Person (org.mitre.synthea.world.agents.Person)1 ClaimEntry (org.mitre.synthea.world.concepts.Claim.ClaimEntry)1 HealthRecord (org.mitre.synthea.world.concepts.HealthRecord)1 Device (org.mitre.synthea.world.concepts.HealthRecord.Device)1 Supply (org.mitre.synthea.world.concepts.HealthRecord.Supply)1