Search in sources :

Example 1 with ObservationComponentComponent

use of org.hl7.fhir.r4.model.Observation.ObservationComponentComponent in project odm2fhir by num-codex.

the class SOFAScore method createObservation.

private Observation createObservation(List<ItemData> itemDatas, ItemData sofaTotalScore, ItemData dateCoding) {
    var observation = (Observation) new Observation().addIdentifier(createIdentifier(OBSERVATION, sofaTotalScore).setType(OBI).setAssigner(getOrganizationReference())).setStatus(FINAL).setEffective(createDateTimeType(dateCoding)).addCategory(SURVEY).setCode(createCodeableConcept(createCoding(ECRF_PARAMETER_CODES, "06", "SOFA-Score")).setText("Sepsis-related organ failure assessment score")).setMeta(createMeta(NUMStructureDefinition.SOFA_SCORE));
    itemDatas.stream().map(ItemData::getValue).filter(StringUtils::isNotBlank).forEach(code -> observation.addComponent(new ObservationComponentComponent().setCode(createCodeableConcept(createCoding(SOFA_SCORE, chop(code), getDisplay(chop(code)))).setText(getDefinition(chop(code)))).setValue(createCodeableConcept(createCoding(SOFA_SCORE, code, getDisplay(code))).setText(getDefinition(code)))));
    if (sofaTotalScore.isEmpty()) {
        observation.setDataAbsentReason(UNKNOWN);
    } else {
        observation.setValue(new IntegerType().setValue(Integer.valueOf(sofaTotalScore.getValue())));
    }
    return observation;
}
Also used : IntegerType(org.hl7.fhir.r4.model.IntegerType) ObservationComponentComponent(org.hl7.fhir.r4.model.Observation.ObservationComponentComponent) Observation(org.hl7.fhir.r4.model.Observation) ItemData(de.difuture.uds.odm2fhir.odm.model.ItemData)

Example 2 with ObservationComponentComponent

use of org.hl7.fhir.r4.model.Observation.ObservationComponentComponent in project eCRNow by drajer-health.

the class CdaResultGenerator method getXmlForObservation.

public static String getXmlForObservation(LaunchDetails details, Observation obs, String contentId, int row) {
    StringBuilder lrEntry = new StringBuilder(2000);
    String contentRef = contentId + Integer.toString(row);
    Boolean foundComponent = false;
    if (obs.getComponent() != null && !obs.getComponent().isEmpty()) {
        CodeableConcept cc = obs.getCode();
        Type val = obs.getValue();
        List<CodeableConcept> interpretation = obs.getInterpretation();
        StringBuilder id = new StringBuilder(200);
        id.append(obs.getId());
        int rowNum = 1;
        for (ObservationComponentComponent oc : obs.getComponent()) {
            logger.debug("Found Observation Components ");
            if (oc.getCode() != null) {
                cc = oc.getCode();
            }
            if (oc.getValue() != null) {
                val = oc.getValue();
            }
            if (oc.getInterpretation() != null) {
                interpretation = oc.getInterpretation();
            }
            id.append("-");
            id.append(Integer.toBinaryString(rowNum));
            String compString = getXmlForObservationComponent(details, cc, val, id.toString(), obs.getEffective(), interpretation, contentRef);
            if (!compString.isEmpty() && !foundComponent)
                foundComponent = true;
            lrEntry.append(compString);
            rowNum++;
        }
    }
    if (!foundComponent) {
        logger.debug("No component found , so directly adding the observation code ");
        lrEntry.append(getXmlForObservationComponent(details, obs.getCode(), obs.getValue(), obs.getId(), obs.getEffective(), obs.getInterpretation(), contentRef));
    }
    logger.debug("Lr Entry = {}", lrEntry);
    return lrEntry.toString();
}
Also used : Type(org.hl7.fhir.r4.model.Type) ObservationComponentComponent(org.hl7.fhir.r4.model.Observation.ObservationComponentComponent) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept)

Example 3 with ObservationComponentComponent

use of org.hl7.fhir.r4.model.Observation.ObservationComponentComponent in project synthea by synthetichealth.

