StableVersion4.3/HL_FristAidPlatform_Trauma/Form_PatientList.cs

537 lines
20 KiB
C#

using DevExpress.XtraEditors;
using HL_FristAidPlatform_DTO;
using HL_FristAidPlatform_Public;
using Microsoft.AspNetCore.SignalR.Client;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Drawing;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace HL_FristAidPlatform_Trauma
{
public partial class Form_PatientList : XtraForm
{
/// <summary>
/// 当前页
/// </summary>
public int curPage = 1;
/// <summary>
/// 每页大小
/// </summary>
public int pageSize = 50;
/// <summary>
/// 所有记录条数
/// </summary>
public int totalNumber = 0;
int gender = -1;
public HubConnection connection;
public Form_PatientList()
{
InitializeComponent();
SignalRConnection();
}
public async void SignalRConnection()
{
connection = new HubConnectionBuilder().WithUrl(ConfigurationManager.AppSettings["WebApiUrl"] + "signalr/chatHub")
.Build();
await connection.StartAsync();
connection.Closed += async (error) =>
{
await Task.Delay(new Random().Next(0, 5) * 1000);
await connection.StartAsync();
};
}
public async void ReceiveMessage()
{
//发送上线信息
await connection.InvokeAsync("OnLine", Information.Hospital.GUID.ToString());
// 从中心调用客户端方法 一种订阅,可以从集线器方法中取消订阅
connection.On<object>("ReceiveUpdate", (message) =>
{
Invoke(new Action(() =>
{
string Content = "";
Content = message.ToString();
if (Content.Contains("创伤患者列表刷新"))
{
PatientList(Information.Hospital.GUID, txt_name.Text, -1, -1, timeControl1.TimeValue, timeControl2.TimeValue);
}
}));
});
}
private void Form_PatientList_Load(object sender, EventArgs e)
{
gridView1.OptionsFind.AlwaysVisible = false;
gridView1.BestFitColumns();
GetEventList();
ReceiveMessage();
PatientList(Information.Hospital.GUID, txt_name.Text, -1, -1, timeControl1.TimeValue, timeControl2.TimeValue);
}
public void PatientList(string hospitalGuid, string name, int gender, int illness, string stratTime, string endTime)
{
string GreenWay = "";
switch (comboBoxEdit2.Text)
{
case "绿道患者":
GreenWay = "1";
break;
case "非绿道患者":
GreenWay = "0";
break;
}
string eventID = com_AccidentInfo.Text == "全部" ? "" : com_AccidentInfo.SelectedValue.ToString();
DataTable dt = DBHelpClass.Get(string.Format("api/service/T_Service_TraumaPatient/GetTraumaPatientList?hospitalGuid={0}&name={1}&gender={2}&illness={3}&startTime={4}&endTime={5}&pageIndex={6}&pageSize={7}&GreenWay={8}&eventID={9}", Information.Hospital.GUID, name, gender, illness, timeControl1.TimeValue, timeControl2.TimeValue, curPage, pageSize, GreenWay, eventID));
gridControl1.DataSource = dt;
gridView1.BestFitColumns();//列宽自适应
totalNumber = DBHelpClass.TotalNumber;
userControlForPage.RefreshPager(pageSize, totalNumber, curPage);//更新分页控件显示
}
private void gridView1_CustomColumnDisplayText(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDisplayTextEventArgs e)
{
if (e.Column.FieldName == "Gender")
{
int value = PublicClass.ToInt32(e.Value, -1);
switch (value)
{
case 0:
e.DisplayText = "未知";
break;
case 1:
e.DisplayText = "男";
break;
case 2:
e.DisplayText = "女";
break;
}
}
if (e.Column.FieldName == "IllnessLevel")
{
int value = PublicClass.ToInt32(e.Value, -1);
switch (value)
{
case 1:
e.DisplayText = "濒危";
break;
case 2:
e.DisplayText = "危重";
break;
case 3:
e.DisplayText = "急症";
break;
case 4:
e.DisplayText = "非急症";
break;
case 5:
e.DisplayText = "已死亡";
break;
}
}
if (e.Column.FieldName == "EmergencyState")
{
int value = PublicClass.ToInt32(e.Value, -1);
switch (value)
{
case 0:
e.DisplayText = "急救中";
break;
case 1:
e.DisplayText = "住院中";
break;
case 2:
e.DisplayText = "已转归";
break;
case -1:
e.DisplayText = "";
break;
}
}
if (e.Column.FieldName == "MPDSType")
{
int value = PublicClass.ToInt32(e.Value, -1);
switch (value)
{
case 1:
e.DisplayText = "创伤";
break;
case 4:
e.DisplayText = "其他";
break;
}
}
//是否绿道患者
if (e.Column.FieldName == "IsGreenWay")
{
string value = PublicClass.ToString(e.Value, "");
switch (value)
{
case "1":
e.DisplayText = "绿道患者";
break;
default:
e.DisplayText = "非绿道患者";
break;
}
}
if (e.Column.FieldName == "ComeHosptialWay")
{
int value = PublicClass.ToInt32(e.Value, -1);
switch (value)
{
case 1:
e.DisplayText = "呼救救护车";
break;
case 2:
e.DisplayText = "外院转诊";
break;
case 3:
e.DisplayText = "自行来院";
break;
case 4:
e.DisplayText = "院内发病";
break;
case 5:
e.DisplayText = "其他";
break;
}
}
}
private void simpleButton1_Click(object sender, EventArgs e)
{
int illness = -1;
switch (comboBoxEdit1.Text)
{
case "全部":
illness = -1;
break;
case "濒危":
illness = 1;
break;
case "危重":
illness = 2;
break;
case "急症":
illness = 3;
break;
case "非急症":
illness = 4;
break;
case "已死亡":
illness = 5;
break;
}
string name = txt_name.Text + "";
PatientList(Information.Hospital.GUID, name, gender, illness, timeControl1.TimeValue, timeControl2.TimeValue);
}
/// <summary>
/// 新增患者
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void simpleButton2_Click(object sender, EventArgs e)
{
Form_PublisAddPatient from = new Form_PublisAddPatient(long.Parse(PublicClassForDataBase.Config10003), "");
from.Show();
}
private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
if (radioButton1.Checked == true)
{
gender = -1;
}
}
private void radioButton2_CheckedChanged(object sender, EventArgs e)
{
if (radioButton2.Checked == true)
{
gender = 1;
}
}
private void radioButton3_CheckedChanged(object sender, EventArgs e)
{
if (radioButton3.Checked == true)
{
gender = 2;
}
}
private void gridView1_DoubleClick(object sender, EventArgs e)
{
try
{
ShowDetail();
}
catch (Exception ex)
{
PublicClass.WriteErrorLog(this.Text, "查看创伤患者详情:\r\n" + ex);
}
}
private void ShowDetail()
{
if (gridView1.DataRowCount > 0)
{
int selectRow = gridView1.GetSelectedRows()[0];
string GUID = gridView1.GetRowCellValue(selectRow, "GUID").ToString();
string Name = gridView1.GetRowCellValue(selectRow, "Name").ToString();
string Age = gridView1.GetRowCellValue(selectRow, "Age").ToString();
string patientId = gridView1.GetRowCellValue(selectRow, "ID").ToString();
string gender = gridView1.GetRowCellValue(selectRow, "Gender").ToString();
string gendername = "";
switch (gender)
{
case "0":
gendername = "未知";
break;
case "1":
gendername = "男";
break;
case "2":
gendername = "女";
break;
}
Form_PatientMainInfo detail = new Form_PatientMainInfo(GUID, Name, Age, gendername, patientId);
detail.Owner = this;
detail.Show();
}
}
private void ToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
if (gridView1.DataRowCount > 0)
{
int selectRow = gridView1.FocusedRowHandle;
string _guid = PublicClass.ToString(gridView1.GetRowCellValue(selectRow, "GUID"), "");
DialogResult dr = XtraMessageBox.Show("是否确定删除该病例?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
if (dr == DialogResult.Yes)
{
List<T_Service_PatientDTO> list = new List<T_Service_PatientDTO>();
T_Service_PatientDTO dto = new T_Service_PatientDTO();
dto.GUID = _guid;
string Url = "api/service/T_Service_Patient/DeleteByGuid";
list.Add(dto);
//初始化两个工厂
ClientFactory<T_Service_PatientDTO> httpClient = new HttpClientFactory<T_Service_PatientDTO>();
Client<T_Service_PatientDTO> client = httpClient.VisitFactory();
//访问
ListEntity<T_Service_PatientDTO> t = client.Post(Url, list);
if (t.Success)
{
JObject jo = (JObject)JsonConvert.DeserializeObject(t.DataString);
string msg = jo["Msg"].ToString();
if (!string.IsNullOrEmpty(msg))
{
XtraMessageBox.Show(msg);
PatientList(Information.Hospital.GUID, txt_name.Text, -1, -1, timeControl1.TimeValue, timeControl2.TimeValue);
}
}
else
{
MessageBox.Show("删除失败");
}
}
else
{
return;
}
}
}
catch (Exception ex)
{
PublicClass.WriteErrorLog(this.Text, "胸痛单元患者病历删除失败:\r\n" + ex);
}
}
private void userControlForPage_myPagerEvents(int curPage, int pageSize)
{
userControlForPage.myPagerEvents += MyPagerEvents;
}
private void MyPagerEvents(int curPage, int pageSize)
{
this.curPage = curPage;
this.pageSize = pageSize;
PatientList(Information.Hospital.GUID, txt_name.Text, -1, -1, timeControl1.TimeValue, timeControl2.TimeValue);
}
private void simpleButton3_Click(object sender, EventArgs e)
{
Form_AddGroupInjury form = new Form_AddGroupInjury();
form.Owner = this;
//Form_PublisAddPatient from = new Form_PublisAddPatient(long.Parse(PublicClassForDataBase.Config10003), "");
form.ShowDialog();
}
public void refreshlist()
{
string GreenWay = "";
switch (comboBoxEdit2.Text)
{
case "绿道患者":
GreenWay = "1";
break;
case "非绿道患者":
GreenWay = "0";
break;
}
DataTable dt = DBHelpClass.Get(string.Format("api/service/T_Service_TraumaPatient/GetTraumaPatientList?hospitalGuid={0}&name={1}&gender={2}&illness={3}&startTime={4}&endTime={5}&pageIndex={6}&pageSize={7}&GreenWay={8}", Information.Hospital.GUID, "", gender, "", timeControl1.TimeValue, timeControl2.TimeValue, curPage, pageSize, GreenWay));
gridControl1.DataSource = dt;
gridView1.BestFitColumns();//列宽自适应
totalNumber = DBHelpClass.TotalNumber;
userControlForPage.RefreshPager(pageSize, totalNumber, curPage);//更新分页控件显示
}
public void GetEventList()
{
List<AccidentInfoDTO> list = DBHelpClass.GetList<AccidentInfoDTO>("/api/base/T_Base_AccidentInfo/GetAccidentInfoClass");
AccidentInfoDTO dto = new AccidentInfoDTO();
dto.ID = 0;
dto.Name = "全部";
List<AccidentInfoDTO> list1 = new List<AccidentInfoDTO>();
list1.Add(dto);
list1.AddRange(list);
com_AccidentInfo.DisplayMember = "Name";
com_AccidentInfo.ValueMember = "ID";
com_AccidentInfo.DataSource = list1;
}
/// <summary>
/// 事故分类
/// </summary>
private class AccidentInfoDTO
{
/// <summary>
/// 事故ID
/// </summary>
public int ID { get; set; }
/// <summary>
/// 事故名称
/// </summary>
public string Name { get; set; }
}
private void gridView1_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
{
if (gridView1.GetRow(e.RowHandle) == null)
{
return;
}
else
{
if (e.Column.FieldName == "IsGreenWay")
{
string value = gridView1.GetRowCellValue(e.RowHandle, "IsGreenWay").ToString();
if (value == "1") //条件判断
{
e.Appearance.BackColor = Color.FromArgb(25, 190, 107);
e.Appearance.ForeColor = Color.White;
}
}
if (e.Column.FieldName == "IllnessLevel")
{
string value = gridView1.GetRowCellValue(e.RowHandle, "IllnessLevel").ToString();
if (value == "1")
e.Appearance.ForeColor = Color.FromArgb(236, 81, 103);
if (value == "2")
e.Appearance.ForeColor = Color.FromArgb(237, 111, 132);
if (value == "3")
e.Appearance.ForeColor = Color.FromArgb(246, 171, 96);
if (value == "4")
e.Appearance.ForeColor = Color.FromArgb(41, 178, 148);
if (value == "5")
e.Appearance.ForeColor = Color.FromArgb(166, 165, 165);
}
//急救状态
if (e.Column.FieldName == "EmergencyState")
{
string cellValue = PublicClass.ToString(e.CellValue, "");
if (!string.IsNullOrEmpty(cellValue))
{
if (cellValue == "0")
{
e.Appearance.ForeColor = Color.Red;
}
if (cellValue == "1")
{
e.Appearance.ForeColor = Color.Green;
#region 背景渐变色
//e.Appearance.BackColor = Color.Red;
//e.Appearance.BackColor2 = Color.FromArgb(255, 255, 255);
#endregion
}
}
}
}
}
private void simpleButton4_Click(object sender, EventArgs e)
{
if (gridView1.DataRowCount > 0)
{
int selectRow = gridView1.GetSelectedRows()[0];
string GUID = gridView1.GetRowCellValue(selectRow, "GUID").ToString();
string Name = gridView1.GetRowCellValue(selectRow, "Name").ToString();
string Age = gridView1.GetRowCellValue(selectRow, "Age").ToString();
string MPDSContent = gridView1.GetRowCellValue(selectRow, "MPDSContent").ToString();
string gender = gridView1.GetRowCellValue(selectRow, "Gender").ToString();
string gendername = "";
switch (gender)
{
case "0":
gendername = "未知";
break;
case "1":
gendername = "男";
break;
case "2":
gendername = "女";
break;
}
Form_BedsideCard userControl = new Form_BedsideCard(Name, gendername, Age, MPDSContent, "");
userControl.Show();
}
}
private void simpleButton5_Click(object sender, EventArgs e)
{
txt_name.Text = "";
timeControl1.TimeValue = "";
timeControl2.TimeValue = "";
com_AccidentInfo.SelectedIndex = 0;
comboBoxEdit1.SelectedIndex = 0;
comboBoxEdit2.SelectedIndex = 0;
PatientList(Information.Hospital.GUID, "", gender, -1, timeControl1.TimeValue, timeControl2.TimeValue);
}
}
}