114 lines
5.3 KiB
C#
114 lines
5.3 KiB
C#
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<TraumaStatisticsModel> GetSevereTraumaStatistics(string hospitalGuid, string startTime, string endTime)
|
|
{
|
|
List<TraumaStatisticsModel> list = new List<TraumaStatisticsModel>();
|
|
|
|
int Month = (Convert.ToDateTime(endTime).Year - Convert.ToDateTime(startTime).Year) * 12 + (Convert.ToDateTime(endTime).Month - Convert.ToDateTime(startTime).Month);
|
|
List<DateTime> monthList = new List<DateTime>();
|
|
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<T_Service_Patient, T_Service_Trauma_BaseInfo, T_Service_Trauma_ReceiveInfo, T_Service_Trauma_ISSAIS>((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<T_Service_Patient, T_Service_Trauma_BaseInfo, T_Service_Trauma_ReceiveInfo, T_Service_Trauma_ISSAIS, T_Service_Trauma_OutCome>((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;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 计算月份
|
|
/// </summary>
|
|
/// <param name="month"></param>
|
|
/// <returns></returns>
|
|
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;
|
|
}
|
|
}
|
|
|
|
|
|
} |