Skip to content
Open
Show file tree
Hide file tree
Changes from 102 commits
Commits
Show all changes
128 commits
Select commit Hold shift + click to select a range
35d6287
diabetes module and test file
thewati Feb 11, 2025
fd4fa73
Add HSI and appointment
thewati Feb 11, 2025
97487a0
Add HSI and appointment fix
thewati Feb 11, 2025
df1b116
Adding DR analyses file
thewati Feb 14, 2025
e8524dc
Renaming files and adding effectiveness in HSI
thewati Feb 20, 2025
0419122
tidy up
thewati Feb 24, 2025
626155c
Merge branch 'master' into wati/diabetic_retinopathy
thewati Feb 24, 2025
84968f0
HSI testing for symptoms, stacked bars, temp item codes in res file, …
thewati Feb 27, 2025
1a8a2e5
reformat test file, add initial prevalence test
thewati Feb 28, 2025
6df9cf5
tidy up
thewati Feb 28, 2025
3c41ba3
more tidy up
thewati Feb 28, 2025
0a4800a
reworked plots
thewati Mar 12, 2025
7c2729b
High prevalence tests and Diet Management HSI. HSI call Incomplete
thewati Mar 12, 2025
4b35792
comment out unused variables
thewati Mar 13, 2025
ba71d97
diet management initial param and linear model. Define treatment IDs …
thewati Mar 17, 2025
4e6e8a7
Selected for regular eye exam
thewati Mar 21, 2025
af8bad3
Merge branch 'master' into wati/diabetic_retinopathy
tbhallett Mar 31, 2025
cee5630
New stages. 3 tests adjusted
thewati Apr 7, 2025
780d438
Remove Testing HSI
thewati Apr 7, 2025
ad861fe
Consumables and severe stage regression, zero prev test logic
thewati Apr 7, 2025
c9f40c0
Merge remote-tracking branch 'origin/wati/diabetic_retinopathy' into …
thewati Apr 8, 2025
f307e0b
tidy up
thewati Apr 8, 2025
ac614b9
declare has_dmo, and has_csdmo_ncsdmo
thewati May 6, 2025
b06af99
remove unused variable and import
thewati May 6, 2025
76b633c
remove Dr_Investigation
thewati May 6, 2025
5a609ab
Merge branch 'master' into wati/diabetic_retinopathy
thewati May 22, 2025
d0fc275
prob matrix for dmo_status
thewati May 26, 2025
bcc95f2
remove List todo
thewati May 26, 2025
63eea54
Mapping dmo_status to dr_status using probs
thewati May 27, 2025
c7ec0e8
Use HSI_CardioMetabolicDisorders_StartWeightLossAndMedication in firs…
thewati May 28, 2025
e5b2fdb
HSI for DR and DMO. Disconnected. Removed Health Mgmt
thewati May 29, 2025
1d31d39
Merge branch 'master' into wati/diabetic_retinopathy
thewati Jun 13, 2025
3a35f7c
Merge branch 'master' into wati/diabetic_retinopathy
thewati Jun 13, 2025
a67bdd1
Modifying LM
thewati Jun 17, 2025
4fa42d8
Add LM Predictor for people ever been treated. Remove resourcefilepat…
thewati Jun 25, 2025
0de5c4c
Calling HSI_Dr_Dmo_AdvancedTreatment
thewati Jun 25, 2025
01c5de2
Tidy up
thewati Jun 26, 2025
8c2694c
Merge branch 'master' into wati/diabetic_retinopathy
thewati Jun 26, 2025
7d981df
tidy up
thewati Jun 26, 2025
85d8691
Parameters for controlled diabetes
thewati Jul 10, 2025
813ce1b
Controlled diabetes regression to "none" in polling event
thewati Jul 10, 2025
c67b606
tidy up
thewati Jul 10, 2025
74ff6dd
Resource file. Not populated
thewati Jul 10, 2025
104f4a4
resolve conflict
thewati Jul 14, 2025
b1dc7b1
Merge branch 'master' into wati/diabetic_retinopathy
thewati Jul 14, 2025
8c41334
resolve conflicts
thewati Jul 15, 2025
01d2739
readme
thewati Jul 15, 2025
02f4ad9
remove moderate stage and introduce mild/moderate stage
thewati Aug 21, 2025
1ad3fe4
HSI Laser Pan Retinal Coagulation. Not working yet
thewati Aug 22, 2025
155f363
Add 4 HSIs
thewati Aug 27, 2025
4d72e19
eligible population for screening
thewati Aug 27, 2025
b77cbd1
Selected for screening from polling event
thewati Aug 28, 2025
85097f5
call eye exam cons in HSI
thewati Sep 18, 2025
70801f2
schedule mild moderate from eye exam
thewati Oct 1, 2025
70fa684
progression logic for proliferative, severe and mild/moderate
thewati Oct 1, 2025
638a78b
Merge branch 'master' into wati/diabetic_retinopathy
thewati Oct 1, 2025
c99e5de
update priority policies in healthsystem
thewati Oct 1, 2025
f2cc431
remove unused variables
thewati Oct 2, 2025
b586bfc
add session
thewati Oct 2, 2025
f8e9e26
change comment in laser pan retinal coagulation
thewati Oct 6, 2025
75cd2c7
remove generic first appointment
thewati Oct 9, 2025
6a59ff7
remove unused params and symbols. Partially populate resource file
thewati Oct 30, 2025
fd25bb3
call csmo HSIs
thewati Oct 31, 2025
f9447bf
Merge branch 'master' into wati/diabetic_retinopathy
thewati Oct 31, 2025
c846cfd
Equipment and consumables
thewati Nov 19, 2025
c6b8723
Merge branch 'master' into wati/diabetic_retinopathy
thewati Nov 19, 2025
aa9b9e1
Fix errors from merge
thewati Nov 19, 2025
474566b
parameters use csv
thewati Dec 4, 2025
0bb709b
changes years in eye exam to params
thewati Dec 4, 2025
6657544
.
thewati Dec 9, 2025
0a95a42
Merge remote-tracking branch 'origin/master'
thewati Dec 9, 2025
c81e3a5
reformat
thewati Dec 11, 2025
d7e4526
Change logic of HSI Laser PRC
thewati Dec 12, 2025
2d266c7
add diabetes_duration_greater_than_15_years as risk factor
thewati Dec 12, 2025
3fd8de2
re-work dr and dmo combination scheduling
thewati Dec 12, 2025
c93e484
Merge branch 'master' into wati/diabetic_retinopathy
thewati Dec 12, 2025
6e84902
Merge remote-tracking branch 'origin/master'
thewati Dec 28, 2025
3a5a782
Merge branch 'master' into wati/diabetic_retinopathy
thewati Jan 3, 2026
492c004
treatment success
thewati Jan 3, 2026
f6cd794
Merge remote-tracking branch 'origin/master'
thewati Jan 12, 2026
b5f655a
Merge branch 'master' into wati/diabetic_retinopathy
thewati Jan 14, 2026
8ce181d
treatment improving vision path
thewati Jan 14, 2026
341da6a
create diagnostic for dilated eye exam
thewati Jan 16, 2026
d2cf2a5
report dalys
thewati Jan 16, 2026
d6519f1
normalise cols to sum to 1
thewati Jan 19, 2026
660f2a0
Merge remote-tracking branch 'origin/master'
thewati Jan 19, 2026
54330f1
Merge branch 'master' into wati/diabetic_retinopathy
thewati Jan 19, 2026
6475b06
fix progression logic and dr_diagnosed
thewati Jan 19, 2026
8590b2f
Add logging. Fix resourcefile issue
thewati Jan 19, 2026
7536de8
isort
thewati Jan 20, 2026
74e7486
Merge remote-tracking branch 'origin/master'
thewati Jan 23, 2026
8b2a6b2
review HSI, update update_vision_status, date_last_screening
thewati Jan 27, 2026
11128c3
cleann up and re-work transition matrices
thewati Jan 27, 2026
e3d3c41
Merge remote-tracking branch 'origin/master'
thewati Jan 27, 2026
2b51c8a
Merge branch 'master' into wati/diabetic_retinopathy
thewati Jan 27, 2026
3cd79bc
policy files update
thewati Jan 28, 2026
992984a
Merge remote-tracking branch 'origin/master'
thewati Feb 3, 2026
af3261e
Merge remote-tracking branch 'origin/master'
thewati Feb 4, 2026
8c0a02d
Merge remote-tracking branch 'origin/master'
thewati Feb 9, 2026
541555d
Merge remote-tracking branch 'origin/master'
thewati Feb 11, 2026
685d91c
Merge remote-tracking branch 'origin/master'
thewati Feb 12, 2026
5b704b3
Merge branch 'master' into wati/diabetic_retinopathy
thewati Feb 12, 2026
f48c011
Merge remote-tracking branch 'origin/master'
thewati Feb 16, 2026
2dbd72b
Merge branch 'master' into wati/diabetic_retinopathy
thewati Feb 16, 2026
29f3a3d
Merge remote-tracking branch 'origin/master'
thewati Feb 19, 2026
f31863d
Merge branch 'master' into wati/diabetic_retinopathy
thewati Feb 19, 2026
d064b81
From LFS to Git
thewati Feb 19, 2026
9a577b0
Update equip availability estimates
thewati Feb 19, 2026
5436c6f
Merge remote-tracking branch 'origin/master'
thewati Feb 25, 2026
f3d65f8
Merge remote-tracking branch 'origin/master'
thewati Mar 11, 2026
88d4012
Addressing comments
thewati Mar 11, 2026
42fc098
Merge branch 'master' into wati/diabetic_retinopathy
thewati Mar 11, 2026
7d92e23
Merge remote-tracking branch 'origin/master'
thewati Mar 12, 2026
05aba63
Merge remote-tracking branch 'origin/master'
thewati Mar 19, 2026
dc00df5
Merge remote-tracking branch 'origin/master'
thewati Mar 30, 2026
866c737
Use dictionary
thewati Mar 31, 2026
d7764e9
Rollback. Changed wrong file
thewati Mar 31, 2026
d79246d
incidence and its plots
thewati Apr 17, 2026
dfb7ff1
Merge remote-tracking branch 'origin/master'
thewati Apr 20, 2026
92f9160
Merge branch 'master' into wati/diabetic_retinopathy
thewati Apr 20, 2026
e00d1d5
Merge branch 'master' into wati/diabetic_retinopathy
Gabbie123king Apr 20, 2026
93830d1
use nc_diabetes_date_onset from CMD as a risk factor
Gabbie123king Apr 23, 2026
6a1349e
Merge branch 'master' into wati/diabetic_retinopathy
Gabbie123king Apr 30, 2026
f934aaf
use diabetes_onset_dates from CMD as a risk factor
Gabbie123king Apr 30, 2026
713f489
plotting incidence and prevalence
thewati May 4, 2026
b3e967a
Merge remote-tracking branch 'origin/wati/diabetic_retinopathy' into …
thewati May 4, 2026
94056d8
change to yearly poll and logging
thewati May 18, 2026
be82c21
log every month and plot prev among diabetics
thewati Jun 18, 2026
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
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
import datetime
from pathlib import Path

