Search in sources :

Example 1 with CarePlan

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

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

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

the class FhirDstu2 method careplan.

/**
 * Map the given CarePlan to a FHIR CarePlan resource, and add it to the given Bundle.
 *
 * @param rand
 *          Source of randomness to use when generating ids etc
 * @param personEntry
 *          The Entry for the Person
 * @param bundle
 *          Bundle to add the CarePlan to
 * @param encounterEntry
 *          Current Encounter entry
 * @param carePlan
 *          The CarePlan to map to FHIR and add to the bundle
 * @return The added Entry
 */
private static Entry careplan(RandomNumberGenerator rand, Entry personEntry, Bundle bundle, Entry encounterEntry, CarePlan carePlan) {
    ca.uhn.fhir.model.dstu2.resource.CarePlan careplanResource = new ca.uhn.fhir.model.dstu2.resource.CarePlan();
    careplanResource.setSubject(new ResourceReferenceDt(personEntry.getFullUrl()));
    careplanResource.setContext(new ResourceReferenceDt(encounterEntry.getFullUrl()));
    Code code = carePlan.codes.get(0);
    careplanResource.addCategory(mapCodeToCodeableConcept(code, SNOMED_URI));
    NarrativeDt narrative = new NarrativeDt();
    narrative.setStatus(NarrativeStatusEnum.GENERATED);
    narrative.setDiv(code.display);
    careplanResource.setText(narrative);
    CarePlanActivityStatusEnum activityStatus;
    GoalStatusEnum goalStatus;
    PeriodDt period = new PeriodDt().setStart(new DateTimeDt(new Date(carePlan.start)));
    careplanResource.setPeriod(period);
    if (carePlan.stop != 0L) {
        period.setEnd(new DateTimeDt(new Date(carePlan.stop)));
        careplanResource.setStatus(CarePlanStatusEnum.COMPLETED);
        activityStatus = CarePlanActivityStatusEnum.COMPLETED;
        goalStatus = GoalStatusEnum.ACHIEVED;
    } else {
        careplanResource.setStatus(CarePlanStatusEnum.ACTIVE);
        activityStatus = CarePlanActivityStatusEnum.IN_PROGRESS;
        goalStatus = GoalStatusEnum.IN_PROGRESS;
    }
    if (!carePlan.activities.isEmpty()) {
        for (Code activity : carePlan.activities) {
            Activity activityComponent = new Activity();
            ActivityDetail activityDetailComponent = new ActivityDetail();
            activityDetailComponent.setStatus(activityStatus);
            activityDetailComponent.setCode(mapCodeToCodeableConcept(activity, SNOMED_URI));
            activityDetailComponent.setProhibited(new BooleanDt(false));
            activityComponent.setDetail(activityDetailComponent);
            careplanResource.addActivity(activityComponent);
        }
    }
    if (!carePlan.reasons.isEmpty()) {
        // Only one element in list
        Code reason = carePlan.reasons.get(0);
        for (Entry entry : bundle.getEntry()) {
            if (entry.getResource().getResourceName().equals("Condition")) {
                Condition condition = (Condition) entry.getResource();
                // Only one element in list
                CodingDt coding = condition.getCode().getCoding().get(0);
                if (reason.code.equals(coding.getCode())) {
                    careplanResource.addAddresses().setReference(entry.getFullUrl());
                }
            }
        }
    }
    for (JsonObject goal : carePlan.goals) {
        Entry goalEntry = caregoal(rand, bundle, goalStatus, goal);
        careplanResource.addGoal().setReference(goalEntry.getFullUrl());
    }
    return newEntry(rand, bundle, careplanResource);
}
Also used : Condition(ca.uhn.fhir.model.dstu2.resource.Condition) ResourceReferenceDt(ca.uhn.fhir.model.dstu2.composite.ResourceReferenceDt) PeriodDt(ca.uhn.fhir.model.dstu2.composite.PeriodDt) Activity(ca.uhn.fhir.model.dstu2.resource.CarePlan.Activity) JsonObject(com.google.gson.JsonObject) Code(org.mitre.synthea.world.concepts.HealthRecord.Code) NarrativeDt(ca.uhn.fhir.model.dstu2.composite.NarrativeDt) Date(java.util.Date) CarePlan(org.mitre.synthea.world.concepts.HealthRecord.CarePlan) Entry(ca.uhn.fhir.model.dstu2.resource.Bundle.Entry) DateTimeDt(ca.uhn.fhir.model.primitive.DateTimeDt) GoalStatusEnum(ca.uhn.fhir.model.dstu2.valueset.GoalStatusEnum) CodingDt(ca.uhn.fhir.model.dstu2.composite.CodingDt) BooleanDt(ca.uhn.fhir.model.primitive.BooleanDt) CarePlanActivityStatusEnum(ca.uhn.fhir.model.dstu2.valueset.CarePlanActivityStatusEnum) ActivityDetail(ca.uhn.fhir.model.dstu2.resource.CarePlan.ActivityDetail)

Example 4 with CarePlan

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

