SGHI FHIR Profile Implementation Guide
0.1.0 - ci-build

SGHI FHIR Profile Implementation Guide, published by Kathurima Kimathi. This guide is not an authorized publication; it is the continuous build for version 0.1.0 built by the FHIR (HL7® FHIR® Standard) CI Build. This version is based on the current content of https://github.com/savannahghi/sil_fhir_profile_ig/ and changes regularly. See the Directory of published versions

## StructureMap: Glasgow Coma Scale Extraction (Experimental)

Official URL: https://fhir.slade360.co.ke/fhir/StructureMap/GlasgowCommaScaleExtract | Version: 0.1.0
Active as of 2026-05-21 | Computable Name: GlasgowCommaScaleExtract

Extracts three Observation resources, one per GCS subscore, from a QuestionnaireResponse to the GCS questionnaire.

    /// url = 'https://fhir.slade360.co.ke/fhir/StructureMap/GlasgowCommaScaleExtract'
    /// name = 'GlasgowCommaScaleExtract'
    /// title = 'Glasgow Coma Scale Extraction'
    /// status = 'active'

    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 GlasgowCommaScaleExtract(source qr : QR, target bundle : Bundle) {
      qr -> bundle.type = 'transaction' "setBundleType";
      qr.item as itV where linkId = 'verbal-response' ->  bundle.entry as eV,  eV.resource = create('Observation') as oV then {
        qr -> oV.id then BuildBaseObs(qr, oV, eV) "baseV";
        qr -> oV.category = cc('http://terminology.hl7.org/CodeSystem/observation-category', 'survey', 'Survey') "catVSystem";
        qr -> oV.code = cc('http://loinc.org', '9270-0', 'Glasgow coma score verbal') "codeVCode";
        qr -> oV.id then SetValueFromItem(itV, oV) "valV";
      } "verbalResponseObs"; // Verbal
      qr.item as itM where linkId = 'motor-response' ->  bundle.entry as eM,  eM.resource = create('Observation') as oM then {
        qr -> oM.id then BuildBaseObs(qr, oM, eM) "baseM";
        qr -> oM.category = cc('http://terminology.hl7.org/CodeSystem/observation-category', 'survey', 'Survey') "catMSystem";
        qr -> oM.code = cc('http://loinc.org', '9268-4', 'Glasgow coma score motor') "catMCode";
        qr -> oM.id then SetValueFromItem(itM, oM) "valM";
      } "motorResponseObs"; // Motor
      qr.item as itE where linkId = 'eye-opening' ->  bundle.entry as eE,  eE.resource = create('Observation') as oE then {
        qr -> oE.id then BuildBaseObs(qr, oE, eE) "baseE";
        qr -> oE.category = cc('http://terminology.hl7.org/CodeSystem/observation-category', 'survey', 'Survey') "catESystem";
        qr -> oE.code = cc('http://loinc.org', '9267-6', 'Glasgow coma score eye opening') "catECode";
        qr -> oE.id then SetValueFromItem(itE, oE) "valE";
      } "eyeResponseObs"; // Eye
    }

    group BuildBaseObs(source qr : QR, target obs : Observation, target entry) {
      qr -> entry.request as req then {
        qr -> req.method = 'POST' "reqMethod";
        qr -> req.url = 'Observation' "reqUrl";
      } "entryRequest";
      qr -> obs.id = uuid() then SetFullUrl(obs, entry) "setIdAndFullUrl";
      qr -> obs.status = 'final' "setStatus";
      qr.subject as s -> obs.subject = create('Reference') as r then {
        s.reference as ref -> r.reference = ref "subRef";
        s.display as disp -> r.display = disp "subDisp";
      } "setSubject";
      qr.authored as t -> obs.effective = t "setEffective";
      qr.authored as t -> obs.issued = t "setIssued";
      qr -> obs.derivedFrom = create('Reference') as dr then {
        qr.id as id -> dr.reference = append('QuestionnaireResponse/', id) "derRef";
      } "setDerivedFrom";
    }

    group SetValueFromItem(source it : Element, target obs : Observation) {
      it.answer as a -> obs.value = create('CodeableConcept') as c then {
        a.value as coding -> c.coding = coding as nc "copyCoding";
      } "setValueCC";
    }

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