import matplotlib.pyplot as plt
import pandas as pd

from tlo import Date, Simulation
from tlo.analysis.utils import parse_log_file
from tlo.methods import (
cardio_metabolic_disorders,
care_of_women_during_pregnancy,
contraception,
demography,
depression,
diabetic_retinopathy,
enhanced_lifestyle,
epi,
healthburden,
healthseekingbehaviour,
healthsystem,
hiv,
labour,
newborn_outcomes,
oesophagealcancer,
postnatal_supervisor,
pregnancy_supervisor,
symptommanager,
tb,
)

# Where will outputs go
outputpath = Path("./outputs") # folder for convenience of storing outputs

# date-stamp to label log files and any other outputs
datestamp = datetime.date.today().strftime("__%Y_%m_%d")

# The resource files
resourcefilepath = Path("./resources")

# Set parameters for the simulation
start_date = Date(2010, 1, 1)
end_date = Date(2012, 1, 1)
popsize = 5000

def run_sim(service_availability):
# log_config = {
# 'filename': 'LogFile',
# 'directory': outputpath
# }
sim = Simulation(start_date=start_date, seed=0, log_config={"filename": "LogFile"})

# Register the appropriate modules
sim.register(care_of_women_during_pregnancy.CareOfWomenDuringPregnancy(resourcefilepath=resourcefilepath),
demography.Demography(resourcefilepath=resourcefilepath),
contraception.Contraception(resourcefilepath=resourcefilepath),
enhanced_lifestyle.Lifestyle(resourcefilepath=resourcefilepath),
healthsystem.HealthSystem(resourcefilepath=resourcefilepath,
service_availability=service_availability),
symptommanager.SymptomManager(resourcefilepath=resourcefilepath),
healthseekingbehaviour.HealthSeekingBehaviour(resourcefilepath=resourcefilepath),
healthburden.HealthBurden(resourcefilepath=resourcefilepath),
labour.Labour(resourcefilepath=resourcefilepath),
newborn_outcomes.NewbornOutcomes(resourcefilepath=resourcefilepath),
pregnancy_supervisor.PregnancySupervisor(resourcefilepath=resourcefilepath),
oesophagealcancer.OesophagealCancer(resourcefilepath=resourcefilepath),
postnatal_supervisor.PostnatalSupervisor(resourcefilepath=resourcefilepath),
diabetic_retinopathy.DiabeticRetinopathy(),
hiv.Hiv(resourcefilepath=resourcefilepath),
tb.Tb(resourcefilepath=resourcefilepath),
epi.Epi(resourcefilepath=resourcefilepath),
cardio_metabolic_disorders.CardioMetabolicDisorders(resourcefilepath=resourcefilepath),
depression.Depression(resourcefilepath=resourcefilepath),
)

