/// <summary> /// 获取一个这是第几次诊断。 /// </summary> /// <param name="surveys"></param> /// <returns>0初诊,1复诊。</returns> public static int GetDiagnosisCount(this Surveys surveys) { var ary = EntityUtility.GetTuples(surveys.UserState); var flag = ary.FirstOrDefault(c => c.Item1 == "诊次")?.Item2 ?? 0; return((int)flag); }
/// <summary> /// 设置诊断次数。 /// </summary> /// <param name="surveys"></param> /// <param name="count">0初诊,1复诊。</param> public static void SetDiagnosisCount(this Surveys surveys, int count) { var ary = EntityUtility.GetTuples(surveys.UserState); var flag = ary.FirstOrDefault(c => c.Item1 == "诊次"); if (null != flag) { ary.Remove(flag); } flag = Tuple.Create("诊次", (decimal)count); ary.Add(flag); surveys.UserState = string.Join(",", ary.Select(c => $"{c.Item1}{c.Item2.ToString()}")); }
/// <summary> /// 获取最初症状的结构化数据。 /// </summary> /// <param name="surveys"></param> /// <param name="db"></param> InsomniaAnalysisData GetFirstCore(Surveys surveys, ApplicationDbContext db) { InsomniaAnalysisData result = new InsomniaAnalysisData(); var answerTemplates = db.Set <SurveysAnswerTemplate>(); var quesetions = db.Set <SurveysQuestionTemplate>(); quesetions.Load(); var tb1 = db.Set <InsomniaConversion11>(); tb1.Load(); var answers = surveys.SurveysAnswers; foreach (var answer in answers) { var answerTemplate = answerTemplates.Find(answer.TemplateId); if (null == answerTemplate) //若不是选择题 { var question = quesetions.Find(answer.TemplateId); if (null == quesetions) { continue; } switch (question.QuestionTitle) { case "姓名": result.Name = answer.Guts; break; case "性别": result.Gender = answer.Guts; break; case "年龄": if (decimal.TryParse(answer.Guts, out decimal age)) { result.Age = age; } break; default: break; } continue; } //选择题 var props = EntityUtility.GetTuples(answerTemplate.UserState); var number = props.FirstOrDefault(c => c.Item1 == "编号"); if (null == number) { continue; } var conv11 = InsomniaConversion11.DefaultCollection.FirstOrDefault(c => c.CnSymptomNumber == number.Item2.ToString()); if (null == conv11) { continue; } result.InsomniaConversion11s.Add(conv11); var propIns = EntityUtility.GetTuples(answer.UserState); var invalid = propIns.FirstOrDefault(c => c.Item1 == "无效"); if (null != invalid && invalid.Item2 != 0) //若存在无效条目 { result.Invalid11s.Add(conv11); } } return(result); }