Skip to main content

Providers, hooks, and submit utilities

Use the compound QuestionnaireForm for the standard form. The exports on this page are lower-level building blocks for an app that needs a custom renderer or navigation UI. They expose implementation state and should be used together with the documented questionnaire types.

Providers and hooks​

ExportPurpose
QuestionnaireFormProviderOwns Formik values, validation, and submit behavior for a questionnaire.
QuestionnaireNavigationProviderShares current page/item and navigation actions with navigation children.
useQuestionnaireFormReads form values, errors, submission state, and questionnaire navigation state.
useQuestionnaireNavigationReads the current navigation context.
useQuestionnaireNavigationStateDerives required, answered, final-item, and progress state from form and navigation inputs.
useNavigationHandlersBuilds the next/previous handlers used by the standard navigation UI.
useInitialSelectedValuesDerives initial form values from questionnaire items.

useQuestionnaireForm and useQuestionnaireNavigation throw when used outside the matching provider. QuestionnaireForm mounts the form provider for you; the standard navigation component manages the navigation provider. Prefer those higher-level components unless you are replacing their rendering behavior.

Submit utility​

QuestionnaireSubmitUtils.createQuestionnaireResponse(responses, pages, questionnaire) builds a FHIR QuestionnaireResponse with status: "completed", a reference to the questionnaire, response items, and an authored timestamp. It does not add subject, encounter, author, or provenance details. Add the context required by your workflow before persisting the resource.

The standard form can either call your onSubmit(values) handler or, when that handler is omitted, produce the FHIR response and report it through onSuccess. Choose one path deliberately and handle failures at the screen boundary.

Contexts and types​

The subpath also exports QuestionnaireFormContext, QuestionnaireNavigationContext, their context/provider types, QuestionnaireFormProps, QuestionnaireFormValues, ResponseValues, ExtendedQuestionnaireItem, and the FHIR QuestionnaireResponse type. Use the hooks in component code instead of reading contexts directly.