Contact Us

If you still have questions or prefer to get help directly from an agent, please submit a request.
We’ll get back to you as soon as possible.

Please fill out the contact form below and we will reply as soon as possible.

  • Contact Us
  • Home
  • CDMS
  • Castor CDMS Calculations Manual
  • Introduction to calculations: the basics

Introduction to calculation fields and syntax in EDC/CDMS

Contact Us

If you still have questions or prefer to get help directly from an agent, please submit a request.
We’ll get back to you as soon as possible.

Please fill out the contact form below and we will reply as soon as possible.

  • CDMS
    Castor CDMS Manual Castor CDMS Calculations Manual Frequently Asked Questions Articles for Data Managers Castor CDMS Compliance Release Documents
  • eConsent
    Castor eConsent Manual Castor eConsent Compliance Release Documents
  • SMS
    Castor SMS Manual Castor SMS Compliance Release Documents
  • Castor Connect
    Castor Connect Compliance Release Documents Castor Connect Manual Castor Connect - Participant Quick Start Guide
  • Helpdesk
    News Other Resources Castor products knowledge resources
  • Status page
  • Completing a Study
+ More

Table of Contents

Common applications of calculations Referencing study variables Form Exchange Calculation Helper JavaScript

Calculation fields in Castor allow you to solve different mathematical problems by using the variables from your eCRF.

Common applications of calculations

Calculations can be used for simple mathematical operations, such as calculating the body mass index from two variables - height and weight. The calculation fields can also be used for more complex operations, such as calculating a score from multiple questions in a survey, or defining diagnosis groups based on a selected diagnosis.


You can also use calculations for non-mathematical problems, such as cross-checking different variables within your eCRF, e.g. when you want to ensure that the date of discharge is later than the date of admission. If you want to use multiple dependencies - to make a field appear if two or more conditions are met, you can also use calculations. 


Our online manual also contains examples of calculations that you can use. You will need to adjust the calculations to your own study. You can use information from other fields by using the variable name of the fields in the calculation. Variable names are always between braces ({}) like this: {variable_name}.


Referencing study variables

You can access the value of the field by putting the variable name of the field between braces: 

{variable_name_here}

When contacting Castor EDC support with questions about calculations, we recommend adding the stored calculation link to your question. Accessing the calculation details can help us answer your question.


If you want to use the text value of a field, enter the variable name and braces in quotes: 

'{variable_name_here}' 



Grid and checkbox fields need to be used differently in calculation fields. See how you can use grid fields and checkbox fields in calculations. It is also possible to reference record IDs, institutes and institute countries.

Form Exchange

A great way to get started with calculations is by using our Form Exchange calculation templates. Learn how to use it here. 

Calculation Helper

You can use the calculation helper tool to check the syntax and output of your calculations. Read further instructions here.

JavaScript

Castor uses JavaScript to solve your Calculation Template. If you are a beginner, we suggest you have a look at the general calculation templates - you can find most commonly used templates here and you can simply copy the template into your own calculation field and adjust it as necessary.


Standard arithmetic operators in JavaScript:

+ Addition
- Subtraction
* Multiplication
/ Division
% Modulus (division remainder)


Different mathematical functions in JavaScript:

Method Description
Math.abs({variable}) Returns the absolute value of the variable
Math.ceil({variable}) Returns variable, rounded upwards to the nearest integer
Math.floor({variable}) Returns variable, rounded downwards to the nearest integer
Math.log({variable}) Returns the natural logarithm (base E) of the variable
Math.max({variable1}, {variable2}, {variable3}, ...) Returns the number with the highest value from variable1, variable2 and variable3
Math.min({variable1}, {variable2}, {variable3}, ...) Returns the number with the lowest value variable1, variable2 and variable3
Math.pow({variable},x) Returns the value of variable to the power of x
Math.round({variable}) Rounds variable to the nearest integer
Math.sqrt({variable}) Returns the square root of variable 


You can find more mathematical functions here.


Set conditions (if statements) in JavaScript:

  • You can use conditions to run formulas only if a variable matches your condition. 

For example (open the calculation in the calculation helper):

if({variable} > 0) 100 / {variable};


You can find more information about if/else logic here.


.toFixed(n) - Adjusting the number of digits after the decimal point

.toFixed(n) helps to adjust the number of digits appearing after the decimal point.


For example, when calculating a BMI, it is possible to display 3 digits after the decimal point

var bmi = {pat_weight}/({pat_height}*{pat_height});
bmi.toFixed(3);


Test this calculation here.

It is also possible to add this in the end of the formula, by just putting the end result in parenthesis and then adding .toFixed(x) at the end. For example: 

if({measurement_unit} == 0) {
({weight} * 2.2046).toFixed(4)
}


Test this calculation here.

If you want to learn more about JavaScript, you can check out this JavaScript Tutorial. 


Below is the list of the most relevant articles from the tutorial that will help you get started with JavaScript:

  • Syntax
  • Operators
  • If...Else
  • Comparison Operators
  • Statements
  • Arithmetic
  • Data Types
  • String Methods and Properties
  • For Loop
  • Arrays
  • Array Methods
  • Get Date Methods
  • Date Objects
  • Math Object
  • Number Methods
edc syntax calculation fields

Was this article helpful?

Yes
No
Give feedback about this article

Related Articles

  • Using the "for loop" in calculations in EDC/CDMS
  • Forcing Castor to calculate with empty fields in EDC/CDMS
  • Comparing variables with calculation fields in EDC/CDMS
  • Compare several numerical variables against a specific variable in EDC/CDMS
ISO 27001
FDA - 21 CFR part 11
ICH GCP compliant
HIPAA compliant
CDISC
ISO 9001
gdpr compliant

Products & Industries

  • Electronic Data Capture (EDC)
  • ePRO
  • eConsent
  • Decentralized Clinical Trials (DCT)
  • Clinical Data Management
  • Medical Device & Diagnostics
  • Biotech & Pharma
  • CROs
  • Academic Research

Resources

  • Thought Leadership
  • Blog
  • Castor Academy
  • Knowledge Base

 

Company

  • About Us
  • Careers
  • News
  • Contact Support
  • Contact Us

Legal & Compliance

  • Terms of Use
  • Privacy & Cookie Statement
  • Responsible Disclosure Policy
  • Good Clinical Practice (GCP)
  • ISO Compliance Certificates
  • GDPR & HIPAA Compliance
  • Security Statement

© 2022, Castor. All Rights Reserved.

Follow us on social media


Knowledge Base Software powered by Helpjuice

Definition by Author

0
0
Expand