@@ -2919,9 +2919,39 @@ def __init__(self, module):
2919
2919
super ().__init__ (module , frequency = DateOffset (years = 100 ))
2920
2920
2921
2921
def apply (self , population ):
2922
+ preswitch_mode = self .module .mode_appt_constraints
2923
+ health_system : HealthSystem = self .module
2922
2924
2923
2925
# Change mode_appt_constraints
2924
- self .module .mode_appt_constraints = self .module .parameters ["mode_appt_constraints_postSwitch" ]
2926
+ health_system .mode_appt_constraints = health_system .parameters ["mode_appt_constraints_postSwitch" ]
2927
+
2928
+ # If we've changed from mode 1 to mode 2, update the priority for every HSI event in the queue
2929
+ if preswitch_mode == 1 and health_system .mode_appt_constraints == 2 :
2930
+ # A place to store events with updated priority
2931
+ updated_events : List [HSIEventQueueItem | None ] = [None ] * len (health_system .HSI_EVENT_QUEUE )
2932
+ offset = 0
2933
+
2934
+ # For each HSI event in the queue
2935
+ while health_system .HSI_EVENT_QUEUE :
2936
+ event = hp .heappop (health_system .HSI_EVENT_QUEUE )
2937
+
2938
+ # Get its priority
2939
+ enforced_priority = health_system .enforce_priority_policy (event .hsi_event )
2940
+
2941
+ # If it's different
2942
+ if event .priority != enforced_priority :
2943
+ # Wrap it up with the new priority - everything else is the same
2944
+ event = HSIEventQueueItem (enforced_priority , event .topen , event .rand_queue_counter , event .queue_counter , event .tclose , event .hsi_event )
2945
+
2946
+ # Save it
2947
+ updated_events [offset ] = event
2948
+ offset += 1
2949
+
2950
+ # Add all the events back in the event queue
2951
+ while updated_events :
2952
+ hp .heappush (health_system .HSI_EVENT_QUEUE , updated_events .pop ())
2953
+
2954
+ del updated_events
2925
2955
2926
2956
logger .info (key = "message" ,
2927
2957
data = f"Switched mode at sim date: "
0 commit comments