use of org.hl7.fhir.dstu3.model.Observation.ObservationRelatedComponent in project org.hl7.fhir.core by hapifhir.
the class CCDAConverter method processSocialObservation.
protected void processSocialObservation(ListResource list, Element so, SocialHistoryType type) throws Exception {
Observation obs = new Observation();
addItemToList(list, obs);
switch(type) {
case SocialHistory:
cda.checkTemplateId(so, "2.16.840.1.113883.10.20.22.4.38");
// SHALL contain exactly one [1..1] code (CONF:8558/).
obs.setCode(convert.makeCodeableConceptFromCD(cda.getChild(so, "code")));
break;
case Pregnancy:
cda.checkTemplateId(so, "2.16.840.1.113883.10.20.15.3.8");
// SHALL contain exactly one [1..1] code (CONF:8558/), which SHALL be an assertion
obs.setCode(Factory.newCodeableConcept("11449-6", "http://loinc.org", "Pregnancy Status"));
break;
case SmokingStatus:
cda.checkTemplateId(so, "2.16.840.1.113883.10.20.22.4.78");
// SHALL contain exactly one [1..1] code (CONF:8558/), which SHALL be an assertion
obs.setCode(Factory.newCodeableConcept("72166-2", "http://loinc.org", "Tobacco Smoking Status"));
break;
case TobaccoUse:
cda.checkTemplateId(so, "2.16.840.1.113883.10.20.22.4.12");
// SHALL contain exactly one [1..1] code (CONF:8558/), which SHALL be an assertion
obs.setCode(Factory.newCodeableConcept("11367-0", "http://loinc.org", "History of Tobacco Use"));
}
// SHALL contain at least one [1..*] id (8551).
for (Element e : cda.getChildren(so, "id")) obs.getIdentifier().add(convert.makeIdentifierFromII(e));
// SHALL contain exactly one [1..1] statusCode (CONF:8553/455/14809).
// a. This statusCode SHALL contain exactly one [1..1] @code="completed" Completed (CodeSystem: ActStatus 2.16.840.1.113883.5.14 STATIC) (CONF:19117).
obs.setStatus(ObservationStatus.FINAL);
// SHOULD contain zero or one [0..1] effectiveTime (CONF:2018/14814).
// for smoking status/tobacco: low only. in R2, this is just value. So we treat low only as just a value
Element et = cda.getChild(so, "effectiveTime");
if (et != null) {
if (cda.getChild(et, "low") != null)
obs.setEffective(convert.makeDateTimeFromTS(cda.getChild(et, "low")));
else
obs.setEffective(convert.makeDateTimeFromIVL(et));
}
// a. Observation/value can be any data type.
for (Element e : cda.getChildren(so, "value")) if (obs.getValue() == null) {
// special case for pregnancy:
if (type == SocialHistoryType.Pregnancy && "true".equals(e.getAttribute("negationInd"))) {
obs.setValue(Factory.newCodeableConcept("60001007", "http://snomed.info/sct", "Not pregnant"));
} else {
// negationInd is not described. but it might well be used. For now, we blow up
checkNoNegation(so, "Social Observation (" + type + ")");
if (so.hasAttribute("nullFlavor"))
obs.setValue(convert.makeCodeableConceptFromNullFlavor(so.getAttribute("nullFlavor")));
else if (e.hasAttribute("nullFlavor") && !"OTH".equals(e.getAttribute("nullFlavor")))
obs.setValue(convert.makeCodeableConceptFromNullFlavor(e.getAttribute("nullFlavor")));
else
obs.setValue(convert.makeTypeFromANY(e));
}
} else
throw new Exception("too many values on Social Observation");
if (type == SocialHistoryType.Pregnancy) {
for (Element e : cda.getChildren(so, "entyRelationship")) {
Element dd = cda.getChild(e, "observation");
checkNoNegationOrNullFlavor(dd, "Estimated Date of Delivery");
// MAY contain zero or one [0..1] entryRelationship (CONF:458) such that it
// SHALL contain exactly one [1..1] @typeCode="REFR" Refers to (CodeSystem: HL7ActRelationshipType 2.16.840.1.113883.5.1002 STATIC) (CONF:459).
// SHALL contain exactly one [1..1] Estimated Date of Delivery (templateId:2.16.840.1.113883.10.20.15.3.1) (CONF:15584).
Observation co = new Observation();
String id = nextRef();
co.setId(id);
obs.getContained().add(co);
ObservationRelatedComponent or = new ObservationRelatedComponent();
obs.getRelated().add(or);
or.setType(ObservationRelationshipType.HASMEMBER);
or.setTarget(Factory.makeReference("#" + id));
co.setCode(Factory.newCodeableConcept("11778-8", "http://loinc.org", "Delivery date Estimated"));
// not legal, see gForge http://gforge.hl7.org/gf/project/fhir/tracker/?action=TrackerItemEdit&tracker_item_id=3125&start=0
co.setValue(convert.makeDateTimeFromTS(cda.getChild(dd, "value")));
}
}
}
use of org.hl7.fhir.dstu3.model.Observation.ObservationRelatedComponent in project org.hl7.fhir.core by hapifhir.
the class CCDAConverter method processVitalSignsOrganizer.
protected void processVitalSignsOrganizer(ListResource list, Element organizer) throws Exception {
cda.checkTemplateId(organizer, "2.16.840.1.113883.10.20.22.4.26");
checkNoNegationOrNullFlavor(organizer, "Vital Signs Organizer");
checkNoSubject(organizer, "Vital Signs Organizer");
// moodCode is EVN.
Observation obs = new Observation();
addItemToList(list, obs);
// SHALL contain at least one [1..*] id (CONF:7282).
for (Element e : cda.getChildren(organizer, "id")) obs.getIdentifier().add(convert.makeIdentifierFromII(e));
// SHALL contain exactly one [1..1] code (CONF:19176).
// This code SHALL contain exactly one [1..1] @code="46680005" Vital signs (CodeSystem: SNOMED-CT 2.16.840.1.113883.6.96 STATIC) (CONF:19177).
obs.setCode(convert.makeCodeableConceptFromCD(cda.getChild(organizer, "code")));
// SHALL contain exactly one [1..1] effectiveTime (CONF:7288).
obs.setEffective(convert.makeMatchingTypeFromIVL(cda.getChild(organizer, "effectiveTime")));
// SHALL contain exactly one [1..1] Vital Sign Observation (templateId:2.16.840.1.113883.10.20.22.4.27) (CONF:15946).
for (Element e : cda.getChildren(organizer, "component")) {
ObservationRelatedComponent ro = new ObservationRelatedComponent();
ro.setType(ObservationRelationshipType.HASMEMBER);
ro.setTarget(Factory.makeReference("#" + processVitalSignsObservation(e, list)));
}
}
Aggregations