Healthy Route Implementation Guide
0.2.0 - ci-build

Healthy Route Implementation Guide, published by Savannah Informatics. This guide is not an authorized publication; it is the continuous build for version 0.2.0 built by the FHIR (HL7® FHIR® Standard) CI Build. This version is based on the current content of https://github.com/savannahghi/healthy-route-ig/ and changes regularly. See the Directory of published versions

: Extract the medications form - XML Representation

Draft as of 2026-11-12

Raw xml | Download


<StructureMap xmlns="http://hl7.org/fhir">
  <id value="HRExtractMedications"/>
  <text>
    <status value="generated"/>
    <div xmlns="http://www.w3.org/1999/xhtml"><p class="res-header-id"><b>Generated Narrative: StructureMap HRExtractMedications</b></p><a name="HRExtractMedications"> </a><a name="hcHRExtractMedications"> </a><pre class="fml">
<span style="color: #cc00cc">/// <b>url</b> = </span><span style="color: blue">'https://fhir.optimalhealth.org/ig/healthy-route/StructureMap/HRExtractMedications'</span>
<span style="color: #cc00cc">/// <b>version</b> = </span><span style="color: blue">'0.2.0'</span>
<span style="color: #cc00cc">/// <b>name</b> = </span><span style="color: blue">'HRExtractMedications'</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/observation.html" title="Observation">http://hl7.org/fhir/StructureDefinition/Observation</a><span style="color: navy">&quot; </span><b>alias </b>Observation <b>as </b><b>target</b>
<b>uses</b><span style="color: navy"> &quot;</span><a href="http://hl7.org/fhir/R5/medicationstatement.html" title="MedicationStatement">http://hl7.org/fhir/StructureDefinition/MedicationStatement</a><span style="color: navy">&quot; </span><b>alias </b>MedicationStatement <b>as </b><b>target</b>

