Refactor Doctor Assignment Flow to Specialization-Based Manual Assignment
Issue Summary
Refactor Doctor Assignment Flow to Specialization-Based Manual Assignment
Problem Statement
Currently, the frontend follows an outdated workflow where:
- Doctors are assigned immediately after patient registration
- All doctors are displayed without filtering by specialization or availability
This conflicts with the updated backend logic, which:
- Requires patients to select a specialization during registration
- Assigns doctors only at consultation time
- Uses intelligent filtering and load balancing
Issues
- Incorrect doctor assignment timing
- No specialization-based filtering
- UI does not align with backend validation (doctor_id required only during consultation)
- Potential API errors due to missing doctor_id
Impact
- Broken consultation flow
- Invalid API calls
- Poor user experience
Proposed Solution
Update frontend flow to match backend:
New Flow
Register (select specialization) → Vitals → Start Consultation → Suggest Doctor → Confirm → Assign Doctor
Key Changes
-
Remove doctor assignment from registration step
-
Add specialization selection UI
-
Fetch and display only available specializations
-
On "Start Consultation":
- Call
GET /api/v1/queue/suggest-doctor - Show modal with suggested doctors
- On confirm → call
PUT /api/v1/queue/status-update
- Call
Test-Driven Development
Acceptance Criteria (Given-When-Then)
Scenario 1: Registration with specialization
Given a user is registering a patient
When they select a specialization and submit
Then the system should store the specialization
And no doctor should be assigned
Scenario 2: Start consultation triggers doctor suggestion
Given a patient has completed vitals
When user clicks "Start Consultation"
Then the system should call suggest-doctor API
And display a list of filtered doctors
Scenario 3: Confirm doctor assignment
Given suggested doctors are displayed
When user selects and confirms a doctor
Then the system should call status-update API
And assign the selected doctor
Scenario 4: No doctors available
Given no doctors are available for a specialization
When user clicks "Start Consultation"
Then the system should show "No doctors available"
Test Cases
| Test ID | Test Description | Precondition | Test Steps | Expected Result | Priority |
|---|---|---|---|---|---|
| TC-001 | Register with specialization | Registration page open | 1. Select specialization 2. Submit |
Specialization stored, no doctor assigned | High |
| TC-002 | Start consultation API call | Patient completed vitals | Click Start Consultation | Suggest API called | High |
| TC-003 | Doctor selection modal | Suggest API success | View modal | Doctors sorted by load | High |
| TC-004 | Confirm doctor assignment | Modal open | Select doctor → Confirm | status-update API called | High |
| TC-005 | No doctors case | No active doctors | Click Start | Error message shown | Medium |
Unit Test Requirements
Components/Functions to Test:
| Module/Component | Function/Hook | Test Cases |
|---|---|---|
| RegisterPage.tsx | handleRegister | TC-001 |
| ConsultationPage.tsx | handleStartConsultation | TC-002 |
| DoctorSuggestModal.tsx | handleConfirmDoctor | TC-004 |
Test Assertions Required:
-
Renders correctly with initial state -
Handles user input correctly -
Calls API with correct payload -
Handles loading state -
Handles success response -
Handles error response -
Updates UI state appropriately
Implementation Details
Files to Change
| File Path | Action | Purpose |
|---|---|---|
| src/pages/RegisterPage.tsx | Modify | Add specialization selection |
| src/components/SpecializationList.tsx | Create | Display specializations |
| src/pages/ConsultationPage.tsx | Modify | Update consultation flow |
| src/components/DoctorSuggestModal.tsx | Create | Show suggested doctors |
| src/services/api.ts | Modify | Add new API calls |
Technical Considerations
-
Use React state or Context/Redux for:
- selected specialization
- suggested doctors
-
API Integration:
- GET
/api/v1/queue/suggest-doctor - PUT
/api/v1/queue/status-update
- GET
-
Remove all old doctor assignment logic
UI/UX Requirements
-
Replace doctor list with specialization cards
-
Add modal for doctor suggestion:
- Show doctor name + current load
- Sort by least load
-
Show error message:
- "No doctors available"
-
Disable Start Consultation when required
Testing Strategy
Manual Testing
- Register patient with specialization
- Complete vitals
- Click Start Consultation
- Select doctor
- Confirm assignment
Definition of Done
-
Specialization selection implemented -
Old doctor assignment removed -
Suggest doctor API integrated -
Confirmation modal implemented -
Status update API working -
UI tested and validated -
No console errors -
Code reviewed
Additional Context
Notes
- Backend no longer supports auto-assignment
- Doctor assignment must happen ONLY during consultation
- Ensure strict API flow: suggest-doctor → confirm → status-update