Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@skylander86
Created October 17, 2017 02:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skylander86/a2c17a630428d37913ba0f3940c87146 to your computer and use it in GitHub Desktop.
Save skylander86/a2c17a630428d37913ba0f3940c87146 to your computer and use it in GitHub Desktop.
Creatinine Clearance Calculator Javascript Logic
// set up our units of conversions, could be shared between multiple calculators
var units = {
"age": {"yr": 1, "mth": 12.0},
"weight": {"kg": 1, "lb": 2.20462},
"creatinine": {"gm/L": 0.01, "gm/dL": 0.001, "mg%": 1, "mg/dL": 1, "mg/mL": 0.01},
"output": {"mL/min": 1, "L/hr": 0.06}
};
// get the inputs specific to this calculator (irl, this would come from the form fields)
var inputs = {
"sex": {"value": "male"},
"age": {"value": 30, "unit": "yr"},
"weight": {"value": 150, "unit": "lb"},
"creatinine": {"value": 0.008, "unit": "gm/L"}
};
// standardize all the inputs in the units of our equation
var standardized = {};
for (var key in inputs) {
if ("unit" in inputs[key] || !inputs[key]["unit"]) {
standardized[key] = inputs[key]["value"] / units[key][inputs[key]["unit"]];
} else{
standardized[key] = inputs[key]["value"]; // ignore those unit less inputs
}
}
standardized["output"] = (standardized["sex"] == "male" ? 1.0 : 0.85) * (140 - standardized["age"]) * standardized["weight"] / (72 * standardized["creatinine"]);
output = standardized["output"] * units["output"]["mL/min"]; // desired output unit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment