Skip to content

Commit

Permalink
Roll back PR #1027 (#1140)
Browse files Browse the repository at this point in the history
* Revert "Decouple ANC logic from tclose (#1027)"

This reverts commit bbf33e2  **** & subsequent changes

* removed old logic relating to pnc_date that should have been rolled back

---------

Co-authored-by: joehcollins <joseph.h.collins@ucl.ac.uk>
  • Loading branch information
tbhallett and joehcollins authored Oct 2, 2023
1 parent dc702a5 commit 4c3303c
Show file tree
Hide file tree
Showing 10 changed files with 112 additions and 175 deletions.
155 changes: 81 additions & 74 deletions src/tlo/methods/care_of_women_during_pregnancy.py

Large diffs are not rendered by default.

66 changes: 20 additions & 46 deletions src/tlo/methods/labour.py
Original file line number Diff line number Diff line change
Expand Up @@ -2278,12 +2278,7 @@ def run_if_receives_postnatal_check_cant_run(self, hsi_event):
:param hsi_event: HSI event in which the function has been called:
"""
person_id = hsi_event.target
mni = self.sim.modules['PregnancySupervisor'].mother_and_newborn_info

logger.debug(key='message', data=f'HSI_Labour_ReceivesPostnatalCheck will not run for {person_id}')
if person_id in mni:
mni[person_id]['pnc_date'] = pd.NaT

self.apply_risk_of_early_postpartum_death(person_id)

def run_if_receives_comprehensive_emergency_obstetric_care_cant_run(self, hsi_event):
Expand All @@ -2295,17 +2290,12 @@ def run_if_receives_comprehensive_emergency_obstetric_care_cant_run(self, hsi_ev
:param hsi_event: HSI event in which the function has been called:
"""
person_id = hsi_event.target
mni = self.sim.modules['PregnancySupervisor'].mother_and_newborn_info

logger.debug(key='message', data=f'HSI_Labour_ReceivesComprehensiveEmergencyObstetricCare will not run for'
f' {person_id}')

# For women referred to this event after the postnatal SBA HSI we apply risk of death (as if should have been
# applied in this event if it ran)
if hsi_event.timing == 'postpartum':
if person_id in mni:
mni[person_id]['pnc_date'] = pd.NaT

self.apply_risk_of_early_postpartum_death(person_id)


Expand Down Expand Up @@ -2808,7 +2798,6 @@ def apply(self, mother_id):

if timing == '<48' or has_comps:
mni[mother_id]['will_receive_pnc'] = 'early'
mni[mother_id]['pnc_date'] = self.sim.date

early_event = HSI_Labour_ReceivesPostnatalCheck(
module=self.module, person_id=mother_id)
Expand Down Expand Up @@ -2868,10 +2857,6 @@ def apply(self, person_id, squeeze_factor):
if not df.at[person_id, 'is_alive']:
return

# If more than 2 days have passed, keep expected footprint but assume no effect
if (self.sim.date - df.at[person_id, 'la_due_date_current_pregnancy']).days > 2:
return

# First we capture women who have presented to this event during labour at home. Currently we just set these
# women to be delivering at a health centre (this will need to be randomised to match any available data)
if mni[person_id]['delivery_setting'] == 'home_birth' and mni[person_id]['sought_care_for_complication']:
Expand Down Expand Up @@ -3016,7 +3001,11 @@ def never_ran(self):
self.module.run_if_receives_skilled_birth_attendance_cant_run(self)

def did_not_run(self):
pass
self.module.run_if_receives_skilled_birth_attendance_cant_run(self)
return False

def not_available(self):
self.module.run_if_receives_skilled_birth_attendance_cant_run(self)


class HSI_Labour_ReceivesPostnatalCheck(HSI_Event, IndividualScopeEventMixin):
Expand All @@ -3043,15 +3032,6 @@ def apply(self, person_id, squeeze_factor):
if not df.at[person_id, 'is_alive'] or pd.isnull(df.at[person_id, 'la_date_most_recent_delivery']):
return None

if person_id in mni:
if pd.isnull(mni[person_id]['pnc_date']):
return None

if (self.sim.date - mni[person_id]['pnc_date']).days > 2:
mni[person_id]['pnc_date'] = pd.NaT
self.module.apply_risk_of_early_postpartum_death(person_id)
return

