/// <summary> /// 判读数据库中是否存在此身份证ID /// </summary> /// <param name="pId"></param> /// <returns></returns> private bool PatientInfo_IsExsist(string pId) { string sql = string.Format("select count(*) as Num from Tb_PatientInfo where P_Id='{0}'", pId); DataTable dt = _sqlite.ExcuteSqlite(sql); if (null != dt && dt.Rows.Count > 0) { if (Convert.ToInt32(dt.Rows[0]["Num"]) == 0) { return(false); } return(true); } return(false); }
private bool AddApplicationInfo() { bool ok = false; string sqlApp = "select * from Tb_Application where ApplicationID='" + ConfigHelper.AppId + "'"; DataTable dt = _sqlite.ExcuteSqlite(sqlApp); if (null != dt) { var lsp = new List <SQLiteParameter>(); if (dt.Rows.Count == 0) { sqlApp = "Insert into [Tb_Application](ApplicationID,PatientID,wardshipId,Mmol) Values(@ApplicationID,@PatientID,@wardshipId,@Mmol)"; lsp.Add(new SQLiteParameter("@ApplicationID", ConfigHelper.AppId)); lsp.Add(new SQLiteParameter("@PatientID", ConfigHelper.PatientId)); lsp.Add(new SQLiteParameter("@wardshipId", DateTime.Now.ToString("s"))); lsp.Add(new SQLiteParameter("@Mmol", lbMmol.Text.Trim())); ok = _sqlite.ExecuteSql(sqlApp, lsp.ToArray()) > 0; } else { sqlApp = "update Tb_Application set Mmol=@Mmol where ApplicationID=@ApplicationID"; lsp.Add(new SQLiteParameter("@Mmol", lbMmol.Text.Trim())); lsp.Add(new SQLiteParameter("@ApplicationID", ConfigHelper.AppId)); ok = _sqlite.ExecuteSql(sqlApp, lsp.ToArray()) > 0; } lsp.Clear(); } return(ok); }
/// <summary> /// 验证密码 /// </summary> /// <returns></returns> private bool ValidationPassword(string userName, string userPassword) { string sql = string.Format("select * from tb_Doctor where DoctorName='{0}' and DoctorPassword='******'", userName, userPassword); DataTable dt = _sqlite.ExcuteSqlite(sql); if (null != dt && dt.Rows.Count > 0) { ConfigHelper.LoginId = dt.Rows[0]["ID"].ToString(); ConfigHelper.LoginName = dt.Rows[0]["DoctorName"].ToString(); ConfigHelper.LoginPassword = userPassword; return(true); } return(false); }
private bool AddApplicationInfo() { bool ok = false; string sqlApp = "select * from Tb_Application where ApplicationID='" + ConfigHelper.AppId + "'"; DataTable dt = _sqlite.ExcuteSqlite(sqlApp); if (null != dt) { var lsp = new List <SQLiteParameter>(); if (dt.Rows.Count == 0) { sqlApp = "Insert into [Tb_Application](ApplicationID,PatientID,wardshipId,LEU,NIT,UBG,PRO,PH,BLD,KET,BIL,GLU,VC,SG) Values(@ApplicationID,@PatientID,@wardshipId,@LEU,@NIT,@UBG,@PRO,@PH,@BLD,@KET,@BIL,@GLU,@VC,@SG)"; lsp.Add(new SQLiteParameter("@ApplicationID", ConfigHelper.AppId)); lsp.Add(new SQLiteParameter("@PatientID", ConfigHelper.PatientId)); lsp.Add(new SQLiteParameter("@wardshipId", DateTime.Now.ToString("s"))); lsp.Add(new SQLiteParameter("@LEU", lb_LEU.Text.Trim())); lsp.Add(new SQLiteParameter("@NIT", lb_NIT.Text.Trim())); lsp.Add(new SQLiteParameter("@UBG", lb_UBG.Text.Trim())); lsp.Add(new SQLiteParameter("@PRO", lb_PRO.Text.Trim())); lsp.Add(new SQLiteParameter("@PH", lb_PH.Text.Trim())); lsp.Add(new SQLiteParameter("@BLD", lb_BLD.Text.Trim())); lsp.Add(new SQLiteParameter("@KET", lb_KET.Text.Trim())); lsp.Add(new SQLiteParameter("@BIL", lb_BIL.Text.Trim())); lsp.Add(new SQLiteParameter("@GLU", lb_GLU.Text.Trim())); lsp.Add(new SQLiteParameter("@VC", lb_VC.Text.Trim())); lsp.Add(new SQLiteParameter("@SG", lb_SG.Text.Trim())); ok = _sqlite.ExecuteSql(sqlApp, lsp.ToArray()) > 0; } else { sqlApp = "update Tb_Application set LEU=@LEU,NIT=@NIT,UBG=@UBG,PRO=@PRO,PH=@PH,BLD=@BLD,KET=@KET,BIL=@BIL,GLU=@GLU,VC=@VC,SG=@SG where ApplicationID=@ApplicationID"; lsp.Add(new SQLiteParameter("@LEU", lb_LEU.Text.Trim())); lsp.Add(new SQLiteParameter("@NIT", lb_NIT.Text.Trim())); lsp.Add(new SQLiteParameter("@UBG", lb_UBG.Text.Trim())); lsp.Add(new SQLiteParameter("@PRO", lb_PRO.Text.Trim())); lsp.Add(new SQLiteParameter("@PH", lb_PH.Text.Trim())); lsp.Add(new SQLiteParameter("@BLD", lb_BLD.Text.Trim())); lsp.Add(new SQLiteParameter("@KET", lb_KET.Text.Trim())); lsp.Add(new SQLiteParameter("@BIL", lb_BIL.Text.Trim())); lsp.Add(new SQLiteParameter("@GLU", lb_GLU.Text.Trim())); lsp.Add(new SQLiteParameter("@VC", lb_VC.Text.Trim())); lsp.Add(new SQLiteParameter("@SG", lb_SG.Text.Trim())); lsp.Add(new SQLiteParameter("@ApplicationID", ConfigHelper.AppId)); ok = _sqlite.ExecuteSql(sqlApp, lsp.ToArray()) > 0; } lsp.Clear(); } return(ok); }
/// <summary> /// 添加患者和数据的中间表 /// </summary> private void AddApplationInfo() { string sqlApp = "select * from Tb_Application where ApplicationID='" + ConfigHelper.AppId + "'"; DataTable dt = _sqlite.ExcuteSqlite(sqlApp); if (null != dt && dt.Rows.Count == 0) { var lsp = new List <SQLiteParameter>(); sqlApp = "Insert into [Tb_Application](ApplicationID,PatientID,wardshipId,InterpretationStatus) Values(@ApplicationID,@PatientID,@wardshipId,@InterpretationStatus)"; lsp.Add(new SQLiteParameter("@ApplicationID", ConfigHelper.AppId)); lsp.Add(new SQLiteParameter("@PatientID", _patientId)); lsp.Add(new SQLiteParameter("@wardshipId", _wardshipId)); lsp.Add(new SQLiteParameter("@InterpretationStatus", "未判读")); _sqlite.ExecuteSql(sqlApp, lsp.ToArray()); lsp.Clear(); } }
//验证SQLITE中是否存在该记录 private bool IsDataExists(string tableName, string contidition) { bool sign = false; string sql = "select count(1) from " + tableName + " where " + contidition; SqliteOptions sqlite = new SqliteOptions(); DataTable dt = sqlite.ExcuteSqlite(sql); if (dt != null && dt.Rows.Count > 0) { int count = Convert.ToInt32(dt.Rows[0][0]); if (count > 0) { sign = true; } } return(sign); }
/// <summary> /// 更新判读结果 /// </summary> /// <param name="applicationId"></param> /// <param name="beginTime"></param> /// <param name="diagnosis"></param> private void UpdateApplicationDiagnosis(string applicationId, DateTime beginTime, string diagnosis) { var so = new SqliteOptions(); string sql = string.Format("update tb_Application set InterpretationStatus='已判读' where ApplicationId='{0}'", applicationId); so.SqliteUpdate(sql); sql = string.Format("select * from Tb_Snapshot where ApplicationID='{0}'", applicationId); DataTable dso = so.ExcuteSqlite(sql); if (null != dso && dso.Rows.Count > 0) { sql = string.Format("update Tb_Snapshot set Diagnosis='{1}' where ApplicationID='{0}'", applicationId, diagnosis); so.SqliteUpdate(sql); } else { sql = string.Format(" insert into Tb_Snapshot(ID,ApplicationID,SnapshotTime,Diagnosis) Values('{0}','{1}','{2}','{3}')", Guid.NewGuid(), applicationId, beginTime.ToString("s"), diagnosis); so.SqliteAdd(sql); } }
/// <summary> /// 构造函数 /// </summary> /// <param name="pmd"> /// </param> /// <param name="isPrint">是否为快速打印</param> /// <param name="strQiBo"></param> /// <param name="isApped"></param> /// <param name="errorLead"></param> public EcgViewFrm(PatientMd pmd, bool isPrint, string strQiBo, bool isApped, string errorLead) { InitializeComponent(); lb_Time.Parent = pictureEdit3; _patientId = pmd.PatientID; _patientName = pmd.PatientName; _gender = pmd.Gender; _age = pmd.AgeStart; _idStr = pmd.P_Id; _pdStatus = pmd.Pdstatus; label2.Text = _patientName; label13.Text = _gender; _isQiBo = strQiBo; #region 尿常规、血糖、血氧、血压、体温 lb_LEU.Text = pmd.LEU; lb_BIL.Text = pmd.BIL; lb_BLD.Text = pmd.BLD; lb_DIA.Text = pmd.DIA + @" mmHg"; lb_GLU.Text = pmd.GLU; lb_KET.Text = pmd.KET; lb_Mmol.Text = pmd.Mmol + @" mmol/L"; lb_NIT.Text = pmd.NIT; lb_PH.Text = pmd.PH; lb_PRO.Text = pmd.PRO; lb_SG.Text = pmd.SG; lb_Spo2.Text = pmd.Spo2 + @" %"; lb_SYS.Text = pmd.SYS + @" mmHg"; lb_TEMP.Text = pmd.Temperature + @" ℃"; lb_UBG.Text = pmd.UBG; lb_VC.Text = pmd.VC; #endregion label19.Text = ((_age == @"0") ? " " : (_age + @" 岁")); _isApped = isApped; _applicationId = pmd.AppId; ErrorLead = errorLead; _dt1 = new DataTable(); string sqlite = "SELECT beginTime,LeadEndTime,LeadType,InterpretationStatus FROM data_packs inner join tb_Application on data_packs.ApplicationID=tb_Application.ApplicationID WHERE data_packs.applicationID='" + _applicationId + "' and isLead='" + StrIsLead + "' order by beginTime asc limit 1 offset 0"; DataTable dtBeginTime = _sqHelper.ExcuteSqlite(sqlite); if (dtBeginTime.Rows.Count == 1) { _applicationInterpretationStatus = dtBeginTime.Rows[0]["InterpretationStatus"].ToString(); _currentTime = Convert.ToDateTime(dtBeginTime.Rows[0]["beginTime"].ToString().Trim()); _beginTime = _currentTime; } sqlite = "select * from data_packs WHERE applicationID='" + _applicationId + "' and isLead='" + StrIsLead + "' order by beginTime asc"; _dt1 = _sqHelper.ExcuteSqlite(sqlite); if (_dt1.Rows.Count > 0) { if (_dt1.Rows[0]["pureData"] == DBNull.Value) { string ednPathDir = Application.StartupPath + "\\ECG_DATA_NEW" + "\\" + _applicationId + "_" + StrIsLead; if (File.Exists(ednPathDir)) { var fs = new FileStream(ednPathDir, FileMode.Open, FileAccess.Read); var br = new BinaryReader(fs, Encoding.UTF8); _dt1.Rows[0]["pureData"] = br.ReadBytes((int)fs.Length); br.Close(); //fs.Close(); } } if (!string.IsNullOrEmpty(_dt1.Rows[0]["paceLocs"].ToString())) { string[] pL = _dt1.Rows[0]["paceLocs"].ToString().Split(','); foreach (string t in pL) { PLocsView.Add(Convert.ToInt32(t)); } } } _ecgDataDicAfterFilter.Clear(); GetEcgData(_dt1); //获取原始心电数据 if (_ecgDataDicAfterFilter.Count > 0) { hScrollBar_Lead.Maximum = _ecgDataDicAfterFilter[0].Count / 1000; //hScrollBar_Lead.Maximum = GetMaximun(EcgData_Dic_AfterFilter[0].Count) / 1000; //if (hScrollBar_Lead.Maximum <= 0) //{ // hScrollBar_Lead.Maximum = 1; //} //shortLeadRemove = GetMaximun(EcgData_Dic_AfterFilter[0].Count) % 1000; } if (_applicationInterpretationStatus != "未判读" && _applicationInterpretationStatus != "已作废") { _isFastPrint = isPrint; BindSnapInfo(); // 加载患者心电图快照的时间 if (isPrint) { if (listBox1.Items.Count > 0) { EcgView_Frm_Load(null, null); } else { XtraMessageBox.Show(@"请添加参考记录,再做打印!", @"提示:", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); // lblMsg.Text = "提示:" + "请添加参考记录,再做打印!"; } } } else { if (isPrint) { XtraMessageBox.Show(@"请添加参考记录,再做打印!", @"提示:", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); //lblMsg.Text = "提示:" + "请添加参考记录,再做打印!!"; } } }
//转换数据 public void TranslateData() { if (File.Exists(Application.StartupPath + "\\EcgView.dll") && File.Exists(Application.StartupPath + "\\EcgView2.dll")) { try { AccessOptions aoc = new AccessOptions(); DataTable patients = aoc.ExcuteSqlite("select * from Tb_PatientInfo"); SqliteOptions sq = new SqliteOptions(); DateTime defaultDate = new DateTime(2012, 2, 15); if (patients != null && patients.Rows.Count > 0) { foreach (DataRow dr in patients.Rows) { #region 插入患者 string CaseID = dr["CaseID"] != DBNull.Value ? dr["CaseID"].ToString() : ""; string RoomNum = dr["RoomNum"] != DBNull.Value ? dr["RoomNum"].ToString() : ""; string PBedNum = dr["PBedNum"] != DBNull.Value ? dr["PBedNum"].ToString() : ""; string cd = dr["CreateDate"] != DBNull.Value ? Convert.ToDateTime(dr["CreateDate"]).ToString("s") : defaultDate.ToString("s"); sq.SqliteAdd("INSERT INTO [Tb_PatientInfo]([ID],[PatientName],[Gender],[Birthday],[PatientID],[PatientIdType],[Remark],[CreateDate],[P_Id],[Area],CaseID,RoomNum,PBedNum)VALUES('" + dr["ID"].ToString() + "','" + dr["PatientName"].ToString() + "','" + dr["Gender"].ToString() + "','" + dr["Birthday"].ToString() + "','" + dr["PatientID"].ToString() + "','" + dr["PatientIdType"].ToString() + "','" + dr["Remark"].ToString() + "','" + cd + "','" + dr["P_Id"].ToString() + "','" + dr["Area"].ToString() + "','" + CaseID + "','" + RoomNum + "','" + PBedNum + "')"); #endregion #region 插入合同与数据、快照、自动分析、远程报告名称 DataTable apps = aoc.ExcuteSqlite("Select distinct WardshipId,PatientID,ApplicationID,Status,CreateDate,InterpretationStatus from data_packs where PatientID='" + dr["PatientID"].ToString() + "'"); if (apps != null && apps.Rows.Count > 0) { foreach (DataRow app in apps.Rows) { string cdate = app["CreateDate"] != DBNull.Value ? Convert.ToDateTime(app["CreateDate"]).ToString("s") : defaultDate.ToString("s"); sq.SqliteAdd("insert into tb_application(ApplicationID,PatientID,Status,InterpretationStatus,CreateDate,wardshipId) values('" + app["ApplicationID"].ToString() + "','" + app["PatientID"].ToString() + "','" + app["Status"].ToString() + "','" + app["InterpretationStatus"].ToString() + "','" + cdate + "','" + app["wardshipId"].ToString() + "')"); //以上是申请,一下是心电数据 DataTable dps = aoc.ExcuteSqlite("Select ApplicationID,beginTime,pureData,dataSizePerLead,EcgFilter from data_packs where PatientID='" + app["PatientID"].ToString() + "' and ApplicationID='" + app["ApplicationID"].ToString() + "'"); if (dps != null && dps.Rows.Count > 0) { foreach (DataRow dp in dps.Rows) { SQLiteParameter sqp = new SQLiteParameter("@Hospita", DbType.Binary); sqp.Value = (byte[])dp["pureData"]; sq.ExecuteSql("insert into data_packs(ApplicationID,beginTime,pureData,dataSizePerLead,EcgFilter) values('" + dp["ApplicationID"].ToString() + "','" + Convert.ToDateTime(dp["beginTime"]).ToString("s") + "',@Hospita,'" + dp["dataSizePerLead"].ToString() + "','" + dp["EcgFilter"].ToString() + "')", new SQLiteParameter[] { sqp }); } } #region 插入快照 DataTable snapshots = aoc.ExcuteSqlite("Select * from Tb_Snapshot where PatientID='" + app["PatientID"].ToString() + "' and wardshipId='" + app["wardshipId"].ToString() + "'"); if (snapshots != null && snapshots.Rows.Count > 0) { foreach (DataRow s in snapshots.Rows) { string strType = string.Empty; try { strType = s["Type"].ToString(); } catch { } sq.SqliteAdd("insert into tb_snapshot(ID,ApplicationID,SnapshotTime,Diagnosis,Type) values('" + s["ID"].ToString() + "','" + app["ApplicationID"].ToString() + "','" + Convert.ToDateTime(s["SnapshotTime"]).ToString("s") + "','" + s["Diagnosis"].ToString() + "','" + strType + "')"); } } #endregion #region 插入自动分析 DataTable autoDiagnosis = aoc.ExcuteSqlite("Select ID,wardshipId,PatientID,SnapshotTime,P,P_R,QRS,QT_QTC,QRSDZ,RV5_SV1,BMP from AutoDiagnosis where PatientID='" + app["PatientID"].ToString() + "' and wardshipId='" + app["wardshipId"].ToString() + "'"); if (autoDiagnosis != null && autoDiagnosis.Rows.Count > 0) { foreach (DataRow ad in autoDiagnosis.Rows) { sq.SqliteAdd("INSERT INTO [AutoDiagnosis]([ID],[ApplicationID],[SnapshotTime],[P],[P_R],[QRS],[QT_QTC],[QRSDZ],[RV5_SV1],[BMP]) VALUES('" + ad["ID"].ToString() + "','" + app["ApplicationID"].ToString() + "','" + Convert.ToDateTime(ad["SnapshotTime"]).ToString("s") + "','" + ad["P"].ToString() + "','" + ad["P_R"].ToString() + "','" + ad["QRS"].ToString() + "','" + ad["QT_QTC"].ToString() + "','" + ad["QRSDZ"].ToString() + "','" + ad["RV5_SV1"].ToString() + "','" + ad["BMP"].ToString() + "')"); } } #endregion #region 插入报告名称 DataTable rts = aoc.ExcuteSqlite("Select * from Tb_ReportTitle where PatientID='" + app["PatientID"].ToString() + "' and wardshipId='" + app["wardshipId"].ToString() + "'"); if (rts != null && rts.Rows.Count > 0) { foreach (DataRow rt in rts.Rows) { string ldept = string.Empty; string sdept = string.Empty; try { ldept = rt["LastDept"].ToString(); sdept = rt["SecondDept"].ToString(); } catch { } sq.SqliteAdd("insert into Tb_ReportTitle (ID,ReportTitleName,CreateTime,[ApplicationID],[FirstUser],[SecondUser],[LastUser],[LastDept],[SecondDept]) values ('" + rt["ID"].ToString() + "','" + rt["ReportTitleName"].ToString() + "','" + Convert.ToDateTime(rt["CreateTime"]).ToString("s") + "','" + app["ApplicationID"].ToString() + "','" + rt["FirstUser"].ToString() + "','" + rt["SecondUser"].ToString() + "','" + rt["LastUser"].ToString() + "','" + ldept + "','" + sdept + "')"); } } #endregion } } #endregion } #region 插入病房和病室 DataTable rooms = aoc.ExcuteSqlite("select ID,PatientRoomName from PatientRooms"); if (rooms != null && rooms.Rows.Count > 0) { foreach (DataRow r in rooms.Rows) { if (!IsDataExists("PatientRooms", "PatientRoomName='" + r["PatientRoomName"].ToString() + "'")) { sq.SqliteAdd("insert into PatientRooms(ID,PatientRoomName) values('" + r["ID"].ToString() + "','" + r["PatientRoomName"].ToString() + "')"); } } } DataTable beds = aoc.ExcuteSqlite("select ID,PatientBedName from PatientBeds"); if (beds != null && beds.Rows.Count > 0) { foreach (DataRow b in beds.Rows) { if (!IsDataExists("PatientBeds", "PatientBedName='" + b["PatientBedName"].ToString() + "'")) { sq.SqliteAdd("insert into PatientBeds(ID,PatientBedName) values('" + b["ID"].ToString() + "','" + b["PatientBedName"].ToString() + "')"); } } } #endregion #region 插入科室和默认报告名称、医生 DataTable depts = aoc.ExcuteSqlite("Select ID,SectionName,ActiveSection,CreateDateTime from Tb_Section"); if (depts != null && depts.Rows.Count > 0) { foreach (DataRow d in depts.Rows) { if (!IsDataExists("Tb_Section", "SectionName='" + d["SectionName"].ToString() + "'")) { sq.SqliteAdd("insert into Tb_Section(ID,SectionName,ActiveSection,CreateDateTime) values('" + d["ID"].ToString() + "','" + d["SectionName"].ToString() + "','" + d["ActiveSection"].ToString() + "','" + Convert.ToDateTime(d["CreateDateTime"]).ToString("s") + "')"); } } } DataTable doctors = aoc.ExcuteSqlite("Select ID,DoctorName,ActiveDoctor,CreateDateTime from Tb_Doctor"); if (doctors != null && doctors.Rows.Count > 0) { foreach (DataRow d in doctors.Rows) { if (!IsDataExists("Tb_Doctor", "DoctorName='" + d["DoctorName"].ToString() + "'")) { sq.SqliteAdd("insert into Tb_Doctor(ID,DoctorName,ActiveDoctor,CreateDateTime) values('" + d["ID"].ToString() + "','" + d["DoctorName"].ToString() + "','" + d["ActiveDoctor"].ToString() + "','" + Convert.ToDateTime(d["CreateDateTime"]).ToString("s") + "')"); } } } string sql = "select count(1) from Tb_ReportTitle where ApplicationID is null"; DataTable dt = sq.ExcuteSqlite(sql); if (dt != null && dt.Rows.Count > 0) { DataTable titles = aoc.ExcuteSqlite("Select * from Tb_ReportTitle where PatientID is null"); if (titles != null && titles.Rows.Count > 0) { int count = Convert.ToInt32(dt.Rows[0][0]); if (count == 0) { foreach (DataRow rt in titles.Rows) { sq.SqliteAdd("insert into Tb_ReportTitle (ID,ReportTitleName,CreateTime) values ('" + rt["ID"].ToString() + "','" + rt["ReportTitleName"].ToString() + "','" + Convert.ToDateTime(rt["CreateTime"]).ToString("s") + "')"); } } } } #endregion try { File.Delete(Application.StartupPath + "\\EcgView.dll"); } catch { } } } catch (Exception ex) { FileInfo info = new FileInfo(Application.StartupPath + "\\EcgView.dll"); try { info.MoveTo(Application.StartupPath + "\\EcgView20130722.dll"); } catch { } } } }
/// <summary> /// 根据条件分页查询患者 /// </summary> /// <param name="pm">患者对象(检索条件)</param> /// <param name="pageSize">每页显示记录数</param> /// <param name="pageIndex">第几页(从第一页开始)</param> /// <param name="rowsCount">返回总记录数</param> /// <returns></returns> private DataTable QueryPatients(PatientMd pm, int pageSize, int pageIndex, ref int rowsCount) { DateTime startDate = Convert.ToDateTime(pm.CollectionStartDate); DateTime endDate = Convert.ToDateTime(pm.ConllectionEndDate); if (startDate > endDate) { string dtTmp = pm.CollectionStartDate; pm.CollectionStartDate = pm.ConllectionEndDate; pm.ConllectionEndDate = dtTmp; } int start = (pageIndex - 1) * pageSize; //从第N条开始取数据 var dt = new DataTable(); //存储分页数据 var tbl = new DataTable(); //存储行数 const string of = " CreateDate desc"; #region SQLITE 分页语句 const string strPdzt = " InterpretationStatus as PDZT,"; string sql = @"select ifnull(b.[wardshipId],a.CreateDate)- Birthday as Birthday2,IsQiBo,Folk,[Gender],Birthday,[P_Id],[PatientName],(case when( select count(1) as SumEcg from Tb_Application d where d.PatientID=a.PatientID)>0 then '有' else '无' end) as EcgDataState,(case when( select count(1) as SumStatus from Tb_Application dp where dp.PatientID=a.PatientID and Status='3') >0 then '有' else '无' end) as OpeartionState," + strPdzt + "ifnull(b.[wardshipId],a.CreateDate) as CreateDate2,a.CreateDate,a.PatientID,ID,b.CompressType from tb_patientinfo a left join tb_application b on a.[PatientID]=b.[PatientID] WHERE 1=1 "; var sbQuery = new StringBuilder(sql); var sbCount = new StringBuilder("SELECT COUNT(*) FROM(select a.[PatientID]," + strPdzt + "ifnull(b.[wardshipId],a.CreateDate) as CreateDate2,a.PatientID,ID from tb_patientinfo a left join tb_application b on a.[PatientID]=b.[PatientID] WHERE 1=1 "); var sbFilter = new StringBuilder(); if (ConfigHelper.LoginName != "admin") { sbFilter.Append(" and DoctorId = '").Append(ConfigHelper.LoginId).Append("' "); } if (!string.IsNullOrEmpty(pm.P_Id)) { sbFilter.Append(" and P_ID like '%").Append(pm.P_Id).Append("%' "); } if (!string.IsNullOrEmpty(pm.PatientName)) { sbFilter.Append(" and PatientName like '%").Append(pm.PatientName).Append("%' "); } if (!string.IsNullOrEmpty(pm.Gender) && pm.Gender != "0") { sbFilter.Append(" and Gender= '").Append(pm.Gender).Append("' "); } if (!string.IsNullOrEmpty(pm.AgeStart)) { var startTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day); sbFilter.Append(" and Birthday <='").Append(startTime.AddYears(-Convert.ToInt32(tbAgeStart.Text) + 1).ToString("yyyy-MM-dd")).Append("' "); } if (!string.IsNullOrEmpty(pm.AgeEnd)) { var date = new DateTime(DateTime.Now.Year, 1, 1); sbFilter.Append(" and Birthday >='").Append(date.AddYears(-Convert.ToInt32(tbAgeEnd.Text)).ToString("yyyy-MM-dd")).Append("' "); } var sbCjsj = new StringBuilder(); bool canCancel = !string.IsNullOrEmpty(pm.P_Id); if (!canCancel) { sbCjsj.Append(" and createdate2 >='").Append(Convert.ToDateTime(pm.CollectionStartDate).ToString("yyyy-MM-dd")).Append("'").Append(" and createdate2 <'").Append(Convert.ToDateTime(pm.ConllectionEndDate).AddDays(1).ToString("yyyy-MM-dd")).Append("'"); } if (sbFilter.Length > 0) { sbQuery.Append(sbFilter); sbCount.Append(sbFilter); } sbQuery.Append(sbCjsj); sbQuery.Append(") as t "); sbCount.Append(sbCjsj); string s = "select Birthday2,IsQiBo,Folk,[Gender],Birthday,[P_Id],strftime('%Y-%m-%d'," + of.Replace(" desc", "") + ") as CreateDate,[PatientName],[PatientID],[ID],CompressType,EcgDataState,OpeartionState,PDZT,'查阅与诊断' as EcgAnalisis,'采集' as EcgGather ,'修改' as EditPatient,'删除' as DeletePatient from ("; var sbUnion = new StringBuilder(s); sbUnion.Append(sbQuery).Append(" group by [PatientID] order by ").Append(" strftime('%Y-%m-%d %H:%M:%S', CreateDate2) desc ").Append(" limit ").Append(pageSize.ToString()).Append(" offset ").Append(start.ToString()); try { sql = sbUnion.ToString(); dt = _sqlite.ExcuteSqlite(sql); sbCount.Append(" group by a.[PatientID])"); sql = sbCount.ToString(); tbl = _sqlite.ExcuteSqlite(sql); } catch { } #endregion if (tbl != null && tbl.Rows.Count > 0) { rowsCount = Convert.ToInt32(tbl.Rows[0][0]); } if (dt != null && dt.Rows.Count > 0) { var dcFlag = new DataColumn("flag", typeof(bool)); dt.Columns.Add(dcFlag); for (int i = 0; i < dt.Rows.Count; i++) { dt.Rows[i]["flag"] = false; } } return(dt); }