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

<StructureMap xmlns="http://hl7.org/fhir">
  <id value="ExtractIntakeOutputRecord"/>
  <text>
    <status value="generated"/><div xmlns="http://www.w3.org/1999/xhtml"><p class="res-header-id"><b>Generated Narrative: StructureMap ExtractIntakeOutputRecord</b></p><a name="ExtractIntakeOutputRecord"> </a><a name="hcExtractIntakeOutputRecord"> </a><pre class="fml">
<span style="color: #cc00cc">/// <b>url</b> = </span><span style="color: blue">'https://fhir.slade360.co.ke/fhir/StructureMap/ExtractIntakeOutputRecord'</span>
<span style="color: #cc00cc">/// <b>name</b> = </span><span style="color: blue">'ExtractIntakeOutputRecord'</span>
<span style="color: #cc00cc">/// <b>title</b> = </span><span style="color: blue">'Intake and Output Record 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 24-hour totals under LOINC 9108-2 fluid intake and 9192-6 urine output, plus the balance and each hourly row as its own pair of panels. The sheet\'s own instruction is to add the columns and circle the figure; the form computes it instead, because that circled number at the end of a twelve-hour shift is the most error-prone arithmetic on any ward chart -- and the hourly rows are still extracted so the total can be audited against them.'</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>group </b>ExtractIntakeOutputRecord<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>
  qr.item<b> as </b><span style="color: maroon">g</span><b> where </b><span style="color: navy">(</span>linkId = 'totals'<span style="color: navy">)</span><b> then</b><span style="color: navy"> {
</span>    g.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'totals/intake') and answer.value.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>SetVitalSignsCategory<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>
      it<span style="color: navy"><b> -&gt; </b></span>obs.code<b> as </b><span style="color: maroon">cc</span><b> then</b><span style="color: navy"> {
</span>        it<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>          it<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'http://loinc.org'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
          it<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'9108-2'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
          it<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Fluid intake total 24 hour'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;code&quot;</i><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">v</span><span style="color: navy"><b> -&gt; </b></span>obs.value = <b>create</b><span style="color: navy">(</span><span style="color: blue">'Quantity'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">q</span><b> then</b><span style="color: navy"> {
</span>          v<span style="color: navy"><b> -&gt; </b></span>q.value = <span style="color: maroon">v</span> <i>&quot;qValue&quot;</i><span style="color: navy">;</span>
          v<span style="color: navy"><b> -&gt; </b></span>q.unit = <span style="color: blue">'mL'</span> <i>&quot;qUnit&quot;</i><span style="color: navy">;</span>
          v<span style="color: navy"><b> -&gt; </b></span>q.system = <span style="color: blue">'http://unitsofmeasure.org'</span> <i>&quot;qSystem&quot;</i><span style="color: navy">;</span>
          v<span style="color: navy"><b> -&gt; </b></span>q.code = <span style="color: blue">'mL'</span> <i>&quot;qCode&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;quantity&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span><span style="color: navy">;</span>
      it<span style="color: navy"><b> -&gt; </b></span> obs.note<b> as </b><span style="color: maroon">n</span><span style="color: navy">, </span> n.text = <span style="color: blue">'Computed from the hourly rows rather than added by hand.'</span> <i>&quot;note&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;measureq_9108_2&quot;</i><span style="color: navy">;</span>
    g.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'totals/output') and answer.value.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>SetVitalSignsCategory<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>
      it<span style="color: navy"><b> -&gt; </b></span>obs.code<b> as </b><span style="color: maroon">cc</span><b> then</b><span style="color: navy"> {
</span>        it<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>          it<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
          it<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'fluid-balance-fluid-output-total-24-hours'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
          it<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Fluid output total 24 hours'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;code&quot;</i><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">v</span><span style="color: navy"><b> -&gt; </b></span>obs.value = <b>create</b><span style="color: navy">(</span><span style="color: blue">'Quantity'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">q</span><b> then</b><span style="color: navy"> {
</span>          v<span style="color: navy"><b> -&gt; </b></span>q.value = <span style="color: maroon">v</span> <i>&quot;qValue&quot;</i><span style="color: navy">;</span>
          v<span style="color: navy"><b> -&gt; </b></span>q.unit = <span style="color: blue">'mL'</span> <i>&quot;qUnit&quot;</i><span style="color: navy">;</span>
          v<span style="color: navy"><b> -&gt; </b></span>q.system = <span style="color: blue">'http://unitsofmeasure.org'</span> <i>&quot;qSystem&quot;</i><span style="color: navy">;</span>
          v<span style="color: navy"><b> -&gt; </b></span>q.code = <span style="color: blue">'mL'</span> <i>&quot;qCode&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;quantity&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;measureq_fluid_balance&quot;</i><span style="color: navy">;</span>
    g.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'totals/balance') and answer.value.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>SetVitalSignsCategory<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>
      it<span style="color: navy"><b> -&gt; </b></span>obs.code<b> as </b><span style="color: maroon">cc</span><b> then</b><span style="color: navy"> {
</span>        it<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>          it<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
          it<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'fluid-balance-over-24-hours'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
          it<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Fluid balance over 24 hours'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;code&quot;</i><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">v</span><span style="color: navy"><b> -&gt; </b></span>obs.value = <b>create</b><span style="color: navy">(</span><span style="color: blue">'Quantity'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">q</span><b> then</b><span style="color: navy"> {
</span>          v<span style="color: navy"><b> -&gt; </b></span>q.value = <span style="color: maroon">v</span> <i>&quot;qValue&quot;</i><span style="color: navy">;</span>
          v<span style="color: navy"><b> -&gt; </b></span>q.unit = <span style="color: blue">'mL'</span> <i>&quot;qUnit&quot;</i><span style="color: navy">;</span>
          v<span style="color: navy"><b> -&gt; </b></span>q.system = <span style="color: blue">'http://unitsofmeasure.org'</span> <i>&quot;qSystem&quot;</i><span style="color: navy">;</span>
          v<span style="color: navy"><b> -&gt; </b></span>q.code = <span style="color: blue">'mL'</span> <i>&quot;qCode&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;quantity&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;measureq_fluid_balance2&quot;</i><span style="color: navy">;</span>
    g.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'totals/remarks') and answer.value.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>
      it<span style="color: navy"><b> -&gt; </b></span>obs.code<b> as </b><span style="color: maroon">cc</span><b> then</b><span style="color: navy"> {
</span>        it<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>          it<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
          it<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'fluid-balance-remarks-on-the-intake-and-output-record'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
          it<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Remarks on the intake and output record'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;code&quot;</i><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">txt</span><span style="color: navy"><b> -&gt; </b></span> obs.note<b> as </b><span style="color: maroon">n</span><span style="color: navy">, </span> n.text = <span style="color: maroon">txt</span> <i>&quot;text&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;narr_fluid_balance_remarks_on_the_intake_and_output_record&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">}</span> <i>&quot;totalsGroup&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">// </span><span style="color: green">The urine output on its own, under its own LOINC code and summed from the</span>
  <span style="color: navy">// </span><span style="color: green">rows. Urine output is what says whether a kidney is still working and it</span>
  <span style="color: navy">// </span><span style="color: green">is asked for on its own, not as half of a balance.</span>
  qr<b> where </b><span style="color: navy">(</span>item.where(linkId = 'hour').item.where(linkId = 'hour/output').item.where(linkId = 'hour/output/urine').answer.value.ofType(Quantity).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>SetVitalSignsCategory<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">obs</span><span style="color: navy">)</span> <i>&quot;category&quot;</i><span style="color: navy">;</span>
    qr<span style="color: navy"><b> -&gt; </b></span>obs.code<b> as </b><span style="color: maroon">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">cg</span><b> then</b><span style="color: navy"> {
</span>        qr<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'http://loinc.org'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
        qr<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'9192-6'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
        qr<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Urine output 24 hour'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;code&quot;</i><span style="color: navy">;</span>
    qr<span style="color: navy"><b> -&gt; </b></span>obs.value = <b>create</b><span style="color: navy">(</span><span style="color: blue">'Quantity'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">q</span><b> then</b><span style="color: navy"> {
</span>      qr<span style="color: navy"><b> -&gt; </b></span>q.value = evaluate<span style="color: navy">(</span>qr<span style="color: navy">, </span>item.where(linkId = 'hour').item.where(linkId = 'hour/output').item.where(linkId = 'hour/output/urine').answer.value.ofType(Quantity).value.aggregate($this + $total, 0)<span style="color: navy">)</span> <i>&quot;qValue&quot;</i><span style="color: navy">;</span>
      qr<span style="color: navy"><b> -&gt; </b></span>q.unit = <span style="color: blue">'mL'</span> <i>&quot;qUnit&quot;</i><span style="color: navy">;</span>
      qr<span style="color: navy"><b> -&gt; </b></span>q.system = <span style="color: blue">'http://unitsofmeasure.org'</span> <i>&quot;qSystem&quot;</i><span style="color: navy">;</span>
      qr<span style="color: navy"><b> -&gt; </b></span>q.code = <span style="color: blue">'mL'</span> <i>&quot;qCode&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;quantity&quot;</i><span style="color: navy">;</span>
    qr<span style="color: navy"><b> -&gt; </b></span> obs.note<b> as </b><span style="color: maroon">n</span><span style="color: navy">, </span> n.text = <span style="color: blue">'Summed from the hourly rows on the intake and output record'</span> <i>&quot;sumNote&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">}</span> <i>&quot;urineOutputTotal&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">// </span><span style="color: green">── One hourly row ──────────────────────────────────────────────────────</span>
  qr.item<b> as </b><span style="color: maroon">row</span><b> where </b><span style="color: navy">(</span>linkId = 'hour'<span style="color: navy">)</span><b> then</b><span style="color: navy"> {
</span>    row.item<b> as </b><span style="color: maroon">i</span><b> where </b><span style="color: navy">(</span>(linkId = 'hour/intake') and item.answer.value.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>SetVitalSignsCategory<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>
      i<span style="color: navy"><b> -&gt; </b></span>obs.code<b> as </b><span style="color: maroon">cc</span><b> then</b><span style="color: navy"> {
</span>        i<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>          i<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
          i<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'fluid-balance-hourly-fluid-intake'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
          i<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Hourly fluid intake'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;code&quot;</i><span style="color: navy">;</span>
      i.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'hour/intake/oral') 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">cc</span><b> then</b><span style="color: navy"> {
</span>          it<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>            it<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
            it<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'fluid-balance-oral-fluid-volume'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
            it<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Oral fluid volume'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;code&quot;</i><span style="color: navy">;</span>
        it<span style="color: navy"><b> -&gt; </b></span>comp<b> then </b>SetComponentValue<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;value&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;comp_fluid_balance_oral_fluid_volume&quot;</i><span style="color: navy">;</span>
      i.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'hour/intake/iv-infusion-name') 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">cc</span><b> then</b><span style="color: navy"> {
</span>          it<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>            it<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
            it<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'fluid-balance-iv-infusion-given'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
            it<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'IV infusion given'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;code&quot;</i><span style="color: navy">;</span>
        it<span style="color: navy"><b> -&gt; </b></span>comp<b> then </b>SetComponentValue<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;value&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;comp_fluid_balance_iv_infusion_given&quot;</i><span style="color: navy">;</span>
      i.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'hour/intake/iv-amount') 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">cc</span><b> then</b><span style="color: navy"> {
</span>          it<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>            it<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
            it<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'fluid-balance-iv-fluid-volume'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
            it<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'IV fluid volume'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;code&quot;</i><span style="color: navy">;</span>
        it<span style="color: navy"><b> -&gt; </b></span>comp<b> then </b>SetComponentValue<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;value&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;comp_fluid_balance_iv_fluid_volume&quot;</i><span style="color: navy">;</span>
      i.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'hour/intake/ng-feeding') 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">cc</span><b> then</b><span style="color: navy"> {
</span>          it<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>            it<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
            it<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'fluid-balance-nasogastric-feed-volume'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
            it<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Nasogastric feed volume'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;code&quot;</i><span style="color: navy">;</span>
        it<span style="color: navy"><b> -&gt; </b></span>comp<b> then </b>SetComponentValue<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;value&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;comp_fluid_balance_nasogastric_feed_volume&quot;</i><span style="color: navy">;</span>
      row<span style="color: navy"><b> -&gt; </b></span>obs<b> then </b>SetIoRowTime<span style="color: navy">(</span><span style="color: maroon">row</span><span style="color: navy">, </span><span style="color: maroon">obs</span><span style="color: navy">)</span> <i>&quot;rowTime&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;hourlyIntake&quot;</i><span style="color: navy">;</span>
    row.item<b> as </b><span style="color: maroon">o</span><b> where </b><span style="color: navy">(</span>(linkId = 'hour/output') and item.answer.value.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>SetVitalSignsCategory<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>
      o<span style="color: navy"><b> -&gt; </b></span>obs.code<b> as </b><span style="color: maroon">cc</span><b> then</b><span style="color: navy"> {
</span>        o<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>          o<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
          o<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'fluid-balance-hourly-fluid-output'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
          o<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Hourly fluid output'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;code&quot;</i><span style="color: navy">;</span>
      o.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'hour/output/urine') 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">cc</span><b> then</b><span style="color: navy"> {
</span>          it<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>            it<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
            it<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'fluid-balance-urine-volume'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
            it<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Urine volume'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;code&quot;</i><span style="color: navy">;</span>
        it<span style="color: navy"><b> -&gt; </b></span>comp<b> then </b>SetComponentValue<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;value&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;comp_fluid_balance_urine_volume&quot;</i><span style="color: navy">;</span>
      o.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'hour/output/stools') 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">cc</span><b> then</b><span style="color: navy"> {
</span>          it<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>            it<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
            it<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'fluid-balance-stool-volume'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
            it<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Stool volume'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;code&quot;</i><span style="color: navy">;</span>
        it<span style="color: navy"><b> -&gt; </b></span>comp<b> then </b>SetComponentValue<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;value&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;comp_fluid_balance_stool_volume&quot;</i><span style="color: navy">;</span>
      o.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'hour/output/vomit') 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">cc</span><b> then</b><span style="color: navy"> {
</span>          it<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>            it<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
            it<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'fluid-balance-vomit-volume'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
            it<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Vomit volume'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;code&quot;</i><span style="color: navy">;</span>
        it<span style="color: navy"><b> -&gt; </b></span>comp<b> then </b>SetComponentValue<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;value&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;comp_fluid_balance_vomit_volume&quot;</i><span style="color: navy">;</span>
      o.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'hour/output/ng-suction') 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">cc</span><b> then</b><span style="color: navy"> {
