medicafe 0.250720.1__tar.gz → 0.250722.0__tar.gz
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.
- {medicafe-0.250720.1 → medicafe-0.250722.0}/MediBot/MediBot.bat +2 -0
- {medicafe-0.250720.1 → medicafe-0.250722.0}/MediBot/MediBot_Preprocessor.py +36 -21
- {medicafe-0.250720.1 → medicafe-0.250722.0}/MediBot/MediBot_Preprocessor_lib.py +59 -22
- {medicafe-0.250720.1 → medicafe-0.250722.0}/MediLink/MediLink_837p_cob_library.py +18 -15
- {medicafe-0.250720.1 → medicafe-0.250722.0}/MediLink/MediLink_837p_encoder.py +27 -3
- {medicafe-0.250720.1 → medicafe-0.250722.0}/MediLink/MediLink_837p_encoder_library.py +48 -14
- {medicafe-0.250720.1 → medicafe-0.250722.0}/MediLink/MediLink_DataMgmt.py +10 -5
- {medicafe-0.250720.1 → medicafe-0.250722.0}/PKG-INFO +1 -1
- {medicafe-0.250720.1 → medicafe-0.250722.0}/medicafe.egg-info/PKG-INFO +1 -1
- {medicafe-0.250720.1 → medicafe-0.250722.0}/setup.py +1 -1
- {medicafe-0.250720.1 → medicafe-0.250722.0}/LICENSE +0 -0
- {medicafe-0.250720.1 → medicafe-0.250722.0}/MANIFEST.in +0 -0
- {medicafe-0.250720.1 → medicafe-0.250722.0}/MediBot/MediBot.py +0 -0
- {medicafe-0.250720.1 → medicafe-0.250722.0}/MediBot/MediBot_Charges.py +0 -0
- {medicafe-0.250720.1 → medicafe-0.250722.0}/MediBot/MediBot_Crosswalk_Library.py +0 -0
- {medicafe-0.250720.1 → medicafe-0.250722.0}/MediBot/MediBot_Post.py +0 -0
- {medicafe-0.250720.1 → medicafe-0.250722.0}/MediBot/MediBot_UI.py +0 -0
- {medicafe-0.250720.1 → medicafe-0.250722.0}/MediBot/MediBot_dataformat_library.py +0 -0
- {medicafe-0.250720.1 → medicafe-0.250722.0}/MediBot/MediBot_docx_decoder.py +0 -0
- {medicafe-0.250720.1 → medicafe-0.250722.0}/MediBot/PDF_to_CSV_Cleaner.py +0 -0
- {medicafe-0.250720.1 → medicafe-0.250722.0}/MediBot/__init__.py +0 -0
- {medicafe-0.250720.1 → medicafe-0.250722.0}/MediBot/update_json.py +0 -0
- {medicafe-0.250720.1 → medicafe-0.250722.0}/MediBot/update_medicafe.py +0 -0
- {medicafe-0.250720.1 → medicafe-0.250722.0}/MediLink/MediLink.py +0 -0
- {medicafe-0.250720.1 → medicafe-0.250722.0}/MediLink/MediLink_837p_utilities.py +0 -0
- {medicafe-0.250720.1 → medicafe-0.250722.0}/MediLink/MediLink_API_Generator.py +0 -0
- {medicafe-0.250720.1 → medicafe-0.250722.0}/MediLink/MediLink_API_v2.py +0 -0
- {medicafe-0.250720.1 → medicafe-0.250722.0}/MediLink/MediLink_API_v3.py +0 -0
- {medicafe-0.250720.1 → medicafe-0.250722.0}/MediLink/MediLink_APIs.py +0 -0
- {medicafe-0.250720.1 → medicafe-0.250722.0}/MediLink/MediLink_Azure.py +0 -0
- {medicafe-0.250720.1 → medicafe-0.250722.0}/MediLink/MediLink_ClaimStatus.py +0 -0
- {medicafe-0.250720.1 → medicafe-0.250722.0}/MediLink/MediLink_ConfigLoader.py +0 -0
- {medicafe-0.250720.1 → medicafe-0.250722.0}/MediLink/MediLink_Decoder.py +0 -0
- {medicafe-0.250720.1 → medicafe-0.250722.0}/MediLink/MediLink_Deductible.py +0 -0
- {medicafe-0.250720.1 → medicafe-0.250722.0}/MediLink/MediLink_Deductible_Validator.py +0 -0
- {medicafe-0.250720.1 → medicafe-0.250722.0}/MediLink/MediLink_Down.py +0 -0
- {medicafe-0.250720.1 → medicafe-0.250722.0}/MediLink/MediLink_Gmail.py +0 -0
- {medicafe-0.250720.1 → medicafe-0.250722.0}/MediLink/MediLink_GraphQL.py +0 -0
- {medicafe-0.250720.1 → medicafe-0.250722.0}/MediLink/MediLink_Mailer.py +0 -0
- {medicafe-0.250720.1 → medicafe-0.250722.0}/MediLink/MediLink_Parser.py +0 -0
- {medicafe-0.250720.1 → medicafe-0.250722.0}/MediLink/MediLink_Scan.py +0 -0
- {medicafe-0.250720.1 → medicafe-0.250722.0}/MediLink/MediLink_Scheduler.py +0 -0
- {medicafe-0.250720.1 → medicafe-0.250722.0}/MediLink/MediLink_UI.py +0 -0
- {medicafe-0.250720.1 → medicafe-0.250722.0}/MediLink/MediLink_Up.py +0 -0
- {medicafe-0.250720.1 → medicafe-0.250722.0}/MediLink/MediLink_batch.bat +0 -0
- {medicafe-0.250720.1 → medicafe-0.250722.0}/MediLink/Soumit_api.py +0 -0
- {medicafe-0.250720.1 → medicafe-0.250722.0}/MediLink/__init__.py +0 -0
- {medicafe-0.250720.1 → medicafe-0.250722.0}/MediLink/openssl.cnf +0 -0
- {medicafe-0.250720.1 → medicafe-0.250722.0}/MediLink/test.py +0 -0
- {medicafe-0.250720.1 → medicafe-0.250722.0}/MediLink/test_cob_library.py +0 -0
- {medicafe-0.250720.1 → medicafe-0.250722.0}/MediLink/test_validation.py +0 -0
- {medicafe-0.250720.1 → medicafe-0.250722.0}/MediLink/webapp.html +0 -0
- {medicafe-0.250720.1 → medicafe-0.250722.0}/README.md +0 -0
- {medicafe-0.250720.1 → medicafe-0.250722.0}/medicafe.egg-info/SOURCES.txt +0 -0
- {medicafe-0.250720.1 → medicafe-0.250722.0}/medicafe.egg-info/dependency_links.txt +0 -0
- {medicafe-0.250720.1 → medicafe-0.250722.0}/medicafe.egg-info/not-zip-safe +0 -0
- {medicafe-0.250720.1 → medicafe-0.250722.0}/medicafe.egg-info/requires.txt +0 -0
- {medicafe-0.250720.1 → medicafe-0.250722.0}/medicafe.egg-info/top_level.txt +0 -0
- {medicafe-0.250720.1 → medicafe-0.250722.0}/setup.cfg +0 -0
|
@@ -281,9 +281,11 @@ for %%f in ("%target_folder%\!latest_csv!") do set "latest_csv_name=%%~nxf"
|
|
|
281
281
|
|
|
282
282
|
:: Compare the paths and prompt user if necessary
|
|
283
283
|
if not "!current_csv_name!"=="!latest_csv_name!" (
|
|
284
|
+
echo.
|
|
284
285
|
echo ALERT: Config file CSV path differs from the latest CSV. This can happen if a new CSV is downloaded.
|
|
285
286
|
echo Current CSV: !current_csv_name!
|
|
286
287
|
echo Latest CSV: !latest_csv_name!
|
|
288
|
+
echo.
|
|
287
289
|
set /p update_choice="Do you want to update to the latest CSV? (Y/N): "
|
|
288
290
|
if /i "!update_choice!"=="Y" (
|
|
289
291
|
echo Updating config file with latest CSV...
|
|
@@ -25,7 +25,8 @@ except ImportError as e:
|
|
|
25
25
|
|
|
26
26
|
# Load configuration
|
|
27
27
|
# Should this also take args? Path for ./MediLink needed to be added for this to resolve
|
|
28
|
-
|
|
28
|
+
# Use cached configuration to avoid repeated I/O operations
|
|
29
|
+
config, crosswalk = MediBot_Preprocessor_lib.get_cached_configuration()
|
|
29
30
|
|
|
30
31
|
# CSV Preprocessor built for Carol
|
|
31
32
|
def preprocess_csv_data(csv_data, crosswalk):
|
|
@@ -57,9 +58,7 @@ def preprocess_csv_data(csv_data, crosswalk):
|
|
|
57
58
|
# and which haven't been yet. So, if the patient 'exists' in the system, the next quetion is about claims/billing status.
|
|
58
59
|
# Eventually, we really want to get out of Medisoft...
|
|
59
60
|
|
|
60
|
-
#
|
|
61
|
-
# Combine 'Patient First', 'Patient Middle', and 'Patient Last' into a single 'Patient Name' field.
|
|
62
|
-
# Combine 'Patient Address1' and 'Patient Address2' into a single 'Patient Street' field.
|
|
61
|
+
# Batch field operations: Convert dates, combine names/addresses, and apply replacements
|
|
63
62
|
MediLink_ConfigLoader.log("CSV Pre-processor: Constructing Patient Name and Address for Medisoft...", level="INFO")
|
|
64
63
|
MediBot_Preprocessor_lib.combine_fields(csv_data)
|
|
65
64
|
|
|
@@ -97,7 +96,8 @@ def preprocess_csv_data(csv_data, crosswalk):
|
|
|
97
96
|
|
|
98
97
|
def check_existing_patients(selected_patient_ids, MAPAT_MED_PATH):
|
|
99
98
|
existing_patients = []
|
|
100
|
-
|
|
99
|
+
# Convert to set for O(1) lookup performance
|
|
100
|
+
selected_patient_ids_set = set(selected_patient_ids)
|
|
101
101
|
|
|
102
102
|
try:
|
|
103
103
|
with open(MAPAT_MED_PATH, 'r') as file:
|
|
@@ -107,17 +107,17 @@ def check_existing_patients(selected_patient_ids, MAPAT_MED_PATH):
|
|
|
107
107
|
patient_id = line[194:202].strip() # Extract Patient ID (Columns 195-202)
|
|
108
108
|
patient_name = line[9:39].strip() # Extract Patient Name (Columns 10-39)
|
|
109
109
|
|
|
110
|
-
if patient_id in
|
|
110
|
+
if patient_id in selected_patient_ids_set:
|
|
111
111
|
existing_patients.append((patient_id, patient_name))
|
|
112
|
-
# Remove
|
|
113
|
-
|
|
112
|
+
# Remove from set for O(1) operation
|
|
113
|
+
selected_patient_ids_set.discard(patient_id)
|
|
114
114
|
except FileNotFoundError:
|
|
115
115
|
# Handle the case where MAPAT_MED_PATH is not found
|
|
116
116
|
print("MAPAT.med was not found at location indicated in config file.")
|
|
117
117
|
print("Skipping existing patient check and continuing...")
|
|
118
118
|
|
|
119
|
-
#
|
|
120
|
-
patients_to_process =
|
|
119
|
+
# Convert remaining set back to list for return
|
|
120
|
+
patients_to_process = list(selected_patient_ids_set)
|
|
121
121
|
|
|
122
122
|
return existing_patients, patients_to_process
|
|
123
123
|
|
|
@@ -129,14 +129,25 @@ def intake_scan(csv_headers, field_mapping):
|
|
|
129
129
|
MediLink_ConfigLoader.log("Intake Scan - Field Mapping: {}".format(field_mapping), level="DEBUG")
|
|
130
130
|
MediLink_ConfigLoader.log("Intake Scan - CSV Headers: {}".format(csv_headers), level="DEBUG")
|
|
131
131
|
|
|
132
|
+
# Pre-compile regex patterns for better performance
|
|
133
|
+
compiled_patterns = {}
|
|
134
|
+
for medisoft_field, patterns in field_mapping.items():
|
|
135
|
+
compiled_patterns[medisoft_field] = [re.compile(pattern, re.IGNORECASE) for pattern in patterns]
|
|
136
|
+
|
|
137
|
+
# Pre-compile the alphanumeric regex for policy number validation
|
|
138
|
+
alphanumeric_pattern = re.compile("^[a-zA-Z0-9]*$")
|
|
139
|
+
|
|
132
140
|
# Iterate over the Medisoft fields defined in field_mapping
|
|
133
141
|
for medisoft_field in field_mapping.keys():
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
142
|
+
matched = False
|
|
143
|
+
for pattern in compiled_patterns[medisoft_field]:
|
|
144
|
+
# Use early termination - find first match and break
|
|
145
|
+
for header in csv_headers:
|
|
146
|
+
if pattern.search(header):
|
|
147
|
+
identified_fields[header] = medisoft_field
|
|
148
|
+
matched = True
|
|
149
|
+
break
|
|
150
|
+
if matched:
|
|
140
151
|
break
|
|
141
152
|
else:
|
|
142
153
|
# Check if the missing field is a required field before appending the warning
|
|
@@ -160,7 +171,7 @@ def intake_scan(csv_headers, field_mapping):
|
|
|
160
171
|
if 'Insurance Policy Number' in field:
|
|
161
172
|
policy_number = identified_fields.get(header)
|
|
162
173
|
MediLink_ConfigLoader.log("Checking Insurance Policy Number '{}' for alphanumeric characters.".format(policy_number), level="DEBUG")
|
|
163
|
-
if not
|
|
174
|
+
if not alphanumeric_pattern.match(policy_number):
|
|
164
175
|
missing_fields_warnings.append("WARNING: Insurance Policy Number '{}' contains invalid characters.".format(policy_number))
|
|
165
176
|
MediLink_ConfigLoader.log("Insurance Policy Number '{}' contains invalid characters.".format(policy_number), level="WARNING")
|
|
166
177
|
# Additional checks can be added as needed for other fields
|
|
@@ -187,15 +198,19 @@ def main():
|
|
|
187
198
|
|
|
188
199
|
args = parser.parse_args()
|
|
189
200
|
|
|
190
|
-
config, crosswalk = MediLink_ConfigLoader.load_configuration()
|
|
191
|
-
|
|
192
|
-
client = APIClient()
|
|
193
|
-
|
|
194
201
|
# If no arguments provided, print usage instructions
|
|
195
202
|
if not any(vars(args).values()):
|
|
196
203
|
parser.print_help()
|
|
197
204
|
return
|
|
198
205
|
|
|
206
|
+
# Load configuration only when needed
|
|
207
|
+
if args.update_crosswalk or args.init_crosswalk or args.load_csv or args.preprocess_csv or args.open_csv:
|
|
208
|
+
config, crosswalk = MediBot_Preprocessor_lib.get_cached_configuration()
|
|
209
|
+
|
|
210
|
+
# Initialize API client only when needed
|
|
211
|
+
if args.update_crosswalk or args.init_crosswalk:
|
|
212
|
+
client = APIClient()
|
|
213
|
+
|
|
199
214
|
if args.update_crosswalk:
|
|
200
215
|
print("Updating the crosswalk...")
|
|
201
216
|
MediBot_Crosswalk_Library.crosswalk_update(client, config, crosswalk)
|
|
@@ -7,6 +7,10 @@ import chardet # Ensure chardet is imported
|
|
|
7
7
|
# Add the parent directory of the project to the Python path
|
|
8
8
|
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
|
|
9
9
|
|
|
10
|
+
# Configuration cache to avoid repeated loading
|
|
11
|
+
_config_cache = None
|
|
12
|
+
_crosswalk_cache = None
|
|
13
|
+
|
|
10
14
|
# Attempt to import necessary modules, falling back if they are not found
|
|
11
15
|
try:
|
|
12
16
|
import MediLink_ConfigLoader
|
|
@@ -44,6 +48,17 @@ def initialize(config):
|
|
|
44
48
|
except AttributeError:
|
|
45
49
|
raise InitializationError("Error: '{}' not found in config.".format(key))
|
|
46
50
|
|
|
51
|
+
def get_cached_configuration():
|
|
52
|
+
"""
|
|
53
|
+
Returns cached configuration and crosswalk data to avoid repeated I/O operations.
|
|
54
|
+
"""
|
|
55
|
+
global _config_cache, _crosswalk_cache
|
|
56
|
+
|
|
57
|
+
if _config_cache is None or _crosswalk_cache is None:
|
|
58
|
+
_config_cache, _crosswalk_cache = MediLink_ConfigLoader.load_configuration()
|
|
59
|
+
|
|
60
|
+
return _config_cache, _crosswalk_cache
|
|
61
|
+
|
|
47
62
|
def open_csv_for_editing(csv_file_path):
|
|
48
63
|
try:
|
|
49
64
|
# Open the CSV file with its associated application
|
|
@@ -105,13 +120,18 @@ def load_csv_data(csv_file_path):
|
|
|
105
120
|
# Clean the headers
|
|
106
121
|
cleaned_headers = clean_header(reader.fieldnames)
|
|
107
122
|
|
|
108
|
-
# Create a mapping of cleaned headers to original headers
|
|
123
|
+
# Create a mapping of cleaned headers to original headers (pre-compute once)
|
|
109
124
|
header_mapping = {cleaned_headers[i]: reader.fieldnames[i] for i in range(len(cleaned_headers))}
|
|
110
125
|
|
|
111
|
-
# Process the remaining rows
|
|
126
|
+
# Process the remaining rows - optimize by pre-allocating the list
|
|
112
127
|
csv_data = []
|
|
128
|
+
# Pre-allocate list size if we can estimate it (optional optimization)
|
|
129
|
+
# csv_data = [None] * estimated_size # if we had row count
|
|
130
|
+
|
|
113
131
|
for row in reader:
|
|
114
|
-
|
|
132
|
+
# Use dict() constructor with generator expression for better performance
|
|
133
|
+
cleaned_row = dict((cleaned_headers[i], row[header_mapping[cleaned_headers[i]]])
|
|
134
|
+
for i in range(len(cleaned_headers)))
|
|
115
135
|
csv_data.append(cleaned_row)
|
|
116
136
|
|
|
117
137
|
return csv_data # Return a list of dictionaries
|
|
@@ -205,12 +225,20 @@ def combine_fields(csv_data):
|
|
|
205
225
|
|
|
206
226
|
def apply_replacements(csv_data, crosswalk):
|
|
207
227
|
replacements = crosswalk.get('csv_replacements', {})
|
|
228
|
+
# Pre-define the keys to check for better performance
|
|
229
|
+
keys_to_check = ['Patient SSN', 'Primary Insurance', 'Ins1 Payer ID']
|
|
230
|
+
|
|
208
231
|
for row in csv_data:
|
|
232
|
+
# Use early termination - check each replacement only if needed
|
|
209
233
|
for old_value, new_value in replacements.items():
|
|
210
|
-
|
|
234
|
+
replacement_made = False
|
|
235
|
+
for key in keys_to_check:
|
|
211
236
|
if row.get(key) == old_value:
|
|
212
237
|
row[key] = new_value
|
|
213
|
-
|
|
238
|
+
replacement_made = True
|
|
239
|
+
break # Exit the key loop once a replacement is made
|
|
240
|
+
if replacement_made:
|
|
241
|
+
break # Exit the replacement loop once any replacement is made
|
|
214
242
|
|
|
215
243
|
import difflib
|
|
216
244
|
from collections import defaultdict
|
|
@@ -230,12 +258,15 @@ def find_best_medisoft_id(insurance_name, medisoft_ids, medisoft_to_mains_names)
|
|
|
230
258
|
best_match_ratio = 0
|
|
231
259
|
best_medisoft_id = None
|
|
232
260
|
|
|
261
|
+
# Pre-process insurance name once
|
|
262
|
+
processed_insurance = ''.join(c for c in insurance_name if not c.isdigit()).upper()
|
|
263
|
+
|
|
233
264
|
for medisoft_id in medisoft_ids:
|
|
234
265
|
mains_names = medisoft_to_mains_names.get(medisoft_id, [])
|
|
235
266
|
for mains_name in mains_names:
|
|
236
267
|
# Preprocess names by extracting non-numeric characters and converting to uppercase
|
|
237
|
-
|
|
238
|
-
|
|
268
|
+
# Use more efficient string processing
|
|
269
|
+
processed_mains = ''.join(c for c in mains_name if not c.isdigit()).upper()
|
|
239
270
|
|
|
240
271
|
# Log the processed names before computing the match ratio
|
|
241
272
|
MediLink_ConfigLoader.log("Processing Medisoft ID '{}': Comparing processed insurance '{}' with processed mains '{}'.".format(medisoft_id, processed_insurance, processed_mains), level="DEBUG")
|
|
@@ -414,8 +445,8 @@ def update_procedure_codes(csv_data, crosswalk):
|
|
|
414
445
|
|
|
415
446
|
def update_diagnosis_codes(csv_data):
|
|
416
447
|
try:
|
|
417
|
-
#
|
|
418
|
-
config, crosswalk =
|
|
448
|
+
# Use cached configuration instead of loading repeatedly
|
|
449
|
+
config, crosswalk = get_cached_configuration()
|
|
419
450
|
|
|
420
451
|
# Extract the local storage path from the configuration
|
|
421
452
|
local_storage_path = config['MediLink_Config']['local_storage_path']
|
|
@@ -449,17 +480,23 @@ def update_diagnosis_codes(csv_data):
|
|
|
449
480
|
MediLink_ConfigLoader.log("BAD IDEA: Processing DOCX files modified between {} and {}.".format(threshold_start, threshold_end), level="INFO")
|
|
450
481
|
|
|
451
482
|
# Gather all relevant DOCX files in the specified directory
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
483
|
+
# Optimize by combining file gathering and filtering in one pass
|
|
484
|
+
valid_files = []
|
|
485
|
+
try:
|
|
486
|
+
for filename in os.listdir(local_storage_path):
|
|
487
|
+
if filename.endswith(".docx"):
|
|
488
|
+
filepath = os.path.join(local_storage_path, filename)
|
|
489
|
+
# Check modification time only once per file
|
|
490
|
+
try:
|
|
491
|
+
mtime = os.path.getmtime(filepath)
|
|
492
|
+
if threshold_start <= datetime.fromtimestamp(mtime) <= threshold_end:
|
|
493
|
+
valid_files.append(filepath)
|
|
494
|
+
except (OSError, ValueError):
|
|
495
|
+
# Skip files with invalid modification times
|
|
496
|
+
continue
|
|
497
|
+
except OSError:
|
|
498
|
+
MediLink_ConfigLoader.log("Error accessing directory: {}".format(local_storage_path), level="ERROR")
|
|
499
|
+
return
|
|
463
500
|
|
|
464
501
|
# Process valid DOCX files
|
|
465
502
|
for filepath in valid_files:
|
|
@@ -583,8 +620,8 @@ def load_insurance_data_from_mains(config):
|
|
|
583
620
|
Returns:
|
|
584
621
|
dict: A dictionary mapping insurance names to insurance IDs.
|
|
585
622
|
"""
|
|
586
|
-
#
|
|
587
|
-
config, crosswalk =
|
|
623
|
+
# Use cached configuration to avoid repeated loading
|
|
624
|
+
config, crosswalk = get_cached_configuration()
|
|
588
625
|
|
|
589
626
|
# Retrieve MAINS path and slicing information from the configuration
|
|
590
627
|
# TODO (Low) For secondary insurance, this needs to be pulling from the correct MAINS (there are 2)
|
|
@@ -56,23 +56,26 @@ project_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
|
|
|
56
56
|
if project_dir not in sys.path:
|
|
57
57
|
sys.path.append(project_dir)
|
|
58
58
|
|
|
59
|
-
#
|
|
59
|
+
# Safe import for utility functions - works in multiple contexts
|
|
60
60
|
try:
|
|
61
61
|
from .MediLink_837p_utilities import convert_date_format
|
|
62
|
-
except ImportError
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
62
|
+
except (ImportError, SystemError):
|
|
63
|
+
try:
|
|
64
|
+
from MediLink_837p_utilities import convert_date_format
|
|
65
|
+
except ImportError as e:
|
|
66
|
+
# Fallback implementation for convert_date_format if utilities module is not available
|
|
67
|
+
MediLink_ConfigLoader.log("Warning: Could not import utilities functions: {}".format(e), level="WARNING")
|
|
68
|
+
def convert_date_format(date_str):
|
|
69
|
+
"""Fallback date format conversion function"""
|
|
70
|
+
try:
|
|
71
|
+
# Parse the input date string into a datetime object
|
|
72
|
+
input_format = "%m-%d-%Y" if len(date_str) == 10 else "%m-%d-%y"
|
|
73
|
+
date_obj = datetime.strptime(date_str, input_format)
|
|
74
|
+
# Format the datetime object into the desired output format
|
|
75
|
+
return date_obj.strftime("%Y%m%d")
|
|
76
|
+
except (ValueError, TypeError):
|
|
77
|
+
# Return original string if conversion fails
|
|
78
|
+
return date_str
|
|
76
79
|
|
|
77
80
|
def create_2320_other_subscriber_segments(patient_data, config, crosswalk):
|
|
78
81
|
"""
|
|
@@ -1,9 +1,33 @@
|
|
|
1
1
|
# MediLink_837p_encoder.py
|
|
2
2
|
import re, argparse, os
|
|
3
3
|
from datetime import datetime
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
|
|
5
|
+
# Safe import for ConfigLoader - works in multiple contexts
|
|
6
|
+
try:
|
|
7
|
+
from . import MediLink_ConfigLoader
|
|
8
|
+
except (ImportError, SystemError):
|
|
9
|
+
try:
|
|
10
|
+
import MediLink_ConfigLoader
|
|
11
|
+
except ImportError:
|
|
12
|
+
from MediLink import MediLink_ConfigLoader
|
|
13
|
+
|
|
14
|
+
# Safe import for DataMgmt functions - works in multiple contexts
|
|
15
|
+
try:
|
|
16
|
+
from .MediLink_DataMgmt import parse_fixed_width_data, read_fixed_width_data
|
|
17
|
+
except (ImportError, SystemError):
|
|
18
|
+
try:
|
|
19
|
+
from MediLink_DataMgmt import parse_fixed_width_data, read_fixed_width_data
|
|
20
|
+
except ImportError:
|
|
21
|
+
from MediLink.MediLink_DataMgmt import parse_fixed_width_data, read_fixed_width_data
|
|
22
|
+
|
|
23
|
+
# Safe import for encoder library - works in multiple contexts
|
|
24
|
+
try:
|
|
25
|
+
from . import MediLink_837p_encoder_library
|
|
26
|
+
except (ImportError, SystemError):
|
|
27
|
+
try:
|
|
28
|
+
import MediLink_837p_encoder_library
|
|
29
|
+
except ImportError:
|
|
30
|
+
from MediLink import MediLink_837p_encoder_library
|
|
7
31
|
# TODO (COB ENHANCEMENT): Import COB library when implementing Medicare and secondary claim support
|
|
8
32
|
# import MediLink_837p_cob_library
|
|
9
33
|
#from tqdm import tqdm
|
|
@@ -10,20 +10,54 @@ if project_dir not in sys.path:
|
|
|
10
10
|
from MediBot import MediBot_Preprocessor_lib
|
|
11
11
|
load_insurance_data_from_mains = MediBot_Preprocessor_lib.load_insurance_data_from_mains
|
|
12
12
|
from MediBot import MediBot_Crosswalk_Library
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
from .
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
13
|
+
|
|
14
|
+
# Safe import for API functions - works in multiple contexts
|
|
15
|
+
try:
|
|
16
|
+
from .MediLink_API_v3 import fetch_payer_name_from_api
|
|
17
|
+
except (ImportError, SystemError):
|
|
18
|
+
try:
|
|
19
|
+
from MediLink_API_v3 import fetch_payer_name_from_api
|
|
20
|
+
except ImportError:
|
|
21
|
+
import MediLink_API_v3
|
|
22
|
+
fetch_payer_name_from_api = MediLink_API_v3.fetch_payer_name_from_api
|
|
23
|
+
|
|
24
|
+
# Safe import for utility functions - works in multiple contexts
|
|
25
|
+
try:
|
|
26
|
+
from .MediLink_837p_utilities import (
|
|
27
|
+
convert_date_format,
|
|
28
|
+
format_datetime,
|
|
29
|
+
get_user_confirmation,
|
|
30
|
+
prompt_user_for_payer_id,
|
|
31
|
+
format_claim_number,
|
|
32
|
+
generate_segment_counts,
|
|
33
|
+
handle_validation_errors,
|
|
34
|
+
get_output_directory,
|
|
35
|
+
winscp_validate_output_directory
|
|
36
|
+
)
|
|
37
|
+
except (ImportError, SystemError):
|
|
38
|
+
try:
|
|
39
|
+
from MediLink_837p_utilities import (
|
|
40
|
+
convert_date_format,
|
|
41
|
+
format_datetime,
|
|
42
|
+
get_user_confirmation,
|
|
43
|
+
prompt_user_for_payer_id,
|
|
44
|
+
format_claim_number,
|
|
45
|
+
generate_segment_counts,
|
|
46
|
+
handle_validation_errors,
|
|
47
|
+
get_output_directory,
|
|
48
|
+
winscp_validate_output_directory
|
|
49
|
+
)
|
|
50
|
+
except ImportError:
|
|
51
|
+
import MediLink_837p_utilities
|
|
52
|
+
convert_date_format = MediLink_837p_utilities.convert_date_format
|
|
53
|
+
format_datetime = MediLink_837p_utilities.format_datetime
|
|
54
|
+
get_user_confirmation = MediLink_837p_utilities.get_user_confirmation
|
|
55
|
+
prompt_user_for_payer_id = MediLink_837p_utilities.prompt_user_for_payer_id
|
|
56
|
+
format_claim_number = MediLink_837p_utilities.format_claim_number
|
|
57
|
+
generate_segment_counts = MediLink_837p_utilities.generate_segment_counts
|
|
58
|
+
handle_validation_errors = MediLink_837p_utilities.handle_validation_errors
|
|
59
|
+
get_output_directory = MediLink_837p_utilities.get_output_directory
|
|
60
|
+
winscp_validate_output_directory = MediLink_837p_utilities.winscp_validate_output_directory
|
|
27
61
|
|
|
28
62
|
|
|
29
63
|
|
|
@@ -88,11 +88,16 @@ def read_fixed_width_data(file_path):
|
|
|
88
88
|
# TODO (Refactor) Consider consolidating with the other read_fixed_with_data
|
|
89
89
|
def read_general_fixed_width_data(file_path, slices):
|
|
90
90
|
# handle any fixed-width data based on provided slice definitions
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
91
|
+
try:
|
|
92
|
+
with open(file_path, 'r', encoding='utf-8') as file:
|
|
93
|
+
next(file) # Skip the header
|
|
94
|
+
for line_number, line in enumerate(file, start=1):
|
|
95
|
+
insurance_name = {key: line[start:end].strip() for key, (start, end) in slices.items()}
|
|
96
|
+
yield insurance_name, line_number
|
|
97
|
+
except FileNotFoundError:
|
|
98
|
+
print("File not found: {}".format(file_path))
|
|
99
|
+
MediLink_ConfigLoader.log("File not found: {}".format(file_path), level="ERROR")
|
|
100
|
+
return
|
|
96
101
|
|
|
97
102
|
def consolidate_csvs(source_directory, file_prefix="Consolidated", interactive=False):
|
|
98
103
|
"""
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|