Search in sources :

Example 1 with CareTeamParticipantComponent

use of org.hl7.fhir.r4.model.CareTeam.CareTeamParticipantComponent 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)

Aggregations

Date (java.util.Date)1 CareTeam (org.hl7.fhir.r4.model.CareTeam)1 CareTeamParticipantComponent (org.hl7.fhir.r4.model.CareTeam.CareTeamParticipantComponent)1 DocumentReference (org.hl7.fhir.r4.model.DocumentReference)1 Meta (org.hl7.fhir.r4.model.Meta)1 Patient (org.hl7.fhir.r4.model.Patient)1 Period (org.hl7.fhir.r4.model.Period)1 Reference (org.hl7.fhir.r4.model.Reference)1 Code (org.mitre.synthea.world.concepts.HealthRecord.Code)1 Encounter (org.mitre.synthea.world.concepts.HealthRecord.Encounter)1