SGHI FHIR Profile Implementation Guide
0.1.0 - ci-build

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

: Inpatient Adult General Admission Assessment Extraction - XML Representation

Active as of 2026-09-14

Raw xml | Download


<StructureMap xmlns="http://hl7.org/fhir">
  <id value="ExtractInpatientAdultGeneralAdmissionAssessment"/>
  <text>
    <status value="generated"/>
    <div xmlns="http://www.w3.org/1999/xhtml"><p class="res-header-id"><b>Generated Narrative: StructureMap ExtractInpatientAdultGeneralAdmissionAssessment</b></p><a name="ExtractInpatientAdultGeneralAdmissionAssessment"> </a><a name="hcExtractInpatientAdultGeneralAdmissionAssessment"> </a><pre class="fml">
<span style="color: #cc00cc">/// <b>url</b> = </span><span style="color: blue">'https://fhir.slade360.co.ke/fhir/StructureMap/ExtractInpatientAdultGeneralAdmissionAssessment'</span>
<span style="color: #cc00cc">/// <b>name</b> = </span><span style="color: blue">'ExtractInpatientAdultGeneralAdmissionAssessment'</span>
<span style="color: #cc00cc">/// <b>title</b> = </span><span style="color: blue">'Inpatient Adult General Admission Assessment Extraction'</span>
<span style="color: #cc00cc">/// <b>status</b> = </span><span style="color: blue">'active'</span>
<span style="color: #cc00cc">/// <b>description</b> = </span><span style="color: blue">'Turns a response to the adult general admission assessment into a chief-complaint Observation, one Observation per vital, and a Composition that files the assessment and carries the allergies and medication the assessor reviewed. Nothing is copied: the allergies and medication are already AllergyIntolerance and MedicationRequest resources -- the form loads them off the server -- so they become section entries. The Composition exists for exactly that reason; without a container those two rows of the assessment extract to nothing at all.'</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/composition.html" title="Composition">http://hl7.org/fhir/StructureDefinition/Composition</a><span style="color: navy">&quot; </span><b>alias </b>Composition <b>as </b><b>target</b>

