SGHI FHIR Profile Implementation Guide
0.1.0 - ci-build

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

: Inpatient Death Note 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/ExtractInpatientDeathNote> a fhir:StructureMap ;
  fhir:nodeRole fhir:treeRoot ;
  fhir:id [ fhir:v "ExtractInpatientDeathNote"] ; # 
  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 ExtractInpatientDeathNote</b></p><a name=\"ExtractInpatientDeathNote\"> </a><a name=\"hcExtractInpatientDeathNote\"> </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/ExtractInpatientDeathNote'</span>\r\n<span style=\"color: #cc00cc\">/// <b>name</b> = </span><span style=\"color: blue\">'ExtractInpatientDeathNote'</span>\r\n<span style=\"color: #cc00cc\">/// <b>title</b> = </span><span style=\"color: blue\">'Inpatient Death Note 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 richest of the seven notes, and the only one that changes a record that already exists. It produces a Composition attested by the clinician who confirmed the death, a Condition carrying the cause as stated, and a FHIRPath PATCH that sets Patient.deceasedDateTime. The PATCH touches that one element and nothing else -- the response carries no demographics, so rebuilding and PUTting the Patient would erase the record. Note this uses the `add` operation: extracting the same death note twice will fail the second time rather than silently overwrite, which is the safer direction for a fact recorded once.'</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/composition.html\" title=\"Composition\">http://hl7.org/fhir/StructureDefinition/Composition</a><span style=\"color: navy\">&quot; </span><b>alias </b>Composition <b>as </b><b>target</b>\r\n<b>uses</b><span style=\"color: navy\"> &quot;</span><a href=\"http://hl7.org/fhir/R5/condition.html\" title=\"Condition\">http://hl7.org/fhir/StructureDefinition/Condition</a><span style=\"color: navy\">&quot; </span><b>alias </b>Condition <b>as </b><b>target</b>\r\n<b>uses</b><span style=\"color: navy\"> &quot;</span><a href=\"http://hl7.org/fhir/R5/parameters.html\" title=\"Parameters\">http://hl7.org/fhir/StructureDefinition/Parameters</a><span style=\"color: navy\">&quot; </span><b>alias </b>Parameters <b>as </b><b>target</b>\r\n\r\n<b>group </b>ExtractInpatientDeathNote<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  qr<span style=\"color: navy\"><b> -&gt; </b></span> bundle.entry<b> as </b><span style=\"color: maroon\">entry</span><span style=\"color: navy\">, </span> entry.resource = <b>create</b><span style=\"color: navy\">(</span><span style=\"color: blue\">'Composition'</span><span style=\"color: navy\">)</span><b> as </b><span style=\"color: maroon\">comp</span><b> then</b><span style=\"color: navy\"> {\r\n</span>    qr<span style=\"color: navy\"><b> -&gt; </b></span>comp<b> then </b>CopyResponseTags<span style=\"color: navy\">(</span><span style=\"color: maroon\">qr</span><span style=\"color: navy\">, </span><span style=\"color: maroon\">comp</span><span style=\"color: navy\">)</span> <i>&quot;responseTags&quot;</i><span style=\"color: navy\">;</span>\r\n    qr<span style=\"color: navy\"><b> -&gt; </b></span> comp<span style=\"color: navy\">, </span> entry<b> then </b>BuildNoteBase<span style=\"color: navy\">(</span><span style=\"color: maroon\">qr</span><span style=\"color: navy\">, </span><span style=\"color: maroon\">comp</span><span style=\"color: navy\">, </span><span style=\"color: maroon\">entry</span><span style=\"color: navy\">)</span> <i>&quot;noteBase&quot;</i><span style=\"color: navy\">;</span>\r\n    qr<span style=\"color: navy\"><b> -&gt; </b></span>comp.name = <span style=\"color: blue\">'InpatientDeathNote'</span> <i>&quot;noteName&quot;</i><span style=\"color: navy\">;</span>\r\n    qr<span style=\"color: navy\"><b> -&gt; </b></span>comp.title = <span style=\"color: blue\">'Death note'</span> <i>&quot;noteTitle&quot;</i><span style=\"color: navy\">;</span>\r\n    <span style=\"color: navy\">// </span><span style=\"color: green\">Deliberately not LOINC 64297-5. That code is the civil death certificate,</span>\r\n    <span style=\"color: navy\">// </span><span style=\"color: green\">a different document with a different author and a different audience.</span>\r\n    qr<span style=\"color: navy\"><b> -&gt; </b></span>comp.type<b> as </b><span style=\"color: maroon\">ty</span><b> then</b><span style=\"color: navy\"> {\r\n</span>      qr<span style=\"color: navy\"><b> -&gt; </b></span>ty.coding<b> as </b><span style=\"color: maroon\">sghi</span><b> then</b><span style=\"color: navy\"> {\r\n</span>        qr<span style=\"color: navy\"><b> -&gt; </b></span>sghi.system = <span style=\"color: blue\">'https://fhir.slade360.co.ke/fhir/CodeSystem/inpatient-document-type-codesystem'</span> <i>&quot;sghiSystem&quot;</i><span style=\"color: navy\">;</span>\r\n        qr<span style=\"color: navy\"><b> -&gt; </b></span>sghi.code = <span style=\"color: blue\">'death-note'</span> <i>&quot;sghiCode&quot;</i><span style=\"color: navy\">;</span>\r\n        qr<span style=\"color: navy\"><b> -&gt; </b></span>sghi.display = <span style=\"color: blue\">'Death note'</span> <i>&quot;sghiDisplay&quot;</i><span style=\"color: navy\">;</span>\r\n      <span style=\"color: navy\">}</span> <i>&quot;sghiCoding&quot;</i><span style=\"color: navy\">;</span>\r\n      qr<span style=\"color: navy\"><b> -&gt; </b></span>ty.text = <span style=\"color: blue\">'Death note'</span> <i>&quot;typeText&quot;</i><span style=\"color: navy\">;</span>\r\n    <span style=\"color: navy\">}</span> <i>&quot;noteType&quot;</i><span style=\"color: navy\">;</span>\r\n    <span style=\"color: navy\">// </span><span style=\"color: green\">The clinician who confirmed the death attests the note.</span>\r\n    qr.item<b> as </b><span style=\"color: maroon\">itC</span><b> where </b><span style=\"color: navy\">(</span>linkId = 'confirmedBy'<span style=\"color: navy\">)</span><b> then</b><span style=\"color: navy\"> {\r\n</span>      itC.answer<b> as </b><span style=\"color: maroon\">aC</span><b> then</b><span style=\"color: navy\"> {\r\n</span>        aC.value<b> as </b><span style=\"color: maroon\">cv</span><span style=\"color: navy\"><b> -&gt; </b></span>comp.attester<b> as </b><span style=\"color: maroon\">att</span><b> then</b><span style=\"color: navy\"> {\r\n</span>          aC<span style=\"color: navy\"><b> -&gt; </b></span>att.mode<b> as </b><span style=\"color: maroon\">mode</span><b> then</b><span style=\"color: navy\"> {\r\n</span>            aC<span style=\"color: navy\"><b> -&gt; </b></span>mode.coding<b> as </b><span style=\"color: maroon\">modec</span><b> then</b><span style=\"color: navy\"> {\r\n</span>              aC<span style=\"color: navy\"><b> -&gt; </b></span>modec.system = <span style=\"color: blue\">'http://hl7.org/fhir/composition-attestation-mode'</span> <i>&quot;attModeSystem&quot;</i><span style=\"color: navy\">;</span>\r\n              aC<span style=\"color: navy\"><b> -&gt; </b></span>modec.code = <span style=\"color: blue\">'professional'</span> <i>&quot;attModeCode&quot;</i><span style=\"color: navy\">;</span>\r\n              aC<span style=\"color: navy\"><b> -&gt; </b></span>modec.display = <span style=\"color: blue\">'Professional'</span> <i>&quot;attModeDisplay&quot;</i><span style=\"color: navy\">;</span>\r\n            <span style=\"color: navy\">}</span> <i>&quot;attModeCoding&quot;</i><span style=\"color: navy\">;</span>\r\n          <span style=\"color: navy\">}</span> <i>&quot;attesterMode&quot;</i><span style=\"color: navy\">;</span>\r\n          qr.item<b> as </b><span style=\"color: maroon\">itT</span><b> where </b><span style=\"color: navy\">(</span>linkId = 'confirmedAt'<span style=\"color: navy\">)</span><b> then</b><span style=\"color: navy\"> {\r\n</span>            itT.answer first<b> as </b><span style=\"color: maroon\">aT</span><b> then</b><span style=\"color: navy\"> {\r\n</span>              aT.value<b> as </b><span style=\"color: maroon\">tv</span><span style=\"color: navy\"><b> -&gt; </b></span>att.time = <span style=\"color: maroon\">tv</span> <i>&quot;attesterTimeFromConfirmedAt&quot;</i><span style=\"color: navy\">;</span>\r\n            <span style=\"color: navy\">}</span> <i>&quot;confirmedAtAnswer&quot;</i><span style=\"color: navy\">;</span>\r\n          <span style=\"color: navy\">}</span> <i>&quot;attesterTimeRule&quot;</i><span style=\"color: navy\">;</span>\r\n          cv<b> where </b><span style=\"color: navy\">(</span>(reference.exists() and (reference.startsWith('Patient/') or reference.startsWith('Organization/'))) or (reference.empty() and (type.empty() or ('/' + type).endsWith('/Patient') or ('/' + type).endsWith('/Organization')))<span style=\"color: navy\">)</span><span style=\"color: navy\"><b> -&gt; </b></span>att.party = <span style=\"color: maroon\">cv</span> <i>&quot;attesterParty&quot;</i><span style=\"color: navy\">;</span>\r\n        <span style=\"color: navy\">}</span> <i>&quot;attester&quot;</i><span style=\"color: navy\">;</span>\r\n      <span style=\"color: navy\">}</span> <i>&quot;confirmedByAnswer&quot;</i><span style=\"color: navy\">;</span>\r\n    <span style=\"color: navy\">}</span> <i>&quot;confirmedByRule&quot;</i><span style=\"color: navy\">;</span>\r\n    <span style=\"color: navy\">// </span><span style=\"color: green\">The confirmed-at time is on the Patient as a fact, and in the document as</span>\r\n    <span style=\"color: navy\">// </span><span style=\"color: green\">a line, because a printed death note that does not say when is not a</span>\r\n    <span style=\"color: navy\">// </span><span style=\"color: green\">death note.</span>\r\n    qr.item<b> as </b><span style=\"color: maroon\">it</span><b> where </b><span style=\"color: navy\">(</span>(linkId = 'confirmedAt') and answer.value.exists()<span style=\"color: navy\">)</span><span style=\"color: navy\"><b> -&gt; </b></span>comp.section<b> as </b><span style=\"color: maroon\">sec</span><b> then</b><span style=\"color: navy\"> {\r\n</span>      it<span style=\"color: navy\"><b> -&gt; </b></span>sec.title = <span style=\"color: blue\">'Death confirmed at'</span> <i>&quot;confirmedAtTitle&quot;</i><span style=\"color: navy\">;</span>\r\n      it<span style=\"color: navy\"><b> -&gt; </b></span>sec<b> then </b>AddSectionText<span style=\"color: navy\">(</span><span style=\"color: maroon\">it</span><span style=\"color: navy\">, </span><span style=\"color: maroon\">sec</span><span style=\"color: navy\">)</span> <i>&quot;confirmedAtText&quot;</i><span style=\"color: navy\">;</span>\r\n    <span style=\"color: navy\">}</span> <i>&quot;confirmedAtSectionRule&quot;</i><span style=\"color: navy\">;</span>\r\n    qr.item<b> as </b><span style=\"color: maroon\">it</span><b> where </b><span style=\"color: navy\">(</span>(linkId = 'circumstances') and answer.value.exists()<span style=\"color: navy\">)</span><span style=\"color: navy\"><b> -&gt; </b></span>comp.section<b> as </b><span style=\"color: maroon\">sec</span><b> then</b><span style=\"color: navy\"> {\r\n</span>      it<span style=\"color: navy\"><b> -&gt; </b></span>sec.title = <span style=\"color: blue\">'Circumstances'</span> <i>&quot;circumstancesTitle&quot;</i><span style=\"color: navy\">;</span>\r\n      it<span style=\"color: navy\"><b> -&gt; </b></span>sec<b> then </b>AddSectionText<span style=\"color: navy\">(</span><span style=\"color: maroon\">it</span><span style=\"color: navy\">, </span><span style=\"color: maroon\">sec</span><span style=\"color: navy\">)</span> <i>&quot;circumstancesText&quot;</i><span style=\"color: navy\">;</span>\r\n    <span style=\"color: navy\">}</span> <i>&quot;circumstancesRule&quot;</i><span style=\"color: navy\">;</span>\r\n    qr.item<b> as </b><span style=\"color: maroon\">it</span><b> where </b><span style=\"color: navy\">(</span>(linkId = 'causeStated') and answer.value.exists()<span style=\"color: navy\">)</span><span style=\"color: navy\"><b> -&gt; </b></span>comp.section<b> as </b><span style=\"color: maroon\">sec</span><b> then</b><span style=\"color: navy\"> {\r\n</span>      it<span style=\"color: navy\"><b> -&gt; </b></span>sec.title = <span style=\"color: blue\">'Cause of death as stated'</span> <i>&quot;causeTitle&quot;</i><span style=\"color: navy\">;</span>\r\n      it<span style=\"color: navy\"><b> -&gt; </b></span>sec<b> then </b>AddSectionText<span style=\"color: navy\">(</span><span style=\"color: maroon\">it</span><span style=\"color: navy\">, </span><span style=\"color: maroon\">sec</span><span style=\"color: navy\">)</span> <i>&quot;causeText&quot;</i><span style=\"color: navy\">;</span>\r\n    <span style=\"color: navy\">}</span> <i>&quot;causeSectionRule&quot;</i><span style=\"color: navy\">;</span>\r\n    qr.item<b> as </b><span style=\"color: maroon\">it</span><b> where </b><span style=\"color: navy\">(</span>(linkId = 'familyInformed') and answer.value.exists()<span style=\"color: navy\">)</span><span style=\"color: navy\"><b> -&gt; </b></span>comp.section<b> as </b><span style=\"color: maroon\">sec</span><b> then</b><span style=\"color: navy\"> {\r\n</span>      it<span style=\"color: navy\"><b> -&gt; </b></span>sec.title = <span style=\"color: blue\">'Family informed'</span> <i>&quot;familyTitle&quot;</i><span style=\"color: navy\">;</span>\r\n      it<span style=\"color: navy\"><b> -&gt; </b></span>sec<b> then </b>AddSectionText<span style=\"color: navy\">(</span><span style=\"color: maroon\">it</span><span style=\"color: navy\">, </span><span style=\"color: maroon\">sec</span><span style=\"color: navy\">)</span> <i>&quot;familyText&quot;</i><span style=\"color: navy\">;</span>\r\n    <span style=\"color: navy\">}</span> <i>&quot;familyRule&quot;</i><span style=\"color: navy\">;</span>\r\n  <span style=\"color: navy\">}</span> <i>&quot;composition&quot;</i><span style=\"color: navy\">;</span>\r\n  <span style=\"color: navy\">// </span><span style=\"color: green\">Cause of death as a Condition. verificationStatus is `confirmed`, not</span>\r\n  <span style=\"color: navy\">// </span><span style=\"color: green\">`provisional` as on the admission note: this is a stated cause, recorded</span>\r\n  <span style=\"color: navy\">// </span><span style=\"color: green\">after the event, not a working impression.</span>\r\n  qr.item<b> as </b><span style=\"color: maroon\">itCause</span><b> where </b><span style=\"color: navy\">(</span>(linkId = 'causeStated') and answer.value.exists()<span style=\"color: navy\">)</span><b> then</b><span style=\"color: navy\"> {\r\n</span>    itCause.answer first<b> as </b><span style=\"color: maroon\">aCause</span><b> then</b><span style=\"color: navy\"> {\r\n</span>      aCause<span style=\"color: navy\"><b> -&gt; </b></span> bundle.entry<b> as </b><span style=\"color: maroon\">entryC</span><span style=\"color: navy\">, </span> entryC.resource = <b>create</b><span style=\"color: navy\">(</span><span style=\"color: blue\">'Condition'</span><span style=\"color: navy\">)</span><b> as </b><span style=\"color: maroon\">cond</span><b> then</b><span style=\"color: navy\"> {\r\n</span>        qr<span style=\"color: navy\"><b> -&gt; </b></span>cond<b> then </b>CopyResponseTags<span style=\"color: navy\">(</span><span style=\"color: maroon\">qr</span><span style=\"color: navy\">, </span><span style=\"color: maroon\">cond</span><span style=\"color: navy\">)</span> <i>&quot;responseTags&quot;</i><span style=\"color: navy\">;</span>\r\n        qr<span style=\"color: navy\"><b> -&gt; </b></span> cond<span style=\"color: navy\">, </span> entryC<b> then </b>BuildConditionBase<span style=\"color: navy\">(</span><span style=\"color: maroon\">qr</span><span style=\"color: navy\">, </span><span style=\"color: maroon\">cond</span><span style=\"color: navy\">, </span><span style=\"color: maroon\">entryC</span><span style=\"color: navy\">)</span> <i>&quot;conditionBase&quot;</i><span style=\"color: navy\">;</span>\r\n        qr<span style=\"color: navy\"><b> -&gt; </b></span>cond.verificationStatus<b> as </b><span style=\"color: maroon\">vs</span><b> then</b><span style=\"color: navy\"> {\r\n</span>          qr<span style=\"color: navy\"><b> -&gt; </b></span>vs.coding<b> as </b><span style=\"color: maroon\">vsc</span><b> then</b><span style=\"color: navy\"> {\r\n</span>            qr<span style=\"color: navy\"><b> -&gt; </b></span>vsc.system = <span style=\"color: blue\">'http://terminology.hl7.org/CodeSystem/condition-ver-status'</span> <i>&quot;verSystem&quot;</i><span style=\"color: navy\">;</span>\r\n            qr<span style=\"color: navy\"><b> -&gt; </b></span>vsc.code = <span style=\"color: blue\">'confirmed'</span> <i>&quot;verCode&quot;</i><span style=\"color: navy\">;</span>\r\n            qr<span style=\"color: navy\"><b> -&gt; </b></span>vsc.display = <span style=\"color: blue\">'Confirmed'</span> <i>&quot;verDisplay&quot;</i><span style=\"color: navy\">;</span>\r\n          <span style=\"color: navy\">}</span> <i>&quot;verCoding&quot;</i><span style=\"color: navy\">;</span>\r\n        <span style=\"color: navy\">}</span> <i>&quot;verificationStatus&quot;</i><span style=\"color: navy\">;</span>\r\n        aCause.value<b> as </b><span style=\"color: maroon\">v</span><span style=\"color: navy\"><b> -&gt; </b></span>cond.code<b> as </b><span style=\"color: maroon\">code</span><b> then</b><span style=\"color: navy\"> {\r\n</span>          v<span style=\"color: navy\"><b> -&gt; </b></span>code.text = <span style=\"color: maroon\">v</span> <i>&quot;codeText&quot;</i><span style=\"color: navy\">;</span>\r\n        <span style=\"color: navy\">}</span> <i>&quot;conditionCode&quot;</i><span style=\"color: navy\">;</span>\r\n        qr<span style=\"color: navy\"><b> -&gt; </b></span>cond.note<b> as </b><span style=\"color: maroon\">note</span><b> then</b><span style=\"color: navy\"> {\r\n</span>          qr<span style=\"color: navy\"><b> -&gt; </b></span>note.text = <span style=\"color: blue\">'Cause of death as stated on the inpatient death note.'</span> <i>&quot;noteText&quot;</i><span style=\"color: navy\">;</span>\r\n        <span style=\"color: navy\">}</span> <i>&quot;conditionNote&quot;</i><span style=\"color: navy\">;</span>\r\n      <span style=\"color: navy\">}</span> <i>&quot;condition&quot;</i><span style=\"color: navy\">;</span>\r\n    <span style=\"color: navy\">}</span> <i>&quot;causeAnswer&quot;</i><span style=\"color: navy\">;</span>\r\n  <span style=\"color: navy\">}</span> <i>&quot;causeConditionRule&quot;</i><span style=\"color: navy\">;</span>\r\n  <span style=\"color: navy\">// </span><span style=\"color: green\">Patient.deceasedDateTime, by FHIRPath PATCH, and only when the response's subject</span>\r\n  <span style=\"color: navy\">// </span><span style=\"color: green\">is a Patient. The patch is addressed to whatever the subject names, so one sent</span>\r\n  <span style=\"color: navy\">// </span><span style=\"color: green\">anywhere else, or with no reference to address, would make the server refuse the</span>\r\n  <span style=\"color: navy\">// </span><span style=\"color: green\">whole transaction; the entry is not built at all rather than built half.</span>\r\n  qr.item<b> as </b><span style=\"color: maroon\">itAt</span><b> where </b><span style=\"color: navy\">(</span>(linkId = 'confirmedAt') and answer.value.exists()<span style=\"color: navy\">)</span><b> then</b><span style=\"color: navy\"> {\r\n</span>    itAt.answer first<b> as </b><span style=\"color: maroon\">aAt</span><b> then</b><span style=\"color: navy\"> {\r\n</span>      qr.subject<b> as </b><span style=\"color: maroon\">s</span><b> where </b><span style=\"color: navy\">(</span>reference.startsWith('Patient/')<span style=\"color: navy\">)</span><b> then</b><span style=\"color: navy\"> {\r\n</span>        aAt<span style=\"color: navy\"><b> -&gt; </b></span> bundle.entry<b> as </b><span style=\"color: maroon\">entryP</span><span style=\"color: navy\">, </span> entryP.resource = <b>create</b><span style=\"color: navy\">(</span><span style=\"color: blue\">'Parameters'</span><span style=\"color: navy\">)</span><b> as </b><span style=\"color: maroon\">params</span><b> then</b><span style=\"color: navy\"> {\r\n</span>          s.reference<b> as </b><span style=\"color: maroon\">sref</span><span style=\"color: navy\"><b> -&gt; </b></span>entryP.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\">'PATCH'</span> <i>&quot;requestMethod&quot;</i><span style=\"color: navy\">;</span>\r\n            <span style=\"color: navy\">// </span><span style=\"color: green\">The patient reference is already relative (&quot;Patient/1051&quot;), which</span>\r\n            <span style=\"color: navy\">// </span><span style=\"color: green\">is exactly what a transaction entry URL wants.</span>\r\n            sref<span style=\"color: navy\"><b> -&gt; </b></span>request.url = <span style=\"color: maroon\">sref</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          aAt.value<b> as </b><span style=\"color: maroon\">dv</span><span style=\"color: navy\"><b> -&gt; </b></span>params.parameter<b> as </b><span style=\"color: maroon\">op</span><b> then</b><span style=\"color: navy\"> {\r\n</span>            aAt<span style=\"color: navy\"><b> -&gt; </b></span>op.name = <span style=\"color: blue\">'operation'</span> <i>&quot;operationName&quot;</i><span style=\"color: navy\">;</span>\r\n            aAt<span style=\"color: navy\"><b> -&gt; </b></span>op.part<b> as </b><span style=\"color: maroon\">partType</span><b> then</b><span style=\"color: navy\"> {\r\n</span>              aAt<span style=\"color: navy\"><b> -&gt; </b></span>partType.name = <span style=\"color: blue\">'type'</span> <i>&quot;typeName&quot;</i><span style=\"color: navy\">;</span>\r\n              aAt<span style=\"color: navy\"><b> -&gt; </b></span>partType.value = <span style=\"color: blue\">'add'</span> <i>&quot;typeValue&quot;</i><span style=\"color: navy\">;</span>\r\n            <span style=\"color: navy\">}</span> <i>&quot;operationType&quot;</i><span style=\"color: navy\">;</span>\r\n            aAt<span style=\"color: navy\"><b> -&gt; </b></span>op.part<b> as </b><span style=\"color: maroon\">partPath</span><b> then</b><span style=\"color: navy\"> {\r\n</span>              aAt<span style=\"color: navy\"><b> -&gt; </b></span>partPath.name = <span style=\"color: blue\">'path'</span> <i>&quot;pathName&quot;</i><span style=\"color: navy\">;</span>\r\n              aAt<span style=\"color: navy\"><b> -&gt; </b></span>partPath.value = <span style=\"color: blue\">'Patient'</span> <i>&quot;pathValue&quot;</i><span style=\"color: navy\">;</span>\r\n            <span style=\"color: navy\">}</span> <i>&quot;operationPath&quot;</i><span style=\"color: navy\">;</span>\r\n            aAt<span style=\"color: navy\"><b> -&gt; </b></span>op.part<b> as </b><span style=\"color: maroon\">partName</span><b> then</b><span style=\"color: navy\"> {\r\n</span>              aAt<span style=\"color: navy\"><b> -&gt; </b></span>partName.name = <span style=\"color: blue\">'name'</span> <i>&quot;nameName&quot;</i><span style=\"color: navy\">;</span>\r\n              aAt<span style=\"color: navy\"><b> -&gt; </b></span>partName.value = <span style=\"color: blue\">'deceasedDateTime'</span> <i>&quot;nameValue&quot;</i><span style=\"color: navy\">;</span>\r\n            <span style=\"color: navy\">}</span> <i>&quot;operationElement&quot;</i><span style=\"color: navy\">;</span>\r\n            aAt<span style=\"color: navy\"><b> -&gt; </b></span>op.part<b> as </b><span style=\"color: maroon\">partValue</span><b> then</b><span style=\"color: navy\"> {\r\n</span>              aAt<span style=\"color: navy\"><b> -&gt; </b></span>partValue.name = <span style=\"color: blue\">'value'</span> <i>&quot;valueName&quot;</i><span style=\"color: navy\">;</span>\r\n              dv<span style=\"color: navy\"><b> -&gt; </b></span>partValue.value = <span style=\"color: maroon\">dv</span> <i>&quot;valueValue&quot;</i><span style=\"color: navy\">;</span>\r\n            <span style=\"color: navy\">}</span> <i>&quot;operationValue&quot;</i><span style=\"color: navy\">;</span>\r\n          <span style=\"color: navy\">}</span> <i>&quot;operation&quot;</i><span style=\"color: navy\">;</span>\r\n        <span style=\"color: navy\">}</span> <i>&quot;patientPatch&quot;</i><span style=\"color: navy\">;</span>\r\n      <span style=\"color: navy\">}</span> <i>&quot;patientSubject&quot;</i><span style=\"color: navy\">;</span>\r\n    <span style=\"color: navy\">}</span> <i>&quot;confirmedAtAnswer&quot;</i><span style=\"color: navy\">;</span>\r\n  <span style=\"color: navy\">}</span> <i>&quot;deceasedPatchRule&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 note scaffolding. Repeated in each note map rather than imported: the</span>\r\n<span style=\"color: navy\">// </span><span style=\"color: green\">transform engine resolves `imports` against whatever StructureMaps happen to</span>\r\n<span style=\"color: navy\">// </span><span style=\"color: green\">be on the server, and a note that stops extracting because a shared map was</span>\r\n<span style=\"color: navy\">// </span><span style=\"color: green\">not uploaded is a worse failure than a duplicated group.</span>\r\n<span style=\"color: navy\">// </span><span style=\"color: green\">─────────────────────────────────────────────────────────────────────────────</span>\r\n<span style=\"color: navy\">// </span><span style=\"color: green\">Two notes on what the publisher's StructureMap validator says about this file.</span>\r\n<span style=\"color: navy\">// </span><span style=\"color: green\">Source parameters below are left untyped on purpose. Writing `: Element` makes</span>\r\n<span style=\"color: navy\">// </span><span style=\"color: green\">the validator compare QuestionnaireResponse.item against the literal 'Element'</span>\r\n<span style=\"color: navy\">// </span><span style=\"color: green\">and report them as incompatible with each other, which is noise, not a finding.</span>\r\n<span style=\"color: navy\">// </span><span style=\"color: green\">Untyped, it says only that it cannot check the paths.</span>\r\n<span style=\"color: navy\">// </span><span style=\"color: green\">`evaluate(context, expression)` is flagged as &quot;takes 1 parameter but 2 were</span>\r\n<span style=\"color: navy\">// </span><span style=\"color: green\">found&quot;. Leave it. The FML parser in the same jar refuses the one-argument form</span>\r\n<span style=\"color: navy\">// </span><span style=\"color: green\">outright -- it wants a parameter, a comma, then the FHIRPath -- so the publisher</span>\r\n<span style=\"color: navy\">// </span><span style=\"color: green\">is objecting to what its own compiler emits. Two arguments is the only form that</span>\r\n<span style=\"color: navy\">// </span><span style=\"color: green\">compiles, and it is what the R5 transform engine executes.</span>\r\n<b>group </b>BuildNoteBase<span style=\"color: navy\">(</span><b>source</b> <span style=\"color: maroon\">qr</span><span style=\"color: navy\"> : </span>QR, <b>target</b> <span style=\"color: maroon\">comp</span><span style=\"color: navy\"> : </span>Composition, <b>target</b> <span style=\"color: maroon\">entry</span><span style=\"color: navy\">)</span><span style=\"color: navy\"> {\r\n</span>  qr<span style=\"color: navy\"><b> -&gt; </b></span>comp.id = <b>uuid</b><span style=\"color: navy\">(</span><span style=\"color: navy\">)</span><b> then </b>SetCompositionFullUrl<span style=\"color: navy\">(</span><span style=\"color: maroon\">comp</span><span style=\"color: navy\">, </span><span style=\"color: maroon\">entry</span><span style=\"color: navy\">)</span> <i>&quot;idAndFullUrl&quot;</i><span style=\"color: navy\">;</span>\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\">'Composition'</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<span style=\"color: navy\"><b> -&gt; </b></span>comp.status = <span style=\"color: blue\">'final'</span> <i>&quot;status&quot;</i><span style=\"color: navy\">;</span>\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.contains('://').not() and reference.startsWith('#').not() and reference.startsWith('urn:').not())) or reference.empty()<span style=\"color: navy\">)</span><span style=\"color: navy\"><b> -&gt; </b></span>comp.subject = <span style=\"color: maroon\">s</span><span style=\"color: navy\">;</span>\r\n  qr.encounter<b> as </b><span style=\"color: maroon\">e</span><b> where </b><span style=\"color: navy\">(</span>(reference.exists() and (reference.startsWith('Encounter/'))) or (reference.empty() and (type.empty() or ('/' + type).endsWith('/Encounter')))<span style=\"color: navy\">)</span><span style=\"color: navy\"><b> -&gt; </b></span>comp.encounter = <span style=\"color: maroon\">e</span><span style=\"color: navy\">;</span>\r\n  <span style=\"color: navy\">// </span><span style=\"color: green\">Composition.date is 1..1. `authored` is only 0..1 on the response, so when a</span>\r\n  <span style=\"color: navy\">// </span><span style=\"color: green\">client sends none the extraction time stands in. It is a poor substitute for</span>\r\n  <span style=\"color: navy\">// </span><span style=\"color: green\">when the note was written, but a document with no date at all is worse, and</span>\r\n  <span style=\"color: navy\">// </span><span style=\"color: green\">extraction happens moments after submission in practice.</span>\r\n  qr.authored<b> as </b><span style=\"color: maroon\">t</span><span style=\"color: navy\"><b> -&gt; </b></span>comp.date = <span style=\"color: maroon\">t</span> <i>&quot;date&quot;</i><span style=\"color: navy\">;</span>\r\n  qr<b> where </b><span style=\"color: navy\">(</span>authored.exists().not()<span style=\"color: navy\">)</span><b> then</b><span style=\"color: navy\"> {\r\n</span>    qr<span style=\"color: navy\"><b> -&gt; </b></span>comp.date = evaluate<span style=\"color: navy\">(</span>qr<span style=\"color: navy\">, </span>now()<span style=\"color: navy\">)</span> <i>&quot;dateFromExtractionTime&quot;</i><span style=\"color: navy\">;</span>\r\n  <span style=\"color: navy\">}</span> <i>&quot;dateFallback&quot;</i><span style=\"color: navy\">;</span>\r\n  <span style=\"color: navy\">// </span><span style=\"color: green\">Composition.author is 1..1 minimum. R5 QuestionnaireResponse carries both</span>\r\n  <span style=\"color: navy\">// </span><span style=\"color: green\">`author` (who recorded the answers) and `source` (who supplied them); the</span>\r\n  <span style=\"color: navy\">// </span><span style=\"color: green\">author is the one who wrote the note, so it wins, and `source` only stands</span>\r\n  <span style=\"color: navy\">// </span><span style=\"color: green\">in when the client did not send an author. If the response carries neither,</span>\r\n  <span style=\"color: navy\">// </span><span style=\"color: green\">the note comes out unauthored -- there is nothing on a QuestionnaireResponse</span>\r\n  <span style=\"color: navy\">// </span><span style=\"color: green\">to invent one from, and guessing at who wrote a clinical note is not a thing</span>\r\n  <span style=\"color: navy\">// </span><span style=\"color: green\">a map should do.</span>\r\n  qr.author<b> as </b><span style=\"color: maroon\">a</span><b> where </b><span style=\"color: navy\">(</span>(reference.exists() and (reference.startsWith('Patient/') or reference.startsWith('Organization/'))) or (reference.empty() and (type.empty() or ('/' + type).endsWith('/Patient') or ('/' + type).endsWith('/Organization')))<span style=\"color: navy\">)</span><span style=\"color: navy\"><b> -&gt; </b></span>comp.author = <span style=\"color: maroon\">a</span> <i>&quot;authorFromAuthor&quot;</i><span style=\"color: navy\">;</span>\r\n  qr<b> where </b><span style=\"color: navy\">(</span>author.where(((reference.exists() and (reference.startsWith('Patient/') or reference.startsWith('Organization/'))) or (reference.empty() and (type.empty() or ('/' + type).endsWith('/Patient') or ('/' + type).endsWith('/Organization'))))).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('Patient/') or reference.startsWith('Organization/'))) or (reference.empty() and (type.empty() or ('/' + type).endsWith('/Patient') or ('/' + type).endsWith('/Organization')))<span style=\"color: navy\">)</span><span style=\"color: navy\"><b> -&gt; </b></span>comp.author = <span style=\"color: maroon\">src</span> <i>&quot;authorFromSource&quot;</i><span style=\"color: navy\">;</span>\r\n  <span style=\"color: navy\">}</span> <i>&quot;authorFallback&quot;</i><span style=\"color: navy\">;</span>\r\n  qr<span style=\"color: navy\"><b> -&gt; </b></span>comp.relatesTo<b> as </b><span style=\"color: maroon\">rel</span><b> then</b><span style=\"color: navy\"> {\r\n</span>    qr<span style=\"color: navy\"><b> -&gt; </b></span>rel.type = <span style=\"color: blue\">'derived-from'</span> <i>&quot;relatesToType&quot;</i><span style=\"color: navy\">;</span>\r\n    qr<span style=\"color: navy\"><b> -&gt; </b></span>rel.resourceReference = <b>create</b><span style=\"color: navy\">(</span><span style=\"color: blue\">'Reference'</span><span style=\"color: navy\">)</span><b> as </b><span style=\"color: maroon\">ref</span><b> then</b><span style=\"color: navy\"> {\r\n</span>      qr.id<b> as </b><span style=\"color: maroon\">qid</span><span style=\"color: navy\"><b> -&gt; </b></span>ref.reference = <span style=\"color: maroon\">qid</span> <i>&quot;relatesToRef&quot;</i><span style=\"color: navy\">;</span>\r\n    <span style=\"color: navy\">}</span> <i>&quot;relatesToTarget&quot;</i><span style=\"color: navy\">;</span>\r\n  <span style=\"color: navy\">}</span> <i>&quot;linkQuestionnaireResponse&quot;</i><span style=\"color: navy\">;</span>\r\n<span style=\"color: navy\">}\r\n\r\n</span><b>group </b>AddSectionText<span style=\"color: navy\">(</span><b>source</b> <span style=\"color: maroon\">it</span>, <b>target</b> <span style=\"color: maroon\">sec</span><span style=\"color: navy\">)</span><span style=\"color: navy\"> {\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\">v</span><span style=\"color: navy\"><b> -&gt; </b></span>sec.text<b> as </b><span style=\"color: maroon\">narrative</span><b> then</b><span style=\"color: navy\"> {\r\n</span>      v<span style=\"color: navy\"><b> -&gt; </b></span>narrative.status = <span style=\"color: blue\">'generated'</span> <i>&quot;narrativeStatus&quot;</i><span style=\"color: navy\">;</span>\r\n      v<span style=\"color: navy\"><b> -&gt; </b></span>narrative.div = <b>create</b><span style=\"color: navy\">(</span><span style=\"color: blue\">'xhtml'</span><span style=\"color: navy\">)</span><b> as </b><span style=\"color: maroon\">xhtml</span><b> then</b><span style=\"color: navy\"> {\r\n</span>        v<span style=\"color: navy\"><b> -&gt; </b></span>xhtml.value = evaluate<span style=\"color: navy\">(</span>a<span style=\"color: navy\">, </span>'&lt;div xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;&lt;p&gt;' + value.toString().escape('html') + '&lt;/p&gt;&lt;/div&gt;'<span style=\"color: navy\">)</span> <i>&quot;narrativeDiv&quot;</i><span style=\"color: navy\">;</span>\r\n      <span style=\"color: navy\">}</span> <i>&quot;narrativeXhtml&quot;</i><span style=\"color: navy\">;</span>\r\n    <span style=\"color: navy\">}</span> <i>&quot;sectionText&quot;</i><span style=\"color: navy\">;</span>\r\n  <span style=\"color: navy\">}</span> <i>&quot;sectionAnswer&quot;</i><span style=\"color: navy\">;</span>\r\n<span style=\"color: navy\">}\r\n\r\n</span><b>group </b>SetCompositionFullUrl<span style=\"color: navy\">(</span><b>source</b> <span style=\"color: maroon\">comp</span><span style=\"color: navy\"> : </span>Composition, <b>target</b> <span style=\"color: maroon\">entry</span><span style=\"color: navy\">)</span><span style=\"color: navy\"> {\r\n</span>  comp.id<b> as </b><span style=\"color: maroon\">id</span><span style=\"color: navy\"><b> -&gt; </b></span>entry.fullUrl = <b>append</b><span style=\"color: navy\">(</span><span style=\"color: blue\">'https://fhir.slade360.co.ke/fhir/Composition/'</span><span style=\"color: navy\">, </span><span style=\"color: maroon\">id</span><span style=\"color: navy\">)</span> <i>&quot;assignFullUrl&quot;</i><span style=\"color: navy\">;</span>\r\n<span style=\"color: navy\">}\r\n\r\n</span><b>group </b>BuildConditionBase<span style=\"color: navy\">(</span><b>source</b> <span style=\"color: maroon\">qr</span><span style=\"color: navy\"> : </span>QR, <b>target</b> <span style=\"color: maroon\">cond</span><span style=\"color: navy\"> : </span>Condition, <b>target</b> <span style=\"color: maroon\">entry</span><span style=\"color: navy\">)</span><span style=\"color: navy\"> {\r\n</span>  qr<span style=\"color: navy\"><b> -&gt; </b></span>cond.id = <b>uuid</b><span style=\"color: navy\">(</span><span style=\"color: navy\">)</span><b> then </b>SetConditionFullUrl<span style=\"color: navy\">(</span><span style=\"color: maroon\">cond</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\">'Condition'</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<span style=\"color: navy\"><b> -&gt; </b></span>cond.clinicalStatus<b> as </b><span style=\"color: maroon\">cs</span><b> then</b><span style=\"color: navy\"> {\r\n</span>    qr<span style=\"color: navy\"><b> -&gt; </b></span>cs.coding<b> as </b><span style=\"color: maroon\">csc</span><b> then</b><span style=\"color: navy\"> {\r\n</span>      qr<span style=\"color: navy\"><b> -&gt; </b></span>csc.system = <span style=\"color: blue\">'http://terminology.hl7.org/CodeSystem/condition-clinical'</span> <i>&quot;clinSystem&quot;</i><span style=\"color: navy\">;</span>\r\n      qr<span style=\"color: navy\"><b> -&gt; </b></span>csc.code = <span style=\"color: blue\">'active'</span> <i>&quot;clinCode&quot;</i><span style=\"color: navy\">;</span>\r\n      qr<span style=\"color: navy\"><b> -&gt; </b></span>csc.display = <span style=\"color: blue\">'Active'</span> <i>&quot;clinDisplay&quot;</i><span style=\"color: navy\">;</span>\r\n    <span style=\"color: navy\">}</span> <i>&quot;clinCoding&quot;</i><span style=\"color: navy\">;</span>\r\n  <span style=\"color: navy\">}</span> <i>&quot;clinicalStatus&quot;</i><span style=\"color: navy\">;</span>\r\n  qr<span style=\"color: navy\"><b> -&gt; </b></span>cond.category<b> as </b><span style=\"color: maroon\">cat</span><b> then</b><span style=\"color: navy\"> {\r\n</span>    qr<span style=\"color: navy\"><b> -&gt; </b></span>cat.coding<b> as </b><span style=\"color: maroon\">catc</span><b> then</b><span style=\"color: navy\"> {\r\n</span>      qr<span style=\"color: navy\"><b> -&gt; </b></span>catc.system = <span style=\"color: blue\">'http://terminology.hl7.org/CodeSystem/condition-category'</span> <i>&quot;catSystem&quot;</i><span style=\"color: navy\">;</span>\r\n      qr<span style=\"color: navy\"><b> -&gt; </b></span>catc.code = <span style=\"color: blue\">'encounter-diagnosis'</span> <i>&quot;catCode&quot;</i><span style=\"color: navy\">;</span>\r\n      qr<span style=\"color: navy\"><b> -&gt; </b></span>catc.display = <span style=\"color: blue\">'Encounter Diagnosis'</span> <i>&quot;catDisplay&quot;</i><span style=\"color: navy\">;</span>\r\n    <span style=\"color: navy\">}</span> <i>&quot;catCoding&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  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>cond.subject = <span style=\"color: maroon\">s</span><span style=\"color: navy\">;</span>\r\n  qr.encounter<b> as </b><span style=\"color: maroon\">e</span><b> where </b><span style=\"color: navy\">(</span>(reference.exists() and (reference.startsWith('Encounter/'))) or (reference.empty() and (type.empty() or ('/' + type).endsWith('/Encounter')))<span style=\"color: navy\">)</span><span style=\"color: navy\"><b> -&gt; </b></span>cond.encounter = <span style=\"color: maroon\">e</span><span style=\"color: navy\">;</span>\r\n  qr.authored<b> as </b><span style=\"color: maroon\">t</span><span style=\"color: navy\"><b> -&gt; </b></span>cond.recordedDate = <span style=\"color: maroon\">t</span> <i>&quot;recordedDate&quot;</i><span style=\"color: navy\">;</span>\r\n  qr.author<b> as </b><span style=\"color: maroon\">a</span><b> where </b><span style=\"color: navy\">(</span>(reference.exists() and (reference.startsWith('Patient/') or reference.startsWith('Organization/'))) or (reference.empty() and (type.empty() or ('/' + type).endsWith('/Patient') or ('/' + type).endsWith('/Organization')))<span style=\"color: navy\">)</span><span style=\"color: navy\"><b> -&gt; </b></span>cond.participant<b> as </b><span style=\"color: maroon\">part</span><b> then</b><span style=\"color: navy\"> {\r\n</span>    qr<span style=\"color: navy\"><b> -&gt; </b></span>part.actor = <span style=\"color: maroon\">a</span> <i>&quot;participantActor&quot;</i><span style=\"color: navy\">;</span>\r\n  <span style=\"color: navy\">}</span> <i>&quot;participantFromAuthor&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('Patient/') or reference.startsWith('Organization/'))) or (reference.empty() and (type.empty() or ('/' + type).endsWith('/Patient') or ('/' + type).endsWith('/Organization'))))).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('Patient/') or reference.startsWith('Organization/'))) or (reference.empty() and (type.empty() or ('/' + type).endsWith('/Patient') or ('/' + type).endsWith('/Organization')))<span style=\"color: navy\">)</span><span style=\"color: navy\"><b> -&gt; </b></span>cond.participant<b> as </b><span style=\"color: maroon\">part2</span><b> then</b><span style=\"color: navy\"> {\r\n</span>      qr<span style=\"color: navy\"><b> -&gt; </b></span>part2.actor = <span style=\"color: maroon\">src</span> <i>&quot;participantActorFromSource&quot;</i><span style=\"color: navy\">;</span>\r\n    <span style=\"color: navy\">}</span> <i>&quot;participantFromSource&quot;</i><span style=\"color: navy\">;</span>\r\n  <span style=\"color: navy\">}</span> <i>&quot;participantFallback&quot;</i><span style=\"color: navy\">;</span>\r\n  qr<span style=\"color: navy\"><b> -&gt; </b></span>cond.evidence<b> as </b><span style=\"color: maroon\">ev</span><b> then</b><span style=\"color: navy\"> {\r\n</span>    qr<span style=\"color: navy\"><b> -&gt; </b></span>ev.reference = <b>create</b><span style=\"color: navy\">(</span><span style=\"color: blue\">'Reference'</span><span style=\"color: navy\">)</span><b> as </b><span style=\"color: maroon\">ref</span><b> then</b><span style=\"color: navy\"> {\r\n</span>      qr.id<b> as </b><span style=\"color: maroon\">qid</span><span style=\"color: navy\"><b> -&gt; </b></span>ref.reference = <span style=\"color: maroon\">qid</span> <i>&quot;evidenceRef&quot;</i><span style=\"color: navy\">;</span>\r\n    <span style=\"color: navy\">}</span> <i>&quot;evidenceTarget&quot;</i><span style=\"color: navy\">;</span>\r\n  <span style=\"color: navy\">}</span> <i>&quot;linkQuestionnaireResponse&quot;</i><span style=\"color: navy\">;</span>\r\n<span style=\"color: navy\">}\r\n\r\n</span><b>group </b>SetConditionFullUrl<span style=\"color: navy\">(</span><b>source</b> <span style=\"color: maroon\">cond</span><span style=\"color: navy\"> : </span>Condition, <b>target</b> <span style=\"color: maroon\">entry</span><span style=\"color: navy\">)</span><span style=\"color: navy\"> {\r\n</span>  cond.id<b> as </b><span style=\"color: maroon\">id</span><span style=\"color: navy\"><b> -&gt; </b></span>entry.fullUrl = <b>append</b><span style=\"color: navy\">(</span><span style=\"color: blue\">'https://fhir.slade360.co.ke/fhir/Condition/'</span><span style=\"color: navy\">, </span><span style=\"color: maroon\">id</span><span style=\"color: navy\">)</span> <i>&quot;assignFullUrl&quot;</i><span style=\"color: navy\">;</span>\r\n<span style=\"color: navy\">}\r\n\r\n</span><span style=\"color: navy\">// </span><span style=\"color: green\">── Tenancy ──────────────────────────────────────────────────────────────────</span>\r\n<span style=\"color: navy\">// </span><span style=\"color: green\">Whose this is. The platform says which tenant a response belongs to with a</span>\r\n<span style=\"color: navy\">// </span><span style=\"color: green\">tag on the response, and every tag the response carries is copied onto</span>\r\n<span style=\"color: navy\">// </span><span style=\"color: green\">everything this map creates, as it is. Copied rather than named here, so the</span>\r\n<span style=\"color: navy\">// </span><span style=\"color: green\">map never has to know which tenant it is running for, nor which system the</span>\r\n<span style=\"color: navy\">// </span><span style=\"color: green\">tag is under: that system has moved more than once.</span>\r\n<b>group </b>CopyResponseTags<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.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\">}\r\n\r\n</span></pre></div>"^^rdf:XMLLiteral ]
  ] ; # 
  fhir:url [ fhir:v "https://fhir.slade360.co.ke/fhir/StructureMap/ExtractInpatientDeathNote"^^xsd:anyURI] ; # 
  fhir:version [ fhir:v "0.1.0"] ; # 
  fhir:name [ fhir:v "ExtractInpatientDeathNote"] ; # 
  fhir:title [ fhir:v "Inpatient Death Note 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 richest of the seven notes, and the only one that changes a record that already exists. It produces a Composition attested by the clinician who confirmed the death, a Condition carrying the cause as stated, and a FHIRPath PATCH that sets Patient.deceasedDateTime. The PATCH touches that one element and nothing else -- the response carries no demographics, so rebuilding and PUTting the Patient would erase the record. Note this uses the `add` operation: extracting the same death note twice will fail the second time rather than silently overwrite, which is the safer direction for a fact recorded once."] ; # 
  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/Composition"^^xsd:anyURI ;
       fhir:link <http://hl7.org/fhir/StructureDefinition/Composition>
     ] ;
     fhir:mode [ fhir:v "target" ] ;
     fhir:alias [ fhir:v "Composition" ]
  ] [
     fhir:url [
       fhir:v "http://hl7.org/fhir/StructureDefinition/Condition"^^xsd:anyURI ;
       fhir:link <http://hl7.org/fhir/StructureDefinition/Condition>
     ] ;
     fhir:mode [ fhir:v "target" ] ;
     fhir:alias [ fhir:v "Condition" ]
  ] [
     fhir:url [
       fhir:v "http://hl7.org/fhir/StructureDefinition/Parameters"^^xsd:anyURI ;
       fhir:link <http://hl7.org/fhir/StructureDefinition/Parameters>
     ] ;
     fhir:mode [ fhir:v "target" ] ;
     fhir:alias [ fhir:v "Parameters" ]
  ] ) ; # 
  fhir:group ( [
     fhir:name [ fhir:v "ExtractInpatientDeathNote" ] ;
     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 "composition" ] ;
       fhir:source ( [
         fhir:context [ fhir:v "qr" ]
       ] ) ;
       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 "comp" ] ;
         fhir:transform [ fhir:v "create" ] ;
         fhir:parameter ( [
           fhir:value [
             a fhir:string ;
             fhir:v "Composition"
           ]
         ] )
       ] ) ;
       fhir:rule ( [
         fhir:name [ fhir:v "responseTags" ] ;
         fhir:source ( [
           fhir:context [ fhir:v "qr" ]
         ] ) ;
         fhir:target ( [
           fhir:context [ fhir:v "comp" ]
         ] ) ;
         fhir:dependent ( [
           fhir:name [ fhir:v "CopyResponseTags" ] ;
           fhir:parameter ( [
             fhir:value [
               a fhir:id ;
               fhir:v "qr"
             ]
           ] [
             fhir:value [
               a fhir:id ;
               fhir:v "comp"
             ]
           ] )
         ] )
       ] [
         fhir:name [ fhir:v "noteBase" ] ;
         fhir:source ( [
           fhir:context [ fhir:v "qr" ]
         ] ) ;
         fhir:target ( [
           fhir:context [ fhir:v "comp" ]
         ] [
           fhir:context [ fhir:v "entry" ]
         ] ) ;
         fhir:dependent ( [
           fhir:name [ fhir:v "BuildNoteBase" ] ;
           fhir:parameter ( [
             fhir:value [
               a fhir:id ;
               fhir:v "qr"
             ]
           ] [
             fhir:value [
               a fhir:id ;
               fhir:v "comp"
             ]
           ] [
             fhir:value [
               a fhir:id ;
               fhir:v "entry"
             ]
           ] )
         ] )
       ] [
         fhir:name [ fhir:v "noteName" ] ;
         fhir:source ( [
           fhir:context [ fhir:v "qr" ]
         ] ) ;
         fhir:target ( [
           fhir:context [ fhir:v "comp" ] ;
           fhir:element [ fhir:v "name" ] ;
           fhir:transform [ fhir:v "copy" ] ;
           fhir:parameter ( [
             fhir:value [
               a fhir:string ;
               fhir:v "InpatientDeathNote"
             ]
           ] )
         ] )
       ] [
         fhir:name [ fhir:v "noteTitle" ] ;
         fhir:source ( [
           fhir:context [ fhir:v "qr" ]
         ] ) ;
         fhir:target ( [
           fhir:context [ fhir:v "comp" ] ;
           fhir:element [ fhir:v "title" ] ;
           fhir:transform [ fhir:v "copy" ] ;
           fhir:parameter ( [
             fhir:value [
               a fhir:string ;
               fhir:v "Death note"
             ]
           ] )
         ] )
       ] [
         fhir:name [ fhir:v "noteType" ] ;
         fhir:source ( [
           fhir:context [ fhir:v "qr" ]
         ] ) ;
         fhir:target ( [
           fhir:context [ fhir:v "comp" ] ;
           fhir:element [ fhir:v "type" ] ;
           fhir:variable [ fhir:v "ty" ]
         ] ) ;
         fhir:rule ( [
           fhir:name [ fhir:v "sghiCoding" ] ;
           fhir:source ( [
             fhir:context [ fhir:v "qr" ]
           ] ) ;
           fhir:target ( [
             fhir:context [ fhir:v "ty" ] ;
             fhir:element [ fhir:v "coding" ] ;
             fhir:variable [ fhir:v "sghi" ]
           ] ) ;
           fhir:rule ( [
             fhir:name [ fhir:v "sghiSystem" ] ;
             fhir:source ( [
               fhir:context [ fhir:v "qr" ]
             ] ) ;
             fhir:target ( [
               fhir:context [ fhir:v "sghi" ] ;
               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/inpatient-document-type-codesystem"
                 ]
               ] )
             ] )
           ] [
             fhir:name [ fhir:v "sghiCode" ] ;
             fhir:source ( [
               fhir:context [ fhir:v "qr" ]
             ] ) ;
             fhir:target ( [
               fhir:context [ fhir:v "sghi" ] ;
               fhir:element [ fhir:v "code" ] ;
               fhir:transform [ fhir:v "copy" ] ;
               fhir:parameter ( [
                 fhir:value [
                   a fhir:string ;
                   fhir:v "death-note"
                 ]
               ] )
             ] )
           ] [
             fhir:name [ fhir:v "sghiDisplay" ] ;
             fhir:source ( [
               fhir:context [ fhir:v "qr" ]
             ] ) ;
             fhir:target ( [
               fhir:context [ fhir:v "sghi" ] ;
               fhir:element [ fhir:v "display" ] ;
               fhir:transform [ fhir:v "copy" ] ;
               fhir:parameter ( [
                 fhir:value [
                   a fhir:string ;
                   fhir:v "Death note"
                 ]
               ] )
             ] )
           ] )
         ] [
           fhir:name [ fhir:v "typeText" ] ;
           fhir:source ( [
             fhir:context [ fhir:v "qr" ]
           ] ) ;
           fhir:target ( [
             fhir:context [ fhir:v "ty" ] ;
             fhir:element [ fhir:v "text" ] ;
             fhir:transform [ fhir:v "copy" ] ;
             fhir:parameter ( [
               fhir:value [
                 a fhir:string ;
                 fhir:v "Death note"
               ]
             ] )
           ] )
         ] ) ;
         fhir:documentation [ fhir:v "Deliberately not LOINC 64297-5. That code is the civil death certificate,\r\na different document with a different author and a different audience." ]
       ] [
         fhir:name [ fhir:v "confirmedByRule" ] ;
         fhir:source ( [
           fhir:context [ fhir:v "qr" ] ;
           fhir:element [ fhir:v "item" ] ;
           fhir:variable [ fhir:v "itC" ] ;
           fhir:condition [ fhir:v "linkId = 'confirmedBy'" ]
         ] ) ;
         fhir:rule ( [
           fhir:name [ fhir:v "confirmedByAnswer" ] ;
           fhir:source ( [
             fhir:context [ fhir:v "itC" ] ;
             fhir:element [ fhir:v "answer" ] ;
             fhir:variable [ fhir:v "aC" ]
           ] ) ;
           fhir:rule ( [
             fhir:name [ fhir:v "attester" ] ;
             fhir:source ( [
               fhir:context [ fhir:v "aC" ] ;
               fhir:element [ fhir:v "value" ] ;
               fhir:variable [ fhir:v "cv" ]
             ] ) ;
             fhir:target ( [
               fhir:context [ fhir:v "comp" ] ;
               fhir:element [ fhir:v "attester" ] ;
               fhir:variable [ fhir:v "att" ]
             ] ) ;
             fhir:rule ( [
               fhir:name [ fhir:v "attesterMode" ] ;
               fhir:source ( [
                 fhir:context [ fhir:v "aC" ]
               ] ) ;
               fhir:target ( [
                 fhir:context [ fhir:v "att" ] ;
                 fhir:element [ fhir:v "mode" ] ;
                 fhir:variable [ fhir:v "mode" ]
               ] ) ;
               fhir:rule ( [
                 fhir:name [ fhir:v "attModeCoding" ] ;
                 fhir:source ( [
                   fhir:context [ fhir:v "aC" ]
                 ] ) ;
                 fhir:target ( [
                   fhir:context [ fhir:v "mode" ] ;
                   fhir:element [ fhir:v "coding" ] ;
                   fhir:variable [ fhir:v "modec" ]
                 ] ) ;
                 fhir:rule ( [
                   fhir:name [ fhir:v "attModeSystem" ] ;
                   fhir:source ( [
                     fhir:context [ fhir:v "aC" ]
                   ] ) ;
                   fhir:target ( [
                     fhir:context [ fhir:v "modec" ] ;
                     fhir:element [ fhir:v "system" ] ;
                     fhir:transform [ fhir:v "copy" ] ;
                     fhir:parameter ( [
                       fhir:value [
                         a fhir:string ;
                         fhir:v "http://hl7.org/fhir/composition-attestation-mode"
                       ]
                     ] )
                   ] )
                 ] [
                   fhir:name [ fhir:v "attModeCode" ] ;
                   fhir:source ( [
                     fhir:context [ fhir:v "aC" ]
                   ] ) ;
                   fhir:target ( [
                     fhir:context [ fhir:v "modec" ] ;
                     fhir:element [ fhir:v "code" ] ;
                     fhir:transform [ fhir:v "copy" ] ;
                     fhir:parameter ( [
                       fhir:value [
                         a fhir:string ;
                         fhir:v "professional"
                       ]
                     ] )
                   ] )
                 ] [
                   fhir:name [ fhir:v "attModeDisplay" ] ;
                   fhir:source ( [
                     fhir:context [ fhir:v "aC" ]
                   ] ) ;
                   fhir:target ( [
                     fhir:context [ fhir:v "modec" ] ;
                     fhir:element [ fhir:v "display" ] ;
                     fhir:transform [ fhir:v "copy" ] ;
                     fhir:parameter ( [
                       fhir:value [
                         a fhir:string ;
                         fhir:v "Professional"
                       ]
                     ] )
                   ] )
                 ] )
               ] )
             ] [
               fhir:name [ fhir:v "attesterTimeRule" ] ;
               fhir:source ( [
                 fhir:context [ fhir:v "qr" ] ;
                 fhir:element [ fhir:v "item" ] ;
                 fhir:variable [ fhir:v "itT" ] ;
                 fhir:condition [ fhir:v "linkId = 'confirmedAt'" ]
               ] ) ;
               fhir:rule ( [
                 fhir:name [ fhir:v "confirmedAtAnswer" ] ;
                 fhir:source ( [
                   fhir:context [ fhir:v "itT" ] ;
                   fhir:element [ fhir:v "answer" ] ;
                   fhir:listMode [ fhir:v "first" ] ;
                   fhir:variable [ fhir:v "aT" ]
                 ] ) ;
                 fhir:rule ( [
                   fhir:name [ fhir:v "attesterTimeFromConfirmedAt" ] ;
                   fhir:source ( [
                     fhir:context [ fhir:v "aT" ] ;
                     fhir:element [ fhir:v "value" ] ;
                     fhir:variable [ fhir:v "tv" ]
                   ] ) ;
                   fhir:target ( [
                     fhir:context [ fhir:v "att" ] ;
                     fhir:element [ fhir:v "time" ] ;
                     fhir:transform [ fhir:v "copy" ] ;
                     fhir:parameter ( [
                       fhir:value [
                         a fhir:id ;
                         fhir:v "tv"
                       ]
                     ] )
                   ] )
                 ] )
               ] )
             ] [
               fhir:name [ fhir:v "attesterParty" ] ;
               fhir:source ( [
                 fhir:context [ fhir:v "cv" ] ;
                 fhir:condition [ fhir:v "(reference.exists() and (reference.startsWith('Patient/') or reference.startsWith('Organization/'))) or (reference.empty() and (type.empty() or ('/' + type).endsWith('/Patient') or ('/' + type).endsWith('/Organization')))" ]
               ] ) ;
               fhir:target ( [
                 fhir:context [ fhir:v "att" ] ;
                 fhir:element [ fhir:v "party" ] ;
                 fhir:transform [ fhir:v "copy" ] ;
                 fhir:parameter ( [
                   fhir:value [
                     a fhir:id ;
                     fhir:v "cv"
                   ]
                 ] )
               ] )
             ] )
           ] )
         ] ) ;
         fhir:documentation [ fhir:v "The clinician who confirmed the death attests the note." ]
       ] [
         fhir:name [ fhir:v "confirmedAtSectionRule" ] ;
         fhir:source ( [
           fhir:context [ fhir:v "qr" ] ;
           fhir:element [ fhir:v "item" ] ;
           fhir:variable [ fhir:v "it" ] ;
           fhir:condition [ fhir:v "(linkId = 'confirmedAt') and answer.value.exists()" ]
         ] ) ;
         fhir:target ( [
           fhir:context [ fhir:v "comp" ] ;
           fhir:element [ fhir:v "section" ] ;
           fhir:variable [ fhir:v "sec" ]
         ] ) ;
         fhir:rule ( [
           fhir:name [ fhir:v "confirmedAtTitle" ] ;
           fhir:source ( [
             fhir:context [ fhir:v "it" ]
           ] ) ;
           fhir:target ( [
             fhir:context [ fhir:v "sec" ] ;
             fhir:element [ fhir:v "title" ] ;
             fhir:transform [ fhir:v "copy" ] ;
             fhir:parameter ( [
               fhir:value [
                 a fhir:string ;
                 fhir:v "Death confirmed at"
               ]
             ] )
           ] )
         ] [
           fhir:name [ fhir:v "confirmedAtText" ] ;
           fhir:source ( [
             fhir:context [ fhir:v "it" ]
           ] ) ;
           fhir:target ( [
             fhir:context [ fhir:v "sec" ]
           ] ) ;
           fhir:dependent ( [
             fhir:name [ fhir:v "AddSectionText" ] ;
             fhir:parameter ( [
               fhir:value [
                 a fhir:id ;
                 fhir:v "it"
               ]
             ] [
               fhir:value [
                 a fhir:id ;
                 fhir:v "sec"
               ]
             ] )
           ] )
         ] ) ;
         fhir:documentation [ fhir:v "The confirmed-at time is on the Patient as a fact, and in the document as\r\na line, because a printed death note that does not say when is not a\r\ndeath note." ]
       ] [
         fhir:name [ fhir:v "circumstancesRule" ] ;
         fhir:source ( [
           fhir:context [ fhir:v "qr" ] ;
           fhir:element [ fhir:v "item" ] ;
           fhir:variable [ fhir:v "it" ] ;
           fhir:condition [ fhir:v "(linkId = 'circumstances') and answer.value.exists()" ]
         ] ) ;
         fhir:target ( [
           fhir:context [ fhir:v "comp" ] ;
           fhir:element [ fhir:v "section" ] ;
           fhir:variable [ fhir:v "sec" ]
         ] ) ;
         fhir:rule ( [
           fhir:name [ fhir:v "circumstancesTitle" ] ;
           fhir:source ( [
             fhir:context [ fhir:v "it" ]
           ] ) ;
           fhir:target ( [
             fhir:context [ fhir:v "sec" ] ;
             fhir:element [ fhir:v "title" ] ;
             fhir:transform [ fhir:v "copy" ] ;
             fhir:parameter ( [
               fhir:value [
                 a fhir:string ;
                 fhir:v "Circumstances"
               ]
             ] )
           ] )
         ] [
           fhir:name [ fhir:v "circumstancesText" ] ;
           fhir:source ( [
             fhir:context [ fhir:v "it" ]
           ] ) ;
           fhir:target ( [
             fhir:context [ fhir:v "sec" ]
           ] ) ;
           fhir:dependent ( [
             fhir:name [ fhir:v "AddSectionText" ] ;
             fhir:parameter ( [
               fhir:value [
                 a fhir:id ;
                 fhir:v "it"
               ]
             ] [
               fhir:value [
                 a fhir:id ;
                 fhir:v "sec"
               ]
             ] )
           ] )
         ] )
       ] [
         fhir:name [ fhir:v "causeSectionRule" ] ;
         fhir:source ( [
           fhir:context [ fhir:v "qr" ] ;
           fhir:element [ fhir:v "item" ] ;
           fhir:variable [ fhir:v "it" ] ;
           fhir:condition [ fhir:v "(linkId = 'causeStated') and answer.value.exists()" ]
         ] ) ;
         fhir:target ( [
           fhir:context [ fhir:v "comp" ] ;
           fhir:element [ fhir:v "section" ] ;
           fhir:variable [ fhir:v "sec" ]
         ] ) ;
         fhir:rule ( [
           fhir:name [ fhir:v "causeTitle" ] ;
           fhir:source ( [
             fhir:context [ fhir:v "it" ]
           ] ) ;
           fhir:target ( [
             fhir:context [ fhir:v "sec" ] ;
             fhir:element [ fhir:v "title" ] ;
             fhir:transform [ fhir:v "copy" ] ;
             fhir:parameter ( [
               fhir:value [
                 a fhir:string ;
                 fhir:v "Cause of death as stated"
               ]
             ] )
           ] )
         ] [
           fhir:name [ fhir:v "causeText" ] ;
           fhir:source ( [
             fhir:context [ fhir:v "it" ]
           ] ) ;
           fhir:target ( [
             fhir:context [ fhir:v "sec" ]
           ] ) ;
           fhir:dependent ( [
             fhir:name [ fhir:v "AddSectionText" ] ;
             fhir:parameter ( [
               fhir:value [
                 a fhir:id ;
                 fhir:v "it"
               ]
             ] [
               fhir:value [
                 a fhir:id ;
                 fhir:v "sec"
               ]
             ] )
           ] )
         ] )
       ] [
         fhir:name [ fhir:v "familyRule" ] ;
         fhir:source ( [
           fhir:context [ fhir:v "qr" ] ;
           fhir:element [ fhir:v "item" ] ;
           fhir:variable [ fhir:v "it" ] ;
           fhir:condition [ fhir:v "(linkId = 'familyInformed') and answer.value.exists()" ]
         ] ) ;
         fhir:target ( [
           fhir:context [ fhir:v "comp" ] ;
           fhir:element [ fhir:v "section" ] ;
           fhir:variable [ fhir:v "sec" ]
         ] ) ;
         fhir:rule ( [
           fhir:name [ fhir:v "familyTitle" ] ;
           fhir:source ( [
             fhir:context [ fhir:v "it" ]
           ] ) ;
           fhir:target ( [
             fhir:context [ fhir:v "sec" ] ;
             fhir:element [ fhir:v "title" ] ;
             fhir:transform [ fhir:v "copy" ] ;
             fhir:parameter ( [
               fhir:value [
                 a fhir:string ;
                 fhir:v "Family informed"
               ]
             ] )
           ] )
         ] [
           fhir:name [ fhir:v "familyText" ] ;
           fhir:source ( [
             fhir:context [ fhir:v "it" ]
           ] ) ;
           fhir:target ( [
             fhir:context [ fhir:v "sec" ]
           ] ) ;
           fhir:dependent ( [
             fhir:name [ fhir:v "AddSectionText" ] ;
             fhir:parameter ( [
               fhir:value [
                 a fhir:id ;
                 fhir:v "it"
               ]
             ] [
               fhir:value [
                 a fhir:id ;
                 fhir:v "sec"
               ]
             ] )
           ] )
         ] )
       ] )
     ] [
       fhir:name [ fhir:v "causeConditionRule" ] ;
       fhir:source ( [
         fhir:context [ fhir:v "qr" ] ;
         fhir:element [ fhir:v "item" ] ;
         fhir:variable [ fhir:v "itCause" ] ;
         fhir:condition [ fhir:v "(linkId = 'causeStated') and answer.value.exists()" ]
       ] ) ;
       fhir:rule ( [
         fhir:name [ fhir:v "causeAnswer" ] ;
         fhir:source ( [
           fhir:context [ fhir:v "itCause" ] ;
           fhir:element [ fhir:v "answer" ] ;
           fhir:listMode [ fhir:v "first" ] ;
           fhir:variable [ fhir:v "aCause" ]
         ] ) ;
         fhir:rule ( [
           fhir:name [ fhir:v "condition" ] ;
           fhir:source ( [
             fhir:context [ fhir:v "aCause" ]
           ] ) ;
           fhir:target ( [
             fhir:context [ fhir:v "bundle" ] ;
             fhir:element [ fhir:v "entry" ] ;
             fhir:variable [ fhir:v "entryC" ]
           ] [
             fhir:context [ fhir:v "entryC" ] ;
             fhir:element [ fhir:v "resource" ] ;
             fhir:variable [ fhir:v "cond" ] ;
             fhir:transform [ fhir:v "create" ] ;
             fhir:parameter ( [
               fhir:value [
                 a fhir:string ;
                 fhir:v "Condition"
               ]
             ] )
           ] ) ;
           fhir:rule ( [
             fhir:name [ fhir:v "responseTags" ] ;
             fhir:source ( [
               fhir:context [ fhir:v "qr" ]
             ] ) ;
             fhir:target ( [
               fhir:context [ fhir:v "cond" ]
             ] ) ;
             fhir:dependent ( [
               fhir:name [ fhir:v "CopyResponseTags" ] ;
               fhir:parameter ( [
                 fhir:value [
                   a fhir:id ;
                   fhir:v "qr"
                 ]
               ] [
                 fhir:value [
                   a fhir:id ;
                   fhir:v "cond"
                 ]
               ] )
             ] )
           ] [
             fhir:name [ fhir:v "conditionBase" ] ;
             fhir:source ( [
               fhir:context [ fhir:v "qr" ]
             ] ) ;
             fhir:target ( [
               fhir:context [ fhir:v "cond" ]
             ] [
               fhir:context [ fhir:v "entryC" ]
             ] ) ;
             fhir:dependent ( [
               fhir:name [ fhir:v "BuildConditionBase" ] ;
               fhir:parameter ( [
                 fhir:value [
                   a fhir:id ;
                   fhir:v "qr"
                 ]
               ] [
                 fhir:value [
                   a fhir:id ;
                   fhir:v "cond"
                 ]
               ] [
                 fhir:value [
                   a fhir:id ;
                   fhir:v "entryC"
                 ]
               ] )
             ] )
           ] [
             fhir:name [ fhir:v "verificationStatus" ] ;
             fhir:source ( [
               fhir:context [ fhir:v "qr" ]
             ] ) ;
             fhir:target ( [
               fhir:context [ fhir:v "cond" ] ;
               fhir:element [ fhir:v "verificationStatus" ] ;
               fhir:variable [ fhir:v "vs" ]
             ] ) ;
             fhir:rule ( [
               fhir:name [ fhir:v "verCoding" ] ;
               fhir:source ( [
                 fhir:context [ fhir:v "qr" ]
               ] ) ;
               fhir:target ( [
                 fhir:context [ fhir:v "vs" ] ;
                 fhir:element [ fhir:v "coding" ] ;
                 fhir:variable [ fhir:v "vsc" ]
               ] ) ;
               fhir:rule ( [
                 fhir:name [ fhir:v "verSystem" ] ;
                 fhir:source ( [
                   fhir:context [ fhir:v "qr" ]
                 ] ) ;
                 fhir:target ( [
                   fhir:context [ fhir:v "vsc" ] ;
                   fhir:element [ fhir:v "system" ] ;
                   fhir:transform [ fhir:v "copy" ] ;
                   fhir:parameter ( [
                     fhir:value [
                       a fhir:string ;
                       fhir:v "http://terminology.hl7.org/CodeSystem/condition-ver-status"
                     ]
                   ] )
                 ] )
               ] [
                 fhir:name [ fhir:v "verCode" ] ;
                 fhir:source ( [
                   fhir:context [ fhir:v "qr" ]
                 ] ) ;
                 fhir:target ( [
                   fhir:context [ fhir:v "vsc" ] ;
                   fhir:element [ fhir:v "code" ] ;
                   fhir:transform [ fhir:v "copy" ] ;
                   fhir:parameter ( [
                     fhir:value [
                       a fhir:string ;
                       fhir:v "confirmed"
                     ]
                   ] )
                 ] )
               ] [
                 fhir:name [ fhir:v "verDisplay" ] ;
                 fhir:source ( [
                   fhir:context [ fhir:v "qr" ]
                 ] ) ;
                 fhir:target ( [
                   fhir:context [ fhir:v "vsc" ] ;
                   fhir:element [ fhir:v "display" ] ;
                   fhir:transform [ fhir:v "copy" ] ;
                   fhir:parameter ( [
                     fhir:value [
                       a fhir:string ;
                       fhir:v "Confirmed"
                     ]
                   ] )
                 ] )
               ] )
             ] )
           ] [
             fhir:name [ fhir:v "conditionCode" ] ;
             fhir:source ( [
               fhir:context [ fhir:v "aCause" ] ;
               fhir:element [ fhir:v "value" ] ;
               fhir:variable [ fhir:v "v" ]
             ] ) ;
             fhir:target ( [
               fhir:context [ fhir:v "cond" ] ;
               fhir:element [ fhir:v "code" ] ;
               fhir:variable [ fhir:v "code" ]
             ] ) ;
             fhir:rule ( [
               fhir:name [ fhir:v "codeText" ] ;
               fhir:source ( [
                 fhir:context [ fhir:v "v" ]
               ] ) ;
               fhir:target ( [
                 fhir:context [ fhir:v "code" ] ;
                 fhir:element [ fhir:v "text" ] ;
                 fhir:transform [ fhir:v "copy" ] ;
                 fhir:parameter ( [
                   fhir:value [
                     a fhir:id ;
                     fhir:v "v"
                   ]
                 ] )
               ] )
             ] )
           ] [
             fhir:name [ fhir:v "conditionNote" ] ;
             fhir:source ( [
               fhir:context [ fhir:v "qr" ]
             ] ) ;
             fhir:target ( [
               fhir:context [ fhir:v "cond" ] ;
               fhir:element [ fhir:v "note" ] ;
               fhir:variable [ fhir:v "note" ]
             ] ) ;
             fhir:rule ( [
               fhir:name [ fhir:v "noteText" ] ;
               fhir:source ( [
                 fhir:context [ fhir:v "qr" ]
               ] ) ;
               fhir:target ( [
                 fhir:context [ fhir:v "note" ] ;
                 fhir:element [ fhir:v "text" ] ;
                 fhir:transform [ fhir:v "copy" ] ;
                 fhir:parameter ( [
                   fhir:value [
                     a fhir:string ;
                     fhir:v "Cause of death as stated on the inpatient death note."
                   ]
                 ] )
               ] )
             ] )
           ] )
         ] )
       ] ) ;
       fhir:documentation [ fhir:v "Cause of death as a Condition. verificationStatus is `confirmed`, not\r\n`provisional` as on the admission note: this is a stated cause, recorded\r\nafter the event, not a working impression." ]
     ] [
       fhir:name [ fhir:v "deceasedPatchRule" ] ;
       fhir:source ( [
         fhir:context [ fhir:v "qr" ] ;
         fhir:element [ fhir:v "item" ] ;
         fhir:variable [ fhir:v "itAt" ] ;
         fhir:condition [ fhir:v "(linkId = 'confirmedAt') and answer.value.exists()" ]
       ] ) ;
       fhir:rule ( [
         fhir:name [ fhir:v "confirmedAtAnswer" ] ;
         fhir:source ( [
           fhir:context [ fhir:v "itAt" ] ;
           fhir:element [ fhir:v "answer" ] ;
           fhir:listMode [ fhir:v "first" ] ;
           fhir:variable [ fhir:v "aAt" ]
         ] ) ;
         fhir:rule ( [
           fhir:name [ fhir:v "patientSubject" ] ;
           fhir:source ( [
             fhir:context [ fhir:v "qr" ] ;
             fhir:element [ fhir:v "subject" ] ;
             fhir:variable [ fhir:v "s" ] ;
             fhir:condition [ fhir:v "reference.startsWith('Patient/')" ]
           ] ) ;
           fhir:rule ( [
             fhir:name [ fhir:v "patientPatch" ] ;
             fhir:source ( [
               fhir:context [ fhir:v "aAt" ]
             ] ) ;
             fhir:target ( [
               fhir:context [ fhir:v "bundle" ] ;
               fhir:element [ fhir:v "entry" ] ;
               fhir:variable [ fhir:v "entryP" ]
             ] [
               fhir:context [ fhir:v "entryP" ] ;
               fhir:element [ fhir:v "resource" ] ;
               fhir:variable [ fhir:v "params" ] ;
               fhir:transform [ fhir:v "create" ] ;
               fhir:parameter ( [
                 fhir:value [
                   a fhir:string ;
                   fhir:v "Parameters"
                 ]
               ] )
             ] ) ;
             fhir:rule ( [
               fhir:name [ fhir:v "entryRequest" ] ;
               fhir:source ( [
                 fhir:context [ fhir:v "s" ] ;
                 fhir:element [ fhir:v "reference" ] ;
                 fhir:variable [ fhir:v "sref" ]
               ] ) ;
               fhir:target ( [
                 fhir:context [ fhir:v "entryP" ] ;
                 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 "PATCH"
                     ]
                   ] )
                 ] )
               ] [
                 fhir:name [ fhir:v "requestUrl" ] ;
                 fhir:source ( [
                   fhir:context [ fhir:v "sref" ]
                 ] ) ;
                 fhir:target ( [
                   fhir:context [ fhir:v "request" ] ;
                   fhir:element [ fhir:v "url" ] ;
                   fhir:transform [ fhir:v "copy" ] ;
                   fhir:parameter ( [
                     fhir:value [
                       a fhir:id ;
                       fhir:v "sref"
                     ]
                   ] )
                 ] ) ;
                 fhir:documentation [ fhir:v "The patient reference is already relative (\"Patient/1051\"), which\r\nis exactly what a transaction entry URL wants." ]
               ] )
             ] [
               fhir:name [ fhir:v "operation" ] ;
               fhir:source ( [
                 fhir:context [ fhir:v "aAt" ] ;
                 fhir:element [ fhir:v "value" ] ;
                 fhir:variable [ fhir:v "dv" ]
               ] ) ;
               fhir:target ( [
                 fhir:context [ fhir:v "params" ] ;
                 fhir:element [ fhir:v "parameter" ] ;
                 fhir:variable [ fhir:v "op" ]
               ] ) ;
               fhir:rule ( [
                 fhir:name [ fhir:v "operationName" ] ;
                 fhir:source ( [
                   fhir:context [ fhir:v "aAt" ]
                 ] ) ;
                 fhir:target ( [
                   fhir:context [ fhir:v "op" ] ;
                   fhir:element [ fhir:v "name" ] ;
                   fhir:transform [ fhir:v "copy" ] ;
                   fhir:parameter ( [
                     fhir:value [
                       a fhir:string ;
                       fhir:v "operation"
                     ]
                   ] )
                 ] )
               ] [
                 fhir:name [ fhir:v "operationType" ] ;
                 fhir:source ( [
                   fhir:context [ fhir:v "aAt" ]
                 ] ) ;
                 fhir:target ( [
                   fhir:context [ fhir:v "op" ] ;
                   fhir:element [ fhir:v "part" ] ;
                   fhir:variable [ fhir:v "partType" ]
                 ] ) ;
                 fhir:rule ( [
                   fhir:name [ fhir:v "typeName" ] ;
                   fhir:source ( [
                     fhir:context [ fhir:v "aAt" ]
                   ] ) ;
                   fhir:target ( [
                     fhir:context [ fhir:v "partType" ] ;
                     fhir:element [ fhir:v "name" ] ;
                     fhir:transform [ fhir:v "copy" ] ;
                     fhir:parameter ( [
                       fhir:value [
                         a fhir:string ;
                         fhir:v "type"
                       ]
                     ] )
                   ] )
                 ] [
                   fhir:name [ fhir:v "typeValue" ] ;
                   fhir:source ( [
                     fhir:context [ fhir:v "aAt" ]
                   ] ) ;
                   fhir:target ( [
                     fhir:context [ fhir:v "partType" ] ;
                     fhir:element [ fhir:v "value" ] ;
                     fhir:transform [ fhir:v "copy" ] ;
                     fhir:parameter ( [
                       fhir:value [
                         a fhir:string ;
                         fhir:v "add"
                       ]
                     ] )
                   ] )
                 ] )
               ] [
                 fhir:name [ fhir:v "operationPath" ] ;
                 fhir:source ( [
                   fhir:context [ fhir:v "aAt" ]
                 ] ) ;
                 fhir:target ( [
                   fhir:context [ fhir:v "op" ] ;
                   fhir:element [ fhir:v "part" ] ;
                   fhir:variable [ fhir:v "partPath" ]
                 ] ) ;
                 fhir:rule ( [
                   fhir:name [ fhir:v "pathName" ] ;
                   fhir:source ( [
                     fhir:context [ fhir:v "aAt" ]
                   ] ) ;
                   fhir:target ( [
                     fhir:context [ fhir:v "partPath" ] ;
                     fhir:element [ fhir:v "name" ] ;
                     fhir:transform [ fhir:v "copy" ] ;
                     fhir:parameter ( [
                       fhir:value [
                         a fhir:string ;
                         fhir:v "path"
                       ]
                     ] )
                   ] )
                 ] [
                   fhir:name [ fhir:v "pathValue" ] ;
                   fhir:source ( [
                     fhir:context [ fhir:v "aAt" ]
                   ] ) ;
                   fhir:target ( [
                     fhir:context [ fhir:v "partPath" ] ;
                     fhir:element [ fhir:v "value" ] ;
                     fhir:transform [ fhir:v "copy" ] ;
                     fhir:parameter ( [
                       fhir:value [
                         a fhir:string ;
                         fhir:v "Patient"
                       ]
                     ] )
                   ] )
                 ] )
               ] [
                 fhir:name [ fhir:v "operationElement" ] ;
                 fhir:source ( [
                   fhir:context [ fhir:v "aAt" ]
                 ] ) ;
                 fhir:target ( [
                   fhir:context [ fhir:v "op" ] ;
                   fhir:element [ fhir:v "part" ] ;
                   fhir:variable [ fhir:v "partName" ]
                 ] ) ;
                 fhir:rule ( [
                   fhir:name [ fhir:v "nameName" ] ;
                   fhir:source ( [
                     fhir:context [ fhir:v "aAt" ]
                   ] ) ;
                   fhir:target ( [
                     fhir:context [ fhir:v "partName" ] ;
                     fhir:element [ fhir:v "name" ] ;
                     fhir:transform [ fhir:v "copy" ] ;
                     fhir:parameter ( [
                       fhir:value [
                         a fhir:string ;
                         fhir:v "name"
                       ]
                     ] )
                   ] )
                 ] [
                   fhir:name [ fhir:v "nameValue" ] ;
                   fhir:source ( [
                     fhir:context [ fhir:v "aAt" ]
                   ] ) ;
                   fhir:target ( [
                     fhir:context [ fhir:v "partName" ] ;
                     fhir:element [ fhir:v "value" ] ;
                     fhir:transform [ fhir:v "copy" ] ;
                     fhir:parameter ( [
                       fhir:value [
                         a fhir:string ;
                         fhir:v "deceasedDateTime"
                       ]
                     ] )
                   ] )
                 ] )
               ] [
                 fhir:name [ fhir:v "operationValue" ] ;
                 fhir:source ( [
                   fhir:context [ fhir:v "aAt" ]
                 ] ) ;
                 fhir:target ( [
                   fhir:context [ fhir:v "op" ] ;
                   fhir:element [ fhir:v "part" ] ;
                   fhir:variable [ fhir:v "partValue" ]
                 ] ) ;
                 fhir:rule ( [
                   fhir:name [ fhir:v "valueName" ] ;
                   fhir:source ( [
                     fhir:context [ fhir:v "aAt" ]
                   ] ) ;
                   fhir:target ( [
                     fhir:context [ fhir:v "partValue" ] ;
                     fhir:element [ fhir:v "name" ] ;
                     fhir:transform [ fhir:v "copy" ] ;
                     fhir:parameter ( [
                       fhir:value [
                         a fhir:string ;
                         fhir:v "value"
                       ]
                     ] )
                   ] )
                 ] [
                   fhir:name [ fhir:v "valueValue" ] ;
                   fhir:source ( [
                     fhir:context [ fhir:v "dv" ]
                   ] ) ;
                   fhir:target ( [
                     fhir:context [ fhir:v "partValue" ] ;
                     fhir:element [ fhir:v "value" ] ;
                     fhir:transform [ fhir:v "copy" ] ;
                     fhir:parameter ( [
                       fhir:value [
                         a fhir:id ;
                         fhir:v "dv"
                       ]
                     ] )
                   ] )
                 ] )
               ] )
             ] )
           ] )
         ] )
       ] ) ;
       fhir:documentation [ fhir:v "Patient.deceasedDateTime, by FHIRPath PATCH, and only when the response's subject\r\nis a Patient. The patch is addressed to whatever the subject names, so one sent\r\nanywhere else, or with no reference to address, would make the server refuse the\r\nwhole transaction; the entry is not built at all rather than built half." ]
     ] )
  ] [
     fhir:name [ fhir:v "BuildNoteBase" ] ;
     fhir:documentation [ fhir:v "─────────────────────────────────────────────────────────────────────────────\r\nShared note scaffolding. Repeated in each note map rather than imported: the\r\ntransform engine resolves `imports` against whatever StructureMaps happen to\r\nbe on the server, and a note that stops extracting because a shared map was\r\nnot uploaded is a worse failure than a duplicated group.\r\n─────────────────────────────────────────────────────────────────────────────\r\nTwo notes on what the publisher's StructureMap validator says about this file.\r\nSource parameters below are left untyped on purpose. Writing `: Element` makes\r\nthe validator compare QuestionnaireResponse.item against the literal 'Element'\r\nand report them as incompatible with each other, which is noise, not a finding.\r\nUntyped, it says only that it cannot check the paths.\r\n`evaluate(context, expression)` is flagged as \"takes 1 parameter but 2 were\r\nfound\". Leave it. The FML parser in the same jar refuses the one-argument form\r\noutright -- it wants a parameter, a comma, then the FHIRPath -- so the publisher\r\nis objecting to what its own compiler emits. Two arguments is the only form that\r\ncompiles, and it is what the R5 transform engine executes." ] ;
     fhir:input ( [
       fhir:name [ fhir:v "qr" ] ;
       fhir:type [ fhir:v "QR" ] ;
       fhir:mode [ fhir:v "source" ]
     ] [
       fhir:name [ fhir:v "comp" ] ;
       fhir:type [ fhir:v "Composition" ] ;
       fhir:mode [ fhir:v "target" ]
     ] [
       fhir:name [ fhir:v "entry" ] ;
       fhir:mode [ fhir:v "target" ]
     ] ) ;
     fhir:rule ( [
       fhir:name [ fhir:v "idAndFullUrl" ] ;
       fhir:source ( [
         fhir:context [ fhir:v "qr" ]
       ] ) ;
       fhir:target ( [
         fhir:context [ fhir:v "comp" ] ;
         fhir:element [ fhir:v "id" ] ;
         fhir:transform [ fhir:v "uuid" ]
       ] ) ;
       fhir:dependent ( [
         fhir:name [ fhir:v "SetCompositionFullUrl" ] ;
         fhir:parameter ( [
           fhir:value [
             a fhir:id ;
             fhir:v "comp"
           ]
         ] [
           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 "Composition"
             ]
           ] )
         ] )
       ] )
     ] [
       fhir:name [ fhir:v "status" ] ;
       fhir:source ( [
         fhir:context [ fhir:v "qr" ]
       ] ) ;
       fhir:target ( [
         fhir:context [ fhir:v "comp" ] ;
         fhir:element [ fhir:v "status" ] ;
         fhir:transform [ fhir:v "copy" ] ;
         fhir:parameter ( [
           fhir:value [
             a fhir:string ;
             fhir:v "final"
           ]
         ] )
       ] )
     ] [
       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.contains('://').not() and reference.startsWith('#').not() and reference.startsWith('urn:').not())) or reference.empty()" ]
       ] ) ;
       fhir:target ( [
         fhir:context [ fhir:v "comp" ] ;
         fhir:element [ fhir:v "subject" ] ;
         fhir:transform [ fhir:v "copy" ] ;
         fhir:parameter ( [
           fhir:value [
             a fhir:id ;
             fhir:v "s"
           ]
         ] )
       ] )
     ] [
       fhir:name [ fhir:v "encounter" ] ;
       fhir:source ( [
         fhir:context [ fhir:v "qr" ] ;
         fhir:element [ fhir:v "encounter" ] ;
         fhir:variable [ fhir:v "e" ] ;
         fhir:condition [ fhir:v "(reference.exists() and (reference.startsWith('Encounter/'))) or (reference.empty() and (type.empty() or ('/' + type).endsWith('/Encounter')))" ]
       ] ) ;
       fhir:target ( [
         fhir:context [ fhir:v "comp" ] ;
         fhir:element [ fhir:v "encounter" ] ;
         fhir:transform [ fhir:v "copy" ] ;
         fhir:parameter ( [
           fhir:value [
             a fhir:id ;
             fhir:v "e"
           ]
         ] )
       ] )
     ] [
       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:context [ fhir:v "comp" ] ;
         fhir:element [ fhir:v "date" ] ;
         fhir:transform [ fhir:v "copy" ] ;
         fhir:parameter ( [
           fhir:value [
             a fhir:id ;
             fhir:v "t"
           ]
         ] )
       ] ) ;
       fhir:documentation [ fhir:v "Composition.date is 1..1. `authored` is only 0..1 on the response, so when a\r\nclient sends none the extraction time stands in. It is a poor substitute for\r\nwhen the note was written, but a document with no date at all is worse, and\r\nextraction happens moments after submission in practice." ]
     ] [
       fhir:name [ fhir:v "dateFallback" ] ;
       fhir:source ( [
         fhir:context [ fhir:v "qr" ] ;
         fhir:condition [ fhir:v "authored.exists().not()" ]
       ] ) ;
       fhir:rule ( [
         fhir:name [ fhir:v "dateFromExtractionTime" ] ;
         fhir:source ( [
           fhir:context [ fhir:v "qr" ]
         ] ) ;
         fhir:target ( [
           fhir:context [ fhir:v "comp" ] ;
           fhir:element [ fhir:v "date" ] ;
           fhir:transform [ fhir:v "evaluate" ] ;
           fhir:parameter ( [
             fhir:value [
               a fhir:id ;
               fhir:v "qr"
             ]
           ] [
             fhir:value [
               a fhir:string ;
               fhir:v "now()"
             ]
           ] )
         ] )
       ] )
     ] [
       fhir:name [ fhir:v "authorFromAuthor" ] ;
       fhir:source ( [
         fhir:context [ fhir:v "qr" ] ;
         fhir:element [ fhir:v "author" ] ;
         fhir:variable [ fhir:v "a" ] ;
         fhir:condition [ fhir:v "(reference.exists() and (reference.startsWith('Patient/') or reference.startsWith('Organization/'))) or (reference.empty() and (type.empty() or ('/' + type).endsWith('/Patient') or ('/' + type).endsWith('/Organization')))" ]
       ] ) ;
       fhir:target ( [
         fhir:context [ fhir:v "comp" ] ;
         fhir:element [ fhir:v "author" ] ;
         fhir:transform [ fhir:v "copy" ] ;
         fhir:parameter ( [
           fhir:value [
             a fhir:id ;
             fhir:v "a"
           ]
         ] )
       ] ) ;
       fhir:documentation [ fhir:v "Composition.author is 1..1 minimum. R5 QuestionnaireResponse carries both\r\n`author` (who recorded the answers) and `source` (who supplied them); the\r\nauthor is the one who wrote the note, so it wins, and `source` only stands\r\nin when the client did not send an author. If the response carries neither,\r\nthe note comes out unauthored -- there is nothing on a QuestionnaireResponse\r\nto invent one from, and guessing at who wrote a clinical note is not a thing\r\na map should do." ]
     ] [
       fhir:name [ fhir:v "authorFallback" ] ;
       fhir:source ( [
         fhir:context [ fhir:v "qr" ] ;
         fhir:condition [ fhir:v "author.where(((reference.exists() and (reference.startsWith('Patient/') or reference.startsWith('Organization/'))) or (reference.empty() and (type.empty() or ('/' + type).endsWith('/Patient') or ('/' + type).endsWith('/Organization'))))).exists().not()" ]
       ] ) ;
       fhir:rule ( [
         fhir:name [ fhir:v "authorFromSource" ] ;
         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('Patient/') or reference.startsWith('Organization/'))) or (reference.empty() and (type.empty() or ('/' + type).endsWith('/Patient') or ('/' + type).endsWith('/Organization')))" ]
         ] ) ;
         fhir:target ( [
           fhir:context [ fhir:v "comp" ] ;
           fhir:element [ fhir:v "author" ] ;
           fhir:transform [ fhir:v "copy" ] ;
           fhir:parameter ( [
             fhir:value [
               a fhir:id ;
               fhir:v "src"
             ]
           ] )
         ] )
       ] )
     ] [
       fhir:name [ fhir:v "linkQuestionnaireResponse" ] ;
       fhir:source ( [
         fhir:context [ fhir:v "qr" ]
       ] ) ;
       fhir:target ( [
         fhir:context [ fhir:v "comp" ] ;
         fhir:element [ fhir:v "relatesTo" ] ;
         fhir:variable [ fhir:v "rel" ]
       ] ) ;
       fhir:rule ( [
         fhir:name [ fhir:v "relatesToType" ] ;
         fhir:source ( [
           fhir:context [ fhir:v "qr" ]
         ] ) ;
         fhir:target ( [
           fhir:context [ fhir:v "rel" ] ;
           fhir:element [ fhir:v "type" ] ;
           fhir:transform [ fhir:v "copy" ] ;
           fhir:parameter ( [
             fhir:value [
               a fhir:string ;
               fhir:v "derived-from"
             ]
           ] )
         ] )
       ] [
         fhir:name [ fhir:v "relatesToTarget" ] ;
         fhir:source ( [
           fhir:context [ fhir:v "qr" ]
         ] ) ;
         fhir:target ( [
           fhir:context [ fhir:v "rel" ] ;
           fhir:element [ fhir:v "resourceReference" ] ;
           fhir:variable [ fhir:v "ref" ] ;
           fhir:transform [ fhir:v "create" ] ;
           fhir:parameter ( [
             fhir:value [
               a fhir:string ;
               fhir:v "Reference"
             ]
           ] )
         ] ) ;
         fhir:rule ( [
           fhir:name [ fhir:v "relatesToRef" ] ;
           fhir:source ( [
             fhir:context [ fhir:v "qr" ] ;
             fhir:element [ fhir:v "id" ] ;
             fhir:variable [ fhir:v "qid" ]
           ] ) ;
           fhir:target ( [
             fhir:context [ fhir:v "ref" ] ;
             fhir:element [ fhir:v "reference" ] ;
             fhir:transform [ fhir:v "copy" ] ;
             fhir:parameter ( [
               fhir:value [
                 a fhir:id ;
                 fhir:v "qid"
               ]
             ] )
           ] )
         ] )
       ] )
     ] )
  ] [
     fhir:name [ fhir:v "AddSectionText" ] ;
     fhir:input ( [
       fhir:name [ fhir:v "it" ] ;
       fhir:mode [ fhir:v "source" ]
     ] [
       fhir:name [ fhir:v "sec" ] ;
       fhir:mode [ fhir:v "target" ]
     ] ) ;
     fhir:rule ( [
       fhir:name [ fhir:v "sectionAnswer" ] ;
       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 "sectionText" ] ;
         fhir:source ( [
           fhir:context [ fhir:v "a" ] ;
           fhir:element [ fhir:v "value" ] ;
           fhir:variable [ fhir:v "v" ]
         ] ) ;
         fhir:target ( [
           fhir:context [ fhir:v "sec" ] ;
           fhir:element [ fhir:v "text" ] ;
           fhir:variable [ fhir:v "narrative" ]
         ] ) ;
         fhir:rule ( [
           fhir:name [ fhir:v "narrativeStatus" ] ;
           fhir:source ( [
             fhir:context [ fhir:v "v" ]
           ] ) ;
           fhir:target ( [
             fhir:context [ fhir:v "narrative" ] ;
             fhir:element [ fhir:v "status" ] ;
             fhir:transform [ fhir:v "copy" ] ;
             fhir:parameter ( [
               fhir:value [
                 a fhir:string ;
                 fhir:v "generated"
               ]
             ] )
           ] )
         ] [
           fhir:name [ fhir:v "narrativeXhtml" ] ;
           fhir:source ( [
             fhir:context [ fhir:v "v" ]
           ] ) ;
           fhir:target ( [
             fhir:context [ fhir:v "narrative" ] ;
             fhir:element [ fhir:v "div" ] ;
             fhir:variable [ fhir:v "xhtml" ] ;
             fhir:transform [ fhir:v "create" ] ;
             fhir:parameter ( [
               fhir:value [
                 a fhir:string ;
                 fhir:v "xhtml"
               ]
             ] )
           ] ) ;
           fhir:rule ( [
             fhir:name [ fhir:v "narrativeDiv" ] ;
             fhir:source ( [
               fhir:context [ fhir:v "v" ]
             ] ) ;
             fhir:target ( [
               fhir:context [ fhir:v "xhtml" ] ;
               fhir:element [ fhir:v "value" ] ;
               fhir:transform [ fhir:v "evaluate" ] ;
               fhir:parameter ( [
                 fhir:value [
                   a fhir:id ;
                   fhir:v "a"
                 ]
               ] [
                 fhir:value [
                   a fhir:string ;
                   fhir:v "'<div xmlns=\"http://www.w3.org/1999/xhtml\"><p>' + value.toString().escape('html') + '</p></div>'"
                 ]
               ] )
             ] )
           ] )
         ] )
       ] )
     ] )
  ] [
     fhir:name [ fhir:v "SetCompositionFullUrl" ] ;
     fhir:input ( [
       fhir:name [ fhir:v "comp" ] ;
       fhir:type [ fhir:v "Composition" ] ;
       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 "comp" ] ;
         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/Composition/"
           ]
         ] [
           fhir:value [
             a fhir:id ;
             fhir:v "id"
           ]
         ] )
       ] )
     ] )
  ] [
     fhir:name [ fhir:v "BuildConditionBase" ] ;
     fhir:input ( [
       fhir:name [ fhir:v "qr" ] ;
       fhir:type [ fhir:v "QR" ] ;
       fhir:mode [ fhir:v "source" ]
     ] [
       fhir:name [ fhir:v "cond" ] ;
       fhir:type [ fhir:v "Condition" ] ;
       fhir:mode [ fhir:v "target" ]
     ] [
       fhir:name [ fhir:v "entry" ] ;
       fhir:mode [ fhir:v "target" ]
     ] ) ;
     fhir:rule ( [
       fhir:name [ fhir:v "idAndFullUrl" ] ;
       fhir:source ( [
         fhir:context [ fhir:v "qr" ]
       ] ) ;
       fhir:target ( [
         fhir:context [ fhir:v "cond" ] ;
         fhir:element [ fhir:v "id" ] ;
         fhir:transform [ fhir:v "uuid" ]
       ] ) ;
       fhir:dependent ( [
         fhir:name [ fhir:v "SetConditionFullUrl" ] ;
         fhir:parameter ( [
           fhir:value [
             a fhir:id ;
             fhir:v "cond"
           ]
         ] [
           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 "Condition"
             ]
           ] )
         ] )
       ] )
     ] [
       fhir:name [ fhir:v "clinicalStatus" ] ;
       fhir:source ( [
         fhir:context [ fhir:v "qr" ]
       ] ) ;
       fhir:target ( [
         fhir:context [ fhir:v "cond" ] ;
         fhir:element [ fhir:v "clinicalStatus" ] ;
         fhir:variable [ fhir:v "cs" ]
       ] ) ;
       fhir:rule ( [
         fhir:name [ fhir:v "clinCoding" ] ;
         fhir:source ( [
           fhir:context [ fhir:v "qr" ]
         ] ) ;
         fhir:target ( [
           fhir:context [ fhir:v "cs" ] ;
           fhir:element [ fhir:v "coding" ] ;
           fhir:variable [ fhir:v "csc" ]
         ] ) ;
         fhir:rule ( [
           fhir:name [ fhir:v "clinSystem" ] ;
           fhir:source ( [
             fhir:context [ fhir:v "qr" ]
           ] ) ;
           fhir:target ( [
             fhir:context [ fhir:v "csc" ] ;
             fhir:element [ fhir:v "system" ] ;
             fhir:transform [ fhir:v "copy" ] ;
             fhir:parameter ( [
               fhir:value [
                 a fhir:string ;
                 fhir:v "http://terminology.hl7.org/CodeSystem/condition-clinical"
               ]
             ] )
           ] )
         ] [
           fhir:name [ fhir:v "clinCode" ] ;
           fhir:source ( [
             fhir:context [ fhir:v "qr" ]
           ] ) ;
           fhir:target ( [
             fhir:context [ fhir:v "csc" ] ;
             fhir:element [ fhir:v "code" ] ;
             fhir:transform [ fhir:v "copy" ] ;
             fhir:parameter ( [
               fhir:value [
                 a fhir:string ;
                 fhir:v "active"
               ]
             ] )
           ] )
         ] [
           fhir:name [ fhir:v "clinDisplay" ] ;
           fhir:source ( [
             fhir:context [ fhir:v "qr" ]
           ] ) ;
           fhir:target ( [
             fhir:context [ fhir:v "csc" ] ;
             fhir:element [ fhir:v "display" ] ;
             fhir:transform [ fhir:v "copy" ] ;
             fhir:parameter ( [
               fhir:value [
                 a fhir:string ;
                 fhir:v "Active"
               ]
             ] )
           ] )
         ] )
       ] )
     ] [
       fhir:name [ fhir:v "category" ] ;
       fhir:source ( [
         fhir:context [ fhir:v "qr" ]
       ] ) ;
       fhir:target ( [
         fhir:context [ fhir:v "cond" ] ;
         fhir:element [ fhir:v "category" ] ;
         fhir:variable [ fhir:v "cat" ]
       ] ) ;
       fhir:rule ( [
         fhir:name [ fhir:v "catCoding" ] ;
         fhir:source ( [
           fhir:context [ fhir:v "qr" ]
         ] ) ;
         fhir:target ( [
           fhir:context [ fhir:v "cat" ] ;
           fhir:element [ fhir:v "coding" ] ;
           fhir:variable [ fhir:v "catc" ]
         ] ) ;
         fhir:rule ( [
           fhir:name [ fhir:v "catSystem" ] ;
           fhir:source ( [
             fhir:context [ fhir:v "qr" ]
           ] ) ;
           fhir:target ( [
             fhir:context [ fhir:v "catc" ] ;
             fhir:element [ fhir:v "system" ] ;
             fhir:transform [ fhir:v "copy" ] ;
             fhir:parameter ( [
               fhir:value [
                 a fhir:string ;
                 fhir:v "http://terminology.hl7.org/CodeSystem/condition-category"
               ]
             ] )
           ] )
         ] [
           fhir:name [ fhir:v "catCode" ] ;
           fhir:source ( [
             fhir:context [ fhir:v "qr" ]
           ] ) ;
           fhir:target ( [
             fhir:context [ fhir:v "catc" ] ;
             fhir:element [ fhir:v "code" ] ;
             fhir:transform [ fhir:v "copy" ] ;
             fhir:parameter ( [
               fhir:value [
                 a fhir:string ;
                 fhir:v "encounter-diagnosis"
               ]
             ] )
           ] )
         ] [
           fhir:name [ fhir:v "catDisplay" ] ;
           fhir:source ( [
             fhir:context [ fhir:v "qr" ]
           ] ) ;
           fhir:target ( [
             fhir:context [ fhir:v "catc" ] ;
             fhir:element [ fhir:v "display" ] ;
             fhir:transform [ fhir:v "copy" ] ;
             fhir:parameter ( [
               fhir:value [
                 a fhir:string ;
                 fhir:v "Encounter Diagnosis"
               ]
             ] )
           ] )
         ] )
       ] )
     ] [
       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 "cond" ] ;
         fhir:element [ fhir:v "subject" ] ;
         fhir:transform [ fhir:v "copy" ] ;
         fhir:parameter ( [
           fhir:value [
             a fhir:id ;
             fhir:v "s"
           ]
         ] )
       ] )
     ] [
       fhir:name [ fhir:v "encounter" ] ;
       fhir:source ( [
         fhir:context [ fhir:v "qr" ] ;
         fhir:element [ fhir:v "encounter" ] ;
         fhir:variable [ fhir:v "e" ] ;
         fhir:condition [ fhir:v "(reference.exists() and (reference.startsWith('Encounter/'))) or (reference.empty() and (type.empty() or ('/' + type).endsWith('/Encounter')))" ]
       ] ) ;
       fhir:target ( [
         fhir:context [ fhir:v "cond" ] ;
         fhir:element [ fhir:v "encounter" ] ;
         fhir:transform [ fhir:v "copy" ] ;
         fhir:parameter ( [
           fhir:value [
             a fhir:id ;
             fhir:v "e"
           ]
         ] )
       ] )
     ] [
       fhir:name [ fhir:v "recordedDate" ] ;
       fhir:source ( [
         fhir:context [ fhir:v "qr" ] ;
         fhir:element [ fhir:v "authored" ] ;
         fhir:variable [ fhir:v "t" ]
       ] ) ;
       fhir:target ( [
         fhir:context [ fhir:v "cond" ] ;
         fhir:element [ fhir:v "recordedDate" ] ;
         fhir:transform [ fhir:v "copy" ] ;
         fhir:parameter ( [
           fhir:value [
             a fhir:id ;
             fhir:v "t"
           ]
         ] )
       ] )
     ] [
       fhir:name [ fhir:v "participantFromAuthor" ] ;
       fhir:source ( [
         fhir:context [ fhir:v "qr" ] ;
         fhir:element [ fhir:v "author" ] ;
         fhir:variable [ fhir:v "a" ] ;
         fhir:condition [ fhir:v "(reference.exists() and (reference.startsWith('Patient/') or reference.startsWith('Organization/'))) or (reference.empty() and (type.empty() or ('/' + type).endsWith('/Patient') or ('/' + type).endsWith('/Organization')))" ]
       ] ) ;
       fhir:target ( [
         fhir:context [ fhir:v "cond" ] ;
         fhir:element [ fhir:v "participant" ] ;
         fhir:variable [ fhir:v "part" ]
       ] ) ;
       fhir:rule ( [
         fhir:name [ fhir:v "participantActor" ] ;
         fhir:source ( [
           fhir:context [ fhir:v "qr" ]
         ] ) ;
         fhir:target ( [
           fhir:context [ fhir:v "part" ] ;
           fhir:element [ fhir:v "actor" ] ;
           fhir:transform [ fhir:v "copy" ] ;
           fhir:parameter ( [
             fhir:value [
               a fhir:id ;
               fhir:v "a"
             ]
           ] )
         ] )
       ] )
     ] [
       fhir:name [ fhir:v "participantFallback" ] ;
       fhir:source ( [
         fhir:context [ fhir:v "qr" ] ;
         fhir:condition [ fhir:v "author.where(((reference.exists() and (reference.startsWith('Patient/') or reference.startsWith('Organization/'))) or (reference.empty() and (type.empty() or ('/' + type).endsWith('/Patient') or ('/' + type).endsWith('/Organization'))))).exists().not()" ]
       ] ) ;
       fhir:rule ( [
         fhir:name [ fhir:v "participantFromSource" ] ;
         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('Patient/') or reference.startsWith('Organization/'))) or (reference.empty() and (type.empty() or ('/' + type).endsWith('/Patient') or ('/' + type).endsWith('/Organization')))" ]
         ] ) ;
         fhir:target ( [
           fhir:context [ fhir:v "cond" ] ;
           fhir:element [ fhir:v "participant" ] ;
           fhir:variable [ fhir:v "part2" ]
         ] ) ;
         fhir:rule ( [
           fhir:name [ fhir:v "participantActorFromSource" ] ;
           fhir:source ( [
             fhir:context [ fhir:v "qr" ]
           ] ) ;
           fhir:target ( [
             fhir:context [ fhir:v "part2" ] ;
             fhir:element [ fhir:v "actor" ] ;
             fhir:transform [ fhir:v "copy" ] ;
             fhir:parameter ( [
               fhir:value [
                 a fhir:id ;
                 fhir:v "src"
               ]
             ] )
           ] )
         ] )
       ] )
     ] [
       fhir:name [ fhir:v "linkQuestionnaireResponse" ] ;
       fhir:source ( [
         fhir:context [ fhir:v "qr" ]
       ] ) ;
       fhir:target ( [
         fhir:context [ fhir:v "cond" ] ;
         fhir:element [ fhir:v "evidence" ] ;
         fhir:variable [ fhir:v "ev" ]
       ] ) ;
       fhir:rule ( [
         fhir:name [ fhir:v "evidenceTarget" ] ;
         fhir:source ( [
           fhir:context [ fhir:v "qr" ]
         ] ) ;
         fhir:target ( [
           fhir:context [ fhir:v "ev" ] ;
           fhir:element [ fhir:v "reference" ] ;
           fhir:variable [ fhir:v "ref" ] ;
           fhir:transform [ fhir:v "create" ] ;
           fhir:parameter ( [
             fhir:value [
               a fhir:string ;
               fhir:v "Reference"
             ]
           ] )
         ] ) ;
         fhir:rule ( [
           fhir:name [ fhir:v "evidenceRef" ] ;
           fhir:source ( [
             fhir:context [ fhir:v "qr" ] ;
             fhir:element [ fhir:v "id" ] ;
             fhir:variable [ fhir:v "qid" ]
           ] ) ;
           fhir:target ( [
             fhir:context [ fhir:v "ref" ] ;
             fhir:element [ fhir:v "reference" ] ;
             fhir:transform [ fhir:v "copy" ] ;
             fhir:parameter ( [
               fhir:value [
                 a fhir:id ;
                 fhir:v "qid"
               ]
             ] )
           ] )
         ] )
       ] )
     ] )
  ] [
     fhir:name [ fhir:v "SetConditionFullUrl" ] ;
     fhir:input ( [
       fhir:name [ fhir:v "cond" ] ;
       fhir:type [ fhir:v "Condition" ] ;
       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 "cond" ] ;
         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/Condition/"
           ]
         ] [
           fhir:value [
             a fhir:id ;
             fhir:v "id"
           ]
         ] )
       ] )
     ] )
  ] [
     fhir:name [ fhir:v "CopyResponseTags" ] ;
     fhir:documentation [ fhir:v "── Tenancy ──────────────────────────────────────────────────────────────────\r\nWhose this is. The platform says which tenant a response belongs to with a\r\ntag on the response, and every tag the response carries is copied onto\r\neverything this map creates, as it is. Copied rather than named here, so the\r\nmap never has to know which tenant it is running for, nor which system the\r\ntag is under: that system has moved more than once." ] ;
     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 "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"
             ]
           ] )
         ] )
       ] )
     ] )
  ] ) . #