<?xml version="1.0" encoding="UTF-8"?>

<StructureMap xmlns="http://hl7.org/fhir">
  <id value="ExtractBradenScale"/>
  <text>
    <status value="generated"/><div xmlns="http://www.w3.org/1999/xhtml"><p class="res-header-id"><b>Generated Narrative: StructureMap ExtractBradenScale</b></p><a name="ExtractBradenScale"> </a><a name="hcExtractBradenScale"> </a><pre class="fml">
<span style="color: #cc00cc">/// <b>url</b> = </span><span style="color: blue">'https://fhir.slade360.co.ke/fhir/StructureMap/ExtractBradenScale'</span>
<span style="color: #cc00cc">/// <b>name</b> = </span><span style="color: blue">'ExtractBradenScale'</span>
<span style="color: #cc00cc">/// <b>title</b> = </span><span style="color: blue">'Braden Scale Skin Assessment 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 Braden scale panel out as one Observation carrying the total, with the six sub-scores 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 sub-scores have been answered: a Braden computed from four of six items is not a Braden score, and banding one would put a number a nurse can act on next to a risk tier that is wrong.'</span>

<b>uses</b><span style="color: navy"> &quot;</span><a href="http://hl7.org/fhir/R5/questionnaireresponse.html" title="QuestionnaireResponse">http://hl7.org/fhir/StructureDefinition/QuestionnaireResponse</a><span style="color: navy">&quot; </span><b>alias </b>QR <b>as </b><b>source</b>
<b>uses</b><span style="color: navy"> &quot;</span><a href="http://hl7.org/fhir/R5/bundle.html" title="Bundle">http://hl7.org/fhir/StructureDefinition/Bundle</a><span style="color: navy">&quot; </span><b>alias </b>Bundle <b>as </b><b>target</b>
<b>uses</b><span style="color: navy"> &quot;</span><a href="http://hl7.org/fhir/R5/observation.html" title="Observation">http://hl7.org/fhir/StructureDefinition/Observation</a><span style="color: navy">&quot; </span><b>alias </b>Observation <b>as </b><b>target</b>
<b>uses</b><span style="color: navy"> &quot;</span><a href="http://hl7.org/fhir/R5/riskassessment.html" title="RiskAssessment">http://hl7.org/fhir/StructureDefinition/RiskAssessment</a><span style="color: navy">&quot; </span><b>alias </b>RiskAssessment <b>as </b><b>target</b>

