Digital questionnaires are widely used in healthcare to collect structured data. They control what is asked and keep answers consistent.
The problem begins after submission. A QuestionnaireResponse stores answers in a nested, form-specific structure. While ideal for capture, this structure is not optimized for querying, interoperability, or analytics.
Data extraction solves this problem. It enables several critical capabilities: interoperability between different healthcare systems, data analytics, and real-time data integration. Data from multiple sources can be consolidated without getting stuck in a single system or in QR code formats that limit processing.
FHIR recommends using Questionnaires to capture raw data, then converting the QuestionnaireResponse into standard FHIR resources such as Observations or MedicationStatements. Once transformed, the data can be searched, shared, and used across systems.
FHIR Questionnaires excel at structured data capture. However, the final QuestionnaireResponse instances that are hard to search, compare, or integrate with other FHIR resources. The core challenge is converting these responses into standard FHIR resources (e.g., Observations, Patient, Condition) for seamless use in documents, messages, or REST APIs.
The SDC guide provides four extraction mechanisms, each tailored to specific use cases in complexity, control, and scalability. In this article, we will only talk about three of them and omit StructureMap-based extraction. You can read more about it here.
Best for: Simple clinical assessments or surveys mapping directly to individual Observations.
Best for: Structured forms designed to mirror FHIR profiles or core resources.
Best for: Forms producing multiple linked resources
Template-based extraction is the newest mechanism added to the SDC specification (after Observation-based, Definition-based, and StructureMap-based). It uses contained FHIR resource or Bundle templates annotated with FHIRPath expressions.
It was introduced specifically to overcome the complexity and governance challenges that implementers frequently encountered with the earlier methods, and it is quickly becoming the preferred choice in many projects.
Template-based extraction is one of the four mechanisms in the FHIR SDC specification for transforming a completed QuestionnaireResponse into one or more FHIR resources or a full transaction Bundle.
It provides a balanced approach:
Teams choose it when they need clear control over the output and need moderate logic such as repeating groups, conditionals, fixed values, profiles, without learning the FHIR mapping language.
You embed ready-made template resources (or a template Bundle) directly inside the Questionnaire as contained resources. These templates already contain the required boilerplate — meta profiles, fixed codes, extensions, narrative, etc.
You then annotate parts of these templates with small FHIRPath expressions that define how data is populated:
When the $extract operation runs, the engine copies the templates, evaluates the expressions against the QuestionnaireResponse, repeats or removes elements as instructed, and returns a ready-to-submit transaction Bundle.

In Aidbox Form Builder, the process is visual: you simply draw your form, then drop ready-made resource templates into the exact groups where the data lives. Aidbox automatically repeats the templates, resolves references, applies profiles, and returns a perfect transaction Bundle.
Let’s build a complete allergy intake form that extracts:
Aidbox Form Builder → New Questionnaire → Title: “Allergy History”
Exact form outline (what clinicians see):

Add a Patient resource template as a contained resource.
Map form fields to Patient elements using FHIRPath expressions.
Add an AllergyIntolerance resource template inside the repeating Allergies group so that one resource is created per recorded allergy.
You can also populate fields in template with static values, for example by selecting an option from ValueSet when it remains constant across resources.
Everything is automatically linked, profiled, and ready to POST.
Template-based extraction provides a practical balance between flexibility, readability, and maintainability within the FHIR SDC specification. It is especially useful when full StructureMap expertise is not available or when authors need direct control over the structure of the resulting FHIR resources.
By embedding resource or Bundle templates directly within the Questionnaire (as contained resources) and annotating them with simple FHIRPath-driven templateExtractContext and templateExtractValue extensions, authors can precisely define:
This method provides visual clarity and immediate testability while still supporting complex transformations, including multiple resources, cross-resource references via allocateId, conditional sections, and full transaction Bundles. Because the output structure is explicitly defined in the template, implementers can validate the expected results at design time, dramatically reducing runtime errors compared with the more procedural alternatives.
For teams that want robust, reusable, profile-conformant resource creation from forms but want to avoid the learning curve of StructureMap or the rigidity of purely definition-based mapping, template-based extraction stands out as the most approachable high-capability option in the SDC toolbox.
Get in touch with us today!
