Skip to content

Commit e371450

Browse files
Param Revamp - Depression (#1701)
* param revamp depression * fix linting errors * update param labeling * update refill window to be local param --------- Co-authored-by: Tim Hallett <[email protected]>
1 parent a5ce511 commit e371450

File tree

2 files changed

+80
-21
lines changed

2 files changed

+80
-21
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:d742f62f0915073bb672c43d9d558599ef38f456f2134d2729d246a6d6d130de
3-
size 3438
2+
oid sha256:f9bb95649b9b8fbf76571b56617c1a4e590ccea40b7f9154565bafe28f4ba3e1
3+
size 5440

src/tlo/methods/depression.py

Lines changed: 78 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,42 @@ def __init__(self, name=None):
198198
'pr_assessed_for_depression_for_perinatal_female': Parameter(
199199
Types.REAL,
200200
'Probability that a perinatal female is assessed for depression during antenatal or postnatal services'),
201+
202+
'recently_pregnant_threshold_years': Parameter(
203+
Types.INT, 'Time period to consider a woman as recently pregnant'
204+
),
205+
206+
'max_talking_therapy_sessions': Parameter(
207+
Types.INT, 'Maximum number of talking therapy sessions per course'
208+
),
209+
210+
'talking_therapy_interval_months': Parameter(
211+
Types.INT, 'Interval between talking therapy sessions in months'
212+
),
213+
214+
'antidepr_refill_interval_months': Parameter(
215+
Types.INT, 'Interval for antidepressant refill appointments in months'
216+
),
217+
218+
'antidepr_refill_window_days': Parameter(
219+
Types.INT, 'Window period for antidepressant refill appointments in days'
220+
),
221+
222+
'selfharm_suicide_event_max_days': Parameter(
223+
Types.INT, 'Maximum days for scheduling self-harm/suicide events'
224+
),
225+
226+
'depression_polling_frequency_months': Parameter(
227+
Types.INT, 'Frequency of depression polling events in months'
228+
),
229+
230+
'age_threshold_adult_care': Parameter(
231+
Types.INT, 'Minimum age for care in non-peds in years'
232+
),
233+
234+
'age_threshold_depression': Parameter(
235+
Types.INT, 'Minimum age for depression'
236+
),
201237
}
202238

203239
# Properties of individuals 'owned' by this module
@@ -267,13 +303,15 @@ def read_parameters(self, resourcefilepath: Optional[Path]=None):
267303
# risk of ever having depression in initial population
268304
self.linearModels['Depression_Ever_At_Population_Initialisation_Males'] = LinearModel.multiplicative(
269305
Predictor('age_years').apply(
270-
lambda x: (x if x > 15 else 0) * self.parameters['init_rp_ever_depr_per_year_older_m']
306+
lambda x: (x if x > p['age_threshold_depression'] else 0) *
307+
self.parameters['init_rp_ever_depr_per_year_older_m']
271308
)
272309
)
273310

274311
# risk of ever having depression in initial population (female)
275312
self.linearModels['Depression_Ever_At_Population_Initialisation_Females'] = LinearModel.multiplicative(
276-
Predictor('age_years').apply(lambda x: (x if x > 15 else 0) * p['init_rp_ever_depr_per_year_older_f'])
313+
Predictor('age_years').apply(lambda x: (x if x > p['age_threshold_depression'] else 0) *
314+
p['init_rp_ever_depr_per_year_older_f'])
277315
)
278316

279317
# risk of ever having diagnosed depression in initial population
@@ -391,6 +429,7 @@ def apply_linear_model(self, lm, df):
391429

392430
def initialise_population(self, population):
393431
df = population.props
432+
p = self.parameters
394433
df['de_depr'] = False
395434
df['de_ever_depr'] = False
396435
df['de_date_init_most_rec_depr'] = pd.NaT
@@ -401,7 +440,7 @@ def initialise_population(self, population):
401440
df['de_ever_talk_ther'] = False
402441
df['de_ever_non_fatal_self_harm_event'] = False
403442
df['de_recently_pregnant'] = df['is_pregnant'] | (
404-
df['date_of_last_pregnancy'] > (self.sim.date - DateOffset(years=1))
443+
df['date_of_last_pregnancy'] > (self.sim.date - DateOffset(years=p['recently_pregnant_threshold_years']))
405444
)
406445
df['de_cc'] = False
407446

