SGHI FHIR Profile Implementation Guide
0.1.0 - ci-build

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

: Cancer Treatment Consent Extraction - XML Representation

Active as of 2026-10-06

Raw xml | Download


<StructureMap xmlns="http://hl7.org/fhir">
  <id value="ExtractCancerTreatmentConsent"/>
  <text>
    <status value="generated"/>
    <div xmlns="http://www.w3.org/1999/xhtml"><p class="res-header-id"><b>Generated Narrative: StructureMap ExtractCancerTreatmentConsent</b></p><a name="ExtractCancerTreatmentConsent"> </a><a name="hcExtractCancerTreatmentConsent"> </a><pre class="fml">
<span style="color: #cc00cc">/// <b>url</b> = </span><span style="color: blue">'https://fhir.slade360.co.ke/fhir/StructureMap/ExtractCancerTreatmentConsent'</span>
<span style="color: #cc00cc">/// <b>name</b> = </span><span style="color: blue">'ExtractCancerTreatmentConsent'</span>
<span style="color: #cc00cc">/// <b>title</b> = </span><span style="color: blue">'Cancer Treatment Consent 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 cancer centre\'s informed consent as one Consent holding everything on the form, built only once the patient has signed: the patient as grantor, the patient and the doctor who recorded it (the response\'s author) as its grantees, that doctor and any interpreter as its two verifications, and the treatment and what was explained as its provisions.'</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/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>ExtractCancerTreatmentConsent<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 Consent ─────────────────────────────────────────────────────────</span>
  <span style="color: navy">// </span><span style="color: green">Guarded on the patient having signed, as the procedure consent is on the</span>
  <span style="color: navy">// </span><span style="color: green">consenter. A Consent built from a form nobody signed asserts a permission</span>
  <span style="color: navy">// </span><span style="color: green">that was never given.</span>
  qr<b> where </b><span style="color: navy">(</span>item.where(linkId = 'patient').item.where(linkId = 'patient/signed').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>
    qr<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>
    qr<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<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>      qr<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>        qr<span style="color: navy"><b> -&gt; </b></span>cg.system = <span style="color: blue">'http://loinc.org'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
        qr<span style="color: navy"><b> -&gt; </b></span>cg.code = <span style="color: blue">'64293-4'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
        qr<span style="color: navy"><b> -&gt; </b></span>cg.display = <span style="color: blue">'Procedure consent Document'</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>
      qr<span style="color: navy"><b> -&gt; </b></span>cat.text = <span style="color: blue">'Consent to systemic anti-cancer therapy'</span> <i>&quot;categoryText&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;category&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">// </span><span style="color: green">The patient consents for themselves: the form has no line for anyone</span>
    <span style="color: navy">// </span><span style="color: green">else to sign on their behalf.</span>
    qr.subject<b> as </b><span style="color: maroon">s</span><b> where </b><span style="color: navy">(</span>(reference.exists() and (reference.startsWith('Organization/') or reference.startsWith('Patient/'))) or (reference.empty() and (type.empty() or ('/' + type).endsWith('/Organization') or ('/' + type).endsWith('/Patient')))<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span>consent.grantor = <span style="color: maroon">s</span> <i>&quot;grantorPatient&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">// </span><span style="color: green">The grantees are both parties to the consent: the patient, written here and only</span>
    <span style="color: navy">// </span><span style="color: green">when the subject is one, and the practitioner who recorded it, the response's</span>
    <span style="color: navy">// </span><span style="color: green">author, which ConformConsent adds. The stamped copy never names the patient</span>
    <span style="color: navy">// </span><span style="color: green">itself; see mapmeta's WHO_NEVER.</span>
    qr.subject<b> as </b><span style="color: maroon">s</span><b> where </b><span style="color: navy">(</span>reference.startsWith('Patient/') and ((reference.exists() and (reference.startsWith('Patient/') or reference.startsWith('Organization/') or reference.startsWith('Practitioner/') or reference.startsWith('PractitionerRole/'))) or (reference.empty() and (type.empty() or ('/' + type).endsWith('/Patient') or ('/' + type).endsWith('/Organization') or ('/' + type).endsWith('/Practitioner') or ('/' + type).endsWith('/PractitionerRole'))))<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span>consent.grantee = <span style="color: maroon">s</span> <i>&quot;granteePatient&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">// </span><span style="color: green">The signing time, from the form, not qr.authored. Consent.date is a</span>
    <span style="color: navy">// </span><span style="color: green">`date` and this is a date and time, so it goes to period.start.</span>
    qr.item<b> as </b><span style="color: maroon">pg</span><b> where </b><span style="color: navy">(</span>linkId = 'patient'<span style="color: navy">)</span><b> then</b><span style="color: navy"> {
</span>      pg.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'patient/signed-at') and answer.value.exists()<span style="color: navy">)</span><b> then</b><span style="color: navy"> {
</span>        it.answer first<b> as </b><span style="color: maroon">a</span><b> then</b><span style="color: navy"> {
</span>          a.value<b> as </b><span style="color: maroon">t</span><span style="color: navy"><b> -&gt; </b></span> 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;signedPeriodStart&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;signedAtRule&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;patientGroup&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">// </span><span style="color: green">── The verifications ─────────────────────────────────────────────────</span>
    <span style="color: navy">// </span><span style="color: green">The doctor's, and the interpreter's when one was used.</span>
    <span style="color: navy">// </span><span style="color: green">The doctor who explained the treatment is the response's author. The form</span>
    <span style="color: navy">// </span><span style="color: green">stopped asking for the doctor's name, designation and signature on</span>
    <span style="color: navy">// </span><span style="color: green">2026-10-06, because whoever records the consent is that doctor. So the</span>
    <span style="color: navy">// </span><span style="color: green">verification is made when the response has an author who is a person, a</span>
    <span style="color: navy">// </span><span style="color: green">Practitioner or a PractitionerRole (an Organization is not a doctor), and</span>
    <span style="color: navy">// </span><span style="color: green">it is verified by them: recording the form is their attestation. No such</span>
    <span style="color: navy">// </span><span style="color: green">author, no doctor's verification. Dated with the patient's signing, the</span>
    <span style="color: navy">// </span><span style="color: green">only time the form records.</span>
    qr.author<b> as </b><span style="color: maroon">au</span><b> where </b><span style="color: navy">(</span>(reference.exists() and (reference.startsWith('Practitioner/') or reference.startsWith('PractitionerRole/'))) or (reference.empty() and (type.empty() or ('/' + type).endsWith('/Practitioner') or ('/' + type).endsWith('/PractitionerRole')))<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span>consent.verification<b> as </b><span style="color: maroon">ver</span><b> then</b><span style="color: navy"> {
</span>      au<span style="color: navy"><b> -&gt; </b></span>ver.verified = <span style="color: blue">true</span> <i>&quot;verified&quot;</i><span style="color: navy">;</span>
      au<span style="color: navy"><b> -&gt; </b></span>ver.verificationType<b> as </b><span style="color: maroon">vt</span><b> then</b><span style="color: navy"> {
</span>        au<span style="color: navy"><b> -&gt; </b></span>vt.coding<b> as </b><span style="color: maroon">vc</span><b> then</b><span style="color: navy"> {
</span>          au<span style="color: navy"><b> -&gt; </b></span>vc.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>
          au<span style="color: navy"><b> -&gt; </b></span>vc.code = <span style="color: blue">'consent-verified-by-doctor'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
          au<span style="color: navy"><b> -&gt; </b></span>vc.display = <span style="color: blue">'Verified by the doctor who explained the treatment'</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>
        au<span style="color: navy"><b> -&gt; </b></span>vt.text = <span style="color: blue">'Doctor'</span> <i>&quot;text&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;doctorVerificationType&quot;</i><span style="color: navy">;</span>
      au<b> where </b><span style="color: navy">(</span>(reference.exists() and (reference.startsWith('Organization/') or reference.startsWith('Practitioner/') or reference.startsWith('PractitionerRole/'))) or (reference.empty() and (type.empty() or ('/' + type).endsWith('/Organization') or ('/' + type).endsWith('/Practitioner') or ('/' + type).endsWith('/PractitionerRole')))<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span>ver.verifiedBy = <span style="color: maroon">au</span> <i>&quot;verifiedBy&quot;</i><span style="color: navy">;</span>
      qr.subject<b> as </b><span style="color: maroon">s</span><b> where </b><span style="color: navy">(</span>(reference.exists() and (reference.startsWith('Patient/'))) or (reference.empty() and (type.empty() or ('/' + type).endsWith('/Patient')))<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span>ver.verifiedWith = <span style="color: maroon">s</span> <i>&quot;verifiedWith&quot;</i><span style="color: navy">;</span>
      qr.item<b> as </b><span style="color: maroon">pg2</span><b> where </b><span style="color: navy">(</span>linkId = 'patient'<span style="color: navy">)</span><b> then</b><span style="color: navy"> {
</span>        pg2.item<b> as </b><span style="color: maroon">st</span><b> where </b><span style="color: navy">(</span>(linkId = 'patient/signed-at') and answer.value.exists()<span style="color: navy">)</span><b> then</b><span style="color: navy"> {
</span>          st.answer first<b> as </b><span style="color: maroon">sa</span><b> then</b><span style="color: navy"> {
</span>            sa.value<b> as </b><span style="color: maroon">t</span><span style="color: navy"><b> -&gt; </b></span>ver.verificationDate = <span style="color: maroon">t</span> <i>&quot;verificationDate&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;signedAtAnswer&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;signedAtRule&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;patientGroupForVerification&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;doctorVerification&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">// </span><span style="color: green">The interpreter, if one was used: whether the explanation reached the patient</span>
    <span style="color: navy">// </span><span style="color: green">in a language they understood is what makes the consent informed. Verified</span>
    <span style="color: navy">// </span><span style="color: green">when they have signed. It names no verifier, because the interpreter is a name</span>
    <span style="color: navy">// </span><span style="color: green">on the form, not a record anything could point at; the name is in its type.</span>
    qr.item<b> as </b><span style="color: maroon">ig</span><b> where </b><span style="color: navy">(</span>linkId = 'interpreter'<span style="color: navy">)</span><b> then</b><span style="color: navy"> {
</span>      ig.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'interpreter/name') 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">name</span><b> where </b><span style="color: navy">(</span>$this is string<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span>consent.verification<b> as </b><span style="color: maroon">iv</span><b> then</b><span style="color: navy"> {
</span>            name<span style="color: navy"><b> -&gt; </b></span>iv.verified = <span style="color: blue">false</span> <i>&quot;verifiedUnlessSigned&quot;</i><span style="color: navy">;</span>
            ig.item<b> as </b><span style="color: maroon">sg</span><b> where </b><span style="color: navy">(</span>(linkId = 'interpreter/signed') and (answer.value = true)<span style="color: navy">)</span><b> then</b><span style="color: navy"> {
</span>              sg<span style="color: navy"><b> -&gt; </b></span>iv.verified = <span style="color: blue">true</span> <i>&quot;interpreterSigned&quot;</i><span style="color: navy">;</span>
            <span style="color: navy">}</span> <i>&quot;interpreterSignedRule&quot;</i><span style="color: navy">;</span>
            name<span style="color: navy"><b> -&gt; </b></span>iv.verificationType<b> as </b><span style="color: maroon">ivt</span><b> then</b><span style="color: navy"> {
</span>              name<span style="color: navy"><b> -&gt; </b></span>ivt.coding<b> as </b><span style="color: maroon">ic</span><b> then</b><span style="color: navy"> {
</span>                name<span style="color: navy"><b> -&gt; </b></span>ic.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>
                name<span style="color: navy"><b> -&gt; </b></span>ic.code = <span style="color: blue">'consent-interpreter-used'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
                name<span style="color: navy"><b> -&gt; </b></span>ic.display = <span style="color: blue">'Interpreter used for the consent discussion'</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>
              name<span style="color: navy"><b> -&gt; </b></span>ivt.text = <b>append</b><span style="color: navy">(</span><span style="color: blue">'Interpreter: '</span><span style="color: navy">, </span><span style="color: maroon">name</span><span style="color: navy">)</span> <i>&quot;text&quot;</i><span style="color: navy">;</span>
            <span style="color: navy">}</span> <i>&quot;interpreterVerificationType&quot;</i><span style="color: navy">;</span>
            qr.subject<b> as </b><span style="color: maroon">s</span><b> where </b><span style="color: navy">(</span>(reference.exists() and (reference.startsWith('Patient/'))) or (reference.empty() and (type.empty() or ('/' + type).endsWith('/Patient')))<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span>iv.verifiedWith = <span style="color: maroon">s</span> <i>&quot;verifiedWith&quot;</i><span style="color: navy">;</span>
            qr.item<b> as </b><span style="color: maroon">pg3</span><b> where </b><span style="color: navy">(</span>linkId = 'patient'<span style="color: navy">)</span><b> then</b><span style="color: navy"> {
</span>              pg3.item<b> as </b><span style="color: maroon">st</span><b> where </b><span style="color: navy">(</span>(linkId = 'patient/signed-at') and answer.value.exists()<span style="color: navy">)</span><b> then</b><span style="color: navy"> {
</span>                st.answer first<b> as </b><span style="color: maroon">sa</span><b> then</b><span style="color: navy"> {
</span>                  sa.value<b> as </b><span style="color: maroon">t</span><span style="color: navy"><b> -&gt; </b></span>iv.verificationDate = <span style="color: maroon">t</span> <i>&quot;verificationDate&quot;</i><span style="color: navy">;</span>
                <span style="color: navy">}</span> <i>&quot;signedAtAnswer&quot;</i><span style="color: navy">;</span>
              <span style="color: navy">}</span> <i>&quot;signedAtRule&quot;</i><span style="color: navy">;</span>
            <span style="color: navy">}</span> <i>&quot;patientGroupForInterpreter&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;interpreterVerification&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>
    <span style="color: navy">}</span> <i>&quot;interpreterGroup&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">// </span><span style="color: green">── The provisions ────────────────────────────────────────────────────</span>
    <span style="color: navy">// </span><span style="color: green">One per kind of therapy ticked, so a consent to hormonal therapy cannot</span>
    <span style="color: navy">// </span><span style="color: green">be read as covering chemotherapy. The local code is what the form</span>
    <span style="color: navy">// </span><span style="color: green">offered; the LOINC answer code beside it is what another system will</span>
    <span style="color: navy">// </span><span style="color: green">recognise, and LOINC is what SGHIConsent binds provision.code to</span>
    <span style="color: navy">// </span><span style="color: green">(consent-content-code, required). Both LOINC codes come from LOINC's</span>
    <span style="color: navy">// </span><span style="color: green">own list of cancer treatments, LL1479-6, and the display is LOINC's to</span>
    <span style="color: navy">// </span><span style="color: green">the letter, trailing slash included. LOINC has no code for targeted</span>
    <span style="color: navy">// </span><span style="color: green">therapy, so that one carries the local code alone.</span>
    <span style="color: navy">// </span><span style="color: green">The regimen and what was explained are provisions too, each labelled.</span>
    <span style="color: navy">// </span><span style="color: green">Consent has no note in R5, and this is where the procedure consent puts</span>
    <span style="color: navy">// </span><span style="color: green">the same prose.</span>
    qr.item<b> as </b><span style="color: maroon">tg</span><b> where </b><span style="color: navy">(</span>linkId = 'treatment'<span style="color: navy">)</span><b> then</b><span style="color: navy"> {
</span>      tg.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>linkId = 'treatment/therapy'<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>consent.provision<b> as </b><span style="color: maroon">prov</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>prov.code<b> as </b><span style="color: maroon">pc</span><b> then</b><span style="color: navy"> {
</span>            cv<span style="color: navy"><b> -&gt; </b></span>pc.coding = <span style="color: maroon">cv</span> <i>&quot;localCoding&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>pc.text = <span style="color: maroon">d</span> <i>&quot;text&quot;</i><span style="color: navy">;</span>
            cv<b> where </b><span style="color: navy">(</span>code = 'anti-cancer-chemotherapy'<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span>pc.coding<b> as </b><span style="color: maroon">loinc</span><b> then</b><span style="color: navy"> {
</span>              cv<span style="color: navy"><b> -&gt; </b></span>loinc.system = <span style="color: blue">'http://loinc.org'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
              cv<span style="color: navy"><b> -&gt; </b></span>loinc.code = <span style="color: blue">'LA6172-6'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
              cv<span style="color: navy"><b> -&gt; </b></span>loinc.display = <span style="color: blue">'Chemotherapy'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
            <span style="color: navy">}</span> <i>&quot;chemotherapyLoinc&quot;</i><span style="color: navy">;</span>
            cv<b> where </b><span style="color: navy">(</span>code = 'anti-cancer-hormonal-therapy'<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span>pc.coding<b> as </b><span style="color: maroon">loinc</span><b> then</b><span style="color: navy"> {
</span>              cv<span style="color: navy"><b> -&gt; </b></span>loinc.system = <span style="color: blue">'http://loinc.org'</span> <i>&quot;sys&quot;</i><span style="color: navy">;</span>
              cv<span style="color: navy"><b> -&gt; </b></span>loinc.code = <span style="color: blue">'LA16052-5'</span> <i>&quot;cd&quot;</i><span style="color: navy">;</span>
              cv<span style="color: navy"><b> -&gt; </b></span>loinc.display = <span style="color: blue">'Hormonal therapy/'</span> <i>&quot;dsp&quot;</i><span style="color: navy">;</span>
            <span style="color: navy">}</span> <i>&quot;hormonalLoinc&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;therapyCode&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;therapyProvision&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;therapyRule&quot;</i><span style="color: navy">;</span>
      tg.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'treatment/regimen') 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> 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 = <b>append</b><span style="color: navy">(</span><span style="color: blue">'Drug regimen: '</span><span style="color: navy">, </span><span style="color: maroon">txt</span><span style="color: navy">)</span> <i>&quot;regimenProvision&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;regimenRule&quot;</i><span style="color: navy">;</span>
      tg.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'treatment/diagnosis') 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> 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 = <b>append</b><span style="color: navy">(</span><span style="color: blue">'Diagnosis explained: '</span><span style="color: navy">, </span><span style="color: maroon">txt</span><span style="color: navy">)</span> <i>&quot;diagnosisProvision&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;diagnosisRule&quot;</i><span style="color: navy">;</span>
      tg.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'treatment/intended-purpose') 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> 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 = <b>append</b><span style="color: navy">(</span><span style="color: blue">'Intended purpose explained: '</span><span style="color: navy">, </span><span style="color: maroon">txt</span><span style="color: navy">)</span> <i>&quot;purposeProvision&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;purposeRule&quot;</i><span style="color: navy">;</span>
      tg.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>(linkId = 'treatment/side-effects-and-risks') 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> 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 = <b>append</b><span style="color: navy">(</span><span style="color: blue">'Side effects and risks explained: '</span><span style="color: navy">, </span><span style="color: maroon">txt</span><span style="color: navy">)</span> <i>&quot;sideEffectsProvision&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;sideEffectsRule&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;treatmentGroup&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">─────────────────────────────────────────────────────────────────────────────</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.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> r.sourceReference = <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">srcRef</span><span style="color: navy">, </span> srcRef.reference = <span style="color: maroon">qid</span> <i>&quot;linkQuestionnaireResponse&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><b> where </b><span style="color: navy">(</span>(reference.exists() and (reference.startsWith('Patient/'))) or (reference.empty() and (type.empty() or ('/' + type).endsWith('/Patient')))<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span>r.subject = <span style="color: maroon">s</span><span style="color: navy">;</span>
  qr<span style="color: navy"><b> -&gt; </b></span>r<b> then </b>ConformConsent<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;profileConformance&quot;</i><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><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. The response's</span>
<span style="color: navy">// </span><span style="color: green">identifier is copied the same way.</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">'cancer-treatment-consent'</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">'Cancer centre informed consent'</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><span style="color: green">The response's identifiers, as they are. Every profile wants one, and it is</span>
  <span style="color: navy">// </span><span style="color: green">the response's to give: nothing here mints one, so a response without an</span>
  <span style="color: navy">// </span><span style="color: green">identifier extracts resources without one. One whose assigner is not of a</span>
  <span style="color: navy">// </span><span style="color: green">type the profiles allow there is left behind whole, not altered.</span>
  qr.identifier<b> as </b><span style="color: maroon">qid</span><b> where </b><span style="color: navy">(</span>assigner.empty() or assigner.where(((reference.exists() and (reference.startsWith('Organization/'))) or (reference.empty() and (type.empty() or ('/' + type).endsWith('/Organization'))))).exists()<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span>r.identifier = <span style="color: maroon">qid</span><span style="color: navy">;</span>
<span style="color: navy">}

</span><span style="color: navy">// </span><span style="color: green">── Conformance to the IG profiles ───────────────────────────────────────────</span>
<span style="color: navy">// </span><span style="color: green">What the IG's profiles require that the response itself can supply. Called at</span>
<span style="color: navy">// </span><span style="color: green">the end of each base group. The encounter and every who-element are the</span>
<span style="color: navy">// </span><span style="color: green">response's own; see mapmeta.py for what is and is not here.</span>
<span style="color: navy">// </span><span style="color: green">── Conformance to the IG profiles ───────────────────────────────────────────</span>
<b>group </b>ConformConsent<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.authored<b> as </b><span style="color: maroon">t</span><span style="color: navy"><b> -&gt; </b></span> evaluate<span style="color: navy">(</span>t<span style="color: navy">, </span>$this.toString().substring(0, 10)<span style="color: navy">)</span><b> as </b><span style="color: maroon">day</span><span style="color: navy">, </span> r.date = <b>cast</b><span style="color: navy">(</span><span style="color: maroon">day</span><span style="color: navy">, </span><span style="color: blue">'date'</span><span style="color: navy">)</span> <i>&quot;date&quot;</i><span style="color: navy">;</span>
  qr.author<b> as </b><span style="color: maroon">au</span><b> where </b><span style="color: navy">(</span>(reference.exists() and (reference.startsWith('Organization/') or reference.startsWith('Practitioner/') or reference.startsWith('PractitionerRole/'))) or (reference.empty() and (type.empty() or ('/' + type).endsWith('/Organization') or ('/' + type).endsWith('/Practitioner') or ('/' + type).endsWith('/PractitionerRole')))<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span>r.grantee = <span style="color: maroon">au</span> <i>&quot;granteeFromAuthor&quot;</i><span style="color: navy">;</span>
  qr<b> where </b><span style="color: navy">(</span>author.where(((reference.exists() and (reference.startsWith('Organization/') or reference.startsWith('Practitioner/') or reference.startsWith('PractitionerRole/'))) or (reference.empty() and (type.empty() or ('/' + type).endsWith('/Organization') or ('/' + type).endsWith('/Practitioner') or ('/' + type).endsWith('/PractitionerRole'))))).exists().not()<span style="color: navy">)</span><b> then</b><span style="color: navy"> {
</span>    qr.source<b> as </b><span style="color: maroon">src</span><b> where </b><span style="color: navy">(</span>(reference.exists() and (reference.startsWith('Organization/') or reference.startsWith('Practitioner/') or reference.startsWith('PractitionerRole/'))) or (reference.empty() and (type.empty() or ('/' + type).endsWith('/Organization') or ('/' + type).endsWith('/Practitioner') or ('/' + type).endsWith('/PractitionerRole')))<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span>r.grantee = <span style="color: maroon">src</span> <i>&quot;granteeFromSource&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">}</span> <i>&quot;granteeFallback&quot;</i><span style="color: navy">;</span>
<span style="color: navy">}

</span></pre></div>
  </text>
  <url
       value="https://fhir.slade360.co.ke/fhir/StructureMap/ExtractCancerTreatmentConsent"/>
  <version value="0.1.0"/>
  <name value="ExtractCancerTreatmentConsent"/>
  <title value="Cancer Treatment Consent Extraction"/>
  <status value="active"/>
  <date value="2026-10-06T18:48:22+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 cancer centre's informed consent as one Consent holding everything on the form, built only once the patient has signed: the patient as grantor, the patient and the doctor who recorded it (the response's author) as its grantees, that doctor and any interpreter as its two verifications, and the treatment and what was explained as its provisions."/>
  <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/Consent"/>
    <mode value="target"/>
    <alias value="Consent"/>
  </structure>
  <group>
    <name value="ExtractCancerTreatmentConsent"/>
    <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="createConsent"/>
      <source>
        <context value="qr"/>
        <condition
                   value="item.where(linkId = 'patient').item.where(linkId = 'patient/signed').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="qr"/>
        </source>
        <target>
          <context value="consent"/>
          <element value="status"/>
          <transform value="copy"/>
          <parameter>
            <valueString value="active"/>
          </parameter>
        </target>
      </rule>
      <rule>
        <name value="decision"/>
        <source>
          <context value="qr"/>
        </source>
        <target>
          <context value="consent"/>
          <element value="decision"/>
          <transform value="copy"/>
          <parameter>
            <valueString value="permit"/>
          </parameter>
        </target>
      </rule>
      <rule>
        <name value="category"/>
        <source>
          <context value="qr"/>
        </source>
        <target>
          <context value="consent"/>
          <element value="category"/>
          <variable value="cat"/>
        </target>
        <rule>
          <name value="coding"/>
          <source>
            <context value="qr"/>
          </source>
          <target>
            <context value="cat"/>
            <element value="coding"/>
            <variable value="cg"/>
          </target>
          <rule>
            <name value="sys"/>
            <source>
              <context value="qr"/>
            </source>
            <target>
              <context value="cg"/>
              <element value="system"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="http://loinc.org"/>
              </parameter>
            </target>
          </rule>
          <rule>
            <name value="cd"/>
            <source>
              <context value="qr"/>
            </source>
            <target>
              <context value="cg"/>
              <element value="code"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="64293-4"/>
              </parameter>
            </target>
          </rule>
          <rule>
            <name value="dsp"/>
            <source>
              <context value="qr"/>
            </source>
            <target>
              <context value="cg"/>
              <element value="display"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="Procedure consent Document"/>
              </parameter>
            </target>
          </rule>
        </rule>
        <rule>
          <name value="categoryText"/>
          <source>
            <context value="qr"/>
          </source>
          <target>
            <context value="cat"/>
            <element value="text"/>
            <transform value="copy"/>
            <parameter>
              <valueString value="Consent to systemic anti-cancer therapy"/>
            </parameter>
          </target>
        </rule>
      </rule>
      <rule>
        <name value="grantorPatient"/>
        <source>
          <context value="qr"/>
          <element value="subject"/>
          <variable value="s"/>
          <condition
                     value="(reference.exists() and (reference.startsWith('Organization/') or reference.startsWith('Patient/'))) or (reference.empty() and (type.empty() or ('/' + type).endsWith('/Organization') or ('/' + type).endsWith('/Patient')))"/>
        </source>
        <target>
          <context value="consent"/>
          <element value="grantor"/>
          <transform value="copy"/>
          <parameter>
            <valueId value="s"/>
          </parameter>
        </target>
        <documentation
                       value="The patient consents for themselves: the form has no line for anyone
else to sign on their behalf."/>
      </rule>
      <rule>
        <name value="granteePatient"/>
        <source>
          <context value="qr"/>
          <element value="subject"/>
          <variable value="s"/>
          <condition
                     value="reference.startsWith('Patient/') and ((reference.exists() and (reference.startsWith('Patient/') or reference.startsWith('Organization/') or reference.startsWith('Practitioner/') or reference.startsWith('PractitionerRole/'))) or (reference.empty() and (type.empty() or ('/' + type).endsWith('/Patient') or ('/' + type).endsWith('/Organization') or ('/' + type).endsWith('/Practitioner') or ('/' + type).endsWith('/PractitionerRole'))))"/>
        </source>
        <target>
          <context value="consent"/>
          <element value="grantee"/>
          <transform value="copy"/>
          <parameter>
            <valueId value="s"/>
          </parameter>
        </target>
        <documentation
                       value="The grantees are both parties to the consent: the patient, written here and only
when the subject is one, and the practitioner who recorded it, the response's
author, which ConformConsent adds. The stamped copy never names the patient
itself; see mapmeta's WHO_NEVER."/>
      </rule>
      <rule>
        <name value="patientGroup"/>
        <source>
          <context value="qr"/>
          <element value="item"/>
          <variable value="pg"/>
          <condition value="linkId = 'patient'"/>
        </source>
        <rule>
          <name value="signedAtRule"/>
          <source>
            <context value="pg"/>
            <element value="item"/>
            <variable value="it"/>
            <condition
                       value="(linkId = 'patient/signed-at') 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="signedPeriodStart"/>
              <source>
                <context value="a"/>
                <element value="value"/>
                <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>
        </rule>
        <documentation
                       value="The signing time, from the form, not qr.authored. Consent.date is a
`date` and this is a date and time, so it goes to period.start."/>
      </rule>
      <rule>
        <name value="doctorVerification"/>
        <source>
          <context value="qr"/>
          <element value="author"/>
          <variable value="au"/>
          <condition
                     value="(reference.exists() and (reference.startsWith('Practitioner/') or reference.startsWith('PractitionerRole/'))) or (reference.empty() and (type.empty() or ('/' + type).endsWith('/Practitioner') or ('/' + type).endsWith('/PractitionerRole')))"/>
        </source>
        <target>
          <context value="consent"/>
          <element value="verification"/>
          <variable value="ver"/>
        </target>
        <rule>
          <name value="verified"/>
          <source>
            <context value="au"/>
          </source>
          <target>
            <context value="ver"/>
            <element value="verified"/>
            <transform value="copy"/>
            <parameter>
              <valueBoolean value="true"/>
            </parameter>
          </target>
        </rule>
        <rule>
          <name value="doctorVerificationType"/>
          <source>
            <context value="au"/>
          </source>
          <target>
            <context value="ver"/>
            <element value="verificationType"/>
            <variable value="vt"/>
          </target>
          <rule>
            <name value="coding"/>
            <source>
              <context value="au"/>
            </source>
            <target>
              <context value="vt"/>
              <element value="coding"/>
              <variable value="vc"/>
            </target>
            <rule>
              <name value="sys"/>
              <source>
                <context value="au"/>
              </source>
              <target>
                <context value="vc"/>
                <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="au"/>
              </source>
              <target>
                <context value="vc"/>
                <element value="code"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="consent-verified-by-doctor"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="dsp"/>
              <source>
                <context value="au"/>
              </source>
              <target>
                <context value="vc"/>
                <element value="display"/>
                <transform value="copy"/>
                <parameter>
                  <valueString
                               value="Verified by the doctor who explained the treatment"/>
                </parameter>
              </target>
            </rule>
          </rule>
          <rule>
            <name value="text"/>
            <source>
              <context value="au"/>
            </source>
            <target>
              <context value="vt"/>
              <element value="text"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="Doctor"/>
              </parameter>
            </target>
          </rule>
        </rule>
        <rule>
          <name value="verifiedBy"/>
          <source>
            <context value="au"/>
            <condition
                       value="(reference.exists() and (reference.startsWith('Organization/') or reference.startsWith('Practitioner/') or reference.startsWith('PractitionerRole/'))) or (reference.empty() and (type.empty() or ('/' + type).endsWith('/Organization') or ('/' + type).endsWith('/Practitioner') or ('/' + type).endsWith('/PractitionerRole')))"/>
          </source>
          <target>
            <context value="ver"/>
            <element value="verifiedBy"/>
            <transform value="copy"/>
            <parameter>
              <valueId value="au"/>
            </parameter>
          </target>
        </rule>
        <rule>
          <name value="verifiedWith"/>
          <source>
            <context value="qr"/>
            <element value="subject"/>
            <variable value="s"/>
            <condition
                       value="(reference.exists() and (reference.startsWith('Patient/'))) or (reference.empty() and (type.empty() or ('/' + type).endsWith('/Patient')))"/>
          </source>
          <target>
            <context value="ver"/>
            <element value="verifiedWith"/>
            <transform value="copy"/>
            <parameter>
              <valueId value="s"/>
            </parameter>
          </target>
        </rule>
        <rule>
          <name value="patientGroupForVerification"/>
          <source>
            <context value="qr"/>
            <element value="item"/>
            <variable value="pg2"/>
            <condition value="linkId = 'patient'"/>
          </source>
          <rule>
            <name value="signedAtRule"/>
            <source>
              <context value="pg2"/>
              <element value="item"/>
              <variable value="st"/>
              <condition
                         value="(linkId = 'patient/signed-at') and answer.value.exists()"/>
            </source>
            <rule>
              <name value="signedAtAnswer"/>
              <source>
                <context value="st"/>
                <element value="answer"/>
                <listMode value="first"/>
                <variable value="sa"/>
              </source>
              <rule>
                <name value="verificationDate"/>
                <source>
                  <context value="sa"/>
                  <element value="value"/>
                  <variable value="t"/>
                </source>
                <target>
                  <context value="ver"/>
                  <element value="verificationDate"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueId value="t"/>
                  </parameter>
                </target>
              </rule>
            </rule>
          </rule>
        </rule>
        <documentation
                       value="── The verifications ─────────────────────────────────────────────────
The doctor's, and the interpreter's when one was used.
The doctor who explained the treatment is the response's author. The form
stopped asking for the doctor's name, designation and signature on
2026-10-06, because whoever records the consent is that doctor. So the
verification is made when the response has an author who is a person, a
Practitioner or a PractitionerRole (an Organization is not a doctor), and
it is verified by them: recording the form is their attestation. No such
author, no doctor's verification. Dated with the patient's signing, the
only time the form records."/>
      </rule>
      <rule>
        <name value="interpreterGroup"/>
        <source>
          <context value="qr"/>
          <element value="item"/>
          <variable value="ig"/>
          <condition value="linkId = 'interpreter'"/>
        </source>
        <rule>
          <name value="nameRule"/>
          <source>
            <context value="ig"/>
            <element value="item"/>
            <variable value="it"/>
            <condition
                       value="(linkId = 'interpreter/name') 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="interpreterVerification"/>
              <source>
                <context value="a"/>
                <element value="value"/>
                <variable value="name"/>
                <condition value="$this is string"/>
              </source>
              <target>
                <context value="consent"/>
                <element value="verification"/>
                <variable value="iv"/>
              </target>
              <rule>
                <name value="verifiedUnlessSigned"/>
                <source>
                  <context value="name"/>
                </source>
                <target>
                  <context value="iv"/>
                  <element value="verified"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueBoolean value="false"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="interpreterSignedRule"/>
                <source>
                  <context value="ig"/>
                  <element value="item"/>
                  <variable value="sg"/>
                  <condition
                             value="(linkId = 'interpreter/signed') and (answer.value = true)"/>
                </source>
                <rule>
                  <name value="interpreterSigned"/>
                  <source>
                    <context value="sg"/>
                  </source>
                  <target>
                    <context value="iv"/>
                    <element value="verified"/>
                    <transform value="copy"/>
                    <parameter>
                      <valueBoolean value="true"/>
                    </parameter>
                  </target>
                </rule>
              </rule>
              <rule>
                <name value="interpreterVerificationType"/>
                <source>
                  <context value="name"/>
                </source>
                <target>
                  <context value="iv"/>
                  <element value="verificationType"/>
                  <variable value="ivt"/>
                </target>
                <rule>
                  <name value="coding"/>
                  <source>
                    <context value="name"/>
                  </source>
                  <target>
                    <context value="ivt"/>
                    <element value="coding"/>
                    <variable value="ic"/>
                  </target>
                  <rule>
                    <name value="sys"/>
                    <source>
                      <context value="name"/>
                    </source>
                    <target>
                      <context value="ic"/>
                      <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="name"/>
                    </source>
                    <target>
                      <context value="ic"/>
                      <element value="code"/>
                      <transform value="copy"/>
                      <parameter>
                        <valueString value="consent-interpreter-used"/>
                      </parameter>
                    </target>
                  </rule>
                  <rule>
                    <name value="dsp"/>
                    <source>
                      <context value="name"/>
                    </source>
                    <target>
                      <context value="ic"/>
                      <element value="display"/>
                      <transform value="copy"/>
                      <parameter>
                        <valueString
                                     value="Interpreter used for the consent discussion"/>
                      </parameter>
                    </target>
                  </rule>
                </rule>
                <rule>
                  <name value="text"/>
                  <source>
                    <context value="name"/>
                  </source>
                  <target>
                    <context value="ivt"/>
                    <element value="text"/>
                    <transform value="append"/>
                    <parameter>
                      <valueString value="Interpreter: "/>
                    </parameter>
                    <parameter>
                      <valueId value="name"/>
                    </parameter>
                  </target>
                </rule>
              </rule>
              <rule>
                <name value="verifiedWith"/>
                <source>
                  <context value="qr"/>
                  <element value="subject"/>
                  <variable value="s"/>
                  <condition
                             value="(reference.exists() and (reference.startsWith('Patient/'))) or (reference.empty() and (type.empty() or ('/' + type).endsWith('/Patient')))"/>
                </source>
                <target>
                  <context value="iv"/>
                  <element value="verifiedWith"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueId value="s"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="patientGroupForInterpreter"/>
                <source>
                  <context value="qr"/>
                  <element value="item"/>
                  <variable value="pg3"/>
                  <condition value="linkId = 'patient'"/>
                </source>
                <rule>
                  <name value="signedAtRule"/>
                  <source>
                    <context value="pg3"/>
                    <element value="item"/>
                    <variable value="st"/>
                    <condition
                               value="(linkId = 'patient/signed-at') and answer.value.exists()"/>
                  </source>
                  <rule>
                    <name value="signedAtAnswer"/>
                    <source>
                      <context value="st"/>
                      <element value="answer"/>
                      <listMode value="first"/>
                      <variable value="sa"/>
                    </source>
                    <rule>
                      <name value="verificationDate"/>
                      <source>
                        <context value="sa"/>
                        <element value="value"/>
                        <variable value="t"/>
                      </source>
                      <target>
                        <context value="iv"/>
                        <element value="verificationDate"/>
                        <transform value="copy"/>
                        <parameter>
                          <valueId value="t"/>
                        </parameter>
                      </target>
                    </rule>
                  </rule>
                </rule>
              </rule>
            </rule>
          </rule>
        </rule>
        <documentation
                       value="The interpreter, if one was used: whether the explanation reached the patient
in a language they understood is what makes the consent informed. Verified
when they have signed. It names no verifier, because the interpreter is a name
on the form, not a record anything could point at; the name is in its type."/>
      </rule>
      <rule>
        <name value="treatmentGroup"/>
        <source>
          <context value="qr"/>
          <element value="item"/>
          <variable value="tg"/>
          <condition value="linkId = 'treatment'"/>
        </source>
        <rule>
          <name value="therapyRule"/>
          <source>
            <context value="tg"/>
            <element value="item"/>
            <variable value="it"/>
            <condition value="linkId = 'treatment/therapy'"/>
          </source>
          <rule>
            <name value="therapyProvision"/>
            <source>
              <context value="it"/>
              <element value="answer"/>
              <variable value="a"/>
            </source>
            <target>
              <context value="consent"/>
              <element value="provision"/>
              <variable value="prov"/>
            </target>
            <rule>
              <name value="therapyCode"/>
              <source>
                <context value="a"/>
                <element value="value"/>
                <variable value="cv"/>
              </source>
              <target>
                <context value="prov"/>
                <element value="code"/>
                <variable value="pc"/>
              </target>
              <rule>
                <name value="localCoding"/>
                <source>
                  <context value="cv"/>
                </source>
                <target>
                  <context value="pc"/>
                  <element value="coding"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueId value="cv"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="text"/>
                <source>
                  <context value="cv"/>
                  <element value="display"/>
                  <variable value="d"/>
                </source>
                <target>
                  <context value="pc"/>
                  <element value="text"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueId value="d"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="chemotherapyLoinc"/>
                <source>
                  <context value="cv"/>
                  <condition value="code = 'anti-cancer-chemotherapy'"/>
                </source>
                <target>
                  <context value="pc"/>
                  <element value="coding"/>
                  <variable value="loinc"/>
                </target>
                <rule>
                  <name value="sys"/>
                  <source>
                    <context value="cv"/>
                  </source>
                  <target>
                    <context value="loinc"/>
                    <element value="system"/>
                    <transform value="copy"/>
                    <parameter>
                      <valueString value="http://loinc.org"/>
                    </parameter>
                  </target>
                </rule>
                <rule>
                  <name value="cd"/>
                  <source>
                    <context value="cv"/>
                  </source>
                  <target>
                    <context value="loinc"/>
                    <element value="code"/>
                    <transform value="copy"/>
                    <parameter>
                      <valueString value="LA6172-6"/>
                    </parameter>
                  </target>
                </rule>
                <rule>
                  <name value="dsp"/>
                  <source>
                    <context value="cv"/>
                  </source>
                  <target>
                    <context value="loinc"/>
                    <element value="display"/>
                    <transform value="copy"/>
                    <parameter>
                      <valueString value="Chemotherapy"/>
                    </parameter>
                  </target>
                </rule>
              </rule>
              <rule>
                <name value="hormonalLoinc"/>
                <source>
                  <context value="cv"/>
                  <condition value="code = 'anti-cancer-hormonal-therapy'"/>
                </source>
                <target>
                  <context value="pc"/>
                  <element value="coding"/>
                  <variable value="loinc"/>
                </target>
                <rule>
                  <name value="sys"/>
                  <source>
                    <context value="cv"/>
                  </source>
                  <target>
                    <context value="loinc"/>
                    <element value="system"/>
                    <transform value="copy"/>
                    <parameter>
                      <valueString value="http://loinc.org"/>
                    </parameter>
                  </target>
                </rule>
                <rule>
                  <name value="cd"/>
                  <source>
                    <context value="cv"/>
                  </source>
                  <target>
                    <context value="loinc"/>
                    <element value="code"/>
                    <transform value="copy"/>
                    <parameter>
                      <valueString value="LA16052-5"/>
                    </parameter>
                  </target>
                </rule>
                <rule>
                  <name value="dsp"/>
                  <source>
                    <context value="cv"/>
                  </source>
                  <target>
                    <context value="loinc"/>
                    <element value="display"/>
                    <transform value="copy"/>
                    <parameter>
                      <valueString value="Hormonal therapy/"/>
                    </parameter>
                  </target>
                </rule>
              </rule>
            </rule>
          </rule>
        </rule>
        <rule>
          <name value="regimenRule"/>
          <source>
            <context value="tg"/>
            <element value="item"/>
            <variable value="it"/>
            <condition
                       value="(linkId = 'treatment/regimen') 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="regimenProvision"/>
              <source>
                <context value="a"/>
                <element value="value"/>
                <variable value="txt"/>
              </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="append"/>
                <parameter>
                  <valueString value="Drug regimen: "/>
                </parameter>
                <parameter>
                  <valueId value="txt"/>
                </parameter>
              </target>
            </rule>
          </rule>
        </rule>
        <rule>
          <name value="diagnosisRule"/>
          <source>
            <context value="tg"/>
            <element value="item"/>
            <variable value="it"/>
            <condition
                       value="(linkId = 'treatment/diagnosis') 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="diagnosisProvision"/>
              <source>
                <context value="a"/>
                <element value="value"/>
                <variable value="txt"/>
              </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="append"/>
                <parameter>
                  <valueString value="Diagnosis explained: "/>
                </parameter>
                <parameter>
                  <valueId value="txt"/>
                </parameter>
              </target>
            </rule>
          </rule>
        </rule>
        <rule>
          <name value="purposeRule"/>
          <source>
            <context value="tg"/>
            <element value="item"/>
            <variable value="it"/>
            <condition
                       value="(linkId = 'treatment/intended-purpose') 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="purposeProvision"/>
              <source>
                <context value="a"/>
                <element value="value"/>
                <variable value="txt"/>
              </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="append"/>
                <parameter>
                  <valueString value="Intended purpose explained: "/>
                </parameter>
                <parameter>
                  <valueId value="txt"/>
                </parameter>
              </target>
            </rule>
          </rule>
        </rule>
        <rule>
          <name value="sideEffectsRule"/>
          <source>
            <context value="tg"/>
            <element value="item"/>
            <variable value="it"/>
            <condition
                       value="(linkId = 'treatment/side-effects-and-risks') 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="sideEffectsProvision"/>
              <source>
                <context value="a"/>
                <element value="value"/>
                <variable value="txt"/>
              </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="append"/>
                <parameter>
                  <valueString value="Side effects and risks explained: "/>
                </parameter>
                <parameter>
                  <valueId value="txt"/>
                </parameter>
              </target>
            </rule>
          </rule>
        </rule>
        <documentation
                       value="── The provisions ────────────────────────────────────────────────────
One per kind of therapy ticked, so a consent to hormonal therapy cannot
be read as covering chemotherapy. The local code is what the form
offered; the LOINC answer code beside it is what another system will
recognise, and LOINC is what SGHIConsent binds provision.code to
(consent-content-code, required). Both LOINC codes come from LOINC's
own list of cancer treatments, LL1479-6, and the display is LOINC's to
the letter, trailing slash included. LOINC has no code for targeted
therapy, so that one carries the local code alone.
The regimen and what was explained are provisions too, each labelled.
Consent has no note in R5, and this is where the procedure consent puts
the same prose."/>
      </rule>
      <documentation
                     value="── The Consent ─────────────────────────────────────────────────────────
Guarded on the patient having signed, as the procedure consent is on the
consenter. A Consent built from a form nobody signed asserts a permission
that was never given."/>
    </rule>
  </group>
  <group>
    <name value="BuildConsentBase"/>
    <documentation
                   value="─────────────────────────────────────────────────────────────────────────────
Shared scaffolding. Repeated in each map rather than imported: the transform
engine resolves `imports` against whatever StructureMaps happen to be on the
server, and a form that stops extracting because a shared map was not
uploaded is a worse failure than a duplicated group.
─────────────────────────────────────────────────────────────────────────────"/>
    <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="linkQuestionnaireResponse"/>
      <source>
        <context value="qr"/>
        <element value="id"/>
        <variable value="qid"/>
        <condition value="$this.hasValue()"/>
      </source>
      <target>
        <context value="r"/>
        <element value="sourceReference"/>
        <variable value="srcRef"/>
        <transform value="create"/>
        <parameter>
          <valueString value="Reference"/>
        </parameter>
      </target>
      <target>
        <context value="srcRef"/>
        <element value="reference"/>
        <transform value="copy"/>
        <parameter>
          <valueId value="qid"/>
        </parameter>
      </target>
    </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"/>
        <condition
                   value="(reference.exists() and (reference.startsWith('Patient/'))) or (reference.empty() and (type.empty() or ('/' + type).endsWith('/Patient')))"/>
      </source>
      <target>
        <context value="r"/>
        <element value="subject"/>
        <transform value="copy"/>
        <parameter>
          <valueId value="s"/>
        </parameter>
      </target>
    </rule>
    <rule>
      <name value="profileConformance"/>
      <source>
        <context value="qr"/>
      </source>
      <target>
        <context value="r"/>
      </target>
      <dependent>
        <name value="ConformConsent"/>
        <parameter>
          <valueId value="qr"/>
        </parameter>
        <parameter>
          <valueId value="r"/>
        </parameter>
      </dependent>
    </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="SetResponseProvenance"/>
    <documentation
                   value="── Provenance and tenancy ───────────────────────────────────────────────────
Two tags on everything this map creates. The first says which questionnaire
produced it, so a form that reopens mid-admission recalls its own earlier
entries and not another form's. The second copies the tenant tags off the
response, because nothing else on the path puts them there. The response's
identifier is copied the same way.
The code is the form's document type, not the questionnaire's id: every
environment mints its own ids, and there is only one set of maps, so an id
here would tie the tag to whichever environment stamped it.
── Provenance and tenancy ───────────────────────────────────────────────────"/>
    <input>
      <name value="qr"/>
      <type value="QR"/>
      <mode value="source"/>
    </input>
    <input>
      <name value="r"/>
      <mode value="target"/>
    </input>
    <rule>
      <name value="provenanceMeta"/>
      <source>
        <context value="qr"/>
      </source>
      <target>
        <context value="r"/>
        <element value="meta"/>
        <variable value="m"/>
      </target>
      <rule>
        <name value="provenanceTag"/>
        <source>
          <context value="qr"/>
        </source>
        <target>
          <context value="m"/>
          <element value="tag"/>
          <variable value="t"/>
        </target>
        <rule>
          <name value="provenanceSystem"/>
          <source>
            <context value="qr"/>
          </source>
          <target>
            <context value="t"/>
            <element value="system"/>
            <transform value="copy"/>
            <parameter>
              <valueString
                           value="http://slade360edi.com/questionnaire-provenance"/>
            </parameter>
          </target>
        </rule>
        <rule>
          <name value="provenanceCode"/>
          <source>
            <context value="qr"/>
          </source>
          <target>
            <context value="t"/>
            <element value="code"/>
            <transform value="copy"/>
            <parameter>
              <valueString value="cancer-treatment-consent"/>
            </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="Cancer centre informed consent"/>
            </parameter>
          </target>
        </rule>
      </rule>
    </rule>
    <rule>
      <name value="tenantTags"/>
      <source>
        <context value="qr"/>
        <element value="meta"/>
        <variable value="qm"/>
      </source>
      <rule>
        <name value="copyTag"/>
        <source>
          <context value="qm"/>
          <element value="tag"/>
          <variable value="qt"/>
        </source>
        <target>
          <context value="r"/>
          <element value="meta"/>
          <variable value="m"/>
        </target>
        <target>
          <context value="m"/>
          <element value="tag"/>
          <transform value="copy"/>
          <parameter>
            <valueId value="qt"/>
          </parameter>
        </target>
      </rule>
      <documentation
                     value="Every tag the response carries, onto the resource. `meta` is 0..1, so this
lands on the same meta the rule above created rather than a second one."/>
    </rule>
    <rule>
      <name value="identifier"/>
      <source>
        <context value="qr"/>
        <element value="identifier"/>
        <variable value="qid"/>
        <condition
                   value="assigner.empty() or assigner.where(((reference.exists() and (reference.startsWith('Organization/'))) or (reference.empty() and (type.empty() or ('/' + type).endsWith('/Organization'))))).exists()"/>
      </source>
      <target>
        <context value="r"/>
        <element value="identifier"/>
        <transform value="copy"/>
        <parameter>
          <valueId value="qid"/>
        </parameter>
      </target>
      <documentation
                     value="The response's identifiers, as they are. Every profile wants one, and it is
the response's to give: nothing here mints one, so a response without an
identifier extracts resources without one. One whose assigner is not of a
type the profiles allow there is left behind whole, not altered."/>
    </rule>
  </group>
  <group>
    <name value="ConformConsent"/>
    <documentation
                   value="── Conformance to the IG profiles ───────────────────────────────────────────
What the IG's profiles require that the response itself can supply. Called at
the end of each base group. The encounter and every who-element are the
response's own; see mapmeta.py for what is and is not here.
── Conformance to the IG profiles ───────────────────────────────────────────"/>
    <input>
      <name value="qr"/>
      <type value="QR"/>
      <mode value="source"/>
    </input>
    <input>
      <name value="r"/>
      <mode value="target"/>
    </input>
    <rule>
      <name value="date"/>
      <source>
        <context value="qr"/>
        <element value="authored"/>
        <variable value="t"/>
      </source>
      <target>
        <variable value="day"/>
        <transform value="evaluate"/>
        <parameter>
          <valueId value="t"/>
        </parameter>
        <parameter>
          <valueString value="$this.toString().substring(0, 10)"/>
        </parameter>
      </target>
      <target>
        <context value="r"/>
        <element value="date"/>
        <transform value="cast"/>
        <parameter>
          <valueId value="day"/>
        </parameter>
        <parameter>
          <valueString value="date"/>
        </parameter>
      </target>
    </rule>
    <rule>
      <name value="granteeFromAuthor"/>
      <source>
        <context value="qr"/>
        <element value="author"/>
        <variable value="au"/>
        <condition
                   value="(reference.exists() and (reference.startsWith('Organization/') or reference.startsWith('Practitioner/') or reference.startsWith('PractitionerRole/'))) or (reference.empty() and (type.empty() or ('/' + type).endsWith('/Organization') or ('/' + type).endsWith('/Practitioner') or ('/' + type).endsWith('/PractitionerRole')))"/>
      </source>
      <target>
        <context value="r"/>
        <element value="grantee"/>
        <transform value="copy"/>
        <parameter>
          <valueId value="au"/>
        </parameter>
      </target>
    </rule>
    <rule>
      <name value="granteeFallback"/>
      <source>
        <context value="qr"/>
        <condition
                   value="author.where(((reference.exists() and (reference.startsWith('Organization/') or reference.startsWith('Practitioner/') or reference.startsWith('PractitionerRole/'))) or (reference.empty() and (type.empty() or ('/' + type).endsWith('/Organization') or ('/' + type).endsWith('/Practitioner') or ('/' + type).endsWith('/PractitionerRole'))))).exists().not()"/>
      </source>
      <rule>
        <name value="granteeFromSource"/>
        <source>
          <context value="qr"/>
          <element value="source"/>
          <variable value="src"/>
          <condition
                     value="(reference.exists() and (reference.startsWith('Organization/') or reference.startsWith('Practitioner/') or reference.startsWith('PractitionerRole/'))) or (reference.empty() and (type.empty() or ('/' + type).endsWith('/Organization') or ('/' + type).endsWith('/Practitioner') or ('/' + type).endsWith('/PractitionerRole')))"/>
        </source>
        <target>
          <context value="r"/>
          <element value="grantee"/>
          <transform value="copy"/>
          <parameter>
            <valueId value="src"/>
          </parameter>
        </target>
      </rule>
    </rule>
  </group>
</StructureMap>