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

Official URL: https://fhir.slade360.co.ke/fhir/StructureMap/EpisodeOfCare4toSGHI5 Version: 0.1.0
Active as of 2025-09-17 Computable Name: EpisodeOfCare4toSGHI5

EpisodeOfCareTransformsR4SGHIR5

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

uses "http://hl7.org/fhir/4.0/StructureDefinition/EpisodeOfCare" alias EpisodeOfCareR4 as source
uses "https://fhir.slade360.co.ke/fhir/StructureDefinition/sghi-episodeofcare" alias SGHIEpisodeOfCare as target

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

group SGHIEpisodeOfCare(source src : EpisodeOfCareR4, target tgt : SGHIEpisodeOfCare) 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/sghi-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/sghi-identifier-codesystem' "creating system";
      src.managingOrganization 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.managingOrganization as smo -> tgt.managingOrganization = create('Reference') as tmo then {
    smo.reference -> tmo.reference;
    smo.display where display.exists() -> tmo.display;
    src.managingOrganization where display.exists().not() -> tmo.display = 'Organization';
    smo.display -> tmo.display;
  };
  src.status -> tgt.status;
  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/sghi-episodeofcare' "setprofileinmeta";
  } "set profile in meta";
  src.period -> tgt.period;
  src.patient -> tgt.patient;
  src where statusHistory.exists().not() -> tgt.statusHistory = create('BackboneElement') as th then {
    src -> th.status = 'planned' "set default status";
    src -> th.period = create('Period') as tp then {
      src.period as sp -> th.period as tp then TransformPeriod(sp, tp);
    } "copying status history period";
  } "creating status history";
}

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

group TransformPeriod(source src, target tgt) <<types>> {
  src.start -> tgt.start;
  src.end -> tgt.end;
}