PharmaSense: Coverage-Aware Prescription Decision Engine

College is the first time a lot of people manage prescriptions without someone translating the whole process.

You show up expecting a quick pickup. Instead you get a price you did not expect, a medication name you cannot pronounce, and that quiet worry: is this safe with my allergies, or with something I already take?

That gap is why we built PharmaSense.

PharmaSense is a point-of-care tool that, before anyone pays or takes anything, shows three side-by-side options (Best Covered, Cheapest, Clinical Backup), surfaces the real copay, runs hard safety checks that can block allergy reactions, severe drug interactions, dosing mistakes, and duplicate therapies, then generates plain-language, bilingual, voice-ready instructions so patients actually understand what they are taking.


The Problem

Prescribing is not one problem. It is three problems that collide at the worst time.

1) Safety can fail under time pressure

Allergies, drug interactions, dose range mistakes, and duplicate therapies are easy to miss when the workflow is rushed.

2) Coverage decides what is actually possible

A clinically strong option means nothing if it is not covered, is unaffordable, or gets rejected at the pharmacy.

3) Understanding determines what happens next

If the patient leaves unsure, the prescription is functionally incomplete.

Most systems handle one of these well and ignore the others. In the real world, they stack.


The Solution

PharmaSense combines artificial intelligence (AI) assistance with deterministic enforcement and patient accessibility in one workflow.

1) Coverage-aware recommendation lanes

Instead of pretending there is one perfect answer, PharmaSense presents three lanes clinicians can act on instantly:

  • Best Covered: optimized for coverage
  • Cheapest: lowest out-of-pocket path
  • Clinical Backup: reasonable alternative if coverage or supply fails

2) Deterministic safety enforcement (cannot be overridden)

AI can propose options, but approval is gated by a rules engine that runs:

  • Allergy detection (including cross-reactivity via drug-class mapping)
  • Drug-drug interactions
  • Dose range validation
  • Duplicate therapy detection

If a prescription is safety-blocked, it cannot be approved.

3) Patient understanding layer (accessibility-first)

After approval, PharmaSense generates a patient pack designed for real comprehension:

  • Plain-language instructions (generated by AI)
  • English and Spanish support
  • Text-to-speech (TTS) voice packs for instructions
  • Drug name pronunciation support
  • Medication schedule view
  • Side effect triage and avoid list
  • Accessibility toolbar
    • high contrast
    • dyslexia-friendly font
    • large type
    • reduced motion
  • Screen reader announcements, skip links, and keyboard navigation

What Makes It Different

We treated PharmaSense like a decision engine, not a chatbot.

The model suggests. The system enforces.

That separation is the trust model:

  • AI handles messy input and generates options fast
  • Deterministic checks keep the workflow safe and auditable
  • Coverage logic makes recommendations realistic
  • Patient output is built for comprehension, not just completeness

We also built for failure instead of assuming every dependency is always available:

  • Voice generation falls back to a silent pack if the text-to-speech provider fails
  • Storage has fallback paths so development and demos do not break
  • Analytics dual-writes without blocking the clinician flow
  • Dashboard queries run Snowflake-first with a PostgreSQL fallback when needed

How We Built It

Backend (FastAPI, Python)

  • Python 3.11 + FastAPI
  • Asynchronous SQLAlchemy + Alembic migrations
  • Service-based architecture to isolate responsibilities

Key services:

  • Prescription orchestration (recommend → validate → approve or reject → generate outputs)
  • Gemini gateway (recommendations, extraction, optical character recognition, chat, patient instructions)
  • Rules engine (deterministic safety checks)
  • Formulary service (coverage status, tier, copay, cheaper alternatives)
  • Voice service (ElevenLabs text-to-speech packs)
  • Portable document format (PDF) generation (ReportLab)
  • Analytics emission + Snowflake synchronization

Centralized prompts:
Role → Context → Task → Constraints → Output Schema

Frontend (React 19, TypeScript)

  • React 19 + TypeScript + Vite + Tailwind CSS v4

Zustand state stores:

  • Authentication
  • User interface preferences and accessibility
  • Visits and extraction workflow
  • Prescription recommendation and approval flow

Axios client with:

  • Bearer token injection
  • Response envelope unwrapping
  • Automatic sign-out on unauthorized responses

  • Framer Motion transitions with reduced motion support


Data and Integrations

  • Supabase PostgreSQL as primary database + authentication using JavaScript Web Token (JWT) role-based access
  • Supabase Realtime for the handwriting drawing channel
  • Snowflake for analytics warehouse + materialized views powering dashboard queries
  • Google Gemini application programming interface (API) for recommendations, extraction, optical character recognition, chat, and patient packs
  • ElevenLabs for text-to-speech voice instructions
  • Simple Storage Service (S3)-compatible object storage for PDF files, images, and voice packs

The Technical Challenge

Building something that feels fast and helpful like AI, while staying safe and enforceable like clinical software.

That meant:

  • Schema-first outputs
  • Server-side validation
  • Deterministic blocking
  • A user interface that shows tradeoffs instead of hiding them

Challenges We Ran Into

1) Handwriting is a real workflow, not an edge case

We needed a path that works when notes are not clean text. The tablet drawing flow plus vision extraction closed that gap.

2) Preventing confident-but-wrong model outputs

We enforced structured schemas and validation, then gated approval behind deterministic checks.

3) Making coverage legible in seconds

Clinicians do not want a pricing spreadsheet mid-visit. The three-lane layout communicates the decision instantly.

4) Reliability across multiple services

External systems fail. We designed graceful degradation so the visit flow still completes and the system stays usable.


Accomplishments We Are Proud Of

  • End-to-end prescription workflow with hard safety blocks
  • Three-lane coverage-aware decision interface that reduces surprises at pickup
  • Real-time tablet handwriting capture plus extraction into clinical notes
  • Patient packs that are plain-language, bilingual, and voice-ready
  • Snowflake-backed analytics with fallbacks for resilience
  • Accessibility features applied across the entire product, not just one page

What We Learned

  • AI only helps in healthcare when the system can say no for the right reasons.
  • Cost and coverage are not billing details. They decide whether treatment happens.
  • The last mile is comprehension. Voice, language, and readability are adherence features.
  • Systems engineering matters more than any one model call.

The Vision

A world where picking up a prescription does not feel like a surprise exam.

Where clinicians prescribe with safety rails. Where coverage is handled before the patient reaches the counter. Where patients leave with instructions they can actually follow.

That is PharmaSense.

Built With

Share this project:

Updates