-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from niranjan93/calc_exp
KOs for Top 10 MDCalc formulas used by clinicians
- Loading branch information
Showing
24 changed files
with
888 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"@context": "https://kgrid.org/koio/2.0/context", | ||
"@id": "ascvd-2013", | ||
"koio:kgrid": "2", | ||
"@type": "koio:KnowledgeObject", | ||
"dc:title": "ASCVD (Atherosclerotic Cardiovascular Disease) 2013 Risk Calculator from AHA/ACC", | ||
"dc:identifier": "ark:ascvd", | ||
"version": "v1.0", | ||
"dc:description": "Estimates the patient's risk of developing their first myocardial infarction or stroke in the next 10 years", | ||
"koio:contributors": "Kgrid Team", | ||
"koio:keywords": [ | ||
"atherosclerotic cardiovascular disease", | ||
"coronary artery disease", | ||
"myocardial infarction", | ||
"stroke", | ||
"risk" | ||
], | ||
"koio:hasKnowledge": { | ||
"@id": "knowledge", | ||
"@type": [ | ||
"Knowledge", | ||
"Function" | ||
], | ||
"implementedBy": "https://raw.githubusercontent.com/kgrid-lab/LLM_with_RAG_chatbot/main/KO/clinical_calculators/code/ascvd_2013.py" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"@context": "https://kgrid.org/koio/2.0/context", | ||
"@id": "bmi", | ||
"koio:kgrid": "2", | ||
"@type": "koio:KnowledgeObject", | ||
"dc:title": "Body Mass Index", | ||
"dc:identifier": "ark:bmi", | ||
"version": "v1.0", | ||
"dc:description": "The Body Mass Index is computed using the patient's height in meters and weight in kilograms. It can be used to estimate whether a patient is underweight or overweight. 18.5 - 25 is the normal range.", | ||
"koio:contributors": "Kgrid Team", | ||
"koio:keywords": [ | ||
"body mass index", | ||
"body weight", | ||
"underweight", | ||
"overweight", | ||
"obesity" | ||
], | ||
"koio:hasKnowledge": { | ||
"@id": "knowledge", | ||
"@type": [ | ||
"Knowledge", | ||
"Function" | ||
], | ||
"implementedBy": "https://raw.githubusercontent.com/kgrid-lab/LLM_with_RAG_chatbot/main/KO/clinical_calculators/code/bmi.py" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"@context": "https://kgrid.org/koio/2.0/context", | ||
"@id": "bsa", | ||
"koio:kgrid": "2", | ||
"@type": "koio:KnowledgeObject", | ||
"dc:title": "Body Surface Area", | ||
"dc:identifier": "ark:bsa", | ||
"version": "v1.0", | ||
"dc:description": "Estimates the patient's body surface area in square meters using the Mosteller formula, given the patient's height in centimeters and weight in kilograms.", | ||
"koio:contributors": "Kgrid Team", | ||
"koio:keywords": [ | ||
"body surface area" | ||
], | ||
"koio:hasKnowledge": { | ||
"@id": "knowledge", | ||
"@type": [ | ||
"Knowledge", | ||
"Function" | ||
], | ||
"implementedBy": "https://raw.githubusercontent.com/kgrid-lab/LLM_with_RAG_chatbot/main/KO/clinical_calculators/code/bsa.py" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"@context": "https://kgrid.org/koio/2.0/context", | ||
"@id": "chadsvasc", | ||
"koio:kgrid": "2", | ||
"@type": "koio:KnowledgeObject", | ||
"dc:title": "CHA2DS2-VASc Score", | ||
"dc:identifier": "ark:chadsvasc", | ||
"version": "v1.0", | ||
"dc:description": "A score representing the risk of stroke in a patient with atrial fibrillation. 0 is low-risk in males. 0 or 1 is low-risk in females. All other scores are higher risk.", | ||
"koio:contributors": "Kgrid Team", | ||
"koio:keywords": [ | ||
"creatinine clearance", | ||
"renal function" | ||
], | ||
"koio:hasKnowledge": { | ||
"@id": "knowledge", | ||
"@type": [ | ||
"Knowledge", | ||
"Function" | ||
], | ||
"implementedBy": "https://raw.githubusercontent.com/kgrid-lab/LLM_with_RAG_chatbot/main/KO/clinical_calculators/code/chadsvasc.py" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"@context": "https://kgrid.org/koio/2.0/context", | ||
"@id": "ckd-epi-gfr-2021", | ||
"koio:kgrid": "2", | ||
"@type": "koio:KnowledgeObject", | ||
"dc:title": "2021 CKD-EPI equation for Glomerular Filtration Rate (GFR)", | ||
"dc:identifier": "ark:ckdepigfr", | ||
"version": "v1.0", | ||
"dc:description": "Steady-state estimate of glomerular filtration rate (GFR) using 2021 CKD-EPI equations using either creatinine alone or both creatinine and cystatin-C.", | ||
"koio:contributors": "Kgrid Team", | ||
"koio:keywords": [ | ||
"glomerular filtration rate", | ||
"renal function" | ||
], | ||
"koio:hasKnowledge": { | ||
"@id": "knowledge", | ||
"@type": [ | ||
"Knowledge", | ||
"Function" | ||
], | ||
"implementedBy": "https://raw.githubusercontent.com/kgrid-lab/LLM_with_RAG_chatbot/main/KO/clinical_calculators/code/ckd_epi_gfr_2021.py" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"@context": "https://kgrid.org/koio/2.0/context", | ||
"@id": "cockroft-gault-cr-cl", | ||
"koio:kgrid": "2", | ||
"@type": "koio:KnowledgeObject", | ||
"dc:title": "Cockroft-Gault Creatinine Clearance", | ||
"dc:identifier": "ark:cgcc", | ||
"version": "v1.0", | ||
"dc:description": "Estimates creatinine clearance in adults using the Cockfort-Gault model.", | ||
"koio:contributors": "Kgrid Team", | ||
"koio:keywords": [ | ||
"creatinine clearance", | ||
"renal function" | ||
], | ||
"koio:hasKnowledge": { | ||
"@id": "knowledge", | ||
"@type": [ | ||
"Knowledge", | ||
"Function" | ||
], | ||
"implementedBy": "https://raw.githubusercontent.com/kgrid-lab/LLM_with_RAG_chatbot/main/KO/clinical_calculators/code/cockroft_gault_cr_cl.py" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
from math import e | ||
from math import log | ||
|
||
def ascvd_2013(age: int, dm: bool, sex: str, smoker: bool, total_cholesterol: int, hdl: int, sbp: int, htn_tx: bool, race: str) -> float: | ||
""" | ||
Parameters: | ||
- age: The patient's age in years. This calculation is only valid for ages 40-75. | ||
- dm: True if the patient has diabetes. False otherwise. | ||
- sex: The patient's sex, either male or female. | ||
- smoker: True if the patient smokes. | ||
- total_cholesterol: The patient's total serum cholesterol in miligrams per deciliter. | ||
- hdl: The patient's serum high-density lipoprotein cholesterol in miligrams per decileter. | ||
- sbp: The patient's systolic blood pressure in mm Hg. | ||
- htn_tx: True if the patient is being treated for hypertension. False otherwise. | ||
- race: The patient's race, either white or african american. | ||
Returns: The patient's risk of developing their first myocardial infarction or stroke in the next 10 years. | ||
""" | ||
coefficients = {} | ||
values = {} | ||
|
||
if race == "african american": | ||
if sex == "female": | ||
coefficients["ln_age"] = 17.114 | ||
coefficients["ln_age_sq"] = 0 | ||
coefficients["ln_tot_col"] = 0.940 | ||
coefficients["ln_age_ln_tot_col"] = 0 | ||
coefficients["ln_hdlc"] = -18.920 | ||
coefficients["ln_age_ln_hdlc"] = 4.475 | ||
coefficients["ln_tx_sbp"] = 29.291 | ||
coefficients["ln_age_ln_tx_sbp"] = -6.432 | ||
coefficients["ln_utx_sbp"] = 27.820 | ||
coefficients["ln_age_ln_utx_sbp"] = -6.087 | ||
coefficients["smoker"] = 0.691 | ||
coefficients["ln_age_smoker"] = 0 | ||
coefficients["diabetes"] = 0.874 | ||
baseline_survival = 0.9533 | ||
mean_score = 86.61 | ||
else: | ||
coefficients["ln_age"] = 2.469 | ||
coefficients["ln_age_sq"] = 0 | ||
coefficients["ln_tot_col"] = 0.302 | ||
coefficients["ln_age_ln_tot_col"] = 0 | ||
coefficients["ln_hdlc"] = -0.307 | ||
coefficients["ln_age_ln_hdlc"] = 0 | ||
coefficients["ln_tx_sbp"] = 1.916 | ||
coefficients["ln_age_ln_tx_sbp"] = 0 | ||
coefficients["ln_utx_sbp"] = 1.809 | ||
coefficients["ln_age_ln_utx_sbp"] = 0 | ||
coefficients["smoker"] = 0.549 | ||
coefficients["ln_age_smoker"] = 0 | ||
coefficients["diabetes"] = 0.645 | ||
baseline_survival = 0.8954 | ||
mean_score = 19.54 | ||
else: | ||
if sex == "female": | ||
coefficients["ln_age"] = -29.799 | ||
coefficients["ln_age_sq"] = 4.884 | ||
coefficients["ln_tot_col"] = 13.540 | ||
coefficients["ln_age_ln_tot_col"] = -3.114 | ||
coefficients["ln_hdlc"] = -13.578 | ||
coefficients["ln_age_ln_hdlc"] = 3.149 | ||
coefficients["ln_tx_sbp"] = 2.019 | ||
coefficients["ln_age_ln_tx_sbp"] = 0 | ||
coefficients["ln_utx_sbp"] = 1.957 | ||
coefficients["ln_age_ln_utx_sbp"] = 0 | ||
coefficients["smoker"] = 7.574 | ||
coefficients["ln_age_smoker"] = -1.665 | ||
coefficients["diabetes"] = 0.661 | ||
baseline_survival = 0.9665 | ||
mean_score = -29.18 | ||
else: | ||
coefficients["ln_age"] = 12.344 | ||
coefficients["ln_age_sq"] = 0 | ||
coefficients["ln_tot_col"] = 11.853 | ||
coefficients["ln_age_ln_tot_col"] = -2.664 | ||
coefficients["ln_hdlc"] = -7.990 | ||
coefficients["ln_age_ln_hdlc"] = 1.769 | ||
coefficients["ln_tx_sbp"] = 1.797 | ||
coefficients["ln_age_ln_tx_sbp"] = 0 | ||
coefficients["ln_utx_sbp"] = 1.764 | ||
coefficients["ln_age_ln_utx_sbp"] = 0 | ||
coefficients["smoker"] = 7.837 | ||
coefficients["ln_age_smoker"] = -1.795 | ||
coefficients["diabetes"] = 0.658 | ||
baseline_survival = 0.9144 | ||
mean_score = 61.18 | ||
|
||
if htn_tx: | ||
coefficients["ln_utx_sbp"] = 0 | ||
coefficients["ln_age_ln_utx_sbp"] = 0 | ||
else: | ||
coefficients["ln_tx_sbp"] = 0 | ||
coefficients["ln_age_ln_tx_sbp"] = 0 | ||
|
||
values["ln_age"] = log(age) | ||
values["ln_age_sq"] = pow(values["ln_age"], 2) | ||
values["ln_tot_col"] = log(total_cholesterol) | ||
values["ln_age_ln_tot_col"] = values["ln_age"] * values["ln_tot_col"] | ||
values["ln_hdlc"] = log(hdl) | ||
values["ln_age_ln_hdlc"] = values["ln_age"] * values["ln_hdlc"] | ||
values["ln_tx_sbp"] = log(sbp) | ||
values["ln_age_ln_tx_sbp"] = values["ln_age"] * values["ln_tx_sbp"] | ||
values["ln_utx_sbp"] = log(sbp) | ||
values["ln_age_ln_utx_sbp"] = values["ln_age"] * values["ln_utx_sbp"] | ||
|
||
if smoker: | ||
values["smoker"] = 1 | ||
else: | ||
values["smoker"] = 0 | ||
|
||
values["ln_age_smoker"] = values["ln_age"] * values["smoker"] | ||
|
||
if dm: | ||
values["diabetes"] = 1 | ||
else: | ||
values["diabetes"] = 0 | ||
|
||
score = sum((coefficients[term] * values[term] for term in coefficients.keys())) | ||
|
||
return 1 - pow(baseline_survival, pow(e, score - mean_score)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
def bmi(height: float, weight: float) -> float: | ||
""" | ||
Paramters: | ||
- height: The patient's height in meters. | ||
- weight: The patient's weight in kilograms. | ||
Returns: The Body Mass Index | ||
""" | ||
return weight / pow(height, 2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
def bsa(height: float, weight: float) -> float: | ||
""" | ||
Paramters: | ||
- height: The patient's height in centimeters. | ||
- weight: The patient's weight in kilograms. | ||
Returns: The patient's body surface area in square meters. | ||
""" | ||
return pow(weight * height, 0.5) / 60 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
def chadsvasc(age: int, sex: str, chf: bool, htn: bool, stroke: bool, vasc: bool, dm: bool) -> int: | ||
""" | ||
Parameters: | ||
- age: The patient's age in years. | ||
- sex: The patient's sex, male or female. | ||
- chf: True if the patient has a history of heart failure. False otherwise. | ||
- htn: True if the patient has a history of hypertension. False otherwise. | ||
- stroke: True if the patient has a history of stroke, TIA, or thromboembolism. False otherwise. | ||
- vasc: True if the patient has a history of vascular disease, including prior myocardial infarction, peripheral arterial disease, or aortic plaque. False otherwise. | ||
- dm: True if the patient has a history of diabetes. False otherwise. | ||
Returns: A score representing the risk of stroke in a patient with atrial fibrillation. 0 is low-risk in males. 0 or 1 is low-risk in females. All other scores are higher risk. | ||
""" | ||
score = 0 | ||
|
||
if age >= 65: | ||
if age >= 75: | ||
score += 2 | ||
else: | ||
score += 1 | ||
|
||
if sex == "female": | ||
score += 1 | ||
|
||
if htn: | ||
score += 1 | ||
|
||
if stroke: | ||
score += 2 | ||
|
||
if vasc: | ||
score += 1 | ||
|
||
if dm: | ||
score +=1 | ||
|
||
return score |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
def ckd_epi_gfr_2021(sex: str, age: int, creatinine: float, cystatinc=None) -> float: | ||
""" | ||
Parameters: | ||
- sex (str): Sex of the patient, male or female. | ||
- age (int): Age of the patient in years. | ||
- creatinine (float): Serum creatinine concentration for the patient, in milligrams per deciliter. | ||
- cystatinc (float): [optional] Serum cystatin-c concentration for the patient, in milligrams per liter. | ||
""" | ||
if cystatinc is None: | ||
if sex == "female": | ||
mult = 1.012 | ||
k = 0.7 | ||
alpha = -0.241 | ||
else: | ||
mult = 1 | ||
k = 0.9 | ||
alpha = -0.302 | ||
|
||
return 142 * pow(min(creatinine / k, 1), alpha) * pow(max(creatinine / k, 1), -1.2) * pow(0.9938, age) * mult | ||
else: | ||
if sex == "female": | ||
mult = 0.963 | ||
k = 0.7 | ||
alpha = -0.219 | ||
else: | ||
mult = 1 | ||
k = 0.9 | ||
alpha = -0.144 | ||
|
||
return 135 * pow(min(creatinine / k, 1), alpha) * pow(max(creatinine / k, 1), -0.544) * pow(min(cystatinc / 0.8, 1), -0.323) * pow(max(cystatinc / 0.8, 1), -0.778) * pow(0.9961, age) * mult |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
def cockroft_gault_cr_cl(sex: str, age: int, weight: float, creatinine: float) -> float: | ||
""" | ||
Parameters: | ||
- sex (str): Sex of the patient, male or female. | ||
- age (int): Age of the patient in years. | ||
- weight (float): Weight of the patient in kilograms. | ||
- creatinine (float): Serum creatinine concentration for the patient, in milligrams per deciliter. | ||
""" | ||
if sex == "female": | ||
mult = 0.85 | ||
else: | ||
mult = 1 | ||
|
||
return (((140 - age) * weight) / (72 * creatinine)) * mult |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
def corr_ca_alb(ca: float, albumin: float, nl_alb=4.0) -> float: | ||
""" | ||
Parameters: | ||
- ca: The patient's serum calcium level in miligrams per deciliter. | ||
- albumin: The patient's serum albumin level in grams per deciliter. | ||
- nl_alb: The normal serum albumin level. Optional. The default is 4 mg/dL. | ||
Returns: The patient's effective serum calcium level, corrected for their albumin level. | ||
""" | ||
return ca + ((nl_alb - albumin) * 0.8) |
Oops, something went wrong.