Skip to content
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

Consolidate Use of 'OPD' Appointment Type #1021

Merged
merged 8 commits into from
Jul 17, 2023
50 changes: 25 additions & 25 deletions src/tlo/methods/hsi_generic_first_appts.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,12 @@ def __init__(self, module, person_id, facility_level='0'):

self.TREATMENT_ID = 'FirstAttendance_NonEmergency'

if facility_level == '0':
appt_type = 'ConWithDCSA'
elif self.sim.population.props.at[person_id, 'age_years'] < 5:
appt_type = 'Under5OPD'
else:
appt_type = 'Over5OPD'

self.ACCEPTED_FACILITY_LEVEL = facility_level
self.EXPECTED_APPT_FOOTPRINT = self.make_appt_footprint({appt_type: 1})
self.EXPECTED_APPT_FOOTPRINT = self.make_appt_footprint({}) # <-- No footprint, as this HSI (mostly just)
# determines which further HSI will be needed
# for this person. In some cases, small bits
# of care are provided (e.g. a diagnosis, or
# the provision of inhaler.).

def apply(self, person_id, squeeze_factor):
"""Run the actions required during the HSI."""
Expand All @@ -84,8 +81,11 @@ def __init__(self, module, person_id):

self.TREATMENT_ID = 'FirstAttendance_Emergency'
self.ACCEPTED_FACILITY_LEVEL = '1b'
self.EXPECTED_APPT_FOOTPRINT = self.make_appt_footprint({
('Under5OPD' if self.sim.population.props.at[person_id, "age_years"] < 5 else 'Over5OPD'): 1})
self.EXPECTED_APPT_FOOTPRINT = self.make_appt_footprint({}) # <-- No footprint, as this HSI (mostly just)
# determines which further HSI will be needed
# for this person. In some cases, small bits
# of care are provided (e.g. a diagnosis, or
# the provision of inhaler.).

def apply(self, person_id, squeeze_factor):

Expand Down Expand Up @@ -340,21 +340,6 @@ def do_at_generic_first_appt_emergency(hsi_event, squeeze_factor):
topen=sim.date,
tclose=None)

# ----- EXAMPLES FOR MOCKITIS AND CHRONIC SYNDROME -----
if 'craving_sandwiches' in symptoms:
event = HSI_ChronicSyndrome_SeeksEmergencyCareAndGetsTreatment(
module=sim.modules['ChronicSyndrome'],
person_id=person_id
)
schedule_hsi(event, priority=1, topen=sim.date)

if 'extreme_pain_in_the_nose' in symptoms:
event = HSI_Mockitis_PresentsForCareWithSevereSymptoms(
module=sim.modules['Mockitis'],
person_id=person_id
)
schedule_hsi(event, priority=1, topen=sim.date)

if 'severe_trauma' in symptoms:
if 'RTI' in sim.modules:
sim.modules['RTI'].do_rti_diagnosis_and_treatment(person_id=person_id)
Expand All @@ -374,3 +359,18 @@ def do_at_generic_first_appt_emergency(hsi_event, squeeze_factor):
if 'Copd' in sim.modules:
if ('breathless_moderate' in symptoms) or ('breathless_severe' in symptoms):
sim.modules['Copd'].do_when_present_with_breathless(person_id=person_id, hsi_event=hsi_event)

# ----- EXAMPLES FOR MOCKITIS AND CHRONIC SYNDROME -----
if 'craving_sandwiches' in symptoms:
event = HSI_ChronicSyndrome_SeeksEmergencyCareAndGetsTreatment(
module=sim.modules['ChronicSyndrome'],
person_id=person_id
)
schedule_hsi(event, priority=1, topen=sim.date)

if 'extreme_pain_in_the_nose' in symptoms:
event = HSI_Mockitis_PresentsForCareWithSevereSymptoms(
module=sim.modules['Mockitis'],
person_id=person_id
)
schedule_hsi(event, priority=1, topen=sim.date)
15 changes: 5 additions & 10 deletions src/tlo/methods/malaria.py
Original file line number Diff line number Diff line change
Expand Up @@ -896,7 +896,9 @@ def __init__(self, module, person_id):
assert isinstance(module, Malaria)

self.TREATMENT_ID = 'Malaria_Treatment'
self.EXPECTED_APPT_FOOTPRINT = self.make_appt_footprint({'Over5OPD': 1})

self.EXPECTED_APPT_FOOTPRINT = self.make_appt_footprint({
('Under5OPD' if self.sim.population.props.at[person_id, "age_years"] < 5 else 'Over5OPD'): 1})
self.ACCEPTED_FACILITY_LEVEL = '1a'

def apply(self, person_id, squeeze_factor):
Expand Down Expand Up @@ -935,13 +937,6 @@ def apply(self, person_id, squeeze_factor):
}
logger.info(key='rdt_log', data=person_details_for_test)