the class CPCDSExporter 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);
    String payerId = "";
    String payerName = "";
    String type = COVERAGE_TYPES[(int) randomLongWithBounds(0, COVERAGE_TYPES.length - 1)];
    int groupSelect = (int) randomLongWithBounds(0, GROUPIDS.length - 1);
    UUID groupId = GROUPIDS[groupSelect];
    String groupName = GROUP_NAMES[groupSelect];
    int planSelect = (int) randomLongWithBounds(0, PLAN_NAMES.length - 1);
    String planName = PLAN_NAMES[planSelect];
    String planId = PLAN_IDS[planSelect];
    long start = 999999999999999999L;
    long end = 0;
    for (Encounter encounter : person.record.encounters) {
        String encounterID = person.randUUID().toString();
        UUID medRecordNumber = person.randUUID();
        CPCDSAttributes encounterAttributes = new CPCDSAttributes(encounter);
        if (Config.getAsBoolean("exporter.cpcds.single_payer")) {
            payerId = "b1c428d6-4f07-31e0-90f0-68ffa6ff8c76";
            payerName = clean(Config.get("single_payer.name"));
        } else {
            payerId = encounter.claim.payer.uuid.toString();
            payerName = encounter.claim.payer.getName();
        }
        for (CarePlan careplan : encounter.careplans) {
            if (careplan.start < start) {
                start = careplan.start;
            }
            if (careplan.stop > end) {
                end = careplan.stop;
            }
        }
        if (start == 999999999999999999L) {
            start = end;
        }
        String coverageID = coverage(person, personID, start, end, payerId, type, groupId, groupName, planName, planId);
        claim(person, encounter, personID, encounterID, medRecordNumber, encounterAttributes, payerId, coverageID);
        hospital(encounter, encounterAttributes, payerName);
    }
    patients.flush();
    coverages.flush();
    claims.flush();
    practitioners.flush();
    hospitals.flush();
}
Also used : CarePlan(org.mitre.synthea.world.concepts.HealthRecord.CarePlan) Encounter(org.mitre.synthea.world.concepts.HealthRecord.Encounter) UUID(java.util.UUID)

Example 5 with CarePlan

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

the class ValueSetCodeResolverTest method resolveCodesInCarePlan.

@Test
public void resolveCodesInCarePlan() {
    Code carePlanCode = new Code(SNOMED_URI, "734163000", "Care plan");
    Code reasonCode = new Code(SNOMED_URI, "90935002", "Haemophilia");
    reasonCode.valueSet = SNOMED_URI + "?fhir_vs=ecl/<64779008";
    Code stopReason = new Code(SNOMED_URI, "301857004", "Finding of body region");
    stopReason.valueSet = SNOMED_URI + "?fhir_vs=ecl/<" + stopReason.code;
    CarePlan carePlan = person.record.careplanStart(time, carePlanCode.display);
    carePlan.reasons.add(reasonCode);
    person.record.careplanEnd(time, carePlanCode.display, stopReason);
    ValueSetCodeResolver valueSetCodeResolver = new ValueSetCodeResolver(person);
    Person resolvedPerson = valueSetCodeResolver.resolve();
    assertEquals(1, resolvedPerson.record.encounters.size());
    Encounter resolvedEncounter = resolvedPerson.record.encounters.get(0);
    assertEquals(1, resolvedEncounter.careplans.size());
    CarePlan resolvedCarePlan = resolvedEncounter.careplans.get(0);
    assertEquals(1, resolvedCarePlan.reasons.size());
    Code actualCarePlanReason = resolvedCarePlan.reasons.get(0);
    assertEquals(SNOMED_URI, actualCarePlanReason.system);
    assertEquals("773422002", actualCarePlanReason.code);
    assertEquals("East Texas bleeding disorder", actualCarePlanReason.display);
    Code actualStopReason = resolvedCarePlan.stopReason;
    assertEquals(SNOMED_URI, actualStopReason.system);
    assertEquals("246995007", actualStopReason.code);
    assertEquals("Pseudo-hypopyon", actualStopReason.display);
}
Also used : CarePlan(org.mitre.synthea.world.concepts.HealthRecord.CarePlan) Encounter(org.mitre.synthea.world.concepts.HealthRecord.Encounter) Code(org.mitre.synthea.world.concepts.HealthRecord.Code) Person(org.mitre.synthea.world.agents.Person) Test(org.junit.Test)

Aggregations

CarePlan (org.mitre.synthea.world.concepts.HealthRecord.CarePlan)14 Encounter (org.mitre.synthea.world.concepts.HealthRecord.Encounter)8 Medication (org.mitre.synthea.world.concepts.HealthRecord.Medication)7 ImagingStudy (org.mitre.synthea.world.concepts.HealthRecord.ImagingStudy)6 Observation (org.mitre.synthea.world.concepts.HealthRecord.Observation)6 Procedure (org.mitre.synthea.world.concepts.HealthRecord.Procedure)6 HealthRecord (org.mitre.synthea.world.concepts.HealthRecord)5 Code (org.mitre.synthea.world.concepts.HealthRecord.Code)5 Entry (org.mitre.synthea.world.concepts.HealthRecord.Entry)4 Report (org.mitre.synthea.world.concepts.HealthRecord.Report)4 JsonObject (com.google.gson.JsonObject)3 ArrayList (java.util.ArrayList)3 Date (java.util.Date)3 Entry (ca.uhn.fhir.model.dstu2.resource.Bundle.Entry)2 File (java.io.File)2 Path (java.nio.file.Path)2 LinkedList (java.util.LinkedList)2 BundleEntryComponent (org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent)2 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)2 Test (org.junit.Test)2