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

Improve MNH logging #1477

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
0c7aa41
created mnh_outcome_logger to eventually replace logging for complica…
joehcollins Oct 7, 2024
87d6f1f
created mnh_outcome_logger to eventually replace logging for complica…
joehcollins Oct 7, 2024
cdd9842
added first logging to pregnancy supervisor
joehcollins Oct 7, 2024
b9a193d
finalising logging event
joehcollins Oct 8, 2024
ada05e0
add health system logging
joehcollins Oct 8, 2024
bfac245
old logging removed
joehcollins Oct 8, 2024
905091b
fix
joehcollins Oct 8, 2024
5a04b44
fix
joehcollins Oct 8, 2024
c62d5df
fix
joehcollins Oct 8, 2024
d8423e1
comments for clarity
joehcollins Oct 8, 2024
a6b12fe
removed counting which wasnt needed
joehcollins Oct 8, 2024
5ca2314
fixes to pregnancy_supervisor test
joehcollins Oct 9, 2024
c271e72
Merge branch 'master' into jcollins/updated_mnh_logging
joehcollins Oct 10, 2024
09a216f
fix denom error
joehcollins Oct 10, 2024
03161e0
fix indentation error
joehcollins Oct 10, 2024
de3ee93
added missing logging
joehcollins Oct 10, 2024
0acf362
removed unused variable
joehcollins Nov 11, 2024
8cc45ab
additional counters and updates to mnh_
joehcollins Dec 2, 2024
2055304
Merge branch 'master' into jcollins/updated_mnh_logging
joehcollins Dec 2, 2024
593f9cd
update calculate_risk_of_death_from_causes to allow for cause of deat…
joehcollins Dec 2, 2024
fdb1adc
Merge branch 'master' into jcollins/updated_mnh_logging
tbhallett Dec 9, 2024
8a88892
Merge branch 'master' into jcollins/updated_mnh_logging
tbhallett Dec 13, 2024
1855730
Merge branch 'master' into jcollins/updated_mnh_logging
tbhallett Dec 15, 2024
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
17 changes: 10 additions & 7 deletions src/tlo/methods/care_of_women_during_pregnancy.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,21 +484,24 @@ def further_on_birth_care_of_women_in_pregnancy(self, mother_id):

if df.at[mother_id, 'is_alive']:

anc_count = df.at[mother_id, "ac_total_anc_visits_current_pregnancy"]

# run a check at birth to make sure no women exceed 8 visits
if df.at[mother_id, 'ac_total_anc_visits_current_pregnancy'] > 9:
if anc_count > 9:
logger.info(key='error', data=f'Mother {mother_id} attended >8 ANC visits during her pregnancy')

# We log the total number of ANC contacts a woman has undergone at the time of birth via this dictionary
if anc_count > 8:
self.sim.modules['PregnancySupervisor'].mnh_outcome_counter['anc8+'] += 1
else:
self.sim.modules['PregnancySupervisor'].mnh_outcome_counter[f'anc{anc_count}'] += 1

# We log the gestational age at first ANC
if 'ga_anc_one' in mni[mother_id]:
ga_anc_one = float(mni[mother_id]['ga_anc_one'])
else:
ga_anc_one = 0.0

total_anc_visit_count = {'person_id': mother_id,
'total_anc': df.at[mother_id, 'ac_total_anc_visits_current_pregnancy'],
'ga_anc_one': ga_anc_one}

