medicafe 0.250728.8__py3-none-any.whl → 0.250805.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


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

Files changed (58) hide show
  1. MediBot/MediBot.bat +233 -19
  2. MediBot/MediBot.py +138 -46
  3. MediBot/MediBot_Crosswalk_Library.py +127 -623
  4. MediBot/MediBot_Crosswalk_Utils.py +618 -0
  5. MediBot/MediBot_Preprocessor.py +72 -17
  6. MediBot/MediBot_Preprocessor_lib.py +470 -76
  7. MediBot/MediBot_UI.py +32 -17
  8. MediBot/MediBot_dataformat_library.py +68 -20
  9. MediBot/MediBot_docx_decoder.py +120 -19
  10. MediBot/MediBot_smart_import.py +180 -0
  11. MediBot/__init__.py +89 -0
  12. MediBot/get_medicafe_version.py +25 -0
  13. MediBot/update_json.py +35 -6
  14. MediBot/update_medicafe.py +19 -1
  15. MediCafe/MediLink_ConfigLoader.py +160 -0
  16. MediCafe/__init__.py +171 -0
  17. MediCafe/__main__.py +222 -0
  18. MediCafe/api_core.py +1098 -0
  19. MediCafe/api_core_backup.py +427 -0
  20. MediCafe/api_factory.py +306 -0
  21. MediCafe/api_utils.py +356 -0
  22. MediCafe/core_utils.py +450 -0
  23. MediCafe/graphql_utils.py +445 -0
  24. MediCafe/logging_config.py +123 -0
  25. MediCafe/logging_demo.py +61 -0
  26. MediCafe/migration_helpers.py +463 -0
  27. MediCafe/smart_import.py +436 -0
  28. MediLink/MediLink.py +66 -26
  29. MediLink/MediLink_837p_cob_library.py +28 -28
  30. MediLink/MediLink_837p_encoder.py +33 -34
  31. MediLink/MediLink_837p_encoder_library.py +243 -151
  32. MediLink/MediLink_837p_utilities.py +129 -5
  33. MediLink/MediLink_API_Generator.py +83 -60
  34. MediLink/MediLink_API_v3.py +1 -1
  35. MediLink/MediLink_ClaimStatus.py +177 -31
  36. MediLink/MediLink_DataMgmt.py +405 -72
  37. MediLink/MediLink_Decoder.py +20 -1
  38. MediLink/MediLink_Deductible.py +155 -28
  39. MediLink/MediLink_Display_Utils.py +72 -0
  40. MediLink/MediLink_Down.py +127 -5
  41. MediLink/MediLink_Gmail.py +712 -653
  42. MediLink/MediLink_PatientProcessor.py +257 -0
  43. MediLink/MediLink_UI.py +85 -61
  44. MediLink/MediLink_Up.py +28 -4
  45. MediLink/MediLink_insurance_utils.py +227 -264
  46. MediLink/MediLink_main.py +248 -0
  47. MediLink/MediLink_smart_import.py +264 -0
  48. MediLink/__init__.py +93 -0
  49. MediLink/insurance_type_integration_test.py +66 -76
  50. MediLink/test.py +1 -1
  51. MediLink/test_timing.py +59 -0
  52. {medicafe-0.250728.8.dist-info → medicafe-0.250805.0.dist-info}/METADATA +1 -1
  53. medicafe-0.250805.0.dist-info/RECORD +81 -0
  54. medicafe-0.250805.0.dist-info/entry_points.txt +2 -0
  55. {medicafe-0.250728.8.dist-info → medicafe-0.250805.0.dist-info}/top_level.txt +1 -0
  56. medicafe-0.250728.8.dist-info/RECORD +0 -59
  57. {medicafe-0.250728.8.dist-info → medicafe-0.250805.0.dist-info}/LICENSE +0 -0
  58. {medicafe-0.250728.8.dist-info → medicafe-0.250805.0.dist-info}/WHEEL +0 -0
MediBot/MediBot.bat CHANGED
@@ -1,4 +1,4 @@
1
- ::MediBot.bat
1
+ ::MediBot.bat - Updated to use MediCafe entry point
2
2
  @echo off
3
3
  setlocal enabledelayedexpansion
4
4
 