<b>group </b>ExtractBradenScale<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> -&gt; </b></span>bundle.type = <span style="color: blue">'transaction'</span> <i>&quot;setBundleType&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">// </span><span style="color: green">LOINC publishes this panel flat -- the six sub-scores, 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 ('38222-6' | '38229-1' | '38223-4' | '38224-2' | '38225-9' | '38226-7')).answer.value.ofType(Coding).exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </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> -&gt; </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>&quot;base&quot;</i><span style="color: navy">;</span>
    qr<span style="color: navy"><b> -&gt; </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>&quot;category&quot;</i><span style="color: navy">;</span>
    qr<span style="color: navy"><b> -&gt; </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> -&gt; </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> -&gt; </b></span>coding.system = <span style="color: blue">'http://loinc.org'</span> <i>&quot;codeSystem&quot;</i><span style="color: navy">;</span>
        qr<span style="color: navy"><b> -&gt; </b></span>coding.code = <span style="color: blue">'38227-5'</span> <i>&quot;codeCode&quot;</i><span style="color: navy">;</span>
        qr<span style="color: navy"><b> -&gt; </b></span>coding.display = <span style="color: blue">'Braden scale total score'</span> <i>&quot;codeDisplay&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;codeCoding&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;code&quot;</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 weight cannot be read off the code the way the SGHI-coded instruments</span>
    <span style="color: navy">// </span><span style="color: green">allow, because these are LOINC answer codes and LA9605-2 says nothing about</span>
    <span style="color: navy">// </span><span style="color: green">being worth 3. It is read off a lookup instead. That lookup is safe to write</span>
    <span style="color: navy">// </span><span style="color: green">globally rather than per sub-score: the twenty-one answer codes across the</span>
    <span style="color: navy">// </span><span style="color: green">six items collapse to nineteen distinct ones, and the two that repeat --</span>
    <span style="color: navy">// </span><span style="color: green">LA9604-5 &quot;Very limited&quot; and LA9605-2 &quot;Slightly limited&quot;, shared by sensory</span>
    <span style="color: navy">// </span><span style="color: green">perception and mobility -- carry the same weight in both. Both paths are the</span>
    <span style="color: navy">// </span><span style="color: green">arithmetic Bergstrom published, so they cannot disagree.</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 sub-scores being present.</span>
    qr<b> where </b><span style="color: navy">(</span>item.where(linkId in ('38222-6' | '38229-1' | '38223-4' | '38224-2' | '38225-9' | '38226-7')).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> -&gt; </b></span>obs.value = evaluate<span style="color: navy">(</span>qr<span style="color: navy">, </span>iif(item.where(linkId = '38227-5').answer.value.exists(), item.where(linkId = '38227-5').answer.value.truncate(), item.where(linkId in ('38222-6' | '38229-1' | '38223-4' | '38224-2' | '38225-9' | '38226-7')).answer.value.ofType(Coding).code.select(iif($this in ('LA9603-7' | 'LA9607-8' | 'LA6742-6' | 'LA9614-4' | 'LA9615-1' | 'LA9617-7'), 1, iif($this in ('LA9604-5' | 'LA9608-6' | 'LA9611-0' | 'LA9616-9' | 'LA9618-5'), 2, iif($this in ('LA9605-2' | 'LA9609-4' | 'LA9612-8' | 'LA8913-1' | 'LA9619-3'), 3, iif($this in ('LA9606-0' | 'LA9610-2' | 'LA9613-6' | 'LA120-8' | 'LA9206-9'), 4, 0))))).aggregate($this + $total, 0))<span style="color: navy">)</span> <i>&quot;totalValue&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;totalRule&quot;</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 = '38222-6') and answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </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> -&gt; </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> -&gt; </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> -&gt; </b></span>coding.system = <span style="color: blue">'http://loinc.org'</span> <i>&quot;codeSystem&quot;</i><span style="color: navy">;</span>
          it<span style="color: navy"><b> -&gt; </b></span>coding.code = <span style="color: blue">'38222-6'</span> <i>&quot;codeCode&quot;</i><span style="color: navy">;</span>
          it<span style="color: navy"><b> -&gt; </b></span>coding.display = <span style="color: blue">'Sensory perception Braden scale'</span> <i>&quot;codeDisplay&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;codeCoding&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;sensoryCode&quot;</i><span style="color: navy">;</span>
      it<span style="color: navy"><b> -&gt; </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>&quot;sensoryValue&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;sensoryRule&quot;</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 = '38229-1') and answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </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> -&gt; </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> -&gt; </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> -&gt; </b></span>coding.system = <span style="color: blue">'http://loinc.org'</span> <i>&quot;codeSystem&quot;</i><span style="color: navy">;</span>
          it<span style="color: navy"><b> -&gt; </b></span>coding.code = <span style="color: blue">'38229-1'</span> <i>&quot;codeCode&quot;</i><span style="color: navy">;</span>
          it<span style="color: navy"><b> -&gt; </b></span>coding.display = <span style="color: blue">'Moisture exposure Braden scale'</span> <i>&quot;codeDisplay&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;codeCoding&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;moistureCode&quot;</i><span style="color: navy">;</span>
      it<span style="color: navy"><b> -&gt; </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>&quot;moistureValue&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;moistureRule&quot;</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 = '38223-4') and answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </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> -&gt; </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> -&gt; </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> -&gt; </b></span>coding.system = <span style="color: blue">'http://loinc.org'</span> <i>&quot;codeSystem&quot;</i><span style="color: navy">;</span>
          it<span style="color: navy"><b> -&gt; </b></span>coding.code = <span style="color: blue">'38223-4'</span> <i>&quot;codeCode&quot;</i><span style="color: navy">;</span>
          it<span style="color: navy"><b> -&gt; </b></span>coding.display = <span style="color: blue">'Physical activity Braden scale'</span> <i>&quot;codeDisplay&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;codeCoding&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;activityCode&quot;</i><span style="color: navy">;</span>
      it<span style="color: navy"><b> -&gt; </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>&quot;activityValue&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;activityRule&quot;</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 = '38224-2') and answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </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> -&gt; </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> -&gt; </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> -&gt; </b></span>coding.system = <span style="color: blue">'http://loinc.org'</span> <i>&quot;codeSystem&quot;</i><span style="color: navy">;</span>
          it<span style="color: navy"><b> -&gt; </b></span>coding.code = <span style="color: blue">'38224-2'</span> <i>&quot;codeCode&quot;</i><span style="color: navy">;</span>
          it<span style="color: navy"><b> -&gt; </b></span>coding.display = <span style="color: blue">'Physical mobility Braden scale'</span> <i>&quot;codeDisplay&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;codeCoding&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;mobilityCode&quot;</i><span style="color: navy">;</span>
      it<span style="color: navy"><b> -&gt; </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>&quot;mobilityValue&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;mobilityRule&quot;</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 = '38225-9') and answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </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> -&gt; </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> -&gt; </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> -&gt; </b></span>coding.system = <span style="color: blue">'http://loinc.org'</span> <i>&quot;codeSystem&quot;</i><span style="color: navy">;</span>
          it<span style="color: navy"><b> -&gt; </b></span>coding.code = <span style="color: blue">'38225-9'</span> <i>&quot;codeCode&quot;</i><span style="color: navy">;</span>
          it<span style="color: navy"><b> -&gt; </b></span>coding.display = <span style="color: blue">'Nutrition intake pattern Braden scale'</span> <i>&quot;codeDisplay&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;codeCoding&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;nutritionCode&quot;</i><span style="color: navy">;</span>
      it<span style="color: navy"><b> -&gt; </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>&quot;nutritionValue&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;nutritionRule&quot;</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 = '38226-7') and answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </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> -&gt; </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> -&gt; </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> -&gt; </b></span>coding.system = <span style="color: blue">'http://loinc.org'</span> <i>&quot;codeSystem&quot;</i><span style="color: navy">;</span>
          it<span style="color: navy"><b> -&gt; </b></span>coding.code = <span style="color: blue">'38226-7'</span> <i>&quot;codeCode&quot;</i><span style="color: navy">;</span>
          it<span style="color: navy"><b> -&gt; </b></span>coding.display = <span style="color: blue">'Friction and shear Braden scale'</span> <i>&quot;codeDisplay&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;codeCoding&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;frictionCode&quot;</i><span style="color: navy">;</span>
      it<span style="color: navy"><b> -&gt; </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>&quot;frictionValue&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;frictionValueRule&quot;</i><span style="color: navy">;</span>
    qr<span style="color: navy"><b> -&gt; </b></span> obs<span style="color: navy">, </span> bundle<b> then </b>AddBradenRiskAssessment<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>&quot;band&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">}</span> <i>&quot;bradenRule&quot;</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">Bergstrom's published tiers: 19 and over no risk, 15-18 mild, 13-14 moderate,</span>
