Search in sources :

Example 1 with Report

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

the class HealthRecordTest method testReportAllObs.

@Test
public void testReportAllObs() {
    Person person = new Person(0L);
    person.coverage.setPayerAtTime(time, noInsurance);
    HealthRecord record = new HealthRecord(person);
    Encounter encounter = record.encounterStart(time, EncounterType.WELLNESS);
    record.observation(time, "A", "A");
    record.observation(time, "B", "B");
    record.observation(time, "C", "C");
    Report report = record.report(time, "R", 3);
    Assert.assertEquals(3, encounter.observations.size());
    Assert.assertEquals(3, report.observations.size());
    Assert.assertEquals("A", report.observations.get(0).value);
    Assert.assertEquals("B", report.observations.get(1).value);
    Assert.assertEquals("C", report.observations.get(2).value);
}
Also used : Report(org.mitre.synthea.world.concepts.HealthRecord.Report) Encounter(org.mitre.synthea.world.concepts.HealthRecord.Encounter) Person(org.mitre.synthea.world.agents.Person) Test(org.junit.Test)

Example 2 with Report

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

the class FhirR4 method convertToFHIR.

/**
 * Convert the given Person into a FHIR Bundle of the Patient and the
 * associated entries from their health record.
 *
 * @param person   Person to generate the FHIR JSON for
 * @param stopTime Time the simulation ended
 * @return FHIR Bundle containing the Person's health record
 */
public static Bundle convertToFHIR(Person person, long stopTime) {
    Bundle bundle = new Bundle();
    if (TRANSACTION_BUNDLE) {
        bundle.setType(BundleType.TRANSACTION);
    } else {
        bundle.setType(BundleType.COLLECTION);
    }
    BundleEntryComponent personEntry = basicInfo(person, bundle, stopTime);
    for (Encounter encounter : person.record.encounters) {
        BundleEntryComponent encounterEntry = encounter(person, personEntry, bundle, encounter);
        for (HealthRecord.Entry condition : encounter.conditions) {
            condition(person, personEntry, bundle, encounterEntry, condition);
        }
        for (HealthRecord.Allergy allergy : encounter.allergies) {
            allergy(person, personEntry, bundle, encounterEntry, allergy);
        }
        for (Observation observation : encounter.observations) {
            // Observation resources in v4 don't support Attachments
            if (observation.value instanceof Attachment) {
                media(person, personEntry, bundle, encounterEntry, observation);
            } else {
                observation(person, personEntry, bundle, encounterEntry, observation);
            }
        }
        for (Procedure procedure : encounter.procedures) {
            procedure(person, personEntry, bundle, encounterEntry, procedure);
        }
        for (HealthRecord.Device device : encounter.devices) {
            device(person, personEntry, bundle, device);
        }
        for (HealthRecord.Supply supply : encounter.supplies) {
            supplyDelivery(person, personEntry, bundle, supply, encounter);
        }
        for (Medication medication : encounter.medications) {
            medicationRequest(person, personEntry, bundle, encounterEntry, medication);
        }
        for (HealthRecord.Entry immunization : encounter.immunizations) {
            immunization(person, personEntry, bundle, encounterEntry, immunization);
        }
        for (Report report : encounter.reports) {
            report(person, personEntry, bundle, encounterEntry, report);
        }
        for (CarePlan careplan : encounter.careplans) {
            BundleEntryComponent careTeamEntry = careTeam(person, personEntry, bundle, encounterEntry, careplan);
            carePlan(person, personEntry, bundle, encounterEntry, encounter.provider, careTeamEntry, careplan);
        }
        for (ImagingStudy imagingStudy : encounter.imagingStudies) {
            imagingStudy(person, personEntry, bundle, encounterEntry, imagingStudy);
        }
        if (USE_US_CORE_IG) {
            String clinicalNoteText = ClinicalNoteExporter.export(person, encounter);
            boolean lastNote = (encounter == person.record.encounters.get(person.record.encounters.size() - 1));
            clinicalNote(person, personEntry, bundle, encounterEntry, clinicalNoteText, lastNote);
        }
        // one claim per encounter
        BundleEntryComponent encounterClaim = encounterClaim(person, personEntry, bundle, encounterEntry, encounter.claim);
        explanationOfBenefit(personEntry, bundle, encounterEntry, person, encounterClaim, encounter);
    }
    if (USE_US_CORE_IG) {
        // Add Provenance to the Bundle
        provenance(bundle, person, stopTime);
    }
    return bundle;
}
Also used : DiagnosticReport(org.hl7.fhir.r4.model.DiagnosticReport) Report(org.mitre.synthea.world.concepts.HealthRecord.Report) Bundle(org.hl7.fhir.r4.model.Bundle) ImagingStudy(org.mitre.synthea.world.concepts.HealthRecord.ImagingStudy) Attachment(org.mitre.synthea.engine.Components.Attachment) HealthRecord(org.mitre.synthea.world.concepts.HealthRecord) CarePlan(org.mitre.synthea.world.concepts.HealthRecord.CarePlan) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) 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)

