The 'Calculation' field in CDMS
Table of Contents
A calculation field allows you to specify a formula or calculation in reference to variables present within the study.
We have a calculation manual where you can find more information about how to use and create calculation templates.
To make calculations with values of different fields, it must be possible to reference other fields. This is done by using the 'Variable name' entered into study fields. Before creating a calculation field, please enter and note the "Variable name" for the fields that are to be used in the calculation, e.g. to reference the field value of "Is the patient older than 18?" you need its variable {INCL03}:
To create a calculation field, select the appropriate button in the form builder field list:
Within the dialog window, complete the field as normal. The 'Summary/Calculation template' field is used to specify the formula/calculation you wish to perform. To reference other fields, place braces '{ }' around the field variable name e.g. {INCL03}. See the image below for a full example:
Please note that the calculation field value is updated when the fields that are used in the calculation are filled in, and if a user opens the form for a participant in which the calculation field is located. It is always necessary to open the form which contains the calculation field to make sure the calculation is updated. For example, if we want to calculate the BMI using two fields 'weight' and 'height' and the fields 'weight' and 'height' are located in the form Baseline while the BMI calculation field is located in the BMI form, it is necessary to open the BMI form to run the calculation.
Common JavaScript syntax
To get you started, here are a few common JavaScript operators to use for basic calculations along with their description.
Description | Operator |
Variable | {Variable} |
Addition | + |
Subtraction | - |
Division | / |
Multiplication | * |
Exponential (x to the power of y) |
Math.pow(x, y) |
Equal to | == |
Not equal to | != |
Greater than | > |
Greater than or equal | >= |
Less than | < |
Less than or equal | <= |
Logical "AND" | && |
Logical "OR" | || |
Referring to surveys
It is also possible to base the calculations in study forms upon data entered in a survey. When creating the calculation field, enter the variable names defined in your survey fields.
For example, using responses from a survey where the patient provides information about weight and height with variable names {surv_pat_weight} and {surv_pat_height}. These variables can be used to create a calculation field inside the study forms that refers to that field, for example:
{surv_pat_weight}/Math.pow({surv_pat_height},2)
Please note - Castor can only calculate in reference to the latest filled in version of a survey. This means that it is not possible for calculations to refer to different versions of a survey inside a participant’s record, only to the most recent version provided.