ismail fd19216b0d
All checks were successful
Build and Push Docker Image / build (push) Successful in 1m5s
track migrations in git, regenerate fresh initial migrations, add staging-test compose, fix .gitignore
2026-05-11 23:34:39 +03:00

151 lines
12 KiB
Python

# Generated by Django 6.0.1 on 2026-05-11 20:32
import django.db.models.deletion
import uuid
from django.conf import settings
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
('organizations', '0001_initial'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]
operations = [
migrations.CreateModel(
name='ExecutiveReport',
fields=[
('created_at', models.DateTimeField(auto_now_add=True, db_index=True)),
('updated_at', models.DateTimeField(auto_now=True)),
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
('report_type', models.CharField(choices=[('weekly', 'Weekly Summary'), ('monthly', 'Monthly Summary'), ('quarterly', 'Quarterly Summary'), ('custom', 'Custom Report')], db_index=True, max_length=20)),
('status', models.CharField(choices=[('pending', 'Pending'), ('generating', 'Generating'), ('completed', 'Completed'), ('failed', 'Failed')], db_index=True, default='pending', max_length=20)),
('start_date', models.DateField()),
('end_date', models.DateField()),
('narrative_en', models.TextField(blank=True, help_text='English narrative summary')),
('narrative_ar', models.TextField(blank=True, help_text='Arabic narrative summary')),
('highlights_en', models.JSONField(blank=True, default=list, help_text='Key highlights (English)')),
('highlights_ar', models.JSONField(blank=True, default=list, help_text='Key highlights (Arabic)')),
('concerns_en', models.JSONField(blank=True, default=list, help_text='Key concerns (English)')),
('concerns_ar', models.JSONField(blank=True, default=list, help_text='Key concerns (Arabic)')),
('metrics_snapshot', models.JSONField(blank=True, default=dict, help_text='Key metrics at report time')),
('ai_model', models.CharField(blank=True, help_text='AI model used for generation', max_length=100)),
('generation_time_ms', models.IntegerField(blank=True, help_text='Generation time in milliseconds', null=True)),
('pdf_file', models.FileField(blank=True, help_text='Generated PDF report', null=True, upload_to='executive_reports/pdfs/%Y/%m/')),
('error_message', models.TextField(blank=True, help_text='Error message if generation failed')),
],
options={
'verbose_name': 'Executive Report',
'verbose_name_plural': 'Executive Reports',
'ordering': ['-created_at'],
'indexes': [models.Index(fields=['report_type', '-created_at'], name='executive_s_report__fd1ff4_idx'), models.Index(fields=['status', '-created_at'], name='executive_s_status_57ab9f_idx')],
},
),
migrations.CreateModel(
name='PredictiveInsight',
fields=[
('created_at', models.DateTimeField(auto_now_add=True, db_index=True)),
('updated_at', models.DateTimeField(auto_now=True)),
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
('insight_type', models.CharField(choices=[('trend_change', 'Trend Change'), ('anomaly', 'Anomaly Detected'), ('risk_warning', 'Risk Warning'), ('sla_breach_risk', 'SLA Breach Risk'), ('performance_drop', 'Performance Drop'), ('volume_spike', 'Volume Spike'), ('satisfaction_decline', 'Satisfaction Decline'), ('positive_trend', 'Positive Trend')], db_index=True, max_length=30)),
('severity', models.CharField(choices=[('low', 'Low'), ('medium', 'Medium'), ('high', 'High'), ('critical', 'Critical')], db_index=True, default='medium', max_length=10)),
('status', models.CharField(choices=[('new', 'New'), ('acknowledged', 'Acknowledged'), ('resolved', 'Resolved'), ('dismissed', 'Dismissed')], db_index=True, default='new', max_length=20)),
('title_en', models.CharField(max_length=300)),
('title_ar', models.CharField(blank=True, max_length=300)),
('description_en', models.TextField()),
('description_ar', models.TextField(blank=True)),
('recommendation_en', models.TextField(blank=True)),
('recommendation_ar', models.TextField(blank=True)),
('metric_type', models.CharField(blank=True, help_text='Related metric type', max_length=50)),
('entity_type', models.CharField(blank=True, help_text='Type of related entity (e.g., complaint, px_action)', max_length=50)),
('entity_id', models.CharField(blank=True, help_text='ID of related entity', max_length=100)),
('current_value', models.DecimalField(blank=True, decimal_places=2, max_digits=10, null=True)),
('predicted_value', models.DecimalField(blank=True, decimal_places=2, max_digits=10, null=True)),
('confidence_score', models.DecimalField(blank=True, decimal_places=2, help_text='AI confidence score (0-100)', max_digits=5, null=True)),
('predicted_date', models.DateField(blank=True, help_text='When this is expected to occur', null=True)),
('acknowledged_at', models.DateTimeField(blank=True, null=True)),
('ai_model', models.CharField(blank=True, max_length=100)),
('detection_metadata', models.JSONField(blank=True, default=dict)),
('acknowledged_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='acknowledged_insights', to=settings.AUTH_USER_MODEL)),
('department', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='predictive_insights', to='organizations.department')),
('hospital', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='predictive_insights', to='organizations.hospital')),
],
options={
'verbose_name': 'Predictive Insight',
'verbose_name_plural': 'Predictive Insights',
'ordering': ['-severity', '-created_at'],
},
),
migrations.CreateModel(
name='AIRecommendation',
fields=[
('created_at', models.DateTimeField(auto_now_add=True, db_index=True)),
('updated_at', models.DateTimeField(auto_now=True)),
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
('category', models.CharField(choices=[('process_improvement', 'Process Improvement'), ('resource_allocation', 'Resource Allocation'), ('training', 'Training'), ('policy_change', 'Policy Change'), ('preventive_action', 'Preventive Action'), ('performance_optimization', 'Performance Optimization'), ('communication', 'Communication'), ('quality_assurance', 'Quality Assurance')], db_index=True, max_length=30)),
('priority', models.CharField(choices=[('low', 'Low'), ('medium', 'Medium'), ('high', 'High'), ('urgent', 'Urgent')], db_index=True, default='medium', max_length=10)),
('status', models.CharField(choices=[('new', 'New'), ('under_review', 'Under Review'), ('approved', 'Approved'), ('implemented', 'Implemented'), ('rejected', 'Rejected')], db_index=True, default='new', max_length=20)),
('title_en', models.CharField(max_length=300)),
('title_ar', models.CharField(blank=True, max_length=300)),
('description_en', models.TextField()),
('description_ar', models.TextField(blank=True)),
('expected_impact_en', models.TextField(blank=True, help_text='Expected impact if implemented (English)')),
('expected_impact_ar', models.TextField(blank=True, help_text='Expected impact if implemented (Arabic)')),
('implemented_at', models.DateTimeField(blank=True, null=True)),
('confidence_score', models.DecimalField(blank=True, decimal_places=2, max_digits=5, null=True)),
('ai_model', models.CharField(blank=True, max_length=100)),
('generation_metadata', models.JSONField(blank=True, default=dict)),
('department', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='ai_recommend', to='organizations.department')),
('hospital', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='ai_recommend', to='organizations.hospital')),
('implemented_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='implemented_recommendations', to=settings.AUTH_USER_MODEL)),
('related_insight', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='recommendations', to='executive_summary.predictiveinsight')),
],
options={
'verbose_name': 'AI Recommendation',
'verbose_name_plural': 'AI Recommendations',
'ordering': ['-priority', '-created_at'],
},
),
migrations.CreateModel(
name='ExecutiveMetric',
fields=[
('created_at', models.DateTimeField(auto_now_add=True, db_index=True)),
('updated_at', models.DateTimeField(auto_now=True)),
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
('metric_date', models.DateField(db_index=True, help_text='Date of this metric snapshot')),
('metric_type', models.CharField(choices=[('complaints_total', 'Total Complaints'), ('complaints_critical', 'Critical Complaints'), ('complaints_overdue', 'Overdue Complaints'), ('complaints_resolution_time', 'Avg Resolution Time (hours)'), ('surveys_total', 'Total Surveys'), ('surveys_satisfaction', 'Satisfaction Rate %'), ('surveys_nps', 'NPS Score'), ('surveys_response_rate', 'Response Rate %'), ('actions_total', 'Total Actions'), ('actions_open', 'Open Actions'), ('actions_overdue', 'Overdue Actions'), ('actions_closed', 'Closed Actions'), ('observations_total', 'Total Observations'), ('observations_critical', 'Critical Observations'), ('inquiries_total', 'Total Inquiries'), ('inquiries_resolved', 'Resolved Inquiries'), ('call_center_total', 'Call Center Interactions'), ('call_center_satisfaction', 'Call Center Satisfaction %'), ('physician_avg_rating', 'Avg Physician Rating')], db_index=True, max_length=50)),
('metric_value', models.DecimalField(decimal_places=2, max_digits=10)),
('variance', models.DecimalField(blank=True, decimal_places=2, help_text='Variance from previous period', max_digits=10, null=True)),
('variance_direction', models.CharField(choices=[('up', 'Up'), ('down', 'Down'), ('neutral', 'Neutral')], default='neutral', help_text='Direction of variance', max_length=10)),
('metadata', models.JSONField(blank=True, default=dict)),
('hospital', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='executive_metrics', to='organizations.hospital')),
],
options={
'verbose_name': 'Executive Metric',
'verbose_name_plural': 'Executive Metrics',
'ordering': ['-metric_date', 'metric_type'],
'indexes': [models.Index(fields=['metric_date', 'metric_type'], name='executive_s_metric__f55857_idx'), models.Index(fields=['hospital', 'metric_date'], name='executive_s_hospita_9e8443_idx')],
},
),
migrations.AddIndex(
model_name='predictiveinsight',
index=models.Index(fields=['status', 'severity', '-created_at'], name='executive_s_status_35974a_idx'),
),
migrations.AddIndex(
model_name='predictiveinsight',
index=models.Index(fields=['hospital', 'status'], name='executive_s_hospita_18595e_idx'),
),
migrations.AddIndex(
model_name='airecommendation',
index=models.Index(fields=['status', 'priority', '-created_at'], name='executive_s_status_f2a1e6_idx'),
),
migrations.AddIndex(
model_name='airecommendation',
index=models.Index(fields=['hospital', 'status'], name='executive_s_hospita_322e48_idx'),
),
]