@@ -487,12 +526,14 @@ def initialise_simulation(self, sim):
487526
df = sim.population.props
488527
if df['de_on_antidepr'].sum():
489528
for person_id in df.loc[df['de_on_antidepr']].index:
490-
date_of_next_appt_scheduled = self.sim.date + DateOffset(days=self.rng.randint(0, 30))
529+
date_of_next_appt_scheduled = self.sim.date + DateOffset(
530+
days=self.rng.randint(0, self.parameters['antidepr_refill_interval_months']*30)
531+
)
491532
self.sim.modules['HealthSystem'].schedule_hsi_event(
492533
hsi_event=HSI_Depression_Refill_Antidepressant(person_id=person_id, module=self),
493534
priority=1,
494535
topen=date_of_next_appt_scheduled,
495-
tclose=date_of_next_appt_scheduled + DateOffset(days=7)
536+
tclose=date_of_next_appt_scheduled + DateOffset(days=self.parameters['antidepr_refill_window_days'])
496537
)
497538

498539
def on_birth(self, mother_id, child_id):
@@ -668,7 +709,7 @@ def diagnosis_function(tests, use_dict: bool = False, report_tried: bool = False
668709
def do_at_generic_first_appt(
669710
self, individual_properties: IndividualProperties, **kwargs
670711
) -> None:
671-
if individual_properties["age_years"] > 5:
712+
if individual_properties["age_years"] > self.parameters["age_threshold_adult_care"]:
672713
self.do_at_generic_first_appt_emergency(
673714
individual_properties=individual_properties,
674715
**kwargs,
@@ -710,7 +751,7 @@ class DepressionPollingEvent(RegularEvent, PopulationScopeEventMixin):
710751
"""
711752

712753
def __init__(self, module):
713-
super().__init__(module, frequency=DateOffset(months=3))
754+
super().__init__(module, frequency=DateOffset(months=module.parameters['depression_polling_frequency_months']))
714755

715756
def apply(self, population):
716757
# Create some shortcuts
@@ -721,12 +762,12 @@ def apply(self, population):
721762
# -----------------------------------------------------------------------------------------------------
722763
# Update properties that are used by the module
723764
df['de_recently_pregnant'] = df['is_pregnant'] | (
724-
df['date_of_last_pregnancy'] > (self.sim.date - DateOffset(years=1)))
765+
df['date_of_last_pregnancy'] > (self.sim.date - DateOffset(years=p['recently_pregnant_threshold_years'])))
725766

726767
assert (df.loc[df['is_pregnant'], 'de_recently_pregnant']).all()
727768
assert not (df['de_recently_pregnant'] & pd.isnull(df['date_of_last_pregnancy'])).any()
728769
assert (df.loc[((~df['is_pregnant']) & df['de_recently_pregnant']), 'date_of_last_pregnancy'] > (
729-
self.sim.date - DateOffset(years=1))).all()
770+
self.sim.date - DateOffset(years=p['recently_pregnant_threshold_years']))).all()
730771

731772
# -----------------------------------------------------------------------------------------------------
732773
# Determine who will be onset with depression among those who are not currently depressed
@@ -769,17 +810,25 @@ def apply(self, population):
769810
df.loc[df['is_alive'] & df['de_depr']]
770811
)
771812
for person_id in will_self_harm_in_next_3mo.loc[will_self_harm_in_next_3mo].index:
772-
self.sim.schedule_event(DepressionSelfHarmEvent(self.module, person_id),
773-
self.sim.date + DateOffset(days=self.module.rng.randint(0, 90)))
813+
self.sim.schedule_event(
814+
DepressionSelfHarmEvent(self.module, person_id),
815+
self.sim.date + DateOffset(
816+
days=self.module.rng.randint(0, p['selfharm_suicide_event_max_days'])
817+
)
818+
)
774819

775820
# Schedule Suicide events for those with current depression (individual level events)
776821
will_suicide_in_next_3mo = apply_linear_model(
777822
self.module.linearModels['Risk_of_Suicide_per3mo'],
778823
df.loc[df['is_alive'] & df['de_depr']]
779824
)
780825
for person_id in will_suicide_in_next_3mo.loc[will_suicide_in_next_3mo].index:
781-
self.sim.schedule_event(DepressionSuicideEvent(self.module, person_id),
782-
self.sim.date + DateOffset(days=self.module.rng.randint(0, 90)))
826+
self.sim.schedule_event(
827+
DepressionSuicideEvent(self.module, person_id),
828+
self.sim.date + DateOffset(
829+
days=self.module.rng.randint(0, p['selfharm_suicide_event_max_days'])
830+
)
831+
)
783832

784833

785834
class DepressionSelfHarmEvent(Event, IndividualScopeEventMixin):
@@ -928,10 +977,10 @@ def apply(self, person_id, squeeze_factor):
928977
if not df.at[person_id, 'de_ever_talk_ther']:
929978
df.at[person_id, 'de_ever_talk_ther'] = True
930979

931-
if self.num_of_sessions_had < 5:
980+
if self.num_of_sessions_had < self.module.parameters['max_talking_therapy_sessions']:
932981
self.sim.modules['HealthSystem'].schedule_hsi_event(
933982
hsi_event=self,
934-
topen=self.sim.date + pd.DateOffset(months=6),
983+
topen=self.sim.date + pd.DateOffset(months=self.module.parameters['talking_therapy_interval_months']),
935984
tclose=None,
936985
priority=1
937986
)
@@ -952,6 +1001,7 @@ def __init__(self, module, person_id):
9521001

9531002
def apply(self, person_id, squeeze_factor):
9541003
df = self.sim.population.props
1004+
p = self.module.parameters
9551005

9561006
# If person is already on anti-depressants, do not do anything
9571007
if df.at[person_id, 'de_on_antidepr']:
@@ -972,8 +1022,12 @@ def apply(self, person_id, squeeze_factor):
9721022
self.sim.modules['HealthSystem'].schedule_hsi_event(
9731023
hsi_event=HSI_Depression_Refill_Antidepressant(person_id=person_id, module=self.module),
9741024
priority=1,
975-
topen=self.sim.date + DateOffset(months=1),
976-
tclose=self.sim.date + DateOffset(months=1) + DateOffset(days=7)
1025+
topen=self.sim.date + DateOffset(months=p['antidepr_refill_interval_months']),
1026+
tclose=(
1027+
self.sim.date +
1028+
DateOffset(months=p['antidepr_refill_interval_months']) +
1029+
DateOffset(days=p['antidepr_refill_window_days'])
1030+
)
9771031
)
9781032

9791033

@@ -994,6 +1048,7 @@ def __init__(self, module, person_id):
9941048

9951049
def apply(self, person_id, squeeze_factor):
9961050
df = self.sim.population.props
1051+
p = self.module.parameters
9971052

9981053
assert df.at[person_id, 'de_ever_diagnosed_depression'], "The person is not diagnosed and so should not be " \
9991054
"receiving an HSI. "
@@ -1013,8 +1068,12 @@ def apply(self, person_id, squeeze_factor):
10131068
self.sim.modules['HealthSystem'].schedule_hsi_event(
10141069
hsi_event=HSI_Depression_Refill_Antidepressant(person_id=person_id, module=self.module),
10151070
priority=1,
1016-
topen=self.sim.date + DateOffset(months=1),
1017-
tclose=self.sim.date + DateOffset(months=1) + DateOffset(days=7)
1071+
topen=self.sim.date + DateOffset(months=p['antidepr_refill_interval_months']),
1072+
tclose=(
1073+
self.sim.date +
1074+
DateOffset(months=p['antidepr_refill_interval_months']) +
1075+
DateOffset(days=p['antidepr_refill_window_days'])
1076+
)
10181077
)
10191078
else:
10201079
# If medication was not available, the persons ceases to be taking antidepressants

0 commit comments

Comments
 (0)