using System; using System.Data; using System.Data.SqlClient; using System.Collections; using System.Collections.Generic; using AIMSModel; using AIMSObjectQuery; using HelperDB; using System.Reflection; using System.Text; using AIMSBLL; namespace AIMSDAL { internal partial class DOperationApply { public static void Add(OperationApply OperationApplyObj) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into [OperationApply]("); strSql.Append("Oris_PatientId,ApplyDepId,OperationType,OrderOperationTime,OperationTimeLeight,IsReturnOperation,IsPlanReturnOperation,IsNotPlanReturnOperation,DiagnoseRemark,OperationRemark,OperationLevelId,Contagion,Intern,Other,ApplyTime,ApplyOperatorNo,State,Remark,OperatorNo,OperatorName,OperateDate,OperationSite"); strSql.Append(")"); strSql.Append(" values ("); strSql.Append("" + OperationApplyObj.OrisPatientId + ","); strSql.Append("" + OperationApplyObj.ApplyDepId + ","); strSql.Append("'" + OperationApplyObj.OperationType + "',"); strSql.Append("'" + OperationApplyObj.OrderOperationTime + "',"); strSql.Append("" + OperationApplyObj.OperationTimeLeight + ","); strSql.Append("" + OperationApplyObj.IsReturnOperation + ","); strSql.Append("" + OperationApplyObj.IsPlanReturnOperation + ","); strSql.Append("" + OperationApplyObj.IsNotPlanReturnOperation + ","); strSql.Append("'" + OperationApplyObj.DiagnoseRemark + "',"); strSql.Append("'" + OperationApplyObj.OperationRemark + "',"); strSql.Append("'" + OperationApplyObj.OperationLevelId + "',"); strSql.Append("'" + OperationApplyObj.Contagion + "',"); strSql.Append("'" + OperationApplyObj.Intern + "',"); strSql.Append("'" + OperationApplyObj.Other + "',"); strSql.Append("'" + OperationApplyObj.ApplyTime + "',"); strSql.Append("'" + OperationApplyObj.ApplyOperatorNo + "',"); //strSql.Append("'"+OperationApplyObj.PlanOperationTime+"',"); //strSql.Append(""+OperationApplyObj.OperationRoomId+","); strSql.Append("" + OperationApplyObj.State + ","); strSql.Append("'" + OperationApplyObj.Remark + "',"); strSql.Append("'" + OperationApplyObj.OperatorNo + "',"); strSql.Append("'" + OperationApplyObj.OperatorName + "',"); strSql.Append("'" + OperationApplyObj.OperateDate + "',"); strSql.Append("'" + OperationApplyObj.OperationSite + "'"); strSql.Append(")"); HelperDB.DbHelperSQL.ExecNonQuery(strSql.ToString()); } public static void UpdateVerifyTime(int ApplyId, string VerifyTime, string VerifyOperatorNo) { string strSql = "UPDATE OperationApply SET VerifyTime ='" + VerifyTime + "',VerifyOperatorNo = '" + VerifyOperatorNo + "' ,[State] = 2 WHERE Id =" + ApplyId + ""; HelperDB.DbHelperSQL.ExecNonQuery(strSql.ToString()); } public static void UpdateApplyState(int ApplyId, int State) { string strSql = "UPDATE OperationApply SET [State] = " + State + "," + "OperatorNo='" + AIMSExtension.PublicMethod.OperatorNo + "'," + "OperatorName='" + AIMSExtension.PublicMethod.OperatorName + "'," + "OperateDate='" + AIMSExtension.PublicMethod.SystemDate() + "' WHERE Id =" + ApplyId + ""; HelperDB.DbHelperSQL.ExecNonQuery(strSql.ToString()); } public static int UpdateApplyRoom(int ApplyId, int room, DateTime PlanOperationTime,int PlanOrder ) { string strSql = "UPDATE OperationApply SET OperationRoomId = " + room + ",PlanOrder=" + PlanOrder + " WHERE Id =" + ApplyId + ""; return HelperDB.DbHelperSQL.ExecNonQuery(strSql.ToString()); } public static void UpdatePlanOperationTime(int ApplyId, string PlanOperationTime, int OperationRoomId, int State) { //HHe 申请状态从 4改为3 3. 预排程 4 已排程 string strSql = "UPDATE OperationApply SET PlanOperationTime ='" + PlanOperationTime + "'," + "OperationRoomId = '" + OperationRoomId + "'," + "[State] = " + State + " ," + "OperatorNo='" + AIMSExtension.PublicMethod.OperatorNo + "'," + "OperatorName='" + AIMSExtension.PublicMethod.OperatorName + "'," + "OperateDate='" + AIMSExtension.PublicMethod.SystemDate() + "' " + "WHERE Id =" + ApplyId + ""; HelperDB.DbHelperSQL.ExecNonQuery(strSql.ToString()); } public static void UpdateStopOperation(int ApplyId, string Content) { string strSql = "UPDATE OperationApply SET [State] = 10 ," + "Remark ='" + Content + "'," + "OperatorNo='" + AIMSExtension.PublicMethod.OperatorNo + "'," + "OperatorName='" + AIMSExtension.PublicMethod.OperatorName + "'," + "OperateDate='" + AIMSExtension.PublicMethod.SystemDate() + "' WHERE Id =" + ApplyId + ""; HelperDB.DbHelperSQL.ExecNonQuery(strSql.ToString()); } public static void UpdatePlanOrder(int ApplyId, int PlanOrder) { string strSql = "UPDATE OperationApply SET PlanOrder = " + PlanOrder + " WHERE Id='" + ApplyId + "'"; HelperDB.DbHelperSQL.ExecNonQuery(strSql); } public static void UpdateASA(int ApplyId, string ASA, string HeartFunctionLevel) { //string strSql = "UPDATE OperationApply SET ASA ='" + ASA + "',HeartFunctionLevel='" + HeartFunctionLevel + "' WHERE id='" + ApplyId + "'"; StringBuilder sb = new StringBuilder(); sb.Append(" UPDATE OperationApply SET"); sb.Append(" ASA ='" + ASA + "'"); sb.Append(" ,HeartFunctionLevel='" + HeartFunctionLevel + "'"); sb.Append(" ,[State] = case [State] when 4 then 5 else [State] end"); sb.Append(" WHERE id='" + ApplyId + "'"); HelperDB.DbHelperSQL.ExecNonQuery(sb.ToString()); } public static int GetMaxPlanOrder(DateTime PlanOperationTime, int OperationRoomId) { string strSql = "SELECT ISNULL((Max(PlanOrder)),0) AS PlanOrder FROM V_OperationFront of1 WHERE of1.OrderOperationTime>='" + PlanOperationTime.ToString("yyyy-MM-dd 00:00:00") + "' AND of1.OrderOperationTime<'" + PlanOperationTime.AddDays(1).ToString("yyyy-MM-dd 00:00:00") + "' AND OperationRoomId=" + OperationRoomId + " ";// of1.[State] in('已排程','预排程','已访视') AND DataTable dt = HelperDB.DbHelperSQL.GetDataTable(strSql.ToString()); return int.Parse(dt.Rows[0]["PlanOrder"].ToString()); } public static OperationApply GetModel(int Id) { OperationApply OperationApplyObj = new OperationApply(); StringBuilder strSql = new StringBuilder(); strSql.Append("select "); strSql.Append("Id,Oris_PatientId,ApplyDepId,OperationType,OrderOperationTime,OperationTimeLeight,IsReturnOperation,IsPlanReturnOperation,IsNotPlanReturnOperation,DiagnoseRemark,OperationRemark,OperationLevelId,Contagion,Intern,Other,ApplyTime,ApplyOperatorNo,PlanOperationTime,OperationRoomId,State,Remark,OperatorNo,OperatorName,OperateDate,PlanOrder,OperationSite,OrderNo "); strSql.Append(" from OperationApply "); strSql.Append(" where Id=" + Id + ""); DataSet ds = HelperDB.DbHelperSQL.GetDataSet(strSql.ToString()); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["Id"].ToString() != "") { OperationApplyObj.Id = int.Parse(ds.Tables[0].Rows[0]["Id"].ToString()); } if (ds.Tables[0].Rows[0]["Oris_PatientId"].ToString() != "") { OperationApplyObj.OrisPatientId = int.Parse(ds.Tables[0].Rows[0]["Oris_PatientId"].ToString()); } if (ds.Tables[0].Rows[0]["ApplyDepId"].ToString() != "") { OperationApplyObj.ApplyDepId = int.Parse(ds.Tables[0].Rows[0]["ApplyDepId"].ToString()); } OperationApplyObj.OperationType = ds.Tables[0].Rows[0]["OperationType"].ToString(); if (ds.Tables[0].Rows[0]["OrderOperationTime"].ToString() != "") { OperationApplyObj.OrderOperationTime = DateTime.Parse(ds.Tables[0].Rows[0]["OrderOperationTime"].ToString()); } if (ds.Tables[0].Rows[0]["OperationTimeLeight"].ToString() != "") { OperationApplyObj.OperationTimeLeight = int.Parse(ds.Tables[0].Rows[0]["OperationTimeLeight"].ToString()); } if (ds.Tables[0].Rows[0]["IsReturnOperation"].ToString() != "") { OperationApplyObj.IsReturnOperation = int.Parse(ds.Tables[0].Rows[0]["IsReturnOperation"].ToString()); } if (ds.Tables[0].Rows[0]["IsPlanReturnOperation"].ToString() != "") { OperationApplyObj.IsPlanReturnOperation = int.Parse(ds.Tables[0].Rows[0]["IsPlanReturnOperation"].ToString()); } if (ds.Tables[0].Rows[0]["IsNotPlanReturnOperation"].ToString() != "") { OperationApplyObj.IsNotPlanReturnOperation = int.Parse(ds.Tables[0].Rows[0]["IsNotPlanReturnOperation"].ToString()); } OperationApplyObj.DiagnoseRemark = ds.Tables[0].Rows[0]["DiagnoseRemark"].ToString(); OperationApplyObj.OperationRemark = ds.Tables[0].Rows[0]["OperationRemark"].ToString(); if (ds.Tables[0].Rows[0]["OperationLevelId"].ToString() != "") { OperationApplyObj.OperationLevelId = int.Parse(ds.Tables[0].Rows[0]["OperationLevelId"].ToString()); } OperationApplyObj.Contagion = ds.Tables[0].Rows[0]["Contagion"].ToString(); OperationApplyObj.Intern = ds.Tables[0].Rows[0]["Intern"].ToString(); OperationApplyObj.Other = ds.Tables[0].Rows[0]["Other"].ToString(); if (ds.Tables[0].Rows[0]["ApplyTime"].ToString() != "") { OperationApplyObj.ApplyTime = DateTime.Parse(ds.Tables[0].Rows[0]["ApplyTime"].ToString()); } OperationApplyObj.ApplyOperatorNo = ds.Tables[0].Rows[0]["ApplyOperatorNo"].ToString(); if (ds.Tables[0].Rows[0]["PlanOperationTime"].ToString() != "") { OperationApplyObj.PlanOperationTime = DateTime.Parse(ds.Tables[0].Rows[0]["PlanOperationTime"].ToString()); } if (ds.Tables[0].Rows[0]["OperationRoomId"].ToString() != "") { OperationApplyObj.OperationRoomId = int.Parse(ds.Tables[0].Rows[0]["OperationRoomId"].ToString()); } if (ds.Tables[0].Rows[0]["State"].ToString() != "") { OperationApplyObj.State = int.Parse(ds.Tables[0].Rows[0]["State"].ToString()); } OperationApplyObj.Remark = ds.Tables[0].Rows[0]["Remark"].ToString(); if (ds.Tables[0].Rows[0]["PlanOrder"].ToString() != "") OperationApplyObj.PlanOrder = int.Parse(ds.Tables[0].Rows[0]["PlanOrder"].ToString()); OperationApplyObj.OperatorNo = ds.Tables[0].Rows[0]["OperatorNo"].ToString(); OperationApplyObj.OperatorName = ds.Tables[0].Rows[0]["OperatorName"].ToString(); if (ds.Tables[0].Rows[0]["OperateDate"].ToString() != "") { OperationApplyObj.OperateDate = DateTime.Parse(ds.Tables[0].Rows[0]["OperateDate"].ToString()); } if (ds.Tables[0].Rows[0]["OperationSite"].ToString() != "") { OperationApplyObj.OperationSite = ds.Tables[0].Rows[0]["OperationSite"].ToString() ; } if (ds.Tables[0].Rows[0]["OrderNo"].ToString() != "") { OperationApplyObj.OrderNo = ds.Tables[0].Rows[0]["OrderNo"].ToString() ; } if (ds.Tables[0].Rows[0]["OperationSite"].ToString() != "") { OperationApplyObj.OperationSite = ds.Tables[0].Rows[0]["OperationSite"].ToString() ; } } return OperationApplyObj; } public static DataTable GetDataTable(string strWhere) { StringBuilder strSql = new StringBuilder(); strSql.Append("select [Id],[Oris_PatientId],[ApplyDepId],[OperationType],[OrderOperationTime],[OperationTimeLeight],[IsReturnOperation],[IsPlanReturnOperation],[IsNotPlanReturnOperation],[DiagnoseRemark],[OperationRemark],[OperationLevelId],[Contagion],[Intern],[Other],[ApplyTime],[ApplyTimeOperatorNo],[PlanOperationTime],[OperationRoomId],[State],of1.StateId,[Remark],[OperatorNo],[OperatorName],[OperateDate] "); strSql.Append(" FROM OperationApply "); if (strWhere.Trim() != "") { strSql.Append(" where " + strWhere); } return HelperDB.DbHelperSQL.GetDataTable(strSql.ToString()); } public static int GetOperationApplyMaxId() { string strSql = "SELECT (ISNULL(MAX(Id),0)) AS Id FROM OperationApply"; DataTable dt = HelperDB.DbHelperSQL.GetDataTable(strSql); return int.Parse(dt.Rows[0]["Id"].ToString()); } public static DataTable GetOperationFrontDataTableByPatientId(int PatientId) { string strSql = "SELECT of1.ApplyId, of1.MdrecNo, of1.ArchivesNo, of1.PatientName,of1.DepartmentId,of1.PatientDepName,of1.ApplyDepName, of1.PatientKind," + "of1.Sex, of1.Age,of1.BirthDay, of1.Height, of1.[Weight], of1.BloodType," + "of1.RHBloodType, of1.Illdistrict, of1.SickBed, of1.OperationType," + "of1.OrderOperationTime, of1.OperationTimeLeight, of1.[State],of1.StateId," + "of1.IsReturnOperation, of1.IsPlanReturnOperation, of1.ApplyDiagnoseInfoName," + "of1.DiagnoseRemark, of1.ApplyOperationInfoName, of1.OperationRemark," + "of1.OperationLevelName, of1.ApplyOperationCutTypeName," + "of1.ApplyOperationPositionName, of1.AnaesthesiaMethodName, of1.Contagion," + "of1.OperationDoctor, of1.Assistant1, of1.Assistant2, of1.Assistant3," + "of1.Intern, of1.Other, of1.ApplyTime, of1.ApplyOperatorName," + "of1.VerifyTime, of1.VerifyOperatorName," + "of1.PlanOperationTime, of1.OperationRoom, of1.AnesthesiaDoctor," + "of1.InstrumentNurse, of1.TourNurse, of1.AnesthesiaDoctorSucceed," + "of1.InstrumentNurseSucceed, of1.TourNurseSucceed,of1.ASA,of1.HeartFunctionLevel,of1.IsFasting, of1.Remark,ApplyDiagnoseInfoId,ApplyOperationInfoId ,of1.PlanOrder,of1.OperationRoomId ,of1.MedicalRecord,of1.PatientType,of1.HISPatientId,of1.VisitTimes " + "FROM V_OperationFront of1 WHERE of1.PatientId='" + PatientId + "'"; return HelperDB.DbHelperSQL.GetDataTable(strSql.ToString()); } public static DataTable GetOperationFrontDataTable(string BegInData, string EndData) { string strSql = "SELECT of1.ApplyId, of1.PatientId,of1.MdrecNo, of1.ArchivesNo, of1.PatientName, of1.PatientName+'('+of1.Sex+of1.Age+')' PatInfo,of1.ApplyDepName, of1.PatientKind," + "of1.Sex, of1.Age, of1.BirthDay, of1.Height, of1.[Weight], of1.BloodType," + "of1.RHBloodType, of1.Illdistrict, of1.SickBed, of1.OperationType," + "of1.OrderOperationTime, of1.OperationTimeLeight, of1.[State],of1.StateId," + "of1.IsReturnOperation, of1.IsPlanReturnOperation, of1.ApplyDiagnoseInfoName," + "of1.DiagnoseRemark, of1.ApplyOperationInfoName, of1.OperationRemark," + "of1.OperationLevelName, of1.ApplyOperationCutTypeName," + "of1.ApplyOperationPositionName, of1.AnaesthesiaMethodName, of1.Contagion," + "of1.OperationDoctor,[dbo].[fun_getPY](of1.OperationDoctor) OperationDoctorcode, of1.Assistant1, of1.Assistant2, of1.Assistant3, isnull(of1.Assistant1,'')+isnull(' '+of1.Assistant2,'')+ isnull(' '+of1.Assistant3,'')Assistants," + "of1.Intern, of1.Other, of1.ApplyTime, of1.ApplyOperatorName," + "of1.VerifyTime, of1.VerifyOperatorName," + "of1.PlanOperationTime, of1.OperationRoom, of1.OperationRoomId, of1.AnesthesiaDoctor," + "of1.InstrumentNurse, of1.TourNurse, of1.AnesthesiaDoctorSucceed," + "of1.InstrumentNurseSucceed, of1.TourNurseSucceed,of1.Remark,of1.PlanOrder,of1.PatientType " + "FROM V_OperationFront of1 WHERE of1.OrderOperationTime>='" + BegInData + "' and of1.OrderOperationTime<'" + EndData + "' order by OperationRoomId,PlanOrder asc"; return HelperDB.DbHelperSQL.GetDataTable(strSql.ToString()); } public static DataTable GetOperationFrontDataTableByPlanOperationTime(string BegInData, string EndData) { string strSql = "SELECT of1.ApplyId,of1.PatientId, of1.MdrecNo, of1.ArchivesNo, of1.PatientName,of1.ApplyDepName, of1.PatientKind," + "of1.Sex, of1.Age,of1.BirthDay, of1.Height, of1.[Weight], of1.BloodType," + "of1.RHBloodType, of1.Illdistrict, of1.SickBed, of1.OperationType," + "of1.OrderOperationTime, of1.OperationTimeLeight, of1.[State],of1.StateId," + "of1.IsReturnOperation, of1.IsPlanReturnOperation, of1.ApplyDiagnoseInfoName," + "of1.DiagnoseRemark, of1.ApplyOperationInfoName, of1.OperationRemark," + "of1.OperationLevelName, of1.ApplyOperationCutTypeName," + "of1.ApplyOperationPositionName, of1.AnaesthesiaMethodName, of1.Contagion," + "of1.OperationDoctor, of1.Assistant1, of1.Assistant2, of1.Assistant3," + "of1.Intern, of1.Other, of1.ApplyTime, of1.ApplyOperatorName," + "of1.VerifyTime, of1.VerifyOperatorName," + "of1.PlanOperationTime, of1.OperationRoom, of1.AnesthesiaDoctor," + "of1.InstrumentNurse, of1.TourNurse, of1.AnesthesiaDoctorSucceed," + "of1.InstrumentNurseSucceed, of1.TourNurseSucceed,of1.Remark,of1.PlanOrder,of1.PatientType " + "FROM V_OperationFront of1 WHERE of1.PlanOperationTime>='" + BegInData + "' and of1.PlanOperationTime<'" + EndData + "' order by OperationRoomId,PlanOrder asc"; return HelperDB.DbHelperSQL.GetDataTable(strSql.ToString()); } public static DataTable SelectPlanedOpeByRoom(string whereSql) { try { string sql = @" SELECT * FROM V_OperationFront where " + whereSql + " "; return DBHelper.GetDataTable(sql); } catch (Exception) { return null; } } public static DataTable SelectPlanedOpe(string whereSql) { try { string sql = @" SELECT * FROM OperationApply where " + whereSql + " "; return DBHelper.GetDataTable(sql); } catch (Exception) { return null; } } public static int SaveDoctorByRommTime(string DoctorNuresName, DateTime SearchTime, int CurrentRoom) { try { string sql = string.Format(@"update OperationApply set {0} where state in(1,2,3,4) and PlanOperationTime<'" + SearchTime.ToString("yyyy-MM-dd 23:59:59") + "' and PlanOperationTime>'" + SearchTime.ToString("yyyy-MM-dd 00:00:00") + "' and OperationRoomId =" + CurrentRoom, DoctorNuresName); return DBHelper.ExecNonQuery(sql); } catch (Exception) { return 0; } } public static void UpdateApplyOrder(int ApplyId, int Order) { string strSql = "UPDATE OperationApply SET PlanOrder=" + Order + " WHERE Id =" + ApplyId + ""; HelperDB.DbHelperSQL.ExecNonQuery(strSql.ToString()); } } }