A draft specification is available in the BASE component, see here.

This page is for discussion on this Rules language, including built-in and plug-in functions, operators and value referencing.

Built-in Functions

Current list of built-in functions

DIPS Function list

3.1. Logical functions

Table 3. Logical functions

Function

Description

AND(logical1, [logical2], …)

Returns TRUE if all of its arguments are TRUE

OR(logical1,logical2,…)

Returns TRUE if any argument is TRUE

NOT(logical)

Reverses the logic of its argument

IF(logical_test, value_if_true, [value_if_false])

Specifies a logical test to perform

TRUE()

Returns the logical value TRUE.

FALSE()

Returns the logical value FALSE.

3.2. Math and trigonometry functions

Table 4. Math and trigonometry functions

Function

Description

ABS(number)

Returns the absolute value of a number. The absolute value of a number is the number without its sign.

ACOS(number)

Returns the arccosine, or inverse cosine, of a number. The arccosine is the angle whose cosine is number. The returned angle is given in radians in the range 0 (zero) to pi.

ASIN(number)

Returns the arcsine, or inverse sine, of a number. The arcsine is the angle whose sine is number. The returned angle is given in radians in the range -pi/2 to pi/2.

ATAN (number)

Returns the arctangent, or inverse tangent, of a number. The arctangent is the angle whose tangent is number. The returned angle is given in radians in the range -pi/2 to pi/2.

ATAN2(x_num,y_num)

Returns the arctangent, or inverse tangent, of the specified x- and y-coordinates. The arctangent is the angle from the x-axis to a line containing the origin (0, 0) and a point with coordinates (x_num, y_num). The angle is given in radians between -pi and pi, excluding -pi.

CEILING(number,significance)

Returns number rounded up, away from zero, to the nearest multiple of significance. For example, if you want to avoid using pennies in your prices and your product is priced at $4.42, use the formula =CEILING(4.42,0.05) to round prices up to the nearest nickel.

COS(number)

Returns the cosine of the given angle.

COSH(number)

Returns the hyperbolic cosine of a number.

EXP(number)

Returns e raised to the power of number. The constant e equals 2.71828182845904, the base of the natural logarithm.

FLOOR(number,significance)

Rounds number down, toward zero, to the nearest multiple of significance.

INT(number)

Rounds a number down to the nearest integer.

LN(number)

Returns the natural logarithm of a number. Natural logarithms are based on the constant e (2.71828182845904).

LOG(number,[base])

Returns the logarithm of a number to the base you specify.

LOG10(number)

Returns the base-10 logarithm of a number.

PI()

Returns the number 3.14159265358979, the mathematical constant pi, accurate to 15 digits.

POWER(number,power)

Returns the result of a number raised to a power.

RAND()

Returns an evenly distributed random real number greater than or equal to 0 and less than 1. A new random real number is returned every time the worksheet is calculated.

RANDBETWEEN(bottom,top)

Returns a random integer number between the numbers you specify. A new random integer number is returned every time the worksheet is calculated.

ROUND(number, [num_digits])

The ROUND function rounds a number to a specified number of digits.

SIGN(number)

Determines the sign of a number. Returns 1 if the number is positive, zero (0) if the number is 0, and -1 if the number is negative.

SIN(number)

Returns the sine of the given angle.

SINH(number)

Returns the hyperbolic sine of a number.

SQRT(number)

Returns a positive square root.

SUM(number1, [number2], [number3], [number4], …)

The SUM function adds all the numbers that you specify as arguments.

TAN(number)

Returns the tangent of the given angle.

TANH(number)

Returns the hyperbolic tangent of a number.

TRUNC(number,num_digits)

Truncates a number to an integer by removing the fractional part of the number.

3.3. Text functions

Table 5. Text functions

Function

Description

CHAR(number)

Returns the character specified by a number. Use CHAR to translate code page numbers you might get from files on other types of computers into characters.

CODE(text)

Returns a numeric code for the first character in a text string. The returned code corresponds to the character set used by your computer.

CONCATENATE(text1, [text2], …)

The CONCATENATE function joins up to 255 text strings into one text string. The joined items can be text, numbers, cell references, or a combination of those items. For example, if your worksheet contains a person’s first name in cell A1 and the person’s last name in cell B1, you can combine the two values in another cell by using the following formula:=CONCATENATE(A1," ",B1)

