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

Stopping PrEP usage #216

Open
wants to merge 14 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/hivpy/column_names.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,10 @@
FIRST_CAB_START_DATE = "first_cab_start_date" # None | date: start date of first ever injectable Cab PrEP usage
FIRST_LEN_START_DATE = "first_len_start_date" # None | date: start date of first ever injectable Len PrEP usage
FIRST_VR_START_DATE = "first_vr_start_date" # None | date: start date of first ever vaginal ring PrEP usage
LAST_PREP_START_DATE = "last_prep_start_date" # None | date: start date of most recent PrEP usage
LAST_PREP_START_DATE = "last_prep_start_date" # None | date: start date of most recent PrEP usage
PREP_JUST_STARTED = "prep_just_started" # Bool: True if PrEP usage began this time step
LAST_PREP_STOP_DATE = "last_prep_stop_date" # None | date: stop date of most recent PrEP usage
LAST_PREP_USE_DATE = "last_prep_use_date" # None | date: most recent date of PrEP usage
LAST_PREP_STOP_DATE = "last_prep_stop_date" # None | date: stop date of most recent PrEP usage
PREP_PAUSED = "prep_paused" # Bool: True if PrEP usage is paused this time step due to ineligibility
CONT_ON_PREP = "cont_on_prep" # None | timedelta: total length of continuous usage of current PrEP based on user intention (breaks due to ineligibility do not count against continuity)
CONT_ACTIVE_ON_PREP = "cont_active_on_prep" # None | timedelta: actual total length of continuous usage of current PrEP
Expand Down
25 changes: 24 additions & 1 deletion src/hivpy/prep.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ def init_prep_variables(self, pop: Population):
pop.init_variable(col.FIRST_VR_START_DATE, None)
pop.init_variable(col.LAST_PREP_START_DATE, None)
pop.init_variable(col.PREP_JUST_STARTED, False)
pop.init_variable(col.LAST_PREP_USE_DATE, None)
pop.init_variable(col.LAST_PREP_STOP_DATE, None)
pop.init_variable(col.PREP_PAUSED, False)
pop.init_variable(col.CONT_ON_PREP, timedelta(months=0))
Expand Down Expand Up @@ -193,6 +194,20 @@ def get_presumed_hiv_neg_pop(self, pop: Population):

return pop.apply_bool_mask(mask, false_neg_pop)

def get_prep_cont_choice_pop(self, pop: Population):
"""
Return the sub-population that have reached a point in their PrEP usage
where they can choose whether to stop or switch. For people on oral
or vaginal ring PrEP this happens every time step, but injectable PrEP
takes some time to wear off (~3 months for cab and ~6 months for len).
"""
return pop.get_sub_pop(OR(COND(col.PREP_TYPE, op.eq, PrEPType.Oral),
COND(col.PREP_TYPE, op.eq, PrEPType.VaginalRing),
AND(COND(col.PREP_TYPE, op.eq, PrEPType.Cabotegravir),
COND(col.LAST_PREP_USE_DATE, op.le, pop.date - timedelta(months=3))),
AND(COND(col.PREP_TYPE, op.eq, PrEPType.Lenacapavir),
COND(col.LAST_PREP_USE_DATE, op.le, pop.date - timedelta(months=6)))))

def prep_preference(self, pop: Population):
"""
Determine PrEP preferences for all PrEP types.
Expand Down Expand Up @@ -531,6 +546,7 @@ def tested_start_prep(self, pop: Population, prep_eligible_pop, prep_type,
pop.set_present_variable(col.CONT_ACTIVE_ON_PREP, time_step, starting_prep_pop)
# increment cumulative use
self.set_all_prep_cumulative(pop, starting_prep_pop, time_step)
pop.set_present_variable(col.LAST_PREP_USE_DATE, pop.date, starting_prep_pop)

def general_start_prep(self, pop: Population, prep_eligible_pop, time_step):
"""
Expand All @@ -557,6 +573,7 @@ def general_start_prep(self, pop: Population, prep_eligible_pop, time_step):
pop.set_present_variable(col.CONT_ACTIVE_ON_PREP, time_step, starting_prep_pop)
# increment cumulative use
self.set_all_prep_cumulative(pop, starting_prep_pop, time_step)
pop.set_present_variable(col.LAST_PREP_USE_DATE, pop.date, starting_prep_pop)

def set_all_prep_start_dates(self, pop: Population, starting_prep_pop):
"""
Expand Down Expand Up @@ -660,11 +677,15 @@ def continue_prep(self, pop: Population, time_step):
OR(COND(col.LAST_TEST_DATE, op.ne, pop.date),
AND(COND(col.LAST_TEST_DATE, op.eq, pop.date),
COND(col.HIV_DIAGNOSED, op.eq, False)))))
# 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(eligible) > 0:
# continuous prep outcomes
prep_types = pop.transform_group([col.PREP_TYPE, col.FAVOURED_PREP_TYPE],
self.calc_current_prep, sub_pop=eligible, dropna=True)
self.calc_current_prep, sub_pop=prep_choice_pop, dropna=True)
# get all current prep types and replace with new outcomes where necessary
prep_types = pop.get_variable(col.PREP_TYPE, eligible).combine(prep_types, lambda _, y: y)
mmcleod89 marked this conversation as resolved.
Show resolved Hide resolved
# find various sub-populations
# people who are continuing current prep
continuing_prep_mask = pop.get_variable(col.PREP_TYPE, eligible) == prep_types
Expand Down Expand Up @@ -696,6 +717,7 @@ def continue_prep(self, pop: Population, time_step):
if len(using_prep_pop) > 0:
# increment cumulative use
self.set_all_prep_cumulative(pop, using_prep_pop, time_step)
pop.set_present_variable(col.LAST_PREP_USE_DATE, pop.date, using_prep_pop)

if len(stopping_prep_pop) > 0:
# stop continuous use
Expand Down Expand Up @@ -752,6 +774,7 @@ def restart_prep(self, pop: Population, time_step):
pop.set_present_variable(col.CONT_ACTIVE_ON_PREP, time_step, restarting_prep_pop)
# increment cumulative use
self.set_all_prep_cumulative(pop, restarting_prep_pop, time_step)
pop.set_present_variable(col.LAST_PREP_USE_DATE, pop.date, restarting_prep_pop)
# unset stop date
pop.set_present_variable(col.LAST_PREP_STOP_DATE, None, restarting_prep_pop)
# unpause prep
Expand Down