@@ -1361,44 +1361,31 @@ def _add_hsi_event_queue_item_to_hsi_event_queue(self, priority, topen, tclose,
1361
1361
# This is where the priority policy is enacted
1362
1362
def enforce_priority_policy (self , hsi_event ) -> int :
1363
1363
"""Return priority for HSI_Event based on policy under consideration """
1364
+ priority_ranking = self .priority_rank_dict
1364
1365
1365
- pr = self .priority_rank_dict
1366
- pdf = self .sim .population .props
1367
-
1368
- if hsi_event .TREATMENT_ID in pr :
1369
- _priority_ranking = pr [hsi_event .TREATMENT_ID ]['Priority' ]
1370
-
1371
- # Check whether fast-tracking routes are available for this treatment. If person qualifies for one
1372
- # don't check remaining.
1373
-
1374
- # Look up relevant attributes for HSI_Event's target
1375
- list_targets = [_t [0 ] for _t in self .list_fasttrack ]
1376
- target_attributes = pdf .loc [hsi_event .target , list_targets ]
1377
-
1378
- # Warning: here assuming that the first fast-tracking eligibility encountered
1379
- # will determine the priority to be used. If different fast-tracking channels have
1380
- # different priorities for the same treatment, this will be a problem!
1381
- # First item in Lists is age-related, therefore need to invoke different logic.
1382
- if (
1383
- (pr [hsi_event .TREATMENT_ID ][self .list_fasttrack [0 ][1 ]] > - 1 )
1384
- and (target_attributes ['age_exact_years' ] <= 5 )
1385
- ):
1386
- return pr [hsi_event .TREATMENT_ID ][self .list_fasttrack [0 ][1 ]]
1387
-
1388
- # All other attributes are looked up the same way, so can do this in for loop
1389
- for i in range (1 , len (self .list_fasttrack )):
1390
- if (
1391
- (pr [hsi_event .TREATMENT_ID ][self .list_fasttrack [i ][1 ]] > - 1 )
1392
- and target_attributes [i ]
1393
- ):
1394
- return pr [hsi_event .TREATMENT_ID ][self .list_fasttrack [i ][1 ]]
1366
+ if hsi_event .TREATMENT_ID not in priority_ranking :
1367
+ # If treatment is not ranked in the policy, issue a warning and assign priority=3 by default
1368
+ warnings .warn (UserWarning (f"Couldn't find priority ranking for TREATMENT_ID { hsi_event .TREATMENT_ID } " ))
1369
+ return self .lowest_priority_considered
1395
1370
1396
- return _priority_ranking
1371
+ # Check whether fast-tracking routes are available for this treatment.
1372
+ # If person qualifies for one don't check remaining.
1373
+ # Warning: here assuming that the first fast-tracking eligibility encountered
1374
+ # will determine the priority to be used. If different fast-tracking channels have
1375
+ # different priorities for the same treatment, this will be a problem!
1376
+ # First item in Lists is age-related, therefore need to invoke different logic.
1377
+ df = self .sim .population .props
1378
+ treatment_ranking = priority_ranking [hsi_event .TREATMENT_ID ]
1379
+ for attribute , fasttrack_code in self .list_fasttrack :
1380
+ if treatment_ranking [fasttrack_code ] > - 1 :
1381
+ if attribute == 'age_exact_years' :
1382
+ if df .at [hsi_event .target , attribute ] <= 5 :
1383
+ return treatment_ranking [fasttrack_code ]
1384
+ else :
1385
+ if df .at [hsi_event .target , attribute ]:
1386
+ return treatment_ranking [fasttrack_code ]
1397
1387
1398
- else : # If treatment is not ranked in the policy, issue a warning and assign priority=3 by default
1399
- warnings .warn (UserWarning (f"Couldn't find priority ranking for TREATMENT_ID \n "
1400
- f"{ hsi_event .TREATMENT_ID } " ))
1401
- return self .lowest_priority_considered
1388
+ return treatment_ranking ["Priority" ]
1402
1389
1403
1390
def check_hsi_event_is_valid (self , hsi_event ):
1404
1391
"""Check the integrity of an HSI_Event."""
0 commit comments