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