Structured Data Capture
3.0.0 - STU 3 International flag

Structured Data Capture, published by HL7 International / FHIR Infrastructure. This guide is not an authorized publication; it is the continuous build for version 3.0.0 built by the FHIR (HL7® FHIR® Standard) CI Build. This version is based on the current content of https://github.com/HL7/sdc/ and changes regularly. See the Directory of published versions

: SDC Map population StructureMap example - XML Representation

Page standards status: Informative

Raw xml | Download



<StructureMap xmlns="http://hl7.org/fhir">
  <id value="questionnaire-population-transform"/>
  <text>
    <status value="generated"/>
    <div xmlns="http://www.w3.org/1999/xhtml"><pre class="fml">
<b>map</b><span style="color: navy"> &quot;</span>http://hl7.org/fhir/uv/sdc/StructureMap/questionnaire-population-transform<span style="color: navy">&quot; = &quot;</span>QuestionnairePopulationTransform<span style="color: navy">&quot;

</span><span style="color: navy">// </span><span style="color: green">Sample structure map showing process for auto-populating a QuestionnaireResponse from a query bundle</span>

<b>uses</b><span style="color: navy"> &quot;</span><a href="http://hl7.org/fhir/R4/bundle.html" title="Bundle">http://hl7.org/fhir/StructureDefinition/Bundle</a><span style="color: navy">&quot; </span><b>as </b><b>source</b>
<b>uses</b><span style="color: navy"> &quot;</span><a href="http://hl7.org/fhir/R4/questionnaireresponse.html" title="QuestionnaireResponse">http://hl7.org/fhir/StructureDefinition/QuestionnaireResponse</a><span style="color: navy">&quot; </span><b>as </b><b>target</b>

