我正在编写诊所的医疗应用程序,我想为心血管疾病,MI(心肌梗塞),中风,CHD_Death,CVD_Death,BNF和ASSIGN(心血管疾病)制作一个页面。
Doctor提供的等式是Framingham Equation:
var framingham = 100*(1-Math.exp(-Math.exp((Math.log(time_period)-(18.8144+(-1.2146*(1-genderVal))+(-1.8443*Math.log(age))+(0*Math.log(age)*Math.log(age))+(0.3668*Math.log(age)*(1-genderVal))
+(0*Math.log(age)*Math.log(age)*(1-genderVal))+(-1.4032*Math.log(systolic))+(-0.3899*smokerVal)+(-0.539*Math.log(total_chol/hdl_chol))
+(-0.3036*diabetes)+(-0.1697*diabetesVal*(1-genderVal))+(-0.3362*lvhVal)+(0*lvhVal*genderVal)))/(Math.exp(0.6536)
*Math.exp(-0.2402*(18.8144+(-1.2146*(1-genderVal))+(-1.8443*Math.log(age))
+(0*Math.log(age)*Math.log(age))+(0.3668*smokerVal)+(-0.539*Math.log(total_chol/hdl_chol))
+(-0.3036*diabetesVal)+(-0.1697*diabetesVal*(1-genderVal))
+(-0.3362*lvhVal)+(0*lvhVal*genderVal)))))));
console.log(framingham);
首先,函数内部有一些部分乘以0,这将使它无效。我测试了它,在控制台上我得到了结果:NaN或非数字。
我测试了变量,计算机正在正确读取它们。
以下是完整的脚本:
$("#calculate_add").on('click', function()
{
var genderVal = 0;
var smokerVal = 0;
var diabetesVal = 0;
var lvhVal = 0;
var time_period = $("#time_period").val();
var gender = $("#gender").val();
var age = $("#age").val();
var smoker = $("#smoker").val();
var systolic = $("#sbp").val();
var total_chol = $("#total_chol").val();
var hdl_chol = $("#hdl_chol").val();
var diabetes = $("#diabetes").val();
var lvh = $("#lvh").val();
if(time_period == "" || time_period<4 || time_period>12)
{
$("#time_period").css('border-color', 'red');
$("#time_period").focus();
}
else if(systolic == "" || systolic == 0)
{
$("#sbp").css('border-color', 'red');
$("#sbp").focus();
}
else if(total_chol == "" || total_chol == 0)
{
$("#total_chol").css('border-color', 'red');
$("#total_chol").focus();
}
else if(hdl_chol == "" || hdl_chol == 0)
{
$("#hdl_chol").css('border-color', 'red');
$("#hdl_chol").focus();
}
else if(diabetes == "select")
{
$("#diabetes").css('border-color', 'red');
$("#diabetes").focus();
}
else if(lvh == "select")
{
$("#lvh").css('border-color', 'red');
$("#lvh").focus();
}
else
{
$("#time_period").css('border-color', '#0090ff');
$("#sbp").css('border-color', '#0090ff');
$("#total_chol").css('border-color', '#0090ff');
$("#hdl_chol").css('border-color', '#0090ff');
$("#diabetes").css('border-color', '#0090ff');
$("#lvh").css('border-color', '#0090ff');
if(gender == "Male")
{
genderVal = 1;
}
else
{
genderVal = 0;
}
if(smoker == "Yes")
{
smokerVal = 1;
}
else
{
smokerVal = 0;
}
if(diabetes == "yes")
{
diabetesVal = 1;
}
else
{
diabetesVal = 0;
}
if(lvh == "yes")
{
lvhVal = 1;
}
else
{
lvhVal = 0;
}
console.log(genderVal);
console.log(diabetesVal);
console.log(lvhVal);
//Formula Calculation
var framingham = 100*(1-Math.exp(-Math.exp((Math.log(time_period)-(18.8144+(-1.2146*(1-genderVal))+(-1.8443*Math.log(age))+(0*Math.log(age)*Math.log(age))+(0.3668*Math.log(age)*(1-genderVal))
+(0*Math.log(age)*Math.log(age)*(1-genderVal))+(-1.4032*Math.log(systolic))+(-0.3899*smokerVal)+(-0.539*Math.log(total_chol/hdl_chol))
+(-0.3036*diabetes)+(-0.1697*diabetesVal*(1-genderVal))+(-0.3362*lvhVal)+(0*lvhVal*genderVal)))/(Math.exp(0.6536)
*Math.exp(-0.2402*(18.8144+(-1.2146*(1-genderVal))+(-1.8443*Math.log(age))
+(0*Math.log(age)*Math.log(age))+(0.3668*smokerVal)+(-0.539*Math.log(total_chol/hdl_chol))
+(-0.3036*diabetesVal)+(-0.1697*diabetesVal*(1-genderVal))
+(-0.3362*lvhVal)+(0*lvhVal*genderVal)))))));
console.log(framingham);
}
});
由于种种原因我无法与医生沟通,也无法在线找到真正的方程式。
修改
我将功能分开:
var var1 = (18.8144+(-1.2146*(1-genderVal))+(-1.8443*Math.log(age))
+(0*Math.log(age)*Math.log(age))+(0.3668*smokerVal)+(-0.539*Math.log(total_chol/hdl_chol))
+(-0.3036*diabetesVal)+(-0.1697*diabetesVal*(1-genderVal))
+(-0.3362*lvhVal)+(0*lvhVal*genderVal));
var var2 = (Math.exp(0.6536)
*Math.exp(-0.2402*var1));
var var3 = (Math.log(time_period)-(18.8144+(-1.2146*(1-genderVal))+(-1.8443*Math.log(age))+(0*Math.log(age)*Math.log(age))+(0.3668*Math.log(age)*(1-genderVal))
+(0*Math.log(age)*Math.log(age)*(1-genderVal))+(-1.4032*Math.log(systolic))+(-0.3899*smokerVal)+(-0.539*Math.log(total_chol/hdl_chol))
+(-0.3036*diabetes)+(-0.1697*diabetesVal*(1-genderVal))+(-0.3362*lvhVal)+(0*lvhVal*genderVal)))/var2
var framingham = 100*(1-Math.exp(-Math.exp(var3)));
console.log(var1);
console.log(var2);
console.log(var3);
console.log(framingham);
var3
和弗雷明汉给了我NaN,其他人给了我十进制数字。