use of ca.uhn.fhir.model.dstu2.resource.Encounter in project synthea by synthetichealth.
the class FhirDstu2 method procedure.
/**
* Map the given Procedure into a FHIR Procedure resource, and add it to the given Bundle.
*
* @param rand
* Source of randomness to use when generating ids etc
* @param personEntry
* The Person entry
* @param bundle
* Bundle to add to
* @param encounterEntry
* The current Encounter entry
* @param procedure
* The Procedure
* @return The added Entry
*/
private static Entry procedure(RandomNumberGenerator rand, Entry personEntry, Bundle bundle, Entry encounterEntry, Procedure procedure) {
ca.uhn.fhir.model.dstu2.resource.Procedure procedureResource = new ca.uhn.fhir.model.dstu2.resource.Procedure();
procedureResource.setStatus(ProcedureStatusEnum.COMPLETED);
procedureResource.setSubject(new ResourceReferenceDt(personEntry.getFullUrl()));
procedureResource.setEncounter(new ResourceReferenceDt(encounterEntry.getFullUrl()));
Code code = procedure.codes.get(0);
procedureResource.setCode(mapCodeToCodeableConcept(code, SNOMED_URI));
if (procedure.stop != 0L) {
Date startDate = new Date(procedure.start);
Date endDate = new Date(procedure.stop);
procedureResource.setPerformed(new PeriodDt().setStart(new DateTimeDt(startDate)).setEnd(new DateTimeDt(endDate)));
} else {
procedureResource.setPerformed(convertFhirDateTime(procedure.start, true));
}
if (!procedure.reasons.isEmpty()) {
// Only one element in list
Code reason = procedure.reasons.get(0);
for (Entry entry : bundle.getEntry()) {
if (entry.getResource().getResourceName().equals("Condition")) {
Condition condition = (Condition) entry.getResource();
// Only one element in list
CodingDt coding = condition.getCode().getCoding().get(0);
if (reason.code.equals(coding.getCode())) {
procedureResource.setReason(new ResourceReferenceDt(entry.getFullUrl()));
}
}
}
}
Entry procedureEntry = newEntry(rand, bundle, procedureResource);
procedure.fullUrl = procedureEntry.getFullUrl();
return procedureEntry;
}
use of ca.uhn.fhir.model.dstu2.resource.Encounter in project synthea by synthetichealth.
the class FhirDstu2 method convertToFHIR.
/**
* Convert the given Person into a FHIR Bundle with the Patient and the
* associated entries from their health record.
*
* @param person Person to generate the FHIR Bundle
* @param stopTime Time the simulation ended
* @return String containing a FHIR Bundle containing the Person's health record
*/
public static Bundle convertToFHIR(Person person, long stopTime) {
Bundle bundle = new Bundle();
if (TRANSACTION_BUNDLE) {
bundle.setType(BundleTypeEnum.TRANSACTION);
} else {
bundle.setType(BundleTypeEnum.COLLECTION);
}
Entry personEntry = basicInfo(person, bundle, stopTime);
for (Encounter encounter : person.record.encounters) {
Entry encounterEntry = encounter(person, personEntry, bundle, encounter);
for (HealthRecord.Entry condition : encounter.conditions) {
condition(person, personEntry, bundle, encounterEntry, condition);
}
for (HealthRecord.Entry allergy : encounter.allergies) {
allergy(person, personEntry, bundle, encounterEntry, allergy);
}
for (Observation observation : encounter.observations) {
// Observation resources in stu3 don't support Attachments
if (observation.value instanceof Attachment) {
media(person, personEntry, bundle, encounterEntry, observation);
} else {
observation(person, personEntry, bundle, encounterEntry, observation);
}
}
for (Procedure procedure : encounter.procedures) {
procedure(person, personEntry, bundle, encounterEntry, procedure);
}
for (Medication medication : encounter.medications) {
medication(person, personEntry, bundle, encounterEntry, medication);
}
for (HealthRecord.Entry immunization : encounter.immunizations) {
immunization(person, personEntry, bundle, encounterEntry, immunization);
}
for (Report report : encounter.reports) {
report(person, personEntry, bundle, encounterEntry, report);
}
for (CarePlan careplan : encounter.careplans) {
careplan(person, personEntry, bundle, encounterEntry, careplan);
}
for (ImagingStudy imagingStudy : encounter.imagingStudies) {
imagingStudy(person, personEntry, bundle, encounterEntry, imagingStudy);
}
for (HealthRecord.Device device : encounter.devices) {
device(person, personEntry, bundle, device);
}
for (HealthRecord.Supply supply : encounter.supplies) {
supplyDelivery(person, personEntry, bundle, supply, encounter);
}
// one claim per encounter
encounterClaim(person, personEntry, bundle, encounterEntry, encounter.claim);
}
return bundle;
}
use of ca.uhn.fhir.model.dstu2.resource.Encounter in project synthea by synthetichealth.
the class FhirDstu2 method condition.
/**
* Map the Condition into a FHIR Condition 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
* The Bundle to add to
* @param encounterEntry
* The current Encounter entry
* @param condition
* The Condition
* @return The added Entry
*/
private static Entry condition(RandomNumberGenerator rand, Entry personEntry, Bundle bundle, Entry encounterEntry, HealthRecord.Entry condition) {
Condition conditionResource = new Condition();
conditionResource.setPatient(new ResourceReferenceDt(personEntry.getFullUrl()));
conditionResource.setEncounter(new ResourceReferenceDt(encounterEntry.getFullUrl()));
Code code = condition.codes.get(0);
conditionResource.setCode(mapCodeToCodeableConcept(code, SNOMED_URI));
conditionResource.setCategory(ConditionCategoryCodesEnum.DIAGNOSIS);
conditionResource.setVerificationStatus(ConditionVerificationStatusEnum.CONFIRMED);
conditionResource.setClinicalStatus(ConditionClinicalStatusCodesEnum.ACTIVE);
conditionResource.setOnset(convertFhirDateTime(condition.start, true));
conditionResource.setDateRecorded(new DateDt(new Date(condition.start)));
if (condition.stop != 0) {
conditionResource.setAbatement(convertFhirDateTime(condition.stop, true));
conditionResource.setClinicalStatus(ConditionClinicalStatusCodesEnum.RESOLVED);
}
Entry conditionEntry = newEntry(rand, bundle, conditionResource);
condition.fullUrl = conditionEntry.getFullUrl();
return conditionEntry;
}
use of ca.uhn.fhir.model.dstu2.resource.Encounter in project synthea by synthetichealth.
the class FhirDstu2 method media.
/**
* Map the given Media element to a FHIR Media 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 Media to
* @param encounterEntry Current Encounter entry
* @param obs The Observation to map to FHIR and add to the bundle
* @return The added Entry
*/
private static Entry media(RandomNumberGenerator rand, Entry personEntry, Bundle bundle, Entry encounterEntry, Observation obs) {
ca.uhn.fhir.model.dstu2.resource.Media mediaResource = new ca.uhn.fhir.model.dstu2.resource.Media();
// Hard code as a photo
mediaResource.setType(DigitalMediaTypeEnum.PHOTO);
mediaResource.setSubject(new ResourceReferenceDt(personEntry.getFullUrl()));
Attachment content = (Attachment) obs.value;
ca.uhn.fhir.model.dstu2.composite.AttachmentDt contentResource = new ca.uhn.fhir.model.dstu2.composite.AttachmentDt();
contentResource.setContentType(content.contentType);
contentResource.setLanguage(content.language);
if (content.data != null) {
ca.uhn.fhir.model.primitive.Base64BinaryDt data = new ca.uhn.fhir.model.primitive.Base64BinaryDt();
data.setValueAsString(content.data);
contentResource.setData(data);
}
contentResource.setUrl(content.url);
contentResource.setSize(content.size);
contentResource.setTitle(content.title);
if (content.hash != null) {
ca.uhn.fhir.model.primitive.Base64BinaryDt hash = new ca.uhn.fhir.model.primitive.Base64BinaryDt();
hash.setValueAsString(content.hash);
contentResource.setHash(hash);
}
mediaResource.setWidth(content.width);
mediaResource.setHeight(content.height);
mediaResource.setContent(contentResource);
return newEntry(rand, bundle, mediaResource);
}
use of ca.uhn.fhir.model.dstu2.resource.Encounter 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