Search in sources :

Example 1 with Observation

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;
}
Also used : Report(org.mitre.synthea.world.concepts.HealthRecord.Report) DiagnosticReport(ca.uhn.fhir.model.dstu2.resource.DiagnosticReport) Bundle(ca.uhn.fhir.model.dstu2.resource.Bundle) ImagingStudy(org.mitre.synthea.world.concepts.HealthRecord.ImagingStudy) Attachment(org.mitre.synthea.engine.Components.Attachment) Entry(ca.uhn.fhir.model.dstu2.resource.Bundle.Entry) HealthRecord(org.mitre.synthea.world.concepts.HealthRecord) CarePlan(org.mitre.synthea.world.concepts.HealthRecord.CarePlan) Observation(org.mitre.synthea.world.concepts.HealthRecord.Observation) Medication(org.mitre.synthea.world.concepts.HealthRecord.Medication) Encounter(org.mitre.synthea.world.concepts.HealthRecord.Encounter) Procedure(org.mitre.synthea.world.concepts.HealthRecord.Procedure)

Example 2 with Observation

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);
}
Also used : ResourceReferenceDt(ca.uhn.fhir.model.dstu2.composite.ResourceReferenceDt) Attachment(org.mitre.synthea.engine.Components.Attachment)

Example 3 with Observation

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;
}
Also used : SampledDataDt(ca.uhn.fhir.model.dstu2.composite.SampledDataDt) SimpleQuantityDt(ca.uhn.fhir.model.dstu2.composite.SimpleQuantityDt) BigDecimal(java.math.BigDecimal)

Example 4 with Observation

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);
}
Also used : CodeableConceptDt(ca.uhn.fhir.model.dstu2.composite.CodeableConceptDt) ResourceReferenceDt(ca.uhn.fhir.model.dstu2.composite.ResourceReferenceDt) ArrayList(java.util.ArrayList) DiagnosticReport(ca.uhn.fhir.model.dstu2.resource.DiagnosticReport) Date(java.util.Date) Observation(org.mitre.synthea.world.concepts.HealthRecord.Observation) Encounter(org.mitre.synthea.world.concepts.HealthRecord.Encounter) InstantDt(ca.uhn.fhir.model.primitive.InstantDt)

Example 5 with Observation

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();
}
Also used : TestHelper.years(org.mitre.synthea.TestHelper.years) Arrays(java.util.Arrays) XPathExpressionException(javax.xml.xpath.XPathExpressionException) Location(org.mitre.synthea.world.geography.Location) Bundle(org.hl7.fhir.dstu3.model.Bundle) BundleEntryComponent(org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent) Coding(org.hl7.fhir.dstu3.model.Coding) CodeableConcept(org.hl7.fhir.dstu3.model.CodeableConcept) Person(org.mitre.synthea.world.agents.Person) Document(org.w3c.dom.Document) After(org.junit.After) Path(java.nio.file.Path) Encounter(org.mitre.synthea.world.concepts.HealthRecord.Encounter) RestTemplate(org.springframework.web.client.RestTemplate) RandomCodeGenerator(org.mitre.synthea.helpers.RandomCodeGenerator) List(java.util.List) SAXException(org.xml.sax.SAXException) LOINC_URI(org.mitre.synthea.TestHelper.LOINC_URI) Optional(java.util.Optional) TestHelper(org.mitre.synthea.TestHelper) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) EncounterType(org.mitre.synthea.world.concepts.HealthRecord.EncounterType) XPath(javax.xml.xpath.XPath) XPathConstants(javax.xml.xpath.XPathConstants) SimpleDateFormat(java.text.SimpleDateFormat) TestHelper.isHttpRecordingEnabled(org.mitre.synthea.TestHelper.isHttpRecordingEnabled) XPathExpression(javax.xml.xpath.XPathExpression) Generator(org.mitre.synthea.engine.Generator) CodingDt(ca.uhn.fhir.model.dstu2.composite.CodingDt) WireMock(com.github.tomakehurst.wiremock.client.WireMock) CodeableConceptDt(ca.uhn.fhir.model.dstu2.composite.CodeableConceptDt) WireMockRule(com.github.tomakehurst.wiremock.junit.WireMockRule) ResourceType(org.hl7.fhir.dstu3.model.ResourceType) Node(org.w3c.dom.Node) Code(org.mitre.synthea.world.concepts.HealthRecord.Code) LOINC_OID(org.mitre.synthea.TestHelper.LOINC_OID) Before(org.junit.Before) TestHelper.wiremockOptions(org.mitre.synthea.TestHelper.wiremockOptions) Config(org.mitre.synthea.helpers.Config) NodeList(org.w3c.dom.NodeList) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Test(org.junit.Test) FileInputStream(java.io.FileInputStream) Payer(org.mitre.synthea.world.agents.Payer) File(java.io.File) Provider(org.mitre.synthea.world.agents.Provider) SNOMED_URI(org.mitre.synthea.TestHelper.SNOMED_URI) XPathFactory(javax.xml.xpath.XPathFactory) Rule(org.junit.Rule) Entry(ca.uhn.fhir.model.dstu2.resource.Bundle.Entry) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) DocumentBuilder(javax.xml.parsers.DocumentBuilder) Assert.assertEquals(org.junit.Assert.assertEquals) TestHelper.getTxRecordingSource(org.mitre.synthea.TestHelper.getTxRecordingSource) InputStream(java.io.InputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Bundle(org.hl7.fhir.dstu3.model.Bundle) FileInputStream(java.io.FileInputStream) BundleEntryComponent(org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent) Encounter(org.mitre.synthea.world.concepts.HealthRecord.Encounter)

Aggregations

Entry (ca.uhn.fhir.model.dstu2.resource.Bundle.Entry)12 Observation (ca.uhn.fhir.model.dstu2.resource.Observation)9 Bundle (ca.uhn.fhir.model.dstu2.resource.Bundle)8 CodeableConceptDt (ca.uhn.fhir.model.dstu2.composite.CodeableConceptDt)7 ArrayList (java.util.ArrayList)7 Condition (ca.uhn.fhir.model.dstu2.resource.Condition)6 CodingDt (ca.uhn.fhir.model.dstu2.composite.CodingDt)5 ResourceReferenceDt (ca.uhn.fhir.model.dstu2.composite.ResourceReferenceDt)5 DiagnosticReport (ca.uhn.fhir.model.dstu2.resource.DiagnosticReport)5 List (java.util.List)5 Encounter (org.mitre.synthea.world.concepts.HealthRecord.Encounter)4 FhirContext (ca.uhn.fhir.context.FhirContext)3 DiagnosticOrder (ca.uhn.fhir.model.dstu2.resource.DiagnosticOrder)3 Encounter (ca.uhn.fhir.model.dstu2.resource.Encounter)3 Organization (ca.uhn.fhir.model.dstu2.resource.Organization)3 Patient (ca.uhn.fhir.model.dstu2.resource.Patient)3 Practitioner (ca.uhn.fhir.model.dstu2.resource.Practitioner)3 WireMock (com.github.tomakehurst.wiremock.client.WireMock)3 WireMockRule (com.github.tomakehurst.wiremock.junit.WireMockRule)3 File (java.io.File)3