<b>group </b>ExtractInpatientAdultGeneralAdmissionAssessment<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">── Presenting complaint ───────────────────────────────────────────────────</span>
  <span style="color: navy">// </span><span style="color: green">Category `social-history` and code 10154-3 match what extract-vital-signs</span>
  <span style="color: navy">// </span><span style="color: green">already produces for a chief complaint, so a consumer querying</span>
  <span style="color: navy">// </span><span style="color: green">category=social-history&amp;code=10154-3 gets both without knowing which form</span>
  <span style="color: navy">// </span><span style="color: green">the complaint came from.</span>
  qr.item<b> as </b><span style="color: maroon">itC</span><b> where </b><span style="color: navy">(</span>(linkId = 'complaint') and answer.value.exists()<span style="color: navy">)</span><b> then</b><span style="color: navy"> {
</span>    itC.answer first<b> as </b><span style="color: maroon">aC</span><b> then</b><span style="color: navy"> {
</span>      aC<span style="color: navy"><b> -&gt; </b></span> bundle.entry<b> as </b><span style="color: maroon">entryC</span><span style="color: navy">, </span> entryC.resource = <b>create</b><span style="color: navy">(</span><span style="color: blue">'Observation'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">obsC</span><b> then</b><span style="color: navy"> {
</span>        qr<span style="color: navy"><b> -&gt; </b></span> obsC<span style="color: navy">, </span> entryC<b> then </b>BuildObsBase<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">obsC</span><span style="color: navy">, </span><span style="color: maroon">entryC</span><span style="color: navy">)</span> <i>&quot;complaintBase&quot;</i><span style="color: navy">;</span>
        qr<span style="color: navy"><b> -&gt; </b></span>obsC<b> then </b>SetSocialHistoryCategory<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">obsC</span><span style="color: navy">)</span> <i>&quot;complaintCategory&quot;</i><span style="color: navy">;</span>
        qr<span style="color: navy"><b> -&gt; </b></span>obsC.code<b> as </b><span style="color: maroon">code</span><b> then</b><span style="color: navy"> {
</span>          qr<span style="color: navy"><b> -&gt; </b></span>code.coding<b> as </b><span style="color: maroon">coding</span><b> then</b><span style="color: navy"> {
</span>            qr<span style="color: navy"><b> -&gt; </b></span>coding.system = <span style="color: blue">'http://loinc.org'</span> <i>&quot;codeSystem&quot;</i><span style="color: navy">;</span>
            qr<span style="color: navy"><b> -&gt; </b></span>coding.code = <span style="color: blue">'10154-3'</span> <i>&quot;codeCode&quot;</i><span style="color: navy">;</span>
            qr<span style="color: navy"><b> -&gt; </b></span>coding.display = <span style="color: blue">'Chief complaint Narrative - Reported'</span> <i>&quot;codeDisplay&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;codeCoding&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;complaintCode&quot;</i><span style="color: navy">;</span>
        aC.value<b> as </b><span style="color: maroon">v</span><span style="color: navy"><b> -&gt; </b></span>obsC.value = <span style="color: maroon">v</span> <i>&quot;complaintValue&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;complaintObservation&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;complaintAnswer&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">}</span> <i>&quot;complaintRule&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">// </span><span style="color: green">── Vitals on admission ────────────────────────────────────────────────────</span>
  <span style="color: navy">// </span><span style="color: green">Six items, six Observations, exactly as the form extracted before it had a</span>
  <span style="color: navy">// </span><span style="color: green">map. Each answer is already a Quantity -- the item is type `quantity` with</span>
  <span style="color: navy">// </span><span style="color: green">a questionnaire-unitOption pinning the unit -- so it is copied through</span>
  <span style="color: navy">// </span><span style="color: green">whole. Rebuilding it here would mean restating a unit the client actually</span>
  <span style="color: navy">// </span><span style="color: green">sent, which turns a wrong unit into a wrong reading.</span>
  qr.item<b> as </b><span style="color: maroon">gV</span><b> where </b><span style="color: navy">(</span>linkId = 'vitals'<span style="color: navy">)</span><b> then</b><span style="color: navy"> {
</span>    gV.item<b> as </b><span style="color: maroon">itS</span><b> where </b><span style="color: navy">(</span>(linkId = 'vitals.bpSys') and answer.value.exists()<span style="color: navy">)</span><b> then</b><span style="color: navy"> {
</span>      itS.answer first<b> as </b><span style="color: maroon">aS</span><b> then</b><span style="color: navy"> {
</span>        aS<span style="color: navy"><b> -&gt; </b></span> bundle.entry<b> as </b><span style="color: maroon">entryS</span><span style="color: navy">, </span> entryS.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">obsS</span><b> then</b><span style="color: navy"> {
</span>          qr<span style="color: navy"><b> -&gt; </b></span> obsS<span style="color: navy">, </span> entryS<b> then </b>BuildObsBase<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">obsS</span><span style="color: navy">, </span><span style="color: maroon">entryS</span><span style="color: navy">)</span> <i>&quot;bpSysBase&quot;</i><span style="color: navy">;</span>
          qr<span style="color: navy"><b> -&gt; </b></span>obsS<b> then </b>SetVitalSignsCategory<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">obsS</span><span style="color: navy">)</span> <i>&quot;bpSysCategory&quot;</i><span style="color: navy">;</span>
          qr<span style="color: navy"><b> -&gt; </b></span>obsS.code<b> as </b><span style="color: maroon">code</span><b> then</b><span style="color: navy"> {
</span>            qr<span style="color: navy"><b> -&gt; </b></span>code.coding<b> as </b><span style="color: maroon">coding</span><b> then</b><span style="color: navy"> {
</span>              qr<span style="color: navy"><b> -&gt; </b></span>coding.system = <span style="color: blue">'http://loinc.org'</span> <i>&quot;codeSystem&quot;</i><span style="color: navy">;</span>
              qr<span style="color: navy"><b> -&gt; </b></span>coding.code = <span style="color: blue">'8480-6'</span> <i>&quot;codeCode&quot;</i><span style="color: navy">;</span>
              qr<span style="color: navy"><b> -&gt; </b></span>coding.display = <span style="color: blue">'Systolic blood pressure'</span> <i>&quot;codeDisplay&quot;</i><span style="color: navy">;</span>
            <span style="color: navy">}</span> <i>&quot;codeCoding&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;bpSysCode&quot;</i><span style="color: navy">;</span>
          aS.value<b> as </b><span style="color: maroon">v</span><span style="color: navy"><b> -&gt; </b></span>obsS.value = <span style="color: maroon">v</span> <i>&quot;bpSysValue&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;bpSysObservation&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;bpSysAnswer&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;bpSysRule&quot;</i><span style="color: navy">;</span>
    gV.item<b> as </b><span style="color: maroon">itD</span><b> where </b><span style="color: navy">(</span>(linkId = 'vitals.bpDia') and answer.value.exists()<span style="color: navy">)</span><b> then</b><span style="color: navy"> {
</span>      itD.answer first<b> as </b><span style="color: maroon">aD</span><b> then</b><span style="color: navy"> {
</span>        aD<span style="color: navy"><b> -&gt; </b></span> bundle.entry<b> as </b><span style="color: maroon">entryD</span><span style="color: navy">, </span> entryD.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">obsD</span><b> then</b><span style="color: navy"> {
</span>          qr<span style="color: navy"><b> -&gt; </b></span> obsD<span style="color: navy">, </span> entryD<b> then </b>BuildObsBase<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">obsD</span><span style="color: navy">, </span><span style="color: maroon">entryD</span><span style="color: navy">)</span> <i>&quot;bpDiaBase&quot;</i><span style="color: navy">;</span>
          qr<span style="color: navy"><b> -&gt; </b></span>obsD<b> then </b>SetVitalSignsCategory<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">obsD</span><span style="color: navy">)</span> <i>&quot;bpDiaCategory&quot;</i><span style="color: navy">;</span>
          qr<span style="color: navy"><b> -&gt; </b></span>obsD.code<b> as </b><span style="color: maroon">code</span><b> then</b><span style="color: navy"> {
</span>            qr<span style="color: navy"><b> -&gt; </b></span>code.coding<b> as </b><span style="color: maroon">coding</span><b> then</b><span style="color: navy"> {
</span>              qr<span style="color: navy"><b> -&gt; </b></span>coding.system = <span style="color: blue">'http://loinc.org'</span> <i>&quot;codeSystem&quot;</i><span style="color: navy">;</span>
              qr<span style="color: navy"><b> -&gt; </b></span>coding.code = <span style="color: blue">'8462-4'</span> <i>&quot;codeCode&quot;</i><span style="color: navy">;</span>
              qr<span style="color: navy"><b> -&gt; </b></span>coding.display = <span style="color: blue">'Diastolic blood pressure'</span> <i>&quot;codeDisplay&quot;</i><span style="color: navy">;</span>
            <span style="color: navy">}</span> <i>&quot;codeCoding&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;bpDiaCode&quot;</i><span style="color: navy">;</span>
          aD.value<b> as </b><span style="color: maroon">v</span><span style="color: navy"><b> -&gt; </b></span>obsD.value = <span style="color: maroon">v</span> <i>&quot;bpDiaValue&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;bpDiaObservation&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;bpDiaAnswer&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;bpDiaRule&quot;</i><span style="color: navy">;</span>
    gV.item<b> as </b><span style="color: maroon">itP</span><b> where </b><span style="color: navy">(</span>(linkId = 'vitals.pulse') and answer.value.exists()<span style="color: navy">)</span><b> then</b><span style="color: navy"> {
</span>      itP.answer first<b> as </b><span style="color: maroon">aP</span><b> then</b><span style="color: navy"> {
</span>        aP<span style="color: navy"><b> -&gt; </b></span> bundle.entry<b> as </b><span style="color: maroon">entryP</span><span style="color: navy">, </span> entryP.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">obsP</span><b> then</b><span style="color: navy"> {
</span>          qr<span style="color: navy"><b> -&gt; </b></span> obsP<span style="color: navy">, </span> entryP<b> then </b>BuildObsBase<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">obsP</span><span style="color: navy">, </span><span style="color: maroon">entryP</span><span style="color: navy">)</span> <i>&quot;pulseBase&quot;</i><span style="color: navy">;</span>
          qr<span style="color: navy"><b> -&gt; </b></span>obsP<b> then </b>SetVitalSignsCategory<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">obsP</span><span style="color: navy">)</span> <i>&quot;pulseCategory&quot;</i><span style="color: navy">;</span>
          qr<span style="color: navy"><b> -&gt; </b></span>obsP.code<b> as </b><span style="color: maroon">code</span><b> then</b><span style="color: navy"> {
</span>            qr<span style="color: navy"><b> -&gt; </b></span>code.coding<b> as </b><span style="color: maroon">coding</span><b> then</b><span style="color: navy"> {
</span>              qr<span style="color: navy"><b> -&gt; </b></span>coding.system = <span style="color: blue">'http://loinc.org'</span> <i>&quot;codeSystem&quot;</i><span style="color: navy">;</span>
              qr<span style="color: navy"><b> -&gt; </b></span>coding.code = <span style="color: blue">'8867-4'</span> <i>&quot;codeCode&quot;</i><span style="color: navy">;</span>
              qr<span style="color: navy"><b> -&gt; </b></span>coding.display = <span style="color: blue">'Heart rate'</span> <i>&quot;codeDisplay&quot;</i><span style="color: navy">;</span>
            <span style="color: navy">}</span> <i>&quot;codeCoding&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;pulseCode&quot;</i><span style="color: navy">;</span>
          aP.value<b> as </b><span style="color: maroon">v</span><span style="color: navy"><b> -&gt; </b></span>obsP.value = <span style="color: maroon">v</span> <i>&quot;pulseValue&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;pulseObservation&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;pulseAnswer&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;pulseRule&quot;</i><span style="color: navy">;</span>
    gV.item<b> as </b><span style="color: maroon">itT</span><b> where </b><span style="color: navy">(</span>(linkId = 'vitals.temp') and answer.value.exists()<span style="color: navy">)</span><b> then</b><span style="color: navy"> {
</span>      itT.answer first<b> as </b><span style="color: maroon">aT</span><b> then</b><span style="color: navy"> {
</span>        aT<span style="color: navy"><b> -&gt; </b></span> bundle.entry<b> as </b><span style="color: maroon">entryT</span><span style="color: navy">, </span> entryT.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">obsT</span><b> then</b><span style="color: navy"> {
</span>          qr<span style="color: navy"><b> -&gt; </b></span> obsT<span style="color: navy">, </span> entryT<b> then </b>BuildObsBase<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">obsT</span><span style="color: navy">, </span><span style="color: maroon">entryT</span><span style="color: navy">)</span> <i>&quot;tempBase&quot;</i><span style="color: navy">;</span>
          qr<span style="color: navy"><b> -&gt; </b></span>obsT<b> then </b>SetVitalSignsCategory<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">obsT</span><span style="color: navy">)</span> <i>&quot;tempCategory&quot;</i><span style="color: navy">;</span>
          qr<span style="color: navy"><b> -&gt; </b></span>obsT.code<b> as </b><span style="color: maroon">code</span><b> then</b><span style="color: navy"> {
</span>            qr<span style="color: navy"><b> -&gt; </b></span>code.coding<b> as </b><span style="color: maroon">coding</span><b> then</b><span style="color: navy"> {
</span>              qr<span style="color: navy"><b> -&gt; </b></span>coding.system = <span style="color: blue">'http://loinc.org'</span> <i>&quot;codeSystem&quot;</i><span style="color: navy">;</span>
              qr<span style="color: navy"><b> -&gt; </b></span>coding.code = <span style="color: blue">'8310-5'</span> <i>&quot;codeCode&quot;</i><span style="color: navy">;</span>
              qr<span style="color: navy"><b> -&gt; </b></span>coding.display = <span style="color: blue">'Body temperature'</span> <i>&quot;codeDisplay&quot;</i><span style="color: navy">;</span>
            <span style="color: navy">}</span> <i>&quot;codeCoding&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;tempCode&quot;</i><span style="color: navy">;</span>
          aT.value<b> as </b><span style="color: maroon">v</span><span style="color: navy"><b> -&gt; </b></span>obsT.value = <span style="color: maroon">v</span> <i>&quot;tempValue&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;tempObservation&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;tempAnswer&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;tempRule&quot;</i><span style="color: navy">;</span>
    gV.item<b> as </b><span style="color: maroon">itR</span><b> where </b><span style="color: navy">(</span>(linkId = 'vitals.resp') and answer.value.exists()<span style="color: navy">)</span><b> then</b><span style="color: navy"> {
</span>      itR.answer first<b> as </b><span style="color: maroon">aR</span><b> then</b><span style="color: navy"> {
</span>        aR<span style="color: navy"><b> -&gt; </b></span> bundle.entry<b> as </b><span style="color: maroon">entryR</span><span style="color: navy">, </span> entryR.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">obsR</span><b> then</b><span style="color: navy"> {
</span>          qr<span style="color: navy"><b> -&gt; </b></span> obsR<span style="color: navy">, </span> entryR<b> then </b>BuildObsBase<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">obsR</span><span style="color: navy">, </span><span style="color: maroon">entryR</span><span style="color: navy">)</span> <i>&quot;respBase&quot;</i><span style="color: navy">;</span>
          qr<span style="color: navy"><b> -&gt; </b></span>obsR<b> then </b>SetVitalSignsCategory<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">obsR</span><span style="color: navy">)</span> <i>&quot;respCategory&quot;</i><span style="color: navy">;</span>
          qr<span style="color: navy"><b> -&gt; </b></span>obsR.code<b> as </b><span style="color: maroon">code</span><b> then</b><span style="color: navy"> {
</span>            qr<span style="color: navy"><b> -&gt; </b></span>code.coding<b> as </b><span style="color: maroon">coding</span><b> then</b><span style="color: navy"> {
</span>              qr<span style="color: navy"><b> -&gt; </b></span>coding.system = <span style="color: blue">'http://loinc.org'</span> <i>&quot;codeSystem&quot;</i><span style="color: navy">;</span>
              qr<span style="color: navy"><b> -&gt; </b></span>coding.code = <span style="color: blue">'9279-1'</span> <i>&quot;codeCode&quot;</i><span style="color: navy">;</span>
              qr<span style="color: navy"><b> -&gt; </b></span>coding.display = <span style="color: blue">'Respiratory rate'</span> <i>&quot;codeDisplay&quot;</i><span style="color: navy">;</span>
            <span style="color: navy">}</span> <i>&quot;codeCoding&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;respCode&quot;</i><span style="color: navy">;</span>
          aR.value<b> as </b><span style="color: maroon">v</span><span style="color: navy"><b> -&gt; </b></span>obsR.value = <span style="color: maroon">v</span> <i>&quot;respValue&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;respObservation&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;respAnswer&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;respRule&quot;</i><span style="color: navy">;</span>
    gV.item<b> as </b><span style="color: maroon">itO</span><b> where </b><span style="color: navy">(</span>(linkId = 'vitals.spo2') and answer.value.exists()<span style="color: navy">)</span><b> then</b><span style="color: navy"> {
</span>      itO.answer first<b> as </b><span style="color: maroon">aO</span><b> then</b><span style="color: navy"> {
</span>        aO<span style="color: navy"><b> -&gt; </b></span> bundle.entry<b> as </b><span style="color: maroon">entryO</span><span style="color: navy">, </span> entryO.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">obsO</span><b> then</b><span style="color: navy"> {
</span>          qr<span style="color: navy"><b> -&gt; </b></span> obsO<span style="color: navy">, </span> entryO<b> then </b>BuildObsBase<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">obsO</span><span style="color: navy">, </span><span style="color: maroon">entryO</span><span style="color: navy">)</span> <i>&quot;spo2Base&quot;</i><span style="color: navy">;</span>
          qr<span style="color: navy"><b> -&gt; </b></span>obsO<b> then </b>SetVitalSignsCategory<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">obsO</span><span style="color: navy">)</span> <i>&quot;spo2Category&quot;</i><span style="color: navy">;</span>
          qr<span style="color: navy"><b> -&gt; </b></span>obsO.code<b> as </b><span style="color: maroon">code</span><b> then</b><span style="color: navy"> {
</span>            qr<span style="color: navy"><b> -&gt; </b></span>code.coding<b> as </b><span style="color: maroon">coding</span><b> then</b><span style="color: navy"> {
</span>              qr<span style="color: navy"><b> -&gt; </b></span>coding.system = <span style="color: blue">'http://loinc.org'</span> <i>&quot;codeSystem&quot;</i><span style="color: navy">;</span>
              qr<span style="color: navy"><b> -&gt; </b></span>coding.code = <span style="color: blue">'59408-5'</span> <i>&quot;codeCode&quot;</i><span style="color: navy">;</span>
              qr<span style="color: navy"><b> -&gt; </b></span>coding.display = <span style="color: blue">'Oxygen saturation in Arterial blood by Pulse oximetry'</span> <i>&quot;codeDisplay&quot;</i><span style="color: navy">;</span>
            <span style="color: navy">}</span> <i>&quot;codeCoding&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;spo2Code&quot;</i><span style="color: navy">;</span>
          aO.value<b> as </b><span style="color: maroon">v</span><span style="color: navy"><b> -&gt; </b></span>obsO.value = <span style="color: maroon">v</span> <i>&quot;spo2Value&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;spo2Observation&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;spo2Answer&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;spo2Rule&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">}</span> <i>&quot;vitalsGroupRule&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">// </span><span style="color: green">── The assessment as a filed document ─────────────────────────────────────</span>
  qr<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">'Composition'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">comp</span><b> then</b><span style="color: navy"> {
</span>    qr<span style="color: navy"><b> -&gt; </b></span> comp<span style="color: navy">, </span> entry<b> then </b>BuildNoteBase<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">comp</span><span style="color: navy">, </span><span style="color: maroon">entry</span><span style="color: navy">)</span> <i>&quot;noteBase&quot;</i><span style="color: navy">;</span>
    qr<span style="color: navy"><b> -&gt; </b></span>comp.name = <span style="color: blue">'InpatientAdultGeneralAdmissionAssessment'</span> <i>&quot;noteName&quot;</i><span style="color: navy">;</span>
    qr<span style="color: navy"><b> -&gt; </b></span>comp.title = <span style="color: blue">'Adult general admission assessment'</span> <i>&quot;noteTitle&quot;</i><span style="color: navy">;</span>
    qr<span style="color: navy"><b> -&gt; </b></span>comp.type<b> as </b><span style="color: maroon">ty</span><b> then</b><span style="color: navy"> {
</span>      qr<span style="color: navy"><b> -&gt; </b></span>ty.coding<b> as </b><span style="color: maroon">sghi</span><b> then</b><span style="color: navy"> {
</span>        qr<span style="color: navy"><b> -&gt; </b></span>sghi.system = <span style="color: blue">'https://fhir.slade360.co.ke/fhir/CodeSystem/inpatient-document-type-codesystem'</span> <i>&quot;sghiSystem&quot;</i><span style="color: navy">;</span>
        qr<span style="color: navy"><b> -&gt; </b></span>sghi.code = <span style="color: blue">'adult-general-admission-assessment'</span> <i>&quot;sghiCode&quot;</i><span style="color: navy">;</span>
        qr<span style="color: navy"><b> -&gt; </b></span>sghi.display = <span style="color: blue">'Adult general admission assessment'</span> <i>&quot;sghiDisplay&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;sghiCoding&quot;</i><span style="color: navy">;</span>
      qr<span style="color: navy"><b> -&gt; </b></span>ty.text = <span style="color: blue">'Adult general admission assessment'</span> <i>&quot;typeText&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;noteType&quot;</i><span style="color: navy">;</span>
    qr.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'complaint') and answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span>comp.section<b> as </b><span style="color: maroon">sec</span><b> then</b><span style="color: navy"> {
</span>      it<span style="color: navy"><b> -&gt; </b></span>sec.title = <span style="color: blue">'Presenting complaint'</span> <i>&quot;complaintTitle&quot;</i><span style="color: navy">;</span>
      it<span style="color: navy"><b> -&gt; </b></span>sec<b> then </b>AddSectionText<span style="color: navy">(</span><span style="color: maroon">it</span><span style="color: navy">, </span><span style="color: maroon">sec</span><span style="color: navy">)</span> <i>&quot;complaintSectionText&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;complaintSectionRule&quot;</i><span style="color: navy">;</span>
    qr.item<b> as </b><span style="color: maroon">itA</span><b> where </b><span style="color: navy">(</span>(linkId = 'allergies') and answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span>comp.section<b> as </b><span style="color: maroon">secA</span><b> then</b><span style="color: navy"> {
</span>      itA<span style="color: navy"><b> -&gt; </b></span>secA.title = <span style="color: blue">'Known allergies'</span> <i>&quot;allergiesTitle&quot;</i><span style="color: navy">;</span>
      itA.answer<b> as </b><span style="color: maroon">aA</span><b> then</b><span style="color: navy"> {
</span>        aA.value<b> as </b><span style="color: maroon">av</span><span style="color: navy"><b> -&gt; </b></span>secA.entry = <span style="color: maroon">av</span> <i>&quot;allergiesEntry&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;allergiesAnswers&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;allergiesRule&quot;</i><span style="color: navy">;</span>
    qr.item<b> as </b><span style="color: maroon">itM</span><b> where </b><span style="color: navy">(</span>(linkId = 'meds') and answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span>comp.section<b> as </b><span style="color: maroon">secM</span><b> then</b><span style="color: navy"> {
</span>      itM<span style="color: navy"><b> -&gt; </b></span>secM.title = <span style="color: blue">'Current medication'</span> <i>&quot;medsTitle&quot;</i><span style="color: navy">;</span>
      itM.answer<b> as </b><span style="color: maroon">aM</span><b> then</b><span style="color: navy"> {
</span>        aM.value<b> as </b><span style="color: maroon">mv</span><span style="color: navy"><b> -&gt; </b></span>secM.entry = <span style="color: maroon">mv</span> <i>&quot;medsEntry&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;medsAnswers&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;medsRule&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">}</span> <i>&quot;composition&quot;</i><span style="color: navy">;</span>
<span style="color: navy">}

</span><span style="color: navy">// </span><span style="color: green">─────────────────────────────────────────────────────────────────────────────</span>
<span style="color: navy">// </span><span style="color: green">Shared scaffolding. Repeated in each map rather than imported: the transform</span>
<span style="color: navy">// </span><span style="color: green">engine resolves `imports` against whatever StructureMaps happen to be on the</span>
<span style="color: navy">// </span><span style="color: green">server, and a form that stops extracting because a shared map was not</span>
<span style="color: navy">// </span><span style="color: green">uploaded is a worse failure than a duplicated group.</span>
<span style="color: navy">// </span><span style="color: green">─────────────────────────────────────────────────────────────────────────────</span>
<span style="color: navy">// </span><span style="color: green">Two notes on what the publisher's StructureMap validator says about this file.</span>
<span style="color: navy">// </span><span style="color: green">Source parameters below are left untyped on purpose. Writing `: Element` makes</span>
<span style="color: navy">// </span><span style="color: green">the validator compare QuestionnaireResponse.item against the literal 'Element'</span>
<span style="color: navy">// </span><span style="color: green">and report them as incompatible with each other, which is noise, not a finding.</span>
<span style="color: navy">// </span><span style="color: green">Untyped, it says only that it cannot check the paths.</span>
<span style="color: navy">// </span><span style="color: green">`evaluate(context, expression)` is flagged as &quot;takes 1 parameter but 2 were</span>
<span style="color: navy">// </span><span style="color: green">found&quot;. Leave it. The FML parser in the same jar refuses the one-argument form</span>
<span style="color: navy">// </span><span style="color: green">outright -- it wants a parameter, a comma, then the FHIRPath -- so the publisher</span>
<span style="color: navy">// </span><span style="color: green">is objecting to what its own compiler emits. Two arguments is the only form that</span>
<span style="color: navy">// </span><span style="color: green">compiles, and it is what the R5 transform engine executes.</span>
<b>group </b>BuildObsBase<span style="color: navy">(</span><b>source</b> <span style="color: maroon">qr</span><span style="color: navy"> : </span>QR, <b>target</b> <span style="color: maroon">obs</span><span style="color: navy"> : </span>Observation, <b>target</b> <span style="color: maroon">entry</span><span style="color: navy">)</span><span style="color: navy"> {
</span>  qr<span style="color: navy"><b> -&gt; </b></span>obs.id = <b>uuid</b><span style="color: navy">(</span><span style="color: navy">)</span><b> then </b>SetObservationFullUrl<span style="color: navy">(</span><span style="color: maroon">obs</span><span style="color: navy">, </span><span style="color: maroon">entry</span><span style="color: navy">)</span> <i>&quot;idAndFullUrl&quot;</i><span style="color: navy">;</span>
  qr<span style="color: navy"><b> -&gt; </b></span>entry.request<b> as </b><span style="color: maroon">request</span><b> then</b><span style="color: navy"> {
</span>    qr<span style="color: navy"><b> -&gt; </b></span>request.method = <span style="color: blue">'POST'</span> <i>&quot;requestMethod&quot;</i><span style="color: navy">;</span>
    qr<span style="color: navy"><b> -&gt; </b></span>request.url = <span style="color: blue">'Observation'</span> <i>&quot;requestUrl&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">}</span> <i>&quot;entryRequest&quot;</i><span style="color: navy">;</span>
  qr<span style="color: navy"><b> -&gt; </b></span>obs.status = <span style="color: blue">'final'</span> <i>&quot;status&quot;</i><span style="color: navy">;</span>
  qr.subject<b> as </b><span style="color: maroon">s</span><span style="color: navy"><b> -&gt; </b></span>obs.subject = <span style="color: maroon">s</span><span style="color: navy">;</span>
  qr.encounter<b> as </b><span style="color: maroon">e</span><span style="color: navy"><b> -&gt; </b></span>obs.encounter = <span style="color: maroon">e</span><span style="color: navy">;</span>
  <span style="color: navy">// </span><span style="color: green">`effective`, not `effectiveDateTime`: the R5 transform engine writes choice</span>
  <span style="color: navy">// </span><span style="color: green">elements by their base name and rejects the typed form. This form asks for</span>
  <span style="color: navy">// </span><span style="color: green">no time of its own, so the moment the response was authored is the best</span>
  <span style="color: navy">// </span><span style="color: green">available.</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">`qr.id` already resolves to the type-qualified relative reference under this</span>
  <span style="color: navy">// </span><span style="color: green">engine, so it is used unprefixed.</span>
  qr<span style="color: navy"><b> -&gt; </b></span>obs.derivedFrom = <b>create</b><span style="color: navy">(</span><span style="color: blue">'Reference'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">ref</span><b> then</b><span style="color: navy"> {
</span>    qr.id<b> as </b><span style="color: maroon">qid</span><span style="color: navy"><b> -&gt; </b></span>ref.reference = <span style="color: maroon">qid</span> <i>&quot;derivedFromRef&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">}</span> <i>&quot;linkQuestionnaireResponse&quot;</i><span style="color: navy">;</span>
<span style="color: navy">}

</span><b>group </b>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>SetSocialHistoryCategory<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">'social-history'</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">'Social History'</span> <i>&quot;categoryDisplay&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;categoryCoding&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">}</span> <i>&quot;category&quot;</i><span style="color: navy">;</span>
<span style="color: navy">}

</span><b>group </b>SetObservationFullUrl<span style="color: navy">(</span><b>source</b> <span style="color: maroon">obs</span><span style="color: navy"> : </span>Observation, <b>target</b> <span style="color: maroon">entry</span><span style="color: navy">)</span><span style="color: navy"> {
</span>  obs.id<b> as </b><span style="color: maroon">id</span><span style="color: navy"><b> -&gt; </b></span>entry.fullUrl = <b>append</b><span style="color: navy">(</span><span style="color: blue">'https://fhir.slade360.co.ke/fhir/Observation/'</span><span style="color: navy">, </span><span style="color: maroon">id</span><span style="color: navy">)</span> <i>&quot;assignFullUrl&quot;</i><span style="color: navy">;</span>
<span style="color: navy">}

</span><b>group </b>BuildNoteBase<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">comp</span><span style="color: navy"> : </span>Composition, <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>comp.id = <b>uuid</b><span style="color: navy">(</span><span style="color: navy">)</span><b> then </b>SetCompositionFullUrl<span style="color: navy">(</span><span style="color: maroon">comp</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">'Composition'</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>comp.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>comp.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>comp.encounter = <span style="color: maroon">e</span><span style="color: navy">;</span>
  <span style="color: navy">// </span><span style="color: green">Composition.date is 1..1. `authored` is only 0..1 on the response, so when a</span>
  <span style="color: navy">// </span><span style="color: green">client sends none the extraction time stands in. It is a poor substitute for</span>
  <span style="color: navy">// </span><span style="color: green">when the note was written, but a document with no date at all is worse, and</span>
  <span style="color: navy">// </span><span style="color: green">extraction happens moments after submission in practice.</span>
  qr.authored<b> as </b><span style="color: maroon">t</span><span style="color: navy"><b> -&gt; </b></span>comp.date = <span style="color: maroon">t</span> <i>&quot;date&quot;</i><span style="color: navy">;</span>
  qr<b> where </b><span style="color: navy">(</span>authored.exists().not()<span style="color: navy">)</span><b> then</b><span style="color: navy"> {
</span>    qr<span style="color: navy"><b> -&gt; </b></span>comp.date = evaluate<span style="color: navy">(</span>qr<span style="color: navy">, </span>now()<span style="color: navy">)</span> <i>&quot;dateFromExtractionTime&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">}</span> <i>&quot;dateFallback&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">// </span><span style="color: green">Composition.author is 1..1 minimum. R5 QuestionnaireResponse carries both</span>
  <span style="color: navy">// </span><span style="color: green">`author` (who recorded the answers) and `source` (who supplied them); the</span>
  <span style="color: navy">// </span><span style="color: green">author is the one who wrote the note, so it wins, and `source` only stands</span>
  <span style="color: navy">// </span><span style="color: green">in when the client did not send an author. If the response carries neither,</span>
  <span style="color: navy">// </span><span style="color: green">the note comes out unauthored -- there is nothing on a QuestionnaireResponse</span>
  <span style="color: navy">// </span><span style="color: green">to invent one from, and guessing at who wrote a clinical note is not a thing</span>
  <span style="color: navy">// </span><span style="color: green">a map should do.</span>
  qr.author<b> as </b><span style="color: maroon">a</span><span style="color: navy"><b> -&gt; </b></span>comp.author = <span style="color: maroon">a</span> <i>&quot;authorFromAuthor&quot;</i><span style="color: navy">;</span>
  qr<b> where </b><span style="color: navy">(</span>author.exists().not()<span style="color: navy">)</span><b> then</b><span style="color: navy"> {
</span>    qr.source<b> as </b><span style="color: maroon">src</span><span style="color: navy"><b> -&gt; </b></span>comp.author = <span style="color: maroon">src</span> <i>&quot;authorFromSource&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">}</span> <i>&quot;authorFallback&quot;</i><span style="color: navy">;</span>
  qr<span style="color: navy"><b> -&gt; </b></span>comp.relatesTo<b> as </b><span style="color: maroon">rel</span><b> then</b><span style="color: navy"> {
</span>    qr<span style="color: navy"><b> -&gt; </b></span>rel.type = <span style="color: blue">'derived-from'</span> <i>&quot;relatesToType&quot;</i><span style="color: navy">;</span>
    qr<span style="color: navy"><b> -&gt; </b></span>rel.resourceReference = <b>create</b><span style="color: navy">(</span><span style="color: blue">'Reference'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">ref</span><b> then</b><span style="color: navy"> {
</span>      qr.id<b> as </b><span style="color: maroon">qid</span><span style="color: navy"><b> -&gt; </b></span>ref.reference = <span style="color: maroon">qid</span> <i>&quot;relatesToRef&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;relatesToTarget&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">}</span> <i>&quot;linkQuestionnaireResponse&quot;</i><span style="color: navy">;</span>
<span style="color: navy">}

</span><b>group </b>AddSectionText<span style="color: navy">(</span><b>source</b> <span style="color: maroon">it</span>, <b>target</b> <span style="color: maroon">sec</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>sec.text<b> as </b><span style="color: maroon">narrative</span><b> then</b><span style="color: navy"> {
</span>      v<span style="color: navy"><b> -&gt; </b></span>narrative.status = <span style="color: blue">'generated'</span> <i>&quot;narrativeStatus&quot;</i><span style="color: navy">;</span>
      v<span style="color: navy"><b> -&gt; </b></span>narrative.div = <b>create</b><span style="color: navy">(</span><span style="color: blue">'xhtml'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">xhtml</span><b> then</b><span style="color: navy"> {
</span>        v<span style="color: navy"><b> -&gt; </b></span>xhtml.value = evaluate<span style="color: navy">(</span>a<span style="color: navy">, </span>'&lt;div xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;&lt;p&gt;' + value.toString().escape('html') + '&lt;/p&gt;&lt;/div&gt;'<span style="color: navy">)</span> <i>&quot;narrativeDiv&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;narrativeXhtml&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;sectionText&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">}</span> <i>&quot;sectionAnswer&quot;</i><span style="color: navy">;</span>
<span style="color: navy">}

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

</span></pre></div>
  </text>
  <url
       value="https://fhir.slade360.co.ke/fhir/StructureMap/ExtractInpatientAdultGeneralAdmissionAssessment"/>
  <version value="0.1.0"/>
  <name value="ExtractInpatientAdultGeneralAdmissionAssessment"/>
  <title value="Inpatient Adult General Admission Assessment Extraction"/>
  <status value="active"/>
  <date value="2026-09-14T06:31:13+00:00"/>
  <publisher value="Kathurima Kimathi"/>
  <contact>
    <name value="Kathurima Kimathi"/>
    <telecom>
      <system value="url"/>
      <value value="https://www.linkedin.com/in/kathurima-kimathi/"/>
    </telecom>
    <telecom>
      <system value="email"/>
      <value value="kathurimakimathi415@gmail.com"/>
    </telecom>
  </contact>
  <contact>
    <name value="Oscar John"/>
    <telecom>
      <system value="email"/>
      <value value="oscarjohnotieno@gmail.com"/>
      <use value="work"/>
    </telecom>
  </contact>
  <contact>
    <name value="Kennedy Omondi"/>
    <telecom>
      <system value="email"/>
      <value value="kennankole@gmail.com"/>
      <use value="work"/>
    </telecom>
  </contact>
  <description
               value="Turns a response to the adult general admission assessment into a chief-complaint Observation, one Observation per vital, and a Composition that files the assessment and carries the allergies and medication the assessor reviewed. Nothing is copied: the allergies and medication are already AllergyIntolerance and MedicationRequest resources -- the form loads them off the server -- so they become section entries. The Composition exists for exactly that reason; without a container those two rows of the assessment extract to nothing at all."/>
  <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/Composition"/>
    <mode value="target"/>
    <alias value="Composition"/>
  </structure>
  <group>
    <name value="ExtractInpatientAdultGeneralAdmissionAssessment"/>
    <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="complaintRule"/>
      <source>
        <context value="qr"/>
        <element value="item"/>
        <variable value="itC"/>
        <condition value="(linkId = 'complaint') and answer.value.exists()"/>
      </source>
      <rule>
        <name value="complaintAnswer"/>
        <source>
          <context value="itC"/>
          <element value="answer"/>
          <listMode value="first"/>
          <variable value="aC"/>
        </source>
        <rule>
          <name value="complaintObservation"/>
          <source>
            <context value="aC"/>
          </source>
          <target>
            <context value="bundle"/>
            <element value="entry"/>
            <variable value="entryC"/>
          </target>
          <target>
            <context value="entryC"/>
            <element value="resource"/>
            <variable value="obsC"/>
            <transform value="create"/>
            <parameter>
              <valueString value="Observation"/>
            </parameter>
          </target>
          <rule>
            <name value="complaintBase"/>
            <source>
              <context value="qr"/>
            </source>
            <target>
              <context value="obsC"/>
            </target>
            <target>
              <context value="entryC"/>
            </target>
            <dependent>
              <name value="BuildObsBase"/>
              <parameter>
                <valueId value="qr"/>
              </parameter>
              <parameter>
                <valueId value="obsC"/>
              </parameter>
              <parameter>
                <valueId value="entryC"/>
              </parameter>
            </dependent>
          </rule>
          <rule>
            <name value="complaintCategory"/>
            <source>
              <context value="qr"/>
            </source>
            <target>
              <context value="obsC"/>
            </target>
            <dependent>
              <name value="SetSocialHistoryCategory"/>
              <parameter>
                <valueId value="qr"/>
              </parameter>
              <parameter>
                <valueId value="obsC"/>
              </parameter>
            </dependent>
          </rule>
          <rule>
            <name value="complaintCode"/>
            <source>
              <context value="qr"/>
            </source>
            <target>
              <context value="obsC"/>
              <element value="code"/>
              <variable value="code"/>
            </target>
            <rule>
              <name value="codeCoding"/>
              <source>
                <context value="qr"/>
              </source>
              <target>
                <context value="code"/>
                <element value="coding"/>
                <variable value="coding"/>
              </target>
              <rule>
                <name value="codeSystem"/>
                <source>
                  <context value="qr"/>
                </source>
                <target>
                  <context value="coding"/>
                  <element value="system"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="http://loinc.org"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="codeCode"/>
                <source>
                  <context value="qr"/>
                </source>
                <target>
                  <context value="coding"/>
                  <element value="code"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="10154-3"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="codeDisplay"/>
                <source>
                  <context value="qr"/>
                </source>
                <target>
                  <context value="coding"/>
                  <element value="display"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString
                                 value="Chief complaint Narrative - Reported"/>
                  </parameter>
                </target>
              </rule>
            </rule>
          </rule>
          <rule>
            <name value="complaintValue"/>
            <source>
              <context value="aC"/>
              <element value="value"/>
              <variable value="v"/>
            </source>
            <target>
              <context value="obsC"/>
              <element value="value"/>
              <transform value="copy"/>
              <parameter>
                <valueId value="v"/>
              </parameter>
            </target>
          </rule>
        </rule>
      </rule>
      <documentation
                     value="── Presenting complaint ───────────────────────────────────────────────────
Category `social-history` and code 10154-3 match what extract-vital-signs
already produces for a chief complaint, so a consumer querying
category=social-history&amp;code=10154-3 gets both without knowing which form
the complaint came from."/>
    </rule>
    <rule>
      <name value="vitalsGroupRule"/>
      <source>
        <context value="qr"/>
        <element value="item"/>
        <variable value="gV"/>
        <condition value="linkId = 'vitals'"/>
      </source>
      <rule>
        <name value="bpSysRule"/>
        <source>
          <context value="gV"/>
          <element value="item"/>
          <variable value="itS"/>
          <condition
                     value="(linkId = 'vitals.bpSys') and answer.value.exists()"/>
        </source>
        <rule>
          <name value="bpSysAnswer"/>
          <source>
            <context value="itS"/>
            <element value="answer"/>
            <listMode value="first"/>
            <variable value="aS"/>
          </source>
          <rule>
            <name value="bpSysObservation"/>
            <source>
              <context value="aS"/>
            </source>
            <target>
              <context value="bundle"/>
              <element value="entry"/>
              <variable value="entryS"/>
            </target>
            <target>
              <context value="entryS"/>
              <element value="resource"/>
              <variable value="obsS"/>
              <transform value="create"/>
              <parameter>
                <valueString value="Observation"/>
              </parameter>
            </target>
            <rule>
              <name value="bpSysBase"/>
              <source>
                <context value="qr"/>
              </source>
              <target>
                <context value="obsS"/>
              </target>
              <target>
                <context value="entryS"/>
              </target>
              <dependent>
                <name value="BuildObsBase"/>
                <parameter>
                  <valueId value="qr"/>
                </parameter>
                <parameter>
                  <valueId value="obsS"/>
                </parameter>
                <parameter>
                  <valueId value="entryS"/>
                </parameter>
              </dependent>
            </rule>
            <rule>
              <name value="bpSysCategory"/>
              <source>
                <context value="qr"/>
              </source>
              <target>
                <context value="obsS"/>
              </target>
              <dependent>
                <name value="SetVitalSignsCategory"/>
                <parameter>
                  <valueId value="qr"/>
                </parameter>
                <parameter>
                  <valueId value="obsS"/>
                </parameter>
              </dependent>
            </rule>
            <rule>
              <name value="bpSysCode"/>
              <source>
                <context value="qr"/>
              </source>
              <target>
                <context value="obsS"/>
                <element value="code"/>
                <variable value="code"/>
              </target>
              <rule>
                <name value="codeCoding"/>
                <source>
                  <context value="qr"/>
                </source>
                <target>
                  <context value="code"/>
                  <element value="coding"/>
                  <variable value="coding"/>
                </target>
                <rule>
                  <name value="codeSystem"/>
                  <source>
                    <context value="qr"/>
                  </source>
                  <target>
                    <context value="coding"/>
                    <element value="system"/>
                    <transform value="copy"/>
                    <parameter>
                      <valueString value="http://loinc.org"/>
                    </parameter>
                  </target>
                </rule>
                <rule>
                  <name value="codeCode"/>
                  <source>
                    <context value="qr"/>
                  </source>
                  <target>
                    <context value="coding"/>
                    <element value="code"/>
                    <transform value="copy"/>
                    <parameter>
                      <valueString value="8480-6"/>
                    </parameter>
                  </target>
                </rule>
                <rule>
                  <name value="codeDisplay"/>
                  <source>
                    <context value="qr"/>
                  </source>
                  <target>
                    <context value="coding"/>
                    <element value="display"/>
                    <transform value="copy"/>
                    <parameter>
                      <valueString value="Systolic blood pressure"/>
                    </parameter>
                  </target>
                </rule>
              </rule>
            </rule>
            <rule>
              <name value="bpSysValue"/>
              <source>
                <context value="aS"/>
                <element value="value"/>
                <variable value="v"/>
              </source>
              <target>
                <context value="obsS"/>
                <element value="value"/>
                <transform value="copy"/>
                <parameter>
                  <valueId value="v"/>
                </parameter>
              </target>
            </rule>
          </rule>
        </rule>
      </rule>
      <rule>
        <name value="bpDiaRule"/>
        <source>
          <context value="gV"/>
          <element value="item"/>
          <variable value="itD"/>
          <condition
                     value="(linkId = 'vitals.bpDia') and answer.value.exists()"/>
        </source>
        <rule>
          <name value="bpDiaAnswer"/>
          <source>
            <context value="itD"/>
            <element value="answer"/>
            <listMode value="first"/>
            <variable value="aD"/>
          </source>
          <rule>
            <name value="bpDiaObservation"/>
            <source>
              <context value="aD"/>
            </source>
            <target>
              <context value="bundle"/>
              <element value="entry"/>
              <variable value="entryD"/>
            </target>
            <target>
              <context value="entryD"/>
              <element value="resource"/>
              <variable value="obsD"/>
              <transform value="create"/>
              <parameter>
                <valueString value="Observation"/>
              </parameter>
            </target>
            <rule>
              <name value="bpDiaBase"/>
              <source>
                <context value="qr"/>
              </source>
              <target>
                <context value="obsD"/>
              </target>
              <target>
                <context value="entryD"/>
              </target>
              <dependent>
                <name value="BuildObsBase"/>
                <parameter>
                  <valueId value="qr"/>
                </parameter>
                <parameter>
                  <valueId value="obsD"/>
                </parameter>
                <parameter>
                  <valueId value="entryD"/>
                </parameter>
              </dependent>
            </rule>
            <rule>
              <name value="bpDiaCategory"/>
              <source>
                <context value="qr"/>
              </source>
              <target>
                <context value="obsD"/>
              </target>
              <dependent>
                <name value="SetVitalSignsCategory"/>
                <parameter>
                  <valueId value="qr"/>
                </parameter>
                <parameter>
                  <valueId value="obsD"/>
                </parameter>
              </dependent>
            </rule>
            <rule>
              <name value="bpDiaCode"/>
              <source>
                <context value="qr"/>
              </source>
              <target>
                <context value="obsD"/>
                <element value="code"/>
                <variable value="code"/>
              </target>
              <rule>
                <name value="codeCoding"/>
                <source>
                  <context value="qr"/>
                </source>
                <target>
                  <context value="code"/>
                  <element value="coding"/>
                  <variable value="coding"/>
                </target>
                <rule>
                  <name value="codeSystem"/>
                  <source>
                    <context value="qr"/>
                  </source>
                  <target>
                    <context value="coding"/>
                    <element value="system"/>
                    <transform value="copy"/>
                    <parameter>
                      <valueString value="http://loinc.org"/>
                    </parameter>
                  </target>
                </rule>
                <rule>
                  <name value="codeCode"/>
                  <source>
                    <context value="qr"/>
                  </source>
                  <target>
                    <context value="coding"/>
                    <element value="code"/>
                    <transform value="copy"/>
                    <parameter>
                      <valueString value="8462-4"/>
                    </parameter>
                  </target>
                </rule>
                <rule>
                  <name value="codeDisplay"/>
                  <source>
                    <context value="qr"/>
                  </source>
                  <target>
                    <context value="coding"/>
                    <element value="display"/>
                    <transform value="copy"/>
                    <parameter>
                      <valueString value="Diastolic blood pressure"/>
                    </parameter>
                  </target>
                </rule>
              </rule>
            </rule>
            <rule>
              <name value="bpDiaValue"/>
              <source>
                <context value="aD"/>
                <element value="value"/>
                <variable value="v"/>
              </source>
              <target>
                <context value="obsD"/>
                <element value="value"/>
                <transform value="copy"/>
                <parameter>
                  <valueId value="v"/>
                </parameter>
              </target>
            </rule>
          </rule>
        </rule>
      </rule>
      <rule>
        <name value="pulseRule"/>
        <source>
          <context value="gV"/>
          <element value="item"/>
          <variable value="itP"/>
          <condition
                     value="(linkId = 'vitals.pulse') and answer.value.exists()"/>
        </source>
        <rule>
          <name value="pulseAnswer"/>
          <source>
            <context value="itP"/>
            <element value="answer"/>
            <listMode value="first"/>
            <variable value="aP"/>
          </source>
          <rule>
            <name value="pulseObservation"/>
            <source>
              <context value="aP"/>
            </source>
            <target>
              <context value="bundle"/>
              <element value="entry"/>
              <variable value="entryP"/>
            </target>
            <target>
              <context value="entryP"/>
              <element value="resource"/>
              <variable value="obsP"/>
              <transform value="create"/>
              <parameter>
                <valueString value="Observation"/>
              </parameter>
            </target>
            <rule>
              <name value="pulseBase"/>
              <source>
                <context value="qr"/>
              </source>
              <target>
                <context value="obsP"/>
              </target>
              <target>
                <context value="entryP"/>
              </target>
              <dependent>
                <name value="BuildObsBase"/>
                <parameter>
                  <valueId value="qr"/>
                </parameter>
                <parameter>
                  <valueId value="obsP"/>
                </parameter>
                <parameter>
                  <valueId value="entryP"/>
                </parameter>
              </dependent>
            </rule>
            <rule>
              <name value="pulseCategory"/>
              <source>
                <context value="qr"/>
              </source>
              <target>
                <context value="obsP"/>
              </target>
              <dependent>
                <name value="SetVitalSignsCategory"/>
                <parameter>
                  <valueId value="qr"/>
                </parameter>
                <parameter>
                  <valueId value="obsP"/>
                </parameter>
              </dependent>
            </rule>
            <rule>
              <name value="pulseCode"/>
              <source>
                <context value="qr"/>
              </source>
              <target>
                <context value="obsP"/>
                <element value="code"/>
                <variable value="code"/>
              </target>
              <rule>
                <name value="codeCoding"/>
                <source>
                  <context value="qr"/>
                </source>
                <target>
                  <context value="code"/>
                  <element value="coding"/>
                  <variable value="coding"/>
                </target>
                <rule>
                  <name value="codeSystem"/>
                  <source>
                    <context value="qr"/>
                  </source>
                  <target>
                    <context value="coding"/>
                    <element value="system"/>
                    <transform value="copy"/>
                    <parameter>
                      <valueString value="http://loinc.org"/>
                    </parameter>
                  </target>
                </rule>
                <rule>
                  <name value="codeCode"/>
                  <source>
                    <context value="qr"/>
                  </source>
                  <target>
                    <context value="coding"/>
                    <element value="code"/>
                    <transform value="copy"/>
                    <parameter>
                      <valueString value="8867-4"/>
                    </parameter>
                  </target>
                </rule>
                <rule>
                  <name value="codeDisplay"/>
                  <source>
                    <context value="qr"/>
                  </source>
                  <target>
                    <context value="coding"/>
                    <element value="display"/>
                    <transform value="copy"/>
                    <parameter>
                      <valueString value="Heart rate"/>
                    </parameter>
                  </target>
                </rule>
              </rule>
            </rule>
            <rule>
              <name value="pulseValue"/>
              <source>
                <context value="aP"/>
                <element value="value"/>
                <variable value="v"/>
              </source>
              <target>
                <context value="obsP"/>
                <element value="value"/>
                <transform value="copy"/>
                <parameter>
                  <valueId value="v"/>
                </parameter>
              </target>
            </rule>
          </rule>
        </rule>
      </rule>
      <rule>
        <name value="tempRule"/>
        <source>
          <context value="gV"/>
          <element value="item"/>
          <variable value="itT"/>
          <condition
                     value="(linkId = 'vitals.temp') and answer.value.exists()"/>
        </source>
        <rule>
          <name value="tempAnswer"/>
          <source>
            <context value="itT"/>
            <element value="answer"/>
            <listMode value="first"/>
            <variable value="aT"/>
          </source>
          <rule>
            <name value="tempObservation"/>
            <source>
              <context value="aT"/>
            </source>
            <target>
              <context value="bundle"/>
              <element value="entry"/>
              <variable value="entryT"/>
            </target>
            <target>
              <context value="entryT"/>
              <element value="resource"/>
              <variable value="obsT"/>
              <transform value="create"/>
              <parameter>
                <valueString value="Observation"/>
              </parameter>
            </target>
            <rule>
              <name value="tempBase"/>
              <source>
                <context value="qr"/>
              </source>
              <target>
                <context value="obsT"/>
              </target>
              <target>
                <context value="entryT"/>
              </target>
              <dependent>
                <name value="BuildObsBase"/>
                <parameter>
                  <valueId value="qr"/>
                </parameter>
                <parameter>
                  <valueId value="obsT"/>
                </parameter>
                <parameter>
                  <valueId value="entryT"/>
                </parameter>
              </dependent>
            </rule>
            <rule>
              <name value="tempCategory"/>
              <source>
                <context value="qr"/>
              </source>
              <target>
                <context value="obsT"/>
              </target>
              <dependent>
                <name value="SetVitalSignsCategory"/>
                <parameter>
                  <valueId value="qr"/>
                </parameter>
                <parameter>
                  <valueId value="obsT"/>
                </parameter>
              </dependent>
            </rule>
            <rule>
              <name value="tempCode"/>
              <source>
                <context value="qr"/>
              </source>
              <target>
                <context value="obsT"/>
                <element value="code"/>
                <variable value="code"/>
              </target>
              <rule>
                <name value="codeCoding"/>
                <source>
                  <context value="qr"/>
                </source>
                <target>
                  <context value="code"/>
                  <element value="coding"/>
                  <variable value="coding"/>
                </target>
                <rule>
                  <name value="codeSystem"/>
                  <source>
                    <context value="qr"/>
                  </source>
                  <target>
                    <context value="coding"/>
                    <element value="system"/>
                    <transform value="copy"/>
                    <parameter>
                      <valueString value="http://loinc.org"/>
                    </parameter>
                  </target>
                </rule>
                <rule>
                  <name value="codeCode"/>
                  <source>
                    <context value="qr"/>
                  </source>
                  <target>
                    <context value="coding"/>
                    <element value="code"/>
                    <transform value="copy"/>
                    <parameter>
                      <valueString value="8310-5"/>
                    </parameter>
                  </target>
                </rule>
                <rule>
                  <name value="codeDisplay"/>
                  <source>
                    <context value="qr"/>
                  </source>
                  <target>
                    <context value="coding"/>
                    <element value="display"/>
                    <transform value="copy"/>
                    <parameter>
                      <valueString value="Body temperature"/>
                    </parameter>
                  </target>
                </rule>
              </rule>
            </rule>
            <rule>
              <name value="tempValue"/>
              <source>
                <context value="aT"/>
                <element value="value"/>
                <variable value="v"/>
              </source>
              <target>
                <context value="obsT"/>
                <element value="value"/>
                <transform value="copy"/>
                <parameter>
                  <valueId value="v"/>
                </parameter>
              </target>
            </rule>
          </rule>
        </rule>
      </rule>
      <rule>
        <name value="respRule"/>
        <source>
          <context value="gV"/>
          <element value="item"/>
          <variable value="itR"/>
          <condition
                     value="(linkId = 'vitals.resp') and answer.value.exists()"/>
        </source>
        <rule>
          <name value="respAnswer"/>
          <source>
            <context value="itR"/>
            <element value="answer"/>
            <listMode value="first"/>
            <variable value="aR"/>
          </source>
          <rule>
            <name value="respObservation"/>
            <source>
              <context value="aR"/>
            </source>
            <target>
              <context value="bundle"/>
              <element value="entry"/>
              <variable value="entryR"/>
            </target>
            <target>
              <context value="entryR"/>
              <element value="resource"/>
              <variable value="obsR"/>
              <transform value="create"/>
              <parameter>
                <valueString value="Observation"/>
              </parameter>
            </target>
            <rule>
              <name value="respBase"/>
              <source>
                <context value="qr"/>
              </source>
              <target>
                <context value="obsR"/>
              </target>
              <target>
                <context value="entryR"/>
              </target>
              <dependent>
                <name value="BuildObsBase"/>
                <parameter>
                  <valueId value="qr"/>
                </parameter>
                <parameter>
                  <valueId value="obsR"/>
                </parameter>
                <parameter>
                  <valueId value="entryR"/>
                </parameter>
              </dependent>
            </rule>
            <rule>
              <name value="respCategory"/>
              <source>
                <context value="qr"/>
              </source>
              <target>
                <context value="obsR"/>
              </target>
              <dependent>
                <name value="SetVitalSignsCategory"/>
                <parameter>
                  <valueId value="qr"/>
                </parameter>
                <parameter>
                  <valueId value="obsR"/>
                </parameter>
              </dependent>
            </rule>
            <rule>
              <name value="respCode"/>
              <source>
                <context value="qr"/>
              </source>
              <target>
                <context value="obsR"/>
                <element value="code"/>
                <variable value="code"/>
              </target>
              <rule>
                <name value="codeCoding"/>
                <source>
                  <context value="qr"/>
                </source>
                <target>
                  <context value="code"/>
                  <element value="coding"/>
                  <variable value="coding"/>
                </target>
                <rule>
                  <name value="codeSystem"/>
                  <source>
                    <context value="qr"/>
                  </source>
                  <target>
                    <context value="coding"/>
                    <element value="system"/>
                    <transform value="copy"/>
                    <parameter>
                      <valueString value="http://loinc.org"/>
                    </parameter>
                  </target>
                </rule>
                <rule>
                  <name value="codeCode"/>
                  <source>
                    <context value="qr"/>
                  </source>
                  <target>
                    <context value="coding"/>
                    <element value="code"/>
                    <transform value="copy"/>
                    <parameter>
                      <valueString value="9279-1"/>
                    </parameter>
                  </target>
                </rule>
                <rule>
                  <name value="codeDisplay"/>
                  <source>
                    <context value="qr"/>
                  </source>
                  <target>
                    <context value="coding"/>
                    <element value="display"/>
                    <transform value="copy"/>
                    <parameter>
                      <valueString value="Respiratory rate"/>
                    </parameter>
                  </target>
                </rule>
              </rule>
            </rule>
            <rule>
              <name value="respValue"/>
              <source>
                <context value="aR"/>
                <element value="value"/>
                <variable value="v"/>
              </source>
              <target>
                <context value="obsR"/>
                <element value="value"/>
                <transform value="copy"/>
                <parameter>
                  <valueId value="v"/>
                </parameter>
              </target>
            </rule>
          </rule>
        </rule>
      </rule>
      <rule>
        <name value="spo2Rule"/>
        <source>
          <context value="gV"/>
          <element value="item"/>
          <variable value="itO"/>
          <condition
                     value="(linkId = 'vitals.spo2') and answer.value.exists()"/>
        </source>
        <rule>
          <name value="spo2Answer"/>
          <source>
            <context value="itO"/>
            <element value="answer"/>
            <listMode value="first"/>
            <variable value="aO"/>
          </source>
          <rule>
            <name value="spo2Observation"/>
            <source>
              <context value="aO"/>
            </source>
            <target>
              <context value="bundle"/>
              <element value="entry"/>
              <variable value="entryO"/>
            </target>
            <target>
              <context value="entryO"/>
              <element value="resource"/>
              <variable value="obsO"/>
              <transform value="create"/>
              <parameter>
                <valueString value="Observation"/>
              </parameter>
            </target>
            <rule>
              <name value="spo2Base"/>
              <source>
                <context value="qr"/>
              </source>
              <target>
                <context value="obsO"/>
              </target>
              <target>
                <context value="entryO"/>
              </target>
              <dependent>
                <name value="BuildObsBase"/>
                <parameter>
                  <valueId value="qr"/>
                </parameter>
                <parameter>
                  <valueId value="obsO"/>
                </parameter>
                <parameter>
                  <valueId value="entryO"/>
                </parameter>
              </dependent>
            </rule>
            <rule>
              <name value="spo2Category"/>
              <source>
                <context value="qr"/>
              </source>
              <target>
                <context value="obsO"/>
              </target>
              <dependent>
                <name value="SetVitalSignsCategory"/>
                <parameter>
                  <valueId value="qr"/>
                </parameter>
                <parameter>
                  <valueId value="obsO"/>
                </parameter>
              </dependent>
            </rule>
            <rule>
              <name value="spo2Code"/>
              <source>
                <context value="qr"/>
              </source>
              <target>
                <context value="obsO"/>
                <element value="code"/>
                <variable value="code"/>
              </target>
              <rule>
                <name value="codeCoding"/>
                <source>
                  <context value="qr"/>
                </source>
                <target>
                  <context value="code"/>
                  <element value="coding"/>
                  <variable value="coding"/>
                </target>
                <rule>
                  <name value="codeSystem"/>
                  <source>
                    <context value="qr"/>
                  </source>
                  <target>
                    <context value="coding"/>
                    <element value="system"/>
                    <transform value="copy"/>
                    <parameter>
                      <valueString value="http://loinc.org"/>
                    </parameter>
                  </target>
                </rule>
                <rule>
                  <name value="codeCode"/>
                  <source>
                    <context value="qr"/>
                  </source>
                  <target>
                    <context value="coding"/>
                    <element value="code"/>
                    <transform value="copy"/>
                    <parameter>
                      <valueString value="59408-5"/>
                    </parameter>
                  </target>
                </rule>
                <rule>
                  <name value="codeDisplay"/>
                  <source>
                    <context value="qr"/>
                  </source>
                  <target>
                    <context value="coding"/>
                    <element value="display"/>
                    <transform value="copy"/>
                    <parameter>
                      <valueString
                                   value="Oxygen saturation in Arterial blood by Pulse oximetry"/>
                    </parameter>
                  </target>
                </rule>
              </rule>
            </rule>
            <rule>
              <name value="spo2Value"/>
              <source>
                <context value="aO"/>
                <element value="value"/>
                <variable value="v"/>
              </source>
              <target>
                <context value="obsO"/>
                <element value="value"/>
                <transform value="copy"/>
                <parameter>
                  <valueId value="v"/>
                </parameter>
              </target>
            </rule>
          </rule>
        </rule>
      </rule>
      <documentation
                     value="── Vitals on admission ────────────────────────────────────────────────────
Six items, six Observations, exactly as the form extracted before it had a
map. Each answer is already a Quantity -- the item is type `quantity` with
a questionnaire-unitOption pinning the unit -- so it is copied through
whole. Rebuilding it here would mean restating a unit the client actually
sent, which turns a wrong unit into a wrong reading."/>
    </rule>
    <rule>
      <name value="composition"/>
      <source>
        <context value="qr"/>
      </source>
      <target>
        <context value="bundle"/>
        <element value="entry"/>
        <variable value="entry"/>
      </target>
      <target>
        <context value="entry"/>
        <element value="resource"/>
        <variable value="comp"/>
        <transform value="create"/>
        <parameter>
          <valueString value="Composition"/>
        </parameter>
      </target>
      <rule>
        <name value="noteBase"/>
        <source>
          <context value="qr"/>
        </source>
        <target>
          <context value="comp"/>
        </target>
        <target>
          <context value="entry"/>
        </target>
        <dependent>
          <name value="BuildNoteBase"/>
          <parameter>
            <valueId value="qr"/>
          </parameter>
          <parameter>
            <valueId value="comp"/>
          </parameter>
          <parameter>
            <valueId value="entry"/>
          </parameter>
        </dependent>
      </rule>
      <rule>
        <name value="noteName"/>
        <source>
          <context value="qr"/>
        </source>
        <target>
          <context value="comp"/>
          <element value="name"/>
          <transform value="copy"/>
          <parameter>
            <valueString value="InpatientAdultGeneralAdmissionAssessment"/>
          </parameter>
        </target>
      </rule>
      <rule>
        <name value="noteTitle"/>
        <source>
          <context value="qr"/>
        </source>
        <target>
          <context value="comp"/>
          <element value="title"/>
          <transform value="copy"/>
          <parameter>
            <valueString value="Adult general admission assessment"/>
          </parameter>
        </target>
      </rule>
      <rule>
        <name value="noteType"/>
        <source>
          <context value="qr"/>
        </source>
        <target>
          <context value="comp"/>
          <element value="type"/>
          <variable value="ty"/>
        </target>
        <rule>
          <name value="sghiCoding"/>
          <source>
            <context value="qr"/>
          </source>
          <target>
            <context value="ty"/>
            <element value="coding"/>
            <variable value="sghi"/>
          </target>
          <rule>
            <name value="sghiSystem"/>
            <source>
              <context value="qr"/>
            </source>
            <target>
              <context value="sghi"/>
              <element value="system"/>
              <transform value="copy"/>
              <parameter>
                <valueString
                             value="https://fhir.slade360.co.ke/fhir/CodeSystem/inpatient-document-type-codesystem"/>
              </parameter>
            </target>
          </rule>
          <rule>
            <name value="sghiCode"/>
            <source>
              <context value="qr"/>
            </source>
            <target>
              <context value="sghi"/>
              <element value="code"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="adult-general-admission-assessment"/>
              </parameter>
            </target>
          </rule>
          <rule>
            <name value="sghiDisplay"/>
            <source>
              <context value="qr"/>
            </source>
            <target>
              <context value="sghi"/>
              <element value="display"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="Adult general admission assessment"/>
              </parameter>
            </target>
          </rule>
        </rule>
        <rule>
          <name value="typeText"/>
          <source>
            <context value="qr"/>
          </source>
          <target>
            <context value="ty"/>
            <element value="text"/>
            <transform value="copy"/>
            <parameter>
              <valueString value="Adult general admission assessment"/>
            </parameter>
          </target>
        </rule>
      </rule>
      <rule>
        <name value="complaintSectionRule"/>
        <source>
          <context value="qr"/>
          <element value="item"/>
          <variable value="it"/>
          <condition
                     value="(linkId = 'complaint') and answer.value.exists()"/>
        </source>
        <target>
          <context value="comp"/>
          <element value="section"/>
          <variable value="sec"/>
        </target>
        <rule>
          <name value="complaintTitle"/>
          <source>
            <context value="it"/>
          </source>
          <target>
            <context value="sec"/>
            <element value="title"/>
            <transform value="copy"/>
            <parameter>
              <valueString value="Presenting complaint"/>
            </parameter>
          </target>
        </rule>
        <rule>
          <name value="complaintSectionText"/>
          <source>
            <context value="it"/>
          </source>
          <target>
            <context value="sec"/>
          </target>
          <dependent>
            <name value="AddSectionText"/>
            <parameter>
              <valueId value="it"/>
            </parameter>
            <parameter>
              <valueId value="sec"/>
            </parameter>
          </dependent>
        </rule>
      </rule>
      <rule>
        <name value="allergiesRule"/>
        <source>
          <context value="qr"/>
          <element value="item"/>
          <variable value="itA"/>
          <condition
                     value="(linkId = 'allergies') and answer.value.exists()"/>
        </source>
        <target>
          <context value="comp"/>
          <element value="section"/>
          <variable value="secA"/>
        </target>
        <rule>
          <name value="allergiesTitle"/>
          <source>
            <context value="itA"/>
          </source>
          <target>
            <context value="secA"/>
            <element value="title"/>
            <transform value="copy"/>
            <parameter>
              <valueString value="Known allergies"/>
            </parameter>
          </target>
        </rule>
        <rule>
          <name value="allergiesAnswers"/>
          <source>
            <context value="itA"/>
            <element value="answer"/>
            <variable value="aA"/>
          </source>
          <rule>
            <name value="allergiesEntry"/>
            <source>
              <context value="aA"/>
              <element value="value"/>
              <variable value="av"/>
            </source>
            <target>
              <context value="secA"/>
              <element value="entry"/>
              <transform value="copy"/>
              <parameter>
                <valueId value="av"/>
              </parameter>
            </target>
          </rule>
        </rule>
      </rule>
      <rule>
        <name value="medsRule"/>
        <source>
          <context value="qr"/>
          <element value="item"/>
          <variable value="itM"/>
          <condition value="(linkId = 'meds') and answer.value.exists()"/>
        </source>
        <target>
          <context value="comp"/>
          <element value="section"/>
          <variable value="secM"/>
        </target>
        <rule>
          <name value="medsTitle"/>
          <source>
            <context value="itM"/>
          </source>
          <target>
            <context value="secM"/>
            <element value="title"/>
            <transform value="copy"/>
            <parameter>
              <valueString value="Current medication"/>
            </parameter>
          </target>
        </rule>
        <rule>
          <name value="medsAnswers"/>
          <source>
            <context value="itM"/>
            <element value="answer"/>
            <variable value="aM"/>
          </source>
          <rule>
            <name value="medsEntry"/>
            <source>
              <context value="aM"/>
              <element value="value"/>
              <variable value="mv"/>
            </source>
            <target>
              <context value="secM"/>
              <element value="entry"/>
              <transform value="copy"/>
              <parameter>
                <valueId value="mv"/>
              </parameter>
            </target>
          </rule>
        </rule>
      </rule>
      <documentation
                     value="── The assessment as a filed document ─────────────────────────────────────"/>
    </rule>
  </group>
  <group>
    <name value="BuildObsBase"/>
    <documentation
                   value="─────────────────────────────────────────────────────────────────────────────
Shared scaffolding. Repeated in each map rather than imported: the transform
engine resolves `imports` against whatever StructureMaps happen to be on the
server, and a form that stops extracting because a shared map was not
uploaded is a worse failure than a duplicated group.
─────────────────────────────────────────────────────────────────────────────
Two notes on what the publisher's StructureMap validator says about this file.
Source parameters below are left untyped on purpose. Writing `: Element` makes
the validator compare QuestionnaireResponse.item against the literal 'Element'
and report them as incompatible with each other, which is noise, not a finding.
Untyped, it says only that it cannot check the paths.
`evaluate(context, expression)` is flagged as &quot;takes 1 parameter but 2 were
found&quot;. Leave it. The FML parser in the same jar refuses the one-argument form
outright -- it wants a parameter, a comma, then the FHIRPath -- so the publisher
is objecting to what its own compiler emits. Two arguments is the only form that
compiles, and it is what the R5 transform engine executes."/>
    <input>
      <name value="qr"/>
      <type value="QR"/>
      <mode value="source"/>
    </input>
    <input>
      <name value="obs"/>
      <type value="Observation"/>
      <mode value="target"/>
    </input>
    <input>
      <name value="entry"/>
      <mode value="target"/>
    </input>
    <rule>
      <name value="idAndFullUrl"/>
      <source>
        <context value="qr"/>
      </source>
      <target>
        <context value="obs"/>
        <element value="id"/>
        <transform value="uuid"/>
      </target>
      <dependent>
        <name value="SetObservationFullUrl"/>
        <parameter>
          <valueId value="obs"/>
        </parameter>
        <parameter>
          <valueId value="entry"/>
        </parameter>
      </dependent>
    </rule>
    <rule>
      <name value="entryRequest"/>
      <source>
        <context value="qr"/>
      </source>
      <target>
        <context value="entry"/>
        <element value="request"/>
        <variable value="request"/>
      </target>
      <rule>
        <name value="requestMethod"/>
        <source>
          <context value="qr"/>
        </source>
        <target>
          <context value="request"/>
          <element value="method"/>
          <transform value="copy"/>
          <parameter>
            <valueString value="POST"/>
          </parameter>
        </target>
      </rule>
      <rule>
        <name value="requestUrl"/>
        <source>
          <context value="qr"/>
        </source>
        <target>
          <context value="request"/>
          <element value="url"/>
          <transform value="copy"/>
          <parameter>
            <valueString value="Observation"/>
          </parameter>
        </target>
      </rule>
    </rule>
    <rule>
      <name value="status"/>
      <source>
        <context value="qr"/>
      </source>
      <target>
        <context value="obs"/>
        <element value="status"/>
        <transform value="copy"/>
        <parameter>
          <valueString value="final"/>
        </parameter>
      </target>
    </rule>
    <rule>
      <name value="subject"/>
      <source>
        <context value="qr"/>
        <element value="subject"/>
        <variable value="s"/>
      </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>
      <documentation
                     value="`effective`, not `effectiveDateTime`: the R5 transform engine writes choice
elements by their base name and rejects the typed form. This form asks for
no time of its own, so the moment the response was authored is the best
available."/>
    </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"/>
      </source>
      <target>
        <context value="obs"/>
        <element value="derivedFrom"/>
        <variable value="ref"/>
        <transform value="create"/>
        <parameter>
          <valueString value="Reference"/>
        </parameter>
      </target>
      <rule>
        <name value="derivedFromRef"/>
        <source>
          <context value="qr"/>
          <element value="id"/>
          <variable value="qid"/>
        </source>
        <target>
          <context value="ref"/>
          <element value="reference"/>
          <transform value="copy"/>
          <parameter>
            <valueId value="qid"/>
          </parameter>
        </target>
      </rule>
      <documentation
                     value="`qr.id` already resolves to the type-qualified relative reference under this
engine, so it is used unprefixed."/>
    </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="SetSocialHistoryCategory"/>
    <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="social-history"/>
            </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="Social History"/>
            </parameter>
          </target>
        </rule>
      </rule>
    </rule>
  </group>
  <group>
    <name value="SetObservationFullUrl"/>
    <input>
      <name value="obs"/>
      <type value="Observation"/>
      <mode value="source"/>
    </input>
    <input>
      <name value="entry"/>
      <mode value="target"/>
    </input>
    <rule>
      <name value="assignFullUrl"/>
      <source>
        <context value="obs"/>
        <element value="id"/>
        <variable value="id"/>
      </source>
      <target>
        <context value="entry"/>
        <element value="fullUrl"/>
        <transform value="append"/>
        <parameter>
          <valueString value="https://fhir.slade360.co.ke/fhir/Observation/"/>
        </parameter>
        <parameter>
          <valueId value="id"/>
        </parameter>
      </target>
    </rule>
  </group>
  <group>
    <name value="BuildNoteBase"/>
    <input>
      <name value="qr"/>
      <type value="QR"/>
      <mode value="source"/>
    </input>
    <input>
      <name value="comp"/>
      <type value="Composition"/>
      <mode value="target"/>
    </input>
    <input>
      <name value="entry"/>
      <mode value="target"/>
    </input>
    <rule>
      <name value="idAndFullUrl"/>
      <source>
        <context value="qr"/>
      </source>
      <target>
        <context value="comp"/>
        <element value="id"/>
        <transform value="uuid"/>
      </target>
      <dependent>
        <name value="SetCompositionFullUrl"/>
        <parameter>
          <valueId value="comp"/>
        </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="Composition"/>
          </parameter>
        </target>
      </rule>
    </rule>
    <rule>
      <name value="status"/>
      <source>
        <context value="qr"/>
      </source>
      <target>
        <context value="comp"/>
        <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="comp"/>
        <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="comp"/>
        <element value="encounter"/>
        <transform value="copy"/>
        <parameter>
          <valueId value="e"/>
        </parameter>
      </target>
    </rule>
    <rule>
      <name value="date"/>
      <source>
        <context value="qr"/>
        <element value="authored"/>
        <variable value="t"/>
      </source>
      <target>
        <context value="comp"/>
        <element value="date"/>
        <transform value="copy"/>
        <parameter>
          <valueId value="t"/>
        </parameter>
      </target>
      <documentation
                     value="Composition.date is 1..1. `authored` is only 0..1 on the response, so when a
client sends none the extraction time stands in. It is a poor substitute for
when the note was written, but a document with no date at all is worse, and
extraction happens moments after submission in practice."/>
    </rule>
    <rule>
      <name value="dateFallback"/>
      <source>
        <context value="qr"/>
        <condition value="authored.exists().not()"/>
      </source>
      <rule>
        <name value="dateFromExtractionTime"/>
        <source>
          <context value="qr"/>
        </source>
        <target>
          <context value="comp"/>
          <element value="date"/>
          <transform value="evaluate"/>
          <parameter>
            <valueId value="qr"/>
          </parameter>
          <parameter>
            <valueString value="now()"/>
          </parameter>
        </target>
      </rule>
    </rule>
    <rule>
      <name value="authorFromAuthor"/>
      <source>
        <context value="qr"/>
        <element value="author"/>
        <variable value="a"/>
      </source>
      <target>
        <context value="comp"/>
        <element value="author"/>
        <transform value="copy"/>
        <parameter>
          <valueId value="a"/>
        </parameter>
      </target>
      <documentation
                     value="Composition.author is 1..1 minimum. R5 QuestionnaireResponse carries both
`author` (who recorded the answers) and `source` (who supplied them); the
author is the one who wrote the note, so it wins, and `source` only stands
in when the client did not send an author. If the response carries neither,
the note comes out unauthored -- there is nothing on a QuestionnaireResponse
to invent one from, and guessing at who wrote a clinical note is not a thing
a map should do."/>
    </rule>
    <rule>
      <name value="authorFallback"/>
      <source>
        <context value="qr"/>
        <condition value="author.exists().not()"/>
      </source>
      <rule>
        <name value="authorFromSource"/>
        <source>
          <context value="qr"/>
          <element value="source"/>
          <variable value="src"/>
        </source>
        <target>
          <context value="comp"/>
          <element value="author"/>
          <transform value="copy"/>
          <parameter>
            <valueId value="src"/>
          </parameter>
        </target>
      </rule>
    </rule>
    <rule>
      <name value="linkQuestionnaireResponse"/>
      <source>
        <context value="qr"/>
      </source>
      <target>
        <context value="comp"/>
        <element value="relatesTo"/>
        <variable value="rel"/>
      </target>
      <rule>
        <name value="relatesToType"/>
        <source>
          <context value="qr"/>
        </source>
        <target>
          <context value="rel"/>
          <element value="type"/>
          <transform value="copy"/>
          <parameter>
            <valueString value="derived-from"/>
          </parameter>
        </target>
      </rule>
      <rule>
        <name value="relatesToTarget"/>
        <source>
          <context value="qr"/>
        </source>
        <target>
          <context value="rel"/>
          <element value="resourceReference"/>
          <variable value="ref"/>
          <transform value="create"/>
          <parameter>
            <valueString value="Reference"/>
          </parameter>
        </target>
        <rule>
          <name value="relatesToRef"/>
          <source>
            <context value="qr"/>
            <element value="id"/>
            <variable value="qid"/>
          </source>
          <target>
            <context value="ref"/>
            <element value="reference"/>
            <transform value="copy"/>
            <parameter>
              <valueId value="qid"/>
            </parameter>
          </target>
        </rule>
      </rule>
    </rule>
  </group>
  <group>
    <name value="AddSectionText"/>
    <input>
      <name value="it"/>
      <mode value="source"/>
    </input>
    <input>
      <name value="sec"/>
      <mode value="target"/>
    </input>
    <rule>
      <name value="sectionAnswer"/>
      <source>
        <context value="it"/>
        <element value="answer"/>
        <listMode value="first"/>
        <variable value="a"/>
      </source>
      <rule>
        <name value="sectionText"/>
        <source>
          <context value="a"/>
          <element value="value"/>
          <variable value="v"/>
        </source>
        <target>
          <context value="sec"/>
          <element value="text"/>
          <variable value="narrative"/>
        </target>
        <rule>
          <name value="narrativeStatus"/>
          <source>
            <context value="v"/>
          </source>
          <target>
            <context value="narrative"/>
            <element value="status"/>
            <transform value="copy"/>
            <parameter>
              <valueString value="generated"/>
            </parameter>
          </target>
        </rule>
        <rule>
          <name value="narrativeXhtml"/>
          <source>
            <context value="v"/>
          </source>
          <target>
            <context value="narrative"/>
            <element value="div"/>
            <variable value="xhtml"/>
            <transform value="create"/>
            <parameter>
              <valueString value="xhtml"/>
            </parameter>
          </target>
          <rule>
            <name value="narrativeDiv"/>
            <source>
              <context value="v"/>
            </source>
            <target>
              <context value="xhtml"/>
              <element value="value"/>
              <transform value="evaluate"/>
              <parameter>
                <valueId value="a"/>
              </parameter>
              <parameter>
                <valueString
                             value="'&lt;div xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;&lt;p&gt;' + value.toString().escape('html') + '&lt;/p&gt;&lt;/div&gt;'"/>
              </parameter>
            </target>
          </rule>
        </rule>
      </rule>
    </rule>
  </group>
  <group>
    <name value="SetCompositionFullUrl"/>
    <input>
      <name value="comp"/>
      <type value="Composition"/>
      <mode value="source"/>
    </input>
    <input>
      <name value="entry"/>
      <mode value="target"/>
    </input>
    <rule>
      <name value="assignFullUrl"/>
      <source>
        <context value="comp"/>
        <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/Composition/"/>
        </parameter>
        <parameter>
          <valueId value="id"/>
        </parameter>
      </target>
    </rule>
  </group>
</StructureMap>