81 lines
3.1 KiB
Markdown
81 lines
3.1 KiB
Markdown
# Survey Mapping Dropdowns Fixed
|
|
|
|
## Summary
|
|
|
|
Fixed the empty dropdowns issue in the Survey Mapping Settings page by correcting the hospital access logic in the view and API viewset.
|
|
|
|
## Problem
|
|
|
|
The Survey Mapping Settings page showed empty dropdowns for both Hospital and Survey Template fields because:
|
|
|
|
1. The code tried to access a non-existent `user.accessible_hospitals` relationship
|
|
2. The User model only has a single `hospital` field, not `accessible_hospitals`
|
|
3. This caused the hospital dropdown to be empty
|
|
4. When hospital dropdown was empty, the survey template dropdown couldn't load (it depends on hospital selection via AJAX)
|
|
|
|
## Solution
|
|
|
|
### 1. Fixed `apps/integrations/ui_views.py`
|
|
|
|
**In `survey_mapping_settings` function:**
|
|
- Replaced non-existent `user.accessible_hospitals.all()` with proper role-based logic
|
|
- Superusers: Can see all hospitals (`Hospital.objects.all()`)
|
|
- Regular users: Can only see their assigned hospital (`Hospital.objects.filter(id=user.hospital.id)`)
|
|
- Users without hospital: No access (empty list)
|
|
|
|
**In `SurveyTemplateMappingViewSet.get_queryset`:**
|
|
- Fixed hospital filtering to use `user.hospital` instead of `user.accessible_hospitals`
|
|
- Properly handles users without hospital assignment (returns empty queryset)
|
|
|
|
## Test Results
|
|
|
|
Running `test_survey_mapping_dropdowns.py` confirmed:
|
|
|
|
✅ **Hospitals**: 2 available
|
|
- Al Hammadi Hospital - Riyadh
|
|
- Alhammadi Hospital
|
|
|
|
✅ **Survey Templates**: 8 available with correct satisfaction options
|
|
- Appointment Satisfaction Survey (10 questions, 5 satisfaction options)
|
|
- Inpatient Satisfaction Survey (12 questions, 5 satisfaction options)
|
|
- Outpatient Satisfaction Survey (8 questions, 5 satisfaction options)
|
|
- Plus 5 additional survey templates
|
|
|
|
✅ **Satisfaction Options**: All configured correctly with bilingual labels:
|
|
1. Very Unsatisfied / غير راضٍ جداً
|
|
2. Poor / ضعيف
|
|
3. Neutral / محايد
|
|
4. Good / جيد
|
|
5. Very Satisfied / راضٍ جداً
|
|
|
|
✅ **User Access**: 6 active users with proper hospital access
|
|
- Superusers: Access to all hospitals
|
|
- Regular users: Access to their assigned hospital only
|
|
|
|
✅ **Dropdown Population**:
|
|
- Hospital dropdown: Will show available hospitals
|
|
- Survey Template dropdown: Will populate with templates for selected hospital
|
|
|
|
## Impact
|
|
|
|
The Survey Mapping Settings page will now work correctly:
|
|
1. Users can select a hospital from the dropdown
|
|
2. When hospital is selected, survey templates load dynamically
|
|
3. Users can create mappings between patient types and survey templates
|
|
4. Proper role-based access control is maintained
|
|
|
|
## Related Files Modified
|
|
|
|
- `apps/integrations/ui_views.py` - Fixed hospital access logic
|
|
- `test_survey_mapping_dropdowns.py` - Created test script to verify fixes
|
|
|
|
## Next Steps
|
|
|
|
Users can now:
|
|
1. Navigate to Survey Mapping Settings (sidebar link added)
|
|
2. Select a hospital from the dropdown
|
|
3. Select survey templates for that hospital
|
|
4. Create mappings for different patient types (Inpatient, Outpatient, Appointment, etc.)
|
|
5. Set priorities for each mapping
|
|
|
|
The surveys with satisfaction options are already in the database and ready to use. |