FHIR Questionnaire React Renderer With AI Prefill: The LLM Only Suggests

Smart Forms vs Formbox for FHIR Questionnaires in React, and AI prefill done right: SDC $populate first, LLM suggests only empty fields, no accept-all.

Clint JohnsonPublished 10 min read

Key takeaways

  • Use Smart Forms if you want a maintained $populate package next to the renderer, or Formbox if you need headless theming and will own population yourself.
  • Fill in a fixed order: SDC $populate first, LLM suggestions only for still-empty items, and blank where neither can answer.
  • A suggestion is not an answer until a clinician confirms it, and code checks enableWhen, scores, value sets and the launch patient before submit.

An LLM should never be the first thing that writes into a FHIR Questionnaire. Keep the model out of $populate. The chart fills what it can. The model suggests answers only for fields that are still empty. Everything else stays blank.

That starts with picking a renderer. Use CSIRO Smart Forms if you want a maintained $populate implementation sitting next to the renderer. Use Formbox if you want a headless renderer themed to your design system (antd, Mantine or NHS) and you're willing to own population yourself. Don't write your own renderer.

The order never changes:

  • Deterministic SDC $populate runs first.
  • The model suggests, with cited evidence, only for empty items.
  • Blank means nothing could answer.

Every item records whether its answer came from the chart, the model or a human. A clinician confirms scored items one at a time. There is no accept-all.

Here's an example five-item intake form when it opens:

ItemWho answersState when the form opens
Date of birth$populate from Patient.birthDatechart
Weight$populate from an Observation inside observationLinkPeriodchart
Tobacco useModel, citing a progress notesuggested, not an answer yet
Fall in the last 12 monthsModel found no evidence, so it says nothingblank
Pain today (0-10)Only the patient, todayblank

Two chart answers, one suggestion, two blanks. That's a good form. The blanks are doing their job.

Smart Forms or Formbox: which React renderer to use

Both are open source and actively maintained. They differ in where population lives and how much of the UI you own.

Smart FormsFormbox
Package@aehrc/smart-forms-renderer@formbox/renderer (formerly Aidbox Forms)
What it isReact engine, reference implementation of the SDC Form FillerHeadless, typed React renderer
PopulationNot in the renderer. @aehrc/sdc-populate does it, in your app or as a serviceREADME shows initialResponse seeding. $populate not confirmed
FHIR versionsNot confirmedR4 and R5, via a fhirVersion prop
StylingDefault UI, with sdcUiOverrideComponentsYou must pass a theme and its CSS: hs-theme, nshuk-theme, antd-theme, mantine-theme
Per-item renderingqItemOverrideComponentsNot confirmed
StateParent app owns FHIR client, patient, user and encounterMobX (mobx, mobx-react-lite are peer deps)
Other SDC operationsSeparate $assemble and $extract packagesNot confirmed
LicenseApache 2.0Check the repo

The detail that matters most is in the Smart Forms renderer API docs: the renderer does no pre-population. populateQuestionnaire from @aehrc/sdc-populate runs in your client with a callback that fetches resources, instead of calling a remote $populate service (populate docs). A Docker image (aehrc/smart-forms-populate) exists if you want it as a service, and ?debug=true helps when a field won't fill.

You pass the result to buildForm() as the starting QuestionnaireResponse. qItemOverrideComponents is where the suggestion UI goes. Set the terminology server explicitly. If you don't, buildForm() falls back to a public Ontoserver.

Formbox (repo) wins when the form has to look like the rest of your app. Health Samurai pitches it on pluggable themes, predictable state and Storybook-ready previews. Its README shows seeding through initialResponse, not $populate. Verify population support before you plan around it.

With either one, own population in the app and hand the renderer a finished starting response. Population, suggestions and the submit gate become plain functions you can test without a browser. Swapping renderers later stays cheap.

Chart first: what $populate owns

SDC $populate takes a Questionnaire and returns a QuestionnaireResponse with the answers it could find. It works from data passed in with the operation or data the server already has about the subject (SDC $populate). It maps chart data. It doesn't generate answers. That's what you want for birth date, latest weight or a computed BMI.

The spec is strict about when a mapping is safe (SDC population):

  • The question has to mean the same thing as the mapped element.
  • Its value set has to fall inside the element's value set.
  • Data types have to match or be convertible.
  • Observation-based population only searches inside the observationLinkPeriod window. A weight older than the window never shows up as today's weight.
  • An invalid embedded query gets logged and treated as no data.

Every one of those rules ends in an empty field, not a guess. I like that. A plausible wrong answer in a field nobody looks at twice is how bad data gets into the chart.

