fix(queue): align frontend queue flow
Overview This MR fixes inconsistencies in the volunteer consultation workflow by standardizing the patient journey step to waiting, limiting prescription-related actions to the latest consultation only, and simplifying doctor reassignment. It is needed to prevent volunteers from acting on stale consultations and to keep patient progress aligned with the actual queue state.
What does this MR do and why? The main motivation was workflow correctness. The UI mixed queue and waiting, prescription screens exposed historical consultations, and doctor reassignment asked users to select a consultation even though the action is patient-level. The chosen approach was to align the status model with the API, derive the latest consultation in the affected volunteer pages, and reuse the existing reassignment mutation with patient book_no. The trade-off is that older consultations are no longer directly selectable from these volunteer screens, which is intentional for safety.
Changes Made
- Standardized the volunteer journey step from
queuetowaiting - Updated patient status tracking/page logic to match the new step
- Limited Update Prescription to the latest consultation
- Limited Verify Medicines to the latest consultation
- Simplified Change Doctor to remove consultation selection
- Added/updated focused tests and synced the changelog
| File | Action | Purpose |
|---|---|---|
| src/hooks/usePatientStatus.ts | Modify | Align status model and step labels with waiting
|
| src/pages/volunteer/PatientStatus.tsx | Modify | Keep patient journey UI consistent |
| src/pages/volunteer/AssignDoctorPage.tsx | Modify | Simplify reassignment flow and invalidate relevant queries |
| src/pages/volunteer/UpdatePrescriptionPage.tsx | Modify | Show only the latest consultation |
| src/pages/volunteer/VerifyMedicinesPage.tsx | Modify | Show only the latest consultation |
| src/types/api.ts | Modify | Add waiting to patient status types |
| tests/usePatientStatus.test.tsx | Create | Cover waiting-step behavior |
| tests/unit/components/AssignDoctorPage.test.tsx | Modify | Cover simplified reassignment |
| tests/unit/pages/volunteer/UpdatePrescriptionPage.test.tsx | Modify | Update expectations for latest-only consultation behavior |
| tests/volunteers/UpdatePrescriptionPage.test.tsx | Modify | Integration coverage for latest-only selection |
| tests/volunteers/VerifyMedicinesPage.test.tsx | Modify | Integration coverage for latest-only selection |
Technical Details Root cause:
- The patient journey UI used a synthetic
queuestep while queue data/state already useswaiting. - Prescription-related volunteer pages rendered all consultations instead of the current/latest one.
- Doctor reassignment flow was modeled as consultation-specific, creating unnecessary friction.
Fix:
- Replaced
queuejourney usage with typedwaiting - Derived
latestConsultationby sorting consultations bycreated_at - Reused patient-level reassignment via
assignToDoctor({ book_no, doctor_id }) - Invalidated queue, consultations, doctors, and patient-status queries after reassignment
Architecture/state notes:
- TanStack Query remains the server-state source of truth
- No API contract changes were introduced
- No env/config changes were required
Type of Change
-
Bug fix -
New feature -
Breaking change -
Documentation update -
UI/UX improvement -
Refactor -
Performance improvement -
Test update -
Configuration change -
Security fix
Related Issues / References
- Closes: N/A
- Fixes: N/A
- Related to: volunteer queue / consultation workflow consistency
Screenshots or Screen Recordings N/A for layout changes. This MR mainly changes workflow logic and small UI labels. Before: mixed queue/waiting, multiple consultations shown, consultation picker required for reassignment. After: waiting is consistent, only latest consultation is actionable, reassignment is patient-level.
How to Set Up and Validate Locally
- Checkout this branch/MR.
- Install deps:
bun install
- Set backend URL if needed:
VITE_SERVER_URL=http://localhost:8000
VITE_SOCKET_URL=http://localhost:8000
- Start app:
bun dev
- Validate:
- Open volunteer Patient Status and confirm the step shows
Waiting - Open Update Prescription for a patient with multiple consultations and confirm only the latest card is shown
- Open Verify Medicines for the same patient and confirm only the latest card is shown
- Open Assign Doctor and confirm Change Doctor works without a consultation dropdown
- Automated validation:
bun run lint
bun run test:run
bun run test:coverage
bun run build
Testing Done
-
Manual testing completed -
Unit tests added/updated
| Scenario | Expected Result | Status |
|---|---|---|
| Waiting status renders consistently |
Waiting step shown and used in logic |
|
| Update Prescription uses latest consultation only | Only latest consultation card is rendered/actionable | |
| Verify Medicines uses latest consultation only | Only latest consultation card is rendered/actionable | |
| Incomplete consultation is blocked | Error shown and dialog does not open | |
| Change Doctor no longer needs consultation selection | Reassignment succeeds with patient book_no payload |
Automated results:
- Full suite passed:
1447/1447 - Coverage passed:
94.27%statements,88.82%branches,95.5%functions,94.71%lines -
knipand production build passed
Code Quality Checklist
-
Project conventions, formatting, TypeScript, and query patterns follow repo standards -
TanStack Query loading/error/cache invalidation handled appropriately -
ESLint/Prettier, i18n check, tests, coverage, knip, and build all pass -
CHANGELOG updated -
Manual browser validation completed
Known Limitations / Technical Debt
- Historical consultations are intentionally hidden from these volunteer action flows; if editing old consultations is needed later, that should be handled in a separate dedicated flow.
- Existing unrelated console/test warnings still appear during repo-wide test runs, but they do not fail CI for this MR.
Additional Notes This MR is low risk from an API standpoint and moderate impact from a workflow standpoint. It improves correctness and reduces volunteer error by narrowing actions to the current/latest consultation.
MR Acceptance Checklist Evaluation
- Quality: Low risk, backed by targeted and full-suite coverage
- Reliability: Improved by removing ambiguous status/state handling
- Performance: Neutral; only lightweight consultation sorting was added
- Security: No auth or permission model changes
- Maintainability: Improved through consistent status typing and stronger tests