HH/apps/integrations/migrations/0001_initial.py
2026-01-24 15:07:27 +03:00

78 lines
5.5 KiB
Python

# Generated by Django 6.0 on 2026-01-12 09:50
import django.db.models.deletion
import uuid
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
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='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'],
'indexes': [models.Index(fields=['status', '-received_at'], name='integration_status_f5244c_idx'), models.Index(fields=['encounter_id', 'event_code'], name='integration_encount_e7d795_idx'), models.Index(fields=['source_system', '-received_at'], name='integration_source__bacde5_idx')],
},
),
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)),
('integration_config', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='event_mappings', to='integrations.integrationconfig')),
],
options={
'ordering': ['integration_config', 'external_event_code'],
'unique_together': {('integration_config', 'external_event_code')},
},
),
]