<b>group </b>main<span style="color: navy">(</span><b>source</b> <span style="color: maroon">src</span><span style="color: navy"> : </span>Bundle, <b>target</b> <span style="color: maroon">qr</span><span style="color: navy"> : </span>QuestionnaireResponse<span style="color: navy">)</span><span style="color: navy"> {
</span>  src<span style="color: navy"><b> -&gt; </b></span>qr.questionnaire = <span style="color: blue">'http://hl7.org/fhir/uv/sdc/Questionnaire/questionnaire-sdc-test-fhirpath-prepop-source-query'</span> <i>&quot;questionnaire&quot;</i><span style="color: navy">;</span>
  src<span style="color: navy"><b> -&gt; </b></span>qr.status = <span style="color: blue">'in-progress'</span> <i>&quot;status&quot;</i><span style="color: navy">;</span>
  src<span style="color: navy"><b> -&gt; </b></span>qr.authored = <span style="color: navy">(</span>now()<span style="color: navy">)</span> <i>&quot;authored&quot;</i><span style="color: navy">;</span>
  src.entry first<b> as </b><span style="color: maroon">patient</span><span style="color: navy"><b> -&gt; </b></span> qr.subject<b> as </b><span style="color: maroon">subject</span><span style="color: navy">, </span> subject.reference = <span style="color: navy">(</span>patient.resource.entry.fullUrl<span style="color: navy">)</span> <i>&quot;subject&quot;</i><span style="color: navy">;</span>
  src<span style="color: navy"><b> -&gt; </b></span> qr.item<b> as </b><span style="color: maroon">grp</span><span style="color: navy">, </span> grp.linkId = <span style="color: blue">'grp'</span><b> then</b><span style="color: navy"> {
</span>    src<span style="color: navy"><b> -&gt; </b></span> grp.item<b> as </b><span style="color: maroon">partDetails</span><span style="color: navy">, </span> partDetails.linkId = <span style="color: blue">'part-details'</span><b> then</b><span style="color: navy"> {
</span>      src.entry first<b> as </b><span style="color: maroon">patient</span><span style="color: navy"><b> -&gt; </b></span><span style="color: maroon">partDetails</span><b> then</b><span style="color: navy"> {
</span>        patient.resource<b> as </b><span style="color: maroon">patientRes</span><span style="color: navy"><b> -&gt; </b></span> partDetails.item<b> as </b><span style="color: maroon">participantId</span><span style="color: navy">, </span> participantId.linkId = <span style="color: blue">'participant-id'</span><b> then</b><span style="color: navy"> {
</span>          patientRes.entry<b> as </b><span style="color: maroon">patientResEntry</span><span style="color: navy"><b> -&gt; </b></span> participantId.answer<b> as </b><span style="color: maroon">participantIdAnswer</span><span style="color: navy">, </span> participantIdAnswer.value = <span style="color: navy">(</span>patientResEntry.resource.id<span style="color: navy">)</span> <i>&quot;participantIdValue&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;participantId&quot;</i><span style="color: navy">;</span>
        patient.resource<b> as </b><span style="color: maroon">patientRes</span><span style="color: navy"><b> -&gt; </b></span> partDetails.item<b> as </b><span style="color: maroon">familyName</span><span style="color: navy">, </span> familyName.linkId = <span style="color: blue">'family-name'</span><b> then</b><span style="color: navy"> {
</span>          patientRes.entry<b> as </b><span style="color: maroon">patientResEntry</span><span style="color: navy"><b> -&gt; </b></span> familyName.answer<b> as </b><span style="color: maroon">familyNameAnswer</span><span style="color: navy">, </span> familyNameAnswer.value = <span style="color: navy">(</span>patientResEntry.resource.name.first().family<span style="color: navy">)</span> <i>&quot;familyNameValue&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;familyName&quot;</i><span style="color: navy">;</span>
        patient.resource<b> as </b><span style="color: maroon">patientRes</span><span style="color: navy"><b> -&gt; </b></span> partDetails.item<b> as </b><span style="color: maroon">givenName</span><span style="color: navy">, </span> givenName.linkId = <span style="color: blue">'given-name'</span><b> then</b><span style="color: navy"> {
</span>          patientRes.entry<b> as </b><span style="color: maroon">patientResEntry</span><span style="color: navy"><b> -&gt; </b></span> givenName.answer<b> as </b><span style="color: maroon">givenNameAnswer</span><span style="color: navy">, </span> givenNameAnswer.value = <span style="color: navy">(</span>patientResEntry.resource.name.first().given.aggregate(iif($total.empty(), $this, $total &amp; ' ' &amp; $this))<span style="color: navy">)</span> <i>&quot;givenNameValue&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;givenName&quot;</i><span style="color: navy">;</span>
        patient.resource<b> as </b><span style="color: maroon">patientRes</span><span style="color: navy"><b> -&gt; </b></span> partDetails.item<b> as </b><span style="color: maroon">dob</span><span style="color: navy">, </span> dob.linkId = <span style="color: blue">'dob'</span><b> then</b><span style="color: navy"> {
</span>          patientRes.entry<b> as </b><span style="color: maroon">patientResEntry</span><span style="color: navy"><b> -&gt; </b></span> dob.answer<b> as </b><span style="color: maroon">dobAnswer</span><span style="color: navy">, </span> dobAnswer.value = <span style="color: navy">(</span>patientResEntry.resource.birthDate<span style="color: navy">)</span> <i>&quot;dobValue&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;dob&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;patientDetails&quot;</i><span style="color: navy">;</span>
      src.entry<b> as </b><span style="color: maroon">conditions</span><b> where </b>(resource.link.url.contains('/Condition?'))<span style="color: navy"><b> -&gt; </b></span> partDetails.item<b> as </b><span style="color: maroon">conditionItem</span><span style="color: navy">, </span> conditionItem.linkId = <span style="color: blue">'condition-count'</span><b> then</b><span style="color: navy"> {
</span>        conditions<span style="color: navy"><b> -&gt; </b></span> conditionItem.answer<b> as </b><span style="color: maroon">conditionCountAnswer</span><span style="color: navy">, </span> conditionCountAnswer.value = <span style="color: navy">(</span>conditions.resource.entry.count()<span style="color: navy">)</span> <i>&quot;conditionCountAnswer&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;condition-count&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;part-details&quot;</i><span style="color: navy">;</span>
    src.entry<b> as </b><span style="color: maroon">medications</span><b> where </b>(resource.link.url.contains('/MedicationStatement?'))<span style="color: navy"><b> -&gt; </b></span><span style="color: maroon">grp</span><b> then</b><span style="color: navy"> {
</span>      medications.resource<b> as </b><span style="color: maroon">medRes</span><span style="color: navy"><b> -&gt; </b></span><span style="color: maroon">grp</span><b> then</b><span style="color: navy"> {
</span>        medRes.entry<b> as </b><span style="color: maroon">med</span><b> where </b>(resource is MedicationStatement)<span style="color: navy"><b> -&gt; </b></span> grp.item<b> as </b><span style="color: maroon">medsItem</span><span style="color: navy">, </span> medsItem.linkId = <span style="color: blue">'meds'</span><b> then</b><span style="color: navy"> {
</span>          med.resource<b> as </b><span style="color: maroon">medResource</span><span style="color: navy"><b> -&gt; </b></span> medsItem.item<b> as </b><span style="color: maroon">medsName</span><span style="color: navy">, </span> medsName.linkId = <span style="color: blue">'meds-name'</span><b> then</b><span style="color: navy"> {
</span>            medResource.medication<b> as </b><span style="color: maroon">medMedication</span><span style="color: navy"><b> -&gt; </b></span> medsName.answer<b> as </b><span style="color: maroon">medsNameAnswer</span><span style="color: navy">, </span> medsNameAnswer.value = <span style="color: navy">(</span>medMedication.select(iif(text, text, coding.display.first()))<span style="color: navy">)</span> <i>&quot;medsNameAnswer&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;medsName&quot;</i><span style="color: navy">;</span>
          med.resource<b> as </b><span style="color: maroon">medResource</span><span style="color: navy"><b> -&gt; </b></span> medsItem.item<b> as </b><span style="color: maroon">medsStatus</span><span style="color: navy">, </span> medsStatus.linkId = <span style="color: blue">'med-status'</span><b> then</b><span style="color: navy"> {
</span>            medResource.medication<b> as </b><span style="color: maroon">medsMedication</span><span style="color: navy"><b> -&gt; </b></span> medsStatus.answer<b> as </b><span style="color: maroon">medsStatusAnswer</span><span style="color: navy">, </span> medsStatusAnswer.value = <span style="color: navy">(</span>medResource.status<span style="color: navy">)</span> <i>&quot;medsStatusAnswer&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;medsStatus&quot;</i><span style="color: navy">;</span>
          med.resource<b> as </b><span style="color: maroon">medResource</span><b> where </b>(category.coding.where(system = 'http://terminology.hl7.org/CodeSystem/medicationrequest-category').exists())<span style="color: navy"><b> -&gt; </b></span> medsItem.item<b> as </b><span style="color: maroon">medsCategory</span><span style="color: navy">, </span> medsCategory.linkId = <span style="color: blue">'meds-category'</span><b> then</b><span style="color: navy"> {
</span>            medResource<span style="color: navy"><b> -&gt; </b></span> medsCategory.answer<b> as </b><span style="color: maroon">medsCategoryAnswer</span><span style="color: navy">, </span> medsCategoryAnswer.value = <span style="color: navy">(</span>medResource.category.coding.where(system = 'http://terminology.hl7.org/CodeSystem/medicationrequest-category').code.aggregate(iif($total.empty(), $this, $total &amp; ' ' &amp; $this))<span style="color: navy">)</span> <i>&quot;medsCategoryAnswer&quot;</i><span style="color: navy">;</span>
          <span style="color: navy">}</span> <i>&quot;medsCategory&quot;</i><span style="color: navy">;</span>
        <span style="color: navy">}</span> <i>&quot;medItem&quot;</i><span style="color: navy">;</span>
      <span style="color: navy">}</span> <i>&quot;medEntry&quot;</i><span style="color: navy">;</span>
    <span style="color: navy">}</span> <i>&quot;meds&quot;</i><span style="color: navy">;</span>
  <span style="color: navy">}</span> <i>&quot;grp&quot;</i><span style="color: navy">;</span>
<span style="color: navy">}

</span></pre></div>
  </text>
  <extension
             url="http://hl7.org/fhir/StructureDefinition/structuredefinition-wg">
    <valueCode value="fhir"/>
  </extension>
  <url
       value="http://hl7.org/fhir/uv/sdc/StructureMap/questionnaire-population-transform"/>
  <version value="3.0.0"/>
  <name value="QuestionnairePopulationTransform"/>
  <title value="Questionnaire Population Transform"/>
  <status value="draft"/>
  <experimental value="true"/>
  <date value="2023-12-07T23:07:45+00:00"/>
  <publisher value="HL7 International / FHIR Infrastructure"/>
  <contact>
    <name value="HL7 International / FHIR Infrastructure"/>
    <telecom>
      <system value="url"/>
      <value value="http://www.hl7.org/Special/committees/fiwg"/>
    </telecom>
  </contact>
  <contact>
    <telecom>
      <system value="url"/>
      <value value="http://www.hl7.org/Special/committees/fiwg"/>
    </telecom>
  </contact>
  <description
               value="Sample structure map showing process for auto-populating a QuestionnaireResponse from a query bundle"/>
  <jurisdiction>
    <coding>
      <system value="http://unstats.un.org/unsd/methods/m49/m49.htm"/>
      <code value="001"/>
      <display value="World"/>
    </coding>
  </jurisdiction>
  <structure>
    <url value="http://hl7.org/fhir/StructureDefinition/Bundle"/>
    <mode value="source"/>
  </structure>
  <structure>
    <url
         value="http://hl7.org/fhir/StructureDefinition/QuestionnaireResponse"/>
    <mode value="target"/>
  </structure>
  <group>
    <name value="main"/>
    <typeMode value="none"/>
    <input>
      <name value="src"/>
      <type value="Bundle"/>
      <mode value="source"/>
    </input>
    <input>
      <name value="qr"/>
      <type value="QuestionnaireResponse"/>
      <mode value="target"/>
    </input>
    <rule>
      <name value="questionnaire"/>
      <source>
        <context value="src"/>
      </source>
      <target>
        <context value="qr"/>
        <contextType value="variable"/>
        <element value="questionnaire"/>
        <transform value="copy"/>
        <parameter>
          <valueString
                       value="http://hl7.org/fhir/uv/sdc/Questionnaire/questionnaire-sdc-test-fhirpath-prepop-source-query"/>
        </parameter>
      </target>
    </rule>
    <rule>
      <name value="status"/>
      <source>
        <context value="src"/>
      </source>
      <target>
        <context value="qr"/>
        <contextType value="variable"/>
        <element value="status"/>
        <transform value="copy"/>
        <parameter>
          <valueString value="in-progress"/>
        </parameter>
      </target>
    </rule>
    <rule>
      <name value="authored"/>
      <source>
        <context value="src"/>
      </source>
      <target>
        <context value="qr"/>
        <contextType value="variable"/>
        <element value="authored"/>
        <transform value="evaluate"/>
        <parameter>
          <valueString value="now()"/>
        </parameter>
      </target>
    </rule>
    <rule>
      <name value="subject"/>
      <source>
        <context value="src"/>
        <element value="entry"/>
        <listMode value="first"/>
        <variable value="patient"/>
      </source>
      <target>
        <context value="qr"/>
        <contextType value="variable"/>
        <element value="subject"/>
        <variable value="subject"/>
      </target>
      <target>
        <context value="subject"/>
        <contextType value="variable"/>
        <element value="reference"/>
        <transform value="evaluate"/>
        <parameter>
          <valueString value="patient.resource.entry.fullUrl"/>
        </parameter>
      </target>
    </rule>
    <rule>
      <name value="grp"/>
      <source>
        <context value="src"/>
      </source>
      <target>
        <context value="qr"/>
        <contextType value="variable"/>
        <element value="item"/>
        <variable value="grp"/>
      </target>
      <target>
        <context value="grp"/>
        <contextType value="variable"/>
        <element value="linkId"/>
        <transform value="copy"/>
        <parameter>
          <valueString value="grp"/>
        </parameter>
      </target>
      <rule>
        <name value="part-details"/>
        <source>
          <context value="src"/>
        </source>
        <target>
          <context value="grp"/>
          <contextType value="variable"/>
          <element value="item"/>
          <variable value="partDetails"/>
        </target>
        <target>
          <context value="partDetails"/>
          <contextType value="variable"/>
          <element value="linkId"/>
          <transform value="copy"/>
          <parameter>
            <valueString value="part-details"/>
          </parameter>
        </target>
        <rule>
          <name value="patientDetails"/>
          <source>
            <context value="src"/>
            <element value="entry"/>
            <listMode value="first"/>
            <variable value="patient"/>
          </source>
          <target>
            <contextType value="variable"/>
            <transform value="copy"/>
            <parameter>
              <valueId value="partDetails"/>
            </parameter>
          </target>
          <rule>
            <name value="participantId"/>
            <source>
              <context value="patient"/>
              <element value="resource"/>
              <variable value="patientRes"/>
            </source>
            <target>
              <context value="partDetails"/>
              <contextType value="variable"/>
              <element value="item"/>
              <variable value="participantId"/>
            </target>
            <target>
              <context value="participantId"/>
              <contextType value="variable"/>
              <element value="linkId"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="participant-id"/>
              </parameter>
            </target>
            <rule>
              <name value="participantIdValue"/>
              <source>
                <context value="patientRes"/>
                <element value="entry"/>
                <variable value="patientResEntry"/>
              </source>
              <target>
                <context value="participantId"/>
                <contextType value="variable"/>
                <element value="answer"/>
                <variable value="participantIdAnswer"/>
              </target>
              <target>
                <context value="participantIdAnswer"/>
                <contextType value="variable"/>
                <element value="value"/>
                <transform value="evaluate"/>
                <parameter>
                  <valueString value="patientResEntry.resource.id"/>
                </parameter>
              </target>
            </rule>
          </rule>
          <rule>
            <name value="familyName"/>
            <source>
              <context value="patient"/>
              <element value="resource"/>
              <variable value="patientRes"/>
            </source>
            <target>
              <context value="partDetails"/>
              <contextType value="variable"/>
              <element value="item"/>
              <variable value="familyName"/>
            </target>
            <target>
              <context value="familyName"/>
              <contextType value="variable"/>
              <element value="linkId"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="family-name"/>
              </parameter>
            </target>
            <rule>
              <name value="familyNameValue"/>
              <source>
                <context value="patientRes"/>
                <element value="entry"/>
                <variable value="patientResEntry"/>
              </source>
              <target>
                <context value="familyName"/>
                <contextType value="variable"/>
                <element value="answer"/>
                <variable value="familyNameAnswer"/>
              </target>
              <target>
                <context value="familyNameAnswer"/>
                <contextType value="variable"/>
                <element value="value"/>
                <transform value="evaluate"/>
                <parameter>
                  <valueString
                               value="patientResEntry.resource.name.first().family"/>
                </parameter>
              </target>
            </rule>
          </rule>
          <rule>
            <name value="givenName"/>
            <source>
              <context value="patient"/>
              <element value="resource"/>
              <variable value="patientRes"/>
            </source>
            <target>
              <context value="partDetails"/>
              <contextType value="variable"/>
              <element value="item"/>
              <variable value="givenName"/>
            </target>
            <target>
              <context value="givenName"/>
              <contextType value="variable"/>
              <element value="linkId"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="given-name"/>
              </parameter>
            </target>
            <rule>
              <name value="givenNameValue"/>
              <source>
                <context value="patientRes"/>
                <element value="entry"/>
                <variable value="patientResEntry"/>
              </source>
              <target>
                <context value="givenName"/>
                <contextType value="variable"/>
                <element value="answer"/>
                <variable value="givenNameAnswer"/>
              </target>
              <target>
                <context value="givenNameAnswer"/>
                <contextType value="variable"/>
                <element value="value"/>
                <transform value="evaluate"/>
                <parameter>
                  <valueString
                               value="patientResEntry.resource.name.first().given.aggregate(iif($total.empty(), $this, $total &amp; ' ' &amp; $this))"/>
                </parameter>
              </target>
            </rule>
          </rule>
          <rule>
            <name value="dob"/>
            <source>
              <context value="patient"/>
              <element value="resource"/>
              <variable value="patientRes"/>
            </source>
            <target>
              <context value="partDetails"/>
              <contextType value="variable"/>
              <element value="item"/>
              <variable value="dob"/>
            </target>
            <target>
              <context value="dob"/>
              <contextType value="variable"/>
              <element value="linkId"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="dob"/>
              </parameter>
            </target>
            <rule>
              <name value="dobValue"/>
              <source>
                <context value="patientRes"/>
                <element value="entry"/>
                <variable value="patientResEntry"/>
              </source>
              <target>
                <context value="dob"/>
                <contextType value="variable"/>
                <element value="answer"/>
                <variable value="dobAnswer"/>
              </target>
              <target>
                <context value="dobAnswer"/>
                <contextType value="variable"/>
                <element value="value"/>
                <transform value="evaluate"/>
                <parameter>
                  <valueString value="patientResEntry.resource.birthDate"/>
                </parameter>
              </target>
            </rule>
          </rule>
        </rule>
        <rule>
          <name value="condition-count"/>
          <source>
            <context value="src"/>
            <element value="entry"/>
            <variable value="conditions"/>
            <condition value="(resource.link.url.contains('/Condition?'))"/>
          </source>
          <target>
            <context value="partDetails"/>
            <contextType value="variable"/>
            <element value="item"/>
            <variable value="conditionItem"/>
          </target>
          <target>
            <context value="conditionItem"/>
            <contextType value="variable"/>
            <element value="linkId"/>
            <transform value="copy"/>
            <parameter>
              <valueString value="condition-count"/>
            </parameter>
          </target>
          <rule>
            <name value="conditionCountAnswer"/>
            <source>
              <context value="conditions"/>
            </source>
            <target>
              <context value="conditionItem"/>
              <contextType value="variable"/>
              <element value="answer"/>
              <variable value="conditionCountAnswer"/>
            </target>
            <target>
              <context value="conditionCountAnswer"/>
              <contextType value="variable"/>
              <element value="value"/>
              <transform value="evaluate"/>
              <parameter>
                <valueString value="conditions.resource.entry.count()"/>
              </parameter>
            </target>
          </rule>
        </rule>
      </rule>
      <rule>
        <name value="meds"/>
        <source>
          <context value="src"/>
          <element value="entry"/>
          <variable value="medications"/>
          <condition
                     value="(resource.link.url.contains('/MedicationStatement?'))"/>
        </source>
        <target>
          <contextType value="variable"/>
          <transform value="copy"/>
          <parameter>
            <valueId value="grp"/>
          </parameter>
        </target>
        <rule>
          <name value="medEntry"/>
          <source>
            <context value="medications"/>
            <element value="resource"/>
            <variable value="medRes"/>
          </source>
          <target>
            <contextType value="variable"/>
            <transform value="copy"/>
            <parameter>
              <valueId value="grp"/>
            </parameter>
          </target>
          <rule>
            <name value="medItem"/>
            <source>
              <context value="medRes"/>
              <element value="entry"/>
              <variable value="med"/>
              <condition value="(resource is MedicationStatement)"/>
            </source>
            <target>
              <context value="grp"/>
              <contextType value="variable"/>
              <element value="item"/>
              <variable value="medsItem"/>
            </target>
            <target>
              <context value="medsItem"/>
              <contextType value="variable"/>
              <element value="linkId"/>
              <transform value="copy"/>
              <parameter>
                <valueString value="meds"/>
              </parameter>
            </target>
            <rule>
              <name value="medsName"/>
              <source>
                <context value="med"/>
                <element value="resource"/>
                <variable value="medResource"/>
              </source>
              <target>
                <context value="medsItem"/>
                <contextType value="variable"/>
                <element value="item"/>
                <variable value="medsName"/>
              </target>
              <target>
                <context value="medsName"/>
                <contextType value="variable"/>
                <element value="linkId"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="meds-name"/>
                </parameter>
              </target>
              <rule>
                <name value="medsNameAnswer"/>
                <source>
                  <context value="medResource"/>
                  <element value="medication"/>
                  <variable value="medMedication"/>
                </source>
                <target>
                  <context value="medsName"/>
                  <contextType value="variable"/>
                  <element value="answer"/>
                  <variable value="medsNameAnswer"/>
                </target>
                <target>
                  <context value="medsNameAnswer"/>
                  <contextType value="variable"/>
                  <element value="value"/>
                  <transform value="evaluate"/>
                  <parameter>
                    <valueString
                                 value="medMedication.select(iif(text, text, coding.display.first()))"/>
                  </parameter>
                </target>
              </rule>
            </rule>
            <rule>
              <name value="medsStatus"/>
              <source>
                <context value="med"/>
                <element value="resource"/>
                <variable value="medResource"/>
              </source>
              <target>
                <context value="medsItem"/>
                <contextType value="variable"/>
                <element value="item"/>
                <variable value="medsStatus"/>
              </target>
              <target>
                <context value="medsStatus"/>
                <contextType value="variable"/>
                <element value="linkId"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="med-status"/>
                </parameter>
              </target>
              <rule>
                <name value="medsStatusAnswer"/>
                <source>
                  <context value="medResource"/>
                  <element value="medication"/>
                  <variable value="medsMedication"/>
                </source>
                <target>
                  <context value="medsStatus"/>
                  <contextType value="variable"/>
                  <element value="answer"/>
                  <variable value="medsStatusAnswer"/>
                </target>
                <target>
                  <context value="medsStatusAnswer"/>
                  <contextType value="variable"/>
                  <element value="value"/>
                  <transform value="evaluate"/>
                  <parameter>
                    <valueString value="medResource.status"/>
                  </parameter>
                </target>
              </rule>
            </rule>
            <rule>
              <name value="medsCategory"/>
              <source>
                <context value="med"/>
                <element value="resource"/>
                <variable value="medResource"/>
                <condition
                           value="(category.coding.where(system = 'http://terminology.hl7.org/CodeSystem/medicationrequest-category').exists())"/>
              </source>
              <target>
                <context value="medsItem"/>
                <contextType value="variable"/>
                <element value="item"/>
                <variable value="medsCategory"/>
              </target>
              <target>
                <context value="medsCategory"/>
                <contextType value="variable"/>
                <element value="linkId"/>
                <transform value="copy"/>
                <parameter>
                  <valueString value="meds-category"/>
                </parameter>
              </target>
              <rule>
                <name value="medsCategoryAnswer"/>
                <source>
                  <context value="medResource"/>
                </source>
                <target>
                  <context value="medsCategory"/>
                  <contextType value="variable"/>
                  <element value="answer"/>
                  <variable value="medsCategoryAnswer"/>
                </target>
                <target>
                  <context value="medsCategoryAnswer"/>
                  <contextType value="variable"/>
                  <element value="value"/>
                  <transform value="evaluate"/>
                  <parameter>
                    <valueString
                                 value="medResource.category.coding.where(system = 'http://terminology.hl7.org/CodeSystem/medicationrequest-category').code.aggregate(iif($total.empty(), $this, $total &amp; ' ' &amp; $this))"/>
                  </parameter>
                </target>
              </rule>
            </rule>
          </rule>
        </rule>
      </rule>
    </rule>
  </group>
</StructureMap>