# Run the simulation
sim.make_initial_population(n=popsize)
sim.simulate(end_date=end_date)

return sim.log_filepath

def get_summary_stats(logfile):
output = parse_log_file(logfile)
counts_by_stage = output['tlo.methods.diabetic_retinopathy']['summary_stats']
counts_by_stage['date'] = pd.to_datetime(counts_by_stage['date'])
counts_by_stage = counts_by_stage.set_index('date', drop=True)

# summary = {
# 'total': counts_by_stage.filter(like='total_').sum(axis=1),
# 'off': counts_by_stage.filter(like='off_treatment_').sum(axis=1),
# 'tr': counts_by_stage.filter(like='treatment_').sum(axis=1),
# 'new_early': counts_by_stage.get('new_early', pd.Series(0, index=counts_by_stage.index)),
# 'new_late': counts_by_stage.get('new_late', pd.Series(0, index=counts_by_stage.index))
# }

# 2) NUMBERS UNDIAGNOSED-DIAGNOSED-TREATED-PALLIATIVE CARE OVER TIME (SUMMED ACROSS TYPES OF CANCER)
def get_cols_excl_none(allcols, stub):
# helper function to some columns with a certain prefix stub - excluding the 'none' columns (ie. those
# that do not have cancer)
cols = allcols[allcols.str.startswith(stub)]
cols_not_none = [s for s in cols if ("none" not in s)]
return cols_not_none

