SGHI FHIR Profile Implementation Guide
0.1.0 - ci-build

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

: Anaesthetic Record Extraction - XML Representation

Active as of 2026-09-14

Raw xml | Download


<StructureMap xmlns="http://hl7.org/fhir">
  <id value="ExtractAnaestheticRecord"/>
  <text>
    <status value="generated"/>
    <div xmlns="http://www.w3.org/1999/xhtml"><p class="res-header-id"><b>Generated Narrative: StructureMap ExtractAnaestheticRecord</b></p><a name="ExtractAnaestheticRecord"> </a><a name="hcExtractAnaestheticRecord"> </a><pre class="fml">
<span style="color: #cc00cc">/// <b>url</b> = </span><span style="color: blue">'https://fhir.slade360.co.ke/fhir/StructureMap/ExtractAnaestheticRecord'</span>
<span style="color: #cc00cc">/// <b>name</b> = </span><span style="color: blue">'ExtractAnaestheticRecord'</span>
<span style="color: #cc00cc">/// <b>title</b> = </span><span style="color: blue">'Anaesthetic 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 anaesthetic chart out as: one Procedure for the anaesthesia itself, carrying the technique as its category, the anaesthetist as its performer and the start and completion times as its period; one Observation per timed reading taken through the case, each with its own effective time, because the paper chart is a graph and a graph is a time series; one MedicationAdministration per drug and per fluid, because those were given rather than ordered; and the estimated blood loss as its own Observation under the LOINC operation-note code, marked as an estimate.'</span>

<b>uses</b><span style="color: navy"> &quot;</span><a href="http://hl7.org/fhir/R5/questionnaireresponse.html" title="QuestionnaireResponse">http://hl7.org/fhir/StructureDefinition/QuestionnaireResponse</a><span style="color: navy">&quot; </span><b>alias </b>QR <b>as </b><b>source</b>
<b>uses</b><span style="color: navy"> &quot;</span><a href="http://hl7.org/fhir/R5/bundle.html" title="Bundle">http://hl7.org/fhir/StructureDefinition/Bundle</a><span style="color: navy">&quot; </span><b>alias </b>Bundle <b>as </b><b>target</b>
<b>uses</b><span style="color: navy"> &quot;</span><a href="http://hl7.org/fhir/R5/observation.html" title="Observation">http://hl7.org/fhir/StructureDefinition/Observation</a><span style="color: navy">&quot; </span><b>alias </b>Observation <b>as </b><b>target</b>
<b>uses</b><span style="color: navy"> &quot;</span><a href="http://hl7.org/fhir/R5/procedure.html" title="Procedure">http://hl7.org/fhir/StructureDefinition/Procedure</a><span style="color: navy">&quot; </span><b>alias </b>Procedure <b>as </b><b>target</b>
<b>uses</b><span style="color: navy"> &quot;</span><a href="http://hl7.org/fhir/R5/medicationadministration.html" title="MedicationAdministration">http://hl7.org/fhir/StructureDefinition/MedicationAdministration</a><span style="color: navy">&quot; </span><b>alias </b>MedicationAdministration <b>as </b><b>target</b>

