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: Maleand 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:
- 1.Select
Typewidget in outline - 2.Choose
Staticoptions and create two options:- 1.code:
meat, display:Meat; - 2.code:
vegetables, display:Vegetables.
- 3.Select
Foodwidget in outline - 4.Choose
Expressionoptions and select LanguageFHIRPath - 5.Write down expression:
- 1.We define variable called
value, which will be used as source of code fromTypeanswer - 2.And create function
iifwhich will define answer options matchingTypeanswer - 3.Then we use
combinefunction to unite ouriifconditions
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')))
Take note: Actual linkId may differ! You must select linkId equals to Type widget.
Now let's setup second group with FHIR Query expression:
- 1.Select
Genderwidget in outline - 2.Choose
Staticoptions and create two options:- 1.code:
male, display:Male; - 2.code:
female, display:Female.
- 3.Select
Patientwidget in outline - 4.Choose
Expressionoptions and select LanguageFHIRQuery - 5.Write down expression:
- 1.We define query to our resource
Patientand parametergender - 2.And links question from where code will be queried
Patient?gender={{ %resource.repeat(item).where(linkId = 'gender-choice').answer.valueCoding.code }}
Take note: Actual linkId may differ! You must select linkId equals to Gender widget.
Usage
Now let's try to answer on questions:
- 1.Diet questions:
- 1.If user choose into Type question
Meatanswer. Into Food question will be available onlyBeefandLambanswer. - 2.If user choose
Vegetablesanswer into Type question — into Food question will be available onlyCarrotandPotatoanswers.
- 2.Patients questions:
- 1.If user choose into Gender question
Maleanswer. Into Patient reference question will be available list of patients only withMalegender. - 2.If user choose
Femaleanswer into Gender question — into Patient question will be available list of patients only withFemalegender.