SGHI FHIR Profile Implementation Guide
0.1.0 - ci-build

SGHI FHIR Profile Implementation Guide, published by Kathurima Kimathi. This guide is not an authorized publication; it is the continuous build for version 0.1.0 built by the FHIR (HL7® FHIR® Standard) CI Build. This version is based on the current content of https://github.com/savannahghi/sil_fhir_profile_ig/ and changes regularly. See the Directory of published versions

: Inpatient Nutrition Screening (MUST) Extraction - XML Representation

Active as of 2026-10-06

Raw xml | Download


<StructureMap xmlns="http://hl7.org/fhir">
  <id value="ExtractInpatientNutritionScreening"/>
  <text>
    <status value="generated"/>
    <div xmlns="http://www.w3.org/1999/xhtml"><p class="res-header-id"><b>Generated Narrative: StructureMap ExtractInpatientNutritionScreening</b></p><a name="ExtractInpatientNutritionScreening"> </a><a name="hcExtractInpatientNutritionScreening"> </a><pre class="fml">
<span style="color: #cc00cc">/// <b>url</b> = </span><span style="color: blue">'https://fhir.slade360.co.ke/fhir/StructureMap/ExtractInpatientNutritionScreening'</span>
<span style="color: #cc00cc">/// <b>name</b> = </span><span style="color: blue">'ExtractInpatientNutritionScreening'</span>
<span style="color: #cc00cc">/// <b>title</b> = </span><span style="color: blue">'Inpatient Nutrition Screening (MUST) 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 MUST score becomes one Observation carrying the total with its three steps as components, plus a RiskAssessment for the band. The nutritional plan becomes a CarePlan, and a score in the high-risk band raises a dietitian referral. That referral is intent `proposal` and status `draft` deliberately: a map should not put an active order in a dietitian\'s queue on its own, so it arrives as something a clinician signs.'</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>uses</b><span style="color: navy"> &quot;</span><a href="http://hl7.org/fhir/R5/careplan.html" title="CarePlan">http://hl7.org/fhir/StructureDefinition/CarePlan</a><span style="color: navy">&quot; </span><b>alias </b>CarePlan <b>as </b><b>target</b>
<b>uses</b><span style="color: navy"> &quot;</span><a href="http://hl7.org/fhir/R5/servicerequest.html" title="ServiceRequest">http://hl7.org/fhir/StructureDefinition/ServiceRequest</a><span style="color: navy">&quot; </span><b>alias </b>ServiceRequest <b>as </b><b>target</b>

