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

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

AppointmentTransformsR4SGHIR5

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

uses "http://hl7.org/fhir/4.0/StructureDefinition/Appointment" alias AppointmentR4 as source
uses "https://fhir.slade360.co.ke/fhir/StructureDefinition/sghi-appointment" alias SGHIAppointment as target

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

group SGHIAppointment(source src : AppointmentR4, target tgt : SGHIAppointment) <<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/sghi-appointment' "addsghiprofile";
  } "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/sghi-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/sghi-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.verificationStatus as sv -> tgt.verificationStatus as tv then {
    sv.coding as sc -> tv.coding as tc then TransformCoding(sc, tc);
    sv.text -> tv.text;
  };
  src where created.exists() then {
    src.created as sd -> tgt.created = sd;
  } "settingcreated";
  src where created.exists().not() then {
    src.start as sd -> tgt.created = sd;
  } "settingcreated";
  src.start -> tgt.start;
  src.end -> tgt.end;
  src where participant.exists().not() -> tgt.participant = create('BackboneElement') as tb then {
    src.patient as sp -> tb.actor = create('Reference') as trf then TransformReference(sp, trf);
  } "setting participant";
  src.participant as sp then {
    sp.actor as sa -> tgt.subject = create('Reference') as trf then TransformReference(sa, trf);
  };
  src.participant as sp -> tgt.participant as tp then {
    sp.actor as sa -> tp.actor as ta then TransformReference(sa, ta);
    sp.status -> tp.status;
    sp where status.exists().not() -> tp.status = 'needs-action' "settingparticipantstatus";
  };
  src where reasonCode.exists().not() -> tgt.reason = create('CodeableReference') as tcf then {
    src -> tcf.concept = create('Concept') as tcc then {
      src.reasonCode as sc then {
        sc.coding as scode -> tcc.coding = create('Coding') as tcoding then {
          scode.code as d -> tcoding.code = translate(d, 'https://fhir.slade360.co.ke/fhir/ConceptMap/CIELtoLOINCObservationMap', 'code');
          scode.code as d -> tcoding.system = translate(d, 'https://fhir.slade360.co.ke/fhir/ConceptMap/CIELtoLOINCObservationMap', 'system');
          scode.code as d -> tcoding.display = translate(d, 'https://fhir.slade360.co.ke/fhir/ConceptMap/CIELtoLOINCObservationMap', 'display');
          scode.code as d -> tcc.text = translate(d, 'https://fhir.slade360.co.ke/fhir/ConceptMap/CIELtoLOINCObservationMap', 'display');
        };
      };
    } "settingconcept";
  } "setting reason code";
  src -> tgt.reason = create('CodeableReference') as tcrf then {
    src.reasonCode as sc -> tcrf.concept = create('CodeableConcept') as tcc then {
      sc.coding as scode -> tcc.coding = create('Coding') as tcoding then {
        scode.code as d -> tcoding.code = translate(d, 'https://fhir.slade360.co.ke/fhir/ConceptMap/CIELtoLOINCObservationMap', 'code');
        scode.code as d -> tcoding.system = translate(d, 'https://fhir.slade360.co.ke/fhir/ConceptMap/CIELtoLOINCObservationMap', 'system');
        scode.code as d -> tcoding.display = translate(d, 'https://fhir.slade360.co.ke/fhir/ConceptMap/CIELtoLOINCObservationMap', 'display');
        scode.code as d -> tcc.text = translate(d, 'https://fhir.slade360.co.ke/fhir/ConceptMap/CIELtoLOINCObservationMap', 'display');
      };
    };
  } "settingappointmenttype";
  src.status -> tgt.status;
  src.specialty -> tgt.specialty;
  src where specialty.exists().not() then {
    src -> tgt.specialty = create('CodeableConcept') as tcc then {
      src ->  tcc.coding = create('Coding') as tc,  tc.system = 'https://fhir.slade360.co.ke/fhir/CodeSystem/sghi-specialtycodesystem',  tc.code = 'general-practitioner',  tc.display = 'General Practitioner' "setspecialtycoding";
    } "settingspeciality";
  } "settingdefaultspecialty";
  src -> tgt.priority = cc('http://terminology.hl7.org/CodeSystem/v3-ActPriority', 'R', 'routine') "setpriority";
  src.appointmentType -> tgt.appointmentType;
  src where appointmentType.exists().not() -> tgt.appointmentType = cc('http://terminology.hl7.org/CodeSystem/v2-0276', 'ROUTINE', 'Routine appointment - default if not valued') "setting appointment type";
}

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;
}