IN THIS ARTICLE
Subscribe to Our Newsletter
When it comes to patient healthcare monitoring, reliable and secure realtime data streaming is mission critical. With patient healthcare, having access to a patients vital parameters in realtime makes a great deal of difference in providing timely and accurate services on-site or remotely.
In this tutorial, we’ll build a simple healthcare monitoring application for Android (on the patient side), and a monitoring realtime dashboard (on the caregiver’s side) for capturing health data and displaying it in realtime. In this tutorial, our application will collect heart rate and stream the data from the Android phone in realtime to our dashboard UI.
Android Healthcare Overview
In our Android application, the phone’s camera will be used to capture the heart rate. When the app user presses a finger against the camera, an image processing algorithm detects the red component on the finger image to sense the blood flow and then calculates a reading. The reading is averaged at the time span of one minute, and the heart rate is determined. Once we have the heart rate reading, the app streams the data in realtime to a monitoring dashboard.
Note: this sample application is meant for educational and entertainment purposes, and should not be used for actual medical practice.
- Android Heart Rate Monitor GitHub Repository
- APK Release Package
- Realtime Dashboard (receives and publishes heart rate data)
- PubNub Android SDK
Note : The terms “pulse rate” and “heart rate” are used interchangeably across the tutorial and source code literature.
Here is the application in-action:
Android App Core Functionality
1. PubNub Initialization
At the start, the MainActivity on the Android app triggers PubNub initialization followed by doctor’s ID registration.
Users can key in a doctor’s ID to associate with a doctor’s profile for sending their healthcare data, in this case, the heart rate monitor.
The saveDoctorId( ) function takes the doctor id keyed in by the user and saves it in the application configuration.
A PubNub channel name is created based on this id by appending the string “heartbeat_alert” to this doctor id.
Once the doctor id is registered, the application switches to the HeartRateMonitor activity and initializes the callbacks for publishing the readings.
3. Heart Rate Sensing
) function does the background image processing on the camera image to sense the pulse rate.
The camera captures the frames for a duration of 10 seconds. The algorithm within
) calculates the variation in the average RED color intensity in the frames captured, multiplies that value by six, to arrive at the approximate reading for beats per minute.
Once the reading is taken, it is published over PubNub using PubNub Data Streams to the realtime dashboard which live updates as new information comes through.
Building the Realtime Dashboard
Our realtime dashboard is subscribed to our Android application and receives the heart rate data in realtime, then visualizes it.
Our’s looks like this:
Initially, after launching the dashboard application, the user needs to key in the doctor id. The getDoctorId() function captures the id and initializes PubNub channel subscription for receiving published readings from the Android app.
Additionally , the dashboard user can retrieve the historical readings. This is done using the PubNub’s Storage & Playback (aka History API) feature.
That’s it! We’ve built a simple heart rate monitoring application for Android without using any external components. This app gives you a good idea of how to combine the functionality of an Android smartphone with realtime data streams for healthcare applications.
Because we show no bias when it comes to mobile operating systems, next week, we’ll release our tutorial building this application for iOS, so stay tuned!