<b>group </b>ExtractInpatientNutritionScreening<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">── MUST score ─────────────────────────────────────────────────────────────</span>
  <span style="color: navy">// </span><span style="color: green">LOINC has 101789-6 for the screening itself and 101807-6 for its result</span>
  <span style="color: navy">// </span><span style="color: green">indicator, but nothing for the three steps, so those carry local codes.</span>
  qr.item<b> as </b><span style="color: maroon">gM</span><b> where </b><span style="color: navy">(</span>(linkId = 'must') and item.answer.value.ofType(Coding).exists()<span style="color: navy">)</span><b> then</b><span style="color: navy"> {
</span>    gM<span style="color: navy"><b> -&gt; </b></span> bundle.entry<b> as </b><span style="color: maroon">entryM</span><span style="color: navy">, </span> entryM.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">obsM</span><b> then</b><span style="color: navy"> {
</span>      qr<span style="color: navy"><b> -&gt; </b></span>obsM<b> then </b>CopyResponseTags<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">obsM</span><span style="color: navy">)</span> <i>&quot;responseTags&quot;</i><span style="color: navy">;</span>
      qr<span style="color: navy"><b> -&gt; </b></span> obsM<span style="color: navy">, </span> entryM<b> then </b>BuildObsBase<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">obsM</span><span style="color: navy">, </span><span style="color: maroon">entryM</span><span style="color: navy">)</span> <i>&quot;mustBase&quot;</i><span style="color: navy">;</span>
      qr<span style="color: navy"><b> -&gt; </b></span>obsM<b> then </b>SetSurveyCategory<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">obsM</span><span style="color: navy">)</span> <i>&quot;mustCategory&quot;</i><span style="color: navy">;</span>
      qr<span style="color: navy"><b> -&gt; </b></span>obsM.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">'101789-6'</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">'Malnutrition risk screening'</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>
        qr<span style="color: navy"><b> -&gt; </b></span>code.text = <span style="color: blue">'MUST score'</span> <i>&quot;codeText&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;mustCode&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">// </span><span style="color: green">The submitted total wins; otherwise sum the answers, reading each</span>
      <span style="color: navy">// </span><span style="color: green">weight off the tail of its code (must-loss-2 is worth 2). Guarded on</span>
      <span style="color: navy">// </span><span style="color: green">all three steps being answered -- MUST is a sum of three, and a sum of</span>
      <span style="color: navy">// </span><span style="color: green">two banded as low risk would send a wasting patient home.</span>
      gM<b> where </b><span style="color: navy">(</span>item.answer.value.ofType(Coding).count() = 3<span style="color: navy">)</span><b> then</b><span style="color: navy"> {
</span>        gM<span style="color: navy"><b> -&gt; </b></span>obsM.value = evaluate<span style="color: navy">(</span>gM<span style="color: navy">, </span>iif(item.where(linkId = 'must.total').answer.value.exists(), item.where(linkId = 'must.total').answer.value, item.answer.value.ofType(Coding).code.select($this.split('-').last().toInteger()).aggregate($this + $total, 0))<span style="color: navy">)</span> <i>&quot;mustTotalValue&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;mustTotalRule&quot;</i><span style="color: navy">;</span>
      gM.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'must.bmi') and answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span>obsM.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">'https://fhir.slade360.co.ke/fhir/CodeSystem/inpatient-clinical-concept-codesystem'</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">'must-bmi-score'</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">'BMI score (MUST)'</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;bmiCode&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;bmiValue&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;mustBmiRule&quot;</i><span style="color: navy">;</span>
      gM.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'must.loss') and answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span>obsM.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">'https://fhir.slade360.co.ke/fhir/CodeSystem/inpatient-clinical-concept-codesystem'</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">'must-weight-loss-score'</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">'Unplanned weight loss score (MUST)'</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;lossCode&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;lossValue&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;mustLossRule&quot;</i><span style="color: navy">;</span>
      gM.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'must.acute') and answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span>obsM.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">'https://fhir.slade360.co.ke/fhir/CodeSystem/inpatient-clinical-concept-codesystem'</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">'must-acute-disease-score'</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">'Acute disease effect score (MUST)'</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;acuteCode&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;acuteValue&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;mustAcuteRule&quot;</i><span style="color: navy">;</span>
      qr<span style="color: navy"><b> -&gt; </b></span> obsM<span style="color: navy">, </span> bundle<b> then </b>AddMustRiskAssessment<span style="color: navy">(</span><span style="color: maroon">obsM</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;mustBand&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">// </span><span style="color: green">BAPEN's management guidance for a MUST of 2 or more is to refer to a</span>
      <span style="color: navy">// </span><span style="color: green">dietitian, so a high-risk score raises the referral rather than leaving</span>
      <span style="color: navy">// </span><span style="color: green">it to be remembered. Draft and proposal: it needs a signature.</span>
      qr<span style="color: navy"><b> -&gt; </b></span> obsM<span style="color: navy">, </span> bundle<b> then </b>AddDietitianReferral<span style="color: navy">(</span><span style="color: maroon">obsM</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;dietitianReferral&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;mustObservation&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">}</span> <i>&quot;mustRule&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">// </span><span style="color: green">── Nutritional plan ───────────────────────────────────────────────────────</span>
  qr.item<b> as </b><span style="color: maroon">itP</span><b> where </b><span style="color: navy">(</span>(linkId = 'plan') and answer.value.exists()<span style="color: navy">)</span><b> then</b><span style="color: navy"> {
</span>    itP.answer first<b> as </b><span style="color: maroon">aP</span><b> then</b><span style="color: navy"> {
</span>      aP<span style="color: navy"><b> -&gt; </b></span> bundle.entry<b> as </b><span style="color: maroon">entryC</span><span style="color: navy">, </span> entryC.resource = <b>create</b><span style="color: navy">(</span><span style="color: blue">'CarePlan'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">plan</span><b> then</b><span style="color: navy"> {
</span>        qr<span style="color: navy"><b> -&gt; </b></span>plan<b> then </b>CopyResponseTags<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">plan</span><span style="color: navy">)</span> <i>&quot;responseTags&quot;</i><span style="color: navy">;</span>
        qr<span style="color: navy"><b> -&gt; </b></span>plan.id = <b>uuid</b><span style="color: navy">(</span><span style="color: navy">)</span><b> then </b>SetCarePlanFullUrl<span style="color: navy">(</span><span style="color: maroon">plan</span><span style="color: navy">, </span><span style="color: maroon">entryC</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>entryC.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">'CarePlan'</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>plan.status = <span style="color: blue">'active'</span> <i>&quot;status&quot;</i><span style="color: navy">;</span>
        qr<span style="color: navy"><b> -&gt; </b></span>plan.intent = <span style="color: blue">'plan'</span> <i>&quot;intent&quot;</i><span style="color: navy">;</span>
        qr<span style="color: navy"><b> -&gt; </b></span>plan.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">'https://fhir.slade360.co.ke/fhir/CodeSystem/inpatient-clinical-concept-codesystem'</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">'nutrition-care-plan'</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">'Nutritional plan'</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>
        qr<span style="color: navy"><b> -&gt; </b></span>plan.title = <span style="color: blue">'Nutritional plan'</span> <i>&quot;title&quot;</i><span style="color: navy">;</span>
        aP.value<b> as </b><span style="color: maroon">v</span><span style="color: navy"><b> -&gt; </b></span>plan.description = <span style="color: maroon">v</span> <i>&quot;description&quot;</i><span style="color: navy">;</span>
        qr.subject<b> as </b><span style="color: maroon">s</span><b> where </b><span style="color: navy">(</span>(reference.exists() and (reference.startsWith('Patient/'))) or (reference.empty() and (type.empty() or ('/' + type).endsWith('/Patient')))<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span>plan.subject = <span style="color: maroon">s</span><span style="color: navy">;</span>
        qr.encounter<b> as </b><span style="color: maroon">e</span><b> where </b><span style="color: navy">(</span>(reference.exists() and (reference.startsWith('Encounter/'))) or (reference.empty() and (type.empty() or ('/' + type).endsWith('/Encounter')))<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span>plan.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>plan.created = <span style="color: maroon">t</span> <i>&quot;created&quot;</i><span style="color: navy">;</span>
        qr.author<b> as </b><span style="color: maroon">a</span><b> where </b><span style="color: navy">(</span>(reference.exists() and (reference.startsWith('Patient/') or reference.startsWith('Practitioner/') or reference.startsWith('PractitionerRole/') or reference.startsWith('Device/') or reference.startsWith('RelatedPerson/') or reference.startsWith('Organization/') or reference.startsWith('CareTeam/'))) or (reference.empty() and (type.empty() or ('/' + type).endsWith('/Patient') or ('/' + type).endsWith('/Practitioner') or ('/' + type).endsWith('/PractitionerRole') or ('/' + type).endsWith('/Device') or ('/' + type).endsWith('/RelatedPerson') or ('/' + type).endsWith('/Organization') or ('/' + type).endsWith('/CareTeam')))<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span>plan.contributor = <span style="color: maroon">a</span> <i>&quot;contributorFromAuthor&quot;</i><span style="color: navy">;</span>
        qr<b> where </b><span style="color: navy">(</span>author.where(((reference.exists() and (reference.startsWith('Patient/') or reference.startsWith('Practitioner/') or reference.startsWith('PractitionerRole/') or reference.startsWith('Device/') or reference.startsWith('RelatedPerson/') or reference.startsWith('Organization/') or reference.startsWith('CareTeam/'))) or (reference.empty() and (type.empty() or ('/' + type).endsWith('/Patient') or ('/' + type).endsWith('/Practitioner') or ('/' + type).endsWith('/PractitionerRole') or ('/' + type).endsWith('/Device') or ('/' + type).endsWith('/RelatedPerson') or ('/' + type).endsWith('/Organization') or ('/' + type).endsWith('/CareTeam'))))).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><b> where </b><span style="color: navy">(</span>(reference.exists() and (reference.startsWith('Patient/') or reference.startsWith('Practitioner/') or reference.startsWith('PractitionerRole/') or reference.startsWith('Device/') or reference.startsWith('RelatedPerson/') or reference.startsWith('Organization/') or reference.startsWith('CareTeam/'))) or (reference.empty() and (type.empty() or ('/' + type).endsWith('/Patient') or ('/' + type).endsWith('/Practitioner') or ('/' + type).endsWith('/PractitionerRole') or ('/' + type).endsWith('/Device') or ('/' + type).endsWith('/RelatedPerson') or ('/' + type).endsWith('/Organization') or ('/' + type).endsWith('/CareTeam')))<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span>plan.contributor = <span style="color: maroon">src</span> <i>&quot;contributorFromSource&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;contributorFallback&quot;</i><span style="color: navy">;</span>
        qr<span style="color: navy"><b> -&gt; </b></span>plan.supportingInfo = <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><b> then</b><span style="color: navy"> {
</span>          qr.id<b> as </b><span style="color: maroon">qid</span><span style="color: navy"><b> -&gt; </b></span>ref.reference = <span style="color: maroon">qid</span> <i>&quot;supportingInfoRef&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;linkQuestionnaireResponse&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;carePlan&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;planAnswer&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">}</span> <i>&quot;planRule&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">MUST bands (BAPEN): 0 low risk, 1 medium risk, 2 or more high risk.</span>
<span style="color: navy">// </span><span style="color: green">─────────────────────────────────────────────────────────────────────────────</span>
<b>group </b>AddMustRiskAssessment<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) = 0<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<b> then </b>CopyResponseTags<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;responseTags&quot;</i><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>SetMustRiskCode<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;riskCoding&quot;</i><span style="color: navy">;</span>
        qr<span style="color: navy"><b> -&gt; </b></span>risk.text = <span style="color: blue">'Low 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;mustLow&quot;</i><span style="color: navy">;</span>
  obs<b> where </b><span style="color: navy">(</span>value.ofType(integer) = 1<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<b> then </b>CopyResponseTags<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;responseTags&quot;</i><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>SetMustRiskCode<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;riskCoding&quot;</i><span style="color: navy">;</span>
        qr<span style="color: navy"><b> -&gt; </b></span>risk.text = <span style="color: blue">'Medium 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;mustMedium&quot;</i><span style="color: navy">;</span>
  obs<b> where </b><span style="color: navy">(</span>value.ofType(integer) &gt;= 2<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<b> then </b>CopyResponseTags<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;responseTags&quot;</i><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>SetMustRiskCode<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;riskCoding&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;mustHigh&quot;</i><span style="color: navy">;</span>
<span style="color: navy">}

</span><b>group </b>SetMustRiskCode<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">'101807-6'</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">'Malnutrition risk screen results indicator'</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><b>group </b>AddDietitianReferral<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) &gt;= 2<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">'ServiceRequest'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">sr</span><b> then</b><span style="color: navy"> {
</span>    qr<span style="color: navy"><b> -&gt; </b></span>sr<b> then </b>CopyResponseTags<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">sr</span><span style="color: navy">)</span> <i>&quot;responseTags&quot;</i><span style="color: navy">;</span>
    qr<span style="color: navy"><b> -&gt; </b></span>sr.id = <b>uuid</b><span style="color: navy">(</span><span style="color: navy">)</span><b> then </b>SetServiceRequestFullUrl<span style="color: navy">(</span><span style="color: maroon">sr</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">'ServiceRequest'</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>sr.status = <span style="color: blue">'draft'</span> <i>&quot;status&quot;</i><span style="color: navy">;</span>
    qr<span style="color: navy"><b> -&gt; </b></span>sr.intent = <span style="color: blue">'proposal'</span> <i>&quot;intent&quot;</i><span style="color: navy">;</span>
    qr<span style="color: navy"><b> -&gt; </b></span>sr.priority = <span style="color: blue">'routine'</span> <i>&quot;priority&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">// </span><span style="color: green">R5 ServiceRequest.code is a CodeableReference, so the concept sits one</span>
    <span style="color: navy">// </span><span style="color: green">level down.</span>
    qr<span style="color: navy"><b> -&gt; </b></span>sr.code<b> as </b><span style="color: maroon">codeRef</span><b> then</b><span style="color: navy"> {
</span>      qr<span style="color: navy"><b> -&gt; </b></span>codeRef.concept<b> as </b><span style="color: maroon">concept</span><b> then</b><span style="color: navy"> {
</span>        qr<span style="color: navy"><b> -&gt; </b></span>concept.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">'https://fhir.slade360.co.ke/fhir/CodeSystem/inpatient-clinical-concept-codesystem'</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">'dietitian-referral'</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">'Referral to a dietitian'</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>
        qr<span style="color: navy"><b> -&gt; </b></span>concept.text = <span style="color: blue">'Referral to a dietitian'</span> <i>&quot;codeText&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;codeConcept&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;serviceRequestCode&quot;</i><span style="color: navy">;</span>
    qr<span style="color: navy"><b> -&gt; </b></span>sr.performerType<b> as </b><span style="color: maroon">pt</span><b> then</b><span style="color: navy"> {
</span>      qr<span style="color: navy"><b> -&gt; </b></span>pt.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">'https://fhir.slade360.co.ke/fhir/CodeSystem/practitioner-specialty-codesystem'</span> <i>&quot;performerTypeSystem&quot;</i><span style="color: navy">;</span>
        qr<span style="color: navy"><b> -&gt; </b></span>coding.code = <span style="color: blue">'nutritionist'</span> <i>&quot;performerTypeCode&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;performerTypeCoding&quot;</i><span style="color: navy">;</span>
      qr<span style="color: navy"><b> -&gt; </b></span>pt.text = <span style="color: blue">'Nutritionist'</span> <i>&quot;performerTypeText&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;performerType&quot;</i><span style="color: navy">;</span>
    qr.subject<b> as </b><span style="color: maroon">s</span><b> where </b><span style="color: navy">(</span>(reference.exists() and (reference.startsWith('Patient/'))) or (reference.empty() and (type.empty() or ('/' + type).endsWith('/Patient')))<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span>sr.subject = <span style="color: maroon">s</span><span style="color: navy">;</span>
    qr.encounter<b> as </b><span style="color: maroon">e</span><b> where </b><span style="color: navy">(</span>(reference.exists() and (reference.startsWith('Encounter/'))) or (reference.empty() and (type.empty() or ('/' + type).endsWith('/Encounter')))<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span>sr.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>sr.authoredOn = <span style="color: maroon">t</span> <i>&quot;authoredOn&quot;</i><span style="color: navy">;</span>
    qr.author<b> as </b><span style="color: maroon">a</span><b> where </b><span style="color: navy">(</span>(reference.exists() and (reference.startsWith('Organization/') or reference.startsWith('Patient/'))) or (reference.empty() and (type.empty() or ('/' + type).endsWith('/Organization') or ('/' + type).endsWith('/Patient')))<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span>sr.requester = <span style="color: maroon">a</span> <i>&quot;requesterFromAuthor&quot;</i><span style="color: navy">;</span>
    qr<b> where </b><span style="color: navy">(</span>author.where(((reference.exists() and (reference.startsWith('Organization/') or reference.startsWith('Patient/'))) or (reference.empty() and (type.empty() or ('/' + type).endsWith('/Organization') or ('/' + type).endsWith('/Patient'))))).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><b> where </b><span style="color: navy">(</span>(reference.exists() and (reference.startsWith('Organization/') or reference.startsWith('Patient/'))) or (reference.empty() and (type.empty() or ('/' + type).endsWith('/Organization') or ('/' + type).endsWith('/Patient')))<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span>sr.requester = <span style="color: maroon">src</span> <i>&quot;requesterFromSource&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;requesterFallback&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">// </span><span style="color: green">Why this referral exists: the score that triggered it.</span>
    obs.id<b> as </b><span style="color: maroon">oid</span><span style="color: navy"><b> -&gt; </b></span>sr.reason<b> as </b><span style="color: maroon">reason</span><b> then</b><span style="color: navy"> {
</span>      oid<span style="color: navy"><b> -&gt; </b></span>reason.reference = <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><b> then</b><span style="color: navy"> {
</span>        oid<span style="color: navy"><b> -&gt; </b></span>ref.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;reasonRef&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;reasonTarget&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;reason&quot;</i><span style="color: navy">;</span>
    qr<span style="color: navy"><b> -&gt; </b></span>sr.supportingInfo<b> as </b><span style="color: maroon">si</span><b> then</b><span style="color: navy"> {
</span>      qr<span style="color: navy"><b> -&gt; </b></span>si.reference = <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><b> then</b><span style="color: navy"> {
</span>        qr.id<b> as </b><span style="color: maroon">qid</span><span style="color: navy"><b> -&gt; </b></span>ref.reference = <span style="color: maroon">qid</span> <i>&quot;supportingInfoRef&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;supportingInfoTarget&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;linkQuestionnaireResponse&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">}</span> <i>&quot;dietitianReferral&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><b> where </b><span style="color: navy">(</span>(reference.exists() and (reference.startsWith('Patient/'))) or (reference.empty() and (type.empty() or ('/' + type).endsWith('/Patient')))<span style="color: navy">)</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><b> where </b><span style="color: navy">(</span>(reference.exists() and (reference.startsWith('Encounter/'))) or (reference.empty() and (type.empty() or ('/' + type).endsWith('/Encounter')))<span style="color: navy">)</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><b> where </b><span style="color: navy">(</span>(reference.exists() and (reference.startsWith('Organization/') or reference.startsWith('Patient/'))) or (reference.empty() and (type.empty() or ('/' + type).endsWith('/Organization') or ('/' + type).endsWith('/Patient')))<span style="color: navy">)</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.where(((reference.exists() and (reference.startsWith('Organization/') or reference.startsWith('Patient/'))) or (reference.empty() and (type.empty() or ('/' + type).endsWith('/Organization') or ('/' + type).endsWith('/Patient'))))).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><b> where </b><span style="color: navy">(</span>(reference.exists() and (reference.startsWith('Organization/') or reference.startsWith('Patient/'))) or (reference.empty() and (type.empty() or ('/' + type).endsWith('/Organization') or ('/' + type).endsWith('/Patient')))<span style="color: navy">)</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>
  qr<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><b> then</b><span style="color: navy"> {
</span>    qr.id<b> as </b><span style="color: maroon">qid</span><span style="color: navy"><b> -&gt; </b></span>ref.reference = <span style="color: maroon">qid</span> <i>&quot;derivedFromRef&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">}</span> <i>&quot;linkQuestionnaireResponse&quot;</i><span style="color: navy">;</span>
<span style="color: navy">}

</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><b> where </b><span style="color: navy">(</span>(reference.exists() and (reference.startsWith('Patient/'))) or (reference.empty() and (type.empty() or ('/' + type).endsWith('/Patient')))<span style="color: navy">)</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><b> where </b><span style="color: navy">(</span>(reference.exists() and (reference.startsWith('Encounter/'))) or (reference.empty() and (type.empty() or ('/' + type).endsWith('/Encounter')))<span style="color: navy">)</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><b> where </b><span style="color: navy">(</span>(reference.exists() and (reference.startsWith('Patient/') or reference.startsWith('Practitioner/'))) or (reference.empty() and (type.empty() or ('/' + type).endsWith('/Patient') or ('/' + type).endsWith('/Practitioner')))<span style="color: navy">)</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.where(((reference.exists() and (reference.startsWith('Patient/') or reference.startsWith('Practitioner/'))) or (reference.empty() and (type.empty() or ('/' + type).endsWith('/Patient') or ('/' + type).endsWith('/Practitioner'))))).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><b> where </b><span style="color: navy">(</span>(reference.exists() and (reference.startsWith('Patient/') or reference.startsWith('Practitioner/'))) or (reference.empty() and (type.empty() or ('/' + type).endsWith('/Patient') or ('/' + type).endsWith('/Practitioner')))<span style="color: navy">)</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<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><b> then</b><span style="color: navy"> {
</span>    qr.id<b> as </b><span style="color: maroon">qid</span><span style="color: navy"><b> -&gt; </b></span>qref.reference = <span style="color: maroon">qid</span> <i>&quot;basisQuestionnaireResponse&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">}</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><b>group </b>SetCarePlanFullUrl<span style="color: navy">(</span><b>source</b> <span style="color: maroon">plan</span><span style="color: navy"> : </span>CarePlan, <b>target</b> <span style="color: maroon">entry</span><span style="color: navy">)</span><span style="color: navy"> {
</span>  plan.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/CarePlan/'</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>SetServiceRequestFullUrl<span style="color: navy">(</span><b>source</b> <span style="color: maroon">sr</span><span style="color: navy"> : </span>ServiceRequest, <b>target</b> <span style="color: maroon">entry</span><span style="color: navy">)</span><span style="color: navy"> {
</span>  sr.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/ServiceRequest/'</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><span style="color: navy">// </span><span style="color: green">── Tenancy ──────────────────────────────────────────────────────────────────</span>
<span style="color: navy">// </span><span style="color: green">Whose this is. The platform says which tenant a response belongs to with a</span>
<span style="color: navy">// </span><span style="color: green">tag on the response, and every tag the response carries is copied onto</span>
<span style="color: navy">// </span><span style="color: green">everything this map creates, as it is. Copied rather than named here, so the</span>
<span style="color: navy">// </span><span style="color: green">map never has to know which tenant it is running for, nor which system the</span>
<span style="color: navy">// </span><span style="color: green">tag is under: that system has moved more than once.</span>
<b>group </b>CopyResponseTags<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">r</span><span style="color: navy">)</span><span style="color: navy"> {
</span>  qr.meta<b> as </b><span style="color: maroon">qm</span><b> then</b><span style="color: navy"> {
</span>    qm.tag<b> as </b><span style="color: maroon">qt</span><span style="color: navy"><b> -&gt; </b></span> r.meta<b> as </b><span style="color: maroon">m</span><span style="color: navy">, </span> m.tag = <span style="color: maroon">qt</span> <i>&quot;copyTag&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">}</span> <i>&quot;tenantTags&quot;</i><span style="color: navy">;</span>
<span style="color: navy">}

</span></pre></div>
  </text>
  <url
       value="https://fhir.slade360.co.ke/fhir/StructureMap/ExtractInpatientNutritionScreening"/>
  <version value="0.1.0"/>
  <name value="ExtractInpatientNutritionScreening"/>
  <title value="Inpatient Nutrition Screening (MUST) Extraction"/>
  <status value="active"/>
  <date value="2026-10-06T18:48:22+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 MUST score becomes one Observation carrying the total with its three steps as components, plus a RiskAssessment for the band. The nutritional plan becomes a CarePlan, and a score in the high-risk band raises a dietitian referral. That referral is intent `proposal` and status `draft` deliberately: a map should not put an active order in a dietitian's queue on its own, so it arrives as something a clinician signs."/>
  <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>
  <structure>
    <url value="http://hl7.org/fhir/StructureDefinition/CarePlan"/>
    <mode value="target"/>
    <alias value="CarePlan"/>
  </structure>
  <structure>
    <url value="http://hl7.org/fhir/StructureDefinition/ServiceRequest"/>
    <mode value="target"/>
    <alias value="ServiceRequest"/>
  </structure>
  <group>
    <name value="ExtractInpatientNutritionScreening"/>
    <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="mustRule"/>
      <source>
        <context value="qr"/>
        <element value="item"/>
        <variable value="gM"/>
        <condition
                   value="(linkId = 'must') and item.answer.value.ofType(Coding).exists()"/>
      </source>
      <rule>
        <name value="mustObservation"/>
        <source>
          <context value="gM"/>
        </source>
        <target>
          <context value="bundle"/>
          <element value="entry"/>
          <variable value="entryM"/>
        </target>
        <target>
          <context value="entryM"/>
          <element value="resource"/>
          <variable value="obsM"/>
          <transform value="create"/>
          <parameter>
            <valueString value="Observation"/>
          </parameter>
        </target>
        <rule>
          <name value="responseTags"/>
          <source>
            <context value="qr"/>
          </source>
          <target>
            <context value="obsM"/>
          </target>
          <dependent>
            <name value="CopyResponseTags"/>
            <parameter>
              <valueId value="qr"/>
            </parameter>
            <parameter>
              <valueId value="obsM"/>
            </parameter>
          </dependent>
        </rule>
        <rule>
          <name value="mustBase"/>
          <source>
            <context value="qr"/>
          </source>
          <target>
            <context value="obsM"/>
          </target>
          <target>
            <context value="entryM"/>
          </target>
          <dependent>
            <name value="BuildObsBase"/>
            <parameter>
              <valueId value="qr"/>
            </parameter>
            <parameter>
              <valueId value="obsM"/>
            </parameter>
            <parameter>
              <valueId value="entryM"/>
            </parameter>
          </dependent>
        </rule>
        <rule>
          <name value="mustCategory"/>
          <source>
            <context value="qr"/>
          </source>
          <target>
            <context value="obsM"/>
          </target>
          <dependent>
            <name value="SetSurveyCategory"/>
            <parameter>
              <valueId value="qr"/>
            </parameter>
            <parameter>
              <valueId value="obsM"/>
            </parameter>
          </dependent>
        </rule>
        <rule>
          <name value="mustCode"/>
          <source>
            <context value="qr"/>
          </source>
          <target>
            <context value="obsM"/>
            <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="101789-6"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="codeDisplay"/>
              <source>
                <context value="qr"/>
              </source>
              <target>
                <context value="coding"/>
                <element value="display"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="Malnutrition risk screening"/>
                </parameter>
              </target>
            </rule>
          </rule>
          <rule>
            <name value="codeText"/>
            <source>
              <context value="qr"/>
            </source>
            <target>
              <context value="code"/>
              <element value="text"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="MUST score"/>
              </parameter>
            </target>
          </rule>
        </rule>
        <rule>
          <name value="mustTotalRule"/>
          <source>
            <context value="gM"/>
            <condition value="item.answer.value.ofType(Coding).count() = 3"/>
          </source>
          <rule>
            <name value="mustTotalValue"/>
            <source>
              <context value="gM"/>
            </source>
            <target>
              <context value="obsM"/>
              <element value="value"/>
              <transform value="evaluate"/>
              <parameter>
                <valueId value="gM"/>
              </parameter>
              <parameter>
                <valueString
                             value="iif(item.where(linkId = 'must.total').answer.value.exists(), item.where(linkId = 'must.total').answer.value, item.answer.value.ofType(Coding).code.select($this.split('-').last().toInteger()).aggregate($this + $total, 0))"/>
              </parameter>
            </target>
          </rule>
          <documentation
                         value="The submitted total wins; otherwise sum the answers, reading each
weight off the tail of its code (must-loss-2 is worth 2). Guarded on
all three steps being answered -- MUST is a sum of three, and a sum of
two banded as low risk would send a wasting patient home."/>
        </rule>
        <rule>
          <name value="mustBmiRule"/>
          <source>
            <context value="gM"/>
            <element value="item"/>
            <variable value="it"/>
            <condition
                       value="(linkId = 'must.bmi') and answer.value.exists()"/>
          </source>
          <target>
            <context value="obsM"/>
            <element value="component"/>
            <variable value="comp"/>
          </target>
          <rule>
            <name value="bmiCode"/>
            <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="https://fhir.slade360.co.ke/fhir/CodeSystem/inpatient-clinical-concept-codesystem"/>
                  </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="must-bmi-score"/>
                  </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="BMI score (MUST)"/>
                  </parameter>
                </target>
              </rule>
            </rule>
          </rule>
          <rule>
            <name value="bmiValue"/>
            <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="mustLossRule"/>
          <source>
            <context value="gM"/>
            <element value="item"/>
            <variable value="it"/>
            <condition
                       value="(linkId = 'must.loss') and answer.value.exists()"/>
          </source>
          <target>
            <context value="obsM"/>
            <element value="component"/>
            <variable value="comp"/>
          </target>
          <rule>
            <name value="lossCode"/>
            <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="https://fhir.slade360.co.ke/fhir/CodeSystem/inpatient-clinical-concept-codesystem"/>
                  </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="must-weight-loss-score"/>
                  </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="Unplanned weight loss score (MUST)"/>
                  </parameter>
                </target>
              </rule>
            </rule>
          </rule>
          <rule>
            <name value="lossValue"/>
            <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="mustAcuteRule"/>
          <source>
            <context value="gM"/>
            <element value="item"/>
            <variable value="it"/>
            <condition
                       value="(linkId = 'must.acute') and answer.value.exists()"/>
          </source>
          <target>
            <context value="obsM"/>
            <element value="component"/>
            <variable value="comp"/>
          </target>
          <rule>
            <name value="acuteCode"/>
            <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="https://fhir.slade360.co.ke/fhir/CodeSystem/inpatient-clinical-concept-codesystem"/>
                  </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="must-acute-disease-score"/>
                  </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="Acute disease effect score (MUST)"/>
                  </parameter>
                </target>
              </rule>
            </rule>
          </rule>
          <rule>
            <name value="acuteValue"/>
            <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="mustBand"/>
          <source>
            <context value="qr"/>
          </source>
          <target>
            <context value="obsM"/>
          </target>
          <target>
            <context value="bundle"/>
          </target>
          <dependent>
            <name value="AddMustRiskAssessment"/>
            <parameter>
              <valueId value="obsM"/>
            </parameter>
            <parameter>
              <valueId value="qr"/>
            </parameter>
            <parameter>
              <valueId value="bundle"/>
            </parameter>
          </dependent>
        </rule>
        <rule>
          <name value="dietitianReferral"/>
          <source>
            <context value="qr"/>
          </source>
          <target>
            <context value="obsM"/>
          </target>
          <target>
            <context value="bundle"/>
          </target>
          <dependent>
            <name value="AddDietitianReferral"/>
            <parameter>
              <valueId value="obsM"/>
            </parameter>
            <parameter>
              <valueId value="qr"/>
            </parameter>
            <parameter>
              <valueId value="bundle"/>
            </parameter>
          </dependent>
          <documentation
                         value="BAPEN's management guidance for a MUST of 2 or more is to refer to a
dietitian, so a high-risk score raises the referral rather than leaving
it to be remembered. Draft and proposal: it needs a signature."/>
        </rule>
      </rule>
      <documentation
                     value="── MUST score ─────────────────────────────────────────────────────────────
LOINC has 101789-6 for the screening itself and 101807-6 for its result
indicator, but nothing for the three steps, so those carry local codes."/>
    </rule>
    <rule>
      <name value="planRule"/>
      <source>
        <context value="qr"/>
        <element value="item"/>
        <variable value="itP"/>
        <condition value="(linkId = 'plan') and answer.value.exists()"/>
      </source>
      <rule>
        <name value="planAnswer"/>
        <source>
          <context value="itP"/>
          <element value="answer"/>
          <listMode value="first"/>
          <variable value="aP"/>
        </source>
        <rule>
          <name value="carePlan"/>
          <source>
            <context value="aP"/>
          </source>
          <target>
            <context value="bundle"/>
            <element value="entry"/>
            <variable value="entryC"/>
          </target>
          <target>
            <context value="entryC"/>
            <element value="resource"/>
            <variable value="plan"/>
            <transform value="create"/>
            <parameter>
              <valueString value="CarePlan"/>
            </parameter>
          </target>
          <rule>
            <name value="responseTags"/>
            <source>
              <context value="qr"/>
            </source>
            <target>
              <context value="plan"/>
            </target>
            <dependent>
              <name value="CopyResponseTags"/>
              <parameter>
                <valueId value="qr"/>
              </parameter>
              <parameter>
                <valueId value="plan"/>
              </parameter>
            </dependent>
          </rule>
          <rule>
            <name value="idAndFullUrl"/>
            <source>
              <context value="qr"/>
            </source>
            <target>
              <context value="plan"/>
              <element value="id"/>
              <transform value="uuid"/>
            </target>
            <dependent>
              <name value="SetCarePlanFullUrl"/>
              <parameter>
                <valueId value="plan"/>
              </parameter>
              <parameter>
                <valueId value="entryC"/>
              </parameter>
            </dependent>
          </rule>
          <rule>
            <name value="entryRequest"/>
            <source>
              <context value="qr"/>
            </source>
            <target>
              <context value="entryC"/>
              <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="CarePlan"/>
                </parameter>
              </target>
            </rule>
          </rule>
          <rule>
            <name value="status"/>
            <source>
              <context value="qr"/>
            </source>
            <target>
              <context value="plan"/>
              <element value="status"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="active"/>
              </parameter>
            </target>
          </rule>
          <rule>
            <name value="intent"/>
            <source>
              <context value="qr"/>
            </source>
            <target>
              <context value="plan"/>
              <element value="intent"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="plan"/>
              </parameter>
            </target>
          </rule>
          <rule>
            <name value="category"/>
            <source>
              <context value="qr"/>
            </source>
            <target>
              <context value="plan"/>
              <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="https://fhir.slade360.co.ke/fhir/CodeSystem/inpatient-clinical-concept-codesystem"/>
                  </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="nutrition-care-plan"/>
                  </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="Nutritional plan"/>
                  </parameter>
                </target>
              </rule>
            </rule>
          </rule>
          <rule>
            <name value="title"/>
            <source>
              <context value="qr"/>
            </source>
            <target>
              <context value="plan"/>
              <element value="title"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="Nutritional plan"/>
              </parameter>
            </target>
          </rule>
          <rule>
            <name value="description"/>
            <source>
              <context value="aP"/>
              <element value="value"/>
              <variable value="v"/>
            </source>
            <target>
              <context value="plan"/>
              <element value="description"/>
              <transform value="copy"/>
              <parameter>
                <valueId value="v"/>
              </parameter>
            </target>
          </rule>
          <rule>
            <name value="subject"/>
            <source>
              <context value="qr"/>
              <element value="subject"/>
              <variable value="s"/>
              <condition
                         value="(reference.exists() and (reference.startsWith('Patient/'))) or (reference.empty() and (type.empty() or ('/' + type).endsWith('/Patient')))"/>
            </source>
            <target>
              <context value="plan"/>
              <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"/>
              <condition
                         value="(reference.exists() and (reference.startsWith('Encounter/'))) or (reference.empty() and (type.empty() or ('/' + type).endsWith('/Encounter')))"/>
            </source>
            <target>
              <context value="plan"/>
              <element value="encounter"/>
              <transform value="copy"/>
              <parameter>
                <valueId value="e"/>
              </parameter>
            </target>
          </rule>
          <rule>
            <name value="created"/>
            <source>
              <context value="qr"/>
              <element value="authored"/>
              <variable value="t"/>
            </source>
            <target>
              <context value="plan"/>
              <element value="created"/>
              <transform value="copy"/>
              <parameter>
                <valueId value="t"/>
              </parameter>
            </target>
          </rule>
          <rule>
            <name value="contributorFromAuthor"/>
            <source>
              <context value="qr"/>
              <element value="author"/>
              <variable value="a"/>
              <condition
                         value="(reference.exists() and (reference.startsWith('Patient/') or reference.startsWith('Practitioner/') or reference.startsWith('PractitionerRole/') or reference.startsWith('Device/') or reference.startsWith('RelatedPerson/') or reference.startsWith('Organization/') or reference.startsWith('CareTeam/'))) or (reference.empty() and (type.empty() or ('/' + type).endsWith('/Patient') or ('/' + type).endsWith('/Practitioner') or ('/' + type).endsWith('/PractitionerRole') or ('/' + type).endsWith('/Device') or ('/' + type).endsWith('/RelatedPerson') or ('/' + type).endsWith('/Organization') or ('/' + type).endsWith('/CareTeam')))"/>
            </source>
            <target>
              <context value="plan"/>
              <element value="contributor"/>
              <transform value="copy"/>
              <parameter>
                <valueId value="a"/>
              </parameter>
            </target>
          </rule>
          <rule>
            <name value="contributorFallback"/>
            <source>
              <context value="qr"/>
              <condition
                         value="author.where(((reference.exists() and (reference.startsWith('Patient/') or reference.startsWith('Practitioner/') or reference.startsWith('PractitionerRole/') or reference.startsWith('Device/') or reference.startsWith('RelatedPerson/') or reference.startsWith('Organization/') or reference.startsWith('CareTeam/'))) or (reference.empty() and (type.empty() or ('/' + type).endsWith('/Patient') or ('/' + type).endsWith('/Practitioner') or ('/' + type).endsWith('/PractitionerRole') or ('/' + type).endsWith('/Device') or ('/' + type).endsWith('/RelatedPerson') or ('/' + type).endsWith('/Organization') or ('/' + type).endsWith('/CareTeam'))))).exists().not()"/>
            </source>
            <rule>
              <name value="contributorFromSource"/>
              <source>
                <context value="qr"/>
                <element value="source"/>
                <variable value="src"/>
                <condition
                           value="(reference.exists() and (reference.startsWith('Patient/') or reference.startsWith('Practitioner/') or reference.startsWith('PractitionerRole/') or reference.startsWith('Device/') or reference.startsWith('RelatedPerson/') or reference.startsWith('Organization/') or reference.startsWith('CareTeam/'))) or (reference.empty() and (type.empty() or ('/' + type).endsWith('/Patient') or ('/' + type).endsWith('/Practitioner') or ('/' + type).endsWith('/PractitionerRole') or ('/' + type).endsWith('/Device') or ('/' + type).endsWith('/RelatedPerson') or ('/' + type).endsWith('/Organization') or ('/' + type).endsWith('/CareTeam')))"/>
              </source>
              <target>
                <context value="plan"/>
                <element value="contributor"/>
                <transform value="copy"/>
                <parameter>
                  <valueId value="src"/>
                </parameter>
              </target>
            </rule>
          </rule>
          <rule>
            <name value="linkQuestionnaireResponse"/>
            <source>
              <context value="qr"/>
            </source>
            <target>
              <context value="plan"/>
              <element value="supportingInfo"/>
              <variable value="ref"/>
              <transform value="create"/>
              <parameter>
                <valueString value="Reference"/>
              </parameter>
            </target>
            <rule>
              <name value="supportingInfoRef"/>
              <source>
                <context value="qr"/>
                <element value="id"/>
                <variable value="qid"/>
              </source>
              <target>
                <context value="ref"/>
                <element value="reference"/>
                <transform value="copy"/>
                <parameter>
                  <valueId value="qid"/>
                </parameter>
              </target>
            </rule>
          </rule>
        </rule>
      </rule>
      <documentation
                     value="── Nutritional plan ───────────────────────────────────────────────────────"/>
    </rule>
  </group>
  <group>
    <name value="AddMustRiskAssessment"/>
    <documentation
                   value="─────────────────────────────────────────────────────────────────────────────
MUST bands (BAPEN): 0 low risk, 1 medium risk, 2 or more high risk.
─────────────────────────────────────────────────────────────────────────────"/>
    <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="mustLow"/>
      <source>
        <context value="obs"/>
        <condition value="value.ofType(integer) = 0"/>
      </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="responseTags"/>
        <source>
          <context value="qr"/>
        </source>
        <target>
          <context value="ra"/>
        </target>
        <dependent>
          <name value="CopyResponseTags"/>
          <parameter>
            <valueId value="qr"/>
          </parameter>
          <parameter>
            <valueId value="ra"/>
          </parameter>
        </dependent>
      </rule>
      <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="SetMustRiskCode"/>
          <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="riskCoding"/>
            <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="riskText"/>
            <source>
              <context value="qr"/>
            </source>
            <target>
              <context value="risk"/>
              <element value="text"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="Low risk"/>
              </parameter>
            </target>
          </rule>
        </rule>
      </rule>
    </rule>
    <rule>
      <name value="mustMedium"/>
      <source>
        <context value="obs"/>
        <condition value="value.ofType(integer) = 1"/>
      </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="responseTags"/>
        <source>
          <context value="qr"/>
        </source>
        <target>
          <context value="ra"/>
        </target>
        <dependent>
          <name value="CopyResponseTags"/>
          <parameter>
            <valueId value="qr"/>
          </parameter>
          <parameter>
            <valueId value="ra"/>
          </parameter>
        </dependent>
      </rule>
      <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="SetMustRiskCode"/>
          <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="riskCoding"/>
            <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="riskText"/>
            <source>
              <context value="qr"/>
            </source>
            <target>
              <context value="risk"/>
              <element value="text"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="Medium risk"/>
              </parameter>
            </target>
          </rule>
        </rule>
      </rule>
    </rule>
    <rule>
      <name value="mustHigh"/>
      <source>
        <context value="obs"/>
        <condition value="value.ofType(integer) &gt;= 2"/>
      </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="responseTags"/>
        <source>
          <context value="qr"/>
        </source>
        <target>
          <context value="ra"/>
        </target>
        <dependent>
          <name value="CopyResponseTags"/>
          <parameter>
            <valueId value="qr"/>
          </parameter>
          <parameter>
            <valueId value="ra"/>
          </parameter>
        </dependent>
      </rule>
      <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="SetMustRiskCode"/>
          <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="riskCoding"/>
            <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="riskText"/>
            <source>
              <context value="qr"/>
            </source>
            <target>
              <context value="risk"/>
              <element value="text"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="High risk"/>
              </parameter>
            </target>
          </rule>
        </rule>
      </rule>
    </rule>
  </group>
  <group>
    <name value="SetMustRiskCode"/>
    <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="101807-6"/>
            </parameter>
          </target>
        </rule>
        <rule>
          <name value="codeDisplay"/>
          <source>
            <context value="qr"/>
          </source>
          <target>
            <context value="coding"/>
            <element value="display"/>
            <transform value="copy"/>
            <parameter>
              <valueString
                           value="Malnutrition risk screen results indicator"/>
            </parameter>
          </target>
        </rule>
      </rule>
    </rule>
  </group>
  <group>
    <name value="AddDietitianReferral"/>
    <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="dietitianReferral"/>
      <source>
        <context value="obs"/>
        <condition value="value.ofType(integer) &gt;= 2"/>
      </source>
      <target>
        <context value="bundle"/>
        <element value="entry"/>
        <variable value="entry"/>
      </target>
      <target>
        <context value="entry"/>
        <element value="resource"/>
        <variable value="sr"/>
        <transform value="create"/>
        <parameter>
          <valueString value="ServiceRequest"/>
        </parameter>
      </target>
      <rule>
        <name value="responseTags"/>
        <source>
          <context value="qr"/>
        </source>
        <target>
          <context value="sr"/>
        </target>
        <dependent>
          <name value="CopyResponseTags"/>
          <parameter>
            <valueId value="qr"/>
          </parameter>
          <parameter>
            <valueId value="sr"/>
          </parameter>
        </dependent>
      </rule>
      <rule>
        <name value="idAndFullUrl"/>
        <source>
          <context value="qr"/>
        </source>
        <target>
          <context value="sr"/>
          <element value="id"/>
          <transform value="uuid"/>
        </target>
        <dependent>
          <name value="SetServiceRequestFullUrl"/>
          <parameter>
            <valueId value="sr"/>
          </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="ServiceRequest"/>
            </parameter>
          </target>
        </rule>
      </rule>
      <rule>
        <name value="status"/>
        <source>
          <context value="qr"/>
        </source>
        <target>
          <context value="sr"/>
          <element value="status"/>
          <transform value="copy"/>
          <parameter>
            <valueString value="draft"/>
          </parameter>
        </target>
      </rule>
      <rule>
        <name value="intent"/>
        <source>
          <context value="qr"/>
        </source>
        <target>
          <context value="sr"/>
          <element value="intent"/>
          <transform value="copy"/>
          <parameter>
            <valueString value="proposal"/>
          </parameter>
        </target>
      </rule>
      <rule>
        <name value="priority"/>
        <source>
          <context value="qr"/>
        </source>
        <target>
          <context value="sr"/>
          <element value="priority"/>
          <transform value="copy"/>
          <parameter>
            <valueString value="routine"/>
          </parameter>
        </target>
      </rule>
      <rule>
        <name value="serviceRequestCode"/>
        <source>
          <context value="qr"/>
        </source>
        <target>
          <context value="sr"/>
          <element value="code"/>
          <variable value="codeRef"/>
        </target>
        <rule>
          <name value="codeConcept"/>
          <source>
            <context value="qr"/>
          </source>
          <target>
            <context value="codeRef"/>
            <element value="concept"/>
            <variable value="concept"/>
          </target>
          <rule>
            <name value="codeCoding"/>
            <source>
              <context value="qr"/>
            </source>
            <target>
              <context value="concept"/>
              <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="https://fhir.slade360.co.ke/fhir/CodeSystem/inpatient-clinical-concept-codesystem"/>
                </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="dietitian-referral"/>
                </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="Referral to a dietitian"/>
                </parameter>
              </target>
            </rule>
          </rule>
          <rule>
            <name value="codeText"/>
            <source>
              <context value="qr"/>
            </source>
            <target>
              <context value="concept"/>
              <element value="text"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="Referral to a dietitian"/>
              </parameter>
            </target>
          </rule>
        </rule>
        <documentation
                       value="R5 ServiceRequest.code is a CodeableReference, so the concept sits one
level down."/>
      </rule>
      <rule>
        <name value="performerType"/>
        <source>
          <context value="qr"/>
        </source>
        <target>
          <context value="sr"/>
          <element value="performerType"/>
          <variable value="pt"/>
        </target>
        <rule>
          <name value="performerTypeCoding"/>
          <source>
            <context value="qr"/>
          </source>
          <target>
            <context value="pt"/>
            <element value="coding"/>
            <variable value="coding"/>
          </target>
          <rule>
            <name value="performerTypeSystem"/>
            <source>
              <context value="qr"/>
            </source>
            <target>
              <context value="coding"/>
              <element value="system"/>
              <transform value="copy"/>
              <parameter>
                <valueString
                             value="https://fhir.slade360.co.ke/fhir/CodeSystem/practitioner-specialty-codesystem"/>
              </parameter>
            </target>
          </rule>
          <rule>
            <name value="performerTypeCode"/>
            <source>
              <context value="qr"/>
            </source>
            <target>
              <context value="coding"/>
              <element value="code"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="nutritionist"/>
              </parameter>
            </target>
          </rule>
        </rule>
        <rule>
          <name value="performerTypeText"/>
          <source>
            <context value="qr"/>
          </source>
          <target>
            <context value="pt"/>
            <element value="text"/>
            <transform value="copy"/>
            <parameter>
              <valueString value="Nutritionist"/>
            </parameter>
          </target>
        </rule>
      </rule>
      <rule>
        <name value="subject"/>
        <source>
          <context value="qr"/>
          <element value="subject"/>
          <variable value="s"/>
          <condition
                     value="(reference.exists() and (reference.startsWith('Patient/'))) or (reference.empty() and (type.empty() or ('/' + type).endsWith('/Patient')))"/>
        </source>
        <target>
          <context value="sr"/>
          <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"/>
          <condition
                     value="(reference.exists() and (reference.startsWith('Encounter/'))) or (reference.empty() and (type.empty() or ('/' + type).endsWith('/Encounter')))"/>
        </source>
        <target>
          <context value="sr"/>
          <element value="encounter"/>
          <transform value="copy"/>
          <parameter>
            <valueId value="e"/>
          </parameter>
        </target>
      </rule>
      <rule>
        <name value="authoredOn"/>
        <source>
          <context value="qr"/>
          <element value="authored"/>
          <variable value="t"/>
        </source>
        <target>
          <context value="sr"/>
          <element value="authoredOn"/>
          <transform value="copy"/>
          <parameter>
            <valueId value="t"/>
          </parameter>
        </target>
      </rule>
      <rule>
        <name value="requesterFromAuthor"/>
        <source>
          <context value="qr"/>
          <element value="author"/>
          <variable value="a"/>
          <condition
                     value="(reference.exists() and (reference.startsWith('Organization/') or reference.startsWith('Patient/'))) or (reference.empty() and (type.empty() or ('/' + type).endsWith('/Organization') or ('/' + type).endsWith('/Patient')))"/>
        </source>
        <target>
          <context value="sr"/>
          <element value="requester"/>
          <transform value="copy"/>
          <parameter>
            <valueId value="a"/>
          </parameter>
        </target>
      </rule>
      <rule>
        <name value="requesterFallback"/>
        <source>
          <context value="qr"/>
          <condition
                     value="author.where(((reference.exists() and (reference.startsWith('Organization/') or reference.startsWith('Patient/'))) or (reference.empty() and (type.empty() or ('/' + type).endsWith('/Organization') or ('/' + type).endsWith('/Patient'))))).exists().not()"/>
        </source>
        <rule>
          <name value="requesterFromSource"/>
          <source>
            <context value="qr"/>
            <element value="source"/>
            <variable value="src"/>
            <condition
                       value="(reference.exists() and (reference.startsWith('Organization/') or reference.startsWith('Patient/'))) or (reference.empty() and (type.empty() or ('/' + type).endsWith('/Organization') or ('/' + type).endsWith('/Patient')))"/>
          </source>
          <target>
            <context value="sr"/>
            <element value="requester"/>
            <transform value="copy"/>
            <parameter>
              <valueId value="src"/>
            </parameter>
          </target>
        </rule>
      </rule>
      <rule>
        <name value="reason"/>
        <source>
          <context value="obs"/>
          <element value="id"/>
          <variable value="oid"/>
        </source>
        <target>
          <context value="sr"/>
          <element value="reason"/>
          <variable value="reason"/>
        </target>
        <rule>
          <name value="reasonTarget"/>
          <source>
            <context value="oid"/>
          </source>
          <target>
            <context value="reason"/>
            <element value="reference"/>
            <variable value="ref"/>
            <transform value="create"/>
            <parameter>
              <valueString value="Reference"/>
            </parameter>
          </target>
          <rule>
            <name value="reasonRef"/>
            <source>
              <context value="oid"/>
            </source>
            <target>
              <context value="ref"/>
              <element value="reference"/>
              <transform value="append"/>
              <parameter>
                <valueString value="Observation/"/>
              </parameter>
              <parameter>
                <valueId value="oid"/>
              </parameter>
            </target>
          </rule>
        </rule>
        <documentation
                       value="Why this referral exists: the score that triggered it."/>
      </rule>
      <rule>
        <name value="linkQuestionnaireResponse"/>
        <source>
          <context value="qr"/>
        </source>
        <target>
          <context value="sr"/>
          <element value="supportingInfo"/>
          <variable value="si"/>
        </target>
        <rule>
          <name value="supportingInfoTarget"/>
          <source>
            <context value="qr"/>
          </source>
          <target>
            <context value="si"/>
            <element value="reference"/>
            <variable value="ref"/>
            <transform value="create"/>
            <parameter>
              <valueString value="Reference"/>
            </parameter>
          </target>
          <rule>
            <name value="supportingInfoRef"/>
            <source>
              <context value="qr"/>
              <element value="id"/>
              <variable value="qid"/>
            </source>
            <target>
              <context value="ref"/>
              <element value="reference"/>
              <transform value="copy"/>
              <parameter>
                <valueId value="qid"/>
              </parameter>
            </target>
          </rule>
        </rule>
      </rule>
    </rule>
  </group>
  <group>
    <name value="BuildObsBase"/>
    <documentation
                   value="─────────────────────────────────────────────────────────────────────────────
Shared scaffolding. Repeated in each map rather than imported: the transform
engine resolves `imports` against whatever StructureMaps happen to be on the
server, and a form that stops extracting because a shared map was not
uploaded is a worse failure than a duplicated group.
─────────────────────────────────────────────────────────────────────────────
Two notes on what the publisher's StructureMap validator says about this file.
Source parameters below are left untyped on purpose. Writing `: Element` makes
the validator compare QuestionnaireResponse.item against the literal 'Element'
and report them as incompatible with each other, which is noise, not a finding.
Untyped, it says only that it cannot check the paths.
`evaluate(context, expression)` is flagged as &quot;takes 1 parameter but 2 were
found&quot;. Leave it. The FML parser in the same jar refuses the one-argument form
outright -- it wants a parameter, a comma, then the FHIRPath -- so the publisher
is objecting to what its own compiler emits. Two arguments is the only form that
compiles, and it is what the R5 transform engine executes."/>
    <input>
      <name value="qr"/>
      <type value="QR"/>
      <mode value="source"/>
    </input>
    <input>
      <name value="obs"/>
      <type value="Observation"/>
      <mode value="target"/>
    </input>
    <input>
      <name value="entry"/>
      <mode value="target"/>
    </input>
    <rule>
      <name value="idAndFullUrl"/>
      <source>
        <context value="qr"/>
      </source>
      <target>
        <context value="obs"/>
        <element value="id"/>
        <transform value="uuid"/>
      </target>
      <dependent>
        <name value="SetObservationFullUrl"/>
        <parameter>
          <valueId value="obs"/>
        </parameter>
        <parameter>
          <valueId value="entry"/>
        </parameter>
      </dependent>
    </rule>
    <rule>
      <name value="entryRequest"/>
      <source>
        <context value="qr"/>
      </source>
      <target>
        <context value="entry"/>
        <element value="request"/>
        <variable value="request"/>
      </target>
      <rule>
        <name value="requestMethod"/>
        <source>
          <context value="qr"/>
        </source>
        <target>
          <context value="request"/>
          <element value="method"/>
          <transform value="copy"/>
          <parameter>
            <valueString value="POST"/>
          </parameter>
        </target>
      </rule>
      <rule>
        <name value="requestUrl"/>
        <source>
          <context value="qr"/>
        </source>
        <target>
          <context value="request"/>
          <element value="url"/>
          <transform value="copy"/>
          <parameter>
            <valueString value="Observation"/>
          </parameter>
        </target>
      </rule>
    </rule>
    <rule>
      <name value="status"/>
      <source>
        <context value="qr"/>
      </source>
      <target>
        <context value="obs"/>
        <element value="status"/>
        <transform value="copy"/>
        <parameter>
          <valueString value="final"/>
        </parameter>
      </target>
    </rule>
    <rule>
      <name value="subject"/>
      <source>
        <context value="qr"/>
        <element value="subject"/>
        <variable value="s"/>
        <condition
                   value="(reference.exists() and (reference.startsWith('Patient/'))) or (reference.empty() and (type.empty() or ('/' + type).endsWith('/Patient')))"/>
      </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"/>
        <condition
                   value="(reference.exists() and (reference.startsWith('Encounter/'))) or (reference.empty() and (type.empty() or ('/' + type).endsWith('/Encounter')))"/>
      </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"/>
        <condition
                   value="(reference.exists() and (reference.startsWith('Organization/') or reference.startsWith('Patient/'))) or (reference.empty() and (type.empty() or ('/' + type).endsWith('/Organization') or ('/' + type).endsWith('/Patient')))"/>
      </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.where(((reference.exists() and (reference.startsWith('Organization/') or reference.startsWith('Patient/'))) or (reference.empty() and (type.empty() or ('/' + type).endsWith('/Organization') or ('/' + type).endsWith('/Patient'))))).exists().not()"/>
      </source>
      <rule>
        <name value="performerFromAuthor"/>
        <source>
          <context value="qr"/>
          <element value="author"/>
          <variable value="a"/>
          <condition
                     value="(reference.exists() and (reference.startsWith('Organization/') or reference.startsWith('Patient/'))) or (reference.empty() and (type.empty() or ('/' + type).endsWith('/Organization') or ('/' + type).endsWith('/Patient')))"/>
        </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"/>
      </source>
      <target>
        <context value="obs"/>
        <element value="derivedFrom"/>
        <variable value="ref"/>
        <transform value="create"/>
        <parameter>
          <valueString value="Reference"/>
        </parameter>
      </target>
      <rule>
        <name value="derivedFromRef"/>
        <source>
          <context value="qr"/>
          <element value="id"/>
          <variable value="qid"/>
        </source>
        <target>
          <context value="ref"/>
          <element value="reference"/>
          <transform value="copy"/>
          <parameter>
            <valueId value="qid"/>
          </parameter>
        </target>
      </rule>
    </rule>
  </group>
  <group>
    <name value="BuildRiskBase"/>
    <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"/>
        <condition
                   value="(reference.exists() and (reference.startsWith('Patient/'))) or (reference.empty() and (type.empty() or ('/' + type).endsWith('/Patient')))"/>
      </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"/>
        <condition
                   value="(reference.exists() and (reference.startsWith('Encounter/'))) or (reference.empty() and (type.empty() or ('/' + type).endsWith('/Encounter')))"/>
      </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"/>
        <condition
                   value="(reference.exists() and (reference.startsWith('Patient/') or reference.startsWith('Practitioner/'))) or (reference.empty() and (type.empty() or ('/' + type).endsWith('/Patient') or ('/' + type).endsWith('/Practitioner')))"/>
      </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.where(((reference.exists() and (reference.startsWith('Patient/') or reference.startsWith('Practitioner/'))) or (reference.empty() and (type.empty() or ('/' + type).endsWith('/Patient') or ('/' + type).endsWith('/Practitioner'))))).exists().not()"/>
      </source>
      <rule>
        <name value="performerFromSource"/>
        <source>
          <context value="qr"/>
          <element value="source"/>
          <variable value="src"/>
          <condition
                     value="(reference.exists() and (reference.startsWith('Patient/') or reference.startsWith('Practitioner/'))) or (reference.empty() and (type.empty() or ('/' + type).endsWith('/Patient') or ('/' + type).endsWith('/Practitioner')))"/>
        </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"/>
      </source>
      <target>
        <context value="ra"/>
        <element value="basis"/>
        <variable value="qref"/>
        <transform value="create"/>
        <parameter>
          <valueString value="Reference"/>
        </parameter>
      </target>
      <rule>
        <name value="basisQuestionnaireResponse"/>
        <source>
          <context value="qr"/>
          <element value="id"/>
          <variable value="qid"/>
        </source>
        <target>
          <context value="qref"/>
          <element value="reference"/>
          <transform value="copy"/>
          <parameter>
            <valueId value="qid"/>
          </parameter>
        </target>
      </rule>
    </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>
  <group>
    <name value="SetCarePlanFullUrl"/>
    <input>
      <name value="plan"/>
      <type value="CarePlan"/>
      <mode value="source"/>
    </input>
    <input>
      <name value="entry"/>
      <mode value="target"/>
    </input>
    <rule>
      <name value="assignFullUrl"/>
      <source>
        <context value="plan"/>
        <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/CarePlan/"/>
        </parameter>
        <parameter>
          <valueId value="id"/>
        </parameter>
      </target>
    </rule>
  </group>
  <group>
    <name value="SetServiceRequestFullUrl"/>
    <input>
      <name value="sr"/>
      <type value="ServiceRequest"/>
      <mode value="source"/>
    </input>
    <input>
      <name value="entry"/>
      <mode value="target"/>
    </input>
    <rule>
      <name value="assignFullUrl"/>
      <source>
        <context value="sr"/>
        <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/ServiceRequest/"/>
        </parameter>
        <parameter>
          <valueId value="id"/>
        </parameter>
      </target>
    </rule>
  </group>
  <group>
    <name value="CopyResponseTags"/>
    <documentation
                   value="── Tenancy ──────────────────────────────────────────────────────────────────
Whose this is. The platform says which tenant a response belongs to with a
tag on the response, and every tag the response carries is copied onto
everything this map creates, as it is. Copied rather than named here, so the
map never has to know which tenant it is running for, nor which system the
tag is under: that system has moved more than once."/>
    <input>
      <name value="qr"/>
      <type value="QR"/>
      <mode value="source"/>
    </input>
    <input>
      <name value="r"/>
      <mode value="target"/>
    </input>
    <rule>
      <name value="tenantTags"/>
      <source>
        <context value="qr"/>
        <element value="meta"/>
        <variable value="qm"/>
      </source>
      <rule>
        <name value="copyTag"/>
        <source>
          <context value="qm"/>
          <element value="tag"/>
          <variable value="qt"/>
        </source>
        <target>
          <context value="r"/>
          <element value="meta"/>
          <variable value="m"/>
        </target>
        <target>
          <context value="m"/>
          <element value="tag"/>
          <transform value="copy"/>
          <parameter>
            <valueId value="qt"/>
          </parameter>
        </target>
      </rule>
    </rule>
  </group>
</StructureMap>