# change footprint type if young child
if person['age_years'] < 5:
ACTUAL_APPT_FOOTPRINT = self.make_appt_footprint(
{'Under5OPD': 1}
)
return ACTUAL_APPT_FOOTPRINT

def get_drugs(self, age_of_person):
"""
:param age_of_person:
Expand Down Expand Up @@ -993,7 +988,8 @@ def __init__(self, module, person_id):
assert isinstance(module, Malaria)

self.TREATMENT_ID = 'Malaria_Treatment_Complicated'
self.EXPECTED_APPT_FOOTPRINT = self.make_appt_footprint({})
self.EXPECTED_APPT_FOOTPRINT = self.make_appt_footprint({
('Under5OPD' if self.sim.population.props.at[person_id, "age_years"] < 5 else 'Over5OPD'): 1})
self.ACCEPTED_FACILITY_LEVEL = '1b'
self.BEDDAYS_FOOTPRINT = self.make_beddays_footprint({'general_bed': 5})

Expand Down Expand Up @@ -1035,7 +1031,6 @@ def apply(self, person_id, squeeze_factor):
def did_not_run(self):
logger.debug(key='message',
data='HSI_Malaria_Treatment_Complicated: did not run')
pass


class HSI_MalariaIPTp(HSI_Event, IndividualScopeEventMixin):
Expand Down
3 changes: 2 additions & 1 deletion src/tlo/methods/measles.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,8 @@ def __init__(self, module, person_id):
assert isinstance(module, Measles)

self.TREATMENT_ID = "Measles_Treatment"
self.EXPECTED_APPT_FOOTPRINT = self.make_appt_footprint({"Over5OPD": 1})
self.EXPECTED_APPT_FOOTPRINT = self.make_appt_footprint({
('Under5OPD' if self.sim.population.props.at[person_id, "age_years"] < 5 else 'Over5OPD'): 1})
self.ACCEPTED_FACILITY_LEVEL = '1a'

def apply(self, person_id, squeeze_factor):
Expand Down
16 changes: 11 additions & 5 deletions tests/test_healthsystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ def test_run_in_mode_1_with_capacity(tmpdir, seed):

@pytest.mark.slow
def test_run_in_mode_1_with_no_capacity(tmpdir, seed):
# Events should run but with high squeeze factors
# Events should run but (for those with non-blank footprints) with high squeeze factors
# (Mode 1 -> elastic constraints)

# Establish the simulation object
Expand Down Expand Up @@ -372,7 +372,10 @@ def test_run_in_mode_1_with_no_capacity(tmpdir, seed):
assert len(output['tlo.methods.healthsystem']['HSI_Event']) > 0
hsi_events = output['tlo.methods.healthsystem']['HSI_Event']
assert hsi_events['did_run'].all()
assert (hsi_events.loc[hsi_events['Person_ID'] >= 0, 'Squeeze_Factor'] == 100.0).all()
assert (
hsi_events.loc[(hsi_events['Person_ID'] >= 0) & (hsi_events['Number_By_Appt_Type_Code'] != {}),
'Squeeze_Factor'] == 100.0
).all() # All the events that had a non-blank footprint experienced high squeezing.
assert (hsi_events.loc[hsi_events['Person_ID'] < 0, 'Squeeze_Factor'] == 0.0).all()

# Check that some Mockitis cures occurred (though health system)
Expand Down Expand Up @@ -434,8 +437,8 @@ def test_run_in_mode_2_with_capacity(tmpdir, seed):
@pytest.mark.slow
@pytest.mark.group2
def test_run_in_mode_2_with_no_capacity(tmpdir, seed):
# No individual level events should run and the log should contain events with a flag showing that all individual
# events did not run. Population level events should have run.
# No individual level events (with non-blank footprint) should run and the log should contain events with a flag
# showing that all individual events did not run. Population level events should have run.
# (Mode 2 -> hard constraints)

# Establish the simulation object
Expand Down Expand Up @@ -478,7 +481,10 @@ def test_run_in_mode_2_with_no_capacity(tmpdir, seed):

# Do the checks
hsi_events = output['tlo.methods.healthsystem']['HSI_Event']
assert not (hsi_events.loc[hsi_events['Person_ID'] >= 0, 'did_run'].astype(bool)).any() # not any Individual level
assert not (
hsi_events.loc[(hsi_events['Person_ID'] >= 0) & (hsi_events['Number_By_Appt_Type_Code'] != {}),
'did_run'].astype(bool)
).any() # not any Individual level with non-blank footprints
assert (output['tlo.methods.healthsystem']['Capacity']['Frac_Time_Used_Overall'] == 0.0).all()
assert (hsi_events.loc[hsi_events['Person_ID'] < 0, 'did_run']).astype(bool).all() # all Population level events
assert pd.isnull(sim.population.props['mi_date_cure']).all() # No cures of mockitis occurring
Expand Down