medicafe 0.240415.1__tar.gz → 0.240517.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.240517.0/MANIFEST.in +2 -0
- medicafe-0.240517.0/MediBot/MediBot.bat +198 -0
- medicafe-0.240517.0/MediBot/MediBot.py +346 -0
- medicafe-0.240517.0/MediBot/MediBot_Charges.py +28 -0
- medicafe-0.240517.0/MediBot/MediBot_Crosswalk_Library.py +280 -0
- medicafe-0.240517.0/MediBot/MediBot_Preprocessor.py +247 -0
- medicafe-0.240517.0/MediBot/MediBot_Preprocessor_lib.py +357 -0
- medicafe-0.240517.0/MediBot/MediBot_UI.py +240 -0
- medicafe-0.240517.0/MediBot/MediBot_dataformat_library.py +198 -0
- medicafe-0.240517.0/MediBot/MediBot_docx_decoder.py +80 -0
- medicafe-0.240517.0/MediBot/MediPost.py +5 -0
- medicafe-0.240517.0/MediBot/PDF_to_CSV_Cleaner.py +211 -0
- medicafe-0.240517.0/MediBot/__init__.py +0 -0
- medicafe-0.240517.0/MediBot/update_json.py +43 -0
- medicafe-0.240517.0/MediBot/update_medicafe.py +57 -0
- medicafe-0.240517.0/MediLink/MediLink.py +381 -0
- medicafe-0.240517.0/MediLink/MediLink_277_decoder.py +92 -0
- medicafe-0.240517.0/MediLink/MediLink_837p_encoder.py +502 -0
- medicafe-0.240517.0/MediLink/MediLink_837p_encoder_library.py +890 -0
- medicafe-0.240517.0/MediLink/MediLink_API_v2.py +174 -0
- medicafe-0.240517.0/MediLink/MediLink_APIs.py +137 -0
- medicafe-0.240517.0/MediLink/MediLink_ConfigLoader.py +81 -0
- medicafe-0.240517.0/MediLink/MediLink_DataMgmt.py +258 -0
- medicafe-0.240517.0/MediLink/MediLink_Down.py +128 -0
- medicafe-0.240517.0/MediLink/MediLink_ERA_decoder.py +192 -0
- medicafe-0.240517.0/MediLink/MediLink_Gmail.py +100 -0
- medicafe-0.240517.0/MediLink/MediLink_Mailer.py +7 -0
- medicafe-0.240517.0/MediLink/MediLink_Scheduler.py +173 -0
- medicafe-0.240517.0/MediLink/MediLink_StatusCheck.py +4 -0
- medicafe-0.240517.0/MediLink/MediLink_UI.py +118 -0
- medicafe-0.240517.0/MediLink/MediLink_Up.py +383 -0
- medicafe-0.240517.0/MediLink/MediLink_batch.bat +7 -0
- medicafe-0.240517.0/MediLink/Soumit_api.py +22 -0
- medicafe-0.240517.0/MediLink/__init__.py +0 -0
- medicafe-0.240517.0/MediLink/test.py +74 -0
- medicafe-0.240517.0/PKG-INFO +48 -0
- medicafe-0.240517.0/README.md +42 -0
- medicafe-0.240517.0/medicafe.egg-info/PKG-INFO +48 -0
- medicafe-0.240517.0/medicafe.egg-info/SOURCES.txt +44 -0
- medicafe-0.240517.0/medicafe.egg-info/requires.txt +5 -0
- medicafe-0.240517.0/medicafe.egg-info/top_level.txt +2 -0
- medicafe-0.240517.0/setup.py +63 -0
- medicafe-0.240415.1/PKG-INFO +0 -17
- medicafe-0.240415.1/README.md +0 -28
- medicafe-0.240415.1/medicafe.egg-info/PKG-INFO +0 -17
- medicafe-0.240415.1/medicafe.egg-info/SOURCES.txt +0 -9
- medicafe-0.240415.1/medicafe.egg-info/requires.txt +0 -4
- medicafe-0.240415.1/medicafe.egg-info/top_level.txt +0 -1
- medicafe-0.240415.1/setup.py +0 -22
- {medicafe-0.240415.1 → medicafe-0.240517.0}/LICENSE +0 -0
- {medicafe-0.240415.1 → medicafe-0.240517.0}/medicafe.egg-info/dependency_links.txt +0 -0
- {medicafe-0.240415.1 → medicafe-0.240517.0}/medicafe.egg-info/not-zip-safe +0 -0
- {medicafe-0.240415.1 → medicafe-0.240517.0}/setup.cfg +0 -0
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
@echo off
|
|
2
|
+
setlocal enabledelayedexpansion
|
|
3
|
+
|
|
4
|
+
:: Define paths
|
|
5
|
+
set "source_folder=C:\MEDIANSI\MediCare"
|
|
6
|
+
set "target_folder=C:\MEDIANSI\MediCare\CSV"
|
|
7
|
+
set "config_file=F:\Medibot\json\config.json"
|
|
8
|
+
set "python_script=C:\Python34\Lib\site-packages\MediBot\update_json.py"
|
|
9
|
+
set "python_script2=C:\Python34\Lib\site-packages\MediBot\Medibot.py"
|
|
10
|
+
set "medicafe_package=medicafe"
|
|
11
|
+
set "upgrade_medicafe=F:\Medibot\update_medicafe.py"
|
|
12
|
+
set "temp_file=F:\Medibot\last_update_timestamp.txt"
|
|
13
|
+
set "firefox_path=C:\Program Files\Mozilla Firefox\firefox.exe"
|
|
14
|
+
set "package_version="
|
|
15
|
+
set PYTHONWARNINGS=ignore
|
|
16
|
+
|
|
17
|
+
:: Check if Python is installed and the path is correctly set
|
|
18
|
+
python --version >nul 2>&1
|
|
19
|
+
if %errorlevel% neq 0 (
|
|
20
|
+
echo Python is not installed or not added to PATH.
|
|
21
|
+
exit /b
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
:: Check if the MediCafe package is installed and retrieve its version
|
|
25
|
+
echo Checking for installed MediCafe package version...
|
|
26
|
+
python -c "import pkg_resources; print('MediCafe=='+pkg_resources.get_distribution('medicafe').version)" > temp.txt 2>nul
|
|
27
|
+
set /p package_version=<temp.txt
|
|
28
|
+
del temp.txt
|
|
29
|
+
|
|
30
|
+
if not defined package_version (
|
|
31
|
+
echo MediCafe package version not detected or MediCafe not installed. Consider manual re-install.
|
|
32
|
+
exit /b
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
:: Extract version number and display it
|
|
36
|
+
for /f "tokens=2 delims==" %%a in ("%package_version%") do (
|
|
37
|
+
set "medicafe_version=%%a"
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
if not defined medicafe_version (
|
|
41
|
+
echo Failed to detect MediCafe version.
|
|
42
|
+
) else (
|
|
43
|
+
echo Detected MediCafe version: %medicafe_version%
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
:: Check for internet connectivity
|
|
47
|
+
ping -n 1 google.com > nul 2>&1
|
|
48
|
+
if %ERRORLEVEL% neq 0 (
|
|
49
|
+
set "internet_available=0"
|
|
50
|
+
echo No internet connection detected.
|
|
51
|
+
) else (
|
|
52
|
+
set "internet_available=1"
|
|
53
|
+
echo Internet connection detected.
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
:: Common pre-menu setup
|
|
57
|
+
echo Setting up the environment...
|
|
58
|
+
if not exist "%config_file%" (
|
|
59
|
+
echo Configuration file missing.
|
|
60
|
+
goto end_script
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
:: Check if the file exists and attempt to move it
|
|
64
|
+
:: Implementing a check with copy as a fallback if move fails
|
|
65
|
+
echo Checking for the upgrade script...
|
|
66
|
+
if exist "C:\Python34\Lib\site-packages\MediBot\upgrade_medicafe.py" (
|
|
67
|
+
echo Found upgrade_medicafe.py. Attempting to move...
|
|
68
|
+
move "C:\Python34\Lib\site-packages\MediBot\upgrade_medicafe.py" "F:\Medibot\upgrade_medicafe.py" >nul 2>&1
|
|
69
|
+
if %errorlevel% neq 0 (
|
|
70
|
+
echo Move failed. Attempting copy and delete as fallback...
|
|
71
|
+
copy "C:\Python34\Lib\site-packages\MediBot\upgrade_medicafe.py" "F:\Medibot\upgrade_medicafe.py" >nul 2>&1
|
|
72
|
+
if %errorlevel% neq 0 (
|
|
73
|
+
echo Copy failed. Error Level: %errorlevel%
|
|
74
|
+
) else (
|
|
75
|
+
del "C:\Python34\Lib\site-packages\MediBot\upgrade_medicafe.py" >nul 2>&1
|
|
76
|
+
if %errorlevel% neq 0 (
|
|
77
|
+
echo Delete failed. Manual cleanup may be required.
|
|
78
|
+
) else (
|
|
79
|
+
echo File copied and original deleted successfully.
|
|
80
|
+
)
|
|
81
|
+
)
|
|
82
|
+
) else (
|
|
83
|
+
echo File moved successfully.
|
|
84
|
+
)
|
|
85
|
+
) else (
|
|
86
|
+
echo upgrade_medicafe.py not detected. Check path and filename.
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
:: Main menu
|
|
90
|
+
:main_menu
|
|
91
|
+
cls
|
|
92
|
+
echo version: %medicafe_version%
|
|
93
|
+
echo --------------------------------------------------------------
|
|
94
|
+
echo .//* Welcome to MediCafe *\\.
|
|
95
|
+
echo --------------------------------------------------------------
|
|
96
|
+
echo.
|
|
97
|
+
echo Please select an option:
|
|
98
|
+
if "!internet_available!"=="1" (
|
|
99
|
+
echo 1. Check for MediCafe Package Updates
|
|
100
|
+
echo 2. Download Email de Carol
|
|
101
|
+
echo 3. MediLink Claims
|
|
102
|
+
)
|
|
103
|
+
echo 4. Run MediBot
|
|
104
|
+
echo 5. Exit
|
|
105
|
+
echo.
|
|
106
|
+
set /p choice=Enter your choice:
|
|
107
|
+
|
|
108
|
+
if "!choice!"=="5" goto end_script
|
|
109
|
+
if "!choice!"=="4" goto medibot_flow
|
|
110
|
+
if "!choice!"=="3" goto medilink_flow
|
|
111
|
+
if "!choice!"=="2" goto download_emails
|
|
112
|
+
if "!choice!"=="1" goto check_updates
|
|
113
|
+
|
|
114
|
+
:: Medicafe Update
|
|
115
|
+
:check_updates
|
|
116
|
+
if "!internet_available!"=="0" (
|
|
117
|
+
echo No internet connection available.
|
|
118
|
+
goto main_menu
|
|
119
|
+
)
|
|
120
|
+
echo Checking for MediCafe package updates. Please wait...
|
|
121
|
+
start cmd /c py "%upgrade_medicafe%" > upgrade_log.txt 2>&1 && (
|
|
122
|
+
echo %DATE% %TIME% Upgrade initiated. >> "%temp_file%"
|
|
123
|
+
echo Exiting batch to complete the upgrade.
|
|
124
|
+
) || (
|
|
125
|
+
echo %DATE% %TIME% Update failed. Check logs. >> upgrade_log.txt
|
|
126
|
+
)
|
|
127
|
+
exit /b
|
|
128
|
+
|
|
129
|
+
:: Download Carol's Emails
|
|
130
|
+
:download_emails
|
|
131
|
+
if "!internet_available!"=="0" (
|
|
132
|
+
echo No internet connection available.
|
|
133
|
+
goto main_menu
|
|
134
|
+
)
|
|
135
|
+
echo Downloading emails...
|
|
136
|
+
py "../MediLink/MediLink_Gmail.py" "%firefox_path%"
|
|
137
|
+
if errorlevel 1 (
|
|
138
|
+
echo Failed to download emails.
|
|
139
|
+
pause
|
|
140
|
+
) else (
|
|
141
|
+
echo Calling CSV Processor...
|
|
142
|
+
call :process_csvs
|
|
143
|
+
)
|
|
144
|
+
goto main_menu
|
|
145
|
+
|
|
146
|
+
:: Run MediBot Flow
|
|
147
|
+
:medibot_flow
|
|
148
|
+
call :process_csvs
|
|
149
|
+
cls
|
|
150
|
+
echo Please wait...
|
|
151
|
+
py "%python_script2%" "%config_file%"
|
|
152
|
+
if errorlevel 1 echo Failed to run MediBot.
|
|
153
|
+
pause
|
|
154
|
+
goto main_menu
|
|
155
|
+
|
|
156
|
+
:: Continue to MediLink
|
|
157
|
+
:medilink_flow
|
|
158
|
+
if "!internet_available!"=="0" (
|
|
159
|
+
echo No internet connection available.
|
|
160
|
+
goto main_menu
|
|
161
|
+
)
|
|
162
|
+
call :process_csvs
|
|
163
|
+
cls
|
|
164
|
+
py "C:\Python34\Lib\site-packages\MediLink\MediLink.py"
|
|
165
|
+
if errorlevel 1 echo MediLink failed to execute.
|
|
166
|
+
pause
|
|
167
|
+
goto main_menu
|
|
168
|
+
|
|
169
|
+
:: Process CSV Files
|
|
170
|
+
:process_csvs
|
|
171
|
+
for /f "tokens=1-5 delims=/: " %%a in ('echo %time%') do (
|
|
172
|
+
set "hour=%%a"
|
|
173
|
+
set "minute=%%b"
|
|
174
|
+
set "second=%%c"
|
|
175
|
+
)
|
|
176
|
+
set "timestamp=%DATE:~-4%%DATE:~3,2%%DATE:~0,2%_%hour%%minute%"
|
|
177
|
+
set "latest_csv="
|
|
178
|
+
for /f "delims=" %%a in ('dir /b /a-d /o-d "%source_folder%\*.csv" 2^>nul') do (
|
|
179
|
+
set "latest_csv=%%a"
|
|
180
|
+
echo Found New CSV Files...
|
|
181
|
+
goto process_found_csv
|
|
182
|
+
)
|
|
183
|
+
::echo CSV Check Complete.
|
|
184
|
+
goto :eof
|
|
185
|
+
|
|
186
|
+
:process_found_csv
|
|
187
|
+
echo Processing CSVs...
|
|
188
|
+
move "%source_folder%\!latest_csv!" "%target_folder%\SX_CSV_!timestamp!.csv"
|
|
189
|
+
set "new_csv_path=%target_folder%\SX_CSV_!timestamp!.csv"
|
|
190
|
+
py "%python_script%" "%config_file%" "!new_csv_path!"
|
|
191
|
+
echo CSV Processor Complete...
|
|
192
|
+
goto :eof
|
|
193
|
+
|
|
194
|
+
:: Exit Script
|
|
195
|
+
:end_script
|
|
196
|
+
echo Exiting MediCafe.
|
|
197
|
+
pause
|
|
198
|
+
exit /b
|
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
import subprocess
|
|
2
|
+
import os
|
|
3
|
+
import tempfile
|
|
4
|
+
import traceback
|
|
5
|
+
import re #for addresses
|
|
6
|
+
from collections import OrderedDict
|
|
7
|
+
import MediBot_dataformat_library
|
|
8
|
+
import MediBot_Preprocessor
|
|
9
|
+
from MediBot_Preprocessor_lib import initialize, AHK_EXECUTABLE, CSV_FILE_PATH, field_mapping, load_csv_data
|
|
10
|
+
from MediBot_UI import app_control, manage_script_pause, user_interaction
|
|
11
|
+
|
|
12
|
+
# Add parent directory of the project to the Python path
|
|
13
|
+
import sys
|
|
14
|
+
project_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
|
|
15
|
+
sys.path.append(project_dir)
|
|
16
|
+
|
|
17
|
+
from MediLink import MediLink_ConfigLoader
|
|
18
|
+
|
|
19
|
+
try:
|
|
20
|
+
from MediBot_Crosswalk_Library import crosswalk_update
|
|
21
|
+
except ImportError:
|
|
22
|
+
from MediBot import MediBot_Crosswalk_Library
|
|
23
|
+
crosswalk_update = MediBot_Crosswalk_Library.crosswalk_update
|
|
24
|
+
|
|
25
|
+
"""
|
|
26
|
+
# Development Task List for MediBot
|
|
27
|
+
|
|
28
|
+
Error Handling Improvements
|
|
29
|
+
- [ ] Its really difficult to get out of the main menu if you go open MediBot by accident
|
|
30
|
+
- [ ] Develop a centralized error handling and logging mechanism for improved troubleshooting.
|
|
31
|
+
- [ ] Implement validation checks during patient data entry to prevent submission of incomplete or incorrect records.
|
|
32
|
+
|
|
33
|
+
Insurance Mode Adjustments
|
|
34
|
+
- [ ] Integrate a comprehensive list of insurance company codes for automatic selection.
|
|
35
|
+
- [ ] Automate insurance-specific data entry adjustments, such as character replacements specific to Medicare.
|
|
36
|
+
|
|
37
|
+
Diagnosis Entry
|
|
38
|
+
- [ ] Automate data extraction from Surgery Schedule to import to CSV a column indicating diagnosis code per px.
|
|
39
|
+
|
|
40
|
+
Script Efficiency and Reliability
|
|
41
|
+
- [ ] Ensure robust handling of Medisoft's field navigation quirks, particularly for fields that are skipped or require special access.
|
|
42
|
+
|
|
43
|
+
Documentation and Support
|
|
44
|
+
- [ ] Create detailed documentation for setup, configuration, and usage of the script.
|
|
45
|
+
- [ ] Establish a support channel for users to report issues or request features.
|
|
46
|
+
|
|
47
|
+
Future Directions
|
|
48
|
+
- [ ] Consider developing a graphical user interface (GUI) for non-technical users for easier script management and execution.
|
|
49
|
+
|
|
50
|
+
Medisoft Field Navigation:
|
|
51
|
+
Investigate and optimize navigation for fields that Medisoft skips or requires backward navigation to access.
|
|
52
|
+
|
|
53
|
+
Insurance Mode Features:
|
|
54
|
+
Evaluate the feasibility and implement the use of the F6 search for insurance address verification, enhancing user verification processes.
|
|
55
|
+
|
|
56
|
+
Error Handling and Logging:
|
|
57
|
+
Implement a check for AHK script execution status, providing feedback or troubleshooting steps if the script encounters issues.
|
|
58
|
+
"""
|
|
59
|
+
|
|
60
|
+
def identify_field(header, field_mapping):
|
|
61
|
+
for medisoft_field, patterns in field_mapping.items():
|
|
62
|
+
for pattern in patterns:
|
|
63
|
+
if re.search(pattern, header, re.IGNORECASE):
|
|
64
|
+
return medisoft_field
|
|
65
|
+
return None
|
|
66
|
+
|
|
67
|
+
# Add this print to a function that is calling identify_field
|
|
68
|
+
#print("Warning: No matching field found for CSV header '{}'".format(header))
|
|
69
|
+
|
|
70
|
+
# Function to execute an AutoHotkey script
|
|
71
|
+
def run_ahk_script(script_content):
|
|
72
|
+
temp_script_name = None
|
|
73
|
+
try:
|
|
74
|
+
# Create a temporary AHK script file
|
|
75
|
+
with tempfile.NamedTemporaryFile(delete=False, suffix='.ahk') as temp_script:
|
|
76
|
+
temp_script_name = temp_script.name
|
|
77
|
+
temp_script.write(script_content.encode('utf-8'))
|
|
78
|
+
temp_script.flush()
|
|
79
|
+
# Attempt to run the AHK script
|
|
80
|
+
subprocess.check_call([AHK_EXECUTABLE, temp_script_name])
|
|
81
|
+
except subprocess.CalledProcessError as e:
|
|
82
|
+
# This exception will catch any non-zero exit status from the AHK script
|
|
83
|
+
print("AHK script failed with exit status:", e.returncode)
|
|
84
|
+
print("Output from AHK script:", e.output)
|
|
85
|
+
except Exception as e:
|
|
86
|
+
# This catches any other exceptions that may occur
|
|
87
|
+
print("An unexpected error occurred while running the AHK script:", e)
|
|
88
|
+
traceback.print_exc() # Print the stack trace of the exception
|
|
89
|
+
finally:
|
|
90
|
+
# Delete the temporary script file
|
|
91
|
+
if temp_script_name:
|
|
92
|
+
try:
|
|
93
|
+
os.unlink(temp_script_name)
|
|
94
|
+
except OSError as e:
|
|
95
|
+
print("Error deleting temporary script file:", e)
|
|
96
|
+
|
|
97
|
+
# Global variable to store the last processed entry
|
|
98
|
+
last_processed_entry = None
|
|
99
|
+
# Global variable to store temporarily parsed address components
|
|
100
|
+
parsed_address_components = {}
|
|
101
|
+
|
|
102
|
+
def process_field(medisoft_field, csv_row, parsed_address_components, reverse_mapping, csv_data, fixed_values):
|
|
103
|
+
global last_processed_entry
|
|
104
|
+
|
|
105
|
+
try:
|
|
106
|
+
value = ''
|
|
107
|
+
if medisoft_field in parsed_address_components:
|
|
108
|
+
value = parsed_address_components.get(medisoft_field, '')
|
|
109
|
+
elif medisoft_field in fixed_values:
|
|
110
|
+
value = fixed_values[medisoft_field][0] # Use the fixed value
|
|
111
|
+
elif medisoft_field in reverse_mapping:
|
|
112
|
+
if medisoft_field == "Ins1 Insurance ID" or reverse_mapping[medisoft_field] == "Primary Insurance Company":
|
|
113
|
+
MediLink_ConfigLoader.log("Detected {} or {}: {}".format(medisoft_field, reverse_mapping[medisoft_field], value))
|
|
114
|
+
csv_header = reverse_mapping[medisoft_field]
|
|
115
|
+
value = csv_row.get(csv_header, '')
|
|
116
|
+
|
|
117
|
+
formatted_value = MediBot_dataformat_library.format_data(medisoft_field, value, csv_data, reverse_mapping, parsed_address_components) if value else 'Send, {Enter}'
|
|
118
|
+
run_ahk_script(formatted_value)
|
|
119
|
+
|
|
120
|
+
last_processed_entry = (medisoft_field, value)
|
|
121
|
+
return 'continue', last_processed_entry
|
|
122
|
+
except Exception as e:
|
|
123
|
+
return handle_error(e, medisoft_field, last_processed_entry, csv_data)
|
|
124
|
+
|
|
125
|
+
def handle_error(error, medisoft_field, last_processed_entry, csv_data):
|
|
126
|
+
MediLink_ConfigLoader.log("Error in process_field: ", e)
|
|
127
|
+
print("An error occurred while processing {0}: {1}".format(medisoft_field, error))
|
|
128
|
+
# Assuming the interaction mode is 'error' in this case
|
|
129
|
+
interaction_mode = 'error'
|
|
130
|
+
response = user_interaction(csv_data, interaction_mode, error, reverse_mapping)
|
|
131
|
+
return response, last_processed_entry
|
|
132
|
+
|
|
133
|
+
# iterating through each field defined in the field_mapping.
|
|
134
|
+
def iterate_fields(csv_row, field_mapping, parsed_address_components, reverse_mapping, csv_data, fixed_values):
|
|
135
|
+
global last_processed_entry
|
|
136
|
+
# Check for user action at the start of each field processing
|
|
137
|
+
for medisoft_field in field_mapping.keys():
|
|
138
|
+
action = manage_script_pause(csv_data,'',reverse_mapping) # per-field pause availability. Necessary to provide frequent opportunities for the user to pause the script.
|
|
139
|
+
if action != 0: # If action is either 'Retry' (-1) or 'Skip' (1)
|
|
140
|
+
return action # Break out and pass the action up
|
|
141
|
+
|
|
142
|
+
# Process each field in the row
|
|
143
|
+
_, last_processed_entry = process_field(medisoft_field, csv_row, parsed_address_components, reverse_mapping, csv_data, fixed_values)
|
|
144
|
+
|
|
145
|
+
return 0 # Default action to continue
|
|
146
|
+
|
|
147
|
+
def data_entry_loop(csv_data, field_mapping, reverse_mapping, fixed_values):
|
|
148
|
+
global last_processed_entry, parsed_address_components
|
|
149
|
+
# last_processed_entry, parsed_address_components = None, {} // BUG should this just be this line rather than the global line above?
|
|
150
|
+
error_message = '' # Initialize error_message once
|
|
151
|
+
current_row_index = 0
|
|
152
|
+
|
|
153
|
+
while current_row_index < len(csv_data):
|
|
154
|
+
row = csv_data[current_row_index]
|
|
155
|
+
|
|
156
|
+
# Handle script pause at the start of each row (patient record).
|
|
157
|
+
manage_script_pause(csv_data, error_message, reverse_mapping)
|
|
158
|
+
error_message = '' # Clear error message for the next iteration
|
|
159
|
+
|
|
160
|
+
if app_control.get_pause_status():
|
|
161
|
+
continue # Skip processing this row if the script is paused
|
|
162
|
+
|
|
163
|
+
# I feel like this is overwriting what would have already been idenfitied in the mapping.
|
|
164
|
+
# This probably needs to be initialized differently.
|
|
165
|
+
# parsed_address_components = {'City': '', 'State': '', 'Zip Code': ''}
|
|
166
|
+
parsed_address_components = {}
|
|
167
|
+
|
|
168
|
+
# Process each field in the row
|
|
169
|
+
action = iterate_fields(row, field_mapping, parsed_address_components, reverse_mapping, csv_data, fixed_values)
|
|
170
|
+
# TODO (Low) add a feature here where if you accidentally started overwriting a patient that you could go back 2 patients.
|
|
171
|
+
# Need to tell the user which patient we're talking about because it won't be obvious anymore.
|
|
172
|
+
if action == -1: # Retry
|
|
173
|
+
continue # Remain on the current row.
|
|
174
|
+
elif action == 1: # Skip
|
|
175
|
+
if current_row_index == len(csv_data) - 1: # If it's the last row
|
|
176
|
+
MediLink_ConfigLoader.log("Reached the end of the patient list.")
|
|
177
|
+
print("Reached the end of the patient list. Looping back to the beginning.")
|
|
178
|
+
current_row_index = 0 # Reset to the first row
|
|
179
|
+
else:
|
|
180
|
+
current_row_index += 1 # Move to the next row
|
|
181
|
+
continue
|
|
182
|
+
elif action == -2: # Go back two patients and redo
|
|
183
|
+
current_row_index = max(0, current_row_index - 2) # Go back two rows, but not below 0
|
|
184
|
+
continue
|
|
185
|
+
|
|
186
|
+
# Code to handle the end of a patient record
|
|
187
|
+
# TODO One day this can just not pause...
|
|
188
|
+
app_control.set_pause_status(True) # Pause at the end of processing each patient record
|
|
189
|
+
current_row_index += 1 # Move to the next row by default
|
|
190
|
+
|
|
191
|
+
def open_medisoft(shortcut_path):
|
|
192
|
+
try:
|
|
193
|
+
os.startfile(shortcut_path)
|
|
194
|
+
print("Medisoft is being opened...\n")
|
|
195
|
+
except subprocess.CalledProcessError as e:
|
|
196
|
+
print("Failed to open Medisoft:", e)
|
|
197
|
+
print("Please manually open Medisoft.")
|
|
198
|
+
except Exception as e:
|
|
199
|
+
print("An unexpected error occurred:", e)
|
|
200
|
+
print("Please manually open Medisoft.")
|
|
201
|
+
finally:
|
|
202
|
+
print("Press 'F12' to begin data entry.")
|
|
203
|
+
|
|
204
|
+
# Placeholder for any cleanup
|
|
205
|
+
def cleanup():
|
|
206
|
+
print("\n**** Medibot Finished! ****\n")
|
|
207
|
+
# THis might need to delete the staging stuff that gets set up by mostly MediLink but maybe other stuff too.
|
|
208
|
+
pass
|
|
209
|
+
|
|
210
|
+
class ExecutionState:
|
|
211
|
+
def __init__(self, config_path, crosswalk_path) -> None:
|
|
212
|
+
try:
|
|
213
|
+
config, crosswalk = MediLink_ConfigLoader.load_configuration(config_path, crosswalk_path)
|
|
214
|
+
self.verify_config_type(config)
|
|
215
|
+
self.crosswalk = crosswalk
|
|
216
|
+
self.config = config
|
|
217
|
+
MediLink_ConfigLoader.log("Config loaded successfully...")
|
|
218
|
+
|
|
219
|
+
crosswalk_update(config, crosswalk)
|
|
220
|
+
MediLink_ConfigLoader.log("Crosswalk update complete...")
|
|
221
|
+
|
|
222
|
+
initialize(config)
|
|
223
|
+
MediLink_ConfigLoader.log("Constants initialized...")
|
|
224
|
+
|
|
225
|
+
except Exception as e:
|
|
226
|
+
print("Failed to load or update configuration: {}".format(e))
|
|
227
|
+
raise # Re-throwing the exception or using a more sophisticated error handling mechanism might be needed
|
|
228
|
+
# Handle the exception somehow (e.g., retry, halt, log)??
|
|
229
|
+
|
|
230
|
+
def verify_config_type(self, config):
|
|
231
|
+
if not isinstance(config, (dict, OrderedDict)):
|
|
232
|
+
raise TypeError("Error: Configuration must be a dictionary or an OrderedDict. Check unpacking.")
|
|
233
|
+
|
|
234
|
+
# Main script execution wrapped in try-except for error handling
|
|
235
|
+
if __name__ == "__main__":
|
|
236
|
+
e_state = None
|
|
237
|
+
try:
|
|
238
|
+
print("Please wait...")
|
|
239
|
+
# Default paths
|
|
240
|
+
default_config_path = os.path.join(os.path.dirname(__file__), '..', 'json', 'config.json')
|
|
241
|
+
default_crosswalk_path = os.path.join(os.path.dirname(__file__), '..', 'json', 'crosswalk.json')
|
|
242
|
+
|
|
243
|
+
# Check if command-line arguments are provided
|
|
244
|
+
if len(sys.argv) > 1:
|
|
245
|
+
# If arguments are provided, use them
|
|
246
|
+
config_path = sys.argv[1]
|
|
247
|
+
crosswalk_path = sys.argv[2] if len(sys.argv) > 2 else default_crosswalk_path
|
|
248
|
+
else:
|
|
249
|
+
# If no arguments are provided, use default paths
|
|
250
|
+
config_path = default_config_path
|
|
251
|
+
crosswalk_path = default_crosswalk_path
|
|
252
|
+
|
|
253
|
+
e_state = ExecutionState(config_path, crosswalk_path)
|
|
254
|
+
|
|
255
|
+
print("Loading CSV Data...")
|
|
256
|
+
MediLink_ConfigLoader.log("Loading CSV Data...", level="INFO")
|
|
257
|
+
csv_data = load_csv_data(CSV_FILE_PATH)
|
|
258
|
+
|
|
259
|
+
# Pre-process CSV data to add combined fields & crosswalk values.
|
|
260
|
+
print("Pre-Processing CSV...")
|
|
261
|
+
MediLink_ConfigLoader.log("Pre-processing CSV Data...", level="INFO")
|
|
262
|
+
MediBot_Preprocessor.preprocess_csv_data(csv_data, e_state.crosswalk)
|
|
263
|
+
headers = csv_data[0].keys() # Make sure all the headers are in place
|
|
264
|
+
|
|
265
|
+
print("Performing Intake Scan...")
|
|
266
|
+
MediLink_ConfigLoader.log("Performing Intake Scan...", level="INFO")
|
|
267
|
+
# identified_fields is an OrderedDict
|
|
268
|
+
identified_fields = MediBot_Preprocessor.intake_scan(headers, field_mapping)
|
|
269
|
+
|
|
270
|
+
# Reverse the identified_fields mapping for lookup
|
|
271
|
+
reverse_mapping = {v: k for k, v in identified_fields.items()}
|
|
272
|
+
# MediLink_ConfigLoader.log("Reverse Mapping: {}".format(reverse_mapping))
|
|
273
|
+
|
|
274
|
+
# CSV Patient Triage
|
|
275
|
+
interaction_mode = 'triage' # Start in triage mode
|
|
276
|
+
error_message = "" # This will be filled if an error has occurred
|
|
277
|
+
#print("Debug - Identified fields mapping (main): {}".format(identified_fields)) # Debug Line
|
|
278
|
+
|
|
279
|
+
print("Load Complete...")
|
|
280
|
+
_ = os.system('cls')
|
|
281
|
+
|
|
282
|
+
proceed, selected_patient_ids, selected_indices, fixed_values = user_interaction(csv_data, interaction_mode, error_message, reverse_mapping)
|
|
283
|
+
|
|
284
|
+
if proceed:
|
|
285
|
+
# Filter csv_data for selected patients from Triage mode.
|
|
286
|
+
csv_data = [row for index, row in enumerate(csv_data) if index in selected_indices]
|
|
287
|
+
|
|
288
|
+
# Check if MAPAT_MED_PATH is missing or blank
|
|
289
|
+
if not app_control.get_mapat_med_path() or not os.path.exists(app_control.get_mapat_med_path()):
|
|
290
|
+
print("Warning: MAPAT.MED PATH is missing or invalid. Please check the path configuration.")
|
|
291
|
+
|
|
292
|
+
# Perform the existing patients check
|
|
293
|
+
existing_patients, patients_to_process = MediBot_Preprocessor.check_existing_patients(selected_patient_ids, app_control.get_mapat_med_path())
|
|
294
|
+
|
|
295
|
+
if existing_patients:
|
|
296
|
+
print("\nNOTE: The following patient(s) already EXIST in the system and \n will be excluded from processing:")
|
|
297
|
+
for patient_id, patient_name in existing_patients:
|
|
298
|
+
print("(ID: {0}) {1}".format(patient_id, patient_name))
|
|
299
|
+
# Update csv_data to exclude existing patients
|
|
300
|
+
csv_data = [row for row in csv_data if row[reverse_mapping['Patient ID #2']] in patients_to_process]
|
|
301
|
+
else:
|
|
302
|
+
print("\nSelected patient(s) are NEW patients and will be processed.")
|
|
303
|
+
|
|
304
|
+
if len(patients_to_process) == 0:
|
|
305
|
+
proceed = input("\nAll patients have been processed. Continue anyway?: ").lower().strip() in ['yes', 'y']
|
|
306
|
+
else:
|
|
307
|
+
proceed = input("\nDo you want to proceed with the {} remaining patient(s)? (yes/no): ".format(len(patients_to_process))).lower().strip() in ['yes', 'y']
|
|
308
|
+
|
|
309
|
+
if proceed:
|
|
310
|
+
|
|
311
|
+
# Would be nice to have some kind of self-test here.
|
|
312
|
+
# print("\nDebug - Starting AHK script. Reload AHK if failed...")
|
|
313
|
+
# try:
|
|
314
|
+
# subprocess.call([AHK_EXECUTABLE, r"G:\My Drive\CocoWave\XP typing bot\notepad_test.ahk"])
|
|
315
|
+
# run_ahk_script('MsgBox, Test AHK Script Execution')
|
|
316
|
+
# except subprocess.CalledProcessError as e:
|
|
317
|
+
# print("Error running AHK script. Please reload AHK and try again. Error: {}".format(e))
|
|
318
|
+
# exit(1)
|
|
319
|
+
# except Exception as e:
|
|
320
|
+
# print("An unexpected error occurred while running the AHK script: {}".format(e))
|
|
321
|
+
# exit(1)
|
|
322
|
+
|
|
323
|
+
print("\nRemember, when in Medisoft:")
|
|
324
|
+
print(" Press 'F8' to create a New Patient.")
|
|
325
|
+
print(" Press 'F12' to begin data entry.")
|
|
326
|
+
print(" Press 'F11' at any time to Pause.")
|
|
327
|
+
input("\n*** Press [Enter] when ready to begin! ***\n")
|
|
328
|
+
MediLink_ConfigLoader.log("Opening Medisoft...")
|
|
329
|
+
open_medisoft(app_control.get_medisoft_shortcut())
|
|
330
|
+
app_control.set_pause_status(True)
|
|
331
|
+
_ = manage_script_pause(csv_data, error_message, reverse_mapping)
|
|
332
|
+
data_entry_loop(csv_data, field_mapping, reverse_mapping, fixed_values)
|
|
333
|
+
cleanup()
|
|
334
|
+
else:
|
|
335
|
+
print("Data entry canceled by user. Exiting MediBot.")
|
|
336
|
+
except Exception as e:
|
|
337
|
+
if e_state:
|
|
338
|
+
interaction_mode = 'error' # Switch to error mode
|
|
339
|
+
error_message = str(e) # Capture the error message
|
|
340
|
+
print("An error occurred while running MediBot: {0}".format(e))
|
|
341
|
+
# Handle the error by calling user interaction with the error information
|
|
342
|
+
# Ensure that identified_fields is defined before using it in user interaction
|
|
343
|
+
if 'identified_fields' in locals():
|
|
344
|
+
_ = user_interaction(csv_data, interaction_mode, error_message, reverse_mapping)
|
|
345
|
+
else:
|
|
346
|
+
print("Please ensure CSV headers match expected field names in config file, then re-run Medibot.")
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"""
|
|
2
|
+
MediBot_Charges.py
|
|
3
|
+
|
|
4
|
+
This module provides a helper function for MediBot.py, specifically designed to handle the charge entry process in Medisoft for patients undergoing cataract surgeries. Each patient typically undergoes procedures on both eyes, treated as separate procedures but often requiring price bundling to address patient preferences for consistent billing across both eyes.
|
|
5
|
+
|
|
6
|
+
Key Features:
|
|
7
|
+
- Handles up to 200 patients in a single batch, with typical usage around 20 patients.
|
|
8
|
+
- Implements price bundling logic to ensure that if a patient has multiple procedures (one for each eye), the charges are balanced such that the total cost is evenly spread across both procedures. This approach aligns with patient expectations of receiving consistent charges for each eye.
|
|
9
|
+
- Integrates pricing schedules from a configuration file for private insurance, which vary based on the duration of the procedure:
|
|
10
|
+
- $450 for 1-15 minutes
|
|
11
|
+
- $480 for 16-22 minutes
|
|
12
|
+
- $510 for 23-27 minutes
|
|
13
|
+
- $540 for 28-37 minutes
|
|
14
|
+
- $580 for 37-59 minutes (59 minutes being the maximum allowed duration)
|
|
15
|
+
- Special handling for Medicare patients, details of which are pending clarification.
|
|
16
|
+
|
|
17
|
+
Limitations:
|
|
18
|
+
- The bundling logic for commercial insurance billing is subject to the fulfillment of deductibles and other conditions, which do not necessarily synchronize with the timing of procedures for both eyes. The exact mechanics of this bundling under various conditions remain partially unspecified.
|
|
19
|
+
|
|
20
|
+
Usage:
|
|
21
|
+
- This module is intended to be used as part of the MediBot system, interfaced through MediBot.py, to automate the data entry and billing process in Medisoft for ophthalmology clinics, specifically those performing cataract surgeries.
|
|
22
|
+
|
|
23
|
+
Note:
|
|
24
|
+
- The exact implementation details for Medicare patients and the full logic for price bundling under all insurance conditions are yet to be finalized and documented.
|
|
25
|
+
|
|
26
|
+
Date:
|
|
27
|
+
- 4/16/24
|
|
28
|
+
"""
|