From 3e8a8fb2a1c313336134a05398d90899630df1f2 Mon Sep 17 00:00:00 2001 From: Tim Hallett <39991060+tbhallett@users.noreply.github.com> Date: Wed, 14 Aug 2024 10:13:14 +0100 Subject: [PATCH 1/2] initial structure for a secular time-trend in consumables availability --- .../healthsystem/ResourceFile_HealthSystem_parameters.csv | 4 ++-- .../scenario_historical_changes_in_hr.py | 0 src/tlo/analysis/utils.py | 3 ++- src/tlo/methods/healthsystem.py | 6 ++++++ 4 files changed, 10 insertions(+), 3 deletions(-) create mode 100644 src/scripts/impact_of_historical_changes_in_hr/scenario_historical_changes_in_hr.py diff --git a/resources/healthsystem/ResourceFile_HealthSystem_parameters.csv b/resources/healthsystem/ResourceFile_HealthSystem_parameters.csv index 8c670a914d..db66d7922b 100644 --- a/resources/healthsystem/ResourceFile_HealthSystem_parameters.csv +++ b/resources/healthsystem/ResourceFile_HealthSystem_parameters.csv @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:f1cb38ba76c5673855e2e17e28ad1d36b5cec07d5d7872a7d6bc8aafde0f7009 -size 828 +oid sha256:3e015c43b392786c76492452de3b49b2fbd268a414f67a16bb10846d1be2f159 +size 873 diff --git a/src/scripts/impact_of_historical_changes_in_hr/scenario_historical_changes_in_hr.py b/src/scripts/impact_of_historical_changes_in_hr/scenario_historical_changes_in_hr.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/tlo/analysis/utils.py b/src/tlo/analysis/utils.py index 201f2fb25e..c186cfcb6d 100644 --- a/src/tlo/analysis/utils.py +++ b/src/tlo/analysis/utils.py @@ -1127,9 +1127,10 @@ def get_parameters_for_status_quo() -> Dict: "cons_availability": "default", "beds_availability": "default", "equip_availability": "all", # <--- NB. Existing calibration is assuming all equipment is available + # "consumables_availability_time_trend": True, # <-- not included yet, but future update should include. }, } - + def get_parameters_for_standard_mode2_runs() -> Dict: """ Returns a dictionary of parameters and their updated values to indicate diff --git a/src/tlo/methods/healthsystem.py b/src/tlo/methods/healthsystem.py index cf51b4c0ab..bf020d60e0 100644 --- a/src/tlo/methods/healthsystem.py +++ b/src/tlo/methods/healthsystem.py @@ -189,6 +189,12 @@ class HealthSystem(Module): " When using 'all' or 'none', requests for consumables are not logged. NB. This parameter is over-ridden" "if an argument is provided to the module initialiser." "Note that other options are also available: see the `Consumables` class."), + 'consumables_availability_time_trend': Parameter( + Types.BOOL, "Whether to incorporate the observed time-trend in availability of consumables." + ), + 'availability_estimates_time_trend': Parameter( + Types.DATA_FRAME, "The data on the trend over time in the availability of consumables." + ), # Infrastructure and Equipment 'BedCapacity': Parameter( From ba143cde86a0f2b21cb7c6e90c54829bbe3cdd7e Mon Sep 17 00:00:00 2001 From: Tim Hallett <39991060+tbhallett@users.noreply.github.com> Date: Wed, 14 Aug 2024 11:06:36 +0100 Subject: [PATCH 2/2] initial structure --- ...les_availability_estimates_time_trend.xlsx | 3 ++ src/tlo/methods/consumables.py | 30 +++++++++++++++++-- src/tlo/methods/healthsystem.py | 11 +++++-- 3 files changed, 39 insertions(+), 5 deletions(-) create mode 100644 resources/healthsystem/consumables/ResourceFile_Consumables_availability_estimates_time_trend.xlsx diff --git a/resources/healthsystem/consumables/ResourceFile_Consumables_availability_estimates_time_trend.xlsx b/resources/healthsystem/consumables/ResourceFile_Consumables_availability_estimates_time_trend.xlsx new file mode 100644 index 0000000000..27d014f428 --- /dev/null +++ b/resources/healthsystem/consumables/ResourceFile_Consumables_availability_estimates_time_trend.xlsx @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d46b31019147c959f10726b1d64114dc54a2c365c7681f9e7855d3e218f33447 +size 27793 diff --git a/src/tlo/methods/consumables.py b/src/tlo/methods/consumables.py index 674035ad98..a2c2565aa3 100644 --- a/src/tlo/methods/consumables.py +++ b/src/tlo/methods/consumables.py @@ -34,7 +34,9 @@ def __init__(self, availability_data: pd.DataFrame = None, item_code_designations: pd.DataFrame = None, rng: np.random = None, - availability: str = 'default' + availability: str = 'default', + use_time_trend: bool = False, + time_trend_data: dict = None, ) -> None: self._options_for_availability = { @@ -56,8 +58,10 @@ def __init__(self, self._is_unknown_item_available = None # Whether an unknown item is available, by facility_id self._not_recognised_item_codes = set() # The item codes requested but which are not recognised. - # Save designations + # Save designations and time-trend info self._item_code_designations = item_code_designations + self._time_trend_data = time_trend_data + self._use_time_trend = use_time_trend # Save all item_codes that are defined and pd.Series with probs of availability from ResourceFile self.item_codes, self._processed_consumables_data = \ @@ -266,7 +270,7 @@ def _lookup_availability_of_consumables(self, def on_simulation_end(self): """Do tasks at the end of the simulation. - + Raise warnings and enter to log about item_codes not recognised. """ if self._not_recognised_item_codes: @@ -289,6 +293,26 @@ def on_simulation_end(self): def on_end_of_year(self): self._summary_counter.write_to_log_and_reset_counters() + # Update consumables availability (for next year) to reflect secular trend + self._update_availability() + + def _update_availability(self): + """Update availability of consumables""" + if not self._use_time_trend: + return # Do nothing if there should not be a time-trend in the availability + + # Data on the changes in availability + data = self._time_trend_data + + # Annual multiplier on availability for each category.... + + # Items in each category.... (look up from the categories provided in the sheet) + + # For each group, multiply availabilities in `self._prob_item_codes_available`, and clip to 1.0 + + + + def get_item_codes_from_package_name(lookup_df: pd.DataFrame, package: str) -> dict: """Helper function to provide the item codes and quantities in a dict of the form {:} for diff --git a/src/tlo/methods/healthsystem.py b/src/tlo/methods/healthsystem.py index bf020d60e0..5a4f3fcfec 100644 --- a/src/tlo/methods/healthsystem.py +++ b/src/tlo/methods/healthsystem.py @@ -193,7 +193,7 @@ class HealthSystem(Module): Types.BOOL, "Whether to incorporate the observed time-trend in availability of consumables." ), 'availability_estimates_time_trend': Parameter( - Types.DATA_FRAME, "The data on the trend over time in the availability of consumables." + Types.DICT, "Dict of dataframes describing the trend over time in the availability of consumables." ), # Infrastructure and Equipment @@ -570,6 +570,11 @@ def read_parameters(self, data_folder): ).set_index('Item_Code') self.parameters['availability_estimates'] = pd.read_csv( path_to_resourcefiles_for_healthsystem / 'consumables' / 'ResourceFile_Consumables_availability_small.csv') + self.parameters['availability_estimates_time_trend'] = pd.read_excel( + path_to_resourcefiles_for_healthsystem / 'consumables' / + 'ResourceFile_Consumables_availability_estimates_time_trend.xlsx', + sheet_name=None + ) # Data on the number of beds available of each type by facility_id self.parameters['BedCapacity'] = pd.read_csv( @@ -669,7 +674,9 @@ def pre_initialise_population(self): self.parameters['availability_estimates']), item_code_designations=self.parameters['consumables_item_designations'], rng=rng_for_consumables, - availability=self.get_cons_availability() + availability=self.get_cons_availability(), + use_time_trend=self.parameters['consumables_availability_time_trend'], + time_trend_data=self.parameters['availability_estimates_time_trend'] ) # Determine equip_availability