Low-Level Design: Pharmacy Prescription System — Drug Interactions, Refills, Insurance Adjudication, and Dispensing

Core Entities

Patient: (patient_id, name, dob, allergies[], insurance_id, primary_care_provider_id). Prescription: (rx_id, patient_id, prescriber_id, drug_ndc, drug_name, dosage, quantity, days_supply, refills_remaining, written_date, expiry_date, status=ACTIVE|FILLED|CANCELLED|EXPIRED). Fill: (fill_id, rx_id, fill_number, dispensed_quantity, dispensed_date, pharmacist_id, insurance_claim_id, patient_copay_cents, status). Drug: (ndc, name, generic_name, drug_class, is_controlled, schedule, manufacturer). DrugInteraction: (drug_ndc_a, drug_ndc_b, severity=MINOR|MODERATE|MAJOR|CONTRAINDICATED, description).

Drug Interaction Checking

Before dispensing any prescription: check for drug interactions with the patient’s current active medications. Algorithm: retrieve all active prescriptions for the patient (status=ACTIVE, refills_remaining > 0, not expired). For the new prescription drug: query DrugInteraction table for (new_drug, each_active_drug) pairs. Flag interactions by severity: MINOR: log and continue. MODERATE: display warning to pharmacist, require acknowledgment. MAJOR: require pharmacist override with documented reason. CONTRAINDICATED: block dispensing entirely, require prescriber contact. Allergy check: compare drug’s allergy_cross_reactivity field against patient.allergies. Therapeutic duplication: flag if patient already has an active prescription in the same drug class (e.g., two antidepressants). Alert the pharmacist but do not block — therapeutic duplication is sometimes intentional.

Refill Management

Refill eligibility: a prescription can be refilled when refills_remaining > 0 and the prescription is not expired. Early refill rules: for non-controlled medications, allow refill when >= 75% of the supply has been used (fill_date + 0.75 * days_supply 0. Create a refill request and notify the patient. Refill reminders: send push notification or SMS 3 days before running out (fill_date + days_supply – 3 = today).

Insurance Adjudication

Insurance adjudication determines the patient’s copay. Flow: pharmacist submits a claim to the patient’s insurance (PBM — Pharmacy Benefit Manager) via the NCPDP standard protocol. Claim includes: patient insurance ID, drug NDC, quantity, days supply, prescriber NPI, pharmacy NPI. PBM responds with: copay amount (patient responsibility), plan paid amount, rejection reason if denied. Rejection codes: 70 (drug not covered on formulary — needs prior authorization), 75 (refill too soon), 88 (DUR — drug utilization review conflict). On rejection: pharmacist reviews the rejection code. Options: process as cash pay, request prior authorization, select an alternative drug. Store the adjudication response on the Fill record for audit.

Controlled Substance Compliance

Controlled substances (opioids, benzodiazepines, stimulants) require: state PDMP (Prescription Drug Monitoring Program) reporting — submit each dispensed controlled substance fill to the state PDMP database within 24 hours (often real-time required). PDMP query: before dispensing, query the patient’s PDMP history to detect “doctor shopping” (obtaining controlled substances from multiple prescribers). Red flags: 3+ prescribers for the same drug class in 90 days, overlapping fills from different pharmacies. Schedule II restrictions: no refills allowed. Each fill requires a new prescription. Paper or electronic prescription only (no verbal orders). Audit trail: all access to Schedule II prescription records is logged with the accessor, timestamp, and reason.

Interview Tips

  • Drug interaction checking is the most safety-critical feature. Emphasize fail-safe behavior: on any system error during interaction checking, default to blocking the fill until manually reviewed.
  • The insurance adjudication flow (NCPDP protocol) is real-world pharmacy-specific knowledge. In an interview, describe the pattern (submit claim, receive copay or rejection, handle rejection) without needing to know the exact protocol details.
  • Controlled substance compliance is a regulatory requirement with serious legal consequences for violations. Always flag this as needing legal/compliance team involvement in the design phase.

Asked at: Stripe Interview Guide

Asked at: Atlassian Interview Guide

Asked at: Shopify Interview Guide

Asked at: DoorDash Interview Guide

Scroll to Top