using HL_FristAidPlatform_Help; using HL_FristAidPlatform_IDataBase; using HL_FristAidPlatform_Models; using SqlSugar; using System; using System.Collections.Generic; namespace HL_FristAidPlatform_DataBase { //T_Service_FollowUp_Apoplexy public class T_Service_FollowUp_ApoplexyDB : BaseDB, IT_Service_FollowUp_Apoplexy { public SqlSugarClient db = GetClient(); /// /// 增加一条数据 /// public bool Add(T_Service_FollowUp_Apoplexy model) { return db.Insertable(model).ExecuteCommand() == 0 ? false : true; } /// /// 更新一条数据 /// public bool Update(T_Service_FollowUp_Apoplexy 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) { List data = db.Queryable().Where(FollowUp => FollowUp.PatientGuid == pGuid && FollowUp.DeleteFlag == 0).OrderBy(FollowUp => FollowUp.FollowUpDate, OrderByType.Asc).ToPageList(pageIndex, pageSize); TableModel t = new TableModel(); t.Code = 0; t.PageCount = data.Count; t.TotalNumber = data.Count; t.Data = data; t.Msg = "成功"; return t; } public TableModel GetModelByFollowUp(string key, string startTime, string endTime, int state, int pageIndex, int pageSize, long SystemModuleID, string hospitalGuid) { int TotalNumber = 0; List data = new List(); data = db.Queryable ((Patient, FollowUp, Gender) =>// Patient.GUID == FollowUp.PatientGuid && Patient.Gender == Gender.GenderCode) 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, FollowUp.FollowUpType }) .Select((Patient, FollowUp, Gender) => new T_Service_FollowUp_Apoplexy_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, FollowUpType = FollowUp.FollowUpType, }).ToPageList(pageIndex, pageSize, ref TotalNumber); //string where = " "; //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] AS[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); 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_Apoplexy Get(string ID) { return db.Queryable().First(it => it.ID.ToString() == ID); } /// /// 查询卒中患者详情 /// /// /// /// public T_Service_FollowUp_Apoplexy GetApoplexyPatientDetail(string pGuid, DateTime followDate) { T_Service_FollowUp_Apoplexy apoplexy = new T_Service_FollowUp_Apoplexy(); apoplexy = db.Queryable() .Where(it => it.PatientGuid == pGuid && it.FollowUpDate.Date == followDate.Date).First(); return apoplexy; } /// ///修改卒中患者详情 /// /// /// public bool UpdateFollowUp_Apoplexy(T_Service_FollowUp_Apoplexy model) { var date = db.Queryable() .Where(it => it.PatientGuid == model.PatientGuid && it.FollowUpDate.Date == model.FollowUpDate.Date).First(); model.ID = date.ID; model.GUID = date.GUID; return db.Updateable(model).ExecuteCommand() == 0 ? false : true; } } }