agdar/mdt/migrations/0001_initial_mdt_models.py
Marwan Alwali 2f1681b18c update
2025-11-11 13:44:48 +03:00

226 lines
16 KiB
Python

# Generated by Django 5.2.3 on 2025-11-09 19:18
import django.db.models.deletion
import simple_history.models
import uuid
from django.conf import settings
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
('core', '0009_add_consent_expiry_date'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]
operations = [
migrations.CreateModel(
name='HistoricalMDTNote',
fields=[
('id', models.UUIDField(db_index=True, default=uuid.uuid4, editable=False, verbose_name='ID')),
('created_at', models.DateTimeField(blank=True, editable=False, verbose_name='Created At')),
('updated_at', models.DateTimeField(blank=True, editable=False, verbose_name='Updated At')),
('title', models.CharField(help_text='Brief title for this MDT note', max_length=200, verbose_name='Title')),
('purpose', models.TextField(help_text='Purpose of this MDT discussion', verbose_name='Purpose')),
('status', models.CharField(choices=[('DRAFT', 'Draft'), ('PENDING_APPROVAL', 'Pending Approval'), ('FINALIZED', 'Finalized'), ('ARCHIVED', 'Archived')], default='DRAFT', max_length=20, verbose_name='Status')),
('finalized_at', models.DateTimeField(blank=True, null=True, verbose_name='Finalized At')),
('version', models.PositiveIntegerField(default=1, verbose_name='Version')),
('summary', models.TextField(blank=True, help_text='Final summary of MDT discussion and recommendations', verbose_name='Summary')),
('recommendations', models.TextField(blank=True, help_text='Action items and recommendations from MDT', verbose_name='Recommendations')),
('history_id', models.AutoField(primary_key=True, serialize=False)),
('history_date', models.DateTimeField(db_index=True)),
('history_change_reason', models.CharField(max_length=100, null=True)),
('history_type', models.CharField(choices=[('+', 'Created'), ('~', 'Changed'), ('-', 'Deleted')], max_length=1)),
('history_user', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL)),
('initiated_by', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to=settings.AUTH_USER_MODEL, verbose_name='Initiated By')),
('patient', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='core.patient', verbose_name='Patient')),
('tenant', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='core.tenant', verbose_name='Tenant')),
],
options={
'verbose_name': 'historical MDT Note',
'verbose_name_plural': 'historical MDT Notes',
'ordering': ('-history_date', '-history_id'),
'get_latest_by': ('history_date', 'history_id'),
},
bases=(simple_history.models.HistoricalChanges, models.Model),
),
migrations.CreateModel(
name='MDTApproval',
fields=[
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False, verbose_name='ID')),
('created_at', models.DateTimeField(auto_now_add=True, verbose_name='Created At')),
('updated_at', models.DateTimeField(auto_now=True, verbose_name='Updated At')),
('approved', models.BooleanField(default=False, verbose_name='Approved')),
('approved_at', models.DateTimeField(blank=True, null=True, verbose_name='Approved At')),
('comments', models.TextField(blank=True, help_text='Optional comments from the approver', verbose_name='Comments')),
('approver', models.ForeignKey(help_text='Must be a Senior Therapist', on_delete=django.db.models.deletion.CASCADE, related_name='mdt_approvals', to=settings.AUTH_USER_MODEL, verbose_name='Approver')),
('clinic', models.ForeignKey(help_text='Department the approver represents', on_delete=django.db.models.deletion.CASCADE, related_name='mdt_approvals', to='core.clinic', verbose_name='Clinic')),
],
options={
'verbose_name': 'MDT Approval',
'verbose_name_plural': 'MDT Approvals',
'ordering': ['approved_at'],
},
),
migrations.CreateModel(
name='MDTContribution',
fields=[
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False, verbose_name='ID')),
('created_at', models.DateTimeField(auto_now_add=True, verbose_name='Created At')),
('updated_at', models.DateTimeField(auto_now=True, verbose_name='Updated At')),
('content', models.TextField(help_text='Contribution from this professional', verbose_name='Content')),
('is_final', models.BooleanField(default=False, help_text='Whether this contribution is finalized', verbose_name='Is Final')),
('edited_at', models.DateTimeField(auto_now=True, verbose_name='Last Edited At')),
('clinic', models.ForeignKey(help_text='Department/clinic the contributor represents', on_delete=django.db.models.deletion.CASCADE, related_name='mdt_contributions', to='core.clinic', verbose_name='Clinic')),
('contributor', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='mdt_contributions', to=settings.AUTH_USER_MODEL, verbose_name='Contributor')),
('mentioned_users', models.ManyToManyField(blank=True, help_text='Users tagged in this contribution', related_name='mdt_mentions', to=settings.AUTH_USER_MODEL, verbose_name='Mentioned Users')),
],
options={
'verbose_name': 'MDT Contribution',
'verbose_name_plural': 'MDT Contributions',
'ordering': ['created_at'],
},
),
migrations.CreateModel(
name='MDTNote',
fields=[
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False, verbose_name='ID')),
('created_at', models.DateTimeField(auto_now_add=True, verbose_name='Created At')),
('updated_at', models.DateTimeField(auto_now=True, verbose_name='Updated At')),
('title', models.CharField(help_text='Brief title for this MDT note', max_length=200, verbose_name='Title')),
('purpose', models.TextField(help_text='Purpose of this MDT discussion', verbose_name='Purpose')),
('status', models.CharField(choices=[('DRAFT', 'Draft'), ('PENDING_APPROVAL', 'Pending Approval'), ('FINALIZED', 'Finalized'), ('ARCHIVED', 'Archived')], default='DRAFT', max_length=20, verbose_name='Status')),
('finalized_at', models.DateTimeField(blank=True, null=True, verbose_name='Finalized At')),
('version', models.PositiveIntegerField(default=1, verbose_name='Version')),
('summary', models.TextField(blank=True, help_text='Final summary of MDT discussion and recommendations', verbose_name='Summary')),
('recommendations', models.TextField(blank=True, help_text='Action items and recommendations from MDT', verbose_name='Recommendations')),
('contributors', models.ManyToManyField(related_name='contributed_mdt_notes', through='mdt.MDTContribution', to=settings.AUTH_USER_MODEL, verbose_name='Contributors')),
('finalized_by', models.ManyToManyField(help_text='Requires at least 2 seniors from different departments', related_name='finalized_mdt_notes', through='mdt.MDTApproval', to=settings.AUTH_USER_MODEL, verbose_name='Finalized By')),
('initiated_by', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='initiated_mdt_notes', to=settings.AUTH_USER_MODEL, verbose_name='Initiated By')),
('patient', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='mdt_notes', to='core.patient', verbose_name='Patient')),
('tenant', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='%(app_label)s_%(class)s_related', to='core.tenant', verbose_name='Tenant')),
],
options={
'verbose_name': 'MDT Note',
'verbose_name_plural': 'MDT Notes',
'ordering': ['-created_at'],
},
),
migrations.AddField(
model_name='mdtcontribution',
name='mdt_note',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='contributions', to='mdt.mdtnote', verbose_name='MDT Note'),
),
migrations.CreateModel(
name='MDTAttachment',
fields=[
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False, verbose_name='ID')),
('created_at', models.DateTimeField(auto_now_add=True, verbose_name='Created At')),
('updated_at', models.DateTimeField(auto_now=True, verbose_name='Updated At')),
('file', models.FileField(upload_to='mdt/attachments/%Y/%m/%d/', verbose_name='File')),
('file_type', models.CharField(choices=[('REPORT', 'Report'), ('IMAGE', 'Image'), ('DOCUMENT', 'Document'), ('LAB_RESULT', 'Lab Result'), ('ASSESSMENT', 'Assessment'), ('OTHER', 'Other')], max_length=20, verbose_name='File Type')),
('description', models.TextField(blank=True, verbose_name='Description')),
('uploaded_by', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='uploaded_mdt_attachments', to=settings.AUTH_USER_MODEL, verbose_name='Uploaded By')),
('mdt_note', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='attachments', to='mdt.mdtnote', verbose_name='MDT Note')),
],
options={
'verbose_name': 'MDT Attachment',
'verbose_name_plural': 'MDT Attachments',
'ordering': ['-created_at'],
},
),
migrations.AddField(
model_name='mdtapproval',
name='mdt_note',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='approvals', to='mdt.mdtnote', verbose_name='MDT Note'),
),
migrations.CreateModel(
name='HistoricalMDTContribution',
fields=[
('id', models.UUIDField(db_index=True, default=uuid.uuid4, editable=False, verbose_name='ID')),
('created_at', models.DateTimeField(blank=True, editable=False, verbose_name='Created At')),
('updated_at', models.DateTimeField(blank=True, editable=False, verbose_name='Updated At')),
('content', models.TextField(help_text='Contribution from this professional', verbose_name='Content')),
('is_final', models.BooleanField(default=False, help_text='Whether this contribution is finalized', verbose_name='Is Final')),
('edited_at', models.DateTimeField(blank=True, editable=False, verbose_name='Last Edited At')),
('history_id', models.AutoField(primary_key=True, serialize=False)),
('history_date', models.DateTimeField(db_index=True)),
('history_change_reason', models.CharField(max_length=100, null=True)),
('history_type', models.CharField(choices=[('+', 'Created'), ('~', 'Changed'), ('-', 'Deleted')], max_length=1)),
('clinic', models.ForeignKey(blank=True, db_constraint=False, help_text='Department/clinic the contributor represents', null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='core.clinic', verbose_name='Clinic')),
('contributor', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to=settings.AUTH_USER_MODEL, verbose_name='Contributor')),
('history_user', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL)),
('mdt_note', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='mdt.mdtnote', verbose_name='MDT Note')),
],
options={
'verbose_name': 'historical MDT Contribution',
'verbose_name_plural': 'historical MDT Contributions',
'ordering': ('-history_date', '-history_id'),
'get_latest_by': ('history_date', 'history_id'),
},
bases=(simple_history.models.HistoricalChanges, models.Model),
),
migrations.CreateModel(
name='MDTMention',
fields=[
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False, verbose_name='ID')),
('created_at', models.DateTimeField(auto_now_add=True, verbose_name='Created At')),
('updated_at', models.DateTimeField(auto_now=True, verbose_name='Updated At')),
('notified_at', models.DateTimeField(blank=True, null=True, verbose_name='Notified At')),
('viewed_at', models.DateTimeField(blank=True, null=True, verbose_name='Viewed At')),
('contribution', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='mentions', to='mdt.mdtcontribution', verbose_name='Contribution')),
('mentioned_user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='received_mdt_mentions', to=settings.AUTH_USER_MODEL, verbose_name='Mentioned User')),
],
options={
'verbose_name': 'MDT Mention',
'verbose_name_plural': 'MDT Mentions',
'ordering': ['-created_at'],
'indexes': [models.Index(fields=['mentioned_user', 'viewed_at'], name='mdt_mdtment_mention_081f2a_idx')],
'unique_together': {('contribution', 'mentioned_user')},
},
),
migrations.AddIndex(
model_name='mdtnote',
index=models.Index(fields=['patient', 'status'], name='mdt_mdtnote_patient_a88e08_idx'),
),
migrations.AddIndex(
model_name='mdtnote',
index=models.Index(fields=['status', 'created_at'], name='mdt_mdtnote_status_b168c3_idx'),
),
migrations.AddIndex(
model_name='mdtnote',
index=models.Index(fields=['tenant', 'status'], name='mdt_mdtnote_tenant__a9bd22_idx'),
),
migrations.AddIndex(
model_name='mdtcontribution',
index=models.Index(fields=['mdt_note', 'created_at'], name='mdt_mdtcont_mdt_not_be3b20_idx'),
),
migrations.AddIndex(
model_name='mdtcontribution',
index=models.Index(fields=['contributor', 'created_at'], name='mdt_mdtcont_contrib_445c38_idx'),
),
migrations.AlterUniqueTogether(
name='mdtcontribution',
unique_together={('mdt_note', 'contributor', 'clinic')},
),
migrations.AddIndex(
model_name='mdtattachment',
index=models.Index(fields=['mdt_note', 'created_at'], name='mdt_mdtatta_mdt_not_6050b1_idx'),
),
migrations.AddIndex(
model_name='mdtapproval',
index=models.Index(fields=['mdt_note', 'approved'], name='mdt_mdtappr_mdt_not_3dac21_idx'),
),
migrations.AddIndex(
model_name='mdtapproval',
index=models.Index(fields=['approver', 'approved_at'], name='mdt_mdtappr_approve_d7ca1b_idx'),
),
migrations.AlterUniqueTogether(
name='mdtapproval',
unique_together={('mdt_note', 'approver')},
),
]