# Ensure that women who were scheduled to receive early PNC have received care prior to passing through
# PostnatalWeekOneMaternalEvent

Expand All @@ -3069,9 +3049,6 @@ def apply(self, person_id, squeeze_factor):
if not df.at[person_id, 'la_pn_checks_maternal'] == 0:
logger.info(key='error', data=f'Mother {person_id} attended late PNC twice')

if pd.isnull(mni[person_id]['pnc_date']) and (df.at[person_id, 'la_pn_checks_maternal'] == 0):
logger.info(key='error', data='Individual at PNC HSI without topen')

# Run checks
self.module.postpartum_characteristics_checker(person_id)

Expand Down Expand Up @@ -3133,7 +3110,6 @@ def apply(self, person_id, squeeze_factor):

# ====================================== APPLY RISK OF DEATH===================================================
if not mni[person_id]['referred_for_surgery'] and not mni[person_id]['referred_for_blood']:
mni[person_id]['pnc_date'] = pd.NaT
self.module.apply_risk_of_early_postpartum_death(person_id)

return self.EXPECTED_APPT_FOOTPRINT
Expand All @@ -3142,7 +3118,11 @@ def never_ran(self):
self.module.run_if_receives_postnatal_check_cant_run(self)

def did_not_run(self):
pass
self.module.run_if_receives_postnatal_check_cant_run(self)
return False

def not_available(self):
self.module.run_if_receives_postnatal_check_cant_run(self)

def _get_facility_level_for_pnc(self, person_id):
mni = self.sim.modules['PregnancySupervisor'].mother_and_newborn_info
Expand Down Expand Up @@ -3176,20 +3156,6 @@ def apply(self, person_id, squeeze_factor):
mni = self.sim.modules['PregnancySupervisor'].mother_and_newborn_info
params = self.module.current_parameters

# If more than 2 days have passed, keep expected footprint but assume no effect
if (self.timing == 'intrapartum') and \
(self.sim.date - df.at[person_id, 'la_due_date_current_pregnancy']).days > 2:
return

if self.timing == 'postpartum':
if pd.isnull(mni[person_id]['pnc_date']) and (df.at[person_id, 'la_pn_checks_maternal'] == 0):
logger.info(key='error', data='Individual at PNC HSI (comp) without topen')

if (self.sim.date - mni[person_id]['pnc_date']).days > 2:
mni[person_id]['pnc_date'] = pd.NaT
self.module.apply_risk_of_early_postpartum_death(person_id)
return

# If the squeeze factor is too high we assume delay in receiving interventions occurs (increasing risk
# of death if complications occur)
pregnancy_helper_functions.check_if_delayed_care_delivery(self.module, squeeze_factor, person_id,
Expand Down Expand Up @@ -3267,7 +3233,6 @@ def apply(self, person_id, squeeze_factor):
# Women who have passed through the postpartum SBA HSI have not yet had their risk of death calculated because
# they required interventions delivered via this event. We now determine if these women will survive
if self.timing == 'postpartum':
mni[person_id]['pnc_date'] = pd.NaT
self.module.apply_risk_of_early_postpartum_death(person_id)

# Schedule HSI that captures inpatient days
Expand All @@ -3293,7 +3258,11 @@ def never_ran(self):
self.module.run_if_receives_comprehensive_emergency_obstetric_care_cant_run(self)

def did_not_run(self):
pass
self.module.run_if_receives_comprehensive_emergency_obstetric_care_cant_run(self)
return False

def not_available(self):
self.module.run_if_receives_comprehensive_emergency_obstetric_care_cant_run(self)


class HSI_Labour_PostnatalWardInpatientCare(HSI_Event, IndividualScopeEventMixin):
Expand All @@ -3318,6 +3287,11 @@ def apply(self, person_id, squeeze_factor):

def did_not_run(self):
logger.debug(key='message', data='HSI_Labour_PostnatalWardInpatientCare: did not run')
return False

def not_available(self):
logger.debug(key='message', data='HSI_Labour_PostnatalWardInpatientCare: cannot not run with '
'this configuration')


class LabourAndPostnatalCareAnalysisEvent(Event, PopulationScopeEventMixin):
Expand Down
28 changes: 10 additions & 18 deletions src/tlo/methods/newborn_outcomes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1060,7 +1060,6 @@ def schedule_pnc(self, child_id):
# will automatically attend early
if (timing == '<48') or (m['pnc_twin_one'] == 'early'):
nci[child_id]['will_receive_pnc'] = 'early'
nci[child_id]['pnc_date'] = self.sim.date

if df.at[mother_id, 'ps_multiple_pregnancy'] and (m['twin_count'] == 1):
m['pnc_twin_one'] = 'early'
Expand Down Expand Up @@ -1213,8 +1212,7 @@ def on_birth(self, mother_id, child_id):
'sepsis_postnatal': False,
'passed_through_week_one': False,
'will_receive_pnc': 'none',
'third_delay': False,
'pnc_date': pd.NaT}
'third_delay': False}

