Quickstart
Build a CAMS app that schedules a daily WHO-5 survey and prints the answers as measurements.
Build an app that schedules the WHO-5 well-being survey every day at 13:00, lists the due surveys and prints each result as a measurement.
Prerequisites
- A Flutter app set up as described in Installation, including the CARP Mobile Sensing (CAMS) base setup.
Complete example
Replace the contents of lib/main.dart with:
How it works
| Stage | What it does |
|---|---|
| 1. Register | Makes RPAppTask and the survey measure known to CAMS, and registers the factory that turns a triggered survey task into a SurveyUserTask. It must run before configure(). CarpMobileSensing.ensureInitialized() runs first, because registering needs an initialized CAMS. |
| 2. Protocol | Defines the study with the phone as the only device and a SQLite database on the phone as the data endpoint. |
| 3. Survey task | Wraps who5Task, the WHO-5 survey that ships with the package, in an RPAppTask. The trigger repeats it every day at 13:00, and notification: true shows a notification with the task's title and description. |
| 4. Deploy | Deploys the study on the first run. On later runs, configure() restores the saved study, so the app does not add a second one with its own survey schedule. |
| 5. Measurements | Prints every measurement, including the survey result when the participant submits or leaves a survey. |
| 6. Start sampling | startSampling() waits until CAMS has connected the phone, the last step of setting up the study. It then queues the survey tasks that CAMS scheduled for the next 15 days and resumes sampling. A resume() right after tryDeployment() comes too early: CAMS ignores it, and no survey reaches the task list. |
| 7. Task list | Lists the due tasks that the participant can start. Tapping one calls onStart() and pushes task.widget, which closes itself when the participant finishes or leaves the survey. |
The material.dart import hides Flutter's TimeOfDay, because the trigger takes the TimeOfDay class from carp_core.
Run the app
See the survey sooner
Before the first run, change TimeOfDay(hour: 13) to a time a few minutes from now, for example TimeOfDay(hour: 9, minute: 41). The app deploys the protocol only once, so after a change, uninstall the app and run it again.
Start the app
Allow notifications when the app asks. The task list stays empty until the first survey is due.
Open the survey
At 13:00, a notification with the title Well-being survey appears. Tap it to open the app, then tap the task in the list. To open the survey straight from the notification, see Open a task from its notification.
Answer the questions
Answer the five questions and tap DONE on the last screen. The survey closes, and the task leaves the list.
Check the data
The console prints the survey result as a dk.cachet.carp.survey measurement. Formatted, and with four of the five question results left out, it looks like this:
The answer to each question is a list of the selected choices. CAMS also prints a dk.cachet.carp.completedapptask.survey measurement that holds the same result. See Survey data for every field.
Troubleshooting
Wait until the trigger time. A scheduled task enters the list only when its time has passed, and a changed trigger time takes effect only after you uninstall the app. Also check that the app registers SurveySamplingPackage before it calls configure().
Allow notifications for the app in the system settings. On Android, a scheduled notification may arrive late when the app is not allowed to schedule exact alarms.
Next steps
Building surveys
Build a survey from Research Package steps and add it to a protocol.
Scheduling and notifications
Choose triggers, notify participants and keep the task list in sync.
Cognitive tests
Add Cognition Package tests and sample sensors during them.
Survey data
The survey measurement and the Research Package result inside it.