function calculateGFR() {
var serumCreatinine = parseFloat(document.getElementById("serumCreatinine").value);
var age = parseInt(document.getElementById("age").value);
var gender = document.getElementById("gender").value;
var race = document.getElementById("race").value;
var isValid = true;
if (isNaN(serumCreatinine) || serumCreatinine <= 0) {
isValid = false;
alert("Please enter a valid Serum Creatinine value (greater than 0).");
}
if (isNaN(age) || age <= 0) {
isValid = false;
alert("Please enter a valid Age (greater than 0).");
}
if (!isValid) {
return;
}
var a = -0.241;
var b = -1.207; // for females
var c = -0.752; // for Black individuals
var d = -0.176; // for Black females
var raceFactor = 1.0;
if (race === "black") {
raceFactor = 1.159; // CKD-EPI 2021 uses a different factor for Black individuals
}
var genderFactor = 1.0;
if (gender === "female") {
genderFactor = 0.735;
} else if (gender === "nonbinary") {
genderFactor = 0.735; // Often uses female equation as a proxy if no specific data
}
// CKD-EPI 2021 creatinine equation
// Source: https://www.nejm.org/doi/full/10.1056/NEJMoa2026979
var eGFR;
var serumCreatinine_mg_dL = serumCreatinine;
if (age = 18 && age = 40 && age = 50 && age = 65
k = 0.475;
}
var scr_adj = serumCreatinine_mg_dL / k;
var factor = 1.0; // Default for male/white/asian/other
if (gender === "female" || gender === "nonbinary") {
factor *= Math.pow(0.735, genderFactor); // Use 0.735 for females/nonbinary
if (race === "black") {
factor *= 1.159; // CKD-EPI 2021 does NOT have separate race factors for females
}
} else { // Male
if (race === "black") {
factor *= 1.159;
}
}
// The CKD-EPI 2021 equation simplifies the gender and race adjustments within the formula structure.
// The formula used here is a more direct representation of the 2021 update,
// which removed the explicit "Black" adjustment for males and integrated it differently.
// For clarity and based on common implementations of CKD-EPI 2021, the following is used.
var numerator;
if (gender === "male" || gender === "nonbinary") { // Nonbinary treated as male for this simplified formula part
if (race === "black") {
numerator = 1463;
genderFactor = 1.0; // Black male has no specific gender factor applied here
} else {
numerator = 1412;
genderFactor = 1.0;
}
} else { // Female
numerator = 1441;
genderFactor = 0.735;
}
eGFR = numerator * Math.pow(scr_adj, genderFactor) * Math.pow(age, b); // b = -1.207 for all
// CKD-EPI 2021 revision applied race adjustment more broadly:
// For Black individuals, the value is multiplied by 1.159
if (race === "black" && (gender === "male" || gender === "nonbinary")) {
eGFR *= 1.159;
}
// The 2021 equation is:
// eGFR = 1412 * (Scr/0.9)^(-1.207) * (0.735 if Female)^(-1.207) * (1.159 if Black)^(-1.207) * Age^(-0.321)
// Simplified and re-arranged for calculation
var sexMultiplier;
if (gender === "male" || gender === "nonbinary") {
sexMultiplier = 1.0;
} else { // Female
sexMultiplier = 0.735;
}
var raceMultiplier = 1.0;
if (race === "black") {
raceMultiplier = 1.159;
}
var final_eGFR = 1463 * Math.pow(serumCreatinine_mg_dL / k, -1.207) * Math.pow(sexMultiplier, -1.207) * Math.pow(raceMultiplier, -1.207) * Math.pow(age, -0.321);
// The 2021 CKD-EPI equation has a different structure than previous versions.
// The values for the exponents and the constants differ.
// The 2021 equation is:
// eGFR = 1463 * (Scr/k)^(-1.207) * (0.735 if Female)^( -1.207 ) * (1.159 if Black)^( -1.207 ) * Age^(-0.321)
// However, the common interpretation and implementation in many systems often leads to the following simplified calculation for adults:
// If Male or Non-binary, Race White/Asian/Other: eGFR = 1412 * (Scr/k)^(-1.207) * Age^(-0.321)
// If Female or Non-binary, Race White/Asian/Other: eGFR = 1441 * (Scr/k)^(-1.207) * Age^(-0.321) * 0.735
// If Male or Non-binary, Race Black: eGFR = 1412 * (Scr/k)^(-1.207) * Age^(-0.321) * 1.159
// If Female or Non-binary, Race Black: eGFR = 1441 * (Scr/k)^(-1.207) * Age^(-0.321) * 0.735 * 1.159
var calculated_eGFR;
if (gender === "male" || gender === "nonbinary") {
if (race === "black") {
calculated_eGFR = 1412 * Math.pow(serumCreatinine_mg_dL / k, -1.207) * Math.pow(age, -0.321) * 1.159;
} else { // White, Asian, Other
calculated_eGFR = 1412 * Math.pow(serumCreatinine_mg_dL / k, -1.207) * Math.pow(age, -0.321);
}
} else { // Female
if (race === "black") {
calculated_eGFR = 1441 * Math.pow(serumCreatinine_mg_dL / k, -1.207) * Math.pow(age, -0.321) * 0.735 * 1.159;
} else { // White, Asian, Other
calculated_eGFR = 1441 * Math.pow(serumCreatinine_mg_dL / k, -1.207) * Math.pow(age, -0.321) * 0.735;
}
}
var finalGFR = Math.round(calculated_eGFR);
var interpretationText = "";
if (finalGFR = 15 && finalGFR = 30 && finalGFR = 60 && finalGFR = 90
interpretationText = "Stage 1 CKD (Normal Kidney Function).";
}
document.getElementById("gfrValue").textContent = finalGFR + " mL/min/1.73m²";
document.getElementById("interpretation").textContent = interpretationText;
}
.calculator-wrapper {
font-family: Arial, sans-serif;
max-width: 600px;
margin: 20px auto;
padding: 20px;
border: 1px solid #ddd;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}
.calculator-inputs h2, .calculator-result h3 {
text-align: center;
color: #333;
margin-bottom: 15px;
}
.calculator-inputs p {
color: #555;
line-height: 1.6;
margin-bottom: 20px;
}
.input-group {
margin-bottom: 15px;
}
.input-group label {
display: block;
margin-bottom: 5px;
font-weight: bold;
color: #444;
}
.input-group input[type="number"],
.input-group select {
width: calc(100% – 22px);
padding: 10px;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
font-size: 1rem;
}
.input-group select {
cursor: pointer;
}
.calculator-wrapper button {
display: block;
width: 100%;
padding: 12px;
background-color: #007bff;
color: white;
border: none;
border-radius: 4px;
font-size: 1.1rem;
cursor: pointer;
transition: background-color 0.3s ease;
}
.calculator-wrapper button:hover {
background-color: #0056b3;
}
.calculator-result {
margin-top: 25px;
padding: 15px;
background-color: #f8f9fa;
border: 1px solid #e0e0e0;
border-radius: 4px;
text-align: center;
}
#gfrValue {
font-size: 1.8rem;
font-weight: bold;
color: #28a745;
margin-bottom: 10px;
}
#interpretation {
font-size: 1.1rem;
color: #6c757d;
}