189 lines
9.2 KiB
C#
189 lines
9.2 KiB
C#
|
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();
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 增加一条数据
|
|||
|
/// </summary>
|
|||
|
public bool Add(T_Service_FollowUp_Apoplexy model)
|
|||
|
{
|
|||
|
return db.Insertable(model).ExecuteCommand() == 0 ? false : true;
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 更新一条数据
|
|||
|
/// </summary>
|
|||
|
public bool Update(T_Service_FollowUp_Apoplexy model)
|
|||
|
{
|
|||
|
return db.Updateable(model).ExecuteCommand() == 0 ? false : true;
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 删除一条数据
|
|||
|
/// </summary>
|
|||
|
public bool Delete(long ID)
|
|||
|
{
|
|||
|
return db.Deleteable<T_Service_FollowUp_Apoplexy>(it => it.ID == ID).ExecuteCommand() == 0 ? false : true; ;
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 获得数据列表
|
|||
|
/// </summary>
|
|||
|
public TableModel<T_Service_FollowUp_Apoplexy> GetPageList(int pageIndex, int pageSize)
|
|||
|
{
|
|||
|
int total = 0;
|
|||
|
List<T_Service_FollowUp_Apoplexy> data = db.Queryable<T_Service_FollowUp_Apoplexy>().Where(it => it.DeleteFlag == 0).ToPageList(pageIndex, pageSize, ref total);
|
|||
|
TableModel<T_Service_FollowUp_Apoplexy> t = new TableModel<T_Service_FollowUp_Apoplexy>();
|
|||
|
t.Code = 0;
|
|||
|
t.PageCount = data.Count;
|
|||
|
t.TotalNumber = total;
|
|||
|
t.Data = data;
|
|||
|
t.Msg = "成功";
|
|||
|
return t;
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
/// 根据病人ID获取随访记录
|
|||
|
/// </summary>
|
|||
|
/// <param name="pageIndex"></param>
|
|||
|
/// <param name="pageSize"></param>
|
|||
|
/// <param name="pGuid"></param>
|
|||
|
/// <returns></returns>
|
|||
|
public TableModel<T_Service_FollowUp_Apoplexy> GetPageList(int pageIndex, int pageSize, string pGuid)
|
|||
|
{
|
|||
|
List<T_Service_FollowUp_Apoplexy> data = db.Queryable<T_Service_FollowUp_Apoplexy>().Where(FollowUp => FollowUp.PatientGuid == pGuid && FollowUp.DeleteFlag == 0).OrderBy(FollowUp => FollowUp.FollowUpDate, OrderByType.Asc).ToPageList(pageIndex, pageSize);
|
|||
|
TableModel<T_Service_FollowUp_Apoplexy> t = new TableModel<T_Service_FollowUp_Apoplexy>();
|
|||
|
t.Code = 0;
|
|||
|
t.PageCount = data.Count;
|
|||
|
t.TotalNumber = data.Count;
|
|||
|
t.Data = data;
|
|||
|
t.Msg = "成功";
|
|||
|
return t;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
public TableModel<T_Service_FollowUp_Apoplexy_Patient> GetModelByFollowUp(string key, string startTime, string endTime, int state, int pageIndex, int pageSize, long SystemModuleID, string hospitalGuid)
|
|||
|
{
|
|||
|
int TotalNumber = 0;
|
|||
|
List<T_Service_FollowUp_Apoplexy_Patient> data = new List<T_Service_FollowUp_Apoplexy_Patient>();
|
|||
|
|
|||
|
data = db.Queryable<T_Service_Patient, T_Service_FollowUp_Apoplexy, T_Base_Gender>
|
|||
|
((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<T_Service_FollowUp_Apoplexy_Patient>(sql);
|
|||
|
|
|||
|
TableModel<T_Service_FollowUp_Apoplexy_Patient> t = new TableModel<T_Service_FollowUp_Apoplexy_Patient>();
|
|||
|
|
|||
|
t.Code = 0;
|
|||
|
t.PageCount = data.Count;
|
|||
|
t.TotalNumber = TotalNumber;
|
|||
|
t.Data = data;
|
|||
|
t.Msg = "成功";
|
|||
|
return t;
|
|||
|
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
/// 获得前几行数据
|
|||
|
/// </summary>
|
|||
|
public T_Service_FollowUp_Apoplexy Get(string ID)
|
|||
|
{
|
|||
|
return db.Queryable<T_Service_FollowUp_Apoplexy>().First(it => it.ID.ToString() == ID);
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 查询卒中患者详情
|
|||
|
/// </summary>
|
|||
|
/// <param name="pGuid"></param>
|
|||
|
/// <param name="followDate"></param>
|
|||
|
/// <returns></returns>
|
|||
|
public T_Service_FollowUp_Apoplexy GetApoplexyPatientDetail(string pGuid, DateTime followDate)
|
|||
|
{
|
|||
|
T_Service_FollowUp_Apoplexy apoplexy = new T_Service_FollowUp_Apoplexy();
|
|||
|
apoplexy = db.Queryable<T_Service_FollowUp_Apoplexy>()
|
|||
|
.Where(it => it.PatientGuid == pGuid && it.FollowUpDate.Date == followDate.Date).First();
|
|||
|
return apoplexy;
|
|||
|
}
|
|||
|
|
|||
|
///<summary>
|
|||
|
///修改卒中患者详情
|
|||
|
/// </summary>
|
|||
|
/// <param name="model"></param>
|
|||
|
/// <returns></returns>
|
|||
|
public bool UpdateFollowUp_Apoplexy(T_Service_FollowUp_Apoplexy model)
|
|||
|
{
|
|||
|
var date = db.Queryable<T_Service_FollowUp_Apoplexy>()
|
|||
|
.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;
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
}
|