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

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

ServiceRequestTransformsR4SGHIR5

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

    uses "http://hl7.org/fhir/4.0/StructureDefinition/ServiceRequest" alias ServiceRequestR4 as source
    uses "https://fhir.slade360.co.ke/fhir/StructureDefinition/servicerequest" alias SGHIServiceRequest as target

    group SGHIServiceRequest(source src : ServiceRequestR4, target tgt : SGHIServiceRequest) <<type+>> {
      src.id as uuid -> tgt.id = uuid;
      src.active -> tgt.active = 'true';
      src.language as sl -> tgt.language = sl;
      src.authoredOn as sa -> tgt.authoredOn = sa;
      src where text.exists().not() -> 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 -> 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"; // Create identifier
      src.meta as s_meta -> tgt.meta as t_meta then {
        s_meta.lastUpdated as sl -> t_meta.lastUpdated = sl;
        s_meta.language as sl -> t_meta.language = sl;
        s_meta.tags as st -> t_meta.tags = st;
        src.meta as sp where profile.exists().not() -> t_meta.profile = 'https://fhir.slade360.co.ke/fhir/StructureDefinition/servicerequest' "setprofileinmeta";
      } "set profile in meta";
      src where status != 'finished' then {
        src.status as sd -> tgt.status = sd;
      } "coppying status";
      src where status = 'finished' -> tgt.status = 'completed' "settingR5status";
      src.dateTime as sd -> tgt.date = sd;
      src.basedOn as sb -> tgt.basedOn as tb then TransformReference(sb, tb);
      src.category as scat -> tgt.category as tcat then {
        scat.coding as d where d.system.exists().not() -> tcat.coding = translate(d, 'https://fhir.slade360.co.ke/fhir/ConceptMap/CIELtoFHIRCategoryCodeBindingsMap', 'Coding');
        scat.coding as d where d.system.exists() -> tcat.coding = create('Coding') as tcoding then {
          d.code as d -> tcoding.code = translate(d, 'https://fhir.slade360.co.ke/fhir/ConceptMap/CIELtoFHIRCategoryCodeBindingsMap', 'code');
          d.code as d -> tcoding.system = translate(d, 'https://fhir.slade360.co.ke/fhir/ConceptMap/CIELtoFHIRCategoryCodeBindingsMap', 'system');
          d.code as d -> tcoding.display = translate(d, 'https://fhir.slade360.co.ke/fhir/ConceptMap/CIELtoFHIRCategoryCodeBindingsMap', 'display');
          d.code as d -> tcat.text = translate(d, 'https://fhir.slade360.co.ke/fhir/ConceptMap/CIELtoFHIRCategoryCodeBindingsMap', 'display');
        };
      };
      src.encounter as se -> tgt.encounter as te then TransformReference(se, te);
      src.requester as sr -> tgt.requester as tr then TransformReference(sr, tr);
      src.subject as sbb -> tgt.subject as tbb then TransformReference(sbb, tbb);
      src.performer as sp -> tgt.performer as tp then TransformReference(sp, tp);
      src where performer.exists().not() then {
        src.meta as sm then {
          sm.tag last as sp -> tgt.performer = create('Reference') as tp then TransformAssigner(sp, tp);
        } "setting performer";
      } "settingperformer";
      src where requester.exists().not() then {
        src.meta as sm then {
          sm.tag last as sr -> tgt.requester = create('Reference') as tr then TransformAssigner(sr, tr);
        } "setting requester";
      } "settingrequester";
      src.priority as sp -> tgt.priority = sp;
      src.intent as sti -> tgt.intent = sti;
      src -> tgt.code = create('CodeableReference') as trf then {
        src.code as scc -> trf.concept = create('CodeableConcept') as tcc then TranslateCoding(scc, tcc);
      } "translate codeableConcept to CodeableReference in R5";
      src -> tgt.reason = create('CodeableReference') as tr then {
        src.code as scc -> tr.concept = create('CodeableConcept') as tcc then TranslateCoding(scc, tcc);
      } "setting reason";
    }

    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 as d -> tgt.display = d;
      src.code as dc -> tgt.id = dc;
    }

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

    group TranslateCoding(source scc, target tcc) <<types>> {
      scc.coding as d where d.system.exists().not() -> tcc.coding = translate(d, 'https://fhir.slade360.co.ke/fhir/ConceptMap/CIELtoLOINCServiceRequestMap', 'Coding');
      scc.coding as scode where (scode.code = '1271').exists() and (scode.display = 'Pap smear/cytology') -> tcc.coding as tcode then {
        scode -> tcode.code = 'LA16047-5' "override code";
        scode.display as d -> tcode.display = d;
        scode -> tcode.system = 'http://loinc.org' "overriedsystem";
      };
      scc.coding as scode where (scode.code = '1271').exists() and (scode.display = 'HPV') -> tcc.coding as tcode then {
        scode -> tcode.code = 'LP14836-8' "override code";
        scode -> tcode.display = 'Human papilloma virus' "settinghpvdisplay";
        scode -> tcode.system = 'http://loinc.org' "overriedsystem";
      };
      scc.coding as scode where (scode.code = '1271').exists() and (scode.display = 'Mammogram') -> tcc.coding as tcode then {
        scode -> tcode.code = 'LA16046-7' "override code";
        scode.display as d -> tcode.display = d;
        scode -> tcode.system = 'http://loinc.org' "overriedsystem";
      };
      scc.coding as scode where (scode.code = '1271').exists() and (scode.display = 'VIA') -> tcc.coding as tcode then {
        scode -> tcode.code = 'LP404404-8' "override code";
        scode -> tcode.display = 'Screening techniques | Cervix or Vagina | Cytology' "settingdisplay";
        scode -> tcode.system = 'http://loinc.org' "overriedsystem";
      };
      scc.coding as scode where (scode.code = '1271').exists() and (scode.display = 'Biopsy') -> tcc.coding as tcode then {
        scode -> tcode.code = 'LA15393-4' "override code";
        scode -> tcode.display = 'Biopsy' "settingdisplay";
        scode -> tcode.system = 'http://loinc.org' "overriedsystem";
      };
      scc.coding as scode where (scode.code = '1271').exists() and (scode.display = 'Ultrasound') -> tcc.coding as tcode then {
        scode -> tcode.code = '24630-6' "override code";
        scode -> tcode.display = 'US Chest' "settingdisplay";
        scode -> tcode.system = 'http://loinc.org' "overriedsystem";
      };
      scc.coding as scode where (scode.code = '1271').exists() and (scode.display = 'MRI') -> tcc.coding as tcode then {
        scode -> tcode.code = '30794-2' "override code";
        scode -> tcode.display = 'MR Breast' "settingdisplay";
        scode -> tcode.system = 'http://loinc.org' "overriedsystem";
      };
      scc.coding as scode where (scode.code = '1271').exists() and (scode.display = 'Prostate Specific Antigen - Serum') -> tcc.coding as tcode then {
        scode -> tcode.code = '32465-7' "override code";
        scode -> tcode.display = 'Physical findings of Prostate' "settingdisplay";
        scode -> tcode.system = 'http://loinc.org' "overriedsystem";
      };
      scc.coding as scode where (scode.code = '1271').exists() and (scode.display = 'Prostate Specific Antigen - Whole Blood') -> tcc.coding as tcode then {
        scode -> tcode.code = 'LP15247-7' "override code";
        scode -> tcode.display = 'Whole Blood' "settingdisplay";
        scode -> tcode.system = 'http://loinc.org' "overriedsystem";
      };
      scc.coding as d where d.system.exists() -> tcc.coding = create('Coding') as tcoding then {
        d.code as d -> tcoding.code = translate(d, 'https://fhir.slade360.co.ke/fhir/ConceptMap/CIELtoLOINCServiceRequestMap', 'code');
        d.code as d -> tcoding.system = translate(d, 'https://fhir.slade360.co.ke/fhir/ConceptMap/CIELtoLOINCServiceRequestMap', 'system');
        d.code as d -> tcoding.display = translate(d, 'https://fhir.slade360.co.ke/fhir/ConceptMap/CIELtoLOINCServiceRequestMap', 'display');
        d.code as d -> tcoding.text = translate(d, 'https://fhir.slade360.co.ke/fhir/ConceptMap/CIELtoLOINCServiceRequestMap', 'display');
      };
    }