medicafe 0.240716.2__tar.gz → 0.240809.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.240716.2 → medicafe-0.240809.0}/MediBot/MediBot.py +13 -2
- {medicafe-0.240716.2 → medicafe-0.240809.0}/MediBot/MediBot_Preprocessor_lib.py +14 -2
- {medicafe-0.240716.2 → medicafe-0.240809.0}/MediLink/MediLink.py +4 -4
- {medicafe-0.240716.2 → medicafe-0.240809.0}/MediLink/MediLink_837p_encoder.py +64 -47
- {medicafe-0.240716.2 → medicafe-0.240809.0}/MediLink/MediLink_837p_encoder_library.py +20 -8
- {medicafe-0.240716.2 → medicafe-0.240809.0}/MediLink/MediLink_API_v3.py +109 -5
- {medicafe-0.240716.2 → medicafe-0.240809.0}/MediLink/MediLink_ConfigLoader.py +1 -1
- {medicafe-0.240716.2 → medicafe-0.240809.0}/MediLink/MediLink_DataMgmt.py +4 -4
- {medicafe-0.240716.2 → medicafe-0.240809.0}/MediLink/MediLink_Deductible.py +57 -50
- {medicafe-0.240716.2 → medicafe-0.240809.0}/MediLink/MediLink_Down.py +29 -30
- {medicafe-0.240716.2 → medicafe-0.240809.0}/MediLink/MediLink_UI.py +9 -1
- {medicafe-0.240716.2 → medicafe-0.240809.0}/MediLink/MediLink_Up.py +179 -110
- {medicafe-0.240716.2/medicafe.egg-info → medicafe-0.240809.0}/PKG-INFO +1 -1
- {medicafe-0.240716.2 → medicafe-0.240809.0/medicafe.egg-info}/PKG-INFO +1 -1
- {medicafe-0.240716.2 → medicafe-0.240809.0}/setup.py +1 -1
- {medicafe-0.240716.2 → medicafe-0.240809.0}/LICENSE +0 -0
- {medicafe-0.240716.2 → medicafe-0.240809.0}/MANIFEST.in +0 -0
- {medicafe-0.240716.2 → medicafe-0.240809.0}/MediBot/MediBot.bat +0 -0
- {medicafe-0.240716.2 → medicafe-0.240809.0}/MediBot/MediBot_Charges.py +0 -0
- {medicafe-0.240716.2 → medicafe-0.240809.0}/MediBot/MediBot_Crosswalk_Library.py +0 -0
- {medicafe-0.240716.2 → medicafe-0.240809.0}/MediBot/MediBot_Post.py +0 -0
- {medicafe-0.240716.2 → medicafe-0.240809.0}/MediBot/MediBot_Preprocessor.py +0 -0
- {medicafe-0.240716.2 → medicafe-0.240809.0}/MediBot/MediBot_UI.py +0 -0
- {medicafe-0.240716.2 → medicafe-0.240809.0}/MediBot/MediBot_dataformat_library.py +0 -0
- {medicafe-0.240716.2 → medicafe-0.240809.0}/MediBot/MediBot_docx_decoder.py +0 -0
- {medicafe-0.240716.2 → medicafe-0.240809.0}/MediBot/PDF_to_CSV_Cleaner.py +0 -0
- {medicafe-0.240716.2 → medicafe-0.240809.0}/MediBot/__init__.py +0 -0
- {medicafe-0.240716.2 → medicafe-0.240809.0}/MediBot/update_json.py +0 -0
- {medicafe-0.240716.2 → medicafe-0.240809.0}/MediBot/update_medicafe.py +0 -0
- {medicafe-0.240716.2 → medicafe-0.240809.0}/MediLink/MediLink_API_Generator.py +0 -0
- {medicafe-0.240716.2 → medicafe-0.240809.0}/MediLink/MediLink_API_v2.py +0 -0
- {medicafe-0.240716.2 → medicafe-0.240809.0}/MediLink/MediLink_APIs.py +0 -0
- {medicafe-0.240716.2 → medicafe-0.240809.0}/MediLink/MediLink_ClaimStatus.py +0 -0
- {medicafe-0.240716.2 → medicafe-0.240809.0}/MediLink/MediLink_Decoder.py +0 -0
- {medicafe-0.240716.2 → medicafe-0.240809.0}/MediLink/MediLink_Gmail.py +0 -0
- {medicafe-0.240716.2 → medicafe-0.240809.0}/MediLink/MediLink_Mailer.py +0 -0
- {medicafe-0.240716.2 → medicafe-0.240809.0}/MediLink/MediLink_Parser.py +0 -0
- {medicafe-0.240716.2 → medicafe-0.240809.0}/MediLink/MediLink_Scan.py +0 -0
- {medicafe-0.240716.2 → medicafe-0.240809.0}/MediLink/MediLink_Scheduler.py +0 -0
- {medicafe-0.240716.2 → medicafe-0.240809.0}/MediLink/MediLink_batch.bat +0 -0
- {medicafe-0.240716.2 → medicafe-0.240809.0}/MediLink/Soumit_api.py +0 -0
- {medicafe-0.240716.2 → medicafe-0.240809.0}/MediLink/__init__.py +0 -0
- {medicafe-0.240716.2 → medicafe-0.240809.0}/MediLink/test.py +0 -0
- {medicafe-0.240716.2 → medicafe-0.240809.0}/README.md +0 -0
- {medicafe-0.240716.2 → medicafe-0.240809.0}/medicafe.egg-info/SOURCES.txt +0 -0
- {medicafe-0.240716.2 → medicafe-0.240809.0}/medicafe.egg-info/dependency_links.txt +0 -0
- {medicafe-0.240716.2 → medicafe-0.240809.0}/medicafe.egg-info/not-zip-safe +0 -0
- {medicafe-0.240716.2 → medicafe-0.240809.0}/medicafe.egg-info/requires.txt +0 -0
- {medicafe-0.240716.2 → medicafe-0.240809.0}/medicafe.egg-info/top_level.txt +0 -0
- {medicafe-0.240716.2 → medicafe-0.240809.0}/setup.cfg +0 -0
|
@@ -262,10 +262,21 @@ if __name__ == "__main__":
|
|
|
262
262
|
print("\nNOTE: The following patient(s) already EXIST in the system and \n will be excluded from processing:")
|
|
263
263
|
# TODO ... not excluded anymore, because charges may need to be added.
|
|
264
264
|
# So at this point in the processing, we should have already processed the surgery schedules and enriched the data with Charges.
|
|
265
|
+
# Find the corresponding rows in csv_data to get the surgery dates and store them along with patient info
|
|
266
|
+
patient_info = []
|
|
265
267
|
for patient_id, patient_name in existing_patients:
|
|
266
|
-
|
|
268
|
+
surgery_date = next((row.get('Surgery Date', 'Unknown Date') for row in csv_data if row.get(reverse_mapping['Patient ID #2']) == patient_id), 'Unknown Date')
|
|
269
|
+
patient_info.append((surgery_date, patient_name, patient_id))
|
|
270
|
+
|
|
271
|
+
# Sort by surgery date first and then by patient name
|
|
272
|
+
patient_info.sort(key=lambda x: (x[0], x[1]))
|
|
273
|
+
|
|
274
|
+
# Print the sorted patient info
|
|
275
|
+
for index, (surgery_date, patient_name, patient_id) in enumerate(patient_info):
|
|
276
|
+
print("{0:03d}: {3:%m-%d} (ID: {2}) {1} ".format(index + 1, patient_name, patient_id, surgery_date))
|
|
277
|
+
|
|
267
278
|
# Update csv_data to exclude existing patients
|
|
268
|
-
# TODO This now has to be updated to handle patients that exist but need new charges added.
|
|
279
|
+
# TODO This now has to be updated to handle patients that exist but need new charges added.
|
|
269
280
|
csv_data = [row for row in csv_data if row[reverse_mapping['Patient ID #2']] in patients_to_process]
|
|
270
281
|
else:
|
|
271
282
|
print("\nSelected patient(s) are NEW patients and will be processed.")
|
|
@@ -124,7 +124,8 @@ def sort_and_deduplicate(csv_data):
|
|
|
124
124
|
if patient_id not in unique_patients or row['Surgery Date'] < unique_patients[patient_id]['Surgery Date']:
|
|
125
125
|
unique_patients[patient_id] = row
|
|
126
126
|
csv_data[:] = list(unique_patients.values())
|
|
127
|
-
# TODO Sorting, now that we're going to have the Surgery Schedules available, should
|
|
127
|
+
# TODO Sorting, now that we're going to have the Surgery Schedules available, should (or shouldn't??
|
|
128
|
+
# maybe we should build in the option as liek a 'setting' in the config) be ordered as the patients show up on the schedule.
|
|
128
129
|
# If we don't have that surgery schedule yet for some reason, we should default to the current ordering strategy.
|
|
129
130
|
csv_data.sort(key=lambda x: (x['Surgery Date'], x.get('Patient Last', '').strip()))
|
|
130
131
|
|
|
@@ -161,7 +162,16 @@ def update_insurance_ids(csv_data, crosswalk):
|
|
|
161
162
|
medisoft_ids = crosswalk['payer_id'][ins1_payer_id].get('medisoft_id', [])
|
|
162
163
|
if medisoft_ids:
|
|
163
164
|
medisoft_ids = [int(id) for id in medisoft_ids]
|
|
164
|
-
# TODO Try to match OpenPM's Insurance Name to get a better match
|
|
165
|
+
# TODO Try to match OpenPM's Insurance Name to get a better match.
|
|
166
|
+
# Potential approach:
|
|
167
|
+
# 1. Retrieve the insurance name from the current row
|
|
168
|
+
# insurance_name = row.get('Primary Insurnace', '').strip()
|
|
169
|
+
# 2. Check if the insurance name exists in the subset of MAINS names associated with
|
|
170
|
+
# crosswalk medisoft ID values for the given payer ID.
|
|
171
|
+
# 3. If an approximate match is found above a certain confidence, use the corresponding medisoft_id.
|
|
172
|
+
# else: 4. If no match is found, default to the first medisoft_id
|
|
173
|
+
# row['Ins1 Insurance ID'] = medisoft_ids[0]
|
|
174
|
+
|
|
165
175
|
row['Ins1 Insurance ID'] = medisoft_ids[0]
|
|
166
176
|
# MediLink_ConfigLoader.log("Ins1 Insurance ID '{}' used for Payer ID {} in crosswalk.".format(row.get('Ins1 Insurance ID', ''), ins1_payer_id))
|
|
167
177
|
else:
|
|
@@ -367,6 +377,8 @@ def load_insurance_data_from_mains(config):
|
|
|
367
377
|
# Retrieve MAINS path and slicing information from the configuration
|
|
368
378
|
# TODO (Low) For secondary insurance, this needs to be pulling from the correct MAINS (there are 2)
|
|
369
379
|
# TODO (Low) Performance: There probably needs to be a dictionary proxy for MAINS that gets updated.
|
|
380
|
+
# Meh, this just has to be part of the new architecture plan where we make Medisoft a downstream
|
|
381
|
+
# recipient from the db.
|
|
370
382
|
mains_path = config['MAINS_MED_PATH']
|
|
371
383
|
mains_slices = crosswalk['mains_mapping']['slices']
|
|
372
384
|
|
|
@@ -58,7 +58,7 @@ def enrich_with_insurance_type(detailed_patient_data, patient_insurance_type_map
|
|
|
58
58
|
TODO: Implement a function to provide `patient_insurance_mapping` from a reliable source.
|
|
59
59
|
"""
|
|
60
60
|
if patient_insurance_type_mapping is None:
|
|
61
|
-
MediLink_ConfigLoader.log("No Patient:Insurance-Type mapping available.")
|
|
61
|
+
MediLink_ConfigLoader.log("No Patient:Insurance-Type mapping available.", level="WARNING")
|
|
62
62
|
patient_insurance_type_mapping = {}
|
|
63
63
|
|
|
64
64
|
for data in detailed_patient_data:
|
|
@@ -86,7 +86,7 @@ def extract_and_suggest_endpoint(file_path, config, crosswalk):
|
|
|
86
86
|
|
|
87
87
|
# Load insurance data from MAINS to create a mapping from insurance names to their respective IDs
|
|
88
88
|
insurance_to_id = load_insurance_data_from_mains(config)
|
|
89
|
-
MediLink_ConfigLoader.log("Insurance data loaded from MAINS. {} insurance providers found.".format(len(insurance_to_id)))
|
|
89
|
+
MediLink_ConfigLoader.log("Insurance data loaded from MAINS. {} insurance providers found.".format(len(insurance_to_id)), level="INFO")
|
|
90
90
|
|
|
91
91
|
for personal_info, insurance_info, service_info, service_info_2, service_info_3 in MediLink_DataMgmt.read_fixed_width_data(file_path):
|
|
92
92
|
parsed_data = MediLink_DataMgmt.parse_fixed_width_data(personal_info, insurance_info, service_info, service_info_2, service_info_3, config.get('MediLink_Config', config))
|
|
@@ -148,13 +148,13 @@ def check_for_new_remittances(config):
|
|
|
148
148
|
try:
|
|
149
149
|
ERA_path = MediLink_Down.main(desired_endpoint=endpoint_key)
|
|
150
150
|
processed_endpoints.append((endpoint_info['name'], ERA_path))
|
|
151
|
-
MediLink_ConfigLoader.log("Results for {} saved to: {}".format(endpoint_info['name'], ERA_path))
|
|
151
|
+
MediLink_ConfigLoader.log("Results for {} saved to: {}".format(endpoint_info['name'], ERA_path), level="DEBUG")
|
|
152
152
|
# TODO (Low SFTP - Download side) This needs to check to see if this actually worked maybe winscplog before saying it completed successfully
|
|
153
153
|
# Check if there is commonality with the upload side so we can use the same validation function.
|
|
154
154
|
except Exception as e:
|
|
155
155
|
print("An error occurred while checking remittances for {}: {}".format(endpoint_info['name'], e))
|
|
156
156
|
else:
|
|
157
|
-
MediLink_ConfigLoader.log("Skipping endpoint '{}' as it does not have 'remote_directory_down' configured.".format(endpoint_info['name']))
|
|
157
|
+
MediLink_ConfigLoader.log("Skipping endpoint '{}' as it does not have 'remote_directory_down' configured.".format(endpoint_info['name']), level="WARNING")
|
|
158
158
|
else:
|
|
159
159
|
print("Error: Endpoint config is not a 'dictionary' as expected.")
|
|
160
160
|
# Check if all ERA paths are the same
|
|
@@ -77,33 +77,27 @@ def format_single_claim(patient_data, config, endpoint, transaction_set_control_
|
|
|
77
77
|
|
|
78
78
|
return formatted_837p
|
|
79
79
|
|
|
80
|
-
def write_output_file(document_segments, output_directory, endpoint_key, input_file_path, config):
|
|
80
|
+
def write_output_file(document_segments, output_directory, endpoint_key, input_file_path, config, suffix=""):
|
|
81
81
|
"""
|
|
82
82
|
Writes formatted 837P document segments to an output file with a dynamically generated name.
|
|
83
|
-
|
|
84
|
-
Development Roadmap:
|
|
85
|
-
- Ensure input `document_segments` is a non-empty list to avoid creating empty files.
|
|
86
|
-
- Verify `output_directory` exists and is writable before proceeding. Create the directory if it does not exist.
|
|
87
|
-
- Consider parameterizing the file naming convention or providing options for customization to accommodate different organizational needs.
|
|
88
|
-
- Implement error handling to gracefully manage file writing failures, potentially returning a status or error message alongside the file path.
|
|
89
|
-
- Incorporate logging directly within the function, accepting an optional `config` or `logger` parameter to facilitate tracking of the file writing process and outcomes.
|
|
90
|
-
- Update the return value to include both the path to the output file and any relevant status information (e.g., success flag, error message) to enhance downstream error handling and user feedback.
|
|
91
|
-
|
|
83
|
+
|
|
92
84
|
Parameters:
|
|
93
85
|
- document_segments: List of strings, where each string is a segment of the 837P document to be written.
|
|
94
86
|
- output_directory: String specifying the directory where the output file will be saved.
|
|
95
87
|
- endpoint_key: String specifying the endpoint for which the claim is processed, used in naming the output file.
|
|
96
88
|
- input_file_path: String specifying the path to the input file being processed, used in naming the output file.
|
|
97
|
-
|
|
89
|
+
- config: Configuration settings for logging and other purposes.
|
|
90
|
+
- suffix: Optional string to differentiate filenames, useful for single-patient processing.
|
|
91
|
+
|
|
98
92
|
Returns:
|
|
99
|
-
- String specifying the path to the successfully created output file
|
|
93
|
+
- String specifying the path to the successfully created output file, or None if an error occurred.
|
|
100
94
|
"""
|
|
101
|
-
#
|
|
95
|
+
# Ensure the document segments are not empty
|
|
102
96
|
if not document_segments:
|
|
103
97
|
MediLink_ConfigLoader.log("Error: Empty document segments provided. No output file created.", config, level="ERROR")
|
|
104
98
|
return None
|
|
105
99
|
|
|
106
|
-
#
|
|
100
|
+
# Verify the output directory exists and is writable, create if necessary
|
|
107
101
|
if not os.path.exists(output_directory):
|
|
108
102
|
try:
|
|
109
103
|
os.makedirs(output_directory)
|
|
@@ -114,13 +108,13 @@ def write_output_file(document_segments, output_directory, endpoint_key, input_f
|
|
|
114
108
|
MediLink_ConfigLoader.log("Error: Output directory is not writable.", config, level="ERROR")
|
|
115
109
|
return None
|
|
116
110
|
|
|
117
|
-
# Generate new output file path
|
|
111
|
+
# Generate the new output file path
|
|
118
112
|
base_name = os.path.splitext(os.path.basename(input_file_path))[0]
|
|
119
113
|
timestamp = datetime.now().strftime("%m%d%H%M")
|
|
120
|
-
new_output_file_name = "{}_{}_{}.txt".format(base_name, endpoint_key.lower(), timestamp)
|
|
114
|
+
new_output_file_name = "{}_{}_{}{}.txt".format(base_name, endpoint_key.lower(), timestamp, suffix)
|
|
121
115
|
new_output_file_path = os.path.join(output_directory, new_output_file_name)
|
|
122
116
|
|
|
123
|
-
# Write
|
|
117
|
+
# Write the document to the output file
|
|
124
118
|
try:
|
|
125
119
|
with open(new_output_file_path, 'w') as output_file:
|
|
126
120
|
output_file.write('\n'.join(document_segments))
|
|
@@ -335,7 +329,7 @@ def main():
|
|
|
335
329
|
parser.add_argument(
|
|
336
330
|
"-e", "--endpoint",
|
|
337
331
|
required=True,
|
|
338
|
-
choices=["AVAILITY", "OPTUMEDI", "PNT_DATA"],
|
|
332
|
+
choices=["AVAILITY", "OPTUMEDI", "PNT_DATA", "UHCAPI"],
|
|
339
333
|
help="Specify the endpoint for which the conversion is intended."
|
|
340
334
|
)
|
|
341
335
|
parser.add_argument(
|
|
@@ -388,9 +382,9 @@ if __name__ == "__main__":
|
|
|
388
382
|
#######################################################################################
|
|
389
383
|
|
|
390
384
|
def convert_files_for_submission(detailed_patient_data, config):
|
|
391
|
-
"""
|
|
385
|
+
"""
|
|
392
386
|
Processes detailed patient data for submission based on their confirmed endpoints,
|
|
393
|
-
generating
|
|
387
|
+
generating separate 837P files for each endpoint according to the configured submission type.
|
|
394
388
|
|
|
395
389
|
Parameters:
|
|
396
390
|
- detailed_patient_data: A list containing detailed patient data with endpoint information.
|
|
@@ -398,73 +392,93 @@ def convert_files_for_submission(detailed_patient_data, config):
|
|
|
398
392
|
|
|
399
393
|
Returns:
|
|
400
394
|
- A list of paths to the converted files ready for submission.
|
|
395
|
+
|
|
396
|
+
Note:
|
|
397
|
+
- This function currently supports batch and single-patient submissions based on the configuration.
|
|
398
|
+
- Future implementation may include progress tracking using tools like `tqdm`.
|
|
401
399
|
"""
|
|
402
400
|
|
|
403
401
|
# Initialize a dictionary to hold patient data segregated by confirmed endpoints
|
|
404
402
|
data_by_endpoint = {}
|
|
405
|
-
|
|
406
|
-
#
|
|
403
|
+
|
|
404
|
+
# Group patient data by endpoint
|
|
407
405
|
for data in detailed_patient_data:
|
|
408
|
-
endpoint = data
|
|
409
|
-
if endpoint
|
|
410
|
-
|
|
411
|
-
|
|
406
|
+
endpoint = data.get('confirmed_endpoint')
|
|
407
|
+
if endpoint:
|
|
408
|
+
if endpoint not in data_by_endpoint:
|
|
409
|
+
data_by_endpoint[endpoint] = []
|
|
410
|
+
data_by_endpoint[endpoint].append(data)
|
|
412
411
|
|
|
413
412
|
# List to store paths of converted files for each endpoint
|
|
414
413
|
converted_files_paths = []
|
|
415
414
|
|
|
416
|
-
# Determine the total number of unique endpoints for progress bar
|
|
417
|
-
# total_endpoints = len(data_by_endpoint)
|
|
418
|
-
|
|
419
415
|
# Iterate over each endpoint and process its corresponding patient data
|
|
420
416
|
for endpoint, patient_data_list in data_by_endpoint.items():
|
|
421
|
-
#
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
417
|
+
# Retrieve submission type from config; default to "batch" if not specified
|
|
418
|
+
submission_type = config.get('MediLink_Config', {}).get('endpoints', {}).get(endpoint, {}).get('submission_type', 'batch')
|
|
419
|
+
|
|
420
|
+
if submission_type == 'single':
|
|
421
|
+
# Process each patient's data individually for single-patient submissions
|
|
422
|
+
for patient_data in patient_data_list:
|
|
423
|
+
# Generate a unique suffix for each patient, e.g., using a truncated chart number
|
|
424
|
+
chart_number = patient_data.get('CHART', 'UNKNOWN')#[:5] truncation might cause collisions.
|
|
425
|
+
suffix = "_{}".format(chart_number)
|
|
426
|
+
# Process and convert each patient's data to a separate file
|
|
427
|
+
converted_path = process_claim(config, endpoint, [patient_data], suffix)
|
|
428
|
+
if converted_path:
|
|
429
|
+
converted_files_paths.append(converted_path)
|
|
430
|
+
else:
|
|
431
|
+
# Process all patient data together for batch submissions
|
|
432
|
+
converted_path = process_claim(config, endpoint, patient_data_list)
|
|
425
433
|
if converted_path:
|
|
426
434
|
converted_files_paths.append(converted_path)
|
|
427
|
-
|
|
435
|
+
|
|
428
436
|
return converted_files_paths
|
|
429
437
|
|
|
430
|
-
def process_claim(config, endpoint, patient_data_list):
|
|
438
|
+
def process_claim(config, endpoint, patient_data_list, suffix=""):
|
|
431
439
|
"""
|
|
432
440
|
Processes patient data for a specified endpoint, converting it into the 837P format.
|
|
433
|
-
|
|
441
|
+
Can handle both batch and single-patient submissions.
|
|
434
442
|
|
|
435
443
|
Parameters:
|
|
436
444
|
- config: Configuration settings loaded from a JSON file.
|
|
437
|
-
-
|
|
445
|
+
- endpoint: The key representing the endpoint for which the data is being processed.
|
|
438
446
|
- patient_data_list: A list of dictionaries, each containing detailed patient data.
|
|
447
|
+
- suffix: An optional suffix to differentiate filenames for single-patient processing.
|
|
439
448
|
|
|
440
449
|
Returns:
|
|
441
450
|
- Path to the converted file, or None if an error occurs.
|
|
442
|
-
|
|
443
|
-
TODO (LOW) Why are there duplicated interchange flows? Because the arg if we're doing a .dat directory or not.
|
|
444
|
-
Although, that shouldn't be making duplicates of these interchange headers. That's still confusing and could end up making
|
|
445
|
-
duplicate interchange headers because processing .dat in batch might be fast enough to be a problem.
|
|
446
451
|
"""
|
|
452
|
+
# Ensure we're accessing the correct configuration key
|
|
453
|
+
config = config.get('MediLink_Config', config)
|
|
454
|
+
|
|
455
|
+
# Retrieve the output directory from the configuration
|
|
447
456
|
output_directory = MediLink_837p_encoder_library.get_output_directory(config)
|
|
448
457
|
if not output_directory:
|
|
449
458
|
return None
|
|
450
459
|
|
|
451
|
-
# Initialize the transaction set control number and document segments
|
|
452
460
|
transaction_set_control_number = 1
|
|
453
461
|
document_segments = []
|
|
454
462
|
|
|
455
|
-
# Process each patient's data in the list
|
|
456
463
|
for patient_data in patient_data_list:
|
|
457
|
-
# Validate each patient's data
|
|
464
|
+
# Validate each patient's data before processing
|
|
458
465
|
is_valid, validation_errors = validate_claim_data(patient_data, config)
|
|
459
466
|
if is_valid:
|
|
460
|
-
# Format the claim
|
|
467
|
+
# Format the claim into 837P segments
|
|
461
468
|
formatted_claim = format_single_claim(patient_data, config, endpoint, transaction_set_control_number)
|
|
462
469
|
document_segments.append(formatted_claim)
|
|
463
470
|
transaction_set_control_number += 1
|
|
464
471
|
else:
|
|
472
|
+
# Log any validation errors encountered
|
|
473
|
+
MediLink_ConfigLoader.log("Validation errors for patient data: {}".format(validation_errors), config, level="ERROR")
|
|
465
474
|
if MediLink_837p_encoder_library.handle_validation_errors(transaction_set_control_number, validation_errors, config):
|
|
466
475
|
continue # Skip the current patient
|
|
467
476
|
|
|
477
|
+
if not document_segments:
|
|
478
|
+
# If no valid segments were created, log the issue and return None
|
|
479
|
+
MediLink_ConfigLoader.log("No valid document segments created.", config, level="ERROR")
|
|
480
|
+
return None
|
|
481
|
+
|
|
468
482
|
# Create interchange elements with the final transaction set control number
|
|
469
483
|
isa_header, gs_header, ge_trailer, iea_trailer = MediLink_837p_encoder_library.create_interchange_elements(config, endpoint, transaction_set_control_number - 1)
|
|
470
484
|
|
|
@@ -473,5 +487,8 @@ def process_claim(config, endpoint, patient_data_list):
|
|
|
473
487
|
document_segments.insert(0, isa_header)
|
|
474
488
|
document_segments.extend([ge_trailer, iea_trailer])
|
|
475
489
|
|
|
476
|
-
#
|
|
477
|
-
|
|
490
|
+
# Use the first patient's file path as a reference for output file naming
|
|
491
|
+
input_file_path = patient_data_list[0].get('file_path', 'UNKNOWN')
|
|
492
|
+
# Write the complete 837P document to an output file
|
|
493
|
+
converted_file_path = write_output_file(document_segments, output_directory, endpoint, input_file_path, config, suffix)
|
|
494
|
+
return converted_file_path
|
|
@@ -288,7 +288,7 @@ def resolve_payer_name(payer_id, config, primary_endpoint, insurance_name, parse
|
|
|
288
288
|
MediLink_ConfigLoader.log("API Resolved to standard insurance name: {} for corrected payer ID: {}".format(resolved_name, corrected_payer_id), config, level="INFO")
|
|
289
289
|
|
|
290
290
|
confirmation = input("Is the standard insurance name '{}' correct? (yes/no): ".format(resolved_name)).strip().lower()
|
|
291
|
-
|
|
291
|
+
# BUG There is duplication of code here.
|
|
292
292
|
if confirmation in ['yes', 'y']:
|
|
293
293
|
if MediBot_Crosswalk_Library.update_crosswalk_with_corrected_payer_id(payer_id, corrected_payer_id):
|
|
294
294
|
return resolved_name
|
|
@@ -309,11 +309,16 @@ def resolve_payer_name(payer_id, config, primary_endpoint, insurance_name, parse
|
|
|
309
309
|
|
|
310
310
|
def prompt_user_for_payer_id(insurance_name):
|
|
311
311
|
"""
|
|
312
|
-
Prompts the user to input the payer ID manually.
|
|
312
|
+
Prompts the user to input the payer ID manually and ensures that a valid ID is provided.
|
|
313
313
|
"""
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
314
|
+
while True:
|
|
315
|
+
print("Manual intervention required: No payer ID found for insurance name '{}'.".format(insurance_name))
|
|
316
|
+
payer_id = input("Please enter the payer ID manually: ").strip()
|
|
317
|
+
|
|
318
|
+
if payer_id:
|
|
319
|
+
return payer_id
|
|
320
|
+
else:
|
|
321
|
+
print("Error: Payer ID cannot be empty. Please try again.")
|
|
317
322
|
|
|
318
323
|
def build_nm1_segment(payer_name, payer_id):
|
|
319
324
|
# Step 1: Build NM1 segment using payer name and ID
|
|
@@ -407,7 +412,7 @@ def handle_missing_payer_id(insurance_name, config):
|
|
|
407
412
|
|
|
408
413
|
# Ask for user confirmation
|
|
409
414
|
confirmation = input("Is the standard insurance name '{}' correct? (yes/no): ".format(standard_insurance_name)).strip().lower() or 'yes'
|
|
410
|
-
|
|
415
|
+
# BUG There is duplication of code here.
|
|
411
416
|
if confirmation in ['yes', 'y']:
|
|
412
417
|
# Update the crosswalk with the new payer ID and insurance name mapping
|
|
413
418
|
MediBot_Crosswalk_Library.update_crosswalk_with_new_payer_id(insurance_name, payer_id, config)
|
|
@@ -847,10 +852,17 @@ def winscp_validate_output_directory(output_directory):
|
|
|
847
852
|
|
|
848
853
|
def get_output_directory(config):
|
|
849
854
|
# Retrieve desired default output file path from config
|
|
850
|
-
output_directory = config.get('outputFilePath', '')
|
|
855
|
+
output_directory = config.get('outputFilePath', '').strip()
|
|
851
856
|
# BUG (Low SFTP) Add WinSCP validation because of the mishandling of spaces in paths. (This shouldn't need to exist.)
|
|
857
|
+
if not output_directory:
|
|
858
|
+
print("Output file path is not specified in the configuration.")
|
|
859
|
+
output_directory = input("Please enter a valid output directory path: ").strip()
|
|
860
|
+
|
|
861
|
+
# Validate the directory path (checks for spaces and existence)
|
|
852
862
|
output_directory = winscp_validate_output_directory(output_directory)
|
|
863
|
+
|
|
853
864
|
if not os.path.isdir(output_directory):
|
|
854
|
-
print("Output directory does not exist. Please check the configuration.")
|
|
865
|
+
print("Output directory does not exist or is not accessible. Please check the configuration.")
|
|
855
866
|
return None
|
|
867
|
+
|
|
856
868
|
return output_directory
|
|
@@ -9,6 +9,14 @@ try:
|
|
|
9
9
|
except ImportError:
|
|
10
10
|
import MediLink_ConfigLoader
|
|
11
11
|
|
|
12
|
+
"""
|
|
13
|
+
TODO At some point it might make sense to test their acknoledgment endpoint. body is transactionId.
|
|
14
|
+
This API is used to extract the claim acknowledgement details for the given transactionid which was
|
|
15
|
+
generated for 837 requests in claim submission process. Claims Acknowledgement (277CA) will provide
|
|
16
|
+
a status of claim-level acknowledgement of all claims received in the front-end processing system and
|
|
17
|
+
adjudication system.
|
|
18
|
+
"""
|
|
19
|
+
|
|
12
20
|
class ConfigLoader:
|
|
13
21
|
@staticmethod
|
|
14
22
|
def load_configuration(config_path=os.path.join(os.path.dirname(__file__), '..', 'json', 'config.json'),
|
|
@@ -175,7 +183,7 @@ def fetch_payer_name_from_api(payer_id, config, primary_endpoint='AVAILITY'):
|
|
|
175
183
|
raise ValueError(error_message)
|
|
176
184
|
|
|
177
185
|
def get_claim_summary_by_provider(client, tin, first_service_date, last_service_date, payer_id, get_standard_error='false'):
|
|
178
|
-
endpoint_name = '
|
|
186
|
+
endpoint_name = 'UHCAPI'
|
|
179
187
|
url_extension = client.config['MediLink_Config']['endpoints'][endpoint_name]['additional_endpoints']['claim_summary_by_provider']
|
|
180
188
|
headers = {
|
|
181
189
|
'tin': tin,
|
|
@@ -188,7 +196,7 @@ def get_claim_summary_by_provider(client, tin, first_service_date, last_service_
|
|
|
188
196
|
return client.make_api_call(endpoint_name, 'GET', url_extension, params=None, data=None, headers=headers)
|
|
189
197
|
|
|
190
198
|
def get_eligibility(client, payer_id, provider_last_name, search_option, date_of_birth, member_id, npi):
|
|
191
|
-
endpoint_name = '
|
|
199
|
+
endpoint_name = 'UHCAPI'
|
|
192
200
|
url_extension = client.config['MediLink_Config']['endpoints'][endpoint_name]['additional_endpoints']['eligibility']
|
|
193
201
|
url_extension = url_extension + '?payerID={}&providerLastName={}&searchOption={}&dateOfBirth={}&memberId={}&npi={}'.format(
|
|
194
202
|
payer_id, provider_last_name, search_option, date_of_birth, member_id, npi)
|
|
@@ -210,7 +218,7 @@ def get_eligibility_v3(client, payer_id, provider_last_name, search_option, date
|
|
|
210
218
|
if payer_id not in valid_payer_ids:
|
|
211
219
|
raise ValueError("Invalid payer_id: {}. Must be one of: {}".format(payer_id, ", ".join(valid_payer_ids)))
|
|
212
220
|
|
|
213
|
-
endpoint_name = '
|
|
221
|
+
endpoint_name = 'UHCAPI'
|
|
214
222
|
url_extension = client.config['MediLink_Config']['endpoints'][endpoint_name]['additional_endpoints']['eligibility_v3']
|
|
215
223
|
|
|
216
224
|
# Construct request body
|
|
@@ -253,6 +261,90 @@ def get_eligibility_v3(client, payer_id, provider_last_name, search_option, date
|
|
|
253
261
|
|
|
254
262
|
return client.make_api_call(endpoint_name, 'POST', url_extension, params=None, data=body)
|
|
255
263
|
|
|
264
|
+
def is_test_mode(client, body, endpoint_type):
|
|
265
|
+
"""
|
|
266
|
+
Checks if Test Mode is enabled in the client's configuration and simulates the response if it is.
|
|
267
|
+
|
|
268
|
+
:param client: An instance of APIClient
|
|
269
|
+
:param body: The intended request body
|
|
270
|
+
:param endpoint_type: The type of endpoint being accessed ('claim_submission' or 'claim_details')
|
|
271
|
+
:return: A dummy response simulating the real API call if Test Mode is enabled, otherwise None
|
|
272
|
+
"""
|
|
273
|
+
if client.config.get("MediLink_Config", {}).get("TestMode", True):
|
|
274
|
+
print("Test Mode is enabled! API Call not executed.")
|
|
275
|
+
print("\nIntended request body:", body)
|
|
276
|
+
MediLink_ConfigLoader.log("Test Mode is enabled! Simulating API response for {}.".format(endpoint_type), level="INFO")
|
|
277
|
+
MediLink_ConfigLoader.log("Intended request body: {}".format(body), level="INFO")
|
|
278
|
+
|
|
279
|
+
if endpoint_type == 'claim_submission':
|
|
280
|
+
dummy_response = {
|
|
281
|
+
"transactionId": "CS07180420240328013411240", # This is the tID for the sandbox Claim Acknowledgement endpoint.
|
|
282
|
+
"x12ResponseData": "ISA*00* *00* *ZZ*TEST1234567890 *33*TEST *210101*0101*^*00501*000000001*0*P*:~GS*HC*TEST1234567890*TEST*20210101*0101*1*X*005010X222A1~ST*837*000000001*005010X222A1~BHT*0019*00*00001*20210101*0101*CH~NM1*41*2*TEST SUBMITTER*****46*TEST~PER*IC*TEST CONTACT*TE*1234567890~NM1*40*2*TEST RECEIVER*****46*TEST~HL*1**20*1~NM1*85*2*TEST PROVIDER*****XX*1234567890~N3*TEST ADDRESS~N4*TEST CITY*TEST STATE*12345~REF*EI*123456789~PER*IC*TEST PROVIDER*TE*1234567890~NM1*87*2~N3*TEST ADDRESS~N4*TEST CITY*TEST STATE*12345~HL*2*1*22*0~SBR*P*18*TEST GROUP******CI~NM1*IL*1*TEST PATIENT****MI*123456789~N3*TEST ADDRESS~N4*TEST CITY*TEST STATE*12345~DMG*D8*19800101*M~NM1*PR*2*TEST INSURANCE*****PI*12345~CLM*TESTCLAIM*100***12:B:1*Y*A*Y*Y*P~REF*D9*TESTREFERENCE~HI*ABK:TEST~NM1*DN*1*TEST DOCTOR****XX*1234567890~LX*1~SV1*HC:TEST*100*UN*1***1~DTP*472*RD8*20210101-20210101~REF*6R*TESTREFERENCE~SE*30*000000001~GE*1*1~IEA*1*000000001~",
|
|
283
|
+
"responseType": "dummy_response_837999",
|
|
284
|
+
"message": "Test Mode: Claim validated and sent for further processing"
|
|
285
|
+
}
|
|
286
|
+
elif endpoint_type == 'claim_details':
|
|
287
|
+
dummy_response = {
|
|
288
|
+
"responseType": "dummy_response_277CA-CH",
|
|
289
|
+
"x12ResponseData": "ISA*00* *00* *ZZ*841162764 *ZZ*UB920086 *240318*0921*^*00501*000165687*0*T*:~GS*HN*841162764*UB920086*20240318*0921*0165687*X*005010X214~ST*277*000000006*005010X214~…………….. SE*116*000000006~GE*1*0165687~IEA*1*000165687~",
|
|
290
|
+
"statuscode": "000",
|
|
291
|
+
"message:": ""
|
|
292
|
+
}
|
|
293
|
+
return dummy_response
|
|
294
|
+
return None
|
|
295
|
+
|
|
296
|
+
def submit_uhc_claim(client, x12_request_data):
|
|
297
|
+
"""
|
|
298
|
+
Submits a UHC claim and retrieves the claim acknowledgement details.
|
|
299
|
+
|
|
300
|
+
This function first submits the claim using the provided x12 837p data. If the client is in Test Mode,
|
|
301
|
+
it returns a simulated response. If Test Mode is not enabled, it submits the claim and then retrieves
|
|
302
|
+
the claim acknowledgement details using the transaction ID from the initial response.
|
|
303
|
+
|
|
304
|
+
:param client: An instance of APIClient
|
|
305
|
+
:param x12_request_data: The x12 837p data as a string
|
|
306
|
+
:return: The final response containing the claim acknowledgement details or a dummy response if in Test Mode
|
|
307
|
+
"""
|
|
308
|
+
endpoint_name = 'UHCAPI'
|
|
309
|
+
claim_submission_url = client.config['MediLink_Config']['endpoints'][endpoint_name]['additional_endpoints']['claim_submission']
|
|
310
|
+
claim_details_url = client.config['MediLink_Config']['endpoints'][endpoint_name]['additional_endpoints']['claim_details']
|
|
311
|
+
|
|
312
|
+
# Headers for the request
|
|
313
|
+
headers = {'Content-Type': 'application/json'}
|
|
314
|
+
|
|
315
|
+
# Request body for claim submission
|
|
316
|
+
claim_body = {'x12RequestData': x12_request_data}
|
|
317
|
+
|
|
318
|
+
# Check if Test Mode is enabled and return simulated response if so
|
|
319
|
+
test_mode_response = is_test_mode(client, claim_body, 'claim_submission')
|
|
320
|
+
if test_mode_response:
|
|
321
|
+
return test_mode_response
|
|
322
|
+
|
|
323
|
+
# Make the API call to submit the claim
|
|
324
|
+
try:
|
|
325
|
+
submission_response = client.make_api_call(endpoint_name, 'POST', claim_submission_url, data=claim_body, headers=headers)
|
|
326
|
+
|
|
327
|
+
# Extract the transaction ID from the submission response
|
|
328
|
+
transaction_id = submission_response.get('transactionId')
|
|
329
|
+
if not transaction_id:
|
|
330
|
+
raise ValueError("transactionId not found in the submission response")
|
|
331
|
+
|
|
332
|
+
# Prepare the request body for the claim acknowledgement retrieval
|
|
333
|
+
acknowledgement_body = {'transactionId': transaction_id}
|
|
334
|
+
|
|
335
|
+
# Check if Test Mode is enabled and return simulated response if so
|
|
336
|
+
test_mode_response = is_test_mode(client, acknowledgement_body, 'claim_details')
|
|
337
|
+
if test_mode_response:
|
|
338
|
+
return test_mode_response
|
|
339
|
+
|
|
340
|
+
# Make the API call to retrieve the claim acknowledgement details
|
|
341
|
+
acknowledgement_response = client.make_api_call(endpoint_name, 'POST', claim_details_url, data=acknowledgement_body, headers=headers)
|
|
342
|
+
return acknowledgement_response
|
|
343
|
+
|
|
344
|
+
except Exception as e:
|
|
345
|
+
print("Error during claim processing: {}".format(e))
|
|
346
|
+
raise
|
|
347
|
+
|
|
256
348
|
if __name__ == "__main__":
|
|
257
349
|
client = APIClient()
|
|
258
350
|
|
|
@@ -261,7 +353,8 @@ if __name__ == "__main__":
|
|
|
261
353
|
'test_fetch_payer_name': False,
|
|
262
354
|
'test_claim_summary': False,
|
|
263
355
|
'test_eligibility': False,
|
|
264
|
-
'test_eligibility_v3':
|
|
356
|
+
'test_eligibility_v3': False,
|
|
357
|
+
'test_claim_submission': True,
|
|
265
358
|
}
|
|
266
359
|
|
|
267
360
|
try:
|
|
@@ -321,5 +414,16 @@ if __name__ == "__main__":
|
|
|
321
414
|
except Exception as e:
|
|
322
415
|
print("Error in getting eligibility for {}: {}".format(patient['provider_last_name'], e))
|
|
323
416
|
"""
|
|
417
|
+
# Test 5: UHC Claim Submission
|
|
418
|
+
if test_config.get('test_claim_submission', False):
|
|
419
|
+
try:
|
|
420
|
+
x12_request_data = (
|
|
421
|
+
"ISA*00* *00* *ZZ*BRT219991205 *33*87726 *170417*1344*^*00501*019160001*0*P*:~GS*HC*BRT219991205*B2BRTA*20170417*134455*19160001*X*005010X222A1~ST*837*000000001*005010X222A1~BHT*0019*00*00001*20170417*134455*CH~NM1*41*2*B00099999819*****46*BB2B~PER*IC*NO NAME*TE*1234567890~NM1*40*2*TIGER*****46*87726~HL*1**20*1~NM1*85*2*XYZ ADDRESS*****XX*1073511762~N3*123 CITY#680~N4*STATE*TG*98765~REF*EI*943319804~PER*IC*XYZ ADDRESS*TE*8008738385*TE*9142862043*FX*1234567890~NM1*87*2~N3*PO BOX 277500~N4*STATE*TS*303847000~HL*2*1*22*0~SBR*P*18*701648******CI~NM1*IL*1*FNAME*LNAME****MI*00123456789~N3*2020 CITY~N4*STATE*TG*80001~DMG*D8*19820220*M~NM1*PR*2*PROVIDER XYZ*****PI*87726~\nCLM*TOSRTA-SPL1*471***12:B:1*Y*A*Y*Y*P~REF*D9*H4HZMH0R4P0104~HI*ABK:Z12~NM1*DN*1*DN*SKO****XX*1255589300~LX*1~SV1*HC:73525*471*UN*1***1~DTP*472*RD8*0190701-20190701~REF*6R*2190476543Z1~SE*30*000000001~GE*1*19160001~IEA*1*019160001~"
|
|
422
|
+
)
|
|
423
|
+
response = submit_uhc_claim(client, x12_request_data)
|
|
424
|
+
print("\nTEST API: Claim Submission Response:\n", response)
|
|
425
|
+
except Exception as e:
|
|
426
|
+
print("\nTEST API: Error in Claim Submission Test:\n", e)
|
|
427
|
+
|
|
324
428
|
except Exception as e:
|
|
325
|
-
print("TEST API: Unexpected Error: {}".format(e))
|
|
429
|
+
print("TEST API: Unexpected Error: {}".format(e))
|
|
@@ -17,7 +17,7 @@ def load_configuration(config_path=os.path.join(os.path.dirname(__file__), '..',
|
|
|
17
17
|
Returns: A tuple containing dictionaries with configuration settings for the main config and crosswalk.
|
|
18
18
|
"""
|
|
19
19
|
# TODO (Low Config Upgrade) The Medicare / Private differentiator flag probably needs to be pulled or passed to this.
|
|
20
|
-
# BUG Hardcode sucks.
|
|
20
|
+
# BUG Hardcode sucks. This should probably be some local env variable.
|
|
21
21
|
# Detect the operating system
|
|
22
22
|
if platform.system() == 'Windows' and platform.release() == 'XP':
|
|
23
23
|
# Use F: paths for Windows XP
|
|
@@ -219,11 +219,11 @@ def operate_winscp(operation_type, files, endpoint_config, local_storage_path, c
|
|
|
219
219
|
except KeyError as e:
|
|
220
220
|
# Log the missing key information
|
|
221
221
|
missing_key = str(e)
|
|
222
|
-
message = "
|
|
222
|
+
message = "Critical Error: Endpoint config is missing key: {}".format(missing_key)
|
|
223
223
|
MediLink_ConfigLoader.log(message)
|
|
224
|
-
#
|
|
225
|
-
|
|
226
|
-
|
|
224
|
+
# Raise an exception to halt execution
|
|
225
|
+
raise RuntimeError("Configuration error: The endpoint configuration is missing definitions for the required remote directories. Please check the configuration and try again.")
|
|
226
|
+
|
|
227
227
|
# Command building
|
|
228
228
|
command = [
|
|
229
229
|
winscp_path,
|