The model second, and outside $populate

SDC says the same element "should only be populated in one way." It calls behavior undefined when two population mechanisms target one item. It says nothing about suggestion layers outside SDC. Apply the rule anyway: the model only sees items that are still empty after $populate returns. Then no answer ever has two writers.

SDC also shows where the model belongs. It defines three population modes. Automated population is the only one $populate can perform. Choice selection (here are candidates, pick one) and answer context (here are the Observations and Conditions, you decide) are interactive only. An LLM suggestion with evidence attached is a cousin of those two. It's UI work, so keep it in the UI.

One discriminated union per item

The QuestionnaireResponse doesn't tell you how a value got there. Track that per item as a discriminated union, for the reasons in Stop Using Optional Props:

type Evidence = [string, ...string[]]; // at least one cited resource

type ItemState =
  | { kind: "blank" }
  | { kind: "chart"; value: Answer; sources: string[] }                   // from $populate
  | { kind: "suggested"; value: Answer; evidence: Evidence; run: string } // LLM, not an answer yet
  | { kind: "confirmed"; value: Answer; origin: "chart" | "model" | "human"; reviewer: string };

The non-empty tuple makes a suggestion with no evidence a compile error. An empty reviewer string still type-checks, so check it at runtime.

The rule: suggested never gets serialized into the QuestionnaireResponse. A suggestion becomes an answer only when a person moves it to confirmed. If the page reloads, unconfirmed suggestions are gone. They don't quietly turn into data.

When a clinician edits a chart-filled value, it becomes confirmed with origin human. That transition is your edit-rate signal.

Evidence on click, and no accept-all on scores

SDC says answer-context information SHOULD appear on user action, like a button that opens a dialog, "rather than being presented by default." Follow it. Show the suggested value in a distinct, unconfirmed style, with a "Why?" control that opens the cited chart entries. Inline evidence on every row becomes text people learn to skim.

Don't ship accept-all on a PHQ-9 or any form where items add up to a score. Every scored item gets its own confirm. Accept-all turns review into one click, and review is the step the spec protects. SDC says the point of $populate is "merely to reduce redundant data entry," that clients SHOULD let a human review auto-populated answers, and that mapping "can lead to the sharing of incorrect data," with more risk on complex questionnaires. A bulk confirm on chart-filled demographics is defensible. On a score, it isn't.

Re-population runs only when the user asks, and it never overwrites what the user changed. Smart Forms exposes repopulateResponse(). Put a diff view in front of it that shows new values next to old ones.

Build the model's context with the clinician's access, not a service account's. SDC says users SHALL NOT see populated data they couldn't see in the source system, and that applies to what you feed the model. SMART Backend Services for AI Agents covers why. Sending chart data to whatever does population also discloses PHI to it. Your LLM vendor needs to be trusted and under the right agreements.

Recording where each answer came from

This is where the standards run out.

Core FHIR has an item-level questionnaireresponse-author extension that can reference a Device (R4B). It records who answered, not how.

Da Vinci DTR has an information-origin extension on each answer, with codes auto-client | auto-server | override | manual (DTR). None means "a model suggested it and a human accepted it." override and manual require an author, so an accepted suggestion gets coded as human work and the model's part vanishes. DTR is also a US Da Vinci IG, not core SDC. You'll meet it in CMS-0057-F prior auth work.

So use a custom extension, label it non-standard and keep it narrow. Here's the intake form after the clinician confirms, trimmed to two items:

{
  "resourceType": "QuestionnaireResponse",
  "status": "completed",
  "subject": { "reference": "Patient/123" },
  "item": [
    { "linkId": "weight", "answer": [{
      "valueQuantity": { "value": 82, "unit": "kg" },
      "extension": [{ "url": "https://example.org/fhir/StructureDefinition/answer-origin",
        "extension": [{ "url": "origin", "valueCode": "chart" }] }] }] },
    { "linkId": "tobacco", "answer": [{
      "valueCoding": { "system": "https://example.org/tobacco", "code": "former" },
      "extension": [{ "url": "https://example.org/fhir/StructureDefinition/answer-origin",
        "extension": [
          { "url": "origin", "valueCode": "model" },
          { "url": "run", "valueString": "suggest-run-8f2c" },
          { "url": "confirmedBy", "valueReference": { "reference": "Practitioner/456" } }
        ] }] }] }
  ]
}

The pain and fall items are absent until someone answers them.

