8.7 KiB
InsuranceClaim Model Merge Plan
Overview
Merge patients.InsuranceClaim into billing.InsuranceClaim to eliminate duplication and centralize claim management.
Current State Analysis
billing.InsuranceClaim (Canonical - Keep This)
Location: billing/models.py (line 606+)
Core Fields:
medical_bill(FK to MedicalBill)claim_id,claim_numberinsurance_info(FK to patients.InsuranceInfo)claim_type(PRIMARY, SECONDARY, TERTIARY, etc.)submission_date,service_date_from,service_date_tobilled_amount,allowed_amount,paid_amountpatient_responsibility,deductible_amount,coinsurance_amount,copay_amountstatus(DRAFT, SUBMITTED, PENDING, PROCESSING, PAID, DENIED, etc.)clearinghouse,batch_numberresponse_date,check_number,check_datedenial_reason,denial_codeprior_auth_numbernotesoriginal_claim(FK to self for resubmissions)resubmission_count
Missing Saudi-Specific Fields:
- ❌
saudi_id_number - ❌
insurance_card_number - ❌
service_provider,service_provider_license - ❌
facility_name,facility_license - ❌
primary_diagnosis_code,primary_diagnosis_description - ❌
secondary_diagnosis_codes(JSON) - ❌
procedure_codes(JSON) - ❌
discount_amount - ❌
appeal_date,appeal_reason - ❌
attachments(JSON) - ❌
processed_date,payment_date
patients.InsuranceClaim (Duplicate - Remove This)
Location: patients/models.py (line 784+)
Unique Fields Not in billing:
- ✅
service_provider,service_provider_license- Provider details - ✅
facility_name,facility_license- Facility details - ✅
primary_diagnosis_code,primary_diagnosis_description- Diagnosis info - ✅
secondary_diagnosis_codes(JSON) - Additional diagnoses - ✅
procedure_codes(JSON) - Procedures performed - ✅
discount_amount- Discounts applied - ✅
saudi_id_number- Saudi National ID - ✅
insurance_card_number- Insurance card number - ✅
appeal_date,appeal_reason- Appeal information - ✅
attachments(JSON) - Document attachments - ✅
processed_date,payment_date- Additional date tracking - ✅
priority(LOW, NORMAL, HIGH, URGENT, EMERGENCY) - ✅
claim_typehas more options (MEDICAL, DENTAL, VISION, etc.)
Fields Already in billing:
claim_number,patient,insurance_infostatus,billed_amount,approved_amount,paid_amountpatient_responsibility,denial_reason,denial_codeauthorization_number(same asprior_auth_number)
Merge Strategy
Step 1: Add Missing Fields to billing.InsuranceClaim
Add these fields to billing/models.py InsuranceClaim model:
# Saudi-specific fields
saudi_id_number = models.CharField(
max_length=10,
blank=True,
null=True,
help_text='Saudi National ID or Iqama number'
)
insurance_card_number = models.CharField(
max_length=50,
blank=True,
null=True,
help_text='Insurance card number'
)
# Provider and Facility Information
service_provider = models.CharField(
max_length=200,
blank=True,
null=True,
help_text='Healthcare provider who provided the service'
)
service_provider_license = models.CharField(
max_length=50,
blank=True,
null=True,
help_text='Provider license number (Saudi Medical License)'
)
facility_name = models.CharField(
max_length=200,
blank=True,
null=True,
help_text='Healthcare facility name'
)
facility_license = models.CharField(
max_length=50,
blank=True,
null=True,
help_text='Facility license number (MOH License)'
)
# Medical Codes
primary_diagnosis_code = models.CharField(
max_length=20,
blank=True,
null=True,
help_text='Primary diagnosis code (ICD-10)'
)
primary_diagnosis_description = models.TextField(
blank=True,
null=True,
help_text='Primary diagnosis description'
)
secondary_diagnosis_codes = models.JSONField(
default=list,
blank=True,
help_text='Secondary diagnosis codes and descriptions'
)
procedure_codes = models.JSONField(
default=list,
blank=True,
help_text='Procedure codes (CPT/HCPCS) and descriptions'
)
# Additional Financial
discount_amount = models.DecimalField(
max_digits=12,
decimal_places=2,
default=Decimal('0.00'),
help_text='Discount applied (SAR)'
)
# Additional Dates
processed_date = models.DateTimeField(
blank=True,
null=True,
help_text='Date claim was processed'
)
payment_date = models.DateTimeField(
blank=True,
null=True,
help_text='Date payment was received'
)
# Appeal Information (already has denial_reason, denial_code)
appeal_date = models.DateTimeField(
blank=True,
null=True,
help_text='Date appeal was filed'
)
appeal_reason = models.TextField(
blank=True,
null=True,
help_text='Reason for appeal'
)
# Attachments
attachments = models.JSONField(
default=list,
blank=True,
help_text='List of attached documents'
)
# Priority (add to ClaimProcessingStatus choices)
priority = models.CharField(
max_length=10,
choices=[
('LOW', 'Low'),
('NORMAL', 'Normal'),
('HIGH', 'High'),
('URGENT', 'Urgent'),
('EMERGENCY', 'Emergency'),
],
default='NORMAL',
blank=True,
help_text='Claim priority'
)
Step 2: Move Related Models to billing
ClaimDocument Model
Action: Move from patients/models.py to billing/models.py
Changes Needed:
- Update FK:
claim = models.ForeignKey(InsuranceClaim, ...)(already correct) - Update
db_tablefrompatients_claim_documenttobilling_claim_document - Update Meta class
ClaimStatusHistory Model
Action: Already exists in billing as ClaimStatusUpdate
Decision: Keep billing.ClaimStatusUpdate, remove patients.ClaimStatusHistory
Comparison:
patients.ClaimStatusHistory- simpler, just tracks status changesbilling.ClaimStatusUpdate- more comprehensive with financial updates
Action: Enhance ClaimStatusUpdate if needed, but it's already more complete
Step 3: Remove from patients app
Remove these models from patients/models.py:
InsuranceClaim(line 784+)ClaimDocument(line 1121+)ClaimStatusHistory(line 1197+)
Add import at top of file:
from billing.models import InsuranceClaim, ClaimDocument
Step 4: Update All References
Files to Update:
- patients/admin.py - Update imports
- patients/views.py - Update imports
- patients/forms.py - Update imports
- patients/api/ - Update imports and serializers
- billing/admin.py - Add ClaimDocument admin
- Any other files importing from patients.models
Search Pattern:
grep -r "from patients.models import.*InsuranceClaim" .
grep -r "patients.InsuranceClaim" .
Migration Strategy
Option A: Data Migration (Recommended for Production)
- Add new fields to billing.InsuranceClaim
- Create data migration to copy data from patients to billing
- Update all FK references
- Remove old models from patients
- Run migrations
Option B: Drop and Reseed (Recommended for Development)
- Backup any important data
- Drop database
- Make all model changes
- Run fresh migrations
- Reseed data
Implementation Checklist
- Add missing fields to billing.InsuranceClaim
- Move ClaimDocument model to billing app
- Update ClaimDocument db_table and Meta
- Remove InsuranceClaim from patients/models.py
- Remove ClaimDocument from patients/models.py
- Remove ClaimStatusHistory from patients/models.py
- Add imports in patients/models.py
- Update patients/admin.py imports
- Update patients/views.py imports
- Update patients/forms.py imports
- Update patients/api/ imports
- Update billing/admin.py to include ClaimDocument
- Search and update all other references
- Create/run migrations
- Test thoroughly
- Update REFACTORING_PROGRESS.md
Risk Assessment
High Risk:
- Data loss if migration not done correctly
- Broken FK references if not all updated
- Admin interface breakage
Mitigation:
- Comprehensive testing before deployment
- Database backup before changes
- Incremental implementation with testing at each step
- Consider drop-and-reseed for cleanest implementation
Benefits After Merge
- Single Source of Truth: All insurance claims in one place
- Consistent API: Unified claim management interface
- Better Reporting: Centralized claim analytics
- Reduced Confusion: No duplicate models
- Easier Maintenance: Changes in one place only
- Saudi Compliance: All Saudi-specific fields included
Status: Ready for Implementation
Next Step: Add missing fields to billing.InsuranceClaim