<b>group </b>ExtractAnaestheticRecord<span style="color: navy">(</span><b>source</b> <span style="color: maroon">qr</span><span style="color: navy"> : </span>QR, <b>target</b> <span style="color: maroon">bundle</span><span style="color: navy"> : </span>Bundle<span style="color: navy">)</span><span style="color: navy"> {
</span>  qr<span style="color: navy"><b> -&gt; </b></span>bundle.type = <span style="color: blue">'transaction'</span> <i>&quot;setBundleType&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">// </span><span style="color: green">── The anaesthesia, as a Procedure ─────────────────────────────────────</span>
  <span style="color: navy">// </span><span style="color: green">SNOMED 399097000, administration of anaesthesia, which was checked against</span>
  <span style="color: navy">// </span><span style="color: green">tx.fhir.org. The technique -- general, spinal, block, sedation, local --</span>
  <span style="color: navy">// </span><span style="color: green">becomes Procedure.category, because it classifies the procedure rather than</span>
  <span style="color: navy">// </span><span style="color: green">being a separate finding about it.</span>
  <span style="color: navy">// </span><span style="color: green">The performer is the anaesthetist named on the chart, not the response's</span>
  <span style="color: navy">// </span><span style="color: green">source: an anaesthetic record is sometimes written up by someone else, and</span>
  <span style="color: navy">// </span><span style="color: green">attributing the anaesthetic to the transcriber would be wrong.</span>
  qr.item<b> as </b><span style="color: maroon">g</span><b> where </b><span style="color: navy">(</span>linkId = 'case'<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">'Procedure'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">proc</span><b> then</b><span style="color: navy"> {
</span>    qr<span style="color: navy"><b> -&gt; </b></span> proc<span style="color: navy">, </span> entry<b> then </b>BuildProcedureBase<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">proc</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>
    g<span style="color: navy"><b> -&gt; </b></span>proc.status = <span style="color: blue">'completed'</span> <i>&quot;status&quot;</i><span style="color: navy">;</span>
    g<span style="color: navy"><b> -&gt; </b></span>proc.code<b> as </b><span style="color: maroon">cc</span><b> then</b><span style="color: navy"> {
</span>      g<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>        g<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'http://snomed.info/sct'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
        g<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'399097000'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
        g<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Administration of anaesthesia'</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.encounter<b> as </b><span style="color: maroon">e</span><span style="color: navy"><b> -&gt; </b></span>proc.encounter = <span style="color: maroon">e</span><span style="color: navy">;</span>
    <span style="color: navy">// </span><span style="color: green">Start and completion as a Period. Both, when both are given: the duration</span>
    <span style="color: navy">// </span><span style="color: green">is what an audit reads, and it can only be derived if both ends are there.</span>
    g.item<b> as </b><span style="color: maroon">st</span><b> where </b><span style="color: navy">(</span>(linkId = 'case/started') and answer.value.exists()<span style="color: navy">)</span><b> then</b><span style="color: navy"> {
</span>      st.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> proc.occurrence = <b>create</b><span style="color: navy">(</span><span style="color: blue">'Period'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">per</span><span style="color: navy">, </span> per.start = <span style="color: maroon">t</span> <i>&quot;periodStart&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;startRule&quot;</i><span style="color: navy">;</span>
    g.item<b> as </b><span style="color: maroon">an</span><b> where </b><span style="color: navy">(</span>(linkId = 'case/anaesthetist') and answer.value.exists()<span style="color: navy">)</span><b> then</b><span style="color: navy"> {
</span>      an.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">ref</span><span style="color: navy"><b> -&gt; </b></span>proc.performer<b> as </b><span style="color: maroon">p</span><b> then</b><span style="color: navy"> {
</span>          ref<span style="color: navy"><b> -&gt; </b></span>p.actor = <span style="color: maroon">ref</span> <i>&quot;actor&quot;</i><span style="color: navy">;</span>
          ref<span style="color: navy"><b> -&gt; </b></span>p.function<b> as </b><span style="color: maroon">fn</span><b> then</b><span style="color: navy"> {
</span>            ref<span style="color: navy"><b> -&gt; </b></span>fn.coding<b> as </b><span style="color: maroon">fcg</span><b> then</b><span style="color: navy"> {
</span>              ref<span style="color: navy"><b> -&gt; </b></span>fcg.system = <span style="color: blue">'https://fhir.slade360.co.ke/fhir/CodeSystem/practitioner-specialty-codesystem'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
              ref<span style="color: navy"><b> -&gt; </b></span>fcg.code = <span style="color: blue">'anaesthesia'</span> <i>&quot;cd&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;function&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;performer&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;anaesthetistRule&quot;</i><span style="color: navy">;</span>
    g.item<b> as </b><span style="color: maroon">sg</span><b> where </b><span style="color: navy">(</span>(linkId = 'case/surgeon') and answer.value.exists()<span style="color: navy">)</span><b> then</b><span style="color: navy"> {
</span>      sg.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">ref</span><span style="color: navy"><b> -&gt; </b></span>proc.performer<b> as </b><span style="color: maroon">p</span><b> then</b><span style="color: navy"> {
</span>          ref<span style="color: navy"><b> -&gt; </b></span>p.actor = <span style="color: maroon">ref</span> <i>&quot;actor&quot;</i><span style="color: navy">;</span>
          ref<span style="color: navy"><b> -&gt; </b></span>p.function<b> as </b><span style="color: maroon">fn</span><b> then</b><span style="color: navy"> {
</span>            ref<span style="color: navy"><b> -&gt; </b></span>fn.coding<b> as </b><span style="color: maroon">fcg</span><b> then</b><span style="color: navy"> {
</span>              ref<span style="color: navy"><b> -&gt; </b></span>fcg.system = <span style="color: blue">'https://fhir.slade360.co.ke/fhir/CodeSystem/practitioner-specialty-codesystem'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
              ref<span style="color: navy"><b> -&gt; </b></span>fcg.code = <span style="color: blue">'general-surgery'</span> <i>&quot;cd&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;function&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;performer&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;surgeonRule&quot;</i><span style="color: navy">;</span>
    g.item<b> as </b><span style="color: maroon">sn</span><b> where </b><span style="color: navy">(</span>(linkId = 'case/scrub-nurse') and answer.value.exists()<span style="color: navy">)</span><b> then</b><span style="color: navy"> {
</span>      sn.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">ref</span><span style="color: navy"><b> -&gt; </b></span> proc.performer<b> as </b><span style="color: maroon">p</span><span style="color: navy">, </span> p.actor = <span style="color: maroon">ref</span> <i>&quot;scrubNurse&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;scrubNurseRule&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">// </span><span style="color: green">Type of surgery goes to Procedure.reason: this anaesthetic was given in</span>
    <span style="color: navy">// </span><span style="color: green">order to allow that operation. Free text, because the theatre list is not</span>
    <span style="color: navy">// </span><span style="color: green">a coded catalogue here.</span>
    g.item<b> as </b><span style="color: maroon">ts</span><b> where </b><span style="color: navy">(</span>(linkId = 'case/type-of-surgery') and answer.value.exists()<span style="color: navy">)</span><b> then</b><span style="color: navy"> {
</span>      ts.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> proc.reason<b> as </b><span style="color: maroon">rsn</span><span style="color: navy">, </span> rsn.concept<b> as </b><span style="color: maroon">rc</span><span style="color: navy">, </span> rc.text = <span style="color: maroon">txt</span> <i>&quot;reasonText&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;typeOfSurgeryRule&quot;</i><span style="color: navy">;</span>
    g.item<b> as </b><span style="color: maroon">dx</span><b> where </b><span style="color: navy">(</span>(linkId = 'case/diagnosis') and answer.value.exists()<span style="color: navy">)</span><b> then</b><span style="color: navy"> {
</span>      dx.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> proc.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;diagnosisNote&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;diagnosisRule&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">// </span><span style="color: green">Technique as Procedure.category, and the agents as notes. The agents are</span>
    <span style="color: navy">// </span><span style="color: green">free text on the chart -- &quot;propofol / sevo / fentanyl&quot; on one line -- and</span>
    <span style="color: navy">// </span><span style="color: green">splitting that into MedicationAdministrations would invent doses.</span>
    qr.item<b> as </b><span style="color: maroon">tg</span><b> where </b><span style="color: navy">(</span>linkId = 'technique'<span style="color: navy">)</span><b> then</b><span style="color: navy"> {
</span>      tg.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'technique/type') 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">cv</span><span style="color: navy"><b> -&gt; </b></span>proc.category<b> as </b><span style="color: maroon">cat</span><b> then</b><span style="color: navy"> {
</span>            cv<span style="color: navy"><b> -&gt; </b></span>cat.coding = <span style="color: maroon">cv</span> <i>&quot;categoryCoding&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>cat.text = <span style="color: maroon">d</span> <i>&quot;categoryText&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: navy">}</span> <i>&quot;techniqueTypeRule&quot;</i><span style="color: navy">;</span>
      tg.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>linkId = 'technique/premedication'<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">txt</span><span style="color: navy"><b> -&gt; </b></span> proc.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;note&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;technique_premedication&quot;</i><span style="color: navy">;</span>
      tg.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>linkId = 'technique/induction'<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">txt</span><span style="color: navy"><b> -&gt; </b></span> proc.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;note&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;technique_induction&quot;</i><span style="color: navy">;</span>
      tg.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>linkId = 'technique/maintenance'<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">txt</span><span style="color: navy"><b> -&gt; </b></span> proc.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;note&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;technique_maintenance&quot;</i><span style="color: navy">;</span>
      tg.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>linkId = 'technique/position'<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">txt</span><span style="color: navy"><b> -&gt; </b></span> proc.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;note&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;technique_position&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;techniqueGroup&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">// </span><span style="color: green">The outcome sections. `outcome` takes the result of the operation;</span>
    <span style="color: navy">// </span><span style="color: green">reversal and post-operative instructions are what recovery has to act</span>
    <span style="color: navy">// </span><span style="color: green">on, so they are followUp rather than notes -- a note is read, a followUp</span>
    <span style="color: navy">// </span><span style="color: green">is a stated instruction.</span>
    qr.item<b> as </b><span style="color: maroon">og</span><b> where </b><span style="color: navy">(</span>linkId = 'outcome'<span style="color: navy">)</span><b> then</b><span style="color: navy"> {
</span>      og.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'outcome/result-and-remarks') 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">txt</span><span style="color: navy"><b> -&gt; </b></span> proc.outcome<b> as </b><span style="color: maroon">oc</span><span style="color: navy">, </span> oc.text = <span style="color: maroon">txt</span> <i>&quot;outcomeText&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;outcomeRule&quot;</i><span style="color: navy">;</span>
      og.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'outcome/reversal-notes') 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">txt</span><span style="color: navy"><b> -&gt; </b></span> proc.followUp<b> as </b><span style="color: maroon">fu</span><span style="color: navy">, </span> fu.text = <span style="color: maroon">txt</span> <i>&quot;reversalText&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;reversalRule&quot;</i><span style="color: navy">;</span>
      og.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'outcome/post-operative-instructions') 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">txt</span><span style="color: navy"><b> -&gt; </b></span> proc.followUp<b> as </b><span style="color: maroon">fu</span><span style="color: navy">, </span> fu.text = <span style="color: maroon">txt</span> <i>&quot;instructionsText&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;instructionsRule&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;outcomeGroup&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">}</span> <i>&quot;anaesthesiaProcedure&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">// </span><span style="color: green">── The observations taken through the case ─────────────────────────────</span>
  <span style="color: navy">// </span><span style="color: green">One Observation per reading, each with the reading's own time as its</span>
  <span style="color: navy">// </span><span style="color: green">effective time. The chart is a graph at half-hourly gridlines; collapsing</span>
  <span style="color: navy">// </span><span style="color: green">it into one Observation with thirty components would lose the axis the</span>
  <span style="color: navy">// </span><span style="color: green">graph exists for.</span>
  <span style="color: navy">// </span><span style="color: green">The time on the chart is a clock time with no date. It is written to</span>
  <span style="color: navy">// </span><span style="color: green">Observation.effective as given; the case's own date is on the Procedure</span>
  <span style="color: navy">// </span><span style="color: green">this Observation sits beside, and inventing a date here would be a guess</span>
  <span style="color: navy">// </span><span style="color: green">that reads as a fact.</span>
  qr.item<b> as </b><span style="color: maroon">g</span><b> where </b><span style="color: navy">(</span>(linkId = 'observation') 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>
    g<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>      g<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>        g<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>
        g<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'8716-3'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
        g<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Vital signs note'</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>
      g<span style="color: navy"><b> -&gt; </b></span>cc.text = <span style="color: blue">'Observation during anaesthesia'</span> <i>&quot;codeText&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;code&quot;</i><span style="color: navy">;</span>
    g.item<b> as </b><span style="color: maroon">tm</span><b> where </b><span style="color: navy">(</span>(linkId = 'observation/time') and answer.value.exists()<span style="color: navy">)</span><b> then</b><span style="color: navy"> {
</span>      tm.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">'Reading taken at the time recorded on the anaesthetic chart'</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;readingTimeRule&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 = 'observation/systolic') 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">'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">'8480-6'</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">'Systolic blood pressure'</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_8480_6&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 = 'observation/diastolic') 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">'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">'8462-4'</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">'Diastolic blood pressure'</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_8462_4&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 = 'observation/pulse') 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">'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">'8867-4'</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">'Heart rate'</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_8867_4&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 = 'observation/oxygen-saturation') 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">'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">'59408-5'</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">'Oxygen saturation in Arterial blood by Pulse oximetry'</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_59408_5&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">}</span> <i>&quot;intraOperativeReading&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">// </span><span style="color: green">── Drugs and fluids given ──────────────────────────────────────────────</span>
  <span style="color: navy">// </span><span style="color: green">MedicationAdministration, not MedicationRequest. These were given, in</span>
  <span style="color: navy">// </span><span style="color: green">theatre, by the anaesthetist; there was no order to fulfil and no pharmacy</span>
  <span style="color: navy">// </span><span style="color: green">in the loop. `status = 'completed'` for the same reason.</span>
  <span style="color: navy">// </span><span style="color: green">`medication.concept.text` carries the drug name as written. The hospital's</span>
  <span style="color: navy">// </span><span style="color: green">formulary is not coded and a guessed RxNorm or ATC code on a cytotoxic or an</span>
  <span style="color: navy">// </span><span style="color: green">induction agent is a patient-safety risk, not a data-quality nicety.</span>
  qr.item<b> as </b><span style="color: maroon">g</span><b> where </b><span style="color: navy">(</span>(linkId = 'drug') and item.where(linkId = 'drug/name').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">'MedicationAdministration'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">ma</span><b> then</b><span style="color: navy"> {
</span>    qr<span style="color: navy"><b> -&gt; </b></span> ma<span style="color: navy">, </span> entry<b> then </b>BuildMedicationAdministrationBase<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">ma</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>
    g<span style="color: navy"><b> -&gt; </b></span>ma.status = <span style="color: blue">'completed'</span> <i>&quot;status&quot;</i><span style="color: navy">;</span>
    qr.encounter<b> as </b><span style="color: maroon">e</span><span style="color: navy"><b> -&gt; </b></span>ma.encounter = <span style="color: maroon">e</span><span style="color: navy">;</span>
    qr.source<b> as </b><span style="color: maroon">src</span><span style="color: navy"><b> -&gt; </b></span> ma.performer<b> as </b><span style="color: maroon">p</span><span style="color: navy">, </span> p.actor = <b>create</b><span style="color: navy">(</span><span style="color: blue">'CodeableReference'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">cr</span><span style="color: navy">, </span> cr.reference = <span style="color: maroon">src</span> <i>&quot;performer&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 = 'drug/name'<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">txt</span><span style="color: navy"><b> -&gt; </b></span> ma.medication<b> as </b><span style="color: maroon">med</span><span style="color: navy">, </span> med.concept<b> as </b><span style="color: maroon">mc</span><span style="color: navy">, </span> mc.text = <span style="color: maroon">txt</span> <i>&quot;medicationText&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;drugNameRule&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 = 'drug/dose') 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">txt</span><span style="color: navy"><b> -&gt; </b></span> ma.dosage<b> as </b><span style="color: maroon">dos</span><span style="color: navy">, </span> dos.text = <span style="color: maroon">txt</span> <i>&quot;dosageText&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;drugDoseRule&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 = 'drug/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> ma.note<b> as </b><span style="color: maroon">n</span><span style="color: navy">, </span> n.text = <span style="color: blue">'Given at the time recorded on the anaesthetic chart'</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;drugTimeRule&quot;</i><span style="color: navy">;</span>
    qr.authored<b> as </b><span style="color: maroon">t</span><span style="color: navy"><b> -&gt; </b></span>ma.occurence = <span style="color: maroon">t</span> <i>&quot;occurrence&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">}</span> <i>&quot;drugAdministration&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 = 'iv-fluid') and item.where(linkId = 'iv-fluid/name').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">'MedicationAdministration'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">ma</span><b> then</b><span style="color: navy"> {
</span>    qr<span style="color: navy"><b> -&gt; </b></span> ma<span style="color: navy">, </span> entry<b> then </b>BuildMedicationAdministrationBase<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">ma</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>
    g<span style="color: navy"><b> -&gt; </b></span>ma.status = <span style="color: blue">'completed'</span> <i>&quot;status&quot;</i><span style="color: navy">;</span>
    qr.encounter<b> as </b><span style="color: maroon">e</span><span style="color: navy"><b> -&gt; </b></span>ma.encounter = <span style="color: maroon">e</span><span style="color: navy">;</span>
    qr.source<b> as </b><span style="color: maroon">src</span><span style="color: navy"><b> -&gt; </b></span> ma.performer<b> as </b><span style="color: maroon">p</span><span style="color: navy">, </span> p.actor = <b>create</b><span style="color: navy">(</span><span style="color: blue">'CodeableReference'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">cr</span><span style="color: navy">, </span> cr.reference = <span style="color: maroon">src</span> <i>&quot;performer&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 = 'iv-fluid/name'<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">txt</span><span style="color: navy"><b> -&gt; </b></span> ma.medication<b> as </b><span style="color: maroon">med</span><span style="color: navy">, </span> med.concept<b> as </b><span style="color: maroon">mc</span><span style="color: navy">, </span> mc.text = <span style="color: maroon">txt</span> <i>&quot;medicationText&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;fluidNameRule&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">// </span><span style="color: green">Guarded on the answer being a Quantity, not merely present. Dosage.dose</span>
    <span style="color: navy">// </span><span style="color: green">takes a Quantity or a Range and nothing else, so a client that submits</span>
    <span style="color: navy">// </span><span style="color: green">a bare string there fails the rule and takes the whole extraction with</span>
    <span style="color: navy">// </span><span style="color: green">it -- which is exactly what the questionnaire tester does: it renders a</span>
    <span style="color: navy">// </span><span style="color: green">`quantity` item as a plain text box and submits valueString &quot;5&quot;.</span>
    <span style="color: navy">// </span><span style="color: green">`$validate` on such a response says so plainly (&quot;Answer value must be</span>
    <span style="color: navy">// </span><span style="color: green">of the type Quantity not string&quot;); one non-conformant field should not</span>
    <span style="color: navy">// </span><span style="color: green">cost every other resource on the form.</span>
    g.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'iv-fluid/volume') and answer.value.ofType(Quantity).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">v</span><span style="color: navy"><b> -&gt; </b></span> ma.dosage<b> as </b><span style="color: maroon">dos</span><span style="color: navy">, </span> dos.dose = <span style="color: maroon">v</span> <i>&quot;dosageVolume&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;fluidVolumeRule&quot;</i><span style="color: navy">;</span>
    qr.authored<b> as </b><span style="color: maroon">t</span><span style="color: navy"><b> -&gt; </b></span>ma.occurence = <span style="color: maroon">t</span> <i>&quot;occurrence&quot;</i><span style="color: navy">;</span>
    g<span style="color: navy"><b> -&gt; </b></span> ma.note<b> as </b><span style="color: maroon">n</span><span style="color: navy">, </span> n.text = <span style="color: blue">'Intravenous fluid given during anaesthesia'</span> <i>&quot;fluidNote&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">}</span> <i>&quot;fluidAdministration&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">// </span><span style="color: green">── Estimated blood loss ────────────────────────────────────────────────</span>
  <span style="color: navy">// </span><span style="color: green">LOINC 8717-1, the operation note's own term for it, which is exactly what</span>
  <span style="color: navy">// </span><span style="color: green">this is. The note says it is an estimate: the figure drives a transfusion</span>
  <span style="color: navy">// </span><span style="color: green">decision and a reader has to know it was eyeballed, not measured.</span>
  qr.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'estimated-blood-loss') 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>SetProcedureCategory<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">'8717-1'</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">'Surgical operation note estimated blood loss [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.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 = <span style="color: maroon">v</span> <i>&quot;set&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">'An estimate made in theatre, not a measured volume.'</span> <i>&quot;estimateNote&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">}</span> <i>&quot;bloodLossObservation&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">// </span><span style="color: green">── Anaesthesia duration ────────────────────────────────────────────────</span>
  <span style="color: navy">// </span><span style="color: green">Extracted only when the form carries it. The questionnaire leaves the field</span>
  <span style="color: navy">// </span><span style="color: green">read-only and expects the client to derive it from the start and completion</span>
  <span style="color: navy">// </span><span style="color: green">times; where the client did, that value is authoritative and is recorded</span>
  <span style="color: navy">// </span><span style="color: green">under LOINC 89874-2. Where it did not, nothing is written -- the Procedure's</span>
  <span style="color: navy">// </span><span style="color: green">period already holds both ends, and a duration computed here from a clock</span>
  <span style="color: navy">// </span><span style="color: green">time with no date could be a day out.</span>
  qr.item<b> as </b><span style="color: maroon">g</span><b> where </b><span style="color: navy">(</span>linkId = 'case'<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 = 'case/duration') 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>SetProcedureCategory<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">'89874-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">'Anesthesia duration'</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 = <span style="color: maroon">v</span> <i>&quot;set&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;durationObservation&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">}</span> <i>&quot;durationGroup&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><b>group </b>SetProcedureCategory<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">'procedure'</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">'Procedure'</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>BuildProcedureBase<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>Procedure, <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>r<b> then </b>SetResponseProvenance<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">r</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>r.id = <b>uuid</b><span style="color: navy">(</span><span style="color: navy">)</span><b> then </b>SetProcedureFullUrl<span style="color: navy">(</span><span style="color: maroon">r</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">'Procedure'</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>
  <span style="color: navy">// </span><span style="color: green">The response's own time, as a floor, the way BuildObsBase does it. A rule</span>
  <span style="color: navy">// </span><span style="color: green">that reads a time off the form overwrites this; without it a procedure whose</span>
  <span style="color: navy">// </span><span style="color: green">date column was taken off on review has no time at all, and a procedure with</span>
  <span style="color: navy">// </span><span style="color: green">no time cannot be ordered against the rest of the admission.</span>
  qr.authored<b> as </b><span style="color: maroon">t</span><span style="color: navy"><b> -&gt; </b></span>r.occurrence = <span style="color: maroon">t</span> <i>&quot;occurrenceFallback&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>r.subject = <span style="color: maroon">s</span><span style="color: navy">;</span>
<span style="color: navy">}

</span><b>group </b>SetProcedureFullUrl<span style="color: navy">(</span><b>source</b> <span style="color: maroon">r</span><span style="color: navy"> : </span>Procedure, <b>target</b> <span style="color: maroon">entry</span><span style="color: navy">)</span><span style="color: navy"> {
</span>  r.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/Procedure/'</span><span style="color: navy">, </span><span style="color: maroon">id</span><span style="color: navy">)</span> <i>&quot;assignFullUrl&quot;</i><span style="color: navy">;</span>
<span style="color: navy">}

</span><b>group </b>BuildMedicationAdministrationBase<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>MedicationAdministration, <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>r<b> then </b>SetResponseProvenance<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">r</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>r.id = <b>uuid</b><span style="color: navy">(</span><span style="color: navy">)</span><b> then </b>SetMedicationAdministrationFullUrl<span style="color: navy">(</span><span style="color: maroon">r</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">'MedicationAdministration'</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.subject<b> as </b><span style="color: maroon">s</span><span style="color: navy"><b> -&gt; </b></span>r.subject = <span style="color: maroon">s</span><span style="color: navy">;</span>
  <span style="color: navy">// </span><span style="color: green">The response's own time, as a floor. A row that names the time it was given</span>
  <span style="color: navy">// </span><span style="color: green">overwrites this; a form whose time column was taken off on review would</span>
  <span style="color: navy">// </span><span style="color: green">otherwise produce an administration with no time at all, which is not a</span>
  <span style="color: navy">// </span><span style="color: green">record of an administration. Same fallback BuildObsBase already applies.</span>
  qr.authored<b> as </b><span style="color: maroon">t</span><span style="color: navy"><b> -&gt; </b></span>r.occurence = <span style="color: maroon">t</span> <i>&quot;occurrenceFallback&quot;</i><span style="color: navy">;</span>
<span style="color: navy">}

</span><b>group </b>SetMedicationAdministrationFullUrl<span style="color: navy">(</span><b>source</b> <span style="color: maroon">r</span><span style="color: navy"> : </span>MedicationAdministration, <b>target</b> <span style="color: maroon">entry</span><span style="color: navy">)</span><span style="color: navy"> {
</span>  r.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/MedicationAdministration/'</span><span style="color: navy">, </span><span style="color: maroon">id</span><span style="color: navy">)</span> <i>&quot;assignFullUrl&quot;</i><span style="color: navy">;</span>
<span style="color: navy">}

</span><span style="color: navy">// </span><span style="color: green">── Provenance and tenancy ───────────────────────────────────────────────────</span>
<span style="color: navy">// </span><span style="color: green">Two tags on everything this map creates. The first says which questionnaire</span>
<span style="color: navy">// </span><span style="color: green">produced it, so a 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">'anaesthetic-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">'Anaesthetic 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/ExtractAnaestheticRecord"/>
  <version value="0.1.0"/>
  <name value="ExtractAnaestheticRecord"/>
  <title value="Anaesthetic 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 anaesthetic chart out as: one Procedure for the anaesthesia itself, carrying the technique as its category, the anaesthetist as its performer and the start and completion times as its period; one Observation per timed reading taken through the case, each with its own effective time, because the paper chart is a graph and a graph is a time series; one MedicationAdministration per drug and per fluid, because those were given rather than ordered; and the estimated blood loss as its own Observation under the LOINC operation-note code, marked as an estimate."/>
  <structure>
    <url
         value="http://hl7.org/fhir/StructureDefinition/QuestionnaireResponse"/>
    <mode value="source"/>
    <alias value="QR"/>
  </structure>
  <structure>
    <url value="http://hl7.org/fhir/StructureDefinition/Bundle"/>
    <mode value="target"/>
    <alias value="Bundle"/>
  </structure>
  <structure>
    <url value="http://hl7.org/fhir/StructureDefinition/Observation"/>
    <mode value="target"/>
    <alias value="Observation"/>
  </structure>
  <structure>
    <url value="http://hl7.org/fhir/StructureDefinition/Procedure"/>
    <mode value="target"/>
    <alias value="Procedure"/>
  </structure>
  <structure>
    <url
         value="http://hl7.org/fhir/StructureDefinition/MedicationAdministration"/>
    <mode value="target"/>
    <alias value="MedicationAdministration"/>
  </structure>
  <group>
    <name value="ExtractAnaestheticRecord"/>
    <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="anaesthesiaProcedure"/>
      <source>
        <context value="qr"/>
        <element value="item"/>
        <variable value="g"/>
        <condition value="linkId = 'case'"/>
      </source>
      <target>
        <context value="bundle"/>
        <element value="entry"/>
        <variable value="entry"/>
      </target>
      <target>
        <context value="entry"/>
        <element value="resource"/>
        <variable value="proc"/>
        <transform value="create"/>
        <parameter>
          <valueString value="Procedure"/>
        </parameter>
      </target>
      <rule>
        <name value="base"/>
        <source>
          <context value="qr"/>
        </source>
        <target>
          <context value="proc"/>
        </target>
        <target>
          <context value="entry"/>
        </target>
        <dependent>
          <name value="BuildProcedureBase"/>
          <parameter>
            <valueId value="qr"/>
          </parameter>
          <parameter>
            <valueId value="proc"/>
          </parameter>
          <parameter>
            <valueId value="entry"/>
          </parameter>
        </dependent>
      </rule>
      <rule>
        <name value="status"/>
        <source>
          <context value="g"/>
        </source>
        <target>
          <context value="proc"/>
          <element value="status"/>
          <transform value="copy"/>
          <parameter>
            <valueString value="completed"/>
          </parameter>
        </target>
      </rule>
      <rule>
        <name value="code"/>
        <source>
          <context value="g"/>
        </source>
        <target>
          <context value="proc"/>
          <element value="code"/>
          <variable value="cc"/>
        </target>
        <rule>
          <name value="coding"/>
          <source>
            <context value="g"/>
          </source>
          <target>
            <context value="cc"/>
            <element value="coding"/>
            <variable value="cg"/>
          </target>
          <rule>
            <name value="sys"/>
            <source>
              <context value="g"/>
            </source>
            <target>
              <context value="cg"/>
              <element value="system"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="http://snomed.info/sct"/>
              </parameter>
            </target>
          </rule>
          <rule>
            <name value="cd"/>
            <source>
              <context value="g"/>
            </source>
            <target>
              <context value="cg"/>
              <element value="code"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="399097000"/>
              </parameter>
            </target>
          </rule>
          <rule>
            <name value="dsp"/>
            <source>
              <context value="g"/>
            </source>
            <target>
              <context value="cg"/>
              <element value="display"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="Administration of anaesthesia"/>
              </parameter>
            </target>
          </rule>
        </rule>
      </rule>
      <rule>
        <name value="encounter"/>
        <source>
          <context value="qr"/>
          <element value="encounter"/>
          <variable value="e"/>
        </source>
        <target>
          <context value="proc"/>
          <element value="encounter"/>
          <transform value="copy"/>
          <parameter>
            <valueId value="e"/>
          </parameter>
        </target>
      </rule>
      <rule>
        <name value="startRule"/>
        <source>
          <context value="g"/>
          <element value="item"/>
          <variable value="st"/>
          <condition
                     value="(linkId = 'case/started') and answer.value.exists()"/>
        </source>
        <rule>
          <name value="answer"/>
          <source>
            <context value="st"/>
            <element value="answer"/>
            <listMode value="first"/>
            <variable value="a"/>
          </source>
          <rule>
            <name value="periodStart"/>
            <source>
              <context value="a"/>
              <element value="value"/>
              <variable value="t"/>
            </source>
            <target>
              <context value="proc"/>
              <element value="occurrence"/>
              <variable value="per"/>
              <transform value="create"/>
              <parameter>
                <valueString value="Period"/>
              </parameter>
            </target>
            <target>
              <context value="per"/>
              <element value="start"/>
              <transform value="copy"/>
              <parameter>
                <valueId value="t"/>
              </parameter>
            </target>
          </rule>
        </rule>
        <documentation
                       value="Start and completion as a Period. Both, when both are given: the duration
is what an audit reads, and it can only be derived if both ends are there."/>
      </rule>
      <rule>
        <name value="anaesthetistRule"/>
        <source>
          <context value="g"/>
          <element value="item"/>
          <variable value="an"/>
          <condition
                     value="(linkId = 'case/anaesthetist') and answer.value.exists()"/>
        </source>
        <rule>
          <name value="answer"/>
          <source>
            <context value="an"/>
            <element value="answer"/>
            <listMode value="first"/>
            <variable value="a"/>
          </source>
          <rule>
            <name value="performer"/>
            <source>
              <context value="a"/>
              <element value="value"/>
              <variable value="ref"/>
            </source>
            <target>
              <context value="proc"/>
              <element value="performer"/>
              <variable value="p"/>
            </target>
            <rule>
              <name value="actor"/>
              <source>
                <context value="ref"/>
              </source>
              <target>
                <context value="p"/>
                <element value="actor"/>
                <transform value="copy"/>
                <parameter>
                  <valueId value="ref"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="function"/>
              <source>
                <context value="ref"/>
              </source>
              <target>
                <context value="p"/>
                <element value="function"/>
                <variable value="fn"/>
              </target>
              <rule>
                <name value="coding"/>
                <source>
                  <context value="ref"/>
                </source>
                <target>
                  <context value="fn"/>
                  <element value="coding"/>
                  <variable value="fcg"/>
                </target>
                <rule>
                  <name value="sys"/>
                  <source>
                    <context value="ref"/>
                  </source>
                  <target>
                    <context value="fcg"/>
                    <element value="system"/>
                    <transform value="copy"/>
                    <parameter>
                      <valueString
                                   value="https://fhir.slade360.co.ke/fhir/CodeSystem/practitioner-specialty-codesystem"/>
                    </parameter>
                  </target>
                </rule>
                <rule>
                  <name value="cd"/>
                  <source>
                    <context value="ref"/>
                  </source>
                  <target>
                    <context value="fcg"/>
                    <element value="code"/>
                    <transform value="copy"/>
                    <parameter>
                      <valueString value="anaesthesia"/>
                    </parameter>
                  </target>
                </rule>
              </rule>
            </rule>
          </rule>
        </rule>
      </rule>
      <rule>
        <name value="surgeonRule"/>
        <source>
          <context value="g"/>
          <element value="item"/>
          <variable value="sg"/>
          <condition
                     value="(linkId = 'case/surgeon') and answer.value.exists()"/>
        </source>
        <rule>
          <name value="answer"/>
          <source>
            <context value="sg"/>
            <element value="answer"/>
            <listMode value="first"/>
            <variable value="a"/>
          </source>
          <rule>
            <name value="performer"/>
            <source>
              <context value="a"/>
              <element value="value"/>
              <variable value="ref"/>
            </source>
            <target>
              <context value="proc"/>
              <element value="performer"/>
              <variable value="p"/>
            </target>
            <rule>
              <name value="actor"/>
              <source>
                <context value="ref"/>
              </source>
              <target>
                <context value="p"/>
                <element value="actor"/>
                <transform value="copy"/>
                <parameter>
                  <valueId value="ref"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="function"/>
              <source>
                <context value="ref"/>
              </source>
              <target>
                <context value="p"/>
                <element value="function"/>
                <variable value="fn"/>
              </target>
              <rule>
                <name value="coding"/>
                <source>
                  <context value="ref"/>
                </source>
                <target>
                  <context value="fn"/>
                  <element value="coding"/>
                  <variable value="fcg"/>
                </target>
                <rule>
                  <name value="sys"/>
                  <source>
                    <context value="ref"/>
                  </source>
                  <target>
                    <context value="fcg"/>
                    <element value="system"/>
                    <transform value="copy"/>
                    <parameter>
                      <valueString
                                   value="https://fhir.slade360.co.ke/fhir/CodeSystem/practitioner-specialty-codesystem"/>
                    </parameter>
                  </target>
                </rule>
                <rule>
                  <name value="cd"/>
                  <source>
                    <context value="ref"/>
                  </source>
                  <target>
                    <context value="fcg"/>
                    <element value="code"/>
                    <transform value="copy"/>
                    <parameter>
                      <valueString value="general-surgery"/>
                    </parameter>
                  </target>
                </rule>
              </rule>
            </rule>
          </rule>
        </rule>
      </rule>
      <rule>
        <name value="scrubNurseRule"/>
        <source>
          <context value="g"/>
          <element value="item"/>
          <variable value="sn"/>
          <condition
                     value="(linkId = 'case/scrub-nurse') and answer.value.exists()"/>
        </source>
        <rule>
          <name value="answer"/>
          <source>
            <context value="sn"/>
            <element value="answer"/>
            <listMode value="first"/>
            <variable value="a"/>
          </source>
          <rule>
            <name value="scrubNurse"/>
            <source>
              <context value="a"/>
              <element value="value"/>
              <variable value="ref"/>
            </source>
            <target>
              <context value="proc"/>
              <element value="performer"/>
              <variable value="p"/>
            </target>
            <target>
              <context value="p"/>
              <element value="actor"/>
              <transform value="copy"/>
              <parameter>
                <valueId value="ref"/>
              </parameter>
            </target>
          </rule>
        </rule>
      </rule>
      <rule>
        <name value="typeOfSurgeryRule"/>
        <source>
          <context value="g"/>
          <element value="item"/>
          <variable value="ts"/>
          <condition
                     value="(linkId = 'case/type-of-surgery') and answer.value.exists()"/>
        </source>
        <rule>
          <name value="answer"/>
          <source>
            <context value="ts"/>
            <element value="answer"/>
            <listMode value="first"/>
            <variable value="a"/>
          </source>
          <rule>
            <name value="reasonText"/>
            <source>
              <context value="a"/>
              <element value="value"/>
              <variable value="txt"/>
            </source>
            <target>
              <context value="proc"/>
              <element value="reason"/>
              <variable value="rsn"/>
            </target>
            <target>
              <context value="rsn"/>
              <element value="concept"/>
              <variable value="rc"/>
            </target>
            <target>
              <context value="rc"/>
              <element value="text"/>
              <transform value="copy"/>
              <parameter>
                <valueId value="txt"/>
              </parameter>
            </target>
          </rule>
        </rule>
        <documentation
                       value="Type of surgery goes to Procedure.reason: this anaesthetic was given in
order to allow that operation. Free text, because the theatre list is not
a coded catalogue here."/>
      </rule>
      <rule>
        <name value="diagnosisRule"/>
        <source>
          <context value="g"/>
          <element value="item"/>
          <variable value="dx"/>
          <condition
                     value="(linkId = 'case/diagnosis') and answer.value.exists()"/>
        </source>
        <rule>
          <name value="answer"/>
          <source>
            <context value="dx"/>
            <element value="answer"/>
            <listMode value="first"/>
            <variable value="a"/>
          </source>
          <rule>
            <name value="diagnosisNote"/>
            <source>
              <context value="a"/>
              <element value="value"/>
              <variable value="txt"/>
            </source>
            <target>
              <context value="proc"/>
              <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>
        <name value="techniqueGroup"/>
        <source>
          <context value="qr"/>
          <element value="item"/>
          <variable value="tg"/>
          <condition value="linkId = 'technique'"/>
        </source>
        <rule>
          <name value="techniqueTypeRule"/>
          <source>
            <context value="tg"/>
            <element value="item"/>
            <variable value="it"/>
            <condition
                       value="(linkId = 'technique/type') 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="category"/>
              <source>
                <context value="a"/>
                <element value="value"/>
                <variable value="cv"/>
              </source>
              <target>
                <context value="proc"/>
                <element value="category"/>
                <variable value="cat"/>
              </target>
              <rule>
                <name value="categoryCoding"/>
                <source>
                  <context value="cv"/>
                </source>
                <target>
                  <context value="cat"/>
                  <element value="coding"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueId value="cv"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="categoryText"/>
                <source>
                  <context value="cv"/>
                  <element value="display"/>
                  <variable value="d"/>
                </source>
                <target>
                  <context value="cat"/>
                  <element value="text"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueId value="d"/>
                  </parameter>
                </target>
              </rule>
            </rule>
          </rule>
        </rule>
        <rule>
          <name value="technique_premedication"/>
          <source>
            <context value="tg"/>
            <element value="item"/>
            <variable value="it"/>
            <condition value="linkId = 'technique/premedication'"/>
          </source>
          <rule>
            <name value="answer"/>
            <source>
              <context value="it"/>
              <element value="answer"/>
              <listMode value="first"/>
              <variable value="a"/>
            </source>
            <rule>
              <name value="note"/>
              <source>
                <context value="a"/>
                <element value="value"/>
                <variable value="txt"/>
              </source>
              <target>
                <context value="proc"/>
                <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>
          <name value="technique_induction"/>
          <source>
            <context value="tg"/>
            <element value="item"/>
            <variable value="it"/>
            <condition value="linkId = 'technique/induction'"/>
          </source>
          <rule>
            <name value="answer"/>
            <source>
              <context value="it"/>
              <element value="answer"/>
              <listMode value="first"/>
              <variable value="a"/>
            </source>
            <rule>
              <name value="note"/>
              <source>
                <context value="a"/>
                <element value="value"/>
                <variable value="txt"/>
              </source>
              <target>
                <context value="proc"/>
                <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>
          <name value="technique_maintenance"/>
          <source>
            <context value="tg"/>
            <element value="item"/>
            <variable value="it"/>
            <condition value="linkId = 'technique/maintenance'"/>
          </source>
          <rule>
            <name value="answer"/>
            <source>
              <context value="it"/>
              <element value="answer"/>
              <listMode value="first"/>
              <variable value="a"/>
            </source>
            <rule>
              <name value="note"/>
              <source>
                <context value="a"/>
                <element value="value"/>
                <variable value="txt"/>
              </source>
              <target>
                <context value="proc"/>
                <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>
          <name value="technique_position"/>
          <source>
            <context value="tg"/>
            <element value="item"/>
            <variable value="it"/>
            <condition value="linkId = 'technique/position'"/>
          </source>
          <rule>
            <name value="answer"/>
            <source>
              <context value="it"/>
              <element value="answer"/>
              <listMode value="first"/>
              <variable value="a"/>
            </source>
            <rule>
              <name value="note"/>
              <source>
                <context value="a"/>
                <element value="value"/>
                <variable value="txt"/>
              </source>
              <target>
                <context value="proc"/>
                <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>
        <documentation
                       value="Technique as Procedure.category, and the agents as notes. The agents are
free text on the chart -- &quot;propofol / sevo / fentanyl&quot; on one line -- and
splitting that into MedicationAdministrations would invent doses."/>
      </rule>
      <rule>
        <name value="outcomeGroup"/>
        <source>
          <context value="qr"/>
          <element value="item"/>
          <variable value="og"/>
          <condition value="linkId = 'outcome'"/>
        </source>
        <rule>
          <name value="outcomeRule"/>
          <source>
            <context value="og"/>
            <element value="item"/>
            <variable value="it"/>
            <condition
                       value="(linkId = 'outcome/result-and-remarks') 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="outcomeText"/>
              <source>
                <context value="a"/>
                <element value="value"/>
                <variable value="txt"/>
              </source>
              <target>
                <context value="proc"/>
                <element value="outcome"/>
                <variable value="oc"/>
              </target>
              <target>
                <context value="oc"/>
                <element value="text"/>
                <transform value="copy"/>
                <parameter>
                  <valueId value="txt"/>
                </parameter>
              </target>
            </rule>
          </rule>
        </rule>
        <rule>
          <name value="reversalRule"/>
          <source>
            <context value="og"/>
            <element value="item"/>
            <variable value="it"/>
            <condition
                       value="(linkId = 'outcome/reversal-notes') 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="reversalText"/>
              <source>
                <context value="a"/>
                <element value="value"/>
                <variable value="txt"/>
              </source>
              <target>
                <context value="proc"/>
                <element value="followUp"/>
                <variable value="fu"/>
              </target>
              <target>
                <context value="fu"/>
                <element value="text"/>
                <transform value="copy"/>
                <parameter>
                  <valueId value="txt"/>
                </parameter>
              </target>
            </rule>
          </rule>
        </rule>
        <rule>
          <name value="instructionsRule"/>
          <source>
            <context value="og"/>
            <element value="item"/>
            <variable value="it"/>
            <condition
                       value="(linkId = 'outcome/post-operative-instructions') 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="instructionsText"/>
              <source>
                <context value="a"/>
                <element value="value"/>
                <variable value="txt"/>
              </source>
              <target>
                <context value="proc"/>
                <element value="followUp"/>
                <variable value="fu"/>
              </target>
              <target>
                <context value="fu"/>
                <element value="text"/>
                <transform value="copy"/>
                <parameter>
                  <valueId value="txt"/>
                </parameter>
              </target>
            </rule>
          </rule>
        </rule>
        <documentation
                       value="The outcome sections. `outcome` takes the result of the operation;
reversal and post-operative instructions are what recovery has to act
on, so they are followUp rather than notes -- a note is read, a followUp
is a stated instruction."/>
      </rule>
      <documentation
                     value="── The anaesthesia, as a Procedure ─────────────────────────────────────
SNOMED 399097000, administration of anaesthesia, which was checked against
tx.fhir.org. The technique -- general, spinal, block, sedation, local --
becomes Procedure.category, because it classifies the procedure rather than
being a separate finding about it.
The performer is the anaesthetist named on the chart, not the response's
source: an anaesthetic record is sometimes written up by someone else, and
attributing the anaesthetic to the transcriber would be wrong."/>
    </rule>
    <rule>
      <name value="intraOperativeReading"/>
      <source>
        <context value="qr"/>
        <element value="item"/>
        <variable value="g"/>
        <condition
                   value="(linkId = 'observation') 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="g"/>
        </source>
        <target>
          <context value="obs"/>
          <element value="code"/>
          <variable value="cc"/>
        </target>
        <rule>
          <name value="coding"/>
          <source>
            <context value="g"/>
          </source>
          <target>
            <context value="cc"/>
            <element value="coding"/>
            <variable value="cg"/>
          </target>
          <rule>
            <name value="sys"/>
            <source>
              <context value="g"/>
            </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="g"/>
            </source>
            <target>
              <context value="cg"/>
              <element value="code"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="8716-3"/>
              </parameter>
            </target>
          </rule>
          <rule>
            <name value="dsp"/>
            <source>
              <context value="g"/>
            </source>
            <target>
              <context value="cg"/>
              <element value="display"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="Vital signs note"/>
              </parameter>
            </target>
          </rule>
        </rule>
        <rule>
          <name value="codeText"/>
          <source>
            <context value="g"/>
          </source>
          <target>
            <context value="cc"/>
            <element value="text"/>
            <transform value="copy"/>
            <parameter>
              <valueString value="Observation during anaesthesia"/>
            </parameter>
          </target>
        </rule>
      </rule>
      <rule>
        <name value="readingTimeRule"/>
        <source>
          <context value="g"/>
          <element value="item"/>
          <variable value="tm"/>
          <condition
                     value="(linkId = 'observation/time') and answer.value.exists()"/>
        </source>
        <rule>
          <name value="answer"/>
          <source>
            <context value="tm"/>
            <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="Reading taken at the time recorded on the anaesthetic chart"/>
              </parameter>
            </target>
          </rule>
        </rule>
      </rule>
      <rule>
        <name value="comp_8480_6"/>
        <source>
          <context value="g"/>
          <element value="item"/>
          <variable value="it"/>
          <condition
                     value="(linkId = 'observation/systolic') 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="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="8480-6"/>
                </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="Systolic blood pressure"/>
                </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_8462_4"/>
        <source>
          <context value="g"/>
          <element value="item"/>
          <variable value="it"/>
          <condition
                     value="(linkId = 'observation/diastolic') 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="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="8462-4"/>
                </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="Diastolic blood pressure"/>
                </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_8867_4"/>
        <source>
          <context value="g"/>
          <element value="item"/>
          <variable value="it"/>
          <condition
                     value="(linkId = 'observation/pulse') 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="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="8867-4"/>
                </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="Heart rate"/>
                </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_59408_5"/>
        <source>
          <context value="g"/>
          <element value="item"/>
          <variable value="it"/>
          <condition
                     value="(linkId = 'observation/oxygen-saturation') 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="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="59408-5"/>
                </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="Oxygen saturation in Arterial blood by Pulse oximetry"/>
                </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>
      <documentation
                     value="── The observations taken through the case ─────────────────────────────
One Observation per reading, each with the reading's own time as its
effective time. The chart is a graph at half-hourly gridlines; collapsing
it into one Observation with thirty components would lose the axis the
graph exists for.
The time on the chart is a clock time with no date. It is written to
Observation.effective as given; the case's own date is on the Procedure
this Observation sits beside, and inventing a date here would be a guess
that reads as a fact."/>
    </rule>
    <rule>
      <name value="drugAdministration"/>
      <source>
        <context value="qr"/>
        <element value="item"/>
        <variable value="g"/>
        <condition
                   value="(linkId = 'drug') and item.where(linkId = 'drug/name').answer.value.exists()"/>
      </source>
      <target>
        <context value="bundle"/>
        <element value="entry"/>
        <variable value="entry"/>
      </target>
      <target>
        <context value="entry"/>
        <element value="resource"/>
        <variable value="ma"/>
        <transform value="create"/>
        <parameter>
          <valueString value="MedicationAdministration"/>
        </parameter>
      </target>
      <rule>
        <name value="base"/>
        <source>
          <context value="qr"/>
        </source>
        <target>
          <context value="ma"/>
        </target>
        <target>
          <context value="entry"/>
        </target>
        <dependent>
          <name value="BuildMedicationAdministrationBase"/>
          <parameter>
            <valueId value="qr"/>
          </parameter>
          <parameter>
            <valueId value="ma"/>
          </parameter>
          <parameter>
            <valueId value="entry"/>
          </parameter>
        </dependent>
      </rule>
      <rule>
        <name value="status"/>
        <source>
          <context value="g"/>
        </source>
        <target>
          <context value="ma"/>
          <element value="status"/>
          <transform value="copy"/>
          <parameter>
            <valueString value="completed"/>
          </parameter>
        </target>
      </rule>
      <rule>
        <name value="encounter"/>
        <source>
          <context value="qr"/>
          <element value="encounter"/>
          <variable value="e"/>
        </source>
        <target>
          <context value="ma"/>
          <element value="encounter"/>
          <transform value="copy"/>
          <parameter>
            <valueId value="e"/>
          </parameter>
        </target>
      </rule>
      <rule>
        <name value="performer"/>
        <source>
          <context value="qr"/>
          <element value="source"/>
          <variable value="src"/>
        </source>
        <target>
          <context value="ma"/>
          <element value="performer"/>
          <variable value="p"/>
        </target>
        <target>
          <context value="p"/>
          <element value="actor"/>
          <variable value="cr"/>
          <transform value="create"/>
          <parameter>
            <valueString value="CodeableReference"/>
          </parameter>
        </target>
        <target>
          <context value="cr"/>
          <element value="reference"/>
          <transform value="copy"/>
          <parameter>
            <valueId value="src"/>
          </parameter>
        </target>
      </rule>
      <rule>
        <name value="drugNameRule"/>
        <source>
          <context value="g"/>
          <element value="item"/>
          <variable value="it"/>
          <condition value="linkId = 'drug/name'"/>
        </source>
        <rule>
          <name value="answer"/>
          <source>
            <context value="it"/>
            <element value="answer"/>
            <listMode value="first"/>
            <variable value="a"/>
          </source>
          <rule>
            <name value="medicationText"/>
            <source>
              <context value="a"/>
              <element value="value"/>
              <variable value="txt"/>
            </source>
            <target>
              <context value="ma"/>
              <element value="medication"/>
              <variable value="med"/>
            </target>
            <target>
              <context value="med"/>
              <element value="concept"/>
              <variable value="mc"/>
            </target>
            <target>
              <context value="mc"/>
              <element value="text"/>
              <transform value="copy"/>
              <parameter>
                <valueId value="txt"/>
              </parameter>
            </target>
          </rule>
        </rule>
      </rule>
      <rule>
        <name value="drugDoseRule"/>
        <source>
          <context value="g"/>
          <element value="item"/>
          <variable value="it"/>
          <condition
                     value="(linkId = 'drug/dose') 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="dosageText"/>
            <source>
              <context value="a"/>
              <element value="value"/>
              <variable value="txt"/>
            </source>
            <target>
              <context value="ma"/>
              <element value="dosage"/>
              <variable value="dos"/>
            </target>
            <target>
              <context value="dos"/>
              <element value="text"/>
              <transform value="copy"/>
              <parameter>
                <valueId value="txt"/>
              </parameter>
            </target>
          </rule>
        </rule>
      </rule>
      <rule>
        <name value="drugTimeRule"/>
        <source>
          <context value="g"/>
          <element value="item"/>
          <variable value="it"/>
          <condition
                     value="(linkId = 'drug/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="ma"/>
              <element value="note"/>
              <variable value="n"/>
            </target>
            <target>
              <context value="n"/>
              <element value="text"/>
              <transform value="copy"/>
              <parameter>
                <valueString
                             value="Given at the time recorded on the anaesthetic chart"/>
              </parameter>
            </target>
          </rule>
        </rule>
      </rule>
      <rule>
        <name value="occurrence"/>
        <source>
          <context value="qr"/>
          <element value="authored"/>
          <variable value="t"/>
        </source>
        <target>
          <context value="ma"/>
          <element value="occurence"/>
          <transform value="copy"/>
          <parameter>
            <valueId value="t"/>
          </parameter>
        </target>
      </rule>
      <documentation
                     value="── Drugs and fluids given ──────────────────────────────────────────────
MedicationAdministration, not MedicationRequest. These were given, in
theatre, by the anaesthetist; there was no order to fulfil and no pharmacy
in the loop. `status = 'completed'` for the same reason.
`medication.concept.text` carries the drug name as written. The hospital's
formulary is not coded and a guessed RxNorm or ATC code on a cytotoxic or an
induction agent is a patient-safety risk, not a data-quality nicety."/>
    </rule>
    <rule>
      <name value="fluidAdministration"/>
      <source>
        <context value="qr"/>
        <element value="item"/>
        <variable value="g"/>
        <condition
                   value="(linkId = 'iv-fluid') and item.where(linkId = 'iv-fluid/name').answer.value.exists()"/>
      </source>
      <target>
        <context value="bundle"/>
        <element value="entry"/>
        <variable value="entry"/>
      </target>
      <target>
        <context value="entry"/>
        <element value="resource"/>
        <variable value="ma"/>
        <transform value="create"/>
        <parameter>
          <valueString value="MedicationAdministration"/>
        </parameter>
      </target>
      <rule>
        <name value="base"/>
        <source>
          <context value="qr"/>
        </source>
        <target>
          <context value="ma"/>
        </target>
        <target>
          <context value="entry"/>
        </target>
        <dependent>
          <name value="BuildMedicationAdministrationBase"/>
          <parameter>
            <valueId value="qr"/>
          </parameter>
          <parameter>
            <valueId value="ma"/>
          </parameter>
          <parameter>
            <valueId value="entry"/>
          </parameter>
        </dependent>
      </rule>
      <rule>
        <name value="status"/>
        <source>
          <context value="g"/>
        </source>
        <target>
          <context value="ma"/>
          <element value="status"/>
          <transform value="copy"/>
          <parameter>
            <valueString value="completed"/>
          </parameter>
        </target>
      </rule>
      <rule>
        <name value="encounter"/>
        <source>
          <context value="qr"/>
          <element value="encounter"/>
          <variable value="e"/>
        </source>
        <target>
          <context value="ma"/>
          <element value="encounter"/>
          <transform value="copy"/>
          <parameter>
            <valueId value="e"/>
          </parameter>
        </target>
      </rule>
      <rule>
        <name value="performer"/>
        <source>
          <context value="qr"/>
          <element value="source"/>
          <variable value="src"/>
        </source>
        <target>
          <context value="ma"/>
          <element value="performer"/>
          <variable value="p"/>
        </target>
        <target>
          <context value="p"/>
          <element value="actor"/>
          <variable value="cr"/>
          <transform value="create"/>
          <parameter>
            <valueString value="CodeableReference"/>
          </parameter>
        </target>
        <target>
          <context value="cr"/>
          <element value="reference"/>
          <transform value="copy"/>
          <parameter>
            <valueId value="src"/>
          </parameter>
        </target>
      </rule>
      <rule>
        <name value="fluidNameRule"/>
        <source>
          <context value="g"/>
          <element value="item"/>
          <variable value="it"/>
          <condition value="linkId = 'iv-fluid/name'"/>
        </source>
        <rule>
          <name value="answer"/>
          <source>
            <context value="it"/>
            <element value="answer"/>
            <listMode value="first"/>
            <variable value="a"/>
          </source>
          <rule>
            <name value="medicationText"/>
            <source>
              <context value="a"/>
              <element value="value"/>
              <variable value="txt"/>
            </source>
            <target>
              <context value="ma"/>
              <element value="medication"/>
              <variable value="med"/>
            </target>
            <target>
              <context value="med"/>
              <element value="concept"/>
              <variable value="mc"/>
            </target>
            <target>
              <context value="mc"/>
              <element value="text"/>
              <transform value="copy"/>
              <parameter>
                <valueId value="txt"/>
              </parameter>
            </target>
          </rule>
        </rule>
      </rule>
      <rule>
        <name value="fluidVolumeRule"/>
        <source>
          <context value="g"/>
          <element value="item"/>
          <variable value="it"/>
          <condition
                     value="(linkId = 'iv-fluid/volume') and answer.value.ofType(Quantity).exists()"/>
        </source>
        <rule>
          <name value="answer"/>
          <source>
            <context value="it"/>
            <element value="answer"/>
            <listMode value="first"/>
            <variable value="a"/>
          </source>
          <rule>
            <name value="dosageVolume"/>
            <source>
              <context value="a"/>
              <element value="value"/>
              <variable value="v"/>
            </source>
            <target>
              <context value="ma"/>
              <element value="dosage"/>
              <variable value="dos"/>
            </target>
            <target>
              <context value="dos"/>
              <element value="dose"/>
              <transform value="copy"/>
              <parameter>
                <valueId value="v"/>
              </parameter>
            </target>
          </rule>
        </rule>
        <documentation
                       value="Guarded on the answer being a Quantity, not merely present. Dosage.dose
takes a Quantity or a Range and nothing else, so a client that submits
a bare string there fails the rule and takes the whole extraction with
it -- which is exactly what the questionnaire tester does: it renders a
`quantity` item as a plain text box and submits valueString &quot;5&quot;.
`$validate` on such a response says so plainly (&quot;Answer value must be
of the type Quantity not string&quot;); one non-conformant field should not
cost every other resource on the form."/>
      </rule>
      <rule>
        <name value="occurrence"/>
        <source>
          <context value="qr"/>
          <element value="authored"/>
          <variable value="t"/>
        </source>
        <target>
          <context value="ma"/>
          <element value="occurence"/>
          <transform value="copy"/>
          <parameter>
            <valueId value="t"/>
          </parameter>
        </target>
      </rule>
      <rule>
        <name value="fluidNote"/>
        <source>
          <context value="g"/>
        </source>
        <target>
          <context value="ma"/>
          <element value="note"/>
          <variable value="n"/>
        </target>
        <target>
          <context value="n"/>
          <element value="text"/>
          <transform value="copy"/>
          <parameter>
            <valueString value="Intravenous fluid given during anaesthesia"/>
          </parameter>
        </target>
      </rule>
    </rule>
    <rule>
      <name value="bloodLossObservation"/>
      <source>
        <context value="qr"/>
        <element value="item"/>
        <variable value="it"/>
        <condition
                   value="(linkId = 'estimated-blood-loss') 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="SetProcedureCategory"/>
          <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="8717-1"/>
              </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="Surgical operation note estimated blood loss [Volume]"/>
              </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="set"/>
          <source>
            <context value="a"/>
            <element value="value"/>
            <variable value="v"/>
          </source>
          <target>
            <context value="obs"/>
            <element value="value"/>
            <transform value="copy"/>
            <parameter>
              <valueId value="v"/>
            </parameter>
          </target>
        </rule>
      </rule>
      <rule>
        <name value="estimateNote"/>
        <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="An estimate made in theatre, not a measured volume."/>
          </parameter>
        </target>
      </rule>
      <documentation
                     value="── Estimated blood loss ────────────────────────────────────────────────
LOINC 8717-1, the operation note's own term for it, which is exactly what
this is. The note says it is an estimate: the figure drives a transfusion
decision and a reader has to know it was eyeballed, not measured."/>
    </rule>
    <rule>
      <name value="durationGroup"/>
      <source>
        <context value="qr"/>
        <element value="item"/>
        <variable value="g"/>
        <condition value="linkId = 'case'"/>
      </source>
      <rule>
        <name value="durationObservation"/>
        <source>
          <context value="g"/>
          <element value="item"/>
          <variable value="it"/>
          <condition
                     value="(linkId = 'case/duration') 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="SetProcedureCategory"/>
            <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="89874-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="Anesthesia duration"/>
                </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="set"/>
            <source>
              <context value="a"/>
              <element value="value"/>
              <variable value="v"/>
            </source>
            <target>
              <context value="obs"/>
              <element value="value"/>
              <transform value="copy"/>
              <parameter>
                <valueId value="v"/>
              </parameter>
            </target>
          </rule>
        </rule>
      </rule>
      <documentation
                     value="── Anaesthesia duration ────────────────────────────────────────────────
Extracted only when the form carries it. The questionnaire leaves the field
read-only and expects the client to derive it from the start and completion
times; where the client did, that value is authoritative and is recorded
under LOINC 89874-2. Where it did not, nothing is written -- the Procedure's
period already holds both ends, and a duration computed here from a clock
time with no date could be a day out."/>
    </rule>
  </group>
  <group>
    <name value="BuildObsBase"/>
    <documentation
                   value="─────────────────────────────────────────────────────────────────────────────
Shared scaffolding. Repeated in each map rather than imported: the transform
engine resolves `imports` against whatever StructureMaps happen to be on the
server, and a form that stops extracting because a shared map was not
uploaded is a worse failure than a duplicated group.
Two notes on what the publisher's StructureMap validator says about this file.
Source parameters below are left untyped on purpose. Writing `: Element` makes
the validator compare QuestionnaireResponse.item against the literal 'Element'
and report them as incompatible with each other, which is noise, not a finding.
`evaluate(context, expression)` is flagged as &quot;takes 1 parameter but 2 were
found&quot;. Leave it. The FML parser in the same jar refuses the one-argument form
outright -- it wants a parameter, a comma, then the FHIRPath -- so the
publisher is objecting to what its own compiler emits. Two arguments is the
only form that compiles, and it is what the R5 transform engine executes.
─────────────────────────────────────────────────────────────────────────────"/>
    <input>
      <name value="qr"/>
      <type value="QR"/>
      <mode value="source"/>
    </input>
    <input>
      <name value="obs"/>
      <type value="Observation"/>
      <mode value="target"/>
    </input>
    <input>
      <name value="entry"/>
      <mode value="target"/>
    </input>
    <rule>
      <name value="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
a relative reference as it stands. The hasValue() guard is what stops an
unsaved response -- one posted straight to $extract rather than saved first
-- from writing &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
untyped `.value` accessor: reading `valueCoding` or `valueQuantity` by its
typed property name fails at transform time on HAPI R5 with &quot;Attempt to read
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="SetProcedureCategory"/>
    <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="procedure"/>
            </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="Procedure"/>
            </parameter>
          </target>
        </rule>
      </rule>
    </rule>
  </group>
  <group>
    <name value="BuildProcedureBase"/>
    <input>
      <name value="qr"/>
      <type value="QR"/>
      <mode value="source"/>
    </input>
    <input>
      <name value="r"/>
      <type value="Procedure"/>
      <mode value="target"/>
    </input>
    <input>
      <name value="entry"/>
      <mode value="target"/>
    </input>
    <rule>
      <name value="responseProvenance"/>
      <source>
        <context value="qr"/>
      </source>
      <target>
        <context value="r"/>
      </target>
      <dependent>
        <name value="SetResponseProvenance"/>
        <parameter>
          <valueId value="qr"/>
        </parameter>
        <parameter>
          <valueId value="r"/>
        </parameter>
      </dependent>
    </rule>
    <rule>
      <name value="idAndFullUrl"/>
      <source>
        <context value="qr"/>
      </source>
      <target>
        <context value="r"/>
        <element value="id"/>
        <transform value="uuid"/>
      </target>
      <dependent>
        <name value="SetProcedureFullUrl"/>
        <parameter>
          <valueId value="r"/>
        </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="Procedure"/>
          </parameter>
        </target>
      </rule>
    </rule>
    <rule>
      <name value="occurrenceFallback"/>
      <source>
        <context value="qr"/>
        <element value="authored"/>
        <variable value="t"/>
      </source>
      <target>
        <context value="r"/>
        <element value="occurrence"/>
        <transform value="copy"/>
        <parameter>
          <valueId value="t"/>
        </parameter>
      </target>
      <documentation
                     value="The response's own time, as a floor, the way BuildObsBase does it. A rule
that reads a time off the form overwrites this; without it a procedure whose
date column was taken off on review has no time at all, and a procedure with
no time cannot be ordered against the rest of the admission."/>
    </rule>
    <rule>
      <name value="subject"/>
      <source>
        <context value="qr"/>
        <element value="subject"/>
        <variable value="s"/>
      </source>
      <target>
        <context value="r"/>
        <element value="subject"/>
        <transform value="copy"/>
        <parameter>
          <valueId value="s"/>
        </parameter>
      </target>
    </rule>
  </group>
  <group>
    <name value="SetProcedureFullUrl"/>
    <input>
      <name value="r"/>
      <type value="Procedure"/>
      <mode value="source"/>
    </input>
    <input>
      <name value="entry"/>
      <mode value="target"/>
    </input>
    <rule>
      <name value="assignFullUrl"/>
      <source>
        <context value="r"/>
        <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/Procedure/"/>
        </parameter>
        <parameter>
          <valueId value="id"/>
        </parameter>
      </target>
    </rule>
  </group>
  <group>
    <name value="BuildMedicationAdministrationBase"/>
    <input>
      <name value="qr"/>
      <type value="QR"/>
      <mode value="source"/>
    </input>
    <input>
      <name value="r"/>
      <type value="MedicationAdministration"/>
      <mode value="target"/>
    </input>
    <input>
      <name value="entry"/>
      <mode value="target"/>
    </input>
    <rule>
      <name value="responseProvenance"/>
      <source>
        <context value="qr"/>
      </source>
      <target>
        <context value="r"/>
      </target>
      <dependent>
        <name value="SetResponseProvenance"/>
        <parameter>
          <valueId value="qr"/>
        </parameter>
        <parameter>
          <valueId value="r"/>
        </parameter>
      </dependent>
    </rule>
    <rule>
      <name value="idAndFullUrl"/>
      <source>
        <context value="qr"/>
      </source>
      <target>
        <context value="r"/>
        <element value="id"/>
        <transform value="uuid"/>
      </target>
      <dependent>
        <name value="SetMedicationAdministrationFullUrl"/>
        <parameter>
          <valueId value="r"/>
        </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="MedicationAdministration"/>
          </parameter>
        </target>
      </rule>
    </rule>
    <rule>
      <name value="subject"/>
      <source>
        <context value="qr"/>
        <element value="subject"/>
        <variable value="s"/>
      </source>
      <target>
        <context value="r"/>
        <element value="subject"/>
        <transform value="copy"/>
        <parameter>
          <valueId value="s"/>
        </parameter>
      </target>
    </rule>
    <rule>
      <name value="occurrenceFallback"/>
      <source>
        <context value="qr"/>
        <element value="authored"/>
        <variable value="t"/>
      </source>
      <target>
        <context value="r"/>
        <element value="occurence"/>
        <transform value="copy"/>
        <parameter>
          <valueId value="t"/>
        </parameter>
      </target>
      <documentation
                     value="The response's own time, as a floor. A row that names the time it was given
overwrites this; a form whose time column was taken off on review would
otherwise produce an administration with no time at all, which is not a
record of an administration. Same fallback BuildObsBase already applies."/>
    </rule>
  </group>
  <group>
    <name value="SetMedicationAdministrationFullUrl"/>
    <input>
      <name value="r"/>
      <type value="MedicationAdministration"/>
      <mode value="source"/>
    </input>
    <input>
      <name value="entry"/>
      <mode value="target"/>
    </input>
    <rule>
      <name value="assignFullUrl"/>
      <source>
        <context value="r"/>
        <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/MedicationAdministration/"/>
        </parameter>
        <parameter>
          <valueId value="id"/>
        </parameter>
      </target>
    </rule>
  </group>
  <group>
    <name value="SetResponseProvenance"/>
    <documentation
                   value="── Provenance and tenancy ───────────────────────────────────────────────────
Two tags on everything this map creates. The first says which questionnaire
produced it, so a form that reopens mid-admission recalls its own earlier
entries and not another form's. The second copies the tenant tags off the
response, because nothing else on the path puts them there.
The code is the form's document type, not the questionnaire's id: every
environment mints its own ids, and there is only one set of maps, so an id
here would tie the tag to whichever environment stamped it.
── 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="anaesthetic-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="Anaesthetic 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
lands on the same meta the rule above created rather than a second one."/>
    </rule>
  </group>
</StructureMap>