Skip to content

Commit e46f3be

Browse files
committed
Update the priorities of the HSI events if we change from mode 1 to 2
1 parent 036b34a commit e46f3be

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

src/tlo/methods/healthsystem.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2919,9 +2919,39 @@ def __init__(self, module):
29192919
super().__init__(module, frequency=DateOffset(years=100))
29202920

29212921
def apply(self, population):
2922+
preswitch_mode = self.module.mode_appt_constraints
2923+
health_system: HealthSystem = self.module
29222924

29232925
# 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
29252955

29262956
logger.info(key="message",
29272957
data=f"Switched mode at sim date: "

0 commit comments

Comments
 (0)