Inspiration

Cholera can kill within hours, so the first suspected cases need to reach the district quickly. What slows them down is a step nobody sees: a community health worker writes a note in a notebook, and later someone retypes it into a reporting form. During the 2018 cholera outbreak in the South West Region of Cameroon, average timeliness of routine surveillance (IDSR) reporting was 16.3%, and the authors concluded that routine data could not give early warning of that outbreak (PMC9903268).

The easy answer would be to send the note to a cloud model and let it fill the form. Those notes contain children's names, mothers' phone numbers and directions to a house, so I didn't want them leaving the phone. Firebase AI Logic lets one code path run Gemini Nano on the device or Gemini in the cloud, and I built the app around a single rule: which model may read a piece of data depends on how identifying that data is.

What it does

OutbreakPulse has a field side and a county side.

On the field side, a health worker types a note the way they would write it in a notebook, or photographs a paper note. The app removes identifiers with a deterministic scrubber, extracts the case (age band, sex, symptoms, danger signs, sick or dead household members), sets a risk level with a rules engine and checks the case against the GTFCC suspected cholera definition. The worker reviews every field before saving. The saved record is a fixed list of 25 fields enforced by Firestore security rules, and the only text in it is a short de-identified summary. It is written to Firestore without waiting for the network, so the flow works offline and syncs later.

Where the AI runs depends on what it is about to read:

  • The raw note only goes to Gemini Nano, through an ONLY_ON_DEVICE model. The SDK has no cloud fallback to take with it. Nano extracts the fields and lists identifiers the scrubber missed.
  • A photo of a paper note is also ONLY_ON_DEVICE. A photo can't be scrubbed before upload, so it has no cloud path at all.
  • Without Nano, the worker sees the exact de-identified text and decides whether to send it to a PREFER_ON_DEVICE model, which falls back to Gemini in the cloud.
  • Offline without Nano, keyword extraction fills the form and the scrubbed text waits in an IndexedDB queue until the connection comes back.

The rules engine sets a floor. The AI can raise the risk level with a stated reason and can never lower it.

On the county side, cases are aggregated per sub-county by deterministic code. Alert thresholds come from Remote Config, and the GTFCC cholera alert is built in: two or more people aged 2 or older with acute watery diarrhoea and severe dehydration, or dying of it, in the same sub-county. The dashboard has a map of the fictional county, an epidemic curve by onset day and a button to declare an outbreak in a sub-county. A declaration switches field triage there to the outbreak case definition, offline too. Gemini in the cloud (ONLY_IN_CLOUD) drafts a situation report from the aggregate table only, and the dashboard shows the exact payload it sent.

Two pages exist so that nobody has to take my word for the privacy claims. System has a ledger of every request that carried content off the device during the session, with the exact content, next to the AI calls that stayed on it. Evidence runs a labelled set of fictional notes through each tier and scores it in the browser.

How I built it

  • Next.js as a static export with strict TypeScript and Tailwind, hosted on Firebase Hosting. A hand-written service worker caches the app shell so it opens offline.
  • Firebase AI Logic with four model instances: raw note, photo, scrubbed note and situation report. On-device responseConstraint and cloud responseSchema share one schema, and zod validates every response. Each result records inferenceSource and latency, and the UI shows both. The hosted demo uses the Agent Platform backend.
  • App Check with reCAPTCHA Enterprise, enforced for AI Logic. Anonymous Auth for a one-click guest login, where each guest gets a private workspace.
  • Firestore with a persistent local cache, writes that are never awaited, pending-sync state read from snapshot metadata and security rules with a field allowlist.
  • Remote Config for alert thresholds, time windows, the situation report model and the privacy gate.
  • 71 Vitest unit tests covering the scrubber, the rules engine and GTFCC definitions, risk merging, routing, aggregation, alert detection, the epidemic curve, the egress ledger and the evaluation scores. GitHub Actions runs them on every push.

Challenges I ran into

Measuring my own scrubber was humbling. I wrote fictional notes with planted names, phone numbers, IDs and addresses, and the first runs showed an ID with a letter prefix leaking through and names written without a title getting missed. I fixed both, then noticed I had tuned the scrubber on the same notes I was scoring it with. So I wrote a second set of 12 notes and never tuned on it. The scrubber still misses 1 identifier out of 26 there. I left that number in the README, because it is the best argument for sending raw notes only to Nano.

My first rules used an under-5 age band. The GTFCC definition splits at 2 years and changes once an outbreak is declared, so I changed the bands and added the declaration. Records already stored had the old band, so the schema reads it as unknown instead of rejecting the record. Those records also had no suspected cholera field, and the new epidemic curve showed zero suspected cases in a cluster that obviously had some. Records without the field are now classified with the standard definition.

Gemini Nano is slow on my PC. On the held-out notes the median was 24 040 ms per note, against 1 726 ms in the cloud, and the SDK can't cancel an on-device prompt. I kept Nano for raw notes and added an elapsed-time counter with a "Continue with the rules engine" button, so a worker in a hurry is never stuck. Nano also gets things wrong. While I recorded the demo, it ticked vomiting and fever on a note that said "no vomiting" and "no fever". This is why the worker reviews every field before the case is saved.

Chrome on Android doesn't expose Gemini Nano to web pages. On my phone the photo button was greyed out with a message that looked like a bug, so I rewrote it to say that photos are only read by Nano on a computer and never sent to the cloud.

Accomplishments that I'm proud of

On the held-out notes, Gemini Nano removed all 26 identifiers and nothing identifiable left the device. The cloud path, which only sees scrubbed text, let 1 through. With either AI tier the rules engine under-triaged none of the 12 cases, against 2 with keyword extraction alone.

Danger signs are where the AI matters most. I score them with

$$F_1 = \frac{2 \cdot P \cdot R}{P + R}$$

where P is precision and R is recall over the danger sign codes. Keyword extraction gets 0.63, and Gemini Nano gets 0.95, the same as the cloud model.

The privacy claim can be checked inside the app, in the egress ledger, and the whole field flow works with the network off.

What I learned

The inference mode works as a privacy setting. Choosing ONLY_ON_DEVICE for raw notes removes a whole class of leak, because there is no fallback left to misconfigure.

Nano follows a JSON schema well enough to share one schema with the cloud model, and the zod layer turns a bad value into a safe default instead of a crash.

My development set said 40 of 40 identifiers removed. The held-out set said 25 of 26. I trust the second number more.

What's next for OutbreakPulse

  • Test it with consented field notes and county staff, under ethics review, before anyone relies on it.
  • An Android app with Gemini Nano through Firebase AI Logic, since many health workers only carry a phone.
  • Notes written in Kiswahili and French.
  • Organisation workspaces instead of guest sandboxes, and more syndromes after acute watery diarrhoea.

Built With

  • chrome-prompt-api
  • cloud-firestore
  • firebase
  • firebase-ai-logic
  • firebase-app-check
  • firebase-authentication
  • firebase-hosting
  • firebase-remote-config
  • gemini
  • gemini-nano
  • github
  • indexeddb
  • next.js
  • react
  • recaptcha-enterprise
  • service-worker
  • tailwind-css
  • typescript
  • vitest
  • zod
Share this project:

Updates

Submission history