Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

This section includes a number of commonly used EDC formulas.


Panel
bgColor#C0B6F2

Any formula that returns a value of TRUE or FALSE will be indicated with a 1 or 0 respectively in the report.

Panel
bgColor#B3D4FF

Average

The

‘Average’

average formula is used to average all

responses

values for any given question.

Formula parameters include:
  1. Question Name

  2. Precision of Calculation (optional, but required if a third parameter is added)

  3. Type of Average (optional, but required if more parameters are added)

Panel
bgColor#DEEBFF

1 → Average all the values
2 → Average last n days (4th parameter is required of type number of days)
3 → Average n days starting from a specific date (4th parameter is number of days, 5th parameter is a date value)
4 → Average n days ending on a specific date (4th parameter is number of days, 5th parameter is date value)
5 → Average last n responses (4th parameter is number of responses)
6 → Average n responses starting from a specific date (4th parameter is number of responses, 5th parameter is date)
7 → Average n responses end on a specific date (4th parameter is number of responses, 5th parameter is date)
8 → Average since specific date (4th parameter is date)
9 → Average until a specific date (4th parameter is date)
10 → Average between start date and end date (4th parameter is a date and 5th parameter is a date)

  1. Based on the option selected in 3rd parameter (may or may not be required)

  2. Based on the option selected in 3rd parameter (may or may not be required)

Note: If the 3rd parameter is part of the function call, then the corresponding parameters corresponding to that option become necessary.

Example:

Image Removed

Panel
bgColor#B3D4FF

Iff

The ‘Iff’ formula is used to evaluate a certain condition and then further evaluate a formula based on how the condition is evaluated. Parameters include:

The “Iff” formula is used to evaluate a condition as TRUE/FALSE. Based on that evaluation, a value is assigned to the Calculated Field. Parameters include:

Code Block
Iff({Condition to check},"Value if TRUE","Value if FALSE")
Parameter 1. {Condition to check}
Parameter 2. "Value if TRUE"
Parameter 3. "Value if FALSE"
  1. Condition to check - a boolean equation that should result in a value of TRUE or FALSE

  2. Value if TRUE - the value the Calculated Field Question will be if the Condition to check is TRUE

  3. Value if FALSE - the value the Calculated Field Question will be if the Condition to check is FALSE

Examples

  • Iff((14 - 7) > 0, DateDiff('today', ‘yesterday', ‘h'), 50 / 2)

    • The “Condition to check” is “(14 - 7) > 0”

    • The “Value if TRUE” is “DateDiff(’today’, ‘yesterday’, 'h')” which is 24

    • The “Value if FALSE” is “50 / 2” which is 25

    • Since (14 - 7) > 0 is TRUE, the value assigned to the Calculated Field Question will be 24

  • Iff([RadioQ1] > 0, [RadioQ1] < 3, FALSE)

    • The “Condition to check” is “[RadioQ1] > 0”

    • The “Value if TRUE” is “[RadioQ1] < 3” which will be TRUE/FALSE depending on the value of [RadioQ1]

    • The “Value if FALSE” is “FALSE”

    • The table below will show what the Calculated Field Question value will be based on the value of [RadioQ1]

[RadioQ1] Value

Calculated Field Question Value

Reasoning

0

FALSE

Since [RadioQ1] = 0, then the “Condition to check” equates to FALSE since 0 is not greater than 0. Since it is FALSE, the “Value if FALSE” will be assigned to the Calculated Field Question, which is FALSE.

1

TRUE

The “Condition to check” will equate to TRUE since 1 is greater than 0. Since it is TRUE, the “Value if TRUE” will be assigned to the Calculated Field Question.

Since [RadioQ1] = 1, then the “Value if TRUE” will equal TRUE since 1 is less than 3. Therefore, the Calculated Field Question will be assigned a value of TRUE.

2

TRUE

The “Condition to check” will equate to TRUE since 2 is greater than 0. Since it is TRUE, the “Value if TRUE” will be assigned to the Calculated Field Question.

Since [RadioQ1] = 2, then the “Value if TRUE” will equal TRUE since 2 is less than 3. Therefore, the Calculated Field Question will be assigned a value of TRUE.

3

FALSE

The “Condition to check” will equate to TRUE since 3 is greater than 0. Since it is TRUE, the “Value if TRUE” will be assigned to the Calculated Field Question.

Since [RadioQ1] = 3, then the “Value if TRUE” will equal FALSE since 3 is NOT less than 3. Therefore, the Calculated Field Question will be assigned a value of FALSE.

  • Iff(Contains([QuestionOne], 2), 1, 0)

    • The “Condition to check” is “Contains([QuestionOne],2)”

    • The “Value if TRUE” is 1

    • The “Value if FALSE” is 0

    • If the participant included option value 2 in checkbox question [QuestionOne], then the “Condition to check” equates to TRUE and the “Value if TRUE” will be assigned to the Calculated Field Question, which is 1.

    • If the participant didn’t include option value 2 in checkbox question [QuestionOne], then the “Condition to check” equates to FALSE and the “Value if FALSE” will be assigned to the Calculated Field Question, which is 0.

Panel
bgColor#B3D4FF

DateDiff

