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: Encounter Transforms: R4 → SGHI R5

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

EncounterTransformsR4SGHIR5

    /// url = 'https://fhir.slade360.co.ke/fhir/StructureMap/Encounter4toSGHI5'
    /// name = 'Encounter4toSGHI5'
    /// title = 'Encounter Transforms: R4 → SGHI R5'
    /// status = 'active'

    uses "http://hl7.org/fhir/4.0/StructureDefinition/Encounter" alias EncounterR4 as source
    uses "https://fhir.slade360.co.ke/fhir/StructureDefinition/encounter" alias SGHIEncounter as target

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

    group SGHIEncounter(source src : EncounterR4, target tgt : SGHIEncounter) extends DomainResource <<type+>> {
      src.id -> tgt.id;
      src.active -> tgt.active = 'true';
      src.language -> tgt.language;
      src -> tgt.text = create('Narrative') as tgt_n then {
        src -> tgt_n.status = 'generated' "settextstatus";
        src -> tgt_n.div = '<div xmlns=\"http://www.w3.org/1999/xhtml\"><h1>Generated text</h1></div>' "settextdiv";
      } "createhardcodedtext";
      src as sc where identifier.exists().not() -> tgt.identifier = create('Identifier') as tt_id then {
        src.id as uuid -> tt_id.value = uuid "creating id";
        src -> tt_id.use = 'official' "creating use";
        src -> tt_id.type as ty then {
          src -> ty.coding = create('CodeableConcept') as ty_c then {
            src -> ty_c.system = 'https://fhir.slade360.co.ke/fhir/CodeSystem/identifier-codesystem' "creating coding";
            src -> ty_c.code = 'fhir-id' "creating code";
            src -> ty_c.display = 'FHIR Id' "creating display";
          } "creating identifier type";
          src -> tt_id.system = 'https://fhir.slade360.co.ke/fhir/CodeSystem/identifier-codesystem' "creating system";
          src.serviceProvider as sp -> tt_id.assigner = create('Reference') as t_assigner then {
            sp.reference -> t_assigner.reference;
            sp.display -> t_assigner.display;
          };
        } "creating identifier type";
      } "creating identifier"; // Create identifier
      src.episodeOfCare as se -> tgt.episodeOfCare = create('Reference') as te then {
        se.reference -> te.reference;
        se.id -> te.id;
        se.display where display.exists() -> te.display;
        src.episodeOfCare where display.exists().not() -> te.display = 'Encounter';
        se.display -> te.display;
      };
      src.status -> tgt.status;
      src where status = 'finished' then {
        src -> tgt.status = 'completed' "setting R5 status";
      } "setting R5 status in target";
      src -> tgt.class as t_c then {
        src.class as sc -> t_c.coding = create('CodeableConcept') as tt then TransformEncounterClass(sc, tt);
      } "translate coding to codeableconcept";
      src.serviceProvider -> tgt.serviceProvider;
      src.meta as s_meta -> tgt.meta as t_meta then {
        s_meta.lastUpdated -> t_meta.lastUpdated;
        s_meta.language -> t_meta.language;
        s_meta.tags -> t_meta.tags;
        src.meta where profile.exists().not() -> t_meta.profile = 'https://fhir.slade360.co.ke/fhir/StructureDefinition/encounter' "setprofileinmeta";
      } "set profile in meta";
      src.period -> tgt.actualPeriod;
      src.subject -> tgt.subject;
      src.episodeOfcare -> tgt.episodeOfcare;
      src.subject as sb -> tgt.participant as tb then {
        sb -> tb.actor = create('Reference') as ar then {
          sb.reference -> ar.reference;
          sb.display -> ar.display;
        } "set actor from subject";
      };
    }

    group TransformAssigner(source src, target tgt) <<types>> {
      src.reference -> tgt.reference;
      src.display -> tgt.display;
    }

    group TransformEncounterClass(source src, target tgt) <<types>> {
      src.code -> tgt.code;
      src.display -> tgt.display;
      src.system -> tgt.system;
      src.userSelected -> tgt.userSelected;
      src.version -> tgt.version;
    }