Skip to content

[Audit & Fixes] Offline 41k Formulary Persistence, Drug Autocomplete Ranking, Clinical Safety Guardrails & WCAG A11y #2

Open

Description

@refat247

Overview & Clinical Appreciation

Dear Dr. Gazi Md Emran Ahmed (@eabgitbd),

First of all, congratulations and sincere appreciation on building PrescribePro-Rx! As general practitioners and medical software developers practicing in Bangladesh, an open-source, local-first digital prescription pad designed specifically around ISO 216 A4 physical dimensions and the BMDC workflow is a tremendous service to our medical community.

After a deep architectural, clinical safety, and UI/UX audit of the codebase (v3.0 Pro), we identified several key clinical, offline, and accessibility defects that affect real-world practice. We have already developed, tested, and pushed a complete, non-breaking Pull Request fixing every single one of these items.

Here is the comprehensive breakdown of the issues identified and addressed:


1. 🚨 Offline Architecture & 41k Drug Catalog Persistence Failure

  • The Issue:
    1. data/drugs.json is 5.42 MB (stringified in UTF-8). Standard browser localStorage enforces a strict 5 MB origin quota.
    2. In scripts.js, localStorage.setItem('prescribepro_cached_drugs', ...) throws an unhandled QuotaExceededError on every session and fails silently.
    3. Crucially, there is no Service Worker registered (sw.js did not exist in the repo).
    4. Clinical Consequence: If a doctor opens the app offline or reloads with no internet connection, the fetch('data/drugs.json') fails, and the formulary silently collapses from 41,249 medicines down to only 58 fallback items (a 99.86% data drop).
  • The Fix:
    • Implemented a lightweight native IndexedDB storage engine (PrescribeProDB / drugs_cache) in scripts.js that bypasses the 5 MB localStorage quota and instantly loads the 41k catalog in ~0ms offline.
    • Added a standards-compliant Service Worker (sw.js) pre-caching the application shell and formulary, turning PrescribePro-Rx into a true, installable PWA.
    • Fixed UTF-8 character encoding mojibake in manifest.json.

2. 🚨 Clinical Drug Autocomplete & Search Ranking Defects

  • The Issue:
    1. Top Brands Hidden: drugSearch() performs a linear scan through getActiveDrugs() and truncates immediately after finding 30 matches (matches.length < 30). Because drugs.json is ordered alphabetically by manufacturer (starting with AB Life Science, APC, Ablation, ACI, Acme), typing a generic like "Paracetamol" stops after 30 matches from companies starting with "A".
    2. Veterinary & Raw API Pollution: The 41k formulary contains 1,061 veterinary drugs (e.g. Adpara Bolus Vet, Acitamol Vet) and 53 raw industrial APIs/pellets (e.g. Acetone BP (API) 1000 ml, Boric Acid 500 gm, Omeprazole Pellets 8.5%/kg). These appear in clinical autocomplete alongside human medications.
    3. Blank Dose Attribute: 100% of records in drugs.json have "dose": "", leaving the dose field blank on drug selection unless manually typed.
  • The Fix:
    • Implemented intelligent tiered search ranking:
      1. Brand name prefix matches.
      2. Major trusted pharmaceutical manufacturer boost (Square, Beximco, Renata, Incepta, ACI, Healthcare, Eskayef, Acme, Opsonin, Aristopharma).
      3. Generic molecule prefix matches.
    • Filtered out industrial bulk chemical raw materials ((API), Pellets, Kg, Liter).
    • Added a distinct 🐾 Vet badge for veterinary products.
    • Added automatic dosage strength extraction from the generic string (e.g. "Paracetamol 500 mg" automatically populates "500 mg" into ddose-${id}).

3. 🛡️ Clinical Safety & Guardrails (Allergies & Duplicates)

  • The Issue:
    1. Passive Allergy Display: Documented patient allergies (e.g. Penicillin) are merely displayed as a static text string at the top of the A4 paper. Prescribing Amoxil (Amoxicillin) to a penicillin-allergic patient triggers zero warning or alert.
    2. No Duplicate Molecule Check: Doctors can accidentally prescribe duplicate active ingredients (e.g. Napa + Ace) concurrently without detection.
  • The Fix:
    • Implemented real-time Allergy Checking (checkDrugSafety(rowId)): Cross-references prescribed brand names and generic molecules against patient allergy tokens (including Penicillin $\leftrightarrow$ Amoxicillin/Ampicillin, Sulfa $\leftrightarrow$ Cotrimoxazole, NSAID $\leftrightarrow$ Ibuprofen/Diclofenac/Naproxen) and highlights the card in red with a prominent warning banner.
    • Implemented Duplicate Molecule Checking: Warns if the same active generic molecule is already prescribed in another row during the consultation.

4. 🖥️ UI / UX & Print Engine Improvements

  • The Issue:
    1. No Escape Key Handler: Modals cannot be dismissed with the Esc key; doctors must manually click the ✕ button.
    2. Native Print Isolation (Ctrl+P): Pressing Ctrl+P in the browser printed the entire dashboard UI, buttons, and background instead of isolating the clean prescription pad.
    3. Draft Leakage: Opening "+ New Prescription" from the dashboard silently restored any previous patient's draft without checking patient ID.
    4. Corrupted Screenshot: screenshots/Create login.jpg was a corrupted 2-byte file.
  • The Fix:
    • Added a global Escape key event listener that dismisses autocomplete dropdowns and top-level modals.
    • Enhanced @media print in styles.css to cleanly isolate #rx-a4 at 210mm × 296.8mm on Ctrl+P.
    • Isolated unsaved drafts so they only restore when opening the specific patient they were drafted for.
    • Replaced the 2-byte corrupted screenshot with a valid image asset.

5. ♿ Web Accessibility Compliance (WCAG 2.1 AA)

  • The Issue: Zero out of 42 <label> tags in the application had a for attribute linking to input ids, failing WCAG 2.1 Success Criterion 1.3.1.
  • The Fix: Associated explicit for="..." attributes on all 30+ form labels across patient demographics, doctor profile, pad settings, and consultation forms.

Accompanying Pull Request

We have submitted an accompanying Pull Request linking to this issue with all the above fixes cleanly implemented, zero external dependencies, and fully backward-compatible with Version 3.0 Pro.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions