# ExtractMedicationRequest - SGHI FHIR Profile Implementation Guide v0.1.0

* [**Table of Contents**](toc.md)
* [**Artifacts Summary**](artifacts.md)
* **ExtractMedicationRequest**

## StructureMap: ExtractMedicationRequest 

| | |
| :--- | :--- |
| *Official URL*:https://fhir.slade360.co.ke/fhir/StructureMap/ExtractMedicationRequest | *Version*:0.1.0 |
| Draft as of 2026-04-27 | *Computable Name*:ExtractMedicationRequest |



## Resource Content

```json
{
  "resourceType" : "StructureMap",
  "id" : "ExtractMedicationRequest",
  "url" : "https://fhir.slade360.co.ke/fhir/StructureMap/ExtractMedicationRequest",
  "version" : "0.1.0",
  "name" : "ExtractMedicationRequest",
  "status" : "draft",
  "date" : "2026-04-27T09:21:43+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/MedicationRequest",
    "mode" : "target",
    "alias" : "MedicationRequest"
  },
  {
    "url" : "http://hl7.org/fhir/StructureDefinition/Medication",
    "mode" : "target",
    "alias" : "Medication"
  }],
  "group" : [{
    "name" : "ExtractMedicationRequest",
    "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" : "findPrescriptionGroup",
      "source" : [{
        "context" : "qr",
        "element" : "item",
        "variable" : "prescriptionGroup",
        "condition" : "(linkId = 'prescription-form')"
      }],
      "rule" : [{
        "name" : "createMedReq",
        "source" : [{
          "context" : "prescriptionGroup"
        }],
        "target" : [{
          "context" : "bundle",
          "element" : "entry",
          "variable" : "entry"
        },
        {
          "context" : "entry",
          "element" : "resource",
          "variable" : "medReq",
          "transform" : "create",
          "parameter" : [{
            "valueString" : "MedicationRequest"
          }]
        }],
        "rule" : [{
          "name" : "buildMedReq",
          "source" : [{
            "context" : "qr"
          }],
          "target" : [{
            "transform" : "copy",
            "parameter" : [{
              "valueId" : "medReq"
            }]
          },
          {
            "transform" : "copy",
            "parameter" : [{
              "valueId" : "entry"
            }]
          }],
          "dependent" : [{
            "name" : "BuildMedicationRequest",
            "parameter" : [{
              "valueId" : "qr"
            },
            {
              "valueId" : "prescriptionGroup"
            },
            {
              "valueId" : "medReq"
            },
            {
              "valueId" : "entry"
            }]
          }]
        }]
      }]
    }]
  },
  {
    "name" : "BuildMedicationRequest",
    "input" : [{
      "name" : "qr",
      "type" : "QR",
      "mode" : "source"
    },
    {
      "name" : "prescriptionGroup",
      "mode" : "source"
    },
    {
      "name" : "medReq",
      "type" : "MedicationRequest",
      "mode" : "target"
    },
    {
      "name" : "entry",
      "mode" : "target"
    }],
    "rule" : [{
      "name" : "setStatus",
      "source" : [{
        "context" : "qr"
      }],
      "target" : [{
        "context" : "medReq",
        "element" : "status",
        "transform" : "copy",
        "parameter" : [{
          "valueString" : "draft"
        }]
      }],
      "documentation" : "status will always be draft until medication has been signed off"
    },
    {
      "name" : "setIntent",
      "source" : [{
        "context" : "qr"
      }],
      "target" : [{
        "context" : "medReq",
        "element" : "intent",
        "transform" : "copy",
        "parameter" : [{
          "valueString" : "order"
        }]
      }]
    },
    {
      "name" : "setSubject",
      "source" : [{
        "context" : "qr",
        "element" : "subject",
        "variable" : "s"
      }],
      "target" : [{
        "context" : "medReq",
        "element" : "subject",
        "transform" : "copy",
        "parameter" : [{
          "valueId" : "s"
        }]
      }],
      "documentation" : "Subject from QuestionnaireResponse"
    },
    {
      "name" : "setEncounter",
      "source" : [{
        "context" : "qr",
        "element" : "encounter",
        "variable" : "enc"
      }],
      "target" : [{
        "context" : "medReq",
        "element" : "encounter",
        "transform" : "copy",
        "parameter" : [{
          "valueId" : "enc"
        }]
      }],
      "documentation" : "Encounter from QuestionnaireResponse"
    },
    {
      "name" : "setAuthoredOn",
      "source" : [{
        "context" : "qr",
        "element" : "authored",
        "variable" : "authored"
      }],
      "target" : [{
        "context" : "medReq",
        "element" : "authoredOn",
        "transform" : "copy",
        "parameter" : [{
          "valueId" : "authored"
        }]
      }],
      "documentation" : "AuthoredOn from QuestionnaireResponse.authored"
    },
    {
      "name" : "setRequester",
      "source" : [{
        "context" : "qr",
        "element" : "source",
        "variable" : "src"
      }],
      "target" : [{
        "context" : "medReq",
        "element" : "requester",
        "transform" : "copy",
        "parameter" : [{
          "valueId" : "src"
        }]
      }],
      "documentation" : "Requester from QuestionnaireResponse.source (the Organization)"
    },
    {
      "name" : "copyIdentifier",
      "source" : [{
        "context" : "qr",
        "element" : "identifier",
        "listMode" : "first",
        "variable" : "qrIdent"
      }],
      "target" : [{
        "context" : "medReq",
        "element" : "identifier",
        "transform" : "copy",
        "parameter" : [{
          "valueId" : "qrIdent"
        }]
      }],
      "documentation" : "Copy identifier from QuestionnaireResponse to MedicationRequest"
    },
    {
      "name" : "findMedicationExt",
      "source" : [{
        "context" : "qr",
        "element" : "extension",
        "listMode" : "first",
        "variable" : "ext"
      }],
      "rule" : [{
        "name" : "accessMedication",
        "source" : [{
          "context" : "ext",
          "element" : "valueCodeableConcept",
          "variable" : "medCC"
        }],
        "target" : [{
          "context" : "medReq",
          "element" : "medication",
          "variable" : "med"
        }],
        "rule" : [{
          "name" : "setMedConcept",
          "source" : [{
            "context" : "medCC"
          }],
          "target" : [{
            "context" : "med",
            "element" : "concept",
            "transform" : "copy",
            "parameter" : [{
              "valueId" : "medCC"
            }]
          }]
        }]
      }],
      "documentation" : "Medication as CodeableReference from QR extension (using concept)"
    },
    {
      "name" : "findPriority",
      "source" : [{
        "context" : "prescriptionGroup",
        "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" : "valueCoding",
            "variable" : "priorityCoding"
          }],
          "rule" : [{
            "name" : "setPriorityCode",
            "source" : [{
              "context" : "priorityCoding",
              "element" : "code",
              "variable" : "pCode"
            }],
            "target" : [{
              "context" : "medReq",
              "element" : "priority",
              "transform" : "copy",
              "parameter" : [{
                "valueId" : "pCode"
              }]
            }]
          }]
        }]
      }],
      "documentation" : "Priority"
    },
    {
      "name" : "createDosage",
      "source" : [{
        "context" : "qr"
      }],
      "target" : [{
        "context" : "medReq",
        "element" : "dosageInstruction",
        "variable" : "dosage",
        "transform" : "create",
        "parameter" : [{
          "valueString" : "Dosage"
        }]
      }],
      "rule" : [{
        "name" : "buildDosage",
        "source" : [{
          "context" : "prescriptionGroup"
        }],
        "target" : [{
          "transform" : "copy",
          "parameter" : [{
            "valueId" : "dosage"
          }]
        }],
        "dependent" : [{
          "name" : "BuildDosage",
          "parameter" : [{
            "valueId" : "prescriptionGroup"
          },
          {
            "valueId" : "dosage"
          }]
        }]
      }],
      "documentation" : "Dosage Instruction"
    },
    {
      "name" : "findSubst",
      "source" : [{
        "context" : "prescriptionGroup",
        "element" : "item",
        "variable" : "substItem",
        "condition" : "(linkId = 'substitutable')"
      }],
      "rule" : [{
        "name" : "extractSubst",
        "source" : [{
          "context" : "substItem",
          "element" : "answer",
          "listMode" : "first",
          "variable" : "substAns"
        }],
        "rule" : [{
          "name" : "createSubst",
          "source" : [{
            "context" : "substAns",
            "element" : "valueBoolean",
            "variable" : "substBool"
          }],
          "target" : [{
            "context" : "medReq",
            "element" : "substitution",
            "variable" : "subst"
          }],
          "rule" : [{
            "name" : "setSubstValue",
            "source" : [{
              "context" : "substBool"
            }],
            "target" : [{
              "context" : "subst",
              "element" : "allowedBoolean",
              "transform" : "copy",
              "parameter" : [{
                "valueId" : "substBool"
              }]
            }]
          }]
        }]
      }],
      "documentation" : "Substitution"
    },
    {
      "name" : "createDispReq",
      "source" : [{
        "context" : "qr"
      }],
      "target" : [{
        "context" : "medReq",
        "element" : "dispenseRequest",
        "variable" : "dispReq"
      }],
      "rule" : [{
        "name" : "buildDispReq",
        "source" : [{
          "context" : "prescriptionGroup"
        }],
        "target" : [{
          "transform" : "copy",
          "parameter" : [{
            "valueId" : "dispReq"
          }]
        }],
        "dependent" : [{
          "name" : "BuildDispenseRequest",
          "parameter" : [{
            "valueId" : "qr"
          },
          {
            "valueId" : "prescriptionGroup"
          },
          {
            "valueId" : "dispReq"
          }]
        }]
      }],
      "documentation" : "Dispense Request"
    },
    {
      "name" : "setMedReqIdAndFullUrl",
      "source" : [{
        "context" : "qr"
      }],
      "target" : [{
        "context" : "medReq",
        "element" : "id",
        "transform" : "uuid"
      }],
      "dependent" : [{
        "name" : "SetMedicationRequestFullUrl",
        "parameter" : [{
          "valueId" : "medReq"
        },
        {
          "valueId" : "entry"
        }]
      }],
      "documentation" : "Set ID and FullUrl"
    },
    {
      "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" : "MedicationRequest"
          }]
        }]
      }],
      "documentation" : "Entry request for transaction bundle"
    }]
  },
  {
    "name" : "BuildDosage",
    "input" : [{
      "name" : "prescriptionGroup",
      "mode" : "source"
    },
    {
      "name" : "dosage",
      "type" : "Dosage",
      "mode" : "target"
    }],
    "rule" : [{
      "name" : "accessTiming",
      "source" : [{
        "context" : "prescriptionGroup"
      }],
      "target" : [{
        "context" : "dosage",
        "element" : "timing",
        "variable" : "timing"
      }],
      "rule" : [{
        "name" : "accessRepeat",
        "source" : [{
          "context" : "prescriptionGroup"
        }],
        "target" : [{
          "context" : "timing",
          "element" : "repeat",
          "variable" : "repeat"
        }],
        "rule" : [{
          "name" : "findFreq",
          "source" : [{
            "context" : "prescriptionGroup",
            "element" : "item",
            "variable" : "freqItem",
            "condition" : "(linkId = 'frequency')"
          }],
          "rule" : [{
            "name" : "extractFreq",
            "source" : [{
              "context" : "freqItem",
              "element" : "answer",
              "listMode" : "first",
              "variable" : "freqAns"
            }],
            "rule" : [{
              "name" : "setFreqOD",
              "source" : [{
                "context" : "freqAns",
                "element" : "valueCoding",
                "variable" : "freqCoding",
                "condition" : "(code = 'OD')"
              }],
              "target" : [{
                "context" : "repeat",
                "element" : "frequency",
                "transform" : "copy",
                "parameter" : [{
                  "valueString" : "1"
                }]
              }]
            },
            {
              "name" : "setFreqBD",
              "source" : [{
                "context" : "freqAns",
                "element" : "valueCoding",
                "variable" : "freqCoding",
                "condition" : "(code = 'BD')"
              }],
              "target" : [{
                "context" : "repeat",
                "element" : "frequency",
                "transform" : "copy",
                "parameter" : [{
                  "valueString" : "2"
                }]
              }]
            },
            {
              "name" : "setFreqTID",
              "source" : [{
                "context" : "freqAns",
                "element" : "valueCoding",
                "variable" : "freqCoding",
                "condition" : "(code = 'TID')"
              }],
              "target" : [{
                "context" : "repeat",
                "element" : "frequency",
                "transform" : "copy",
                "parameter" : [{
                  "valueString" : "3"
                }]
              }]
            },
            {
              "name" : "setFreqQID",
              "source" : [{
                "context" : "freqAns",
                "element" : "valueCoding",
                "variable" : "freqCoding",
                "condition" : "(code = 'QID')"
              }],
              "target" : [{
                "context" : "repeat",
                "element" : "frequency",
                "transform" : "copy",
                "parameter" : [{
                  "valueString" : "4"
                }]
              }]
            }]
          }],
          "documentation" : "Frequency (OD, BD, TID, QID)"
        },
        {
          "name" : "setPeriod",
          "source" : [{
            "context" : "prescriptionGroup"
          }],
          "target" : [{
            "context" : "repeat",
            "element" : "period",
            "transform" : "copy",
            "parameter" : [{
              "valueString" : "1"
            }]
          }],
          "documentation" : "Period (1 day)"
        },
        {
          "name" : "setPeriodUnit",
          "source" : [{
            "context" : "prescriptionGroup"
          }],
          "target" : [{
            "context" : "repeat",
            "element" : "periodUnit",
            "transform" : "copy",
            "parameter" : [{
              "valueString" : "d"
            }]
          }]
        },
        {
          "name" : "findDuration",
          "source" : [{
            "context" : "prescriptionGroup",
            "element" : "item",
            "variable" : "durItem",
            "condition" : "(linkId = 'duration')"
          }],
          "rule" : [{
            "name" : "extractDuration",
            "source" : [{
              "context" : "durItem",
              "element" : "answer",
              "listMode" : "first",
              "variable" : "durAns"
            }],
            "rule" : [{
              "name" : "setDuration",
              "source" : [{
                "context" : "durAns",
                "element" : "valueInteger",
                "variable" : "durValue"
              }],
              "target" : [{
                "context" : "repeat",
                "element" : "duration",
                "transform" : "copy",
                "parameter" : [{
                  "valueId" : "durValue"
                }]
              }]
            }]
          }],
          "documentation" : "Duration"
        },
        {
          "name" : "findDurUom",
          "source" : [{
            "context" : "prescriptionGroup",
            "element" : "item",
            "variable" : "durUomItem",
            "condition" : "(linkId = 'duration-uom')"
          }],
          "rule" : [{
            "name" : "extractDurUom",
            "source" : [{
              "context" : "durUomItem",
              "element" : "answer",
              "listMode" : "first",
              "variable" : "durUomAns"
            }],
            "rule" : [{
              "name" : "extractDurUomCode",
              "source" : [{
                "context" : "durUomAns",
                "element" : "valueCoding",
                "variable" : "durUomCoding"
              }],
              "rule" : [{
                "name" : "setDurationUnit",
                "source" : [{
                  "context" : "durUomCoding",
                  "element" : "code",
                  "variable" : "durUomCode"
                }],
                "target" : [{
                  "context" : "repeat",
                  "element" : "durationUnit",
                  "transform" : "copy",
                  "parameter" : [{
                    "valueId" : "durUomCode"
                  }]
                }]
              }]
            }]
          }],
          "documentation" : "Duration UOM - directly use the code from unitsofmeasure.org (h, d, wk, mo, a)"
        },
        {
          "name" : "findWhen",
          "source" : [{
            "context" : "prescriptionGroup",
            "element" : "item",
            "variable" : "whenItem",
            "condition" : "(linkId = 'when-to-take')"
          }],
          "rule" : [{
            "name" : "extractWhen",
            "source" : [{
              "context" : "whenItem",
              "element" : "answer",
              "listMode" : "first",
              "variable" : "whenAns"
            }],
            "rule" : [{
              "name" : "extractWhenCode",
              "source" : [{
                "context" : "whenAns",
                "element" : "valueCoding",
                "variable" : "whenCoding"
              }],
              "rule" : [{
                "name" : "setWhenCode",
                "source" : [{
                  "context" : "whenCoding",
                  "element" : "code",
                  "variable" : "whenCode"
                }],
                "target" : [{
                  "context" : "repeat",
                  "element" : "when",
                  "transform" : "copy",
                  "parameter" : [{
                    "valueId" : "whenCode"
                  }]
                }]
              }]
            }]
          }],
          "documentation" : "When to take - directly use the code (AC, PC, ACM, ACD, ACV, PCM, PCD, PCV, etc.)"
        },
        {
          "name" : "findStartDate",
          "source" : [{
            "context" : "prescriptionGroup",
            "element" : "item",
            "variable" : "startItem",
            "condition" : "(linkId = 'start-date')"
          }],
          "rule" : [{
            "name" : "extractStartDate",
            "source" : [{
              "context" : "startItem",
              "element" : "answer",
              "listMode" : "first",
              "variable" : "startAns"
            }],
            "rule" : [{
              "name" : "createBoundsPeriod",
              "source" : [{
                "context" : "startAns",
                "element" : "valueDate",
                "variable" : "startDate"
              }],
              "target" : [{
                "context" : "repeat",
                "element" : "boundsPeriod",
                "variable" : "boundsPeriod"
              }],
              "rule" : [{
                "name" : "setBoundsStart",
                "source" : [{
                  "context" : "startDate"
                }],
                "target" : [{
                  "context" : "boundsPeriod",
                  "element" : "start",
                  "transform" : "copy",
                  "parameter" : [{
                    "valueId" : "startDate"
                  }]
                }]
              },
              {
                "name" : "findEndDate",
                "source" : [{
                  "context" : "prescriptionGroup",
                  "element" : "item",
                  "variable" : "endItem",
                  "condition" : "(linkId = 'end-date')"
                }],
                "rule" : [{
                  "name" : "extractEndDate",
                  "source" : [{
                    "context" : "endItem",
                    "element" : "answer",
                    "listMode" : "first",
                    "variable" : "endAns"
                  }],
                  "rule" : [{
                    "name" : "setBoundsEnd",
                    "source" : [{
                      "context" : "endAns",
                      "element" : "valueDate",
                      "variable" : "endDate"
                    }],
                    "target" : [{
                      "context" : "boundsPeriod",
                      "element" : "end",
                      "transform" : "copy",
                      "parameter" : [{
                        "valueId" : "endDate"
                      }]
                    }]
                  }]
                }]
              }]
            }]
          }],
          "documentation" : "Bounds Period from start-date and end-date"
        }]
      }]
    },
    {
      "name" : "findRoute",
      "source" : [{
        "context" : "prescriptionGroup",
        "element" : "item",
        "variable" : "routeItem",
        "condition" : "(linkId = 'route')"
      }],
      "rule" : [{
        "name" : "extractRoute",
        "source" : [{
          "context" : "routeItem",
          "element" : "answer",
          "listMode" : "first",
          "variable" : "routeAns"
        }],
        "rule" : [{
          "name" : "setRouteCC",
          "source" : [{
            "context" : "routeAns",
            "element" : "valueCoding",
            "variable" : "routeCoding"
          }],
          "target" : [{
            "context" : "dosage",
            "element" : "route",
            "variable" : "routeCC",
            "transform" : "create",
            "parameter" : [{
              "valueString" : "CodeableConcept"
            }]
          }],
          "rule" : [{
            "name" : "setRouteCoding",
            "source" : [{
              "context" : "routeCoding"
            }],
            "target" : [{
              "context" : "routeCC",
              "element" : "coding",
              "transform" : "copy",
              "parameter" : [{
                "valueId" : "routeCoding"
              }]
            }]
          },
          {
            "name" : "setRouteText",
            "source" : [{
              "context" : "routeCoding",
              "element" : "display",
              "variable" : "disp"
            }],
            "target" : [{
              "context" : "routeCC",
              "element" : "text",
              "transform" : "copy",
              "parameter" : [{
                "valueId" : "disp"
              }]
            }]
          }]
        }]
      }],
      "documentation" : "Route"
    },
    {
      "name" : "findDose",
      "source" : [{
        "context" : "prescriptionGroup",
        "element" : "item",
        "variable" : "doseItem",
        "condition" : "(linkId = 'dose')"
      }],
      "rule" : [{
        "name" : "extractDoseAns",
        "source" : [{
          "context" : "doseItem",
          "element" : "answer",
          "listMode" : "first",
          "variable" : "doseAns"
        }],
        "rule" : [{
          "name" : "createDoseAndRate",
          "source" : [{
            "context" : "doseAns",
            "element" : "valueInteger",
            "variable" : "doseValue"
          }],
          "target" : [{
            "context" : "dosage",
            "element" : "doseAndRate",
            "variable" : "doseRate"
          },
          {
            "context" : "doseRate",
            "element" : "doseQuantity",
            "variable" : "doseQty"
          }],
          "rule" : [{
            "name" : "setDoseValue",
            "source" : [{
              "context" : "doseValue"
            }],
            "target" : [{
              "context" : "doseQty",
              "element" : "value",
              "transform" : "copy",
              "parameter" : [{
                "valueId" : "doseValue"
              }]
            }]
          },
          {
            "name" : "findDoseUnit",
            "source" : [{
              "context" : "prescriptionGroup",
              "element" : "item",
              "variable" : "doseUnitItem",
              "condition" : "(linkId = 'dosage-unit')"
            }],
            "rule" : [{
              "name" : "extractDoseUnitAns",
              "source" : [{
                "context" : "doseUnitItem",
                "element" : "answer",
                "listMode" : "first",
                "variable" : "doseUnitAns"
              }],
              "rule" : [{
                "name" : "extractUnitCoding",
                "source" : [{
                  "context" : "doseUnitAns",
                  "element" : "valueCoding",
                  "variable" : "unitCoding"
                }],
                "rule" : [{
                  "name" : "setDoseUnit",
                  "source" : [{
                    "context" : "unitCoding",
                    "element" : "display",
                    "variable" : "unitDisp"
                  }],
                  "target" : [{
                    "context" : "doseQty",
                    "element" : "unit",
                    "transform" : "copy",
                    "parameter" : [{
                      "valueId" : "unitDisp"
                    }]
                  }]
                },
                {
                  "name" : "setDoseCode",
                  "source" : [{
                    "context" : "unitCoding",
                    "element" : "code",
                    "variable" : "unitCode"
                  }],
                  "target" : [{
                    "context" : "doseQty",
                    "element" : "code",
                    "transform" : "copy",
                    "parameter" : [{
                      "valueId" : "unitCode"
                    }]
                  }]
                },
                {
                  "name" : "setDoseSystem",
                  "source" : [{
                    "context" : "unitCoding",
                    "element" : "system",
                    "variable" : "unitSys"
                  }],
                  "target" : [{
                    "context" : "doseQty",
                    "element" : "system",
                    "transform" : "copy",
                    "parameter" : [{
                      "valueId" : "unitSys"
                    }]
                  }]
                }]
              }]
            }]
          }]
        }]
      }],
      "documentation" : "Dose and Rate"
    },
    {
      "name" : "findDosageInstr",
      "source" : [{
        "context" : "prescriptionGroup",
        "element" : "item",
        "variable" : "instrItem",
        "condition" : "(linkId = 'dosage-instructions')"
      }],
      "rule" : [{
        "name" : "extractInstr",
        "source" : [{
          "context" : "instrItem",
          "element" : "answer",
          "listMode" : "first",
          "variable" : "instrAns"
        }],
        "rule" : [{
          "name" : "setPatientInstruction",
          "source" : [{
            "context" : "instrAns",
            "element" : "valueString",
            "variable" : "instrText"
          }],
          "target" : [{
            "context" : "dosage",
            "element" : "patientInstruction",
            "transform" : "copy",
            "parameter" : [{
              "valueId" : "instrText"
            }]
          }]
        }]
      }],
      "documentation" : "Dosage Instructions (patient instruction)"
    },
    {
      "name" : "findAddInstr",
      "source" : [{
        "context" : "prescriptionGroup",
        "element" : "item",
        "variable" : "addInstrItem",
        "condition" : "(linkId = 'additional-instructions')"
      }],
      "rule" : [{
        "name" : "extractAddInstr",
        "source" : [{
          "context" : "addInstrItem",
          "element" : "answer",
          "listMode" : "first",
          "variable" : "addInstrAns"
        }],
        "rule" : [{
          "name" : "setDosageText",
          "source" : [{
            "context" : "addInstrAns",
            "element" : "valueString",
            "variable" : "addInstrText"
          }],
          "target" : [{
            "context" : "dosage",
            "element" : "text",
            "transform" : "copy",
            "parameter" : [{
              "valueId" : "addInstrText"
            }]
          }]
        }]
      }],
      "documentation" : "Additional Instructions (text)"
    }]
  },
  {
    "name" : "BuildDispenseRequest",
    "input" : [{
      "name" : "qr",
      "type" : "QR",
      "mode" : "source"
    },
    {
      "name" : "prescriptionGroup",
      "mode" : "source"
    },
    {
      "name" : "dispReq",
      "mode" : "target"
    }],
    "rule" : [{
      "name" : "findRefills",
      "source" : [{
        "context" : "prescriptionGroup",
        "element" : "item",
        "variable" : "refillsItem",
        "condition" : "(linkId = 'refills')"
      }],
      "rule" : [{
        "name" : "extractRefills",
        "source" : [{
          "context" : "refillsItem",
          "element" : "answer",
          "listMode" : "first",
          "variable" : "refillsAns"
        }],
        "rule" : [{
          "name" : "setRefills",
          "source" : [{
            "context" : "refillsAns",
            "element" : "valueInteger",
            "variable" : "refillsValue"
          }],
          "target" : [{
            "context" : "dispReq",
            "element" : "numberOfRepeatsAllowed",
            "transform" : "copy",
            "parameter" : [{
              "valueId" : "refillsValue"
            }]
          }]
        }]
      }],
      "documentation" : "Refills"
    },
    {
      "name" : "findValidityStart",
      "source" : [{
        "context" : "prescriptionGroup",
        "element" : "item",
        "variable" : "startItem",
        "condition" : "(linkId = 'start-date')"
      }],
      "rule" : [{
        "name" : "extractValidityStart",
        "source" : [{
          "context" : "startItem",
          "element" : "answer",
          "listMode" : "first",
          "variable" : "startAns"
        }],
        "rule" : [{
          "name" : "createValidityPeriod",
          "source" : [{
            "context" : "startAns",
            "element" : "valueDate",
            "variable" : "startDate"
          }],
          "target" : [{
            "context" : "dispReq",
            "element" : "validityPeriod",
            "variable" : "validPeriod"
          }],
          "rule" : [{
            "name" : "setValidityStart",
            "source" : [{
              "context" : "startDate"
            }],
            "target" : [{
              "context" : "validPeriod",
              "element" : "start",
              "transform" : "copy",
              "parameter" : [{
                "valueId" : "startDate"
              }]
            }]
          },
          {
            "name" : "findValidityEnd",
            "source" : [{
              "context" : "prescriptionGroup",
              "element" : "item",
              "variable" : "endItem",
              "condition" : "(linkId = 'end-date')"
            }],
            "rule" : [{
              "name" : "extractValidityEnd",
              "source" : [{
                "context" : "endItem",
                "element" : "answer",
                "listMode" : "first",
                "variable" : "endAns"
              }],
              "rule" : [{
                "name" : "setValidityEnd",
                "source" : [{
                  "context" : "endAns",
                  "element" : "valueDate",
                  "variable" : "endDate"
                }],
                "target" : [{
                  "context" : "validPeriod",
                  "element" : "end",
                  "transform" : "copy",
                  "parameter" : [{
                    "valueId" : "endDate"
                  }]
                }]
              }]
            }]
          }]
        }]
      }],
      "documentation" : "Validity Period from start-date and end-date"
    },
    {
      "name" : "findSupplyDuration",
      "source" : [{
        "context" : "prescriptionGroup",
        "element" : "item",
        "variable" : "durItem",
        "condition" : "(linkId = 'duration')"
      }],
      "rule" : [{
        "name" : "extractSupplyDuration",
        "source" : [{
          "context" : "durItem",
          "element" : "answer",
          "listMode" : "first",
          "variable" : "durAns"
        }],
        "rule" : [{
          "name" : "createSupplyDuration",
          "source" : [{
            "context" : "durAns",
            "element" : "valueInteger",
            "variable" : "durValue"
          }],
          "target" : [{
            "context" : "dispReq",
            "element" : "expectedSupplyDuration",
            "variable" : "supplyDur"
          }],
          "rule" : [{
            "name" : "setSupplyDurValue",
            "source" : [{
              "context" : "durValue"
            }],
            "target" : [{
              "context" : "supplyDur",
              "element" : "value",
              "transform" : "copy",
              "parameter" : [{
                "valueId" : "durValue"
              }]
            }]
          },
          {
            "name" : "findSupplyDurUom",
            "source" : [{
              "context" : "prescriptionGroup",
              "element" : "item",
              "variable" : "durUomItem",
              "condition" : "(linkId = 'duration-uom')"
            }],
            "rule" : [{
              "name" : "extractSupplyDurUomAns",
              "source" : [{
                "context" : "durUomItem",
                "element" : "answer",
                "listMode" : "first",
                "variable" : "durUomAns"
              }],
              "rule" : [{
                "name" : "extractSupplyDurUom",
                "source" : [{
                  "context" : "durUomAns",
                  "element" : "valueCoding",
                  "variable" : "durUomCoding"
                }],
                "rule" : [{
                  "name" : "setSupplyDurCode",
                  "source" : [{
                    "context" : "durUomCoding",
                    "element" : "code",
                    "variable" : "uomCode"
                  }],
                  "target" : [{
                    "context" : "supplyDur",
                    "element" : "code",
                    "transform" : "copy",
                    "parameter" : [{
                      "valueId" : "uomCode"
                    }]
                  }]
                },
                {
                  "name" : "setSupplyDurUnit",
                  "source" : [{
                    "context" : "durUomCoding",
                    "element" : "display",
                    "variable" : "uomDisplay"
                  }],
                  "target" : [{
                    "context" : "supplyDur",
                    "element" : "unit",
                    "transform" : "copy",
                    "parameter" : [{
                      "valueId" : "uomDisplay"
                    }]
                  }]
                },
                {
                  "name" : "setSupplyDurSystem",
                  "source" : [{
                    "context" : "durUomCoding",
                    "element" : "system",
                    "variable" : "uomSystem"
                  }],
                  "target" : [{
                    "context" : "supplyDur",
                    "element" : "system",
                    "transform" : "copy",
                    "parameter" : [{
                      "valueId" : "uomSystem"
                    }]
                  }]
                }]
              }]
            }]
          }]
        }]
      }],
      "documentation" : "Expected Supply Duration"
    },
    {
      "name" : "setDispenser",
      "source" : [{
        "context" : "qr",
        "element" : "source",
        "variable" : "src"
      }],
      "target" : [{
        "context" : "dispReq",
        "element" : "dispenser",
        "transform" : "copy",
        "parameter" : [{
          "valueId" : "src"
        }]
      }],
      "documentation" : "Dispenser - from QuestionnaireResponse.source (Organization)"
    }]
  },
  {
    "name" : "SetMedicationRequestFullUrl",
    "input" : [{
      "name" : "medReq",
      "type" : "MedicationRequest",
      "mode" : "source"
    },
    {
      "name" : "entry",
      "mode" : "target"
    }],
    "rule" : [{
      "name" : "assignFullUrl",
      "source" : [{
        "context" : "medReq",
        "element" : "id",
        "variable" : "id"
      }],
      "target" : [{
        "context" : "entry",
        "element" : "fullUrl",
        "transform" : "append",
        "parameter" : [{
          "valueString" : "https://fhir.slade360.co.ke/fhir/MedicationRequest/"
        },
        {
          "valueId" : "id"
        }]
      }]
    }]
  }]
}

```
