medicafe 0.240517.0__py3-none-any.whl → 0.240613.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.

MediLink/MediLink_Down.py CHANGED
@@ -1,123 +1,117 @@
1
+ # MediLink_Down.py
1
2
  import os
2
3
  import argparse
3
4
  import shutil
4
- from datetime import datetime
5
5
  import glob
6
- import MediLink_ERA_decoder
7
- from MediLink_DataMgmt import operate_winscp
6
+ from MediLink_Decoder import process_file
7
+ from MediLink_DataMgmt import operate_winscp, consolidate_csvs
8
8
  import MediLink_ConfigLoader
9
+ # Import decoders for other file types
9
10
 
10
11
  """
11
- We need to make another function that figures out claim rejections and tries to solve them.
12
+ Main triaging function for handling report downloads and processing from various endpoints. This function
13
+ handles downloading reports, moving files, and decoding them into a readable format. The goal is to
14
+ provide detailed receipt and troubleshooting information for the claims.
12
15
 
13
- 1. Config File Path Adjustment: Ensure the configuration file's path is adaptable for various environments, or clearly document the process for setting this path.
14
- 2. Logging Enhancements: Improve the logging mechanism to offer comprehensive insights through both file and console outputs, aiding in troubleshooting and operational monitoring.
15
- 3. CSV Output Refinement: Update the CSV output structure to include essential ERA data such as Payer Address, ensuring completeness and accuracy of information.
16
- 4. CSV Consolidation Logic: Develop logic for intelligently consolidating CSV outputs from batch-processed ERA files, ensuring coherent and comprehensive data aggregation.
17
- 5. Secure Endpoint Authentication: Establish a secure method for inputting and storing endpoint authentication details, enhancing script security.
18
- 6. Automated Endpoint Processing: Integrate automated looping through configured endpoints for ERA file retrieval, maximizing efficiency and reducing manual oversight.
19
- 7. Configuration Key Accuracy: Audit the script to correct any inaccuracies in configuration key references, ensuring seamless configuration data retrieval.
16
+ Key Enhancements:
17
+ - Handle multiple file types (ERA, 277, etc.) and integrate respective decoders.
18
+ - Support multi-endpoint processing.
19
+ - Implement progress tracking for long-running operations.
20
+ - Provide both consolidated CSV output and in-memory parsed data for real-time display.
20
21
  """
21
-
22
- # Because I can't figure out how to get it to work directly in the WinSCP command.
23
- # And on the Windows XP machine apparently the default path is C:\\ ...
24
- # This needs to get fixed. Ugh.
25
- def move_downloaded_files(local_storage_path):
26
- # Define the target directory for storing downloaded files
22
+ def move_downloaded_files(local_storage_path, config):
27
23
  local_response_directory = os.path.join(local_storage_path, "responses")
28
24
 
29
25
  if not os.path.exists(local_response_directory):
30
26
  os.makedirs(local_response_directory)
31
27
 
32
- # Identify all downloaded .era files in the current directory
33
- # downloaded_files = [f for f in os.listdir('.') if f.endswith('.era')]
34
- downloaded_files = [f for f in os.listdir('C:\\Users\\danie\\OneDrive\\Documents') if f.endswith('.era')]
28
+ download_dir = config['MediLink_Config']['local_storage_path']
29
+ file_extensions = ['.era', '.277'] # Extendable list of file extensions
35
30
 
36
- # Move each file to the local_response_directory
37
- for file in downloaded_files:
38
- source_path = os.path.join('C:\\Users\\danie\\OneDrive\\Documents', file)
39
- # source_path = os.path.join('.', file) for the XP machine? -- This whole thing needs repaired.
40
- destination_path = os.path.join(local_response_directory, file)
41
- shutil.move(source_path, destination_path)
42
- MediLink_ConfigLoader.log("Moved '{}' to '{}'".format(file, local_response_directory))
31
+ for ext in file_extensions:
32
+ downloaded_files = [f for f in os.listdir(download_dir) if f.endswith(ext)]
33
+ for file in downloaded_files:
34
+ source_path = os.path.join(download_dir, file)
35
+ destination_path = os.path.join(local_response_directory, file)
36
+ shutil.move(source_path, destination_path)
37
+ MediLink_ConfigLoader.log("Moved '{}' to '{}'".format(file, local_response_directory))
43
38
 
