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 Progress Note Extraction - TTL Representation

Active as of 2026-09-14

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/ExtractInpatientProgressNote> a fhir:StructureMap ;
  fhir:nodeRole fhir:treeRoot ;
  fhir:id [ fhir:v "ExtractInpatientProgressNote"] ; # 
  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 ExtractInpatientProgressNote</b></p><a name=\"ExtractInpatientProgressNote\"> </a><a name=\"hcExtractInpatientProgressNote\"> </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/ExtractInpatientProgressNote'</span>\r\n<span style=\"color: #cc00cc\">/// <b>name</b> = </span><span style=\"color: blue\">'ExtractInpatientProgressNote'</span>\r\n<span style=\"color: #cc00cc\">/// <b>title</b> = </span><span style=\"color: blue\">'Inpatient Progress 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\">'Turns a response to the inpatient progress note into a single Composition with one section per SOAP heading. Nothing here is a discrete clinical fact -- a progress note is a document -- so no Observation, Condition or Task is produced. The QuestionnaireResponse remains the signed record and the Composition points back at it through relatesTo.'</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\r\n<b>group </b>ExtractInpatientProgressNote<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<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\">'InpatientProgressNote'</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\">'Progress note'</span> <i>&quot;noteTitle&quot;</i><span style=\"color: navy\">;</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\">'progress-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\">'Progress 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.coding<b> as </b><span style=\"color: maroon\">loinc</span><b> then</b><span style=\"color: navy\"> {\r\n</span>        qr<span style=\"color: navy\"><b> -&gt; </b></span>loinc.system = <span style=\"color: blue\">'http://loinc.org'</span> <i>&quot;loincSystem&quot;</i><span style=\"color: navy\">;</span>\r\n        qr<span style=\"color: navy\"><b> -&gt; </b></span>loinc.code = <span style=\"color: blue\">'11506-3'</span> <i>&quot;loincCode&quot;</i><span style=\"color: navy\">;</span>\r\n        qr<span style=\"color: navy\"><b> -&gt; </b></span>loinc.display = <span style=\"color: blue\">'Progress note'</span> <i>&quot;loincDisplay&quot;</i><span style=\"color: navy\">;</span>\r\n      <span style=\"color: navy\">}</span> <i>&quot;loincCoding&quot;</i><span style=\"color: navy\">;</span>\r\n      qr<span style=\"color: navy\"><b> -&gt; </b></span>ty.text = <span style=\"color: blue\">'Progress 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\">Sections in the order the form asks for them, so the printed note reads</span>\r\n    <span style=\"color: navy\">// </span><span style=\"color: green\">the way it was written. The `answer.value.exists()` guard is not</span>\r\n    <span style=\"color: navy\">// </span><span style=\"color: green\">decoration: a section with a title and no content breaks cmp-1, and an</span>\r\n    <span style=\"color: navy\">// </span><span style=\"color: green\">unanswered optional item still arrives as an empty item.</span>\r\n    qr.item<b> as </b><span style=\"color: maroon\">it</span><b> where </b><span style=\"color: navy\">(</span>(linkId = 'subjective') 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\">'Subjective'</span> <i>&quot;subjectiveTitle&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;subjectiveText&quot;</i><span style=\"color: navy\">;</span>\r\n    <span style=\"color: navy\">}</span> <i>&quot;subjectiveRule&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 = 'objective') 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\">'Objective'</span> <i>&quot;objectiveTitle&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;objectiveText&quot;</i><span style=\"color: navy\">;</span>\r\n    <span style=\"color: navy\">}</span> <i>&quot;objectiveRule&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 = 'assessment') 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\">'Assessment'</span> <i>&quot;assessmentTitle&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;assessmentText&quot;</i><span style=\"color: navy\">;</span>\r\n    <span style=\"color: navy\">}</span> <i>&quot;assessmentRule&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 = 'plan') 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\">'Plan'</span> <i>&quot;planTitle&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;planText&quot;</i><span style=\"color: navy\">;</span>\r\n    <span style=\"color: navy\">}</span> <i>&quot;planRule&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\">}\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><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><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><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.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><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  <span style=\"color: navy\">// </span><span style=\"color: green\">The note is derived from the response, not a copy of it. relatesTo is the</span>\r\n  <span style=\"color: navy\">// </span><span style=\"color: green\">only element on R5 Composition that can say so.</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>      <span style=\"color: navy\">// </span><span style=\"color: green\">`qr.id` already resolves to the type-qualified relative reference under</span>\r\n      <span style=\"color: navy\">// </span><span style=\"color: green\">this engine, so it is used unprefixed.</span>\r\n      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><span style=\"color: navy\">// </span><span style=\"color: green\">The narrative half of a section. The title stays with the caller because a</span>\r\n<span style=\"color: navy\">// </span><span style=\"color: green\">group can only be invoked with variables, not string literals.</span>\r\n<span style=\"color: navy\">// </span><span style=\"color: green\">Two things here are deliberate. `create('xhtml')` rather than assigning the</span>\r\n<span style=\"color: navy\">// </span><span style=\"color: green\">string straight to `div`: the engine hard-casts whatever it is given to</span>\r\n<span style=\"color: navy\">// </span><span style=\"color: green\">XhtmlType, so a plain string fails with a ClassCastException. And</span>\r\n<span style=\"color: navy\">// </span><span style=\"color: green\">`escape('html')` on the answer: a nurse writing &quot;sats &lt; 92% &amp; falling&quot; would</span>\r\n<span style=\"color: navy\">// </span><span style=\"color: green\">otherwise produce a div the server refuses to parse.</span>\r\n<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></pre></div>"^^rdf:XMLLiteral ]
  ] ; # 
  fhir:url [ fhir:v "https://fhir.slade360.co.ke/fhir/StructureMap/ExtractInpatientProgressNote"^^xsd:anyURI] ; # 
  fhir:version [ fhir:v "0.1.0"] ; # 
  fhir:name [ fhir:v "ExtractInpatientProgressNote"] ; # 
  fhir:title [ fhir:v "Inpatient Progress Note Extraction"] ; # 
  fhir:status [ fhir:v "active"] ; # 
  fhir:date [ fhir:v "2026-09-14T06:31:13+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 "Turns a response to the inpatient progress note into a single Composition with one section per SOAP heading. Nothing here is a discrete clinical fact -- a progress note is a document -- so no Observation, Condition or Task is produced. The QuestionnaireResponse remains the signed record and the Composition points back at it through relatesTo."] ; # 
  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:group ( [
     fhir:name [ fhir:v "ExtractInpatientProgressNote" ] ;
     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 "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 "InpatientProgressNote"
             ]
           ] )
         ] )
       ] [
         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 "Progress 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 "progress-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 "Progress note"
                 ]
               ] )
             ] )
           ] )
         ] [
           fhir:name [ fhir:v "loincCoding" ] ;
           fhir:source ( [
             fhir:context [ fhir:v "qr" ]
           ] ) ;
           fhir:target ( [
             fhir:context [ fhir:v "ty" ] ;
             fhir:element [ fhir:v "coding" ] ;
             fhir:variable [ fhir:v "loinc" ]
           ] ) ;
           fhir:rule ( [
             fhir:name [ fhir:v "loincSystem" ] ;
             fhir:source ( [
               fhir:context [ fhir:v "qr" ]
             ] ) ;
             fhir:target ( [
               fhir:context [ fhir:v "loinc" ] ;
               fhir:element [ fhir:v "system" ] ;
               fhir:transform [ fhir:v "copy" ] ;
               fhir:parameter ( [
                 fhir:value [
                   a fhir:string ;
                   fhir:v "http://loinc.org"
                 ]
               ] )
             ] )
           ] [
             fhir:name [ fhir:v "loincCode" ] ;
             fhir:source ( [
               fhir:context [ fhir:v "qr" ]
             ] ) ;
             fhir:target ( [
               fhir:context [ fhir:v "loinc" ] ;
               fhir:element [ fhir:v "code" ] ;
               fhir:transform [ fhir:v "copy" ] ;
               fhir:parameter ( [
                 fhir:value [
                   a fhir:string ;
                   fhir:v "11506-3"
                 ]
               ] )
             ] )
           ] [
             fhir:name [ fhir:v "loincDisplay" ] ;
             fhir:source ( [
               fhir:context [ fhir:v "qr" ]
             ] ) ;
             fhir:target ( [
               fhir:context [ fhir:v "loinc" ] ;
               fhir:element [ fhir:v "display" ] ;
               fhir:transform [ fhir:v "copy" ] ;
               fhir:parameter ( [
                 fhir:value [
                   a fhir:string ;
                   fhir:v "Progress 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 "Progress note"
               ]
             ] )
           ] )
         ] )
       ] [
         fhir:name [ fhir:v "subjectiveRule" ] ;
         fhir:source ( [
           fhir:context [ fhir:v "qr" ] ;
           fhir:element [ fhir:v "item" ] ;
           fhir:variable [ fhir:v "it" ] ;
           fhir:condition [ fhir:v "(linkId = 'subjective') 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 "subjectiveTitle" ] ;
           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 "Subjective"
               ]
             ] )
           ] )
         ] [
           fhir:name [ fhir:v "subjectiveText" ] ;
           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 "Sections in the order the form asks for them, so the printed note reads\r\nthe way it was written. The `answer.value.exists()` guard is not\r\ndecoration: a section with a title and no content breaks cmp-1, and an\r\nunanswered optional item still arrives as an empty item." ]
       ] [
         fhir:name [ fhir:v "objectiveRule" ] ;
         fhir:source ( [
           fhir:context [ fhir:v "qr" ] ;
           fhir:element [ fhir:v "item" ] ;
           fhir:variable [ fhir:v "it" ] ;
           fhir:condition [ fhir:v "(linkId = 'objective') 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 "objectiveTitle" ] ;
           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 "Objective"
               ]
             ] )
           ] )
         ] [
           fhir:name [ fhir:v "objectiveText" ] ;
           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 "assessmentRule" ] ;
         fhir:source ( [
           fhir:context [ fhir:v "qr" ] ;
           fhir:element [ fhir:v "item" ] ;
           fhir:variable [ fhir:v "it" ] ;
           fhir:condition [ fhir:v "(linkId = 'assessment') 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 "assessmentTitle" ] ;
           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 "Assessment"
               ]
             ] )
           ] )
         ] [
           fhir:name [ fhir:v "assessmentText" ] ;
           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 "planRule" ] ;
         fhir:source ( [
           fhir:context [ fhir:v "qr" ] ;
           fhir:element [ fhir:v "item" ] ;
           fhir:variable [ fhir:v "it" ] ;
           fhir:condition [ fhir:v "(linkId = 'plan') 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 "planTitle" ] ;
           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 "Plan"
               ]
             ] )
           ] )
         ] [
           fhir:name [ fhir:v "planText" ] ;
           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 "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: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: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: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.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: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:documentation [ fhir:v "`qr.id` already resolves to the type-qualified relative reference under\r\nthis engine, so it is used unprefixed." ]
         ] )
       ] ) ;
       fhir:documentation [ fhir:v "The note is derived from the response, not a copy of it. relatesTo is the\r\nonly element on R5 Composition that can say so." ]
     ] )
  ] [
     fhir:name [ fhir:v "AddSectionText" ] ;
     fhir:documentation [ fhir:v "The narrative half of a section. The title stays with the caller because a\r\ngroup can only be invoked with variables, not string literals.\r\nTwo things here are deliberate. `create('xhtml')` rather than assigning the\r\nstring straight to `div`: the engine hard-casts whatever it is given to\r\nXhtmlType, so a plain string fails with a ClassCastException. And\r\n`escape('html')` on the answer: a nurse writing \"sats < 92% & falling\" would\r\notherwise produce a div the server refuses to parse." ] ;
     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"
           ]
         ] )
       ] )
     ] )
  ] ) . #