FHIR IG analytics| Package | silfhirprofileig |
| Resource Type | StructureMap |
| Id | StructureMap-ExtractInpatientDischargeNote.json |
| FHIR Version | R5 |
| Source | https://build.fhir.org/ig/savannahghi/sil_fhir_profile_ig/StructureMap-ExtractInpatientDischargeNote.html |
| URL | https://fhir.slade360.co.ke/fhir/StructureMap/ExtractInpatientDischargeNote |
| Version | 0.1.0 |
| Status | active |
| Date | 2026-09-11T12:18:36+00:00 |
| Name | ExtractInpatientDischargeNote |
| Title | Inpatient Discharge Note Extraction |
| Description | Turns a response to the inpatient discharge note into a discharge-summary Composition and a ServiceRequest for the follow-up. Medication on discharge is referenced, never copied: those MedicationRequests already exist on the server -- the form picks them from it -- so they become section entries rather than new resources. The follow-up is intent `plan` rather than an Appointment because the form captures it as free text with no date to book against; give the item a date and an Appointment becomes the truer target. The Encounter is deliberately untouched: closing the stay -- Encounter.status and the discharge disposition -- belongs to the EMR's discharge workflow, which knows about bed release, billing and the actual moment the patient left. Writing a note is not the same event as being discharged, and a map that conflated them would close stays early. |
No resources found
No resources found
Note: links and images are rebased to the (stated) source
Generated Narrative: StructureMap ExtractInpatientDischargeNote
/// url = 'https://fhir.slade360.co.ke/fhir/StructureMap/ExtractInpatientDischargeNote' /// name = 'ExtractInpatientDischargeNote' /// title = 'Inpatient Discharge Note Extraction' /// status = 'active' /// description = 'Turns a response to the inpatient discharge note into a discharge-summary Composition and a ServiceRequest for the follow-up. Medication on discharge is referenced, never copied: those MedicationRequests already exist on the server -- the form picks them from it -- so they become section entries rather than new resources. The follow-up is intent `plan` rather than an Appointment because the form captures it as free text with no date to book against; give the item a date and an Appointment becomes the truer target. The Encounter is deliberately untouched: closing the stay -- Encounter.status and the discharge disposition -- belongs to the EMR\'s discharge workflow, which knows about bed release, billing and the actual moment the patient left. Writing a note is not the same event as being discharged, and a map that conflated them would close stays early.' 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/ServiceRequest" alias ServiceRequest as target group ExtractInpatientDischargeNote(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 = 'InpatientDischargeNote' "noteName"; qr -> comp.title = 'Discharge note' "noteTitle"; 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 = 'discharge-note' "sghiCode"; qr -> sghi.display = 'Discharge note' "sghiDisplay"; } "sghiCoding"; qr -> ty.coding as loinc then { qr -> loinc.system = 'http://loinc.org' "loincSystem"; qr -> loinc.code = '18842-5' "loincCode"; qr -> loinc.display = 'Discharge summary' "loincDisplay"; } "loincCoding"; qr -> ty.text = 'Discharge summary' "typeText"; } "noteType"; qr.item as it where ((linkId = 'summary') and answer.value.exists()) -> comp.section as sec then { it -> sec.title = 'Admission summary' "summaryTitle"; it -> sec then AddSectionText(it, sec) "summaryText"; } "summaryRule"; // One section, one entry per medication. No MedicationRequest is created: // the form picked these off the server, and minting copies would double the // patient's prescription list. qr.item as itM where ((linkId = 'medsOnDischarge') and answer.value.exists()) -> comp.section as secM then { itM -> secM.title = 'Medication on discharge' "medsTitle"; itM.answer as aM then { aM.value as mv -> secM.entry = mv "medsEntry"; } "medsAnswers"; } "medsRule"; qr.item as it where ((linkId = 'followUp') and answer.value.exists()) -> comp.section as sec then { it -> sec.title = 'Follow-up' "followUpTitle"; it -> sec then AddSectionText(it, sec) "followUpText"; } "followUpSectionRule"; qr.item as it where ((linkId = 'adviceGiven') and answer.value.exists()) -> comp.section as sec then { it -> sec.title = 'Advice given' "adviceTitle"; it -> sec then AddSectionText(it, sec) "adviceText"; } "adviceRule"; } "composition"; // The follow-up also leaves the document, so it can be worked rather than read. qr.item as itF where ((linkId = 'followUp') and answer.value.exists()) then { itF.answer first as aF then { aF -> bundle.entry as entryS, entryS.resource = create('ServiceRequest') as sr then { qr -> sr.id = uuid() then SetServiceRequestFullUrl(sr, entryS) "idAndFullUrl"; qr -> entryS.request as request then { qr -> request.method = 'POST' "requestMethod"; qr -> request.url = 'ServiceRequest' "requestUrl"; } "entryRequest"; qr -> sr.status = 'active' "status"; qr -> sr.intent = 'plan' "intent"; qr -> sr.priority = 'routine' "priority"; // R5 ServiceRequest.code is a CodeableReference, so the concept sits one // level down. aF.value as v -> sr.code as codeRef then { aF -> codeRef.concept as concept then { aF -> concept.coding as coding then { aF -> coding.system = 'https://fhir.slade360.co.ke/fhir/CodeSystem/inpatient-clinical-concept-codesystem' "codeSystem"; aF -> coding.code = 'discharge-follow-up' "codeCode"; aF -> coding.display = 'Follow-up arranged on discharge' "codeDisplay"; } "codeCoding"; v -> concept.text = v "codeText"; } "codeConcept"; } "serviceRequestCode"; qr.subject as s -> sr.subject = s; qr.encounter as e -> sr.encounter = e; qr.authored as t -> sr.authoredOn = t "authoredOn"; qr.author as a -> sr.requester = a "requesterFromAuthor"; qr where (author.exists().not()) then { qr.source as src -> sr.requester = src "requesterFromSource"; } "requesterFallback"; qr -> sr.supportingInfo as si then { qr -> si.reference = create('Reference') as ref then { qr.id as qid -> ref.reference = qid "supportingInfoRef"; } "supportingInfoTarget"; } "linkQuestionnaireResponse"; } "serviceRequest"; } "followUpAnswer"; } "followUpRequestRule"; } // ───────────────────────────────────────────────────────────────────────────── // 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 SetServiceRequestFullUrl(source sr : ServiceRequest, target entry) { sr.id as id -> entry.fullUrl = append('https://fhir.slade360.co.ke/fhir/ServiceRequest/', id) "assignFullUrl"; }
{
"resourceType": "StructureMap",
"id": "ExtractInpatientDischargeNote",
"text": {
"status": "generated",
"div": "<!-- snip (see above) -->"
},
"url": "https://fhir.slade360.co.ke/fhir/StructureMap/ExtractInpatientDischargeNote",
"version": "0.1.0",
"name": "ExtractInpatientDischargeNote",
"title": "Inpatient Discharge 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": "Turns a response to the inpatient discharge note into a discharge-summary Composition and a ServiceRequest for the follow-up. Medication on discharge is referenced, never copied: those MedicationRequests already exist on the server -- the form picks them from it -- so they become section entries rather than new resources. The follow-up is intent `plan` rather than an Appointment because the form captures it as free text with no date to book against; give the item a date and an Appointment becomes the truer target. The Encounter is deliberately untouched: closing the stay -- Encounter.status and the discharge disposition -- belongs to the EMR's discharge workflow, which knows about bed release, billing and the actual moment the patient left. Writing a note is not the same event as being discharged, and a map that conflated them would close stays early.",
"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/ServiceRequest",
"mode": "target",
"alias": "ServiceRequest"
}
],
"group": [
{
"name": "ExtractInpatientDischargeNote",
"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": "InpatientDischargeNote"
}
]
}
]
},
{
"name": "noteTitle",
"source": [
{
"context": "qr"
}
],
"target": [
{
"context": "comp",
"element": "title",
"transform": "copy",
"parameter": [
{
"valueString": "Discharge 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": "discharge-note"
}
]
}
]
},
{
"name": "sghiDisplay",
"source": [
{
"context": "qr"
}
],
"target": [
{
"context": "sghi",
"element": "display",
"transform": "copy",
"parameter": [
{
"valueString": "Discharge note"
}
]
}
]
}
]
},
{
"name": "loincCoding",
"source": [
{
"context": "qr"
}
],
"target": [
{
"context": "ty",
"element": "coding",
"variable": "loinc"
}
],
"rule": [
{
"name": "loincSystem",
"source": [
{
"context": "qr"
}
],
"target": [
{
"context": "loinc",
"element": "system",
"transform": "copy",
"parameter": [
{
"valueString": "http://loinc.org"
}
]
}
]
},
{
"name": "loincCode",
"source": [
{
"context": "qr"
}
],
"target": [
{
"context": "loinc",
"element": "code",
"transform": "copy",
"parameter": [
{
"valueString": "18842-5"
}
]
}
]
},
{
"name": "loincDisplay",
"source": [
{
"context": "qr"
}
],
"target": [
{
"context": "loinc",
"element": "display",
"transform": "copy",
"parameter": [
{
"valueString": "Discharge summary"
}
]
}
]
}
]
},
{
"name": "typeText",
"source": [
{
"context": "qr"
}
],
"target": [
{
"context": "ty",
"element": "text",
"transform": "copy",
"parameter": [
{
"valueString": "Discharge summary"
}
]
}
]
}
]
},
{
"name": "summaryRule",
"source": [
{
"context": "qr",
"element": "item",
"variable": "it",
"condition": "(linkId = 'summary') and answer.value.exists()"
}
],
"target": [
{
"context": "comp",
"element": "section",
"variable": "sec"
}
],
"rule": [
{
"name": "summaryTitle",
"source": [
{
"context": "it"
}
],
"target": [
{
"context": "sec",
"element": "title",
"transform": "copy",
"parameter": [
{
"valueString": "Admission summary"
}
]
}
]
},
{
"name": "summaryText",
"source": [
{
"context": "it"
}
],
"target": [
{
"context": "sec"
}
],
"dependent": [
{
"name": "AddSectionText",
"parameter": [
{
"valueId": "it"
},
{
"valueId": "sec"
}
]
}
]
}
]
},
{
"name": "medsRule",
"source": [
{
"context": "qr",
"element": "item",
"variable": "itM",
"condition": "(linkId = 'medsOnDischarge') and answer.value.exists()"
}
],
"target": [
{
"context": "comp",
"element": "section",
"variable": "secM"
}
],
"rule": [
{
"name": "medsTitle",
"source": [
{
"context": "itM"
}
],
"target": [
{
"context": "secM",
"element": "title",
"transform": "copy",
"parameter": [
{
"valueString": "Medication on discharge"
}
]
}
]
},
{
"name": "medsAnswers",
"source": [
{
"context": "itM",
"element": "answer",
"variable": "aM"
}
],
"rule": [
{
"name": "medsEntry",
"source": [
{
"context": "aM",
"element": "value",
"variable": "mv"
}
],
"target": [
{
"context": "secM",
"element": "entry",
"transform": "copy",
"parameter": [
{
"valueId": "mv"
}
]
}
]
}
]
}
],
"documentation": "One section, one entry per medication. No MedicationRequest is created:\r\nthe form picked these off the server, and minting copies would double the\r\npatient's prescription list."
},
{
"name": "followUpSectionRule",
"source": [
{
"context": "qr",
"element": "item",
"variable": "it",
"condition": "(linkId = 'followUp') and answer.value.exists()"
}
],
"target": [
{
"context": "comp",
"element": "section",
"variable": "sec"
}
],
"rule": [
{
"name": "followUpTitle",
"source": [
{
"context": "it"
}
],
"target": [
{
"context": "sec",
"element": "title",
"transform": "copy",
"parameter": [
{
"valueString": "Follow-up"
}
]
}
]
},
{
"name": "followUpText",
"source": [
{
"context": "it"
}
],
"target": [
{
"context": "sec"
}
],
"dependent": [
{
"name": "AddSectionText",
"parameter": [
{
"valueId": "it"
},
{
"valueId": "sec"
}
]
}
]
}
]
},
{
"name": "adviceRule",
"source": [
{
"context": "qr",
"element": "item",
"variable": "it",
"condition": "(linkId = 'adviceGiven') and answer.value.exists()"
}
],
"target": [
{
"context": "comp",
"element": "section",
"variable": "sec"
}
],
"rule": [
{
"name": "adviceTitle",
"source": [
{
"context": "it"
}
],
"target": [
{
"context": "sec",
"element": "title",
"transform": "copy",
"parameter": [
{
"valueString": "Advice given"
}
]
}
]
},
{
"name": "adviceText",
"source": [
{
"context": "it"
}
],
"target": [
{
"context": "sec"
}
],
"dependent": [
{
"name": "AddSectionText",
"parameter": [
{
"valueId": "it"
},
{
"valueId": "sec"
}
]
}
]
}
]
}
]
},
{
"name": "followUpRequestRule",
"source": [
{
"context": "qr",
"element": "item",
"variable": "itF",
"condition": "(linkId = 'followUp') and answer.value.exists()"
}
],
"rule": [
{
"name": "followUpAnswer",
"source": [
{
"context": "itF",
"element": "answer",
"listMode": "first",
"variable": "aF"
}
],
"rule": [
{
"name": "serviceRequest",
"source": [
{
"context": "aF"
}
],
"target": [
{
"context": "bundle",
"element": "entry",
"variable": "entryS"
},
{
"context": "entryS",
"element": "resource",
"variable": "sr",
"transform": "create",
"parameter": [
{
"valueString": "ServiceRequest"
}
]
}
],
"rule": [
{
"name": "idAndFullUrl",
"source": [
{
"context": "qr"
}
],
"target": [
{
"context": "sr",
"element": "id",
"transform": "uuid"
}
],
"dependent": [
{
"name": "SetServiceRequestFullUrl",
"parameter": [
{
"valueId": "sr"
},
{
"valueId": "entryS"
}
]
}
]
},
{
"name": "entryRequest",
"source": [
{
"context": "qr"
}
],
"target": [
{
"context": "entryS",
"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": "ServiceRequest"
}
]
}
]
}
]
},
{
"name": "status",
"source": [
{
"context": "qr"
}
],
"target": [
{
"context": "sr",
"element": "status",
"transform": "copy",
"parameter": [
{
"valueString": "active"
}
]
}
]
},
{
"name": "intent",
"source": [
{
"context": "qr"
}
],
"target": [
{
"context": "sr",
"element": "intent",
"transform": "copy",
"parameter": [
{
"valueString": "plan"
}
]
}
]
},
{
"name": "priority",
"source": [
{
"context": "qr"
}
],
"target": [
{
"context": "sr",
"element": "priority",
"transform": "copy",
"parameter": [
{
"valueString": "routine"
}
]
}
]
},
{
"name": "serviceRequestCode",
"source": [
{
"context": "aF",
"element": "value",
"variable": "v"
}
],
"target": [
{
"context": "sr",
"element": "code",
"variable": "codeRef"
}
],
"rule": [
{
"name": "codeConcept",
"source": [
{
"context": "aF"
}
],
"target": [
{
"context": "codeRef",
"element": "concept",
"variable": "concept"
}
],
"rule": [
{
"name": "codeCoding",
"source": [
{
"context": "aF"
}
],
"target": [
{
"context": "concept",
"element": "coding",
"variable": "coding"
}
],
"rule": [
{
"name": "codeSystem",
"source": [
{
"context": "aF"
}
],
"target": [
{
"context": "coding",
"element": "system",
"transform": "copy",
"parameter": [
{
"valueString": "https://fhir.slade360.co.ke/fhir/CodeSystem/inpatient-clinical-concept-codesystem"
}
]
}
]
},
{
"name": "codeCode",
"source": [
{
"context": "aF"
}
],
"target": [
{
"context": "coding",
"element": "code",
"transform": "copy",
"parameter": [
{
"valueString": "discharge-follow-up"
}
]
}
]
},
{
"name": "codeDisplay",
"source": [
{
"context": "aF"
}
],
"target": [
{
"context": "coding",
"element": "display",
"transform": "copy",
"parameter": [
{
"valueString": "Follow-up arranged on discharge"
}
]
}
]
}
]
},
{
"name": "codeText",
"source": [
{
"context": "v"
}
],
"target": [
{
"context": "concept",
"element": "text",
"transform": "copy",
"parameter": [
{
"valueId": "v"
}
]
}
]
}
]
}
],
"documentation": "R5 ServiceRequest.code is a CodeableReference, so the concept sits one\r\nlevel down."
},
{
"name": "subject",
"source": [
{
"context": "qr",
"element": "subject",
"variable": "s"
}
],
"target": [
{
"context": "sr",
"element": "subject",
"transform": "copy",
"parameter": [
{
"valueId": "s"
}
]
}
]
},
{
"name": "encounter",
"source": [
{
"context": "qr",
"element": "encounter",
"variable": "e"
}
],
"target": [
{
"context": "sr",
"element": "encounter",
"transform": "copy",
"parameter": [
{
"valueId": "e"
}
]
}
]
},
{
"name": "authoredOn",
"source": [
{
"context": "qr",
"element": "authored",
"variable": "t"
}
],
"target": [
{
"context": "sr",
"element": "authoredOn",
"transform": "copy",
"parameter": [
{
"valueId": "t"
}
]
}
]
},
{
"name": "requesterFromAuthor",
"source": [
{
"context": "qr",
"element": "author",
"variable": "a"
}
],
"target": [
{
"context": "sr",
"element": "requester",
"transform": "copy",
"parameter": [
{
"valueId": "a"
}
]
}
]
},
{
"name": "requesterFallback",
"source": [
{
"context": "qr",
"condition": "author.exists().not()"
}
],
"rule": [
{
"name": "requesterFromSource",
"source": [
{
"context": "qr",
"element": "source",
"variable": "src"
}
],
"target": [
{
"context": "sr",
"element": "requester",
"transform": "copy",
"parameter": [
{
"valueId": "src"
}
]
}
]
}
]
},
{
"name": "linkQuestionnaireResponse",
"source": [
{
"context": "qr"
}
],
"target": [
{
"context": "sr",
"element": "supportingInfo",
"variable": "si"
}
],
"rule": [
{
"name": "supportingInfoTarget",
"source": [
{
"context": "qr"
}
],
"target": [
{
"context": "si",
"element": "reference",
"variable": "ref",
"transform": "create",
"parameter": [
{
"valueString": "Reference"
}
]
}
],
"rule": [
{
"name": "supportingInfoRef",
"source": [
{
"context": "qr",
"element": "id",
"variable": "qid"
}
],
"target": [
{
"context": "ref",
"element": "reference",
"transform": "copy",
"parameter": [
{
"valueId": "qid"
}
]
}
]
}
]
}
]
}
]
}
]
}
],
"documentation": "The follow-up also leaves the document, so it can be worked rather than read."
}
]
},
{
"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": "SetServiceRequestFullUrl",
"input": [
{
"name": "sr",
"type": "ServiceRequest",
"mode": "source"
},
{
"name": "entry",
"mode": "target"
}
],
"rule": [
{
"name": "assignFullUrl",
"source": [
{
"context": "sr",
"element": "id",
"variable": "id"
}
],
"target": [
{
"context": "entry",
"element": "fullUrl",
"transform": "append",
"parameter": [
{
"valueString": "https://fhir.slade360.co.ke/fhir/ServiceRequest/"
},
{
"valueId": "id"
}
]
}
]
}
]
}
]
}