-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BedDays
availability switch now correctly updates capacities
#1352
Open
willGraham01
wants to merge
3
commits into
master
Choose a base branch
from
wgraham/fix-beddays-mode-switch
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,12 +5,12 @@ | |
|
||
""" | ||
from collections import defaultdict | ||
from typing import Dict, Tuple | ||
from typing import Dict, Literal, Tuple | ||
|
||
import numpy as np | ||
import pandas as pd | ||
|
||
from tlo import Property, Types, logging | ||
from tlo import Date, Property, Types, logging | ||
|
||
# --------------------------------------------------------------------------------------------------------- | ||
# CLASS DEFINITIONS | ||
|
@@ -145,6 +145,40 @@ def initialise_beddays_tracker(self, model_to_data_popsize_ratio=1.0): | |
assert not df.isna().any().any() | ||
self.bed_tracker[bed_type] = df | ||
|
||
def switch_beddays_availability( | ||
self, | ||
new_availability: Literal["all", "none", "default"], | ||
effective_on_and_from: Date, | ||
model_to_data_popsize_ratio: float = 1.0, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it would be nicer (I think) if the user didn't need to pass this. It hasn't changed since the beginning of the simulation, so it seems awkward to pass it in just to instruct a change in availability to all/none/default. |
||
) -> None: | ||
""" | ||
Action to be taken if the beddays availability changes in the middle | ||
of the simulation. | ||
|
||
If bed capacities are reduced below the currently scheduled occupancy, | ||
inpatients are not evicted from beds and are allowed to remain in the | ||
bed until they are scheduled to leave. Obviously, no new patients will | ||
be admitted if there is no room in the new capacities. | ||
|
||
:param new_availability: The new bed availability. See __init__ for details. | ||
:param effective_on_and_from: First day from which the new capacities will be imposed. | ||
:param model_to_data_popsize_ratio: As in initialise_population. | ||
""" | ||
# Store new bed availability | ||
self.availability = new_availability | ||
# Before we update the bed capacity, we need to store its old values | ||
# This is because we will need to update the trackers to reflect the new# | ||
# maximum capacities for each bed type. | ||
old_max_capacities: pd.DataFrame = self._scaled_capacity.copy() | ||
# Set the new capacity for beds | ||
self.set_scaled_capacity(model_to_data_popsize_ratio) | ||
# Compute the difference between the new max capacities and the old max capacities | ||
difference_in_max = self._scaled_capacity - old_max_capacities | ||
# For each tracker, after the effective date, impose the difference on the max | ||
# number of beds | ||
for bed_type, tracker in self.bed_tracker.items(): | ||
tracker.loc[effective_on_and_from:] += difference_in_max[bed_type] | ||
|
||
def on_start_of_day(self): | ||
"""Things to do at the start of each new day: | ||
* Refresh inpatient status | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The way in which we expect to use this (i.e., from
HealthSystemChangeParameters
) I think we can always assume that this is equal to today's date. This is the way in which other things (consumables, equipment) have their availability updated.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With regards to this and the below comment - I think exposing
effective_on_and_from
andmodel_to_data_popsize_ratio
as arguments has an advantage in terms of making it easier to test (as we can pass in relevant values directly rather than having to manipulate the other objects they would be instead read from) and keeping it's implementation decoupled from implementation details of other classes, however we can possibly still achieve this by making the currentswitch_beddays_availability
method instead_switch_beddays_availability
to indicate for internal use only, and exposing a 'public' methodThis would still allow using the current
_switch_beddays_availability
implementation in tests.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Happy to make a public/private method like is suggested above, though I'd quite like to avoid spreading the
self.sim.modules...
cross-class-coupling into the bed-days class if possible.switch_beddays_availability
is already called by classes that have this cross-class-coupling anyway, so it might as well stay isolated to there?