use of org.mitre.synthea.engine.Components.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.mitre.synthea.engine.Components.Attachment 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 org.mitre.synthea.engine.Components.Attachment 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 org.mitre.synthea.engine.Components.Attachment in project synthea by synthetichealth.
the class StateTest method observation.
@Test
public void observation() throws Exception {
Module module = TestHelper.getFixture("observation.json");
State vitalsign = module.getState("VitalSign");
assertTrue(vitalsign.process(person, time));
person.history.add(vitalsign);
State encounter = module.getState("SomeEncounter");
assertTrue(encounter.process(person, time));
person.history.add(encounter);
State physiology = module.getState("Simulate_CVS");
assertTrue(physiology.process(person, time));
person.history.add(physiology);
State vitalObs = module.getState("VitalSignObservation");
assertTrue(vitalObs.process(person, time));
State codeObs = module.getState("CodeObservation");
assertTrue(codeObs.process(person, time));
State sampleObs = module.getState("SampledDataObservation");
assertTrue(sampleObs.process(person, time));
State chartObs = module.getState("ChartObservation");
assertTrue(chartObs.process(person, time));
State urlObs = module.getState("UrlObservation");
assertTrue(urlObs.process(person, time));
HealthRecord.Observation vitalObservation = person.record.encounters.get(0).observations.get(0);
assertEquals(120.0, vitalObservation.value);
assertEquals("vital-signs", vitalObservation.category);
assertEquals("mm[Hg]", vitalObservation.unit);
Code vitalObsCode = vitalObservation.codes.get(0);
assertEquals("8480-6", vitalObsCode.code);
assertEquals("Systolic Blood Pressure", vitalObsCode.display);
HealthRecord.Observation codeObservation = person.record.encounters.get(0).observations.get(1);
assertEquals("procedure", codeObservation.category);
// assertEquals("LOINC", codeObservation.value.system);
// assertEquals("25428-4", codeObservation.value.code);
// assertEquals("Glucose [Presence] in Urine by Test strip", codeObservation.value.system);
Code testCode = new Code("LOINC", "25428-4", "Glucose [Presence] in Urine by Test strip");
assertEquals(testCode.toString(), codeObservation.value.toString());
Code codeObsCode = codeObservation.codes.get(0);
assertEquals("24356-8", codeObsCode.code);
assertEquals("Urinalysis complete panel - Urine", codeObsCode.display);
HealthRecord.Observation sampleObservation = person.record.encounters.get(0).observations.get(2);
assertEquals("procedure", sampleObservation.category);
assertEquals("mmHg", sampleObservation.unit);
assertTrue(sampleObservation.value instanceof SampledData);
SampledData sampledData = (SampledData) sampleObservation.value;
assertEquals("P_ao", sampledData.attributes.get(0));
assertEquals("P_lv", sampledData.attributes.get(1));
assertEquals("P_rv", sampledData.attributes.get(2));
assertEquals(3, sampledData.series.size());
HealthRecord.Observation chartObservation = person.record.encounters.get(0).observations.get(3);
assertTrue(chartObservation.value instanceof Attachment);
Attachment obsAttachment = (Attachment) chartObservation.value;
assertEquals("Media Test", obsAttachment.title);
assertEquals(400, obsAttachment.width);
assertEquals(200, obsAttachment.height);
assertEquals("image/png", obsAttachment.contentType);
assertTrue(Base64.isBase64(obsAttachment.data));
HealthRecord.Observation urlObservation = person.record.encounters.get(0).observations.get(4);
assertTrue(urlObservation.value instanceof Attachment);
Attachment urlAttachment = (Attachment) urlObservation.value;
assertEquals("Test Image URL", urlAttachment.title);
assertEquals("66bb1cb31c9b502daa7081ae36631f9df9c6d16a", urlAttachment.hash);
assertEquals("en-US", urlAttachment.language);
assertEquals("https://example.com/image/12498596132", urlAttachment.url);
}
use of org.mitre.synthea.engine.Components.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);
}
Aggregations