Sentry For Good: Exploring Health And Tech With Resolve To Save Lives
Welcome to our Sentry for Good blog post series, where we share the stories of organizations making a difference in the world while also positively influencing the broader developer ecosystem. In this post, we highlight Sentry customer and non-profit Resolve to Save Lives.
Resolve to Save Lives, an initiative of Vital Strategies, is a global health initiative founded by the former head of the CDC that, perhaps unsurprisingly, is resolved to save lives. With goals of saving 100 million lives from cardiovascular disease and preventing epidemics, Resolve to Save Lives works alongside governments to apply scalable health processes.
Intersecting health and tech
Resolve to Save Lives partnered with two development firms in Bangalore, Obvious and Nilenso, to build a mobile app — Simple. Simple is an extremely lightweight electronic health record containing basic patient contact info, BP history, and current medications.
Used by healthcare workers to keep records for over 100,000 patients across nine districts in two states in India, Simple solves for two separate, but related, problems: paper records were too slow for healthcare workers and were easily lost by patients.
Creating a patient record with Simple is easy: healthcare workers enter basic patient identification, answer four short medical history questions, today’s BP, and the patient’s current BP medications. That’s it. Healthcare workers can then access the patient record during follow-up visits.
As a shortcut for quickly locating patient records, Simple created a BP passport with a unique QR code that connects to the database. While the passport includes basic contact information, it also includes short medical records, like most recent BP, current medications, and upcoming appointments. The passport is easily replaceable (solving the patient problem) and quickly scannable (solving the healthcare worker problem).
According to Tim Cheadle, Director of Engineering at Resolve to Save Lives, "before Simple, they were making paper records, which took between two and four minutes per patient. With Simple, healthcare workers can look up patients and record their most recent blood pressure (BP) reading in under 15 seconds."
Asynchronous data syncing
Simple's Android app was built offline first, primarily due to unstable network and power reliability in India. Since it's common to go long periods without power, Simple's developers didn't want power outages to stand in the way of treating patients. Simple’s engineering team created a three-step data sync mechanism to allow asynchronous record syncing.
1. Send records from device to server.
As expected, the mobile device needs to keep track of records to be synced. Whether the records are new or updated, the server handles disambiguation. All records that need to be synced must be sent before fetching records from the server.
2. Fetch records from server to device.
A distinction is made when fetching records for the first time versus subsequent syncs using a search parameter. Subsequent syncs return a cursor that can be used to continue syncing for the next sync.
3. Merge.
Merging happens on the server-side. Conflict resolution is a last-write-wins (LWW) scenario, ensuring that the latest updated values are given preference. The server may send back the same record multiple times, so updating records on the device needs to be idempotent.
Allowing Simple to run offline on personal mobile phones provides asynchronous communication with the patient database. However, offline functionality sparks questions of when errors happen and how those errors are surfaced.
Simple + Sentry
Simple is a standard Rails 5 app that uses raven-ruby to interface with Sentry. For every new error received, the stack trace with the exact line-number specified is used to identify the potential severity of the error. Sentry's UI picks up request headers for particular code-paths, provides helpful information for database debugging (like patient or facility ID), and helps validate whether the error itself is meaningful.
For example, Simple developers recently discovered that the mobile app was sending duplicate requests for the same sync resource. By tracing the duplicate requests as separate events in Sentry, they uncovered the root cause of PG::UniqueViolation: ERROR
.
Here, we have a mix-in called Mergeable that is shared by all resources. Mergeable is responsible for conflict resolution and eventually saving a new record into the database if necessary. Mergeable always checks for the resource ID before inserting into the database but does not attempt the find-or-create atomically. It relies on the database for the last-mile validation of the record uniqueness. Upon further investigation, we realized that the BloodPressures resources was the biggest culprit of this since that has the highest sync volume across the board.
Since the app is expected to work in unstable network conditions, Simple consumes errors and processes them when syncing. However, the team needs visibility into certain errors that don't actually impact the functionality of the app (like HTTP 500 or HTTP 400). These errors are pushed to Sentry as custom errors so that the team is alerted and can review them on a regular basis.
Tim says that Sentry "plays a huge role in being able to provide a stable app" by providing offline support and uncovering rich context about errors in the Simple app. Without Sentry, Simple developers would need to rely on healthcare workers to relay information about every exception, crash, device, and context. By integrating with Simple's existing bug tracking system inside Pivotal and Slack, Sentry provides immediate, actionable alerts, stack traces, and mobile device information necessary to fix the issue and minimize the impact on healthcare workers and patients.
How you can help
Simple isn't really about the software or turning a profit. The goal is to make people healthy — Simple is just a means to that end. Simple is free and open-source, and always will be. Simple's open-source code goes a long way in ensuring Simple is a compliment (and not a competitor) to existing electronic medical records. Instead of locking code away behind proprietary apps, the Simple team wants to provide the right tools and education when it makes sense.
If you have a desire to do good, there are open-source communities that need varying degrees and types of contributions. Do you want to collect water samples and report them somehow? There's an open-source project for that.
If you'd like to contribute to one of Simple's repository, you can find them here. You're also welcome to contribute to Sentry at any time, and you can do so here.