# Complaint SLA Management Feature ## Overview A dedicated PX Admin-only interface for managing complaint SLA (Service Level Agreement) configurations with automatic hospital selection from session. ## Features ### 1. PX Admin Only Access - Protected by `@px_admin_required` decorator - Automatically uses hospital from session (`selected_hospital_id`) - Redirects to hospital selection if no hospital is selected ### 2. Hospital Context - Hospital is **automatically set** from the first selection after login - Stored in session as `selected_hospital_id` - No need to manually select hospital for each configuration ### 3. SLA Configuration Types #### Source-Based SLAs - Configure SLAs based on complaint source (MOH, CCHI, Patient, etc.) - Takes precedence over severity-based configs - Example: MOH complaints = 24 hours, CCHI = 48 hours #### Severity/Priority-Based SLAs - Configure SLAs based on severity and priority levels - Used when no source-based config exists - Example: Critical/Urgent = 12 hours, Low/Low = 72 hours ### 4. Timing Configuration #### SLA Deadline - Total hours from complaint creation until deadline - Example: 24, 48, 72 hours #### Reminder Timing (Modern) - **First Reminder**: X hours after complaint creation - **Second Reminder**: X hours after complaint creation - Set to 0 to use legacy timing #### Reminder Timing (Legacy) - **First Reminder**: X hours before deadline - **Second Reminder**: X hours before deadline (with enable checkbox) #### Escalation - X hours after creation to auto-escalate - Set to 0 to use standard overdue logic ## URLs | URL | View | Description | |-----|------|-------------| | `/complaints/settings/sla-management/` | `sla_management` | Main SLA management page | | `/complaints/settings/sla-management/new/` | `sla_management_create` | Create new SLA config | | `/complaints/settings/sla-management//edit/` | `sla_management_edit` | Edit existing config | | `/complaints/settings/sla-management//toggle/` | `sla_management_toggle` | Toggle active status | ## Files Created/Modified ### New Files 1. `/apps/complaints/management/commands/test_sla_reminders.py` - Test command 2. `/templates/complaints/sla_management.html` - Main management page 3. `/templates/complaints/sla_management_form.html` - Create/Edit form 4. `/templates/complaints/partials/severity_badge.html` - Severity badge partial 5. `/templates/complaints/partials/priority_badge.html` - Priority badge partial ### Modified Files 1. `/apps/complaints/ui_views.py` - Added 4 new views 2. `/apps/complaints/urls.py` - Added 4 new URL routes 3. `/templates/config/dashboard.html` - Added navigation card ## Usage ### For PX Admins 1. **Login** as PX Admin 2. **Select Hospital** (first time after login) 3. **Navigate to** System Configuration → Complaint SLA - Or directly: `/complaints/settings/sla-management/` 4. **Configure SLAs**: - Click "Add SLA Configuration" - Choose Source (for source-based) OR Severity/Priority - Set SLA hours, reminders, escalation - Save ### Example Configuration **MOH Complaints (Source-Based)**: - Source: Ministry of Health - SLA Hours: 24 - First Reminder: 12 hours after creation - Second Reminder: 18 hours after creation - Escalation: 24 hours after creation **Critical/Urgent Complaints (Severity-Based)**: - Severity: Critical - Priority: Urgent - SLA Hours: 12 - First Reminder: 6 hours after creation - Second Reminder: 9 hours after creation - Escalation: 12 hours after creation ## Testing Use the management command to test SLA reminders: ```bash # Create test complaints and run SLA reminder task python manage.py test_sla_reminders --run-task # Dry run (preview only) python manage.py test_sla_reminders --dry-run # Test specific scenario python manage.py test_sla_reminders --scenario assigned --complaint-count 3 # Clean up test data python manage.py test_sla_reminders --cleanup ``` ## SLA Priority Order 1. **Source-based config** (MOH, CCHI, Internal) 2. **Severity/Priority-based config** 3. **System defaults** (from settings) ## Key Benefits ✅ **Hospital Auto-Selection**: No need to manually select hospital each time ✅ **PX Admin Only**: Secure, role-based access ✅ **Visual Interface**: Clean, modern UI with badges and stats ✅ **Flexible Timing**: Support for both modern (after creation) and legacy (before deadline) timing ✅ **Toggle Status**: Easily enable/disable configs without deleting ✅ **Audit Logging**: All changes logged for compliance ## Session Flow ``` 1. PX Admin logs in ↓ 2. Redirected to hospital selection page ↓ 3. Selects hospital → stored in session['selected_hospital_id'] ↓ 4. All SLA configs use this hospital automatically ↓ 5. Can switch hospitals anytime from sidebar ```