This service manages the random invocation of EMA surveys based on various MyDataHelp (MDH) participant custom fields.
- MyDataHelp (MDH) - mHealth platform used for this study which provides 3rd API access.
- External AWS Service - An external service that packages and runs this code. The easiest solution is to run this on Lambda invoking it periodically each day using AWS Event Scheduler.
- Create a single monolithic EMA survey with all the questions you want to ask.
- Divide this monolithic survey into categories if needed. Categories can be used to logically divide the surveys into EMA’s meassuring different things - Mood EMAs, Truma EMAs, Sleep EMAs’ etc. A random EMA is picked from each category.
- All categories must have the same number of EMA. Variable number of EMA per category is not currently supported.
- Each survey question inside a category must be conditioned to only be displayed on category
specific custom variable. More on this later in the Survey Question Conditioning Section.
An image showing individual survey questions categorized by EMA type
This service when run generates a random integer contained within [1, ema_max] where ema_max is a
coordinator configured MDH participant custom field. It represents the total number of surveys per
EMA category.
This service updates a survey category custom field labeled ema_random<a> where <a> category
number starting from 1. For example if we have a total of 3 EMA survey categories then we would have
3 custom fields in MDH namely - ema_random1, ema_random2, ema_random3.
ema_random1 == 1). This can be
done through the navigation tab in MDH survey.
<x> is a placeholder for category number. For example if there are 3 categories then <x> will range
from 1..3, with each category having its own custom field. Any field marked with (**) is coordinator editable.
(*)ema_categories (int)- (Read) Stores total number categories inside the complete EMA survey.(*)ema_max (int)- (Read) Total number of EMA surveys per category.ema_metadata<x> (string)- (Read / Write) Stores the random numbers already seen in a comma seperated format. Cycles back automatically when no more random numbers can be generated. Example -1,3,7ema_random<x> (string)- (Write) Holds the random number generated by this service within[1, ema_max]. Condition your individual surveys for each catgegory on this variable.ema_status (string)- (Write) Updates topassedorfailed <failure message>after this service has run for a particular participant.
(*)ema_enabled (string)-yes|noindicating if the EMA logic should be enabled or not.(*)ema_morning_time (timeofday)- Holds the time on which MDH moring schedules are anchored to send the morning EMA. Allows for coordinators to tune this to the participants liking.(*)ema_evening_time (timeofday)- Holds the time on which MDH evening schedules are anchored.
Several environment variables hold MDH sercret key credentials, project id and account id need to be
configured prior to running this service locally. Check out the example environment file env.local.
Once you have edited it, make sure to rename this file as .env before testing this service out. This
will allow dotenv package to automatically pick up these values without needing to export them to
your terminal session.
npm install
node index.mjs
