fix: queue gender mapping
Merge Request
Overview
This MR fixes the issue where patient_sex was not being populated correctly in the queue API, causing incorrect filtering and backend crashes.
What does this MR do and why?
Previously, the queue API attempted to fetch gender using a non-existent field (patient_record.patient_sex) from the Patient model. This resulted in:
- Internal Server Errors
- Incorrect or null gender values
- UI filtering (male/female/other) not working
This MR corrects the data source and ensures proper handling of gender values.
Changes Made
- Replaced incorrect
patient_record.patient_sexusage - Used
user_record.user_genderas the correct source of gender - Fixed Enum handling using
.value.lower() - Ensured null-safe checks to prevent runtime errors
- Updated queue response mapping
Technical Details
-
Root Cause: Patient model does not contain
patient_sex -
Fix: Fetch gender from User model (
user_gender) -
Enum Handling: Used
.value.lower()to convert Enum to string safely
"patient_sex": (
user_record.user_gender.value.lower()
if user_record and user_record.user_gender
else None
),
Type of Change
-
🐛 Bug fix (non-breaking change that fixes an issue)
Related Issues / References
- Fixes patient gender not showing in queue
- Fixes UI filtering issue for male/female/other
How to Validate Locally
- Start backend:
docker compose up -d
- Login:
curl -X POST http://localhost:8000/api/v1/auth/login \
-H "Content-Type: application/json" \
-d '{"book_no": 1, "password": "admin123"}'
- Call queue API:
curl -H "Authorization: Bearer <TOKEN>" \
http://localhost:8000/api/v1/queue/all
- Verify:
-
patient_sexis populated correctly - No Internal Server Error
- Filtering works:
/api/v1/queue/all?gender=male
Testing Done
-
API tested using curl -
Verified gender values in response -
Verified no crashes -
Verified filtering works correctly
Code Quality Checklist
-
No unused imports -
Proper null checks added -
Enum handled correctly -
No breaking changes introduced
Impact
- Fixes backend crash
- Enables correct gender filtering
- Improves API reliability
Additional Notes
This change ensures consistency between backend data and frontend filtering logic.