Marwan Alwali 4d06ca4b5e update
2025-09-20 14:26:19 +03:00

864 lines
35 KiB
Python

# Generated by Django 5.2.6 on 2025-09-19 10:58
import django.core.validators
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 = [
("core", "0001_initial"),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]
operations = [
migrations.CreateModel(
name="ExternalSystem",
fields=[
(
"system_id",
models.UUIDField(
default=uuid.uuid4,
editable=False,
primary_key=True,
serialize=False,
),
),
("name", models.CharField(max_length=200)),
("description", models.TextField(blank=True)),
(
"system_type",
models.CharField(
choices=[
("ehr", "Electronic Health Record"),
("his", "Hospital Information System"),
("lis", "Laboratory Information System"),
("ris", "Radiology Information System"),
("pacs", "Picture Archiving System"),
("pharmacy", "Pharmacy Management System"),
("billing", "Billing System"),
("insurance", "Insurance System"),
("government", "Government System"),
("vendor", "Vendor System"),
("api", "API Service"),
("database", "Database System"),
("file", "File System"),
("ftp", "FTP Server"),
("sftp", "SFTP Server"),
("cloud", "Cloud Service"),
("iot", "IoT Device"),
("monitoring", "Monitoring System"),
("analytics", "Analytics Platform"),
("other", "Other System"),
],
max_length=20,
),
),
("vendor", models.CharField(blank=True, max_length=200)),
("version", models.CharField(blank=True, max_length=100)),
("base_url", models.URLField(blank=True)),
("host", models.CharField(blank=True, max_length=255)),
(
"port",
models.PositiveIntegerField(
blank=True,
null=True,
validators=[
django.core.validators.MinValueValidator(1),
django.core.validators.MaxValueValidator(65535),
],
),
),
("database_name", models.CharField(blank=True, max_length=200)),
(
"authentication_type",
models.CharField(
choices=[
("none", "No Authentication"),
("basic", "Basic Authentication"),
("bearer", "Bearer Token"),
("api_key", "API Key"),
("oauth2", "OAuth 2.0"),
("certificate", "Client Certificate"),
("custom", "Custom Authentication"),
],
default="none",
max_length=20,
),
),
("authentication_config", models.JSONField(blank=True, default=dict)),
("configuration", models.JSONField(blank=True, default=dict)),
("timeout_seconds", models.PositiveIntegerField(default=30)),
("retry_attempts", models.PositiveIntegerField(default=3)),
("retry_delay_seconds", models.PositiveIntegerField(default=5)),
("is_active", models.BooleanField(default=True)),
("is_healthy", models.BooleanField(default=False)),
("last_health_check", models.DateTimeField(blank=True, null=True)),
(
"health_check_interval",
models.PositiveIntegerField(
default=300, help_text="Health check interval in seconds"
),
),
("connection_count", models.PositiveIntegerField(default=0)),
("success_count", models.PositiveIntegerField(default=0)),
("failure_count", models.PositiveIntegerField(default=0)),
("last_used_at", models.DateTimeField(blank=True, null=True)),
("created_at", models.DateTimeField(auto_now_add=True)),
("updated_at", models.DateTimeField(auto_now=True)),
(
"created_by",
models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="created_external_systems",
to=settings.AUTH_USER_MODEL,
),
),
(
"tenant",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="external_systems",
to="core.tenant",
),
),
],
options={
"db_table": "integration_external_system",
},
),
migrations.CreateModel(
name="IntegrationEndpoint",
fields=[
(
"endpoint_id",
models.UUIDField(
default=uuid.uuid4,
editable=False,
primary_key=True,
serialize=False,
),
),
("name", models.CharField(max_length=200)),
("description", models.TextField(blank=True)),
(
"endpoint_type",
models.CharField(
choices=[
("rest_api", "REST API"),
("soap", "SOAP Web Service"),
("hl7", "HL7 Interface"),
("dicom", "DICOM Service"),
("ftp", "FTP Transfer"),
("sftp", "SFTP Transfer"),
("database", "Database Query"),
("file", "File Processing"),
("webhook", "Webhook"),
("queue", "Message Queue"),
("email", "Email"),
("custom", "Custom Integration"),
],
max_length=20,
),
),
("path", models.CharField(blank=True, max_length=500)),
(
"method",
models.CharField(
choices=[
("GET", "GET"),
("POST", "POST"),
("PUT", "PUT"),
("PATCH", "PATCH"),
("DELETE", "DELETE"),
("HEAD", "HEAD"),
("OPTIONS", "OPTIONS"),
],
default="GET",
max_length=10,
),
),
(
"direction",
models.CharField(
choices=[
("inbound", "Inbound"),
("outbound", "Outbound"),
("bidirectional", "Bidirectional"),
],
default="outbound",
max_length=20,
),
),
("headers", models.JSONField(blank=True, default=dict)),
("parameters", models.JSONField(blank=True, default=dict)),
("request_format", models.CharField(default="json", max_length=50)),
("response_format", models.CharField(default="json", max_length=50)),
("request_mapping", models.JSONField(blank=True, default=dict)),
("response_mapping", models.JSONField(blank=True, default=dict)),
("request_schema", models.JSONField(blank=True, default=dict)),
("response_schema", models.JSONField(blank=True, default=dict)),
("is_active", models.BooleanField(default=True)),
("execution_count", models.PositiveIntegerField(default=0)),
("success_count", models.PositiveIntegerField(default=0)),
("failure_count", models.PositiveIntegerField(default=0)),
("last_executed_at", models.DateTimeField(blank=True, null=True)),
("created_at", models.DateTimeField(auto_now_add=True)),
("updated_at", models.DateTimeField(auto_now=True)),
(
"created_by",
models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="created_integration_endpoints",
to=settings.AUTH_USER_MODEL,
),
),
(
"external_system",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="endpoints",
to="integration.externalsystem",
),
),
],
options={
"db_table": "integration_endpoint",
},
),
migrations.CreateModel(
name="DataMapping",
fields=[
(
"mapping_id",
models.UUIDField(
default=uuid.uuid4,
editable=False,
primary_key=True,
serialize=False,
),
),
("name", models.CharField(max_length=200)),
("description", models.TextField(blank=True)),
(
"mapping_type",
models.CharField(
choices=[
("field", "Field Mapping"),
("value", "Value Mapping"),
("transformation", "Data Transformation"),
("validation", "Data Validation"),
("enrichment", "Data Enrichment"),
("filtering", "Data Filtering"),
],
max_length=20,
),
),
("source_field", models.CharField(max_length=500)),
("source_format", models.CharField(blank=True, max_length=100)),
("source_validation", models.JSONField(blank=True, default=dict)),
("target_field", models.CharField(max_length=500)),
("target_format", models.CharField(blank=True, max_length=100)),
("target_validation", models.JSONField(blank=True, default=dict)),
(
"transformation_type",
models.CharField(
choices=[
("none", "No Transformation"),
("format", "Format Conversion"),
("calculation", "Calculation"),
("lookup", "Lookup Table"),
("concatenation", "Concatenation"),
("split", "Split Field"),
("default", "Default Value"),
("conditional", "Conditional Logic"),
("custom", "Custom Function"),
],
default="none",
max_length=20,
),
),
("transformation_config", models.JSONField(blank=True, default=dict)),
("is_required", models.BooleanField(default=False)),
("validation_rules", models.JSONField(blank=True, default=dict)),
("default_value", models.TextField(blank=True)),
("is_active", models.BooleanField(default=True)),
("usage_count", models.PositiveIntegerField(default=0)),
("success_count", models.PositiveIntegerField(default=0)),
("failure_count", models.PositiveIntegerField(default=0)),
("last_used_at", models.DateTimeField(blank=True, null=True)),
("created_at", models.DateTimeField(auto_now_add=True)),
("updated_at", models.DateTimeField(auto_now=True)),
(
"created_by",
models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="created_data_mappings",
to=settings.AUTH_USER_MODEL,
),
),
(
"endpoint",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="data_mappings",
to="integration.integrationendpoint",
),
),
],
options={
"db_table": "integration_data_mapping",
},
),
migrations.CreateModel(
name="IntegrationExecution",
fields=[
(
"execution_id",
models.UUIDField(
default=uuid.uuid4,
editable=False,
primary_key=True,
serialize=False,
),
),
(
"execution_type",
models.CharField(
choices=[
("manual", "Manual Execution"),
("scheduled", "Scheduled Execution"),
("triggered", "Event Triggered"),
("webhook", "Webhook Triggered"),
("api", "API Call"),
("batch", "Batch Processing"),
("real_time", "Real-time Processing"),
],
max_length=20,
),
),
(
"status",
models.CharField(
choices=[
("pending", "Pending"),
("running", "Running"),
("completed", "Completed"),
("failed", "Failed"),
("cancelled", "Cancelled"),
("timeout", "Timeout"),
("retry", "Retrying"),
],
default="pending",
max_length=20,
),
),
("started_at", models.DateTimeField(auto_now_add=True)),
("completed_at", models.DateTimeField(blank=True, null=True)),
("request_data", models.JSONField(blank=True, default=dict)),
("response_data", models.JSONField(blank=True, default=dict)),
("request_size_bytes", models.PositiveIntegerField(default=0)),
("response_size_bytes", models.PositiveIntegerField(default=0)),
(
"processing_time_ms",
models.PositiveIntegerField(blank=True, null=True),
),
("network_time_ms", models.PositiveIntegerField(blank=True, null=True)),
("error_message", models.TextField(blank=True)),
("error_details", models.JSONField(blank=True, default=dict)),
("retry_count", models.PositiveIntegerField(default=0)),
("external_id", models.CharField(blank=True, max_length=200)),
("correlation_id", models.CharField(blank=True, max_length=200)),
("metadata", models.JSONField(blank=True, default=dict)),
(
"endpoint",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="executions",
to="integration.integrationendpoint",
),
),
(
"triggered_by",
models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="triggered_integrations",
to=settings.AUTH_USER_MODEL,
),
),
],
options={
"db_table": "integration_execution",
},
),
migrations.CreateModel(
name="IntegrationLog",
fields=[
(
"log_id",
models.UUIDField(
default=uuid.uuid4,
editable=False,
primary_key=True,
serialize=False,
),
),
(
"level",
models.CharField(
choices=[
("debug", "Debug"),
("info", "Info"),
("warning", "Warning"),
("error", "Error"),
("critical", "Critical"),
],
max_length=20,
),
),
(
"category",
models.CharField(
choices=[
("connection", "Connection"),
("authentication", "Authentication"),
("data_transfer", "Data Transfer"),
("transformation", "Data Transformation"),
("validation", "Data Validation"),
("error", "Error"),
("performance", "Performance"),
("security", "Security"),
("audit", "Audit"),
("system", "System"),
],
max_length=20,
),
),
("message", models.TextField()),
("details", models.JSONField(blank=True, default=dict)),
("correlation_id", models.CharField(blank=True, max_length=200)),
("timestamp", models.DateTimeField(auto_now_add=True)),
("metadata", models.JSONField(blank=True, default=dict)),
(
"endpoint",
models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.CASCADE,
related_name="logs",
to="integration.integrationendpoint",
),
),
(
"execution",
models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.CASCADE,
related_name="logs",
to="integration.integrationexecution",
),
),
(
"external_system",
models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.CASCADE,
related_name="logs",
to="integration.externalsystem",
),
),
(
"user",
models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="integration_logs",
to=settings.AUTH_USER_MODEL,
),
),
],
options={
"db_table": "integration_log",
},
),
migrations.CreateModel(
name="WebhookEndpoint",
fields=[
(
"webhook_id",
models.UUIDField(
default=uuid.uuid4,
editable=False,
primary_key=True,
serialize=False,
),
),
("name", models.CharField(max_length=200)),
("description", models.TextField(blank=True)),
(
"url_path",
models.CharField(
help_text="URL path for webhook endpoint",
max_length=500,
unique=True,
),
),
(
"allowed_methods",
models.JSONField(default=list, help_text="Allowed HTTP methods"),
),
(
"authentication_type",
models.CharField(
choices=[
("none", "No Authentication"),
("basic", "Basic Authentication"),
("bearer", "Bearer Token"),
("api_key", "API Key"),
("signature", "Signature Verification"),
("ip_whitelist", "IP Whitelist"),
("custom", "Custom Authentication"),
],
default="none",
max_length=20,
),
),
("authentication_config", models.JSONField(blank=True, default=dict)),
("processing_config", models.JSONField(blank=True, default=dict)),
(
"rate_limit_per_minute",
models.PositiveIntegerField(
blank=True, help_text="Maximum requests per minute", null=True
),
),
(
"rate_limit_per_hour",
models.PositiveIntegerField(
blank=True, help_text="Maximum requests per hour", null=True
),
),
("is_active", models.BooleanField(default=True)),
("request_count", models.PositiveIntegerField(default=0)),
("success_count", models.PositiveIntegerField(default=0)),
("failure_count", models.PositiveIntegerField(default=0)),
("last_request_at", models.DateTimeField(blank=True, null=True)),
("created_at", models.DateTimeField(auto_now_add=True)),
("updated_at", models.DateTimeField(auto_now=True)),
(
"created_by",
models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="created_webhooks",
to=settings.AUTH_USER_MODEL,
),
),
(
"data_mapping",
models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="webhooks",
to="integration.datamapping",
),
),
(
"external_system",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="webhooks",
to="integration.externalsystem",
),
),
],
options={
"db_table": "integration_webhook_endpoint",
},
),
migrations.CreateModel(
name="WebhookExecution",
fields=[
(
"execution_id",
models.UUIDField(
default=uuid.uuid4,
editable=False,
primary_key=True,
serialize=False,
),
),
("method", models.CharField(max_length=10)),
("headers", models.JSONField(blank=True, default=dict)),
("query_params", models.JSONField(blank=True, default=dict)),
("payload", models.JSONField(blank=True, default=dict)),
("payload_size_bytes", models.PositiveIntegerField(default=0)),
("client_ip", models.GenericIPAddressField(blank=True, null=True)),
("user_agent", models.TextField(blank=True)),
(
"status",
models.CharField(
choices=[
("received", "Received"),
("processing", "Processing"),
("completed", "Completed"),
("failed", "Failed"),
("rejected", "Rejected"),
("timeout", "Timeout"),
],
default="received",
max_length=20,
),
),
("received_at", models.DateTimeField(auto_now_add=True)),
("processed_at", models.DateTimeField(blank=True, null=True)),
(
"processing_time_ms",
models.PositiveIntegerField(blank=True, null=True),
),
("response_status", models.PositiveIntegerField(default=200)),
("response_data", models.JSONField(blank=True, default=dict)),
("error_message", models.TextField(blank=True)),
("error_details", models.JSONField(blank=True, default=dict)),
("external_id", models.CharField(blank=True, max_length=200)),
("correlation_id", models.CharField(blank=True, max_length=200)),
("metadata", models.JSONField(blank=True, default=dict)),
(
"webhook",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="executions",
to="integration.webhookendpoint",
),
),
],
options={
"db_table": "integration_webhook_execution",
},
),
migrations.AddIndex(
model_name="externalsystem",
index=models.Index(
fields=["tenant", "system_type"], name="integration_tenant__0b880e_idx"
),
),
migrations.AddIndex(
model_name="externalsystem",
index=models.Index(
fields=["tenant", "is_active"], name="integration_tenant__7cea32_idx"
),
),
migrations.AddIndex(
model_name="externalsystem",
index=models.Index(
fields=["tenant", "is_healthy"], name="integration_tenant__f600ec_idx"
),
),
migrations.AddIndex(
model_name="externalsystem",
index=models.Index(
fields=["last_health_check"], name="integration_last_he_66ff14_idx"
),
),
migrations.AlterUniqueTogether(
name="externalsystem",
unique_together={("tenant", "name")},
),
migrations.AddIndex(
model_name="integrationendpoint",
index=models.Index(
fields=["external_system", "endpoint_type"],
name="integration_externa_fde0b6_idx",
),
),
migrations.AddIndex(
model_name="integrationendpoint",
index=models.Index(
fields=["external_system", "is_active"],
name="integration_externa_67957b_idx",
),
),
migrations.AddIndex(
model_name="integrationendpoint",
index=models.Index(
fields=["direction"], name="integration_directi_1190f7_idx"
),
),
migrations.AddIndex(
model_name="integrationendpoint",
index=models.Index(
fields=["last_executed_at"], name="integration_last_ex_d374d8_idx"
),
),
migrations.AlterUniqueTogether(
name="integrationendpoint",
unique_together={("external_system", "name")},
),
migrations.AddIndex(
model_name="datamapping",
index=models.Index(
fields=["endpoint", "mapping_type"],
name="integration_endpoin_62e62a_idx",
),
),
migrations.AddIndex(
model_name="datamapping",
index=models.Index(
fields=["endpoint", "is_active"], name="integration_endpoin_44aabe_idx"
),
),
migrations.AddIndex(
model_name="datamapping",
index=models.Index(
fields=["source_field"], name="integration_source__728b0c_idx"
),
),
migrations.AddIndex(
model_name="datamapping",
index=models.Index(
fields=["target_field"], name="integration_target__30c08e_idx"
),
),
migrations.AlterUniqueTogether(
name="datamapping",
unique_together={("endpoint", "name")},
),
migrations.AddIndex(
model_name="integrationexecution",
index=models.Index(
fields=["endpoint", "status"], name="integration_endpoin_a017e3_idx"
),
),
migrations.AddIndex(
model_name="integrationexecution",
index=models.Index(
fields=["endpoint", "started_at"], name="integration_endpoin_551374_idx"
),
),
migrations.AddIndex(
model_name="integrationexecution",
index=models.Index(
fields=["execution_type"], name="integration_executi_0a5ddb_idx"
),
),
migrations.AddIndex(
model_name="integrationexecution",
index=models.Index(
fields=["correlation_id"], name="integration_correla_151a7b_idx"
),
),
migrations.AddIndex(
model_name="integrationexecution",
index=models.Index(
fields=["external_id"], name="integration_externa_2f8fed_idx"
),
),
migrations.AddIndex(
model_name="integrationlog",
index=models.Index(
fields=["external_system", "level"],
name="integration_externa_99fd4b_idx",
),
),
migrations.AddIndex(
model_name="integrationlog",
index=models.Index(
fields=["endpoint", "level"], name="integration_endpoin_25f102_idx"
),
),
migrations.AddIndex(
model_name="integrationlog",
index=models.Index(
fields=["execution"], name="integration_executi_d5e356_idx"
),
),
migrations.AddIndex(
model_name="integrationlog",
index=models.Index(
fields=["level", "timestamp"], name="integration_level_49e86f_idx"
),
),
migrations.AddIndex(
model_name="integrationlog",
index=models.Index(
fields=["category", "timestamp"], name="integration_categor_4f1e9b_idx"
),
),
migrations.AddIndex(
model_name="integrationlog",
index=models.Index(
fields=["correlation_id"], name="integration_correla_b2b006_idx"
),
),
migrations.AddIndex(
model_name="webhookendpoint",
index=models.Index(
fields=["external_system", "is_active"],
name="integration_externa_b28e43_idx",
),
),
migrations.AddIndex(
model_name="webhookendpoint",
index=models.Index(
fields=["url_path"], name="integration_url_pat_dcb242_idx"
),
),
migrations.AddIndex(
model_name="webhookendpoint",
index=models.Index(
fields=["last_request_at"], name="integration_last_re_48c6d8_idx"
),
),
migrations.AlterUniqueTogether(
name="webhookendpoint",
unique_together={("external_system", "name")},
),
migrations.AddIndex(
model_name="webhookexecution",
index=models.Index(
fields=["webhook", "status"], name="integration_webhook_437431_idx"
),
),
migrations.AddIndex(
model_name="webhookexecution",
index=models.Index(
fields=["webhook", "received_at"], name="integration_webhook_87a955_idx"
),
),
migrations.AddIndex(
model_name="webhookexecution",
index=models.Index(
fields=["client_ip"], name="integration_client__708643_idx"
),
),
migrations.AddIndex(
model_name="webhookexecution",
index=models.Index(
fields=["correlation_id"], name="integration_correla_319e41_idx"
),
),
migrations.AddIndex(
model_name="webhookexecution",
index=models.Index(
fields=["external_id"], name="integration_externa_c632ac_idx"
),
),
]