44
- def find_era_files(era_file_path):
45
- """
46
- Find all files matching the era_file_path pattern.
47
- This function normalizes the path and supports wildcard patterns.
48
- """
49
- # Normalize the path to handle slashes correctly
50
- normalized_path = os.path.normpath(era_file_path)
39
+ def find_files(file_path_pattern):
40
+ normalized_path = os.path.normpath(file_path_pattern)
51
41
 
52
- # Handling different wildcard scenarios
53
42
  if "*" in normalized_path:
54
- # Use glob to find all files matching the pattern
55
43
  matching_files = glob.glob(normalized_path)
56
- # Normalize paths in the resulting list
57
44
  return [os.path.normpath(file) for file in matching_files]
58
45
  else:
59
- # Single file specified, return it in a list if it exists
60
46
  return [normalized_path] if os.path.exists(normalized_path) else []
61
47
 
48
+ def translate_files(files, output_directory):
49
+ translated_files = []
50
+ for file in files:
51
+ try:
52
+ process_file(file, output_directory)
53
+ csv_file_path = os.path.join(output_directory, os.path.basename(file) + '_decoded.csv')
54
+ MediLink_ConfigLoader.log("Translated file to CSV: {}".format(csv_file_path), level="INFO")
55
+ translated_files.append(csv_file_path)
56
+ except ValueError as ve:
57
+ MediLink_ConfigLoader.log("Unsupported file type: {}".format(file), level="WARNING")
58
+ except Exception as e:
59
+ MediLink_ConfigLoader.log("Error processing file {}: {}".format(file, e), level="ERROR")
60
+
61
+ consolidate_csv_path = consolidate_csvs(output_directory, file_prefix="Consolidated", interactive=True)
62
+ MediLink_ConfigLoader.log("Consolidated CSV path: {}".format(consolidate_csv_path), level="INFO")
63
+ return consolidate_csv_path, translated_files
64
+
65
+ def display_translated_files(translated_files):
66
+ print("\nTranslated Files Summary:")
67
+ for file in translated_files:
68
+ print(" - {}",format(file))
69
+
62
70
  def main(desired_endpoint='AVAILITY'):
63
- parser = argparse.ArgumentParser(description="Process ERA files and convert them to CSV format.")
64
- parser.add_argument('--config_path', type=str, help='Path to the configuration JSON file', default="json\\config.json") # Default handling of json path
71
+ parser = argparse.ArgumentParser(description="Process files and convert them to CSV format.")
72
+ parser.add_argument('--config_path', type=str, help='Path to the configuration JSON file', default="json/config.json")
65
73
  parser.add_argument('--desired_endpoint', type=str, help='The desired endpoint key from the configuration.', default=desired_endpoint)
66
- parser.add_argument('--era_file_path', type=str, help='Optional: Specify a path to an ERA file for direct translation.', default=None)
74
+ parser.add_argument('--file_path_pattern', type=str, help='Optional: Specify a path pattern for files for direct translation.', default=None)
67
75
  args = parser.parse_args()
68
76
 
69
- # Setup Logger, Load configuration and output directory
70
77
  config, _ = MediLink_ConfigLoader.load_configuration(args.config_path)
71
78
  local_storage_path = config['MediLink_Config']['local_storage_path']
72
79
  output_directory = os.path.join(local_storage_path, "translated_csvs")
