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

<StructureMap xmlns="http://hl7.org/fhir">
  <id value="ExtractPaediatricTbIcfScreening"/>
  <text>
    <status value="generated"/><div xmlns="http://www.w3.org/1999/xhtml"><p class="res-header-id"><b>Generated Narrative: StructureMap ExtractPaediatricTbIcfScreening</b></p><a name="ExtractPaediatricTbIcfScreening"> </a><a name="hcExtractPaediatricTbIcfScreening"> </a><pre class="fml">
<span style="color: #cc00cc">/// <b>url</b> = </span><span style="color: blue">'https://fhir.slade360.co.ke/fhir/StructureMap/ExtractPaediatricTbIcfScreening'</span>
<span style="color: #cc00cc">/// <b>name</b> = </span><span style="color: blue">'ExtractPaediatricTbIcfScreening'</span>
<span style="color: #cc00cc">/// <b>title</b> = </span><span style="color: blue">'Paediatric TB Intensified Case Finding Screening 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 paediatric intensified case finding screen out as one Observation carrying the screen result, with the five questions as components, plus a RiskAssessment for the band that result falls in. The tool has no score: it is answered yes to any one question or no to all five, so the band is binary and the arithmetic is a disjunction rather than a sum. Both branches extract. A screen that came back negative is the record that the screen was done, which is what makes the guideline\'s `repeat screening on subsequent visits` a thing the notes can show, and it is what carries the IPT workup as its mitigation. The result is derived from the five answers rather than read off an outcome item the form does not have, so the questions and the conclusion cannot disagree.'</span>

<b>uses</b><span style="color: navy"> &quot;</span><a href="http://hl7.org/fhir/R5/questionnaireresponse.html" title="QuestionnaireResponse">http://hl7.org/fhir/StructureDefinition/QuestionnaireResponse</a><span style="color: navy">&quot; </span><b>alias </b>QR <b>as </b><b>source</b>
<b>uses</b><span style="color: navy"> &quot;</span><a href="http://hl7.org/fhir/R5/bundle.html" title="Bundle">http://hl7.org/fhir/StructureDefinition/Bundle</a><span style="color: navy">&quot; </span><b>alias </b>Bundle <b>as </b><b>target</b>
<b>uses</b><span style="color: navy"> &quot;</span><a href="http://hl7.org/fhir/R5/observation.html" title="Observation">http://hl7.org/fhir/StructureDefinition/Observation</a><span style="color: navy">&quot; </span><b>alias </b>Observation <b>as </b><b>target</b>
<b>uses</b><span style="color: navy"> &quot;</span><a href="http://hl7.org/fhir/R5/riskassessment.html" title="RiskAssessment">http://hl7.org/fhir/StructureDefinition/RiskAssessment</a><span style="color: navy">&quot; </span><b>alias </b>RiskAssessment <b>as </b><b>target</b>

