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 - TTL Representation

Active as of 2026-10-06

Raw ttl | Download

@prefix fhir: <http://hl7.org/fhir/> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

# - resource -------------------------------------------------------------------

<http://hl7.org/fhir/StructureMap/ExtractCancerTreatmentConsent> a fhir:StructureMap ;
  fhir:nodeRole fhir:treeRoot ;
  fhir:id [ fhir:v "ExtractCancerTreatmentConsent"] ; # 
  fhir:text [
     fhir:status [ fhir:v "generated" ] ;
     fhir:div [ fhir:v "<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\">\r\n<span style=\"color: #cc00cc\">/// <b>url</b> = </span><span style=\"color: blue\">'https://fhir.slade360.co.ke/fhir/StructureMap/ExtractCancerTreatmentConsent'</span>\r\n<span style=\"color: #cc00cc\">/// <b>name</b> = </span><span style=\"color: blue\">'ExtractCancerTreatmentConsent'</span>\r\n<span style=\"color: #cc00cc\">/// <b>title</b> = </span><span style=\"color: blue\">'Cancer Treatment Consent Extraction'</span>\r\n<span style=\"color: #cc00cc\">/// <b>status</b> = </span><span style=\"color: blue\">'active'</span>\r\n<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>\r\n\r\n<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>\r\n<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>\r\n<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>\r\n\r\n<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\"> {\r\n</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>\r\n  <span style=\"color: navy\">// </span><span style=\"color: green\">── The Consent ─────────────────────────────────────────────────────────</span>\r\n  <span style=\"color: navy\">// </span><span style=\"color: green\">Guarded on the patient having signed, as the procedure consent is on the</span>\r\n  <span style=\"color: navy\">// </span><span style=\"color: green\">consenter. A Consent built from a form nobody signed asserts a permission</span>\r\n  <span style=\"color: navy\">// </span><span style=\"color: green\">that was never given.</span>\r\n  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\"> {\r\n</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>\r\n    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>\r\n    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>\r\n    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\"> {\r\n</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\"> {\r\n</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>\r\n        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>\r\n        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>\r\n      <span style=\"color: navy\">}</span> <i>&quot;coding&quot;</i><span style=\"color: navy\">;</span>\r\n      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>\r\n    <span style=\"color: navy\">}</span> <i>&quot;category&quot;</i><span style=\"color: navy\">;</span>\r\n    <span style=\"color: navy\">// </span><span style=\"color: green\">The patient consents for themselves: the form has no line for anyone</span>\r\n    <span style=\"color: navy\">// </span><span style=\"color: green\">else to sign on their behalf.</span>\r\n    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>\r\n    <span style=\"color: navy\">// </span><span style=\"color: green\">The grantees are both parties to the consent: the patient, written here and only</span>\r\n    <span style=\"color: navy\">// </span><span style=\"color: green\">when the subject is one, and the practitioner who recorded it, the response's</span>\r\n    <span style=\"color: navy\">// </span><span style=\"color: green\">author, which ConformConsent adds. The stamped copy never names the patient</span>\r\n    <span style=\"color: navy\">// </span><span style=\"color: green\">itself; see mapmeta's WHO_NEVER.</span>\r\n    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>\r\n    <span style=\"color: navy\">// </span><span style=\"color: green\">The signing time, from the form, not qr.authored. Consent.date is a</span>\r\n    <span style=\"color: navy\">// </span><span style=\"color: green\">`date` and this is a date and time, so it goes to period.start.</span>\r\n    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\"> {\r\n</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\"> {\r\n</span>        it.answer first<b> as </b><span style=\"color: maroon\">a</span><b> then</b><span style=\"color: navy\"> {\r\n</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>\r\n        <span style=\"color: navy\">}</span><span style=\"color: navy\">;</span>\r\n      <span style=\"color: navy\">}</span> <i>&quot;signedAtRule&quot;</i><span style=\"color: navy\">;</span>\r\n    <span style=\"color: navy\">}</span> <i>&quot;patientGroup&quot;</i><span style=\"color: navy\">;</span>\r\n    <span style=\"color: navy\">// </span><span style=\"color: green\">── The verifications ─────────────────────────────────────────────────</span>\r\n    <span style=\"color: navy\">// </span><span style=\"color: green\">The doctor's, and the interpreter's when one was used.</span>\r\n    <span style=\"color: navy\">// </span><span style=\"color: green\">The doctor who explained the treatment is the response's author. The form</span>\r\n    <span style=\"color: navy\">// </span><span style=\"color: green\">stopped asking for the doctor's name, designation and signature on</span>\r\n    <span style=\"color: navy\">// </span><span style=\"color: green\">2026-10-06, because whoever records the consent is that doctor. So the</span>\r\n    <span style=\"color: navy\">// </span><span style=\"color: green\">verification is made when the response has an author who is a person, a</span>\r\n    <span style=\"color: navy\">// </span><span style=\"color: green\">Practitioner or a PractitionerRole (an Organization is not a doctor), and</span>\r\n    <span style=\"color: navy\">// </span><span style=\"color: green\">it is verified by them: recording the form is their attestation. No such</span>\r\n    <span style=\"color: navy\">// </span><span style=\"color: green\">author, no doctor's verification. Dated with the patient's signing, the</span>\r\n    <span style=\"color: navy\">// </span><span style=\"color: green\">only time the form records.</span>\r\n    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\"> {\r\n</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>\r\n      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\"> {\r\n</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\"> {\r\n</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>\r\n          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>\r\n          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>\r\n        <span style=\"color: navy\">}</span> <i>&quot;coding&quot;</i><span style=\"color: navy\">;</span>\r\n        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>\r\n      <span style=\"color: navy\">}</span> <i>&quot;doctorVerificationType&quot;</i><span style=\"color: navy\">;</span>\r\n      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>\r\n      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>\r\n      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\"> {\r\n</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\"> {\r\n</span>          st.answer first<b> as </b><span style=\"color: maroon\">sa</span><b> then</b><span style=\"color: navy\"> {\r\n</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>\r\n          <span style=\"color: navy\">}</span> <i>&quot;signedAtAnswer&quot;</i><span style=\"color: navy\">;</span>\r\n        <span style=\"color: navy\">}</span> <i>&quot;signedAtRule&quot;</i><span style=\"color: navy\">;</span>\r\n      <span style=\"color: navy\">}</span> <i>&quot;patientGroupForVerification&quot;</i><span style=\"color: navy\">;</span>\r\n    <span style=\"color: navy\">}</span> <i>&quot;doctorVerification&quot;</i><span style=\"color: navy\">;</span>\r\n    <span style=\"color: navy\">// </span><span style=\"color: green\">The interpreter, if one was used: whether the explanation reached the patient</span>\r\n    <span style=\"color: navy\">// </span><span style=\"color: green\">in a language they understood is what makes the consent informed. Verified</span>\r\n    <span style=\"color: navy\">// </span><span style=\"color: green\">when they have signed. It names no verifier, because the interpreter is a name</span>\r\n    <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>\r\n    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\"> {\r\n</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\"> {\r\n</span>        it.answer first<b> as </b><span style=\"color: maroon\">a</span><b> then</b><span style=\"color: navy\"> {\r\n</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\"> {\r\n</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>\r\n            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\"> {\r\n</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>\r\n            <span style=\"color: navy\">}</span> <i>&quot;interpreterSignedRule&quot;</i><span style=\"color: navy\">;</span>\r\n            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\"> {\r\n</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\"> {\r\n</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>\r\n                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>\r\n                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>\r\n              <span style=\"color: navy\">}</span> <i>&quot;coding&quot;</i><span style=\"color: navy\">;</span>\r\n              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>\r\n            <span style=\"color: navy\">}</span> <i>&quot;interpreterVerificationType&quot;</i><span style=\"color: navy\">;</span>\r\n            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>\r\n            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\"> {\r\n</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\"> {\r\n</span>                st.answer first<b> as </b><span style=\"color: maroon\">sa</span><b> then</b><span style=\"color: navy\"> {\r\n</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>\r\n                <span style=\"color: navy\">}</span> <i>&quot;signedAtAnswer&quot;</i><span style=\"color: navy\">;</span>\r\n              <span style=\"color: navy\">}</span> <i>&quot;signedAtRule&quot;</i><span style=\"color: navy\">;</span>\r\n            <span style=\"color: navy\">}</span> <i>&quot;patientGroupForInterpreter&quot;</i><span style=\"color: navy\">;</span>\r\n          <span style=\"color: navy\">}</span> <i>&quot;interpreterVerification&quot;</i><span style=\"color: navy\">;</span>\r\n        <span style=\"color: navy\">}</span><span style=\"color: navy\">;</span>\r\n      <span style=\"color: navy\">}</span> <i>&quot;nameRule&quot;</i><span style=\"color: navy\">;</span>\r\n    <span style=\"color: navy\">}</span> <i>&quot;interpreterGroup&quot;</i><span style=\"color: navy\">;</span>\r\n    <span style=\"color: navy\">// </span><span style=\"color: green\">── The provisions ────────────────────────────────────────────────────</span>\r\n    <span style=\"color: navy\">// </span><span style=\"color: green\">One per kind of therapy ticked, so a consent to hormonal therapy cannot</span>\r\n    <span style=\"color: navy\">// </span><span style=\"color: green\">be read as covering chemotherapy. The local code is what the form</span>\r\n    <span style=\"color: navy\">// </span><span style=\"color: green\">offered; the LOINC answer code beside it is what another system will</span>\r\n    <span style=\"color: navy\">// </span><span style=\"color: green\">recognise, and LOINC is what SGHIConsent binds provision.code to</span>\r\n    <span style=\"color: navy\">// </span><span style=\"color: green\">(consent-content-code, required). Both LOINC codes come from LOINC's</span>\r\n    <span style=\"color: navy\">// </span><span style=\"color: green\">own list of cancer treatments, LL1479-6, and the display is LOINC's to</span>\r\n    <span style=\"color: navy\">// </span><span style=\"color: green\">the letter, trailing slash included. LOINC has no code for targeted</span>\r\n    <span style=\"color: navy\">// </span><span style=\"color: green\">therapy, so that one carries the local code alone.</span>\r\n    <span style=\"color: navy\">// </span><span style=\"color: green\">The regimen and what was explained are provisions too, each labelled.</span>\r\n    <span style=\"color: navy\">// </span><span style=\"color: green\">Consent has no note in R5, and this is where the procedure consent puts</span>\r\n    <span style=\"color: navy\">// </span><span style=\"color: green\">the same prose.</span>\r\n    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\"> {\r\n</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\"> {\r\n</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\"> {\r\n</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\"> {\r\n</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>\r\n            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>\r\n            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\"> {\r\n</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>\r\n              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>\r\n              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>\r\n            <span style=\"color: navy\">}</span> <i>&quot;chemotherapyLoinc&quot;</i><span style=\"color: navy\">;</span>\r\n            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\"> {\r\n</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>\r\n              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>\r\n              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>\r\n            <span style=\"color: navy\">}</span> <i>&quot;hormonalLoinc&quot;</i><span style=\"color: navy\">;</span>\r\n          <span style=\"color: navy\">}</span> <i>&quot;therapyCode&quot;</i><span style=\"color: navy\">;</span>\r\n        <span style=\"color: navy\">}</span> <i>&quot;therapyProvision&quot;</i><span style=\"color: navy\">;</span>\r\n      <span style=\"color: navy\">}</span> <i>&quot;therapyRule&quot;</i><span style=\"color: navy\">;</span>\r\n      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\"> {\r\n</span>        it.answer first<b> as </b><span style=\"color: maroon\">a</span><b> then</b><span style=\"color: navy\"> {\r\n</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>\r\n        <span style=\"color: navy\">}</span><span style=\"color: navy\">;</span>\r\n      <span style=\"color: navy\">}</span> <i>&quot;regimenRule&quot;</i><span style=\"color: navy\">;</span>\r\n      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\"> {\r\n</span>        it.answer first<b> as </b><span style=\"color: maroon\">a</span><b> then</b><span style=\"color: navy\"> {\r\n</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>\r\n        <span style=\"color: navy\">}</span><span style=\"color: navy\">;</span>\r\n      <span style=\"color: navy\">}</span> <i>&quot;diagnosisRule&quot;</i><span style=\"color: navy\">;</span>\r\n      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\"> {\r\n</span>        it.answer first<b> as </b><span style=\"color: maroon\">a</span><b> then</b><span style=\"color: navy\"> {\r\n</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>\r\n        <span style=\"color: navy\">}</span><span style=\"color: navy\">;</span>\r\n      <span style=\"color: navy\">}</span> <i>&quot;purposeRule&quot;</i><span style=\"color: navy\">;</span>\r\n      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\"> {\r\n</span>        it.answer first<b> as </b><span style=\"color: maroon\">a</span><b> then</b><span style=\"color: navy\"> {\r\n</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>\r\n        <span style=\"color: navy\">}</span><span style=\"color: navy\">;</span>\r\n      <span style=\"color: navy\">}</span> <i>&quot;sideEffectsRule&quot;</i><span style=\"color: navy\">;</span>\r\n    <span style=\"color: navy\">}</span> <i>&quot;treatmentGroup&quot;</i><span style=\"color: navy\">;</span>\r\n  <span style=\"color: navy\">}</span> <i>&quot;createConsent&quot;</i><span style=\"color: navy\">;</span>\r\n<span style=\"color: navy\">}\r\n\r\n</span><span style=\"color: navy\">// </span><span style=\"color: green\">─────────────────────────────────────────────────────────────────────────────</span>\r\n<span style=\"color: navy\">// </span><span style=\"color: green\">Shared scaffolding. Repeated in each map rather than imported: the transform</span>\r\n<span style=\"color: navy\">// </span><span style=\"color: green\">engine resolves `imports` against whatever StructureMaps happen to be on the</span>\r\n<span style=\"color: navy\">// </span><span style=\"color: green\">server, and a form that stops extracting because a shared map was not</span>\r\n<span style=\"color: navy\">// </span><span style=\"color: green\">uploaded is a worse failure than a duplicated group.</span>\r\n<span style=\"color: navy\">// </span><span style=\"color: green\">─────────────────────────────────────────────────────────────────────────────</span>\r\n<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\"> {\r\n</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>\r\n  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>\r\n  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>\r\n  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\"> {\r\n</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>\r\n    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>\r\n  <span style=\"color: navy\">}</span> <i>&quot;entryRequest&quot;</i><span style=\"color: navy\">;</span>\r\n  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>\r\n  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>\r\n<span style=\"color: navy\">}\r\n\r\n</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\"> {\r\n</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>\r\n<span style=\"color: navy\">}\r\n\r\n</span><span style=\"color: navy\">// </span><span style=\"color: green\">── Provenance and tenancy ───────────────────────────────────────────────────</span>\r\n<span style=\"color: navy\">// </span><span style=\"color: green\">Two tags on everything this map creates. The first says which questionnaire</span>\r\n<span style=\"color: navy\">// </span><span style=\"color: green\">produced it, so a form that reopens mid-admission recalls its own earlier</span>\r\n<span style=\"color: navy\">// </span><span style=\"color: green\">entries and not another form's. The second copies the tenant tags off the</span>\r\n<span style=\"color: navy\">// </span><span style=\"color: green\">response, because nothing else on the path puts them there. The response's</span>\r\n<span style=\"color: navy\">// </span><span style=\"color: green\">identifier is copied the same way.</span>\r\n<span style=\"color: navy\">// </span><span style=\"color: green\">The code is the form's document type, not the questionnaire's id: every</span>\r\n<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>\r\n<span style=\"color: navy\">// </span><span style=\"color: green\">here would tie the tag to whichever environment stamped it.</span>\r\n<span style=\"color: navy\">// </span><span style=\"color: green\">── Provenance and tenancy ───────────────────────────────────────────────────</span>\r\n<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\"> {\r\n</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\"> {\r\n</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\"> {\r\n</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>\r\n      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>\r\n      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>\r\n    <span style=\"color: navy\">}</span> <i>&quot;provenanceTag&quot;</i><span style=\"color: navy\">;</span>\r\n  <span style=\"color: navy\">}</span> <i>&quot;provenanceMeta&quot;</i><span style=\"color: navy\">;</span>\r\n  <span style=\"color: navy\">// </span><span style=\"color: green\">Every tag the response carries, onto the resource. `meta` is 0..1, so this</span>\r\n  <span style=\"color: navy\">// </span><span style=\"color: green\">lands on the same meta the rule above created rather than a second one.</span>\r\n  qr.meta<b> as </b><span style=\"color: maroon\">qm</span><b> then</b><span style=\"color: navy\"> {\r\n</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>\r\n  <span style=\"color: navy\">}</span> <i>&quot;tenantTags&quot;</i><span style=\"color: navy\">;</span>\r\n  <span style=\"color: navy\">// </span><span style=\"color: green\">The response's identifiers, as they are. Every profile wants one, and it is</span>\r\n  <span style=\"color: navy\">// </span><span style=\"color: green\">the response's to give: nothing here mints one, so a response without an</span>\r\n  <span style=\"color: navy\">// </span><span style=\"color: green\">identifier extracts resources without one. One whose assigner is not of a</span>\r\n  <span style=\"color: navy\">// </span><span style=\"color: green\">type the profiles allow there is left behind whole, not altered.</span>\r\n  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>\r\n<span style=\"color: navy\">}\r\n\r\n</span><span style=\"color: navy\">// </span><span style=\"color: green\">── Conformance to the IG profiles ───────────────────────────────────────────</span>\r\n<span style=\"color: navy\">// </span><span style=\"color: green\">What the IG's profiles require that the response itself can supply. Called at</span>\r\n<span style=\"color: navy\">// </span><span style=\"color: green\">the end of each base group. The encounter and every who-element are the</span>\r\n<span style=\"color: navy\">// </span><span style=\"color: green\">response's own; see mapmeta.py for what is and is not here.</span>\r\n<span style=\"color: navy\">// </span><span style=\"color: green\">── Conformance to the IG profiles ───────────────────────────────────────────</span>\r\n<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\"> {\r\n</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>\r\n  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>\r\n  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\"> {\r\n</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>\r\n  <span style=\"color: navy\">}</span> <i>&quot;granteeFallback&quot;</i><span style=\"color: navy\">;</span>\r\n<span style=\"color: navy\">}\r\n\r\n</span></pre></div>"^^rdf:XMLLiteral ]
  ] ; # 
  fhir:url [ fhir:v "https://fhir.slade360.co.ke/fhir/StructureMap/ExtractCancerTreatmentConsent"^^xsd:anyURI] ; # 
  fhir:version [ fhir:v "0.1.0"] ; # 
  fhir:name [ fhir:v "ExtractCancerTreatmentConsent"] ; # 
  fhir:title [ fhir:v "Cancer Treatment Consent Extraction"] ; # 
  fhir:status [ fhir:v "active"] ; # 
  fhir:date [ fhir:v "2026-10-06T18:48:22+00:00"^^xsd:dateTime] ; # 
  fhir:publisher [ fhir:v "Kathurima Kimathi"] ; # 
  fhir:contact ( [
     fhir:name [ fhir:v "Kathurima Kimathi" ] ;
     fhir:telecom ( [
       fhir:system [ fhir:v "url" ] ;
       fhir:value [ fhir:v "https://www.linkedin.com/in/kathurima-kimathi/" ]
     ] [
       fhir:system [ fhir:v "email" ] ;
       fhir:value [ fhir:v "kathurimakimathi415@gmail.com" ]
     ] )
  ] [
     fhir:name [ fhir:v "Oscar John" ] ;
     fhir:telecom ( [
       fhir:system [ fhir:v "email" ] ;
       fhir:value [ fhir:v "oscarjohnotieno@gmail.com" ] ;
       fhir:use [ fhir:v "work" ]
     ] )
  ] [
     fhir:name [ fhir:v "Kennedy Omondi" ] ;
     fhir:telecom ( [
       fhir:system [ fhir:v "email" ] ;
       fhir:value [ fhir:v "kennankole@gmail.com" ] ;
       fhir:use [ fhir:v "work" ]
     ] )
  ] ) ; # 
  fhir:description [ fhir:v "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."] ; # 
  fhir:structure ( [
     fhir:url [
       fhir:v "http://hl7.org/fhir/StructureDefinition/QuestionnaireResponse"^^xsd:anyURI ;
       fhir:link <http://hl7.org/fhir/StructureDefinition/QuestionnaireResponse>
     ] ;
     fhir:mode [ fhir:v "source" ] ;
     fhir:alias [ fhir:v "QR" ]
  ] [
     fhir:url [
       fhir:v "http://hl7.org/fhir/StructureDefinition/Bundle"^^xsd:anyURI ;
       fhir:link <http://hl7.org/fhir/StructureDefinition/Bundle>
     ] ;
     fhir:mode [ fhir:v "target" ] ;
     fhir:alias [ fhir:v "Bundle" ]
  ] [
     fhir:url [
       fhir:v "http://hl7.org/fhir/StructureDefinition/Consent"^^xsd:anyURI ;
       fhir:link <http://hl7.org/fhir/StructureDefinition/Consent>
     ] ;
     fhir:mode [ fhir:v "target" ] ;
     fhir:alias [ fhir:v "Consent" ]
  ] ) ; # 
  fhir:group ( [
     fhir:name [ fhir:v "ExtractCancerTreatmentConsent" ] ;
     fhir:input ( [
       fhir:name [ fhir:v "qr" ] ;
       fhir:type [ fhir:v "QR" ] ;
       fhir:mode [ fhir:v "source" ]
     ] [
       fhir:name [ fhir:v "bundle" ] ;
       fhir:type [ fhir:v "Bundle" ] ;
       fhir:mode [ fhir:v "target" ]
     ] ) ;
     fhir:rule ( [
       fhir:name [ fhir:v "setBundleType" ] ;
       fhir:source ( [
         fhir:context [ fhir:v "qr" ]
       ] ) ;
       fhir:target ( [
         fhir:context [ fhir:v "bundle" ] ;
         fhir:element [ fhir:v "type" ] ;
         fhir:transform [ fhir:v "copy" ] ;
         fhir:parameter ( [
           fhir:value [
             a fhir:string ;
             fhir:v "transaction"
           ]
         ] )
       ] )
     ] [
       fhir:name [ fhir:v "createConsent" ] ;
       fhir:source ( [
         fhir:context [ fhir:v "qr" ] ;
         fhir:condition [ fhir:v "item.where(linkId = 'patient').item.where(linkId = 'patient/signed').answer.value = true" ]
       ] ) ;
       fhir:target ( [
         fhir:context [ fhir:v "bundle" ] ;
         fhir:element [ fhir:v "entry" ] ;
         fhir:variable [ fhir:v "entry" ]
       ] [
         fhir:context [ fhir:v "entry" ] ;
         fhir:element [ fhir:v "resource" ] ;
         fhir:variable [ fhir:v "consent" ] ;
         fhir:transform [ fhir:v "create" ] ;
         fhir:parameter ( [
           fhir:value [
             a fhir:string ;
             fhir:v "Consent"
           ]
         ] )
       ] ) ;
       fhir:rule ( [
         fhir:name [ fhir:v "base" ] ;
         fhir:source ( [
           fhir:context [ fhir:v "qr" ]
         ] ) ;
         fhir:target ( [
           fhir:context [ fhir:v "consent" ]
         ] [
           fhir:context [ fhir:v "entry" ]
         ] ) ;
         fhir:dependent ( [
           fhir:name [ fhir:v "BuildConsentBase" ] ;
           fhir:parameter ( [
             fhir:value [
               a fhir:id ;
               fhir:v "qr"
             ]
           ] [
             fhir:value [
               a fhir:id ;
               fhir:v "consent"
             ]
           ] [
             fhir:value [
               a fhir:id ;
               fhir:v "entry"
             ]
           ] )
         ] )
       ] [
         fhir:name [ fhir:v "status" ] ;
         fhir:source ( [
           fhir:context [ fhir:v "qr" ]
         ] ) ;
         fhir:target ( [
           fhir:context [ fhir:v "consent" ] ;
           fhir:element [ fhir:v "status" ] ;
           fhir:transform [ fhir:v "copy" ] ;
           fhir:parameter ( [
             fhir:value [
               a fhir:string ;
               fhir:v "active"
             ]
           ] )
         ] )
       ] [
         fhir:name [ fhir:v "decision" ] ;
         fhir:source ( [
           fhir:context [ fhir:v "qr" ]
         ] ) ;
         fhir:target ( [
           fhir:context [ fhir:v "consent" ] ;
           fhir:element [ fhir:v "decision" ] ;
           fhir:transform [ fhir:v "copy" ] ;
           fhir:parameter ( [
             fhir:value [
               a fhir:string ;
               fhir:v "permit"
             ]
           ] )
         ] )
       ] [
         fhir:name [ fhir:v "category" ] ;
         fhir:source ( [
           fhir:context [ fhir:v "qr" ]
         ] ) ;
         fhir:target ( [
           fhir:context [ fhir:v "consent" ] ;
           fhir:element [ fhir:v "category" ] ;
           fhir:variable [ fhir:v "cat" ]
         ] ) ;
         fhir:rule ( [
           fhir:name [ fhir:v "coding" ] ;
           fhir:source ( [
             fhir:context [ fhir:v "qr" ]
           ] ) ;
           fhir:target ( [
             fhir:context [ fhir:v "cat" ] ;
             fhir:element [ fhir:v "coding" ] ;
             fhir:variable [ fhir:v "cg" ]
           ] ) ;
           fhir:rule ( [
             fhir:name [ fhir:v "sys" ] ;
             fhir:source ( [
               fhir:context [ fhir:v "qr" ]
             ] ) ;
             fhir:target ( [
               fhir:context [ fhir:v "cg" ] ;
               fhir:element [ fhir:v "system" ] ;
               fhir:transform [ fhir:v "copy" ] ;
               fhir:parameter ( [
                 fhir:value [
                   a fhir:string ;
                   fhir:v "http://loinc.org"
                 ]
               ] )
             ] )
           ] [
             fhir:name [ fhir:v "cd" ] ;
             fhir:source ( [
               fhir:context [ fhir:v "qr" ]
             ] ) ;
             fhir:target ( [
               fhir:context [ fhir:v "cg" ] ;
               fhir:element [ fhir:v "code" ] ;
               fhir:transform [ fhir:v "copy" ] ;
               fhir:parameter ( [
                 fhir:value [
                   a fhir:string ;
                   fhir:v "64293-4"
                 ]
               ] )
             ] )
           ] [
             fhir:name [ fhir:v "dsp" ] ;
             fhir:source ( [
               fhir:context [ fhir:v "qr" ]
             ] ) ;
             fhir:target ( [
               fhir:context [ fhir:v "cg" ] ;
               fhir:element [ fhir:v "display" ] ;
               fhir:transform [ fhir:v "copy" ] ;
               fhir:parameter ( [
                 fhir:value [
                   a fhir:string ;
                   fhir:v "Procedure consent Document"
                 ]
               ] )
             ] )
           ] )
         ] [
           fhir:name [ fhir:v "categoryText" ] ;
           fhir:source ( [
             fhir:context [ fhir:v "qr" ]
           ] ) ;
           fhir:target ( [
             fhir:context [ fhir:v "cat" ] ;
             fhir:element [ fhir:v "text" ] ;
             fhir:transform [ fhir:v "copy" ] ;
             fhir:parameter ( [
               fhir:value [
                 a fhir:string ;
                 fhir:v "Consent to systemic anti-cancer therapy"
               ]
             ] )
           ] )
         ] )
       ] [
         fhir:name [ fhir:v "grantorPatient" ] ;
         fhir:source ( [
           fhir:context [ fhir:v "qr" ] ;
           fhir:element [ fhir:v "subject" ] ;
           fhir:variable [ fhir:v "s" ] ;
           fhir:condition [ fhir:v "(reference.exists() and (reference.startsWith('Organization/') or reference.startsWith('Patient/'))) or (reference.empty() and (type.empty() or ('/' + type).endsWith('/Organization') or ('/' + type).endsWith('/Patient')))" ]
         ] ) ;
         fhir:target ( [
           fhir:context [ fhir:v "consent" ] ;
           fhir:element [ fhir:v "grantor" ] ;
           fhir:transform [ fhir:v "copy" ] ;
           fhir:parameter ( [
             fhir:value [
               a fhir:id ;
               fhir:v "s"
             ]
           ] )
         ] ) ;
         fhir:documentation [ fhir:v "The patient consents for themselves: the form has no line for anyone\r\nelse to sign on their behalf." ]
       ] [
         fhir:name [ fhir:v "granteePatient" ] ;
         fhir:source ( [
           fhir:context [ fhir:v "qr" ] ;
           fhir:element [ fhir:v "subject" ] ;
           fhir:variable [ fhir:v "s" ] ;
           fhir:condition [ fhir:v "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'))))" ]
         ] ) ;
         fhir:target ( [
           fhir:context [ fhir:v "consent" ] ;
           fhir:element [ fhir:v "grantee" ] ;
           fhir:transform [ fhir:v "copy" ] ;
           fhir:parameter ( [
             fhir:value [
               a fhir:id ;
               fhir:v "s"
             ]
           ] )
         ] ) ;
         fhir:documentation [ fhir:v "The grantees are both parties to the consent: the patient, written here and only\r\nwhen the subject is one, and the practitioner who recorded it, the response's\r\nauthor, which ConformConsent adds. The stamped copy never names the patient\r\nitself; see mapmeta's WHO_NEVER." ]
       ] [
         fhir:name [ fhir:v "patientGroup" ] ;
         fhir:source ( [
           fhir:context [ fhir:v "qr" ] ;
           fhir:element [ fhir:v "item" ] ;
           fhir:variable [ fhir:v "pg" ] ;
           fhir:condition [ fhir:v "linkId = 'patient'" ]
         ] ) ;
         fhir:rule ( [
           fhir:name [ fhir:v "signedAtRule" ] ;
           fhir:source ( [
             fhir:context [ fhir:v "pg" ] ;
             fhir:element [ fhir:v "item" ] ;
             fhir:variable [ fhir:v "it" ] ;
             fhir:condition [ fhir:v "(linkId = 'patient/signed-at') and answer.value.exists()" ]
           ] ) ;
           fhir:rule ( [
             fhir:name [ fhir:v "answer" ] ;
             fhir:source ( [
               fhir:context [ fhir:v "it" ] ;
               fhir:element [ fhir:v "answer" ] ;
               fhir:listMode [ fhir:v "first" ] ;
               fhir:variable [ fhir:v "a" ]
             ] ) ;
             fhir:rule ( [
               fhir:name [ fhir:v "signedPeriodStart" ] ;
               fhir:source ( [
                 fhir:context [ fhir:v "a" ] ;
                 fhir:element [ fhir:v "value" ] ;
                 fhir:variable [ fhir:v "t" ]
               ] ) ;
               fhir:target ( [
                 fhir:context [ fhir:v "consent" ] ;
                 fhir:element [ fhir:v "period" ] ;
                 fhir:variable [ fhir:v "per" ]
               ] [
                 fhir:context [ fhir:v "per" ] ;
                 fhir:element [ fhir:v "start" ] ;
                 fhir:transform [ fhir:v "copy" ] ;
                 fhir:parameter ( [
                   fhir:value [
                     a fhir:id ;
                     fhir:v "t"
                   ]
                 ] )
               ] )
             ] )
           ] )
         ] ) ;
         fhir:documentation [ fhir:v "The signing time, from the form, not qr.authored. Consent.date is a\r\n`date` and this is a date and time, so it goes to period.start." ]
       ] [
         fhir:name [ fhir:v "doctorVerification" ] ;
         fhir:source ( [
           fhir:context [ fhir:v "qr" ] ;
           fhir:element [ fhir:v "author" ] ;
           fhir:variable [ fhir:v "au" ] ;
           fhir:condition [ fhir:v "(reference.exists() and (reference.startsWith('Practitioner/') or reference.startsWith('PractitionerRole/'))) or (reference.empty() and (type.empty() or ('/' + type).endsWith('/Practitioner') or ('/' + type).endsWith('/PractitionerRole')))" ]
         ] ) ;
         fhir:target ( [
           fhir:context [ fhir:v "consent" ] ;
           fhir:element [ fhir:v "verification" ] ;
           fhir:variable [ fhir:v "ver" ]
         ] ) ;
         fhir:rule ( [
           fhir:name [ fhir:v "verified" ] ;
           fhir:source ( [
             fhir:context [ fhir:v "au" ]
           ] ) ;
           fhir:target ( [
             fhir:context [ fhir:v "ver" ] ;
             fhir:element [ fhir:v "verified" ] ;
             fhir:transform [ fhir:v "copy" ] ;
             fhir:parameter ( [
               fhir:value [
                 a fhir:boolean ;
                 fhir:v true
               ]
             ] )
           ] )
         ] [
           fhir:name [ fhir:v "doctorVerificationType" ] ;
           fhir:source ( [
             fhir:context [ fhir:v "au" ]
           ] ) ;
           fhir:target ( [
             fhir:context [ fhir:v "ver" ] ;
             fhir:element [ fhir:v "verificationType" ] ;
             fhir:variable [ fhir:v "vt" ]
           ] ) ;
           fhir:rule ( [
             fhir:name [ fhir:v "coding" ] ;
             fhir:source ( [
               fhir:context [ fhir:v "au" ]
             ] ) ;
             fhir:target ( [
               fhir:context [ fhir:v "vt" ] ;
               fhir:element [ fhir:v "coding" ] ;
               fhir:variable [ fhir:v "vc" ]
             ] ) ;
             fhir:rule ( [
               fhir:name [ fhir:v "sys" ] ;
               fhir:source ( [
                 fhir:context [ fhir:v "au" ]
               ] ) ;
               fhir:target ( [
                 fhir:context [ fhir:v "vc" ] ;
                 fhir:element [ fhir:v "system" ] ;
                 fhir:transform [ fhir:v "copy" ] ;
                 fhir:parameter ( [
                   fhir:value [
                     a fhir:string ;
                     fhir:v "https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem"
                   ]
                 ] )
               ] )
             ] [
               fhir:name [ fhir:v "cd" ] ;
               fhir:source ( [
                 fhir:context [ fhir:v "au" ]
               ] ) ;
               fhir:target ( [
                 fhir:context [ fhir:v "vc" ] ;
                 fhir:element [ fhir:v "code" ] ;
                 fhir:transform [ fhir:v "copy" ] ;
                 fhir:parameter ( [
                   fhir:value [
                     a fhir:string ;
                     fhir:v "consent-verified-by-doctor"
                   ]
                 ] )
               ] )
             ] [
               fhir:name [ fhir:v "dsp" ] ;
               fhir:source ( [
                 fhir:context [ fhir:v "au" ]
               ] ) ;
               fhir:target ( [
                 fhir:context [ fhir:v "vc" ] ;
                 fhir:element [ fhir:v "display" ] ;
                 fhir:transform [ fhir:v "copy" ] ;
                 fhir:parameter ( [
                   fhir:value [
                     a fhir:string ;
                     fhir:v "Verified by the doctor who explained the treatment"
                   ]
                 ] )
               ] )
             ] )
           ] [
             fhir:name [ fhir:v "text" ] ;
             fhir:source ( [
               fhir:context [ fhir:v "au" ]
             ] ) ;
             fhir:target ( [
               fhir:context [ fhir:v "vt" ] ;
               fhir:element [ fhir:v "text" ] ;
               fhir:transform [ fhir:v "copy" ] ;
               fhir:parameter ( [
                 fhir:value [
                   a fhir:string ;
                   fhir:v "Doctor"
                 ]
               ] )
             ] )
           ] )
         ] [
           fhir:name [ fhir:v "verifiedBy" ] ;
           fhir:source ( [
             fhir:context [ fhir:v "au" ] ;
             fhir:condition [ fhir:v "(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')))" ]
           ] ) ;
           fhir:target ( [
             fhir:context [ fhir:v "ver" ] ;
             fhir:element [ fhir:v "verifiedBy" ] ;
             fhir:transform [ fhir:v "copy" ] ;
             fhir:parameter ( [
               fhir:value [
                 a fhir:id ;
                 fhir:v "au"
               ]
             ] )
           ] )
         ] [
           fhir:name [ fhir:v "verifiedWith" ] ;
           fhir:source ( [
             fhir:context [ fhir:v "qr" ] ;
             fhir:element [ fhir:v "subject" ] ;
             fhir:variable [ fhir:v "s" ] ;
             fhir:condition [ fhir:v "(reference.exists() and (reference.startsWith('Patient/'))) or (reference.empty() and (type.empty() or ('/' + type).endsWith('/Patient')))" ]
           ] ) ;
           fhir:target ( [
             fhir:context [ fhir:v "ver" ] ;
             fhir:element [ fhir:v "verifiedWith" ] ;
             fhir:transform [ fhir:v "copy" ] ;
             fhir:parameter ( [
               fhir:value [
                 a fhir:id ;
                 fhir:v "s"
               ]
             ] )
           ] )
         ] [
           fhir:name [ fhir:v "patientGroupForVerification" ] ;
           fhir:source ( [
             fhir:context [ fhir:v "qr" ] ;
             fhir:element [ fhir:v "item" ] ;
             fhir:variable [ fhir:v "pg2" ] ;
             fhir:condition [ fhir:v "linkId = 'patient'" ]
           ] ) ;
           fhir:rule ( [
             fhir:name [ fhir:v "signedAtRule" ] ;
             fhir:source ( [
               fhir:context [ fhir:v "pg2" ] ;
               fhir:element [ fhir:v "item" ] ;
               fhir:variable [ fhir:v "st" ] ;
               fhir:condition [ fhir:v "(linkId = 'patient/signed-at') and answer.value.exists()" ]
             ] ) ;
             fhir:rule ( [
               fhir:name [ fhir:v "signedAtAnswer" ] ;
               fhir:source ( [
                 fhir:context [ fhir:v "st" ] ;
                 fhir:element [ fhir:v "answer" ] ;
                 fhir:listMode [ fhir:v "first" ] ;
                 fhir:variable [ fhir:v "sa" ]
               ] ) ;
               fhir:rule ( [
                 fhir:name [ fhir:v "verificationDate" ] ;
                 fhir:source ( [
                   fhir:context [ fhir:v "sa" ] ;
                   fhir:element [ fhir:v "value" ] ;
                   fhir:variable [ fhir:v "t" ]
                 ] ) ;
                 fhir:target ( [
                   fhir:context [ fhir:v "ver" ] ;
                   fhir:element [ fhir:v "verificationDate" ] ;
                   fhir:transform [ fhir:v "copy" ] ;
                   fhir:parameter ( [
                     fhir:value [
                       a fhir:id ;
                       fhir:v "t"
                     ]
                   ] )
                 ] )
               ] )
             ] )
           ] )
         ] ) ;
         fhir:documentation [ fhir:v "── The verifications ─────────────────────────────────────────────────\r\nThe doctor's, and the interpreter's when one was used.\r\nThe doctor who explained the treatment is the response's author. The form\r\nstopped asking for the doctor's name, designation and signature on\r\n2026-10-06, because whoever records the consent is that doctor. So the\r\nverification is made when the response has an author who is a person, a\r\nPractitioner or a PractitionerRole (an Organization is not a doctor), and\r\nit is verified by them: recording the form is their attestation. No such\r\nauthor, no doctor's verification. Dated with the patient's signing, the\r\nonly time the form records." ]
       ] [
         fhir:name [ fhir:v "interpreterGroup" ] ;
         fhir:source ( [
           fhir:context [ fhir:v "qr" ] ;
           fhir:element [ fhir:v "item" ] ;
           fhir:variable [ fhir:v "ig" ] ;
           fhir:condition [ fhir:v "linkId = 'interpreter'" ]
         ] ) ;
         fhir:rule ( [
           fhir:name [ fhir:v "nameRule" ] ;
           fhir:source ( [
             fhir:context [ fhir:v "ig" ] ;
             fhir:element [ fhir:v "item" ] ;
             fhir:variable [ fhir:v "it" ] ;
             fhir:condition [ fhir:v "(linkId = 'interpreter/name') and answer.value.exists()" ]
           ] ) ;
           fhir:rule ( [
             fhir:name [ fhir:v "answer" ] ;
             fhir:source ( [
               fhir:context [ fhir:v "it" ] ;
               fhir:element [ fhir:v "answer" ] ;
               fhir:listMode [ fhir:v "first" ] ;
               fhir:variable [ fhir:v "a" ]
             ] ) ;
             fhir:rule ( [
               fhir:name [ fhir:v "interpreterVerification" ] ;
               fhir:source ( [
                 fhir:context [ fhir:v "a" ] ;
                 fhir:element [ fhir:v "value" ] ;
                 fhir:variable [ fhir:v "name" ] ;
                 fhir:condition [ fhir:v "$this is string" ]
               ] ) ;
               fhir:target ( [
                 fhir:context [ fhir:v "consent" ] ;
                 fhir:element [ fhir:v "verification" ] ;
                 fhir:variable [ fhir:v "iv" ]
               ] ) ;
               fhir:rule ( [
                 fhir:name [ fhir:v "verifiedUnlessSigned" ] ;
                 fhir:source ( [
                   fhir:context [ fhir:v "name" ]
                 ] ) ;
                 fhir:target ( [
                   fhir:context [ fhir:v "iv" ] ;
                   fhir:element [ fhir:v "verified" ] ;
                   fhir:transform [ fhir:v "copy" ] ;
                   fhir:parameter ( [
                     fhir:value [
                       a fhir:boolean ;
                       fhir:v false
                     ]
                   ] )
                 ] )
               ] [
                 fhir:name [ fhir:v "interpreterSignedRule" ] ;
                 fhir:source ( [
                   fhir:context [ fhir:v "ig" ] ;
                   fhir:element [ fhir:v "item" ] ;
                   fhir:variable [ fhir:v "sg" ] ;
                   fhir:condition [ fhir:v "(linkId = 'interpreter/signed') and (answer.value = true)" ]
                 ] ) ;
                 fhir:rule ( [
                   fhir:name [ fhir:v "interpreterSigned" ] ;
                   fhir:source ( [
                     fhir:context [ fhir:v "sg" ]
                   ] ) ;
                   fhir:target ( [
                     fhir:context [ fhir:v "iv" ] ;
                     fhir:element [ fhir:v "verified" ] ;
                     fhir:transform [ fhir:v "copy" ] ;
                     fhir:parameter ( [
                       fhir:value [
                         a fhir:boolean ;
                         fhir:v true
                       ]
                     ] )
                   ] )
                 ] )
               ] [
                 fhir:name [ fhir:v "interpreterVerificationType" ] ;
                 fhir:source ( [
                   fhir:context [ fhir:v "name" ]
                 ] ) ;
                 fhir:target ( [
                   fhir:context [ fhir:v "iv" ] ;
                   fhir:element [ fhir:v "verificationType" ] ;
                   fhir:variable [ fhir:v "ivt" ]
                 ] ) ;
                 fhir:rule ( [
                   fhir:name [ fhir:v "coding" ] ;
                   fhir:source ( [
                     fhir:context [ fhir:v "name" ]
                   ] ) ;
                   fhir:target ( [
                     fhir:context [ fhir:v "ivt" ] ;
                     fhir:element [ fhir:v "coding" ] ;
                     fhir:variable [ fhir:v "ic" ]
                   ] ) ;
                   fhir:rule ( [
                     fhir:name [ fhir:v "sys" ] ;
                     fhir:source ( [
                       fhir:context [ fhir:v "name" ]
                     ] ) ;
                     fhir:target ( [
                       fhir:context [ fhir:v "ic" ] ;
                       fhir:element [ fhir:v "system" ] ;
                       fhir:transform [ fhir:v "copy" ] ;
                       fhir:parameter ( [
                         fhir:value [
                           a fhir:string ;
                           fhir:v "https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem"
                         ]
                       ] )
                     ] )
                   ] [
                     fhir:name [ fhir:v "cd" ] ;
                     fhir:source ( [
                       fhir:context [ fhir:v "name" ]
                     ] ) ;
                     fhir:target ( [
                       fhir:context [ fhir:v "ic" ] ;
                       fhir:element [ fhir:v "code" ] ;
                       fhir:transform [ fhir:v "copy" ] ;
                       fhir:parameter ( [
                         fhir:value [
                           a fhir:string ;
                           fhir:v "consent-interpreter-used"
                         ]
                       ] )
                     ] )
                   ] [
                     fhir:name [ fhir:v "dsp" ] ;
                     fhir:source ( [
                       fhir:context [ fhir:v "name" ]
                     ] ) ;
                     fhir:target ( [
                       fhir:context [ fhir:v "ic" ] ;
                       fhir:element [ fhir:v "display" ] ;
                       fhir:transform [ fhir:v "copy" ] ;
                       fhir:parameter ( [
                         fhir:value [
                           a fhir:string ;
                           fhir:v "Interpreter used for the consent discussion"
                         ]
                       ] )
                     ] )
                   ] )
                 ] [
                   fhir:name [ fhir:v "text" ] ;
                   fhir:source ( [
                     fhir:context [ fhir:v "name" ]
                   ] ) ;
                   fhir:target ( [
                     fhir:context [ fhir:v "ivt" ] ;
                     fhir:element [ fhir:v "text" ] ;
                     fhir:transform [ fhir:v "append" ] ;
                     fhir:parameter ( [
                       fhir:value [
                         a fhir:string ;
                         fhir:v "Interpreter: "
                       ]
                     ] [
                       fhir:value [
                         a fhir:id ;
                         fhir:v "name"
                       ]
                     ] )
                   ] )
                 ] )
               ] [
                 fhir:name [ fhir:v "verifiedWith" ] ;
                 fhir:source ( [
                   fhir:context [ fhir:v "qr" ] ;
                   fhir:element [ fhir:v "subject" ] ;
                   fhir:variable [ fhir:v "s" ] ;
                   fhir:condition [ fhir:v "(reference.exists() and (reference.startsWith('Patient/'))) or (reference.empty() and (type.empty() or ('/' + type).endsWith('/Patient')))" ]
                 ] ) ;
                 fhir:target ( [
                   fhir:context [ fhir:v "iv" ] ;
                   fhir:element [ fhir:v "verifiedWith" ] ;
                   fhir:transform [ fhir:v "copy" ] ;
                   fhir:parameter ( [
                     fhir:value [
                       a fhir:id ;
                       fhir:v "s"
                     ]
                   ] )
                 ] )
               ] [
                 fhir:name [ fhir:v "patientGroupForInterpreter" ] ;
                 fhir:source ( [
                   fhir:context [ fhir:v "qr" ] ;
                   fhir:element [ fhir:v "item" ] ;
                   fhir:variable [ fhir:v "pg3" ] ;
                   fhir:condition [ fhir:v "linkId = 'patient'" ]
                 ] ) ;
                 fhir:rule ( [
                   fhir:name [ fhir:v "signedAtRule" ] ;
                   fhir:source ( [
                     fhir:context [ fhir:v "pg3" ] ;
                     fhir:element [ fhir:v "item" ] ;
                     fhir:variable [ fhir:v "st" ] ;
                     fhir:condition [ fhir:v "(linkId = 'patient/signed-at') and answer.value.exists()" ]
                   ] ) ;
                   fhir:rule ( [
                     fhir:name [ fhir:v "signedAtAnswer" ] ;
                     fhir:source ( [
                       fhir:context [ fhir:v "st" ] ;
                       fhir:element [ fhir:v "answer" ] ;
                       fhir:listMode [ fhir:v "first" ] ;
                       fhir:variable [ fhir:v "sa" ]
                     ] ) ;
                     fhir:rule ( [
                       fhir:name [ fhir:v "verificationDate" ] ;
                       fhir:source ( [
                         fhir:context [ fhir:v "sa" ] ;
                         fhir:element [ fhir:v "value" ] ;
                         fhir:variable [ fhir:v "t" ]
                       ] ) ;
                       fhir:target ( [
                         fhir:context [ fhir:v "iv" ] ;
                         fhir:element [ fhir:v "verificationDate" ] ;
                         fhir:transform [ fhir:v "copy" ] ;
                         fhir:parameter ( [
                           fhir:value [
                             a fhir:id ;
                             fhir:v "t"
                           ]
                         ] )
                       ] )
                     ] )
                   ] )
                 ] )
               ] )
             ] )
           ] )
         ] ) ;
         fhir:documentation [ fhir:v "The interpreter, if one was used: whether the explanation reached the patient\r\nin a language they understood is what makes the consent informed. Verified\r\nwhen they have signed. It names no verifier, because the interpreter is a name\r\non the form, not a record anything could point at; the name is in its type." ]
       ] [
         fhir:name [ fhir:v "treatmentGroup" ] ;
         fhir:source ( [
           fhir:context [ fhir:v "qr" ] ;
           fhir:element [ fhir:v "item" ] ;
           fhir:variable [ fhir:v "tg" ] ;
           fhir:condition [ fhir:v "linkId = 'treatment'" ]
         ] ) ;
         fhir:rule ( [
           fhir:name [ fhir:v "therapyRule" ] ;
           fhir:source ( [
             fhir:context [ fhir:v "tg" ] ;
             fhir:element [ fhir:v "item" ] ;
             fhir:variable [ fhir:v "it" ] ;
             fhir:condition [ fhir:v "linkId = 'treatment/therapy'" ]
           ] ) ;
           fhir:rule ( [
             fhir:name [ fhir:v "therapyProvision" ] ;
             fhir:source ( [
               fhir:context [ fhir:v "it" ] ;
               fhir:element [ fhir:v "answer" ] ;
               fhir:variable [ fhir:v "a" ]
             ] ) ;
             fhir:target ( [
               fhir:context [ fhir:v "consent" ] ;
               fhir:element [ fhir:v "provision" ] ;
               fhir:variable [ fhir:v "prov" ]
             ] ) ;
             fhir:rule ( [
               fhir:name [ fhir:v "therapyCode" ] ;
               fhir:source ( [
                 fhir:context [ fhir:v "a" ] ;
                 fhir:element [ fhir:v "value" ] ;
                 fhir:variable [ fhir:v "cv" ]
               ] ) ;
               fhir:target ( [
                 fhir:context [ fhir:v "prov" ] ;
                 fhir:element [ fhir:v "code" ] ;
                 fhir:variable [ fhir:v "pc" ]
               ] ) ;
               fhir:rule ( [
                 fhir:name [ fhir:v "localCoding" ] ;
                 fhir:source ( [
                   fhir:context [ fhir:v "cv" ]
                 ] ) ;
                 fhir:target ( [
                   fhir:context [ fhir:v "pc" ] ;
                   fhir:element [ fhir:v "coding" ] ;
                   fhir:transform [ fhir:v "copy" ] ;
                   fhir:parameter ( [
                     fhir:value [
                       a fhir:id ;
                       fhir:v "cv"
                     ]
                   ] )
                 ] )
               ] [
                 fhir:name [ fhir:v "text" ] ;
                 fhir:source ( [
                   fhir:context [ fhir:v "cv" ] ;
                   fhir:element [ fhir:v "display" ] ;
                   fhir:variable [ fhir:v "d" ]
                 ] ) ;
                 fhir:target ( [
                   fhir:context [ fhir:v "pc" ] ;
                   fhir:element [ fhir:v "text" ] ;
                   fhir:transform [ fhir:v "copy" ] ;
                   fhir:parameter ( [
                     fhir:value [
                       a fhir:id ;
                       fhir:v "d"
                     ]
                   ] )
                 ] )
               ] [
                 fhir:name [ fhir:v "chemotherapyLoinc" ] ;
                 fhir:source ( [
                   fhir:context [ fhir:v "cv" ] ;
                   fhir:condition [ fhir:v "code = 'anti-cancer-chemotherapy'" ]
                 ] ) ;
                 fhir:target ( [
                   fhir:context [ fhir:v "pc" ] ;
                   fhir:element [ fhir:v "coding" ] ;
                   fhir:variable [ fhir:v "loinc" ]
                 ] ) ;
                 fhir:rule ( [
                   fhir:name [ fhir:v "sys" ] ;
                   fhir:source ( [
                     fhir:context [ fhir:v "cv" ]
                   ] ) ;
                   fhir:target ( [
                     fhir:context [ fhir:v "loinc" ] ;
                     fhir:element [ fhir:v "system" ] ;
                     fhir:transform [ fhir:v "copy" ] ;
                     fhir:parameter ( [
                       fhir:value [
                         a fhir:string ;
                         fhir:v "http://loinc.org"
                       ]
                     ] )
                   ] )
                 ] [
                   fhir:name [ fhir:v "cd" ] ;
                   fhir:source ( [
                     fhir:context [ fhir:v "cv" ]
                   ] ) ;
                   fhir:target ( [
                     fhir:context [ fhir:v "loinc" ] ;
                     fhir:element [ fhir:v "code" ] ;
                     fhir:transform [ fhir:v "copy" ] ;
                     fhir:parameter ( [
                       fhir:value [
                         a fhir:string ;
                         fhir:v "LA6172-6"
                       ]
                     ] )
                   ] )
                 ] [
                   fhir:name [ fhir:v "dsp" ] ;
                   fhir:source ( [
                     fhir:context [ fhir:v "cv" ]
                   ] ) ;
                   fhir:target ( [
                     fhir:context [ fhir:v "loinc" ] ;
                     fhir:element [ fhir:v "display" ] ;
                     fhir:transform [ fhir:v "copy" ] ;
                     fhir:parameter ( [
                       fhir:value [
                         a fhir:string ;
                         fhir:v "Chemotherapy"
                       ]
                     ] )
                   ] )
                 ] )
               ] [
                 fhir:name [ fhir:v "hormonalLoinc" ] ;
                 fhir:source ( [
                   fhir:context [ fhir:v "cv" ] ;
                   fhir:condition [ fhir:v "code = 'anti-cancer-hormonal-therapy'" ]
                 ] ) ;
                 fhir:target ( [
                   fhir:context [ fhir:v "pc" ] ;
                   fhir:element [ fhir:v "coding" ] ;
                   fhir:variable [ fhir:v "loinc" ]
                 ] ) ;
                 fhir:rule ( [
                   fhir:name [ fhir:v "sys" ] ;
                   fhir:source ( [
                     fhir:context [ fhir:v "cv" ]
                   ] ) ;
                   fhir:target ( [
                     fhir:context [ fhir:v "loinc" ] ;
                     fhir:element [ fhir:v "system" ] ;
                     fhir:transform [ fhir:v "copy" ] ;
                     fhir:parameter ( [
                       fhir:value [
                         a fhir:string ;
                         fhir:v "http://loinc.org"
                       ]
                     ] )
                   ] )
                 ] [
                   fhir:name [ fhir:v "cd" ] ;
                   fhir:source ( [
                     fhir:context [ fhir:v "cv" ]
                   ] ) ;
                   fhir:target ( [
                     fhir:context [ fhir:v "loinc" ] ;
                     fhir:element [ fhir:v "code" ] ;
                     fhir:transform [ fhir:v "copy" ] ;
                     fhir:parameter ( [
                       fhir:value [
                         a fhir:string ;
                         fhir:v "LA16052-5"
                       ]
                     ] )
                   ] )
                 ] [
                   fhir:name [ fhir:v "dsp" ] ;
                   fhir:source ( [
                     fhir:context [ fhir:v "cv" ]
                   ] ) ;
                   fhir:target ( [
                     fhir:context [ fhir:v "loinc" ] ;
                     fhir:element [ fhir:v "display" ] ;
                     fhir:transform [ fhir:v "copy" ] ;
                     fhir:parameter ( [
                       fhir:value [
                         a fhir:string ;
                         fhir:v "Hormonal therapy/"
                       ]
                     ] )
                   ] )
                 ] )
               ] )
             ] )
           ] )
         ] [
           fhir:name [ fhir:v "regimenRule" ] ;
           fhir:source ( [
             fhir:context [ fhir:v "tg" ] ;
             fhir:element [ fhir:v "item" ] ;
             fhir:variable [ fhir:v "it" ] ;
             fhir:condition [ fhir:v "(linkId = 'treatment/regimen') and answer.value.exists()" ]
           ] ) ;
           fhir:rule ( [
             fhir:name [ fhir:v "answer" ] ;
             fhir:source ( [
               fhir:context [ fhir:v "it" ] ;
               fhir:element [ fhir:v "answer" ] ;
               fhir:listMode [ fhir:v "first" ] ;
               fhir:variable [ fhir:v "a" ]
             ] ) ;
             fhir:rule ( [
               fhir:name [ fhir:v "regimenProvision" ] ;
               fhir:source ( [
                 fhir:context [ fhir:v "a" ] ;
                 fhir:element [ fhir:v "value" ] ;
                 fhir:variable [ fhir:v "txt" ]
               ] ) ;
               fhir:target ( [
                 fhir:context [ fhir:v "consent" ] ;
                 fhir:element [ fhir:v "provision" ] ;
                 fhir:variable [ fhir:v "prov" ]
               ] [
                 fhir:context [ fhir:v "prov" ] ;
                 fhir:element [ fhir:v "code" ] ;
                 fhir:variable [ fhir:v "pc" ]
               ] [
                 fhir:context [ fhir:v "pc" ] ;
                 fhir:element [ fhir:v "text" ] ;
                 fhir:transform [ fhir:v "append" ] ;
                 fhir:parameter ( [
                   fhir:value [
                     a fhir:string ;
                     fhir:v "Drug regimen: "
                   ]
                 ] [
                   fhir:value [
                     a fhir:id ;
                     fhir:v "txt"
                   ]
                 ] )
               ] )
             ] )
           ] )
         ] [
           fhir:name [ fhir:v "diagnosisRule" ] ;
           fhir:source ( [
             fhir:context [ fhir:v "tg" ] ;
             fhir:element [ fhir:v "item" ] ;
             fhir:variable [ fhir:v "it" ] ;
             fhir:condition [ fhir:v "(linkId = 'treatment/diagnosis') and answer.value.exists()" ]
           ] ) ;
           fhir:rule ( [
             fhir:name [ fhir:v "answer" ] ;
             fhir:source ( [
               fhir:context [ fhir:v "it" ] ;
               fhir:element [ fhir:v "answer" ] ;
               fhir:listMode [ fhir:v "first" ] ;
               fhir:variable [ fhir:v "a" ]
             ] ) ;
             fhir:rule ( [
               fhir:name [ fhir:v "diagnosisProvision" ] ;
               fhir:source ( [
                 fhir:context [ fhir:v "a" ] ;
                 fhir:element [ fhir:v "value" ] ;
                 fhir:variable [ fhir:v "txt" ]
               ] ) ;
               fhir:target ( [
                 fhir:context [ fhir:v "consent" ] ;
                 fhir:element [ fhir:v "provision" ] ;
                 fhir:variable [ fhir:v "prov" ]
               ] [
                 fhir:context [ fhir:v "prov" ] ;
                 fhir:element [ fhir:v "code" ] ;
                 fhir:variable [ fhir:v "pc" ]
               ] [
                 fhir:context [ fhir:v "pc" ] ;
                 fhir:element [ fhir:v "text" ] ;
                 fhir:transform [ fhir:v "append" ] ;
                 fhir:parameter ( [
                   fhir:value [
                     a fhir:string ;
                     fhir:v "Diagnosis explained: "
                   ]
                 ] [
                   fhir:value [
                     a fhir:id ;
                     fhir:v "txt"
                   ]
                 ] )
               ] )
             ] )
           ] )
         ] [
           fhir:name [ fhir:v "purposeRule" ] ;
           fhir:source ( [
             fhir:context [ fhir:v "tg" ] ;
             fhir:element [ fhir:v "item" ] ;
             fhir:variable [ fhir:v "it" ] ;
             fhir:condition [ fhir:v "(linkId = 'treatment/intended-purpose') and answer.value.exists()" ]
           ] ) ;
           fhir:rule ( [
             fhir:name [ fhir:v "answer" ] ;
             fhir:source ( [
               fhir:context [ fhir:v "it" ] ;
               fhir:element [ fhir:v "answer" ] ;
               fhir:listMode [ fhir:v "first" ] ;
               fhir:variable [ fhir:v "a" ]
             ] ) ;
             fhir:rule ( [
               fhir:name [ fhir:v "purposeProvision" ] ;
               fhir:source ( [
                 fhir:context [ fhir:v "a" ] ;
                 fhir:element [ fhir:v "value" ] ;
                 fhir:variable [ fhir:v "txt" ]
               ] ) ;
               fhir:target ( [
                 fhir:context [ fhir:v "consent" ] ;
                 fhir:element [ fhir:v "provision" ] ;
                 fhir:variable [ fhir:v "prov" ]
               ] [
                 fhir:context [ fhir:v "prov" ] ;
                 fhir:element [ fhir:v "code" ] ;
                 fhir:variable [ fhir:v "pc" ]
               ] [
                 fhir:context [ fhir:v "pc" ] ;
                 fhir:element [ fhir:v "text" ] ;
                 fhir:transform [ fhir:v "append" ] ;
                 fhir:parameter ( [
                   fhir:value [
                     a fhir:string ;
                     fhir:v "Intended purpose explained: "
                   ]
                 ] [
                   fhir:value [
                     a fhir:id ;
                     fhir:v "txt"
                   ]
                 ] )
               ] )
             ] )
           ] )
         ] [
           fhir:name [ fhir:v "sideEffectsRule" ] ;
           fhir:source ( [
             fhir:context [ fhir:v "tg" ] ;
             fhir:element [ fhir:v "item" ] ;
             fhir:variable [ fhir:v "it" ] ;
             fhir:condition [ fhir:v "(linkId = 'treatment/side-effects-and-risks') and answer.value.exists()" ]
           ] ) ;
           fhir:rule ( [
             fhir:name [ fhir:v "answer" ] ;
             fhir:source ( [
               fhir:context [ fhir:v "it" ] ;
               fhir:element [ fhir:v "answer" ] ;
               fhir:listMode [ fhir:v "first" ] ;
               fhir:variable [ fhir:v "a" ]
             ] ) ;
             fhir:rule ( [
               fhir:name [ fhir:v "sideEffectsProvision" ] ;
               fhir:source ( [
                 fhir:context [ fhir:v "a" ] ;
                 fhir:element [ fhir:v "value" ] ;
                 fhir:variable [ fhir:v "txt" ]
               ] ) ;
               fhir:target ( [
                 fhir:context [ fhir:v "consent" ] ;
                 fhir:element [ fhir:v "provision" ] ;
                 fhir:variable [ fhir:v "prov" ]
               ] [
                 fhir:context [ fhir:v "prov" ] ;
                 fhir:element [ fhir:v "code" ] ;
                 fhir:variable [ fhir:v "pc" ]
               ] [
                 fhir:context [ fhir:v "pc" ] ;
                 fhir:element [ fhir:v "text" ] ;
                 fhir:transform [ fhir:v "append" ] ;
                 fhir:parameter ( [
                   fhir:value [
                     a fhir:string ;
                     fhir:v "Side effects and risks explained: "
                   ]
                 ] [
                   fhir:value [
                     a fhir:id ;
                     fhir:v "txt"
                   ]
                 ] )
               ] )
             ] )
           ] )
         ] ) ;
         fhir:documentation [ fhir:v "── The provisions ────────────────────────────────────────────────────\r\nOne per kind of therapy ticked, so a consent to hormonal therapy cannot\r\nbe read as covering chemotherapy. The local code is what the form\r\noffered; the LOINC answer code beside it is what another system will\r\nrecognise, and LOINC is what SGHIConsent binds provision.code to\r\n(consent-content-code, required). Both LOINC codes come from LOINC's\r\nown list of cancer treatments, LL1479-6, and the display is LOINC's to\r\nthe letter, trailing slash included. LOINC has no code for targeted\r\ntherapy, so that one carries the local code alone.\r\nThe regimen and what was explained are provisions too, each labelled.\r\nConsent has no note in R5, and this is where the procedure consent puts\r\nthe same prose." ]
       ] ) ;
       fhir:documentation [ fhir:v "── The Consent ─────────────────────────────────────────────────────────\r\nGuarded on the patient having signed, as the procedure consent is on the\r\nconsenter. A Consent built from a form nobody signed asserts a permission\r\nthat was never given." ]
     ] )
  ] [
     fhir:name [ fhir:v "BuildConsentBase" ] ;
     fhir:documentation [ fhir:v "─────────────────────────────────────────────────────────────────────────────\r\nShared scaffolding. Repeated in each map rather than imported: the transform\r\nengine resolves `imports` against whatever StructureMaps happen to be on the\r\nserver, and a form that stops extracting because a shared map was not\r\nuploaded is a worse failure than a duplicated group.\r\n─────────────────────────────────────────────────────────────────────────────" ] ;
     fhir:input ( [
       fhir:name [ fhir:v "qr" ] ;
       fhir:type [ fhir:v "QR" ] ;
       fhir:mode [ fhir:v "source" ]
     ] [
       fhir:name [ fhir:v "r" ] ;
       fhir:type [ fhir:v "Consent" ] ;
       fhir:mode [ fhir:v "target" ]
     ] [
       fhir:name [ fhir:v "entry" ] ;
       fhir:mode [ fhir:v "target" ]
     ] ) ;
     fhir:rule ( [
       fhir:name [ fhir:v "responseProvenance" ] ;
       fhir:source ( [
         fhir:context [ fhir:v "qr" ]
       ] ) ;
       fhir:target ( [
         fhir:context [ fhir:v "r" ]
       ] ) ;
       fhir:dependent ( [
         fhir:name [ fhir:v "SetResponseProvenance" ] ;
         fhir:parameter ( [
           fhir:value [
             a fhir:id ;
             fhir:v "qr"
           ]
         ] [
           fhir:value [
             a fhir:id ;
             fhir:v "r"
           ]
         ] )
       ] )
     ] [
       fhir:name [ fhir:v "linkQuestionnaireResponse" ] ;
       fhir:source ( [
         fhir:context [ fhir:v "qr" ] ;
         fhir:element [ fhir:v "id" ] ;
         fhir:variable [ fhir:v "qid" ] ;
         fhir:condition [ fhir:v "$this.hasValue()" ]
       ] ) ;
       fhir:target ( [
         fhir:context [ fhir:v "r" ] ;
         fhir:element [ fhir:v "sourceReference" ] ;
         fhir:variable [ fhir:v "srcRef" ] ;
         fhir:transform [ fhir:v "create" ] ;
         fhir:parameter ( [
           fhir:value [
             a fhir:string ;
             fhir:v "Reference"
           ]
         ] )
       ] [
         fhir:context [ fhir:v "srcRef" ] ;
         fhir:element [ fhir:v "reference" ] ;
         fhir:transform [ fhir:v "copy" ] ;
         fhir:parameter ( [
           fhir:value [
             a fhir:id ;
             fhir:v "qid"
           ]
         ] )
       ] )
     ] [
       fhir:name [ fhir:v "idAndFullUrl" ] ;
       fhir:source ( [
         fhir:context [ fhir:v "qr" ]
       ] ) ;
       fhir:target ( [
         fhir:context [ fhir:v "r" ] ;
         fhir:element [ fhir:v "id" ] ;
         fhir:transform [ fhir:v "uuid" ]
       ] ) ;
       fhir:dependent ( [
         fhir:name [ fhir:v "SetConsentFullUrl" ] ;
         fhir:parameter ( [
           fhir:value [
             a fhir:id ;
             fhir:v "r"
           ]
         ] [
           fhir:value [
             a fhir:id ;
             fhir:v "entry"
           ]
         ] )
       ] )
     ] [
       fhir:name [ fhir:v "entryRequest" ] ;
       fhir:source ( [
         fhir:context [ fhir:v "qr" ]
       ] ) ;
       fhir:target ( [
         fhir:context [ fhir:v "entry" ] ;
         fhir:element [ fhir:v "request" ] ;
         fhir:variable [ fhir:v "request" ]
       ] ) ;
       fhir:rule ( [
         fhir:name [ fhir:v "requestMethod" ] ;
         fhir:source ( [
           fhir:context [ fhir:v "qr" ]
         ] ) ;
         fhir:target ( [
           fhir:context [ fhir:v "request" ] ;
           fhir:element [ fhir:v "method" ] ;
           fhir:transform [ fhir:v "copy" ] ;
           fhir:parameter ( [
             fhir:value [
               a fhir:string ;
               fhir:v "POST"
             ]
           ] )
         ] )
       ] [
         fhir:name [ fhir:v "requestUrl" ] ;
         fhir:source ( [
           fhir:context [ fhir:v "qr" ]
         ] ) ;
         fhir:target ( [
           fhir:context [ fhir:v "request" ] ;
           fhir:element [ fhir:v "url" ] ;
           fhir:transform [ fhir:v "copy" ] ;
           fhir:parameter ( [
             fhir:value [
               a fhir:string ;
               fhir:v "Consent"
             ]
           ] )
         ] )
       ] )
     ] [
       fhir:name [ fhir:v "subject" ] ;
       fhir:source ( [
         fhir:context [ fhir:v "qr" ] ;
         fhir:element [ fhir:v "subject" ] ;
         fhir:variable [ fhir:v "s" ] ;
         fhir:condition [ fhir:v "(reference.exists() and (reference.startsWith('Patient/'))) or (reference.empty() and (type.empty() or ('/' + type).endsWith('/Patient')))" ]
       ] ) ;
       fhir:target ( [
         fhir:context [ fhir:v "r" ] ;
         fhir:element [ fhir:v "subject" ] ;
         fhir:transform [ fhir:v "copy" ] ;
         fhir:parameter ( [
           fhir:value [
             a fhir:id ;
             fhir:v "s"
           ]
         ] )
       ] )
     ] [
       fhir:name [ fhir:v "profileConformance" ] ;
       fhir:source ( [
         fhir:context [ fhir:v "qr" ]
       ] ) ;
       fhir:target ( [
         fhir:context [ fhir:v "r" ]
       ] ) ;
       fhir:dependent ( [
         fhir:name [ fhir:v "ConformConsent" ] ;
         fhir:parameter ( [
           fhir:value [
             a fhir:id ;
             fhir:v "qr"
           ]
         ] [
           fhir:value [
             a fhir:id ;
             fhir:v "r"
           ]
         ] )
       ] )
     ] )
  ] [
     fhir:name [ fhir:v "SetConsentFullUrl" ] ;
     fhir:input ( [
       fhir:name [ fhir:v "r" ] ;
       fhir:type [ fhir:v "Consent" ] ;
       fhir:mode [ fhir:v "source" ]
     ] [
       fhir:name [ fhir:v "entry" ] ;
       fhir:mode [ fhir:v "target" ]
     ] ) ;
     fhir:rule ( [
       fhir:name [ fhir:v "assignFullUrl" ] ;
       fhir:source ( [
         fhir:context [ fhir:v "r" ] ;
         fhir:element [ fhir:v "id" ] ;
         fhir:variable [ fhir:v "id" ]
       ] ) ;
       fhir:target ( [
         fhir:context [ fhir:v "entry" ] ;
         fhir:element [ fhir:v "fullUrl" ] ;
         fhir:transform [ fhir:v "append" ] ;
         fhir:parameter ( [
           fhir:value [
             a fhir:string ;
             fhir:v "https://fhir.slade360.co.ke/fhir/Consent/"
           ]
         ] [
           fhir:value [
             a fhir:id ;
             fhir:v "id"
           ]
         ] )
       ] )
     ] )
  ] [
     fhir:name [ fhir:v "SetResponseProvenance" ] ;
     fhir:documentation [ fhir:v "── Provenance and tenancy ───────────────────────────────────────────────────\r\nTwo tags on everything this map creates. The first says which questionnaire\r\nproduced it, so a form that reopens mid-admission recalls its own earlier\r\nentries and not another form's. The second copies the tenant tags off the\r\nresponse, because nothing else on the path puts them there. The response's\r\nidentifier is copied the same way.\r\nThe code is the form's document type, not the questionnaire's id: every\r\nenvironment mints its own ids, and there is only one set of maps, so an id\r\nhere would tie the tag to whichever environment stamped it.\r\n── Provenance and tenancy ───────────────────────────────────────────────────" ] ;
     fhir:input ( [
       fhir:name [ fhir:v "qr" ] ;
       fhir:type [ fhir:v "QR" ] ;
       fhir:mode [ fhir:v "source" ]
     ] [
       fhir:name [ fhir:v "r" ] ;
       fhir:mode [ fhir:v "target" ]
     ] ) ;
     fhir:rule ( [
       fhir:name [ fhir:v "provenanceMeta" ] ;
       fhir:source ( [
         fhir:context [ fhir:v "qr" ]
       ] ) ;
       fhir:target ( [
         fhir:context [ fhir:v "r" ] ;
         fhir:element [ fhir:v "meta" ] ;
         fhir:variable [ fhir:v "m" ]
       ] ) ;
       fhir:rule ( [
         fhir:name [ fhir:v "provenanceTag" ] ;
         fhir:source ( [
           fhir:context [ fhir:v "qr" ]
         ] ) ;
         fhir:target ( [
           fhir:context [ fhir:v "m" ] ;
           fhir:element [ fhir:v "tag" ] ;
           fhir:variable [ fhir:v "t" ]
         ] ) ;
         fhir:rule ( [
           fhir:name [ fhir:v "provenanceSystem" ] ;
           fhir:source ( [
             fhir:context [ fhir:v "qr" ]
           ] ) ;
           fhir:target ( [
             fhir:context [ fhir:v "t" ] ;
             fhir:element [ fhir:v "system" ] ;
             fhir:transform [ fhir:v "copy" ] ;
             fhir:parameter ( [
               fhir:value [
                 a fhir:string ;
                 fhir:v "http://slade360edi.com/questionnaire-provenance"
               ]
             ] )
           ] )
         ] [
           fhir:name [ fhir:v "provenanceCode" ] ;
           fhir:source ( [
             fhir:context [ fhir:v "qr" ]
           ] ) ;
           fhir:target ( [
             fhir:context [ fhir:v "t" ] ;
             fhir:element [ fhir:v "code" ] ;
             fhir:transform [ fhir:v "copy" ] ;
             fhir:parameter ( [
               fhir:value [
                 a fhir:string ;
                 fhir:v "cancer-treatment-consent"
               ]
             ] )
           ] )
         ] [
           fhir:name [ fhir:v "provenanceDisplay" ] ;
           fhir:source ( [
             fhir:context [ fhir:v "qr" ]
           ] ) ;
           fhir:target ( [
             fhir:context [ fhir:v "t" ] ;
             fhir:element [ fhir:v "display" ] ;
             fhir:transform [ fhir:v "copy" ] ;
             fhir:parameter ( [
               fhir:value [
                 a fhir:string ;
                 fhir:v "Cancer centre informed consent"
               ]
             ] )
           ] )
         ] )
       ] )
     ] [
       fhir:name [ fhir:v "tenantTags" ] ;
       fhir:source ( [
         fhir:context [ fhir:v "qr" ] ;
         fhir:element [ fhir:v "meta" ] ;
         fhir:variable [ fhir:v "qm" ]
       ] ) ;
       fhir:rule ( [
         fhir:name [ fhir:v "copyTag" ] ;
         fhir:source ( [
           fhir:context [ fhir:v "qm" ] ;
           fhir:element [ fhir:v "tag" ] ;
           fhir:variable [ fhir:v "qt" ]
         ] ) ;
         fhir:target ( [
           fhir:context [ fhir:v "r" ] ;
           fhir:element [ fhir:v "meta" ] ;
           fhir:variable [ fhir:v "m" ]
         ] [
           fhir:context [ fhir:v "m" ] ;
           fhir:element [ fhir:v "tag" ] ;
           fhir:transform [ fhir:v "copy" ] ;
           fhir:parameter ( [
             fhir:value [
               a fhir:id ;
               fhir:v "qt"
             ]
           ] )
         ] )
       ] ) ;
       fhir:documentation [ fhir:v "Every tag the response carries, onto the resource. `meta` is 0..1, so this\r\nlands on the same meta the rule above created rather than a second one." ]
     ] [
       fhir:name [ fhir:v "identifier" ] ;
       fhir:source ( [
         fhir:context [ fhir:v "qr" ] ;
         fhir:element [ fhir:v "identifier" ] ;
         fhir:variable [ fhir:v "qid" ] ;
         fhir:condition [ fhir:v "assigner.empty() or assigner.where(((reference.exists() and (reference.startsWith('Organization/'))) or (reference.empty() and (type.empty() or ('/' + type).endsWith('/Organization'))))).exists()" ]
       ] ) ;
       fhir:target ( [
         fhir:context [ fhir:v "r" ] ;
         fhir:element [ fhir:v "identifier" ] ;
         fhir:transform [ fhir:v "copy" ] ;
         fhir:parameter ( [
           fhir:value [
             a fhir:id ;
             fhir:v "qid"
           ]
         ] )
       ] ) ;
       fhir:documentation [ fhir:v "The response's identifiers, as they are. Every profile wants one, and it is\r\nthe response's to give: nothing here mints one, so a response without an\r\nidentifier extracts resources without one. One whose assigner is not of a\r\ntype the profiles allow there is left behind whole, not altered." ]
     ] )
  ] [
     fhir:name [ fhir:v "ConformConsent" ] ;
     fhir:documentation [ fhir:v "── Conformance to the IG profiles ───────────────────────────────────────────\r\nWhat the IG's profiles require that the response itself can supply. Called at\r\nthe end of each base group. The encounter and every who-element are the\r\nresponse's own; see mapmeta.py for what is and is not here.\r\n── Conformance to the IG profiles ───────────────────────────────────────────" ] ;
     fhir:input ( [
       fhir:name [ fhir:v "qr" ] ;
       fhir:type [ fhir:v "QR" ] ;
       fhir:mode [ fhir:v "source" ]
     ] [
       fhir:name [ fhir:v "r" ] ;
       fhir:mode [ fhir:v "target" ]
     ] ) ;
     fhir:rule ( [
       fhir:name [ fhir:v "date" ] ;
       fhir:source ( [
         fhir:context [ fhir:v "qr" ] ;
         fhir:element [ fhir:v "authored" ] ;
         fhir:variable [ fhir:v "t" ]
       ] ) ;
       fhir:target ( [
         fhir:variable [ fhir:v "day" ] ;
         fhir:transform [ fhir:v "evaluate" ] ;
         fhir:parameter ( [
           fhir:value [
             a fhir:id ;
             fhir:v "t"
           ]
         ] [
           fhir:value [
             a fhir:string ;
             fhir:v "$this.toString().substring(0, 10)"
           ]
         ] )
       ] [
         fhir:context [ fhir:v "r" ] ;
         fhir:element [ fhir:v "date" ] ;
         fhir:transform [ fhir:v "cast" ] ;
         fhir:parameter ( [
           fhir:value [
             a fhir:id ;
             fhir:v "day"
           ]
         ] [
           fhir:value [
             a fhir:string ;
             fhir:v "date"
           ]
         ] )
       ] )
     ] [
       fhir:name [ fhir:v "granteeFromAuthor" ] ;
       fhir:source ( [
         fhir:context [ fhir:v "qr" ] ;
         fhir:element [ fhir:v "author" ] ;
         fhir:variable [ fhir:v "au" ] ;
         fhir:condition [ fhir:v "(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')))" ]
       ] ) ;
       fhir:target ( [
         fhir:context [ fhir:v "r" ] ;
         fhir:element [ fhir:v "grantee" ] ;
         fhir:transform [ fhir:v "copy" ] ;
         fhir:parameter ( [
           fhir:value [
             a fhir:id ;
             fhir:v "au"
           ]
         ] )
       ] )
     ] [
       fhir:name [ fhir:v "granteeFallback" ] ;
       fhir:source ( [
         fhir:context [ fhir:v "qr" ] ;
         fhir:condition [ fhir:v "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()" ]
       ] ) ;
       fhir:rule ( [
         fhir:name [ fhir:v "granteeFromSource" ] ;
         fhir:source ( [
           fhir:context [ fhir:v "qr" ] ;
           fhir:element [ fhir:v "source" ] ;
           fhir:variable [ fhir:v "src" ] ;
           fhir:condition [ fhir:v "(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')))" ]
         ] ) ;
         fhir:target ( [
           fhir:context [ fhir:v "r" ] ;
           fhir:element [ fhir:v "grantee" ] ;
           fhir:transform [ fhir:v "copy" ] ;
           fhir:parameter ( [
             fhir:value [
               a fhir:id ;
               fhir:v "src"
             ]
           ] )
         ] )
       ] )
     ] )
  ] ) . #