Search in sources :

Example 1 with Hospitalization

use of ca.uhn.fhir.model.dstu2.resource.Encounter.Hospitalization in project synthea by synthetichealth.

the class FhirDstu2 method encounter.

/**
 * Map the given Encounter into a FHIR Encounter resource, and add it to the given Bundle.
 *
 * @param person
 *          Patient at the encounter.
 * @param personEntry
 *          Entry for the Person
 * @param bundle
 *          The Bundle to add to
 * @param encounter
 *          The current Encounter
 * @return The added Entry
 */
private static Entry encounter(Person person, Entry personEntry, Bundle bundle, Encounter encounter) {
    ca.uhn.fhir.model.dstu2.resource.Encounter encounterResource = new ca.uhn.fhir.model.dstu2.resource.Encounter();
    encounterResource.setPatient(new ResourceReferenceDt(personEntry.getFullUrl()));
    encounterResource.setStatus(EncounterStateEnum.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));
    }
    EncounterClassEnum encounterClass = EncounterClassEnum.forCode(encounter.type);
    if (encounterClass == null) {
        encounterClass = EncounterClassEnum.AMBULATORY;
    }
    encounterResource.setClassElement(encounterClass);
    encounterResource.setPeriod(new PeriodDt().setStart(new DateTimeDt(new Date(encounter.start))).setEnd(new DateTimeDt(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 ResourceReferenceDt(ExportHelper.buildFhirSearchUrl("Organization", provider.getResourceID())));
    } else {
        String providerFullUrl = findProviderUrl(provider, bundle);
        if (providerFullUrl != null) {
            encounterResource.setServiceProvider(new ResourceReferenceDt(providerFullUrl));
        } else {
            Entry providerOrganization = provider(bundle, provider);
            encounterResource.setServiceProvider(new ResourceReferenceDt(providerOrganization.getFullUrl()));
        }
    }
    encounterResource.getServiceProvider().setDisplay(provider.name);
    if (encounter.clinician != null) {
        if (TRANSACTION_BUNDLE) {
            encounterResource.addParticipant().setIndividual(new ResourceReferenceDt(ExportHelper.buildFhirNpiSearchUrl(encounter.clinician)));
        } else {
            String practitionerFullUrl = findPractitioner(encounter.clinician, bundle);
            if (practitionerFullUrl != null) {
                encounterResource.addParticipant().setIndividual(new ResourceReferenceDt(practitionerFullUrl));
            } else {
                Entry practitioner = practitioner(bundle, encounter.clinician);
                encounterResource.addParticipant().setIndividual(new ResourceReferenceDt(practitioner.getFullUrl()));
            }
        }
        encounterResource.getParticipantFirstRep().getIndividual().setDisplay(encounter.clinician.getFullname());
    }
    if (encounter.discharge != null) {
        Hospitalization hospitalization = new Hospitalization();
        Code dischargeDisposition = new Code(DISCHARGE_URI, encounter.discharge.code, encounter.discharge.display);
        hospitalization.setDischargeDisposition(mapCodeToCodeableConcept(dischargeDisposition, DISCHARGE_URI));
        encounterResource.setHospitalization(hospitalization);
    }
    return newEntry(person, bundle, encounterResource);
}
Also used : ResourceReferenceDt(ca.uhn.fhir.model.dstu2.composite.ResourceReferenceDt) PeriodDt(ca.uhn.fhir.model.dstu2.composite.PeriodDt) Hospitalization(ca.uhn.fhir.model.dstu2.resource.Encounter.Hospitalization) EncounterClassEnum(ca.uhn.fhir.model.dstu2.valueset.EncounterClassEnum) Code(org.mitre.synthea.world.concepts.HealthRecord.Code) Date(java.util.Date) Provider(org.mitre.synthea.world.agents.Provider) Entry(ca.uhn.fhir.model.dstu2.resource.Bundle.Entry) DateTimeDt(ca.uhn.fhir.model.primitive.DateTimeDt) Encounter(org.mitre.synthea.world.concepts.HealthRecord.Encounter)

Aggregations

PeriodDt (ca.uhn.fhir.model.dstu2.composite.PeriodDt)1 ResourceReferenceDt (ca.uhn.fhir.model.dstu2.composite.ResourceReferenceDt)1 Entry (ca.uhn.fhir.model.dstu2.resource.Bundle.Entry)1 Hospitalization (ca.uhn.fhir.model.dstu2.resource.Encounter.Hospitalization)1 EncounterClassEnum (ca.uhn.fhir.model.dstu2.valueset.EncounterClassEnum)1 DateTimeDt (ca.uhn.fhir.model.primitive.DateTimeDt)1 Date (java.util.Date)1 Provider (org.mitre.synthea.world.agents.Provider)1 Code (org.mitre.synthea.world.concepts.HealthRecord.Code)1 Encounter (org.mitre.synthea.world.concepts.HealthRecord.Encounter)1