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

FHIR IG analytics

Packagesilfhirprofileig
Resource TypeStructureMap
IdStructureMap-ExtractDischargeClearanceClinicalReadiness.json
FHIR VersionR5
Sourcehttps://build.fhir.org/ig/savannahghi/sil_fhir_profile_ig/StructureMap-ExtractDischargeClearanceClinicalReadiness.html
URLhttps://fhir.slade360.co.ke/fhir/StructureMap/ExtractDischargeClearanceClinicalReadiness
Version0.1.0
Statusactive
Date2026-09-11T12:18:36+00:00
NameExtractDischargeClearanceClinicalReadiness
TitleDischarge Clearance: Clinical Readiness Extraction
DescriptionTurns the discharging clinician's readiness attestation into four survey Observations: oral intake, mobility, pain control and the condition the patient is leaving in. Each is its own Observation because a clinician answers four separate questions and one flat resource would let an answer to one stand in for an answer to another. The handover sentence rides as a note on the condition Observation rather than becoming a fifth: it is prose about the discharge, and an Observation whose value is a paragraph answers no query. Nothing here writes to the Encounter -- closing the stay and recording the discharge disposition belong to the EMR's discharge workflow, and the condition a patient leaves in is a different axis from where they went. The signature the form collects is a typed name, which SGHIObservation cannot carry as a performer, so it stays in the response and out of the extracted resources.

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 ExtractDischargeClearanceClinicalReadiness

/// url = 'https://fhir.slade360.co.ke/fhir/StructureMap/ExtractDischargeClearanceClinicalReadiness'
/// name = 'ExtractDischargeClearanceClinicalReadiness'
/// title = 'Discharge Clearance: Clinical Readiness Extraction'
/// status = 'active'
/// description = 'Turns the discharging clinician\'s readiness attestation into four survey Observations: oral intake, mobility, pain control and the condition the patient is leaving in. Each is its own Observation because a clinician answers four separate questions and one flat resource would let an answer to one stand in for an answer to another. The handover sentence rides as a note on the condition Observation rather than becoming a fifth: it is prose about the discharge, and an Observation whose value is a paragraph answers no query. Nothing here writes to the Encounter -- closing the stay and recording the discharge disposition belong to the EMR\'s discharge workflow, and the condition a patient leaves in is a different axis from where they went. The signature the form collects is a typed name, which SGHIObservation cannot carry as a performer, so it stays in the response and out of the extracted resources.'

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/Observation" alias Observation as target

group ExtractDischargeClearanceClinicalReadiness(source qr : QR, target bundle : Bundle) {
  qr -> bundle.type = 'transaction' "setBundleType";
  // linkId 301989955559 — "Oral intake tolerated"
  qr.item as it where ((linkId = '301989955559') and answer.value.exists()) then {
    it.answer first as a then {
      a ->  bundle.entry as entry,  entry.resource = create('Observation') as obs then {
        qr ->  obs,  entry then BuildClearanceObs(qr, obs, entry) "oralIntakeBase";
        qr -> obs.code as oralIntakeCodeCc then {
          qr -> oralIntakeCodeCc.coding as oralIntakeCodeCoding then {
            qr -> oralIntakeCodeCoding.system = 'https://fhir.slade360.co.ke/fhir/CodeSystem/inpatient-clinical-concept-codesystem' "oralIntakeCodeSystem";
            qr -> oralIntakeCodeCoding.code = 'oral-intake-at-discharge' "oralIntakeCodeCode";
            qr -> oralIntakeCodeCoding.display = 'Oral intake tolerated at discharge' "oralIntakeCodeDisplay";
          } "oralIntakeCodeCodingRule";
        } "oralIntakeCode";
        a -> obs then SetCodedValue(a, obs) "oralIntakeValue";
      } "oralIntakeObs";
    } "oralIntakeAnswer";
  } "oralIntakeRule";
  // linkId 507198101338 — "Mobility"
  qr.item as it where ((linkId = '507198101338') and answer.value.exists()) then {
    it.answer first as a then {
      a ->  bundle.entry as entry,  entry.resource = create('Observation') as obs then {
        qr ->  obs,  entry then BuildClearanceObs(qr, obs, entry) "mobilityBase";
        qr -> obs.code as mobilityCodeCc then {
          qr -> mobilityCodeCc.coding as mobilityCodeCoding then {
            qr -> mobilityCodeCoding.system = 'https://fhir.slade360.co.ke/fhir/CodeSystem/inpatient-clinical-concept-codesystem' "mobilityCodeSystem";
            qr -> mobilityCodeCoding.code = 'mobility-at-discharge' "mobilityCodeCode";
            qr -> mobilityCodeCoding.display = 'Mobility at discharge' "mobilityCodeDisplay";
          } "mobilityCodeCodingRule";
        } "mobilityCode";
        a -> obs then SetCodedValue(a, obs) "mobilityValue";
      } "mobilityObs";
    } "mobilityAnswer";
  } "mobilityRule";
  // linkId 852812667233 — "Pain controlled"
  qr.item as it where ((linkId = '852812667233') and answer.value.exists()) then {
    it.answer first as a then {
      a ->  bundle.entry as entry,  entry.resource = create('Observation') as obs then {
        qr ->  obs,  entry then BuildClearanceObs(qr, obs, entry) "painControlBase";
        qr -> obs.code as painControlCodeCc then {
          qr -> painControlCodeCc.coding as painControlCodeCoding then {
            qr -> painControlCodeCoding.system = 'https://fhir.slade360.co.ke/fhir/CodeSystem/inpatient-clinical-concept-codesystem' "painControlCodeSystem";
            qr -> painControlCodeCoding.code = 'pain-control-at-discharge' "painControlCodeCode";
            qr -> painControlCodeCoding.display = 'Pain control at discharge' "painControlCodeDisplay";
          } "painControlCodeCodingRule";
        } "painControlCode";
        a -> obs then SetCodedValue(a, obs) "painControlValue";
      } "painControlObs";
    } "painControlAnswer";
  } "painControlRule";
  // linkId 108099570999 — "Condition at discharge". This one carries the
  // free-text handover as a note, so it is the Observation a reader lands on
  // when they want the clinician's own words.
  qr.item as it where ((linkId = '108099570999') and answer.value.exists()) then {
    it.answer first as a then {
      a ->  bundle.entry as entry,  entry.resource = create('Observation') as obs then {
        qr ->  obs,  entry then BuildClearanceObs(qr, obs, entry) "conditionBase";
        qr -> obs.code as conditionCodeCc then {
          qr -> conditionCodeCc.coding as conditionCodeCoding then {
            qr -> conditionCodeCoding.system = 'https://fhir.slade360.co.ke/fhir/CodeSystem/inpatient-clinical-concept-codesystem' "conditionCodeSystem";
            qr -> conditionCodeCoding.code = 'patient-condition-at-discharge' "conditionCodeCode";
            qr -> conditionCodeCoding.display = 'Condition at discharge' "conditionCodeDisplay";
          } "conditionCodeCodingRule";
        } "conditionCode";
        a -> obs then SetCodedValue(a, obs) "conditionValue";
        // linkId 474741611141 — "Anything the next clinician should know"
        qr.item as itNote where ((linkId = '474741611141') and answer.value.exists()) then {
          itNote.answer first as aNote then {
            aNote.value as nv -> obs.note as note then {
              nv -> note.text = nv "handoverNoteText";
              qr.authored as t -> note.time = t "handoverNoteTime";
            } "handoverNote";
          } "handoverNoteAnswer";
        } "handoverNoteRule";
      } "conditionObs";
    } "conditionAnswer";
  } "conditionRule";
}

