Structured Data Capture, published by HL7 International / FHIR Infrastructure. This guide is not an authorized publication; it is the continuous build for version 4.0.0-ballot 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
Page standards status: Trial-use | Maturity Level: 4 |
{
"resourceType" : "StructureMap",
"id" : "QuestionnairePopulationTransform",
"text" : {
"status" : "additional",
"div" : "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n <pre>/// name = "QuestionnairePopulationTransform"\n/// status = "active"\n/// title = "Questionnaire Population Transform Example"\n/// description = "An example of a StructureMap used to support population of a QuestionnaireResponse from a search bundle"\n/// experimental = "true"\n\nmap "http://hl7.org/fhir/uv/sdc/StructureMap/QuestionnairePopulationTransform" = "QuestionnairePopulationTransform"\n\nuses 'http://hl7.org/fhir/StructureDefinition/Bundle' as source\nuses 'http://hl7.org/fhir/StructureDefinition/QuestionnaireResponse' as target\nuses 'http://hl7.org/fhir/StructureDefinition/MedicationStatement' as source\n\n// The input bundle is a search bundle that contains search bundles for patient, condition, and medication statement resources\n\ngroup main(source src : Bundle, target qr : QuestionnaireResponse) {\n src -> qr.questionnaire = 'http://hl7.org/fhir/uv/sdc/Questionnaire/questionnaire-sdc-test-fhirpath-prepop-source-query' "questionnaire";\n src -> qr.status = 'in-progress' "status";\n src -> qr.authored = (now()) "authored";\n src.entry first as patient -> qr.subject as subject, subject.reference = (%patient.resource.entry.fullUrl.toString()) "subject";\n\n src -> qr.item as grp, grp.linkId = 'grp' then {\n src -> grp.item as partDetails, partDetails.linkId = 'part-details' then {\n src.entry first as patient then {\n patient.resource : Bundle as patientRes -> partDetails then populatePatientGroup(patientRes, partDetails) "partBundleDetails";\n } "patientDetails";\n src.entry as conditions where (resource.link.url.contains("/Condition?")) -> partDetails.item as conditionItem, conditionItem.linkId = 'condition-count' then {\n conditions -> conditionItem.answer as conditionCountAnswer, conditionCountAnswer.value = (%conditions.resource.entry.count()) "conditionCountAnswer";\n } "conditionCount";\n } "partDetails";\n\n // Scan the search bundle for a medication statement bunde\n src.entry as medications where (resource.link.url.contains("/MedicationStatement?")) -> grp then {\n medications.resource : Bundle as medRes then populateMedicationsGroup(medRes, grp) "medEntry";\n } "meds";\n } "grp";\n}\n\ngroup populatePatientGroup(source patientRes : Bundle, target partDetails) {\n patientRes -> partDetails.item as participantId, \n participantId.linkId = 'participant-id',\n participantId.answer as participantIdAnswer,\n participantIdAnswer.value = (%patientRes.entry.resource.id.toString()) "participantIdValue";\n\n patientRes -> partDetails.item as familyName,\n familyName.linkId = 'family-name',\n familyName.answer as familyNameAnswer,\n familyNameAnswer.value = (%patientRes.entry.resource.name.first().family) "familyNameValue";\n\n patientRes -> partDetails.item as givenName,\n givenName.linkId = 'given-names',\n givenName.answer as givenNameAnswer,\n givenNameAnswer.value = (%patientRes.entry.resource.name.first().given.join(', ')) "givenNameValue";\n patientRes -> partDetails.item as dob, \n dob.linkId = 'dob',\n dob.answer as dobAnswer,\n dobAnswer.value = (%patientRes.entry.resource.birthDate) "dobValue";\n}\n\ngroup populateMedicationsGroup(source medRes : Bundle, target grp) {\n medRes.entry as med where (resource is MedicationStatement) -> grp.item as medsItem, medsItem.linkId = 'meds' then {\n med.resource : MedicationStatement as medResource -> medsItem.item as medsName, \n medsName.linkId = 'med-name',\n medsName.answer as medsNameAnswer, \n medsNameAnswer.value = (%medResource.medication.select(iif(text.exists(), text, coding.display.first()))) "medsNameAnswer";\n/* Todo handle medicationReference once resolve is supported\n iif($this is Reference, iif($this.resolve().text.exists(), $this.resolve().text, $this.resolve().coding.display.first()), iif(text, text, coding.display.first())))) "medsNameAnswer";\n*/\n \n med.resource : MedicationStatement as medResource -> medsItem.item as medsStatus, medsStatus.linkId = 'med-status' then {\n medResource.status as medsMedicationStatus -> medsStatus.answer as medsStatusAnswer, medsStatusAnswer.value = c('http://hl7.org/fhir/CodeSystem/medication-status', medsMedicationStatus) "medsStatusAnswer";\n } "medsStatus";\n \n 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 {\n medResource -> medsCategory.answer as medsCategoryAnswer, medsCategoryAnswer.value = (%medResource.category.coding.where(system='http://terminology.hl7.org/CodeSystem/medicationrequest-category').code.join(' ')) "medsCategoryAnswer";\n } "medsCategory";\n } "medItem";\n}\n</pre>\n </div>"
},
"extension" : [
{
"url" : "http://hl7.org/fhir/StructureDefinition/structuredefinition-wg",
"valueCode" : "fhir"
}
],
"url" : "http://hl7.org/fhir/uv/sdc/StructureMap/QuestionnairePopulationTransform",
"identifier" : [
{
"system" : "urn:ietf:rfc:3986",
"value" : "urn:oid:2.16.840.1.113883.4.642.40.17.43.4"
}
],
"version" : "4.0.0-ballot",
"name" : "QuestionnairePopulationTransform",
"status" : "draft",
"date" : "2024-12-16T09:47:19+00:00",
"publisher" : "HL7 International / FHIR Infrastructure",
"contact" : [
{
"name" : "HL7 International / FHIR Infrastructure",
"telecom" : [
{
"system" : "url",
"value" : "http://www.hl7.org/Special/committees/fiwg"
}
]
},
{
"telecom" : [
{
"system" : "url",
"value" : "http://www.hl7.org/Special/committees/fiwg"
}
]
}
],
"jurisdiction" : [
{
"coding" : [
{
"system" : "http://unstats.un.org/unsd/methods/m49/m49.htm",
"code" : "001",
"display" : "World"
}
]
}
],
"structure" : [
{
"url" : "http://hl7.org/fhir/StructureDefinition/Bundle",
"mode" : "source"
},
{
"url" : "http://hl7.org/fhir/StructureDefinition/QuestionnaireResponse",
"mode" : "target"
},
{
"url" : "http://hl7.org/fhir/StructureDefinition/MedicationStatement",
"mode" : "source"
}
],
"group" : [
{
"name" : "main",
"typeMode" : "none",
"input" : [
{
"name" : "src",
"type" : "Bundle",
"mode" : "source"
},
{
"name" : "qr",
"type" : "QuestionnaireResponse",
"mode" : "target"
}
],
"rule" : [
{
"name" : "questionnaire",
"source" : [
{
"context" : "src"
}
],
"target" : [
{
"context" : "qr",
"contextType" : "variable",
"element" : "questionnaire",
"transform" : "copy",
"parameter" : [
{
"valueString" : "http://hl7.org/fhir/uv/sdc/Questionnaire/questionnaire-sdc-test-fhirpath-prepop-source-query"
}
]
}
]
},
{
"name" : "status",
"source" : [
{
"context" : "src"
}
],
"target" : [
{
"context" : "qr",
"contextType" : "variable",
"element" : "status",
"transform" : "copy",
"parameter" : [
{
"valueString" : "in-progress"
}
]
}
]
},
{
"name" : "authored",
"source" : [
{
"context" : "src"
}
],
"target" : [
{
"context" : "qr",
"contextType" : "variable",
"element" : "authored",
"transform" : "evaluate",
"parameter" : [
{
"valueString" : "now()"
}
]
}
]
},
{
"name" : "subject",
"source" : [
{
"context" : "src",
"element" : "entry",
"listMode" : "first",
"variable" : "patient"
}
],
"target" : [
{
"context" : "qr",
"contextType" : "variable",
"element" : "subject",
"variable" : "subject"
},
{
"context" : "subject",
"contextType" : "variable",
"element" : "reference",
"transform" : "evaluate",
"parameter" : [
{
"valueString" : "%patient.resource.entry.fullUrl.toString()"
}
]
}
]
},
{
"name" : "grp",
"source" : [
{
"context" : "src"
}
],
"target" : [
{
"context" : "qr",
"contextType" : "variable",
"element" : "item",
"variable" : "grp"
},
{
"context" : "grp",
"contextType" : "variable",
"element" : "linkId",
"transform" : "copy",
"parameter" : [
{
"valueString" : "grp"
}
]
}
],
"rule" : [
{
"name" : "partDetails",
"source" : [
{
"context" : "src"
}
],
"target" : [
{
"context" : "grp",
"contextType" : "variable",
"element" : "item",
"variable" : "partDetails"
},
{
"context" : "partDetails",
"contextType" : "variable",
"element" : "linkId",
"transform" : "copy",
"parameter" : [
{
"valueString" : "part-details"
}
]
}
],
"rule" : [
{
"name" : "patientDetails",
"source" : [
{
"context" : "src",
"element" : "entry",
"listMode" : "first",
"variable" : "patient"
}
],
"rule" : [
{
"name" : "partBundleDetails",
"source" : [
{
"context" : "patient",
"type" : "Bundle",
"element" : "resource",
"variable" : "patientRes"
}
],
"target" : [
{
"contextType" : "variable",
"transform" : "copy",
"parameter" : [
{
"valueId" : "partDetails"
}
]
}
],
"dependent" : [
{
"name" : "populatePatientGroup",
"variable" : [
"patientRes",
"partDetails"
]
}
]
}
]
},
{
"name" : "conditionCount",
"source" : [
{
"context" : "src",
"element" : "entry",
"variable" : "conditions",
"condition" : "(resource.link.url.contains('/Condition?'))"
}
],
"target" : [
{
"context" : "partDetails",
"contextType" : "variable",
"element" : "item",
"variable" : "conditionItem"
},
{
"context" : "conditionItem",
"contextType" : "variable",
"element" : "linkId",
"transform" : "copy",
"parameter" : [
{
"valueString" : "condition-count"
}
]
}
],
"rule" : [
{
"name" : "conditionCountAnswer",
"source" : [
{
"context" : "conditions"
}
],
"target" : [
{
"context" : "conditionItem",
"contextType" : "variable",
"element" : "answer",
"variable" : "conditionCountAnswer"
},
{
"context" : "conditionCountAnswer",
"contextType" : "variable",
"element" : "value",
"transform" : "evaluate",
"parameter" : [
{
"valueString" : "%conditions.resource.entry.count()"
}
]
}
]
}
]
}
]
},
{
"name" : "meds",
"source" : [
{
"context" : "src",
"element" : "entry",
"variable" : "medications",
"condition" : "(resource.link.url.contains('/MedicationStatement?'))"
}
],
"target" : [
{
"contextType" : "variable",
"transform" : "copy",
"parameter" : [
{
"valueId" : "grp"
}
]
}
],
"rule" : [
{
"name" : "medEntry",
"source" : [
{
"context" : "medications",
"type" : "Bundle",
"element" : "resource",
"variable" : "medRes"
}
],
"dependent" : [
{
"name" : "populateMedicationsGroup",
"variable" : [
"medRes",
"grp"
]
}
]
}
]
}
]
}
]
},
{
"name" : "populatePatientGroup",
"typeMode" : "none",
"input" : [
{
"name" : "patientRes",
"type" : "Bundle",
"mode" : "source"
},
{
"name" : "partDetails",
"mode" : "target"
}
],
"rule" : [
{
"name" : "participantIdValue",
"source" : [
{
"context" : "patientRes"
}
],
"target" : [
{
"context" : "partDetails",
"contextType" : "variable",
"element" : "item",
"variable" : "participantId"
},
{
"context" : "participantId",
"contextType" : "variable",
"element" : "linkId",
"transform" : "copy",
"parameter" : [
{
"valueString" : "participant-id"
}
]
},
{
"context" : "participantId",
"contextType" : "variable",
"element" : "answer",
"variable" : "participantIdAnswer"
},
{
"context" : "participantIdAnswer",
"contextType" : "variable",
"element" : "value",
"transform" : "evaluate",
"parameter" : [
{
"valueString" : "%patientRes.entry.resource.id.toString()"
}
]
}
]
},
{
"name" : "familyNameValue",
"source" : [
{
"context" : "patientRes"
}
],
"target" : [
{
"context" : "partDetails",
"contextType" : "variable",
"element" : "item",
"variable" : "familyName"
},
{
"context" : "familyName",
"contextType" : "variable",
"element" : "linkId",
"transform" : "copy",
"parameter" : [
{
"valueString" : "family-name"
}
]
},
{
"context" : "familyName",
"contextType" : "variable",
"element" : "answer",
"variable" : "familyNameAnswer"
},
{
"context" : "familyNameAnswer",
"contextType" : "variable",
"element" : "value",
"transform" : "evaluate",
"parameter" : [
{
"valueString" : "%patientRes.entry.resource.name.first().family"
}
]
}
]
},
{
"name" : "givenNameValue",
"source" : [
{
"context" : "patientRes"
}
],
"target" : [
{
"context" : "partDetails",
"contextType" : "variable",
"element" : "item",
"variable" : "givenName"
},
{
"context" : "givenName",
"contextType" : "variable",
"element" : "linkId",
"transform" : "copy",
"parameter" : [
{
"valueString" : "given-names"
}
]
},
{
"context" : "givenName",
"contextType" : "variable",
"element" : "answer",
"variable" : "givenNameAnswer"
},
{
"context" : "givenNameAnswer",
"contextType" : "variable",
"element" : "value",
"transform" : "evaluate",
"parameter" : [
{
"valueString" : "%patientRes.entry.resource.name.first().given.join(', ')"
}
]
}
]
},
{
"name" : "dobValue",
"source" : [
{
"context" : "patientRes"
}
],
"target" : [
{
"context" : "partDetails",
"contextType" : "variable",
"element" : "item",
"variable" : "dob"
},
{
"context" : "dob",
"contextType" : "variable",
"element" : "linkId",
"transform" : "copy",
"parameter" : [
{
"valueString" : "dob"
}
]
},
{
"context" : "dob",
"contextType" : "variable",
"element" : "answer",
"variable" : "dobAnswer"
},
{
"context" : "dobAnswer",
"contextType" : "variable",
"element" : "value",
"transform" : "evaluate",
"parameter" : [
{
"valueString" : "%patientRes.entry.resource.birthDate"
}
]
}
]
}
]
},
{
"name" : "populateMedicationsGroup",
"typeMode" : "none",
"input" : [
{
"name" : "medRes",
"type" : "Bundle",
"mode" : "source"
},
{
"name" : "grp",
"mode" : "target"
}
],
"rule" : [
{
"name" : "medItem",
"source" : [
{
"context" : "medRes",
"element" : "entry",
"variable" : "med",
"condition" : "(resource is MedicationStatement)"
}
],
"target" : [
{
"context" : "grp",
"contextType" : "variable",
"element" : "item",
"variable" : "medsItem"
},
{
"context" : "medsItem",
"contextType" : "variable",
"element" : "linkId",
"transform" : "copy",
"parameter" : [
{
"valueString" : "meds"
}
]
}
],
"rule" : [
{
"name" : "medsNameAnswer",
"source" : [
{
"context" : "med",
"type" : "MedicationStatement",
"element" : "resource",
"variable" : "medResource"
}
],
"target" : [
{
"context" : "medsItem",
"contextType" : "variable",
"element" : "item",
"variable" : "medsName"
},
{
"context" : "medsName",
"contextType" : "variable",
"element" : "linkId",
"transform" : "copy",
"parameter" : [
{
"valueString" : "med-name"
}
]
},
{
"context" : "medsName",
"contextType" : "variable",
"element" : "answer",
"variable" : "medsNameAnswer"
},
{
"context" : "medsNameAnswer",
"contextType" : "variable",
"element" : "value",
"transform" : "evaluate",
"parameter" : [
{
"valueString" : "%medResource.medication.select(iif(text.exists(), text, coding.display.first()))"
}
]
}
]
},
{
"name" : "medsStatus",
"source" : [
{
"context" : "med",
"type" : "MedicationStatement",
"element" : "resource",
"variable" : "medResource"
}
],
"target" : [
{
"context" : "medsItem",
"contextType" : "variable",
"element" : "item",
"variable" : "medsStatus"
},
{
"context" : "medsStatus",
"contextType" : "variable",
"element" : "linkId",
"transform" : "copy",
"parameter" : [
{
"valueString" : "med-status"
}
]
}
],
"rule" : [
{
"name" : "medsStatusAnswer",
"source" : [
{
"context" : "medResource",
"element" : "status",
"variable" : "medsMedicationStatus"
}
],
"target" : [
{
"context" : "medsStatus",
"contextType" : "variable",
"element" : "answer",
"variable" : "medsStatusAnswer"
},
{
"context" : "medsStatusAnswer",
"contextType" : "variable",
"element" : "value",
"transform" : "c",
"parameter" : [
{
"valueString" : "http://hl7.org/fhir/CodeSystem/medication-status"
},
{
"valueId" : "medsMedicationStatus"
}
]
}
]
}
]
},
{
"name" : "medsCategory",
"source" : [
{
"context" : "med",
"element" : "resource",
"variable" : "medResource",
"condition" : "(category.coding.where(system = 'http://terminology.hl7.org/CodeSystem/medicationrequest-category').exists())"
}
],
"target" : [
{
"context" : "medsItem",
"contextType" : "variable",
"element" : "item",
"variable" : "medsCategory"
},
{
"context" : "medsCategory",
"contextType" : "variable",
"element" : "linkId",
"transform" : "copy",
"parameter" : [
{
"valueString" : "meds-category"
}
]
}
],
"rule" : [
{
"name" : "medsCategoryAnswer",
"source" : [
{
"context" : "medResource"
}
],
"target" : [
{
"context" : "medsCategory",
"contextType" : "variable",
"element" : "answer",
"variable" : "medsCategoryAnswer"
},
{
"context" : "medsCategoryAnswer",
"contextType" : "variable",
"element" : "value",
"transform" : "evaluate",
"parameter" : [
{
"valueString" : "%medResource.category.coding.where(system = 'http://terminology.hl7.org/CodeSystem/medicationrequest-category').code.join(' ')"
}
]
}
]
}
]
}
]
}
]
}
]
}