Skip to content

Commit

Permalink
Ensure mode_appt_constraints shift even under naive policy (#1096)
Browse files Browse the repository at this point in the history
* Ensure that mode_appt_constraints shift takes place even under Naive policy

* Style fixes

* Move check on whether policy is empty inside load_priority_policy fnc

* linting

---------

Co-authored-by: Tim Hallett <[email protected]>
  • Loading branch information
marghe-molaro and tbhallett authored Sep 13, 2023
1 parent d38b541 commit 308724a
Showing 1 changed file with 28 additions and 20 deletions.
48 changes: 28 additions & 20 deletions src/tlo/methods/healthsystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -871,10 +871,9 @@ def initialise_simulation(self, sim):
self.healthsystemscheduler = HealthSystemScheduler(self)
sim.schedule_event(self.healthsystemscheduler, sim.date)

# Schedule priority policy change
if self.parameters["policy_name"] != self.parameters["policy_name_post_switch"]:
sim.schedule_event(HealthSystemChangePriorityPolicy(self),
Date(self.parameters["year_policy_switch"], 1, 1))
# Schedule priority policy and mode_appt_constraints change
sim.schedule_event(HealthSystemChangePriorityPolicyAndMode(self),
Date(self.parameters["year_policy_switch"], 1, 1))

def on_birth(self, mother_id, child_id):
self.bed_days.on_birth(self.sim.population.props, mother_id, child_id)
Expand Down Expand Up @@ -914,8 +913,7 @@ def setup_priority_policy(self):
# If adopting a policy, initialise here all other relevant variables.
# Use of blank instead of None is not ideal, however couldn't seem to recover actual
# None from parameter file.
if self.priority_policy != "":
self.load_priority_policy(self.priority_policy)
self.load_priority_policy(self.priority_policy)

# Initialise the fast-tracking routes.
# The attributes that can be looked up to determine whether a person might be eligible
Expand Down Expand Up @@ -1241,18 +1239,21 @@ def get_priority_policy_initial(self) -> str:

def load_priority_policy(self, policy):

# Select the chosen policy from dictionary of all possible policies
Policy_df = self.parameters['priority_rank'][policy]
if policy != "":
# Select the chosen policy from dictionary of all possible policies
Policy_df = self.parameters['priority_rank'][policy]

# If a policy is adopted, following variable *must* always be taken from policy.
# Over-write any other values here.
self.lowest_priority_considered = Policy_df.loc[Policy_df['Treatment'] == 'lowest_priority_considered',
'Priority'].iloc[0]
# If a policy is adopted, following variable *must* always be taken from policy.
# Over-write any other values here.
self.lowest_priority_considered = Policy_df.loc[
Policy_df['Treatment'] == 'lowest_priority_considered',
'Priority'
].iloc[0]

# Convert policy dataframe into dictionary to speed-up look-up process.
self.priority_rank_dict = \
Policy_df.set_index("Treatment", drop=True).to_dict(orient="index")
del self.priority_rank_dict["lowest_priority_considered"]
# Convert policy dataframe into dictionary to speed-up look-up process.
self.priority_rank_dict = \
Policy_df.set_index("Treatment", drop=True).to_dict(orient="index")
del self.priority_rank_dict["lowest_priority_considered"]

def schedule_hsi_event(
self,
Expand Down Expand Up @@ -2782,21 +2783,28 @@ def apply(self, population):
self.module.bed_days.availability = self._parameters['beds_availability']


class HealthSystemChangePriorityPolicy(RegularEvent, PopulationScopeEventMixin):
class HealthSystemChangePriorityPolicyAndMode(RegularEvent, PopulationScopeEventMixin):
""" This event exists to change the priority policy adopted by the
HealthSystem at a given year. """

def __init__(self, module):
super().__init__(module, frequency=DateOffset(years=100))

def apply(self, population):
self.module.priority_policy = self.module.parameters["policy_name_post_switch"]

# Change mode_appt_constraints
self.module.mode_appt_constraints = self.module.parameters["mode_appt_constraints_postSwitch"]
if self.module.priority_policy != "":

# If policy has changed, update it
if self.module.parameters["policy_name"] != self.module.parameters["policy_name_post_switch"]:
self.module.priority_policy = self.module.parameters["policy_name_post_switch"]
self.module.load_priority_policy(self.module.priority_policy)

logger.info(key="message",
data=f"Switched policy at sim date: "
f"{self.service_availability}"
f"{self.sim.date}"
f"Now using policy: "
f"{self.module.priority_policy}"
f"and mode: "
f"{self.module.mode_appt_constraints}"
)

0 comments on commit 308724a

Please sign in to comment.