// ─────────────────────────────────────────────────────────────────────────────
// Shared scaffolding. Repeated in each clearance map rather than imported: the
// transform engine resolves `imports` against whatever StructureMaps happen to
// be on the server, and a clearance that stops extracting because a shared map
// was not uploaded is a worse failure than a duplicated group.
// Source parameters are left untyped on purpose. Writing `: Element` makes the
// publisher's StructureMap validator compare QuestionnaireResponse.item against
// the literal 'Element' and report them as incompatible, which is noise.
// ─────────────────────────────────────────────────────────────────────────────
group BuildClearanceObs(source qr : QR, target obs : Observation, target entry) {
  qr -> obs.id = uuid() then SetObservationFullUrl(obs, entry) "idAndFullUrl";
  qr -> entry.request as request then {
    qr -> request.method = 'POST' "requestMethod";
    qr -> request.url = 'Observation' "requestUrl";
  } "entryRequest";
  qr -> obs.status = 'final' "status";
  qr -> obs.category as categoryCc then {
    qr -> categoryCc.coding as categoryCoding then {
      qr -> categoryCoding.system = 'http://terminology.hl7.org/CodeSystem/observation-category' "categorySystem";
      qr -> categoryCoding.code = 'survey' "categoryCode";
      qr -> categoryCoding.display = 'Survey' "categoryDisplay";
    } "categoryCodingRule";
  } "category";
  qr.subject as s -> obs.subject = s;
  qr.encounter as e -> obs.encounter = e;
  // `effective`, not `effectiveInstant`: the R5 transform engine writes choice
  // elements by their base name and rejects the typed form.
  // Advantage stamps `authored` when the clearances are submitted, not when each
  // was signed, so a clearance signed at two in the morning and submitted at the
  // handover carries the handover time. Sending the signature time on the
  // response would fix it at the source; there is nothing on the response for a
  // map to read it from.
  qr.authored as t -> obs.effective = t "effective";
  qr.authored as t -> obs.issued = cast(t, 'instant') "issued";
  // The facility, not the person who signed: SGHIObservation admits only an
  // Organization or a Patient as performer, and the form's signature is a typed
  // name that resolves to neither.
  qr.source as src -> obs.performer = create('Reference') as perf then {
    src.reference as ref -> perf.reference = ref "performerRef";
    src.display as disp -> perf.display = disp "performerDisplay";
  } "performer";
  // One identifier per resource. Copying the response's own would give every
  // Observation from a single form the same business identity.
  qr -> obs.identifier as ident then {
    qr -> ident.use = 'official' "identifierUse";
    qr -> ident.type as identifierTypeCc then {
      qr -> identifierTypeCc.coding as identifierTypeCoding then {
        qr -> identifierTypeCoding.system = 'https://fhir.slade360.co.ke/fhir/CodeSystem/default-identifier-codesystem' "identifierTypeSystem";
        qr -> identifierTypeCoding.code = 'default-id' "identifierTypeCode";
        qr -> identifierTypeCoding.display = 'Default Resource Identifier' "identifierTypeDisplay";
      } "identifierTypeCodingRule";
    } "identifierType";
    qr -> ident.system = 'https://fhir.slade360.co.ke/fhir/CodeSystem/default-identifier-codesystem' "identifierSystem";
    qr -> ident.value = uuid() "identifierValue";
    qr.source as src -> ident.assigner = src "identifierAssigner";
  } "identifier";
  // No append: under this engine `qr.id` already resolves to the type-qualified
  // relative reference, so prefixing it again produces a reference to nothing.
  qr -> obs.derivedFrom = create('Reference') as ref then {
    qr.id as qid -> ref.reference = qid "derivedFromRef";
  } "linkQuestionnaireResponse";
}

