HH/apps/rca/migrations/0001_initial.py
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

222 lines
15 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 = [
('contenttypes', '0002_remove_content_type_name'),
('organizations', '0001_initial'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]
operations = [
migrations.CreateModel(
name='RootCauseAnalysis',
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)),
('object_id', models.UUIDField(blank=True, db_index=True, help_text='ID of the related item', null=True)),
('title', models.CharField(max_length=500)),
('description', models.TextField(help_text='Description of the incident/issue')),
('background', models.TextField(blank=True, help_text='Background information and context')),
('status', models.CharField(choices=[('draft', 'Draft'), ('in_progress', 'In Progress'), ('review', 'Under Review'), ('approved', 'Approved'), ('closed', 'Closed')], db_index=True, default='draft', max_length=20)),
('severity', models.CharField(choices=[('low', 'Low'), ('medium', 'Medium'), ('high', 'High'), ('critical', 'Critical')], db_index=True, default='medium', max_length=20)),
('priority', models.CharField(choices=[('low', 'Low'), ('medium', 'Medium'), ('high', 'High'), ('critical', 'Critical')], db_index=True, default='medium', max_length=20)),
('root_cause_summary', models.TextField(blank=True, help_text='Summary of root cause analysis findings')),
('assigned_at', models.DateTimeField(blank=True, null=True)),
('approved_at', models.DateTimeField(blank=True, null=True)),
('approval_notes', models.TextField(blank=True)),
('closed_at', models.DateTimeField(blank=True, null=True)),
('closure_notes', models.TextField(blank=True)),
('target_completion_date', models.DateField(blank=True, help_text='Target date for RCA completion', null=True)),
('actual_completion_date', models.DateField(blank=True, null=True)),
('metadata', models.JSONField(blank=True, default=dict)),
('is_deleted', models.BooleanField(db_index=True, default=False)),
('deleted_at', models.DateTimeField(blank=True, null=True)),
('approved_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='rca_approved_items', to=settings.AUTH_USER_MODEL)),
('assigned_to', models.ForeignKey(blank=True, help_text='Person responsible for RCA', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='assigned_rcas', to=settings.AUTH_USER_MODEL)),
('closed_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='closed_rcas', to=settings.AUTH_USER_MODEL)),
('content_type', models.ForeignKey(blank=True, help_text='Type of the related item', null=True, on_delete=django.db.models.deletion.PROTECT, related_name='related_rcas', to='contenttypes.contenttype')),
('created_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='created_rcas', to=settings.AUTH_USER_MODEL)),
('deleted_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='deleted_rcas', to=settings.AUTH_USER_MODEL)),
('department', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='rcas', to='organizations.department')),
('hospital', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='rcas', to='organizations.hospital')),
],
options={
'verbose_name': 'Root Cause Analysis',
'verbose_name_plural': 'Root Cause Analyses',
'ordering': ['-created_at'],
},
),
migrations.CreateModel(
name='RCAStatusLog',
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)),
('old_status', models.CharField(blank=True, max_length=20)),
('new_status', models.CharField(db_index=True, max_length=20)),
('notes', models.TextField(blank=True)),
('metadata', models.JSONField(blank=True, default=dict)),
('changed_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='rca_status_changes', to=settings.AUTH_USER_MODEL)),
('rca', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='status_logs', to='rca.rootcauseanalysis')),
],
options={
'verbose_name': 'RCA Status Log',
'verbose_name_plural': 'RCA Status Logs',
'ordering': ['-created_at'],
},
),
migrations.CreateModel(
name='RCARootCause',
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)),
('description', models.TextField(help_text='Description of root cause')),
('category', models.CharField(choices=[('process', 'Process/Procedure'), ('people', 'People/Training'), ('equipment', 'Equipment/Resources'), ('communication', 'Communication'), ('policy', 'Policy/Regulation'), ('environment', 'Environment'), ('technology', 'Technology/Systems'), ('other', 'Other')], db_index=True, max_length=50)),
('contributing_factors', models.TextField(blank=True, help_text='Factors that contributed to this root cause')),
('likelihood', models.IntegerField(blank=True, help_text='Likelihood score (1-5)', null=True)),
('impact', models.IntegerField(blank=True, help_text='Impact score (1-5)', null=True)),
('risk_score', models.IntegerField(blank=True, help_text='Risk score (likelihood * impact)', null=True)),
('evidence', models.TextField(blank=True, help_text='Evidence supporting this root cause')),
('is_verified', models.BooleanField(default=False)),
('verified_at', models.DateTimeField(blank=True, null=True)),
('verified_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='verified_root_causes', to=settings.AUTH_USER_MODEL)),
('rca', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='root_causes', to='rca.rootcauseanalysis')),
],
options={
'verbose_name': 'Root Cause',
'verbose_name_plural': 'Root Causes',
'ordering': ['-created_at'],
},
),
migrations.CreateModel(
name='RCANote',
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)),
('note', models.TextField()),
('is_internal', models.BooleanField(default=True, help_text='Internal note (not visible in reports)')),
('created_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='rca_notes', to=settings.AUTH_USER_MODEL)),
('rca', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='notes', to='rca.rootcauseanalysis')),
],
options={
'verbose_name': 'RCA Note',
'verbose_name_plural': 'RCA Notes',
'ordering': ['-created_at'],
},
),
migrations.CreateModel(
name='RCACorrectiveAction',
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)),
('description', models.TextField(help_text='Description of corrective action')),
('action_type', models.CharField(choices=[('preventive', 'Preventive'), ('corrective', 'Corrective'), ('immediate', 'Immediate Action'), ('long_term', 'Long-term Solution')], db_index=True, default='corrective', max_length=20)),
('target_date', models.DateField(blank=True, help_text='Target date for completion', null=True)),
('completion_date', models.DateField(blank=True, help_text='Actual completion date', null=True)),
('status', models.CharField(choices=[('not_started', 'Not Started'), ('in_progress', 'In Progress'), ('completed', 'Completed'), ('cancelled', 'Cancelled')], db_index=True, default='not_started', max_length=20)),
('effectiveness_measure', models.TextField(blank=True, help_text='How effectiveness will be measured')),
('effectiveness_assessment', models.TextField(blank=True, help_text='Assessment of action effectiveness')),
('effectiveness_score', models.IntegerField(blank=True, help_text='Effectiveness score (1-5)', null=True)),
('obstacles', models.TextField(blank=True, help_text='Obstacles encountered during implementation')),
('metadata', models.JSONField(blank=True, default=dict)),
('responsible_person', models.ForeignKey(blank=True, help_text='Person responsible for implementing the action', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='corrective_actions', to='organizations.staff')),
('root_cause', models.ForeignKey(blank=True, help_text='Root cause this action addresses', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='corrective_actions', to='rca.rcarootcause')),
('rca', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='corrective_actions', to='rca.rootcauseanalysis')),
],
options={
'verbose_name': 'Corrective Action',
'verbose_name_plural': 'Corrective Actions',
'ordering': ['target_date', '-created_at'],
},
),
migrations.CreateModel(
name='RCAAttachment',
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)),
('file', models.FileField(upload_to='rca/%Y/%m/%d/')),
('filename', models.CharField(max_length=500)),
('file_type', models.CharField(blank=True, max_length=100)),
('file_size', models.IntegerField(help_text='File size in bytes')),
('description', models.TextField(blank=True)),
('uploaded_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='rca_attachments', to=settings.AUTH_USER_MODEL)),
('rca', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='attachments', to='rca.rootcauseanalysis')),
],
options={
'verbose_name': 'RCA Attachment',
'verbose_name_plural': 'RCA Attachments',
'ordering': ['-created_at'],
},
),
migrations.AddIndex(
model_name='rootcauseanalysis',
index=models.Index(fields=['status', '-created_at'], name='rca_rootcau_status_de172e_idx'),
),
migrations.AddIndex(
model_name='rootcauseanalysis',
index=models.Index(fields=['hospital', 'status', '-created_at'], name='rca_rootcau_hospita_105ba2_idx'),
),
migrations.AddIndex(
model_name='rootcauseanalysis',
index=models.Index(fields=['department', 'status', '-created_at'], name='rca_rootcau_departm_ca310d_idx'),
),
migrations.AddIndex(
model_name='rootcauseanalysis',
index=models.Index(fields=['assigned_to', 'status', '-created_at'], name='rca_rootcau_assigne_71e4cf_idx'),
),
migrations.AddIndex(
model_name='rootcauseanalysis',
index=models.Index(fields=['is_deleted', '-created_at'], name='rca_rootcau_is_dele_1b8ad5_idx'),
),
migrations.AddIndex(
model_name='rootcauseanalysis',
index=models.Index(fields=['content_type', 'object_id'], name='rca_rootcau_content_08b595_idx'),
),
migrations.AddIndex(
model_name='rcastatuslog',
index=models.Index(fields=['rca', '-created_at'], name='rca_rcastat_rca_id_26e67b_idx'),
),
migrations.AddIndex(
model_name='rcastatuslog',
index=models.Index(fields=['new_status', '-created_at'], name='rca_rcastat_new_sta_09a9ea_idx'),
),
migrations.AddIndex(
model_name='rcarootcause',
index=models.Index(fields=['rca', '-created_at'], name='rca_rcaroot_rca_id_4c7113_idx'),
),
migrations.AddIndex(
model_name='rcarootcause',
index=models.Index(fields=['category', '-created_at'], name='rca_rcaroot_categor_9eb3ca_idx'),
),
migrations.AddIndex(
model_name='rcanote',
index=models.Index(fields=['rca', '-created_at'], name='rca_rcanote_rca_id_ade9da_idx'),
),
migrations.AddIndex(
model_name='rcacorrectiveaction',
index=models.Index(fields=['rca', '-created_at'], name='rca_rcacorr_rca_id_49e717_idx'),
),
migrations.AddIndex(
model_name='rcacorrectiveaction',
index=models.Index(fields=['status', 'target_date'], name='rca_rcacorr_status_96ba71_idx'),
),
migrations.AddIndex(
model_name='rcacorrectiveaction',
index=models.Index(fields=['action_type', '-created_at'], name='rca_rcacorr_action__39700e_idx'),
),
]