The ‘DateDiff’ formula is used to evaluate the difference between two Dates or two Times. Parameters include:

  1. The Date or Time from which the other date will be subtracted from.

  2. The Date or Time that will be subtracted from the first parameter.
    For the above two parameters, the date can be optionally specified as the following strings:
    'now' → Date and time at the moment logic is evaluated
    'today' → Date on which the formula is evaluated
    'yesterday' → Yesterday’s date (no time component)
    'tomorrow' → Tomorrow’s date (no time component)

  3. The format in which the result is required.
    The format can be:
    'd' → total days
    'h' → total hours
    'm' → total minutes
    's' → total seconds

Examples:

  • DateDiff('yesterday', ‘now', ‘m')
    This calculates the total minutes between yesterday’s date (parameter 1) and the date and time for right now (parameter 2).
    If yesterday's date is 07/10/2023 and we are evaluating this function for 07/11/2023 at 4:07p.m. then the results (in minutes) should look like: ‘yesterday’ (Parameter 1) minus ‘now’ (Parameter 2) = -2407.5039294216667

Using DateDiff to change stages:

  • When do I use DateDiff to change stages?

    • DateDiff can be used when you want to change to the next stage after a certain amount of time has elapsed and after the date question has been answered.

The following scenario can be interpreted as such:

Stage Name

Question Name

Question Type

Question Text

Response

StartStudy

nextstage

Radio

Would you like to start the study?

Yes = 1
No = 2

Baseline

pmpiq23

Radio

I like that nobody can tell when I am using a mobile phone intervention.

Strongly disagree = 1
Disagree = 2
Disagree a little = 3
Neither agree nor disagree = 4
Agree a little = 5
Agree = 6
Strongly agree = 7

Baseline

study_startdate

Date

Please select today’s date…

PT enters date on phone:
04/17/2024

The Formula Based “StartStudy” stage contains an assessment that includes a radio question type named “nextstage” and when answered with “yes”, it will transition to the “Baseline” stage.

The Formula Based “Baseline” stage contains a baseline assessment that includes a radio question type named “pmpiq23” and when answered (since all responses are greater than 0) will transition to the “FinalStage”. However, if the baseline assessment is not answered within 3 days (as shown in the example below), then the stage transition from “Baseline” to “FinalStage” will still occur.

The “FinalStage” stage is Time Based and will only be active for 1 day (24 hours) since the stage does not end at midnight.

image-20240417-180836.pngImage Removeddatediff('today', [study_startdate],'d')>=3

Current Date

Question Variable

Result

Interpretation

today = 04/17/2024

study_startdate = 04/17/2024

0

False - stays in the current stage

today = 04/17/2024

study_startdate = 04/12/224

5

True - transitions to next stage

Panel
bgColor#B3D4FF

Contains

The ‘Contains’ formula is a TRUE/FALSE statement used to check if a particular option was selected in a checkbox question type. In CMS (platform v1), the way to do that is to write something like this: [checkboxq(value)] == 1. This has been changed up in V2. The new formula to check if a checkbox contains a specific value is:

Contains([questionName], 2)

This formula accepts two parameters:

  1. The variable/question name

  2. The value to check

Examples:

  • Contains([CheckboxQ1], 3)
    The formula will get the last response(s) for the question “CheckboxQ1” and check if ‘3' was one of them. If ‘3’ was one of them the logic will return TRUE and if '3’ was not one of them the logic will return FALSE.

Panel
bgColor#B3D4FF

Checkbox Syntax

Checkbox syntax from CMS is now supported. [CheckboxQuestion(1)] will result in 0 if the option with value “1” was not selected by participant and vice versa. This syntax doesn’t support default value format such as [RadioQuestion:-999] (which will result in a default value of -999 if no value was found for the question “RadioQuestion”]

Panel
bgColor#B3D4FF

ResponseExists/Exists

This formula is used to check if a particular question has been recorded in the Database with a response or not. This formula accepts one parameter which is the question name. The formula returns true if a response was found and false if a response was not found.

Example

  • ResponseExists([RadioQ])

  • Exists([RadioQ])

Panel
bgColor#B3D4FF

Last

Automatically returns the most recent response value when the variable name is put within brackets [ ] .

Panel
bgColor#B3D4FF

Default Values

Default values (applied when a response for a question cannot be found) can be defined in the declaration of question name followed by a colon “:”.

Examples:

  • [colorblue:-1] → Value assumed for the variable “colorblue” is -1 if no response found in the database.

  • [study_startdate:2100-01-01] → Value assumed for the variable “study_startdate” is 2100-01-01 if not value found.

  • [RadioQ1:0] → If no response found, the value for “RadioQ1” is assumed to be 0.

If no colon (:) is used, the following default values are used for the question types listed under them.

-999

  • Dropdown

  • Radio

  • Slider

  • RandomNumberGenerator

  • Video

Empty String

  • Text Field

  • Text Area

1970-01-01 00:00:00

  • Date

  • Time

Panel
bgColor#B3D4FF

Display PHI information

If a study is collecting PHI from participants, the information provided can be used to curate RichText and Email questions as desired. The table below shows what to use for each of the PHI fields offered in the EDC

EDC PHI Field

RichText/Email format

First Name

{{Personalization.FirstName}}

Middle Name

{{Personalization.MiddleName}}

Last Name

{{Personalization.LastName}}

Street Address

{{Personalization.AddressLn1}}

Apartment Number

{{Personalization.AddressLn2}}

City

{{Personalization.City}}

State

