Search in sources :

Example 1 with IDatatype

use of ca.uhn.fhir.model.api.IDatatype in project synthea by synthetichealth.

the class FhirDstu2 method observation.

/**
 * Map the given Observation into a FHIR Observation resource, and add it to the given Bundle.
 *
 * @param rand
 *          Source of randomness to use when generating ids etc
 * @param personEntry
 *          The Person Entry
 * @param bundle
 *          The Bundle to add to
 * @param encounterEntry
 *          The current Encounter entry
 * @param observation
 *          The Observation
 * @return The added Entry
 */
private static Entry observation(RandomNumberGenerator rand, Entry personEntry, Bundle bundle, Entry encounterEntry, Observation observation) {
    ca.uhn.fhir.model.dstu2.resource.Observation observationResource = new ca.uhn.fhir.model.dstu2.resource.Observation();
    observationResource.setSubject(new ResourceReferenceDt(personEntry.getFullUrl()));
    observationResource.setEncounter(new ResourceReferenceDt(encounterEntry.getFullUrl()));
    observationResource.setStatus(ObservationStatusEnum.FINAL);
    Code code = observation.codes.get(0);
    observationResource.setCode(mapCodeToCodeableConcept(code, LOINC_URI));
    Code category = new Code("http://hl7.org/fhir/observation-category", observation.category, observation.category);
    observationResource.setCategory(mapCodeToCodeableConcept(category, "http://hl7.org/fhir/observation-category"));
    if (observation.value != null) {
        IDatatype value = mapValueToFHIRType(observation.value, observation.unit);
        observationResource.setValue(value);
    } else if (observation.observations != null && !observation.observations.isEmpty()) {
        // multi-observation (ex blood pressure)
        for (Observation subObs : observation.observations) {
            Component comp = new Component();
            comp.setCode(mapCodeToCodeableConcept(subObs.codes.get(0), LOINC_URI));
            IDatatype value = mapValueToFHIRType(subObs.value, subObs.unit);
            comp.setValue(value);
            observationResource.addComponent(comp);
        }
    }
    observationResource.setEffective(convertFhirDateTime(observation.start, true));
    observationResource.setIssued(new InstantDt(new Date(observation.start)));
    Entry entry = newEntry(rand, bundle, observationResource);
    observation.fullUrl = entry.getFullUrl();
    return entry;
}
Also used : IDatatype(ca.uhn.fhir.model.api.IDatatype) ResourceReferenceDt(ca.uhn.fhir.model.dstu2.composite.ResourceReferenceDt) Code(org.mitre.synthea.world.concepts.HealthRecord.Code) Date(java.util.Date) Entry(ca.uhn.fhir.model.dstu2.resource.Bundle.Entry) Observation(org.mitre.synthea.world.concepts.HealthRecord.Observation) Component(ca.uhn.fhir.model.dstu2.resource.Observation.Component) InstantDt(ca.uhn.fhir.model.primitive.InstantDt)

Aggregations

IDatatype (ca.uhn.fhir.model.api.IDatatype)1 ResourceReferenceDt (ca.uhn.fhir.model.dstu2.composite.ResourceReferenceDt)1 Entry (ca.uhn.fhir.model.dstu2.resource.Bundle.Entry)1 Component (ca.uhn.fhir.model.dstu2.resource.Observation.Component)1 InstantDt (ca.uhn.fhir.model.primitive.InstantDt)1 Date (java.util.Date)1 Code (org.mitre.synthea.world.concepts.HealthRecord.Code)1 Observation (org.mitre.synthea.world.concepts.HealthRecord.Observation)1