<span style="color: navy">// </span><span style="color: green">10-12 high, 9 and under very high. Lower is worse.</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, and it has five concepts against Braden's five tiers</span>
<span style="color: navy">// </span><span style="color: green">but not the same five, so &quot;very high&quot; and &quot;high&quot; both land on #high. LOINC's</span>
<span style="color: navy">// </span><span style="color: green">own answer list for 81636-3 -- the list printed on the form the nurse filled</span>
<span style="color: navy">// </span><span style="color: green">in -- has the tier exactly, so it rides alongside and the two never drift. The</span>
<span style="color: navy">// </span><span style="color: green">text spells the published wording out for anything that only prints.</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>AddBradenRiskAssessment<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) &lt;= 9<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </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> -&gt; </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>&quot;riskBase&quot;</i><span style="color: navy">;</span>
    qr<span style="color: navy"><b> -&gt; </b></span>ra<b> then </b>SetBradenRiskCode<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>&quot;riskCode&quot;</i><span style="color: navy">;</span>
    qr<span style="color: navy"><b> -&gt; </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> -&gt; </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> -&gt; </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> -&gt; </b></span>coding.system = <span style="color: blue">'http://terminology.hl7.org/CodeSystem/risk-probability'</span> <i>&quot;riskSystem&quot;</i><span style="color: navy">;</span>
          qr<span style="color: navy"><b> -&gt; </b></span>coding.code = <span style="color: blue">'high'</span> <i>&quot;riskCode&quot;</i><span style="color: navy">;</span>
          qr<span style="color: navy"><b> -&gt; </b></span>coding.display = <span style="color: blue">'High likelihood'</span> <i>&quot;riskDisplay&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;hl7Coding&quot;</i><span style="color: navy">;</span>
        qr<span style="color: navy"><b> -&gt; </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> -&gt; </b></span>loinc.system = <span style="color: blue">'http://loinc.org'</span> <i>&quot;loincSystem&quot;</i><span style="color: navy">;</span>
          qr<span style="color: navy"><b> -&gt; </b></span>loinc.code = <span style="color: blue">'LA14637-5'</span> <i>&quot;loincCode&quot;</i><span style="color: navy">;</span>
          qr<span style="color: navy"><b> -&gt; </b></span>loinc.display = <span style="color: blue">'Very high'</span> <i>&quot;loincDisplay&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;loincCoding&quot;</i><span style="color: navy">;</span>
        qr<span style="color: navy"><b> -&gt; </b></span>risk.text = <span style="color: blue">'Very high risk'</span> <i>&quot;riskText&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;qualitativeRisk&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;prediction&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">}</span> <i>&quot;bradenVeryHigh&quot;</i><span style="color: navy">;</span>
  obs<b> where </b><span style="color: navy">(</span>(value.ofType(integer) &gt;= 10) and (value.ofType(integer) &lt;= 12)<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </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> -&gt; </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>&quot;riskBase&quot;</i><span style="color: navy">;</span>
    qr<span style="color: navy"><b> -&gt; </b></span>ra<b> then </b>SetBradenRiskCode<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>&quot;riskCode&quot;</i><span style="color: navy">;</span>
    qr<span style="color: navy"><b> -&gt; </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> -&gt; </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> -&gt; </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> -&gt; </b></span>coding.system = <span style="color: blue">'http://terminology.hl7.org/CodeSystem/risk-probability'</span> <i>&quot;riskSystem&quot;</i><span style="color: navy">;</span>
          qr<span style="color: navy"><b> -&gt; </b></span>coding.code = <span style="color: blue">'high'</span> <i>&quot;riskCode&quot;</i><span style="color: navy">;</span>
          qr<span style="color: navy"><b> -&gt; </b></span>coding.display = <span style="color: blue">'High likelihood'</span> <i>&quot;riskDisplay&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;hl7Coding&quot;</i><span style="color: navy">;</span>
        qr<span style="color: navy"><b> -&gt; </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> -&gt; </b></span>loinc.system = <span style="color: blue">'http://loinc.org'</span> <i>&quot;loincSystem&quot;</i><span style="color: navy">;</span>
          qr<span style="color: navy"><b> -&gt; </b></span>loinc.code = <span style="color: blue">'LA9193-9'</span> <i>&quot;loincCode&quot;</i><span style="color: navy">;</span>
          qr<span style="color: navy"><b> -&gt; </b></span>loinc.display = <span style="color: blue">'High'</span> <i>&quot;loincDisplay&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;loincCoding&quot;</i><span style="color: navy">;</span>
        qr<span style="color: navy"><b> -&gt; </b></span>risk.text = <span style="color: blue">'High risk'</span> <i>&quot;riskText&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;qualitativeRisk&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;prediction&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">}</span> <i>&quot;bradenHigh&quot;</i><span style="color: navy">;</span>
  obs<b> where </b><span style="color: navy">(</span>(value.ofType(integer) &gt;= 13) and (value.ofType(integer) &lt;= 14)<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </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> -&gt; </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>&quot;riskBase&quot;</i><span style="color: navy">;</span>
    qr<span style="color: navy"><b> -&gt; </b></span>ra<b> then </b>SetBradenRiskCode<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>&quot;riskCode&quot;</i><span style="color: navy">;</span>
    qr<span style="color: navy"><b> -&gt; </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> -&gt; </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> -&gt; </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> -&gt; </b></span>coding.system = <span style="color: blue">'http://terminology.hl7.org/CodeSystem/risk-probability'</span> <i>&quot;riskSystem&quot;</i><span style="color: navy">;</span>
          qr<span style="color: navy"><b> -&gt; </b></span>coding.code = <span style="color: blue">'moderate'</span> <i>&quot;riskCode&quot;</i><span style="color: navy">;</span>
          qr<span style="color: navy"><b> -&gt; </b></span>coding.display = <span style="color: blue">'Moderate likelihood'</span> <i>&quot;riskDisplay&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;hl7Coding&quot;</i><span style="color: navy">;</span>
        qr<span style="color: navy"><b> -&gt; </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> -&gt; </b></span>loinc.system = <span style="color: blue">'http://loinc.org'</span> <i>&quot;loincSystem&quot;</i><span style="color: navy">;</span>
          qr<span style="color: navy"><b> -&gt; </b></span>loinc.code = <span style="color: blue">'LA6751-7'</span> <i>&quot;loincCode&quot;</i><span style="color: navy">;</span>
          qr<span style="color: navy"><b> -&gt; </b></span>loinc.display = <span style="color: blue">'Moderate'</span> <i>&quot;loincDisplay&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;loincCoding&quot;</i><span style="color: navy">;</span>
        qr<span style="color: navy"><b> -&gt; </b></span>risk.text = <span style="color: blue">'Moderate risk'</span> <i>&quot;riskText&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;qualitativeRisk&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;prediction&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">}</span> <i>&quot;bradenModerate&quot;</i><span style="color: navy">;</span>
  obs<b> where </b><span style="color: navy">(</span>(value.ofType(integer) &gt;= 15) and (value.ofType(integer) &lt;= 18)<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </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> -&gt; </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>&quot;riskBase&quot;</i><span style="color: navy">;</span>
    qr<span style="color: navy"><b> -&gt; </b></span>ra<b> then </b>SetBradenRiskCode<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>&quot;riskCode&quot;</i><span style="color: navy">;</span>
    qr<span style="color: navy"><b> -&gt; </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> -&gt; </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> -&gt; </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> -&gt; </b></span>coding.system = <span style="color: blue">'http://terminology.hl7.org/CodeSystem/risk-probability'</span> <i>&quot;riskSystem&quot;</i><span style="color: navy">;</span>
          qr<span style="color: navy"><b> -&gt; </b></span>coding.code = <span style="color: blue">'low'</span> <i>&quot;riskCode&quot;</i><span style="color: navy">;</span>
          qr<span style="color: navy"><b> -&gt; </b></span>coding.display = <span style="color: blue">'Low likelihood'</span> <i>&quot;riskDisplay&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;hl7Coding&quot;</i><span style="color: navy">;</span>
        qr<span style="color: navy"><b> -&gt; </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> -&gt; </b></span>loinc.system = <span style="color: blue">'http://loinc.org'</span> <i>&quot;loincSystem&quot;</i><span style="color: navy">;</span>
          qr<span style="color: navy"><b> -&gt; </b></span>loinc.code = <span style="color: blue">'LA6752-5'</span> <i>&quot;loincCode&quot;</i><span style="color: navy">;</span>
          qr<span style="color: navy"><b> -&gt; </b></span>loinc.display = <span style="color: blue">'Mild'</span> <i>&quot;loincDisplay&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;loincCoding&quot;</i><span style="color: navy">;</span>
        qr<span style="color: navy"><b> -&gt; </b></span>risk.text = <span style="color: blue">'Mild risk'</span> <i>&quot;riskText&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;qualitativeRisk&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;prediction&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">}</span> <i>&quot;bradenMild&quot;</i><span style="color: navy">;</span>
  obs<b> where </b><span style="color: navy">(</span>value.ofType(integer) &gt;= 19<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </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> -&gt; </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>&quot;riskBase&quot;</i><span style="color: navy">;</span>
    qr<span style="color: navy"><b> -&gt; </b></span>ra<b> then </b>SetBradenRiskCode<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>&quot;riskCode&quot;</i><span style="color: navy">;</span>
    qr<span style="color: navy"><b> -&gt; </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> -&gt; </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> -&gt; </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> -&gt; </b></span>coding.system = <span style="color: blue">'http://terminology.hl7.org/CodeSystem/risk-probability'</span> <i>&quot;riskSystem&quot;</i><span style="color: navy">;</span>
          qr<span style="color: navy"><b> -&gt; </b></span>coding.code = <span style="color: blue">'negligible'</span> <i>&quot;riskCode&quot;</i><span style="color: navy">;</span>
          qr<span style="color: navy"><b> -&gt; </b></span>coding.display = <span style="color: blue">'Negligible likelihood'</span> <i>&quot;riskDisplay&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;hl7Coding&quot;</i><span style="color: navy">;</span>
        qr<span style="color: navy"><b> -&gt; </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> -&gt; </b></span>loinc.system = <span style="color: blue">'http://loinc.org'</span> <i>&quot;loincSystem&quot;</i><span style="color: navy">;</span>
          qr<span style="color: navy"><b> -&gt; </b></span>loinc.code = <span style="color: blue">'LA19983-8'</span> <i>&quot;loincCode&quot;</i><span style="color: navy">;</span>
          qr<span style="color: navy"><b> -&gt; </b></span>loinc.display = <span style="color: blue">'No risk'</span> <i>&quot;loincDisplay&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;loincCoding&quot;</i><span style="color: navy">;</span>
        qr<span style="color: navy"><b> -&gt; </b></span>risk.text = <span style="color: blue">'No risk identified'</span> <i>&quot;riskText&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;qualitativeRisk&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;prediction&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">}</span> <i>&quot;bradenNoRisk&quot;</i><span style="color: navy">;</span>
<span style="color: navy">}

</span><b>group </b>SetBradenRiskCode<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> -&gt; </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> -&gt; </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> -&gt; </b></span>coding.system = <span style="color: blue">'http://loinc.org'</span> <i>&quot;codeSystem&quot;</i><span style="color: navy">;</span>
      qr<span style="color: navy"><b> -&gt; </b></span>coding.code = <span style="color: blue">'81636-3'</span> <i>&quot;codeCode&quot;</i><span style="color: navy">;</span>
      qr<span style="color: navy"><b> -&gt; </b></span>coding.display = <span style="color: blue">'Pressure injury risk level Braden scale'</span> <i>&quot;codeDisplay&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;codeCoding&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">}</span> <i>&quot;code&quot;</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 &quot;takes 1 parameter but 2 were</span>
<span style="color: navy">// </span><span style="color: green">found&quot;. 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> -&gt; </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>&quot;idAndFullUrl&quot;</i><span style="color: navy">;</span>
  qr<span style="color: navy"><b> -&gt; </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> -&gt; </b></span>request.method = <span style="color: blue">'POST'</span> <i>&quot;requestMethod&quot;</i><span style="color: navy">;</span>
    qr<span style="color: navy"><b> -&gt; </b></span>request.url = <span style="color: blue">'Observation'</span> <i>&quot;requestUrl&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">}</span> <i>&quot;entryRequest&quot;</i><span style="color: navy">;</span>
  qr<span style="color: navy"><b> -&gt; </b></span>obs.status = <span style="color: blue">'final'</span> <i>&quot;status&quot;</i><span style="color: navy">;</span>
  qr.subject<b> as </b><span style="color: maroon">s</span><span style="color: navy"><b> -&gt; </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> -&gt; </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> -&gt; </b></span>obs.effective = <span style="color: maroon">t</span> <i>&quot;effective&quot;</i><span style="color: navy">;</span>
  qr.source<b> as </b><span style="color: maroon">src</span><span style="color: navy"><b> -&gt; </b></span>obs.performer = <span style="color: maroon">src</span> <i>&quot;performerFromSource&quot;</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> -&gt; </b></span>obs.performer = <span style="color: maroon">a</span> <i>&quot;performerFromAuthor&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">}</span> <i>&quot;performerFallback&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">// </span><span style="color: green">A stored response's id already reads &quot;QuestionnaireResponse/&lt;id&gt;&quot;, 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 &quot;QuestionnaireResponse/null&quot; 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> -&gt; </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>&quot;linkQuestionnaireResponse&quot;</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> -&gt; </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>&quot;idAndFullUrl&quot;</i><span style="color: navy">;</span>
  qr<span style="color: navy"><b> -&gt; </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> -&gt; </b></span>request.method = <span style="color: blue">'POST'</span> <i>&quot;requestMethod&quot;</i><span style="color: navy">;</span>
    qr<span style="color: navy"><b> -&gt; </b></span>request.url = <span style="color: blue">'RiskAssessment'</span> <i>&quot;requestUrl&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">}</span> <i>&quot;entryRequest&quot;</i><span style="color: navy">;</span>
  qr<span style="color: navy"><b> -&gt; </b></span>ra.status = <span style="color: blue">'final'</span> <i>&quot;status&quot;</i><span style="color: navy">;</span>
  qr.subject<b> as </b><span style="color: maroon">s</span><span style="color: navy"><b> -&gt; </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> -&gt; </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> -&gt; </b></span>ra.occurrence = <span style="color: maroon">t</span> <i>&quot;occurrence&quot;</i><span style="color: navy">;</span>
  qr.author<b> as </b><span style="color: maroon">a</span><span style="color: navy"><b> -&gt; </b></span>ra.performer = <span style="color: maroon">a</span> <i>&quot;performerFromAuthor&quot;</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> -&gt; </b></span>ra.performer = <span style="color: maroon">src</span> <i>&quot;performerFromSource&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">}</span> <i>&quot;performerFallback&quot;</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> -&gt; </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>&quot;basisResponse&quot;</i><span style="color: navy">;</span>
  obs.id<b> as </b><span style="color: maroon">oid</span><span style="color: navy"><b> -&gt; </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> -&gt; </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>&quot;basisObservationRef&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">}</span> <i>&quot;basisObservation&quot;</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> -&gt; </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> -&gt; </b></span>cc.coding = <span style="color: maroon">cv</span> <i>&quot;valueCoding&quot;</i><span style="color: navy">;</span>
      cv.display<b> as </b><span style="color: maroon">d</span><span style="color: navy"><b> -&gt; </b></span>cc.text = <span style="color: maroon">d</span> <i>&quot;valueText&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;codedValue&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">}</span> <i>&quot;componentAnswer&quot;</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> -&gt; </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> -&gt; </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> -&gt; </b></span>coding.system = <span style="color: blue">'http://terminology.hl7.org/CodeSystem/observation-category'</span> <i>&quot;categorySystem&quot;</i><span style="color: navy">;</span>
      qr<span style="color: navy"><b> -&gt; </b></span>coding.code = <span style="color: blue">'survey'</span> <i>&quot;categoryCode&quot;</i><span style="color: navy">;</span>
      qr<span style="color: navy"><b> -&gt; </b></span>coding.display = <span style="color: blue">'Survey'</span> <i>&quot;categoryDisplay&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;categoryCoding&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">}</span> <i>&quot;category&quot;</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> -&gt; </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>&quot;assignFullUrl&quot;</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> -&gt; </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>&quot;assignFullUrl&quot;</i><span style="color: navy">;</span>
<span style="color: navy">}

</span></pre></div>
  </text>
  <url value="https://fhir.slade360.co.ke/fhir/StructureMap/ExtractBradenScale"/>
  <version value="0.1.0"/>
  <name value="ExtractBradenScale"/>
  <title value="Braden Scale Skin Assessment 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 Braden scale panel out as one Observation carrying the total, with the six sub-scores 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 sub-scores have been answered: a Braden computed from four of six items is not a Braden score, and banding one would put 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="ExtractBradenScale"/>
    <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="bradenRule"/>
      <source>
        <context value="qr"/>
        <condition value="item.where(linkId in ('38222-6' | '38229-1' | '38223-4' | '38224-2' | '38225-9' | '38226-7')).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="38227-5"/>
              </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="Braden scale total score"/>
              </parameter>
            </target>
          </rule>
        </rule>
      </rule>
      <rule>
        <name value="totalRule"/>
        <source>
          <context value="qr"/>
          <condition value="item.where(linkId in ('38222-6' | '38229-1' | '38223-4' | '38224-2' | '38225-9' | '38226-7')).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 = '38227-5').answer.value.exists(), item.where(linkId = '38227-5').answer.value.truncate(), item.where(linkId in ('38222-6' | '38229-1' | '38223-4' | '38224-2' | '38225-9' | '38226-7')).answer.value.ofType(Coding).code.select(iif($this in ('LA9603-7' | 'LA9607-8' | 'LA6742-6' | 'LA9614-4' | 'LA9615-1' | 'LA9617-7'), 1, iif($this in ('LA9604-5' | 'LA9608-6' | 'LA9611-0' | 'LA9616-9' | 'LA9618-5'), 2, iif($this in ('LA9605-2' | 'LA9609-4' | 'LA9612-8' | 'LA8913-1' | 'LA9619-3'), 3, iif($this in ('LA9606-0' | 'LA9610-2' | 'LA9613-6' | 'LA120-8' | 'LA9206-9'), 4, 0))))).aggregate($this + $total, 0))"/>
            </parameter>
          </target>
        </rule>
        <documentation value="The submitted total wins; otherwise sum the answers.&#xD;&#xA;The weight cannot be read off the code the way the SGHI-coded instruments&#xD;&#xA;allow, because these are LOINC answer codes and LA9605-2 says nothing about&#xD;&#xA;being worth 3. It is read off a lookup instead. That lookup is safe to write&#xD;&#xA;globally rather than per sub-score: the twenty-one answer codes across the&#xD;&#xA;six items collapse to nineteen distinct ones, and the two that repeat --&#xD;&#xA;LA9604-5 &quot;Very limited&quot; and LA9605-2 &quot;Slightly limited&quot;, shared by sensory&#xD;&#xA;perception and mobility -- carry the same weight in both. Both paths are the&#xD;&#xA;arithmetic Bergstrom published, so they cannot disagree.&#xD;&#xA;truncate(), not toInteger(): the form types the total `decimal`, and this&#xD;&#xA;engine's toInteger() returns empty for anything with a fractional part.&#xD;&#xA;Observation.value has no decimal choice, so it has to land as an integer.&#xD;&#xA;Guarded on all six sub-scores being present."/>
      </rule>
      <rule>
        <name value="sensoryRule"/>
        <source>
          <context value="qr"/>
          <element value="item"/>
          <variable value="it"/>
          <condition value="(linkId = '38222-6') and answer.value.exists()"/>
        </source>
        <target>
          <context value="obs"/>
          <element value="component"/>
          <variable value="comp"/>
        </target>
        <rule>
          <name value="sensoryCode"/>
          <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="38222-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="Sensory perception Braden scale"/>
                </parameter>
              </target>
            </rule>
          </rule>
        </rule>
        <rule>
          <name value="sensoryValue"/>
          <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="moistureRule"/>
        <source>
          <context value="qr"/>
          <element value="item"/>
          <variable value="it"/>
          <condition value="(linkId = '38229-1') and answer.value.exists()"/>
        </source>
        <target>
          <context value="obs"/>
          <element value="component"/>
          <variable value="comp"/>
        </target>
        <rule>
          <name value="moistureCode"/>
          <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="38229-1"/>
                </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="Moisture exposure Braden scale"/>
                </parameter>
              </target>
            </rule>
          </rule>
        </rule>
        <rule>
          <name value="moistureValue"/>
          <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="activityRule"/>
        <source>
          <context value="qr"/>
          <element value="item"/>
          <variable value="it"/>
          <condition value="(linkId = '38223-4') and answer.value.exists()"/>
        </source>
        <target>
          <context value="obs"/>
          <element value="component"/>
          <variable value="comp"/>
        </target>
        <rule>
          <name value="activityCode"/>
          <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="38223-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="Physical activity Braden scale"/>
                </parameter>
              </target>
            </rule>
          </rule>
        </rule>
        <rule>
          <name value="activityValue"/>
          <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="mobilityRule"/>
        <source>
          <context value="qr"/>
          <element value="item"/>
          <variable value="it"/>
          <condition value="(linkId = '38224-2') and answer.value.exists()"/>
        </source>
        <target>
          <context value="obs"/>
          <element value="component"/>
          <variable value="comp"/>
        </target>
        <rule>
          <name value="mobilityCode"/>
          <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="38224-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="Physical mobility Braden scale"/>
                </parameter>
              </target>
            </rule>
          </rule>
        </rule>
        <rule>
          <name value="mobilityValue"/>
          <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="nutritionRule"/>
        <source>
          <context value="qr"/>
          <element value="item"/>
          <variable value="it"/>
          <condition value="(linkId = '38225-9') and answer.value.exists()"/>
        </source>
        <target>
          <context value="obs"/>
          <element value="component"/>
          <variable value="comp"/>
        </target>
        <rule>
          <name value="nutritionCode"/>
          <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="38225-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="Nutrition intake pattern Braden scale"/>
                </parameter>
              </target>
            </rule>
          </rule>
        </rule>
        <rule>
          <name value="nutritionValue"/>
          <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="frictionValueRule"/>
        <source>
          <context value="qr"/>
          <element value="item"/>
          <variable value="it"/>
          <condition value="(linkId = '38226-7') and answer.value.exists()"/>
        </source>
        <target>
          <context value="obs"/>
          <element value="component"/>
          <variable value="comp"/>
        </target>
        <rule>
          <name value="frictionCode"/>
          <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="38226-7"/>
                </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="Friction and shear Braden scale"/>
                </parameter>
              </target>
            </rule>
          </rule>
        </rule>
        <rule>
          <name value="frictionValue"/>
          <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="AddBradenRiskAssessment"/>
          <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 sub-scores, the total and the risk&#xD;&#xA;level are all top-level items, keyed by their own LOINC code -- so there is no&#xD;&#xA;group to hang the Observation off and the response itself is the anchor."/>
    </rule>
  </group>
  <group>
    <name value="AddBradenRiskAssessment"/>
    <documentation value="─────────────────────────────────────────────────────────────────────────────&#xD;&#xA;The band&#xD;&#xA;Bergstrom's published tiers: 19 and over no risk, 15-18 mild, 13-14 moderate,&#xD;&#xA;10-12 high, 9 and under very high. Lower is worse.&#xD;&#xA;qualitativeRisk carries two codings and a text. HL7's risk-probability is what&#xD;&#xA;a consumer escalates on, and it has five concepts against Braden's five tiers&#xD;&#xA;but not the same five, so &quot;very high&quot; and &quot;high&quot; both land on #high. LOINC's&#xD;&#xA;own answer list for 81636-3 -- the list printed on the form the nurse filled&#xD;&#xA;in -- has the tier exactly, so it rides alongside and the two never drift. The&#xD;&#xA;text spells the published wording out for anything that only prints.&#xD;&#xA;The band is derived from the total rather than copied from the form's own&#xD;&#xA;risk-level item. That item is a free pick list with nothing calculating it, so&#xD;&#xA;deriving is the only way the number and the tier are guaranteed to agree.&#xD;&#xA;─────────────────────────────────────────────────────────────────────────────"/>
    <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="bradenVeryHigh"/>
      <source>
        <context value="obs"/>
        <condition value="value.ofType(integer) &lt;= 9"/>
      </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="SetBradenRiskCode"/>
          <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="LA14637-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="Very high"/>
                </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="Very high risk"/>
              </parameter>
            </target>
          </rule>
        </rule>
      </rule>
    </rule>
    <rule>
      <name value="bradenHigh"/>
      <source>
        <context value="obs"/>
        <condition value="(value.ofType(integer) &gt;= 10) and (value.ofType(integer) &lt;= 12)"/>
      </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="SetBradenRiskCode"/>
          <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="LA9193-9"/>
                </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"/>
                </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>
    <rule>
      <name value="bradenModerate"/>
      <source>
        <context value="obs"/>
        <condition value="(value.ofType(integer) &gt;= 13) and (value.ofType(integer) &lt;= 14)"/>
      </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="SetBradenRiskCode"/>
          <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="LA6751-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="Moderate"/>
                </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="bradenMild"/>
      <source>
        <context value="obs"/>
        <condition value="(value.ofType(integer) &gt;= 15) and (value.ofType(integer) &lt;= 18)"/>
      </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="SetBradenRiskCode"/>
          <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="LA6752-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="Mild"/>
                </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="Mild risk"/>
              </parameter>
            </target>
          </rule>
        </rule>
      </rule>
    </rule>
    <rule>
      <name value="bradenNoRisk"/>
      <source>
        <context value="obs"/>
        <condition value="value.ofType(integer) &gt;= 19"/>
      </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="SetBradenRiskCode"/>
          <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="negligible"/>
                </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="Negligible 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="LA19983-8"/>
                </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="No risk"/>
                </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="No risk identified"/>
              </parameter>
            </target>
          </rule>
        </rule>
      </rule>
    </rule>
  </group>
  <group>
    <name value="SetBradenRiskCode"/>
    <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="81636-3"/>
            </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="Pressure injury risk level Braden scale"/>
            </parameter>
          </target>
        </rule>
      </rule>
    </rule>
  </group>
  <group>
    <name value="BuildObsBase"/>
    <documentation value="─────────────────────────────────────────────────────────────────────────────&#xD;&#xA;Shared scaffolding. Repeated in each map rather than imported: the transform&#xD;&#xA;engine resolves `imports` against whatever StructureMaps happen to be on the&#xD;&#xA;server, and a form that stops extracting because a shared map was not&#xD;&#xA;uploaded is a worse failure than a duplicated group.&#xD;&#xA;─────────────────────────────────────────────────────────────────────────────&#xD;&#xA;Two notes on what the publisher's StructureMap validator says about this file.&#xD;&#xA;Source parameters below are left untyped on purpose. Writing `: Element` makes&#xD;&#xA;the validator compare QuestionnaireResponse.item against the literal 'Element'&#xD;&#xA;and report them as incompatible with each other, which is noise, not a finding.&#xD;&#xA;Untyped, it says only that it cannot check the paths.&#xD;&#xA;`evaluate(context, expression)` is flagged as &quot;takes 1 parameter but 2 were&#xD;&#xA;found&quot;. Leave it. The FML parser in the same jar refuses the one-argument form&#xD;&#xA;outright -- it wants a parameter, a comma, then the FHIRPath -- so the publisher&#xD;&#xA;is objecting to what its own compiler emits. Two arguments is the only form that&#xD;&#xA;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 &quot;QuestionnaireResponse/&lt;id&gt;&quot;, so it is a&#xD;&#xA;relative reference as it stands. The hasValue() guard is what stops an&#xD;&#xA;unsaved response -- one posted straight to $extract rather than saved first --&#xD;&#xA;from writing &quot;QuestionnaireResponse/null&quot; into the record."/>
    </rule>
  </group>
  <group>
    <name value="BuildRiskBase"/>
    <documentation value="The RiskAssessment stands on two things: the response that was filled in and&#xD;&#xA;the Observation that holds the number. Both go in basis, which is what the&#xD;&#xA;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>