{{Personalization.State}}

Zip Code

{{Personalization.ZipCode}}

Country

{{Personalization.Country}}

Cell Number
(International code and phone number)

{{Personalization.CellPhoneIntlCode}}
{{Personalization.CellPhone}}

Work Number
(International code and phone number)

{{Personalization.WorkPhoneIntlCode}}
{{Personalization.WorkPhone}}

Home Number
(International code and phone number)

{{Personalization.HomePhoneIntlCode}}
{{Personalization.HomePhone}}

Email

{{Personalization.Email}}

Ethnicity

{{Personalization.Ethnicity}}

This could be useful if a study needs to keep a mailing address up to date to display what the current address is, and if it needs to be changed, the participant’s response can be emailed to researchers to update the PHI for that participant.

Payments

In the event of no response given for a question, it is not included in the average calculation.

Code Block
Average({Variable Name}, "Decimal point precision", "Average Type", 
      "Varied parameter based on Average Type", "Varied parameter based on Average Type")
Parameter 1. {Variable Name}
Parameter 2. "Decimal point precision"
Parameter 3. "Average Type"
Parameter 4 & 5. "Varied parameter based on Average Type"
  1. {Variable Name} - required parameter to find and average values

  2. “Decimal point precision” - optional, but required if an average type is specified

  3. “Average Type” - optional; explained below

  4. “Varied parameter based on Average Type” - required based on average type parameter

Average Types

Below are explanations of each average type. The decimal point precision (parameter 2) will be 3, but it can be any number needed for your study.

  1. Average all response values

    1. Average([VariableName])

    2. Average([VariableName], 3)

    3. Average([VariableName], 3, 1)

      1. If using example a, the decimal point precision is defaulted to 2.

  2. Average last n days

    1. Average([VariableName], 3, 2, n)

      1. Parameter 4 specifies n number of days

  3. Average n days starting from a specific date

    1. Average([VariableName], 3, 3, n, ‘Date’)

      1. Parameter 4 specifies n number of days

      2. Parameter 5 specifies a start date. This can be in ‘YYYY-MM-DD’ notation or a Date question.

  4. Average n days ending on a specific date

    1. Average([VariableName], 3, 4, n, ‘Date’)

      1. Parameter 4 specifies n number of days

      2. Parameter 5 specifies an end date. This can be in ‘YYYY-MM-DD’ notation or a Date question. The responses recorded on this date are EXCLUDED from the calculation.

  5. Average last n responses

    1. Average([VariableName], 3, 5, n)

      1. Parameter 4 specifies n number of responses

  6. Average n responses starting from a specific date

    1. Average([VariableName], 3, 6, n, ‘Date’)

      1. Parameter 4 specifies n number of responses

      2. Parameter 5 specifies a start date. This can be in ‘YYYY-MM-DD’ notation or a Date question.

  7. Average n responses ending on a specific date

    1. Average([VariableName], 3, 7, n, ‘Date’)

      1. Parameter 4 specifies n number of responses

      2. Parameter 5 specifies an end date. This can be in ‘YYYY-MM-DD’ notation or a Date question. The responses recorded on this date are EXCLUDED from the calculation.

  8. Average since a specific date

    1. Average([VariableName], 3, 8, ‘Date’)

      1. Parameter 4 specifies a start date. This can be in ‘YYYY-MM-DD’ notation or a Date question.

  9. Average until a specific date

    1. Average([VariableName], 3, 9, ‘Date’)

      1. Parameter 4 specifies an end date. This can be in ‘YYYY-MM-DD’ notation or a Date question. The responses recorded on this date are EXCLUDED from the calculation.

  10. Average between a specified start and end date

    1. Average([VariableName], 3, 10, ‘Start Date’, ‘End Date’)

      1. Parameter 4 specifies a start date. This can be in ‘YYYY-MM-DD’ notation or a Date question.

      2. Parameter 5 specifies an end date. This can be in ‘YYYY-MM-DD’ notation or a Date question. The responses recorded on this date are EXCLUDED from the calculation.

Suppose there’s a study that wants to check a participant’s average cigarette use after 20 days. The following table contains responses recorded in the dropdown question [CigarettesSmoked] over 20 days.

[CigarettesSmoked] = Dropdown question

How many cigarettes did you smoke?

0-10+

Date

Value(s) reported

Date

Value(s) reported

04/03/2024

6, 4, 5, 3, 1

04/13/2024

2, 2, 2, 2

04/04/2024

5, 7, 3, 1, 1

04/14/2024

3, 1, 2

04/05/2024

0, 4, 3, 6, 3

04/15/2024

2, 5

04/06/2024

0, 5, 6

04/16/2024

3, 3, 3, 2

04/07/2024

10, 1, 0, 1

04/17/2024

5

04/08/2024

6, 3, 4

04/18/2024

04/09/2024

04/19/2024

04/10/2024

0

04/20/2024

1, 3, 4

04/11/2024

3, 2, 2

04/21/2024

3, 2

04/12/2024

1, 2

04/22/2024

1

Average Type 1: Average all response values

  1. Average([CigarettesSmoked]) = 2.92

  2. Average([CigarettesSmoked], 5) = 2.9157

  3. Average([CigarettesSmoked], 3, 1) = 2.922

This average type will give the total average all recorded responses.

