Request Interception
A detailed guide on intercepting requests in Aidbox Form Builder and Renderer.
Aidbox Form Builder & Renderer Request Interception
Request interception allows you to modify network requests made by Aidbox Form Builder and Aidbox Form Renderer. This is useful for debugging, adding authentication, redirecting requests, or handling custom logic before requests are sent.
Enabling Request Interception
To enable request interception, set the onFetch
property on the builder or renderer element. This property should be a function that takes two arguments: the URL and the request options. The function should return a promise that resolves to the response.
The interception function must follow the same signature as the standard fetch function, with the following exceptions:
The function can return null or undefined to bypass the interception and allow the builder to handle the request using the standard fetch.
The init object (the second argument) may include an additional tag property. This tag is a string representing the name of one of the endpoints, allowing you to differentiate between them without relying on the URL or HTTP method, which may be subject to future changes.
Common Use Cases
These examples demonstrate how to use request interception in various scenarios. Most of the examples are also applicable to the Renderer component.
1. Logging Requests
To inspect outgoing requests and responses:
2. Adding Authorization Headers
To include an authorization token in requests:
3. Redirecting Requests
To change the endpoint of requests dynamically:
4. Handling Custom Questionnaire Storage
To store and retrieve forms from local storage:
5. Modifying Extracted Data
To manipulate extraction results before they are processed:
Request Tags
Request tags are used to differentiate between different types of requests. They are passed as a property in the init
object and can be used to identify the request type in the interception function.
The following tags are available:
During component initialization (if config is referenced)
Loads SDCConfig for themes, localization, etc.
During initialization if config references a theme
Fetches the theme used by builder.
On initialization or after saving a theme
Loads available themes for theme selector.
During builder startup
Fetches CapabilityStatement for autocomplete.
During builder startup
Loads JSON schemas for FHIR resources.
When initializing the form for editing
Loads questionnaire by ID.
After loading questionnaire with sub-questionnaire references
Fetches a fully assembled version.
When opening a sub-questionnaire reference
Loads a sub-questionnaire by canonical URL.
When searching for sub-questionnaires
Lists sub-questionnaires by extension/title.
Before saving a questionnaire
Checks if canonical URL is already in use.
When saving a new questionnaire
Creates a new Questionnaire resource.
When updating an existing questionnaire
Saves changes to the questionnaire.
When saving an outline item as sub-questionnaire
Creates a canonical sub-questionnaire.
When clicking the "Import" button
Imports a new questionnaire JSON.
When clicking "Populate" in debug panel
Prefills fields using subject/context.
When clicking "Extract" in debug panel
Extracts resources from the questionnaire response.
When clicking "Validate Questionnaire" in debug panel
Validates questionnaire resource.
When clicking "Validate Response" in debug panel
Validates questionnaire response resource
When saving a new theme
Creates a new QuestionnaireTheme.
When saving changes to an existing theme
Updates the theme resource.
delete-attachment
Triggered in renderer when the attachment input field is cleared.
Request
Where <filepath>
is the path of the attachment being deleted.
Response
Response shape is specific to the storage type and is not processed by the frontend.
extract
Triggered when the "Extract" button in the builder debug panel is clicked.
Request
Where <questionnaire-response>
is the questionnaire response being extracted and <questionnaire>
is the questionnaire it is based on.
Response
Where <bundle>
is the bundle of resources extracted from the questionnaire response.
get-assembled-questionnaire
Triggered after retrieving the current questionnaire to obtain its fully assembled version, if it includes sub-questionnaires.
Request
Where <questionnaire-url>
represents the canonical URL, and <questionnaire-version>
specifies the version of the assembled questionnaire being requested.
Response
Where <bundle>
is the bundle containing zero or one questionnaire resource.
get-config
Triggered during the initialization of the builder or renderer to fetch configuration details.
Request
Where <config-id>
refers to the ID of the SDCConfig resource included in the JWT token payload of the current authentication session. This parameter is omitted if no configuration is specified.
Response
Where <config>
is the SDCConfig resource containing the configuration details.
get-questionnaire
Triggered during the initialization of the builder or renderer to fetch the current questionnaire.
Request
Where <questionnaire-id>
is the ID of the questionnaire being requested.
Response
Where <questionnaire>
is the questionnaire being requested.
get-response
Triggered during the initialization of the renderer to fetch the current user response.
Request
Where <questionnaire-response-id>
is the ID of the questionnaire response being requested.
Response
Where <questionnaire-response>
is the questionnaire response being requested.
get-fhir-metadata
Triggered during the initialization of the builder to fetch metadata for FHIR resources, which aids in autocompletion.
Request
Response
Where <fhir-metadata>
is the metadata for the FHIR server.
get-fhir-schemas
Triggered during the initialization of the builder to fetch schemas for FHIR resource elements, aiding in autocompletion.
Request
Response
Where <fhir-schemas>
is the JSON object containing the schemas for the FHIR resource elements.
get-theme
Triggered during the initialization of the web component if a theme is referenced in the configuration.
Request
Where <theme-id>
is the ID of the theme being requested.
Response
Where <theme>
is the theme being requested.
get-themes
Triggered during the initialization of the builder web component and after saving a theme to list available themes in the theme selector.
Request
Response
Where <bundle>
is the bundle of themes.
import-questionnaire
Triggered when the "Import" button is clicked in the questionnaire importer.
Request
Where <questionnaire>
is the questionnaire being imported.
Response
Where <questionnaire>
is the questionnaire that was imported.
populate
Triggered when the "Populate" button is clicked in the builder debug panel.
Request
Where <questionnaire>
is the questionnaire being populated, <patient-id>
is the ID of the patient, and <encounter-id>
is the ID of the encounter selected in the builder debug panel.
Response
Where <parameters>
is a parameters resource containing the populated questionnaire response under the response
name.
save-response
Triggered by the auto-save mechanism shortly after the user makes changes in the form.
Request
Where <response>
is the response being submitted.
Status Value
Since auto-save is only enabled for non-completed forms, the response
parameter always has the status in-progress
.
Response
Where <parameters>
is a parameters that includes:
response
: the saved questionnaire response.issues
: any validation or processing issues, if available.
submit-response
Triggered when the user submits a response by clicking the submit button. The submit button is displayed when the questionnaire response is either in progress (in-progress
) or when the user is amending a completed response.
Request
Where <response>
is the response being submitted.
Status Value
The response
parameter contains the current status, and the Aidbox backend is responsible for transitioning it to the appropriate new state. Therefore, if you need to, for example, intercept an amending submission, you should check for the condition response.status = 'completed'
.
Response
Where <parameters>
is a parameters that includes:
response
: the processed questionnaire response.issues
: any validation or processing issues, if available.outcome
: a list of extracted resources when the questionnaire has extraction rules.
repopulate
Triggered when the "Repopulate" button is clicked by the user.
Request
Where <questionnaire>
, <questionnaire-response>
, <patient-id>
, and <encounter-id>
are as described in the populate request.
Response
Where <parameters>
is a parameters resource containing the repopulated questionnaire response under the response
name.
create-questionnaire
Triggered when the "Save" button is clicked in the builder for a new questionnaire.
Request
Where <questionnaire>
is the new questionnaire being created.
Response
Where <questionnaire>
is the questionnaire that was created.
save-questionnaire
Triggered when the "Save" button is clicked in the builder.
Request
Where <questionnaire>
is the questionnaire being saved.
Response
Where <questionnaire>
is the questionnaire that was saved.
create-sub-questionnaire
Triggered when an outline item is saved as a sub-questionnaire.
Request
Where <sub-questionnaire-url>
is the canonical URL of the sub-questionnaire and <sub-questionnaire>
is the sub-questionnaire being saved.
Response
Where <sub-questionnaire>
is the questionnaire that was created.
create-theme
Triggered when the "Save" button is clicked in the theme editor for a new theme.
Request
Where <theme>
is the new theme being created.
Response
Where <theme>
is the theme being created.
save-theme
Triggered when the "Save" button is clicked in the theme editor.
Request
Where <theme>
is the theme being saved.
Response
Where <theme>
is the theme being saved.
search-choice-options
Triggered in renderer by dynamic dropdowns (choice items with external value sets or resource lookups) when the user clicks on the dropdown to fetch the options.
Request
Where <url>
is the URL of the value set or resources associated with the choice item.
Response
Response be a plain list or bundle of resources (e.g. ValueSet) depending on the source of the options.
search-questionnaires-by-url
Triggered before saving the current questionnaire to check for conflicts with existing questionnaires based on their URL.
Request
Where <questionnaire-url>
is the canonical URL of the questionnaire being checked.
Response
Where <bundle>
is the bundle of questionnaires with the same URL.
search-sub-questionnaires
Triggered when the user searches for sub-questionnaires in the builder.
Request
Where <search-term>
is the term being searched for.
Response
Where <bundle>
is the bundle of sub-questionnaires.
get-sub-questionnaire
Triggered to retrieve a sub-questionnaire when it is referenced in a parent questionnaire.
Request
Where <sub-questionnaire-url>
is the canonical URL of the sub-questionnaire being requested. Parameter version
is omitted if no version is specified in the reference.
Response
Where <bundle>
is the bundle containing zero or one questionnaire resource.
upload-attachment
Triggered when a file is selected in the attachment input field.
Request
Where <file-content>
is the content of the file being uploaded and <file-name>
is the path and name of the file.
Response
Where <file-url>
is the URL of the uploaded file which will further be used to either download or delete the file.
validate-questionnaire
Triggered when the "Validate Questionnaire" button is clicked in the builder debug panel.
Request
Where <questionnaire>
is the questionnaire being validated.
Response
Where <operation-outcome>
is the operation outcome of the validation.
validate-response
Triggered when the "Validate Questionnaire Response" button is clicked in the builder debug panel.
Request
Where <questionnaire-response>
is the response being validated.
Response
Where <operation-outcome>
is the operation outcome of the validation.
Sequence Diagram
Builder
Renderer
Last updated
Was this helpful?