示例#1
1
function LBFvbf_javascript()
{
    global $formid;
    echo "// Compute Body Mass Index.\nfunction vbfComputeBMI() {\n var f = document.forms[0];\n var bmi = 0;\n var stat = '';\n var height = parseFloat(f.form_height_in.value);\n var weight = parseFloat(f.form_weight_lbs.value);\n if(isNaN(height) || isNaN(weight) || height <= 0 || weight <= 0) {\n  bmi = '';\n }\n else {\n  bmi = weight / height / height * 703;\n  bmi = bmi.toFixed(1);\n  if      (bmi > 42  ) stat = '" . xl('Obesity III') . "';\n  else if (bmi > 34  ) stat = '" . xl('Obesity II') . "';\n  else if (bmi > 30  ) stat = '" . xl('Obesity I') . "';\n  else if (bmi > 27  ) stat = '" . xl('Overweight') . "';\n  else if (bmi > 18.5) stat = '" . xl('Normal') . "';\n  else                 stat = '" . xl('Underweight') . "';\n }\n if (f.form_bmi) f.form_bmi.value = bmi;\n if (f.form_bmi_status) f.form_bmi_status.value = stat;\n}\n";
    echo "// Height in cm has changed.\nfunction vbf_height_cm_changed() {\n var f = document.forms[0];\n var cm = f.form_height_cm.value;\n if (cm == parseFloat(cm)) {\n  inch = cm / 2.54;\n  f.form_height_in.value = inch.toFixed(2);\n }\n else {\n  f.form_height_in.value = '';\n }\n vbfComputeBMI();\n}\n";
    echo "// Height in inches has changed.\nfunction vbf_height_in_changed() {\n var f = document.forms[0];\n var inch = f.form_height_in.value;\n if (inch == parseFloat(inch)) {\n  cm = inch * 2.54;\n  f.form_height_cm.value = cm.toFixed(2);\n }\n else {\n  f.form_height_cm.value = '';\n }\n vbfComputeBMI();\n}\n";
    echo "// Weight in kg has changed.\nfunction vbf_weight_kg_changed() {\n var f = document.forms[0];\n var kg = f.form_weight_kg.value;\n if (kg == parseFloat(kg)) {\n  lbs = kg / 0.45359237;\n  f.form_weight_lbs.value = lbs.toFixed(2);\n }\n else {\n  f.form_weight_lbs.value = '';\n }\n vbfComputeBMI();\n}\n";
    echo "// Weight in lbs has changed.\nfunction vbf_weight_lbs_changed() {\n var f = document.forms[0];\n var lbs = f.form_weight_lbs.value;\n if (lbs == parseFloat(lbs)) {\n  kg = lbs * 0.45359237;\n  f.form_weight_kg.value = kg.toFixed(2);\n }\n else {\n  f.form_weight_kg.value = '';\n }\n vbfComputeBMI();\n}\n";
    echo "// Temperature in centigrade has changed.\nfunction vbf_temperature_c_changed() {\n var f = document.forms[0];\n var tc = f.form_temperature_c.value;\n if (tc == parseFloat(tc)) {\n  tf = tc * 9 / 5 + 32;\n  f.form_temperature_f.value = tf.toFixed(2);\n }\n else {\n  f.form_temperature_f.value = '';\n }\n}\n";
    echo "// Temperature in farenheit has changed.\nfunction vbf_temperature_f_changed() {\n var f = document.forms[0];\n var tf = f.form_temperature_f.value;\n if (tf == parseFloat(tf)) {\n  tc = (tf - 32) * 5 / 9;\n  f.form_temperature_c.value = tc.toFixed(2);\n }\n else {\n  f.form_temperature_c.value = '';\n }\n}\n";
    // Compute patient age and sex.
    $ptrow = sqlQuery("SELECT DOB, sex FROM patient_data WHERE " . "pid = '{$pid}' LIMIT 1");
    $pt_age = 0 + getpatientAge($ptrow['DOB']);
    $pt_sex = strtoupper(substr($ptrow['sex'], 0, 1)) == 'F' ? 1 : 0;
    echo "// Compute Body Fat Percentage.\nfunction vbfComputeBF() {\n var f = document.forms[0];\n var age = {$pt_age}; // Patient age in years\n var sex = {$pt_sex}; // 0 = Male, 1 = Female\n if (!f.form_sf_sum || !f.form_body_fat) return;\n var sfsum = f.form_sf_sum.value;\n if (sfsum != parseFloat(sfsum) || sfsum <= 0) {\n  f.form_body_fat.value = '';\n  return;\n }\n var d = 0;\n var sflog = Math.LOG10E * Math.log(sfsum);\n if (sex == 0) {\n  if      (age < 17) d = 1.1533 - 0.0643 * sflog;\n  else if (age < 20) d = 1.1620 - 0.0630 * sflog;\n  else if (age < 30) d = 1.1631 - 0.0632 * sflog;\n  else if (age < 40) d = 1.1422 - 0.0544 * sflog;\n  else if (age < 50) d = 1.1620 - 0.0700 * sflog;\n  else               d = 1.1715 - 0.0779 * sflog;\n }\n else {\n  if      (age < 17) d = 1.1369 - 0.0598 * sflog;\n  else if (age < 20) d = 1.1549 - 0.0678 * sflog;\n  else if (age < 30) d = 1.1599 - 0.0717 * sflog;\n  else if (age < 40) d = 1.1423 - 0.0632 * sflog;\n  else if (age < 50) d = 1.1333 - 0.0612 * sflog;\n  else               d = 1.1339 - 0.0645 * sflog;\n }\n var bf = 495 / d - 450;\n f.form_body_fat.value = bf.toFixed(2);\n}\n";
    echo "// Tally skin fold measurements.\nfunction vbfSFChanged() {\n var f = document.forms[0];\n var sum = 0;\n for (var i = 0; i < f.elements.length; ++i) {\n  var e = f.elements[i];\n  if (e.name.substring(0,8) == 'form_sf_' && e.name != 'form_sf_sum') {\n   if (e.value == parseFloat(e.value)) sum += parseFloat(e.value);\n  }\n }\n f.form_sf_sum.value = sum.toFixed(2);\n vbfComputeBF();\n}\n";
}
示例#2
0
function LBFathbf_javascript()
{
    global $formid;
    // Compute patient age and sex.
    $ptrow = sqlQuery("SELECT DOB, sex FROM patient_data WHERE " . "pid = '{$pid}' LIMIT 1");
    $pt_age = 0 + getpatientAge($ptrow['DOB']);
    $pt_sex = strtoupper(substr($ptrow['sex'], 0, 1)) == 'F' ? 1 : 0;
    echo "// Compute Body Fat Percentage.\nfunction athbfComputeBF() {\n var f = document.forms[0];\n var age = {$pt_age}; // Patient age in years\n var sex = {$pt_sex}; // 0 = Male, 1 = Female\n if (!f.form_sf_sum || !f.form_body_fat) return;\n var sfsum = f.form_sf_sum.value;\n if (sfsum != parseFloat(sfsum) || sfsum <= 0) {\n  f.form_body_fat.value = '';\n  return;\n }\n var d = 0;\n var sflog = Math.LOG10E * Math.log(sfsum);\n if (sex == 0) {\n  if      (age < 17) d = 1.1533 - 0.0643 * sflog;\n  else if (age < 20) d = 1.1620 - 0.0630 * sflog;\n  else if (age < 30) d = 1.1631 - 0.0632 * sflog;\n  else if (age < 40) d = 1.1422 - 0.0544 * sflog;\n  else if (age < 50) d = 1.1620 - 0.0700 * sflog;\n  else               d = 1.1715 - 0.0779 * sflog;\n }\n else {\n  if      (age < 17) d = 1.1369 - 0.0598 * sflog;\n  else if (age < 20) d = 1.1549 - 0.0678 * sflog;\n  else if (age < 30) d = 1.1599 - 0.0717 * sflog;\n  else if (age < 40) d = 1.1423 - 0.0632 * sflog;\n  else if (age < 50) d = 1.1333 - 0.0612 * sflog;\n  else               d = 1.1339 - 0.0645 * sflog;\n }\n var bf = 495 / d - 450;\n f.form_body_fat.value = bf.toFixed(2);\n}\n";
    echo "// Tally skin fold measurements.\nfunction athbfSFChanged() {\n var f = document.forms[0];\n var sum = 0;\n for (var i = 0; i < f.elements.length; ++i) {\n  var e = f.elements[i];\n  if (e.name.substring(0,8) == 'form_sf_' && e.name != 'form_sf_sum') {\n   if (e.value == parseFloat(e.value)) sum += parseFloat(e.value);\n  }\n }\n f.form_sf_sum.value = sum.toFixed(2);\n athbfComputeBF();\n}\n";
}