Search in sources :

Example 16 with Entry

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

the class TextExporter method exportEncounter.

/**
 * Produce and export a person's record in text format.
 *
 * @param person Person
 * @param time Time the simulation ended
 * @throws IOException if any error occurs writing to the standard export location
 */
public static void exportEncounter(Person person, long time) throws IOException {
    List<Encounter> encounters = person.record.encounters;
    List<Entry> conditions = new ArrayList<>();
    List<Entry> allergies = new ArrayList<>();
    List<Medication> medications = new ArrayList<>();
    List<CarePlan> careplans = new ArrayList<>();
    for (Encounter encounter : person.record.encounters) {
        conditions.addAll(encounter.conditions);
        allergies.addAll(encounter.allergies);
        medications.addAll(encounter.medications);
        careplans.addAll(encounter.careplans);
    }
    // reverse these items so they are displayed in reverse chrono order
    Collections.reverse(encounters);
    Collections.reverse(conditions);
    Collections.reverse(allergies);
    Collections.reverse(medications);
    Collections.reverse(careplans);
    // set an integer that will be used as a counter for file naming purposes
    int encounterNumber = 0;
    for (Encounter encounter : encounters) {
        // make a record for each encounter to write information
        List<String> textRecord = new LinkedList<>();
        basicInfo(textRecord, person, time);
        breakline(textRecord);
        textRecord.add("ALLERGIES:");
        if (allergies.isEmpty()) {
            textRecord.add("No Known Allergies");
        } else {
            for (Entry allergy : allergies) {
                condition(textRecord, allergy, false);
            }
        }
        breakline(textRecord);
        textRecord.add("ENCOUNTER");
        encounterReport(textRecord, person, encounter);
        breakline(textRecord);
        textRecord.add("CONTINUING");
        textRecord.add("   ");
        textRecord.add("   CONDITIONS:");
        for (Entry condition : conditions) {
            conditionpast(textRecord, condition, encounter);
        }
        textRecord.add("   ");
        textRecord.add("   MEDICATIONS:");
        for (Medication medication : medications) {
            medicationpast(textRecord, medication, encounter);
        }
        textRecord.add("   ");
        textRecord.add("   CAREPLANS:");
        for (CarePlan careplan : careplans) {
            careplanpast(textRecord, careplan, encounter);
        }
        textRecord.add("   ");
        breakline(textRecord);
        encounterNumber++;
        // write to the file
        File outDirectory2 = Exporter.getOutputFolder("text_encounters", person);
        Path outFilePath2 = outDirectory2.toPath().resolve(Exporter.filename(person, Integer.toString(encounterNumber), "txt"));
        Files.write(outFilePath2, textRecord, StandardOpenOption.CREATE_NEW);
    }
}
Also used : Path(java.nio.file.Path) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) Entry(org.mitre.synthea.world.concepts.HealthRecord.Entry) CarePlan(org.mitre.synthea.world.concepts.HealthRecord.CarePlan) Medication(org.mitre.synthea.world.concepts.HealthRecord.Medication) Encounter(org.mitre.synthea.world.concepts.HealthRecord.Encounter) File(java.io.File)

Example 17 with Entry

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

the class QualityOfLifeModule method calculate.

/**
 * Calculate the HALYs for this person, at the given time. HALYs include QALY
 * and DALY.
 *
 * @param person Person to calculate
 * @param stop   current timestamp
 * @return array of [daly (cumulative), qaly (cumulative), current disability
 *         weight]
 */
public static double[] calculate(Person person, long stop) {
    // Disability-Adjusted Life Year = DALY = YLL + YLD
    // Years of Life Lost = YLL = (1) * (standard life expectancy at age of death in
    // years)
    // Years Lost due to Disability = YLD = (disability weight) * (average duration
    // of case)
    // from http://www.who.int/healthinfo/global_burden_disease/metrics_daly/en/
    double yll = 0.0;
    double yld = 0.0;
    int age = person.ageInYears(stop);
    long birthdate = (long) person.attributes.get(Person.BIRTHDATE);
    if (!person.alive(stop)) {
        // life expectancy equation derived from IHME GBD 2015 Reference Life Table
        // 6E-5x^3 - 0.0054x^2 - 0.8502x + 86.16
        // R^2 = 0.99978
        double l = ((0.00006 * Math.pow(age, 3)) - (0.0054 * Math.pow(age, 2)) - (0.8502 * age) + 86.16);
        yll = l;
    }
    // Get counts of covered healthcare.
    List<Entry> allConditions = new ArrayList<Entry>();
    int coveredMedicationCount = 0;
    int coveredProcedureCount = 0;
    int coveredImmunizationCount = 0;
    int coveredEncounterCount = 0;
    for (Encounter encounter : person.defaultRecord.encounters) {
        for (Entry condition : encounter.conditions) {
            allConditions.add(condition);
        }
        coveredMedicationCount += encounter.medications.size();
        coveredProcedureCount += encounter.procedures.size();
        coveredImmunizationCount += encounter.immunizations.size();
        coveredEncounterCount++;
    }
    int coveredEntries = coveredEncounterCount + coveredMedicationCount + coveredProcedureCount + coveredImmunizationCount;
    // Get counts of uncovered healthcare.
    int uncoveredEntries;
    if (person.lossOfCareEnabled) {
        List<Entry> allLossOfCareConditions = new ArrayList<Entry>();
        int uncoveredMedicationCount = 0;
        int uncoveredProcedureCount = 0;
        int uncoveredImmunizationCount = 0;
        int uncoveredEncounterCount = 0;
        for (Encounter encounter : person.lossOfCareRecord.encounters) {
            for (Entry condition : encounter.conditions) {
                allLossOfCareConditions.add(condition);
            }
            uncoveredMedicationCount += encounter.medications.size();
            uncoveredProcedureCount += encounter.procedures.size();
            uncoveredImmunizationCount += encounter.immunizations.size();
            uncoveredEncounterCount++;
        }
        uncoveredEntries = uncoveredEncounterCount + uncoveredMedicationCount + uncoveredProcedureCount + uncoveredImmunizationCount;
        allConditions.addAll(allLossOfCareConditions);
    } else {
        uncoveredEntries = 0;
    }
    // NOTE: This percentageOfCoveredCare is based on entire life, not just current year.
    if (coveredEntries < 1) {
        coveredEntries = 1;
    }
    double percentageOfCoveredCare = coveredEntries / (coveredEntries + uncoveredEntries);
    double disabilityWeight = 0.0;
    // calculate yld with yearly timestep
    for (int i = 0; i < age + 1; i++) {
        long yearStart = birthdate + TimeUnit.DAYS.toMillis((long) (365.25 * i));
        long yearEnd = birthdate + (TimeUnit.DAYS.toMillis((long) (365.25 * (i + 1) - 1)));
        List<Entry> conditionsInYear = conditionsInYear(allConditions, yearStart, yearEnd);
        disabilityWeight = 0.0;
        for (Entry condition : conditionsInYear) {
            // Get the disability weight for this condition based on the percentageOfCoveredCare.
            disabilityWeight += (double) disabilityWeights.get(condition.codes.get(0).code).getWeight(percentageOfCoveredCare);
        }
        disabilityWeight = Math.min(1.0, weight(disabilityWeight, i + 1));
        yld += disabilityWeight;
    }
    double daly = yll + yld;
    double qaly = age - yld;
    return new double[] { daly, qaly, 1 - disabilityWeight };
}
Also used : Entry(org.mitre.synthea.world.concepts.HealthRecord.Entry) ArrayList(java.util.ArrayList) Encounter(org.mitre.synthea.world.concepts.HealthRecord.Encounter)