73
-
74
- # Direct ERA file translation if a file path is provided
75
- if args.era_file_path:
76
- era_files = find_era_files(args.era_file_path)
77
- if era_files:
78
- era_files_str = ', '.join(era_files)
79
- MediLink_ConfigLoader.log("Translating ERA files: {}".format(era_files_str))
80
- MediLink_ERA_decoder.translate_era_to_csv(era_files, output_directory)
81
- # Instead of returning a single CSV file path, consolidate here
82
- consolidate_csv_path = MediLink_ERA_decoder.consolidate_csvs(output_directory)
83
- MediLink_ConfigLoader.log("Translation and consolidation completed.")
80
+
81
+ if args.file_path_pattern:
82
+ files = find_files(args.file_path_pattern)
83
+ if files:
84
+ files_str = ', '.join(files)
85
+ MediLink_ConfigLoader.log("Translating files: {}".format(files_str), level="INFO")
86
+ consolidate_csv_path, translated_files = translate_files(files, output_directory)
87
+ MediLink_ConfigLoader.log("Translation and consolidation completed.", level="INFO")
88
+ display_translated_files(translated_files)
84
89
  return consolidate_csv_path
85
90
  else:
86
- MediLink_ConfigLoader.log("No ERA files found matching: {}".format(args.era_file_path))
91
+ MediLink_ConfigLoader.log("No files found matching: {}".format(args.file_path_pattern), level="WARNING")
87
92
  return
88
93
 
89
- # TODO (Low Remit) This probably needs to be built into a loop that cycles through all 3 endpoints.
90
- # I think the uploader has something like this implemented already since it sends to all the endpoints.
91
- # The loop should use the tdqa or whatever the progress bar is called.
92
- # print("Please wait...\n")
93
-
94
- # Validate endpoint key
95
94
  endpoint_key = args.desired_endpoint
96
95
  if endpoint_key not in config['MediLink_Config']['endpoints']:
97
- MediLink_ConfigLoader.log("Endpoint '{}' not found in configuration. Using default 'AVAILITY'.".format(endpoint_key))
96
+ MediLink_ConfigLoader.log("Endpoint '{}' not found in configuration. Using default 'AVAILITY'.".format(endpoint_key), level="WARNING")
98
97
  endpoint_key = 'AVAILITY'
99
98
 
100
- # Retrieve endpoint configuration and local storage path
101
- endpoint_config = config['MediLink_Config']['endpoints'][endpoint_key]
102
- local_storage_path = config['MediLink_Config']['local_storage_path']
103
-
104
- # Download ERA files from the configured endpoint
105
- downloaded_files = operate_winscp("download", None, endpoint_config, local_storage_path, config)
99
+ endpoint_configs = [config['MediLink_Config']['endpoints'][key] for key in config['MediLink_Config']['endpoints']]
100
+ downloaded_files = []
106
101
 
107
- # Translate downloaded ERA files to CSV format
108
- translated_csv_paths = []
109
- for file in downloaded_files:
110
- # TODO (Low Remit) This needs to add functionality for differentiating between ERA, 277, IBT or
111
- # whatever else might be included in the download folders.
112
- MediLink_ERA_decoder.translate_era_to_csv([file], output_directory)
113
- csv_file_path = os.path.join(output_directory, os.path.basename(file) + '.csv')
114
- translated_csv_paths.append(csv_file_path)
115
- MediLink_ConfigLoader.log("Translated ERA to CSV: {}".format(csv_file_path))
102
+ for endpoint_config in endpoint_configs:
103
+ downloaded_files += operate_winscp("download", None, endpoint_config, local_storage_path, config)
104
+
105
+ move_downloaded_files(local_storage_path, config)
106
+
107
+ # Implement progress tracking
108
+ # from tqdm import tqdm
109
+ # for file in tqdm(downloaded_files, desc="Translating files"):
110
+ # translate_files([file], output_directory)
116
111
 
117
- # Consolidate new CSVs
118
- consolidate_csv_path = MediLink_ERA_decoder.consolidate_csvs(output_directory)
112
+ consolidate_csv_path, translated_files = translate_files(downloaded_files, output_directory)
113
+ display_translated_files(translated_files)
119
114
 
120
- # Return the list of translated CSV file paths
121
115
  return consolidate_csv_path
122
116
 
123
117
  if __name__ == "__main__":