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 - XML Representation

Draft as of 2026-04-27

Raw xml | Download

    <StructureMap xmlns="http://hl7.org/fhir">
      <id value="ExtractMedicationRequest"/>
      <text>
        <status value="generated"/>
        <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">
    <span style="color: #cc00cc">/// <b>url</b> = </span><span style="color: blue">'https://fhir.slade360.co.ke/fhir/StructureMap/ExtractMedicationRequest'</span>
    <span style="color: #cc00cc">/// <b>name</b> = </span><span style="color: blue">'ExtractMedicationRequest'</span>
    <span style="color: #cc00cc">/// <b>status</b> = </span><span style="color: blue">'draft'</span>

    <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>
    <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>
    <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>
    <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>

    <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"> {
    </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>
      qr.item<b> as </b><span style="color: maroon">prescriptionGroup</span><b> where </b>(linkId = 'prescription-form')<b> then</b><span style="color: navy"> {
    </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"> {
    </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>
        <span style="color: navy">}</span> <i>&quot;createMedReq&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;findPrescriptionGroup&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}

    </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"> {
    </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>
      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>
      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>
      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>
      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>
      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>
      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>
      qr.extension first<b> as </b><span style="color: maroon">ext</span><b> then</b><span style="color: navy"> {
    </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"> {
    </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>
        <span style="color: navy">}</span> <i>&quot;accessMedication&quot;</i><span style="color: navy">;</span>
      <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>
      prescriptionGroup.item<b> as </b><span style="color: maroon">priorityItem</span><b> where </b>(linkId = 'priority')<b> then</b><span style="color: navy"> {
    </span>    priorityItem.answer first<b> as </b><span style="color: maroon">priorityAns</span><b> then</b><span style="color: navy"> {
    </span>      priorityAns.valueCoding<b> as </b><span style="color: maroon">priorityCoding</span><b> then</b><span style="color: navy"> {
    </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>
          <span style="color: navy">}</span> <i>&quot;extractPriorityCode&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;extractPriority&quot;</i><span style="color: navy">;</span>
      <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>
      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"> {
    </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>
      <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>
      prescriptionGroup.item<b> as </b><span style="color: maroon">substItem</span><b> where </b>(linkId = 'substitutable')<b> then</b><span style="color: navy"> {
    </span>    substItem.answer first<b> as </b><span style="color: maroon">substAns</span><b> then</b><span style="color: navy"> {
    </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"> {
    </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>
          <span style="color: navy">}</span> <i>&quot;createSubst&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;extractSubst&quot;</i><span style="color: navy">;</span>
      <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>
      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"> {
    </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>
      <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>
      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>
      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"> {
    </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>
        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>
      <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>
    <span style="color: navy">}

    </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"> {
    </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"> {
    </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"> {
    </span>      prescriptionGroup.item<b> as </b><span style="color: maroon">freqItem</span><b> where </b>(linkId = 'frequency')<b> then</b><span style="color: navy"> {
    </span>        freqItem.answer first<b> as </b><span style="color: maroon">freqAns</span><b> then</b><span style="color: navy"> {
    </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>
              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>
              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>
              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>
            <span style="color: navy">}</span> <i>&quot;extractFreq&quot;</i><span style="color: navy">;</span>
          <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>
          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>
          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>
          prescriptionGroup.item<b> as </b><span style="color: maroon">durItem</span><b> where </b>(linkId = 'duration')<b> then</b><span style="color: navy"> {
    </span>        durItem.answer first<b> as </b><span style="color: maroon">durAns</span><b> then</b><span style="color: navy"> {
    </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>
            <span style="color: navy">}</span> <i>&quot;extractDuration&quot;</i><span style="color: navy">;</span>
          <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>
          prescriptionGroup.item<b> as </b><span style="color: maroon">durUomItem</span><b> where </b>(linkId = 'duration-uom')<b> then</b><span style="color: navy"> {
    </span>        durUomItem.answer first<b> as </b><span style="color: maroon">durUomAns</span><b> then</b><span style="color: navy"> {
    </span>          durUomAns.valueCoding<b> as </b><span style="color: maroon">durUomCoding</span><b> then</b><span style="color: navy"> {
    </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>
              <span style="color: navy">}</span> <i>&quot;extractDurUomCode&quot;</i><span style="color: navy">;</span>
            <span style="color: navy">}</span> <i>&quot;extractDurUom&quot;</i><span style="color: navy">;</span>
          <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>
          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"> {
    </span>        whenItem.answer first<b> as </b><span style="color: maroon">whenAns</span><b> then</b><span style="color: navy"> {
    </span>          whenAns.valueCoding<b> as </b><span style="color: maroon">whenCoding</span><b> then</b><span style="color: navy"> {
    </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>
              <span style="color: navy">}</span> <i>&quot;extractWhenCode&quot;</i><span style="color: navy">;</span>
            <span style="color: navy">}</span> <i>&quot;extractWhen&quot;</i><span style="color: navy">;</span>
          <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>
          prescriptionGroup.item<b> as </b><span style="color: maroon">startItem</span><b> where </b>(linkId = 'start-date')<b> then</b><span style="color: navy"> {
    </span>        startItem.answer first<b> as </b><span style="color: maroon">startAns</span><b> then</b><span style="color: navy"> {
    </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"> {
    </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>
                prescriptionGroup.item<b> as </b><span style="color: maroon">endItem</span><b> where </b>(linkId = 'end-date')<b> then</b><span style="color: navy"> {
    </span>              endItem.answer first<b> as </b><span style="color: maroon">endAns</span><b> then</b><span style="color: navy"> {
    </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>
                  <span style="color: navy">}</span> <i>&quot;extractEndDate&quot;</i><span style="color: navy">;</span>
                <span style="color: navy">}</span> <i>&quot;findEndDate&quot;</i><span style="color: navy">;</span>
              <span style="color: navy">}</span> <i>&quot;createBoundsPeriod&quot;</i><span style="color: navy">;</span>
            <span style="color: navy">}</span> <i>&quot;extractStartDate&quot;</i><span style="color: navy">;</span>
          <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>
        <span style="color: navy">}</span> <i>&quot;accessRepeat&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;accessTiming&quot;</i><span style="color: navy">;</span>
      prescriptionGroup.item<b> as </b><span style="color: maroon">routeItem</span><b> where </b>(linkId = 'route')<b> then</b><span style="color: navy"> {
    </span>    routeItem.answer first<b> as </b><span style="color: maroon">routeAns</span><b> then</b><span style="color: navy"> {
    </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"> {
    </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>
            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>
          <span style="color: navy">}</span> <i>&quot;setRouteCC&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;extractRoute&quot;</i><span style="color: navy">;</span>
      <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>
      prescriptionGroup.item<b> as </b><span style="color: maroon">doseItem</span><b> where </b>(linkId = 'dose')<b> then</b><span style="color: navy"> {
    </span>    doseItem.answer first<b> as </b><span style="color: maroon">doseAns</span><b> then</b><span style="color: navy"> {
    </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"> {
    </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>
            prescriptionGroup.item<b> as </b><span style="color: maroon">doseUnitItem</span><b> where </b>(linkId = 'dosage-unit')<b> then</b><span style="color: navy"> {
    </span>          doseUnitItem.answer first<b> as </b><span style="color: maroon">doseUnitAns</span><b> then</b><span style="color: navy"> {
    </span>            doseUnitAns.valueCoding<b> as </b><span style="color: maroon">unitCoding</span><b> then</b><span style="color: navy"> {
    </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>
                  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>
                  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>
                <span style="color: navy">}</span> <i>&quot;extractUnitCoding&quot;</i><span style="color: navy">;</span>
              <span style="color: navy">}</span> <i>&quot;extractDoseUnitAns&quot;</i><span style="color: navy">;</span>
            <span style="color: navy">}</span> <i>&quot;findDoseUnit&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;createDoseAndRate&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;extractDoseAns&quot;</i><span style="color: navy">;</span>
      <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>
      prescriptionGroup.item<b> as </b><span style="color: maroon">instrItem</span><b> where </b>(linkId = 'dosage-instructions')<b> then</b><span style="color: navy"> {
    </span>    instrItem.answer first<b> as </b><span style="color: maroon">instrAns</span><b> then</b><span style="color: navy"> {
    </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>
        <span style="color: navy">}</span> <i>&quot;extractInstr&quot;</i><span style="color: navy">;</span>
      <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>
      prescriptionGroup.item<b> as </b><span style="color: maroon">addInstrItem</span><b> where </b>(linkId = 'additional-instructions')<b> then</b><span style="color: navy"> {
    </span>    addInstrItem.answer first<b> as </b><span style="color: maroon">addInstrAns</span><b> then</b><span style="color: navy"> {
    </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>
        <span style="color: navy">}</span> <i>&quot;extractAddInstr&quot;</i><span style="color: navy">;</span>
      <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>
    <span style="color: navy">}

    </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"> {
    </span>  prescriptionGroup.item<b> as </b><span style="color: maroon">refillsItem</span><b> where </b>(linkId = 'refills')<b> then</b><span style="color: navy"> {
    </span>    refillsItem.answer first<b> as </b><span style="color: maroon">refillsAns</span><b> then</b><span style="color: navy"> {
    </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>
        <span style="color: navy">}</span> <i>&quot;extractRefills&quot;</i><span style="color: navy">;</span>
      <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>
      prescriptionGroup.item<b> as </b><span style="color: maroon">startItem</span><b> where </b>(linkId = 'start-date')<b> then</b><span style="color: navy"> {
    </span>    startItem.answer first<b> as </b><span style="color: maroon">startAns</span><b> then</b><span style="color: navy"> {
    </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"> {
    </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>
            prescriptionGroup.item<b> as </b><span style="color: maroon">endItem</span><b> where </b>(linkId = 'end-date')<b> then</b><span style="color: navy"> {
    </span>          endItem.answer first<b> as </b><span style="color: maroon">endAns</span><b> then</b><span style="color: navy"> {
    </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>
              <span style="color: navy">}</span> <i>&quot;extractValidityEnd&quot;</i><span style="color: navy">;</span>
            <span style="color: navy">}</span> <i>&quot;findValidityEnd&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;createValidityPeriod&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;extractValidityStart&quot;</i><span style="color: navy">;</span>
      <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>
      prescriptionGroup.item<b> as </b><span style="color: maroon">durItem</span><b> where </b>(linkId = 'duration')<b> then</b><span style="color: navy"> {
    </span>    durItem.answer first<b> as </b><span style="color: maroon">durAns</span><b> then</b><span style="color: navy"> {
    </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"> {
    </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>
            prescriptionGroup.item<b> as </b><span style="color: maroon">durUomItem</span><b> where </b>(linkId = 'duration-uom')<b> then</b><span style="color: navy"> {
    </span>          durUomItem.answer first<b> as </b><span style="color: maroon">durUomAns</span><b> then</b><span style="color: navy"> {
    </span>            durUomAns.valueCoding<b> as </b><span style="color: maroon">durUomCoding</span><b> then</b><span style="color: navy"> {
    </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>
                  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>
                  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>
                <span style="color: navy">}</span> <i>&quot;extractSupplyDurUom&quot;</i><span style="color: navy">;</span>
              <span style="color: navy">}</span> <i>&quot;extractSupplyDurUomAns&quot;</i><span style="color: navy">;</span>
            <span style="color: navy">}</span> <i>&quot;findSupplyDurUom&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;createSupplyDuration&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;extractSupplyDuration&quot;</i><span style="color: navy">;</span>
      <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>
      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>
    <span style="color: navy">}

    </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"> {
    </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>
    <span style="color: navy">}

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