Search in sources :

Example 1 with EncounterHospitalizationComponent

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

the class FhirR4 method encounter.

/**
 * Map the given Encounter into a FHIR Encounter resource, and add it to the given Bundle.
 *
 * @param personEntry Entry for the Person
 * @param bundle      The Bundle to add to
 * @param encounter   The current Encounter
 * @return The added Entry
 */
private static BundleEntryComponent encounter(Person person, BundleEntryComponent personEntry, Bundle bundle, Encounter encounter) {
    org.hl7.fhir.r4.model.Encounter encounterResource = new org.hl7.fhir.r4.model.Encounter();
    if (USE_US_CORE_IG) {
        Meta meta = new Meta();
        meta.addProfile("http://hl7.org/fhir/us/core/StructureDefinition/us-core-encounter");
        encounterResource.setMeta(meta);
    } else if (USE_SHR_EXTENSIONS) {
        encounterResource.setMeta(new Meta().addProfile(SHR_EXT + "shr-encounter-EncounterPerformed"));
        Extension performedContext = new Extension();
        performedContext.setUrl(SHR_EXT + "shr-action-PerformedContext-extension");
        performedContext.addExtension(SHR_EXT + "shr-action-Status-extension", new CodeType("finished"));
        encounterResource.addExtension(performedContext);
    }
    Patient patient = (Patient) personEntry.getResource();
    encounterResource.setSubject(new Reference().setReference(personEntry.getFullUrl()).setDisplay(patient.getNameFirstRep().getNameAsSingleString()));
    encounterResource.setStatus(EncounterStatus.FINISHED);
    if (encounter.codes.isEmpty()) {
        // wellness encounter
        encounterResource.addType().addCoding().setCode("185349003").setDisplay("Encounter for check up").setSystem(SNOMED_URI);
    } else {
        Code code = encounter.codes.get(0);
        encounterResource.addType(mapCodeToCodeableConcept(code, SNOMED_URI));
    }
    Coding classCode = new Coding();
    classCode.setCode(EncounterType.fromString(encounter.type).code());
    classCode.setSystem("http://terminology.hl7.org/CodeSystem/v3-ActCode");
    encounterResource.setClass_(classCode);
    encounterResource.setPeriod(new Period().setStart(new Date(encounter.start)).setEnd(new Date(encounter.stop)));
    if (encounter.reason != null) {
        encounterResource.addReasonCode().addCoding().setCode(encounter.reason.code).setDisplay(encounter.reason.display).setSystem(SNOMED_URI);
    }
    Provider provider = encounter.provider;
    if (provider == null) {
        // no associated provider, patient goes to wellness provider
        provider = person.getProvider(EncounterType.WELLNESS, encounter.start);
    }
    if (TRANSACTION_BUNDLE) {
        encounterResource.setServiceProvider(new Reference(ExportHelper.buildFhirSearchUrl("Organization", provider.getResourceID())));
    } else {
        String providerFullUrl = findProviderUrl(provider, bundle);
        if (providerFullUrl != null) {
            encounterResource.setServiceProvider(new Reference(providerFullUrl));
        } else {
            BundleEntryComponent providerOrganization = provider(person, bundle, provider);
            encounterResource.setServiceProvider(new Reference(providerOrganization.getFullUrl()));
        }
    }
    encounterResource.getServiceProvider().setDisplay(provider.name);
    if (USE_US_CORE_IG) {
        String referenceUrl;
        String display;
        if (TRANSACTION_BUNDLE) {
            if (encounter.type.equals(EncounterType.VIRTUAL.toString())) {
                referenceUrl = ExportHelper.buildFhirSearchUrl("Location", FhirR4PatientHome.getPatientHome().getId());
                display = "Patient's Home";
            } else {
                referenceUrl = ExportHelper.buildFhirSearchUrl("Location", provider.getResourceLocationID());
                display = provider.name;
            }
        } else {
            if (encounter.type.equals(EncounterType.VIRTUAL.toString())) {
                referenceUrl = addPatientHomeLocation(bundle);
                display = "Patient's Home";
            } else {
                referenceUrl = findLocationUrl(provider, bundle);
                display = provider.name;
            }
        }
        encounterResource.addLocation().setLocation(new Reference().setReference(referenceUrl).setDisplay(display));
    }
    if (encounter.clinician != null) {
        if (TRANSACTION_BUNDLE) {
            encounterResource.addParticipant().setIndividual(new Reference(ExportHelper.buildFhirNpiSearchUrl(encounter.clinician)));
        } else {
            String practitionerFullUrl = findPractitioner(encounter.clinician, bundle);
            if (practitionerFullUrl != null) {
                encounterResource.addParticipant().setIndividual(new Reference(practitionerFullUrl));
            } else {
                BundleEntryComponent practitioner = practitioner(person, bundle, encounter.clinician);
                encounterResource.addParticipant().setIndividual(new Reference(practitioner.getFullUrl()));
            }
        }
        encounterResource.getParticipantFirstRep().getIndividual().setDisplay(encounter.clinician.getFullname());
        encounterResource.getParticipantFirstRep().addType(mapCodeToCodeableConcept(new Code("http://terminology.hl7.org/CodeSystem/v3-ParticipationType", "PPRF", "primary performer"), null));
        encounterResource.getParticipantFirstRep().setPeriod(encounterResource.getPeriod());
    }
    if (encounter.discharge != null) {
        EncounterHospitalizationComponent hospitalization = new EncounterHospitalizationComponent();
        Code dischargeDisposition = new Code(DISCHARGE_URI, encounter.discharge.code, encounter.discharge.display);
        hospitalization.setDischargeDisposition(mapCodeToCodeableConcept(dischargeDisposition, DISCHARGE_URI));
        encounterResource.setHospitalization(hospitalization);
    }
    BundleEntryComponent entry = newEntry(person, bundle, encounterResource);
    if (USE_US_CORE_IG) {
        // US Core Encounters should have an identifier to support the required
        // Encounter.identifier search parameter
        encounterResource.addIdentifier().setUse(IdentifierUse.OFFICIAL).setSystem(SYNTHEA_IDENTIFIER).setValue(encounterResource.getId());
    }
    return entry;
}
Also used : Meta(org.hl7.fhir.r4.model.Meta) Reference(org.hl7.fhir.r4.model.Reference) DocumentReference(org.hl7.fhir.r4.model.DocumentReference) Patient(org.hl7.fhir.r4.model.Patient) Period(org.hl7.fhir.r4.model.Period) EncounterHospitalizationComponent(org.hl7.fhir.r4.model.Encounter.EncounterHospitalizationComponent) Code(org.mitre.synthea.world.concepts.HealthRecord.Code) Date(java.util.Date) Provider(org.mitre.synthea.world.agents.Provider) Extension(org.hl7.fhir.r4.model.Extension) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) Coding(org.hl7.fhir.r4.model.Coding) Encounter(org.mitre.synthea.world.concepts.HealthRecord.Encounter) CodeType(org.hl7.fhir.r4.model.CodeType)