</span>          it<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>            it<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
            it<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'fluid-balance-nasogastric-suction-volume'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
            it<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Nasogastric suction volume'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;code&quot;</i><span style="color: navy">;</span>
        it<span style="color: navy"><b> -&gt; </b></span>comp<b> then </b>SetComponentValue<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;value&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;comp_fluid_balance_nasogastric_suction_volume&quot;</i><span style="color: navy">;</span>
      o.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'hour/output/drainage') 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">cc</span><b> then</b><span style="color: navy"> {
</span>          it<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>            it<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
            it<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'fluid-balance-drainage-volume'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
            it<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Drainage volume'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;code&quot;</i><span style="color: navy">;</span>
        it<span style="color: navy"><b> -&gt; </b></span>comp<b> then </b>SetComponentValue<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;value&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;comp_fluid_balance_drainage_volume&quot;</i><span style="color: navy">;</span>
      row<span style="color: navy"><b> -&gt; </b></span>obs<b> then </b>SetIoRowTime<span style="color: navy">(</span><span style="color: maroon">row</span><span style="color: navy">, </span><span style="color: maroon">obs</span><span style="color: navy">)</span> <i>&quot;rowTime&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;hourlyOutput&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">}</span> <i>&quot;hourlyRows&quot;</i><span style="color: navy">;</span>
<span style="color: navy">}

</span><span style="color: navy">// </span><span style="color: green">A clock time, not a dateTime -- the sheet is one day per block with the date</span>
<span style="color: navy">// </span><span style="color: green">in its header -- so it rides as a note rather than being forced into</span>
<span style="color: navy">// </span><span style="color: green">Observation.effective as a bare time, which that element does not accept.</span>
<b>group </b>SetIoRowTime<span style="color: navy">(</span><b>source</b> <span style="color: maroon">row</span>, <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>  row.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'hour/time') and answer.value.exists()<span style="color: navy">)</span><b> then</b><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">t</span><span style="color: navy"><b> -&gt; </b></span> obs.note<b> as </b><span style="color: maroon">n</span><span style="color: navy">, </span> n.text = <span style="color: blue">'Recorded against the clock hour on the intake and output record'</span> <i>&quot;timeNote&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span><span style="color: navy">;</span>
  <span style="color: navy">}</span> <i>&quot;rowTimeRule&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><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><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>SetComponentValue<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">v</span><span style="color: navy"><b> -&gt; </b></span>comp.value = <span style="color: maroon">v</span> <i>&quot;plainValue&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>SetVitalSignsCategory<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">'vital-signs'</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">'Vital Signs'</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><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 form that reopens mid-admission recalls its own earlier</span>
