medicafe 0.250722.0__py3-none-any.whl → 0.250723.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.

MediBot/MediBot.py CHANGED
@@ -40,8 +40,42 @@ def identify_field(header, field_mapping):
40
40
  # Add this print to a function that is calling identify_field
41
41
  #print("Warning: No matching field found for CSV header '{}'".format(header))
42
42
 
43
+ # Global flag to control AHK execution method - set to True to use optimized stdin method
44
+ USE_AHK_STDIN_OPTIMIZATION = True
45
+
43
46
  # Function to execute an AutoHotkey script
44
47
  def run_ahk_script(script_content):
48
+ """
49
+ Execute an AutoHotkey script using either optimized stdin method or traditional file method.
50
+ Automatically falls back to file method if stdin method fails.
51
+ """
52
+ if USE_AHK_STDIN_OPTIMIZATION:
53
+ try:
54
+ # Optimized method: Execute AHK script via stdin pipe - eliminates temporary file creation
55
+ # Compatible with Windows XP and AutoHotkey v1.0.48+
56
+ process = subprocess.Popen(
57
+ [AHK_EXECUTABLE, '/f', '*'], # '/f *' tells AHK to read from stdin
58
+ stdin=subprocess.PIPE,
59
+ stdout=subprocess.PIPE,
60
+ stderr=subprocess.PIPE,
61
+ shell=False
62
+ )
63
+
64
+ # Send script content via stdin
65
+ stdout, stderr = process.communicate(input=script_content.encode('utf-8'))
66
+
67
+ if process.returncode != 0:
68
+ print("AHK script failed with exit status: {}".format(process.returncode)) # Log the exit status of the failed script
69
+ if stderr:
70
+ print("AHK Error: {}".format(stderr.decode('utf-8', errors='ignore')))
71
+ return # Success - no file cleanup needed
72
+
73
+ except Exception as e:
74
+ # If stdin method fails, fall back to traditional file method
75
+ print("AHK stdin execution failed, falling back to file method: {}".format(e))
76
+ # Continue to fallback implementation below
77
+
78
+ # Traditional file-based method (fallback or when optimization disabled)
45
79
  temp_script_name = None # Initialize variable to hold the name of the temporary script file
46
80
  try:
47
81
  # Create a temporary AHK script file
@@ -70,6 +104,8 @@ def run_ahk_script(script_content):
70
104
  last_processed_entry = None
71
105
  # Global variable to store temporarily parsed address components
72
106
  parsed_address_components = {}
107
+ # Global variable to store patient context for F11 menu (preserved across patients)
108
+ current_patient_context = None
73
109
 
74
110
  def process_field(medisoft_field, csv_row, parsed_address_components, reverse_mapping, csv_data, fixed_values):
75
111
  global last_processed_entry
