FHIR © HL7.org  |  FHIRsmith 4.0.1  |  Server Home  |  XIG Home  |  XIG Stats  | 

FHIR IG analytics

Packagesilfhirprofileig
Resource TypeStructureMap
IdStructureMap-ExtractAnaestheticRecord.json
FHIR VersionR5
Sourcehttps://build.fhir.org/ig/savannahghi/sil_fhir_profile_ig/StructureMap-ExtractAnaestheticRecord.html
URLhttps://fhir.slade360.co.ke/fhir/StructureMap/ExtractAnaestheticRecord
Version0.1.0
Statusactive
Date2026-09-11T12:18:36+00:00
NameExtractAnaestheticRecord
TitleAnaesthetic Record Extraction
DescriptionThe anaesthetic chart out as: one Procedure for the anaesthesia itself, carrying the technique as its category, the anaesthetist as its performer and the start and completion times as its period; one Observation per timed reading taken through the case, each with its own effective time, because the paper chart is a graph and a graph is a time series; one MedicationAdministration per drug and per fluid, because those were given rather than ordered; and the estimated blood loss as its own Observation under the LOINC operation-note code, marked as an estimate.

Resources that use this resource

No resources found


Resources that this resource uses

No resources found


Narrative

Note: links and images are rebased to the (stated) source

Generated Narrative: StructureMap ExtractAnaestheticRecord

/// url = 'https://fhir.slade360.co.ke/fhir/StructureMap/ExtractAnaestheticRecord'
/// name = 'ExtractAnaestheticRecord'
/// title = 'Anaesthetic Record Extraction'
/// status = 'active'
/// description = 'The anaesthetic chart out as: one Procedure for the anaesthesia itself, carrying the technique as its category, the anaesthetist as its performer and the start and completion times as its period; one Observation per timed reading taken through the case, each with its own effective time, because the paper chart is a graph and a graph is a time series; one MedicationAdministration per drug and per fluid, because those were given rather than ordered; and the estimated blood loss as its own Observation under the LOINC operation-note code, marked as an estimate.'

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/Procedure" alias Procedure as target
uses "http://hl7.org/fhir/StructureDefinition/MedicationAdministration" alias MedicationAdministration as target

group ExtractAnaestheticRecord(source qr : QR, target bundle : Bundle) {
  qr -> bundle.type = 'transaction' "setBundleType";
  // ── The anaesthesia, as a Procedure ─────────────────────────────────────
  // SNOMED 399097000, administration of anaesthesia, which was checked against
  // tx.fhir.org. The technique -- general, spinal, block, sedation, local --
  // becomes Procedure.category, because it classifies the procedure rather than
  // being a separate finding about it.
  // The performer is the anaesthetist named on the chart, not the response's
  // source: an anaesthetic record is sometimes written up by someone else, and
  // attributing the anaesthetic to the transcriber would be wrong.
  qr.item as g where (linkId = 'case') ->  bundle.entry as entry,  entry.resource = create('Procedure') as proc then {
    qr ->  proc,  entry then BuildProcedureBase(qr, proc, entry) "base";
    g -> proc.status = 'completed' "status";
    g -> proc.code as cc then {
      g -> cc.coding as cg then {
        g -> cg.system = 'http://snomed.info/sct' "sys";
        g -> cg.code = '399097000' "cd";
        g -> cg.display = 'Administration of anaesthesia' "dsp";
      } "coding";
    } "code";
    qr.encounter as e -> proc.encounter = e;
    // Start and completion as a Period. Both, when both are given: the duration
    // is what an audit reads, and it can only be derived if both ends are there.
    g.item as st where ((linkId = 'case/started') and answer.value.exists()) then {
      st.answer first as a then {
        a.value as t ->  proc.occurrence = create('Period') as per,  per.start = t "periodStart";
      };
    } "startRule";
    g.item as an where ((linkId = 'case/anaesthetist') and answer.value.exists()) then {
      an.answer first as a then {
        a.value as ref -> proc.performer as p then {
          ref -> p.actor = ref "actor";
          ref -> p.function as fn then {
            ref -> fn.coding as fcg then {
              ref -> fcg.system = 'https://fhir.slade360.co.ke/fhir/CodeSystem/practitioner-specialty-codesystem' "sys";
              ref -> fcg.code = 'anaesthesia' "cd";
            } "coding";
          } "function";
        } "performer";
      };
    } "anaesthetistRule";
    g.item as sg where ((linkId = 'case/surgeon') and answer.value.exists()) then {
      sg.answer first as a then {
        a.value as ref -> proc.performer as p then {
          ref -> p.actor = ref "actor";
          ref -> p.function as fn then {
            ref -> fn.coding as fcg then {
              ref -> fcg.system = 'https://fhir.slade360.co.ke/fhir/CodeSystem/practitioner-specialty-codesystem' "sys";
              ref -> fcg.code = 'general-surgery' "cd";
            } "coding";
          } "function";
        } "performer";
      };
    } "surgeonRule";
    g.item as sn where ((linkId = 'case/scrub-nurse') and answer.value.exists()) then {
      sn.answer first as a then {
        a.value as ref ->  proc.performer as p,  p.actor = ref "scrubNurse";
      };
    } "scrubNurseRule";
    // Type of surgery goes to Procedure.reason: this anaesthetic was given in
    // order to allow that operation. Free text, because the theatre list is not
    // a coded catalogue here.
    g.item as ts where ((linkId = 'case/type-of-surgery') and answer.value.exists()) then {
      ts.answer first as a then {
        a.value as txt ->  proc.reason as rsn,  rsn.concept as rc,  rc.text = txt "reasonText";
      };
    } "typeOfSurgeryRule";
    g.item as dx where ((linkId = 'case/diagnosis') and answer.value.exists()) then {
      dx.answer first as a then {
        a.value as txt ->  proc.note as n,  n.text = txt "diagnosisNote";
      };
    } "diagnosisRule";
    // Technique as Procedure.category, and the agents as notes. The agents are
    // free text on the chart -- "propofol / sevo / fentanyl" on one line -- and
    // splitting that into MedicationAdministrations would invent doses.
    qr.item as tg where (linkId = 'technique') then {
      tg.item as it where ((linkId = 'technique/type') and answer.value.exists()) then {
        it.answer first as a then {
          a.value as cv -> proc.category as cat then {
            cv -> cat.coding = cv "categoryCoding";
            cv.display as d -> cat.text = d "categoryText";
          } "category";
        };
      } "techniqueTypeRule";
      tg.item as it where (linkId = 'technique/premedication') then {
        it.answer first as a then {
          a.value as txt ->  proc.note as n,  n.text = txt "note";
        };
      } "technique_premedication";
      tg.item as it where (linkId = 'technique/induction') then {
        it.answer first as a then {
          a.value as txt ->  proc.note as n,  n.text = txt "note";
        };
      } "technique_induction";
      tg.item as it where (linkId = 'technique/maintenance') then {
        it.answer first as a then {
          a.value as txt ->  proc.note as n,  n.text = txt "note";
        };
      } "technique_maintenance";
      tg.item as it where (linkId = 'technique/position') then {
        it.answer first as a then {
          a.value as txt ->  proc.note as n,  n.text = txt "note";
        };
      } "technique_position";
    } "techniqueGroup";
    // The outcome sections. `outcome` takes the result of the operation;
    // reversal and post-operative instructions are what recovery has to act
    // on, so they are followUp rather than notes -- a note is read, a followUp
    // is a stated instruction.
    qr.item as og where (linkId = 'outcome') then {
      og.item as it where ((linkId = 'outcome/result-and-remarks') and answer.value.exists()) then {
        it.answer first as a then {
          a.value as txt ->  proc.outcome as oc,  oc.text = txt "outcomeText";
        };
      } "outcomeRule";
      og.item as it where ((linkId = 'outcome/reversal-notes') and answer.value.exists()) then {
        it.answer first as a then {
          a.value as txt ->  proc.followUp as fu,  fu.text = txt "reversalText";
        };
      } "reversalRule";
      og.item as it where ((linkId = 'outcome/post-operative-instructions') and answer.value.exists()) then {
        it.answer first as a then {
          a.value as txt ->  proc.followUp as fu,  fu.text = txt "instructionsText";
        };
      } "instructionsRule";
    } "outcomeGroup";
  } "anaesthesiaProcedure";
  // ── The observations taken through the case ─────────────────────────────
  // One Observation per reading, each with the reading's own time as its
  // effective time. The chart is a graph at half-hourly gridlines; collapsing
  // it into one Observation with thirty components would lose the axis the
  // graph exists for.
  // The time on the chart is a clock time with no date. It is written to
  // Observation.effective as given; the case's own date is on the Procedure
  // this Observation sits beside, and inventing a date here would be a guess
  // that reads as a fact.
  qr.item as g where ((linkId = 'observation') 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";
    g -> obs.code as cc then {
      g -> cc.coding as cg then {
        g -> cg.system = 'http://loinc.org' "sys";
        g -> cg.code = '8716-3' "cd";
        g -> cg.display = 'Vital signs note' "dsp";
      } "coding";
      g -> cc.text = 'Observation during anaesthesia' "codeText";
    } "code";
    g.item as tm where ((linkId = 'observation/time') and answer.value.exists()) then {
      tm.answer first as a then {
        a.value as t ->  obs.note as n,  n.text = 'Reading taken at the time recorded on the anaesthetic chart' "timeNote";
      };
    } "readingTimeRule";
    g.item as it where ((linkId = 'observation/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";
    g.item as it where ((linkId = 'observation/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";
    g.item as it where ((linkId = 'observation/pulse') 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 = '8867-4' "cd";
          it -> cg.display = 'Heart rate' "dsp";
        } "coding";
      } "code";
      it -> comp then SetComponentValue(it, comp) "value";
    } "comp_8867_4";
    g.item as it where ((linkId = 'observation/oxygen-saturation') 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 = '59408-5' "cd";
          it -> cg.display = 'Oxygen saturation in Arterial blood by Pulse oximetry' "dsp";
        } "coding";
      } "code";
      it -> comp then SetComponentValue(it, comp) "value";
    } "comp_59408_5";
  } "intraOperativeReading";
  // ── Drugs and fluids given ──────────────────────────────────────────────
  // MedicationAdministration, not MedicationRequest. These were given, in
  // theatre, by the anaesthetist; there was no order to fulfil and no pharmacy
  // in the loop. `status = 'completed'` for the same reason.
  // `medication.concept.text` carries the drug name as written. The hospital's
  // formulary is not coded and a guessed RxNorm or ATC code on a cytotoxic or an
  // induction agent is a patient-safety risk, not a data-quality nicety.
  qr.item as g where ((linkId = 'drug') and item.where(linkId = 'drug/name').answer.value.exists()) ->  bundle.entry as entry,  entry.resource = create('MedicationAdministration') as ma then {
    qr ->  ma,  entry then BuildMedicationAdministrationBase(qr, ma, entry) "base";
    g -> ma.status = 'completed' "status";
    qr.encounter as e -> ma.encounter = e;
    qr.source as src ->  ma.performer as p,  p.actor = create('CodeableReference') as cr,  cr.reference = src "performer";
    g.item as it where (linkId = 'drug/name') then {
      it.answer first as a then {
        a.value as txt ->  ma.medication as med,  med.concept as mc,  mc.text = txt "medicationText";
      };
    } "drugNameRule";
    g.item as it where ((linkId = 'drug/dose') and answer.value.exists()) then {
      it.answer first as a then {
        a.value as txt ->  ma.dosage as dos,  dos.text = txt "dosageText";
      };
    } "drugDoseRule";
    g.item as it where ((linkId = 'drug/time') and answer.value.exists()) then {
      it.answer first as a then {
        a.value as t ->  ma.note as n,  n.text = 'Given at the time recorded on the anaesthetic chart' "timeNote";
      };
    } "drugTimeRule";
    qr.authored as t -> ma.occurence = t "occurrence";
  } "drugAdministration";
  qr.item as g where ((linkId = 'iv-fluid') and item.where(linkId = 'iv-fluid/name').answer.value.exists()) ->  bundle.entry as entry,  entry.resource = create('MedicationAdministration') as ma then {
    qr ->  ma,  entry then BuildMedicationAdministrationBase(qr, ma, entry) "base";
    g -> ma.status = 'completed' "status";
    qr.encounter as e -> ma.encounter = e;
    qr.source as src ->  ma.performer as p,  p.actor = create('CodeableReference') as cr,  cr.reference = src "performer";
    g.item as it where (linkId = 'iv-fluid/name') then {
      it.answer first as a then {
        a.value as txt ->  ma.medication as med,  med.concept as mc,  mc.text = txt "medicationText";
      };
    } "fluidNameRule";
    // Guarded on the answer being a Quantity, not merely present. Dosage.dose
    // takes a Quantity or a Range and nothing else, so a client that submits
    // a bare string there fails the rule and takes the whole extraction with
    // it -- which is exactly what the questionnaire tester does: it renders a
    // `quantity` item as a plain text box and submits valueString "5".
    // `$validate` on such a response says so plainly ("Answer value must be
    // of the type Quantity not string"); one non-conformant field should not
    // cost every other resource on the form.
    g.item as it where ((linkId = 'iv-fluid/volume') and answer.value.ofType(Quantity).exists()) then {
      it.answer first as a then {
        a.value as v ->  ma.dosage as dos,  dos.dose = v "dosageVolume";
      };
    } "fluidVolumeRule";
    qr.authored as t -> ma.occurence = t "occurrence";
    g ->  ma.note as n,  n.text = 'Intravenous fluid given during anaesthesia' "fluidNote";
  } "fluidAdministration";
  // ── Estimated blood loss ────────────────────────────────────────────────
  // LOINC 8717-1, the operation note's own term for it, which is exactly what
  // this is. The note says it is an estimate: the figure drives a transfusion
  // decision and a reader has to know it was eyeballed, not measured.
  qr.item as it where ((linkId = 'estimated-blood-loss') 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 SetProcedureCategory(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 = '8717-1' "cd";
        it -> cg.display = 'Surgical operation note estimated blood loss [Volume]' "dsp";
      } "coding";
    } "code";
    it.answer first as a then {
      a.value as v -> obs.value = v "set";
    };
    it ->  obs.note as n,  n.text = 'An estimate made in theatre, not a measured volume.' "estimateNote";
  } "bloodLossObservation";
  // ── Anaesthesia duration ────────────────────────────────────────────────
  // Extracted only when the form carries it. The questionnaire leaves the field
  // read-only and expects the client to derive it from the start and completion
  // times; where the client did, that value is authoritative and is recorded
  // under LOINC 89874-2. Where it did not, nothing is written -- the Procedure's
  // period already holds both ends, and a duration computed here from a clock
  // time with no date could be a day out.
  qr.item as g where (linkId = 'case') then {
    g.item as it where ((linkId = 'case/duration') 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 SetProcedureCategory(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 = '89874-2' "cd";
          it -> cg.display = 'Anesthesia duration' "dsp";
        } "coding";
      } "code";
      it.answer first as a then {
        a.value as v -> obs.value = v "set";
      };
    } "durationObservation";
  } "durationGroup";
}

