A calculation field allows you to specify a formula or calculation in reference to variables present within the study.
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. weight (Pat_Weight) and length (Pat_Length):
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. to reference patient length, enter {Pat_Length}. See the image below for a full example:
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 record, only to the most recent version provided.
Castor Support Team