Structured Data Capture
4.0.0-ballot - STU 4 ballot International flag

This page is part of the Structured Data Capture FHIR IG (v4.0.0-ballot: STU 4 Ballot 1) based on FHIR (HL7® FHIR® Standard) R4. The current version which supersedes this version is 3.0.0. For a full list of available versions, see the Directory of published versions

: QuestionnairePopulationTransform - XML Representation

Page standards status: Trial-use Maturity Level: 4

Raw xml | Download


<StructureMap xmlns="http://hl7.org/fhir">
  <id value="QuestionnairePopulationTransform"/>
  <text>
    <status value="additional"/>
    <div xmlns="http://www.w3.org/1999/xhtml">
      <pre>/// name = &quot;QuestionnairePopulationTransform&quot;
/// status = &quot;active&quot;
/// title = &quot;Questionnaire Population Transform Example&quot;
/// description = &quot;An example of a StructureMap used to support population of a QuestionnaireResponse from a search bundle&quot;
/// experimental = &quot;true&quot;

map &quot;http://hl7.org/fhir/uv/sdc/StructureMap/QuestionnairePopulationTransform&quot; = &quot;QuestionnairePopulationTransform&quot;

uses 'http://hl7.org/fhir/StructureDefinition/Bundle' as source
uses 'http://hl7.org/fhir/StructureDefinition/QuestionnaireResponse' as target
uses 'http://hl7.org/fhir/StructureDefinition/MedicationStatement' as source

// The input bundle is a search bundle that contains search bundles for patient, condition, and medication statement resources

group main(source src : Bundle, target qr : QuestionnaireResponse) {
  src -&gt; qr.questionnaire = 'http://hl7.org/fhir/uv/sdc/Questionnaire/questionnaire-sdc-test-fhirpath-prepop-source-query' &quot;questionnaire&quot;;
  src -&gt; qr.status = 'in-progress' &quot;status&quot;;
  src -&gt; qr.authored = (now()) &quot;authored&quot;;
  src.entry first as patient -&gt; qr.subject as subject, subject.reference = (%patient.resource.entry.fullUrl.toString()) &quot;subject&quot;;

  src -&gt; qr.item as grp, grp.linkId = 'grp' then {
    src -&gt; grp.item as partDetails, partDetails.linkId = 'part-details' then {
      src.entry first as patient then {
        patient.resource : Bundle as patientRes -&gt; partDetails then populatePatientGroup(patientRes, partDetails) &quot;partBundleDetails&quot;;
      } &quot;patientDetails&quot;;
      src.entry as conditions where (resource.link.url.contains(&quot;/Condition?&quot;)) -&gt; partDetails.item as conditionItem, conditionItem.linkId = 'condition-count' then {
        conditions -&gt; conditionItem.answer as conditionCountAnswer, conditionCountAnswer.value = (%conditions.resource.entry.count()) &quot;conditionCountAnswer&quot;;
      } &quot;conditionCount&quot;;
    } &quot;partDetails&quot;;

    // Scan the search bundle for a medication statement bunde
    src.entry as medications where (resource.link.url.contains(&quot;/MedicationStatement?&quot;)) -&gt; grp then {
      medications.resource : Bundle as medRes then populateMedicationsGroup(medRes, grp) &quot;medEntry&quot;;
    } &quot;meds&quot;;
  } &quot;grp&quot;;
}

group populatePatientGroup(source patientRes : Bundle, target partDetails) {
  patientRes -&gt; partDetails.item as participantId, 
                    participantId.linkId = 'participant-id',
                    participantId.answer as participantIdAnswer,
                    participantIdAnswer.value = (%patientRes.entry.resource.id.toString()) &quot;participantIdValue&quot;;

  patientRes -&gt; partDetails.item as familyName,
                    familyName.linkId = 'family-name',
                    familyName.answer as familyNameAnswer,
                    familyNameAnswer.value = (%patientRes.entry.resource.name.first().family) &quot;familyNameValue&quot;;

  patientRes -&gt; partDetails.item as givenName,
                    givenName.linkId = 'given-names',
                    givenName.answer as givenNameAnswer,
                    givenNameAnswer.value = (%patientRes.entry.resource.name.first().given.join(', ')) &quot;givenNameValue&quot;;
  patientRes -&gt; partDetails.item as dob, 
                    dob.linkId = 'dob',
                    dob.answer as dobAnswer,
                    dobAnswer.value = (%patientRes.entry.resource.birthDate) &quot;dobValue&quot;;
}

