How to create a form with dynamical answers into questions
Aidbox forms supports fetching answers into question with conditions and logic
What is answer expression
Aidbox Forms allows to create form which dynamically fetch answers into questions. An expression with FHIRPath or FHIR Query that resolves to a list of permitted answers for the question item or that establishes context for a group item. The user may select from among the list to choose answers for the question.
Example Use Case
Form have two questions. User wants filtrate possible answers into second question depends on answer from first question.
For example first question named Gender
have two options: Male
and Female
. Depends on answer from Gender
, second question named Patient
will have two possible lists of answer options with patients who have gender equals to Male
or Female
.
How to build form
In this guide we will create form with usage of FHIRPath expression and FHIR Query expression.
1. Form setup
Let's create a form which first group will have questions with FHIRPath expression and second group with FHIR Query expression.
Create in builder group called Diet
and two items into, so your form in item tree should look like this:
Diet [group]
- Type [string]
- Food [string]
Then create another group called Patients
and two items into, final item tree should like this:
Diet [group]
- Type [choice]
- Food [choice]
Patients [group]
- Gender [choice]
- Patient [reference]
2. Setting widgets
Let's setup first group with FHIRPath expression:
Select
Type
widget in outlineChoose
Static
options and create two options:code:
meat
, display:Meat
;code:
vegetables
, display:Vegetables
.
Select
Food
widget in outlineChoose
Expression
options and select LanguageFHIRPath
Write down expression:
We define variable called
value
, which will be used as source of code fromType
answerAnd create function
iif
which will define answer options matchingType
answerThen we use
combine
function to unite ouriif
conditions
defineVariable('value', %resource.repeat(item).where(linkId = 'type-choice').answer.valueCoding.code).
select(iif(%value.exists($this = 'meat'), 'Beef' | 'Lamb').
combine(iif(%value.exists($this = 'vegetable'), 'Carrot' | 'Potato')))
Now let's setup second group with FHIR Query expression:
Select
Gender
widget in outlineChoose
Static
options and create two options:code:
male
, display:Male
;code:
female
, display:Female
.
Select
Patient
widget in outlineChoose
Expression
options and select LanguageFHIRQuery
Write down expression:
We define query to our resource
Patient
and parametergender
And links question from where code will be queried
Patient?gender={{ %resource.repeat(item).where(linkId = 'gender-choice').answer.valueCoding.code }}
Usage
Now let's try to answer on questions:
Diet questions:
If user choose into Type question
Meat
answer. Into Food question will be available onlyBeef
andLamb
answer.If user choose
Vegetables
answer into Type question — into Food question will be available onlyCarrot
andPotato
answers.
Patients questions:
If user choose into Gender question
Male
answer. Into Patient reference question will be available list of patients only withMale
gender.If user choose
Female
answer into Gender question — into Patient question will be available list of patients only withFemale
gender.
Last updated
Was this helpful?