For this study, we may want to get the total average as a comparison for the participant, maybe to provide a monetary incentive or encouraging message for smoking less in a later part of the study.

Average Type 2: Average last n days

Date 04/07/2024: Average([CigarettesSmoked], 3, 2, 5) = 3.409
Date 04/12/2024: Average([CigarettesSmoked], 3, 2, 5) = 2.556
Date 04/17/2024: Average([CigarettesSmoked], 3, 2, 5) = 2.643
Date 04/22/2024: Average([CigarettesSmoked], 3, 2, 5) = 2.333

This average type will average all recorded values a number of days from the day it’s calculating.

For this study, we may want to get an average every 5 days as a way to measure the participant’s progress.

Average Type 3: Average n days starting from a specific date

[QuitDate] = 04/08/2024

Average([CigarettesSmoked], 3, 3, 7, [QuitDate]) = 2.313

This average type can be used to specify an average a number of days after the specified date.

For this study, we may want to see if a week after the participant specified a Quit Date if their average cigarette usage is lower than their total average. which could be used to add a bonus monetary incentive.

Average Type 4: Average n days ending on a specific date

Average([CigarettesSmoked], 3, 4, 7, [QuitDate]) = 3.409

This Average Type will average all values a number of days prior to the specified date. Remember that this average will exclude all values recorded on the specified date from the calculation.

For this study, we may want to get a baseline average of how many cigarettes the participant smoked prior to their specified Quit Date. We can use this value as a general guideline for the participant’s progress on smoking less or compare their average towards the end of the stage/study to the beginning.

Average Type 5: Average last n responses

Date 04/08/2024: Average([CigarettesSmoked], 3, 5, 13) = 3.692
Date 04/15/2024: Average([CigarettesSmoked], 3, 5, 13) = 2.154
Date 04/20/2024: Average([CigarettesSmoked], 3, 5, 13) = 2.846

This average type is similar to Average Type 2, but instead of specifying the number of days, it specifies the number of responses for the total average.

For this study, we may want to check the average number of cigarettes the participant reports smoking. In this case, we may want this calculation to go off randomly using a Random Number Generator question to trigger this calculation in the assessment.

Average Type 6: Average n responses starting from a specific date

Average([CigarettesSmoked], 3, 6, 25, [QuitDate]) = 2.56

This average type is similar to Average Type 3, but instead of specifying the number of days, it specifies the number of responses for the total average.

For this study, we may want to get an average based on the responses in order to get an idea of how many cigarettes the participant will report when they answer this question.

Average Type 7: Average n responses ending on a specific date

Average([CigarettesSmoked], 3, 7, 15, [QuitDate]) = 2.933

This average type is similar to Average Type 4, but instead of specifying the number of days, it specifies the number of responses for the total average.

Note

Remember that recorded responses made on this date are not considered part of the average calculation.

For this study, we may want to get an idea of how many cigarettes the participant typically reported prior to their quit date.

Average Type 8: Average since specific date

[MidDate] = 04/13/2024

Average([CigarettesSmoked], 3, 8, [MidDate]) = 2.55

This average type will take the total average starting on a date up to the most recent response entered.

For this study, we may want to find the average cigarettes smoked reported after the midpoint of the study and compare it to the average before the midpoint.

Average Type 9: Average until a specific date

Average([CigarettesSmoked], 3, 9, [MidDate]) = 3.161

This average type will take the total average starting on the first recorded response up to the specified date.

Note

Remember that recorded responses made on this date are not considered part of the average calculation.

For this study, we may want to find the average cigarettes smoked reported before the midpoint of the study and compare it to the average after the midpoint.

Average Type 10: Average between a specified start and end date

Average([CigarettesSmoked], 3, 10, [QuitDate], [MidDate]) = 2.556

This average type will take the total average from the start date up to the quit date.

Note

Remember that recorded responses made on the end date are not considered part of the average calculation.

For this study, we may want to check if the participant is on a downward trend from their Quit Date up to the Mid Date. This can be used to predict if the participant will be successful in reducing their smoking habit.

Panel
bgColor#B3D4FF

Iff

The ‘Iff’ formula is used to evaluate a certain condition and then further evaluate a formula based on how the condition is evaluated. Parameters include:

The “Iff” formula is used to evaluate a condition as TRUE/FALSE. Based on that evaluation, a value is assigned to the Calculated Field. Parameters include:

Code Block
Iff({Condition to check},"Value if TRUE","Value if FALSE")
Parameter 1. {Condition to check}
Parameter 2. "Value if TRUE"
Parameter 3. "Value if FALSE"
  1. Condition to check - a boolean equation that should result in a value of TRUE or FALSE

  2. Value if TRUE - the value the Calculated Field Question will be if the Condition to check is TRUE

  3. Value if FALSE - the value the Calculated Field Question will be if the Condition to check is FALSE

Examples

  • Iff((14 - 7) > 0, DateDiff('today', ‘yesterday', ‘h'), 50 / 2)

    • The “Condition to check” is “(14 - 7) > 0”

    • The “Value if TRUE” is “DateDiff(’today’, ‘yesterday’, 'h')” which is 24

    • The “Value if FALSE” is “50 / 2” which is 25

    • Since (14 - 7) > 0 is TRUE, the value assigned to the Calculated Field Question will be 24

  • Iff([RadioQ1] > 0, [RadioQ1] < 3, FALSE)

    • The “Condition to check” is “[RadioQ1] > 0”

    • The “Value if TRUE” is “[RadioQ1] < 3” which will be TRUE/FALSE depending on the value of [RadioQ1]

    • The “Value if FALSE” is “FALSE”

    • The table below will show what the Calculated Field Question value will be based on the value of [RadioQ1]

