# Generated by Django 6.0.1 on 2026-05-11 20:32

import apps.core.encryption
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 = [
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name='Location',
            fields=[
                ('id', models.IntegerField(primary_key=True, serialize=False)),
                ('name_ar', models.CharField(max_length=100)),
                ('name_en', models.CharField(max_length=100)),
            ],
        ),
        migrations.CreateModel(
            name='MainSection',
            fields=[
                ('id', models.IntegerField(primary_key=True, serialize=False)),
                ('name_ar', models.CharField(max_length=100)),
                ('name_en', models.CharField(max_length=100)),
            ],
        ),
        migrations.CreateModel(
            name='Organization',
            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)')),
                ('code', models.CharField(max_length=50, unique=True)),
                ('phone', models.CharField(blank=True, max_length=20)),
                ('email', models.EmailField(blank=True, max_length=254)),
                ('address', models.TextField(blank=True)),
                ('city', models.CharField(blank=True, max_length=100)),
                ('preferred_language', models.CharField(choices=[('en', 'English'), ('ar', 'Arabic')], default='en', help_text='Preferred language for surveys and notifications', max_length=10)),
                ('status', models.CharField(choices=[('active', 'Active'), ('inactive', 'Inactive'), ('pending', 'Pending'), ('completed', 'Completed'), ('cancelled', 'Cancelled')], db_index=True, default='active', max_length=20)),
            ],
            options={
                'verbose_name': 'Organization',
                'verbose_name_plural': 'Organizations',
                'ordering': ['name'],
            },
        ),
        migrations.CreateModel(
            name='Hospital',
            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)')),
                ('display_name', models.CharField(blank=True, help_text="Display name (English). Falls back to 'name' if empty.", max_length=200)),
                ('display_name_ar', models.CharField(blank=True, help_text="Display name (Arabic). Falls back to 'name_ar' if empty.", max_length=200, verbose_name='Display Name (Arabic)')),
                ('code', models.CharField(max_length=50, unique=True)),
                ('address', models.TextField(blank=True)),
                ('city', models.CharField(blank=True, max_length=100)),
                ('phone', models.CharField(blank=True, max_length=20)),
                ('email', models.EmailField(blank=True, max_length=254)),
                ('status', models.CharField(choices=[('active', 'Active'), ('inactive', 'Inactive'), ('pending', 'Pending'), ('completed', 'Completed'), ('cancelled', 'Cancelled')], db_index=True, default='active', max_length=20)),
                ('license_number', models.CharField(blank=True, max_length=100)),
                ('capacity', models.IntegerField(blank=True, help_text='Bed capacity', null=True)),
                ('metadata', models.JSONField(blank=True, default=dict, help_text='Hospital configuration settings')),
                ('ceo', models.ForeignKey(blank=True, help_text='Chief Executive Officer', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='hospitals_as_ceo', to=settings.AUTH_USER_MODEL, verbose_name='CEO')),
                ('cfo', models.ForeignKey(blank=True, help_text='Chief Financial Officer', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='hospitals_as_cfo', to=settings.AUTH_USER_MODEL, verbose_name='CFO')),
                ('coo', models.ForeignKey(blank=True, help_text='Chief Operating Officer', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='hospitals_as_coo', to=settings.AUTH_USER_MODEL, verbose_name='COO')),
                ('medical_director', models.ForeignKey(blank=True, help_text='Medical Director', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='hospitals_as_medical_director', to=settings.AUTH_USER_MODEL, verbose_name='Medical Director')),
                ('organization', models.ForeignKey(blank=True, help_text='Parent organization (null for backward compatibility)', null=True, on_delete=django.db.models.deletion.CASCADE, related_name='hospitals', to='organizations.organization')),
            ],
            options={
                'verbose_name_plural': 'Hospitals',
                'ordering': ['name'],
            },
        ),
        migrations.CreateModel(
            name='Department',
            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_en', models.CharField(blank=True, max_length=200)),
                ('name_ar', models.CharField(blank=True, max_length=200, verbose_name='Name (Arabic)')),
                ('code', models.CharField(db_index=True, max_length=50)),
                ('category', models.CharField(blank=True, choices=[('nursing', 'Nursing'), ('support_services', 'Support Services'), ('medical', 'Medical'), ('non_medical', 'Non-Medical')], db_index=True, default='', max_length=30)),
                ('phone', models.CharField(blank=True, max_length=20)),
                ('email', models.EmailField(blank=True, max_length=254)),
                ('location', models.CharField(blank=True, help_text='Building/Floor/Room', max_length=200)),
                ('status', models.CharField(choices=[('active', 'Active'), ('inactive', 'Inactive'), ('pending', 'Pending'), ('completed', 'Completed'), ('cancelled', 'Cancelled')], db_index=True, default='active', max_length=20)),
                ('manager', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='managed_departments', to=settings.AUTH_USER_MODEL)),
                ('parent', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='sub_departments', to='organizations.department')),
                ('hospital', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='departments', to='organizations.hospital')),
            ],
            options={
                'ordering': ['hospital', 'name'],
            },
        ),
        migrations.CreateModel(
            name='Patient',
            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)),
                ('mrn', models.CharField(max_length=50, unique=True, verbose_name='Medical Record Number')),
                ('national_id', apps.core.encryption.EncryptedCharField(blank=True, default='', max_length=256)),
                ('national_id_hash', models.CharField(blank=True, db_index=True, default='', max_length=64)),
                ('first_name', models.CharField(max_length=100)),
                ('last_name', models.CharField(max_length=100)),
                ('first_name_ar', models.CharField(blank=True, max_length=100)),
                ('last_name_ar', models.CharField(blank=True, max_length=100)),
                ('date_of_birth', models.DateField(blank=True, null=True)),
                ('gender', models.CharField(blank=True, choices=[('male', 'Male'), ('female', 'Female'), ('other', 'Other')], max_length=10)),
                ('nationality', models.CharField(blank=True, db_index=True, max_length=100)),
                ('phone', models.CharField(blank=True, max_length=20)),
                ('email', models.EmailField(blank=True, max_length=254)),
                ('address', models.TextField(blank=True)),
                ('city', models.CharField(blank=True, max_length=100)),
                ('status', models.CharField(choices=[('active', 'Active'), ('inactive', 'Inactive'), ('pending', 'Pending'), ('completed', 'Completed'), ('cancelled', 'Cancelled')], db_index=True, default='active', max_length=20)),
                ('primary_hospital', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='patients', to='organizations.hospital')),
            ],
            options={
                'ordering': ['last_name', 'first_name'],
            },
        ),
        migrations.CreateModel(
            name='Staff',
            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)),
                ('first_name', models.CharField(max_length=100)),
                ('last_name', models.CharField(max_length=100)),
                ('first_name_ar', models.CharField(blank=True, max_length=100)),
                ('last_name_ar', models.CharField(blank=True, max_length=100)),
                ('staff_type', models.CharField(choices=[('physician', 'Physician'), ('nurse', 'Nurse'), ('admin', 'Administrative'), ('other', 'Other')], max_length=20)),
                ('department_type', models.CharField(blank=True, choices=[('nursing', 'Nursing'), ('support_services', 'Support Services'), ('medical', 'Medical'), ('non_medical', 'Non-Medical')], db_index=True, default='', max_length=30)),
                ('job_title', models.CharField(max_length=200)),
                ('license_number', models.CharField(blank=True, max_length=100, null=True, unique=True)),
                ('specialization', models.CharField(blank=True, max_length=200)),
                ('email', models.EmailField(blank=True, max_length=254)),
                ('phone', models.CharField(blank=True, max_length=20, verbose_name='Phone Number')),
                ('employee_id', models.CharField(max_length=50, unique=True)),
                ('name', models.CharField(blank=True, max_length=300, verbose_name='Full Name (Original)')),
                ('name_ar', models.CharField(blank=True, max_length=300, verbose_name='Full Name (Arabic)')),
                ('civil_id', models.CharField(blank=True, db_index=True, max_length=50, verbose_name='Civil Identity Number')),
                ('country', models.CharField(blank=True, max_length=100, verbose_name='Country')),
                ('country_ar', models.CharField(blank=True, max_length=100, verbose_name='Country (Arabic)')),
                ('location', models.CharField(blank=True, max_length=200, verbose_name='Location')),
                ('location_ar', models.CharField(blank=True, max_length=200, verbose_name='Location (Arabic)')),
                ('gender', models.CharField(blank=True, choices=[('male', 'Male'), ('female', 'Female'), ('other', 'Other')], max_length=10)),
                ('department_name', models.CharField(blank=True, max_length=200, verbose_name='Department (Original)')),
                ('department_name_ar', models.CharField(blank=True, max_length=200, verbose_name='Department (Arabic)')),
                ('section', models.CharField(blank=True, max_length=200, verbose_name='Section')),
                ('section_ar', models.CharField(blank=True, max_length=200, verbose_name='Section (Arabic)')),
                ('subsection', models.CharField(blank=True, max_length=200, verbose_name='Subsection')),
                ('subsection_ar', models.CharField(blank=True, max_length=200, verbose_name='Subsection (Arabic)')),
                ('job_title_ar', models.CharField(blank=True, max_length=200, verbose_name='Job Title (Arabic)')),
                ('is_head', models.BooleanField(default=False, verbose_name='Is Head')),
                ('physician', models.BooleanField(default=False, help_text='Set to True when staff record comes from physician rating import', verbose_name='Is Physician')),
                ('status', models.CharField(choices=[('active', 'Active'), ('inactive', 'Inactive'), ('pending', 'Pending'), ('completed', 'Completed'), ('cancelled', 'Cancelled')], default='active', max_length=20)),
                ('department', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='staff', to='organizations.department')),
                ('hospital', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='staff', to='organizations.hospital')),
                ('report_to', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='direct_reports', to='organizations.staff', verbose_name='Reports To')),
                ('user', models.OneToOneField(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='staff_profile', to=settings.AUTH_USER_MODEL)),
            ],
        ),
        migrations.AddField(
            model_name='department',
            name='respondent',
            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='respondent_departments', to='organizations.staff'),
        ),
        migrations.CreateModel(
            name='StaffSection',
            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)')),
                ('code', models.CharField(blank=True, max_length=50)),
                ('status', models.CharField(choices=[('active', 'Active'), ('inactive', 'Inactive'), ('pending', 'Pending'), ('completed', 'Completed'), ('cancelled', 'Cancelled')], db_index=True, default='active', max_length=20)),
                ('department', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='sections', to='organizations.department')),
                ('head', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='headed_sections', to='organizations.staff')),
            ],
            options={
                'ordering': ['department', 'name'],
                'unique_together': {('department', 'name')},
            },
        ),
        migrations.AddField(
            model_name='staff',
            name='section_fk',
            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='staff_members', to='organizations.staffsection', verbose_name='Section (FK)'),
        ),
        migrations.CreateModel(
            name='StaffSubsection',
            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)')),
                ('code', models.CharField(blank=True, max_length=50)),
                ('status', models.CharField(choices=[('active', 'Active'), ('inactive', 'Inactive'), ('pending', 'Pending'), ('completed', 'Completed'), ('cancelled', 'Cancelled')], db_index=True, default='active', max_length=20)),
                ('head', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='headed_subsections', to='organizations.staff')),
                ('section', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='subsections', to='organizations.staffsection')),
            ],
            options={
                'ordering': ['section', 'name'],
                'unique_together': {('section', 'name')},
            },
        ),
        migrations.AddField(
            model_name='staff',
            name='subsection_fk',
            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='staff_members', to='organizations.staffsubsection', verbose_name='Subsection (FK)'),
        ),
        migrations.CreateModel(
            name='SubSection',
            fields=[
                ('internal_id', models.IntegerField(primary_key=True, serialize=False)),
                ('name_ar', models.CharField(max_length=255)),
                ('name_en', models.CharField(max_length=255)),
                ('location', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='subsections', to='organizations.location')),
                ('main_section', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='subsections', to='organizations.mainsection')),
            ],
        ),
        migrations.AlterUniqueTogether(
            name='department',
            unique_together={('hospital', 'code')},
        ),
        migrations.AddIndex(
            model_name='staff',
            index=models.Index(fields=['hospital', 'department', 'status'], name='organizatio_hospita_b3a37a_idx'),
        ),
        migrations.AddIndex(
            model_name='staff',
            index=models.Index(fields=['hospital', 'status'], name='organizatio_hospita_136205_idx'),
        ),
        migrations.AddIndex(
            model_name='staff',
            index=models.Index(fields=['department', 'status'], name='organizatio_departm_7a09d9_idx'),
        ),
        migrations.AddIndex(
            model_name='staff',
            index=models.Index(fields=['status'], name='organizatio_status_2156dc_idx'),
        ),
    ]
