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

FHIR IG analytics

Packagesilfhirprofileig
Resource TypeStructureMap
IdStructureMap-ExtractDeviceRequest.json
FHIR VersionR5
Sourcehttps://build.fhir.org/ig/savannahghi/sil_fhir_profile_ig/StructureMap-ExtractDeviceRequest.html
URLhttps://fhir.slade360.co.ke/fhir/StructureMap/ExtractDeviceRequest
Version0.1.0
Statusdraft
Date2026-09-11T12:18:36+00:00
NameExtractDeviceRequest

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 ExtractDeviceRequest

/// url = 'https://fhir.slade360.co.ke/fhir/StructureMap/ExtractDeviceRequest'
/// name = 'ExtractDeviceRequest'
/// status = 'draft'

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/DeviceRequest" alias DeviceRequest as target

group ExtractDeviceRequest(source qr : QR, target bundle : Bundle) {
  qr -> bundle.type = 'transaction' "setBundleType";
  // Subject, encounter, authored date, requester, identifier and the device extension all
  // live on the response itself, so the whole of it is carried into the build group rather
  // than the answer group alone.
  qr.item as requestGroup where (linkId = 'the-request') then {
    requestGroup ->  bundle.entry as entry,  entry.resource = create('DeviceRequest') as devReq then {
      qr ->  devReq,  entry then BuildDeviceRequest(qr, requestGroup, devReq, entry) "buildDevReq";
    } "createDevReq";
  } "findRequestGroup";
}

