Start a conversation

Calculation errors

This article provides an overview of errors you might find in your calculation field in data entry. The most common reason for calculation errors are mistakes in syntax (in the calculation template). You can check your calculations using the Castor Calculation Helper -  this tool can help identify syntax errors and incorrect references in calculations.

First make sure that when using a variable that is marked as a string (e.g. a checkbox field, a text field or a date field - anything that is not a numerical value), the variable name is between quotation marks, such as "{date_of_visit}".  This is the most common reason for calculation errors.

Errors in calculation fields can be seen in data entry, and look something like this:

In the examples below some other frequent errors are shown.  For every error, you will see the wrong calculation with comments about what is wrong after "//Reason:". The correct solution is shown below under "//Solution".

Not all values for this calculation are available (yet)

This is not an error per se, but simply indicates that not all values are available for the variables used in the calculation. This includes the situation when there is a dependent field used in the calculation which has no data.  The error can be solved using '##allowempty##'  in the beginning of the calculation. For more information, see the article Forcing Castor to calculate with empty fields.

Unexpected end of input

This can mean that one of your opening parentheses "(" or brackets "{" is not closed with ")" or "}". For example, the following calculation misses a closing bracket } in the end :

//Example of an unexpected end of input
'##allowempty##';
if ("{allergy}" == "'NA'") {
1; //Reason: A closing bracket is missing!
//Solution
'##allowempty##';
if ("{allergy}" == "'NA'") {
1;
} //Correct!

Unexpected identifier

This can mean that

  • A semicolon ";" is missing at the end of an outcome of a calculation:
//Example 1 of an unexpected identifier
'##allowempty##';
if ("{slider}" == "'NA'") {
1 //Reason: A semicolon is missing here!
}
//Solution
'##allowempty##';
if ("{slider}" == "'NA'") {
1; //Correct!
}
  • Both double and single quotation marks are used:
//Example 2 of an unexpected identifier
'##allowempty##';
if ('{allergy}' == "'NA'") { //Error: {allergy} should be with double quotation marks, because 'NA' also uses double quotation marks!
"The patient does not have allergies.";
}
//Solution
'##allowempty##';
if ("{allergy}" == "'NA'") { //Correct!
"The patient does not have allergies.";
}

Invalid or unexpected token

This can mean that

  • One of your quotes is not closed:
//Example of a missing closing quote
'##allowempty##';
if ("{allergy}" == "'NA'") {
"The patient does not have allergies.; //Reason: a closing quotation mark is missing here!
}
//Solution
'##allowempty##';
if ("{allergy}" == "'NA'") {
"The patient does not have allergies."; //Correct!
}
  • There are too many brackets { } or parentheses ( ):
//Example of too many brackets
'##allowempty##';
if ("{meds}" == "'NA'") {{ //Error: there are too many brackets!
"No medication";
}
//Solution
'##allowempty##';
if ("{meds}" == "'NA'") { //Correct!
"No medication";
}
  • There are too few brackets { } or parentheses ( ):
//Example of too few parentheses
'##allowempty##';
if ("{meds}" == "'NA'" { //Reason: a closing parenthesis is missing here!
"No medication";
}
//Solution
'##allowempty##';
if ("{meds}" == "'NA'") { //Correct!
"No medication";
}

Missing ) after argument list

This can mean that you're trying to use getTimeDiff with empty values. Solution: Insert these tags at the top of your calculation:

'##allowempty##'; '##setemptytozero##';

Cannot read property '4' of null, Unable to get property '4' of undefined or null reference

This can mean that you're trying to use some functions, such as getDateDiff, with empty values. This type of function cannot use empty values. If you are using the '##allowempty##' tag in your calculation, make sure that you actually need to use this tag - this is only necessary when you need to force Castor to calculate with empty fields, for example, if you are checking whether a field is empty.

Choose files or drag and drop files
Was this article helpful?
Yes
No
  1. Castor Support Team

  2. Posted
  3. Updated