Survey Engine Expressions
Expression is a a general concept used in several places of the Influenzanet Survey System. Before reading this page you should read the general concept of expressions.
Logical Expression
Logical expressions evaluate the logical operations using boolean result of one or several expression evaluated value. Each expression argument is evaluated and casted as boolean
- Numerical result :
true
if > 0, andfalse
if <= 0 - String result :
true
if not empty,false
if empty (=='')
Several operators are available:
and
(e1, e2) : AND operator (true
if e1 istrue
AND if e2 istrue
)or
(e1, e2) : OR operator (true
if e1 istrue
OR if e2 istrue
)not
(e1): NOT operator (true
if e1 isfalse
,false
if e1 istrue
)
Comparison operators
eq
(e1, e2, ..., en) : Equal operator, true if all operators are equals, if e1 === e2 (... === en)gt
(e1, e2) : Greater than operator (true if e1 > e2)gte
(e1, e2) : Greater or equal operator (true if e1 >= e2)lt
(e1, e2) : Lower than operator (true if e1 < e2)lte
(e1, e2) : Lower or Equal operator (true if e1 <e; e2)
Nota: The Javascript implementation uses the '===' operator, checking for value AND type for equality.
Only onlineUtilities
isDefined
()
isDefined Operator test if an expression returns a defined value (i.e. the value is not undefined
nor null
for javascript engine).
getContext
()
getContext returns the current Runtime Context, allowing to get Participant attributes
getAttribute
(object, name)
Extract a attribute from an object
This is a low level function Common case is to extract attribute from the context, to check for a Participant flag.
Only onlineFortunately CASE Editor Tools provides some helpers to generate such complex expressions
Only onlineResponses expressions
These expressions are used to get and test the current survey responses.
hasResponse
(item_key, rg_key):boolean
Check if an item has a specific response object (by key)
item_key
: key of the item (question)rg_key
: path of the response component from the root in the question
getResponseValueAsNum
(item_key, rg_key):number
Get the response value of an Response component of an Item, and parse it as numeric value
item_key
: key of the item (question)rg_key
: path of the response component in the item.
getResponseValueAsStr
(item_key, rg_key): string
Get the response value of an Response component of an Item as a string
item_key
: key of the item (question)rg_key
: path of the response component in the item.
responseHasKeysAny
(item_key, rg_key, option_key...):boolean
Test if the response component of a item as any response key from the option_key list of value. This expression is used to test if the current response of a categorical component have at least one response in a given list options are identified by their key value.
item_key
: key of the item (question)rg_key
: path of the response component in the item.- option_key... : one or several key of option
responseHasKeysAll
(item_key, rg_key, option_key...):boolean
Same as responseHasKeysAny
, but test if the current response include all the provided option key
For example, if the question intake.Q1 has the current response 'cat' AND 'dog'
Only onlineresponseHasOnlyKeysOtherThan
(item_key, rg_key, option_key...):boolean
Same as responseHasKeysAny
, but test if the current response DOES NOT include any option key in the provided list
checkResponseValueWithRegex
(item_key, rg_key, pattern ):boolean
Check if the response of an item match a the given Regular Expression pattern. The pattern is using Javascript ECMAScript Regular Expression
Only onlinecountResponseItems
(item_key, rg_key):number
Count the number of responses selected in a Response component of an item.
If the item is not found or no response is provided yet, the expression will return -1 value.
Validation
getSurveyItemValidation
(item_key, validation_key)
Time functions
timestampWithOffset
(offset, refTime)
offset
is the number of seconds to add to the reference timerefTime
is the reference time (if not provided the current time will be used)
Both are evaluated to number but they can be expressions.
Only onlinegetSecondsSince
(time):number
Returns the number of seconds from the given time and the current time.
time must be evaluated to a Unix timestamp (number of seconds since 1970-01-01), it can be an expression returning the timestamp (Date and time response component returns response as timestamp value)
dateResponseDiffFromNow
(item_key, rg_key, ?unit, ?unsigned)
Evaluate time difference from now using response of an item
item_key
: key of the item (question)rg_key
: path of the response component from the root in the question (always starts with 'rg.' representing the Response Group Component)unit
: time unit to use as output, accepted values are 'years', 'months', 'weeks', 'hours', 'minutes', 'seconds'unsigned
: flag to have a unsigned result (ignore sign of the result) if the value is evaluated to true (e.g. 1), otherwise result can output negative value.
Low level expression
Most of the time you wont need these expression, but in some case it's necessary to use them.
getResponses
()
getRenderedItems
()
getArrayItemAtIndex
()
getArrayItemByKey
()
getObjByHierarchicalKey
()
getNestedObjectByKey
()
findPreviousSurveyResponsesByKey
()
getLastFromSurveyResponses
()
getPreviousResponses
()
filterResponsesByIncludesKeys
()
filterResponsesByValue
()
getLastFromSurveyItemResponses
()
getResponseItem
()
parseValueAsNum
(value):number
Evaluate the argument value (can be an expression), and parse it to number