group BuildDeviceRequest(source qr : QR, source requestGroup, target devReq : DeviceRequest, target entry) {
  // The form has no sign-off step, so a submitted order is already actionable. If a
  // review step is added later this becomes 'draft', as it is on the medication order.
  qr -> devReq.status = 'active' "setStatus";
  qr.subject as s -> devReq.subject = s "setSubject";
  qr.encounter as enc -> devReq.encounter = enc "setEncounter";
  qr.authored as authored -> devReq.authoredOn = authored "setAuthoredOn";
  qr.source as src -> devReq.requester = src "setRequester";
  qr.identifier first as qrIdent -> devReq.identifier = qrIdent "copyIdentifier";
  // Device as CodeableReference from the QR extension (using concept). The ordering
  // client sets the device there rather than answering a form item, so this reads exactly
  // as the medication order map reads its medication concept. Assigning the whole
  // CodeableConcept carries its codings and their systems, so nothing further is copied.
  // `value`, not `valueCodeableConcept`: this engine resolves the choice element by its
  // base name and rejects the typed one outright --
  // "Attempt to read invalid property 'valueCodeableConcept' on type Extension" -- which
  // fails the whole transform, not just this rule. Same accessor every answer below uses.
  // The url is matched on its tail rather than in full: a map is published once at the
  // production canonical while the extension url is built from each environment's own
  // base, so an equality test would hold in production alone. Matching beats taking the
  // first extension, which silently reads whichever one the client happened to put first.
  qr.extension as ext where (url.endsWith('/StructureDefinition/device-reference')) then {
    ext.value as deviceCC -> devReq.code as code then {
      deviceCC -> code.concept = deviceCC "setDeviceConcept";
    } "accessDevice";
  } "findDeviceExt";
  // Intent. DeviceRequest.intent is a code, not a Coding: it takes the code alone and has
  // nowhere to record the system it came from.
  requestGroup.item as intentItem where (linkId = 'intent') then {
    intentItem.answer first as intentAns then {
      intentAns.value as intentCoding then {
        intentCoding.code as intentCode -> devReq.intent = intentCode "setIntentCode";
      } "extractIntentCode";
    } "extractIntent";
  } "findIntent";
  // Priority. Same shape as intent, and same reason.
  requestGroup.item as priorityItem where (linkId = 'priority') then {
    priorityItem.answer first as priorityAns then {
      priorityAns.value as priorityCoding then {
        priorityCoding.code as priorityCode -> devReq.priority = priorityCode "setPriorityCode";
      } "extractPriorityCode";
    } "extractPriority";
  } "findPriority";
  requestGroup.item as qtyItem where (linkId = 'quantity') then {
    qtyItem.answer first as qtyAns then {
      qtyAns.value as qtyValue -> devReq.quantity = qtyValue "setQuantity";
    } "extractQuantity";
  } "findQuantity";
  // How it is supplied. DeviceRequest has no element for this, so it becomes a parameter:
  // parameter.code names the question, parameter.value carries the answer.
  requestGroup.item as supplyItem where (linkId = 'supply-method') then {
    supplyItem.answer first as supplyAns then {
      supplyAns.value as supplyCoding -> devReq.parameter as param then {
        supplyCoding -> param.code = create('CodeableConcept') as paramCode then {
          supplyCoding -> paramCode.coding = create('Coding') as paramCoding then {
            supplyCoding -> paramCoding.system = 'https://fhir.slade360.co.ke/fhir/CodeSystem/device-order-codesystem' "setParamSystem";
            supplyCoding -> paramCoding.code = 'supply-method' "setParamCode";
            supplyCoding -> paramCoding.display = 'How the device is supplied' "setParamDisplay";
          } "buildParamCoding";
        } "buildParamCode";
        supplyCoding -> param.value = create('CodeableConcept') as paramValue then {
          supplyCoding -> paramValue.coding = supplyCoding "setParamValueCoding";
          supplyCoding.display as supplyDisp -> paramValue.text = supplyDisp "setParamValueText";
        } "buildParamValue";
      } "createParameter";
    } "extractSupply";
  } "findSupply";
  // Reason is free text on the form, so it lands as CodeableReference.concept.text with
  // no coding. A coded reason would need a value set the form does not offer.
  requestGroup.item as reasonItem where (linkId = 'reason') then {
    reasonItem.answer first as reasonAns then {
      reasonAns.value as reasonText ->  devReq.reason as reasonRef,  reasonRef.concept as reasonCC then {
        reasonText -> reasonCC.text = reasonText "setReasonText";
      } "setReason";
    } "extractReason";
  } "findReason";
  // Patient instruction. DeviceRequest has no equivalent of Dosage.patientInstruction, so
  // this rides a local extension rather than collapsing into note alongside the message
  // written for the dispensing team.
  requestGroup.item as instructionItem where (linkId = 'patient-instructions') then {
    instructionItem.answer first as instructionAns then {
      instructionAns.value as instructionText -> devReq.extension as instructionExt then {
        instructionText -> instructionExt.url = 'https://fhir.slade360.co.ke/fhir/StructureDefinition/sghi-device-patient-instruction' "setInstructionExtUrl";
        instructionText -> instructionExt.value = instructionText "setInstructionExtValue";
      } "createInstructionExt";
    } "extractInstruction";
  } "findInstruction";
  requestGroup.item as notesItem where (linkId = 'notes') then {
    notesItem.answer first as notesAns then {
      notesAns.value as notesText -> devReq.note as note then {
        notesText -> note.text = notesText "setNoteText";
      } "createNote";
    } "extractNotes";
  } "findNotes";
  qr -> devReq.id = uuid() then SetDeviceRequestFullUrl(devReq, entry) "setDevReqIdAndFullUrl";
  qr -> entry.request as request then {
    qr -> request.method = 'POST' "reqMethod";
    qr -> request.url = 'DeviceRequest' "reqUrl";
  } "entryRequest";
}

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


Source1

