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
  • General calculation templates

Calculating with checkbox fields 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

Check if a box was checked Retrieve the highest or lowest value of the selected checkboxes Calculate the sum of multiple options of a checkbox field Calculate the number of checked boxes Calculate if any checkbox was selected Calculate how many checkboxes are selected and their total sum Assign different values to checkbox options and calculate the total

When testing your calculation with checkboxes in the Calculation Helper, use commas (,) as separator instead of semicolon (;). On the contrary, Castor CDMS uses semicolon (;).

 

 

Check if a box was checked

Checkbox fields are saved as a semi-colon separated string, e.g. "1;4;5". To be able to perform calculations with these values, you will need to split the string in separate values and check if a specific value of interest is in the collection of values.

 

For example, to check whether a checkbox with the option value 5 was checked, you can use:

 

var splitted = "{variable_name}".split(';');
if (splitted.indexOf("5") > -1) {
 1;
} else {
 0;
}

This will return 1 if that option was checked or 0 if it wasn't. Replace variable_name with your own checkbox variable and '5' with your values of interest.

Retrieve the highest or lowest value of the selected checkboxes

To retrieve the highest value you can use Math.max.apply() and Math.min.apply() to retrieve the lowest value.

 

The below calculation will return the maximum value from the selected checkbox values.

 

var splitted = "{variable_name}".split(';');
Math.max.apply(null, splitted);

The below calculation will return the minimum value from the selected checkbox values.

 

var splitted = "{variable_name}".split(';');
Math.min.apply(null, splitted);

Calculate the sum of multiple options of a checkbox field

The below calculation will calculate the sum of multiple options of a checkbox field. 

 

var splitted = "{variable_name}".split(";");
var myTotal = 0; // Variable to hold your total
for(var i = 0, len = splitted.length; i < len; i++) {
 myTotal += Number(splitted[i]);
}
myTotal;

In the third line, a for loop iterates over the values of your checkbox fields that are selected.

Calculate the number of checked boxes

The below calculation will calculate the number of checked boxes:

 

'##allowempty##';
if("{variable_name}" == "'NA'") {
'0';
} else {
var splitted = "{variable_name}".split(";");
splitted.length;
}

Please note that "splitted.length" will always be >= 1.

Calculate if any checkbox was selected

The below calculation will calculate if any of the checkboxes have been selected.

 

'##allowempty##';
if ("{variable_name}" == "'NA'") {
 'Checkbox is empty'
}; 

Calculate how many checkboxes are selected and their total sum

The below calculation will calculate how many checkboxes were selected and their total sum.

 

var string = "{check_boxes}".split(";");
var myTotal = 0;
var sum = 0;
for (var i = 0; i < string.length; i++) {
 if (string.indexOf(string[i]) > -1) {
 myTotal = myTotal + 1;
 sum = sum + parseInt(string[i]);
 }
};
"There are " + myTotal + " selected checkboxes with a total sum of " + sum + " .";

Assign different values to checkbox options and calculate the total

All options in a checkbox option group must have a unique value. For example, 'Option A' with value 1, 'Option B' with value 2 and 'Option C' with value 3. However in some cases it is necessary to assign the same values to different options to calculate the total score. 

 

For example, 'Option A' with value 1, 'Option B' with value 1 and 'Option C' with value 2. Use this calculation template to assign the same values to different options and calculate their total score:

 

var splitted = "{checkbox_variable}".split(";");
var myTotal = 0;
if (splitted.indexOf("1") > -1) {
myTotal+=1;
}
if (splitted.indexOf("2") > -1) {
myTotal+=1;
}
if (splitted.indexOf("3") > -1) {
myTotal+=2;
}
if (splitted.indexOf("4") > -1) {
myTotal+=3;
}
if (splitted.indexOf("5") > -1) {
myTotal+=3;
}
myTotal;
edc cdms checkbox calculations

Was this article helpful?

Yes
No
Give feedback about this article

Related Articles

  • Predefined variables in EDC/CDMS
  • Force not to round a calculation result in EDC/CDMS
  • Calculating with numbers in grids in EDC/CDMS
  • Check if all fields are filled in with 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