Skip to main content
Version: latest

Expressions Reference Guide

This page provides a list of attribute-driven use case expressions that can be used to help you write code expressions required for configuring Profiles, Cohorts, Goals, and Mission Interventions.

When you are configuring Cortex Profile and Campaign elements you must enter attribute expressions that drive system behavior. If these expressions are not written correctly system errors occur. An expression builder is provided to assist you, and this guide can help you make the most of that tool. Additionally expressions can be constructed using JavaScript. This guide shows you both options.

You are required to enter expressions in the following cases:

  • Profile custom attribute expression
  • Cohort group query expression
  • KPI measure expression
  • Goal success condition expression
  • Intervention Pre-condition expression
  • Intervention Effect expression

Use this guide:

  1. Find a use case that most closely mirrors your own for the given element you are configuring.
  2. Copy the expression (either the system provided syntax or JavaScript).
  3. Replace the example attributes with the attributes from your Data Sources.

If you encounter errors when you deploy the mission, revisit your expressions and make sure that they are formatted correctly.

Expression Use Cases


Add attribute values

  • Example: Calculate total loan payback amount, principle plus interest
  • Expression builder syntax:
    principle.plus(interest)
  • JavaScript expression:
    "let patientData = [{loan: 10000, int: 100}, {loan: 20000, int: 200}]
    loanData.map(x => x.loan + x.int)
    output >> [10100, 20200]"

Subtract one attribute value from another

  • Example: Calculate savings, income less expenses
  • Expression builder syntax:
    attributeName1.minus(attributeName2)
  • JavaScript expression:
    "let incomeData = [{income: 10000, expenses: 3000}, {income: 20000, expenses: 7000}]
    data.map(x => x. income - x. expenses)
    output >> [7000, 13000]"

Find an attribute value multiplied by another attribute value

  • Example: Calculate department-wide total salary paid to employees last year
  • Expression builder syntax:
    attributeName.multiply()
  • JavaScript expression:
    "let incomeData = [{department: """"dept1"""",  no_of_employees: 23, avg_salary: 60000}, {department: """"dept2"""",  no_of_employees: 11, avg_salary: 70000}]
    data.map(x => x. no_of_employees * x. avg_salary)
    output >> [1380000, 770000]"

Find an attribute value divided by another attribute value

  • Example: Calculate state-wide per capita income

  • Expression builder syntax:

    attributeName.divide()
  • JavaScript expression:

    "let incomeData = [{state: ""Texas"",  total_income: 1.8 trillion, population: 30000000}, {department: ""Florida"",  total_income: 2.8 trillion,, population: 40000000}];

    incomeData.map(x => x. total_income/x. population)
    output >> [60000, 70000]"

Find attribute values that equal a remainder after integer division with another attribute value

  • Example: Identify phone_numbers ending with with 9

  • Expression builder syntax:

    attributeName.mod(10). equalTo(9)
  • JavaScript expression:

    "let patientData = [{phone_number: 989898989}, {phone_number: 1212121221}];

    patientData.map(x => x. phone%10===9)
    output >> [true, false]"

Find attribute values that are equal to one value or another

  • Example: Determine if a case is either criticalriskcommertial or highriskmedicare

  • Expression builder syntax:

    criticalriskcommercial.or(highriskmedicare)
  • JavaScript expression:

    "let patientData = [{criticalriskcommercial: 1, highriskmedicare: 0}, {criticalriskcommercial: 0, highriskmedicare: 0}];

    patientData.map(x => x. criticalriskcommercial || x. highriskmedicare)
    output >> [true, false]"

Find attribute values that equal a specified value

  • Example: Identify members who have received their flu shots

  • Expression builder syntax:

    attributeName.equalTo(true)

    or

    attributeName.eq(true)
  • JavaScript expression:

    "let patientData = [{has_flu_shot: 1}, {has_flu_shot: 0}];

    patientData.map(x => x. has_flu_shot)
    output >> [true, false]"

Find all attribute values except the specified value

  • Example: Identify members who are NOT part of the Medicare group

  • Expression builder syntax:

    segment.notEqual("Medicare")

    or

    segment.neq("Medicare")
  • JavaScript expression:

    "let segmentList = ['segment1', 'segment2', 'Medicare'];

    patientData.map(x => x !== 'Medicare')
    output >> [true, true, false]"

Return "True" if an attribute is greater than or equal to another

  • Example: Determine if a members flu risk score is greater than or equal to 50%

  • Expression builder syntax:

    attributeName.geq(0.5)

    or

    attributeName.gte(0.5)
  • JavaScript expression:

    "let patientData = [{flu_risk_score: 0.4}, {flu_risk_score: 0.5}];

    patientData.map(x => x. flu_risk_score >= 0.5)
    output >> [false, true]"

Return "True" if an attribute value is less than another

  • Example: Determine if a members flu risk score is less than 50%

  • Expression builder syntax:

    attributeName.lt(0.5)

    or

    attributeName.leq(0.5)
  • JavaScript expression:

    "let patientData = [{flu_risk_score: 0.4}, {flu_risk_score: 0.6}];

    patientData.map(x => x. flu_risk_score <= 0.5)
    output >> [true, false]"

Return "True" if an object exists in the array (i.e. 3.isIn([1,2,3]) == True)

  • Example: Determine if a member is a part of a list of Medicare Members
    • Expression builder syntax:
    segment.isIn(segmentList)
  • JavaScript expression:
    "var segmentList = [""Neil"", ""Sue"", ""Steve""]
    var segment = ""Sue""
    segmentList.includes(segment)
    output >> true
    "