Then write one Provenance for the response, the way SDC describes it. target is the QuestionnaireResponse. entity.what with role = source lists the Patient, the weight Observation and the progress note the suggestion cited. agent is the software that populated the form. Add the suggester as a second Device agent.

SDC's Provenance guidance covers the whole response, not each item. That's why the per-item detail lives in the extension. When a standard code for model-originated answers shows up, migrating is one mapping function.

The submit gate runs in code

The model never decides whether a form is valid. Plain functions do. The two that people get wrong are enableWhen and the patient check:

type EnableWhen = { question: string; operator: string; answerBoolean?: boolean; [k: string]: unknown };

// expected answer[x]; codings compare by code
const expected = (ew: EnableWhen) => {
  const [k, v] = Object.entries(ew).find(([key]) => key.startsWith("answer")) ?? [];
  return k === "answerCoding" ? (v as { code: string }).code : v;
};

// answers: linkId -> values, codings reduced to their code
function isEnabled(enableWhen: EnableWhen[] | undefined, behavior: "all" | "any" | undefined,
                   answers: Map<string, unknown[]>): boolean {
  if (!enableWhen?.length) return true;
  const hits = enableWhen.map(ew => {
    const got = answers.get(ew.question) ?? [];
    if (ew.operator === "exists") return (got.length > 0) === ew.answerBoolean;
    if (ew.operator === "=") return got.includes(expected(ew));
    throw new Error(`enableWhen operator ${ew.operator} not handled`); // fail closed
  });
  return behavior === "any" ? hits.some(Boolean) : hits.every(Boolean);
}

function sameLaunchPatient(ref: string | undefined, fhirBase: string, id: string) {
  const base = fhirBase.replace(/\/$/, "");
  return ref === `Patient/${id}` || ref === `${base}/Patient/${id}`;
}

Prune by enableWhen every time. The $populate spec lets a server fill every answer it knows, regardless of conditional logic, and expects the client to prune after review. Servers differ. Walk the Questionnaire tree with isEnabled, treat children of a disabled item as disabled, and reject any answer on a disabled item. Unknown operators throw and block submit until you handle them. The first test to write: smoke-detail is enabled only when smokes = true, $populate answers both, the clinician flips smokes to false, and submit must fail.

Check the subject. This catches the worst failure in the flow: a response filed on the wrong patient. Accept Patient/123 or the absolute URL on the launch server's FHIR base. A contained or identifier-only reference fails. So does the same id on another server, because that's a different patient.

Block unreviewed suggestions. Any item still in suggested blocks submit.

Recompute scores and check codes. Re-run every calculatedExpression from confirmed answers with a FHIRPath engine. Never trust a stored score. Check each coding against the item's expanded answer value set.

What to measure, with starting thresholds

These thresholds are starting points, not numbers from a live system. Tune them once you have data.

Suggestion acceptance rate per item. A blended rate hides the one question the model always gets wrong. Don't read an item's rate until it has about 30 suggestions. If it then sits below 50%, turn suggestions off for that item. Blank beats a bad guess. Near-100% worries me too. It can mean nobody is reading, so sample those confirmations by hand.

Edit rate on chart-filled fields, per field. If clinicians change more than about 5% of a chart-filled field, review the mapping: the observationLinkPeriod, the units, the value-set mapping. That's a pipeline bug, not a model problem. It's the same override signal as in Detecting Model Drift in Clinical AI.

Completion time per form. Compare the median before and after prefill. If it doesn't drop, you added review work without saving any typing.

Clinician corrections as eval cases. Every rejected or edited suggestion goes into the eval set with its evidence and the final answer. That's a labeled dataset without a labeling project, and it's step one of product evals in three steps.

Questions people ask

Which React renderer should I use for FHIR Questionnaires?

Use CSIRO Smart Forms if you want a maintained $populate package alongside the renderer. Use Formbox if you want a headless renderer themed with antd, Mantine or NHS styling and you're willing to own population yourself.

Does the Smart Forms React renderer do SDC pre-population?

No. The renderer does no pre-population. Population comes from the separate @aehrc/sdc-populate package, which can run in your client app, and you pass its result to buildForm() as the starting QuestionnaireResponse.

How do I mark that a QuestionnaireResponse answer came from an AI model?

No standard code exists. DTR's information-origin codes have no value for a model suggestion, and the core author extension records who answered, not how. Use a clearly labeled non-standard extension per answer, plus one Provenance for the whole response.

Should AI-prefilled clinical forms have an accept-all button?

Not for scored instruments like a PHQ-9. Accept-all turns review into one click, and SDC says clients should give a human the chance to review auto-populated answers, so each scored item gets its own confirmation.