From 60b936904d8775785766b120153c7b23f8d34bf0 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 2 Dec 2024 10:32:28 +0000 Subject: [PATCH] Added additional testing code for people continuing injectable PrEP without choice. --- src/hivpy/prep.py | 2 +- src/tests/test_prep.py | 32 ++++++++++++++++++++++++++++---- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/src/hivpy/prep.py b/src/hivpy/prep.py index 002627a..11d35cd 100644 --- a/src/hivpy/prep.py +++ b/src/hivpy/prep.py @@ -680,7 +680,7 @@ def continue_prep(self, pop: Population, time_step): # people who can choose to stop or switch this time step prep_choice_pop = pop.get_sub_pop_intersection(eligible, self.get_prep_cont_choice_pop(pop)) - if len(prep_choice_pop) > 0: + if len(eligible) > 0: # continuous prep outcomes prep_types = pop.transform_group([col.PREP_TYPE, col.FAVOURED_PREP_TYPE], self.calc_current_prep, sub_pop=prep_choice_pop, dropna=True) diff --git a/src/tests/test_prep.py b/src/tests/test_prep.py index 620f061..eda55c2 100644 --- a/src/tests/test_prep.py +++ b/src/tests/test_prep.py @@ -848,19 +848,43 @@ def test_continuing_prep(): pop.data[col.FAVOURED_PREP_TYPE] = PrEPType.Oral # nobody stops prep prob_base_prep_stop = 0 + pop.prep.prob_oral_prep_stop = prob_base_prep_stop pop.prep.prob_cab_prep_stop = prob_base_prep_stop pop.prep.prob_len_prep_stop = prob_base_prep_stop + pop.prep.prob_vr_prep_stop = prob_base_prep_stop pop.prep.continue_prep(pop, time_step) # len prep not updated because last prep usage is too recent - print(pop.data[col.LAST_PREP_USE_DATE].array) - print(pop.data[col.PREP_TYPE].array) - print(((pop.data[col.PREP_TYPE] == PrEPType.Lenacapavir) == - (pop.data[col.LAST_PREP_USE_DATE] == pop.date - timedelta(months=3))).array) assert all((pop.data[col.PREP_TYPE] == PrEPType.Lenacapavir) == (pop.data[col.LAST_PREP_USE_DATE] == pop.date - timedelta(months=3))) assert all((pop.data[col.PREP_TYPE] == PrEPType.Oral) == (pop.data[col.LAST_PREP_USE_DATE] == pop.date)) + assert all(pop.data[col.LAST_PREP_STOP_DATE].isnull()) + + pop.data[col.LAST_PREP_USE_DATE] = pop.date - time_step + pop.data[col.PREP_TYPE] = [PrEPType.Oral, PrEPType.Cabotegravir, + PrEPType.Lenacapavir, PrEPType.VaginalRing] * (N // 4) + + pop.prep.continue_prep(pop, time_step) + # no injectable prep updated because last prep usage is too recent + assert all((pop.data[col.PREP_TYPE] != PrEPType.Oral) == + (pop.data[col.LAST_PREP_USE_DATE] == pop.date - time_step)) + assert all((pop.data[col.PREP_TYPE] == PrEPType.Oral) == + (pop.data[col.LAST_PREP_USE_DATE] == pop.date)) + assert sum(pop.data[col.PREP_TYPE] == PrEPType.Oral) == N/2 + assert all(pop.data[col.LAST_PREP_STOP_DATE].isnull()) + + pop.data[col.LAST_PREP_USE_DATE] = pop.date - time_step + pop.data[col.PREP_TYPE] = PrEPType.Lenacapavir + pop.data[col.CONT_ON_PREP] = time_step + pop.data[col.CUMULATIVE_PREP_LEN] = timedelta(months=2) + + pop.prep.continue_prep(pop, time_step) + # everyone continues prep without choice + assert all(pop.data[col.PREP_TYPE] == PrEPType.Lenacapavir) + assert all(pop.data[col.LAST_PREP_USE_DATE] == pop.date - time_step) + assert all((pop.data[col.CONT_ON_PREP] == timedelta(months=2))) + assert all((pop.data[col.CUMULATIVE_PREP_LEN] == timedelta(months=3))) def test_restarting_prep():