use of org.hl7.fhir.r4b.model.Attachment in project synthea by synthetichealth.
the class FhirR4 method convertToFHIR.
/**
* Convert the given Person into a FHIR Bundle of the Patient and the
* associated entries from their health record.
*
* @param person Person to generate the FHIR JSON for
* @param stopTime Time the simulation ended
* @return 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(BundleType.TRANSACTION);
} else {
bundle.setType(BundleType.COLLECTION);
}
BundleEntryComponent personEntry = basicInfo(person, bundle, stopTime);
for (Encounter encounter : person.record.encounters) {
BundleEntryComponent encounterEntry = encounter(person, personEntry, bundle, encounter);
for (HealthRecord.Entry condition : encounter.conditions) {
condition(person, personEntry, bundle, encounterEntry, condition);
}
for (HealthRecord.Allergy allergy : encounter.allergies) {
allergy(person, personEntry, bundle, encounterEntry, allergy);
}
for (Observation observation : encounter.observations) {
// Observation resources in v4 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 (HealthRecord.Device device : encounter.devices) {
device(person, personEntry, bundle, device);
}
for (HealthRecord.Supply supply : encounter.supplies) {
supplyDelivery(person, personEntry, bundle, supply, encounter);
}
for (Medication medication : encounter.medications) {
medicationRequest(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) {
BundleEntryComponent careTeamEntry = careTeam(person, personEntry, bundle, encounterEntry, careplan);
carePlan(person, personEntry, bundle, encounterEntry, encounter.provider, careTeamEntry, careplan);
}
for (ImagingStudy imagingStudy : encounter.imagingStudies) {
imagingStudy(person, personEntry, bundle, encounterEntry, imagingStudy);
}
if (USE_US_CORE_IG) {
String clinicalNoteText = ClinicalNoteExporter.export(person, encounter);
boolean lastNote = (encounter == person.record.encounters.get(person.record.encounters.size() - 1));
clinicalNote(person, personEntry, bundle, encounterEntry, clinicalNoteText, lastNote);
}
// one claim per encounter
BundleEntryComponent encounterClaim = encounterClaim(person, personEntry, bundle, encounterEntry, encounter.claim);
explanationOfBenefit(personEntry, bundle, encounterEntry, person, encounterClaim, encounter);
}
if (USE_US_CORE_IG) {
// Add Provenance to the Bundle
provenance(bundle, person, stopTime);
}
return bundle;
}
use of org.hl7.fhir.r4b.model.Attachment in project synthea by synthetichealth.
the class FhirR4 method media.
/**
* Map the given Observation with attachment 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 BundleEntryComponent media(RandomNumberGenerator rand, BundleEntryComponent personEntry, Bundle bundle, BundleEntryComponent encounterEntry, Observation obs) {
org.hl7.fhir.r4.model.Media mediaResource = new org.hl7.fhir.r4.model.Media();
// Hard code as Image since we don't anticipate using video or audio any time soon
Code mediaType = new Code("http://terminology.hl7.org/CodeSystem/media-type", "image", "Image");
if (obs.codes != null && obs.codes.size() > 0) {
List<CodeableConcept> reasonList = obs.codes.stream().map(code -> mapCodeToCodeableConcept(code, SNOMED_URI)).collect(Collectors.toList());
mediaResource.setReasonCode(reasonList);
}
mediaResource.setType(mapCodeToCodeableConcept(mediaType, MEDIA_TYPE_URI));
mediaResource.setStatus(MediaStatus.COMPLETED);
mediaResource.setSubject(new Reference(personEntry.getFullUrl()));
mediaResource.setEncounter(new Reference(encounterEntry.getFullUrl()));
Attachment content = (Attachment) obs.value;
org.hl7.fhir.r4.model.Attachment contentResource = new org.hl7.fhir.r4.model.Attachment();
contentResource.setContentType(content.contentType);
contentResource.setLanguage(content.language);
if (content.data != null) {
contentResource.setDataElement(new org.hl7.fhir.r4.model.Base64BinaryType(content.data));
} else {
contentResource.setSize(content.size);
}
contentResource.setUrl(content.url);
contentResource.setTitle(content.title);
if (content.hash != null) {
contentResource.setHashElement(new org.hl7.fhir.r4.model.Base64BinaryType(content.hash));
}
mediaResource.setWidth(content.width);
mediaResource.setHeight(content.height);
mediaResource.setContent(contentResource);
return newEntry(rand, bundle, mediaResource);
}
use of org.hl7.fhir.r4b.model.Attachment in project synthea by synthetichealth.
the class FhirStu3 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 BundleEntryComponent media(RandomNumberGenerator rand, BundleEntryComponent personEntry, Bundle bundle, BundleEntryComponent encounterEntry, Observation obs) {
org.hl7.fhir.dstu3.model.Media mediaResource = new org.hl7.fhir.dstu3.model.Media();
if (obs.codes != null && obs.codes.size() > 0) {
List<CodeableConcept> reasonList = obs.codes.stream().map(code -> mapCodeToCodeableConcept(code, SNOMED_URI)).collect(Collectors.toList());
mediaResource.setReasonCode(reasonList);
}
// Hard code as an image
mediaResource.setType(DigitalMediaType.PHOTO);
mediaResource.setSubject(new Reference(personEntry.getFullUrl()));
Attachment content = (Attachment) obs.value;
org.hl7.fhir.dstu3.model.Attachment contentResource = new org.hl7.fhir.dstu3.model.Attachment();
contentResource.setContentType(content.contentType);
contentResource.setLanguage(content.language);
if (content.data != null) {
contentResource.setDataElement(new org.hl7.fhir.dstu3.model.Base64BinaryType(content.data));
}
contentResource.setUrl(content.url);
contentResource.setSize(content.size);
contentResource.setTitle(content.title);
if (content.hash != null) {
contentResource.setHashElement(new org.hl7.fhir.dstu3.model.Base64BinaryType(content.hash));
}
mediaResource.setWidth(content.width);
mediaResource.setHeight(content.height);
mediaResource.setContent(contentResource);
return newEntry(rand, bundle, mediaResource);
}
use of org.hl7.fhir.r4b.model.Attachment in project synthea by synthetichealth.
the class FhirStu3 method convertToFHIR.
/**
* Convert the given Person into a FHIR Bundle, containing the Patient and the
* associated entries from their health record.
*
* @param person Person to generate the FHIR from
* @param stopTime Time the simulation ended
* @return 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(BundleType.TRANSACTION);
} else {
bundle.setType(BundleType.COLLECTION);
}
BundleEntryComponent personEntry = basicInfo(person, bundle, stopTime);
for (Encounter encounter : person.record.encounters) {
BundleEntryComponent 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
BundleEntryComponent encounterClaim = encounterClaim(person, personEntry, bundle, encounterEntry, encounter.claim);
explanationOfBenefit(personEntry, bundle, encounterEntry, person, encounterClaim, encounter);
}
return bundle;
}
use of org.hl7.fhir.r4b.model.Attachment in project synthea by synthetichealth.
the class ExportHelper method getObservationValue.
/**
* Helper to get a readable string representation of an Observation's value.
* Units are not included.
*
* @param observation The observation to get the value from
* @return A human-readable string representation of observation.value
*/
public static String getObservationValue(Observation observation) {
String value = null;
if (observation.value instanceof Condition) {
Code conditionCode = ((HealthRecord.Entry) observation.value).codes.get(0);
value = conditionCode.display;
} else if (observation.value instanceof Code) {
value = ((Code) observation.value).display;
} else if (observation.value instanceof String) {
value = (String) observation.value;
} else if (observation.value instanceof Double) {
// round to 1 decimal place for display
value = String.format(Locale.US, "%.1f", observation.value);
} else if (observation.value instanceof SampledData) {
value = sampledDataToValueString((SampledData) observation.value);
} else if (observation.value instanceof Attachment) {
value = attachmentToValueString((Attachment) observation.value);
} else if (observation.value != null) {
value = observation.value.toString();
}
return value;
}
Aggregations