<b>group </b>ExtractPaediatricTbIcfScreening<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">The paper is a flat five-row table, so the questions are top-level items and</span>
  <span style="color: navy">// </span><span style="color: green">the response itself is the anchor. One answered question is enough to make</span>
  <span style="color: navy">// </span><span style="color: green">an Observation: a partly filled screen still records findings worth keeping.</span>
  <span style="color: navy">// </span><span style="color: green">Whether it is enough to conclude anything is a separate question, and</span>
  <span style="color: navy">// </span><span style="color: green">SetScreenOutcome is where that is decided.</span>
  qr<b> where </b><span style="color: navy">(</span>item.where(linkId in ('cough' | 'fever' | 'failure-to-thrive' | 'lethargy' | 'tb-contact')).answer.value.ofType(Coding).exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span> bundle.entry<b> as </b><span style="color: maroon">entry</span><span style="color: navy">, </span> entry.resource = <b>create</b><span style="color: navy">(</span><span style="color: blue">'Observation'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">obs</span><b> then</b><span style="color: navy"> {
</span>    qr<span style="color: navy"><b> -&gt; </b></span> obs<span style="color: navy">, </span> entry<b> then </b>BuildObsBase<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">obs</span><span style="color: navy">, </span><span style="color: maroon">entry</span><span style="color: navy">)</span> <i>&quot;base&quot;</i><span style="color: navy">;</span>
    qr<span style="color: navy"><b> -&gt; </b></span>obs<b> then </b>SetSurveyCategory<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">obs</span><span style="color: navy">)</span> <i>&quot;category&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">// </span><span style="color: green">Local, from concept-codesystem, because no code system this IG can resolve</span>
    <span style="color: navy">// </span><span style="color: green">names this screen. LOINC publishes no paediatric TB symptom screen -- only</span>
    <span style="color: navy">// </span><span style="color: green">the CPHS exposure-screen family, which is about exposure follow-up in a US</span>
    <span style="color: navy">// </span><span style="color: green">public-health programme -- and the ICD-10 and ICD-11 resources here are</span>
    <span style="color: navy">// </span><span style="color: green">`content: fragment` stubs with no url, so an ICD code could not be</span>
    <span style="color: navy">// </span><span style="color: green">validated against anything. The same code goes on the RiskAssessment: the</span>
    <span style="color: navy">// </span><span style="color: green">resource type already says which of the two is the observation and which</span>
    <span style="color: navy">// </span><span style="color: green">is the assessment, so a second code would only be a second thing to keep</span>
    <span style="color: navy">// </span><span style="color: green">in step.</span>
    qr<span style="color: navy"><b> -&gt; </b></span>obs.code<b> as </b><span style="color: maroon">code</span><b> then</b><span style="color: navy"> {
</span>      qr<span style="color: navy"><b> -&gt; </b></span>code.coding<b> as </b><span style="color: maroon">coding</span><b> then</b><span style="color: navy"> {
</span>        qr<span style="color: navy"><b> -&gt; </b></span>coding.system = <span style="color: blue">'https://fhir.slade360.co.ke/fhir/CodeSystem/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">'tb-screen'</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">'Paediatric TB intensified case finding screen'</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">'Paediatric TB intensified case finding screen'</span> <i>&quot;codeText&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;code&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">// </span><span style="color: green">The five questions, each coded to the finding it asks about rather than to</span>
    <span style="color: navy">// </span><span style="color: green">one bucket code with the question in the display. Observation.component</span>
    <span style="color: navy">// </span><span style="color: green">.code is what a query filters on, so `which children screened positive for</span>
    <span style="color: navy">// </span><span style="color: green">a TB contact` has to be a question the record can answer.</span>
    qr.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'cough') and answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span>obs.component<b> as </b><span style="color: maroon">comp</span><b> then</b><span style="color: navy"> {
</span>      it<span style="color: navy"><b> -&gt; </b></span>comp.code<b> as </b><span style="color: maroon">code</span><b> then</b><span style="color: navy"> {
</span>        it<span style="color: navy"><b> -&gt; </b></span>code.coding<b> as </b><span style="color: maroon">coding</span><b> then</b><span style="color: navy"> {
</span>          it<span style="color: navy"><b> -&gt; </b></span>coding.system = <span style="color: blue">'https://fhir.slade360.co.ke/fhir/CodeSystem/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">'tb-screen-cough'</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">'Cough of any duration'</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>
        it<span style="color: navy"><b> -&gt; </b></span>code.text = <span style="color: blue">'Cough of any duration'</span> <i>&quot;codeText&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;coughCode&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;coughValue&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;coughRule&quot;</i><span style="color: navy">;</span>
    qr.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'fever') and answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span>obs.component<b> as </b><span style="color: maroon">comp</span><b> then</b><span style="color: navy"> {
</span>      it<span style="color: navy"><b> -&gt; </b></span>comp.code<b> as </b><span style="color: maroon">code</span><b> then</b><span style="color: navy"> {
</span>        it<span style="color: navy"><b> -&gt; </b></span>code.coding<b> as </b><span style="color: maroon">coding</span><b> then</b><span style="color: navy"> {
</span>          it<span style="color: navy"><b> -&gt; </b></span>coding.system = <span style="color: blue">'https://fhir.slade360.co.ke/fhir/CodeSystem/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">'tb-screen-fever'</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">'Fever'</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>
        it<span style="color: navy"><b> -&gt; </b></span>code.text = <span style="color: blue">'Fever'</span> <i>&quot;codeText&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;feverCode&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;feverValue&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;feverRule&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">// </span><span style="color: green">One item on the paper, and one component here. The tool asks failure to</span>
    <span style="color: navy">// </span><span style="color: green">thrive *or* poor weight gain as a single question and the reviewer wrote</span>
    <span style="color: navy">// </span><span style="color: green">`malnutrition` against it, so splitting it into two components would</span>
    <span style="color: navy">// </span><span style="color: green">invent a distinction the nurse was never asked to make. The question as</span>
    <span style="color: navy">// </span><span style="color: green">printed is what the code and its text both say.</span>
    qr.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'failure-to-thrive') and answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span>obs.component<b> as </b><span style="color: maroon">comp</span><b> then</b><span style="color: navy"> {
</span>      it<span style="color: navy"><b> -&gt; </b></span>comp.code<b> as </b><span style="color: maroon">code</span><b> then</b><span style="color: navy"> {
</span>        it<span style="color: navy"><b> -&gt; </b></span>code.coding<b> as </b><span style="color: maroon">coding</span><b> then</b><span style="color: navy"> {
</span>          it<span style="color: navy"><b> -&gt; </b></span>coding.system = <span style="color: blue">'https://fhir.slade360.co.ke/fhir/CodeSystem/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">'tb-screen-failure-to-thrive'</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">'Failure to thrive or poor weight gain'</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>
        it<span style="color: navy"><b> -&gt; </b></span>code.text = <span style="color: blue">'Failure to thrive or poor weight gain'</span> <i>&quot;codeText&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;thriveCode&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;thriveValue&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;thriveRule&quot;</i><span style="color: navy">;</span>
    qr.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'lethargy') and answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span>obs.component<b> as </b><span style="color: maroon">comp</span><b> then</b><span style="color: navy"> {
</span>      it<span style="color: navy"><b> -&gt; </b></span>comp.code<b> as </b><span style="color: maroon">code</span><b> then</b><span style="color: navy"> {
</span>        it<span style="color: navy"><b> -&gt; </b></span>code.coding<b> as </b><span style="color: maroon">coding</span><b> then</b><span style="color: navy"> {
</span>          it<span style="color: navy"><b> -&gt; </b></span>coding.system = <span style="color: blue">'https://fhir.slade360.co.ke/fhir/CodeSystem/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">'tb-screen-lethargy'</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">'Lethargy, less playful than usual'</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>
        it<span style="color: navy"><b> -&gt; </b></span>code.text = <span style="color: blue">'Lethargy, less playful than usual'</span> <i>&quot;codeText&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;lethargyCode&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;lethargyValue&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;lethargyRule&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">// </span><span style="color: green">The one question of the five that is about exposure rather than about the</span>
    <span style="color: navy">// </span><span style="color: green">child. It stays a component of the same screen rather than becoming its</span>
    <span style="color: navy">// </span><span style="color: green">own resource: what makes it meaningful is the four answers beside it.</span>
    qr.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'tb-contact') and answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span>obs.component<b> as </b><span style="color: maroon">comp</span><b> then</b><span style="color: navy"> {
</span>      it<span style="color: navy"><b> -&gt; </b></span>comp.code<b> as </b><span style="color: maroon">code</span><b> then</b><span style="color: navy"> {
</span>        it<span style="color: navy"><b> -&gt; </b></span>code.coding<b> as </b><span style="color: maroon">coding</span><b> then</b><span style="color: navy"> {
</span>          it<span style="color: navy"><b> -&gt; </b></span>coding.system = <span style="color: blue">'https://fhir.slade360.co.ke/fhir/CodeSystem/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">'tb-screen-contact'</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">'Contact with a TB case'</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>
        it<span style="color: navy"><b> -&gt; </b></span>code.text = <span style="color: blue">'Contact with a TB case'</span> <i>&quot;codeText&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;contactCode&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;contactValue&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;contactRule&quot;</i><span style="color: navy">;</span>
    qr<span style="color: navy"><b> -&gt; </b></span>obs<b> then </b>SetScreenOutcome<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">obs</span><span style="color: navy">)</span> <i>&quot;outcome&quot;</i><span style="color: navy">;</span>
    qr<span style="color: navy"><b> -&gt; </b></span> obs<span style="color: navy">, </span> bundle<b> then </b>AddTbScreenRiskAssessment<span style="color: navy">(</span><span style="color: maroon">obs</span><span style="color: navy">, </span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">bundle</span><span style="color: navy">)</span> <i>&quot;band&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">}</span> <i>&quot;screenRule&quot;</i><span style="color: navy">;</span>
<span style="color: navy">}

</span><span style="color: navy">// </span><span style="color: green">─────────────────────────────────────────────────────────────────────────────</span>
<span style="color: navy">// </span><span style="color: green">The screen result</span>
<span style="color: navy">// </span><span style="color: green">The tool states its own rule, in the two bullets printed under the table: yes</span>
<span style="color: navy">// </span><span style="color: green">to any one question means suspect TB, no to all of them means initiate workup</span>
<span style="color: navy">// </span><span style="color: green">for IPT and screen again next visit. So the result is a disjunction over five</span>
<span style="color: navy">// </span><span style="color: green">yes/no answers, and there is nothing to sum.</span>
<span style="color: navy">// </span><span style="color: green">**Both branches are guarded on all five having been answered.** The positive</span>
<span style="color: navy">// </span><span style="color: green">branch does not need to be for the yes to be true -- one yes is one yes -- but</span>
<span style="color: navy">// </span><span style="color: green">it does need to be for the *negative* branch to be safe, and the two have to</span>
<span style="color: navy">// </span><span style="color: green">agree about what a complete screen is or a form answered `no, no, yes` to the</span>
<span style="color: navy">// </span><span style="color: green">first three questions would extract a positive result while `no, no, no` to</span>
<span style="color: navy">// </span><span style="color: green">the same three extracted nothing at all. A screen short of an item is not this</span>
<span style="color: navy">// </span><span style="color: green">screen: four questions answered no says nothing about the fifth, and a clinician</span>
<span style="color: navy">// </span><span style="color: green">reading `no signs of TB` off a form where nobody asked about the TB contact is</span>
<span style="color: navy">// </span><span style="color: green">being told something the form does not know.</span>
<span style="color: navy">// </span><span style="color: green">The answers are `Y` and `N`, from CodeSystem/v2-0532. The value set the form</span>
<span style="color: navy">// </span><span style="color: green">binds is ValueSet/v2-0136, whose codes come from 0532 -- table 0136 was folded</span>
<span style="color: navy">// </span><span style="color: green">into it -- so a guard testing 'yes' compiles, never fires, and silently</span>
<span style="color: navy">// </span><span style="color: green">extracts nothing.</span>
<span style="color: navy">// </span><span style="color: green">The result reuses `special-clinic-code-system#presumed-tb` and `#no-tb-signs`,</span>
<span style="color: navy">// </span><span style="color: green">which this IG already defines for TB screening in the ANC and CWC workflows.</span>
<span style="color: navy">// </span><span style="color: green">Nothing new was minted for it: a query for presumed TB should find this form</span>
<span style="color: navy">// </span><span style="color: green">and those together, and a second code saying the same thing in a different</span>
<span style="color: navy">// </span><span style="color: green">system would be a synonym to keep in step rather than information.</span>
<span style="color: navy">// </span><span style="color: green">─────────────────────────────────────────────────────────────────────────────</span>
<b>group </b>SetScreenOutcome<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<b> where </b><span style="color: navy">(</span>(item.where(linkId in ('cough' | 'fever' | 'failure-to-thrive' | 'lethargy' | 'tb-contact')).answer.value.ofType(Coding).count() = 5) and item.where(linkId in ('cough' | 'fever' | 'failure-to-thrive' | 'lethargy' | 'tb-contact')).answer.value.ofType(Coding).where(code = 'Y').exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span>obs.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>    qr<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">local</span><b> then</b><span style="color: navy"> {
</span>      qr<span style="color: navy"><b> -&gt; </b></span>local.system = <span style="color: blue">'https://fhir.slade360.co.ke/fhir/CodeSystem/special-clinic-code-system'</span> <i>&quot;localSystem&quot;</i><span style="color: navy">;</span>
      qr<span style="color: navy"><b> -&gt; </b></span>local.code = <span style="color: blue">'presumed-tb'</span> <i>&quot;localCode&quot;</i><span style="color: navy">;</span>
      qr<span style="color: navy"><b> -&gt; </b></span>local.display = <span style="color: blue">'Presumed TB'</span> <i>&quot;localDisplay&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;localCoding&quot;</i><span style="color: navy">;</span>
    qr<span style="color: navy"><b> -&gt; </b></span>cc.text = <span style="color: blue">'Presumed TB — at least one screening question answered yes'</span> <i>&quot;outcomeText&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">}</span> <i>&quot;screenPositive&quot;</i><span style="color: navy">;</span>
  qr<b> where </b><span style="color: navy">(</span>(item.where(linkId in ('cough' | 'fever' | 'failure-to-thrive' | 'lethargy' | 'tb-contact')).answer.value.ofType(Coding).count() = 5) and item.where(linkId in ('cough' | 'fever' | 'failure-to-thrive' | 'lethargy' | 'tb-contact')).answer.value.ofType(Coding).where(code = 'Y').exists().not()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span>obs.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>    qr<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">local</span><b> then</b><span style="color: navy"> {
</span>      qr<span style="color: navy"><b> -&gt; </b></span>local.system = <span style="color: blue">'https://fhir.slade360.co.ke/fhir/CodeSystem/special-clinic-code-system'</span> <i>&quot;localSystem&quot;</i><span style="color: navy">;</span>
      qr<span style="color: navy"><b> -&gt; </b></span>local.code = <span style="color: blue">'no-tb-signs'</span> <i>&quot;localCode&quot;</i><span style="color: navy">;</span>
      qr<span style="color: navy"><b> -&gt; </b></span>local.display = <span style="color: blue">'No Signs of TB'</span> <i>&quot;localDisplay&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;localCoding&quot;</i><span style="color: navy">;</span>
    qr<span style="color: navy"><b> -&gt; </b></span>cc.text = <span style="color: blue">'No signs of TB — all five screening questions answered no'</span> <i>&quot;outcomeText&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">}</span> <i>&quot;screenNegative&quot;</i><span style="color: navy">;</span>
<span style="color: navy">}

</span><span style="color: navy">// </span><span style="color: green">─────────────────────────────────────────────────────────────────────────────</span>
<span style="color: navy">// </span><span style="color: green">The band</span>
<span style="color: navy">// </span><span style="color: green">Read off the Observation the rule above just built, not recomputed from the</span>
<span style="color: navy">// </span><span style="color: green">answers. Deriving it a second time would be a second implementation of the</span>
<span style="color: navy">// </span><span style="color: green">same disjunction, and two implementations of one rule is one more than can be</span>
<span style="color: navy">// </span><span style="color: green">kept in agreement. It is also why a partly answered screen produces no</span>
<span style="color: navy">// </span><span style="color: green">RiskAssessment at all: no result, nothing to band.</span>
<span style="color: navy">// </span><span style="color: green">`qualitativeRisk` carries HL7 risk-probability -- which is what a consumer</span>
<span style="color: navy">// </span><span style="color: green">escalates on -- alongside the local screen-result code, and the plain wording</span>
<span style="color: navy">// </span><span style="color: green">in `.text`. `prediction.outcome` is the disease being predicted, which is the</span>
<span style="color: navy">// </span><span style="color: green">question a RiskAssessment exists to answer and is the same concept in both</span>
<span style="color: navy">// </span><span style="color: green">branches; only the likelihood differs.</span>
<span style="color: navy">// </span><span style="color: green">`mitigation` is the guideline's own instruction, verbatim in substance. That</span>
<span style="color: navy">// </span><span style="color: green">element is the right home for it: it is what to do to reduce the risk, it</span>
<span style="color: navy">// </span><span style="color: green">travels with the assessment, and it means a screen recorded at a health centre</span>
<span style="color: navy">// </span><span style="color: green">arrives at the next clinician with the action already attached.</span>
<span style="color: navy">// </span><span style="color: green">A negative screen bands `low`, not `negligible`. The tool does not clear a</span>
<span style="color: navy">// </span><span style="color: green">child -- it sends them for IPT workup and asks for the screen again next visit</span>
<span style="color: navy">// </span><span style="color: green">-- so a code that reads as no further action would misstate it.</span>
<span style="color: navy">// </span><span style="color: green">─────────────────────────────────────────────────────────────────────────────</span>
<b>group </b>AddTbScreenRiskAssessment<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(CodeableConcept).coding.where(code = 'presumed-tb').exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span> bundle.entry<b> as </b><span style="color: maroon">entry</span><span style="color: navy">, </span> entry.resource = <b>create</b><span style="color: navy">(</span><span style="color: blue">'RiskAssessment'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">ra</span><b> then</b><span style="color: navy"> {
</span>    qr<span style="color: navy"><b> -&gt; </b></span> ra<span style="color: navy">, </span> entry<b> then </b>BuildRiskBase<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">obs</span><span style="color: navy">, </span><span style="color: maroon">ra</span><span style="color: navy">, </span><span style="color: maroon">entry</span><span style="color: navy">)</span> <i>&quot;riskBase&quot;</i><span style="color: navy">;</span>
    qr<span style="color: navy"><b> -&gt; </b></span>ra<b> then </b>SetTbScreenRiskCode<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<b> then </b>SetTbPredictionOutcome<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">pred</span><span style="color: navy">)</span> <i>&quot;predictionOutcome&quot;</i><span style="color: navy">;</span>
      qr<span style="color: navy"><b> -&gt; </b></span>pred.qualitativeRisk<b> as </b><span style="color: maroon">risk</span><b> then</b><span style="color: navy"> {
</span>        qr<span style="color: navy"><b> -&gt; </b></span>risk.coding<b> as </b><span style="color: maroon">coding</span><b> then</b><span style="color: navy"> {
</span>          qr<span style="color: navy"><b> -&gt; </b></span>coding.system = <span style="color: blue">'http://terminology.hl7.org/CodeSystem/risk-probability'</span> <i>&quot;riskSystem&quot;</i><span style="color: navy">;</span>
          qr<span style="color: navy"><b> -&gt; </b></span>coding.code = <span style="color: blue">'high'</span> <i>&quot;riskCode&quot;</i><span style="color: navy">;</span>
          qr<span style="color: navy"><b> -&gt; </b></span>coding.display = <span style="color: blue">'High likelihood'</span> <i>&quot;riskDisplay&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;hl7Coding&quot;</i><span style="color: navy">;</span>
        qr<span style="color: navy"><b> -&gt; </b></span>risk.coding<b> as </b><span style="color: maroon">local</span><b> then</b><span style="color: navy"> {
</span>          qr<span style="color: navy"><b> -&gt; </b></span>local.system = <span style="color: blue">'https://fhir.slade360.co.ke/fhir/CodeSystem/special-clinic-code-system'</span> <i>&quot;localSystem&quot;</i><span style="color: navy">;</span>
          qr<span style="color: navy"><b> -&gt; </b></span>local.code = <span style="color: blue">'presumed-tb'</span> <i>&quot;localCode&quot;</i><span style="color: navy">;</span>
          qr<span style="color: navy"><b> -&gt; </b></span>local.display = <span style="color: blue">'Presumed TB'</span> <i>&quot;localDisplay&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;localCoding&quot;</i><span style="color: navy">;</span>
        qr<span style="color: navy"><b> -&gt; </b></span>risk.text = <span style="color: blue">'Presumed TB'</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>
      qr<span style="color: navy"><b> -&gt; </b></span>pred.rationale = <span style="color: blue">'At least one of the five intensified case finding questions was answered yes.'</span> <i>&quot;rationale&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;prediction&quot;</i><span style="color: navy">;</span>
    qr<span style="color: navy"><b> -&gt; </b></span>ra.mitigation = <span style="color: blue">'Suspect TB. Examine the child and use the paediatric TB diagnostic algorithm to evaluate for active disease. Rule out underlying conditions and refer if necessary.'</span> <i>&quot;mitigation&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">}</span> <i>&quot;presumedTb&quot;</i><span style="color: navy">;</span>
  obs<b> where </b><span style="color: navy">(</span>value.ofType(CodeableConcept).coding.where(code = 'no-tb-signs').exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span> bundle.entry<b> as </b><span style="color: maroon">entry</span><span style="color: navy">, </span> entry.resource = <b>create</b><span style="color: navy">(</span><span style="color: blue">'RiskAssessment'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">ra</span><b> then</b><span style="color: navy"> {
</span>    qr<span style="color: navy"><b> -&gt; </b></span> ra<span style="color: navy">, </span> entry<b> then </b>BuildRiskBase<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">obs</span><span style="color: navy">, </span><span style="color: maroon">ra</span><span style="color: navy">, </span><span style="color: maroon">entry</span><span style="color: navy">)</span> <i>&quot;riskBase&quot;</i><span style="color: navy">;</span>
    qr<span style="color: navy"><b> -&gt; </b></span>ra<b> then </b>SetTbScreenRiskCode<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<b> then </b>SetTbPredictionOutcome<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">pred</span><span style="color: navy">)</span> <i>&quot;predictionOutcome&quot;</i><span style="color: navy">;</span>
      qr<span style="color: navy"><b> -&gt; </b></span>pred.qualitativeRisk<b> as </b><span style="color: maroon">risk</span><b> then</b><span style="color: navy"> {
</span>        qr<span style="color: navy"><b> -&gt; </b></span>risk.coding<b> as </b><span style="color: maroon">coding</span><b> then</b><span style="color: navy"> {
</span>          qr<span style="color: navy"><b> -&gt; </b></span>coding.system = <span style="color: blue">'http://terminology.hl7.org/CodeSystem/risk-probability'</span> <i>&quot;riskSystem&quot;</i><span style="color: navy">;</span>
          qr<span style="color: navy"><b> -&gt; </b></span>coding.code = <span style="color: blue">'low'</span> <i>&quot;riskCode&quot;</i><span style="color: navy">;</span>
          qr<span style="color: navy"><b> -&gt; </b></span>coding.display = <span style="color: blue">'Low likelihood'</span> <i>&quot;riskDisplay&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;hl7Coding&quot;</i><span style="color: navy">;</span>
        qr<span style="color: navy"><b> -&gt; </b></span>risk.coding<b> as </b><span style="color: maroon">local</span><b> then</b><span style="color: navy"> {
</span>          qr<span style="color: navy"><b> -&gt; </b></span>local.system = <span style="color: blue">'https://fhir.slade360.co.ke/fhir/CodeSystem/special-clinic-code-system'</span> <i>&quot;localSystem&quot;</i><span style="color: navy">;</span>
          qr<span style="color: navy"><b> -&gt; </b></span>local.code = <span style="color: blue">'no-tb-signs'</span> <i>&quot;localCode&quot;</i><span style="color: navy">;</span>
          qr<span style="color: navy"><b> -&gt; </b></span>local.display = <span style="color: blue">'No Signs of TB'</span> <i>&quot;localDisplay&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;localCoding&quot;</i><span style="color: navy">;</span>
        qr<span style="color: navy"><b> -&gt; </b></span>risk.text = <span style="color: blue">'No signs of TB'</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>
      qr<span style="color: navy"><b> -&gt; </b></span>pred.rationale = <span style="color: blue">'All five intensified case finding questions were answered no.'</span> <i>&quot;rationale&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;prediction&quot;</i><span style="color: navy">;</span>
    qr<span style="color: navy"><b> -&gt; </b></span>ra.mitigation = <span style="color: blue">'Initiate workup for isoniazid preventive therapy and repeat this screen at subsequent visits.'</span> <i>&quot;mitigation&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">}</span> <i>&quot;noTbSigns&quot;</i><span style="color: navy">;</span>
<span style="color: navy">}

</span><b>group </b>SetTbScreenRiskCode<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">'https://fhir.slade360.co.ke/fhir/CodeSystem/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">'tb-screen'</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">'Paediatric TB intensified case finding screen'</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">'Paediatric TB intensified case finding screen'</span> <i>&quot;codeText&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>SetTbPredictionOutcome<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">pred</span><span style="color: navy">)</span><span style="color: navy"> {
</span>  qr<span style="color: navy"><b> -&gt; </b></span>pred.outcome<b> as </b><span style="color: maroon">outcome</span><b> then</b><span style="color: navy"> {
</span>    qr<span style="color: navy"><b> -&gt; </b></span>outcome.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/concept-codesystem'</span> <i>&quot;outcomeSystem&quot;</i><span style="color: navy">;</span>
      qr<span style="color: navy"><b> -&gt; </b></span>coding.code = <span style="color: blue">'tb-screen-tuberculosis'</span> <i>&quot;outcomeCode&quot;</i><span style="color: navy">;</span>
      qr<span style="color: navy"><b> -&gt; </b></span>coding.display = <span style="color: blue">'Tuberculosis'</span> <i>&quot;outcomeDisplay&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;outcomeCoding&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">}</span> <i>&quot;predictionOutcome&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">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">`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</span>
<span style="color: navy">// </span><span style="color: green">publisher is objecting to what its own compiler emits. Two arguments is the</span>
<span style="color: navy">// </span><span style="color: green">only form that compiles, and it is what the R5 transform engine executes.</span>
<span style="color: navy">// </span><span style="color: green">─────────────────────────────────────────────────────────────────────────────</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<b> then </b>SetResponseProvenance<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">obs</span><span style="color: navy">)</span> <i>&quot;responseProvenance&quot;</i><span style="color: navy">;</span>
  qr<span style="color: navy"><b> -&gt; </b></span>obs.id = <b>uuid</b><span style="color: navy">(</span><span style="color: navy">)</span><b> then </b>SetObservationFullUrl<span style="color: navy">(</span><span style="color: maroon">obs</span><span style="color: navy">, </span><span style="color: maroon">entry</span><span style="color: navy">)</span> <i>&quot;idAndFullUrl&quot;</i><span style="color: navy">;</span>
  qr<span style="color: navy"><b> -&gt; </b></span>entry.request<b> as </b><span style="color: maroon">request</span><b> then</b><span style="color: navy"> {
</span>    qr<span style="color: navy"><b> -&gt; </b></span>request.method = <span style="color: blue">'POST'</span> <i>&quot;requestMethod&quot;</i><span style="color: navy">;</span>
    qr<span style="color: navy"><b> -&gt; </b></span>request.url = <span style="color: blue">'Observation'</span> <i>&quot;requestUrl&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">}</span> <i>&quot;entryRequest&quot;</i><span style="color: navy">;</span>
  qr<span style="color: navy"><b> -&gt; </b></span>obs.status = <span style="color: blue">'final'</span> <i>&quot;status&quot;</i><span style="color: navy">;</span>
  qr.subject<b> as </b><span style="color: maroon">s</span><span style="color: navy"><b> -&gt; </b></span>obs.subject = <span style="color: maroon">s</span><span style="color: navy">;</span>
  qr.encounter<b> as </b><span style="color: maroon">e</span><span style="color: navy"><b> -&gt; </b></span>obs.encounter = <span style="color: maroon">e</span><span style="color: navy">;</span>
  qr.authored<b> as </b><span style="color: maroon">t</span><span style="color: navy"><b> -&gt; </b></span>obs.effective = <span style="color: maroon">t</span> <i>&quot;effective&quot;</i><span style="color: navy">;</span>
  qr.source<b> as </b><span style="color: maroon">src</span><span style="color: navy"><b> -&gt; </b></span>obs.performer = <span style="color: maroon">src</span> <i>&quot;performerFromSource&quot;</i><span style="color: navy">;</span>
  qr<b> where </b><span style="color: navy">(</span>source.exists().not()<span style="color: navy">)</span><b> then</b><span style="color: navy"> {
</span>    qr.author<b> as </b><span style="color: maroon">a</span><span style="color: navy"><b> -&gt; </b></span>obs.performer = <span style="color: maroon">a</span> <i>&quot;performerFromAuthor&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">}</span> <i>&quot;performerFallback&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">// </span><span style="color: green">A stored response's id already reads &quot;QuestionnaireResponse/&lt;id&gt;&quot;, so it is</span>
  <span style="color: navy">// </span><span style="color: green">a relative reference as it stands. The hasValue() guard is what stops an</span>
  <span style="color: navy">// </span><span style="color: green">unsaved response -- one posted straight to $extract rather than saved first</span>
  <span style="color: navy">// </span><span style="color: green">-- from writing &quot;QuestionnaireResponse/null&quot; into the record.</span>
  qr.id<b> as </b><span style="color: maroon">qid</span><b> where </b><span style="color: navy">(</span>$this.hasValue()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span> obs.derivedFrom = <b>create</b><span style="color: navy">(</span><span style="color: blue">'Reference'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">ref</span><span style="color: navy">, </span> ref.reference = <span style="color: maroon">qid</span> <i>&quot;linkQuestionnaireResponse&quot;</i><span style="color: navy">;</span>
<span style="color: navy">}

</span><span style="color: navy">// </span><span style="color: green">The RiskAssessment stands on two things: the response that was filled in and</span>
<span style="color: navy">// </span><span style="color: green">the Observation that holds the result. Both go in basis, which is what the</span>
<span style="color: navy">// </span><span style="color: green">SGHI RiskAssessment profile binds to a QuestionnaireResponse.</span>
<b>group </b>BuildRiskBase<span style="color: navy">(</span><b>source</b> <span style="color: maroon">qr</span><span style="color: navy"> : </span>QR, <b>source</b> <span style="color: maroon">obs</span><span style="color: navy"> : </span>Observation, <b>target</b> <span style="color: maroon">ra</span><span style="color: navy"> : </span>RiskAssessment, <b>target</b> <span style="color: maroon">entry</span><span style="color: navy">)</span><span style="color: navy"> {
</span>  qr<span style="color: navy"><b> -&gt; </b></span>ra<b> then </b>SetResponseProvenance<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;responseProvenance&quot;</i><span style="color: navy">;</span>
  qr<span style="color: navy"><b> -&gt; </b></span>ra.id = <b>uuid</b><span style="color: navy">(</span><span style="color: navy">)</span><b> then </b>SetRiskAssessmentFullUrl<span style="color: navy">(</span><span style="color: maroon">ra</span><span style="color: navy">, </span><span style="color: maroon">entry</span><span style="color: navy">)</span> <i>&quot;idAndFullUrl&quot;</i><span style="color: navy">;</span>
  qr<span style="color: navy"><b> -&gt; </b></span>entry.request<b> as </b><span style="color: maroon">request</span><b> then</b><span style="color: navy"> {
</span>    qr<span style="color: navy"><b> -&gt; </b></span>request.method = <span style="color: blue">'POST'</span> <i>&quot;requestMethod&quot;</i><span style="color: navy">;</span>
    qr<span style="color: navy"><b> -&gt; </b></span>request.url = <span style="color: blue">'RiskAssessment'</span> <i>&quot;requestUrl&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">}</span> <i>&quot;entryRequest&quot;</i><span style="color: navy">;</span>
  qr<span style="color: navy"><b> -&gt; </b></span>ra.status = <span style="color: blue">'final'</span> <i>&quot;status&quot;</i><span style="color: navy">;</span>
  qr.subject<b> as </b><span style="color: maroon">s</span><span style="color: navy"><b> -&gt; </b></span>ra.subject = <span style="color: maroon">s</span><span style="color: navy">;</span>
  qr.encounter<b> as </b><span style="color: maroon">e</span><span style="color: navy"><b> -&gt; </b></span>ra.encounter = <span style="color: maroon">e</span><span style="color: navy">;</span>
  qr.authored<b> as </b><span style="color: maroon">t</span><span style="color: navy"><b> -&gt; </b></span>ra.occurrence = <span style="color: maroon">t</span> <i>&quot;occurrence&quot;</i><span style="color: navy">;</span>
  qr.author<b> as </b><span style="color: maroon">a</span><span style="color: navy"><b> -&gt; </b></span>ra.performer = <span style="color: maroon">a</span> <i>&quot;performerFromAuthor&quot;</i><span style="color: navy">;</span>
  qr<b> where </b><span style="color: navy">(</span>author.exists().not()<span style="color: navy">)</span><b> then</b><span style="color: navy"> {
</span>    qr.source<b> as </b><span style="color: maroon">src</span><span style="color: navy"><b> -&gt; </b></span>ra.performer = <span style="color: maroon">src</span> <i>&quot;performerFromSource&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">}</span> <i>&quot;performerFallback&quot;</i><span style="color: navy">;</span>
  qr.id<b> as </b><span style="color: maroon">qid</span><b> where </b><span style="color: navy">(</span>$this.hasValue()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span> ra.basis = <b>create</b><span style="color: navy">(</span><span style="color: blue">'Reference'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">qref</span><span style="color: navy">, </span> qref.reference = <span style="color: maroon">qid</span> <i>&quot;basisResponse&quot;</i><span style="color: navy">;</span>
  obs.id<b> as </b><span style="color: maroon">oid</span><span style="color: navy"><b> -&gt; </b></span>ra.basis = <b>create</b><span style="color: navy">(</span><span style="color: blue">'Reference'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">oref</span><b> then</b><span style="color: navy"> {
</span>    oid<span style="color: navy"><b> -&gt; </b></span>oref.reference = <b>append</b><span style="color: navy">(</span><span style="color: blue">'Observation/'</span><span style="color: navy">, </span><span style="color: maroon">oid</span><span style="color: navy">)</span> <i>&quot;basisObservationRef&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">}</span> <i>&quot;basisObservation&quot;</i><span style="color: navy">;</span>
<span style="color: navy">}

</span><span style="color: navy">// </span><span style="color: green">The two answer shapes a component can carry. Both read the answer through the</span>
<span style="color: navy">// </span><span style="color: green">untyped `.value` accessor: reading `valueCoding` or `valueQuantity` by its</span>
<span style="color: navy">// </span><span style="color: green">typed property name fails at transform time on HAPI R5 with &quot;Attempt to read</span>
<span style="color: navy">// </span><span style="color: green">invalid property ... on QuestionnaireResponse.item.answer&quot;.</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><span style="color: navy">// </span><span style="color: green">── Provenance and tenancy ───────────────────────────────────────────────────</span>
<span style="color: navy">// </span><span style="color: green">Two tags on everything this map creates. The first says which questionnaire</span>
<span style="color: navy">// </span><span style="color: green">produced it, so a screen recorded at one visit can be told from the screen</span>
<span style="color: navy">// </span><span style="color: green">recorded at the next and from every other form that codes the same findings.</span>
<span style="color: navy">// </span><span style="color: green">The second copies the tenant tags off the response, because nothing else on</span>
<span style="color: navy">// </span><span style="color: green">the path puts them there.</span>
<span style="color: navy">// </span><span style="color: green">The code is the form's document type, not the questionnaire's id: every</span>
<span style="color: navy">// </span><span style="color: green">environment mints its own ids, and there is only one set of maps, so an id</span>
<span style="color: navy">// </span><span style="color: green">here would tie the tag to whichever environment stamped it.</span>
<span style="color: navy">// </span><span style="color: green">── Provenance and tenancy ───────────────────────────────────────────────────</span>
<b>group </b>SetResponseProvenance<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<span style="color: navy"><b> -&gt; </b></span>r.meta<b> as </b><span style="color: maroon">m</span><b> then</b><span style="color: navy"> {
</span>    qr<span style="color: navy"><b> -&gt; </b></span>m.tag<b> as </b><span style="color: maroon">t</span><b> then</b><span style="color: navy"> {
</span>      qr<span style="color: navy"><b> -&gt; </b></span>t.system = <span style="color: blue">'http://slade360edi.com/questionnaire-provenance'</span> <i>&quot;provenanceSystem&quot;</i><span style="color: navy">;</span>
      qr<span style="color: navy"><b> -&gt; </b></span>t.code = <span style="color: blue">'paediatric-tb-icf-screening'</span> <i>&quot;provenanceCode&quot;</i><span style="color: navy">;</span>
      qr<span style="color: navy"><b> -&gt; </b></span>t.display = <span style="color: blue">'Paediatric TB intensified case finding screening tool'</span> <i>&quot;provenanceDisplay&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;provenanceTag&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">}</span> <i>&quot;provenanceMeta&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">// </span><span style="color: green">Every tag the response carries, onto the resource. `meta` is 0..1, so this</span>
  <span style="color: navy">// </span><span style="color: green">lands on the same meta the rule above created rather than a second one.</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/ExtractPaediatricTbIcfScreening"/>
  <version value="0.1.0"/>
  <name value="ExtractPaediatricTbIcfScreening"/>
  <title value="Paediatric TB Intensified Case Finding Screening Extraction"/>
  <status value="active"/>
  <date value="2026-09-14T06:31:13+00:00"/>
  <publisher value="Kathurima Kimathi"/>
  <contact>
    <name value="Kathurima Kimathi"/>
    <telecom>
      <system value="url"/>
      <value value="https://www.linkedin.com/in/kathurima-kimathi/"/>
    </telecom>
    <telecom>
      <system value="email"/>
      <value value="kathurimakimathi415@gmail.com"/>
    </telecom>
  </contact>
  <contact>
    <name value="Oscar John"/>
    <telecom>
      <system value="email"/>
      <value value="oscarjohnotieno@gmail.com"/>
      <use value="work"/>
    </telecom>
  </contact>
  <contact>
    <name value="Kennedy Omondi"/>
    <telecom>
      <system value="email"/>
      <value value="kennankole@gmail.com"/>
      <use value="work"/>
    </telecom>
  </contact>
  <description value="The paediatric intensified case finding screen out as one Observation carrying the screen result, with the five questions as components, plus a RiskAssessment for the band that result falls in. The tool has no score: it is answered yes to any one question or no to all five, so the band is binary and the arithmetic is a disjunction rather than a sum. Both branches extract. A screen that came back negative is the record that the screen was done, which is what makes the guideline's `repeat screening on subsequent visits` a thing the notes can show, and it is what carries the IPT workup as its mitigation. The result is derived from the five answers rather than read off an outcome item the form does not have, so the questions and the conclusion cannot disagree."/>
  <structure>
    <url value="http://hl7.org/fhir/StructureDefinition/QuestionnaireResponse"/>
    <mode value="source"/>
    <alias value="QR"/>
  </structure>
  <structure>
    <url value="http://hl7.org/fhir/StructureDefinition/Bundle"/>
    <mode value="target"/>
    <alias value="Bundle"/>
  </structure>
  <structure>
    <url value="http://hl7.org/fhir/StructureDefinition/Observation"/>
    <mode value="target"/>
    <alias value="Observation"/>
  </structure>
  <structure>
    <url value="http://hl7.org/fhir/StructureDefinition/RiskAssessment"/>
    <mode value="target"/>
    <alias value="RiskAssessment"/>
  </structure>
  <group>
    <name value="ExtractPaediatricTbIcfScreening"/>
    <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="screenRule"/>
      <source>
        <context value="qr"/>
        <condition value="item.where(linkId in ('cough' | 'fever' | 'failure-to-thrive' | 'lethargy' | 'tb-contact')).answer.value.ofType(Coding).exists()"/>
      </source>
      <target>
        <context value="bundle"/>
        <element value="entry"/>
        <variable value="entry"/>
      </target>
      <target>
        <context value="entry"/>
        <element value="resource"/>
        <variable value="obs"/>
        <transform value="create"/>
        <parameter>
          <valueString value="Observation"/>
        </parameter>
      </target>
      <rule>
        <name value="base"/>
        <source>
          <context value="qr"/>
        </source>
        <target>
          <context value="obs"/>
        </target>
        <target>
          <context value="entry"/>
        </target>
        <dependent>
          <name value="BuildObsBase"/>
          <parameter>
            <valueId value="qr"/>
          </parameter>
          <parameter>
            <valueId value="obs"/>
          </parameter>
          <parameter>
            <valueId value="entry"/>
          </parameter>
        </dependent>
      </rule>
      <rule>
        <name value="category"/>
        <source>
          <context value="qr"/>
        </source>
        <target>
          <context value="obs"/>
        </target>
        <dependent>
          <name value="SetSurveyCategory"/>
          <parameter>
            <valueId value="qr"/>
          </parameter>
          <parameter>
            <valueId value="obs"/>
          </parameter>
        </dependent>
      </rule>
      <rule>
        <name value="code"/>
        <source>
          <context value="qr"/>
        </source>
        <target>
          <context value="obs"/>
          <element value="code"/>
          <variable value="code"/>
        </target>
        <rule>
          <name value="codeCoding"/>
          <source>
            <context value="qr"/>
          </source>
          <target>
            <context value="code"/>
            <element value="coding"/>
            <variable value="coding"/>
          </target>
          <rule>
            <name value="codeSystem"/>
            <source>
              <context value="qr"/>
            </source>
            <target>
              <context value="coding"/>
              <element value="system"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="https://fhir.slade360.co.ke/fhir/CodeSystem/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="tb-screen"/>
              </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="Paediatric TB intensified case finding screen"/>
              </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="Paediatric TB intensified case finding screen"/>
            </parameter>
          </target>
        </rule>
        <documentation value="Local, from concept-codesystem, because no code system this IG can resolve&#xD;&#xA;names this screen. LOINC publishes no paediatric TB symptom screen -- only&#xD;&#xA;the CPHS exposure-screen family, which is about exposure follow-up in a US&#xD;&#xA;public-health programme -- and the ICD-10 and ICD-11 resources here are&#xD;&#xA;`content: fragment` stubs with no url, so an ICD code could not be&#xD;&#xA;validated against anything. The same code goes on the RiskAssessment: the&#xD;&#xA;resource type already says which of the two is the observation and which&#xD;&#xA;is the assessment, so a second code would only be a second thing to keep&#xD;&#xA;in step."/>
      </rule>
      <rule>
        <name value="coughRule"/>
        <source>
          <context value="qr"/>
          <element value="item"/>
          <variable value="it"/>
          <condition value="(linkId = 'cough') and answer.value.exists()"/>
        </source>
        <target>
          <context value="obs"/>
          <element value="component"/>
          <variable value="comp"/>
        </target>
        <rule>
          <name value="coughCode"/>
          <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/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="tb-screen-cough"/>
                </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="Cough of any duration"/>
                </parameter>
              </target>
            </rule>
          </rule>
          <rule>
            <name value="codeText"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="code"/>
              <element value="text"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="Cough of any duration"/>
              </parameter>
            </target>
          </rule>
        </rule>
        <rule>
          <name value="coughValue"/>
          <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>
        <documentation value="The five questions, each coded to the finding it asks about rather than to&#xD;&#xA;one bucket code with the question in the display. Observation.component&#xD;&#xA;.code is what a query filters on, so `which children screened positive for&#xD;&#xA;a TB contact` has to be a question the record can answer."/>
      </rule>
      <rule>
        <name value="feverRule"/>
        <source>
          <context value="qr"/>
          <element value="item"/>
          <variable value="it"/>
          <condition value="(linkId = 'fever') and answer.value.exists()"/>
        </source>
        <target>
          <context value="obs"/>
          <element value="component"/>
          <variable value="comp"/>
        </target>
        <rule>
          <name value="feverCode"/>
          <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/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="tb-screen-fever"/>
                </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="Fever"/>
                </parameter>
              </target>
            </rule>
          </rule>
          <rule>
            <name value="codeText"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="code"/>
              <element value="text"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="Fever"/>
              </parameter>
            </target>
          </rule>
        </rule>
        <rule>
          <name value="feverValue"/>
          <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="thriveRule"/>
        <source>
          <context value="qr"/>
          <element value="item"/>
          <variable value="it"/>
          <condition value="(linkId = 'failure-to-thrive') and answer.value.exists()"/>
        </source>
        <target>
          <context value="obs"/>
          <element value="component"/>
          <variable value="comp"/>
        </target>
        <rule>
          <name value="thriveCode"/>
          <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/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="tb-screen-failure-to-thrive"/>
                </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="Failure to thrive or poor weight gain"/>
                </parameter>
              </target>
            </rule>
          </rule>
          <rule>
            <name value="codeText"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="code"/>
              <element value="text"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="Failure to thrive or poor weight gain"/>
              </parameter>
            </target>
          </rule>
        </rule>
        <rule>
          <name value="thriveValue"/>
          <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>
        <documentation value="One item on the paper, and one component here. The tool asks failure to&#xD;&#xA;thrive *or* poor weight gain as a single question and the reviewer wrote&#xD;&#xA;`malnutrition` against it, so splitting it into two components would&#xD;&#xA;invent a distinction the nurse was never asked to make. The question as&#xD;&#xA;printed is what the code and its text both say."/>
      </rule>
      <rule>
        <name value="lethargyRule"/>
        <source>
          <context value="qr"/>
          <element value="item"/>
          <variable value="it"/>
          <condition value="(linkId = 'lethargy') and answer.value.exists()"/>
        </source>
        <target>
          <context value="obs"/>
          <element value="component"/>
          <variable value="comp"/>
        </target>
        <rule>
          <name value="lethargyCode"/>
          <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/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="tb-screen-lethargy"/>
                </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="Lethargy, less playful than usual"/>
                </parameter>
              </target>
            </rule>
          </rule>
          <rule>
            <name value="codeText"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="code"/>
              <element value="text"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="Lethargy, less playful than usual"/>
              </parameter>
            </target>
          </rule>
        </rule>
        <rule>
          <name value="lethargyValue"/>
          <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="contactRule"/>
        <source>
          <context value="qr"/>
          <element value="item"/>
          <variable value="it"/>
          <condition value="(linkId = 'tb-contact') and answer.value.exists()"/>
        </source>
        <target>
          <context value="obs"/>
          <element value="component"/>
          <variable value="comp"/>
        </target>
        <rule>
          <name value="contactCode"/>
          <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/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="tb-screen-contact"/>
                </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="Contact with a TB case"/>
                </parameter>
              </target>
            </rule>
          </rule>
          <rule>
            <name value="codeText"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="code"/>
              <element value="text"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="Contact with a TB case"/>
              </parameter>
            </target>
          </rule>
        </rule>
        <rule>
          <name value="contactValue"/>
          <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>
        <documentation value="The one question of the five that is about exposure rather than about the&#xD;&#xA;child. It stays a component of the same screen rather than becoming its&#xD;&#xA;own resource: what makes it meaningful is the four answers beside it."/>
      </rule>
      <rule>
        <name value="outcome"/>
        <source>
          <context value="qr"/>
        </source>
        <target>
          <context value="obs"/>
        </target>
        <dependent>
          <name value="SetScreenOutcome"/>
          <parameter>
            <valueId value="qr"/>
          </parameter>
          <parameter>
            <valueId value="obs"/>
          </parameter>
        </dependent>
      </rule>
      <rule>
        <name value="band"/>
        <source>
          <context value="qr"/>
        </source>
        <target>
          <context value="obs"/>
        </target>
        <target>
          <context value="bundle"/>
        </target>
        <dependent>
          <name value="AddTbScreenRiskAssessment"/>
          <parameter>
            <valueId value="obs"/>
          </parameter>
          <parameter>
            <valueId value="qr"/>
          </parameter>
          <parameter>
            <valueId value="bundle"/>
          </parameter>
        </dependent>
      </rule>
      <documentation value="The paper is a flat five-row table, so the questions are top-level items and&#xD;&#xA;the response itself is the anchor. One answered question is enough to make&#xD;&#xA;an Observation: a partly filled screen still records findings worth keeping.&#xD;&#xA;Whether it is enough to conclude anything is a separate question, and&#xD;&#xA;SetScreenOutcome is where that is decided."/>
    </rule>
  </group>
  <group>
    <name value="SetScreenOutcome"/>
    <documentation value="─────────────────────────────────────────────────────────────────────────────&#xD;&#xA;The screen result&#xD;&#xA;The tool states its own rule, in the two bullets printed under the table: yes&#xD;&#xA;to any one question means suspect TB, no to all of them means initiate workup&#xD;&#xA;for IPT and screen again next visit. So the result is a disjunction over five&#xD;&#xA;yes/no answers, and there is nothing to sum.&#xD;&#xA;**Both branches are guarded on all five having been answered.** The positive&#xD;&#xA;branch does not need to be for the yes to be true -- one yes is one yes -- but&#xD;&#xA;it does need to be for the *negative* branch to be safe, and the two have to&#xD;&#xA;agree about what a complete screen is or a form answered `no, no, yes` to the&#xD;&#xA;first three questions would extract a positive result while `no, no, no` to&#xD;&#xA;the same three extracted nothing at all. A screen short of an item is not this&#xD;&#xA;screen: four questions answered no says nothing about the fifth, and a clinician&#xD;&#xA;reading `no signs of TB` off a form where nobody asked about the TB contact is&#xD;&#xA;being told something the form does not know.&#xD;&#xA;The answers are `Y` and `N`, from CodeSystem/v2-0532. The value set the form&#xD;&#xA;binds is ValueSet/v2-0136, whose codes come from 0532 -- table 0136 was folded&#xD;&#xA;into it -- so a guard testing 'yes' compiles, never fires, and silently&#xD;&#xA;extracts nothing.&#xD;&#xA;The result reuses `special-clinic-code-system#presumed-tb` and `#no-tb-signs`,&#xD;&#xA;which this IG already defines for TB screening in the ANC and CWC workflows.&#xD;&#xA;Nothing new was minted for it: a query for presumed TB should find this form&#xD;&#xA;and those together, and a second code saying the same thing in a different&#xD;&#xA;system would be a synonym to keep in step rather than information.&#xD;&#xA;─────────────────────────────────────────────────────────────────────────────"/>
    <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="screenPositive"/>
      <source>
        <context value="qr"/>
        <condition value="(item.where(linkId in ('cough' | 'fever' | 'failure-to-thrive' | 'lethargy' | 'tb-contact')).answer.value.ofType(Coding).count() = 5) and item.where(linkId in ('cough' | 'fever' | 'failure-to-thrive' | 'lethargy' | 'tb-contact')).answer.value.ofType(Coding).where(code = 'Y').exists()"/>
      </source>
      <target>
        <context value="obs"/>
        <element value="value"/>
        <variable value="cc"/>
        <transform value="create"/>
        <parameter>
          <valueString value="CodeableConcept"/>
        </parameter>
      </target>
      <rule>
        <name value="localCoding"/>
        <source>
          <context value="qr"/>
        </source>
        <target>
          <context value="cc"/>
          <element value="coding"/>
          <variable value="local"/>
        </target>
        <rule>
          <name value="localSystem"/>
          <source>
            <context value="qr"/>
          </source>
          <target>
            <context value="local"/>
            <element value="system"/>
            <transform value="copy"/>
            <parameter>
              <valueString value="https://fhir.slade360.co.ke/fhir/CodeSystem/special-clinic-code-system"/>
            </parameter>
          </target>
        </rule>
        <rule>
          <name value="localCode"/>
          <source>
            <context value="qr"/>
          </source>
          <target>
            <context value="local"/>
            <element value="code"/>
            <transform value="copy"/>
            <parameter>
              <valueString value="presumed-tb"/>
            </parameter>
          </target>
        </rule>
        <rule>
          <name value="localDisplay"/>
          <source>
            <context value="qr"/>
          </source>
          <target>
            <context value="local"/>
            <element value="display"/>
            <transform value="copy"/>
            <parameter>
              <valueString value="Presumed TB"/>
            </parameter>
          </target>
        </rule>
      </rule>
      <rule>
        <name value="outcomeText"/>
        <source>
          <context value="qr"/>
        </source>
        <target>
          <context value="cc"/>
          <element value="text"/>
          <transform value="copy"/>
          <parameter>
            <valueString value="Presumed TB — at least one screening question answered yes"/>
          </parameter>
        </target>
      </rule>
    </rule>
    <rule>
      <name value="screenNegative"/>
      <source>
        <context value="qr"/>
        <condition value="(item.where(linkId in ('cough' | 'fever' | 'failure-to-thrive' | 'lethargy' | 'tb-contact')).answer.value.ofType(Coding).count() = 5) and item.where(linkId in ('cough' | 'fever' | 'failure-to-thrive' | 'lethargy' | 'tb-contact')).answer.value.ofType(Coding).where(code = 'Y').exists().not()"/>
      </source>
      <target>
        <context value="obs"/>
        <element value="value"/>
        <variable value="cc"/>
        <transform value="create"/>
        <parameter>
          <valueString value="CodeableConcept"/>
        </parameter>
      </target>
      <rule>
        <name value="localCoding"/>
        <source>
          <context value="qr"/>
        </source>
        <target>
          <context value="cc"/>
          <element value="coding"/>
          <variable value="local"/>
        </target>
        <rule>
          <name value="localSystem"/>
          <source>
            <context value="qr"/>
          </source>
          <target>
            <context value="local"/>
            <element value="system"/>
            <transform value="copy"/>
            <parameter>
              <valueString value="https://fhir.slade360.co.ke/fhir/CodeSystem/special-clinic-code-system"/>
            </parameter>
          </target>
        </rule>
        <rule>
          <name value="localCode"/>
          <source>
            <context value="qr"/>
          </source>
          <target>
            <context value="local"/>
            <element value="code"/>
            <transform value="copy"/>
            <parameter>
              <valueString value="no-tb-signs"/>
            </parameter>
          </target>
        </rule>
        <rule>
          <name value="localDisplay"/>
          <source>
            <context value="qr"/>
          </source>
          <target>
            <context value="local"/>
            <element value="display"/>
            <transform value="copy"/>
            <parameter>
              <valueString value="No Signs of TB"/>
            </parameter>
          </target>
        </rule>
      </rule>
      <rule>
        <name value="outcomeText"/>
        <source>
          <context value="qr"/>
        </source>
        <target>
          <context value="cc"/>
          <element value="text"/>
          <transform value="copy"/>
          <parameter>
            <valueString value="No signs of TB — all five screening questions answered no"/>
          </parameter>
        </target>
      </rule>
    </rule>
  </group>
  <group>
    <name value="AddTbScreenRiskAssessment"/>
    <documentation value="─────────────────────────────────────────────────────────────────────────────&#xD;&#xA;The band&#xD;&#xA;Read off the Observation the rule above just built, not recomputed from the&#xD;&#xA;answers. Deriving it a second time would be a second implementation of the&#xD;&#xA;same disjunction, and two implementations of one rule is one more than can be&#xD;&#xA;kept in agreement. It is also why a partly answered screen produces no&#xD;&#xA;RiskAssessment at all: no result, nothing to band.&#xD;&#xA;`qualitativeRisk` carries HL7 risk-probability -- which is what a consumer&#xD;&#xA;escalates on -- alongside the local screen-result code, and the plain wording&#xD;&#xA;in `.text`. `prediction.outcome` is the disease being predicted, which is the&#xD;&#xA;question a RiskAssessment exists to answer and is the same concept in both&#xD;&#xA;branches; only the likelihood differs.&#xD;&#xA;`mitigation` is the guideline's own instruction, verbatim in substance. That&#xD;&#xA;element is the right home for it: it is what to do to reduce the risk, it&#xD;&#xA;travels with the assessment, and it means a screen recorded at a health centre&#xD;&#xA;arrives at the next clinician with the action already attached.&#xD;&#xA;A negative screen bands `low`, not `negligible`. The tool does not clear a&#xD;&#xA;child -- it sends them for IPT workup and asks for the screen again next visit&#xD;&#xA;-- so a code that reads as no further action would misstate it.&#xD;&#xA;─────────────────────────────────────────────────────────────────────────────"/>
    <input>
      <name value="obs"/>
      <type value="Observation"/>
      <mode value="source"/>
    </input>
    <input>
      <name value="qr"/>
      <type value="QR"/>
      <mode value="source"/>
    </input>
    <input>
      <name value="bundle"/>
      <type value="Bundle"/>
      <mode value="target"/>
    </input>
    <rule>
      <name value="presumedTb"/>
      <source>
        <context value="obs"/>
        <condition value="value.ofType(CodeableConcept).coding.where(code = 'presumed-tb').exists()"/>
      </source>
      <target>
        <context value="bundle"/>
        <element value="entry"/>
        <variable value="entry"/>
      </target>
      <target>
        <context value="entry"/>
        <element value="resource"/>
        <variable value="ra"/>
        <transform value="create"/>
        <parameter>
          <valueString value="RiskAssessment"/>
        </parameter>
      </target>
      <rule>
        <name value="riskBase"/>
        <source>
          <context value="qr"/>
        </source>
        <target>
          <context value="ra"/>
        </target>
        <target>
          <context value="entry"/>
        </target>
        <dependent>
          <name value="BuildRiskBase"/>
          <parameter>
            <valueId value="qr"/>
          </parameter>
          <parameter>
            <valueId value="obs"/>
          </parameter>
          <parameter>
            <valueId value="ra"/>
          </parameter>
          <parameter>
            <valueId value="entry"/>
          </parameter>
        </dependent>
      </rule>
      <rule>
        <name value="riskCode"/>
        <source>
          <context value="qr"/>
        </source>
        <target>
          <context value="ra"/>
        </target>
        <dependent>
          <name value="SetTbScreenRiskCode"/>
          <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="predictionOutcome"/>
          <source>
            <context value="qr"/>
          </source>
          <target>
            <context value="pred"/>
          </target>
          <dependent>
            <name value="SetTbPredictionOutcome"/>
            <parameter>
              <valueId value="qr"/>
            </parameter>
            <parameter>
              <valueId value="pred"/>
            </parameter>
          </dependent>
        </rule>
        <rule>
          <name value="qualitativeRisk"/>
          <source>
            <context value="qr"/>
          </source>
          <target>
            <context value="pred"/>
            <element value="qualitativeRisk"/>
            <variable value="risk"/>
          </target>
          <rule>
            <name value="hl7Coding"/>
            <source>
              <context value="qr"/>
            </source>
            <target>
              <context value="risk"/>
              <element value="coding"/>
              <variable value="coding"/>
            </target>
            <rule>
              <name value="riskSystem"/>
              <source>
                <context value="qr"/>
              </source>
              <target>
                <context value="coding"/>
                <element value="system"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="http://terminology.hl7.org/CodeSystem/risk-probability"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="riskCode"/>
              <source>
                <context value="qr"/>
              </source>
              <target>
                <context value="coding"/>
                <element value="code"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="high"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="riskDisplay"/>
              <source>
                <context value="qr"/>
              </source>
              <target>
                <context value="coding"/>
                <element value="display"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="High likelihood"/>
                </parameter>
              </target>
            </rule>
          </rule>
          <rule>
            <name value="localCoding"/>
            <source>
              <context value="qr"/>
            </source>
            <target>
              <context value="risk"/>
              <element value="coding"/>
              <variable value="local"/>
            </target>
            <rule>
              <name value="localSystem"/>
              <source>
                <context value="qr"/>
              </source>
              <target>
                <context value="local"/>
                <element value="system"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="https://fhir.slade360.co.ke/fhir/CodeSystem/special-clinic-code-system"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="localCode"/>
              <source>
                <context value="qr"/>
              </source>
              <target>
                <context value="local"/>
                <element value="code"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="presumed-tb"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="localDisplay"/>
              <source>
                <context value="qr"/>
              </source>
              <target>
                <context value="local"/>
                <element value="display"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="Presumed TB"/>
                </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="Presumed TB"/>
              </parameter>
            </target>
          </rule>
        </rule>
        <rule>
          <name value="rationale"/>
          <source>
            <context value="qr"/>
          </source>
          <target>
            <context value="pred"/>
            <element value="rationale"/>
            <transform value="copy"/>
            <parameter>
              <valueString value="At least one of the five intensified case finding questions was answered yes."/>
            </parameter>
          </target>
        </rule>
      </rule>
      <rule>
        <name value="mitigation"/>
        <source>
          <context value="qr"/>
        </source>
        <target>
          <context value="ra"/>
          <element value="mitigation"/>
          <transform value="copy"/>
          <parameter>
            <valueString value="Suspect TB. Examine the child and use the paediatric TB diagnostic algorithm to evaluate for active disease. Rule out underlying conditions and refer if necessary."/>
          </parameter>
        </target>
      </rule>
    </rule>
    <rule>
      <name value="noTbSigns"/>
      <source>
        <context value="obs"/>
        <condition value="value.ofType(CodeableConcept).coding.where(code = 'no-tb-signs').exists()"/>
      </source>
      <target>
        <context value="bundle"/>
        <element value="entry"/>
        <variable value="entry"/>
      </target>
      <target>
        <context value="entry"/>
        <element value="resource"/>
        <variable value="ra"/>
        <transform value="create"/>
        <parameter>
          <valueString value="RiskAssessment"/>
        </parameter>
      </target>
      <rule>
        <name value="riskBase"/>
        <source>
          <context value="qr"/>
        </source>
        <target>
          <context value="ra"/>
        </target>
        <target>
          <context value="entry"/>
        </target>
        <dependent>
          <name value="BuildRiskBase"/>
          <parameter>
            <valueId value="qr"/>
          </parameter>
          <parameter>
            <valueId value="obs"/>
          </parameter>
          <parameter>
            <valueId value="ra"/>
          </parameter>
          <parameter>
            <valueId value="entry"/>
          </parameter>
        </dependent>
      </rule>
      <rule>
        <name value="riskCode"/>
        <source>
          <context value="qr"/>
        </source>
        <target>
          <context value="ra"/>
        </target>
        <dependent>
          <name value="SetTbScreenRiskCode"/>
          <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="predictionOutcome"/>
          <source>
            <context value="qr"/>
          </source>
          <target>
            <context value="pred"/>
          </target>
          <dependent>
            <name value="SetTbPredictionOutcome"/>
            <parameter>
              <valueId value="qr"/>
            </parameter>
            <parameter>
              <valueId value="pred"/>
            </parameter>
          </dependent>
        </rule>
        <rule>
          <name value="qualitativeRisk"/>
          <source>
            <context value="qr"/>
          </source>
          <target>
            <context value="pred"/>
            <element value="qualitativeRisk"/>
            <variable value="risk"/>
          </target>
          <rule>
            <name value="hl7Coding"/>
            <source>
              <context value="qr"/>
            </source>
            <target>
              <context value="risk"/>
              <element value="coding"/>
              <variable value="coding"/>
            </target>
            <rule>
              <name value="riskSystem"/>
              <source>
                <context value="qr"/>
              </source>
              <target>
                <context value="coding"/>
                <element value="system"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="http://terminology.hl7.org/CodeSystem/risk-probability"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="riskCode"/>
              <source>
                <context value="qr"/>
              </source>
              <target>
                <context value="coding"/>
                <element value="code"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="low"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="riskDisplay"/>
              <source>
                <context value="qr"/>
              </source>
              <target>
                <context value="coding"/>
                <element value="display"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="Low likelihood"/>
                </parameter>
              </target>
            </rule>
          </rule>
          <rule>
            <name value="localCoding"/>
            <source>
              <context value="qr"/>
            </source>
            <target>
              <context value="risk"/>
              <element value="coding"/>
              <variable value="local"/>
            </target>
            <rule>
              <name value="localSystem"/>
              <source>
                <context value="qr"/>
              </source>
              <target>
                <context value="local"/>
                <element value="system"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="https://fhir.slade360.co.ke/fhir/CodeSystem/special-clinic-code-system"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="localCode"/>
              <source>
                <context value="qr"/>
              </source>
              <target>
                <context value="local"/>
                <element value="code"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="no-tb-signs"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="localDisplay"/>
              <source>
                <context value="qr"/>
              </source>
              <target>
                <context value="local"/>
                <element value="display"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="No Signs of TB"/>
                </parameter>
              </target>
            </rule>
          </rule>
          <rule>
            <name value="riskText"/>
            <source>
              <context value="qr"/>
            </source>
            <target>
              <context value="risk"/>
              <element value="text"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="No signs of TB"/>
              </parameter>
            </target>
          </rule>
        </rule>
        <rule>
          <name value="rationale"/>
          <source>
            <context value="qr"/>
          </source>
          <target>
            <context value="pred"/>
            <element value="rationale"/>
            <transform value="copy"/>
            <parameter>
              <valueString value="All five intensified case finding questions were answered no."/>
            </parameter>
          </target>
        </rule>
      </rule>
      <rule>
        <name value="mitigation"/>
        <source>
          <context value="qr"/>
        </source>
        <target>
          <context value="ra"/>
          <element value="mitigation"/>
          <transform value="copy"/>
          <parameter>
            <valueString value="Initiate workup for isoniazid preventive therapy and repeat this screen at subsequent visits."/>
          </parameter>
        </target>
      </rule>
    </rule>
  </group>
  <group>
    <name value="SetTbScreenRiskCode"/>
    <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="https://fhir.slade360.co.ke/fhir/CodeSystem/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="tb-screen"/>
            </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="Paediatric TB intensified case finding screen"/>
            </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="Paediatric TB intensified case finding screen"/>
          </parameter>
        </target>
      </rule>
    </rule>
  </group>
  <group>
    <name value="SetTbPredictionOutcome"/>
    <input>
      <name value="qr"/>
      <type value="QR"/>
      <mode value="source"/>
    </input>
    <input>
      <name value="pred"/>
      <mode value="target"/>
    </input>
    <rule>
      <name value="predictionOutcome"/>
      <source>
        <context value="qr"/>
      </source>
      <target>
        <context value="pred"/>
        <element value="outcome"/>
        <variable value="outcome"/>
      </target>
      <rule>
        <name value="outcomeCoding"/>
        <source>
          <context value="qr"/>
        </source>
        <target>
          <context value="outcome"/>
          <element value="coding"/>
          <variable value="coding"/>
        </target>
        <rule>
          <name value="outcomeSystem"/>
          <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/concept-codesystem"/>
            </parameter>
          </target>
        </rule>
        <rule>
          <name value="outcomeCode"/>
          <source>
            <context value="qr"/>
          </source>
          <target>
            <context value="coding"/>
            <element value="code"/>
            <transform value="copy"/>
            <parameter>
              <valueString value="tb-screen-tuberculosis"/>
            </parameter>
          </target>
        </rule>
        <rule>
          <name value="outcomeDisplay"/>
          <source>
            <context value="qr"/>
          </source>
          <target>
            <context value="coding"/>
            <element value="display"/>
            <transform value="copy"/>
            <parameter>
              <valueString value="Tuberculosis"/>
            </parameter>
          </target>
        </rule>
      </rule>
    </rule>
  </group>
  <group>
    <name value="BuildObsBase"/>
    <documentation value="─────────────────────────────────────────────────────────────────────────────&#xD;&#xA;Shared scaffolding. Repeated in each map rather than imported: the transform&#xD;&#xA;engine resolves `imports` against whatever StructureMaps happen to be on the&#xD;&#xA;server, and a form that stops extracting because a shared map was not&#xD;&#xA;uploaded is a worse failure than a duplicated group.&#xD;&#xA;Two notes on what the publisher's StructureMap validator says about this file.&#xD;&#xA;Source parameters below are left untyped on purpose. Writing `: Element` makes&#xD;&#xA;the validator compare QuestionnaireResponse.item against the literal 'Element'&#xD;&#xA;and report them as incompatible with each other, which is noise, not a finding.&#xD;&#xA;`evaluate(context, expression)` is flagged as &quot;takes 1 parameter but 2 were&#xD;&#xA;found&quot;. Leave it. The FML parser in the same jar refuses the one-argument form&#xD;&#xA;outright -- it wants a parameter, a comma, then the FHIRPath -- so the&#xD;&#xA;publisher is objecting to what its own compiler emits. Two arguments is the&#xD;&#xA;only form that compiles, and it is what the R5 transform engine executes.&#xD;&#xA;─────────────────────────────────────────────────────────────────────────────"/>
    <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="responseProvenance"/>
      <source>
        <context value="qr"/>
      </source>
      <target>
        <context value="obs"/>
      </target>
      <dependent>
        <name value="SetResponseProvenance"/>
        <parameter>
          <valueId value="qr"/>
        </parameter>
        <parameter>
          <valueId value="obs"/>
        </parameter>
      </dependent>
    </rule>
    <rule>
      <name value="idAndFullUrl"/>
      <source>
        <context value="qr"/>
      </source>
      <target>
        <context value="obs"/>
        <element value="id"/>
        <transform value="uuid"/>
      </target>
      <dependent>
        <name value="SetObservationFullUrl"/>
        <parameter>
          <valueId value="obs"/>
        </parameter>
        <parameter>
          <valueId value="entry"/>
        </parameter>
      </dependent>
    </rule>
    <rule>
      <name value="entryRequest"/>
      <source>
        <context value="qr"/>
      </source>
      <target>
        <context value="entry"/>
        <element value="request"/>
        <variable value="request"/>
      </target>
      <rule>
        <name value="requestMethod"/>
        <source>
          <context value="qr"/>
        </source>
        <target>
          <context value="request"/>
          <element value="method"/>
          <transform value="copy"/>
          <parameter>
            <valueString value="POST"/>
          </parameter>
        </target>
      </rule>
      <rule>
        <name value="requestUrl"/>
        <source>
          <context value="qr"/>
        </source>
        <target>
          <context value="request"/>
          <element value="url"/>
          <transform value="copy"/>
          <parameter>
            <valueString value="Observation"/>
          </parameter>
        </target>
      </rule>
    </rule>
    <rule>
      <name value="status"/>
      <source>
        <context value="qr"/>
      </source>
      <target>
        <context value="obs"/>
        <element value="status"/>
        <transform value="copy"/>
        <parameter>
          <valueString value="final"/>
        </parameter>
      </target>
    </rule>
    <rule>
      <name value="subject"/>
      <source>
        <context value="qr"/>
        <element value="subject"/>
        <variable value="s"/>
      </source>
      <target>
        <context value="obs"/>
        <element value="subject"/>
        <transform value="copy"/>
        <parameter>
          <valueId value="s"/>
        </parameter>
      </target>
    </rule>
    <rule>
      <name value="encounter"/>
      <source>
        <context value="qr"/>
        <element value="encounter"/>
        <variable value="e"/>
      </source>
      <target>
        <context value="obs"/>
        <element value="encounter"/>
        <transform value="copy"/>
        <parameter>
          <valueId value="e"/>
        </parameter>
      </target>
    </rule>
    <rule>
      <name value="effective"/>
      <source>
        <context value="qr"/>
        <element value="authored"/>
        <variable value="t"/>
      </source>
      <target>
        <context value="obs"/>
        <element value="effective"/>
        <transform value="copy"/>
        <parameter>
          <valueId value="t"/>
        </parameter>
      </target>
    </rule>
    <rule>
      <name value="performerFromSource"/>
      <source>
        <context value="qr"/>
        <element value="source"/>
        <variable value="src"/>
      </source>
      <target>
        <context value="obs"/>
        <element value="performer"/>
        <transform value="copy"/>
        <parameter>
          <valueId value="src"/>
        </parameter>
      </target>
    </rule>
    <rule>
      <name value="performerFallback"/>
      <source>
        <context value="qr"/>
        <condition value="source.exists().not()"/>
      </source>
      <rule>
        <name value="performerFromAuthor"/>
        <source>
          <context value="qr"/>
          <element value="author"/>
          <variable value="a"/>
        </source>
        <target>
          <context value="obs"/>
          <element value="performer"/>
          <transform value="copy"/>
          <parameter>
            <valueId value="a"/>
          </parameter>
        </target>
      </rule>
    </rule>
    <rule>
      <name value="linkQuestionnaireResponse"/>
      <source>
        <context value="qr"/>
        <element value="id"/>
        <variable value="qid"/>
        <condition value="$this.hasValue()"/>
      </source>
      <target>
        <context value="obs"/>
        <element value="derivedFrom"/>
        <variable value="ref"/>
        <transform value="create"/>
        <parameter>
          <valueString value="Reference"/>
        </parameter>
      </target>
      <target>
        <context value="ref"/>
        <element value="reference"/>
        <transform value="copy"/>
        <parameter>
          <valueId value="qid"/>
        </parameter>
      </target>
      <documentation value="A stored response's id already reads &quot;QuestionnaireResponse/&lt;id&gt;&quot;, so it is&#xD;&#xA;a relative reference as it stands. The hasValue() guard is what stops an&#xD;&#xA;unsaved response -- one posted straight to $extract rather than saved first&#xD;&#xA;-- from writing &quot;QuestionnaireResponse/null&quot; into the record."/>
    </rule>
  </group>
  <group>
    <name value="BuildRiskBase"/>
    <documentation value="The RiskAssessment stands on two things: the response that was filled in and&#xD;&#xA;the Observation that holds the result. Both go in basis, which is what the&#xD;&#xA;SGHI RiskAssessment profile binds to a QuestionnaireResponse."/>
    <input>
      <name value="qr"/>
      <type value="QR"/>
      <mode value="source"/>
    </input>
    <input>
      <name value="obs"/>
      <type value="Observation"/>
      <mode value="source"/>
    </input>
    <input>
      <name value="ra"/>
      <type value="RiskAssessment"/>
      <mode value="target"/>
    </input>
    <input>
      <name value="entry"/>
      <mode value="target"/>
    </input>
    <rule>
      <name value="responseProvenance"/>
      <source>
        <context value="qr"/>
      </source>
      <target>
        <context value="ra"/>
      </target>
      <dependent>
        <name value="SetResponseProvenance"/>
        <parameter>
          <valueId value="qr"/>
        </parameter>
        <parameter>
          <valueId value="ra"/>
        </parameter>
      </dependent>
    </rule>
    <rule>
      <name value="idAndFullUrl"/>
      <source>
        <context value="qr"/>
      </source>
      <target>
        <context value="ra"/>
        <element value="id"/>
        <transform value="uuid"/>
      </target>
      <dependent>
        <name value="SetRiskAssessmentFullUrl"/>
        <parameter>
          <valueId value="ra"/>
        </parameter>
        <parameter>
          <valueId value="entry"/>
        </parameter>
      </dependent>
    </rule>
    <rule>
      <name value="entryRequest"/>
      <source>
        <context value="qr"/>
      </source>
      <target>
        <context value="entry"/>
        <element value="request"/>
        <variable value="request"/>
      </target>
      <rule>
        <name value="requestMethod"/>
        <source>
          <context value="qr"/>
        </source>
        <target>
          <context value="request"/>
          <element value="method"/>
          <transform value="copy"/>
          <parameter>
            <valueString value="POST"/>
          </parameter>
        </target>
      </rule>
      <rule>
        <name value="requestUrl"/>
        <source>
          <context value="qr"/>
        </source>
        <target>
          <context value="request"/>
          <element value="url"/>
          <transform value="copy"/>
          <parameter>
            <valueString value="RiskAssessment"/>
          </parameter>
        </target>
      </rule>
    </rule>
    <rule>
      <name value="status"/>
      <source>
        <context value="qr"/>
      </source>
      <target>
        <context value="ra"/>
        <element value="status"/>
        <transform value="copy"/>
        <parameter>
          <valueString value="final"/>
        </parameter>
      </target>
    </rule>
    <rule>
      <name value="subject"/>
      <source>
        <context value="qr"/>
        <element value="subject"/>
        <variable value="s"/>
      </source>
      <target>
        <context value="ra"/>
        <element value="subject"/>
        <transform value="copy"/>
        <parameter>
          <valueId value="s"/>
        </parameter>
      </target>
    </rule>
    <rule>
      <name value="encounter"/>
      <source>
        <context value="qr"/>
        <element value="encounter"/>
        <variable value="e"/>
      </source>
      <target>
        <context value="ra"/>
        <element value="encounter"/>
        <transform value="copy"/>
        <parameter>
          <valueId value="e"/>
        </parameter>
      </target>
    </rule>
    <rule>
      <name value="occurrence"/>
      <source>
        <context value="qr"/>
        <element value="authored"/>
        <variable value="t"/>
      </source>
      <target>
        <context value="ra"/>
        <element value="occurrence"/>
        <transform value="copy"/>
        <parameter>
          <valueId value="t"/>
        </parameter>
      </target>
    </rule>
    <rule>
      <name value="performerFromAuthor"/>
      <source>
        <context value="qr"/>
        <element value="author"/>
        <variable value="a"/>
      </source>
      <target>
        <context value="ra"/>
        <element value="performer"/>
        <transform value="copy"/>
        <parameter>
          <valueId value="a"/>
        </parameter>
      </target>
    </rule>
    <rule>
      <name value="performerFallback"/>
      <source>
        <context value="qr"/>
        <condition value="author.exists().not()"/>
      </source>
      <rule>
        <name value="performerFromSource"/>
        <source>
          <context value="qr"/>
          <element value="source"/>
          <variable value="src"/>
        </source>
        <target>
          <context value="ra"/>
          <element value="performer"/>
          <transform value="copy"/>
          <parameter>
            <valueId value="src"/>
          </parameter>
        </target>
      </rule>
    </rule>
    <rule>
      <name value="basisResponse"/>
      <source>
        <context value="qr"/>
        <element value="id"/>
        <variable value="qid"/>
        <condition value="$this.hasValue()"/>
      </source>
      <target>
        <context value="ra"/>
        <element value="basis"/>
        <variable value="qref"/>
        <transform value="create"/>
        <parameter>
          <valueString value="Reference"/>
        </parameter>
      </target>
      <target>
        <context value="qref"/>
        <element value="reference"/>
        <transform value="copy"/>
        <parameter>
          <valueId value="qid"/>
        </parameter>
      </target>
    </rule>
    <rule>
      <name value="basisObservation"/>
      <source>
        <context value="obs"/>
        <element value="id"/>
        <variable value="oid"/>
      </source>
      <target>
        <context value="ra"/>
        <element value="basis"/>
        <variable value="oref"/>
        <transform value="create"/>
        <parameter>
          <valueString value="Reference"/>
        </parameter>
      </target>
      <rule>
        <name value="basisObservationRef"/>
        <source>
          <context value="oid"/>
        </source>
        <target>
          <context value="oref"/>
          <element value="reference"/>
          <transform value="append"/>
          <parameter>
            <valueString value="Observation/"/>
          </parameter>
          <parameter>
            <valueId value="oid"/>
          </parameter>
        </target>
      </rule>
    </rule>
  </group>
  <group>
    <name value="SetComponentCodedValue"/>
    <documentation value="The two answer shapes a component can carry. Both read the answer through the&#xD;&#xA;untyped `.value` accessor: reading `valueCoding` or `valueQuantity` by its&#xD;&#xA;typed property name fails at transform time on HAPI R5 with &quot;Attempt to read&#xD;&#xA;invalid property ... on QuestionnaireResponse.item.answer&quot;."/>
    <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="SetResponseProvenance"/>
    <documentation value="── Provenance and tenancy ───────────────────────────────────────────────────&#xD;&#xA;Two tags on everything this map creates. The first says which questionnaire&#xD;&#xA;produced it, so a screen recorded at one visit can be told from the screen&#xD;&#xA;recorded at the next and from every other form that codes the same findings.&#xD;&#xA;The second copies the tenant tags off the response, because nothing else on&#xD;&#xA;the path puts them there.&#xD;&#xA;The code is the form's document type, not the questionnaire's id: every&#xD;&#xA;environment mints its own ids, and there is only one set of maps, so an id&#xD;&#xA;here would tie the tag to whichever environment stamped it.&#xD;&#xA;── Provenance and tenancy ───────────────────────────────────────────────────"/>
    <input>
      <name value="qr"/>
      <type value="QR"/>
      <mode value="source"/>
    </input>
    <input>
      <name value="r"/>
      <mode value="target"/>
    </input>
    <rule>
      <name value="provenanceMeta"/>
      <source>
        <context value="qr"/>
      </source>
      <target>
        <context value="r"/>
        <element value="meta"/>
        <variable value="m"/>
      </target>
      <rule>
        <name value="provenanceTag"/>
        <source>
          <context value="qr"/>
        </source>
        <target>
          <context value="m"/>
          <element value="tag"/>
          <variable value="t"/>
        </target>
        <rule>
          <name value="provenanceSystem"/>
          <source>
            <context value="qr"/>
          </source>
          <target>
            <context value="t"/>
            <element value="system"/>
            <transform value="copy"/>
            <parameter>
              <valueString value="http://slade360edi.com/questionnaire-provenance"/>
            </parameter>
          </target>
        </rule>
        <rule>
          <name value="provenanceCode"/>
          <source>
            <context value="qr"/>
          </source>
          <target>
            <context value="t"/>
            <element value="code"/>
            <transform value="copy"/>
            <parameter>
              <valueString value="paediatric-tb-icf-screening"/>
            </parameter>
          </target>
        </rule>
        <rule>
          <name value="provenanceDisplay"/>
          <source>
            <context value="qr"/>
          </source>
          <target>
            <context value="t"/>
            <element value="display"/>
            <transform value="copy"/>
            <parameter>
              <valueString value="Paediatric TB intensified case finding screening tool"/>
            </parameter>
          </target>
        </rule>
      </rule>
    </rule>
    <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>
      <documentation value="Every tag the response carries, onto the resource. `meta` is 0..1, so this&#xD;&#xA;lands on the same meta the rule above created rather than a second one."/>
    </rule>
  </group>
</StructureMap>