use of ca.uhn.fhir.model.dstu2.resource.Observation 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.Observation 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.Observation in project synthea by synthetichealth.
the class FhirDstu2 method mapValueToSampledData.
/**
* Maps a Synthea internal SampledData object to the FHIR standard SampledData
* representation.
*
* @param value Synthea internal SampledData instance
* @param unit Observation unit value
* @return
*/
static SampledDataDt mapValueToSampledData(Components.SampledData value, String unit) {
SampledDataDt recordData = new SampledDataDt();
SimpleQuantityDt origin = new SimpleQuantityDt();
origin.setValue(new BigDecimal(value.originValue)).setCode(unit).setSystem(UNITSOFMEASURE_URI).setUnit(unit);
recordData.setOrigin(origin);
// Use the period from the first series. They should all be the same.
// FHIR output is milliseconds so we need to convert from TimeSeriesData seconds.
recordData.setPeriod(value.series.get(0).getPeriod() * 1000);
// Set optional fields if they were provided
if (value.factor != null) {
recordData.setFactor(value.factor);
}
if (value.lowerLimit != null) {
recordData.setLowerLimit(value.lowerLimit);
}
if (value.upperLimit != null) {
recordData.setUpperLimit(value.upperLimit);
}
recordData.setDimensions(value.series.size());
recordData.setData(ExportHelper.sampledDataToValueString(value));
return recordData;
}
use of ca.uhn.fhir.model.dstu2.resource.Observation in project synthea by synthetichealth.
the class FhirDstu2 method report.
/**
* Map the given Report to a FHIR DiagnosticReport 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 Report to
* @param encounterEntry
* Current Encounter entry
* @param report
* The Report
* @return The added Entry
*/
private static Entry report(RandomNumberGenerator rand, Entry personEntry, Bundle bundle, Entry encounterEntry, Report report) {
DiagnosticReport reportResource = new DiagnosticReport();
reportResource.setStatus(DiagnosticReportStatusEnum.FINAL);
/*
* Technically, the CodeableConcept system should be "http://hl7.org/fhir/v2/0074"
* But the official Argonauts profiles incorrectly list the category pattern as
* the ValueSet (which contains the above system) as
* "http://hl7.org/fhir/ValueSet/diagnostic-service-sections", so we repeat the
* error here.
*/
CodeableConceptDt category = new CodeableConceptDt("http://hl7.org/fhir/ValueSet/diagnostic-service-sections", "LAB");
reportResource.setCategory(category);
reportResource.setCode(mapCodeToCodeableConcept(report.codes.get(0), LOINC_URI));
reportResource.setSubject(new ResourceReferenceDt(personEntry.getFullUrl()));
reportResource.setEncounter(new ResourceReferenceDt(encounterEntry.getFullUrl()));
reportResource.setEffective(convertFhirDateTime(report.start, true));
reportResource.setIssued(new InstantDt(new Date(report.start)));
ca.uhn.fhir.model.dstu2.resource.Encounter encounter = (ca.uhn.fhir.model.dstu2.resource.Encounter) encounterEntry.getResource();
reportResource.setPerformer(encounter.getServiceProvider());
for (Observation observation : report.observations) {
ResourceReferenceDt reference = new ResourceReferenceDt(observation.fullUrl);
reference.setDisplay(observation.codes.get(0).display);
List<ResourceReferenceDt> result = new ArrayList<ResourceReferenceDt>();
result.add(reference);
reportResource.setResult(result);
}
return newEntry(rand, bundle, reportResource);
}
use of ca.uhn.fhir.model.dstu2.resource.Observation in project synthea by synthetichealth.
the class CodeResolveAndExportTest method verifyEncounterCodeR4.
private void verifyEncounterCodeR4() throws IOException {
InputStream inputStream = new FileInputStream(r4OutputPath.toFile().getAbsolutePath());
org.hl7.fhir.r4.model.Bundle bundle = (org.hl7.fhir.r4.model.Bundle) FhirR4.getContext().newJsonParser().parseResource(inputStream);
// Find encounter reason code.
Optional<org.hl7.fhir.r4.model.Bundle.BundleEntryComponent> maybeEncounterEntry = bundle.getEntry().stream().filter(entry -> entry.getResource().getResourceType().equals(org.hl7.fhir.r4.model.ResourceType.Encounter)).findFirst();
assertTrue(maybeEncounterEntry.isPresent());
org.hl7.fhir.r4.model.Encounter encounterResource = (org.hl7.fhir.r4.model.Encounter) maybeEncounterEntry.get().getResource();
assertEquals(encounterResource.getReasonCode().size(), 1);
org.hl7.fhir.r4.model.CodeableConcept encounterReason = encounterResource.getReasonCode().get(0);
assertEquals(encounterReason.getCoding().size(), 1);
org.hl7.fhir.r4.model.Coding reasonCoding = encounterReason.getCoding().get(0);
// Check encounter reason code.
assertEquals(SNOMED_URI, reasonCoding.getSystem());
assertEquals(EXPECTED_REASON_CODE, reasonCoding.getCode());
assertEquals(EXPECTED_REASON_DISPLAY, reasonCoding.getDisplay());
Optional<org.hl7.fhir.r4.model.Bundle.BundleEntryComponent> maybeObservationEntry = bundle.getEntry().stream().filter(entry -> entry.getResource().getResourceType().equals(org.hl7.fhir.r4.model.ResourceType.Observation)).findFirst();
assertTrue(maybeObservationEntry.isPresent());
// Find observation type code.
org.hl7.fhir.r4.model.Observation observationResource = (org.hl7.fhir.r4.model.Observation) maybeObservationEntry.get().getResource();
org.hl7.fhir.r4.model.CodeableConcept observationType = observationResource.getCode();
assertNotNull(observationType);
assertEquals(observationType.getCoding().size(), 1);
org.hl7.fhir.r4.model.Coding observationTypeCoding = observationType.getCoding().get(0);
// Check observation type code.
assertEquals(LOINC_URI, observationTypeCoding.getSystem());
assertEquals(OBSERVATION_CODE, observationTypeCoding.getCode());
assertEquals(OBSERVATION_DISPLAY, observationTypeCoding.getDisplay());
// Find observation value code.
org.hl7.fhir.r4.model.CodeableConcept observationValue = observationResource.getValueCodeableConcept();
assertNotNull(observationValue);
assertEquals(observationValue.getCoding().size(), 1);
org.hl7.fhir.r4.model.Coding observationValueCoding = observationValue.getCoding().get(0);
// Check observation value code.
assertEquals(LOINC_URI, observationValueCoding.getSystem());
assertEquals(EXPECTED_VALUE_CODE, observationValueCoding.getCode());
assertEquals(EXPECTED_VALUE_DISPLAY, observationValueCoding.getDisplay());
inputStream.close();
}
Aggregations