Javascript Expressions - erwinwinder/molgenis GitHub Wiki

Introduction

Javascript expressions can be used to define mappings between datasets in the molgenis datamapper and for the 'expression' and 'validationExpression' columns of the EMX 'attributes' sheet.

Syntax

The javascript API offers a simple way to access attribute values of an entity.

Selector

The '$' function returns the attribute value of the current entity. Each script is run within it's own entity context.

Chaining

Methods from this API return an object to which a method can be directly applied. This allow method calls chaining.

Examples

$('gender').isNull().not().value()
$('gender').eq('Female').or($('name').isNull()).value()

Methods

Name Description
$ Returns the attribute value of the current entity.
value Returns the javascript value of the expression.
pow Returns the value raised to the power of the operand.
div Returns result of first operand value divided by second operand value.
age Returns the age if the value is a date
map Uses a lookup table to map ta value to another
eq Returns if left operand value is equal to right operand value.
isNull Returns true if the value is null.
not Returns the logically not of the left operand value.
or Returns the logically or of the left operand value and the right operand value.
gt Returns if left operand value is greater than right operand value.
lt Returns if left operand value is lower than right operand value.
ge Returns if left operand value is greater equal than right operand value.
le Returns if left operand value is lower equal than right operand value.

$

Returns the attribute value of the current entity.

Syntax
$(attributeName)

Parameters
attributeName, the name of the attribute where to retrieve the value for.

Example
$('myAttribute')

value

Returns the javascript value from the expression.

Syntax
value()

Parameters
None

Example
$('myAttribute').value()

pow

Returns the value raised to the power of the argument.

Syntax
pow(power)

Parameters
power, the power to raise the value to.

Example
$('myAttribute').pow(2)

div

Returns result of first operand value divided by second operand value. The operands must be either be of integer or decimal type. The result of the div operations is always of decimal type.

Syntax
div(value)

Parameters
value, he right operand Value.

Example
$('myAttribute').div($('anotherAttribute'))

age

Returns the age in years if the value is a date.

Syntax
age()

Parameters
None

Example
$('myDateAttribute').age()

map

Uses a lookup table to map the a value to another.

Syntax
$('gender').map({key_1:value_1[, key_i:value_i[, ...]]})

Parameters
key_i, the value to be mapped.
value_i, the value to map to.

Example
$('gender').map({1:'Male', 2:'Female'})

eq

Returns if left operand value is equal to right operand value. If either parameters are null, then false is returned. Values must be of type string, int, long or decimal.

Syntax
eq(value)

Parameters
value, the value to compare to.

Example
$('myAttribute').eq($('anotherAttribute'))

isNull

Returns true if the value is null.

Syntax
isNull()

Parameters
None

Example
$('myAttribute').isNull()

not

Returns the contrary of a boolean value.

Syntax
not()

Parameters
None

Example
$('myBooleanAttribute').not()

or

Returns the logically or between the lefthand boolean operand and the righthand boolean operand.

Syntax
or(value)

Parameters
value, boolean expression.

Example
$('myBooleanAttribute').or($('anotherBooleanAttribute'))

gt

Returns if left operand value is greater than right operand value. The operands must be either be of int, long or decimal type.

Syntax
gt(value)

Parameters
value, the Value to be compared to.

Example
$('myAttribute').gt($('anotherAttribute'))

lt

Returns if left operand value is less than right operand value. The operands must be either be of int, long or decimal type.

Syntax
lt(value)

Parameters
value, the Value to be compared to.

Example
$('myAttribute').lt($('anotherAttribute'))

ge

Returns if left operand value is greater than or equal to right operand value. The operands must be either be of int, long or decimal type.

Syntax
ge(value)

Parameters
value, the Value to be compared to.

Example
$('myAttribute').ge($('anotherAttribute'))

le

Returns if left operand value is less than or equal to the right operand value. The operands must be either be of int, long or decimal type.

Syntax
le(value)

Parameters
value, the Value to be compared to.

Example
$('myAttribute').le($('anotherAttribute'))