using HL_FristAidPlatform_Help; using HL_FristAidPlatform_IDataBase; using HL_FristAidPlatform_Models; using SqlSugar; using System.Collections.Generic; namespace HL_FristAidPlatform_DataBase { //T_Service_FollowUp public class T_Service_FollowUpDB : BaseDB, IT_Service_FollowUp { public SqlSugarClient db = GetClient(); /// /// 增加一条数据 /// public bool Add(T_Service_FollowUp model) { return db.Insertable(model).ExecuteCommand() == 0 ? false : true; } /// /// 更新一条数据 /// public bool Update(T_Service_FollowUp model) { return db.Updateable(model).ExecuteCommand() == 0 ? false : true; } /// /// 删除一条数据 /// public bool Delete(long ID) { return db.Deleteable(it => it.ID == ID).ExecuteCommand() == 0 ? false : true; ; } /// /// 获得数据列表 /// public TableModel GetPageList(int pageIndex, int pageSize) { int total = 0; List data = db.Queryable().Where(it => it.DeleteFlag == 0).ToPageList(pageIndex, pageSize, ref total); TableModel t = new TableModel(); t.Code = 0; t.PageCount = data.Count; t.TotalNumber = total; t.Data = data; t.Msg = "成功"; return t; } /// /// 根据病人ID获取随访记录 /// /// /// /// /// public TableModel GetPageList(int pageIndex, int pageSize, string pGuid) { int TotalNumber = 0; List data = db.Queryable().Where(FollowUp => FollowUp.PatientGuid == pGuid && FollowUp.DeleteFlag == 0).OrderBy(FollowUp => FollowUp.FollowUpDate, OrderByType.Asc).ToPageList(pageIndex, pageSize, ref TotalNumber); TableModel t = new TableModel(); t.Code = 0; t.PageCount = data.Count; t.TotalNumber = TotalNumber; t.Data = data; t.Msg = "成功"; return t; } /// /// 获得前几行数据 /// public T_Service_FollowUp Get(string ID) { return db.Queryable().First(it => it.ID.ToString() == ID); } public TableModel GetModelByFollowUp(string key, string startTime, string endTime, int state, int pageIndex, int pageSize, long SystemModuleID, string hospitalGuid) { List data = new List(); string where = " "; if (string.IsNullOrEmpty(key)) { where += " AND ((([Patient].[Name] like '%'" + key + "'%') " + " OR ([Patient].[IdentityCard] like '%'" + key + "'%') ) " + " OR ([Patient].EmergencyContactPhone] like '%'" + key + "'%')) "; } if (string.IsNullOrEmpty(startTime)) { where += " AND( [Patient].[RegisterTime] >= CAST('" + startTime + "' AS DATETIME)) "; } if (string.IsNullOrEmpty(endTime)) { where += " AND( [Patient].[RegisterTime] <= CAST('" + endTime + "' AS DATETIME)) "; } if (state >= 0) { where += " AND( [Patient].[EmergencyState] = " + state + ") "; } if (SystemModuleID >= 0) { where += " AND( [Patient].[SystemModuleID]= " + SystemModuleID + " ) "; } if (string.IsNullOrEmpty(hospitalGuid)) { where += " AND( [Patient].[HospitalGuid] = '" + hospitalGuid + "' ) "; } string sql = @" SELECT * FROM (SELECT [Patient].[ID] AS[ID] , [Patient].[GUID] AS [GUID] , [Patient].[Name] AS[Name] , [Patient].[Age] AS[Age] , [Gender].[GenderName] AS[GenderString] , [Patient].[IdentityCard] AS[IdentityCard] , [Patient].[MobilePhone] AS[MobilePhone], MIN([FollowUp].[FollowUpDate]) AS[FollowUpDate] , [FollowUp]. [FollowUpStatus] [FollowUpStatus] , FollowUp.[FollowUpType] AS[FollowUpType] , ROW_NUMBER() OVER(ORDER BY GetDate()) AS RowIndex FROM[T_Service_Patient] Patient Inner JOIN[T_Service_FollowUp_Apoplexy] FollowUp ON [Patient].[GUID] = [FollowUp].[PatientGuid] Left JOIN[T_Base_Gender] Gender ON [Patient].[Gender] = [Gender].[GenderCode] WHERE FollowUp.FollowUpDate =(SELECT TOP 1 FollowUpDate FROM T_Service_FollowUp_Apoplexy WHERE [PatientGuid] = FollowUp.[PatientGuid] ORDER BY ABS(DATEDIFF(second, getdate(), FollowUpDate))) AND [Patient].[DeleteFlag] = 0 " + where + " GROUP BY[FollowUpDate],[Patient].[ID],[Patient].[GUID],[Patient].[Name],[Patient].[Age],[Gender].[GenderName], [Patient].[IdentityCard],[Patient].[MobilePhone],[FollowUp].[FollowUpStatus],[FollowUp].[FollowUpType] ) " + " T WHERE RowIndex BETWEEN " + pageIndex + " AND " + pageSize + " "; data = db.Ado.SqlQuery(sql); var total = data.Count; #region MyRegion //data = db.Queryable((Patient, FollowUp, Gender) => new object[] //{ // JoinType.Inner, Patient.GUID == FollowUp.PatientGuid, // JoinType.Left,Patient.Gender==Gender.GenderCode //}) //.WhereIF(!string.IsNullOrEmpty(key), Patient => Patient.Name.Contains(key) || Patient.IdentityCard.Contains(key) || Patient.EmergencyContactPhone.Contains(key)) //.WhereIF(!string.IsNullOrEmpty(startTime), Patient => Patient.RegisterTime >= Convert.ToDateTime(startTime)) //.WhereIF(!string.IsNullOrEmpty(endTime), Patient => Patient.RegisterTime <= Convert.ToDateTime(endTime)) //.WhereIF(!string.IsNullOrEmpty(hospitalGuid), Patient => Patient.HospitalGuid == hospitalGuid) //.Where(Patient => Patient.DeleteFlag == 0 && Patient.EmergencyState == state && Patient.SystemModuleID == SystemModuleID).GroupBy((Patient, FollowUp, Gender) => new { Patient.ID, Patient.GUID, Patient.Name, Patient.Age, Gender.GenderName, Patient.IdentityCard, Patient.MobilePhone, FollowUp.FollowUpStatus }) //.Select((Patient, FollowUp, Gender) => new T_Service_FollowUp_ChestPain_Patient //{ // ID = Patient.ID, // GUID = Patient.GUID, // Name = Patient.Name, // Age = Patient.Age, // GenderString = Gender.GenderName, // IdentityCard = Patient.IdentityCard, // MobilePhone = Patient.MobilePhone, // FollowUpDate = SqlFunc.AggregateMin(FollowUp.FollowUpDate), // FollowUpStatus = FollowUp.FollowUpStatus //}).ToPageList(pageIndex, pageSize, ref TotalNumber); #endregion TableModel t = new TableModel(); t.Code = 0; t.PageCount = data.Count; t.TotalNumber = total; t.Data = data; t.Msg = "成功"; return t; } /// /// 获得患者随访记录数据列表 /// public TableModel GetPatientFollowList(string pGuid) { int TotalNumber = 0; TableModel t = new TableModel(); var listFollowData = db.Queryable() .Where(it => it.PatientGuid == pGuid && it.DeleteFlag == 0).ToPageList(1, 100, ref TotalNumber); t.Code = 0; t.PageCount = listFollowData.Count; t.TotalNumber = TotalNumber; t.Data = listFollowData; t.Msg = "成功"; return t; } /// ///修改卒中患者详情 /// /// /// public bool UpdateFollowUp(int id) { return db.Updateable().SetColumns(it => it.FollowUpStatus == "1").Where(it => it.ID == id).ExecuteCommand() == 0 ? false : true; } } }