the class FhirR4 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 BundleEntryComponent observation(RandomNumberGenerator rand, BundleEntryComponent personEntry, Bundle bundle, BundleEntryComponent encounterEntry, Observation observation) {
    org.hl7.fhir.r4.model.Observation observationResource = new org.hl7.fhir.r4.model.Observation();
    observationResource.setSubject(new Reference(personEntry.getFullUrl()));
    observationResource.setEncounter(new Reference(encounterEntry.getFullUrl()));
    observationResource.setStatus(ObservationStatus.FINAL);
    Code code = observation.codes.get(0);
    observationResource.setCode(mapCodeToCodeableConcept(code, LOINC_URI));
    // add extra codes, if there are any...
    if (observation.codes.size() > 1) {
        for (int i = 1; i < observation.codes.size(); i++) {
            code = observation.codes.get(i);
            Coding coding = new Coding();
            coding.setCode(code.code);
            coding.setDisplay(code.display);
            coding.setSystem(LOINC_URI);
            observationResource.getCode().addCoding(coding);
        }
    }
    observationResource.addCategory().addCoding().setCode(observation.category).setSystem("http://terminology.hl7.org/CodeSystem/observation-category").setDisplay(observation.category);
    if (observation.value != null) {
        Type 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) {
            ObservationComponentComponent comp = new ObservationComponentComponent();
            comp.setCode(mapCodeToCodeableConcept(subObs.codes.get(0), LOINC_URI));
            Type value = mapValueToFHIRType(subObs.value, subObs.unit);
            comp.setValue(value);
            observationResource.addComponent(comp);
        }
    }
    observationResource.setEffective(convertFhirDateTime(observation.start, true));
    observationResource.setIssued(new Date(observation.start));
    if (USE_US_CORE_IG) {
        Meta meta = new Meta();
        // add the specific profile based on code
        String codeMappingUri = US_CORE_MAPPING.get(LOINC_URI, code.code);
        if (codeMappingUri != null) {
            meta.addProfile(codeMappingUri);
            if (!codeMappingUri.contains("/us/core/") && observation.category.equals("vital-signs")) {
                meta.addProfile("http://hl7.org/fhir/StructureDefinition/vitalsigns");
            }
        } else if (observation.report != null && observation.category.equals("laboratory")) {
            meta.addProfile("http://hl7.org/fhir/us/core/StructureDefinition/us-core-observation-lab");
        }
        if (meta.hasProfile()) {
            observationResource.setMeta(meta);
        }
    } else if (USE_SHR_EXTENSIONS) {
        Meta meta = new Meta();
        // all Observations are Observations
        meta.addProfile(SHR_EXT + "shr-finding-Observation");
        if ("vital-signs".equals(observation.category)) {
            meta.addProfile(SHR_EXT + "shr-vital-VitalSign");
        }
        // add the specific profile based on code
        String codeMappingUri = SHR_MAPPING.get(LOINC_URI, code.code);
        if (codeMappingUri != null) {
            meta.addProfile(codeMappingUri);
        }
        observationResource.setMeta(meta);
    }
    BundleEntryComponent entry = newEntry(rand, bundle, observationResource);
    observation.fullUrl = entry.getFullUrl();
    return entry;
}
Also used : Meta(org.hl7.fhir.r4.model.Meta) Reference(org.hl7.fhir.r4.model.Reference) DocumentReference(org.hl7.fhir.r4.model.DocumentReference) Code(org.mitre.synthea.world.concepts.HealthRecord.Code) ContactPoint(org.hl7.fhir.r4.model.ContactPoint) Date(java.util.Date) IntegerType(org.hl7.fhir.r4.model.IntegerType) BooleanType(org.hl7.fhir.r4.model.BooleanType) BundleType(org.hl7.fhir.r4.model.Bundle.BundleType) EncounterType(org.mitre.synthea.world.concepts.HealthRecord.EncounterType) DeviceNameType(org.hl7.fhir.r4.model.Device.DeviceNameType) DateTimeType(org.hl7.fhir.r4.model.DateTimeType) AllergyIntoleranceType(org.hl7.fhir.r4.model.AllergyIntolerance.AllergyIntoleranceType) DecimalType(org.hl7.fhir.r4.model.DecimalType) CodeType(org.hl7.fhir.r4.model.CodeType) NodeType(org.hl7.fhir.utilities.xhtml.NodeType) StringType(org.hl7.fhir.r4.model.StringType) DateType(org.hl7.fhir.r4.model.DateType) PositiveIntType(org.hl7.fhir.r4.model.PositiveIntType) Type(org.hl7.fhir.r4.model.Type) DoseRateType(org.hl7.fhir.r4.model.codesystems.DoseRateType) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) Coding(org.hl7.fhir.r4.model.Coding) ObservationComponentComponent(org.hl7.fhir.r4.model.Observation.ObservationComponentComponent) Observation(org.mitre.synthea.world.concepts.HealthRecord.Observation)

