medicafe 0.250728.6__py3-none-any.whl → 0.250728.8__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of medicafe might be problematic. Click here for more details.
- MediBot/MediBot.py +2 -22
- MediBot/MediBot_UI.py +12 -71
- MediLink/MediLink.py +48 -6
- MediLink/MediLink_837p_encoder_library.py +15 -1
- MediLink/MediLink_API_v3.py +62 -0
- MediLink/MediLink_Up.py +6 -1
- MediLink/MediLink_api_utils.py +305 -0
- MediLink/MediLink_insurance_utils.py +265 -0
- MediLink/insurance_type_integration_test.py +368 -0
- {medicafe-0.250728.6.dist-info → medicafe-0.250728.8.dist-info}/METADATA +1 -1
- {medicafe-0.250728.6.dist-info → medicafe-0.250728.8.dist-info}/RECORD +14 -11
- {medicafe-0.250728.6.dist-info → medicafe-0.250728.8.dist-info}/LICENSE +0 -0
- {medicafe-0.250728.6.dist-info → medicafe-0.250728.8.dist-info}/WHEEL +0 -0
- {medicafe-0.250728.6.dist-info → medicafe-0.250728.8.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
# MediLink_insurance_utils.py
|
|
2
|
+
# Insurance type enhancement utilities extracted from enhanced implementations
|
|
3
|
+
# Provides safe helper functions for production integration
|
|
4
|
+
# Python 3.4.4 compatible implementation
|
|
5
|
+
|
|
6
|
+
import time
|
|
7
|
+
import json
|
|
8
|
+
|
|
9
|
+
try:
|
|
10
|
+
from MediLink import MediLink_ConfigLoader
|
|
11
|
+
from MediLink import MediLink_UI
|
|
12
|
+
except ImportError:
|
|
13
|
+
import MediLink_ConfigLoader
|
|
14
|
+
import MediLink_UI
|
|
15
|
+
|
|
16
|
+
# Feature flag system
|
|
17
|
+
def get_feature_flag(flag_name, default=False):
|
|
18
|
+
"""Centralized feature flag management"""
|
|
19
|
+
try:
|
|
20
|
+
config, _ = MediLink_ConfigLoader.load_configuration()
|
|
21
|
+
feature_flags = config.get("MediLink_Config", {}).get("feature_flags", {})
|
|
22
|
+
return feature_flags.get(flag_name, default)
|
|
23
|
+
except Exception as e:
|
|
24
|
+
MediLink_ConfigLoader.log("Error reading feature flag {}: {}".format(flag_name, str(e)), level="WARNING")
|
|
25
|
+
return default
|
|
26
|
+
|
|
27
|
+
# Enhanced insurance type validation
|
|
28
|
+
def validate_insurance_type_from_config(insurance_type_code, payer_id=""):
|
|
29
|
+
"""
|
|
30
|
+
Validate insurance type against configuration with proper logging.
|
|
31
|
+
Returns validated type or safe fallback.
|
|
32
|
+
"""
|
|
33
|
+
try:
|
|
34
|
+
config, _ = MediLink_ConfigLoader.load_configuration()
|
|
35
|
+
insurance_options = config['MediLink_Config'].get('insurance_options', {})
|
|
36
|
+
|
|
37
|
+
if not insurance_type_code:
|
|
38
|
+
MediLink_ConfigLoader.log("Empty insurance type code for payer {}, using default PPO".format(payer_id), level="WARNING")
|
|
39
|
+
return '12' # Default to PPO
|
|
40
|
+
|
|
41
|
+
# Direct lookup - insurance type already in config
|
|
42
|
+
if insurance_type_code in insurance_options:
|
|
43
|
+
MediLink_ConfigLoader.log("Validated insurance type '{}' for payer {}".format(
|
|
44
|
+
insurance_type_code, payer_id), level="DEBUG")
|
|
45
|
+
return insurance_type_code
|
|
46
|
+
|
|
47
|
+
# Unknown type - log and fallback
|
|
48
|
+
MediLink_ConfigLoader.log("UNKNOWN insurance type '{}' for payer {} - using PPO fallback".format(
|
|
49
|
+
insurance_type_code, payer_id), level="WARNING")
|
|
50
|
+
|
|
51
|
+
return '12' # Safe fallback to PPO
|
|
52
|
+
|
|
53
|
+
except Exception as e:
|
|
54
|
+
MediLink_ConfigLoader.log("Insurance validation error: {} - using PPO fallback".format(str(e)), level="ERROR")
|
|
55
|
+
return '12'
|
|
56
|
+
|
|
57
|
+
# Enhanced patient data enrichment
|
|
58
|
+
def enrich_patient_data_with_metadata(detailed_patient_data, insurance_source='MANUAL'):
|
|
59
|
+
"""
|
|
60
|
+
Add metadata to patient data for tracking and monitoring.
|
|
61
|
+
Safe enhancement that doesn't break existing functionality.
|
|
62
|
+
"""
|
|
63
|
+
enhanced_data = []
|
|
64
|
+
|
|
65
|
+
for data in detailed_patient_data:
|
|
66
|
+
# Create enhanced copy
|
|
67
|
+
enhanced_record = data.copy()
|
|
68
|
+
|
|
69
|
+
# Add metadata fields
|
|
70
|
+
enhanced_record['insurance_type_source'] = insurance_source
|
|
71
|
+
enhanced_record['insurance_type_validated'] = True
|
|
72
|
+
enhanced_record['insurance_type_timestamp'] = time.time()
|
|
73
|
+
enhanced_record['insurance_type_metadata'] = {}
|
|
74
|
+
|
|
75
|
+
enhanced_data.append(enhanced_record)
|
|
76
|
+
|
|
77
|
+
return enhanced_data
|
|
78
|
+
|
|
79
|
+
# Insurance type assignment logging
|
|
80
|
+
def log_insurance_type_decision(patient_id, insurance_type, source, metadata=None):
|
|
81
|
+
"""Enhanced logging for insurance type assignments"""
|
|
82
|
+
log_data = {
|
|
83
|
+
'patient_id': patient_id,
|
|
84
|
+
'insurance_type': insurance_type,
|
|
85
|
+
'source': source,
|
|
86
|
+
'timestamp': time.time()
|
|
87
|
+
}
|
|
88
|
+
if metadata:
|
|
89
|
+
log_data['metadata'] = metadata
|
|
90
|
+
|
|
91
|
+
MediLink_ConfigLoader.log("Insurance assignment: {}".format(json.dumps(log_data)), level="INFO")
|
|
92
|
+
|
|
93
|
+
# Monitoring and statistics
|
|
94
|
+
def generate_insurance_assignment_summary(detailed_patient_data):
|
|
95
|
+
"""
|
|
96
|
+
Generate summary statistics for insurance type assignments.
|
|
97
|
+
Helps monitor system performance and data quality.
|
|
98
|
+
"""
|
|
99
|
+
if not detailed_patient_data:
|
|
100
|
+
return {}
|
|
101
|
+
|
|
102
|
+
# Collect statistics
|
|
103
|
+
source_counts = {}
|
|
104
|
+
insurance_type_counts = {}
|
|
105
|
+
|
|
106
|
+
for data in detailed_patient_data:
|
|
107
|
+
source = data.get('insurance_type_source', 'UNKNOWN')
|
|
108
|
+
insurance_type = data.get('insurance_type', 'UNKNOWN')
|
|
109
|
+
|
|
110
|
+
source_counts[source] = source_counts.get(source, 0) + 1
|
|
111
|
+
insurance_type_counts[insurance_type] = insurance_type_counts.get(insurance_type, 0) + 1
|
|
112
|
+
|
|
113
|
+
total_patients = len(detailed_patient_data)
|
|
114
|
+
|
|
115
|
+
summary = {
|
|
116
|
+
'total_patients': total_patients,
|
|
117
|
+
'sources': source_counts,
|
|
118
|
+
'insurance_types': insurance_type_counts,
|
|
119
|
+
'timestamp': time.time()
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
# Log summary
|
|
123
|
+
MediLink_ConfigLoader.log("Insurance Assignment Summary: {}".format(json.dumps(summary)), level="INFO")
|
|
124
|
+
|
|
125
|
+
return summary
|
|
126
|
+
|
|
127
|
+
# Safe wrapper for insurance type selection
|
|
128
|
+
def safe_insurance_type_selection(parsed_data, fallback_function):
|
|
129
|
+
"""
|
|
130
|
+
Safe wrapper that attempts enhanced selection with fallback to original function.
|
|
131
|
+
Provides comprehensive error handling and logging.
|
|
132
|
+
"""
|
|
133
|
+
patient_name = parsed_data.get('LAST', 'UNKNOWN')
|
|
134
|
+
|
|
135
|
+
try:
|
|
136
|
+
# Check if enhanced mode is enabled
|
|
137
|
+
enhanced_mode = get_feature_flag('enhanced_insurance_selection', default=False)
|
|
138
|
+
|
|
139
|
+
if enhanced_mode:
|
|
140
|
+
# Try enhanced selection (would be implemented here)
|
|
141
|
+
MediLink_ConfigLoader.log("Attempting enhanced insurance selection for {}".format(patient_name), level="DEBUG")
|
|
142
|
+
# For now, just call fallback - actual enhancement would go here
|
|
143
|
+
result = fallback_function(parsed_data)
|
|
144
|
+
log_insurance_type_decision(patient_name, result, 'ENHANCED')
|
|
145
|
+
return result
|
|
146
|
+
else:
|
|
147
|
+
# Use standard selection
|
|
148
|
+
result = fallback_function(parsed_data)
|
|
149
|
+
log_insurance_type_decision(patient_name, result, 'MANUAL')
|
|
150
|
+
return result
|
|
151
|
+
|
|
152
|
+
except Exception as e:
|
|
153
|
+
# Error handling with safe fallback
|
|
154
|
+
MediLink_ConfigLoader.log("Insurance selection error for {}: {}. Using PPO default.".format(
|
|
155
|
+
patient_name, str(e)), level="ERROR")
|
|
156
|
+
|
|
157
|
+
log_insurance_type_decision(patient_name, '12', 'ERROR_FALLBACK', {'error': str(e)})
|
|
158
|
+
return '12' # Safe fallback
|
|
159
|
+
|
|
160
|
+
# Configuration validation
|
|
161
|
+
def validate_insurance_configuration():
|
|
162
|
+
"""
|
|
163
|
+
Validate insurance configuration for production readiness.
|
|
164
|
+
Returns True if valid, raises exception if invalid.
|
|
165
|
+
"""
|
|
166
|
+
try:
|
|
167
|
+
config, _ = MediLink_ConfigLoader.load_configuration()
|
|
168
|
+
insurance_options = config['MediLink_Config'].get('insurance_options', {})
|
|
169
|
+
|
|
170
|
+
if not insurance_options:
|
|
171
|
+
raise ValueError("Missing insurance_options in MediLink_Config")
|
|
172
|
+
|
|
173
|
+
# Validate insurance options format
|
|
174
|
+
for code, description in insurance_options.items():
|
|
175
|
+
if not isinstance(code, str) or len(code) < 1:
|
|
176
|
+
raise ValueError("Invalid insurance code format: {}".format(code))
|
|
177
|
+
if not isinstance(description, str):
|
|
178
|
+
raise ValueError("Invalid insurance description for code: {}".format(code))
|
|
179
|
+
|
|
180
|
+
MediLink_ConfigLoader.log("Insurance configuration validation passed: {} options loaded".format(
|
|
181
|
+
len(insurance_options)), level="INFO")
|
|
182
|
+
return True
|
|
183
|
+
|
|
184
|
+
except Exception as e:
|
|
185
|
+
MediLink_ConfigLoader.log("Insurance configuration validation failed: {}".format(str(e)), level="ERROR")
|
|
186
|
+
raise e
|
|
187
|
+
|
|
188
|
+
# Production readiness check
|
|
189
|
+
def check_production_readiness():
|
|
190
|
+
"""
|
|
191
|
+
Check if system is ready for production deployment.
|
|
192
|
+
Returns list of warnings/errors that need attention.
|
|
193
|
+
"""
|
|
194
|
+
issues = []
|
|
195
|
+
|
|
196
|
+
try:
|
|
197
|
+
# Check configuration
|
|
198
|
+
validate_insurance_configuration()
|
|
199
|
+
except Exception as e:
|
|
200
|
+
issues.append("Configuration invalid: {}".format(str(e)))
|
|
201
|
+
|
|
202
|
+
# Check for test mode flags
|
|
203
|
+
try:
|
|
204
|
+
config, _ = MediLink_ConfigLoader.load_configuration()
|
|
205
|
+
test_mode = config.get("MediLink_Config", {}).get("TestMode", False)
|
|
206
|
+
if test_mode:
|
|
207
|
+
issues.append("TestMode is enabled - should be disabled for production")
|
|
208
|
+
except Exception as e:
|
|
209
|
+
issues.append("Cannot check test mode: {}".format(str(e)))
|
|
210
|
+
|
|
211
|
+
return issues
|
|
212
|
+
|
|
213
|
+
# Enhanced error handling wrapper
|
|
214
|
+
def with_insurance_error_handling(func):
|
|
215
|
+
"""
|
|
216
|
+
Decorator for insurance-related functions to add consistent error handling.
|
|
217
|
+
Python 3.4.4 compatible implementation.
|
|
218
|
+
"""
|
|
219
|
+
def wrapper(*args, **kwargs):
|
|
220
|
+
try:
|
|
221
|
+
return func(*args, **kwargs)
|
|
222
|
+
except Exception as e:
|
|
223
|
+
MediLink_ConfigLoader.log("Insurance function error in {}: {}".format(func.__name__, str(e)), level="ERROR")
|
|
224
|
+
# Return safe defaults based on function type
|
|
225
|
+
if 'insurance_type' in func.__name__:
|
|
226
|
+
return '12' # Default PPO for insurance type functions
|
|
227
|
+
else:
|
|
228
|
+
raise e # Re-raise for non-insurance type functions
|
|
229
|
+
return wrapper
|
|
230
|
+
|
|
231
|
+
# Utility for batch processing with progress tracking
|
|
232
|
+
def process_patients_with_progress(patients, processing_function, description="Processing patients"):
|
|
233
|
+
"""
|
|
234
|
+
Process patients with progress tracking and error collection.
|
|
235
|
+
Returns processed results and error summary.
|
|
236
|
+
"""
|
|
237
|
+
processed_results = []
|
|
238
|
+
errors = []
|
|
239
|
+
|
|
240
|
+
try:
|
|
241
|
+
from tqdm import tqdm
|
|
242
|
+
iterator = tqdm(patients, desc=description)
|
|
243
|
+
except ImportError:
|
|
244
|
+
iterator = patients
|
|
245
|
+
MediLink_ConfigLoader.log("Processing {} patients (tqdm not available)".format(len(patients)), level="INFO")
|
|
246
|
+
|
|
247
|
+
for i, patient in enumerate(iterator):
|
|
248
|
+
try:
|
|
249
|
+
result = processing_function(patient)
|
|
250
|
+
processed_results.append(result)
|
|
251
|
+
except Exception as e:
|
|
252
|
+
error_info = {
|
|
253
|
+
'patient_index': i,
|
|
254
|
+
'patient_id': patient.get('patient_id', 'UNKNOWN'),
|
|
255
|
+
'error': str(e)
|
|
256
|
+
}
|
|
257
|
+
errors.append(error_info)
|
|
258
|
+
MediLink_ConfigLoader.log("Error processing patient {}: {}".format(
|
|
259
|
+
patient.get('patient_id', i), str(e)), level="ERROR")
|
|
260
|
+
|
|
261
|
+
if errors:
|
|
262
|
+
MediLink_ConfigLoader.log("Batch processing completed with {} errors out of {} patients".format(
|
|
263
|
+
len(errors), len(patients)), level="WARNING")
|
|
264
|
+
|
|
265
|
+
return processed_results, errors
|
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
# insurance_type_integration_test.py
|
|
2
|
+
# Integration testing and validation for insurance type selection enhancement
|
|
3
|
+
# Python 3.4.4 compatible implementation
|
|
4
|
+
|
|
5
|
+
import time
|
|
6
|
+
import json
|
|
7
|
+
|
|
8
|
+
try:
|
|
9
|
+
from MediLink import MediLink_ConfigLoader
|
|
10
|
+
from MediLink_API_v3_enhanced import (
|
|
11
|
+
validate_production_readiness,
|
|
12
|
+
validate_insurance_configuration,
|
|
13
|
+
get_feature_flag,
|
|
14
|
+
EnhancedAPIClient
|
|
15
|
+
)
|
|
16
|
+
from MediLink_enhanced import (
|
|
17
|
+
enrich_with_insurance_type,
|
|
18
|
+
monitor_insurance_type_assignments
|
|
19
|
+
)
|
|
20
|
+
from MediLink_837p_encoder_library_enhanced import (
|
|
21
|
+
insurance_type_selection,
|
|
22
|
+
insurance_type_selection_safe,
|
|
23
|
+
is_api_insurance_selection_available
|
|
24
|
+
)
|
|
25
|
+
except ImportError as e:
|
|
26
|
+
print("Import error: {}".format(str(e)))
|
|
27
|
+
print("This module requires the enhanced insurance type components.")
|
|
28
|
+
|
|
29
|
+
def run_insurance_type_integration_tests():
|
|
30
|
+
"""
|
|
31
|
+
Run comprehensive integration tests for insurance type selection enhancement.
|
|
32
|
+
Python 3.4.4 compatible implementation.
|
|
33
|
+
"""
|
|
34
|
+
print("=" * 60)
|
|
35
|
+
print("INSURANCE TYPE SELECTION ENHANCEMENT - INTEGRATION TESTS")
|
|
36
|
+
print("=" * 60)
|
|
37
|
+
|
|
38
|
+
test_results = {
|
|
39
|
+
'total_tests': 0,
|
|
40
|
+
'passed_tests': 0,
|
|
41
|
+
'failed_tests': 0,
|
|
42
|
+
'test_details': []
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
# Test 1: Production Readiness Validation
|
|
46
|
+
test_results['total_tests'] += 1
|
|
47
|
+
try:
|
|
48
|
+
print("\n1. Testing Production Readiness Validation...")
|
|
49
|
+
validate_production_readiness()
|
|
50
|
+
print(" ✅ Production readiness validation PASSED")
|
|
51
|
+
test_results['passed_tests'] += 1
|
|
52
|
+
test_results['test_details'].append({'test': 'production_readiness', 'status': 'PASSED'})
|
|
53
|
+
except Exception as e:
|
|
54
|
+
print(" ❌ Production readiness validation FAILED: {}".format(str(e)))
|
|
55
|
+
test_results['failed_tests'] += 1
|
|
56
|
+
test_results['test_details'].append({'test': 'production_readiness', 'status': 'FAILED', 'error': str(e)})
|
|
57
|
+
|
|
58
|
+
# Test 2: Insurance Configuration Validation
|
|
59
|
+
test_results['total_tests'] += 1
|
|
60
|
+
try:
|
|
61
|
+
print("\n2. Testing Insurance Configuration Validation...")
|
|
62
|
+
validate_insurance_configuration()
|
|
63
|
+
print(" ✅ Insurance configuration validation PASSED")
|
|
64
|
+
test_results['passed_tests'] += 1
|
|
65
|
+
test_results['test_details'].append({'test': 'insurance_config', 'status': 'PASSED'})
|
|
66
|
+
except Exception as e:
|
|
67
|
+
print(" ❌ Insurance configuration validation FAILED: {}".format(str(e)))
|
|
68
|
+
test_results['failed_tests'] += 1
|
|
69
|
+
test_results['test_details'].append({'test': 'insurance_config', 'status': 'FAILED', 'error': str(e)})
|
|
70
|
+
|
|
71
|
+
# Test 3: Feature Flag System
|
|
72
|
+
test_results['total_tests'] += 1
|
|
73
|
+
try:
|
|
74
|
+
print("\n3. Testing Feature Flag System...")
|
|
75
|
+
api_flag = get_feature_flag('api_insurance_selection', default=False)
|
|
76
|
+
enhanced_flag = get_feature_flag('enhanced_insurance_enrichment', default=False)
|
|
77
|
+
print(" API Insurance Selection Flag: {}".format(api_flag))
|
|
78
|
+
print(" Enhanced Insurance Enrichment Flag: {}".format(enhanced_flag))
|
|
79
|
+
print(" ✅ Feature flag system PASSED")
|
|
80
|
+
test_results['passed_tests'] += 1
|
|
81
|
+
test_results['test_details'].append({'test': 'feature_flags', 'status': 'PASSED'})
|
|
82
|
+
except Exception as e:
|
|
83
|
+
print(" ❌ Feature flag system FAILED: {}".format(str(e)))
|
|
84
|
+
test_results['failed_tests'] += 1
|
|
85
|
+
test_results['test_details'].append({'test': 'feature_flags', 'status': 'FAILED', 'error': str(e)})
|
|
86
|
+
|
|
87
|
+
# Test 4: Enhanced API Client Initialization
|
|
88
|
+
test_results['total_tests'] += 1
|
|
89
|
+
try:
|
|
90
|
+
print("\n4. Testing Enhanced API Client Initialization...")
|
|
91
|
+
api_client = EnhancedAPIClient()
|
|
92
|
+
print(" ✅ Enhanced API client initialization PASSED")
|
|
93
|
+
test_results['passed_tests'] += 1
|
|
94
|
+
test_results['test_details'].append({'test': 'api_client_init', 'status': 'PASSED'})
|
|
95
|
+
except Exception as e:
|
|
96
|
+
print(" ❌ Enhanced API client initialization FAILED: {}".format(str(e)))
|
|
97
|
+
test_results['failed_tests'] += 1
|
|
98
|
+
test_results['test_details'].append({'test': 'api_client_init', 'status': 'FAILED', 'error': str(e)})
|
|
99
|
+
|
|
100
|
+
# Test 5: Insurance Type Selection Backward Compatibility
|
|
101
|
+
test_results['total_tests'] += 1
|
|
102
|
+
try:
|
|
103
|
+
print("\n5. Testing Insurance Type Selection Backward Compatibility...")
|
|
104
|
+
test_parsed_data = {
|
|
105
|
+
'LAST': 'TESTPATIENT',
|
|
106
|
+
'FIRST': 'TEST',
|
|
107
|
+
'BDAY': '1980-01-01',
|
|
108
|
+
'insurance_type': '12' # Pre-assigned
|
|
109
|
+
}
|
|
110
|
+
result = insurance_type_selection(test_parsed_data)
|
|
111
|
+
assert result == '12', "Should return pre-assigned insurance type"
|
|
112
|
+
print(" ✅ Insurance type selection backward compatibility PASSED")
|
|
113
|
+
test_results['passed_tests'] += 1
|
|
114
|
+
test_results['test_details'].append({'test': 'backward_compatibility', 'status': 'PASSED'})
|
|
115
|
+
except Exception as e:
|
|
116
|
+
print(" ❌ Insurance type selection backward compatibility FAILED: {}".format(str(e)))
|
|
117
|
+
test_results['failed_tests'] += 1
|
|
118
|
+
test_results['test_details'].append({'test': 'backward_compatibility', 'status': 'FAILED', 'error': str(e)})
|
|
119
|
+
|
|
120
|
+
# Test 6: Patient Data Enrichment
|
|
121
|
+
test_results['total_tests'] += 1
|
|
122
|
+
try:
|
|
123
|
+
print("\n6. Testing Patient Data Enrichment...")
|
|
124
|
+
test_patient_data = [
|
|
125
|
+
{
|
|
126
|
+
'patient_id': 'TEST001',
|
|
127
|
+
'patient_name': 'Test Patient',
|
|
128
|
+
'primary_insurance_id': '87726'
|
|
129
|
+
}
|
|
130
|
+
]
|
|
131
|
+
enriched_data = enrich_with_insurance_type(test_patient_data)
|
|
132
|
+
assert len(enriched_data) == 1, "Should return same number of patients"
|
|
133
|
+
assert 'insurance_type' in enriched_data[0], "Should add insurance_type field"
|
|
134
|
+
assert 'insurance_type_source' in enriched_data[0], "Should add source tracking"
|
|
135
|
+
print(" ✅ Patient data enrichment PASSED")
|
|
136
|
+
test_results['passed_tests'] += 1
|
|
137
|
+
test_results['test_details'].append({'test': 'patient_enrichment', 'status': 'PASSED'})
|
|
138
|
+
except Exception as e:
|
|
139
|
+
print(" ❌ Patient data enrichment FAILED: {}".format(str(e)))
|
|
140
|
+
test_results['failed_tests'] += 1
|
|
141
|
+
test_results['test_details'].append({'test': 'patient_enrichment', 'status': 'FAILED', 'error': str(e)})
|
|
142
|
+
|
|
143
|
+
# Test 7: API Availability Check
|
|
144
|
+
test_results['total_tests'] += 1
|
|
145
|
+
try:
|
|
146
|
+
print("\n7. Testing API Availability Check...")
|
|
147
|
+
api_available = is_api_insurance_selection_available()
|
|
148
|
+
print(" API Insurance Selection Available: {}".format(api_available))
|
|
149
|
+
print(" ✅ API availability check PASSED")
|
|
150
|
+
test_results['passed_tests'] += 1
|
|
151
|
+
test_results['test_details'].append({'test': 'api_availability', 'status': 'PASSED'})
|
|
152
|
+
except Exception as e:
|
|
153
|
+
print(" ❌ API availability check FAILED: {}".format(str(e)))
|
|
154
|
+
test_results['failed_tests'] += 1
|
|
155
|
+
test_results['test_details'].append({'test': 'api_availability', 'status': 'FAILED', 'error': str(e)})
|
|
156
|
+
|
|
157
|
+
# Test 8: Monitoring System
|
|
158
|
+
test_results['total_tests'] += 1
|
|
159
|
+
try:
|
|
160
|
+
print("\n8. Testing Monitoring System...")
|
|
161
|
+
test_patient_data = [
|
|
162
|
+
{
|
|
163
|
+
'patient_id': 'TEST001',
|
|
164
|
+
'insurance_type': '12',
|
|
165
|
+
'insurance_type_source': 'DEFAULT'
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
'patient_id': 'TEST002',
|
|
169
|
+
'insurance_type': 'HM',
|
|
170
|
+
'insurance_type_source': 'API'
|
|
171
|
+
}
|
|
172
|
+
]
|
|
173
|
+
monitor_insurance_type_assignments(test_patient_data)
|
|
174
|
+
print(" ✅ Monitoring system PASSED")
|
|
175
|
+
test_results['passed_tests'] += 1
|
|
176
|
+
test_results['test_details'].append({'test': 'monitoring', 'status': 'PASSED'})
|
|
177
|
+
except Exception as e:
|
|
178
|
+
print(" ❌ Monitoring system FAILED: {}".format(str(e)))
|
|
179
|
+
test_results['failed_tests'] += 1
|
|
180
|
+
test_results['test_details'].append({'test': 'monitoring', 'status': 'FAILED', 'error': str(e)})
|
|
181
|
+
|
|
182
|
+
# Print Test Summary
|
|
183
|
+
print("\n" + "=" * 60)
|
|
184
|
+
print("TEST SUMMARY")
|
|
185
|
+
print("=" * 60)
|
|
186
|
+
print("Total Tests: {}".format(test_results['total_tests']))
|
|
187
|
+
print("Passed: {} ✅".format(test_results['passed_tests']))
|
|
188
|
+
print("Failed: {} ❌".format(test_results['failed_tests']))
|
|
189
|
+
|
|
190
|
+
if test_results['failed_tests'] == 0:
|
|
191
|
+
print("\n🎉 ALL TESTS PASSED! System ready for deployment.")
|
|
192
|
+
else:
|
|
193
|
+
print("\n⚠️ {} TESTS FAILED. Review before deployment.".format(test_results['failed_tests']))
|
|
194
|
+
for test in test_results['test_details']:
|
|
195
|
+
if test['status'] == 'FAILED':
|
|
196
|
+
print(" - {}: {}".format(test['test'], test.get('error', 'Unknown error')))
|
|
197
|
+
|
|
198
|
+
return test_results
|
|
199
|
+
|
|
200
|
+
def test_insurance_type_validation():
|
|
201
|
+
"""Test insurance type validation with various scenarios"""
|
|
202
|
+
print("\n" + "=" * 50)
|
|
203
|
+
print("INSURANCE TYPE VALIDATION TESTS")
|
|
204
|
+
print("=" * 50)
|
|
205
|
+
|
|
206
|
+
# Import validation function
|
|
207
|
+
from MediLink_API_v3_enhanced import validate_insurance_type_from_super_connector
|
|
208
|
+
|
|
209
|
+
test_cases = [
|
|
210
|
+
{
|
|
211
|
+
'name': 'Valid PPO Type',
|
|
212
|
+
'plan_description': 'Preferred Provider Organization',
|
|
213
|
+
'insurance_type': '12',
|
|
214
|
+
'payer_id': '87726',
|
|
215
|
+
'expected': '12'
|
|
216
|
+
},
|
|
217
|
+
{
|
|
218
|
+
'name': 'Valid HMO Type',
|
|
219
|
+
'plan_description': 'Health Maintenance Organization',
|
|
220
|
+
'insurance_type': 'HM',
|
|
221
|
+
'payer_id': '87726',
|
|
222
|
+
'expected': 'HM'
|
|
223
|
+
},
|
|
224
|
+
{
|
|
225
|
+
'name': 'Novel Valid Type',
|
|
226
|
+
'plan_description': 'Exclusive Provider Organization',
|
|
227
|
+
'insurance_type': 'EP',
|
|
228
|
+
'payer_id': '87726',
|
|
229
|
+
'expected': 'EP' # Should accept if format is valid
|
|
230
|
+
},
|
|
231
|
+
{
|
|
232
|
+
'name': 'Invalid Type Format',
|
|
233
|
+
'plan_description': 'Some Plan',
|
|
234
|
+
'insurance_type': 'INVALID123',
|
|
235
|
+
'payer_id': '87726',
|
|
236
|
+
'expected': '12' # Should fallback to PPO
|
|
237
|
+
},
|
|
238
|
+
{
|
|
239
|
+
'name': 'Empty Type',
|
|
240
|
+
'plan_description': 'Some Plan',
|
|
241
|
+
'insurance_type': '',
|
|
242
|
+
'payer_id': '87726',
|
|
243
|
+
'expected': '12' # Should fallback to PPO
|
|
244
|
+
}
|
|
245
|
+
]
|
|
246
|
+
|
|
247
|
+
passed = 0
|
|
248
|
+
failed = 0
|
|
249
|
+
|
|
250
|
+
for test_case in test_cases:
|
|
251
|
+
try:
|
|
252
|
+
result = validate_insurance_type_from_super_connector(
|
|
253
|
+
test_case['plan_description'],
|
|
254
|
+
test_case['insurance_type'],
|
|
255
|
+
test_case['payer_id']
|
|
256
|
+
)
|
|
257
|
+
|
|
258
|
+
if result == test_case['expected']:
|
|
259
|
+
print("✅ {}: {} -> {}".format(test_case['name'], test_case['insurance_type'], result))
|
|
260
|
+
passed += 1
|
|
261
|
+
else:
|
|
262
|
+
print("❌ {}: Expected {}, got {}".format(test_case['name'], test_case['expected'], result))
|
|
263
|
+
failed += 1
|
|
264
|
+
|
|
265
|
+
except Exception as e:
|
|
266
|
+
print("❌ {}: Exception - {}".format(test_case['name'], str(e)))
|
|
267
|
+
failed += 1
|
|
268
|
+
|
|
269
|
+
print("\nValidation Tests Summary: {} passed, {} failed".format(passed, failed))
|
|
270
|
+
return passed, failed
|
|
271
|
+
|
|
272
|
+
def create_test_configuration():
|
|
273
|
+
"""Create test configuration for development and testing"""
|
|
274
|
+
print("\n" + "=" * 50)
|
|
275
|
+
print("CREATING TEST CONFIGURATION")
|
|
276
|
+
print("=" * 50)
|
|
277
|
+
|
|
278
|
+
test_config = {
|
|
279
|
+
"MediLink_Config": {
|
|
280
|
+
"feature_flags": {
|
|
281
|
+
"api_insurance_selection": False, # Start disabled
|
|
282
|
+
"enhanced_insurance_enrichment": False, # Start disabled
|
|
283
|
+
"enhanced_insurance_selection": False # Start disabled
|
|
284
|
+
},
|
|
285
|
+
"insurance_options": {
|
|
286
|
+
"12": "Preferred Provider Organization (PPO)",
|
|
287
|
+
"13": "Point of Service (POS)",
|
|
288
|
+
"14": "Exclusive Provider Organization (EPO)",
|
|
289
|
+
"16": "Indemnity",
|
|
290
|
+
"HM": "Health Maintenance Organization (HMO)",
|
|
291
|
+
"BL": "Blue Cross/Blue Shield",
|
|
292
|
+
"CI": "Commercial Insurance",
|
|
293
|
+
"MA": "Medicare Advantage",
|
|
294
|
+
"MB": "Medicare Part B",
|
|
295
|
+
"MC": "Medicare Part C"
|
|
296
|
+
},
|
|
297
|
+
"default_insurance_type": "12",
|
|
298
|
+
"TestMode": False # Must be False for production
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
print("Test configuration created:")
|
|
303
|
+
print(json.dumps(test_config, indent=2))
|
|
304
|
+
print("\n📝 Copy this configuration to your config.json file")
|
|
305
|
+
print("🚨 Ensure TestMode is False for production")
|
|
306
|
+
print("🔧 Enable feature flags gradually during rollout")
|
|
307
|
+
|
|
308
|
+
return test_config
|
|
309
|
+
|
|
310
|
+
def deployment_checklist():
|
|
311
|
+
"""Print deployment checklist for insurance type enhancement"""
|
|
312
|
+
print("\n" + "=" * 60)
|
|
313
|
+
print("DEPLOYMENT CHECKLIST")
|
|
314
|
+
print("=" * 60)
|
|
315
|
+
|
|
316
|
+
checklist = [
|
|
317
|
+
"[ ] All integration tests pass",
|
|
318
|
+
"[ ] Production readiness validation passes",
|
|
319
|
+
"[ ] Insurance configuration validation passes",
|
|
320
|
+
"[ ] TestMode is disabled in configuration",
|
|
321
|
+
"[ ] Feature flags are properly configured (default: disabled)",
|
|
322
|
+
"[ ] Enhanced API client initializes successfully",
|
|
323
|
+
"[ ] Backward compatibility verified with existing callers",
|
|
324
|
+
"[ ] Monitoring system is functional",
|
|
325
|
+
"[ ] Circuit breaker, caching, and rate limiting are active",
|
|
326
|
+
"[ ] Fallback mechanisms tested and working",
|
|
327
|
+
"[ ] Log rotation configured for increased logging volume",
|
|
328
|
+
"[ ] Documentation updated with new features",
|
|
329
|
+
"[ ] Team trained on new monitoring and feature flags"
|
|
330
|
+
]
|
|
331
|
+
|
|
332
|
+
for item in checklist:
|
|
333
|
+
print(item)
|
|
334
|
+
|
|
335
|
+
print("\n📋 Complete all checklist items before deployment")
|
|
336
|
+
print("🚀 Follow gradual rollout plan with feature flags")
|
|
337
|
+
print("🔍 Monitor logs and metrics closely during rollout")
|
|
338
|
+
|
|
339
|
+
if __name__ == "__main__":
|
|
340
|
+
print("Insurance Type Selection Enhancement - Integration Test Suite")
|
|
341
|
+
print("Python 3.4.4 Compatible Implementation")
|
|
342
|
+
|
|
343
|
+
# Run all tests
|
|
344
|
+
test_results = run_insurance_type_integration_tests()
|
|
345
|
+
|
|
346
|
+
# Run validation tests
|
|
347
|
+
validation_passed, validation_failed = test_insurance_type_validation()
|
|
348
|
+
|
|
349
|
+
# Create test configuration
|
|
350
|
+
test_config = create_test_configuration()
|
|
351
|
+
|
|
352
|
+
# Display deployment checklist
|
|
353
|
+
deployment_checklist()
|
|
354
|
+
|
|
355
|
+
# Final summary
|
|
356
|
+
print("\n" + "=" * 60)
|
|
357
|
+
print("FINAL SUMMARY")
|
|
358
|
+
print("=" * 60)
|
|
359
|
+
total_passed = test_results['passed_tests'] + validation_passed
|
|
360
|
+
total_failed = test_results['failed_tests'] + validation_failed
|
|
361
|
+
total_tests = test_results['total_tests'] + validation_passed + validation_failed
|
|
362
|
+
|
|
363
|
+
print("Overall Tests: {} passed, {} failed out of {} total".format(total_passed, total_failed, total_tests))
|
|
364
|
+
|
|
365
|
+
if total_failed == 0:
|
|
366
|
+
print("🎉 ALL SYSTEMS GO! Ready for phased deployment.")
|
|
367
|
+
else:
|
|
368
|
+
print("⚠️ Address {} failed tests before deployment.".format(total_failed))
|