@@ -25,6 +25,94 @@ if %errorlevel% neq 0 (
25
25
  exit /b
26
26
  )
27
27
 
28
+ :: Check if critical directories exist
29
+ if not exist "%source_folder%" (
30
+ echo.
31
+ echo Warning: Source folder not found at: %source_folder%
32
+ echo.
33
+ echo Would you like to provide an alternate path for the source folder?
34
+ set /p provide_alt_source="Enter 'Y' to provide alternate path, or any other key to continue: "
35
+ if /i "!provide_alt_source!"=="Y" (
36
+ echo.
37
+ echo Please enter the full path to your source folder.
38
+ echo Example: C:\MediCare\Data
39
+ echo Example with spaces: "G:\My Drive\MediCare\Data"
40
+ echo.
41
+ echo Note: If your path contains spaces, please include quotes around the entire path.
42
+ echo.
43
+ set /p alt_source_path="Enter source folder path: "
44
+ :: Remove any surrounding quotes from user input and re-add them for consistency
45
+ set "alt_source_path=!alt_source_path:"=!"
46
+ if exist "!alt_source_path!" (
47
+ echo Source folder found at: !alt_source_path!
48
+ set "source_folder=!alt_source_path!"
49
+ ) else (
50
+ echo Source folder not found at: !alt_source_path!
51
+ echo Continuing with default path...
52
+ )
53
+ ) else (
54
+ echo Continuing with default path...
55
+ )
56
+ )
57
+
58
+ if not exist "%local_storage_path%" (
59
+ echo.
60
+ echo Warning: Local storage path not found at: %local_storage_path%
61
+ echo.
62
+ echo Would you like to provide an alternate path for the local storage?
63
+ set /p provide_alt_storage="Enter 'Y' to provide alternate path, or any other key to continue: "
64
+ if /i "!provide_alt_storage!"=="Y" (
65
+ echo.
66
+ echo Please enter the full path to your local storage folder.
67
+ echo Example: C:\MediBot\Downloads
68
+ echo Example with spaces: "G:\My Drive\MediBot\Downloads"
69
+ echo.
70
+ echo Note: If your path contains spaces, please include quotes around the entire path.
71
+ echo.
72
+ set /p alt_storage_path="Enter local storage path: "
73
+ :: Remove any surrounding quotes from user input and re-add them for consistency
74
+ set "alt_storage_path=!alt_storage_path:"=!"
75
+ if exist "!alt_storage_path!" (
76
+ echo Local storage folder found at: !alt_storage_path!
77
+ set "local_storage_path=!alt_storage_path!"
78
+ ) else (
79
+ echo Local storage folder not found at: !alt_storage_path!
80
+ echo Continuing with default path...
81
+ )
82
+ ) else (
83
+ echo Continuing with default path...
84
+ )
85
+ )
86
+
87
+ if not exist "%target_folder%" (
88
+ echo.
89
+ echo Warning: Target folder not found at: %target_folder%
90
+ echo.
91
+ echo Would you like to provide an alternate path for the target folder?
92
+ set /p provide_alt_target="Enter 'Y' to provide alternate path, or any other key to continue: "
93
+ if /i "!provide_alt_target!"=="Y" (
94
+ echo.
95
+ echo Please enter the full path to your target folder.
96
+ echo Example: C:\MediCare\CSV
97
+ echo Example with spaces: "G:\My Drive\MediCare\CSV"
98
+ echo.
99
+ echo Note: If your path contains spaces, please include quotes around the entire path.
100
+ echo.
101
+ set /p alt_target_path="Enter target folder path: "
102
+ :: Remove any surrounding quotes from user input and re-add them for consistency
103
+ set "alt_target_path=!alt_target_path:"=!"
104
+ if exist "!alt_target_path!" (
105
+ echo Target folder found at: !alt_target_path!
106
+ set "target_folder=!alt_target_path!"
107
+ ) else (
108
+ echo Target folder not found at: !alt_target_path!
109
+ echo Continuing with default path...
110
+ )
111
+ ) else (
112
+ echo Continuing with default path...
113
+ )
114
+ )
115
+
28
116
  :: Check if the MediCafe package is installed and retrieve its version
29
117
  echo Checking for installed MediCafe package version...