// ─────────────────────────────────────────────────────────────────────────────
// 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 SetProcedureCategory(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 = 'procedure' "categoryCode";
      qr -> coding.display = 'Procedure' "categoryDisplay";
    } "categoryCoding";
  } "category";
}

group BuildProcedureBase(source qr : QR, target r : Procedure, target entry) {
  qr -> r then SetResponseProvenance(qr, r) "responseProvenance";
  qr -> r.id = uuid() then SetProcedureFullUrl(r, entry) "idAndFullUrl";
  qr -> entry.request as request then {
    qr -> request.method = 'POST' "requestMethod";
    qr -> request.url = 'Procedure' "requestUrl";
  } "entryRequest";
  // The response's own time, as a floor, the way BuildObsBase does it. A rule
  // that reads a time off the form overwrites this; without it a procedure whose
  // date column was taken off on review has no time at all, and a procedure with
  // no time cannot be ordered against the rest of the admission.
  qr.authored as t -> r.occurrence = t "occurrenceFallback";
  qr.subject as s -> r.subject = s;
}

group SetProcedureFullUrl(source r : Procedure, target entry) {
  r.id as id -> entry.fullUrl = append('https://fhir.slade360.co.ke/fhir/Procedure/', id) "assignFullUrl";
}

group BuildMedicationAdministrationBase(source qr : QR, target r : MedicationAdministration, target entry) {
  qr -> r then SetResponseProvenance(qr, r) "responseProvenance";
  qr -> r.id = uuid() then SetMedicationAdministrationFullUrl(r, entry) "idAndFullUrl";
  qr -> entry.request as request then {
    qr -> request.method = 'POST' "requestMethod";
    qr -> request.url = 'MedicationAdministration' "requestUrl";
  } "entryRequest";
  qr.subject as s -> r.subject = s;
  // The response's own time, as a floor. A row that names the time it was given
  // overwrites this; a form whose time column was taken off on review would
  // otherwise produce an administration with no time at all, which is not a
  // record of an administration. Same fallback BuildObsBase already applies.
  qr.authored as t -> r.occurence = t "occurrenceFallback";
}

