Search in sources :

Example 86 with Encounter

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

the class FhirStu3 method medicationClaim.

/**
 * Create an entry for the given Claim, which references a Medication.
 *
 * @param rand Source of randomness to use when generating ids etc
 * @param personEntry Entry for the person
 * @param bundle The Bundle to add to
 * @param encounterEntry The current Encounter
 * @param claim the Claim object
 * @param medicationEntry The Entry for the Medication object, previously created
 * @return the added Entry
 */
private static BundleEntryComponent medicationClaim(RandomNumberGenerator rand, BundleEntryComponent personEntry, Bundle bundle, BundleEntryComponent encounterEntry, Claim claim, BundleEntryComponent medicationEntry) {
    org.hl7.fhir.dstu3.model.Claim claimResource = new org.hl7.fhir.dstu3.model.Claim();
    org.hl7.fhir.dstu3.model.Encounter encounterResource = (org.hl7.fhir.dstu3.model.Encounter) encounterEntry.getResource();
    claimResource.setStatus(ClaimStatus.ACTIVE);
    claimResource.setUse(org.hl7.fhir.dstu3.model.Claim.Use.COMPLETE);
    // duration of encounter
    claimResource.setBillablePeriod(encounterResource.getPeriod());
    claimResource.setPatient(new Reference(personEntry.getFullUrl()));
    claimResource.setOrganization(encounterResource.getServiceProvider());
    // add item for encounter
    claimResource.addItem(new org.hl7.fhir.dstu3.model.Claim.ItemComponent(new PositiveIntType(1)).addEncounter(new Reference(encounterEntry.getFullUrl())));
    // add prescription.
    claimResource.setPrescription(new Reference(medicationEntry.getFullUrl()));
    Money moneyResource = new Money();
    moneyResource.setValue(claim.getTotalClaimCost());
    moneyResource.setCode("USD");
    moneyResource.setSystem("urn:iso:std:iso:4217");
    claimResource.setTotal(moneyResource);
    return newEntry(rand, bundle, claimResource);
}
Also used : Reference(org.hl7.fhir.dstu3.model.Reference) PositiveIntType(org.hl7.fhir.dstu3.model.PositiveIntType) Money(org.hl7.fhir.dstu3.model.Money) ItemComponent(org.hl7.fhir.dstu3.model.Claim.ItemComponent) SupplyDeliverySuppliedItemComponent(org.hl7.fhir.dstu3.model.SupplyDelivery.SupplyDeliverySuppliedItemComponent) Encounter(org.mitre.synthea.world.concepts.HealthRecord.Encounter) Claim(org.mitre.synthea.world.concepts.Claim)

Example 87 with Encounter

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

the class FhirStu3 method convertToFHIR.

/**
 * Convert the given Person into a FHIR Bundle, containing the Patient and the
 * associated entries from their health record.
 *
 * @param person Person to generate the FHIR from
 * @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.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
        BundleEntryComponent encounterClaim = encounterClaim(person, personEntry, bundle, encounterEntry, encounter.claim);
        explanationOfBenefit(personEntry, bundle, encounterEntry, person, encounterClaim, encounter);
    }
    return bundle;
}
Also used : DiagnosticReport(org.hl7.fhir.dstu3.model.DiagnosticReport) Report(org.mitre.synthea.world.concepts.HealthRecord.Report) Bundle(org.hl7.fhir.dstu3.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.dstu3.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 88 with Encounter

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

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

the class ClinicalNoteExporter method export.

/**
 * Export all the encounter notes for a Person in a single
 * document, with the most recent encounter on top.
 *
 * @param person Person to write notes about.
 * @return A set of consolidated clinical notes as plain text.
 */
public static String export(Person person) {
    String consolidatedNotes = "";
    for (int i = person.record.encounters.size() - 1; i >= 0; i--) {
        Encounter encounter = person.record.encounters.get(i);
        consolidatedNotes += export(person, encounter) + "\n\n";
    }
    return consolidatedNotes;
}
Also used : Encounter(org.mitre.synthea.world.concepts.HealthRecord.Encounter)

Example 90 with Encounter

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

the class ClinicalNoteExporter method export.

/**
 * Export a clinical note for a Person at a given Encounter.
 *
 * @param person Person to write a note about.
 * @param encounter Encounter to write a note about.
 * @return Clinical note as a plain text string.
 */
