Delivered remotely for a business based in Oslo, Norway. Names withheld by agreement.
Project Overview
Missing a blood-pressure tablet or double-dosing an evening anticoagulant rarely stems from carelessness alone. For patients living with diabetes, cardiovascular disease, or post-transplant regimens in Oslo, medication schedules quickly fragment across multiple clinics, shifting dosages, and paper blister packs. When a reminder app relies on constant cellular connectivity or blasts vague chimes that disappear from a lock screen, adherence drops precisely when routines become stressful.
We engineered an offline-first medication adherence application using Flutter and Firebase to give patients reliable, distraction-free dosing guidance across iOS and Android. Every scheduled dose lives inside a local encrypted SQLite ledger paired with native operating-system alarms, while Cloud Firestore and serverless Cloud Functions coordinate optional caregiver visibility, refill warnings, and structured clinical summaries.
Adherence & Mobile Reliability Gaps
Existing consumer pill-reminder tools routinely break under real-world clinical and mobile OS constraints:
- Cloud-tethered notifications: Apps driven purely by server push messages miss firing windows inside basements, ferries, or rural mountain tunnels without signal.
- Rigid daily recurrence: Standard alarm clocks cannot express tapering prednisone schedules, every-other-day warfarin rotations, or maximum-daily PRN rescue rules.
- Aggressive OS background throttling: Modern Android Doze modes and iOS background execution limits silently kill unanchored timer services within days of install.
- All-or-nothing caregiver sharing: Caregivers either lack timely visibility when an elderly parent skips critical morning doses, or receive noisy alerts for every minor schedule shift.
Architectural Strategy
The engineering blueprint inverted typical mobile cloud design: the phone is the source of truth for timing, and Firebase is the asynchronous coordination plane. Flutter writes every regimen rule and dose action into a local SQLite database via Drift first, ensuring instant UI responsiveness and zero dependency on network round-trips.
Because iOS caps pending local notifications per app and Android restricts background wakeups, the client runs a deterministic schedule compiler. Whenever a prescription changes, the app opens, or a dose is logged, the compiler regenerates the next 14 days of concrete alarm triggers and registers them directly with native notification channels. Background sync workers then replicate confirmed, snoozed, and skipped dose events into Cloud Firestore using idempotent event keys.
Core Capabilities
- Typed Regimen Rule Engine: Supports fixed daily times, cyclic N-day intervals, multi-phase dose tapers, and PRN medications gated by minimum lockout hours and 24-hour caps.
- Interactive Notification Actions: Patients confirm "Taken", trigger a bounded 15-minute snooze, or log a structured skip reason directly from the lock screen without opening the full app.
- Refill & Inventory Countdown: Tracks remaining tablet counts against active consumption rates and raises early pharmacy renewal prompts before stock runs out.
- Tiered Caregiver Escalation: Configurable grace windows let a patient delay a dose briefly without alarming family members, escalating via Firebase Cloud Messaging only after an unconfirmed cutoff expires.
- Accessible Senior-Friendly Mode: High-contrast typography, large tap targets, and spoken confirmation cues support patients with reduced dexterity or visual impairment.
- Appointment Adherence Reports: Exports clean multi-week compliance timelines directly from local history for review with general practitioners and community pharmacists.
Technical Architecture
The Flutter application isolates domain rules from Firebase transport so the clinical state machine behaves identically online and offline. Platform channels bridge Dart business logic to Android exact-alarm scheduling and iOS notification categories, while Firebase Auth, Cloud Firestore, and Cloud Functions manage multi-device reconciliation and caregiver alerting.
Flow: Flutter Regimen Editor → SQLite (Drift) Outbox → Native OS Alarm Scheduler → Lock-Screen Dose Action → Cloud Firestore Sync → Firebase Cloud Functions Grace-Window Evaluator → FCM Caregiver Alert
Separating the local event log from Cloud Firestore documents eliminates race conditions when a patient carries both a phone and a tablet. Each dose action appends an immutable event record stamped with device monotonic metadata and local wall-clock time; Firestore security rules validate schema integrity before triggering downstream escalation checks.
Technology Stack
| Category | Technology detail |
|---|---|
| Mobile Client | Flutter and Dart single codebase targeting iOS and Android with accessibility scaling |
| Local Persistence | Encrypted SQLite (Drift) storing active regimens, dose state machines, and offline mutations |
| Alarm & Notification Engine | OS exact-alarm and UNUserNotificationCenter local triggers independent of network state |
| Backend Platform | Firebase project suite coordinating identity, data sync, and serverless rules |
| Cloud Synchronization | Cloud Firestore multi-device state sync with idempotent client event IDs |
| Escalation Workers | TypeScript Cloud Functions evaluating missed-dose grace periods and caregiver routing |
| Push Delivery | Firebase Cloud Messaging (FCM) delivering silent schedule updates and caregiver alerts |
| Authentication & Consent | Firebase Auth with biometric app lock and scoped caregiver invitation tokens |
| Clinical Reporting | On-device PDF adherence summary builder for outpatient GP and pharmacy reviews |
Engineering Trade-offs & Solutions
| Engineering Challenge | Solution & Trade-off |
|---|---|
| iOS 64-notification ceiling truncates long-term medication schedules | Implemented a rolling 14-day schedule horizon refreshed on every app open, action, and background fetch; trades unlimited static pre-scheduling for guaranteed near-term accuracy across multi-drug profiles. |
| Android OEM battery managers suppress recurring background reminders | Used SCHEDULE_EXACT_ALARM with dedicated high-priority notification channels and a guided onboarding battery-exemption check, accepting an extra permission prompt for dependable chime delivery. |
| Caregiver alerts fire falsely during transient offline periods | Added a server-side grace buffer plus retroactive reconciliation check in Cloud Functions so delayed offline confirmations cancel pending escalations where possible; trades immediate zero-minute alerting for far fewer false alarms. |
| Time-zone travel breaks strict hourly vs. morning meal routines | Separated regimens into wall-clock-anchored and UTC-interval-anchored types, rebuilding local triggers on OS timezone change events; adds regimen setup metadata while preventing accidental double-dosing on flights. |
Security & Privacy Architecture
Medication lists reveal sensitive diagnoses, making privacy-by-design essential under European GDPR expectations. Local SQLite storage is encrypted with keys wrapped by the iOS Keychain and Android Keystore, and an optional biometric gate shields prescription details even when a phone is unlocked.
On the Firebase side, Cloud Firestore security rules enforce strict ownership boundaries so patients control exactly which caregiver UIDs can view adherence summaries—and whether specific drug names are masked behind generic labels such as "Morning Schedule". Caregiver links use short-lived, single-use invitation codes that can be revoked immediately from the patient's settings screen, halting further FCM notifications.
Reliability & Sync Scale
Because adherence events are append-only state transitions rather than broad document overwrites, Firestore sync remains lightweight even for patients logging ten or more daily doses. Outbox batching coalesces rapid confirmation taps into compact writes once connectivity returns, keeping battery drain negligible.
On the serverless side, Cloud Functions process scheduled grace-window evaluations through partitioned time-bucket queries rather than full-collection scans. Indexing pending confirmation windows by rounded target timestamps keeps lookup costs predictable as active patient cohorts grow.
Operational Outcomes
Moving medication scheduling from fragile cloud timers to a deterministic local-first engine paired with Firebase coordination produced clear day-to-day benefits for patients and care circles:
- Dependable offline reminders: Patients receive accurate, on-time prompts regardless of roaming restrictions, subway commutes, or rural dead zones.
- Calm, targeted caregiver support: Family members stay informed about genuine missed-dose risks without drowning in constant check-in messages or false alarms.
- Support for realistic prescriptions: Multi-phase tapers, cyclic schedules, and rescue medications live inside one coherent timeline instead of requiring separate sticky notes.
- Actionable clinical conversations: General practitioners and pharmacists review concise, verifiable adherence patterns during consultations rather than relying on patient recall.