HH/apps/observations/migrations/0016_observation_observation_status_valid.py
ismail 45b75eb9ef
All checks were successful
Build and Push Docker Image / build (push) Successful in 2m27s
fix: align workflow behavior (Phase 1) + lucide icon-race mitigation
Behavioral consistency across complaint/inquiry/observation (re-run: 0 FAIL):
- activation gate on complaints: complaint_send_to + send_to_department_form now
  reject status=open ("Activate this complaint before sending it to a department")
- observation resolve dead-end fixed: observation_change_status now allows
  hospital_admin (was triage_perm/px_admin only) + added a Resolve action on the
  observation detail page -> accepted dept responses can be resolved from the flow
- status validation: Observation.clean() rejects invalid statuses + a DB
  CheckConstraint (migration 0016 normalizes legacy "new"->"open" first)
- inquiry sent_to_department consistency: inquiry_transfer_to_department now also
  sets sent_to_department=True/At (matches observation/complaint for cross-module queries)

Lucide icon-race mitigation: added a defensive `window.lucide || {createIcons:noop}`
shim to the three base layouts + standalone CDN pages (login, select_hospital,
password reset) so the "lucide is not defined" ReferenceError can't throw during
navigation races. Audit listener classifies any residual occurrence as WARN (cosmetic).

Docs: docs/workflows.md records the intentional complaint vs inquiry/observation
differences (multi-dept join + manager review vs single-dept flat) + the field-name map.

Specs: champion spec now activates before send (matches the new gate).
2026-06-14 23:27:03 +03:00

35 lines
1.3 KiB
Python

# Generated by Django 6.0.1 on 2026-06-14 19:15
from django.conf import settings
from django.db import migrations, models
def normalize_invalid_statuses(apps, schema_editor):
"""Map any observation status not in the valid set to 'open' so the
CheckConstraint can be added without failing on legacy/seed rows."""
Observation = apps.get_model('observations', 'Observation')
valid = {'open', 'in_progress', 'resolved', 'closed'}
qs = Observation.objects.exclude(status__in=list(valid))
for obs in qs:
obs.status = 'open'
obs.save(update_fields=['status'])
class Migration(migrations.Migration):
dependencies = [
('complaints', '0019_add_response_token'),
('observations', '0015_add_response_token'),
('organizations', '0014_remove_department_manager_1st'),
('px_sources', '0001_initial'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]
operations = [
migrations.RunPython(normalize_invalid_statuses, migrations.RunPython.noop),
migrations.AddConstraint(
model_name='observation',
constraint=models.CheckConstraint(condition=models.Q(('status__in', ['open', 'in_progress', 'resolved', 'closed'])), name='observation_status_valid'),
),
]