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
| Official URL: https://fhir.slade360.co.ke/fhir/StructureMap/ExtractSurgicalSafetyChecklist | Version: 0.1.0 | |||
| Active as of 2026-09-14 | Computable Name: ExtractSurgicalSafetyChecklist | |||
The checklist out as one Observation per WHO phase, so a sign-out that never happened is a missing resource rather than a resource full of blanks – which is the only shape that lets a compliance audit tell an unperformed phase from an unticked one. The ward's pre-operative preparation and post-operative checks become two further panels, every investigation ticked becomes a ServiceRequest, the vital signs before and after theatre become their own Observations tagged with which side of theatre they were taken on, and the instrument count gets an Observation of its own because a wrong count is a never event.
/// url = 'https://fhir.slade360.co.ke/fhir/StructureMap/ExtractSurgicalSafetyChecklist' /// name = 'ExtractSurgicalSafetyChecklist' /// title = 'Surgical Safety Checklist Extraction' /// status = 'active' /// description = 'The checklist out as one Observation per WHO phase, so a sign-out that never happened is a missing resource rather than a resource full of blanks -- which is the only shape that lets a compliance audit tell an unperformed phase from an unticked one. The ward\'s pre-operative preparation and post-operative checks become two further panels, every investigation ticked becomes a ServiceRequest, the vital signs before and after theatre become their own Observations tagged with which side of theatre they were taken on, and the instrument count gets an Observation of its own because a wrong count is a never event.' uses "http://hl7.org/fhir/StructureDefinition/QuestionnaireResponse" alias QR as source uses "http://hl7.org/fhir/StructureDefinition/Bundle" alias Bundle as target uses "http://hl7.org/fhir/StructureDefinition/Observation" alias Observation as target uses "http://hl7.org/fhir/StructureDefinition/ServiceRequest" alias ServiceRequest as target group ExtractSurgicalSafetyChecklist(source qr : QR, target bundle : Bundle) { qr -> bundle.type = 'transaction' "setBundleType"; // ── The three WHO phases ──────────────────────────────────────────────── // One Observation each. This is the whole design decision on this form: a // single Observation with twenty-two components could not distinguish "the // team did the sign-out and confirmed nothing" from "the team never did the // sign-out", and those are a documentation lapse and a safety failure // respectively. // Each phase is guarded on at least one of its own items being answered, and // carries `Observation.effective` from the phase's own completion time when // the team recorded one, so the interval between induction and incision is // recoverable. qr.item as wg where (linkId = 'who-checklist') then { wg.item as g where ((linkId = 'who-checklist/sign-in') and item.answer.value.exists()) -> bundle.entry as entry, entry.resource = create('Observation') as obs then { qr -> obs, entry then BuildObsBase(qr, obs, entry) "base"; qr -> obs then SetSurveyCategory(qr, obs) "category"; g -> obs.code as cc then { g -> cc.coding as cg then { g -> cg.system = 'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem' "sys"; g -> cg.code = 'surgical-safety-phase' "cd"; g -> cg.display = 'Surgical safety checklist phase' "dsp"; } "coding"; g -> cc.text = 'Sign in — before induction of anaesthesia' "codeText"; } "code"; g -> obs.value = create('CodeableConcept') as vc then { g -> vc.coding as vcg then { g -> vcg.system = 'https://fhir.slade360.co.ke/fhir/CodeSystem/answer-codesystem' "sys"; g -> vcg.code = 'phase-sign-in' "cd"; g -> vcg.display = 'Sign in — before induction of anaesthesia' "dsp"; } "coding"; } "phaseValue"; // The phase's own completion time, not the form's authored time. g.item as ct where ((linkId = 'who-checklist/sign-in/completed-at') and answer.value.exists()) then { ct.answer first as a then { a.value as t -> obs.effective = t "phaseEffective"; }; } "phaseTime"; g.item as it where ((linkId = 'who-checklist/sign-in/identity-site-procedure-consent') and answer.value.exists()) -> obs.component as comp then { it -> comp.code as cc then { it -> cc.coding as cg then { it -> cg.system = 'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem' "sys"; it -> cg.code = 'who-check-patient-confirmed-identity-site-procedure-and' "cd"; it -> cg.display = 'Patient confirmed identity, site, procedure and consent' "dsp"; } "coding"; } "code"; it -> comp then SetComponentCodedValue(it, comp) "value"; } "comp_who_check_patient_confirmed_identity_site_procedure_and"; g.item as it where ((linkId = 'who-checklist/sign-in/site-marked') and answer.value.exists()) -> obs.component as comp then { it -> comp.code as cc then { it -> cc.coding as cg then { it -> cg.system = 'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem' "sys"; it -> cg.code = 'who-check-site-marked' "cd"; it -> cg.display = 'Site marked' "dsp"; } "coding"; } "code"; it -> comp then SetComponentCodedValue(it, comp) "value"; } "comp_who_check_site_marked"; g.item as it where ((linkId = 'who-checklist/sign-in/anaesthesia-machine-and-medication-check') and answer.value.exists()) -> obs.component as comp then { it -> comp.code as cc then { it -> cc.coding as cg then { it -> cg.system = 'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem' "sys"; it -> cg.code = 'who-check-anaesthesia-machine-and-medication-check-complete' "cd"; it -> cg.display = 'Anaesthesia machine and medication check complete' "dsp"; } "coding"; } "code"; it -> comp then SetComponentCodedValue(it, comp) "value"; } "comp_who_check_anaesthesia_machine_and_medication_check_complete"; g.item as it where ((linkId = 'who-checklist/sign-in/pulse-oximeter-on-and-functioning') and answer.value.exists()) -> obs.component as comp then { it -> comp.code as cc then { it -> cc.coding as cg then { it -> cg.system = 'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem' "sys"; it -> cg.code = 'who-check-pulse-oximeter-on-the-patient-and-functioning' "cd"; it -> cg.display = 'Pulse oximeter on the patient and functioning' "dsp"; } "coding"; } "code"; it -> comp then SetComponentCodedValue(it, comp) "value"; } "comp_who_check_pulse_oximeter_on_the_patient_and_functioning"; g.item as it where ((linkId = 'who-checklist/sign-in/known-allergy-reviewed') and answer.value.exists()) -> obs.component as comp then { it -> comp.code as cc then { it -> cc.coding as cg then { it -> cg.system = 'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem' "sys"; it -> cg.code = 'who-check-known-allergy-reviewed' "cd"; it -> cg.display = 'Known allergy reviewed' "dsp"; } "coding"; } "code"; it -> comp then SetComponentCodedValue(it, comp) "value"; } "comp_who_check_known_allergy_reviewed"; g.item as it where ((linkId = 'who-checklist/sign-in/difficult-airway-or-aspiration-risk') and answer.value.exists()) -> obs.component as comp then { it -> comp.code as cc then { it -> cc.coding as cg then { it -> cg.system = 'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem' "sys"; it -> cg.code = 'who-check-difficult-airway-or-aspiration-risk-assessed' "cd"; it -> cg.display = 'Difficult airway or aspiration risk assessed' "dsp"; } "coding"; } "code"; it -> comp then SetComponentCodedValue(it, comp) "value"; } "comp_who_check_difficult_airway_or_aspiration_risk_assessed"; g.item as it where ((linkId = 'who-checklist/sign-in/blood-loss-risk-over-500ml') and answer.value.exists()) -> obs.component as comp then { it -> comp.code as cc then { it -> cc.coding as cg then { it -> cg.system = 'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem' "sys"; it -> cg.code = 'who-check-risk-of-over-500-ml-blood-loss-assessed-access-and' "cd"; it -> cg.display = 'Risk of over 500 ml blood loss assessed, access and fluids planned' "dsp"; } "coding"; } "code"; it -> comp then SetComponentCodedValue(it, comp) "value"; } "comp_who_check_risk_of_over_500_ml_blood_loss_assessed_access_and"; } "phase_sign_in"; wg.item as g where ((linkId = 'who-checklist/time-out') and item.answer.value.exists()) -> bundle.entry as entry, entry.resource = create('Observation') as obs then { qr -> obs, entry then BuildObsBase(qr, obs, entry) "base"; qr -> obs then SetSurveyCategory(qr, obs) "category"; g -> obs.code as cc then { g -> cc.coding as cg then { g -> cg.system = 'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem' "sys"; g -> cg.code = 'surgical-safety-phase' "cd"; g -> cg.display = 'Surgical safety checklist phase' "dsp"; } "coding"; g -> cc.text = 'Time out — before skin incision' "codeText"; } "code"; g -> obs.value = create('CodeableConcept') as vc then { g -> vc.coding as vcg then { g -> vcg.system = 'https://fhir.slade360.co.ke/fhir/CodeSystem/answer-codesystem' "sys"; g -> vcg.code = 'phase-time-out' "cd"; g -> vcg.display = 'Time out — before skin incision' "dsp"; } "coding"; } "phaseValue"; // The phase's own completion time, not the form's authored time. g.item as ct where ((linkId = 'who-checklist/time-out/completed-at') and answer.value.exists()) then { ct.answer first as a then { a.value as t -> obs.effective = t "phaseEffective"; }; } "phaseTime2"; g.item as it where ((linkId = 'who-checklist/time-out/team-introductions') and answer.value.exists()) -> obs.component as comp then { it -> comp.code as cc then { it -> cc.coding as cg then { it -> cg.system = 'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem' "sys"; it -> cg.code = 'who-check-all-team-members-introduced-by-name-and-role' "cd"; it -> cg.display = 'All team members introduced by name and role' "dsp"; } "coding"; } "code"; it -> comp then SetComponentCodedValue(it, comp) "value"; } "comp_who_check_all_team_members_introduced_by_name_and_role"; g.item as it where ((linkId = 'who-checklist/time-out/confirm-patient-procedure-incision') and answer.value.exists()) -> obs.component as comp then { it -> comp.code as cc then { it -> cc.coding as cg then { it -> cg.system = 'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem' "sys"; it -> cg.code = 'who-check-patient-procedure-and-incision-site-confirmed' "cd"; it -> cg.display = 'Patient, procedure and incision site confirmed' "dsp"; } "coding"; } "code"; it -> comp then SetComponentCodedValue(it, comp) "value"; } "comp_who_check_patient_procedure_and_incision_site_confirmed"; g.item as it where ((linkId = 'who-checklist/time-out/antibiotic-prophylaxis-within-60-minutes') and answer.value.exists()) -> obs.component as comp then { it -> comp.code as cc then { it -> cc.coding as cg then { it -> cg.system = 'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem' "sys"; it -> cg.code = 'who-check-antibiotic-prophylaxis-given-within-the-last-60' "cd"; it -> cg.display = 'Antibiotic prophylaxis given within the last 60 minutes' "dsp"; } "coding"; } "code"; it -> comp then SetComponentCodedValue(it, comp) "value"; } "comp_who_check_antibiotic_prophylaxis_given_within_the_last_60"; g.item as it where ((linkId = 'who-checklist/time-out/critical-steps-reviewed') and answer.value.exists()) -> obs.component as comp then { it -> comp.code as cc then { it -> cc.coding as cg then { it -> cg.system = 'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem' "sys"; it -> cg.code = 'who-check-critical-or-non-routine-steps-reviewed' "cd"; it -> cg.display = 'Critical or non-routine steps reviewed' "dsp"; } "coding"; } "code"; it -> comp then SetComponentCodedValue(it, comp) "value"; } "comp_who_check_critical_or_non_routine_steps_reviewed"; g.item as it where ((linkId = 'who-checklist/time-out/case-duration-reviewed') and answer.value.exists()) -> obs.component as comp then { it -> comp.code as cc then { it -> cc.coding as cg then { it -> cg.system = 'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem' "sys"; it -> cg.code = 'who-check-case-duration-reviewed' "cd"; it -> cg.display = 'Case duration reviewed' "dsp"; } "coding"; } "code"; it -> comp then SetComponentCodedValue(it, comp) "value"; } "comp_who_check_case_duration_reviewed"; g.item as it where ((linkId = 'who-checklist/time-out/anticipated-blood-loss-reviewed') and answer.value.exists()) -> obs.component as comp then { it -> comp.code as cc then { it -> cc.coding as cg then { it -> cg.system = 'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem' "sys"; it -> cg.code = 'who-check-anticipated-blood-loss-reviewed' "cd"; it -> cg.display = 'Anticipated blood loss reviewed' "dsp"; } "coding"; } "code"; it -> comp then SetComponentCodedValue(it, comp) "value"; } "comp_who_check_anticipated_blood_loss_reviewed"; g.item as it where ((linkId = 'who-checklist/time-out/anaesthetist-patient-specific-concerns') and answer.value.exists()) -> obs.component as comp then { it -> comp.code as cc then { it -> cc.coding as cg then { it -> cg.system = 'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem' "sys"; it -> cg.code = 'who-check-anaesthetist-s-patient-specific-concerns-reviewed' "cd"; it -> cg.display = 'Anaesthetist\'s patient-specific concerns reviewed' "dsp"; } "coding"; } "code"; it -> comp then SetComponentCodedValue(it, comp) "value"; } "comp_who_check_anaesthetist_s_patient_specific_concerns_reviewed"; g.item as it where ((linkId = 'who-checklist/time-out/sterility-confirmed') and answer.value.exists()) -> obs.component as comp then { it -> comp.code as cc then { it -> cc.coding as cg then { it -> cg.system = 'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem' "sys"; it -> cg.code = 'who-check-sterility-including-indicator-results-confirmed' "cd"; it -> cg.display = 'Sterility, including indicator results, confirmed' "dsp"; } "coding"; } "code"; it -> comp then SetComponentCodedValue(it, comp) "value"; } "comp_who_check_sterility_including_indicator_results_confirmed"; g.item as it where ((linkId = 'who-checklist/time-out/equipment-issues-reviewed') and answer.value.exists()) -> obs.component as comp then { it -> comp.code as cc then { it -> cc.coding as cg then { it -> cg.system = 'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem' "sys"; it -> cg.code = 'who-check-equipment-issues-or-concerns-reviewed' "cd"; it -> cg.display = 'Equipment issues or concerns reviewed' "dsp"; } "coding"; } "code"; it -> comp then SetComponentCodedValue(it, comp) "value"; } "comp_who_check_equipment_issues_or_concerns_reviewed"; g.item as it where ((linkId = 'who-checklist/time-out/essential-imaging-displayed') and answer.value.exists()) -> obs.component as comp then { it -> comp.code as cc then { it -> cc.coding as cg then { it -> cg.system = 'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem' "sys"; it -> cg.code = 'who-check-essential-imaging-displayed' "cd"; it -> cg.display = 'Essential imaging displayed' "dsp"; } "coding"; } "code"; it -> comp then SetComponentCodedValue(it, comp) "value"; } "comp_who_check_essential_imaging_displayed"; } "phase_time_out"; wg.item as g where ((linkId = 'who-checklist/sign-out') and item.answer.value.exists()) -> bundle.entry as entry, entry.resource = create('Observation') as obs then { qr -> obs, entry then BuildObsBase(qr, obs, entry) "base"; qr -> obs then SetSurveyCategory(qr, obs) "category"; g -> obs.code as cc then { g -> cc.coding as cg then { g -> cg.system = 'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem' "sys"; g -> cg.code = 'surgical-safety-phase' "cd"; g -> cg.display = 'Surgical safety checklist phase' "dsp"; } "coding"; g -> cc.text = 'Sign out — before the patient leaves the operating room' "codeText"; } "code"; g -> obs.value = create('CodeableConcept') as vc then { g -> vc.coding as vcg then { g -> vcg.system = 'https://fhir.slade360.co.ke/fhir/CodeSystem/answer-codesystem' "sys"; g -> vcg.code = 'phase-sign-out' "cd"; g -> vcg.display = 'Sign out — before the patient leaves the operating room' "dsp"; } "coding"; } "phaseValue"; // The phase's own completion time, not the form's authored time. g.item as ct where ((linkId = 'who-checklist/sign-out/completed-at') and answer.value.exists()) then { ct.answer first as a then { a.value as t -> obs.effective = t "phaseEffective"; }; } "phaseTime3"; g.item as it where ((linkId = 'who-checklist/sign-out/procedure-name-recorded') and answer.value.exists()) -> obs.component as comp then { it -> comp.code as cc then { it -> cc.coding as cg then { it -> cg.system = 'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem' "sys"; it -> cg.code = 'who-check-name-of-the-procedure-verbally-confirmed' "cd"; it -> cg.display = 'Name of the procedure verbally confirmed' "dsp"; } "coding"; } "code"; it -> comp then SetComponentCodedValue(it, comp) "value"; } "comp_who_check_name_of_the_procedure_verbally_confirmed"; g.item as it where ((linkId = 'who-checklist/sign-out/counts-complete') and answer.value.exists()) -> obs.component as comp then { it -> comp.code as cc then { it -> cc.coding as cg then { it -> cg.system = 'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem' "sys"; it -> cg.code = 'who-check-instrument-sponge-and-needle-counts-complete' "cd"; it -> cg.display = 'Instrument, sponge and needle counts complete' "dsp"; } "coding"; } "code"; it -> comp then SetComponentCodedValue(it, comp) "value"; } "comp_who_check_instrument_sponge_and_needle_counts_complete"; g.item as it where ((linkId = 'who-checklist/sign-out/specimen-labelling') and answer.value.exists()) -> obs.component as comp then { it -> comp.code as cc then { it -> cc.coding as cg then { it -> cg.system = 'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem' "sys"; it -> cg.code = 'who-check-specimen-labelling-read-aloud-including-the-patient' "cd"; it -> cg.display = 'Specimen labelling read aloud, including the patient name' "dsp"; } "coding"; } "code"; it -> comp then SetComponentCodedValue(it, comp) "value"; } "comp_who_check_specimen_labelling_read_aloud_including_the_patient"; g.item as it where ((linkId = 'who-checklist/sign-out/equipment-problems-addressed') and answer.value.exists()) -> obs.component as comp then { it -> comp.code as cc then { it -> cc.coding as cg then { it -> cg.system = 'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem' "sys"; it -> cg.code = 'who-check-equipment-problems-to-be-addressed-identified' "cd"; it -> cg.display = 'Equipment problems to be addressed identified' "dsp"; } "coding"; } "code"; it -> comp then SetComponentCodedValue(it, comp) "value"; } "comp_who_check_equipment_problems_to_be_addressed_identified"; g.item as it where ((linkId = 'who-checklist/sign-out/recovery-key-concerns') and answer.value.exists()) -> obs.component as comp then { it -> comp.code as cc then { it -> cc.coding as cg then { it -> cg.system = 'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem' "sys"; it -> cg.code = 'who-check-key-concerns-for-recovery-and-management-reviewed' "cd"; it -> cg.display = 'Key concerns for recovery and management reviewed' "dsp"; } "coding"; } "code"; it -> comp then SetComponentCodedValue(it, comp) "value"; } "comp_who_check_key_concerns_for_recovery_and_management_reviewed"; } "phase_sign_out"; } "whoChecklistGroup"; // ── The instrument, sponge and needle count ───────────────────────────── // Lifted out of the sign-out panel into an Observation of its own. An // incorrect count is a never event and a retained item is a serious incident; // a fact that triggers an incident report has to be findable by its own code // and not only by reading a twenty-two-component panel. qr.item as wg where (linkId = 'who-checklist') then { wg.item as g where (linkId = 'who-checklist/sign-out') then { g.item as it where ((linkId = 'who-checklist/sign-out/counts-complete') and answer.value.exists()) -> bundle.entry as entry, entry.resource = create('Observation') as obs then { qr -> obs, entry then BuildObsBase(qr, obs, entry) "base"; qr -> obs then SetSurveyCategory(qr, obs) "category"; it -> obs.code as cc then { it -> cc.coding as cg then { it -> cg.system = 'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem' "sys"; it -> cg.code = 'instrument-count-complete' "cd"; it -> cg.display = 'Instrument, sponge and needle count complete' "dsp"; } "coding"; } "code"; it.answer first as a then { a.value as cv -> obs.value = create('CodeableConcept') as vc then { cv -> vc.coding = cv "valueCoding"; cv.display as d -> vc.text = d "valueText"; } "codedValue"; }; // Anything other than a confirmed count is abnormal. Stated, not left // to a reader: this is the flag a theatre audit filters on. it.answer first as a then { a.value as cv where (code != 'check-confirmed') -> obs.interpretation as interp then { cv -> interp.coding as icg then { cv -> icg.system = 'http://terminology.hl7.org/CodeSystem/v3-ObservationInterpretation' "sys"; cv -> icg.code = 'A' "cd"; cv -> icg.display = 'Abnormal' "dsp"; } "coding"; } "abnormal"; } "countInterpretation"; } "instrumentCountObservation"; } "signOutSub"; } "instrumentCountGroup"; // ── The ward's pre-operative preparation ──────────────────────────────── qr.item as pg where (linkId = 'pre-operative') then { pg.item as g where ((linkId = 'pre-operative/preparation') and item.answer.value.exists()) -> bundle.entry as entry, entry.resource = create('Observation') as obs then { qr -> obs, entry then BuildObsBase(qr, obs, entry) "base"; qr -> obs then SetSurveyCategory(qr, obs) "category"; g -> obs.code as cc then { g -> cc.coding as cg then { g -> cg.system = 'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem' "sys"; g -> cg.code = 'preoperative-preparation' "cd"; g -> cg.display = 'Pre-operative preparation completed' "dsp"; } "coding"; } "code"; g.item as it where ((linkId = 'pre-operative/preparation/fasting') and answer.value.exists()) -> obs.component as comp then { it -> comp.code as cc then { it -> cc.coding as cg then { it -> cg.system = 'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem' "sys"; it -> cg.code = 'preop-fasting' "cd"; it -> cg.display = 'Fasting' "dsp"; } "coding"; } "code"; it -> comp then SetComponentCodedValue(it, comp) "value"; } "comp_preop_fasting"; g.item as it where ((linkId = 'pre-operative/preparation/dentures-removed') and answer.value.exists()) -> obs.component as comp then { it -> comp.code as cc then { it -> cc.coding as cg then { it -> cg.system = 'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem' "sys"; it -> cg.code = 'preop-dentures-removed' "cd"; it -> cg.display = 'Dentures removed' "dsp"; } "coding"; } "code"; it -> comp then SetComponentCodedValue(it, comp) "value"; } "comp_preop_dentures_removed"; g.item as it where ((linkId = 'pre-operative/preparation/jewellery-removed') and answer.value.exists()) -> obs.component as comp then { it -> comp.code as cc then { it -> cc.coding as cg then { it -> cg.system = 'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem' "sys"; it -> cg.code = 'preop-jewellery-removed' "cd"; it -> cg.display = 'Jewellery removed' "dsp"; } "coding"; } "code"; it -> comp then SetComponentCodedValue(it, comp) "value"; } "comp_preop_jewellery_removed"; g.item as it where ((linkId = 'pre-operative/preparation/artificial-limb-removed') and answer.value.exists()) -> obs.component as comp then { it -> comp.code as cc then { it -> cc.coding as cg then { it -> cg.system = 'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem' "sys"; it -> cg.code = 'preop-artificial-limb-removed' "cd"; it -> cg.display = 'Artificial limb removed' "dsp"; } "coding"; } "code"; it -> comp then SetComponentCodedValue(it, comp) "value"; } "comp_preop_artificial_limb_removed"; g.item as it where ((linkId = 'pre-operative/preparation/nail-varnish-removed') and answer.value.exists()) -> obs.component as comp then { it -> comp.code as cc then { it -> cc.coding as cg then { it -> cg.system = 'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem' "sys"; it -> cg.code = 'preop-nail-varnish-removed' "cd"; it -> cg.display = 'Nail varnish removed' "dsp"; } "coding"; } "code"; it -> comp then SetComponentCodedValue(it, comp) "value"; } "comp_preop_nail_varnish_removed"; g.item as it where ((linkId = 'pre-operative/preparation/shaving') and answer.value.exists()) -> obs.component as comp then { it -> comp.code as cc then { it -> cc.coding as cg then { it -> cg.system = 'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem' "sys"; it -> cg.code = 'preop-shaving' "cd"; it -> cg.display = 'Shaving' "dsp"; } "coding"; } "code"; it -> comp then SetComponentCodedValue(it, comp) "value"; } "comp_preop_shaving"; g.item as it where ((linkId = 'pre-operative/preparation/bath') and answer.value.exists()) -> obs.component as comp then { it -> comp.code as cc then { it -> cc.coding as cg then { it -> cg.system = 'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem' "sys"; it -> cg.code = 'preop-bath' "cd"; it -> cg.display = 'Bath' "dsp"; } "coding"; } "code"; it -> comp then SetComponentCodedValue(it, comp) "value"; } "comp_preop_bath"; g.item as it where ((linkId = 'pre-operative/preparation/theatre-gown') and answer.value.exists()) -> obs.component as comp then { it -> comp.code as cc then { it -> cc.coding as cg then { it -> cg.system = 'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem' "sys"; it -> cg.code = 'preop-theatre-gown' "cd"; it -> cg.display = 'Theatre gown' "dsp"; } "coding"; } "code"; it -> comp then SetComponentCodedValue(it, comp) "value"; } "comp_preop_theatre_gown"; g.item as it where ((linkId = 'pre-operative/preparation/skin-cleaned') and answer.value.exists()) -> obs.component as comp then { it -> comp.code as cc then { it -> cc.coding as cg then { it -> cg.system = 'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem' "sys"; it -> cg.code = 'preop-skin-cleaned' "cd"; it -> cg.display = 'Skin cleaned' "dsp"; } "coding"; } "code"; it -> comp then SetComponentCodedValue(it, comp) "value"; } "comp_preop_skin_cleaned"; } "preparationPanel"; // Lines and tubes in place. A separate panel from the preparation checklist // because these are devices the theatre has to know about, not tasks the // ward has to have finished. pg.item as g where ((linkId = 'pre-operative/lines') and item.answer.value.exists()) -> bundle.entry as entry, entry.resource = create('Observation') as obs then { qr -> obs, entry then BuildObsBase(qr, obs, entry) "base"; qr -> obs then SetExamCategory(qr, obs) "category"; g -> obs.code as cc then { g -> cc.coding as cg then { g -> cg.system = 'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem' "sys"; g -> cg.code = 'preop-lines-and-tubes-in-place-before-theatre' "cd"; g -> cg.display = 'Lines and tubes in place before theatre' "dsp"; } "coding"; } "code"; g.item as it where ((linkId = 'pre-operative/lines/catheter') and answer.value.exists()) -> obs.component as comp then { it -> comp.code as cc then { it -> cc.coding as cg then { it -> cg.system = 'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem' "sys"; it -> cg.code = 'preop-catheter' "cd"; it -> cg.display = 'Catheter' "dsp"; } "coding"; } "code"; it -> comp then SetComponentCodedValue(it, comp) "value"; } "comp_preop_catheter"; g.item as it where ((linkId = 'pre-operative/lines/nasogastric-tube') and answer.value.exists()) -> obs.component as comp then { it -> comp.code as cc then { it -> cc.coding as cg then { it -> cg.system = 'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem' "sys"; it -> cg.code = 'preop-nasogastric-tube' "cd"; it -> cg.display = 'Nasogastric tube' "dsp"; } "coding"; } "code"; it -> comp then SetComponentCodedValue(it, comp) "value"; } "comp_preop_nasogastric_tube"; g.item as it where ((linkId = 'pre-operative/lines/intravenous-infusion') and answer.value.exists()) -> obs.component as comp then { it -> comp.code as cc then { it -> cc.coding as cg then { it -> cg.system = 'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem' "sys"; it -> cg.code = 'preop-intravenous-infusion' "cd"; it -> cg.display = 'Intravenous infusion' "dsp"; } "coding"; } "code"; it -> comp then SetComponentCodedValue(it, comp) "value"; } "comp_preop_intravenous_infusion"; g.item as it where (linkId = 'pre-operative/lines/other') then { it.answer first as a then { a.value as txt -> obs.note as n, n.text = txt "text"; }; } "note"; } "linesPanel"; // Blood requested, and how many pints are actually available. Two facts, and // the second is the one that stops a case: a request with no units against // it is not blood in the fridge. pg.item as g where ((linkId = 'pre-operative/blood') and item.answer.value.exists()) -> bundle.entry as entry, entry.resource = create('Observation') as obs then { qr -> obs, entry then BuildObsBase(qr, obs, entry) "base"; qr -> obs then SetSurveyCategory(qr, obs) "category"; g -> obs.code as cc then { g -> cc.coding as cg then { g -> cg.system = 'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem' "sys"; g -> cg.code = 'preop-blood-requested-and-available-before-theatre' "cd"; g -> cg.display = 'Blood requested and available before theatre' "dsp"; } "coding"; } "code"; g.item as it where ((linkId = 'pre-operative/blood/requested') and answer.value.exists()) -> obs.component as comp then { it -> comp.code as cc then { it -> cc.coding as cg then { it -> cg.system = 'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem' "sys"; it -> cg.code = 'preop-blood-requested' "cd"; it -> cg.display = 'Blood requested' "dsp"; } "coding"; } "code"; it -> comp then SetComponentCodedValue(it, comp) "value"; } "comp_preop_blood_requested"; g.item as it where ((linkId = 'pre-operative/blood/pints-available') and answer.value.exists()) -> obs.component as comp then { it -> comp.code as cc then { it -> cc.coding as cg then { it -> cg.system = 'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem' "sys"; it -> cg.code = 'preop-pints-available' "cd"; it -> cg.display = 'Pints available' "dsp"; } "coding"; } "code"; it -> comp then SetComponentValue(it, comp) "value"; } "comp_preop_pints_available"; } "bloodPanel"; } "preOperativeGroup"; // ── The post-operative checks ─────────────────────────────────────────── qr.item as g where ((linkId = 'post-operative') and item.answer.value.exists()) -> bundle.entry as entry, entry.resource = create('Observation') as obs then { qr -> obs, entry then BuildObsBase(qr, obs, entry) "base"; qr -> obs then SetExamCategory(qr, obs) "category"; g -> obs.code as cc then { g -> cc.coding as cg then { g -> cg.system = 'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem' "sys"; g -> cg.code = 'postoperative-check' "cd"; g -> cg.display = 'Post-operative check' "dsp"; } "coding"; } "code"; g.item as it where ((linkId = 'post-operative/wound') and answer.value.exists()) -> obs.component as comp then { it -> comp.code as cc then { it -> cc.coding as cg then { it -> cg.system = 'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem' "sys"; it -> cg.code = 'postop-wound-checked' "cd"; it -> cg.display = 'Wound checked' "dsp"; } "coding"; } "code"; it -> comp then SetComponentCodedValue(it, comp) "value"; } "comp_postop_wound_checked"; g.item as it where ((linkId = 'post-operative/drainage') and answer.value.exists()) -> obs.component as comp then { it -> comp.code as cc then { it -> cc.coding as cg then { it -> cg.system = 'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem' "sys"; it -> cg.code = 'postop-drainage-checked' "cd"; it -> cg.display = 'Drainage checked' "dsp"; } "coding"; } "code"; it -> comp then SetComponentCodedValue(it, comp) "value"; } "comp_postop_drainage_checked"; g.item as it where ((linkId = 'post-operative/vomit') and answer.value.exists()) -> obs.component as comp then { it -> comp.code as cc then { it -> cc.coding as cg then { it -> cg.system = 'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem' "sys"; it -> cg.code = 'postop-vomiting-checked' "cd"; it -> cg.display = 'Vomiting checked' "dsp"; } "coding"; } "code"; it -> comp then SetComponentCodedValue(it, comp) "value"; } "comp_postop_vomiting_checked"; g.item as it where ((linkId = 'post-operative/catheter') and answer.value.exists()) -> obs.component as comp then { it -> comp.code as cc then { it -> cc.coding as cg then { it -> cg.system = 'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem' "sys"; it -> cg.code = 'postop-catheter-in-place' "cd"; it -> cg.display = 'Catheter in place' "dsp"; } "coding"; } "code"; it -> comp then SetComponentCodedValue(it, comp) "value"; } "comp_postop_catheter_in_place"; g.item as it where ((linkId = 'post-operative/nasogastric-tube') and answer.value.exists()) -> obs.component as comp then { it -> comp.code as cc then { it -> cc.coding as cg then { it -> cg.system = 'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem' "sys"; it -> cg.code = 'postop-nasogastric-tube-in-place' "cd"; it -> cg.display = 'Nasogastric tube in place' "dsp"; } "coding"; } "code"; it -> comp then SetComponentCodedValue(it, comp) "value"; } "comp_postop_nasogastric_tube_in_place"; g.item as it where ((linkId = 'post-operative/infusion-therapy') and answer.value.exists()) -> obs.component as comp then { it -> comp.code as cc then { it -> cc.coding as cg then { it -> cg.system = 'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem' "sys"; it -> cg.code = 'postop-infusion-therapy-running' "cd"; it -> cg.display = 'Infusion therapy running' "dsp"; } "coding"; } "code"; it -> comp then SetComponentCodedValue(it, comp) "value"; } "comp_postop_infusion_therapy_running"; g.item as it where ((linkId = 'post-operative/oxygen-therapy') and answer.value.exists()) -> obs.component as comp then { it -> comp.code as cc then { it -> cc.coding as cg then { it -> cg.system = 'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem' "sys"; it -> cg.code = 'postop-oxygen-therapy-running' "cd"; it -> cg.display = 'Oxygen therapy running' "dsp"; } "coding"; } "code"; it -> comp then SetComponentCodedValue(it, comp) "value"; } "comp_postop_oxygen_therapy_running"; g.item as it where ((linkId = 'post-operative/analgesic-therapy') and answer.value.exists()) -> obs.component as comp then { it -> comp.code as cc then { it -> cc.coding as cg then { it -> cg.system = 'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem' "sys"; it -> cg.code = 'postop-analgesic-therapy-given' "cd"; it -> cg.display = 'Analgesic therapy given' "dsp"; } "coding"; } "code"; it -> comp then SetComponentCodedValue(it, comp) "value"; } "comp_postop_analgesic_therapy_given"; g.item as it where ((linkId = 'post-operative/pain') and answer.value.exists()) -> obs.component as comp then { it -> comp.code as cc then { it -> cc.coding as cg then { it -> cg.system = 'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem' "sys"; it -> cg.code = 'postop-pain' "cd"; it -> cg.display = 'Pain' "dsp"; } "coding"; } "code"; it -> comp then SetComponentCodedValue(it, comp) "value"; } "comp_postop_pain"; g.item as it where ((linkId = 'post-operative/level-of-consciousness') and answer.value.exists()) -> obs.component as comp then { it -> comp.code as cc then { it -> cc.coding as cg then { it -> cg.system = 'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem' "sys"; it -> cg.code = 'postop-level-of-consciousness' "cd"; it -> cg.display = 'Level of consciousness' "dsp"; } "coding"; } "code"; it -> comp then SetComponentCodedValue(it, comp) "value"; } "comp_postop_level_of_consciousness"; g.item as it where ((linkId = 'post-operative/checklist-complete') and answer.value.exists()) -> obs.component as comp then { it -> comp.code as cc then { it -> cc.coding as cg then { it -> cg.system = 'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem' "sys"; it -> cg.code = 'postop-check-list-operative-complete' "cd"; it -> cg.display = 'Check-list operative complete' "dsp"; } "coding"; } "code"; it -> comp then SetComponentCodedValue(it, comp) "value"; } "comp_postop_check_list_operative_complete"; } "postOperativePanel"; // ── Vital signs, before and after ─────────────────────────────────────── // The same six readings twice. Each Observation carries a note saying which // side of theatre it came from, because both sets have the same LOINC codes // and the response's authored time is one instant for the whole form -- so // without the note a ward could not tell the pre-operative pulse from the // post-operative one. qr.item as g where (linkId = 'pre-operative') then { g.item as g2 where (linkId = 'pre-operative/vitals') then { g2.item as it where ((linkId = 'pre-operative/vitals/temperature') and answer.value.exists()) -> bundle.entry as entry, entry.resource = create('Observation') as obs then { qr -> obs, entry then BuildObsBase(qr, obs, entry) "base"; qr -> obs then SetVitalSignsCategory(qr, obs) "category"; it -> obs.code as cc then { it -> cc.coding as cg then { it -> cg.system = 'http://loinc.org' "sys"; it -> cg.code = '8310-5' "cd"; it -> cg.display = 'Body temperature' "dsp"; } "coding"; } "code"; it.answer first as a then { a.value as v -> obs.value = v "set"; }; it -> obs.note as n, n.text = 'Taken before theatre' "phaseNote"; } "vital_8310_5"; g2.item as it where ((linkId = 'pre-operative/vitals/pulse') and answer.value.exists()) -> bundle.entry as entry, entry.resource = create('Observation') as obs then { qr -> obs, entry then BuildObsBase(qr, obs, entry) "base"; qr -> obs then SetVitalSignsCategory(qr, obs) "category"; it -> obs.code as cc then { it -> cc.coding as cg then { it -> cg.system = 'http://loinc.org' "sys"; it -> cg.code = '8867-4' "cd"; it -> cg.display = 'Heart rate' "dsp"; } "coding"; } "code"; it.answer first as a then { a.value as v -> obs.value = v "set"; }; it -> obs.note as n, n.text = 'Taken before theatre' "phaseNote"; } "vital_8867_4"; g2.item as it where ((linkId = 'pre-operative/vitals/respiratory-rate') and answer.value.exists()) -> bundle.entry as entry, entry.resource = create('Observation') as obs then { qr -> obs, entry then BuildObsBase(qr, obs, entry) "base"; qr -> obs then SetVitalSignsCategory(qr, obs) "category"; it -> obs.code as cc then { it -> cc.coding as cg then { it -> cg.system = 'http://loinc.org' "sys"; it -> cg.code = '9279-1' "cd"; it -> cg.display = 'Respiratory rate' "dsp"; } "coding"; } "code"; it.answer first as a then { a.value as v -> obs.value = v "set"; }; it -> obs.note as n, n.text = 'Taken before theatre' "phaseNote"; } "vital_9279_1"; g2.item as it where ((linkId = 'pre-operative/vitals/oxygen-saturation') and answer.value.exists()) -> bundle.entry as entry, entry.resource = create('Observation') as obs then { qr -> obs, entry then BuildObsBase(qr, obs, entry) "base"; qr -> obs then SetVitalSignsCategory(qr, obs) "category"; it -> obs.code as cc then { it -> cc.coding as cg then { it -> cg.system = 'http://loinc.org' "sys"; it -> cg.code = '59408-5' "cd"; it -> cg.display = 'Oxygen saturation in Arterial blood by Pulse oximetry' "dsp"; } "coding"; } "code"; it.answer first as a then { a.value as v -> obs.value = v "set"; }; it -> obs.note as n, n.text = 'Taken before theatre' "phaseNote"; } "vital_59408_5"; g2.item as bp where ((linkId = 'pre-operative/vitals/blood-pressure') and item.answer.value.exists()) -> bundle.entry as entry, entry.resource = create('Observation') as obs then { qr -> obs, entry then BuildObsBase(qr, obs, entry) "base"; qr -> obs then SetVitalSignsCategory(qr, obs) "category"; bp -> obs.code as cc then { bp -> cc.coding as cg then { bp -> cg.system = 'http://loinc.org' "sys"; bp -> cg.code = '85354-9' "cd"; bp -> cg.display = 'Blood pressure panel with all children optional' "dsp"; } "coding"; } "code"; bp.item as it where ((linkId = 'pre-operative/vitals/blood-pressure/systolic') and answer.value.exists()) -> obs.component as comp then { it -> comp.code as cc then { it -> cc.coding as cg then { it -> cg.system = 'http://loinc.org' "sys"; it -> cg.code = '8480-6' "cd"; it -> cg.display = 'Systolic blood pressure' "dsp"; } "coding"; } "code"; it -> comp then SetComponentValue(it, comp) "value"; } "comp_8480_6"; bp.item as it where ((linkId = 'pre-operative/vitals/blood-pressure/diastolic') and answer.value.exists()) -> obs.component as comp then { it -> comp.code as cc then { it -> cc.coding as cg then { it -> cg.system = 'http://loinc.org' "sys"; it -> cg.code = '8462-4' "cd"; it -> cg.display = 'Diastolic blood pressure' "dsp"; } "coding"; } "code"; it -> comp then SetComponentValue(it, comp) "value"; } "comp_8462_4"; bp -> obs.note as n, n.text = 'Taken before theatre' "phaseNote"; } "bp"; } "vitalsSub"; } "vitalsGrp"; qr.item as g where (linkId = 'post-operative') then { g.item as g2 where (linkId = 'post-operative/vitals') then { g2.item as it where ((linkId = 'post-operative/vitals/temperature') and answer.value.exists()) -> bundle.entry as entry, entry.resource = create('Observation') as obs then { qr -> obs, entry then BuildObsBase(qr, obs, entry) "base"; qr -> obs then SetVitalSignsCategory(qr, obs) "category"; it -> obs.code as cc then { it -> cc.coding as cg then { it -> cg.system = 'http://loinc.org' "sys"; it -> cg.code = '8310-5' "cd"; it -> cg.display = 'Body temperature' "dsp"; } "coding"; } "code"; it.answer first as a then { a.value as v -> obs.value = v "set"; }; it -> obs.note as n, n.text = 'Taken on return from theatre' "phaseNote"; } "vital_8310_52"; g2.item as it where ((linkId = 'post-operative/vitals/pulse') and answer.value.exists()) -> bundle.entry as entry, entry.resource = create('Observation') as obs then { qr -> obs, entry then BuildObsBase(qr, obs, entry) "base"; qr -> obs then SetVitalSignsCategory(qr, obs) "category"; it -> obs.code as cc then { it -> cc.coding as cg then { it -> cg.system = 'http://loinc.org' "sys"; it -> cg.code = '8867-4' "cd"; it -> cg.display = 'Heart rate' "dsp"; } "coding"; } "code"; it.answer first as a then { a.value as v -> obs.value = v "set"; }; it -> obs.note as n, n.text = 'Taken on return from theatre' "phaseNote"; } "vital_8867_42"; g2.item as it where ((linkId = 'post-operative/vitals/respiratory-rate') and answer.value.exists()) -> bundle.entry as entry, entry.resource = create('Observation') as obs then { qr -> obs, entry then BuildObsBase(qr, obs, entry) "base"; qr -> obs then SetVitalSignsCategory(qr, obs) "category"; it -> obs.code as cc then { it -> cc.coding as cg then { it -> cg.system = 'http://loinc.org' "sys"; it -> cg.code = '9279-1' "cd"; it -> cg.display = 'Respiratory rate' "dsp"; } "coding"; } "code"; it.answer first as a then { a.value as v -> obs.value = v "set"; }; it -> obs.note as n, n.text = 'Taken on return from theatre' "phaseNote"; } "vital_9279_12"; g2.item as it where ((linkId = 'post-operative/vitals/oxygen-saturation') and answer.value.exists()) -> bundle.entry as entry, entry.resource = create('Observation') as obs then { qr -> obs, entry then BuildObsBase(qr, obs, entry) "base"; qr -> obs then SetVitalSignsCategory(qr, obs) "category"; it -> obs.code as cc then { it -> cc.coding as cg then { it -> cg.system = 'http://loinc.org' "sys"; it -> cg.code = '59408-5' "cd"; it -> cg.display = 'Oxygen saturation in Arterial blood by Pulse oximetry' "dsp"; } "coding"; } "code"; it.answer first as a then { a.value as v -> obs.value = v "set"; }; it -> obs.note as n, n.text = 'Taken on return from theatre' "phaseNote"; } "vital_59408_52"; g2.item as bp where ((linkId = 'post-operative/vitals/blood-pressure') and item.answer.value.exists()) -> bundle.entry as entry, entry.resource = create('Observation') as obs then { qr -> obs, entry then BuildObsBase(qr, obs, entry) "base"; qr -> obs then SetVitalSignsCategory(qr, obs) "category"; bp -> obs.code as cc then { bp -> cc.coding as cg then { bp -> cg.system = 'http://loinc.org' "sys"; bp -> cg.code = '85354-9' "cd"; bp -> cg.display = 'Blood pressure panel with all children optional' "dsp"; } "coding"; } "code"; bp.item as it where ((linkId = 'post-operative/vitals/blood-pressure/systolic') and answer.value.exists()) -> obs.component as comp then { it -> comp.code as cc then { it -> cc.coding as cg then { it -> cg.system = 'http://loinc.org' "sys"; it -> cg.code = '8480-6' "cd"; it -> cg.display = 'Systolic blood pressure' "dsp"; } "coding"; } "code"; it -> comp then SetComponentValue(it, comp) "value"; } "comp_8480_62"; bp.item as it where ((linkId = 'post-operative/vitals/blood-pressure/diastolic') and answer.value.exists()) -> obs.component as comp then { it -> comp.code as cc then { it -> cc.coding as cg then { it -> cg.system = 'http://loinc.org' "sys"; it -> cg.code = '8462-4' "cd"; it -> cg.display = 'Diastolic blood pressure' "dsp"; } "coding"; } "code"; it -> comp then SetComponentValue(it, comp) "value"; } "comp_8462_42"; bp -> obs.note as n, n.text = 'Taken on return from theatre' "phaseNote"; } "bp2"; } "vitalsSub2"; } "vitalsGrp2"; // ── Investigations ordered, before and after ───────────────────────────── qr.item as g where (linkId = 'pre-operative') then { g.item as g2 where (linkId = 'pre-operative/investigations') then { g2.item as it where ((linkId = 'pre-operative/investigations/fhg') and (answer.value.ofType(Coding).code = 'Y')) -> bundle.entry as entry, entry.resource = create('ServiceRequest') as sr then { qr -> sr, entry then BuildServiceRequestBase(qr, sr, entry) "base"; it -> sr.status = 'active' "status"; it -> sr.intent = 'order' "intent"; it -> sr.category as cat then { it -> cat.coding as cg then { it -> cg.system = 'http://snomed.info/sct' "sys"; it -> cg.code = '108252007' "cd"; it -> cg.display = 'Laboratory procedure' "dsp"; } "coding"; } "category"; it -> sr.code as cr, cr.concept as cc, cc.text = 'Full haemogram' "codeText"; qr.authored as t -> sr.authoredOn = t "authoredOn"; qr.encounter as e -> sr.encounter = e; qr.source as src -> sr.requester = src "requester"; it -> sr.note as n, n.text = 'Ordered before theatre' "phaseNote"; } "order_fhg"; } "orderSub"; } "orderGrp"; qr.item as g where (linkId = 'pre-operative') then { g.item as g2 where (linkId = 'pre-operative/investigations') then { g2.item as it where ((linkId = 'pre-operative/investigations/coagulation') and (answer.value.ofType(Coding).code = 'Y')) -> bundle.entry as entry, entry.resource = create('ServiceRequest') as sr then { qr -> sr, entry then BuildServiceRequestBase(qr, sr, entry) "base"; it -> sr.status = 'active' "status"; it -> sr.intent = 'order' "intent"; it -> sr.category as cat then { it -> cat.coding as cg then { it -> cg.system = 'http://snomed.info/sct' "sys"; it -> cg.code = '108252007' "cd"; it -> cg.display = 'Laboratory procedure' "dsp"; } "coding"; } "category"; it -> sr.code as cr, cr.concept as cc, cc.text = 'Coagulation profile' "codeText"; qr.authored as t -> sr.authoredOn = t "authoredOn"; qr.encounter as e -> sr.encounter = e; qr.source as src -> sr.requester = src "requester"; it -> sr.note as n, n.text = 'Ordered before theatre' "phaseNote"; } "order_coagulation"; } "orderSub2"; } "orderGrp2"; qr.item as g where (linkId = 'pre-operative') then { g.item as g2 where (linkId = 'pre-operative/investigations') then { g2.item as it where ((linkId = 'pre-operative/investigations/urinalysis') and (answer.value.ofType(Coding).code = 'Y')) -> bundle.entry as entry, entry.resource = create('ServiceRequest') as sr then { qr -> sr, entry then BuildServiceRequestBase(qr, sr, entry) "base"; it -> sr.status = 'active' "status"; it -> sr.intent = 'order' "intent"; it -> sr.category as cat then { it -> cat.coding as cg then { it -> cg.system = 'http://snomed.info/sct' "sys"; it -> cg.code = '108252007' "cd"; it -> cg.display = 'Laboratory procedure' "dsp"; } "coding"; } "category"; it -> sr.code as cr, cr.concept as cc, cc.text = 'Urinalysis' "codeText"; qr.authored as t -> sr.authoredOn = t "authoredOn"; qr.encounter as e -> sr.encounter = e; qr.source as src -> sr.requester = src "requester"; it -> sr.note as n, n.text = 'Ordered before theatre' "phaseNote"; } "order_urinalysis"; } "orderSub3"; } "orderGrp3"; qr.item as g where (linkId = 'pre-operative') then { g.item as g2 where (linkId = 'pre-operative/investigations') then { g2.item as it where ((linkId = 'pre-operative/investigations/blood-group') and (answer.value.ofType(Coding).code = 'Y')) -> bundle.entry as entry, entry.resource = create('ServiceRequest') as sr then { qr -> sr, entry then BuildServiceRequestBase(qr, sr, entry) "base"; it -> sr.status = 'active' "status"; it -> sr.intent = 'order' "intent"; it -> sr.category as cat then { it -> cat.coding as cg then { it -> cg.system = 'http://snomed.info/sct' "sys"; it -> cg.code = '108252007' "cd"; it -> cg.display = 'Laboratory procedure' "dsp"; } "coding"; } "category"; it -> sr.code as cr, cr.concept as cc, cc.text = 'Blood group' "codeText"; qr.authored as t -> sr.authoredOn = t "authoredOn"; qr.encounter as e -> sr.encounter = e; qr.source as src -> sr.requester = src "requester"; it -> sr.note as n, n.text = 'Ordered before theatre' "phaseNote"; } "order_blood_group"; } "orderSub4"; } "orderGrp4"; qr.item as g where (linkId = 'pre-operative') then { g.item as g2 where (linkId = 'pre-operative/investigations') then { g2.item as it where ((linkId = 'pre-operative/investigations/x-ray') and (answer.value.ofType(Coding).code = 'Y')) -> bundle.entry as entry, entry.resource = create('ServiceRequest') as sr then { qr -> sr, entry then BuildServiceRequestBase(qr, sr, entry) "base"; it -> sr.status = 'active' "status"; it -> sr.intent = 'order' "intent"; it -> sr.category as cat then { it -> cat.coding as cg then { it -> cg.system = 'http://snomed.info/sct' "sys"; it -> cg.code = '363679005' "cd"; it -> cg.display = 'Imaging' "dsp"; } "coding"; } "category"; it -> sr.code as cr, cr.concept as cc, cc.text = 'X-ray' "codeText"; qr.authored as t -> sr.authoredOn = t "authoredOn"; qr.encounter as e -> sr.encounter = e; qr.source as src -> sr.requester = src "requester"; it -> sr.note as n, n.text = 'Ordered before theatre' "phaseNote"; } "order_x_ray"; } "orderSub5"; } "orderGrp5"; qr.item as g where (linkId = 'post-operative') then { g.item as g2 where (linkId = 'post-operative/investigations') then { g2.item as it where ((linkId = 'post-operative/investigations/fhg') and (answer.value.ofType(Coding).code = 'Y')) -> bundle.entry as entry, entry.resource = create('ServiceRequest') as sr then { qr -> sr, entry then BuildServiceRequestBase(qr, sr, entry) "base"; it -> sr.status = 'active' "status"; it -> sr.intent = 'order' "intent"; it -> sr.category as cat then { it -> cat.coding as cg then { it -> cg.system = 'http://snomed.info/sct' "sys"; it -> cg.code = '108252007' "cd"; it -> cg.display = 'Laboratory procedure' "dsp"; } "coding"; } "category"; it -> sr.code as cr, cr.concept as cc, cc.text = 'Full haemogram' "codeText"; qr.authored as t -> sr.authoredOn = t "authoredOn"; qr.encounter as e -> sr.encounter = e; qr.source as src -> sr.requester = src "requester"; it -> sr.note as n, n.text = 'Ordered on return from theatre' "phaseNote"; } "order_fhg2"; } "orderSub6"; } "orderGrp6"; qr.item as g where (linkId = 'post-operative') then { g.item as g2 where (linkId = 'post-operative/investigations') then { g2.item as it where ((linkId = 'post-operative/investigations/coagulation') and (answer.value.ofType(Coding).code = 'Y')) -> bundle.entry as entry, entry.resource = create('ServiceRequest') as sr then { qr -> sr, entry then BuildServiceRequestBase(qr, sr, entry) "base"; it -> sr.status = 'active' "status"; it -> sr.intent = 'order' "intent"; it -> sr.category as cat then { it -> cat.coding as cg then { it -> cg.system = 'http://snomed.info/sct' "sys"; it -> cg.code = '108252007' "cd"; it -> cg.display = 'Laboratory procedure' "dsp"; } "coding"; } "category"; it -> sr.code as cr, cr.concept as cc, cc.text = 'Coagulation profile' "codeText"; qr.authored as t -> sr.authoredOn = t "authoredOn"; qr.encounter as e -> sr.encounter = e; qr.source as src -> sr.requester = src "requester"; it -> sr.note as n, n.text = 'Ordered on return from theatre' "phaseNote"; } "order_coagulation2"; } "orderSub7"; } "orderGrp7"; qr.item as g where (linkId = 'post-operative') then { g.item as g2 where (linkId = 'post-operative/investigations') then { g2.item as it where ((linkId = 'post-operative/investigations/urinalysis') and (answer.value.ofType(Coding).code = 'Y')) -> bundle.entry as entry, entry.resource = create('ServiceRequest') as sr then { qr -> sr, entry then BuildServiceRequestBase(qr, sr, entry) "base"; it -> sr.status = 'active' "status"; it -> sr.intent = 'order' "intent"; it -> sr.category as cat then { it -> cat.coding as cg then { it -> cg.system = 'http://snomed.info/sct' "sys"; it -> cg.code = '108252007' "cd"; it -> cg.display = 'Laboratory procedure' "dsp"; } "coding"; } "category"; it -> sr.code as cr, cr.concept as cc, cc.text = 'Urinalysis' "codeText"; qr.authored as t -> sr.authoredOn = t "authoredOn"; qr.encounter as e -> sr.encounter = e; qr.source as src -> sr.requester = src "requester"; it -> sr.note as n, n.text = 'Ordered on return from theatre' "phaseNote"; } "order_urinalysis2"; } "orderSub8"; } "orderGrp8"; qr.item as g where (linkId = 'post-operative') then { g.item as g2 where (linkId = 'post-operative/investigations') then { g2.item as it where ((linkId = 'post-operative/investigations/x-ray') and (answer.value.ofType(Coding).code = 'Y')) -> bundle.entry as entry, entry.resource = create('ServiceRequest') as sr then { qr -> sr, entry then BuildServiceRequestBase(qr, sr, entry) "base"; it -> sr.status = 'active' "status"; it -> sr.intent = 'order' "intent"; it -> sr.category as cat then { it -> cat.coding as cg then { it -> cg.system = 'http://snomed.info/sct' "sys"; it -> cg.code = '363679005' "cd"; it -> cg.display = 'Imaging' "dsp"; } "coding"; } "category"; it -> sr.code as cr, cr.concept as cc, cc.text = 'X-ray' "codeText"; qr.authored as t -> sr.authoredOn = t "authoredOn"; qr.encounter as e -> sr.encounter = e; qr.source as src -> sr.requester = src "requester"; it -> sr.note as n, n.text = 'Ordered on return from theatre' "phaseNote"; } "order_x_ray2"; } "orderSub9"; } "orderGrp9"; // ── Allergy recorded on the checklist ─────────────────────────────────── // Recorded as an Observation, not an AllergyIntolerance. The checklist asks // the team to *review* a known allergy, not to record a new one; the drug, // anaesthetic and other lines are what they read out, and creating an // AllergyIntolerance from a read-back would duplicate whatever the pharmacy // already holds. qr.item as g where ((linkId = 'allergy') and item.answer.value.exists()) -> bundle.entry as entry, entry.resource = create('Observation') as obs then { qr -> obs, entry then BuildObsBase(qr, obs, entry) "base"; qr -> obs then SetSurveyCategory(qr, obs) "category"; g -> obs.code as cc then { g -> cc.coding as cg then { g -> cg.system = 'http://loinc.org' "sys"; g -> cg.code = '48765-2' "cd"; g -> cg.display = 'Allergies and adverse reactions Document' "dsp"; } "coding"; g -> cc.text = 'Allergy reviewed at the surgical safety checklist' "codeText"; } "code"; g.item as it where (linkId = 'allergy/drug') then { it.answer first as a then { a.value as txt -> obs.note as n, n.text = txt "text"; }; } "note2"; g.item as it where (linkId = 'allergy/anaesthesia') then { it.answer first as a then { a.value as txt -> obs.note as n, n.text = txt "text"; }; } "note3"; g.item as it where (linkId = 'allergy/other') then { it.answer first as a then { a.value as txt -> obs.note as n, n.text = txt "text"; }; } "note4"; g.item as it where ((linkId = 'allergy/none-known') and answer.value.exists()) -> obs.component as comp then { it -> comp.code as cc then { it -> cc.coding as cg then { it -> cg.system = 'https://fhir.slade360.co.ke/fhir/CodeSystem/concept-codesystem' "sys"; it -> cg.code = 'who-check-no-known-allergies' "cd"; it -> cg.display = 'No known allergies' "dsp"; } "coding"; } "code"; it -> comp then SetComponentCodedValue(it, comp) "value"; } "comp_who_check_no_known_allergies"; } "allergyObservation"; } // ───────────────────────────────────────────────────────────────────────────── // Shared scaffolding. Repeated in each map rather than imported: the transform // engine resolves `imports` against whatever StructureMaps happen to be on the // server, and a form that stops extracting because a shared map was not // uploaded is a worse failure than a duplicated group. // Two notes on what the publisher's StructureMap validator says about this file. // Source parameters below are left untyped on purpose. Writing `: Element` makes // the validator compare QuestionnaireResponse.item against the literal 'Element' // and report them as incompatible with each other, which is noise, not a finding. // `evaluate(context, expression)` is flagged as "takes 1 parameter but 2 were // found". Leave it. The FML parser in the same jar refuses the one-argument form // outright -- it wants a parameter, a comma, then the FHIRPath -- so the // publisher is objecting to what its own compiler emits. Two arguments is the // only form that compiles, and it is what the R5 transform engine executes. // ───────────────────────────────────────────────────────────────────────────── group BuildObsBase(source qr : QR, target obs : Observation, target entry) { qr -> obs then SetResponseProvenance(qr, obs) "responseProvenance"; qr -> obs.id = uuid() then SetObservationFullUrl(obs, entry) "idAndFullUrl"; qr -> entry.request as request then { qr -> request.method = 'POST' "requestMethod"; qr -> request.url = 'Observation' "requestUrl"; } "entryRequest"; qr -> obs.status = 'final' "status"; qr.subject as s -> obs.subject = s; qr.encounter as e -> obs.encounter = e; qr.authored as t -> obs.effective = t "effective"; qr.source as src -> obs.performer = src "performerFromSource"; qr where (source.exists().not()) then { qr.author as a -> obs.performer = a "performerFromAuthor"; } "performerFallback"; // A stored response's id already reads "QuestionnaireResponse/<id>", so it is // a relative reference as it stands. The hasValue() guard is what stops an // unsaved response -- one posted straight to $extract rather than saved first // -- from writing "QuestionnaireResponse/null" into the record. qr.id as qid where ($this.hasValue()) -> obs.derivedFrom = create('Reference') as ref, ref.reference = qid "linkQuestionnaireResponse"; } group SetObservationFullUrl(source obs : Observation, target entry) { obs.id as id -> entry.fullUrl = append('https://fhir.slade360.co.ke/fhir/Observation/', id) "assignFullUrl"; } // The two answer shapes a component can carry. Both read the answer through the // untyped `.value` accessor: reading `valueCoding` or `valueQuantity` by its // typed property name fails at transform time on HAPI R5 with "Attempt to read // invalid property ... on QuestionnaireResponse.item.answer". group SetComponentCodedValue(source it, target comp) { it.answer first as a then { a.value as cv -> comp.value = create('CodeableConcept') as cc then { cv -> cc.coding = cv "valueCoding"; cv.display as d -> cc.text = d "valueText"; } "codedValue"; } "componentAnswer"; } group SetComponentValue(source it, target comp) { it.answer first as a then { a.value as v -> comp.value = v "plainValue"; } "componentAnswer"; } group SetSurveyCategory(source qr : QR, target obs : Observation) { qr -> obs.category as cat then { qr -> cat.coding as coding then { qr -> coding.system = 'http://terminology.hl7.org/CodeSystem/observation-category' "categorySystem"; qr -> coding.code = 'survey' "categoryCode"; qr -> coding.display = 'Survey' "categoryDisplay"; } "categoryCoding"; } "category"; } group SetVitalSignsCategory(source qr : QR, target obs : Observation) { qr -> obs.category as cat then { qr -> cat.coding as coding then { qr -> coding.system = 'http://terminology.hl7.org/CodeSystem/observation-category' "categorySystem"; qr -> coding.code = 'vital-signs' "categoryCode"; qr -> coding.display = 'Vital Signs' "categoryDisplay"; } "categoryCoding"; } "category"; } group SetExamCategory(source qr : QR, target obs : Observation) { qr -> obs.category as cat then { qr -> cat.coding as coding then { qr -> coding.system = 'http://terminology.hl7.org/CodeSystem/observation-category' "categorySystem"; qr -> coding.code = 'exam' "categoryCode"; qr -> coding.display = 'Exam' "categoryDisplay"; } "categoryCoding"; } "category"; } group BuildServiceRequestBase(source qr : QR, target r : ServiceRequest, target entry) { qr -> r then SetResponseProvenance(qr, r) "responseProvenance"; qr -> r.id = uuid() then SetServiceRequestFullUrl(r, entry) "idAndFullUrl"; qr -> entry.request as request then { qr -> request.method = 'POST' "requestMethod"; qr -> request.url = 'ServiceRequest' "requestUrl"; } "entryRequest"; qr.subject as s -> r.subject = s; } group SetServiceRequestFullUrl(source r : ServiceRequest, target entry) { r.id as id -> entry.fullUrl = append('https://fhir.slade360.co.ke/fhir/ServiceRequest/', id) "assignFullUrl"; } // ── Provenance and tenancy ─────────────────────────────────────────────────── // Two tags on everything this map creates. The first says which questionnaire // produced it, so a form that reopens mid-admission recalls its own earlier // entries and not another form's. The second copies the tenant tags off the // response, because nothing else on the path puts them there. // The code is the form's document type, not the questionnaire's id: every // environment mints its own ids, and there is only one set of maps, so an id // here would tie the tag to whichever environment stamped it. // ── Provenance and tenancy ─────────────────────────────────────────────────── group SetResponseProvenance(source qr : QR, target r) { qr -> r.meta as m then { qr -> m.tag as t then { qr -> t.system = 'http://slade360edi.com/questionnaire-provenance' "provenanceSystem"; qr -> t.code = 'surgical-safety-checklist' "provenanceCode"; qr -> t.display = 'Surgical safety checklist' "provenanceDisplay"; } "provenanceTag"; } "provenanceMeta"; // Every tag the response carries, onto the resource. `meta` is 0..1, so this // lands on the same meta the rule above created rather than a second one. qr.meta as qm then { qm.tag as qt -> r.meta as m, m.tag = qt "copyTag"; } "tenantTags"; }