Guest User

Untitled

a guest
Oct 17th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. // set up our units of conversions, could be shared between multiple calculators
  2. var units = {
  3. "age": {"yr": 1, "mth": 12.0},
  4. "weight": {"kg": 1, "lb": 2.20462},
  5. "creatinine": {"gm/L": 0.01, "gm/dL": 0.001, "mg%": 1, "mg/dL": 1, "mg/mL": 0.01},
  6. "output": {"mL/min": 1, "L/hr": 0.06}
  7. };
  8.  
  9. // get the inputs specific to this calculator (irl, this would come from the form fields)
  10. var inputs = {
  11. "sex": {"value": "male"},
  12. "age": {"value": 30, "unit": "yr"},
  13. "weight": {"value": 150, "unit": "lb"},
  14. "creatinine": {"value": 0.008, "unit": "gm/L"}
  15. };
  16.  
  17. // standardize all the inputs in the units of our equation
  18. var standardized = {};
  19. for (var key in inputs) {
  20. if ("unit" in inputs[key] || !inputs[key]["unit"]) {
  21. standardized[key] = inputs[key]["value"] / units[key][inputs[key]["unit"]];
  22. } else{
  23. standardized[key] = inputs[key]["value"]; // ignore those unit less inputs
  24. }
  25. }
  26.  
  27. standardized["output"] = (standardized["sex"] == "male" ? 1.0 : 0.85) * (140 - standardized["age"]) * standardized["weight"] / (72 * standardized["creatinine"]);
  28. output = standardized["output"] * units["output"]["mL/min"]; // desired output unit
Add Comment
Please, Sign In to add comment