using HL_FristAidPlatform_Help;
using HL_FristAidPlatform_IDataBase;
using HL_FristAidPlatform_Models;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Data;
namespace HL_FristAidPlatform_DataBase
{
public class EmergencyTriageService : BaseDB, IEmergencyTriageService
{
public SqlSugarClient db = GetClient();
///
/// 分诊保存
///
///
///
///
///
///
///
///
public string EmergencyTriageTran(T_Service_FirstAid_PatientInfo fp, T_Service_FirstAid_HealthCheckup checkup, T_Service_FirstAid_AssistantExamination ass, T_Service_Patient patient, T_Service_ChestPain_FirstAIDInfo info, T_Service_Apoplexy_Prehospital prehospital, long CreatorID)
{
try
{
db.Ado.BeginTran();
db.Insertable(patient).IgnoreColumns(ignoreNullColumn: true).ExecuteCommand();
db.Insertable(fp).IgnoreColumns(ignoreNullColumn: true).ExecuteCommand();
if (!string.IsNullOrEmpty(checkup.GUID))
{
db.Insertable(checkup).IgnoreColumns(ignoreNullColumn: true).ExecuteCommand();
}
if (!string.IsNullOrEmpty(ass.GUID))
{
db.Insertable(ass).IgnoreColumns(ignoreNullColumn: true).ExecuteCommand();
}
if (!string.IsNullOrEmpty(info.GUID))
{
db.Insertable(info).IgnoreColumns(ignoreNullColumn: true).ExecuteCommand();
}
if (!string.IsNullOrEmpty(prehospital.GUID))
{
db.Insertable(prehospital).IgnoreColumns(ignoreNullColumn: true).ExecuteCommand();
}
if (patient.SystemModuleID == 2)//胸痛类型
{
//胸痛诊疗
T_Service_ChestPain_TreatmentInfo treatmentInfo = new T_Service_ChestPain_TreatmentInfo();
treatmentInfo.PatientGuid = patient.GUID;
treatmentInfo.CreatorID = CreatorID;
treatmentInfo.CreationDate = DateTime.Now;
treatmentInfo.GUID = Guid.NewGuid().ToString();
db.Insertable(treatmentInfo).IgnoreColumns(ignoreNullColumn: true).ExecuteCommand();
//冠状动脉造影
T_Service_ChestPain_CoronaryAngiographie coronary = new T_Service_ChestPain_CoronaryAngiographie();
coronary.PatientGuid = patient.GUID;
coronary.CreatorID = CreatorID;
coronary.CreationDate = DateTime.Now;
coronary.GUID = Guid.NewGuid().ToString();
db.Insertable(coronary).IgnoreColumns(ignoreNullColumn: true).ExecuteCommand();
//转归表
T_Service_ChestPain_OutComeInfo outComeInfo = new T_Service_ChestPain_OutComeInfo();
outComeInfo.PatientGuid = patient.GUID;
outComeInfo.CreatorID = CreatorID;
outComeInfo.CreationDate = DateTime.Now;
outComeInfo.GUID = Guid.NewGuid().ToString();
db.Insertable(outComeInfo).IgnoreColumns(ignoreNullColumn: true).ExecuteCommand();
//增加对应模块的时间节点记录业务 且排除已存在的记录
string Url = string.Format("SELECT ID FROM T_Base_TimeAxis WHERE SystemModuleID={0} AND IsDisplayTimeAxis=0 AND DeleteFlag=0 AND ID NOT IN(SELECT TimeAxisID FROM T_Service_ChestPain_PatientsTimeAxis WHERE PatientGuid='{1}' AND DeleteFlag=0) ORDER BY OrderBy", patient.SystemModuleID, patient.GUID);
DataTable dataTable = db.Ado.GetDataTable(Url);
int number = 0;
if (dataTable.Rows.Count > 0)
{
foreach (DataRow item in dataTable.Rows)
{
T_Service_ChestPain_PatientsTimeAxis InsertModel = new T_Service_ChestPain_PatientsTimeAxis();
InsertModel.GUID = Guid.NewGuid().ToString();
InsertModel.PatientGuid = patient.GUID;
InsertModel.TimeAxisID = Convert.ToInt32(item["ID"] + "");
InsertModel.DeleteFlag = 0;
InsertModel.IsAutoForRFID = 0;
InsertModel.SystemModuleID = patient.SystemModuleID;
number = db.Insertable(InsertModel).InsertColumns(it => new { it.GUID, it.PatientGuid, it.TimeAxisID, it.DeleteFlag, it.IsAutoForRFID, it.SystemModuleID }).ExecuteReturnIdentity();
}
}
}
if (patient.SystemModuleID == 3)
{
//增加对应模块的时间节点记录业务 且排除已存在的记录
string Url = string.Format("SELECT ID FROM T_Base_TimeAxis WHERE SystemModuleID={0} AND IsDisplayTimeAxis=0 AND DeleteFlag=0 AND ID NOT IN(SELECT TimeAxisID FROM T_Service_Apoplexy_PatientsTimeAxis WHERE PatientGuid='{1}' AND DeleteFlag=0) ORDER BY OrderBy", patient.SystemModuleID, patient.GUID);
DataTable dataTable = db.Ado.GetDataTable(Url);
int number = 0;
if (dataTable.Rows.Count > 0)
{
foreach (DataRow item in dataTable.Rows)
{
T_Service_Apoplexy_PatientsTimeAxis InsertModel = new T_Service_Apoplexy_PatientsTimeAxis();
InsertModel.GUID = Guid.NewGuid().ToString();
InsertModel.PatientGuid = patient.GUID;
InsertModel.SystemModuleID = patient.SystemModuleID;
InsertModel.TimeAxisID = Convert.ToInt32(item["ID"] + "");
InsertModel.DeleteFlag = 0;
InsertModel.IsAutoForRFID = 0;
number = db.Insertable(InsertModel).InsertColumns(it => new { it.GUID, it.PatientGuid, it.SystemModuleID, it.TimeAxisID, it.DeleteFlag, it.IsAutoForRFID }).ExecuteReturnIdentity();
}
}
}
var task = db.Queryable().Where(i => i.GUID == fp.TaskGUID).First();
if (task != null)
{
task.ActualPatientsNumber = task.ActualPatientsNumber + 1;
db.Updateable(task).ExecuteCommand();
}
db.Ado.CommitTran();
return patient.GUID;
}
catch (Exception ex)
{
db.Ado.RollbackTran();
Help.WriteErrorLog("急诊分诊:分诊保存(EmergencyTriageTran)", ex.ToString());
return "";
}
}
///
/// 新增急诊分诊患者
///
///
///
///
///
///
public string AddEmergencyTriage(T_Service_FirstAid_PatientInfo fp, T_Service_FirstAid_HealthCheckup checkup, T_Service_FirstAid_AssistantExamination ass, T_Service_Patient patient)
{
try
{
db.Ado.BeginTran();
db.Insertable(patient).IgnoreColumns(ignoreNullColumn: true).ExecuteCommand();
db.Insertable(fp).IgnoreColumns(ignoreNullColumn: true).ExecuteCommand();
if (!string.IsNullOrEmpty(checkup.GUID))
{
db.Insertable(checkup).IgnoreColumns(ignoreNullColumn: true).ExecuteCommand();
}
if (!string.IsNullOrEmpty(ass.GUID))
{
db.Insertable(ass).IgnoreColumns(ignoreNullColumn: true).ExecuteCommand();
}
db.Ado.CommitTran();
return patient.GUID;
}
catch (Exception ex)
{
db.Ado.RollbackTran();
Help.WriteErrorLog("急诊分诊:分诊保存(EmergencyTriage)", ex.ToString());
return "";
}
}
public string AddBatchPatient(T_Service_FirstAid_PatientInfo fp,T_Service_Patient patient)
{
try
{
db.Ado.BeginTran();
db.Insertable(patient).IgnoreColumns(ignoreNullColumn: true).ExecuteCommand();
db.Insertable(fp).IgnoreColumns(ignoreNullColumn: true).ExecuteCommand();
db.Ado.CommitTran();
return patient.GUID;
}
catch (Exception ex)
{
db.Ado.RollbackTran();
Help.WriteErrorLog("急诊分诊:批量创建患者(AddBatchPatient)", ex.ToString());
return "";
}
}
///
/// 出科召回
///
///
///
public string RecallDepartment(T_Service_FirstAid_PatientInfo fp)
{
try
{
return db.Updateable(t => t.TriageDepartment == fp.TriageDepartment).Where(t => t.PatientGUID == fp.PatientGUID).ExecuteCommand().ToString();
}
catch (Exception ex)
{
db.Ado.RollbackTran();
Help.WriteErrorLog("急诊分诊:出科召回(RecallDepartment)", ex.ToString());
return "";
}
}
///
/// 交接 非重大事故
///
///
///
///
///
///
public bool HandoverVehicleAndPer(T_Service_Patient patient, T_Service_FirstAid_HealthCheckup health, List perlist, List ambList, T_Service_FirstAid_Call call, int id)
{
try
{
db.Ado.BeginTran();
if (patient != null)
{
db.Insertable(patient).IgnoreColumns(ignoreNullColumn: true).ExecuteCommand();
db.Insertable(health).IgnoreColumns(ignoreNullColumn: true).ExecuteCommand();
// 新增工作量 评分统计
T_Service_FirstAid_WorkLoad work = new T_Service_FirstAid_WorkLoad();
if (!SqlFunc.IsNullOrEmpty(health.Pulse))
work.FourTestsMark = work.FourTestsMark + 1;
if (!SqlFunc.IsNullOrEmpty(health.HeartRate))
work.FourTestsMark = work.FourTestsMark + 1;
if (!SqlFunc.IsNullOrEmpty(health.SystolicPressure) && !SqlFunc.IsNullOrEmpty(health.DiastolicPressure))
work.FourTestsMark = work.FourTestsMark + 1;
if (!SqlFunc.IsNullOrEmpty(health.Temperature))
work.FourTestsMark = work.FourTestsMark + 1;
work.CensusScore = work.CensusScore + work.FourTestsMark;
if (work != null)
if (work != null)
{
work.GUID = Guid.NewGuid().ToString();
work.CallGUID = call.GUID;
db.Insertable(work).IgnoreColumns(ignoreNullColumn: true).ExecuteCommand();
}
}
if (perlist != null)
db.Updateable(perlist).SetColumns(t => t.CurrentState == 0).ExecuteCommand();
if (ambList != null)
db.Updateable(ambList).SetColumns(t => t.State == 1).ExecuteCommand();
db.Updateable().SetColumns(it =>
new T_Service_FirstAid_Call
{
HandoverTime = DateTime.Now.ToString(),
HandoverUser = call.HandoverUser,
TaskState = 5
}).Where(it => it.GUID == call.GUID).ExecuteCommand();
if (id > 0)
db.Updateable().SetColumns(it => it.Status == 0).Where(it => it.ID == id).ExecuteCommand();
db.Ado.CommitTran();
return true;
}
catch (Exception ex)
{
return false;
Help.WriteErrorLog("急诊分诊:交接 非重大事故(HandoverVehicleAndPer)", ex.ToString());
throw;
}
}
///
/// 交接 重大事故(未修改标签卡状态 后期加)
///
///
///
///
public bool HandoverVehicleAndPer(List perlist, List ambList, string guid)
{
try
{
db.Ado.BeginTran();
if (perlist != null && perlist.Count > 0)
db.Updateable(perlist).SetColumns(t => t.CurrentState == 0).ExecuteCommand();
if (ambList != null && ambList.Count > 0)
db.Updateable(ambList).SetColumns(t => t.State == 1).ExecuteCommand();
string sql = string.Format(@" select GUID, Name, CurrentState,Role,Gender from dbo.T_Service_FirstAid_Personnel where GUID in
(select SUBSTRING(a.AccompanyinPersonnel, number, CHARINDEX(',', a.AccompanyinPersonnel + ',', number) - number)
from dbo.T_Service_FirstAid_Call a,master..spt_values
where GUID = '{0}'
and CurrentState=2
and number >= 1 and number= 1 and number().SetColumns(it => new T_Service_FirstAid_Call() { TaskState = 5, HandoverTime = DateTime.Now.ToString() }).Where(it => it.GUID == guid).ExecuteCommand();
}
db.Ado.CommitTran();
return true;
}
catch (Exception ex)
{
return false;
Help.WriteErrorLog("急诊分诊:交接 重大事故(HandoverVehicleAndPer)", ex.ToString());
throw;
}
}
}
}