if mni[mother_id]['clean_birth_practices']:
df.at[child_id, 'nb_clean_birth'] = True
Expand Down Expand Up @@ -1364,7 +1362,6 @@ def run_if_care_of_the_receives_postnatal_check_cant_run(self, hsi_event):
logger.debug(key='message', data=f'HSI_NewbornOutcomes_ReceivesPostnatalCheck did not run for '
f'{person_id}')
if person_id in nci:
nci[person_id]['date_pnc_check'] = pd.NaT
self.set_death_status(person_id)


Expand Down Expand Up @@ -1392,15 +1389,6 @@ def apply(self, person_id, squeeze_factor):
if not df.at[person_id, 'is_alive'] or df.at[person_id, 'nb_death_after_birth'] or (person_id not in nci):
return

if person_id in nci:
if pd.isnull(nci[person_id]['pnc_date']):
return None

if (self.sim.date - nci[person_id]['pnc_date']).days > 2:
nci[person_id]['date_pnc_check'] = pd.NaT
self.module.set_death_status(person_id)
return

if (nci[person_id]['will_receive_pnc'] == 'early') and not nci[person_id]['passed_through_week_one']:
if not self.sim.date <= (df.at[person_id, 'date_of_birth'] + pd.DateOffset(days=2)):
logger.info(key='error', data=f'Child {person_id} arrived at early PNC too late')
Expand All @@ -1415,17 +1403,13 @@ def apply(self, person_id, squeeze_factor):
if not df.at[person_id, 'nb_pnc_check'] == 0:
logger.info(key='error', data=f'Child {person_id} arrived at late PNC twice')

if pd.isnull(nci[person_id]['pnc_date']):
logger.info(key='error', data='Individual at neonatal PNC HSI without topen')

# Log the PNC check
logger.info(key='postnatal_check', data={'person_id': person_id,
'delivery_setting': nci[person_id]['delivery_setting'],
'visit_number': df.at[person_id, 'nb_pnc_check'],
'timing': nci[person_id]['will_receive_pnc']})

df.at[person_id, 'nb_pnc_check'] += 1
nci[person_id]['date_pnc_check'] = pd.NaT

if squeeze_factor > params['squeeze_threshold_for_delay_three_nb_care']:
nci[person_id]['third_delay'] = True
Expand Down Expand Up @@ -1459,7 +1443,11 @@ def never_ran(self):
self.module.run_if_care_of_the_receives_postnatal_check_cant_run(self)

def did_not_run(self):
pass
self.module.run_if_care_of_the_receives_postnatal_check_cant_run(self)
return False

def not_available(self):
self.module.run_if_care_of_the_receives_postnatal_check_cant_run(self)

def _get_facility_level_for_pnc(self, person_id):
nci = self.module.newborn_care_info
Expand Down Expand Up @@ -1491,7 +1479,11 @@ def apply(self, person_id, squeeze_factor):

def did_not_run(self):
logger.debug(key='message', data='HSI_PostnatalSupervisor_NeonatalWardInpatientCare: did not run')
return False

def not_available(self):
logger.debug(key='message', data='HSI_PostnatalSupervisor_NeonatalWardInpatientCare: cannot not run with '
'this configuration')
return False


Expand Down
8 changes: 0 additions & 8 deletions src/tlo/methods/postnatal_supervisor.py
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,6 @@ def log_new_progressed_cases(disease):
# Schedule the HSI event
for person in care_seekers.loc[care_seekers].index:
from tlo.methods.labour import HSI_Labour_ReceivesPostnatalCheck
mni[person]['pnc_date'] = self.sim.date

