Multi-Doctor Consultation & Reassignment Flow
Issue: Multi-Doctor Consultation & Reassignment Flow
Issue Summary
Implementation of a seamless multi-doctor consultation workflow that allows patients to see multiple doctors (different specializations) in a single visit without losing record continuity or prematurely exiting the queue.
Current Behavior: Patients were restricted to a single consultation cycle. Reassigning a doctor did not synchronize the queue's specialization, and completing one prescription/verification would automatically navigate the user away, even if other doctor records were pending.
Expected Behavior: Coordinators can reassign patients to new specializations or swap doctors on existing records. Volunteers can complete all pending prescriptions/verifications sequentially on the same page. Counseling and Verification queues should show unique patients even if they have multiple consultation records.
Problem Statement
The healthcare system lacked support for "referrals" where a patient needs to see a second doctor (e.g., Dentist → Pediatrician) within the same camp visit.
Issues:
- Data Locking: Backend restricted prescription edits to only the "latest" record.
- Queue Fragmentation: Reassigning a doctor didn't update the specialization filter in the queue.
- UX Interruptions: Automatic redirects after a single update forced volunteers to repeatedly search for the same patient.
- Duplicate Cards: Patients appeared multiple times in Counseling queues if they saw multiple doctors.
Proposed Solution
Backend Refactor: Decouple prescription validation from "cycle numbers" and support visit-wide updates.
Dynamic Queue Sync: Force the ConsultationQueue record to match the active doctor's specialization.
Multi-Card Assignment UI: Create a clear 3-card flow in AssignDoctorPage for:
- Initial assignment
- Referral (new record)
- Doctor swap (existing record)
Stateful Navigation: Add completedConsultationIds tracking to frontend pages to prevent navigation until the entire visit list is processed.
Distinct Queue Querying: Use PostgreSQL DISTINCT ON to ensure unique patient entries in dashboard queues.
Test-Driven Development
Acceptance Criteria
Scenario 1: Doctor Reassignment (Swap)
Given a patient is currently in the Consultation Queue for "Dentist"
When a coordinator uses "Change Doctor" to swap the dentist for an "Ophthalmologist"
Then the patient's specialization in the queue should update to "Ophthalmologist"
And the patient should immediately appear in the new specialization's waiting list.
Scenario 2: Multi-Specialty Referral
Given a patient has finished a consultation with Doctor A
And needs to see Doctor B for a different specialty
When the coordinator uses "Reassign Specialization"
Then a second consultation record is created
And the patient stays in the active queue flow.
Scenario 3: Sequential Verification
Given a patient has two pending prescriptions from different doctors
When a pharmacist verifies the first doctor's medications
Then the system should stay on the patient's record
And display a "verified" status for the first doctor
And only navigate away once the second doctor's medications are verified.
Test Cases
| Test ID | Test Description | Precondition | Test Steps | Expected Result | Priority |
|---|---|---|---|---|---|
| TC-001 | Hide Card 1 on Reassign | Patient in Queue | Search Book # | Card 1 hidden; Cards 2 & 3 visible | High |
| TC-002 | Queue Spec Sync | Patient with Spec X | Change doctor to Spec Y | Queue listing shows Spec Y | High |
| TC-003 | Multi-Doc Stay-on-Page | 2 Consultations | Complete first form | UI stays; first card marked complete | Medium |
| TC-004 | Distinct Queue Count | 2 Consultations | View Counseling Queue | Single entry per patient | Medium |
Implementation Details
Files Changed
- app/services/patient_consultation_service.py — Allow all consultations in a visit to be updated; sync queue specialization.
- app/services/consultation_queue_service.py — Use DISTINCT ON (book_no) in get_all_active_queue.
- src/pages/volunteer/AssignDoctorPage.tsx — Implemented 3-card logic and conditional visibility.
- src/pages/volunteer/UpdatePrescriptionPage.tsx — Prevent premature navigation in multi-doctor visits.
- src/pages/volunteer/VerifyMedicinesPage.tsx — Added completedConsultationIds state and sequential verification UI.
Technical Considerations
- PostgreSQL DISTINCT ON requires ORDER BY to match the distinct column first.
- Frontend uses local state (completedConsultationIds) to track progression within a session.
Testing Strategy
Manual Testing
Roles: Coordinator / Volunteer
Steps:
- Register a patient and assign to "Dentist".
- Use AssignDoctorPage to swap to "Ophthalmologist".
- Complete consultation.
- Reassign to "Pediatrician".
- Verify medicines for both consultations without redirection.
Automated Testing
- Updated AssignDoctorPage.test.tsx to handle new queue state.
- Verified getPatientQueueStatus API integration and lifecycle behavior.
Reference
Source content provided by user.