[RadioQ1] Value

Calculated Field Question Value

Reasoning

0

FALSE

Since [RadioQ1] = 0, then the “Condition to check” equates to FALSE since 0 is not greater than 0. Since it is FALSE, the “Value if FALSE” will be assigned to the Calculated Field Question, which is FALSE.

1

TRUE

The “Condition to check” will equate to TRUE since 1 is greater than 0. Since it is TRUE, the “Value if TRUE” will be assigned to the Calculated Field Question.

Since [RadioQ1] = 1, then the “Value if TRUE” will equal TRUE since 1 is less than 3. Therefore, the Calculated Field Question will be assigned a value of TRUE.

2

TRUE

The “Condition to check” will equate to TRUE since 2 is greater than 0. Since it is TRUE, the “Value if TRUE” will be assigned to the Calculated Field Question.

Since [RadioQ1] = 2, then the “Value if TRUE” will equal TRUE since 2 is less than 3. Therefore, the Calculated Field Question will be assigned a value of TRUE.

3

FALSE

The “Condition to check” will equate to TRUE since 3 is greater than 0. Since it is TRUE, the “Value if TRUE” will be assigned to the Calculated Field Question.

Since [RadioQ1] = 3, then the “Value if TRUE” will equal FALSE since 3 is NOT less than 3. Therefore, the Calculated Field Question will be assigned a value of FALSE.

  • Iff(Contains([QuestionOne], 2), 1, 0)

    • The “Condition to check” is “Contains([QuestionOne],2)”

    • The “Value if TRUE” is 1

    • The “Value if FALSE” is 0

    • If the participant included option value 2 in checkbox question [QuestionOne], then the “Condition to check” equates to TRUE and the “Value if TRUE” will be assigned to the Calculated Field Question, which is 1.

    • If the participant didn’t include option value 2 in checkbox question [QuestionOne], then the “Condition to check” equates to FALSE and the “Value if FALSE” will be assigned to the Calculated Field Question, which is 0.

This formula can be used in any number of ways needed for a study which include, but is not limited to:

  • Trigger calculations dependent on participant responses

  • Save a specific value to display a question later on

  • Save a specific value to trigger the end of a stage

Panel
bgColor#B3D4FF

DateDiff

The ‘DateDiff’ formula is used to evaluate the difference between two Dates or two Times. Parameters include:

Code Block
DateDiff({Date/Time Minuend}, {Date/Time Subtrahend}, 'Unit difference')
Parameter 1. {Date/Time Minuend}
Parameter 2. {Date/Time Subtrahend}
Parameter 3. 'Unit difference'
  1. Date/Time Minuend - The Date or Time from which the other date will be subtracted from.

  2. Date/Time Subtrahend - The Date or Time that will be subtracted from the first parameter.

  3. Unit Difference - The format in which the difference is required.
    The format can be:
    'd' → total days
    'cd' → calendar days
    'h' → total hours
    'm' → total minutes
    's' → total seconds

The difference between total days ‘d' and calendar days ‘cd’ is that ‘cd’ does not take into account the time difference. e.g. [date1] = ‘2024-07-31 11:35:22 PM’ and [date2] = ‘2024-08-01 12:15:17 AM’

