HH/.mimocode/plans/1781172520267-calm-canyon.md
ismail 7369d08012
All checks were successful
Build and Push Docker Image / build (push) Successful in 4m14s
feat: unified reference numbers + feedback modules QA audit
Reference numbers (unified scheme PREFIX-YYYYMM-HOSP-NNNN, e.g. CMP-202606-HHN-0001):
- new ReferenceSequence model + generate_reference() helper (apps/core)
- Complaint/Inquiry/Observation/Appreciation/Suggestion emit unified refs via save()
- prefix-based auto-routing in public track API (CMP/INQ/OBS trackable; APR/SGT internal-only)
- removed legacy CMP-/INQ- generators in ui_views, integrations, px_sources
- migrations: core.0003_referencesequence, appreciation.0006, feedback.0008, observations.0012
- unit tests (format, sanitization, monthly reset, 40-thread concurrency)

QA audit:
- isolated E2E hospital sandbox mirroring HH-N + 10 role users (create_e2e_isolated_env)
- feedback-modules-audit.spec.ts + audit helper (headed, run-to-completion)
- reports/feedback-modules-qa-report.md

Also bundles accumulated in-progress work across complaints, observations,
organizations, templates, and other modules.
2026-06-14 14:29:23 +03:00

103 lines
4.0 KiB
Markdown

# Plan: Unify Department Response + Add Reporter Notifications
## Goal
1. Make all three types use the same department response approach (token-based, no login)
2. Add reporter notifications for complaint/inquiry when department responds
---
## 1. UNIFY DEPARTMENT RESPONSE (Token-Based for All)
### Current State
- **Complaint**: Uses `ComplaintExplanation` model with token links — champion clicks link, submits explanation without login
- **Observation**: Champion logs into system, navigates to department detail page, submits response via form
- **Inquiry**: Same as observation — login required
### Target State
All three use token-based links (like complaint):
- PX team sends to department → champion receives email with one-time link
- Champion clicks link → submits response without login
- Link expires after use
### Changes Needed
#### a) Create shared `DepartmentResponse` model (or reuse existing patterns)
Better approach: Create a token-based response flow for observation and inquiry similar to complaint's `ComplaintExplanation`.
**New model in `apps/organizations/models.py`** (or `apps/core/models.py`):
```python
class DepartmentResponseToken(UUIDModel, TimeStampedModel):
"""Token-based department response link for observations and inquiries."""
content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
object_id = models.UUIDField()
content_object = GenericForeignKey('content_type', 'object_id')
department = models.ForeignKey('organizations.Department', on_delete=models.CASCADE)
staff = models.ForeignKey('organizations.Staff', on_delete=models.CASCADE)
token = models.CharField(max_length=100, unique=True)
is_used = models.BooleanField(default=False)
responded_at = models.DateTimeField(null=True, blank=True)
# SLA
sla_due_at = models.DateTimeField(null=True, blank=True)
is_overdue = models.BooleanField(default=False)
class Meta:
indexes = [models.Index(fields=['token'])]
```
Actually, simpler approach: just add token fields to the existing models and create views for token-based response.
**For Observation** (`apps/observations/models.py`):
- Add `response_token` field (CharField, unique, nullable)
- Add `response_token_used` (BooleanField, default=False)
- Add `response_token_sent_at` (DateTimeField, nullable)
**For Inquiry** (`apps/complaints/models.py`):
- Add same fields to Inquiry model
#### b) Create token-based response views
- `observation_respond_with_token(request, pk, token)` — public view, no auth required
- `inquiry_respond_with_token(request, pk, token)` — public view, no auth required
#### c) Update "Send to Department" views
- Generate token, include in email link
- Email template similar to complaint's explanation request
#### d) Update department detail page
- Remove direct response forms (or keep as fallback for logged-in users)
- Show token-based response status instead
---
## 2. ADD REPORTER NOTIFICATIONS
### Current State
- **Complaint**: No notification to complainant when department responds
- **Observation**: SMS + email to reporter when department responds ✓
- **Inquiry**: No notification to inquirer when department responds
### Changes Needed
#### a) Complaint — notify complainant on department response
**File**: `apps/complaints/ui_views.py` (in `involved_department_response` view)
- After department submits response, send SMS + email to complainant
- Include tracking link
#### b) Inquiry — notify inquirer on department response
**File**: `apps/complaints/ui_views.py` (in `inquiry_department_response` view)
- After department submits response, send SMS + email to inquirer
- Include tracking link
---
## Implementation Order
1. Add token fields to Observation and Inquiry models
2. Create token-based response views for both
3. Update "Send to Department" to generate tokens and send email links
4. Add reporter notifications to complaint and inquiry department response flows
5. Update templates
6. Create migration