Search in sources :

Example 21 with CarePlan

use of org.hl7.fhir.dstu3.model.CarePlan in project org.hl7.fhir.core by hapifhir.

the class TurtleTests method test_careplan_example_GPVisit.

@Test
public void test_careplan_example_GPVisit() throws FileNotFoundException, IOException, Exception {
    System.out.println("careplan-example-GPVisit.ttl");
    new Turtle().parse(TextFile.fileToString("C:\\work\\org.hl7.fhir\\build\\publish\\careplan-example-GPVisit.ttl"));
}
Also used : Turtle(org.hl7.fhir.dstu3.utils.formats.Turtle) Test(org.junit.jupiter.api.Test)

Example 22 with CarePlan

use of org.hl7.fhir.dstu3.model.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 23 with CarePlan

use of org.hl7.fhir.dstu3.model.CarePlan in project synthea by synthetichealth.

the class FhirR4 method careTeam.

/**
 * Map the given CarePlan to a FHIR CareTeam 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 BundleEntryComponent careTeam(RandomNumberGenerator rand, BundleEntryComponent personEntry, Bundle bundle, BundleEntryComponent encounterEntry, CarePlan carePlan) {
    CareTeam careTeam = new CareTeam();
    if (USE_US_CORE_IG) {
        Meta meta = new Meta();
        meta.addProfile("http://hl7.org/fhir/us/core/StructureDefinition/us-core-careteam");
        careTeam.setMeta(meta);
    }
    Period period = new Period().setStart(new Date(carePlan.start));
    careTeam.setPeriod(period);
    if (carePlan.stop != 0L) {
        period.setEnd(new Date(carePlan.stop));
        careTeam.setStatus(CareTeamStatus.INACTIVE);
    } else {
        careTeam.setStatus(CareTeamStatus.ACTIVE);
    }
    careTeam.setSubject(new Reference(personEntry.getFullUrl()));
    careTeam.setEncounter(new Reference(encounterEntry.getFullUrl()));
    if (carePlan.reasons != null && !carePlan.reasons.isEmpty()) {
        for (Code code : carePlan.reasons) {
            careTeam.addReasonCode(mapCodeToCodeableConcept(code, SNOMED_URI));
        }
    }
    // The first participant is the patient...
    CareTeamParticipantComponent participant = careTeam.addParticipant();
    participant.addRole(mapCodeToCodeableConcept(new Code(SNOMED_URI, "116154003", "Patient"), SNOMED_URI));
    Patient patient = (Patient) personEntry.getResource();
    participant.setMember(new Reference().setReference(personEntry.getFullUrl()).setDisplay(patient.getNameFirstRep().getNameAsSingleString()));
    org.hl7.fhir.r4.model.Encounter encounter = (org.hl7.fhir.r4.model.Encounter) encounterEntry.getResource();
    // The second participant is the practitioner...
    if (encounter.hasParticipant()) {
        participant = careTeam.addParticipant();
        participant.addRole(mapCodeToCodeableConcept(new Code(SNOMED_URI, "223366009", "Healthcare professional (occupation)"), SNOMED_URI));
        participant.setMember(encounter.getParticipantFirstRep().getIndividual());
    }
    // The last participant is the organization...
    participant = careTeam.addParticipant();
    participant.addRole(mapCodeToCodeableConcept(new Code(SNOMED_URI, "224891009", "Healthcare services (qualifier value)"), SNOMED_URI));
    participant.setMember(encounter.getServiceProvider());
    careTeam.addManagingOrganization(encounter.getServiceProvider());
    return newEntry(rand, bundle, careTeam);
}
Also used : Meta(org.hl7.fhir.r4.model.Meta) CareTeam(org.hl7.fhir.r4.model.CareTeam) Reference(org.hl7.fhir.r4.model.Reference) DocumentReference(org.hl7.fhir.r4.model.DocumentReference) Period(org.hl7.fhir.r4.model.Period) Patient(org.hl7.fhir.r4.model.Patient) Code(org.mitre.synthea.world.concepts.HealthRecord.Code) Date(java.util.Date) CareTeamParticipantComponent(org.hl7.fhir.r4.model.CareTeam.CareTeamParticipantComponent) Encounter(org.mitre.synthea.world.concepts.HealthRecord.Encounter)

Example 24 with CarePlan

use of org.hl7.fhir.dstu3.model.CarePlan in project synthea by synthetichealth.

the class FhirR4 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 provider       The current provider
 * @param carePlan       The CarePlan to map to FHIR and add to the bundle
 * @return The added Entry
 */