FIND(find_text,within_text,start_num)

FIND locate one text string within a second text string, and return the number of the starting position of the first text string from the first character of the second text string.

LEFT(text,num_chars)

LEFT returns the first character or characters in a text string, based on the number of characters you specify.

LEN(text)

LEN returns the number of characters in a text string.

LOWER(text)

Converts all uppercase letters in a text string to lowercase.

MID(text,start_num,num_chars)

MID returns a specific number of characters from a text string, starting at the position you specify, based on the number of characters you specify.

PROPER(text)

Capitalizes the first letter in a text string and any other letters in text that follow any character other than a letter. Converts all other letters to lowercase letters.

REPLACE(old_text,start_num,num_chars,new_text)

REPLACE replaces part of a text string, based on the number of characters you specify, with a different text string.

REPT(text,number_times)

Repeats text a given number of times. Use REPT to fill a cell with a number of instances of a text string.

RIGHT(text,num_chars)

RIGHT returns the last character or characters in a text string, based on the number of characters you specify.

SEARCH(find_text, within_text, [start_num])

The SEARCH and SEARCHB functions locate one text string within a second text string, and return the number of the starting position of the first text string from the first character of the second text string. For example, to find the position of the letter "n" in the word "printer", you can use the following function: =SEARCH("n","printer") This function returns 4 because "n" is the fourth character in the word "printer."

SUBSTITUTE(text,old_text,new_text,instance_num)

Substitutes new_text for old_text in a text string. Use SUBSTITUTE when you want to replace specific text in a text string; use REPLACE when you want to replace any text that occurs in a specific location in a text string.

T(value)

Returns the text referred to by value.

TEXT(value, [format_text])

The TEXT function converts a numeric value to text and lets you specify the display formatting by using special format strings.

TRIM(text)

Removes all spaces from text except for single spaces between words. Use TRIM on text that you have received from another application that may have irregular spacing.

UPPER(text)

Converts text to uppercase.

VALUE(text)

Converts a text string that represents a number to a number.

3.4. Statistical functions

Table 6. Statistical functions

Function

Description

AVERAGE(number1, [number2],…)

Returns the average (arithmetic mean) of the arguments.

AVERAGEA(value1,value2,…)

Calculates the average (arithmetic mean) of the values in the list of arguments.

COUNT(value1, [value2],…)

The COUNT function counts the number of vaues that contain numbers, and counts numbers within the list of arguments.

COUNTA(value1, [value2], …)

The COUNTA function counts the number of values that are not empty in a range.

COUNTBLANK(value1, [value2], …)

Counts empty values in a specified range of values.

COUNTIF(value1, [value2], …, ">2")

The COUNTIF function counts the number of values within a range that meet a single criterion that you specify

MAX(number1,number2,…)

Returns the largest value in a set of values.

MAXA(value1,value2,…)

Returns the largest value in a list of arguments.

MIN(number1,number2,…)

Returns the smallest number in a set of values.

MINA(value1,value2,…)

Returns the smallest value in the list of arguments.

STDEV(number1,number2,…)

Estimates standard deviation based on a sample. The standard deviation is a measure of how widely values are dispersed from the average value (the mean).

STDEVA(value1,value2,…)

Estimates standard deviation based on a sample. The standard deviation is a measure of how widely values are dispersed from the average value (the mean).

STDEVP(number1,number2,…)

Calculates standard deviation based on the entire population given as arguments. The standard deviation is a measure of how widely values are dispersed from the average value (the mean).

STDEVPA(value1,value2,…)

Calculates standard deviation based on the entire population given as arguments, including text and logical values. The standard deviation is a measure of how widely values are dispersed from the average value (the mean).

VAR(number1,number2,…)

Estimates variance based on a sample.

VARA(value1,value2,…)

Estimates variance based on a sample.

VARP(number1,number2,…)

Calculates variance based on the entire population.

VARPA(value1,value2,…)

Calculates variance based on the entire population.

3.5. Date and time functions

Table 7. Date and time functions

Function

Description

NOW()

Returns the datetime that represent the current date and time.

TODAY()

Returns the datetime that represent the current date.

NOWTICKS()

Returns the number of ticks that represent the current datetime.

TODAYTICKS()

Returns the number of ticks that represent the current date.

DATEVALUE(date_text)

