Skip to content

Commit

Permalink
Added additional testing code for people continuing injectable PrEP w…
Browse files Browse the repository at this point in the history
…ithout choice.
  • Loading branch information
pineapple-cat committed Dec 2, 2024
1 parent 2505e8f commit 60b9369
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/hivpy/prep.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
32 changes: 28 additions & 4 deletions src/tests/test_prep.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down

0 comments on commit 60b9369

Please sign in to comment.