{
  "resourceType": "StructureMap",
  "id": "ExtractDeviceRequest",
  "text": {
    "status": "generated",
    "div": "<!-- snip (see above) -->"
  },
  "url": "https://fhir.slade360.co.ke/fhir/StructureMap/ExtractDeviceRequest",
  "version": "0.1.0",
  "name": "ExtractDeviceRequest",
  "status": "draft",
  "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"
        }
      ]
    }
  ],
  "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/DeviceRequest",
      "mode": "target",
      "alias": "DeviceRequest"
    }
  ],
  "group": [
    {
      "name": "ExtractDeviceRequest",
      "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": "findRequestGroup",
          "source": [
            {
              "context": "qr",
              "element": "item",
              "variable": "requestGroup",
              "condition": "linkId = 'the-request'"
            }
          ],
          "rule": [
            {
              "name": "createDevReq",
              "source": [
                {
                  "context": "requestGroup"
                }
              ],
              "target": [
                {
                  "context": "bundle",
                  "element": "entry",
                  "variable": "entry"
                },
                {
                  "context": "entry",
                  "element": "resource",
                  "variable": "devReq",
                  "transform": "create",
                  "parameter": [
                    {
                      "valueString": "DeviceRequest"
                    }
                  ]
                }
              ],
              "rule": [
                {
                  "name": "buildDevReq",
                  "source": [
                    {
                      "context": "qr"
                    }
                  ],
                  "target": [
                    {
                      "context": "devReq"
                    },
                    {
                      "context": "entry"
                    }
                  ],
                  "dependent": [
                    {
                      "name": "BuildDeviceRequest",
                      "parameter": [
                        {
                          "valueId": "qr"
                        },
                        {
                          "valueId": "requestGroup"
                        },
                        {
                          "valueId": "devReq"
                        },
                        {
                          "valueId": "entry"
                        }
                      ]
                    }
                  ]
                }
              ]
            }
          ],
          "documentation": "Subject, encounter, authored date, requester, identifier and the device extension all\r\nlive on the response itself, so the whole of it is carried into the build group rather\r\nthan the answer group alone."
        }
      ]
    },
    {
      "name": "BuildDeviceRequest",
      "input": [
        {
          "name": "qr",
          "type": "QR",
          "mode": "source"
        },
        {
          "name": "requestGroup",
          "mode": "source"
        },
        {
          "name": "devReq",
          "type": "DeviceRequest",
          "mode": "target"
        },
        {
          "name": "entry",
          "mode": "target"
        }
      ],
      "rule": [
        {
          "name": "setStatus",
          "source": [
            {
              "context": "qr"
            }
          ],
          "target": [
            {
              "context": "devReq",
              "element": "status",
              "transform": "copy",
              "parameter": [
                {
                  "valueString": "active"
                }
              ]
            }
          ],
          "documentation": "The form has no sign-off step, so a submitted order is already actionable. If a\r\nreview step is added later this becomes 'draft', as it is on the medication order."
        },
        {
          "name": "setSubject",
          "source": [
            {
              "context": "qr",
              "element": "subject",
              "variable": "s"
            }
          ],
          "target": [
            {
              "context": "devReq",
              "element": "subject",
              "transform": "copy",
              "parameter": [
                {
                  "valueId": "s"
                }
              ]
            }
          ]
        },
        {
          "name": "setEncounter",
          "source": [
            {
              "context": "qr",
              "element": "encounter",
              "variable": "enc"
            }
          ],
          "target": [
            {
              "context": "devReq",
              "element": "encounter",
              "transform": "copy",
              "parameter": [
                {
                  "valueId": "enc"
                }
              ]
            }
          ]
        },
        {
          "name": "setAuthoredOn",
          "source": [
            {
              "context": "qr",
              "element": "authored",
              "variable": "authored"
            }
          ],
          "target": [
            {
              "context": "devReq",
              "element": "authoredOn",
              "transform": "copy",
              "parameter": [
                {
                  "valueId": "authored"
                }
              ]
            }
          ]
        },
        {
          "name": "setRequester",
          "source": [
            {
              "context": "qr",
              "element": "source",
              "variable": "src"
            }
          ],
          "target": [
            {
              "context": "devReq",
              "element": "requester",
              "transform": "copy",
              "parameter": [
                {
                  "valueId": "src"
                }
              ]
            }
          ]
        },
        {
          "name": "copyIdentifier",
          "source": [
            {
              "context": "qr",
              "element": "identifier",
              "listMode": "first",
              "variable": "qrIdent"
            }
          ],
          "target": [
            {
              "context": "devReq",
              "element": "identifier",
              "transform": "copy",
              "parameter": [
                {
                  "valueId": "qrIdent"
                }
              ]
            }
          ]
        },
        {
          "name": "findDeviceExt",
          "source": [
            {
              "context": "qr",
              "element": "extension",
              "variable": "ext",
              "condition": "url.endsWith('/StructureDefinition/device-reference')"
            }
          ],
          "rule": [
            {
              "name": "accessDevice",
              "source": [
                {
                  "context": "ext",
                  "element": "value",
                  "variable": "deviceCC"
                }
              ],
              "target": [
                {
                  "context": "devReq",
                  "element": "code",
                  "variable": "code"
                }
              ],
              "rule": [
                {
                  "name": "setDeviceConcept",
                  "source": [
                    {
                      "context": "deviceCC"
                    }
                  ],
                  "target": [
                    {
                      "context": "code",
                      "element": "concept",
                      "transform": "copy",
                      "parameter": [
                        {
                          "valueId": "deviceCC"
                        }
                      ]
                    }
                  ]
                }
              ]
            }
          ],
          "documentation": "Device as CodeableReference from the QR extension (using concept). The ordering\r\nclient sets the device there rather than answering a form item, so this reads exactly\r\nas the medication order map reads its medication concept. Assigning the whole\r\nCodeableConcept carries its codings and their systems, so nothing further is copied.\r\n`value`, not `valueCodeableConcept`: this engine resolves the choice element by its\r\nbase name and rejects the typed one outright --\r\n\"Attempt to read invalid property 'valueCodeableConcept' on type Extension\" -- which\r\nfails the whole transform, not just this rule. Same accessor every answer below uses.\r\nThe url is matched on its tail rather than in full: a map is published once at the\r\nproduction canonical while the extension url is built from each environment's own\r\nbase, so an equality test would hold in production alone. Matching beats taking the\r\nfirst extension, which silently reads whichever one the client happened to put first."
        },
        {
          "name": "findIntent",
          "source": [
            {
              "context": "requestGroup",
              "element": "item",
              "variable": "intentItem",
              "condition": "linkId = 'intent'"
            }
          ],
          "rule": [
            {
              "name": "extractIntent",
              "source": [
                {
                  "context": "intentItem",
                  "element": "answer",
                  "listMode": "first",
                  "variable": "intentAns"
                }
              ],
              "rule": [
                {
                  "name": "extractIntentCode",
                  "source": [
                    {
                      "context": "intentAns",
                      "element": "value",
                      "variable": "intentCoding"
                    }
                  ],
                  "rule": [
                    {
                      "name": "setIntentCode",
                      "source": [
                        {
                          "context": "intentCoding",
                          "element": "code",
                          "variable": "intentCode"
                        }
                      ],
                      "target": [
                        {
                          "context": "devReq",
                          "element": "intent",
                          "transform": "copy",
                          "parameter": [
                            {
                              "valueId": "intentCode"
                            }
                          ]
                        }
                      ]
                    }
                  ]
                }
              ]
            }
          ],
          "documentation": "Intent. DeviceRequest.intent is a code, not a Coding: it takes the code alone and has\r\nnowhere to record the system it came from."
        },
        {
          "name": "findPriority",
          "source": [
            {
              "context": "requestGroup",
              "element": "item",
              "variable": "priorityItem",
              "condition": "linkId = 'priority'"
            }
          ],
          "rule": [
            {
              "name": "extractPriority",
              "source": [
                {
                  "context": "priorityItem",
                  "element": "answer",
                  "listMode": "first",
                  "variable": "priorityAns"
                }
              ],
              "rule": [
                {
                  "name": "extractPriorityCode",
                  "source": [
                    {
                      "context": "priorityAns",
                      "element": "value",
                      "variable": "priorityCoding"
                    }
                  ],
                  "rule": [
                    {
                      "name": "setPriorityCode",
                      "source": [
                        {
                          "context": "priorityCoding",
                          "element": "code",
                          "variable": "priorityCode"
                        }
                      ],
                      "target": [
                        {
                          "context": "devReq",
                          "element": "priority",
                          "transform": "copy",
                          "parameter": [
                            {
                              "valueId": "priorityCode"
                            }
                          ]
                        }
                      ]
                    }
                  ]
                }
              ]
            }
          ],
          "documentation": "Priority. Same shape as intent, and same reason."
        },
        {
          "name": "findQuantity",
          "source": [
            {
              "context": "requestGroup",
              "element": "item",
              "variable": "qtyItem",
              "condition": "linkId = 'quantity'"
            }
          ],
          "rule": [
            {
              "name": "extractQuantity",
              "source": [
                {
                  "context": "qtyItem",
                  "element": "answer",
                  "listMode": "first",
                  "variable": "qtyAns"
                }
              ],
              "rule": [
                {
                  "name": "setQuantity",
                  "source": [
                    {
                      "context": "qtyAns",
                      "element": "value",
                      "variable": "qtyValue"
                    }
                  ],
                  "target": [
                    {
                      "context": "devReq",
                      "element": "quantity",
                      "transform": "copy",
                      "parameter": [
                        {
                          "valueId": "qtyValue"
                        }
                      ]
                    }
                  ]
                }
              ]
            }
          ]
        },
        {
          "name": "findSupply",
          "source": [
            {
              "context": "requestGroup",
              "element": "item",
              "variable": "supplyItem",
              "condition": "linkId = 'supply-method'"
            }
          ],
          "rule": [
            {
              "name": "extractSupply",
              "source": [
                {
                  "context": "supplyItem",
                  "element": "answer",
                  "listMode": "first",
                  "variable": "supplyAns"
                }
              ],
              "rule": [
                {
                  "name": "createParameter",
                  "source": [
                    {
                      "context": "supplyAns",
                      "element": "value",
                      "variable": "supplyCoding"
                    }
                  ],
                  "target": [
                    {
                      "context": "devReq",
                      "element": "parameter",
                      "variable": "param"
                    }
                  ],
                  "rule": [
                    {
                      "name": "buildParamCode",
                      "source": [
                        {
                          "context": "supplyCoding"
                        }
                      ],
                      "target": [
                        {
                          "context": "param",
                          "element": "code",
                          "variable": "paramCode",
                          "transform": "create",
                          "parameter": [
                            {
                              "valueString": "CodeableConcept"
                            }
                          ]
                        }
                      ],
                      "rule": [
                        {
                          "name": "buildParamCoding",
                          "source": [
                            {
                              "context": "supplyCoding"
                            }
                          ],
                          "target": [
                            {
                              "context": "paramCode",
                              "element": "coding",
                              "variable": "paramCoding",
                              "transform": "create",
                              "parameter": [
                                {
                                  "valueString": "Coding"
                                }
                              ]
                            }
                          ],
                          "rule": [
                            {
                              "name": "setParamSystem",
                              "source": [
                                {
                                  "context": "supplyCoding"
                                }
                              ],
                              "target": [
                                {
                                  "context": "paramCoding",
                                  "element": "system",
                                  "transform": "copy",
                                  "parameter": [
                                    {
                                      "valueString": "https://fhir.slade360.co.ke/fhir/CodeSystem/device-order-codesystem"
                                    }
                                  ]
                                }
                              ]
                            },
                            {
                              "name": "setParamCode",
                              "source": [
                                {
                                  "context": "supplyCoding"
                                }
                              ],
                              "target": [
                                {
                                  "context": "paramCoding",
                                  "element": "code",
                                  "transform": "copy",
                                  "parameter": [
                                    {
                                      "valueString": "supply-method"
                                    }
                                  ]
                                }
                              ]
                            },
                            {
                              "name": "setParamDisplay",
                              "source": [
                                {
                                  "context": "supplyCoding"
                                }
                              ],
                              "target": [
                                {
                                  "context": "paramCoding",
                                  "element": "display",
                                  "transform": "copy",
                                  "parameter": [
                                    {
                                      "valueString": "How the device is supplied"
                                    }
                                  ]
                                }
                              ]
                            }
                          ]
                        }
                      ]
                    },
                    {
                      "name": "buildParamValue",
                      "source": [
                        {
                          "context": "supplyCoding"
                        }
                      ],
                      "target": [
                        {
                          "context": "param",
                          "element": "value",
                          "variable": "paramValue",
                          "transform": "create",
                          "parameter": [
                            {
                              "valueString": "CodeableConcept"
                            }
                          ]
                        }
                      ],
                      "rule": [
                        {
                          "name": "setParamValueCoding",
                          "source": [
                            {
                              "context": "supplyCoding"
                            }
                          ],
                          "target": [
                            {
                              "context": "paramValue",
                              "element": "coding",
                              "transform": "copy",
                              "parameter": [
                                {
                                  "valueId": "supplyCoding"
                                }
                              ]
                            }
                          ]
                        },
                        {
                          "name": "setParamValueText",
                          "source": [
                            {
                              "context": "supplyCoding",
                              "element": "display",
                              "variable": "supplyDisp"
                            }
                          ],
                          "target": [
                            {
                              "context": "paramValue",
                              "element": "text",
                              "transform": "copy",
                              "parameter": [
                                {
                                  "valueId": "supplyDisp"
                                }
                              ]
                            }
                          ]
                        }
                      ]
                    }
                  ]
                }
              ]
            }
          ],
          "documentation": "How it is supplied. DeviceRequest has no element for this, so it becomes a parameter:\r\nparameter.code names the question, parameter.value carries the answer."
        },
        {
          "name": "findReason",
          "source": [
            {
              "context": "requestGroup",
              "element": "item",
              "variable": "reasonItem",
              "condition": "linkId = 'reason'"
            }
          ],
          "rule": [
            {
              "name": "extractReason",
              "source": [
                {
                  "context": "reasonItem",
                  "element": "answer",
                  "listMode": "first",
                  "variable": "reasonAns"
                }
              ],
              "rule": [
                {
                  "name": "setReason",
                  "source": [
                    {
                      "context": "reasonAns",
                      "element": "value",
                      "variable": "reasonText"
                    }
                  ],
                  "target": [
                    {
                      "context": "devReq",
                      "element": "reason",
                      "variable": "reasonRef"
                    },
                    {
                      "context": "reasonRef",
                      "element": "concept",
                      "variable": "reasonCC"
                    }
                  ],
                  "rule": [
                    {
                      "name": "setReasonText",
                      "source": [
                        {
                          "context": "reasonText"
                        }
                      ],
                      "target": [
                        {
                          "context": "reasonCC",
                          "element": "text",
                          "transform": "copy",
                          "parameter": [
                            {
                              "valueId": "reasonText"
                            }
                          ]
                        }
                      ]
                    }
                  ]
                }
              ]
            }
          ],
          "documentation": "Reason is free text on the form, so it lands as CodeableReference.concept.text with\r\nno coding. A coded reason would need a value set the form does not offer."
        },
        {
          "name": "findInstruction",
          "source": [
            {
              "context": "requestGroup",
              "element": "item",
              "variable": "instructionItem",
              "condition": "linkId = 'patient-instructions'"
            }
          ],
          "rule": [
            {
              "name": "extractInstruction",
              "source": [
                {
                  "context": "instructionItem",
                  "element": "answer",
                  "listMode": "first",
                  "variable": "instructionAns"
                }
              ],
              "rule": [
                {
                  "name": "createInstructionExt",
                  "source": [
                    {
                      "context": "instructionAns",
                      "element": "value",
                      "variable": "instructionText"
                    }
                  ],
                  "target": [
                    {
                      "context": "devReq",
                      "element": "extension",
                      "variable": "instructionExt"
                    }
                  ],
                  "rule": [
                    {
                      "name": "setInstructionExtUrl",
                      "source": [
                        {
                          "context": "instructionText"
                        }
                      ],
                      "target": [
                        {
                          "context": "instructionExt",
                          "element": "url",
                          "transform": "copy",
                          "parameter": [
                            {
                              "valueString": "https://fhir.slade360.co.ke/fhir/StructureDefinition/sghi-device-patient-instruction"
                            }
                          ]
                        }
                      ]
                    },
                    {
                      "name": "setInstructionExtValue",
                      "source": [
                        {
                          "context": "instructionText"
                        }
                      ],
                      "target": [
                        {
                          "context": "instructionExt",
                          "element": "value",
                          "transform": "copy",
                          "parameter": [
                            {
                              "valueId": "instructionText"
                            }
                          ]
                        }
                      ]
                    }
                  ]
                }
              ]
            }
          ],
          "documentation": "Patient instruction. DeviceRequest has no equivalent of Dosage.patientInstruction, so\r\nthis rides a local extension rather than collapsing into note alongside the message\r\nwritten for the dispensing team."
        },
        {
          "name": "findNotes",
          "source": [
            {
              "context": "requestGroup",
              "element": "item",
              "variable": "notesItem",
              "condition": "linkId = 'notes'"
            }
          ],
          "rule": [
            {
              "name": "extractNotes",
              "source": [
                {
                  "context": "notesItem",
                  "element": "answer",
                  "listMode": "first",
                  "variable": "notesAns"
                }
              ],
              "rule": [
                {
                  "name": "createNote",
                  "source": [
                    {
                      "context": "notesAns",
                      "element": "value",
                      "variable": "notesText"
                    }
                  ],
                  "target": [
                    {
                      "context": "devReq",
                      "element": "note",
                      "variable": "note"
                    }
                  ],
                  "rule": [
                    {
                      "name": "setNoteText",
                      "source": [
                        {
                          "context": "notesText"
                        }
                      ],
                      "target": [
                        {
                          "context": "note",
                          "element": "text",
                          "transform": "copy",
                          "parameter": [
                            {
                              "valueId": "notesText"
                            }
                          ]
                        }
                      ]
                    }
                  ]
                }
              ]
            }
          ]
        },
        {
          "name": "setDevReqIdAndFullUrl",
          "source": [
            {
              "context": "qr"
            }
          ],
          "target": [
            {
              "context": "devReq",
              "element": "id",
              "transform": "uuid"
            }
          ],
          "dependent": [
            {
              "name": "SetDeviceRequestFullUrl",
              "parameter": [
                {
                  "valueId": "devReq"
                },
                {
                  "valueId": "entry"
                }
              ]
            }
          ]
        },
        {
          "name": "entryRequest",
          "source": [
            {
              "context": "qr"
            }
          ],
          "target": [
            {
              "context": "entry",
              "element": "request",
              "variable": "request"
            }
          ],
          "rule": [
            {
              "name": "reqMethod",
              "source": [
                {
                  "context": "qr"
                }
              ],
              "target": [
                {
                  "context": "request",
                  "element": "method",
                  "transform": "copy",
                  "parameter": [
                    {
                      "valueString": "POST"
                    }
                  ]
                }
              ]
            },
            {
              "name": "reqUrl",
              "source": [
                {
                  "context": "qr"
                }
              ],
              "target": [
                {
                  "context": "request",
                  "element": "url",
                  "transform": "copy",
                  "parameter": [
                    {
                      "valueString": "DeviceRequest"
                    }
                  ]
                }
              ]
            }
          ]
        }
      ]
    },
    {
      "name": "SetDeviceRequestFullUrl",
      "input": [
        {
          "name": "devReq",
          "type": "DeviceRequest",
          "mode": "source"
        },
        {
          "name": "entry",
          "mode": "target"
        }
      ],
      "rule": [
        {
          "name": "assignFullUrl",
          "source": [
            {
              "context": "devReq",
              "element": "id",
              "variable": "id"
            }
          ],
          "target": [
            {
              "context": "entry",
              "element": "fullUrl",
              "transform": "append",
              "parameter": [
                {
                  "valueString": "https://fhir.slade360.co.ke/fhir/DeviceRequest/"
                },
                {
                  "valueId": "id"
                }
              ]
            }
          ]
        }
      ]
    }
  ]
}