hospital-management/appointments/migrations/0003_appointmentpriorityrule_schedulingmetrics_and_more.py
Marwan Alwali 263292f6be update
2025-11-04 00:50:06 +03:00

380 lines
14 KiB
Python

# Generated by Django 5.2.7 on 2025-10-07 23:58
import django.core.validators
import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("appointments", "0002_initial"),
("core", "0001_initial"),
("patients", "0001_initial"),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]
operations = [
migrations.CreateModel(
name="AppointmentPriorityRule",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("name", models.CharField(help_text="Rule name", max_length=100)),
("description", models.TextField(help_text="Rule description")),
(
"specialties",
models.JSONField(
blank=True, default=list, help_text="Applicable specialties"
),
),
(
"diagnosis_codes",
models.JSONField(
blank=True,
default=list,
help_text="ICD-10 diagnosis codes that trigger this rule",
),
),
(
"base_priority_score",
models.IntegerField(
default=0,
help_text="Base priority score (0-100)",
validators=[
django.core.validators.MinValueValidator(0),
django.core.validators.MaxValueValidator(100),
],
),
),
(
"urgency_multiplier",
models.DecimalField(
decimal_places=2,
default=1.0,
help_text="Urgency multiplier for scoring",
max_digits=3,
validators=[
django.core.validators.MinValueValidator(0.1),
django.core.validators.MaxValueValidator(10.0),
],
),
),
(
"max_wait_days",
models.IntegerField(
blank=True,
help_text="Maximum acceptable wait time in days",
null=True,
),
),
(
"requires_same_day",
models.BooleanField(
default=False, help_text="Requires same-day appointment"
),
),
(
"is_active",
models.BooleanField(default=True, help_text="Rule is active"),
),
("created_at", models.DateTimeField(auto_now_add=True)),
("updated_at", models.DateTimeField(auto_now=True)),
(
"appointment_types",
models.ManyToManyField(
blank=True,
help_text="Applicable appointment types",
related_name="priority_rules",
to="appointments.appointmenttemplate",
),
),
(
"created_by",
models.ForeignKey(
blank=True,
help_text="User who created the rule",
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="created_priority_rules",
to=settings.AUTH_USER_MODEL,
),
),
(
"tenant",
models.ForeignKey(
help_text="Organization tenant",
on_delete=django.db.models.deletion.CASCADE,
related_name="appointment_priority_rules",
to="core.tenant",
),
),
],
options={
"verbose_name": "Appointment Priority Rule",
"verbose_name_plural": "Appointment Priority Rules",
"db_table": "appointments_priority_rule",
"ordering": ["-base_priority_score", "name"],
"indexes": [
models.Index(
fields=["tenant", "is_active"],
name="appointment_tenant__d8693d_idx",
),
models.Index(
fields=["base_priority_score"],
name="appointment_base_pr_a4d52d_idx",
),
],
},
),
migrations.CreateModel(
name="SchedulingMetrics",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("date", models.DateField(help_text="Metrics date")),
(
"total_slots",
models.IntegerField(default=0, help_text="Total available slots"),
),
(
"booked_slots",
models.IntegerField(default=0, help_text="Number of booked slots"),
),
(
"completed_appointments",
models.IntegerField(
default=0, help_text="Number of completed appointments"
),
),
(
"no_shows",
models.IntegerField(default=0, help_text="Number of no-shows"),
),
(
"cancellations",
models.IntegerField(default=0, help_text="Number of cancellations"),
),
(
"average_appointment_duration",
models.DurationField(
blank=True, help_text="Average appointment duration", null=True
),
),
(
"average_wait_time",
models.DurationField(
blank=True, help_text="Average patient wait time", null=True
),
),
(
"total_overtime_minutes",
models.IntegerField(
default=0, help_text="Total overtime in minutes"
),
),
(
"utilization_rate",
models.DecimalField(
decimal_places=2,
default=0,
help_text="Slot utilization rate percentage",
max_digits=5,
validators=[
django.core.validators.MinValueValidator(0),
django.core.validators.MaxValueValidator(100),
],
),
),
(
"no_show_rate",
models.DecimalField(
decimal_places=2,
default=0,
help_text="No-show rate percentage",
max_digits=5,
validators=[
django.core.validators.MinValueValidator(0),
django.core.validators.MaxValueValidator(100),
],
),
),
("created_at", models.DateTimeField(auto_now_add=True)),
("updated_at", models.DateTimeField(auto_now=True)),
(
"provider",
models.ForeignKey(
help_text="Healthcare provider",
on_delete=django.db.models.deletion.CASCADE,
related_name="scheduling_metrics",
to=settings.AUTH_USER_MODEL,
),
),
(
"tenant",
models.ForeignKey(
help_text="Organization tenant",
on_delete=django.db.models.deletion.CASCADE,
related_name="scheduling_metrics",
to="core.tenant",
),
),
],
options={
"verbose_name": "Scheduling Metrics",
"verbose_name_plural": "Scheduling Metrics",
"db_table": "appointments_scheduling_metrics",
"ordering": ["-date"],
"indexes": [
models.Index(
fields=["tenant", "provider", "date"],
name="appointment_tenant__e82448_idx",
),
models.Index(fields=["date"], name="appointment_date_bf0416_idx"),
models.Index(
fields=["utilization_rate"],
name="appointment_utiliza_64b3e0_idx",
),
models.Index(
fields=["no_show_rate"], name="appointment_no_show_61eedc_idx"
),
],
"unique_together": {("tenant", "provider", "date")},
},
),
migrations.CreateModel(
name="SchedulingPreference",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
(
"preferred_days",
models.JSONField(
blank=True,
default=list,
help_text='Preferred days of week (e.g., ["Monday", "Wednesday"])',
),
),
(
"preferred_times",
models.JSONField(
blank=True,
default=list,
help_text='Preferred times of day (e.g., ["morning", "afternoon"])',
),
),
(
"average_no_show_rate",
models.DecimalField(
decimal_places=2,
default=0,
help_text="Average no-show rate percentage",
max_digits=5,
validators=[
django.core.validators.MinValueValidator(0),
django.core.validators.MaxValueValidator(100),
],
),
),
(
"average_late_arrival_minutes",
models.IntegerField(
default=0, help_text="Average late arrival in minutes"
),
),
(
"total_appointments",
models.IntegerField(
default=0, help_text="Total number of appointments"
),
),
(
"completed_appointments",
models.IntegerField(
default=0, help_text="Number of completed appointments"
),
),
(
"home_address",
models.TextField(
blank=True, help_text="Patient home address", null=True
),
),
(
"travel_time_to_clinic",
models.DurationField(
blank=True,
help_text="Estimated travel time to clinic",
null=True,
),
),
("created_at", models.DateTimeField(auto_now_add=True)),
("updated_at", models.DateTimeField(auto_now=True)),
(
"patient",
models.OneToOneField(
help_text="Patient profile",
on_delete=django.db.models.deletion.CASCADE,
related_name="scheduling_preference",
to="patients.patientprofile",
),
),
(
"preferred_providers",
models.ManyToManyField(
blank=True,
help_text="Preferred healthcare providers",
related_name="preferred_by_patients",
to=settings.AUTH_USER_MODEL,
),
),
(
"tenant",
models.ForeignKey(
help_text="Organization tenant",
on_delete=django.db.models.deletion.CASCADE,
related_name="scheduling_preferences",
to="core.tenant",
),
),
],
options={
"verbose_name": "Scheduling Preference",
"verbose_name_plural": "Scheduling Preferences",
"db_table": "appointments_scheduling_preference",
"indexes": [
models.Index(
fields=["tenant", "patient"],
name="appointment_tenant__c6a42f_idx",
),
models.Index(
fields=["average_no_show_rate"],
name="appointment_average_54e4a7_idx",
),
],
},
),
]