using HL_FristAidPlatform_Help; using HL_FristAidPlatform_IDataBase; using HL_FristAidPlatform_Models; using SqlSugar; using System; using System.Collections.Generic; using System.Linq; namespace HL_FristAidPlatform_DataBase { public class T_Service_Trauma_SevereTraumaDB :BaseDB, IT_Service_Trauma_SevereTrauma { public SqlSugarClient db = GetClient(); public List GetSevereTraumaStatistics(string hospitalGuid, string startTime, string endTime) { List list = new List(); int Month = (Convert.ToDateTime(endTime).Year - Convert.ToDateTime(startTime).Year) * 12 + (Convert.ToDateTime(endTime).Month - Convert.ToDateTime(startTime).Month); List monthList = new List(); for (int i = 0; i < Month; i++) { string res = Convert.ToDateTime(startTime).AddMonths(i).Year + "-" + GetMonthZero(Convert.ToDateTime(startTime).AddMonths(i).Month) + "-01"; DateTime dt = Convert.ToDateTime(res); monthList.Add(dt.AddDays(1 - dt.Day)); } //ArriveEmergencyDeath ArriveOutpatientDeath IllnessLevel var oneClass = db.Queryable((a, b, c, d) => new JoinQueryInfos( JoinType.Left, a.GUID == b.PatientGuid, JoinType.Left, a.GUID == c.PatientGuid, JoinType.Left, a.GUID == d.PatientGuid)) .Where((a, b, c, d) => a.HospitalGuid == hospitalGuid && a.SystemModuleID == 4 && a.DeleteFlag == 0 && d.Grave == 1) .Where((a, b, c, d) => a.CreationDate >= SqlFunc.ToDate(startTime) && a.CreationDate <= SqlFunc.ToDate(endTime)).ToList(); var twoClass = db.Queryable((a, b, c, d, e) => new JoinQueryInfos( JoinType.Left, a.GUID == b.PatientGuid, JoinType.Left, a.GUID == c.PatientGuid, JoinType.Left, a.GUID == d.PatientGuid, JoinType.Left, a.GUID == e.PatientGuid)) .Where((a, b, c, d, e) => a.HospitalGuid == hospitalGuid && a.SystemModuleID == 4 && a.DeleteFlag == 0 && d.Grave == 1 && a.CreationDate >= SqlFunc.ToDate(startTime) && a.CreationDate <= SqlFunc.ToDate(endTime) && b.IllnessLevel == "5" || c.Death == "1" || c.ObservationDead == "1" || e.Whereabouts == "4") .ToList(); if (oneClass != null) { int sum = 0; for (int i = 0; i < monthList.Count; i++) { TraumaStatisticsModel model = new TraumaStatisticsModel(); model.Month = monthList[i].ToString("yyyy-MM"); int count = oneClass.Where(j => j.CreationDate >= SqlFunc.ToDate(monthList[i].ToString()) && j.CreationDate <= Convert.ToDateTime(SqlFunc.ToDate(monthList[i].ToString()).AddMonths(1).ToString("yyyy-MM-01")).AddDays(-1)).Count(); sum += count; int Deathcount = 0; if (twoClass != null) { Deathcount = twoClass.Where(j => j.CreationDate >= SqlFunc.ToDate(monthList[i].ToString()) && j.CreationDate <= Convert.ToDateTime(SqlFunc.ToDate(monthList[i].ToString()).AddMonths(1).ToString("yyyy-MM-01")).AddDays(-1)).Count(); } model.Count = count + ""; model.DeathRate = "0"; if (count != 0) { double temp = ((double)Deathcount / (double)count) * 100; model.DeathRate = Math.Round(temp, 2)+""; } if(twoClass != null) { if(i == monthList.Count - 1) { model.SumCount = sum + ""; double temp = 0; if (sum != 0) { temp = ((double)twoClass.Count() / (double)sum) * 100; } model.SumDeathRate = Math.Round(temp, 2) + ""; } } list.Add(model); } } return list; } /// /// 计算月份 /// /// /// private string GetMonthZero(int month) { if (month < 10) { return "0" + month; } else { return month.ToString(); } } private int GetMinutes(DateTime startTime, DateTime endTime) { DateTime dtone = Convert.ToDateTime(startTime); DateTime dttwo = Convert.ToDateTime(endTime); TimeSpan span = dttwo.Subtract(dtone); //算法是dttwo 减去 dtone int ss = span.Days * 1440 + span.Hours * 60 + span.Minutes; return ss; } } }