FHIR © HL7.org  |  FHIRsmith 4.0.1  |  Server Home  |  XIG Home  |  XIG Stats  | 

FHIR IG analytics

Packagesilfhirprofileig
Resource TypeStructureMap
IdStructureMap-ExtractInpatientAdmissionNote.json
FHIR VersionR5
Sourcehttps://build.fhir.org/ig/savannahghi/sil_fhir_profile_ig/StructureMap-ExtractInpatientAdmissionNote.html
URLhttps://fhir.slade360.co.ke/fhir/StructureMap/ExtractInpatientAdmissionNote
Version0.1.0
Statusactive
Date2026-09-11T12:18:36+00:00
NameExtractInpatientAdmissionNote
TitleInpatient Admission Note Extraction
DescriptionTurns a response to the inpatient admission note into a Composition with one section per heading, plus a Condition for the impression -- the one line on this form that belongs on the problem list. The Condition is verificationStatus `provisional` because an admitting impression is exactly that; the team confirms or replaces it as the stay goes on. Its code carries the clinician's wording as text rather than an ICD-11 coding, because the form asks for prose and guessing a diagnosis code from prose is not something a map should do.

Resources that use this resource

No resources found


Resources that this resource uses

No resources found


Narrative

Note: links and images are rebased to the (stated) source

Generated Narrative: StructureMap ExtractInpatientAdmissionNote

/// url = 'https://fhir.slade360.co.ke/fhir/StructureMap/ExtractInpatientAdmissionNote'
/// name = 'ExtractInpatientAdmissionNote'
/// title = 'Inpatient Admission Note Extraction'
/// status = 'active'
/// description = 'Turns a response to the inpatient admission note into a Composition with one section per heading, plus a Condition for the impression -- the one line on this form that belongs on the problem list. The Condition is verificationStatus `provisional` because an admitting impression is exactly that; the team confirms or replaces it as the stay goes on. Its code carries the clinician\'s wording as text rather than an ICD-11 coding, because the form asks for prose and guessing a diagnosis code from prose is not something a map should do.'

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

group ExtractInpatientAdmissionNote(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 = 'InpatientAdmissionNote' "noteName";
    qr -> comp.title = 'Admission 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 = 'admission-note' "sghiCode";
        qr -> sghi.display = 'Admission note' "sghiDisplay";
      } "sghiCoding";
      qr -> ty.coding as loinc then {
        qr -> loinc.system = 'http://loinc.org' "loincSystem";
        qr -> loinc.code = '34117-2' "loincCode";
        qr -> loinc.display = 'History and physical note' "loincDisplay";
      } "loincCoding";
      qr -> ty.text = 'Admission note' "typeText";
    } "noteType";
    qr.item as it where ((linkId = 'history') and answer.value.exists()) -> comp.section as sec then {
      it -> sec.title = 'History' "historyTitle";
      it -> sec then AddSectionText(it, sec) "historyText";
    } "historyRule";
    qr.item as it where ((linkId = 'exam') and answer.value.exists()) -> comp.section as sec then {
      it -> sec.title = 'Examination' "examTitle";
      it -> sec then AddSectionText(it, sec) "examText";
    } "examRule";
    // The impression is both a section of the note and a Condition. It stays in
    // the document so the note reads whole, and it also lands on the problem
    // list so the rest of the stay can hang off it.
    qr.item as it where ((linkId = 'impression') and answer.value.exists()) -> comp.section as sec then {
      it -> sec.title = 'Impression' "impressionTitle";
      it -> sec then AddSectionText(it, sec) "impressionText";
    } "impressionSectionRule";
    qr.item as it where ((linkId = 'plan') and answer.value.exists()) -> comp.section as sec then {
      it -> sec.title = 'Initial plan' "planTitle";
      it -> sec then AddSectionText(it, sec) "planText";
    } "planRule";
  } "composition";
  qr.item as itImp where ((linkId = 'impression') and answer.value.exists()) then {
    itImp.answer first as aImp then {
      aImp ->  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 = 'provisional' "verCode";
            qr -> vsc.display = 'Provisional' "verDisplay";
          } "verCoding";
        } "verificationStatus";
        aImp.value as v -> cond.code as code then {
          v -> code.text = v "codeText";
        } "conditionCode";
      } "condition";
    } "impressionAnswer";
  } "impressionConditionRule";
}

// ─────────────────────────────────────────────────────────────────────────────
// 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";
}