30
118
  python -c "import pkg_resources; print('MediCafe=='+pkg_resources.get_distribution('medicafe').version)" > temp.txt 2>nul
@@ -62,9 +150,70 @@ if %ERRORLEVEL% neq 0 (
62
150
  echo Setting up the environment...
63
151
  if not exist "%config_file%" (
64
152
  echo Configuration file missing.
65
- goto end_script
153
+ echo.
154
+ echo Expected configuration file path: %config_file%
155
+ echo.
156
+ echo Would you like to provide an alternate path for the configuration file?
157
+ set /p provide_alt="Enter 'Y' to provide alternate path, or any other key to exit: "
158
+ if /i "!provide_alt!"=="Y" (
159
+ echo.
160
+ echo Please enter the full path to your configuration file.
161
+ echo Example: C:\MediBot\config\config.json
162
+ echo Example with spaces: "G:\My Drive\MediBot\config\config.json"
163
+ echo.
164
+ echo Note: If your path contains spaces, please include quotes around the entire path.
165
+ echo.
166
+ set /p alt_config_path="Enter configuration file path: "
167
+ :: Remove any surrounding quotes from user input and re-add them for consistency
168
+ set "alt_config_path=!alt_config_path:"=!"
169
+ if exist "!alt_config_path!" (
170
+ echo Configuration file found at: !alt_config_path!
171
+ set "config_file=!alt_config_path!"
172
+ goto config_check_complete
173
+ ) else (
174
+ echo Configuration file not found at: !alt_config_path!
175
+ echo.
176
+ set /p retry="Would you like to try another path? (Y/N): "
177
+ if /i "!retry!"=="Y" (
178
+ goto retry_config_path
179
+ ) else (
180
+ goto end_script
181
+ )
182
+ )
183
+ ) else (
184
+ goto end_script
185
+ )
186
+ ) else (
187
+ goto config_check_complete
66
188
  )
67
189
 
190
+ :retry_config_path
191
+ echo.
192
+ echo Please enter the full path to your configuration file.
193
+ echo Example: C:\MediBot\config\config.json
194
+ echo Example with spaces: "G:\My Drive\MediBot\config\config.json"
195
+ echo.
196
+ echo Note: If your path contains spaces, please include quotes around the entire path.
197
+ echo.
198
+ set /p alt_config_path="Enter configuration file path: "
199
+ :: Remove any surrounding quotes from user input and re-add them for consistency
200
+ set "alt_config_path=!alt_config_path:"=!"
201
+ if exist "!alt_config_path!" (
202
+ echo Configuration file found at: !alt_config_path!
203
+ set "config_file=!alt_config_path!"
204
+ ) else (
205
+ echo Configuration file not found at: !alt_config_path!
206
+ echo.
207
+ set /p retry="Would you like to try another path? (Y/N): "
208
+ if /i "!retry!"=="Y" (
209
+ goto retry_config_path
210
+ ) else (
211
+ goto end_script
212
+ )
213
+ )
214
+
215
+ :config_check_complete
216
+
68
217
  :: Check if the file exists and attempt to move it
69
218
  :: Implementing a check with copy as a fallback if move fails
70
219
  echo Checking for the update script...
@@ -102,7 +251,34 @@ if exist "C:\Python34\Lib\site-packages\MediBot\update_medicafe.py" (
102
251
  ping -n 2 127.0.0.1 >nul
103
252
  ) else (
104
253
  echo update_medicafe.py not detected in either location. Check path and filename.
105
- ping -n 2 127.0.0.1 >nul
254
+ echo.
255
+ echo Expected update script path: F:\Medibot\update_medicafe.py
256
+ echo.
257
+ echo Would you like to provide an alternate path for the update script?
258
+ set /p provide_alt_update="Enter 'Y' to provide alternate path, or any other key to continue: "
259
+ if /i "!provide_alt_update!"=="Y" (
260
+ echo.
261
+ echo Please enter the full path to your update_medicafe.py file.
262
+ echo Example: C:\MediBot\scripts\update_medicafe.py
263
+ echo Example with spaces: "G:\My Drive\MediBot\scripts\update_medicafe.py"
264
+ echo.
265
+ echo Note: If your path contains spaces, please include quotes around the entire path.
266
+ echo.
267
+ set /p alt_update_path="Enter update script path: "
268
+ :: Remove any surrounding quotes from user input and re-add them for consistency
269
+ set "alt_update_path=!alt_update_path:"=!"
270
+ if exist "!alt_update_path!" (
271
+ echo Update script found at: !alt_update_path!
272
+ set "upgrade_medicafe=!alt_update_path!"
273
+ ) else (
274
+ echo Update script not found at: !alt_update_path!
275
+ echo Continuing without update script...
276
+ ping -n 2 127.0.0.1 >nul
277
+ )
278
+ ) else (
279
+ echo Continuing without update script...
280
+ ping -n 2 127.0.0.1 >nul
281
+ )
106
282
  )
107
283
  )