Example 18 with Entry

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

the class CostsTest method testDeviceCostByKnownCode.

@Test
public void testDeviceCostByKnownCode() {
    Code code = new Code("SNOMED", "363753007", "Crutches");
    double minCost = 66.96;
    double maxCost = 66.96;
    Entry fakeDevice = person.record.deviceImplant(time, code.display);
    fakeDevice.codes.add(code);
    double cost = Costs.determineCostOfEntry(fakeDevice, person);
    // at this point person has no state set, so there won't be a geographic factor applied
    assertTrue(cost <= maxCost);
    assertTrue(cost >= minCost);
    person.attributes.put(Person.STATE, "Massachusetts");
    double adjFactor = 0.8183;
    cost = Costs.determineCostOfEntry(fakeDevice, person);
    assertTrue(cost <= (maxCost * adjFactor));
    assertTrue(cost >= (minCost * adjFactor));
}
Also used : Entry(org.mitre.synthea.world.concepts.HealthRecord.Entry) Code(org.mitre.synthea.world.concepts.HealthRecord.Code) Test(org.junit.Test)

Example 19 with Entry

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

the class CostsTest method testCostByKnownCode.

@Test
public void testCostByKnownCode() {
    Code code = new Code("RxNorm", "705129", "Nitroglycerin 0.4 MG/ACTUAT Mucosal Spray");
    // note: cost range = 8.5-400, with mode at 20
    double minCost = 8.5;
    double maxCost = 400;
    Entry fakeMedication = person.record.medicationStart(time, code.display, true);
    fakeMedication.codes.add(code);
    double cost = Costs.determineCostOfEntry(fakeMedication, person);
    // at this point person has no state set, so there won't be a geographic factor applied
    assertTrue(cost <= maxCost);
    assertTrue(cost >= minCost);
    person.attributes.put(Person.STATE, "Massachusetts");
    double adjFactor = 0.5096;
    cost = Costs.determineCostOfEntry(fakeMedication, person);
    assertTrue(cost <= (maxCost * adjFactor));
    assertTrue(cost >= (minCost * adjFactor));
}
Also used : Entry(org.mitre.synthea.world.concepts.HealthRecord.Entry) Code(org.mitre.synthea.world.concepts.HealthRecord.Code) Test(org.junit.Test)

Aggregations

Entry (org.mitre.synthea.world.concepts.HealthRecord.Entry)19 Code (org.mitre.synthea.world.concepts.HealthRecord.Code)11 Test (org.junit.Test)7 Encounter (org.mitre.synthea.world.concepts.HealthRecord.Encounter)7 Procedure (org.mitre.synthea.world.concepts.HealthRecord.Procedure)7 ArrayList (java.util.ArrayList)6 Medication (org.mitre.synthea.world.concepts.HealthRecord.Medication)6 CarePlan (org.mitre.synthea.world.concepts.HealthRecord.CarePlan)3 File (java.io.File)2 Path (java.nio.file.Path)2 LinkedList (java.util.LinkedList)2 HealthRecord (org.mitre.synthea.world.concepts.HealthRecord)2 ImagingStudy (org.mitre.synthea.world.concepts.HealthRecord.ImagingStudy)2 Observation (org.mitre.synthea.world.concepts.HealthRecord.Observation)2 Report (org.mitre.synthea.world.concepts.HealthRecord.Report)2 JsonObject (com.google.gson.JsonObject)1 Template (freemarker.template.Template)1 TemplateException (freemarker.template.TemplateException)1 StringWriter (java.io.StringWriter)1 BigDecimal (java.math.BigDecimal)1