feat(consultation): implement specialization-based automatic doctor assignment
title: "feat(consultation): implement specialization-based automatic doctor assignment"
🚀 Feature Request
Is your feature request related to a problem? Please describe.
Currently, doctor consultation is created through manual doctor assignment. This approach introduces several limitations:
- Manual intervention is required to assign doctors to patients.
- No load balancing between doctors, leading to uneven distribution of patients.
- The system does not consider doctor availability (login/logout) in real time.
- The queue is tightly coupled with doctor assignment, making it inflexible and hard to scale.
Describe the solution you'd like
Refactor the consultation and queue system to support specialization-based automatic doctor assignment.
Proposed solution:
- Assign patients to a specialization instead of a specific doctor during registration.
- Create a ConsultationQueue record immediately upon patient registration with
doctor_id = NULL. - Maintain queue numbers as time-based and independent of doctor assignment.
- Dynamically assign doctors in the backend when the patient is ready for consultation (e.g., status = waiting).
Doctor assignment logic:
-
Fetch doctors registered for the camp with the required specialization.
-
Filter doctors based on availability:
login_time IS NOT NULLlogout_time IS NULL
-
Compute active patient load per doctor using ConsultationQueue (active statuses).
-
Assign the patient to the doctor with the lowest current load.
-
Update the existing queue record with the selected
doctor_id.
Describe alternatives you've considered
- Continuing manual doctor assignment (rejected due to inefficiency and lack of scalability).
- Assigning doctors at registration time (rejected because it does not account for real-time availability changes).
- Round-robin assignment (considered but less optimal than load-based assignment).
Additional context
This change will:
- Decouple queue management from doctor assignment.
- Enable real-time, dynamic doctor allocation.
- Improve scalability for large medical camps.
- Align the system with real-world hospital workflows where patients are routed by specialization first and doctors are assigned dynamically based on availability.
This feature also involves partial refactoring of:
- Consultation creation logic
- Queue management flow
- Patient registration flow