public static String export(Person person, Encounter encounter) {
    // The export templates fill in the record by accessing the attributes
    // of the Person, so we add a few attributes just for the purposes of export.
    Set<String> activeAllergies = new HashSet<String>();
    Set<String> activeConditions = new HashSet<String>();
    Set<String> activeMedications = new HashSet<String>();
    Set<String> activeProcedures = new HashSet<String>();
    // need to loop through record until THIS encounter
    // to get previous data, since "present" is what is present
    // at time of export and NOT what is present at this
    // encounter.
    long encounterTime = encounter.start;
    for (Encounter pastEncounter : person.record.encounters) {
        if (pastEncounter == encounter || pastEncounter.stop >= encounterTime) {
            break;
        }
        for (Entry allergy : pastEncounter.allergies) {
            if (allergy.stop != 0L || allergy.stop > encounterTime) {
                activeAllergies.add(allergy.codes.get(0).display);
            }
        }
        for (Entry condition : pastEncounter.conditions) {
            if (condition.stop != 0L || condition.stop > encounterTime) {
                activeConditions.add(condition.codes.get(0).display);
            }
        }
        for (Medication medication : pastEncounter.medications) {
            if (medication.stop != 0L || medication.stop > encounterTime) {
                activeMedications.add(medication.codes.get(0).display);
            }
        }
        for (Procedure procedure : pastEncounter.procedures) {
            if (procedure.stop != 0L || procedure.stop > encounterTime) {
                activeProcedures.add(procedure.codes.get(0).display);
            }
        }
    }
    Payer payer = person.coverage.getPayerAtTime(encounter.start);
    if (payer == null) {
        person.attributes.put("ehr_insurance", "unknown insurance coverage");
    } else {
        person.attributes.put("ehr_insurance", payer.getName());
    }
    person.attributes.put("ehr_ageInYears", person.ageInYears(encounter.start));
    person.attributes.put("ehr_ageInMonths", person.ageInMonths(encounter.start));
    person.attributes.put("ehr_symptoms", person.getSymptoms());
    person.attributes.put("ehr_activeAllergies", activeAllergies);
    person.attributes.put("ehr_activeConditions", activeConditions);
    if (activeConditions.contains("Normal pregnancy")) {
        person.attributes.put("pregnant", true);
    } else {
        person.attributes.remove("pregnant");
    }
    person.attributes.put("ehr_activeMedications", activeMedications);
    person.attributes.put("ehr_activeProcedures", activeProcedures);
    person.attributes.put("ehr_conditions", encounter.conditions);
    person.attributes.put("ehr_allergies", encounter.allergies);
    person.attributes.put("ehr_procedures", encounter.procedures);
    person.attributes.put("ehr_immunizations", encounter.immunizations);
    person.attributes.put("ehr_medications", encounter.medications);
    person.attributes.put("ehr_careplans", encounter.careplans);
    person.attributes.put("ehr_imaging_studies", encounter.imagingStudies);
    person.attributes.put("time", encounter.start);
    if (person.attributes.containsKey(LifecycleModule.QUIT_SMOKING_AGE)) {
        person.attributes.put("quit_smoking_age", person.attributes.get(LifecycleModule.QUIT_SMOKING_AGE));
    }
    person.attributes.put("race_lookup", RaceAndEthnicity.LOOK_UP_CDC_RACE);
    person.attributes.put("ethnicity_lookup", RaceAndEthnicity.LOOK_UP_CDC_ETHNICITY_CODE);
    person.attributes.put("ethnicity_display_lookup", RaceAndEthnicity.LOOK_UP_CDC_ETHNICITY_DISPLAY);
    StringWriter writer = new StringWriter();
    try {
        Template template = TEMPLATES.getTemplate("note.ftl");
        template.process(person.attributes, writer);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return writer.toString();
}
Also used : Payer(org.mitre.synthea.world.agents.Payer) Entry(org.mitre.synthea.world.concepts.HealthRecord.Entry) StringWriter(java.io.StringWriter) Medication(org.mitre.synthea.world.concepts.HealthRecord.Medication) Encounter(org.mitre.synthea.world.concepts.HealthRecord.Encounter) Procedure(org.mitre.synthea.world.concepts.HealthRecord.Procedure) TemplateException(freemarker.template.TemplateException) HashSet(java.util.HashSet) Template(freemarker.template.Template)

Aggregations

Encounter (org.mitre.synthea.world.concepts.HealthRecord.Encounter)99 Test (org.junit.Test)54 Code (org.mitre.synthea.world.concepts.HealthRecord.Code)51 HealthRecord (org.mitre.synthea.world.concepts.HealthRecord)29 Person (org.mitre.synthea.world.agents.Person)28 ProviderTest (org.mitre.synthea.world.agents.ProviderTest)22 DeathModule (org.mitre.synthea.modules.DeathModule)17 QualityOfLifeModule (org.mitre.synthea.modules.QualityOfLifeModule)17 ArrayList (java.util.ArrayList)16 CardiovascularDiseaseModule (org.mitre.synthea.modules.CardiovascularDiseaseModule)16 EncounterModule (org.mitre.synthea.modules.EncounterModule)16 LifecycleModule (org.mitre.synthea.modules.LifecycleModule)16 WeightLossModule (org.mitre.synthea.modules.WeightLossModule)16 Provider (org.mitre.synthea.world.agents.Provider)16 Medication (org.mitre.synthea.world.concepts.HealthRecord.Medication)16 Observation (org.mitre.synthea.world.concepts.HealthRecord.Observation)16 Procedure (org.mitre.synthea.world.concepts.HealthRecord.Procedure)16 Report (org.mitre.synthea.world.concepts.HealthRecord.Report)14 Date (java.util.Date)13 Claim (org.mitre.synthea.world.concepts.Claim)12