using AIMSBLL; using AIMSModel; using AIMSObjectQuery; using DrawGraph; using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using System.Text; namespace AIMSDAL { internal partial class DOperationRecord { public static int AddTitleTime(int PatientId, int ApplyId, int RecoverId, int State, DateTime Time, int RoomId) { string ApplyAnaesthesiaMethod = BApplyAnaesthesiaMethod.GetApplyAnaesthesiaMethod(ApplyId); string strSql = "INSERT INTO OperationRecord(PatientId,OperationApplyId,RecoverId,[State],InRoomTime,OperatorNo,OperatorName,OperateDate,RoomId,AnaesthesiaMethodName,Fasting)" + "VALUES (" + PatientId + "," + ApplyId + "," + RecoverId + ",'" + State + "','" + Time + "','" + AIMSExtension.PublicMethod.OperatorNo + "','" + AIMSExtension.PublicMethod.OperatorName + "','" + AIMSExtension.PublicMethod.SystemDate() + "','" + RoomId + "','" + ApplyAnaesthesiaMethod + "','是');select @@identity "; return Convert.ToInt32(HelperDB.DbHelperSQL.ExecNonQuery(strSql)); } public static int AddTitleTime2(int PatientId, int ApplyId, int RecoverId, int State, DateTime Time, int RoomId) { OperationRecord _record = new OperationRecord(); BOperationRecord.SelectSingle(PatientId, 1, ref _record); string strSql = "INSERT INTO OperationRecord(PatientId,OperationApplyId,RecoverId,[State],InRoomTime,OperatorNo,OperatorName,OperateDate,RoomId,AnaesthesiaMethodName,ASALevel)" + "VALUES (" + PatientId + "," + ApplyId + "," + RecoverId + ",'" + State + "','" + Time + "','" + AIMSExtension.PublicMethod.OperatorNo + "','" + AIMSExtension.PublicMethod.OperatorName + "','" + AIMSExtension.PublicMethod.SystemDate() + "','" + RoomId + "','" + _record.AnaesthesiaMethodName + "','" + _record.ASALevel + "');select @@identity "; return Convert.ToInt32(HelperDB.DbHelperSQL.ExecNonQuery(strSql)); } public static DataTable GetOperationDoingMainInfo(int PatientId, int TypeId) { string strSql = "SELECT od.Id,od.PatientId, od.ApplyId, InRoomTime, OutRoomTime, OperationBeginTime, OperationEndTime, " + " od.DiagnoseInfoName, od.OperationInfoName,od.AnaesthesiaMethodName, od.OperationCutTypeName," + "od.OperationBodyPositionName, od.OperationPositionName, od.OperationDoctor,od.Assistant, od.AnesthesiaDoctor, od.Nurse,od.Nurse2," + "od.OperatorNo,od.OperatorName,od.OperateDate,od.State,OperationDoctorId ,[AssistantId] ,[AnesthesiaDoctorId] ,[InstrumentNurseId],[TourNurseId],DiagnoseInfoId,OperationInfoId,AnaesthesiaMethodId,OrtherDoctor,OrtherDoctorId,OperationPositionId,OperationBodyPositionId,ASALevel,SpecialCase,Fasting,BloodType,OperationRoom FROM V_OperationDoing od WHERE od.PatientId=" + PatientId + " and od.RecoverId='" + TypeId + "'"; return HelperDB.DbHelperSQL.GetDataTable(strSql); } public static void UpdateState(int PatientId, int TypeId, int State) { string strSql = "UPDATE OperationRecord SET " + (State == 1 ? " OutRoomTime=null, " : "") + " [State] = " + State + ",OperatorNo = '" + AIMSExtension.PublicMethod.OperatorNo + "',OperatorName = '" + AIMSExtension.PublicMethod.OperatorName + "',OperateDate = '" + AIMSExtension.PublicMethod.SystemDate() + "' WHERE PatientId=" + PatientId + " and RecoverId='" + TypeId + "'"; HelperDB.DbHelperSQL.ExecNonQuery(strSql.ToString()); } public static void UpdateOpeState(int PatientId, int TypeId, int State, string Text) { string strSql = "UPDATE OperationRecord SET " + (State == 1 ? " OutRoomTime=null, " : "") + " [State] = " + State + ",Remark3 = '" + Text + "',OperatorNo = '" + AIMSExtension.PublicMethod.OperatorNo + "',OperatorName = '" + AIMSExtension.PublicMethod.OperatorName + "',OperateDate = '" + AIMSExtension.PublicMethod.SystemDate() + "' WHERE PatientId=" + PatientId + " and RecoverId='" + TypeId + "'"; HelperDB.DbHelperSQL.ExecNonQuery(strSql.ToString()); } public static void UpdateTimeSpan(int Id) { string strSql = " update OperationRecord set RoomTimeSpan=ISNULL(DATEDIFF(minute,InRoomTime,OutRoomTime),0),OperationTimeSpan=ISNULL(DATEDIFF(minute,OperationBeginTime,OperationEndTime),0),AnaesthesiaTimeSpan=ISNULL(DATEDIFF(minute,AnesthesiaBeginTime, AnesthesiaEndTime),0) where id ='" + Id + "' "; HelperDB.DbHelperSQL.ExecNonQuery(strSql.ToString()); } public static void DeleteOperationRecordData(int RecorId, int PatientId, int TypeId) { HelperDB.DbHelperSQL.ExecNonQuery("DELETE FROM FactAnaesthesiaMethod WHERE PatientId=" + PatientId + ""); HelperDB.DbHelperSQL.ExecNonQuery("DELETE FROM FactBloodGasAnalysis WHERE OperationRecordId=" + RecorId + ""); HelperDB.DbHelperSQL.ExecNonQuery("DELETE FROM FactDiagnoseInfo WHERE PatientId=" + PatientId + ""); HelperDB.DbHelperSQL.ExecNonQuery("DELETE FROM FactDrug WHERE DrugTypeId=" + TypeId + " and PatientId=" + PatientId + ""); HelperDB.DbHelperSQL.ExecNonQuery("DELETE FROM FactEvents WHERE EventTypeId=" + TypeId + " and PatientId=" + PatientId + ""); HelperDB.DbHelperSQL.ExecNonQuery("DELETE FROM FactOperationBodyPosition WHERE PatientId=" + PatientId + ""); HelperDB.DbHelperSQL.ExecNonQuery("DELETE FROM FactOperationCutType WHERE PatientId=" + PatientId + ""); HelperDB.DbHelperSQL.ExecNonQuery("DELETE FROM FactOperationInfo WHERE PatientId=" + PatientId + ""); HelperDB.DbHelperSQL.ExecNonQuery("DELETE FROM FactOperationPosition WHERE PatientId=" + PatientId + ""); HelperDB.DbHelperSQL.ExecNonQuery("DELETE FROM FactOutputLiquids WHERE OutputLiquidsTypeId=" + TypeId + " and PatientId=" + PatientId + ""); HelperDB.DbHelperSQL.ExecNonQuery("DELETE FROM FactPersonDuty WHERE PatientId=" + PatientId + " "); HelperDB.DbHelperSQL.ExecNonQuery("DELETE FROM OperationRecordInfo WHERE OperationRecordId=" + RecorId); HelperDB.DbHelperSQL.ExecNonQuery("DELETE FROM PhysioData WHERE PatientId =" + RecorId); HelperDB.DbHelperSQL.ExecNonQuery("DELETE FROM OperationRecordInstrumentList WHERE OperationRecordId =" + RecorId); HelperDB.DbHelperSQL.ExecNonQuery("DELETE FROM OperationRecordAnalgesia WHERE OperationRecordId =" + RecorId); HelperDB.DbHelperSQL.ExecNonQuery("DELETE FROM ApplianceRecord WHERE OperationRecordId =" + RecorId); HelperDB.DbHelperSQL.ExecNonQuery("DELETE FROM OperationRecord WHERE id=" + RecorId); } public static void DeleteOperationRecorvreData(int RecorId, int PatientId, int TypeId) { HelperDB.DbHelperSQL.ExecNonQuery("DELETE FROM FactDrug WHERE DrugTypeId=" + TypeId + " and PatientId=" + PatientId + ""); HelperDB.DbHelperSQL.ExecNonQuery("DELETE FROM FactEvents WHERE EventTypeId=" + TypeId + " and PatientId=" + PatientId + ""); HelperDB.DbHelperSQL.ExecNonQuery("DELETE FROM FactOutputLiquids WHERE OutputLiquidsTypeId=" + TypeId + " and PatientId=" + PatientId + ""); HelperDB.DbHelperSQL.ExecNonQuery("DELETE FROM FactPersonDuty WHERE PatientId=" + PatientId + " and PersonDutyId=" + TypeId + ""); HelperDB.DbHelperSQL.ExecNonQuery("DELETE FROM OperationRecoverInInfo WHERE OperationRecordId =" + RecorId); HelperDB.DbHelperSQL.ExecNonQuery("DELETE FROM OperationRecordAnalgesia WHERE OperationRecordId =" + RecorId); HelperDB.DbHelperSQL.ExecNonQuery("DELETE FROM OperationRecoverOutInfo WHERE OperationRecordId =" + RecorId); HelperDB.DbHelperSQL.ExecNonQuery("DELETE FROM OperationRecord WHERE Id=" + RecorId + ""); } public static void DeleteEvent(int PatientId, int EventId) { HelperDB.DbHelperSQL.ExecNonQuery("DELETE FROM FactEvents WHERE EventTypeId=1 and EventId =" + EventId + " and PatientId=" + PatientId + ""); } public static DataTable FillDrugData(int PatientId, int DrugTypeId) { string strSql = " SELECT fd.Id,d.Id as DrugsId, d.Name AS DrugName ,fd.IsContinue,fd.Dosage,fd.DosageUnit,fd.DrugBeginTime, fd.DrugEndTime,fd.DrugChannel,fd.GiveDrugType,fd.Remark,d.DrugKind,[Density],[DensityUnit],[Velocity],[VelocityUnit],[BloodType] ,fd.[OperatorNo],fd.[OperatorName],fd.[OperateDate],fd.ParentId,d.AnesType,d.Comment,fd.Access FROM FactDrug fd " + "LEFT JOIN Drugs d ON d.Id = fd.DrugId " + "WHERE fd.PatientId=" + PatientId + " AND fd.DrugTypeId=" + DrugTypeId + " "; return HelperDB.DbHelperSQL.GetDataTable(strSql.ToString()); } public static DataTable FillOutFluid(int PatientId, int DrugTypeId) { string strSql = "SELECT fol.Id, fol.OutputLiquidsId,ol.Name AS OutputLiquidsName, fol.BeginTime, fol.EndTime, fol.Dosage, fol.DosageUnit,fol.Remark " + "FROM FactOutputLiquids fol " + "LEFT JOIN OutputLiquids ol ON ol.Id = fol.OutputLiquidsId " + "WHERE fol.PatientId=" + PatientId + " AND fol.OutputLiquidsTypeId=" + DrugTypeId + " "; return HelperDB.DbHelperSQL.GetDataTable(strSql.ToString()); } public static DateTime GetMaxTime(int PatientId, int TypeId) { string strSql = "SELECT ISNULL(MAX(A.MaxTime),GETDATE()) MaxTime FROM ( " + "SELECT fd.DrugEndTime AS MaxTime FROM FactDrug fd WHERE fd.DrugTypeId=" + TypeId + " and fd.PatientId=" + PatientId + " " + "UNION ALL " + "SELECT fe.EventEndTime AS MaxTime FROM FactEvents fe LEFT JOIN Events e ON e.Id =fe.EventId WHERE fe.EventTypeId=" + TypeId + " and fe.PatientId=" + PatientId + " " + "UNION ALL " + "SELECT fol.EndTime AS MaxTime FROM FactOutputLiquids fol WHERE fol.OutputLiquidsTypeId=" + TypeId + " and fol.PatientId=" + PatientId + " )A "; DataTable dt = HelperDB.DbHelperSQL.GetDataTable(strSql); return DateTime.Parse(dt.Rows[0]["MaxTime"].ToString()); } public static int GetDataCount(int RecorId, int PatientId, int TypeId) { string strSql = "SELECT SUM(A.RowCounts) AS RowCounts FROM ( " + "SELECT COUNT(*) AS RowCounts FROM FactDrug fd WHERE fd.DrugTypeId =" + TypeId + " and fd.PatientId=" + PatientId + " UNION ALL " + "SELECT COUNT(*) AS RowCounts FROM FactEvents fe WHERE fe.EventTypeId=" + TypeId + " and fe.PatientId=" + PatientId + " and EventId<>7 UNION ALL " + "SELECT COUNT(*) AS RowCounts FROM FactOutputLiquids fol WHERE OutputLiquidsTypeId=" + TypeId + " and fol.PatientId=" + PatientId + " UNION ALL " + "SELECT COUNT(*) AS RowCounts FROM FactBloodGasAnalysis fol WHERE OperationRecordId=" + RecorId + " )A "; DataTable dt = HelperDB.DbHelperSQL.GetDataTable(strSql); return int.Parse(dt.Rows[0]["RowCounts"].ToString()); } internal static void SelectSingleEntity(string oql, ref OperationRecord operationRecord) { using (SqlConnection conn = new SqlConnection(Connection.ConnectionString)) { conn.Open(); using (SqlCommand cmd = conn.CreateCommand()) { string filterString = SyntaxAnalyzer.ParseSql(oql, new OperationRecordMap()); if (filterString != string.Empty) { filterString = " where " + filterString; } cmd.CommandText = "select * from OperationRecord " + filterString; cmd.Parameters.Clear(); using (SqlDataReader dr = cmd.ExecuteReader()) { if (dr.Read()) operationRecord = DataReaderToEntity(dr, ref operationRecord); } } } } private static OperationRecord DataReaderToEntity(SqlDataReader dr, ref OperationRecord entity) { if (entity == null) { entity = new OperationRecord(); } if (dr["Id"] != System.DBNull.Value) { entity.Id = Convert.ToInt32(dr["Id"]); } if (dr["PatientId"] != System.DBNull.Value) { entity.PatientId = Convert.ToInt32(dr["PatientId"]); } if (dr["OperationApplyId"] != System.DBNull.Value) { entity.OperationApplyId = Convert.ToInt32(dr["OperationApplyId"]); } if (dr["InRoomTime"] != System.DBNull.Value) { entity.InRoomTime = Convert.ToDateTime(dr["InRoomTime"]); } if (dr["OutRoomTime"] != System.DBNull.Value) { entity.OutRoomTime = Convert.ToDateTime(dr["OutRoomTime"]); } if (dr["OperationBeginTime"] != System.DBNull.Value) { entity.OperationBeginTime = Convert.ToDateTime(dr["OperationBeginTime"]); } if (dr["OperationEndTime"] != System.DBNull.Value) { entity.OperationEndTime = Convert.ToDateTime(dr["OperationEndTime"]); } if (dr["AnesthesiaBeginTime"] != System.DBNull.Value) { entity.AnesthesiaBeginTime = Convert.ToDateTime(dr["AnesthesiaBeginTime"]); } if (dr["AnesthesiaEndTime"] != System.DBNull.Value) { entity.AnesthesiaEndTime = Convert.ToDateTime(dr["AnesthesiaEndTime"]); } if (dr["ASALevel"] != System.DBNull.Value) { entity.ASALevel = Convert.ToInt32(dr["ASALevel"]); } if (dr["SpecialCase"] != System.DBNull.Value) { entity.SpecialCase = dr["SpecialCase"].ToString(); } if (dr["Fasting"] != System.DBNull.Value) { entity.Fasting = dr["Fasting"].ToString(); } if (dr["BloodType"] != System.DBNull.Value) { entity.BloodType = dr["BloodType"].ToString(); } if (dr["OperationDate"] != System.DBNull.Value) { entity.OperationDate = dr["OperationDate"].ToString(); } if (dr["OpeSpecialCondition"] != System.DBNull.Value) { entity.OpeSpecialCondition = dr["OpeSpecialCondition"].ToString(); } if (dr["BMI"] != System.DBNull.Value) { entity.BMI = dr["BMI"].ToString(); } if (dr["BeforeDrugs"] != System.DBNull.Value) { entity.BeforeDrugs = dr["BeforeDrugs"].ToString(); } if (dr["AnaesthesiaMethodName"] != System.DBNull.Value) { entity.AnaesthesiaMethodName = dr["AnaesthesiaMethodName"].ToString(); } if (dr["AnaesthesiaTechnology"] != System.DBNull.Value) { entity.AnaesthesiaTechnology = dr["AnaesthesiaTechnology"].ToString(); } if (dr["AnaesthesiaComplication"] != System.DBNull.Value) { entity.AnaesthesiaComplication = dr["AnaesthesiaComplication"].ToString(); } if (dr["SpecialEvent"] != System.DBNull.Value) { entity.SpecialEvent = dr["SpecialEvent"].ToString(); } if (dr["SuddenSituation"] != System.DBNull.Value) { entity.SuddenSituation = dr["SuddenSituation"].ToString(); } if (dr["ConditionChage"] != System.DBNull.Value) { entity.ConditionChage = dr["ConditionChage"].ToString(); } if (dr["RescueMeasures"] != System.DBNull.Value) { entity.RescueMeasures = dr["RescueMeasures"].ToString(); } if (dr["RescueTime"] != System.DBNull.Value) { entity.RescueTime = dr["RescueTime"].ToString(); } if (dr["RescuePerson"] != System.DBNull.Value) { entity.RescuePerson = dr["RescuePerson"].ToString(); } if (dr["RescueTechnology"] != System.DBNull.Value) { entity.RescueTechnology = dr["RescueTechnology"].ToString(); } if (dr["SpileInTime"] != System.DBNull.Value) { entity.SpileInTime = Convert.ToDateTime(dr["SpileInTime"]); } if (dr["SpileOutTime"] != System.DBNull.Value) { entity.SpileOutTime = Convert.ToDateTime(dr["SpileOutTime"]); } if (dr["SpileSituation"] != System.DBNull.Value) { entity.SpileSituation = dr["SpileSituation"].ToString(); } if (dr["SpileWard"] != System.DBNull.Value) { entity.SpileWard = dr["SpileWard"].ToString(); } if (dr["SpileBeforCondition"] != System.DBNull.Value) { entity.SpileBeforCondition = dr["SpileBeforCondition"].ToString(); } if (dr["SpileAffterCondition"] != System.DBNull.Value) { entity.SpileAffterCondition = dr["SpileAffterCondition"].ToString(); } if (dr["RefluxFlag"] != System.DBNull.Value) { entity.RefluxFlag = dr["RefluxFlag"].ToString(); } if (dr["MuscleStrengthRecovery"] != System.DBNull.Value) { entity.MuscleStrengthRecovery = dr["MuscleStrengthRecovery"].ToString(); } if (dr["CoughReflex"] != System.DBNull.Value) { entity.CoughReflex = dr["CoughReflex"].ToString(); } if (dr["InOperaRoomState"] != System.DBNull.Value) { entity.InOperaRoomState = dr["InOperaRoomState"].ToString(); } if (dr["BloodPressure"] != System.DBNull.Value) { entity.BloodPressure = dr["BloodPressure"].ToString(); } if (dr["Tempeture"] != System.DBNull.Value) { entity.Tempeture = dr["Tempeture"].ToString(); } if (dr["Pulse"] != System.DBNull.Value) { entity.Pulse = dr["Pulse"].ToString(); } if (dr["Breath"] != System.DBNull.Value) { entity.Breath = dr["Breath"].ToString(); } if (dr["IsolationIndicator"] != System.DBNull.Value) { entity.IsolationIndicator = dr["IsolationIndicator"].ToString(); } if (dr["AnesMachine"] != System.DBNull.Value) { entity.AnesMachine = dr["AnesMachine"].ToString(); } if (dr["ControlledAnalgesia"] != System.DBNull.Value) { entity.ControlledAnalgesia = dr["ControlledAnalgesia"].ToString(); } if (dr["AnalgesiaModel"] != System.DBNull.Value) { entity.AnalgesiaModel = dr["AnalgesiaModel"].ToString(); } if (dr["AnalgesiaRate"] != System.DBNull.Value) { entity.AnalgesiaRate = dr["AnalgesiaRate"].ToString(); } if (dr["AnalgesiaDrug"] != System.DBNull.Value) { entity.AnalgesiaDrug = dr["AnalgesiaDrug"].ToString(); } if (dr["AldreteScore"] != System.DBNull.Value) { entity.AldreteScore = dr["AldreteScore"].ToString(); } if (dr["RouteMonitoring"] != System.DBNull.Value) { entity.RouteMonitoring = dr["RouteMonitoring"].ToString(); } if (dr["Entourage"] != System.DBNull.Value) { entity.Entourage = dr["Entourage"].ToString(); } if (dr["Remark1"] != System.DBNull.Value) { entity.Remark1 = dr["Remark1"].ToString(); } if (dr["Remark2"] != System.DBNull.Value) { entity.Remark2 = dr["Remark2"].ToString(); } if (dr["Remark3"] != System.DBNull.Value) { entity.Remark3 = dr["Remark3"].ToString(); } if (dr["Crystal"] != System.DBNull.Value) { entity.Crystal = dr["Crystal"].ToString(); } if (dr["Colloid"] != System.DBNull.Value) { entity.Colloid = dr["Colloid"].ToString(); } if (dr["InAmount"] != System.DBNull.Value) { entity.InAmount = dr["InAmount"].ToString(); } if (dr["OutAmount"] != System.DBNull.Value) { entity.OutAmount = dr["OutAmount"].ToString(); } if (dr["OperationTimeSpan"] != System.DBNull.Value) { entity.OperationTimeSpan = dr["OperationTimeSpan"].ToString(); } if (dr["AnaesthesiaTimeSpan"] != System.DBNull.Value) { entity.AnaesthesiaTimeSpan = dr["AnaesthesiaTimeSpan"].ToString(); } if (dr["RoomTimeSpan"] != System.DBNull.Value) { entity.RoomTimeSpan = dr["RoomTimeSpan"].ToString(); } if (dr["AnesthesiaDoctorTimeMinute"] != System.DBNull.Value) { entity.AnesthesiaDoctorTimeMinute = dr["AnesthesiaDoctorTimeMinute"].ToString(); } if (dr["anesthesiaDoctorSucceedTimeMinute"] != System.DBNull.Value) { entity.AnesthesiaDoctorSucceedTimeMinute = dr["anesthesiaDoctorSucceedTimeMinute"].ToString(); } if (dr["instrumentNurseTimeMinute"] != System.DBNull.Value) { entity.InstrumentNurseTimeMinute = dr["instrumentNurseTimeMinute"].ToString(); } if (dr["instrumentNurseSucceedTimeMinute"] != System.DBNull.Value) { entity.InstrumentNurseSucceedTimeMinute = dr["instrumentNurseSucceedTimeMinute"].ToString(); } if (dr["tourNurseTimeMinute"] != System.DBNull.Value) { entity.TourNurseTimeMinute = dr["tourNurseTimeMinute"].ToString(); } if (dr["tourNurseSucceedTimeMinute"] != System.DBNull.Value) { entity.TourNurseSucceedTimeMinute = dr["tourNurseSucceedTimeMinute"].ToString(); } if (dr["RecordPageCount"] != System.DBNull.Value) { entity.RecordPageCount = dr["RecordPageCount"].ToString(); } if (dr["SignName"] != System.DBNull.Value) { entity.SignName = dr["SignName"].ToString(); } if (dr["SignTime"] != System.DBNull.Value) { entity.SignTime = dr["SignTime"].ToString(); } if (dr["RoomId"] != System.DBNull.Value) { entity.RoomId = Convert.ToInt32(dr["RoomId"]); } if (dr["State"] != System.DBNull.Value) { entity.State = Convert.ToInt32(dr["State"]); } if (dr["RecoverId"] != System.DBNull.Value) { entity.RecoverId = Convert.ToInt32(dr["RecoverId"]); } if (dr["OperatorNo"] != System.DBNull.Value) { entity.OperatorNo = dr["OperatorNo"].ToString(); } if (dr["OperatorName"] != System.DBNull.Value) { entity.OperatorName = dr["OperatorName"].ToString(); } if (dr["OperateDate"] != System.DBNull.Value) { entity.OperateDate = Convert.ToDateTime(dr["OperateDate"]); } if (dr["Remarks"] != System.DBNull.Value) { entity.Remarks = dr["Remarks"].ToString(); } return entity; } } }