The DATEVALUE function converts a date or datetime that is stored as string to ticks.

DAYTICKS(days)

The DAYTICKS function converts days to ticks.

HOURTICKS(hours)

The HOURTICKS function converts hours to ticks.

MINUTETICKS(minutes)

The MINUTETICKS function converts hours to ticks.

DATETIME(ticks)

The DATETIME function converts ticks to datetime.

ISO8601DATETIME(ticks)

The ISO8601DATETIME function converts ticks to iso8601 datetime string.

ISO8601DATE(ticks)

The ISO8601DATE function converts ticks to iso8601 date string.

ISO8601TIME(ticks)

The ISO8601TIME function converts ticks to iso8601 time string.

WEEKNUM(ticks)

Returns the week of the year that includes the date in the specified datetime value represented by ticks.

DURATIONTICKS(duration_text)

The DURATIONTICKS function converts iso8601 duration text to ticks.

DAYS(end_date, start_date)

Returns the number of days between two dates.

HOURS(end_date, start_date)

Returns the number of hours between two dates.

WEEKS(end_date, start_date)

Returns the number of weeks between two dates.

MONTH(ticks)

Returns the month of a date represented by ticks. The month is returned as an integer, ranging from 1 (January) to 12 (December).

YEAR(ticks)

Returns the year of a date represented by ticks. The year is returned as an integer in the range 0001-9999.

3.6. Information functions

Table 8. Information functions

Function

Description

ISBLANK(value)

Value refers to an empty value.

ISNUMBER(value)

Value refers to a number.

IBIME Function list

Take into account that the following functions are used for data transformation, so probably some of them don't make sense in validation rules. Most functions are just calls to XQuery native functions

4.1. Logical functions

Table 9. IBIME Logical functions

Function

Description

logical1 AND logical2

Logical AND operator

logical1 OR logical2

Logical OR operator

NOT(logical)

Logical NOT operator

TRUE

Returns the logical value TRUE.

FALSE

Returns the logical value FALSE.

*We don't specify an IF function, as the conditions are expressed as filter/function pairs

4.2. Math and trigonometry functions

Table 10. IBIME Math and trigonometry functions

Function

Description

abs(number)

Absolute value from the expression

ceiling(number)

Turns a Real number to its nearest greater Integer

floor(number)

Turns a Real number to its nearest lesserInteger

round(number)

Turns a Real number to its lesser (<=0.5) or greater (>0.5) Integer

round-half-to-even(real,long)

Rounds a real number with the required decimals

toFloat(number or string)

Transforms a number or string to Float

toInteger(number or string)

Transforms a number or string to Integer

random()

Returns a random number

4.3. Text functions

Table 11. IBIME Text functions

Function

Description

left(String, Int)

Trims a string from the left a number of characters

right(String, Int)

Trims a string from the right a number of characters

starts-with(String, String)

Returns if a string starts with another string

ends-with(String, String)

Returns if a string ends with another string

lower-case(String)

Returns the lowercase string of the string

upper-case(String)

Returns the uppercase string of the string

capitalize-first(String)

Returns the string with the first letter in uppercase

compare(String, String)

Returns an integer (-1, 0, 1) resulting of the comparison of the strings

contains(String, String)

Returns if a string contains another string

matches(String, Regex)

Returns if a string matches a regular expression

concat(String, String)

Concatenates two strings (resulting in another string)

index-of-string-first(String, String)

Returns an integer representing the first position of a substring within a string

normalize-space(String)

Returns the string without all the spaces and identation characters

substring(String, Int)

Returns the string that is the substring of the string from a position. example: substring("abcd",2)="bcd"

substring(String, Int, Int)

Returns the string that is the substring of the string from a position with a length given. example: substring("abcd",1,2)="bc"

substring-before(String, String)

Returns the string that is the substring that appears before the first occurrence of another specified string.  example: substring-before("abcd","b")="a"

substring-after(String, String)

Returns the string that is the substring that appears after the first occurrence of another specified string. example: substring-after("abcd","b")="cd"

replace(string, Regex, String)

Replaces all the occurrences of the regular expression by the chosen string.    example: replace("baba","b","cd")="cdacda"

replace-first(string, Regex, String)

Replaces the first occurrence of the regular expression by the chosen string.    example: replace-first("baba","b","cd")="cdaba"