<span style="color: navy">// </span><span style="color: green">entries and not another form's. The second copies the tenant tags off the</span>
<span style="color: navy">// </span><span style="color: green">response, because nothing else on 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">'intake-output-record'</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">'Intake and output record'</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/ExtractIntakeOutputRecord"/>
  <version value="0.1.0"/>
  <name value="ExtractIntakeOutputRecord"/>
  <title value="Intake and Output Record 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 24-hour totals under LOINC 9108-2 fluid intake and 9192-6 urine output, plus the balance and each hourly row as its own pair of panels. The sheet's own instruction is to add the columns and circle the figure; the form computes it instead, because that circled number at the end of a twelve-hour shift is the most error-prone arithmetic on any ward chart -- and the hourly rows are still extracted so the total can be audited against them."/>
  <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>
  <group>
    <name value="ExtractIntakeOutputRecord"/>
    <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="totalsGroup"/>
      <source>
        <context value="qr"/>
        <element value="item"/>
        <variable value="g"/>
        <condition value="linkId = 'totals'"/>
      </source>
      <rule>
        <name value="measureq_9108_2"/>
        <source>
          <context value="g"/>
          <element value="item"/>
          <variable value="it"/>
          <condition value="(linkId = 'totals/intake') and answer.value.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="SetVitalSignsCategory"/>
            <parameter>
              <valueId value="qr"/>
            </parameter>
            <parameter>
              <valueId value="obs"/>
            </parameter>
          </dependent>
        </rule>
        <rule>
          <name value="code"/>
          <source>
            <context value="it"/>
          </source>
          <target>
            <context value="obs"/>
            <element value="code"/>
            <variable value="cc"/>
          </target>
          <rule>
            <name value="coding"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="cc"/>
              <element value="coding"/>
              <variable value="cg"/>
            </target>
            <rule>
              <name value="sys"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="system"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="http://loinc.org"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="cd"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="code"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="9108-2"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="dsp"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="display"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="Fluid intake total 24 hour"/>
                </parameter>
              </target>
            </rule>
          </rule>
        </rule>
        <rule>
          <name value="answer"/>
          <source>
            <context value="it"/>
            <element value="answer"/>
            <listMode value="first"/>
            <variable value="a"/>
          </source>
          <rule>
            <name value="quantity"/>
            <source>
              <context value="a"/>
              <element value="value"/>
              <variable value="v"/>
            </source>
            <target>
              <context value="obs"/>
              <element value="value"/>
              <variable value="q"/>
              <transform value="create"/>
              <parameter>
                <valueString value="Quantity"/>
              </parameter>
            </target>
            <rule>
              <name value="qValue"/>
              <source>
                <context value="v"/>
              </source>
              <target>
                <context value="q"/>
                <element value="value"/>
                <transform value="copy"/>
                <parameter>
                  <valueId value="v"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="qUnit"/>
              <source>
                <context value="v"/>
              </source>
              <target>
                <context value="q"/>
                <element value="unit"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="mL"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="qSystem"/>
              <source>
                <context value="v"/>
              </source>
              <target>
                <context value="q"/>
                <element value="system"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="http://unitsofmeasure.org"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="qCode"/>
              <source>
                <context value="v"/>
              </source>
              <target>
                <context value="q"/>
                <element value="code"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="mL"/>
                </parameter>
              </target>
            </rule>
          </rule>
        </rule>
        <rule>
          <name value="note"/>
          <source>
            <context value="it"/>
          </source>
          <target>
            <context value="obs"/>
            <element value="note"/>
            <variable value="n"/>
          </target>
          <target>
            <context value="n"/>
            <element value="text"/>
            <transform value="copy"/>
            <parameter>
              <valueString value="Computed from the hourly rows rather than added by hand."/>
            </parameter>
          </target>
        </rule>
      </rule>
      <rule>
        <name value="measureq_fluid_balance"/>
        <source>
          <context value="g"/>
          <element value="item"/>
          <variable value="it"/>
          <condition value="(linkId = 'totals/output') and answer.value.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="SetVitalSignsCategory"/>
            <parameter>
              <valueId value="qr"/>
            </parameter>
            <parameter>
              <valueId value="obs"/>
            </parameter>
          </dependent>
        </rule>
        <rule>
          <name value="code"/>
          <source>
            <context value="it"/>
          </source>
          <target>
            <context value="obs"/>
            <element value="code"/>
            <variable value="cc"/>
          </target>
          <rule>
            <name value="coding"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="cc"/>
              <element value="coding"/>
              <variable value="cg"/>
            </target>
            <rule>
              <name value="sys"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="system"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="cd"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="code"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="fluid-balance-fluid-output-total-24-hours"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="dsp"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="display"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="Fluid output total 24 hours"/>
                </parameter>
              </target>
            </rule>
          </rule>
        </rule>
        <rule>
          <name value="answer"/>
          <source>
            <context value="it"/>
            <element value="answer"/>
            <listMode value="first"/>
            <variable value="a"/>
          </source>
          <rule>
            <name value="quantity"/>
            <source>
              <context value="a"/>
              <element value="value"/>
              <variable value="v"/>
            </source>
            <target>
              <context value="obs"/>
              <element value="value"/>
              <variable value="q"/>
              <transform value="create"/>
              <parameter>
                <valueString value="Quantity"/>
              </parameter>
            </target>
            <rule>
              <name value="qValue"/>
              <source>
                <context value="v"/>
              </source>
              <target>
                <context value="q"/>
                <element value="value"/>
                <transform value="copy"/>
                <parameter>
                  <valueId value="v"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="qUnit"/>
              <source>
                <context value="v"/>
              </source>
              <target>
                <context value="q"/>
                <element value="unit"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="mL"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="qSystem"/>
              <source>
                <context value="v"/>
              </source>
              <target>
                <context value="q"/>
                <element value="system"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="http://unitsofmeasure.org"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="qCode"/>
              <source>
                <context value="v"/>
              </source>
              <target>
                <context value="q"/>
                <element value="code"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="mL"/>
                </parameter>
              </target>
            </rule>
          </rule>
        </rule>
      </rule>
      <rule>
        <name value="measureq_fluid_balance2"/>
        <source>
          <context value="g"/>
          <element value="item"/>
          <variable value="it"/>
          <condition value="(linkId = 'totals/balance') and answer.value.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="SetVitalSignsCategory"/>
            <parameter>
              <valueId value="qr"/>
            </parameter>
            <parameter>
              <valueId value="obs"/>
            </parameter>
          </dependent>
        </rule>
        <rule>
          <name value="code"/>
          <source>
            <context value="it"/>
          </source>
          <target>
            <context value="obs"/>
            <element value="code"/>
            <variable value="cc"/>
          </target>
          <rule>
            <name value="coding"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="cc"/>
              <element value="coding"/>
              <variable value="cg"/>
            </target>
            <rule>
              <name value="sys"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="system"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="cd"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="code"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="fluid-balance-over-24-hours"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="dsp"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="display"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="Fluid balance over 24 hours"/>
                </parameter>
              </target>
            </rule>
          </rule>
        </rule>
        <rule>
          <name value="answer"/>
          <source>
            <context value="it"/>
            <element value="answer"/>
            <listMode value="first"/>
            <variable value="a"/>
          </source>
          <rule>
            <name value="quantity"/>
            <source>
              <context value="a"/>
              <element value="value"/>
              <variable value="v"/>
            </source>
            <target>
              <context value="obs"/>
              <element value="value"/>
              <variable value="q"/>
              <transform value="create"/>
              <parameter>
                <valueString value="Quantity"/>
              </parameter>
            </target>
            <rule>
              <name value="qValue"/>
              <source>
                <context value="v"/>
              </source>
              <target>
                <context value="q"/>
                <element value="value"/>
                <transform value="copy"/>
                <parameter>
                  <valueId value="v"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="qUnit"/>
              <source>
                <context value="v"/>
              </source>
              <target>
                <context value="q"/>
                <element value="unit"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="mL"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="qSystem"/>
              <source>
                <context value="v"/>
              </source>
              <target>
                <context value="q"/>
                <element value="system"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="http://unitsofmeasure.org"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="qCode"/>
              <source>
                <context value="v"/>
              </source>
              <target>
                <context value="q"/>
                <element value="code"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="mL"/>
                </parameter>
              </target>
            </rule>
          </rule>
        </rule>
      </rule>
      <rule>
        <name value="narr_fluid_balance_remarks_on_the_intake_and_output_record"/>
        <source>
          <context value="g"/>
          <element value="item"/>
          <variable value="it"/>
          <condition value="(linkId = 'totals/remarks') and answer.value.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="it"/>
          </source>
          <target>
            <context value="obs"/>
            <element value="code"/>
            <variable value="cc"/>
          </target>
          <rule>
            <name value="coding"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="cc"/>
              <element value="coding"/>
              <variable value="cg"/>
            </target>
            <rule>
              <name value="sys"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="system"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="cd"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="code"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="fluid-balance-remarks-on-the-intake-and-output-record"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="dsp"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="display"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="Remarks on the intake and output record"/>
                </parameter>
              </target>
            </rule>
          </rule>
        </rule>
        <rule>
          <name value="answer"/>
          <source>
            <context value="it"/>
            <element value="answer"/>
            <listMode value="first"/>
            <variable value="a"/>
          </source>
          <rule>
            <name value="text"/>
            <source>
              <context value="a"/>
              <element value="value"/>
              <variable value="txt"/>
            </source>
            <target>
              <context value="obs"/>
              <element value="note"/>
              <variable value="n"/>
            </target>
            <target>
              <context value="n"/>
              <element value="text"/>
              <transform value="copy"/>
              <parameter>
                <valueId value="txt"/>
              </parameter>
            </target>
          </rule>
        </rule>
      </rule>
    </rule>
    <rule>
      <name value="urineOutputTotal"/>
      <source>
        <context value="qr"/>
        <condition value="item.where(linkId = 'hour').item.where(linkId = 'hour/output').item.where(linkId = 'hour/output/urine').answer.value.ofType(Quantity).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="SetVitalSignsCategory"/>
          <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="cc"/>
        </target>
        <rule>
          <name value="coding"/>
          <source>
            <context value="qr"/>
          </source>
          <target>
            <context value="cc"/>
            <element value="coding"/>
            <variable value="cg"/>
          </target>
          <rule>
            <name value="sys"/>
            <source>
              <context value="qr"/>
            </source>
            <target>
              <context value="cg"/>
              <element value="system"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="http://loinc.org"/>
              </parameter>
            </target>
          </rule>
          <rule>
            <name value="cd"/>
            <source>
              <context value="qr"/>
            </source>
            <target>
              <context value="cg"/>
              <element value="code"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="9192-6"/>
              </parameter>
            </target>
          </rule>
          <rule>
            <name value="dsp"/>
            <source>
              <context value="qr"/>
            </source>
            <target>
              <context value="cg"/>
              <element value="display"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="Urine output 24 hour"/>
              </parameter>
            </target>
          </rule>
        </rule>
      </rule>
      <rule>
        <name value="quantity"/>
        <source>
          <context value="qr"/>
        </source>
        <target>
          <context value="obs"/>
          <element value="value"/>
          <variable value="q"/>
          <transform value="create"/>
          <parameter>
            <valueString value="Quantity"/>
          </parameter>
        </target>
        <rule>
          <name value="qValue"/>
          <source>
            <context value="qr"/>
          </source>
          <target>
            <context value="q"/>
            <element value="value"/>
            <transform value="evaluate"/>
            <parameter>
              <valueId value="qr"/>
            </parameter>
            <parameter>
              <valueString value="item.where(linkId = 'hour').item.where(linkId = 'hour/output').item.where(linkId = 'hour/output/urine').answer.value.ofType(Quantity).value.aggregate($this + $total, 0)"/>
            </parameter>
          </target>
        </rule>
        <rule>
          <name value="qUnit"/>
          <source>
            <context value="qr"/>
          </source>
          <target>
            <context value="q"/>
            <element value="unit"/>
            <transform value="copy"/>
            <parameter>
              <valueString value="mL"/>
            </parameter>
          </target>
        </rule>
        <rule>
          <name value="qSystem"/>
          <source>
            <context value="qr"/>
          </source>
          <target>
            <context value="q"/>
            <element value="system"/>
            <transform value="copy"/>
            <parameter>
              <valueString value="http://unitsofmeasure.org"/>
            </parameter>
          </target>
        </rule>
        <rule>
          <name value="qCode"/>
          <source>
            <context value="qr"/>
          </source>
          <target>
            <context value="q"/>
            <element value="code"/>
            <transform value="copy"/>
            <parameter>
              <valueString value="mL"/>
            </parameter>
          </target>
        </rule>
      </rule>
      <rule>
        <name value="sumNote"/>
        <source>
          <context value="qr"/>
        </source>
        <target>
          <context value="obs"/>
          <element value="note"/>
          <variable value="n"/>
        </target>
        <target>
          <context value="n"/>
          <element value="text"/>
          <transform value="copy"/>
          <parameter>
            <valueString value="Summed from the hourly rows on the intake and output record"/>
          </parameter>
        </target>
      </rule>
      <documentation value="The urine output on its own, under its own LOINC code and summed from the&#xD;&#xA;rows. Urine output is what says whether a kidney is still working and it&#xD;&#xA;is asked for on its own, not as half of a balance."/>
    </rule>
    <rule>
      <name value="hourlyRows"/>
      <source>
        <context value="qr"/>
        <element value="item"/>
        <variable value="row"/>
        <condition value="linkId = 'hour'"/>
      </source>
      <rule>
        <name value="hourlyIntake"/>
        <source>
          <context value="row"/>
          <element value="item"/>
          <variable value="i"/>
          <condition value="(linkId = 'hour/intake') and item.answer.value.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="SetVitalSignsCategory"/>
            <parameter>
              <valueId value="qr"/>
            </parameter>
            <parameter>
              <valueId value="obs"/>
            </parameter>
          </dependent>
        </rule>
        <rule>
          <name value="code"/>
          <source>
            <context value="i"/>
          </source>
          <target>
            <context value="obs"/>
            <element value="code"/>
            <variable value="cc"/>
          </target>
          <rule>
            <name value="coding"/>
            <source>
              <context value="i"/>
            </source>
            <target>
              <context value="cc"/>
              <element value="coding"/>
              <variable value="cg"/>
            </target>
            <rule>
              <name value="sys"/>
              <source>
                <context value="i"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="system"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="cd"/>
              <source>
                <context value="i"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="code"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="fluid-balance-hourly-fluid-intake"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="dsp"/>
              <source>
                <context value="i"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="display"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="Hourly fluid intake"/>
                </parameter>
              </target>
            </rule>
          </rule>
        </rule>
        <rule>
          <name value="comp_fluid_balance_oral_fluid_volume"/>
          <source>
            <context value="i"/>
            <element value="item"/>
            <variable value="it"/>
            <condition value="(linkId = 'hour/intake/oral') and answer.value.exists()"/>
          </source>
          <target>
            <context value="obs"/>
            <element value="component"/>
            <variable value="comp"/>
          </target>
          <rule>
            <name value="code"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="comp"/>
              <element value="code"/>
              <variable value="cc"/>
            </target>
            <rule>
              <name value="coding"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cc"/>
                <element value="coding"/>
                <variable value="cg"/>
              </target>
              <rule>
                <name value="sys"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="system"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="cd"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="code"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="fluid-balance-oral-fluid-volume"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="dsp"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="display"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="Oral fluid volume"/>
                  </parameter>
                </target>
              </rule>
            </rule>
          </rule>
          <rule>
            <name value="value"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="comp"/>
            </target>
            <dependent>
              <name value="SetComponentValue"/>
              <parameter>
                <valueId value="it"/>
              </parameter>
              <parameter>
                <valueId value="comp"/>
              </parameter>
            </dependent>
          </rule>
        </rule>
        <rule>
          <name value="comp_fluid_balance_iv_infusion_given"/>
          <source>
            <context value="i"/>
            <element value="item"/>
            <variable value="it"/>
            <condition value="(linkId = 'hour/intake/iv-infusion-name') and answer.value.exists()"/>
          </source>
          <target>
            <context value="obs"/>
            <element value="component"/>
            <variable value="comp"/>
          </target>
          <rule>
            <name value="code"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="comp"/>
              <element value="code"/>
              <variable value="cc"/>
            </target>
            <rule>
              <name value="coding"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cc"/>
                <element value="coding"/>
                <variable value="cg"/>
              </target>
              <rule>
                <name value="sys"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="system"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="cd"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="code"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="fluid-balance-iv-infusion-given"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="dsp"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="display"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="IV infusion given"/>
                  </parameter>
                </target>
              </rule>
            </rule>
          </rule>
          <rule>
            <name value="value"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="comp"/>
            </target>
            <dependent>
              <name value="SetComponentValue"/>
              <parameter>
                <valueId value="it"/>
              </parameter>
              <parameter>
                <valueId value="comp"/>
              </parameter>
            </dependent>
          </rule>
        </rule>
        <rule>
          <name value="comp_fluid_balance_iv_fluid_volume"/>
          <source>
            <context value="i"/>
            <element value="item"/>
            <variable value="it"/>
            <condition value="(linkId = 'hour/intake/iv-amount') and answer.value.exists()"/>
          </source>
          <target>
            <context value="obs"/>
            <element value="component"/>
            <variable value="comp"/>
          </target>
          <rule>
            <name value="code"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="comp"/>
              <element value="code"/>
              <variable value="cc"/>
            </target>
            <rule>
              <name value="coding"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cc"/>
                <element value="coding"/>
                <variable value="cg"/>
              </target>
              <rule>
                <name value="sys"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="system"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="cd"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="code"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="fluid-balance-iv-fluid-volume"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="dsp"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="display"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="IV fluid volume"/>
                  </parameter>
                </target>
              </rule>
            </rule>
          </rule>
          <rule>
            <name value="value"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="comp"/>
            </target>
            <dependent>
              <name value="SetComponentValue"/>
              <parameter>
                <valueId value="it"/>
              </parameter>
              <parameter>
                <valueId value="comp"/>
              </parameter>
            </dependent>
          </rule>
        </rule>
        <rule>
          <name value="comp_fluid_balance_nasogastric_feed_volume"/>
          <source>
            <context value="i"/>
            <element value="item"/>
            <variable value="it"/>
            <condition value="(linkId = 'hour/intake/ng-feeding') and answer.value.exists()"/>
          </source>
          <target>
            <context value="obs"/>
            <element value="component"/>
            <variable value="comp"/>
          </target>
          <rule>
            <name value="code"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="comp"/>
              <element value="code"/>
              <variable value="cc"/>
            </target>
            <rule>
              <name value="coding"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cc"/>
                <element value="coding"/>
                <variable value="cg"/>
              </target>
              <rule>
                <name value="sys"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="system"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="cd"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="code"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="fluid-balance-nasogastric-feed-volume"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="dsp"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="display"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="Nasogastric feed volume"/>
                  </parameter>
                </target>
              </rule>
            </rule>
          </rule>
          <rule>
            <name value="value"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="comp"/>
            </target>
            <dependent>
              <name value="SetComponentValue"/>
              <parameter>
                <valueId value="it"/>
              </parameter>
              <parameter>
                <valueId value="comp"/>
              </parameter>
            </dependent>
          </rule>
        </rule>
        <rule>
          <name value="rowTime"/>
          <source>
            <context value="row"/>
          </source>
          <target>
            <context value="obs"/>
          </target>
          <dependent>
            <name value="SetIoRowTime"/>
            <parameter>
              <valueId value="row"/>
            </parameter>
            <parameter>
              <valueId value="obs"/>
            </parameter>
          </dependent>
        </rule>
      </rule>
      <rule>
        <name value="hourlyOutput"/>
        <source>
          <context value="row"/>
          <element value="item"/>
          <variable value="o"/>
          <condition value="(linkId = 'hour/output') and item.answer.value.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="SetVitalSignsCategory"/>
            <parameter>
              <valueId value="qr"/>
            </parameter>
            <parameter>
              <valueId value="obs"/>
            </parameter>
          </dependent>
        </rule>
        <rule>
          <name value="code"/>
          <source>
            <context value="o"/>
          </source>
          <target>
            <context value="obs"/>
            <element value="code"/>
            <variable value="cc"/>
          </target>
          <rule>
            <name value="coding"/>
            <source>
              <context value="o"/>
            </source>
            <target>
              <context value="cc"/>
              <element value="coding"/>
              <variable value="cg"/>
            </target>
            <rule>
              <name value="sys"/>
              <source>
                <context value="o"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="system"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="cd"/>
              <source>
                <context value="o"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="code"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="fluid-balance-hourly-fluid-output"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="dsp"/>
              <source>
                <context value="o"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="display"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="Hourly fluid output"/>
                </parameter>
              </target>
            </rule>
          </rule>
        </rule>
        <rule>
          <name value="comp_fluid_balance_urine_volume"/>
          <source>
            <context value="o"/>
            <element value="item"/>
            <variable value="it"/>
            <condition value="(linkId = 'hour/output/urine') and answer.value.exists()"/>
          </source>
          <target>
            <context value="obs"/>
            <element value="component"/>
            <variable value="comp"/>
          </target>
          <rule>
            <name value="code"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="comp"/>
              <element value="code"/>
              <variable value="cc"/>
            </target>
            <rule>
              <name value="coding"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cc"/>
                <element value="coding"/>
                <variable value="cg"/>
              </target>
              <rule>
                <name value="sys"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="system"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="cd"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="code"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="fluid-balance-urine-volume"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="dsp"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="display"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="Urine volume"/>
                  </parameter>
                </target>
              </rule>
            </rule>
          </rule>
          <rule>
            <name value="value"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="comp"/>
            </target>
            <dependent>
              <name value="SetComponentValue"/>
              <parameter>
                <valueId value="it"/>
              </parameter>
              <parameter>
                <valueId value="comp"/>
              </parameter>
            </dependent>
          </rule>
        </rule>
        <rule>
          <name value="comp_fluid_balance_stool_volume"/>
          <source>
            <context value="o"/>
            <element value="item"/>
            <variable value="it"/>
            <condition value="(linkId = 'hour/output/stools') and answer.value.exists()"/>
          </source>
          <target>
            <context value="obs"/>
            <element value="component"/>
            <variable value="comp"/>
          </target>
          <rule>
            <name value="code"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="comp"/>
              <element value="code"/>
              <variable value="cc"/>
            </target>
            <rule>
              <name value="coding"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cc"/>
                <element value="coding"/>
                <variable value="cg"/>
              </target>
              <rule>
                <name value="sys"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="system"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="cd"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="code"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="fluid-balance-stool-volume"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="dsp"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="display"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="Stool volume"/>
                  </parameter>
                </target>
              </rule>
            </rule>
          </rule>
          <rule>
            <name value="value"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="comp"/>
            </target>
            <dependent>
              <name value="SetComponentValue"/>
              <parameter>
                <valueId value="it"/>
              </parameter>
              <parameter>
                <valueId value="comp"/>
              </parameter>
            </dependent>
          </rule>
        </rule>
        <rule>
          <name value="comp_fluid_balance_vomit_volume"/>
          <source>
            <context value="o"/>
            <element value="item"/>
            <variable value="it"/>
            <condition value="(linkId = 'hour/output/vomit') and answer.value.exists()"/>
          </source>
          <target>
            <context value="obs"/>
            <element value="component"/>
            <variable value="comp"/>
          </target>
          <rule>
            <name value="code"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="comp"/>
              <element value="code"/>
              <variable value="cc"/>
            </target>
            <rule>
              <name value="coding"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cc"/>
                <element value="coding"/>
                <variable value="cg"/>
              </target>
              <rule>
                <name value="sys"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="system"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="cd"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="code"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="fluid-balance-vomit-volume"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="dsp"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="display"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="Vomit volume"/>
                  </parameter>
                </target>
              </rule>
            </rule>
          </rule>
          <rule>
            <name value="value"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="comp"/>
            </target>
            <dependent>
              <name value="SetComponentValue"/>
              <parameter>
                <valueId value="it"/>
              </parameter>
              <parameter>
                <valueId value="comp"/>
              </parameter>
            </dependent>
          </rule>
        </rule>
        <rule>
          <name value="comp_fluid_balance_nasogastric_suction_volume"/>
          <source>
            <context value="o"/>
            <element value="item"/>
            <variable value="it"/>
            <condition value="(linkId = 'hour/output/ng-suction') and answer.value.exists()"/>
          </source>
          <target>
            <context value="obs"/>
            <element value="component"/>
            <variable value="comp"/>
          </target>
          <rule>
            <name value="code"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="comp"/>
              <element value="code"/>
              <variable value="cc"/>
            </target>
            <rule>
              <name value="coding"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cc"/>
                <element value="coding"/>
                <variable value="cg"/>
              </target>
              <rule>
                <name value="sys"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="system"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="cd"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="code"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="fluid-balance-nasogastric-suction-volume"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="dsp"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="display"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="Nasogastric suction volume"/>
                  </parameter>
                </target>
              </rule>
            </rule>
          </rule>
          <rule>
            <name value="value"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="comp"/>
            </target>
            <dependent>
              <name value="SetComponentValue"/>
              <parameter>
                <valueId value="it"/>
              </parameter>
              <parameter>
                <valueId value="comp"/>
              </parameter>
            </dependent>
          </rule>
        </rule>
        <rule>
          <name value="comp_fluid_balance_drainage_volume"/>
          <source>
            <context value="o"/>
            <element value="item"/>
            <variable value="it"/>
            <condition value="(linkId = 'hour/output/drainage') and answer.value.exists()"/>
          </source>
          <target>
            <context value="obs"/>
            <element value="component"/>
            <variable value="comp"/>
          </target>
          <rule>
            <name value="code"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="comp"/>
              <element value="code"/>
              <variable value="cc"/>
            </target>
            <rule>
              <name value="coding"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cc"/>
                <element value="coding"/>
                <variable value="cg"/>
              </target>
              <rule>
                <name value="sys"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="system"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="cd"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="code"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="fluid-balance-drainage-volume"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="dsp"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="display"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="Drainage volume"/>
                  </parameter>
                </target>
              </rule>
            </rule>
          </rule>
          <rule>
            <name value="value"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="comp"/>
            </target>
            <dependent>
              <name value="SetComponentValue"/>
              <parameter>
                <valueId value="it"/>
              </parameter>
              <parameter>
                <valueId value="comp"/>
              </parameter>
            </dependent>
          </rule>
        </rule>
        <rule>
          <name value="rowTime"/>
          <source>
            <context value="row"/>
          </source>
          <target>
            <context value="obs"/>
          </target>
          <dependent>
            <name value="SetIoRowTime"/>
            <parameter>
              <valueId value="row"/>
            </parameter>
            <parameter>
              <valueId value="obs"/>
            </parameter>
          </dependent>
        </rule>
      </rule>
      <documentation value="── One hourly row ──────────────────────────────────────────────────────"/>
    </rule>
  </group>
  <group>
    <name value="SetIoRowTime"/>
    <documentation value="A clock time, not a dateTime -- the sheet is one day per block with the date&#xD;&#xA;in its header -- so it rides as a note rather than being forced into&#xD;&#xA;Observation.effective as a bare time, which that element does not accept."/>
    <input>
      <name value="row"/>
      <mode value="source"/>
    </input>
    <input>
      <name value="obs"/>
      <type value="Observation"/>
      <mode value="target"/>
    </input>
    <rule>
      <name value="rowTimeRule"/>
      <source>
        <context value="row"/>
        <element value="item"/>
        <variable value="it"/>
        <condition value="(linkId = 'hour/time') and answer.value.exists()"/>
      </source>
      <rule>
        <name value="answer"/>
        <source>
          <context value="it"/>
          <element value="answer"/>
          <listMode value="first"/>
          <variable value="a"/>
        </source>
        <rule>
          <name value="timeNote"/>
          <source>
            <context value="a"/>
            <element value="value"/>
            <variable value="t"/>
          </source>
          <target>
            <context value="obs"/>
            <element value="note"/>
            <variable value="n"/>
          </target>
          <target>
            <context value="n"/>
            <element value="text"/>
            <transform value="copy"/>
            <parameter>
              <valueString value="Recorded against the clock hour on the intake and output record"/>
            </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="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="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="SetComponentValue"/>
    <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="plainValue"/>
        <source>
          <context value="a"/>
          <element value="value"/>
          <variable value="v"/>
        </source>
        <target>
          <context value="comp"/>
          <element value="value"/>
          <transform value="copy"/>
          <parameter>
            <valueId value="v"/>
          </parameter>
        </target>
      </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="SetVitalSignsCategory"/>
    <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="vital-signs"/>
            </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="Vital Signs"/>
            </parameter>
          </target>
        </rule>
      </rule>
    </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 form that reopens mid-admission recalls its own earlier&#xD;&#xA;entries and not another form's. The second copies the tenant tags off the&#xD;&#xA;response, because nothing else on 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="intake-output-record"/>
            </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="Intake and output record"/>
            </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>