SGHI FHIR Profile Implementation Guide
0.1.0 - ci-build

SGHI FHIR Profile Implementation Guide, published by Kathurima Kimathi. This guide is not an authorized publication; it is the continuous build for version 0.1.0 built by the FHIR (HL7® FHIR® Standard) CI Build. This version is based on the current content of https://github.com/savannahghi/sil_fhir_profile_ig/ and changes regularly. See the Directory of published versions

## : ExtractMedicationRequest - JSON Representation

Draft as of 2026-04-27

Raw json | Download

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