public ActionResult Test(FormCollection collection) { Stopwatch sw = Stopwatch.StartNew(); var bpSys = collection["BpSys"]; var bpDia = collection["BpDia"]; var cTnT = collection["CTnT"]; var cTnI = collection["CTnI"]; var context = new Context(); context.NumericParameters.Add("肌钙蛋白T测定", double.Parse(cTnT)); context.NumericParameters.Add("肌钙蛋白I测定", double.Parse(cTnI)); context.NumericParameters.Add("肱动脉收缩压", double.Parse(bpSys)); context.NumericParameters.Add("肱动脉舒张压", double.Parse(bpDia)); var filteredProblems = new List <ClinicalProblemDefinition>(); using (var db = new KBEntities()) { filteredProblems.Add(db.ClinicalProblemDefinition.FirstOrDefault(x => x.Name == "心肌梗死")); filteredProblems.Add(db.ClinicalProblemDefinition.FirstOrDefault(x => x.Name == "高血压")); var triggeredProblems = (new DecisionSupportService()).Reason(filteredProblems, context); var result = "发现的临床问题:"; triggeredProblems.ToList().ForEach(x => result = result + x + ";"); sw.Stop(); ViewBag.Performance = "Total consumed time (ms): " + sw.ElapsedMilliseconds; return(View(triggeredProblems)); } }
//[TODO] unfinished. () not considered. Only numeric items are considered public static List <LaymanRuleCondition> BreakDownRuleCondition(Rule rule) { using (var db = new KBEntities()) { var list = new List <LaymanRuleCondition>(); var condition = rule.Condition.ToString() .Replace("this.Context.NumericParameters.get_Item(\"", "") .Replace("this.Context.BooleanParameters.get_Item(\"", "") .Replace("this.Context.StringParameters.get_Item(\"", "") .Replace("\")", "");; var delimiters = new List <string>(); foreach (EnumLogicalOperator value in Enum.GetValues(typeof(EnumLogicalOperator))) { delimiters.Add(EnumHelper.GetEnumDescription <EnumLogicalOperator>(value)); } string[] parts = condition.Split(delimiters.ToArray(), StringSplitOptions.RemoveEmptyEntries); string temp = condition; string delimiter = "&&"; foreach (var part in parts) { var item = new LaymanRuleCondition(); temp = temp.Substring(part.Length).Trim(); delimiter = delimiters.FirstOrDefault(x => temp.StartsWith(x) == true); item.OuterOperator = EnumHelper.GetEnumFromDescription <EnumLogicalOperator>(delimiter); var innerDelimiters = new List <string>(); foreach (EnumComparisonOperator value in Enum.GetValues(typeof(EnumComparisonOperator))) { innerDelimiters.Add(EnumHelper.GetEnumDescription <EnumComparisonOperator>(value)); } string[] innerParts = part.Split(innerDelimiters.ToArray(), StringSplitOptions.RemoveEmptyEntries); if (innerParts.Length == 2) //lhs & rhs { var lhs = innerParts[0].Trim(); var rhs = innerParts[1].Trim(); var contextItem = db.ContextItemDefinition.FirstOrDefault(x => x.Name == lhs); item.Name = contextItem.Name; item.Unit = contextItem.Unit; item.DataType = (EnumDataType)Enum.Parse(typeof(EnumDataType), contextItem.DataType); item.NumericValue = double.Parse(rhs); item.InnerOperator = EnumHelper.GetEnumFromDescription <EnumComparisonOperator>(part.Replace(lhs, "").Replace(rhs, "").Trim()); list.Add(item); } } return(list); } }
public IList <YuQuan.Models.Encounter> GetActiveEncounterList(KBEntities db) { var db2 = new CPEntities(); var list = new List <Encounter>(); if (db == null || db.Encounter == null) { return(list); } foreach (var x in db.Encounter) { var y = db2.CP_VISIT.FirstOrDefault(z => z.CP_ID == x.FK_EMR_Encounter_Id); if (y == null) { continue; } //var encounter = new Encounter() //{ // PatientId = y.INPATIENT_NO, // PatientName = ChineseNameGenerator.GetChineseName(), // Diagnosis = y.DIAGNOSIS, // Admission = y.ADMISSION_TIME, // Discharge = y.DISCHARGE_TIME, // PatientBirthDay = y.BIRTHDAY, // PatientGender = y.GENDER, // PatientPhotoURL = y.GENDER == "女" ? // "/GuLangYu;component/Resources/female.PNG" : // "/GuLangYu;component/Resources/male.PNG", // BedNO = x.Id.ToString(), // FK_EMR_Encounter_Id = x.FK_EMR_Encounter_Id //}; x.PatientId = y.INPATIENT_NO; x.PatientName = ChineseNameGenerator.GetChineseName(); x.Diagnosis = y.DIAGNOSIS; x.Admission = y.ADMISSION_TIME; x.Discharge = y.DISCHARGE_TIME; x.PatientBirthDay = y.BIRTHDAY; x.PatientGender = y.GENDER; x.PatientPhotoURL = (y.GENDER == "女") ? "/GuLangYu;component/Resources/female.PNG" : "/GuLangYu;component/Resources/male.PNG"; x.BedNO = x.Id.ToString(); x.FK_EMR_Encounter_Id = x.FK_EMR_Encounter_Id; list.Add(x); // use original entity, not copied entity. Because later we need to access its navigation property } return(list); }
/// <summary> /// used for demo purpose only /// </summary> /// <param name="id"></param> /// <param name="db"></param> /// <returns></returns> public IEnumerable <Fact> GetFactsFromReportMock(int id, KBEntities db) { var facts = new List <Fact>(); if (db == null) { return(facts); } var report = db.Report.Find(id); if (report == null) { return(facts); } if (report.Event.EventType == EnumEventType.体征数据.ToString()) // && db.Fact.Where(x=>x.Report.Id==report.Id && x.LifeSpan == EnumLifeSpan.Temporary.ToString()).Count()<=0) { var contextItem = db.ContextItemDefinition.FirstOrDefault(x => x.Name == "肱动脉收缩压"); if (contextItem != null) { facts.Add(new Fact() { Report = report, NumericValue = 160 + RandomNumberHelper.GetRandomNumber(-20, 20), IsAbnormal = true, Confidence = 100, ContextItemDefinition = contextItem, LifeSpan = EnumLifeSpan.Temporary.ToString() }); } contextItem = db.ContextItemDefinition.FirstOrDefault(x => x.Name == "肱动脉舒张压"); if (contextItem != null) { facts.Add(new Fact() { Report = report, NumericValue = 120 + RandomNumberHelper.GetRandomNumber(-20, 20), IsAbnormal = true, Confidence = 100, ContextItemDefinition = contextItem, LifeSpan = EnumLifeSpan.Temporary.ToString() }); } } else { foreach (var x in db.Fact) { if (x.Report.Id == id && x.LifeSpan == EnumLifeSpan.Temporary.ToString()) { facts.Add(x); } } } return(facts); }