StableVersion4.3/HL_FristAidPlatform_DataBase/Service/T_Service_ChestPain_OutCome...

380 lines
17 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using HL_FristAidPlatform_Help;
using HL_FristAidPlatform_IDataBase;
using HL_FristAidPlatform_Models;
using SqlSugar;
using System;
using System.Collections.Generic;
namespace HL_FristAidPlatform_DataBase
{
/// <summary>
/// 患者转归 V2.1版
/// </summary>
public class T_Service_ChestPain_OutComeInfoDB : BaseDB, IT_Service_ChestPain_OutComeInfo
{
public SqlSugarClient db = GetClient();
#region 增
/// <summary>
/// 新增
/// </summary>
/// <param name="model">实体</param>
/// <returns></returns>
public bool Add(T_Service_ChestPain_OutComeInfo model)
{
if (!string.IsNullOrEmpty(model.PatientGuid))
{
var patient = db.Queryable<T_Service_Patient>().Where(i => i.GUID == model.PatientGuid).First();
if (patient != null)
{
patient.EmergencyState = 2;
db.Updateable(patient).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommand();
}
}
return db.Insertable(model).ExecuteCommand() == 0 ? false : true;
}
/// <summary>
/// 新增 仅更新赋值的字段
/// </summary>
/// <param name="model">实体类</param>
/// <returns></returns>
public bool AddNotNullColumns(T_Service_ChestPain_OutComeInfo model)
{
try
{
db.Ado.BeginTran();
db.Insertable(model).IgnoreColumns(ignoreNullColumn: true).ExecuteCommand();
if (model.CP_Diagnosis_Code == "1" || model.CP_Diagnosis_Code == "2" || model.CP_Diagnosis_Code == "3")
{
int count = db.Queryable<T_Service_ChestPain_FollowUpInfo>().Where(i => i.registerId == model.PatientGuid).Count();
if (count <= 0)
{
T_Service_ChestPain_FollowUpInfo f1 = new T_Service_ChestPain_FollowUpInfo();
f1.registerId = model.PatientGuid;
f1.month = "1";
db.Insertable(f1).IgnoreColumns(ignoreNullColumn: true).ExecuteCommand();
T_Service_ChestPain_FollowUpInfo f2 = new T_Service_ChestPain_FollowUpInfo();
f2.registerId = model.PatientGuid;
f2.month = "3";
db.Insertable(f2).IgnoreColumns(ignoreNullColumn: true).ExecuteCommand();
T_Service_ChestPain_FollowUpInfo f3 = new T_Service_ChestPain_FollowUpInfo();
f3.registerId = model.PatientGuid;
f3.month = "6";
db.Insertable(f3).IgnoreColumns(ignoreNullColumn: true).ExecuteCommand();
T_Service_ChestPain_FollowUpInfo f4 = new T_Service_ChestPain_FollowUpInfo();
f4.registerId = model.PatientGuid;
f4.month = "12";
db.Insertable(f4).IgnoreColumns(ignoreNullColumn: true).ExecuteCommand();
}
}
db.Ado.CommitTran();
return true;
}
catch (Exception ex)
{
db.Ado.RollbackTran();
Help.WriteErrorLog("患者转归AddNotNullColumns", ex.ToString());
return false;
}
}
/// <summary>
/// 新增 仅更新赋值的字段
/// 用于移动端
/// </summary>
/// <param name="model">实体类</param>
/// <returns></returns>
public bool AddForApp(T_Service_ChestPain_OutComeInfo model)
{
try
{
db.Ado.BeginTran();
db.Insertable(model).IgnoreColumns(ignoreNullColumn: true).ExecuteCommand();
if (model.CP_Diagnosis_Code == "1" || model.CP_Diagnosis_Code == "2" || model.CP_Diagnosis_Code == "3")
{
int count = db.Queryable<T_Service_ChestPain_FollowUpInfo>().Where(i => i.registerId == model.PatientGuid).Count();
if (count <= 0)
{
T_Service_ChestPain_FollowUpInfo f1 = new T_Service_ChestPain_FollowUpInfo();
f1.registerId = model.PatientGuid;
f1.month = "1";
db.Insertable(f1).IgnoreColumns(ignoreNullColumn: true).ExecuteCommand();
T_Service_ChestPain_FollowUpInfo f2 = new T_Service_ChestPain_FollowUpInfo();
f2.registerId = model.PatientGuid;
f2.month = "3";
db.Insertable(f2).IgnoreColumns(ignoreNullColumn: true).ExecuteCommand();
T_Service_ChestPain_FollowUpInfo f3 = new T_Service_ChestPain_FollowUpInfo();
f3.registerId = model.PatientGuid;
f3.month = "6";
db.Insertable(f3).IgnoreColumns(ignoreNullColumn: true).ExecuteCommand();
T_Service_ChestPain_FollowUpInfo f4 = new T_Service_ChestPain_FollowUpInfo();
f4.registerId = model.PatientGuid;
f4.month = "12";
db.Insertable(f4).IgnoreColumns(ignoreNullColumn: true).ExecuteCommand();
}
}
db.Ado.CommitTran();
return true;
}
catch (Exception ex)
{
db.Ado.RollbackTran();
Help.WriteErrorLog("患者转归AddForApp", ex.ToString());
return false;
}
}
#endregion
#region 删
/// <summary>
/// 删除一条数据
/// </summary>
public bool Delete(long ID)
{
return db.Deleteable<T_Service_ChestPain_OutComeInfo>(it => it.ID == ID).ExecuteCommand() == 0 ? false : true; ;
}
#endregion
#region 改
/// <summary>
/// 更新一条数据
/// </summary>
public bool Update(T_Service_ChestPain_OutComeInfo model)
{
return db.Updateable(model).ExecuteCommand() == 0 ? false : true;
}
/// <summary>
/// 仅更新赋值的字段
/// </summary>
/// <param name="model">实体类</param>
/// <returns></returns>
public bool UpdateNotNullColumns(T_Service_ChestPain_OutComeInfo model)
{
try
{
db.Ado.BeginTran();
T_Service_Patient patient = new T_Service_Patient();
patient = db.Queryable<T_Service_Patient>().First(i => i.GUID == model.PatientGuid);
if (patient != null)
{
T_Base_WristStrap wristStrap = new T_Base_WristStrap();
wristStrap = db.Queryable<T_Base_WristStrap>().Where(i => i.ID == patient.WristStrapID).First();
if (wristStrap != null && !SqlFunc.IsNullOrEmpty(wristStrap.GUID))
{
wristStrap.Status = 0;
wristStrap.DeleteFlag = 0;
db.Updateable(wristStrap).UpdateColumns(it => new { it.Status, it.DeleteFlag }).ExecuteCommand();
patient.WristStrapID = 0;
}
patient.EmergencyState = 2;
db.Updateable(patient).UpdateColumns(it => new { it.WristStrapID, it.EmergencyState }).ExecuteCommand();
db.Updateable(model).IgnoreColumns(ignoreAllNullColumns: false).ExecuteCommand();
}
if (!string.IsNullOrEmpty(model.CP_Diagnosis_Code))
{
int count = db.Queryable<T_Service_ChestPain_FollowUpInfo>().Where(i => i.registerId == model.PatientGuid).Count();
if (model.CP_Diagnosis_Code == "1" || model.CP_Diagnosis_Code == "2" || model.CP_Diagnosis_Code == "3")
{
if (count <= 0)
{
T_Service_ChestPain_FollowUpInfo f1 = new T_Service_ChestPain_FollowUpInfo();
f1.registerId = model.PatientGuid;
f1.month = "1";
db.Insertable(f1).IgnoreColumns(ignoreNullColumn: true).ExecuteCommand();
T_Service_ChestPain_FollowUpInfo f2 = new T_Service_ChestPain_FollowUpInfo();
f2.registerId = model.PatientGuid;
f2.month = "3";
db.Insertable(f2).IgnoreColumns(ignoreNullColumn: true).ExecuteCommand();
T_Service_ChestPain_FollowUpInfo f3 = new T_Service_ChestPain_FollowUpInfo();
f3.registerId = model.PatientGuid;
f3.month = "6";
db.Insertable(f3).IgnoreColumns(ignoreNullColumn: true).ExecuteCommand();
T_Service_ChestPain_FollowUpInfo f4 = new T_Service_ChestPain_FollowUpInfo();
f4.registerId = model.PatientGuid;
f4.month = "12";
db.Insertable(f4).IgnoreColumns(ignoreNullColumn: true).ExecuteCommand();
}
}
else
{
if (count > 0)
{
db.Deleteable<T_Service_ChestPain_FollowUpInfo>().Where(i => i.registerId == model.PatientGuid).ExecuteCommand();
}
}
}
db.Ado.CommitTran();
return true;
}
catch (Exception ex)
{
db.Ado.RollbackTran();
Help.WriteErrorLog("患者转归", ex.ToString());
return false;
}
}
public int updateTime(T_Service_ChestPain_OutComeInfo model)
{
return db.Updateable(model).UpdateColumns(i => new { i.Diagnosis_Time, i.Leave_Time, i.Hand_Time, i.Start_Radiography_Time, i.Decision_Operation_Time, i.Trans_ECG_Time, i.Transfer_Date, i.Death_Time, i.BALLOON_EXPANSION_TIME }).ExecuteCommand();
}
/// <summary>
/// 修改--仅更新赋值的字段
/// 用于移动端
/// </summary>
/// <param name="model">实体类</param>
/// <returns></returns>
public bool UpdateForApp(T_Service_ChestPain_OutComeInfo model)
{
try
{
db.Ado.BeginTran();
T_Service_Patient patient = new T_Service_Patient();
patient = db.Queryable<T_Service_Patient>().First(i => i.GUID == model.PatientGuid);
if (patient != null)
{
T_Base_WristStrap wristStrap = new T_Base_WristStrap();
wristStrap = db.Queryable<T_Base_WristStrap>().Where(i => i.ID == patient.WristStrapID).First();
if (wristStrap != null)
{
wristStrap.Status = 0;
wristStrap.DeleteFlag = 0;
db.Updateable(wristStrap).UpdateColumns(it => new { it.Status, it.DeleteFlag }).ExecuteCommand();
patient.WristStrapID = 0;
}
patient.EmergencyState = 2;
db.Updateable(patient).UpdateColumns(it => new { it.WristStrapID, it.EmergencyState }).ExecuteCommand();
}
db.Updateable(model).IgnoreColumns(ignoreAllNullColumns: false).ExecuteCommand();
if (model.CP_Diagnosis_Code == "1" || model.CP_Diagnosis_Code == "2" || model.CP_Diagnosis_Code == "3")
{
int count = db.Queryable<T_Service_ChestPain_FollowUpInfo>().Where(i => i.registerId == model.PatientGuid).Count();
if (count <= 0)
{
T_Service_ChestPain_FollowUpInfo f1 = new T_Service_ChestPain_FollowUpInfo();
f1.registerId = model.PatientGuid;
f1.month = "1";
db.Insertable(f1).IgnoreColumns(ignoreNullColumn: true).ExecuteCommand();
T_Service_ChestPain_FollowUpInfo f2 = new T_Service_ChestPain_FollowUpInfo();
f2.registerId = model.PatientGuid;
f2.month = "3";
db.Insertable(f2).IgnoreColumns(ignoreNullColumn: true).ExecuteCommand();
T_Service_ChestPain_FollowUpInfo f3 = new T_Service_ChestPain_FollowUpInfo();
f3.registerId = model.PatientGuid;
f3.month = "6";
db.Insertable(f3).IgnoreColumns(ignoreNullColumn: true).ExecuteCommand();
T_Service_ChestPain_FollowUpInfo f4 = new T_Service_ChestPain_FollowUpInfo();
f4.registerId = model.PatientGuid;
f4.month = "12";
db.Insertable(f4).IgnoreColumns(ignoreNullColumn: true).ExecuteCommand();
}
}
db.Ado.CommitTran();
return true;
}
catch (Exception ex)
{
db.Ado.RollbackTran();
Help.WriteErrorLog("患者转归", ex.ToString());
return false;
}
}
#endregion
#region 查
/// <summary>
/// 得到一个对象实体
/// </summary>
public T_Service_ChestPain_OutComeInfo GetModel(string GUID)
{
return db.Queryable<T_Service_ChestPain_OutComeInfo>().First(it => it.GUID == GUID);
}
/// <summary>
/// 得到一个对象实体
/// </summary>
public T_Service_ChestPain_OutComeInfo GetModelForUnit(string GUID)
{
return db.Queryable<T_Service_ChestPain_OutComeInfo>().First(it => it.PatientGuid == GUID);
}
/// <summary>
/// 获得前几行数据
/// </summary>
/// <param name="pageIndex">起始页</param>
/// <param name="pageSize">每页条数</param>
/// <returns></returns>
public TableModel<T_Service_ChestPain_OutComeInfo> GetPageList(int pageIndex, int pageSize)
{
int total = 0;
List<T_Service_ChestPain_OutComeInfo> data = db.Queryable<T_Service_ChestPain_OutComeInfo>().Where(it => it.DeleteFlag == 0).ToPageList(pageIndex, pageSize, ref total);
TableModel<T_Service_ChestPain_OutComeInfo> t = new TableModel<T_Service_ChestPain_OutComeInfo>();
t.Code = 0;
t.PageCount = data.Count;
t.TotalNumber = total;
t.Data = data;
t.Msg = "成功";
return t;
}
/// <summary>
/// 根据患者编号(GUID) 获取数据信息
/// </summary>
/// <param name="patientGuid">病人编号(GUID)</param>
/// <returns></returns>
public TableModel<T_Service_ChestPain_OutComeInfo> GetByPatientGuid(string patientGuid)
{
TableModel<T_Service_ChestPain_OutComeInfo> t = new TableModel<T_Service_ChestPain_OutComeInfo>();
List<T_Service_ChestPain_OutComeInfo> listMode = db.Queryable<T_Service_ChestPain_OutComeInfo>().Where(it => it.PatientGuid == patientGuid && it.DeleteFlag == 0).ToList();
t.Code = 0;
t.TotalNumber = listMode.Count;
t.Data = listMode;
t.Msg = "成功";
return t;
}
/// <summary>
/// 根据患者编号(GUID) 获取数据信息
/// </summary>
/// <param name="patientGuid">病人编号(GUID)</param>
/// <returns></returns>
public TableModel<T_Service_ChestPain_OutComeInfo> GetByPatientGuidForApp(string patientGuid)
{
TableModel<T_Service_ChestPain_OutComeInfo> t = new TableModel<T_Service_ChestPain_OutComeInfo>();
List<T_Service_ChestPain_OutComeInfo> listMode = db.Queryable<T_Service_ChestPain_OutComeInfo>().Where(it => it.PatientGuid == patientGuid && it.DeleteFlag == 0).ToList();
t.Code = 0;
t.TotalNumber = listMode.Count;
t.Data = listMode;
t.Msg = "成功";
return t;
}
#endregion
/// <summary>
/// 获取STEMI初步诊断时间
/// </summary>
/// <param name="patientGuid"></param>
/// <returns></returns>
public string GetSTEMIDiagnosisTime(string patientGuid)
{
string time = "";
var oneClass = db.Queryable<T_Service_ChestPain_TreatmentInfo>().Where(it => it.PatientGuid == patientGuid && it.DeleteFlag == 0 && !SqlFunc.IsNullOrEmpty(it.STEMI_Diagnosis_Time)).Select(it => new { STEMI_Diagnosis_Time = it.STEMI_Diagnosis_Time }).First();
if (oneClass != null)
time = Convert.ToDateTime(oneClass.STEMI_Diagnosis_Time).ToString("yyyy-MM-dd HH:mm");
return time;
}
}
}