AIMS/AIMSEntity/Extensions/SelectPatient.cs
2022-11-02 23:13:38 +08:00

225 lines
17 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using AIMSModel;
using DrawGraph;
using AIMSDAL;
namespace AIMSBLL
{
public class SelectPatient
{
public static DataTable GetSelectPatientDataTable(DateTime BeginDate)
{
string strSql = "SELECT of1.PatientId, of1.ApplyId, of1.ApplyDepName, of1.OperationType, of1.MdrecNo, of1.PatientName, " +
"of1.ApplyOperationInfoName, of1.OperationDoctor, " +
"of1.AnesthesiaDoctor,of1.OperationRoomId " +
"FROM V_OperationFront of1 WHERE of1.State in('已排程','已访视') and of1.PlanOperationTime>='" + BeginDate + "' AND of1.PlanOperationTime<'" + BeginDate.AddDays(1) + "'";
return HelperDB.DbHelperSQL.GetDataTable(strSql.ToString());
}
public static DataTable GetSelectPatientDataTable(DateTime BeginDate, string Room)
{
string strSql = "SELECT of1.ApplyId Id, of1.PatientId, of1.ApplyId, of1.ApplyDepName, of1.OperationType, of1.MdrecNo, of1.PatientName, " +
"of1.ApplyOperationInfoName, of1.OperationDoctor, " +
"of1.AnesthesiaDoctor,of1.OperationRoomId , of1.State ,of1.Sex,[dbo].[funGetAge](of1.BirthDay,getdate()) age,of1.PlanOperationTime,of1.InstrumentNurse,of1.TourNurse,of1.ApplyDiagnoseInfoName,of1.OperationRoom ,of1.Contagion,of1.OrderOperationTime " +
"FROM V_OperationFront of1 WHERE of1.State in('已审核','预排程','已排程','已访视') and of1.OrderOperationTime>='" + BeginDate + "' AND of1.OrderOperationTime<'" + BeginDate.AddDays(1) + "'";
if (Room != "" && Room != "-1") strSql += " and of1.OperationRoomId='" + Room + "'";
return HelperDB.DbHelperSQL.GetDataTable(strSql.ToString());
}
public static DataTable GetRelieveLockingPatientDataTable(DateTime BeginDate)
{
string strSql = "SELECT of1.PatientId, of1.ApplyId, of1.ApplyDepName, of1.OperationType, of1.MdrecNo, of1.PatientName, of1.ApplyOperationInfoName, of1.OperationDoctor, of1.AnesthesiaDoctor,of1.OperationRoomId,of2.State FROM V_OperationDoing of2 left join[dbo].[V_OperationFront] of1 on of1.PatientId = of2.PatientId WHERE of1.State in( '手术中','手术结束') and of2.InRoomTime >= '" + BeginDate + "' AND of2.InRoomTime<'" + BeginDate.AddDays(1) + "'";
return HelperDB.DbHelperSQL.GetDataTable(strSql.ToString());
}
public static DataTable GetRelieveLockingPatientDataTable(DateTime BeginDate, string Room)
{
string strSql = "SELECT of2.Id,of1.PatientId, of1.ApplyId, of1.ApplyDepName, of1.OperationType, of1.MdrecNo, of1.PatientName, of2.OperationInfoNames ApplyOperationInfoName, of2.OperationDoctor, of2.AnesthesiaDoctor,of2.OperationRoomId,of2.State ,of1.Sex,[dbo].[funGetAge](of1.BirthDay,getdate()) age,of2.InRoomTime PlanOperationTime,of2.Nurse InstrumentNurse,of2.Nurse2 TourNurse,of2.DiagnoseInfoName ApplyDiagnoseInfoName ,of2.OperationRoom ,of1.Contagion,of1.OrderOperationTime FROM V_OperationDoing of2 left join[dbo].[V_OperationFront] of1 on of1.PatientId = of2.PatientId WHERE of2.State in( '手术中','手术结束','停止手术') and of2.InRoomTime >= '" + BeginDate + "' AND of2.InRoomTime<'" + BeginDate.AddDays(1) + "' and RecoverId=1";
if (Room != "" && Room != "-1") strSql += " and of1.OperationRoomId='" + Room + "'";
strSql += " order by [StateId] asc";
return HelperDB.DbHelperSQL.GetDataTable(strSql.ToString());
}
public static DataTable GetTodayDoOpePatientDataTable(DateTime BeginDate)
{
string strSql = "SELECT of2.Id,of1.PatientId, of1.ApplyId, of1.ApplyDepName, of1.OperationType, of1.MdrecNo, of1.PatientName, of2.OperationInfoNames ApplyOperationInfoName, of2.OperationDoctor, of2.AnesthesiaDoctor,of2.OperationRoomId,of2.State ,of1.Sex,[dbo].[funGetAge](of1.BirthDay,getdate()) age,of2.InRoomTime PlanOperationTime,of2.Nurse InstrumentNurse,of2.Nurse2 TourNurse,of2.DiagnoseInfoName ApplyDiagnoseInfoName ,of2.OperationRoom ,of1.Contagion FROM V_OperationDoing of2 left join[dbo].[V_OperationFront] of1 on of1.PatientId = of2.PatientId WHERE of2.State in( '手术中') and of2.InRoomTime >= '" + BeginDate + "' AND of2.InRoomTime<'" + BeginDate.AddDays(1) + "' and RecoverId=1";
strSql += " order by [StateId] asc";
return HelperDB.DbHelperSQL.GetDataTable(strSql.ToString());
}
public static DataTable GetRecoverPatientDataTable(DateTime BeginDate)
{
string strSql = "SELECT of2.Id,of1.PatientId, of1.ApplyId, of1.ApplyDepName, of1.OperationType, of1.MdrecNo, of1.PatientName, of2.OperationInfoNames ApplyOperationInfoName, of2.OperationDoctor, of2.AnesthesiaDoctor,of2.OperationRoomId,of2.State ,of1.Sex,[dbo].[funGetAge](of1.BirthDay,getdate()) age,of2.OutRoomTime ,of2.Nurse InstrumentNurse,of2.Nurse2 TourNurse,of2.DiagnoseInfoName ApplyDiagnoseInfoName ,of2.OperationRoom,of2.Whereabouts FROM V_OperationDoing of2 left join[dbo].[V_OperationFront] of1 on of1.PatientId = of2.PatientId WHERE of1.State in( '手术结束') and of2.Whereabouts='恢复室' and of2.OutRoomTime >= '" + BeginDate + "' AND of2.OutRoomTime<'" + BeginDate.AddDays(1) + "' and RecoverId=1 and of2.Id not in (select iD from OperationRecord where RecoverId<>1)";
return HelperDB.DbHelperSQL.GetDataTable(strSql.ToString());
}
public static DataTable GetRecoverPatientOutDataTable(DateTime BeginDate)
{
string strSql = "SELECT of2.Id,of1.PatientId, of1.ApplyId, of1.ApplyDepName, of1.OperationType, of1.MdrecNo, of1.PatientName, of2.OperationInfoNames ApplyOperationInfoName, of2.OperationDoctor, of2.AnesthesiaDoctor,of2.OperationRoomId,of2.State ,of1.Sex,[dbo].[funGetAge](of1.BirthDay,getdate()) age,of2.OutRoomTime ,of2.Nurse InstrumentNurse,of2.Nurse2 TourNurse,of2.DiagnoseInfoName ApplyDiagnoseInfoName ,of2.OperationRoom FROM V_OperationDoing of2 left join[dbo].[V_OperationFront] of1 on of1.PatientId = of2.PatientId WHERE of1.State in( '麻醉恢复结束') and of2.OutRoomTime >= '" + BeginDate + "' AND of2.OutRoomTime<'" + BeginDate.AddDays(1) + "' and RecoverId=2 order by OutRoomTime desc ";
return HelperDB.DbHelperSQL.GetDataTable(strSql.ToString());
}
public static DataTable GetSelectPatientDataTable(DateTime BeginDate, DateTime EndDate, bool isLoginPerson, string person, bool isEnOpe)
{
string strSql = "SELECT of1.PatientId, of1.ApplyId, of1.ApplyDepName, of1.OperationType, of1.MdrecNo, of1.PatientName, " +
"of1.ApplyOperationInfoName, of1.OperationDoctor, of1.State ," +
"of1.AnesthesiaDoctor,of1.OperationRoomId,of1.InstrumentNurse,of1.TourNurse " +
"FROM V_OperationFront of1 WHERE of1.OrderOperationTime>='" + BeginDate + "' AND of1.OrderOperationTime<'" + EndDate + "' ";
if (isLoginPerson == true) strSql += " and AnesthesiaDoctor like '%" + person + "%'";
if (isEnOpe == true) strSql += " and state ='手术结束'";
return HelperDB.DbHelperSQL.GetDataTable(strSql.ToString());
}
public static DataTable GetSelectPatientChart()
{
string strSql = "select CONVERT(nvarchar(7), InRoomTime,120) dat, SUM(ROUND((DATEDIFF(minute, OperationBeginTime, OperationEndTime)) / CONVERT(FLOAT, 60), 1)) AS DiffDate from V_OperationDoing group by CONVERT(nvarchar(7), InRoomTime, 120)";
return HelperDB.DbHelperSQL.GetDataTable(strSql.ToString());
}
public static DataTable GetSelectPatientChart2()
{
string strSql = "select CONVERT(nvarchar(7), InRoomTime,120) dat,COUNT(*) con from V_OperationDoing group by CONVERT(nvarchar(7), InRoomTime,120) ";
return HelperDB.DbHelperSQL.GetDataTable(strSql.ToString());
}
public static DataTable GetRecoverSelectPatientDataTable(DateTime BeginDate)
{
string strSql = "SELECT of1.PatientId, of1.ApplyId, of1.ApplyDepName, of1.OperationType, of1.MdrecNo, of1.PatientName, " +
"or2.OperationInfoName AS ApplyOperationInfoName,or2.OperationDoctor,or2.AnesthesiaDoctor,of1.OperationRoomId " +
"FROM V_OperationFront of1 " +
"LEFT JOIN V_OperationDoing or2 ON or2.PatientId =of1.PatientId " +
"WHERE of1.State ='手术结束' and or2.InRoomTime>='" + BeginDate + "' AND or2.InRoomTime<'" + BeginDate.AddDays(1) + "'";
return HelperDB.DbHelperSQL.GetDataTable(strSql.ToString());
}
public static DataTable GetRecoverLockingPatientDataTable(DateTime BeginDate)
{
string strSql = "SELECT of2.Id,of1.PatientId, of1.ApplyId, of1.ApplyDepName, of1.OperationType, of1.MdrecNo, of1.PatientName, of2.OperationInfoNames ApplyOperationInfoName, of2.OperationDoctor, of2.AnesthesiaDoctor,of2.OperationRoomId,of2.State ,of1.Sex,[dbo].[funGetAge](of1.BirthDay,getdate()) age,of2.InRoomTime,of2.Nurse InstrumentNurse,of2.Nurse2 TourNurse,of2.DiagnoseInfoName ApplyDiagnoseInfoName ,of2.OperationRoom,(select OutRoomTime from OperationRecord where OperationRecord.RecoverId=1 and OperationRecord.PatientId=of2.PatientId) OutRoomTime FROM V_OperationDoing of2 left join[dbo].[V_OperationFront] of1 on of1.PatientId = of2.PatientId WHERE of2.State in( '麻醉恢复中') and of2.InRoomTime >= '" + BeginDate + "' AND of2.InRoomTime<'" + BeginDate.AddDays(1) + "' and RecoverId=2 ";
strSql += " order by [StateId] asc";
return HelperDB.DbHelperSQL.GetDataTable(strSql.ToString());
}
public static void UpdateApplyState(int PatientId, int ApplyId)
{
try
{
HelperDB.DbHelperSQL.BeginTrans();
BOperationApply.UpdateApplyState(ApplyId, 6); //修改状态为手术中
//手术诊断
List<int> ApplyDiagnoseIdList = BApplyDiagnoseInfo.GetApplyDiagnoseIdList(ApplyId);
for (int i = 0; i < ApplyDiagnoseIdList.Count; i++)
{
FactDiagnoseInfo FactDiagnoseInfoObj = new FactDiagnoseInfo();
FactDiagnoseInfoObj.PatientId = PatientId;
FactDiagnoseInfoObj.ApplyId = ApplyId;
FactDiagnoseInfoObj.DiagnoseId = ApplyDiagnoseIdList[i];
FactDiagnoseInfoObj.OperatorNo = AIMSExtension.PublicMethod.OperatorNo;
FactDiagnoseInfoObj.OperatorName = AIMSExtension.PublicMethod.OperatorName;
FactDiagnoseInfoObj.OperateDate = AIMSExtension.PublicMethod.SystemDate();
BFactDiagnoseInfo.Add(FactDiagnoseInfoObj);
}
//实施手术
List<ApplyOperationInfo> ApplyOperationInfoList = BApplyOperationInfo.GetApplyOperationIdList(ApplyId);
for (int i = 0; i < ApplyOperationInfoList.Count; i++)
{
FactOperationInfo FactOperationInfoObj = new FactOperationInfo();
FactOperationInfoObj.PatientId = PatientId;
FactOperationInfoObj.ApplyId = ApplyId;
FactOperationInfoObj.OperationId = ApplyOperationInfoList[i].OperationId.Value;
FactOperationInfoObj.OperationName = ApplyOperationInfoList[i].OperationName;
FactOperationInfoObj.LeftRemark = ApplyOperationInfoList[i].LeftRemark;
FactOperationInfoObj.RightRemark = ApplyOperationInfoList[i].RightRemark;
FactOperationInfoObj.OperatorNo = AIMSExtension.PublicMethod.OperatorNo;
FactOperationInfoObj.OperatorName = AIMSExtension.PublicMethod.OperatorName;
FactOperationInfoObj.OperateDate = AIMSExtension.PublicMethod.SystemDate();
BFactOperationInfo.Add(FactOperationInfoObj);
}
//实施麻醉
List<int> ApplyAnaesthesiaMethodList = BApplyAnaesthesiaMethod.GetApplyAnaesthesiaMethodList(ApplyId);
for (int i = 0; i < ApplyAnaesthesiaMethodList.Count; i++)
{
FactAnaesthesiaMethod FactAnaesthesiaMethodObj = new FactAnaesthesiaMethod();
FactAnaesthesiaMethodObj.PatientId = PatientId;
FactAnaesthesiaMethodObj.ApplyId = ApplyId;
FactAnaesthesiaMethodObj.AnaesthesiaMethodId = ApplyAnaesthesiaMethodList[i];
FactAnaesthesiaMethodObj.OperatorNo = AIMSExtension.PublicMethod.OperatorNo;
FactAnaesthesiaMethodObj.OperatorName = AIMSExtension.PublicMethod.OperatorName;
FactAnaesthesiaMethodObj.OperateDate = AIMSExtension.PublicMethod.SystemDate();
BFactAnaesthesiaMethod.Add(FactAnaesthesiaMethodObj);
}
//手术部位
List<int> ApplyOperationPositionList = BApplyOperationPosition.GetApplyOperationPositionIdList(ApplyId);
for (int i = 0; i < ApplyOperationPositionList.Count; i++)
{
FactOperationPosition FactOperationPositionObj = new FactOperationPosition();
FactOperationPositionObj.PatientId = PatientId;
FactOperationPositionObj.ApplyId = ApplyId;
FactOperationPositionObj.OperationPositionId = ApplyOperationPositionList[i];
FactOperationPositionObj.OperatorNo = AIMSExtension.PublicMethod.OperatorNo;
FactOperationPositionObj.OperatorName = AIMSExtension.PublicMethod.OperatorName;
FactOperationPositionObj.OperateDate = AIMSExtension.PublicMethod.SystemDate();
BFactOperationPosition.Add(FactOperationPositionObj);
}
//手术切口
List<int> ApplyOperationCutTypeList = BApplyOperationCutType.GetApplyOperationCutTypeIdList(ApplyId);
for (int i = 0; i < ApplyOperationCutTypeList.Count; i++)
{
FactOperationCutType FactOperationCutTypeObj = new FactOperationCutType();
FactOperationCutTypeObj.PatientId = PatientId;
FactOperationCutTypeObj.ApplyId = ApplyId;
FactOperationCutTypeObj.OperationCutTypeId = ApplyOperationCutTypeList[i];
FactOperationCutTypeObj.OperatorNo = AIMSExtension.PublicMethod.OperatorNo;
FactOperationCutTypeObj.OperatorName = AIMSExtension.PublicMethod.OperatorName;
FactOperationCutTypeObj.OperateDate = AIMSExtension.PublicMethod.SystemDate();
BFactOperationCutType.Add(FactOperationCutTypeObj);
}
//医生信息
DataTable dt = BApplyPersonDuty.GetPersonDataTable(ApplyId);
for (int i = 0; i < dt.Rows.Count; i++)
{
FactPersonDuty FactPersonDutyObj = new FactPersonDuty();
FactPersonDutyObj.PatientId = PatientId;
FactPersonDutyObj.ApplyId = ApplyId;
FactPersonDutyObj.PersonDutyId = int.Parse(dt.Rows[i]["PersonDutyId"].ToString());
FactPersonDutyObj.PersonId = int.Parse(dt.Rows[i]["PersonId"].ToString());
FactPersonDutyObj.OperatorNo = AIMSExtension.PublicMethod.OperatorNo;
FactPersonDutyObj.OperatorName = AIMSExtension.PublicMethod.OperatorName;
FactPersonDutyObj.OperateDate = AIMSExtension.PublicMethod.SystemDate();
BFactPersonDuty.Add(FactPersonDutyObj);
}
//增加入室事件
Events EventsObj = BEvents.GetModelByName("入室");
if (EventsObj.Name != null)
{
FactEvents FactEventsObj = new FactEvents();
FactEventsObj.EventId = EventsObj.Id;
FactEventsObj.EventTypeId = 1;
FactEventsObj.EventBeginTime = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd HH:mm:00"));
FactEventsObj.EventEndTime = FactEventsObj.EventBeginTime;
FactEventsObj.IsContinue = 0;
FactEventsObj.PatientId = PatientId;
FactEventsObj.OperatorNo = AIMSExtension.PublicMethod.OperatorNo;
FactEventsObj.OperatorName = AIMSExtension.PublicMethod.OperatorName;
FactEventsObj.OperateDate = AIMSExtension.PublicMethod.SystemDate();
BFactEvents.Add(FactEventsObj);
}
HelperDB.DbHelperSQL.CommitTrans();
}
catch
{
HelperDB.DbHelperSQL.RollbackTrans();
}
}
}
}