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: Composition Transforms: R4 to SGHI R5

Official URL: https://fhir.slade360.co.ke/fhir/StructureMap/Composition4toSGHI5 | Version: 0.1.0
Active as of 2026-04-27 | Computable Name: Composition4toSGHI5

CompositionTransformsR4toSGHIR5

    /// url = 'https://fhir.slade360.co.ke/fhir/StructureMap/Composition4toSGHI5'
    /// name = 'Composition4toSGHI5'
    /// title = 'Composition Transforms: R4 to SGHI R5'
    /// status = 'active'

    uses "http://hl7.org/fhir/4.0/StructureDefinition/Composition" alias CompositionR4 as source
    uses "https://fhir.slade360.co.ke/fhir/StructureDefinition/composition" alias SGHIComposition as target

    imports "http://hl7.org/fhir/StructureMap/*4to5"

    group SGHIComposition(source src : CompositionR4, target tgt : SGHIComposition) <<type+>> {
      src.id as uuid -> tgt.id = uuid;
      src.active -> tgt.active;
      src.language -> tgt.language;
      src -> tgt.meta as t_meta then {
        src -> t_meta.profile = 'https://fhir.slade360.co.ke/fhir/StructureDefinition/composition' "addprofile";
      } "addtometa";
      src where text.exists().not() -> tgt.text = create('Narrative') as t_text then {
        src -> t_text.status = 'generated' "settextstatus";
        src -> t_text.div = '<div xmlns=\"http://www.w3.org/1999/xhtml\"><h1>Generated text</h1></div>' "settextdiv";
      } "createhardcodedtext";
      src -> tgt.text = create('Narrative') as ttt then {
        src.text as st then {
          st.status as s -> ttt.status = s;
          st.div as d -> ttt.div = ('<div xmlns=\"http://www.w3.org/1999/xhtml\"><p>' + d + '</p></div>') "wraptextinhtml";
        };
      } "setting text";
      src.id as s_id -> tgt.identifier = create('Identifier') as t_ident then {
        s_id as uuid -> t_ident.value = uuid "copyid";
        src -> t_ident.use = 'official' "setuse";
        src -> t_ident.system = 'https://fhir.slade360.co.ke/fhir/CodeSystem/identifier-codesystem' "setsystem";
        src -> t_ident.type = create('CodeableConcept') as t_type then {
          src -> t_type.coding = create('Coding') as t_code then {
            src -> t_code.system = 'https://fhir.slade360.co.ke/fhir/CodeSystem/identifier-codesystem' "typesystem";
            src -> t_code.code = 'fhir-id' "typecode";
            src -> t_code.display = 'FHIR Id' "typedisplay";
          } "initcoding";
        } "inittype";
        src.meta as sm then {
          sm.tag last as st -> t_ident.assigner = create('Reference') as ta then TransformAssigner(st, ta);
        } "setting owner";
      } "addfhirididentifier";
      src.status -> tgt.status;
      src.type as stype -> tgt.type as ttype then {
        stype.coding as scoding -> ttype.coding as tcoding then TransformCoding(scoding, tcoding);
        stype.text -> ttype.text;
      };
      src.category as sg -> tgt.category as tg then {
        sg.coding as sc -> tg.coding as tc then TransformCoding(sc, tc);
        sg.text -> tg.text;
      };
      src.author as sat -> tgt.author as tat then TransformReference(sat, tat);
      src.subject as sb -> tgt.subject as tb then TransformReference(sb, tb);
      src.encounter as se -> tgt.encounter as te then TransformReference(se, te);
      src.title -> tgt.name;
      src.title -> tgt.title;
      src.date -> tgt.date;
      src.section as sct -> tgt.section as tct then {
        sct.author as sa -> tct.author as ta then TransformReference(sa, ta);
        sct.code as scc -> tct.code = create('CodeableConcept') as tcc then {
          scc.coding as sc -> tcc.coding as tc then TransformCoding(sc, tc);
        };
        sct.text as sdiv -> tct.text as tdiv then {
          sdiv.status -> tdiv.status;
          sdiv.id -> tdiv.id;
          sdiv.div as div -> tdiv.div = ('<div xmlns=\"http://www.w3.org/1999/xhtml\"><p>' + div + '</p></div>');
        };
        sct.title -> tct.title;
      };
    }

    group TransformAssigner(source src, target tgt) <<types>> {
      src.code as code -> tgt.reference = append('Organization/', code);
      src where display.exists().not() -> tgt.display = 'Unknown display' "setting default display";
      src.display -> tgt.display;
      src.code -> tgt.id;
    }

    group TransformReference(source src, target tgt) <<types>> {
      src.id -> tgt.id;
      src.reference -> tgt.reference;
      src.display -> tgt.display;
      src where display.exists().not() -> tgt.display = 'Unknown display' "setting display";
    }

    group TransformCoding(source src, target tgt) <<types>> {
      src.code -> tgt.code;
      src.display -> tgt.display;
      src where display.exists().not() -> tgt.display = 'Unknown display' "settingdefaultdisplay";
      src.system -> tgt.system = 'http://loinc.org';
    }