108
284
 
@@ -147,6 +323,11 @@ if "!choice!"=="3" goto medilink_flow
147
323
  if "!choice!"=="2" goto download_emails
148
324
  if "!choice!"=="1" goto check_updates
149
325
 
326
+ :: Invalid choice - return to menu
327
+ echo Invalid choice. Please try again.
328
+ pause
329
+ goto main_menu
330
+
150
331
  :: Medicafe Update
151
332
  :check_updates
152
333
  if "!internet_available!"=="0" (
@@ -163,21 +344,20 @@ start "Medicafe Update" cmd /c py "%upgrade_medicafe%" %package_version% > upgra
163
344
  )
164
345
  exit /b
165
346
 
166
- :: Download Carol's Emails
347
+ :: Download Carol's Emails - Using MediCafe entry point
167
348
  :download_emails
168
349
  if "!internet_available!"=="0" (
169
350
  echo No internet connection available.
170
351
  goto main_menu
171
352
  )
172
- echo Downloading emails...
173
- :: move this path.
174
- py "../MediLink/MediLink_Gmail.py" "%firefox_path%"
353
+ call :process_csvs
354
+ cls
355
+ echo Starting email download via MediCafe...
356
+ cd /d "%~dp0.."
357
+ python -m MediCafe download_emails
175
358
  if errorlevel 1 (
176
359
  echo Failed to download emails.
177
360
  pause
178
- ) else (
179
- echo Calling CSV Processor...
180
- call :process_csvs
181
361
  )
182
362
  goto main_menu
183
363
 
@@ -185,8 +365,9 @@ goto main_menu
185
365
  :medibot_flow
186
366
  call :process_csvs
187
367
  cls
188
- echo Starting MediBot...
189
- py "%python_script2%" "%config_file%"
368
+ echo Starting MediBot via MediCafe...
369
+ cd /d "%~dp0.."
370
+ python -m MediCafe medibot "%config_file%"
190
371
  if errorlevel 1 echo Failed to run MediBot.
191
372
  pause
192
373
  goto main_menu
