use of ca.uhn.fhir.model.dstu2.valueset.EncounterClassEnum 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);
}
Aggregations