using HL_FristAidPlatform_Help; using HL_FristAidPlatform_IDataBase.Service; using HL_FristAidPlatform_Models; using SqlSugar; using System; using System.Collections.Generic; namespace HL_FristAidPlatform_DataBase { public class T_Service_Chest_UpwardReferralDB: BaseDB, IT_Service_Chest_UpwardReferral { public SqlSugarClient db = GetClient(); public T_Service_Chest_UpwardReferral Add(T_Service_Chest_UpwardReferral model) { T_Service_Patient patient = new T_Service_Patient(); patient.GUID = model.PatientGuid; patient.IsForward = "1"; db.Updateable(patient).UpdateColumns(it => new { it.IsForward }).Where(it => it.GUID == patient.GUID).ExecuteCommand(); return db.Insertable(model).ExecuteReturnEntity(); } public ChestPatientReferralModel GetByPatientGuid(string patientGuid, string hospitalGuid) { ChestPatientReferralModel model = new ChestPatientReferralModel(); model = db.Queryable ((a, b, c, d, e) => new JoinQueryInfos( JoinType.Left, a.GUID == b.PatientGuid, JoinType.Left, a.GUID == c.PatientGuid, JoinType.Left, a.GUID == d.PatientGuid, JoinType.Left, a.HospitalGuid == e.GUID)) .Where((a, b, c, d, e) => a.GUID == patientGuid && a.HospitalGuid == hospitalGuid && a.DeleteFlag == 0) .Select((a, b, c, d, e) => new ChestPatientReferralModel() { HospitalGuid = a.HospitalGuid, PatientGuid = a.GUID, Name = a.Name, Gender = a.Gender, Age = a.Age, Phone = a.MobilePhone, Inpatient_ID = b.Inpatient_ID, Medical_Insurance_Type = b.Medical_Insurance_Type, LeaveTime = d.LeaveTime != "" ? d.LeaveTime : SqlFunc.ToDate(c.Hand_Time).ToString("yyyy-MM-dd"), LeaveHospital = d.TransferHospital != "" ? d.TransferHospital : e.Name, IllnessExplain = d.IllnessExplain, TransferNotice = d.TransferNotice, ReceiveHospital = d.ReceiveHospital, AppointHospital = d.AppointHospital, PatientSignature = d.PatientSignature, ReferringDoctorSignature = d.ReferringDoctorSignature, TransferWay = d.TransferWay }).First(); return model; } public T_Service_Chest_UpwardReferral GetByPatientGuid1(string PatientGuid) { return db.Queryable().Where(it => it.PatientGuid == PatientGuid && it.DeleteFlag == 0).First(); } public string GetHospitalParentGUID(string receiveHospital) { return db.Queryable().Where(it => it.Name== receiveHospital).Select(it => it.GUID).First(); } public int Update(T_Service_Chest_UpwardReferral model) { return db.Updateable(model).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommand(); } /// /// 以下用于上级医院新增数据 /// /// /// public T_Service_Patient Get(string guid) { return db.Queryable().Where(it => it.GUID == guid).First(); } public T_Service_ChestPain_FirstAIDInfo GetModelOfPatient(string patientGUID) { return db.Queryable().First(it => it.PatientGuid == patientGUID); } public T_Service_ChestPain_TreatmentInfo GetTreatmentByPatientGUID(string patientGUID) { return db.Queryable().First(it => it.PatientGuid == patientGUID); } public T_Service_ChestPain_OutComeInfo GetOutComeByPatientGUID(string patientGUID) { return db.Queryable().First(it => it.PatientGuid == patientGUID); } public List GetECGByPatientGUID(string patientGUID) { return db.Queryable().Where(it => it.PatientGuid == patientGUID && it.DeleteFlag == 0).ToList(); } public List GetCTNTByPatientGUID(string patientGUID) { return db.Queryable().Where(it => it.PatientGuid == patientGUID && it.DeleteFlag == 0).ToList(); } public string GetNetHospitalParentGUID(string hospitalname) { return db.Queryable().Where(it => it.HospitalName == hospitalname).Select(it => it.HospitalGuid).First(); } public void InsertChestData(T_Service_Patient upwardPatient, T_Service_ChestPain_FirstAIDInfo upt_Service_ChestPain_FirstAIDInfo, T_Service_ChestPain_TreatmentInfo upt_Service_ChestPain_Treatment, T_Service_ChestPain_OutComeInfo upt_Service_ChestPain_OutCome, List uplistECG, List uplistCTNT) { try { db.Ado.BeginTran(); if (SqlFunc.IsNullOrEmpty(upwardPatient.GUID)) { upwardPatient.GUID = Guid.NewGuid().ToString(); db.Insertable(upwardPatient).IgnoreColumns(it => new { it.ID }).ExecuteCommand(); } else { db.Insertable(upwardPatient).IgnoreColumns(it => new { it.ID }).ExecuteCommand(); } if (SqlFunc.IsNullOrEmpty(upt_Service_ChestPain_FirstAIDInfo.GUID)) { upt_Service_ChestPain_FirstAIDInfo.GUID = Guid.NewGuid().ToString(); db.Insertable(upt_Service_ChestPain_FirstAIDInfo).IgnoreColumns(it => new { it.ID }).ExecuteCommand(); } else { db.Insertable(upt_Service_ChestPain_FirstAIDInfo).IgnoreColumns(it => new { it.ID }).ExecuteCommand(); } if (SqlFunc.IsNullOrEmpty(upt_Service_ChestPain_Treatment.GUID)) { upt_Service_ChestPain_Treatment.GUID = Guid.NewGuid().ToString(); db.Insertable(upt_Service_ChestPain_Treatment).IgnoreColumns(it => new { it.ID }).ExecuteCommand(); } else { db.Insertable(upt_Service_ChestPain_Treatment).IgnoreColumns(it => new { it.ID }).ExecuteCommand(); } if (SqlFunc.IsNullOrEmpty(upt_Service_ChestPain_OutCome.GUID)) { upt_Service_ChestPain_OutCome.GUID = Guid.NewGuid().ToString(); db.Insertable(upt_Service_ChestPain_OutCome).IgnoreColumns(it => new { it.ID }).ExecuteCommand(); } else { db.Insertable(upt_Service_ChestPain_OutCome).IgnoreColumns(it => new { it.ID }).ExecuteCommand(); } for (int i = 0; i < uplistECG.Count; i++) { if (SqlFunc.IsNullOrEmpty(uplistECG[i].GUID)) { uplistECG[i].GUID = Guid.NewGuid().ToString(); db.Insertable(uplistECG[i]).IgnoreColumns(it => new { it.ID }).ExecuteCommand(); } else { db.Insertable(uplistECG[i]).IgnoreColumns(it => new { it.ID }).ExecuteCommand(); } } for (int i = 0; i < uplistCTNT.Count; i++) { if (SqlFunc.IsNullOrEmpty(uplistCTNT[i].GUID)) { uplistCTNT[i].GUID = Guid.NewGuid().ToString(); db.Insertable(uplistCTNT[i]).IgnoreColumns(it => new { it.ID }).ExecuteCommand(); } else { db.Insertable(uplistCTNT[i]).IgnoreColumns(it => new { it.ID }).ExecuteCommand(); } } db.Ado.CommitTran(); } catch (Exception ex) { db.Ado.RollbackTran(); Help.WriteErrorLog("上转数据报错日志:", ex.ToString()); throw; } } } }