Awell Health Developer Hub
Developer Hub

This mutation evaluates all conditional logic defined in a form and lets you know which questions (that have display logic) should be visible or hidden.

When working with forms that use conditional logic, you have to call this mutation every time a user answers any question in the form. This guarantees that you will always show the relevant questions only.

How it works

Rendering a form with Awell
Rendering a form with Awell

Request

Mutation

  • graphql
01mutation EvaluateFormRules($input: EvaluateFormRulesInput!) {
02 evaluateFormRules(input: $input) {
03 results {
04 question_id
05 satisfied
06 }
07 }
08}

Variables

  • json
01{
02 "input": {
03 "form_id": "{{FORM_ID}}",
04 "answers": [
05 {
06 "question_id": "{{HEIGHT_QUESTION_ID}}",
07 "value": "183"
08 }
09 ]
10 }
11}

Serialization

Given form responses are polymorphic, the answer value for a question should always be sent as a string. Values are validated and deserialized on the Awell side and we will throw an error if a value does not match the corresponding data point value type.

In table below you can find an overview of all question types, their corresponding data point value type, and the value type you should be sending to the Awell API.

Question typeData point value typeValue type to sendExamples
DatedateISO8601 string"2023-01-01"
Numbernumberstring"10"
Short Textstringstring"Awell is great"
Long Textstringstring"A long story about why Awell is so great"
Multiple Choicenumberstring
(value of selected option)
"1"
Multiple Selectnumbers_arraystring
(array of values of the selected options)
"[1, 2, 4]"
"['1', '2', '4']"
Slidernumberstring"50"
Yes/Nobooleanstring
(we accept different values for booleans)
"true" | "false"
"t" | "f"
"yes" | "no"
"y" | "n"
"1" | "0"

Response

Important to note is that the response of this mutation returns an array of results stating what questions should be visible or hidden based on the configured display logic (=rules).

If a question is always visible because it has no display logic configured, then it won't be included in the response. This means that, by default, questions not included in the response should be visible.

Example

  • A form has 4 questions: Q1, Q2, Q3, and Q4
  • Q1 and Q2 don't have display logic defined
  • Q3 and Q4 do have display logic defined
  • json
01{
02 "data": {
03 "evaluateFormRules": {
04 "results": [
05 {
06 "question_id": "Q3",
07 "satisfied": true
08 },
09 {
10 "question_id": "Q4",
11 "satisfied": false
12 }
13 ]
14 }
15 }
16}

Given the above response, we know that Q1, Q2, and Q3 should be visible and that Q4 needs to be hidden.

Code snippet to get you going

  • typescript
01type QuestionRuleResult = {
02 question_id: string
03 satisfied: boolean
04}
05
06const isQuestionVisible = (
07 questionId: string,
08 evaluationResults: Array<QuestionRuleResult>
09): boolean => {
10 const questionEvaluationResult = evaluationResults.find(
11 (result) => result.question_id === questionId
12 )
13
14 /**
15 * If there's no evaluation result for our question (i.e. question has no display logic) --> show it by default
16 * If there's an evaluation result for our question: see whether the display logic rule was satisfied
17 */
18 const isVisible = isNil(questionEvaluationResult)
19 ? true
20 : questionEvaluationResult.satisfied
21
22 return isVisible
23}

How to use