Search in sources :

Example 1 with HealthRecord

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

the class PayerTest method payerCoversEncounter.

@Test
public void payerCoversEncounter() {
    person = new Person(0L);
    person.attributes.put(Person.BIRTHDATE, 0L);
    person.coverage.setPayerAtTime(0L, testPrivatePayer1);
    HealthRecord healthRecord = new HealthRecord(person);
    Encounter encounter = healthRecord.encounterStart(0L, EncounterType.INPATIENT);
    encounter.provider = new Provider();
    encounter.codes.add(new Code("SNOMED-CT", "705129", "Fake SNOMED for null entry"));
    assertTrue(testPrivatePayer1.coversService(encounter.type));
    healthRecord.encounterEnd(0L, EncounterType.INPATIENT);
    // Person's coverage should equal the cost of the encounter
    double coverage = encounter.claim.totals.coinsurance + encounter.claim.totals.payer;
    assertEquals(person.coverage.getTotalCoverage(), coverage, 0.001);
    double result = encounter.claim.totals.coinsurance + encounter.claim.totals.copay + encounter.claim.totals.deductible + encounter.claim.totals.payer + encounter.claim.totals.pocket;
    assertEquals(encounter.getCost().doubleValue(), result, 0.001);
    // Person's expenses should equal the copay.
    double expenses = encounter.claim.totals.copay + encounter.claim.totals.deductible + encounter.claim.totals.pocket;
    assertEquals(person.coverage.getTotalExpenses(), expenses, 0.001);
}
Also used : HealthRecord(org.mitre.synthea.world.concepts.HealthRecord) Encounter(org.mitre.synthea.world.concepts.HealthRecord.Encounter) Code(org.mitre.synthea.world.concepts.HealthRecord.Code) Test(org.junit.Test)

Example 2 with HealthRecord

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

the class PayerTest method incrementEncounters.

@Test
public void incrementEncounters() {
    person = new Person(0L);
    person.coverage.setPayerAtTime(0L, testPrivatePayer1);
    HealthRecord healthRecord = new HealthRecord(person);
    Code code = new Code("SNOMED-CT", "705129", "Fake Code");
    Encounter fakeEncounter = healthRecord.encounterStart(0L, EncounterType.INPATIENT);
    fakeEncounter.codes.add(code);
    fakeEncounter.provider = new Provider();
    healthRecord.encounterEnd(0L, EncounterType.INPATIENT);
    fakeEncounter = healthRecord.encounterStart(0L, EncounterType.AMBULATORY);
    fakeEncounter.provider = new Provider();
    fakeEncounter.codes.add(code);
    healthRecord.encounterEnd(0L, EncounterType.AMBULATORY);
    fakeEncounter = healthRecord.encounterStart(0L, EncounterType.EMERGENCY);
    fakeEncounter.codes.add(code);
    fakeEncounter.provider = new Provider();
    healthRecord.encounterEnd(0L, EncounterType.EMERGENCY);
    assertEquals(3, testPrivatePayer1.getEncountersCoveredCount());
}
Also used : HealthRecord(org.mitre.synthea.world.concepts.HealthRecord) Encounter(org.mitre.synthea.world.concepts.HealthRecord.Encounter) Code(org.mitre.synthea.world.concepts.HealthRecord.Code) Test(org.junit.Test)

Example 3 with HealthRecord

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

the class Exporter method filterForExport.

/**
 * Filter the patient's history to only the last __ years
 * but also include relevant history from before that. Exclude
 * any history that occurs after the specified end_time -- typically
 * this is the current time/System.currentTimeMillis().
 *
 * @param original    The Person to filter.
 * @param yearsToKeep The last __ years to keep.
 * @param endTime     The time the history ends.
 * @return Modified Person with history expunged.
 */
public static Person filterForExport(Person original, int yearsToKeep, long endTime) {
    // TODO: clone the patient so that we export only the last _ years
    // but the rest still exists, just in case
    // .clone();
    Person filtered = original;
    if (filtered.hasMultipleRecords) {
        for (String key : filtered.records.keySet()) {
            HealthRecord record = filtered.records.get(key);
            filterForExport(record, yearsToKeep, endTime);
        }
    } else {
        filtered.record = filterForExport(filtered.record, yearsToKeep, endTime);
    }
    return filtered;
}
Also used : HealthRecord(org.mitre.synthea.world.concepts.HealthRecord) Person(org.mitre.synthea.world.agents.Person)