DateDiff([date2], [date1], ‘d') = 0.2772
DateDiff([date2], [date1], 'cd’) = 1

Parameter 1 and Parameter 2 can have a manually input date or time following this format:
Date - ‘yyyy-MM-dd’ (example: 2024-08-17)
Time - ‘HH:mm:ss’ (example: 17:15:32)

They can also have a Date or Time variable as the input as well as the following key words:
'now' → Date and time at the moment logic is evaluated
'today' → Date on which the formula is evaluated
'yesterday' → Yesterday’s date
'tomorrow' → Tomorrow’s date

For the ‘today’, ‘yesterday’, and ‘tomorrow’ key words, the Time component is defaulted to midnight, 00:00:00.

I.E. if today is 05/01/2024 12:39:42 PM, then:

Keyword

Date

Time

Date and Time

‘now’

‘2024-05-01’

‘12:39:42’

‘2024-05-01 12:39:42’

‘today’

‘2024-05-01’

‘00:00:00’

‘2024-05-01 00:00:00’

‘yesterday’

‘2024-04-30’

‘00:00:00’

‘2024-04-30 00:00:00’

‘tomorrow’

‘2024-05-02’

‘00:00:00’

‘2024-05-02 00:00:00’

Examples:

  • DateDiff('yesterday', ‘now', ‘m')
    This calculates the total minutes between yesterday’s date (parameter 1) and the date and time for right now (parameter 2).
    If yesterday's date is 07/10/2023 and we are evaluating this function for 07/11/2023 at 4:07p.m. then the results (in minutes) should look like: ‘yesterday’ (Parameter 1) minus ‘now’ (Parameter 2) = -2407.5039294216667

Using DateDiff to change stages:

  • When do I use DateDiff to change stages?

    • DateDiff can be used when you want to change to the next stage after a certain amount of time has elapsed and after the date question has been answered.

The following scenario can be interpreted as such:

Stage Name

Question Name

Question Type

Question Text

Response

StartStudy

nextstage

Radio

Would you like to start the study?

Yes = 1
No = 2

StartStudy

study_startdate

Date

Please select today’s date…

PT enters date on phone:
04/17/2024

Baseline

pmpiq23

Radio

I like that nobody can tell when I am using a mobile phone intervention.

Strongly disagree = 1
Disagree = 2
Disagree a little = 3
Neither agree nor disagree = 4
Agree a little = 5
Agree = 6
Strongly agree = 7

The Formula Based “StartStudy” stage contains an assessment that includes a radio question type named “nextstage” and when answered with “yes”, it will transition to the “Baseline” stage.

The Formula Based “Baseline” stage contains a baseline assessment that includes a radio question type named “pmpiq23” and when answered (since all responses are greater than 0) will transition to the “FinalStage”. However, if the baseline assessment is not answered within 3 days (as shown in the example below), then the stage transition from “Baseline” to “FinalStage” will still occur.

The “FinalStage” stage is Time Based and will only be active for 1 day (24 hours) since the stage does not end at midnight.

image-20240417-180836.pngImage Added


datediff('today', [study_startdate],'d')>=3

Current Date

Question Variable

Result

Interpretation

today = 04/17/2024

study_startdate = 04/17/2024

0

False - stays in the current stage

today = 04/22/2024

study_startdate = 04/17/224

5

True - transitions to next stage

Panel
bgColor#B3D4FF

Contains

The ‘Contains’ formula is a TRUE/FALSE statement used to check if a particular option was selected in a checkbox question type.

Code Block
Contains({Checkbox Question},'Response Value to check')
Parameter 1. {Checkbox Question}
Parameter 2. 'Response Value to check'
  1. Checkbox Question - Any checkbox question name

  2. Response Value to check - a single number that matches the value of a response in the checkbox question. See example below.

Suppose a study wants to find a correlation of emotions to the amount of cigarettes a participant smokes. At the end of the day, the participant is presented with a checkbox question [FeelingToday] as follows:

Reflecting on today, which of these emotions did you feel? Check all that apply.

image-20240509-165509.pngImage Added

Then, in a calculated field question [Feeling], the following formula is calculated:

Iff(Contains([FeelingToday], 1), 1, 0) + Iff(Contains([FeelingToday], 2), 2, 0) +
Iff(Contains([FeelingToday], 3), 4, 0) + Iff(Contains([FeelingToday], 4), 8, 0) +
Iff(Contains([FeelingToday], 5), 16, 0) + Iff(Contains([FeelingToday], 6), 32, 0) = 17

Contains Calculation

Iff Formula Calculation

Contains([FeelingToday], 1) = TRUE

Iff(Contains([FeelingToday], 1), 1, 0) = 1

Contains([FeelingToday], 2) = FALSE

Iff(Contains([FeelingToday], 2), 2, 0) = 0

Contains([FeelingToday], 3) = FALSE

Iff(Contains([FeelingToday], 3), 4, 0) = 0

Contains([FeelingToday], 4) = FALSE

Iff(Contains([FeelingToday], 4), 8, 0) = 0

Contains([FeelingToday], 5) = TRUE

Iff(Contains([FeelingToday], 5), 16, 0) = 16

Contains([FeelingToday], 6) = FALSE

Iff(Contains([FeelingToday], 6), 32, 0) = 0

The purpose of this formula is to determine what emotion, or combination of emotions, is associated with the amount of cigarettes the participant smokes. This could be used in an Average calculation when the participant enters the next stage to present helpful tips to the participant if they report feeling one of these emotions.

Alternatively, if the study wants to present messages to the participant if they responded feeling “Sad” which has a value of 2, then the following formula can be used in the Display Logic for the message:

Contains([FeelingToday], 2)

This would evaluate to TRUE and display the desired message to the participant.

Panel
bgColor#B3D4FF

Checkbox Syntax

Checkbox syntax from CMS is now supported. [CheckboxQuestion(1)] will result in 0 if the option with value “1” was not selected by participant and vice versa. This syntax doesn’t support default value format such as [RadioQuestion:-999] (which will result in a default value of -999 if no value was found for the question “RadioQuestion.”

Panel
bgColor#B3D4FF

ResponseExists/Exists

This formula is used to check if a particular question has been recorded in the database with a response or not. This formula accepts one parameter which is the question name. The formula returns TRUE if a response was found and FALSE if a response was not found.

Code Block
Variant 1: ResponseExists({Variable Name})
Variant 2: Exists({Variable Name})
Parameter 1: {Variable Name}
  1. {Variable Name} - any question type that records a response from the participant

This formula can use either of the keywords “ResponseExists” or “Exists”

Suppose a baseline assessment contains two radio questions, [SmokerYN] and [VapeYN], asking the participant the following:

Display Logic

Question Name

Question Text

Response Text (Response Value)

(none)

[SmokerYN]

Do you currently smoke?

Yes (value 1)
No (value 2)

[SmokerYN] == 1

[VapeYN]

Do you also vape?

Yes (value 1)
No (value 2)

If the participant answers “Yes” to [SmokerYN], then they’ll be presented [VapeYN] to answer, otherwise, they don’t get shown [VapeYN].

Suppose this participant responds “No” in the assessment. After completing the baseline, they are moved into the next stage that has an assessment containing questions dependent on the participant’s answer to [VapeYN].

However, since the participant in this example didn’t see [VapeYN], these questions should include the following formula in their Display Logic:

ResponseExists([VapeYN])
OR
Exists([VapeYN])

Alternatively, we can add a calculated field question that has the following formula to determine if the participant answered the Vape question:

Iff(ResponseExists([VapeYN], 1, 0)

Panel
bgColor#B3D4FF

Last Response Value

Putting variable names in square brackets [] will automatically return the last response value a participant has input regardless of whether the variable is in the same assessment or from an assessment two stages prior. This is especially important for the formulas described in this section to be used in Calculated Field Questions, Display Logic in assessments, and ending FormulaBased stages.

Suppose in a Baseline assessment, the participant is asked a Radio Question [DailyCigs] that says:

How many cigarettes do you typically smoke daily?

  • 0 - 3 (value 1)

  • 4 - 6 (value 2)

  • 7 - 9 (value 3)

  • 10+ (value 4)

Then in an assessment in a different stage, it uses the value from [DailyCigs] to present certain questions to the participant or a calculated field question can use the value to calculate/keep track of the difference between the users reported cigarette usage and how many they said in [DailyCigs].

Panel
bgColor#B3D4FF

Default Values

Default values (applied when a response for a question cannot be found) can be defined in the declaration of question name followed by a colon “:”.

Time Question types cannot be assigned a default value due to its use of colon. Attempting to assign a default value to a Time Question type will result in a conflict of function.

Examples:

  • [colorblue:-1] → Value assumed for the variable “colorblue” is -1 if no response found in the database.

  • [study_startdate:2100-01-01] → Value assumed for the variable “study_startdate” is 2100-01-01 if not value found.

  • [RadioQ1:0] → If no response found, the value for “RadioQ1” is assumed to be 0.

If no colon (:) is used, the following default values are used for the question types listed under them.

-999

  • Dropdown

  • Radio

  • Slider

  • RandomNumberGenerator

  • Video

Empty String

  • Text Field

  • Text Area

1970-01-01 00:00:00

  • Date

  • Time

  • Timestamp

Panel
bgColor#B3D4FF

Display PHI information

If a study is collecting PHI from participants, the information provided can be used to curate RichText and Email questions as desired. The table below shows what to use for each of the PHI fields offered in the EDC.

Panel
bgColor#C0B6F2

If a field is called on but there is no data for that participant’s PHI field, then it’ll return blank.

EDC PHI Field

RichText/Email format

Subject ID

{{Personalization.SubjectId}}

First Name

{{Personalization.FirstName}}

Middle Name

{{Personalization.MiddleName}}

Last Name

{{Personalization.LastName}}

Street Address

{{Personalization.AddressLn1}}

Apartment Number

{{Personalization.AddressLn2}}

City

{{Personalization.City}}

State

{{Personalization.State}}

Zip Code

{{Personalization.ZipCode}}

Country

{{Personalization.Country}}

Cell Number
(International code and phone number)

{{Personalization.CellPhoneIntlCode}}
{{Personalization.CellPhone}}

Work Number
(International code and phone number)

{{Personalization.WorkPhoneIntlCode}}
{{Personalization.WorkPhone}}

Home Number
(International code and phone number)

{{Personalization.HomePhoneIntlCode}}
{{Personalization.HomePhone}}

Email

{{Personalization.Email}}

Ethnicity

{{Personalization.Ethnicity}}

Suppose a study has an assessment that changes a participant’s mailing address. The following example shows what the RichText question will look like using the formulas and what will be displayed to the participant in the Insight app:

Code Block
      Subject ID: PT015
      First Name: John
       Last Name: Doe
  Street Address: 123 First St.
Apartment Number: 
            City: Townsville
           State: IL
        Zip Code: 12345

RichText Formula/Text

Insight App Display

Hello {{Personalization.FirstName}}.
Your current address is:
{{Personalization.AddressLn1}} {{Personalization.AddressLn2}}
{{Personalization.City}}, {{Personalization.State}} {{Personalization.ZipCode}}

Hello John.
Your current address is:
123 First St.
Townsville, IL 12345

Now suppose the participant wants to change their address. They are shown a series of Text Field questions [NewStreetAddress], [NewApartmentNumber], [NewCity], [NewState], and [NewZipCode] as follows:

Question Name

Response

[NewStreetAddress]

456 Main St.

[NewApartmentNumber]

N/A

[NewCity]

Villageton

[NewState]

WV

[NewZipCode]

67890

The participant can then be presented with their responses to verify if they are correct:

RichText Formula/Text

Insight App Display

Your new address is now:
{{[NewStreetAddress]}} {{[NewApartmentNumber]}}
{{[NewCity]}}, {{[NewState]}} {{[NewZipCode]}}

Your new address is now:
456 Main St. N/A
Villageton, WV 67890

This information can be used in an email to be sent to researchers as follows:

Email Formula/Text Body

Email Received Body

Participant {{Personalization.SubjectId}} has requested a change in address as follows:
New Street Address: {{[NewStreetAddress]}}
New Apartment Number: {{[NewApartmentNumber]}}
New City: {{[NewCity]}}
New State: {{[NewState]}}
New Zip Code: {{[NewZipCode]}}

Please edit the appropriate PHI Fields as soon as possible at the earliest convenience.

Participant PT015 has requested a change in address as follows:
New Street Address: 456 Main St.
New Apartment Number: N/A
New City: Villageton
New State: WV
New Zip Code: 67890

Please edit the appropriate PHI Fields as soon as possible at the earliest convenience.

Panel
bgColor#DEEBFF

Concat

{{Concat([CheckboxQuestion], “Concatenation Type”, ‘Delimiter’)}}

Concat, short for “concatenation,” is a special formula that can list out the selected responses from a Checkbox question type. There are 3 concatenation types as explained below:

[Question] = Checkbox Question type

image-20240509-165549.pngImage Added

 

Concatenation type

List type

Formula

Displayed as

  1. Bullet list

Displays each item chosen in a bullet list

{{Concat([Question],1)}}

  • Item 1

  • Item 3

  • Item 4

  1. Numbered list

Displays each item chosen in a numbered list

{{Concat([Question], 2)}}

  1. Item 1

  2. Item 3

  3. Item 4

  1. Linear list

Displays each item as a linear list separated by the desired delimiter

{{Concat([Question], 3, ', ')}}

Item 1, Item 3, Item 4

 

This can be used to display a list of sample goals a participant can achieve in a RichText question and be an easier way to read a participant’s response in an Email.

Special Case - Concatenation Type 4

{{Concat([TextAreaQuestion], 4, “Add Header”, ‘Header Text’)}}

This is a special use case of the Concat function that will display all entries a participant enters into a Text Area Question type. The primary use case is to display past journal entries and/or responses.

Please see the following table for a brief explanation of each formula:

Formula

List type

Displayed as

{{Concat([TextAreaQuestion], 4)}}

Will display each response in [TextAreaQuestion] separated by a divider line

Entry 1 will be listed first


Entry 2 will be listed second


etc…

{{Concat([TextAreaQuestion], 4, 0)}}

Will display each response in [TextAreaQuestion] separated by the default title “Journal Entry #:” where “#” is a count of each entry

Journal Entry 1:

Entry 1 will be listed first

Journal Entry 2:

Entry 2 will be listed second

Journal Entry…

etc…

{{Concat([TextAreaQuestion], 4, 1, ‘You said on day’)}}

Will display each response in [TextAreaQuestion] separated by a custom title. In this example, it will be separated by “You said on day #:” where “#” is a count of each entry

You said on day 1:

Entry 1 will be listed first

You said on day 2:

Entry 2 will be listed second

You said on day…

etc…

Panel
bgColor#DEEBFF

DateFormat

{{DateFormat([Date/TimeQuestion], ‘Desired formatting’)}}

DateFormat is a special formula that formats a Date or Time question type. The table below explains and shows the different formatting that is possible:

[Date] = ‘2024-03-08’
[Time1] = ‘17:03:06’
[Time2] = ‘08:17:53’

Format

Explanation

Formula

Output

y

Displays month and year

{{DateFormat([Date], 'y')}}

March 2024

yy

Displays abbreviated year

{{DateFormat([Date], ‘yy’)}}

24

yyyy

Displays year

{{DateFormat([Date], ‘yyyy’)}}

2024

d

Displays date in short format

{{DateFormat([Date], ‘d’)}}

3/8/2024

dd

Displays two-digit day

{{DateFormat([Date], ‘dd’)}}

08

ddd

Displays abbreviated day of the week

{{DateFormat([Date], ‘ddd’)}}

Fri

dddd

Displays day of the week

{{DateFormat([Date], ‘dddd’)}}

Friday

M

Display month and day

{{DateFormat([Date], ‘M’)}}

March 8

MM

Displays two-digit month

{{DateFormat([Date], ‘MM’)}}

03

MMM

Displays abbreviated month

{{DateFormat([Date], ‘MMM’)}}

Mar

MMMM

Displays month

{{DateFormat([Date], ‘MMMM’)}}

March

MM/dd/yyyy

Displays two-digit month and day and the full year

{{DateFormat([Date], ‘MM/dd/yyyy’)}}

03/08/2024

dddd, MMMM dd yyyy

Displays day of the week, month, two-digit day, and year

{{DateFormat([Date], ‘dddd, MMMM dd yyyy)}}

Friday, March 08 2024

h

Displays hour

{{DateFormat([Time1], ‘h’)}}

5

hh

Displays two-digit hour

{{DateFormat([Time1], ‘hh’)}}

05

H

Displays hour in military time

{{DateFormat([Time2], ‘H’)}}

8

HH

Displays two-digit hour in military time

{{DateFormat([Time2], ‘HH’)}}

08

mm

Display two-digit minutes

{{DateFormat([Time1], ‘mm’)}}

03

ss

Displays two-digit seconds

{{DateFormat([Time1], ‘ss’)}}

06

t

Displays time with AM/PM

{{DateFormat([Time1], ‘t’)}}

5:03 PM

tt

Displays if time is AM or PM

{{DateFormat([Time2], ‘tt’)}}

AM

h:m t

Displays, hour, minute with AM/PM

{{DateFormat([Time1], ‘h:m t’)}}

5:3 PM

HH:mm

Displays military time

{{DateFormat([Time1], ‘HH:mm’)}}

17:03


Panel
bgColor#DEEBFF

Home | Submit a Ticket | SCC | Privacy