private static BundleEntryComponent carePlan(RandomNumberGenerator rand, BundleEntryComponent personEntry, Bundle bundle, BundleEntryComponent encounterEntry, Provider provider, BundleEntryComponent careTeamEntry, CarePlan carePlan) {
    org.hl7.fhir.r4.model.CarePlan careplanResource = new org.hl7.fhir.r4.model.CarePlan();
    if (USE_US_CORE_IG) {
        Meta meta = new Meta();
        meta.addProfile("http://hl7.org/fhir/us/core/StructureDefinition/us-core-careplan");
        careplanResource.setMeta(meta);
        careplanResource.addCategory(mapCodeToCodeableConcept(new Code("http://hl7.org/fhir/us/core/CodeSystem/careplan-category", "assess-plan", null), null));
    }
    String narrative = "Care Plan for ";
    careplanResource.setIntent(CarePlanIntent.ORDER);
    careplanResource.setSubject(new Reference(personEntry.getFullUrl()));
    careplanResource.setEncounter(new Reference(encounterEntry.getFullUrl()));
    careplanResource.addCareTeam(new Reference(careTeamEntry.getFullUrl()));
    Code code = carePlan.codes.get(0);
    careplanResource.addCategory(mapCodeToCodeableConcept(code, SNOMED_URI));
    narrative += code.display + ".";
    CarePlanActivityStatus activityStatus;
    CodeableConcept goalStatus = new CodeableConcept();
    goalStatus.getCodingFirstRep().setSystem("http://terminology.hl7.org/CodeSystem/goal-achievement");
    Period period = new Period().setStart(new Date(carePlan.start));
    careplanResource.setPeriod(period);
    if (carePlan.stop != 0L) {
        period.setEnd(new Date(carePlan.stop));
        careplanResource.setStatus(CarePlanStatus.COMPLETED);
        activityStatus = CarePlanActivityStatus.COMPLETED;
        goalStatus.getCodingFirstRep().setCode("achieved");
    } else {
        careplanResource.setStatus(CarePlanStatus.ACTIVE);
        activityStatus = CarePlanActivityStatus.INPROGRESS;
        goalStatus.getCodingFirstRep().setCode("in-progress");
    }
    if (!carePlan.activities.isEmpty()) {
        narrative += "<br/>Activities: <ul>";
        String locationUrl = findLocationUrl(provider, bundle);
        for (Code activity : carePlan.activities) {
            narrative += "<li>" + code.display + "</li>";
            CarePlanActivityComponent activityComponent = new CarePlanActivityComponent();
            CarePlanActivityDetailComponent activityDetailComponent = new CarePlanActivityDetailComponent();
            activityDetailComponent.setStatus(activityStatus);
            activityDetailComponent.setLocation(new Reference().setReference(locationUrl).setDisplay(provider.name));
            activityDetailComponent.setCode(mapCodeToCodeableConcept(activity, SNOMED_URI));
            activityComponent.setDetail(activityDetailComponent);
            careplanResource.addActivity(activityComponent);
        }
        narrative += "</ul>";
    }
    if (!carePlan.reasons.isEmpty()) {
        // Only one element in list
        Code reason = carePlan.reasons.get(0);
        narrative += "<br/>Care plan is meant to treat " + reason.display + ".";
        for (BundleEntryComponent entry : bundle.getEntry()) {
            if (entry.getResource().fhirType().equals("Condition")) {
                Condition condition = (Condition) entry.getResource();
                // Only one element in list
                Coding coding = condition.getCode().getCoding().get(0);
                if (reason.code.equals(coding.getCode())) {
                    careplanResource.addAddresses().setReference(entry.getFullUrl());
                }
            }
        }
    }
    for (JsonObject goal : carePlan.goals) {
        BundleEntryComponent goalEntry = careGoal(rand, bundle, personEntry, carePlan.start, goalStatus, goal);
        careplanResource.addGoal().setReference(goalEntry.getFullUrl());
    }
    careplanResource.setText(new Narrative().setStatus(NarrativeStatus.GENERATED).setDiv(new XhtmlNode(NodeType.Element).setValue(narrative)));
    return newEntry(rand, bundle, careplanResource);
}
Also used : Condition(org.hl7.fhir.r4.model.Condition) Meta(org.hl7.fhir.r4.model.Meta) Reference(org.hl7.fhir.r4.model.Reference) DocumentReference(org.hl7.fhir.r4.model.DocumentReference) Period(org.hl7.fhir.r4.model.Period) JsonObject(com.google.gson.JsonObject) Code(org.mitre.synthea.world.concepts.HealthRecord.Code) Date(java.util.Date) CarePlanActivityDetailComponent(org.hl7.fhir.r4.model.CarePlan.CarePlanActivityDetailComponent) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode) CarePlan(org.mitre.synthea.world.concepts.HealthRecord.CarePlan) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) Coding(org.hl7.fhir.r4.model.Coding) Narrative(org.hl7.fhir.r4.model.Narrative) CarePlanActivityStatus(org.hl7.fhir.r4.model.CarePlan.CarePlanActivityStatus) CarePlanActivityComponent(org.hl7.fhir.r4.model.CarePlan.CarePlanActivityComponent) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept)

Example 25 with CarePlan

use of org.hl7.fhir.dstu3.model.CarePlan in project synthea by synthetichealth.

