Emergency App ============= **Purpose**: Handle situations where the assigned field team is unavailable on survey or installation day — find backup teams or reschedule. Responsibilities ---------------- - Log emergency events (team unavailable for scheduled survey or installation) - Search for available backup teams in the same zone - Create emergency assignments to backup teams - Manage priority rescheduling when no backup is available - Track emergency resolution Dependencies ------------ - **accounts** — Team availability checks, Central Ops handlers - **surveys** — Emergency events linked to surveys - **installations** — Emergency events linked to installations Key Models ---------- - **EmergencyEvent** — Records that a team is unavailable for a scheduled job. Links to either a Survey or an Installation (exactly one, enforced by constraint). Tracks resolution status. - **BackupSearch** — Log of each team checked during the backup search process. Records whether the team was available. - **EmergencyAssignment** — When a backup team is found, records the reassignment with outcome tracking. - **PriorityReschedule** — When no backup is found, records the new date/time offered to the customer and their confirmation status. Business Rules -------------- - An emergency can only be linked to one survey OR one installation, never both, never neither. - Backup search checks teams in the same zone first, then adjacent zones. - Only teams with ``is_available=True`` and matching ``team_type`` (survey or installation) are considered. - If no backup is found within the zone, a priority reschedule is created. - Priority reschedules require customer confirmation — the new date is proposed, not imposed. - Emergency events must be resolved (either reassigned or rescheduled) within 4 hours of creation. - All emergency events are flagged on the Central Ops dashboard for immediate attention.