Example 4 with ObservationComponentComponent

use of org.hl7.fhir.r4.model.Observation.ObservationComponentComponent in project synthea by synthetichealth.

the class FhirStu3 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 BundleEntryComponent observation(RandomNumberGenerator rand, BundleEntryComponent personEntry, Bundle bundle, BundleEntryComponent encounterEntry, Observation observation) {
    org.hl7.fhir.dstu3.model.Observation observationResource = new org.hl7.fhir.dstu3.model.Observation();
    observationResource.setSubject(new Reference(personEntry.getFullUrl()));
    observationResource.setContext(new Reference(encounterEntry.getFullUrl()));
    observationResource.setStatus(ObservationStatus.FINAL);
    Code code = observation.codes.get(0);
    observationResource.setCode(mapCodeToCodeableConcept(code, LOINC_URI));
    observationResource.addCategory().addCoding().setCode(observation.category).setSystem("http://hl7.org/fhir/observation-category").setDisplay(observation.category);
    if (observation.value != null) {
        Type 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) {
            ObservationComponentComponent comp = new ObservationComponentComponent();
            comp.setCode(mapCodeToCodeableConcept(subObs.codes.get(0), LOINC_URI));
            Type value = mapValueToFHIRType(subObs.value, subObs.unit);
            comp.setValue(value);
            observationResource.addComponent(comp);
        }
    }
    observationResource.setEffective(convertFhirDateTime(observation.start, true));
    observationResource.setIssued(new Date(observation.start));
    if (USE_SHR_EXTENSIONS) {
        Meta meta = new Meta();
        // all Observations are Observations
        meta.addProfile(SHR_EXT + "shr-finding-Observation");
        if ("vital-signs".equals(observation.category)) {
            meta.addProfile(SHR_EXT + "shr-vital-VitalSign");
        }
        // add the specific profile based on code
        String codeMappingUri = SHR_MAPPING.get(LOINC_URI, code.code);
        if (codeMappingUri != null) {
            meta.addProfile(codeMappingUri);
        }
        observationResource.setMeta(meta);
    }
    BundleEntryComponent entry = newEntry(rand, bundle, observationResource);
    observation.fullUrl = entry.getFullUrl();
    return entry;
}
Also used : Meta(org.hl7.fhir.dstu3.model.Meta) Reference(org.hl7.fhir.dstu3.model.Reference) Code(org.mitre.synthea.world.concepts.HealthRecord.Code) Date(java.util.Date) Type(org.hl7.fhir.dstu3.model.Type) DigitalMediaType(org.hl7.fhir.dstu3.model.Media.DigitalMediaType) EncounterType(org.mitre.synthea.world.concepts.HealthRecord.EncounterType) CodeType(org.hl7.fhir.dstu3.model.CodeType) IntegerType(org.hl7.fhir.dstu3.model.IntegerType) PositiveIntType(org.hl7.fhir.dstu3.model.PositiveIntType) NodeType(org.hl7.fhir.utilities.xhtml.NodeType) StringType(org.hl7.fhir.dstu3.model.StringType) BooleanType(org.hl7.fhir.dstu3.model.BooleanType) DateType(org.hl7.fhir.dstu3.model.DateType) DateTimeType(org.hl7.fhir.dstu3.model.DateTimeType) BundleType(org.hl7.fhir.dstu3.model.Bundle.BundleType) DecimalType(org.hl7.fhir.dstu3.model.DecimalType) AllergyIntoleranceType(org.hl7.fhir.dstu3.model.AllergyIntolerance.AllergyIntoleranceType) BundleEntryComponent(org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent) ObservationComponentComponent(org.hl7.fhir.dstu3.model.Observation.ObservationComponentComponent) Observation(org.mitre.synthea.world.concepts.HealthRecord.Observation)

Example 5 with ObservationComponentComponent

use of org.hl7.fhir.r4.model.Observation.ObservationComponentComponent in project odm2fhir by num-codex.

the class HistoryOfTravel method createObservation.

