269 lines
13 KiB
C#
269 lines
13 KiB
C#
using HL_FristAidPlatform_Help;
|
||
using HL_FristAidPlatform_IDataBase;
|
||
using HL_FristAidPlatform_Models;
|
||
using Newtonsoft.Json;
|
||
using SqlSugar;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Data;
|
||
|
||
namespace HL_FristAidPlatform_DataBase
|
||
{
|
||
public class T_Service_Trauma_PatientsTimeAxisDB : BaseDB, IT_Service_Trauma_PatientsTimeAxis
|
||
{
|
||
public SqlSugarClient db = GetClient();
|
||
|
||
#region 增
|
||
/// <summary>
|
||
/// 批量新增 根据病人编号新增所有时间节点业务记录
|
||
/// </summary>
|
||
/// <param name="model">必须传病人编号+所属系统模块编号</param>
|
||
/// <returns></returns>
|
||
public bool Add(T_Service_Trauma_PatientsTimeAxis model)
|
||
{
|
||
//增加对应模块的时间节点记录业务 且排除已存在的记录
|
||
string Url = string.Format("SELECT ID FROM T_Base_TimeAxis WHERE SystemModuleID={0} AND DeleteFlag=0 AND ID NOT IN(SELECT TimeAxisID FROM T_Service_Trauma_PatientsTimeAxis WHERE PatientGuid='{1}' AND DeleteFlag=0) ORDER BY OrderBy", model.SystemModuleID, model.PatientGuid);
|
||
DataTable dataTable = db.Ado.GetDataTable(Url);
|
||
|
||
int number = 0;
|
||
if (dataTable.Rows.Count > 0)
|
||
{
|
||
foreach (DataRow item in dataTable.Rows)
|
||
{
|
||
T_Service_Trauma_PatientsTimeAxis InsertModel = new T_Service_Trauma_PatientsTimeAxis();
|
||
InsertModel.PatientGuid = model.PatientGuid;
|
||
InsertModel.SystemModuleID = model.SystemModuleID;
|
||
InsertModel.TimeAxisID = Convert.ToInt32(item["ID"] + "");
|
||
number = db.Insertable(InsertModel).InsertColumns(it => new { it.PatientGuid, it.TimeAxisID, it.SystemModuleID }).ExecuteReturnIdentity();
|
||
}
|
||
}
|
||
|
||
return number > 0 ? true : false;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 直接新增有值的数据
|
||
/// </summary>
|
||
/// <param name="model"></param>
|
||
/// <returns></returns>
|
||
public bool DirectAdd(T_Service_Trauma_PatientsTimeAxis model)
|
||
{
|
||
return db.Insertable(model).ExecuteCommand() == 0 ? false : true;
|
||
}
|
||
#endregion
|
||
|
||
#region 删
|
||
public bool Dels(string GUID)
|
||
{
|
||
return db.Deleteable<T_Service_Trauma_PatientsTimeAxis>().Where(it => it.GUID == GUID).ExecuteCommand() == 0 ? false : true;
|
||
}
|
||
#endregion
|
||
|
||
#region 改
|
||
public bool Update(T_Service_Trauma_PatientsTimeAxis menu)
|
||
{
|
||
return db.Updateable(menu).ExecuteCommand() == 0 ? false : true;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 根据病人编号和时间节点编号更改记录时间
|
||
/// 用于快速扫码记录
|
||
/// </summary>
|
||
/// <param name="patientGuid">病人编号</param>
|
||
/// <param name="timeAxisID">时间节点编号</param>
|
||
/// <param name="recordingTime">操作时间</param>
|
||
/// <returns></returns>
|
||
public bool UpdateRecordingTimeByPatientIDAndTimeAxisID(string patientGuid, long timeAxisID, DateTime recordingTime)
|
||
{
|
||
int InfluenceNumber = db.Updateable<T_Service_Trauma_PatientsTimeAxis>().SetColumns(it => new T_Service_Trauma_PatientsTimeAxis() { RecordingTime = recordingTime }).Where(it => it.PatientGuid == patientGuid && it.TimeAxisID == timeAxisID).ExecuteCommand();
|
||
|
||
return InfluenceNumber > 0 ? true : false;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 根据病人编号和时间节点编号更改参考正常时间
|
||
/// </summary>
|
||
/// <param name="patientGuid">病人编号</param>
|
||
/// <param name="timeAxisID"></param>
|
||
/// <param name="normalTime"></param>
|
||
/// <returns></returns>
|
||
public bool UpdateNormalTime(string patientGuid, long timeAxisID, DateTime normalTime)
|
||
{
|
||
int InfluenceNumber = db.Updateable<T_Service_Trauma_PatientsTimeAxis>().SetColumns(it => new T_Service_Trauma_PatientsTimeAxis() { NormalTime = normalTime }).Where(it => it.PatientGuid == patientGuid && it.TimeAxisID == timeAxisID).ExecuteCommand();
|
||
return InfluenceNumber > 0 ? true : false;
|
||
}
|
||
#endregion
|
||
|
||
#region 查
|
||
public T_Service_Trauma_PatientsTimeAxis Get(long ID)
|
||
{
|
||
return db.Queryable<T_Service_Trauma_PatientsTimeAxis>().First(it => it.ID == ID);
|
||
}
|
||
|
||
public TableModel<T_Service_Trauma_PatientsTimeAxis> GetPageList(int pageIndex, int pageSize)
|
||
{
|
||
int total = 0;
|
||
List<T_Service_Trauma_PatientsTimeAxis> data = db.Queryable<T_Service_Trauma_PatientsTimeAxis>().ToPageList(pageIndex, pageSize, ref total);
|
||
TableModel<T_Service_Trauma_PatientsTimeAxis> t = new TableModel<T_Service_Trauma_PatientsTimeAxis>();
|
||
t.Code = 0;
|
||
t.PageCount = data.Count;
|
||
t.TotalNumber = total;
|
||
t.Data = data;
|
||
t.Msg = "成功";
|
||
return t;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取患者列表--动态时间节点列
|
||
/// </summary>
|
||
/// <param name="pageIndex">起始页</param>
|
||
/// <param name="pageSize">每页大小</param>
|
||
/// <param name="hospitalGuid">所属院区GUID</param>
|
||
/// <param name="systemModuleID">所属模块ID</param>
|
||
/// <param name="startTime">开始时间(创建)</param>
|
||
/// <param name="endTime">结束时间(创建)</param>
|
||
/// <param name="emergencyState">急救状态:-1全部 0未结束(对应急救中0+住院中1) 1已结束(对应已转归2)</param>
|
||
/// <param name="hospitalMode">来院方式代码 0:未选择;参考字典表T_Base_HospitalMode</param>
|
||
/// <param name="vehicleout_Unit">出车单位代码0:未选择;1:120救护车;2:本院救护车;3:外院救护车</param>
|
||
/// <param name="preliminaryDiagnosis">初步诊断0:未选择,参考字典表T_Base_PreliminaryDiagnosis</param>
|
||
/// <param name="keyWord">关键词</param>
|
||
/// <returns></returns>
|
||
public TableModel<ViewModel_PatientsList> GetPatientsTime(int pageIndex, int pageSize, string hospitalGuid, long systemModuleID, string startTime, string endTime, int state, int hospitalMode, int vehicleoutUnit, int preliminaryDiagnosis, string keyWord)
|
||
{
|
||
int TotalNumber = 0;
|
||
TableModel<ViewModel_PatientsList> t = new TableModel<ViewModel_PatientsList>();
|
||
|
||
var listMode = db.Queryable<T_Service_Patient, T_Service_Trauma_Prehospital, T_Base_Gender, T_Base_Hospital, T_Base_WristStrap, T_Base_HospitalMode>((a, b, c, d, e, f) => new object[] {
|
||
JoinType.Left,a.GUID == b.PatientGuid,
|
||
JoinType.Left,a.Gender == c.GenderCode,
|
||
JoinType.Left,a.HospitalGuid == d.GUID,
|
||
JoinType.Left,a.WristStrapID == e.ID,
|
||
JoinType.Left,b.HospitalMode.ToString() == f.Value,
|
||
}).Where((a, b, c, d, e, f) => SqlFunc.Between(a.RegisterTime, startTime, endTime) & a.SystemModuleID == systemModuleID & a.DeleteFlag == 0)
|
||
.WhereIF(!string.IsNullOrEmpty(hospitalGuid), (a, b, c, d, e, f) => a.HospitalGuid == hospitalGuid)
|
||
.WhereIF(state == 0, (a, b, c, d, e, f) => a.EmergencyState == 0 || a.EmergencyState == 1)
|
||
.WhereIF(state == 1, (a, b, c, d, e, f) => a.EmergencyState == 2)
|
||
.WhereIF(!string.IsNullOrEmpty(keyWord), (a, b, c, d, e, f) => a.Name.Contains(keyWord) || a.PymCode.Contains(keyWord) || a.WbmCode.Contains(keyWord) || a.CustomCode.Contains(keyWord) || a.MobilePhone.Contains(keyWord) || a.IdentityCard.Contains(keyWord) || a.Address.Contains(keyWord) || a.OutpatientNumber.Contains(keyWord) || a.AdmissionNumber.Contains(keyWord) || e.Code.Contains(keyWord))
|
||
.Select((a, b, c, d, e, f) => new ViewModel_PatientsList
|
||
{
|
||
ID = a.ID,
|
||
GUID = a.GUID,
|
||
Name = a.Name,
|
||
Gender = a.Gender,
|
||
GenderName = c.GenderName,
|
||
Age = a.Age,
|
||
EmergencyState = a.EmergencyState,
|
||
EmergencyStateCase = a.EmergencyState.ToString(),
|
||
MobilePhone = a.MobilePhone,
|
||
IdentityCard = a.IdentityCard,
|
||
Address = a.Address,
|
||
Attack_Address = a.Attack_Address,
|
||
OutpatientNumber = a.OutpatientNumber,
|
||
AdmissionNumber = a.AdmissionNumber,
|
||
HospitalModeName = f.Content,
|
||
RegisterTime = a.RegisterTime,
|
||
HospitalGuid = a.HospitalGuid,
|
||
HospitalName = d.Name,
|
||
WristStrapCode = e.Code,
|
||
WristStrapCodeAlias = e.Alias,
|
||
Vehicleout_Unit = b.Vehicleout_Unit.ToString(),
|
||
PymCode = a.PymCode,
|
||
WbmCode = a.WbmCode,
|
||
CustomCode = a.CustomCode,
|
||
}).OrderBy((a) => a.ID, OrderByType.Desc).ToPageList(pageIndex, pageSize, ref TotalNumber);
|
||
|
||
t.Code = 0;
|
||
t.PageCount = listMode.Count;
|
||
t.TotalNumber = TotalNumber;
|
||
t.Data = listMode;
|
||
t.Msg = "成功";
|
||
return t;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 根据病人编号获取所有记录节点时间
|
||
/// </summary>
|
||
/// <param name="patientGuid">病人编号</param>
|
||
/// <param name="isDisplayTimeAxis">是否显示到时间轴0是1否</param>
|
||
/// <returns></returns>
|
||
public string GetPatientDetailTime(string patientGuid, int isDisplayTimeAxis)
|
||
{
|
||
string SqlStr = @"SELECT c.ID,a.[GUID],a.Name,a.Age,a.Gender,c.TimeName,b.RecordingTime,c.Interval,c.ParentID,c.OrderBy,b.NormalTime,c.LocationX,c.LocationY,c.ContrastTimeAxisID,c.Describe
|
||
FROM dbo.T_Service_Patient a
|
||
LEFT JOIN T_Service_Trauma_PatientsTimeAxis b on a.GUID = b.PatientGuid
|
||
LEFT JOIN T_Base_TimeAxis c on b.TimeAxisID = c.ID
|
||
WHERE a.GUID = '{0}' {1} AND a.DeleteFlag=0 AND b.DeleteFlag=0 AND c.DeleteFlag=0 ORDER BY c.OrderBy";
|
||
|
||
string whereStr = "";
|
||
if (isDisplayTimeAxis != -1)
|
||
{
|
||
whereStr = " AND c.IsDisplayTimeAxis = " + isDisplayTimeAxis;
|
||
}
|
||
SqlStr = string.Format(SqlStr, patientGuid, whereStr);
|
||
DataTable dt = db.Ado.GetDataTable(SqlStr);
|
||
string items = "";
|
||
|
||
foreach (DataRow item in dt.Rows)
|
||
{
|
||
string row = "";
|
||
for (int i = 0; i < dt.Columns.Count; i++)
|
||
{
|
||
row += JsonConvert.SerializeObject(dt.Columns[i].ColumnName) + ":";
|
||
row += JsonConvert.SerializeObject(item[i]) + ",";
|
||
}
|
||
row = row.Remove(row.Length - 1);
|
||
items += "{" + row + "}" + ",";
|
||
|
||
}
|
||
items = items.Remove(items.Length - 1);
|
||
items = "[" + items + "]";
|
||
return items;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 根据病人编号+时间节点标识 获取记录时间
|
||
/// </summary>
|
||
/// <param name="patientGuid">病人编号</param>
|
||
/// <param name="timeAxisID">时间节点编号:-1查询该病人的全部节点</param>
|
||
/// <returns></returns>
|
||
public TableModel<T_Service_Trauma_PatientsTimeAxis> GetRecordingTime(string patientGuid, long timeAxisID)
|
||
{
|
||
TableModel<T_Service_Trauma_PatientsTimeAxis> t = new TableModel<T_Service_Trauma_PatientsTimeAxis>();
|
||
|
||
var listMode = db.Queryable<T_Service_Trauma_PatientsTimeAxis>().Where(it => it.PatientGuid == patientGuid && it.DeleteFlag == 0).WhereIF(timeAxisID > 0, it => it.TimeAxisID == timeAxisID)
|
||
.Select(it => new T_Service_Trauma_PatientsTimeAxis
|
||
{
|
||
ID = it.ID,
|
||
GUID = it.GUID.ToString(),
|
||
PatientGuid = it.PatientGuid,
|
||
TimeAxisID = it.TimeAxisID,
|
||
DeleteFlag = it.DeleteFlag,
|
||
RecordingTime = it.RecordingTime,
|
||
NormalTime = it.NormalTime
|
||
}).OrderBy((it) => it.RecordingTime).ToList();
|
||
|
||
t.Code = 0;
|
||
t.PageCount = listMode.Count;
|
||
t.TotalNumber = listMode.Count;
|
||
t.Data = listMode;
|
||
t.Msg = "成功";
|
||
return t;
|
||
}
|
||
|
||
public TableModel<T_Service_Trauma_PatientsTimeAxis> GetModelByReport(string where)
|
||
{
|
||
string sql = "SELECT * FROM T_Service_Trauma_PatientsTimeAxis WHERE DeleteFlag=0 and " + where + "";
|
||
List<T_Service_Trauma_PatientsTimeAxis> data = db.Ado.SqlQuery<T_Service_Trauma_PatientsTimeAxis>(sql);
|
||
TableModel<T_Service_Trauma_PatientsTimeAxis> t = new TableModel<T_Service_Trauma_PatientsTimeAxis>();
|
||
t.Code = 0;
|
||
t.PageCount = data.Count;
|
||
t.TotalNumber = data.Count;
|
||
t.Data = data;
|
||
t.Msg = "成功";
|
||
return t;
|
||
}
|
||
|
||
|
||
#endregion
|
||
}
|
||
} |