Skip to main content

Medication Reminders

Automated process designed to send medication reminders to patients at four distinct times throughout the day. These reminders are scheduled to coincide with common medication times 1-1-1-1, ensuring patients receive timely prompts based on their prescribed medication schedules. The system harnesses the robust capabilities of Firebase to deliver notifications reliably and securely.

The solution is orchestrated through GitHub Actions, which employs a cron job to trigger an HTTP function hosted on Vercel. The function operates at 2:15 AM UTC, 6:15 AM UTC, 2:15 PM UTC. This schedule corresponds to strategically chosen times that cater to a wide range of time zones, maximizing the likelihood that patients are alerted at convenient times for medication adherence.

Upon activation, the Vercel function executes a series of steps that involve fetching data from Patient Encounters, Patients Data, and Device Details APIs. The data from these APIs is then combined and processed to determine which patients are eligible for a reminder at any given time. Eligible patients receive a personalized notification message created by the system, which is sent to their devices using Firebase's notification service.

Each notification sent is logged, capturing both successful deliveries and any failures. These logs are stored in a Postgres table named notification_logs, providing a comprehensive audit trail for system accountability and traceability.

Automated Medication Reminder process flow

Process Flow Steps

Here are the steps outlined in a sequential process flow:

  1. GitHub Actions/Cron Job: Executes the automated task on a scheduled basis, four times a day, to trigger the medication reminder system.

  2. Vercel HTTP Function: Acts as the operational hub, initiating the medication reminder workflow by gathering data from multiple sources.

  3. Patient Encounters API Fetch: Collects data on patient encounters, including prescription details and scheduled medication times.

  4. Patients Data API Fetch: Retrieves patient-specific information such as names and contact details to personalize the reminders.

  5. Device Details API Fetch: Gathers device information to identify the patient's preferred notification delivery method and device tokens.

  6. Process & Merge Data: Integrates data from the previous steps, preparing a consolidated view of each patient's information and scheduled medications.

  7. Check Eligibility: Evaluates the consolidated data to determine which patients are due to receive their medication reminders based on the current time and their schedule.

  8. Create Notification Message: For eligible patients, crafts a tailored notification message that includes personalized instructions or reminders to take medications.

  9. Send Firebase Notification: Dispatches the prepared notification messages to the appropriate devices through Firebase Cloud Messaging service.

  10. Log Notification Success/Failure: Monitors the outcome of each notification sent and records the status, capturing successful deliveries and noting any failures.

  11. notification_logs Table: Aggregates the success and failure logs in a Postgres table named notification_logs, providing a comprehensive audit trail for system monitoring and performance evaluation.

Components

ComponentDescription
GitHub ActionsTriggers the Vercel-hosted HTTP function based on a cron schedule.
Vercel HTTP FunctionProcesses patient data, checks eligibility, and sends notifications.
FirebaseUsed for sending push notifications to patients' devices.
Database/API CallsFetch patient encounters, patient details, and device information through specified API endpoints.

Prerequisites:

  • npm Packages: node-fetch for API requests, lodash for data manipulation.
  • Firebase Setup: Configured Firebase project with proper authentication.
  • Utility Functions:
FunctionDescription
dosageTextEquivalent()Converts dosage strings into human-readable times for notification messages.
sendMedicationReminders()Main function to process and send reminders, utilizing other utility functions for customization.
createNotificationMessage()Crafts custom notification messages based on patient name and dosage times.
getCurrentTimePeriod()Determines the current time period (morning, noon, evening, night) for sending reminders.

Github Actions Worklfow

name: healthbuddy medication reminders

on:
workflow_dispatch:
schedule:
# Runs at 2:15 AM UTC (7:45 AM IST) every day
- cron: '15 2 * * *'
# Runs at 6:15 AM UTC (11:45 AM IST) every day
- cron: '15 6 * * *'
# Runs at 2:15 PM UTC (7:45 PM IST) every day
- cron: '15 14 * * *'

jobs:
make-request:
runs-on: ubuntu-latest
steps:
- name: Curl request
run: curl https://api.zynomi.com/api/v1/reminders

Diagram as code