FHIR IG analytics| Package | silfhirprofileig |
| Resource Type | StructureMap |
| Id | StructureMap-ExtractInpatientDeathNote.json |
| FHIR Version | R5 |
| Source | https://build.fhir.org/ig/savannahghi/sil_fhir_profile_ig/StructureMap-ExtractInpatientDeathNote.html |
| URL | https://fhir.slade360.co.ke/fhir/StructureMap/ExtractInpatientDeathNote |
| Version | 0.1.0 |
| Status | active |
| Date | 2026-09-11T12:18:36+00:00 |
| Name | ExtractInpatientDeathNote |
| Title | Inpatient Death Note Extraction |
| Description | 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. |
No resources found
No resources found
Note: links and images are rebased to the (stated) source
Generated Narrative: StructureMap ExtractInpatientDeathNote
/// url = 'https://fhir.slade360.co.ke/fhir/StructureMap/ExtractInpatientDeathNote' /// name = 'ExtractInpatientDeathNote' /// title = 'Inpatient Death Note Extraction' /// status = 'active' /// description = '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.' uses "http://hl7.org/fhir/StructureDefinition/QuestionnaireResponse" alias QR as source uses "http://hl7.org/fhir/StructureDefinition/Bundle" alias Bundle as target uses "http://hl7.org/fhir/StructureDefinition/Composition" alias Composition as target uses "http://hl7.org/fhir/StructureDefinition/Condition" alias Condition as target uses "http://hl7.org/fhir/StructureDefinition/Parameters" alias Parameters as target group ExtractInpatientDeathNote(source qr : QR, target bundle : Bundle) { qr -> bundle.type = 'transaction' "setBundleType"; qr -> bundle.entry as entry, entry.resource = create('Composition') as comp then { qr -> comp, entry then BuildNoteBase(qr, comp, entry) "noteBase"; qr -> comp.name = 'InpatientDeathNote' "noteName"; qr -> comp.title = 'Death note' "noteTitle"; // Deliberately not LOINC 64297-5. That code is the civil death certificate, // a different document with a different author and a different audience. qr -> comp.type as ty then { qr -> ty.coding as sghi then { qr -> sghi.system = 'https://fhir.slade360.co.ke/fhir/CodeSystem/inpatient-document-type-codesystem' "sghiSystem"; qr -> sghi.code = 'death-note' "sghiCode"; qr -> sghi.display = 'Death note' "sghiDisplay"; } "sghiCoding"; qr -> ty.text = 'Death note' "typeText"; } "noteType"; // The clinician who confirmed the death attests the note. qr.item as itC where (linkId = 'confirmedBy') then { itC.answer as aC then { aC.value as cv -> comp.attester as att then { aC -> att.mode as mode then { aC -> mode.coding as modec then { aC -> modec.system = 'http://hl7.org/fhir/composition-attestation-mode' "attModeSystem"; aC -> modec.code = 'professional' "attModeCode"; aC -> modec.display = 'Professional' "attModeDisplay"; } "attModeCoding"; } "attesterMode"; qr.item as itT where (linkId = 'confirmedAt') then { itT.answer first as aT then { aT.value as tv -> att.time = tv "attesterTimeFromConfirmedAt"; } "confirmedAtAnswer"; } "attesterTimeRule"; cv -> att.party = cv "attesterParty"; } "attester"; } "confirmedByAnswer"; } "confirmedByRule"; // The confirmed-at time is on the Patient as a fact, and in the document as // a line, because a printed death note that does not say when is not a // death note. qr.item as it where ((linkId = 'confirmedAt') and answer.value.exists()) -> comp.section as sec then { it -> sec.title = 'Death confirmed at' "confirmedAtTitle"; it -> sec then AddSectionText(it, sec) "confirmedAtText"; } "confirmedAtSectionRule"; qr.item as it where ((linkId = 'circumstances') and answer.value.exists()) -> comp.section as sec then { it -> sec.title = 'Circumstances' "circumstancesTitle"; it -> sec then AddSectionText(it, sec) "circumstancesText"; } "circumstancesRule"; qr.item as it where ((linkId = 'causeStated') and answer.value.exists()) -> comp.section as sec then { it -> sec.title = 'Cause of death as stated' "causeTitle"; it -> sec then AddSectionText(it, sec) "causeText"; } "causeSectionRule"; qr.item as it where ((linkId = 'familyInformed') and answer.value.exists()) -> comp.section as sec then { it -> sec.title = 'Family informed' "familyTitle"; it -> sec then AddSectionText(it, sec) "familyText"; } "familyRule"; } "composition"; // Cause of death as a Condition. verificationStatus is `confirmed`, not // `provisional` as on the admission note: this is a stated cause, recorded // after the event, not a working impression. qr.item as itCause where ((linkId = 'causeStated') and answer.value.exists()) then { itCause.answer first as aCause then { aCause -> bundle.entry as entryC, entryC.resource = create('Condition') as cond then { qr -> cond, entryC then BuildConditionBase(qr, cond, entryC) "conditionBase"; qr -> cond.verificationStatus as vs then { qr -> vs.coding as vsc then { qr -> vsc.system = 'http://terminology.hl7.org/CodeSystem/condition-ver-status' "verSystem"; qr -> vsc.code = 'confirmed' "verCode"; qr -> vsc.display = 'Confirmed' "verDisplay"; } "verCoding"; } "verificationStatus"; aCause.value as v -> cond.code as code then { v -> code.text = v "codeText"; } "conditionCode"; qr -> cond.note as note then { qr -> note.text = 'Cause of death as stated on the inpatient death note.' "noteText"; } "conditionNote"; } "condition"; } "causeAnswer"; } "causeConditionRule"; // Patient.deceasedDateTime, by FHIRPath PATCH. qr.item as itAt where ((linkId = 'confirmedAt') and answer.value.exists()) then { itAt.answer first as aAt then { aAt -> bundle.entry as entryP, entryP.resource = create('Parameters') as params then { qr.subject as s then { s.reference as sref -> entryP.request as request then { qr -> request.method = 'PATCH' "requestMethod"; // The patient reference is already relative ("Patient/1051"), which // is exactly what a transaction entry URL wants. sref -> request.url = sref "requestUrl"; } "entryRequest"; } "patientReference"; aAt.value as dv -> params.parameter as op then { aAt -> op.name = 'operation' "operationName"; aAt -> op.part as partType then { aAt -> partType.name = 'type' "typeName"; aAt -> partType.value = 'add' "typeValue"; } "operationType"; aAt -> op.part as partPath then { aAt -> partPath.name = 'path' "pathName"; aAt -> partPath.value = 'Patient' "pathValue"; } "operationPath"; aAt -> op.part as partName then { aAt -> partName.name = 'name' "nameName"; aAt -> partName.value = 'deceasedDateTime' "nameValue"; } "operationElement"; aAt -> op.part as partValue then { aAt -> partValue.name = 'value' "valueName"; dv -> partValue.value = dv "valueValue"; } "operationValue"; } "operation"; } "patientPatch"; } "confirmedAtAnswer"; } "deceasedPatchRule"; } // ───────────────────────────────────────────────────────────────────────────── // Shared note scaffolding. Repeated in each note map rather than imported: the // transform engine resolves `imports` against whatever StructureMaps happen to // be on the server, and a note that stops extracting because a shared map was // not uploaded is a worse failure than a duplicated group. // ───────────────────────────────────────────────────────────────────────────── // Two notes on what the publisher's StructureMap validator says about this file. // Source parameters below are left untyped on purpose. Writing `: Element` makes // the validator compare QuestionnaireResponse.item against the literal 'Element' // and report them as incompatible with each other, which is noise, not a finding. // Untyped, it says only that it cannot check the paths. // `evaluate(context, expression)` is flagged as "takes 1 parameter but 2 were // found". Leave it. The FML parser in the same jar refuses the one-argument form // outright -- it wants a parameter, a comma, then the FHIRPath -- so the publisher // is objecting to what its own compiler emits. Two arguments is the only form that // compiles, and it is what the R5 transform engine executes. group BuildNoteBase(source qr : QR, target comp : Composition, target entry) { qr -> comp.id = uuid() then SetCompositionFullUrl(comp, entry) "idAndFullUrl"; qr -> entry.request as request then { qr -> request.method = 'POST' "requestMethod"; qr -> request.url = 'Composition' "requestUrl"; } "entryRequest"; qr -> comp.status = 'final' "status"; qr.subject as s -> comp.subject = s; qr.encounter as e -> comp.encounter = e; // Composition.date is 1..1. `authored` is only 0..1 on the response, so when a // client sends none the extraction time stands in. It is a poor substitute for // when the note was written, but a document with no date at all is worse, and // extraction happens moments after submission in practice. qr.authored as t -> comp.date = t "date"; qr where (authored.exists().not()) then { qr -> comp.date = evaluate(qr, now()) "dateFromExtractionTime"; } "dateFallback"; // Composition.author is 1..1 minimum. R5 QuestionnaireResponse carries both // `author` (who recorded the answers) and `source` (who supplied them); the // author is the one who wrote the note, so it wins, and `source` only stands // in when the client did not send an author. If the response carries neither, // the note comes out unauthored -- there is nothing on a QuestionnaireResponse // to invent one from, and guessing at who wrote a clinical note is not a thing // a map should do. qr.author as a -> comp.author = a "authorFromAuthor"; qr where (author.exists().not()) then { qr.source as src -> comp.author = src "authorFromSource"; } "authorFallback"; qr -> comp.relatesTo as rel then { qr -> rel.type = 'derived-from' "relatesToType"; qr -> rel.resourceReference = create('Reference') as ref then { qr.id as qid -> ref.reference = qid "relatesToRef"; } "relatesToTarget"; } "linkQuestionnaireResponse"; } group AddSectionText(source it, target sec) { it.answer first as a then { a.value as v -> sec.text as narrative then { v -> narrative.status = 'generated' "narrativeStatus"; v -> narrative.div = create('xhtml') as xhtml then { v -> xhtml.value = evaluate(a, '<div xmlns="http://www.w3.org/1999/xhtml"><p>' + value.toString().escape('html') + '</p></div>') "narrativeDiv"; } "narrativeXhtml"; } "sectionText"; } "sectionAnswer"; } group SetCompositionFullUrl(source comp : Composition, target entry) { comp.id as id -> entry.fullUrl = append('https://fhir.slade360.co.ke/fhir/Composition/', id) "assignFullUrl"; } group BuildConditionBase(source qr : QR, target cond : Condition, target entry) { qr -> cond.id = uuid() then SetConditionFullUrl(cond, entry) "idAndFullUrl"; qr -> entry.request as request then { qr -> request.method = 'POST' "requestMethod"; qr -> request.url = 'Condition' "requestUrl"; } "entryRequest"; qr -> cond.clinicalStatus as cs then { qr -> cs.coding as csc then { qr -> csc.system = 'http://terminology.hl7.org/CodeSystem/condition-clinical' "clinSystem"; qr -> csc.code = 'active' "clinCode"; qr -> csc.display = 'Active' "clinDisplay"; } "clinCoding"; } "clinicalStatus"; qr -> cond.category as cat then { qr -> cat.coding as catc then { qr -> catc.system = 'http://terminology.hl7.org/CodeSystem/condition-category' "catSystem"; qr -> catc.code = 'encounter-diagnosis' "catCode"; qr -> catc.display = 'Encounter Diagnosis' "catDisplay"; } "catCoding"; } "category"; qr.subject as s -> cond.subject = s; qr.encounter as e -> cond.encounter = e; qr.authored as t -> cond.recordedDate = t "recordedDate"; qr.author as a -> cond.participant as part then { qr -> part.actor = a "participantActor"; } "participantFromAuthor"; qr where (author.exists().not()) then { qr.source as src -> cond.participant as part2 then { qr -> part2.actor = src "participantActorFromSource"; } "participantFromSource"; } "participantFallback"; qr -> cond.evidence as ev then { qr -> ev.reference = create('Reference') as ref then { qr.id as qid -> ref.reference = qid "evidenceRef"; } "evidenceTarget"; } "linkQuestionnaireResponse"; } group SetConditionFullUrl(source cond : Condition, target entry) { cond.id as id -> entry.fullUrl = append('https://fhir.slade360.co.ke/fhir/Condition/', id) "assignFullUrl"; }
{
"resourceType": "StructureMap",
"id": "ExtractInpatientDeathNote",
"text": {
"status": "generated",
"div": "<!-- snip (see above) -->"
},
"url": "https://fhir.slade360.co.ke/fhir/StructureMap/ExtractInpatientDeathNote",
"version": "0.1.0",
"name": "ExtractInpatientDeathNote",
"title": "Inpatient Death Note Extraction",
"status": "active",
"date": "2026-09-11T12:18:36+00:00",
"publisher": "Kathurima Kimathi",
"contact": [
{
"name": "Kathurima Kimathi",
"telecom": [
{
"system": "url",
"value": "https://www.linkedin.com/in/kathurima-kimathi/"
},
{
"system": "email",
"value": "kathurimakimathi415@gmail.com"
}
]
},
{
"name": "Oscar John",
"telecom": [
{
"system": "email",
"value": "oscarjohnotieno@gmail.com",
"use": "work"
}
]
},
{
"name": "Kennedy Omondi",
"telecom": [
{
"system": "email",
"value": "kennankole@gmail.com",
"use": "work"
}
]
}
],
"description": "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.",
"structure": [
{
"url": "http://hl7.org/fhir/StructureDefinition/QuestionnaireResponse",
"mode": "source",
"alias": "QR"
},
{
"url": "http://hl7.org/fhir/StructureDefinition/Bundle",
"mode": "target",
"alias": "Bundle"
},
{
"url": "http://hl7.org/fhir/StructureDefinition/Composition",
"mode": "target",
"alias": "Composition"
},
{
"url": "http://hl7.org/fhir/StructureDefinition/Condition",
"mode": "target",
"alias": "Condition"
},
{
"url": "http://hl7.org/fhir/StructureDefinition/Parameters",
"mode": "target",
"alias": "Parameters"
}
],
"group": [
{
"name": "ExtractInpatientDeathNote",
"input": [
{
"name": "qr",
"type": "QR",
"mode": "source"
},
{
"name": "bundle",
"type": "Bundle",
"mode": "target"
}
],
"rule": [
{
"name": "setBundleType",
"source": [
{
"context": "qr"
}
],
"target": [
{
"context": "bundle",
"element": "type",
"transform": "copy",
"parameter": [
{
"valueString": "transaction"
}
]
}
]
},
{
"name": "composition",
"source": [
{
"context": "qr"
}
],
"target": [
{
"context": "bundle",
"element": "entry",
"variable": "entry"
},
{
"context": "entry",
"element": "resource",
"variable": "comp",
"transform": "create",
"parameter": [
{
"valueString": "Composition"
}
]
}
],
"rule": [
{
"name": "noteBase",
"source": [
{
"context": "qr"
}
],
"target": [
{
"context": "comp"
},
{
"context": "entry"
}
],
"dependent": [
{
"name": "BuildNoteBase",
"parameter": [
{
"valueId": "qr"
},
{
"valueId": "comp"
},
{
"valueId": "entry"
}
]
}
]
},
{
"name": "noteName",
"source": [
{
"context": "qr"
}
],
"target": [
{
"context": "comp",
"element": "name",
"transform": "copy",
"parameter": [
{
"valueString": "InpatientDeathNote"
}
]
}
]
},
{
"name": "noteTitle",
"source": [
{
"context": "qr"
}
],
"target": [
{
"context": "comp",
"element": "title",
"transform": "copy",
"parameter": [
{
"valueString": "Death note"
}
]
}
]
},
{
"name": "noteType",
"source": [
{
"context": "qr"
}
],
"target": [
{
"context": "comp",
"element": "type",
"variable": "ty"
}
],
"rule": [
{
"name": "sghiCoding",
"source": [
{
"context": "qr"
}
],
"target": [
{
"context": "ty",
"element": "coding",
"variable": "sghi"
}
],
"rule": [
{
"name": "sghiSystem",
"source": [
{
"context": "qr"
}
],
"target": [
{
"context": "sghi",
"element": "system",
"transform": "copy",
"parameter": [
{
"valueString": "https://fhir.slade360.co.ke/fhir/CodeSystem/inpatient-document-type-codesystem"
}
]
}
]
},
{
"name": "sghiCode",
"source": [
{
"context": "qr"
}
],
"target": [
{
"context": "sghi",
"element": "code",
"transform": "copy",
"parameter": [
{
"valueString": "death-note"
}
]
}
]
},
{
"name": "sghiDisplay",
"source": [
{
"context": "qr"
}
],
"target": [
{
"context": "sghi",
"element": "display",
"transform": "copy",
"parameter": [
{
"valueString": "Death note"
}
]
}
]
}
]
},
{
"name": "typeText",
"source": [
{
"context": "qr"
}
],
"target": [
{
"context": "ty",
"element": "text",
"transform": "copy",
"parameter": [
{
"valueString": "Death note"
}
]
}
]
}
],
"documentation": "Deliberately not LOINC 64297-5. That code is the civil death certificate,\r\na different document with a different author and a different audience."
},
{
"name": "confirmedByRule",
"source": [
{
"context": "qr",
"element": "item",
"variable": "itC",
"condition": "linkId = 'confirmedBy'"
}
],
"rule": [
{
"name": "confirmedByAnswer",
"source": [
{
"context": "itC",
"element": "answer",
"variable": "aC"
}
],
"rule": [
{
"name": "attester",
"source": [
{
"context": "aC",
"element": "value",
"variable": "cv"
}
],
"target": [
{
"context": "comp",
"element": "attester",
"variable": "att"
}
],
"rule": [
{
"name": "attesterMode",
"source": [
{
"context": "aC"
}
],
"target": [
{
"context": "att",
"element": "mode",
"variable": "mode"
}
],
"rule": [
{
"name": "attModeCoding",
"source": [
{
"context": "aC"
}
],
"target": [
{
"context": "mode",
"element": "coding",
"variable": "modec"
}
],
"rule": [
{
"name": "attModeSystem",
"source": [
{
"context": "aC"
}
],
"target": [
{
"context": "modec",
"element": "system",
"transform": "copy",
"parameter": [
{
"valueString": "http://hl7.org/fhir/composition-attestation-mode"
}
]
}
]
},
{
"name": "attModeCode",
"source": [
{
"context": "aC"
}
],
"target": [
{
"context": "modec",
"element": "code",
"transform": "copy",
"parameter": [
{
"valueString": "professional"
}
]
}
]
},
{
"name": "attModeDisplay",
"source": [
{
"context": "aC"
}
],
"target": [
{
"context": "modec",
"element": "display",
"transform": "copy",
"parameter": [
{
"valueString": "Professional"
}
]
}
]
}
]
}
]
},
{
"name": "attesterTimeRule",
"source": [
{
"context": "qr",
"element": "item",
"variable": "itT",
"condition": "linkId = 'confirmedAt'"
}
],
"rule": [
{
"name": "confirmedAtAnswer",
"source": [
{
"context": "itT",
"element": "answer",
"listMode": "first",
"variable": "aT"
}
],
"rule": [
{
"name": "attesterTimeFromConfirmedAt",
"source": [
{
"context": "aT",
"element": "value",
"variable": "tv"
}
],
"target": [
{
"context": "att",
"element": "time",
"transform": "copy",
"parameter": [
{
"valueId": "tv"
}
]
}
]
}
]
}
]
},
{
"name": "attesterParty",
"source": [
{
"context": "cv"
}
],
"target": [
{
"context": "att",
"element": "party",
"transform": "copy",
"parameter": [
{
"valueId": "cv"
}
]
}
]
}
]
}
]
}
],
"documentation": "The clinician who confirmed the death attests the note."
},
{
"name": "confirmedAtSectionRule",
"source": [
{
"context": "qr",
"element": "item",
"variable": "it",
"condition": "(linkId = 'confirmedAt') and answer.value.exists()"
}
],
"target": [
{
"context": "comp",
"element": "section",
"variable": "sec"
}
],
"rule": [
{
"name": "confirmedAtTitle",
"source": [
{
"context": "it"
}
],
"target": [
{
"context": "sec",
"element": "title",
"transform": "copy",
"parameter": [
{
"valueString": "Death confirmed at"
}
]
}
]
},
{
"name": "confirmedAtText",
"source": [
{
"context": "it"
}
],
"target": [
{
"context": "sec"
}
],
"dependent": [
{
"name": "AddSectionText",
"parameter": [
{
"valueId": "it"
},
{
"valueId": "sec"
}
]
}
]
}
],
"documentation": "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."
},
{
"name": "circumstancesRule",
"source": [
{
"context": "qr",
"element": "item",
"variable": "it",
"condition": "(linkId = 'circumstances') and answer.value.exists()"
}
],
"target": [
{
"context": "comp",
"element": "section",
"variable": "sec"
}
],
"rule": [
{
"name": "circumstancesTitle",
"source": [
{
"context": "it"
}
],
"target": [
{
"context": "sec",
"element": "title",
"transform": "copy",
"parameter": [
{
"valueString": "Circumstances"
}
]
}
]
},
{
"name": "circumstancesText",
"source": [
{
"context": "it"
}
],
"target": [
{
"context": "sec"
}
],
"dependent": [
{
"name": "AddSectionText",
"parameter": [
{
"valueId": "it"
},
{
"valueId": "sec"
}
]
}
]
}
]
},
{
"name": "causeSectionRule",
"source": [
{
"context": "qr",
"element": "item",
"variable": "it",
"condition": "(linkId = 'causeStated') and answer.value.exists()"
}
],
"target": [
{
"context": "comp",
"element": "section",
"variable": "sec"
}
],
"rule": [
{
"name": "causeTitle",
"source": [
{
"context": "it"
}
],
"target": [
{
"context": "sec",
"element": "title",
"transform": "copy",
"parameter": [
{
"valueString": "Cause of death as stated"
}
]
}
]
},
{
"name": "causeText",
"source": [
{
"context": "it"
}
],
"target": [
{
"context": "sec"
}
],
"dependent": [
{
"name": "AddSectionText",
"parameter": [
{
"valueId": "it"
},
{
"valueId": "sec"
}
]
}
]
}
]
},
{
"name": "familyRule",
"source": [
{
"context": "qr",
"element": "item",
"variable": "it",
"condition": "(linkId = 'familyInformed') and answer.value.exists()"
}
],
"target": [
{
"context": "comp",
"element": "section",
"variable": "sec"
}
],
"rule": [
{
"name": "familyTitle",
"source": [
{
"context": "it"
}
],
"target": [
{
"context": "sec",
"element": "title",
"transform": "copy",
"parameter": [
{
"valueString": "Family informed"
}
]
}
]
},
{
"name": "familyText",
"source": [
{
"context": "it"
}
],
"target": [
{
"context": "sec"
}
],
"dependent": [
{
"name": "AddSectionText",
"parameter": [
{
"valueId": "it"
},
{
"valueId": "sec"
}
]
}
]
}
]
}
]
},
{
"name": "causeConditionRule",
"source": [
{
"context": "qr",
"element": "item",
"variable": "itCause",
"condition": "(linkId = 'causeStated') and answer.value.exists()"
}
],
"rule": [
{
"name": "causeAnswer",
"source": [
{
"context": "itCause",
"element": "answer",
"listMode": "first",
"variable": "aCause"
}
],
"rule": [
{
"name": "condition",
"source": [
{
"context": "aCause"
}
],
"target": [
{
"context": "bundle",
"element": "entry",
"variable": "entryC"
},
{
"context": "entryC",
"element": "resource",
"variable": "cond",
"transform": "create",
"parameter": [
{
"valueString": "Condition"
}
]
}
],
"rule": [
{
"name": "conditionBase",
"source": [
{
"context": "qr"
}
],
"target": [
{
"context": "cond"
},
{
"context": "entryC"
}
],
"dependent": [
{
"name": "BuildConditionBase",
"parameter": [
{
"valueId": "qr"
},
{
"valueId": "cond"
},
{
"valueId": "entryC"
}
]
}
]
},
{
"name": "verificationStatus",
"source": [
{
"context": "qr"
}
],
"target": [
{
"context": "cond",
"element": "verificationStatus",
"variable": "vs"
}
],
"rule": [
{
"name": "verCoding",
"source": [
{
"context": "qr"
}
],
"target": [
{
"context": "vs",
"element": "coding",
"variable": "vsc"
}
],
"rule": [
{
"name": "verSystem",
"source": [
{
"context": "qr"
}
],
"target": [
{
"context": "vsc",
"element": "system",
"transform": "copy",
"parameter": [
{
"valueString": "http://terminology.hl7.org/CodeSystem/condition-ver-status"
}
]
}
]
},
{
"name": "verCode",
"source": [
{
"context": "qr"
}
],
"target": [
{
"context": "vsc",
"element": "code",
"transform": "copy",
"parameter": [
{
"valueString": "confirmed"
}
]
}
]
},
{
"name": "verDisplay",
"source": [
{
"context": "qr"
}
],
"target": [
{
"context": "vsc",
"element": "display",
"transform": "copy",
"parameter": [
{
"valueString": "Confirmed"
}
]
}
]
}
]
}
]
},
{
"name": "conditionCode",
"source": [
{
"context": "aCause",
"element": "value",
"variable": "v"
}
],
"target": [
{
"context": "cond",
"element": "code",
"variable": "code"
}
],
"rule": [
{
"name": "codeText",
"source": [
{
"context": "v"
}
],
"target": [
{
"context": "code",
"element": "text",
"transform": "copy",
"parameter": [
{
"valueId": "v"
}
]
}
]
}
]
},
{
"name": "conditionNote",
"source": [
{
"context": "qr"
}
],
"target": [
{
"context": "cond",
"element": "note",
"variable": "note"
}
],
"rule": [
{
"name": "noteText",
"source": [
{
"context": "qr"
}
],
"target": [
{
"context": "note",
"element": "text",
"transform": "copy",
"parameter": [
{
"valueString": "Cause of death as stated on the inpatient death note."
}
]
}
]
}
]
}
]
}
]
}
],
"documentation": "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."
},
{
"name": "deceasedPatchRule",
"source": [
{
"context": "qr",
"element": "item",
"variable": "itAt",
"condition": "(linkId = 'confirmedAt') and answer.value.exists()"
}
],
"rule": [
{
"name": "confirmedAtAnswer",
"source": [
{
"context": "itAt",
"element": "answer",
"listMode": "first",
"variable": "aAt"
}
],
"rule": [
{
"name": "patientPatch",
"source": [
{
"context": "aAt"
}
],
"target": [
{
"context": "bundle",
"element": "entry",
"variable": "entryP"
},
{
"context": "entryP",
"element": "resource",
"variable": "params",
"transform": "create",
"parameter": [
{
"valueString": "Parameters"
}
]
}
],
"rule": [
{
"name": "patientReference",
"source": [
{
"context": "qr",
"element": "subject",
"variable": "s"
}
],
"rule": [
{
"name": "entryRequest",
"source": [
{
"context": "s",
"element": "reference",
"variable": "sref"
}
],
"target": [
{
"context": "entryP",
"element": "request",
"variable": "request"
}
],
"rule": [
{
"name": "requestMethod",
"source": [
{
"context": "qr"
}
],
"target": [
{
"context": "request",
"element": "method",
"transform": "copy",
"parameter": [
{
"valueString": "PATCH"
}
]
}
]
},
{
"name": "requestUrl",
"source": [
{
"context": "sref"
}
],
"target": [
{
"context": "request",
"element": "url",
"transform": "copy",
"parameter": [
{
"valueId": "sref"
}
]
}
],
"documentation": "The patient reference is already relative (\"Patient/1051\"), which\r\nis exactly what a transaction entry URL wants."
}
]
}
]
},
{
"name": "operation",
"source": [
{
"context": "aAt",
"element": "value",
"variable": "dv"
}
],
"target": [
{
"context": "params",
"element": "parameter",
"variable": "op"
}
],
"rule": [
{
"name": "operationName",
"source": [
{
"context": "aAt"
}
],
"target": [
{
"context": "op",
"element": "name",
"transform": "copy",
"parameter": [
{
"valueString": "operation"
}
]
}
]
},
{
"name": "operationType",
"source": [
{
"context": "aAt"
}
],
"target": [
{
"context": "op",
"element": "part",
"variable": "partType"
}
],
"rule": [
{
"name": "typeName",
"source": [
{
"context": "aAt"
}
],
"target": [
{
"context": "partType",
"element": "name",
"transform": "copy",
"parameter": [
{
"valueString": "type"
}
]
}
]
},
{
"name": "typeValue",
"source": [
{
"context": "aAt"
}
],
"target": [
{
"context": "partType",
"element": "value",
"transform": "copy",
"parameter": [
{
"valueString": "add"
}
]
}
]
}
]
},
{
"name": "operationPath",
"source": [
{
"context": "aAt"
}
],
"target": [
{
"context": "op",
"element": "part",
"variable": "partPath"
}
],
"rule": [
{
"name": "pathName",
"source": [
{
"context": "aAt"
}
],
"target": [
{
"context": "partPath",
"element": "name",
"transform": "copy",
"parameter": [
{
"valueString": "path"
}
]
}
]
},
{
"name": "pathValue",
"source": [
{
"context": "aAt"
}
],
"target": [
{
"context": "partPath",
"element": "value",
"transform": "copy",
"parameter": [
{
"valueString": "Patient"
}
]
}
]
}
]
},
{
"name": "operationElement",
"source": [
{
"context": "aAt"
}
],
"target": [
{
"context": "op",
"element": "part",
"variable": "partName"
}
],
"rule": [
{
"name": "nameName",
"source": [
{
"context": "aAt"
}
],
"target": [
{
"context": "partName",
"element": "name",
"transform": "copy",
"parameter": [
{
"valueString": "name"
}
]
}
]
},
{
"name": "nameValue",
"source": [
{
"context": "aAt"
}
],
"target": [
{
"context": "partName",
"element": "value",
"transform": "copy",
"parameter": [
{
"valueString": "deceasedDateTime"
}
]
}
]
}
]
},
{
"name": "operationValue",
"source": [
{
"context": "aAt"
}
],
"target": [
{
"context": "op",
"element": "part",
"variable": "partValue"
}
],
"rule": [
{
"name": "valueName",
"source": [
{
"context": "aAt"
}
],
"target": [
{
"context": "partValue",
"element": "name",
"transform": "copy",
"parameter": [
{
"valueString": "value"
}
]
}
]
},
{
"name": "valueValue",
"source": [
{
"context": "dv"
}
],
"target": [
{
"context": "partValue",
"element": "value",
"transform": "copy",
"parameter": [
{
"valueId": "dv"
}
]
}
]
}
]
}
]
}
]
}
]
}
],
"documentation": "Patient.deceasedDateTime, by FHIRPath PATCH."
}
]
},
{
"name": "BuildNoteBase",
"documentation": "─────────────────────────────────────────────────────────────────────────────\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.",
"input": [
{
"name": "qr",
"type": "QR",
"mode": "source"
},
{
"name": "comp",
"type": "Composition",
"mode": "target"
},
{
"name": "entry",
"mode": "target"
}
],
"rule": [
{
"name": "idAndFullUrl",
"source": [
{
"context": "qr"
}
],
"target": [
{
"context": "comp",
"element": "id",
"transform": "uuid"
}
],
"dependent": [
{
"name": "SetCompositionFullUrl",
"parameter": [
{
"valueId": "comp"
},
{
"valueId": "entry"
}
]
}
]
},
{
"name": "entryRequest",
"source": [
{
"context": "qr"
}
],
"target": [
{
"context": "entry",
"element": "request",
"variable": "request"
}
],
"rule": [
{
"name": "requestMethod",
"source": [
{
"context": "qr"
}
],
"target": [
{
"context": "request",
"element": "method",
"transform": "copy",
"parameter": [
{
"valueString": "POST"
}
]
}
]
},
{
"name": "requestUrl",
"source": [
{
"context": "qr"
}
],
"target": [
{
"context": "request",
"element": "url",
"transform": "copy",
"parameter": [
{
"valueString": "Composition"
}
]
}
]
}
]
},
{
"name": "status",
"source": [
{
"context": "qr"
}
],
"target": [
{
"context": "comp",
"element": "status",
"transform": "copy",
"parameter": [
{
"valueString": "final"
}
]
}
]
},
{
"name": "subject",
"source": [
{
"context": "qr",
"element": "subject",
"variable": "s"
}
],
"target": [
{
"context": "comp",
"element": "subject",
"transform": "copy",
"parameter": [
{
"valueId": "s"
}
]
}
]
},
{
"name": "encounter",
"source": [
{
"context": "qr",
"element": "encounter",
"variable": "e"
}
],
"target": [
{
"context": "comp",
"element": "encounter",
"transform": "copy",
"parameter": [
{
"valueId": "e"
}
]
}
]
},
{
"name": "date",
"source": [
{
"context": "qr",
"element": "authored",
"variable": "t"
}
],
"target": [
{
"context": "comp",
"element": "date",
"transform": "copy",
"parameter": [
{
"valueId": "t"
}
]
}
],
"documentation": "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."
},
{
"name": "dateFallback",
"source": [
{
"context": "qr",
"condition": "authored.exists().not()"
}
],
"rule": [
{
"name": "dateFromExtractionTime",
"source": [
{
"context": "qr"
}
],
"target": [
{
"context": "comp",
"element": "date",
"transform": "evaluate",
"parameter": [
{
"valueId": "qr"
},
{
"valueString": "now()"
}
]
}
]
}
]
},
{
"name": "authorFromAuthor",
"source": [
{
"context": "qr",
"element": "author",
"variable": "a"
}
],
"target": [
{
"context": "comp",
"element": "author",
"transform": "copy",
"parameter": [
{
"valueId": "a"
}
]
}
],
"documentation": "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."
},
{
"name": "authorFallback",
"source": [
{
"context": "qr",
"condition": "author.exists().not()"
}
],
"rule": [
{
"name": "authorFromSource",
"source": [
{
"context": "qr",
"element": "source",
"variable": "src"
}
],
"target": [
{
"context": "comp",
"element": "author",
"transform": "copy",
"parameter": [
{
"valueId": "src"
}
]
}
]
}
]
},
{
"name": "linkQuestionnaireResponse",
"source": [
{
"context": "qr"
}
],
"target": [
{
"context": "comp",
"element": "relatesTo",
"variable": "rel"
}
],
"rule": [
{
"name": "relatesToType",
"source": [
{
"context": "qr"
}
],
"target": [
{
"context": "rel",
"element": "type",
"transform": "copy",
"parameter": [
{
"valueString": "derived-from"
}
]
}
]
},
{
"name": "relatesToTarget",
"source": [
{
"context": "qr"
}
],
"target": [
{
"context": "rel",
"element": "resourceReference",
"variable": "ref",
"transform": "create",
"parameter": [
{
"valueString": "Reference"
}
]
}
],
"rule": [
{
"name": "relatesToRef",
"source": [
{
"context": "qr",
"element": "id",
"variable": "qid"
}
],
"target": [
{
"context": "ref",
"element": "reference",
"transform": "copy",
"parameter": [
{
"valueId": "qid"
}
]
}
]
}
]
}
]
}
]
},
{
"name": "AddSectionText",
"input": [
{
"name": "it",
"mode": "source"
},
{
"name": "sec",
"mode": "target"
}
],
"rule": [
{
"name": "sectionAnswer",
"source": [
{
"context": "it",
"element": "answer",
"listMode": "first",
"variable": "a"
}
],
"rule": [
{
"name": "sectionText",
"source": [
{
"context": "a",
"element": "value",
"variable": "v"
}
],
"target": [
{
"context": "sec",
"element": "text",
"variable": "narrative"
}
],
"rule": [
{
"name": "narrativeStatus",
"source": [
{
"context": "v"
}
],
"target": [
{
"context": "narrative",
"element": "status",
"transform": "copy",
"parameter": [
{
"valueString": "generated"
}
]
}
]
},
{
"name": "narrativeXhtml",
"source": [
{
"context": "v"
}
],
"target": [
{
"context": "narrative",
"element": "div",
"variable": "xhtml",
"transform": "create",
"parameter": [
{
"valueString": "xhtml"
}
]
}
],
"rule": [
{
"name": "narrativeDiv",
"source": [
{
"context": "v"
}
],
"target": [
{
"context": "xhtml",
"element": "value",
"transform": "evaluate",
"parameter": [
{
"valueId": "a"
},
{
"valueString": "'<div xmlns=\"http://www.w3.org/1999/xhtml\"><p>' + value.toString().escape('html') + '</p></div>'"
}
]
}
]
}
]
}
]
}
]
}
]
},
{
"name": "SetCompositionFullUrl",
"input": [
{
"name": "comp",
"type": "Composition",
"mode": "source"
},
{
"name": "entry",
"mode": "target"
}
],
"rule": [
{
"name": "assignFullUrl",
"source": [
{
"context": "comp",
"element": "id",
"variable": "id"
}
],
"target": [
{
"context": "entry",
"element": "fullUrl",
"transform": "append",
"parameter": [
{
"valueString": "https://fhir.slade360.co.ke/fhir/Composition/"
},
{
"valueId": "id"
}
]
}
]
}
]
},
{
"name": "BuildConditionBase",
"input": [
{
"name": "qr",
"type": "QR",
"mode": "source"
},
{
"name": "cond",
"type": "Condition",
"mode": "target"
},
{
"name": "entry",
"mode": "target"
}
],
"rule": [
{
"name": "idAndFullUrl",
"source": [
{
"context": "qr"
}
],
"target": [
{
"context": "cond",
"element": "id",
"transform": "uuid"
}
],
"dependent": [
{
"name": "SetConditionFullUrl",
"parameter": [
{
"valueId": "cond"
},
{
"valueId": "entry"
}
]
}
]
},
{
"name": "entryRequest",
"source": [
{
"context": "qr"
}
],
"target": [
{
"context": "entry",
"element": "request",
"variable": "request"
}
],
"rule": [
{
"name": "requestMethod",
"source": [
{
"context": "qr"
}
],
"target": [
{
"context": "request",
"element": "method",
"transform": "copy",
"parameter": [
{
"valueString": "POST"
}
]
}
]
},
{
"name": "requestUrl",
"source": [
{
"context": "qr"
}
],
"target": [
{
"context": "request",
"element": "url",
"transform": "copy",
"parameter": [
{
"valueString": "Condition"
}
]
}
]
}
]
},
{
"name": "clinicalStatus",
"source": [
{
"context": "qr"
}
],
"target": [
{
"context": "cond",
"element": "clinicalStatus",
"variable": "cs"
}
],
"rule": [
{
"name": "clinCoding",
"source": [
{
"context": "qr"
}
],
"target": [
{
"context": "cs",
"element": "coding",
"variable": "csc"
}
],
"rule": [
{
"name": "clinSystem",
"source": [
{
"context": "qr"
}
],
"target": [
{
"context": "csc",
"element": "system",
"transform": "copy",
"parameter": [
{
"valueString": "http://terminology.hl7.org/CodeSystem/condition-clinical"
}
]
}
]
},
{
"name": "clinCode",
"source": [
{
"context": "qr"
}
],
"target": [
{
"context": "csc",
"element": "code",
"transform": "copy",
"parameter": [
{
"valueString": "active"
}
]
}
]
},
{
"name": "clinDisplay",
"source": [
{
"context": "qr"
}
],
"target": [
{
"context": "csc",
"element": "display",
"transform": "copy",
"parameter": [
{
"valueString": "Active"
}
]
}
]
}
]
}
]
},
{
"name": "category",
"source": [
{
"context": "qr"
}
],
"target": [
{
"context": "cond",
"element": "category",
"variable": "cat"
}
],
"rule": [
{
"name": "catCoding",
"source": [
{
"context": "qr"
}
],
"target": [
{
"context": "cat",
"element": "coding",
"variable": "catc"
}
],
"rule": [
{
"name": "catSystem",
"source": [
{
"context": "qr"
}
],
"target": [
{
"context": "catc",
"element": "system",
"transform": "copy",
"parameter": [
{
"valueString": "http://terminology.hl7.org/CodeSystem/condition-category"
}
]
}
]
},
{
"name": "catCode",
"source": [
{
"context": "qr"
}
],
"target": [
{
"context": "catc",
"element": "code",
"transform": "copy",
"parameter": [
{
"valueString": "encounter-diagnosis"
}
]
}
]
},
{
"name": "catDisplay",
"source": [
{
"context": "qr"
}
],
"target": [
{
"context": "catc",
"element": "display",
"transform": "copy",
"parameter": [
{
"valueString": "Encounter Diagnosis"
}
]
}
]
}
]
}
]
},
{
"name": "subject",
"source": [
{
"context": "qr",
"element": "subject",
"variable": "s"
}
],
"target": [
{
"context": "cond",
"element": "subject",
"transform": "copy",
"parameter": [
{
"valueId": "s"
}
]
}
]
},
{
"name": "encounter",
"source": [
{
"context": "qr",
"element": "encounter",
"variable": "e"
}
],
"target": [
{
"context": "cond",
"element": "encounter",
"transform": "copy",
"parameter": [
{
"valueId": "e"
}
]
}
]
},
{
"name": "recordedDate",
"source": [
{
"context": "qr",
"element": "authored",
"variable": "t"
}
],
"target": [
{
"context": "cond",
"element": "recordedDate",
"transform": "copy",
"parameter": [
{
"valueId": "t"
}
]
}
]
},
{
"name": "participantFromAuthor",
"source": [
{
"context": "qr",
"element": "author",
"variable": "a"
}
],
"target": [
{
"context": "cond",
"element": "participant",
"variable": "part"
}
],
"rule": [
{
"name": "participantActor",
"source": [
{
"context": "qr"
}
],
"target": [
{
"context": "part",
"element": "actor",
"transform": "copy",
"parameter": [
{
"valueId": "a"
}
]
}
]
}
]
},
{
"name": "participantFallback",
"source": [
{
"context": "qr",
"condition": "author.exists().not()"
}
],
"rule": [
{
"name": "participantFromSource",
"source": [
{
"context": "qr",
"element": "source",
"variable": "src"
}
],
"target": [
{
"context": "cond",
"element": "participant",
"variable": "part2"
}
],
"rule": [
{
"name": "participantActorFromSource",
"source": [
{
"context": "qr"
}
],
"target": [
{
"context": "part2",
"element": "actor",
"transform": "copy",
"parameter": [
{
"valueId": "src"
}
]
}
]
}
]
}
]
},
{
"name": "linkQuestionnaireResponse",
"source": [
{
"context": "qr"
}
],
"target": [
{
"context": "cond",
"element": "evidence",
"variable": "ev"
}
],
"rule": [
{
"name": "evidenceTarget",
"source": [
{
"context": "qr"
}
],
"target": [
{
"context": "ev",
"element": "reference",
"variable": "ref",
"transform": "create",
"parameter": [
{
"valueString": "Reference"
}
]
}
],
"rule": [
{
"name": "evidenceRef",
"source": [
{
"context": "qr",
"element": "id",
"variable": "qid"
}
],
"target": [
{
"context": "ref",
"element": "reference",
"transform": "copy",
"parameter": [
{
"valueId": "qid"
}
]
}
]
}
]
}
]
}
]
},
{
"name": "SetConditionFullUrl",
"input": [
{
"name": "cond",
"type": "Condition",
"mode": "source"
},
{
"name": "entry",
"mode": "target"
}
],
"rule": [
{
"name": "assignFullUrl",
"source": [
{
"context": "cond",
"element": "id",
"variable": "id"
}
],
"target": [
{
"context": "entry",
"element": "fullUrl",
"transform": "append",
"parameter": [
{
"valueString": "https://fhir.slade360.co.ke/fhir/Condition/"
},
{
"valueId": "id"
}
]
}
]
}
]
}
]
}