logger.info(key='anc_count_on_birth', data=total_anc_visit_count,
logger.info(key='ga_at_anc1', data={'person_id': mother_id, 'ga_anc_one': ga_anc_one},
description='A dictionary containing the number of ANC visits each woman has on birth')

def on_hsi_alert(self, person_id, treatment_id):
Expand Down
102 changes: 33 additions & 69 deletions src/tlo/methods/labour.py
Original file line number Diff line number Diff line change
Expand Up @@ -1056,9 +1056,10 @@ def further_on_birth_labour(self, mother_id):
mni = self.sim.modules['PregnancySupervisor'].mother_and_newborn_info

# log delivery setting
logger.info(key='delivery_setting_and_mode', data={'mother': mother_id,
'facility_type': str(mni[mother_id]['delivery_setting']),
'mode': mni[mother_id]['mode_of_delivery']})
logger.info(key='delivery_mode', data={'mother': mother_id, 'mode': mni[mother_id]['mode_of_delivery']})

self.sim.modules['PregnancySupervisor'].mnh_outcome_counter[
f'{str(mni[mother_id]["delivery_setting"])}_delivery'] += 1

# Store only live births to a mother parity
if not df.at[mother_id, 'la_intrapartum_still_birth']:
Expand Down Expand Up @@ -1282,9 +1283,7 @@ def set_intrapartum_complications(self, individual_id, complication):
pregnancy_helper_functions.store_dalys_in_mni(individual_id, mni, 'obstructed_labour_onset',
self.sim.date)

logger.info(key='maternal_complication', data={'person': individual_id,
'type': f'{complication}',
'timing': 'intrapartum'})
self.sim.modules['PregnancySupervisor'].mnh_outcome_counter[complication] += 1

if complication == 'obstruction_cpd':
mni[individual_id]['cpd'] = True
Expand All @@ -1293,9 +1292,8 @@ def set_intrapartum_complications(self, individual_id, complication):
# to labour)
elif complication == 'placental_abruption':
df.at[individual_id, 'la_placental_abruption'] = True
logger.info(key='maternal_complication', data={'person': individual_id,
'type': 'placental_abruption',
'timing': 'intrapartum'})

self.sim.modules['PregnancySupervisor'].mnh_outcome_counter['placental_abruption'] += 1

elif complication == 'antepartum_haem':
random_choice = self.rng.choice(['mild_moderate', 'severe'],
Expand All @@ -1305,33 +1303,29 @@ def set_intrapartum_complications(self, individual_id, complication):
if random_choice != 'severe':
pregnancy_helper_functions.store_dalys_in_mni(individual_id, mni, 'mild_mod_aph_onset',
self.sim.date)
logger.info(key='maternal_complication', data={'person': individual_id,
'type': 'mild_mod_antepartum_haemorrhage',
'timing': 'intrapartum'})

self.sim.modules['PregnancySupervisor'].mnh_outcome_counter['mild_mod_antepartum_haemorrhage'] += 1

else:
pregnancy_helper_functions.store_dalys_in_mni(individual_id, mni, 'severe_aph_onset',
self.sim.date)
logger.info(key='maternal_complication', data={'person': individual_id,
'type': 'severe_antepartum_haemorrhage',
'timing': 'intrapartum'})

self.sim.modules['PregnancySupervisor'].mnh_outcome_counter['severe_antepartum_haemorrhage'] += 1

elif complication == 'sepsis_chorioamnionitis':
df.at[individual_id, 'la_sepsis'] = True
mni[individual_id]['chorio_in_preg'] = True
pregnancy_helper_functions.store_dalys_in_mni(individual_id, mni, 'sepsis_onset',
self.sim.date)
logger.info(key='maternal_complication', data={'person': individual_id,
'type': 'sepsis',
'timing': 'intrapartum'})

self.sim.modules['PregnancySupervisor'].mnh_outcome_counter['sepsis_intrapartum'] += 1

elif complication == 'uterine_rupture':
df.at[individual_id, 'la_uterine_rupture'] = True
pregnancy_helper_functions.store_dalys_in_mni(individual_id, mni, f'{complication}_onset',
self.sim.date)
logger.info(key='maternal_complication', data={'person': individual_id,
'type': 'uterine_rupture',
'timing': 'intrapartum'})

self.sim.modules['PregnancySupervisor'].mnh_outcome_counter['uterine_rupture'] += 1

def set_postpartum_complications(self, individual_id, complication):
"""
Expand Down Expand Up @@ -1384,9 +1378,7 @@ def set_postpartum_complications(self, individual_id, complication):
# Set primary complication to true
df.at[individual_id, 'la_postpartum_haem'] = True

logger_pn.info(key='maternal_complication', data={'person': individual_id,
'type': f'{complication}',
'timing': 'postnatal'})
self.sim.modules['PregnancySupervisor'].mnh_outcome_counter[complication] += 1

# Store mni variables used during treatment
if complication == 'pph_uterine_atony':
Expand Down Expand Up @@ -1422,13 +1414,6 @@ def progression_of_hypertensive_disorders(self, individual_id, property_prefix):
params = self.current_parameters
mni = self.sim.modules['PregnancySupervisor'].mother_and_newborn_info

if property_prefix == 'ps':
timing = 'intrapartum'
current_log = logger
else:
timing = 'postnatal'
current_log = logger_pn

# n.b. on birth women whose hypertension will continue into the postnatal period have their disease state stored
# in a new property therefore antenatal/intrapartum hypertension is 'ps_htn_disorders' and postnatal is
# 'pn_htn_disorders' hence the use of property prefix variable (as this function is called before and after
Expand All @@ -1454,9 +1439,7 @@ def progression_of_hypertensive_disorders(self, individual_id, property_prefix):
pregnancy_helper_functions.store_dalys_in_mni(individual_id, mni, 'eclampsia_onset',
self.sim.date)

current_log.info(key='maternal_complication', data={'person': individual_id,
'type': 'eclampsia',
'timing': timing})
self.sim.modules['PregnancySupervisor'].mnh_outcome_counter['eclampsia'] +=1

# Or from mild to severe gestational hypertension, risk reduced by treatment
if df.at[individual_id, f'{property_prefix}_htn_disorders'] == 'gest_htn':
Expand All @@ -1469,29 +1452,23 @@ def progression_of_hypertensive_disorders(self, individual_id, property_prefix):
if risk_prog_gh_sgh > self.rng.random_sample():
df.at[individual_id, f'{property_prefix}_htn_disorders'] = 'severe_gest_htn'

current_log.info(key='maternal_complication', data={'person': individual_id,
'type': 'severe_gest_htn',
'timing': timing})
self.sim.modules['PregnancySupervisor'].mnh_outcome_counter['severe_gest_htn'] +=1

# Or from severe gestational hypertension to severe pre-eclampsia...
if df.at[individual_id, f'{property_prefix}_htn_disorders'] == 'severe_gest_htn':
if params['prob_progression_severe_gest_htn'] > self.rng.random_sample():
df.at[individual_id, f'{property_prefix}_htn_disorders'] = 'severe_pre_eclamp'
mni[individual_id]['new_onset_spe'] = True

current_log.info(key='maternal_complication', data={'person': individual_id,
'type': 'severe_pre_eclamp',
'timing': timing})
self.sim.modules['PregnancySupervisor'].mnh_outcome_counter['severe_pre_eclamp'] +=1

# Or from mild pre-eclampsia to severe pre-eclampsia...
if df.at[individual_id, f'{property_prefix}_htn_disorders'] == 'mild_pre_eclamp':
if params['prob_progression_mild_pre_eclamp'] > self.rng.random_sample():
df.at[individual_id, f'{property_prefix}_htn_disorders'] = 'severe_pre_eclamp'
mni[individual_id]['new_onset_spe'] = True

current_log.info(key='maternal_complication', data={'person': individual_id,
'type': 'severe_pre_eclamp',
'timing': timing})
self.sim.modules['PregnancySupervisor'].mnh_outcome_counter['severe_pre_eclamp'] +=1

def apply_risk_of_early_postpartum_death(self, individual_id):
"""
Expand Down Expand Up @@ -1519,9 +1496,12 @@ def apply_risk_of_early_postpartum_death(self, individual_id):
# If a cause is returned death is scheduled
if potential_cause_of_death:
pregnancy_helper_functions.log_mni_for_maternal_death(self, individual_id)
self.sim.modules['PregnancySupervisor'].mnh_outcome_counter['direct_mat_death'] += 1

self.sim.modules['Demography'].do_death(individual_id=individual_id, cause=potential_cause_of_death,
originating_module=self.sim.modules['Labour'])


# If she hasn't died from any complications, we reset some key properties that resolve after risk of death
# has been applied
else:
Expand Down Expand Up @@ -2423,29 +2403,20 @@ def apply(self, individual_id):
'defining_term_status'][3]:

mni[individual_id]['labour_state'] = 'early_preterm_labour'

logger.info(key='maternal_complication', data={'person': individual_id,
'type': 'early_preterm_labour',
'timing': 'intrapartum'})
self.sim.modules['PregnancySupervisor'].mnh_outcome_counter['early_preterm_labour'] += 1

elif params['list_limits_for_defining_term_status'][4] <= gestational_age_in_days <= params['list_limits'
'_for_defining'
'_term_'
'status'][5]:

mni[individual_id]['labour_state'] = 'late_preterm_labour'

logger.info(key='maternal_complication', data={'person': individual_id,
'type': 'late_preterm_labour',
'timing': 'intrapartum'})
self.sim.modules['PregnancySupervisor'].mnh_outcome_counter['late_preterm_labour'] += 1

elif gestational_age_in_days >= params['list_limits_for_defining_term_status'][6]:

mni[individual_id]['labour_state'] = 'postterm_labour'

logger.info(key='maternal_complication', data={'person': individual_id,
'type': 'post_term_labour',
'timing': 'intrapartum'})
self.sim.modules['PregnancySupervisor'].mnh_outcome_counter['post_term_labour'] += 1

labour_state = mni[individual_id]['labour_state']

Expand Down Expand Up @@ -2612,9 +2583,7 @@ def apply(self, individual_id):
self.module.set_intrapartum_complications(individual_id, complication=complication)

if df.at[individual_id, 'la_obstructed_labour']:
logger.info(key='maternal_complication', data={'person': individual_id,
'type': 'obstructed_labour',
'timing': 'intrapartum'})
self.sim.modules['PregnancySupervisor'].mnh_outcome_counter['obstructed_labour'] += 1

# And we determine if any existing hypertensive disorders would worsen
self.module.progression_of_hypertensive_disorders(individual_id, property_prefix='ps')
Expand Down Expand Up @@ -2686,6 +2655,7 @@ def apply(self, individual_id):
# If a cause is returned death is scheduled
if potential_cause_of_death:
pregnancy_helper_functions.log_mni_for_maternal_death(self.module, individual_id)
self.sim.modules['PregnancySupervisor'].mnh_outcome_counter['direct_mat_death'] += 1
self.sim.modules['Demography'].do_death(individual_id=individual_id, cause=potential_cause_of_death,
originating_module=self.sim.modules['Labour'])

Expand Down Expand Up @@ -2729,8 +2699,7 @@ def apply(self, individual_id):
del mni[individual_id]

if df.at[individual_id, 'la_intrapartum_still_birth'] or mni[individual_id]['single_twin_still_birth']:
logger.info(key='intrapartum_stillbirth', data={'mother_id': individual_id,
'date_of_ip_stillbirth': self.sim.date})
self.sim.modules['PregnancySupervisor'].mnh_outcome_counter['intrapartum_stillbirth'] += 1

# Reset property
if individual_id in mni:
Expand Down Expand Up @@ -2818,13 +2787,10 @@ def apply(self, mother_id):
self.module.set_postpartum_complications(mother_id, complication=complication)

if df.at[mother_id, 'la_sepsis_pp']:
logger_pn.info(key='maternal_complication', data={'person': mother_id,
'type': 'sepsis_postnatal',
'timing': 'postnatal'})
self.sim.modules['PregnancySupervisor'].mnh_outcome_counter['sepsis_postnatal'] += 1

if df.at[mother_id, 'la_postpartum_haem']:
logger_pn.info(key='maternal_complication', data={'person': mother_id,
'type': 'primary_postpartum_haemorrhage',
'timing': 'postnatal'})
self.sim.modules['PregnancySupervisor'].mnh_outcome_counter['primary_postpartum_haemorrhage'] += 1

self.module.progression_of_hypertensive_disorders(mother_id, property_prefix='pn')

Expand Down Expand Up @@ -2977,9 +2943,7 @@ def apply(self, person_id, squeeze_factor):
self.module.progression_of_hypertensive_disorders(person_id, property_prefix='ps')

if df.at[person_id, 'la_obstructed_labour']:
logger.info(key='maternal_complication', data={'person': person_id,
'type': 'obstructed_labour',
'timing': 'intrapartum'})
self.sim.modules['PregnancySupervisor'].mnh_outcome_counter['obstructed_labour'] += 1

# ======================================= COMPLICATION MANAGEMENT ==========================
# Next, women in labour are assessed for complications and treatment delivered if a need is identified and
Expand Down
Loading
Loading