SGHI FHIR Profile Implementation Guide
0.1.0 - ci-build
SGHI FHIR Profile Implementation Guide, published by Kathurima Kimathi. This guide is not an authorized publication; it is the continuous build for version 0.1.0 built by the FHIR (HL7® FHIR® Standard) CI Build. This version is based on the current content of https://github.com/savannahghi/sil_fhir_profile_ig/ and changes regularly. See the Directory of published versions
| Active as of 2026-09-14 |
<StructureMap xmlns="http://hl7.org/fhir">
<id value="ExtractMorseFallScale"/>
<text>
<status value="generated"/>
<div xmlns="http://www.w3.org/1999/xhtml"><p class="res-header-id"><b>Generated Narrative: StructureMap ExtractMorseFallScale</b></p><a name="ExtractMorseFallScale"> </a><a name="hcExtractMorseFallScale"> </a><pre class="fml">
<span style="color: #cc00cc">/// <b>url</b> = </span><span style="color: blue">'https://fhir.slade360.co.ke/fhir/StructureMap/ExtractMorseFallScale'</span>
<span style="color: #cc00cc">/// <b>name</b> = </span><span style="color: blue">'ExtractMorseFallScale'</span>
<span style="color: #cc00cc">/// <b>title</b> = </span><span style="color: blue">'Morse Fall Scale Extraction'</span>
<span style="color: #cc00cc">/// <b>status</b> = </span><span style="color: blue">'active'</span>
<span style="color: #cc00cc">/// <b>description</b> = </span><span style="color: blue">'The LOINC Morse Fall Scale panel out as one Observation carrying the total, with the six weighted questions as components, plus a RiskAssessment for the band the total falls in. The total prefers what the form submitted and otherwise sums the answers itself, and it only extracts when all six questions have been answered: a Morse score short of an item is not a Morse score, and banding one puts a number a nurse can act on next to a risk tier that is wrong.'</span>
<b>uses</b><span style="color: navy"> "</span><a href="http://hl7.org/fhir/R5/questionnaireresponse.html" title="QuestionnaireResponse">http://hl7.org/fhir/StructureDefinition/QuestionnaireResponse</a><span style="color: navy">" </span><b>alias </b>QR <b>as </b><b>source</b>
<b>uses</b><span style="color: navy"> "</span><a href="http://hl7.org/fhir/R5/bundle.html" title="Bundle">http://hl7.org/fhir/StructureDefinition/Bundle</a><span style="color: navy">" </span><b>alias </b>Bundle <b>as </b><b>target</b>
<b>uses</b><span style="color: navy"> "</span><a href="http://hl7.org/fhir/R5/observation.html" title="Observation">http://hl7.org/fhir/StructureDefinition/Observation</a><span style="color: navy">" </span><b>alias </b>Observation <b>as </b><b>target</b>
<b>uses</b><span style="color: navy"> "</span><a href="http://hl7.org/fhir/R5/riskassessment.html" title="RiskAssessment">http://hl7.org/fhir/StructureDefinition/RiskAssessment</a><span style="color: navy">" </span><b>alias </b>RiskAssessment <b>as </b><b>target</b>
<b>group </b>ExtractMorseFallScale<span style="color: navy">(</span><b>source</b> <span style="color: maroon">qr</span><span style="color: navy"> : </span>QR, <b>target</b> <span style="color: maroon">bundle</span><span style="color: navy"> : </span>Bundle<span style="color: navy">)</span><span style="color: navy"> {
</span> qr<span style="color: navy"><b> -> </b></span>bundle.type = <span style="color: blue">'transaction'</span> <i>"setBundleType"</i><span style="color: navy">;</span>
<span style="color: navy">// </span><span style="color: green">LOINC publishes this panel flat -- the six questions, the total and the risk</span>
<span style="color: navy">// </span><span style="color: green">level are all top-level items keyed by their own LOINC code -- so there is no</span>
<span style="color: navy">// </span><span style="color: green">group to hang the Observation off and the response itself is the anchor.</span>
qr<b> where </b><span style="color: navy">(</span>item.where(linkId in ('59454-9' | '59455-6' | '59456-4' | '59457-2' | '59458-0' | '59459-8')).answer.value.ofType(Coding).exists()<span style="color: navy">)</span><span style="color: navy"><b> -> </b></span> bundle.entry<b> as </b><span style="color: maroon">entry</span><span style="color: navy">, </span> entry.resource = <b>create</b><span style="color: navy">(</span><span style="color: blue">'Observation'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">obs</span><b> then</b><span style="color: navy"> {
</span> qr<span style="color: navy"><b> -> </b></span> obs<span style="color: navy">, </span> entry<b> then </b>BuildObsBase<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">obs</span><span style="color: navy">, </span><span style="color: maroon">entry</span><span style="color: navy">)</span> <i>"base"</i><span style="color: navy">;</span>
qr<span style="color: navy"><b> -> </b></span>obs<b> then </b>SetSurveyCategory<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">obs</span><span style="color: navy">)</span> <i>"category"</i><span style="color: navy">;</span>
qr<span style="color: navy"><b> -> </b></span>obs.code<b> as </b><span style="color: maroon">code</span><b> then</b><span style="color: navy"> {
</span> qr<span style="color: navy"><b> -> </b></span>code.coding<b> as </b><span style="color: maroon">coding</span><b> then</b><span style="color: navy"> {
</span> qr<span style="color: navy"><b> -> </b></span>coding.system = <span style="color: blue">'http://loinc.org'</span> <i>"codeSystem"</i><span style="color: navy">;</span>
qr<span style="color: navy"><b> -> </b></span>coding.code = <span style="color: blue">'59460-6'</span> <i>"codeCode"</i><span style="color: navy">;</span>
qr<span style="color: navy"><b> -> </b></span>coding.display = <span style="color: blue">'Fall risk total [Morse Fall Scale]'</span> <i>"codeDisplay"</i><span style="color: navy">;</span>
<span style="color: navy">}</span> <i>"codeCoding"</i><span style="color: navy">;</span>
<span style="color: navy">}</span> <i>"code"</i><span style="color: navy">;</span>
<span style="color: navy">// </span><span style="color: green">The submitted total wins; otherwise sum the answers.</span>
<span style="color: navy">// </span><span style="color: green">The weights have to be resolved question by question rather than from one</span>
<span style="color: navy">// </span><span style="color: green">lookup, because Morse reuses LOINC's plain yes/no pair across three</span>
<span style="color: navy">// </span><span style="color: green">questions at three different weights: LA33-6 "Yes" is worth 25 on the</span>
<span style="color: navy">// </span><span style="color: green">history of falling, 15 on a secondary diagnosis and 20 on an intravenous</span>
<span style="color: navy">// </span><span style="color: green">line. A global code-to-weight table would silently score all three the</span>
<span style="color: navy">// </span><span style="color: green">same. The weights are Morse's own, as printed on the form.</span>
<span style="color: navy">// </span><span style="color: green">truncate(), not toInteger(): the form types the total `decimal`, and this</span>
<span style="color: navy">// </span><span style="color: green">engine's toInteger() returns empty for anything with a fractional part.</span>
<span style="color: navy">// </span><span style="color: green">Observation.value has no decimal choice, so it has to land as an integer.</span>
<span style="color: navy">// </span><span style="color: green">Guarded on all six questions being answered.</span>
qr<b> where </b><span style="color: navy">(</span>item.where(linkId in ('59454-9' | '59455-6' | '59456-4' | '59457-2' | '59458-0' | '59459-8')).answer.value.ofType(Coding).count() = 6<span style="color: navy">)</span><b> then</b><span style="color: navy"> {
</span> qr<span style="color: navy"><b> -> </b></span>obs.value = evaluate<span style="color: navy">(</span>qr<span style="color: navy">, </span>iif(item.where(linkId = '59460-6').answer.value.exists(), item.where(linkId = '59460-6').answer.value.truncate(), iif(item.where(linkId = '59454-9').answer.value.ofType(Coding).code = 'LA33-6', 25, 0) + iif(item.where(linkId = '59455-6').answer.value.ofType(Coding).code = 'LA33-6', 15, 0) + iif(item.where(linkId = '59456-4').answer.value.ofType(Coding).code = 'LA13031-2', 15, iif(item.where(linkId = '59456-4').answer.value.ofType(Coding).code = 'LA13032-0', 30, 0)) + iif(item.where(linkId = '59457-2').answer.value.ofType(Coding).code = 'LA33-6', 20, 0) + iif(item.where(linkId = '59458-0').answer.value.ofType(Coding).code = 'LA13034-6', 10, iif(item.where(linkId = '59458-0').answer.value.ofType(Coding).code = 'LA13035-3', 20, 0)) + iif(item.where(linkId = '59459-8').answer.value.ofType(Coding).code = 'LA13037-9', 15, 0))<span style="color: navy">)</span> <i>"totalValue"</i><span style="color: navy">;</span>
<span style="color: navy">}</span> <i>"totalRule"</i><span style="color: navy">;</span>
qr.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = '59454-9') and answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -> </b></span>obs.component<b> as </b><span style="color: maroon">comp</span><b> then</b><span style="color: navy"> {
</span> it<span style="color: navy"><b> -> </b></span>comp.code<b> as </b><span style="color: maroon">code</span><b> then</b><span style="color: navy"> {
</span> it<span style="color: navy"><b> -> </b></span>code.coding<b> as </b><span style="color: maroon">coding</span><b> then</b><span style="color: navy"> {
</span> it<span style="color: navy"><b> -> </b></span>coding.system = <span style="color: blue">'http://loinc.org'</span> <i>"codeSystem"</i><span style="color: navy">;</span>
it<span style="color: navy"><b> -> </b></span>coding.code = <span style="color: blue">'59454-9'</span> <i>"codeCode"</i><span style="color: navy">;</span>
it<span style="color: navy"><b> -> </b></span>coding.display = <span style="color: blue">'History of falling; immediate or within 3 months [Morse Fall Scale]'</span> <i>"codeDisplay"</i><span style="color: navy">;</span>
<span style="color: navy">}</span> <i>"codeCoding"</i><span style="color: navy">;</span>
<span style="color: navy">}</span> <i>"historyCode"</i><span style="color: navy">;</span>
it<span style="color: navy"><b> -> </b></span>comp<b> then </b>SetComponentCodedValue<span style="color: navy">(</span><span style="color: maroon">it</span><span style="color: navy">, </span><span style="color: maroon">comp</span><span style="color: navy">)</span> <i>"historyValue"</i><span style="color: navy">;</span>
<span style="color: navy">}</span> <i>"historyRule"</i><span style="color: navy">;</span>
qr.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = '59455-6') and answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -> </b></span>obs.component<b> as </b><span style="color: maroon">comp</span><b> then</b><span style="color: navy"> {
</span> it<span style="color: navy"><b> -> </b></span>comp.code<b> as </b><span style="color: maroon">code</span><b> then</b><span style="color: navy"> {
</span> it<span style="color: navy"><b> -> </b></span>code.coding<b> as </b><span style="color: maroon">coding</span><b> then</b><span style="color: navy"> {
</span> it<span style="color: navy"><b> -> </b></span>coding.system = <span style="color: blue">'http://loinc.org'</span> <i>"codeSystem"</i><span style="color: navy">;</span>
it<span style="color: navy"><b> -> </b></span>coding.code = <span style="color: blue">'59455-6'</span> <i>"codeCode"</i><span style="color: navy">;</span>
it<span style="color: navy"><b> -> </b></span>coding.display = <span style="color: blue">'Secondary diagnosis is present'</span> <i>"codeDisplay"</i><span style="color: navy">;</span>
<span style="color: navy">}</span> <i>"codeCoding"</i><span style="color: navy">;</span>
<span style="color: navy">}</span> <i>"diagnosisCode"</i><span style="color: navy">;</span>
it<span style="color: navy"><b> -> </b></span>comp<b> then </b>SetComponentCodedValue<span style="color: navy">(</span><span style="color: maroon">it</span><span style="color: navy">, </span><span style="color: maroon">comp</span><span style="color: navy">)</span> <i>"diagnosisValue"</i><span style="color: navy">;</span>
<span style="color: navy">}</span> <i>"diagnosisRule"</i><span style="color: navy">;</span>
qr.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = '59456-4') and answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -> </b></span>obs.component<b> as </b><span style="color: maroon">comp</span><b> then</b><span style="color: navy"> {
</span> it<span style="color: navy"><b> -> </b></span>comp.code<b> as </b><span style="color: maroon">code</span><b> then</b><span style="color: navy"> {
</span> it<span style="color: navy"><b> -> </b></span>code.coding<b> as </b><span style="color: maroon">coding</span><b> then</b><span style="color: navy"> {
</span> it<span style="color: navy"><b> -> </b></span>coding.system = <span style="color: blue">'http://loinc.org'</span> <i>"codeSystem"</i><span style="color: navy">;</span>
it<span style="color: navy"><b> -> </b></span>coding.code = <span style="color: blue">'59456-4'</span> <i>"codeCode"</i><span style="color: navy">;</span>
it<span style="color: navy"><b> -> </b></span>coding.display = <span style="color: blue">'Ambulatory aid [Morse Fall Scale]'</span> <i>"codeDisplay"</i><span style="color: navy">;</span>
<span style="color: navy">}</span> <i>"codeCoding"</i><span style="color: navy">;</span>
<span style="color: navy">}</span> <i>"aidCode"</i><span style="color: navy">;</span>
it<span style="color: navy"><b> -> </b></span>comp<b> then </b>SetComponentCodedValue<span style="color: navy">(</span><span style="color: maroon">it</span><span style="color: navy">, </span><span style="color: maroon">comp</span><span style="color: navy">)</span> <i>"aidValue"</i><span style="color: navy">;</span>
<span style="color: navy">}</span> <i>"aidRule"</i><span style="color: navy">;</span>
qr.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = '59457-2') and answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -> </b></span>obs.component<b> as </b><span style="color: maroon">comp</span><b> then</b><span style="color: navy"> {
</span> it<span style="color: navy"><b> -> </b></span>comp.code<b> as </b><span style="color: maroon">code</span><b> then</b><span style="color: navy"> {
</span> it<span style="color: navy"><b> -> </b></span>code.coding<b> as </b><span style="color: maroon">coding</span><b> then</b><span style="color: navy"> {
</span> it<span style="color: navy"><b> -> </b></span>coding.system = <span style="color: blue">'http://loinc.org'</span> <i>"codeSystem"</i><span style="color: navy">;</span>
it<span style="color: navy"><b> -> </b></span>coding.code = <span style="color: blue">'59457-2'</span> <i>"codeCode"</i><span style="color: navy">;</span>
it<span style="color: navy"><b> -> </b></span>coding.display = <span style="color: blue">'Intravenous apparatus [Morse Fall Scale]'</span> <i>"codeDisplay"</i><span style="color: navy">;</span>
<span style="color: navy">}</span> <i>"codeCoding"</i><span style="color: navy">;</span>
<span style="color: navy">}</span> <i>"ivCode"</i><span style="color: navy">;</span>
it<span style="color: navy"><b> -> </b></span>comp<b> then </b>SetComponentCodedValue<span style="color: navy">(</span><span style="color: maroon">it</span><span style="color: navy">, </span><span style="color: maroon">comp</span><span style="color: navy">)</span> <i>"ivValue"</i><span style="color: navy">;</span>
<span style="color: navy">}</span> <i>"ivRule"</i><span style="color: navy">;</span>
qr.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = '59458-0') and answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -> </b></span>obs.component<b> as </b><span style="color: maroon">comp</span><b> then</b><span style="color: navy"> {
</span> it<span style="color: navy"><b> -> </b></span>comp.code<b> as </b><span style="color: maroon">code</span><b> then</b><span style="color: navy"> {
</span> it<span style="color: navy"><b> -> </b></span>code.coding<b> as </b><span style="color: maroon">coding</span><b> then</b><span style="color: navy"> {
</span> it<span style="color: navy"><b> -> </b></span>coding.system = <span style="color: blue">'http://loinc.org'</span> <i>"codeSystem"</i><span style="color: navy">;</span>
it<span style="color: navy"><b> -> </b></span>coding.code = <span style="color: blue">'59458-0'</span> <i>"codeCode"</i><span style="color: navy">;</span>
it<span style="color: navy"><b> -> </b></span>coding.display = <span style="color: blue">'Gait [Morse Fall Scale]'</span> <i>"codeDisplay"</i><span style="color: navy">;</span>
<span style="color: navy">}</span> <i>"codeCoding"</i><span style="color: navy">;</span>
<span style="color: navy">}</span> <i>"gaitCode"</i><span style="color: navy">;</span>
it<span style="color: navy"><b> -> </b></span>comp<b> then </b>SetComponentCodedValue<span style="color: navy">(</span><span style="color: maroon">it</span><span style="color: navy">, </span><span style="color: maroon">comp</span><span style="color: navy">)</span> <i>"gaitValue"</i><span style="color: navy">;</span>
<span style="color: navy">}</span> <i>"gaitRule"</i><span style="color: navy">;</span>
qr.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = '59459-8') and answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -> </b></span>obs.component<b> as </b><span style="color: maroon">comp</span><b> then</b><span style="color: navy"> {
</span> it<span style="color: navy"><b> -> </b></span>comp.code<b> as </b><span style="color: maroon">code</span><b> then</b><span style="color: navy"> {
</span> it<span style="color: navy"><b> -> </b></span>code.coding<b> as </b><span style="color: maroon">coding</span><b> then</b><span style="color: navy"> {
</span> it<span style="color: navy"><b> -> </b></span>coding.system = <span style="color: blue">'http://loinc.org'</span> <i>"codeSystem"</i><span style="color: navy">;</span>
it<span style="color: navy"><b> -> </b></span>coding.code = <span style="color: blue">'59459-8'</span> <i>"codeCode"</i><span style="color: navy">;</span>
it<span style="color: navy"><b> -> </b></span>coding.display = <span style="color: blue">'Mental status [Morse Fall Scale]'</span> <i>"codeDisplay"</i><span style="color: navy">;</span>
<span style="color: navy">}</span> <i>"codeCoding"</i><span style="color: navy">;</span>
<span style="color: navy">}</span> <i>"mentalCode"</i><span style="color: navy">;</span>
it<span style="color: navy"><b> -> </b></span>comp<b> then </b>SetComponentCodedValue<span style="color: navy">(</span><span style="color: maroon">it</span><span style="color: navy">, </span><span style="color: maroon">comp</span><span style="color: navy">)</span> <i>"mentalValue"</i><span style="color: navy">;</span>
<span style="color: navy">}</span> <i>"mentalRule"</i><span style="color: navy">;</span>
qr<span style="color: navy"><b> -> </b></span> obs<span style="color: navy">, </span> bundle<b> then </b>AddMorseRiskAssessment<span style="color: navy">(</span><span style="color: maroon">obs</span><span style="color: navy">, </span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">bundle</span><span style="color: navy">)</span> <i>"band"</i><span style="color: navy">;</span>
<span style="color: navy">}</span> <i>"morseRule"</i><span style="color: navy">;</span>
<span style="color: navy">}
</span><span style="color: navy">// </span><span style="color: green">─────────────────────────────────────────────────────────────────────────────</span>
<span style="color: navy">// </span><span style="color: green">The band</span>
<span style="color: navy">// </span><span style="color: green">These are the tiers LOINC's own answer list for 59461-4 carries, which is the</span>
<span style="color: navy">// </span><span style="color: green">three-tier reading of Morse in general use and the list printed on this form:</span>
<span style="color: navy">// </span><span style="color: green">0-24 low, 25-45 moderate, 50 and over high. Higher is worse.</span>
<span style="color: navy">// </span><span style="color: green">Two things to know about it.</span>
<span style="color: navy">// </span><span style="color: green">The published list leaves 46 to 49 unnamed. A computed total never lands</span>
<span style="color: navy">// </span><span style="color: green">there -- every one of Morse's item weights is a multiple of five, so the sum</span>
<span style="color: navy">// </span><span style="color: green">is too -- but a total the form submits can, since that item is a free decimal.</span>
<span style="color: navy">// </span><span style="color: green">It is folded into moderate, because the alternative is a score that extracts a</span>
<span style="color: navy">// </span><span style="color: green">number and no band at all.</span>
<span style="color: navy">// </span><span style="color: green">It is not the banding `ExtractInpatientFallsAndPressureUlcerRiskAssessment`</span>
<span style="color: navy">// </span><span style="color: green">uses. That map scores the same six items from a hand-built form and bands them</span>
<span style="color: navy">// </span><span style="color: green">on Morse's original paper -- 0-24 no risk, 25-50 low, 51 and over high -- so</span>
<span style="color: navy">// </span><span style="color: green">the two maps can disagree between 25 and 50. The divergence is deliberate: a</span>
<span style="color: navy">// </span><span style="color: green">band that contradicts the pick list on the form in front of the nurse is worse</span>
<span style="color: navy">// </span><span style="color: green">than a band that differs from another form's. Reconciling them means agreeing</span>
<span style="color: navy">// </span><span style="color: green">one Morse banding for the IG and changing whichever form loses.</span>
<span style="color: navy">// </span><span style="color: green">qualitativeRisk carries two codings and a text. HL7's risk-probability is what</span>
<span style="color: navy">// </span><span style="color: green">a consumer escalates on; LOINC's answer code is the tier exactly as the form</span>
<span style="color: navy">// </span><span style="color: green">states it, ranges and all; the text is the plain wording.</span>
<span style="color: navy">// </span><span style="color: green">The band is derived from the total rather than copied from the form's own</span>
<span style="color: navy">// </span><span style="color: green">risk-level item. That item is a free pick list with nothing calculating it, so</span>
<span style="color: navy">// </span><span style="color: green">deriving is the only way the number and the tier are guaranteed to agree.</span>
<span style="color: navy">// </span><span style="color: green">─────────────────────────────────────────────────────────────────────────────</span>
<b>group </b>AddMorseRiskAssessment<span style="color: navy">(</span><b>source</b> <span style="color: maroon">obs</span><span style="color: navy"> : </span>Observation, <b>source</b> <span style="color: maroon">qr</span><span style="color: navy"> : </span>QR, <b>target</b> <span style="color: maroon">bundle</span><span style="color: navy"> : </span>Bundle<span style="color: navy">)</span><span style="color: navy"> {
</span> obs<b> where </b><span style="color: navy">(</span>value.ofType(integer) <= 24<span style="color: navy">)</span><span style="color: navy"><b> -> </b></span> bundle.entry<b> as </b><span style="color: maroon">entry</span><span style="color: navy">, </span> entry.resource = <b>create</b><span style="color: navy">(</span><span style="color: blue">'RiskAssessment'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">ra</span><b> then</b><span style="color: navy"> {
</span> qr<span style="color: navy"><b> -> </b></span> ra<span style="color: navy">, </span> entry<b> then </b>BuildRiskBase<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">obs</span><span style="color: navy">, </span><span style="color: maroon">ra</span><span style="color: navy">, </span><span style="color: maroon">entry</span><span style="color: navy">)</span> <i>"riskBase"</i><span style="color: navy">;</span>
qr<span style="color: navy"><b> -> </b></span>ra<b> then </b>SetMorseRiskCode<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">ra</span><span style="color: navy">)</span> <i>"riskCode"</i><span style="color: navy">;</span>
qr<span style="color: navy"><b> -> </b></span>ra.prediction<b> as </b><span style="color: maroon">pred</span><b> then</b><span style="color: navy"> {
</span> qr<span style="color: navy"><b> -> </b></span>pred.qualitativeRisk<b> as </b><span style="color: maroon">risk</span><b> then</b><span style="color: navy"> {
</span> qr<span style="color: navy"><b> -> </b></span>risk.coding<b> as </b><span style="color: maroon">coding</span><b> then</b><span style="color: navy"> {
</span> qr<span style="color: navy"><b> -> </b></span>coding.system = <span style="color: blue">'http://terminology.hl7.org/CodeSystem/risk-probability'</span> <i>"riskSystem"</i><span style="color: navy">;</span>
qr<span style="color: navy"><b> -> </b></span>coding.code = <span style="color: blue">'low'</span> <i>"riskCode"</i><span style="color: navy">;</span>
qr<span style="color: navy"><b> -> </b></span>coding.display = <span style="color: blue">'Low likelihood'</span> <i>"riskDisplay"</i><span style="color: navy">;</span>
<span style="color: navy">}</span> <i>"hl7Coding"</i><span style="color: navy">;</span>
qr<span style="color: navy"><b> -> </b></span>risk.coding<b> as </b><span style="color: maroon">loinc</span><b> then</b><span style="color: navy"> {
</span> qr<span style="color: navy"><b> -> </b></span>loinc.system = <span style="color: blue">'http://loinc.org'</span> <i>"loincSystem"</i><span style="color: navy">;</span>
qr<span style="color: navy"><b> -> </b></span>loinc.code = <span style="color: blue">'LA13038-7'</span> <i>"loincCode"</i><span style="color: navy">;</span>
qr<span style="color: navy"><b> -> </b></span>loinc.display = <span style="color: blue">'Low Risk (MFS Score 0 - 24)'</span> <i>"loincDisplay"</i><span style="color: navy">;</span>
<span style="color: navy">}</span> <i>"loincCoding"</i><span style="color: navy">;</span>
qr<span style="color: navy"><b> -> </b></span>risk.text = <span style="color: blue">'Low risk'</span> <i>"riskText"</i><span style="color: navy">;</span>
<span style="color: navy">}</span> <i>"qualitativeRisk"</i><span style="color: navy">;</span>
<span style="color: navy">}</span> <i>"prediction"</i><span style="color: navy">;</span>
<span style="color: navy">}</span> <i>"morseLow"</i><span style="color: navy">;</span>
obs<b> where </b><span style="color: navy">(</span>(value.ofType(integer) >= 25) and (value.ofType(integer) <= 49)<span style="color: navy">)</span><span style="color: navy"><b> -> </b></span> bundle.entry<b> as </b><span style="color: maroon">entry</span><span style="color: navy">, </span> entry.resource = <b>create</b><span style="color: navy">(</span><span style="color: blue">'RiskAssessment'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">ra</span><b> then</b><span style="color: navy"> {
</span> qr<span style="color: navy"><b> -> </b></span> ra<span style="color: navy">, </span> entry<b> then </b>BuildRiskBase<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">obs</span><span style="color: navy">, </span><span style="color: maroon">ra</span><span style="color: navy">, </span><span style="color: maroon">entry</span><span style="color: navy">)</span> <i>"riskBase"</i><span style="color: navy">;</span>
qr<span style="color: navy"><b> -> </b></span>ra<b> then </b>SetMorseRiskCode<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">ra</span><span style="color: navy">)</span> <i>"riskCode"</i><span style="color: navy">;</span>
qr<span style="color: navy"><b> -> </b></span>ra.prediction<b> as </b><span style="color: maroon">pred</span><b> then</b><span style="color: navy"> {
</span> qr<span style="color: navy"><b> -> </b></span>pred.qualitativeRisk<b> as </b><span style="color: maroon">risk</span><b> then</b><span style="color: navy"> {
</span> qr<span style="color: navy"><b> -> </b></span>risk.coding<b> as </b><span style="color: maroon">coding</span><b> then</b><span style="color: navy"> {
</span> qr<span style="color: navy"><b> -> </b></span>coding.system = <span style="color: blue">'http://terminology.hl7.org/CodeSystem/risk-probability'</span> <i>"riskSystem"</i><span style="color: navy">;</span>
qr<span style="color: navy"><b> -> </b></span>coding.code = <span style="color: blue">'moderate'</span> <i>"riskCode"</i><span style="color: navy">;</span>
qr<span style="color: navy"><b> -> </b></span>coding.display = <span style="color: blue">'Moderate likelihood'</span> <i>"riskDisplay"</i><span style="color: navy">;</span>
<span style="color: navy">}</span> <i>"hl7Coding"</i><span style="color: navy">;</span>
qr<span style="color: navy"><b> -> </b></span>risk.coding<b> as </b><span style="color: maroon">loinc</span><b> then</b><span style="color: navy"> {
</span> qr<span style="color: navy"><b> -> </b></span>loinc.system = <span style="color: blue">'http://loinc.org'</span> <i>"loincSystem"</i><span style="color: navy">;</span>
qr<span style="color: navy"><b> -> </b></span>loinc.code = <span style="color: blue">'LA13039-5'</span> <i>"loincCode"</i><span style="color: navy">;</span>
qr<span style="color: navy"><b> -> </b></span>loinc.display = <span style="color: blue">'Moderate Risk (MFS Score 25 - 45)'</span> <i>"loincDisplay"</i><span style="color: navy">;</span>
<span style="color: navy">}</span> <i>"loincCoding"</i><span style="color: navy">;</span>
qr<span style="color: navy"><b> -> </b></span>risk.text = <span style="color: blue">'Moderate risk'</span> <i>"riskText"</i><span style="color: navy">;</span>
<span style="color: navy">}</span> <i>"qualitativeRisk"</i><span style="color: navy">;</span>
<span style="color: navy">}</span> <i>"prediction"</i><span style="color: navy">;</span>
<span style="color: navy">}</span> <i>"morseModerate"</i><span style="color: navy">;</span>
obs<b> where </b><span style="color: navy">(</span>value.ofType(integer) >= 50<span style="color: navy">)</span><span style="color: navy"><b> -> </b></span> bundle.entry<b> as </b><span style="color: maroon">entry</span><span style="color: navy">, </span> entry.resource = <b>create</b><span style="color: navy">(</span><span style="color: blue">'RiskAssessment'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">ra</span><b> then</b><span style="color: navy"> {
</span> qr<span style="color: navy"><b> -> </b></span> ra<span style="color: navy">, </span> entry<b> then </b>BuildRiskBase<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">obs</span><span style="color: navy">, </span><span style="color: maroon">ra</span><span style="color: navy">, </span><span style="color: maroon">entry</span><span style="color: navy">)</span> <i>"riskBase"</i><span style="color: navy">;</span>
qr<span style="color: navy"><b> -> </b></span>ra<b> then </b>SetMorseRiskCode<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">ra</span><span style="color: navy">)</span> <i>"riskCode"</i><span style="color: navy">;</span>
qr<span style="color: navy"><b> -> </b></span>ra.prediction<b> as </b><span style="color: maroon">pred</span><b> then</b><span style="color: navy"> {
</span> qr<span style="color: navy"><b> -> </b></span>pred.qualitativeRisk<b> as </b><span style="color: maroon">risk</span><b> then</b><span style="color: navy"> {
</span> qr<span style="color: navy"><b> -> </b></span>risk.coding<b> as </b><span style="color: maroon">coding</span><b> then</b><span style="color: navy"> {
</span> qr<span style="color: navy"><b> -> </b></span>coding.system = <span style="color: blue">'http://terminology.hl7.org/CodeSystem/risk-probability'</span> <i>"riskSystem"</i><span style="color: navy">;</span>
qr<span style="color: navy"><b> -> </b></span>coding.code = <span style="color: blue">'high'</span> <i>"riskCode"</i><span style="color: navy">;</span>
qr<span style="color: navy"><b> -> </b></span>coding.display = <span style="color: blue">'High likelihood'</span> <i>"riskDisplay"</i><span style="color: navy">;</span>
<span style="color: navy">}</span> <i>"hl7Coding"</i><span style="color: navy">;</span>
qr<span style="color: navy"><b> -> </b></span>risk.coding<b> as </b><span style="color: maroon">loinc</span><b> then</b><span style="color: navy"> {
</span> qr<span style="color: navy"><b> -> </b></span>loinc.system = <span style="color: blue">'http://loinc.org'</span> <i>"loincSystem"</i><span style="color: navy">;</span>
qr<span style="color: navy"><b> -> </b></span>loinc.code = <span style="color: blue">'LA13040-3'</span> <i>"loincCode"</i><span style="color: navy">;</span>
qr<span style="color: navy"><b> -> </b></span>loinc.display = <span style="color: blue">'High Risk (MFS Score 50+)'</span> <i>"loincDisplay"</i><span style="color: navy">;</span>
<span style="color: navy">}</span> <i>"loincCoding"</i><span style="color: navy">;</span>
qr<span style="color: navy"><b> -> </b></span>risk.text = <span style="color: blue">'High risk'</span> <i>"riskText"</i><span style="color: navy">;</span>
<span style="color: navy">}</span> <i>"qualitativeRisk"</i><span style="color: navy">;</span>
<span style="color: navy">}</span> <i>"prediction"</i><span style="color: navy">;</span>
<span style="color: navy">}</span> <i>"morseHigh"</i><span style="color: navy">;</span>
<span style="color: navy">}
</span><b>group </b>SetMorseRiskCode<span style="color: navy">(</span><b>source</b> <span style="color: maroon">qr</span><span style="color: navy"> : </span>QR, <b>target</b> <span style="color: maroon">ra</span><span style="color: navy"> : </span>RiskAssessment<span style="color: navy">)</span><span style="color: navy"> {
</span> qr<span style="color: navy"><b> -> </b></span>ra.code<b> as </b><span style="color: maroon">code</span><b> then</b><span style="color: navy"> {
</span> qr<span style="color: navy"><b> -> </b></span>code.coding<b> as </b><span style="color: maroon">coding</span><b> then</b><span style="color: navy"> {
</span> qr<span style="color: navy"><b> -> </b></span>coding.system = <span style="color: blue">'http://loinc.org'</span> <i>"codeSystem"</i><span style="color: navy">;</span>
qr<span style="color: navy"><b> -> </b></span>coding.code = <span style="color: blue">'59461-4'</span> <i>"codeCode"</i><span style="color: navy">;</span>
qr<span style="color: navy"><b> -> </b></span>coding.display = <span style="color: blue">'Fall risk level [Morse Fall Scale]'</span> <i>"codeDisplay"</i><span style="color: navy">;</span>
<span style="color: navy">}</span> <i>"codeCoding"</i><span style="color: navy">;</span>
<span style="color: navy">}</span> <i>"code"</i><span style="color: navy">;</span>
<span style="color: navy">}
</span><span style="color: navy">// </span><span style="color: green">─────────────────────────────────────────────────────────────────────────────</span>
<span style="color: navy">// </span><span style="color: green">Shared scaffolding. Repeated in each map rather than imported: the transform</span>
<span style="color: navy">// </span><span style="color: green">engine resolves `imports` against whatever StructureMaps happen to be on the</span>
<span style="color: navy">// </span><span style="color: green">server, and a form that stops extracting because a shared map was not</span>
<span style="color: navy">// </span><span style="color: green">uploaded is a worse failure than a duplicated group.</span>
<span style="color: navy">// </span><span style="color: green">─────────────────────────────────────────────────────────────────────────────</span>
<span style="color: navy">// </span><span style="color: green">Two notes on what the publisher's StructureMap validator says about this file.</span>
<span style="color: navy">// </span><span style="color: green">Source parameters below are left untyped on purpose. Writing `: Element` makes</span>
<span style="color: navy">// </span><span style="color: green">the validator compare QuestionnaireResponse.item against the literal 'Element'</span>
<span style="color: navy">// </span><span style="color: green">and report them as incompatible with each other, which is noise, not a finding.</span>
<span style="color: navy">// </span><span style="color: green">Untyped, it says only that it cannot check the paths.</span>
<span style="color: navy">// </span><span style="color: green">`evaluate(context, expression)` is flagged as "takes 1 parameter but 2 were</span>
<span style="color: navy">// </span><span style="color: green">found". Leave it. The FML parser in the same jar refuses the one-argument form</span>
<span style="color: navy">// </span><span style="color: green">outright -- it wants a parameter, a comma, then the FHIRPath -- so the publisher</span>
<span style="color: navy">// </span><span style="color: green">is objecting to what its own compiler emits. Two arguments is the only form that</span>
<span style="color: navy">// </span><span style="color: green">compiles, and it is what the R5 transform engine executes.</span>
<b>group </b>BuildObsBase<span style="color: navy">(</span><b>source</b> <span style="color: maroon">qr</span><span style="color: navy"> : </span>QR, <b>target</b> <span style="color: maroon">obs</span><span style="color: navy"> : </span>Observation, <b>target</b> <span style="color: maroon">entry</span><span style="color: navy">)</span><span style="color: navy"> {
</span> qr<span style="color: navy"><b> -> </b></span>obs.id = <b>uuid</b><span style="color: navy">(</span><span style="color: navy">)</span><b> then </b>SetObservationFullUrl<span style="color: navy">(</span><span style="color: maroon">obs</span><span style="color: navy">, </span><span style="color: maroon">entry</span><span style="color: navy">)</span> <i>"idAndFullUrl"</i><span style="color: navy">;</span>
qr<span style="color: navy"><b> -> </b></span>entry.request<b> as </b><span style="color: maroon">request</span><b> then</b><span style="color: navy"> {
</span> qr<span style="color: navy"><b> -> </b></span>request.method = <span style="color: blue">'POST'</span> <i>"requestMethod"</i><span style="color: navy">;</span>
qr<span style="color: navy"><b> -> </b></span>request.url = <span style="color: blue">'Observation'</span> <i>"requestUrl"</i><span style="color: navy">;</span>
<span style="color: navy">}</span> <i>"entryRequest"</i><span style="color: navy">;</span>
qr<span style="color: navy"><b> -> </b></span>obs.status = <span style="color: blue">'final'</span> <i>"status"</i><span style="color: navy">;</span>
qr.subject<b> as </b><span style="color: maroon">s</span><span style="color: navy"><b> -> </b></span>obs.subject = <span style="color: maroon">s</span><span style="color: navy">;</span>
qr.encounter<b> as </b><span style="color: maroon">e</span><span style="color: navy"><b> -> </b></span>obs.encounter = <span style="color: maroon">e</span><span style="color: navy">;</span>
qr.authored<b> as </b><span style="color: maroon">t</span><span style="color: navy"><b> -> </b></span>obs.effective = <span style="color: maroon">t</span> <i>"effective"</i><span style="color: navy">;</span>
qr.source<b> as </b><span style="color: maroon">src</span><span style="color: navy"><b> -> </b></span>obs.performer = <span style="color: maroon">src</span> <i>"performerFromSource"</i><span style="color: navy">;</span>
qr<b> where </b><span style="color: navy">(</span>source.exists().not()<span style="color: navy">)</span><b> then</b><span style="color: navy"> {
</span> qr.author<b> as </b><span style="color: maroon">a</span><span style="color: navy"><b> -> </b></span>obs.performer = <span style="color: maroon">a</span> <i>"performerFromAuthor"</i><span style="color: navy">;</span>
<span style="color: navy">}</span> <i>"performerFallback"</i><span style="color: navy">;</span>
<span style="color: navy">// </span><span style="color: green">A stored response's id already reads "QuestionnaireResponse/<id>", so it is a</span>
<span style="color: navy">// </span><span style="color: green">relative reference as it stands. The hasValue() guard is what stops an</span>
<span style="color: navy">// </span><span style="color: green">unsaved response -- one posted straight to $extract rather than saved first --</span>
<span style="color: navy">// </span><span style="color: green">from writing "QuestionnaireResponse/null" into the record.</span>
qr.id<b> as </b><span style="color: maroon">qid</span><b> where </b><span style="color: navy">(</span>$this.hasValue()<span style="color: navy">)</span><span style="color: navy"><b> -> </b></span> obs.derivedFrom = <b>create</b><span style="color: navy">(</span><span style="color: blue">'Reference'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">ref</span><span style="color: navy">, </span> ref.reference = <span style="color: maroon">qid</span> <i>"linkQuestionnaireResponse"</i><span style="color: navy">;</span>
<span style="color: navy">}
</span><span style="color: navy">// </span><span style="color: green">The RiskAssessment stands on two things: the response that was filled in and</span>
<span style="color: navy">// </span><span style="color: green">the Observation that holds the number. Both go in basis, which is what the</span>
<span style="color: navy">// </span><span style="color: green">SGHI RiskAssessment profile binds to a QuestionnaireResponse.</span>
<b>group </b>BuildRiskBase<span style="color: navy">(</span><b>source</b> <span style="color: maroon">qr</span><span style="color: navy"> : </span>QR, <b>source</b> <span style="color: maroon">obs</span><span style="color: navy"> : </span>Observation, <b>target</b> <span style="color: maroon">ra</span><span style="color: navy"> : </span>RiskAssessment, <b>target</b> <span style="color: maroon">entry</span><span style="color: navy">)</span><span style="color: navy"> {
</span> qr<span style="color: navy"><b> -> </b></span>ra.id = <b>uuid</b><span style="color: navy">(</span><span style="color: navy">)</span><b> then </b>SetRiskAssessmentFullUrl<span style="color: navy">(</span><span style="color: maroon">ra</span><span style="color: navy">, </span><span style="color: maroon">entry</span><span style="color: navy">)</span> <i>"idAndFullUrl"</i><span style="color: navy">;</span>
qr<span style="color: navy"><b> -> </b></span>entry.request<b> as </b><span style="color: maroon">request</span><b> then</b><span style="color: navy"> {
</span> qr<span style="color: navy"><b> -> </b></span>request.method = <span style="color: blue">'POST'</span> <i>"requestMethod"</i><span style="color: navy">;</span>
qr<span style="color: navy"><b> -> </b></span>request.url = <span style="color: blue">'RiskAssessment'</span> <i>"requestUrl"</i><span style="color: navy">;</span>
<span style="color: navy">}</span> <i>"entryRequest"</i><span style="color: navy">;</span>
qr<span style="color: navy"><b> -> </b></span>ra.status = <span style="color: blue">'final'</span> <i>"status"</i><span style="color: navy">;</span>
qr.subject<b> as </b><span style="color: maroon">s</span><span style="color: navy"><b> -> </b></span>ra.subject = <span style="color: maroon">s</span><span style="color: navy">;</span>
qr.encounter<b> as </b><span style="color: maroon">e</span><span style="color: navy"><b> -> </b></span>ra.encounter = <span style="color: maroon">e</span><span style="color: navy">;</span>
qr.authored<b> as </b><span style="color: maroon">t</span><span style="color: navy"><b> -> </b></span>ra.occurrence = <span style="color: maroon">t</span> <i>"occurrence"</i><span style="color: navy">;</span>
qr.author<b> as </b><span style="color: maroon">a</span><span style="color: navy"><b> -> </b></span>ra.performer = <span style="color: maroon">a</span> <i>"performerFromAuthor"</i><span style="color: navy">;</span>
qr<b> where </b><span style="color: navy">(</span>author.exists().not()<span style="color: navy">)</span><b> then</b><span style="color: navy"> {
</span> qr.source<b> as </b><span style="color: maroon">src</span><span style="color: navy"><b> -> </b></span>ra.performer = <span style="color: maroon">src</span> <i>"performerFromSource"</i><span style="color: navy">;</span>
<span style="color: navy">}</span> <i>"performerFallback"</i><span style="color: navy">;</span>
qr.id<b> as </b><span style="color: maroon">qid</span><b> where </b><span style="color: navy">(</span>$this.hasValue()<span style="color: navy">)</span><span style="color: navy"><b> -> </b></span> ra.basis = <b>create</b><span style="color: navy">(</span><span style="color: blue">'Reference'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">qref</span><span style="color: navy">, </span> qref.reference = <span style="color: maroon">qid</span> <i>"basisResponse"</i><span style="color: navy">;</span>
obs.id<b> as </b><span style="color: maroon">oid</span><span style="color: navy"><b> -> </b></span>ra.basis = <b>create</b><span style="color: navy">(</span><span style="color: blue">'Reference'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">oref</span><b> then</b><span style="color: navy"> {
</span> oid<span style="color: navy"><b> -> </b></span>oref.reference = <b>append</b><span style="color: navy">(</span><span style="color: blue">'Observation/'</span><span style="color: navy">, </span><span style="color: maroon">oid</span><span style="color: navy">)</span> <i>"basisObservationRef"</i><span style="color: navy">;</span>
<span style="color: navy">}</span> <i>"basisObservation"</i><span style="color: navy">;</span>
<span style="color: navy">}
</span><b>group </b>SetComponentCodedValue<span style="color: navy">(</span><b>source</b> <span style="color: maroon">it</span>, <b>target</b> <span style="color: maroon">comp</span><span style="color: navy">)</span><span style="color: navy"> {
</span> it.answer first<b> as </b><span style="color: maroon">a</span><b> then</b><span style="color: navy"> {
</span> a.value<b> as </b><span style="color: maroon">cv</span><span style="color: navy"><b> -> </b></span>comp.value = <b>create</b><span style="color: navy">(</span><span style="color: blue">'CodeableConcept'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">cc</span><b> then</b><span style="color: navy"> {
</span> cv<span style="color: navy"><b> -> </b></span>cc.coding = <span style="color: maroon">cv</span> <i>"valueCoding"</i><span style="color: navy">;</span>
cv.display<b> as </b><span style="color: maroon">d</span><span style="color: navy"><b> -> </b></span>cc.text = <span style="color: maroon">d</span> <i>"valueText"</i><span style="color: navy">;</span>
<span style="color: navy">}</span> <i>"codedValue"</i><span style="color: navy">;</span>
<span style="color: navy">}</span> <i>"componentAnswer"</i><span style="color: navy">;</span>
<span style="color: navy">}
</span><b>group </b>SetSurveyCategory<span style="color: navy">(</span><b>source</b> <span style="color: maroon">qr</span><span style="color: navy"> : </span>QR, <b>target</b> <span style="color: maroon">obs</span><span style="color: navy"> : </span>Observation<span style="color: navy">)</span><span style="color: navy"> {
</span> qr<span style="color: navy"><b> -> </b></span>obs.category<b> as </b><span style="color: maroon">cat</span><b> then</b><span style="color: navy"> {
</span> qr<span style="color: navy"><b> -> </b></span>cat.coding<b> as </b><span style="color: maroon">coding</span><b> then</b><span style="color: navy"> {
</span> qr<span style="color: navy"><b> -> </b></span>coding.system = <span style="color: blue">'http://terminology.hl7.org/CodeSystem/observation-category'</span> <i>"categorySystem"</i><span style="color: navy">;</span>
qr<span style="color: navy"><b> -> </b></span>coding.code = <span style="color: blue">'survey'</span> <i>"categoryCode"</i><span style="color: navy">;</span>
qr<span style="color: navy"><b> -> </b></span>coding.display = <span style="color: blue">'Survey'</span> <i>"categoryDisplay"</i><span style="color: navy">;</span>
<span style="color: navy">}</span> <i>"categoryCoding"</i><span style="color: navy">;</span>
<span style="color: navy">}</span> <i>"category"</i><span style="color: navy">;</span>
<span style="color: navy">}
</span><b>group </b>SetObservationFullUrl<span style="color: navy">(</span><b>source</b> <span style="color: maroon">obs</span><span style="color: navy"> : </span>Observation, <b>target</b> <span style="color: maroon">entry</span><span style="color: navy">)</span><span style="color: navy"> {
</span> obs.id<b> as </b><span style="color: maroon">id</span><span style="color: navy"><b> -> </b></span>entry.fullUrl = <b>append</b><span style="color: navy">(</span><span style="color: blue">'https://fhir.slade360.co.ke/fhir/Observation/'</span><span style="color: navy">, </span><span style="color: maroon">id</span><span style="color: navy">)</span> <i>"assignFullUrl"</i><span style="color: navy">;</span>
<span style="color: navy">}
</span><b>group </b>SetRiskAssessmentFullUrl<span style="color: navy">(</span><b>source</b> <span style="color: maroon">ra</span><span style="color: navy"> : </span>RiskAssessment, <b>target</b> <span style="color: maroon">entry</span><span style="color: navy">)</span><span style="color: navy"> {
</span> ra.id<b> as </b><span style="color: maroon">id</span><span style="color: navy"><b> -> </b></span>entry.fullUrl = <b>append</b><span style="color: navy">(</span><span style="color: blue">'https://fhir.slade360.co.ke/fhir/RiskAssessment/'</span><span style="color: navy">, </span><span style="color: maroon">id</span><span style="color: navy">)</span> <i>"assignFullUrl"</i><span style="color: navy">;</span>
<span style="color: navy">}
</span></pre></div>
</text>
<url
value="https://fhir.slade360.co.ke/fhir/StructureMap/ExtractMorseFallScale"/>
<version value="0.1.0"/>
<name value="ExtractMorseFallScale"/>
<title value="Morse Fall Scale Extraction"/>
<status value="active"/>
<date value="2026-09-14T06:31:13+00:00"/>
<publisher value="Kathurima Kimathi"/>
<contact>
<name value="Kathurima Kimathi"/>
<telecom>
<system value="url"/>
<value value="https://www.linkedin.com/in/kathurima-kimathi/"/>
</telecom>
<telecom>
<system value="email"/>
<value value="kathurimakimathi415@gmail.com"/>
</telecom>
</contact>
<contact>
<name value="Oscar John"/>
<telecom>
<system value="email"/>
<value value="oscarjohnotieno@gmail.com"/>
<use value="work"/>
</telecom>
</contact>
<contact>
<name value="Kennedy Omondi"/>
<telecom>
<system value="email"/>
<value value="kennankole@gmail.com"/>
<use value="work"/>
</telecom>
</contact>
<description
value="The LOINC Morse Fall Scale panel out as one Observation carrying the total, with the six weighted questions as components, plus a RiskAssessment for the band the total falls in. The total prefers what the form submitted and otherwise sums the answers itself, and it only extracts when all six questions have been answered: a Morse score short of an item is not a Morse score, and banding one puts a number a nurse can act on next to a risk tier that is wrong."/>
<structure>
<url
value="http://hl7.org/fhir/StructureDefinition/QuestionnaireResponse"/>
<mode value="source"/>
<alias value="QR"/>
</structure>
<structure>
<url value="http://hl7.org/fhir/StructureDefinition/Bundle"/>
<mode value="target"/>
<alias value="Bundle"/>
</structure>
<structure>
<url value="http://hl7.org/fhir/StructureDefinition/Observation"/>
<mode value="target"/>
<alias value="Observation"/>
</structure>
<structure>
<url value="http://hl7.org/fhir/StructureDefinition/RiskAssessment"/>
<mode value="target"/>
<alias value="RiskAssessment"/>
</structure>
<group>
<name value="ExtractMorseFallScale"/>
<input>
<name value="qr"/>
<type value="QR"/>
<mode value="source"/>
</input>
<input>
<name value="bundle"/>
<type value="Bundle"/>
<mode value="target"/>
</input>
<rule>
<name value="setBundleType"/>
<source>
<context value="qr"/>
</source>
<target>
<context value="bundle"/>
<element value="type"/>
<transform value="copy"/>
<parameter>
<valueString value="transaction"/>
</parameter>
</target>
</rule>
<rule>
<name value="morseRule"/>
<source>
<context value="qr"/>
<condition
value="item.where(linkId in ('59454-9' | '59455-6' | '59456-4' | '59457-2' | '59458-0' | '59459-8')).answer.value.ofType(Coding).exists()"/>
</source>
<target>
<context value="bundle"/>
<element value="entry"/>
<variable value="entry"/>
</target>
<target>
<context value="entry"/>
<element value="resource"/>
<variable value="obs"/>
<transform value="create"/>
<parameter>
<valueString value="Observation"/>
</parameter>
</target>
<rule>
<name value="base"/>
<source>
<context value="qr"/>
</source>
<target>
<context value="obs"/>
</target>
<target>
<context value="entry"/>
</target>
<dependent>
<name value="BuildObsBase"/>
<parameter>
<valueId value="qr"/>
</parameter>
<parameter>
<valueId value="obs"/>
</parameter>
<parameter>
<valueId value="entry"/>
</parameter>
</dependent>
</rule>
<rule>
<name value="category"/>
<source>
<context value="qr"/>
</source>
<target>
<context value="obs"/>
</target>
<dependent>
<name value="SetSurveyCategory"/>
<parameter>
<valueId value="qr"/>
</parameter>
<parameter>
<valueId value="obs"/>
</parameter>
</dependent>
</rule>
<rule>
<name value="code"/>
<source>
<context value="qr"/>
</source>
<target>
<context value="obs"/>
<element value="code"/>
<variable value="code"/>
</target>
<rule>
<name value="codeCoding"/>
<source>
<context value="qr"/>
</source>
<target>
<context value="code"/>
<element value="coding"/>
<variable value="coding"/>
</target>
<rule>
<name value="codeSystem"/>
<source>
<context value="qr"/>
</source>
<target>
<context value="coding"/>
<element value="system"/>
<transform value="copy"/>
<parameter>
<valueString value="http://loinc.org"/>
</parameter>
</target>
</rule>
<rule>
<name value="codeCode"/>
<source>
<context value="qr"/>
</source>
<target>
<context value="coding"/>
<element value="code"/>
<transform value="copy"/>
<parameter>
<valueString value="59460-6"/>
</parameter>
</target>
</rule>
<rule>
<name value="codeDisplay"/>
<source>
<context value="qr"/>
</source>
<target>
<context value="coding"/>
<element value="display"/>
<transform value="copy"/>
<parameter>
<valueString value="Fall risk total [Morse Fall Scale]"/>
</parameter>
</target>
</rule>
</rule>
</rule>
<rule>
<name value="totalRule"/>
<source>
<context value="qr"/>
<condition
value="item.where(linkId in ('59454-9' | '59455-6' | '59456-4' | '59457-2' | '59458-0' | '59459-8')).answer.value.ofType(Coding).count() = 6"/>
</source>
<rule>
<name value="totalValue"/>
<source>
<context value="qr"/>
</source>
<target>
<context value="obs"/>
<element value="value"/>
<transform value="evaluate"/>
<parameter>
<valueId value="qr"/>
</parameter>
<parameter>
<valueString
value="iif(item.where(linkId = '59460-6').answer.value.exists(), item.where(linkId = '59460-6').answer.value.truncate(), iif(item.where(linkId = '59454-9').answer.value.ofType(Coding).code = 'LA33-6', 25, 0) + iif(item.where(linkId = '59455-6').answer.value.ofType(Coding).code = 'LA33-6', 15, 0) + iif(item.where(linkId = '59456-4').answer.value.ofType(Coding).code = 'LA13031-2', 15, iif(item.where(linkId = '59456-4').answer.value.ofType(Coding).code = 'LA13032-0', 30, 0)) + iif(item.where(linkId = '59457-2').answer.value.ofType(Coding).code = 'LA33-6', 20, 0) + iif(item.where(linkId = '59458-0').answer.value.ofType(Coding).code = 'LA13034-6', 10, iif(item.where(linkId = '59458-0').answer.value.ofType(Coding).code = 'LA13035-3', 20, 0)) + iif(item.where(linkId = '59459-8').answer.value.ofType(Coding).code = 'LA13037-9', 15, 0))"/>
</parameter>
</target>
</rule>
<documentation
value="The submitted total wins; otherwise sum the answers.
The weights have to be resolved question by question rather than from one
lookup, because Morse reuses LOINC's plain yes/no pair across three
questions at three different weights: LA33-6 "Yes" is worth 25 on the
history of falling, 15 on a secondary diagnosis and 20 on an intravenous
line. A global code-to-weight table would silently score all three the
same. The weights are Morse's own, as printed on the form.
truncate(), not toInteger(): the form types the total `decimal`, and this
engine's toInteger() returns empty for anything with a fractional part.
Observation.value has no decimal choice, so it has to land as an integer.
Guarded on all six questions being answered."/>
</rule>
<rule>
<name value="historyRule"/>
<source>
<context value="qr"/>
<element value="item"/>
<variable value="it"/>
<condition value="(linkId = '59454-9') and answer.value.exists()"/>
</source>
<target>
<context value="obs"/>
<element value="component"/>
<variable value="comp"/>
</target>
<rule>
<name value="historyCode"/>
<source>
<context value="it"/>
</source>
<target>
<context value="comp"/>
<element value="code"/>
<variable value="code"/>
</target>
<rule>
<name value="codeCoding"/>
<source>
<context value="it"/>
</source>
<target>
<context value="code"/>
<element value="coding"/>
<variable value="coding"/>
</target>
<rule>
<name value="codeSystem"/>
<source>
<context value="it"/>
</source>
<target>
<context value="coding"/>
<element value="system"/>
<transform value="copy"/>
<parameter>
<valueString value="http://loinc.org"/>
</parameter>
</target>
</rule>
<rule>
<name value="codeCode"/>
<source>
<context value="it"/>
</source>
<target>
<context value="coding"/>
<element value="code"/>
<transform value="copy"/>
<parameter>
<valueString value="59454-9"/>
</parameter>
</target>
</rule>
<rule>
<name value="codeDisplay"/>
<source>
<context value="it"/>
</source>
<target>
<context value="coding"/>
<element value="display"/>
<transform value="copy"/>
<parameter>
<valueString
value="History of falling; immediate or within 3 months [Morse Fall Scale]"/>
</parameter>
</target>
</rule>
</rule>
</rule>
<rule>
<name value="historyValue"/>
<source>
<context value="it"/>
</source>
<target>
<context value="comp"/>
</target>
<dependent>
<name value="SetComponentCodedValue"/>
<parameter>
<valueId value="it"/>
</parameter>
<parameter>
<valueId value="comp"/>
</parameter>
</dependent>
</rule>
</rule>
<rule>
<name value="diagnosisRule"/>
<source>
<context value="qr"/>
<element value="item"/>
<variable value="it"/>
<condition value="(linkId = '59455-6') and answer.value.exists()"/>
</source>
<target>
<context value="obs"/>
<element value="component"/>
<variable value="comp"/>
</target>
<rule>
<name value="diagnosisCode"/>
<source>
<context value="it"/>
</source>
<target>
<context value="comp"/>
<element value="code"/>
<variable value="code"/>
</target>
<rule>
<name value="codeCoding"/>
<source>
<context value="it"/>
</source>
<target>
<context value="code"/>
<element value="coding"/>
<variable value="coding"/>
</target>
<rule>
<name value="codeSystem"/>
<source>
<context value="it"/>
</source>
<target>
<context value="coding"/>
<element value="system"/>
<transform value="copy"/>
<parameter>
<valueString value="http://loinc.org"/>
</parameter>
</target>
</rule>
<rule>
<name value="codeCode"/>
<source>
<context value="it"/>
</source>
<target>
<context value="coding"/>
<element value="code"/>
<transform value="copy"/>
<parameter>
<valueString value="59455-6"/>
</parameter>
</target>
</rule>
<rule>
<name value="codeDisplay"/>
<source>
<context value="it"/>
</source>
<target>
<context value="coding"/>
<element value="display"/>
<transform value="copy"/>
<parameter>
<valueString value="Secondary diagnosis is present"/>
</parameter>
</target>
</rule>
</rule>
</rule>
<rule>
<name value="diagnosisValue"/>
<source>
<context value="it"/>
</source>
<target>
<context value="comp"/>
</target>
<dependent>
<name value="SetComponentCodedValue"/>
<parameter>
<valueId value="it"/>
</parameter>
<parameter>
<valueId value="comp"/>
</parameter>
</dependent>
</rule>
</rule>
<rule>
<name value="aidRule"/>
<source>
<context value="qr"/>
<element value="item"/>
<variable value="it"/>
<condition value="(linkId = '59456-4') and answer.value.exists()"/>
</source>
<target>
<context value="obs"/>
<element value="component"/>
<variable value="comp"/>
</target>
<rule>
<name value="aidCode"/>
<source>
<context value="it"/>
</source>
<target>
<context value="comp"/>
<element value="code"/>
<variable value="code"/>
</target>
<rule>
<name value="codeCoding"/>
<source>
<context value="it"/>
</source>
<target>
<context value="code"/>
<element value="coding"/>
<variable value="coding"/>
</target>
<rule>
<name value="codeSystem"/>
<source>
<context value="it"/>
</source>
<target>
<context value="coding"/>
<element value="system"/>
<transform value="copy"/>
<parameter>
<valueString value="http://loinc.org"/>
</parameter>
</target>
</rule>
<rule>
<name value="codeCode"/>
<source>
<context value="it"/>
</source>
<target>
<context value="coding"/>
<element value="code"/>
<transform value="copy"/>
<parameter>
<valueString value="59456-4"/>
</parameter>
</target>
</rule>
<rule>
<name value="codeDisplay"/>
<source>
<context value="it"/>
</source>
<target>
<context value="coding"/>
<element value="display"/>
<transform value="copy"/>
<parameter>
<valueString value="Ambulatory aid [Morse Fall Scale]"/>
</parameter>
</target>
</rule>
</rule>
</rule>
<rule>
<name value="aidValue"/>
<source>
<context value="it"/>
</source>
<target>
<context value="comp"/>
</target>
<dependent>
<name value="SetComponentCodedValue"/>
<parameter>
<valueId value="it"/>
</parameter>
<parameter>
<valueId value="comp"/>
</parameter>
</dependent>
</rule>
</rule>
<rule>
<name value="ivRule"/>
<source>
<context value="qr"/>
<element value="item"/>
<variable value="it"/>
<condition value="(linkId = '59457-2') and answer.value.exists()"/>
</source>
<target>
<context value="obs"/>
<element value="component"/>
<variable value="comp"/>
</target>
<rule>
<name value="ivCode"/>
<source>
<context value="it"/>
</source>
<target>
<context value="comp"/>
<element value="code"/>
<variable value="code"/>
</target>
<rule>
<name value="codeCoding"/>
<source>
<context value="it"/>
</source>
<target>
<context value="code"/>
<element value="coding"/>
<variable value="coding"/>
</target>
<rule>
<name value="codeSystem"/>
<source>
<context value="it"/>
</source>
<target>
<context value="coding"/>
<element value="system"/>
<transform value="copy"/>
<parameter>
<valueString value="http://loinc.org"/>
</parameter>
</target>
</rule>
<rule>
<name value="codeCode"/>
<source>
<context value="it"/>
</source>
<target>
<context value="coding"/>
<element value="code"/>
<transform value="copy"/>
<parameter>
<valueString value="59457-2"/>
</parameter>
</target>
</rule>
<rule>
<name value="codeDisplay"/>
<source>
<context value="it"/>
</source>
<target>
<context value="coding"/>
<element value="display"/>
<transform value="copy"/>
<parameter>
<valueString
value="Intravenous apparatus [Morse Fall Scale]"/>
</parameter>
</target>
</rule>
</rule>
</rule>
<rule>
<name value="ivValue"/>
<source>
<context value="it"/>
</source>
<target>
<context value="comp"/>
</target>
<dependent>
<name value="SetComponentCodedValue"/>
<parameter>
<valueId value="it"/>
</parameter>
<parameter>
<valueId value="comp"/>
</parameter>
</dependent>
</rule>
</rule>
<rule>
<name value="gaitRule"/>
<source>
<context value="qr"/>
<element value="item"/>
<variable value="it"/>
<condition value="(linkId = '59458-0') and answer.value.exists()"/>
</source>
<target>
<context value="obs"/>
<element value="component"/>
<variable value="comp"/>
</target>
<rule>
<name value="gaitCode"/>
<source>
<context value="it"/>
</source>
<target>
<context value="comp"/>
<element value="code"/>
<variable value="code"/>
</target>
<rule>
<name value="codeCoding"/>
<source>
<context value="it"/>
</source>
<target>
<context value="code"/>
<element value="coding"/>
<variable value="coding"/>
</target>
<rule>
<name value="codeSystem"/>
<source>
<context value="it"/>
</source>
<target>
<context value="coding"/>
<element value="system"/>
<transform value="copy"/>
<parameter>
<valueString value="http://loinc.org"/>
</parameter>
</target>
</rule>
<rule>
<name value="codeCode"/>
<source>
<context value="it"/>
</source>
<target>
<context value="coding"/>
<element value="code"/>
<transform value="copy"/>
<parameter>
<valueString value="59458-0"/>
</parameter>
</target>
</rule>
<rule>
<name value="codeDisplay"/>
<source>
<context value="it"/>
</source>
<target>
<context value="coding"/>
<element value="display"/>
<transform value="copy"/>
<parameter>
<valueString value="Gait [Morse Fall Scale]"/>
</parameter>
</target>
</rule>
</rule>
</rule>
<rule>
<name value="gaitValue"/>
<source>
<context value="it"/>
</source>
<target>
<context value="comp"/>
</target>
<dependent>
<name value="SetComponentCodedValue"/>
<parameter>
<valueId value="it"/>
</parameter>
<parameter>
<valueId value="comp"/>
</parameter>
</dependent>
</rule>
</rule>
<rule>
<name value="mentalRule"/>
<source>
<context value="qr"/>
<element value="item"/>
<variable value="it"/>
<condition value="(linkId = '59459-8') and answer.value.exists()"/>
</source>
<target>
<context value="obs"/>
<element value="component"/>
<variable value="comp"/>
</target>
<rule>
<name value="mentalCode"/>
<source>
<context value="it"/>
</source>
<target>
<context value="comp"/>
<element value="code"/>
<variable value="code"/>
</target>
<rule>
<name value="codeCoding"/>
<source>
<context value="it"/>
</source>
<target>
<context value="code"/>
<element value="coding"/>
<variable value="coding"/>
</target>
<rule>
<name value="codeSystem"/>
<source>
<context value="it"/>
</source>
<target>
<context value="coding"/>
<element value="system"/>
<transform value="copy"/>
<parameter>
<valueString value="http://loinc.org"/>
</parameter>
</target>
</rule>
<rule>
<name value="codeCode"/>
<source>
<context value="it"/>
</source>
<target>
<context value="coding"/>
<element value="code"/>
<transform value="copy"/>
<parameter>
<valueString value="59459-8"/>
</parameter>
</target>
</rule>
<rule>
<name value="codeDisplay"/>
<source>
<context value="it"/>
</source>
<target>
<context value="coding"/>
<element value="display"/>
<transform value="copy"/>
<parameter>
<valueString value="Mental status [Morse Fall Scale]"/>
</parameter>
</target>
</rule>
</rule>
</rule>
<rule>
<name value="mentalValue"/>
<source>
<context value="it"/>
</source>
<target>
<context value="comp"/>
</target>
<dependent>
<name value="SetComponentCodedValue"/>
<parameter>
<valueId value="it"/>
</parameter>
<parameter>
<valueId value="comp"/>
</parameter>
</dependent>
</rule>
</rule>
<rule>
<name value="band"/>
<source>
<context value="qr"/>
</source>
<target>
<context value="obs"/>
</target>
<target>
<context value="bundle"/>
</target>
<dependent>
<name value="AddMorseRiskAssessment"/>
<parameter>
<valueId value="obs"/>
</parameter>
<parameter>
<valueId value="qr"/>
</parameter>
<parameter>
<valueId value="bundle"/>
</parameter>
</dependent>
</rule>
<documentation
value="LOINC publishes this panel flat -- the six questions, the total and the risk
level are all top-level items keyed by their own LOINC code -- so there is no
group to hang the Observation off and the response itself is the anchor."/>
</rule>
</group>
<group>
<name value="AddMorseRiskAssessment"/>
<documentation
value="─────────────────────────────────────────────────────────────────────────────
The band
These are the tiers LOINC's own answer list for 59461-4 carries, which is the
three-tier reading of Morse in general use and the list printed on this form:
0-24 low, 25-45 moderate, 50 and over high. Higher is worse.
Two things to know about it.
The published list leaves 46 to 49 unnamed. A computed total never lands
there -- every one of Morse's item weights is a multiple of five, so the sum
is too -- but a total the form submits can, since that item is a free decimal.
It is folded into moderate, because the alternative is a score that extracts a
number and no band at all.
It is not the banding `ExtractInpatientFallsAndPressureUlcerRiskAssessment`
uses. That map scores the same six items from a hand-built form and bands them
on Morse's original paper -- 0-24 no risk, 25-50 low, 51 and over high -- so
the two maps can disagree between 25 and 50. The divergence is deliberate: a
band that contradicts the pick list on the form in front of the nurse is worse
than a band that differs from another form's. Reconciling them means agreeing
one Morse banding for the IG and changing whichever form loses.
qualitativeRisk carries two codings and a text. HL7's risk-probability is what
a consumer escalates on; LOINC's answer code is the tier exactly as the form
states it, ranges and all; the text is the plain wording.
The band is derived from the total rather than copied from the form's own
risk-level item. That item is a free pick list with nothing calculating it, so
deriving is the only way the number and the tier are guaranteed to agree.
─────────────────────────────────────────────────────────────────────────────"/>
<input>
<name value="obs"/>
<type value="Observation"/>
<mode value="source"/>
</input>
<input>
<name value="qr"/>
<type value="QR"/>
<mode value="source"/>
</input>
<input>
<name value="bundle"/>
<type value="Bundle"/>
<mode value="target"/>
</input>
<rule>
<name value="morseLow"/>
<source>
<context value="obs"/>
<condition value="value.ofType(integer) <= 24"/>
</source>
<target>
<context value="bundle"/>
<element value="entry"/>
<variable value="entry"/>
</target>
<target>
<context value="entry"/>
<element value="resource"/>
<variable value="ra"/>
<transform value="create"/>
<parameter>
<valueString value="RiskAssessment"/>
</parameter>
</target>
<rule>
<name value="riskBase"/>
<source>
<context value="qr"/>
</source>
<target>
<context value="ra"/>
</target>
<target>
<context value="entry"/>
</target>
<dependent>
<name value="BuildRiskBase"/>
<parameter>
<valueId value="qr"/>
</parameter>
<parameter>
<valueId value="obs"/>
</parameter>
<parameter>
<valueId value="ra"/>
</parameter>
<parameter>
<valueId value="entry"/>
</parameter>
</dependent>
</rule>
<rule>
<name value="riskCode"/>
<source>
<context value="qr"/>
</source>
<target>
<context value="ra"/>
</target>
<dependent>
<name value="SetMorseRiskCode"/>
<parameter>
<valueId value="qr"/>
</parameter>
<parameter>
<valueId value="ra"/>
</parameter>
</dependent>
</rule>
<rule>
<name value="prediction"/>
<source>
<context value="qr"/>
</source>
<target>
<context value="ra"/>
<element value="prediction"/>
<variable value="pred"/>
</target>
<rule>
<name value="qualitativeRisk"/>
<source>
<context value="qr"/>
</source>
<target>
<context value="pred"/>
<element value="qualitativeRisk"/>
<variable value="risk"/>
</target>
<rule>
<name value="hl7Coding"/>
<source>
<context value="qr"/>
</source>
<target>
<context value="risk"/>
<element value="coding"/>
<variable value="coding"/>
</target>
<rule>
<name value="riskSystem"/>
<source>
<context value="qr"/>
</source>
<target>
<context value="coding"/>
<element value="system"/>
<transform value="copy"/>
<parameter>
<valueString
value="http://terminology.hl7.org/CodeSystem/risk-probability"/>
</parameter>
</target>
</rule>
<rule>
<name value="riskCode"/>
<source>
<context value="qr"/>
</source>
<target>
<context value="coding"/>
<element value="code"/>
<transform value="copy"/>
<parameter>
<valueString value="low"/>
</parameter>
</target>
</rule>
<rule>
<name value="riskDisplay"/>
<source>
<context value="qr"/>
</source>
<target>
<context value="coding"/>
<element value="display"/>
<transform value="copy"/>
<parameter>
<valueString value="Low likelihood"/>
</parameter>
</target>
</rule>
</rule>
<rule>
<name value="loincCoding"/>
<source>
<context value="qr"/>
</source>
<target>
<context value="risk"/>
<element value="coding"/>
<variable value="loinc"/>
</target>
<rule>
<name value="loincSystem"/>
<source>
<context value="qr"/>
</source>
<target>
<context value="loinc"/>
<element value="system"/>
<transform value="copy"/>
<parameter>
<valueString value="http://loinc.org"/>
</parameter>
</target>
</rule>
<rule>
<name value="loincCode"/>
<source>
<context value="qr"/>
</source>
<target>
<context value="loinc"/>
<element value="code"/>
<transform value="copy"/>
<parameter>
<valueString value="LA13038-7"/>
</parameter>
</target>
</rule>
<rule>
<name value="loincDisplay"/>
<source>
<context value="qr"/>
</source>
<target>
<context value="loinc"/>
<element value="display"/>
<transform value="copy"/>
<parameter>
<valueString value="Low Risk (MFS Score 0 - 24)"/>
</parameter>
</target>
</rule>
</rule>
<rule>
<name value="riskText"/>
<source>
<context value="qr"/>
</source>
<target>
<context value="risk"/>
<element value="text"/>
<transform value="copy"/>
<parameter>
<valueString value="Low risk"/>
</parameter>
</target>
</rule>
</rule>
</rule>
</rule>
<rule>
<name value="morseModerate"/>
<source>
<context value="obs"/>
<condition
value="(value.ofType(integer) >= 25) and (value.ofType(integer) <= 49)"/>
</source>
<target>
<context value="bundle"/>
<element value="entry"/>
<variable value="entry"/>
</target>
<target>
<context value="entry"/>
<element value="resource"/>
<variable value="ra"/>
<transform value="create"/>
<parameter>
<valueString value="RiskAssessment"/>
</parameter>
</target>
<rule>
<name value="riskBase"/>
<source>
<context value="qr"/>
</source>
<target>
<context value="ra"/>
</target>
<target>
<context value="entry"/>
</target>
<dependent>
<name value="BuildRiskBase"/>
<parameter>
<valueId value="qr"/>
</parameter>
<parameter>
<valueId value="obs"/>
</parameter>
<parameter>
<valueId value="ra"/>
</parameter>
<parameter>
<valueId value="entry"/>
</parameter>
</dependent>
</rule>
<rule>
<name value="riskCode"/>
<source>
<context value="qr"/>
</source>
<target>
<context value="ra"/>
</target>
<dependent>
<name value="SetMorseRiskCode"/>
<parameter>
<valueId value="qr"/>
</parameter>
<parameter>
<valueId value="ra"/>
</parameter>
</dependent>
</rule>
<rule>
<name value="prediction"/>
<source>
<context value="qr"/>
</source>
<target>
<context value="ra"/>
<element value="prediction"/>
<variable value="pred"/>
</target>
<rule>
<name value="qualitativeRisk"/>
<source>
<context value="qr"/>
</source>
<target>
<context value="pred"/>
<element value="qualitativeRisk"/>
<variable value="risk"/>
</target>
<rule>
<name value="hl7Coding"/>
<source>
<context value="qr"/>
</source>
<target>
<context value="risk"/>
<element value="coding"/>
<variable value="coding"/>
</target>
<rule>
<name value="riskSystem"/>
<source>
<context value="qr"/>
</source>
<target>
<context value="coding"/>
<element value="system"/>
<transform value="copy"/>
<parameter>
<valueString
value="http://terminology.hl7.org/CodeSystem/risk-probability"/>
</parameter>
</target>
</rule>
<rule>
<name value="riskCode"/>
<source>
<context value="qr"/>
</source>
<target>
<context value="coding"/>
<element value="code"/>
<transform value="copy"/>
<parameter>
<valueString value="moderate"/>
</parameter>
</target>
</rule>
<rule>
<name value="riskDisplay"/>
<source>
<context value="qr"/>
</source>
<target>
<context value="coding"/>
<element value="display"/>
<transform value="copy"/>
<parameter>
<valueString value="Moderate likelihood"/>
</parameter>
</target>
</rule>
</rule>
<rule>
<name value="loincCoding"/>
<source>
<context value="qr"/>
</source>
<target>
<context value="risk"/>
<element value="coding"/>
<variable value="loinc"/>
</target>
<rule>
<name value="loincSystem"/>
<source>
<context value="qr"/>
</source>
<target>
<context value="loinc"/>
<element value="system"/>
<transform value="copy"/>
<parameter>
<valueString value="http://loinc.org"/>
</parameter>
</target>
</rule>
<rule>
<name value="loincCode"/>
<source>
<context value="qr"/>
</source>
<target>
<context value="loinc"/>
<element value="code"/>
<transform value="copy"/>
<parameter>
<valueString value="LA13039-5"/>
</parameter>
</target>
</rule>
<rule>
<name value="loincDisplay"/>
<source>
<context value="qr"/>
</source>
<target>
<context value="loinc"/>
<element value="display"/>
<transform value="copy"/>
<parameter>
<valueString value="Moderate Risk (MFS Score 25 - 45)"/>
</parameter>
</target>
</rule>
</rule>
<rule>
<name value="riskText"/>
<source>
<context value="qr"/>
</source>
<target>
<context value="risk"/>
<element value="text"/>
<transform value="copy"/>
<parameter>
<valueString value="Moderate risk"/>
</parameter>
</target>
</rule>
</rule>
</rule>
</rule>
<rule>
<name value="morseHigh"/>
<source>
<context value="obs"/>
<condition value="value.ofType(integer) >= 50"/>
</source>
<target>
<context value="bundle"/>
<element value="entry"/>
<variable value="entry"/>
</target>
<target>
<context value="entry"/>
<element value="resource"/>
<variable value="ra"/>
<transform value="create"/>
<parameter>
<valueString value="RiskAssessment"/>
</parameter>
</target>
<rule>
<name value="riskBase"/>
<source>
<context value="qr"/>
</source>
<target>
<context value="ra"/>
</target>
<target>
<context value="entry"/>
</target>
<dependent>
<name value="BuildRiskBase"/>
<parameter>
<valueId value="qr"/>
</parameter>
<parameter>
<valueId value="obs"/>
</parameter>
<parameter>
<valueId value="ra"/>
</parameter>
<parameter>
<valueId value="entry"/>
</parameter>
</dependent>
</rule>
<rule>
<name value="riskCode"/>
<source>
<context value="qr"/>
</source>
<target>
<context value="ra"/>
</target>
<dependent>
<name value="SetMorseRiskCode"/>
<parameter>
<valueId value="qr"/>
</parameter>
<parameter>
<valueId value="ra"/>
</parameter>
</dependent>
</rule>
<rule>
<name value="prediction"/>
<source>
<context value="qr"/>
</source>
<target>
<context value="ra"/>
<element value="prediction"/>
<variable value="pred"/>
</target>
<rule>
<name value="qualitativeRisk"/>
<source>
<context value="qr"/>
</source>
<target>
<context value="pred"/>
<element value="qualitativeRisk"/>
<variable value="risk"/>
</target>
<rule>
<name value="hl7Coding"/>
<source>
<context value="qr"/>
</source>
<target>
<context value="risk"/>
<element value="coding"/>
<variable value="coding"/>
</target>
<rule>
<name value="riskSystem"/>
<source>
<context value="qr"/>
</source>
<target>
<context value="coding"/>
<element value="system"/>
<transform value="copy"/>
<parameter>
<valueString
value="http://terminology.hl7.org/CodeSystem/risk-probability"/>
</parameter>
</target>
</rule>
<rule>
<name value="riskCode"/>
<source>
<context value="qr"/>
</source>
<target>
<context value="coding"/>
<element value="code"/>
<transform value="copy"/>
<parameter>
<valueString value="high"/>
</parameter>
</target>
</rule>
<rule>
<name value="riskDisplay"/>
<source>
<context value="qr"/>
</source>
<target>
<context value="coding"/>
<element value="display"/>
<transform value="copy"/>
<parameter>
<valueString value="High likelihood"/>
</parameter>
</target>
</rule>
</rule>
<rule>
<name value="loincCoding"/>
<source>
<context value="qr"/>
</source>
<target>
<context value="risk"/>
<element value="coding"/>
<variable value="loinc"/>
</target>
<rule>
<name value="loincSystem"/>
<source>
<context value="qr"/>
</source>
<target>
<context value="loinc"/>
<element value="system"/>
<transform value="copy"/>
<parameter>
<valueString value="http://loinc.org"/>
</parameter>
</target>
</rule>
<rule>
<name value="loincCode"/>
<source>
<context value="qr"/>
</source>
<target>
<context value="loinc"/>
<element value="code"/>
<transform value="copy"/>
<parameter>
<valueString value="LA13040-3"/>
</parameter>
</target>
</rule>
<rule>
<name value="loincDisplay"/>
<source>
<context value="qr"/>
</source>
<target>
<context value="loinc"/>
<element value="display"/>
<transform value="copy"/>
<parameter>
<valueString value="High Risk (MFS Score 50+)"/>
</parameter>
</target>
</rule>
</rule>
<rule>
<name value="riskText"/>
<source>
<context value="qr"/>
</source>
<target>
<context value="risk"/>
<element value="text"/>
<transform value="copy"/>
<parameter>
<valueString value="High risk"/>
</parameter>
</target>
</rule>
</rule>
</rule>
</rule>
</group>
<group>
<name value="SetMorseRiskCode"/>
<input>
<name value="qr"/>
<type value="QR"/>
<mode value="source"/>
</input>
<input>
<name value="ra"/>
<type value="RiskAssessment"/>
<mode value="target"/>
</input>
<rule>
<name value="code"/>
<source>
<context value="qr"/>
</source>
<target>
<context value="ra"/>
<element value="code"/>
<variable value="code"/>
</target>
<rule>
<name value="codeCoding"/>
<source>
<context value="qr"/>
</source>
<target>
<context value="code"/>
<element value="coding"/>
<variable value="coding"/>
</target>
<rule>
<name value="codeSystem"/>
<source>
<context value="qr"/>
</source>
<target>
<context value="coding"/>
<element value="system"/>
<transform value="copy"/>
<parameter>
<valueString value="http://loinc.org"/>
</parameter>
</target>
</rule>
<rule>
<name value="codeCode"/>
<source>
<context value="qr"/>
</source>
<target>
<context value="coding"/>
<element value="code"/>
<transform value="copy"/>
<parameter>
<valueString value="59461-4"/>
</parameter>
</target>
</rule>
<rule>
<name value="codeDisplay"/>
<source>
<context value="qr"/>
</source>
<target>
<context value="coding"/>
<element value="display"/>
<transform value="copy"/>
<parameter>
<valueString value="Fall risk level [Morse Fall Scale]"/>
</parameter>
</target>
</rule>
</rule>
</rule>
</group>
<group>
<name value="BuildObsBase"/>
<documentation
value="─────────────────────────────────────────────────────────────────────────────
Shared scaffolding. Repeated in each map rather than imported: the transform
engine resolves `imports` against whatever StructureMaps happen to be on the
server, and a form that stops extracting because a shared map was not
uploaded is a worse failure than a duplicated group.
─────────────────────────────────────────────────────────────────────────────
Two notes on what the publisher's StructureMap validator says about this file.
Source parameters below are left untyped on purpose. Writing `: Element` makes
the validator compare QuestionnaireResponse.item against the literal 'Element'
and report them as incompatible with each other, which is noise, not a finding.
Untyped, it says only that it cannot check the paths.
`evaluate(context, expression)` is flagged as "takes 1 parameter but 2 were
found". Leave it. The FML parser in the same jar refuses the one-argument form
outright -- it wants a parameter, a comma, then the FHIRPath -- so the publisher
is objecting to what its own compiler emits. Two arguments is the only form that
compiles, and it is what the R5 transform engine executes."/>
<input>
<name value="qr"/>
<type value="QR"/>
<mode value="source"/>
</input>
<input>
<name value="obs"/>
<type value="Observation"/>
<mode value="target"/>
</input>
<input>
<name value="entry"/>
<mode value="target"/>
</input>
<rule>
<name value="idAndFullUrl"/>
<source>
<context value="qr"/>
</source>
<target>
<context value="obs"/>
<element value="id"/>
<transform value="uuid"/>
</target>
<dependent>
<name value="SetObservationFullUrl"/>
<parameter>
<valueId value="obs"/>
</parameter>
<parameter>
<valueId value="entry"/>
</parameter>
</dependent>
</rule>
<rule>
<name value="entryRequest"/>
<source>
<context value="qr"/>
</source>
<target>
<context value="entry"/>
<element value="request"/>
<variable value="request"/>
</target>
<rule>
<name value="requestMethod"/>
<source>
<context value="qr"/>
</source>
<target>
<context value="request"/>
<element value="method"/>
<transform value="copy"/>
<parameter>
<valueString value="POST"/>
</parameter>
</target>
</rule>
<rule>
<name value="requestUrl"/>
<source>
<context value="qr"/>
</source>
<target>
<context value="request"/>
<element value="url"/>
<transform value="copy"/>
<parameter>
<valueString value="Observation"/>
</parameter>
</target>
</rule>
</rule>
<rule>
<name value="status"/>
<source>
<context value="qr"/>
</source>
<target>
<context value="obs"/>
<element value="status"/>
<transform value="copy"/>
<parameter>
<valueString value="final"/>
</parameter>
</target>
</rule>
<rule>
<name value="subject"/>
<source>
<context value="qr"/>
<element value="subject"/>
<variable value="s"/>
</source>
<target>
<context value="obs"/>
<element value="subject"/>
<transform value="copy"/>
<parameter>
<valueId value="s"/>
</parameter>
</target>
</rule>
<rule>
<name value="encounter"/>
<source>
<context value="qr"/>
<element value="encounter"/>
<variable value="e"/>
</source>
<target>
<context value="obs"/>
<element value="encounter"/>
<transform value="copy"/>
<parameter>
<valueId value="e"/>
</parameter>
</target>
</rule>
<rule>
<name value="effective"/>
<source>
<context value="qr"/>
<element value="authored"/>
<variable value="t"/>
</source>
<target>
<context value="obs"/>
<element value="effective"/>
<transform value="copy"/>
<parameter>
<valueId value="t"/>
</parameter>
</target>
</rule>
<rule>
<name value="performerFromSource"/>
<source>
<context value="qr"/>
<element value="source"/>
<variable value="src"/>
</source>
<target>
<context value="obs"/>
<element value="performer"/>
<transform value="copy"/>
<parameter>
<valueId value="src"/>
</parameter>
</target>
</rule>
<rule>
<name value="performerFallback"/>
<source>
<context value="qr"/>
<condition value="source.exists().not()"/>
</source>
<rule>
<name value="performerFromAuthor"/>
<source>
<context value="qr"/>
<element value="author"/>
<variable value="a"/>
</source>
<target>
<context value="obs"/>
<element value="performer"/>
<transform value="copy"/>
<parameter>
<valueId value="a"/>
</parameter>
</target>
</rule>
</rule>
<rule>
<name value="linkQuestionnaireResponse"/>
<source>
<context value="qr"/>
<element value="id"/>
<variable value="qid"/>
<condition value="$this.hasValue()"/>
</source>
<target>
<context value="obs"/>
<element value="derivedFrom"/>
<variable value="ref"/>
<transform value="create"/>
<parameter>
<valueString value="Reference"/>
</parameter>
</target>
<target>
<context value="ref"/>
<element value="reference"/>
<transform value="copy"/>
<parameter>
<valueId value="qid"/>
</parameter>
</target>
<documentation
value="A stored response's id already reads "QuestionnaireResponse/<id>", so it is a
relative reference as it stands. The hasValue() guard is what stops an
unsaved response -- one posted straight to $extract rather than saved first --
from writing "QuestionnaireResponse/null" into the record."/>
</rule>
</group>
<group>
<name value="BuildRiskBase"/>
<documentation
value="The RiskAssessment stands on two things: the response that was filled in and
the Observation that holds the number. Both go in basis, which is what the
SGHI RiskAssessment profile binds to a QuestionnaireResponse."/>
<input>
<name value="qr"/>
<type value="QR"/>
<mode value="source"/>
</input>
<input>
<name value="obs"/>
<type value="Observation"/>
<mode value="source"/>
</input>
<input>
<name value="ra"/>
<type value="RiskAssessment"/>
<mode value="target"/>
</input>
<input>
<name value="entry"/>
<mode value="target"/>
</input>
<rule>
<name value="idAndFullUrl"/>
<source>
<context value="qr"/>
</source>
<target>
<context value="ra"/>
<element value="id"/>
<transform value="uuid"/>
</target>
<dependent>
<name value="SetRiskAssessmentFullUrl"/>
<parameter>
<valueId value="ra"/>
</parameter>
<parameter>
<valueId value="entry"/>
</parameter>
</dependent>
</rule>
<rule>
<name value="entryRequest"/>
<source>
<context value="qr"/>
</source>
<target>
<context value="entry"/>
<element value="request"/>
<variable value="request"/>
</target>
<rule>
<name value="requestMethod"/>
<source>
<context value="qr"/>
</source>
<target>
<context value="request"/>
<element value="method"/>
<transform value="copy"/>
<parameter>
<valueString value="POST"/>
</parameter>
</target>
</rule>
<rule>
<name value="requestUrl"/>
<source>
<context value="qr"/>
</source>
<target>
<context value="request"/>
<element value="url"/>
<transform value="copy"/>
<parameter>
<valueString value="RiskAssessment"/>
</parameter>
</target>
</rule>
</rule>
<rule>
<name value="status"/>
<source>
<context value="qr"/>
</source>
<target>
<context value="ra"/>
<element value="status"/>
<transform value="copy"/>
<parameter>
<valueString value="final"/>
</parameter>
</target>
</rule>
<rule>
<name value="subject"/>
<source>
<context value="qr"/>
<element value="subject"/>
<variable value="s"/>
</source>
<target>
<context value="ra"/>
<element value="subject"/>
<transform value="copy"/>
<parameter>
<valueId value="s"/>
</parameter>
</target>
</rule>
<rule>
<name value="encounter"/>
<source>
<context value="qr"/>
<element value="encounter"/>
<variable value="e"/>
</source>
<target>
<context value="ra"/>
<element value="encounter"/>
<transform value="copy"/>
<parameter>
<valueId value="e"/>
</parameter>
</target>
</rule>
<rule>
<name value="occurrence"/>
<source>
<context value="qr"/>
<element value="authored"/>
<variable value="t"/>
</source>
<target>
<context value="ra"/>
<element value="occurrence"/>
<transform value="copy"/>
<parameter>
<valueId value="t"/>
</parameter>
</target>
</rule>
<rule>
<name value="performerFromAuthor"/>
<source>
<context value="qr"/>
<element value="author"/>
<variable value="a"/>
</source>
<target>
<context value="ra"/>
<element value="performer"/>
<transform value="copy"/>
<parameter>
<valueId value="a"/>
</parameter>
</target>
</rule>
<rule>
<name value="performerFallback"/>
<source>
<context value="qr"/>
<condition value="author.exists().not()"/>
</source>
<rule>
<name value="performerFromSource"/>
<source>
<context value="qr"/>
<element value="source"/>
<variable value="src"/>
</source>
<target>
<context value="ra"/>
<element value="performer"/>
<transform value="copy"/>
<parameter>
<valueId value="src"/>
</parameter>
</target>
</rule>
</rule>
<rule>
<name value="basisResponse"/>
<source>
<context value="qr"/>
<element value="id"/>
<variable value="qid"/>
<condition value="$this.hasValue()"/>
</source>
<target>
<context value="ra"/>
<element value="basis"/>
<variable value="qref"/>
<transform value="create"/>
<parameter>
<valueString value="Reference"/>
</parameter>
</target>
<target>
<context value="qref"/>
<element value="reference"/>
<transform value="copy"/>
<parameter>
<valueId value="qid"/>
</parameter>
</target>
</rule>
<rule>
<name value="basisObservation"/>
<source>
<context value="obs"/>
<element value="id"/>
<variable value="oid"/>
</source>
<target>
<context value="ra"/>
<element value="basis"/>
<variable value="oref"/>
<transform value="create"/>
<parameter>
<valueString value="Reference"/>
</parameter>
</target>
<rule>
<name value="basisObservationRef"/>
<source>
<context value="oid"/>
</source>
<target>
<context value="oref"/>
<element value="reference"/>
<transform value="append"/>
<parameter>
<valueString value="Observation/"/>
</parameter>
<parameter>
<valueId value="oid"/>
</parameter>
</target>
</rule>
</rule>
</group>
<group>
<name value="SetComponentCodedValue"/>
<input>
<name value="it"/>
<mode value="source"/>
</input>
<input>
<name value="comp"/>
<mode value="target"/>
</input>
<rule>
<name value="componentAnswer"/>
<source>
<context value="it"/>
<element value="answer"/>
<listMode value="first"/>
<variable value="a"/>
</source>
<rule>
<name value="codedValue"/>
<source>
<context value="a"/>
<element value="value"/>
<variable value="cv"/>
</source>
<target>
<context value="comp"/>
<element value="value"/>
<variable value="cc"/>
<transform value="create"/>
<parameter>
<valueString value="CodeableConcept"/>
</parameter>
</target>
<rule>
<name value="valueCoding"/>
<source>
<context value="cv"/>
</source>
<target>
<context value="cc"/>
<element value="coding"/>
<transform value="copy"/>
<parameter>
<valueId value="cv"/>
</parameter>
</target>
</rule>
<rule>
<name value="valueText"/>
<source>
<context value="cv"/>
<element value="display"/>
<variable value="d"/>
</source>
<target>
<context value="cc"/>
<element value="text"/>
<transform value="copy"/>
<parameter>
<valueId value="d"/>
</parameter>
</target>
</rule>
</rule>
</rule>
</group>
<group>
<name value="SetSurveyCategory"/>
<input>
<name value="qr"/>
<type value="QR"/>
<mode value="source"/>
</input>
<input>
<name value="obs"/>
<type value="Observation"/>
<mode value="target"/>
</input>
<rule>
<name value="category"/>
<source>
<context value="qr"/>
</source>
<target>
<context value="obs"/>
<element value="category"/>
<variable value="cat"/>
</target>
<rule>
<name value="categoryCoding"/>
<source>
<context value="qr"/>
</source>
<target>
<context value="cat"/>
<element value="coding"/>
<variable value="coding"/>
</target>
<rule>
<name value="categorySystem"/>
<source>
<context value="qr"/>
</source>
<target>
<context value="coding"/>
<element value="system"/>
<transform value="copy"/>
<parameter>
<valueString
value="http://terminology.hl7.org/CodeSystem/observation-category"/>
</parameter>
</target>
</rule>
<rule>
<name value="categoryCode"/>
<source>
<context value="qr"/>
</source>
<target>
<context value="coding"/>
<element value="code"/>
<transform value="copy"/>
<parameter>
<valueString value="survey"/>
</parameter>
</target>
</rule>
<rule>
<name value="categoryDisplay"/>
<source>
<context value="qr"/>
</source>
<target>
<context value="coding"/>
<element value="display"/>
<transform value="copy"/>
<parameter>
<valueString value="Survey"/>
</parameter>
</target>
</rule>
</rule>
</rule>
</group>
<group>
<name value="SetObservationFullUrl"/>
<input>
<name value="obs"/>
<type value="Observation"/>
<mode value="source"/>
</input>
<input>
<name value="entry"/>
<mode value="target"/>
</input>
<rule>
<name value="assignFullUrl"/>
<source>
<context value="obs"/>
<element value="id"/>
<variable value="id"/>
</source>
<target>
<context value="entry"/>
<element value="fullUrl"/>
<transform value="append"/>
<parameter>
<valueString value="https://fhir.slade360.co.ke/fhir/Observation/"/>
</parameter>
<parameter>
<valueId value="id"/>
</parameter>
</target>
</rule>
</group>
<group>
<name value="SetRiskAssessmentFullUrl"/>
<input>
<name value="ra"/>
<type value="RiskAssessment"/>
<mode value="source"/>
</input>
<input>
<name value="entry"/>
<mode value="target"/>
</input>
<rule>
<name value="assignFullUrl"/>
<source>
<context value="ra"/>
<element value="id"/>
<variable value="id"/>
</source>
<target>
<context value="entry"/>
<element value="fullUrl"/>
<transform value="append"/>
<parameter>
<valueString
value="https://fhir.slade360.co.ke/fhir/RiskAssessment/"/>
</parameter>
<parameter>
<valueId value="id"/>
</parameter>
</target>
</rule>
</group>
</StructureMap>