@@ -200,7 +381,8 @@ if "!internet_available!"=="0" (
200
381
  call :process_csvs
201
382
  cls
202
383
  :: move this path.
203
- py "C:\Python34\Lib\site-packages\MediLink\MediLink.py"
384
+ cd /d "%~dp0.."
385
+ python -m MediCafe medilink
204
386
  if errorlevel 1 echo MediLink failed to execute.
205
387
  pause
206
388
  goto main_menu
@@ -212,8 +394,9 @@ if "!internet_available!"=="0" (
212
394
  goto main_menu
213
395
  )
214
396
  cls
215
- echo Checking United Claims Status...
216
- py "%claims_status_script%"
397
+ echo Loading United Claims Status...
398
+ cd /d "%~dp0.."
399
+ python -m MediCafe claims_status
217
400
  if errorlevel 1 echo Failed to check United Claims Status.
218
401
  pause
219
402
  goto main_menu
@@ -225,8 +408,9 @@ if "!internet_available!"=="0" (
225
408
  goto main_menu
226
409
  )
227
410
  cls
228
- echo Checking United Deductible...
229
- py "%deductible_script%"
411
+ echo Loading United Deductible...
412
+ cd /d "%~dp0.."
413
+ python -m MediCafe deductible
230
414
  if errorlevel 1 echo Failed to check United Deductible.
231
415
  pause
232
416
  goto main_menu
@@ -234,10 +418,40 @@ goto main_menu
234
418
  :: Process CSV Files and Validate Against Config
235
419
  :process_csvs
236
420
 
421
+ :: Check if the Python script for JSON updates exists
422
+ if not exist "%python_script%" (
423
+ echo.
424
+ echo Warning: Python script for JSON updates not found at: %python_script%
425
+ echo.
426
+ echo Would you like to provide an alternate path for the JSON update script?
427
+ set /p provide_alt_json="Enter 'Y' to provide alternate path, or any other key to continue: "
428
+ if /i "!provide_alt_json!"=="Y" (
429
+ echo.
430
+ echo Please enter the full path to your update_json.py file.
431
+ echo Example: C:\MediBot\scripts\update_json.py
432
+ echo Example with spaces: "G:\My Drive\MediBot\scripts\update_json.py"
433
+ echo.
434
+ echo Note: If your path contains spaces, please include quotes around the entire path.
435
+ echo.
436
+ set /p alt_json_path="Enter JSON update script path: "
437
+ :: Remove any surrounding quotes from user input and re-add them for consistency
438
+ set "alt_json_path=!alt_json_path:"=!"
439
+ if exist "!alt_json_path!" (
440
+ echo JSON update script found at: !alt_json_path!
441
+ set "python_script=!alt_json_path!"
442
+ ) else (
443
+ echo JSON update script not found at: !alt_json_path!
444
+ echo Continuing without JSON update script...
445
+ )
446
+ ) else (
447
+ echo Continuing without JSON update script...
448
+ )
449
+ )
450
+
237
451
  :: Move CSV files from local_storage_path to source_folder in case AK sends it unencrypted by accident.
238
452
  echo Checking for new CSV files in local storage...
239
453
  for %%f in ("%local_storage_path%\*.csv") do (
240
- echo WARNING: Found unencrypted CSV files!
454
+ echo WARNING: Found CSV files!
241
455
  echo Moving %%f to %source_folder%...
242
456
  move "%%f" "%source_folder%" >nul 2>&1
243
457
  if errorlevel 1 (
@@ -442,4 +656,4 @@ for /l %%i in (%start%,1,%count%) do (
442
656
  )
443
657
 
444
658
  endlocal
445
- exit /b 0
659
+ goto :eof
MediBot/MediBot.py CHANGED
@@ -1,36 +1,71 @@
1
1
  #MediBot.py
2
- import subprocess, os, tempfile, traceback, re, sys, time, msvcrt
3
- from collections import OrderedDict
4
- import MediBot_dataformat_library
5
- import MediBot_Preprocessor
6
- from MediBot_Preprocessor_lib import initialize, AHK_EXECUTABLE, CSV_FILE_PATH, field_mapping, load_csv_data
7
- from MediBot_UI import app_control, manage_script_pause, user_interaction
8
-
2
+ import os, sys # Must be imported first
9
3
  # Add parent directory of the project to the Python path
10
4
  project_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
11
- sys.path.append(project_dir)
12
-
13
- from MediLink import MediLink_ConfigLoader
14
-
15
-
5
+ if project_dir not in sys.path:
6
+ sys.path.append(project_dir)
16
7
 
8
+ import subprocess, tempfile, traceback, re, time
17
9
  try:
18
- from MediBot_Crosswalk_Library import crosswalk_update
10
+ import msvcrt # Windows-specific module
19
11
  except ImportError:
20
- from MediBot import MediBot_Crosswalk_Library
21
- crosswalk_update = MediBot_Crosswalk_Library.crosswalk_update
12
+ msvcrt = None # Not available on non-Windows systems
13
+ from collections import OrderedDict
14
+
15
+ # Use core utilities for standardized imports
16
+ from MediCafe.core_utils import (
17
+ import_medibot_module_with_debug,
18
+ get_config_loader_with_fallback,
19
+ get_api_client_factory
20
+ )
21
+
22
+ # Initialize configuration loader with fallback
23
+ MediLink_ConfigLoader = get_config_loader_with_fallback()
24
+
25
+ # Import MediBot modules using centralized import functions with debugging
26
+ MediBot_dataformat_library = import_medibot_module_with_debug('MediBot_dataformat_library')
27
+ MediBot_Preprocessor = import_medibot_module_with_debug('MediBot_Preprocessor')
28
+ MediBot_Preprocessor_lib = import_medibot_module_with_debug('MediBot_Preprocessor_lib')
29
+
30
+ # Import UI components with function extraction
31
+ MediBot_UI = import_medibot_module_with_debug('MediBot_UI')
32
+ if MediBot_UI:
33
+ app_control = getattr(MediBot_UI, 'app_control', None)
34
+ manage_script_pause = getattr(MediBot_UI, 'manage_script_pause', None)
35
+ user_interaction = getattr(MediBot_UI, 'user_interaction', None)
36
+ else:
37
+ app_control = None
38
+ manage_script_pause = None
39
+ user_interaction = None
40
+
41
+ # Import crosswalk library
42
+ MediBot_Crosswalk_Library = import_medibot_module_with_debug('MediBot_Crosswalk_Library')
43
+ if MediBot_Crosswalk_Library:
44
+ crosswalk_update = getattr(MediBot_Crosswalk_Library, 'crosswalk_update', None)
45
+ else:
46
+ crosswalk_update = None
47
+
48
+ # Initialize API client variables
49
+ api_client = None
50
+ factory = None
22
51
 
23
52
  try:
24
- from MediLink.MediLink_API_v3 import APIClient
53
+ # Try to get API client factory
54
+ factory = get_api_client_factory()
55
+ if factory:
56
+ api_client = factory.get_shared_client() # Use shared client for token caching benefits
57
+ if MediLink_ConfigLoader:
58
+ MediLink_ConfigLoader.log("MediBot using API Factory with shared client", level="INFO")
25
59
  except ImportError as e:
26
- raise ImportError("Failed to import APIClient from MediLink.MediLink_API_v3. "
27
- "Ensure the MediLink_API_v3 module is installed and accessible.") from e
28
-
29
- # After successful import
30
- try:
31
- api_client = APIClient() # Pass necessary arguments if required
32
- except Exception as e:
33
- raise RuntimeError("Failed to instantiate APIClient. Ensure correct initialization parameters.") from e
60
+ # Fallback to basic API client
61
+ try:
62
+ from MediCafe.core_utils import get_api_client
63
+ api_client = get_api_client()
64
+ if MediLink_ConfigLoader:
65
+ MediLink_ConfigLoader.log("MediBot using fallback API client", level="WARNING")
66
+ except ImportError as e2:
67
+ # Make API client optional - don't log warning for now
68
+ pass
34
69
 
35
70
  def identify_field(header, field_mapping):
36
71
  for medisoft_field, patterns in field_mapping.items():
@@ -56,7 +91,7 @@ def run_ahk_script(script_content):
56
91
  # Optimized method: Execute AHK script via stdin pipe - eliminates temporary file creation
57
92
  # Compatible with Windows XP and AutoHotkey v1.0.48+
58
93
  process = subprocess.Popen(
59
- [AHK_EXECUTABLE, '/f', '*'], # '/f *' tells AHK to read from stdin
94
+ [MediBot_Preprocessor_lib.AHK_EXECUTABLE, '/', '*'], # '/f *' tells AHK to read from stdin
60
95
  stdin=subprocess.PIPE,
61
96
  stdout=subprocess.PIPE,
62
97
  stderr=subprocess.PIPE,
@@ -89,7 +124,7 @@ def run_ahk_script(script_content):
89
124
  temp_script.write(script_content) # Write the script content to the temporary file
90
125
  temp_script.flush() # Ensure the file is written to disk
91
126
  # Attempt to run the AHK script
92
- subprocess.check_call([AHK_EXECUTABLE, temp_script_name]) # Execute the AHK script using the AutoHotkey executable
127
+ subprocess.check_call([MediBot_Preprocessor_lib.AHK_EXECUTABLE, temp_script_name]) # Execute the AHK script using the AutoHotkey executable
93
128
  except subprocess.CalledProcessError as e:
94
129
  print("AHK script failed with exit status: {}".format(e.returncode)) # Log the exit status of the failed script
95
130
  MediLink_ConfigLoader.log("AHK script failed with exit status: {}".format(e.returncode), level="ERROR")
@@ -286,16 +321,28 @@ class ExecutionState:
286
321
  self.config = config
287
322
  MediLink_ConfigLoader.log("Config loaded successfully...")
288
323
 
289
- # Instantiate APIClient
290
- self.api_client = APIClient() # Pass required arguments if any
291
-
292
- # Simplified isinstance check
293
- if not isinstance(self.api_client, APIClient):
294
- raise TypeError("MediBot Error: api_client must be an instance of APIClient.")
324
+ # Get APIClient via factory
325
+ try:
326
+ from MediCafe.api_factory import APIClientFactory
327
+ factory = APIClientFactory()
328
+ self.api_client = factory.get_shared_client() # Use shared client for token caching benefits
329
+ MediLink_ConfigLoader.log("ExecutionState using API Factory with shared client", level="INFO")
330
+ except ImportError as e:
331
+ # Fallback to basic API client
332
+ try:
333
+ from MediCafe.core_utils import get_api_client
334
+ self.api_client = get_api_client()
335
+ MediLink_ConfigLoader.log("ExecutionState using fallback API client", level="WARNING")
336
+ except ImportError as e2:
337
+ self.api_client = None
295
338
 
296
339
  # Log before calling crosswalk_update
297
- MediLink_ConfigLoader.log("Updating crosswalk with client and config...", level="INFO")
298
- update_successful = crosswalk_update(self.api_client, config, crosswalk) # Ensure crosswalk_update uses the instance. TODO We need an internet-disabled version of this.
340
+ if self.api_client is not None:
341
+ MediLink_ConfigLoader.log("Updating crosswalk with client and config...", level="INFO")
342
+ update_successful = crosswalk_update(self.api_client, config, crosswalk)
343
+ else:
344
+ MediLink_ConfigLoader.log("Skipping crosswalk update - API client not available", level="WARNING")
345
+ update_successful = False
299
346
  if update_successful:
300
347
  MediLink_ConfigLoader.log("Crosswalk update completed successfully.", level="INFO")
301
348
  print("Crosswalk update completed successfully.")
@@ -314,34 +361,76 @@ class ExecutionState:
314
361
  if not isinstance(config, (dict, OrderedDict)):
315
362
  raise TypeError("Error: Configuration must be a dictionary or an OrderedDict. Check unpacking.")
316
363
 
364
+ # Import centralized logging configuration
365
+ try:
366
+ from MediCafe.logging_config import PERFORMANCE_LOGGING
367
+ except ImportError:
368
+ # Fallback to local flag if centralized config is not available
369
+ PERFORMANCE_LOGGING = False
370
+
317
371
  # Main script execution wrapped in try-except for error handling
318
372
  if __name__ == "__main__":
319
373
  e_state = None
320
374
  try:
321
- print("Initializing. Loading configuration and preparing environment...")
322
- # Default paths for configuration and crosswalk files
323
- default_config_path = os.path.join(os.path.dirname(__file__), '..', 'json', 'config.json')
375
+ if PERFORMANCE_LOGGING:
376
+ print("Initializing. Loading configuration and preparing environment...")
377
+ # Use MediCafe configuration system
378
+ try:
379
+ config_loader = get_config_loader_with_fallback()
380
+ if config_loader and len(sys.argv) <= 1:
381
+ # Use config loader when no command line arguments provided
382
+ config, crosswalk = config_loader.load_configuration()
383
+ config_path = None # Signal to use loaded config directly
384
+ else:
385
+ # Fall back to command line paths if provided
386
+ default_config_path = os.path.join(os.path.dirname(__file__), '..', 'json', 'config.json')
387
+ config_path = sys.argv[1] if len(sys.argv) > 1 else default_config_path
388
+ except Exception:
389
+ # Fallback to original behavior
390
+ default_config_path = os.path.join(os.path.dirname(__file__), '..', 'json', 'config.json')
391
+ config_path = sys.argv[1] if len(sys.argv) > 1 else default_config_path
392
+
393
+ # Define default crosswalk path
324
394
  default_crosswalk_path = os.path.join(os.path.dirname(__file__), '..', 'json', 'crosswalk.json')
325
-
326
- # Determine paths based on command-line arguments or use defaults
327
- config_path = sys.argv[1] if len(sys.argv) > 1 else default_config_path
328
395
  crosswalk_path = sys.argv[2] if len(sys.argv) > 2 else default_crosswalk_path
329
396
 
330
397
  e_state = ExecutionState(config_path, crosswalk_path)
331
398
 
332
- print("Loading CSV Data...")
399
+ # Initialize constants from config
400
+ MediBot_Preprocessor_lib.initialize(e_state.config)
401
+
402
+ if PERFORMANCE_LOGGING:
403
+ print("Loading CSV Data...")
333
404
  MediLink_ConfigLoader.log("Loading CSV Data...", level="INFO")
334
- csv_data = load_csv_data(CSV_FILE_PATH)
405
+ csv_data = MediBot_Preprocessor_lib.load_csv_data(MediBot_Preprocessor_lib.CSV_FILE_PATH)
335
406
 
336
407
  # Pre-process CSV data to add combined fields & crosswalk values
337
- print("Pre-Processing CSV...")
408
+ if PERFORMANCE_LOGGING:
409
+ print("Pre-Processing CSV...")
338
410
  MediLink_ConfigLoader.log("Pre-processing CSV Data...", level="INFO")
411
+
412
+ # TIMING: Start CSV preprocessing timing
413
+ preprocessing_start_time = time.time()
414
+ if PERFORMANCE_LOGGING:
415
+ print("Starting CSV preprocessing at: {}".format(time.strftime("%H:%M:%S")))
416
+ MediLink_ConfigLoader.log("Starting CSV preprocessing at: {}".format(time.strftime("%H:%M:%S")), level="INFO")
417
+
339
418
  MediBot_Preprocessor.preprocess_csv_data(csv_data, e_state.crosswalk)
419
+
420
+ # TIMING: End CSV preprocessing timing
421
+ preprocessing_end_time = time.time()
422
+ preprocessing_duration = preprocessing_end_time - preprocessing_start_time
423
+ if PERFORMANCE_LOGGING:
424
+ print("CSV preprocessing completed at: {} (Duration: {:.2f} seconds)".format(
425
+ time.strftime("%H:%M:%S"), preprocessing_duration))
426
+ MediLink_ConfigLoader.log("CSV preprocessing completed at: {} (Duration: {:.2f} seconds)".format(
427
+ time.strftime("%H:%M:%S"), preprocessing_duration), level="INFO")
428
+
340
429
  headers = csv_data[0].keys() # Ensure all headers are in place
341
430
 
342
431
  print("Performing Intake Scan...")
343
432
  MediLink_ConfigLoader.log("Performing Intake Scan...", level="INFO")
344
- identified_fields = MediBot_Preprocessor.intake_scan(headers, field_mapping)
433
+ identified_fields = MediBot_Preprocessor.intake_scan(headers, MediBot_Preprocessor_lib.field_mapping)
345
434
 
346
435
  # Reverse the identified_fields mapping for lookup
347
436
  reverse_mapping = {v: k for k, v in identified_fields.items()}
@@ -353,7 +442,10 @@ if __name__ == "__main__":
353
442
  print("Load Complete...")
354
443
  MediLink_ConfigLoader.log("Load Complete event triggered. Clearing console. Displaying Menu...", level="INFO")
355
444
  # Windows XP console buffer fix: Use cls with echo to reset buffer state
356
- _ = os.system('cls && echo.')
445
+ # Add a debug switch to optionally skip clearing the console for debugging purposes
446
+ CLEAR_CONSOLE_ON_LOAD = False # Set to False to keep previous output visible for debugging
447
+ if CLEAR_CONSOLE_ON_LOAD:
448
+ _ = os.system('cls && echo.')
357
449
 
358
450
  proceed, selected_patient_ids, selected_indices, fixed_values = user_interaction(csv_data, interaction_mode, error_message, reverse_mapping)
359
451
 
@@ -417,7 +509,7 @@ if __name__ == "__main__":
417
509
  open_medisoft(app_control.get_medisoft_shortcut())
418
510
  app_control.set_pause_status(True)
419
511
  _ = manage_script_pause(csv_data, error_message, reverse_mapping)
420
- data_entry_loop(csv_data, field_mapping, reverse_mapping, fixed_values)
512
+ data_entry_loop(csv_data, MediBot_Preprocessor_lib.field_mapping, reverse_mapping, fixed_values)
421
513
  cleanup()
422
514
  else:
423
515
  print("Data entry canceled by user. Exiting MediBot.")