Example 2 with EncounterHospitalizationComponent

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

the class FhirStu3 method encounter.

/**
 * Map the given Encounter into a FHIR Encounter resource, and add it to the given Bundle.
 *
 * @param personEntry Entry for the Person
 * @param bundle The Bundle to add to
 * @param encounter The current Encounter
 * @return The added Entry
 */
private static BundleEntryComponent encounter(Person person, BundleEntryComponent personEntry, Bundle bundle, Encounter encounter) {
    org.hl7.fhir.dstu3.model.Encounter encounterResource = new org.hl7.fhir.dstu3.model.Encounter();
    encounterResource.setSubject(new Reference(personEntry.getFullUrl()));
    encounterResource.setStatus(EncounterStatus.FINISHED);
    if (encounter.codes.isEmpty()) {
        // wellness encounter
        encounterResource.addType().addCoding().setCode("185349003").setDisplay("Encounter for check up").setSystem(SNOMED_URI);
    } else {
        Code code = encounter.codes.get(0);
        encounterResource.addType(mapCodeToCodeableConcept(code, SNOMED_URI));
    }
    Coding classCode = new Coding();
    classCode.setCode(EncounterType.fromString(encounter.type).code());
    classCode.setSystem("http://terminology.hl7.org/CodeSystem/v3-ActCode");
    encounterResource.setClass_(classCode);
    encounterResource.setPeriod(new Period().setStart(new Date(encounter.start)).setEnd(new Date(encounter.stop)));
    if (encounter.reason != null) {
        encounterResource.addReason().addCoding().setCode(encounter.reason.code).setDisplay(encounter.reason.display).setSystem(SNOMED_URI);
    }
    Provider provider = encounter.provider;
    if (provider == null) {
        // no associated provider, patient goes to wellness provider
        provider = person.getProvider(EncounterType.WELLNESS, encounter.start);
    }
    if (TRANSACTION_BUNDLE) {
        encounterResource.setServiceProvider(new Reference(ExportHelper.buildFhirSearchUrl("Organization", provider.getResourceID())));
    } else {
        String providerFullUrl = findProviderUrl(provider, bundle);
        if (providerFullUrl != null) {
            encounterResource.setServiceProvider(new Reference(providerFullUrl));
        } else {
            BundleEntryComponent providerOrganization = provider(bundle, provider);
            encounterResource.setServiceProvider(new Reference(providerOrganization.getFullUrl()));
        }
    }
    encounterResource.getServiceProvider().setDisplay(provider.name);
    if (encounter.clinician != null) {
        if (TRANSACTION_BUNDLE) {
            encounterResource.addParticipant().setIndividual(new Reference(ExportHelper.buildFhirNpiSearchUrl(encounter.clinician)));
        } else {
            String practitionerFullUrl = findPractitioner(encounter.clinician, bundle);
            if (practitionerFullUrl != null) {
                encounterResource.addParticipant().setIndividual(new Reference(practitionerFullUrl));
            } else {
                BundleEntryComponent practitioner = practitioner(bundle, encounter.clinician);
                encounterResource.addParticipant().setIndividual(new Reference(practitioner.getFullUrl()));
            }
        }
        encounterResource.getParticipantFirstRep().getIndividual().setDisplay(encounter.clinician.getFullname());
    }
    if (encounter.discharge != null) {
        EncounterHospitalizationComponent hospitalization = new EncounterHospitalizationComponent();
        Code dischargeDisposition = new Code(DISCHARGE_URI, encounter.discharge.code, encounter.discharge.display);
        hospitalization.setDischargeDisposition(mapCodeToCodeableConcept(dischargeDisposition, DISCHARGE_URI));
        encounterResource.setHospitalization(hospitalization);
    }
    if (USE_SHR_EXTENSIONS) {
        encounterResource.setMeta(new Meta().addProfile(SHR_EXT + "shr-encounter-EncounterPerformed"));
        // required fields for this profile are status & action-PerformedContext-extension
        Extension performedContext = new Extension();
        performedContext.setUrl(SHR_EXT + "shr-action-PerformedContext-extension");
        performedContext.addExtension(SHR_EXT + "shr-action-Status-extension", new CodeType("finished"));
        encounterResource.addExtension(performedContext);
    }
    return newEntry(person, bundle, encounterResource);
}
Also used : Meta(org.hl7.fhir.dstu3.model.Meta) Reference(org.hl7.fhir.dstu3.model.Reference) Period(org.hl7.fhir.dstu3.model.Period) EncounterHospitalizationComponent(org.hl7.fhir.dstu3.model.Encounter.EncounterHospitalizationComponent) Code(org.mitre.synthea.world.concepts.HealthRecord.Code) Date(java.util.Date) Provider(org.mitre.synthea.world.agents.Provider) Extension(org.hl7.fhir.dstu3.model.Extension) BundleEntryComponent(org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent) Coding(org.hl7.fhir.dstu3.model.Coding) Encounter(org.mitre.synthea.world.concepts.HealthRecord.Encounter) CodeType(org.hl7.fhir.dstu3.model.CodeType)

Example 3 with EncounterHospitalizationComponent

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

the class ArgonautConverter method makeEncounter.

// /serviceEvent/performer/functionCode: 9036
private Encounter makeEncounter(CDAUtilities cda, Convert convert, Element doc, Context context, String id) throws Exception {
    Element co = cda.getChild(doc, "componentOf");
    Element ee = cda.getChild(co, "encompassingEncounter");
    scanSection("Encounter", co);
    Element of = cda.getChild(doc, "documentationOf");
    Element se = cda.getChild(of, "serviceEvent");
    scanSection("Encounter", of);
    Encounter enc = new Encounter();
    enc.setId(id);
    enc.setUserData("profile", "http://hl7.org/fhir/StructureDefinition/encounter-daf-dafencounter");
    context.setEncounter(enc);
    enc.setSubject(context.getSubjectRef());
    for (Element e : cda.getChildren(ee, "id")) enc.getIdentifier().add(convert.makeIdentifierFromII(e));
    checkGenerateIdentifier(enc.getIdentifier(), enc);
    Period p1 = convert.makePeriodFromIVL(cda.getChild(ee, "effectiveTime"));
    // Period p2 = convert.makePeriodFromIVL(cda.getChild(se, "effectiveTime")); // well, what is this?
    // if (!Base.compareDeep(p1, p2, false))
    // throw new Error("episode time mismatch: "+NarrativeGenerator.displayPeriod(p1)+" & "+NarrativeGenerator.displayPeriod(p2));
    enc.setPeriod(p1);
    if (p1.hasEnd())
        enc.setStatus(EncounterStatus.FINISHED);
    else
        enc.setStatus(EncounterStatus.INPROGRESS);
    enc.setClass_(context.getEncClass());
    Element dd = cda.getChild(ee, "dischargeDispositionCode");
    if (dd != null) {
        enc.setHospitalization(new EncounterHospitalizationComponent());
        enc.getHospitalization().setDischargeDisposition(convert.makeCodeableConceptFromCD(dd));
    }
    for (Element e : cda.getChildren(se, "performer")) {
        Practitioner p = processPerformer(cda, convert, context, e, "assignedEntity", "assignedPerson");
        Reference ref = new Reference().setReference("Practitioner/" + p.getId()).setDisplay(p.getUserString("display"));
        if (ref != null)
            enc.addParticipant().setIndividual(ref);
    }
    return enc;
}
Also used : Element(org.w3c.dom.Element) EncounterHospitalizationComponent(org.hl7.fhir.dstu3.model.Encounter.EncounterHospitalizationComponent)

