FHIR DrillDocs

Profiles & validation

Forms (SDC) with Smart Forms

The Structured Data Capture lifecycle in the lab: author a Questionnaire, pre-fill it from the EHR, calculate, extract resources, using CSIRO Smart Forms launched from OpenEMR.

Structured Data Capture (SDC) is the HL7 guide that turns FHIR Questionnaires from static forms into smart ones. They can pre-fill from the patient's record, calculate scores, show and hide questions, look up terminology, and turn the answers back into proper clinical resources.

The lifecycle#

Step SDC feature In the lab
Author Questionnaire + SDC extensions JSON files in ~/fhir-lab/smartforms/forms/, loaded into the forms library
Pre-fill launchContext + initialExpression (or $populate) Smart Forms reads the patient from OpenEMR over SMART
Behave variable, calculatedExpression, enableWhen, answerValueSet Evaluated live in the Smart Forms renderer
Capture QuestionnaireResponse Previewed in Smart Forms; stored natively by OpenEMR's assessment engine
Extract Template-based $extract (templateExtract + templateExtractValue) Smart Forms shows the resources it would create

The pieces#

Piece Where
Smart Forms (CSIRO, Apache-2.0, v1.5.0) https://emr.fhirdrill.dev/smartforms/ (SMART app registered in OpenEMR)
Forms library (Questionnaires) https://emr.fhirdrill.dev/forms/fhir, which is the lab HAPI served through the gateway
Terminology for answer lists CSIRO's public Ontoserver (r4.ontoserver.csiro.au), which includes SNOMED CT-AU
OpenEMR's own form engine Patient → Assessments → Questionnaires

The library starts with one form, FHIR Drill: Vitals check. The 53 CSIRO, Telstra and test sample forms that shipped with Smart Forms were removed on 2026-11-26. A backup bundle is on the lab box at ~/fhir-lab/smartforms/backups/questionnaires-2026-11-26.json, so any of them (for example the MBS 715 health check) can be put back with the loader below.

Fill a form#

Launch Smart Forms from a chart#

In OpenEMR, open a patient (for example Chester Aufderhar), expand SMART Enabled Apps and click Launch next to CSIRO Smart Forms. Approve the scopes. Smart Forms opens with the patient and the user (Practitioner) from OpenEMR.

Pick a form#

Search for Vitals, select FHIR Drill: Vitals check, then click Create response.

Watch SDC work#

Name and date of birth are already filled in from OpenEMR (initialExpression against %patient). Enter a weight and height, and BMI calculates as you type (calculatedExpression). Answer Yes to "Any concerns?" and a follow-up question appears (enableWhen).

See the extraction#

Click Save As Final & Write Back. The dialog lists the resources template extraction produced from your answers: Body weight, Body height and BMI Observations, built from the templates contained in the Questionnaire.

Saving back to OpenEMR is blocked, on purpose

OpenEMR 8.5 only grants create through user/*.cud scopes, and only to confidential clients (apps with a secret). A browser app can't keep a secret, so Smart Forms is registered read-only, and Save returns 401. For forms that need saving, use OpenEMR's own engine (Patient → Assessments → Start Assessment). The production answer is a small backend ("backend for frontend") that holds a confidential client and writes on the app's behalf. That's a good drill.

Write your own form#

Start from forms/fhirdrill-vitals-check.json. It shows the patterns you'll use most:

JSON
{ "url": "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-launchContext",
  "extension": [ { "url": "name", "valueCoding": { "system": "http://hl7.org/fhir/uv/sdc/CodeSystem/launchContext", "code": "patient" } },
                 { "url": "type", "valueCode": "Patient" } ] }
JSON
{ "url": "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-initialExpression",
  "valueExpression": { "language": "text/fhirpath", "expression": "%patient.birthDate" } }
JSON
{ "url": "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-calculatedExpression",
  "valueExpression": { "language": "text/fhirpath",
    "expression": "iif(%weight.exists() and %height.exists(), (%weight / ((%height / 100).power(2))).round(1), {})" } }

Extraction: put a template resource in contained, mark values with templateExtractValue FHIRPath, and point an item at it:

JSON
"valueQuantity": { "_value": { "extension": [ {
  "url": "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-templateExtractValue",
  "valueString": "$this.answer.value" } ] }, "unit": "kg", "system": "http://unitsofmeasure.org", "code": "kg" }
JSON
{ "url": "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-templateExtract",
  "extension": [ { "url": "template", "valueReference": { "reference": "#BodyWeightTemplate" } } ] }

Load or update a form in the library (the LAN address goes straight to HAPI):

Shell
curl -s -X PUT "http://192.168.1.181:8080/fhir/Questionnaire/my-form" \
  -H "Content-Type: application/fhir+json" --data-binary @my-form.json -o /dev/null -w "%{http_code}\n"

Or, on the lab box, use the loader. It checks that each file is a Questionnaire with an id, then PUTs it by that id, so re-running a file updates the form:

Shell
cd ~/fhir-lab/smartforms
./load-form.sh forms/my-form.json other-form.json
# remove one
curl -X DELETE http://localhost:8080/fhir/Questionnaire/my-form

Give every form "status": "active", a title and a stable url. Then reload Smart Forms. To test a form without any EHR, open the Smart Forms Playground (/smartforms/playground) and paste the JSON.

How the lab is wired (and what had to be fixed)#

Issue Fix
Smart Forms expects to sit at the root of its own site Built from source with base path /smartforms/ (~/fhir-lab/smartforms/fhirdrill-smartforms-v1.5.0.patch)
Its forms server is read without a token The gateway serves HAPI at emr.fhirdrill.dev/forms/fhir (same origin, X-Forwarded-Prefix: /forms/fhir)
It needs a Practitioner user; OpenEMR's admin was a Person Gave admin a test NPI (1234567893); OpenEMR treats users with an NPI as Practitioners
OpenEMR 8.5 returns 500 for QuestionnaireResponse?questionnaire=<canonical> Patched Smart Forms to filter the patient's responses by canonical in the browser when the server is OpenEMR
OpenEMR only allows patient/* reads for public clients Read-only registration; saving uses OpenEMR's own engine

Rebuild after changing the source: ~/fhir-lab/smartforms/build.sh.

FHIR Drill lab docs · synthetic data only · built 2026-11-26