medicafe 0.250728.8__py3-none-any.whl → 0.250805.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.

Potentially problematic release.


This version of medicafe might be problematic. Click here for more details.

Files changed (58) hide show
  1. MediBot/MediBot.bat +233 -19
  2. MediBot/MediBot.py +138 -46
  3. MediBot/MediBot_Crosswalk_Library.py +127 -623
  4. MediBot/MediBot_Crosswalk_Utils.py +618 -0
  5. MediBot/MediBot_Preprocessor.py +72 -17
  6. MediBot/MediBot_Preprocessor_lib.py +470 -76
  7. MediBot/MediBot_UI.py +32 -17
  8. MediBot/MediBot_dataformat_library.py +68 -20
  9. MediBot/MediBot_docx_decoder.py +120 -19
  10. MediBot/MediBot_smart_import.py +180 -0
  11. MediBot/__init__.py +89 -0
  12. MediBot/get_medicafe_version.py +25 -0
  13. MediBot/update_json.py +35 -6
  14. MediBot/update_medicafe.py +19 -1
  15. MediCafe/MediLink_ConfigLoader.py +160 -0
  16. MediCafe/__init__.py +171 -0
  17. MediCafe/__main__.py +222 -0
  18. MediCafe/api_core.py +1098 -0
  19. MediCafe/api_core_backup.py +427 -0
  20. MediCafe/api_factory.py +306 -0
  21. MediCafe/api_utils.py +356 -0
  22. MediCafe/core_utils.py +450 -0
  23. MediCafe/graphql_utils.py +445 -0
  24. MediCafe/logging_config.py +123 -0
  25. MediCafe/logging_demo.py +61 -0
  26. MediCafe/migration_helpers.py +463 -0
  27. MediCafe/smart_import.py +436 -0
  28. MediLink/MediLink.py +66 -26
  29. MediLink/MediLink_837p_cob_library.py +28 -28
  30. MediLink/MediLink_837p_encoder.py +33 -34
  31. MediLink/MediLink_837p_encoder_library.py +243 -151
  32. MediLink/MediLink_837p_utilities.py +129 -5
  33. MediLink/MediLink_API_Generator.py +83 -60
  34. MediLink/MediLink_API_v3.py +1 -1
  35. MediLink/MediLink_ClaimStatus.py +177 -31
  36. MediLink/MediLink_DataMgmt.py +405 -72
  37. MediLink/MediLink_Decoder.py +20 -1
  38. MediLink/MediLink_Deductible.py +155 -28
  39. MediLink/MediLink_Display_Utils.py +72 -0
  40. MediLink/MediLink_Down.py +127 -5
  41. MediLink/MediLink_Gmail.py +712 -653
  42. MediLink/MediLink_PatientProcessor.py +257 -0
  43. MediLink/MediLink_UI.py +85 -61
  44. MediLink/MediLink_Up.py +28 -4
  45. MediLink/MediLink_insurance_utils.py +227 -264
  46. MediLink/MediLink_main.py +248 -0
  47. MediLink/MediLink_smart_import.py +264 -0
  48. MediLink/__init__.py +93 -0
  49. MediLink/insurance_type_integration_test.py +66 -76
  50. MediLink/test.py +1 -1
  51. MediLink/test_timing.py +59 -0
  52. {medicafe-0.250728.8.dist-info → medicafe-0.250805.0.dist-info}/METADATA +1 -1
  53. medicafe-0.250805.0.dist-info/RECORD +81 -0
  54. medicafe-0.250805.0.dist-info/entry_points.txt +2 -0
  55. {medicafe-0.250728.8.dist-info → medicafe-0.250805.0.dist-info}/top_level.txt +1 -0
  56. medicafe-0.250728.8.dist-info/RECORD +0 -59
  57. {medicafe-0.250728.8.dist-info → medicafe-0.250805.0.dist-info}/LICENSE +0 -0
  58. {medicafe-0.250728.8.dist-info → medicafe-0.250805.0.dist-info}/WHEEL +0 -0
