use of org.hl7.fhir.dstu3.model.ListResource in project integration-adaptor-111 by nhsconnect.
the class ListMapperTest method shouldMapList.
@Test
public void shouldMapList() {
ListResource listResource = listMapper.mapList(clinicalDocument, encounter, resourcesCreated, deviceRef);
assertThat(listResource.getStatus()).isEqualTo(CURRENT);
assertThat(listResource.getTitle()).isEqualTo("111 Report List");
assertThat(listResource.getMode()).isEqualTo(WORKING);
Coding orderByCode = listResource.getOrderedBy().getCodingFirstRep();
assertThat(orderByCode.getSystem()).isEqualTo("http://hl7.org/fhir/list-order");
assertThat(orderByCode.getCode()).isEqualTo("event-date");
assertThat(orderByCode.getDisplay()).isEqualTo("Sorted by Event Date");
Coding code = listResource.getCode().getCodingFirstRep();
assertThat(code.getSystem()).isEqualTo("http://snomed.info/sct");
assertThat(code.getCode()).isEqualTo("225390008");
assertThat(code.getDisplay()).isEqualTo("Triage");
assertThat(listResource.getEntry().size()).isEqualTo(1);
assertThat(listResource.getIdElement().getValue()).isEqualTo(RANDOM_UUID);
assertThat(deviceRef).isEqualTo(listResource.getSource());
assertThat(listResource.getDateElement().getValue()).isEqualTo(DateUtil.parse(effectiveTime.getValue()).getValue());
}
use of org.hl7.fhir.dstu3.model.ListResource in project org.hl7.fhir.core by hapifhir.
the class CCDAConverter method processAllergyProblemAct.
protected void processAllergyProblemAct(ListResource list, Element concern) throws Exception {
cda.checkTemplateId(concern, "2.16.840.1.113883.10.20.22.4.30");
// Allergy Problem Act - this is a concern - we treat the concern as information about it's place in the list
checkNoNegationOrNullFlavor(concern, "Allergy Problem Act");
checkNoSubject(concern, "Allergy Problem Act");
// SHALL contain exactly one [1..1] Allergy - intolerance Observation
for (Element entry : cda.getChildren(concern, "entryRelationship")) {
Element obs = cda.getChild(entry, "observation");
cda.checkTemplateId(obs, "2.16.840.1.113883.10.20.22.4.7");
checkNoNegationOrNullFlavor(obs, "Allergy - intolerance Observation");
checkNoSubject(obs, "Allergy Problem Act");
AllergyIntolerance ai = new AllergyIntolerance();
ListEntryComponent item = addItemToList(list, ai);
// SHALL contain at least one [1..*] id (CONF:7472).
for (Element e : cda.getChildren(concern, "id")) ai.getIdentifier().add(convert.makeIdentifierFromII(e));
// SHALL contain exactly one [1..1] statusCode, which SHALL be selected from ValueSet 2.16.840.1.113883.3.88.12.80.68 HITSPProblemStatus DYNAMIC (CONF:7485)
// the status code is about the concern (e.g. the entry in the list)
// possible values: active, suspended, aborted, completed, with an effective time
String s = cda.getStatus(concern);
item.setFlag(Factory.newCodeableConcept(s, "http://hl7.org/fhir/v3/ActStatus", s));
if (// only on this condition?
s.equals("aborted"))
item.setDeleted(true);
// SHALL contain exactly one [1..1] effectiveTime (CONF:7498)
Period p = convert.makePeriodFromIVL(cda.getChild(concern, "effectiveTime"));
item.getExtension().add(Factory.newExtension("http://www.healthintersections.com.au/fhir/extensions/list-period", p, false));
if (p.getEnd() != null)
item.setDate(p.getEnd());
else
item.setDate(p.getStart());
// SHALL contain at least one [1..*] id (CONF:7382)
for (Element e : cda.getChildren(obs, "id")) ai.getIdentifier().add(convert.makeIdentifierFromII(e));
// SHALL contain exactly one [1..1] effectiveTime (CONF:7387)
ai.getExtension().add(Factory.newExtension("http://www.healthintersections.com.au/fhir/extensions/allergyintolerance-period", convert.makePeriodFromIVL(cda.getChild(obs, "effectiveTime")), false));
// SHALL contain exactly one [1..1] value with @xsi:type="CD" (CONF:7390)
CodeableConcept type = convert.makeCodeableConceptFromCD(cda.getChild(obs, "value"));
// This value SHALL contain @code, which SHALL be selected from ValueSet 2.16.840.1.113883.3.88.12.3221.6.2 Allergy/Adverse Event Type
String ss = type.getCoding().get(0).getCode();
if (ss.equals("416098002") || ss.equals("414285001"))
ai.setType(AllergyIntoleranceType.ALLERGY);
else if (ss.equals("59037007") || ss.equals("235719002"))
ai.setType(AllergyIntoleranceType.INTOLERANCE);
ai.getExtension().add(Factory.newExtension("http://www.healthintersections.com.au/fhir/extensions/allergy-category", type, false));
// SHOULD contain zero or one [0..1] participant (CONF:7402) such that it
// ......This playingEntity SHALL contain exactly one [1..1] code
ai.setCode(convert.makeCodeableConceptFromCD(cda.getDescendent(obs, "participant/participantRole/playingEntity/code")));
// SHOULD contain zero or more [0..*] entryRelationship (CONF:7447) such that it SHALL contain exactly one [1..1] Reaction Observation (templateId:2.16.840.1.113883.10.20.22.4.9) (CONF:7450).
for (Element e : cda.getChildren(obs, "entryRelationship")) {
Element child = cda.getChild(e, "observation");
if (cda.hasTemplateId(child, "2.16.840.1.113883.10.20.22.4.28") && ai.getClinicalStatus() == null) {
// SHALL contain exactly one [1..1] value with @xsi:type="CE", where the @code SHALL be selected from ValueSet Problem Status Value Set 2.16.840.1.113883.3.88.12.80.68 DYNAMIC (CONF:7322).
// 55561003 SNOMED CT Active
// 73425007 SNOMED CT Inactive
// 413322009 SNOMED CT Resolved
String sc = cda.getChild(child, "value").getAttribute("code");
if (sc.equals("55561003")) {
ai.setClinicalStatus(AllergyIntoleranceClinicalStatus.ACTIVE);
ai.setVerificationStatus(AllergyIntoleranceVerificationStatus.CONFIRMED);
} else
ai.setClinicalStatus(AllergyIntoleranceClinicalStatus.RESOLVED);
} else if (cda.hasTemplateId(child, "2.16.840.1.113883.10.20.22.4.9")) {
ai.getReaction().add(processAdverseReactionObservation(child));
}
}
// SHOULD contain zero or one [0..1] entryRelationship (CONF:9961) such that it SHALL contain exactly one [1..1] Severity Observation (templateId:2.16.840.1.113883.10.20.22.4.8) (CONF:9963).
ai.setCriticality(readCriticality(cda.getSeverity(obs)));
}
}
use of org.hl7.fhir.dstu3.model.ListResource in project org.hl7.fhir.core by hapifhir.
the class CCDAConverter method processProcedure.
protected void processProcedure(ListResource list, Element procedure, ProcedureType type) throws Exception {
switch(type) {
case Procedure:
cda.checkTemplateId(procedure, "2.16.840.1.113883.10.20.22.4.14");
break;
case Observation:
cda.checkTemplateId(procedure, "2.16.840.1.113883.10.20.22.4.13");
break;
case Act:
cda.checkTemplateId(procedure, "2.16.840.1.113883.10.20.22.4.12");
}
checkNoNegationOrNullFlavor(procedure, "Procedure (" + type + ")");
checkNoSubject(procedure, "Procedure (" + type + ")");
Procedure p = new Procedure();
addItemToList(list, p);
// moodCode is either INT or EVN. INT is not handled yet. INT is deprecated anyway
if (procedure.getAttribute("moodCode").equals("INT"))
p.getModifierExtension().add(Factory.newExtension("http://www.healthintersections.com.au/fhir/extensions/procedure-planned", Factory.newBoolean(true), false));
// SHALL contain at least one [1..*] id (CONF:7655).
for (Element e : cda.getChildren(procedure, "id")) p.getIdentifier().add(convert.makeIdentifierFromII(e));
// SHALL contain exactly one [1..1] code (CONF:7656).
// This code @code in a procedure activity SHOULD be selected from LOINC or SNOMED CT and MAY be selected from CPT-4, ICD9 Procedures, ICD10 Procedures
p.setCode(convert.makeCodeableConceptFromCD(cda.getChild(procedure, "code")));
// SHALL contain exactly one [1..1] statusCode/@code, which SHALL be selected from ValueSet 2.16.840.1.113883.11.20.9.22 ProcedureAct
// completed | active | aborted | cancelled - not in FHIR
p.getModifierExtension().add(Factory.newExtension("http://www.healthintersections.com.au/fhir/extensions/procedure-status", Factory.newCode(cda.getStatus(procedure)), false));
// SHOULD contain zero or one [0..1] effectiveTime (CONF:7662).
p.setPerformed(convert.makePeriodFromIVL(cda.getChild(procedure, "effectiveTime")));
// MAY contain zero or one [0..1] priorityCode/@code, which SHALL be selected from ValueSet 2.16.840.1.113883.1.11.16866 ActPriority DYNAMIC (CONF:7668)
p.getExtension().add(Factory.newExtension("http://www.healthintersections.com.au/fhir/extensions/procedure-priority", convert.makeCodeableConceptFromCD(cda.getChild(procedure, "priorityCode")), false));
// MAY contain zero or one [0..1] methodCode (CONF:7670).
p.getExtension().add(Factory.newExtension("http://www.healthintersections.com.au/fhir/extensions/procedure-method", convert.makeCodeableConceptFromCD(cda.getChild(procedure, "methodCode")), false));
if (type == ProcedureType.Observation) {
// for Procedure-Observation:
// 9. SHALL contain exactly one [1..1] value (CONF:16846).
// don't know what this is. It's not the actual result of the procedure (that goes in results "This section records ... procedure observations"), and there seems to be no value. The example as <value xsi:type="CD"/> which is not valid
// so we ignore this for now
}
// SHOULD contain zero or more [0..*] targetSiteCode/@code, which SHALL be selected from ValueSet 2.16.840.1.113883.3.88.12.3221.8.9 Body site DYNAMIC (CONF:7683).
for (Element e : cda.getChildren(procedure, "targetSiteCode")) p.addBodySite(convert.makeCodeableConceptFromCD(e));
// SHOULD contain zero or more [0..*] performer (CONF:7718) such that it
for (Element e : cda.getChildren(procedure, "performer")) {
ProcedurePerformerComponent pp = new ProcedurePerformerComponent();
p.getPerformer().add(pp);
pp.setActor(makeReferenceToPractitionerForAssignedEntity(e, p));
}
for (Element participant : cda.getChildren(procedure, "participant")) {
Element participantRole = cda.getlastChild(participant);
if (type == ProcedureType.Procedure && cda.hasTemplateId(participantRole, "2.16.840.1.113883.10.20.22.4.37")) {
// MAY contain zero or more [0..*] participant (CONF:7751) such that it SHALL contain exactly one [1..1] @typeCode="DEV" Device
// implanted devices
p.getExtension().add(Factory.newExtension("http://www.healthintersections.com.au/fhir/extensions/implanted-devices", Factory.makeReference(processDevice(participantRole, p)), false));
} else if (cda.hasTemplateId(participantRole, "2.16.840.1.113883.10.20.22.4.32")) {
// MAY contain zero or more [0..*] participant (CONF:7765) such that it SHALL contain exactly one [1..1] Service Delivery Location (templateId:2.16.840.1.113883.10.20.22.4.32) (CONF:7767)
p.getExtension().add(Factory.newExtension("http://www.healthintersections.com.au/fhir/extensions/location", Factory.makeReference(processSDLocation(participantRole, p)), false));
}
}
for (Element e : cda.getChildren(procedure, "entryRelationship")) {
Element a = /* act*/
cda.getlastChild(e);
if (a.getLocalName().equals("encounter")) {
// MAY contain zero or more [0..*] entryRelationship (CONF:7768) such that it SHALL contain exactly one encounter which SHALL contain exactly one [1..1] id (CONF:7773).
// todo - and process as a full encounter while we're at it
} else if (cda.hasTemplateId(a, "2.16.840.1.113883.10.20.22.4.20")) {
// MAY contain zero or one [0..1] entryRelationship (CONF:7775) such that it SHALL contain exactly one [1..1] Instructions (templateId:2.16.840.1.113883.10.20.22.4.20) (CONF:7778).
// had code for type, plus text for instructions
Extension n = Factory.newExtension("http://www.healthintersections.com.au/fhir/extensions/procedure-instructions", null, true);
n.getExtension().add(Factory.newExtension("http://www.healthintersections.com.au/fhir/extensions/procedure-instructions-type", convert.makeCodeableConceptFromCD(cda.getChild(a, "code")), false));
n.getExtension().add(Factory.newExtension("http://www.healthintersections.com.au/fhir/extensions/procedure-instructions-text", convert.makeStringFromED(cda.getChild(a, "text")), false));
p.getExtension().add(n);
} else if (cda.hasTemplateId(a, "2.16.840.1.113883.10.20.22.4.19")) {
// MAY contain zero or more [0..*] entryRelationship (CONF:7779) such that it SHALL contain exactly one [1..1] Indication (templateId:2.16.840.1.113883.10.20.22.4.19) (CONF:7781).
p.addReasonCode(processIndication(a));
} else if (cda.hasTemplateId(cda.getlastChild(e), "2.16.840.1.113883.10.20.22.4.16")) {
// MAY contain zero or one [0..1] entryRelationship (CONF:7886) such that it SHALL contain exactly one [1..1] Medication Activity (templateId:2.16.840.1.113883.10.20.22.4.16) (CONF:7888).
// todo
}
}
}
use of org.hl7.fhir.dstu3.model.ListResource 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.ListResource in project org.hl7.fhir.core by hapifhir.
the class ArgonautConverter method processMedicationsSection.
private void processMedicationsSection(CDAUtilities cda, Convert convert, Element section, Context context) throws Exception {
scanSection("Medications", section);
ListResource list = new ListResource();
list.setId(context.getBaseId() + "-list-medications");
list.setUserData("profile", "http://hl7.org/fhir/StructureDefinition/list-daf-dafmedicationlist");
list.setSubject(context.getSubjectRef());
list.setCode(inspectCode(convert.makeCodeableConceptFromCD(cda.getChild(section, "code")), null));
list.setTitle(cda.getChild(section, "title").getTextContent());
list.setStatus(ListStatus.CURRENT);
list.setMode(ListMode.SNAPSHOT);
list.setDateElement(context.getNow());
list.setSource(context.getAuthorRef());
buildNarrative(list, cda.getChild(section, "text"));
int i = 0;
for (Element c : cda.getChildren(section, "entry")) {
// allergy problem act
Element sa = cda.getChild(c, "substanceAdministration");
MedicationStatement ms = new MedicationStatement();
ms.setId(context.getBaseId() + "-medication-" + i);
ms.setUserData("profile", "http://hl7.org/fhir/StructureDefinition/medicationstatement-daf-dafmedicationstatement");
i++;
ms.setSubject(context.getSubjectRef());
boolean found = false;
for (Element e : cda.getChildren(sa, "id")) {
Identifier id = convert.makeIdentifierFromII(e);
ms.getIdentifier().add(id);
}
if (!found) {
ms.setStatus(MedicationStatementStatus.COMPLETED);
list.addEntry().setItem(new Reference().setReference("MedicationStatement/" + ms.getId()));
// allergy observation
Element mm = cda.getChild(cda.getChild(cda.getChild(sa, "consumable"), "manufacturedProduct"), "manufacturedMaterial");
ms.setMedication(new Reference().setReference("#med"));
Medication med = new Medication();
med.setId("med");
med.setCode(inspectCode(convert.makeCodeableConceptFromCD(cda.getChild(mm, "code")), null));
ms.getContained().add(med);
Dosage dosage = ms.addDosage();
// allergy observation
Element qty = cda.getChild(sa, "doseQuantity");
try {
if (cda.getChild(qty, "low") != null) {
// todo: this is not correct?
dosage.getExtension().add(new Extension().setUrl("http://healthintersections.com.au/fhir/extensions/medication-statement-range").setValue(convert.makeRangeFromIVLPQ(qty)));
} else {
dosage.setDose(convert.makeQuantityFromPQ(qty));
}
} catch (Exception e) {
System.out.println(" invalid dose quantity '" + qty.getAttribute("value") + " " + qty.getAttribute("unit") + "' (" + e.getClass().getName() + ") in " + context.getBaseId());
}
dosage.setRoute(inspectCode(convert.makeCodeableConceptFromCD(cda.getChild(sa, "routeCode")), null));
Type t = convert.makeSomethingFromGTS(cda.getChildren(sa, "effectiveTime"));
if (t instanceof Timing) {
dosage.setTiming((Timing) t);
if (dosage.getTiming().hasRepeat() && dosage.getTiming().getRepeat().hasBounds())
ms.setEffective(dosage.getTiming().getRepeat().getBounds());
} else if (t instanceof Period)
ms.setEffective(t);
else
throw new Exception("Undecided how to handle " + t.getClass().getName());
for (Element e : cda.getChildren(sa, "author")) {
if (ms.hasInformationSource())
throw new Error("additional author discovered");
Practitioner p = processPerformer(cda, convert, context, e, "assignedAuthor", "assignedPerson");
Reference ref = new Reference().setReference("Practitioner/" + p.getId()).setDisplay(p.getUserString("display"));
ms.setInformationSource(ref);
ms.setDateAssertedElement(convert.makeDateTimeFromTS(cda.getChild(e, "time")));
}
saveResource(ms);
}
}
saveResource(list);
}
Aggregations