private Observation createObservation(ItemData generalCoding, ItemData answerCoding, Map<String, ItemData> travelActivity) {
    var observation = (Observation) new Observation().addIdentifier(createIdentifier(OBSERVATION, travelActivity.get("country")).setType(OBI).setAssigner(getOrganizationReference())).setStatus(FINAL).setEffective(// TODO Set actual DateTime value
    UNKNOWN_DATE_TIME).addCategory(SOCIAL_HISTORY).setMeta(createMeta(HISTORY_OF_TRAVEL));
    var codeCodeableConcept = createCodeableConcept(generalCoding).setText("History of Travel");
    if (!codeCodeableConcept.isEmpty()) {
        observation.setCode(codeCodeableConcept);
    }
    var valueCodeableConcept = createCodeableConcept(answerCoding);
    if (!valueCodeableConcept.isEmpty()) {
        observation.setValue(valueCodeableConcept);
    }
    var startDate = travelActivity.get("start");
    if (!startDate.isEmpty()) {
        observation.addComponent(new ObservationComponentComponent().setCode(createCodeableConcept(createCoding(LOINC, "82752-7", "Date travel started")).setText("Travel start date")).setValue(createDateTimeType(startDate)));
    }
    var endDate = travelActivity.get("end");
    if (!endDate.isEmpty()) {
        observation.addComponent(new ObservationComponentComponent().setCode(createCodeableConcept(createCoding(LOINC, "91560-3", "Date of departure from travel destination")).setText("Travel end date")).setValue(createDateTimeType(endDate)));
    }
    var country = travelActivity.get("country");
    if (!country.isEmpty()) {
        var countryCoding = createCoding(country);
        countryCoding.setDisplay(new Locale("", countryCoding.getCode()).getDisplayCountry(ENGLISH));
        observation.addComponent(new ObservationComponentComponent().setCode(createCodeableConcept(createCoding(LOINC, "94651-7", "Country of travel")).setText("Country of travel")).setValue(createCodeableConcept(countryCoding).setText(countryCoding.getDisplay())));
    }
    var state = travelActivity.get("state");
    if (!state.isEmpty()) {
        var stateCoding = createCoding(state);
        stateCoding.setDisplay(STATES.getOrDefault(stateCoding.getCode(), stateCoding.getCode()));
        observation.addComponent(new ObservationComponentComponent().setCode(createCodeableConcept(createCoding(LOINC, "82754-3", "State of travel")).setText("State of travel")).setValue(createCodeableConcept(stateCoding).setText(stateCoding.getDisplay())));
    }
    var city = travelActivity.get("city");
    if (!city.isEmpty()) {
        observation.addComponent(new ObservationComponentComponent().setCode(createCodeableConcept(createCoding(LOINC, "94653-3", "City of travel")).setText("City of travel")).setValue(createStringType(city)));
    }
    // no Components added = no travel activity
    return observation.getComponent().isEmpty() ? new Observation() : observation;
}
Also used : Locale(java.util.Locale) ObservationComponentComponent(org.hl7.fhir.r4.model.Observation.ObservationComponentComponent) Observation(org.hl7.fhir.r4.model.Observation)

Aggregations

ObservationComponentComponent (org.hl7.fhir.r4.model.Observation.ObservationComponentComponent)5 Observation (org.hl7.fhir.r4.model.Observation)3 Date (java.util.Date)2 ObservationComponentComponent (org.hl7.fhir.dstu3.model.Observation.ObservationComponentComponent)2 Coding (org.hl7.fhir.r4.model.Coding)2 IntegerType (org.hl7.fhir.r4.model.IntegerType)2 Type (org.hl7.fhir.r4.model.Type)2 NodeType (org.hl7.fhir.utilities.xhtml.NodeType)2 Code (org.mitre.synthea.world.concepts.HealthRecord.Code)2 EncounterType (org.mitre.synthea.world.concepts.HealthRecord.EncounterType)2 Observation (org.mitre.synthea.world.concepts.HealthRecord.Observation)2 PatientVitals (com.redhat.naps.process.model.PatientVitals)1 ItemData (de.difuture.uds.odm2fhir.odm.model.ItemData)1 Locale (java.util.Locale)1 AllergyIntoleranceType (org.hl7.fhir.dstu3.model.AllergyIntolerance.AllergyIntoleranceType)1 BooleanType (org.hl7.fhir.dstu3.model.BooleanType)1 BundleEntryComponent (org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent)1 BundleType (org.hl7.fhir.dstu3.model.Bundle.BundleType)1 CodeType (org.hl7.fhir.dstu3.model.CodeType)1 DateTimeType (org.hl7.fhir.dstu3.model.DateTimeType)1