Skip to content

Commit e9a61dc

Browse files
authored
Improve performance when checking availability of officers (#1814)
1 parent 5788fff commit e9a61dc

File tree

1 file changed

+16
-20
lines changed

1 file changed

+16
-20
lines changed

src/tlo/methods/healthsystem.py

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1549,6 +1549,15 @@ def schedule_hsi_event(
15491549
hsi_event.initialise()
15501550
clinic_eligibility = self.get_clinic_eligibility(hsi_event.TREATMENT_ID)
15511551

1552+
# Check we recognise requested officers
1553+
for officer in hsi_event.expected_time_requests:
1554+
if officer not in self._daily_capabilities[clinic_eligibility]:
1555+
logger.warning(
1556+
key="message",
1557+
data=f"Unknown officer '{officer}' requested by "
1558+
f"{hsi_event.__class__.__name__} at time of scheduling."
1559+
)
1560+
15521561
self._add_hsi_event_queue_item_to_hsi_event_queue(
15531562
clinic_eligibility=clinic_eligibility,
15541563
priority=priority,
@@ -2105,26 +2114,13 @@ def on_end_of_year(self) -> None:
21052114
# Record equipment usage for the year, for each facility
21062115
self._record_general_equipment_usage_for_year()
21072116

2108-
def check_if_all_required_officers_have_nonzero_capabilities(self, expected_time_requests, clinic)-> bool:
2117+
def do_all_required_officers_have_nonzero_capabilities(self, expected_time_requests, clinic)-> bool:
21092118
"""Check if all officers required by the appt footprint are available to perform the HSI"""
2110-
2111-
ok_to_run = True
2112-
2113-
for officer in expected_time_requests.keys():
2114-
availability = self.capabilities_today[clinic][officer]
2115-
2116-
# If officer does not exist in the relevant facility, log warning and proceed as if availability = 0
2117-
if availability is None:
2118-
logger.warning(
2119-
key="message",
2120-
data=(f"Requested officer {officer} is not contemplated by health system. ")
2121-
)
2122-
availability = 0.0
2123-
2124-
if availability == 0.0:
2125-
ok_to_run = False
2126-
2127-
return ok_to_run
2119+
clinic_capabilities = self.capabilities_today[clinic]
2120+
for officer in expected_time_requests:
2121+
if clinic_capabilities.get(officer, 0.0) == 0.0:
2122+
return False
2123+
return True
21282124

21292125
def run_individual_level_events_in_mode_1(
21302126
self, _list_of_individual_hsi_event_tuples: List[HSIEventQueueItem]
@@ -2145,7 +2141,7 @@ def run_individual_level_events_in_mode_1(
21452141
# In this mode, all HSI Events run provided all required officers have non-zero capabilities
21462142
ok_to_run = True
21472143
if event.expected_time_requests:
2148-
ok_to_run = self.check_if_all_required_officers_have_nonzero_capabilities(
2144+
ok_to_run = self.do_all_required_officers_have_nonzero_capabilities(
21492145
event.expected_time_requests, clinic=clinic)
21502146
if ok_to_run:
21512147

0 commit comments

Comments
 (0)