# 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='DoctorRatingImportJob',
            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)),
                ('status', models.CharField(choices=[('pending', 'Pending'), ('processing', 'Processing'), ('completed', 'Completed'), ('failed', 'Failed'), ('partial', 'Partial Success')], default='pending', max_length=20)),
                ('source', models.CharField(choices=[('his_api', 'HIS API'), ('csv_upload', 'CSV Upload')], max_length=20)),
                ('total_records', models.IntegerField(default=0)),
                ('processed_count', models.IntegerField(default=0)),
                ('success_count', models.IntegerField(default=0)),
                ('failed_count', models.IntegerField(default=0)),
                ('skipped_count', models.IntegerField(default=0)),
                ('started_at', models.DateTimeField(blank=True, null=True)),
                ('completed_at', models.DateTimeField(blank=True, null=True)),
                ('results', models.JSONField(blank=True, default=dict, help_text='Processing results and errors')),
                ('error_message', models.TextField(blank=True)),
                ('raw_data', models.JSONField(blank=True, default=list, help_text='Stored raw data for processing')),
                ('created_by', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='doctor_rating_jobs', to=settings.AUTH_USER_MODEL)),
                ('hospital', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='doctor_rating_jobs', to='organizations.hospital')),
            ],
            options={
                'ordering': ['-created_at'],
            },
        ),
        migrations.CreateModel(
            name='PhysicianIndividualRating',
            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)),
                ('source', models.CharField(choices=[('his_api', 'HIS API'), ('csv_import', 'CSV Import'), ('manual', 'Manual Entry')], default='manual', max_length=20)),
                ('source_reference', models.CharField(blank=True, help_text='Reference ID from source system (e.g., HIS record ID)', max_length=100)),
                ('doctor_name_raw', models.CharField(help_text='Doctor name as received (may include ID prefix)', max_length=300)),
                ('doctor_id', models.CharField(blank=True, db_index=True, help_text="Doctor ID extracted from source (e.g., '10738')", max_length=50)),
                ('doctor_name', models.CharField(blank=True, help_text='Clean doctor name without ID', max_length=200)),
                ('department_name', models.CharField(blank=True, help_text='Department name from source', max_length=200)),
                ('patient_uhid', models.CharField(blank=True, db_index=True, help_text='Patient UHID/MRN (optional for HIS ratings)', max_length=100, null=True)),
                ('patient_name', models.CharField(blank=True, max_length=300, null=True)),
                ('patient_gender', models.CharField(blank=True, default='', max_length=20)),
                ('patient_age', models.CharField(blank=True, default='', max_length=50)),
                ('patient_nationality', models.CharField(blank=True, default='', max_length=100)),
                ('patient_phone', models.CharField(blank=True, default='', max_length=30)),
                ('patient_type', models.CharField(blank=True, choices=[('IP', 'Inpatient'), ('OP', 'Outpatient'), ('ER', 'Emergency'), ('DC', 'Day Case')], max_length=10, null=True)),
                ('admit_date', models.DateTimeField(blank=True, null=True)),
                ('discharge_date', models.DateTimeField(blank=True, null=True)),
                ('rating', models.IntegerField(help_text='Rating from 1-5')),
                ('feedback', models.TextField(blank=True)),
                ('rating_date', models.DateTimeField()),
                ('is_aggregated', models.BooleanField(default=False, help_text='Whether this rating has been included in monthly aggregation')),
                ('aggregated_at', models.DateTimeField(blank=True, null=True)),
                ('metadata', models.JSONField(blank=True, default=dict, help_text='Additional data from source')),
                ('hospital', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='physician_ratings', to='organizations.hospital')),
                ('staff', models.ForeignKey(blank=True, help_text='Linked staff record (if matched)', null=True, on_delete=django.db.models.deletion.CASCADE, related_name='individual_ratings', to='organizations.staff')),
            ],
            options={
                'ordering': ['-rating_date', '-created_at'],
                'indexes': [models.Index(fields=['hospital', '-rating_date'], name='physicians__hospita_aeea63_idx'), models.Index(fields=['staff', '-rating_date'], name='physicians__staff_i_6b8c39_idx'), models.Index(fields=['doctor_id', '-rating_date'], name='physicians__doctor__b60e4e_idx'), models.Index(fields=['is_aggregated', 'rating_date'], name='physicians__is_aggr_01d659_idx'), models.Index(fields=['patient_uhid', '-rating_date'], name='physicians__patient_5e8644_idx')],
            },
        ),
        migrations.CreateModel(
            name='PhysicianMonthlyRating',
            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)),
                ('year', models.IntegerField(db_index=True)),
                ('month', models.IntegerField(db_index=True, help_text='1-12')),
                ('average_rating', models.DecimalField(decimal_places=2, help_text='Average rating (1-5)', max_digits=3)),
                ('total_surveys', models.IntegerField(help_text='Number of surveys included')),
                ('positive_count', models.IntegerField(default=0)),
                ('neutral_count', models.IntegerField(default=0)),
                ('negative_count', models.IntegerField(default=0)),
                ('rating_1_count', models.IntegerField(default=0)),
                ('rating_2_count', models.IntegerField(default=0)),
                ('rating_3_count', models.IntegerField(default=0)),
                ('rating_4_count', models.IntegerField(default=0)),
                ('rating_5_count', models.IntegerField(default=0)),
                ('md_consult_rating', models.DecimalField(blank=True, decimal_places=2, max_digits=3, null=True)),
                ('hospital_rank', models.IntegerField(blank=True, help_text='Rank within hospital', null=True)),
                ('department_rank', models.IntegerField(blank=True, help_text='Rank within department', null=True)),
                ('metadata', models.JSONField(blank=True, default=dict)),
                ('staff', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='monthly_ratings', to='organizations.staff')),
            ],
            options={
                'ordering': ['-year', '-month', '-average_rating'],
                'indexes': [models.Index(fields=['staff', '-year', '-month'], name='physicians__staff_i_f4cc8b_idx'), models.Index(fields=['year', 'month', '-average_rating'], name='physicians__year_e38883_idx')],
                'unique_together': {('staff', 'year', 'month')},
            },
        ),
    ]