Example 4 with HealthRecord

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

the class Exporter method filterForExport.

/**
 * Filter the health record to only the last __ years
 * but also include relevant history from before that. Exclude
 * any history that occurs after the specified end_time -- typically
 * this is the current time/System.currentTimeMillis().
 *
 * @param record    The record to filter.
 * @param yearsToKeep The last __ years to keep.
 * @param endTime     The time the history ends.
 * @return Modified record with history expunged.
 */
private static HealthRecord filterForExport(HealthRecord record, int yearsToKeep, long endTime) {
    long cutoffDate = endTime - Utilities.convertTime("years", yearsToKeep);
    Predicate<HealthRecord.Entry> notFutureDated = e -> e.start <= endTime;
    for (Encounter encounter : record.encounters) {
        List<Claim.ClaimEntry> claimItems = encounter.claim.items;
        // keep conditions if still active, regardless of start date
        Predicate<HealthRecord.Entry> conditionActive = c -> record.conditionActive(c.type);
        // or if the condition was active at any point since the cutoff date
        Predicate<HealthRecord.Entry> activeWithinCutoff = c -> c.stop != 0L && c.stop > cutoffDate;
        Predicate<HealthRecord.Entry> keepCondition = conditionActive.or(activeWithinCutoff);
        filterEntries(encounter.conditions, claimItems, cutoffDate, endTime, keepCondition);
        // allergies are essentially the same as conditions
        // But we need to redefine all of the predicates, because we are talking about Allergies as
        // opposed to Entries... You would think that it would work... but generics are hard
        Predicate<HealthRecord.Allergy> allergyActive = c -> record.allergyActive(c.type);
        // or if the condition was active at any point since the cutoff date
        Predicate<HealthRecord.Allergy> allergyActiveWithinCutoff = c -> c.stop != 0L && c.stop > cutoffDate;
        Predicate<HealthRecord.Allergy> keepAllergy = allergyActive.or(allergyActiveWithinCutoff);
        filterEntries(encounter.allergies, claimItems, cutoffDate, endTime, keepAllergy);
        // some of the "future death" logic could potentially add a future-dated death certificate
        Predicate<Observation> isCauseOfDeath = o -> DeathModule.CAUSE_OF_DEATH_CODE.code.equals(o.type);
        // keep cause of death unless it's future dated
        Predicate<Observation> keepObservation = isCauseOfDeath.and(notFutureDated);
        filterEntries(encounter.observations, claimItems, cutoffDate, endTime, keepObservation);
        // keep all death certificates, unless they are future-dated
        Predicate<Report> isDeathCertificate = r -> DeathModule.DEATH_CERTIFICATE.code.equals(r.type);
        Predicate<Report> keepReport = isDeathCertificate.and(notFutureDated);
        filterEntries(encounter.reports, claimItems, cutoffDate, endTime, keepReport);
        filterEntries(encounter.procedures, claimItems, cutoffDate, endTime, null);
        // keep medications if still active, regardless of start date
        filterEntries(encounter.medications, claimItems, cutoffDate, endTime, med -> record.medicationActive(med.type));
        filterEntries(encounter.immunizations, claimItems, cutoffDate, endTime, null);
        // keep careplans if they are still active, regardless of start date
        filterEntries(encounter.careplans, claimItems, cutoffDate, endTime, cp -> record.careplanActive(cp.type));
    }
    // if ANY of these are not empty, the encounter is not empty
    Predicate<Encounter> encounterNotEmpty = e -> !e.conditions.isEmpty() || !e.allergies.isEmpty() || !e.observations.isEmpty() || !e.reports.isEmpty() || !e.procedures.isEmpty() || !e.medications.isEmpty() || !e.immunizations.isEmpty() || !e.careplans.isEmpty();
    Predicate<Encounter> isDeathCertification = e -> !e.codes.isEmpty() && DeathModule.DEATH_CERTIFICATION.equals(e.codes.get(0));
    Predicate<Encounter> keepEncounter = encounterNotEmpty.or(isDeathCertification.and(notFutureDated));
    // finally filter out any empty encounters
    filterEntries(record.encounters, Collections.emptyList(), cutoffDate, endTime, keepEncounter);
    return record;
}
Also used : Generator(org.mitre.synthea.engine.Generator) ArrayList(java.util.ArrayList) Person(org.mitre.synthea.world.agents.Person) Pair(org.apache.commons.lang3.tuple.Pair) FixedRecordGroup(org.mitre.synthea.input.FixedRecordGroup) LinkedList(java.util.LinkedList) Path(java.nio.file.Path) Encounter(org.mitre.synthea.world.concepts.HealthRecord.Encounter) IParser(ca.uhn.fhir.parser.IParser) PrintWriter(java.io.PrintWriter) Config(org.mitre.synthea.helpers.Config) Iterator(java.util.Iterator) Files(java.nio.file.Files) Report(org.mitre.synthea.world.concepts.HealthRecord.Report) BufferedWriter(java.io.BufferedWriter) Predicate(java.util.function.Predicate) FileWriter(java.io.FileWriter) StandardOpenOption(java.nio.file.StandardOpenOption) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HealthRecord(org.mitre.synthea.world.concepts.HealthRecord) IOException(java.io.IOException) BlockingQueue(java.util.concurrent.BlockingQueue) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) File(java.io.File) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) Utilities(org.mitre.synthea.helpers.Utilities) Claim(org.mitre.synthea.world.concepts.Claim) List(java.util.List) Paths(java.nio.file.Paths) Observation(org.mitre.synthea.world.concepts.HealthRecord.Observation) DeathModule(org.mitre.synthea.modules.DeathModule) Collections(java.util.Collections) FixedRecord(org.mitre.synthea.input.FixedRecord) Report(org.mitre.synthea.world.concepts.HealthRecord.Report) Observation(org.mitre.synthea.world.concepts.HealthRecord.Observation) Encounter(org.mitre.synthea.world.concepts.HealthRecord.Encounter)