// Everything a Condition extracted from one of these forms shares. The caller
// supplies verificationStatus and code, because those are the two things that
// differ between an admitting impression and a stated cause of death.
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";
}


Source1

{
  "resourceType": "StructureMap",
  "id": "ExtractInpatientAdmissionNote",
  "text": {
    "status": "generated",
    "div": "<!-- snip (see above) -->"
  },
  "url": "https://fhir.slade360.co.ke/fhir/StructureMap/ExtractInpatientAdmissionNote",
  "version": "0.1.0",
  "name": "ExtractInpatientAdmissionNote",
  "title": "Inpatient Admission 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 admission note into a Composition with one section per heading, plus a Condition for the impression -- the one line on this form that belongs on the problem list. The Condition is verificationStatus `provisional` because an admitting impression is exactly that; the team confirms or replaces it as the stay goes on. Its code carries the clinician's wording as text rather than an ICD-11 coding, because the form asks for prose and guessing a diagnosis code from prose is not something a map should do.",
  "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"
    }
  ],
  "group": [
    {
      "name": "ExtractInpatientAdmissionNote",
      "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": "InpatientAdmissionNote"
                    }
                  ]
                }
              ]
            },
            {
              "name": "noteTitle",
              "source": [
                {
                  "context": "qr"
                }
              ],
              "target": [
                {
                  "context": "comp",
                  "element": "title",
                  "transform": "copy",
                  "parameter": [
                    {
                      "valueString": "Admission 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": "admission-note"
                            }
                          ]
                        }
                      ]
                    },
                    {
                      "name": "sghiDisplay",
                      "source": [
                        {
                          "context": "qr"
                        }
                      ],
                      "target": [
                        {
                          "context": "sghi",
                          "element": "display",
                          "transform": "copy",
                          "parameter": [
                            {
                              "valueString": "Admission 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": "34117-2"
                            }
                          ]
                        }
                      ]
                    },
                    {
                      "name": "loincDisplay",
                      "source": [
                        {
                          "context": "qr"
                        }
                      ],
                      "target": [
                        {
                          "context": "loinc",
                          "element": "display",
                          "transform": "copy",
                          "parameter": [
                            {
                              "valueString": "History and physical note"
                            }
                          ]
                        }
                      ]
                    }
                  ]
                },
                {
                  "name": "typeText",
                  "source": [
                    {
                      "context": "qr"
                    }
                  ],
                  "target": [
                    {
                      "context": "ty",
                      "element": "text",
                      "transform": "copy",
                      "parameter": [
                        {
                          "valueString": "Admission note"
                        }
                      ]
                    }
                  ]
                }
              ]
            },
            {
              "name": "historyRule",
              "source": [
                {
                  "context": "qr",
                  "element": "item",
                  "variable": "it",
                  "condition": "(linkId = 'history') and answer.value.exists()"
                }
              ],
              "target": [
                {
                  "context": "comp",
                  "element": "section",
                  "variable": "sec"
                }
              ],
              "rule": [
                {
                  "name": "historyTitle",
                  "source": [
                    {
                      "context": "it"
                    }
                  ],
                  "target": [
                    {
                      "context": "sec",
                      "element": "title",
                      "transform": "copy",
                      "parameter": [
                        {
                          "valueString": "History"
                        }
                      ]
                    }
                  ]
                },
                {
                  "name": "historyText",
                  "source": [
                    {
                      "context": "it"
                    }
                  ],
                  "target": [
                    {
                      "context": "sec"
                    }
                  ],
                  "dependent": [
                    {
                      "name": "AddSectionText",
                      "parameter": [
                        {
                          "valueId": "it"
                        },
                        {
                          "valueId": "sec"
                        }
                      ]
                    }
                  ]
                }
              ]
            },
            {
              "name": "examRule",
              "source": [
                {
                  "context": "qr",
                  "element": "item",
                  "variable": "it",
                  "condition": "(linkId = 'exam') and answer.value.exists()"
                }
              ],
              "target": [
                {
                  "context": "comp",
                  "element": "section",
                  "variable": "sec"
                }
              ],
              "rule": [
                {
                  "name": "examTitle",
                  "source": [
                    {
                      "context": "it"
                    }
                  ],
                  "target": [
                    {
                      "context": "sec",
                      "element": "title",
                      "transform": "copy",
                      "parameter": [
                        {
                          "valueString": "Examination"
                        }
                      ]
                    }
                  ]
                },
                {
                  "name": "examText",
                  "source": [
                    {
                      "context": "it"
                    }
                  ],
                  "target": [
                    {
                      "context": "sec"
                    }
                  ],
                  "dependent": [
                    {
                      "name": "AddSectionText",
                      "parameter": [
                        {
                          "valueId": "it"
                        },
                        {
                          "valueId": "sec"
                        }
                      ]
                    }
                  ]
                }
              ]
            },
            {
              "name": "impressionSectionRule",
              "source": [
                {
                  "context": "qr",
                  "element": "item",
                  "variable": "it",
                  "condition": "(linkId = 'impression') and answer.value.exists()"
                }
              ],
              "target": [
                {
                  "context": "comp",
                  "element": "section",
                  "variable": "sec"
                }
              ],
              "rule": [
                {
                  "name": "impressionTitle",
                  "source": [
                    {
                      "context": "it"
                    }
                  ],
                  "target": [
                    {
                      "context": "sec",
                      "element": "title",
                      "transform": "copy",
                      "parameter": [
                        {
                          "valueString": "Impression"
                        }
                      ]
                    }
                  ]
                },
                {
                  "name": "impressionText",
                  "source": [
                    {
                      "context": "it"
                    }
                  ],
                  "target": [
                    {
                      "context": "sec"
                    }
                  ],
                  "dependent": [
                    {
                      "name": "AddSectionText",
                      "parameter": [
                        {
                          "valueId": "it"
                        },
                        {
                          "valueId": "sec"
                        }
                      ]
                    }
                  ]
                }
              ],
              "documentation": "The impression is both a section of the note and a Condition. It stays in\r\nthe document so the note reads whole, and it also lands on the problem\r\nlist so the rest of the stay can hang off it."
            },
            {
              "name": "planRule",
              "source": [
                {
                  "context": "qr",
                  "element": "item",
                  "variable": "it",
                  "condition": "(linkId = 'plan') and answer.value.exists()"
                }
              ],
              "target": [
                {
                  "context": "comp",
                  "element": "section",
                  "variable": "sec"
                }
              ],
              "rule": [
                {
                  "name": "planTitle",
                  "source": [
                    {
                      "context": "it"
                    }
                  ],
                  "target": [
                    {
                      "context": "sec",
                      "element": "title",
                      "transform": "copy",
                      "parameter": [
                        {
                          "valueString": "Initial plan"
                        }
                      ]
                    }
                  ]
                },
                {
                  "name": "planText",
                  "source": [
                    {
                      "context": "it"
                    }
                  ],
                  "target": [
                    {
                      "context": "sec"
                    }
                  ],
                  "dependent": [
                    {
                      "name": "AddSectionText",
                      "parameter": [
                        {
                          "valueId": "it"
                        },
                        {
                          "valueId": "sec"
                        }
                      ]
                    }
                  ]
                }
              ]
            }
          ]
        },
        {
          "name": "impressionConditionRule",
          "source": [
            {
              "context": "qr",
              "element": "item",
              "variable": "itImp",
              "condition": "(linkId = 'impression') and answer.value.exists()"
            }
          ],
          "rule": [
            {
              "name": "impressionAnswer",
              "source": [
                {
                  "context": "itImp",
                  "element": "answer",
                  "listMode": "first",
                  "variable": "aImp"
                }
              ],
              "rule": [
                {
                  "name": "condition",
                  "source": [
                    {
                      "context": "aImp"
                    }
                  ],
                  "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": "provisional"
                                    }
                                  ]
                                }
                              ]
                            },
                            {
                              "name": "verDisplay",
                              "source": [
                                {
                                  "context": "qr"
                                }
                              ],
                              "target": [
                                {
                                  "context": "vsc",
                                  "element": "display",
                                  "transform": "copy",
                                  "parameter": [
                                    {
                                      "valueString": "Provisional"
                                    }
                                  ]
                                }
                              ]
                            }
                          ]
                        }
                      ]
                    },
                    {
                      "name": "conditionCode",
                      "source": [
                        {
                          "context": "aImp",
                          "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": "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",
      "documentation": "Everything a Condition extracted from one of these forms shares. The caller\r\nsupplies verificationStatus and code, because those are the two things that\r\ndiffer between an admitting impression and a stated cause of death.",
      "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"
                }
              ]
            }
          ]
        }
      ]
    }
  ]
}