Skip to content

Logic, Variables & Scoring ​

A Medipal questionnaire is more than a list of questions. Each question can carry actions that run when a respondent enters or answers it, and the questionnaire can hold variables and functions that compute scores while the respondent progresses. All of this is built visually in the designer, with an escape hatch to custom code for advanced cases.

How actions work ​

Select a question and open the Actions tab of the side panel. Actions are attached to one of two triggers:

TriggerWhen it runsWhat it can see
When entering a questionJust before the question is displayedThe question definition
When answering a questionWhen the respondent confirms an answer and moves onThe question and the given answer

Under a trigger you add one or more action groups. A group has:

  • a condition (an expression that evaluates to true or false; an empty condition is always true),
  • a list of actions to run if the condition is met,
  • a list of actions to run else.

Groups run in order. If a question has no answer-time actions at all, the engine simply moves to the next question. As soon as you add an answer-time group, navigation becomes explicit: one of your actions must decide where to go next (for example Next Question), otherwise the respondent stays on the question.

Available actions ​

ActionEffect
Next QuestionContinue to the next question in order.
Skip QuestionJump over the following question.
Go To QuestionJump to a specific question chosen by reference name.
Go To Question IndexJump to a question by its position.
Set VariableAssign a value (or the result of an expression) to a questionnaire variable.
End QuestionnaireFinish immediately and submit the answers collected so far.
Custom CodeRun a JavaScript expression you write yourself.

The expression builder ​

Conditions and values are composed from blocks rather than typed by hand. Blocks are grouped in the command panel; start typing to search.

GroupExamples
Question ReferencesThe current answer, the raw answer value of any question, question properties.
ComparisonEquals, Not Equals, Less Than, Greater Than (and the "or equal" variants), Includes (for multiple choice).
ArithmeticAddition, Subtraction, Multiplication, Division, Modulo, Exponentiation.
LogicalAND, OR, NOT, and grouping parentheses.
TextContains, Does Not Contain, Starts With, Ends With, case changes, trim, length, substring, replace, split.
NumberRound, Floor, Ceil, Absolute, To Fixed.
BooleanNegate, cast to boolean.
Array and ObjectLength, first/last item, get by index, map/filter/reduce, keys, values, entries.
ValuesLiteral text, numbers, true/false.
Variables and FunctionsRead a variable, call a global function.

Two illustrative conditions, as the builder assembles them:

Current Question Answer  Equals  "Yes"
Raw Answer Value of "pain_score"  Greater Than  7   AND   Variable "visit_number"  Equals  1

Custom Code blocks accept a JavaScript expression when the built-in blocks are not enough. Expressions run in an isolated context with access only to the question, the answer and the questionnaire methods; they cannot reach the page or the network.

Variables ​

Open Variables in the questionnaire navigation to manage global variables. Each has a Name (letters, digits and underscores, starting with a letter or underscore), a Label, a Description, a Type (Number, String or Boolean) and a Default Value.

Variables hold state for the whole session: a running score, a flag set by an earlier answer, a value carried into later logic. Set them with Set Variable actions and read them anywhere in conditions. Their final values are stored with the submission and appear on the Scoring tab of every submission preview.

Schedules can also seed initial variables per enrollment (for example the visit number or a baseline value), so the same questionnaire behaves differently for different patients. See Scheduling & Enrollments.

Functions ​

Functions are reusable calculations defined once and called from any expression. A function has a Name, Label, Description, a list of typed Arguments, a Return Type and its Function Code in JavaScript.

Typical uses: computing an index from several answers (for example a BMI from weight and height), normalising a raw total to a 0–100 scale, or mapping a score to a category label. Use a Set Variable action to store the function result so that it is included in the submission's scoring.

Scoring actions ​

Beyond variables, the Scoring area lets you define scoring actions evaluated when the questionnaire is submitted. Each action combines a condition built from sections, questions, results, total score and comparison operators with one of:

  • Alert: flag the submission for attention.
  • Send email: notify an address with a subject and content you define.

These are the simplest way to react to a threshold (for example a high symptom score) without building a workflow. For richer automation across systems, use Workflows.

Simulation ​

Simulation runs the questionnaire with the real engine against your current draft, including unsaved changes, and shows what happens as you answer:

  • which question is displayed next after each answer,
  • the current value of every variable,
  • the scoring output that would be submitted.

Use it to verify skip logic, dead ends and threshold rules before publishing. Nothing is stored; simulated answers are discarded when you leave the page.

Relations between questionnaires ​

Versions & Relations shows how a questionnaire relates to others: its version tree (earlier and later versions), duplicates made from it and the revision history. See Versions & Publishing.

Troubleshooting ​

SymptomLikely causeWhat to do
The respondent is stuck on a question after answeringAn answer-time action group exists but no navigation action runs on every pathAdd Next Question to the else branch (or to the group) so a path always continues.
A condition is never trueComparing the wrong value type (text vs number) or the wrong reference nameCheck the answer's raw value in Simulation; use the type-safe blocks or a cast.
"Missing Argument" on an actionA block was left incompleteOpen the action and fill every argument; empty conditions are allowed, empty arguments are not.
A variable shows its default value in the submissionIt was never set on the path the respondent tookSet it in the answer-time actions of the relevant questions or seed it from the schedule.
Changing languages broke an expressionLogic referenced an option label rather than a valueCompare against option values, which are language-independent.
A function call errors in simulationArgument count or type mismatch, or the code has no returnCheck the argument list and make sure the code returns a value.