using HL_FristAidPlatform_Help; using HL_FristAidPlatform_IDataBase; using HL_FristAidPlatform_Models; using SqlSugar; using System; using System.Collections.Generic; namespace HL_FristAidPlatform_DataBase { /// /// 患者转归 V2.1版 /// public class T_Service_ChestPain_OutComeInfoDB : BaseDB, IT_Service_ChestPain_OutComeInfo { public SqlSugarClient db = GetClient(); #region 增 /// /// 新增 /// /// 实体 /// public bool Add(T_Service_ChestPain_OutComeInfo model) { if (!string.IsNullOrEmpty(model.PatientGuid)) { var patient = db.Queryable().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; } /// /// 新增 仅更新赋值的字段 /// /// 实体类 /// 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().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; } } /// /// 新增 仅更新赋值的字段 /// 用于移动端 /// /// 实体类 /// 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().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 删 /// /// 删除一条数据 /// public bool Delete(long ID) { return db.Deleteable(it => it.ID == ID).ExecuteCommand() == 0 ? false : true; ; } #endregion #region 改 /// /// 更新一条数据 /// public bool Update(T_Service_ChestPain_OutComeInfo model) { return db.Updateable(model).ExecuteCommand() == 0 ? false : true; } /// /// 仅更新赋值的字段 /// /// 实体类 /// public bool UpdateNotNullColumns(T_Service_ChestPain_OutComeInfo model) { try { db.Ado.BeginTran(); T_Service_Patient patient = new T_Service_Patient(); patient = db.Queryable().First(i => i.GUID == model.PatientGuid); if (patient != null) { T_Base_WristStrap wristStrap = new T_Base_WristStrap(); wristStrap = db.Queryable().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().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().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(); } /// /// 修改--仅更新赋值的字段 /// 用于移动端 /// /// 实体类 /// public bool UpdateForApp(T_Service_ChestPain_OutComeInfo model) { try { db.Ado.BeginTran(); T_Service_Patient patient = new T_Service_Patient(); patient = db.Queryable().First(i => i.GUID == model.PatientGuid); if (patient != null) { T_Base_WristStrap wristStrap = new T_Base_WristStrap(); wristStrap = db.Queryable().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().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 查 /// /// 得到一个对象实体 /// public T_Service_ChestPain_OutComeInfo GetModel(string GUID) { return db.Queryable().First(it => it.GUID == GUID); } /// /// 得到一个对象实体 /// public T_Service_ChestPain_OutComeInfo GetModelForUnit(string GUID) { return db.Queryable().First(it => it.PatientGuid == GUID); } /// /// 获得前几行数据 /// /// 起始页 /// 每页条数 /// 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; } /// /// 根据患者编号(GUID) 获取数据信息 /// /// 病人编号(GUID) /// public TableModel GetByPatientGuid(string patientGuid) { TableModel t = new TableModel(); List listMode = db.Queryable().Where(it => it.PatientGuid == patientGuid && it.DeleteFlag == 0).ToList(); t.Code = 0; t.TotalNumber = listMode.Count; t.Data = listMode; t.Msg = "成功"; return t; } /// /// 根据患者编号(GUID) 获取数据信息 /// /// 病人编号(GUID) /// public TableModel GetByPatientGuidForApp(string patientGuid) { TableModel t = new TableModel(); List listMode = db.Queryable().Where(it => it.PatientGuid == patientGuid && it.DeleteFlag == 0).ToList(); t.Code = 0; t.TotalNumber = listMode.Count; t.Data = listMode; t.Msg = "成功"; return t; } #endregion /// /// 获取STEMI初步诊断时间 /// /// /// public string GetSTEMIDiagnosisTime(string patientGuid) { string time = ""; var oneClass = db.Queryable().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; } } }