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

<StructureMap xmlns="http://hl7.org/fhir">
  <id value="ExtractMaternityRecord"/>
  <text>
    <status value="generated"/><div xmlns="http://www.w3.org/1999/xhtml"><p class="res-header-id"><b>Generated Narrative: StructureMap ExtractMaternityRecord</b></p><a name="ExtractMaternityRecord"> </a><a name="hcExtractMaternityRecord"> </a><pre class="fml">
<span style="color: #cc00cc">/// <b>url</b> = </span><span style="color: blue">'https://fhir.slade360.co.ke/fhir/StructureMap/ExtractMaternityRecord'</span>
<span style="color: #cc00cc">/// <b>name</b> = </span><span style="color: blue">'ExtractMaternityRecord'</span>
<span style="color: #cc00cc">/// <b>title</b> = </span><span style="color: blue">'Maternity Record Extraction'</span>
<span style="color: #cc00cc">/// <b>status</b> = </span><span style="color: blue">'active'</span>
<span style="color: #cc00cc">/// <b>description</b> = </span><span style="color: blue">'The maternity record out as: the pregnancy dates and the parity as their own Observations, because a booking is read from them; an AllergyIntolerance per allergy, since that is the one thing on this record that has to reach whoever prescribes next; the family, social and obstetric histories as panels; the admission examination and the vital-plus-rapid assessment as Observations, with the blood pressure paired; a Condition per provisional and differential diagnosis; a Procedure for the delivery itself, coded by its mode and carrying the stage durations; the third-stage findings and both mother\'s and baby\'s observations as Observations of their own; a CarePlan for the management plan; and a Consent for the admission.'</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/condition.html" title="Condition">http://hl7.org/fhir/StructureDefinition/Condition</a><span style="color: navy">&quot; </span><b>alias </b>Condition <b>as </b><b>target</b>
<b>uses</b><span style="color: navy"> &quot;</span><a href="http://hl7.org/fhir/R5/allergyintolerance.html" title="AllergyIntolerance">http://hl7.org/fhir/StructureDefinition/AllergyIntolerance</a><span style="color: navy">&quot; </span><b>alias </b>AllergyIntolerance <b>as </b><b>target</b>
<b>uses</b><span style="color: navy"> &quot;</span><a href="http://hl7.org/fhir/R5/procedure.html" title="Procedure">http://hl7.org/fhir/StructureDefinition/Procedure</a><span style="color: navy">&quot; </span><b>alias </b>Procedure <b>as </b><b>target</b>
<b>uses</b><span style="color: navy"> &quot;</span><a href="http://hl7.org/fhir/R5/careplan.html" title="CarePlan">http://hl7.org/fhir/StructureDefinition/CarePlan</a><span style="color: navy">&quot; </span><b>alias </b>CarePlan <b>as </b><b>target</b>
<b>uses</b><span style="color: navy"> &quot;</span><a href="http://hl7.org/fhir/R5/consent.html" title="Consent">http://hl7.org/fhir/StructureDefinition/Consent</a><span style="color: navy">&quot; </span><b>alias </b>Consent <b>as </b><b>target</b>

<b>group </b>ExtractMaternityRecord<span style="color: navy">(</span><b>source</b> <span style="color: maroon">qr</span><span style="color: navy"> : </span>QR, <b>target</b> <span style="color: maroon">bundle</span><span style="color: navy"> : </span>Bundle<span style="color: navy">)</span><span style="color: navy"> {
</span>  qr<span style="color: navy"><b> -&gt; </b></span>bundle.type = <span style="color: blue">'transaction'</span> <i>&quot;setBundleType&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">// </span><span style="color: green">── The present pregnancy's dates ───────────────────────────────────────</span>
  <span style="color: navy">// </span><span style="color: green">LMP, EDD by dates and the final agreed EDD after a dating scan, each as its</span>
  <span style="color: navy">// </span><span style="color: green">own Observation. All three are kept: the gap between an EDD by dates and an</span>
  <span style="color: navy">// </span><span style="color: green">EDD by scan is what a post-dates decision turns on, and collapsing them</span>
  <span style="color: navy">// </span><span style="color: green">into one would erase the disagreement.</span>
  qr.item<b> as </b><span style="color: maroon">g</span><b> where </b><span style="color: navy">(</span>linkId = 'present-pregnancy'<span style="color: navy">)</span><b> then</b><span style="color: navy"> {
</span>    g.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'present-pregnancy/lmp') and answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span> bundle.entry<b> as </b><span style="color: maroon">entry</span><span style="color: navy">, </span> entry.resource = <b>create</b><span style="color: navy">(</span><span style="color: blue">'Observation'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">obs</span><b> then</b><span style="color: navy"> {
</span>      qr<span style="color: navy"><b> -&gt; </b></span> obs<span style="color: navy">, </span> entry<b> then </b>BuildObsBase<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">obs</span><span style="color: navy">, </span><span style="color: maroon">entry</span><span style="color: navy">)</span> <i>&quot;base&quot;</i><span style="color: navy">;</span>
      qr<span style="color: navy"><b> -&gt; </b></span>obs<b> then </b>SetSurveyCategory<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">obs</span><span style="color: navy">)</span> <i>&quot;category&quot;</i><span style="color: navy">;</span>
      it<span style="color: navy"><b> -&gt; </b></span>obs.code<b> as </b><span style="color: maroon">cc</span><b> then</b><span style="color: navy"> {
</span>        it<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>          it<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'http://loinc.org'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
          it<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'8665-2'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
          it<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Last menstrual period start date'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;code&quot;</i><span style="color: navy">;</span>
      it.answer first<b> as </b><span style="color: maroon">a</span><b> then</b><span style="color: navy"> {
</span>        a.value<b> as </b><span style="color: maroon">v</span><span style="color: navy"><b> -&gt; </b></span>obs.value = <b>cast</b><span style="color: navy">(</span><span style="color: maroon">v</span><span style="color: navy">, </span><span style="color: blue">'dateTime'</span><span style="color: navy">)</span> <i>&quot;set&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;measure_8665_2&quot;</i><span style="color: navy">;</span>
    g.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'present-pregnancy/edd-by-dates') and answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span> bundle.entry<b> as </b><span style="color: maroon">entry</span><span style="color: navy">, </span> entry.resource = <b>create</b><span style="color: navy">(</span><span style="color: blue">'Observation'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">obs</span><b> then</b><span style="color: navy"> {
</span>      qr<span style="color: navy"><b> -&gt; </b></span> obs<span style="color: navy">, </span> entry<b> then </b>BuildObsBase<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">obs</span><span style="color: navy">, </span><span style="color: maroon">entry</span><span style="color: navy">)</span> <i>&quot;base&quot;</i><span style="color: navy">;</span>
      qr<span style="color: navy"><b> -&gt; </b></span>obs<b> then </b>SetSurveyCategory<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">obs</span><span style="color: navy">)</span> <i>&quot;category&quot;</i><span style="color: navy">;</span>
      it<span style="color: navy"><b> -&gt; </b></span>obs.code<b> as </b><span style="color: maroon">cc</span><b> then</b><span style="color: navy"> {
</span>        it<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>          it<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'http://loinc.org'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
          it<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'11778-8'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
          it<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Delivery date Estimated'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;code&quot;</i><span style="color: navy">;</span>
      it.answer first<b> as </b><span style="color: maroon">a</span><b> then</b><span style="color: navy"> {
</span>        a.value<b> as </b><span style="color: maroon">v</span><span style="color: navy"><b> -&gt; </b></span>obs.value = <b>cast</b><span style="color: navy">(</span><span style="color: maroon">v</span><span style="color: navy">, </span><span style="color: blue">'dateTime'</span><span style="color: navy">)</span> <i>&quot;set&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span><span style="color: navy">;</span>
      it<span style="color: navy"><b> -&gt; </b></span> obs.note<b> as </b><span style="color: maroon">n</span><span style="color: navy">, </span> n.text = <span style="color: blue">'Estimated from the last menstrual period.'</span> <i>&quot;note&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;measure_11778_8&quot;</i><span style="color: navy">;</span>
    g.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'present-pregnancy/edd-final') and answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span> bundle.entry<b> as </b><span style="color: maroon">entry</span><span style="color: navy">, </span> entry.resource = <b>create</b><span style="color: navy">(</span><span style="color: blue">'Observation'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">obs</span><b> then</b><span style="color: navy"> {
</span>      qr<span style="color: navy"><b> -&gt; </b></span> obs<span style="color: navy">, </span> entry<b> then </b>BuildObsBase<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">obs</span><span style="color: navy">, </span><span style="color: maroon">entry</span><span style="color: navy">)</span> <i>&quot;base&quot;</i><span style="color: navy">;</span>
      qr<span style="color: navy"><b> -&gt; </b></span>obs<b> then </b>SetSurveyCategory<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">obs</span><span style="color: navy">)</span> <i>&quot;category&quot;</i><span style="color: navy">;</span>
      it<span style="color: navy"><b> -&gt; </b></span>obs.code<b> as </b><span style="color: maroon">cc</span><b> then</b><span style="color: navy"> {
</span>        it<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>          it<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'http://loinc.org'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
          it<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'11778-8'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
          it<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Delivery date Estimated'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;code&quot;</i><span style="color: navy">;</span>
      it.answer first<b> as </b><span style="color: maroon">a</span><b> then</b><span style="color: navy"> {
</span>        a.value<b> as </b><span style="color: maroon">v</span><span style="color: navy"><b> -&gt; </b></span>obs.value = <b>cast</b><span style="color: navy">(</span><span style="color: maroon">v</span><span style="color: navy">, </span><span style="color: blue">'dateTime'</span><span style="color: navy">)</span> <i>&quot;set&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span><span style="color: navy">;</span>
      it<span style="color: navy"><b> -&gt; </b></span> obs.note<b> as </b><span style="color: maroon">n</span><span style="color: navy">, </span> n.text = <span style="color: blue">'The final agreed date after the dating scan. Where this differs from the date by LMP, this is the one care was planned against.'</span> <i>&quot;note&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;measure_11778_82&quot;</i><span style="color: navy">;</span>
    g.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'present-pregnancy/anc-visits') and answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span> bundle.entry<b> as </b><span style="color: maroon">entry</span><span style="color: navy">, </span> entry.resource = <b>create</b><span style="color: navy">(</span><span style="color: blue">'Observation'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">obs</span><b> then</b><span style="color: navy"> {
</span>      qr<span style="color: navy"><b> -&gt; </b></span> obs<span style="color: navy">, </span> entry<b> then </b>BuildObsBase<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">obs</span><span style="color: navy">, </span><span style="color: maroon">entry</span><span style="color: navy">)</span> <i>&quot;base&quot;</i><span style="color: navy">;</span>
      qr<span style="color: navy"><b> -&gt; </b></span>obs<b> then </b>SetSurveyCategory<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">obs</span><span style="color: navy">)</span> <i>&quot;category&quot;</i><span style="color: navy">;</span>
      it<span style="color: navy"><b> -&gt; </b></span>obs.code<b> as </b><span style="color: maroon">cc</span><b> then</b><span style="color: navy"> {
</span>        it<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>          it<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
          it<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'obs-number-of-antenatal-visits'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
          it<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Number of antenatal visits'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;code&quot;</i><span style="color: navy">;</span>
      it.answer first<b> as </b><span style="color: maroon">a</span><b> then</b><span style="color: navy"> {
</span>        a.value<b> as </b><span style="color: maroon">v</span><span style="color: navy"><b> -&gt; </b></span>obs.value = <span style="color: maroon">v</span> <i>&quot;set&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;measure_labour_stage_duration&quot;</i><span style="color: navy">;</span>
    g.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'present-pregnancy/other-significant-history') and answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span> bundle.entry<b> as </b><span style="color: maroon">entry</span><span style="color: navy">, </span> entry.resource = <b>create</b><span style="color: navy">(</span><span style="color: blue">'Observation'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">obs</span><b> then</b><span style="color: navy"> {
</span>      qr<span style="color: navy"><b> -&gt; </b></span> obs<span style="color: navy">, </span> entry<b> then </b>BuildObsBase<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">obs</span><span style="color: navy">, </span><span style="color: maroon">entry</span><span style="color: navy">)</span> <i>&quot;base&quot;</i><span style="color: navy">;</span>
      qr<span style="color: navy"><b> -&gt; </b></span>obs<b> then </b>SetSurveyCategory<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">obs</span><span style="color: navy">)</span> <i>&quot;category&quot;</i><span style="color: navy">;</span>
      it<span style="color: navy"><b> -&gt; </b></span>obs.code<b> as </b><span style="color: maroon">cc</span><b> then</b><span style="color: navy"> {
</span>        it<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>          it<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'http://loinc.org'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
          it<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'10164-2'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
          it<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'History of Present illness Narrative'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
        it<span style="color: navy"><b> -&gt; </b></span>cc.text = <span style="color: blue">'Other significant history of this pregnancy'</span> <i>&quot;codeText&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;code&quot;</i><span style="color: navy">;</span>
      it.answer first<b> as </b><span style="color: maroon">a</span><b> then</b><span style="color: navy"> {
</span>        a.value<b> as </b><span style="color: maroon">txt</span><span style="color: navy"><b> -&gt; </b></span> obs.note<b> as </b><span style="color: maroon">n</span><span style="color: navy">, </span> n.text = <span style="color: maroon">txt</span> <i>&quot;text&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;narr_10164_2&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">}</span> <i>&quot;presentPregnancyGroup&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">// </span><span style="color: green">── Parity ──────────────────────────────────────────────────────────────</span>
  <span style="color: navy">// </span><span style="color: green">LOINC 11977-6, [#] Parity, with the abortion count beside it as a</span>
  <span style="color: navy">// </span><span style="color: green">component: the sheet prints them as &quot;para 3 + 1&quot; and the two numbers are</span>
  <span style="color: navy">// </span><span style="color: green">read together.</span>
  qr.item<b> as </b><span style="color: maroon">g</span><b> where </b><span style="color: navy">(</span>(linkId = 'obstetric-history') and item.where(linkId = 'obstetric-history/parity').answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span> bundle.entry<b> as </b><span style="color: maroon">entry</span><span style="color: navy">, </span> entry.resource = <b>create</b><span style="color: navy">(</span><span style="color: blue">'Observation'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">obs</span><b> then</b><span style="color: navy"> {
</span>    qr<span style="color: navy"><b> -&gt; </b></span> obs<span style="color: navy">, </span> entry<b> then </b>BuildObsBase<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">obs</span><span style="color: navy">, </span><span style="color: maroon">entry</span><span style="color: navy">)</span> <i>&quot;base&quot;</i><span style="color: navy">;</span>
    qr<span style="color: navy"><b> -&gt; </b></span>obs<b> then </b>SetSurveyCategory<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">obs</span><span style="color: navy">)</span> <i>&quot;category&quot;</i><span style="color: navy">;</span>
    g<span style="color: navy"><b> -&gt; </b></span>obs.code<b> as </b><span style="color: maroon">cc</span><b> then</b><span style="color: navy"> {
</span>      g<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>        g<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'http://loinc.org'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
        g<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'11977-6'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
        g<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'[#] Parity'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;code&quot;</i><span style="color: navy">;</span>
    g.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>linkId = 'obstetric-history/parity'<span style="color: navy">)</span><b> then</b><span style="color: navy"> {
</span>      it.answer first<b> as </b><span style="color: maroon">a</span><b> then</b><span style="color: navy"> {
</span>        a.value<b> as </b><span style="color: maroon">v</span><span style="color: navy"><b> -&gt; </b></span>obs.value = <span style="color: maroon">v</span> <i>&quot;parityValue&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;parityRule&quot;</i><span style="color: navy">;</span>
    g.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'obstetric-history/abortions') and answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span>obs.component<b> as </b><span style="color: maroon">comp</span><b> then</b><span style="color: navy"> {
</span>      it<span style="color: navy"><b> -&gt; </b></span>comp.code<b> as </b><span style="color: maroon">cc</span><b> then</b><span style="color: navy"> {
</span>        it<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>          it<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
          it<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'obs-abortions'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
          it<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Abortions'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;code&quot;</i><span style="color: navy">;</span>
      it<span style="color: navy"><b> -&gt; </b></span>comp<b> then </b>SetComponentValue<span style="color: navy">(</span><span style="color: maroon">it</span><span style="color: navy">, </span><span style="color: maroon">comp</span><span style="color: navy">)</span> <i>&quot;value&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;comp_obs_abortions&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">}</span> <i>&quot;parityObservation&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">// </span><span style="color: green">── Allergies ───────────────────────────────────────────────────────────</span>
  <span style="color: navy">// </span><span style="color: green">AllergyIntolerance per row. This is the one thing on a maternity record</span>
  <span style="color: navy">// </span><span style="color: green">that has to be visible to whoever prescribes next, and a note on an</span>
  <span style="color: navy">// </span><span style="color: green">Observation is not visible to a prescribing system.</span>
  <span style="color: navy">// </span><span style="color: green">verificationStatus is 'unconfirmed': what the sheet holds is the woman's</span>
  <span style="color: navy">// </span><span style="color: green">own account at booking. `reaction.manifestation` carries what she said</span>
  <span style="color: navy">// </span><span style="color: green">happens, as text, because the sheet takes free text and a coded</span>
  <span style="color: navy">// </span><span style="color: green">manifestation would be an invention.</span>
  qr.item<b> as </b><span style="color: maroon">ag</span><b> where </b><span style="color: navy">(</span>linkId = 'allergies'<span style="color: navy">)</span><b> then</b><span style="color: navy"> {
</span>    ag.item<b> as </b><span style="color: maroon">g</span><b> where </b><span style="color: navy">(</span>(linkId = 'allergies/allergy') and item.where(linkId = 'allergies/allergy/substance').answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span> bundle.entry<b> as </b><span style="color: maroon">entry</span><span style="color: navy">, </span> entry.resource = <b>create</b><span style="color: navy">(</span><span style="color: blue">'AllergyIntolerance'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">allergy</span><b> then</b><span style="color: navy"> {
</span>      qr<span style="color: navy"><b> -&gt; </b></span> allergy<span style="color: navy">, </span> entry<b> then </b>BuildAllergyIntoleranceBase<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">allergy</span><span style="color: navy">, </span><span style="color: maroon">entry</span><span style="color: navy">)</span> <i>&quot;base&quot;</i><span style="color: navy">;</span>
      g<span style="color: navy"><b> -&gt; </b></span>allergy.clinicalStatus<b> as </b><span style="color: maroon">cs</span><b> then</b><span style="color: navy"> {
</span>        g<span style="color: navy"><b> -&gt; </b></span>cs.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>          g<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'http://terminology.hl7.org/CodeSystem/allergyintolerance-clinical'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
          g<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'active'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
          g<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Active'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;clinicalStatus&quot;</i><span style="color: navy">;</span>
      g<span style="color: navy"><b> -&gt; </b></span>allergy.verificationStatus<b> as </b><span style="color: maroon">vs</span><b> then</b><span style="color: navy"> {
</span>        g<span style="color: navy"><b> -&gt; </b></span>vs.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>          g<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'http://terminology.hl7.org/CodeSystem/allergyintolerance-verification'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
          g<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'unconfirmed'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
          g<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Unconfirmed'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;verificationStatus&quot;</i><span style="color: navy">;</span>
      g.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>linkId = 'allergies/allergy/substance'<span style="color: navy">)</span><b> then</b><span style="color: navy"> {
</span>        it.answer first<b> as </b><span style="color: maroon">a</span><b> then</b><span style="color: navy"> {
</span>          a.value<b> as </b><span style="color: maroon">txt</span><span style="color: navy"><b> -&gt; </b></span> allergy.code<b> as </b><span style="color: maroon">cc</span><span style="color: navy">, </span> cc.text = <span style="color: maroon">txt</span> <i>&quot;substanceText&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;substanceRule&quot;</i><span style="color: navy">;</span>
      g.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'allergies/allergy/reaction') and answer.value.exists()<span style="color: navy">)</span><b> then</b><span style="color: navy"> {
</span>        it.answer first<b> as </b><span style="color: maroon">a</span><b> then</b><span style="color: navy"> {
</span>          a.value<b> as </b><span style="color: maroon">txt</span><span style="color: navy"><b> -&gt; </b></span> allergy.reaction<b> as </b><span style="color: maroon">rx</span><span style="color: navy">, </span> rx.manifestation<b> as </b><span style="color: maroon">man</span><span style="color: navy">, </span> man.concept<b> as </b><span style="color: maroon">mc</span><span style="color: navy">, </span> mc.text = <span style="color: maroon">txt</span> <i>&quot;manifestationText&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;reactionRule&quot;</i><span style="color: navy">;</span>
      qr.authored<b> as </b><span style="color: maroon">t</span><span style="color: navy"><b> -&gt; </b></span>allergy.recordedDate = <span style="color: maroon">t</span> <i>&quot;recordedDate&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;createAllergy&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">// </span><span style="color: green">&quot;No known allergies&quot; is a positive statement and gets its own</span>
    <span style="color: navy">// </span><span style="color: green">AllergyIntolerance with the HL7 no-known-allergy code -- which is the</span>
    <span style="color: navy">// </span><span style="color: green">difference between a woman who was asked and had none and a woman nobody</span>
    <span style="color: navy">// </span><span style="color: green">asked.</span>
    ag.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'allergies/none-known') and (answer.value.ofType(Coding).code = 'Y')<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span> bundle.entry<b> as </b><span style="color: maroon">entry</span><span style="color: navy">, </span> entry.resource = <b>create</b><span style="color: navy">(</span><span style="color: blue">'AllergyIntolerance'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">allergy</span><b> then</b><span style="color: navy"> {
</span>      qr<span style="color: navy"><b> -&gt; </b></span> allergy<span style="color: navy">, </span> entry<b> then </b>BuildAllergyIntoleranceBase<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">allergy</span><span style="color: navy">, </span><span style="color: maroon">entry</span><span style="color: navy">)</span> <i>&quot;base&quot;</i><span style="color: navy">;</span>
      it<span style="color: navy"><b> -&gt; </b></span>allergy.clinicalStatus<b> as </b><span style="color: maroon">cs</span><b> then</b><span style="color: navy"> {
</span>        it<span style="color: navy"><b> -&gt; </b></span>cs.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>          it<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'http://terminology.hl7.org/CodeSystem/allergyintolerance-clinical'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
          it<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'active'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
          it<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Active'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;clinicalStatus&quot;</i><span style="color: navy">;</span>
      it<span style="color: navy"><b> -&gt; </b></span>allergy.code<b> as </b><span style="color: maroon">cc</span><b> then</b><span style="color: navy"> {
</span>        it<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>          it<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'http://terminology.hl7.org/CodeSystem/v3-NullFlavor'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
          it<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'NA'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
          it<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'not applicable'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
        it<span style="color: navy"><b> -&gt; </b></span>cc.text = <span style="color: blue">'No known allergies'</span> <i>&quot;codeText&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;code&quot;</i><span style="color: navy">;</span>
      qr.authored<b> as </b><span style="color: maroon">t</span><span style="color: navy"><b> -&gt; </b></span>allergy.recordedDate = <span style="color: maroon">t</span> <i>&quot;recordedDate&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;noKnownAllergies&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">}</span> <i>&quot;allergiesGroup&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">// </span><span style="color: green">── Past obstetric history, one Observation per previous pregnancy ──────</span>
  <span style="color: navy">// </span><span style="color: green">One per row rather than one panel of everything. Each row is a pregnancy</span>
  <span style="color: navy">// </span><span style="color: green">with its own year, gestation, mode and outcome, and the obstetric decision</span>
  <span style="color: navy">// </span><span style="color: green">this record informs — whether a previous caesarean allows a trial of</span>
  <span style="color: navy">// </span><span style="color: green">labour — is a question about one specific row.</span>
  qr.item<b> as </b><span style="color: maroon">og</span><b> where </b><span style="color: navy">(</span>linkId = 'obstetric-history'<span style="color: navy">)</span><b> then</b><span style="color: navy"> {
</span>    og.item<b> as </b><span style="color: maroon">g</span><b> where </b><span style="color: navy">(</span>(linkId = 'obstetric-history/pregnancy') and item.answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span> bundle.entry<b> as </b><span style="color: maroon">entry</span><span style="color: navy">, </span> entry.resource = <b>create</b><span style="color: navy">(</span><span style="color: blue">'Observation'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">obs</span><b> then</b><span style="color: navy"> {
</span>      qr<span style="color: navy"><b> -&gt; </b></span> obs<span style="color: navy">, </span> entry<b> then </b>BuildObsBase<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">obs</span><span style="color: navy">, </span><span style="color: maroon">entry</span><span style="color: navy">)</span> <i>&quot;base&quot;</i><span style="color: navy">;</span>
      qr<span style="color: navy"><b> -&gt; </b></span>obs<b> then </b>SetSurveyCategory<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">obs</span><span style="color: navy">)</span> <i>&quot;category&quot;</i><span style="color: navy">;</span>
      g<span style="color: navy"><b> -&gt; </b></span>obs.code<b> as </b><span style="color: maroon">cc</span><b> then</b><span style="color: navy"> {
</span>        g<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>          g<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'http://loinc.org'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
          g<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'10162-6'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
          g<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'History of pregnancies Narrative'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
        g<span style="color: navy"><b> -&gt; </b></span>cc.text = <span style="color: blue">'Previous pregnancy'</span> <i>&quot;codeText&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;code&quot;</i><span style="color: navy">;</span>
      g.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'obstetric-history/pregnancy/year') and answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span>obs.component<b> as </b><span style="color: maroon">comp</span><b> then</b><span style="color: navy"> {
</span>        it<span style="color: navy"><b> -&gt; </b></span>comp.code<b> as </b><span style="color: maroon">cc</span><b> then</b><span style="color: navy"> {
</span>          it<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>            it<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
            it<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'obs-year'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
            it<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Year'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;code&quot;</i><span style="color: navy">;</span>
        it<span style="color: navy"><b> -&gt; </b></span>comp<b> then </b>SetComponentValue<span style="color: navy">(</span><span style="color: maroon">it</span><span style="color: navy">, </span><span style="color: maroon">comp</span><span style="color: navy">)</span> <i>&quot;value&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;comp_obs_year&quot;</i><span style="color: navy">;</span>
      g.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'obstetric-history/pregnancy/gestation') and answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span>obs.component<b> as </b><span style="color: maroon">comp</span><b> then</b><span style="color: navy"> {
</span>        it<span style="color: navy"><b> -&gt; </b></span>comp.code<b> as </b><span style="color: maroon">cc</span><b> then</b><span style="color: navy"> {
</span>          it<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>            it<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'http://loinc.org'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
            it<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'11884-4'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
            it<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Gestational age Estimated'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;code&quot;</i><span style="color: navy">;</span>
        it<span style="color: navy"><b> -&gt; </b></span>comp<b> then </b>SetComponentValue<span style="color: navy">(</span><span style="color: maroon">it</span><span style="color: navy">, </span><span style="color: maroon">comp</span><span style="color: navy">)</span> <i>&quot;value&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;comp_11884_4&quot;</i><span style="color: navy">;</span>
      g.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'obstetric-history/pregnancy/mode-of-delivery') and answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span>obs.component<b> as </b><span style="color: maroon">comp</span><b> then</b><span style="color: navy"> {
</span>        it<span style="color: navy"><b> -&gt; </b></span>comp.code<b> as </b><span style="color: maroon">cc</span><b> then</b><span style="color: navy"> {
</span>          it<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>            it<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
            it<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'obstetric-mode-of-delivery'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
            it<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Mode of delivery'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;code&quot;</i><span style="color: navy">;</span>
        it<span style="color: navy"><b> -&gt; </b></span>comp<b> then </b>SetComponentCodedValue<span style="color: navy">(</span><span style="color: maroon">it</span><span style="color: navy">, </span><span style="color: maroon">comp</span><span style="color: navy">)</span> <i>&quot;value&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;comp_obstetric_mode_of_delivery&quot;</i><span style="color: navy">;</span>
      g.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'obstetric-history/pregnancy/birth-weight') and answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span>obs.component<b> as </b><span style="color: maroon">comp</span><b> then</b><span style="color: navy"> {
</span>        it<span style="color: navy"><b> -&gt; </b></span>comp.code<b> as </b><span style="color: maroon">cc</span><b> then</b><span style="color: navy"> {
</span>          it<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>            it<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'http://loinc.org'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
            it<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'8339-4'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
            it<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Birth weight Measured'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;code&quot;</i><span style="color: navy">;</span>
        it<span style="color: navy"><b> -&gt; </b></span>comp<b> then </b>SetComponentValue<span style="color: navy">(</span><span style="color: maroon">it</span><span style="color: navy">, </span><span style="color: maroon">comp</span><span style="color: navy">)</span> <i>&quot;value&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;comp_8339_4&quot;</i><span style="color: navy">;</span>
      g.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'obstetric-history/pregnancy/outcome') and answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span>obs.component<b> as </b><span style="color: maroon">comp</span><b> then</b><span style="color: navy"> {
</span>        it<span style="color: navy"><b> -&gt; </b></span>comp.code<b> as </b><span style="color: maroon">cc</span><b> then</b><span style="color: navy"> {
</span>          it<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>            it<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
            it<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'obs-outcome'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
            it<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Outcome'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;code&quot;</i><span style="color: navy">;</span>
        it<span style="color: navy"><b> -&gt; </b></span>comp<b> then </b>SetComponentValue<span style="color: navy">(</span><span style="color: maroon">it</span><span style="color: navy">, </span><span style="color: maroon">comp</span><span style="color: navy">)</span> <i>&quot;value&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;comp_obs_outcome&quot;</i><span style="color: navy">;</span>
      g.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'obstetric-history/pregnancy/pregnancy-course') and answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span>obs.component<b> as </b><span style="color: maroon">comp</span><b> then</b><span style="color: navy"> {
</span>        it<span style="color: navy"><b> -&gt; </b></span>comp.code<b> as </b><span style="color: maroon">cc</span><b> then</b><span style="color: navy"> {
</span>          it<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>            it<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
            it<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'obs-course-of-the-pregnancy'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
            it<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Course of the pregnancy'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;code&quot;</i><span style="color: navy">;</span>
        it<span style="color: navy"><b> -&gt; </b></span>comp<b> then </b>SetComponentValue<span style="color: navy">(</span><span style="color: maroon">it</span><span style="color: navy">, </span><span style="color: maroon">comp</span><span style="color: navy">)</span> <i>&quot;value&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;comp_obs_course_of_the_pregnancy&quot;</i><span style="color: navy">;</span>
      g.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'obstetric-history/pregnancy/labour') and answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span>obs.component<b> as </b><span style="color: maroon">comp</span><b> then</b><span style="color: navy"> {
</span>        it<span style="color: navy"><b> -&gt; </b></span>comp.code<b> as </b><span style="color: maroon">cc</span><b> then</b><span style="color: navy"> {
</span>          it<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>            it<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
            it<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'obs-labour'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
            it<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Labour'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;code&quot;</i><span style="color: navy">;</span>
        it<span style="color: navy"><b> -&gt; </b></span>comp<b> then </b>SetComponentValue<span style="color: navy">(</span><span style="color: maroon">it</span><span style="color: navy">, </span><span style="color: maroon">comp</span><span style="color: navy">)</span> <i>&quot;value&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;comp_obs_labour&quot;</i><span style="color: navy">;</span>
      g.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'obstetric-history/pregnancy/puerperium') and answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span>obs.component<b> as </b><span style="color: maroon">comp</span><b> then</b><span style="color: navy"> {
</span>        it<span style="color: navy"><b> -&gt; </b></span>comp.code<b> as </b><span style="color: maroon">cc</span><b> then</b><span style="color: navy"> {
</span>          it<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>            it<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
            it<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'obs-puerperium'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
            it<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Puerperium'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;code&quot;</i><span style="color: navy">;</span>
        it<span style="color: navy"><b> -&gt; </b></span>comp<b> then </b>SetComponentValue<span style="color: navy">(</span><span style="color: maroon">it</span><span style="color: navy">, </span><span style="color: maroon">comp</span><span style="color: navy">)</span> <i>&quot;value&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;comp_obs_puerperium&quot;</i><span style="color: navy">;</span>
      g.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'obstetric-history/pregnancy/baby-admitted-nbu') and answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span>obs.component<b> as </b><span style="color: maroon">comp</span><b> then</b><span style="color: navy"> {
</span>        it<span style="color: navy"><b> -&gt; </b></span>comp.code<b> as </b><span style="color: maroon">cc</span><b> then</b><span style="color: navy"> {
</span>          it<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>            it<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
            it<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'obs-baby-admitted-to-nbu'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
            it<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Baby admitted to NBU'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;code&quot;</i><span style="color: navy">;</span>
        it<span style="color: navy"><b> -&gt; </b></span>comp<b> then </b>SetComponentCodedValue<span style="color: navy">(</span><span style="color: maroon">it</span><span style="color: navy">, </span><span style="color: maroon">comp</span><span style="color: navy">)</span> <i>&quot;value&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;comp_obs_baby_admitted_to_nbu&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;previousPregnancy&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">}</span> <i>&quot;obstetricHistoryGroup&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">// </span><span style="color: green">── Family history ──────────────────────────────────────────────────────</span>
  <span style="color: navy">// </span><span style="color: green">A panel, not FamilyMemberHistory resources. The sheet ticks whether there</span>
  <span style="color: navy">// </span><span style="color: green">is diabetes, hypertension, twins or an inherited condition in the family</span>
  <span style="color: navy">// </span><span style="color: green">and names no relative, and a FamilyMemberHistory with no relationship is</span>
  <span style="color: navy">// </span><span style="color: green">not a family history.</span>
  qr.item<b> as </b><span style="color: maroon">g</span><b> where </b><span style="color: navy">(</span>(linkId = 'family-history') and item.answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span> bundle.entry<b> as </b><span style="color: maroon">entry</span><span style="color: navy">, </span> entry.resource = <b>create</b><span style="color: navy">(</span><span style="color: blue">'Observation'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">obs</span><b> then</b><span style="color: navy"> {
</span>    qr<span style="color: navy"><b> -&gt; </b></span> obs<span style="color: navy">, </span> entry<b> then </b>BuildObsBase<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">obs</span><span style="color: navy">, </span><span style="color: maroon">entry</span><span style="color: navy">)</span> <i>&quot;base&quot;</i><span style="color: navy">;</span>
    qr<span style="color: navy"><b> -&gt; </b></span>obs<b> then </b>SetSurveyCategory<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">obs</span><span style="color: navy">)</span> <i>&quot;category&quot;</i><span style="color: navy">;</span>
    g<span style="color: navy"><b> -&gt; </b></span>obs.code<b> as </b><span style="color: maroon">cc</span><b> then</b><span style="color: navy"> {
</span>      g<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>        g<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'http://loinc.org'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
        g<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'10157-6'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
        g<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'History of family member diseases note'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;code&quot;</i><span style="color: navy">;</span>
    g.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'family-history/twins') and answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span>obs.component<b> as </b><span style="color: maroon">comp</span><b> then</b><span style="color: navy"> {
</span>      it<span style="color: navy"><b> -&gt; </b></span>comp.code<b> as </b><span style="color: maroon">cc</span><b> then</b><span style="color: navy"> {
</span>        it<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>          it<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
          it<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'obs-twins'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
          it<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Twins'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;code&quot;</i><span style="color: navy">;</span>
      it<span style="color: navy"><b> -&gt; </b></span>comp<b> then </b>SetComponentCodedValue<span style="color: navy">(</span><span style="color: maroon">it</span><span style="color: navy">, </span><span style="color: maroon">comp</span><span style="color: navy">)</span> <i>&quot;value&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;comp_obs_twins&quot;</i><span style="color: navy">;</span>
    g.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'family-history/diabetes') and answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span>obs.component<b> as </b><span style="color: maroon">comp</span><b> then</b><span style="color: navy"> {
</span>      it<span style="color: navy"><b> -&gt; </b></span>comp.code<b> as </b><span style="color: maroon">cc</span><b> then</b><span style="color: navy"> {
</span>        it<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>          it<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
          it<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'obs-diabetes'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
          it<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Diabetes'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;code&quot;</i><span style="color: navy">;</span>
      it<span style="color: navy"><b> -&gt; </b></span>comp<b> then </b>SetComponentCodedValue<span style="color: navy">(</span><span style="color: maroon">it</span><span style="color: navy">, </span><span style="color: maroon">comp</span><span style="color: navy">)</span> <i>&quot;value&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;comp_obs_diabetes&quot;</i><span style="color: navy">;</span>
    g.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'family-history/hypertension') and answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span>obs.component<b> as </b><span style="color: maroon">comp</span><b> then</b><span style="color: navy"> {
</span>      it<span style="color: navy"><b> -&gt; </b></span>comp.code<b> as </b><span style="color: maroon">cc</span><b> then</b><span style="color: navy"> {
</span>        it<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>          it<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
          it<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'obs-hypertension'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
          it<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Hypertension'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;code&quot;</i><span style="color: navy">;</span>
      it<span style="color: navy"><b> -&gt; </b></span>comp<b> then </b>SetComponentCodedValue<span style="color: navy">(</span><span style="color: maroon">it</span><span style="color: navy">, </span><span style="color: maroon">comp</span><span style="color: navy">)</span> <i>&quot;value&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;comp_obs_hypertension&quot;</i><span style="color: navy">;</span>
    g.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'family-history/inherited-conditions') and answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span>obs.component<b> as </b><span style="color: maroon">comp</span><b> then</b><span style="color: navy"> {
</span>      it<span style="color: navy"><b> -&gt; </b></span>comp.code<b> as </b><span style="color: maroon">cc</span><b> then</b><span style="color: navy"> {
</span>        it<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>          it<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
          it<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'obs-inherited-conditions'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
          it<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Inherited conditions'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;code&quot;</i><span style="color: navy">;</span>
      it<span style="color: navy"><b> -&gt; </b></span>comp<b> then </b>SetComponentCodedValue<span style="color: navy">(</span><span style="color: maroon">it</span><span style="color: navy">, </span><span style="color: maroon">comp</span><span style="color: navy">)</span> <i>&quot;value&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;comp_obs_inherited_conditions&quot;</i><span style="color: navy">;</span>
    g.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'family-history/other') and answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span>obs.component<b> as </b><span style="color: maroon">comp</span><b> then</b><span style="color: navy"> {
</span>      it<span style="color: navy"><b> -&gt; </b></span>comp.code<b> as </b><span style="color: maroon">cc</span><b> then</b><span style="color: navy"> {
</span>        it<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>          it<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
          it<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'obs-any-other'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
          it<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Any other'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;code&quot;</i><span style="color: navy">;</span>
      it<span style="color: navy"><b> -&gt; </b></span>comp<b> then </b>SetComponentValue<span style="color: navy">(</span><span style="color: maroon">it</span><span style="color: navy">, </span><span style="color: maroon">comp</span><span style="color: navy">)</span> <i>&quot;value&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;comp_obs_any_other&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">}</span> <i>&quot;familyHistoryPanel&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">// </span><span style="color: green">── Social history ──────────────────────────────────────────────────────</span>
  qr.item<b> as </b><span style="color: maroon">g</span><b> where </b><span style="color: navy">(</span>(linkId = 'social-history') and item.item.answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span> bundle.entry<b> as </b><span style="color: maroon">entry</span><span style="color: navy">, </span> entry.resource = <b>create</b><span style="color: navy">(</span><span style="color: blue">'Observation'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">obs</span><b> then</b><span style="color: navy"> {
</span>    qr<span style="color: navy"><b> -&gt; </b></span> obs<span style="color: navy">, </span> entry<b> then </b>BuildObsBase<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">obs</span><span style="color: navy">, </span><span style="color: maroon">entry</span><span style="color: navy">)</span> <i>&quot;base&quot;</i><span style="color: navy">;</span>
    qr<span style="color: navy"><b> -&gt; </b></span>obs<b> then </b>SetSurveyCategory<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">obs</span><span style="color: navy">)</span> <i>&quot;category&quot;</i><span style="color: navy">;</span>
    g<span style="color: navy"><b> -&gt; </b></span>obs.code<b> as </b><span style="color: maroon">cc</span><b> then</b><span style="color: navy"> {
</span>      g<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>        g<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'http://loinc.org'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
        g<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'29762-2'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
        g<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Social history note'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;code&quot;</i><span style="color: navy">;</span>
    g.item<b> as </b><span style="color: maroon">g2</span><b> where </b><span style="color: navy">(</span>linkId = 'social-history/smoking'<span style="color: navy">)</span><b> then</b><span style="color: navy"> {
</span>      g2.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'social-history/smoking/status') and answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span>obs.component<b> as </b><span style="color: maroon">comp</span><b> then</b><span style="color: navy"> {
</span>        it<span style="color: navy"><b> -&gt; </b></span>comp.code<b> as </b><span style="color: maroon">cc</span><b> then</b><span style="color: navy"> {
</span>          it<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>            it<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
            it<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'obs-smoker'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
            it<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Smoker'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;code&quot;</i><span style="color: navy">;</span>
        it<span style="color: navy"><b> -&gt; </b></span>comp<b> then </b>SetComponentCodedValue<span style="color: navy">(</span><span style="color: maroon">it</span><span style="color: navy">, </span><span style="color: maroon">comp</span><span style="color: navy">)</span> <i>&quot;value&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;comp_obs_smoker&quot;</i><span style="color: navy">;</span>
      g2.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'social-history/smoking/detail') and answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span>obs.component<b> as </b><span style="color: maroon">comp</span><b> then</b><span style="color: navy"> {
</span>        it<span style="color: navy"><b> -&gt; </b></span>comp.code<b> as </b><span style="color: maroon">cc</span><b> then</b><span style="color: navy"> {
</span>          it<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>            it<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
            it<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'obs-smoking-detail'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
            it<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Smoking detail'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;code&quot;</i><span style="color: navy">;</span>
        it<span style="color: navy"><b> -&gt; </b></span>comp<b> then </b>SetComponentValue<span style="color: navy">(</span><span style="color: maroon">it</span><span style="color: navy">, </span><span style="color: maroon">comp</span><span style="color: navy">)</span> <i>&quot;value&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;comp_obs_smoking_detail&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;smokingSub&quot;</i><span style="color: navy">;</span>
    g.item<b> as </b><span style="color: maroon">g2</span><b> where </b><span style="color: navy">(</span>linkId = 'social-history/alcohol'<span style="color: navy">)</span><b> then</b><span style="color: navy"> {
</span>      g2.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'social-history/alcohol/status') and answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span>obs.component<b> as </b><span style="color: maroon">comp</span><b> then</b><span style="color: navy"> {
</span>        it<span style="color: navy"><b> -&gt; </b></span>comp.code<b> as </b><span style="color: maroon">cc</span><b> then</b><span style="color: navy"> {
</span>          it<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>            it<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
            it<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'obs-alcohol'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
            it<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Alcohol'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;code&quot;</i><span style="color: navy">;</span>
        it<span style="color: navy"><b> -&gt; </b></span>comp<b> then </b>SetComponentCodedValue<span style="color: navy">(</span><span style="color: maroon">it</span><span style="color: navy">, </span><span style="color: maroon">comp</span><span style="color: navy">)</span> <i>&quot;value&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;comp_obs_alcohol&quot;</i><span style="color: navy">;</span>
      g2.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'social-history/alcohol/detail') and answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span>obs.component<b> as </b><span style="color: maroon">comp</span><b> then</b><span style="color: navy"> {
</span>        it<span style="color: navy"><b> -&gt; </b></span>comp.code<b> as </b><span style="color: maroon">cc</span><b> then</b><span style="color: navy"> {
</span>          it<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>            it<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
            it<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'obs-alcohol-detail'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
            it<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Alcohol detail'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;code&quot;</i><span style="color: navy">;</span>
        it<span style="color: navy"><b> -&gt; </b></span>comp<b> then </b>SetComponentValue<span style="color: navy">(</span><span style="color: maroon">it</span><span style="color: navy">, </span><span style="color: maroon">comp</span><span style="color: navy">)</span> <i>&quot;value&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;comp_obs_alcohol_detail&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;alcoholSub&quot;</i><span style="color: navy">;</span>
    g.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'social-history/marital-status') and answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span>obs.component<b> as </b><span style="color: maroon">comp</span><b> then</b><span style="color: navy"> {
</span>      it<span style="color: navy"><b> -&gt; </b></span>comp.code<b> as </b><span style="color: maroon">cc</span><b> then</b><span style="color: navy"> {
</span>        it<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>          it<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
          it<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'obs-marital-status'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
          it<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Marital status'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;code&quot;</i><span style="color: navy">;</span>
      it<span style="color: navy"><b> -&gt; </b></span>comp<b> then </b>SetComponentCodedValue<span style="color: navy">(</span><span style="color: maroon">it</span><span style="color: navy">, </span><span style="color: maroon">comp</span><span style="color: navy">)</span> <i>&quot;value&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;comp_obs_marital_status&quot;</i><span style="color: navy">;</span>
    g.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'social-history/other') and answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span>obs.component<b> as </b><span style="color: maroon">comp</span><b> then</b><span style="color: navy"> {
</span>      it<span style="color: navy"><b> -&gt; </b></span>comp.code<b> as </b><span style="color: maroon">cc</span><b> then</b><span style="color: navy"> {
</span>        it<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>          it<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
          it<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'obs-other-social-history'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
          it<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Other social history'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;code&quot;</i><span style="color: navy">;</span>
      it<span style="color: navy"><b> -&gt; </b></span>comp<b> then </b>SetComponentValue<span style="color: navy">(</span><span style="color: maroon">it</span><span style="color: navy">, </span><span style="color: maroon">comp</span><span style="color: navy">)</span> <i>&quot;value&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;comp_obs_other_social_history&quot;</i><span style="color: navy">;</span>
    g.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>linkId = 'social-history/functional-status'<span style="color: navy">)</span><b> then</b><span style="color: navy"> {
</span>      it.answer first<b> as </b><span style="color: maroon">a</span><b> then</b><span style="color: navy"> {
</span>        a.value<b> as </b><span style="color: maroon">txt</span><span style="color: navy"><b> -&gt; </b></span> obs.note<b> as </b><span style="color: maroon">n</span><span style="color: navy">, </span> n.text = <span style="color: maroon">txt</span> <i>&quot;text&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;note&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">}</span> <i>&quot;socialHistoryPanel&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 = 'gynaecological-history') and answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span> bundle.entry<b> as </b><span style="color: maroon">entry</span><span style="color: navy">, </span> entry.resource = <b>create</b><span style="color: navy">(</span><span style="color: blue">'Observation'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">obs</span><b> then</b><span style="color: navy"> {
</span>    qr<span style="color: navy"><b> -&gt; </b></span> obs<span style="color: navy">, </span> entry<b> then </b>BuildObsBase<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">obs</span><span style="color: navy">, </span><span style="color: maroon">entry</span><span style="color: navy">)</span> <i>&quot;base&quot;</i><span style="color: navy">;</span>
    qr<span style="color: navy"><b> -&gt; </b></span>obs<b> then </b>SetSurveyCategory<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">obs</span><span style="color: navy">)</span> <i>&quot;category&quot;</i><span style="color: navy">;</span>
    it<span style="color: navy"><b> -&gt; </b></span>obs.code<b> as </b><span style="color: maroon">cc</span><b> then</b><span style="color: navy"> {
</span>      it<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>        it<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'http://loinc.org'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
        it<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'10160-0'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
        it<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'History of Medication use Narrative'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
      it<span style="color: navy"><b> -&gt; </b></span>cc.text = <span style="color: blue">'Gynaecological history'</span> <i>&quot;codeText&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;code&quot;</i><span style="color: navy">;</span>
    it.answer first<b> as </b><span style="color: maroon">a</span><b> then</b><span style="color: navy"> {
</span>      a.value<b> as </b><span style="color: maroon">txt</span><span style="color: navy"><b> -&gt; </b></span> obs.note<b> as </b><span style="color: maroon">n</span><span style="color: navy">, </span> n.text = <span style="color: maroon">txt</span> <i>&quot;text&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span><span style="color: navy">;</span>
  <span style="color: navy">}</span> <i>&quot;narr_10160_0&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 = 'past-medical-surgical-history') and answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span> bundle.entry<b> as </b><span style="color: maroon">entry</span><span style="color: navy">, </span> entry.resource = <b>create</b><span style="color: navy">(</span><span style="color: blue">'Observation'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">obs</span><b> then</b><span style="color: navy"> {
</span>    qr<span style="color: navy"><b> -&gt; </b></span> obs<span style="color: navy">, </span> entry<b> then </b>BuildObsBase<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">obs</span><span style="color: navy">, </span><span style="color: maroon">entry</span><span style="color: navy">)</span> <i>&quot;base&quot;</i><span style="color: navy">;</span>
    qr<span style="color: navy"><b> -&gt; </b></span>obs<b> then </b>SetSurveyCategory<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">obs</span><span style="color: navy">)</span> <i>&quot;category&quot;</i><span style="color: navy">;</span>
    it<span style="color: navy"><b> -&gt; </b></span>obs.code<b> as </b><span style="color: maroon">cc</span><b> then</b><span style="color: navy"> {
</span>      it<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>        it<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'http://loinc.org'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
        it<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'11348-0'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
        it<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'History of Past illness note'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
      it<span style="color: navy"><b> -&gt; </b></span>cc.text = <span style="color: blue">'Past medical and surgical history'</span> <i>&quot;codeText&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;code&quot;</i><span style="color: navy">;</span>
    it.answer first<b> as </b><span style="color: maroon">a</span><b> then</b><span style="color: navy"> {
</span>      a.value<b> as </b><span style="color: maroon">txt</span><span style="color: navy"><b> -&gt; </b></span> obs.note<b> as </b><span style="color: maroon">n</span><span style="color: navy">, </span> n.text = <span style="color: maroon">txt</span> <i>&quot;text&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span><span style="color: navy">;</span>
  <span style="color: navy">}</span> <i>&quot;narr_11348_0&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">// </span><span style="color: green">── Drug history ────────────────────────────────────────────────────────</span>
  <span style="color: navy">// </span><span style="color: green">A panel with a component per drug, plus the folic-acid question as its own</span>
  <span style="color: navy">// </span><span style="color: green">component. Not MedicationStatements: the sheet takes a drug name and a</span>
  <span style="color: navy">// </span><span style="color: green">dose-and-frequency string per row with no route and no start date, and a</span>
  <span style="color: navy">// </span><span style="color: green">MedicationStatement built from that looks reconciled and is not.</span>
  qr.item<b> as </b><span style="color: maroon">g</span><b> where </b><span style="color: navy">(</span>(linkId = 'drug-history') and item.answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span> bundle.entry<b> as </b><span style="color: maroon">entry</span><span style="color: navy">, </span> entry.resource = <b>create</b><span style="color: navy">(</span><span style="color: blue">'Observation'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">obs</span><b> then</b><span style="color: navy"> {
</span>    qr<span style="color: navy"><b> -&gt; </b></span> obs<span style="color: navy">, </span> entry<b> then </b>BuildObsBase<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">obs</span><span style="color: navy">, </span><span style="color: maroon">entry</span><span style="color: navy">)</span> <i>&quot;base&quot;</i><span style="color: navy">;</span>
    qr<span style="color: navy"><b> -&gt; </b></span>obs<b> then </b>SetSurveyCategory<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">obs</span><span style="color: navy">)</span> <i>&quot;category&quot;</i><span style="color: navy">;</span>
    g<span style="color: navy"><b> -&gt; </b></span>obs.code<b> as </b><span style="color: maroon">cc</span><b> then</b><span style="color: navy"> {
</span>      g<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>        g<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'http://loinc.org'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
        g<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'10160-0'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
        g<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'History of Medication use Narrative'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;code&quot;</i><span style="color: navy">;</span>
    g.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'drug-history/folic-acid') and answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span>obs.component<b> as </b><span style="color: maroon">comp</span><b> then</b><span style="color: navy"> {
</span>      it<span style="color: navy"><b> -&gt; </b></span>comp.code<b> as </b><span style="color: maroon">cc</span><b> then</b><span style="color: navy"> {
</span>        it<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>          it<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
          it<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'obs-folic-acid-taken-pre-conception-or-in-the-first'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
          it<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Folic acid taken pre-conception or in the first trimester'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;code&quot;</i><span style="color: navy">;</span>
      it<span style="color: navy"><b> -&gt; </b></span>comp<b> then </b>SetComponentCodedValue<span style="color: navy">(</span><span style="color: maroon">it</span><span style="color: navy">, </span><span style="color: maroon">comp</span><span style="color: navy">)</span> <i>&quot;value&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;comp_obs_folic_acid_taken_pre_conception_or_in_the_first&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">}</span> <i>&quot;drugHistoryPanel&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">// </span><span style="color: green">── The drugs themselves, one MedicationStatement per row ───────────────</span>
  <span style="color: navy">// </span><span style="color: green">Requested on review. Two things are done to keep it honest, because this</span>
  <span style="color: navy">// </span><span style="color: green">sheet is a patient-reported history and not a reconciled medication list:</span>
  <span style="color: navy">// </span><span style="color: green">`status` is 'recorded' rather than anything that implies verification, and</span>
  <span style="color: navy">// </span><span style="color: green">`informationSource` points at the patient, so a later reader can see where</span>
  <span style="color: navy">// </span><span style="color: green">the list came from. The whole line goes to medication.concept.text as the</span>
  <span style="color: navy">// </span><span style="color: green">woman reported it -- the formulary is not coded here and a guessed RxNorm</span>
  <span style="color: navy">// </span><span style="color: green">code on a drug taken in pregnancy is the wrong place to be wrong.</span>
  qr.item<b> as </b><span style="color: maroon">g</span><b> where </b><span style="color: navy">(</span>linkId = 'drug-history'<span style="color: navy">)</span><b> then</b><span style="color: navy"> {
</span>    g.item<b> as </b><span style="color: maroon">row</span><b> where </b><span style="color: navy">(</span>(linkId = 'drug-history/drug') and item.where(linkId = 'drug-history/drug/name').answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span> bundle.entry<b> as </b><span style="color: maroon">entry</span><span style="color: navy">, </span> entry.resource = <b>create</b><span style="color: navy">(</span><span style="color: blue">'MedicationStatement'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">ms</span><b> then</b><span style="color: navy"> {
</span>      qr<span style="color: navy"><b> -&gt; </b></span> ms<span style="color: navy">, </span> entry<b> then </b>BuildMedicationStatementBase<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">ms</span><span style="color: navy">, </span><span style="color: maroon">entry</span><span style="color: navy">)</span> <i>&quot;base&quot;</i><span style="color: navy">;</span>
      row<span style="color: navy"><b> -&gt; </b></span>ms.status = <span style="color: blue">'recorded'</span> <i>&quot;status&quot;</i><span style="color: navy">;</span>
      qr.encounter<b> as </b><span style="color: maroon">e</span><span style="color: navy"><b> -&gt; </b></span>ms.encounter = <span style="color: maroon">e</span><span style="color: navy">;</span>
      qr.authored<b> as </b><span style="color: maroon">t</span><span style="color: navy"><b> -&gt; </b></span>ms.dateAsserted = <span style="color: maroon">t</span> <i>&quot;dateAsserted&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>ms.informationSource = <span style="color: maroon">s</span> <i>&quot;informationSourceIsThePatient&quot;</i><span style="color: navy">;</span>
      row<span style="color: navy"><b> -&gt; </b></span>ms.category<b> as </b><span style="color: maroon">cat</span><b> then</b><span style="color: navy"> {
</span>        row<span style="color: navy"><b> -&gt; </b></span>cat.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>          row<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'http://terminology.hl7.org/CodeSystem/medication-statement-category'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
          row<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'patientspecified'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
          row<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Patient Specified'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;category&quot;</i><span style="color: navy">;</span>
      row.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>linkId = 'drug-history/drug/name'<span style="color: navy">)</span><b> then</b><span style="color: navy"> {
</span>        it.answer first<b> as </b><span style="color: maroon">a</span><b> then</b><span style="color: navy"> {
</span>          a.value<b> as </b><span style="color: maroon">txt</span><span style="color: navy"><b> -&gt; </b></span> ms.medication<b> as </b><span style="color: maroon">med</span><span style="color: navy">, </span> med.concept<b> as </b><span style="color: maroon">mc</span><span style="color: navy">, </span> mc.text = <span style="color: maroon">txt</span> <i>&quot;medicationText&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;nameRule&quot;</i><span style="color: navy">;</span>
      row.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'drug-history/drug/dose-and-frequency') and answer.value.exists()<span style="color: navy">)</span><b> then</b><span style="color: navy"> {
</span>        it.answer first<b> as </b><span style="color: maroon">a</span><b> then</b><span style="color: navy"> {
</span>          a.value<b> as </b><span style="color: maroon">txt</span><span style="color: navy"><b> -&gt; </b></span> ms.dosage<b> as </b><span style="color: maroon">dos</span><span style="color: navy">, </span> dos.text = <span style="color: maroon">txt</span> <i>&quot;dosageText&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;doseRule&quot;</i><span style="color: navy">;</span>
      row.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'drug-history/drug/dose-and-frequency') and answer.value.exists()<span style="color: navy">)</span><b> then</b><span style="color: navy"> {
</span>        it.answer first<b> as </b><span style="color: maroon">a</span><b> then</b><span style="color: navy"> {
</span>          a.value<b> as </b><span style="color: maroon">txt</span><span style="color: navy"><b> -&gt; </b></span>ms.renderedDosageInstruction = <span style="color: maroon">txt</span> <i>&quot;renderedDosage&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;renderedRule&quot;</i><span style="color: navy">;</span>
      row<span style="color: navy"><b> -&gt; </b></span> ms.note<b> as </b><span style="color: maroon">n</span><span style="color: navy">, </span> n.text = <span style="color: blue">'Reported by the mother on the maternity record. A history, not a reconciled medication list.'</span> <i>&quot;provenanceNote&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;drugStatement&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">}</span> <i>&quot;drugStatements&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">// </span><span style="color: green">── Examination on admission ────────────────────────────────────────────</span>
  qr.item<b> as </b><span style="color: maroon">eg</span><b> where </b><span style="color: navy">(</span>linkId = 'examination-on-admission'<span style="color: navy">)</span><b> then</b><span style="color: navy"> {
</span>    eg.item<b> as </b><span style="color: maroon">g</span><b> where </b><span style="color: navy">(</span>linkId = 'examination-on-admission/vitals'<span style="color: navy">)</span><b> then</b><span style="color: navy"> {
</span>      g.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'examination-on-admission/vitals/weight') and answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span> bundle.entry<b> as </b><span style="color: maroon">entry</span><span style="color: navy">, </span> entry.resource = <b>create</b><span style="color: navy">(</span><span style="color: blue">'Observation'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">obs</span><b> then</b><span style="color: navy"> {
</span>        qr<span style="color: navy"><b> -&gt; </b></span> obs<span style="color: navy">, </span> entry<b> then </b>BuildObsBase<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">obs</span><span style="color: navy">, </span><span style="color: maroon">entry</span><span style="color: navy">)</span> <i>&quot;base&quot;</i><span style="color: navy">;</span>
        qr<span style="color: navy"><b> -&gt; </b></span>obs<b> then </b>SetVitalSignsCategory<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">obs</span><span style="color: navy">)</span> <i>&quot;category&quot;</i><span style="color: navy">;</span>
        it<span style="color: navy"><b> -&gt; </b></span>obs.code<b> as </b><span style="color: maroon">cc</span><b> then</b><span style="color: navy"> {
</span>          it<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>            it<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'http://loinc.org'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
            it<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'29463-7'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
            it<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Body weight'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;code&quot;</i><span style="color: navy">;</span>
        it.answer first<b> as </b><span style="color: maroon">a</span><b> then</b><span style="color: navy"> {
</span>          a.value<b> as </b><span style="color: maroon">v</span><span style="color: navy"><b> -&gt; </b></span>obs.value = <span style="color: maroon">v</span> <i>&quot;set&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;measure_29463_7&quot;</i><span style="color: navy">;</span>
      g.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'examination-on-admission/vitals/height') and answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span> bundle.entry<b> as </b><span style="color: maroon">entry</span><span style="color: navy">, </span> entry.resource = <b>create</b><span style="color: navy">(</span><span style="color: blue">'Observation'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">obs</span><b> then</b><span style="color: navy"> {
</span>        qr<span style="color: navy"><b> -&gt; </b></span> obs<span style="color: navy">, </span> entry<b> then </b>BuildObsBase<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">obs</span><span style="color: navy">, </span><span style="color: maroon">entry</span><span style="color: navy">)</span> <i>&quot;base&quot;</i><span style="color: navy">;</span>
        qr<span style="color: navy"><b> -&gt; </b></span>obs<b> then </b>SetVitalSignsCategory<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">obs</span><span style="color: navy">)</span> <i>&quot;category&quot;</i><span style="color: navy">;</span>
        it<span style="color: navy"><b> -&gt; </b></span>obs.code<b> as </b><span style="color: maroon">cc</span><b> then</b><span style="color: navy"> {
</span>          it<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>            it<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'http://loinc.org'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
            it<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'8302-2'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
            it<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Body height'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;code&quot;</i><span style="color: navy">;</span>
        it.answer first<b> as </b><span style="color: maroon">a</span><b> then</b><span style="color: navy"> {
</span>          a.value<b> as </b><span style="color: maroon">v</span><span style="color: navy"><b> -&gt; </b></span>obs.value = <span style="color: maroon">v</span> <i>&quot;set&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;measure_8302_2&quot;</i><span style="color: navy">;</span>
      g.item<b> as </b><span style="color: maroon">bp</span><b> where </b><span style="color: navy">(</span>(linkId = 'examination-on-admission/vitals/blood-pressure') and item.answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span> bundle.entry<b> as </b><span style="color: maroon">entry</span><span style="color: navy">, </span> entry.resource = <b>create</b><span style="color: navy">(</span><span style="color: blue">'Observation'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">obs</span><b> then</b><span style="color: navy"> {
</span>        qr<span style="color: navy"><b> -&gt; </b></span> obs<span style="color: navy">, </span> entry<b> then </b>BuildObsBase<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">obs</span><span style="color: navy">, </span><span style="color: maroon">entry</span><span style="color: navy">)</span> <i>&quot;base&quot;</i><span style="color: navy">;</span>
        qr<span style="color: navy"><b> -&gt; </b></span>obs<b> then </b>SetVitalSignsCategory<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">obs</span><span style="color: navy">)</span> <i>&quot;category&quot;</i><span style="color: navy">;</span>
        bp<span style="color: navy"><b> -&gt; </b></span>obs.code<b> as </b><span style="color: maroon">cc</span><b> then</b><span style="color: navy"> {
</span>          bp<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>            bp<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'http://loinc.org'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
            bp<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'85354-9'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
            bp<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Blood pressure panel with all children optional'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;code&quot;</i><span style="color: navy">;</span>
        bp.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'examination-on-admission/vitals/blood-pressure/systolic') and answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span>obs.component<b> as </b><span style="color: maroon">comp</span><b> then</b><span style="color: navy"> {
</span>          it<span style="color: navy"><b> -&gt; </b></span>comp.code<b> as </b><span style="color: maroon">cc</span><b> then</b><span style="color: navy"> {
</span>            it<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>              it<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'http://loinc.org'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
              it<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'8480-6'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
              it<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Systolic blood pressure'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
            <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;code&quot;</i><span style="color: navy">;</span>
          it<span style="color: navy"><b> -&gt; </b></span>comp<b> then </b>SetComponentValue<span style="color: navy">(</span><span style="color: maroon">it</span><span style="color: navy">, </span><span style="color: maroon">comp</span><span style="color: navy">)</span> <i>&quot;value&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;comp_8480_6&quot;</i><span style="color: navy">;</span>
        bp.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'examination-on-admission/vitals/blood-pressure/diastolic') and answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span>obs.component<b> as </b><span style="color: maroon">comp</span><b> then</b><span style="color: navy"> {
</span>          it<span style="color: navy"><b> -&gt; </b></span>comp.code<b> as </b><span style="color: maroon">cc</span><b> then</b><span style="color: navy"> {
</span>            it<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>              it<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'http://loinc.org'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
              it<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'8462-4'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
              it<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Diastolic blood pressure'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
            <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;code&quot;</i><span style="color: navy">;</span>
          it<span style="color: navy"><b> -&gt; </b></span>comp<b> then </b>SetComponentValue<span style="color: navy">(</span><span style="color: maroon">it</span><span style="color: navy">, </span><span style="color: maroon">comp</span><span style="color: navy">)</span> <i>&quot;value&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;comp_8462_4&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;admissionBloodPressure&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;vitalsSub&quot;</i><span style="color: navy">;</span>
    eg.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'examination-on-admission/bmi') and answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span> bundle.entry<b> as </b><span style="color: maroon">entry</span><span style="color: navy">, </span> entry.resource = <b>create</b><span style="color: navy">(</span><span style="color: blue">'Observation'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">obs</span><b> then</b><span style="color: navy"> {
</span>      qr<span style="color: navy"><b> -&gt; </b></span> obs<span style="color: navy">, </span> entry<b> then </b>BuildObsBase<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">obs</span><span style="color: navy">, </span><span style="color: maroon">entry</span><span style="color: navy">)</span> <i>&quot;base&quot;</i><span style="color: navy">;</span>
      qr<span style="color: navy"><b> -&gt; </b></span>obs<b> then </b>SetVitalSignsCategory<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">obs</span><span style="color: navy">)</span> <i>&quot;category&quot;</i><span style="color: navy">;</span>
      it<span style="color: navy"><b> -&gt; </b></span>obs.code<b> as </b><span style="color: maroon">cc</span><b> then</b><span style="color: navy"> {
</span>        it<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>          it<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'http://loinc.org'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
          it<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'39156-5'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
          it<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Body mass index (BMI) [Ratio]'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;code&quot;</i><span style="color: navy">;</span>
      it.answer first<b> as </b><span style="color: maroon">a</span><b> then</b><span style="color: navy"> {
</span>        a.value<b> as </b><span style="color: maroon">v</span><span style="color: navy"><b> -&gt; </b></span>obs.value = <b>create</b><span style="color: navy">(</span><span style="color: blue">'Quantity'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">q</span><b> then</b><span style="color: navy"> {
</span>          v<span style="color: navy"><b> -&gt; </b></span>q.value = <span style="color: maroon">v</span> <i>&quot;qValue&quot;</i><span style="color: navy">;</span>
          v<span style="color: navy"><b> -&gt; </b></span>q.unit = <span style="color: blue">'kg/m2'</span> <i>&quot;qUnit&quot;</i><span style="color: navy">;</span>
          v<span style="color: navy"><b> -&gt; </b></span>q.system = <span style="color: blue">'http://unitsofmeasure.org'</span> <i>&quot;qSystem&quot;</i><span style="color: navy">;</span>
          v<span style="color: navy"><b> -&gt; </b></span>q.code = <span style="color: blue">'kg/m2'</span> <i>&quot;qCode&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;quantity&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span><span style="color: navy">;</span>
      it<span style="color: navy"><b> -&gt; </b></span> obs.note<b> as </b><span style="color: maroon">n</span><span style="color: navy">, </span> n.text = <span style="color: blue">'Derived by the client from the height and weight on this form. The unit is attached by the extraction map, because the form computes a bare number.'</span> <i>&quot;note&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;measureq_39156_5&quot;</i><span style="color: navy">;</span>
    eg.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'examination-on-admission/urinalysis') and answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span> bundle.entry<b> as </b><span style="color: maroon">entry</span><span style="color: navy">, </span> entry.resource = <b>create</b><span style="color: navy">(</span><span style="color: blue">'Observation'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">obs</span><b> then</b><span style="color: navy"> {
</span>      qr<span style="color: navy"><b> -&gt; </b></span> obs<span style="color: navy">, </span> entry<b> then </b>BuildObsBase<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">obs</span><span style="color: navy">, </span><span style="color: maroon">entry</span><span style="color: navy">)</span> <i>&quot;base&quot;</i><span style="color: navy">;</span>
      qr<span style="color: navy"><b> -&gt; </b></span>obs<b> then </b>SetLaboratoryCategory<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">obs</span><span style="color: navy">)</span> <i>&quot;category&quot;</i><span style="color: navy">;</span>
      it<span style="color: navy"><b> -&gt; </b></span>obs.code<b> as </b><span style="color: maroon">cc</span><b> then</b><span style="color: navy"> {
</span>        it<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>          it<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'http://loinc.org'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
          it<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'11502-2'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
          it<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Laboratory report'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
        it<span style="color: navy"><b> -&gt; </b></span>cc.text = <span style="color: blue">'Urinalysis on admission'</span> <i>&quot;codeText&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;code&quot;</i><span style="color: navy">;</span>
      it.answer first<b> as </b><span style="color: maroon">a</span><b> then</b><span style="color: navy"> {
</span>        a.value<b> as </b><span style="color: maroon">txt</span><span style="color: navy"><b> -&gt; </b></span> obs.note<b> as </b><span style="color: maroon">n</span><span style="color: navy">, </span> n.text = <span style="color: maroon">txt</span> <i>&quot;text&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;narr_11502_2&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">// </span><span style="color: green">The obstetric examination, as one panel. Lie, presentation, position,</span>
    <span style="color: navy">// </span><span style="color: green">station, dilation and membrane status are one assessment made at one</span>
    <span style="color: navy">// </span><span style="color: green">vaginal examination, and separating them would let a reader pair a</span>
    <span style="color: navy">// </span><span style="color: green">dilation from one examination with a station from another.</span>
    eg.item<b> as </b><span style="color: maroon">g</span><b> where </b><span style="color: navy">(</span>(linkId = 'examination-on-admission/physical') and item.answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span> bundle.entry<b> as </b><span style="color: maroon">entry</span><span style="color: navy">, </span> entry.resource = <b>create</b><span style="color: navy">(</span><span style="color: blue">'Observation'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">obs</span><b> then</b><span style="color: navy"> {
</span>      qr<span style="color: navy"><b> -&gt; </b></span> obs<span style="color: navy">, </span> entry<b> then </b>BuildObsBase<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">obs</span><span style="color: navy">, </span><span style="color: maroon">entry</span><span style="color: navy">)</span> <i>&quot;base&quot;</i><span style="color: navy">;</span>
      qr<span style="color: navy"><b> -&gt; </b></span>obs<b> then </b>SetExamCategory<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">obs</span><span style="color: navy">)</span> <i>&quot;category&quot;</i><span style="color: navy">;</span>
      g<span style="color: navy"><b> -&gt; </b></span>obs.code<b> as </b><span style="color: maroon">cc</span><b> then</b><span style="color: navy"> {
</span>        g<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>          g<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'http://loinc.org'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
          g<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'11876-0'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
          g<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Fetal presentation palpation'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
        g<span style="color: navy"><b> -&gt; </b></span>cc.text = <span style="color: blue">'Obstetric examination on admission'</span> <i>&quot;codeText&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;code&quot;</i><span style="color: navy">;</span>
      g.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'examination-on-admission/physical/lie') and answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span>obs.component<b> as </b><span style="color: maroon">comp</span><b> then</b><span style="color: navy"> {
</span>        it<span style="color: navy"><b> -&gt; </b></span>comp.code<b> as </b><span style="color: maroon">cc</span><b> then</b><span style="color: navy"> {
</span>          it<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>            it<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
            it<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'fetal-lie'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
            it<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Fetal lie'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;code&quot;</i><span style="color: navy">;</span>
        it<span style="color: navy"><b> -&gt; </b></span>comp<b> then </b>SetComponentCodedValue<span style="color: navy">(</span><span style="color: maroon">it</span><span style="color: navy">, </span><span style="color: maroon">comp</span><span style="color: navy">)</span> <i>&quot;value&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;comp_fetal_lie&quot;</i><span style="color: navy">;</span>
      g.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'examination-on-admission/physical/presentation') and answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span>obs.component<b> as </b><span style="color: maroon">comp</span><b> then</b><span style="color: navy"> {
</span>        it<span style="color: navy"><b> -&gt; </b></span>comp.code<b> as </b><span style="color: maroon">cc</span><b> then</b><span style="color: navy"> {
</span>          it<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>            it<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'http://loinc.org'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
            it<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'11876-0'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
            it<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Fetal presentation palpation'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;code&quot;</i><span style="color: navy">;</span>
        it<span style="color: navy"><b> -&gt; </b></span>comp<b> then </b>SetComponentValue<span style="color: navy">(</span><span style="color: maroon">it</span><span style="color: navy">, </span><span style="color: maroon">comp</span><span style="color: navy">)</span> <i>&quot;value&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;comp_11876_0&quot;</i><span style="color: navy">;</span>
      g.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'examination-on-admission/physical/position') and answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span>obs.component<b> as </b><span style="color: maroon">comp</span><b> then</b><span style="color: navy"> {
</span>        it<span style="color: navy"><b> -&gt; </b></span>comp.code<b> as </b><span style="color: maroon">cc</span><b> then</b><span style="color: navy"> {
</span>          it<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>            it<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
            it<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'obstetric-position'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
            it<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Position'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;code&quot;</i><span style="color: navy">;</span>
        it<span style="color: navy"><b> -&gt; </b></span>comp<b> then </b>SetComponentValue<span style="color: navy">(</span><span style="color: maroon">it</span><span style="color: navy">, </span><span style="color: maroon">comp</span><span style="color: navy">)</span> <i>&quot;value&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;comp_obstetric_position&quot;</i><span style="color: navy">;</span>
      g.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'examination-on-admission/physical/station') and answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span>obs.component<b> as </b><span style="color: maroon">comp</span><b> then</b><span style="color: navy"> {
</span>        it<span style="color: navy"><b> -&gt; </b></span>comp.code<b> as </b><span style="color: maroon">cc</span><b> then</b><span style="color: navy"> {
</span>          it<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>            it<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
            it<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'bishop-head-station'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
            it<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Head station'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;code&quot;</i><span style="color: navy">;</span>
        it<span style="color: navy"><b> -&gt; </b></span>comp<b> then </b>SetComponentValue<span style="color: navy">(</span><span style="color: maroon">it</span><span style="color: navy">, </span><span style="color: maroon">comp</span><span style="color: navy">)</span> <i>&quot;value&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;comp_bishop_head_station&quot;</i><span style="color: navy">;</span>
      g.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'examination-on-admission/physical/dilation') and answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span>obs.component<b> as </b><span style="color: maroon">comp</span><b> then</b><span style="color: navy"> {
</span>        it<span style="color: navy"><b> -&gt; </b></span>comp.code<b> as </b><span style="color: maroon">cc</span><b> then</b><span style="color: navy"> {
</span>          it<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>            it<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
            it<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'bishop-cervical-dilation'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
            it<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Cervical dilation'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;code&quot;</i><span style="color: navy">;</span>
        it<span style="color: navy"><b> -&gt; </b></span>comp<b> then </b>SetComponentValue<span style="color: navy">(</span><span style="color: maroon">it</span><span style="color: navy">, </span><span style="color: maroon">comp</span><span style="color: navy">)</span> <i>&quot;value&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;comp_bishop_cervical_dilation&quot;</i><span style="color: navy">;</span>
      g.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'examination-on-admission/physical/membranes') and answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span>obs.component<b> as </b><span style="color: maroon">comp</span><b> then</b><span style="color: navy"> {
</span>        it<span style="color: navy"><b> -&gt; </b></span>comp.code<b> as </b><span style="color: maroon">cc</span><b> then</b><span style="color: navy"> {
</span>          it<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>            it<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
            it<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'membrane-status'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
            it<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Membrane status'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;code&quot;</i><span style="color: navy">;</span>
        it<span style="color: navy"><b> -&gt; </b></span>comp<b> then </b>SetComponentCodedValue<span style="color: navy">(</span><span style="color: maroon">it</span><span style="color: navy">, </span><span style="color: maroon">comp</span><span style="color: navy">)</span> <i>&quot;value&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;comp_membrane_status&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;obstetricExaminationPanel&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">// </span><span style="color: green">The rapid assessment. The fetal heart rate is lifted out into its own</span>
    <span style="color: navy">// </span><span style="color: green">Observation as well as staying a component here: it is the single most</span>
    <span style="color: navy">// </span><span style="color: green">watched number in labour and it has to be graphable by its LOINC code.</span>
    eg.item<b> as </b><span style="color: maroon">g</span><b> where </b><span style="color: navy">(</span>(linkId = 'examination-on-admission/rapid') and item.answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span> bundle.entry<b> as </b><span style="color: maroon">entry</span><span style="color: navy">, </span> entry.resource = <b>create</b><span style="color: navy">(</span><span style="color: blue">'Observation'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">obs</span><b> then</b><span style="color: navy"> {
</span>      qr<span style="color: navy"><b> -&gt; </b></span> obs<span style="color: navy">, </span> entry<b> then </b>BuildObsBase<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">obs</span><span style="color: navy">, </span><span style="color: maroon">entry</span><span style="color: navy">)</span> <i>&quot;base&quot;</i><span style="color: navy">;</span>
      qr<span style="color: navy"><b> -&gt; </b></span>obs<b> then </b>SetExamCategory<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">obs</span><span style="color: navy">)</span> <i>&quot;category&quot;</i><span style="color: navy">;</span>
      g<span style="color: navy"><b> -&gt; </b></span>obs.code<b> as </b><span style="color: maroon">cc</span><b> then</b><span style="color: navy"> {
</span>        g<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>          g<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'http://loinc.org'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
          g<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'8716-3'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
          g<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Vital signs note'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
        g<span style="color: navy"><b> -&gt; </b></span>cc.text = <span style="color: blue">'Vital and rapid assessment on admission'</span> <i>&quot;codeText&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;code&quot;</i><span style="color: navy">;</span>
      g.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'examination-on-admission/rapid/fetal-heart-rate') and answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span>obs.component<b> as </b><span style="color: maroon">comp</span><b> then</b><span style="color: navy"> {
</span>        it<span style="color: navy"><b> -&gt; </b></span>comp.code<b> as </b><span style="color: maroon">cc</span><b> then</b><span style="color: navy"> {
</span>          it<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>            it<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'http://loinc.org'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
            it<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'55283-6'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
            it<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Fetal Heart rate'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;code&quot;</i><span style="color: navy">;</span>
        it<span style="color: navy"><b> -&gt; </b></span>comp<b> then </b>SetComponentValue<span style="color: navy">(</span><span style="color: maroon">it</span><span style="color: navy">, </span><span style="color: maroon">comp</span><span style="color: navy">)</span> <i>&quot;value&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;comp_55283_6&quot;</i><span style="color: navy">;</span>
      g.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'examination-on-admission/rapid/nst-ctg') and answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span>obs.component<b> as </b><span style="color: maroon">comp</span><b> then</b><span style="color: navy"> {
</span>        it<span style="color: navy"><b> -&gt; </b></span>comp.code<b> as </b><span style="color: maroon">cc</span><b> then</b><span style="color: navy"> {
</span>          it<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>            it<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
            it<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'obs-nst-or-ctg'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
            it<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'NST or CTG'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;code&quot;</i><span style="color: navy">;</span>
        it<span style="color: navy"><b> -&gt; </b></span>comp<b> then </b>SetComponentValue<span style="color: navy">(</span><span style="color: maroon">it</span><span style="color: navy">, </span><span style="color: maroon">comp</span><span style="color: navy">)</span> <i>&quot;value&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;comp_obs_nst_or_ctg&quot;</i><span style="color: navy">;</span>
      g.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'examination-on-admission/rapid/general') and answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span>obs.component<b> as </b><span style="color: maroon">comp</span><b> then</b><span style="color: navy"> {
</span>        it<span style="color: navy"><b> -&gt; </b></span>comp.code<b> as </b><span style="color: maroon">cc</span><b> then</b><span style="color: navy"> {
</span>          it<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>            it<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
            it<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'obs-general'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
            it<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'General'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;code&quot;</i><span style="color: navy">;</span>
        it<span style="color: navy"><b> -&gt; </b></span>comp<b> then </b>SetComponentValue<span style="color: navy">(</span><span style="color: maroon">it</span><span style="color: navy">, </span><span style="color: maroon">comp</span><span style="color: navy">)</span> <i>&quot;value&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;comp_obs_general&quot;</i><span style="color: navy">;</span>
      g.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'examination-on-admission/rapid/appearance') and answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span>obs.component<b> as </b><span style="color: maroon">comp</span><b> then</b><span style="color: navy"> {
</span>        it<span style="color: navy"><b> -&gt; </b></span>comp.code<b> as </b><span style="color: maroon">cc</span><b> then</b><span style="color: navy"> {
</span>          it<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>            it<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
            it<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'obs-appearance'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
            it<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Appearance'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;code&quot;</i><span style="color: navy">;</span>
        it<span style="color: navy"><b> -&gt; </b></span>comp<b> then </b>SetComponentValue<span style="color: navy">(</span><span style="color: maroon">it</span><span style="color: navy">, </span><span style="color: maroon">comp</span><span style="color: navy">)</span> <i>&quot;value&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;comp_obs_appearance&quot;</i><span style="color: navy">;</span>
      g.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'examination-on-admission/rapid/jaundice-pallor') and answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span>obs.component<b> as </b><span style="color: maroon">comp</span><b> then</b><span style="color: navy"> {
</span>        it<span style="color: navy"><b> -&gt; </b></span>comp.code<b> as </b><span style="color: maroon">cc</span><b> then</b><span style="color: navy"> {
</span>          it<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>            it<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
            it<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'obs-jaundice-or-pallor'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
            it<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Jaundice or pallor'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;code&quot;</i><span style="color: navy">;</span>
        it<span style="color: navy"><b> -&gt; </b></span>comp<b> then </b>SetComponentValue<span style="color: navy">(</span><span style="color: maroon">it</span><span style="color: navy">, </span><span style="color: maroon">comp</span><span style="color: navy">)</span> <i>&quot;value&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;comp_obs_jaundice_or_pallor&quot;</i><span style="color: navy">;</span>
      g.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'examination-on-admission/rapid/contractions') and answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span>obs.component<b> as </b><span style="color: maroon">comp</span><b> then</b><span style="color: navy"> {
</span>        it<span style="color: navy"><b> -&gt; </b></span>comp.code<b> as </b><span style="color: maroon">cc</span><b> then</b><span style="color: navy"> {
</span>          it<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>            it<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
            it<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'obs-contractions'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
            it<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Contractions'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;code&quot;</i><span style="color: navy">;</span>
        it<span style="color: navy"><b> -&gt; </b></span>comp<b> then </b>SetComponentValue<span style="color: navy">(</span><span style="color: maroon">it</span><span style="color: navy">, </span><span style="color: maroon">comp</span><span style="color: navy">)</span> <i>&quot;value&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;comp_obs_contractions&quot;</i><span style="color: navy">;</span>
      g.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'examination-on-admission/rapid/bleeding-tenderness') and answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span>obs.component<b> as </b><span style="color: maroon">comp</span><b> then</b><span style="color: navy"> {
</span>        it<span style="color: navy"><b> -&gt; </b></span>comp.code<b> as </b><span style="color: maroon">cc</span><b> then</b><span style="color: navy"> {
</span>          it<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>            it<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
            it<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'obs-bleeding-or-tenderness'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
            it<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Bleeding or tenderness'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;code&quot;</i><span style="color: navy">;</span>
        it<span style="color: navy"><b> -&gt; </b></span>comp<b> then </b>SetComponentValue<span style="color: navy">(</span><span style="color: maroon">it</span><span style="color: navy">, </span><span style="color: maroon">comp</span><span style="color: navy">)</span> <i>&quot;value&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;comp_obs_bleeding_or_tenderness&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;rapidAssessmentPanel&quot;</i><span style="color: navy">;</span>
    eg.item<b> as </b><span style="color: maroon">g</span><b> where </b><span style="color: navy">(</span>linkId = 'examination-on-admission/rapid'<span style="color: navy">)</span><b> then</b><span style="color: navy"> {
</span>      g.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'examination-on-admission/rapid/fetal-heart-rate') and answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span> bundle.entry<b> as </b><span style="color: maroon">entry</span><span style="color: navy">, </span> entry.resource = <b>create</b><span style="color: navy">(</span><span style="color: blue">'Observation'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">obs</span><b> then</b><span style="color: navy"> {
</span>        qr<span style="color: navy"><b> -&gt; </b></span> obs<span style="color: navy">, </span> entry<b> then </b>BuildObsBase<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">obs</span><span style="color: navy">, </span><span style="color: maroon">entry</span><span style="color: navy">)</span> <i>&quot;base&quot;</i><span style="color: navy">;</span>
        qr<span style="color: navy"><b> -&gt; </b></span>obs<b> then </b>SetVitalSignsCategory<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">obs</span><span style="color: navy">)</span> <i>&quot;category&quot;</i><span style="color: navy">;</span>
        it<span style="color: navy"><b> -&gt; </b></span>obs.code<b> as </b><span style="color: maroon">cc</span><b> then</b><span style="color: navy"> {
</span>          it<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>            it<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'http://loinc.org'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
            it<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'55283-6'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
            it<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Fetal Heart rate'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;code&quot;</i><span style="color: navy">;</span>
        it.answer first<b> as </b><span style="color: maroon">a</span><b> then</b><span style="color: navy"> {
</span>          a.value<b> as </b><span style="color: maroon">v</span><span style="color: navy"><b> -&gt; </b></span>obs.value = <span style="color: maroon">v</span> <i>&quot;set&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;measure_55283_6&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;fetalHeartRateGroup&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">}</span> <i>&quot;examinationGroup&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">// </span><span style="color: green">── Investigations on admission ─────────────────────────────────────────</span>
  <span style="color: navy">// </span><span style="color: green">A laboratory panel. Blood group and rhesus factor in particular belong on</span>
  <span style="color: navy">// </span><span style="color: green">the record and not only in the lab: a rhesus-negative woman needs anti-D,</span>
  <span style="color: navy">// </span><span style="color: green">and the decision is made on the ward.</span>
  qr.item<b> as </b><span style="color: maroon">g</span><b> where </b><span style="color: navy">(</span>(linkId = 'investigations-on-admission') and item.answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span> bundle.entry<b> as </b><span style="color: maroon">entry</span><span style="color: navy">, </span> entry.resource = <b>create</b><span style="color: navy">(</span><span style="color: blue">'Observation'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">obs</span><b> then</b><span style="color: navy"> {
</span>    qr<span style="color: navy"><b> -&gt; </b></span> obs<span style="color: navy">, </span> entry<b> then </b>BuildObsBase<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">obs</span><span style="color: navy">, </span><span style="color: maroon">entry</span><span style="color: navy">)</span> <i>&quot;base&quot;</i><span style="color: navy">;</span>
    qr<span style="color: navy"><b> -&gt; </b></span>obs<b> then </b>SetLaboratoryCategory<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">obs</span><span style="color: navy">)</span> <i>&quot;category&quot;</i><span style="color: navy">;</span>
    g<span style="color: navy"><b> -&gt; </b></span>obs.code<b> as </b><span style="color: maroon">cc</span><b> then</b><span style="color: navy"> {
</span>      g<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>        g<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'http://loinc.org'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
        g<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'11502-2'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
        g<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Laboratory report'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
      g<span style="color: navy"><b> -&gt; </b></span>cc.text = <span style="color: blue">'Investigations on admission'</span> <i>&quot;codeText&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;code&quot;</i><span style="color: navy">;</span>
    g.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'investigations-on-admission/blood-group') and answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span>obs.component<b> as </b><span style="color: maroon">comp</span><b> then</b><span style="color: navy"> {
</span>      it<span style="color: navy"><b> -&gt; </b></span>comp.code<b> as </b><span style="color: maroon">cc</span><b> then</b><span style="color: navy"> {
</span>        it<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>          it<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'http://loinc.org'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
          it<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'883-9'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
          it<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'ABO group [Type] in Blood'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;code&quot;</i><span style="color: navy">;</span>
      it<span style="color: navy"><b> -&gt; </b></span>comp<b> then </b>SetComponentValue<span style="color: navy">(</span><span style="color: maroon">it</span><span style="color: navy">, </span><span style="color: maroon">comp</span><span style="color: navy">)</span> <i>&quot;value&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;comp_883_9&quot;</i><span style="color: navy">;</span>
    g.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'investigations-on-admission/rhesus-factor') and answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span>obs.component<b> as </b><span style="color: maroon">comp</span><b> then</b><span style="color: navy"> {
</span>      it<span style="color: navy"><b> -&gt; </b></span>comp.code<b> as </b><span style="color: maroon">cc</span><b> then</b><span style="color: navy"> {
</span>        it<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>          it<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'http://loinc.org'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
          it<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'10331-7'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
          it<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Rh [Type] in Blood'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;code&quot;</i><span style="color: navy">;</span>
      it<span style="color: navy"><b> -&gt; </b></span>comp<b> then </b>SetComponentValue<span style="color: navy">(</span><span style="color: maroon">it</span><span style="color: navy">, </span><span style="color: maroon">comp</span><span style="color: navy">)</span> <i>&quot;value&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;comp_10331_7&quot;</i><span style="color: navy">;</span>
    g.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'investigations-on-admission/pmtct') and answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span>obs.component<b> as </b><span style="color: maroon">comp</span><b> then</b><span style="color: navy"> {
</span>      it<span style="color: navy"><b> -&gt; </b></span>comp.code<b> as </b><span style="color: maroon">cc</span><b> then</b><span style="color: navy"> {
</span>        it<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>          it<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
          it<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'maternal-pmtct'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
          it<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'PMTCT'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;code&quot;</i><span style="color: navy">;</span>
      it<span style="color: navy"><b> -&gt; </b></span>comp<b> then </b>SetComponentCodedValue<span style="color: navy">(</span><span style="color: maroon">it</span><span style="color: navy">, </span><span style="color: maroon">comp</span><span style="color: navy">)</span> <i>&quot;value&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;comp_maternal_pmtct&quot;</i><span style="color: navy">;</span>
    g.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'investigations-on-admission/other') and answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span>obs.component<b> as </b><span style="color: maroon">comp</span><b> then</b><span style="color: navy"> {
</span>      it<span style="color: navy"><b> -&gt; </b></span>comp.code<b> as </b><span style="color: maroon">cc</span><b> then</b><span style="color: navy"> {
</span>        it<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>          it<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
          it<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'obs-other-investigation'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
          it<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Other investigation'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;code&quot;</i><span style="color: navy">;</span>
      it<span style="color: navy"><b> -&gt; </b></span>comp<b> then </b>SetComponentValue<span style="color: navy">(</span><span style="color: maroon">it</span><span style="color: navy">, </span><span style="color: maroon">comp</span><span style="color: navy">)</span> <i>&quot;value&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;comp_obs_other_investigation&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">}</span> <i>&quot;investigationsPanel&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">// </span><span style="color: green">── Diagnoses ───────────────────────────────────────────────────────────</span>
  <span style="color: navy">// </span><span style="color: green">A Condition per provisional and per differential. The differentials carry</span>
  <span style="color: navy">// </span><span style="color: green">`verificationStatus = 'differential'`, which is exactly what that code is</span>
  <span style="color: navy">// </span><span style="color: green">for, so a differential can never be read as a made diagnosis.</span>
  qr.item<b> as </b><span style="color: maroon">g</span><b> where </b><span style="color: navy">(</span>linkId = 'diagnosis'<span style="color: navy">)</span><b> then</b><span style="color: navy"> {
</span>    g.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>linkId = 'diagnosis/provisional'<span style="color: navy">)</span><b> then</b><span style="color: navy"> {
</span>      it.answer<b> as </b><span style="color: maroon">a</span><span style="color: navy"><b> -&gt; </b></span> bundle.entry<b> as </b><span style="color: maroon">entry</span><span style="color: navy">, </span> entry.resource = <b>create</b><span style="color: navy">(</span><span style="color: blue">'Condition'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">cond</span><b> then</b><span style="color: navy"> {
</span>        qr<span style="color: navy"><b> -&gt; </b></span> cond<span style="color: navy">, </span> entry<b> then </b>BuildConditionBase<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">cond</span><span style="color: navy">, </span><span style="color: maroon">entry</span><span style="color: navy">)</span> <i>&quot;base&quot;</i><span style="color: navy">;</span>
        a<span style="color: navy"><b> -&gt; </b></span>cond.clinicalStatus<b> as </b><span style="color: maroon">cs</span><b> then</b><span style="color: navy"> {
</span>          a<span style="color: navy"><b> -&gt; </b></span>cs.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>            a<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'http://terminology.hl7.org/CodeSystem/condition-clinical'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
            a<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'active'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
            a<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Active'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;clinicalStatus&quot;</i><span style="color: navy">;</span>
        a<span style="color: navy"><b> -&gt; </b></span>cond.verificationStatus<b> as </b><span style="color: maroon">vs</span><b> then</b><span style="color: navy"> {
</span>          a<span style="color: navy"><b> -&gt; </b></span>vs.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>            a<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'http://terminology.hl7.org/CodeSystem/condition-ver-status'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
            a<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'provisional'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
            a<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Provisional'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;verificationStatus&quot;</i><span style="color: navy">;</span>
        a<span style="color: navy"><b> -&gt; </b></span>cond.category<b> as </b><span style="color: maroon">cat</span><b> then</b><span style="color: navy"> {
</span>          a<span style="color: navy"><b> -&gt; </b></span>cat.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>            a<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'http://terminology.hl7.org/CodeSystem/condition-category'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
            a<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'encounter-diagnosis'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
            a<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Encounter Diagnosis'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;category&quot;</i><span style="color: navy">;</span>
        a.value<b> as </b><span style="color: maroon">txt</span><span style="color: navy"><b> -&gt; </b></span> cond.code<b> as </b><span style="color: maroon">cc</span><span style="color: navy">, </span> cc.text = <span style="color: maroon">txt</span> <i>&quot;codeText&quot;</i><span style="color: navy">;</span>
        qr.authored<b> as </b><span style="color: maroon">t</span><span style="color: navy"><b> -&gt; </b></span>cond.recordedDate = <span style="color: maroon">t</span> <i>&quot;recordedDate&quot;</i><span style="color: navy">;</span>
        qr.encounter<b> as </b><span style="color: maroon">e</span><span style="color: navy"><b> -&gt; </b></span>cond.encounter = <span style="color: maroon">e</span><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;createProvisional&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;provisionalDiagnoses&quot;</i><span style="color: navy">;</span>
    g.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>linkId = 'diagnosis/differential'<span style="color: navy">)</span><b> then</b><span style="color: navy"> {
</span>      it.answer<b> as </b><span style="color: maroon">a</span><span style="color: navy"><b> -&gt; </b></span> bundle.entry<b> as </b><span style="color: maroon">entry</span><span style="color: navy">, </span> entry.resource = <b>create</b><span style="color: navy">(</span><span style="color: blue">'Condition'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">cond</span><b> then</b><span style="color: navy"> {
</span>        qr<span style="color: navy"><b> -&gt; </b></span> cond<span style="color: navy">, </span> entry<b> then </b>BuildConditionBase<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">cond</span><span style="color: navy">, </span><span style="color: maroon">entry</span><span style="color: navy">)</span> <i>&quot;base&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">// </span><span style="color: green">clinicalStatus is 1..1 on R5 Condition, differential or not -- the</span>
        <span style="color: navy">// </span><span style="color: green">validator rejects it outright: &quot;minimum required = 1, but only found</span>
        <span style="color: navy">// </span><span style="color: green">0&quot;. A differential under active consideration is an active problem;</span>
        <span style="color: navy">// </span><span style="color: green">what marks it as unconfirmed is verificationStatus below.</span>
        a<span style="color: navy"><b> -&gt; </b></span>cond.clinicalStatus<b> as </b><span style="color: maroon">cs</span><b> then</b><span style="color: navy"> {
</span>          a<span style="color: navy"><b> -&gt; </b></span>cs.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>            a<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'http://terminology.hl7.org/CodeSystem/condition-clinical'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
            a<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'active'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
            a<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Active'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;clinicalStatus&quot;</i><span style="color: navy">;</span>
        a<span style="color: navy"><b> -&gt; </b></span>cond.verificationStatus<b> as </b><span style="color: maroon">vs</span><b> then</b><span style="color: navy"> {
</span>          a<span style="color: navy"><b> -&gt; </b></span>vs.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>            a<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'http://terminology.hl7.org/CodeSystem/condition-ver-status'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
            a<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'differential'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
            a<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Differential'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;verificationStatus&quot;</i><span style="color: navy">;</span>
        a<span style="color: navy"><b> -&gt; </b></span>cond.category<b> as </b><span style="color: maroon">cat</span><b> then</b><span style="color: navy"> {
</span>          a<span style="color: navy"><b> -&gt; </b></span>cat.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>            a<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'http://terminology.hl7.org/CodeSystem/condition-category'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
            a<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'encounter-diagnosis'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
            a<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Encounter Diagnosis'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;category&quot;</i><span style="color: navy">;</span>
        a.value<b> as </b><span style="color: maroon">txt</span><span style="color: navy"><b> -&gt; </b></span> cond.code<b> as </b><span style="color: maroon">cc</span><span style="color: navy">, </span> cc.text = <span style="color: maroon">txt</span> <i>&quot;codeText&quot;</i><span style="color: navy">;</span>
        qr.authored<b> as </b><span style="color: maroon">t</span><span style="color: navy"><b> -&gt; </b></span>cond.recordedDate = <span style="color: maroon">t</span> <i>&quot;recordedDate&quot;</i><span style="color: navy">;</span>
        qr.encounter<b> as </b><span style="color: maroon">e</span><span style="color: navy"><b> -&gt; </b></span>cond.encounter = <span style="color: maroon">e</span><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;createDifferential&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;differentialDiagnoses&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">}</span> <i>&quot;diagnosisGroup&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">// </span><span style="color: green">── The delivery, as a Procedure ────────────────────────────────────────</span>
  <span style="color: navy">// </span><span style="color: green">Coded by its mode: SNOMED 11466000 for a caesarean, 177184002 for a normal</span>
  <span style="color: navy">// </span><span style="color: green">delivery, both checked against tx.fhir.org. The two are separated on the</span>
  <span style="color: navy">// </span><span style="color: green">code rather than folded into one &quot;delivery&quot; concept, because whether a</span>
  <span style="color: navy">// </span><span style="color: green">woman has a uterine scar governs every pregnancy she has after this one.</span>
  <span style="color: navy">// </span><span style="color: green">Guarded on the delivery date and time being recorded: that is what says a</span>
  <span style="color: navy">// </span><span style="color: green">delivery happened, as against a maternity record filled in on admission</span>
  <span style="color: navy">// </span><span style="color: green">for a woman still in labour.</span>
  qr.item<b> as </b><span style="color: maroon">lg</span><b> where </b><span style="color: navy">(</span>linkId = 'labour-report'<span style="color: navy">)</span><b> then</b><span style="color: navy"> {
</span>    lg.item<b> as </b><span style="color: maroon">g</span><b> where </b><span style="color: navy">(</span>(linkId = 'labour-report/third-stage') and item.where(linkId = 'labour-report/third-stage/delivery-datetime').answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span> bundle.entry<b> as </b><span style="color: maroon">entry</span><span style="color: navy">, </span> entry.resource = <b>create</b><span style="color: navy">(</span><span style="color: blue">'Procedure'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">proc</span><b> then</b><span style="color: navy"> {
</span>      qr<span style="color: navy"><b> -&gt; </b></span> proc<span style="color: navy">, </span> entry<b> then </b>BuildProcedureBase<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">proc</span><span style="color: navy">, </span><span style="color: maroon">entry</span><span style="color: navy">)</span> <i>&quot;base&quot;</i><span style="color: navy">;</span>
      g<span style="color: navy"><b> -&gt; </b></span>proc.status = <span style="color: blue">'completed'</span> <i>&quot;status&quot;</i><span style="color: navy">;</span>
      qr.encounter<b> as </b><span style="color: maroon">e</span><span style="color: navy"><b> -&gt; </b></span>proc.encounter = <span style="color: maroon">e</span><span style="color: navy">;</span>
      g.item<b> as </b><span style="color: maroon">dt</span><b> where </b><span style="color: navy">(</span>linkId = 'labour-report/third-stage/delivery-datetime'<span style="color: navy">)</span><b> then</b><span style="color: navy"> {
</span>        dt.answer first<b> as </b><span style="color: maroon">a</span><b> then</b><span style="color: navy"> {
</span>          a.value<b> as </b><span style="color: maroon">t</span><span style="color: navy"><b> -&gt; </b></span>proc.occurrence = <span style="color: maroon">t</span> <i>&quot;occurrence&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;deliveryTimeRule&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">// </span><span style="color: green">The mode decides the code. Two rules, mutually exclusive on the answer.</span>
      lg.item<b> as </b><span style="color: maroon">sg</span><b> where </b><span style="color: navy">(</span>linkId = 'labour-report/second-stage'<span style="color: navy">)</span><b> then</b><span style="color: navy"> {
</span>        sg.item<b> as </b><span style="color: maroon">md</span><b> where </b><span style="color: navy">(</span>(linkId = 'labour-report/second-stage/mode-of-delivery') and (answer.value.ofType(Coding).code = 'delivery-caesarean')<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span>proc.code<b> as </b><span style="color: maroon">cc</span><b> then</b><span style="color: navy"> {
</span>          md<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>            md<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'http://snomed.info/sct'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
            md<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'11466000'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
            md<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Cesarean section'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;caesareanCode&quot;</i><span style="color: navy">;</span>
        sg.item<b> as </b><span style="color: maroon">md</span><b> where </b><span style="color: navy">(</span>(linkId = 'labour-report/second-stage/mode-of-delivery') and (answer.value.ofType(Coding).code != 'delivery-caesarean')<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span>proc.code<b> as </b><span style="color: maroon">cc</span><b> then</b><span style="color: navy"> {
</span>          md<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>            md<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'http://snomed.info/sct'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
            md<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'177184002'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
            md<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Normal delivery procedure'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
          md.answer first<b> as </b><span style="color: maroon">a</span><b> then</b><span style="color: navy"> {
</span>            a.value<b> as </b><span style="color: maroon">cv</span><b> then</b><span style="color: navy"> {
</span>              cv.display<b> as </b><span style="color: maroon">d</span><span style="color: navy"><b> -&gt; </b></span>cc.text = <span style="color: maroon">d</span> <i>&quot;modeText&quot;</i><span style="color: navy">;</span>
            <span style="color: navy">}</span> <i>&quot;display&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;modeDisplay&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;vaginalCode&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;secondStageGroup&quot;</i><span style="color: navy">;</span>
      g.item<b> as </b><span style="color: maroon">db</span><b> where </b><span style="color: navy">(</span>(linkId = 'labour-report/third-stage/delivered-by') and answer.value.exists()<span style="color: navy">)</span><b> then</b><span style="color: navy"> {
</span>        db.answer first<b> as </b><span style="color: maroon">a</span><b> then</b><span style="color: navy"> {
</span>          a.value<b> as </b><span style="color: maroon">ref</span><span style="color: navy"><b> -&gt; </b></span> proc.performer<b> as </b><span style="color: maroon">p</span><span style="color: navy">, </span> p.actor = <span style="color: maroon">ref</span> <i>&quot;deliveredBy&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;deliveredByRule&quot;</i><span style="color: navy">;</span>
      g.item<b> as </b><span style="color: maroon">rb</span><b> where </b><span style="color: navy">(</span>(linkId = 'labour-report/third-stage/baby-received-by') and answer.value.exists()<span style="color: navy">)</span><b> then</b><span style="color: navy"> {
</span>        rb.answer first<b> as </b><span style="color: maroon">a</span><b> then</b><span style="color: navy"> {
</span>          a.value<b> as </b><span style="color: maroon">ref</span><span style="color: navy"><b> -&gt; </b></span> proc.performer<b> as </b><span style="color: maroon">p</span><span style="color: navy">, </span> p.actor = <span style="color: maroon">ref</span> <i>&quot;babyReceivedBy&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;babyReceivedByRule&quot;</i><span style="color: navy">;</span>
      g.item<b> as </b><span style="color: maroon">pc</span><b> where </b><span style="color: navy">(</span>(linkId = 'labour-report/third-stage/placenta') and (answer.value.ofType(Coding).code = 'placenta-incomplete')<span style="color: navy">)</span><b> then</b><span style="color: navy"> {
</span>        pc<span style="color: navy"><b> -&gt; </b></span> proc.complication<b> as </b><span style="color: maroon">cmp</span><span style="color: navy">, </span> cmp.concept<b> as </b><span style="color: maroon">cpc</span><span style="color: navy">, </span> cpc.text = <span style="color: blue">'Placenta or membranes incomplete — uterine exploration required'</span> <i>&quot;incompletePlacenta&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;placentaComplicationRule&quot;</i><span style="color: navy">;</span>
      g.item<b> as </b><span style="color: maroon">po</span><b> where </b><span style="color: navy">(</span>(linkId = 'labour-report/third-stage/perineum') and (answer.value.ofType(Coding).code = 'perineum-tear')<span style="color: navy">)</span><b> then</b><span style="color: navy"> {
</span>        po<span style="color: navy"><b> -&gt; </b></span> proc.complication<b> as </b><span style="color: maroon">cmp</span><span style="color: navy">, </span> cmp.concept<b> as </b><span style="color: maroon">cpc</span><span style="color: navy">, </span> cpc.text = <span style="color: blue">'Perineal tear'</span> <i>&quot;perinealTear&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;perinealTearRule&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;deliveryProcedure&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">// </span><span style="color: green">── The stage durations ───────────────────────────────────────────────</span>
    lg.item<b> as </b><span style="color: maroon">g</span><b> where </b><span style="color: navy">(</span>linkId = 'labour-report/first-stage'<span style="color: navy">)</span><b> then</b><span style="color: navy"> {
</span>      g.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'labour-report/first-stage/duration') and answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span> bundle.entry<b> as </b><span style="color: maroon">entry</span><span style="color: navy">, </span> entry.resource = <b>create</b><span style="color: navy">(</span><span style="color: blue">'Observation'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">obs</span><b> then</b><span style="color: navy"> {
</span>        qr<span style="color: navy"><b> -&gt; </b></span> obs<span style="color: navy">, </span> entry<b> then </b>BuildObsBase<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">obs</span><span style="color: navy">, </span><span style="color: maroon">entry</span><span style="color: navy">)</span> <i>&quot;base&quot;</i><span style="color: navy">;</span>
        qr<span style="color: navy"><b> -&gt; </b></span>obs<b> then </b>SetProcedureCategory<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">obs</span><span style="color: navy">)</span> <i>&quot;category&quot;</i><span style="color: navy">;</span>
        it<span style="color: navy"><b> -&gt; </b></span>obs.code<b> as </b><span style="color: maroon">cc</span><b> then</b><span style="color: navy"> {
</span>          it<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>            it<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
            it<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'obs-duration-of-the-first-stage-of-labour'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
            it<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Duration of the first stage of labour'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;code&quot;</i><span style="color: navy">;</span>
        it.answer first<b> as </b><span style="color: maroon">a</span><b> then</b><span style="color: navy"> {
</span>          a.value<b> as </b><span style="color: maroon">v</span><span style="color: navy"><b> -&gt; </b></span>obs.value = <span style="color: maroon">v</span> <i>&quot;set&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;measure_labour_stage_duration2&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;stageDuration&quot;</i><span style="color: navy">;</span>
    lg.item<b> as </b><span style="color: maroon">g</span><b> where </b><span style="color: navy">(</span>linkId = 'labour-report/second-stage'<span style="color: navy">)</span><b> then</b><span style="color: navy"> {
</span>      g.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'labour-report/second-stage/duration') and answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span> bundle.entry<b> as </b><span style="color: maroon">entry</span><span style="color: navy">, </span> entry.resource = <b>create</b><span style="color: navy">(</span><span style="color: blue">'Observation'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">obs</span><b> then</b><span style="color: navy"> {
</span>        qr<span style="color: navy"><b> -&gt; </b></span> obs<span style="color: navy">, </span> entry<b> then </b>BuildObsBase<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">obs</span><span style="color: navy">, </span><span style="color: maroon">entry</span><span style="color: navy">)</span> <i>&quot;base&quot;</i><span style="color: navy">;</span>
        qr<span style="color: navy"><b> -&gt; </b></span>obs<b> then </b>SetProcedureCategory<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">obs</span><span style="color: navy">)</span> <i>&quot;category&quot;</i><span style="color: navy">;</span>
        it<span style="color: navy"><b> -&gt; </b></span>obs.code<b> as </b><span style="color: maroon">cc</span><b> then</b><span style="color: navy"> {
</span>          it<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>            it<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
            it<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'obs-duration-of-the-second-stage-of-labour'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
            it<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Duration of the second stage of labour'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;code&quot;</i><span style="color: navy">;</span>
        it.answer first<b> as </b><span style="color: maroon">a</span><b> then</b><span style="color: navy"> {
</span>          a.value<b> as </b><span style="color: maroon">v</span><span style="color: navy"><b> -&gt; </b></span>obs.value = <span style="color: maroon">v</span> <i>&quot;set&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;measure_labour_stage_duration3&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;stageDuration2&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">// </span><span style="color: green">── The third-stage findings ──────────────────────────────────────────</span>
    <span style="color: navy">// </span><span style="color: green">Blood loss on its own, because a postpartum haemorrhage audit filters on</span>
    <span style="color: navy">// </span><span style="color: green">it and the figure has to be findable by its LOINC code.</span>
    lg.item<b> as </b><span style="color: maroon">g</span><b> where </b><span style="color: navy">(</span>linkId = 'labour-report/third-stage'<span style="color: navy">)</span><b> then</b><span style="color: navy"> {
</span>      g.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'labour-report/third-stage/blood-loss') and answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span> bundle.entry<b> as </b><span style="color: maroon">entry</span><span style="color: navy">, </span> entry.resource = <b>create</b><span style="color: navy">(</span><span style="color: blue">'Observation'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">obs</span><b> then</b><span style="color: navy"> {
</span>        qr<span style="color: navy"><b> -&gt; </b></span> obs<span style="color: navy">, </span> entry<b> then </b>BuildObsBase<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">obs</span><span style="color: navy">, </span><span style="color: maroon">entry</span><span style="color: navy">)</span> <i>&quot;base&quot;</i><span style="color: navy">;</span>
        qr<span style="color: navy"><b> -&gt; </b></span>obs<b> then </b>SetProcedureCategory<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">obs</span><span style="color: navy">)</span> <i>&quot;category&quot;</i><span style="color: navy">;</span>
        it<span style="color: navy"><b> -&gt; </b></span>obs.code<b> as </b><span style="color: maroon">cc</span><b> then</b><span style="color: navy"> {
</span>          it<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>            it<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'http://loinc.org'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
            it<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'8717-1'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
            it<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Surgical operation note estimated blood loss [Volume]'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;code&quot;</i><span style="color: navy">;</span>
        it.answer first<b> as </b><span style="color: maroon">a</span><b> then</b><span style="color: navy"> {
</span>          a.value<b> as </b><span style="color: maroon">v</span><span style="color: navy"><b> -&gt; </b></span>obs.value = <span style="color: maroon">v</span> <i>&quot;set&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span><span style="color: navy">;</span>
        it<span style="color: navy"><b> -&gt; </b></span> obs.note<b> as </b><span style="color: maroon">n</span><span style="color: navy">, </span> n.text = <span style="color: blue">'An estimate made at delivery, not a measured volume.'</span> <i>&quot;note&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;measure_8717_1&quot;</i><span style="color: navy">;</span>
      g.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'labour-report/third-stage/placenta-weight') and answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span> bundle.entry<b> as </b><span style="color: maroon">entry</span><span style="color: navy">, </span> entry.resource = <b>create</b><span style="color: navy">(</span><span style="color: blue">'Observation'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">obs</span><b> then</b><span style="color: navy"> {
</span>        qr<span style="color: navy"><b> -&gt; </b></span> obs<span style="color: navy">, </span> entry<b> then </b>BuildObsBase<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">obs</span><span style="color: navy">, </span><span style="color: maroon">entry</span><span style="color: navy">)</span> <i>&quot;base&quot;</i><span style="color: navy">;</span>
        qr<span style="color: navy"><b> -&gt; </b></span>obs<b> then </b>SetProcedureCategory<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">obs</span><span style="color: navy">)</span> <i>&quot;category&quot;</i><span style="color: navy">;</span>
        it<span style="color: navy"><b> -&gt; </b></span>obs.code<b> as </b><span style="color: maroon">cc</span><b> then</b><span style="color: navy"> {
</span>          it<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>            it<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
            it<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'obstetric-placenta-weight'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
            it<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Placenta weight'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;code&quot;</i><span style="color: navy">;</span>
        it.answer first<b> as </b><span style="color: maroon">a</span><b> then</b><span style="color: navy"> {
</span>          a.value<b> as </b><span style="color: maroon">v</span><span style="color: navy"><b> -&gt; </b></span>obs.value = <span style="color: maroon">v</span> <i>&quot;set&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;measure_placenta_completeness&quot;</i><span style="color: navy">;</span>
      g.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'labour-report/third-stage/placenta') and answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span> bundle.entry<b> as </b><span style="color: maroon">entry</span><span style="color: navy">, </span> entry.resource = <b>create</b><span style="color: navy">(</span><span style="color: blue">'Observation'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">obs</span><b> then</b><span style="color: navy"> {
</span>        qr<span style="color: navy"><b> -&gt; </b></span> obs<span style="color: navy">, </span> entry<b> then </b>BuildObsBase<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">obs</span><span style="color: navy">, </span><span style="color: maroon">entry</span><span style="color: navy">)</span> <i>&quot;base&quot;</i><span style="color: navy">;</span>
        qr<span style="color: navy"><b> -&gt; </b></span>obs<b> then </b>SetExamCategory<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">obs</span><span style="color: navy">)</span> <i>&quot;category&quot;</i><span style="color: navy">;</span>
        it<span style="color: navy"><b> -&gt; </b></span>obs.code<b> as </b><span style="color: maroon">cc</span><b> then</b><span style="color: navy"> {
</span>          it<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>            it<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
            it<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'placenta-completeness'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
            it<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Placenta and membrane completeness'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;code&quot;</i><span style="color: navy">;</span>
        it.answer first<b> as </b><span style="color: maroon">a</span><b> then</b><span style="color: navy"> {
</span>          a.value<b> as </b><span style="color: maroon">cv</span><span style="color: navy"><b> -&gt; </b></span>obs.value = <b>create</b><span style="color: navy">(</span><span style="color: blue">'CodeableConcept'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">cc</span><b> then</b><span style="color: navy"> {
</span>            cv<span style="color: navy"><b> -&gt; </b></span>cc.coding = <span style="color: maroon">cv</span> <i>&quot;valueCoding&quot;</i><span style="color: navy">;</span>
            cv.display<b> as </b><span style="color: maroon">d</span><span style="color: navy"><b> -&gt; </b></span>cc.text = <span style="color: maroon">d</span> <i>&quot;valueText&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;codedValue&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;coded_placenta_completeness&quot;</i><span style="color: navy">;</span>
      g.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'labour-report/third-stage/perineum') and answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span> bundle.entry<b> as </b><span style="color: maroon">entry</span><span style="color: navy">, </span> entry.resource = <b>create</b><span style="color: navy">(</span><span style="color: blue">'Observation'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">obs</span><b> then</b><span style="color: navy"> {
</span>        qr<span style="color: navy"><b> -&gt; </b></span> obs<span style="color: navy">, </span> entry<b> then </b>BuildObsBase<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">obs</span><span style="color: navy">, </span><span style="color: maroon">entry</span><span style="color: navy">)</span> <i>&quot;base&quot;</i><span style="color: navy">;</span>
        qr<span style="color: navy"><b> -&gt; </b></span>obs<b> then </b>SetExamCategory<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">obs</span><span style="color: navy">)</span> <i>&quot;category&quot;</i><span style="color: navy">;</span>
        it<span style="color: navy"><b> -&gt; </b></span>obs.code<b> as </b><span style="color: maroon">cc</span><b> then</b><span style="color: navy"> {
</span>          it<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>            it<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
            it<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'perineal-outcome'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
            it<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Perineal outcome'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;code&quot;</i><span style="color: navy">;</span>
        it.answer first<b> as </b><span style="color: maroon">a</span><b> then</b><span style="color: navy"> {
</span>          a.value<b> as </b><span style="color: maroon">cv</span><span style="color: navy"><b> -&gt; </b></span>obs.value = <b>create</b><span style="color: navy">(</span><span style="color: blue">'CodeableConcept'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">cc</span><b> then</b><span style="color: navy"> {
</span>            cv<span style="color: navy"><b> -&gt; </b></span>cc.coding = <span style="color: maroon">cv</span> <i>&quot;valueCoding&quot;</i><span style="color: navy">;</span>
            cv.display<b> as </b><span style="color: maroon">d</span><span style="color: navy"><b> -&gt; </b></span>cc.text = <span style="color: maroon">d</span> <i>&quot;valueText&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;codedValue&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;coded_perineal_outcome&quot;</i><span style="color: navy">;</span>
      g.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'labour-report/third-stage/apgar-1-minute') and answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span> bundle.entry<b> as </b><span style="color: maroon">entry</span><span style="color: navy">, </span> entry.resource = <b>create</b><span style="color: navy">(</span><span style="color: blue">'Observation'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">obs</span><b> then</b><span style="color: navy"> {
</span>        qr<span style="color: navy"><b> -&gt; </b></span> obs<span style="color: navy">, </span> entry<b> then </b>BuildObsBase<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">obs</span><span style="color: navy">, </span><span style="color: maroon">entry</span><span style="color: navy">)</span> <i>&quot;base&quot;</i><span style="color: navy">;</span>
        qr<span style="color: navy"><b> -&gt; </b></span>obs<b> then </b>SetSurveyCategory<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">obs</span><span style="color: navy">)</span> <i>&quot;category&quot;</i><span style="color: navy">;</span>
        it<span style="color: navy"><b> -&gt; </b></span>obs.code<b> as </b><span style="color: maroon">cc</span><b> then</b><span style="color: navy"> {
</span>          it<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>            it<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'http://loinc.org'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
            it<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'9272-6'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
            it<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'1 minute Apgar Score'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;code&quot;</i><span style="color: navy">;</span>
        it.answer first<b> as </b><span style="color: maroon">a</span><b> then</b><span style="color: navy"> {
</span>          a.value<b> as </b><span style="color: maroon">v</span><span style="color: navy"><b> -&gt; </b></span>obs.value = <span style="color: maroon">v</span> <i>&quot;set&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;measure_9272_6&quot;</i><span style="color: navy">;</span>
      g.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'labour-report/third-stage/apgar-5-minutes') and answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span> bundle.entry<b> as </b><span style="color: maroon">entry</span><span style="color: navy">, </span> entry.resource = <b>create</b><span style="color: navy">(</span><span style="color: blue">'Observation'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">obs</span><b> then</b><span style="color: navy"> {
</span>        qr<span style="color: navy"><b> -&gt; </b></span> obs<span style="color: navy">, </span> entry<b> then </b>BuildObsBase<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">obs</span><span style="color: navy">, </span><span style="color: maroon">entry</span><span style="color: navy">)</span> <i>&quot;base&quot;</i><span style="color: navy">;</span>
        qr<span style="color: navy"><b> -&gt; </b></span>obs<b> then </b>SetSurveyCategory<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">obs</span><span style="color: navy">)</span> <i>&quot;category&quot;</i><span style="color: navy">;</span>
        it<span style="color: navy"><b> -&gt; </b></span>obs.code<b> as </b><span style="color: maroon">cc</span><b> then</b><span style="color: navy"> {
</span>          it<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>            it<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'http://loinc.org'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
            it<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'9274-2'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
            it<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'5 minute Apgar Score'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;code&quot;</i><span style="color: navy">;</span>
        it.answer first<b> as </b><span style="color: maroon">a</span><b> then</b><span style="color: navy"> {
</span>          a.value<b> as </b><span style="color: maroon">v</span><span style="color: navy"><b> -&gt; </b></span>obs.value = <span style="color: maroon">v</span> <i>&quot;set&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;measure_9274_2&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">// </span><span style="color: green">The mother's observations after delivery, as one panel with the blood</span>
      <span style="color: navy">// </span><span style="color: green">pressure paired inside it.</span>
      g.item<b> as </b><span style="color: maroon">g2</span><b> where </b><span style="color: navy">(</span>(linkId = 'labour-report/third-stage/mother-observations') and item.answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span> bundle.entry<b> as </b><span style="color: maroon">entry</span><span style="color: navy">, </span> entry.resource = <b>create</b><span style="color: navy">(</span><span style="color: blue">'Observation'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">obs</span><b> then</b><span style="color: navy"> {
</span>        qr<span style="color: navy"><b> -&gt; </b></span> obs<span style="color: navy">, </span> entry<b> then </b>BuildObsBase<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">obs</span><span style="color: navy">, </span><span style="color: maroon">entry</span><span style="color: navy">)</span> <i>&quot;base&quot;</i><span style="color: navy">;</span>
        qr<span style="color: navy"><b> -&gt; </b></span>obs<b> then </b>SetVitalSignsCategory<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">obs</span><span style="color: navy">)</span> <i>&quot;category&quot;</i><span style="color: navy">;</span>
        g2<span style="color: navy"><b> -&gt; </b></span>obs.code<b> as </b><span style="color: maroon">cc</span><b> then</b><span style="color: navy"> {
</span>          g2<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>            g2<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'http://loinc.org'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
            g2<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'8716-3'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
            g2<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Vital signs note'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
          g2<span style="color: navy"><b> -&gt; </b></span>cc.text = <span style="color: blue">'Mother observations after delivery'</span> <i>&quot;codeText&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;code&quot;</i><span style="color: navy">;</span>
        g2.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'labour-report/third-stage/mother-observations/systolic') and answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span>obs.component<b> as </b><span style="color: maroon">comp</span><b> then</b><span style="color: navy"> {
</span>          it<span style="color: navy"><b> -&gt; </b></span>comp.code<b> as </b><span style="color: maroon">cc</span><b> then</b><span style="color: navy"> {
</span>            it<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>              it<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'http://loinc.org'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
              it<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'8480-6'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
              it<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Systolic blood pressure'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
            <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;code&quot;</i><span style="color: navy">;</span>
          it<span style="color: navy"><b> -&gt; </b></span>comp<b> then </b>SetComponentValue<span style="color: navy">(</span><span style="color: maroon">it</span><span style="color: navy">, </span><span style="color: maroon">comp</span><span style="color: navy">)</span> <i>&quot;value&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;comp_8480_62&quot;</i><span style="color: navy">;</span>
        g2.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'labour-report/third-stage/mother-observations/diastolic') and answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span>obs.component<b> as </b><span style="color: maroon">comp</span><b> then</b><span style="color: navy"> {
</span>          it<span style="color: navy"><b> -&gt; </b></span>comp.code<b> as </b><span style="color: maroon">cc</span><b> then</b><span style="color: navy"> {
</span>            it<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>              it<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'http://loinc.org'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
              it<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'8462-4'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
              it<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Diastolic blood pressure'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
            <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;code&quot;</i><span style="color: navy">;</span>
          it<span style="color: navy"><b> -&gt; </b></span>comp<b> then </b>SetComponentValue<span style="color: navy">(</span><span style="color: maroon">it</span><span style="color: navy">, </span><span style="color: maroon">comp</span><span style="color: navy">)</span> <i>&quot;value&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;comp_8462_42&quot;</i><span style="color: navy">;</span>
        g2.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'labour-report/third-stage/mother-observations/pulse') and answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span>obs.component<b> as </b><span style="color: maroon">comp</span><b> then</b><span style="color: navy"> {
</span>          it<span style="color: navy"><b> -&gt; </b></span>comp.code<b> as </b><span style="color: maroon">cc</span><b> then</b><span style="color: navy"> {
</span>            it<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>              it<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'http://loinc.org'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
              it<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'8867-4'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
              it<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Heart rate'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
            <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;code&quot;</i><span style="color: navy">;</span>
          it<span style="color: navy"><b> -&gt; </b></span>comp<b> then </b>SetComponentValue<span style="color: navy">(</span><span style="color: maroon">it</span><span style="color: navy">, </span><span style="color: maroon">comp</span><span style="color: navy">)</span> <i>&quot;value&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;comp_8867_4&quot;</i><span style="color: navy">;</span>
        g2.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'labour-report/third-stage/mother-observations/temperature') and answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span>obs.component<b> as </b><span style="color: maroon">comp</span><b> then</b><span style="color: navy"> {
</span>          it<span style="color: navy"><b> -&gt; </b></span>comp.code<b> as </b><span style="color: maroon">cc</span><b> then</b><span style="color: navy"> {
</span>            it<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>              it<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'http://loinc.org'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
              it<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'8310-5'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
              it<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Body temperature'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
            <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;code&quot;</i><span style="color: navy">;</span>
          it<span style="color: navy"><b> -&gt; </b></span>comp<b> then </b>SetComponentValue<span style="color: navy">(</span><span style="color: maroon">it</span><span style="color: navy">, </span><span style="color: maroon">comp</span><span style="color: navy">)</span> <i>&quot;value&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;comp_8310_5&quot;</i><span style="color: navy">;</span>
        g2.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'labour-report/third-stage/mother-observations/respiratory-rate') and answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span>obs.component<b> as </b><span style="color: maroon">comp</span><b> then</b><span style="color: navy"> {
</span>          it<span style="color: navy"><b> -&gt; </b></span>comp.code<b> as </b><span style="color: maroon">cc</span><b> then</b><span style="color: navy"> {
</span>            it<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>              it<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'http://loinc.org'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
              it<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'9279-1'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
              it<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Respiratory rate'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
            <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;code&quot;</i><span style="color: navy">;</span>
          it<span style="color: navy"><b> -&gt; </b></span>comp<b> then </b>SetComponentValue<span style="color: navy">(</span><span style="color: maroon">it</span><span style="color: navy">, </span><span style="color: maroon">comp</span><span style="color: navy">)</span> <i>&quot;value&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;comp_9279_1&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;motherObservations&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">// </span><span style="color: green">The baby's measurements. These belong to the *baby*, not the mother,</span>
      <span style="color: navy">// </span><span style="color: green">and this response's subject is the mother -- so the map records them</span>
      <span style="color: navy">// </span><span style="color: green">here with a note saying so rather than silently writing a birth weight</span>
      <span style="color: navy">// </span><span style="color: green">onto the mother's chart under her own subject reference. The newborn's</span>
      <span style="color: navy">// </span><span style="color: green">own record carries them properly, from the newborn observation chart.</span>
      g.item<b> as </b><span style="color: maroon">g2</span><b> where </b><span style="color: navy">(</span>(linkId = 'labour-report/third-stage/baby-measurements') and item.answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span> bundle.entry<b> as </b><span style="color: maroon">entry</span><span style="color: navy">, </span> entry.resource = <b>create</b><span style="color: navy">(</span><span style="color: blue">'Observation'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">obs</span><b> then</b><span style="color: navy"> {
</span>        qr<span style="color: navy"><b> -&gt; </b></span> obs<span style="color: navy">, </span> entry<b> then </b>BuildObsBase<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">obs</span><span style="color: navy">, </span><span style="color: maroon">entry</span><span style="color: navy">)</span> <i>&quot;base&quot;</i><span style="color: navy">;</span>
        qr<span style="color: navy"><b> -&gt; </b></span>obs<b> then </b>SetSurveyCategory<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">obs</span><span style="color: navy">)</span> <i>&quot;category&quot;</i><span style="color: navy">;</span>
        g2<span style="color: navy"><b> -&gt; </b></span>obs.code<b> as </b><span style="color: maroon">cc</span><b> then</b><span style="color: navy"> {
</span>          g2<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>            g2<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'http://loinc.org'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
            g2<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'8339-4'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
            g2<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Birth weight Measured'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
          g2<span style="color: navy"><b> -&gt; </b></span>cc.text = <span style="color: blue">'Baby measurements at delivery'</span> <i>&quot;codeText&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;code&quot;</i><span style="color: navy">;</span>
        g2<span style="color: navy"><b> -&gt; </b></span> obs.note<b> as </b><span style="color: maroon">n</span><span style="color: navy">, </span> n.text = <span style="color: blue">'Recorded on the mother\'s maternity record. These are measurements of the baby; the newborn\'s own chart is the authoritative record for them.'</span> <i>&quot;subjectNote&quot;</i><span style="color: navy">;</span>
        g2.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'labour-report/third-stage/baby-measurements/weight') and answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span>obs.component<b> as </b><span style="color: maroon">comp</span><b> then</b><span style="color: navy"> {
</span>          it<span style="color: navy"><b> -&gt; </b></span>comp.code<b> as </b><span style="color: maroon">cc</span><b> then</b><span style="color: navy"> {
</span>            it<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>              it<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'http://loinc.org'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
              it<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'8339-4'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
              it<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Birth weight Measured'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
            <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;code&quot;</i><span style="color: navy">;</span>
          it<span style="color: navy"><b> -&gt; </b></span>comp<b> then </b>SetComponentValue<span style="color: navy">(</span><span style="color: maroon">it</span><span style="color: navy">, </span><span style="color: maroon">comp</span><span style="color: navy">)</span> <i>&quot;value&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;comp_8339_42&quot;</i><span style="color: navy">;</span>
        g2.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'labour-report/third-stage/baby-measurements/length') and answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span>obs.component<b> as </b><span style="color: maroon">comp</span><b> then</b><span style="color: navy"> {
</span>          it<span style="color: navy"><b> -&gt; </b></span>comp.code<b> as </b><span style="color: maroon">cc</span><b> then</b><span style="color: navy"> {
</span>            it<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>              it<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'http://loinc.org'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
              it<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'8306-3'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
              it<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Body height --lying'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
            <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;code&quot;</i><span style="color: navy">;</span>
          it<span style="color: navy"><b> -&gt; </b></span>comp<b> then </b>SetComponentValue<span style="color: navy">(</span><span style="color: maroon">it</span><span style="color: navy">, </span><span style="color: maroon">comp</span><span style="color: navy">)</span> <i>&quot;value&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;comp_8306_3&quot;</i><span style="color: navy">;</span>
        g2.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'labour-report/third-stage/baby-measurements/head-circumference') and answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span>obs.component<b> as </b><span style="color: maroon">comp</span><b> then</b><span style="color: navy"> {
</span>          it<span style="color: navy"><b> -&gt; </b></span>comp.code<b> as </b><span style="color: maroon">cc</span><b> then</b><span style="color: navy"> {
</span>            it<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>              it<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'http://loinc.org'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
              it<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'9843-4'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
              it<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Head Occipital-frontal circumference'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
            <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;code&quot;</i><span style="color: navy">;</span>
          it<span style="color: navy"><b> -&gt; </b></span>comp<b> then </b>SetComponentValue<span style="color: navy">(</span><span style="color: maroon">it</span><span style="color: navy">, </span><span style="color: maroon">comp</span><span style="color: navy">)</span> <i>&quot;value&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;comp_9843_4&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;babyMeasurements&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;thirdStageGroup&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">// </span><span style="color: green">── Notes from the clinician's section ────────────────────────────────</span>
    lg.item<b> as </b><span style="color: maroon">g</span><b> where </b><span style="color: navy">(</span>(linkId = 'labour-report/clinician-section') and item.answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span> bundle.entry<b> as </b><span style="color: maroon">entry</span><span style="color: navy">, </span> entry.resource = <b>create</b><span style="color: navy">(</span><span style="color: blue">'Observation'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">obs</span><b> then</b><span style="color: navy"> {
</span>      qr<span style="color: navy"><b> -&gt; </b></span> obs<span style="color: navy">, </span> entry<b> then </b>BuildObsBase<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">obs</span><span style="color: navy">, </span><span style="color: maroon">entry</span><span style="color: navy">)</span> <i>&quot;base&quot;</i><span style="color: navy">;</span>
      qr<span style="color: navy"><b> -&gt; </b></span>obs<b> then </b>SetSurveyCategory<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">obs</span><span style="color: navy">)</span> <i>&quot;category&quot;</i><span style="color: navy">;</span>
      g<span style="color: navy"><b> -&gt; </b></span>obs.code<b> as </b><span style="color: maroon">cc</span><b> then</b><span style="color: navy"> {
</span>        g<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>          g<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'http://loinc.org'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
          g<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'10164-2'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
          g<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'History of Present illness Narrative'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
        g<span style="color: navy"><b> -&gt; </b></span>cc.text = <span style="color: blue">'Clinician section of the labour report'</span> <i>&quot;codeText&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;code&quot;</i><span style="color: navy">;</span>
      g.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'labour-report/clinician-section/other-children-in-nbu') and answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span>obs.component<b> as </b><span style="color: maroon">comp</span><b> then</b><span style="color: navy"> {
</span>        it<span style="color: navy"><b> -&gt; </b></span>comp.code<b> as </b><span style="color: maroon">cc</span><b> then</b><span style="color: navy"> {
</span>          it<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>            it<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
            it<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'obs-other-children-admitted-in-nbu'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
            it<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Other children admitted in NBU'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;code&quot;</i><span style="color: navy">;</span>
        it<span style="color: navy"><b> -&gt; </b></span>comp<b> then </b>SetComponentCodedValue<span style="color: navy">(</span><span style="color: maroon">it</span><span style="color: navy">, </span><span style="color: maroon">comp</span><span style="color: navy">)</span> <i>&quot;value&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;comp_obs_other_children_admitted_in_nbu&quot;</i><span style="color: navy">;</span>
      g.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>linkId = 'labour-report/clinician-section/nbu-reason'<span style="color: navy">)</span><b> then</b><span style="color: navy"> {
</span>        it.answer first<b> as </b><span style="color: maroon">a</span><b> then</b><span style="color: navy"> {
</span>          a.value<b> as </b><span style="color: maroon">txt</span><span style="color: navy"><b> -&gt; </b></span> obs.note<b> as </b><span style="color: maroon">n</span><span style="color: navy">, </span> n.text = <span style="color: maroon">txt</span> <i>&quot;text&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;note2&quot;</i><span style="color: navy">;</span>
      g.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>linkId = 'labour-report/clinician-section/exchange-transfusion'<span style="color: navy">)</span><b> then</b><span style="color: navy"> {
</span>        it.answer first<b> as </b><span style="color: maroon">a</span><b> then</b><span style="color: navy"> {
</span>          a.value<b> as </b><span style="color: maroon">txt</span><span style="color: navy"><b> -&gt; </b></span> obs.note<b> as </b><span style="color: maroon">n</span><span style="color: navy">, </span> n.text = <span style="color: maroon">txt</span> <i>&quot;text&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;note3&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;clinicianSectionObservation&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">}</span> <i>&quot;labourReportGroup&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">// </span><span style="color: green">── The management plan ─────────────────────────────────────────────────</span>
  qr.item<b> as </b><span style="color: maroon">g</span><b> where </b><span style="color: navy">(</span>(linkId = 'management-plan') and item.where(linkId = 'management-plan/plan').answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span> bundle.entry<b> as </b><span style="color: maroon">entry</span><span style="color: navy">, </span> entry.resource = <b>create</b><span style="color: navy">(</span><span style="color: blue">'CarePlan'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">plan</span><b> then</b><span style="color: navy"> {
</span>    qr<span style="color: navy"><b> -&gt; </b></span> plan<span style="color: navy">, </span> entry<b> then </b>BuildCarePlanBase<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">plan</span><span style="color: navy">, </span><span style="color: maroon">entry</span><span style="color: navy">)</span> <i>&quot;base&quot;</i><span style="color: navy">;</span>
    g<span style="color: navy"><b> -&gt; </b></span>plan.status = <span style="color: blue">'active'</span> <i>&quot;status&quot;</i><span style="color: navy">;</span>
    g<span style="color: navy"><b> -&gt; </b></span>plan.intent = <span style="color: blue">'plan'</span> <i>&quot;intent&quot;</i><span style="color: navy">;</span>
    g<span style="color: navy"><b> -&gt; </b></span>plan.title = <span style="color: blue">'Maternity management plan'</span> <i>&quot;title&quot;</i><span style="color: navy">;</span>
    qr.authored<b> as </b><span style="color: maroon">t</span><span style="color: navy"><b> -&gt; </b></span>plan.created = <span style="color: maroon">t</span> <i>&quot;created&quot;</i><span style="color: navy">;</span>
    qr.encounter<b> as </b><span style="color: maroon">e</span><span style="color: navy"><b> -&gt; </b></span>plan.encounter = <span style="color: maroon">e</span><span style="color: navy">;</span>
    g<span style="color: navy"><b> -&gt; </b></span>plan.category<b> as </b><span style="color: maroon">cat</span><b> then</b><span style="color: navy"> {
</span>      g<span style="color: navy"><b> -&gt; </b></span>cat.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>        g<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'https://fhir.slade360.co.ke/fhir/CodeSystem/document-type-codesystem'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
        g<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'maternity-record'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
        g<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Maternity record'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;category&quot;</i><span style="color: navy">;</span>
    g.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>linkId = 'management-plan/plan'<span style="color: navy">)</span><b> then</b><span style="color: navy"> {
</span>      it.answer first<b> as </b><span style="color: maroon">a</span><b> then</b><span style="color: navy"> {
</span>        a.value<b> as </b><span style="color: maroon">txt</span><span style="color: navy"><b> -&gt; </b></span>plan.description = <span style="color: maroon">txt</span> <i>&quot;description&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;planRule&quot;</i><span style="color: navy">;</span>
    g.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'management-plan/signed-by') and answer.value.exists()<span style="color: navy">)</span><b> then</b><span style="color: navy"> {
</span>      it.answer first<b> as </b><span style="color: maroon">a</span><b> then</b><span style="color: navy"> {
</span>        a.value<b> as </b><span style="color: maroon">ref</span><span style="color: navy"><b> -&gt; </b></span>plan.custodian = <span style="color: maroon">ref</span> <i>&quot;custodian&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;signedByRule&quot;</i><span style="color: navy">;</span>
    g.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'management-plan/delivery-summary') and answer.value.exists()<span style="color: navy">)</span><b> then</b><span style="color: navy"> {
</span>      it.answer first<b> as </b><span style="color: maroon">a</span><b> then</b><span style="color: navy"> {
</span>        a.value<b> as </b><span style="color: maroon">txt</span><span style="color: navy"><b> -&gt; </b></span> plan.note<b> as </b><span style="color: maroon">n</span><span style="color: navy">, </span> n.text = <span style="color: maroon">txt</span> <i>&quot;deliverySummaryNote&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;deliverySummaryRule&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">}</span> <i>&quot;managementCarePlan&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">// </span><span style="color: green">── Diet and nutrition ──────────────────────────────────────────────────</span>
  qr.item<b> as </b><span style="color: maroon">g</span><b> where </b><span style="color: navy">(</span>(linkId = 'diet-and-nutrition') and item.answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span> bundle.entry<b> as </b><span style="color: maroon">entry</span><span style="color: navy">, </span> entry.resource = <b>create</b><span style="color: navy">(</span><span style="color: blue">'Observation'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">obs</span><b> then</b><span style="color: navy"> {
</span>    qr<span style="color: navy"><b> -&gt; </b></span> obs<span style="color: navy">, </span> entry<b> then </b>BuildObsBase<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">obs</span><span style="color: navy">, </span><span style="color: maroon">entry</span><span style="color: navy">)</span> <i>&quot;base&quot;</i><span style="color: navy">;</span>
    qr<span style="color: navy"><b> -&gt; </b></span>obs<b> then </b>SetSurveyCategory<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">obs</span><span style="color: navy">)</span> <i>&quot;category&quot;</i><span style="color: navy">;</span>
    g<span style="color: navy"><b> -&gt; </b></span>obs.code<b> as </b><span style="color: maroon">cc</span><b> then</b><span style="color: navy"> {
</span>      g<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>        g<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'https://fhir.slade360.co.ke/fhir/CodeSystem/inpatient-clinical-concept-codesystem'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
        g<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'feeding'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
        g<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Feeding'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
      g<span style="color: navy"><b> -&gt; </b></span>cc.text = <span style="color: blue">'Diet and nutrition assessment'</span> <i>&quot;codeText&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;code&quot;</i><span style="color: navy">;</span>
    g.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'diet-and-nutrition/vegetarian') and answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span>obs.component<b> as </b><span style="color: maroon">comp</span><b> then</b><span style="color: navy"> {
</span>      it<span style="color: navy"><b> -&gt; </b></span>comp.code<b> as </b><span style="color: maroon">cc</span><b> then</b><span style="color: navy"> {
</span>        it<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>          it<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
          it<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'obs-vegetarian'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
          it<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Vegetarian'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;code&quot;</i><span style="color: navy">;</span>
      it<span style="color: navy"><b> -&gt; </b></span>comp<b> then </b>SetComponentCodedValue<span style="color: navy">(</span><span style="color: maroon">it</span><span style="color: navy">, </span><span style="color: maroon">comp</span><span style="color: navy">)</span> <i>&quot;value&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;comp_obs_vegetarian&quot;</i><span style="color: navy">;</span>
    g.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'diet-and-nutrition/other-diet-issue') and answer.value.exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span>obs.component<b> as </b><span style="color: maroon">comp</span><b> then</b><span style="color: navy"> {
</span>      it<span style="color: navy"><b> -&gt; </b></span>comp.code<b> as </b><span style="color: maroon">cc</span><b> then</b><span style="color: navy"> {
</span>        it<span style="color: navy"><b> -&gt; </b></span>cc.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>          it<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
          it<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'obs-other-diet-issue'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
          it<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Other diet issue'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;code&quot;</i><span style="color: navy">;</span>
      it<span style="color: navy"><b> -&gt; </b></span>comp<b> then </b>SetComponentValue<span style="color: navy">(</span><span style="color: maroon">it</span><span style="color: navy">, </span><span style="color: maroon">comp</span><span style="color: navy">)</span> <i>&quot;value&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;comp_obs_other_diet_issue&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">}</span> <i>&quot;dietObservation&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">// </span><span style="color: green">── Discharge ───────────────────────────────────────────────────────────</span>
  qr.item<b> as </b><span style="color: maroon">g</span><b> where </b><span style="color: navy">(</span>linkId = 'discharge'<span style="color: navy">)</span><b> then</b><span style="color: navy"> {
</span>    g.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>linkId = 'discharge/diagnosis'<span style="color: navy">)</span><b> then</b><span style="color: navy"> {
</span>      it.answer<b> as </b><span style="color: maroon">a</span><span style="color: navy"><b> -&gt; </b></span> bundle.entry<b> as </b><span style="color: maroon">entry</span><span style="color: navy">, </span> entry.resource = <b>create</b><span style="color: navy">(</span><span style="color: blue">'Condition'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">cond</span><b> then</b><span style="color: navy"> {
</span>        qr<span style="color: navy"><b> -&gt; </b></span> cond<span style="color: navy">, </span> entry<b> then </b>BuildConditionBase<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">cond</span><span style="color: navy">, </span><span style="color: maroon">entry</span><span style="color: navy">)</span> <i>&quot;base&quot;</i><span style="color: navy">;</span>
        a<span style="color: navy"><b> -&gt; </b></span>cond.clinicalStatus<b> as </b><span style="color: maroon">cs</span><b> then</b><span style="color: navy"> {
</span>          a<span style="color: navy"><b> -&gt; </b></span>cs.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>            a<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'http://terminology.hl7.org/CodeSystem/condition-clinical'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
            a<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'resolved'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
            a<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Resolved'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;clinicalStatus&quot;</i><span style="color: navy">;</span>
        a<span style="color: navy"><b> -&gt; </b></span>cond.verificationStatus<b> as </b><span style="color: maroon">vs</span><b> then</b><span style="color: navy"> {
</span>          a<span style="color: navy"><b> -&gt; </b></span>vs.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>            a<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'http://terminology.hl7.org/CodeSystem/condition-ver-status'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
            a<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'confirmed'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
            a<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Confirmed'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;verificationStatus&quot;</i><span style="color: navy">;</span>
        a<span style="color: navy"><b> -&gt; </b></span>cond.category<b> as </b><span style="color: maroon">cat</span><b> then</b><span style="color: navy"> {
</span>          a<span style="color: navy"><b> -&gt; </b></span>cat.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>            a<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'http://terminology.hl7.org/CodeSystem/condition-category'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
            a<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'encounter-diagnosis'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
            a<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Encounter Diagnosis'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;category&quot;</i><span style="color: navy">;</span>
        a.value<b> as </b><span style="color: maroon">txt</span><span style="color: navy"><b> -&gt; </b></span> cond.code<b> as </b><span style="color: maroon">cc</span><span style="color: navy">, </span> cc.text = <span style="color: maroon">txt</span> <i>&quot;codeText&quot;</i><span style="color: navy">;</span>
        qr.authored<b> as </b><span style="color: maroon">t</span><span style="color: navy"><b> -&gt; </b></span>cond.recordedDate = <span style="color: maroon">t</span> <i>&quot;recordedDate&quot;</i><span style="color: navy">;</span>
        qr.encounter<b> as </b><span style="color: maroon">e</span><span style="color: navy"><b> -&gt; </b></span>cond.encounter = <span style="color: maroon">e</span><span style="color: navy">;</span>
        a<span style="color: navy"><b> -&gt; </b></span> cond.note<b> as </b><span style="color: maroon">n</span><span style="color: navy">, </span> n.text = <span style="color: blue">'Diagnosis on discharge from the maternity ward.'</span> <i>&quot;dischargeNote&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;createDischargeCondition&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;dischargeDiagnoses&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">}</span> <i>&quot;dischargeGroup&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">// </span><span style="color: green">── Consent for admission ───────────────────────────────────────────────</span>
  qr.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'consent-for-admission') and (answer.value = true)<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span> bundle.entry<b> as </b><span style="color: maroon">entry</span><span style="color: navy">, </span> entry.resource = <b>create</b><span style="color: navy">(</span><span style="color: blue">'Consent'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">consent</span><b> then</b><span style="color: navy"> {
</span>    qr<span style="color: navy"><b> -&gt; </b></span> consent<span style="color: navy">, </span> entry<b> then </b>BuildConsentBase<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">consent</span><span style="color: navy">, </span><span style="color: maroon">entry</span><span style="color: navy">)</span> <i>&quot;base&quot;</i><span style="color: navy">;</span>
    it<span style="color: navy"><b> -&gt; </b></span>consent.status = <span style="color: blue">'active'</span> <i>&quot;status&quot;</i><span style="color: navy">;</span>
    it<span style="color: navy"><b> -&gt; </b></span>consent.category<b> as </b><span style="color: maroon">cat</span><b> then</b><span style="color: navy"> {
</span>      it<span style="color: navy"><b> -&gt; </b></span>cat.coding<b> as </b><span style="color: maroon">cg</span><b> then</b><span style="color: navy"> {
</span>        it<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'http://terminology.hl7.org/CodeSystem/consentcategorycodes'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
        it<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'acd'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
        it<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Advance Directive'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
      it<span style="color: navy"><b> -&gt; </b></span>cat.text = <span style="color: blue">'Consent for admission and relevant management'</span> <i>&quot;categoryText&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;category&quot;</i><span style="color: navy">;</span>
    it<span style="color: navy"><b> -&gt; </b></span>consent.decision = <span style="color: blue">'permit'</span> <i>&quot;decision&quot;</i><span style="color: navy">;</span>
    qr.authored<b> as </b><span style="color: maroon">t</span><span style="color: navy"><b> -&gt; </b></span> consent.period<b> as </b><span style="color: maroon">per</span><span style="color: navy">, </span> per.start = <span style="color: maroon">t</span> <i>&quot;consentPeriodStart&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>consent.grantee = <span style="color: maroon">src</span> <i>&quot;grantee&quot;</i><span style="color: navy">;</span>
    it<span style="color: navy"><b> -&gt; </b></span> consent.provision<b> as </b><span style="color: maroon">prov</span><span style="color: navy">, </span> prov.code<b> as </b><span style="color: maroon">pc</span><span style="color: navy">, </span> pc.text = <span style="color: blue">'Taken on the maternity record. The woman signed the sheet; this records that the signature was obtained, not the signature itself.'</span> <i>&quot;provenanceNote&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">}</span> <i>&quot;createConsent&quot;</i><span style="color: navy">;</span>
<span style="color: navy">}

</span><span style="color: navy">// </span><span style="color: green">─────────────────────────────────────────────────────────────────────────────</span>
<span style="color: navy">// </span><span style="color: green">Shared scaffolding. Repeated in each map rather than imported: the transform</span>
<span style="color: navy">// </span><span style="color: green">engine resolves `imports` against whatever StructureMaps happen to be on the</span>
<span style="color: navy">// </span><span style="color: green">server, and a form that stops extracting because a shared map was not</span>
<span style="color: navy">// </span><span style="color: green">uploaded is a worse failure than a duplicated group.</span>
<span style="color: navy">// </span><span style="color: green">Two notes on what the publisher's StructureMap validator says about this file.</span>
<span style="color: navy">// </span><span style="color: green">Source parameters below are left untyped on purpose. Writing `: Element` makes</span>
<span style="color: navy">// </span><span style="color: green">the validator compare QuestionnaireResponse.item against the literal 'Element'</span>
<span style="color: navy">// </span><span style="color: green">and report them as incompatible with each other, which is noise, not a finding.</span>
<span style="color: navy">// </span><span style="color: green">`evaluate(context, expression)` is flagged as &quot;takes 1 parameter but 2 were</span>
<span style="color: navy">// </span><span style="color: green">found&quot;. Leave it. The FML parser in the same jar refuses the one-argument form</span>
<span style="color: navy">// </span><span style="color: green">outright -- it wants a parameter, a comma, then the FHIRPath -- so the</span>
<span style="color: navy">// </span><span style="color: green">publisher is objecting to what its own compiler emits. Two arguments is the</span>
<span style="color: navy">// </span><span style="color: green">only form that compiles, and it is what the R5 transform engine executes.</span>
<span style="color: navy">// </span><span style="color: green">─────────────────────────────────────────────────────────────────────────────</span>
<b>group </b>BuildObsBase<span style="color: navy">(</span><b>source</b> <span style="color: maroon">qr</span><span style="color: navy"> : </span>QR, <b>target</b> <span style="color: maroon">obs</span><span style="color: navy"> : </span>Observation, <b>target</b> <span style="color: maroon">entry</span><span style="color: navy">)</span><span style="color: navy"> {
</span>  qr<span style="color: navy"><b> -&gt; </b></span>obs<b> then </b>SetResponseProvenance<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">obs</span><span style="color: navy">)</span> <i>&quot;responseProvenance&quot;</i><span style="color: navy">;</span>
  qr<span style="color: navy"><b> -&gt; </b></span>obs.id = <b>uuid</b><span style="color: navy">(</span><span style="color: navy">)</span><b> then </b>SetObservationFullUrl<span style="color: navy">(</span><span style="color: maroon">obs</span><span style="color: navy">, </span><span style="color: maroon">entry</span><span style="color: navy">)</span> <i>&quot;idAndFullUrl&quot;</i><span style="color: navy">;</span>
  qr<span style="color: navy"><b> -&gt; </b></span>entry.request<b> as </b><span style="color: maroon">request</span><b> then</b><span style="color: navy"> {
</span>    qr<span style="color: navy"><b> -&gt; </b></span>request.method = <span style="color: blue">'POST'</span> <i>&quot;requestMethod&quot;</i><span style="color: navy">;</span>
    qr<span style="color: navy"><b> -&gt; </b></span>request.url = <span style="color: blue">'Observation'</span> <i>&quot;requestUrl&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">}</span> <i>&quot;entryRequest&quot;</i><span style="color: navy">;</span>
  qr<span style="color: navy"><b> -&gt; </b></span>obs.status = <span style="color: blue">'final'</span> <i>&quot;status&quot;</i><span style="color: navy">;</span>
  qr.subject<b> as </b><span style="color: maroon">s</span><span style="color: navy"><b> -&gt; </b></span>obs.subject = <span style="color: maroon">s</span><span style="color: navy">;</span>
  qr.encounter<b> as </b><span style="color: maroon">e</span><span style="color: navy"><b> -&gt; </b></span>obs.encounter = <span style="color: maroon">e</span><span style="color: navy">;</span>
  qr.authored<b> as </b><span style="color: maroon">t</span><span style="color: navy"><b> -&gt; </b></span>obs.effective = <span style="color: maroon">t</span> <i>&quot;effective&quot;</i><span style="color: navy">;</span>
  qr.source<b> as </b><span style="color: maroon">src</span><span style="color: navy"><b> -&gt; </b></span>obs.performer = <span style="color: maroon">src</span> <i>&quot;performerFromSource&quot;</i><span style="color: navy">;</span>
  qr<b> where </b><span style="color: navy">(</span>source.exists().not()<span style="color: navy">)</span><b> then</b><span style="color: navy"> {
</span>    qr.author<b> as </b><span style="color: maroon">a</span><span style="color: navy"><b> -&gt; </b></span>obs.performer = <span style="color: maroon">a</span> <i>&quot;performerFromAuthor&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">}</span> <i>&quot;performerFallback&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">// </span><span style="color: green">A stored response's id already reads &quot;QuestionnaireResponse/&lt;id&gt;&quot;, so it is</span>
  <span style="color: navy">// </span><span style="color: green">a relative reference as it stands. The hasValue() guard is what stops an</span>
  <span style="color: navy">// </span><span style="color: green">unsaved response -- one posted straight to $extract rather than saved first</span>
  <span style="color: navy">// </span><span style="color: green">-- from writing &quot;QuestionnaireResponse/null&quot; into the record.</span>
  qr.id<b> as </b><span style="color: maroon">qid</span><b> where </b><span style="color: navy">(</span>$this.hasValue()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span> obs.derivedFrom = <b>create</b><span style="color: navy">(</span><span style="color: blue">'Reference'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">ref</span><span style="color: navy">, </span> ref.reference = <span style="color: maroon">qid</span> <i>&quot;linkQuestionnaireResponse&quot;</i><span style="color: navy">;</span>
<span style="color: navy">}

</span><b>group </b>SetObservationFullUrl<span style="color: navy">(</span><b>source</b> <span style="color: maroon">obs</span><span style="color: navy"> : </span>Observation, <b>target</b> <span style="color: maroon">entry</span><span style="color: navy">)</span><span style="color: navy"> {
</span>  obs.id<b> as </b><span style="color: maroon">id</span><span style="color: navy"><b> -&gt; </b></span>entry.fullUrl = <b>append</b><span style="color: navy">(</span><span style="color: blue">'https://fhir.slade360.co.ke/fhir/Observation/'</span><span style="color: navy">, </span><span style="color: maroon">id</span><span style="color: navy">)</span> <i>&quot;assignFullUrl&quot;</i><span style="color: navy">;</span>
<span style="color: navy">}

</span><span style="color: navy">// </span><span style="color: green">The two answer shapes a component can carry. Both read the answer through the</span>
<span style="color: navy">// </span><span style="color: green">untyped `.value` accessor: reading `valueCoding` or `valueQuantity` by its</span>
<span style="color: navy">// </span><span style="color: green">typed property name fails at transform time on HAPI R5 with &quot;Attempt to read</span>
<span style="color: navy">// </span><span style="color: green">invalid property ... on QuestionnaireResponse.item.answer&quot;.</span>
<b>group </b>SetComponentCodedValue<span style="color: navy">(</span><b>source</b> <span style="color: maroon">it</span>, <b>target</b> <span style="color: maroon">comp</span><span style="color: navy">)</span><span style="color: navy"> {
</span>  it.answer first<b> as </b><span style="color: maroon">a</span><b> then</b><span style="color: navy"> {
</span>    a.value<b> as </b><span style="color: maroon">cv</span><span style="color: navy"><b> -&gt; </b></span>comp.value = <b>create</b><span style="color: navy">(</span><span style="color: blue">'CodeableConcept'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">cc</span><b> then</b><span style="color: navy"> {
</span>      cv<span style="color: navy"><b> -&gt; </b></span>cc.coding = <span style="color: maroon">cv</span> <i>&quot;valueCoding&quot;</i><span style="color: navy">;</span>
      cv.display<b> as </b><span style="color: maroon">d</span><span style="color: navy"><b> -&gt; </b></span>cc.text = <span style="color: maroon">d</span> <i>&quot;valueText&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;codedValue&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">}</span> <i>&quot;componentAnswer&quot;</i><span style="color: navy">;</span>
<span style="color: navy">}

</span><b>group </b>SetComponentValue<span style="color: navy">(</span><b>source</b> <span style="color: maroon">it</span>, <b>target</b> <span style="color: maroon">comp</span><span style="color: navy">)</span><span style="color: navy"> {
</span>  it.answer first<b> as </b><span style="color: maroon">a</span><b> then</b><span style="color: navy"> {
</span>    a.value<b> as </b><span style="color: maroon">v</span><span style="color: navy"><b> -&gt; </b></span>comp.value = <span style="color: maroon">v</span> <i>&quot;plainValue&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">}</span> <i>&quot;componentAnswer&quot;</i><span style="color: navy">;</span>
<span style="color: navy">}

</span><b>group </b>SetSurveyCategory<span style="color: navy">(</span><b>source</b> <span style="color: maroon">qr</span><span style="color: navy"> : </span>QR, <b>target</b> <span style="color: maroon">obs</span><span style="color: navy"> : </span>Observation<span style="color: navy">)</span><span style="color: navy"> {
</span>  qr<span style="color: navy"><b> -&gt; </b></span>obs.category<b> as </b><span style="color: maroon">cat</span><b> then</b><span style="color: navy"> {
</span>    qr<span style="color: navy"><b> -&gt; </b></span>cat.coding<b> as </b><span style="color: maroon">coding</span><b> then</b><span style="color: navy"> {
</span>      qr<span style="color: navy"><b> -&gt; </b></span>coding.system = <span style="color: blue">'http://terminology.hl7.org/CodeSystem/observation-category'</span> <i>&quot;categorySystem&quot;</i><span style="color: navy">;</span>
      qr<span style="color: navy"><b> -&gt; </b></span>coding.code = <span style="color: blue">'survey'</span> <i>&quot;categoryCode&quot;</i><span style="color: navy">;</span>
      qr<span style="color: navy"><b> -&gt; </b></span>coding.display = <span style="color: blue">'Survey'</span> <i>&quot;categoryDisplay&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;categoryCoding&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">}</span> <i>&quot;category&quot;</i><span style="color: navy">;</span>
<span style="color: navy">}

</span><b>group </b>SetVitalSignsCategory<span style="color: navy">(</span><b>source</b> <span style="color: maroon">qr</span><span style="color: navy"> : </span>QR, <b>target</b> <span style="color: maroon">obs</span><span style="color: navy"> : </span>Observation<span style="color: navy">)</span><span style="color: navy"> {
</span>  qr<span style="color: navy"><b> -&gt; </b></span>obs.category<b> as </b><span style="color: maroon">cat</span><b> then</b><span style="color: navy"> {
</span>    qr<span style="color: navy"><b> -&gt; </b></span>cat.coding<b> as </b><span style="color: maroon">coding</span><b> then</b><span style="color: navy"> {
</span>      qr<span style="color: navy"><b> -&gt; </b></span>coding.system = <span style="color: blue">'http://terminology.hl7.org/CodeSystem/observation-category'</span> <i>&quot;categorySystem&quot;</i><span style="color: navy">;</span>
      qr<span style="color: navy"><b> -&gt; </b></span>coding.code = <span style="color: blue">'vital-signs'</span> <i>&quot;categoryCode&quot;</i><span style="color: navy">;</span>
      qr<span style="color: navy"><b> -&gt; </b></span>coding.display = <span style="color: blue">'Vital Signs'</span> <i>&quot;categoryDisplay&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;categoryCoding&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">}</span> <i>&quot;category&quot;</i><span style="color: navy">;</span>
<span style="color: navy">}

</span><b>group </b>SetExamCategory<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">'exam'</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">'Exam'</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>SetLaboratoryCategory<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">'laboratory'</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">'Laboratory'</span> <i>&quot;categoryDisplay&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;categoryCoding&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">}</span> <i>&quot;category&quot;</i><span style="color: navy">;</span>
<span style="color: navy">}

</span><b>group </b>SetProcedureCategory<span style="color: navy">(</span><b>source</b> <span style="color: maroon">qr</span><span style="color: navy"> : </span>QR, <b>target</b> <span style="color: maroon">obs</span><span style="color: navy"> : </span>Observation<span style="color: navy">)</span><span style="color: navy"> {
</span>  qr<span style="color: navy"><b> -&gt; </b></span>obs.category<b> as </b><span style="color: maroon">cat</span><b> then</b><span style="color: navy"> {
</span>    qr<span style="color: navy"><b> -&gt; </b></span>cat.coding<b> as </b><span style="color: maroon">coding</span><b> then</b><span style="color: navy"> {
</span>      qr<span style="color: navy"><b> -&gt; </b></span>coding.system = <span style="color: blue">'http://terminology.hl7.org/CodeSystem/observation-category'</span> <i>&quot;categorySystem&quot;</i><span style="color: navy">;</span>
      qr<span style="color: navy"><b> -&gt; </b></span>coding.code = <span style="color: blue">'procedure'</span> <i>&quot;categoryCode&quot;</i><span style="color: navy">;</span>
      qr<span style="color: navy"><b> -&gt; </b></span>coding.display = <span style="color: blue">'Procedure'</span> <i>&quot;categoryDisplay&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;categoryCoding&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">}</span> <i>&quot;category&quot;</i><span style="color: navy">;</span>
<span style="color: navy">}

</span><b>group </b>BuildConditionBase<span style="color: navy">(</span><b>source</b> <span style="color: maroon">qr</span><span style="color: navy"> : </span>QR, <b>target</b> <span style="color: maroon">r</span><span style="color: navy"> : </span>Condition, <b>target</b> <span style="color: maroon">entry</span><span style="color: navy">)</span><span style="color: navy"> {
</span>  qr<span style="color: navy"><b> -&gt; </b></span>r<b> then </b>SetResponseProvenance<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">r</span><span style="color: navy">)</span> <i>&quot;responseProvenance&quot;</i><span style="color: navy">;</span>
  qr<span style="color: navy"><b> -&gt; </b></span>r.id = <b>uuid</b><span style="color: navy">(</span><span style="color: navy">)</span><b> then </b>SetConditionFullUrl<span style="color: navy">(</span><span style="color: maroon">r</span><span style="color: navy">, </span><span style="color: maroon">entry</span><span style="color: navy">)</span> <i>&quot;idAndFullUrl&quot;</i><span style="color: navy">;</span>
  qr<span style="color: navy"><b> -&gt; </b></span>entry.request<b> as </b><span style="color: maroon">request</span><b> then</b><span style="color: navy"> {
</span>    qr<span style="color: navy"><b> -&gt; </b></span>request.method = <span style="color: blue">'POST'</span> <i>&quot;requestMethod&quot;</i><span style="color: navy">;</span>
    qr<span style="color: navy"><b> -&gt; </b></span>request.url = <span style="color: blue">'Condition'</span> <i>&quot;requestUrl&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">}</span> <i>&quot;entryRequest&quot;</i><span style="color: navy">;</span>
  qr.subject<b> as </b><span style="color: maroon">s</span><span style="color: navy"><b> -&gt; </b></span>r.subject = <span style="color: maroon">s</span><span style="color: navy">;</span>
<span style="color: navy">}

</span><b>group </b>SetConditionFullUrl<span style="color: navy">(</span><b>source</b> <span style="color: maroon">r</span><span style="color: navy"> : </span>Condition, <b>target</b> <span style="color: maroon">entry</span><span style="color: navy">)</span><span style="color: navy"> {
</span>  r.id<b> as </b><span style="color: maroon">id</span><span style="color: navy"><b> -&gt; </b></span>entry.fullUrl = <b>append</b><span style="color: navy">(</span><span style="color: blue">'https://fhir.slade360.co.ke/fhir/Condition/'</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>BuildAllergyIntoleranceBase<span style="color: navy">(</span><b>source</b> <span style="color: maroon">qr</span><span style="color: navy"> : </span>QR, <b>target</b> <span style="color: maroon">r</span><span style="color: navy"> : </span>AllergyIntolerance, <b>target</b> <span style="color: maroon">entry</span><span style="color: navy">)</span><span style="color: navy"> {
</span>  qr<span style="color: navy"><b> -&gt; </b></span>r<b> then </b>SetResponseProvenance<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">r</span><span style="color: navy">)</span> <i>&quot;responseProvenance&quot;</i><span style="color: navy">;</span>
  qr<span style="color: navy"><b> -&gt; </b></span>r.id = <b>uuid</b><span style="color: navy">(</span><span style="color: navy">)</span><b> then </b>SetAllergyIntoleranceFullUrl<span style="color: navy">(</span><span style="color: maroon">r</span><span style="color: navy">, </span><span style="color: maroon">entry</span><span style="color: navy">)</span> <i>&quot;idAndFullUrl&quot;</i><span style="color: navy">;</span>
  qr<span style="color: navy"><b> -&gt; </b></span>entry.request<b> as </b><span style="color: maroon">request</span><b> then</b><span style="color: navy"> {
</span>    qr<span style="color: navy"><b> -&gt; </b></span>request.method = <span style="color: blue">'POST'</span> <i>&quot;requestMethod&quot;</i><span style="color: navy">;</span>
    qr<span style="color: navy"><b> -&gt; </b></span>request.url = <span style="color: blue">'AllergyIntolerance'</span> <i>&quot;requestUrl&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">}</span> <i>&quot;entryRequest&quot;</i><span style="color: navy">;</span>
  qr.subject<b> as </b><span style="color: maroon">s</span><span style="color: navy"><b> -&gt; </b></span>r.patient = <span style="color: maroon">s</span><span style="color: navy">;</span>
<span style="color: navy">}

</span><b>group </b>SetAllergyIntoleranceFullUrl<span style="color: navy">(</span><b>source</b> <span style="color: maroon">r</span><span style="color: navy"> : </span>AllergyIntolerance, <b>target</b> <span style="color: maroon">entry</span><span style="color: navy">)</span><span style="color: navy"> {
</span>  r.id<b> as </b><span style="color: maroon">id</span><span style="color: navy"><b> -&gt; </b></span>entry.fullUrl = <b>append</b><span style="color: navy">(</span><span style="color: blue">'https://fhir.slade360.co.ke/fhir/AllergyIntolerance/'</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>BuildProcedureBase<span style="color: navy">(</span><b>source</b> <span style="color: maroon">qr</span><span style="color: navy"> : </span>QR, <b>target</b> <span style="color: maroon">r</span><span style="color: navy"> : </span>Procedure, <b>target</b> <span style="color: maroon">entry</span><span style="color: navy">)</span><span style="color: navy"> {
</span>  qr<span style="color: navy"><b> -&gt; </b></span>r<b> then </b>SetResponseProvenance<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">r</span><span style="color: navy">)</span> <i>&quot;responseProvenance&quot;</i><span style="color: navy">;</span>
  qr<span style="color: navy"><b> -&gt; </b></span>r.id = <b>uuid</b><span style="color: navy">(</span><span style="color: navy">)</span><b> then </b>SetProcedureFullUrl<span style="color: navy">(</span><span style="color: maroon">r</span><span style="color: navy">, </span><span style="color: maroon">entry</span><span style="color: navy">)</span> <i>&quot;idAndFullUrl&quot;</i><span style="color: navy">;</span>
  qr<span style="color: navy"><b> -&gt; </b></span>entry.request<b> as </b><span style="color: maroon">request</span><b> then</b><span style="color: navy"> {
</span>    qr<span style="color: navy"><b> -&gt; </b></span>request.method = <span style="color: blue">'POST'</span> <i>&quot;requestMethod&quot;</i><span style="color: navy">;</span>
    qr<span style="color: navy"><b> -&gt; </b></span>request.url = <span style="color: blue">'Procedure'</span> <i>&quot;requestUrl&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">}</span> <i>&quot;entryRequest&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">// </span><span style="color: green">The response's own time, as a floor, the way BuildObsBase does it. A rule</span>
  <span style="color: navy">// </span><span style="color: green">that reads a time off the form overwrites this; without it a procedure whose</span>
  <span style="color: navy">// </span><span style="color: green">date column was taken off on review has no time at all, and a procedure with</span>
  <span style="color: navy">// </span><span style="color: green">no time cannot be ordered against the rest of the admission.</span>
  qr.authored<b> as </b><span style="color: maroon">t</span><span style="color: navy"><b> -&gt; </b></span>r.occurrence = <span style="color: maroon">t</span> <i>&quot;occurrenceFallback&quot;</i><span style="color: navy">;</span>
  qr.subject<b> as </b><span style="color: maroon">s</span><span style="color: navy"><b> -&gt; </b></span>r.subject = <span style="color: maroon">s</span><span style="color: navy">;</span>
<span style="color: navy">}

</span><b>group </b>SetProcedureFullUrl<span style="color: navy">(</span><b>source</b> <span style="color: maroon">r</span><span style="color: navy"> : </span>Procedure, <b>target</b> <span style="color: maroon">entry</span><span style="color: navy">)</span><span style="color: navy"> {
</span>  r.id<b> as </b><span style="color: maroon">id</span><span style="color: navy"><b> -&gt; </b></span>entry.fullUrl = <b>append</b><span style="color: navy">(</span><span style="color: blue">'https://fhir.slade360.co.ke/fhir/Procedure/'</span><span style="color: navy">, </span><span style="color: maroon">id</span><span style="color: navy">)</span> <i>&quot;assignFullUrl&quot;</i><span style="color: navy">;</span>
<span style="color: navy">}

</span><b>group </b>BuildCarePlanBase<span style="color: navy">(</span><b>source</b> <span style="color: maroon">qr</span><span style="color: navy"> : </span>QR, <b>target</b> <span style="color: maroon">r</span><span style="color: navy"> : </span>CarePlan, <b>target</b> <span style="color: maroon">entry</span><span style="color: navy">)</span><span style="color: navy"> {
</span>  qr<span style="color: navy"><b> -&gt; </b></span>r<b> then </b>SetResponseProvenance<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">r</span><span style="color: navy">)</span> <i>&quot;responseProvenance&quot;</i><span style="color: navy">;</span>
  qr<span style="color: navy"><b> -&gt; </b></span>r.id = <b>uuid</b><span style="color: navy">(</span><span style="color: navy">)</span><b> then </b>SetCarePlanFullUrl<span style="color: navy">(</span><span style="color: maroon">r</span><span style="color: navy">, </span><span style="color: maroon">entry</span><span style="color: navy">)</span> <i>&quot;idAndFullUrl&quot;</i><span style="color: navy">;</span>
  qr<span style="color: navy"><b> -&gt; </b></span>entry.request<b> as </b><span style="color: maroon">request</span><b> then</b><span style="color: navy"> {
</span>    qr<span style="color: navy"><b> -&gt; </b></span>request.method = <span style="color: blue">'POST'</span> <i>&quot;requestMethod&quot;</i><span style="color: navy">;</span>
    qr<span style="color: navy"><b> -&gt; </b></span>request.url = <span style="color: blue">'CarePlan'</span> <i>&quot;requestUrl&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">}</span> <i>&quot;entryRequest&quot;</i><span style="color: navy">;</span>
  qr.subject<b> as </b><span style="color: maroon">s</span><span style="color: navy"><b> -&gt; </b></span>r.subject = <span style="color: maroon">s</span><span style="color: navy">;</span>
<span style="color: navy">}

</span><b>group </b>SetCarePlanFullUrl<span style="color: navy">(</span><b>source</b> <span style="color: maroon">r</span><span style="color: navy"> : </span>CarePlan, <b>target</b> <span style="color: maroon">entry</span><span style="color: navy">)</span><span style="color: navy"> {
</span>  r.id<b> as </b><span style="color: maroon">id</span><span style="color: navy"><b> -&gt; </b></span>entry.fullUrl = <b>append</b><span style="color: navy">(</span><span style="color: blue">'https://fhir.slade360.co.ke/fhir/CarePlan/'</span><span style="color: navy">, </span><span style="color: maroon">id</span><span style="color: navy">)</span> <i>&quot;assignFullUrl&quot;</i><span style="color: navy">;</span>
<span style="color: navy">}

</span><b>group </b>BuildConsentBase<span style="color: navy">(</span><b>source</b> <span style="color: maroon">qr</span><span style="color: navy"> : </span>QR, <b>target</b> <span style="color: maroon">r</span><span style="color: navy"> : </span>Consent, <b>target</b> <span style="color: maroon">entry</span><span style="color: navy">)</span><span style="color: navy"> {
</span>  qr<span style="color: navy"><b> -&gt; </b></span>r<b> then </b>SetResponseProvenance<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">r</span><span style="color: navy">)</span> <i>&quot;responseProvenance&quot;</i><span style="color: navy">;</span>
  qr<span style="color: navy"><b> -&gt; </b></span>r.id = <b>uuid</b><span style="color: navy">(</span><span style="color: navy">)</span><b> then </b>SetConsentFullUrl<span style="color: navy">(</span><span style="color: maroon">r</span><span style="color: navy">, </span><span style="color: maroon">entry</span><span style="color: navy">)</span> <i>&quot;idAndFullUrl&quot;</i><span style="color: navy">;</span>
  qr<span style="color: navy"><b> -&gt; </b></span>entry.request<b> as </b><span style="color: maroon">request</span><b> then</b><span style="color: navy"> {
</span>    qr<span style="color: navy"><b> -&gt; </b></span>request.method = <span style="color: blue">'POST'</span> <i>&quot;requestMethod&quot;</i><span style="color: navy">;</span>
    qr<span style="color: navy"><b> -&gt; </b></span>request.url = <span style="color: blue">'Consent'</span> <i>&quot;requestUrl&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">}</span> <i>&quot;entryRequest&quot;</i><span style="color: navy">;</span>
  qr.subject<b> as </b><span style="color: maroon">s</span><span style="color: navy"><b> -&gt; </b></span>r.subject = <span style="color: maroon">s</span><span style="color: navy">;</span>
<span style="color: navy">}

</span><b>group </b>SetConsentFullUrl<span style="color: navy">(</span><b>source</b> <span style="color: maroon">r</span><span style="color: navy"> : </span>Consent, <b>target</b> <span style="color: maroon">entry</span><span style="color: navy">)</span><span style="color: navy"> {
</span>  r.id<b> as </b><span style="color: maroon">id</span><span style="color: navy"><b> -&gt; </b></span>entry.fullUrl = <b>append</b><span style="color: navy">(</span><span style="color: blue">'https://fhir.slade360.co.ke/fhir/Consent/'</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>BuildMedicationStatementBase<span style="color: navy">(</span><b>source</b> <span style="color: maroon">qr</span><span style="color: navy"> : </span>QR, <b>target</b> <span style="color: maroon">r</span><span style="color: navy"> : </span>MedicationStatement, <b>target</b> <span style="color: maroon">entry</span><span style="color: navy">)</span><span style="color: navy"> {
</span>  qr<span style="color: navy"><b> -&gt; </b></span>r<b> then </b>SetResponseProvenance<span style="color: navy">(</span><span style="color: maroon">qr</span><span style="color: navy">, </span><span style="color: maroon">r</span><span style="color: navy">)</span> <i>&quot;responseProvenance&quot;</i><span style="color: navy">;</span>
  qr<span style="color: navy"><b> -&gt; </b></span>r.id = <b>uuid</b><span style="color: navy">(</span><span style="color: navy">)</span><b> then </b>SetMedicationStatementFullUrl<span style="color: navy">(</span><span style="color: maroon">r</span><span style="color: navy">, </span><span style="color: maroon">entry</span><span style="color: navy">)</span> <i>&quot;idAndFullUrl&quot;</i><span style="color: navy">;</span>
  qr<span style="color: navy"><b> -&gt; </b></span>entry.request<b> as </b><span style="color: maroon">request</span><b> then</b><span style="color: navy"> {
</span>    qr<span style="color: navy"><b> -&gt; </b></span>request.method = <span style="color: blue">'POST'</span> <i>&quot;requestMethod&quot;</i><span style="color: navy">;</span>
    qr<span style="color: navy"><b> -&gt; </b></span>request.url = <span style="color: blue">'MedicationStatement'</span> <i>&quot;requestUrl&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">}</span> <i>&quot;entryRequest&quot;</i><span style="color: navy">;</span>
  qr.subject<b> as </b><span style="color: maroon">s</span><span style="color: navy"><b> -&gt; </b></span>r.subject = <span style="color: maroon">s</span><span style="color: navy">;</span>
<span style="color: navy">}

</span><b>group </b>SetMedicationStatementFullUrl<span style="color: navy">(</span><b>source</b> <span style="color: maroon">r</span><span style="color: navy"> : </span>MedicationStatement, <b>target</b> <span style="color: maroon">entry</span><span style="color: navy">)</span><span style="color: navy"> {
</span>  r.id<b> as </b><span style="color: maroon">id</span><span style="color: navy"><b> -&gt; </b></span>entry.fullUrl = <b>append</b><span style="color: navy">(</span><span style="color: blue">'https://fhir.slade360.co.ke/fhir/MedicationStatement/'</span><span style="color: navy">, </span><span style="color: maroon">id</span><span style="color: navy">)</span> <i>&quot;assignFullUrl&quot;</i><span style="color: navy">;</span>
<span style="color: navy">}

</span><span style="color: navy">// </span><span style="color: green">── Provenance and tenancy ───────────────────────────────────────────────────</span>
<span style="color: navy">// </span><span style="color: green">Two tags on everything this map creates. The first says which questionnaire</span>
<span style="color: navy">// </span><span style="color: green">produced it, so a form that reopens mid-admission recalls its own earlier</span>
<span style="color: navy">// </span><span style="color: green">entries and not another form's. The second copies the tenant tags off the</span>
<span style="color: navy">// </span><span style="color: green">response, because nothing else on the path puts them there.</span>
<span style="color: navy">// </span><span style="color: green">The code is the form's document type, not the questionnaire's id: every</span>
<span style="color: navy">// </span><span style="color: green">environment mints its own ids, and there is only one set of maps, so an id</span>
<span style="color: navy">// </span><span style="color: green">here would tie the tag to whichever environment stamped it.</span>
<span style="color: navy">// </span><span style="color: green">── Provenance and tenancy ───────────────────────────────────────────────────</span>
<b>group </b>SetResponseProvenance<span style="color: navy">(</span><b>source</b> <span style="color: maroon">qr</span><span style="color: navy"> : </span>QR, <b>target</b> <span style="color: maroon">r</span><span style="color: navy">)</span><span style="color: navy"> {
</span>  qr<span style="color: navy"><b> -&gt; </b></span>r.meta<b> as </b><span style="color: maroon">m</span><b> then</b><span style="color: navy"> {
</span>    qr<span style="color: navy"><b> -&gt; </b></span>m.tag<b> as </b><span style="color: maroon">t</span><b> then</b><span style="color: navy"> {
</span>      qr<span style="color: navy"><b> -&gt; </b></span>t.system = <span style="color: blue">'http://slade360edi.com/questionnaire-provenance'</span> <i>&quot;provenanceSystem&quot;</i><span style="color: navy">;</span>
      qr<span style="color: navy"><b> -&gt; </b></span>t.code = <span style="color: blue">'maternity-record'</span> <i>&quot;provenanceCode&quot;</i><span style="color: navy">;</span>
      qr<span style="color: navy"><b> -&gt; </b></span>t.display = <span style="color: blue">'Maternity record'</span> <i>&quot;provenanceDisplay&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;provenanceTag&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">}</span> <i>&quot;provenanceMeta&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">// </span><span style="color: green">Every tag the response carries, onto the resource. `meta` is 0..1, so this</span>
  <span style="color: navy">// </span><span style="color: green">lands on the same meta the rule above created rather than a second one.</span>
  qr.meta<b> as </b><span style="color: maroon">qm</span><b> then</b><span style="color: navy"> {
</span>    qm.tag<b> as </b><span style="color: maroon">qt</span><span style="color: navy"><b> -&gt; </b></span> r.meta<b> as </b><span style="color: maroon">m</span><span style="color: navy">, </span> m.tag = <span style="color: maroon">qt</span> <i>&quot;copyTag&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">}</span> <i>&quot;tenantTags&quot;</i><span style="color: navy">;</span>
<span style="color: navy">}

</span></pre></div>
  </text>
  <url value="https://fhir.slade360.co.ke/fhir/StructureMap/ExtractMaternityRecord"/>
  <version value="0.1.0"/>
  <name value="ExtractMaternityRecord"/>
  <title value="Maternity Record Extraction"/>
  <status value="active"/>
  <date value="2026-09-14T06:31:13+00:00"/>
  <publisher value="Kathurima Kimathi"/>
  <contact>
    <name value="Kathurima Kimathi"/>
    <telecom>
      <system value="url"/>
      <value value="https://www.linkedin.com/in/kathurima-kimathi/"/>
    </telecom>
    <telecom>
      <system value="email"/>
      <value value="kathurimakimathi415@gmail.com"/>
    </telecom>
  </contact>
  <contact>
    <name value="Oscar John"/>
    <telecom>
      <system value="email"/>
      <value value="oscarjohnotieno@gmail.com"/>
      <use value="work"/>
    </telecom>
  </contact>
  <contact>
    <name value="Kennedy Omondi"/>
    <telecom>
      <system value="email"/>
      <value value="kennankole@gmail.com"/>
      <use value="work"/>
    </telecom>
  </contact>
  <description value="The maternity record out as: the pregnancy dates and the parity as their own Observations, because a booking is read from them; an AllergyIntolerance per allergy, since that is the one thing on this record that has to reach whoever prescribes next; the family, social and obstetric histories as panels; the admission examination and the vital-plus-rapid assessment as Observations, with the blood pressure paired; a Condition per provisional and differential diagnosis; a Procedure for the delivery itself, coded by its mode and carrying the stage durations; the third-stage findings and both mother's and baby's observations as Observations of their own; a CarePlan for the management plan; and a Consent for the admission."/>
  <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/Condition"/>
    <mode value="target"/>
    <alias value="Condition"/>
  </structure>
  <structure>
    <url value="http://hl7.org/fhir/StructureDefinition/AllergyIntolerance"/>
    <mode value="target"/>
    <alias value="AllergyIntolerance"/>
  </structure>
  <structure>
    <url value="http://hl7.org/fhir/StructureDefinition/Procedure"/>
    <mode value="target"/>
    <alias value="Procedure"/>
  </structure>
  <structure>
    <url value="http://hl7.org/fhir/StructureDefinition/CarePlan"/>
    <mode value="target"/>
    <alias value="CarePlan"/>
  </structure>
  <structure>
    <url value="http://hl7.org/fhir/StructureDefinition/Consent"/>
    <mode value="target"/>
    <alias value="Consent"/>
  </structure>
  <group>
    <name value="ExtractMaternityRecord"/>
    <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="presentPregnancyGroup"/>
      <source>
        <context value="qr"/>
        <element value="item"/>
        <variable value="g"/>
        <condition value="linkId = 'present-pregnancy'"/>
      </source>
      <rule>
        <name value="measure_8665_2"/>
        <source>
          <context value="g"/>
          <element value="item"/>
          <variable value="it"/>
          <condition value="(linkId = 'present-pregnancy/lmp') and answer.value.exists()"/>
        </source>
        <target>
          <context value="bundle"/>
          <element value="entry"/>
          <variable value="entry"/>
        </target>
        <target>
          <context value="entry"/>
          <element value="resource"/>
          <variable value="obs"/>
          <transform value="create"/>
          <parameter>
            <valueString value="Observation"/>
          </parameter>
        </target>
        <rule>
          <name value="base"/>
          <source>
            <context value="qr"/>
          </source>
          <target>
            <context value="obs"/>
          </target>
          <target>
            <context value="entry"/>
          </target>
          <dependent>
            <name value="BuildObsBase"/>
            <parameter>
              <valueId value="qr"/>
            </parameter>
            <parameter>
              <valueId value="obs"/>
            </parameter>
            <parameter>
              <valueId value="entry"/>
            </parameter>
          </dependent>
        </rule>
        <rule>
          <name value="category"/>
          <source>
            <context value="qr"/>
          </source>
          <target>
            <context value="obs"/>
          </target>
          <dependent>
            <name value="SetSurveyCategory"/>
            <parameter>
              <valueId value="qr"/>
            </parameter>
            <parameter>
              <valueId value="obs"/>
            </parameter>
          </dependent>
        </rule>
        <rule>
          <name value="code"/>
          <source>
            <context value="it"/>
          </source>
          <target>
            <context value="obs"/>
            <element value="code"/>
            <variable value="cc"/>
          </target>
          <rule>
            <name value="coding"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="cc"/>
              <element value="coding"/>
              <variable value="cg"/>
            </target>
            <rule>
              <name value="sys"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="system"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="http://loinc.org"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="cd"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="code"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="8665-2"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="dsp"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="display"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="Last menstrual period start date"/>
                </parameter>
              </target>
            </rule>
          </rule>
        </rule>
        <rule>
          <name value="answer"/>
          <source>
            <context value="it"/>
            <element value="answer"/>
            <listMode value="first"/>
            <variable value="a"/>
          </source>
          <rule>
            <name value="set"/>
            <source>
              <context value="a"/>
              <element value="value"/>
              <variable value="v"/>
            </source>
            <target>
              <context value="obs"/>
              <element value="value"/>
              <transform value="cast"/>
              <parameter>
                <valueId value="v"/>
              </parameter>
              <parameter>
                <valueString value="dateTime"/>
              </parameter>
            </target>
          </rule>
        </rule>
      </rule>
      <rule>
        <name value="measure_11778_8"/>
        <source>
          <context value="g"/>
          <element value="item"/>
          <variable value="it"/>
          <condition value="(linkId = 'present-pregnancy/edd-by-dates') and answer.value.exists()"/>
        </source>
        <target>
          <context value="bundle"/>
          <element value="entry"/>
          <variable value="entry"/>
        </target>
        <target>
          <context value="entry"/>
          <element value="resource"/>
          <variable value="obs"/>
          <transform value="create"/>
          <parameter>
            <valueString value="Observation"/>
          </parameter>
        </target>
        <rule>
          <name value="base"/>
          <source>
            <context value="qr"/>
          </source>
          <target>
            <context value="obs"/>
          </target>
          <target>
            <context value="entry"/>
          </target>
          <dependent>
            <name value="BuildObsBase"/>
            <parameter>
              <valueId value="qr"/>
            </parameter>
            <parameter>
              <valueId value="obs"/>
            </parameter>
            <parameter>
              <valueId value="entry"/>
            </parameter>
          </dependent>
        </rule>
        <rule>
          <name value="category"/>
          <source>
            <context value="qr"/>
          </source>
          <target>
            <context value="obs"/>
          </target>
          <dependent>
            <name value="SetSurveyCategory"/>
            <parameter>
              <valueId value="qr"/>
            </parameter>
            <parameter>
              <valueId value="obs"/>
            </parameter>
          </dependent>
        </rule>
        <rule>
          <name value="code"/>
          <source>
            <context value="it"/>
          </source>
          <target>
            <context value="obs"/>
            <element value="code"/>
            <variable value="cc"/>
          </target>
          <rule>
            <name value="coding"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="cc"/>
              <element value="coding"/>
              <variable value="cg"/>
            </target>
            <rule>
              <name value="sys"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="system"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="http://loinc.org"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="cd"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="code"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="11778-8"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="dsp"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="display"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="Delivery date Estimated"/>
                </parameter>
              </target>
            </rule>
          </rule>
        </rule>
        <rule>
          <name value="answer"/>
          <source>
            <context value="it"/>
            <element value="answer"/>
            <listMode value="first"/>
            <variable value="a"/>
          </source>
          <rule>
            <name value="set"/>
            <source>
              <context value="a"/>
              <element value="value"/>
              <variable value="v"/>
            </source>
            <target>
              <context value="obs"/>
              <element value="value"/>
              <transform value="cast"/>
              <parameter>
                <valueId value="v"/>
              </parameter>
              <parameter>
                <valueString value="dateTime"/>
              </parameter>
            </target>
          </rule>
        </rule>
        <rule>
          <name value="note"/>
          <source>
            <context value="it"/>
          </source>
          <target>
            <context value="obs"/>
            <element value="note"/>
            <variable value="n"/>
          </target>
          <target>
            <context value="n"/>
            <element value="text"/>
            <transform value="copy"/>
            <parameter>
              <valueString value="Estimated from the last menstrual period."/>
            </parameter>
          </target>
        </rule>
      </rule>
      <rule>
        <name value="measure_11778_82"/>
        <source>
          <context value="g"/>
          <element value="item"/>
          <variable value="it"/>
          <condition value="(linkId = 'present-pregnancy/edd-final') and answer.value.exists()"/>
        </source>
        <target>
          <context value="bundle"/>
          <element value="entry"/>
          <variable value="entry"/>
        </target>
        <target>
          <context value="entry"/>
          <element value="resource"/>
          <variable value="obs"/>
          <transform value="create"/>
          <parameter>
            <valueString value="Observation"/>
          </parameter>
        </target>
        <rule>
          <name value="base"/>
          <source>
            <context value="qr"/>
          </source>
          <target>
            <context value="obs"/>
          </target>
          <target>
            <context value="entry"/>
          </target>
          <dependent>
            <name value="BuildObsBase"/>
            <parameter>
              <valueId value="qr"/>
            </parameter>
            <parameter>
              <valueId value="obs"/>
            </parameter>
            <parameter>
              <valueId value="entry"/>
            </parameter>
          </dependent>
        </rule>
        <rule>
          <name value="category"/>
          <source>
            <context value="qr"/>
          </source>
          <target>
            <context value="obs"/>
          </target>
          <dependent>
            <name value="SetSurveyCategory"/>
            <parameter>
              <valueId value="qr"/>
            </parameter>
            <parameter>
              <valueId value="obs"/>
            </parameter>
          </dependent>
        </rule>
        <rule>
          <name value="code"/>
          <source>
            <context value="it"/>
          </source>
          <target>
            <context value="obs"/>
            <element value="code"/>
            <variable value="cc"/>
          </target>
          <rule>
            <name value="coding"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="cc"/>
              <element value="coding"/>
              <variable value="cg"/>
            </target>
            <rule>
              <name value="sys"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="system"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="http://loinc.org"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="cd"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="code"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="11778-8"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="dsp"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="display"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="Delivery date Estimated"/>
                </parameter>
              </target>
            </rule>
          </rule>
        </rule>
        <rule>
          <name value="answer"/>
          <source>
            <context value="it"/>
            <element value="answer"/>
            <listMode value="first"/>
            <variable value="a"/>
          </source>
          <rule>
            <name value="set"/>
            <source>
              <context value="a"/>
              <element value="value"/>
              <variable value="v"/>
            </source>
            <target>
              <context value="obs"/>
              <element value="value"/>
              <transform value="cast"/>
              <parameter>
                <valueId value="v"/>
              </parameter>
              <parameter>
                <valueString value="dateTime"/>
              </parameter>
            </target>
          </rule>
        </rule>
        <rule>
          <name value="note"/>
          <source>
            <context value="it"/>
          </source>
          <target>
            <context value="obs"/>
            <element value="note"/>
            <variable value="n"/>
          </target>
          <target>
            <context value="n"/>
            <element value="text"/>
            <transform value="copy"/>
            <parameter>
              <valueString value="The final agreed date after the dating scan. Where this differs from the date by LMP, this is the one care was planned against."/>
            </parameter>
          </target>
        </rule>
      </rule>
      <rule>
        <name value="measure_labour_stage_duration"/>
        <source>
          <context value="g"/>
          <element value="item"/>
          <variable value="it"/>
          <condition value="(linkId = 'present-pregnancy/anc-visits') and answer.value.exists()"/>
        </source>
        <target>
          <context value="bundle"/>
          <element value="entry"/>
          <variable value="entry"/>
        </target>
        <target>
          <context value="entry"/>
          <element value="resource"/>
          <variable value="obs"/>
          <transform value="create"/>
          <parameter>
            <valueString value="Observation"/>
          </parameter>
        </target>
        <rule>
          <name value="base"/>
          <source>
            <context value="qr"/>
          </source>
          <target>
            <context value="obs"/>
          </target>
          <target>
            <context value="entry"/>
          </target>
          <dependent>
            <name value="BuildObsBase"/>
            <parameter>
              <valueId value="qr"/>
            </parameter>
            <parameter>
              <valueId value="obs"/>
            </parameter>
            <parameter>
              <valueId value="entry"/>
            </parameter>
          </dependent>
        </rule>
        <rule>
          <name value="category"/>
          <source>
            <context value="qr"/>
          </source>
          <target>
            <context value="obs"/>
          </target>
          <dependent>
            <name value="SetSurveyCategory"/>
            <parameter>
              <valueId value="qr"/>
            </parameter>
            <parameter>
              <valueId value="obs"/>
            </parameter>
          </dependent>
        </rule>
        <rule>
          <name value="code"/>
          <source>
            <context value="it"/>
          </source>
          <target>
            <context value="obs"/>
            <element value="code"/>
            <variable value="cc"/>
          </target>
          <rule>
            <name value="coding"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="cc"/>
              <element value="coding"/>
              <variable value="cg"/>
            </target>
            <rule>
              <name value="sys"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="system"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="cd"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="code"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="obs-number-of-antenatal-visits"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="dsp"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="display"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="Number of antenatal visits"/>
                </parameter>
              </target>
            </rule>
          </rule>
        </rule>
        <rule>
          <name value="answer"/>
          <source>
            <context value="it"/>
            <element value="answer"/>
            <listMode value="first"/>
            <variable value="a"/>
          </source>
          <rule>
            <name value="set"/>
            <source>
              <context value="a"/>
              <element value="value"/>
              <variable value="v"/>
            </source>
            <target>
              <context value="obs"/>
              <element value="value"/>
              <transform value="copy"/>
              <parameter>
                <valueId value="v"/>
              </parameter>
            </target>
          </rule>
        </rule>
      </rule>
      <rule>
        <name value="narr_10164_2"/>
        <source>
          <context value="g"/>
          <element value="item"/>
          <variable value="it"/>
          <condition value="(linkId = 'present-pregnancy/other-significant-history') and answer.value.exists()"/>
        </source>
        <target>
          <context value="bundle"/>
          <element value="entry"/>
          <variable value="entry"/>
        </target>
        <target>
          <context value="entry"/>
          <element value="resource"/>
          <variable value="obs"/>
          <transform value="create"/>
          <parameter>
            <valueString value="Observation"/>
          </parameter>
        </target>
        <rule>
          <name value="base"/>
          <source>
            <context value="qr"/>
          </source>
          <target>
            <context value="obs"/>
          </target>
          <target>
            <context value="entry"/>
          </target>
          <dependent>
            <name value="BuildObsBase"/>
            <parameter>
              <valueId value="qr"/>
            </parameter>
            <parameter>
              <valueId value="obs"/>
            </parameter>
            <parameter>
              <valueId value="entry"/>
            </parameter>
          </dependent>
        </rule>
        <rule>
          <name value="category"/>
          <source>
            <context value="qr"/>
          </source>
          <target>
            <context value="obs"/>
          </target>
          <dependent>
            <name value="SetSurveyCategory"/>
            <parameter>
              <valueId value="qr"/>
            </parameter>
            <parameter>
              <valueId value="obs"/>
            </parameter>
          </dependent>
        </rule>
        <rule>
          <name value="code"/>
          <source>
            <context value="it"/>
          </source>
          <target>
            <context value="obs"/>
            <element value="code"/>
            <variable value="cc"/>
          </target>
          <rule>
            <name value="coding"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="cc"/>
              <element value="coding"/>
              <variable value="cg"/>
            </target>
            <rule>
              <name value="sys"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="system"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="http://loinc.org"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="cd"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="code"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="10164-2"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="dsp"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="display"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="History of Present illness Narrative"/>
                </parameter>
              </target>
            </rule>
          </rule>
          <rule>
            <name value="codeText"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="cc"/>
              <element value="text"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="Other significant history of this pregnancy"/>
              </parameter>
            </target>
          </rule>
        </rule>
        <rule>
          <name value="answer"/>
          <source>
            <context value="it"/>
            <element value="answer"/>
            <listMode value="first"/>
            <variable value="a"/>
          </source>
          <rule>
            <name value="text"/>
            <source>
              <context value="a"/>
              <element value="value"/>
              <variable value="txt"/>
            </source>
            <target>
              <context value="obs"/>
              <element value="note"/>
              <variable value="n"/>
            </target>
            <target>
              <context value="n"/>
              <element value="text"/>
              <transform value="copy"/>
              <parameter>
                <valueId value="txt"/>
              </parameter>
            </target>
          </rule>
        </rule>
      </rule>
      <documentation value="── The present pregnancy's dates ───────────────────────────────────────&#xD;&#xA;LMP, EDD by dates and the final agreed EDD after a dating scan, each as its&#xD;&#xA;own Observation. All three are kept: the gap between an EDD by dates and an&#xD;&#xA;EDD by scan is what a post-dates decision turns on, and collapsing them&#xD;&#xA;into one would erase the disagreement."/>
    </rule>
    <rule>
      <name value="parityObservation"/>
      <source>
        <context value="qr"/>
        <element value="item"/>
        <variable value="g"/>
        <condition value="(linkId = 'obstetric-history') and item.where(linkId = 'obstetric-history/parity').answer.value.exists()"/>
      </source>
      <target>
        <context value="bundle"/>
        <element value="entry"/>
        <variable value="entry"/>
      </target>
      <target>
        <context value="entry"/>
        <element value="resource"/>
        <variable value="obs"/>
        <transform value="create"/>
        <parameter>
          <valueString value="Observation"/>
        </parameter>
      </target>
      <rule>
        <name value="base"/>
        <source>
          <context value="qr"/>
        </source>
        <target>
          <context value="obs"/>
        </target>
        <target>
          <context value="entry"/>
        </target>
        <dependent>
          <name value="BuildObsBase"/>
          <parameter>
            <valueId value="qr"/>
          </parameter>
          <parameter>
            <valueId value="obs"/>
          </parameter>
          <parameter>
            <valueId value="entry"/>
          </parameter>
        </dependent>
      </rule>
      <rule>
        <name value="category"/>
        <source>
          <context value="qr"/>
        </source>
        <target>
          <context value="obs"/>
        </target>
        <dependent>
          <name value="SetSurveyCategory"/>
          <parameter>
            <valueId value="qr"/>
          </parameter>
          <parameter>
            <valueId value="obs"/>
          </parameter>
        </dependent>
      </rule>
      <rule>
        <name value="code"/>
        <source>
          <context value="g"/>
        </source>
        <target>
          <context value="obs"/>
          <element value="code"/>
          <variable value="cc"/>
        </target>
        <rule>
          <name value="coding"/>
          <source>
            <context value="g"/>
          </source>
          <target>
            <context value="cc"/>
            <element value="coding"/>
            <variable value="cg"/>
          </target>
          <rule>
            <name value="sys"/>
            <source>
              <context value="g"/>
            </source>
            <target>
              <context value="cg"/>
              <element value="system"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="http://loinc.org"/>
              </parameter>
            </target>
          </rule>
          <rule>
            <name value="cd"/>
            <source>
              <context value="g"/>
            </source>
            <target>
              <context value="cg"/>
              <element value="code"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="11977-6"/>
              </parameter>
            </target>
          </rule>
          <rule>
            <name value="dsp"/>
            <source>
              <context value="g"/>
            </source>
            <target>
              <context value="cg"/>
              <element value="display"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="[#] Parity"/>
              </parameter>
            </target>
          </rule>
        </rule>
      </rule>
      <rule>
        <name value="parityRule"/>
        <source>
          <context value="g"/>
          <element value="item"/>
          <variable value="it"/>
          <condition value="linkId = 'obstetric-history/parity'"/>
        </source>
        <rule>
          <name value="answer"/>
          <source>
            <context value="it"/>
            <element value="answer"/>
            <listMode value="first"/>
            <variable value="a"/>
          </source>
          <rule>
            <name value="parityValue"/>
            <source>
              <context value="a"/>
              <element value="value"/>
              <variable value="v"/>
            </source>
            <target>
              <context value="obs"/>
              <element value="value"/>
              <transform value="copy"/>
              <parameter>
                <valueId value="v"/>
              </parameter>
            </target>
          </rule>
        </rule>
      </rule>
      <rule>
        <name value="comp_obs_abortions"/>
        <source>
          <context value="g"/>
          <element value="item"/>
          <variable value="it"/>
          <condition value="(linkId = 'obstetric-history/abortions') and answer.value.exists()"/>
        </source>
        <target>
          <context value="obs"/>
          <element value="component"/>
          <variable value="comp"/>
        </target>
        <rule>
          <name value="code"/>
          <source>
            <context value="it"/>
          </source>
          <target>
            <context value="comp"/>
            <element value="code"/>
            <variable value="cc"/>
          </target>
          <rule>
            <name value="coding"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="cc"/>
              <element value="coding"/>
              <variable value="cg"/>
            </target>
            <rule>
              <name value="sys"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="system"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="cd"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="code"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="obs-abortions"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="dsp"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="display"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="Abortions"/>
                </parameter>
              </target>
            </rule>
          </rule>
        </rule>
        <rule>
          <name value="value"/>
          <source>
            <context value="it"/>
          </source>
          <target>
            <context value="comp"/>
          </target>
          <dependent>
            <name value="SetComponentValue"/>
            <parameter>
              <valueId value="it"/>
            </parameter>
            <parameter>
              <valueId value="comp"/>
            </parameter>
          </dependent>
        </rule>
      </rule>
      <documentation value="── Parity ──────────────────────────────────────────────────────────────&#xD;&#xA;LOINC 11977-6, [#] Parity, with the abortion count beside it as a&#xD;&#xA;component: the sheet prints them as &quot;para 3 + 1&quot; and the two numbers are&#xD;&#xA;read together."/>
    </rule>
    <rule>
      <name value="allergiesGroup"/>
      <source>
        <context value="qr"/>
        <element value="item"/>
        <variable value="ag"/>
        <condition value="linkId = 'allergies'"/>
      </source>
      <rule>
        <name value="createAllergy"/>
        <source>
          <context value="ag"/>
          <element value="item"/>
          <variable value="g"/>
          <condition value="(linkId = 'allergies/allergy') and item.where(linkId = 'allergies/allergy/substance').answer.value.exists()"/>
        </source>
        <target>
          <context value="bundle"/>
          <element value="entry"/>
          <variable value="entry"/>
        </target>
        <target>
          <context value="entry"/>
          <element value="resource"/>
          <variable value="allergy"/>
          <transform value="create"/>
          <parameter>
            <valueString value="AllergyIntolerance"/>
          </parameter>
        </target>
        <rule>
          <name value="base"/>
          <source>
            <context value="qr"/>
          </source>
          <target>
            <context value="allergy"/>
          </target>
          <target>
            <context value="entry"/>
          </target>
          <dependent>
            <name value="BuildAllergyIntoleranceBase"/>
            <parameter>
              <valueId value="qr"/>
            </parameter>
            <parameter>
              <valueId value="allergy"/>
            </parameter>
            <parameter>
              <valueId value="entry"/>
            </parameter>
          </dependent>
        </rule>
        <rule>
          <name value="clinicalStatus"/>
          <source>
            <context value="g"/>
          </source>
          <target>
            <context value="allergy"/>
            <element value="clinicalStatus"/>
            <variable value="cs"/>
          </target>
          <rule>
            <name value="coding"/>
            <source>
              <context value="g"/>
            </source>
            <target>
              <context value="cs"/>
              <element value="coding"/>
              <variable value="cg"/>
            </target>
            <rule>
              <name value="sys"/>
              <source>
                <context value="g"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="system"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="http://terminology.hl7.org/CodeSystem/allergyintolerance-clinical"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="cd"/>
              <source>
                <context value="g"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="code"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="active"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="dsp"/>
              <source>
                <context value="g"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="display"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="Active"/>
                </parameter>
              </target>
            </rule>
          </rule>
        </rule>
        <rule>
          <name value="verificationStatus"/>
          <source>
            <context value="g"/>
          </source>
          <target>
            <context value="allergy"/>
            <element value="verificationStatus"/>
            <variable value="vs"/>
          </target>
          <rule>
            <name value="coding"/>
            <source>
              <context value="g"/>
            </source>
            <target>
              <context value="vs"/>
              <element value="coding"/>
              <variable value="cg"/>
            </target>
            <rule>
              <name value="sys"/>
              <source>
                <context value="g"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="system"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="http://terminology.hl7.org/CodeSystem/allergyintolerance-verification"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="cd"/>
              <source>
                <context value="g"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="code"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="unconfirmed"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="dsp"/>
              <source>
                <context value="g"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="display"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="Unconfirmed"/>
                </parameter>
              </target>
            </rule>
          </rule>
        </rule>
        <rule>
          <name value="substanceRule"/>
          <source>
            <context value="g"/>
            <element value="item"/>
            <variable value="it"/>
            <condition value="linkId = 'allergies/allergy/substance'"/>
          </source>
          <rule>
            <name value="answer"/>
            <source>
              <context value="it"/>
              <element value="answer"/>
              <listMode value="first"/>
              <variable value="a"/>
            </source>
            <rule>
              <name value="substanceText"/>
              <source>
                <context value="a"/>
                <element value="value"/>
                <variable value="txt"/>
              </source>
              <target>
                <context value="allergy"/>
                <element value="code"/>
                <variable value="cc"/>
              </target>
              <target>
                <context value="cc"/>
                <element value="text"/>
                <transform value="copy"/>
                <parameter>
                  <valueId value="txt"/>
                </parameter>
              </target>
            </rule>
          </rule>
        </rule>
        <rule>
          <name value="reactionRule"/>
          <source>
            <context value="g"/>
            <element value="item"/>
            <variable value="it"/>
            <condition value="(linkId = 'allergies/allergy/reaction') and answer.value.exists()"/>
          </source>
          <rule>
            <name value="answer"/>
            <source>
              <context value="it"/>
              <element value="answer"/>
              <listMode value="first"/>
              <variable value="a"/>
            </source>
            <rule>
              <name value="manifestationText"/>
              <source>
                <context value="a"/>
                <element value="value"/>
                <variable value="txt"/>
              </source>
              <target>
                <context value="allergy"/>
                <element value="reaction"/>
                <variable value="rx"/>
              </target>
              <target>
                <context value="rx"/>
                <element value="manifestation"/>
                <variable value="man"/>
              </target>
              <target>
                <context value="man"/>
                <element value="concept"/>
                <variable value="mc"/>
              </target>
              <target>
                <context value="mc"/>
                <element value="text"/>
                <transform value="copy"/>
                <parameter>
                  <valueId value="txt"/>
                </parameter>
              </target>
            </rule>
          </rule>
        </rule>
        <rule>
          <name value="recordedDate"/>
          <source>
            <context value="qr"/>
            <element value="authored"/>
            <variable value="t"/>
          </source>
          <target>
            <context value="allergy"/>
            <element value="recordedDate"/>
            <transform value="copy"/>
            <parameter>
              <valueId value="t"/>
            </parameter>
          </target>
        </rule>
      </rule>
      <rule>
        <name value="noKnownAllergies"/>
        <source>
          <context value="ag"/>
          <element value="item"/>
          <variable value="it"/>
          <condition value="(linkId = 'allergies/none-known') and (answer.value.ofType(Coding).code = 'Y')"/>
        </source>
        <target>
          <context value="bundle"/>
          <element value="entry"/>
          <variable value="entry"/>
        </target>
        <target>
          <context value="entry"/>
          <element value="resource"/>
          <variable value="allergy"/>
          <transform value="create"/>
          <parameter>
            <valueString value="AllergyIntolerance"/>
          </parameter>
        </target>
        <rule>
          <name value="base"/>
          <source>
            <context value="qr"/>
          </source>
          <target>
            <context value="allergy"/>
          </target>
          <target>
            <context value="entry"/>
          </target>
          <dependent>
            <name value="BuildAllergyIntoleranceBase"/>
            <parameter>
              <valueId value="qr"/>
            </parameter>
            <parameter>
              <valueId value="allergy"/>
            </parameter>
            <parameter>
              <valueId value="entry"/>
            </parameter>
          </dependent>
        </rule>
        <rule>
          <name value="clinicalStatus"/>
          <source>
            <context value="it"/>
          </source>
          <target>
            <context value="allergy"/>
            <element value="clinicalStatus"/>
            <variable value="cs"/>
          </target>
          <rule>
            <name value="coding"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="cs"/>
              <element value="coding"/>
              <variable value="cg"/>
            </target>
            <rule>
              <name value="sys"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="system"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="http://terminology.hl7.org/CodeSystem/allergyintolerance-clinical"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="cd"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="code"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="active"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="dsp"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="display"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="Active"/>
                </parameter>
              </target>
            </rule>
          </rule>
        </rule>
        <rule>
          <name value="code"/>
          <source>
            <context value="it"/>
          </source>
          <target>
            <context value="allergy"/>
            <element value="code"/>
            <variable value="cc"/>
          </target>
          <rule>
            <name value="coding"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="cc"/>
              <element value="coding"/>
              <variable value="cg"/>
            </target>
            <rule>
              <name value="sys"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="system"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="http://terminology.hl7.org/CodeSystem/v3-NullFlavor"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="cd"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="code"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="NA"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="dsp"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="display"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="not applicable"/>
                </parameter>
              </target>
            </rule>
          </rule>
          <rule>
            <name value="codeText"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="cc"/>
              <element value="text"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="No known allergies"/>
              </parameter>
            </target>
          </rule>
        </rule>
        <rule>
          <name value="recordedDate"/>
          <source>
            <context value="qr"/>
            <element value="authored"/>
            <variable value="t"/>
          </source>
          <target>
            <context value="allergy"/>
            <element value="recordedDate"/>
            <transform value="copy"/>
            <parameter>
              <valueId value="t"/>
            </parameter>
          </target>
        </rule>
        <documentation value="&quot;No known allergies&quot; is a positive statement and gets its own&#xD;&#xA;AllergyIntolerance with the HL7 no-known-allergy code -- which is the&#xD;&#xA;difference between a woman who was asked and had none and a woman nobody&#xD;&#xA;asked."/>
      </rule>
      <documentation value="── Allergies ───────────────────────────────────────────────────────────&#xD;&#xA;AllergyIntolerance per row. This is the one thing on a maternity record&#xD;&#xA;that has to be visible to whoever prescribes next, and a note on an&#xD;&#xA;Observation is not visible to a prescribing system.&#xD;&#xA;verificationStatus is 'unconfirmed': what the sheet holds is the woman's&#xD;&#xA;own account at booking. `reaction.manifestation` carries what she said&#xD;&#xA;happens, as text, because the sheet takes free text and a coded&#xD;&#xA;manifestation would be an invention."/>
    </rule>
    <rule>
      <name value="obstetricHistoryGroup"/>
      <source>
        <context value="qr"/>
        <element value="item"/>
        <variable value="og"/>
        <condition value="linkId = 'obstetric-history'"/>
      </source>
      <rule>
        <name value="previousPregnancy"/>
        <source>
          <context value="og"/>
          <element value="item"/>
          <variable value="g"/>
          <condition value="(linkId = 'obstetric-history/pregnancy') and item.answer.value.exists()"/>
        </source>
        <target>
          <context value="bundle"/>
          <element value="entry"/>
          <variable value="entry"/>
        </target>
        <target>
          <context value="entry"/>
          <element value="resource"/>
          <variable value="obs"/>
          <transform value="create"/>
          <parameter>
            <valueString value="Observation"/>
          </parameter>
        </target>
        <rule>
          <name value="base"/>
          <source>
            <context value="qr"/>
          </source>
          <target>
            <context value="obs"/>
          </target>
          <target>
            <context value="entry"/>
          </target>
          <dependent>
            <name value="BuildObsBase"/>
            <parameter>
              <valueId value="qr"/>
            </parameter>
            <parameter>
              <valueId value="obs"/>
            </parameter>
            <parameter>
              <valueId value="entry"/>
            </parameter>
          </dependent>
        </rule>
        <rule>
          <name value="category"/>
          <source>
            <context value="qr"/>
          </source>
          <target>
            <context value="obs"/>
          </target>
          <dependent>
            <name value="SetSurveyCategory"/>
            <parameter>
              <valueId value="qr"/>
            </parameter>
            <parameter>
              <valueId value="obs"/>
            </parameter>
          </dependent>
        </rule>
        <rule>
          <name value="code"/>
          <source>
            <context value="g"/>
          </source>
          <target>
            <context value="obs"/>
            <element value="code"/>
            <variable value="cc"/>
          </target>
          <rule>
            <name value="coding"/>
            <source>
              <context value="g"/>
            </source>
            <target>
              <context value="cc"/>
              <element value="coding"/>
              <variable value="cg"/>
            </target>
            <rule>
              <name value="sys"/>
              <source>
                <context value="g"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="system"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="http://loinc.org"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="cd"/>
              <source>
                <context value="g"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="code"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="10162-6"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="dsp"/>
              <source>
                <context value="g"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="display"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="History of pregnancies Narrative"/>
                </parameter>
              </target>
            </rule>
          </rule>
          <rule>
            <name value="codeText"/>
            <source>
              <context value="g"/>
            </source>
            <target>
              <context value="cc"/>
              <element value="text"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="Previous pregnancy"/>
              </parameter>
            </target>
          </rule>
        </rule>
        <rule>
          <name value="comp_obs_year"/>
          <source>
            <context value="g"/>
            <element value="item"/>
            <variable value="it"/>
            <condition value="(linkId = 'obstetric-history/pregnancy/year') and answer.value.exists()"/>
          </source>
          <target>
            <context value="obs"/>
            <element value="component"/>
            <variable value="comp"/>
          </target>
          <rule>
            <name value="code"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="comp"/>
              <element value="code"/>
              <variable value="cc"/>
            </target>
            <rule>
              <name value="coding"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cc"/>
                <element value="coding"/>
                <variable value="cg"/>
              </target>
              <rule>
                <name value="sys"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="system"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="cd"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="code"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="obs-year"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="dsp"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="display"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="Year"/>
                  </parameter>
                </target>
              </rule>
            </rule>
          </rule>
          <rule>
            <name value="value"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="comp"/>
            </target>
            <dependent>
              <name value="SetComponentValue"/>
              <parameter>
                <valueId value="it"/>
              </parameter>
              <parameter>
                <valueId value="comp"/>
              </parameter>
            </dependent>
          </rule>
        </rule>
        <rule>
          <name value="comp_11884_4"/>
          <source>
            <context value="g"/>
            <element value="item"/>
            <variable value="it"/>
            <condition value="(linkId = 'obstetric-history/pregnancy/gestation') and answer.value.exists()"/>
          </source>
          <target>
            <context value="obs"/>
            <element value="component"/>
            <variable value="comp"/>
          </target>
          <rule>
            <name value="code"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="comp"/>
              <element value="code"/>
              <variable value="cc"/>
            </target>
            <rule>
              <name value="coding"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cc"/>
                <element value="coding"/>
                <variable value="cg"/>
              </target>
              <rule>
                <name value="sys"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="system"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="http://loinc.org"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="cd"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="code"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="11884-4"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="dsp"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="display"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="Gestational age Estimated"/>
                  </parameter>
                </target>
              </rule>
            </rule>
          </rule>
          <rule>
            <name value="value"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="comp"/>
            </target>
            <dependent>
              <name value="SetComponentValue"/>
              <parameter>
                <valueId value="it"/>
              </parameter>
              <parameter>
                <valueId value="comp"/>
              </parameter>
            </dependent>
          </rule>
        </rule>
        <rule>
          <name value="comp_obstetric_mode_of_delivery"/>
          <source>
            <context value="g"/>
            <element value="item"/>
            <variable value="it"/>
            <condition value="(linkId = 'obstetric-history/pregnancy/mode-of-delivery') and answer.value.exists()"/>
          </source>
          <target>
            <context value="obs"/>
            <element value="component"/>
            <variable value="comp"/>
          </target>
          <rule>
            <name value="code"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="comp"/>
              <element value="code"/>
              <variable value="cc"/>
            </target>
            <rule>
              <name value="coding"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cc"/>
                <element value="coding"/>
                <variable value="cg"/>
              </target>
              <rule>
                <name value="sys"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="system"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="cd"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="code"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="obstetric-mode-of-delivery"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="dsp"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="display"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="Mode of delivery"/>
                  </parameter>
                </target>
              </rule>
            </rule>
          </rule>
          <rule>
            <name value="value"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="comp"/>
            </target>
            <dependent>
              <name value="SetComponentCodedValue"/>
              <parameter>
                <valueId value="it"/>
              </parameter>
              <parameter>
                <valueId value="comp"/>
              </parameter>
            </dependent>
          </rule>
        </rule>
        <rule>
          <name value="comp_8339_4"/>
          <source>
            <context value="g"/>
            <element value="item"/>
            <variable value="it"/>
            <condition value="(linkId = 'obstetric-history/pregnancy/birth-weight') and answer.value.exists()"/>
          </source>
          <target>
            <context value="obs"/>
            <element value="component"/>
            <variable value="comp"/>
          </target>
          <rule>
            <name value="code"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="comp"/>
              <element value="code"/>
              <variable value="cc"/>
            </target>
            <rule>
              <name value="coding"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cc"/>
                <element value="coding"/>
                <variable value="cg"/>
              </target>
              <rule>
                <name value="sys"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="system"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="http://loinc.org"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="cd"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="code"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="8339-4"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="dsp"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="display"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="Birth weight Measured"/>
                  </parameter>
                </target>
              </rule>
            </rule>
          </rule>
          <rule>
            <name value="value"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="comp"/>
            </target>
            <dependent>
              <name value="SetComponentValue"/>
              <parameter>
                <valueId value="it"/>
              </parameter>
              <parameter>
                <valueId value="comp"/>
              </parameter>
            </dependent>
          </rule>
        </rule>
        <rule>
          <name value="comp_obs_outcome"/>
          <source>
            <context value="g"/>
            <element value="item"/>
            <variable value="it"/>
            <condition value="(linkId = 'obstetric-history/pregnancy/outcome') and answer.value.exists()"/>
          </source>
          <target>
            <context value="obs"/>
            <element value="component"/>
            <variable value="comp"/>
          </target>
          <rule>
            <name value="code"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="comp"/>
              <element value="code"/>
              <variable value="cc"/>
            </target>
            <rule>
              <name value="coding"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cc"/>
                <element value="coding"/>
                <variable value="cg"/>
              </target>
              <rule>
                <name value="sys"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="system"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="cd"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="code"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="obs-outcome"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="dsp"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="display"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="Outcome"/>
                  </parameter>
                </target>
              </rule>
            </rule>
          </rule>
          <rule>
            <name value="value"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="comp"/>
            </target>
            <dependent>
              <name value="SetComponentValue"/>
              <parameter>
                <valueId value="it"/>
              </parameter>
              <parameter>
                <valueId value="comp"/>
              </parameter>
            </dependent>
          </rule>
        </rule>
        <rule>
          <name value="comp_obs_course_of_the_pregnancy"/>
          <source>
            <context value="g"/>
            <element value="item"/>
            <variable value="it"/>
            <condition value="(linkId = 'obstetric-history/pregnancy/pregnancy-course') and answer.value.exists()"/>
          </source>
          <target>
            <context value="obs"/>
            <element value="component"/>
            <variable value="comp"/>
          </target>
          <rule>
            <name value="code"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="comp"/>
              <element value="code"/>
              <variable value="cc"/>
            </target>
            <rule>
              <name value="coding"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cc"/>
                <element value="coding"/>
                <variable value="cg"/>
              </target>
              <rule>
                <name value="sys"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="system"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="cd"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="code"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="obs-course-of-the-pregnancy"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="dsp"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="display"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="Course of the pregnancy"/>
                  </parameter>
                </target>
              </rule>
            </rule>
          </rule>
          <rule>
            <name value="value"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="comp"/>
            </target>
            <dependent>
              <name value="SetComponentValue"/>
              <parameter>
                <valueId value="it"/>
              </parameter>
              <parameter>
                <valueId value="comp"/>
              </parameter>
            </dependent>
          </rule>
        </rule>
        <rule>
          <name value="comp_obs_labour"/>
          <source>
            <context value="g"/>
            <element value="item"/>
            <variable value="it"/>
            <condition value="(linkId = 'obstetric-history/pregnancy/labour') and answer.value.exists()"/>
          </source>
          <target>
            <context value="obs"/>
            <element value="component"/>
            <variable value="comp"/>
          </target>
          <rule>
            <name value="code"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="comp"/>
              <element value="code"/>
              <variable value="cc"/>
            </target>
            <rule>
              <name value="coding"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cc"/>
                <element value="coding"/>
                <variable value="cg"/>
              </target>
              <rule>
                <name value="sys"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="system"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="cd"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="code"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="obs-labour"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="dsp"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="display"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="Labour"/>
                  </parameter>
                </target>
              </rule>
            </rule>
          </rule>
          <rule>
            <name value="value"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="comp"/>
            </target>
            <dependent>
              <name value="SetComponentValue"/>
              <parameter>
                <valueId value="it"/>
              </parameter>
              <parameter>
                <valueId value="comp"/>
              </parameter>
            </dependent>
          </rule>
        </rule>
        <rule>
          <name value="comp_obs_puerperium"/>
          <source>
            <context value="g"/>
            <element value="item"/>
            <variable value="it"/>
            <condition value="(linkId = 'obstetric-history/pregnancy/puerperium') and answer.value.exists()"/>
          </source>
          <target>
            <context value="obs"/>
            <element value="component"/>
            <variable value="comp"/>
          </target>
          <rule>
            <name value="code"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="comp"/>
              <element value="code"/>
              <variable value="cc"/>
            </target>
            <rule>
              <name value="coding"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cc"/>
                <element value="coding"/>
                <variable value="cg"/>
              </target>
              <rule>
                <name value="sys"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="system"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="cd"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="code"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="obs-puerperium"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="dsp"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="display"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="Puerperium"/>
                  </parameter>
                </target>
              </rule>
            </rule>
          </rule>
          <rule>
            <name value="value"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="comp"/>
            </target>
            <dependent>
              <name value="SetComponentValue"/>
              <parameter>
                <valueId value="it"/>
              </parameter>
              <parameter>
                <valueId value="comp"/>
              </parameter>
            </dependent>
          </rule>
        </rule>
        <rule>
          <name value="comp_obs_baby_admitted_to_nbu"/>
          <source>
            <context value="g"/>
            <element value="item"/>
            <variable value="it"/>
            <condition value="(linkId = 'obstetric-history/pregnancy/baby-admitted-nbu') and answer.value.exists()"/>
          </source>
          <target>
            <context value="obs"/>
            <element value="component"/>
            <variable value="comp"/>
          </target>
          <rule>
            <name value="code"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="comp"/>
              <element value="code"/>
              <variable value="cc"/>
            </target>
            <rule>
              <name value="coding"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cc"/>
                <element value="coding"/>
                <variable value="cg"/>
              </target>
              <rule>
                <name value="sys"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="system"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="cd"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="code"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="obs-baby-admitted-to-nbu"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="dsp"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="display"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="Baby admitted to NBU"/>
                  </parameter>
                </target>
              </rule>
            </rule>
          </rule>
          <rule>
            <name value="value"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="comp"/>
            </target>
            <dependent>
              <name value="SetComponentCodedValue"/>
              <parameter>
                <valueId value="it"/>
              </parameter>
              <parameter>
                <valueId value="comp"/>
              </parameter>
            </dependent>
          </rule>
        </rule>
      </rule>
      <documentation value="── Past obstetric history, one Observation per previous pregnancy ──────&#xD;&#xA;One per row rather than one panel of everything. Each row is a pregnancy&#xD;&#xA;with its own year, gestation, mode and outcome, and the obstetric decision&#xD;&#xA;this record informs — whether a previous caesarean allows a trial of&#xD;&#xA;labour — is a question about one specific row."/>
    </rule>
    <rule>
      <name value="familyHistoryPanel"/>
      <source>
        <context value="qr"/>
        <element value="item"/>
        <variable value="g"/>
        <condition value="(linkId = 'family-history') and item.answer.value.exists()"/>
      </source>
      <target>
        <context value="bundle"/>
        <element value="entry"/>
        <variable value="entry"/>
      </target>
      <target>
        <context value="entry"/>
        <element value="resource"/>
        <variable value="obs"/>
        <transform value="create"/>
        <parameter>
          <valueString value="Observation"/>
        </parameter>
      </target>
      <rule>
        <name value="base"/>
        <source>
          <context value="qr"/>
        </source>
        <target>
          <context value="obs"/>
        </target>
        <target>
          <context value="entry"/>
        </target>
        <dependent>
          <name value="BuildObsBase"/>
          <parameter>
            <valueId value="qr"/>
          </parameter>
          <parameter>
            <valueId value="obs"/>
          </parameter>
          <parameter>
            <valueId value="entry"/>
          </parameter>
        </dependent>
      </rule>
      <rule>
        <name value="category"/>
        <source>
          <context value="qr"/>
        </source>
        <target>
          <context value="obs"/>
        </target>
        <dependent>
          <name value="SetSurveyCategory"/>
          <parameter>
            <valueId value="qr"/>
          </parameter>
          <parameter>
            <valueId value="obs"/>
          </parameter>
        </dependent>
      </rule>
      <rule>
        <name value="code"/>
        <source>
          <context value="g"/>
        </source>
        <target>
          <context value="obs"/>
          <element value="code"/>
          <variable value="cc"/>
        </target>
        <rule>
          <name value="coding"/>
          <source>
            <context value="g"/>
          </source>
          <target>
            <context value="cc"/>
            <element value="coding"/>
            <variable value="cg"/>
          </target>
          <rule>
            <name value="sys"/>
            <source>
              <context value="g"/>
            </source>
            <target>
              <context value="cg"/>
              <element value="system"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="http://loinc.org"/>
              </parameter>
            </target>
          </rule>
          <rule>
            <name value="cd"/>
            <source>
              <context value="g"/>
            </source>
            <target>
              <context value="cg"/>
              <element value="code"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="10157-6"/>
              </parameter>
            </target>
          </rule>
          <rule>
            <name value="dsp"/>
            <source>
              <context value="g"/>
            </source>
            <target>
              <context value="cg"/>
              <element value="display"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="History of family member diseases note"/>
              </parameter>
            </target>
          </rule>
        </rule>
      </rule>
      <rule>
        <name value="comp_obs_twins"/>
        <source>
          <context value="g"/>
          <element value="item"/>
          <variable value="it"/>
          <condition value="(linkId = 'family-history/twins') and answer.value.exists()"/>
        </source>
        <target>
          <context value="obs"/>
          <element value="component"/>
          <variable value="comp"/>
        </target>
        <rule>
          <name value="code"/>
          <source>
            <context value="it"/>
          </source>
          <target>
            <context value="comp"/>
            <element value="code"/>
            <variable value="cc"/>
          </target>
          <rule>
            <name value="coding"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="cc"/>
              <element value="coding"/>
              <variable value="cg"/>
            </target>
            <rule>
              <name value="sys"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="system"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="cd"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="code"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="obs-twins"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="dsp"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="display"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="Twins"/>
                </parameter>
              </target>
            </rule>
          </rule>
        </rule>
        <rule>
          <name value="value"/>
          <source>
            <context value="it"/>
          </source>
          <target>
            <context value="comp"/>
          </target>
          <dependent>
            <name value="SetComponentCodedValue"/>
            <parameter>
              <valueId value="it"/>
            </parameter>
            <parameter>
              <valueId value="comp"/>
            </parameter>
          </dependent>
        </rule>
      </rule>
      <rule>
        <name value="comp_obs_diabetes"/>
        <source>
          <context value="g"/>
          <element value="item"/>
          <variable value="it"/>
          <condition value="(linkId = 'family-history/diabetes') and answer.value.exists()"/>
        </source>
        <target>
          <context value="obs"/>
          <element value="component"/>
          <variable value="comp"/>
        </target>
        <rule>
          <name value="code"/>
          <source>
            <context value="it"/>
          </source>
          <target>
            <context value="comp"/>
            <element value="code"/>
            <variable value="cc"/>
          </target>
          <rule>
            <name value="coding"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="cc"/>
              <element value="coding"/>
              <variable value="cg"/>
            </target>
            <rule>
              <name value="sys"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="system"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="cd"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="code"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="obs-diabetes"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="dsp"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="display"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="Diabetes"/>
                </parameter>
              </target>
            </rule>
          </rule>
        </rule>
        <rule>
          <name value="value"/>
          <source>
            <context value="it"/>
          </source>
          <target>
            <context value="comp"/>
          </target>
          <dependent>
            <name value="SetComponentCodedValue"/>
            <parameter>
              <valueId value="it"/>
            </parameter>
            <parameter>
              <valueId value="comp"/>
            </parameter>
          </dependent>
        </rule>
      </rule>
      <rule>
        <name value="comp_obs_hypertension"/>
        <source>
          <context value="g"/>
          <element value="item"/>
          <variable value="it"/>
          <condition value="(linkId = 'family-history/hypertension') and answer.value.exists()"/>
        </source>
        <target>
          <context value="obs"/>
          <element value="component"/>
          <variable value="comp"/>
        </target>
        <rule>
          <name value="code"/>
          <source>
            <context value="it"/>
          </source>
          <target>
            <context value="comp"/>
            <element value="code"/>
            <variable value="cc"/>
          </target>
          <rule>
            <name value="coding"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="cc"/>
              <element value="coding"/>
              <variable value="cg"/>
            </target>
            <rule>
              <name value="sys"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="system"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="cd"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="code"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="obs-hypertension"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="dsp"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="display"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="Hypertension"/>
                </parameter>
              </target>
            </rule>
          </rule>
        </rule>
        <rule>
          <name value="value"/>
          <source>
            <context value="it"/>
          </source>
          <target>
            <context value="comp"/>
          </target>
          <dependent>
            <name value="SetComponentCodedValue"/>
            <parameter>
              <valueId value="it"/>
            </parameter>
            <parameter>
              <valueId value="comp"/>
            </parameter>
          </dependent>
        </rule>
      </rule>
      <rule>
        <name value="comp_obs_inherited_conditions"/>
        <source>
          <context value="g"/>
          <element value="item"/>
          <variable value="it"/>
          <condition value="(linkId = 'family-history/inherited-conditions') and answer.value.exists()"/>
        </source>
        <target>
          <context value="obs"/>
          <element value="component"/>
          <variable value="comp"/>
        </target>
        <rule>
          <name value="code"/>
          <source>
            <context value="it"/>
          </source>
          <target>
            <context value="comp"/>
            <element value="code"/>
            <variable value="cc"/>
          </target>
          <rule>
            <name value="coding"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="cc"/>
              <element value="coding"/>
              <variable value="cg"/>
            </target>
            <rule>
              <name value="sys"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="system"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="cd"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="code"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="obs-inherited-conditions"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="dsp"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="display"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="Inherited conditions"/>
                </parameter>
              </target>
            </rule>
          </rule>
        </rule>
        <rule>
          <name value="value"/>
          <source>
            <context value="it"/>
          </source>
          <target>
            <context value="comp"/>
          </target>
          <dependent>
            <name value="SetComponentCodedValue"/>
            <parameter>
              <valueId value="it"/>
            </parameter>
            <parameter>
              <valueId value="comp"/>
            </parameter>
          </dependent>
        </rule>
      </rule>
      <rule>
        <name value="comp_obs_any_other"/>
        <source>
          <context value="g"/>
          <element value="item"/>
          <variable value="it"/>
          <condition value="(linkId = 'family-history/other') and answer.value.exists()"/>
        </source>
        <target>
          <context value="obs"/>
          <element value="component"/>
          <variable value="comp"/>
        </target>
        <rule>
          <name value="code"/>
          <source>
            <context value="it"/>
          </source>
          <target>
            <context value="comp"/>
            <element value="code"/>
            <variable value="cc"/>
          </target>
          <rule>
            <name value="coding"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="cc"/>
              <element value="coding"/>
              <variable value="cg"/>
            </target>
            <rule>
              <name value="sys"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="system"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="cd"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="code"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="obs-any-other"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="dsp"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="display"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="Any other"/>
                </parameter>
              </target>
            </rule>
          </rule>
        </rule>
        <rule>
          <name value="value"/>
          <source>
            <context value="it"/>
          </source>
          <target>
            <context value="comp"/>
          </target>
          <dependent>
            <name value="SetComponentValue"/>
            <parameter>
              <valueId value="it"/>
            </parameter>
            <parameter>
              <valueId value="comp"/>
            </parameter>
          </dependent>
        </rule>
      </rule>
      <documentation value="── Family history ──────────────────────────────────────────────────────&#xD;&#xA;A panel, not FamilyMemberHistory resources. The sheet ticks whether there&#xD;&#xA;is diabetes, hypertension, twins or an inherited condition in the family&#xD;&#xA;and names no relative, and a FamilyMemberHistory with no relationship is&#xD;&#xA;not a family history."/>
    </rule>
    <rule>
      <name value="socialHistoryPanel"/>
      <source>
        <context value="qr"/>
        <element value="item"/>
        <variable value="g"/>
        <condition value="(linkId = 'social-history') and item.item.answer.value.exists()"/>
      </source>
      <target>
        <context value="bundle"/>
        <element value="entry"/>
        <variable value="entry"/>
      </target>
      <target>
        <context value="entry"/>
        <element value="resource"/>
        <variable value="obs"/>
        <transform value="create"/>
        <parameter>
          <valueString value="Observation"/>
        </parameter>
      </target>
      <rule>
        <name value="base"/>
        <source>
          <context value="qr"/>
        </source>
        <target>
          <context value="obs"/>
        </target>
        <target>
          <context value="entry"/>
        </target>
        <dependent>
          <name value="BuildObsBase"/>
          <parameter>
            <valueId value="qr"/>
          </parameter>
          <parameter>
            <valueId value="obs"/>
          </parameter>
          <parameter>
            <valueId value="entry"/>
          </parameter>
        </dependent>
      </rule>
      <rule>
        <name value="category"/>
        <source>
          <context value="qr"/>
        </source>
        <target>
          <context value="obs"/>
        </target>
        <dependent>
          <name value="SetSurveyCategory"/>
          <parameter>
            <valueId value="qr"/>
          </parameter>
          <parameter>
            <valueId value="obs"/>
          </parameter>
        </dependent>
      </rule>
      <rule>
        <name value="code"/>
        <source>
          <context value="g"/>
        </source>
        <target>
          <context value="obs"/>
          <element value="code"/>
          <variable value="cc"/>
        </target>
        <rule>
          <name value="coding"/>
          <source>
            <context value="g"/>
          </source>
          <target>
            <context value="cc"/>
            <element value="coding"/>
            <variable value="cg"/>
          </target>
          <rule>
            <name value="sys"/>
            <source>
              <context value="g"/>
            </source>
            <target>
              <context value="cg"/>
              <element value="system"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="http://loinc.org"/>
              </parameter>
            </target>
          </rule>
          <rule>
            <name value="cd"/>
            <source>
              <context value="g"/>
            </source>
            <target>
              <context value="cg"/>
              <element value="code"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="29762-2"/>
              </parameter>
            </target>
          </rule>
          <rule>
            <name value="dsp"/>
            <source>
              <context value="g"/>
            </source>
            <target>
              <context value="cg"/>
              <element value="display"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="Social history note"/>
              </parameter>
            </target>
          </rule>
        </rule>
      </rule>
      <rule>
        <name value="smokingSub"/>
        <source>
          <context value="g"/>
          <element value="item"/>
          <variable value="g2"/>
          <condition value="linkId = 'social-history/smoking'"/>
        </source>
        <rule>
          <name value="comp_obs_smoker"/>
          <source>
            <context value="g2"/>
            <element value="item"/>
            <variable value="it"/>
            <condition value="(linkId = 'social-history/smoking/status') and answer.value.exists()"/>
          </source>
          <target>
            <context value="obs"/>
            <element value="component"/>
            <variable value="comp"/>
          </target>
          <rule>
            <name value="code"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="comp"/>
              <element value="code"/>
              <variable value="cc"/>
            </target>
            <rule>
              <name value="coding"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cc"/>
                <element value="coding"/>
                <variable value="cg"/>
              </target>
              <rule>
                <name value="sys"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="system"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="cd"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="code"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="obs-smoker"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="dsp"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="display"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="Smoker"/>
                  </parameter>
                </target>
              </rule>
            </rule>
          </rule>
          <rule>
            <name value="value"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="comp"/>
            </target>
            <dependent>
              <name value="SetComponentCodedValue"/>
              <parameter>
                <valueId value="it"/>
              </parameter>
              <parameter>
                <valueId value="comp"/>
              </parameter>
            </dependent>
          </rule>
        </rule>
        <rule>
          <name value="comp_obs_smoking_detail"/>
          <source>
            <context value="g2"/>
            <element value="item"/>
            <variable value="it"/>
            <condition value="(linkId = 'social-history/smoking/detail') and answer.value.exists()"/>
          </source>
          <target>
            <context value="obs"/>
            <element value="component"/>
            <variable value="comp"/>
          </target>
          <rule>
            <name value="code"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="comp"/>
              <element value="code"/>
              <variable value="cc"/>
            </target>
            <rule>
              <name value="coding"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cc"/>
                <element value="coding"/>
                <variable value="cg"/>
              </target>
              <rule>
                <name value="sys"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="system"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="cd"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="code"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="obs-smoking-detail"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="dsp"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="display"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="Smoking detail"/>
                  </parameter>
                </target>
              </rule>
            </rule>
          </rule>
          <rule>
            <name value="value"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="comp"/>
            </target>
            <dependent>
              <name value="SetComponentValue"/>
              <parameter>
                <valueId value="it"/>
              </parameter>
              <parameter>
                <valueId value="comp"/>
              </parameter>
            </dependent>
          </rule>
        </rule>
      </rule>
      <rule>
        <name value="alcoholSub"/>
        <source>
          <context value="g"/>
          <element value="item"/>
          <variable value="g2"/>
          <condition value="linkId = 'social-history/alcohol'"/>
        </source>
        <rule>
          <name value="comp_obs_alcohol"/>
          <source>
            <context value="g2"/>
            <element value="item"/>
            <variable value="it"/>
            <condition value="(linkId = 'social-history/alcohol/status') and answer.value.exists()"/>
          </source>
          <target>
            <context value="obs"/>
            <element value="component"/>
            <variable value="comp"/>
          </target>
          <rule>
            <name value="code"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="comp"/>
              <element value="code"/>
              <variable value="cc"/>
            </target>
            <rule>
              <name value="coding"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cc"/>
                <element value="coding"/>
                <variable value="cg"/>
              </target>
              <rule>
                <name value="sys"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="system"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="cd"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="code"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="obs-alcohol"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="dsp"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="display"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="Alcohol"/>
                  </parameter>
                </target>
              </rule>
            </rule>
          </rule>
          <rule>
            <name value="value"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="comp"/>
            </target>
            <dependent>
              <name value="SetComponentCodedValue"/>
              <parameter>
                <valueId value="it"/>
              </parameter>
              <parameter>
                <valueId value="comp"/>
              </parameter>
            </dependent>
          </rule>
        </rule>
        <rule>
          <name value="comp_obs_alcohol_detail"/>
          <source>
            <context value="g2"/>
            <element value="item"/>
            <variable value="it"/>
            <condition value="(linkId = 'social-history/alcohol/detail') and answer.value.exists()"/>
          </source>
          <target>
            <context value="obs"/>
            <element value="component"/>
            <variable value="comp"/>
          </target>
          <rule>
            <name value="code"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="comp"/>
              <element value="code"/>
              <variable value="cc"/>
            </target>
            <rule>
              <name value="coding"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cc"/>
                <element value="coding"/>
                <variable value="cg"/>
              </target>
              <rule>
                <name value="sys"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="system"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="cd"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="code"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="obs-alcohol-detail"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="dsp"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="display"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="Alcohol detail"/>
                  </parameter>
                </target>
              </rule>
            </rule>
          </rule>
          <rule>
            <name value="value"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="comp"/>
            </target>
            <dependent>
              <name value="SetComponentValue"/>
              <parameter>
                <valueId value="it"/>
              </parameter>
              <parameter>
                <valueId value="comp"/>
              </parameter>
            </dependent>
          </rule>
        </rule>
      </rule>
      <rule>
        <name value="comp_obs_marital_status"/>
        <source>
          <context value="g"/>
          <element value="item"/>
          <variable value="it"/>
          <condition value="(linkId = 'social-history/marital-status') and answer.value.exists()"/>
        </source>
        <target>
          <context value="obs"/>
          <element value="component"/>
          <variable value="comp"/>
        </target>
        <rule>
          <name value="code"/>
          <source>
            <context value="it"/>
          </source>
          <target>
            <context value="comp"/>
            <element value="code"/>
            <variable value="cc"/>
          </target>
          <rule>
            <name value="coding"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="cc"/>
              <element value="coding"/>
              <variable value="cg"/>
            </target>
            <rule>
              <name value="sys"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="system"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="cd"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="code"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="obs-marital-status"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="dsp"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="display"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="Marital status"/>
                </parameter>
              </target>
            </rule>
          </rule>
        </rule>
        <rule>
          <name value="value"/>
          <source>
            <context value="it"/>
          </source>
          <target>
            <context value="comp"/>
          </target>
          <dependent>
            <name value="SetComponentCodedValue"/>
            <parameter>
              <valueId value="it"/>
            </parameter>
            <parameter>
              <valueId value="comp"/>
            </parameter>
          </dependent>
        </rule>
      </rule>
      <rule>
        <name value="comp_obs_other_social_history"/>
        <source>
          <context value="g"/>
          <element value="item"/>
          <variable value="it"/>
          <condition value="(linkId = 'social-history/other') and answer.value.exists()"/>
        </source>
        <target>
          <context value="obs"/>
          <element value="component"/>
          <variable value="comp"/>
        </target>
        <rule>
          <name value="code"/>
          <source>
            <context value="it"/>
          </source>
          <target>
            <context value="comp"/>
            <element value="code"/>
            <variable value="cc"/>
          </target>
          <rule>
            <name value="coding"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="cc"/>
              <element value="coding"/>
              <variable value="cg"/>
            </target>
            <rule>
              <name value="sys"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="system"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="cd"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="code"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="obs-other-social-history"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="dsp"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="display"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="Other social history"/>
                </parameter>
              </target>
            </rule>
          </rule>
        </rule>
        <rule>
          <name value="value"/>
          <source>
            <context value="it"/>
          </source>
          <target>
            <context value="comp"/>
          </target>
          <dependent>
            <name value="SetComponentValue"/>
            <parameter>
              <valueId value="it"/>
            </parameter>
            <parameter>
              <valueId value="comp"/>
            </parameter>
          </dependent>
        </rule>
      </rule>
      <rule>
        <name value="note"/>
        <source>
          <context value="g"/>
          <element value="item"/>
          <variable value="it"/>
          <condition value="linkId = 'social-history/functional-status'"/>
        </source>
        <rule>
          <name value="answer"/>
          <source>
            <context value="it"/>
            <element value="answer"/>
            <listMode value="first"/>
            <variable value="a"/>
          </source>
          <rule>
            <name value="text"/>
            <source>
              <context value="a"/>
              <element value="value"/>
              <variable value="txt"/>
            </source>
            <target>
              <context value="obs"/>
              <element value="note"/>
              <variable value="n"/>
            </target>
            <target>
              <context value="n"/>
              <element value="text"/>
              <transform value="copy"/>
              <parameter>
                <valueId value="txt"/>
              </parameter>
            </target>
          </rule>
        </rule>
      </rule>
      <documentation value="── Social history ──────────────────────────────────────────────────────"/>
    </rule>
    <rule>
      <name value="narr_10160_0"/>
      <source>
        <context value="qr"/>
        <element value="item"/>
        <variable value="it"/>
        <condition value="(linkId = 'gynaecological-history') and answer.value.exists()"/>
      </source>
      <target>
        <context value="bundle"/>
        <element value="entry"/>
        <variable value="entry"/>
      </target>
      <target>
        <context value="entry"/>
        <element value="resource"/>
        <variable value="obs"/>
        <transform value="create"/>
        <parameter>
          <valueString value="Observation"/>
        </parameter>
      </target>
      <rule>
        <name value="base"/>
        <source>
          <context value="qr"/>
        </source>
        <target>
          <context value="obs"/>
        </target>
        <target>
          <context value="entry"/>
        </target>
        <dependent>
          <name value="BuildObsBase"/>
          <parameter>
            <valueId value="qr"/>
          </parameter>
          <parameter>
            <valueId value="obs"/>
          </parameter>
          <parameter>
            <valueId value="entry"/>
          </parameter>
        </dependent>
      </rule>
      <rule>
        <name value="category"/>
        <source>
          <context value="qr"/>
        </source>
        <target>
          <context value="obs"/>
        </target>
        <dependent>
          <name value="SetSurveyCategory"/>
          <parameter>
            <valueId value="qr"/>
          </parameter>
          <parameter>
            <valueId value="obs"/>
          </parameter>
        </dependent>
      </rule>
      <rule>
        <name value="code"/>
        <source>
          <context value="it"/>
        </source>
        <target>
          <context value="obs"/>
          <element value="code"/>
          <variable value="cc"/>
        </target>
        <rule>
          <name value="coding"/>
          <source>
            <context value="it"/>
          </source>
          <target>
            <context value="cc"/>
            <element value="coding"/>
            <variable value="cg"/>
          </target>
          <rule>
            <name value="sys"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="cg"/>
              <element value="system"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="http://loinc.org"/>
              </parameter>
            </target>
          </rule>
          <rule>
            <name value="cd"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="cg"/>
              <element value="code"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="10160-0"/>
              </parameter>
            </target>
          </rule>
          <rule>
            <name value="dsp"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="cg"/>
              <element value="display"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="History of Medication use Narrative"/>
              </parameter>
            </target>
          </rule>
        </rule>
        <rule>
          <name value="codeText"/>
          <source>
            <context value="it"/>
          </source>
          <target>
            <context value="cc"/>
            <element value="text"/>
            <transform value="copy"/>
            <parameter>
              <valueString value="Gynaecological history"/>
            </parameter>
          </target>
        </rule>
      </rule>
      <rule>
        <name value="answer"/>
        <source>
          <context value="it"/>
          <element value="answer"/>
          <listMode value="first"/>
          <variable value="a"/>
        </source>
        <rule>
          <name value="text"/>
          <source>
            <context value="a"/>
            <element value="value"/>
            <variable value="txt"/>
          </source>
          <target>
            <context value="obs"/>
            <element value="note"/>
            <variable value="n"/>
          </target>
          <target>
            <context value="n"/>
            <element value="text"/>
            <transform value="copy"/>
            <parameter>
              <valueId value="txt"/>
            </parameter>
          </target>
        </rule>
      </rule>
    </rule>
    <rule>
      <name value="narr_11348_0"/>
      <source>
        <context value="qr"/>
        <element value="item"/>
        <variable value="it"/>
        <condition value="(linkId = 'past-medical-surgical-history') and answer.value.exists()"/>
      </source>
      <target>
        <context value="bundle"/>
        <element value="entry"/>
        <variable value="entry"/>
      </target>
      <target>
        <context value="entry"/>
        <element value="resource"/>
        <variable value="obs"/>
        <transform value="create"/>
        <parameter>
          <valueString value="Observation"/>
        </parameter>
      </target>
      <rule>
        <name value="base"/>
        <source>
          <context value="qr"/>
        </source>
        <target>
          <context value="obs"/>
        </target>
        <target>
          <context value="entry"/>
        </target>
        <dependent>
          <name value="BuildObsBase"/>
          <parameter>
            <valueId value="qr"/>
          </parameter>
          <parameter>
            <valueId value="obs"/>
          </parameter>
          <parameter>
            <valueId value="entry"/>
          </parameter>
        </dependent>
      </rule>
      <rule>
        <name value="category"/>
        <source>
          <context value="qr"/>
        </source>
        <target>
          <context value="obs"/>
        </target>
        <dependent>
          <name value="SetSurveyCategory"/>
          <parameter>
            <valueId value="qr"/>
          </parameter>
          <parameter>
            <valueId value="obs"/>
          </parameter>
        </dependent>
      </rule>
      <rule>
        <name value="code"/>
        <source>
          <context value="it"/>
        </source>
        <target>
          <context value="obs"/>
          <element value="code"/>
          <variable value="cc"/>
        </target>
        <rule>
          <name value="coding"/>
          <source>
            <context value="it"/>
          </source>
          <target>
            <context value="cc"/>
            <element value="coding"/>
            <variable value="cg"/>
          </target>
          <rule>
            <name value="sys"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="cg"/>
              <element value="system"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="http://loinc.org"/>
              </parameter>
            </target>
          </rule>
          <rule>
            <name value="cd"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="cg"/>
              <element value="code"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="11348-0"/>
              </parameter>
            </target>
          </rule>
          <rule>
            <name value="dsp"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="cg"/>
              <element value="display"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="History of Past illness note"/>
              </parameter>
            </target>
          </rule>
        </rule>
        <rule>
          <name value="codeText"/>
          <source>
            <context value="it"/>
          </source>
          <target>
            <context value="cc"/>
            <element value="text"/>
            <transform value="copy"/>
            <parameter>
              <valueString value="Past medical and surgical history"/>
            </parameter>
          </target>
        </rule>
      </rule>
      <rule>
        <name value="answer"/>
        <source>
          <context value="it"/>
          <element value="answer"/>
          <listMode value="first"/>
          <variable value="a"/>
        </source>
        <rule>
          <name value="text"/>
          <source>
            <context value="a"/>
            <element value="value"/>
            <variable value="txt"/>
          </source>
          <target>
            <context value="obs"/>
            <element value="note"/>
            <variable value="n"/>
          </target>
          <target>
            <context value="n"/>
            <element value="text"/>
            <transform value="copy"/>
            <parameter>
              <valueId value="txt"/>
            </parameter>
          </target>
        </rule>
      </rule>
    </rule>
    <rule>
      <name value="drugHistoryPanel"/>
      <source>
        <context value="qr"/>
        <element value="item"/>
        <variable value="g"/>
        <condition value="(linkId = 'drug-history') and item.answer.value.exists()"/>
      </source>
      <target>
        <context value="bundle"/>
        <element value="entry"/>
        <variable value="entry"/>
      </target>
      <target>
        <context value="entry"/>
        <element value="resource"/>
        <variable value="obs"/>
        <transform value="create"/>
        <parameter>
          <valueString value="Observation"/>
        </parameter>
      </target>
      <rule>
        <name value="base"/>
        <source>
          <context value="qr"/>
        </source>
        <target>
          <context value="obs"/>
        </target>
        <target>
          <context value="entry"/>
        </target>
        <dependent>
          <name value="BuildObsBase"/>
          <parameter>
            <valueId value="qr"/>
          </parameter>
          <parameter>
            <valueId value="obs"/>
          </parameter>
          <parameter>
            <valueId value="entry"/>
          </parameter>
        </dependent>
      </rule>
      <rule>
        <name value="category"/>
        <source>
          <context value="qr"/>
        </source>
        <target>
          <context value="obs"/>
        </target>
        <dependent>
          <name value="SetSurveyCategory"/>
          <parameter>
            <valueId value="qr"/>
          </parameter>
          <parameter>
            <valueId value="obs"/>
          </parameter>
        </dependent>
      </rule>
      <rule>
        <name value="code"/>
        <source>
          <context value="g"/>
        </source>
        <target>
          <context value="obs"/>
          <element value="code"/>
          <variable value="cc"/>
        </target>
        <rule>
          <name value="coding"/>
          <source>
            <context value="g"/>
          </source>
          <target>
            <context value="cc"/>
            <element value="coding"/>
            <variable value="cg"/>
          </target>
          <rule>
            <name value="sys"/>
            <source>
              <context value="g"/>
            </source>
            <target>
              <context value="cg"/>
              <element value="system"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="http://loinc.org"/>
              </parameter>
            </target>
          </rule>
          <rule>
            <name value="cd"/>
            <source>
              <context value="g"/>
            </source>
            <target>
              <context value="cg"/>
              <element value="code"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="10160-0"/>
              </parameter>
            </target>
          </rule>
          <rule>
            <name value="dsp"/>
            <source>
              <context value="g"/>
            </source>
            <target>
              <context value="cg"/>
              <element value="display"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="History of Medication use Narrative"/>
              </parameter>
            </target>
          </rule>
        </rule>
      </rule>
      <rule>
        <name value="comp_obs_folic_acid_taken_pre_conception_or_in_the_first"/>
        <source>
          <context value="g"/>
          <element value="item"/>
          <variable value="it"/>
          <condition value="(linkId = 'drug-history/folic-acid') and answer.value.exists()"/>
        </source>
        <target>
          <context value="obs"/>
          <element value="component"/>
          <variable value="comp"/>
        </target>
        <rule>
          <name value="code"/>
          <source>
            <context value="it"/>
          </source>
          <target>
            <context value="comp"/>
            <element value="code"/>
            <variable value="cc"/>
          </target>
          <rule>
            <name value="coding"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="cc"/>
              <element value="coding"/>
              <variable value="cg"/>
            </target>
            <rule>
              <name value="sys"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="system"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="cd"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="code"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="obs-folic-acid-taken-pre-conception-or-in-the-first"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="dsp"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="display"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="Folic acid taken pre-conception or in the first trimester"/>
                </parameter>
              </target>
            </rule>
          </rule>
        </rule>
        <rule>
          <name value="value"/>
          <source>
            <context value="it"/>
          </source>
          <target>
            <context value="comp"/>
          </target>
          <dependent>
            <name value="SetComponentCodedValue"/>
            <parameter>
              <valueId value="it"/>
            </parameter>
            <parameter>
              <valueId value="comp"/>
            </parameter>
          </dependent>
        </rule>
      </rule>
      <documentation value="── Drug history ────────────────────────────────────────────────────────&#xD;&#xA;A panel with a component per drug, plus the folic-acid question as its own&#xD;&#xA;component. Not MedicationStatements: the sheet takes a drug name and a&#xD;&#xA;dose-and-frequency string per row with no route and no start date, and a&#xD;&#xA;MedicationStatement built from that looks reconciled and is not."/>
    </rule>
    <rule>
      <name value="drugStatements"/>
      <source>
        <context value="qr"/>
        <element value="item"/>
        <variable value="g"/>
        <condition value="linkId = 'drug-history'"/>
      </source>
      <rule>
        <name value="drugStatement"/>
        <source>
          <context value="g"/>
          <element value="item"/>
          <variable value="row"/>
          <condition value="(linkId = 'drug-history/drug') and item.where(linkId = 'drug-history/drug/name').answer.value.exists()"/>
        </source>
        <target>
          <context value="bundle"/>
          <element value="entry"/>
          <variable value="entry"/>
        </target>
        <target>
          <context value="entry"/>
          <element value="resource"/>
          <variable value="ms"/>
          <transform value="create"/>
          <parameter>
            <valueString value="MedicationStatement"/>
          </parameter>
        </target>
        <rule>
          <name value="base"/>
          <source>
            <context value="qr"/>
          </source>
          <target>
            <context value="ms"/>
          </target>
          <target>
            <context value="entry"/>
          </target>
          <dependent>
            <name value="BuildMedicationStatementBase"/>
            <parameter>
              <valueId value="qr"/>
            </parameter>
            <parameter>
              <valueId value="ms"/>
            </parameter>
            <parameter>
              <valueId value="entry"/>
            </parameter>
          </dependent>
        </rule>
        <rule>
          <name value="status"/>
          <source>
            <context value="row"/>
          </source>
          <target>
            <context value="ms"/>
            <element value="status"/>
            <transform value="copy"/>
            <parameter>
              <valueString value="recorded"/>
            </parameter>
          </target>
        </rule>
        <rule>
          <name value="encounter"/>
          <source>
            <context value="qr"/>
            <element value="encounter"/>
            <variable value="e"/>
          </source>
          <target>
            <context value="ms"/>
            <element value="encounter"/>
            <transform value="copy"/>
            <parameter>
              <valueId value="e"/>
            </parameter>
          </target>
        </rule>
        <rule>
          <name value="dateAsserted"/>
          <source>
            <context value="qr"/>
            <element value="authored"/>
            <variable value="t"/>
          </source>
          <target>
            <context value="ms"/>
            <element value="dateAsserted"/>
            <transform value="copy"/>
            <parameter>
              <valueId value="t"/>
            </parameter>
          </target>
        </rule>
        <rule>
          <name value="informationSourceIsThePatient"/>
          <source>
            <context value="qr"/>
            <element value="subject"/>
            <variable value="s"/>
          </source>
          <target>
            <context value="ms"/>
            <element value="informationSource"/>
            <transform value="copy"/>
            <parameter>
              <valueId value="s"/>
            </parameter>
          </target>
        </rule>
        <rule>
          <name value="category"/>
          <source>
            <context value="row"/>
          </source>
          <target>
            <context value="ms"/>
            <element value="category"/>
            <variable value="cat"/>
          </target>
          <rule>
            <name value="coding"/>
            <source>
              <context value="row"/>
            </source>
            <target>
              <context value="cat"/>
              <element value="coding"/>
              <variable value="cg"/>
            </target>
            <rule>
              <name value="sys"/>
              <source>
                <context value="row"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="system"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="http://terminology.hl7.org/CodeSystem/medication-statement-category"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="cd"/>
              <source>
                <context value="row"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="code"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="patientspecified"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="dsp"/>
              <source>
                <context value="row"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="display"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="Patient Specified"/>
                </parameter>
              </target>
            </rule>
          </rule>
        </rule>
        <rule>
          <name value="nameRule"/>
          <source>
            <context value="row"/>
            <element value="item"/>
            <variable value="it"/>
            <condition value="linkId = 'drug-history/drug/name'"/>
          </source>
          <rule>
            <name value="answer"/>
            <source>
              <context value="it"/>
              <element value="answer"/>
              <listMode value="first"/>
              <variable value="a"/>
            </source>
            <rule>
              <name value="medicationText"/>
              <source>
                <context value="a"/>
                <element value="value"/>
                <variable value="txt"/>
              </source>
              <target>
                <context value="ms"/>
                <element value="medication"/>
                <variable value="med"/>
              </target>
              <target>
                <context value="med"/>
                <element value="concept"/>
                <variable value="mc"/>
              </target>
              <target>
                <context value="mc"/>
                <element value="text"/>
                <transform value="copy"/>
                <parameter>
                  <valueId value="txt"/>
                </parameter>
              </target>
            </rule>
          </rule>
        </rule>
        <rule>
          <name value="doseRule"/>
          <source>
            <context value="row"/>
            <element value="item"/>
            <variable value="it"/>
            <condition value="(linkId = 'drug-history/drug/dose-and-frequency') and answer.value.exists()"/>
          </source>
          <rule>
            <name value="answer"/>
            <source>
              <context value="it"/>
              <element value="answer"/>
              <listMode value="first"/>
              <variable value="a"/>
            </source>
            <rule>
              <name value="dosageText"/>
              <source>
                <context value="a"/>
                <element value="value"/>
                <variable value="txt"/>
              </source>
              <target>
                <context value="ms"/>
                <element value="dosage"/>
                <variable value="dos"/>
              </target>
              <target>
                <context value="dos"/>
                <element value="text"/>
                <transform value="copy"/>
                <parameter>
                  <valueId value="txt"/>
                </parameter>
              </target>
            </rule>
          </rule>
        </rule>
        <rule>
          <name value="renderedRule"/>
          <source>
            <context value="row"/>
            <element value="item"/>
            <variable value="it"/>
            <condition value="(linkId = 'drug-history/drug/dose-and-frequency') and answer.value.exists()"/>
          </source>
          <rule>
            <name value="answer"/>
            <source>
              <context value="it"/>
              <element value="answer"/>
              <listMode value="first"/>
              <variable value="a"/>
            </source>
            <rule>
              <name value="renderedDosage"/>
              <source>
                <context value="a"/>
                <element value="value"/>
                <variable value="txt"/>
              </source>
              <target>
                <context value="ms"/>
                <element value="renderedDosageInstruction"/>
                <transform value="copy"/>
                <parameter>
                  <valueId value="txt"/>
                </parameter>
              </target>
            </rule>
          </rule>
        </rule>
        <rule>
          <name value="provenanceNote"/>
          <source>
            <context value="row"/>
          </source>
          <target>
            <context value="ms"/>
            <element value="note"/>
            <variable value="n"/>
          </target>
          <target>
            <context value="n"/>
            <element value="text"/>
            <transform value="copy"/>
            <parameter>
              <valueString value="Reported by the mother on the maternity record. A history, not a reconciled medication list."/>
            </parameter>
          </target>
        </rule>
      </rule>
      <documentation value="── The drugs themselves, one MedicationStatement per row ───────────────&#xD;&#xA;Requested on review. Two things are done to keep it honest, because this&#xD;&#xA;sheet is a patient-reported history and not a reconciled medication list:&#xD;&#xA;`status` is 'recorded' rather than anything that implies verification, and&#xD;&#xA;`informationSource` points at the patient, so a later reader can see where&#xD;&#xA;the list came from. The whole line goes to medication.concept.text as the&#xD;&#xA;woman reported it -- the formulary is not coded here and a guessed RxNorm&#xD;&#xA;code on a drug taken in pregnancy is the wrong place to be wrong."/>
    </rule>
    <rule>
      <name value="examinationGroup"/>
      <source>
        <context value="qr"/>
        <element value="item"/>
        <variable value="eg"/>
        <condition value="linkId = 'examination-on-admission'"/>
      </source>
      <rule>
        <name value="vitalsSub"/>
        <source>
          <context value="eg"/>
          <element value="item"/>
          <variable value="g"/>
          <condition value="linkId = 'examination-on-admission/vitals'"/>
        </source>
        <rule>
          <name value="measure_29463_7"/>
          <source>
            <context value="g"/>
            <element value="item"/>
            <variable value="it"/>
            <condition value="(linkId = 'examination-on-admission/vitals/weight') and answer.value.exists()"/>
          </source>
          <target>
            <context value="bundle"/>
            <element value="entry"/>
            <variable value="entry"/>
          </target>
          <target>
            <context value="entry"/>
            <element value="resource"/>
            <variable value="obs"/>
            <transform value="create"/>
            <parameter>
              <valueString value="Observation"/>
            </parameter>
          </target>
          <rule>
            <name value="base"/>
            <source>
              <context value="qr"/>
            </source>
            <target>
              <context value="obs"/>
            </target>
            <target>
              <context value="entry"/>
            </target>
            <dependent>
              <name value="BuildObsBase"/>
              <parameter>
                <valueId value="qr"/>
              </parameter>
              <parameter>
                <valueId value="obs"/>
              </parameter>
              <parameter>
                <valueId value="entry"/>
              </parameter>
            </dependent>
          </rule>
          <rule>
            <name value="category"/>
            <source>
              <context value="qr"/>
            </source>
            <target>
              <context value="obs"/>
            </target>
            <dependent>
              <name value="SetVitalSignsCategory"/>
              <parameter>
                <valueId value="qr"/>
              </parameter>
              <parameter>
                <valueId value="obs"/>
              </parameter>
            </dependent>
          </rule>
          <rule>
            <name value="code"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="obs"/>
              <element value="code"/>
              <variable value="cc"/>
            </target>
            <rule>
              <name value="coding"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cc"/>
                <element value="coding"/>
                <variable value="cg"/>
              </target>
              <rule>
                <name value="sys"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="system"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="http://loinc.org"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="cd"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="code"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="29463-7"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="dsp"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="display"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="Body weight"/>
                  </parameter>
                </target>
              </rule>
            </rule>
          </rule>
          <rule>
            <name value="answer"/>
            <source>
              <context value="it"/>
              <element value="answer"/>
              <listMode value="first"/>
              <variable value="a"/>
            </source>
            <rule>
              <name value="set"/>
              <source>
                <context value="a"/>
                <element value="value"/>
                <variable value="v"/>
              </source>
              <target>
                <context value="obs"/>
                <element value="value"/>
                <transform value="copy"/>
                <parameter>
                  <valueId value="v"/>
                </parameter>
              </target>
            </rule>
          </rule>
        </rule>
        <rule>
          <name value="measure_8302_2"/>
          <source>
            <context value="g"/>
            <element value="item"/>
            <variable value="it"/>
            <condition value="(linkId = 'examination-on-admission/vitals/height') and answer.value.exists()"/>
          </source>
          <target>
            <context value="bundle"/>
            <element value="entry"/>
            <variable value="entry"/>
          </target>
          <target>
            <context value="entry"/>
            <element value="resource"/>
            <variable value="obs"/>
            <transform value="create"/>
            <parameter>
              <valueString value="Observation"/>
            </parameter>
          </target>
          <rule>
            <name value="base"/>
            <source>
              <context value="qr"/>
            </source>
            <target>
              <context value="obs"/>
            </target>
            <target>
              <context value="entry"/>
            </target>
            <dependent>
              <name value="BuildObsBase"/>
              <parameter>
                <valueId value="qr"/>
              </parameter>
              <parameter>
                <valueId value="obs"/>
              </parameter>
              <parameter>
                <valueId value="entry"/>
              </parameter>
            </dependent>
          </rule>
          <rule>
            <name value="category"/>
            <source>
              <context value="qr"/>
            </source>
            <target>
              <context value="obs"/>
            </target>
            <dependent>
              <name value="SetVitalSignsCategory"/>
              <parameter>
                <valueId value="qr"/>
              </parameter>
              <parameter>
                <valueId value="obs"/>
              </parameter>
            </dependent>
          </rule>
          <rule>
            <name value="code"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="obs"/>
              <element value="code"/>
              <variable value="cc"/>
            </target>
            <rule>
              <name value="coding"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cc"/>
                <element value="coding"/>
                <variable value="cg"/>
              </target>
              <rule>
                <name value="sys"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="system"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="http://loinc.org"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="cd"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="code"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="8302-2"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="dsp"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="display"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="Body height"/>
                  </parameter>
                </target>
              </rule>
            </rule>
          </rule>
          <rule>
            <name value="answer"/>
            <source>
              <context value="it"/>
              <element value="answer"/>
              <listMode value="first"/>
              <variable value="a"/>
            </source>
            <rule>
              <name value="set"/>
              <source>
                <context value="a"/>
                <element value="value"/>
                <variable value="v"/>
              </source>
              <target>
                <context value="obs"/>
                <element value="value"/>
                <transform value="copy"/>
                <parameter>
                  <valueId value="v"/>
                </parameter>
              </target>
            </rule>
          </rule>
        </rule>
        <rule>
          <name value="admissionBloodPressure"/>
          <source>
            <context value="g"/>
            <element value="item"/>
            <variable value="bp"/>
            <condition value="(linkId = 'examination-on-admission/vitals/blood-pressure') and item.answer.value.exists()"/>
          </source>
          <target>
            <context value="bundle"/>
            <element value="entry"/>
            <variable value="entry"/>
          </target>
          <target>
            <context value="entry"/>
            <element value="resource"/>
            <variable value="obs"/>
            <transform value="create"/>
            <parameter>
              <valueString value="Observation"/>
            </parameter>
          </target>
          <rule>
            <name value="base"/>
            <source>
              <context value="qr"/>
            </source>
            <target>
              <context value="obs"/>
            </target>
            <target>
              <context value="entry"/>
            </target>
            <dependent>
              <name value="BuildObsBase"/>
              <parameter>
                <valueId value="qr"/>
              </parameter>
              <parameter>
                <valueId value="obs"/>
              </parameter>
              <parameter>
                <valueId value="entry"/>
              </parameter>
            </dependent>
          </rule>
          <rule>
            <name value="category"/>
            <source>
              <context value="qr"/>
            </source>
            <target>
              <context value="obs"/>
            </target>
            <dependent>
              <name value="SetVitalSignsCategory"/>
              <parameter>
                <valueId value="qr"/>
              </parameter>
              <parameter>
                <valueId value="obs"/>
              </parameter>
            </dependent>
          </rule>
          <rule>
            <name value="code"/>
            <source>
              <context value="bp"/>
            </source>
            <target>
              <context value="obs"/>
              <element value="code"/>
              <variable value="cc"/>
            </target>
            <rule>
              <name value="coding"/>
              <source>
                <context value="bp"/>
              </source>
              <target>
                <context value="cc"/>
                <element value="coding"/>
                <variable value="cg"/>
              </target>
              <rule>
                <name value="sys"/>
                <source>
                  <context value="bp"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="system"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="http://loinc.org"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="cd"/>
                <source>
                  <context value="bp"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="code"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="85354-9"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="dsp"/>
                <source>
                  <context value="bp"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="display"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="Blood pressure panel with all children optional"/>
                  </parameter>
                </target>
              </rule>
            </rule>
          </rule>
          <rule>
            <name value="comp_8480_6"/>
            <source>
              <context value="bp"/>
              <element value="item"/>
              <variable value="it"/>
              <condition value="(linkId = 'examination-on-admission/vitals/blood-pressure/systolic') and answer.value.exists()"/>
            </source>
            <target>
              <context value="obs"/>
              <element value="component"/>
              <variable value="comp"/>
            </target>
            <rule>
              <name value="code"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="comp"/>
                <element value="code"/>
                <variable value="cc"/>
              </target>
              <rule>
                <name value="coding"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cc"/>
                  <element value="coding"/>
                  <variable value="cg"/>
                </target>
                <rule>
                  <name value="sys"/>
                  <source>
                    <context value="it"/>
                  </source>
                  <target>
                    <context value="cg"/>
                    <element value="system"/>
                    <transform value="copy"/>
                    <parameter>
                      <valueString value="http://loinc.org"/>
                    </parameter>
                  </target>
                </rule>
                <rule>
                  <name value="cd"/>
                  <source>
                    <context value="it"/>
                  </source>
                  <target>
                    <context value="cg"/>
                    <element value="code"/>
                    <transform value="copy"/>
                    <parameter>
                      <valueString value="8480-6"/>
                    </parameter>
                  </target>
                </rule>
                <rule>
                  <name value="dsp"/>
                  <source>
                    <context value="it"/>
                  </source>
                  <target>
                    <context value="cg"/>
                    <element value="display"/>
                    <transform value="copy"/>
                    <parameter>
                      <valueString value="Systolic blood pressure"/>
                    </parameter>
                  </target>
                </rule>
              </rule>
            </rule>
            <rule>
              <name value="value"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="comp"/>
              </target>
              <dependent>
                <name value="SetComponentValue"/>
                <parameter>
                  <valueId value="it"/>
                </parameter>
                <parameter>
                  <valueId value="comp"/>
                </parameter>
              </dependent>
            </rule>
          </rule>
          <rule>
            <name value="comp_8462_4"/>
            <source>
              <context value="bp"/>
              <element value="item"/>
              <variable value="it"/>
              <condition value="(linkId = 'examination-on-admission/vitals/blood-pressure/diastolic') and answer.value.exists()"/>
            </source>
            <target>
              <context value="obs"/>
              <element value="component"/>
              <variable value="comp"/>
            </target>
            <rule>
              <name value="code"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="comp"/>
                <element value="code"/>
                <variable value="cc"/>
              </target>
              <rule>
                <name value="coding"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cc"/>
                  <element value="coding"/>
                  <variable value="cg"/>
                </target>
                <rule>
                  <name value="sys"/>
                  <source>
                    <context value="it"/>
                  </source>
                  <target>
                    <context value="cg"/>
                    <element value="system"/>
                    <transform value="copy"/>
                    <parameter>
                      <valueString value="http://loinc.org"/>
                    </parameter>
                  </target>
                </rule>
                <rule>
                  <name value="cd"/>
                  <source>
                    <context value="it"/>
                  </source>
                  <target>
                    <context value="cg"/>
                    <element value="code"/>
                    <transform value="copy"/>
                    <parameter>
                      <valueString value="8462-4"/>
                    </parameter>
                  </target>
                </rule>
                <rule>
                  <name value="dsp"/>
                  <source>
                    <context value="it"/>
                  </source>
                  <target>
                    <context value="cg"/>
                    <element value="display"/>
                    <transform value="copy"/>
                    <parameter>
                      <valueString value="Diastolic blood pressure"/>
                    </parameter>
                  </target>
                </rule>
              </rule>
            </rule>
            <rule>
              <name value="value"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="comp"/>
              </target>
              <dependent>
                <name value="SetComponentValue"/>
                <parameter>
                  <valueId value="it"/>
                </parameter>
                <parameter>
                  <valueId value="comp"/>
                </parameter>
              </dependent>
            </rule>
          </rule>
        </rule>
      </rule>
      <rule>
        <name value="measureq_39156_5"/>
        <source>
          <context value="eg"/>
          <element value="item"/>
          <variable value="it"/>
          <condition value="(linkId = 'examination-on-admission/bmi') and answer.value.exists()"/>
        </source>
        <target>
          <context value="bundle"/>
          <element value="entry"/>
          <variable value="entry"/>
        </target>
        <target>
          <context value="entry"/>
          <element value="resource"/>
          <variable value="obs"/>
          <transform value="create"/>
          <parameter>
            <valueString value="Observation"/>
          </parameter>
        </target>
        <rule>
          <name value="base"/>
          <source>
            <context value="qr"/>
          </source>
          <target>
            <context value="obs"/>
          </target>
          <target>
            <context value="entry"/>
          </target>
          <dependent>
            <name value="BuildObsBase"/>
            <parameter>
              <valueId value="qr"/>
            </parameter>
            <parameter>
              <valueId value="obs"/>
            </parameter>
            <parameter>
              <valueId value="entry"/>
            </parameter>
          </dependent>
        </rule>
        <rule>
          <name value="category"/>
          <source>
            <context value="qr"/>
          </source>
          <target>
            <context value="obs"/>
          </target>
          <dependent>
            <name value="SetVitalSignsCategory"/>
            <parameter>
              <valueId value="qr"/>
            </parameter>
            <parameter>
              <valueId value="obs"/>
            </parameter>
          </dependent>
        </rule>
        <rule>
          <name value="code"/>
          <source>
            <context value="it"/>
          </source>
          <target>
            <context value="obs"/>
            <element value="code"/>
            <variable value="cc"/>
          </target>
          <rule>
            <name value="coding"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="cc"/>
              <element value="coding"/>
              <variable value="cg"/>
            </target>
            <rule>
              <name value="sys"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="system"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="http://loinc.org"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="cd"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="code"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="39156-5"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="dsp"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="display"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="Body mass index (BMI) [Ratio]"/>
                </parameter>
              </target>
            </rule>
          </rule>
        </rule>
        <rule>
          <name value="answer"/>
          <source>
            <context value="it"/>
            <element value="answer"/>
            <listMode value="first"/>
            <variable value="a"/>
          </source>
          <rule>
            <name value="quantity"/>
            <source>
              <context value="a"/>
              <element value="value"/>
              <variable value="v"/>
            </source>
            <target>
              <context value="obs"/>
              <element value="value"/>
              <variable value="q"/>
              <transform value="create"/>
              <parameter>
                <valueString value="Quantity"/>
              </parameter>
            </target>
            <rule>
              <name value="qValue"/>
              <source>
                <context value="v"/>
              </source>
              <target>
                <context value="q"/>
                <element value="value"/>
                <transform value="copy"/>
                <parameter>
                  <valueId value="v"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="qUnit"/>
              <source>
                <context value="v"/>
              </source>
              <target>
                <context value="q"/>
                <element value="unit"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="kg/m2"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="qSystem"/>
              <source>
                <context value="v"/>
              </source>
              <target>
                <context value="q"/>
                <element value="system"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="http://unitsofmeasure.org"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="qCode"/>
              <source>
                <context value="v"/>
              </source>
              <target>
                <context value="q"/>
                <element value="code"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="kg/m2"/>
                </parameter>
              </target>
            </rule>
          </rule>
        </rule>
        <rule>
          <name value="note"/>
          <source>
            <context value="it"/>
          </source>
          <target>
            <context value="obs"/>
            <element value="note"/>
            <variable value="n"/>
          </target>
          <target>
            <context value="n"/>
            <element value="text"/>
            <transform value="copy"/>
            <parameter>
              <valueString value="Derived by the client from the height and weight on this form. The unit is attached by the extraction map, because the form computes a bare number."/>
            </parameter>
          </target>
        </rule>
      </rule>
      <rule>
        <name value="narr_11502_2"/>
        <source>
          <context value="eg"/>
          <element value="item"/>
          <variable value="it"/>
          <condition value="(linkId = 'examination-on-admission/urinalysis') and answer.value.exists()"/>
        </source>
        <target>
          <context value="bundle"/>
          <element value="entry"/>
          <variable value="entry"/>
        </target>
        <target>
          <context value="entry"/>
          <element value="resource"/>
          <variable value="obs"/>
          <transform value="create"/>
          <parameter>
            <valueString value="Observation"/>
          </parameter>
        </target>
        <rule>
          <name value="base"/>
          <source>
            <context value="qr"/>
          </source>
          <target>
            <context value="obs"/>
          </target>
          <target>
            <context value="entry"/>
          </target>
          <dependent>
            <name value="BuildObsBase"/>
            <parameter>
              <valueId value="qr"/>
            </parameter>
            <parameter>
              <valueId value="obs"/>
            </parameter>
            <parameter>
              <valueId value="entry"/>
            </parameter>
          </dependent>
        </rule>
        <rule>
          <name value="category"/>
          <source>
            <context value="qr"/>
          </source>
          <target>
            <context value="obs"/>
          </target>
          <dependent>
            <name value="SetLaboratoryCategory"/>
            <parameter>
              <valueId value="qr"/>
            </parameter>
            <parameter>
              <valueId value="obs"/>
            </parameter>
          </dependent>
        </rule>
        <rule>
          <name value="code"/>
          <source>
            <context value="it"/>
          </source>
          <target>
            <context value="obs"/>
            <element value="code"/>
            <variable value="cc"/>
          </target>
          <rule>
            <name value="coding"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="cc"/>
              <element value="coding"/>
              <variable value="cg"/>
            </target>
            <rule>
              <name value="sys"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="system"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="http://loinc.org"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="cd"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="code"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="11502-2"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="dsp"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="display"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="Laboratory report"/>
                </parameter>
              </target>
            </rule>
          </rule>
          <rule>
            <name value="codeText"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="cc"/>
              <element value="text"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="Urinalysis on admission"/>
              </parameter>
            </target>
          </rule>
        </rule>
        <rule>
          <name value="answer"/>
          <source>
            <context value="it"/>
            <element value="answer"/>
            <listMode value="first"/>
            <variable value="a"/>
          </source>
          <rule>
            <name value="text"/>
            <source>
              <context value="a"/>
              <element value="value"/>
              <variable value="txt"/>
            </source>
            <target>
              <context value="obs"/>
              <element value="note"/>
              <variable value="n"/>
            </target>
            <target>
              <context value="n"/>
              <element value="text"/>
              <transform value="copy"/>
              <parameter>
                <valueId value="txt"/>
              </parameter>
            </target>
          </rule>
        </rule>
      </rule>
      <rule>
        <name value="obstetricExaminationPanel"/>
        <source>
          <context value="eg"/>
          <element value="item"/>
          <variable value="g"/>
          <condition value="(linkId = 'examination-on-admission/physical') and item.answer.value.exists()"/>
        </source>
        <target>
          <context value="bundle"/>
          <element value="entry"/>
          <variable value="entry"/>
        </target>
        <target>
          <context value="entry"/>
          <element value="resource"/>
          <variable value="obs"/>
          <transform value="create"/>
          <parameter>
            <valueString value="Observation"/>
          </parameter>
        </target>
        <rule>
          <name value="base"/>
          <source>
            <context value="qr"/>
          </source>
          <target>
            <context value="obs"/>
          </target>
          <target>
            <context value="entry"/>
          </target>
          <dependent>
            <name value="BuildObsBase"/>
            <parameter>
              <valueId value="qr"/>
            </parameter>
            <parameter>
              <valueId value="obs"/>
            </parameter>
            <parameter>
              <valueId value="entry"/>
            </parameter>
          </dependent>
        </rule>
        <rule>
          <name value="category"/>
          <source>
            <context value="qr"/>
          </source>
          <target>
            <context value="obs"/>
          </target>
          <dependent>
            <name value="SetExamCategory"/>
            <parameter>
              <valueId value="qr"/>
            </parameter>
            <parameter>
              <valueId value="obs"/>
            </parameter>
          </dependent>
        </rule>
        <rule>
          <name value="code"/>
          <source>
            <context value="g"/>
          </source>
          <target>
            <context value="obs"/>
            <element value="code"/>
            <variable value="cc"/>
          </target>
          <rule>
            <name value="coding"/>
            <source>
              <context value="g"/>
            </source>
            <target>
              <context value="cc"/>
              <element value="coding"/>
              <variable value="cg"/>
            </target>
            <rule>
              <name value="sys"/>
              <source>
                <context value="g"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="system"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="http://loinc.org"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="cd"/>
              <source>
                <context value="g"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="code"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="11876-0"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="dsp"/>
              <source>
                <context value="g"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="display"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="Fetal presentation palpation"/>
                </parameter>
              </target>
            </rule>
          </rule>
          <rule>
            <name value="codeText"/>
            <source>
              <context value="g"/>
            </source>
            <target>
              <context value="cc"/>
              <element value="text"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="Obstetric examination on admission"/>
              </parameter>
            </target>
          </rule>
        </rule>
        <rule>
          <name value="comp_fetal_lie"/>
          <source>
            <context value="g"/>
            <element value="item"/>
            <variable value="it"/>
            <condition value="(linkId = 'examination-on-admission/physical/lie') and answer.value.exists()"/>
          </source>
          <target>
            <context value="obs"/>
            <element value="component"/>
            <variable value="comp"/>
          </target>
          <rule>
            <name value="code"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="comp"/>
              <element value="code"/>
              <variable value="cc"/>
            </target>
            <rule>
              <name value="coding"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cc"/>
                <element value="coding"/>
                <variable value="cg"/>
              </target>
              <rule>
                <name value="sys"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="system"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="cd"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="code"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="fetal-lie"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="dsp"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="display"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="Fetal lie"/>
                  </parameter>
                </target>
              </rule>
            </rule>
          </rule>
          <rule>
            <name value="value"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="comp"/>
            </target>
            <dependent>
              <name value="SetComponentCodedValue"/>
              <parameter>
                <valueId value="it"/>
              </parameter>
              <parameter>
                <valueId value="comp"/>
              </parameter>
            </dependent>
          </rule>
        </rule>
        <rule>
          <name value="comp_11876_0"/>
          <source>
            <context value="g"/>
            <element value="item"/>
            <variable value="it"/>
            <condition value="(linkId = 'examination-on-admission/physical/presentation') and answer.value.exists()"/>
          </source>
          <target>
            <context value="obs"/>
            <element value="component"/>
            <variable value="comp"/>
          </target>
          <rule>
            <name value="code"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="comp"/>
              <element value="code"/>
              <variable value="cc"/>
            </target>
            <rule>
              <name value="coding"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cc"/>
                <element value="coding"/>
                <variable value="cg"/>
              </target>
              <rule>
                <name value="sys"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="system"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="http://loinc.org"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="cd"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="code"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="11876-0"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="dsp"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="display"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="Fetal presentation palpation"/>
                  </parameter>
                </target>
              </rule>
            </rule>
          </rule>
          <rule>
            <name value="value"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="comp"/>
            </target>
            <dependent>
              <name value="SetComponentValue"/>
              <parameter>
                <valueId value="it"/>
              </parameter>
              <parameter>
                <valueId value="comp"/>
              </parameter>
            </dependent>
          </rule>
        </rule>
        <rule>
          <name value="comp_obstetric_position"/>
          <source>
            <context value="g"/>
            <element value="item"/>
            <variable value="it"/>
            <condition value="(linkId = 'examination-on-admission/physical/position') and answer.value.exists()"/>
          </source>
          <target>
            <context value="obs"/>
            <element value="component"/>
            <variable value="comp"/>
          </target>
          <rule>
            <name value="code"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="comp"/>
              <element value="code"/>
              <variable value="cc"/>
            </target>
            <rule>
              <name value="coding"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cc"/>
                <element value="coding"/>
                <variable value="cg"/>
              </target>
              <rule>
                <name value="sys"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="system"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="cd"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="code"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="obstetric-position"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="dsp"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="display"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="Position"/>
                  </parameter>
                </target>
              </rule>
            </rule>
          </rule>
          <rule>
            <name value="value"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="comp"/>
            </target>
            <dependent>
              <name value="SetComponentValue"/>
              <parameter>
                <valueId value="it"/>
              </parameter>
              <parameter>
                <valueId value="comp"/>
              </parameter>
            </dependent>
          </rule>
        </rule>
        <rule>
          <name value="comp_bishop_head_station"/>
          <source>
            <context value="g"/>
            <element value="item"/>
            <variable value="it"/>
            <condition value="(linkId = 'examination-on-admission/physical/station') and answer.value.exists()"/>
          </source>
          <target>
            <context value="obs"/>
            <element value="component"/>
            <variable value="comp"/>
          </target>
          <rule>
            <name value="code"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="comp"/>
              <element value="code"/>
              <variable value="cc"/>
            </target>
            <rule>
              <name value="coding"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cc"/>
                <element value="coding"/>
                <variable value="cg"/>
              </target>
              <rule>
                <name value="sys"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="system"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="cd"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="code"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="bishop-head-station"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="dsp"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="display"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="Head station"/>
                  </parameter>
                </target>
              </rule>
            </rule>
          </rule>
          <rule>
            <name value="value"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="comp"/>
            </target>
            <dependent>
              <name value="SetComponentValue"/>
              <parameter>
                <valueId value="it"/>
              </parameter>
              <parameter>
                <valueId value="comp"/>
              </parameter>
            </dependent>
          </rule>
        </rule>
        <rule>
          <name value="comp_bishop_cervical_dilation"/>
          <source>
            <context value="g"/>
            <element value="item"/>
            <variable value="it"/>
            <condition value="(linkId = 'examination-on-admission/physical/dilation') and answer.value.exists()"/>
          </source>
          <target>
            <context value="obs"/>
            <element value="component"/>
            <variable value="comp"/>
          </target>
          <rule>
            <name value="code"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="comp"/>
              <element value="code"/>
              <variable value="cc"/>
            </target>
            <rule>
              <name value="coding"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cc"/>
                <element value="coding"/>
                <variable value="cg"/>
              </target>
              <rule>
                <name value="sys"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="system"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="cd"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="code"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="bishop-cervical-dilation"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="dsp"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="display"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="Cervical dilation"/>
                  </parameter>
                </target>
              </rule>
            </rule>
          </rule>
          <rule>
            <name value="value"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="comp"/>
            </target>
            <dependent>
              <name value="SetComponentValue"/>
              <parameter>
                <valueId value="it"/>
              </parameter>
              <parameter>
                <valueId value="comp"/>
              </parameter>
            </dependent>
          </rule>
        </rule>
        <rule>
          <name value="comp_membrane_status"/>
          <source>
            <context value="g"/>
            <element value="item"/>
            <variable value="it"/>
            <condition value="(linkId = 'examination-on-admission/physical/membranes') and answer.value.exists()"/>
          </source>
          <target>
            <context value="obs"/>
            <element value="component"/>
            <variable value="comp"/>
          </target>
          <rule>
            <name value="code"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="comp"/>
              <element value="code"/>
              <variable value="cc"/>
            </target>
            <rule>
              <name value="coding"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cc"/>
                <element value="coding"/>
                <variable value="cg"/>
              </target>
              <rule>
                <name value="sys"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="system"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="cd"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="code"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="membrane-status"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="dsp"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="display"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="Membrane status"/>
                  </parameter>
                </target>
              </rule>
            </rule>
          </rule>
          <rule>
            <name value="value"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="comp"/>
            </target>
            <dependent>
              <name value="SetComponentCodedValue"/>
              <parameter>
                <valueId value="it"/>
              </parameter>
              <parameter>
                <valueId value="comp"/>
              </parameter>
            </dependent>
          </rule>
        </rule>
        <documentation value="The obstetric examination, as one panel. Lie, presentation, position,&#xD;&#xA;station, dilation and membrane status are one assessment made at one&#xD;&#xA;vaginal examination, and separating them would let a reader pair a&#xD;&#xA;dilation from one examination with a station from another."/>
      </rule>
      <rule>
        <name value="rapidAssessmentPanel"/>
        <source>
          <context value="eg"/>
          <element value="item"/>
          <variable value="g"/>
          <condition value="(linkId = 'examination-on-admission/rapid') and item.answer.value.exists()"/>
        </source>
        <target>
          <context value="bundle"/>
          <element value="entry"/>
          <variable value="entry"/>
        </target>
        <target>
          <context value="entry"/>
          <element value="resource"/>
          <variable value="obs"/>
          <transform value="create"/>
          <parameter>
            <valueString value="Observation"/>
          </parameter>
        </target>
        <rule>
          <name value="base"/>
          <source>
            <context value="qr"/>
          </source>
          <target>
            <context value="obs"/>
          </target>
          <target>
            <context value="entry"/>
          </target>
          <dependent>
            <name value="BuildObsBase"/>
            <parameter>
              <valueId value="qr"/>
            </parameter>
            <parameter>
              <valueId value="obs"/>
            </parameter>
            <parameter>
              <valueId value="entry"/>
            </parameter>
          </dependent>
        </rule>
        <rule>
          <name value="category"/>
          <source>
            <context value="qr"/>
          </source>
          <target>
            <context value="obs"/>
          </target>
          <dependent>
            <name value="SetExamCategory"/>
            <parameter>
              <valueId value="qr"/>
            </parameter>
            <parameter>
              <valueId value="obs"/>
            </parameter>
          </dependent>
        </rule>
        <rule>
          <name value="code"/>
          <source>
            <context value="g"/>
          </source>
          <target>
            <context value="obs"/>
            <element value="code"/>
            <variable value="cc"/>
          </target>
          <rule>
            <name value="coding"/>
            <source>
              <context value="g"/>
            </source>
            <target>
              <context value="cc"/>
              <element value="coding"/>
              <variable value="cg"/>
            </target>
            <rule>
              <name value="sys"/>
              <source>
                <context value="g"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="system"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="http://loinc.org"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="cd"/>
              <source>
                <context value="g"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="code"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="8716-3"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="dsp"/>
              <source>
                <context value="g"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="display"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="Vital signs note"/>
                </parameter>
              </target>
            </rule>
          </rule>
          <rule>
            <name value="codeText"/>
            <source>
              <context value="g"/>
            </source>
            <target>
              <context value="cc"/>
              <element value="text"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="Vital and rapid assessment on admission"/>
              </parameter>
            </target>
          </rule>
        </rule>
        <rule>
          <name value="comp_55283_6"/>
          <source>
            <context value="g"/>
            <element value="item"/>
            <variable value="it"/>
            <condition value="(linkId = 'examination-on-admission/rapid/fetal-heart-rate') and answer.value.exists()"/>
          </source>
          <target>
            <context value="obs"/>
            <element value="component"/>
            <variable value="comp"/>
          </target>
          <rule>
            <name value="code"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="comp"/>
              <element value="code"/>
              <variable value="cc"/>
            </target>
            <rule>
              <name value="coding"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cc"/>
                <element value="coding"/>
                <variable value="cg"/>
              </target>
              <rule>
                <name value="sys"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="system"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="http://loinc.org"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="cd"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="code"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="55283-6"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="dsp"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="display"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="Fetal Heart rate"/>
                  </parameter>
                </target>
              </rule>
            </rule>
          </rule>
          <rule>
            <name value="value"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="comp"/>
            </target>
            <dependent>
              <name value="SetComponentValue"/>
              <parameter>
                <valueId value="it"/>
              </parameter>
              <parameter>
                <valueId value="comp"/>
              </parameter>
            </dependent>
          </rule>
        </rule>
        <rule>
          <name value="comp_obs_nst_or_ctg"/>
          <source>
            <context value="g"/>
            <element value="item"/>
            <variable value="it"/>
            <condition value="(linkId = 'examination-on-admission/rapid/nst-ctg') and answer.value.exists()"/>
          </source>
          <target>
            <context value="obs"/>
            <element value="component"/>
            <variable value="comp"/>
          </target>
          <rule>
            <name value="code"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="comp"/>
              <element value="code"/>
              <variable value="cc"/>
            </target>
            <rule>
              <name value="coding"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cc"/>
                <element value="coding"/>
                <variable value="cg"/>
              </target>
              <rule>
                <name value="sys"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="system"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="cd"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="code"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="obs-nst-or-ctg"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="dsp"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="display"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="NST or CTG"/>
                  </parameter>
                </target>
              </rule>
            </rule>
          </rule>
          <rule>
            <name value="value"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="comp"/>
            </target>
            <dependent>
              <name value="SetComponentValue"/>
              <parameter>
                <valueId value="it"/>
              </parameter>
              <parameter>
                <valueId value="comp"/>
              </parameter>
            </dependent>
          </rule>
        </rule>
        <rule>
          <name value="comp_obs_general"/>
          <source>
            <context value="g"/>
            <element value="item"/>
            <variable value="it"/>
            <condition value="(linkId = 'examination-on-admission/rapid/general') and answer.value.exists()"/>
          </source>
          <target>
            <context value="obs"/>
            <element value="component"/>
            <variable value="comp"/>
          </target>
          <rule>
            <name value="code"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="comp"/>
              <element value="code"/>
              <variable value="cc"/>
            </target>
            <rule>
              <name value="coding"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cc"/>
                <element value="coding"/>
                <variable value="cg"/>
              </target>
              <rule>
                <name value="sys"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="system"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="cd"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="code"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="obs-general"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="dsp"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="display"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="General"/>
                  </parameter>
                </target>
              </rule>
            </rule>
          </rule>
          <rule>
            <name value="value"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="comp"/>
            </target>
            <dependent>
              <name value="SetComponentValue"/>
              <parameter>
                <valueId value="it"/>
              </parameter>
              <parameter>
                <valueId value="comp"/>
              </parameter>
            </dependent>
          </rule>
        </rule>
        <rule>
          <name value="comp_obs_appearance"/>
          <source>
            <context value="g"/>
            <element value="item"/>
            <variable value="it"/>
            <condition value="(linkId = 'examination-on-admission/rapid/appearance') and answer.value.exists()"/>
          </source>
          <target>
            <context value="obs"/>
            <element value="component"/>
            <variable value="comp"/>
          </target>
          <rule>
            <name value="code"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="comp"/>
              <element value="code"/>
              <variable value="cc"/>
            </target>
            <rule>
              <name value="coding"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cc"/>
                <element value="coding"/>
                <variable value="cg"/>
              </target>
              <rule>
                <name value="sys"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="system"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="cd"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="code"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="obs-appearance"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="dsp"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="display"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="Appearance"/>
                  </parameter>
                </target>
              </rule>
            </rule>
          </rule>
          <rule>
            <name value="value"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="comp"/>
            </target>
            <dependent>
              <name value="SetComponentValue"/>
              <parameter>
                <valueId value="it"/>
              </parameter>
              <parameter>
                <valueId value="comp"/>
              </parameter>
            </dependent>
          </rule>
        </rule>
        <rule>
          <name value="comp_obs_jaundice_or_pallor"/>
          <source>
            <context value="g"/>
            <element value="item"/>
            <variable value="it"/>
            <condition value="(linkId = 'examination-on-admission/rapid/jaundice-pallor') and answer.value.exists()"/>
          </source>
          <target>
            <context value="obs"/>
            <element value="component"/>
            <variable value="comp"/>
          </target>
          <rule>
            <name value="code"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="comp"/>
              <element value="code"/>
              <variable value="cc"/>
            </target>
            <rule>
              <name value="coding"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cc"/>
                <element value="coding"/>
                <variable value="cg"/>
              </target>
              <rule>
                <name value="sys"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="system"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="cd"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="code"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="obs-jaundice-or-pallor"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="dsp"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="display"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="Jaundice or pallor"/>
                  </parameter>
                </target>
              </rule>
            </rule>
          </rule>
          <rule>
            <name value="value"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="comp"/>
            </target>
            <dependent>
              <name value="SetComponentValue"/>
              <parameter>
                <valueId value="it"/>
              </parameter>
              <parameter>
                <valueId value="comp"/>
              </parameter>
            </dependent>
          </rule>
        </rule>
        <rule>
          <name value="comp_obs_contractions"/>
          <source>
            <context value="g"/>
            <element value="item"/>
            <variable value="it"/>
            <condition value="(linkId = 'examination-on-admission/rapid/contractions') and answer.value.exists()"/>
          </source>
          <target>
            <context value="obs"/>
            <element value="component"/>
            <variable value="comp"/>
          </target>
          <rule>
            <name value="code"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="comp"/>
              <element value="code"/>
              <variable value="cc"/>
            </target>
            <rule>
              <name value="coding"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cc"/>
                <element value="coding"/>
                <variable value="cg"/>
              </target>
              <rule>
                <name value="sys"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="system"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="cd"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="code"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="obs-contractions"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="dsp"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="display"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="Contractions"/>
                  </parameter>
                </target>
              </rule>
            </rule>
          </rule>
          <rule>
            <name value="value"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="comp"/>
            </target>
            <dependent>
              <name value="SetComponentValue"/>
              <parameter>
                <valueId value="it"/>
              </parameter>
              <parameter>
                <valueId value="comp"/>
              </parameter>
            </dependent>
          </rule>
        </rule>
        <rule>
          <name value="comp_obs_bleeding_or_tenderness"/>
          <source>
            <context value="g"/>
            <element value="item"/>
            <variable value="it"/>
            <condition value="(linkId = 'examination-on-admission/rapid/bleeding-tenderness') and answer.value.exists()"/>
          </source>
          <target>
            <context value="obs"/>
            <element value="component"/>
            <variable value="comp"/>
          </target>
          <rule>
            <name value="code"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="comp"/>
              <element value="code"/>
              <variable value="cc"/>
            </target>
            <rule>
              <name value="coding"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cc"/>
                <element value="coding"/>
                <variable value="cg"/>
              </target>
              <rule>
                <name value="sys"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="system"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="cd"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="code"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="obs-bleeding-or-tenderness"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="dsp"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="display"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="Bleeding or tenderness"/>
                  </parameter>
                </target>
              </rule>
            </rule>
          </rule>
          <rule>
            <name value="value"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="comp"/>
            </target>
            <dependent>
              <name value="SetComponentValue"/>
              <parameter>
                <valueId value="it"/>
              </parameter>
              <parameter>
                <valueId value="comp"/>
              </parameter>
            </dependent>
          </rule>
        </rule>
        <documentation value="The rapid assessment. The fetal heart rate is lifted out into its own&#xD;&#xA;Observation as well as staying a component here: it is the single most&#xD;&#xA;watched number in labour and it has to be graphable by its LOINC code."/>
      </rule>
      <rule>
        <name value="fetalHeartRateGroup"/>
        <source>
          <context value="eg"/>
          <element value="item"/>
          <variable value="g"/>
          <condition value="linkId = 'examination-on-admission/rapid'"/>
        </source>
        <rule>
          <name value="measure_55283_6"/>
          <source>
            <context value="g"/>
            <element value="item"/>
            <variable value="it"/>
            <condition value="(linkId = 'examination-on-admission/rapid/fetal-heart-rate') and answer.value.exists()"/>
          </source>
          <target>
            <context value="bundle"/>
            <element value="entry"/>
            <variable value="entry"/>
          </target>
          <target>
            <context value="entry"/>
            <element value="resource"/>
            <variable value="obs"/>
            <transform value="create"/>
            <parameter>
              <valueString value="Observation"/>
            </parameter>
          </target>
          <rule>
            <name value="base"/>
            <source>
              <context value="qr"/>
            </source>
            <target>
              <context value="obs"/>
            </target>
            <target>
              <context value="entry"/>
            </target>
            <dependent>
              <name value="BuildObsBase"/>
              <parameter>
                <valueId value="qr"/>
              </parameter>
              <parameter>
                <valueId value="obs"/>
              </parameter>
              <parameter>
                <valueId value="entry"/>
              </parameter>
            </dependent>
          </rule>
          <rule>
            <name value="category"/>
            <source>
              <context value="qr"/>
            </source>
            <target>
              <context value="obs"/>
            </target>
            <dependent>
              <name value="SetVitalSignsCategory"/>
              <parameter>
                <valueId value="qr"/>
              </parameter>
              <parameter>
                <valueId value="obs"/>
              </parameter>
            </dependent>
          </rule>
          <rule>
            <name value="code"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="obs"/>
              <element value="code"/>
              <variable value="cc"/>
            </target>
            <rule>
              <name value="coding"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cc"/>
                <element value="coding"/>
                <variable value="cg"/>
              </target>
              <rule>
                <name value="sys"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="system"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="http://loinc.org"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="cd"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="code"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="55283-6"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="dsp"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="display"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="Fetal Heart rate"/>
                  </parameter>
                </target>
              </rule>
            </rule>
          </rule>
          <rule>
            <name value="answer"/>
            <source>
              <context value="it"/>
              <element value="answer"/>
              <listMode value="first"/>
              <variable value="a"/>
            </source>
            <rule>
              <name value="set"/>
              <source>
                <context value="a"/>
                <element value="value"/>
                <variable value="v"/>
              </source>
              <target>
                <context value="obs"/>
                <element value="value"/>
                <transform value="copy"/>
                <parameter>
                  <valueId value="v"/>
                </parameter>
              </target>
            </rule>
          </rule>
        </rule>
      </rule>
      <documentation value="── Examination on admission ────────────────────────────────────────────"/>
    </rule>
    <rule>
      <name value="investigationsPanel"/>
      <source>
        <context value="qr"/>
        <element value="item"/>
        <variable value="g"/>
        <condition value="(linkId = 'investigations-on-admission') and item.answer.value.exists()"/>
      </source>
      <target>
        <context value="bundle"/>
        <element value="entry"/>
        <variable value="entry"/>
      </target>
      <target>
        <context value="entry"/>
        <element value="resource"/>
        <variable value="obs"/>
        <transform value="create"/>
        <parameter>
          <valueString value="Observation"/>
        </parameter>
      </target>
      <rule>
        <name value="base"/>
        <source>
          <context value="qr"/>
        </source>
        <target>
          <context value="obs"/>
        </target>
        <target>
          <context value="entry"/>
        </target>
        <dependent>
          <name value="BuildObsBase"/>
          <parameter>
            <valueId value="qr"/>
          </parameter>
          <parameter>
            <valueId value="obs"/>
          </parameter>
          <parameter>
            <valueId value="entry"/>
          </parameter>
        </dependent>
      </rule>
      <rule>
        <name value="category"/>
        <source>
          <context value="qr"/>
        </source>
        <target>
          <context value="obs"/>
        </target>
        <dependent>
          <name value="SetLaboratoryCategory"/>
          <parameter>
            <valueId value="qr"/>
          </parameter>
          <parameter>
            <valueId value="obs"/>
          </parameter>
        </dependent>
      </rule>
      <rule>
        <name value="code"/>
        <source>
          <context value="g"/>
        </source>
        <target>
          <context value="obs"/>
          <element value="code"/>
          <variable value="cc"/>
        </target>
        <rule>
          <name value="coding"/>
          <source>
            <context value="g"/>
          </source>
          <target>
            <context value="cc"/>
            <element value="coding"/>
            <variable value="cg"/>
          </target>
          <rule>
            <name value="sys"/>
            <source>
              <context value="g"/>
            </source>
            <target>
              <context value="cg"/>
              <element value="system"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="http://loinc.org"/>
              </parameter>
            </target>
          </rule>
          <rule>
            <name value="cd"/>
            <source>
              <context value="g"/>
            </source>
            <target>
              <context value="cg"/>
              <element value="code"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="11502-2"/>
              </parameter>
            </target>
          </rule>
          <rule>
            <name value="dsp"/>
            <source>
              <context value="g"/>
            </source>
            <target>
              <context value="cg"/>
              <element value="display"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="Laboratory report"/>
              </parameter>
            </target>
          </rule>
        </rule>
        <rule>
          <name value="codeText"/>
          <source>
            <context value="g"/>
          </source>
          <target>
            <context value="cc"/>
            <element value="text"/>
            <transform value="copy"/>
            <parameter>
              <valueString value="Investigations on admission"/>
            </parameter>
          </target>
        </rule>
      </rule>
      <rule>
        <name value="comp_883_9"/>
        <source>
          <context value="g"/>
          <element value="item"/>
          <variable value="it"/>
          <condition value="(linkId = 'investigations-on-admission/blood-group') and answer.value.exists()"/>
        </source>
        <target>
          <context value="obs"/>
          <element value="component"/>
          <variable value="comp"/>
        </target>
        <rule>
          <name value="code"/>
          <source>
            <context value="it"/>
          </source>
          <target>
            <context value="comp"/>
            <element value="code"/>
            <variable value="cc"/>
          </target>
          <rule>
            <name value="coding"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="cc"/>
              <element value="coding"/>
              <variable value="cg"/>
            </target>
            <rule>
              <name value="sys"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="system"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="http://loinc.org"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="cd"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="code"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="883-9"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="dsp"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="display"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="ABO group [Type] in Blood"/>
                </parameter>
              </target>
            </rule>
          </rule>
        </rule>
        <rule>
          <name value="value"/>
          <source>
            <context value="it"/>
          </source>
          <target>
            <context value="comp"/>
          </target>
          <dependent>
            <name value="SetComponentValue"/>
            <parameter>
              <valueId value="it"/>
            </parameter>
            <parameter>
              <valueId value="comp"/>
            </parameter>
          </dependent>
        </rule>
      </rule>
      <rule>
        <name value="comp_10331_7"/>
        <source>
          <context value="g"/>
          <element value="item"/>
          <variable value="it"/>
          <condition value="(linkId = 'investigations-on-admission/rhesus-factor') and answer.value.exists()"/>
        </source>
        <target>
          <context value="obs"/>
          <element value="component"/>
          <variable value="comp"/>
        </target>
        <rule>
          <name value="code"/>
          <source>
            <context value="it"/>
          </source>
          <target>
            <context value="comp"/>
            <element value="code"/>
            <variable value="cc"/>
          </target>
          <rule>
            <name value="coding"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="cc"/>
              <element value="coding"/>
              <variable value="cg"/>
            </target>
            <rule>
              <name value="sys"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="system"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="http://loinc.org"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="cd"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="code"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="10331-7"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="dsp"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="display"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="Rh [Type] in Blood"/>
                </parameter>
              </target>
            </rule>
          </rule>
        </rule>
        <rule>
          <name value="value"/>
          <source>
            <context value="it"/>
          </source>
          <target>
            <context value="comp"/>
          </target>
          <dependent>
            <name value="SetComponentValue"/>
            <parameter>
              <valueId value="it"/>
            </parameter>
            <parameter>
              <valueId value="comp"/>
            </parameter>
          </dependent>
        </rule>
      </rule>
      <rule>
        <name value="comp_maternal_pmtct"/>
        <source>
          <context value="g"/>
          <element value="item"/>
          <variable value="it"/>
          <condition value="(linkId = 'investigations-on-admission/pmtct') and answer.value.exists()"/>
        </source>
        <target>
          <context value="obs"/>
          <element value="component"/>
          <variable value="comp"/>
        </target>
        <rule>
          <name value="code"/>
          <source>
            <context value="it"/>
          </source>
          <target>
            <context value="comp"/>
            <element value="code"/>
            <variable value="cc"/>
          </target>
          <rule>
            <name value="coding"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="cc"/>
              <element value="coding"/>
              <variable value="cg"/>
            </target>
            <rule>
              <name value="sys"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="system"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="cd"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="code"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="maternal-pmtct"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="dsp"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="display"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="PMTCT"/>
                </parameter>
              </target>
            </rule>
          </rule>
        </rule>
        <rule>
          <name value="value"/>
          <source>
            <context value="it"/>
          </source>
          <target>
            <context value="comp"/>
          </target>
          <dependent>
            <name value="SetComponentCodedValue"/>
            <parameter>
              <valueId value="it"/>
            </parameter>
            <parameter>
              <valueId value="comp"/>
            </parameter>
          </dependent>
        </rule>
      </rule>
      <rule>
        <name value="comp_obs_other_investigation"/>
        <source>
          <context value="g"/>
          <element value="item"/>
          <variable value="it"/>
          <condition value="(linkId = 'investigations-on-admission/other') and answer.value.exists()"/>
        </source>
        <target>
          <context value="obs"/>
          <element value="component"/>
          <variable value="comp"/>
        </target>
        <rule>
          <name value="code"/>
          <source>
            <context value="it"/>
          </source>
          <target>
            <context value="comp"/>
            <element value="code"/>
            <variable value="cc"/>
          </target>
          <rule>
            <name value="coding"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="cc"/>
              <element value="coding"/>
              <variable value="cg"/>
            </target>
            <rule>
              <name value="sys"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="system"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="cd"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="code"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="obs-other-investigation"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="dsp"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="display"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="Other investigation"/>
                </parameter>
              </target>
            </rule>
          </rule>
        </rule>
        <rule>
          <name value="value"/>
          <source>
            <context value="it"/>
          </source>
          <target>
            <context value="comp"/>
          </target>
          <dependent>
            <name value="SetComponentValue"/>
            <parameter>
              <valueId value="it"/>
            </parameter>
            <parameter>
              <valueId value="comp"/>
            </parameter>
          </dependent>
        </rule>
      </rule>
      <documentation value="── Investigations on admission ─────────────────────────────────────────&#xD;&#xA;A laboratory panel. Blood group and rhesus factor in particular belong on&#xD;&#xA;the record and not only in the lab: a rhesus-negative woman needs anti-D,&#xD;&#xA;and the decision is made on the ward."/>
    </rule>
    <rule>
      <name value="diagnosisGroup"/>
      <source>
        <context value="qr"/>
        <element value="item"/>
        <variable value="g"/>
        <condition value="linkId = 'diagnosis'"/>
      </source>
      <rule>
        <name value="provisionalDiagnoses"/>
        <source>
          <context value="g"/>
          <element value="item"/>
          <variable value="it"/>
          <condition value="linkId = 'diagnosis/provisional'"/>
        </source>
        <rule>
          <name value="createProvisional"/>
          <source>
            <context value="it"/>
            <element value="answer"/>
            <variable value="a"/>
          </source>
          <target>
            <context value="bundle"/>
            <element value="entry"/>
            <variable value="entry"/>
          </target>
          <target>
            <context value="entry"/>
            <element value="resource"/>
            <variable value="cond"/>
            <transform value="create"/>
            <parameter>
              <valueString value="Condition"/>
            </parameter>
          </target>
          <rule>
            <name value="base"/>
            <source>
              <context value="qr"/>
            </source>
            <target>
              <context value="cond"/>
            </target>
            <target>
              <context value="entry"/>
            </target>
            <dependent>
              <name value="BuildConditionBase"/>
              <parameter>
                <valueId value="qr"/>
              </parameter>
              <parameter>
                <valueId value="cond"/>
              </parameter>
              <parameter>
                <valueId value="entry"/>
              </parameter>
            </dependent>
          </rule>
          <rule>
            <name value="clinicalStatus"/>
            <source>
              <context value="a"/>
            </source>
            <target>
              <context value="cond"/>
              <element value="clinicalStatus"/>
              <variable value="cs"/>
            </target>
            <rule>
              <name value="coding"/>
              <source>
                <context value="a"/>
              </source>
              <target>
                <context value="cs"/>
                <element value="coding"/>
                <variable value="cg"/>
              </target>
              <rule>
                <name value="sys"/>
                <source>
                  <context value="a"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="system"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="http://terminology.hl7.org/CodeSystem/condition-clinical"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="cd"/>
                <source>
                  <context value="a"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="code"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="active"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="dsp"/>
                <source>
                  <context value="a"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="display"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="Active"/>
                  </parameter>
                </target>
              </rule>
            </rule>
          </rule>
          <rule>
            <name value="verificationStatus"/>
            <source>
              <context value="a"/>
            </source>
            <target>
              <context value="cond"/>
              <element value="verificationStatus"/>
              <variable value="vs"/>
            </target>
            <rule>
              <name value="coding"/>
              <source>
                <context value="a"/>
              </source>
              <target>
                <context value="vs"/>
                <element value="coding"/>
                <variable value="cg"/>
              </target>
              <rule>
                <name value="sys"/>
                <source>
                  <context value="a"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="system"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="http://terminology.hl7.org/CodeSystem/condition-ver-status"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="cd"/>
                <source>
                  <context value="a"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="code"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="provisional"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="dsp"/>
                <source>
                  <context value="a"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="display"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="Provisional"/>
                  </parameter>
                </target>
              </rule>
            </rule>
          </rule>
          <rule>
            <name value="category"/>
            <source>
              <context value="a"/>
            </source>
            <target>
              <context value="cond"/>
              <element value="category"/>
              <variable value="cat"/>
            </target>
            <rule>
              <name value="coding"/>
              <source>
                <context value="a"/>
              </source>
              <target>
                <context value="cat"/>
                <element value="coding"/>
                <variable value="cg"/>
              </target>
              <rule>
                <name value="sys"/>
                <source>
                  <context value="a"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="system"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="http://terminology.hl7.org/CodeSystem/condition-category"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="cd"/>
                <source>
                  <context value="a"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="code"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="encounter-diagnosis"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="dsp"/>
                <source>
                  <context value="a"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="display"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="Encounter Diagnosis"/>
                  </parameter>
                </target>
              </rule>
            </rule>
          </rule>
          <rule>
            <name value="codeText"/>
            <source>
              <context value="a"/>
              <element value="value"/>
              <variable value="txt"/>
            </source>
            <target>
              <context value="cond"/>
              <element value="code"/>
              <variable value="cc"/>
            </target>
            <target>
              <context value="cc"/>
              <element value="text"/>
              <transform value="copy"/>
              <parameter>
                <valueId value="txt"/>
              </parameter>
            </target>
          </rule>
          <rule>
            <name value="recordedDate"/>
            <source>
              <context value="qr"/>
              <element value="authored"/>
              <variable value="t"/>
            </source>
            <target>
              <context value="cond"/>
              <element value="recordedDate"/>
              <transform value="copy"/>
              <parameter>
                <valueId value="t"/>
              </parameter>
            </target>
          </rule>
          <rule>
            <name value="encounter"/>
            <source>
              <context value="qr"/>
              <element value="encounter"/>
              <variable value="e"/>
            </source>
            <target>
              <context value="cond"/>
              <element value="encounter"/>
              <transform value="copy"/>
              <parameter>
                <valueId value="e"/>
              </parameter>
            </target>
          </rule>
        </rule>
      </rule>
      <rule>
        <name value="differentialDiagnoses"/>
        <source>
          <context value="g"/>
          <element value="item"/>
          <variable value="it"/>
          <condition value="linkId = 'diagnosis/differential'"/>
        </source>
        <rule>
          <name value="createDifferential"/>
          <source>
            <context value="it"/>
            <element value="answer"/>
            <variable value="a"/>
          </source>
          <target>
            <context value="bundle"/>
            <element value="entry"/>
            <variable value="entry"/>
          </target>
          <target>
            <context value="entry"/>
            <element value="resource"/>
            <variable value="cond"/>
            <transform value="create"/>
            <parameter>
              <valueString value="Condition"/>
            </parameter>
          </target>
          <rule>
            <name value="base"/>
            <source>
              <context value="qr"/>
            </source>
            <target>
              <context value="cond"/>
            </target>
            <target>
              <context value="entry"/>
            </target>
            <dependent>
              <name value="BuildConditionBase"/>
              <parameter>
                <valueId value="qr"/>
              </parameter>
              <parameter>
                <valueId value="cond"/>
              </parameter>
              <parameter>
                <valueId value="entry"/>
              </parameter>
            </dependent>
          </rule>
          <rule>
            <name value="clinicalStatus"/>
            <source>
              <context value="a"/>
            </source>
            <target>
              <context value="cond"/>
              <element value="clinicalStatus"/>
              <variable value="cs"/>
            </target>
            <rule>
              <name value="coding"/>
              <source>
                <context value="a"/>
              </source>
              <target>
                <context value="cs"/>
                <element value="coding"/>
                <variable value="cg"/>
              </target>
              <rule>
                <name value="sys"/>
                <source>
                  <context value="a"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="system"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="http://terminology.hl7.org/CodeSystem/condition-clinical"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="cd"/>
                <source>
                  <context value="a"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="code"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="active"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="dsp"/>
                <source>
                  <context value="a"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="display"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="Active"/>
                  </parameter>
                </target>
              </rule>
            </rule>
            <documentation value="clinicalStatus is 1..1 on R5 Condition, differential or not -- the&#xD;&#xA;validator rejects it outright: &quot;minimum required = 1, but only found&#xD;&#xA;0&quot;. A differential under active consideration is an active problem;&#xD;&#xA;what marks it as unconfirmed is verificationStatus below."/>
          </rule>
          <rule>
            <name value="verificationStatus"/>
            <source>
              <context value="a"/>
            </source>
            <target>
              <context value="cond"/>
              <element value="verificationStatus"/>
              <variable value="vs"/>
            </target>
            <rule>
              <name value="coding"/>
              <source>
                <context value="a"/>
              </source>
              <target>
                <context value="vs"/>
                <element value="coding"/>
                <variable value="cg"/>
              </target>
              <rule>
                <name value="sys"/>
                <source>
                  <context value="a"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="system"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="http://terminology.hl7.org/CodeSystem/condition-ver-status"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="cd"/>
                <source>
                  <context value="a"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="code"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="differential"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="dsp"/>
                <source>
                  <context value="a"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="display"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="Differential"/>
                  </parameter>
                </target>
              </rule>
            </rule>
          </rule>
          <rule>
            <name value="category"/>
            <source>
              <context value="a"/>
            </source>
            <target>
              <context value="cond"/>
              <element value="category"/>
              <variable value="cat"/>
            </target>
            <rule>
              <name value="coding"/>
              <source>
                <context value="a"/>
              </source>
              <target>
                <context value="cat"/>
                <element value="coding"/>
                <variable value="cg"/>
              </target>
              <rule>
                <name value="sys"/>
                <source>
                  <context value="a"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="system"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="http://terminology.hl7.org/CodeSystem/condition-category"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="cd"/>
                <source>
                  <context value="a"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="code"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="encounter-diagnosis"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="dsp"/>
                <source>
                  <context value="a"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="display"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="Encounter Diagnosis"/>
                  </parameter>
                </target>
              </rule>
            </rule>
          </rule>
          <rule>
            <name value="codeText"/>
            <source>
              <context value="a"/>
              <element value="value"/>
              <variable value="txt"/>
            </source>
            <target>
              <context value="cond"/>
              <element value="code"/>
              <variable value="cc"/>
            </target>
            <target>
              <context value="cc"/>
              <element value="text"/>
              <transform value="copy"/>
              <parameter>
                <valueId value="txt"/>
              </parameter>
            </target>
          </rule>
          <rule>
            <name value="recordedDate"/>
            <source>
              <context value="qr"/>
              <element value="authored"/>
              <variable value="t"/>
            </source>
            <target>
              <context value="cond"/>
              <element value="recordedDate"/>
              <transform value="copy"/>
              <parameter>
                <valueId value="t"/>
              </parameter>
            </target>
          </rule>
          <rule>
            <name value="encounter"/>
            <source>
              <context value="qr"/>
              <element value="encounter"/>
              <variable value="e"/>
            </source>
            <target>
              <context value="cond"/>
              <element value="encounter"/>
              <transform value="copy"/>
              <parameter>
                <valueId value="e"/>
              </parameter>
            </target>
          </rule>
        </rule>
      </rule>
      <documentation value="── Diagnoses ───────────────────────────────────────────────────────────&#xD;&#xA;A Condition per provisional and per differential. The differentials carry&#xD;&#xA;`verificationStatus = 'differential'`, which is exactly what that code is&#xD;&#xA;for, so a differential can never be read as a made diagnosis."/>
    </rule>
    <rule>
      <name value="labourReportGroup"/>
      <source>
        <context value="qr"/>
        <element value="item"/>
        <variable value="lg"/>
        <condition value="linkId = 'labour-report'"/>
      </source>
      <rule>
        <name value="deliveryProcedure"/>
        <source>
          <context value="lg"/>
          <element value="item"/>
          <variable value="g"/>
          <condition value="(linkId = 'labour-report/third-stage') and item.where(linkId = 'labour-report/third-stage/delivery-datetime').answer.value.exists()"/>
        </source>
        <target>
          <context value="bundle"/>
          <element value="entry"/>
          <variable value="entry"/>
        </target>
        <target>
          <context value="entry"/>
          <element value="resource"/>
          <variable value="proc"/>
          <transform value="create"/>
          <parameter>
            <valueString value="Procedure"/>
          </parameter>
        </target>
        <rule>
          <name value="base"/>
          <source>
            <context value="qr"/>
          </source>
          <target>
            <context value="proc"/>
          </target>
          <target>
            <context value="entry"/>
          </target>
          <dependent>
            <name value="BuildProcedureBase"/>
            <parameter>
              <valueId value="qr"/>
            </parameter>
            <parameter>
              <valueId value="proc"/>
            </parameter>
            <parameter>
              <valueId value="entry"/>
            </parameter>
          </dependent>
        </rule>
        <rule>
          <name value="status"/>
          <source>
            <context value="g"/>
          </source>
          <target>
            <context value="proc"/>
            <element value="status"/>
            <transform value="copy"/>
            <parameter>
              <valueString value="completed"/>
            </parameter>
          </target>
        </rule>
        <rule>
          <name value="encounter"/>
          <source>
            <context value="qr"/>
            <element value="encounter"/>
            <variable value="e"/>
          </source>
          <target>
            <context value="proc"/>
            <element value="encounter"/>
            <transform value="copy"/>
            <parameter>
              <valueId value="e"/>
            </parameter>
          </target>
        </rule>
        <rule>
          <name value="deliveryTimeRule"/>
          <source>
            <context value="g"/>
            <element value="item"/>
            <variable value="dt"/>
            <condition value="linkId = 'labour-report/third-stage/delivery-datetime'"/>
          </source>
          <rule>
            <name value="answer"/>
            <source>
              <context value="dt"/>
              <element value="answer"/>
              <listMode value="first"/>
              <variable value="a"/>
            </source>
            <rule>
              <name value="occurrence"/>
              <source>
                <context value="a"/>
                <element value="value"/>
                <variable value="t"/>
              </source>
              <target>
                <context value="proc"/>
                <element value="occurrence"/>
                <transform value="copy"/>
                <parameter>
                  <valueId value="t"/>
                </parameter>
              </target>
            </rule>
          </rule>
        </rule>
        <rule>
          <name value="secondStageGroup"/>
          <source>
            <context value="lg"/>
            <element value="item"/>
            <variable value="sg"/>
            <condition value="linkId = 'labour-report/second-stage'"/>
          </source>
          <rule>
            <name value="caesareanCode"/>
            <source>
              <context value="sg"/>
              <element value="item"/>
              <variable value="md"/>
              <condition value="(linkId = 'labour-report/second-stage/mode-of-delivery') and (answer.value.ofType(Coding).code = 'delivery-caesarean')"/>
            </source>
            <target>
              <context value="proc"/>
              <element value="code"/>
              <variable value="cc"/>
            </target>
            <rule>
              <name value="coding"/>
              <source>
                <context value="md"/>
              </source>
              <target>
                <context value="cc"/>
                <element value="coding"/>
                <variable value="cg"/>
              </target>
              <rule>
                <name value="sys"/>
                <source>
                  <context value="md"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="system"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="http://snomed.info/sct"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="cd"/>
                <source>
                  <context value="md"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="code"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="11466000"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="dsp"/>
                <source>
                  <context value="md"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="display"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="Cesarean section"/>
                  </parameter>
                </target>
              </rule>
            </rule>
          </rule>
          <rule>
            <name value="vaginalCode"/>
            <source>
              <context value="sg"/>
              <element value="item"/>
              <variable value="md"/>
              <condition value="(linkId = 'labour-report/second-stage/mode-of-delivery') and (answer.value.ofType(Coding).code != 'delivery-caesarean')"/>
            </source>
            <target>
              <context value="proc"/>
              <element value="code"/>
              <variable value="cc"/>
            </target>
            <rule>
              <name value="coding"/>
              <source>
                <context value="md"/>
              </source>
              <target>
                <context value="cc"/>
                <element value="coding"/>
                <variable value="cg"/>
              </target>
              <rule>
                <name value="sys"/>
                <source>
                  <context value="md"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="system"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="http://snomed.info/sct"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="cd"/>
                <source>
                  <context value="md"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="code"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="177184002"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="dsp"/>
                <source>
                  <context value="md"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="display"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="Normal delivery procedure"/>
                  </parameter>
                </target>
              </rule>
            </rule>
            <rule>
              <name value="modeDisplay"/>
              <source>
                <context value="md"/>
                <element value="answer"/>
                <listMode value="first"/>
                <variable value="a"/>
              </source>
              <rule>
                <name value="display"/>
                <source>
                  <context value="a"/>
                  <element value="value"/>
                  <variable value="cv"/>
                </source>
                <rule>
                  <name value="modeText"/>
                  <source>
                    <context value="cv"/>
                    <element value="display"/>
                    <variable value="d"/>
                  </source>
                  <target>
                    <context value="cc"/>
                    <element value="text"/>
                    <transform value="copy"/>
                    <parameter>
                      <valueId value="d"/>
                    </parameter>
                  </target>
                </rule>
              </rule>
            </rule>
          </rule>
          <documentation value="The mode decides the code. Two rules, mutually exclusive on the answer."/>
        </rule>
        <rule>
          <name value="deliveredByRule"/>
          <source>
            <context value="g"/>
            <element value="item"/>
            <variable value="db"/>
            <condition value="(linkId = 'labour-report/third-stage/delivered-by') and answer.value.exists()"/>
          </source>
          <rule>
            <name value="answer"/>
            <source>
              <context value="db"/>
              <element value="answer"/>
              <listMode value="first"/>
              <variable value="a"/>
            </source>
            <rule>
              <name value="deliveredBy"/>
              <source>
                <context value="a"/>
                <element value="value"/>
                <variable value="ref"/>
              </source>
              <target>
                <context value="proc"/>
                <element value="performer"/>
                <variable value="p"/>
              </target>
              <target>
                <context value="p"/>
                <element value="actor"/>
                <transform value="copy"/>
                <parameter>
                  <valueId value="ref"/>
                </parameter>
              </target>
            </rule>
          </rule>
        </rule>
        <rule>
          <name value="babyReceivedByRule"/>
          <source>
            <context value="g"/>
            <element value="item"/>
            <variable value="rb"/>
            <condition value="(linkId = 'labour-report/third-stage/baby-received-by') and answer.value.exists()"/>
          </source>
          <rule>
            <name value="answer"/>
            <source>
              <context value="rb"/>
              <element value="answer"/>
              <listMode value="first"/>
              <variable value="a"/>
            </source>
            <rule>
              <name value="babyReceivedBy"/>
              <source>
                <context value="a"/>
                <element value="value"/>
                <variable value="ref"/>
              </source>
              <target>
                <context value="proc"/>
                <element value="performer"/>
                <variable value="p"/>
              </target>
              <target>
                <context value="p"/>
                <element value="actor"/>
                <transform value="copy"/>
                <parameter>
                  <valueId value="ref"/>
                </parameter>
              </target>
            </rule>
          </rule>
        </rule>
        <rule>
          <name value="placentaComplicationRule"/>
          <source>
            <context value="g"/>
            <element value="item"/>
            <variable value="pc"/>
            <condition value="(linkId = 'labour-report/third-stage/placenta') and (answer.value.ofType(Coding).code = 'placenta-incomplete')"/>
          </source>
          <rule>
            <name value="incompletePlacenta"/>
            <source>
              <context value="pc"/>
            </source>
            <target>
              <context value="proc"/>
              <element value="complication"/>
              <variable value="cmp"/>
            </target>
            <target>
              <context value="cmp"/>
              <element value="concept"/>
              <variable value="cpc"/>
            </target>
            <target>
              <context value="cpc"/>
              <element value="text"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="Placenta or membranes incomplete — uterine exploration required"/>
              </parameter>
            </target>
          </rule>
        </rule>
        <rule>
          <name value="perinealTearRule"/>
          <source>
            <context value="g"/>
            <element value="item"/>
            <variable value="po"/>
            <condition value="(linkId = 'labour-report/third-stage/perineum') and (answer.value.ofType(Coding).code = 'perineum-tear')"/>
          </source>
          <rule>
            <name value="perinealTear"/>
            <source>
              <context value="po"/>
            </source>
            <target>
              <context value="proc"/>
              <element value="complication"/>
              <variable value="cmp"/>
            </target>
            <target>
              <context value="cmp"/>
              <element value="concept"/>
              <variable value="cpc"/>
            </target>
            <target>
              <context value="cpc"/>
              <element value="text"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="Perineal tear"/>
              </parameter>
            </target>
          </rule>
        </rule>
      </rule>
      <rule>
        <name value="stageDuration"/>
        <source>
          <context value="lg"/>
          <element value="item"/>
          <variable value="g"/>
          <condition value="linkId = 'labour-report/first-stage'"/>
        </source>
        <rule>
          <name value="measure_labour_stage_duration2"/>
          <source>
            <context value="g"/>
            <element value="item"/>
            <variable value="it"/>
            <condition value="(linkId = 'labour-report/first-stage/duration') and answer.value.exists()"/>
          </source>
          <target>
            <context value="bundle"/>
            <element value="entry"/>
            <variable value="entry"/>
          </target>
          <target>
            <context value="entry"/>
            <element value="resource"/>
            <variable value="obs"/>
            <transform value="create"/>
            <parameter>
              <valueString value="Observation"/>
            </parameter>
          </target>
          <rule>
            <name value="base"/>
            <source>
              <context value="qr"/>
            </source>
            <target>
              <context value="obs"/>
            </target>
            <target>
              <context value="entry"/>
            </target>
            <dependent>
              <name value="BuildObsBase"/>
              <parameter>
                <valueId value="qr"/>
              </parameter>
              <parameter>
                <valueId value="obs"/>
              </parameter>
              <parameter>
                <valueId value="entry"/>
              </parameter>
            </dependent>
          </rule>
          <rule>
            <name value="category"/>
            <source>
              <context value="qr"/>
            </source>
            <target>
              <context value="obs"/>
            </target>
            <dependent>
              <name value="SetProcedureCategory"/>
              <parameter>
                <valueId value="qr"/>
              </parameter>
              <parameter>
                <valueId value="obs"/>
              </parameter>
            </dependent>
          </rule>
          <rule>
            <name value="code"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="obs"/>
              <element value="code"/>
              <variable value="cc"/>
            </target>
            <rule>
              <name value="coding"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cc"/>
                <element value="coding"/>
                <variable value="cg"/>
              </target>
              <rule>
                <name value="sys"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="system"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="cd"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="code"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="obs-duration-of-the-first-stage-of-labour"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="dsp"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="display"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="Duration of the first stage of labour"/>
                  </parameter>
                </target>
              </rule>
            </rule>
          </rule>
          <rule>
            <name value="answer"/>
            <source>
              <context value="it"/>
              <element value="answer"/>
              <listMode value="first"/>
              <variable value="a"/>
            </source>
            <rule>
              <name value="set"/>
              <source>
                <context value="a"/>
                <element value="value"/>
                <variable value="v"/>
              </source>
              <target>
                <context value="obs"/>
                <element value="value"/>
                <transform value="copy"/>
                <parameter>
                  <valueId value="v"/>
                </parameter>
              </target>
            </rule>
          </rule>
        </rule>
        <documentation value="── The stage durations ───────────────────────────────────────────────"/>
      </rule>
      <rule>
        <name value="stageDuration2"/>
        <source>
          <context value="lg"/>
          <element value="item"/>
          <variable value="g"/>
          <condition value="linkId = 'labour-report/second-stage'"/>
        </source>
        <rule>
          <name value="measure_labour_stage_duration3"/>
          <source>
            <context value="g"/>
            <element value="item"/>
            <variable value="it"/>
            <condition value="(linkId = 'labour-report/second-stage/duration') and answer.value.exists()"/>
          </source>
          <target>
            <context value="bundle"/>
            <element value="entry"/>
            <variable value="entry"/>
          </target>
          <target>
            <context value="entry"/>
            <element value="resource"/>
            <variable value="obs"/>
            <transform value="create"/>
            <parameter>
              <valueString value="Observation"/>
            </parameter>
          </target>
          <rule>
            <name value="base"/>
            <source>
              <context value="qr"/>
            </source>
            <target>
              <context value="obs"/>
            </target>
            <target>
              <context value="entry"/>
            </target>
            <dependent>
              <name value="BuildObsBase"/>
              <parameter>
                <valueId value="qr"/>
              </parameter>
              <parameter>
                <valueId value="obs"/>
              </parameter>
              <parameter>
                <valueId value="entry"/>
              </parameter>
            </dependent>
          </rule>
          <rule>
            <name value="category"/>
            <source>
              <context value="qr"/>
            </source>
            <target>
              <context value="obs"/>
            </target>
            <dependent>
              <name value="SetProcedureCategory"/>
              <parameter>
                <valueId value="qr"/>
              </parameter>
              <parameter>
                <valueId value="obs"/>
              </parameter>
            </dependent>
          </rule>
          <rule>
            <name value="code"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="obs"/>
              <element value="code"/>
              <variable value="cc"/>
            </target>
            <rule>
              <name value="coding"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cc"/>
                <element value="coding"/>
                <variable value="cg"/>
              </target>
              <rule>
                <name value="sys"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="system"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="cd"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="code"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="obs-duration-of-the-second-stage-of-labour"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="dsp"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="display"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="Duration of the second stage of labour"/>
                  </parameter>
                </target>
              </rule>
            </rule>
          </rule>
          <rule>
            <name value="answer"/>
            <source>
              <context value="it"/>
              <element value="answer"/>
              <listMode value="first"/>
              <variable value="a"/>
            </source>
            <rule>
              <name value="set"/>
              <source>
                <context value="a"/>
                <element value="value"/>
                <variable value="v"/>
              </source>
              <target>
                <context value="obs"/>
                <element value="value"/>
                <transform value="copy"/>
                <parameter>
                  <valueId value="v"/>
                </parameter>
              </target>
            </rule>
          </rule>
        </rule>
      </rule>
      <rule>
        <name value="thirdStageGroup"/>
        <source>
          <context value="lg"/>
          <element value="item"/>
          <variable value="g"/>
          <condition value="linkId = 'labour-report/third-stage'"/>
        </source>
        <rule>
          <name value="measure_8717_1"/>
          <source>
            <context value="g"/>
            <element value="item"/>
            <variable value="it"/>
            <condition value="(linkId = 'labour-report/third-stage/blood-loss') and answer.value.exists()"/>
          </source>
          <target>
            <context value="bundle"/>
            <element value="entry"/>
            <variable value="entry"/>
          </target>
          <target>
            <context value="entry"/>
            <element value="resource"/>
            <variable value="obs"/>
            <transform value="create"/>
            <parameter>
              <valueString value="Observation"/>
            </parameter>
          </target>
          <rule>
            <name value="base"/>
            <source>
              <context value="qr"/>
            </source>
            <target>
              <context value="obs"/>
            </target>
            <target>
              <context value="entry"/>
            </target>
            <dependent>
              <name value="BuildObsBase"/>
              <parameter>
                <valueId value="qr"/>
              </parameter>
              <parameter>
                <valueId value="obs"/>
              </parameter>
              <parameter>
                <valueId value="entry"/>
              </parameter>
            </dependent>
          </rule>
          <rule>
            <name value="category"/>
            <source>
              <context value="qr"/>
            </source>
            <target>
              <context value="obs"/>
            </target>
            <dependent>
              <name value="SetProcedureCategory"/>
              <parameter>
                <valueId value="qr"/>
              </parameter>
              <parameter>
                <valueId value="obs"/>
              </parameter>
            </dependent>
          </rule>
          <rule>
            <name value="code"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="obs"/>
              <element value="code"/>
              <variable value="cc"/>
            </target>
            <rule>
              <name value="coding"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cc"/>
                <element value="coding"/>
                <variable value="cg"/>
              </target>
              <rule>
                <name value="sys"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="system"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="http://loinc.org"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="cd"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="code"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="8717-1"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="dsp"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="display"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="Surgical operation note estimated blood loss [Volume]"/>
                  </parameter>
                </target>
              </rule>
            </rule>
          </rule>
          <rule>
            <name value="answer"/>
            <source>
              <context value="it"/>
              <element value="answer"/>
              <listMode value="first"/>
              <variable value="a"/>
            </source>
            <rule>
              <name value="set"/>
              <source>
                <context value="a"/>
                <element value="value"/>
                <variable value="v"/>
              </source>
              <target>
                <context value="obs"/>
                <element value="value"/>
                <transform value="copy"/>
                <parameter>
                  <valueId value="v"/>
                </parameter>
              </target>
            </rule>
          </rule>
          <rule>
            <name value="note"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="obs"/>
              <element value="note"/>
              <variable value="n"/>
            </target>
            <target>
              <context value="n"/>
              <element value="text"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="An estimate made at delivery, not a measured volume."/>
              </parameter>
            </target>
          </rule>
        </rule>
        <rule>
          <name value="measure_placenta_completeness"/>
          <source>
            <context value="g"/>
            <element value="item"/>
            <variable value="it"/>
            <condition value="(linkId = 'labour-report/third-stage/placenta-weight') and answer.value.exists()"/>
          </source>
          <target>
            <context value="bundle"/>
            <element value="entry"/>
            <variable value="entry"/>
          </target>
          <target>
            <context value="entry"/>
            <element value="resource"/>
            <variable value="obs"/>
            <transform value="create"/>
            <parameter>
              <valueString value="Observation"/>
            </parameter>
          </target>
          <rule>
            <name value="base"/>
            <source>
              <context value="qr"/>
            </source>
            <target>
              <context value="obs"/>
            </target>
            <target>
              <context value="entry"/>
            </target>
            <dependent>
              <name value="BuildObsBase"/>
              <parameter>
                <valueId value="qr"/>
              </parameter>
              <parameter>
                <valueId value="obs"/>
              </parameter>
              <parameter>
                <valueId value="entry"/>
              </parameter>
            </dependent>
          </rule>
          <rule>
            <name value="category"/>
            <source>
              <context value="qr"/>
            </source>
            <target>
              <context value="obs"/>
            </target>
            <dependent>
              <name value="SetProcedureCategory"/>
              <parameter>
                <valueId value="qr"/>
              </parameter>
              <parameter>
                <valueId value="obs"/>
              </parameter>
            </dependent>
          </rule>
          <rule>
            <name value="code"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="obs"/>
              <element value="code"/>
              <variable value="cc"/>
            </target>
            <rule>
              <name value="coding"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cc"/>
                <element value="coding"/>
                <variable value="cg"/>
              </target>
              <rule>
                <name value="sys"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="system"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="cd"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="code"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="obstetric-placenta-weight"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="dsp"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="display"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="Placenta weight"/>
                  </parameter>
                </target>
              </rule>
            </rule>
          </rule>
          <rule>
            <name value="answer"/>
            <source>
              <context value="it"/>
              <element value="answer"/>
              <listMode value="first"/>
              <variable value="a"/>
            </source>
            <rule>
              <name value="set"/>
              <source>
                <context value="a"/>
                <element value="value"/>
                <variable value="v"/>
              </source>
              <target>
                <context value="obs"/>
                <element value="value"/>
                <transform value="copy"/>
                <parameter>
                  <valueId value="v"/>
                </parameter>
              </target>
            </rule>
          </rule>
        </rule>
        <rule>
          <name value="coded_placenta_completeness"/>
          <source>
            <context value="g"/>
            <element value="item"/>
            <variable value="it"/>
            <condition value="(linkId = 'labour-report/third-stage/placenta') and answer.value.exists()"/>
          </source>
          <target>
            <context value="bundle"/>
            <element value="entry"/>
            <variable value="entry"/>
          </target>
          <target>
            <context value="entry"/>
            <element value="resource"/>
            <variable value="obs"/>
            <transform value="create"/>
            <parameter>
              <valueString value="Observation"/>
            </parameter>
          </target>
          <rule>
            <name value="base"/>
            <source>
              <context value="qr"/>
            </source>
            <target>
              <context value="obs"/>
            </target>
            <target>
              <context value="entry"/>
            </target>
            <dependent>
              <name value="BuildObsBase"/>
              <parameter>
                <valueId value="qr"/>
              </parameter>
              <parameter>
                <valueId value="obs"/>
              </parameter>
              <parameter>
                <valueId value="entry"/>
              </parameter>
            </dependent>
          </rule>
          <rule>
            <name value="category"/>
            <source>
              <context value="qr"/>
            </source>
            <target>
              <context value="obs"/>
            </target>
            <dependent>
              <name value="SetExamCategory"/>
              <parameter>
                <valueId value="qr"/>
              </parameter>
              <parameter>
                <valueId value="obs"/>
              </parameter>
            </dependent>
          </rule>
          <rule>
            <name value="code"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="obs"/>
              <element value="code"/>
              <variable value="cc"/>
            </target>
            <rule>
              <name value="coding"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cc"/>
                <element value="coding"/>
                <variable value="cg"/>
              </target>
              <rule>
                <name value="sys"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="system"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="cd"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="code"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="placenta-completeness"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="dsp"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="display"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="Placenta and membrane completeness"/>
                  </parameter>
                </target>
              </rule>
            </rule>
          </rule>
          <rule>
            <name value="answer"/>
            <source>
              <context value="it"/>
              <element value="answer"/>
              <listMode value="first"/>
              <variable value="a"/>
            </source>
            <rule>
              <name value="codedValue"/>
              <source>
                <context value="a"/>
                <element value="value"/>
                <variable value="cv"/>
              </source>
              <target>
                <context value="obs"/>
                <element value="value"/>
                <variable value="cc"/>
                <transform value="create"/>
                <parameter>
                  <valueString value="CodeableConcept"/>
                </parameter>
              </target>
              <rule>
                <name value="valueCoding"/>
                <source>
                  <context value="cv"/>
                </source>
                <target>
                  <context value="cc"/>
                  <element value="coding"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueId value="cv"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="valueText"/>
                <source>
                  <context value="cv"/>
                  <element value="display"/>
                  <variable value="d"/>
                </source>
                <target>
                  <context value="cc"/>
                  <element value="text"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueId value="d"/>
                  </parameter>
                </target>
              </rule>
            </rule>
          </rule>
        </rule>
        <rule>
          <name value="coded_perineal_outcome"/>
          <source>
            <context value="g"/>
            <element value="item"/>
            <variable value="it"/>
            <condition value="(linkId = 'labour-report/third-stage/perineum') and answer.value.exists()"/>
          </source>
          <target>
            <context value="bundle"/>
            <element value="entry"/>
            <variable value="entry"/>
          </target>
          <target>
            <context value="entry"/>
            <element value="resource"/>
            <variable value="obs"/>
            <transform value="create"/>
            <parameter>
              <valueString value="Observation"/>
            </parameter>
          </target>
          <rule>
            <name value="base"/>
            <source>
              <context value="qr"/>
            </source>
            <target>
              <context value="obs"/>
            </target>
            <target>
              <context value="entry"/>
            </target>
            <dependent>
              <name value="BuildObsBase"/>
              <parameter>
                <valueId value="qr"/>
              </parameter>
              <parameter>
                <valueId value="obs"/>
              </parameter>
              <parameter>
                <valueId value="entry"/>
              </parameter>
            </dependent>
          </rule>
          <rule>
            <name value="category"/>
            <source>
              <context value="qr"/>
            </source>
            <target>
              <context value="obs"/>
            </target>
            <dependent>
              <name value="SetExamCategory"/>
              <parameter>
                <valueId value="qr"/>
              </parameter>
              <parameter>
                <valueId value="obs"/>
              </parameter>
            </dependent>
          </rule>
          <rule>
            <name value="code"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="obs"/>
              <element value="code"/>
              <variable value="cc"/>
            </target>
            <rule>
              <name value="coding"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cc"/>
                <element value="coding"/>
                <variable value="cg"/>
              </target>
              <rule>
                <name value="sys"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="system"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="cd"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="code"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="perineal-outcome"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="dsp"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="display"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="Perineal outcome"/>
                  </parameter>
                </target>
              </rule>
            </rule>
          </rule>
          <rule>
            <name value="answer"/>
            <source>
              <context value="it"/>
              <element value="answer"/>
              <listMode value="first"/>
              <variable value="a"/>
            </source>
            <rule>
              <name value="codedValue"/>
              <source>
                <context value="a"/>
                <element value="value"/>
                <variable value="cv"/>
              </source>
              <target>
                <context value="obs"/>
                <element value="value"/>
                <variable value="cc"/>
                <transform value="create"/>
                <parameter>
                  <valueString value="CodeableConcept"/>
                </parameter>
              </target>
              <rule>
                <name value="valueCoding"/>
                <source>
                  <context value="cv"/>
                </source>
                <target>
                  <context value="cc"/>
                  <element value="coding"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueId value="cv"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="valueText"/>
                <source>
                  <context value="cv"/>
                  <element value="display"/>
                  <variable value="d"/>
                </source>
                <target>
                  <context value="cc"/>
                  <element value="text"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueId value="d"/>
                  </parameter>
                </target>
              </rule>
            </rule>
          </rule>
        </rule>
        <rule>
          <name value="measure_9272_6"/>
          <source>
            <context value="g"/>
            <element value="item"/>
            <variable value="it"/>
            <condition value="(linkId = 'labour-report/third-stage/apgar-1-minute') and answer.value.exists()"/>
          </source>
          <target>
            <context value="bundle"/>
            <element value="entry"/>
            <variable value="entry"/>
          </target>
          <target>
            <context value="entry"/>
            <element value="resource"/>
            <variable value="obs"/>
            <transform value="create"/>
            <parameter>
              <valueString value="Observation"/>
            </parameter>
          </target>
          <rule>
            <name value="base"/>
            <source>
              <context value="qr"/>
            </source>
            <target>
              <context value="obs"/>
            </target>
            <target>
              <context value="entry"/>
            </target>
            <dependent>
              <name value="BuildObsBase"/>
              <parameter>
                <valueId value="qr"/>
              </parameter>
              <parameter>
                <valueId value="obs"/>
              </parameter>
              <parameter>
                <valueId value="entry"/>
              </parameter>
            </dependent>
          </rule>
          <rule>
            <name value="category"/>
            <source>
              <context value="qr"/>
            </source>
            <target>
              <context value="obs"/>
            </target>
            <dependent>
              <name value="SetSurveyCategory"/>
              <parameter>
                <valueId value="qr"/>
              </parameter>
              <parameter>
                <valueId value="obs"/>
              </parameter>
            </dependent>
          </rule>
          <rule>
            <name value="code"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="obs"/>
              <element value="code"/>
              <variable value="cc"/>
            </target>
            <rule>
              <name value="coding"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cc"/>
                <element value="coding"/>
                <variable value="cg"/>
              </target>
              <rule>
                <name value="sys"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="system"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="http://loinc.org"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="cd"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="code"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="9272-6"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="dsp"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="display"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="1 minute Apgar Score"/>
                  </parameter>
                </target>
              </rule>
            </rule>
          </rule>
          <rule>
            <name value="answer"/>
            <source>
              <context value="it"/>
              <element value="answer"/>
              <listMode value="first"/>
              <variable value="a"/>
            </source>
            <rule>
              <name value="set"/>
              <source>
                <context value="a"/>
                <element value="value"/>
                <variable value="v"/>
              </source>
              <target>
                <context value="obs"/>
                <element value="value"/>
                <transform value="copy"/>
                <parameter>
                  <valueId value="v"/>
                </parameter>
              </target>
            </rule>
          </rule>
        </rule>
        <rule>
          <name value="measure_9274_2"/>
          <source>
            <context value="g"/>
            <element value="item"/>
            <variable value="it"/>
            <condition value="(linkId = 'labour-report/third-stage/apgar-5-minutes') and answer.value.exists()"/>
          </source>
          <target>
            <context value="bundle"/>
            <element value="entry"/>
            <variable value="entry"/>
          </target>
          <target>
            <context value="entry"/>
            <element value="resource"/>
            <variable value="obs"/>
            <transform value="create"/>
            <parameter>
              <valueString value="Observation"/>
            </parameter>
          </target>
          <rule>
            <name value="base"/>
            <source>
              <context value="qr"/>
            </source>
            <target>
              <context value="obs"/>
            </target>
            <target>
              <context value="entry"/>
            </target>
            <dependent>
              <name value="BuildObsBase"/>
              <parameter>
                <valueId value="qr"/>
              </parameter>
              <parameter>
                <valueId value="obs"/>
              </parameter>
              <parameter>
                <valueId value="entry"/>
              </parameter>
            </dependent>
          </rule>
          <rule>
            <name value="category"/>
            <source>
              <context value="qr"/>
            </source>
            <target>
              <context value="obs"/>
            </target>
            <dependent>
              <name value="SetSurveyCategory"/>
              <parameter>
                <valueId value="qr"/>
              </parameter>
              <parameter>
                <valueId value="obs"/>
              </parameter>
            </dependent>
          </rule>
          <rule>
            <name value="code"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="obs"/>
              <element value="code"/>
              <variable value="cc"/>
            </target>
            <rule>
              <name value="coding"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cc"/>
                <element value="coding"/>
                <variable value="cg"/>
              </target>
              <rule>
                <name value="sys"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="system"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="http://loinc.org"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="cd"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="code"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="9274-2"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="dsp"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="display"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="5 minute Apgar Score"/>
                  </parameter>
                </target>
              </rule>
            </rule>
          </rule>
          <rule>
            <name value="answer"/>
            <source>
              <context value="it"/>
              <element value="answer"/>
              <listMode value="first"/>
              <variable value="a"/>
            </source>
            <rule>
              <name value="set"/>
              <source>
                <context value="a"/>
                <element value="value"/>
                <variable value="v"/>
              </source>
              <target>
                <context value="obs"/>
                <element value="value"/>
                <transform value="copy"/>
                <parameter>
                  <valueId value="v"/>
                </parameter>
              </target>
            </rule>
          </rule>
        </rule>
        <rule>
          <name value="motherObservations"/>
          <source>
            <context value="g"/>
            <element value="item"/>
            <variable value="g2"/>
            <condition value="(linkId = 'labour-report/third-stage/mother-observations') and item.answer.value.exists()"/>
          </source>
          <target>
            <context value="bundle"/>
            <element value="entry"/>
            <variable value="entry"/>
          </target>
          <target>
            <context value="entry"/>
            <element value="resource"/>
            <variable value="obs"/>
            <transform value="create"/>
            <parameter>
              <valueString value="Observation"/>
            </parameter>
          </target>
          <rule>
            <name value="base"/>
            <source>
              <context value="qr"/>
            </source>
            <target>
              <context value="obs"/>
            </target>
            <target>
              <context value="entry"/>
            </target>
            <dependent>
              <name value="BuildObsBase"/>
              <parameter>
                <valueId value="qr"/>
              </parameter>
              <parameter>
                <valueId value="obs"/>
              </parameter>
              <parameter>
                <valueId value="entry"/>
              </parameter>
            </dependent>
          </rule>
          <rule>
            <name value="category"/>
            <source>
              <context value="qr"/>
            </source>
            <target>
              <context value="obs"/>
            </target>
            <dependent>
              <name value="SetVitalSignsCategory"/>
              <parameter>
                <valueId value="qr"/>
              </parameter>
              <parameter>
                <valueId value="obs"/>
              </parameter>
            </dependent>
          </rule>
          <rule>
            <name value="code"/>
            <source>
              <context value="g2"/>
            </source>
            <target>
              <context value="obs"/>
              <element value="code"/>
              <variable value="cc"/>
            </target>
            <rule>
              <name value="coding"/>
              <source>
                <context value="g2"/>
              </source>
              <target>
                <context value="cc"/>
                <element value="coding"/>
                <variable value="cg"/>
              </target>
              <rule>
                <name value="sys"/>
                <source>
                  <context value="g2"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="system"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="http://loinc.org"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="cd"/>
                <source>
                  <context value="g2"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="code"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="8716-3"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="dsp"/>
                <source>
                  <context value="g2"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="display"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="Vital signs note"/>
                  </parameter>
                </target>
              </rule>
            </rule>
            <rule>
              <name value="codeText"/>
              <source>
                <context value="g2"/>
              </source>
              <target>
                <context value="cc"/>
                <element value="text"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="Mother observations after delivery"/>
                </parameter>
              </target>
            </rule>
          </rule>
          <rule>
            <name value="comp_8480_62"/>
            <source>
              <context value="g2"/>
              <element value="item"/>
              <variable value="it"/>
              <condition value="(linkId = 'labour-report/third-stage/mother-observations/systolic') and answer.value.exists()"/>
            </source>
            <target>
              <context value="obs"/>
              <element value="component"/>
              <variable value="comp"/>
            </target>
            <rule>
              <name value="code"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="comp"/>
                <element value="code"/>
                <variable value="cc"/>
              </target>
              <rule>
                <name value="coding"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cc"/>
                  <element value="coding"/>
                  <variable value="cg"/>
                </target>
                <rule>
                  <name value="sys"/>
                  <source>
                    <context value="it"/>
                  </source>
                  <target>
                    <context value="cg"/>
                    <element value="system"/>
                    <transform value="copy"/>
                    <parameter>
                      <valueString value="http://loinc.org"/>
                    </parameter>
                  </target>
                </rule>
                <rule>
                  <name value="cd"/>
                  <source>
                    <context value="it"/>
                  </source>
                  <target>
                    <context value="cg"/>
                    <element value="code"/>
                    <transform value="copy"/>
                    <parameter>
                      <valueString value="8480-6"/>
                    </parameter>
                  </target>
                </rule>
                <rule>
                  <name value="dsp"/>
                  <source>
                    <context value="it"/>
                  </source>
                  <target>
                    <context value="cg"/>
                    <element value="display"/>
                    <transform value="copy"/>
                    <parameter>
                      <valueString value="Systolic blood pressure"/>
                    </parameter>
                  </target>
                </rule>
              </rule>
            </rule>
            <rule>
              <name value="value"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="comp"/>
              </target>
              <dependent>
                <name value="SetComponentValue"/>
                <parameter>
                  <valueId value="it"/>
                </parameter>
                <parameter>
                  <valueId value="comp"/>
                </parameter>
              </dependent>
            </rule>
          </rule>
          <rule>
            <name value="comp_8462_42"/>
            <source>
              <context value="g2"/>
              <element value="item"/>
              <variable value="it"/>
              <condition value="(linkId = 'labour-report/third-stage/mother-observations/diastolic') and answer.value.exists()"/>
            </source>
            <target>
              <context value="obs"/>
              <element value="component"/>
              <variable value="comp"/>
            </target>
            <rule>
              <name value="code"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="comp"/>
                <element value="code"/>
                <variable value="cc"/>
              </target>
              <rule>
                <name value="coding"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cc"/>
                  <element value="coding"/>
                  <variable value="cg"/>
                </target>
                <rule>
                  <name value="sys"/>
                  <source>
                    <context value="it"/>
                  </source>
                  <target>
                    <context value="cg"/>
                    <element value="system"/>
                    <transform value="copy"/>
                    <parameter>
                      <valueString value="http://loinc.org"/>
                    </parameter>
                  </target>
                </rule>
                <rule>
                  <name value="cd"/>
                  <source>
                    <context value="it"/>
                  </source>
                  <target>
                    <context value="cg"/>
                    <element value="code"/>
                    <transform value="copy"/>
                    <parameter>
                      <valueString value="8462-4"/>
                    </parameter>
                  </target>
                </rule>
                <rule>
                  <name value="dsp"/>
                  <source>
                    <context value="it"/>
                  </source>
                  <target>
                    <context value="cg"/>
                    <element value="display"/>
                    <transform value="copy"/>
                    <parameter>
                      <valueString value="Diastolic blood pressure"/>
                    </parameter>
                  </target>
                </rule>
              </rule>
            </rule>
            <rule>
              <name value="value"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="comp"/>
              </target>
              <dependent>
                <name value="SetComponentValue"/>
                <parameter>
                  <valueId value="it"/>
                </parameter>
                <parameter>
                  <valueId value="comp"/>
                </parameter>
              </dependent>
            </rule>
          </rule>
          <rule>
            <name value="comp_8867_4"/>
            <source>
              <context value="g2"/>
              <element value="item"/>
              <variable value="it"/>
              <condition value="(linkId = 'labour-report/third-stage/mother-observations/pulse') and answer.value.exists()"/>
            </source>
            <target>
              <context value="obs"/>
              <element value="component"/>
              <variable value="comp"/>
            </target>
            <rule>
              <name value="code"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="comp"/>
                <element value="code"/>
                <variable value="cc"/>
              </target>
              <rule>
                <name value="coding"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cc"/>
                  <element value="coding"/>
                  <variable value="cg"/>
                </target>
                <rule>
                  <name value="sys"/>
                  <source>
                    <context value="it"/>
                  </source>
                  <target>
                    <context value="cg"/>
                    <element value="system"/>
                    <transform value="copy"/>
                    <parameter>
                      <valueString value="http://loinc.org"/>
                    </parameter>
                  </target>
                </rule>
                <rule>
                  <name value="cd"/>
                  <source>
                    <context value="it"/>
                  </source>
                  <target>
                    <context value="cg"/>
                    <element value="code"/>
                    <transform value="copy"/>
                    <parameter>
                      <valueString value="8867-4"/>
                    </parameter>
                  </target>
                </rule>
                <rule>
                  <name value="dsp"/>
                  <source>
                    <context value="it"/>
                  </source>
                  <target>
                    <context value="cg"/>
                    <element value="display"/>
                    <transform value="copy"/>
                    <parameter>
                      <valueString value="Heart rate"/>
                    </parameter>
                  </target>
                </rule>
              </rule>
            </rule>
            <rule>
              <name value="value"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="comp"/>
              </target>
              <dependent>
                <name value="SetComponentValue"/>
                <parameter>
                  <valueId value="it"/>
                </parameter>
                <parameter>
                  <valueId value="comp"/>
                </parameter>
              </dependent>
            </rule>
          </rule>
          <rule>
            <name value="comp_8310_5"/>
            <source>
              <context value="g2"/>
              <element value="item"/>
              <variable value="it"/>
              <condition value="(linkId = 'labour-report/third-stage/mother-observations/temperature') and answer.value.exists()"/>
            </source>
            <target>
              <context value="obs"/>
              <element value="component"/>
              <variable value="comp"/>
            </target>
            <rule>
              <name value="code"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="comp"/>
                <element value="code"/>
                <variable value="cc"/>
              </target>
              <rule>
                <name value="coding"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cc"/>
                  <element value="coding"/>
                  <variable value="cg"/>
                </target>
                <rule>
                  <name value="sys"/>
                  <source>
                    <context value="it"/>
                  </source>
                  <target>
                    <context value="cg"/>
                    <element value="system"/>
                    <transform value="copy"/>
                    <parameter>
                      <valueString value="http://loinc.org"/>
                    </parameter>
                  </target>
                </rule>
                <rule>
                  <name value="cd"/>
                  <source>
                    <context value="it"/>
                  </source>
                  <target>
                    <context value="cg"/>
                    <element value="code"/>
                    <transform value="copy"/>
                    <parameter>
                      <valueString value="8310-5"/>
                    </parameter>
                  </target>
                </rule>
                <rule>
                  <name value="dsp"/>
                  <source>
                    <context value="it"/>
                  </source>
                  <target>
                    <context value="cg"/>
                    <element value="display"/>
                    <transform value="copy"/>
                    <parameter>
                      <valueString value="Body temperature"/>
                    </parameter>
                  </target>
                </rule>
              </rule>
            </rule>
            <rule>
              <name value="value"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="comp"/>
              </target>
              <dependent>
                <name value="SetComponentValue"/>
                <parameter>
                  <valueId value="it"/>
                </parameter>
                <parameter>
                  <valueId value="comp"/>
                </parameter>
              </dependent>
            </rule>
          </rule>
          <rule>
            <name value="comp_9279_1"/>
            <source>
              <context value="g2"/>
              <element value="item"/>
              <variable value="it"/>
              <condition value="(linkId = 'labour-report/third-stage/mother-observations/respiratory-rate') and answer.value.exists()"/>
            </source>
            <target>
              <context value="obs"/>
              <element value="component"/>
              <variable value="comp"/>
            </target>
            <rule>
              <name value="code"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="comp"/>
                <element value="code"/>
                <variable value="cc"/>
              </target>
              <rule>
                <name value="coding"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cc"/>
                  <element value="coding"/>
                  <variable value="cg"/>
                </target>
                <rule>
                  <name value="sys"/>
                  <source>
                    <context value="it"/>
                  </source>
                  <target>
                    <context value="cg"/>
                    <element value="system"/>
                    <transform value="copy"/>
                    <parameter>
                      <valueString value="http://loinc.org"/>
                    </parameter>
                  </target>
                </rule>
                <rule>
                  <name value="cd"/>
                  <source>
                    <context value="it"/>
                  </source>
                  <target>
                    <context value="cg"/>
                    <element value="code"/>
                    <transform value="copy"/>
                    <parameter>
                      <valueString value="9279-1"/>
                    </parameter>
                  </target>
                </rule>
                <rule>
                  <name value="dsp"/>
                  <source>
                    <context value="it"/>
                  </source>
                  <target>
                    <context value="cg"/>
                    <element value="display"/>
                    <transform value="copy"/>
                    <parameter>
                      <valueString value="Respiratory rate"/>
                    </parameter>
                  </target>
                </rule>
              </rule>
            </rule>
            <rule>
              <name value="value"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="comp"/>
              </target>
              <dependent>
                <name value="SetComponentValue"/>
                <parameter>
                  <valueId value="it"/>
                </parameter>
                <parameter>
                  <valueId value="comp"/>
                </parameter>
              </dependent>
            </rule>
          </rule>
          <documentation value="The mother's observations after delivery, as one panel with the blood&#xD;&#xA;pressure paired inside it."/>
        </rule>
        <rule>
          <name value="babyMeasurements"/>
          <source>
            <context value="g"/>
            <element value="item"/>
            <variable value="g2"/>
            <condition value="(linkId = 'labour-report/third-stage/baby-measurements') and item.answer.value.exists()"/>
          </source>
          <target>
            <context value="bundle"/>
            <element value="entry"/>
            <variable value="entry"/>
          </target>
          <target>
            <context value="entry"/>
            <element value="resource"/>
            <variable value="obs"/>
            <transform value="create"/>
            <parameter>
              <valueString value="Observation"/>
            </parameter>
          </target>
          <rule>
            <name value="base"/>
            <source>
              <context value="qr"/>
            </source>
            <target>
              <context value="obs"/>
            </target>
            <target>
              <context value="entry"/>
            </target>
            <dependent>
              <name value="BuildObsBase"/>
              <parameter>
                <valueId value="qr"/>
              </parameter>
              <parameter>
                <valueId value="obs"/>
              </parameter>
              <parameter>
                <valueId value="entry"/>
              </parameter>
            </dependent>
          </rule>
          <rule>
            <name value="category"/>
            <source>
              <context value="qr"/>
            </source>
            <target>
              <context value="obs"/>
            </target>
            <dependent>
              <name value="SetSurveyCategory"/>
              <parameter>
                <valueId value="qr"/>
              </parameter>
              <parameter>
                <valueId value="obs"/>
              </parameter>
            </dependent>
          </rule>
          <rule>
            <name value="code"/>
            <source>
              <context value="g2"/>
            </source>
            <target>
              <context value="obs"/>
              <element value="code"/>
              <variable value="cc"/>
            </target>
            <rule>
              <name value="coding"/>
              <source>
                <context value="g2"/>
              </source>
              <target>
                <context value="cc"/>
                <element value="coding"/>
                <variable value="cg"/>
              </target>
              <rule>
                <name value="sys"/>
                <source>
                  <context value="g2"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="system"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="http://loinc.org"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="cd"/>
                <source>
                  <context value="g2"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="code"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="8339-4"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="dsp"/>
                <source>
                  <context value="g2"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="display"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="Birth weight Measured"/>
                  </parameter>
                </target>
              </rule>
            </rule>
            <rule>
              <name value="codeText"/>
              <source>
                <context value="g2"/>
              </source>
              <target>
                <context value="cc"/>
                <element value="text"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="Baby measurements at delivery"/>
                </parameter>
              </target>
            </rule>
          </rule>
          <rule>
            <name value="subjectNote"/>
            <source>
              <context value="g2"/>
            </source>
            <target>
              <context value="obs"/>
              <element value="note"/>
              <variable value="n"/>
            </target>
            <target>
              <context value="n"/>
              <element value="text"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="Recorded on the mother's maternity record. These are measurements of the baby; the newborn's own chart is the authoritative record for them."/>
              </parameter>
            </target>
          </rule>
          <rule>
            <name value="comp_8339_42"/>
            <source>
              <context value="g2"/>
              <element value="item"/>
              <variable value="it"/>
              <condition value="(linkId = 'labour-report/third-stage/baby-measurements/weight') and answer.value.exists()"/>
            </source>
            <target>
              <context value="obs"/>
              <element value="component"/>
              <variable value="comp"/>
            </target>
            <rule>
              <name value="code"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="comp"/>
                <element value="code"/>
                <variable value="cc"/>
              </target>
              <rule>
                <name value="coding"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cc"/>
                  <element value="coding"/>
                  <variable value="cg"/>
                </target>
                <rule>
                  <name value="sys"/>
                  <source>
                    <context value="it"/>
                  </source>
                  <target>
                    <context value="cg"/>
                    <element value="system"/>
                    <transform value="copy"/>
                    <parameter>
                      <valueString value="http://loinc.org"/>
                    </parameter>
                  </target>
                </rule>
                <rule>
                  <name value="cd"/>
                  <source>
                    <context value="it"/>
                  </source>
                  <target>
                    <context value="cg"/>
                    <element value="code"/>
                    <transform value="copy"/>
                    <parameter>
                      <valueString value="8339-4"/>
                    </parameter>
                  </target>
                </rule>
                <rule>
                  <name value="dsp"/>
                  <source>
                    <context value="it"/>
                  </source>
                  <target>
                    <context value="cg"/>
                    <element value="display"/>
                    <transform value="copy"/>
                    <parameter>
                      <valueString value="Birth weight Measured"/>
                    </parameter>
                  </target>
                </rule>
              </rule>
            </rule>
            <rule>
              <name value="value"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="comp"/>
              </target>
              <dependent>
                <name value="SetComponentValue"/>
                <parameter>
                  <valueId value="it"/>
                </parameter>
                <parameter>
                  <valueId value="comp"/>
                </parameter>
              </dependent>
            </rule>
          </rule>
          <rule>
            <name value="comp_8306_3"/>
            <source>
              <context value="g2"/>
              <element value="item"/>
              <variable value="it"/>
              <condition value="(linkId = 'labour-report/third-stage/baby-measurements/length') and answer.value.exists()"/>
            </source>
            <target>
              <context value="obs"/>
              <element value="component"/>
              <variable value="comp"/>
            </target>
            <rule>
              <name value="code"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="comp"/>
                <element value="code"/>
                <variable value="cc"/>
              </target>
              <rule>
                <name value="coding"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cc"/>
                  <element value="coding"/>
                  <variable value="cg"/>
                </target>
                <rule>
                  <name value="sys"/>
                  <source>
                    <context value="it"/>
                  </source>
                  <target>
                    <context value="cg"/>
                    <element value="system"/>
                    <transform value="copy"/>
                    <parameter>
                      <valueString value="http://loinc.org"/>
                    </parameter>
                  </target>
                </rule>
                <rule>
                  <name value="cd"/>
                  <source>
                    <context value="it"/>
                  </source>
                  <target>
                    <context value="cg"/>
                    <element value="code"/>
                    <transform value="copy"/>
                    <parameter>
                      <valueString value="8306-3"/>
                    </parameter>
                  </target>
                </rule>
                <rule>
                  <name value="dsp"/>
                  <source>
                    <context value="it"/>
                  </source>
                  <target>
                    <context value="cg"/>
                    <element value="display"/>
                    <transform value="copy"/>
                    <parameter>
                      <valueString value="Body height --lying"/>
                    </parameter>
                  </target>
                </rule>
              </rule>
            </rule>
            <rule>
              <name value="value"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="comp"/>
              </target>
              <dependent>
                <name value="SetComponentValue"/>
                <parameter>
                  <valueId value="it"/>
                </parameter>
                <parameter>
                  <valueId value="comp"/>
                </parameter>
              </dependent>
            </rule>
          </rule>
          <rule>
            <name value="comp_9843_4"/>
            <source>
              <context value="g2"/>
              <element value="item"/>
              <variable value="it"/>
              <condition value="(linkId = 'labour-report/third-stage/baby-measurements/head-circumference') and answer.value.exists()"/>
            </source>
            <target>
              <context value="obs"/>
              <element value="component"/>
              <variable value="comp"/>
            </target>
            <rule>
              <name value="code"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="comp"/>
                <element value="code"/>
                <variable value="cc"/>
              </target>
              <rule>
                <name value="coding"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cc"/>
                  <element value="coding"/>
                  <variable value="cg"/>
                </target>
                <rule>
                  <name value="sys"/>
                  <source>
                    <context value="it"/>
                  </source>
                  <target>
                    <context value="cg"/>
                    <element value="system"/>
                    <transform value="copy"/>
                    <parameter>
                      <valueString value="http://loinc.org"/>
                    </parameter>
                  </target>
                </rule>
                <rule>
                  <name value="cd"/>
                  <source>
                    <context value="it"/>
                  </source>
                  <target>
                    <context value="cg"/>
                    <element value="code"/>
                    <transform value="copy"/>
                    <parameter>
                      <valueString value="9843-4"/>
                    </parameter>
                  </target>
                </rule>
                <rule>
                  <name value="dsp"/>
                  <source>
                    <context value="it"/>
                  </source>
                  <target>
                    <context value="cg"/>
                    <element value="display"/>
                    <transform value="copy"/>
                    <parameter>
                      <valueString value="Head Occipital-frontal circumference"/>
                    </parameter>
                  </target>
                </rule>
              </rule>
            </rule>
            <rule>
              <name value="value"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="comp"/>
              </target>
              <dependent>
                <name value="SetComponentValue"/>
                <parameter>
                  <valueId value="it"/>
                </parameter>
                <parameter>
                  <valueId value="comp"/>
                </parameter>
              </dependent>
            </rule>
          </rule>
          <documentation value="The baby's measurements. These belong to the *baby*, not the mother,&#xD;&#xA;and this response's subject is the mother -- so the map records them&#xD;&#xA;here with a note saying so rather than silently writing a birth weight&#xD;&#xA;onto the mother's chart under her own subject reference. The newborn's&#xD;&#xA;own record carries them properly, from the newborn observation chart."/>
        </rule>
        <documentation value="── The third-stage findings ──────────────────────────────────────────&#xD;&#xA;Blood loss on its own, because a postpartum haemorrhage audit filters on&#xD;&#xA;it and the figure has to be findable by its LOINC code."/>
      </rule>
      <rule>
        <name value="clinicianSectionObservation"/>
        <source>
          <context value="lg"/>
          <element value="item"/>
          <variable value="g"/>
          <condition value="(linkId = 'labour-report/clinician-section') and item.answer.value.exists()"/>
        </source>
        <target>
          <context value="bundle"/>
          <element value="entry"/>
          <variable value="entry"/>
        </target>
        <target>
          <context value="entry"/>
          <element value="resource"/>
          <variable value="obs"/>
          <transform value="create"/>
          <parameter>
            <valueString value="Observation"/>
          </parameter>
        </target>
        <rule>
          <name value="base"/>
          <source>
            <context value="qr"/>
          </source>
          <target>
            <context value="obs"/>
          </target>
          <target>
            <context value="entry"/>
          </target>
          <dependent>
            <name value="BuildObsBase"/>
            <parameter>
              <valueId value="qr"/>
            </parameter>
            <parameter>
              <valueId value="obs"/>
            </parameter>
            <parameter>
              <valueId value="entry"/>
            </parameter>
          </dependent>
        </rule>
        <rule>
          <name value="category"/>
          <source>
            <context value="qr"/>
          </source>
          <target>
            <context value="obs"/>
          </target>
          <dependent>
            <name value="SetSurveyCategory"/>
            <parameter>
              <valueId value="qr"/>
            </parameter>
            <parameter>
              <valueId value="obs"/>
            </parameter>
          </dependent>
        </rule>
        <rule>
          <name value="code"/>
          <source>
            <context value="g"/>
          </source>
          <target>
            <context value="obs"/>
            <element value="code"/>
            <variable value="cc"/>
          </target>
          <rule>
            <name value="coding"/>
            <source>
              <context value="g"/>
            </source>
            <target>
              <context value="cc"/>
              <element value="coding"/>
              <variable value="cg"/>
            </target>
            <rule>
              <name value="sys"/>
              <source>
                <context value="g"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="system"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="http://loinc.org"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="cd"/>
              <source>
                <context value="g"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="code"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="10164-2"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="dsp"/>
              <source>
                <context value="g"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="display"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="History of Present illness Narrative"/>
                </parameter>
              </target>
            </rule>
          </rule>
          <rule>
            <name value="codeText"/>
            <source>
              <context value="g"/>
            </source>
            <target>
              <context value="cc"/>
              <element value="text"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="Clinician section of the labour report"/>
              </parameter>
            </target>
          </rule>
        </rule>
        <rule>
          <name value="comp_obs_other_children_admitted_in_nbu"/>
          <source>
            <context value="g"/>
            <element value="item"/>
            <variable value="it"/>
            <condition value="(linkId = 'labour-report/clinician-section/other-children-in-nbu') and answer.value.exists()"/>
          </source>
          <target>
            <context value="obs"/>
            <element value="component"/>
            <variable value="comp"/>
          </target>
          <rule>
            <name value="code"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="comp"/>
              <element value="code"/>
              <variable value="cc"/>
            </target>
            <rule>
              <name value="coding"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cc"/>
                <element value="coding"/>
                <variable value="cg"/>
              </target>
              <rule>
                <name value="sys"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="system"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="cd"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="code"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="obs-other-children-admitted-in-nbu"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="dsp"/>
                <source>
                  <context value="it"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="display"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="Other children admitted in NBU"/>
                  </parameter>
                </target>
              </rule>
            </rule>
          </rule>
          <rule>
            <name value="value"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="comp"/>
            </target>
            <dependent>
              <name value="SetComponentCodedValue"/>
              <parameter>
                <valueId value="it"/>
              </parameter>
              <parameter>
                <valueId value="comp"/>
              </parameter>
            </dependent>
          </rule>
        </rule>
        <rule>
          <name value="note2"/>
          <source>
            <context value="g"/>
            <element value="item"/>
            <variable value="it"/>
            <condition value="linkId = 'labour-report/clinician-section/nbu-reason'"/>
          </source>
          <rule>
            <name value="answer"/>
            <source>
              <context value="it"/>
              <element value="answer"/>
              <listMode value="first"/>
              <variable value="a"/>
            </source>
            <rule>
              <name value="text"/>
              <source>
                <context value="a"/>
                <element value="value"/>
                <variable value="txt"/>
              </source>
              <target>
                <context value="obs"/>
                <element value="note"/>
                <variable value="n"/>
              </target>
              <target>
                <context value="n"/>
                <element value="text"/>
                <transform value="copy"/>
                <parameter>
                  <valueId value="txt"/>
                </parameter>
              </target>
            </rule>
          </rule>
        </rule>
        <rule>
          <name value="note3"/>
          <source>
            <context value="g"/>
            <element value="item"/>
            <variable value="it"/>
            <condition value="linkId = 'labour-report/clinician-section/exchange-transfusion'"/>
          </source>
          <rule>
            <name value="answer"/>
            <source>
              <context value="it"/>
              <element value="answer"/>
              <listMode value="first"/>
              <variable value="a"/>
            </source>
            <rule>
              <name value="text"/>
              <source>
                <context value="a"/>
                <element value="value"/>
                <variable value="txt"/>
              </source>
              <target>
                <context value="obs"/>
                <element value="note"/>
                <variable value="n"/>
              </target>
              <target>
                <context value="n"/>
                <element value="text"/>
                <transform value="copy"/>
                <parameter>
                  <valueId value="txt"/>
                </parameter>
              </target>
            </rule>
          </rule>
        </rule>
        <documentation value="── Notes from the clinician's section ────────────────────────────────"/>
      </rule>
      <documentation value="── The delivery, as a Procedure ────────────────────────────────────────&#xD;&#xA;Coded by its mode: SNOMED 11466000 for a caesarean, 177184002 for a normal&#xD;&#xA;delivery, both checked against tx.fhir.org. The two are separated on the&#xD;&#xA;code rather than folded into one &quot;delivery&quot; concept, because whether a&#xD;&#xA;woman has a uterine scar governs every pregnancy she has after this one.&#xD;&#xA;Guarded on the delivery date and time being recorded: that is what says a&#xD;&#xA;delivery happened, as against a maternity record filled in on admission&#xD;&#xA;for a woman still in labour."/>
    </rule>
    <rule>
      <name value="managementCarePlan"/>
      <source>
        <context value="qr"/>
        <element value="item"/>
        <variable value="g"/>
        <condition value="(linkId = 'management-plan') and item.where(linkId = 'management-plan/plan').answer.value.exists()"/>
      </source>
      <target>
        <context value="bundle"/>
        <element value="entry"/>
        <variable value="entry"/>
      </target>
      <target>
        <context value="entry"/>
        <element value="resource"/>
        <variable value="plan"/>
        <transform value="create"/>
        <parameter>
          <valueString value="CarePlan"/>
        </parameter>
      </target>
      <rule>
        <name value="base"/>
        <source>
          <context value="qr"/>
        </source>
        <target>
          <context value="plan"/>
        </target>
        <target>
          <context value="entry"/>
        </target>
        <dependent>
          <name value="BuildCarePlanBase"/>
          <parameter>
            <valueId value="qr"/>
          </parameter>
          <parameter>
            <valueId value="plan"/>
          </parameter>
          <parameter>
            <valueId value="entry"/>
          </parameter>
        </dependent>
      </rule>
      <rule>
        <name value="status"/>
        <source>
          <context value="g"/>
        </source>
        <target>
          <context value="plan"/>
          <element value="status"/>
          <transform value="copy"/>
          <parameter>
            <valueString value="active"/>
          </parameter>
        </target>
      </rule>
      <rule>
        <name value="intent"/>
        <source>
          <context value="g"/>
        </source>
        <target>
          <context value="plan"/>
          <element value="intent"/>
          <transform value="copy"/>
          <parameter>
            <valueString value="plan"/>
          </parameter>
        </target>
      </rule>
      <rule>
        <name value="title"/>
        <source>
          <context value="g"/>
        </source>
        <target>
          <context value="plan"/>
          <element value="title"/>
          <transform value="copy"/>
          <parameter>
            <valueString value="Maternity management plan"/>
          </parameter>
        </target>
      </rule>
      <rule>
        <name value="created"/>
        <source>
          <context value="qr"/>
          <element value="authored"/>
          <variable value="t"/>
        </source>
        <target>
          <context value="plan"/>
          <element value="created"/>
          <transform value="copy"/>
          <parameter>
            <valueId value="t"/>
          </parameter>
        </target>
      </rule>
      <rule>
        <name value="encounter"/>
        <source>
          <context value="qr"/>
          <element value="encounter"/>
          <variable value="e"/>
        </source>
        <target>
          <context value="plan"/>
          <element value="encounter"/>
          <transform value="copy"/>
          <parameter>
            <valueId value="e"/>
          </parameter>
        </target>
      </rule>
      <rule>
        <name value="category"/>
        <source>
          <context value="g"/>
        </source>
        <target>
          <context value="plan"/>
          <element value="category"/>
          <variable value="cat"/>
        </target>
        <rule>
          <name value="coding"/>
          <source>
            <context value="g"/>
          </source>
          <target>
            <context value="cat"/>
            <element value="coding"/>
            <variable value="cg"/>
          </target>
          <rule>
            <name value="sys"/>
            <source>
              <context value="g"/>
            </source>
            <target>
              <context value="cg"/>
              <element value="system"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="https://fhir.slade360.co.ke/fhir/CodeSystem/document-type-codesystem"/>
              </parameter>
            </target>
          </rule>
          <rule>
            <name value="cd"/>
            <source>
              <context value="g"/>
            </source>
            <target>
              <context value="cg"/>
              <element value="code"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="maternity-record"/>
              </parameter>
            </target>
          </rule>
          <rule>
            <name value="dsp"/>
            <source>
              <context value="g"/>
            </source>
            <target>
              <context value="cg"/>
              <element value="display"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="Maternity record"/>
              </parameter>
            </target>
          </rule>
        </rule>
      </rule>
      <rule>
        <name value="planRule"/>
        <source>
          <context value="g"/>
          <element value="item"/>
          <variable value="it"/>
          <condition value="linkId = 'management-plan/plan'"/>
        </source>
        <rule>
          <name value="answer"/>
          <source>
            <context value="it"/>
            <element value="answer"/>
            <listMode value="first"/>
            <variable value="a"/>
          </source>
          <rule>
            <name value="description"/>
            <source>
              <context value="a"/>
              <element value="value"/>
              <variable value="txt"/>
            </source>
            <target>
              <context value="plan"/>
              <element value="description"/>
              <transform value="copy"/>
              <parameter>
                <valueId value="txt"/>
              </parameter>
            </target>
          </rule>
        </rule>
      </rule>
      <rule>
        <name value="signedByRule"/>
        <source>
          <context value="g"/>
          <element value="item"/>
          <variable value="it"/>
          <condition value="(linkId = 'management-plan/signed-by') and answer.value.exists()"/>
        </source>
        <rule>
          <name value="answer"/>
          <source>
            <context value="it"/>
            <element value="answer"/>
            <listMode value="first"/>
            <variable value="a"/>
          </source>
          <rule>
            <name value="custodian"/>
            <source>
              <context value="a"/>
              <element value="value"/>
              <variable value="ref"/>
            </source>
            <target>
              <context value="plan"/>
              <element value="custodian"/>
              <transform value="copy"/>
              <parameter>
                <valueId value="ref"/>
              </parameter>
            </target>
          </rule>
        </rule>
      </rule>
      <rule>
        <name value="deliverySummaryRule"/>
        <source>
          <context value="g"/>
          <element value="item"/>
          <variable value="it"/>
          <condition value="(linkId = 'management-plan/delivery-summary') and answer.value.exists()"/>
        </source>
        <rule>
          <name value="answer"/>
          <source>
            <context value="it"/>
            <element value="answer"/>
            <listMode value="first"/>
            <variable value="a"/>
          </source>
          <rule>
            <name value="deliverySummaryNote"/>
            <source>
              <context value="a"/>
              <element value="value"/>
              <variable value="txt"/>
            </source>
            <target>
              <context value="plan"/>
              <element value="note"/>
              <variable value="n"/>
            </target>
            <target>
              <context value="n"/>
              <element value="text"/>
              <transform value="copy"/>
              <parameter>
                <valueId value="txt"/>
              </parameter>
            </target>
          </rule>
        </rule>
      </rule>
      <documentation value="── The management plan ─────────────────────────────────────────────────"/>
    </rule>
    <rule>
      <name value="dietObservation"/>
      <source>
        <context value="qr"/>
        <element value="item"/>
        <variable value="g"/>
        <condition value="(linkId = 'diet-and-nutrition') and item.answer.value.exists()"/>
      </source>
      <target>
        <context value="bundle"/>
        <element value="entry"/>
        <variable value="entry"/>
      </target>
      <target>
        <context value="entry"/>
        <element value="resource"/>
        <variable value="obs"/>
        <transform value="create"/>
        <parameter>
          <valueString value="Observation"/>
        </parameter>
      </target>
      <rule>
        <name value="base"/>
        <source>
          <context value="qr"/>
        </source>
        <target>
          <context value="obs"/>
        </target>
        <target>
          <context value="entry"/>
        </target>
        <dependent>
          <name value="BuildObsBase"/>
          <parameter>
            <valueId value="qr"/>
          </parameter>
          <parameter>
            <valueId value="obs"/>
          </parameter>
          <parameter>
            <valueId value="entry"/>
          </parameter>
        </dependent>
      </rule>
      <rule>
        <name value="category"/>
        <source>
          <context value="qr"/>
        </source>
        <target>
          <context value="obs"/>
        </target>
        <dependent>
          <name value="SetSurveyCategory"/>
          <parameter>
            <valueId value="qr"/>
          </parameter>
          <parameter>
            <valueId value="obs"/>
          </parameter>
        </dependent>
      </rule>
      <rule>
        <name value="code"/>
        <source>
          <context value="g"/>
        </source>
        <target>
          <context value="obs"/>
          <element value="code"/>
          <variable value="cc"/>
        </target>
        <rule>
          <name value="coding"/>
          <source>
            <context value="g"/>
          </source>
          <target>
            <context value="cc"/>
            <element value="coding"/>
            <variable value="cg"/>
          </target>
          <rule>
            <name value="sys"/>
            <source>
              <context value="g"/>
            </source>
            <target>
              <context value="cg"/>
              <element value="system"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="https://fhir.slade360.co.ke/fhir/CodeSystem/inpatient-clinical-concept-codesystem"/>
              </parameter>
            </target>
          </rule>
          <rule>
            <name value="cd"/>
            <source>
              <context value="g"/>
            </source>
            <target>
              <context value="cg"/>
              <element value="code"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="feeding"/>
              </parameter>
            </target>
          </rule>
          <rule>
            <name value="dsp"/>
            <source>
              <context value="g"/>
            </source>
            <target>
              <context value="cg"/>
              <element value="display"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="Feeding"/>
              </parameter>
            </target>
          </rule>
        </rule>
        <rule>
          <name value="codeText"/>
          <source>
            <context value="g"/>
          </source>
          <target>
            <context value="cc"/>
            <element value="text"/>
            <transform value="copy"/>
            <parameter>
              <valueString value="Diet and nutrition assessment"/>
            </parameter>
          </target>
        </rule>
      </rule>
      <rule>
        <name value="comp_obs_vegetarian"/>
        <source>
          <context value="g"/>
          <element value="item"/>
          <variable value="it"/>
          <condition value="(linkId = 'diet-and-nutrition/vegetarian') and answer.value.exists()"/>
        </source>
        <target>
          <context value="obs"/>
          <element value="component"/>
          <variable value="comp"/>
        </target>
        <rule>
          <name value="code"/>
          <source>
            <context value="it"/>
          </source>
          <target>
            <context value="comp"/>
            <element value="code"/>
            <variable value="cc"/>
          </target>
          <rule>
            <name value="coding"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="cc"/>
              <element value="coding"/>
              <variable value="cg"/>
            </target>
            <rule>
              <name value="sys"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="system"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="cd"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="code"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="obs-vegetarian"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="dsp"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="display"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="Vegetarian"/>
                </parameter>
              </target>
            </rule>
          </rule>
        </rule>
        <rule>
          <name value="value"/>
          <source>
            <context value="it"/>
          </source>
          <target>
            <context value="comp"/>
          </target>
          <dependent>
            <name value="SetComponentCodedValue"/>
            <parameter>
              <valueId value="it"/>
            </parameter>
            <parameter>
              <valueId value="comp"/>
            </parameter>
          </dependent>
        </rule>
      </rule>
      <rule>
        <name value="comp_obs_other_diet_issue"/>
        <source>
          <context value="g"/>
          <element value="item"/>
          <variable value="it"/>
          <condition value="(linkId = 'diet-and-nutrition/other-diet-issue') and answer.value.exists()"/>
        </source>
        <target>
          <context value="obs"/>
          <element value="component"/>
          <variable value="comp"/>
        </target>
        <rule>
          <name value="code"/>
          <source>
            <context value="it"/>
          </source>
          <target>
            <context value="comp"/>
            <element value="code"/>
            <variable value="cc"/>
          </target>
          <rule>
            <name value="coding"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="cc"/>
              <element value="coding"/>
              <variable value="cg"/>
            </target>
            <rule>
              <name value="sys"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="system"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="cd"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="code"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="obs-other-diet-issue"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="dsp"/>
              <source>
                <context value="it"/>
              </source>
              <target>
                <context value="cg"/>
                <element value="display"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="Other diet issue"/>
                </parameter>
              </target>
            </rule>
          </rule>
        </rule>
        <rule>
          <name value="value"/>
          <source>
            <context value="it"/>
          </source>
          <target>
            <context value="comp"/>
          </target>
          <dependent>
            <name value="SetComponentValue"/>
            <parameter>
              <valueId value="it"/>
            </parameter>
            <parameter>
              <valueId value="comp"/>
            </parameter>
          </dependent>
        </rule>
      </rule>
      <documentation value="── Diet and nutrition ──────────────────────────────────────────────────"/>
    </rule>
    <rule>
      <name value="dischargeGroup"/>
      <source>
        <context value="qr"/>
        <element value="item"/>
        <variable value="g"/>
        <condition value="linkId = 'discharge'"/>
      </source>
      <rule>
        <name value="dischargeDiagnoses"/>
        <source>
          <context value="g"/>
          <element value="item"/>
          <variable value="it"/>
          <condition value="linkId = 'discharge/diagnosis'"/>
        </source>
        <rule>
          <name value="createDischargeCondition"/>
          <source>
            <context value="it"/>
            <element value="answer"/>
            <variable value="a"/>
          </source>
          <target>
            <context value="bundle"/>
            <element value="entry"/>
            <variable value="entry"/>
          </target>
          <target>
            <context value="entry"/>
            <element value="resource"/>
            <variable value="cond"/>
            <transform value="create"/>
            <parameter>
              <valueString value="Condition"/>
            </parameter>
          </target>
          <rule>
            <name value="base"/>
            <source>
              <context value="qr"/>
            </source>
            <target>
              <context value="cond"/>
            </target>
            <target>
              <context value="entry"/>
            </target>
            <dependent>
              <name value="BuildConditionBase"/>
              <parameter>
                <valueId value="qr"/>
              </parameter>
              <parameter>
                <valueId value="cond"/>
              </parameter>
              <parameter>
                <valueId value="entry"/>
              </parameter>
            </dependent>
          </rule>
          <rule>
            <name value="clinicalStatus"/>
            <source>
              <context value="a"/>
            </source>
            <target>
              <context value="cond"/>
              <element value="clinicalStatus"/>
              <variable value="cs"/>
            </target>
            <rule>
              <name value="coding"/>
              <source>
                <context value="a"/>
              </source>
              <target>
                <context value="cs"/>
                <element value="coding"/>
                <variable value="cg"/>
              </target>
              <rule>
                <name value="sys"/>
                <source>
                  <context value="a"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="system"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="http://terminology.hl7.org/CodeSystem/condition-clinical"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="cd"/>
                <source>
                  <context value="a"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="code"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="resolved"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="dsp"/>
                <source>
                  <context value="a"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="display"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="Resolved"/>
                  </parameter>
                </target>
              </rule>
            </rule>
          </rule>
          <rule>
            <name value="verificationStatus"/>
            <source>
              <context value="a"/>
            </source>
            <target>
              <context value="cond"/>
              <element value="verificationStatus"/>
              <variable value="vs"/>
            </target>
            <rule>
              <name value="coding"/>
              <source>
                <context value="a"/>
              </source>
              <target>
                <context value="vs"/>
                <element value="coding"/>
                <variable value="cg"/>
              </target>
              <rule>
                <name value="sys"/>
                <source>
                  <context value="a"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="system"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="http://terminology.hl7.org/CodeSystem/condition-ver-status"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="cd"/>
                <source>
                  <context value="a"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="code"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="confirmed"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="dsp"/>
                <source>
                  <context value="a"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="display"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="Confirmed"/>
                  </parameter>
                </target>
              </rule>
            </rule>
          </rule>
          <rule>
            <name value="category"/>
            <source>
              <context value="a"/>
            </source>
            <target>
              <context value="cond"/>
              <element value="category"/>
              <variable value="cat"/>
            </target>
            <rule>
              <name value="coding"/>
              <source>
                <context value="a"/>
              </source>
              <target>
                <context value="cat"/>
                <element value="coding"/>
                <variable value="cg"/>
              </target>
              <rule>
                <name value="sys"/>
                <source>
                  <context value="a"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="system"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="http://terminology.hl7.org/CodeSystem/condition-category"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="cd"/>
                <source>
                  <context value="a"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="code"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="encounter-diagnosis"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="dsp"/>
                <source>
                  <context value="a"/>
                </source>
                <target>
                  <context value="cg"/>
                  <element value="display"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="Encounter Diagnosis"/>
                  </parameter>
                </target>
              </rule>
            </rule>
          </rule>
          <rule>
            <name value="codeText"/>
            <source>
              <context value="a"/>
              <element value="value"/>
              <variable value="txt"/>
            </source>
            <target>
              <context value="cond"/>
              <element value="code"/>
              <variable value="cc"/>
            </target>
            <target>
              <context value="cc"/>
              <element value="text"/>
              <transform value="copy"/>
              <parameter>
                <valueId value="txt"/>
              </parameter>
            </target>
          </rule>
          <rule>
            <name value="recordedDate"/>
            <source>
              <context value="qr"/>
              <element value="authored"/>
              <variable value="t"/>
            </source>
            <target>
              <context value="cond"/>
              <element value="recordedDate"/>
              <transform value="copy"/>
              <parameter>
                <valueId value="t"/>
              </parameter>
            </target>
          </rule>
          <rule>
            <name value="encounter"/>
            <source>
              <context value="qr"/>
              <element value="encounter"/>
              <variable value="e"/>
            </source>
            <target>
              <context value="cond"/>
              <element value="encounter"/>
              <transform value="copy"/>
              <parameter>
                <valueId value="e"/>
              </parameter>
            </target>
          </rule>
          <rule>
            <name value="dischargeNote"/>
            <source>
              <context value="a"/>
            </source>
            <target>
              <context value="cond"/>
              <element value="note"/>
              <variable value="n"/>
            </target>
            <target>
              <context value="n"/>
              <element value="text"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="Diagnosis on discharge from the maternity ward."/>
              </parameter>
            </target>
          </rule>
        </rule>
      </rule>
      <documentation value="── Discharge ───────────────────────────────────────────────────────────"/>
    </rule>
    <rule>
      <name value="createConsent"/>
      <source>
        <context value="qr"/>
        <element value="item"/>
        <variable value="it"/>
        <condition value="(linkId = 'consent-for-admission') and (answer.value = true)"/>
      </source>
      <target>
        <context value="bundle"/>
        <element value="entry"/>
        <variable value="entry"/>
      </target>
      <target>
        <context value="entry"/>
        <element value="resource"/>
        <variable value="consent"/>
        <transform value="create"/>
        <parameter>
          <valueString value="Consent"/>
        </parameter>
      </target>
      <rule>
        <name value="base"/>
        <source>
          <context value="qr"/>
        </source>
        <target>
          <context value="consent"/>
        </target>
        <target>
          <context value="entry"/>
        </target>
        <dependent>
          <name value="BuildConsentBase"/>
          <parameter>
            <valueId value="qr"/>
          </parameter>
          <parameter>
            <valueId value="consent"/>
          </parameter>
          <parameter>
            <valueId value="entry"/>
          </parameter>
        </dependent>
      </rule>
      <rule>
        <name value="status"/>
        <source>
          <context value="it"/>
        </source>
        <target>
          <context value="consent"/>
          <element value="status"/>
          <transform value="copy"/>
          <parameter>
            <valueString value="active"/>
          </parameter>
        </target>
      </rule>
      <rule>
        <name value="category"/>
        <source>
          <context value="it"/>
        </source>
        <target>
          <context value="consent"/>
          <element value="category"/>
          <variable value="cat"/>
        </target>
        <rule>
          <name value="coding"/>
          <source>
            <context value="it"/>
          </source>
          <target>
            <context value="cat"/>
            <element value="coding"/>
            <variable value="cg"/>
          </target>
          <rule>
            <name value="sys"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="cg"/>
              <element value="system"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="http://terminology.hl7.org/CodeSystem/consentcategorycodes"/>
              </parameter>
            </target>
          </rule>
          <rule>
            <name value="cd"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="cg"/>
              <element value="code"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="acd"/>
              </parameter>
            </target>
          </rule>
          <rule>
            <name value="dsp"/>
            <source>
              <context value="it"/>
            </source>
            <target>
              <context value="cg"/>
              <element value="display"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="Advance Directive"/>
              </parameter>
            </target>
          </rule>
        </rule>
        <rule>
          <name value="categoryText"/>
          <source>
            <context value="it"/>
          </source>
          <target>
            <context value="cat"/>
            <element value="text"/>
            <transform value="copy"/>
            <parameter>
              <valueString value="Consent for admission and relevant management"/>
            </parameter>
          </target>
        </rule>
      </rule>
      <rule>
        <name value="decision"/>
        <source>
          <context value="it"/>
        </source>
        <target>
          <context value="consent"/>
          <element value="decision"/>
          <transform value="copy"/>
          <parameter>
            <valueString value="permit"/>
          </parameter>
        </target>
      </rule>
      <rule>
        <name value="consentPeriodStart"/>
        <source>
          <context value="qr"/>
          <element value="authored"/>
          <variable value="t"/>
        </source>
        <target>
          <context value="consent"/>
          <element value="period"/>
          <variable value="per"/>
        </target>
        <target>
          <context value="per"/>
          <element value="start"/>
          <transform value="copy"/>
          <parameter>
            <valueId value="t"/>
          </parameter>
        </target>
      </rule>
      <rule>
        <name value="grantee"/>
        <source>
          <context value="qr"/>
          <element value="source"/>
          <variable value="src"/>
        </source>
        <target>
          <context value="consent"/>
          <element value="grantee"/>
          <transform value="copy"/>
          <parameter>
            <valueId value="src"/>
          </parameter>
        </target>
      </rule>
      <rule>
        <name value="provenanceNote"/>
        <source>
          <context value="it"/>
        </source>
        <target>
          <context value="consent"/>
          <element value="provision"/>
          <variable value="prov"/>
        </target>
        <target>
          <context value="prov"/>
          <element value="code"/>
          <variable value="pc"/>
        </target>
        <target>
          <context value="pc"/>
          <element value="text"/>
          <transform value="copy"/>
          <parameter>
            <valueString value="Taken on the maternity record. The woman signed the sheet; this records that the signature was obtained, not the signature itself."/>
          </parameter>
        </target>
      </rule>
      <documentation value="── Consent for admission ───────────────────────────────────────────────"/>
    </rule>
  </group>
  <group>
    <name value="BuildObsBase"/>
    <documentation value="─────────────────────────────────────────────────────────────────────────────&#xD;&#xA;Shared scaffolding. Repeated in each map rather than imported: the transform&#xD;&#xA;engine resolves `imports` against whatever StructureMaps happen to be on the&#xD;&#xA;server, and a form that stops extracting because a shared map was not&#xD;&#xA;uploaded is a worse failure than a duplicated group.&#xD;&#xA;Two notes on what the publisher's StructureMap validator says about this file.&#xD;&#xA;Source parameters below are left untyped on purpose. Writing `: Element` makes&#xD;&#xA;the validator compare QuestionnaireResponse.item against the literal 'Element'&#xD;&#xA;and report them as incompatible with each other, which is noise, not a finding.&#xD;&#xA;`evaluate(context, expression)` is flagged as &quot;takes 1 parameter but 2 were&#xD;&#xA;found&quot;. Leave it. The FML parser in the same jar refuses the one-argument form&#xD;&#xA;outright -- it wants a parameter, a comma, then the FHIRPath -- so the&#xD;&#xA;publisher is objecting to what its own compiler emits. Two arguments is the&#xD;&#xA;only form that compiles, and it is what the R5 transform engine executes.&#xD;&#xA;─────────────────────────────────────────────────────────────────────────────"/>
    <input>
      <name value="qr"/>
      <type value="QR"/>
      <mode value="source"/>
    </input>
    <input>
      <name value="obs"/>
      <type value="Observation"/>
      <mode value="target"/>
    </input>
    <input>
      <name value="entry"/>
      <mode value="target"/>
    </input>
    <rule>
      <name value="responseProvenance"/>
      <source>
        <context value="qr"/>
      </source>
      <target>
        <context value="obs"/>
      </target>
      <dependent>
        <name value="SetResponseProvenance"/>
        <parameter>
          <valueId value="qr"/>
        </parameter>
        <parameter>
          <valueId value="obs"/>
        </parameter>
      </dependent>
    </rule>
    <rule>
      <name value="idAndFullUrl"/>
      <source>
        <context value="qr"/>
      </source>
      <target>
        <context value="obs"/>
        <element value="id"/>
        <transform value="uuid"/>
      </target>
      <dependent>
        <name value="SetObservationFullUrl"/>
        <parameter>
          <valueId value="obs"/>
        </parameter>
        <parameter>
          <valueId value="entry"/>
        </parameter>
      </dependent>
    </rule>
    <rule>
      <name value="entryRequest"/>
      <source>
        <context value="qr"/>
      </source>
      <target>
        <context value="entry"/>
        <element value="request"/>
        <variable value="request"/>
      </target>
      <rule>
        <name value="requestMethod"/>
        <source>
          <context value="qr"/>
        </source>
        <target>
          <context value="request"/>
          <element value="method"/>
          <transform value="copy"/>
          <parameter>
            <valueString value="POST"/>
          </parameter>
        </target>
      </rule>
      <rule>
        <name value="requestUrl"/>
        <source>
          <context value="qr"/>
        </source>
        <target>
          <context value="request"/>
          <element value="url"/>
          <transform value="copy"/>
          <parameter>
            <valueString value="Observation"/>
          </parameter>
        </target>
      </rule>
    </rule>
    <rule>
      <name value="status"/>
      <source>
        <context value="qr"/>
      </source>
      <target>
        <context value="obs"/>
        <element value="status"/>
        <transform value="copy"/>
        <parameter>
          <valueString value="final"/>
        </parameter>
      </target>
    </rule>
    <rule>
      <name value="subject"/>
      <source>
        <context value="qr"/>
        <element value="subject"/>
        <variable value="s"/>
      </source>
      <target>
        <context value="obs"/>
        <element value="subject"/>
        <transform value="copy"/>
        <parameter>
          <valueId value="s"/>
        </parameter>
      </target>
    </rule>
    <rule>
      <name value="encounter"/>
      <source>
        <context value="qr"/>
        <element value="encounter"/>
        <variable value="e"/>
      </source>
      <target>
        <context value="obs"/>
        <element value="encounter"/>
        <transform value="copy"/>
        <parameter>
          <valueId value="e"/>
        </parameter>
      </target>
    </rule>
    <rule>
      <name value="effective"/>
      <source>
        <context value="qr"/>
        <element value="authored"/>
        <variable value="t"/>
      </source>
      <target>
        <context value="obs"/>
        <element value="effective"/>
        <transform value="copy"/>
        <parameter>
          <valueId value="t"/>
        </parameter>
      </target>
    </rule>
    <rule>
      <name value="performerFromSource"/>
      <source>
        <context value="qr"/>
        <element value="source"/>
        <variable value="src"/>
      </source>
      <target>
        <context value="obs"/>
        <element value="performer"/>
        <transform value="copy"/>
        <parameter>
          <valueId value="src"/>
        </parameter>
      </target>
    </rule>
    <rule>
      <name value="performerFallback"/>
      <source>
        <context value="qr"/>
        <condition value="source.exists().not()"/>
      </source>
      <rule>
        <name value="performerFromAuthor"/>
        <source>
          <context value="qr"/>
          <element value="author"/>
          <variable value="a"/>
        </source>
        <target>
          <context value="obs"/>
          <element value="performer"/>
          <transform value="copy"/>
          <parameter>
            <valueId value="a"/>
          </parameter>
        </target>
      </rule>
    </rule>
    <rule>
      <name value="linkQuestionnaireResponse"/>
      <source>
        <context value="qr"/>
        <element value="id"/>
        <variable value="qid"/>
        <condition value="$this.hasValue()"/>
      </source>
      <target>
        <context value="obs"/>
        <element value="derivedFrom"/>
        <variable value="ref"/>
        <transform value="create"/>
        <parameter>
          <valueString value="Reference"/>
        </parameter>
      </target>
      <target>
        <context value="ref"/>
        <element value="reference"/>
        <transform value="copy"/>
        <parameter>
          <valueId value="qid"/>
        </parameter>
      </target>
      <documentation value="A stored response's id already reads &quot;QuestionnaireResponse/&lt;id&gt;&quot;, so it is&#xD;&#xA;a relative reference as it stands. The hasValue() guard is what stops an&#xD;&#xA;unsaved response -- one posted straight to $extract rather than saved first&#xD;&#xA;-- from writing &quot;QuestionnaireResponse/null&quot; into the record."/>
    </rule>
  </group>
  <group>
    <name value="SetObservationFullUrl"/>
    <input>
      <name value="obs"/>
      <type value="Observation"/>
      <mode value="source"/>
    </input>
    <input>
      <name value="entry"/>
      <mode value="target"/>
    </input>
    <rule>
      <name value="assignFullUrl"/>
      <source>
        <context value="obs"/>
        <element value="id"/>
        <variable value="id"/>
      </source>
      <target>
        <context value="entry"/>
        <element value="fullUrl"/>
        <transform value="append"/>
        <parameter>
          <valueString value="https://fhir.slade360.co.ke/fhir/Observation/"/>
        </parameter>
        <parameter>
          <valueId value="id"/>
        </parameter>
      </target>
    </rule>
  </group>
  <group>
    <name value="SetComponentCodedValue"/>
    <documentation value="The two answer shapes a component can carry. Both read the answer through the&#xD;&#xA;untyped `.value` accessor: reading `valueCoding` or `valueQuantity` by its&#xD;&#xA;typed property name fails at transform time on HAPI R5 with &quot;Attempt to read&#xD;&#xA;invalid property ... on QuestionnaireResponse.item.answer&quot;."/>
    <input>
      <name value="it"/>
      <mode value="source"/>
    </input>
    <input>
      <name value="comp"/>
      <mode value="target"/>
    </input>
    <rule>
      <name value="componentAnswer"/>
      <source>
        <context value="it"/>
        <element value="answer"/>
        <listMode value="first"/>
        <variable value="a"/>
      </source>
      <rule>
        <name value="codedValue"/>
        <source>
          <context value="a"/>
          <element value="value"/>
          <variable value="cv"/>
        </source>
        <target>
          <context value="comp"/>
          <element value="value"/>
          <variable value="cc"/>
          <transform value="create"/>
          <parameter>
            <valueString value="CodeableConcept"/>
          </parameter>
        </target>
        <rule>
          <name value="valueCoding"/>
          <source>
            <context value="cv"/>
          </source>
          <target>
            <context value="cc"/>
            <element value="coding"/>
            <transform value="copy"/>
            <parameter>
              <valueId value="cv"/>
            </parameter>
          </target>
        </rule>
        <rule>
          <name value="valueText"/>
          <source>
            <context value="cv"/>
            <element value="display"/>
            <variable value="d"/>
          </source>
          <target>
            <context value="cc"/>
            <element value="text"/>
            <transform value="copy"/>
            <parameter>
              <valueId value="d"/>
            </parameter>
          </target>
        </rule>
      </rule>
    </rule>
  </group>
  <group>
    <name value="SetComponentValue"/>
    <input>
      <name value="it"/>
      <mode value="source"/>
    </input>
    <input>
      <name value="comp"/>
      <mode value="target"/>
    </input>
    <rule>
      <name value="componentAnswer"/>
      <source>
        <context value="it"/>
        <element value="answer"/>
        <listMode value="first"/>
        <variable value="a"/>
      </source>
      <rule>
        <name value="plainValue"/>
        <source>
          <context value="a"/>
          <element value="value"/>
          <variable value="v"/>
        </source>
        <target>
          <context value="comp"/>
          <element value="value"/>
          <transform value="copy"/>
          <parameter>
            <valueId value="v"/>
          </parameter>
        </target>
      </rule>
    </rule>
  </group>
  <group>
    <name value="SetSurveyCategory"/>
    <input>
      <name value="qr"/>
      <type value="QR"/>
      <mode value="source"/>
    </input>
    <input>
      <name value="obs"/>
      <type value="Observation"/>
      <mode value="target"/>
    </input>
    <rule>
      <name value="category"/>
      <source>
        <context value="qr"/>
      </source>
      <target>
        <context value="obs"/>
        <element value="category"/>
        <variable value="cat"/>
      </target>
      <rule>
        <name value="categoryCoding"/>
        <source>
          <context value="qr"/>
        </source>
        <target>
          <context value="cat"/>
          <element value="coding"/>
          <variable value="coding"/>
        </target>
        <rule>
          <name value="categorySystem"/>
          <source>
            <context value="qr"/>
          </source>
          <target>
            <context value="coding"/>
            <element value="system"/>
            <transform value="copy"/>
            <parameter>
              <valueString value="http://terminology.hl7.org/CodeSystem/observation-category"/>
            </parameter>
          </target>
        </rule>
        <rule>
          <name value="categoryCode"/>
          <source>
            <context value="qr"/>
          </source>
          <target>
            <context value="coding"/>
            <element value="code"/>
            <transform value="copy"/>
            <parameter>
              <valueString value="survey"/>
            </parameter>
          </target>
        </rule>
        <rule>
          <name value="categoryDisplay"/>
          <source>
            <context value="qr"/>
          </source>
          <target>
            <context value="coding"/>
            <element value="display"/>
            <transform value="copy"/>
            <parameter>
              <valueString value="Survey"/>
            </parameter>
          </target>
        </rule>
      </rule>
    </rule>
  </group>
  <group>
    <name value="SetVitalSignsCategory"/>
    <input>
      <name value="qr"/>
      <type value="QR"/>
      <mode value="source"/>
    </input>
    <input>
      <name value="obs"/>
      <type value="Observation"/>
      <mode value="target"/>
    </input>
    <rule>
      <name value="category"/>
      <source>
        <context value="qr"/>
      </source>
      <target>
        <context value="obs"/>
        <element value="category"/>
        <variable value="cat"/>
      </target>
      <rule>
        <name value="categoryCoding"/>
        <source>
          <context value="qr"/>
        </source>
        <target>
          <context value="cat"/>
          <element value="coding"/>
          <variable value="coding"/>
        </target>
        <rule>
          <name value="categorySystem"/>
          <source>
            <context value="qr"/>
          </source>
          <target>
            <context value="coding"/>
            <element value="system"/>
            <transform value="copy"/>
            <parameter>
              <valueString value="http://terminology.hl7.org/CodeSystem/observation-category"/>
            </parameter>
          </target>
        </rule>
        <rule>
          <name value="categoryCode"/>
          <source>
            <context value="qr"/>
          </source>
          <target>
            <context value="coding"/>
            <element value="code"/>
            <transform value="copy"/>
            <parameter>
              <valueString value="vital-signs"/>
            </parameter>
          </target>
        </rule>
        <rule>
          <name value="categoryDisplay"/>
          <source>
            <context value="qr"/>
          </source>
          <target>
            <context value="coding"/>
            <element value="display"/>
            <transform value="copy"/>
            <parameter>
              <valueString value="Vital Signs"/>
            </parameter>
          </target>
        </rule>
      </rule>
    </rule>
  </group>
  <group>
    <name value="SetExamCategory"/>
    <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="exam"/>
            </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="Exam"/>
            </parameter>
          </target>
        </rule>
      </rule>
    </rule>
  </group>
  <group>
    <name value="SetLaboratoryCategory"/>
    <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="laboratory"/>
            </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="Laboratory"/>
            </parameter>
          </target>
        </rule>
      </rule>
    </rule>
  </group>
  <group>
    <name value="SetProcedureCategory"/>
    <input>
      <name value="qr"/>
      <type value="QR"/>
      <mode value="source"/>
    </input>
    <input>
      <name value="obs"/>
      <type value="Observation"/>
      <mode value="target"/>
    </input>
    <rule>
      <name value="category"/>
      <source>
        <context value="qr"/>
      </source>
      <target>
        <context value="obs"/>
        <element value="category"/>
        <variable value="cat"/>
      </target>
      <rule>
        <name value="categoryCoding"/>
        <source>
          <context value="qr"/>
        </source>
        <target>
          <context value="cat"/>
          <element value="coding"/>
          <variable value="coding"/>
        </target>
        <rule>
          <name value="categorySystem"/>
          <source>
            <context value="qr"/>
          </source>
          <target>
            <context value="coding"/>
            <element value="system"/>
            <transform value="copy"/>
            <parameter>
              <valueString value="http://terminology.hl7.org/CodeSystem/observation-category"/>
            </parameter>
          </target>
        </rule>
        <rule>
          <name value="categoryCode"/>
          <source>
            <context value="qr"/>
          </source>
          <target>
            <context value="coding"/>
            <element value="code"/>
            <transform value="copy"/>
            <parameter>
              <valueString value="procedure"/>
            </parameter>
          </target>
        </rule>
        <rule>
          <name value="categoryDisplay"/>
          <source>
            <context value="qr"/>
          </source>
          <target>
            <context value="coding"/>
            <element value="display"/>
            <transform value="copy"/>
            <parameter>
              <valueString value="Procedure"/>
            </parameter>
          </target>
        </rule>
      </rule>
    </rule>
  </group>
  <group>
    <name value="BuildConditionBase"/>
    <input>
      <name value="qr"/>
      <type value="QR"/>
      <mode value="source"/>
    </input>
    <input>
      <name value="r"/>
      <type value="Condition"/>
      <mode value="target"/>
    </input>
    <input>
      <name value="entry"/>
      <mode value="target"/>
    </input>
    <rule>
      <name value="responseProvenance"/>
      <source>
        <context value="qr"/>
      </source>
      <target>
        <context value="r"/>
      </target>
      <dependent>
        <name value="SetResponseProvenance"/>
        <parameter>
          <valueId value="qr"/>
        </parameter>
        <parameter>
          <valueId value="r"/>
        </parameter>
      </dependent>
    </rule>
    <rule>
      <name value="idAndFullUrl"/>
      <source>
        <context value="qr"/>
      </source>
      <target>
        <context value="r"/>
        <element value="id"/>
        <transform value="uuid"/>
      </target>
      <dependent>
        <name value="SetConditionFullUrl"/>
        <parameter>
          <valueId value="r"/>
        </parameter>
        <parameter>
          <valueId value="entry"/>
        </parameter>
      </dependent>
    </rule>
    <rule>
      <name value="entryRequest"/>
      <source>
        <context value="qr"/>
      </source>
      <target>
        <context value="entry"/>
        <element value="request"/>
        <variable value="request"/>
      </target>
      <rule>
        <name value="requestMethod"/>
        <source>
          <context value="qr"/>
        </source>
        <target>
          <context value="request"/>
          <element value="method"/>
          <transform value="copy"/>
          <parameter>
            <valueString value="POST"/>
          </parameter>
        </target>
      </rule>
      <rule>
        <name value="requestUrl"/>
        <source>
          <context value="qr"/>
        </source>
        <target>
          <context value="request"/>
          <element value="url"/>
          <transform value="copy"/>
          <parameter>
            <valueString value="Condition"/>
          </parameter>
        </target>
      </rule>
    </rule>
    <rule>
      <name value="subject"/>
      <source>
        <context value="qr"/>
        <element value="subject"/>
        <variable value="s"/>
      </source>
      <target>
        <context value="r"/>
        <element value="subject"/>
        <transform value="copy"/>
        <parameter>
          <valueId value="s"/>
        </parameter>
      </target>
    </rule>
  </group>
  <group>
    <name value="SetConditionFullUrl"/>
    <input>
      <name value="r"/>
      <type value="Condition"/>
      <mode value="source"/>
    </input>
    <input>
      <name value="entry"/>
      <mode value="target"/>
    </input>
    <rule>
      <name value="assignFullUrl"/>
      <source>
        <context value="r"/>
        <element value="id"/>
        <variable value="id"/>
      </source>
      <target>
        <context value="entry"/>
        <element value="fullUrl"/>
        <transform value="append"/>
        <parameter>
          <valueString value="https://fhir.slade360.co.ke/fhir/Condition/"/>
        </parameter>
        <parameter>
          <valueId value="id"/>
        </parameter>
      </target>
    </rule>
  </group>
  <group>
    <name value="BuildAllergyIntoleranceBase"/>
    <input>
      <name value="qr"/>
      <type value="QR"/>
      <mode value="source"/>
    </input>
    <input>
      <name value="r"/>
      <type value="AllergyIntolerance"/>
      <mode value="target"/>
    </input>
    <input>
      <name value="entry"/>
      <mode value="target"/>
    </input>
    <rule>
      <name value="responseProvenance"/>
      <source>
        <context value="qr"/>
      </source>
      <target>
        <context value="r"/>
      </target>
      <dependent>
        <name value="SetResponseProvenance"/>
        <parameter>
          <valueId value="qr"/>
        </parameter>
        <parameter>
          <valueId value="r"/>
        </parameter>
      </dependent>
    </rule>
    <rule>
      <name value="idAndFullUrl"/>
      <source>
        <context value="qr"/>
      </source>
      <target>
        <context value="r"/>
        <element value="id"/>
        <transform value="uuid"/>
      </target>
      <dependent>
        <name value="SetAllergyIntoleranceFullUrl"/>
        <parameter>
          <valueId value="r"/>
        </parameter>
        <parameter>
          <valueId value="entry"/>
        </parameter>
      </dependent>
    </rule>
    <rule>
      <name value="entryRequest"/>
      <source>
        <context value="qr"/>
      </source>
      <target>
        <context value="entry"/>
        <element value="request"/>
        <variable value="request"/>
      </target>
      <rule>
        <name value="requestMethod"/>
        <source>
          <context value="qr"/>
        </source>
        <target>
          <context value="request"/>
          <element value="method"/>
          <transform value="copy"/>
          <parameter>
            <valueString value="POST"/>
          </parameter>
        </target>
      </rule>
      <rule>
        <name value="requestUrl"/>
        <source>
          <context value="qr"/>
        </source>
        <target>
          <context value="request"/>
          <element value="url"/>
          <transform value="copy"/>
          <parameter>
            <valueString value="AllergyIntolerance"/>
          </parameter>
        </target>
      </rule>
    </rule>
    <rule>
      <name value="subject"/>
      <source>
        <context value="qr"/>
        <element value="subject"/>
        <variable value="s"/>
      </source>
      <target>
        <context value="r"/>
        <element value="patient"/>
        <transform value="copy"/>
        <parameter>
          <valueId value="s"/>
        </parameter>
      </target>
    </rule>
  </group>
  <group>
    <name value="SetAllergyIntoleranceFullUrl"/>
    <input>
      <name value="r"/>
      <type value="AllergyIntolerance"/>
      <mode value="source"/>
    </input>
    <input>
      <name value="entry"/>
      <mode value="target"/>
    </input>
    <rule>
      <name value="assignFullUrl"/>
      <source>
        <context value="r"/>
        <element value="id"/>
        <variable value="id"/>
      </source>
      <target>
        <context value="entry"/>
        <element value="fullUrl"/>
        <transform value="append"/>
        <parameter>
          <valueString value="https://fhir.slade360.co.ke/fhir/AllergyIntolerance/"/>
        </parameter>
        <parameter>
          <valueId value="id"/>
        </parameter>
      </target>
    </rule>
  </group>
  <group>
    <name value="BuildProcedureBase"/>
    <input>
      <name value="qr"/>
      <type value="QR"/>
      <mode value="source"/>
    </input>
    <input>
      <name value="r"/>
      <type value="Procedure"/>
      <mode value="target"/>
    </input>
    <input>
      <name value="entry"/>
      <mode value="target"/>
    </input>
    <rule>
      <name value="responseProvenance"/>
      <source>
        <context value="qr"/>
      </source>
      <target>
        <context value="r"/>
      </target>
      <dependent>
        <name value="SetResponseProvenance"/>
        <parameter>
          <valueId value="qr"/>
        </parameter>
        <parameter>
          <valueId value="r"/>
        </parameter>
      </dependent>
    </rule>
    <rule>
      <name value="idAndFullUrl"/>
      <source>
        <context value="qr"/>
      </source>
      <target>
        <context value="r"/>
        <element value="id"/>
        <transform value="uuid"/>
      </target>
      <dependent>
        <name value="SetProcedureFullUrl"/>
        <parameter>
          <valueId value="r"/>
        </parameter>
        <parameter>
          <valueId value="entry"/>
        </parameter>
      </dependent>
    </rule>
    <rule>
      <name value="entryRequest"/>
      <source>
        <context value="qr"/>
      </source>
      <target>
        <context value="entry"/>
        <element value="request"/>
        <variable value="request"/>
      </target>
      <rule>
        <name value="requestMethod"/>
        <source>
          <context value="qr"/>
        </source>
        <target>
          <context value="request"/>
          <element value="method"/>
          <transform value="copy"/>
          <parameter>
            <valueString value="POST"/>
          </parameter>
        </target>
      </rule>
      <rule>
        <name value="requestUrl"/>
        <source>
          <context value="qr"/>
        </source>
        <target>
          <context value="request"/>
          <element value="url"/>
          <transform value="copy"/>
          <parameter>
            <valueString value="Procedure"/>
          </parameter>
        </target>
      </rule>
    </rule>
    <rule>
      <name value="occurrenceFallback"/>
      <source>
        <context value="qr"/>
        <element value="authored"/>
        <variable value="t"/>
      </source>
      <target>
        <context value="r"/>
        <element value="occurrence"/>
        <transform value="copy"/>
        <parameter>
          <valueId value="t"/>
        </parameter>
      </target>
      <documentation value="The response's own time, as a floor, the way BuildObsBase does it. A rule&#xD;&#xA;that reads a time off the form overwrites this; without it a procedure whose&#xD;&#xA;date column was taken off on review has no time at all, and a procedure with&#xD;&#xA;no time cannot be ordered against the rest of the admission."/>
    </rule>
    <rule>
      <name value="subject"/>
      <source>
        <context value="qr"/>
        <element value="subject"/>
        <variable value="s"/>
      </source>
      <target>
        <context value="r"/>
        <element value="subject"/>
        <transform value="copy"/>
        <parameter>
          <valueId value="s"/>
        </parameter>
      </target>
    </rule>
  </group>
  <group>
    <name value="SetProcedureFullUrl"/>
    <input>
      <name value="r"/>
      <type value="Procedure"/>
      <mode value="source"/>
    </input>
    <input>
      <name value="entry"/>
      <mode value="target"/>
    </input>
    <rule>
      <name value="assignFullUrl"/>
      <source>
        <context value="r"/>
        <element value="id"/>
        <variable value="id"/>
      </source>
      <target>
        <context value="entry"/>
        <element value="fullUrl"/>
        <transform value="append"/>
        <parameter>
          <valueString value="https://fhir.slade360.co.ke/fhir/Procedure/"/>
        </parameter>
        <parameter>
          <valueId value="id"/>
        </parameter>
      </target>
    </rule>
  </group>
  <group>
    <name value="BuildCarePlanBase"/>
    <input>
      <name value="qr"/>
      <type value="QR"/>
      <mode value="source"/>
    </input>
    <input>
      <name value="r"/>
      <type value="CarePlan"/>
      <mode value="target"/>
    </input>
    <input>
      <name value="entry"/>
      <mode value="target"/>
    </input>
    <rule>
      <name value="responseProvenance"/>
      <source>
        <context value="qr"/>
      </source>
      <target>
        <context value="r"/>
      </target>
      <dependent>
        <name value="SetResponseProvenance"/>
        <parameter>
          <valueId value="qr"/>
        </parameter>
        <parameter>
          <valueId value="r"/>
        </parameter>
      </dependent>
    </rule>
    <rule>
      <name value="idAndFullUrl"/>
      <source>
        <context value="qr"/>
      </source>
      <target>
        <context value="r"/>
        <element value="id"/>
        <transform value="uuid"/>
      </target>
      <dependent>
        <name value="SetCarePlanFullUrl"/>
        <parameter>
          <valueId value="r"/>
        </parameter>
        <parameter>
          <valueId value="entry"/>
        </parameter>
      </dependent>
    </rule>
    <rule>
      <name value="entryRequest"/>
      <source>
        <context value="qr"/>
      </source>
      <target>
        <context value="entry"/>
        <element value="request"/>
        <variable value="request"/>
      </target>
      <rule>
        <name value="requestMethod"/>
        <source>
          <context value="qr"/>
        </source>
        <target>
          <context value="request"/>
          <element value="method"/>
          <transform value="copy"/>
          <parameter>
            <valueString value="POST"/>
          </parameter>
        </target>
      </rule>
      <rule>
        <name value="requestUrl"/>
        <source>
          <context value="qr"/>
        </source>
        <target>
          <context value="request"/>
          <element value="url"/>
          <transform value="copy"/>
          <parameter>
            <valueString value="CarePlan"/>
          </parameter>
        </target>
      </rule>
    </rule>
    <rule>
      <name value="subject"/>
      <source>
        <context value="qr"/>
        <element value="subject"/>
        <variable value="s"/>
      </source>
      <target>
        <context value="r"/>
        <element value="subject"/>
        <transform value="copy"/>
        <parameter>
          <valueId value="s"/>
        </parameter>
      </target>
    </rule>
  </group>
  <group>
    <name value="SetCarePlanFullUrl"/>
    <input>
      <name value="r"/>
      <type value="CarePlan"/>
      <mode value="source"/>
    </input>
    <input>
      <name value="entry"/>
      <mode value="target"/>
    </input>
    <rule>
      <name value="assignFullUrl"/>
      <source>
        <context value="r"/>
        <element value="id"/>
        <variable value="id"/>
      </source>
      <target>
        <context value="entry"/>
        <element value="fullUrl"/>
        <transform value="append"/>
        <parameter>
          <valueString value="https://fhir.slade360.co.ke/fhir/CarePlan/"/>
        </parameter>
        <parameter>
          <valueId value="id"/>
        </parameter>
      </target>
    </rule>
  </group>
  <group>
    <name value="BuildConsentBase"/>
    <input>
      <name value="qr"/>
      <type value="QR"/>
      <mode value="source"/>
    </input>
    <input>
      <name value="r"/>
      <type value="Consent"/>
      <mode value="target"/>
    </input>
    <input>
      <name value="entry"/>
      <mode value="target"/>
    </input>
    <rule>
      <name value="responseProvenance"/>
      <source>
        <context value="qr"/>
      </source>
      <target>
        <context value="r"/>
      </target>
      <dependent>
        <name value="SetResponseProvenance"/>
        <parameter>
          <valueId value="qr"/>
        </parameter>
        <parameter>
          <valueId value="r"/>
        </parameter>
      </dependent>
    </rule>
    <rule>
      <name value="idAndFullUrl"/>
      <source>
        <context value="qr"/>
      </source>
      <target>
        <context value="r"/>
        <element value="id"/>
        <transform value="uuid"/>
      </target>
      <dependent>
        <name value="SetConsentFullUrl"/>
        <parameter>
          <valueId value="r"/>
        </parameter>
        <parameter>
          <valueId value="entry"/>
        </parameter>
      </dependent>
    </rule>
    <rule>
      <name value="entryRequest"/>
      <source>
        <context value="qr"/>
      </source>
      <target>
        <context value="entry"/>
        <element value="request"/>
        <variable value="request"/>
      </target>
      <rule>
        <name value="requestMethod"/>
        <source>
          <context value="qr"/>
        </source>
        <target>
          <context value="request"/>
          <element value="method"/>
          <transform value="copy"/>
          <parameter>
            <valueString value="POST"/>
          </parameter>
        </target>
      </rule>
      <rule>
        <name value="requestUrl"/>
        <source>
          <context value="qr"/>
        </source>
        <target>
          <context value="request"/>
          <element value="url"/>
          <transform value="copy"/>
          <parameter>
            <valueString value="Consent"/>
          </parameter>
        </target>
      </rule>
    </rule>
    <rule>
      <name value="subject"/>
      <source>
        <context value="qr"/>
        <element value="subject"/>
        <variable value="s"/>
      </source>
      <target>
        <context value="r"/>
        <element value="subject"/>
        <transform value="copy"/>
        <parameter>
          <valueId value="s"/>
        </parameter>
      </target>
    </rule>
  </group>
  <group>
    <name value="SetConsentFullUrl"/>
    <input>
      <name value="r"/>
      <type value="Consent"/>
      <mode value="source"/>
    </input>
    <input>
      <name value="entry"/>
      <mode value="target"/>
    </input>
    <rule>
      <name value="assignFullUrl"/>
      <source>
        <context value="r"/>
        <element value="id"/>
        <variable value="id"/>
      </source>
      <target>
        <context value="entry"/>
        <element value="fullUrl"/>
        <transform value="append"/>
        <parameter>
          <valueString value="https://fhir.slade360.co.ke/fhir/Consent/"/>
        </parameter>
        <parameter>
          <valueId value="id"/>
        </parameter>
      </target>
    </rule>
  </group>
  <group>
    <name value="BuildMedicationStatementBase"/>
    <input>
      <name value="qr"/>
      <type value="QR"/>
      <mode value="source"/>
    </input>
    <input>
      <name value="r"/>
      <type value="MedicationStatement"/>
      <mode value="target"/>
    </input>
    <input>
      <name value="entry"/>
      <mode value="target"/>
    </input>
    <rule>
      <name value="responseProvenance"/>
      <source>
        <context value="qr"/>
      </source>
      <target>
        <context value="r"/>
      </target>
      <dependent>
        <name value="SetResponseProvenance"/>
        <parameter>
          <valueId value="qr"/>
        </parameter>
        <parameter>
          <valueId value="r"/>
        </parameter>
      </dependent>
    </rule>
    <rule>
      <name value="idAndFullUrl"/>
      <source>
        <context value="qr"/>
      </source>
      <target>
        <context value="r"/>
        <element value="id"/>
        <transform value="uuid"/>
      </target>
      <dependent>
        <name value="SetMedicationStatementFullUrl"/>
        <parameter>
          <valueId value="r"/>
        </parameter>
        <parameter>
          <valueId value="entry"/>
        </parameter>
      </dependent>
    </rule>
    <rule>
      <name value="entryRequest"/>
      <source>
        <context value="qr"/>
      </source>
      <target>
        <context value="entry"/>
        <element value="request"/>
        <variable value="request"/>
      </target>
      <rule>
        <name value="requestMethod"/>
        <source>
          <context value="qr"/>
        </source>
        <target>
          <context value="request"/>
          <element value="method"/>
          <transform value="copy"/>
          <parameter>
            <valueString value="POST"/>
          </parameter>
        </target>
      </rule>
      <rule>
        <name value="requestUrl"/>
        <source>
          <context value="qr"/>
        </source>
        <target>
          <context value="request"/>
          <element value="url"/>
          <transform value="copy"/>
          <parameter>
            <valueString value="MedicationStatement"/>
          </parameter>
        </target>
      </rule>
    </rule>
    <rule>
      <name value="subject"/>
      <source>
        <context value="qr"/>
        <element value="subject"/>
        <variable value="s"/>
      </source>
      <target>
        <context value="r"/>
        <element value="subject"/>
        <transform value="copy"/>
        <parameter>
          <valueId value="s"/>
        </parameter>
      </target>
    </rule>
  </group>
  <group>
    <name value="SetMedicationStatementFullUrl"/>
    <input>
      <name value="r"/>
      <type value="MedicationStatement"/>
      <mode value="source"/>
    </input>
    <input>
      <name value="entry"/>
      <mode value="target"/>
    </input>
    <rule>
      <name value="assignFullUrl"/>
      <source>
        <context value="r"/>
        <element value="id"/>
        <variable value="id"/>
      </source>
      <target>
        <context value="entry"/>
        <element value="fullUrl"/>
        <transform value="append"/>
        <parameter>
          <valueString value="https://fhir.slade360.co.ke/fhir/MedicationStatement/"/>
        </parameter>
        <parameter>
          <valueId value="id"/>
        </parameter>
      </target>
    </rule>
  </group>
  <group>
    <name value="SetResponseProvenance"/>
    <documentation value="── Provenance and tenancy ───────────────────────────────────────────────────&#xD;&#xA;Two tags on everything this map creates. The first says which questionnaire&#xD;&#xA;produced it, so a form that reopens mid-admission recalls its own earlier&#xD;&#xA;entries and not another form's. The second copies the tenant tags off the&#xD;&#xA;response, because nothing else on the path puts them there.&#xD;&#xA;The code is the form's document type, not the questionnaire's id: every&#xD;&#xA;environment mints its own ids, and there is only one set of maps, so an id&#xD;&#xA;here would tie the tag to whichever environment stamped it.&#xD;&#xA;── Provenance and tenancy ───────────────────────────────────────────────────"/>
    <input>
      <name value="qr"/>
      <type value="QR"/>
      <mode value="source"/>
    </input>
    <input>
      <name value="r"/>
      <mode value="target"/>
    </input>
    <rule>
      <name value="provenanceMeta"/>
      <source>
        <context value="qr"/>
      </source>
      <target>
        <context value="r"/>
        <element value="meta"/>
        <variable value="m"/>
      </target>
      <rule>
        <name value="provenanceTag"/>
        <source>
          <context value="qr"/>
        </source>
        <target>
          <context value="m"/>
          <element value="tag"/>
          <variable value="t"/>
        </target>
        <rule>
          <name value="provenanceSystem"/>
          <source>
            <context value="qr"/>
          </source>
          <target>
            <context value="t"/>
            <element value="system"/>
            <transform value="copy"/>
            <parameter>
              <valueString value="http://slade360edi.com/questionnaire-provenance"/>
            </parameter>
          </target>
        </rule>
        <rule>
          <name value="provenanceCode"/>
          <source>
            <context value="qr"/>
          </source>
          <target>
            <context value="t"/>
            <element value="code"/>
            <transform value="copy"/>
            <parameter>
              <valueString value="maternity-record"/>
            </parameter>
          </target>
        </rule>
        <rule>
          <name value="provenanceDisplay"/>
          <source>
            <context value="qr"/>
          </source>
          <target>
            <context value="t"/>
            <element value="display"/>
            <transform value="copy"/>
            <parameter>
              <valueString value="Maternity record"/>
            </parameter>
          </target>
        </rule>
      </rule>
    </rule>
    <rule>
      <name value="tenantTags"/>
      <source>
        <context value="qr"/>
        <element value="meta"/>
        <variable value="qm"/>
      </source>
      <rule>
        <name value="copyTag"/>
        <source>
          <context value="qm"/>
          <element value="tag"/>
          <variable value="qt"/>
        </source>
        <target>
          <context value="r"/>
          <element value="meta"/>
          <variable value="m"/>
        </target>
        <target>
          <context value="m"/>
          <element value="tag"/>
          <transform value="copy"/>
          <parameter>
            <valueId value="qt"/>
          </parameter>
        </target>
      </rule>
      <documentation value="Every tag the response carries, onto the resource. `meta` is 0..1, so this&#xD;&#xA;lands on the same meta the rule above created rather than a second one."/>
    </rule>
  </group>
</StructureMap>