# Generated by Django 6.0.1 on 2026-05-11 20:32 import django.db.models.deletion import uuid from django.db import migrations, models class Migration(migrations.Migration): initial = True dependencies = [ ('organizations', '0001_initial'), ] operations = [ migrations.CreateModel( name='EventMapping', 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)), ('external_event_code', models.CharField(help_text='Event code from external system', max_length=100)), ('internal_event_code', models.CharField(help_text='Internal event code used in journey stages', max_length=100)), ('field_mappings', models.JSONField(blank=True, default=dict, help_text='Maps external field names to internal field names')), ('is_active', models.BooleanField(default=True)), ], options={ 'ordering': ['integration_config', 'external_event_code'], }, ), migrations.CreateModel( name='HISEventType', 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)), ('event_type', models.CharField(help_text="HIS event type name (e.g., 'Lab Bill', 'Triage')", max_length=200, unique=True)), ('patient_types', models.JSONField(blank=True, default=list, help_text="Patient types that have this event: ['OP', 'IP', 'ED']")), ('event_count', models.IntegerField(default=0, help_text='Total number of times this event type has been seen')), ('last_seen_at', models.DateTimeField(auto_now=True)), ], options={ 'verbose_name': 'HIS Event Type', 'verbose_name_plural': 'HIS Event Types', 'ordering': ['event_type'], }, ), migrations.CreateModel( name='HISTestPatient', fields=[ ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('created_at', models.DateTimeField(auto_now_add=True, db_index=True)), ('updated_at', models.DateTimeField(auto_now=True)), ('admission_id', models.CharField(db_index=True, max_length=100)), ('patient_id', models.CharField(db_index=True, max_length=100)), ('patient_type', models.CharField(db_index=True, max_length=10)), ('reg_code', models.CharField(blank=True, db_index=True, max_length=100)), ('ssn', models.CharField(blank=True, db_index=True, max_length=50)), ('mobile_no', models.CharField(blank=True, db_index=True, max_length=20)), ('admit_date', models.DateTimeField(db_index=True)), ('discharge_date', models.DateTimeField(blank=True, null=True)), ('patient_data', models.JSONField(default=dict)), ('hospital_id', models.CharField(blank=True, max_length=20)), ('hospital_name', models.CharField(blank=True, max_length=200)), ('patient_name', models.CharField(blank=True, max_length=300)), ], options={ 'ordering': ['admit_date'], }, ), migrations.CreateModel( name='HISTestVisit', fields=[ ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('created_at', models.DateTimeField(auto_now_add=True, db_index=True)), ('updated_at', models.DateTimeField(auto_now=True)), ('admission_id', models.CharField(db_index=True, max_length=100)), ('patient_id', models.CharField(db_index=True, max_length=100)), ('visit_category', models.CharField(db_index=True, max_length=10)), ('event_type', models.CharField(blank=True, max_length=200)), ('bill_date', models.DateTimeField(blank=True, db_index=True, null=True)), ('reg_code', models.CharField(blank=True, max_length=100)), ('ssn', models.CharField(blank=True, db_index=True, max_length=50)), ('mobile_no', models.CharField(blank=True, db_index=True, max_length=20)), ('visit_data', models.JSONField(default=dict)), ], options={ 'ordering': ['bill_date'], }, ), migrations.CreateModel( name='HISVisitEvent', 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)), ('event_type', models.CharField(blank=True, help_text="Type from HIS (e.g., 'Registration')", max_length=200)), ('bill_date', models.CharField(blank=True, help_text='Raw BillDate from HIS (DD-Mon-YYYY HH:MM)', max_length=50)), ('parsed_date', models.DateTimeField(blank=True, db_index=True, help_text='Parsed bill_date', null=True)), ('patient_type', models.CharField(blank=True, help_text='PatientType for this event', max_length=10)), ('visit_category', models.CharField(blank=True, help_text='Visit category: ED, IP, OP', max_length=10)), ('admission_id', models.CharField(blank=True, db_index=True, max_length=100)), ('patient_id', models.CharField(blank=True, db_index=True, help_text='PatientID from HIS', max_length=100)), ('reg_code', models.CharField(blank=True, db_index=True, max_length=100)), ('ssn', models.CharField(blank=True, db_index=True, max_length=50)), ('mobile_no', models.CharField(blank=True, max_length=50)), ], options={ 'ordering': ['parsed_date'], }, ), migrations.CreateModel( name='InboundEvent', 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_system', models.CharField(choices=[('his', 'Hospital Information System'), ('lab', 'Laboratory System'), ('radiology', 'Radiology System'), ('pharmacy', 'Pharmacy System'), ('moh', 'Ministry of Health'), ('chi', 'Council of Health Insurance'), ('pxconnect', 'PX Connect'), ('other', 'Other')], db_index=True, help_text='System that sent this event', max_length=50)), ('event_code', models.CharField(db_index=True, help_text='Event type code (e.g., OPD_VISIT_COMPLETED, LAB_ORDER_COMPLETED)', max_length=100)), ('encounter_id', models.CharField(db_index=True, help_text='Encounter ID from HIS system', max_length=100)), ('patient_identifier', models.CharField(blank=True, db_index=True, help_text='Patient MRN or other identifier', max_length=100)), ('payload_json', models.JSONField(help_text='Full event payload from source system')), ('status', models.CharField(choices=[('pending', 'Pending'), ('processing', 'Processing'), ('processed', 'Processed'), ('failed', 'Failed'), ('ignored', 'Ignored')], db_index=True, default='pending', max_length=20)), ('received_at', models.DateTimeField(auto_now_add=True, db_index=True)), ('processed_at', models.DateTimeField(blank=True, null=True)), ('error', models.TextField(blank=True, help_text='Error message if processing failed')), ('processing_attempts', models.IntegerField(default=0, help_text='Number of processing attempts')), ('physician_license', models.CharField(blank=True, help_text='Physician license number from event', max_length=100)), ('department_code', models.CharField(blank=True, help_text='Department code from event', max_length=50)), ('metadata', models.JSONField(blank=True, default=dict, help_text='Additional processing metadata')), ], options={ 'ordering': ['-received_at'], }, ), migrations.CreateModel( name='IntegrationConfig', 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, unique=True)), ('source_system', models.CharField(choices=[('his', 'Hospital Information System'), ('lab', 'Laboratory System'), ('radiology', 'Radiology System'), ('pharmacy', 'Pharmacy System'), ('moh', 'Ministry of Health'), ('chi', 'Council of Health Insurance'), ('pxconnect', 'PX Connect'), ('other', 'Other')], max_length=50, unique=True)), ('api_url', models.URLField(blank=True, help_text='API endpoint URL')), ('api_key', models.CharField(blank=True, help_text='API key (encrypted)', max_length=500)), ('is_active', models.BooleanField(default=True)), ('config_json', models.JSONField(blank=True, default=dict, help_text='Additional configuration (event mappings, field mappings, etc.)')), ('description', models.TextField(blank=True)), ('last_sync_at', models.DateTimeField(blank=True, null=True)), ], options={ 'ordering': ['name'], }, ), migrations.CreateModel( name='SurveyTemplateMapping', 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)), ('patient_type', models.CharField(choices=[('IP', 'Inpatient'), ('OP', 'Outpatient'), ('ED', 'Emergency'), ('DAYCASE', 'Day Case'), ('APPOINTMENT', 'Appointment')], db_index=True, help_text='Patient type from HIS system', max_length=20)), ('is_active', models.BooleanField(db_index=True, default=True, help_text='Whether this mapping is active')), ('send_delay_hours', models.IntegerField(default=1, help_text='Hours after discharge to send survey')), ], options={ 'ordering': ['hospital', 'patient_type'], }, ), migrations.CreateModel( name='HISPatientVisit', 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)), ('admission_id', models.CharField(db_index=True, max_length=100)), ('reg_code', models.CharField(blank=True, db_index=True, max_length=100)), ('patient_id_his', models.CharField(blank=True, db_index=True, help_text='PatientID from HIS', max_length=100)), ('patient_type', models.CharField(help_text='ED, IP, OP from HIS', max_length=10)), ('admit_date', models.DateTimeField(blank=True, null=True)), ('discharge_date', models.DateTimeField(blank=True, help_text='From HIS DischargeDate (null for OP)', null=True)), ('effective_discharge_date', models.DateTimeField(blank=True, help_text='For OP: last visit timestamp when deemed complete', null=True)), ('visit_data', models.JSONField(blank=True, default=dict, help_text='Full patient demographic dict from HIS')), ('visit_timeline', models.JSONField(blank=True, default=list, help_text='Extracted visit events for this patient')), ('primary_doctor', models.CharField(blank=True, help_text='From HIS PrimaryDoctor (raw text fallback)', max_length=300)), ('consultant_id', models.CharField(blank=True, help_text='From HIS ConsultantID (raw text fallback)', max_length=50)), ('company_name', models.CharField(blank=True, help_text='From HIS CompanyName (insurance sponsor)', max_length=300)), ('grade_name', models.CharField(blank=True, help_text='From HIS GradeName (insurance grade)', max_length=100)), ('insurance_company_name', models.CharField(blank=True, help_text='From HIS InsuranceCompanyName', max_length=300)), ('bill_type', models.CharField(blank=True, help_text='From HIS BillType (CS/CR)', max_length=20)), ('is_vip', models.BooleanField(db_index=True, default=False, help_text='From HIS IsVIP')), ('nationality', models.CharField(blank=True, help_text='From HIS PatientNationality', max_length=100)), ('is_visit_complete', models.BooleanField(db_index=True, default=False)), ('last_his_fetch_at', models.DateTimeField(blank=True, help_text='Last time this visit was seen in a HIS fetch', null=True)), ('consultant_fk', models.ForeignKey(blank=True, help_text='Resolved Staff record from ConsultantID', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='his_visits_as_consultant', to='organizations.staff')), ('hospital', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='his_visits', to='organizations.hospital')), ('patient', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='his_visits', to='organizations.patient')), ('primary_doctor_fk', models.ForeignKey(blank=True, help_text='Resolved Staff record from PrimaryDoctor ID prefix', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='his_visits_as_doctor', to='organizations.staff')), ], options={ 'ordering': ['-created_at'], }, ), ]