Search in sources :

Example 1 with Supply

use of org.mitre.synthea.world.concepts.HealthRecord.Supply in project synthea by synthetichealth.

the class CSVExporter method export.

/**
 * Add a single Person's health record info to the CSV records.
 *
 * @param person Person to write record data for
 * @param time   Time the simulation ended
 * @throws IOException if any IO error occurs
 */
public void export(Person person, long time) throws IOException {
    String personID = patient(person, time);
    for (Encounter encounter : person.record.encounters) {
        String encounterID = encounter(person, personID, encounter);
        String payerID = encounter.claim.payer.uuid;
        claim(person, encounter.claim, encounter, encounterID, time);
        for (HealthRecord.Entry condition : encounter.conditions) {
            /* condition to ignore codes other then retrieved from terminology url */
            if (!StringUtils.isEmpty(Config.get("generate.terminology_service_url")) && !RandomCodeGenerator.selectedCodes.isEmpty()) {
                if (RandomCodeGenerator.selectedCodes.stream().filter(code -> code.code.equals(condition.codes.get(0).code)).findFirst().isPresent()) {
                    condition(personID, encounterID, condition);
                }
            } else {
                condition(personID, encounterID, condition);
            }
        }
        for (HealthRecord.Allergy allergy : encounter.allergies) {
            allergy(personID, encounterID, allergy);
        }
        for (Observation observation : encounter.observations) {
            observation(personID, encounterID, observation);
        }
        for (Procedure procedure : encounter.procedures) {
            procedure(personID, encounterID, procedure);
        }
        for (Medication medication : encounter.medications) {
            medication(personID, encounterID, payerID, medication, time);
            claim(person, medication.claim, encounter, encounterID, time);
        }
        for (HealthRecord.Entry immunization : encounter.immunizations) {
            immunization(personID, encounterID, immunization);
        }
        for (CarePlan careplan : encounter.careplans) {
            careplan(person, personID, encounterID, careplan);
        }
        for (ImagingStudy imagingStudy : encounter.imagingStudies) {
            imagingStudy(person, personID, encounterID, imagingStudy);
        }
        for (Device device : encounter.devices) {
            device(personID, encounterID, device);
        }
        for (Supply supply : encounter.supplies) {
            supply(personID, encounterID, encounter, supply);
        }
    }
    CSVExporter.getInstance().exportPayerTransitions(person, time);
    int yearsOfHistory = Integer.parseInt(Config.get("exporter.years_of_history"));
    Calendar cutOff = new GregorianCalendar(1900, 0, 1);
    if (yearsOfHistory > 0) {
        cutOff = Calendar.getInstance();
        cutOff.set(cutOff.get(Calendar.YEAR) - yearsOfHistory, 0, 1);
    }
    Calendar now = Calendar.getInstance();
    Calendar birthDay = Calendar.getInstance();
    birthDay.setTimeInMillis((long) person.attributes.get(Person.BIRTHDATE));
    String[] gbdMetrics = { QualityOfLifeModule.QALY, QualityOfLifeModule.DALY, QualityOfLifeModule.QOLS };
    String unit = null;
    for (String score : gbdMetrics) {
        if (score.equals(QualityOfLifeModule.QOLS)) {
            unit = "{score}";
        } else {
            // years in UCUM is "a" for Latin "Annus"
            unit = "a";
        }
        @SuppressWarnings("unchecked") Map<Integer, Double> scores = (Map<Integer, Double>) person.attributes.get(score);
        for (Integer year : scores.keySet()) {
            birthDay.set(Calendar.YEAR, year);
            if (birthDay.after(cutOff) && birthDay.before(now)) {
                Observation obs = person.record.new Observation(birthDay.getTimeInMillis(), score, scores.get(year));
                obs.unit = unit;
                Code code = new Code("GBD", score, score);
                obs.codes.add(code);
                observation(personID, "", obs);
            }
        }
    }
    patients.flush();
    encounters.flush();
    conditions.flush();
    allergies.flush();
    medications.flush();
    careplans.flush();
    observations.flush();
    procedures.flush();
    immunizations.flush();
    imagingStudies.flush();
    devices.flush();
    supplies.flush();
    claims.flush();
    claimsTransactions.flush();
}
Also used : Device(org.mitre.synthea.world.concepts.HealthRecord.Device) GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) Supply(org.mitre.synthea.world.concepts.HealthRecord.Supply) GregorianCalendar(java.util.GregorianCalendar) ImagingStudy(org.mitre.synthea.world.concepts.HealthRecord.ImagingStudy) Code(org.mitre.synthea.world.concepts.HealthRecord.Code) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HealthRecord(org.mitre.synthea.world.concepts.HealthRecord) CarePlan(org.mitre.synthea.world.concepts.HealthRecord.CarePlan) Entry(org.mitre.synthea.world.concepts.HealthRecord.Entry) Observation(org.mitre.synthea.world.concepts.HealthRecord.Observation) Medication(org.mitre.synthea.world.concepts.HealthRecord.Medication) Encounter(org.mitre.synthea.world.concepts.HealthRecord.Encounter) Procedure(org.mitre.synthea.world.concepts.HealthRecord.Procedure) Map(java.util.Map)

Example 2 with Supply

use of org.mitre.synthea.world.concepts.HealthRecord.Supply 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 || encounter.stop < claimCutoff) {
            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());
        fieldValues.put(DME.LINE_PLACE_OF_SRVC_CD, getPlaceOfService(encounter));
        // 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.add(subTotals.payer)));
        fieldValues.put(DME.NCH_CARR_CLM_ALOWD_AMT, String.format("%.2f", subTotals.cost.subtract(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.add(subTotals.payer)));
        fieldValues.put(DME.CLM_PMT_AMT, String.format("%.2f", subTotals.coinsurance.add(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.add(lineItem.deductible).add(lineItem.pocket)));
                fieldValues.put(DME.LINE_PRVDR_PMT_AMT, String.format("%.2f", lineItem.coinsurance.add(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.subtract(lineItem.adjustment)));
                fieldValues.put(DME.LINE_PRMRY_ALOWD_CHRG_AMT, String.format("%.2f", lineItem.cost.subtract(lineItem.adjustment)));
                fieldValues.put(DME.LINE_NCH_PMT_AMT, String.format("%.2f", lineItem.coinsurance.add(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

HealthRecord (org.mitre.synthea.world.concepts.HealthRecord)2 Device (org.mitre.synthea.world.concepts.HealthRecord.Device)2 Supply (org.mitre.synthea.world.concepts.HealthRecord.Supply)2 Calendar (java.util.Calendar)1 GregorianCalendar (java.util.GregorianCalendar)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 DME (org.mitre.synthea.export.BB2RIFStructure.DME)1 ClaimEntry (org.mitre.synthea.world.concepts.Claim.ClaimEntry)1 CarePlan (org.mitre.synthea.world.concepts.HealthRecord.CarePlan)1 Code (org.mitre.synthea.world.concepts.HealthRecord.Code)1 Encounter (org.mitre.synthea.world.concepts.HealthRecord.Encounter)1 Entry (org.mitre.synthea.world.concepts.HealthRecord.Entry)1 ImagingStudy (org.mitre.synthea.world.concepts.HealthRecord.ImagingStudy)1 Medication (org.mitre.synthea.world.concepts.HealthRecord.Medication)1 Observation (org.mitre.synthea.world.concepts.HealthRecord.Observation)1 Procedure (org.mitre.synthea.world.concepts.HealthRecord.Procedure)1