Initially we referred to this as compliance, but because “compliance” also has meaning in a governance context, we’re using “adherence” to describe the measurement of study member participation in the study.
In the v2 science APIs, Bridge has three APIs that are involved in schedule adherence:
The schedule itself, which is finite in length and described by a timeline;
The set of adherence records for the participant which describe what the participant has done in that timeline (we only work with the session records when calculating adherence);
A set of event timestamps that tell us where the participant is at in the timeline (ie what the user should have done and what they should currently be doing in the schedule).
So far the Bridge server provides this information through separate APIs and does not keep track of the time of the participants. For the sake of efficiency, I think we want the Bridge server to combine this information and provide reports on the status of the account, which will be less resource intensive that serving out all the information to be processed by a client or worker process. The issues I see with this:
For the first time the server will need to have knowledge of the participant’s time and time zone(?);
Because this information depends on the time of the request, it is not very cacheable;
The reports probably update infrequently compared to the amount they will be read (the exact amount depends on many factors). We will have to devise caching strategies to make the system performant when looking at many participants.
Persistent time windows will be excluded from all adherence reports. Completing assessments that are part of a persistent window do not count for or against adherence.
All of these views operate on the most recent timestamps for all events. Building schedules that rely on a mutable event changing, and triggering a new timeline of sessions to perform, will not work with these adherence APIs. That would be events like “do X when session type Y has been completed.” Since it will show compliance with the most event time stream, it may be sufficient anyway. Past time streams are no longer actionable.
APIs
Method | Path (Under /v5/studies/{studyId} | Description |
---|---|---|
GET | /participants/{userId}/adherence/eventstream | EventStreamAdherenceReport for one user. This view includes scheduling based on events the user does not have, and is a detailed view of the entire schedule for one user. |
GET | /participants/{userId}/adherence/weekly | A WeeklyAdherenceReport for one user. This calculates the “current week” of each event timestamp and aligns it to a seven day schedule. |
GET | /participants/adherence/weekly | A paged list where each record is a WeeklyAdherenceReport for one user. If no call has generated this report, it is not generated as part of this call, so a worker process will need to periodically generate these out-of-request. |
GET | /v1/apps/{appId}/studies/{studyId} | Worker endpoint to create and persist the weekly report for users, to enable the paged view across all accounts. |
Each report builds on the latter report.
EventStream Report (all adherence data for one participant)
This is what the JSON would like like:
{ "activeOnly": false, "timestamp": "2021-11-23T22:00:31.699Z", "adherencePercent": 25, "streams": [ { "startEventId": "custom:event1", "eventTimestamp": "2021-11-21T20:00:00.000Z", "daysSinceEvent": 2, "byDayEntries": { "0": [ { "sessionGuid": "eRLgI5gfe1kef_XRZDfdFU9I", "sessionLabel": "Session #2", "sessionSymbol": "2", "startDay": 0, "startDate": "2021-11-21", "timeWindows": [ { "sessionInstanceGuid": "bDBVV02XrjrOG8NgBYSYFg", "timeWindowGuid": "KZ1piANVdeD-r8PCHL2bviLh", "state": "completed", "endDay": 0, "endDate": "2021-11-21", "type": "EventStreamWindow" } ], "type": "EventStreamDay" } ], "1": [ { "sessionGuid": "eRLgI5gfe1kef_XRZDfdFU9I", "sessionLabel": "Session #2", "sessionSymbol": "2", "startDay": 1, "startDate": "2021-11-22", "timeWindows": [ { "sessionInstanceGuid": "u-cc8Ou4xqUPVnht4oh-bw", "timeWindowGuid": "KZ1piANVdeD-r8PCHL2bviLh", "state": "expired", "endDay": 1, "endDate": "2021-11-22", "type": "EventStreamWindow" } ], "type": "EventStreamDay" } ] }, "type": "EventStream" }, { "startEventId": "custom:event2", "eventTimestamp": "2021-11-15T20:00:00.000Z", "daysSinceEvent": 8, "byDayEntries": { "0": [ { "sessionGuid": "z_jb4p2Lr9Q56z8AwiYNieqw", "sessionLabel": "Session #3", "sessionSymbol": "3", "startDay": 0, "startDate": "2021-11-15", "timeWindows": [ { "sessionInstanceGuid": "KAxvwhsX6jSVl89a3-gdKw", "timeWindowGuid": "gF6hy-UiipJLXqe7F_yK-wQc", "state": "expired", "endDay": 2, "endDate": "2021-11-17", "type": "EventStreamWindow" } ], "type": "EventStreamDay" } ], "3": [ { "sessionGuid": "z_jb4p2Lr9Q56z8AwiYNieqw", "sessionLabel": "Session #3", "sessionSymbol": "3", "startDay": 3, "startDate": "2021-11-18", "timeWindows": [ { "sessionInstanceGuid": "nQnWs_4ECvLtY4K1gYk67g", "timeWindowGuid": "gF6hy-UiipJLXqe7F_yK-wQc", "state": "expired", "endDay": 5, "endDate": "2021-11-20", "type": "EventStreamWindow" } ], "type": "EventStreamDay" } ] }, "type": "EventStream" }, { "startEventId": "study_burst:main-sequence:01", "eventTimestamp": "2021-11-21T20:00:00.000Z", "daysSinceEvent": 2, "studyBurstId": "main-sequence", "studyBurstNum": 1, "byDayEntries": { "0": [ { "sessionGuid": "LcWpQFKaGY5FSQ0LT4tnvdO7", "sessionLabel": "Session #1", "sessionSymbol": "1", "startDay": 0, "startDate": "2021-11-21", "timeWindows": [ { "sessionInstanceGuid": "1aCbUaFYkixIsIJBf9WGpg", "timeWindowGuid": "GNp94CnfTTtR-s0OzrFeftrh", "state": "expired", "endDay": 0, "endDate": "2021-11-21", "type": "EventStreamWindow" }, { "sessionInstanceGuid": "yQnubrShfYMY9ZzOE3zw3Q", "timeWindowGuid": "aRaHNKIY0yKgOl5CLuA3ZDHJ", "state": "expired", "endDay": 0, "endDate": "2021-11-21", "type": "EventStreamWindow" } ], "type": "EventStreamDay" } ] }, "type": "EventStream" } ], "type": "EventStreamAdherenceReport" }
EventStreamWindow
includes the state of that session (which is the basis for adherence calculation). This adherence report could be displayed on a calendar since it is specific to a user and the server must know all the calendrical values to calculate it (and it's the only report that can take a timestamp to indicate the time at which the report should be calculated).
The completion states are:
State | Description | Adherence |
---|---|---|
not_applicable | Participant does not have this event in their events, so these sessions will not currently ever be shown to the participant. | N/A |
not_yet_available | Participant should not have seen or started this session. It’s in the future. | N/A |
unstarted | Participant should see the session (they are being asked to do it now), but they have not started it. | unknown |
started | Participant has started the session. | unknown |
completed | Participant completed the session before it expired. | compliant |
abandoned | Participant started or finished at least one assessment in the session, but there was more work to do and it expired before they finished it. | noncompliant |
expired | Participant did not start the session and it is now expired. | noncompliant |
We can calculate a compliance percentage from these values across a participant’s entire participation in the study. In the weekly report below, we can calculate adherence for that week alone.
Weekly Adherence Report
This report always returns seven days of adherence records for a given user. The report calculates this information by finding the “week since event N” for every event and every session (it will be the week that has the day that falls on “today.”) This timestamp won’t be adjustable since every timestamp would require a recalculation of all these reports—so it’ll have to be a date on the server, possibly adjustable per study to a different time zone. Note that the the individual sessions listed in this report are not lined up by calendar date (unless they were triggered by the same event). The structure of this report would be as follows:
{ "participant": { "firstName": "A-chan", "email": "alx.dark+achan@sagebase.org", "externalId": "asdfasdf", "identifier": "GqYpNUWolebxS2eQudF1hc-a", "type": "AccountRef" }, "timestamp": "2021-11-23T22:03:21.356Z", "weeklyAdherencePercent": 33, "byDayEntries": { "0": [ { "sessionGuid": "eRLgI5gfe1kef_XRZDfdFU9I", "sessionLabel": "Session #2", "sessionSymbol": "2", "week": 1, "startDate": "2021-11-21", "timeWindows": [ { "sessionInstanceGuid": "bDBVV02XrjrOG8NgBYSYFg", "timeWindowGuid": "KZ1piANVdeD-r8PCHL2bviLh", "state": "completed", "endDate": "2021-11-21", "type": "EventStreamWindow" } ], "type": "EventStreamDay" }, { "sessionGuid": "LcWpQFKaGY5FSQ0LT4tnvdO7", "sessionLabel": "Session #1", "sessionSymbol": "1", "week": 1, "studyBurstId": "main-sequence", "studyBurstNum": 1, "startDate": "2021-11-21", "timeWindows": [ { "sessionInstanceGuid": "1aCbUaFYkixIsIJBf9WGpg", "timeWindowGuid": "GNp94CnfTTtR-s0OzrFeftrh", "state": "expired", "endDate": "2021-11-21", "type": "EventStreamWindow" }, { "sessionInstanceGuid": "yQnubrShfYMY9ZzOE3zw3Q", "timeWindowGuid": "aRaHNKIY0yKgOl5CLuA3ZDHJ", "state": "expired", "endDate": "2021-11-21", "type": "EventStreamWindow" } ], "type": "EventStreamDay" } ], "1": [ { "sessionGuid": "eRLgI5gfe1kef_XRZDfdFU9I", "sessionLabel": "Session #2", "sessionSymbol": "2", "week": 1, "startDate": "2021-11-22", "timeWindows": [ { "sessionInstanceGuid": "u-cc8Ou4xqUPVnht4oh-bw", "timeWindowGuid": "KZ1piANVdeD-r8PCHL2bviLh", "state": "expired", "endDate": "2021-11-22", "type": "EventStreamWindow" } ], "type": "EventStreamDay" }, { "sessionGuid": "LcWpQFKaGY5FSQ0LT4tnvdO7", "sessionLabel": "Session #1", "sessionSymbol": "1", "week": 1, "studyBurstId": "main-sequence", "studyBurstNum": 1, "startDate": "2021-11-22", "timeWindows": [ { "sessionInstanceGuid": "7HaIdOehYJrJk3VZcGeNxg", "timeWindowGuid": "GNp94CnfTTtR-s0OzrFeftrh", "state": "completed", "endDate": "2021-11-22", "type": "EventStreamWindow" }, { "sessionInstanceGuid": "R0I7n1fEeIR88fYv6iVPTg", "timeWindowGuid": "aRaHNKIY0yKgOl5CLuA3ZDHJ", "state": "expired", "endDate": "2021-11-22", "type": "EventStreamWindow" } ], "type": "EventStreamDay" } ], "2": [ { "sessionGuid": "eRLgI5gfe1kef_XRZDfdFU9I", "sessionLabel": "Session #2", "sessionSymbol": "2", "week": 1, "startDate": "2021-11-23", "timeWindows": [ { "sessionInstanceGuid": "s7HuTxm4E-ffhfiddVFkXQ", "timeWindowGuid": "KZ1piANVdeD-r8PCHL2bviLh", "state": "started", "endDate": "2021-11-23", "type": "EventStreamWindow" } ], "type": "EventStreamDay" }, { "sessionGuid": "z_jb4p2Lr9Q56z8AwiYNieqw", "sessionLabel": "Session #3", "sessionSymbol": "3", "week": 2, "startDate": "2021-11-24", "timeWindows": [ { "sessionInstanceGuid": "WHE_gHE71tk8qFERatcruA", "timeWindowGuid": "gF6hy-UiipJLXqe7F_yK-wQc", "state": "not_yet_available", "endDate": "2021-11-26", "type": "EventStreamWindow" } ], "type": "EventStreamDay" }, { "sessionGuid": "LcWpQFKaGY5FSQ0LT4tnvdO7", "sessionLabel": "Session #1", "sessionSymbol": "1", "week": 1, "studyBurstId": "main-sequence", "studyBurstNum": 1, "startDate": "2021-11-23", "timeWindows": [ { "sessionInstanceGuid": "SgTohgnPkGjB9eE73QRXEA", "timeWindowGuid": "GNp94CnfTTtR-s0OzrFeftrh", "state": "completed", "endDate": "2021-11-23", "type": "EventStreamWindow" }, { "sessionInstanceGuid": "ezwrtaRiJd5Bfa3w5Xxffw", "timeWindowGuid": "aRaHNKIY0yKgOl5CLuA3ZDHJ", "state": "unstarted", "endDate": "2021-11-23", "type": "EventStreamWindow" } ], "type": "EventStreamDay" } ], "3": [ { "sessionGuid": "eRLgI5gfe1kef_XRZDfdFU9I", "sessionLabel": "Session #2", "sessionSymbol": "2", "week": 1, "startDate": "2021-11-24", "timeWindows": [ { "sessionInstanceGuid": "u78_-kFdyNnKt6wbUmSXcA", "timeWindowGuid": "KZ1piANVdeD-r8PCHL2bviLh", "state": "not_yet_available", "endDate": "2021-11-24", "type": "EventStreamWindow" } ], "type": "EventStreamDay" }, { "sessionGuid": "LcWpQFKaGY5FSQ0LT4tnvdO7", "sessionLabel": "Session #1", "sessionSymbol": "1", "week": 1, "studyBurstId": "main-sequence", "studyBurstNum": 1, "startDate": "2021-11-24", "timeWindows": [ { "sessionInstanceGuid": "mcpv_-sW1vXfk4Vyi5dwgg", "timeWindowGuid": "GNp94CnfTTtR-s0OzrFeftrh", "state": "not_yet_available", "endDate": "2021-11-24", "type": "EventStreamWindow" }, { "sessionInstanceGuid": "t4AEs7UzOjXYACSOO1REPA", "timeWindowGuid": "aRaHNKIY0yKgOl5CLuA3ZDHJ", "state": "not_yet_available", "endDate": "2021-11-24", "type": "EventStreamWindow" } ], "type": "EventStreamDay" } ], "4": [ { "sessionGuid": "eRLgI5gfe1kef_XRZDfdFU9I", "sessionLabel": "Session #2", "sessionSymbol": "2", "week": 1, "startDate": "2021-11-25", "timeWindows": [ { "sessionInstanceGuid": "tJxcgcQK40X6jL71MORb3g", "timeWindowGuid": "KZ1piANVdeD-r8PCHL2bviLh", "state": "not_yet_available", "endDate": "2021-11-25", "type": "EventStreamWindow" } ], "type": "EventStreamDay" }, { "sessionGuid": "LcWpQFKaGY5FSQ0LT4tnvdO7", "sessionLabel": "Session #1", "sessionSymbol": "1", "week": 1, "studyBurstId": "main-sequence", "studyBurstNum": 1, "startDate": "2021-11-25", "timeWindows": [ { "sessionInstanceGuid": "22nOvDMhYIE7btX6X8zlHw", "timeWindowGuid": "GNp94CnfTTtR-s0OzrFeftrh", "state": "not_yet_available", "endDate": "2021-11-25", "type": "EventStreamWindow" }, { "sessionInstanceGuid": "H2EG1SV-tF_s8dmKWwvtOQ", "timeWindowGuid": "aRaHNKIY0yKgOl5CLuA3ZDHJ", "state": "not_yet_available", "endDate": "2021-11-25", "type": "EventStreamWindow" } ], "type": "EventStreamDay" } ], "5": [ { "sessionGuid": "eRLgI5gfe1kef_XRZDfdFU9I", "sessionLabel": "Session #2", "sessionSymbol": "2", "week": 1, "startDate": "2021-11-26", "timeWindows": [ { "sessionInstanceGuid": "-OoNi3vhifRUqN6X9WTMCg", "timeWindowGuid": "KZ1piANVdeD-r8PCHL2bviLh", "state": "not_yet_available", "endDate": "2021-11-26", "type": "EventStreamWindow" } ], "type": "EventStreamDay" }, { "sessionGuid": "z_jb4p2Lr9Q56z8AwiYNieqw", "sessionLabel": "Session #3", "sessionSymbol": "3", "week": 2, "startDate": "2021-11-27", "timeWindows": [ { "sessionInstanceGuid": "2O-jPnpWOYZLx0VjBvvO8g", "timeWindowGuid": "gF6hy-UiipJLXqe7F_yK-wQc", "state": "not_yet_available", "endDate": "2021-11-29", "type": "EventStreamWindow" } ], "type": "EventStreamDay" }, { "sessionGuid": "LcWpQFKaGY5FSQ0LT4tnvdO7", "sessionLabel": "Session #1", "sessionSymbol": "1", "week": 1, "studyBurstId": "main-sequence", "studyBurstNum": 1, "startDate": "2021-11-26", "timeWindows": [ { "sessionInstanceGuid": "JfyiAbHZ-nlmTZui_N19Tg", "timeWindowGuid": "GNp94CnfTTtR-s0OzrFeftrh", "state": "not_yet_available", "endDate": "2021-11-26", "type": "EventStreamWindow" }, { "sessionInstanceGuid": "g6kRO-JZgt0lGghDT8v37A", "timeWindowGuid": "aRaHNKIY0yKgOl5CLuA3ZDHJ", "state": "not_yet_available", "endDate": "2021-11-26", "type": "EventStreamWindow" } ], "type": "EventStreamDay" } ], "6": [ { "sessionGuid": "eRLgI5gfe1kef_XRZDfdFU9I", "sessionLabel": "Session #2", "sessionSymbol": "2", "week": 1, "startDate": "2021-11-27", "timeWindows": [ { "sessionInstanceGuid": "_-1AlFrrN9IfA5tK-OYvag", "timeWindowGuid": "KZ1piANVdeD-r8PCHL2bviLh", "state": "not_yet_available", "endDate": "2021-11-27", "type": "EventStreamWindow" } ], "type": "EventStreamDay" }, { "sessionGuid": "LcWpQFKaGY5FSQ0LT4tnvdO7", "sessionLabel": "Session #1", "sessionSymbol": "1", "week": 1, "studyBurstId": "main-sequence", "studyBurstNum": 1, "startDate": "2021-11-27", "timeWindows": [ { "sessionInstanceGuid": "IUBXsO4ioFgJfi8GA9NSxw", "timeWindowGuid": "GNp94CnfTTtR-s0OzrFeftrh", "state": "not_yet_available", "endDate": "2021-11-27", "type": "EventStreamWindow" }, { "sessionInstanceGuid": "WdRjHkDWoqmQx4vxRuCVeg", "timeWindowGuid": "aRaHNKIY0yKgOl5CLuA3ZDHJ", "state": "not_yet_available", "endDate": "2021-11-27", "type": "EventStreamWindow" } ], "type": "EventStreamDay" } ] }, "type": "WeeklyAdherenceReport" }
This API would calculate and persist this report before returning it in the call, so that this call can be used by a worker process to build a record for every participant. The call could also be used to retrieve up-to-date state information for a specific participant. If this call is not called for a user, it will not show up in the paginated view of these records. We may want to hide a record that hasn’t been updated in the last 24 hours although a worker process will hopefully force a refresh on all accounts.
The SQL table for this report will not attempt to store the report normalized:
CREATE TABLE `WeeklyAdherenceReports` ( `appId` varchar(255) NOT NULL, `studyId` varchar(255) NOT NULL, `userId` varchar(255) NOT NULL, `clientTimestamp` bigint(20) unsigned NOT NULL, `createdOn` bigint(20) unsigned NOT NULL, `labels` text NOT NULL, `weeklyAdherencePercent` int(3) unsigned NOT NULL, `reportData` mediumtext NOT NULL, PRIMARY KEY (`appId`, `studyId`, `userId`), CONSTRAINT `WeeklyAdherenceReports-Study-Constraint` FOREIGN KEY (`studyId`, `appId`) REFERENCES `Substudies` (`id`, `studyId`) ON DELETE CASCADE, CONSTRAINT `WeeklyAdherenceReports-Account-Constraint` FOREIGN KEY (`userId`) REFERENCES `Accounts` (`id`) ON DELETE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
The “labels“ columns will pull out the labels from the JSON into a pipe-delimited string, to enable searching for records that match the label in the study-scoped API (searching by label and percentage of adherence are UI design requirements). Note that right now, this would mean the server would need to create the labels and the client would need to search with those server-supplied labels.
Weekly Adherence Reports for Study
The final API will allow an admin to retrieve a paged set of weekly adherence records for all participants in the study. This retrieves the records from the database and does not calculate them. The paging search criteria should be the same as the study participants search API. In addition to the search arguments in the /v5/studies/{studyId}/participants/search
API, it should be possible to filter and or sort on the following fields:
The adherence percentage;
The label of individual windows (through a like query on the labels column).
I would like to reuse the search code for participants, but it may be necessary to join tables in a way where that can’t be done, while still maintaining the desired paging logic. To start, it’s probably possible to just search and sort by adherence and labels.
Protocol adherence and notifications
Since all the reports give an adherence percentage (whole study or one week), we can use this to sort records by adherence in the weekly view, or to generate a message to administrators as part of the worker process that will be run nightly to update the weekly reports. Any necessary configuration for this can be added to the Study
model (in particular, at what percentage of adherence should we notify administrators that a participant is out of adherence).
A worker process would go through all apps nightly, looking for apps with studies that have schedules, and then for each of these studies, it would iterate through all participants in the study, calling the weekly adherence API endpoint for that participant. This would generate and persist their adherence report. It can also generate adherence messages, if need be.
If that’s too much, we can set a flag on apps or studies to do this caching or not.
Adherence Service
The following methods will be added to the AdherenceService:
public class AdherenceService { public EventStreamAdherenceReport getEventStreamAdherenceReport( String appId, String studyId, String userId, DateTime now, boolean showActive) { } public WeeklyAdherenceReport getWeeklyAdherenceReport( String appId, String studyId, String userId, DateTime now) { } public PagedResourceList<WeeklyAdherenceReport> getPagedWeeklyAdherenceReports( AdherenceSearch search) { } } public class AdherenceSearch { int offsetBy; int pageSize; searches accounts that are enrolled in a specific study String studyId; String emailFilter; String phoneFilter; Set<String> allOfGroups; Set<String> noneOfGroups; String language; DateTime startTime; DateTime endTime; String externalIdFilter; AccountStatus status; String attributeKey; String attributeValueFilter; String sessionLabel; Integer weekNumber; String studyBurstId; Integer studyBurstNum; Integer maxAdherencePercent; SearchTermPredicate predicate; StringSearchPosition stringSearchPosition; }
System Messaging APIs
We have had requirements to message both participants and study administrators over the years. For example, very early on we embedded a blog in an app for this purpose. Then we implemented support for remote push notifications and topics (rarely used). Instead in recent studies we have tried using local notifications based on scheduling information. Now we are talking about showing notifications to administrators about participants being out-of-adherence in an administrative UI. Because “notifications” is heavily overloaded for Bridge, I will call these “system messages.”
I would like to add a simple Ωmessaging system to Bridge which could be used to persist, deliver, and record the consumption of messages. Features would include:
API would be pub-sub and pull-based (write a message, request a list of active messages for a recipient; push-push via something like SMS or email is a lot more complicated);
Recipients should include individuals only, opt-in, to start;
Each recipient could mark the message as “read” to hide it from their UIs, or “resolved” to hide it for everyone. They would not be deleted so they are auditable. We should record who deleted or resolved the message;
Messages would have a type (“out of adherence,” “study joined,” “study completed”, etc.) and messages could be filtered on the type and/or study;
These should be app-scoped because it would be very annoying to have to go into every study to see what needed attention in that study.
This should meet the basics needs of our recent UI designs.
Method | Path | Description |
---|---|---|
GET | /v1/messages | Get the messages (paged and filterable by type and whether message has been read) for the caller. |
POST | /v1/messages | Publish a message to all subscribers. |
DELETE | /v1/messages/{guid} | Mark a message as read or resolved (if resolved=true) |
GET | /v1/messages/subscriptions | Get the studies and types of messages you are subscribed to |
POST | /v1/messages/subscriptions/{studyId}/{type} | Subscribe to receive messages of a specific type in a specific study. |
DELETE | /v1/messages/subscriptions/{studyId}/{type} | Unsubscribe from receiving messages of a given type in a given study. |
The objects (subscriptions and message):
public class Subscription { String appId; String studyId; MessageType messageType; String recipientId; } // As submitted public class Message { String studyId; MessageType messageType; String text; } // As persisted, one record per subscription public class Message { String guid; String appId; String studyId; String userId; MessageType messageType; String text; boolean read; String readBy; }