Emergency Models

EmergencyEvent

Records that an assigned field team is unavailable for a scheduled survey or installation.

Field

Type

Constraints

Description

id

UUIDField

PK, default=uuid4

Primary key

event_type

CharField(20)

choices: survey, installation

What type of job was affected

survey

ForeignKey(Survey)

nullable, on_delete=CASCADE

If a survey emergency

installation

ForeignKey(Installation)

nullable, on_delete=CASCADE

If an installation emergency

original_team

ForeignKey(Team)

not null, on_delete=PROTECT

Team that reported unavailability

reason

TextField

not null

Why the team is unavailable

reported_by

ForeignKey(User)

not null, on_delete=PROTECT

Who reported the emergency

status

CharField(20)

choices: reported, searching_backup, backup_found, reassigned, rescheduled

Event resolution state

created_at

DateTimeField

auto_now_add

When reported

resolved_at

DateTimeField

nullable

When resolved

Constraint: Exactly one of survey or installation must be non-null (enforced via CheckConstraint).

Indexes: status, event_type, created_at

BackupSearch

Log of each team checked during the backup team search process.

Field

Type

Constraints

Description

id

UUIDField

PK, default=uuid4

Primary key

emergency

ForeignKey(EmergencyEvent)

not null, on_delete=CASCADE

Parent emergency event

searched_team

ForeignKey(Team)

not null, on_delete=PROTECT

Team that was checked

is_available

BooleanField

not null

Whether the team was available

searched_at

DateTimeField

auto_now_add

When the check was performed

searched_by

ForeignKey(User)

not null, on_delete=PROTECT

Central Ops who performed the search

EmergencyAssignment

Records the reassignment to a backup team when one is found.

Field

Type

Constraints

Description

id

UUIDField

PK, default=uuid4

Primary key

emergency

OneToOneField(EmergencyEvent)

not null, on_delete=CASCADE

Parent emergency event

backup_team

ForeignKey(Team)

not null, on_delete=PROTECT

Team taking over

assigned_by

ForeignKey(User)

not null, on_delete=PROTECT

Central Ops who made the assignment

assigned_at

DateTimeField

auto_now_add

Assignment timestamp

outcome

CharField(20)

choices: completed, failed, cancelled

Final outcome of backup assignment

PriorityReschedule

Records a rescheduled appointment when no backup team is available.

Field

Type

Constraints

Description

id

UUIDField

PK, default=uuid4

Primary key

emergency

OneToOneField(EmergencyEvent)

not null, on_delete=CASCADE

Parent emergency event

new_date

DateField

not null

Proposed new date

new_time_slot

CharField(20)

choices: morning, afternoon, evening

Proposed new time slot

customer_confirmed

BooleanField

default=False

Customer agreed to new date

rescheduled_by

ForeignKey(User)

not null, on_delete=PROTECT

Central Ops who rescheduled

created_at

DateTimeField

auto_now_add

When reschedule was created