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
Page standards status: Trial-use | Maturity Level: 4 |
<StructureMap xmlns="http://hl7.org/fhir">
<id value="QuestionnairePopulationTransform"/>
<text>
<status value="additional"/>
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>/// name = "QuestionnairePopulationTransform"
/// status = "active"
/// title = "Questionnaire Population Transform Example"
/// description = "An example of a StructureMap used to support population of a QuestionnaireResponse from a search bundle"
/// experimental = "true"
map "http://hl7.org/fhir/uv/sdc/StructureMap/QuestionnairePopulationTransform" = "QuestionnairePopulationTransform"
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 -> qr.questionnaire = 'http://hl7.org/fhir/uv/sdc/Questionnaire/questionnaire-sdc-test-fhirpath-prepop-source-query' "questionnaire";
src -> qr.status = 'in-progress' "status";
src -> qr.authored = (now()) "authored";
src.entry first as patient -> qr.subject as subject, subject.reference = (%patient.resource.entry.fullUrl.toString()) "subject";
src -> qr.item as grp, grp.linkId = 'grp' then {
src -> grp.item as partDetails, partDetails.linkId = 'part-details' then {
src.entry first as patient then {
patient.resource : Bundle as patientRes -> partDetails then populatePatientGroup(patientRes, partDetails) "partBundleDetails";
} "patientDetails";
src.entry as conditions where (resource.link.url.contains("/Condition?")) -> partDetails.item as conditionItem, conditionItem.linkId = 'condition-count' then {
conditions -> conditionItem.answer as conditionCountAnswer, conditionCountAnswer.value = (%conditions.resource.entry.count()) "conditionCountAnswer";
} "conditionCount";
} "partDetails";
// Scan the search bundle for a medication statement bunde
src.entry as medications where (resource.link.url.contains("/MedicationStatement?")) -> grp then {
medications.resource : Bundle as medRes then populateMedicationsGroup(medRes, grp) "medEntry";
} "meds";
} "grp";
}
group populatePatientGroup(source patientRes : Bundle, target partDetails) {
patientRes -> partDetails.item as participantId,
participantId.linkId = 'participant-id',
participantId.answer as participantIdAnswer,
participantIdAnswer.value = (%patientRes.entry.resource.id.toString()) "participantIdValue";
patientRes -> partDetails.item as familyName,
familyName.linkId = 'family-name',
familyName.answer as familyNameAnswer,
familyNameAnswer.value = (%patientRes.entry.resource.name.first().family) "familyNameValue";
patientRes -> partDetails.item as givenName,
givenName.linkId = 'given-names',
givenName.answer as givenNameAnswer,
givenNameAnswer.value = (%patientRes.entry.resource.name.first().given.join(', ')) "givenNameValue";
patientRes -> partDetails.item as dob,
dob.linkId = 'dob',
dob.answer as dobAnswer,
dobAnswer.value = (%patientRes.entry.resource.birthDate) "dobValue";
}
group populateMedicationsGroup(source medRes : Bundle, target grp) {
medRes.entry as med where (resource is MedicationStatement) -> grp.item as medsItem, medsItem.linkId = 'meds' then {
med.resource : MedicationStatement as medResource -> medsItem.item as medsName,
medsName.linkId = 'med-name',
medsName.answer as medsNameAnswer,
medsNameAnswer.value = (%medResource.medication.select(iif(text.exists(), text, coding.display.first()))) "medsNameAnswer";
/* 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())))) "medsNameAnswer";
*/
med.resource : MedicationStatement as medResource -> medsItem.item as medsStatus, medsStatus.linkId = 'med-status' then {
medResource.status as medsMedicationStatus -> medsStatus.answer as medsStatusAnswer, medsStatusAnswer.value = c('http://hl7.org/fhir/CodeSystem/medication-status', medsMedicationStatus) "medsStatusAnswer";
} "medsStatus";
med.resource as medResource where (category.coding.where(system='http://terminology.hl7.org/CodeSystem/medicationrequest-category').exists()) -> medsItem.item as medsCategory, medsCategory.linkId = 'meds-category' then {
medResource -> medsCategory.answer as medsCategoryAnswer, medsCategoryAnswer.value = (%medResource.category.coding.where(system='http://terminology.hl7.org/CodeSystem/medicationrequest-category').code.join(' ')) "medsCategoryAnswer";
} "medsCategory";
} "medItem";
}
</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>