Return "True" if an object does not exist in the array

  • Example: Determine if a member is NOT a part of a list of Medicare members
  • Expression builder syntax:
    segment.isNotIn(segmentList)
  • JavaScript expression:
    "var segmentList = [""Neil"", ""Sue"", ""Steve""]
    var segment = ""Jay""
    !segmentList.includes(segment)
    output >> true
    "

Return "True" if an attribute value object contains a specified object (i.e. "computer".contains("comp") == True //inverse of isIn)**

  • Example: Determine if segmentList has the value 'Medicare'
  • Expression builder syntax:
    segmentList.isNotIn('medicare')
  • JavaScript expression:
    "var computer = ""computer""
    var comp = ""comp""
    computer.includes(comp)
    output >> true"

Return "True" if an attribute value contains a particular data value (boolean and case sensitive)

  • Example: Determine if segmentName ends with 's'

  • Expression builder syntax:

    segment_name.like("%s")
  • JavaScript expression:

    "let patientData = [{name: 'John'}, {name: 'Stokes'}];

    patientData.map(x => x. name.endsWith('s'))
    output >> [false, true]"

Find attribute values that match a specified value

  • Example: Determine if there is any digit in a member id
  • Expression builder syntax:
    id.rlike(".*[0-9].*")
  • JavaScript expression:
    "let patientData = [{id: 'jdsxnx12asas'}, {id: 'ndsajsdsad'}];
    const regex = /.*[0-9].*/gm;
    patientData.map(x => regex.test(x.id));
    output >> [true, false]"

Round floating point attribute values down

  • Example: Round flu-risk_score values to their respective floors

  • Expression builder syntax:

    attributeName.floor()
  • JavaScript expression:

    "let patientData = [{flu_risk_score: 0.4}, {flu_risk_score: 0.6}];

    patientData.map(x => Math.floor(x. flu_risk_score));
    output >> [0, 0]"

Round floating point attribute values up (ie: 5.43.ceil() == 6)

  • Example: Round flu_risk_score values to their respective ceilings

  • Expression builder syntax:

    fattributeName.ceil()
  • JavaScript expression:

    "let patientData = [{flu_risk_score: 0.4}, {flu_risk_score: 0.6}];

    patientData.map(x => Math.ceil(x. flu_risk_score));
    output >> [1, 1]"

Find the natural logarithm (inverse exponential function) of attribute values

  • Example: Used to perform analysis on attribute values
  • Expression builder syntax:
    attributeName.ln()
  • JavaScript expression:
    "Math.log(10)
    output >> 2.302585092994046"

Find the common logarithm of attribute values using base 10 (i.e. The number of times an value must be multiplied by 10 to get a desired value; log10(1000) = 3

  • Example: Determine earthquake intensity on the Richter scale
  • Expression builder syntax:
    attributeName.log10()
  • JavaScript expression:
    "Math.log10(100000)
    output >> 5"

Calculate a logarithmic function of attribute values with a given base as input

  • Example: Find the logarithm value with a given base for some other value, used for perming analysis
  • Expression builder syntax:
    attributeName.log(base)
  • JavaScript expression:
    "Eg- Find log(2, 8):
    Math.log(8)/Math.log(2)
    output >> 3"

Round attribute values to the nearest number (ie: 3.43 = 3, 3.63 = 4)

  • Example: Round the flu_risk_score

  • Expression builder syntax:

    attributeName.round()
  • JavaScript expression:

    "let patientData = [{flu_risk_score: 0.4}, {flu_risk_score: 0.6}];

    patientData.map(x => Math.round(x. flu_risk_score));
    output >> [0, 1]"

Raise a value by an exponent; take a value to the power of r (ie: 2.pow(3) == 8)

  • Example: square of a particular attribute

  • Expression builder syntax:

    attributename.pow()
  • JavaScript expression:

    "Math.pow(x,y)
    Math.pow(2,3)
    output >> 8

    x is the number to be raised to the y power"

Find the average of attribute values

  • Example: The average flu risk score for all members
  • Expression builder syntax:
    attributeName.mean()
  • JavaScript expression:
    "var total = 0;
    for(var i = 0; i < flu_score.length; i++) {
    total += flu_score[i];
    }
    var avg = total / flu_score.length;"

Find the square root of an attribute value

  • Example: Calculate square root of an attribute value
  • Expression builder syntax:
    attributeName.sqrt()
  • JavaScript expression:
    "Math.sqrt(9)
    output >> 3"

Get the attribute value which is greater than a given percentage for a particular attribute

  • Example: Get the flu_score_risk value which is 80% higher than the other flu_score_risk values
  • Expression builder syntax:
    callUDF("percentile", flu_score_risk, 0.8)
  • JavaScript expression:
    "const percentile = (arr, val) =>
    (100 *
    arr.reduce(
    (acc, v) => acc + (v < val ? 1 : 0) + (v === val ? 0.5 : 0),
    0
    )) /
    arr.length;
    percentile([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 6);
    output >> 55"

Get the attribute value which is greater than a given percentage for a particular attribute with a given accuracy

  • Example: Get the flu_score_risk value which is 80% higher than the other flu_score_risk values with 99% accuracy
  • Expression builder syntax:
    callUDF("percentile_approx", flu_score_risk, 0.8, 0.99)
  • JavaScript expression:
    "const percentile = (arr, val) =>
    (100 *
    arr.reduce(
    (acc, v) => acc + (v < val ? 1 : 0) + (v === val ? 0.5 : 0),
    0
    )) /
    arr.length;
    percentile([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 6);
    output >> 55"

Return the number of occurrences of a specified attribute value

  • Example:The count of patients with flu_risk_score of 0.4 or 0.6

  • Expression builder syntax:

    attributeName.count()
  • JavaScript expression:

    "let patientData = [{flu_risk_score: 0.4}, {flu_risk_score: 0.6}];

    patientData.length;
    output >> 2"