Calculated fields rules

 

Variables

A variable is a specific field within a referenced order or study. They are represented by column IDs, COLID. The list of COLIDs are displayed on the Customize Labels pages and in the Calculated Fields User Manual.

 

Variables types

Each Variable has a type depending on the information the field conveys. Some macros and operators work only if the arguments are of the required type. The table below lists the supported variable types.

 

Boolean

A binary value in the form "yes" or "no" used by the boolean macros.

DateTime

All fields that contain a Date, Time or Date+Time value.

Interval

Expresses an interval of time between DateTime values. The display format of this type variable is defined in the Date Format section of the Settings page.

Number

Binary integer or floating point number fields.

String

All alphanumeric strings.

 

Constants

Constants are literal values entered in the calculated field rule. Their format is defined as follows:

 

DateTime

Date and time expressed in the format YYYYMMDD_HHMMSS. To express time only, the format is 00000000_HHMMSS. Date-only constants are formatted YYYYMMDD_000000

Interval

Interval constants, expressed in seconds, using the format <number>S. For example, 1200S for 1,200 seconds. Used to add time to DateTime variables.

Number

Integer or floating point constants expressed as a string of numbers. Negative values must be expressed as an operation. For example, for -5, use 0-5. For -2.3, use 0-2.3.

State

System-defined study states, expressed as the state label without any quotes. States are Cancelled, Checked In, Checked Out, Completed, Dictated, Final, In Process, Ordered, Preliminary, Read, Scheduled, Unviewed and Viewed.

String

String constants enclosed in double quotes.

 

Macros and Operations

 

Arithmetic macros and operations

add(a,b[,c...])

Add the operands. If the Type of all operands is Number or Interval, the result is an arithmetic sum of the values. If the Type of all operands is String, the result is the concatenation of the strings. If the operands are a DateTime and one or more Interval variables, the Interval variables are added to the DateTime variables and the result is a DateTime variable. All other combinations of variable types is unsupported and returns NULL.

div(a,b)

Divide the operands. If the Type of all operands is Number or Interval, the result is the arithmetic dividend a/b. All other combinations of variable types are unsupported and return NULL. Division by zero is checked, but zero-value variables may fail and produce undefined results.

mul(a,b[,c...])

Multiply the operands. If the Type of all operands is Number or Interval, the result is the arithmetic product of the values. All other combinations of variable types is unsupported and returns NULL.

sub(a,b)

Subtract the operands. If the Type of all operands is Number, Interval or DateTime, the result is the arithmetic difference a-b. If operand a's Type is DateTime and b's Type is Interval, the result is a DateTime variable a-b. All other combinations of variable types is unsupported and returns NULL.

+

Same as add() with a limit of two operands, in the format a+b.

-

Same as sub() using the format a-b.

*

Same as mul(), with a limit of two operands, in the format a*b.

/

Same as div() using the format a/b.

 

Boolean macros and operations

and (x,y)

The result is “yes” if Boolean expression x and y are both “yes”. If either Boolean expression is “no", the result is “no”.

not(x)

The result is “yes” if the Boolean expression x is “no”. Otherwise, the result is “yes”.

or(x,y)

The result is “yes” if Boolean expression x or y is “yes”. If neither Boolean expression is “yes”, the result is “no”.

xor(x,y)

The result is “yes” if either Boolean expression x or y is “yes”. If both Boolean expressions are “no” or if both are “yes”, the result is “no”.

&

Same as and(), in the format x&y.

|

Same as or(), in the format x|y.

^

Same as xor(), in the format x^y.

 

Calendar macros and operations

createdate(y,m,d[,h[,min[,s]]])

Returns a datetime value constructed from the numbers specifying the year (y), month (m) and day (d). Includes the hour (h), minutes (min) and seconds (s), if specified. Otherwise, hours, minutes and seconds are returned as 000000. If any value exceeds the applicable values, such as a day=32, the operation will fail and return an empty string.

day(dt)

Returns the day part of datetime, dt, as a number 0 through 31.

hour(dt)

Returns the hour part of the datetime, dt, as a number 0 through 23.

minute(dt)

Returns the minute part of the datetime, dt, as a number 0 through 59.

month(dt)

Returns the month part of datetime, dt, as a number 0 through 12.

second(dt)

Returns the seconds part of datetime, dt, as a number 0 through 59.

year(dt)

Return the month part of datetime, dt, as a number.

 

Conditional macros and operations

equals(x,y)

The result is the boolean "yes" if the two values are the same. Otherwise, the result is "no". Both x and y must be the same type: string, number or interval.

greater(x,y)

The result is the boolean "yes" if x is greater than y. Otherwise, the result is "no". Both x and y must be the same type: number or interval.

if(condition,x,y)

Returns x if the Boolean expression condition evaluates to "yes". Otherwise, the result is y.

less(x,y)

The result is "yes" if x is less than y. Otherwise, the result is "no". Both x and y must be the same type: number or interval.

=

Same as equals(), in the format x=y.

>

Same as greater(), in the format x>y

<

Same as less(), in the format x<y

 

Date macros and operations

age(d1,d2)

Returns the difference d1-d2 in calendar years.

atleaststatemintime(s)

Returns the earliest date and time the order or study existed in state s or any later state. The result is in DateTime format. Available for the Study Information table only.

atmoststatemaxtime(s)

Returns the most recent date and time the order or study was in state s or any earlier state. The result is in DateTime format. Available for the Study Information table only.

curdatetime()

Returns the current date and time in DateTime format.

minstatetime(s)

Returns the earliest date and time the order or study existed in state, s. The result is in DateTime format.

maxstatetime(s)

Returns the most recent date and time the order or study existed in state, s. The result is in DateTime format.

 

Multi-value macros and operations

avg(id)

Returns the mathematical average of the values in the multi-valued field, id, such as an object-level field in the study table. Number and Interval Type variables only.

count(id)

Returns the number of entries in the multi-valued field, id, such as an object-level field in the study table.

countif(id,s)

Returns the number of entries in the multi-valued field, id, whose value is s. Number, Interval and String Type variables only. The result is in Number format.

hasvalue(id)

Checks the specified field's, id's, value for NULL or an empty string. Returns the boolean “no” if no value is present. Otherwise, it returns the boolean “yes”.

max(id)

Returns the greatest value in the multi-valued field, id, such as an object-level field in the study table. The comparison is numeric for Number and Interval Types, lexicographic for String and DateTime Types.

min(id)

Returns the lowest value in the multi-valued field, id, such as an object-level field in the study table. The comparison is numeric for Number and Interval Types, lexicographic for String and DateTime Types.

sum(id)

Returns the mathematical sum of the values in the multi-valued field, id, such as an object-level field in the study-table. Number and Interval Type variables only.

 

String macros and operations

concat(s1,s2[,s3...])

Concatenates the values s1 and s2 (and s3, etc.) NULL values are treated as an empty string, "".

indexof(s,p)

Returns the starting position of pattern p in string s. The first position in string s is 0. Returns -1 if p is not found in s. Returns NULL if s or p is NULL. Matching is case-sensitive.

strlen(s)

Returns the number of characters in string s.

substr(s,from[,len])

Returns the len characters in string s, starting at position from. The first position is '0'. If from extends past the end of the string, an empty string is returned. If len is omitted, the remaining string is returned.

 

Type conversion macros and operations

floor(n)

Returns the truncated integer part of the number, n.

interval(n)

Convert the number, n, to an interval.

number(s)

If the argument s is a string, convert the first non-numeric or decimal characters to a floating point number. If s is an interval, convert it to a number representing the number of seconds in the interval.

string(n)

Convert the number, n, to a string.