Inspiration

Primary health centers are often the only point of care for a community, and they run on limited staff, shared devices and unreliable internet. Triage there can't depend on a cloud connection, and sending patient symptoms off-device isn't always appropriate. We wanted to see how far hybrid AI could go here: run the model on the device when possible, use the cloud when it isn't, and never leave the clinic without an answer.

What it does

MediGuide is a patient-flow and triage platform for primary health centers. It covers patient registration, symptom intake, a priority queue, records, prescriptions, referrals, pharmacy, and offline sync with conflict handling.

For this hackathon we moved its AI onto Firebase AI Logic hybrid inference:

  • Clinical triage uses InferenceMode. In desktop Chrome with Gemini Nano available, the assessment runs locally. Otherwise the same call goes to gemini-3.5-flash-lite in the cloud.
  • Rule engine as the last resort. If the AI is unavailable, offline or returns unusable output, a deterministic rule-based scorer still produces a priority. Triage never fails silently.
  • Clinical safety guard. For red-flag symptoms (chest pain, breathing difficulty, stroke signs, severe bleeding, loss of consciousness), the AI can confirm or raise the priority but never lower it below the rule baseline.
  • Inference transparency. Every assessment shows where it came from: On-device, Cloud, or Clinical Rule Engine, and the source is saved with the record.
  • Hybrid Health Guide. A new patient health-education screen that uses the same hybrid setup, with a system prompt that avoids diagnosis and points to emergency care when needed.

How we built it

React 18 + TypeScript + Vite + Tailwind on the front end, with Firebase Authentication, Firestore and App Check protecting AI calls. The AI layer lives in src/lib/hybridAIService.ts and src/lib/geminiService.ts. Each feature (triage and Health Guide) has its own model instance with its own system prompt, passed to the cloud through systemInstruction and to Gemini Nano through the Prompt API's initialPrompts. The AI output is parsed defensively, then clamped and validated before it can affect a priority.

Built before vs. during the hackathon

MediGuide already existed as a non-AI-hybrid platform (queue, records, prescriptions, offline sync and more). During the hackathon period we built: the Firebase AI Logic hybrid integration, the shared App Check setup, the triage migration with the safety guard and rule fallback, the inference-source badge and storage, the Health Guide screen, security rules hardening, and the documentation.

Challenges

  • Shared model, wrong prompt Our first version reused one model for both features, so the cloud triage call inherited a health-education system prompt and broke the JSON output. We split them into separate instances.
  • On-device models need their own system prompt. We first set the system instruction only for the cloud, which left Gemini Nano without the safety rules. Passing it through initialPrompts fixed that.
  • Small models and JSON. On-device output is less predictable, so we validate and clamp everything and fall back to the rule engine when parsing fails.
  • Moving targets. Gemini 2.5 models are being deprecated, so we moved to gemini-3.5-flash-lite, and App Check enforcement meant the cloud path needed proper attestation setup.

What we learned

Hybrid AI is more than a performance trick: it changes what a clinic can rely on. The hard part wasn't calling a model, it was deciding what happens when the model is missing, wrong or offline, and making that visible to the user.

Limitations

This is a prototype, not a medical device. The AI triage has not been clinically validated, and an under-triage error could delay care, which is why the guard and the rule engine exist.

What's next

A held-out evaluation of triage accuracy and under-triage rate against published triage criteria, clinician review of the rules, and testing on real PHC workflows.

Built With

Share this project:

Updates

Submission history