JAGADISWAR / LEARNINGS / ESIC-MEDSTOCK
HEALTHCARE / INVENTORY

What I learned
building ESIC MedStock.

Working prototypeNext.jsTypeScriptFirebaseFirestore

A pharmacy-assistance system designed to help ESIC patients check medicine availability and reduce unnecessary waiting through a kiosk-first flow.

LEARNINGS / ESIC-MEDSTOCKWORKING PROTOTYPEAMBATI JAGADISWAR REDDY
01 / OVERVIEW & STATUS

What it is, and where it stands.

The web kiosk lets a patient pick a hospital branch, look up a prescription by ID or QR code, and see whether each prescribed medicine is available, limited, out of stock, or unknown, along with queue information.

It is a prototype built on Next.js and Firebase Cloud Firestore. The same Firestore database is also used by an Android app, so stock updated by pharmacy staff on the app shows up on the kiosk. The two apps never talk to each other directly.

Status
Working prototype (web kiosk)
Platform
Web kiosk, Next.js App Router; Vercel deployment per the README
Data
Cloud Firestore: inventory, prescriptions, queue, hospital_status
Branches in the test plan
Peenya, Sanath Nagar, Basaidarapur
Interface languages
English, Telugu, Hindi
Stack
Next.js 16, React 19, TypeScript, Tailwind CSS 4, Firebase SDK, Framer Motion, html5-qrcode
02 / WHAT I LEARNED

Lessons from the build.

The biggest lessons came from one stubborn bug: patients saw “Inventory Record Not Found” even though related medicine data existed.

LESSON / 01

A missing record is not an empty shelf

The availability logic returns four states: available, limited, out of stock and unknown. “Out of stock” is only shown when an inventory record confirms zero stock or unavailability. No record means “unknown”, never “out”.

LESSON / 02

Debug the data flow, not the screen

The fix came from tracing the whole chain (prescription, medicine reference, medicine identifier, inventory lookup, hospital validation) and checking it against the actual Firestore data instead of tweaking the UI.

LESSON / 03

Real identifiers are messy

Prescriptions often store an inventory document ID where a medicine name or code is expected, and names can carry hospital suffixes. The lookup therefore indexes each inventory item by document ID, medicine code, medicine name and a normalized identity.

LESSON / 04

A shared screen needs session hygiene

The kiosk returns to the dashboard after 2 minutes of inactivity, with a warning in the last 30 seconds, and any touch, key press or scroll resets the timer. Language switching and manual ID entry (alongside QR scanning) keep it usable for more patients.

TECHNICAL CONCEPTS

Firestore document model

Four collections (inventory, prescriptions, queue, hospital_status) shared by the web kiosk and the Android app.

Real-time listeners

The dashboard, queue and prescription pages use Firestore onSnapshot listeners for live data.

Identifier normalization

Helper functions trim, lowercase and strip hospital suffixes and punctuation so near-identical names resolve to one identity.

Branch scoping

An isSameHospital check compares normalized hospital values so one branch’s stock is not shown for another branch’s prescription.

Shared pure logic

Availability classification lives in one utility module used by both the prescription and inventory pages.

Failure states as UI

Offline status, a Firestore permission warning, and error and not-found pages are part of the interface.

03 / CHALLENGES & DECISIONS

Challenges and engineering decisions.

Where the build pushed back, and what I decided to do about it.

Data matching

Prescription and inventory IDs did not line up across branches

CHALLENGELookups returned “not found” when the identifiers in prescriptions did not match the ones in inventory records.

DECISIONBuild a lookup map keyed by several deterministic identifiers in priority order (document ID, medicine code, medicine name, normalized identity) and share that logic across pages.

Trust

Unknown being mistaken for out of stock

CHALLENGETreating a failed lookup as zero stock would tell a patient a medicine is unavailable when the system simply could not find it.

DECISIONReturn a separate unknown state, and only report out of stock when a valid record says so. In code, more than 5 units counts as available and 1 to 5 as limited.

Correctness

Records leaking across hospital branches

CHALLENGEThe same medicine can exist at several branches with different stock.

DECISIONValidate the hospital on both the prescription and the inventory record before displaying anything.

Security honesty

Admin settings on a public screen

CHALLENGEChanging the kiosk’s hospital is gated by an admin PIN, but the PIN comes from a NEXT_PUBLIC environment variable, which is visible in the browser bundle.

DECISIONThe code documents this as a prototype-level convenience gate, not a secure server-side secret. Being explicit about what is and is not a security boundary is part of the design.

Regression risk

Fixing one flow without breaking the others

CHALLENGELookup changes touch the prescription, inventory, queue and QR flows.

DECISIONThe SDLC docs keep a written test checklist per branch (valid, invalid, missing and wrong-hospital prescriptions, multi-medicine cases) and a regression rule that a lookup fix must not break other working features.

04 / POTENTIAL IMPROVEMENTS

What I would improve next.

Ideas grounded in what the current code and documentation say is missing.

From prototype
to something sturdier.

  • Replace the client-side admin PIN with real authentication and server-side validation for staff workflows.
  • Reconcile medicine identifiers across branches at the data level, so lookups rely less on fallback matching.
  • Turn the manual test checklist into automated tests for the classification and normalization rules. I did not find automated test files in the repository.
  • Show when each stock record was last updated so patients can judge how fresh the availability is.
  • Continue the documented roadmap: accessibility improvements, branch-level analytics, and a controlled pharmacy assistant.

The code is the artifact.
The learning is the leverage.

Concise notes on ESIC MedStock, written to make the decisions behind it easy to discuss in a review, interview or collaboration.