Aggregations

Date (java.util.Date)2 EncounterHospitalizationComponent (org.hl7.fhir.dstu3.model.Encounter.EncounterHospitalizationComponent)2 Provider (org.mitre.synthea.world.agents.Provider)2 Code (org.mitre.synthea.world.concepts.HealthRecord.Code)2 Encounter (org.mitre.synthea.world.concepts.HealthRecord.Encounter)2 BundleEntryComponent (org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent)1 CodeType (org.hl7.fhir.dstu3.model.CodeType)1 Coding (org.hl7.fhir.dstu3.model.Coding)1 Extension (org.hl7.fhir.dstu3.model.Extension)1 Meta (org.hl7.fhir.dstu3.model.Meta)1 Period (org.hl7.fhir.dstu3.model.Period)1 Reference (org.hl7.fhir.dstu3.model.Reference)1 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)1 CodeType (org.hl7.fhir.r4.model.CodeType)1 Coding (org.hl7.fhir.r4.model.Coding)1 DocumentReference (org.hl7.fhir.r4.model.DocumentReference)1 EncounterHospitalizationComponent (org.hl7.fhir.r4.model.Encounter.EncounterHospitalizationComponent)1 Extension (org.hl7.fhir.r4.model.Extension)1 Meta (org.hl7.fhir.r4.model.Meta)1 Patient (org.hl7.fhir.r4.model.Patient)1