medicafe 0.250822.2__py3-none-any.whl → 0.250909.0__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.
@@ -1,361 +0,0 @@
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
- import sys, os
8
- sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
9
-
10
- # Use core utilities for standardized imports
11
- from MediCafe.core_utils import get_shared_config_loader
12
- MediLink_ConfigLoader = get_shared_config_loader()
13
-
14
- try:
15
- from MediCafe.api_core import (
16
- APIClient
17
- )
18
- from MediLink import (
19
- enrich_with_insurance_type
20
- )
21
- from MediLink_837p_encoder_library import (
22
- insurance_type_selection,
23
- _original_insurance_type_selection_logic
24
- )
25
- from MediLink import MediLink_insurance_utils
26
- validate_insurance_type_from_config = getattr(MediLink_insurance_utils, 'validate_insurance_type_from_config', None)
27
- get_feature_flag = getattr(MediLink_insurance_utils, 'get_feature_flag', None)
28
- generate_insurance_assignment_summary = getattr(MediLink_insurance_utils, 'generate_insurance_assignment_summary', None)
29
- except ImportError as e:
30
- print("Import error: {}".format(str(e)))
31
- print("This module requires the insurance type components.")
32
-
33
- def run_insurance_type_integration_tests():
34
- """
35
- Run comprehensive integration tests for insurance type selection enhancement.
36
- Python 3.4.4 compatible implementation.
37
- """
38
- print("=" * 60)
39
- print("INSURANCE TYPE SELECTION ENHANCEMENT - INTEGRATION TESTS")
40
- print("=" * 60)
41
-
42
- test_results = {
43
- 'total_tests': 0,
44
- 'passed_tests': 0,
45
- 'failed_tests': 0,
46
- 'test_details': []
47
- }
48
-
49
- # Test 1: Production Readiness Validation
50
- test_results['total_tests'] += 1
51
- try:
52
- print("\n1. Testing Production Readiness Validation...")
53
- from MediLink import MediLink_insurance_utils
54
- validate_insurance_configuration = getattr(MediLink_insurance_utils, 'validate_insurance_configuration', None)
55
- if validate_insurance_configuration:
56
- validate_insurance_configuration()
57
- print(" PASS Production readiness validation PASSED")
58
- test_results['passed_tests'] += 1
59
- test_results['test_details'].append({'test': 'production_readiness', 'status': 'PASSED'})
60
- except Exception as e:
61
- print(" FAIL Production readiness validation FAILED: {}".format(str(e)))
62
- test_results['failed_tests'] += 1
63
- test_results['test_details'].append({'test': 'production_readiness', 'status': 'FAILED', 'error': str(e)})
64
-
65
- # Test 2: Insurance Configuration Validation
66
- test_results['total_tests'] += 1
67
- try:
68
- print("\n2. Testing Insurance Configuration Validation...")
69
- from MediLink import MediLink_insurance_utils
70
- validate_insurance_configuration = getattr(MediLink_insurance_utils, 'validate_insurance_configuration', None)
71
- if validate_insurance_configuration:
72
- validate_insurance_configuration()
73
- print(" PASS Insurance configuration validation PASSED")
74
- test_results['passed_tests'] += 1
75
- test_results['test_details'].append({'test': 'insurance_config', 'status': 'PASSED'})
76
- except Exception as e:
77
- print(" FAIL Insurance configuration validation FAILED: {}".format(str(e)))
78
- test_results['failed_tests'] += 1
79
- test_results['test_details'].append({'test': 'insurance_config', 'status': 'FAILED', 'error': str(e)})
80
-
81
- # Test 3: Feature Flag System
82
- test_results['total_tests'] += 1
83
- try:
84
- print("\n3. Testing Feature Flag System...")
85
- api_flag = get_feature_flag('api_insurance_selection', default=False)
86
- enhanced_flag = get_feature_flag('enhanced_insurance_enrichment', default=False)
87
- print(" API Insurance Selection Flag: {}".format(api_flag))
88
- print(" Enhanced Insurance Enrichment Flag: {}".format(enhanced_flag))
89
- print(" PASS Feature flag system PASSED")
90
- test_results['passed_tests'] += 1
91
- test_results['test_details'].append({'test': 'feature_flags', 'status': 'PASSED'})
92
- except Exception as e:
93
- print(" FAIL Feature flag system FAILED: {}".format(str(e)))
94
- test_results['failed_tests'] += 1
95
- test_results['test_details'].append({'test': 'feature_flags', 'status': 'FAILED', 'error': str(e)})
96
-
97
- # Test 4: API Client Initialization
98
- test_results['total_tests'] += 1
99
- try:
100
- print("\n4. Testing API Client Initialization...")
101
- # Test both factory and direct instantiation
102
- try:
103
- from MediCafe.core_utils import get_api_client
104
- api_client = get_api_client()
105
- if api_client is None:
106
- api_client = APIClient()
107
- except ImportError:
108
- api_client = APIClient()
109
- print(" PASS API client initialization PASSED")
110
- test_results['passed_tests'] += 1
111
- test_results['test_details'].append({'test': 'api_client_init', 'status': 'PASSED'})
112
- except Exception as e:
113
- print(" FAIL API client initialization FAILED: {}".format(str(e)))
114
- test_results['failed_tests'] += 1
115
- test_results['test_details'].append({'test': 'api_client_init', 'status': 'FAILED', 'error': str(e)})
116
-
117
- # Test 5: Insurance Type Selection Backward Compatibility
118
- test_results['total_tests'] += 1
119
- try:
120
- print("\n5. Testing Insurance Type Selection Backward Compatibility...")
121
- test_parsed_data = {
122
- 'LAST': 'TESTPATIENT',
123
- 'FIRST': 'TEST',
124
- 'BDAY': '1980-01-01',
125
- 'insurance_type': '12' # Pre-assigned
126
- }
127
- result = insurance_type_selection(test_parsed_data)
128
- assert result == '12', "Should return pre-assigned insurance type"
129
- print(" PASS Insurance type selection backward compatibility PASSED")
130
- test_results['passed_tests'] += 1
131
- test_results['test_details'].append({'test': 'backward_compatibility', 'status': 'PASSED'})
132
- except Exception as e:
133
- print(" FAIL Insurance type selection backward compatibility FAILED: {}".format(str(e)))
134
- test_results['failed_tests'] += 1
135
- test_results['test_details'].append({'test': 'backward_compatibility', 'status': 'FAILED', 'error': str(e)})
136
-
137
- # Test 6: Patient Data Enrichment
138
- test_results['total_tests'] += 1
139
- try:
140
- print("\n6. Testing Patient Data Enrichment...")
141
- test_patient_data = [
142
- {
143
- 'patient_id': 'TEST001',
144
- 'patient_name': 'Test Patient',
145
- 'primary_insurance_id': '87726'
146
- }
147
- ]
148
- enriched_data = enrich_with_insurance_type(test_patient_data)
149
- assert len(enriched_data) == 1, "Should return same number of patients"
150
- assert 'insurance_type' in enriched_data[0], "Should add insurance_type field"
151
- print(" PASS Patient data enrichment PASSED")
152
- test_results['passed_tests'] += 1
153
- test_results['test_details'].append({'test': 'patient_enrichment', 'status': 'PASSED'})
154
- except Exception as e:
155
- print(" FAIL Patient data enrichment FAILED: {}".format(str(e)))
156
- test_results['failed_tests'] += 1
157
- test_results['test_details'].append({'test': 'patient_enrichment', 'status': 'FAILED', 'error': str(e)})
158
-
159
- # Test 7: Monitoring System
160
- test_results['total_tests'] += 1
161
- try:
162
- print("\n7. Testing Monitoring System...")
163
- test_patient_data = [
164
- {
165
- 'patient_id': 'TEST001',
166
- 'insurance_type': '12',
167
- 'insurance_type_source': 'DEFAULT'
168
- },
169
- {
170
- 'patient_id': 'TEST002',
171
- 'insurance_type': 'HM',
172
- 'insurance_type_source': 'API'
173
- }
174
- ]
175
- generate_insurance_assignment_summary(test_patient_data)
176
- print(" PASS Monitoring system PASSED")
177
- test_results['passed_tests'] += 1
178
- test_results['test_details'].append({'test': 'monitoring', 'status': 'PASSED'})
179
- except Exception as e:
180
- print(" FAIL Monitoring system FAILED: {}".format(str(e)))
181
- test_results['failed_tests'] += 1
182
- test_results['test_details'].append({'test': 'monitoring', 'status': 'FAILED', 'error': str(e)})
183
-
184
- # Print Test Summary
185
- print("\n" + "=" * 60)
186
- print("TEST SUMMARY")
187
- print("=" * 60)
188
- print("Total Tests: {}".format(test_results['total_tests']))
189
- print("Passed: {}".format(test_results['passed_tests']))
190
- print("Failed: {}".format(test_results['failed_tests']))
191
-
192
- if test_results['failed_tests'] == 0:
193
- print("\nPASS ALL TESTS! System ready for deployment.")
194
- else:
195
- print("\nFAIL {} TESTS. Review before deployment.".format(test_results['failed_tests']))
196
- for test in test_results['test_details']:
197
- if test['status'] == 'FAILED':
198
- print(" - {}: {}".format(test['test'], test.get('error', 'Unknown error')))
199
-
200
- return test_results
201
-
202
- def test_insurance_type_validation():
203
- """Test insurance type validation with various scenarios"""
204
- print("\n" + "=" * 50)
205
- print("INSURANCE TYPE VALIDATION TESTS")
206
- print("=" * 50)
207
-
208
- test_cases = [
209
- {
210
- 'name': 'Valid PPO Type',
211
- 'insurance_type': '12',
212
- 'payer_id': '87726',
213
- 'expected': '12'
214
- },
215
- {
216
- 'name': 'Valid HMO Type',
217
- 'insurance_type': 'HM',
218
- 'payer_id': '87726',
219
- 'expected': 'HM'
220
- },
221
- {
222
- 'name': 'Novel Valid Type (Strict Validation)',
223
- 'insurance_type': 'EP',
224
- 'payer_id': '87726',
225
- 'expected': '12' # Strict validation rejects novel codes
226
- },
227
- {
228
- 'name': 'Invalid Type Format',
229
- 'insurance_type': 'INVALID123',
230
- 'payer_id': '87726',
231
- 'expected': '12' # Should fallback to PPO
232
- },
233
- {
234
- 'name': 'Empty Type',
235
- 'insurance_type': '',
236
- 'payer_id': '87726',
237
- 'expected': '12' # Should fallback to PPO
238
- }
239
- ]
240
-
241
- passed = 0
242
- failed = 0
243
-
244
- for test_case in test_cases:
245
- try:
246
- result = validate_insurance_type_from_config(
247
- test_case['insurance_type'],
248
- test_case['payer_id']
249
- )
250
-
251
- if result == test_case['expected']:
252
- print("PASS {}: {} -> {}".format(test_case['name'], test_case['insurance_type'], result))
253
- passed += 1
254
- else:
255
- print("FAIL {}: Expected {}, got {}".format(test_case['name'], test_case['expected'], result))
256
- failed += 1
257
-
258
- except Exception as e:
259
- print("FAIL {}: Exception - {}".format(test_case['name'], str(e)))
260
- failed += 1
261
-
262
- print("\nValidation Tests Summary: {} passed, {} failed".format(passed, failed))
263
- return passed, failed
264
-
265
- def create_test_configuration():
266
- """Create test configuration for development and testing"""
267
- print("\n" + "=" * 50)
268
- print("CREATING TEST CONFIGURATION")
269
- print("=" * 50)
270
-
271
- test_config = {
272
- "MediLink_Config": {
273
- "feature_flags": {
274
- "api_insurance_selection": False, # Start disabled
275
- "enhanced_insurance_enrichment": False, # Start disabled
276
- "enhanced_insurance_selection": False # Start disabled
277
- },
278
- "insurance_options": {
279
- "12": "Preferred Provider Organization (PPO)",
280
- "13": "Point of Service (POS)",
281
- "14": "Exclusive Provider Organization (EPO)",
282
- "16": "Indemnity",
283
- "HM": "Health Maintenance Organization (HMO)",
284
- "BL": "Blue Cross/Blue Shield",
285
- "CI": "Commercial Insurance",
286
- "MA": "Medicare Advantage",
287
- "MB": "Medicare Part B",
288
- "MC": "Medicare Part C"
289
- },
290
- "default_insurance_type": "12",
291
- "TestMode": False # Must be False for production
292
- }
293
- }
294
-
295
- print("Test configuration created:")
296
- print(json.dumps(test_config, indent=2))
297
- print("\nCopy this configuration to your config.json file")
298
- print("Ensure TestMode is False for production")
299
- print("Enable feature flags gradually during rollout")
300
-
301
- return test_config
302
-
303
- def deployment_checklist():
304
- """Print deployment checklist for insurance type enhancement"""
305
- print("\n" + "=" * 60)
306
- print("DEPLOYMENT CHECKLIST")
307
- print("=" * 60)
308
-
309
- checklist = [
310
- "[ ] All integration tests pass",
311
- "[ ] Production readiness validation passes",
312
- "[ ] Insurance configuration validation passes",
313
- "[ ] TestMode is disabled in configuration",
314
- "[ ] Feature flags are properly configured (default: disabled)",
315
- "[ ] Enhanced API client initializes successfully",
316
- "[ ] Backward compatibility verified with existing callers",
317
- "[ ] Monitoring system is functional",
318
- "[ ] Circuit breaker, caching, and rate limiting are active",
319
- "[ ] Fallback mechanisms tested and working",
320
- "[ ] Log rotation configured for increased logging volume",
321
- "[ ] Documentation updated with new features",
322
- "[ ] Team trained on new monitoring and feature flags"
323
- ]
324
-
325
- for item in checklist:
326
- print(item)
327
-
328
- print("\nComplete all checklist items before deployment")
329
- print("Follow gradual rollout plan with feature flags")
330
- print("Monitor logs and metrics closely during rollout")
331
-
332
- if __name__ == "__main__":
333
- print("Insurance Type Selection Enhancement - Integration Test Suite")
334
- print("Python 3.4.4 Compatible Implementation")
335
-
336
- # Run all tests
337
- test_results = run_insurance_type_integration_tests()
338
-
339
- # Run validation tests
340
- validation_passed, validation_failed = test_insurance_type_validation()
341
-
342
- # Create test configuration
343
- test_config = create_test_configuration()
344
-
345
- # Display deployment checklist
346
- deployment_checklist()
347
-
348
- # Final summary
349
- print("\n" + "=" * 60)
350
- print("FINAL SUMMARY")
351
- print("=" * 60)
352
- total_passed = test_results['passed_tests'] + validation_passed
353
- total_failed = test_results['failed_tests'] + validation_failed
354
- total_tests = test_results['total_tests'] + validation_passed + validation_failed
355
-
356
- print("Overall Tests: {} passed, {} failed out of {} total".format(total_passed, total_failed, total_tests))
357
-
358
- if total_failed == 0:
359
- print("PASS ALL SYSTEMS GO! Ready for phased deployment.")
360
- else:
361
- print("FAIL Address {} failed tests before deployment.".format(total_failed))