group SetCodedValue(source a, target obs : Observation) {
  a.value as cv -> obs.value = create('CodeableConcept') as concept then {
    cv -> concept.coding = cv "valueCoding";
    cv.display as d -> concept.text = d "valueText";
  } "codedValue";
}

group SetObservationFullUrl(source obs : Observation, target entry) {
  obs.id as id -> entry.fullUrl = append('https://fhir.slade360.co.ke/fhir/Observation/', id) "assignFullUrl";
}


Source1

{
  "resourceType": "StructureMap",
  "id": "ExtractDischargeClearanceClinicalReadiness",
  "text": {
    "status": "generated",
    "div": "<!-- snip (see above) -->"
  },
  "url": "https://fhir.slade360.co.ke/fhir/StructureMap/ExtractDischargeClearanceClinicalReadiness",
  "version": "0.1.0",
  "name": "ExtractDischargeClearanceClinicalReadiness",
  "title": "Discharge Clearance: Clinical Readiness 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 the discharging clinician's readiness attestation into four survey Observations: oral intake, mobility, pain control and the condition the patient is leaving in. Each is its own Observation because a clinician answers four separate questions and one flat resource would let an answer to one stand in for an answer to another. The handover sentence rides as a note on the condition Observation rather than becoming a fifth: it is prose about the discharge, and an Observation whose value is a paragraph answers no query. Nothing here writes to the Encounter -- closing the stay and recording the discharge disposition belong to the EMR's discharge workflow, and the condition a patient leaves in is a different axis from where they went. The signature the form collects is a typed name, which SGHIObservation cannot carry as a performer, so it stays in the response and out of the extracted resources.",
  "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/Observation",
      "mode": "target",
      "alias": "Observation"
    }
  ],
  "group": [
    {
      "name": "ExtractDischargeClearanceClinicalReadiness",
      "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": "oralIntakeRule",
          "source": [
            {
              "context": "qr",
              "element": "item",
              "variable": "it",
              "condition": "(linkId = '301989955559') and answer.value.exists()"
            }
          ],
          "rule": [
            {
              "name": "oralIntakeAnswer",
              "source": [
                {
                  "context": "it",
                  "element": "answer",
                  "listMode": "first",
                  "variable": "a"
                }
              ],
              "rule": [
                {
                  "name": "oralIntakeObs",
                  "source": [
                    {
                      "context": "a"
                    }
                  ],
                  "target": [
                    {
                      "context": "bundle",
                      "element": "entry",
                      "variable": "entry"
                    },
                    {
                      "context": "entry",
                      "element": "resource",
                      "variable": "obs",
                      "transform": "create",
                      "parameter": [
                        {
                          "valueString": "Observation"
                        }
                      ]
                    }
                  ],
                  "rule": [
                    {
                      "name": "oralIntakeBase",
                      "source": [
                        {
                          "context": "qr"
                        }
                      ],
                      "target": [
                        {
                          "context": "obs"
                        },
                        {
                          "context": "entry"
                        }
                      ],
                      "dependent": [
                        {
                          "name": "BuildClearanceObs",
                          "parameter": [
                            {
                              "valueId": "qr"
                            },
                            {
                              "valueId": "obs"
                            },
                            {
                              "valueId": "entry"
                            }
                          ]
                        }
                      ]
                    },
                    {
                      "name": "oralIntakeCode",
                      "source": [
                        {
                          "context": "qr"
                        }
                      ],
                      "target": [
                        {
                          "context": "obs",
                          "element": "code",
                          "variable": "oralIntakeCodeCc"
                        }
                      ],
                      "rule": [
                        {
                          "name": "oralIntakeCodeCodingRule",
                          "source": [
                            {
                              "context": "qr"
                            }
                          ],
                          "target": [
                            {
                              "context": "oralIntakeCodeCc",
                              "element": "coding",
                              "variable": "oralIntakeCodeCoding"
                            }
                          ],
                          "rule": [
                            {
                              "name": "oralIntakeCodeSystem",
                              "source": [
                                {
                                  "context": "qr"
                                }
                              ],
                              "target": [
                                {
                                  "context": "oralIntakeCodeCoding",
                                  "element": "system",
                                  "transform": "copy",
                                  "parameter": [
                                    {
                                      "valueString": "https://fhir.slade360.co.ke/fhir/CodeSystem/inpatient-clinical-concept-codesystem"
                                    }
                                  ]
                                }
                              ]
                            },
                            {
                              "name": "oralIntakeCodeCode",
                              "source": [
                                {
                                  "context": "qr"
                                }
                              ],
                              "target": [
                                {
                                  "context": "oralIntakeCodeCoding",
                                  "element": "code",
                                  "transform": "copy",
                                  "parameter": [
                                    {
                                      "valueString": "oral-intake-at-discharge"
                                    }
                                  ]
                                }
                              ]
                            },
                            {
                              "name": "oralIntakeCodeDisplay",
                              "source": [
                                {
                                  "context": "qr"
                                }
                              ],
                              "target": [
                                {
                                  "context": "oralIntakeCodeCoding",
                                  "element": "display",
                                  "transform": "copy",
                                  "parameter": [
                                    {
                                      "valueString": "Oral intake tolerated at discharge"
                                    }
                                  ]
                                }
                              ]
                            }
                          ]
                        }
                      ]
                    },
                    {
                      "name": "oralIntakeValue",
                      "source": [
                        {
                          "context": "a"
                        }
                      ],
                      "target": [
                        {
                          "context": "obs"
                        }
                      ],
                      "dependent": [
                        {
                          "name": "SetCodedValue",
                          "parameter": [
                            {
                              "valueId": "a"
                            },
                            {
                              "valueId": "obs"
                            }
                          ]
                        }
                      ]
                    }
                  ]
                }
              ]
            }
          ],
          "documentation": "linkId 301989955559 — \"Oral intake tolerated\""
        },
        {
          "name": "mobilityRule",
          "source": [
            {
              "context": "qr",
              "element": "item",
              "variable": "it",
              "condition": "(linkId = '507198101338') and answer.value.exists()"
            }
          ],
          "rule": [
            {
              "name": "mobilityAnswer",
              "source": [
                {
                  "context": "it",
                  "element": "answer",
                  "listMode": "first",
                  "variable": "a"
                }
              ],
              "rule": [
                {
                  "name": "mobilityObs",
                  "source": [
                    {
                      "context": "a"
                    }
                  ],
                  "target": [
                    {
                      "context": "bundle",
                      "element": "entry",
                      "variable": "entry"
                    },
                    {
                      "context": "entry",
                      "element": "resource",
                      "variable": "obs",
                      "transform": "create",
                      "parameter": [
                        {
                          "valueString": "Observation"
                        }
                      ]
                    }
                  ],
                  "rule": [
                    {
                      "name": "mobilityBase",
                      "source": [
                        {
                          "context": "qr"
                        }
                      ],
                      "target": [
                        {
                          "context": "obs"
                        },
                        {
                          "context": "entry"
                        }
                      ],
                      "dependent": [
                        {
                          "name": "BuildClearanceObs",
                          "parameter": [
                            {
                              "valueId": "qr"
                            },
                            {
                              "valueId": "obs"
                            },
                            {
                              "valueId": "entry"
                            }
                          ]
                        }
                      ]
                    },
                    {
                      "name": "mobilityCode",
                      "source": [
                        {
                          "context": "qr"
                        }
                      ],
                      "target": [
                        {
                          "context": "obs",
                          "element": "code",
                          "variable": "mobilityCodeCc"
                        }
                      ],
                      "rule": [
                        {
                          "name": "mobilityCodeCodingRule",
                          "source": [
                            {
                              "context": "qr"
                            }
                          ],
                          "target": [
                            {
                              "context": "mobilityCodeCc",
                              "element": "coding",
                              "variable": "mobilityCodeCoding"
                            }
                          ],
                          "rule": [
                            {
                              "name": "mobilityCodeSystem",
                              "source": [
                                {
                                  "context": "qr"
                                }
                              ],
                              "target": [
                                {
                                  "context": "mobilityCodeCoding",
                                  "element": "system",
                                  "transform": "copy",
                                  "parameter": [
                                    {
                                      "valueString": "https://fhir.slade360.co.ke/fhir/CodeSystem/inpatient-clinical-concept-codesystem"
                                    }
                                  ]
                                }
                              ]
                            },
                            {
                              "name": "mobilityCodeCode",
                              "source": [
                                {
                                  "context": "qr"
                                }
                              ],
                              "target": [
                                {
                                  "context": "mobilityCodeCoding",
                                  "element": "code",
                                  "transform": "copy",
                                  "parameter": [
                                    {
                                      "valueString": "mobility-at-discharge"
                                    }
                                  ]
                                }
                              ]
                            },
                            {
                              "name": "mobilityCodeDisplay",
                              "source": [
                                {
                                  "context": "qr"
                                }
                              ],
                              "target": [
                                {
                                  "context": "mobilityCodeCoding",
                                  "element": "display",
                                  "transform": "copy",
                                  "parameter": [
                                    {
                                      "valueString": "Mobility at discharge"
                                    }
                                  ]
                                }
                              ]
                            }
                          ]
                        }
                      ]
                    },
                    {
                      "name": "mobilityValue",
                      "source": [
                        {
                          "context": "a"
                        }
                      ],
                      "target": [
                        {
                          "context": "obs"
                        }
                      ],
                      "dependent": [
                        {
                          "name": "SetCodedValue",
                          "parameter": [
                            {
                              "valueId": "a"
                            },
                            {
                              "valueId": "obs"
                            }
                          ]
                        }
                      ]
                    }
                  ]
                }
              ]
            }
          ],
          "documentation": "linkId 507198101338 — \"Mobility\""
        },
        {
          "name": "painControlRule",
          "source": [
            {
              "context": "qr",
              "element": "item",
              "variable": "it",
              "condition": "(linkId = '852812667233') and answer.value.exists()"
            }
          ],
          "rule": [
            {
              "name": "painControlAnswer",
              "source": [
                {
                  "context": "it",
                  "element": "answer",
                  "listMode": "first",
                  "variable": "a"
                }
              ],
              "rule": [
                {
                  "name": "painControlObs",
                  "source": [
                    {
                      "context": "a"
                    }
                  ],
                  "target": [
                    {
                      "context": "bundle",
                      "element": "entry",
                      "variable": "entry"
                    },
                    {
                      "context": "entry",
                      "element": "resource",
                      "variable": "obs",
                      "transform": "create",
                      "parameter": [
                        {
                          "valueString": "Observation"
                        }
                      ]
                    }
                  ],
                  "rule": [
                    {
                      "name": "painControlBase",
                      "source": [
                        {
                          "context": "qr"
                        }
                      ],
                      "target": [
                        {
                          "context": "obs"
                        },
                        {
                          "context": "entry"
                        }
                      ],
                      "dependent": [
                        {
                          "name": "BuildClearanceObs",
                          "parameter": [
                            {
                              "valueId": "qr"
                            },
                            {
                              "valueId": "obs"
                            },
                            {
                              "valueId": "entry"
                            }
                          ]
                        }
                      ]
                    },
                    {
                      "name": "painControlCode",
                      "source": [
                        {
                          "context": "qr"
                        }
                      ],
                      "target": [
                        {
                          "context": "obs",
                          "element": "code",
                          "variable": "painControlCodeCc"
                        }
                      ],
                      "rule": [
                        {
                          "name": "painControlCodeCodingRule",
                          "source": [
                            {
                              "context": "qr"
                            }
                          ],
                          "target": [
                            {
                              "context": "painControlCodeCc",
                              "element": "coding",
                              "variable": "painControlCodeCoding"
                            }
                          ],
                          "rule": [
                            {
                              "name": "painControlCodeSystem",
                              "source": [
                                {
                                  "context": "qr"
                                }
                              ],
                              "target": [
                                {
                                  "context": "painControlCodeCoding",
                                  "element": "system",
                                  "transform": "copy",
                                  "parameter": [
                                    {
                                      "valueString": "https://fhir.slade360.co.ke/fhir/CodeSystem/inpatient-clinical-concept-codesystem"
                                    }
                                  ]
                                }
                              ]
                            },
                            {
                              "name": "painControlCodeCode",
                              "source": [
                                {
                                  "context": "qr"
                                }
                              ],
                              "target": [
                                {
                                  "context": "painControlCodeCoding",
                                  "element": "code",
                                  "transform": "copy",
                                  "parameter": [
                                    {
                                      "valueString": "pain-control-at-discharge"
                                    }
                                  ]
                                }
                              ]
                            },
                            {
                              "name": "painControlCodeDisplay",
                              "source": [
                                {
                                  "context": "qr"
                                }
                              ],
                              "target": [
                                {
                                  "context": "painControlCodeCoding",
                                  "element": "display",
                                  "transform": "copy",
                                  "parameter": [
                                    {
                                      "valueString": "Pain control at discharge"
                                    }
                                  ]
                                }
                              ]
                            }
                          ]
                        }
                      ]
                    },
                    {
                      "name": "painControlValue",
                      "source": [
                        {
                          "context": "a"
                        }
                      ],
                      "target": [
                        {
                          "context": "obs"
                        }
                      ],
                      "dependent": [
                        {
                          "name": "SetCodedValue",
                          "parameter": [
                            {
                              "valueId": "a"
                            },
                            {
                              "valueId": "obs"
                            }
                          ]
                        }
                      ]
                    }
                  ]
                }
              ]
            }
          ],
          "documentation": "linkId 852812667233 — \"Pain controlled\""
        },
        {
          "name": "conditionRule",
          "source": [
            {
              "context": "qr",
              "element": "item",
              "variable": "it",
              "condition": "(linkId = '108099570999') and answer.value.exists()"
            }
          ],
          "rule": [
            {
              "name": "conditionAnswer",
              "source": [
                {
                  "context": "it",
                  "element": "answer",
                  "listMode": "first",
                  "variable": "a"
                }
              ],
              "rule": [
                {
                  "name": "conditionObs",
                  "source": [
                    {
                      "context": "a"
                    }
                  ],
                  "target": [
                    {
                      "context": "bundle",
                      "element": "entry",
                      "variable": "entry"
                    },
                    {
                      "context": "entry",
                      "element": "resource",
                      "variable": "obs",
                      "transform": "create",
                      "parameter": [
                        {
                          "valueString": "Observation"
                        }
                      ]
                    }
                  ],
                  "rule": [
                    {
                      "name": "conditionBase",
                      "source": [
                        {
                          "context": "qr"
                        }
                      ],
                      "target": [
                        {
                          "context": "obs"
                        },
                        {
                          "context": "entry"
                        }
                      ],
                      "dependent": [
                        {
                          "name": "BuildClearanceObs",
                          "parameter": [
                            {
                              "valueId": "qr"
                            },
                            {
                              "valueId": "obs"
                            },
                            {
                              "valueId": "entry"
                            }
                          ]
                        }
                      ]
                    },
                    {
                      "name": "conditionCode",
                      "source": [
                        {
                          "context": "qr"
                        }
                      ],
                      "target": [
                        {
                          "context": "obs",
                          "element": "code",
                          "variable": "conditionCodeCc"
                        }
                      ],
                      "rule": [
                        {
                          "name": "conditionCodeCodingRule",
                          "source": [
                            {
                              "context": "qr"
                            }
                          ],
                          "target": [
                            {
                              "context": "conditionCodeCc",
                              "element": "coding",
                              "variable": "conditionCodeCoding"
                            }
                          ],
                          "rule": [
                            {
                              "name": "conditionCodeSystem",
                              "source": [
                                {
                                  "context": "qr"
                                }
                              ],
                              "target": [
                                {
                                  "context": "conditionCodeCoding",
                                  "element": "system",
                                  "transform": "copy",
                                  "parameter": [
                                    {
                                      "valueString": "https://fhir.slade360.co.ke/fhir/CodeSystem/inpatient-clinical-concept-codesystem"
                                    }
                                  ]
                                }
                              ]
                            },
                            {
                              "name": "conditionCodeCode",
                              "source": [
                                {
                                  "context": "qr"
                                }
                              ],
                              "target": [
                                {
                                  "context": "conditionCodeCoding",
                                  "element": "code",
                                  "transform": "copy",
                                  "parameter": [
                                    {
                                      "valueString": "patient-condition-at-discharge"
                                    }
                                  ]
                                }
                              ]
                            },
                            {
                              "name": "conditionCodeDisplay",
                              "source": [
                                {
                                  "context": "qr"
                                }
                              ],
                              "target": [
                                {
                                  "context": "conditionCodeCoding",
                                  "element": "display",
                                  "transform": "copy",
                                  "parameter": [
                                    {
                                      "valueString": "Condition at discharge"
                                    }
                                  ]
                                }
                              ]
                            }
                          ]
                        }
                      ]
                    },
                    {
                      "name": "conditionValue",
                      "source": [
                        {
                          "context": "a"
                        }
                      ],
                      "target": [
                        {
                          "context": "obs"
                        }
                      ],
                      "dependent": [
                        {
                          "name": "SetCodedValue",
                          "parameter": [
                            {
                              "valueId": "a"
                            },
                            {
                              "valueId": "obs"
                            }
                          ]
                        }
                      ]
                    },
                    {
                      "name": "handoverNoteRule",
                      "source": [
                        {
                          "context": "qr",
                          "element": "item",
                          "variable": "itNote",
                          "condition": "(linkId = '474741611141') and answer.value.exists()"
                        }
                      ],
                      "rule": [
                        {
                          "name": "handoverNoteAnswer",
                          "source": [
                            {
                              "context": "itNote",
                              "element": "answer",
                              "listMode": "first",
                              "variable": "aNote"
                            }
                          ],
                          "rule": [
                            {
                              "name": "handoverNote",
                              "source": [
                                {
                                  "context": "aNote",
                                  "element": "value",
                                  "variable": "nv"
                                }
                              ],
                              "target": [
                                {
                                  "context": "obs",
                                  "element": "note",
                                  "variable": "note"
                                }
                              ],
                              "rule": [
                                {
                                  "name": "handoverNoteText",
                                  "source": [
                                    {
                                      "context": "nv"
                                    }
                                  ],
                                  "target": [
                                    {
                                      "context": "note",
                                      "element": "text",
                                      "transform": "copy",
                                      "parameter": [
                                        {
                                          "valueId": "nv"
                                        }
                                      ]
                                    }
                                  ]
                                },
                                {
                                  "name": "handoverNoteTime",
                                  "source": [
                                    {
                                      "context": "qr",
                                      "element": "authored",
                                      "variable": "t"
                                    }
                                  ],
                                  "target": [
                                    {
                                      "context": "note",
                                      "element": "time",
                                      "transform": "copy",
                                      "parameter": [
                                        {
                                          "valueId": "t"
                                        }
                                      ]
                                    }
                                  ]
                                }
                              ]
                            }
                          ]
                        }
                      ],
                      "documentation": "linkId 474741611141 — \"Anything the next clinician should know\""
                    }
                  ]
                }
              ]
            }
          ],
          "documentation": "linkId 108099570999 — \"Condition at discharge\". This one carries the\r\nfree-text handover as a note, so it is the Observation a reader lands on\r\nwhen they want the clinician's own words."
        }
      ]
    },
    {
      "name": "BuildClearanceObs",
      "documentation": "─────────────────────────────────────────────────────────────────────────────\r\nShared scaffolding. Repeated in each clearance map rather than imported: the\r\ntransform engine resolves `imports` against whatever StructureMaps happen to\r\nbe on the server, and a clearance that stops extracting because a shared map\r\nwas not uploaded is a worse failure than a duplicated group.\r\nSource parameters are left untyped on purpose. Writing `: Element` makes the\r\npublisher's StructureMap validator compare QuestionnaireResponse.item against\r\nthe literal 'Element' and report them as incompatible, which is noise.\r\n─────────────────────────────────────────────────────────────────────────────",
      "input": [
        {
          "name": "qr",
          "type": "QR",
          "mode": "source"
        },
        {
          "name": "obs",
          "type": "Observation",
          "mode": "target"
        },
        {
          "name": "entry",
          "mode": "target"
        }
      ],
      "rule": [
        {
          "name": "idAndFullUrl",
          "source": [
            {
              "context": "qr"
            }
          ],
          "target": [
            {
              "context": "obs",
              "element": "id",
              "transform": "uuid"
            }
          ],
          "dependent": [
            {
              "name": "SetObservationFullUrl",
              "parameter": [
                {
                  "valueId": "obs"
                },
                {
                  "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": "Observation"
                    }
                  ]
                }
              ]
            }
          ]
        },
        {
          "name": "status",
          "source": [
            {
              "context": "qr"
            }
          ],
          "target": [
            {
              "context": "obs",
              "element": "status",
              "transform": "copy",
              "parameter": [
                {
                  "valueString": "final"
                }
              ]
            }
          ]
        },
        {
          "name": "category",
          "source": [
            {
              "context": "qr"
            }
          ],
          "target": [
            {
              "context": "obs",
              "element": "category",
              "variable": "categoryCc"
            }
          ],
          "rule": [
            {
              "name": "categoryCodingRule",
              "source": [
                {
                  "context": "qr"
                }
              ],
              "target": [
                {
                  "context": "categoryCc",
                  "element": "coding",
                  "variable": "categoryCoding"
                }
              ],
              "rule": [
                {
                  "name": "categorySystem",
                  "source": [
                    {
                      "context": "qr"
                    }
                  ],
                  "target": [
                    {
                      "context": "categoryCoding",
                      "element": "system",
                      "transform": "copy",
                      "parameter": [
                        {
                          "valueString": "http://terminology.hl7.org/CodeSystem/observation-category"
                        }
                      ]
                    }
                  ]
                },
                {
                  "name": "categoryCode",
                  "source": [
                    {
                      "context": "qr"
                    }
                  ],
                  "target": [
                    {
                      "context": "categoryCoding",
                      "element": "code",
                      "transform": "copy",
                      "parameter": [
                        {
                          "valueString": "survey"
                        }
                      ]
                    }
                  ]
                },
                {
                  "name": "categoryDisplay",
                  "source": [
                    {
                      "context": "qr"
                    }
                  ],
                  "target": [
                    {
                      "context": "categoryCoding",
                      "element": "display",
                      "transform": "copy",
                      "parameter": [
                        {
                          "valueString": "Survey"
                        }
                      ]
                    }
                  ]
                }
              ]
            }
          ]
        },
        {
          "name": "subject",
          "source": [
            {
              "context": "qr",
              "element": "subject",
              "variable": "s"
            }
          ],
          "target": [
            {
              "context": "obs",
              "element": "subject",
              "transform": "copy",
              "parameter": [
                {
                  "valueId": "s"
                }
              ]
            }
          ]
        },
        {
          "name": "encounter",
          "source": [
            {
              "context": "qr",
              "element": "encounter",
              "variable": "e"
            }
          ],
          "target": [
            {
              "context": "obs",
              "element": "encounter",
              "transform": "copy",
              "parameter": [
                {
                  "valueId": "e"
                }
              ]
            }
          ]
        },
        {
          "name": "effective",
          "source": [
            {
              "context": "qr",
              "element": "authored",
              "variable": "t"
            }
          ],
          "target": [
            {
              "context": "obs",
              "element": "effective",
              "transform": "copy",
              "parameter": [
                {
                  "valueId": "t"
                }
              ]
            }
          ],
          "documentation": "`effective`, not `effectiveInstant`: the R5 transform engine writes choice\r\nelements by their base name and rejects the typed form.\r\nAdvantage stamps `authored` when the clearances are submitted, not when each\r\nwas signed, so a clearance signed at two in the morning and submitted at the\r\nhandover carries the handover time. Sending the signature time on the\r\nresponse would fix it at the source; there is nothing on the response for a\r\nmap to read it from."
        },
        {
          "name": "issued",
          "source": [
            {
              "context": "qr",
              "element": "authored",
              "variable": "t"
            }
          ],
          "target": [
            {
              "context": "obs",
              "element": "issued",
              "transform": "cast",
              "parameter": [
                {
                  "valueId": "t"
                },
                {
                  "valueString": "instant"
                }
              ]
            }
          ]
        },
        {
          "name": "performer",
          "source": [
            {
              "context": "qr",
              "element": "source",
              "variable": "src"
            }
          ],
          "target": [
            {
              "context": "obs",
              "element": "performer",
              "variable": "perf",
              "transform": "create",
              "parameter": [
                {
                  "valueString": "Reference"
                }
              ]
            }
          ],
          "rule": [
            {
              "name": "performerRef",
              "source": [
                {
                  "context": "src",
                  "element": "reference",
                  "variable": "ref"
                }
              ],
              "target": [
                {
                  "context": "perf",
                  "element": "reference",
                  "transform": "copy",
                  "parameter": [
                    {
                      "valueId": "ref"
                    }
                  ]
                }
              ]
            },
            {
              "name": "performerDisplay",
              "source": [
                {
                  "context": "src",
                  "element": "display",
                  "variable": "disp"
                }
              ],
              "target": [
                {
                  "context": "perf",
                  "element": "display",
                  "transform": "copy",
                  "parameter": [
                    {
                      "valueId": "disp"
                    }
                  ]
                }
              ]
            }
          ],
          "documentation": "The facility, not the person who signed: SGHIObservation admits only an\r\nOrganization or a Patient as performer, and the form's signature is a typed\r\nname that resolves to neither."
        },
        {
          "name": "identifier",
          "source": [
            {
              "context": "qr"
            }
          ],
          "target": [
            {
              "context": "obs",
              "element": "identifier",
              "variable": "ident"
            }
          ],
          "rule": [
            {
              "name": "identifierUse",
              "source": [
                {
                  "context": "qr"
                }
              ],
              "target": [
                {
                  "context": "ident",
                  "element": "use",
                  "transform": "copy",
                  "parameter": [
                    {
                      "valueString": "official"
                    }
                  ]
                }
              ]
            },
            {
              "name": "identifierType",
              "source": [
                {
                  "context": "qr"
                }
              ],
              "target": [
                {
                  "context": "ident",
                  "element": "type",
                  "variable": "identifierTypeCc"
                }
              ],
              "rule": [
                {
                  "name": "identifierTypeCodingRule",
                  "source": [
                    {
                      "context": "qr"
                    }
                  ],
                  "target": [
                    {
                      "context": "identifierTypeCc",
                      "element": "coding",
                      "variable": "identifierTypeCoding"
                    }
                  ],
                  "rule": [
                    {
                      "name": "identifierTypeSystem",
                      "source": [
                        {
                          "context": "qr"
                        }
                      ],
                      "target": [
                        {
                          "context": "identifierTypeCoding",
                          "element": "system",
                          "transform": "copy",
                          "parameter": [
                            {
                              "valueString": "https://fhir.slade360.co.ke/fhir/CodeSystem/default-identifier-codesystem"
                            }
                          ]
                        }
                      ]
                    },
                    {
                      "name": "identifierTypeCode",
                      "source": [
                        {
                          "context": "qr"
                        }
                      ],
                      "target": [
                        {
                          "context": "identifierTypeCoding",
                          "element": "code",
                          "transform": "copy",
                          "parameter": [
                            {
                              "valueString": "default-id"
                            }
                          ]
                        }
                      ]
                    },
                    {
                      "name": "identifierTypeDisplay",
                      "source": [
                        {
                          "context": "qr"
                        }
                      ],
                      "target": [
                        {
                          "context": "identifierTypeCoding",
                          "element": "display",
                          "transform": "copy",
                          "parameter": [
                            {
                              "valueString": "Default Resource Identifier"
                            }
                          ]
                        }
                      ]
                    }
                  ]
                }
              ]
            },
            {
              "name": "identifierSystem",
              "source": [
                {
                  "context": "qr"
                }
              ],
              "target": [
                {
                  "context": "ident",
                  "element": "system",
                  "transform": "copy",
                  "parameter": [
                    {
                      "valueString": "https://fhir.slade360.co.ke/fhir/CodeSystem/default-identifier-codesystem"
                    }
                  ]
                }
              ]
            },
            {
              "name": "identifierValue",
              "source": [
                {
                  "context": "qr"
                }
              ],
              "target": [
                {
                  "context": "ident",
                  "element": "value",
                  "transform": "uuid"
                }
              ]
            },
            {
              "name": "identifierAssigner",
              "source": [
                {
                  "context": "qr",
                  "element": "source",
                  "variable": "src"
                }
              ],
              "target": [
                {
                  "context": "ident",
                  "element": "assigner",
                  "transform": "copy",
                  "parameter": [
                    {
                      "valueId": "src"
                    }
                  ]
                }
              ]
            }
          ],
          "documentation": "One identifier per resource. Copying the response's own would give every\r\nObservation from a single form the same business identity."
        },
        {
          "name": "linkQuestionnaireResponse",
          "source": [
            {
              "context": "qr"
            }
          ],
          "target": [
            {
              "context": "obs",
              "element": "derivedFrom",
              "variable": "ref",
              "transform": "create",
              "parameter": [
                {
                  "valueString": "Reference"
                }
              ]
            }
          ],
          "rule": [
            {
              "name": "derivedFromRef",
              "source": [
                {
                  "context": "qr",
                  "element": "id",
                  "variable": "qid"
                }
              ],
              "target": [
                {
                  "context": "ref",
                  "element": "reference",
                  "transform": "copy",
                  "parameter": [
                    {
                      "valueId": "qid"
                    }
                  ]
                }
              ]
            }
          ],
          "documentation": "No append: under this engine `qr.id` already resolves to the type-qualified\r\nrelative reference, so prefixing it again produces a reference to nothing."
        }
      ]
    },
    {
      "name": "SetCodedValue",
      "input": [
        {
          "name": "a",
          "mode": "source"
        },
        {
          "name": "obs",
          "type": "Observation",
          "mode": "target"
        }
      ],
      "rule": [
        {
          "name": "codedValue",
          "source": [
            {
              "context": "a",
              "element": "value",
              "variable": "cv"
            }
          ],
          "target": [
            {
              "context": "obs",
              "element": "value",
              "variable": "concept",
              "transform": "create",
              "parameter": [
                {
                  "valueString": "CodeableConcept"
                }
              ]
            }
          ],
          "rule": [
            {
              "name": "valueCoding",
              "source": [
                {
                  "context": "cv"
                }
              ],
              "target": [
                {
                  "context": "concept",
                  "element": "coding",
                  "transform": "copy",
                  "parameter": [
                    {
                      "valueId": "cv"
                    }
                  ]
                }
              ]
            },
            {
              "name": "valueText",
              "source": [
                {
                  "context": "cv",
                  "element": "display",
                  "variable": "d"
                }
              ],
              "target": [
                {
                  "context": "concept",
                  "element": "text",
                  "transform": "copy",
                  "parameter": [
                    {
                      "valueId": "d"
                    }
                  ]
                }
              ]
            }
          ]
        }
      ]
    },
    {
      "name": "SetObservationFullUrl",
      "input": [
        {
          "name": "obs",
          "type": "Observation",
          "mode": "source"
        },
        {
          "name": "entry",
          "mode": "target"
        }
      ],
      "rule": [
        {
          "name": "assignFullUrl",
          "source": [
            {
              "context": "obs",
              "element": "id",
              "variable": "id"
            }
          ],
          "target": [
            {
              "context": "entry",
              "element": "fullUrl",
              "transform": "append",
              "parameter": [
                {
                  "valueString": "https://fhir.slade360.co.ke/fhir/Observation/"
                },
                {
                  "valueId": "id"
                }
              ]
            }
          ]
        }
      ]
    }
  ]
}