summary = {
'total': counts_by_stage[get_cols_excl_none(counts_by_stage.columns, 'total_')].sum(axis=1),
'udx': counts_by_stage[get_cols_excl_none(counts_by_stage.columns, 'undiagnosed_')].sum(axis=1),
'dx': counts_by_stage[get_cols_excl_none(counts_by_stage.columns, 'diagnosed_')].sum(axis=1),
'tr': counts_by_stage[get_cols_excl_none(counts_by_stage.columns, 'treatment_')].sum(axis=1)
}

counts_by_cascade = pd.DataFrame(summary)
# counts_by_stage['year'] = counts_by_stage.index.year
# incidence_by_stage = pd.DataFrame({'new_early': summary['new_early'], 'new_late': summary['new_late']})

# Rates of diagnosis per year:
counts_by_stage['year'] = counts_by_stage.index.year
annual_count_of_dxtr = counts_by_stage.groupby(by='year')[['diagnosed_since_last_log',
'treated_since_last_log']].sum()

return {
'total_counts_by_stage_over_time': counts_by_stage,
'counts_by_cascade': counts_by_cascade,
'annual_count_of_dxtr': annual_count_of_dxtr
}


def plot_dr_progression(counts_by_stage, title):
"""Plot stacked bars for early and late diabetic retinopathy over time."""