Example 5 with HealthRecord

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

the class LogicTest method test_condition_condition.

@Test
public void test_condition_condition() {
    person.record = new HealthRecord(person);
    assertFalse(doTest("diabetesConditionTest"));
    assertFalse(doTest("alzheimersConditionTest"));
    HealthRecord.Code diabetesCode = new HealthRecord.Code("SNOMED-CT", "73211009", "Diabetes mellitus");
    person.record.conditionStart(time, diabetesCode.code);
    assertTrue(doTest("diabetesConditionTest"));
    assertFalse(doTest("alzheimersConditionTest"));
    time += Utilities.convertTime("years", 10);
    person.record.conditionEnd(time, diabetesCode.code);
    assertFalse(doTest("diabetesConditionTest"));
    HealthRecord.Code alzCode = new HealthRecord.Code("SNOMED-CT", "26929004", "Alzheimer's disease (disorder)");
    HealthRecord.Entry cond = person.record.conditionStart(time, alzCode.code);
    person.attributes.put("Alzheimer's Variant", cond);
    assertTrue(doTest("alzheimersConditionTest"));
}
Also used : HealthRecord(org.mitre.synthea.world.concepts.HealthRecord) Test(org.junit.Test)

Aggregations

HealthRecord (org.mitre.synthea.world.concepts.HealthRecord)14 Test (org.junit.Test)9 Encounter (org.mitre.synthea.world.concepts.HealthRecord.Encounter)5 Person (org.mitre.synthea.world.agents.Person)4 Code (org.mitre.synthea.world.concepts.HealthRecord.Code)4 Observation (org.mitre.synthea.world.concepts.HealthRecord.Observation)2 IParser (ca.uhn.fhir.parser.IParser)1 BufferedWriter (java.io.BufferedWriter)1 File (java.io.File)1 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 PrintWriter (java.io.PrintWriter)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 Paths (java.nio.file.Paths)1 StandardOpenOption (java.nio.file.StandardOpenOption)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 Iterator (java.util.Iterator)1 LinkedList (java.util.LinkedList)1