HH/apps/surveys/migrations/0001_initial.py

142 lines
10 KiB
Python

<<<<<<< HEAD
# Generated by Django 6.0 on 2026-01-12 09:50
=======
# Generated by Django 6.0.1 on 2026-01-12 09:50
>>>>>>> 1f9d8a7 (update on the complaint sla and staff hierarchy)
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 = [
('journeys', '0001_initial'),
('organizations', '0001_initial'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]
operations = [
migrations.CreateModel(
name='SurveyTemplate',
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)),
('name', models.CharField(max_length=200)),
('name_ar', models.CharField(blank=True, max_length=200, verbose_name='Name (Arabic)')),
('description', models.TextField(blank=True)),
('description_ar', models.TextField(blank=True, verbose_name='Description (Arabic)')),
('survey_type', models.CharField(choices=[('stage', 'Journey Stage Survey'), ('complaint_resolution', 'Complaint Resolution Satisfaction'), ('general', 'General Feedback'), ('nps', 'Net Promoter Score')], db_index=True, default='stage', max_length=50)),
('scoring_method', models.CharField(choices=[('average', 'Average Score'), ('weighted', 'Weighted Average'), ('nps', 'NPS Calculation')], default='average', max_length=20)),
('negative_threshold', models.DecimalField(decimal_places=1, default=3.0, help_text='Scores below this trigger PX actions (out of 5)', max_digits=3)),
('is_active', models.BooleanField(db_index=True, default=True)),
('version', models.IntegerField(default=1)),
('hospital', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='survey_templates', to='organizations.hospital')),
],
options={
'ordering': ['hospital', 'name'],
},
),
migrations.CreateModel(
name='SurveyQuestion',
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)),
('text', models.TextField(verbose_name='Question Text (English)')),
('text_ar', models.TextField(blank=True, verbose_name='Question Text (Arabic)')),
('question_type', models.CharField(choices=[('rating', 'Rating (1-5 stars)'), ('nps', 'NPS (0-10)'), ('yes_no', 'Yes/No'), ('multiple_choice', 'Multiple Choice'), ('text', 'Text (Short Answer)'), ('textarea', 'Text Area (Long Answer)'), ('likert', 'Likert Scale (1-5)')], default='rating', max_length=20)),
('order', models.IntegerField(default=0, help_text='Display order')),
('is_required', models.BooleanField(default=True)),
('choices_json', models.JSONField(blank=True, default=list, help_text="Array of choice objects: [{'value': '1', 'label': 'Option 1', 'label_ar': 'خيار 1'}]")),
('weight', models.DecimalField(decimal_places=2, default=1.0, help_text='Weight for weighted average scoring', max_digits=3)),
('branch_logic', models.JSONField(blank=True, default=dict, help_text="Conditional display logic: {'show_if': {'question_id': 'value'}}")),
('help_text', models.TextField(blank=True)),
('help_text_ar', models.TextField(blank=True)),
('survey_template', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='questions', to='surveys.surveytemplate')),
],
options={
'ordering': ['survey_template', 'order'],
},
),
migrations.CreateModel(
name='SurveyInstance',
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)),
('encounter_id', models.CharField(blank=True, db_index=True, max_length=100)),
('delivery_channel', models.CharField(choices=[('sms', 'SMS'), ('whatsapp', 'WhatsApp'), ('email', 'Email')], default='sms', max_length=20)),
('recipient_phone', models.CharField(blank=True, max_length=20)),
('recipient_email', models.EmailField(blank=True, max_length=254)),
('access_token', models.CharField(blank=True, db_index=True, help_text='Secure token for survey access', max_length=100, unique=True)),
('token_expires_at', models.DateTimeField(blank=True, help_text='Token expiration date', null=True)),
('status', models.CharField(choices=[('active', 'Active'), ('inactive', 'Inactive'), ('pending', 'Pending'), ('completed', 'Completed'), ('cancelled', 'Cancelled')], db_index=True, default='pending', max_length=20)),
('sent_at', models.DateTimeField(blank=True, db_index=True, null=True)),
('opened_at', models.DateTimeField(blank=True, null=True)),
('completed_at', models.DateTimeField(blank=True, null=True)),
('total_score', models.DecimalField(blank=True, decimal_places=2, help_text='Calculated total score', max_digits=5, null=True)),
('is_negative', models.BooleanField(db_index=True, default=False, help_text='True if score below threshold')),
('metadata', models.JSONField(blank=True, default=dict)),
('patient_contacted', models.BooleanField(default=False, help_text='Whether patient was contacted about negative survey')),
('patient_contacted_at', models.DateTimeField(blank=True, null=True)),
('contact_notes', models.TextField(blank=True, help_text='Notes from patient contact')),
('issue_resolved', models.BooleanField(default=False, help_text='Whether the issue was resolved/explained')),
('satisfaction_feedback_sent', models.BooleanField(default=False, help_text='Whether satisfaction feedback form was sent')),
('satisfaction_feedback_sent_at', models.DateTimeField(blank=True, null=True)),
('hospital', models.ForeignKey(help_text='Tenant hospital for this record', on_delete=django.db.models.deletion.CASCADE, related_name='%(app_label)s_%(class)s_related', to='organizations.hospital')),
('journey_instance', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='surveys', to='journeys.patientjourneyinstance')),
('journey_stage_instance', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='surveys', to='journeys.patientjourneystageinstance')),
('patient', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='surveys', to='organizations.patient')),
('patient_contacted_by', models.ForeignKey(blank=True, help_text='User who contacted the patient', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='contacted_surveys', to=settings.AUTH_USER_MODEL)),
('survey_template', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='instances', to='surveys.surveytemplate')),
],
options={
'ordering': ['-created_at'],
},
),
migrations.CreateModel(
name='SurveyResponse',
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)),
('numeric_value', models.DecimalField(blank=True, decimal_places=2, help_text='For rating, NPS, Likert questions', max_digits=10, null=True)),
('text_value', models.TextField(blank=True, help_text='For text, textarea questions')),
('choice_value', models.CharField(blank=True, help_text='For multiple choice questions', max_length=200)),
('response_time_seconds', models.IntegerField(blank=True, help_text='Time taken to answer this question', null=True)),
('question', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='responses', to='surveys.surveyquestion')),
('survey_instance', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='responses', to='surveys.surveyinstance')),
],
options={
'ordering': ['survey_instance', 'question__order'],
'unique_together': {('survey_instance', 'question')},
},
),
migrations.AddIndex(
model_name='surveytemplate',
index=models.Index(fields=['hospital', 'survey_type', 'is_active'], name='surveys_sur_hospita_0c8e30_idx'),
),
migrations.AddIndex(
model_name='surveyquestion',
index=models.Index(fields=['survey_template', 'order'], name='surveys_sur_survey__d8acd5_idx'),
),
migrations.AddIndex(
model_name='surveyinstance',
index=models.Index(fields=['patient', '-created_at'], name='surveys_sur_patient_7e68b1_idx'),
),
migrations.AddIndex(
model_name='surveyinstance',
index=models.Index(fields=['status', '-sent_at'], name='surveys_sur_status_ce377b_idx'),
),
migrations.AddIndex(
model_name='surveyinstance',
index=models.Index(fields=['is_negative', '-completed_at'], name='surveys_sur_is_nega_46c933_idx'),
),
]