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

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

MedicationRequestTransformsR4SGHIR5

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

uses "http://hl7.org/fhir/4.0/StructureDefinition/MedicationRequest" alias MedicationRequestR4 as source
uses "https://fhir.slade360.co.ke/fhir/StructureDefinition/sghi-medicationrequest" alias SGHIMedicationRequest as target

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

group SGHIMedicationRequest(source src : MedicationRequestR4, target tgt : SGHIMedicationRequest) <<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-medicationrequest' "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.status -> tgt.status;
  src.intent -> tgt.intent;
  src.priority -> tgt.priority;
  src.authoredOn -> tgt.authoredOn;
  src.medication as sm -> tgt.medication = create('CodeableReference') as tm then {
    src where reference.exists().not() -> tm.reference = create('Reference') as trf then {
      sm.text -> trf.display;
      sm.text as txt -> trf.reference = append('Medication/', txt) "dummy reference";
    } "set reference";
  };
  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.requester as sr -> tgt.requester as tr then TransformReference(sr, tr);
  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.note as sn -> tgt.note as tn then {
    sn.time -> tn.time;
    sn.text -> tn.text;
  };
  src.dosageInstruction as sd -> tgt.dosageInstruction as td then {
    sd.asNeeded -> td.asNeeded;
    sd.doseAndRate as sd -> td.doseAndRate as td then {
      sd.doseQuantity as sq -> td.doseQuantity as tq then {
        sq.code -> tq.code;
        sq.system -> tq.system;
        sq.unit -> tq.unit;
        sq.value -> tq.value;
      };
    };
    sd.patientInstruction -> td.patientInstruction;
    sd.route as sr -> td.route as tr then {
      sr.coding as sc -> tr.coding as tc then TransformCoding(sc, tc);
      sr where coding.exists().not() ->  tr.coding = create('Coding') as tc,  tc.system = 'https://fhir.slade360.co.ke/fhir/CodeSystem/sghi-identifier-codesystem',  tc.code = 'iv',  tc.display = 'Intravenous' "setting default route";
      sr.text -> tr.text;
    };
    sd.timing as st -> td.timing as tt then {
      st.repeat as sp -> tt.repeat as tp then {
        sp.boundsPeriod as sprd -> tp.boundsPeriod as tprd then {
          sprd.end -> tprd.end;
          sprd.start -> tprd.start;
        };
        sp.duration -> tp.duration;
        sp.durationUnit -> tp.durationUnit;
        sp.frequency -> tp.frequency;
        sp.period -> tp.period;
        sp.periodUnit -> tp.periodUnit;
      };
    };
  };
}

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