Skip to content

Commit

Permalink
improve pre-hypertension, and include correct meds (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
benwallace2nhs authored Dec 16, 2024
2 parents 66bfef9 + bdb178b commit 86b2417
Show file tree
Hide file tree
Showing 5 changed files with 396 additions and 200 deletions.
42 changes: 33 additions & 9 deletions notebooks/ht_analysis.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,39 @@
" truncated_str = date_str[:10]\n",
" return pd.to_datetime(truncated_str)\n",
"\n",
"def date_first_ht_med(meds_df, patient_id):\n",
" patient_ht_meds = meds_df[(meds_df[\"PATIENT\"] == patient_id) & (meds_df[\"REASONCODE\"] == \"hypertension_dx\")]\n",
" first_date = patient_meds[\"START\"].min()\n",
" return first_date\n",
"def date_first_and_last_ht_med(meds_df, patient_id):\n",
" patient_ht_meds = meds_df[(meds_df[\"PATIENT\"] == patient_id) & (meds_df[\"REASONCODE\"] == \"Essential hypertension (disorder)\")]\n",
" first_date = patient_ht_meds[\"START\"].min()\n",
" last_date = patient_ht_meds[\"START\"].max()\n",
" return first_date, last_date\n",
"\n",
"def plot_bp(patient_id, obs_df, conds, encounters):\n",
"def plot_bp(patient_id, obs_df, conds, meds):\n",
" \n",
" ht_conds = conds[conds[\"DESCRIPTION\"] == \"Essential hypertension (disorder)\"]\n",
" ht_patients = list(ht_conds[\"PATIENT\"])\n",
" ht_meds = meds[meds[\"REASONCODE\"] == \"Essential hypertension (disorder)\"]\n",
" ht_meds_patients = set(ht_meds[\"PATIENT\"])\n",
" if patient_id in ht_patients:\n",
" ht_diagnosis_date = ht_conds[ht_conds[\"PATIENT\"] == patient_id][\"START\"].iloc[0]\n",
" print(ht_diagnosis_date)\n",
" ht_diagnosis_date = date_format(ht_diagnosis_date)\n",
" print(ht_diagnosis_date)\n",
" \n",
" else:\n",
" ht_diagnosis_date = None\n",
"\n",
" if patient_id in ht_meds_patients:\n",
" date_meds_first, date_meds_last = date_first_and_last_ht_med(meds, patient_id)\n",
" date_meds_last = date_format(date_meds_last)\n",
" date_meds_first = date_format(date_meds_first)\n",
"\n",
" if date_meds_first == date_meds_last:\n",
" date_meds_last = None\n",
" else:\n",
" date_meds_first = None\n",
" date_meds_last = None\n",
"\n",
"\n",
" sys_values = obs_df[(obs_df[\"DESCRIPTION\"].str.contains(\"Systolic\")) & (obs[\"PATIENT\"] == patient_id)]\n",
" dia_values = obs_df[(obs_df[\"DESCRIPTION\"].str.contains(\"Diastolic\")) & (obs[\"PATIENT\"] == patient_id)]\n",
" fig, ax = plt.subplots(1,1, figsize=(8,4))\n",
Expand All @@ -71,6 +89,12 @@
"\n",
" if ht_diagnosis_date:\n",
" ax.axvline(ht_diagnosis_date, label=\"HT Diagnosis\", c=\"r\", linestyle = \"--\")\n",
" \n",
" if date_meds_first:\n",
" ax.axvline(date_meds_first, label=\"First HT Meds\", c=\"b\", linestyle = \"--\")\n",
" \n",
" if date_meds_last:\n",
" ax.axvline(date_meds_last, label=\"Last HT Meds\", c=\"g\", linestyle = \"--\")\n",
" ax.set_title(title)\n",
" plt.xticks(rotation = 45)\n",
" plt.legend()\n",
Expand All @@ -87,8 +111,8 @@
"patients = list(set(conds[\"PATIENT\"]))\n",
"\n",
"# plot for first 10 patients\n",
"for pat in patients[:4]:\n",
" plot_bp(pat, obs, conds, encounters)"
"for pat in patients[:10]:\n",
" plot_bp(pat, obs, conds, meds)"
]
},
{
Expand Down Expand Up @@ -226,7 +250,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "swp",
"display_name": ".venv",
"language": "python",
"name": "python3"
},
Expand All @@ -240,7 +264,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.16"
"version": "3.12.0"
}
},
"nbformat": 4,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,7 @@ public double getValue(long time) {
cachedValue = baseline
+ getMedicationImpacts(person)
+ getLifestyleImpacts(person, baseline, time)
+ getVariation(person, time)
+ getPreHypertensionImpacts(person);
+ getVariation(person, time);

cacheTime = time;
return cachedValue;
Expand Down Expand Up @@ -133,7 +132,7 @@ private static double getDrugImpact(Person person, String drug, SysDias sysDias,
private double calculateBaseline(Person person) {
boolean hypertension = (boolean) person.attributes.getOrDefault("hypertension", false);
boolean severe = (boolean) person.attributes.getOrDefault("hypertension_severe", false);

int pre_hypertension_step = ((Number) person.attributes.getOrDefault("pre_hypertension_step", 0)).intValue();
double baseline;

String bpBaselineKey = "bp_baseline_" + hypertension + "_" + sysDias.toString();
Expand All @@ -144,7 +143,7 @@ private double calculateBaseline(Person person) {

} else {
if (sysDias == SysDias.SYSTOLIC) {
if (hypertension) {
if (hypertension && pre_hypertension_step > 0) {
if (severe) {
// this leaves fewer people at the upper end of the spectrum
baseline = person.rand(HYPERTENSIVE_SYS_BP_RANGE[1], HYPERTENSIVE_SYS_BP_RANGE[2]);
Expand All @@ -157,7 +156,7 @@ private double calculateBaseline(Person person) {
baseline = person.rand(NORMAL_SYS_BP_RANGE);
}
} else {
if (hypertension) {
if (hypertension && pre_hypertension_step > 0) {
baseline = person.rand(HYPERTENSIVE_DIA_BP_RANGE);
} else {
baseline = person.rand(NORMAL_DIA_BP_RANGE);
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/htn_drugs.csv
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@ Diuretic,Diuretic,Triamterene/HCTZ,310818,hydroCHLOROthiazide 50 MG / triamteren
Diuretic,Diuretic,Amiloride,977880,aMILoride hydrochloride 5 MG Oral Tablet,-11.5,-16.29,-9.3,-11.7
Diuretic,Diuretic,HCTZ,310798,Hydrochlorothiazide 25 MG Oral Tablet,-11.5,-16.29,-9.3,-11.7
Ace Inhibitor,ACE or ARB,Lisinopril,314076,lisinopril 10 MG Oral Tablet,-11.5,-16.29,-7.2,-13.6
Ace Inhibitor,ACE or ARB,enalapril,3827,enalapril maleate 20 MG Oral Tablet ,-11.5,-16.29,-7.2,-13.6
Angiotensin Receptor Blocker,ACE or ARB,Losartan,979492,losartan potassium 50 MG Oral Tablet,-11.5,-16.29,-9.3,-11.7
Angiotensin Receptor Blocker,ACE or ARB,Azilsartan,1091646,azilsartan medoxomil 40 MG Oral Tablet,-11.5,-16.29,-9.3,-11.7
Angiotensin Receptor Blocker,ACE or ARB,Azilsartan/chlorthalidone,1235144,azilsartan medoxomil 40 MG / chlorthalidone 12.5 MG Oral Tablet,-11.5,-16.29,-9.3,-11.7
Angiotensin Receptor Blocker, ACE or ARB,Candesartan,153822,candesartan cilexetil 4 MG Oral Tablet,-11.5,-16.29,-9.3,-11.7
Calcium Channel Blockers,Calcium Channel Blockers,Diltiazem,830877,24 HR dilTIAZem hydrochloride 180 MG Extended Release Oral Tablet,-11.5,-16.29,-9.3,-11.7
Calcium Channel Blockers,Calcium Channel Blockers,Amlodipine,197361,amLODIPine 5 MG Oral Tablet,-11.5,-16.29,-9.3,-11.7
Calcium Channel Blockers,Calcium Channel Blockers,Amlodipine,308136,amLODIPine 2.5 MG Oral Tablet,-11.5,-16.29,-9.3,-11.7
Beta Blockers,Beta Blockers,Metoprolol Tartrate,866514,metoprolol tartrate 50 MG Oral Tablet,-11.5,-16.29,-8.7,-15.5
Beta Blockers,Beta Blockers,Metoprolol ER,866412,24 HR metoprolol succinate 100 MG Extended Release Oral Tablet,-11.5,-16.29,-8.7,-15.5
Beta Blockers,Beta Blockers,Atenolol,197381,atenolol 50 MG Oral Tablet,-11.5,-16.29,-8.7,-15.5
Beta Blockers,Beta Blockers,Atenolol/Chlorthalidone,197383,atenolol 50 MG / chlorthalidone 25 MG Oral Tablet,-11.5,-16.29,-8.7,-15.5
Beta Blockers,Beta Blockers,Labetalol,896758,labetalol hydrochloride 100 MG Oral Tablet ,-11.5,-16.29,-8.7,-15.5
Vasodilators,Vasodilators,Hydralazine,905395,hydrALAZINE hydrochloride 50 MG Oral Tablet,-11.5,-16.29,-9.3,-11.7
Vasodilators,Vasodilators,Minoxidil,197987,minoxidil 2.5 MG Oral Tablet,-11.5,-16.29,-9.3,-11.7
Alpha 2 Agonist,Alpha 2 Agonist,Guanfacine,197745,guanFACINE 1 MG Oral Tablet,-11.5,-16.29,-9.3,-11.7
Expand Down
Loading

0 comments on commit 86b2417

Please sign in to comment.