use of org.hl7.fhir.r4.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.r4.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.r4.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;
}
use of org.hl7.fhir.r4.model.Attachment in project cqf-ruler by DBCG.
the class ActivityDefinitionApplyProvider method resolveDiagnosticReport.
private DiagnosticReport resolveDiagnosticReport(ActivityDefinition activityDefinition, String patientId) {
DiagnosticReport diagnosticReport = new DiagnosticReport();
diagnosticReport.setStatus(DiagnosticReport.DiagnosticReportStatus.UNKNOWN);
diagnosticReport.setSubject(new Reference(patientId));
if (activityDefinition.hasCode()) {
diagnosticReport.setCode(activityDefinition.getCode());
} else {
throw new ActivityDefinitionApplyException("Missing required ActivityDefinition.code property for DiagnosticReport");
}
if (activityDefinition.hasRelatedArtifact()) {
List<Attachment> presentedFormAttachments = new ArrayList<>();
for (RelatedArtifact artifact : activityDefinition.getRelatedArtifact()) {
Attachment attachment = new Attachment();
if (artifact.hasUrl()) {
attachment.setUrl(artifact.getUrl());
}
if (artifact.hasDisplay()) {
attachment.setTitle(artifact.getDisplay());
}
presentedFormAttachments.add(attachment);
}
diagnosticReport.setPresentedForm(presentedFormAttachments);
}
return diagnosticReport;
}
use of org.hl7.fhir.r4.model.Attachment in project cqf-ruler by DBCG.
the class ActivityDefinitionApplyProvider method resolveCommunicationRequest.
private CommunicationRequest resolveCommunicationRequest(ActivityDefinition activityDefinition, String patientId) {
CommunicationRequest communicationRequest = new CommunicationRequest();
communicationRequest.setStatus(CommunicationRequest.CommunicationRequestStatus.UNKNOWN);
communicationRequest.setSubject(new Reference(patientId));
// Unsure if this is correct - this is the way Motive is doing it...
if (activityDefinition.hasCode()) {
if (activityDefinition.getCode().hasText()) {
communicationRequest.addPayload().setContent(new StringType(activityDefinition.getCode().getText()));
}
}
if (activityDefinition.hasRelatedArtifact()) {
for (RelatedArtifact artifact : activityDefinition.getRelatedArtifact()) {
if (artifact.hasUrl()) {
Attachment attachment = new Attachment().setUrl(artifact.getUrl());
if (artifact.hasDisplay()) {
attachment.setTitle(artifact.getDisplay());
}
CommunicationRequest.CommunicationRequestPayloadComponent payload = new CommunicationRequest.CommunicationRequestPayloadComponent();
payload.setContent(artifact.hasDisplay() ? attachment.setTitle(artifact.getDisplay()) : attachment);
communicationRequest.setPayload(Collections.singletonList(payload));
}
// TODO - other relatedArtifact types
}
}
return communicationRequest;
}
Aggregations