AIMS/AIMS.UI/DocManager/frmDocument3.cs
2023-08-16 00:51:07 +08:00

485 lines
18 KiB
C#

using AIMS.OremrUserControl;
using AIMSBLL;
using AIMSExtension;
using AIMSModel;
using DCSoftDotfuscate;
using DevComponents.AdvTree;
using DevComponents.DotNetBar;
using DocumentManagement;
using System;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace AIMS.OperationAfter.UI
{
public partial class frmDocument3 : Form
{
//文档目录
private ucClassify ucClassify;
//患者基本信息
private PatientRecord Patient;
const int CLOSE_SIZE = 18; //关闭图标尺寸
public string PerortName;
//患者信息
DataRow vPatient = null;
/// <summary>
/// 声明保存数据时的状态
/// </summary>
public EditState _state;
public frmDocument3()
{
InitializeComponent();
//基本信息初始化
Patient = new PatientRecord();
}
public frmDocument3(PatientRecord p)
{
InitializeComponent();
Patient = p;
StringBuilder sb = new StringBuilder();
string t = " ";
sb.Append("患者:" + Patient.PatientName + t);
sb.Append("住院号:" + Patient.MdrecNo + t);
sb.Append("性别:" + Patient.Sex + t);
sb.Append("手术名称:" + Patient.OperationInfoName + t);
sb.Append("状态:" + Patient.State + t);
this.lblPatient.Text = sb.ToString();
}
/// <summary>
/// 医疗文书窗体加载
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void frmDocument3_Load_1(object sender, EventArgs e)
{
ControlExtension.GetOperationSiteRoom(labelSite, CboOperationSite, null);
if (PublicMethod.OperatorNo == "admin" || PublicMethod.RoleName.Contains("数据中心"))
{
buttonX1.Visible = true;
}
System.Drawing.Size mSize = SystemInformation.WorkingArea.Size;
txtnameOrHnum.Text = "姓名或住院号关键字";
txtnameOrHnum.ForeColor = Color.FromArgb(164, 164, 164);
dtpSearchTime.Value = DateTime.Now;
//ucClassify初始化
ucClassify = new DocumentManagement.ucClassify();
this.expandablePanel1.Controls.Add(ucClassify);
ucClassify.IsReadOnly = true;
ucClassify.Dock = DockStyle.Fill;
ucClassify.tv.NodeMouseClick += new TreeNodeMouseClickEventHandler(tv_NodeMouseClick);
ucClassify.RefreshTree(Patient.PatientId);
tsbDoc.TabItemClose += new TabStrip.UserActionEventHandler(tsbDoc_TabItemClose);
this.CboOperationSite.SelectedIndexChanged += new System.EventHandler(this.CboOperationSite_SelectedIndexChanged);
if (PublicMethod.OperatorNo == "admin" || PublicMethod.RoleName.Contains("删除医疗文书"))
{
btnDelete.Visible = true;
}
}
/// <summary>
/// 手术间信息加载到treeview
/// </summary>
private void FullTreeView()
{
treeViewPatient.Nodes.Clear();
try
{
DateTime beginTime = Convert.ToDateTime(dtpSearchTime.Value.ToString("yyyy-MM-dd 00:00:00"));
DateTime endTime = Convert.ToDateTime(dtpSearchTime.Value.ToString("yyyy-MM-dd 23:59:59"));
DataTable vPlanedOpeList = BOperationApply.GetOperationFrontDataTable(beginTime.ToString("yyyy-MM-dd 00:00:00"), endTime.ToString("yyyy-MM-dd 23:59:59"));
if (vPlanedOpeList.Rows.Count <= 0) return;
vPlanedOpeList = AIMSExtension.PublicMethod.GetNewDataTable(vPlanedOpeList, "State not IN ('退回','作废') ", "");
if (CboOperationSite.Visible == true && CboOperationSite.SelectedIndex > 0)
{
vPlanedOpeList = AIMSExtension.PublicMethod.GetNewDataTable(vPlanedOpeList, " OperationSite ='" + CboOperationSite.SelectedValue + "' ", "");
}
List<string> list = new List<string>();
foreach (var item in ControlExtension.SiteRooms)
{
foreach (DataRow po in vPlanedOpeList.Rows)
{
if (po["OperationRoom"].ToString() != "" && po["OperationRoom"].ToString() == item.Name)
{
list.Add(item.Name);
break;
}
}
}
foreach (var item in list)
{
TreeNode roomnode = new TreeNode(item);
roomnode.Tag = item;
treeViewPatient.Nodes.Add(roomnode);
foreach (DataRow vpo in vPlanedOpeList.Rows)
{
if (item == vpo["OperationRoom"].ToString())
{
TreeNode sNode = new TreeNode(vpo["PatientName"].ToString() + "-" + vpo["MdrecNo"].ToString());
sNode.Tag = vpo;
roomnode.Nodes.Add(sNode);
}
}
}
TreeNode roomnodenull = new TreeNode("未排程");
foreach (DataRow vpo in vPlanedOpeList.Rows)
{
if (vpo["OperationRoom"].ToString() == "")
{
TreeNode sNode = new TreeNode(vpo["PatientName"].ToString() + "-" + vpo["MdrecNo"].ToString());
sNode.Tag = vpo;
roomnodenull.Nodes.Add(sNode);
}
}
treeViewPatient.Nodes.Add(roomnodenull);
}
catch (Exception exp)
{
//异常处理保存
PublicMethod.WriteLog(exp, "");
}
}
String templateName = string.Empty;
/// <summary>
/// 添加医疗文书选项卡
/// </summary>
public Form frmss;
/// <summary>
/// 查询手术间患者
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnChoose_Click_1(object sender, EventArgs e)
{
this.treeViewPatient.AfterSelect -= new System.Windows.Forms.TreeViewEventHandler(this.treeViewPatient_AfterSelect);
FullTreeView();
treeViewPatient.ExpandAll();
this.treeViewPatient.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.treeViewPatient_AfterSelect);
}
private void dtpSearchTime_ValueChanged(object sender, EventArgs e)
{
panel2.Width = groupBox2.Width;
txtnameOrHnum.Text = "";
this.treeViewPatient.AfterSelect -= new System.Windows.Forms.TreeViewEventHandler(this.treeViewPatient_AfterSelect);
FullTreeView();
treeViewPatient.ExpandAll();
//if (treeViewPatient.Nodes.Count > 0) treeViewPatient.SelectedNode = treeViewPatient.Nodes[0];
this.treeViewPatient.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.treeViewPatient_AfterSelect);
}
private void txtnameOrHnum_Leave(object sender, EventArgs e)
{
if (txtnameOrHnum.Text.Equals(""))
{
txtnameOrHnum.Text = "姓名或住院号关键字";
txtnameOrHnum.ForeColor = Color.FromArgb(164, 164, 164);
}
}
private void btnBeforeDay_Click(object sender, EventArgs e)
{
dtpSearchTime.Value = dtpSearchTime.Value.AddDays(-1);
}
private void btnAfterDay_Click(object sender, EventArgs e)
{
dtpSearchTime.Value = dtpSearchTime.Value.AddDays(1);
}
private void txtnameOrHnum_KeyUp(object sender, KeyEventArgs e)
{
this.treeViewPatient.AfterSelect -= new System.Windows.Forms.TreeViewEventHandler(this.treeViewPatient_AfterSelect);
FullTreeView();
if (treeViewPatient.Nodes.Count > 0)
{
treeViewPatient.ExpandAll();
//treeViewPatient.SelectedNode = treeViewPatient.Nodes[0];
}
this.treeViewPatient.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.treeViewPatient_AfterSelect);
}
private void txtnameOrHnum_Click_1(object sender, EventArgs e)
{
txtnameOrHnum.Text = "";
txtnameOrHnum.ForeColor = Color.Black;
}
private void txtnameOrHnum_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
FullTreeView();
treeViewPatient.ExpandAll();
}
}
/// <summary>
/// 赋值患者基本信息
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void treeViewPatient_AfterSelect(object sender, TreeViewEventArgs e)
{
vPatient = treeViewPatient.SelectedNode.Tag as DataRow;
//如果有患者就是读患者的记录,否则以日期为条件取记录
if (vPatient != null)
{
//关闭打开的文档
while (tsbDoc.Tabs.Count > 0)
{
tsbDoc.SelectedTab = tsbDoc.Tabs[0];
CloseTab();
}
GetPatinentRecord(vPatient["PatientId"].ToString());
StringBuilder sb = new StringBuilder();
string t = " ";
sb.Append("患者:" + Patient.PatientName + t);
sb.Append("住院号:" + Patient.MdrecNo + t);
sb.Append("性别:" + Patient.Sex + t);
//sb.Append("手术名称:" + Patient.OperationInfoName + t);
//sb.Append("状态:" + Patient.State + t);
this.lblPatient.Text = sb.ToString();
this.ucClassify.RefreshTree(this.Patient.PatientId);
}
}
public void GetPatinentRecord(string Patientid)
{
this.Patient = PatientRecord.GetPatientRecord(int.Parse(Patientid));
}
void tsbDoc_TabItemClose(object sender, TabStripActionEventArgs e)
{
TabItem tb = (sender as DevComponents.DotNetBar.TabControl).SelectedTab;
ucDocument doc = tb.AttachedControl.Controls[0] as ucDocument;
doc.CloseMsg(tb.Text, ref e.Cancel);
}
/// <summary>
/// 文档目录点击事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void tv_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
//判断是否选择患者
if (this.Patient.PatientId == 0)
{
MessageBox.Show("请先选择患者!", "系统提示");
return;
}
TreeNode node = e.Node;
//父节点不操作
if (node.Parent == null)
{
foreach (TreeNode item in node.Nodes)
{
item.Checked = node.Checked;
}
return;
}
if (this.Patient.PatientId > 0)
{
//判断是否已经打开文书
foreach (var item in tsbDoc.Tabs)
{
if ((item as TabItem).Text.Replace("*", "").Equals(node.Text))
{
tsbDoc.SelectedTab = item as TabItem;
return;
}
}
//创建该文书标签
TabItem tb = this.tsbDoc.CreateTab(node.Text);
tsbDoc.SelectedTab = tb;
Control c = tb.AttachedControl;
ucDocument doc = new ucDocument(int.Parse(node.Name), int.Parse(node.Tag.ToString()), Patient);
doc.RefreshUc += new ucDocument.RefreshUcClassify(ucClassify.RefreshTree);
doc.ModifyT += new ucDocument.ModifyTitle(ModifyTitle);
doc.ClearT += new ucDocument.ClearTitle(ClearTitle);
doc.CloseP += new ucDocument.CloseParent(CloseTab);
doc.Parent = c;
doc.Dock = DockStyle.Fill;
doc.Show();
}
}
}
/// <summary>
/// 关闭标签
/// </summary>
private void CloseTab()
{
ucDocument doc = tsbDoc.SelectedTab.AttachedControl.Controls[0] as ucDocument;
bool isCancel = false;
doc.CloseMsg(tsbDoc.SelectedTab.Text, ref isCancel);
if (!isCancel)
{
tsbDoc.Tabs.Remove(tsbDoc.SelectedTab);
}
}
/// <summary>
/// 添加标题*号
/// </summary>
private void ModifyTitle()
{
if (!tsbDoc.SelectedTab.Text.EndsWith("*"))
{
tsbDoc.SelectedTab.Text += "*";
}
}
/// <summary>
/// 清除标题*号
/// </summary>
private void ClearTitle()
{
tsbDoc.SelectedTab.Text = tsbDoc.SelectedTab.Text.Replace("*", "");
}
private void txtnameOrHnum_TextChanged(object sender, EventArgs e)
{
}
private void dtpSearchTime_Click(object sender, EventArgs e)
{
}
private void btnSel_Click(object sender, EventArgs e)
{
//判断是否选择患者
if (this.Patient.PatientId == 0)
{
MessageBox.Show("请先选择患者!");
return;
}
string showtext = "";
//判断是否已经打开文书
foreach (var item in tsbDoc.Tabs)
{
if ((item as TabItem).Text.Contains("*"))
{
tsbDoc.SelectedTab = item as TabItem;
showtext += (item as TabItem).Text + " ";
}
}
if (showtext != "")
{
MessageBox.Show(showtext + "未保存 请确认保存后批量打印!", "系统提示");
return;
}
tsbDoc.Tabs.Clear();
List<int> Ids = new List<int>();
for (int i = 0; i < ucClassify.tv.Nodes.Count; i++)
{
TreeNode item = ucClassify.tv.Nodes[i];
if (item != null && item.Parent == null)
{
foreach (TreeNode node in item.Nodes)
{
if (node.Tag != null && int.Parse(node.Tag.ToString()) > 0 && this.Patient.PatientId > 0 && node.Checked == true)
{
Ids.Add(int.Parse(node.Tag.ToString()));
}
}
}
}
for (int i = 0; i < ucClassify.tv.Nodes.Count; i++)
{
TreeNode item = ucClassify.tv.Nodes[i];
if (item != null)
{
foreach (TreeNode node in item.Nodes)
{
if (Ids.Contains(int.Parse(node.Tag.ToString())))
{
//创建该文书标签
TabItem tb = this.tsbDoc.CreateTab(node.Text);
tsbDoc.SelectedTab = tb;
Control c = tb.AttachedControl;
ucDocument doc = new ucDocument(int.Parse(node.Name), int.Parse(node.Tag.ToString()), Patient);
doc.RefreshUc += new ucDocument.RefreshUcClassify(ucClassify.RefreshTree);
doc.ModifyT += new ucDocument.ModifyTitle(ModifyTitle);
doc.ClearT += new ucDocument.ClearTitle(ClearTitle);
doc.CloseP += new ucDocument.CloseParent(CloseTab);
doc.Parent = c;
doc.Dock = DockStyle.Fill;
doc.Show();
doc.myEditControl.ExecuteCommand("FilePrint", false, null);
ControlExtension.UPDocument(Patient.PatientId, Patient.ApplyId, doc.DModel.Id, 3, doc.DModel.TemplateId.ToString(), doc.DModel.XmlFileName);
}
}
}
}
}
private void buttonX1_Click(object sender, EventArgs e)
{
//判断是否选择患者
if (this.Patient.PatientId == 0)
{
MessageBox.Show("请先选择患者!", "系统提示");
return;
}
EMRExtension.OpenEMRS(Patient.PatientId, Patient.ApplyId);
}
private void btnDelete_Click(object sender, EventArgs e)
{
//判断是否选择患者
if (this.Patient.PatientId == 0 || tsbDoc.SelectedTab == null)
{
MessageBox.Show("请先选择患者!", "系统提示");
return;
}
PrintDocument DModel = DocumentDAL.GetDocumentbyName(tsbDoc.SelectedTab.Text, Patient.PatientId);
if (DModel != null && DModel.Id > 0)
{
DialogResult dialogResult = MessageBox.Show("确认要删除 " + tsbDoc.SelectedTab.Text + " 文书?", "系统提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (dialogResult == DialogResult.Yes)
{
DocumentDAL.DeletePrintDocument2(DModel);
PublicMethod.WriteLog("删除文书" + tsbDoc.SelectedTab.Text, Patient.PatientId);
this.ucClassify.RefreshTree(this.Patient.PatientId);
CloseTab();
}
}
}
private void CboOperationSite_SelectedIndexChanged(object sender, EventArgs e)
{
ControlExtension.SetOperationSiteRoom(CboOperationSite, null);
dtpSearchTime_ValueChanged(null, null);
}
}
}