string-length(String)Returns the length of the string
toString(value)Transforms parameter to a string
base64-encode(value)Transforms anything to a base64 string.

4.4. Statistical functions

Table 12. IBIME Statistical functions

Function

Description

count(path, [condition])

Counts the number of times the path is repeated on the source data (with optional condition)

sum(path, [condition])

Sums the numeric values on the selected path (with optional condition)
max(path,[condition])Returns the maximum value on the selected path (with optional condition)

min(path, [condition])

Returns the minimum value on the selected path (with optional condition)

avg(path, [condition])

Returns the average for the numeric values on the selected path that (with optional condition)

4.5. Date and time functions

Table 13. IBIME Date and time functions

Function

Description

toISODate(date,"yyyy-MM-dd")

Transforms a string to a ISO date, being first parameter the date you want to read and the second parameter the pattern to read it

toISOTime(time,"HH:mm:ss")

Transforms a string to a ISO time, being first parameter the date you want to read and the second parameter the pattern to read it

toISODateTime(datetime,"yyyy-MM-dd'T'HH:mm:ss")

Transforms a string to a ISO date time, being first parameter the date you want to read and the second parameter the pattern to read it

monthNameFromValue(Int, Int)

Returns the name of the month from a value (from 1 = January to 12 = December) and a length of the desired output string. Any 0 or negative length returns the full word

day-from-date(date)

Extracts days value from an ISO Date

day-from-dateTime(datetime)

Extracts days value from an ISO DateTime

month-from-dateTime(datetime)Extracts months value from an ISO DateTime
month-from-date(date)Extracts months value from an ISO Date
year-from-dateTime(datetime)Extracts year value from an ISO DateTime
year-from-date(date)Extracts year value from an ISO Date

hours-from-dateTime(datetime)

Extracts hours value from an ISO DateTime

hours-from-time(time)

Extracts hours value from an ISO Time

minutes-from-dateTime(datetime)

TExtracts minutes value from an ISO DateTime

minutes-from-time(time)

Extracts minutes value from an ISO Time

seconds-from-dateTime(datetime)Extracts seconds value from an ISO DateTime
seconds-from-time(time)Extracts seconds value from an ISO Time
current-dateTime()Gets current system datetime
current-date()Gets current system date
current-time()Gets current system time
current-dateTime-TZ()Gets current system datetime with timezone
current-date-TZ()Gets current system date with timezone
current-time-TZ()Gets current system time with timezone
toDate(String)Transforms current String in ISO format to a Date
toTime(String)Transforms current String in ISO format to a Time
toDateTime(String)Transforms current String in ISO format to a DateTime
days-from-duration(Duration)

calculates the total number of whole days in a normalized duration value. This is not necessarily the same as the integer that appears before the D in the value. For example, if the duration is P1DT36H, the function returns 2 rather than 1. This is because 36 hours is equal to 1.5 days, and the normalized value is therefore P2DT12H. This function does not round the number of days; if the duration is 2 days and 23 hours, it returns the integer 2.

total-days-from-duration(Duration)Returns the total number of days in Duration. If it is an uneven number of days, it will return a fractional part.
hours-from-duration(Duration)Calculates the hours component of a normalized duration value, as an integer between -23 and 23 (inclusive). This is not necessarily the same as the integer that appears before the H in the value. For example, if the duration is PT1H90M, the function returns 2 rather than 1. This is because 90 minutes is equal to 1.5 hours, and the normalized value is therefore PT2H30M. Likewise, if the duration is PT36H, the result is 12, because the normalized value is P1DT12H.
total-hours-from-duration(Duration)Returns the total number of hours in Duration. If it is an uneven number of hours, it will return a fractional part.
minutes-from-duration(Duration)Calculates the minutes component of a normalized duration value, as an integer between -59 and 59 inclusive. This is not necessarily the same as the integer that appears before the M in the value. For example, if the duration is PT1M90S, the function returns 2 rather than 1. This is because 90 seconds is equal to 1.5 minutes, and the normalized value is therefore PT2M30S. Likewise, if the duration is PT90M, the result is 30, because the normalized value is PT1H30M.
total-minutes-from-duration(Duration)Returns the total number of minutes in Duration;. If it is an uneven number of minutes, it will return a fractional part.
seconds-from-duration(Duration)Calculates the seconds component of a normalized duration value, as a decimal number between -60 and 60 exclusive. This is not necessarily the same as the number that appears before the S in the value. For example, if the duration is PT90S, the function returns 30 rather than 90. This is because 60 of those seconds are considered to be one minute, and the normalized value would therefore be PT1M30S.
total-seconds-from-duration(Duration)Returns the total number of seconds in Duration