Example 3 with Report

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

the class FhirDstu2 method convertToFHIR.

/**
 * Convert the given Person into a FHIR Bundle with the Patient and the
 * associated entries from their health record.
 *
 * @param person Person to generate the FHIR Bundle
 * @param stopTime Time the simulation ended
 * @return String containing a FHIR Bundle containing the Person's health record
 */
public static Bundle convertToFHIR(Person person, long stopTime) {
    Bundle bundle = new Bundle();
    if (TRANSACTION_BUNDLE) {
        bundle.setType(BundleTypeEnum.TRANSACTION);
    } else {
        bundle.setType(BundleTypeEnum.COLLECTION);
    }
    Entry personEntry = basicInfo(person, bundle, stopTime);
    for (Encounter encounter : person.record.encounters) {
        Entry encounterEntry = encounter(person, personEntry, bundle, encounter);
        for (HealthRecord.Entry condition : encounter.conditions) {
            condition(person, personEntry, bundle, encounterEntry, condition);
        }
        for (HealthRecord.Entry allergy : encounter.allergies) {
            allergy(person, personEntry, bundle, encounterEntry, allergy);
        }
        for (Observation observation : encounter.observations) {
            // Observation resources in stu3 don't support Attachments
            if (observation.value instanceof Attachment) {
                media(person, personEntry, bundle, encounterEntry, observation);
            } else {
                observation(person, personEntry, bundle, encounterEntry, observation);
            }
        }
        for (Procedure procedure : encounter.procedures) {
            procedure(person, personEntry, bundle, encounterEntry, procedure);
        }
        for (Medication medication : encounter.medications) {
            medication(person, personEntry, bundle, encounterEntry, medication);
        }
        for (HealthRecord.Entry immunization : encounter.immunizations) {
            immunization(person, personEntry, bundle, encounterEntry, immunization);
        }
        for (Report report : encounter.reports) {
            report(person, personEntry, bundle, encounterEntry, report);
        }
        for (CarePlan careplan : encounter.careplans) {
            careplan(person, personEntry, bundle, encounterEntry, careplan);
        }
        for (ImagingStudy imagingStudy : encounter.imagingStudies) {
            imagingStudy(person, personEntry, bundle, encounterEntry, imagingStudy);
        }
        for (HealthRecord.Device device : encounter.devices) {
            device(person, personEntry, bundle, device);
        }
        for (HealthRecord.Supply supply : encounter.supplies) {
            supplyDelivery(person, personEntry, bundle, supply, encounter);
        }
        // one claim per encounter
        encounterClaim(person, personEntry, bundle, encounterEntry, encounter.claim);
    }
    return bundle;
}
Also used : Report(org.mitre.synthea.world.concepts.HealthRecord.Report) DiagnosticReport(ca.uhn.fhir.model.dstu2.resource.DiagnosticReport) Bundle(ca.uhn.fhir.model.dstu2.resource.Bundle) ImagingStudy(org.mitre.synthea.world.concepts.HealthRecord.ImagingStudy) Attachment(org.mitre.synthea.engine.Components.Attachment) Entry(ca.uhn.fhir.model.dstu2.resource.Bundle.Entry) HealthRecord(org.mitre.synthea.world.concepts.HealthRecord) CarePlan(org.mitre.synthea.world.concepts.HealthRecord.CarePlan) 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)

