# Generated by Django 5.2.7 on 2025-10-06 21:15 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 = [ ("contenttypes", "0002_remove_content_type_name"), ("core", "0001_initial"), ("patients", "0001_initial"), migrations.swappable_dependency(settings.AUTH_USER_MODEL), ] operations = [ migrations.CreateModel( name="InsuranceApprovalRequest", fields=[ ( "id", models.BigAutoField( auto_created=True, primary_key=True, serialize=False, verbose_name="ID", ), ), ( "approval_id", models.UUIDField( default=uuid.uuid4, editable=False, help_text="Unique approval identifier", unique=True, ), ), ( "approval_number", models.CharField( help_text="Approval request number", max_length=30, unique=True ), ), ( "object_id", models.PositiveIntegerField( blank=True, help_text="ID of the related order", null=True ), ), ( "request_type", models.CharField( choices=[ ("LABORATORY", "Laboratory Test"), ("RADIOLOGY", "Radiology/Imaging"), ("PHARMACY", "Medication/Prescription"), ("PROCEDURE", "Medical Procedure"), ("SURGERY", "Surgical Procedure"), ("THERAPY", "Therapy Services"), ("DME", "Durable Medical Equipment"), ("HOME_HEALTH", "Home Health Services"), ("OTHER", "Other Services"), ], help_text="Type of approval request", max_length=20, ), ), ( "service_description", models.CharField( help_text="Description of service/procedure", max_length=500 ), ), ( "procedure_codes", models.JSONField( default=list, help_text="CPT/HCPCS procedure codes" ), ), ( "diagnosis_codes", models.JSONField(default=list, help_text="ICD-10 diagnosis codes"), ), ( "clinical_justification", models.TextField(help_text="Clinical justification for service"), ), ( "medical_necessity", models.TextField( blank=True, help_text="Medical necessity statement", null=True ), ), ( "alternative_treatments_tried", models.TextField( blank=True, help_text="Alternative treatments attempted", null=True, ), ), ( "requested_quantity", models.PositiveIntegerField( default=1, help_text="Quantity requested" ), ), ( "requested_visits", models.PositiveIntegerField( blank=True, help_text="Number of visits requested", null=True ), ), ( "requested_units", models.PositiveIntegerField( blank=True, help_text="Number of units requested", null=True ), ), ( "service_start_date", models.DateField(help_text="Requested service start date"), ), ( "service_end_date", models.DateField( blank=True, help_text="Requested service end date", null=True ), ), ( "status", models.CharField( choices=[ ("DRAFT", "Draft"), ("PENDING_SUBMISSION", "Pending Submission"), ("SUBMITTED", "Submitted to Insurance"), ("UNDER_REVIEW", "Under Review"), ("ADDITIONAL_INFO_REQUESTED", "Additional Info Requested"), ("APPROVED", "Approved"), ("PARTIALLY_APPROVED", "Partially Approved"), ("DENIED", "Denied"), ("APPEALED", "Appealed"), ("APPEAL_APPROVED", "Appeal Approved"), ("APPEAL_DENIED", "Appeal Denied"), ("EXPIRED", "Expired"), ("CANCELLED", "Cancelled"), ], default="DRAFT", help_text="Current approval status", max_length=30, ), ), ( "priority", models.CharField( choices=[ ("ROUTINE", "Routine"), ("URGENT", "Urgent"), ("STAT", "STAT"), ("EMERGENCY", "Emergency"), ], default="ROUTINE", help_text="Request priority", max_length=20, ), ), ( "submission_method", models.CharField( blank=True, choices=[ ("FAX", "Fax"), ("PHONE", "Phone"), ("PORTAL", "Insurance Portal"), ("EMAIL", "Email"), ("MAIL", "Mail"), ("EDI", "Electronic Data Interchange"), ], help_text="Method used to submit request", max_length=20, null=True, ), ), ( "submitted_date", models.DateTimeField( blank=True, help_text="Date and time submitted to insurance", null=True, ), ), ( "decision_date", models.DateTimeField( blank=True, help_text="Date insurance made decision", null=True ), ), ( "authorization_number", models.CharField( blank=True, help_text="Insurance authorization number", max_length=100, null=True, ), ), ( "reference_number", models.CharField( blank=True, help_text="Insurance reference number", max_length=100, null=True, ), ), ( "approved_quantity", models.PositiveIntegerField( blank=True, help_text="Approved quantity", null=True ), ), ( "approved_visits", models.PositiveIntegerField( blank=True, help_text="Approved number of visits", null=True ), ), ( "approved_units", models.PositiveIntegerField( blank=True, help_text="Approved number of units", null=True ), ), ( "approved_amount", models.DecimalField( blank=True, decimal_places=2, help_text="Approved dollar amount", max_digits=12, null=True, ), ), ( "effective_date", models.DateField( blank=True, help_text="Authorization effective date", null=True ), ), ( "expiration_date", models.DateField( blank=True, help_text="Authorization expiration date", null=True ), ), ( "denial_reason", models.TextField( blank=True, help_text="Reason for denial", null=True ), ), ( "denial_code", models.CharField( blank=True, help_text="Insurance denial code", max_length=50, null=True, ), ), ( "appeal_date", models.DateTimeField( blank=True, help_text="Date appeal was filed", null=True ), ), ( "appeal_reason", models.TextField( blank=True, help_text="Reason for appeal", null=True ), ), ( "appeal_deadline", models.DateField( blank=True, help_text="Deadline to file appeal", null=True ), ), ( "last_contact_date", models.DateTimeField( blank=True, help_text="Last contact with insurance", null=True ), ), ( "last_contact_method", models.CharField( blank=True, help_text="Method of last contact", max_length=20, null=True, ), ), ( "last_contact_notes", models.TextField( blank=True, help_text="Notes from last contact", null=True ), ), ( "is_urgent", models.BooleanField(default=False, help_text="Urgent request"), ), ( "is_expedited", models.BooleanField( default=False, help_text="Expedited processing requested" ), ), ( "requires_peer_review", models.BooleanField( default=False, help_text="Requires peer-to-peer review" ), ), ( "internal_notes", models.TextField( blank=True, help_text="Internal staff notes", null=True ), ), ( "insurance_notes", models.TextField( blank=True, help_text="Notes from insurance company", null=True ), ), ("created_at", models.DateTimeField(auto_now_add=True)), ("updated_at", models.DateTimeField(auto_now=True)), ( "assigned_to", models.ForeignKey( blank=True, help_text="Staff member assigned to this request", null=True, on_delete=django.db.models.deletion.SET_NULL, related_name="assigned_approvals", to=settings.AUTH_USER_MODEL, ), ), ( "content_type", models.ForeignKey( blank=True, help_text="Type of order (Lab, Radiology, Pharmacy, etc.)", null=True, on_delete=django.db.models.deletion.CASCADE, to="contenttypes.contenttype", ), ), ( "created_by", models.ForeignKey( blank=True, help_text="User who created the request", null=True, on_delete=django.db.models.deletion.SET_NULL, related_name="created_approvals", to=settings.AUTH_USER_MODEL, ), ), ( "insurance_info", models.ForeignKey( help_text="Insurance information", on_delete=django.db.models.deletion.CASCADE, related_name="approval_requests", to="patients.insuranceinfo", ), ), ( "patient", models.ForeignKey( help_text="Patient", on_delete=django.db.models.deletion.CASCADE, related_name="approval_requests", to="patients.patientprofile", ), ), ( "requesting_provider", models.ForeignKey( help_text="Provider requesting the approval", on_delete=django.db.models.deletion.CASCADE, related_name="requested_approvals", to=settings.AUTH_USER_MODEL, ), ), ( "submitted_by", models.ForeignKey( blank=True, help_text="User who submitted the request", null=True, on_delete=django.db.models.deletion.SET_NULL, related_name="submitted_approvals", to=settings.AUTH_USER_MODEL, ), ), ( "tenant", models.ForeignKey( help_text="Organization tenant", on_delete=django.db.models.deletion.CASCADE, related_name="approval_requests", to="core.tenant", ), ), ], options={ "verbose_name": "Insurance Approval Request", "verbose_name_plural": "Insurance Approval Requests", "db_table": "insurance_approvals_request", "ordering": ["-created_at"], }, ), migrations.CreateModel( name="ApprovalStatusHistory", fields=[ ( "id", models.BigAutoField( auto_created=True, primary_key=True, serialize=False, verbose_name="ID", ), ), ( "from_status", models.CharField( blank=True, help_text="Previous status", max_length=30, null=True, ), ), ("to_status", models.CharField(help_text="New status", max_length=30)), ( "reason", models.TextField( blank=True, help_text="Reason for status change", null=True ), ), ( "notes", models.TextField( blank=True, help_text="Additional notes", null=True ), ), ("changed_at", models.DateTimeField(auto_now_add=True)), ( "changed_by", models.ForeignKey( blank=True, help_text="User who made the change", null=True, on_delete=django.db.models.deletion.SET_NULL, related_name="approval_status_changes", to=settings.AUTH_USER_MODEL, ), ), ( "approval_request", models.ForeignKey( help_text="Related approval request", on_delete=django.db.models.deletion.CASCADE, related_name="status_history", to="insurance_approvals.insuranceapprovalrequest", ), ), ], options={ "verbose_name": "Approval Status History", "verbose_name_plural": "Approval Status Histories", "db_table": "insurance_approvals_status_history", "ordering": ["-changed_at"], }, ), migrations.CreateModel( name="ApprovalDocument", fields=[ ( "id", models.BigAutoField( auto_created=True, primary_key=True, serialize=False, verbose_name="ID", ), ), ( "document_id", models.UUIDField( default=uuid.uuid4, editable=False, help_text="Unique document identifier", unique=True, ), ), ( "document_type", models.CharField( choices=[ ("MEDICAL_RECORDS", "Medical Records"), ("LAB_RESULTS", "Lab Results"), ("IMAGING_REPORTS", "Imaging Reports"), ("CLINICAL_NOTES", "Clinical Notes"), ("PRESCRIPTION", "Prescription"), ( "LETTER_OF_MEDICAL_NECESSITY", "Letter of Medical Necessity", ), ("PRIOR_AUTH_FORM", "Prior Authorization Form"), ("INSURANCE_CARD", "Insurance Card"), ("CONSENT_FORM", "Consent Form"), ("APPEAL_LETTER", "Appeal Letter"), ("PEER_REVIEW", "Peer Review Documentation"), ("OTHER", "Other"), ], help_text="Type of document", max_length=30, ), ), ("title", models.CharField(help_text="Document title", max_length=200)), ( "description", models.TextField( blank=True, help_text="Document description", null=True ), ), ( "file", models.FileField( help_text="Document file", upload_to="approval_documents/%Y/%m/" ), ), ( "file_size", models.PositiveIntegerField(help_text="File size in bytes"), ), ("mime_type", models.CharField(help_text="MIME type", max_length=100)), ("uploaded_at", models.DateTimeField(auto_now_add=True)), ( "uploaded_by", models.ForeignKey( blank=True, help_text="User who uploaded the document", null=True, on_delete=django.db.models.deletion.SET_NULL, related_name="uploaded_approval_documents", to=settings.AUTH_USER_MODEL, ), ), ( "approval_request", models.ForeignKey( help_text="Related approval request", on_delete=django.db.models.deletion.CASCADE, related_name="documents", to="insurance_approvals.insuranceapprovalrequest", ), ), ], options={ "verbose_name": "Approval Document", "verbose_name_plural": "Approval Documents", "db_table": "insurance_approvals_document", "ordering": ["-uploaded_at"], }, ), migrations.CreateModel( name="ApprovalCommunicationLog", fields=[ ( "id", models.BigAutoField( auto_created=True, primary_key=True, serialize=False, verbose_name="ID", ), ), ( "communication_id", models.UUIDField( default=uuid.uuid4, editable=False, help_text="Unique communication identifier", unique=True, ), ), ( "communication_type", models.CharField( choices=[ ("PHONE_CALL", "Phone Call"), ("FAX_SENT", "Fax Sent"), ("FAX_RECEIVED", "Fax Received"), ("EMAIL_SENT", "Email Sent"), ("EMAIL_RECEIVED", "Email Received"), ("PORTAL_MESSAGE", "Portal Message"), ("MAIL_SENT", "Mail Sent"), ("MAIL_RECEIVED", "Mail Received"), ("IN_PERSON", "In Person"), ], help_text="Type of communication", max_length=20, ), ), ( "contact_person", models.CharField( blank=True, help_text="Insurance contact person", max_length=200, null=True, ), ), ( "contact_number", models.CharField( blank=True, help_text="Contact phone/fax number", max_length=50, null=True, ), ), ( "subject", models.CharField(help_text="Communication subject", max_length=200), ), ("message", models.TextField(help_text="Message content")), ( "response", models.TextField( blank=True, help_text="Response received", null=True ), ), ( "outcome", models.CharField( blank=True, help_text="Communication outcome", max_length=200, null=True, ), ), ( "follow_up_required", models.BooleanField(default=False, help_text="Follow-up required"), ), ( "follow_up_date", models.DateField(blank=True, help_text="Follow-up date", null=True), ), ("communicated_at", models.DateTimeField(auto_now_add=True)), ( "communicated_by", models.ForeignKey( blank=True, help_text="User who made the communication", null=True, on_delete=django.db.models.deletion.SET_NULL, related_name="approval_communications", to=settings.AUTH_USER_MODEL, ), ), ( "approval_request", models.ForeignKey( help_text="Related approval request", on_delete=django.db.models.deletion.CASCADE, related_name="communications", to="insurance_approvals.insuranceapprovalrequest", ), ), ], options={ "verbose_name": "Approval Communication Log", "verbose_name_plural": "Approval Communication Logs", "db_table": "insurance_approvals_communication_log", "ordering": ["-communicated_at"], }, ), migrations.CreateModel( name="ApprovalTemplate", fields=[ ( "id", models.BigAutoField( auto_created=True, primary_key=True, serialize=False, verbose_name="ID", ), ), ( "template_id", models.UUIDField( default=uuid.uuid4, editable=False, help_text="Unique template identifier", unique=True, ), ), ("name", models.CharField(help_text="Template name", max_length=200)), ( "description", models.TextField( blank=True, help_text="Template description", null=True ), ), ( "request_type", models.CharField( help_text="Type of request this template is for", max_length=20 ), ), ( "insurance_company", models.CharField( blank=True, help_text="Specific insurance company (optional)", max_length=200, null=True, ), ), ( "clinical_justification_template", models.TextField(help_text="Template for clinical justification"), ), ( "medical_necessity_template", models.TextField( blank=True, help_text="Template for medical necessity statement", null=True, ), ), ( "required_documents", models.JSONField( default=list, help_text="List of required document types" ), ), ( "required_codes", models.JSONField( default=dict, help_text="Required procedure/diagnosis codes" ), ), ( "is_active", models.BooleanField(default=True, help_text="Template is active"), ), ( "usage_count", models.PositiveIntegerField( default=0, help_text="Number of times template has been used" ), ), ("created_at", models.DateTimeField(auto_now_add=True)), ("updated_at", models.DateTimeField(auto_now=True)), ( "created_by", models.ForeignKey( blank=True, help_text="User who created the template", null=True, on_delete=django.db.models.deletion.SET_NULL, related_name="created_approval_templates", to=settings.AUTH_USER_MODEL, ), ), ( "tenant", models.ForeignKey( help_text="Organization tenant", on_delete=django.db.models.deletion.CASCADE, related_name="approval_templates", to="core.tenant", ), ), ], options={ "verbose_name": "Approval Template", "verbose_name_plural": "Approval Templates", "db_table": "insurance_approvals_template", "ordering": ["name"], "indexes": [ models.Index( fields=["tenant", "is_active"], name="insurance_a_tenant__21856c_idx", ), models.Index( fields=["request_type"], name="insurance_a_request_631392_idx" ), ], "unique_together": {("tenant", "name")}, }, ), migrations.AddIndex( model_name="insuranceapprovalrequest", index=models.Index( fields=["tenant", "status"], name="insurance_a_tenant__d6763e_idx" ), ), migrations.AddIndex( model_name="insuranceapprovalrequest", index=models.Index( fields=["patient", "status"], name="insurance_a_patient_00ddbd_idx" ), ), migrations.AddIndex( model_name="insuranceapprovalrequest", index=models.Index( fields=["insurance_info", "status"], name="insurance_a_insuran_438196_idx", ), ), migrations.AddIndex( model_name="insuranceapprovalrequest", index=models.Index( fields=["approval_number"], name="insurance_a_approva_cefd6a_idx" ), ), migrations.AddIndex( model_name="insuranceapprovalrequest", index=models.Index( fields=["authorization_number"], name="insurance_a_authori_f05618_idx" ), ), migrations.AddIndex( model_name="insuranceapprovalrequest", index=models.Index( fields=["expiration_date"], name="insurance_a_expirat_ef068e_idx" ), ), migrations.AddIndex( model_name="insuranceapprovalrequest", index=models.Index( fields=["assigned_to", "status"], name="insurance_a_assigne_19b007_idx" ), ), migrations.AddIndex( model_name="insuranceapprovalrequest", index=models.Index( fields=["content_type", "object_id"], name="insurance_a_content_de7404_idx", ), ), migrations.AddIndex( model_name="insuranceapprovalrequest", index=models.Index( fields=["priority", "status"], name="insurance_a_priorit_0abcbd_idx" ), ), migrations.AddIndex( model_name="approvalstatushistory", index=models.Index( fields=["approval_request", "changed_at"], name="insurance_a_approva_a5298b_idx", ), ), migrations.AddIndex( model_name="approvaldocument", index=models.Index( fields=["approval_request", "document_type"], name="insurance_a_approva_eae9e0_idx", ), ), migrations.AddIndex( model_name="approvalcommunicationlog", index=models.Index( fields=["approval_request", "communicated_at"], name="insurance_a_approva_fa779d_idx", ), ), migrations.AddIndex( model_name="approvalcommunicationlog", index=models.Index( fields=["follow_up_required", "follow_up_date"], name="insurance_a_follow__2a3b0a_idx", ), ), ]