# check if care seeking is delayed
if self.rng.random_sample() < self.sim.modules['Labour'].current_parameters['prob_delay_one_two_fd']:
Expand Down Expand Up @@ -798,7 +797,6 @@ def set_postnatal_complications_neonates(self, upper_and_lower_day_limits):

# We schedule the HSI according
for person in care_seeking.loc[care_seeking].index:
nci[person]['pnc_date'] = self.sim.date

from tlo.methods.newborn_outcomes import HSI_NewbornOutcomes_ReceivesPostnatalCheck
postnatal_check = HSI_NewbornOutcomes_ReceivesPostnatalCheck(
Expand Down Expand Up @@ -1187,8 +1185,6 @@ def log_new_progressed_cases(disease):
if (mni[individual_id]['will_receive_pnc'] == 'late') or (self.module.rng.random_sample() <
params['prob_care_seeking_postnatal_emergency']):

mni[individual_id]['pnc_date'] = self.sim.date

# If care will be sought, check if they experience delay seeking care
pregnancy_helper_functions.check_if_delayed_careseeking(self.module, individual_id)

Expand All @@ -1203,7 +1199,6 @@ def log_new_progressed_cases(disease):
# Women without complications in week one are scheduled to attend PNC in the future
if mni[individual_id]['will_receive_pnc'] == 'late':
appt_date = self.sim.date + pd.DateOffset(self.module.rng.randint(0, 35))
mni[individual_id]['pnc_date'] = appt_date
self.sim.modules['HealthSystem'].schedule_hsi_event(
pnc_one_maternal, priority=0, topen=appt_date, tclose=appt_date + pd.DateOffset(days=2))

Expand Down Expand Up @@ -1248,11 +1243,9 @@ def apply(self, individual_id):

# Neonates with sepsis are more likely to receive PNC that those without
if df.at[individual_id, 'pn_sepsis_early_neonatal']:

if ((nci[individual_id]['will_receive_pnc'] == 'late') or (self.module.rng.random_sample() <
params['prob_care_seeking_postnatal_'
'emergency_neonate'])):
nci[individual_id]['pnc_date'] = self.sim.date

self.sim.modules['HealthSystem'].schedule_hsi_event(pnc_one_neonatal,
priority=0,
Expand All @@ -1267,7 +1260,6 @@ def apply(self, individual_id):
elif not df.at[individual_id, 'pn_sepsis_early_neonatal'] and (nci[individual_id]['will_'
'receive_pnc'] == 'late'):
days_till_day_7 = 7 - df.at[individual_id, 'age_days']
nci[individual_id]['pnc_date'] = self.sim.date

self.sim.modules['HealthSystem'].schedule_hsi_event(
pnc_one_neonatal,
Expand Down
3 changes: 0 additions & 3 deletions src/tlo/methods/pregnancy_helper_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -627,8 +627,6 @@ def update_mni_dictionary(self, individual_id):
'vesicovaginal_fistula_resolution': pd.NaT,
'rectovaginal_fistula_onset': pd.NaT,
'rectovaginal_fistula_resolution': pd.NaT,
'date_anc_admission': pd.NaT,
'date_preg_emergency': pd.NaT,
'test_run': False, # used by labour module when running some model tests
'pred_syph_infect': pd.NaT, # date syphilis is predicted to onset
'new_onset_spe': False,
Expand Down Expand Up @@ -670,7 +668,6 @@ def update_mni_dictionary(self, individual_id):
'death_in_labour': False, # True (T) or False (F)
'single_twin_still_birth': False, # True (T) or False (F)
'will_receive_pnc': 'none',
'pnc_date': pd.NaT,
'passed_through_week_one': False}

mni[individual_id].update(labour_variables)
Expand Down
2 changes: 0 additions & 2 deletions src/tlo/methods/pregnancy_supervisor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1846,8 +1846,6 @@ def apply_death_risk(person_id):
for person in care_seeking.loc[care_seeking].index:
if not df.at[person, 'hs_is_inpatient']:

mni[person]['date_preg_emergency'] = self.sim.date

# Determine if care seeking is delayed
pregnancy_helper_functions.check_if_delayed_careseeking(self.module, person)

Expand Down
Loading

0 comments on commit 4c3303c

Please sign in to comment.