public override double calculateResult(HPN_TESTRESULT testResult, List <HPN_TESTRESULTDETAILS> testDetails) { double height = testDetails.Find(p => p.TEMPLATEITEMNAME == "height").ITEMRESULT.ToDouble(0) / 100; double weight = testDetails.Find(p => p.TEMPLATEITEMNAME == "weight").ITEMRESULT.ToDouble(0); double loseweight = testDetails.Find(p => p.TEMPLATEITEMNAME == "loseweight").ITEMRESULT.ToDouble(0); double disease = testDetails.Find(p => p.TEMPLATEITEMNAME == "disease").ITEMRESULT.ToDouble(0); string testNo = testDetails.First().TESTNO; double bmi = weight / height / height; double weightlosepersent = loseweight / (weight + loseweight); double score = 0; if (bmi < 18.5) { score += 2; } else if (bmi < 20) { score += 1; } if (weightlosepersent >= 0.05 && weightlosepersent <= 0.1) { score += 1; } else if (weightlosepersent > 0.1) { score += 2; } score += disease; testResult.RESULTDETAIL = string.Format("测试结果为:{0}分", score); return(score); }
public override double calculateResult(HPN_TESTRESULT testResult, List <HPN_TESTRESULTDETAILS> testDetails) { double weight = testDetails.Find(p => p.TEMPLATEITEMNAME == "weight").ITEMRESULT.ToDouble(0); double height = testDetails.Find(p => p.TEMPLATEITEMNAME == "height").ITEMRESULT.ToDouble(0) / 100; string testNo = testDetails.First().TESTNO; double bmi = weight / height / height; double score = 0; if (bmi >= 19 && bmi < 21) { score += 1; } else if (bmi >= 21 && bmi < 23) { score += 2; } else if (bmi >= 23) { score += 3; } testDetails = testDetails.FindAll(p => p.TEMPLATEITEMNAME.Contains("_")); foreach (HPN_TESTRESULTDETAILS item in testDetails) { score += item.ITEMRESULT.ToDouble(0); } testResult.RESULTDETAIL = string.Format("测试结果为:{0}分", score); return(score); }
public override double calculateResult(HPN_TESTRESULT testResult, List <HPN_TESTRESULTDETAILS> testDetails) { int score = 0, sum1 = 0, sum2 = 0, sum3 = 0; sum1 = testDetails.FindAll(p => p.ITEMRESULT == "0").Count; sum2 = testDetails.FindAll(p => p.ITEMRESULT == "1").Count; sum3 = testDetails.FindAll(p => p.ITEMRESULT == "2").Count; string testNo = testDetails.First().TESTNO; if (sum1 > sum2 && sum1 > sum3) { score = 0; } else if (sum2 > sum1 && sum2 > sum3) { score = 1; } else if (sum3 > sum1 && sum3 > sum2) { score = 2; } testResult.RESULTDETAIL = string.Format("测试结果为:{0}分", score); return(score); }
public override double calculateResult(HPN_TESTRESULT testResult, List <HPN_TESTRESULTDETAILS> testDetails) { double score = base.calculateResult(testResult, testDetails); testResult.RESULTDETAIL = string.Format("测试结果为:{0}分", score); return(score); }
public ActionResult getTestList(string UserId = null, decimal?TemplateType = null) { IQueryable <HPN_TEMPLATE> testList = _db.Set <HPN_TEMPLATE>().Where(p => p.STATUS == 1 && (TemplateType == null ? true : p.TYPE == TemplateType)).OrderBy(p => p.INDEX); List <object> list = new List <object>(); HR_CNR_USER user = null; if (!string.IsNullOrEmpty(UserId)) { user = _db.Set <HR_CNR_USER>().Where(p => p.USERID == UserId).FirstOrDefault(); if (user != null) { foreach (HPN_TEMPLATE item in testList) { HPN_TESTRESULT testResult = (from x in _db.Set <HPN_TESTRESULT>() where x.TEMPLATENAME == item.NAME select x).OrderByDescending(p => p.INPUTTIME).FirstOrDefault(); if (testResult == null) { continue; } if (!string.IsNullOrEmpty(testResult.RESULT)) { item.TestScore = testResult.RESULT.ToDouble(0); } var result = templateService.getResultDescByScore(testResult.TEMPLATENAME, testResult.RESULT.ToDouble(0)); item.WELCOMELABEL = string.Empty; if (result.Count > 0) { string desc = result.First().RESULT; if (string.IsNullOrEmpty(desc)) { desc = result.First().RESULTDETAIL; } if (!string.IsNullOrEmpty(desc)) { item.TestResult = desc; } } if (testResult.INPUTTIME != null) { item.TestTime = testResult.INPUTTIME; } } } } foreach (HPN_TEMPLATE item in testList) { list.Add(new { Title = item.TITLE, ActionName = item.NAME, TestScore = item.TestScore == 0 ? string.Empty : item.TestScore.ToString(), TestResult = item.TestResult, TestTime = item.TestTime.ToString() }); } return(Json(new { UserInfo = user, Templates = list, TemplateType = TemplateType == 1 ? "营养状况量表列表" : TemplateType == 2 ? "心理状况量表列表" : TemplateType == 3 ? "体力状况量表列表" : string.Empty }, JsonRequestBehavior.AllowGet)); }
public HPN_TESTRESULT handleResult(HPN_TESTRESULT testResult, List <HPN_TESTRESULTDETAILS> testDetails) { try { Template template = CreateInstance(testResult.TEMPLATENAME); template.setContext(_db); double result = template.calculateResult(testResult, testDetails); testResult.TESTRESULT = result.ToString(); return(testResult); }catch (Exception ex) { throw ex; } }
public virtual double calculateResult(HPN_TESTRESULT testResult, List <HPN_TESTRESULTDETAILS> testDetails) { double score = 0; foreach (HPN_TESTRESULTDETAILS item in testDetails) { if (!item.TEMPLATEITEMNAME.Contains('_')) { continue; } score += item.ITEMRESULT.ToDouble(0); } var resultDesc = (from x in _db.Set <HPN_RESULTDESC>() where x.TEMPLATENAME == testResult.TEMPLATENAME && x.MINSCORES <= (decimal)score && x.MAXSCORES >= (decimal)score select x).FirstOrDefault(); if (resultDesc != null) { testResult.TESTRESULT = resultDesc.RESULTDETAIL; } return(score); }
public override double calculateResult(HPN_TESTRESULT testResult, List <HPN_TESTRESULTDETAILS> testDetails) { double score = 0; var item = testDetails.Find(p => p.TEMPLATEITEMNAME == "nrs_4"); score += item == null ? 0 : item.ITEMRESULT.ToDouble(0); item = testDetails.Find(p => p.TEMPLATEITEMNAME == "nrs_5"); score += item == null ? 0 : item.ITEMRESULT.ToDouble(0); item = testDetails.Find(p => p.TEMPLATEITEMNAME == "age"); string testNo = testDetails.First().TESTNO; if (item != null) { if (item.ITEMRESULT.ToDouble(0) >= 70) { score += 1; } } testResult.RESULTDETAIL = string.Format("测试结果为:{0}分", score); return(score); }
public ActionResult getResult(string testno) { HPN_TESTRESULT testResult = (from x in _db.Set <HPN_TESTRESULT>() where x.TESTNO == testno select x).FirstOrDefault(); List <subresult> list = new List <subresult>(); HPN_TEMPLATE t = (from x in _db.Set <HPN_TEMPLATE>() where x.NAME == testResult.TEMPLATENAME select x).FirstOrDefault(); int templateType = 1; if (t != null) { templateType = (int)t.TYPE; } if (!string.IsNullOrEmpty(testResult.RESULT)) { list = testResult.RESULT.JsonDeserialize() as List <subresult>; } else { List <HPN_RESULTDESC> resultList = templateService.getResultDescByScore(testResult.TEMPLATENAME, testResult.RESULT.ToDouble(0)); if (resultList.Count <= 0) { subresult sr = new subresult(); sr.Score = testResult.RESULT.ToDouble(0); sr.RESULT = string.Empty; sr.Remark = string.Empty; list.Add(sr); } else { foreach (HPN_RESULTDESC result in resultList) { subresult sr = new subresult(); sr.Score = testResult.RESULT.ToDouble(0); sr.RESULT = result.RESULT; sr.Remark = result.RESULTDETAIL; list.Add(sr); } } } return(Json(new { Score = testResult.RESULT, Result = list, IsFinish = testResult.USERID == "0" ? true : false, TemplateType = templateType, UserId = testResult.USERID }, JsonRequestBehavior.AllowGet)); }
public ActionResult submitTest() { try { #region 验证参数 string templateName = Request.Form["templateName"]; if (string.IsNullOrEmpty(templateName)) { return(Json(new { Status = -9, Data = string.Empty, Msg = "参数不正确" })); } #endregion #region 生成订单 DateTime dtNow = DateTime.Now; string testNo = dtNow.Year.ToString().PadLeft(4, '0') + dtNow.Month.ToString().PadLeft(2, '0') + dtNow.Day.ToString().PadLeft(2, '0') + dtNow.Hour.ToString().PadLeft(2, '0') + dtNow.Minute.ToString().PadLeft(2, '0') + dtNow.Second.ToString().PadLeft(2, '0'); HPN_TESTRESULT test = new HPN_TESTRESULT(); test.INPUTTIME = dtNow; test.TESTNO = testNo; test.OTHERTESTNO = string.Empty; UserInfo user = _user.GetCurrentUser(); test.USERID = user == null ? "0" : user.UserId; test.TEMPLATENAME = templateName; test.STATUS = 1; test.IP = StringExtension.getIPAddress(); test.RESULT = string.Empty; test.RESULT = string.Empty; test.RESULTDETAIL = string.Empty; test.ID = Guid.NewGuid().ToString(); #endregion #region 保存明细 List <HPN_TEMPLATEITEM> questions = templateService.getTemplateItemList(templateName).ToList(); if (questions.Count <= 0) { return(Json(new { Status = -8, Data = string.Empty, Msg = "模版关键字不正确" })); } List <HPN_TEMPLATEITEMOPTIONS> options = templateService.getTemplateItemOptionsListByTemplateName(templateName); HPN_TESTRESULTDETAILS detail = new HPN_TESTRESULTDETAILS(); List <HPN_TESTRESULTDETAILS> testDetails = new List <HPN_TESTRESULTDETAILS>(); foreach (HPN_TEMPLATEITEM item in questions) { if (item.TAGTYPE == 4) { detail = new HPN_TESTRESULTDETAILS(); detail.INPUTTIME = dtNow; detail.TESTNO = testNo; detail.TEMPLATEITEMNAME = item.KWD; HPN_TEMPLATEITEMOPTIONS option = options.Find(p => p.TEMPLATEITEMNAME == item.KWD && p.VALUE.Trim() == Request.Form[item.KWD].Trim()); detail.ITEMRESULTID = option.IDATTR; detail.ITEMRESULT = Request.Form[item.KWD]; } else { //直接写 detail = new HPN_TESTRESULTDETAILS(); detail.INPUTTIME = dtNow; detail.TESTNO = testNo; detail.TEMPLATEITEMNAME = item.KWD; detail.ITEMRESULTID = item.KWD; if ((templateName == "Psqi" && item.KWD == "psqi_1") || (templateName == "Psqi" && item.KWD == "psqi_3")) { string val = Request.Form[item.KWD]; string[] arr = val.Split(':'); if (arr.Length == 2) { val = (arr[0].ToDouble(0) + arr[1].ToDouble(0) / 60).ToString(); } detail.ITEMRESULT = val; } else { detail.ITEMRESULT = Request.Form[item.KWD]; } } detail.ID = Guid.NewGuid().ToString(); testDetails.Add(detail); } #endregion #region 计算分数 TemplateService _tservice = new TemplateService(_db); test = _tservice.handleResult(test, testDetails); #endregion #region 保存结果 _db.Set <HPN_TESTRESULT>().Add(test); _db.Set <HPN_TESTRESULTDETAILS>().AddRange(testDetails); _db.SaveChanges(); #endregion return(Json(new { Status = 1, Data = string.Empty, Msg = "操作成功", Url = "/result/" + testNo })); } catch (Exception ex) { LogService.WriteErrorLog("HPNController[Post]", ex.ToString()); return(Json(new { Status = -99, Data = string.Empty, Msg = ex.Message })); } }
public override double calculateResult(HPN_TESTRESULT testResult, List <HPN_TESTRESULTDETAILS> testDetails) { //计算分数,并且把结果保存到HPN_TestResult的Remark字段,本函数返回分数 double score = 0, subscore = 0; Dictionary <string, string> dic = new Dictionary <string, string>(); string testNo = testDetails.First().TESTNO; StringBuilder sb = new StringBuilder("<div class='panel-group' id='Scl' style='margin-bottom:2rem;'>"); #region A睡眠质量 HPN_TESTRESULTDETAILS testResultDetail = testDetails.Find(p => p.TEMPLATEITEMNAME == "psqi_6"); subscore = testResultDetail.ITEMRESULT.ToDouble(0); score += subscore; sb.Append("<div class='panel panel-default'>"); sb.Append("<div class='panel-heading'>"); sb.Append("<h4 class='panel-title'>"); sb.Append("<a data-toggle='collapse' style='text-decoration:none; width: 100 %; display: block; '>"); sb.AppendFormat("{0}<span class='pull-right'>{1}</span>", "睡眠质量", subscore + "分"); sb.Append("</a>"); sb.Append("</h4>"); sb.Append("</div>"); sb.Append("</div>"); subscore = 0; #endregion #region B入睡时间 testResultDetail = testDetails.Find(p => p.TEMPLATEITEMNAME == "psqi_2"); double d = testResultDetail.ITEMRESULT.ToDouble(0); if (d >= 16 && d <= 30) { subscore += 1; } else if (d >= 31 && d < 60) { subscore += 2; } else if (d >= 60) { subscore += 3; } testResultDetail = testDetails.Find(p => p.TEMPLATEITEMNAME == "psqi_5_a"); subscore += testResultDetail.ITEMRESULT.ToDouble(0); if (subscore >= 1 && subscore <= 2) { subscore = 1; } else if (subscore >= 3 && subscore <= 4) { subscore = 2; } else if (subscore >= 5) { subscore = 3; } score += subscore; sb.Append("<div class='panel panel-default'>"); sb.Append("<div class='panel-heading'>"); sb.Append("<h4 class='panel-title'>"); sb.Append("<a data-toggle='collapse' style='text-decoration:none; width: 100 %; display: block; '>"); sb.AppendFormat("{0}<span class='pull-right'>{1}</span>", "入睡时间", subscore + "分"); sb.Append("</a>"); sb.Append("</h4>"); sb.Append("</div>"); sb.Append("</div>"); subscore = 0; #endregion #region C睡眠时间 testResultDetail = testDetails.Find(p => p.TEMPLATEITEMNAME == "psqi_4"); d = testResultDetail.ITEMRESULT.ToDouble(0); if (d < 5) { subscore = 3; } else if (d >= 5 && d < 6) { subscore = 2; } else if (d >= 6 && d < 7) { subscore = 1; } score += subscore; sb.Append("<div class='panel panel-default'>"); sb.Append("<div class='panel-heading'>"); sb.Append("<h4 class='panel-title'>"); sb.Append("<a data-toggle='collapse' style='text-decoration:none; width: 100 %; display: block; '>"); sb.AppendFormat("{0}<span class='pull-right'>{1}</span>", "睡眠时间", subscore + "分"); sb.Append("</a>"); sb.Append("</h4>"); sb.Append("</div>"); sb.Append("</div>"); subscore = 0; #endregion #region D睡眠效率 testResultDetail = testDetails.Find(p => p.TEMPLATEITEMNAME == "psqi_3"); HPN_TESTRESULTDETAILS tempResultDetail = testDetails.Find(p => p.TEMPLATEITEMNAME == "psqi_1"); double time1 = testResultDetail.ITEMRESULT.ToDouble(0) + 24 - tempResultDetail.ITEMRESULT.ToDouble(0); testResultDetail = testDetails.Find(p => p.TEMPLATEITEMNAME == "psqi_4"); double persent = testResultDetail.ITEMRESULT.ToDouble(0) / time1 * 100; if (persent < 65) { subscore = 3; } else if (persent >= 65 && persent < 75) { subscore = 2; } else if (persent >= 75 && persent < 85) { subscore = 1; } score += subscore; sb.Append("<div class='panel panel-default'>"); sb.Append("<div class='panel-heading'>"); sb.Append("<h4 class='panel-title'>"); sb.Append("<a data-toggle='collapse' style='text-decoration:none; width: 100 %; display: block; '>"); sb.AppendFormat("{0}<span class='pull-right'>{1}</span>", "睡眠效率", subscore + "分"); sb.Append("</a>"); sb.Append("</h4>"); sb.Append("</div>"); sb.Append("</div>"); subscore = 0; #endregion #region E睡眠障碍 testResultDetail = testDetails.Find(p => p.TEMPLATEITEMNAME == "psqi_5_b"); subscore += testResultDetail.ITEMRESULT.ToDouble(0); testResultDetail = testDetails.Find(p => p.TEMPLATEITEMNAME == "psqi_5_c"); subscore += testResultDetail.ITEMRESULT.ToDouble(0); testResultDetail = testDetails.Find(p => p.TEMPLATEITEMNAME == "psqi_5_d"); subscore += testResultDetail.ITEMRESULT.ToDouble(0); testResultDetail = testDetails.Find(p => p.TEMPLATEITEMNAME == "psqi_5_e"); subscore += testResultDetail.ITEMRESULT.ToDouble(0); testResultDetail = testDetails.Find(p => p.TEMPLATEITEMNAME == "psqi_5_f"); subscore += testResultDetail.ITEMRESULT.ToDouble(0); testResultDetail = testDetails.Find(p => p.TEMPLATEITEMNAME == "psqi_5_g"); subscore += testResultDetail.ITEMRESULT.ToDouble(0); testResultDetail = testDetails.Find(p => p.TEMPLATEITEMNAME == "psqi_5_h"); subscore += testResultDetail.ITEMRESULT.ToDouble(0); testResultDetail = testDetails.Find(p => p.TEMPLATEITEMNAME == "psqi_5_i"); subscore += testResultDetail.ITEMRESULT.ToDouble(0); testResultDetail = testDetails.Find(p => p.TEMPLATEITEMNAME == "psqi_5_j"); subscore += testResultDetail.ITEMRESULT.ToDouble(0); if (subscore >= 19) { subscore = 3; } else if (subscore >= 10 && subscore < 19) { subscore = 2; } else if (subscore >= 1 && subscore < 10) { subscore = 1; } score += subscore; sb.Append("<div class='panel panel-default'>"); sb.Append("<div class='panel-heading'>"); sb.Append("<h4 class='panel-title'>"); sb.Append("<a data-toggle='collapse' style='text-decoration:none; width: 100 %; display: block; '>"); sb.AppendFormat("{0}<span class='pull-right'>{1}</span>", "睡眠障碍", subscore + "分"); sb.Append("</a>"); sb.Append("</h4>"); sb.Append("</div>"); sb.Append("</div>"); subscore = 0; #endregion #region F催眠药物 testResultDetail = testDetails.Find(p => p.TEMPLATEITEMNAME == "psqi_7"); subscore = testResultDetail.ITEMRESULT.ToDouble(0); score += subscore; sb.Append("<div class='panel panel-default'>"); sb.Append("<div class='panel-heading'>"); sb.Append("<h4 class='panel-title'>"); sb.Append("<a data-toggle='collapse' style='text-decoration:none; width: 100 %; display: block; '>"); sb.AppendFormat("{0}<span class='pull-right'>{1}</span>", "催眠药物", subscore + "分"); sb.Append("</a>"); sb.Append("</h4>"); sb.Append("</div>"); sb.Append("</div>"); subscore = 0; #endregion #region G日间功能障碍 testResultDetail = testDetails.Find(p => p.TEMPLATEITEMNAME == "psqi_8"); subscore = testResultDetail.ITEMRESULT.ToDouble(0); testResultDetail = testDetails.Find(p => p.TEMPLATEITEMNAME == "psqi_9"); subscore = testResultDetail.ITEMRESULT.ToDouble(0); if (subscore >= 5) { subscore = 3; } else if (subscore >= 3 && subscore <= 4) { subscore = 2; } else if (subscore >= 1 && subscore <= 2) { subscore = 1; } score += subscore; sb.Append("<div class='panel panel-default'>"); sb.Append("<div class='panel-heading'>"); sb.Append("<h4 class='panel-title'>"); sb.Append("<a data-toggle='collapse' style='text-decoration:none; width: 100 %; display: block; '>"); sb.AppendFormat("{0}<span class='pull-right'>{1}</span>", "日间功能障碍", subscore + "分"); sb.Append("</a>"); sb.Append("</h4>"); sb.Append("</div>"); sb.Append("</div>"); subscore = 0; #endregion sb.Append("</div>"); testResult.RESULTDETAIL = string.Format("测试结果为:{0}分", score); testResult.TESTRESULT = sb.ToString(); return(score); }