the class FhirStu3 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 BundleEntryComponent careplan(RandomNumberGenerator rand, BundleEntryComponent personEntry, Bundle bundle, BundleEntryComponent encounterEntry, CarePlan carePlan) {
    org.hl7.fhir.dstu3.model.CarePlan careplanResource = new org.hl7.fhir.dstu3.model.CarePlan();
    careplanResource.setIntent(CarePlanIntent.ORDER);
    careplanResource.setSubject(new Reference(personEntry.getFullUrl()));
    careplanResource.setContext(new Reference(encounterEntry.getFullUrl()));
    Code code = carePlan.codes.get(0);
    careplanResource.addCategory(mapCodeToCodeableConcept(code, SNOMED_URI));
    CarePlanActivityStatus activityStatus;
    GoalStatus goalStatus;
    Period period = new Period().setStart(new Date(carePlan.start));
    careplanResource.setPeriod(period);
    if (carePlan.stop != 0L) {
        period.setEnd(new Date(carePlan.stop));
        careplanResource.setStatus(CarePlanStatus.COMPLETED);
        activityStatus = CarePlanActivityStatus.COMPLETED;
        goalStatus = GoalStatus.ACHIEVED;
    } else {
        careplanResource.setStatus(CarePlanStatus.ACTIVE);
        activityStatus = CarePlanActivityStatus.INPROGRESS;
        goalStatus = GoalStatus.INPROGRESS;
    }
    if (!carePlan.activities.isEmpty()) {
        for (Code activity : carePlan.activities) {
            CarePlanActivityComponent activityComponent = new CarePlanActivityComponent();
            CarePlanActivityDetailComponent activityDetailComponent = new CarePlanActivityDetailComponent();
            activityDetailComponent.setStatus(activityStatus);
            activityDetailComponent.setCode(mapCodeToCodeableConcept(activity, SNOMED_URI));
            activityComponent.setDetail(activityDetailComponent);
            careplanResource.addActivity(activityComponent);
        }
    }
    if (!carePlan.reasons.isEmpty()) {
        // Only one element in list
        Code reason = carePlan.reasons.get(0);
        for (BundleEntryComponent entry : bundle.getEntry()) {
            if (entry.getResource().fhirType().equals("Condition")) {
                Condition condition = (Condition) entry.getResource();
                // Only one element in list
                Coding coding = condition.getCode().getCoding().get(0);
                if (reason.code.equals(coding.getCode())) {
                    careplanResource.addAddresses().setReference(entry.getFullUrl());
                }
            }
        }
    }
    for (JsonObject goal : carePlan.goals) {
        BundleEntryComponent goalEntry = caregoal(rand, bundle, goalStatus, goal);
        careplanResource.addGoal().setReference(goalEntry.getFullUrl());
    }
    return newEntry(rand, bundle, careplanResource);
}
Also used : Condition(org.hl7.fhir.dstu3.model.Condition) Reference(org.hl7.fhir.dstu3.model.Reference) Period(org.hl7.fhir.dstu3.model.Period) JsonObject(com.google.gson.JsonObject) Code(org.mitre.synthea.world.concepts.HealthRecord.Code) Date(java.util.Date) CarePlanActivityDetailComponent(org.hl7.fhir.dstu3.model.CarePlan.CarePlanActivityDetailComponent) CarePlan(org.mitre.synthea.world.concepts.HealthRecord.CarePlan) BundleEntryComponent(org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent) GoalStatus(org.hl7.fhir.dstu3.model.Goal.GoalStatus) Coding(org.hl7.fhir.dstu3.model.Coding) CarePlanActivityStatus(org.hl7.fhir.dstu3.model.CarePlan.CarePlanActivityStatus) CarePlanActivityComponent(org.hl7.fhir.dstu3.model.CarePlan.CarePlanActivityComponent)

Aggregations

Test (org.junit.jupiter.api.Test)14 Turtle (org.hl7.fhir.dstu3.utils.formats.Turtle)10 CarePlan (org.hl7.fhir.dstu3.model.CarePlan)8 Reference (org.hl7.fhir.dstu3.model.Reference)7 ArrayList (java.util.ArrayList)6 Complex (org.hl7.fhir.dstu2016may.formats.RdfGenerator.Complex)5 Reference (org.hl7.fhir.r4.model.Reference)4 Date (java.util.Date)3 Composition (org.hl7.fhir.dstu3.model.Composition)3 DomainResource (org.hl7.fhir.dstu3.model.DomainResource)3 Encounter (org.hl7.fhir.dstu3.model.Encounter)3 Complex (org.hl7.fhir.dstu3.utils.formats.Turtle.Complex)3 CarePlan (org.hl7.fhir.r4.model.CarePlan)3 CarePlan (org.mitre.synthea.world.concepts.HealthRecord.CarePlan)3 SystemRequestDetails (ca.uhn.fhir.jpa.partition.SystemRequestDetails)2 Operation (ca.uhn.fhir.rest.annotation.Operation)2 JsonObject (com.google.gson.JsonObject)2 IOException (java.io.IOException)2 Bundle (org.hl7.fhir.dstu3.model.Bundle)2 BundleEntryComponent (org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent)2