Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Table of Contents
minLevel1
maxLevel6
outlinefalse
typelist
printablefalse
separatorbrackets

...

Info

Note

  • We do not recommend storing any calculated field values since it is duplicate information.

  • You can configure the code in JSON workflow within the 'Dictionary' section.

Example 1: Display participant concatenated first name and last name

...

Example 18: Calculating the months remaining after counting the completed years

Expand
Code Block
{
  "name": "calcCpr.birthDate",
  "displayExpr": "(fns.dateDiffInDays(cpr.participant.birthDate, fns.now()) / 365 * 12 -fns.ageInYears(cpr.participant.birthDate, fns.now()) * 12).toFixed(0) + ' months'",
  "caption": "Age",
  "type": "span"
},

...

Expand
Code Block
      "name" : "calcCpr.cohort",
      "displayExpr" : "consents.consentSignatureDate > 1502841600000 && consents.consentSignatureDate < 1582588800000 ? 'Cohort 1' : (consents.consentSignatureDate > 1582675200000 && consents.consentSignatureDate < 1672531200000 ? 'Cohort 2' : (consents.consentSignatureDate > 1672617600000 ? 'Cohort 3' : 'Unknown'))",
      "caption" : "Cohort",
      "type" : "span"
    }

  • image-20240215-142634.png

Example 20: Calculating the Field based on Custom Number field divided by user input value.

Expand
Code Block
{
      "name" : "calcSpecimen.numberField",
      "displayExpr" : "fns.ifNotNull(specimen.extensionDetail.attrsMap.number1,((+specimen.extensionDetail.attrsMap.number1)/100), 'Not Specified')",
      "caption" : "Divided Cal Field",
      "type" : "span"
    },

image-20240306-044650.pngImage Added

Inbuilt Functions

Expand
Note

Note: Currently, the only collection and received event fields can be used for calculated fields. Fields of other events cannot be used.

Function

Description

fns.ifNull(cond, 'truthValue', 'falseValue')

Returns truthValue when 'cond' is evaluated to either null or undefined. Otherwise, it returns falseValue.

fns.ifNotNull(cond, 'truthValue', 'falseValue')

Returns truthValue when 'cond' is evaluated to non-null or a defined value. Otherwise, it returns falseValue.

fns.concatList(coll, expr, separator)

Concatenates the elements of the collection 'coll' and joins them using the input 'separator'. e.g. fns.concatList(persons, "\'firstName\' + ' ' + \'lastName\'", ",") yields Virat Kohli, Dhanraj Pillay, Atul Bedade

fns.concat(varargs)

Concatenates input arguments using the separator ' '

fns.minValue(coll, expr)

Returns the min value of the 'expr' in the input collection 'coll'

fns.toDateStr(dateObj, [fmt])

Returns date string in locale format or requested format 'fmt'

fns.toDateTimeStr(dateObj, [fmt])

Returns date-time string in locale format or requested format 'fmt'

fns.now() fns.currentTime()

Returns current time in number of milliseconds elapsed since Epoch.

fns.dateDiffInYears(d1, d2)

Returns the number of completed years between d1 and d2.

fns.ageInYears(d1)

Convenience function, which is equivalent to fns.dateDiffInYears(d1, fns.now())

fns.dateDiffInDays(d1, d2)

Returns the number of completed days between d1 and d2.

fns.dateDiffInMinutes(d1, d2)

Returns the number of minutes elapsed between d1 and d2 where d1 < d2

fns.dateDiffInSeconds(d1, d2)

Returns the number of seconds elapsed between d1 and d2 where d1 < d2

fns.split(str, regex) 

Returns an array of substrings that are delimited by the regex in the input string.

fns.join(strArray, separator)

Returns concatenation of array of substrings delimited by the separator.

...