From 3e3f98722876ff89fd9136a0e1141500d8da061d Mon Sep 17 00:00:00 2001 From: nicx503 Date: Wed, 29 Jan 2025 13:26:19 +0000 Subject: [PATCH] added return statements and footprints and as treatment_id for Xrays, culture, clinical diagnosis not printed --- src/scripts/hiv/DAH/analysis_tb_DAH10x.py | 2 +- src/scripts/hiv/DAH/tb_DAH_scenarios10x.py | 4 +-- src/tlo/methods/tb.py | 34 ++++++++++++++++------ 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/src/scripts/hiv/DAH/analysis_tb_DAH10x.py b/src/scripts/hiv/DAH/analysis_tb_DAH10x.py index 9847fa2f2f..fa5c78ec4a 100644 --- a/src/scripts/hiv/DAH/analysis_tb_DAH10x.py +++ b/src/scripts/hiv/DAH/analysis_tb_DAH10x.py @@ -36,7 +36,7 @@ #outputfilepath = Path("./outputs") -results_folder = get_scenario_outputs('tb_DAH_scenarios10x-2025-01-29T090853Z', outputfilepath) [-1] +results_folder = get_scenario_outputs('tb_DAH_scenarios10x-2025-01-29T121043Z', outputfilepath) [-1] log = load_pickled_dataframes(results_folder) info = get_scenario_info(results_folder) print(info) diff --git a/src/scripts/hiv/DAH/tb_DAH_scenarios10x.py b/src/scripts/hiv/DAH/tb_DAH_scenarios10x.py index b04ed7f5f6..7e68f4ed28 100644 --- a/src/scripts/hiv/DAH/tb_DAH_scenarios10x.py +++ b/src/scripts/hiv/DAH/tb_DAH_scenarios10x.py @@ -40,8 +40,8 @@ def __init__(self): self.seed = 2134 #self.seed = random.randint(0, 50000), self.start_date = Date(2010, 1, 1) - self.end_date = Date(2011, 12, 31) - self.pop_size = 600 + self.end_date = Date(2012, 12, 31) + self.pop_size = 100 self._scenarios = self._get_scenarios() self.number_of_draws = len(self._scenarios) self.runs_per_draw = 2 diff --git a/src/tlo/methods/tb.py b/src/tlo/methods/tb.py index 1df2bd0931..ec4b0a7d89 100644 --- a/src/tlo/methods/tb.py +++ b/src/tlo/methods/tb.py @@ -2275,21 +2275,25 @@ def apply(self, person_id, squeeze_factor): if not df.at[person_id, "is_alive"] or df.at[person_id, "tb_diagnosed"]: return self.sim.modules["HealthSystem"].get_blank_appt_footprint() + #Run TB culture test test_result = self.sim.modules["HealthSystem"].dx_manager.run_dx_test( dx_tests_to_run="tb_culture_test", hsi_event=self) + #ACTUAL_APPT_FOOTPRINT = self.make_appt_footprint({}) + # todo equipment required: MGIT instrument, MGIT tube, reagent kit included in consumables if test_result is not None: self.add_equipment({'Autoclave', 'Blood culture incubator', 'Vortex mixer', 'Dispensing pumps for culture media preparation', 'Biosafety Cabinet (Class II)', 'Centrifuge'}) + ACTUAL_APPT_FOOTPRINT = self.make_appt_footprint({"LabTBMicro": 1}) + # if test returns positive result, refer for appropriate treatment if test_result: df.at[person_id, "tb_diagnosed"] = True df.at[person_id, "tb_date_diagnosed"] = self.sim.date - ACTUAL_APPT_FOOTPRINT = self.make_appt_footprint({"LabTBMicro": 1}) self.sim.modules["HealthSystem"].schedule_hsi_event( HSI_Tb_StartTreatment( @@ -2302,7 +2306,7 @@ def apply(self, person_id, squeeze_factor): # Return the footprint. If it should be suppressed, return a blank footprint. if self.suppress_footprint: - return self.make_appt_footprint({}) + return else: return ACTUAL_APPT_FOOTPRINT @@ -2326,13 +2330,17 @@ def __init__(self, module, person_id, suppress_footprint=False): self.ACCEPTED_FACILITY_LEVEL = '1b' def apply(self, person_id, squeeze_factor): + persons_symptoms = self.sim.modules["SymptomManager"].has_what(person_id) + if not any(x in self.module.symptom_list for x in persons_symptoms): + print(f"Facility CXR scheduled for person {person_id} due to TB symptoms.") + return self.sim.modules["HealthSystem"].get_blank_appt_footprint() df = self.sim.population.props if not df.at[person_id, "is_alive"] or df.at[person_id, "tb_diagnosed"]: return self.sim.modules["HealthSystem"].get_blank_appt_footprint() - ACTUAL_APPT_FOOTPRINT = self.EXPECTED_APPT_FOOTPRINT + #ACTUAL_APPT_FOOTPRINT = self.EXPECTED_APPT_FOOTPRINT smear_status = df.at[person_id, "tb_smear"] @@ -2355,9 +2363,18 @@ def apply(self, person_id, squeeze_factor): # return blank footprint as xray did not occur if test_result is None: - ACTUAL_APPT_FOOTPRINT = self.make_appt_footprint({}) + if smear_status: + test_result = self.sim.modules["HealthSystem"].dx_manager.run_dx_test( + dx_tests_to_run="tb_clinical", hsi_event=self + ) + + # add another clinic appointment + ACTUAL_APPT_FOOTPRINT = self.make_appt_footprint( + {"Under5OPD": 1, "DiagRadio": 1} + ) - self.sim.modules["HealthSystem"].schedule_hsi_event( + else: + self.sim.modules["HealthSystem"].schedule_hsi_event( HSI_Tb_Xray_level2(person_id=person_id, module=self.module), topen=self.sim.date + pd.DateOffset(weeks=1), tclose=None, @@ -2429,6 +2446,7 @@ def apply(self, person_id, squeeze_factor): test_result = self.sim.modules["HealthSystem"].dx_manager.run_dx_test( dx_tests_to_run="tb_xray_smear_negative", hsi_event=self ) + if test_result is not None: self.add_equipment(self.healthcare_system.equipment.from_pkg_names('X-ray')) @@ -2438,7 +2456,7 @@ def apply(self, person_id, squeeze_factor): # return blank footprint as xray was not available if test_result is None: - ACTUAL_APPT_FOOTPRINT = self.make_appt_footprint({}) + #ACTUAL_APPT_FOOTPRINT = self.make_appt_footprint({}) self.sim.modules["HealthSystem"].schedule_hsi_event( HSI_Tb_ClinicalDiagnosis(person_id=person_id, module=self.module), @@ -2452,8 +2470,6 @@ def apply(self, person_id, squeeze_factor): df.at[person_id, "tb_diagnosed"] = True df.at[person_id, "tb_date_diagnosed"] = self.sim.date - - self.sim.modules["HealthSystem"].schedule_hsi_event( HSI_Tb_StartTreatment( person_id=person_id, module=self.module, facility_level="1a" @@ -2984,7 +3000,7 @@ def apply(self, person_id, squeeze_factor): dx_tests_to_run="tb_xray_smear_negative", hsi_event=self ) - ACTUAL_APPOINTMENT=self.make_appt_footprint({"ConWithDCSA": 1}) + #ACTUAL_APPOINTMENT=self.make_appt_footprint({"ConWithDCSA": 1}) # If the test returns a positive result, refer for appropriate treatment if test_result: