Inspiration
Millions of people around the world—especially in regions with unreliable mobile data or limited clinic access—need fast, private, and medically responsible health guidance even when offline. At the same time, sensitive patient records, child safety, and life-threatening emergencies require strict privacy controls and instant fail-safe escalation. We upgraded HealthConnect into a universal, installable Hybrid AI healthcare Progressive Web App (PWA) that works on any device, online or offline.
What it does
HealthConnect is an adaptive, family-ready healthcare PWA built around Hybrid AI and patient safety:
- Hybrid AI Health Assistant (On-Device + Cloud + Offline): Powered by Firebase AI Logic (
firebase/ai) withInferenceMode.PREFER_ON_DEVICEandInferenceMode.ONLY_ON_DEVICE. On supported Chrome devices with Gemini Nano, prompts run locally on-device with zero latency and maximum privacy; otherwise, HealthConnect seamlessly falls back to Cloud AI (Gemini) or its bundled offline verified medical library. Every message shows an honest badge indicating the actual execution path used (Local On-Device,Hybrid,Cloud,Offline Library, orSafety Middleware). - Verified Medical Knowledge & Interactive Triage (Local & Cloud): Grounded in curated references from the Human Disease Ontology (DOID), WHO ICD-11, and MedlinePlus, plus a live openFDA Drug Lookup tab. When a user says "I feel sick", both Local AI and Cloud AI ask ChatGPT-style clarifying follow-up questions with clickable quick-reply chips.
- Medical Red-Flag Keyword Filtering Middleware: A dual-layer (client + Express server) safety middleware scans every user message and AI output for emergency red flags (e.g., shortness of breath, unconscious, chest pain, severe bleeding, seizures). When detected, it halts educational dialogue immediately, appends
Urgent: Seek Professional Care, and links directly to the Emergency Centre. - Multimodal Emergency / Accident Photo Upload: Users can upload or snap a photo of an injury, burn, rash, or medication label. Online, Cloud AI Vision assists with first-aid education; offline, HealthConnect switches automatically to structured offline first-aid triage checklists.
- Age- & Gender-Adaptive Dashboard with Strict Child Safety: Pre-account health onboarding (and post-Google Sign-In completion) collects Date of Birth, confirmed gender, blood group, genotype, allergies, and ICE contacts. The dashboard adapts across 5 life stages (Children 0–12, Teenagers 13–17, Young Adults 18–30, Adults 31–50, Older Adults 51+) across a 120-capability blueprint. Ages 0–12 strictly lock into Guardian Child Safety Mode, hiding all adult and reproductive modules.
- Smartwatch & Wearable Hub + GPS Emergency Escalation: Connects via Web Bluetooth GATT (plus labeled demo simulation presets for testing), monitors configurable critical vital thresholds, triggers a 15-second cancellable emergency countdown, ranks nearest 24/7 hospitals using browser GPS, and provides 1-tap emergency dialing.
- 100% Local Offline Emergency Medical QR Code: Generates a high-contrast Medical ID QR code directly in the browser (no external QR servers) with privacy field toggles and PNG export for phone lockscreens or smartwatch faces.
How we built it
- Frontend & PWA: React 19, TypeScript, Tailwind CSS, Vite 8, and
vite-plugin-pwa(Workbox service worker withNetworkOnlyprivacy rules for Firestore/Auth/API routes and precached offline UI + medical guides). - Hybrid AI Architecture: Firebase AI Logic SDK (
firebase/ai—getAI,GoogleAIBackend,getGenerativeModel,InferenceMode) integrated with a unified Hybrid AI Router, client/server Medical Red-Flag Middleware, and an Express backend proxy for Gemini Vision, openFDA drug lookup, and secure server-side API key isolation. - Data & Security: Firebase Authentication (Email/Password + Google Sign-In) and Cloud Firestore with owner-scoped RBAC security rules (
firestore.rules) and explicit one-time + per-chat consent before sending personal health profile context to Cloud AI. - Hardware & Offline Utilities: Web Bluetooth API for wearable heart-rate sensors, HTML5 Geolocation for nearest-hospital ranking, and local SVG/PNG QR generation via
qrcode. - Testing: Automated Vitest suite covering 47 unit and integration tests across Hybrid AI routing, Red-Flag middleware, DOID ontology intake, Child Safety gating, Smartwatch escalation, Offline QR, and Firestore/RBAC rules.
Challenges we ran into
- Supporting every phone & browser gracefully: Not all mobile browsers expose Chrome's built-in Gemini Nano Prompt API yet. We solved this by building a 3-tier Hybrid fallback chain (On-Device Gemini Nano → Cloud AI via Firebase AI Logic / Gemini → Curated Offline DOID/WHO/MedlinePlus Engine) so no user is ever left stranded offline.
- Balancing AI helpfulness with clinical safety: Ensuring neither local nor cloud models continue chatting during a life-threatening emergency required intercepting both incoming prompts and outgoing AI responses with deterministic red-flag middleware.
- Strict privacy for patient health data: Ensuring PWA service workers never cache private Firestore records (
NetworkOnlyrules), keeping API keys strictly server-side, and generating Emergency Medical QR codes 100% client-side.
Accomplishments that we're proud of
- Full offline-first Hybrid AI healthcare experience that works smoothly even in Airplane Mode.
- 47/47 automated tests passing across AI safety, clinical intake, child protection, wearables, and backend security.
- Complete Guardian Child Safety Mode preventing exposure of adult modules to users under 13.
- Instant Emergency Medical QR + GPS hospital finder + Red-Flag middleware working together as a cohesive safety net.
What we learned
- Hybrid AI shines brightest in healthcare when on-device inference handles fast, private everyday triage and seamlessly hands off complex or multimodal (photo) cases to the cloud—while always guaranteeing an offline fallback.
- Honest transparency badges (showing whether a response actually ran On-Device, in the Cloud, or Offline) build user trust far better than hiding AI routing behind a black box.
What's next for HealthConnect
- Companion native smartwatch integration (Wear OS / Apple Watch) for continuous background SpO2 and fall-detection telemetry synced to HealthConnect's emergency escalation flow.
- Multilingual offline medical guides and voice-guided triage for low-literacy and rural communities.
- Expanded clinician-verified hospital directory coverage across more regions globally.
Built With
- cloud-firestore
- express.js
- firebase
- firebase-ai-logic
- firebase-authentication
- gemini-api
- gemini-nano
- google-drive-api
- google-maps-platform
- health-2.0
- interswitch
- node.js
- pwa
- react
- recharts
- tailwindcss
- twilio
- typescript
- vite
- vitest
- zod