@@ -107,8 +143,19 @@ def process_field(medisoft_field, csv_row, parsed_address_components, reverse_ma
107
143
  return handle_error(e, medisoft_field, last_processed_entry, csv_data)
108
144
 
109
145
  def handle_error(error, medisoft_field, last_processed_entry, csv_data):
146
+ global current_patient_context
110
147
  MediLink_ConfigLoader.log("Error in process_field: ", e)
111
148
  print("An error occurred while processing {0}: {1}".format(medisoft_field, error))
149
+
150
+ # Update patient context with current error information for F11 menu
151
+ if current_patient_context is None:
152
+ current_patient_context = {}
153
+ current_patient_context.update({
154
+ 'last_field': medisoft_field,
155
+ 'error_occurred': True,
156
+ 'error_message': str(error)
157
+ })
158
+
112
159
  # Assuming the interaction mode is 'error' in this case
113
160
  interaction_mode = 'error'
114
161
  response = user_interaction(csv_data, interaction_mode, error, reverse_mapping)
@@ -129,7 +176,7 @@ def iterate_fields(csv_row, field_mapping, parsed_address_components, reverse_ma
129
176
  return 0 # Default action to continue
130
177
 
131
178
  def data_entry_loop(csv_data, field_mapping, reverse_mapping, fixed_values):
132
- global last_processed_entry, parsed_address_components
179
+ global last_processed_entry, parsed_address_components, current_patient_context
133
180
  # last_processed_entry, parsed_address_components = None, {} // BUG should this just be this line rather than the global line above?
134
181
  error_message = '' # Initialize error_message once
135
182
  current_row_index = 0
@@ -137,6 +184,23 @@ def data_entry_loop(csv_data, field_mapping, reverse_mapping, fixed_values):
137
184
  while current_row_index < len(csv_data):
138
185
  row = csv_data[current_row_index]
139
186
 
187
+ # PERFORMANCE FIX: Clear accumulating memory while preserving F11 menu context
188
+ # Store patient context before clearing last_processed_entry for F11 "Retry last entry" functionality
189
+ if last_processed_entry is not None:
190
+ patient_name = row.get(reverse_mapping.get('Patient Name', ''), 'Unknown Patient')
191
+ surgery_date = row.get('Surgery Date', 'Unknown Date')
192
+ current_patient_context = {
193
+ 'patient_name': patient_name,
194
+ 'surgery_date': surgery_date,
195
+ 'last_field': last_processed_entry[0] if last_processed_entry else None,
196
+ 'last_value': last_processed_entry[1] if last_processed_entry else None,
197
+ 'row_index': current_row_index
198
+ }
199
+
200
+ # Clear memory-accumulating structures while preserving F11 context above
201
+ last_processed_entry = None
202
+ parsed_address_components = {}
203
+
140
204
  # Handle script pause at the start of each row (patient record).
141
205
  manage_script_pause(csv_data, error_message, reverse_mapping)
142
206
  error_message = '' # Clear error message for the next iteration
@@ -146,8 +210,9 @@ def data_entry_loop(csv_data, field_mapping, reverse_mapping, fixed_values):
146
210
 
147
211
  # I feel like this is overwriting what would have already been idenfitied in the mapping.
148
212
  # This probably needs to be initialized differently.
213
+ # Note: parsed_address_components is now explicitly cleared above for performance
149
214
  # parsed_address_components = {'City': '', 'State': '', 'Zip Code': ''}
150
- parsed_address_components = {}
215
+ # parsed_address_components = {} # Moved to top of loop for memory management
151
216
 
152
217
  # Process each field in the row
153
218
  action = iterate_fields(row, field_mapping, parsed_address_components, reverse_mapping, csv_data, fixed_values)
@@ -170,6 +235,14 @@ def data_entry_loop(csv_data, field_mapping, reverse_mapping, fixed_values):
170
235
  # Code to handle the end of a patient record
171
236
  # TODO One day this can just not pause...
172
237
  app_control.set_pause_status(True) # Pause at the end of processing each patient record
238
+
239
+ # PERFORMANCE FIX: Explicit cleanup at end of patient processing
240
+ # Clear global state to prevent accumulation over processing sessions
241
+ # Note: current_patient_context is preserved for F11 menu functionality
242
+ if current_row_index != len(csv_data) - 1: # Not the last patient
243
+ last_processed_entry = None
244
+ parsed_address_components.clear()
245
+
173
246
  current_row_index += 1 # Move to the next row by default
174
247
 
175
248
  def open_medisoft(shortcut_path):
@@ -481,13 +481,15 @@ def crosswalk_update(client, config, crosswalk, skip_known_payers=True): # Upstr
481
481
 
482
482
  crosswalk['payer_id'][payer_id] = {
483
483
  'endpoint': selected_endpoint,
484
- 'medisoft_id': set(), # Use set to store multiple IDs
485
- 'medisoft_medicare_id': set()
484
+ 'medisoft_id': [], # PERFORMANCE FIX: Use list instead of set to avoid conversions
485
+ 'medisoft_medicare_id': [] # PERFORMANCE FIX: Use list instead of set to avoid conversions
486
486
  }
487
487
  MediLink_ConfigLoader.log("Initialized payer ID {} in crosswalk with endpoint '{}'.".format(payer_id, selected_endpoint), config, level="DEBUG")
488
488
 
489
- # Add the insurance ID to the payer ID entry
490
- crosswalk['payer_id'][payer_id]['medisoft_id'].add(str(insurance_id)) # Ensure IDs are strings
489
+ # Add the insurance ID to the payer ID entry (PERFORMANCE FIX: Use list operations)
490
+ insurance_id_str = str(insurance_id) # Ensure ID is string
491
+ if insurance_id_str not in crosswalk['payer_id'][payer_id]['medisoft_id']:
492
+ crosswalk['payer_id'][payer_id]['medisoft_id'].append(insurance_id_str) # Avoid duplicates
491
493
  MediLink_ConfigLoader.log(
492
494
  "Added new insurance ID {} to payer ID {}.".format(insurance_id, payer_id),
493
495
  config,
@@ -517,14 +519,26 @@ def crosswalk_update(client, config, crosswalk, skip_known_payers=True): # Upstr
517
519
  fetch_and_store_payer_name(client, payer_id, crosswalk, config)
518
520
  MediLink_ConfigLoader.log("Successfully fetched and stored payer name for unknown payer_id: {}".format(payer_id), config, level="INFO")
519
521
 
520
- # Ensure multiple medisoft_id values are preserved by converting sets to sorted lists
522
+ # PERFORMANCE FIX: Optimized list management - avoid redundant set/list conversions
523
+ # Ensure multiple medisoft_id values are preserved and deduplicated efficiently
521
524
  for payer_id, details in crosswalk.get('payer_id', {}).items():
522
- if isinstance(details.get('medisoft_id'), set):
523
- crosswalk['payer_id'][payer_id]['medisoft_id'] = sorted(list(details['medisoft_id']))
524
- MediLink_ConfigLoader.log("Converted medisoft_id for payer ID {} to sorted list.".format(payer_id), config, level="DEBUG")
525
- if isinstance(details.get('medisoft_medicare_id'), set):
526
- crosswalk['payer_id'][payer_id]['medisoft_medicare_id'] = sorted(list(details['medisoft_medicare_id']))
527
- MediLink_ConfigLoader.log("Converted medisoft_medicare_id for payer ID {} to sorted list.".format(payer_id), config, level="DEBUG")
525
+ # Handle medisoft_id - convert sets to lists or deduplicate existing lists
526
+ medisoft_id = details.get('medisoft_id', [])
527
+ if isinstance(medisoft_id, set):
528
+ crosswalk['payer_id'][payer_id]['medisoft_id'] = sorted(list(medisoft_id))
529
+ MediLink_ConfigLoader.log("Converted medisoft_id set to sorted list for payer ID {}.".format(payer_id), config, level="DEBUG")
530
+ elif isinstance(medisoft_id, list) and medisoft_id:
531
+ # Remove duplicates using dict.fromkeys() - preserves order, O(n) performance
532
+ crosswalk['payer_id'][payer_id]['medisoft_id'] = list(dict.fromkeys(medisoft_id))
533
+
534
+ # Handle medisoft_medicare_id - convert sets to lists or deduplicate existing lists
535
+ medicare_id = details.get('medisoft_medicare_id', [])
536
+ if isinstance(medicare_id, set):
537
+ crosswalk['payer_id'][payer_id]['medisoft_medicare_id'] = sorted(list(medicare_id))
538
+ MediLink_ConfigLoader.log("Converted medisoft_medicare_id set to sorted list for payer ID {}.".format(payer_id), config, level="DEBUG")
539
+ elif isinstance(medicare_id, list) and medicare_id:
540
+ # Remove duplicates using dict.fromkeys() - preserves order, O(n) performance
541
+ crosswalk['payer_id'][payer_id]['medisoft_medicare_id'] = list(dict.fromkeys(medicare_id))
528
542
 
529
543
  MediLink_ConfigLoader.log("Crosswalk update process completed. Processed {} payer IDs.".format(len(patient_id_to_payer_id)), config, level="INFO")
530
544
  return save_crosswalk(client, config, crosswalk)
@@ -635,7 +649,7 @@ def update_crosswalk_with_new_payer_id(client, insurance_name, payer_id, config,
635
649
  # Ensure the 'payer_id' key exists in the crosswalk
636
650
  crosswalk['payer_id'][payer_id] = {
637
651
  'endpoint': selected_endpoint,
638
- 'medisoft_id': set(),
652
+ 'medisoft_id': [], # PERFORMANCE FIX: Use list instead of set to avoid conversions
639
653
  'medisoft_medicare_id': []
640
654
  }
641
655
  MediLink_ConfigLoader.log("Initialized payer ID {} in crosswalk with endpoint '{}'.".format(payer_id, selected_endpoint), config, level="DEBUG")