using AIMSExtension;
using HelperDB;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Text;
using System.Windows.Forms;
namespace AIMS.OperationAanesthesia
{
public class OpeApplyAnalyze
{
public void Analyze(string name)
{
string sqlStr = string.Format("select * from AIMS_SCHEDULES where patient_id in (select patient_id from AIMS_PATIENTS where patient_name='{0}')", name);
DataTable dt = null;
try
{
dt = PGDBHelper.GetDataTable(sqlStr);
int count = 0;
if (dt != null && dt.Rows.Count > 0)
{
Analysis(dt, ref count);
}
if (count == 0)
{
MessageBox.Show("HIS也没找到'" + name + "'病人申请 找李工看吧 ┐(─.─)┌ ");
}
}
catch (Exception ex)
{
PublicMethod.WriteLog(ex, "");
}
}
#region 解析手术申请预约信息
///
/// 解析手术申请预约信息
///
///
private void Analysis(DataTable table, ref int count)
{
if (table != null)
foreach (DataRow row in table.Rows)
{
OpeApply oa = new OpeApply();
OPPatients p;
string Site = row["APPLY_SITE"].ToString();
if (Site.Length == 0) { Site = "手术室"; }
if (Site == "内镜室") Site = "内镜室";
else Site = "手术室";
string anes = row["ANAESTHESIA_NAME"].ToString().Trim();
if (anes == "" && Site == "内镜室") anes = "全身麻醉";
DateTime time = DateTime.Parse(row["APPLY_DATE"].ToString());
string operation = row["OPERATION1_NAME"].ToString().Trim();
//if (operation.Contains("非手术室")) continue;
#region 解析手术申请
string PatientId = row["PATIENT_ID"].ToString();//HIS患者ID
string Encounterid = row["IPD_NO"].ToString();//HIS患者住院号
string PatientCaseNO = row["APD_NO"].ToString();//HIS患者病案号
string ScheduleNo = row["APPLY_NUM"].ToString(); //手术申请单号,手术序号
string VisitTiems = row["IPDNEXT"].ToString();//HIS患者住院次数
string hOrderdeptno = row["SECTION_CODE"].ToString(); //申请手术科室编码
if (PatientId == "" || Encounterid == "" || ScheduleNo == "" || GetOpeApply(ScheduleNo, row) || GetOpeApply2(ScheduleNo, row))
{
continue;
}
//select * from AIMS_PATIENTS where patient_id='825660820380852224'
int OrderDeptId = GetDepartmentName(hOrderdeptno);
if (OrderDeptId < 1)
{
continue;
}
int patientId = FullPatient(PatientId, Encounterid, VisitTiems, OrderDeptId, out p);
if (patientId == 0)
{
continue;
}
string ScheduleNo2 = "";
List OperationIds2 = new List();
if (Site == "内镜室")
foreach (DataRow row2 in table.Rows)
{
string PatientId2 = row2["PATIENT_ID"].ToString();//HIS患者ID
DateTime time2 = DateTime.Parse(row2["APPLY_DATE"].ToString());
string ScheduleNot = row2["APPLY_NUM"].ToString(); //手术申请单号,手术序号
if (PatientId == PatientId2 && time == time2 && ScheduleNot != ScheduleNo)
{
ScheduleNo2 = ScheduleNot;
string OperationRemark2 = "";
OperationIds2 = this.GetOperationIds(new string[]
{
row2["OPERATION1_ICD"].ToString()
}, new string[]
{
row2["OPERATION1_NAME"].ToString().Trim()
}, new string[]
{
"未分级"
}, out OperationRemark2);
}
}
string Reqworkno = row["APPLYDOCTORCODE"].ToString(); //申请手术医生工号
string ReqworkName = row["APPLYDOCTORNAME"].ToString(); //申请手术医生工号
int ReqworkId = GetWorkerId(Reqworkno, OrderDeptId);
DateTime Reqdatetime = time;
if (row["SUBMIT_DATE"].ToString() != "")
Reqdatetime = Convert.ToDateTime(row["SUBMIT_DATE"].ToString()); //申请手术时间
string DiagnoseRemark = "";
List DiseaseIds = this.GetDiseaseIds(new string[] { row["DIAGNOSE1_ICD"].ToString() }, new string[] { row["DIAGNOSE1_NAME"].ToString() }, out DiagnoseRemark);
List DiseaseIds2 = this.GetDiseaseIds(new string[] { row["DIAGNOSE2_ICD"].ToString() }, new string[] { row["DIAGNOSE2_NAME"].ToString() }, out DiagnoseRemark);
if (DiseaseIds.Count == 0 && DiseaseIds2.Count > 0)
{
DiseaseIds = DiseaseIds2;
}
DiagnoseRemark = "";
string OperationRemark = "";
List OperationIds = this.GetOperationIds(new string[]
{
row["OPERATION1_ICD"].ToString()
}, new string[]
{
operation
}, new string[]
{
"未分级"
}, out OperationRemark);
//foreach (var item in OperationIds2)
//{
// OperationIds.Add(item);
//}
if (Site == "内镜室")
{
OperationIds = new List() { 18036, 18037, 18038, 18039, 18040 };
}
OperationRemark = row["OPERATION_REMARK"].ToString();// row["OperationRemark"].ToString(); //拟施手术备注
string Remark = row["APPLY_REMARK"].ToString(); //手术备注
string OperationScale = row["operation5_level"].ToString(); //拟施手术综合等级
int OperationLeveId = GetOperationLeveId(OperationScale);//手术分级
string OperationPriority = row["EMERGENCY"].ToString() == "急诊" ? "急诊" : "择期"; //手术类型0,1,2(择期、急诊、日间)
if (time.Date == Reqdatetime.Date) OperationPriority = "急诊";
if (Site == "内镜室") OperationPriority = "择期";
//string Operationcut = row["OPERAITION_CUT"].ToString(); //手术切口
//int? OperationcutId = GetOperationCutId(Operationcut);
string OperationPosition = row["OPERAITION_POSITION"].ToString(); //手术部位
string OperationPositionIds = GetOperationPositionId(OperationPosition);
string OperationSite = row["OPERATION_SITE"].ToString(); //手术体位
string OperationSiteIds = GetOperationSiteId(OperationSite);
string Contagion = row["CONTAGION"].ToString(); //传染病
string ContagionIds = GetContagionIds(Contagion);
List AnaesthesiamethodIds = GetAnaesthesiaMethodIds(anes);//麻醉方式编号
int? SpecializedAnaesthesia = null; //专科麻醉类型
int IsReturnOperation = 0;
string SurgeonWorkNo = row["SURGEON_NO"].ToString(); //手术医生工号
string SurgeonWorkName = row["SURGEON_NAME"].ToString(); //手术医生工号
if (Site == "内镜室")
{
SurgeonWorkNo = "0065";
SurgeonWorkName = "毕晓艳";
}
if (SurgeonWorkNo == "" && SurgeonWorkName == "")
{
SurgeonWorkNo = Reqworkno;
SurgeonWorkName = ReqworkName;
}
List SurgeonWorkIds = GetSurgeonWorkIds(new string[] { SurgeonWorkNo }, OrderDeptId);
if (SurgeonWorkIds == null || SurgeonWorkIds.Count <= 0)
{
SurgeonWorkIds = new List();
int SurgeonWorkId = GetWorkerName(SurgeonWorkName, OrderDeptId);
if (SurgeonWorkId != -1)
SurgeonWorkIds.Add(SurgeonWorkId);
}
string FirstAssistantWorkNo = row["ASSISTANT1_NO"].ToString(); //助手工号1
string Assistant1 = GetWorkerId(FirstAssistantWorkNo, OrderDeptId).ToString();
string OperationGroup = row["OperationGroup"].ToString(); //手术分组
#endregion
#region 封装手术申请信息
oa = new OpeApply();
oa.PatientId = patientId;
//oa.PatientType = Patienttype;//患者类别
oa.ApplyDepartmentId = OrderDeptId;//申请科室编号
oa.DiagnoseRemark = DiagnoseRemark;//诊断备注
oa.OPerationRemark = OperationRemark;//手术备注
oa.Remark = Remark;//手术备注
oa.OperationLevelId = OperationLeveId;//手术分级编号
oa.OperationPriorityId = OperationPriority;//手术优先级编号0、择期、1急诊、2、日间
oa.OperationPositionId = OperationPositionIds;//手术部位
oa.Contagion = ContagionIds;//等待HIS提供传染病
oa.SpecializedAnaesthesiaId = SpecializedAnaesthesia;//专科麻醉类型
oa.IsReturnOperation = IsReturnOperation;//是否重返再手术
//oa.IsPlanReturnOperation = IsPlanReturnOperation;//是否计划重返再手术
//oa.IsNotPlanReturnOperation = IsReturnOperation == 1 && IsPlanReturnOperation == 0 ? 1 : 0;//是非否计划重返再手术
oa.OrderOperationTime = Reqdatetime;//预约手术时间
oa.OperationTimeLeight = 0; //预计手术用时(分钟)
oa.Assistant1 = int.Parse(Assistant1) < 1 ? "" : Assistant1;
//oa.Assistant2 = int.Parse(Assistant2) < 1 ? "" : Assistant2;
//oa.Assistant3 = int.Parse(Assistant3) < 1 ? "" : Assistant3;
oa.Intern = "";
oa.Other = "";
oa.IsVerify = 1;
oa.VerifyTime = time;
oa.State = 1;
if (Reqworkno != "")
{
oa.OperatorId = GetWorkerId(Reqworkno, OrderDeptId);
}
else
{
oa.OperatorId = 1;
}
oa.OperatorTime = time;
oa.ScheduleNo = ScheduleNo;
oa.ScheduleNo2 = ScheduleNo2;
#endregion
#region 保存手术申请信息
try
{
StringBuilder sb = new StringBuilder("insert into OperationApply values(");
sb.Append("" + oa.PatientId + ",");
sb.Append("" + oa.ApplyDepartmentId + ",");
sb.Append("'" + oa.OperationPriorityId + "',");
sb.Append("'" + oa.OrderOperationTime + "',");
sb.Append("0,0,0,0,");
sb.Append("'" + oa.DiagnoseRemark + "',");
sb.Append("'" + oa.OPerationRemark + "',");
sb.Append("'" + oa.OperationLevelId + "',");
sb.Append("'" + oa.Contagion + "',");
sb.Append("'" + oa.Intern + "',");
sb.Append("'" + oa.Other + "',");
sb.Append("'" + oa.VerifyTime + "',");
sb.Append("'" + ReqworkName + "',");
sb.Append("'" + oa.VerifyTime + "',");
sb.Append("'" + ReqworkName + "',");
sb.Append("NULL,NULL,NULL,2,NULL,NULL,0, ");
sb.Append("'" + oa.Remark + "',");
sb.Append("'admin','系统管理员',getdate(), ");
sb.Append("'" + Site + "',");
sb.Append("'" + oa.ScheduleNo + "',null,null,'" + oa.ScheduleNo2 + "','" + OperationGroup + "') Select @@Identity");
int operApplyId = Convert.ToInt32(DBHelper.ExecuteScalar(sb.ToString()));
if (operApplyId > 0)
{
//导入医生 手术 诊断 麻醉方式
if (SurgeonWorkIds != null && SurgeonWorkIds.Count > 0)
foreach (int PersonId in SurgeonWorkIds)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("insert into [ApplyPersonDuty](");
strSql.Append("OperationApplyId,PersonDutyId,PersonId,OperatorNo,OperatorName,OperateDate");
strSql.Append(")");
strSql.Append(" values (");
strSql.Append("" + operApplyId + ",");
strSql.Append("" + 1 + ",");
strSql.Append("" + PersonId + ",");
strSql.Append("'" + SurgeonWorkNo + "',");
strSql.Append("'" + SurgeonWorkName + "',");
strSql.Append("getdate()");
strSql.Append(")");
DBHelper.ExecNonQuery(strSql.ToString());
}
if (oa.Assistant1 != null && oa.Assistant1 != "")
{
StringBuilder strSqlAssistant = new StringBuilder();
strSqlAssistant.Append("insert into [ApplyPersonDuty](");
strSqlAssistant.Append("OperationApplyId,PersonDutyId,PersonId,OperatorNo,OperatorName,OperateDate");
strSqlAssistant.Append(")");
strSqlAssistant.Append(" values (");
strSqlAssistant.Append("" + operApplyId + ",");
strSqlAssistant.Append("" + 2 + ",");
strSqlAssistant.Append("" + oa.Assistant1 + ",");
strSqlAssistant.Append("'" + SurgeonWorkNo + "',");
strSqlAssistant.Append("'" + SurgeonWorkName + "',");
strSqlAssistant.Append("getdate()");
strSqlAssistant.Append(")");
DBHelper.ExecNonQuery(strSqlAssistant.ToString());
}
if (AnaesthesiamethodIds != null && AnaesthesiamethodIds.Count > 0)
foreach (int AnaesthesiaMethodId in AnaesthesiamethodIds)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("insert into [ApplyAnaesthesiaMethod](");
strSql.Append("OperationApplyId,AnaesthesiaMethodId,OperatorNo,OperatorName,OperateDate");
strSql.Append(")");
strSql.Append(" values (");
strSql.Append("" + operApplyId + ",");
strSql.Append("" + AnaesthesiaMethodId + ",");
strSql.Append("'" + SurgeonWorkNo + "',");
strSql.Append("'" + SurgeonWorkName + "',");
strSql.Append("getdate()");
strSql.Append(")");
DBHelper.ExecNonQuery(strSql.ToString());
}
if (DiseaseIds != null && DiseaseIds.Count > 0)
foreach (int DiseaseId in DiseaseIds)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("insert into [ApplyDiagnoseInfo](");
strSql.Append("OperationApplyId,DiagnoseId,OperatorNo,OperatorName,OperateDate");
strSql.Append(")");
strSql.Append(" values (");
strSql.Append("" + operApplyId + ",");
strSql.Append("" + DiseaseId + ",");
strSql.Append("'" + SurgeonWorkNo + "',");
strSql.Append("'" + SurgeonWorkName + "',");
strSql.Append("getdate()");
strSql.Append(")");
DBHelper.ExecNonQuery(strSql.ToString());
}
if (OperationIds != null && OperationIds.Count > 0)
foreach (int OperationId in OperationIds)
{
string OperationName = operation;
DataTable dt = DBHelper.GetDataTable("select * from Operation where id ='" + OperationId + "'");
if (dt.Rows.Count > 0)
{
OperationName = dt.Rows[0]["Name"].ToString();
}
StringBuilder strSql = new StringBuilder();
strSql.Append("insert into [ApplyOperationInfo](");
strSql.Append("OperationApplyId,OperationId,OperationName,OperatorNo,OperatorName,OperateDate");
strSql.Append(")");
strSql.Append(" values (");
strSql.Append("" + operApplyId + ",");
strSql.Append("" + OperationId + ",");
strSql.Append("'" + OperationName + "',");
strSql.Append("'" + SurgeonWorkNo + "',");
strSql.Append("'" + SurgeonWorkName + "',");
strSql.Append("getdate()");
strSql.Append(")");
DBHelper.ExecNonQuery(strSql.ToString());
}
}
MessageBox.Show("【同步完成】患者姓名:" + p.Name, "系统提示");
count++;
}
catch (Exception ex)
{
PublicMethod.WriteLog(ex, "");
}
#endregion
}
}
#endregion
#region 判断手术申请是否存在
private bool GetOpeApply(string ScheduleId, DataRow row)
{
DataTable dt = DBHelper.GetDataTable("select * from OperationApply where OrderNo='" + ScheduleId + "'");
if (dt.Rows.Count > 0)
{
return true;
}
else
{
return false;
}
}
private bool GetOpeApply2(string ScheduleId, DataRow row)
{
DataTable dt = DBHelper.GetDataTable("select * from OperationApply where OrderNo2='" + ScheduleId + "'");
if (dt.Rows.Count > 0)
{
return true;
}
else
{
return false;
}
}
#endregion
#region 解析并保存申请手术的患者信息
///
/// 解析并保存申请手术的患者信息
///
///
///
///
///
///
///
private int FullPatient(string PatientId, string Encounterid, string VisitId, int OrderDeptId, out OPPatients patient)
{
patient = new OPPatients();
int patientId = 0;
string sqlStr = string.Format("select * from {0} where patient_id='{1}' ", "AIMS_PATIENTS", PatientId);
DataTable dt = null;
try
{
dt = PGDBHelper.GetDataTable(sqlStr);
#region 解析患者信息
if (dt != null && dt.Rows.Count > 0)
{
DataRow row = dt.Rows[0];
patient.HISPatientId = PatientId;
patient.HISPatientId2 = row["Patient_id2"].ToString();
patient.InHospitalNo = Encounterid;
patient.MedicalHistoryNo = Encounterid;
string hDeptNo = row["DEPARTMENT_NO"].ToString();
patient.DepartmentId = GetDepartmentName(hDeptNo);
if (patient.DepartmentId <= 1) patient.DepartmentId = OrderDeptId;
patient.Name = row["PATIENT_NAME"].ToString();
patient.SpareEight = row["PATIENT_TYPE"].ToString();
patient.Sex = row["PATIENT_SEX"].ToString();
try
{
patient.BirthDay = Convert.ToDateTime(row["PATIENT_BIRTH"].ToString());
}
catch (Exception)
{
patient.BirthDay = DateTime.Now;
}
patient.Age = PublicMethod.GetAge(patient.BirthDay.Value);
if (row["INHOSPITALTIME"].ToString() != "")
patient.InHospitalTime = Convert.ToDateTime(row["INHOSPITALTIME"].ToString());
string PATIENT_HEIGHT = row["PATIENT_HEIGHT"].ToString().Trim();
string PATIENT_WEIGHT = row["PATIENT_WEIGHT"].ToString().Trim();
double HEIGHT = 0;
if (double.TryParse(PATIENT_HEIGHT, out HEIGHT))
{
if (HEIGHT != 0)
patient.Height = HEIGHT.ToString();
}
double WEIGHT = 0;
if (double.TryParse(PATIENT_WEIGHT, out WEIGHT))
{
if (WEIGHT != 0)
patient.Weight = WEIGHT.ToString();
}
string MedicalHistory = row["HISTORYRENARK"].ToString();
patient.BloodType = row["PATINET_BLOODTYPE"].ToString();
patient.RHBloodType = "";// row["PATINET_BLOODTYPE_RH"].ToString();
patient.Identity = row["IDNO"].ToString();
patient.FareType = row["PATIENT_CHARGE_TYPE"].ToString();
patient.EndemicArea = row["WARD_NO"].ToString();
patient.Bed = row["ROOM_NO"].ToString();
patient.ADDRESS = row["PATIENT_ADDRESS"].ToString();
patient.Contacts = row["PATIENT_CONTACTOR"].ToString();
patient.ContactsPhone = row["PATIENT_CONTACTOR_PHONE"].ToString();
if (VisitId != "")
{
patient.VisitId = Convert.ToInt32(VisitId);//VisitId
}
else
{
patient.VisitId = 1;
}
patient.IsValid = 1;
patient.OperatorId = 1;
patient.OperatorTime = DateTime.Now;
#region 保存患者信息
StringBuilder sb = new StringBuilder("insert into Oris_Patient values(");
sb.Append("'" + patient.InHospitalNo + "',");
sb.Append("'" + patient.MedicalHistoryNo + "',");
sb.Append("'" + patient.Name + "',");
sb.Append("'" + patient.Sex + "',");
sb.Append("'" + patient.BirthDay + "',");
sb.Append("'" + patient.Height + "',");
sb.Append("'" + patient.Weight + "',");
sb.Append("" + patient.DepartmentId + ",");
sb.Append("'" + patient.EndemicArea + "',");
sb.Append("'" + patient.Bed + "',");
sb.Append("'" + patient.BloodType + "',");
sb.Append("'" + patient.RHBloodType + "',");
sb.Append("'" + patient.FareType + "',");
sb.Append("'" + patient.InHospitalTime + "',");
sb.Append("'" + patient.Identity + "',");
sb.Append("'" + patient.Contacts + "',");
sb.Append("'" + patient.ContactsPhone + "',");
sb.Append("'admin','系统管理员',getdate(),");
sb.Append("'" + patient.SpareEight + "',");
sb.Append("'" + patient.HISPatientId + "',");
sb.Append("'" + patient.VisitId + "',");
sb.Append("'" + patient.ADDRESS + "',");
sb.Append("'','" + MedicalHistory.Trim() + "',null,null,null,'" + patient.HISPatientId2 + "' ,'" + patient.Age + "') Select @@Identity");
patientId = Convert.ToInt32(DBHelper.ExecuteScalar(sb.ToString()));
#endregion
}
#endregion
}
catch (Exception ex)
{
PublicMethod.WriteLog(ex, "");
}
return patientId;
}
#endregion
#region 获取科室编号
private static int GetDepartmentName(string Userdeptid)
{
DataTable dtdept = DBHelper.GetDataTable("select * from Department where Clinic='" + Userdeptid + "'");
int id = -1;
try
{
if (dtdept.Rows.Count > 0)
{
id = int.Parse(dtdept.Rows[0]["Id"].ToString());
}
}
catch (Exception)
{
}
return id;
}
#endregion
#region 获取用户编号
///
/// 获取用户编号
///
///
///
///
private static int GetWorkerId(string workNo, int OrderDeptId)
{
if (workNo == "")
{
return -1;
}
DataTable dtdept = DBHelper.GetDataTable("select * from person where No='" + workNo + "' ");// and DepartmentId=" + OrderDeptId);
int id = -1;
try
{
if (dtdept != null && dtdept.Rows.Count > 0)
{
id = int.Parse(dtdept.Rows[0]["Id"].ToString());
}
//else
//{
// WorkerAnalyze wa = new WorkerAnalyze();
// if (id == 0)
// {
// Exception ex = new Exception("工号:" + workNo + "错误!");
// PublicMethod.WriteLog(ex, "");
// }
//}
}
catch (Exception)
{
}
return id;
}
private static int GetWorkerName(string name, int OrderDeptId)
{
if (name.Trim() == "")
{
return -1;
}
DataTable dtdept = DBHelper.GetDataTable("select * from person where Name='" + name + "' ");// and DepartmentId=" + OrderDeptId);
int id = -1;
try
{
if (dtdept != null && dtdept.Rows.Count > 0)
{
id = int.Parse(dtdept.Rows[0]["Id"].ToString());
}
}
catch (Exception)
{
}
return id;
}
#endregion
#region 获取所有诊断编号
///
/// 获取所有诊断编号
///
///
///
///
private List GetDiseaseIds(string[] icds, string[] names, out string remark)
{
List result = new List();
remark = "";
try
{
for (int i = 0; i < names.Length; i++)
{
if (names[i] == "") continue;
DataTable dt = new DataTable();
if (dt == null || dt.Rows.Count <= 0)
{
string name = "";
name = names[i].Replace("\r\n", "");
name = name.Trim();
string icd = "";
icd = icds[i].Replace("\r\n", "");
icd = icd.Trim();
dt = DBHelper.GetDataTable("select * from Disease where Name ='" + name + "'");
if (dt.Rows.Count == 0)
{
DBHelper.ExecNonQuery(string.Concat(new Object[]{
"insert into Disease(ICDCode,Name,[HelpCode],UseRate,IsValid,[OperatorNo],[OperatorName],OperateDate) values('"+icd+"','"+name+"','"+PublicMethod.GetFirstLetter(name)+"',0,1,'admin','系统管理员','"+DateTime.Now+"')"}));
}
dt = DBHelper.GetDataTable("select * from Disease where Name ='" + name + "'");
}
if (dt != null && dt.Rows.Count > 0)
{
for (int j = 0; j < dt.Rows.Count; j++)
{
result.Add(int.Parse(dt.Rows[j]["Id"].ToString()));
}
}
}
}
catch (Exception)
{
}
return result;
}
#endregion
#region 获取所有手术编号
///
/// 获取所有手术编号
///
///
///
///
private List GetOperationIds(string[] icds, string[] names, string[] levels, out string remark)
{
List result = new List();
remark = "";
try
{
for (int i = 0; i < names.Length; i++)
{
if (names[i] == "") continue;
DataTable dt = new DataTable();
if (dt == null || dt.Rows.Count <= 0)
{
string name = "";
name = names[i].Replace("\r\n", "");
name = name.Trim();
dt = DBHelper.GetDataTable("select * from Operation where Name ='" + name + "'");
if (dt.Rows.Count == 0)
{
DBHelper.ExecNonQuery(string.Concat(new Object[]{
"insert into Operation(ICDCode,Name,HelpCode,IsValid,UseRate,OperatorNo,[OperatorName],OperateDate) values('"+icds[i]+"','"+name+"','"+PublicMethod.GetFirstLetter(name)+"',1,1,'admin','系统管理员','"+DateTime.Now+"')"}));
}
dt = DBHelper.GetDataTable("select * from Operation where Name ='" + name + "'");
}
if (dt.Rows.Count > 0)
{
for (int j = 0; j < dt.Rows.Count; j++)
{
result.Add(int.Parse(dt.Rows[0]["Id"].ToString()));
}
}
}
}
catch (Exception)
{
}
return result;
}
#endregion
#region 获取手术分级编号
///
/// 获取手术分级编号
///
///
///
private int GetOperationLeveId(string OperationLeve)
{
int level = 5;
try
{
if (OperationLeve == "Ⅰ" || OperationLeve == "一级")
{
level = 1;
}
else if (OperationLeve == "Ⅱ" || OperationLeve == "二级")
{
level = 2;
}
else if (OperationLeve == "Ⅲ" || OperationLeve == "三级")
{
level = 3;
}
else if (OperationLeve == "Ⅳ" || OperationLeve == "四级")
{
level = 4;
}
}
catch (Exception)
{
level = 5;
}
return level;
}
#endregion
#region 获取手术切口编号
///
/// 获取手术分级编号
///
///
///
private int? GetOperationCutId(string cut)
{
if (cut != "")
{
DataTable dt = DBHelper.GetDataTable("select * from BasicDictionary where ParentId=(select Id from BasicDictionary where Name='手术切口') and Name like '%" + cut + "%'");
if (dt.Rows.Count > 0)
{
return int.Parse((dt.Rows[0]["Id"].ToString()));
}
else
{
return null;
}
}
else
{
return null;
}
}
#endregion
#region 获取手术部位编号
///
/// 获取手术部位编号
///
///
///
private string GetOperationPositionId(string posi)
{
StringBuilder sb = new StringBuilder();
string result = "";
try
{
if (posi != "")
{
string[] strs = null;
if (posi.Contains("|"))
strs = posi.Split('|');
else if (posi.Contains(","))
strs = posi.Split(',');
else
{
strs = new string[1];
strs[0] = posi;
}
foreach (string ss in strs)
{
DataTable dt = DBHelper.GetDataTable("select * from BasicDictionary where ParentId=(select Id from BasicDictionary where Name='手术部位') and Name = '" + ss + "'");
if (dt.Rows.Count > 0)
{
sb.Append(dt.Rows[0]["Id"].ToString() + ",");
}
else
{
int pid = int.Parse(DBHelper.ExecuteScalar("select Id from BasicDictionary where Name='手术部位'").ToString());
string sql = string.Format("insert into BasicDictionary values({0},'{1}','{2}',1,0,null,1,'{3}',null) select @@Identity", pid, ss, PublicMethod.GetFirstLetter(ss), DateTime.Now.ToString());
sb.Append(DBHelper.ExecuteScalar(sql).ToString() + ",");
}
}
}
if (sb.ToString().Length > 1)
{
result = sb.ToString().Substring(0, sb.ToString().Length - 1);
}
}
catch (Exception)
{
}
return result;
}
#endregion
#region 获取手术体位编号
///
/// 获取手术体位编号
///
///
///
private string GetOperationSiteId(string site)
{
StringBuilder sb = new StringBuilder();
string result = "";
try
{
if (site != "")
{
string[] strs = null;
if (site.Contains("|"))
strs = site.Split('|');
else if (site.Contains(","))
strs = site.Split(',');
else
{
strs = new string[1];
strs[0] = site;
}
foreach (string ss in strs)
{
DataTable dt = DBHelper.GetDataTable("select * from BasicDictionary where ParentId=(select Id from BasicDictionary where Name='手术体位') and Name = '" + ss + "'");
if (dt.Rows.Count > 0)
{
sb.Append(dt.Rows[0]["Id"].ToString() + ",");
}
else
{
int pid = int.Parse(DBHelper.ExecuteScalar("select Id from BasicDictionary where Name='手术体位'").ToString());
string sql = string.Format("insert into BasicDictionary values({0},'{1}','{2}',1,0,null,1,'{3}',null) select @@Identity", pid, ss, PublicMethod.GetFirstLetter(ss), DateTime.Now.ToString());
sb.Append(DBHelper.ExecuteScalar(sql).ToString() + ",");
}
}
}
if (sb.ToString().Length > 1)
{
result = sb.ToString().Substring(0, sb.ToString().Length - 1);
}
}
catch (Exception)
{
}
return result;
}
#endregion
#region 获取传染病编号
///
/// 获取传染病编号
///
///
///
private string GetContagionIds(string cont)
{
StringBuilder sb = new StringBuilder();
string result = "";
try
{
if (cont != "")
{
string[] strs = null;
if (cont.Contains("|"))
strs = cont.Split('|');
else if (cont.Contains(","))
strs = cont.Split(',');
else
{
strs = new string[1];
strs[0] = cont;
}
foreach (string ss in strs)
{
DataTable dt = DBHelper.GetDataTable("select * from BasicDictionary where ParentId=(select Id from BasicDictionary where Name='传染病') and Name = '" + ss + "'");
if (dt.Rows.Count > 0)
{
sb.Append(dt.Rows[0]["Id"].ToString() + ",");
}
else
{
int pid = int.Parse(DBHelper.ExecuteScalar("select Id from BasicDictionary where Name='传染病'").ToString());
string sql = string.Format("insert into BasicDictionary values({0},'{1}','{2}',1,0,null,1,'{3}',null) select @@Identity", pid, ss, PublicMethod.GetFirstLetter(ss), DateTime.Now.ToString());
sb.Append(DBHelper.ExecuteScalar(sql).ToString() + ",");
}
}
}
if (sb.ToString().Length > 1)
{
result = sb.ToString().Substring(0, sb.ToString().Length - 1);
}
}
catch (Exception)
{
}
return result;
}
#endregion
#region 获取麻醉方式编号
///
/// 获取麻醉方式编号
///
///
///
private List GetAnaesthesiaMethodIds(string str)
{
List result = new List();
try
{
if (str.Contains("全麻+"))
{
result.Add(1);
str = str.Replace("全麻+", "");
}
if (str.Length > 0)
{
DataTable dt = DBHelper.GetDataTable("select * from AnaesthesiaMethod where Name = '" + str + "'");
if (dt != null && dt.Rows.Count > 0)
{
result.Add(int.Parse(dt.Rows[0]["Id"].ToString()));
}
else
{
DBHelper.ExecNonQuery(string.Concat(new Object[]{
"insert into AnaesthesiaMethod values( '"+str+"','"+PublicMethod.GetFirstLetter(str)+"',0,1,1,'admin','系统管理员','"+DateTime.Now+"','')"}));
DataTable dtt = DBHelper.GetDataTable("select * from AnaesthesiaMethod where Name = '" + str + "'");
if (dtt != null && dtt.Rows.Count > 0)
{
result.Add(int.Parse(dtt.Rows[0]["Id"].ToString()));
}
}
}
}
catch (Exception)
{
}
return result;
}
#endregion
#region 获取手术医生编号
///
/// 获取手术医生编号
///
///
///
///
private List GetSurgeonWorkIds(string[] workNos, int OrderDeptId)
{
List result = new List();
try
{
for (int i = 0; i < workNos.Length; i++)
{
if (workNos[i] != "")
{
result.Add(GetWorkerId(workNos[i], OrderDeptId));
}
}
}
catch (Exception)
{
}
return result;
}
#endregion
}
[Serializable]
public partial class OpeApply
{
private int? id;
private int? patientId;
private string patientType;
private int? applyDepartmentId;
private string diagnose;
private string diagnoseRemark;
private string operation;
private string oPerationRemark;
private int? operationLevelId;
private string operationPriorityId;
private string operationCutId;
private string operationPositionId;
private string anaesthesiaMethodId;
private string contagion;
private int? specializedAnaesthesiaId;
private int? isReturnOperation;
private int? isPlanReturnOperation;
private int? isNotPlanReturnOperation;
private DateTime? orderOperationTime;
private int? operationTimeLeight;
private string operationDoctor;
private string assistant1;
private string assistant2;
private string assistant3;
private string intern;
private string other;
private int? isVerify;
private DateTime? verifyTime;
private int? verifyWorkerId;
private DateTime? planOperationTime;
private int? planOperationRoom;
private int? tableIndex;
private string instrumentNurse;
private string instrumentNurseSucceed;
private string tourNurse;
private string tourNurseSucceed;
private string anesthesiaDoctor;
private string anesthesiaDoctorSucceed;
private int? state;
private string cancelReason;
private int? aSALevel;
private int? nYI_IA;
private int? fasting;
private int? takeMedicine;
private int? aPassApply;
private int? nPassApply;
private DateTime? planTime;
private int? planOperatorId;
private int? operatorId;
private DateTime? operatorTime;
private string remark;
private string scheduleNo;
private string scheduleNo2;
private int? execDepartmentId;
private string orderNo;
private string whereabouts;
private string cATALOGUE;
private string spareOne;
private string spareTwo;
private string spareThree;
private string spareFour;
private string spareFive;
private string spareSix;
private string spareSeven;
private string spareEight;
private string spareNine;
private string spareTen;
///
/// 编号,自增
///
public int? Id
{
get { return id; }
set { id = value; }
}
///
/// 患者编号
///
public int? PatientId
{
get { return patientId; }
set { patientId = value; }
}
///
/// 患者类别,住院\门诊
///
public string PatientType
{
get { return patientType; }
set { patientType = value; }
}
///
/// 申请部门编号
///
public int? ApplyDepartmentId
{
get { return applyDepartmentId; }
set { applyDepartmentId = value; }
}
///
/// 术前诊断
///
public string Diagnose
{
get { return diagnose; }
set { diagnose = value; }
}
///
/// 诊断备注
///
public string DiagnoseRemark
{
get { return diagnoseRemark; }
set { diagnoseRemark = value; }
}
///
/// 拟施手术
///
public string Operation
{
get { return operation; }
set { operation = value; }
}
///
/// 手术备注
///
public string OPerationRemark
{
get { return oPerationRemark; }
set { oPerationRemark = value; }
}
///
/// 手术分级编号
///
public int? OperationLevelId
{
get { return operationLevelId; }
set { operationLevelId = value; }
}
///
/// 手术优先级编号
///0、择期
///1、急诊
///2、日间
///
public string OperationPriorityId
{
get { return operationPriorityId; }
set { operationPriorityId = value; }
}
///
/// 手术切口分类,多选
///
public string OperationCutId
{
get { return operationCutId; }
set { operationCutId = value; }
}
///
/// 手术部位分类,多选
///
public string OperationPositionId
{
get { return operationPositionId; }
set { operationPositionId = value; }
}
///
/// 麻醉方式编号,多选
///
public string AnaesthesiaMethodId
{
get { return anaesthesiaMethodId; }
set { anaesthesiaMethodId = value; }
}
///
/// 传染病
///
public string Contagion
{
get { return contagion; }
set { contagion = value; }
}
///
/// 专科麻醉类型,类型由基础字典维护
///
public int? SpecializedAnaesthesiaId
{
get { return specializedAnaesthesiaId; }
set { specializedAnaesthesiaId = value; }
}
///
/// 是否重返再手术
///
public int? IsReturnOperation
{
get { return isReturnOperation; }
set { isReturnOperation = value; }
}
///
/// 计划再次手术
///
public int? IsPlanReturnOperation
{
get { return isPlanReturnOperation; }
set { isPlanReturnOperation = value; }
}
///
/// 非计划再次手术
///
public int? IsNotPlanReturnOperation
{
get { return isNotPlanReturnOperation; }
set { isNotPlanReturnOperation = value; }
}
///
/// 预约手术时间
///
public DateTime? OrderOperationTime
{
get { return orderOperationTime; }
set { orderOperationTime = value; }
}
///
/// 预计手术用时(分钟)
///
public int? OperationTimeLeight
{
get { return operationTimeLeight; }
set { operationTimeLeight = value; }
}
///
/// 手术医生
///
public string OperationDoctor
{
get { return operationDoctor; }
set { operationDoctor = value; }
}
///
/// 助理1
///
public string Assistant1
{
get { return assistant1; }
set { assistant1 = value; }
}
///
/// 助理2
///
public string Assistant2
{
get { return assistant2; }
set { assistant2 = value; }
}
///
/// 助理3
///
public string Assistant3
{
get { return assistant3; }
set { assistant3 = value; }
}
///
/// 实习生
///
public string Intern
{
get { return intern; }
set { intern = value; }
}
///
/// 其他人员
///
public string Other
{
get { return other; }
set { other = value; }
}
///
/// 是否审核,0未审核,1审核
///
public int? IsVerify
{
get { return isVerify; }
set { isVerify = value; }
}
///
/// 审核时间
///
public DateTime? VerifyTime
{
get { return verifyTime; }
set { verifyTime = value; }
}
///
/// 审核人员编号
///
public int? VerifyWorkerId
{
get { return verifyWorkerId; }
set { verifyWorkerId = value; }
}
///
/// 安排手术时间
///
public DateTime? PlanOperationTime
{
get { return planOperationTime; }
set { planOperationTime = value; }
}
///
/// 安排手术间
///
public int? PlanOperationRoom
{
get { return planOperationRoom; }
set { planOperationRoom = value; }
}
///
/// 手术台次
///
public int? TableIndex
{
get { return tableIndex; }
set { tableIndex = value; }
}
///
/// 器械护士
///
public string InstrumentNurse
{
get { return instrumentNurse; }
set { instrumentNurse = value; }
}
///
/// 器械接台护士
///
public string InstrumentNurseSucceed
{
get { return instrumentNurseSucceed; }
set { instrumentNurseSucceed = value; }
}
///
/// 巡回护士
///
public string TourNurse
{
get { return tourNurse; }
set { tourNurse = value; }
}
///
/// 巡回接台护士
///
public string TourNurseSucceed
{
get { return tourNurseSucceed; }
set { tourNurseSucceed = value; }
}
///
/// 麻醉医生
///
public string AnesthesiaDoctor
{
get { return anesthesiaDoctor; }
set { anesthesiaDoctor = value; }
}
///
/// 麻醉接台医生 改为 麻醉助手
///
public string AnesthesiaDoctorSucceed
{
get { return anesthesiaDoctorSucceed; }
set { anesthesiaDoctorSucceed = value; }
}
///
/// 申请状态
///0、待审核
///1、待排程
///2、待手术
///3、已手术
///9、作废
///
public int? State
{
get { return state; }
set { state = value; }
}
///
/// 取消申请原因
///
public string CancelReason
{
get { return cancelReason; }
set { cancelReason = value; }
}
///
/// ASA分级
///该项数据应在访视后添加到申请表
///
public int? ASALevel
{
get { return aSALevel; }
set { aSALevel = value; }
}
///
/// 心功能分级
/// 该项数据应在访视后添加到申请表
///
public int? NYI_IA
{
get { return nYI_IA; }
set { nYI_IA = value; }
}
///
/// 术前8小时禁食
///该项数据应在访视后添加到申请表
///
public int? Fasting
{
get { return fasting; }
set { fasting = value; }
}
///
/// 术晨用一小口水(5ml)服用抗高压药物。
///该项数据应在访视后添加到申请表
///
public int? TakeMedicine
{
get { return takeMedicine; }
set { takeMedicine = value; }
}
///
/// 麻醉师排程状态:0、已排程未通过,1、已排程已通过
///
public int? APassApply
{
get { return aPassApply; }
set { aPassApply = value; }
}
///
/// 护士排程状态:0、已排程未通过,1、已排程已通过
///
public int? NPassApply
{
get { return nPassApply; }
set { nPassApply = value; }
}
///
/// 排程操作时间
///
public DateTime? PlanTime
{
get { return planTime; }
set { planTime = value; }
}
///
/// 排程操作员编号
///
public int? PlanOperatorId
{
get { return planOperatorId; }
set { planOperatorId = value; }
}
///
/// 操作员
///
public int? OperatorId
{
get { return operatorId; }
set { operatorId = value; }
}
///
/// 操作时间
///
public DateTime? OperatorTime
{
get { return operatorTime; }
set { operatorTime = value; }
}
///
/// 备注
///
public string Remark
{
get { return remark; }
set { remark = value; }
}
///
/// 外键关联的实体属性
///
public string ScheduleNo
{
get { return scheduleNo; }
set { scheduleNo = value; }
}
///
/// 外键关联的实体属性
///
public string ScheduleNo2
{
get { return scheduleNo2; }
set { scheduleNo2 = value; }
}
///
/// 执行科室
///
public int? ExecDepartmentId
{
get { return execDepartmentId; }
set { execDepartmentId = value; }
}
///
/// 医嘱号
///
public string OrderNo
{
get { return orderNo; }
set { orderNo = value; }
}
///
/// 计划去向
///
public string Whereabouts
{
get { return whereabouts; }
set { whereabouts = value; }
}
///
///
///
public string CATALOGUE
{
get { return cATALOGUE; }
set { cATALOGUE = value; }
}
///
///
///
public string SpareOne
{
get { return spareOne; }
set { spareOne = value; }
}
///
///
///
public string SpareTwo
{
get { return spareTwo; }
set { spareTwo = value; }
}
///
///
///
public string SpareThree
{
get { return spareThree; }
set { spareThree = value; }
}
///
///
///
public string SpareFour
{
get { return spareFour; }
set { spareFour = value; }
}
///
///
///
public string SpareFive
{
get { return spareFive; }
set { spareFive = value; }
}
///
///
///
public string SpareSix
{
get { return spareSix; }
set { spareSix = value; }
}
///
///
///
public string SpareSeven
{
get { return spareSeven; }
set { spareSeven = value; }
}
///
///
///
public string SpareEight
{
get { return spareEight; }
set { spareEight = value; }
}
///
///
///
public string SpareNine
{
get { return spareNine; }
set { spareNine = value; }
}
///
///
///
public string SpareTen
{
get { return spareTen; }
set { spareTen = value; }
}
}
[Serializable]
public partial class OPPatients
{
private int? id;
private string hISPatientId;
private string hISPatientId2;
private string inHospitalNo;
private string medicalHistoryNo;
private int? departmentId;
private string name;
private string sex;
private string age;
private DateTime? birthDay;
private string height;
private string weight;
private string identity;
private string bloodType;
private string rHBloodType;
private string fareType;
private string endemicArea;
private string bed;
private string contacts;
private string contactsPhone;
private DateTime? inHospitalTime;
private int? visitId;
private int? isValid;
private int? operatorId;
private DateTime? operatorTime;
private string remark;
private string spareOne;
private string spareTwo;
private string spareThree;
private string spareFour;
private string spareFive;
private string spareSix;
private string spareSeven;
private string spareEight;
private string spareNine;
private string spareTen;
public string Icdname { get; set; }
public string IcdId { get; set; }
///
/// 编号,自增
///
public int? Id
{
get { return id; }
set { id = value; }
}
///
/// HIS编号
///
public string HISPatientId
{
get { return hISPatientId; }
set { hISPatientId = value; }
}
///
/// HIS编号
///
public string HISPatientId2
{
get { return hISPatientId2; }
set { hISPatientId2 = value; }
}
///
/// 住院号
///
public string InHospitalNo
{
get { return inHospitalNo; }
set { inHospitalNo = value; }
}
///
/// 病历号
///
public string MedicalHistoryNo
{
get { return medicalHistoryNo; }
set { medicalHistoryNo = value; }
}
///
/// 科室编号
///
public int? DepartmentId
{
get { return departmentId; }
set { departmentId = value; }
}
///
/// 患者姓名
///
public string Name
{
get { return name; }
set { name = value; }
}
///
/// 性别
///
public string Sex
{
get { return sex; }
set { sex = value; }
}
///
/// 出生日期
///
public DateTime? BirthDay
{
get { return birthDay; }
set { birthDay = value; }
}
///
/// 年龄
///
public string Age
{
get { return age; }
set { age = value; }
}
///
/// 身高,单位cm
///
public string Height
{
get { return height; }
set { height = value; }
}
///
/// 体重,单位kg
///
public string Weight
{
get { return weight; }
set { weight = value; }
}
///
/// 身份证号码
///
public string Identity
{
get { return identity; }
set { identity = value; }
}
///
/// 血型
///
public string BloodType
{
get { return bloodType; }
set { bloodType = value; }
}
///
/// RH血型
///
public string RHBloodType
{
get { return rHBloodType; }
set { rHBloodType = value; }
}
///
/// 医保类别
///
public string FareType
{
get { return fareType; }
set { fareType = value; }
}
///
/// 病区
///
public string EndemicArea
{
get { return endemicArea; }
set { endemicArea = value; }
}
///
/// 病区床位
///
public string Bed
{
get { return bed; }
set { bed = value; }
}
public string ADDRESS { get; set; }
///
/// 联系人
///
public string Contacts
{
get { return contacts; }
set { contacts = value; }
}
///
/// 联系人电话
///
public string ContactsPhone
{
get { return contactsPhone; }
set { contactsPhone = value; }
}
///
/// 入院时间
///
public DateTime? InHospitalTime
{
get { return inHospitalTime; }
set { inHospitalTime = value; }
}
///
/// 住院次数
///
public int? VisitId
{
get { return visitId; }
set { visitId = value; }
}
///
/// 是否有效
///
public int? IsValid
{
get { return isValid; }
set { isValid = value; }
}
///
/// 操作员编号
///
public int? OperatorId
{
get { return operatorId; }
set { operatorId = value; }
}
///
/// 操作时间
///
public DateTime? OperatorTime
{
get { return operatorTime; }
set { operatorTime = value; }
}
///
/// 备注
///
public string Remark
{
get { return remark; }
set { remark = value; }
}
///
///
///
public string SpareOne
{
get { return spareOne; }
set { spareOne = value; }
}
///
///
///
public string SpareTwo
{
get { return spareTwo; }
set { spareTwo = value; }
}
///
///
///
public string SpareThree
{
get { return spareThree; }
set { spareThree = value; }
}
///
///
///
public string SpareFour
{
get { return spareFour; }
set { spareFour = value; }
}
///
///
///
public string SpareFive
{
get { return spareFive; }
set { spareFive = value; }
}
///
///
///
public string SpareSix
{
get { return spareSix; }
set { spareSix = value; }
}
///
///
///
public string SpareSeven
{
get { return spareSeven; }
set { spareSeven = value; }
}
///
///
///
public string SpareEight
{
get { return spareEight; }
set { spareEight = value; }
}
///
///
///
public string SpareNine
{
get { return spareNine; }
set { spareNine = value; }
}
///
///
///
public string SpareTen
{
get { return spareTen; }
set { spareTen = value; }
}
}
}