use of org.hl7.fhir.r4.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 = TRANSACTION_BUNDLE ? ExportHelper.buildFhirSearchUrl("Location", provider.getResourceLocationID()) : findLocationUrl(provider, bundle);
encounterResource.addLocation().setLocation(new Reference().setReference(referenceUrl).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(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;
}
use of org.hl7.fhir.r4.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);
}
use of org.hl7.fhir.r4.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;
}
Aggregations