518 lines
26 KiB
C#
518 lines
26 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;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace HL_FristAidPlatform_DataBase
|
|
{
|
|
/// <summary>
|
|
/// 胸痛单元接口
|
|
/// </summary>
|
|
public class ChestPainUnitDB : BaseDB, IChestPainUnit
|
|
{
|
|
public SqlSugarClient db = GetClient();
|
|
|
|
/// <summary>
|
|
/// 胸痛单元患者列表查询
|
|
/// </summary>
|
|
/// <param name="hospitalGuid"></param>
|
|
/// <param name="starTime"></param>
|
|
/// <param name="endTime"></param>
|
|
/// <param name="preliminaryDiagnosis"></param>
|
|
/// <param name="hospitalMode"></param>
|
|
/// <param name="name"></param>
|
|
/// <param name="pageIndex"></param>
|
|
/// <param name="pageSize"></param>
|
|
/// <returns></returns>
|
|
public TableModel<ChestPainUnitModel> GetChestPainUnitList(string hospitalGuid, int systemId, string starTime, string endTime, string preliminaryDiagnosis, string hospitalMode, string name, int pageIndex, int pageSize, string GreenWay)
|
|
{
|
|
List<ChestPainUnitModel> list = new List<ChestPainUnitModel>();
|
|
string str = "";
|
|
if (!string.IsNullOrEmpty(name))
|
|
str += " AND ([a].Name Like '%" + name + "%')";
|
|
if (!string.IsNullOrEmpty(hospitalMode))
|
|
str += " AND ([b].CW_Coming_Way_Code='" + hospitalMode + "')";
|
|
if (!string.IsNullOrEmpty(preliminaryDiagnosis))
|
|
str += " AND ([c].CP_Diagnosis_Code='" + preliminaryDiagnosis + "')";
|
|
if (!string.IsNullOrEmpty(starTime))
|
|
str += " AND ([a].[CreationDate]> ='" + Convert.ToDateTime(starTime) + "')";
|
|
if (!string.IsNullOrEmpty(endTime))
|
|
str += " AND ([a].[CreationDate] < '" + Convert.ToDateTime(endTime).AddDays(1) + "')";
|
|
|
|
if (!string.IsNullOrEmpty(GreenWay))
|
|
str += " AND ([a].[IsGreenWay] ='" + GreenWay + "')";
|
|
|
|
string sql = string.Format(@"SELECT * FROM (select ROW_NUMBER() OVER(Order by [a].CreationDate DESC) AS RowNumber, COUNT(1) OVER() AS TotalCount, [a].CreationDate, [a].GUID,[a].Name,[a].Gender,[a].Age, [a].Status,[a].[IsGreenWay],[a].IsForward,
|
|
[a].RegisterTime, [b].Attack_Time,[b].CW_Coming_Way_Code, [c].CP_Diagnosis_Code, [b].Is_Null_Attack_Detail_Time,
|
|
CASE WHEN CW_Coming_Way_Code ='1' THEN CW_120_First_MC_Time
|
|
WHEN CW_Coming_Way_Code='3' THEN CW_ZXLY_First_MC_Time
|
|
WHEN CW_Coming_Way_Code='4' THEN CW_YNFB_First_MC_Time END AS [First_MC_Time]
|
|
FROM [T_Service_Patient] a
|
|
LEFT JOIN [T_Service_ChestPain_FirstAIDInfo] b ON ( [a].[GUID] = [b].[PatientGuid] )
|
|
LEFT JOIN [T_Service_ChestPain_TreatmentInfo]c ON ( [a].[GUID] = [c].[PatientGuid] )
|
|
WHERE ( [a].[HospitalGuid] = '{0}' )
|
|
AND ( [a].[SystemModuleID] = {1} )
|
|
AND ( [a].[DeleteFlag] = 0 )
|
|
AND ( [a].[CreationDate] IS NOT NULL )
|
|
" + str + " ) AS B where b.RowNumber BETWEEN ({2}-1)*{3}+1 and {4}*{5} ORDER BY B.[CreationDate] DESC", hospitalGuid, systemId, pageIndex, pageSize, pageIndex, pageSize);
|
|
list = db.Ado.SqlQuery<ChestPainUnitModel>(sql);
|
|
int total = 0;
|
|
if (list.Count > 0)
|
|
{
|
|
total = list[0].TotalCount;
|
|
for (int i = 0; i < list.Count; i++)
|
|
{
|
|
if (list[i].Attack_Time != null && list[i].Attack_Time.ToString() != "")
|
|
{
|
|
if (list[i].Is_Null_Attack_Detail_Time == "1")
|
|
{
|
|
list[i].Attack_Time = Convert.ToDateTime(list[i].Attack_Time).ToString("yyyy-MM-dd");
|
|
}
|
|
else if (list[i].Is_Null_Attack_Detail_Time == "0")
|
|
{
|
|
list[i].Attack_Time = Convert.ToDateTime(list[i].Attack_Time).ToString("yyyy-MM-dd HH:mm");
|
|
}
|
|
}
|
|
if (list[i].First_MC_Time != null && list[i].First_MC_Time.ToString() != "")
|
|
{
|
|
if (list[i].Is_Null_Attack_Detail_Time == "1")
|
|
{
|
|
list[i].First_MC_Time = Convert.ToDateTime(list[i].First_MC_Time).ToString("yyyy-MM-dd");
|
|
}
|
|
else if (list[i].Is_Null_Attack_Detail_Time == "0")
|
|
{
|
|
list[i].First_MC_Time = Convert.ToDateTime(list[i].First_MC_Time).ToString("yyyy-MM-dd HH:mm");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
TableModel<ChestPainUnitModel> t = new TableModel<ChestPainUnitModel>();
|
|
t.Code = 0;
|
|
t.PageCount = list.Count;
|
|
t.TotalNumber = total;
|
|
t.Data = list;
|
|
t.Msg = "成功";
|
|
return t;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 胸痛单元来院方式统计查询
|
|
/// </summary>
|
|
/// <param name="hospitalGuid"></param>
|
|
/// <param name="systemId"></param>
|
|
/// <returns></returns>
|
|
public ChestPainUnitHospitalModel GetChestPainUnitHospitalModel(string hospitalGuid, int systemId)
|
|
{
|
|
ChestPainUnitHospitalModel model = new ChestPainUnitHospitalModel();
|
|
var oneClass = db.Queryable<T_Service_Patient, T_Service_ChestPain_FirstAIDInfo>((a, b) => new JoinQueryInfos(JoinType.Inner, a.GUID == b.PatientGuid)).Where((a, b) => a.HospitalGuid == hospitalGuid && a.SystemModuleID == systemId && a.DeleteFlag == 0).Select((a, b) => new
|
|
{
|
|
ComeHosptialWay = b.CW_Coming_Way_Code
|
|
}).ToList();
|
|
|
|
if (oneClass != null)
|
|
{
|
|
model.TotalOne = oneClass.Where(i => i.ComeHosptialWay == "1").Count();
|
|
model.TotalTwo = oneClass.Where(i => i.ComeHosptialWay == "3").Count();
|
|
model.TotalThree = oneClass.Where(i => i.ComeHosptialWay == "4").Count();
|
|
model.TotalFour = oneClass.Count() - (model.TotalOne + model.TotalTwo + model.TotalThree);
|
|
}
|
|
return model;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 胸痛单元病例个数统计
|
|
/// </summary>
|
|
/// <param name="hospitalGuid"></param>
|
|
/// <param name="systemId"></param>
|
|
/// <returns></returns>
|
|
public List<CaseStatisticsModel> GetCaseStatistics(string hospitalGuid, int systemId)
|
|
{
|
|
List<CaseStatisticsModel> list = new List<CaseStatisticsModel>();
|
|
CaseStatisticsModel model;
|
|
var oneCalss = db.Queryable<T_Service_Patient>().Where(i => i.HospitalGuid == hospitalGuid && i.SystemModuleID == systemId && i.DeleteFlag == 0).Select(i => new
|
|
{
|
|
CreationDate = i.CreationDate,
|
|
CCPC_State = i.CCPC_State
|
|
}).ToList();
|
|
//当天新增病例个数
|
|
int ToDayCaseCount = oneCalss.Where(i => i.CreationDate >= Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd")) && i.CreationDate < DateTime.Now.AddDays(1)).Count();
|
|
model = new CaseStatisticsModel();
|
|
model.Name = "ToDayCaseCount";
|
|
model.Count = ToDayCaseCount;
|
|
list.Add(model);
|
|
|
|
//本月新增病例个数
|
|
DateTime date = DateTime.Now;
|
|
DateTime startMonth = date.AddDays(1 - date.Day); //本月月初
|
|
DateTime endMonth = startMonth.AddMonths(1).AddDays(-1); //本月月末
|
|
int ThisMonthCount = oneCalss.Where(i => i.CreationDate >= startMonth && i.CreationDate <= endMonth).Count();
|
|
model = new CaseStatisticsModel();
|
|
model.Name = "ThisMonthCount";
|
|
model.Count = ThisMonthCount;
|
|
list.Add(model);
|
|
|
|
//本年新增病例个数
|
|
DateTime startYear = new DateTime(date.Year, 1, 1); //本年年初
|
|
DateTime endYear = new DateTime(date.Year, 12, 31); //本年年末
|
|
int ThisYear = oneCalss.Where(i => i.CreationDate >= startYear && i.CreationDate <= endYear).Count();
|
|
model = new CaseStatisticsModel();
|
|
model.Name = "ThisYear";
|
|
model.Count = ThisYear;
|
|
list.Add(model);
|
|
|
|
//累计增病例个数
|
|
int Total = oneCalss.Count();
|
|
model = new CaseStatisticsModel();
|
|
model.Name = "Total";
|
|
model.Count = Total;
|
|
list.Add(model);
|
|
|
|
//本月上报数
|
|
int ThisMothReportCount = oneCalss.Where(i => i.CreationDate >= startMonth && i.CreationDate <= endMonth && i.CCPC_State == 1).Count();
|
|
model = new CaseStatisticsModel();
|
|
model.Name = "ThisMothReportCount";
|
|
model.Count = ThisMothReportCount;
|
|
list.Add(model);
|
|
|
|
//累计上报数
|
|
int ToatlReportCount = oneCalss.Where(i => i.CCPC_State == 1).Count();
|
|
model = new CaseStatisticsModel();
|
|
model.Name = "ToatlReportCount";
|
|
model.Count = ToatlReportCount;
|
|
list.Add(model);
|
|
return list;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 首次医疗接触到首份心电图平均耗时统计查询
|
|
/// </summary>
|
|
/// <param name="hospitalGuid"></param>
|
|
/// <param name="systemId"></param>
|
|
/// <param name="startTime"></param>
|
|
/// <param name="endTime"></param>
|
|
/// <returns></returns>
|
|
public List<DateTimeAVGModel> GetFMCTOECGAVG(string hospitalGuid, int systemId, string startTime, string endTime)
|
|
{
|
|
//List<QCReportModel> QCLst = new List<QCReportModel>();
|
|
List<DateTimeAVGModel> list = new List<DateTimeAVGModel>();
|
|
List<string> lst = new List<string>();
|
|
List<DateTimeList> timeList = new List<DateTimeList>();
|
|
string sql = string.Format(@"SELECT CASE WHEN CW_Coming_Way_Code ='1' THEN CW_120_First_MC_Time
|
|
WHEN CW_Coming_Way_Code='3' THEN CW_ZXLY_First_MC_Time
|
|
WHEN CW_Coming_Way_Code='4' THEN CW_YNFB_First_MC_Time END AS [DateTimeOne] , CAST([c].[ECG_Time] AS DATETIME) AS [DateTimeTwo]
|
|
FROM [T_Service_Patient] a
|
|
Inner JOIN [T_Service_ChestPain_FirstAIDInfo] b ON ( [a].[GUID] = [b].[PatientGuid] )
|
|
Inner JOIN [T_Service_ChestPain_ECG] c ON ( [a].[GUID] = [c].[PatientGuid] )
|
|
Inner JOIN [T_Service_ChestPain_TreatmentInfo] d ON ( [a].[GUID] = [d].[PatientGuid] )
|
|
WHERE ((((((( [a].[HospitalGuid] = '{0}' )
|
|
AND ( [a].[SystemModuleID] = {1} ))
|
|
AND ( [a].[DeleteFlag] = 0 ))
|
|
AND ( [b].[Attack_Time] IS NOT NULL ))
|
|
AND ( [c].[ECG_Time] IS NOT NULL ))
|
|
AND ( [c].[FirstECG] = 1 ))
|
|
AND ( [d].[CP_Diagnosis_Code] <> '' ))
|
|
AND ( CASE WHEN CW_Coming_Way_Code ='1' THEN CW_120_First_MC_Time
|
|
WHEN CW_Coming_Way_Code='3' THEN CW_ZXLY_First_MC_Time
|
|
WHEN CW_Coming_Way_Code='4' THEN CW_YNFB_First_MC_Time END >= CAST('{2}' AS DATETIME))
|
|
AND (CASE WHEN CW_Coming_Way_Code ='1' THEN CW_120_First_MC_Time
|
|
WHEN CW_Coming_Way_Code='3' THEN CW_ZXLY_First_MC_Time
|
|
WHEN CW_Coming_Way_Code='4' THEN CW_YNFB_First_MC_Time END <= CAST('{3}' AS DATETIME))ORDER BY [b].[Attack_Time] DESC", hospitalGuid, systemId, startTime, endTime);
|
|
|
|
timeList = db.Ado.SqlQuery<DateTimeList>(sql);
|
|
|
|
|
|
//月份集合
|
|
List<DateTime> monthList = new List<DateTime>();
|
|
DateTime dt1 = DateTime.Now;
|
|
DateTime dt2 = DateTime.Now.AddMonths(-11);
|
|
|
|
if (string.IsNullOrEmpty(startTime) && string.IsNullOrEmpty(endTime) && timeList.Count > 0)
|
|
{
|
|
dt1 = timeList[0].DateTimeOne;
|
|
dt2 = timeList[timeList.Count - 1].DateTimeOne;
|
|
}
|
|
else if (!string.IsNullOrEmpty(startTime) && !string.IsNullOrEmpty(endTime))
|
|
{
|
|
dt1 = Convert.ToDateTime(endTime);
|
|
dt2 = Convert.ToDateTime(startTime);
|
|
|
|
}
|
|
int Month = (dt1.Year - dt2.Year) * 12 + (dt1.Month - dt2.Month);
|
|
for (int i = 0; i < Month + 1; i++)
|
|
{
|
|
string res = dt2.AddMonths(i).Year + "-" + GetMonthZero(dt2.AddMonths(i).Month) + "-01";
|
|
DateTime dt = Convert.ToDateTime(res);
|
|
monthList.Add(dt.AddDays(1 - dt.Day));
|
|
}
|
|
if (timeList.Count() > 0)
|
|
{
|
|
for (int i = 0; i < monthList.Count; i++)
|
|
{
|
|
// QCReportModel qcmodel = new QCReportModel();
|
|
DateTimeAVGModel model = new DateTimeAVGModel();
|
|
model.Month = monthList[i].ToString("yyyy年MM月");
|
|
//qcmodel.Month = model.Month;
|
|
double sum = 0;
|
|
int count = timeList.Where(j => j.DateTimeOne >= SqlFunc.ToDate(monthList[i]) && j.DateTimeOne <= SqlFunc.ToDate(monthList[i].AddMonths(1).ToString("yyyy-MM-dd")).AddDays(-1)).Count();
|
|
var templist = timeList.Where(j => j.DateTimeOne >= SqlFunc.ToDate(monthList[i]) && j.DateTimeOne <= SqlFunc.ToDate(monthList[i].AddMonths(1).ToString("yyyy-MM-dd")).AddDays(-1)).ToList();
|
|
List<double> timelst = new List<double>();
|
|
foreach (var item in templist)
|
|
{
|
|
double timeSum = DiffMinutes(item.DateTimeOne, item.DateTimeTwo);
|
|
timelst.Add(timeSum);
|
|
sum += timeSum;
|
|
}
|
|
if (sum != 0 && count != 0)
|
|
{
|
|
model.AVGTime = (int)(sum / (double)count);
|
|
//qcmodel.AVGTime = (int)(sum / (double)count);
|
|
}
|
|
//if (templist.Count > 0)
|
|
//{
|
|
// qcmodel.MinMum = timelst.Min().ToString();
|
|
// qcmodel.MaxMum = timelst.Max().ToString();
|
|
//}
|
|
list.Add(model);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
for (int i = 0; i < monthList.Count; i++)
|
|
{
|
|
DateTimeAVGModel model = new DateTimeAVGModel();
|
|
model.Month = monthList[i].ToString("yyyy年MM月");
|
|
list.Add(model);
|
|
}
|
|
}
|
|
return list;
|
|
}
|
|
|
|
|
|
|
|
public List<QCReportModel> GetFMCTOECGAVGList(string hospitalGuid, int systemId, string startTime, string endTime)
|
|
{
|
|
List<QCReportModel> QCLst = new List<QCReportModel>();
|
|
// List<DateTimeAVGModel> list = new List<DateTimeAVGModel>();
|
|
List<string> lst = new List<string>();
|
|
List<DateTimeList> timeList = new List<DateTimeList>();
|
|
string sql = string.Format(@"SELECT CASE WHEN CW_Coming_Way_Code ='1' THEN CW_120_First_MC_Time
|
|
WHEN CW_Coming_Way_Code='3' THEN CW_ZXLY_First_MC_Time
|
|
WHEN CW_Coming_Way_Code='4' THEN CW_YNFB_First_MC_Time END AS [DateTimeOne] , CAST([c].[ECG_Time] AS DATETIME) AS [DateTimeTwo] ,
|
|
CASE WHEN CW_Coming_Way_Code ='1' THEN DATEDIFF(MINUTE, CW_120_First_MC_Time, [ECG_Time])
|
|
WHEN CW_Coming_Way_Code='3' THEN DATEDIFF(MINUTE, CW_ZXLY_First_MC_Time, [ECG_Time])
|
|
WHEN CW_Coming_Way_Code='4' THEN DATEDIFF(MINUTE, CW_YNFB_First_MC_Time, [ECG_Time]) END AS MinutesDiff
|
|
FROM [T_Service_Patient] a
|
|
Inner JOIN [T_Service_ChestPain_FirstAIDInfo] b ON ( [a].[GUID] = [b].[PatientGuid] )
|
|
Inner JOIN [T_Service_ChestPain_ECG] c ON ( [a].[GUID] = [c].[PatientGuid] )
|
|
Inner JOIN [T_Service_ChestPain_TreatmentInfo] d ON ( [a].[GUID] = [d].[PatientGuid] )
|
|
WHERE ((((((( [a].[HospitalGuid] = '{0}' )
|
|
AND ( [a].[SystemModuleID] = {1} ))
|
|
AND ( [a].[DeleteFlag] = 0 ))
|
|
AND ( [b].[Attack_Time] IS NOT NULL ))
|
|
AND ( [c].[ECG_Time] IS NOT NULL ))
|
|
AND ( [c].[FirstECG] = 1 ))
|
|
AND ( [d].[CP_Diagnosis_Code] <> '' ))
|
|
AND ( CASE WHEN CW_Coming_Way_Code ='1' THEN CW_120_First_MC_Time
|
|
WHEN CW_Coming_Way_Code='3' THEN CW_ZXLY_First_MC_Time
|
|
WHEN CW_Coming_Way_Code='4' THEN CW_YNFB_First_MC_Time END >= CAST('{2}' AS DATETIME))
|
|
AND (CASE WHEN CW_Coming_Way_Code ='1' THEN CW_120_First_MC_Time
|
|
WHEN CW_Coming_Way_Code='3' THEN CW_ZXLY_First_MC_Time
|
|
WHEN CW_Coming_Way_Code='4' THEN CW_YNFB_First_MC_Time END <= CAST('{3}' AS DATETIME))ORDER BY [b].[Attack_Time] DESC", hospitalGuid, systemId, startTime, endTime);
|
|
|
|
timeList = db.Ado.SqlQuery<DateTimeList>(sql);
|
|
|
|
|
|
//月份集合
|
|
List<DateTime> monthList = new List<DateTime>();
|
|
DateTime dt1 = Convert.ToDateTime(startTime);
|
|
DateTime dt2 = Convert.ToDateTime(endTime);
|
|
|
|
if (string.IsNullOrEmpty(startTime) && string.IsNullOrEmpty(endTime) && timeList.Count > 0)
|
|
{
|
|
dt1 = timeList[0].DateTimeOne;
|
|
dt2 = timeList[timeList.Count - 1].DateTimeOne;
|
|
}
|
|
else if (!string.IsNullOrEmpty(startTime) && !string.IsNullOrEmpty(endTime))
|
|
{
|
|
dt1 = Convert.ToDateTime(endTime);
|
|
dt2 = Convert.ToDateTime(startTime);
|
|
|
|
}
|
|
int Month = (dt1.Year - dt2.Year) * 12 + (dt1.Month - dt2.Month);
|
|
for (int i = 0; i < Month + 1; i++)
|
|
{
|
|
string res = dt2.AddMonths(i).Year + "-" + GetMonthZero(dt2.AddMonths(i).Month) + "-01";
|
|
DateTime dt = Convert.ToDateTime(res);
|
|
monthList.Add(dt.AddDays(1 - dt.Day));
|
|
}
|
|
if (timeList.Count() > 0)
|
|
{
|
|
for (int i = 0; i < monthList.Count; i++)
|
|
{
|
|
QCReportModel qcmodel = new QCReportModel();
|
|
qcmodel.Month = monthList[i].ToString("yyyy年MM月");
|
|
int qualified = timeList.Where(j => j.DateTimeOne >= SqlFunc.ToDate(monthList[i]) && j.DateTimeOne < SqlFunc.ToDate(monthList[i].AddMonths(1).ToString("yyyy-MM-dd")).AddDays(-1) && j.MinutesDiff <= 10).Count();
|
|
if (qualified >= 0)
|
|
qcmodel.QualifiedCount = qualified.ToString();
|
|
double sum = 0;
|
|
int count = timeList.Where(j => j.DateTimeOne >= SqlFunc.ToDate(monthList[i]) && j.DateTimeOne < SqlFunc.ToDate(monthList[i].AddMonths(1).ToString("yyyy-MM-dd")).AddDays(-1)).Count();
|
|
var templist = timeList.Where(j => j.DateTimeOne >= SqlFunc.ToDate(monthList[i]) && j.DateTimeOne < SqlFunc.ToDate(monthList[i].AddMonths(1).ToString("yyyy-MM-dd")).AddDays(-1)).ToList();
|
|
List<double> timelst = new List<double>();
|
|
foreach (var item in templist)
|
|
{
|
|
double timeSum = DiffMinutes(item.DateTimeOne, item.DateTimeTwo);
|
|
timelst.Add(timeSum);
|
|
sum += timeSum;
|
|
}
|
|
if (sum != 0 && count != 0)
|
|
{
|
|
qcmodel.AVGTime = (int)(sum / (double)count);
|
|
}
|
|
if (templist.Count > 0)
|
|
{
|
|
qcmodel.MinMum = timelst.Min().ToString();
|
|
qcmodel.MaxMum = timelst.Max().ToString();
|
|
}
|
|
QCLst.Add(qcmodel);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
for (int i = 0; i < monthList.Count; i++)
|
|
{
|
|
QCReportModel model = new QCReportModel();
|
|
model.Month = monthList[i].ToString("yyyy年MM月");
|
|
QCLst.Add(model);
|
|
}
|
|
}
|
|
return QCLst;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 肌钙蛋白抽血完成至出报告时间统计
|
|
/// </summary>
|
|
/// <param name="hospitalGuid"></param>
|
|
/// <param name="systemId"></param>
|
|
/// <param name="startTime"></param>
|
|
/// <param name="endTime"></param>
|
|
/// <returns></returns>
|
|
public List<DateTimeAVGModel> GetTroponinAVG(string hospitalGuid, int systemId, string startTime, string endTime)
|
|
{
|
|
List<DateTimeAVGModel> list = new List<DateTimeAVGModel>();
|
|
List<string> lst = new List<string>();
|
|
|
|
List<DateTimeList> timeList = new List<DateTimeList>();
|
|
timeList = db.Queryable<T_Service_Patient, T_Service_ChestPain_CTNT>((a, b) => new JoinQueryInfos(
|
|
JoinType.Inner, a.GUID == b.PatientGuid))
|
|
.Where((a, b) => a.HospitalGuid == hospitalGuid && a.SystemModuleID == systemId && a.DeleteFlag == 0 && b.Blood_Time != null && b.Report_Time != null)
|
|
.WhereIF(!SqlFunc.IsNullOrEmpty(startTime), (a, b) => b.Blood_Time >= SqlFunc.ToDate(startTime))
|
|
.WhereIF(!SqlFunc.IsNullOrEmpty(endTime), (a, b) => b.Blood_Time < SqlFunc.ToDate(endTime))
|
|
.Select((a, b) => new DateTimeList()
|
|
{
|
|
DateTimeOne = SqlFunc.ToDate(b.Blood_Time),
|
|
DateTimeTwo = SqlFunc.ToDate(b.Report_Time)
|
|
}).ToList();
|
|
List<DateTime> monthList = new List<DateTime>();
|
|
DateTime dt1 = DateTime.Now;
|
|
DateTime dt2 = DateTime.Now.AddMonths(-11);
|
|
|
|
if (string.IsNullOrEmpty(startTime) && string.IsNullOrEmpty(endTime) && timeList.Count > 0)
|
|
{
|
|
dt1 = timeList[0].DateTimeOne;
|
|
dt2 = timeList[timeList.Count - 1].DateTimeOne;
|
|
}
|
|
else if (!string.IsNullOrEmpty(startTime) && !string.IsNullOrEmpty(endTime))
|
|
{
|
|
dt1 = Convert.ToDateTime(endTime);
|
|
dt2 = Convert.ToDateTime(startTime);
|
|
|
|
}
|
|
int Month = (dt1.Year - dt2.Year) * 12 + (dt1.Month - dt2.Month);
|
|
for (int i = 0; i < Month + 1; i++)
|
|
{
|
|
string res = dt2.AddMonths(i).Year + "-" + GetMonthZero(dt2.AddMonths(i).Month) + "-01";
|
|
DateTime dt = Convert.ToDateTime(res);
|
|
monthList.Add(dt.AddDays(1 - dt.Day));
|
|
}
|
|
if (timeList.Count() > 0)
|
|
{
|
|
for (int i = 0; i < monthList.Count; i++)
|
|
{
|
|
DateTimeAVGModel model = new DateTimeAVGModel();
|
|
model.Month = monthList[i].ToString("yyyy年MM月");
|
|
int qualified = timeList.Where(j => j.DateTimeOne >= SqlFunc.ToDate(monthList[i]) && j.DateTimeOne < SqlFunc.ToDate(monthList[i].AddMonths(1).ToString("yyyy-MM-dd")).AddDays(-1) && j.MinutesDiff <= 20).Count();
|
|
if (qualified >= 0)
|
|
model.QualifiedCount = qualified.ToString();
|
|
double sum = 0;
|
|
int count = timeList.Where(j => j.DateTimeOne >= SqlFunc.ToDate(monthList[i]) && j.DateTimeOne <= SqlFunc.ToDate(monthList[i].AddMonths(1)).AddDays(-1)).Count();
|
|
var templist = timeList.Where(j => j.DateTimeOne >= SqlFunc.ToDate(monthList[i]) && j.DateTimeOne <= SqlFunc.ToDate(monthList[i].AddMonths(1)).AddDays(-1)).ToList();
|
|
List<double> timelst = new List<double>();
|
|
foreach (var item in templist)
|
|
{
|
|
timelst.Add(DiffMinutes(item.DateTimeOne, item.DateTimeTwo));
|
|
sum += DiffMinutes(item.DateTimeOne, item.DateTimeTwo);
|
|
}
|
|
if (sum != 0 && count != 0)
|
|
{
|
|
model.AVGTime = (int)(sum / (double)count);
|
|
}
|
|
if (templist.Count > 0)
|
|
{
|
|
model.MinMum = timelst.Min().ToString();
|
|
model.MaxMum = timelst.Max().ToString();
|
|
}
|
|
list.Add(model);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
for (int i = 0; i < monthList.Count; i++)
|
|
{
|
|
DateTimeAVGModel model = new DateTimeAVGModel();
|
|
model.Month = monthList[i].ToString("yyyy年MM月");
|
|
list.Add(model);
|
|
}
|
|
}
|
|
return list;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 计算月份
|
|
/// </summary>
|
|
/// <param name="month"></param>
|
|
/// <returns></returns>
|
|
public string GetMonthZero(int month)
|
|
{
|
|
if (month < 10)
|
|
{
|
|
return "0" + month;
|
|
}
|
|
else
|
|
{
|
|
return month.ToString();
|
|
}
|
|
}
|
|
|
|
public double DiffMinutes(DateTime startTime, DateTime endTime)
|
|
{
|
|
TimeSpan minuteSpan = new TimeSpan(endTime.Ticks - startTime.Ticks);
|
|
return minuteSpan.TotalMinutes;
|
|
}
|
|
|
|
}
|
|
|
|
public class DateTimeList
|
|
{
|
|
public DateTime DateTimeOne { get; set; }
|
|
public DateTime DateTimeTwo { get; set; }
|
|
public int MinutesDiff { get; set; }
|
|
}
|
|
}
|