@@ -1993,89 +1993,102 @@ def apply(self, person_id, squeeze_factor):
19931993 "directory" : tmpdir ,
19941994 "custom_levels" : {"tlo.methods.healthsystem" : logging .DEBUG },
19951995 }
1996- sim = Simulation (start_date = start_date , seed = seed , log_config = log_config )
1996+
1997+ def simulate (task_shifting_option , Ntarget ):
1998+
1999+ sim = Simulation (start_date = start_date , seed = seed , log_config = log_config )
19972000
1998- # Register the core modules and simulate for 0 days
1999- sim .register (demography .Demography (resourcefilepath = resourcefilepath ),
2000- healthsystem .HealthSystem (resourcefilepath = resourcefilepath ,
2001- capabilities_coefficient = 1.0 ,
2002- mode_appt_constraints = 2 ,
2003- include_task_shifting = True ,
2004- ignore_priority = False ,
2005- randomise_queue = True ,
2006- policy_name = "" ,
2007- use_funded_or_actual_staffing = 'funded_plus' ),
2008- DummyModule ()
2009- )
2001+ # Register the core modules and simulate for 0 days
2002+ sim .register (demography .Demography (resourcefilepath = resourcefilepath ),
2003+ healthsystem .HealthSystem (resourcefilepath = resourcefilepath ,
2004+ capabilities_coefficient = 1.0 ,
2005+ mode_appt_constraints = 2 ,
2006+ include_task_shifting = task_shifting_option ,
2007+ ignore_priority = False ,
2008+ randomise_queue = True ,
2009+ policy_name = "" ,
2010+ use_funded_or_actual_staffing = 'funded_plus' ),
2011+ DummyModule ()
2012+ )
20102013
2011- tot_population = 100
2012- sim .make_initial_population (n = tot_population )
2013- sim .simulate (end_date = sim .start_date )
2014+ tot_population = 100
2015+ sim .make_initial_population (n = tot_population )
2016+ sim .simulate (end_date = sim .start_date )
20142017
2015- # Get pointer to the HealthSystemScheduler event
2016- healthsystemscheduler = sim .modules ['HealthSystem' ].healthsystemscheduler
2018+ # Get pointer to the HealthSystemScheduler event
2019+ healthsystemscheduler = sim .modules ['HealthSystem' ].healthsystemscheduler
20172020
2018- # Force entire population in one district (keys_district[0]) and get facility ID
2019- person_for_district = {d : i for i , d in enumerate (sim .population .props ['district_of_residence' ].cat .categories )}
2020- keys_district = list (person_for_district .keys ())
2021+ # Force entire population in one district (keys_district[0]) and get facility ID
2022+ person_for_district = {d : i for i , d in enumerate (sim .population .props ['district_of_residence' ].cat .categories )}
2023+ keys_district = list (person_for_district .keys ())
20212024
2022- for i in range (0 , int (tot_population )):
2023- sim .population .props .at [i , 'district_of_residence' ] = keys_district [0 ]
2025+ for i in range (0 , int (tot_population )):
2026+ sim .population .props .at [i , 'district_of_residence' ] = keys_district [0 ]
20242027
20252028
2026- # Schedule an identical appointment for all individuals
2027- for i in range (0 , tot_population ):
2029+ # Schedule an identical appointment for all individuals
2030+ for i in range (0 , tot_population ):
20282031
2029- hsi = DummyHSIEvent (module = sim .modules ['DummyModule' ],
2030- person_id = i ,
2031- appt_type = 'MinorSurg' ,
2032- level = '1a' )
2032+ hsi = DummyHSIEvent (module = sim .modules ['DummyModule' ],
2033+ person_id = i ,
2034+ appt_type = 'MinorSurg' ,
2035+ level = '1a' )
20332036
2034- sim .modules ['HealthSystem' ].schedule_hsi_event (
2035- hsi ,
2036- topen = sim .date ,
2037- tclose = sim .date + pd .DateOffset (days = 1 ),
2038- # Assign equal priority
2039- priority = 0
2040- )
2037+ sim .modules ['HealthSystem' ].schedule_hsi_event (
2038+ hsi ,
2039+ topen = sim .date ,
2040+ tclose = sim .date + pd .DateOffset (days = 1 ),
2041+ # Assign equal priority
2042+ priority = 0
2043+ )
20412044
2042- hsi1 = DummyHSIEvent (module = sim .modules ['DummyModule' ],
2043- person_id = 0 , # Ensures call is on officers in first district
2044- appt_type = 'MinorSurg' ,
2045- level = '1a' )
2046- hsi1 .initialise ()
2047-
2048- # Get facility ID
2049- facID = int ((re .search (r'\d+' , next (iter (hsi1 .expected_time_requests )))).group ())
2050-
2051- pharmacy_task_time = hsi1 .expected_time_requests ['FacilityID_' + str (facID ) + '_Officer_Pharmacy' ]
2052- nursing_task_time = hsi1 .expected_time_requests ['FacilityID_' + str (facID ) + '_Officer_Nursing_and_Midwifery' ]
2053- clinical_task_time = hsi1 .expected_time_requests ['FacilityID_' + str (facID ) + '_Officer_Clinical' ]
2054-
2055- # Check that first choice of task-shifting officer for Pharmacy is Nursing_and_Midwifery, and get their factor
2056- assert 'Nursing_and_Midwifery' == sim .modules ['HealthSystem' ].global_task_shifting .get ('Pharmacy' )[0 ][0 ]
2057- nursing_task_shift_factor = sim .modules ['HealthSystem' ].global_task_shifting .get ('Pharmacy' )[1 ][0 ]
2058-
2059- # Number of appts that want to see delivered if pharmacy time is set to zero,
2060- # clinical time is set to perform 50 appts, and nursing time is set to perform 50 appts including
2061- # both nursing and pharmacy tasks.
2045+ hsi1 = DummyHSIEvent (module = sim .modules ['DummyModule' ],
2046+ person_id = 0 , # Ensures call is on officers in first district
2047+ appt_type = 'MinorSurg' ,
2048+ level = '1a' )
2049+ hsi1 .initialise ()
2050+
2051+ # Get facility ID
2052+ facID = int ((re .search (r'\d+' , next (iter (hsi1 .expected_time_requests )))).group ())
2053+
2054+ pharmacy_task_time = hsi1 .expected_time_requests ['FacilityID_' + str (facID ) + '_Officer_Pharmacy' ]
2055+ nursing_task_time = hsi1 .expected_time_requests ['FacilityID_' + str (facID ) + '_Officer_Nursing_and_Midwifery' ]
2056+ clinical_task_time = hsi1 .expected_time_requests ['FacilityID_' + str (facID ) + '_Officer_Clinical' ]
2057+
2058+ # Check that first choice of task-shifting officer for Pharmacy is Nursing_and_Midwifery, and get their factor
2059+ assert 'Nursing_and_Midwifery' == sim .modules ['HealthSystem' ].global_task_shifting .get ('Pharmacy' )[0 ][0 ]
2060+ nursing_task_shift_factor = sim .modules ['HealthSystem' ].global_task_shifting .get ('Pharmacy' )[1 ][0 ]
2061+
2062+ # Always set Pharmacy capabilities to zero. Set Clinical and Nursing capabilities such that Ntarget appointments
2063+ # can be delivered by relying on task-shifting from Nursing only. Setting Clinical time to Ntarget x clinical_task_time
2064+ # checks that when task-shifting first option (nurses) where always preferentially chosen over second.
2065+ # one (clinicians)
2066+ sim .modules ['HealthSystem' ]._daily_capabilities ['FacilityID_' + str (facID ) + '_Officer_Pharmacy' ] = 0.0
2067+ sim .modules ['HealthSystem' ]._daily_capabilities ['FacilityID_' + str (facID ) + '_Officer_Clinical' ] = Ntarget * (clinical_task_time )
2068+ sim .modules ['HealthSystem' ]._daily_capabilities ['FacilityID_' + str (facID ) + '_Officer_Nursing_and_Midwifery' ] = Ntarget * (nursing_task_time + nursing_task_shift_factor * pharmacy_task_time )
2069+
2070+ # Run healthsystemscheduler
2071+ healthsystemscheduler .apply (sim .population )
2072+
2073+ # read the results
2074+ output = parse_log_file (sim .log_filepath , level = logging .DEBUG )
2075+ hs_output = output ['tlo.methods.healthsystem' ]['HSI_Event' ]
2076+
2077+ return hs_output
2078+
2079+ # Pharmacy capabilities set to zero. Clinical and Nursing capabilities initialised such that Ntarget
2080+ # appointments can be performed iff using task-shifting
20622081 Ntarget = 50
20632082
2064- sim .modules ['HealthSystem' ]._daily_capabilities ['FacilityID_' + str (facID ) + '_Officer_Pharmacy' ] = 0.0
2065- sim .modules ['HealthSystem' ]._daily_capabilities ['FacilityID_' + str (facID ) + '_Officer_Clinical' ] = Ntarget * (clinical_task_time )
2066- sim .modules ['HealthSystem' ]._daily_capabilities ['FacilityID_' + str (facID ) + '_Officer_Nursing_and_Midwifery' ] = Ntarget * (nursing_task_time + nursing_task_shift_factor * pharmacy_task_time )
2067-
2068- # Run healthsystemscheduler
2069- healthsystemscheduler .apply (sim .population )
2070-
2071- # read the results
2072- output = parse_log_file (sim .log_filepath , level = logging .DEBUG )
2073- hs_output = output ['tlo.methods.healthsystem' ]['HSI_Event' ]
2074-
2075- # Check that all events could run, even if Pharmacy capabilities were set to zero,
2076- # and that when task-shifting first option (nurses) where always preferentially chosen over second
2077- # one (clinicians)
2083+ # Allow for task-shifting to take place, and check that all Ntarget events could run, even if Pharmacy
2084+ # capabilities were set to zero,
2085+ hs_output = simulate (task_shifting_option = True , Ntarget = Ntarget )
20782086 assert hs_output ['did_run' ].sum () == Ntarget
2087+
2088+ # Do not allow for task-shifting to take place, and check that as a result no events could run, since
2089+ # Pharmacy capabilities were set to zero.
2090+ hs_output = simulate (task_shifting_option = False , Ntarget = Ntarget )
2091+ assert hs_output ['did_run' ].sum () == 0
20792092
20802093
20812094@pytest .mark .slow
0 commit comments