# Generated by Django 5.2.6 on 2025-09-19 10: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): initial = True dependencies = [ ("core", "0001_initial"), ("hr", "0001_initial"), ("patients", "0001_initial"), migrations.swappable_dependency(settings.AUTH_USER_MODEL), ] operations = [ migrations.CreateModel( name="AuditPlan", fields=[ ( "id", models.BigAutoField( auto_created=True, primary_key=True, serialize=False, verbose_name="ID", ), ), ("title", models.CharField(max_length=200)), ("description", models.TextField()), ( "audit_type", models.CharField( choices=[ ("internal", "Internal"), ("external", "External"), ("regulatory", "Regulatory"), ("accreditation", "Accreditation"), ("quality", "Quality"), ("compliance", "Compliance"), ("safety", "Safety"), ("operational", "Operational"), ("financial", "Financial"), ("clinical", "Clinical"), ], max_length=20, ), ), ("scope", models.TextField()), ("criteria", models.TextField()), ("planned_start_date", models.DateField()), ("planned_end_date", models.DateField()), ("actual_start_date", models.DateField(blank=True, null=True)), ("actual_end_date", models.DateField(blank=True, null=True)), ( "status", models.CharField( choices=[ ("planned", "Planned"), ("in_progress", "In Progress"), ("completed", "Completed"), ("cancelled", "Cancelled"), ("postponed", "Postponed"), ], default="planned", max_length=20, ), ), ( "priority", models.CharField( choices=[ ("low", "Low"), ("medium", "Medium"), ("high", "High"), ("urgent", "Urgent"), ], default="medium", max_length=10, ), ), ("regulatory_requirement", models.BooleanField(default=False)), ("accreditation_body", models.CharField(blank=True, max_length=200)), ("objectives", models.TextField(blank=True)), ("notes", models.TextField(blank=True)), ("created_at", models.DateTimeField(auto_now_add=True)), ("updated_at", models.DateTimeField(auto_now=True)), ( "audit_team", models.ManyToManyField( blank=True, related_name="audit_team_memberships", to=settings.AUTH_USER_MODEL, ), ), ( "auditor", models.ForeignKey( blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name="led_audits", to=settings.AUTH_USER_MODEL, ), ), ( "created_by", models.ForeignKey( on_delete=django.db.models.deletion.CASCADE, related_name="created_audit_plans", to=settings.AUTH_USER_MODEL, ), ), ( "department", models.ForeignKey( blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name="audit_plans", to="hr.department", ), ), ( "tenant", models.ForeignKey( on_delete=django.db.models.deletion.CASCADE, related_name="audit_plans", to="core.tenant", ), ), ], options={ "db_table": "audit_plan", "ordering": ["planned_start_date"], }, ), migrations.CreateModel( name="AuditFinding", fields=[ ( "id", models.BigAutoField( auto_created=True, primary_key=True, serialize=False, verbose_name="ID", ), ), ("finding_number", models.CharField(max_length=50)), ("title", models.CharField(max_length=200)), ("description", models.TextField()), ( "finding_type", models.CharField( choices=[ ("non_conformity", "Non-Conformity"), ("observation", "Observation"), ( "opportunity_for_improvement", "Opportunity for Improvement", ), ("positive_finding", "Positive Finding"), ("recommendation", "Recommendation"), ], max_length=30, ), ), ("finding_date", models.DateField()), ( "severity", models.CharField( choices=[ ("minor", "Minor"), ("major", "Major"), ("critical", "Critical"), ], max_length=20, ), ), ( "category", models.CharField( choices=[ ("documentation", "Documentation"), ("process", "Process"), ("training", "Training"), ("equipment", "Equipment"), ("environment", "Environment"), ("management", "Management"), ("communication", "Communication"), ("safety", "Safety"), ("quality", "Quality"), ("compliance", "Compliance"), ], max_length=20, ), ), ("criteria_reference", models.CharField(max_length=200)), ("evidence", models.TextField()), ("root_cause", models.TextField(blank=True)), ("corrective_action_required", models.BooleanField(default=True)), ("corrective_actions", models.TextField(blank=True)), ("target_completion_date", models.DateField(blank=True, null=True)), ("actual_completion_date", models.DateField(blank=True, null=True)), ( "status", models.CharField( choices=[ ("open", "Open"), ("in_progress", "In Progress"), ("completed", "Completed"), ("verified", "Verified"), ("closed", "Closed"), ], default="open", max_length=20, ), ), ("verification_method", models.CharField(blank=True, max_length=200)), ("verified_date", models.DateField(blank=True, null=True)), ("created_at", models.DateTimeField(auto_now_add=True)), ("updated_at", models.DateTimeField(auto_now=True)), ( "created_by", models.ForeignKey( on_delete=django.db.models.deletion.CASCADE, related_name="created_findings", to=settings.AUTH_USER_MODEL, ), ), ( "responsible_person", models.ForeignKey( blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name="responsible_findings", to=settings.AUTH_USER_MODEL, ), ), ( "tenant", models.ForeignKey( on_delete=django.db.models.deletion.CASCADE, related_name="audit_findings", to="core.tenant", ), ), ( "verified_by", models.ForeignKey( blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name="verified_findings", to=settings.AUTH_USER_MODEL, ), ), ( "audit_plan", models.ForeignKey( on_delete=django.db.models.deletion.CASCADE, related_name="findings", to="quality.auditplan", ), ), ], options={ "db_table": "audit_finding", "ordering": ["-severity", "target_completion_date"], }, ), migrations.CreateModel( name="ImprovementProject", fields=[ ( "id", models.BigAutoField( auto_created=True, primary_key=True, serialize=False, verbose_name="ID", ), ), ("project_number", models.CharField(max_length=50, unique=True)), ("title", models.CharField(max_length=200)), ("description", models.TextField()), ( "project_type", models.CharField( choices=[ ("quality_improvement", "Quality Improvement"), ("process_improvement", "Process Improvement"), ("safety_initiative", "Safety Initiative"), ("compliance_project", "Compliance Project"), ("cost_reduction", "Cost Reduction"), ("efficiency_improvement", "Efficiency Improvement"), ("patient_satisfaction", "Patient Satisfaction"), ("staff_satisfaction", "Staff Satisfaction"), ("technology_implementation", "Technology Implementation"), ("training_program", "Training Program"), ], max_length=30, ), ), ( "methodology", models.CharField( choices=[ ("pdsa", "PDSA (Plan-Do-Study-Act)"), ("lean", "Lean"), ("six_sigma", "Six Sigma"), ("kaizen", "Kaizen"), ("root_cause_analysis", "Root Cause Analysis"), ("failure_mode_analysis", "Failure Mode Analysis"), ("other", "Other"), ], max_length=30, ), ), ("problem_statement", models.TextField()), ("goal_statement", models.TextField()), ("success_metrics", models.TextField()), ("baseline_data", models.TextField(blank=True)), ("target_metrics", models.TextField()), ("scope", models.TextField()), ("planned_start_date", models.DateField()), ("planned_end_date", models.DateField()), ("actual_start_date", models.DateField(blank=True, null=True)), ("actual_end_date", models.DateField(blank=True, null=True)), ( "status", models.CharField( choices=[ ("planned", "Planned"), ("active", "Active"), ("on_hold", "On Hold"), ("completed", "Completed"), ("cancelled", "Cancelled"), ], default="planned", max_length=20, ), ), ( "phase", models.CharField( choices=[ ("define", "Define"), ("measure", "Measure"), ("analyze", "Analyze"), ("improve", "Improve"), ("control", "Control"), ("plan", "Plan"), ("do", "Do"), ("study", "Study"), ("act", "Act"), ], default="define", max_length=20, ), ), ( "estimated_cost", models.DecimalField( blank=True, decimal_places=2, max_digits=12, null=True ), ), ("resources_required", models.TextField(blank=True)), ( "actual_cost", models.DecimalField( blank=True, decimal_places=2, max_digits=12, null=True ), ), ( "roi_expected", models.DecimalField( blank=True, decimal_places=2, max_digits=10, null=True ), ), ( "roi_actual", models.DecimalField( blank=True, decimal_places=2, max_digits=10, null=True ), ), ("lessons_learned", models.TextField(blank=True)), ("notes", models.TextField(blank=True)), ("sustainability_plan", models.TextField(blank=True)), ("created_at", models.DateTimeField(auto_now_add=True)), ("updated_at", models.DateTimeField(auto_now=True)), ( "created_by", models.ForeignKey( on_delete=django.db.models.deletion.CASCADE, related_name="created_improvement_projects", to=settings.AUTH_USER_MODEL, ), ), ( "department", models.ForeignKey( blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name="improvement_projects", to="hr.department", ), ), ( "project_manager", models.ForeignKey( blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name="managed_projects", to=settings.AUTH_USER_MODEL, ), ), ( "project_team", models.ManyToManyField( blank=True, related_name="project_team_memberships", to=settings.AUTH_USER_MODEL, ), ), ( "sponsor", models.ForeignKey( blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name="sponsored_projects", to=settings.AUTH_USER_MODEL, ), ), ( "tenant", models.ForeignKey( on_delete=django.db.models.deletion.CASCADE, related_name="improvement_projects", to="core.tenant", ), ), ], options={ "db_table": "improvement_project", "ordering": ["planned_start_date"], }, ), migrations.CreateModel( name="IncidentReport", fields=[ ( "id", models.BigAutoField( auto_created=True, primary_key=True, serialize=False, verbose_name="ID", ), ), ("incident_number", models.CharField(max_length=50, unique=True)), ("title", models.CharField(max_length=200)), ("description", models.TextField()), ( "incident_type", models.CharField( choices=[ ("medication_error", "Medication Error"), ("fall", "Fall"), ("infection", "Infection"), ("equipment_failure", "Equipment Failure"), ("documentation_error", "Documentation Error"), ("communication_failure", "Communication Failure"), ("surgical_complication", "Surgical Complication"), ("diagnostic_error", "Diagnostic Error"), ("treatment_delay", "Treatment Delay"), ("other", "Other"), ], max_length=30, ), ), ( "severity", models.CharField( choices=[ ("no_harm", "No Harm"), ("minor_harm", "Minor Harm"), ("moderate_harm", "Moderate Harm"), ("severe_harm", "Severe Harm"), ("death", "Death"), ], max_length=20, ), ), ( "category", models.CharField( choices=[ ("patient_safety", "Patient Safety"), ("medication", "Medication"), ("infection_control", "Infection Control"), ("equipment", "Equipment"), ("documentation", "Documentation"), ("communication", "Communication"), ("surgical", "Surgical"), ("diagnostic", "Diagnostic"), ("treatment", "Treatment"), ("environmental", "Environmental"), ], max_length=30, ), ), ("location", models.CharField(max_length=200)), ("incident_date", models.DateField()), ("incident_time", models.TimeField()), ("discovered_date", models.DateTimeField()), ("witness_information", models.TextField(blank=True, null=True)), ( "status", models.CharField( choices=[ ("reported", "Reported"), ("under_investigation", "Under Investigation"), ("investigated", "Investigated"), ("closed", "Closed"), ("cancelled", "Cancelled"), ], default="reported", max_length=30, ), ), ( "priority", models.CharField( choices=[ ("low", "Low"), ("medium", "Medium"), ("high", "High"), ("urgent", "Urgent"), ], default="medium", max_length=10, ), ), ("root_cause", models.TextField(blank=True)), ("contributing_factors", models.TextField(blank=True)), ("corrective_actions", models.TextField(blank=True)), ("preventive_actions", models.TextField(blank=True)), ("due_date", models.DateField(blank=True, null=True)), ("closed_date", models.DateTimeField(blank=True, null=True)), ("is_confidential", models.BooleanField(default=False)), ("regulatory_notification", models.BooleanField(default=False)), ("created_at", models.DateTimeField(auto_now_add=True)), ("updated_at", models.DateTimeField(auto_now=True)), ( "assigned_to", models.ForeignKey( blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name="assigned_incidents", to=settings.AUTH_USER_MODEL, ), ), ( "patient", models.ForeignKey( blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name="incident_reports", to="patients.patientprofile", ), ), ( "reported_by", models.ForeignKey( on_delete=django.db.models.deletion.CASCADE, related_name="reported_incidents", to=settings.AUTH_USER_MODEL, ), ), ( "tenant", models.ForeignKey( on_delete=django.db.models.deletion.CASCADE, related_name="incident_reports", to="core.tenant", ), ), ], options={ "db_table": "incident_report", "ordering": ["-incident_date"], }, ), migrations.CreateModel( name="QualityIndicator", fields=[ ( "id", models.BigAutoField( auto_created=True, primary_key=True, serialize=False, verbose_name="ID", ), ), ("name", models.CharField(max_length=200)), ("description", models.TextField()), ( "category", models.CharField( choices=[ ("clinical", "Clinical"), ("safety", "Safety"), ("operational", "Operational"), ("financial", "Financial"), ("patient_satisfaction", "Patient Satisfaction"), ("staff_satisfaction", "Staff Satisfaction"), ("compliance", "Compliance"), ("efficiency", "Efficiency"), ("quality", "Quality"), ("outcome", "Outcome"), ], max_length=50, ), ), ( "type", models.CharField( choices=[ ("structure", "Structure"), ("process", "Process"), ("outcome", "Outcome"), ("balancing", "Balancing"), ], max_length=20, ), ), ("measurement_unit", models.CharField(max_length=50)), ("target_value", models.DecimalField(decimal_places=2, max_digits=10)), ("current_value", models.DecimalField(decimal_places=2, max_digits=10)), ( "threshold_warning", models.DecimalField(decimal_places=2, max_digits=10), ), ( "threshold_critical", models.DecimalField(decimal_places=2, max_digits=10), ), ("calculation_method", models.TextField()), ("data_source", models.CharField(max_length=200)), ( "frequency", models.CharField( choices=[ ("daily", "Daily"), ("weekly", "Weekly"), ("monthly", "Monthly"), ("quarterly", "Quarterly"), ("annually", "Annually"), ], max_length=20, ), ), ("is_active", models.BooleanField(default=True)), ("regulatory_requirement", models.BooleanField(default=False)), ("created_at", models.DateTimeField(auto_now_add=True)), ("updated_at", models.DateTimeField(auto_now=True)), ( "responsible_department", models.ForeignKey( blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to="hr.department", ), ), ( "responsible_user", models.ForeignKey( blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name="responsible_quality_indicators", to=settings.AUTH_USER_MODEL, ), ), ( "tenant", models.ForeignKey( on_delete=django.db.models.deletion.CASCADE, related_name="quality_indicators", to="core.tenant", ), ), ], options={ "db_table": "quality_indicator", "ordering": ["name"], }, ), migrations.CreateModel( name="QualityMeasurement", fields=[ ( "id", models.BigAutoField( auto_created=True, primary_key=True, serialize=False, verbose_name="ID", ), ), ("measurement_date", models.DateField()), ("value", models.DecimalField(decimal_places=2, max_digits=10)), ("numerator", models.IntegerField(blank=True, null=True)), ("denominator", models.IntegerField(blank=True, null=True)), ( "status", models.CharField( choices=[ ("within_target", "Within Target"), ("warning", "Warning"), ("critical", "Critical"), ("improving", "Improving"), ("declining", "Declining"), ], max_length=20, ), ), ("measurement_method", models.TextField(blank=True)), ( "sample_size", models.DecimalField( blank=True, decimal_places=2, max_digits=10, null=True ), ), ( "data_source", models.CharField(blank=True, max_length=200, null=True), ), ("notes", models.TextField(blank=True)), ("data_source_reference", models.CharField(blank=True, max_length=200)), ("verified_at", models.DateTimeField(blank=True, null=True)), ("created_at", models.DateTimeField(auto_now_add=True)), ("updated_at", models.DateTimeField(auto_now=True)), ( "created_by", models.ForeignKey( on_delete=django.db.models.deletion.CASCADE, related_name="created_measurements", to=settings.AUTH_USER_MODEL, ), ), ( "indicator", models.ForeignKey( on_delete=django.db.models.deletion.CASCADE, related_name="measurements", to="quality.qualityindicator", ), ), ( "tenant", models.ForeignKey( on_delete=django.db.models.deletion.CASCADE, related_name="quality_measurements", to="core.tenant", ), ), ( "verified_by", models.ForeignKey( blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name="verified_measurements", to=settings.AUTH_USER_MODEL, ), ), ], options={ "db_table": "quality_measurement", "ordering": ["-measurement_date"], }, ), migrations.CreateModel( name="RiskAssessment", fields=[ ( "id", models.BigAutoField( auto_created=True, primary_key=True, serialize=False, verbose_name="ID", ), ), ("title", models.CharField(max_length=200)), ("description", models.TextField()), ( "risk_category", models.CharField( choices=[ ("clinical", "Clinical"), ("operational", "Operational"), ("financial", "Financial"), ("regulatory", "Regulatory"), ("reputational", "Reputational"), ("strategic", "Strategic"), ("technology", "Technology"), ("environmental", "Environmental"), ("security", "Security"), ("legal", "Legal"), ], max_length=20, ), ), ( "risk_type", models.CharField( choices=[ ("patient_safety", "Patient Safety"), ("quality", "Quality"), ("compliance", "Compliance"), ("financial", "Financial"), ("operational", "Operational"), ("strategic", "Strategic"), ("technology", "Technology"), ("environmental", "Environmental"), ("security", "Security"), ("legal", "Legal"), ], max_length=20, ), ), ( "likelihood", models.IntegerField( choices=[ (1, "Very Low"), (2, "Low"), (3, "Medium"), (4, "High"), (5, "Very High"), ] ), ), ( "impact", models.IntegerField( choices=[ (1, "Very Low"), (2, "Low"), (3, "Medium"), (4, "High"), (5, "Very High"), ] ), ), ( "risk_score", models.IntegerField( validators=[ django.core.validators.MinValueValidator(1), django.core.validators.MaxValueValidator(25), ] ), ), ( "risk_level", models.CharField( choices=[ ("low", "Low"), ("medium", "Medium"), ("high", "High"), ("critical", "Critical"), ], max_length=20, ), ), ("current_controls", models.TextField()), ( "control_effectiveness", models.CharField( choices=[ ("poor", "Poor"), ("fair", "Fair"), ("good", "Good"), ("excellent", "Excellent"), ], max_length=20, ), ), ("mitigation_plan", models.TextField()), ("target_completion_date", models.DateTimeField()), ("review_date", models.DateField()), ("review_notes", models.TextField(blank=True, null=True)), ( "status", models.CharField( choices=[ ("draft", "Draft"), ("active", "Active"), ("under_review", "Under Review"), ("closed", "Closed"), ("cancelled", "Cancelled"), ], default="draft", max_length=20, ), ), ("created_at", models.DateTimeField(auto_now_add=True)), ("updated_at", models.DateTimeField(auto_now=True)), ( "created_by", models.ForeignKey( on_delete=django.db.models.deletion.CASCADE, related_name="created_risk_assessments", to=settings.AUTH_USER_MODEL, ), ), ( "incident_report", models.ForeignKey( blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name="risk_assessments", to="quality.incidentreport", ), ), ( "responsible_person", models.ForeignKey( blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name="responsible_risks", to=settings.AUTH_USER_MODEL, ), ), ( "tenant", models.ForeignKey( on_delete=django.db.models.deletion.CASCADE, related_name="risk_assessments", to="core.tenant", ), ), ], options={ "db_table": "risk_assessment", "ordering": ["-risk_score", "-created_at"], }, ), migrations.AddIndex( model_name="auditplan", index=models.Index( fields=["tenant", "audit_type", "status"], name="audit_plan_tenant__ae9ac5_idx", ), ), migrations.AddIndex( model_name="auditplan", index=models.Index( fields=["department", "auditor"], name="audit_plan_departm_35e0f4_idx" ), ), migrations.AddIndex( model_name="auditplan", index=models.Index( fields=["planned_start_date", "planned_end_date"], name="audit_plan_planned_270c4b_idx", ), ), migrations.AddIndex( model_name="auditfinding", index=models.Index( fields=["tenant", "audit_plan", "finding_type"], name="audit_findi_tenant__297c78_idx", ), ), migrations.AddIndex( model_name="auditfinding", index=models.Index( fields=["severity", "status", "responsible_person"], name="audit_findi_severit_37dcec_idx", ), ), migrations.AddIndex( model_name="auditfinding", index=models.Index( fields=["target_completion_date", "verified_by"], name="audit_findi_target__fae3cf_idx", ), ), migrations.AlterUniqueTogether( name="auditfinding", unique_together={("audit_plan", "finding_number")}, ), migrations.AddIndex( model_name="improvementproject", index=models.Index( fields=["tenant", "project_type", "status"], name="improvement_tenant__125e2f_idx", ), ), migrations.AddIndex( model_name="improvementproject", index=models.Index( fields=["project_manager", "sponsor", "department"], name="improvement_project_af5638_idx", ), ), migrations.AddIndex( model_name="improvementproject", index=models.Index( fields=["planned_start_date", "planned_end_date"], name="improvement_planned_ac84fb_idx", ), ), migrations.AddIndex( model_name="incidentreport", index=models.Index( fields=["tenant", "incident_type", "severity"], name="incident_re_tenant__98d502_idx", ), ), migrations.AddIndex( model_name="incidentreport", index=models.Index( fields=["status", "priority", "assigned_to"], name="incident_re_status_ca8f48_idx", ), ), migrations.AddIndex( model_name="incidentreport", index=models.Index( fields=["incident_date", "patient"], name="incident_re_inciden_58af86_idx", ), ), migrations.AddIndex( model_name="qualityindicator", index=models.Index( fields=["tenant", "category", "type"], name="quality_ind_tenant__ddd0bb_idx", ), ), migrations.AddIndex( model_name="qualityindicator", index=models.Index( fields=["is_active", "regulatory_requirement"], name="quality_ind_is_acti_d5de60_idx", ), ), migrations.AddIndex( model_name="qualityindicator", index=models.Index( fields=["responsible_department", "responsible_user"], name="quality_ind_respons_59e154_idx", ), ), migrations.AddIndex( model_name="qualitymeasurement", index=models.Index( fields=["tenant", "indicator", "measurement_date"], name="quality_mea_tenant__7f64b3_idx", ), ), migrations.AddIndex( model_name="qualitymeasurement", index=models.Index( fields=["status", "verified_by"], name="quality_mea_status_8f5d57_idx" ), ), migrations.AddIndex( model_name="qualitymeasurement", index=models.Index( fields=["created_by", "created_at"], name="quality_mea_created_ac4c92_idx", ), ), migrations.AlterUniqueTogether( name="qualitymeasurement", unique_together={("indicator", "measurement_date")}, ), migrations.AddIndex( model_name="riskassessment", index=models.Index( fields=["tenant", "risk_category", "risk_level"], name="risk_assess_tenant__8ecf55_idx", ), ), migrations.AddIndex( model_name="riskassessment", index=models.Index( fields=["status", "responsible_person"], name="risk_assess_status_0240b3_idx", ), ), migrations.AddIndex( model_name="riskassessment", index=models.Index( fields=["review_date", "created_by"], name="risk_assess_review__90054e_idx", ), ), ]