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;
}
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();
}
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;
}
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;
}
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;
}
Aggregations