Generated Narrative: StructureMap ExtractVitalSigns #xD; /// url = 'https://fhir.slade360.co.ke/fhir/StructureMap/ExtractVitalSigns'#xD; /// name = 'ExtractVitalSigns'#xD; /// status = 'draft'#xD; #xD; uses "http://hl7.org/fhir/StructureDefinition/QuestionnaireResponse" alias QR as source#xD; uses "http://hl7.org/fhir/StructureDefinition/Bundle" alias Bundle as target#xD; uses "http://hl7.org/fhir/StructureDefinition/Observation" alias Observation as target#xD; #xD; group ExtractVitalSigns(source qr : QR, target bundle : Bundle) {#xD; qr -> bundle.type = 'transaction' "setBundleType";#xD; qr.item as itH where (linkId = '8302-2') then {#xD; itH.answer first as aH then {#xD; aH -> bundle.entry as eH, eH.resource = create('Observation') as oH then {#xD; qr -> oH, eH then BuildBaseObs(qr, oH, eH) "heightBase";#xD; qr -> oH.code = cc('http://loinc.org', '8302-2', 'Body Height') "codeH";#xD; aH.value as hv -> oH.valueQuantity as vH then {#xD; hv -> vH.value = hv "setVal";#xD; qr -> vH.system = 'http://unitsofmeasure.org' "setSys";#xD; qr -> vH.code = 'cm' "setCode";#xD; qr -> vH.unit = 'centimeter' "setUnit";#xD; } "valH";#xD; } "heightObs";#xD; } "heightAns";#xD; } "heightRule"; // Height#xD; qr.item as itW where (linkId = '29463-7') then {#xD; itW.answer first as aW then {#xD; aW -> bundle.entry as eW, eW.resource = create('Observation') as oW then {#xD; qr -> oW, eW then BuildBaseObs(qr, oW, eW) "weightBase";#xD; qr -> oW.code = cc('http://loinc.org', '29463-7', 'Body Weight') "codeW";#xD; aW.value as hv -> oW.valueQuantity as vW then {#xD; hv -> vW.value = hv "setVal";#xD; qr -> vW.system = 'http://unitsofmeasure.org' "setSys";#xD; qr -> vW.code = 'kg' "setCode";#xD; qr -> vW.unit = 'kilogram' "setUnit";#xD; } "valW";#xD; } "weightObs";#xD; } "weightAns";#xD; } "weightRule"; // Weight#xD; qr.item as itBmi where (linkId = '39156-5') then {#xD; itBmi.answer first as aBmi then {#xD; aBmi -> bundle.entry as eBmi, eBmi.resource = create('Observation') as oBmi then {#xD; qr -> oBmi, eBmi then BuildBaseObs(qr, oBmi, eBmi) "bmiBase";#xD; qr -> oBmi.code = cc('http://loinc.org', '39156-5', 'Body mass index (BMI) [Ratio]') "codeBmi";#xD; aBmi.value as hv -> oBmi.valueQuantity as vBmi then {#xD; hv -> vBmi.value = hv "setVal";#xD; qr -> vBmi.system = 'http://unitsofmeasure.org' "setSys";#xD; qr -> vBmi.code = 'kg/m2' "setCode";#xD; qr -> vBmi.unit = 'kilogram per square meter' "setUnit";#xD; } "valBmi";#xD; itBmi.item as bmiStatusItem where (linkId = '39156-5_status') then {#xD; bmiStatusItem.answer first as bmiStatusAns -> oBmi.interpretation as iBmi then {#xD; bmiStatusAns.value as statusText -> iBmi.text = statusText "interpBmi";#xD; } "setInterpBmi";#xD; } "findBmiStatus"; // Interpretation 39156-5_status#xD; } "bmiObs";#xD; } "bmiAns";#xD; } "bmiRule"; // BMI#xD; qr.item as itP where (linkId = '8889-8') then {#xD; itP.answer first as aP then {#xD; aP -> bundle.entry as eP, eP.resource = create('Observation') as oP then {#xD; qr -> oP, eP then BuildBaseObs(qr, oP, eP) "pulseBase";#xD; qr -> oP.code = cc('http://loinc.org', '8889-8', 'Heart rate by Pulse oximetry') "codeP";#xD; aP.value as hv -> oP.valueQuantity as vP then {#xD; hv -> vP.value = hv "setVal";#xD; qr -> vP.system = 'http://unitsofmeasure.org' "setSys";#xD; qr -> vP.code = '/min' "setCode";#xD; qr -> vP.unit = 'per minute' "setUnit";#xD; } "valP";#xD; } "pulseObs";#xD; } "pulseAns";#xD; } "pulseRule"; // Pulse#xD; qr.item as itBP where (linkId = '55284-4') then {#xD; itBP.answer first as aPanel then {#xD; aPanel -> bundle.entry as eBP, eBP.resource = create('Observation') as oBP then {#xD; qr -> oBP, eBP then BuildBaseObs(qr, oBP, eBP) "bpBase";#xD; qr -> oBP.code = cc('http://loinc.org', '55284-4', 'Blood pressure systolic and diastolic') "codeBP";#xD; itBP.item as itSys where (linkId = '8480-6') then {#xD; itSys.answer first as aSys -> oBP.component as cSys then {#xD; aSys -> cSys.code = cc('http://loinc.org', '8480-6', 'Systolic blood pressure') "bpSysCode";#xD; aSys.value as hv -> cSys.valueQuantity as vSys then {#xD; hv -> vSys.value = hv "setVal";#xD; qr -> vSys.system = 'http://unitsofmeasure.org' "setSys";#xD; qr -> vSys.code = 'mm[Hg]' "setCode";#xD; qr -> vSys.unit = 'millimeter of mercury' "setUnit";#xD; } "bpSysVal";#xD; } "bpSysComponent";#xD; } "bpSysRule"; // Systolic 8480-6#xD; itBP.item as itDia where (linkId = '8462-4') then {#xD; itDia.answer first as aDia -> oBP.component as cDia then {#xD; aDia -> cDia.code = cc('http://loinc.org', '8462-4', 'Diastolic blood pressure') "bpDiaCode";#xD; aDia.value as hv -> cDia.valueQuantity as vDia then {#xD; hv -> vDia.value = hv "setVal";#xD; qr -> vDia.system = 'http://unitsofmeasure.org' "setSys";#xD; qr -> vDia.code = 'mm[Hg]' "setCode";#xD; qr -> vDia.unit = 'millimeter of mercury' "setUnit";#xD; } "bpDiaVal";#xD; } "bpDiaComponent";#xD; } "bpDiaRule"; // Diastolic 8462-4#xD; } "bpObs";#xD; } "bpAns";#xD; } "bpRule"; // Blood Pressure#xD; qr.item as itT where (linkId = '8310-5') then {#xD; itT.answer first as aT then {#xD; aT -> bundle.entry as eT, eT.resource = create('Observation') as oT then {#xD; qr -> oT, eT then BuildBaseObs(qr, oT, eT) "tempBase";#xD; qr -> oT.code = cc('http://loinc.org', '8310-5', 'Body Temperature') "codeT";#xD; aT.value as hv -> oT.valueQuantity as vT then {#xD; hv -> vT.value = hv "setVal";#xD; qr -> vT.system = 'http://unitsofmeasure.org' "setSys";#xD; qr -> vT.code = 'Cel' "setCode";#xD; qr -> vT.unit = 'degree Celsius' "setUnit";#xD; } "valT";#xD; itT.item as tStatusItem where (linkId = '8310-5_status') then {#xD; tStatusItem.answer first as tStatusAns -> oT.interpretation as iT then {#xD; tStatusAns.value as statusText -> iT.text = statusText "interpT";#xD; } "setInterpT";#xD; } "findTStatus"; // Interpretation 8310-5_status#xD; } "tempObs";#xD; } "tempAns";#xD; } "tempRule"; // Temperature#xD; qr.item as itO2 where (linkId = '20564-1') then {#xD; itO2.answer first as aO2 then {#xD; aO2 -> bundle.entry as eO2, eO2.resource = create('Observation') as oO2 then {#xD; qr -> oO2, eO2 then BuildBaseObs(qr, oO2, eO2) "spo2Base";#xD; qr -> oO2.code = cc('http://loinc.org', '20564-1', 'Oxygen saturation in Blood') "codeO2";#xD; aO2.value as hv -> oO2.valueQuantity as vO2 then {#xD; hv -> vO2.value = hv "setVal";#xD; qr -> vO2.system = 'http://unitsofmeasure.org' "setSys";#xD; qr -> vO2.code = '%' "setCode";#xD; qr -> vO2.unit = '%' "setUnit";#xD; } "valO2";#xD; itO2.item as o2StatusItem where (linkId = '20564-1_status') then {#xD; o2StatusItem.answer first as o2StatusAns -> oO2.interpretation as iO2 then {#xD; o2StatusAns.value as statusText -> iO2.text = statusText "interpO2";#xD; } "setInterpO2";#xD; } "findO2Status"; // Interpretation of SpO2 20564-1_status#xD; } "spo2Obs";#xD; } "spo2Ans";#xD; } "spo2Rule"; // SpO2#xD; qr.item as itRR where (linkId = '9279-1') then {#xD; itRR.answer first as aRR then {#xD; aRR -> bundle.entry as eRR, eRR.resource = create('Observation') as oRR then {#xD; qr -> oRR, eRR then BuildBaseObs(qr, oRR, eRR) "rrBase";#xD; qr -> oRR.code = cc('http://loinc.org', '9279-1', 'Respiratory rate') "codeRR";#xD; aRR.value as hv -> oRR.valueQuantity as vRR then {#xD; hv -> vRR.value = hv "setVal";#xD; qr -> vRR.system = 'http://unitsofmeasure.org' "setSys";#xD; qr -> vRR.code = '/min' "setCode";#xD; qr -> vRR.unit = 'per minute' "setUnit";#xD; } "valRR";#xD; } "rrObs";#xD; } "rrAns";#xD; } "rrRule"; // Respiratory rate#xD; qr.item as itMuac where (linkId = '9847-5') then {#xD; itMuac.answer first as aMuac then {#xD; aMuac -> bundle.entry as eMuac, eMuac.resource = create('Observation') as oMuac then {#xD; qr -> oMuac, eMuac then BuildBaseObs(qr, oMuac, eMuac) "muacBase";#xD; qr -> oMuac.code = cc('http://loinc.org', '9847-5', 'Circumference') "codeMuac";#xD; aMuac.value as hv -> oMuac.valueQuantity as vMuac then {#xD; hv -> vMuac.value = hv "setVal";#xD; qr -> vMuac.system = 'http://unitsofmeasure.org' "setSys";#xD; qr -> vMuac.code = 'mm' "setCode";#xD; qr -> vMuac.unit = 'millimeter' "setUnit";#xD; } "valMuac";#xD; } "muacObs";#xD; } "muacAns";#xD; } "muacRule"; // MUAC#xD; qr.item as itCC where (linkId = '10154-3') then {#xD; itCC.answer first as aCC then {#xD; aCC -> bundle.entry as eCC, eCC.resource = create('Observation') as oCC then {#xD; qr -> oCC, eCC then BuildBaseObs(qr, oCC, eCC) "chiefComplaintBase";#xD; qr -> oCC.category = cc('http://terminology.hl7.org/CodeSystem/observation-category', 'social-history', 'Social History') "chiefComplaintCategory"; // Override category to social-history#xD; qr -> oCC.code = cc('http://loinc.org', '10154-3', 'Chief complaint Narrative') "chiefComplaintCode";#xD; aCC.value as textVal -> oCC.valueString = textVal "chiefComplaintValue";#xD; } "chiefComplaintObs";#xD; } "chiefComplaintAns";#xD; } "chiefComplaintRule"; // Chief Complaint#xD; qr.item as hpiCC where (linkId = '8684-3') then {#xD; hpiCC.answer first as aCC then {#xD; aCC -> bundle.entry as eCC, eCC.resource = create('Observation') as oCC then {#xD; qr -> oCC, eCC then BuildBaseObs(qr, oCC, eCC) "historyOfPIBase";#xD; qr -> oCC.category = cc('http://terminology.hl7.org/CodeSystem/observation-category', 'social-history', 'Social History') "historyOfPICategory"; // Override category to social-history#xD; qr -> oCC.code = cc('http://loinc.org', '8684-3', 'History of Present illness') "historyOfPICode";#xD; aCC.value as textVal -> oCC.valueString = textVal "historyOfPIValue";#xD; } "historyOfPIObs";#xD; } "historyOfPIAns";#xD; } "historyOfPIRule"; // History of Presenting Illness#xD; qr.item as hPastCC where (linkId = '11349-8') then {#xD; hPastCC.answer first as aCC then {#xD; aCC -> bundle.entry as eCC, eCC.resource = create('Observation') as oCC then {#xD; qr -> oCC, eCC then BuildBaseObs(qr, oCC, eCC) "historyOfPastIBase";#xD; qr -> oCC.category = cc('http://terminology.hl7.org/CodeSystem/observation-category', 'social-history', 'Social History') "historyOfPastICategory"; // Override category to social-history#xD; qr -> oCC.code = cc('http://loinc.org', '11349-8', 'History of Past illness') "historyOfPastICode";#xD; aCC.value as textVal -> oCC.valueString = textVal "historyOfPastIValue";#xD; } "historyOfPastIObs";#xD; } "historyOfPastIAns";#xD; } "historyOfPastIRule"; // History of Past Illness#xD; }#xD; #xD; group BuildBaseObs(source qr : QR, target obs : Observation, target entry) {#xD; qr -> obs.status = 'final' "status";#xD; qr.subject as s -> obs.subject = s;#xD; qr.encounter as e -> obs.encounter = e;#xD; qr.authored as t -> obs.effectiveDateTime = t "effective";#xD; qr -> obs.category = cc('http://terminology.hl7.org/CodeSystem/observation-category', 'vital-signs', 'Vital Signs') "category"; // Category (vital signs) - defaukt#xD; qr -> obs.id = uuid() then SetObservationFullUrl(obs, entry) "setObsIdAndFullUrl"; // Observation id and fullUrl#xD; qr -> entry.request as request then {#xD; qr -> request.method = 'POST' "reqMethod";#xD; qr -> request.url = 'Observation' "reqUrl";#xD; } "entryRequest"; // Bundle.entry.request (transaction POST Observation)#xD; qr -> obs.derivedFrom = create('Reference') as newRef then {#xD; qr.id as qid -> newRef.reference = append('QuestionnaireResponse/', qid) "setQRRef";#xD; } "linkQR"; // Link Observation -> QuestionnaireResponse#xD; }#xD; #xD; group SetObservationFullUrl(source obs : Observation, target entry) {#xD; obs.id as id -> entry.fullUrl = append('https://fhir.slade360.co.ke/fhir/Observation/', id) "assignFullUrl";#xD; }#xD; #xD;
Bundle.entry.request (transaction POST Observation)
Link Observation -> QuestionnaireResponse