Example 4 with Report

use of org.mitre.synthea.world.concepts.HealthRecord.Report 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 Report

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

the class DeathModuleTest method testDeathCertificate.

@Test
public void testDeathCertificate() {
    /*
     * death_certificate: { description: 'U.S. standard certificate of death - 2003 revision', code:
     * '69409-1' }, cause_of_death: { description: 'Cause of Death [US Standard Certificate of
     * Death]', code: '69453-9', value_type: 'condition' },
     *
     * death_certification: {description: 'Death Certification', codes: {'SNOMED-CT' =>
     * ['308646001']}, class: 'ambulatory'}
     */
    Code causeOfDeath = new Code("SNOMED-CT", "12345", "Some disease");
    person.recordDeath(time, causeOfDeath);
    DeathModule.process(person, time);
    Encounter enc = person.record.encounters.get(0);
    assertEquals(EncounterType.WELLNESS.toString(), enc.type);
    assertEquals(time, enc.start);
    Code code = enc.codes.get(0);
    assertEquals("308646001", code.code);
    assertEquals("Death Certification", code.display);
    Report report = enc.reports.get(0);
    assertEquals("69409-1", report.type);
    assertEquals(time, report.start);
    code = report.codes.get(0);
    assertEquals("69409-1", code.code);
    assertEquals("U.S. standard certificate of death - 2003 revision", code.display);
    Observation obs = report.observations.get(0);
    assertEquals("69453-9", obs.type);
    assertEquals(time, obs.start);
    code = (Code) obs.value;
    assertEquals(causeOfDeath.code, code.code);
    assertEquals(causeOfDeath.display, code.display);
    code = obs.codes.get(0);
    assertEquals("69453-9", code.code);
    assertEquals("Cause of Death [US Standard Certificate of Death]", code.display);
}
Also used : Report(org.mitre.synthea.world.concepts.HealthRecord.Report) Observation(org.mitre.synthea.world.concepts.HealthRecord.Observation) Encounter(org.mitre.synthea.world.concepts.HealthRecord.Encounter) Code(org.mitre.synthea.world.concepts.HealthRecord.Code) Test(org.junit.Test)

Aggregations

Report (org.mitre.synthea.world.concepts.HealthRecord.Report)13 Encounter (org.mitre.synthea.world.concepts.HealthRecord.Encounter)12 Observation (org.mitre.synthea.world.concepts.HealthRecord.Observation)10 Medication (org.mitre.synthea.world.concepts.HealthRecord.Medication)6 Procedure (org.mitre.synthea.world.concepts.HealthRecord.Procedure)6 Test (org.junit.Test)5 Person (org.mitre.synthea.world.agents.Person)5 HealthRecord (org.mitre.synthea.world.concepts.HealthRecord)5 CarePlan (org.mitre.synthea.world.concepts.HealthRecord.CarePlan)5 ImagingStudy (org.mitre.synthea.world.concepts.HealthRecord.ImagingStudy)5 ArrayList (java.util.ArrayList)3 Attachment (org.mitre.synthea.engine.Components.Attachment)3 Entry (org.mitre.synthea.world.concepts.HealthRecord.Entry)3 File (java.io.File)2 Path (java.nio.file.Path)2 LinkedList (java.util.LinkedList)2 Code (org.mitre.synthea.world.concepts.HealthRecord.Code)2 Bundle (ca.uhn.fhir.model.dstu2.resource.Bundle)1 Entry (ca.uhn.fhir.model.dstu2.resource.Bundle.Entry)1 DiagnosticReport (ca.uhn.fhir.model.dstu2.resource.DiagnosticReport)1