group SetMedicationAdministrationFullUrl(source r : MedicationAdministration, target entry) {
  r.id as id -> entry.fullUrl = append('https://fhir.slade360.co.ke/fhir/MedicationAdministration/', 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 = 'anaesthetic-record' "provenanceCode";
      qr -> t.display = 'Anaesthetic record' "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";
}


Source1

{
  "resourceType": "StructureMap",
  "id": "ExtractAnaestheticRecord",
  "text": {
    "status": "generated",
    "div": "<!-- snip (see above) -->"
  },
  "url": "https://fhir.slade360.co.ke/fhir/StructureMap/ExtractAnaestheticRecord",
  "version": "0.1.0",
  "name": "ExtractAnaestheticRecord",
  "title": "Anaesthetic Record Extraction",
  "status": "active",
  "date": "2026-09-11T12:18:36+00:00",
  "publisher": "Kathurima Kimathi",
  "contact": [
    {
      "name": "Kathurima Kimathi",
      "telecom": [
        {
          "system": "url",
          "value": "https://www.linkedin.com/in/kathurima-kimathi/"
        },
        {
          "system": "email",
          "value": "kathurimakimathi415@gmail.com"
        }
      ]
    },
    {
      "name": "Oscar John",
      "telecom": [
        {
          "system": "email",
          "value": "oscarjohnotieno@gmail.com",
          "use": "work"
        }
      ]
    },
    {
      "name": "Kennedy Omondi",
      "telecom": [
        {
          "system": "email",
          "value": "kennankole@gmail.com",
          "use": "work"
        }
      ]
    }
  ],
  "description": "The anaesthetic chart out as: one Procedure for the anaesthesia itself, carrying the technique as its category, the anaesthetist as its performer and the start and completion times as its period; one Observation per timed reading taken through the case, each with its own effective time, because the paper chart is a graph and a graph is a time series; one MedicationAdministration per drug and per fluid, because those were given rather than ordered; and the estimated blood loss as its own Observation under the LOINC operation-note code, marked as an estimate.",
  "structure": [
    {
      "url": "http://hl7.org/fhir/StructureDefinition/QuestionnaireResponse",
      "mode": "source",
      "alias": "QR"
    },
    {
      "url": "http://hl7.org/fhir/StructureDefinition/Bundle",
      "mode": "target",
      "alias": "Bundle"
    },
    {
      "url": "http://hl7.org/fhir/StructureDefinition/Observation",
      "mode": "target",
      "alias": "Observation"
    },
    {
      "url": "http://hl7.org/fhir/StructureDefinition/Procedure",
      "mode": "target",
      "alias": "Procedure"
    },
    {
      "url": "http://hl7.org/fhir/StructureDefinition/MedicationAdministration",
      "mode": "target",
      "alias": "MedicationAdministration"
    }
  ],
  "group": [
    {
      "name": "ExtractAnaestheticRecord",
      "input": [
        {
          "name": "qr",
          "type": "QR",
          "mode": "source"
        },
        {
          "name": "bundle",
          "type": "Bundle",
          "mode": "target"
        }
      ],
      "rule": [
        {
          "name": "setBundleType",
          "source": [
            {
              "context": "qr"
            }
          ],
          "target": [
            {
              "context": "bundle",
              "element": "type",
              "transform": "copy",
              "parameter": [
                {
                  "valueString": "transaction"
                }
              ]
            }
          ]
        },
        {
          "name": "anaesthesiaProcedure",
          "source": [
            {
              "context": "qr",
              "element": "item",
              "variable": "g",
              "condition": "linkId = 'case'"
            }
          ],
          "target": [
            {
              "context": "bundle",
              "element": "entry",
              "variable": "entry"
            },
            {
              "context": "entry",
              "element": "resource",
              "variable": "proc",
              "transform": "create",
              "parameter": [
                {
                  "valueString": "Procedure"
                }
              ]
            }
          ],
          "rule": [
            {
              "name": "base",
              "source": [
                {
                  "context": "qr"
                }
              ],
              "target": [
                {
                  "context": "proc"
                },
                {
                  "context": "entry"
                }
              ],
              "dependent": [
                {
                  "name": "BuildProcedureBase",
                  "parameter": [
                    {
                      "valueId": "qr"
                    },
                    {
                      "valueId": "proc"
                    },
                    {
                      "valueId": "entry"
                    }
                  ]
                }
              ]
            },
            {
              "name": "status",
              "source": [
                {
                  "context": "g"
                }
              ],
              "target": [
                {
                  "context": "proc",
                  "element": "status",
                  "transform": "copy",
                  "parameter": [
                    {
                      "valueString": "completed"
                    }
                  ]
                }
              ]
            },
            {
              "name": "code",
              "source": [
                {
                  "context": "g"
                }
              ],
              "target": [
                {
                  "context": "proc",
                  "element": "code",
                  "variable": "cc"
                }
              ],
              "rule": [
                {
                  "name": "coding",
                  "source": [
                    {
                      "context": "g"
                    }
                  ],
                  "target": [
                    {
                      "context": "cc",
                      "element": "coding",
                      "variable": "cg"
                    }
                  ],
                  "rule": [
                    {
                      "name": "sys",
                      "source": [
                        {
                          "context": "g"
                        }
                      ],
                      "target": [
                        {
                          "context": "cg",
                          "element": "system",
                          "transform": "copy",
                          "parameter": [
                            {
                              "valueString": "http://snomed.info/sct"
                            }
                          ]
                        }
                      ]
                    },
                    {
                      "name": "cd",
                      "source": [
                        {
                          "context": "g"
                        }
                      ],
                      "target": [
                        {
                          "context": "cg",
                          "element": "code",
                          "transform": "copy",
                          "parameter": [
                            {
                              "valueString": "399097000"
                            }
                          ]
                        }
                      ]
                    },
                    {
                      "name": "dsp",
                      "source": [
                        {
                          "context": "g"
                        }
                      ],
                      "target": [
                        {
                          "context": "cg",
                          "element": "display",
                          "transform": "copy",
                          "parameter": [
                            {
                              "valueString": "Administration of anaesthesia"
                            }
                          ]
                        }
                      ]
                    }
                  ]
                }
              ]
            },
            {
              "name": "encounter",
              "source": [
                {
                  "context": "qr",
                  "element": "encounter",
                  "variable": "e"
                }
              ],
              "target": [
                {
                  "context": "proc",
                  "element": "encounter",
                  "transform": "copy",
                  "parameter": [
                    {
                      "valueId": "e"
                    }
                  ]
                }
              ]
            },
            {
              "name": "startRule",
              "source": [
                {
                  "context": "g",
                  "element": "item",
                  "variable": "st",
                  "condition": "(linkId = 'case/started') and answer.value.exists()"
                }
              ],
              "rule": [
                {
                  "name": "answer",
                  "source": [
                    {
                      "context": "st",
                      "element": "answer",
                      "listMode": "first",
                      "variable": "a"
                    }
                  ],
                  "rule": [
                    {
                      "name": "periodStart",
                      "source": [
                        {
                          "context": "a",
                          "element": "value",
                          "variable": "t"
                        }
                      ],
                      "target": [
                        {
                          "context": "proc",
                          "element": "occurrence",
                          "variable": "per",
                          "transform": "create",
                          "parameter": [
                            {
                              "valueString": "Period"
                            }
                          ]
                        },
                        {
                          "context": "per",
                          "element": "start",
                          "transform": "copy",
                          "parameter": [
                            {
                              "valueId": "t"
                            }
                          ]
                        }
                      ]
                    }
                  ]
                }
              ],
              "documentation": "Start and completion as a Period. Both, when both are given: the duration\r\nis what an audit reads, and it can only be derived if both ends are there."
            },
            {
              "name": "anaesthetistRule",
              "source": [
                {
                  "context": "g",
                  "element": "item",
                  "variable": "an",
                  "condition": "(linkId = 'case/anaesthetist') and answer.value.exists()"
                }
              ],
              "rule": [
                {
                  "name": "answer",
                  "source": [
                    {
                      "context": "an",
                      "element": "answer",
                      "listMode": "first",
                      "variable": "a"
                    }
                  ],
                  "rule": [
                    {
                      "name": "performer",
                      "source": [
                        {
                          "context": "a",
                          "element": "value",
                          "variable": "ref"
                        }
                      ],
                      "target": [
                        {
                          "context": "proc",
                          "element": "performer",
                          "variable": "p"
                        }
                      ],
                      "rule": [
                        {
                          "name": "actor",
                          "source": [
                            {
                              "context": "ref"
                            }
                          ],
                          "target": [
                            {
                              "context": "p",
                              "element": "actor",
                              "transform": "copy",
                              "parameter": [
                                {
                                  "valueId": "ref"
                                }
                              ]
                            }
                          ]
                        },
                        {
                          "name": "function",
                          "source": [
                            {
                              "context": "ref"
                            }
                          ],
                          "target": [
                            {
                              "context": "p",
                              "element": "function",
                              "variable": "fn"
                            }
                          ],
                          "rule": [
                            {
                              "name": "coding",
                              "source": [
                                {
                                  "context": "ref"
                                }
                              ],
                              "target": [
                                {
                                  "context": "fn",
                                  "element": "coding",
                                  "variable": "fcg"
                                }
                              ],
                              "rule": [
                                {
                                  "name": "sys",
                                  "source": [
                                    {
                                      "context": "ref"
                                    }
                                  ],
                                  "target": [
                                    {
                                      "context": "fcg",
                                      "element": "system",
                                      "transform": "copy",
                                      "parameter": [
                                        {
                                          "valueString": "https://fhir.slade360.co.ke/fhir/CodeSystem/practitioner-specialty-codesystem"
                                        }
                                      ]
                                    }
                                  ]
                                },
                                {
                                  "name": "cd",
                                  "source": [
                                    {
                                      "context": "ref"
                                    }
                                  ],
                                  "target": [
                                    {
                                      "context": "fcg",
                                      "element": "code",
                                      "transform": "copy",
                                      "parameter": [
                                        {
                                          "valueString": "anaesthesia"
                                        }
                                      ]
                                    }
                                  ]
                                }
                              ]
                            }
                          ]
                        }
                      ]
                    }
                  ]
                }
              ]
            },
            {
              "name": "surgeonRule",
              "source": [
                {
                  "context": "g",
                  "element": "item",
                  "variable": "sg",
                  "condition": "(linkId = 'case/surgeon') and answer.value.exists()"
                }
              ],
              "rule": [
                {
                  "name": "answer",
                  "source": [
                    {
                      "context": "sg",
                      "element": "answer",
                      "listMode": "first",
                      "variable": "a"
                    }
                  ],
                  "rule": [
                    {
                      "name": "performer",
                      "source": [
                        {
                          "context": "a",
                          "element": "value",
                          "variable": "ref"
                        }
                      ],
                      "target": [
                        {
                          "context": "proc",
                          "element": "performer",
                          "variable": "p"
                        }
                      ],
                      "rule": [
                        {
                          "name": "actor",
                          "source": [
                            {
                              "context": "ref"
                            }
                          ],
                          "target": [
                            {
                              "context": "p",
                              "element": "actor",
                              "transform": "copy",
                              "parameter": [
                                {
                                  "valueId": "ref"
                                }
                              ]
                            }
                          ]
                        },
                        {
                          "name": "function",
                          "source": [
                            {
                              "context": "ref"
                            }
                          ],
                          "target": [
                            {
                              "context": "p",
                              "element": "function",
                              "variable": "fn"
                            }
                          ],
                          "rule": [
                            {
                              "name": "coding",
                              "source": [
                                {
                                  "context": "ref"
                                }
                              ],
                              "target": [
                                {
                                  "context": "fn",
                                  "element": "coding",
                                  "variable": "fcg"
                                }
                              ],
                              "rule": [
                                {
                                  "name": "sys",
                                  "source": [
                                    {
                                      "context": "ref"
                                    }
                                  ],
                                  "target": [
                                    {
                                      "context": "fcg",
                                      "element": "system",
                                      "transform": "copy",
                                      "parameter": [
                                        {
                                          "valueString": "https://fhir.slade360.co.ke/fhir/CodeSystem/practitioner-specialty-codesystem"
                                        }
                                      ]
                                    }
                                  ]
                                },
                                {
                                  "name": "cd",
                                  "source": [
                                    {
                                      "context": "ref"
                                    }
                                  ],
                                  "target": [
                                    {
                                      "context": "fcg",
                                      "element": "code",
                                      "transform": "copy",
                                      "parameter": [
                                        {
                                          "valueString": "general-surgery"
                                        }
                                      ]
                                    }
                                  ]
                                }
                              ]
                            }
                          ]
                        }
                      ]
                    }
                  ]
                }
              ]
            },
            {
              "name": "scrubNurseRule",
              "source": [
                {
                  "context": "g",
                  "element": "item",
                  "variable": "sn",
                  "condition": "(linkId = 'case/scrub-nurse') and answer.value.exists()"
                }
              ],
              "rule": [
                {
                  "name": "answer",
                  "source": [
                    {
                      "context": "sn",
                      "element": "answer",
                      "listMode": "first",
                      "variable": "a"
                    }
                  ],
                  "rule": [
                    {
                      "name": "scrubNurse",
                      "source": [
                        {
                          "context": "a",
                          "element": "value",
                          "variable": "ref"
                        }
                      ],
                      "target": [
                        {
                          "context": "proc",
                          "element": "performer",
                          "variable": "p"
                        },
                        {
                          "context": "p",
                          "element": "actor",
                          "transform": "copy",
                          "parameter": [
                            {
                              "valueId": "ref"
                            }
                          ]
                        }
                      ]
                    }
                  ]
                }
              ]
            },
            {
              "name": "typeOfSurgeryRule",
              "source": [
                {
                  "context": "g",
                  "element": "item",
                  "variable": "ts",
                  "condition": "(linkId = 'case/type-of-surgery') and answer.value.exists()"
                }
              ],
              "rule": [
                {
                  "name": "answer",
                  "source": [
                    {
                      "context": "ts",
                      "element": "answer",
                      "listMode": "first",
                      "variable": "a"
                    }
                  ],
                  "rule": [
                    {
                      "name": "reasonText",
                      "source": [
                        {
                          "context": "a",
                          "element": "value",
                          "variable": "txt"
                        }
                      ],
                      "target": [
                        {
                          "context": "proc",
                          "element": "reason",
                          "variable": "rsn"
                        },
                        {
                          "context": "rsn",
                          "element": "concept",
                          "variable": "rc"
                        },
                        {
                          "context": "rc",
                          "element": "text",
                          "transform": "copy",
                          "parameter": [
                            {
                              "valueId": "txt"
                            }
                          ]
                        }
                      ]
                    }
                  ]
                }
              ],
              "documentation": "Type of surgery goes to Procedure.reason: this anaesthetic was given in\r\norder to allow that operation. Free text, because the theatre list is not\r\na coded catalogue here."
            },
            {
              "name": "diagnosisRule",
              "source": [
                {
                  "context": "g",
                  "element": "item",
                  "variable": "dx",
                  "condition": "(linkId = 'case/diagnosis') and answer.value.exists()"
                }
              ],
              "rule": [
                {
                  "name": "answer",
                  "source": [
                    {
                      "context": "dx",
                      "element": "answer",
                      "listMode": "first",
                      "variable": "a"
                    }
                  ],
                  "rule": [
                    {
                      "name": "diagnosisNote",
                      "source": [
                        {
                          "context": "a",
                          "element": "value",
                          "variable": "txt"
                        }
                      ],
                      "target": [
                        {
                          "context": "proc",
                          "element": "note",
                          "variable": "n"
                        },
                        {
                          "context": "n",
                          "element": "text",
                          "transform": "copy",
                          "parameter": [
                            {
                              "valueId": "txt"
                            }
                          ]
                        }
                      ]
                    }
                  ]
                }
              ]
            },
            {
              "name": "techniqueGroup",
              "source": [
                {
                  "context": "qr",
                  "element": "item",
                  "variable": "tg",
                  "condition": "linkId = 'technique'"
                }
              ],
              "rule": [
                {
                  "name": "techniqueTypeRule",
                  "source": [
                    {
                      "context": "tg",
                      "element": "item",
                      "variable": "it",
                      "condition": "(linkId = 'technique/type') and answer.value.exists()"
                    }
                  ],
                  "rule": [
                    {
                      "name": "answer",
                      "source": [
                        {
                          "context": "it",
                          "element": "answer",
                          "listMode": "first",
                          "variable": "a"
                        }
                      ],
                      "rule": [
                        {
                          "name": "category",
                          "source": [
                            {
                              "context": "a",
                              "element": "value",
                              "variable": "cv"
                            }
                          ],
                          "target": [
                            {
                              "context": "proc",
                              "element": "category",
                              "variable": "cat"
                            }
                          ],
                          "rule": [
                            {
                              "name": "categoryCoding",
                              "source": [
                                {
                                  "context": "cv"
                                }
                              ],
                              "target": [
                                {
                                  "context": "cat",
                                  "element": "coding",
                                  "transform": "copy",
                                  "parameter": [
                                    {
                                      "valueId": "cv"
                                    }
                                  ]
                                }
                              ]
                            },
                            {
                              "name": "categoryText",
                              "source": [
                                {
                                  "context": "cv",
                                  "element": "display",
                                  "variable": "d"
                                }
                              ],
                              "target": [
                                {
                                  "context": "cat",
                                  "element": "text",
                                  "transform": "copy",
                                  "parameter": [
                                    {
                                      "valueId": "d"
                                    }
                                  ]
                                }
                              ]
                            }
                          ]
                        }
                      ]
                    }
                  ]
                },
                {
                  "name": "technique_premedication",
                  "source": [
                    {
                      "context": "tg",
                      "element": "item",
                      "variable": "it",
                      "condition": "linkId = 'technique/premedication'"
                    }
                  ],
                  "rule": [
                    {
                      "name": "answer",
                      "source": [
                        {
                          "context": "it",
                          "element": "answer",
                          "listMode": "first",
                          "variable": "a"
                        }
                      ],
                      "rule": [
                        {
                          "name": "note",
                          "source": [
                            {
                              "context": "a",
                              "element": "value",
                              "variable": "txt"
                            }
                          ],
                          "target": [
                            {
                              "context": "proc",
                              "element": "note",
                              "variable": "n"
                            },
                            {
                              "context": "n",
                              "element": "text",
                              "transform": "copy",
                              "parameter": [
                                {
                                  "valueId": "txt"
                                }
                              ]
                            }
                          ]
                        }
                      ]
                    }
                  ]
                },
                {
                  "name": "technique_induction",
                  "source": [
                    {
                      "context": "tg",
                      "element": "item",
                      "variable": "it",
                      "condition": "linkId = 'technique/induction'"
                    }
                  ],
                  "rule": [
                    {
                      "name": "answer",
                      "source": [
                        {
                          "context": "it",
                          "element": "answer",
                          "listMode": "first",
                          "variable": "a"
                        }
                      ],
                      "rule": [
                        {
                          "name": "note",
                          "source": [
                            {
                              "context": "a",
                              "element": "value",
                              "variable": "txt"
                            }
                          ],
                          "target": [
                            {
                              "context": "proc",
                              "element": "note",
                              "variable": "n"
                            },
                            {
                              "context": "n",
                              "element": "text",
                              "transform": "copy",
                              "parameter": [
                                {
                                  "valueId": "txt"
                                }
                              ]
                            }
                          ]
                        }
                      ]
                    }
                  ]
                },
                {
                  "name": "technique_maintenance",
                  "source": [
                    {
                      "context": "tg",
                      "element": "item",
                      "variable": "it",
                      "condition": "linkId = 'technique/maintenance'"
                    }
                  ],
                  "rule": [
                    {
                      "name": "answer",
                      "source": [
                        {
                          "context": "it",
                          "element": "answer",
                          "listMode": "first",
                          "variable": "a"
                        }
                      ],
                      "rule": [
                        {
                          "name": "note",
                          "source": [
                            {
                              "context": "a",
                              "element": "value",
                              "variable": "txt"
                            }
                          ],
                          "target": [
                            {
                              "context": "proc",
                              "element": "note",
                              "variable": "n"
                            },
                            {
                              "context": "n",
                              "element": "text",
                              "transform": "copy",
                              "parameter": [
                                {
                                  "valueId": "txt"
                                }
                              ]
                            }
                          ]
                        }
                      ]
                    }
                  ]
                },
                {
                  "name": "technique_position",
                  "source": [
                    {
                      "context": "tg",
                      "element": "item",
                      "variable": "it",
                      "condition": "linkId = 'technique/position'"
                    }
                  ],
                  "rule": [
                    {
                      "name": "answer",
                      "source": [
                        {
                          "context": "it",
                          "element": "answer",
                          "listMode": "first",
                          "variable": "a"
                        }
                      ],
                      "rule": [
                        {
                          "name": "note",
                          "source": [
                            {
                              "context": "a",
                              "element": "value",
                              "variable": "txt"
                            }
                          ],
                          "target": [
                            {
                              "context": "proc",
                              "element": "note",
                              "variable": "n"
                            },
                            {
                              "context": "n",
                              "element": "text",
                              "transform": "copy",
                              "parameter": [
                                {
                                  "valueId": "txt"
                                }
                              ]
                            }
                          ]
                        }
                      ]
                    }
                  ]
                }
              ],
              "documentation": "Technique as Procedure.category, and the agents as notes. The agents are\r\nfree text on the chart -- \"propofol / sevo / fentanyl\" on one line -- and\r\nsplitting that into MedicationAdministrations would invent doses."
            },
            {
              "name": "outcomeGroup",
              "source": [
                {
                  "context": "qr",
                  "element": "item",
                  "variable": "og",
                  "condition": "linkId = 'outcome'"
                }
              ],
              "rule": [
                {
                  "name": "outcomeRule",
                  "source": [
                    {
                      "context": "og",
                      "element": "item",
                      "variable": "it",
                      "condition": "(linkId = 'outcome/result-and-remarks') and answer.value.exists()"
                    }
                  ],
                  "rule": [
                    {
                      "name": "answer",
                      "source": [
                        {
                          "context": "it",
                          "element": "answer",
                          "listMode": "first",
                          "variable": "a"
                        }
                      ],
                      "rule": [
                        {
                          "name": "outcomeText",
                          "source": [
                            {
                              "context": "a",
                              "element": "value",
                              "variable": "txt"
                            }
                          ],
                          "target": [
                            {
                              "context": "proc",
                              "element": "outcome",
                              "variable": "oc"
                            },
                            {
                              "context": "oc",
                              "element": "text",
                              "transform": "copy",
                              "parameter": [
                                {
                                  "valueId": "txt"
                                }
                              ]
                            }
                          ]
                        }
                      ]
                    }
                  ]
                },
                {
                  "name": "reversalRule",
                  "source": [
                    {
                      "context": "og",
                      "element": "item",
                      "variable": "it",
                      "condition": "(linkId = 'outcome/reversal-notes') and answer.value.exists()"
                    }
                  ],
                  "rule": [
                    {
                      "name": "answer",
                      "source": [
                        {
                          "context": "it",
                          "element": "answer",
                          "listMode": "first",
                          "variable": "a"
                        }
                      ],
                      "rule": [
                        {
                          "name": "reversalText",
                          "source": [
                            {
                              "context": "a",
                              "element": "value",
                              "variable": "txt"
                            }
                          ],
                          "target": [
                            {
                              "context": "proc",
                              "element": "followUp",
                              "variable": "fu"
                            },
                            {
                              "context": "fu",
                              "element": "text",
                              "transform": "copy",
                              "parameter": [
                                {
                                  "valueId": "txt"
                                }
                              ]
                            }
                          ]
                        }
                      ]
                    }
                  ]
                },
                {
                  "name": "instructionsRule",
                  "source": [
                    {
                      "context": "og",
                      "element": "item",
                      "variable": "it",
                      "condition": "(linkId = 'outcome/post-operative-instructions') and answer.value.exists()"
                    }
                  ],
                  "rule": [
                    {
                      "name": "answer",
                      "source": [
                        {
                          "context": "it",
                          "element": "answer",
                          "listMode": "first",
                          "variable": "a"
                        }
                      ],
                      "rule": [
                        {
                          "name": "instructionsText",
                          "source": [
                            {
                              "context": "a",
                              "element": "value",
                              "variable": "txt"
                            }
                          ],
                          "target": [
                            {
                              "context": "proc",
                              "element": "followUp",
                              "variable": "fu"
                            },
                            {
                              "context": "fu",
                              "element": "text",
                              "transform": "copy",
                              "parameter": [
                                {
                                  "valueId": "txt"
                                }
                              ]
                            }
                          ]
                        }
                      ]
                    }
                  ]
                }
              ],
              "documentation": "The outcome sections. `outcome` takes the result of the operation;\r\nreversal and post-operative instructions are what recovery has to act\r\non, so they are followUp rather than notes -- a note is read, a followUp\r\nis a stated instruction."
            }
          ],
          "documentation": "── The anaesthesia, as a Procedure ─────────────────────────────────────\r\nSNOMED 399097000, administration of anaesthesia, which was checked against\r\ntx.fhir.org. The technique -- general, spinal, block, sedation, local --\r\nbecomes Procedure.category, because it classifies the procedure rather than\r\nbeing a separate finding about it.\r\nThe performer is the anaesthetist named on the chart, not the response's\r\nsource: an anaesthetic record is sometimes written up by someone else, and\r\nattributing the anaesthetic to the transcriber would be wrong."
        },
        {
          "name": "intraOperativeReading",
          "source": [
            {
              "context": "qr",
              "element": "item",
              "variable": "g",
              "condition": "(linkId = 'observation') and item.answer.value.exists()"
            }
          ],
          "target": [
            {
              "context": "bundle",
              "element": "entry",
              "variable": "entry"
            },
            {
              "context": "entry",
              "element": "resource",
              "variable": "obs",
              "transform": "create",
              "parameter": [
                {
                  "valueString": "Observation"
                }
              ]
            }
          ],
          "rule": [
            {
              "name": "base",
              "source": [
                {
                  "context": "qr"
                }
              ],
              "target": [
                {
                  "context": "obs"
                },
                {
                  "context": "entry"
                }
              ],
              "dependent": [
                {
                  "name": "BuildObsBase",
                  "parameter": [
                    {
                      "valueId": "qr"
                    },
                    {
                      "valueId": "obs"
                    },
                    {
                      "valueId": "entry"
                    }
                  ]
                }
              ]
            },
            {
              "name": "category",
              "source": [
                {
                  "context": "qr"
                }
              ],
              "target": [
                {
                  "context": "obs"
                }
              ],
              "dependent": [
                {
                  "name": "SetVitalSignsCategory",
                  "parameter": [
                    {
                      "valueId": "qr"
                    },
                    {
                      "valueId": "obs"
                    }
                  ]
                }
              ]
            },
            {
              "name": "code",
              "source": [
                {
                  "context": "g"
                }
              ],
              "target": [
                {
                  "context": "obs",
                  "element": "code",
                  "variable": "cc"
                }
              ],
              "rule": [
                {
                  "name": "coding",
                  "source": [
                    {
                      "context": "g"
                    }
                  ],
                  "target": [
                    {
                      "context": "cc",
                      "element": "coding",
                      "variable": "cg"
                    }
                  ],
                  "rule": [
                    {
                      "name": "sys",
                      "source": [
                        {
                          "context": "g"
                        }
                      ],
                      "target": [
                        {
                          "context": "cg",
                          "element": "system",
                          "transform": "copy",
                          "parameter": [
                            {
                              "valueString": "http://loinc.org"
                            }
                          ]
                        }
                      ]
                    },
                    {
                      "name": "cd",
                      "source": [
                        {
                          "context": "g"
                        }
                      ],
                      "target": [
                        {
                          "context": "cg",
                          "element": "code",
                          "transform": "copy",
                          "parameter": [
                            {
                              "valueString": "8716-3"
                            }
                          ]
                        }
                      ]
                    },
                    {
                      "name": "dsp",
                      "source": [
                        {
                          "context": "g"
                        }
                      ],
                      "target": [
                        {
                          "context": "cg",
                          "element": "display",
                          "transform": "copy",
                          "parameter": [
                            {
                              "valueString": "Vital signs note"
                            }
                          ]
                        }
                      ]
                    }
                  ]
                },
                {
                  "name": "codeText",
                  "source": [
                    {
                      "context": "g"
                    }
                  ],
                  "target": [
                    {
                      "context": "cc",
                      "element": "text",
                      "transform": "copy",
                      "parameter": [
                        {
                          "valueString": "Observation during anaesthesia"
                        }
                      ]
                    }
                  ]
                }
              ]
            },
            {
              "name": "readingTimeRule",
              "source": [
                {
                  "context": "g",
                  "element": "item",
                  "variable": "tm",
                  "condition": "(linkId = 'observation/time') and answer.value.exists()"
                }
              ],
              "rule": [
                {
                  "name": "answer",
                  "source": [
                    {
                      "context": "tm",
                      "element": "answer",
                      "listMode": "first",
                      "variable": "a"
                    }
                  ],
                  "rule": [
                    {
                      "name": "timeNote",
                      "source": [
                        {
                          "context": "a",
                          "element": "value",
                          "variable": "t"
                        }
                      ],
                      "target": [
                        {
                          "context": "obs",
                          "element": "note",
                          "variable": "n"
                        },
                        {
                          "context": "n",
                          "element": "text",
                          "transform": "copy",
                          "parameter": [
                            {
                              "valueString": "Reading taken at the time recorded on the anaesthetic chart"
                            }
                          ]
                        }
                      ]
                    }
                  ]
                }
              ]
            },
            {
              "name": "comp_8480_6",
              "source": [
                {
                  "context": "g",
                  "element": "item",
                  "variable": "it",
                  "condition": "(linkId = 'observation/systolic') and answer.value.exists()"
                }
              ],
              "target": [
                {
                  "context": "obs",
                  "element": "component",
                  "variable": "comp"
                }
              ],
              "rule": [
                {
                  "name": "code",
                  "source": [
                    {
                      "context": "it"
                    }
                  ],
                  "target": [
                    {
                      "context": "comp",
                      "element": "code",
                      "variable": "cc"
                    }
                  ],
                  "rule": [
                    {
                      "name": "coding",
                      "source": [
                        {
                          "context": "it"
                        }
                      ],
                      "target": [
                        {
                          "context": "cc",
                          "element": "coding",
                          "variable": "cg"
                        }
                      ],
                      "rule": [
                        {
                          "name": "sys",
                          "source": [
                            {
                              "context": "it"
                            }
                          ],
                          "target": [
                            {
                              "context": "cg",
                              "element": "system",
                              "transform": "copy",
                              "parameter": [
                                {
                                  "valueString": "http://loinc.org"
                                }
                              ]
                            }
                          ]
                        },
                        {
                          "name": "cd",
                          "source": [
                            {
                              "context": "it"
                            }
                          ],
                          "target": [
                            {
                              "context": "cg",
                              "element": "code",
                              "transform": "copy",
                              "parameter": [
                                {
                                  "valueString": "8480-6"
                                }
                              ]
                            }
                          ]
                        },
                        {
                          "name": "dsp",
                          "source": [
                            {
                              "context": "it"
                            }
                          ],
                          "target": [
                            {
                              "context": "cg",
                              "element": "display",
                              "transform": "copy",
                              "parameter": [
                                {
                                  "valueString": "Systolic blood pressure"
                                }
                              ]
                            }
                          ]
                        }
                      ]
                    }
                  ]
                },
                {
                  "name": "value",
                  "source": [
                    {
                      "context": "it"
                    }
                  ],
                  "target": [
                    {
                      "context": "comp"
                    }
                  ],
                  "dependent": [
                    {
                      "name": "SetComponentValue",
                      "parameter": [
                        {
                          "valueId": "it"
                        },
                        {
                          "valueId": "comp"
                        }
                      ]
                    }
                  ]
                }
              ]
            },
            {
              "name": "comp_8462_4",
              "source": [
                {
                  "context": "g",
                  "element": "item",
                  "variable": "it",
                  "condition": "(linkId = 'observation/diastolic') and answer.value.exists()"
                }
              ],
              "target": [
                {
                  "context": "obs",
                  "element": "component",
                  "variable": "comp"
                }
              ],
              "rule": [
                {
                  "name": "code",
                  "source": [
                    {
                      "context": "it"
                    }
                  ],
                  "target": [
                    {
                      "context": "comp",
                      "element": "code",
                      "variable": "cc"
                    }
                  ],
                  "rule": [
                    {
                      "name": "coding",
                      "source": [
                        {
                          "context": "it"
                        }
                      ],
                      "target": [
                        {
                          "context": "cc",
                          "element": "coding",
                          "variable": "cg"
                        }
                      ],
                      "rule": [
                        {
                          "name": "sys",
                          "source": [
                            {
                              "context": "it"
                            }
                          ],
                          "target": [
                            {
                              "context": "cg",
                              "element": "system",
                              "transform": "copy",
                              "parameter": [
                                {
                                  "valueString": "http://loinc.org"
                                }
                              ]
                            }
                          ]
                        },
                        {
                          "name": "cd",
                          "source": [
                            {
                              "context": "it"
                            }
                          ],
                          "target": [
                            {
                              "context": "cg",
                              "element": "code",
                              "transform": "copy",
                              "parameter": [
                                {
                                  "valueString": "8462-4"
                                }
                              ]
                            }
                          ]
                        },
                        {
                          "name": "dsp",
                          "source": [
                            {
                              "context": "it"
                            }
                          ],
                          "target": [
                            {
                              "context": "cg",
                              "element": "display",
                              "transform": "copy",
                              "parameter": [
                                {
                                  "valueString": "Diastolic blood pressure"
                                }
                              ]
                            }
                          ]
                        }
                      ]
                    }
                  ]
                },
                {
                  "name": "value",
                  "source": [
                    {
                      "context": "it"
                    }
                  ],
                  "target": [
                    {
                      "context": "comp"
                    }
                  ],
                  "dependent": [
                    {
                      "name": "SetComponentValue",
                      "parameter": [
                        {
                          "valueId": "it"
                        },
                        {
                          "valueId": "comp"
                        }
                      ]
                    }
                  ]
                }
              ]
            },
            {
              "name": "comp_8867_4",
              "source": [
                {
                  "context": "g",
                  "element": "item",
                  "variable": "it",
                  "condition": "(linkId = 'observation/pulse') and answer.value.exists()"
                }
              ],
              "target": [
                {
                  "context": "obs",
                  "element": "component",
                  "variable": "comp"
                }
              ],
              "rule": [
                {
                  "name": "code",
                  "source": [
                    {
                      "context": "it"
                    }
                  ],
                  "target": [
                    {
                      "context": "comp",
                      "element": "code",
                      "variable": "cc"
                    }
                  ],
                  "rule": [
                    {
                      "name": "coding",
                      "source": [
                        {
                          "context": "it"
                        }
                      ],
                      "target": [
                        {
                          "context": "cc",
                          "element": "coding",
                          "variable": "cg"
                        }
                      ],
                      "rule": [
                        {
                          "name": "sys",
                          "source": [
                            {
                              "context": "it"
                            }
                          ],
                          "target": [
                            {
                              "context": "cg",
                              "element": "system",
                              "transform": "copy",
                              "parameter": [
                                {
                                  "valueString": "http://loinc.org"
                                }
                              ]
                            }
                          ]
                        },
                        {
                          "name": "cd",
                          "source": [
                            {
                              "context": "it"
                            }
                          ],
                          "target": [
                            {
                              "context": "cg",
                              "element": "code",
                              "transform": "copy",
                              "parameter": [
                                {
                                  "valueString": "8867-4"
                                }
                              ]
                            }
                          ]
                        },
                        {
                          "name": "dsp",
                          "source": [
                            {
                              "context": "it"
                            }
                          ],
                          "target": [
                            {
                              "context": "cg",
                              "element": "display",
                              "transform": "copy",
                              "parameter": [
                                {
                                  "valueString": "Heart rate"
                                }
                              ]
                            }
                          ]
                        }
                      ]
                    }
                  ]
                },
                {
                  "name": "value",
                  "source": [
                    {
                      "context": "it"
                    }
                  ],
                  "target": [
                    {
                      "context": "comp"
                    }
                  ],
                  "dependent": [
                    {
                      "name": "SetComponentValue",
                      "parameter": [
                        {
                          "valueId": "it"
                        },
                        {
                          "valueId": "comp"
                        }
                      ]
                    }
                  ]
                }
              ]
            },
            {
              "name": "comp_59408_5",
              "source": [
                {
                  "context": "g",
                  "element": "item",
                  "variable": "it",
                  "condition": "(linkId = 'observation/oxygen-saturation') and answer.value.exists()"
                }
              ],
              "target": [
                {
                  "context": "obs",
                  "element": "component",
                  "variable": "comp"
                }
              ],
              "rule": [
                {
                  "name": "code",
                  "source": [
                    {
                      "context": "it"
                    }
                  ],
                  "target": [
                    {
                      "context": "comp",
                      "element": "code",
                      "variable": "cc"
                    }
                  ],
                  "rule": [
                    {
                      "name": "coding",
                      "source": [
                        {
                          "context": "it"
                        }
                      ],
                      "target": [
                        {
                          "context": "cc",
                          "element": "coding",
                          "variable": "cg"
                        }
                      ],
                      "rule": [
                        {
                          "name": "sys",
                          "source": [
                            {
                              "context": "it"
                            }
                          ],
                          "target": [
                            {
                              "context": "cg",
                              "element": "system",
                              "transform": "copy",
                              "parameter": [
                                {
                                  "valueString": "http://loinc.org"
                                }
                              ]
                            }
                          ]
                        },
                        {
                          "name": "cd",
                          "source": [
                            {
                              "context": "it"
                            }
                          ],
                          "target": [
                            {
                              "context": "cg",
                              "element": "code",
                              "transform": "copy",
                              "parameter": [
                                {
                                  "valueString": "59408-5"
                                }
                              ]
                            }
                          ]
                        },
                        {
                          "name": "dsp",
                          "source": [
                            {
                              "context": "it"
                            }
                          ],
                          "target": [
                            {
                              "context": "cg",
                              "element": "display",
                              "transform": "copy",
                              "parameter": [
                                {
                                  "valueString": "Oxygen saturation in Arterial blood by Pulse oximetry"
                                }
                              ]
                            }
                          ]
                        }
                      ]
                    }
                  ]
                },
                {
                  "name": "value",
                  "source": [
                    {
                      "context": "it"
                    }
                  ],
                  "target": [
                    {
                      "context": "comp"
                    }
                  ],
                  "dependent": [
                    {
                      "name": "SetComponentValue",
                      "parameter": [
                        {
                          "valueId": "it"
                        },
                        {
                          "valueId": "comp"
                        }
                      ]
                    }
                  ]
                }
              ]
            }
          ],
          "documentation": "── The observations taken through the case ─────────────────────────────\r\nOne Observation per reading, each with the reading's own time as its\r\neffective time. The chart is a graph at half-hourly gridlines; collapsing\r\nit into one Observation with thirty components would lose the axis the\r\ngraph exists for.\r\nThe time on the chart is a clock time with no date. It is written to\r\nObservation.effective as given; the case's own date is on the Procedure\r\nthis Observation sits beside, and inventing a date here would be a guess\r\nthat reads as a fact."
        },
        {
          "name": "drugAdministration",
          "source": [
            {
              "context": "qr",
              "element": "item",
              "variable": "g",
              "condition": "(linkId = 'drug') and item.where(linkId = 'drug/name').answer.value.exists()"
            }
          ],
          "target": [
            {
              "context": "bundle",
              "element": "entry",
              "variable": "entry"
            },
            {
              "context": "entry",
              "element": "resource",
              "variable": "ma",
              "transform": "create",
              "parameter": [
                {
                  "valueString": "MedicationAdministration"
                }
              ]
            }
          ],
          "rule": [
            {
              "name": "base",
              "source": [
                {
                  "context": "qr"
                }
              ],
              "target": [
                {
                  "context": "ma"
                },
                {
                  "context": "entry"
                }
              ],
              "dependent": [
                {
                  "name": "BuildMedicationAdministrationBase",
                  "parameter": [
                    {
                      "valueId": "qr"
                    },
                    {
                      "valueId": "ma"
                    },
                    {
                      "valueId": "entry"
                    }
                  ]
                }
              ]
            },
            {
              "name": "status",
              "source": [
                {
                  "context": "g"
                }
              ],
              "target": [
                {
                  "context": "ma",
                  "element": "status",
                  "transform": "copy",
                  "parameter": [
                    {
                      "valueString": "completed"
                    }
                  ]
                }
              ]
            },
            {
              "name": "encounter",
              "source": [
                {
                  "context": "qr",
                  "element": "encounter",
                  "variable": "e"
                }
              ],
              "target": [
                {
                  "context": "ma",
                  "element": "encounter",
                  "transform": "copy",
                  "parameter": [
                    {
                      "valueId": "e"
                    }
                  ]
                }
              ]
            },
            {
              "name": "performer",
              "source": [
                {
                  "context": "qr",
                  "element": "source",
                  "variable": "src"
                }
              ],
              "target": [
                {
                  "context": "ma",
                  "element": "performer",
                  "variable": "p"
                },
                {
                  "context": "p",
                  "element": "actor",
                  "variable": "cr",
                  "transform": "create",
                  "parameter": [
                    {
                      "valueString": "CodeableReference"
                    }
                  ]
                },
                {
                  "context": "cr",
                  "element": "reference",
                  "transform": "copy",
                  "parameter": [
                    {
                      "valueId": "src"
                    }
                  ]
                }
              ]
            },
            {
              "name": "drugNameRule",
              "source": [
                {
                  "context": "g",
                  "element": "item",
                  "variable": "it",
                  "condition": "linkId = 'drug/name'"
                }
              ],
              "rule": [
                {
                  "name": "answer",
                  "source": [
                    {
                      "context": "it",
                      "element": "answer",
                      "listMode": "first",
                      "variable": "a"
                    }
                  ],
                  "rule": [
                    {
                      "name": "medicationText",
                      "source": [
                        {
                          "context": "a",
                          "element": "value",
                          "variable": "txt"
                        }
                      ],
                      "target": [
                        {
                          "context": "ma",
                          "element": "medication",
                          "variable": "med"
                        },
                        {
                          "context": "med",
                          "element": "concept",
                          "variable": "mc"
                        },
                        {
                          "context": "mc",
                          "element": "text",
                          "transform": "copy",
                          "parameter": [
                            {
                              "valueId": "txt"
                            }
                          ]
                        }
                      ]
                    }
                  ]
                }
              ]
            },
            {
              "name": "drugDoseRule",
              "source": [
                {
                  "context": "g",
                  "element": "item",
                  "variable": "it",
                  "condition": "(linkId = 'drug/dose') and answer.value.exists()"
                }
              ],
              "rule": [
                {
                  "name": "answer",
                  "source": [
                    {
                      "context": "it",
                      "element": "answer",
                      "listMode": "first",
                      "variable": "a"
                    }
                  ],
                  "rule": [
                    {
                      "name": "dosageText",
                      "source": [
                        {
                          "context": "a",
                          "element": "value",
                          "variable": "txt"
                        }
                      ],
                      "target": [
                        {
                          "context": "ma",
                          "element": "dosage",
                          "variable": "dos"
                        },
                        {
                          "context": "dos",
                          "element": "text",
                          "transform": "copy",
                          "parameter": [
                            {
                              "valueId": "txt"
                            }
                          ]
                        }
                      ]
                    }
                  ]
                }
              ]
            },
            {
              "name": "drugTimeRule",
              "source": [
                {
                  "context": "g",
                  "element": "item",
                  "variable": "it",
                  "condition": "(linkId = 'drug/time') and answer.value.exists()"
                }
              ],
              "rule": [
                {
                  "name": "answer",
                  "source": [
                    {
                      "context": "it",
                      "element": "answer",
                      "listMode": "first",
                      "variable": "a"
                    }
                  ],
                  "rule": [
                    {
                      "name": "timeNote",
                      "source": [
                        {
                          "context": "a",
                          "element": "value",
                          "variable": "t"
                        }
                      ],
                      "target": [
                        {
                          "context": "ma",
                          "element": "note",
                          "variable": "n"
                        },
                        {
                          "context": "n",
                          "element": "text",
                          "transform": "copy",
                          "parameter": [
                            {
                              "valueString": "Given at the time recorded on the anaesthetic chart"
                            }
                          ]
                        }
                      ]
                    }
                  ]
                }
              ]
            },
            {
              "name": "occurrence",
              "source": [
                {
                  "context": "qr",
                  "element": "authored",
                  "variable": "t"
                }
              ],
              "target": [
                {
                  "context": "ma",
                  "element": "occurence",
                  "transform": "copy",
                  "parameter": [
                    {
                      "valueId": "t"
                    }
                  ]
                }
              ]
            }
          ],
          "documentation": "── Drugs and fluids given ──────────────────────────────────────────────\r\nMedicationAdministration, not MedicationRequest. These were given, in\r\ntheatre, by the anaesthetist; there was no order to fulfil and no pharmacy\r\nin the loop. `status = 'completed'` for the same reason.\r\n`medication.concept.text` carries the drug name as written. The hospital's\r\nformulary is not coded and a guessed RxNorm or ATC code on a cytotoxic or an\r\ninduction agent is a patient-safety risk, not a data-quality nicety."
        },
        {
          "name": "fluidAdministration",
          "source": [
            {
              "context": "qr",
              "element": "item",
              "variable": "g",
              "condition": "(linkId = 'iv-fluid') and item.where(linkId = 'iv-fluid/name').answer.value.exists()"
            }
          ],
          "target": [
            {
              "context": "bundle",
              "element": "entry",
              "variable": "entry"
            },
            {
              "context": "entry",
              "element": "resource",
              "variable": "ma",
              "transform": "create",
              "parameter": [
                {
                  "valueString": "MedicationAdministration"
                }
              ]
            }
          ],
          "rule": [
            {
              "name": "base",
              "source": [
                {
                  "context": "qr"
                }
              ],
              "target": [
                {
                  "context": "ma"
                },
                {
                  "context": "entry"
                }
              ],
              "dependent": [
                {
                  "name": "BuildMedicationAdministrationBase",
                  "parameter": [
                    {
                      "valueId": "qr"
                    },
                    {
                      "valueId": "ma"
                    },
                    {
                      "valueId": "entry"
                    }
                  ]
                }
              ]
            },
            {
              "name": "status",
              "source": [
                {
                  "context": "g"
                }
              ],
              "target": [
                {
                  "context": "ma",
                  "element": "status",
                  "transform": "copy",
                  "parameter": [
                    {
                      "valueString": "completed"
                    }
                  ]
                }
              ]
            },
            {
              "name": "encounter",
              "source": [
                {
                  "context": "qr",
                  "element": "encounter",
                  "variable": "e"
                }
              ],
              "target": [
                {
                  "context": "ma",
                  "element": "encounter",
                  "transform": "copy",
                  "parameter": [
                    {
                      "valueId": "e"
                    }
                  ]
                }
              ]
            },
            {
              "name": "performer",
              "source": [
                {
                  "context": "qr",
                  "element": "source",
                  "variable": "src"
                }
              ],
              "target": [
                {
                  "context": "ma",
                  "element": "performer",
                  "variable": "p"
                },
                {
                  "context": "p",
                  "element": "actor",
                  "variable": "cr",
                  "transform": "create",
                  "parameter": [
                    {
                      "valueString": "CodeableReference"
                    }
                  ]
                },
                {
                  "context": "cr",
                  "element": "reference",
                  "transform": "copy",
                  "parameter": [
                    {
                      "valueId": "src"
                    }
                  ]
                }
              ]
            },
            {
              "name": "fluidNameRule",
              "source": [
                {
                  "context": "g",
                  "element": "item",
                  "variable": "it",
                  "condition": "linkId = 'iv-fluid/name'"
                }
              ],
              "rule": [
                {
                  "name": "answer",
                  "source": [
                    {
                      "context": "it",
                      "element": "answer",
                      "listMode": "first",
                      "variable": "a"
                    }
                  ],
                  "rule": [
                    {
                      "name": "medicationText",
                      "source": [
                        {
                          "context": "a",
                          "element": "value",
                          "variable": "txt"
                        }
                      ],
                      "target": [
                        {
                          "context": "ma",
                          "element": "medication",
                          "variable": "med"
                        },
                        {
                          "context": "med",
                          "element": "concept",
                          "variable": "mc"
                        },
                        {
                          "context": "mc",
                          "element": "text",
                          "transform": "copy",
                          "parameter": [
                            {
                              "valueId": "txt"
                            }
                          ]
                        }
                      ]
                    }
                  ]
                }
              ]
            },
            {
              "name": "fluidVolumeRule",
              "source": [
                {
                  "context": "g",
                  "element": "item",
                  "variable": "it",
                  "condition": "(linkId = 'iv-fluid/volume') and answer.value.ofType(Quantity).exists()"
                }
              ],
              "rule": [
                {
                  "name": "answer",
                  "source": [
                    {
                      "context": "it",
                      "element": "answer",
                      "listMode": "first",
                      "variable": "a"
                    }
                  ],
                  "rule": [
                    {
                      "name": "dosageVolume",
                      "source": [
                        {
                          "context": "a",
                          "element": "value",
                          "variable": "v"
                        }
                      ],
                      "target": [
                        {
                          "context": "ma",
                          "element": "dosage",
                          "variable": "dos"
                        },
                        {
                          "context": "dos",
                          "element": "dose",
                          "transform": "copy",
                          "parameter": [
                            {
                              "valueId": "v"
                            }
                          ]
                        }
                      ]
                    }
                  ]
                }
              ],
              "documentation": "Guarded on the answer being a Quantity, not merely present. Dosage.dose\r\ntakes a Quantity or a Range and nothing else, so a client that submits\r\na bare string there fails the rule and takes the whole extraction with\r\nit -- which is exactly what the questionnaire tester does: it renders a\r\n`quantity` item as a plain text box and submits valueString \"5\".\r\n`$validate` on such a response says so plainly (\"Answer value must be\r\nof the type Quantity not string\"); one non-conformant field should not\r\ncost every other resource on the form."
            },
            {
              "name": "occurrence",
              "source": [
                {
                  "context": "qr",
                  "element": "authored",
                  "variable": "t"
                }
              ],
              "target": [
                {
                  "context": "ma",
                  "element": "occurence",
                  "transform": "copy",
                  "parameter": [
                    {
                      "valueId": "t"
                    }
                  ]
                }
              ]
            },
            {
              "name": "fluidNote",
              "source": [
                {
                  "context": "g"
                }
              ],
              "target": [
                {
                  "context": "ma",
                  "element": "note",
                  "variable": "n"
                },
                {
                  "context": "n",
                  "element": "text",
                  "transform": "copy",
                  "parameter": [
                    {
                      "valueString": "Intravenous fluid given during anaesthesia"
                    }
                  ]
                }
              ]
            }
          ]
        },
        {
          "name": "bloodLossObservation",
          "source": [
            {
              "context": "qr",
              "element": "item",
              "variable": "it",
              "condition": "(linkId = 'estimated-blood-loss') and answer.value.exists()"
            }
          ],
          "target": [
            {
              "context": "bundle",
              "element": "entry",
              "variable": "entry"
            },
            {
              "context": "entry",
              "element": "resource",
              "variable": "obs",
              "transform": "create",
              "parameter": [
                {
                  "valueString": "Observation"
                }
              ]
            }
          ],
          "rule": [
            {
              "name": "base",
              "source": [
                {
                  "context": "qr"
                }
              ],
              "target": [
                {
                  "context": "obs"
                },
                {
                  "context": "entry"
                }
              ],
              "dependent": [
                {
                  "name": "BuildObsBase",
                  "parameter": [
                    {
                      "valueId": "qr"
                    },
                    {
                      "valueId": "obs"
                    },
                    {
                      "valueId": "entry"
                    }
                  ]
                }
              ]
            },
            {
              "name": "category",
              "source": [
                {
                  "context": "qr"
                }
              ],
              "target": [
                {
                  "context": "obs"
                }
              ],
              "dependent": [
                {
                  "name": "SetProcedureCategory",
                  "parameter": [
                    {
                      "valueId": "qr"
                    },
                    {
                      "valueId": "obs"
                    }
                  ]
                }
              ]
            },
            {
              "name": "code",
              "source": [
                {
                  "context": "it"
                }
              ],
              "target": [
                {
                  "context": "obs",
                  "element": "code",
                  "variable": "cc"
                }
              ],
              "rule": [
                {
                  "name": "coding",
                  "source": [
                    {
                      "context": "it"
                    }
                  ],
                  "target": [
                    {
                      "context": "cc",
                      "element": "coding",
                      "variable": "cg"
                    }
                  ],
                  "rule": [
                    {
                      "name": "sys",
                      "source": [
                        {
                          "context": "it"
                        }
                      ],
                      "target": [
                        {
                          "context": "cg",
                          "element": "system",
                          "transform": "copy",
                          "parameter": [
                            {
                              "valueString": "http://loinc.org"
                            }
                          ]
                        }
                      ]
                    },
                    {
                      "name": "cd",
                      "source": [
                        {
                          "context": "it"
                        }
                      ],
                      "target": [
                        {
                          "context": "cg",
                          "element": "code",
                          "transform": "copy",
                          "parameter": [
                            {
                              "valueString": "8717-1"
                            }
                          ]
                        }
                      ]
                    },
                    {
                      "name": "dsp",
                      "source": [
                        {
                          "context": "it"
                        }
                      ],
                      "target": [
                        {
                          "context": "cg",
                          "element": "display",
                          "transform": "copy",
                          "parameter": [
                            {
                              "valueString": "Surgical operation note estimated blood loss [Volume]"
                            }
                          ]
                        }
                      ]
                    }
                  ]
                }
              ]
            },
            {
              "name": "answer",
              "source": [
                {
                  "context": "it",
                  "element": "answer",
                  "listMode": "first",
                  "variable": "a"
                }
              ],
              "rule": [
                {
                  "name": "set",
                  "source": [
                    {
                      "context": "a",
                      "element": "value",
                      "variable": "v"
                    }
                  ],
                  "target": [
                    {
                      "context": "obs",
                      "element": "value",
                      "transform": "copy",
                      "parameter": [
                        {
                          "valueId": "v"
                        }
                      ]
                    }
                  ]
                }
              ]
            },
            {
              "name": "estimateNote",
              "source": [
                {
                  "context": "it"
                }
              ],
              "target": [
                {
                  "context": "obs",
                  "element": "note",
                  "variable": "n"
                },
                {
                  "context": "n",
                  "element": "text",
                  "transform": "copy",
                  "parameter": [
                    {
                      "valueString": "An estimate made in theatre, not a measured volume."
                    }
                  ]
                }
              ]
            }
          ],
          "documentation": "── Estimated blood loss ────────────────────────────────────────────────\r\nLOINC 8717-1, the operation note's own term for it, which is exactly what\r\nthis is. The note says it is an estimate: the figure drives a transfusion\r\ndecision and a reader has to know it was eyeballed, not measured."
        },
        {
          "name": "durationGroup",
          "source": [
            {
              "context": "qr",
              "element": "item",
              "variable": "g",
              "condition": "linkId = 'case'"
            }
          ],
          "rule": [
            {
              "name": "durationObservation",
              "source": [
                {
                  "context": "g",
                  "element": "item",
                  "variable": "it",
                  "condition": "(linkId = 'case/duration') and answer.value.exists()"
                }
              ],
              "target": [
                {
                  "context": "bundle",
                  "element": "entry",
                  "variable": "entry"
                },
                {
                  "context": "entry",
                  "element": "resource",
                  "variable": "obs",
                  "transform": "create",
                  "parameter": [
                    {
                      "valueString": "Observation"
                    }
                  ]
                }
              ],
              "rule": [
                {
                  "name": "base",
                  "source": [
                    {
                      "context": "qr"
                    }
                  ],
                  "target": [
                    {
                      "context": "obs"
                    },
                    {
                      "context": "entry"
                    }
                  ],
                  "dependent": [
                    {
                      "name": "BuildObsBase",
                      "parameter": [
                        {
                          "valueId": "qr"
                        },
                        {
                          "valueId": "obs"
                        },
                        {
                          "valueId": "entry"
                        }
                      ]
                    }
                  ]
                },
                {
                  "name": "category",
                  "source": [
                    {
                      "context": "qr"
                    }
                  ],
                  "target": [
                    {
                      "context": "obs"
                    }
                  ],
                  "dependent": [
                    {
                      "name": "SetProcedureCategory",
                      "parameter": [
                        {
                          "valueId": "qr"
                        },
                        {
                          "valueId": "obs"
                        }
                      ]
                    }
                  ]
                },
                {
                  "name": "code",
                  "source": [
                    {
                      "context": "it"
                    }
                  ],
                  "target": [
                    {
                      "context": "obs",
                      "element": "code",
                      "variable": "cc"
                    }
                  ],
                  "rule": [
                    {
                      "name": "coding",
                      "source": [
                        {
                          "context": "it"
                        }
                      ],
                      "target": [
                        {
                          "context": "cc",
                          "element": "coding",
                          "variable": "cg"
                        }
                      ],
                      "rule": [
                        {
                          "name": "sys",
                          "source": [
                            {
                              "context": "it"
                            }
                          ],
                          "target": [
                            {
                              "context": "cg",
                              "element": "system",
                              "transform": "copy",
                              "parameter": [
                                {
                                  "valueString": "http://loinc.org"
                                }
                              ]
                            }
                          ]
                        },
                        {
                          "name": "cd",
                          "source": [
                            {
                              "context": "it"
                            }
                          ],
                          "target": [
                            {
                              "context": "cg",
                              "element": "code",
                              "transform": "copy",
                              "parameter": [
                                {
                                  "valueString": "89874-2"
                                }
                              ]
                            }
                          ]
                        },
                        {
                          "name": "dsp",
                          "source": [
                            {
                              "context": "it"
                            }
                          ],
                          "target": [
                            {
                              "context": "cg",
                              "element": "display",
                              "transform": "copy",
                              "parameter": [
                                {
                                  "valueString": "Anesthesia duration"
                                }
                              ]
                            }
                          ]
                        }
                      ]
                    }
                  ]
                },
                {
                  "name": "answer",
                  "source": [
                    {
                      "context": "it",
                      "element": "answer",
                      "listMode": "first",
                      "variable": "a"
                    }
                  ],
                  "rule": [
                    {
                      "name": "set",
                      "source": [
                        {
                          "context": "a",
                          "element": "value",
                          "variable": "v"
                        }
                      ],
                      "target": [
                        {
                          "context": "obs",
                          "element": "value",
                          "transform": "copy",
                          "parameter": [
                            {
                              "valueId": "v"
                            }
                          ]
                        }
                      ]
                    }
                  ]
                }
              ]
            }
          ],
          "documentation": "── Anaesthesia duration ────────────────────────────────────────────────\r\nExtracted only when the form carries it. The questionnaire leaves the field\r\nread-only and expects the client to derive it from the start and completion\r\ntimes; where the client did, that value is authoritative and is recorded\r\nunder LOINC 89874-2. Where it did not, nothing is written -- the Procedure's\r\nperiod already holds both ends, and a duration computed here from a clock\r\ntime with no date could be a day out."
        }
      ]
    },
    {
      "name": "BuildObsBase",
      "documentation": "─────────────────────────────────────────────────────────────────────────────\r\nShared scaffolding. Repeated in each map rather than imported: the transform\r\nengine resolves `imports` against whatever StructureMaps happen to be on the\r\nserver, and a form that stops extracting because a shared map was not\r\nuploaded is a worse failure than a duplicated group.\r\nTwo notes on what the publisher's StructureMap validator says about this file.\r\nSource parameters below are left untyped on purpose. Writing `: Element` makes\r\nthe validator compare QuestionnaireResponse.item against the literal 'Element'\r\nand report them as incompatible with each other, which is noise, not a finding.\r\n`evaluate(context, expression)` is flagged as \"takes 1 parameter but 2 were\r\nfound\". Leave it. The FML parser in the same jar refuses the one-argument form\r\noutright -- it wants a parameter, a comma, then the FHIRPath -- so the\r\npublisher is objecting to what its own compiler emits. Two arguments is the\r\nonly form that compiles, and it is what the R5 transform engine executes.\r\n─────────────────────────────────────────────────────────────────────────────",
      "input": [
        {
          "name": "qr",
          "type": "QR",
          "mode": "source"
        },
        {
          "name": "obs",
          "type": "Observation",
          "mode": "target"
        },
        {
          "name": "entry",
          "mode": "target"
        }
      ],
      "rule": [
        {
          "name": "responseProvenance",
          "source": [
            {
              "context": "qr"
            }
          ],
          "target": [
            {
              "context": "obs"
            }
          ],
          "dependent": [
            {
              "name": "SetResponseProvenance",
              "parameter": [
                {
                  "valueId": "qr"
                },
                {
                  "valueId": "obs"
                }
              ]
            }
          ]
        },
        {
          "name": "idAndFullUrl",
          "source": [
            {
              "context": "qr"
            }
          ],
          "target": [
            {
              "context": "obs",
              "element": "id",
              "transform": "uuid"
            }
          ],
          "dependent": [
            {
              "name": "SetObservationFullUrl",
              "parameter": [
                {
                  "valueId": "obs"
                },
                {
                  "valueId": "entry"
                }
              ]
            }
          ]
        },
        {
          "name": "entryRequest",
          "source": [
            {
              "context": "qr"
            }
          ],
          "target": [
            {
              "context": "entry",
              "element": "request",
              "variable": "request"
            }
          ],
          "rule": [
            {
              "name": "requestMethod",
              "source": [
                {
                  "context": "qr"
                }
              ],
              "target": [
                {
                  "context": "request",
                  "element": "method",
                  "transform": "copy",
                  "parameter": [
                    {
                      "valueString": "POST"
                    }
                  ]
                }
              ]
            },
            {
              "name": "requestUrl",
              "source": [
                {
                  "context": "qr"
                }
              ],
              "target": [
                {
                  "context": "request",
                  "element": "url",
                  "transform": "copy",
                  "parameter": [
                    {
                      "valueString": "Observation"
                    }
                  ]
                }
              ]
            }
          ]
        },
        {
          "name": "status",
          "source": [
            {
              "context": "qr"
            }
          ],
          "target": [
            {
              "context": "obs",
              "element": "status",
              "transform": "copy",
              "parameter": [
                {
                  "valueString": "final"
                }
              ]
            }
          ]
        },
        {
          "name": "subject",
          "source": [
            {
              "context": "qr",
              "element": "subject",
              "variable": "s"
            }
          ],
          "target": [
            {
              "context": "obs",
              "element": "subject",
              "transform": "copy",
              "parameter": [
                {
                  "valueId": "s"
                }
              ]
            }
          ]
        },
        {
          "name": "encounter",
          "source": [
            {
              "context": "qr",
              "element": "encounter",
              "variable": "e"
            }
          ],
          "target": [
            {
              "context": "obs",
              "element": "encounter",
              "transform": "copy",
              "parameter": [
                {
                  "valueId": "e"
                }
              ]
            }
          ]
        },
        {
          "name": "effective",
          "source": [
            {
              "context": "qr",
              "element": "authored",
              "variable": "t"
            }
          ],
          "target": [
            {
              "context": "obs",
              "element": "effective",
              "transform": "copy",
              "parameter": [
                {
                  "valueId": "t"
                }
              ]
            }
          ]
        },
        {
          "name": "performerFromSource",
          "source": [
            {
              "context": "qr",
              "element": "source",
              "variable": "src"
            }
          ],
          "target": [
            {
              "context": "obs",
              "element": "performer",
              "transform": "copy",
              "parameter": [
                {
                  "valueId": "src"
                }
              ]
            }
          ]
        },
        {
          "name": "performerFallback",
          "source": [
            {
              "context": "qr",
              "condition": "source.exists().not()"
            }
          ],
          "rule": [
            {
              "name": "performerFromAuthor",
              "source": [
                {
                  "context": "qr",
                  "element": "author",
                  "variable": "a"
                }
              ],
              "target": [
                {
                  "context": "obs",
                  "element": "performer",
                  "transform": "copy",
                  "parameter": [
                    {
                      "valueId": "a"
                    }
                  ]
                }
              ]
            }
          ]
        },
        {
          "name": "linkQuestionnaireResponse",
          "source": [
            {
              "context": "qr",
              "element": "id",
              "variable": "qid",
              "condition": "$this.hasValue()"
            }
          ],
          "target": [
            {
              "context": "obs",
              "element": "derivedFrom",
              "variable": "ref",
              "transform": "create",
              "parameter": [
                {
                  "valueString": "Reference"
                }
              ]
            },
            {
              "context": "ref",
              "element": "reference",
              "transform": "copy",
              "parameter": [
                {
                  "valueId": "qid"
                }
              ]
            }
          ],
          "documentation": "A stored response's id already reads \"QuestionnaireResponse/<id>\", so it is\r\na relative reference as it stands. The hasValue() guard is what stops an\r\nunsaved response -- one posted straight to $extract rather than saved first\r\n-- from writing \"QuestionnaireResponse/null\" into the record."
        }
      ]
    },
    {
      "name": "SetObservationFullUrl",
      "input": [
        {
          "name": "obs",
          "type": "Observation",
          "mode": "source"
        },
        {
          "name": "entry",
          "mode": "target"
        }
      ],
      "rule": [
        {
          "name": "assignFullUrl",
          "source": [
            {
              "context": "obs",
              "element": "id",
              "variable": "id"
            }
          ],
          "target": [
            {
              "context": "entry",
              "element": "fullUrl",
              "transform": "append",
              "parameter": [
                {
                  "valueString": "https://fhir.slade360.co.ke/fhir/Observation/"
                },
                {
                  "valueId": "id"
                }
              ]
            }
          ]
        }
      ]
    },
    {
      "name": "SetComponentCodedValue",
      "documentation": "The two answer shapes a component can carry. Both read the answer through the\r\nuntyped `.value` accessor: reading `valueCoding` or `valueQuantity` by its\r\ntyped property name fails at transform time on HAPI R5 with \"Attempt to read\r\ninvalid property ... on QuestionnaireResponse.item.answer\".",
      "input": [
        {
          "name": "it",
          "mode": "source"
        },
        {
          "name": "comp",
          "mode": "target"
        }
      ],
      "rule": [
        {
          "name": "componentAnswer",
          "source": [
            {
              "context": "it",
              "element": "answer",
              "listMode": "first",
              "variable": "a"
            }
          ],
          "rule": [
            {
              "name": "codedValue",
              "source": [
                {
                  "context": "a",
                  "element": "value",
                  "variable": "cv"
                }
              ],
              "target": [
                {
                  "context": "comp",
                  "element": "value",
                  "variable": "cc",
                  "transform": "create",
                  "parameter": [
                    {
                      "valueString": "CodeableConcept"
                    }
                  ]
                }
              ],
              "rule": [
                {
                  "name": "valueCoding",
                  "source": [
                    {
                      "context": "cv"
                    }
                  ],
                  "target": [
                    {
                      "context": "cc",
                      "element": "coding",
                      "transform": "copy",
                      "parameter": [
                        {
                          "valueId": "cv"
                        }
                      ]
                    }
                  ]
                },
                {
                  "name": "valueText",
                  "source": [
                    {
                      "context": "cv",
                      "element": "display",
                      "variable": "d"
                    }
                  ],
                  "target": [
                    {
                      "context": "cc",
                      "element": "text",
                      "transform": "copy",
                      "parameter": [
                        {
                          "valueId": "d"
                        }
                      ]
                    }
                  ]
                }
              ]
            }
          ]
        }
      ]
    },
    {
      "name": "SetComponentValue",
      "input": [
        {
          "name": "it",
          "mode": "source"
        },
        {
          "name": "comp",
          "mode": "target"
        }
      ],
      "rule": [
        {
          "name": "componentAnswer",
          "source": [
            {
              "context": "it",
              "element": "answer",
              "listMode": "first",
              "variable": "a"
            }
          ],
          "rule": [
            {
              "name": "plainValue",
              "source": [
                {
                  "context": "a",
                  "element": "value",
                  "variable": "v"
                }
              ],
              "target": [
                {
                  "context": "comp",
                  "element": "value",
                  "transform": "copy",
                  "parameter": [
                    {
                      "valueId": "v"
                    }
                  ]
                }
              ]
            }
          ]
        }
      ]
    },
    {
      "name": "SetSurveyCategory",
      "input": [
        {
          "name": "qr",
          "type": "QR",
          "mode": "source"
        },
        {
          "name": "obs",
          "type": "Observation",
          "mode": "target"
        }
      ],
      "rule": [
        {
          "name": "category",
          "source": [
            {
              "context": "qr"
            }
          ],
          "target": [
            {
              "context": "obs",
              "element": "category",
              "variable": "cat"
            }
          ],
          "rule": [
            {
              "name": "categoryCoding",
              "source": [
                {
                  "context": "qr"
                }
              ],
              "target": [
                {
                  "context": "cat",
                  "element": "coding",
                  "variable": "coding"
                }
              ],
              "rule": [
                {
                  "name": "categorySystem",
                  "source": [
                    {
                      "context": "qr"
                    }
                  ],
                  "target": [
                    {
                      "context": "coding",
                      "element": "system",
                      "transform": "copy",
                      "parameter": [
                        {
                          "valueString": "http://terminology.hl7.org/CodeSystem/observation-category"
                        }
                      ]
                    }
                  ]
                },
                {
                  "name": "categoryCode",
                  "source": [
                    {
                      "context": "qr"
                    }
                  ],
                  "target": [
                    {
                      "context": "coding",
                      "element": "code",
                      "transform": "copy",
                      "parameter": [
                        {
                          "valueString": "survey"
                        }
                      ]
                    }
                  ]
                },
                {
                  "name": "categoryDisplay",
                  "source": [
                    {
                      "context": "qr"
                    }
                  ],
                  "target": [
                    {
                      "context": "coding",
                      "element": "display",
                      "transform": "copy",
                      "parameter": [
                        {
                          "valueString": "Survey"
                        }
                      ]
                    }
                  ]
                }
              ]
            }
          ]
        }
      ]
    },
    {
      "name": "SetVitalSignsCategory",
      "input": [
        {
          "name": "qr",
          "type": "QR",
          "mode": "source"
        },
        {
          "name": "obs",
          "type": "Observation",
          "mode": "target"
        }
      ],
      "rule": [
        {
          "name": "category",
          "source": [
            {
              "context": "qr"
            }
          ],
          "target": [
            {
              "context": "obs",
              "element": "category",
              "variable": "cat"
            }
          ],
          "rule": [
            {
              "name": "categoryCoding",
              "source": [
                {
                  "context": "qr"
                }
              ],
              "target": [
                {
                  "context": "cat",
                  "element": "coding",
                  "variable": "coding"
                }
              ],
              "rule": [
                {
                  "name": "categorySystem",
                  "source": [
                    {
                      "context": "qr"
                    }
                  ],
                  "target": [
                    {
                      "context": "coding",
                      "element": "system",
                      "transform": "copy",
                      "parameter": [
                        {
                          "valueString": "http://terminology.hl7.org/CodeSystem/observation-category"
                        }
                      ]
                    }
                  ]
                },
                {
                  "name": "categoryCode",
                  "source": [
                    {
                      "context": "qr"
                    }
                  ],
                  "target": [
                    {
                      "context": "coding",
                      "element": "code",
                      "transform": "copy",
                      "parameter": [
                        {
                          "valueString": "vital-signs"
                        }
                      ]
                    }
                  ]
                },
                {
                  "name": "categoryDisplay",
                  "source": [
                    {
                      "context": "qr"
                    }
                  ],
                  "target": [
                    {
                      "context": "coding",
                      "element": "display",
                      "transform": "copy",
                      "parameter": [
                        {
                          "valueString": "Vital Signs"
                        }
                      ]
                    }
                  ]
                }
              ]
            }
          ]
        }
      ]
    },
    {
      "name": "SetProcedureCategory",
      "input": [
        {
          "name": "qr",
          "type": "QR",
          "mode": "source"
        },
        {
          "name": "obs",
          "type": "Observation",
          "mode": "target"
        }
      ],
      "rule": [
        {
          "name": "category",
          "source": [
            {
              "context": "qr"
            }
          ],
          "target": [
            {
              "context": "obs",
              "element": "category",
              "variable": "cat"
            }
          ],
          "rule": [
            {
              "name": "categoryCoding",
              "source": [
                {
                  "context": "qr"
                }
              ],
              "target": [
                {
                  "context": "cat",
                  "element": "coding",
                  "variable": "coding"
                }
              ],
              "rule": [
                {
                  "name": "categorySystem",
                  "source": [
                    {
                      "context": "qr"
                    }
                  ],
                  "target": [
                    {
                      "context": "coding",
                      "element": "system",
                      "transform": "copy",
                      "parameter": [
                        {
                          "valueString": "http://terminology.hl7.org/CodeSystem/observation-category"
                        }
                      ]
                    }
                  ]
                },
                {
                  "name": "categoryCode",
                  "source": [
                    {
                      "context": "qr"
                    }
                  ],
                  "target": [
                    {
                      "context": "coding",
                      "element": "code",
                      "transform": "copy",
                      "parameter": [
                        {
                          "valueString": "procedure"
                        }
                      ]
                    }
                  ]
                },
                {
                  "name": "categoryDisplay",
                  "source": [
                    {
                      "context": "qr"
                    }
                  ],
                  "target": [
                    {
                      "context": "coding",
                      "element": "display",
                      "transform": "copy",
                      "parameter": [
                        {
                          "valueString": "Procedure"
                        }
                      ]
                    }
                  ]
                }
              ]
            }
          ]
        }
      ]
    },
    {
      "name": "BuildProcedureBase",
      "input": [
        {
          "name": "qr",
          "type": "QR",
          "mode": "source"
        },
        {
          "name": "r",
          "type": "Procedure",
          "mode": "target"
        },
        {
          "name": "entry",
          "mode": "target"
        }
      ],
      "rule": [
        {
          "name": "responseProvenance",
          "source": [
            {
              "context": "qr"
            }
          ],
          "target": [
            {
              "context": "r"
            }
          ],
          "dependent": [
            {
              "name": "SetResponseProvenance",
              "parameter": [
                {
                  "valueId": "qr"
                },
                {
                  "valueId": "r"
                }
              ]
            }
          ]
        },
        {
          "name": "idAndFullUrl",
          "source": [
            {
              "context": "qr"
            }
          ],
          "target": [
            {
              "context": "r",
              "element": "id",
              "transform": "uuid"
            }
          ],
          "dependent": [
            {
              "name": "SetProcedureFullUrl",
              "parameter": [
                {
                  "valueId": "r"
                },
                {
                  "valueId": "entry"
                }
              ]
            }
          ]
        },
        {
          "name": "entryRequest",
          "source": [
            {
              "context": "qr"
            }
          ],
          "target": [
            {
              "context": "entry",
              "element": "request",
              "variable": "request"
            }
          ],
          "rule": [
            {
              "name": "requestMethod",
              "source": [
                {
                  "context": "qr"
                }
              ],
              "target": [
                {
                  "context": "request",
                  "element": "method",
                  "transform": "copy",
                  "parameter": [
                    {
                      "valueString": "POST"
                    }
                  ]
                }
              ]
            },
            {
              "name": "requestUrl",
              "source": [
                {
                  "context": "qr"
                }
              ],
              "target": [
                {
                  "context": "request",
                  "element": "url",
                  "transform": "copy",
                  "parameter": [
                    {
                      "valueString": "Procedure"
                    }
                  ]
                }
              ]
            }
          ]
        },
        {
          "name": "occurrenceFallback",
          "source": [
            {
              "context": "qr",
              "element": "authored",
              "variable": "t"
            }
          ],
          "target": [
            {
              "context": "r",
              "element": "occurrence",
              "transform": "copy",
              "parameter": [
                {
                  "valueId": "t"
                }
              ]
            }
          ],
          "documentation": "The response's own time, as a floor, the way BuildObsBase does it. A rule\r\nthat reads a time off the form overwrites this; without it a procedure whose\r\ndate column was taken off on review has no time at all, and a procedure with\r\nno time cannot be ordered against the rest of the admission."
        },
        {
          "name": "subject",
          "source": [
            {
              "context": "qr",
              "element": "subject",
              "variable": "s"
            }
          ],
          "target": [
            {
              "context": "r",
              "element": "subject",
              "transform": "copy",
              "parameter": [
                {
                  "valueId": "s"
                }
              ]
            }
          ]
        }
      ]
    },
    {
      "name": "SetProcedureFullUrl",
      "input": [
        {
          "name": "r",
          "type": "Procedure",
          "mode": "source"
        },
        {
          "name": "entry",
          "mode": "target"
        }
      ],
      "rule": [
        {
          "name": "assignFullUrl",
          "source": [
            {
              "context": "r",
              "element": "id",
              "variable": "id"
            }
          ],
          "target": [
            {
              "context": "entry",
              "element": "fullUrl",
              "transform": "append",
              "parameter": [
                {
                  "valueString": "https://fhir.slade360.co.ke/fhir/Procedure/"
                },
                {
                  "valueId": "id"
                }
              ]
            }
          ]
        }
      ]
    },
    {
      "name": "BuildMedicationAdministrationBase",
      "input": [
        {
          "name": "qr",
          "type": "QR",
          "mode": "source"
        },
        {
          "name": "r",
          "type": "MedicationAdministration",
          "mode": "target"
        },
        {
          "name": "entry",
          "mode": "target"
        }
      ],
      "rule": [
        {
          "name": "responseProvenance",
          "source": [
            {
              "context": "qr"
            }
          ],
          "target": [
            {
              "context": "r"
            }
          ],
          "dependent": [
            {
              "name": "SetResponseProvenance",
              "parameter": [
                {
                  "valueId": "qr"
                },
                {
                  "valueId": "r"
                }
              ]
            }
          ]
        },
        {
          "name": "idAndFullUrl",
          "source": [
            {
              "context": "qr"
            }
          ],
          "target": [
            {
              "context": "r",
              "element": "id",
              "transform": "uuid"
            }
          ],
          "dependent": [
            {
              "name": "SetMedicationAdministrationFullUrl",
              "parameter": [
                {
                  "valueId": "r"
                },
                {
                  "valueId": "entry"
                }
              ]
            }
          ]
        },
        {
          "name": "entryRequest",
          "source": [
            {
              "context": "qr"
            }
          ],
          "target": [
            {
              "context": "entry",
              "element": "request",
              "variable": "request"
            }
          ],
          "rule": [
            {
              "name": "requestMethod",
              "source": [
                {
                  "context": "qr"
                }
              ],
              "target": [
                {
                  "context": "request",
                  "element": "method",
                  "transform": "copy",
                  "parameter": [
                    {
                      "valueString": "POST"
                    }
                  ]
                }
              ]
            },
            {
              "name": "requestUrl",
              "source": [
                {
                  "context": "qr"
                }
              ],
              "target": [
                {
                  "context": "request",
                  "element": "url",
                  "transform": "copy",
                  "parameter": [
                    {
                      "valueString": "MedicationAdministration"
                    }
                  ]
                }
              ]
            }
          ]
        },
        {
          "name": "subject",
          "source": [
            {
              "context": "qr",
              "element": "subject",
              "variable": "s"
            }
          ],
          "target": [
            {
              "context": "r",
              "element": "subject",
              "transform": "copy",
              "parameter": [
                {
                  "valueId": "s"
                }
              ]
            }
          ]
        },
        {
          "name": "occurrenceFallback",
          "source": [
            {
              "context": "qr",
              "element": "authored",
              "variable": "t"
            }
          ],
          "target": [
            {
              "context": "r",
              "element": "occurence",
              "transform": "copy",
              "parameter": [
                {
                  "valueId": "t"
                }
              ]
            }
          ],
          "documentation": "The response's own time, as a floor. A row that names the time it was given\r\noverwrites this; a form whose time column was taken off on review would\r\notherwise produce an administration with no time at all, which is not a\r\nrecord of an administration. Same fallback BuildObsBase already applies."
        }
      ]
    },
    {
      "name": "SetMedicationAdministrationFullUrl",
      "input": [
        {
          "name": "r",
          "type": "MedicationAdministration",
          "mode": "source"
        },
        {
          "name": "entry",
          "mode": "target"
        }
      ],
      "rule": [
        {
          "name": "assignFullUrl",
          "source": [
            {
              "context": "r",
              "element": "id",
              "variable": "id"
            }
          ],
          "target": [
            {
              "context": "entry",
              "element": "fullUrl",
              "transform": "append",
              "parameter": [
                {
                  "valueString": "https://fhir.slade360.co.ke/fhir/MedicationAdministration/"
                },
                {
                  "valueId": "id"
                }
              ]
            }
          ]
        }
      ]
    },
    {
      "name": "SetResponseProvenance",
      "documentation": "── Provenance and tenancy ───────────────────────────────────────────────────\r\nTwo tags on everything this map creates. The first says which questionnaire\r\nproduced it, so a form that reopens mid-admission recalls its own earlier\r\nentries and not another form's. The second copies the tenant tags off the\r\nresponse, because nothing else on the path puts them there.\r\nThe code is the form's document type, not the questionnaire's id: every\r\nenvironment mints its own ids, and there is only one set of maps, so an id\r\nhere would tie the tag to whichever environment stamped it.\r\n── Provenance and tenancy ───────────────────────────────────────────────────",
      "input": [
        {
          "name": "qr",
          "type": "QR",
          "mode": "source"
        },
        {
          "name": "r",
          "mode": "target"
        }
      ],
      "rule": [
        {
          "name": "provenanceMeta",
          "source": [
            {
              "context": "qr"
            }
          ],
          "target": [
            {
              "context": "r",
              "element": "meta",
              "variable": "m"
            }
          ],
          "rule": [
            {
              "name": "provenanceTag",
              "source": [
                {
                  "context": "qr"
                }
              ],
              "target": [
                {
                  "context": "m",
                  "element": "tag",
                  "variable": "t"
                }
              ],
              "rule": [
                {
                  "name": "provenanceSystem",
                  "source": [
                    {
                      "context": "qr"
                    }
                  ],
                  "target": [
                    {
                      "context": "t",
                      "element": "system",
                      "transform": "copy",
                      "parameter": [
                        {
                          "valueString": "http://slade360edi.com/questionnaire-provenance"
                        }
                      ]
                    }
                  ]
                },
                {
                  "name": "provenanceCode",
                  "source": [
                    {
                      "context": "qr"
                    }
                  ],
                  "target": [
                    {
                      "context": "t",
                      "element": "code",
                      "transform": "copy",
                      "parameter": [
                        {
                          "valueString": "anaesthetic-record"
                        }
                      ]
                    }
                  ]
                },
                {
                  "name": "provenanceDisplay",
                  "source": [
                    {
                      "context": "qr"
                    }
                  ],
                  "target": [
                    {
                      "context": "t",
                      "element": "display",
                      "transform": "copy",
                      "parameter": [
                        {
                          "valueString": "Anaesthetic record"
                        }
                      ]
                    }
                  ]
                }
              ]
            }
          ]
        },
        {
          "name": "tenantTags",
          "source": [
            {
              "context": "qr",
              "element": "meta",
              "variable": "qm"
            }
          ],
          "rule": [
            {
              "name": "copyTag",
              "source": [
                {
                  "context": "qm",
                  "element": "tag",
                  "variable": "qt"
                }
              ],
              "target": [
                {
                  "context": "r",
                  "element": "meta",
                  "variable": "m"
                },
                {
                  "context": "m",
                  "element": "tag",
                  "transform": "copy",
                  "parameter": [
                    {
                      "valueId": "qt"
                    }
                  ]
                }
              ]
            }
          ],
          "documentation": "Every tag the response carries, onto the resource. `meta` is 0..1, so this\r\nlands on the same meta the rule above created rather than a second one."
        }
      ]
    }
  ]
}