@@ -1,265 +1,228 @@
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
-
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
+ # Use core utilities for standardized imports
10
+ from MediCafe.core_utils import get_shared_config_loader
11
+ MediLink_ConfigLoader = get_shared_config_loader()
12
+
13
+ # Safe tqdm import with fallback
14
+ try:
15
+ from tqdm import tqdm
16
+ except ImportError:
17
+ # Fallback for when tqdm is not available
18
+ def tqdm(iterable, desc="Processing", **kwargs):
19
+ if desc:
20
+ print("{}...".format(desc))
21
+ return iterable
22
+
23
+ # Feature flag system
24
+ def get_feature_flag(flag_name, default=False):
25
+ """Get feature flag from config or return default"""
26
+ try:
27
+ config, _ = MediLink_ConfigLoader.load_configuration()
28
+ feature_flags = config.get("MediLink_Config", {}).get("feature_flags", {})
29
+ return feature_flags.get(flag_name, default)
30
+ except Exception as e:
31
+ MediLink_ConfigLoader.log("Error reading feature flag {}: {}".format(flag_name, str(e)), level="WARNING")
32
+ return default
33
+
34
+ # Enhanced insurance type validation
35
+ def validate_insurance_type_from_config(insurance_type_code, payer_id=""):
36
+ """
37
+ Validate insurance type against configuration.
38
+ Returns validated type or safe fallback.
39
+ """
40
+ try:
41
+ config, _ = MediLink_ConfigLoader.load_configuration()
42
+ insurance_options = config.get('MediLink_Config', {}).get('insurance_options', {})
43
+
44
+ if not insurance_type_code:
45
+ MediLink_ConfigLoader.log("Empty insurance type code for payer {}, using default PPO".format(payer_id), level="INFO")
46
+ return '12' # Default to PPO
47
+
48
+ # Clean and normalize input
49
+ insurance_type_code = str(insurance_type_code).strip().upper()
50
+
51
+ # Basic format validation
52
+ if len(insurance_type_code) > 3 or not insurance_type_code.isalnum():
53
+ MediLink_ConfigLoader.log("Invalid insurance type format '{}' for payer {}, using PPO fallback".format(
54
+ insurance_type_code, payer_id), level="WARNING")
55
+ return '12'
56
+
57
+ # Configuration lookup - insurance type exists in config
58
+ if insurance_type_code in insurance_options:
59
+ MediLink_ConfigLoader.log("Validated insurance type '{}' for payer {}".format(
60
+ insurance_type_code, payer_id), level="DEBUG")
61
+ return insurance_type_code
62
+
63
+ # Unknown type - log and fallback
64
+ MediLink_ConfigLoader.log("Unknown insurance type '{}' for payer {} - using PPO fallback".format(
65
+ insurance_type_code, payer_id), level="WARNING")
66
+
67
+ return '12' # Safe fallback to PPO
68
+
69
+ except Exception as e:
70
+ MediLink_ConfigLoader.log("Insurance validation error: {} - using PPO fallback".format(str(e)), level="ERROR")
71
+ return '12'
72
+
73
+ # Monitoring and statistics
74
+ def generate_insurance_assignment_summary(detailed_patient_data):
75
+ """Generate basic summary statistics for insurance type assignments"""
76
+ if not detailed_patient_data:
77
+ return {}
78
+
79
+ # Collect basic statistics
80
+ insurance_type_counts = {}
81
+
82
+ for data in detailed_patient_data:
83
+ insurance_type = data.get('insurance_type', 'UNKNOWN')
84
+ insurance_type_counts[insurance_type] = insurance_type_counts.get(insurance_type, 0) + 1
85
+
86
+ summary = {
87
+ 'total_patients': len(detailed_patient_data),
88
+ 'insurance_types': insurance_type_counts
89
+ }
90
+
91
+ # Log summary
92
+ MediLink_ConfigLoader.log("Insurance Assignment Summary: {}".format(json.dumps(summary)), level="INFO")
93
+
94
+ return summary
95
+
96
+ # Safe wrapper for insurance type selection
97
+ def safe_insurance_type_selection(parsed_data, fallback_function):
98
+ """
99
+ Safe wrapper that attempts enhanced selection with fallback to original function.
100
+ Provides comprehensive error handling and logging.
101
+ """
102
+ patient_name = parsed_data.get('LAST', 'UNKNOWN')
103
+
104
+ try:
105
+ # Check if enhanced mode is enabled
106
+ enhanced_mode = get_feature_flag('enhanced_insurance_selection', default=False)
107
+
108
+ if enhanced_mode:
109
+ # Try enhanced selection (would be implemented here)
110
+ MediLink_ConfigLoader.log("Attempting enhanced insurance selection", level="DEBUG")
111
+ # For now, just call fallback - actual enhancement would go here
112
+ result = fallback_function(parsed_data)
113
+ MediLink_ConfigLoader.log("Insurance decision: type={}, method=ENHANCED".format(result), level="INFO")
114
+ return result
115
+ else:
116
+ # Use standard selection
117
+ result = fallback_function(parsed_data)
118
+ MediLink_ConfigLoader.log("Insurance decision: type={}, method=MANUAL".format(result), level="INFO")
119
+ return result
120
+
121
+ except Exception as e:
122
+ # Error handling with safe fallback
123
+ MediLink_ConfigLoader.log("Insurance selection error: {}. Using PPO default.".format(str(e)), level="ERROR")
124
+
125
+ MediLink_ConfigLoader.log("Insurance decision: type=12, method=ERROR_FALLBACK, error={}".format(str(e)), level="INFO")
126
+ return '12' # Safe fallback
127
+
128
+ # Configuration validation
129
+ def validate_insurance_configuration():
130
+ """
131
+ Validate insurance configuration for production readiness.
132
+ Returns True if valid, raises exception if invalid.
133
+ """
134
+ try:
135
+ config, _ = MediLink_ConfigLoader.load_configuration()
136
+ insurance_options = config['MediLink_Config'].get('insurance_options', {})
137
+
138
+ if not insurance_options:
139
+ raise ValueError("Missing insurance_options in MediLink_Config")
140
+
141
+ # Validate insurance options format
142
+ for code, description in insurance_options.items():
143
+ if not isinstance(code, str) or len(code) < 1:
144
+ raise ValueError("Invalid insurance code format: {}".format(code))
145
+ if not isinstance(description, str):
146
+ raise ValueError("Invalid insurance description for code: {}".format(code))
147
+
148
+ MediLink_ConfigLoader.log("Insurance configuration validation passed: {} options loaded".format(
149
+ len(insurance_options)), level="INFO")
150
+ return True
151
+
152
+ except Exception as e:
153
+ MediLink_ConfigLoader.log("Insurance configuration validation failed: {}".format(str(e)), level="ERROR")
154
+ raise e
155
+
156
+ # Production readiness check
157
+ def check_production_readiness():
158
+ """
159
+ Check if system is ready for production deployment.
160
+ Returns list of warnings/errors that need attention.
161
+ """
162
+ issues = []
163
+
164
+ try:
165
+ # Check configuration
166
+ validate_insurance_configuration()
167
+ except Exception as e:
168
+ issues.append("Configuration invalid: {}".format(str(e)))
169
+
170
+ # Check for test mode flags
171
+ try:
172
+ config, _ = MediLink_ConfigLoader.load_configuration()
173
+ test_mode = config.get("MediLink_Config", {}).get("TestMode", False)
174
+ if test_mode:
175
+ issues.append("TestMode is enabled - should be disabled for production")
176
+ except Exception as e:
177
+ issues.append("Cannot check test mode: {}".format(str(e)))
178
+
179
+ return issues
180
+
181
+ # Enhanced error handling wrapper
182
+ def with_insurance_error_handling(func):
183
+ """
184
+ Decorator for insurance-related functions to add consistent error handling.
185
+ Python 3.4.4 compatible implementation.
186
+ """
187
+ def wrapper(*args, **kwargs):
188
+ try:
189
+ return func(*args, **kwargs)
190
+ except Exception as e:
191
+ MediLink_ConfigLoader.log("Insurance function error in {}: {}".format(func.__name__, str(e)), level="ERROR")
192
+ # Return safe defaults based on function type
193
+ if 'insurance_type' in func.__name__:
194
+ return '12' # Default PPO for insurance type functions
195
+ else:
196
+ raise e # Re-raise for non-insurance type functions
197
+ return wrapper
198
+
199
+ # Utility for batch processing with progress tracking
200
+ def process_patients_with_progress(patients, processing_function, description="Processing patients"):
201
+ """
202
+ Process patients with progress tracking and error collection.
203
+ Returns processed results and error summary.
204
+ """
205
+ processed_results = []
206
+ errors = []
207
+
208
+ iterator = tqdm(patients, desc=description)
209
+
210
+ for i, patient in enumerate(iterator):
211
+ try:
212
+ result = processing_function(patient)
213
+ processed_results.append(result)
214
+ except Exception as e:
215
+ error_info = {
216
+ 'patient_index': i,
217
+ 'patient_id': patient.get('patient_id', 'UNKNOWN'),
218
+ 'error': str(e)
219
+ }
220
+ errors.append(error_info)
221
+ MediLink_ConfigLoader.log("Error processing patient {}: {}".format(
222
+ patient.get('patient_id', i), str(e)), level="ERROR")
223
+
224
+ if errors:
225
+ MediLink_ConfigLoader.log("Batch processing completed with {} errors out of {} patients".format(
226
+ len(errors), len(patients)), level="WARNING")
227
+
265
228
  return processed_results, errors