Files
tj-tzhg/JJMediSys/MZCY.cs
2025-11-26 17:21:18 +08:00

1191 lines
50 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using DotNetSpeech;
using JJMediSys.cs;
using JJServer;
using log4net;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Speech.Synthesis;
using System.IO;
namespace JJMediSys
{
public partial class MZCY : Form
{
public ILog logger = LogManager.GetLogger("WebLogger");
public string Recp = "";
public MZCY()
{
InitializeComponent();
}
public static List<string> CandispenseTuble = new List<string> { "YELLOW","GREEN" };
public string Candispensestr = "";
private string LastCardNo = ""; // 保存上一次输入卡号的内容
private System.Windows.Forms.Timer TimerforCheckSameInput;
private const int TIME_THRESHOLD = 10000; // 设置时间阈值为 5 秒5000 毫秒)
NetCom netCom = new NetCom();
public string Url = "http://172.26.168.222:8096/api/medicare/third/channel/";
//public string Url = "https://mock.apipost.net/mock/43943dfb4003000/medicare/out/api/channel/";
public string confirmUrl = "http://172.26.168.222:8096/api/medicare/third/channel/sampleGatherConfirm";
//public string confirmUrl = "https://mock.apipost.net/mock/43943dfb4003000/api/medicare/third/channel/sampleGatherConfirmCommon";
public List<ItemInfo> itemInfos = new List<ItemInfo>();
public List<ItemInfo> itemInfostoShow = new List<ItemInfo>();
public Patient_Info CurPatientInfo;
public static bool ThreadRun = true;
public static Queue<ConformTask> ConformTaskQueue = new Queue<ConformTask>();
public struct ConformTask
{
public List<OrginData> orginDatas { get; set; }
}
public int ItemTotalCount = 0;
public int ItemSGCount = 0;
public int ItemBQCount = 0;
public int ItemSelectTotalCount = 0;
public int ItemSelectSGCount = 0;
public int ItemSelectBQCount = 0;
public class ListMedia
{
public string MediaContent { get; set; }
public string WavePath { get; set; }
public int State { get; set; }
}
private bool MediaState = false;
private static List<ListMedia> AllMediaList = new List<ListMedia>();
private ListMedia CurrInfo = new ListMedia();
private SpeechSynthesizer speech = null;
// 创建一个 Dictionary
public static Dictionary<string, string> colorDict = new Dictionary<string, string>
{
{ "YELLOW", "黄管" },
{ "LIGHTYELLOW", "亮黄" },
{ "RED", "红管" },
{ "GREEN", "绿色" },
{ "PURPLE", "紫管" }
};
public static string GetColorInfo(string input,bool ColorCode)
{
foreach(var v in colorDict)
{
if(ColorCode&&v.Key.Equals(input))
{
return v.Value;
}
else if (!ColorCode && v.Value.Equals(input))
{
return v.Key;
}
}
if(ColorCode)
{
return "白";
}
return "WHITE";
}
public struct ItemInfo {
public string XH { get; set; }
public string Barcode { get; set; }
public string Tuble { get; set; }
public string ItemName { get; set; }
public string ItemCount { get; set; }
public string Status { get; set; }
public string JYType { get; set; }
public string DoDept { get; set; }
public string OperTime { get; set; }
public string OperDept { get; set; }
public string ItemDetails { get; set; }
public string PrintTime { get; set; }
public string PrintDev { get; set; } //打印设备 同操作员
public string Source { get; set; } //数据来源 来自lis 或者历史数据库
}
public struct DataStruct
{
//public string patientId { get; set; } //examinationCode
//public string name { get; set; } //name
//public string age { get; set; }
//public string sex { get; set; } //sexName
//public string windowNo { get; set; }
//public string photo { get; set; }
//public int itemCount { get; set; }
//public string userType { get; set; }
//public string idCardNo { get; set; } //certificateNo
//public string phone { get; set; }
//public string healthCardNo { get; set; }
//public string doctor { get; set; }
//public List<Projecct> pojoList { get; set; }
public user user { get; set; }
public List<Projecct> list { get; set; }
}
public struct user
{
public string examinationCode { get; set; } //体检号
public int certificateType { get; set; } //证件类型
public string certificateTypeName { get; set; } //证件类型
public string certificateNo { get; set; } //证件号码
public string name { get; set; } //姓名
//public int sexid { get; set; } //sex性别 1男2女3未知
public int sex { get; set; } //sexName 性别
public string sexName { get; set; } //姓名
public int age { get; set; } //年龄 age int类型
}
public struct Projecct
{
public string barCode { get; set; } //条码号
public string sampleName { get; set; } //样本名称
public string sampleTypeName { get; set; } //样本类型
public string containerTypeName { get; set; } //容器类型
public string tubeColorName { get; set; } //试管颜色
public string compositeItemName { get; set; } //组合项目名称
public string checkListName { get; set; } //检查项目单名称
//public string requestId { get; set; }
//public string napatientIdme { get; set; }
//public string ward { get; set; }
//public string wardId { get; set; }
//public string bedNo { get; set; }
//public string tubeConvert { get; set; }
//public string noteLabel { get; set; }
//public string mnemotests { get; set; }
//public string station { get; set; }
//public string stationId { get; set; }
//public string state { get; set; }
//public string datebz { get; set; }
//public string descbz { get; set; }
//public string pickupLocation { get; set; }
//public string pickupTime { get; set; }
//public string groupId { get; set; }
//public string labelCount { get; set; }
//public string mnemoitems { get; set; }
}
private void MZCY_Load(object sender, EventArgs e)
{
//this.Size = MainForm.TabPageSize;
//panelData.Size = new Size((int)(MainForm.TabPageSize.Width * 0.99), (int)(MainForm.TabPageSize.Height * 0.4));
//panelData.Location = new Point(1 , (int)(MainForm.TabPageSize.Height * 0.17));
//gridControl1.Size = new Size((int)(MainForm.TabPageSize.Width * 0.99-5), (int)(MainForm.TabPageSize.Height * 0.4-20));
Recp = ConfigFileReader.GetValue("/configuration/appSettings/add[@key='RecpFormat']");
gridView1.GroupPanelText = "申请医嘱列表:";
gridView1.OptionsBehavior.Editable = false;
gridView1.OptionsView.ShowIndicator = false;// 显示最左边空白列
//dateStart.Properties.ReadOnly = true;
// dateEnd.Properties.ReadOnly = true;
dateStart.DateTime = DateTime.Now.AddDays(-7);
dateEnd.DateTime = DateTime.Now;
this.gridView1.RowCellStyle += new DevExpress.XtraGrid.Views.Grid.RowCellStyleEventHandler(gridView1_RowCellStyle);
SetRowsSelectionBasedOnData();
CandispenseTuble = SystemSet.mTubeLabelTool.canDispenseTubles;
string Ret = GetDaylyCountInfo(SystemSet.mTubeLabelTool.canDispenseTubles, Login.nurseDeskInfo.NurseName);
string[] Arr = Ret.Split('|');
LabDayPersonCount.Text = Arr[0];
LabDaySGCount.Text = Arr[1];
LabDayBQCount.Text = Arr[2];
Thread threadDispenseConformTask = new Thread(DoConformTask);// 处理发管确认任务
threadDispenseConformTask.Start();
TimerforCheckSameInput = new System.Windows.Forms.Timer();
TimerforCheckSameInput.Interval = TIME_THRESHOLD; // 设置计时器的时间间隔为 5 秒
TimerforCheckSameInput.Tick += EnterTimer_Tick;
speech = new SpeechSynthesizer();
}
private void EnterTimer_Tick(object sender, EventArgs e)
{
// 当计时器触发时,表示超过了 5 秒,重置状态
TimerforCheckSameInput.Stop();
}
public void DoConformTask()
{
while (ThreadRun)
{
if (ConformTaskQueue.Count > 0)
{
ConformTask data = ConformTaskQueue.Dequeue();
Thread threadSendBle = new Thread(SendConform);// 发送蓝牙数据
threadSendBle.Start(data);
}
Thread.Sleep(500);
}
}
public void SendConform(object obj)
{
//// 创建 []
//JObject root = new JObject
//{
// ["barCodes"] = new JArray()
//};
//JArray barCodes = (JArray)root["barCodes"];
ConformTask data = (ConformTask)obj;
NetCom mnetCom = new NetCom();
foreach (OrginData orginData in data.orginDatas)
{
string confirmstring = "{\"account\": \"" + Login.nurseDeskInfo.NurseID
+ "\",\"barCode\": \"" + orginData.Barcode + "\"}";
logger.Info("confirmstring =" + confirmstring);
bool result = mnetCom.SendAndRecv(confirmUrl, confirmstring, TextPatCardNo.Text);
string sql = "Insert into trans_history(PatID,PatName,PatAge,PatSex,Barcode,Tuble ,ItemName ,ItemCount,ItemType ,DoDept ,OprDept ,OprTime,PrintTime,ItemStatus,ItemsDetails,PrinterDev)values('" + orginData.PatID + "','" + orginData.PatName + "','" + orginData.PatAge + "','" + orginData.PatSex + "','" + orginData.Barcode + "','" + orginData.Tuble + "','" + orginData.ItemName + "','" + orginData.ItemCount + "','" + orginData.ItemType + "','" + orginData.DoDept + "','" + orginData.OprDept + "','" + orginData.OprTime + "','" + orginData.PrintTime + "','" + orginData.ItemStatus + "','" + orginData.ItemsDetails + "','" + orginData.PrinterDev + "') ON DUPLICATE KEY UPDATE Tuble = VALUES(Tuble),ItemName = VALUES(ItemName),ItemCount = VALUES(ItemCount),ItemType = VALUES(ItemType),OprTime = VALUES(OprTime),OprDept = VALUES(OprDept),DoDept = VALUES(DoDept),PrintTime = VALUES(PrintTime),ItemStatus = VALUES(ItemStatus),ItemsDetails = VALUES(ItemsDetails),PrinterDev = VALUES(PrinterDev)";
logger.Info("Mysql sql=" + sql);
try
{
int Ret = DoDBMySql.ExecuteSql(sql);
}
catch (Exception ex)
{
}
//barCodes.Add(orginData.Barcode);
}
//string confirmstring = "{\"hospitalld\": 1966041738358272002,"
// + "\"operateUserAccount\": \"" + Login.nurseDeskInfo.NurseID
// + "\",\"operateUsername\": \"" + Login.nurseDeskInfo.NurseName
// + "\",\"operateType\": 10,"
// + root.ToString(Formatting.None).Trim().TrimStart('{').TrimEnd('}') + "}";
//logger.Info("confirmstring =" + confirmstring);
//bool result = mnetCom.SendAndRecv(confirmUrl, confirmstring, TextPatCardNo.Text);
try
{
string daylycount = GetDaylyCountInfo(SystemSet.mTubeLabelTool.canDispenseTubles, Login.nurseDeskInfo.NurseName);
string[] Arr = daylycount.Split('|');
this.Invoke((MethodInvoker)delegate
{
LabDayPersonCount.Text = Arr[0];
LabDaySGCount.Text = Arr[1];
LabDayBQCount.Text = Arr[2];
});
}
catch (Exception ex)
{
}
}
private void gridView1_RowCellStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs e)
{
if (e.Column.Name == "Tuble")
{
var v = e.CellValue;
if (v != null)
{
e.Appearance.BackColor = Color.FromName(GetColorInfo(v.ToString(), false));
}
}else if (e.Column.Name == "Status")
{
var v = e.CellValue;
if (v != null)
{
if(v.ToString().Equals("未打印"))
e.Appearance.ForeColor = Color.Green;
else if (v.ToString().Equals("已打印"))
{
e.Appearance.ForeColor = Color.Brown;
}
else
{
e.Appearance.ForeColor = Color.DarkGreen;
}
}
}
}
private void SetRowsSelectionBasedOnData()
{
gridView1.ClearSelection();
for (int i = 0; i < gridView1.DataRowCount; i++)
{
object cellValue = gridView1.GetRowCellValue(i, "Status"); // 替换为实际条件列名称
if (cellValue != null && cellValue.ToString() == "未打印") // 根据你的条件进行判断
{
gridView1.SelectRow(i); // 选中满足条件的行
}
else
{
gridView1.UnselectRow(i); // 取消选中不满足条件的行
}
}
}
public bool GetDataFromLis(ref List<ItemInfo> PatientIteminfos) //从Lis获取检验信息 当返回
{
bool result = netCom.SendAndRecv(Url + "getBarCodeList", "{\"examinationCode\":\"" + TextPatCardNo.Text + "\"}", TextPatCardNo.Text); //来自lis的数据
if (!result)
{
MessageBox.Show(netCom.OutString);
return false;
}
JObject jObject = (JObject)JsonConvert.DeserializeObject(netCom.OutString);
// 定位data -> list
JArray listArray = jObject.SelectToken("data.list") as JArray;
bool isListEmpty = listArray == null || listArray.Count == 0;
if (jObject["code"].ToString() != "0")//201 401 403 404
{
//直接提示错误信息
MessageBox.Show(jObject["message"].ToString());
TextPatCardNo.Text = "";
return false;
}
else if ((jObject["code"].ToString() == "0") & (jObject["data"].ToString() == ""))//201 401 403 404
{
//直接提示错误信息
MessageBox.Show("数据为空,未开单!");
TextPatCardNo.Text = "";
return false;
}
else if ((jObject["code"].ToString() == "0") & (isListEmpty == true))//201 401 403 404
{
//直接提示错误信息
MessageBox.Show("项目数据为空,未开单!");
TextPatCardNo.Text = "";
return false;
}
else
{
DataStruct dataStruct = (DataStruct)JsonConvert.DeserializeObject<DataStruct>(jObject["data"].ToString());
CurPatientInfo = new Patient_Info();
CurPatientInfo.Name = dataStruct.user.name;
CurPatientInfo.Age = dataStruct.user.age.ToString() + "岁";
CurPatientInfo.Sex = dataStruct.user.sexName;
CurPatientInfo.CardNo = dataStruct.user.examinationCode;
CurPatientInfo.BedNo = "";
CurPatientInfo.Memo = CurPatientInfo.Name + "|" + CurPatientInfo.CardNo + "|" + CurPatientInfo.Sex + "|" + CurPatientInfo.Age + "|" + CurPatientInfo.BedNo;
itemInfos.Clear();
//测试没有数据的情况
//if (dataStruct.itemCount <= 0)
//{
// return true; //即使没数据 也是正常查询
//}
int i = 1;
foreach (Projecct projecct in dataStruct.list)
{
ItemInfo itemInfo = new ItemInfo();
itemInfo.XH = i.ToString();
itemInfo.Barcode = projecct.barCode;
//itemInfo.Tuble = GetColorInfo(projecct.tubeColorName, true); //需要看实际返回
itemInfo.Tuble = projecct.tubeColorName; //需要看实际返回 颜色
itemInfo.ItemName = projecct.checkListName; //检查单名称
itemInfo.ItemCount = "1"; //当前项目需要打印的标签数量。默认为1 projecct.labelCount;
itemInfo.Status = "0"; //打印状态0未打印,1已打印,2已撤销,3已采集已确认。 TransItemStatus(projecct.state);
itemInfo.JYType = ""; //不需要打印 projecct.sampleTypeName; //样本类型projecct.noteLabel;
itemInfo.DoDept = ""; //如果是住院,为住院科室名称;如果是门诊,为开单科室名称,可为空 projecct.ward;
itemInfo.OperTime = ""; //条码生成时间格式要求0000-00-00 00:00:00 rojecct.datebz;
itemInfo.OperDept = ""; //执行科室名称 projecct.station;
itemInfo.ItemDetails = "";//不需要打印 projecct.sampleName; //项目名称 projecct.mnemoitems;
itemInfo.PrintTime = "";
itemInfo.PrintDev = "";
itemInfo.Source = "LIS";
PatientIteminfos.Add(itemInfo);
i++;
}
LabCurCardNo.Text = CurPatientInfo.CardNo;
LabCurName.Text = CurPatientInfo.Name;
LabCurAge.Text = CurPatientInfo.Age;
LabCurSex.Text = CurPatientInfo.Sex;
return true;
}
}
public bool GetDataFromDB(ref List<ItemInfo> PatientIteminfos) //从数据库获取检验信息
{
try
{
string sql = "select * from trans_history where PatID ='" + TextPatCardNo.Text + "' and DBExcTime >'" + dateStart.DateTime.Date.ToString("yyyy-MM-dd") + "' and DBExcTime <='" + dateEnd.DateTime.Date.AddDays(1).ToString("yyyy-MM-dd") + "'";
logger.Info("Mysql sql=" + sql);
DataSet dataSet = DoDBMySql.Query(sql);
if (dataSet.Tables.Count <= 0 || dataSet.Tables[0].Rows.Count <= 0)
{
return true;
}
foreach (DataRow row in dataSet.Tables[0].Rows)
{
if (CurPatientInfo.Name == null || CurPatientInfo.Name == "")
{
CurPatientInfo.Name = row["PatName"] == null ? "" : row["PatName"].ToString();
CurPatientInfo.Age = row["PatAge"] == null ? "" : row["PatAge"].ToString();
CurPatientInfo.Sex = row["PatSex"] == null ? "" : row["PatSex"].ToString();
CurPatientInfo.CardNo = row["PatID"] == null ? "" : row["PatID"].ToString();
CurPatientInfo.BedNo = "";
CurPatientInfo.Memo = CurPatientInfo.Name + "|" + CurPatientInfo.CardNo + "|" + CurPatientInfo.Sex + "|" + CurPatientInfo.Age + "|" + CurPatientInfo.BedNo;
}
string sBarcode = row["Barcode"] == null ? "" : row["Barcode"].ToString();
if (PatientIteminfos.Any(item => item.Barcode == sBarcode))
{
continue;
}
ItemInfo itemInfo = new ItemInfo();
itemInfo.XH = (PatientIteminfos.Count+1).ToString();
itemInfo.Barcode = row["Barcode"] == null ? "" : row["Barcode"].ToString();
itemInfo.Tuble = row["Tuble"] == null ? "" : row["Tuble"].ToString();
itemInfo.ItemName = row["ItemName"] == null ? "" : row["ItemName"].ToString();
itemInfo.ItemCount = row["ItemCount"] == null ? "" : row["ItemCount"].ToString();
itemInfo.Status = TransItemStatus(row["ItemStatus"] == null ? "" : row["ItemStatus"].ToString());
itemInfo.JYType = row["ItemType"] == null ? "" : row["ItemType"].ToString();
itemInfo.DoDept = row["DoDept"] == null ? "" : row["DoDept"].ToString();
itemInfo.OperTime = row["OprTime"] == null ? "" : row["OprTime"].ToString();
itemInfo.OperDept = row["OprDept"] == null ? "" : row["OprDept"].ToString();
itemInfo.ItemDetails = row["ItemsDetails"] == null ? "" : row["ItemsDetails"].ToString();
itemInfo.PrintTime = row["PrintTime"] == null ? "" : row["PrintTime"].ToString();
itemInfo.PrintDev = row["PrinterDev"] == null ? "" : row["PrinterDev"].ToString();
itemInfo.Source = "DB";
PatientIteminfos.Add(itemInfo);
}
return true;
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
return false;
}
}
public void GetNameFromDBbyBarcode(string barcode)
{
try
{
logger.Info("扫到条码:" + barcode);
string sql = "select PatName from trans_history where Barcode ='" + barcode + "' and DBExcTime >'" + dateStart.DateTime.Date.ToString("yyyy-MM-dd") + "' and DBExcTime <='" + dateEnd.DateTime.Date.AddDays(1).ToString("yyyy-MM-dd") + "' limit 1";
DataSet dataSet = DoDBMySql.Query(sql);
if (dataSet.Tables.Count <= 0 || dataSet.Tables[0].Rows.Count <= 0)
{
logger.Info($"没有检索到{barcode}相关记录");
MyMessageBox myMessageBox = new MyMessageBox(MessageBoxButtons.OKCancel, "提示", $"没有检索到{barcode}相关记录", 3);
myMessageBox.ShowDialog();
TextPatCardNo.Text = "";
return ;
}
foreach (DataRow row in dataSet.Tables[0].Rows)
{
string Callinfo = string.Format("请{0}到{1}采血 ", row["PatName"].ToString(), Login.nurseDeskInfo.WindowName);
Callinfo = Callinfo + "... " + Callinfo ;
logger.Info($"插入语音叫号数据 【{Callinfo}】");
Addmedia(Callinfo);
TextPatCardNo.Text = "";
return ;
}
return ;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
return ;
}
}
public bool GetPatientData()
{
if (TextPatCardNo.Text.Length <= 0)
{
//MessageBox.Show("患者卡信息不能为空");
MyMessageBox myMessageBox = new MyMessageBox(MessageBoxButtons.OKCancel, "提示", "患者卡信息不能为空", 3);
myMessageBox.ShowDialog();
TextPatCardNo.Text = "";
return false;
}
ClearDefaultData();
List<ItemInfo> PatientIteminfos = new List<ItemInfo>();
if (!GetDataFromLis(ref PatientIteminfos))
return false;
logger.Info($"执行诊结");
string cardNo = TextPatCardNo.Text;
Task.Run(() => NetCom.SendHisComplete(cardNo));
GetDataFromDB(ref PatientIteminfos);
itemInfos = PatientIteminfos;
LabCurCardNo.Text = CurPatientInfo.CardNo;
LabCurName.Text = CurPatientInfo.Name;
LabCurAge.Text = CurPatientInfo.Age;
LabCurSex.Text = CurPatientInfo.Sex;
UpdateInfo(GetCheckedRadio());
if(ItemTotalCount<=0)
{
MyMessageBox myMessageBox = new MyMessageBox(MessageBoxButtons.OKCancel, "提示", $"没有检索到{TextPatCardNo.Text}相关信息", 3);
myMessageBox.ShowDialog();
TextPatCardNo.Text = "";
return false;
}
TextPatCardNo.Text = "";
return true;
}
public static bool CanDispense(string Tube)
{
if (SystemSet.mTubeLabelTool.canDispenseTubles.Contains(Tube))
return true;
else
return false;
}
public void ClearDefaultData()
{
LabCurCardNo.Text ="";
LabCurName.Text = "";
LabCurAge.Text = "";
LabCurSex.Text = "";
ItemTotalCount = 0;
ItemSGCount = 0;
ItemBQCount = 0;
ItemSelectTotalCount = 0;
ItemSelectSGCount = 0;
ItemSelectBQCount = 0;
LabItemTotal.Text = "";
LabItemSG.Text = "";
LabItemBQ.Text = "";
LabItemSelectTotal.Text = "";
LabItemSelectSG.Text = "";
LabItemSelectBQ.Text = "";
itemInfos.Clear();
itemInfostoShow.Clear();
gridControl1.DataSource = null;
gridControl1.DataSource = itemInfostoShow;
gridControl1.RefreshDataSource();
}
private void BGetData_Click(object sender, EventArgs e)
{
GetPatientData();
}
public static string TransItemStatus(string status)
{
string Outstr = "";
switch(status)
{
case "0":
Outstr = "未打印";
break;
case "1":
Outstr = "已打印";
break;
case "2":
Outstr = "已撤销";
break;
case "3":
Outstr = "已采集已确认";
break;
}
return Outstr;
}
private void CheckedChanged(object sender, EventArgs e)
{
RadioButton radioButton = sender as RadioButton;
if(radioButton.Checked == true)
{
UpdateInfo(radioButton.Text);
}
}
public string GetCheckedRadio()
{
if (RadAll.Checked)
return RadAll.Text;
if (RadUnPrint.Checked)
return RadUnPrint.Text;
if (RadPrinted.Checked)
return RadPrinted.Text;
if (RadCanceld.Checked)
return RadCanceld.Text;
if (RadComp.Checked)
return RadComp.Text;
return RadAll.Text;
}
public void UpdateInfo(string Tag)
{
ItemTotalCount = 0;
ItemSGCount = 0;
ItemBQCount = 0;
ItemSelectTotalCount = 0;
ItemSelectSGCount = 0;
ItemSelectBQCount = 0;
switch (Tag)
{
case "全部":
itemInfostoShow = new List<ItemInfo>();
foreach (ItemInfo itemInfo in itemInfos)
{
itemInfostoShow.Add(itemInfo);
ItemTotalCount++;
if (CanDispense(itemInfo.Tuble))
{
ItemSGCount++;
}
else
{
ItemBQCount++;
}
}
itemInfostoShow = itemInfos;
break;
default:
itemInfostoShow = new List<ItemInfo>();
foreach (ItemInfo itemInfo in itemInfos)
{
if (itemInfo.Status.Equals(Tag))
{
itemInfostoShow.Add(itemInfo);
ItemTotalCount++;
if (CanDispense(itemInfo.Tuble))
{
ItemSGCount++;
}
else
{
ItemBQCount++;
}
}
}
break;
}
gridControl1.DataSource = null;
gridControl1.DataSource = itemInfostoShow;
gridControl1.RefreshDataSource();
gridView1.SelectAll();
gridView1.RefreshData();
LabItemTotal.Text = ItemTotalCount.ToString();
LabItemSG.Text = ItemSGCount.ToString();
LabItemBQ.Text = ItemBQCount.ToString();
LabItemSelectTotal.Text = "";
LabItemSelectSG.Text = "";
LabItemSelectBQ.Text = "";
//SetRowsSelectionBasedOnData();
}
private void TextPatCardNo_TextChanged(object sender, EventArgs e)
{
}
private void TextPatCardNo_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == 13)
{
string currentInput = TextPatCardNo.Text.Trim();
if (string.IsNullOrWhiteSpace(currentInput))
{
return;
}
// 检查当前输入是否与上一次输入相同
if (currentInput == LastCardNo)
{
// 如果计时器正在运行,说明这是 5 秒内的第二次输入
if (TimerforCheckSameInput.Enabled)
{
TimerforCheckSameInput.Stop();
MyMessageBox myMessageBox = new MyMessageBox(MessageBoxButtons.YesNo, "提示", $"连续输入相同卡号{LastCardNo},是否确认打印", 3);
myMessageBox.ShowDialog();
DialogResult dialogResult = myMessageBox.DialogResult;// MessageBox.Show($"连续输入相同卡号{LastCardNo},是否确认打印", "提示", MessageBoxButtons.YesNo);
if (dialogResult == DialogResult.No)
{
TextPatCardNo.Text = "";
return;
}
}
}
LastCardNo = currentInput;
TimerforCheckSameInput.Start();
if (GetPatientData()&&ItemSelectTotalCount > 0)
{
AutoDispense();
}
}
}
private void timerForFouce_Tick(object sender, EventArgs e)
{
if(MainForm.selectedTabPage.Name=="门诊采血")
{
TextPatCardNo.Focus();
}
}
private void gridView1_SelectionChanged(object sender, DevExpress.Data.SelectionChangedEventArgs e)
{
int[] selectedRowHandles = gridView1.GetSelectedRows();
ItemSelectTotalCount = 0;
ItemSelectSGCount = 0;
ItemSelectBQCount = 0;
// 遍历选中的行
foreach (int rowHandle in selectedRowHandles)
{
// 检查行是否有效
if (rowHandle >= 0 && rowHandle < gridView1.DataRowCount)
{
// 获取行数据
object dataRow = gridView1.GetDataRow(rowHandle);
string columnValue = gridView1.GetRowCellValue(rowHandle, "Tuble").ToString();
if(CanDispense(columnValue))
{
ItemSelectSGCount++;
}
else
{
ItemSelectBQCount++;
}
ItemSelectTotalCount++;
}
}
LabItemSelectTotal.Text = ItemSelectTotalCount.ToString();
LabItemSelectSG.Text = ItemSelectSGCount.ToString();
LabItemSelectBQ.Text = ItemSelectBQCount.ToString();
}
private void bPrint_Click(object sender, EventArgs e)
{
AutoDispense();
}
public void AutoDispense()
{
if (ItemSelectTotalCount <= 0)
{
MessageBox.Show("请先选择需要打印的项目");
return;
}
bool ItemStatusExp = false; //项目状态异常 需要进行提示
bool ItemSourceExp = false; //项目来源异常 需要进行提示
int[] selectedRowHandles = gridView1.GetSelectedRows();
// 遍历选中的行
PatientDatail patientDatail = new PatientDatail();
patientDatail.PatientInfo = CurPatientInfo;
List<jyData> jyDatas = new List<jyData>();
List<OrginData> orginDatas = new List<OrginData>();
foreach (int rowHandle in selectedRowHandles)
{
// 检查行是否有效
if (rowHandle >= 0 && rowHandle < gridView1.DataRowCount)
{
// 获取行数据
object dataRow = gridView1.GetDataRow(rowHandle);
string PatID = CurPatientInfo.CardNo;
string PatName = CurPatientInfo.Name;
string PatAge = CurPatientInfo.Age;
string PatSex = CurPatientInfo.Sex;
string Barcode = gridView1.GetRowCellValue(rowHandle, "Barcode").ToString();
string Tuble = gridView1.GetRowCellValue(rowHandle, "Tuble").ToString();
string ItemName = gridView1.GetRowCellValue(rowHandle, "ItemName").ToString();
string ItemCount = gridView1.GetRowCellValue(rowHandle, "ItemCount").ToString();
string ItemType = gridView1.GetRowCellValue(rowHandle, "JYType").ToString();
string DoDept = gridView1.GetRowCellValue(rowHandle, "DoDept").ToString();
string OprDept = gridView1.GetRowCellValue(rowHandle, "OperDept").ToString();
string OprTime = gridView1.GetRowCellValue(rowHandle, "OperTime").ToString();
string PrintTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
string ItemStatus = gridView1.GetRowCellValue(rowHandle, "Status").ToString(); ;
string ItemsDetails = gridView1.GetRowCellValue(rowHandle, "ItemDetails").ToString();
string Source = gridView1.GetRowCellValue(rowHandle, "Source").ToString();
if (!ItemStatus.Equals("未打印"))
{
ItemStatusExp = true;
}
if (Source.Equals("DB"))
{
ItemSourceExp = true;
}
jyData mjyData = new jyData();
mjyData.sgname = Tuble;
mjyData.Barcode = Barcode;
mjyData.itemInfo = ItemName;
var variables = new Dictionary<string, string>
{
{ "pictureBox1", Barcode },
{ "Barcode", Barcode },
{ "ItemInfo", ItemName },
{ "CardNo", PatID },
{ "ItemType", ItemType },
{ "Age", PatAge },
{ "PrintTime", PrintTime },
{ "OprDept", OprDept },
{ "DoDept", DoDept },
{ "Tuble", Tuble },
{ "patSex", PatSex },
{ "patName", PatName }
};
string bqxx = Regex.Replace(Recp, @"\{(\w+)\}", match =>
{
string variableName = match.Groups[1].Value;
return variables.ContainsKey(variableName) ? variables[variableName] : match.Value;
});
//string bqxx = "B060010255050|" + mjyData.Barcode + "@TB18320020080040|L^" + Tuble + "@TB18110060220040|L^" + mjyData.Barcode + "@TB18032090400040|L^" + CurPatientInfo.Name + " " + CurPatientInfo.Sex + " " + OprDept + " " + DoDept + "@TB18032120400040|L^" + DateTime.Now.ToString("yyyy-MM-dd") + " " + ItemType + " " + CurPatientInfo.CardNo + "@TB18032150400080|L^" + mjyData.itemInfo;
if (!RecpOnly.Checked)
{
mjyData.sgxx = bqxx;
if(CanDispense(mjyData.sgname))
{
mjyData.bqtype = 1;
}
else
{
mjyData.bqtype = 2;
}
}
else
{
mjyData.sgxx = bqxx;
mjyData.bqtype = 2;
}
jyDatas.Add(mjyData);
OrginData orginData = new OrginData();
orginData.PatID = CurPatientInfo.CardNo;
orginData.PatName = CurPatientInfo.Name;
orginData.PatAge = CurPatientInfo.Age;
orginData.PatSex = CurPatientInfo.Sex;
orginData.Barcode = Barcode;
orginData.Tuble = Tuble;
orginData.ItemName = ItemName;
orginData.ItemCount = ItemCount;
orginData.ItemType = ItemType;
orginData.DoDept = DoDept;
orginData.OprDept = OprDept;
orginData.OprTime = OprTime;
orginData.PrintTime = PrintTime;
orginData.ItemStatus = "1";
orginData.ItemsDetails = ItemsDetails;
orginData.PrinterDev = Login.nurseDeskInfo.NurseName;
orginDatas.Add(orginData);
patientDatail.ItemCount++;
}
}
patientDatail.jyDatas = jyDatas;
patientDatail.OrginDatas = orginDatas;
//if (ItemSourceExp|| ItemStatusExp)
//{
// DialogResult dialogResult = MessageBox.Show((ItemStatusExp ? "所选项目部分状态异常,是否确认打印?\r\n" : "")+ (ItemSourceExp ? "所选项目部分来源于历史数据库" : ""), "提示", MessageBoxButtons.YesNo);
// if (dialogResult == DialogResult.No)
// return;
//}
SystemSet.systemSet.myServer.ParseData(patientDatail);
/********************测试用****************************/
//MZCY.ConformTask conformTask = new MZCY.ConformTask();
//conformTask.orginDatas = patientDatail.OrginDatas;
//MZCY.ConformTaskQueue.Enqueue(conformTask);
}
public string GetDaylyCountInfo(List<string> Candispense,string User)
{
try
{
if (Candispensestr == "")
{
foreach (string str in SystemSet.mTubeLabelTool.canDispenseTubles)
{
if (Candispensestr == "")
{
Candispensestr = "\'" + str + "\'";
}
else
{
Candispensestr = Candispensestr + ",\'" + str + "\'";
}
}
}
string Sql = "SELECT COUNT(DISTINCT PatID) AS UniqueCardNoCount,COUNT(CASE WHEN Tuble in(" + (Candispensestr == "" ? "'BUG'" : Candispensestr) + ") THEN 1 END) AS SGCount,COUNT(CASE WHEN Tuble not in(" + (Candispensestr == "" ? "'BUG'" : Candispensestr) + ") THEN 1 END) AS BQCount FROM trans_history where DBExcTime BETWEEN CURDATE() AND DATE_ADD(CURDATE(), INTERVAL 1 DAY) AND PrinterDev='" + User + "'";
DataSet dataSet = DoDBMySql.Query(Sql);
if (dataSet.Tables[0].Rows.Count <= 0)
{
return "0|0|0";
}
return dataSet.Tables[0].Rows[0]["UniqueCardNoCount"].ToString() + "|" + dataSet.Tables[0].Rows[0]["SGCount"].ToString() + "|" + dataSet.Tables[0].Rows[0]["BQCount"].ToString();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
return "0|0|0";
}
}
private void gridView1_RowCellClick(object sender, DevExpress.XtraGrid.Views.Grid.RowCellClickEventArgs e)
{
if (e.Column != null && e.Column.FieldName == "ItemName")
{
string detailes = gridView1.GetRowCellValue(e.RowHandle, "ItemDetails").ToString();
ItemsShowBox itemsShowBox = new ItemsShowBox(detailes);
itemsShowBox.Show();
}
}
private void MZCY_FormClosing(object sender, FormClosingEventArgs e)
{
ThreadRun = false;
}
private void BSetStatus_Click(object sender, EventArgs e)
{
/********************测试用****************************/
//for(int i=1;i<120;i++)
//{
// string sql = "Insert into trans_history(PatID,PatName,PatAge,PatSex,Barcode,Tuble ,ItemName ,ItemCount,ItemType ,DoDept ,OprDept ,OprTime,PrintTime,ItemStatus,ItemsDetails,PrinterDev)values('HN755155','马洪义','66','男','"+DateTime.Now.ToString("yyyyMMddHHmmssfff")+"','黄','血清三碘甲腺原氨酸测定等20项','1','静脉血','免疫室','健康管理中心','2024-12-06 10:11:42','2024-12-07 11:55:11','1','血清三碘甲腺原氨酸测定;血清甲状腺素测定;血清游离T3测定;血清游离T4测定;血清促甲状腺激素测定;促甲状腺激素受体抗体测定;抗甲状腺过氧化物酶抗体测定;血清甲状腺球蛋白抗体测定;甲胎蛋白测定;血清CA125;血清CA19-9;PSA(游离);血清CA15-3;PSA(总);血清CA724;细胞角质素片段19;神经原特异性烯醇化酶;鳞状上皮细胞癌相关抗原;胃泌素释放肽前体;癌胚抗原测定;','0338') ON DUPLICATE KEY UPDATE Tuble = VALUES(Tuble),ItemName = VALUES(ItemName),ItemCount = VALUES(ItemCount),ItemType = VALUES(ItemType),OprTime = VALUES(OprTime),OprDept = VALUES(OprDept),DoDept = VALUES(DoDept),PrintTime = VALUES(PrintTime),ItemStatus = VALUES(ItemStatus),ItemsDetails = VALUES(ItemsDetails),PrinterDev = VALUES(PrinterDev)";
// logger.Info("Mysql sql=" + sql);
// int Ret = DoDBMySql.ExecuteSql(sql);
//}
}
private void gridView1_DoubleClick(object sender, EventArgs e)
{
if (gridView1.RowCount > 0 && gridView1.FocusedColumn != null && gridView1.FocusedRowHandle >= 0)
{
string data = gridView1.GetFocusedRowCellDisplayText(gridView1.FocusedColumn);
if (!String.IsNullOrEmpty(data))
Clipboard.SetText(data, TextDataFormat.Text);
}
}
private void gridControl1_Click(object sender, EventArgs e)
{
}
private void PicClear_Click(object sender, EventArgs e)
{
TextPatCardNo.Clear();
}
#region
/// <summary>
/// 向媒体控制接口发送控制命令
/// </summary>
/// <param name="lpszCommand">命令,参见
/// http://msdn.microsoft.com/en-us/library/windows/desktop/dd743572(v=vs.85).aspx </param>
/// <param name="lpszReturnString">命令返回的信息如果没有需要返回的信息可以为null</param>
/// <param name="cchReturn">指定返回信息的字符串大小</param>
/// <param name="hwndCallback">回调句柄如果命令参数中没有指定notify标识可以为new IntPtr(0)</param>
/// <returns>返回命令执行状态的错误代码</returns>
[DllImport("winmm.dll")]
static extern Int32 mciSendString(string lpszCommand, StringBuilder returnString, int bufferSize, IntPtr hwndCallback);
/// <summary>
/// 返回对执行状态错误代码的描述
/// </summary>
/// <param name="errorCode">mciSendCommand或者mciSendString返回的错误代码</param>
/// <param name="errorText">对错误代码的描述字符串</param>
/// <param name="errorTextSize">指定字符串的大小</param>
/// <returns>如果ERROR Code未知返回false</returns>
[DllImport("winmm.dll")]
static extern bool mciGetErrorString(Int32 errorCode, StringBuilder errorText, Int32 errorTextSize);
public const int MM_MCINOTIFY = 0x3B9; //这是声明 播完音乐 mciSendString向系统发送的指令
protected override void DefWndProc(ref System.Windows.Forms.Message m)
{
base.DefWndProc(ref m);
if (m.Msg == MM_MCINOTIFY)//播放结束
{
MediaState = false;
AllMediaList.Remove(CurrInfo);
}
}
private delegate void MediaAddHandel();
private void InvokeMedia()
{
if (!this.InvokeRequired)
{
MediaAddHandel md = new MediaAddHandel(MediaAdd);
Invoke(md);
}
else
{
MediaAddHandel md = new MediaAddHandel(MediaAdd);
Invoke(md);
}
}
private void MediaAdd()
{
ProcessInfo();
}
// static Form1 Form1handle;
public static void Addmedia(string str)
{
AllMediaList.Add(new ListMedia { MediaContent = str, State = 0, WavePath = "" });
// InvokeMedia();
}
private void ProcessInfo()
{
if (AllMediaList.Count > 0)
{
if (!MediaState)
{
MediaState = true;
CurrInfo = AllMediaList.First();
TTS(AllMediaList.First().MediaContent);
}
}
}
private void TransferTextToFile(string txt, string path)
{
SpeechStreamFileMode SpFileMode = SpeechStreamFileMode.SSFMCreateForWrite;
SpFileStream SpFileStream = new SpFileStream();
SpFileStream.Open(path, SpFileMode, false); // ZC: 保存文件 与 输出文件流 绑定
string speakWeather = txt;
SpeechVoiceSpeakFlags SpFlags = SpeechVoiceSpeakFlags.SVSFlagsAsync;//异步的播放方式
SpVoice Mvoice = new SpVoice();
Mvoice.Voice = Mvoice.GetVoices("name=Microsoft Server Speech Text to Speech Voice (zh-CN, HuiHui)", "").Item(0);
Mvoice.AudioOutputStream = SpFileStream;
Mvoice.Speak(speakWeather, SpFlags);
Mvoice.WaitUntilDone(500);
SpFileStream.Close();
//MessageBox.Show("导出语音成功!");
// logger.Debug("导出语音成功!");
}
private void TTS(string ttsstr)
{
if (ttsstr == null)
{
MediaState = false;
return;
}
if (Login.nurseDeskInfo.PcType == "Win10" || Login.nurseDeskInfo.PcType == "Win8")
{
// ttsstr = "请" + ttsstr + "号到" + CkH + "号窗口采血";
SpeechSynthesizer speech = new SpeechSynthesizer { Rate = 0, Volume = 100 };
speech.SelectVoice("Microsoft Huihui Desktop");
speech.SpeakAsync(ttsstr);
AllMediaList.Remove(CurrInfo);
MediaState = false;
}
else
{
if (!Directory.Exists(AppDomain.CurrentDomain.BaseDirectory + "tts"))
{
Directory.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory + "tts");
}
CurrInfo.WavePath = AppDomain.CurrentDomain.BaseDirectory + "tts\\" + System.DateTime.Now.ToString("hhmmss") + ".wav";
TransferTextToFile(ttsstr, CurrInfo.WavePath);
PlaySong(CurrInfo.WavePath);
}
}
public void PlaySong(string file)
{
try
{
mciSendString("close myDivece", null, 0, IntPtr.Zero); //关闭
int error = mciSendString("open " + file + " alias myDivece", null, 0, new IntPtr(0));
if (error == 0)
{
mciSendString("play myDivece notify", null, 0, this.Handle); //播放
}
else
{
StringBuilder errorText = new StringBuilder();
mciGetErrorString(error, errorText, 50);
// MessageBox.Show(errorText.ToString());
}
}
catch (Exception)
{
mciSendString("close myDivece", null, 0, IntPtr.Zero); //关闭
}
}
#endregion
private void TimeForCall_Tick(object sender, EventArgs e)
{
Thread myThread = new Thread(new ThreadStart(ProcessInfo));//实例化Thread线程类对象
myThread.Start();
}
private void Bcall_Click(object sender, EventArgs e)
{
ReadBarcode readBarcode = new ReadBarcode();
if(readBarcode.ShowDialog()==DialogResult.OK)
{
GetNameFromDBbyBarcode(readBarcode.InputString);
}
}
private void panelData_Paint(object sender, PaintEventArgs e)
{
}
}
}