Fix: reasign and change specialization in consulatation
Merge Request: Multi-Doctor Consultation & Reassignment Flow
Overview
This MR implements a robust Multi-Doctor workflow, allowing patients to see multiple specialists in a single camp visit. It resolves the issue where patients were "lost" or "locked" after a single consultation and enables coordinated referrals with seamless medication verification across all doctors.
What does this MR do and why?
Motivation
Previously, the system assumed a linear one-doctor-per-visit model, which failed in real-world camp scenarios where patients need multiple consultations (e.g., Dentist → Pediatrician).
Approach
- Decoupled prescription validation from cycle counts in the backend.
- Introduced a state-aware multi-doctor flow in the frontend.
- Enabled handling of multiple active consultations per visit.
Trade-offs
- Multiple active consultations required adding DISTINCT logic in queue dashboards to avoid duplicate patient entries.
Changes Made
Frontend (Vite + TypeScript)
-
AssignDoctorPage.tsx-
Redesigned into a 3-card layout:
- Initial Assignment
- Referral
- Doctor Swap
-
-
UpdatePrescriptionPage.tsx- Prevents auto-navigation if other doctor records are pending.
-
VerifyMedicinesPage.tsx- Added
completedConsultationIdstracking - Enables sequential verification of multiple doctors.
- Added
Tests
-
Updated
AssignDoctorPage.test.tsx- Supports new state-based UI logic and card visibility.
Technical Details
Root Cause (Bug Fix)
Reassigning a doctor (Card 3) previously left the old specialization in the queue, making patients invisible to the new doctor.
Architecture Change
-
Shifted from one-shot navigation → state-aware progression
-
Frontend now:
- Fetches all consultations in a visit
- Requires all to be completed/verified before queue transition
Type of Change
-
✨ New feature (non-breaking functionality) -
🎨 UI/UX improvement - 🧪 Test update
Related Issues / References
closes #325 (closed)
Screenshots / Recordings
| Before | After |
|---|---|
| Original Single Card UI | New 3-Card Reassign UI |
How to Set Up and Validate Locally
Setup
- Pull latest backend and frontend changes
- Run Alembic migrations
- Start backend and frontend servers
Validation Steps
-
Assign patient to Doctor A (Spec X)
-
In
AssignDoctorPage, use Card 2 to refer to Spec Y -
Complete both consultations
-
Open Verify Medicines
-
Validate flow:
- Verify Doctor A → success toast → card turns green
- Verify Doctor B → auto-navigation to queue
Run Tests
npm test tests/unit/components/AssignDoctorPage.test.tsx
Testing Done
-
✔ Manual testing for referral and doctor swap flows -
✔ Unit tests updated and passing -
✔ Database validation:- Book #18 (closed) → multi-consultation record
- Book #19 (closed) → single consultation record
Code Quality Checklist
Code Standards
- Code follows project structure and naming conventions
- No
console.log()statements - No
anytypes used - ESLint and Prettier checks pass
React Best Practices
-
VerifyMedicinesPageuses state tracking (completedConsultationIds) - Conditional rendering implemented for 3-card UI
- Proper dependency handling in
useEffect
Known Limitations / Technical Debt
-
DISTINCT ONis PostgreSQL-specific (may require changes for other DBs) - UI may need scroll optimization for 3+ consultations
closes #325 (closed)
