体检系统架构
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

1176 lines
43 KiB

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Printing;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DevExpress.XtraGrid.Views.Base;
using DevExpress.XtraGrid.Views.Grid;
using PEIS.Base;
using PEIS.Entity;
using PEIS.Event;
using PEIS.Model;
using PEIS.Model.Exam;
using PEIS.Presenter;
using PEIS.Utils;
using PEIS.View.UControl;
using static PEIS.Utils.ColorHelper;
namespace PEIS.View.Exam
{
public partial class TotalForm : ViewBase, ITotalView
{
/// <summary>
/// 创建Presenter
/// </summary>
/// <returns></returns>
protected override object CreatePresenter()
{
return new TotalPresenter(this);
}
private HistoryView historyView;
private readonly string _watermarkTeam = @"团检号或团队名称";
private readonly string _watermarkInfo = @"体检号或体检者姓名";
// 定义一个委托
public delegate void SelectedPatientDelegate(long? eid);
// 声明一个事件,供父窗体订阅
public event SelectedPatientDelegate SelectedPatientEvent;
#region 属性
/// <summary>
/// 体检者列表
/// </summary>
private List<EnrollmentPatient> _patientList = new List<EnrollmentPatient>();
/// <summary>
/// 当前选中体检者
/// </summary>
private EnrollmentPatient _patient = new EnrollmentPatient();
/// <summary>
/// 科室分检
/// </summary>
private List<ExamPart> _examPart = new List<ExamPart>();
/// <summary>
/// 结论
/// </summary>
private List<ExamConclusion> _examConclusion = new List<ExamConclusion>();
/// <summary>
/// 检验报告结果
/// </summary>
private List<ExamResult> _lisReport = new List<ExamResult>();
/// <summary>
/// 是否是体检科
/// </summary>
private bool _isPeidDeptUser;
#endregion 属性
public TotalForm()
{
InitializeComponent();
//页面显示
Shown += TotalForm_Shown;
DgvPatient.RowClick += DgvPatientRowClick;
//RadioButtonClick
RbStatus1.Click += RadioButton_Click;
RbStatus2.Click += RadioButton_Click;
// 输入体检号回车
//txtId.KeyDown += TxtId_KeyDown;
OpsConclusion.TsmiRefresh.Text = "上移";
OpsConclusion.TsmiRefresh.Image = Properties.Resources.shang;
OpsConclusion.TsmiAdd.Text = "下移";
OpsConclusion.TsmiAdd.Image = Properties.Resources.xia;
//结论-排序
OpsConclusion.TsmiRefresh.Click += (s, e) =>
{
ConclusionSort(-1);
};
OpsConclusion.TsmiAdd.Click += (s, e) =>
{
ConclusionSort(1);
};
//结论-删除
OpsConclusion.TsmiDelete.Click += ConclusionDelete_Click;
//结论-保存
OpsConclusion.TsmiSave.Click += ConclusionSave_Click;
// 切换Tab页加载数据
TabPart.SelectedPageChanged += TabPart_SelectedPageChanged;
//完结
TsmiFinish.Click += (s, e) =>
{
if (!_isPeidDeptUser)
{
Global.MsgWarn("权限不足!");
return;
}
var dept = DAOHelp.GetDataBySQL<ExamPart>($@"SELECT a.DeptName FROM Enrollment_FeeItem a
LEFT JOIN Exam_Part b ON a.EID = b.EID AND a.DeptCode = b.DeptCode
LEFT JOIN Dict_FeeItem C ON a.KeyNo = C.KeyNo
WHERE a.EID = {_patient.ID} AND a.GiveUpTime IS NULL AND a.ItemClass <> '检验' AND b.VerifyTime IS NULL AND C.IsHide=0");
if (dept.Count > 0)
{
var result = MessageBox.Show($@"{dept.FirstOrDefault()?.DeptName} 存在未审核的检查项目,是否仍要完结?", @"完结",
MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (result != DialogResult.Yes) return;
}
Finish?.Invoke(this, new Args<bool>()
{
ID = _patient.ID,
Code = Global.currentUser.Code,
Name = Global.currentUser.Name,
Item = true
});
};
// 取消完结
TsmiFinishCancel.Click += (s, e) =>
{
try
{
if (!_isPeidDeptUser)
{
Global.MsgWarn("权限不足!");
return;
}
Finish?.Invoke(this, new Args<bool>()
{
ID = _patient.ID,
Code = Global.currentUser.Code,
Name = Global.currentUser.Name,
Item = false
});
}
catch (Exception exception)
{
Console.WriteLine(exception);
throw;
}
};
TsmiWeChatViewReport.Click += (s, e) =>
{
var status = !_patient.IsWeChatView ?? false;
if (_patient.FinishTime == null)
{
Global.MsgWarn("体检未完结!");
return;
}
WeChatViewRpt?.Invoke(this, new Args<bool>()
{
ID = _patient.ID,
Item = status
});
_patient.IsWeChatView = status;
TsmiWeChatViewReport.Text = status ? "已允许微信查看报告" : "已禁止微信查看报告";
TsmiWeChatViewReport.ForeColor = status ? Color.Black : Color.Red;
picWeChat.Visible = status;
};
TsmiAbandoned.Click += TsmiAbandoned_Click;
//1.2.1.PACS
DgvRptPacs.RowClick += DgvReportPacs_DoubleClick;
//1.3.1.其他报告
DgvRptExt.RowClick += (o, e) =>
{
if (DgvRptExt.GetFocusedRow() is ReportExt selected) SetPictureBoxReportExt(selected);
};
//颜色
// DgvExamResult.CustomDrawCell += DgvExamResult_CustomDrawCell;
//结论选择
CmbSearchConclusion.DisplayMember = "ConclusionName";
CmbSearchConclusion.ValueMember = "ConclusionName";
CmbSearchConclusion.DataSource = Global._lstConclusion;
CmbSearchConclusion.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor;
CmbSearchConclusion.CloseUp += CmbSearchConclusion_CloseUp;
var userModel = new UserModel();
_isPeidDeptUser = userModel.IsPeidDept();
BtnRefresh.Click += BtnRefresh_Click;
DgvLisReport.CustomDrawCell += DgvLisReport_CustomDrawCell;
DgvPatient.Initialize();
DgvPatient.CustomDrawCell += DgvPatient_CustomDrawCell;
txtTeam.KeyDown += (s, e) =>
{
if (e.KeyCode == Keys.Enter) OnGetPatientList();
};
txtInfo.KeyDown += (s, e) =>
{
if (e.KeyCode == Keys.Enter) OnGetPatientList();
};
txtConclusionSerch.KeyDown += (s, e) =>
{
if (e.KeyCode == Keys.Enter) SearchAllConclusion();
};
txtConclusionSerch.TextChanged += (s, e) =>
{
SearchAllConclusion();
};
DgvExamConclusion.OptionsCustomization.AllowSort = true;
//DgcAllConclusion.DataSource = Global._lstConclusion;
// DgvAllConclusion.OptionsFind.AlwaysVisible = true;
// DgvAllConclusion.OptionsFind.ShowClearButton = false;
// DgvAllConclusion.OptionsFind.ShowCloseButton = false;
DgvAllConclusion.DoubleClick += DgvAllConclusion_DoubleClick;
DgvExamResultData.CustomDrawCell += DgvExamResultData_CustomDrawCell;
// 启用行选择
DgvExamConclusion.OptionsSelection.EnableAppearanceFocusedCell = false;
DgvExamConclusion.OptionsSelection.MultiSelect = false; // 限制单选
// 启用编辑功能,以便显示勾选框
DgvExamConclusion.OptionsBehavior.Editable = true;
// 设置行头自动调整高度以显示勾选框
DgvExamConclusion.OptionsView.RowAutoHeight = true;
// pacs报告打印
PrintPacs.Click += PrintPacs_Click;
}
private void ConclusionSort(int i)
{
if (DgvExamConclusion.GetFocusedRow() is ExamConclusion selected)
{
var current = _examConclusion.IndexOf(selected);
if ((current == 0 && i < 0) || (current == _examConclusion.Count - 1 && i > 0))
{
return;
}
var temp = _examConclusion[current + i];
var tempSeq = _examConclusion[current + i].Seq;
temp.Seq = selected.Seq;
selected.Seq = tempSeq;
_examConclusion[current + i] = selected;
_examConclusion[current] = temp;
_examConclusion = _examConclusion.OrderBy(o => o.Seq).ToList();
// for (int j = 0; j < _examConclusion.Count; j++)
// {
// _examConclusion[j].Seq = j + 1;
// }
Invoke(new Action(() => DgcExamConclusion.DataSource = null));
Invoke(new Action(() => DgcExamConclusion.DataSource = _examConclusion));
Invoke(new Action(() => DgcExamConclusion.DataSource = _examConclusion));
Invoke(new Action(() => DgvExamConclusion.FocusedRowHandle = current+i));
Invoke(new Action(() => DgvExamConclusion.SelectRow(current + i)));
}
}
private void SearchAllConclusion()
{
var query = txtConclusionSerch.Text;
var isId = long.TryParse(query, out var id);
var list = string.IsNullOrEmpty(query)
? Global._lstConclusion
: Global._lstConclusion.Where(p => p.SpellCode.Contains(query) || p.ConclusionName.Contains(query) || (isId && p.ID == id)).ToList();
Invoke(new Action(() => DgcAllConclusion.DataSource = null));
Invoke(new Action(() => DgcAllConclusion.DataSource = list));
}
private void DgvAllConclusion_DoubleClick(object sender, EventArgs e)
{
if (!_isPeidDeptUser)
{
MessageBox.Show(@"权限不足!");
return;
}
if (_patient.FinishTime != null)
{
return;
}
if (DgvAllConclusion.GetFocusedRow() is Conclusion selected)
_examConclusion.Add(new ExamConclusion()
{
EID = _patient.ID,
Seq = _examConclusion.Count + 1,
Conclusion = selected.ConclusionName,
Suggestion = selected.Suggestion
});
ShowExamConclusion(_examConclusion);
}
/// <summary>
/// 体检者列表-自定义绘制单元格
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void DgvPatient_CustomDrawCell(object sender, RowCellCustomDrawEventArgs e)
{
if (e.Column.Caption != @"状态")
{
return;
}
var gridView = (GridView)sender;
if (e.RowHandle < 0 || e.Column == null) return;
// 获取当前单元格所在行的数据
var rowData = gridView.GetRow(e.RowHandle) as EnrollmentPatient;
switch (rowData?.Status)
{
case "科室分检":
e.Appearance.ForeColor = Color.Black;
e.Appearance.BackColor = Color.White;
break;
case "总检":
e.Appearance.ForeColor = ForeMain;
e.Appearance.BackColor = BackMain;
break;
case "打印":
e.Appearance.ForeColor = ForeSuccess;
e.Appearance.BackColor = BackSuccess;
break;
case "弃检":
e.Appearance.ForeColor = ForeWarning;
e.Appearance.BackColor = BackWarning;
break;
default:
e.Appearance.ForeColor = ForeInfo;
e.Appearance.BackColor = BackInfo;
break;
}
}
private void DgvLisReport_CustomDrawCell(object sender, RowCellCustomDrawEventArgs e)
{
var gridView = (GridView)sender;
if (e.RowHandle < 0 || e.Column == null) return;
// 获取当前单元格所在行的数据
var rowData = gridView.GetRow(e.RowHandle) as ExamResult;
if (string.IsNullOrEmpty(rowData?.UnusualFlag)) return;
switch (rowData.UnusualFlag)
{
case "↑":
e.Appearance.ForeColor = ColorHelper.ForeDanger;
e.Appearance.BackColor = ColorHelper.BackDanger;
break;
case "↓":
e.Appearance.ForeColor = ColorHelper.ForeMain;
e.Appearance.BackColor = ColorHelper.BackMain;
break;
}
}
private void TabPart_SelectedPageChanged(object sender, DevExpress.XtraTab.TabPageChangedEventArgs e)
{
RefreshTabPageData(e.Page.Text);
}
private void CmbSearchConclusion_CloseUp(object sender, DevExpress.XtraEditors.Controls.CloseUpEventArgs e)
{
if (e.AcceptValue)
{
var editor = sender as SearchLookUpEdit;
if (editor != null)
{
// 获取选中的行数据
var rowData = editor.Properties.View.GetFocusedRow() as Conclusion;
if (rowData != null)
{
var conclusion = DgvExamConclusion.GetFocusedRow() as ExamConclusion;
if (rowData == null || conclusion == null) return;
var index = _examConclusion.IndexOf(conclusion);
_examConclusion[index].Conclusion = rowData.ConclusionName;
_examConclusion[index].Suggestion = rowData.Suggestion;
ShowExamConclusion(_examConclusion);
}
}
}
// if (string.IsNullOrEmpty(e?.Value?.ToString())) return;
// var rowData = Global._lstConclusion.FirstOrDefault(p => p.ConclusionName == e.Value.ToString());
// var conclusion = DgvExamConclusion.GetFocusedRow() as ExamConclusion;
// if (rowData == null || conclusion == null) return;
// var index = _examConclusion.IndexOf(conclusion);
// _examConclusion[index].Conclusion = rowData.ConclusionName;
// _examConclusion[index].Suggestion = rowData.Suggestion;
// ShowExamConclusion(_examConclusion);
}
private void DgvExamResult_CustomDrawCell(object sender, RowCellCustomDrawEventArgs e)
{
var gridView = (GridView)sender;
if (e.RowHandle < 0 || e.Column == null) return;
// 获取当前单元格所在行的数据
var rowData = gridView.GetRow(e.RowHandle) as ExamResult;
if (rowData?.VerifyTime != null) return;
e.Appearance.ForeColor = ColorHelper.ForeWarning;
e.Appearance.BackColor = ColorHelper.BackWarning;
}
/// <summary>
/// 刷新科室体检者列表
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void BtnRefresh_Click(object sender, EventArgs e)
{
OnGetPatientList();
}
/// <summary>
/// 预览报告单
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void TsmiAbandoned_Click(object sender, EventArgs e)
{
var eid = _patient.ID;
if (eid > 0)
{
var rpt = ReportHelper.GetReport(eid);
if (rpt == null)
{
Global.Msg("err", "报告生成失败!");
return;
}
rpt.Show();
}
}
#region IViewClick
/// <summary>
/// 2.获取体检者列表
/// </summary>
public event EventHandler<Args<string>> GetPatientList;
public event EventHandler<Args<object>> GetPatient;
public void ShowPatient(EnrollmentPatient item)
{
RefreshPatient(item);
RefreshTabPageData(TabPart.SelectedTabPage.Text);
}
public void ShowPatientList(List<EnrollmentPatient> items)
{
Invoke(new Action(() => _patientList = items));
Invoke(new Action(() => DgcPatient.DataSource = null));
Invoke(new Action(() => DgcPatient.DataSource = _patientList));
Invoke(new Action(() => RbStatus1.Checked = false));
Invoke(new Action(() => RbStatus2.Checked = false));
Invoke(new Action(() => RbStatus3.Checked = false));
Invoke(new Action(() => RbStatus4.Checked = true));
Invoke(new Action(() => DgcExamResult.DataSource = null));
Invoke(new Action(() => DgvPatient.BestFitColumns()));
}
private void OnGetPatientList()
{
{
if (dateEditBeg?.Value == null || dateEditEnd?.Value == null ||
!DateTime.TryParse(dateEditBeg.Value.ToString(CultureInfo.InvariantCulture), out var _) ||
!DateTime.TryParse(dateEditEnd.Value.ToString(CultureInfo.InvariantCulture), out var _))
return;
var dateType = comboDate?.SelectedItem as QueryDateType;
if ((txtTeam.Text != _watermarkTeam || txtInfo.Text != _watermarkInfo)
&& dateEditBeg.Value.Date == DateTime.Now.AddDays(-3).Date &&
dateEditEnd.Value.Date == DateTime.Now.Date)
{
dateEditBeg.Value = DateTime.Now.AddDays(-15);
}
// 1日期类型、2开始日期、3结束日期、4体检团队、5个人信息
GetPatientList?.Invoke(this, new Args<string>()
{
Items = new List<string>()
{
dateType?.Code,
$"{Convert.ToDateTime(dateEditBeg.Value):yyyy-MM-dd}",
$"{Convert.ToDateTime(dateEditEnd.Value).AddDays(1):yyyy-MM-dd}",
txtTeam.Text == _watermarkTeam ? "" : txtTeam.Text,
txtInfo.Text == _watermarkInfo ? "" : txtInfo.Text,
}
});
}
}
/// <summary>
/// 5.获取科室分检结果列表
/// </summary>
public event EventHandler<Args<object>> GetExamResultList;
public void ShowExamResultList(List<ExamResult> items)
{
Invoke(new Action(() => DgcExamResult.DataSource = null));
Invoke(new Action(() => DgcExamResult.DataSource = items));
Invoke(new Action(() => DgvExamResult.ExpandAllGroups()));
}
/// <summary>
/// 3. 获取科室小结
/// </summary>
public event EventHandler<Args<object>> GetSummary;
public void ShowSummary(List<ExamPart> items)
{
Invoke(new Action(() => _examPart = items));
Invoke(new Action(() => txtSummary.Text = null));
Invoke(new Action(() =>
{
txtSummary.Text = @"-- 科室小结 --";
_examPart.ForEach(item =>
{
if (!string.IsNullOrEmpty(item.Summary))
txtSummary.Text += Environment.NewLine + $@"【{item.DeptName}】" + Environment.NewLine + item.Summary +
Environment.NewLine;
});
}));
Invoke(new Action(() => DgcSummary.DataSource = null));
Invoke(new Action(() => DgcSummary.DataSource = _examPart));
Invoke(new Action(() => DgcSummary.DataSource = _examPart));
Invoke(new Action(() => DgvSummary.ExpandAllGroups()));
}
/// <summary>
/// 4. 获取结论词
/// </summary>
public event EventHandler<Args<object>> GetExamConclusion;
public event EventHandler<Args<ExamConclusion>> SaveExamConclusion;
public void ShowExamConclusion(List<ExamConclusion> items)
{
items = items.OrderBy(o => o.Seq).ToList();
for (int j = 0; j < items.Count; j++)
{
items[j].Seq = j + 1;
}
Invoke(new Action(() => DgcExamConclusion.DataSource = null));
Invoke(new Action(() => _examConclusion = items));
Invoke(new Action(() => DgcExamConclusion.DataSource = _examConclusion));
DgvExamConclusion.OptionsView.RowAutoHeight = true; // 启用自动行高调整
DgvExamConclusion.OptionsCustomization.AllowRowSizing = true;
Invoke(new Action(() => DgvExamConclusion.TopRowIndex = items.Count));
//DgvExamConclusion.BestFitColumns(); // 调整列宽以适应内容
}
/// <summary>
/// 11.获取科室分检结果列表
/// </summary>
public event EventHandler<Args<object>> GetLisReport;
public void ShowLisReport(List<ExamResult> items)
{
Invoke(new Action(() => DgcLisReport.DataSource = null));
Invoke(new Action(() => _lisReport = items));
Invoke(new Action(() => DgcLisReport.DataSource = _lisReport));
}
/// <summary>
/// 修改完结状态
/// </summary>
public event EventHandler<Args<bool>> Finish;
public void ShowFinish(int status)
{
Global.MsgInfo(status == 1 ? @"完结成功!" : status == -1 ? "取消完结成功!" : "操作失败,请重试!");
if (DgvPatient.GetFocusedRow() is EnrollmentPatient selected)
{
GetPatient?.Invoke(this, new Args<object>(selected.ID));
GetExamResultList?.Invoke(this, new Args<object>(_patient.ID));
GetSummary?.Invoke(this, new Args<object>(_patient.ID));
Invoke(new Action(() => GetExamResultData(_patient.ID)));
GetExamConclusion?.Invoke(this, new Args<object>(_patient.ID));
}
else
{
_patient = new EnrollmentPatient();
}
}
/// <summary>
/// 修改是否允许微信查看报告
/// </summary>
public event EventHandler<Args<bool>> WeChatViewRpt;
#endregion IViewClick
#region 页面控件事件
/// <summary>
/// 只要窗体是首次显示就发生
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void TotalForm_Shown(object sender, EventArgs e)
{
//赋值
//查询日期
dateEditBeg.Value = DateTime.Now.AddDays(-3);
dateEditEnd.Value = DateTime.Now;
//查询条件初始化
comboDate.DataSource = new QueryDateType().List();
comboDate.DisplayMember = "Name";
comboDate.ValueMember = "Code";
txtTeam.WatermarkText = _watermarkTeam;
txtTeam.Text = _watermarkTeam;
txtInfo.WatermarkText = _watermarkInfo;
txtInfo.Text = _watermarkInfo;
// ThreadPool.QueueUserWorkItem(state =>
// {
// OnGetPatientList();
// });
OnGetPatientList();
}
/// <summary>
/// 患者列表控件双击事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void DgvPatientRowClick(object sender, EventArgs e)
{
if (DgvPatient.GetFocusedRow() is EnrollmentPatient selected)
{
GetPatient?.Invoke(this, new Args<object>(selected.ID));
GetExamResultList?.Invoke(this, new Args<object>(_patient.ID));
GetSummary?.Invoke(this, new Args<object>(_patient.ID));
Invoke(new Action(() => GetExamResultData(_patient.ID)));
GetExamConclusion?.Invoke(this, new Args<object>(_patient.ID));
//调用
SelectedPatientEvent?.Invoke(selected?.ID);
}
else
{
_patient = new EnrollmentPatient();
}
}
/// <summary>
/// 单选按钮选中事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void RadioButton_Click(object sender, EventArgs e)
{
var dataSource = _patientList;
if (RbStatus1.Checked)
{
dataSource = _patientList.Where(p => p.Status == "总检").ToList();
}
else if (RbStatus2.Checked)
{
dataSource = _patientList.Where(p => p.Status == "打印").ToList();
}
else if (RbStatus3.Checked)
{
dataSource = _patientList.Where(p => p.Status == "科室分检").ToList();
}
else if (RbStatus4.Checked)
{
dataSource = _patientList;
}
Invoke(new Action(() => DgcPatient.DataSource = null));
Invoke(new Action(() => DgcPatient.DataSource = dataSource));
}
private void RefreshTabPageData(string text)
{
switch (text)
{
case @"检验报告" when _patient.ID > 0:
GetLisReport?.Invoke(this, new Args<object>()
{
ID = _patient.ID
});
break;
case @"检查报告":
GetPacsRptList(_patient.ID);
break;
case @"其他报告":
GetReportExtList?.Invoke(this, new Args<object>(_patient.ID));
break;
case @"历史结果":
AddHistoryView();
historyView.SearchHistory(_patient.CardNo);
break;
}
}
private void AddHistoryView()
{
tabPageHistory.Controls.Clear();
historyView = new HistoryView(_patient.CardNo);
// 设置子窗体的Dock属性为Fill,使其填充满选项卡页
historyView.Dock = DockStyle.Fill;
// 设置子窗体的父级为当前TabPage
historyView.Parent = tabPageHistory;
// 将子窗体添加到选项卡页中
tabPageHistory.Controls.Add(historyView);
historyView.Show();
}
/// <summary>
/// 获取第三方报告
/// </summary>
public event EventHandler<Args<object>> GetReportExtList;
public void ShowReportExtList(List<ReportExt> items)
{
Invoke(new Action(() => DgcRptExt.DataSource = null));
if (items.Count == 0) return;
Invoke(new Action(() => DgcRptExt.DataSource = items));
SetPictureBoxReportExt(items[0]);
}
/// <summary>
/// 添加结论
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ConclusionAdd_Click(object sender, EventArgs e)
{
if (!_isPeidDeptUser)
{
MessageBox.Show(@"权限不足!");
return;
}
if (_patient.FinishTime != null)
{
return;
}
_examConclusion.Add(new ExamConclusion() { EID = _patient.ID, Seq = _examConclusion.Count + 1 });
ShowExamConclusion(_examConclusion);
}
/// <summary>
/// 删除结论
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ConclusionDelete_Click(object sender, EventArgs e)
{
if (!_isPeidDeptUser)
{
MessageBox.Show(@"权限不足!");
return;
}
if (_patient.FinishTime != null)
{
return;
}
if (DgvExamConclusion.GetSelectedRows().Length == 0) return;
var item = DgvExamConclusion.GetRow(DgvExamConclusion.FocusedRowHandle) as ExamConclusion;
if (item==null)return;
if (!Global.MsgDelete()) return;
_examConclusion.Remove(item);
ShowExamConclusion(_examConclusion);
try
{
var task = new Task(() => item?.Delete());
task.Start();
}
catch (AggregateException ae)
{
Global.MsgErr($@"{item.Conclusion} 结论词删除失败!" + ae.Message);
ae.Handle(ex =>
{
// 处理异常
return true; // 返回true表示已处理异常
});
}
}
/// <summary>
/// 保存结论
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ConclusionSave_Click(object sender, EventArgs e)
{
DgvExamConclusion.CloseEditor();
// 将焦点设置到其他控件,使 DataGrid 控件的单元格失去焦点
OpsConclusion.Focus();
if (!_isPeidDeptUser)
{
MessageBox.Show(@"权限不足!");
return;
}
if (_patient.FinishTime != null)
{
return;
}
SaveExamConclusion?.Invoke(this, new Args<ExamConclusion>()
{
ID = _patient.ID,
Items = _examConclusion.Where(p => !string.IsNullOrEmpty(p.Conclusion)).ToList()
});
//MessageBox.Show(@"保存成功!");
}
#endregion 页面控件事件
#region PACS
public List<Report> GetPacsRptList(long eid)
{
var pacsReportList = DAOHelp.GetDataBySQL<Report>($@"
SELECT
a.EID,
a.FeeItemName,
b.ID,
b.ReportNo ,
b.Class,
b.Class2,
b.Title,
b.Examer,
b.Reporter,
b.ReportTime,
b.Description,
b.Summary,
b.Positive,
b.InTime,
b.SpcimenName
FROM
Enrollment_FeeItem a
LEFT JOIN Report b ON a.EID = b.EID AND (a.ID= b.ReportNo or a.OldId = b.ReportNo)
WHERE
a.ItemClass = '检查' AND a.eid = {eid}").ToList();
ShowPacsRptList(pacsReportList);
return pacsReportList;
}
public void ShowPacsRptList(List<Report> items)
{
Invoke(new Action(() => DgcRptPacs.DataSource = items));
Invoke(new Action(() => DgvRptPacs.BestFitColumns()));
if (items.Count > 0)
{
ShowPacsReportImg(items[0]);
}
}
public List<ExamPacsImage> GetExamPacsImage(long eid, string reportNo)
{
var pacsReportList = DAOHelp.GetDataBySQL<ExamPacsImage>($@"
SELECT *FROM Exam_PacsImage WHERE eid = {eid} and reportNo='{reportNo}'").ToList();
ShowExamPacsImage(pacsReportList);
return pacsReportList;
}
private void ShowExamPacsImage(List<ExamPacsImage> items)
{
flowLayoutPanelPacsImg.Controls.Clear();
items.ForEach(item =>
{
try
{
var picture = new PictureBox()
{
Size = new Size(280, 250),
SizeMode = PictureBoxSizeMode.Zoom,
Margin = new Padding(5)
};
using (var memoryStream = new MemoryStream(item.Image))
{
picture.Image = Image.FromStream(memoryStream);
}
flowLayoutPanelPacsImg.Controls.Add(picture);
}
catch
{
return;
}
});
}
/// <summary>
/// Pacs检查报告列表
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void DgvReportPacs_DoubleClick(object sender, EventArgs e)
{
if (!(DgvRptPacs.GetFocusedRow() is Report selected)) return;
ShowPacsReportImg(selected);
}
private void ShowPacsReportImg(Report selected)
{
pictureBoxPacsRpt.Image = null;
var rpt = DAOHelp.Query<Report>($@"SELECT TOP 1 ReportImage FROM [dbo].[Report] WHERE ID={selected.ID}")
?.FirstOrDefault();
if (rpt?.ReportImage != null)
using (var ms = new MemoryStream(rpt.ReportImage))
{
pictureBoxPacsRpt.Image = Image.FromStream(ms);
}
//获取选中的图片
GetExamPacsImage(selected.EID, selected.ReportNo);
}
/// <summary>
/// pacs报告打印
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void PrintPacs_Click(object sender, EventArgs e)
{
if (!(DgvRptPacs.GetFocusedRow() is Report selected)) return;
var rpt = DAOHelp.Query<Report>($@"SELECT TOP 1 ReportImage FROM [dbo].[Report] WHERE ID={selected.ID}")?.FirstOrDefault();
if (rpt?.ReportImage != null)
{
try
{
using (var ms = new MemoryStream(rpt.ReportImage))
{
Image img = Image.FromStream(ms);
PrintDialog printDialog = new PrintDialog();
printDialog.Document = new PrintDocument();
printDialog.Document.PrintPage += (a, b) =>
{
// 计算图像的宽度和高度
int imageWidth = img.Width;
int imageHeight = img.Height;
// 获取打印区域的宽度和高度(考虑到页边距)
float marginBoundsWidth = b.MarginBounds.Width;
float marginBoundsHeight = b.MarginBounds.Height;
// 计算绘制起点的坐标,使图像居中
float left = (marginBoundsWidth - imageWidth) / 2;
float top = (marginBoundsHeight - imageHeight) / 2;
// 确保坐标值不为负数
left = left < 0 ? 0 : left;
top = top < 0 ? 0 : top;
b.Graphics.DrawImage(img, left, top, imageWidth, imageHeight);
};
printDialog.UseEXDialog = true; // 显示增强的打印对话框
if (printDialog.ShowDialog() == DialogResult.OK)
{
printDialog.Document.Print(); // 执行打印操作
}
}
}
catch (Exception ex)
{
Global.MsgWarn(ex.Message);
Debug.Write(ex.Message);
}
}
}
#endregion PACS
private void SetPictureBoxReportExt(ReportExt item)
{
Invoke(new Action(() => PictureBoxReportExt.Image = null));
if (item.ReportImg == null) return;
try
{
if (item.Class == "十二通道心电图检查")
{
var img = ReportHelper.PdfToImg(item.ReportImg);
if (img != null)
{
var newImg = ReportHelper.RotateImage(img);
Invoke(new Action(() => { PictureBoxReportExt.Image = newImg; }));
}
return;
}
Invoke(new Action(() =>
{
PictureBoxReportExt.Image = null;
if (item?.ReportImg == null) return;
using (var ms = new MemoryStream(item.ReportImg, 0, item.ReportImg.Length))
{
Invoke(new Action(() =>
{
var img = Image.FromStream(ms, true);
PictureBoxReportExt.Image = img;
}));
}
}));
}
catch (Exception e)
{
Global.MsgErr(e.Message);
}
}
#region Refresh
/// <summary>
/// 刷新当前体检者信息
/// </summary>
/// <param name="item"></param>
private void RefreshPatient(EnrollmentPatient item = null)
{
item = item ?? _patient;
Invoke(new Action(() => _patient = item));
SetPatientInfo(item);
if (item.FinishTime != null)
{
//Invoke(new Action(() => lblFinish.Text = @"已完结"));
Invoke(new Action(() => toolStripTxtStatus.Text = $@"已完结 {item.FinishTime:yyyy-MM-dd HH:mm}"));
Invoke(new Action(() => TsmiFinish.Enabled = false));
Invoke(new Action(() => TsmiFinishCancel.Enabled = true));
}
else
{
//Invoke(new Action(() => lblFinish.Text = @"未完结"));
Invoke(new Action(() => toolStripTxtStatus.Text = @"未完结"));
Invoke(new Action(() => TsmiFinish.Enabled = true));
Invoke(new Action(() => TsmiFinishCancel.Enabled = false));
}
}
#endregion Refresh
/// <summary>
/// 显示体检者信息
/// </summary>
/// <param name="patient"></param>
private void SetPatientInfo(EnrollmentPatient patient = null)
{
patient = patient ?? new EnrollmentPatient();
lblName.Text = patient.Name;
lblSex.Text = patient.Sex == "1" ? "男" : patient.Sex == "2" ? "女" : "";
lblAge.Text = (patient.Age.ToString() == "0") ? "" : patient.Age + $@"{patient.AgeClass}";
lblNation.Text = patient.Nation;
lblCardNo.Text = patient.CardNo;
lblEid.Text = (patient.ID.ToString() == "0") ? "" : patient.ID.ToString();
lblType.Text = patient.Type;
lblExamDate.Text = $@"{patient.ExamDate:yyyy-MM-dd}";
lblSignTime.Text = $@"{patient.SignTime:yyyy-MM-dd HH:mm}";
lblOccupation.Text = patient.Occupation;
lblMarriage.Text = patient.Marriage;
lblEducation.Text = patient.Education;
lblTel.Text = $@"{patient.Tel1}";
lblAddress.Text = patient.Address1;
lblOeid.Text = patient.OEID.ToString();
lblOrgName.Text = patient.OrgName;
lblGroupName.Text = patient.GroupName;
picAvatar.Image = null;
if (!string.IsNullOrEmpty(patient.Photo))
{
var imageBytes = Convert.FromBase64String(patient.Photo);
using (var ms = new MemoryStream(imageBytes, 0, imageBytes.Length))
{
Invoke(new Action(() => { picAvatar.Image = Image.FromStream(ms, true); }));
Invoke(new Action(() => { picAvatar.BorderStyle = BorderStyle.None; }));
}
}
else
{
Invoke(new Action(() => { picAvatar.BorderStyle = BorderStyle.FixedSingle; }));
// FixedSingle
}
var status = patient.IsWeChatView ?? false;
picWeChat.Visible = status;
TsmiWeChatViewReport.Text = status ? "已允许微信查看报告" : "已禁止微信查看报告";
TsmiWeChatViewReport.ForeColor = status ? Color.Black : Color.Red;
Invalidate(); // 使控件无效以重绘
}
/// <summary>
/// 科室分检-分科检查结果
/// </summary>
/// <param name="eid"></param>
public void GetExamResultData(long eid)
{
if (eid == 0)
{
return;
}
var data = DAOHelp.GetDataBySQL<ExamResult>($@"SELECT
A.DeptName
,B.FeeItemName
,B.RptItemName
, (ISNULL(TextResult, '') + ' ' + ISNULL(Unit, '')) AS TextResult
,UnusualFlag
, [Range]
, [RptItemCode]
FROM Exam_Part A
LEFT JOIN Exam_Result B ON A.ID = B.PID
WHERE
A.VerifyTime IS NOT NULL
AND A.EID = {eid}
ORDER BY A.DeptCode,FeeItemName,B.ID");
DgcExamResultData.DataSource = null;
DgcExamResultData.DataSource = data;
DgvExamResultData.BestFitColumns();
Invoke(new Action(() => DgvExamResultData.ExpandAllGroups()));
DgvExamResultData.OptionsView.RowAutoHeight = true;
}
private void DgvExamResultData_CustomDrawCell(object sender, RowCellCustomDrawEventArgs e)
{
var gridView = (GridView)sender;
if (e.RowHandle < 0 || e.Column == null) return;
// 获取当前单元格所在行的数据
var rowData = gridView.GetRow(e.RowHandle) as ExamResult;
if (string.IsNullOrEmpty(rowData?.UnusualFlag)) return;
switch (rowData.UnusualFlag)
{
case "↑":
e.Appearance.ForeColor = ForeDanger;
e.Appearance.BackColor = BackDanger;
break;
case "↓":
e.Appearance.ForeColor = ForeMain;
e.Appearance.BackColor = BackMain;
break;
}
}
}
}