/// <summary> /// 計算病程可以修改的時間範圍 /// </summary> /// <param name="node"></param> private void ComputeDateTimeMinAndMax(TreeListNode node, string datetime) { DateTime currentDateTime = Convert.ToDateTime(datetime); if (node != null && node.Tag != null) { EmrModel emrModel = node.Tag as EmrModel; if (emrModel != null && emrModel.DailyEmrModel) { for (int i = 0; i < node.ParentNode.Nodes.Count; i++) { TreeListNode subNode = node.ParentNode.Nodes[i]; EmrModel dailyEmrModel = subNode.Tag as EmrModel; if (dailyEmrModel.DisplayTime < currentDateTime) { if (m_MinDateTime == DateTime.MinValue || m_MinDateTime < dailyEmrModel.DisplayTime) { m_MinDateTime = dailyEmrModel.DisplayTime; } } else if (currentDateTime < dailyEmrModel.DisplayTime) { if (m_MaxDateTime == DateTime.MinValue || dailyEmrModel.DisplayTime < m_MaxDateTime) { m_MaxDateTime = dailyEmrModel.DisplayTime; } } } //首程修改时间限制 if (emrModel.FirstDailyEmrModel) { DataTable allRecordsDT = DS_SqlService.GetRecordsByNoofinpatContainDel((int)m_App.CurrentPatientInfo.NoOfFirstPage); var allRecords = allRecordsDT.Select(" 1=1 "); if (null != allRecords && allRecords.Count() > 0) { if (emrModel.InstanceId == -1) {//新增 DataRow lastRecord = allRecords.OrderByDescending(p => DateTime.Parse(p["captiondatetime"].ToString())).FirstOrDefault(); if (null != lastRecord && null != lastRecord["captiondatetime"] && DateTime.Parse(lastRecord["captiondatetime"].ToString()) > m_MinDateTime) { m_MinDateTime = DateTime.Parse(lastRecord["captiondatetime"].ToString()); } } else {//编辑 //比当前病历时间小的最近一个首程或其它科室病历(包含无效) DataRow preOtherRecord = allRecords.Where(p => DateTime.Parse(p["captiondatetime"].ToString()) < emrModel.DisplayTime && (p["departcode"].ToString().Trim() != emrModel.DepartCode || p["firstdailyflag"].ToString().Trim() == "1")).OrderByDescending(q => DateTime.Parse(q["captiondatetime"].ToString())).FirstOrDefault(); if (null != preOtherRecord && null != preOtherRecord["captiondatetime"] && DateTime.Parse(preOtherRecord["captiondatetime"].ToString()) > m_MinDateTime) { m_MinDateTime = DateTime.Parse(preOtherRecord["captiondatetime"].ToString()); } //编辑首程不能越过其它有效病历(上限) DataRow preValidRecord = allRecords.Where(p => DateTime.Parse(p["captiondatetime"].ToString()) < emrModel.DisplayTime && int.Parse(p["valid"].ToString()) == 1).OrderByDescending(q => DateTime.Parse(q["captiondatetime"].ToString())).FirstOrDefault(); if (null != preValidRecord && null != preValidRecord["captiondatetime"] && DateTime.Parse(preValidRecord["captiondatetime"].ToString()) > m_MinDateTime) { m_MinDateTime = DateTime.Parse(preValidRecord["captiondatetime"].ToString()); } //比当前病历时间大的最近一个首程或其它科室病历 DataRow nextOtherRecord = allRecords.Where(p => DateTime.Parse(p["captiondatetime"].ToString()) > emrModel.DisplayTime && (p["departcode"].ToString().Trim() != emrModel.DepartCode || p["firstdailyflag"].ToString().Trim() == "1")).OrderBy(q => DateTime.Parse(q["captiondatetime"].ToString())).FirstOrDefault(); if (null != nextOtherRecord && null != nextOtherRecord["captiondatetime"] && (m_MaxDateTime < DateTime.Parse("1900-01-01 00:00:00") || DateTime.Parse(nextOtherRecord["captiondatetime"].ToString()) < m_MaxDateTime)) { m_MaxDateTime = DateTime.Parse(nextOtherRecord["captiondatetime"].ToString()); } //编辑首程不能越过其它有效病历(下限) DataRow nextValidRecord = allRecords.Where(p => DateTime.Parse(p["captiondatetime"].ToString()) > emrModel.DisplayTime && int.Parse(p["valid"].ToString()) == 1).OrderBy(q => DateTime.Parse(q["captiondatetime"].ToString())).FirstOrDefault(); if (null != nextValidRecord && null != nextValidRecord["captiondatetime"] && (m_MaxDateTime < DateTime.Parse("1900-01-01 00:00:00") || DateTime.Parse(nextValidRecord["captiondatetime"].ToString()) < m_MaxDateTime)) { m_MaxDateTime = DateTime.Parse(nextValidRecord["captiondatetime"].ToString()); } } } } } } }