medicafe 0.251017.1__py3-none-any.whl → 0.251023.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
@@ -13,6 +13,11 @@ except ImportError:
13
13
  from collections import OrderedDict
14
14
  from datetime import datetime # Added for primary surgery date logic
15
15
  import MediBot_Notepad_Utils # For generating notepad files
16
+ try:
17
+ # Python 3.4.4 on XP does not have typing enhancements; avoid heavy typing usage
18
+ from collections import namedtuple
19
+ except Exception:
20
+ namedtuple = None
16
21
 
17
22
  # ============================================================================
18
23
  # MINIMAL PROTECTION: Import State Validation
@@ -390,15 +395,26 @@ def run_ahk_script(script_content):
390
395
  MediLink_ConfigLoader.log("Error deleting temporary script file: {}".format(e), level="ERROR")
391
396
  # Future Improvement: Implement a cleanup mechanism to handle orphaned temporary files
392
397
 
393
- # Global variable to store the last processed entry
398
+ # Module-scope context container for cross-callback state (XP/3.4.4 compatible)
399
+ try:
400
+ # Avoid dataclasses to maintain 3.4.4 compatibility without external deps
401
+ class MediBotContext(object):
402
+ def __init__(self):
403
+ self.last_processed_entry = None
404
+ self.parsed_address_components = {}
405
+ self.current_patient_context = None
406
+ CTX = MediBotContext()
407
+ except Exception:
408
+ # Fallback simple dict if class definition fails for any reason
409
+ CTX = {
410
+ 'last_processed_entry': None,
411
+ 'parsed_address_components': {},
412
+ 'current_patient_context': None,
413
+ }
414
+
415
+ # Backwards-compatible globals (maintain import contract for MediBot_UI and hotkeys)
394
416
  last_processed_entry = None
395
- # Global variable to store temporarily parsed address components
396
417
  parsed_address_components = {}
397
- # Global variable to store patient context for F11 menu (preserved across patients)
398
- # IMPORTANT: This must remain at module scope so that MediBot_UI can import/access it via
399
- # "from MediBot import current_patient_context" and so that F11 interactions reflect
400
- # the latest state across function boundaries. Switching to locals would break F11 and
401
- # other hotkey-driven flows that rely on module-level shared state.
402
418
  current_patient_context = None
403
419
 
404
420
  def process_field(medisoft_field, csv_row, parsed_address_components, reverse_mapping, csv_data, fixed_values):
@@ -431,14 +447,25 @@ def process_field(medisoft_field, csv_row, parsed_address_components, reverse_ma
431
447
 
432
448
  # Update the last processed entry with the current field and its value
433
449
  last_processed_entry = (medisoft_field, value)
450
+ try:
451
+ # Keep CTX in sync for consumers that adopt CTX
452
+ if hasattr(CTX, 'last_processed_entry'):
453
+ CTX.last_processed_entry = last_processed_entry
454
+ else:
455
+ CTX['last_processed_entry'] = last_processed_entry
456
+ except Exception:
457
+ pass
434
458
  return 'continue', last_processed_entry # Indicate to continue processing
435
459
  except Exception as e:
436
460
  # Handle any exceptions that occur during processing
437
- return handle_error(e, medisoft_field, last_processed_entry, csv_data)
461
+ return handle_error(e, medisoft_field, last_processed_entry, csv_data, reverse_mapping)
438
462
 
439
- def handle_error(error, medisoft_field, last_processed_entry, csv_data):
463
+ def handle_error(error, medisoft_field, last_processed_entry, csv_data, reverse_mapping):
440
464
  global current_patient_context
441
- MediLink_ConfigLoader.log("Error in process_field: ", e)
465
+ try:
466
+ MediLink_ConfigLoader.log("Error in process_field: {}".format(error), level="ERROR")
467
+ except Exception:
468
+ pass
442
469
  print("An error occurred while processing {0}: {1}".format(medisoft_field, error))
443
470
 
444
471
  # Update patient context with current error information for F11 menu
@@ -449,10 +476,17 @@ def handle_error(error, medisoft_field, last_processed_entry, csv_data):
449
476
  'error_occurred': True,
450
477
  'error_message': str(error)
451
478
  })
479
+ try:
480
+ if hasattr(CTX, 'current_patient_context'):
481
+ CTX.current_patient_context = current_patient_context
482
+ else:
483
+ CTX['current_patient_context'] = current_patient_context
484
+ except Exception:
485
+ pass
452
486
 
453
487
  # Assuming the interaction mode is 'error' in this case
454
488
  interaction_mode = 'error'
455
- response = user_interaction(csv_data, interaction_mode, error, reverse_mapping)
489
+ response = user_interaction(csv_data, interaction_mode, str(error), reverse_mapping)
456
490
  return response, last_processed_entry
457
491
 
458
492
  # iterating through each field defined in the field_mapping.
@@ -466,6 +500,13 @@ def iterate_fields(csv_row, field_mapping, parsed_address_components, reverse_ma
466
500
 
467
501
  # Process each field in the row
468
502
  _, last_processed_entry = process_field(medisoft_field, csv_row, parsed_address_components, reverse_mapping, csv_data, fixed_values)
503
+ try:
504
+ if hasattr(CTX, 'last_processed_entry'):
505
+ CTX.last_processed_entry = last_processed_entry
506
+ else:
507
+ CTX['last_processed_entry'] = last_processed_entry
508
+ except Exception:
509
+ pass
469
510
 
470
511
  return 0 # Default action to continue
471
512
 
@@ -494,10 +535,26 @@ def data_entry_loop(csv_data, field_mapping, reverse_mapping, fixed_values):
494
535
  'last_value': last_processed_entry[1] if last_processed_entry else None,
495
536
  'row_index': current_row_index
496
537
  }
538
+ try:
539
+ if hasattr(CTX, 'current_patient_context'):
540
+ CTX.current_patient_context = current_patient_context
541
+ else:
542
+ CTX['current_patient_context'] = current_patient_context
543
+ except Exception:
544
+ pass
497
545
 
498
546
  # Clear memory-accumulating structures while preserving F11 context above
499
547
  last_processed_entry = None
500
548
  parsed_address_components = {}
549
+ try:
550
+ if hasattr(CTX, 'last_processed_entry'):
551
+ CTX.last_processed_entry = None
552
+ CTX.parsed_address_components = {}
553
+ else:
554
+ CTX['last_processed_entry'] = None
555
+ CTX['parsed_address_components'] = {}
556
+ except Exception:
557
+ pass
501
558
 
502
559
  # Handle script pause at the start of each row (patient record).
503
560
  manage_script_pause(csv_data, error_message, reverse_mapping)
@@ -541,6 +598,15 @@ def data_entry_loop(csv_data, field_mapping, reverse_mapping, fixed_values):
541
598
  if current_row_index != len(csv_data) - 1: # Not the last patient
542
599
  last_processed_entry = None
543
600
  parsed_address_components.clear()
601
+ try:
602
+ if hasattr(CTX, 'last_processed_entry'):
603
+ CTX.last_processed_entry = None
604
+ CTX.parsed_address_components = {}
605
+ else:
606
+ CTX['last_processed_entry'] = None
607
+ CTX['parsed_address_components'] = {}
608
+ except Exception:
609
+ pass
544
610
 
545
611
  current_row_index += 1 # Move to the next row by default
546
612