tlo.methods.hsi_event module

class HSI_Event(module, *args, **kwargs)[source]

Base HSI event class, from which all others inherit.

Concrete subclasses should also inherit from one of the EventMixin classes defined in src/tlo/events.py, and implement at least an apply and did_not_run method.

Create a new event.

Note that just creating an event does not schedule it to happen; that must be done by calling Simulation.schedule_event.

Parameters:

module – the module that created this event. All subclasses of Event take this as the first argument in their constructor, but may also take further keyword arguments.

Class attributes:

__annotations__ : {‘module’: ‘Module’, ‘target’: ‘int’, ‘TREATMENT_ID’: ‘str’, ‘ACCEPTED_FACILITY_LEVEL’: ‘str’, ‘BEDDAYS_FOOTPRINT’: ‘Dict[str, Union[float, int]]’, ‘_received_info_about_bed_days’: ‘Dict[str, Union[float, int]]’, ‘expected_time_requests’: ‘Counter’, ‘facility_info’: ‘FacilityInfo’}

_received_info_about_bed_days : None

bed_days_allocated_to_this_event : <property object at 0x117a18900>

expected_time_requests : {}

facility_info : None

healthcare_system : <property object at 0x117a189a0>

is_all_declared_equipment_available : <property object at 0x117a189f0>

sim : <property object at 0x117a18950>

Functions (defined or overridden in class HSI_Event):

__init__(module, *args, **kwargs)[source]

Create a new event.

Note that just creating an event does not schedule it to happen; that must be done by calling Simulation.schedule_event.

Parameters:

module – the module that created this event. All subclasses of Event take this as the first argument in their constructor, but may also take further keyword arguments.

_adjust_facility_level_to_merge_1b_and_2() str[source]

Adjust the facility level of the HSI_Event, so that HSI_Events scheduled at level ‘1b’ and ‘2’ are both directed to level ‘2’

apply(squeeze_factor=0.0, *args, **kwargs)[source]

Apply this event to the population.

Must be implemented by subclasses.

did_not_run(*args, **kwargs) Literal[True][source]

Called when this event is due but it is not run. Return False to prevent the event being rescheduled, or True to allow the rescheduling. This is called each time that the event is tried to be run but it cannot be.

never_ran() None[source]

Called when this event is was entered to the HSI Event Queue, but was never run.

post_apply_hook() None[source]

Do any required processing after apply() completes.

_run_after_hsi_event() None[source]
Do things following the event’s apply and post_apply_hook functions running.
  • Impose the bed-days footprint (if target of the HSI is a person_id)

  • Record the equipment that has been added before and during the course of the HSI Event.

run(squeeze_factor)[source]

Make the event happen.

get_consumables(item_codes: None | integer | int | list | set | dict = None, optional_item_codes: None | integer | int | list | set | dict = None, to_log: bool | None = True, return_individual_results: bool | None = False) bool | dict[source]

Function to allow for getting and checking of entire set of consumables. All requests for consumables should use this function. :param item_codes: The item code(s) (and quantities) of the consumables that are requested and which determine the summary result for availability/non-availability. This can be an int (the item_code needed [assume quantity=1]), a list or set (the collection of item_codes [for each assuming quantity=1]), or a dict (with key:value pairs <item_code>:<quantity>). :param optional_item_codes: The item code(s) (and quantities) of the consumables that are requested and which do

not determine the summary result for availability/non-availability. (Same format as item_codes). This is useful when a large set of items may be used, but the viability of a subsequent operation depends only on a subset.

Parameters:

return_individual_results – If True returns a dict giving the availability of each item_code requested

(otherwise gives a bool indicating if all the item_codes requested are available). :param to_log: If True, logs the request. :returns A bool indicating whether every item is available, or a dict indicating the availability of each

item.

Note that disease module can use the get_item_codes_from_package_name and get_item_code_from_item_name

methods in the HealthSystem module to find item_codes.

make_beddays_footprint(dict_of_beddays) Dict[str, float | int][source]

Helper function to make a correctly-formed ‘bed-days footprint’

is_all_beddays_allocated() bool[source]

Check if the entire footprint requested is allocated

make_appt_footprint(dict_of_appts) Counter[source]

Helper function to make appointment footprint in format expected downstream.

Should be passed a dictionary keyed by appointment type codes with non-negative values.

add_equipment(item_codes: int | str | Iterable[int] | Iterable[str]) None[source]

Declare that piece(s) of equipment are used in this HSI_Event. Equipment items can be identified by their item_codes (int) or descriptors (str); a singular item or an iterable of items (either codes or descriptors but not a mix of both) can be defined at once. Checks are done on the validity of the item_codes/item descriptions and a warning issued if any are not recognised.

probability_all_equipment_available(item_codes: int | str | Iterable[int] | Iterable[str]) float[source]

Returns the probability that all the equipment item_codes are available. This does not imply that the equipment is being used and no logging happens. It is provided as a convenience to disease module authors in case the logic during an HSI_Event depends on the availability of a piece of equipment. This function accepts the item codes/descriptions in a variety of formats, so the argument needs to be parsed.

initialise() None[source]

Initialise the HSI: * Set the facility_info * Compute appt-footprint time requirements

_check_if_appt_footprint_can_run() bool[source]

Check that event (if individual level) is able to run with this configuration of officers (i.e. check that this does not demand officers that are _never_ available), and issue warning if not.

static _return_item_codes_in_dict(item_codes: None | integer | int | list | set | dict) dict[source]

Convert an argument for ‘item_codes` (provided as int, list, set or dict) into the format dict(<item_code>:quantity).

as_namedtuple(actual_appt_footprint: dict | None = None) HSIEventDetails[source]
class HSIEventWrapper(hsi_event, run_hsi=True, *args, **kwargs)[source]

This is wrapper that contains an HSI event.

It is used:

1) When the healthsystem is in mode ‘disabled=True’ such that HSI events sent to the health system scheduler are passed to the main simulation scheduler for running on the date of topen. (Note, it is run with squeeze_factor=0.0.) 2) When the healthsystem is in mode disable_and_reject_all=True such that HSI are not run but the never_ran method is run on the date of tclose. 3) When an HSI has been submitted to schedule_hsi_event but the service is not available.

Create a new event.

Note that just creating an event does not schedule it to happen; that must be done by calling Simulation.schedule_event.

Parameters:
  • module – the module that created this event. All subclasses of Event take this as the first argument in their constructor, but may also take further keyword arguments.

  • priority – a keyword-argument to set the priority (see Priority enum)

Bases: tlo.events.Event

Functions (defined or overridden in class HSIEventWrapper):

__init__(hsi_event, run_hsi=True, *args, **kwargs)[source]

Create a new event.

Note that just creating an event does not schedule it to happen; that must be done by calling Simulation.schedule_event.

Parameters:
  • module – the module that created this event. All subclasses of Event take this as the first argument in their constructor, but may also take further keyword arguments.

  • priority – a keyword-argument to set the priority (see Priority enum)

run()[source]

Do the appropriate action on the HSI event