# Set the index to be years only
counts_by_stage = counts_by_stage.copy()
counts_by_stage.index = counts_by_stage.index.strftime('%Y-%m')

fig, ax = plt.subplots(figsize=(12, 6))

counts_by_stage[['total_early', 'total_late']].plot(
kind='bar', stacked=True, ax=ax, colormap="viridis"
)

ax.set_title(title)
ax.set_xlabel("Time (Months & Years)")
ax.set_ylabel("Number of People")
ax.legend(["Early DR", "Late DR"])
plt.xticks(rotation=45) # Rotate x-axis labels for readability

plt.tight_layout()
plt.show()

def plot_treatment_cascade(counts_by_cascade, title):
"""Plot stacked bar chart for treatment status over time."""

counts_by_cascade = counts_by_cascade.copy()
counts_by_cascade.index = counts_by_cascade.index.strftime('%Y-%m')

fig, ax = plt.subplots(figsize=(12, 6))

counts_by_cascade[['udx', 'dx', 'tr']].plot(
kind='bar', stacked=True, ax=ax, colormap="coolwarm"
)

ax.set_title(title)
ax.set_xlabel("Time (Months & Years)")
ax.set_ylabel("Number of People")
ax.legend(['Undiagnosed', 'Diagnosed', 'On Treatment'])
plt.xticks(rotation=45)

plt.tight_layout()
plt.show()


def plot_dr_incidence(incidence_by_stage, title):
"""Plot stacked bars for new cases of early and late DR over time."""
incidence_by_stage = incidence_by_stage.copy()
incidence_by_stage.index = incidence_by_stage.index.strftime('%Y-%m')

print(f'Incidence data for plotting {incidence_by_stage.head()}')

fig, ax = plt.subplots(figsize=(12, 6))
incidence_by_stage[['new_early', 'new_late']].plot(kind='bar', stacked=True, ax=ax, colormap="plasma")

ax.set_title(title)
ax.set_xlabel("Time (Months & Years)")
ax.set_ylabel("Number of New Cases")
ax.legend(["New Early DR Cases", "New Late DR Cases"])
plt.xticks(rotation=45)
plt.tight_layout()
plt.show()


try:
logfile_with_healthsystem = run_sim(service_availability=['*'])
results_with_healthsystem = get_summary_stats(logfile_with_healthsystem)

logfile_no_healthsystem = run_sim(service_availability=[])
results_no_healthsystem = get_summary_stats(logfile_no_healthsystem)

plot_dr_progression(results_with_healthsystem['total_counts_by_stage_over_time'], "DR Progression Over Time (With Health System)")
plot_dr_progression(results_no_healthsystem['total_counts_by_stage_over_time'], "DR Progression Over Time (No Health System)")
plot_treatment_cascade(results_with_healthsystem['counts_by_cascade'], "Treatment Status Over Time (With Health System)")
plot_treatment_cascade(results_no_healthsystem['counts_by_cascade'], "Treatment Status Over Time (No Health System)")
# plot_dr_incidence(results_with_healthsystem['incidence_by_stage'], "DR Incidence Over Time (With Health System)")
# plot_dr_incidence(results_no_healthsystem['incidence_by_stage'], "DR Incidence Over Time (No Health System)")

except Exception as e:
print(f"Error running simulation: {str(e)}")
raise
Loading