<b>group </b>HRExtractMedications<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;type&quot;</i><span style="color: navy">;</span>
  qr<span style="color: navy"><b> -&gt; </b></span>evaluate<span style="color: navy">(</span>qr<span style="color: navy">, </span>id.replaceMatches('/_history/.*$', '').replaceMatches('^.*/', '')<span style="color: navy">)</span><b> as </b><span style="color: maroon">qid</span><b> then</b><span style="color: navy"> {
</span>    qr.item<b> as </b><span style="color: maroon">it</span><b> where </b><span style="color: navy">(</span>linkId = 'medications-current'<span style="color: navy">)</span><b> then</b><span style="color: navy"> {
</span>      it.answer first<b> as </b><span style="color: maroon">a</span><b> where </b><span style="color: navy">(</span>value = false<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span> bundle.entry<b> as </b><span style="color: maroon">e</span><span style="color: navy">, </span> e.resource = <b>create</b><span style="color: navy">(</span><span style="color: blue">'Observation'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">obs</span><b> then</b><span style="color: navy"> {
</span>        qr<span style="color: navy"><b> -&gt; </b></span> <b>append</b><span style="color: navy">(</span><span style="color: maroon">qid</span><span style="color: navy">, </span><span style="color: blue">'-medications-none'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">idText</span><span style="color: navy">, </span> obs.id = <b>cast</b><span style="color: navy">(</span><span style="color: maroon">idText</span><span style="color: navy">, </span><span style="color: blue">'id'</span><span style="color: navy">)</span> <i>&quot;id&quot;</i><span style="color: navy">;</span>
        qr<span style="color: navy"><b> -&gt; </b></span>e.fullUrl = <b>append</b><span style="color: navy">(</span><span style="color: blue">'Observation/'</span><span style="color: navy">, </span><span style="color: maroon">qid</span><span style="color: navy">, </span><span style="color: blue">'-medications-none'</span><span style="color: navy">)</span> <i>&quot;fullUrl&quot;</i><span style="color: navy">;</span>
        qr<span style="color: navy"><b> -&gt; </b></span>e.request<b> as </b><span style="color: maroon">rq</span><b> then</b><span style="color: navy"> {
</span>          qr<span style="color: navy"><b> -&gt; </b></span>rq.method = <span style="color: blue">'PUT'</span> <i>&quot;method&quot;</i><span style="color: navy">;</span>
          qr<span style="color: navy"><b> -&gt; </b></span>rq.url = <b>append</b><span style="color: navy">(</span><span style="color: blue">'Observation/'</span><span style="color: navy">, </span><span style="color: maroon">qid</span><span style="color: navy">, </span><span style="color: blue">'-medications-none'</span><span style="color: navy">)</span> <i>&quot;url&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;request&quot;</i><span style="color: navy">;</span>
        qr<span style="color: navy"><b> -&gt; </b></span> obs.meta<b> as </b><span style="color: maroon">m</span><span style="color: navy">, </span> m.profile = <span style="color: blue">'https://fhir.optimalhealth.org/ig/healthy-route/StructureDefinition/hr-observation'</span> <i>&quot;profile&quot;</i><span style="color: navy">;</span>
        qr.meta<b> as </b><span style="color: maroon">qm</span><b> then</b><span style="color: navy"> {
</span>          qm.tag<b> as </b><span style="color: maroon">t</span><span style="color: navy"><b> -&gt; </b></span> obs.meta<b> as </b><span style="color: maroon">m</span><span style="color: navy">, </span> m.tag = <span style="color: maroon">t</span><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;tags&quot;</i><span style="color: navy">;</span>
        qr.extension<b> as </b><span style="color: maroon">x</span><b> where </b><span style="color: navy">(</span>url = 'https://fhir.optimalhealth.org/ig/healthy-route/StructureDefinition/hr-tenant'<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span>obs.extension = <span style="color: maroon">x</span> <i>&quot;tenant&quot;</i><span style="color: navy">;</span>
        qr<span style="color: navy"><b> -&gt; </b></span>obs.status = <span style="color: blue">'final'</span> <i>&quot;status&quot;</i><span style="color: navy">;</span>
        qr<span style="color: navy"><b> -&gt; </b></span>obs.category = <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">cv</span><b> then</b><span style="color: navy"> {
</span>          qr<span style="color: navy"><b> -&gt; </b></span>cv.coding = <b>create</b><span style="color: navy">(</span><span style="color: blue">'Coding'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">cd</span><b> then</b><span style="color: navy"> {
</span>            qr<span style="color: navy"><b> -&gt; </b></span>cd.system = <span style="color: blue">'http://terminology.hl7.org/CodeSystem/observation-category'</span> <i>&quot;categorySystem&quot;</i><span style="color: navy">;</span>
            qr<span style="color: navy"><b> -&gt; </b></span>cd.code = <span style="color: blue">'survey'</span> <i>&quot;categoryCode&quot;</i><span style="color: navy">;</span>
            qr<span style="color: navy"><b> -&gt; </b></span>cd.display = <span style="color: blue">'Survey'</span> <i>&quot;categoryDisplay&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;categoryCoding&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;category&quot;</i><span style="color: navy">;</span>
        qr<span style="color: navy"><b> -&gt; </b></span>obs.code = <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">cv</span><b> then</b><span style="color: navy"> {
</span>          qr<span style="color: navy"><b> -&gt; </b></span>cv.coding = <b>create</b><span style="color: navy">(</span><span style="color: blue">'Coding'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">cd</span><b> then</b><span style="color: navy"> {
</span>            qr<span style="color: navy"><b> -&gt; </b></span>cd.system = <span style="color: blue">'https://fhir.optimalhealth.org/ig/healthy-route/CodeSystem/hr-measurement'</span> <i>&quot;codeSystem&quot;</i><span style="color: navy">;</span>
            qr<span style="color: navy"><b> -&gt; </b></span>cd.code = <span style="color: blue">'medications-none'</span> <i>&quot;codeCode&quot;</i><span style="color: navy">;</span>
            qr<span style="color: navy"><b> -&gt; </b></span>cd.display = <span style="color: blue">'No current medication'</span> <i>&quot;codeDisplay&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;codeCoding&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;code&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>obs.subject = <span style="color: maroon">s</span><span style="color: navy">;</span>
        qr.encounter<b> as </b><span style="color: maroon">en</span><span style="color: navy"><b> -&gt; </b></span>obs.encounter = <span style="color: maroon">en</span><span style="color: navy">;</span>
        qr.authored<b> as </b><span style="color: maroon">t</span><span style="color: navy"><b> -&gt; </b></span>obs.effective = <span style="color: maroon">t</span> <i>&quot;effective&quot;</i><span style="color: navy">;</span>
        qr.author<b> as </b><span style="color: maroon">au</span><span style="color: navy"><b> -&gt; </b></span>obs.performer = <span style="color: maroon">au</span> <i>&quot;performer&quot;</i><span style="color: navy">;</span>
        qr<span style="color: navy"><b> -&gt; </b></span>obs.value = <span style="color: blue">true</span> <i>&quot;value&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;none&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;current&quot;</i><span style="color: navy">;</span>
    qr.item<b> as </b><span style="color: maroon">g</span><b> where </b><span style="color: navy">(</span>linkId = 'medicine'<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span> bundle.entry<b> as </b><span style="color: maroon">e</span><span style="color: navy">, </span> e.resource = <b>create</b><span style="color: navy">(</span><span style="color: blue">'MedicationStatement'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">ms</span><b> then</b><span style="color: navy"> {
</span>      g.item<b> as </b><span style="color: maroon">ci</span><b> where </b><span style="color: navy">(</span>linkId = 'medicine.code'<span style="color: navy">)</span><b> then</b><span style="color: navy"> {
</span>        ci.answer first<b> as </b><span style="color: maroon">ca</span><b> then</b><span style="color: navy"> {
</span>          ca.value<span style="color: navy"> : </span>Coding<b> as </b><span style="color: maroon">cv</span><b> then</b><span style="color: navy"> {
</span>            cv.code<b> as </b><span style="color: maroon">c</span><span style="color: navy"><b> -&gt; </b></span> <b>append</b><span style="color: navy">(</span><span style="color: maroon">qid</span><span style="color: navy">, </span><span style="color: blue">'-medicine-'</span><span style="color: navy">, </span><span style="color: maroon">c</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">idText</span><span style="color: navy">, </span> ms.id = <b>cast</b><span style="color: navy">(</span><span style="color: maroon">idText</span><span style="color: navy">, </span><span style="color: blue">'id'</span><span style="color: navy">)</span> <i>&quot;id&quot;</i><span style="color: navy">;</span>
            cv.code<b> as </b><span style="color: maroon">c</span><span style="color: navy"><b> -&gt; </b></span>e.fullUrl = <b>append</b><span style="color: navy">(</span><span style="color: blue">'MedicationStatement/'</span><span style="color: navy">, </span><span style="color: maroon">qid</span><span style="color: navy">, </span><span style="color: blue">'-medicine-'</span><span style="color: navy">, </span><span style="color: maroon">c</span><span style="color: navy">)</span> <i>&quot;fullUrl&quot;</i><span style="color: navy">;</span>
            cv.code<b> as </b><span style="color: maroon">c</span><span style="color: navy"><b> -&gt; </b></span>e.request<b> as </b><span style="color: maroon">rq</span><b> then</b><span style="color: navy"> {
</span>              qr<span style="color: navy"><b> -&gt; </b></span>rq.method = <span style="color: blue">'PUT'</span> <i>&quot;method&quot;</i><span style="color: navy">;</span>
              qr<span style="color: navy"><b> -&gt; </b></span>rq.url = <b>append</b><span style="color: navy">(</span><span style="color: blue">'MedicationStatement/'</span><span style="color: navy">, </span><span style="color: maroon">qid</span><span style="color: navy">, </span><span style="color: blue">'-medicine-'</span><span style="color: navy">, </span><span style="color: maroon">c</span><span style="color: navy">)</span> <i>&quot;url&quot;</i><span style="color: navy">;</span>
            <span style="color: navy">}</span> <i>&quot;request&quot;</i><span style="color: navy">;</span>
            cv<span style="color: navy"><b> -&gt; </b></span> ms.medication = <b>create</b><span style="color: navy">(</span><span style="color: blue">'CodeableReference'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">cr</span><span style="color: navy">, </span> cr.concept = <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">concept</span><b> then</b><span style="color: navy"> {
</span>              cv<span style="color: navy"><b> -&gt; </b></span>concept.coding = <span style="color: maroon">cv</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
              cv.display<b> as </b><span style="color: maroon">d</span><span style="color: navy"><b> -&gt; </b></span>concept.text = <span style="color: maroon">d</span> <i>&quot;text&quot;</i><span style="color: navy">;</span>
            <span style="color: navy">}</span> <i>&quot;medication&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;coded&quot;</i><span style="color: navy">;</span>
          ca.value<span style="color: navy"> : </span>string<b> as </b><span style="color: maroon">sv</span><b> then</b><span style="color: navy"> {
</span>            qr<span style="color: navy"><b> -&gt; </b></span> ms.id = <b>uuid</b><span style="color: navy">(</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">newId</span><span style="color: navy">, </span> e.fullUrl = <b>append</b><span style="color: navy">(</span><span style="color: blue">'urn:uuid:'</span><span style="color: navy">, </span><span style="color: maroon">newId</span><span style="color: navy">)</span> <i>&quot;id&quot;</i><span style="color: navy">;</span>
            qr<span style="color: navy"><b> -&gt; </b></span>e.request<b> as </b><span style="color: maroon">rq</span><b> then</b><span style="color: navy"> {
</span>              qr<span style="color: navy"><b> -&gt; </b></span>rq.method = <span style="color: blue">'POST'</span> <i>&quot;method&quot;</i><span style="color: navy">;</span>
              qr<span style="color: navy"><b> -&gt; </b></span>rq.url = <span style="color: blue">'MedicationStatement'</span> <i>&quot;url&quot;</i><span style="color: navy">;</span>
            <span style="color: navy">}</span> <i>&quot;request&quot;</i><span style="color: navy">;</span>
            sv<span style="color: navy"><b> -&gt; </b></span> ms.medication = <b>create</b><span style="color: navy">(</span><span style="color: blue">'CodeableReference'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">cr</span><span style="color: navy">, </span> cr.concept = <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">concept</span><span style="color: navy">, </span> concept.text = <span style="color: maroon">sv</span> <i>&quot;medication&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;unlisted&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;code&quot;</i><span style="color: navy">;</span>
      qr<span style="color: navy"><b> -&gt; </b></span> ms.meta<b> as </b><span style="color: maroon">m</span><span style="color: navy">, </span> m.profile = <span style="color: blue">'https://fhir.optimalhealth.org/ig/healthy-route/StructureDefinition/hr-medication-statement'</span> <i>&quot;profile&quot;</i><span style="color: navy">;</span>
      qr.meta<b> as </b><span style="color: maroon">qm</span><b> then</b><span style="color: navy"> {
</span>        qm.tag<b> as </b><span style="color: maroon">t</span><span style="color: navy"><b> -&gt; </b></span> ms.meta<b> as </b><span style="color: maroon">m</span><span style="color: navy">, </span> m.tag = <span style="color: maroon">t</span><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;tags&quot;</i><span style="color: navy">;</span>
      qr.extension<b> as </b><span style="color: maroon">x</span><b> where </b><span style="color: navy">(</span>url = 'https://fhir.optimalhealth.org/ig/healthy-route/StructureDefinition/hr-tenant'<span style="color: navy">)</span><span style="color: navy"><b> -&gt; </b></span>ms.extension = <span style="color: maroon">x</span> <i>&quot;tenant&quot;</i><span style="color: navy">;</span>
      qr<span style="color: navy"><b> -&gt; </b></span>ms.status = <span style="color: blue">'recorded'</span> <i>&quot;status&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>ms.subject = <span style="color: maroon">s</span><span style="color: navy">;</span>
      qr.encounter<b> as </b><span style="color: maroon">en</span><span style="color: navy"><b> -&gt; </b></span>ms.encounter = <span style="color: maroon">en</span><span style="color: navy">;</span>
      qr.authored<b> as </b><span style="color: maroon">t</span><span style="color: navy"><b> -&gt; </b></span>ms.dateAsserted = <span style="color: maroon">t</span> <i>&quot;asserted&quot;</i><span style="color: navy">;</span>
      qr.author<b> as </b><span style="color: maroon">au</span><span style="color: navy"><b> -&gt; </b></span>ms.informationSource = <span style="color: maroon">au</span> <i>&quot;source&quot;</i><span style="color: navy">;</span>
      qr<span style="color: navy"><b> -&gt; </b></span>ms.dosage<b> as </b><span style="color: maroon">dos</span><b> then</b><span style="color: navy"> {
</span>        g.item<b> as </b><span style="color: maroon">ri</span><b> where </b><span style="color: navy">(</span>linkId = 'medicine.route'<span style="color: navy">)</span><b> then</b><span style="color: navy"> {
</span>          ri.answer first<b> as </b><span style="color: maroon">ra</span><b> then</b><span style="color: navy"> {
</span>            ra.value<b> as </b><span style="color: maroon">rv</span><span style="color: navy"><b> -&gt; </b></span> dos.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">concept</span><span style="color: navy">, </span> concept.coding = <span style="color: maroon">rv</span> <i>&quot;route&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;routeItem&quot;</i><span style="color: navy">;</span>
        g.item<b> as </b><span style="color: maroon">fi</span><b> where </b><span style="color: navy">(</span>linkId = 'medicine.frequency'<span style="color: navy">)</span><b> then</b><span style="color: navy"> {
</span>          fi.answer first<b> as </b><span style="color: maroon">fa</span><b> then</b><span style="color: navy"> {
</span>            fa.value<b> as </b><span style="color: maroon">fv</span><span style="color: navy"><b> -&gt; </b></span> dos.timing<b> as </b><span style="color: maroon">tm</span><span style="color: navy">, </span> tm.code = <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">concept</span><span style="color: navy">, </span> concept.coding = <span style="color: maroon">fv</span> <i>&quot;frequency&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;frequencyItem&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;dosage&quot;</i><span style="color: navy">;</span>
      g.item<b> as </b><span style="color: maroon">si</span><b> where </b><span style="color: navy">(</span>linkId = 'medicine.strength'<span style="color: navy">)</span><b> then</b><span style="color: navy"> {
</span>        si.answer first<b> as </b><span style="color: maroon">sa</span><b> then</b><span style="color: navy"> {
</span>          sa.value<b> as </b><span style="color: maroon">sv</span><span style="color: navy"><b> -&gt; </b></span> ms.note<b> as </b><span style="color: maroon">n</span><span style="color: navy">, </span> n.text = <b>append</b><span style="color: navy">(</span><span style="color: maroon">sv</span><span style="color: navy">, </span><span style="color: blue">', strength as recorded'</span><span style="color: navy">)</span> <i>&quot;strength&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;strengthItem&quot;</i><span style="color: navy">;</span>
      g.item<b> as </b><span style="color: maroon">fo</span><b> where </b><span style="color: navy">(</span>linkId = 'medicine.form'<span style="color: navy">)</span><b> then</b><span style="color: navy"> {
</span>        fo.answer first<b> as </b><span style="color: maroon">fa</span><b> then</b><span style="color: navy"> {
</span>          fa.value<b> as </b><span style="color: maroon">fv</span><b> then</b><span style="color: navy"> {
</span>            fv.display<b> as </b><span style="color: maroon">d</span><span style="color: navy"><b> -&gt; </b></span> ms.note<b> as </b><span style="color: maroon">n</span><span style="color: navy">, </span> n.text = <b>append</b><span style="color: navy">(</span><span style="color: maroon">d</span><span style="color: navy">, </span><span style="color: blue">', form as recorded'</span><span style="color: navy">)</span> <i>&quot;form&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;coding&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;formItem&quot;</i><span style="color: navy">;</span>
      g.item<b> as </b><span style="color: maroon">re</span><b> where </b><span style="color: navy">(</span>linkId = 'medicine.reason'<span style="color: navy">)</span><b> then</b><span style="color: navy"> {
</span>        re.answer first<b> as </b><span style="color: maroon">ra</span><b> then</b><span style="color: navy"> {
</span>          ra.value<b> as </b><span style="color: maroon">rv</span><span style="color: navy"><b> -&gt; </b></span> ms.reason = <b>create</b><span style="color: navy">(</span><span style="color: blue">'CodeableReference'</span><span style="color: navy">)</span><b> as </b><span style="color: maroon">cr</span><span style="color: navy">, </span> cr.concept = <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">concept</span><span style="color: navy">, </span> concept.text = <span style="color: maroon">rv</span> <i>&quot;reason&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;reasonItem&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;medicine&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">}</span> <i>&quot;response&quot;</i><span style="color: navy">;</span>
<span style="color: navy">}

</span></pre></div>
  </text>
  <url
       value="https://fhir.optimalhealth.org/ig/healthy-route/StructureMap/HRExtractMedications"/>
  <version value="0.2.0"/>
  <name value="HRExtractMedications"/>
  <status value="draft"/>
  <date value="2026-11-12T10:14:36+00:00"/>
  <publisher value="Savannah Informatics"/>
  <contact>
    <name value="Savannah Informatics"/>
    <telecom>
      <system value="url"/>
      <value value="https://optimalhealth.org"/>
    </telecom>
  </contact>
  <contact>
    <name value="Savannah Informatics"/>
    <telecom>
      <system value="url"/>
      <value value="https://optimalhealth.org"/>
    </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/Observation"/>
    <mode value="target"/>
    <alias value="Observation"/>
  </structure>
  <structure>
    <url value="http://hl7.org/fhir/StructureDefinition/MedicationStatement"/>
    <mode value="target"/>
    <alias value="MedicationStatement"/>
  </structure>
  <group>
    <name value="HRExtractMedications"/>
    <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="type"/>
      <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="response"/>
      <source>
        <context value="qr"/>
      </source>
      <target>
        <variable value="qid"/>
        <transform value="evaluate"/>
        <parameter>
          <valueId value="qr"/>
        </parameter>
        <parameter>
          <valueString
                       value="id.replaceMatches('/_history/.*$', '').replaceMatches('^.*/', '')"/>
        </parameter>
      </target>
      <rule>
        <name value="current"/>
        <source>
          <context value="qr"/>
          <element value="item"/>
          <variable value="it"/>
          <condition value="linkId = 'medications-current'"/>
        </source>
        <rule>
          <name value="none"/>
          <source>
            <context value="it"/>
            <element value="answer"/>
            <listMode value="first"/>
            <variable value="a"/>
            <condition value="value = false"/>
          </source>
          <target>
            <context value="bundle"/>
            <element value="entry"/>
            <variable value="e"/>
          </target>
          <target>
            <context value="e"/>
            <element value="resource"/>
            <variable value="obs"/>
            <transform value="create"/>
            <parameter>
              <valueString value="Observation"/>
            </parameter>
          </target>
          <rule>
            <name value="id"/>
            <source>
              <context value="qr"/>
            </source>
            <target>
              <variable value="idText"/>
              <transform value="append"/>
              <parameter>
                <valueId value="qid"/>
              </parameter>
              <parameter>
                <valueString value="-medications-none"/>
              </parameter>
            </target>
            <target>
              <context value="obs"/>
              <element value="id"/>
              <transform value="cast"/>
              <parameter>
                <valueId value="idText"/>
              </parameter>
              <parameter>
                <valueString value="id"/>
              </parameter>
            </target>
          </rule>
          <rule>
            <name value="fullUrl"/>
            <source>
              <context value="qr"/>
            </source>
            <target>
              <context value="e"/>
              <element value="fullUrl"/>
              <transform value="append"/>
              <parameter>
                <valueString value="Observation/"/>
              </parameter>
              <parameter>
                <valueId value="qid"/>
              </parameter>
              <parameter>
                <valueString value="-medications-none"/>
              </parameter>
            </target>
          </rule>
          <rule>
            <name value="request"/>
            <source>
              <context value="qr"/>
            </source>
            <target>
              <context value="e"/>
              <element value="request"/>
              <variable value="rq"/>
            </target>
            <rule>
              <name value="method"/>
              <source>
                <context value="qr"/>
              </source>
              <target>
                <context value="rq"/>
                <element value="method"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="PUT"/>
                </parameter>
              </target>
            </rule>
            <rule>
              <name value="url"/>
              <source>
                <context value="qr"/>
              </source>
              <target>
                <context value="rq"/>
                <element value="url"/>
                <transform value="append"/>
                <parameter>
                  <valueString value="Observation/"/>
                </parameter>
                <parameter>
                  <valueId value="qid"/>
                </parameter>
                <parameter>
                  <valueString value="-medications-none"/>
                </parameter>
              </target>
            </rule>
          </rule>
          <rule>
            <name value="profile"/>
            <source>
              <context value="qr"/>
            </source>
            <target>
              <context value="obs"/>
              <element value="meta"/>
              <variable value="m"/>
            </target>
            <target>
              <context value="m"/>
              <element value="profile"/>
              <transform value="copy"/>
              <parameter>
                <valueString
                             value="https://fhir.optimalhealth.org/ig/healthy-route/StructureDefinition/hr-observation"/>
              </parameter>
            </target>
          </rule>
          <rule>
            <name value="tags"/>
            <source>
              <context value="qr"/>
              <element value="meta"/>
              <variable value="qm"/>
            </source>
            <rule>
              <name value="tag"/>
              <source>
                <context value="qm"/>
                <element value="tag"/>
                <variable value="t"/>
              </source>
              <target>
                <context value="obs"/>
                <element value="meta"/>
                <variable value="m"/>
              </target>
              <target>
                <context value="m"/>
                <element value="tag"/>
                <transform value="copy"/>
                <parameter>
                  <valueId value="t"/>
                </parameter>
              </target>
            </rule>
          </rule>
          <rule>
            <name value="tenant"/>
            <source>
              <context value="qr"/>
              <element value="extension"/>
              <variable value="x"/>
              <condition
                         value="url = 'https://fhir.optimalhealth.org/ig/healthy-route/StructureDefinition/hr-tenant'"/>
            </source>
            <target>
              <context value="obs"/>
              <element value="extension"/>
              <transform value="copy"/>
              <parameter>
                <valueId value="x"/>
              </parameter>
            </target>
          </rule>
          <rule>
            <name value="status"/>
            <source>
              <context value="qr"/>
            </source>
            <target>
              <context value="obs"/>
              <element value="status"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="final"/>
              </parameter>
            </target>
          </rule>
          <rule>
            <name value="category"/>
            <source>
              <context value="qr"/>
            </source>
            <target>
              <context value="obs"/>
              <element value="category"/>
              <variable value="cv"/>
              <transform value="create"/>
              <parameter>
                <valueString value="CodeableConcept"/>
              </parameter>
            </target>
            <rule>
              <name value="categoryCoding"/>
              <source>
                <context value="qr"/>
              </source>
              <target>
                <context value="cv"/>
                <element value="coding"/>
                <variable value="cd"/>
                <transform value="create"/>
                <parameter>
                  <valueString value="Coding"/>
                </parameter>
              </target>
              <rule>
                <name value="categorySystem"/>
                <source>
                  <context value="qr"/>
                </source>
                <target>
                  <context value="cd"/>
                  <element value="system"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString
                                 value="http://terminology.hl7.org/CodeSystem/observation-category"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="categoryCode"/>
                <source>
                  <context value="qr"/>
                </source>
                <target>
                  <context value="cd"/>
                  <element value="code"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="survey"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="categoryDisplay"/>
                <source>
                  <context value="qr"/>
                </source>
                <target>
                  <context value="cd"/>
                  <element value="display"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="Survey"/>
                  </parameter>
                </target>
              </rule>
            </rule>
          </rule>
          <rule>
            <name value="code"/>
            <source>
              <context value="qr"/>
            </source>
            <target>
              <context value="obs"/>
              <element value="code"/>
              <variable value="cv"/>
              <transform value="create"/>
              <parameter>
                <valueString value="CodeableConcept"/>
              </parameter>
            </target>
            <rule>
              <name value="codeCoding"/>
              <source>
                <context value="qr"/>
              </source>
              <target>
                <context value="cv"/>
                <element value="coding"/>
                <variable value="cd"/>
                <transform value="create"/>
                <parameter>
                  <valueString value="Coding"/>
                </parameter>
              </target>
              <rule>
                <name value="codeSystem"/>
                <source>
                  <context value="qr"/>
                </source>
                <target>
                  <context value="cd"/>
                  <element value="system"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString
                                 value="https://fhir.optimalhealth.org/ig/healthy-route/CodeSystem/hr-measurement"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="codeCode"/>
                <source>
                  <context value="qr"/>
                </source>
                <target>
                  <context value="cd"/>
                  <element value="code"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="medications-none"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="codeDisplay"/>
                <source>
                  <context value="qr"/>
                </source>
                <target>
                  <context value="cd"/>
                  <element value="display"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueString value="No current medication"/>
                  </parameter>
                </target>
              </rule>
            </rule>
          </rule>
          <rule>
            <name value="subject"/>
            <source>
              <context value="qr"/>
              <element value="subject"/>
              <variable value="s"/>
            </source>
            <target>
              <context value="obs"/>
              <element value="subject"/>
              <transform value="copy"/>
              <parameter>
                <valueId value="s"/>
              </parameter>
            </target>
          </rule>
          <rule>
            <name value="encounter"/>
            <source>
              <context value="qr"/>
              <element value="encounter"/>
              <variable value="en"/>
            </source>
            <target>
              <context value="obs"/>
              <element value="encounter"/>
              <transform value="copy"/>
              <parameter>
                <valueId value="en"/>
              </parameter>
            </target>
          </rule>
          <rule>
            <name value="effective"/>
            <source>
              <context value="qr"/>
              <element value="authored"/>
              <variable value="t"/>
            </source>
            <target>
              <context value="obs"/>
              <element value="effective"/>
              <transform value="copy"/>
              <parameter>
                <valueId value="t"/>
              </parameter>
            </target>
          </rule>
          <rule>
            <name value="performer"/>
            <source>
              <context value="qr"/>
              <element value="author"/>
              <variable value="au"/>
            </source>
            <target>
              <context value="obs"/>
              <element value="performer"/>
              <transform value="copy"/>
              <parameter>
                <valueId value="au"/>
              </parameter>
            </target>
          </rule>
          <rule>
            <name value="value"/>
            <source>
              <context value="qr"/>
            </source>
            <target>
              <context value="obs"/>
              <element value="value"/>
              <transform value="copy"/>
              <parameter>
                <valueBoolean value="true"/>
              </parameter>
            </target>
          </rule>
        </rule>
      </rule>
      <rule>
        <name value="medicine"/>
        <source>
          <context value="qr"/>
          <element value="item"/>
          <variable value="g"/>
          <condition value="linkId = 'medicine'"/>
        </source>
        <target>
          <context value="bundle"/>
          <element value="entry"/>
          <variable value="e"/>
        </target>
        <target>
          <context value="e"/>
          <element value="resource"/>
          <variable value="ms"/>
          <transform value="create"/>
          <parameter>
            <valueString value="MedicationStatement"/>
          </parameter>
        </target>
        <rule>
          <name value="code"/>
          <source>
            <context value="g"/>
            <element value="item"/>
            <variable value="ci"/>
            <condition value="linkId = 'medicine.code'"/>
          </source>
          <rule>
            <name value="answer"/>
            <source>
              <context value="ci"/>
              <element value="answer"/>
              <listMode value="first"/>
              <variable value="ca"/>
            </source>
            <rule>
              <name value="coded"/>
              <source>
                <context value="ca"/>
                <type value="Coding"/>
                <element value="value"/>
                <variable value="cv"/>
              </source>
              <rule>
                <name value="id"/>
                <source>
                  <context value="cv"/>
                  <element value="code"/>
                  <variable value="c"/>
                </source>
                <target>
                  <variable value="idText"/>
                  <transform value="append"/>
                  <parameter>
                    <valueId value="qid"/>
                  </parameter>
                  <parameter>
                    <valueString value="-medicine-"/>
                  </parameter>
                  <parameter>
                    <valueId value="c"/>
                  </parameter>
                </target>
                <target>
                  <context value="ms"/>
                  <element value="id"/>
                  <transform value="cast"/>
                  <parameter>
                    <valueId value="idText"/>
                  </parameter>
                  <parameter>
                    <valueString value="id"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="fullUrl"/>
                <source>
                  <context value="cv"/>
                  <element value="code"/>
                  <variable value="c"/>
                </source>
                <target>
                  <context value="e"/>
                  <element value="fullUrl"/>
                  <transform value="append"/>
                  <parameter>
                    <valueString value="MedicationStatement/"/>
                  </parameter>
                  <parameter>
                    <valueId value="qid"/>
                  </parameter>
                  <parameter>
                    <valueString value="-medicine-"/>
                  </parameter>
                  <parameter>
                    <valueId value="c"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="request"/>
                <source>
                  <context value="cv"/>
                  <element value="code"/>
                  <variable value="c"/>
                </source>
                <target>
                  <context value="e"/>
                  <element value="request"/>
                  <variable value="rq"/>
                </target>
                <rule>
                  <name value="method"/>
                  <source>
                    <context value="qr"/>
                  </source>
                  <target>
                    <context value="rq"/>
                    <element value="method"/>
                    <transform value="copy"/>
                    <parameter>
                      <valueString value="PUT"/>
                    </parameter>
                  </target>
                </rule>
                <rule>
                  <name value="url"/>
                  <source>
                    <context value="qr"/>
                  </source>
                  <target>
                    <context value="rq"/>
                    <element value="url"/>
                    <transform value="append"/>
                    <parameter>
                      <valueString value="MedicationStatement/"/>
                    </parameter>
                    <parameter>
                      <valueId value="qid"/>
                    </parameter>
                    <parameter>
                      <valueString value="-medicine-"/>
                    </parameter>
                    <parameter>
                      <valueId value="c"/>
                    </parameter>
                  </target>
                </rule>
              </rule>
              <rule>
                <name value="medication"/>
                <source>
                  <context value="cv"/>
                </source>
                <target>
                  <context value="ms"/>
                  <element value="medication"/>
                  <variable value="cr"/>
                  <transform value="create"/>
                  <parameter>
                    <valueString value="CodeableReference"/>
                  </parameter>
                </target>
                <target>
                  <context value="cr"/>
                  <element value="concept"/>
                  <variable value="concept"/>
                  <transform value="create"/>
                  <parameter>
                    <valueString value="CodeableConcept"/>
                  </parameter>
                </target>
                <rule>
                  <name value="coding"/>
                  <source>
                    <context value="cv"/>
                  </source>
                  <target>
                    <context value="concept"/>
                    <element value="coding"/>
                    <transform value="copy"/>
                    <parameter>
                      <valueId value="cv"/>
                    </parameter>
                  </target>
                </rule>
                <rule>
                  <name value="text"/>
                  <source>
                    <context value="cv"/>
                    <element value="display"/>
                    <variable value="d"/>
                  </source>
                  <target>
                    <context value="concept"/>
                    <element value="text"/>
                    <transform value="copy"/>
                    <parameter>
                      <valueId value="d"/>
                    </parameter>
                  </target>
                </rule>
              </rule>
            </rule>
            <rule>
              <name value="unlisted"/>
              <source>
                <context value="ca"/>
                <type value="string"/>
                <element value="value"/>
                <variable value="sv"/>
              </source>
              <rule>
                <name value="id"/>
                <source>
                  <context value="qr"/>
                </source>
                <target>
                  <context value="ms"/>
                  <element value="id"/>
                  <variable value="newId"/>
                  <transform value="uuid"/>
                </target>
                <target>
                  <context value="e"/>
                  <element value="fullUrl"/>
                  <transform value="append"/>
                  <parameter>
                    <valueString value="urn:uuid:"/>
                  </parameter>
                  <parameter>
                    <valueId value="newId"/>
                  </parameter>
                </target>
              </rule>
              <rule>
                <name value="request"/>
                <source>
                  <context value="qr"/>
                </source>
                <target>
                  <context value="e"/>
                  <element value="request"/>
                  <variable value="rq"/>
                </target>
                <rule>
                  <name value="method"/>
                  <source>
                    <context value="qr"/>
                  </source>
                  <target>
                    <context value="rq"/>
                    <element value="method"/>
                    <transform value="copy"/>
                    <parameter>
                      <valueString value="POST"/>
                    </parameter>
                  </target>
                </rule>
                <rule>
                  <name value="url"/>
                  <source>
                    <context value="qr"/>
                  </source>
                  <target>
                    <context value="rq"/>
                    <element value="url"/>
                    <transform value="copy"/>
                    <parameter>
                      <valueString value="MedicationStatement"/>
                    </parameter>
                  </target>
                </rule>
              </rule>
              <rule>
                <name value="medication"/>
                <source>
                  <context value="sv"/>
                </source>
                <target>
                  <context value="ms"/>
                  <element value="medication"/>
                  <variable value="cr"/>
                  <transform value="create"/>
                  <parameter>
                    <valueString value="CodeableReference"/>
                  </parameter>
                </target>
                <target>
                  <context value="cr"/>
                  <element value="concept"/>
                  <variable value="concept"/>
                  <transform value="create"/>
                  <parameter>
                    <valueString value="CodeableConcept"/>
                  </parameter>
                </target>
                <target>
                  <context value="concept"/>
                  <element value="text"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueId value="sv"/>
                  </parameter>
                </target>
              </rule>
            </rule>
          </rule>
        </rule>
        <rule>
          <name value="profile"/>
          <source>
            <context value="qr"/>
          </source>
          <target>
            <context value="ms"/>
            <element value="meta"/>
            <variable value="m"/>
          </target>
          <target>
            <context value="m"/>
            <element value="profile"/>
            <transform value="copy"/>
            <parameter>
              <valueString
                           value="https://fhir.optimalhealth.org/ig/healthy-route/StructureDefinition/hr-medication-statement"/>
            </parameter>
          </target>
        </rule>
        <rule>
          <name value="tags"/>
          <source>
            <context value="qr"/>
            <element value="meta"/>
            <variable value="qm"/>
          </source>
          <rule>
            <name value="tag"/>
            <source>
              <context value="qm"/>
              <element value="tag"/>
              <variable value="t"/>
            </source>
            <target>
              <context value="ms"/>
              <element value="meta"/>
              <variable value="m"/>
            </target>
            <target>
              <context value="m"/>
              <element value="tag"/>
              <transform value="copy"/>
              <parameter>
                <valueId value="t"/>
              </parameter>
            </target>
          </rule>
        </rule>
        <rule>
          <name value="tenant"/>
          <source>
            <context value="qr"/>
            <element value="extension"/>
            <variable value="x"/>
            <condition
                       value="url = 'https://fhir.optimalhealth.org/ig/healthy-route/StructureDefinition/hr-tenant'"/>
          </source>
          <target>
            <context value="ms"/>
            <element value="extension"/>
            <transform value="copy"/>
            <parameter>
              <valueId value="x"/>
            </parameter>
          </target>
        </rule>
        <rule>
          <name value="status"/>
          <source>
            <context value="qr"/>
          </source>
          <target>
            <context value="ms"/>
            <element value="status"/>
            <transform value="copy"/>
            <parameter>
              <valueString value="recorded"/>
            </parameter>
          </target>
        </rule>
        <rule>
          <name value="subject"/>
          <source>
            <context value="qr"/>
            <element value="subject"/>
            <variable value="s"/>
          </source>
          <target>
            <context value="ms"/>
            <element value="subject"/>
            <transform value="copy"/>
            <parameter>
              <valueId value="s"/>
            </parameter>
          </target>
        </rule>
        <rule>
          <name value="encounter"/>
          <source>
            <context value="qr"/>
            <element value="encounter"/>
            <variable value="en"/>
          </source>
          <target>
            <context value="ms"/>
            <element value="encounter"/>
            <transform value="copy"/>
            <parameter>
              <valueId value="en"/>
            </parameter>
          </target>
        </rule>
        <rule>
          <name value="asserted"/>
          <source>
            <context value="qr"/>
            <element value="authored"/>
            <variable value="t"/>
          </source>
          <target>
            <context value="ms"/>
            <element value="dateAsserted"/>
            <transform value="copy"/>
            <parameter>
              <valueId value="t"/>
            </parameter>
          </target>
        </rule>
        <rule>
          <name value="source"/>
          <source>
            <context value="qr"/>
            <element value="author"/>
            <variable value="au"/>
          </source>
          <target>
            <context value="ms"/>
            <element value="informationSource"/>
            <transform value="copy"/>
            <parameter>
              <valueId value="au"/>
            </parameter>
          </target>
        </rule>
        <rule>
          <name value="dosage"/>
          <source>
            <context value="qr"/>
          </source>
          <target>
            <context value="ms"/>
            <element value="dosage"/>
            <variable value="dos"/>
          </target>
          <rule>
            <name value="routeItem"/>
            <source>
              <context value="g"/>
              <element value="item"/>
              <variable value="ri"/>
              <condition value="linkId = 'medicine.route'"/>
            </source>
            <rule>
              <name value="answer"/>
              <source>
                <context value="ri"/>
                <element value="answer"/>
                <listMode value="first"/>
                <variable value="ra"/>
              </source>
              <rule>
                <name value="route"/>
                <source>
                  <context value="ra"/>
                  <element value="value"/>
                  <variable value="rv"/>
                </source>
                <target>
                  <context value="dos"/>
                  <element value="route"/>
                  <variable value="concept"/>
                  <transform value="create"/>
                  <parameter>
                    <valueString value="CodeableConcept"/>
                  </parameter>
                </target>
                <target>
                  <context value="concept"/>
                  <element value="coding"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueId value="rv"/>
                  </parameter>
                </target>
              </rule>
            </rule>
          </rule>
          <rule>
            <name value="frequencyItem"/>
            <source>
              <context value="g"/>
              <element value="item"/>
              <variable value="fi"/>
              <condition value="linkId = 'medicine.frequency'"/>
            </source>
            <rule>
              <name value="answer"/>
              <source>
                <context value="fi"/>
                <element value="answer"/>
                <listMode value="first"/>
                <variable value="fa"/>
              </source>
              <rule>
                <name value="frequency"/>
                <source>
                  <context value="fa"/>
                  <element value="value"/>
                  <variable value="fv"/>
                </source>
                <target>
                  <context value="dos"/>
                  <element value="timing"/>
                  <variable value="tm"/>
                </target>
                <target>
                  <context value="tm"/>
                  <element value="code"/>
                  <variable value="concept"/>
                  <transform value="create"/>
                  <parameter>
                    <valueString value="CodeableConcept"/>
                  </parameter>
                </target>
                <target>
                  <context value="concept"/>
                  <element value="coding"/>
                  <transform value="copy"/>
                  <parameter>
                    <valueId value="fv"/>
                  </parameter>
                </target>
              </rule>
            </rule>
          </rule>
        </rule>
        <rule>
          <name value="strengthItem"/>
          <source>
            <context value="g"/>
            <element value="item"/>
            <variable value="si"/>
            <condition value="linkId = 'medicine.strength'"/>
          </source>
          <rule>
            <name value="answer"/>
            <source>
              <context value="si"/>
              <element value="answer"/>
              <listMode value="first"/>
              <variable value="sa"/>
            </source>
            <rule>
              <name value="strength"/>
              <source>
                <context value="sa"/>
                <element value="value"/>
                <variable value="sv"/>
              </source>
              <target>
                <context value="ms"/>
                <element value="note"/>
                <variable value="n"/>
              </target>
              <target>
                <context value="n"/>
                <element value="text"/>
                <transform value="append"/>
                <parameter>
                  <valueId value="sv"/>
                </parameter>
                <parameter>
                  <valueString value=", strength as recorded"/>
                </parameter>
              </target>
            </rule>
          </rule>
        </rule>
        <rule>
          <name value="formItem"/>
          <source>
            <context value="g"/>
            <element value="item"/>
            <variable value="fo"/>
            <condition value="linkId = 'medicine.form'"/>
          </source>
          <rule>
            <name value="answer"/>
            <source>
              <context value="fo"/>
              <element value="answer"/>
              <listMode value="first"/>
              <variable value="fa"/>
            </source>
            <rule>
              <name value="coding"/>
              <source>
                <context value="fa"/>
                <element value="value"/>
                <variable value="fv"/>
              </source>
              <rule>
                <name value="form"/>
                <source>
                  <context value="fv"/>
                  <element value="display"/>
                  <variable value="d"/>
                </source>
                <target>
                  <context value="ms"/>
                  <element value="note"/>
                  <variable value="n"/>
                </target>
                <target>
                  <context value="n"/>
                  <element value="text"/>
                  <transform value="append"/>
                  <parameter>
                    <valueId value="d"/>
                  </parameter>
                  <parameter>
                    <valueString value=", form as recorded"/>
                  </parameter>
                </target>
              </rule>
            </rule>
          </rule>
        </rule>
        <rule>
          <name value="reasonItem"/>
          <source>
            <context value="g"/>
            <element value="item"/>
            <variable value="re"/>
            <condition value="linkId = 'medicine.reason'"/>
          </source>
          <rule>
            <name value="answer"/>
            <source>
              <context value="re"/>
              <element value="answer"/>
              <listMode value="first"/>
              <variable value="ra"/>
            </source>
            <rule>
              <name value="reason"/>
              <source>
                <context value="ra"/>
                <element value="value"/>
                <variable value="rv"/>
              </source>
              <target>
                <context value="ms"/>
                <element value="reason"/>
                <variable value="cr"/>
                <transform value="create"/>
                <parameter>
                  <valueString value="CodeableReference"/>
                </parameter>
              </target>
              <target>
                <context value="cr"/>
                <element value="concept"/>
                <variable value="concept"/>
                <transform value="create"/>
                <parameter>
                  <valueString value="CodeableConcept"/>
                </parameter>
              </target>
              <target>
                <context value="concept"/>
                <element value="text"/>
                <transform value="copy"/>
                <parameter>
                  <valueId value="rv"/>
                </parameter>
              </target>
            </rule>
          </rule>
        </rule>
      </rule>
    </rule>
  </group>
</StructureMap>