4.6. Archetype functions

Table 14. IBIME archetype-based functions

Function

Description

code()atXXXX code from related to where the function is defined
archetypeName()Archetype identifier
text()Text from nearest father in target archetype (default language)
text("atXXXX")Text from selected target archetype node (default language)
text("atXXXX", Lang)Text from selected target archetype node in the selected language
description()Description from nearest father in target archetype (default language)
description("atXXXX")Description from selected target archetype node (default language)
description("atXXXX", Lang)Description from selected target archetype node in the selected language

uuid()

This function generates a unique identifier.

node-id(path)

Returns an unique id calculated from the source structure path

4.7. Ontology query functions

Table 15. IBIME ontology query functions

Function

Description

detDescription(code)

Returns the description of a given ontology code

in(Code, Expression)Evaluates if a given code is contained in the subset defined in the expression

* We moved from dedicated "descendants", "ascendants", etc. to just execute Snomed expressions (in snomed expression syntax)

4.8. Information functions

Table 16. IBIME Information functions

Function

Description

isnull(value)

Value refers to an empty value.

* XQuery contains a generic "instance of" function, so no dedicated "isnumber" or "isstring" is not needed

 

Rules in Archetypes - natural language

Archetypes currently use no language-dependent symbols, other than the adl language keywords ('archetype', 'description', 'definition' etc). But if we add rules in a typical programming language fashion, we get language-dependency, like this:

rules
	$map_value: Real := /data[id2]/events[id7]/data[id4]/items[id1007]/value/magnitude
	$sys_bp_val: Real := /data[id2]/events[id7]/data[id4]/items[id5]/value/magnitude
	$dia_bp_val: Real := /data[id2]/events[id7]/data[id4]/items[id6]/value/magnitude

	mean_arterial_pressure: $map_value = $dia_bp_val + 0.33 * ($sys_bp_val - $dia_bp_val)

	$pulse_pressure_val: Real := /data[id2]/events[id7]/data[id4]/items[id1008]/value/magnitude

	pulse_pressure: $pulse_pressure_val = $sys_bp_val - $dia_bp_val

Here, the variables '$map_value' etc are all in English; so are the assertion tags 'mean_arterial_pressure' and 'pulse_pressure'. To make this language-independent, we would need to do something like this:

rules
	$[rv1]: Real := /data[id2]/events[id7]/data[id4]/items[id1007]/value/magnitude
	$[rv2]: Real := /data[id2]/events[id7]/data[id4]/items[id5]/value/magnitude
	$[rv3]: Real := /data[id2]/events[id7]/data[id4]/items[id6]/value/magnitude

	[rt1]: $[rv1] = $[rv3] + 0.33 * ( $[rv2] - $[rv3] )

	$[rv4]: Real := /data[id2]/events[id7]/data[id4]/items[id1008]/value/magnitude

	[rt2]: $[rv4] = $[rv2] - $[rv3]
 
terminology
	term_definitions = <
		["en"] = <
			...
			["rv1"] = <
				text = <"map_value">
				description = <"MAP value variable">
			>
			["rv2"] = <
				text = <"sys_bp_val">
				description = <"Systolic BP value variable">
			>
			["rv3"] = <
				text = <"dia_bp_val">
				description = <"Diastolic BP value variable">
			>
			["rv4"] = <
				text = <"pulse_pressure_val">
				description = <"Pulse pressure value variable">
			>
			["rt1"] = <
				text = <"mean_arterial_pressure">
				description = <"MAP assertion tag">
			>
			["rt2"] = <
				text = <"pulse_pressure">
				description = <"Pulse pressure assertion tag">
			>

		>
		["es"] = <
			...
		>
	>
	

In this approach, we are adding new kinds of terms 'rv' = rule variable, 'rt' = rule tag. The implication is that textual substitution of 'rv1' by 'map_value' etc would be done in a GUI tool, and optionally before passing the rules text to an evaluator.

This is perhaps overkill - but it does preserve archetype language independence.