StableVersion4.3/HL_FristAidPlatform_DataBase/Service/T_Service_Apoplexy_DeadColu...

260 lines
11 KiB
C#
Raw Normal View History

2024-03-11 09:47:34 +08:00
using HL_FristAidPlatform_Help;
using HL_FristAidPlatform_IDataBase;
using HL_FristAidPlatform_Models;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HL_FristAidPlatform_DataBase
{
/// <summary>
/// 死亡率
/// </summary>
public class T_Service_Apoplexy_DeadColumnsNumberDB : BaseDB, IT_Service_Apoplexy_DeadColumnsNumber
{
public SqlSugarClient db = GetClient();
/// <summary>
/// 统计:死亡率
/// </summary>
/// <param name="hospitalGuid"></param>
/// type 0年1月
/// <returns></returns>
///
public string GetMonthZero(int month)
{
if (month < 10)
{
return "0" + month;
}
else
{
return month.ToString();
}
}
//按月
/*public List<string> GetMonthList(string startTime, string endTime)
{
DateTime st = Convert.ToDateTime(startTime);
DateTime et = Convert.ToDateTime(endTime);
//保留 年 月 份
int Month = (et.Year - st.Year) * 12 + (et.Month - st.Month);
List<string> monthList = new List<string>();
for (int i = 0; i < Month + 1; i++)
{
monthList.Add(st.AddMonths(i).Year + "-" + GetMonthZero(st.AddMonths(i).Month));
}
return monthList;
}*/
//按年
/*public List<string> GetYearList(string startTime, string endTime)
{
DateTime st = Convert.ToDateTime(startTime);
st = new DateTime(st.Year, 1, 1);
string strST = SqlFunc.ToString(st);
DateTime et = Convert.ToDateTime(endTime);
et = new DateTime(et.Year, 12, 31);
string strET = SqlFunc.ToString(et);
//DateTime yst = st.ToShortDateString() + " 00:00:00";
//DateTime yet = et.ToShortDateString() + " 23:59:59";
//保留 年
int Year = (et.Year - st.Year);
List<string> YearList = new List<string>();
for (int i = 0; i < Year + 1; i++)
{
YearList.Add(st.AddMonths(i).Year + "-" + GetMonthZero(st.AddMonths(i).Month));
}
return YearList;
}*/
/* /// <summary>
/// 死亡率
/// </summary>
/// <param name="hospitalGuid"></param>
/// <param name="startTime"></param>
/// <param name="endTime"></param>
/// <param name="type"></param>
/// <returns></returns>
public List<ApoplexyStatisticsModel> GetDeadColumnsNumber(string hospitalGuid, string startTime, string endTime, int type)
{
List<ApoplexyStatisticsModel> list = new List<ApoplexyStatisticsModel>();
var oneClass = db.Queryable<T_Service_Patient, T_Service_Apoplexy_PatientOutcome>((a, b) => a.GUID == b.PatientGuid)
.Where((a, b) => a.HospitalGuid == hospitalGuid && a.DeleteFlag == 0 && a.SystemModuleID == 3)
.Where((a, b) => !SqlFunc.IsNullOrEmpty(a.CreationDate) && !SqlFunc.IsNullOrEmpty(b.CYSwSj))
.Select((a, b) => new { CreationDate=a.CreationDate, GUID=b.GUID, CYSwSj=b.CYSwSj, CYLyFs=b.CYLyFs }).ToList();
if (type == 1)
{
int Month = (Convert.ToDateTime(endTime).Year - Convert.ToDateTime(startTime).Year) * 12 + (Convert.ToDateTime(endTime).Month - Convert.ToDateTime(startTime).Month);
List<string> monthList = new List<string>();
for (int i = 0; i < Month + 1; i++)
{
monthList.Add(Convert.ToDateTime(startTime).AddMonths(i).Year + "-" + GetMonthZero(Convert.ToDateTime(startTime).AddMonths(i).Month));
}
for (int i = 0; i < monthList.Count(); i++)
{
ApoplexyStatisticsModel model = new ApoplexyStatisticsModel();
DateTime start = Convert.ToDateTime(monthList[i] + "-01");
DateTime end = Convert.ToDateTime(monthList[i]).AddMonths(1).AddDays(-1);
//Queryable 结果直接写连接 5.0.4.3 版本支持
//d db.Queryable(oneClass).LeftJoin<Order>((o, cu) => o.Id == cu.Id).Select(o => o).ToList();
int Count = oneClass.Where( a => a.CreationDate >= Convert.ToDateTime(startTime) && a.CreationDate <= Convert.ToDateTime(endTime)).Count();
int DeathCount = 0;
if (Count > 0)
{
DeathCount = oneClass.Where(a =>Convert.ToDateTime(a.CYSwSj) >= Convert.ToDateTime(startTime) && Convert.ToDateTime(a.CYSwSj) <= Convert.ToDateTime(endTime) && a.CYLyFs == "5").Count();
}
model.Key = monthList[i] + "月";
if (Count <= 0)
{
model.Value = "0.00";
}
else
{
float a = (float)DeathCount / Count * 100;
model.Value = String.Format("{0:F}", a);
}
list.Add(model);
}
}
if (type == 2)
{
int years = int.Parse(startTime);
DateTime dt1 = new DateTime(years, 1, 1);
DateTime dt2 = new DateTime(years, 12, 31);
int Year = (Convert.ToDateTime(endTime).Year - Convert.ToDateTime(startTime).Year);
List<string> yearList = new List<string>();
for (int i = 0; i < Year + 1; i++)
{
yearList.Add(Convert.ToDateTime(startTime).AddYears(i).Year.ToString());
}
for (int i = 0; i < yearList.Count(); i++)
{
ApoplexyStatisticsModel model = new ApoplexyStatisticsModel();
string year = yearList[i];
int Count = oneClass.Where(a => Convert.ToDateTime(a.CreationDate).ToString("yyyy") == year && Convert.ToDateTime(a.CreationDate).ToString("yyyy") == year).Count();
int DeathCount = 0;
if (Count > 0)
{
DeathCount = oneClass.Where(a => Convert.ToDateTime(a.CYSwSj) >= Convert.ToDateTime(startTime) && Convert.ToDateTime(a.CYSwSj) <= Convert.ToDateTime(endTime) && a.CYLyFs == "5").Count();
}
model.Key = yearList[i] + "年";
if (Count <= 0)
{
model.Value = "0.00";
}
else
{
float a = (float)DeathCount / Count * 100;
model.Value = String.Format("{0:F}", a);//四舍五入,保留两位小数
}
list.Add(model);
}
}
return list;
}*/
/// <summary>
/// 死亡率的另一种写法
/// </summary>
/// <param name="hospitalGuid"></param>
/// <param name="startTime"></param>
/// <param name="endTime"></param>
/// <param name="type"></param>
/// <returns></returns>
public List<ApoplexyStatisticsModel> GetDeadColumnsNumber1(string hospitalGuid, string startTime, string endTime, int type)
{
List<ApoplexyStatisticsModel> list = new List<ApoplexyStatisticsModel>();
DateTime dt1 = DateTime.Now;
DateTime dt2 = DateTime.Now;
if (type == 2)
{
int year = int.Parse(startTime);
dt1 = new DateTime(year, 1, 1);
dt2 = new DateTime(year, 12, 31);
}
if (type == 1)
{
DateTime startdt = Convert.ToDateTime(startTime);
dt1 = startdt.AddDays(1 - startdt.Day);
DateTime enddt = Convert.ToDateTime(endTime);
dt2 = enddt.AddDays(1 - enddt.Day).AddMonths(1).AddDays(-1);
}
//数据结果集
var oneClass = db.Queryable<T_Service_Patient, T_Service_Apoplexy_PatientOutcome>((a, b) => a.GUID == b.PatientGuid)
.Where((a, b) => a.HospitalGuid == hospitalGuid && a.DeleteFlag == 0 && a.SystemModuleID == 3)
.Select((a, b) => new { CreationDate = a.CreationDate, GUID = b.GUID, CYSwSj = b.CYSwSj, CYLyFs = b.CYLyFs }).ToList();
//月份集合
List<DateTime> monthList = new List<DateTime>();
int Month = (dt2.Year - dt1.Year) * 12 + (dt2.Month - dt1.Month);
for (int i = 0; i < Month + 1; i++)
{
string res = dt1.AddMonths(i).Year + "-" + GetDateZero(dt1.AddMonths(i).Month) + "-01";
DateTime dt = Convert.ToDateTime(res);
monthList.Add(dt.AddDays(1 - dt.Day));
}
//开始填充集合
if (oneClass != null)
{
if (monthList.Count > 0)
{
ApoplexyStatisticsModel model = null;
for (int i = 0; i < monthList.Count; i++)
{
DateTime start = Convert.ToDateTime(monthList[i]);
DateTime end = Convert.ToDateTime(monthList[i]).AddMonths(1).AddDays(-1);
string timeDate = monthList[i].ToString("yyyy-MM");
model = new ApoplexyStatisticsModel();
model.Key = timeDate;
int sum = oneClass.Where(j =>j.CYLyFs == "5" && SqlFunc.ToDate(j.CreationDate) >= start && SqlFunc.ToDate(j.CreationDate) <= end.AddDays(1)).Count();
int count = oneClass.Where(j => SqlFunc.ToDate(j.CreationDate) >= start && SqlFunc.ToDate(j.CreationDate) <= end.AddDays(1)).Count();
if (count > 0)
model.Value = ((double)sum / count).ToString("#0.00");
if (count == 0)
model.Value = ((double)count).ToString("#0.00");
list.Add(model);
}
}
}
else
{
ApoplexyStatisticsModel model = null;
for (int i = 0; i < monthList.Count; i++)
{
string timeDate = monthList[i].ToString("yyyy-MM");
model = new ApoplexyStatisticsModel();
model.Key = timeDate;
list.Add(model);
}
}
return list;
}
public string GetDateZero(int date)
{
if (date < 10)
{
return "0" + date;
}
else
{
return date.ToString();
}
}
}
}