group populateMedicationsGroup(source medRes : Bundle, target grp) {
  medRes.entry as med where (resource is MedicationStatement) -&gt; grp.item as medsItem, medsItem.linkId = 'meds' then {
    med.resource : MedicationStatement as medResource -&gt; medsItem.item as medsName, 
                    medsName.linkId = 'med-name',
                    medsName.answer as medsNameAnswer, 
                    medsNameAnswer.value = (%medResource.medication.select(iif(text.exists(), text, coding.display.first()))) &quot;medsNameAnswer&quot;;
/* Todo handle medicationReference once resolve is supported
        iif($this is Reference, iif($this.resolve().text.exists(), $this.resolve().text, $this.resolve().coding.display.first()), iif(text, text, coding.display.first())))) &quot;medsNameAnswer&quot;;
*/
    
    med.resource : MedicationStatement as medResource -&gt; medsItem.item as medsStatus, medsStatus.linkId = 'med-status' then {
      medResource.status as medsMedicationStatus -&gt; medsStatus.answer as medsStatusAnswer, medsStatusAnswer.value = c('http://hl7.org/fhir/CodeSystem/medication-status', medsMedicationStatus) &quot;medsStatusAnswer&quot;;
    } &quot;medsStatus&quot;;
    
    med.resource as medResource where (category.coding.where(system='http://terminology.hl7.org/CodeSystem/medicationrequest-category').exists()) -&gt; medsItem.item as medsCategory, medsCategory.linkId = 'meds-category' then {
      medResource -&gt; medsCategory.answer as medsCategoryAnswer, medsCategoryAnswer.value = (%medResource.category.coding.where(system='http://terminology.hl7.org/CodeSystem/medicationrequest-category').code.join(' ')) &quot;medsCategoryAnswer&quot;;
    } &quot;medsCategory&quot;;
  } &quot;medItem&quot;;
}
</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/QuestionnairePopulationTransform"/>
  <identifier>
    <system value="urn:ietf:rfc:3986"/>
    <value value="urn:oid:2.16.840.1.113883.4.642.40.17.43.4"/>
  </identifier>
  <version value="4.0.0-ballot"/>
  <name value="QuestionnairePopulationTransform"/>
  <status value="draft"/>
  <date value="2024-12-17T01:55:34+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>
  <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>
  <structure>
    <url value="http://hl7.org/fhir/StructureDefinition/MedicationStatement"/>
    <mode value="source"/>
  </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.toString()"/>
        </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="partDetails"/>
        <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>
          <rule>
            <name value="partBundleDetails"/>
            <source>
              <context value="patient"/>
              <type value="Bundle"/>
              <element value="resource"/>
              <variable value="patientRes"/>
            </source>
            <target>
              <contextType value="variable"/>
              <transform value="copy"/>
              <parameter>
                <valueId value="partDetails"/>
              </parameter>
            </target>
            <dependent>
              <name value="populatePatientGroup"/>
              <variable value="patientRes"/>
              <variable value="partDetails"/>
            </dependent>
          </rule>
        </rule>
        <rule>
          <name value="conditionCount"/>
          <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"/>
            <type value="Bundle"/>
            <element value="resource"/>
            <variable value="medRes"/>
          </source>
          <dependent>
            <name value="populateMedicationsGroup"/>
            <variable value="medRes"/>
            <variable value="grp"/>
          </dependent>
        </rule>
      </rule>
    </rule>
  </group>
  <group>
    <name value="populatePatientGroup"/>
    <typeMode value="none"/>
    <input>
      <name value="patientRes"/>
      <type value="Bundle"/>
      <mode value="source"/>
    </input>
    <input>
      <name value="partDetails"/>
      <mode value="target"/>
    </input>
    <rule>
      <name value="participantIdValue"/>
      <source>
        <context 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>
      <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="%patientRes.entry.resource.id.toString()"/>
        </parameter>
      </target>
    </rule>
    <rule>
      <name value="familyNameValue"/>
      <source>
        <context 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>
      <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="%patientRes.entry.resource.name.first().family"/>
        </parameter>
      </target>
    </rule>
    <rule>
      <name value="givenNameValue"/>
      <source>
        <context 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-names"/>
        </parameter>
      </target>
      <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="%patientRes.entry.resource.name.first().given.join(', ')"/>
        </parameter>
      </target>
    </rule>
    <rule>
      <name value="dobValue"/>
      <source>
        <context 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>
      <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="%patientRes.entry.resource.birthDate"/>
        </parameter>
      </target>
    </rule>
  </group>
  <group>
    <name value="populateMedicationsGroup"/>
    <typeMode value="none"/>
    <input>
      <name value="medRes"/>
      <type value="Bundle"/>
      <mode value="source"/>
    </input>
    <input>
      <name value="grp"/>
      <mode value="target"/>
    </input>
    <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="medsNameAnswer"/>
        <source>
          <context value="med"/>
          <type value="MedicationStatement"/>
          <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="med-name"/>
          </parameter>
        </target>
        <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="%medResource.medication.select(iif(text.exists(), text, coding.display.first()))"/>
          </parameter>
        </target>
      </rule>
      <rule>
        <name value="medsStatus"/>
        <source>
          <context value="med"/>
          <type value="MedicationStatement"/>
          <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="status"/>
            <variable value="medsMedicationStatus"/>
          </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="c"/>
            <parameter>
              <valueString
                           value="http://hl7.org/fhir/CodeSystem/medication-status"/>
            </parameter>
            <parameter>
              <valueId value="medsMedicationStatus"/>
            </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.join(' ')"/>
            </parameter>
          </target>
        </rule>
      </rule>
    </rule>
  </group>
</StructureMap>