diff --git a/MyHosListener/.gitignore b/MyHosListener/.gitignore new file mode 100644 index 0000000..84c47d5 --- /dev/null +++ b/MyHosListener/.gitignore @@ -0,0 +1,30 @@ +## 编译输出 +bin/ +obj/ + +## Visual Studio +.vs/ +*.user +*.suo +*.sln.docstates +*.userprefs + +## NuGet +packages/ + +## 临时文件 +*.cache +*.tmp +*.log +*.tlog +*.ilk +*.pdb + +## 设计时 +DesignTimeResolveAssemblyReferences* +_dependencies/ + +## 其他 +*.opensdf +*.sdf +ipch/ \ No newline at end of file diff --git a/MyHosListener/App.config b/MyHosListener/App.config new file mode 100755 index 0000000..52251d5 --- /dev/null +++ b/MyHosListener/App.config @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/MyHosListener/App.xaml b/MyHosListener/App.xaml new file mode 100755 index 0000000..3afc944 --- /dev/null +++ b/MyHosListener/App.xaml @@ -0,0 +1,9 @@ + + + + + diff --git a/MyHosListener/App.xaml.cs b/MyHosListener/App.xaml.cs new file mode 100755 index 0000000..d52bb2c --- /dev/null +++ b/MyHosListener/App.xaml.cs @@ -0,0 +1,35 @@ +using log4net; +using log4net.Config; +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Data; +using System.IO; +using System.Linq; +using System.Threading.Tasks; +using System.Windows; + +namespace MyHosListener +{ + /// + /// App.xaml 的交互逻辑 + /// + public partial class App : Application + { + protected override void OnStartup(StartupEventArgs e) + { + base.OnStartup(e); + + var logDirectory = Path.GetDirectoryName("logs\\"); + if (!Directory.Exists(logDirectory)) + { + Directory.CreateDirectory(logDirectory); + } + + // 初始化 log4net + var logCfg = new FileInfo("log4net.config"); + XmlConfigurator.Configure(logCfg); + + } + } +} diff --git a/MyHosListener/MainWindow.xaml b/MyHosListener/MainWindow.xaml new file mode 100755 index 0000000..a964ed3 --- /dev/null +++ b/MyHosListener/MainWindow.xaml @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/MyHosListener/MainWindow.xaml.cs b/MyHosListener/MainWindow.xaml.cs new file mode 100755 index 0000000..8e8f02a --- /dev/null +++ b/MyHosListener/MainWindow.xaml.cs @@ -0,0 +1,343 @@ +using Com.Neusoft.Nhip; +using MyHosListener.common; +using MyHosListener.common.listener; +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Data; +using System.Globalization; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; +using System.Xml; +using System.Xml.Linq; + +namespace MyHosListener +{ + /// + /// MainWindow.xaml 的交互逻辑 + /// + public partial class MainWindow : Window + { + log4net.ILog log = log4net.LogManager.GetLogger(typeof(MainWindow)); + private bool autoClearLog = true; + private bool stopScroll = false; + private int clearCountLimit = 15; // 超过20条清屏 + + private int currentCount = 0; + public MainWindow() + { + InitializeComponent(); + } + + private void Window_Loaded(object sender, RoutedEventArgs e) + { + string maxLineStr = ConfigurationManager.AppSettings["MaxLines"]; + if (int.TryParse(maxLineStr, out int maxLines)) + { + clearCountLimit = maxLines; + } + + log.Info("启动队列监听程序"); + AppendMessage("监听服务正在启动...", 0); + ReceiveMessagesAsynchronous(); + Tools.StartRound(); + } + + private void Window_Closed(object sender, EventArgs e) + { + // 服务器退出时候可以调用(不调用也可) + MQProxy.StopListener(); + log.Info("操作员关闭队列监听程序"); + } + async void ReceiveMessagesAsynchronous() + { + await Task.Run(() => + { + try + { + // 设定监听注册非药品收费项目信息 + //MQProxy.RegisterQueueListener("QhdLK_YYGL_createExamRequest", this.OnMessage); + + // 注册非药品收费项目信息 + //MI0150Listener lis0150 = new MI0150Listener(this); + //MQProxy.RegisterQueueListener("QhdLK_YYGL_createUnDrugsInfo", lis0150.OnMessage); + + // 变更非药品收费项目信息 + //MU0151Listener lis0151 = new MU0151Listener(this); + //MQProxy.RegisterQueueListener("QhdLK_YYGL_updateUnDrugsInfo", lis0151.OnMessage); + + // 注册非药品术语对照信息 + MI0164Listener lis0164 = new MI0164Listener(this); + MQProxy.RegisterQueueListener("QhdLK_YYGL_createOrderTerm", lis0164.OnMessage); + + // 变更非药品术语对照信息 + MU0165Listener lis0165 = new MU0165Listener(this); + MQProxy.RegisterQueueListener("QhdLK_YYGL_updateOrderTerm", lis0165.OnMessage); + + //// 注册检查申请单 + CI0047Listener lis0047 = new CI0047Listener(this); + MQProxy.RegisterQueueListener("QhdLK_YYGL_createExamRequest", lis0047.OnMessage); + + //// 作废检查医嘱 + CD0050Listener lis0050 = new CD0050Listener(this); + MQProxy.RegisterQueueListener("QhdLK_YYGL_deleteExamRequest", lis0050.OnMessage); + + //// 注册检查申请单缴费状态 + CI0054Listener lis0054 = new CI0054Listener(this); + MQProxy.RegisterQueueListener("QhdLK_YYGL_createExamRequestEvent", lis0054.OnMessage); + + //// 注册申请单退费状态 + CI0055Listener lis0055 = new CI0055Listener(this); + MQProxy.RegisterQueueListener("QhdLK_YYGL_stopExamRequestEvent", lis0055.OnMessage); + + //// 注册医嘱执行单信息 + OI0083Listener lis0083 = new OI0083Listener(this); + MQProxy.RegisterQueueListener("QhdLK_YYGL_createOrderExecuteForm", lis0083.OnMessage); + + // 作废医嘱执行单信息 + OD0084Listener lis0084 = new OD0084Listener(this); + MQProxy.RegisterQueueListener("QhdLK_YYGL_cancleOrderExecuteForm", lis0084.OnMessage); + + // 启动队列监听 + MQProxy.StartListener(); + log.Info("队列监听启动成功"); + AppendMessage("监听服务启动成功--开始接收数据", 0); + } + catch (Exception ex) + { + log.Info("启动队列监听失败--" + ex.Message); + AppendMessage("监听服务启动失败!!!(详情请查看日志文件)", 0); + MessageBox.Show(ex.Message); + } + }); + + + } + + #region 两个按钮事件 + + private void ClearLog_Click(object sender, RoutedEventArgs e) + { + if (MessageBox.Show(this, "是否清空全部日志", "系统提示!", MessageBoxButton.OKCancel, MessageBoxImage.Warning, MessageBoxResult.OK) == MessageBoxResult.OK) + { + log.Info("主动清理日志"); + logBox.Clear(); + currentCount = 0; + } + else + { + // do nothing + } + } + /// + /// 可以在此处加入自己的测试代码 + /// + /// + /// + private void Save2Log_Click(object sender, RoutedEventArgs e) + { + + try + { + //string logContent = logBox.Text; + //if (logContent.Length == 0) + //{ + // MessageBox.Show("暂无日志无需保存", "系统提示", MessageBoxButton.OK, MessageBoxImage.Warning); + // return; + //} + //// 获取程序所在路径 + //string appDir = AppDomain.CurrentDomain.BaseDirectory; + //string logDir = System.IO.Path.Combine(appDir, "saveLog"); + + //// 如果文件夹不存在则创建 + //if (!Directory.Exists(logDir)) + //{ + // Directory.CreateDirectory(logDir); + //} + + //// 生成日志文件名(带时间戳) + //string fileName = $"temp_{DateTime.Now:yyyyMMdd_HHmmss}.txt"; + //string fullPath = System.IO.Path.Combine(logDir, fileName); + + //// 写入日志内容 + //File.WriteAllText(fullPath, logContent); + + //MessageBox.Show($"日志保存成功:{fullPath}", "提示", MessageBoxButton.OK, MessageBoxImage.Information); + + + + //string xmlStr = " "; + //string xmlStr = "\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n\r\n"; + + //0083 + //string xmlStr = "\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n\r\n"; + + //0150 + // string xmlStr = "\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n\r\n"; + + //047 + //string xmlStr= " "; + + //0083 + //string xmlStr = " "; + + //050 + // string xmlStr = "\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n\r\n"; + + //054 + //string xmlStr = "\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n\r\n"; + + //151 + // string xmlStr = "\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n\r\n"; + //164 + //string xmlStr = "\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n\r\n"; + //165 + string xmlStr = "\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n\r\n"; + XDocument xdoc = XDocument.Parse(xmlStr); + // 获取默认命名空间 + XNamespace ns = "urn:hl7-org:v3"; + var messageId = xdoc.Descendants(ns + "id") + .FirstOrDefault() // 括号内可以加判定条件 + ?.Attribute("extension")?.Value; + var termCode = xdoc + .Descendants(ns + "item") + .FirstOrDefault(x => (string)x.Attribute("root") == "2.16.156.10011.0.9.2.3.2.101") + ?.Attribute("extension")?.Value; + + var termName = xdoc + .Descendants(ns + "item") + .FirstOrDefault(x => (string)x.Attribute("root") == "2.16.156.10011.0.9.2.3.2.101") + ?.Attribute("identifierName")?.Value; + + var isEffective = xdoc + .Descendants(ns + "item") + .FirstOrDefault(x => (string)x.Attribute("root") == "2.16.156.10011.0.9.2.3.2.101") + ?.Attribute("validTimeLow")?.Value; + + var requestTypeCode = xdoc + .Descendants(ns + "translation") + .FirstOrDefault(x => (string)x.Attribute("code") != null && (string)x.Attribute("codeSystemName")== "申请单类型代码表") + ?.Attribute("code")?.Value; + + + //string sql_exits = "select id from s_check_item where item_code = @item_code"; + //dc.Add("item_code", itemCode); + //if (db.ExecQuery(sql_exits, dc).Rows.Count == 0) + //{ + // //不存在则执行插入操作 + // string insert = @"INSERT INTO s_check_item(termClassId,item_code, item_desc, item_name) VALUES (@termClassId, @item_code, @item_desc, @item_name)"; + // dc.Clear(); + // dc.Add("termClassId", itemGrade); + // dc.Add("item_code", itemCode); + // dc.Add("item_desc", itemName); + // dc.Add("item_name", itemName); + // int ins = db.ExecSQL(insert, dc); + // if (ins > 0) + // { + // // 执行成功了,可以做其他业务处理 + // MyLog.Info("消息已入库成功"); + // MessageBox.Show($"消息入库成功", "系统提示", MessageBoxButton.OK, MessageBoxImage.Information); + // } + // else + // { + // MessageBox.Show($"消息入库失败:{ins}", "系统提示", MessageBoxButton.OK, MessageBoxImage.Error); + // } + // MyLog.Info("itemCode:" + itemCode); + + // return; + //} + + + //string sql_insert = @"INSERT INTO s_list_log(list_id, reg_num, old_status, new_status, create_user) VALUES (@list_id, @reg_num, @old_status, @new_status, @create_user)"; + //dc.Clear(); + //dc.Add("list_id", 12); + //dc.Add("reg_num", "A0001"); + //dc.Add("old_status", "old1"); + //dc.Add("new_status", "new1"); + //dc.Add("create_user", "admin1"); + //int ret = db.ExecSQL(sql_insert, dc); + //if (ret == 0) + //{ + // // 执行成功了,可以做其他业务处理 + // MyLog.Info("消息已入库成功"); + // MessageBox.Show($"消息入库成功", "系统提示", MessageBoxButton.OK, MessageBoxImage.Information); + //} + //else + //{ + // MessageBox.Show($"消息入库失败:{ret}", "系统提示", MessageBoxButton.OK, MessageBoxImage.Error); + //} + //MyLog.Info("cardNo:" + ""); + } + catch (Exception ex) + { + MessageBox.Show($"保存日志时发生错误:{ex.Message}", "错误", MessageBoxButton.OK, MessageBoxImage.Error); + } + } + + private void ToggleScroll_Click(object sender, RoutedEventArgs e) + { + if (stopScroll) + { + iv_scrTag1.Source = new BitmapImage(new Uri("pack://application:,,,/images/pwd_uncheck.png")); + } + else + { + iv_scrTag1.Source = new BitmapImage(new Uri("pack://application:,,,/images/pwd_checked.png")); + } + stopScroll = !stopScroll; + } + + private void ToggleAutoClearLog_Click(object sender, RoutedEventArgs e) + { + //var isRemember = AppConfigHelper.GetVal("app_remember", "1"); + if (autoClearLog) + { + iv_scrTag2.Source = new BitmapImage(new Uri("pack://application:,,,/images/pwd_uncheck.png")); + } + else + { + iv_scrTag2.Source = new BitmapImage(new Uri("pack://application:,,,/images/pwd_checked.png")); + } + autoClearLog = !autoClearLog; + } + #endregion + + /// + /// 输出消息到界面 + /// + /// + /// 0不需要追加结束标记 + public void AppendMessage(string message, int flag = 1) + { + Dispatcher.Invoke(() => + { + currentCount++; + logBox.AppendText(message + Environment.NewLine); + if (flag == 1) + { + logBox.AppendText("==================================================== End ====================================================" + Environment.NewLine); + } + if (!stopScroll) + { + logBox.ScrollToEnd(); + } + if (autoClearLog && currentCount >= clearCountLimit) + { + logBox.Clear(); + currentCount = 0; + } + }); + } + } +} diff --git a/MyHosListener/MyHosListener.csproj b/MyHosListener/MyHosListener.csproj new file mode 100755 index 0000000..f3dc01e --- /dev/null +++ b/MyHosListener/MyHosListener.csproj @@ -0,0 +1,217 @@ + + + + + Debug + AnyCPU + {E0024F00-0A93-4306-8B4A-431FEAF6D4E8} + WinExe + MyHosListener + MyHosListener + v4.7.2 + 512 + {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 4 + true + true + publish\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 0 + 1.0.0.%2a + false + false + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + true + bin\x86\Debug\ + DEBUG;TRACE + full + x86 + 7.3 + prompt + true + + + bin\x86\Release\ + TRACE + true + pdbonly + x86 + 7.3 + prompt + true + + + + ..\MQ SDK\MQ监听代码\bin\MqDebug\Com.Neusoft.Nhip.MqProxy.dll + + + packages\log4net.3.1.0\lib\net462\log4net.dll + + + packages\Microsoft.Bcl.AsyncInterfaces.9.0.6\lib\net462\Microsoft.Bcl.AsyncInterfaces.dll + + + packages\Microsoft.Extensions.DependencyInjection.Abstractions.9.0.6\lib\net462\Microsoft.Extensions.DependencyInjection.Abstractions.dll + + + packages\Microsoft.Extensions.Logging.Abstractions.9.0.6\lib\net462\Microsoft.Extensions.Logging.Abstractions.dll + + + False + ..\MQ SDK\MySqlConnector.dll + + + packages\Newtonsoft.Json.13.0.4\lib\net45\Newtonsoft.Json.dll + + + + packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll + + + + + packages\System.Diagnostics.DiagnosticSource.9.0.6\lib\net462\System.Diagnostics.DiagnosticSource.dll + + + packages\System.Memory.4.5.5\lib\net461\System.Memory.dll + + + + packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll + + + packages\System.Runtime.CompilerServices.Unsafe.6.0.0\lib\net461\System.Runtime.CompilerServices.Unsafe.dll + + + packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll + + + + + + + + + + 4.0 + + + + + + + + MSBuild:Compile + Designer + + + + + TestCode.xaml + + + MSBuild:Compile + Designer + + + App.xaml + Code + + + + + + + + + + + + + + + MainWindow.xaml + Code + + + Designer + MSBuild:Compile + + + + + Code + + + True + True + Resources.resx + + + True + Settings.settings + True + + + ResXFileCodeGenerator + Resources.Designer.cs + + + Always + + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + + + + + + + + + + False + Microsoft .NET Framework 4.7.2 %28x86 和 x64%29 + true + + + False + .NET Framework 3.5 SP1 + false + + + + \ No newline at end of file diff --git a/MyHosListener/MyHosListener.sln b/MyHosListener/MyHosListener.sln new file mode 100755 index 0000000..51d6fdc --- /dev/null +++ b/MyHosListener/MyHosListener.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.14.36203.30 d17.14 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MyHosListener", "MyHosListener.csproj", "{E0024F00-0A93-4306-8B4A-431FEAF6D4E8}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Debug|x86 = Debug|x86 + Release|Any CPU = Release|Any CPU + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {E0024F00-0A93-4306-8B4A-431FEAF6D4E8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E0024F00-0A93-4306-8B4A-431FEAF6D4E8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E0024F00-0A93-4306-8B4A-431FEAF6D4E8}.Debug|x86.ActiveCfg = Debug|x86 + {E0024F00-0A93-4306-8B4A-431FEAF6D4E8}.Debug|x86.Build.0 = Debug|x86 + {E0024F00-0A93-4306-8B4A-431FEAF6D4E8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E0024F00-0A93-4306-8B4A-431FEAF6D4E8}.Release|Any CPU.Build.0 = Release|Any CPU + {E0024F00-0A93-4306-8B4A-431FEAF6D4E8}.Release|x86.ActiveCfg = Release|x86 + {E0024F00-0A93-4306-8B4A-431FEAF6D4E8}.Release|x86.Build.0 = Release|x86 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {A614A8E8-9B14-4801-8D74-AFBAAE2A9E9B} + EndGlobalSection +EndGlobal diff --git a/MyHosListener/Properties/AssemblyInfo.cs b/MyHosListener/Properties/AssemblyInfo.cs new file mode 100755 index 0000000..a60fc05 --- /dev/null +++ b/MyHosListener/Properties/AssemblyInfo.cs @@ -0,0 +1,52 @@ +using System.Reflection; +using System.Resources; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Windows; + +// 有关程序集的一般信息由以下 +// 控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("MyHosListener")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("MyHosListener")] +[assembly: AssemblyCopyright("Copyright © 2025")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 会使此程序集中的类型 +//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型 +//请将此类型的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +//若要开始生成可本地化的应用程序,请设置 +//.csproj 文件中的 CultureYouAreCodingWith +//在 中。例如,如果你使用的是美国英语。 +//使用的是美国英语,请将 设置为 en-US。 然后取消 +//对以下 NeutralResourceLanguage 特性的注释。 更新 +//以下行中的“en-US”以匹配项目文件中的 UICulture 设置。 + +//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)] + + +[assembly: ThemeInfo( + ResourceDictionaryLocation.None, //主题特定资源词典所处位置 + //(未在页面中找到资源时使用, + //或应用程序资源字典中找到时使用) + ResourceDictionaryLocation.SourceAssembly //常规资源词典所处位置 + //(未在页面中找到资源时使用, + //、应用程序或任何主题专用资源字典中找到时使用) +)] + + +// 程序集的版本信息由下列四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/MyHosListener/Properties/Resources.Designer.cs b/MyHosListener/Properties/Resources.Designer.cs new file mode 100755 index 0000000..13877bb --- /dev/null +++ b/MyHosListener/Properties/Resources.Designer.cs @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// 此代码由工具生成。 +// 运行时版本: 4.0.30319.42000 +// +// 对此文件的更改可能导致不正确的行为,如果 +// 重新生成代码,则所做更改将丢失。 +// +//------------------------------------------------------------------------------ + +namespace MyHosListener.Properties +{ + + + /// + /// 强类型资源类,用于查找本地化字符串等。 + /// + // 此类是由 StronglyTypedResourceBuilder + // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 + // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen + // (以 /str 作为命令选项),或重新生成 VS 项目。 + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources + { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() + { + } + + /// + /// 返回此类使用的缓存 ResourceManager 实例。 + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager + { + get + { + if ((resourceMan == null)) + { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("MyHosListener.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// 重写当前线程的 CurrentUICulture 属性,对 + /// 使用此强类型资源类的所有资源查找执行重写。 + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture + { + get + { + return resourceCulture; + } + set + { + resourceCulture = value; + } + } + } +} diff --git a/MyHosListener/Properties/Resources.resx b/MyHosListener/Properties/Resources.resx new file mode 100755 index 0000000..af7dbeb --- /dev/null +++ b/MyHosListener/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/MyHosListener/Properties/Settings.Designer.cs b/MyHosListener/Properties/Settings.Designer.cs new file mode 100755 index 0000000..893816c --- /dev/null +++ b/MyHosListener/Properties/Settings.Designer.cs @@ -0,0 +1,30 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace MyHosListener.Properties +{ + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase + { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default + { + get + { + return defaultInstance; + } + } + } +} diff --git a/MyHosListener/Properties/Settings.settings b/MyHosListener/Properties/Settings.settings new file mode 100755 index 0000000..033d7a5 --- /dev/null +++ b/MyHosListener/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/MyHosListener/TestCode.xaml b/MyHosListener/TestCode.xaml new file mode 100755 index 0000000..fcea0e1 --- /dev/null +++ b/MyHosListener/TestCode.xaml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + diff --git a/MyHosListener/TestCode.xaml.cs b/MyHosListener/TestCode.xaml.cs new file mode 100755 index 0000000..4a8e718 --- /dev/null +++ b/MyHosListener/TestCode.xaml.cs @@ -0,0 +1,480 @@ +using MyHosListener.common; +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Shapes; +using System.Xml.Linq; + +namespace MyHosListener +{ + /// + /// TestCode.xaml 的交互逻辑 + /// + public partial class TestCode : Window + { + public TestCode() + { + InitializeComponent(); + } + + private void bt_test_Click(object sender, RoutedEventArgs e) + { + string testStr = "\r\n\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n"; + ParseMessage(testStr); + } + + private async void ParseMessage(string message) + { + try + { + XDocument xdoc = XDocument.Parse(message); + // 获取默认命名空间 + XNamespace ns = "urn:hl7-org:v3"; + + // 消息ID + var messageId = xdoc.Descendants(ns + "id") + .FirstOrDefault() // 括号内可以加判定条件 + ?.Attribute("extension")?.Value; + + // 1️ 获取 item[@root='2.16.156.10011.2.5.1.4'] + var cardNo = xdoc + .Descendants(ns + "item") + .FirstOrDefault(x => (string)x.Attribute("root") == "2.16.156.10011.2.5.1.4") + ?.Attribute("extension")?.Value; + + // 2️ 获取 patientPerson/name/item/part 的 value + var patientName = xdoc + .Descendants(ns + "patient") + .Descendants(ns + "patientPerson") + .Descendants(ns + "name") + .Descendants(ns + "item") + .Descendants(ns + "part") + .FirstOrDefault() + ?.Attribute("value")?.Value; + + // 3️ 获取 administrativeGenderCode/displayName 的 value + var patientGenderName = xdoc + .Descendants(ns + "administrativeGenderCode") + .Descendants(ns + "displayName") + .FirstOrDefault() + ?.Attribute("value")?.Value; + + // 4.循环component2获取termCode + var termCodes = xdoc + .Descendants(ns + "controlActProcess") + .Descendants(ns + "subject") + .Descendants(ns + "observationRequest") + .Descendants(ns + "component2") + .Select(component => + component + .Descendants(ns + "observationRequest") + .Descendants(ns + "code") + .FirstOrDefault() + ) + .Where(item => item != null) + .Select(item => (string)item.Attribute("code")) + .ToList(); + + // 循环获取的termCode + foreach (var termCode in termCodes) + { + + } + + // 5 获取 controlActProcess/subject/observationRequest/component2/observationRequest/code/displayName + // 循环component2获取termNames + var termNames = xdoc + .Descendants(ns + "controlActProcess") + .Descendants(ns + "subject") + .Descendants(ns + "observationRequest") + .Descendants(ns + "component2") + .Select(component => + component + .Descendants(ns + "observationRequest") + .Descendants(ns + "code") + .Descendants(ns + "displayName") + .FirstOrDefault() + ) + .Where(item => item != null) + .Select(item => (string)item.Attribute("value")) + .ToList(); + + // 循环获取的termName + foreach (var termName in termNames) + { + + } + + // 6 获取 code[@codeSystem='2.16.156.10011.0.9.2.3.2.95']/displayName + var chargeStatusName = xdoc + .Descendants(ns + "code") + .FirstOrDefault(x => (string)x.Attribute("codeSystem") == "2.16.156.10011.0.9.2.3.2.95") + .Descendants(ns + "displayName") + .FirstOrDefault() + ?.Attribute("value")?.Value; + + // 7 获取 representedOrganization/name/item/part + var orderDeptName = xdoc + .Descendants(ns + "representedOrganization") + .Descendants(ns + "name") + .Descendants(ns + "item") + .Descendants(ns + "part") + .FirstOrDefault() + ?.Attribute("value")?.Value; + + // 8 获取 observationRequest/author/time + var requestDate = xdoc + .Descendants(ns + "controlActProcess") + .Descendants(ns + "subject") + .Descendants(ns + "observationRequest") + .Descendants(ns + "author") + .Descendants(ns + "time") + .FirstOrDefault() + ?.Attribute("value")?.Value; + + // 9 获取 componentOf1/encounter/subject/patient/patientPerson/birthTime + var patientBirthDate = xdoc + .Descendants(ns + "patientPerson") + .Descendants(ns + "birthTime") + .FirstOrDefault() + ?.Attribute("value")?.Value; + + // 10 获取 controlActProcess/subject/observationRequest/author/assignedEntity/assignedPerson/name/item/part + var orderPersonName = xdoc + .Descendants(ns + "controlActProcess") + .Descendants(ns + "subject") + .Descendants(ns + "observationRequest") + .Descendants(ns + "author") + .Descendants(ns + "assignedEntity") + .Descendants(ns + "assignedPerson") + .Descendants(ns + "name") + .Descendants(ns + "item") + .Descendants(ns + "part") + .FirstOrDefault() + ?.Attribute("value")?.Value; + + // 11 获取 componentOf1/encounter/code[code] + var visitTypeCode = xdoc + .Descendants(ns + "componentOf1") + .Descendants(ns + "encounter") + .Descendants(ns + "code") + .FirstOrDefault() + ?.Attribute("code")?.Value; + + // 12 获取 patientPerson/telecom/item + var mobile = xdoc + .Descendants(ns + "patientPerson") + .Descendants(ns + "telecom") + .Descendants(ns + "item") + .FirstOrDefault() + ?.Attribute("value")?.Value; + + // controlActProcess/subject/observationRequest/ + // component2/observationRequest/ + // location/serviceDeliveryLocation/serviceProviderOrganization/name/item/part + // 13 循环获取 serviceProviderOrganization/name/item/part + //var execDeptName1 = xdoc + // .Descendants(ns + "item") + // .FirstOrDefault(x => (string)x.Attribute("root") == "2.16.156.10011.1.28") + // ?.Ancestors(ns + "observationRequest") + // .Descendants(ns + "location") + // .Descendants(ns + "serviceDeliveryLocation") + // .Descendants(ns + "serviceProviderOrganization") + // .Descendants(ns + "name") + // .Descendants(ns + "item") + // .Descendants(ns + "part") + // .FirstOrDefault() + // ?.Attribute("value")?.Value; + var execDeptNames = xdoc + .Descendants(ns + "controlActProcess") + .Descendants(ns + "subject") + .Descendants(ns + "observationRequest") + .Descendants(ns + "component2") + .Select(component => + component + .Descendants(ns + "observationRequest") + .Descendants(ns + "location") + .Descendants(ns + "serviceDeliveryLocation") + .Descendants(ns + "serviceProviderOrganization") + .Descendants(ns + "name") + .Descendants(ns + "item") + .Descendants(ns + "part") + .FirstOrDefault() + ) + .Where(item => item != null) + .Select(item => (string)item.Attribute("value")) + .ToList(); + + // 循环获取的 execDeptName + foreach (var execDeptName in execDeptNames) + { + + } + + // 14 循环component2/observationRequest/id/item[@root='2.16.156.10011.1.28'] + //var orderNo = xdoc + // .Descendants(ns + "item") + // .FirstOrDefault(x => (string)x.Attribute("root") == "2.16.156.10011.1.28") + // ?.Attribute("extension")?.Value; + var orderNos = xdoc + .Descendants(ns + "controlActProcess") + .Descendants(ns + "subject") + .Descendants(ns + "observationRequest") + .Descendants(ns + "component2") + .Select(component => + component + .Descendants(ns + "item") + .FirstOrDefault(x => (string)x.Attribute("root") == "2.16.156.10011.1.28") + ) + .Where(item => item != null) + .Select(item => (string)item.Attribute("extension")) + .ToList(); + + // 循环获取的orderNo + foreach (var orderNo in orderNos) + { + + } + + // 15 获取 item[@root='2.16.156.10011.2.5.1.9'] + var visitSqNo = xdoc + .Descendants(ns + "item") + .FirstOrDefault(x => (string)x.Attribute("root") == "2.16.156.10011.2.5.1.9") + ?.Attribute("extension")?.Value; + + // 16 获取 serviceDeliveryLocation/serviceProviderOrganization/id/item + // controlActProcess/subject/observationRequest/component2/ + // observationRequest/location/serviceDeliveryLocation/serviceProviderOrganization/id/item + //var execDeptCode = xdoc + // .Descendants(ns + "item") + // .FirstOrDefault(x => (string)x.Attribute("root") == "2.16.156.10011.1.26") + // ?.Attribute("extension")?.Value; + var execDeptCodes = xdoc + .Descendants(ns + "controlActProcess") + .Descendants(ns + "subject") + .Descendants(ns + "observationRequest") + .Descendants(ns + "component2") + .Select(component => + component + .Descendants(ns + "observationRequest") + .Descendants(ns + "location") + .Descendants(ns + "serviceDeliveryLocation") + .Descendants(ns + "serviceProviderOrganization") + .Descendants(ns + "id") + .Descendants(ns + "item") + .FirstOrDefault() + ) + .Where(item => item != null) + .Select(item => (string)item.Attribute("extension")) + .ToList(); + + // 循环获取的execDeptCode + foreach (var execDeptCode in execDeptCodes) + { + + } + + // 17 获取 item[@root='2.16.156.10011.0.9.1.64']../../name/item/part + var areaName = xdoc + .Descendants(ns + "item") + .FirstOrDefault(x => (string)x.Attribute("root") == "2.16.156.10011.0.9.1.64") + ?.Ancestors(ns + "location") + .Descendants(ns + "name") + .Descendants(ns + "item") + .Descendants(ns + "part") + .FirstOrDefault() + ?.Attribute("value")?.Value; + + // 18 获取 asOrganizationPartOf/wholeOrganization/id/item + var areaCode = xdoc + .Descendants(ns + "wholeOrganization") + .Descendants(ns + "id") + .Descendants(ns + "item") + .FirstOrDefault() + ?.Attribute("extension")?.Value; + + // 19 获取 serviceDeliveryLocation/location/name/item/part + var bedName = xdoc + .Descendants(ns + "item") + .FirstOrDefault(x => (string)x.Attribute("root") == "2.16.156.10011.1.22") + ?.Ancestors(ns + "location") + .Descendants(ns + "name") + .Descendants(ns + "item") + .Descendants(ns + "part") + .FirstOrDefault() + ?.Attribute("value")?.Value; + + // 20 获取 serviceDeliveryLocation/location/id/item + var bedNo = xdoc + .Descendants(ns + "item") + .FirstOrDefault(x => (string)x.Attribute("root") == "2.16.156.10011.1.22") + ?.Attribute("extension")?.Value; + + // 21 获取 subject/observationRequest/id/item + var requestNo = xdoc + .Descendants(ns + "item") + .FirstOrDefault(x => (string)x.Attribute("root") == "2.16.156.10011.1.24") + ?.Attribute("extension")?.Value; + //22 获取身份证 + var idCardNumber = xdoc + .Descendants(ns + "item") + .FirstOrDefault(x => (string)x.Attribute("root") == "2.16.156.10011.1.3") + ?.Attribute("extension")?.Value; + + DBtools db = new DBtools(); + Dictionary dc = new Dictionary(); + // 循环获取的orderNo,分别入库 + for (int i = 0; i < orderNos.Count; i++) + { + dc.Clear(); + dc.Add("entrust_id", orderNos[i]); + //查询库里是否存在该检医嘱 + string sql_exits = "select id from s_list where entrust_id = @entrust_id"; + if (db.ExecQuery(sql_exits, dc).Rows.Count == 0) + { + //不存在则执行插入操作 + DateTime dateTime; + bool success = DateTime.TryParseExact( + requestDate, + "yyyyMMddHHmmss", + CultureInfo.InvariantCulture, + DateTimeStyles.None, + out dateTime); + var entrust_datePart = ""; + var entrust_timePart = ""; + if (success) + { + // 提取格式化后的日期和时间 + entrust_datePart = dateTime.ToString("yyyy-MM-dd"); + entrust_timePart = dateTime.ToString("HH:mm:ss"); + } + //生日 + DateTime birthdayDate; + bool birthdaySuccess = DateTime.TryParseExact( + patientBirthDate, + "yyyyMMdd", + CultureInfo.InvariantCulture, + DateTimeStyles.None, + out birthdayDate); + var birthday = ""; + if (success) + { + birthday = birthdayDate.ToString("yyyy-MM-dd"); + } + //患者类型 + Dictionary mapping = new Dictionary + { + { "03", 0 }, // 住院 + { "01", 1 }, // 门诊 + { "02", 2 }, // 急诊 + { "04", 3 } // 体检 + }; + int patientType = mapping.TryGetValue(visitTypeCode, out int value) ? value : 9; + string insertSql = @" + INSERT INTO s_list ( + list_status, + reg_num, + user_name, + user_sex, + entrust_code, + entrust, + is_pay, + reservation_department, + entrust_date, + entrust_time, + user_brithday, + docotr, + patient_type, + user_phone, + implement_department, + entrust_id, + episodeid, + RISRAcceptDeptCode, + warddesc, + wardcode, + bedname, + bedno, + app_num, + idCardNumber + ) VALUES ( + @list_status, + @reg_num, + @user_name, + @user_sex, + @entrust_code, + @entrust, + @is_pay, + @reservation_department, + @entrust_date, + @entrust_time, + @user_brithday, + @docotr, + @patient_type, + @user_phone, + @implement_department, + @entrust_id, + @episodeid, + @RISRAcceptDeptCode, + @warddesc, + @wardcode, + @bedname, + @bedno, + @app_num, + @idCardNumber + )"; + dc.Clear(); + dc.Add("list_status", 0); // int + dc.Add("reg_num", cardNo); + dc.Add("user_name", patientName); + dc.Add("user_sex", patientGenderName == "男" ? 1 : 2); // int + dc.Add("entrust_code", termCodes[i]); + dc.Add("entrust", termNames[i]); + dc.Add("is_pay", chargeStatusName == "已收费" ? 1 : 0); // int + dc.Add("reservation_department", orderDeptName); + dc.Add("entrust_date", entrust_datePart); + dc.Add("entrust_time", entrust_timePart); + dc.Add("user_brithday", birthday); + dc.Add("docotr", orderPersonName); + dc.Add("patient_type", patientType); + dc.Add("user_phone", mobile); + dc.Add("implement_department", execDeptNames[i]); + dc.Add("entrust_id", orderNos[i]); + dc.Add("episodeid", visitSqNo); + dc.Add("RISRAcceptDeptCode", execDeptCodes[i]); + dc.Add("warddesc", areaName); + dc.Add("wardcode", areaCode); + dc.Add("bedname", bedName); + dc.Add("bedno", bedNo); + dc.Add("app_num", requestNo); + dc.Add("idCardNumber", idCardNumber); + int ins = db.ExecSQL(insertSql, dc); + if (ins > 0) + { + // 执行成功了,可以做其他业务处理 + MyLog.Info($"0047消息已入库成功,orderNo:{orderNos[i]}"); + await Tools.NoticeEntrustChange(orderNos[i]); + } + else + { + MyLog.Info($"0047消息入库失败:{ins},orderNo:{orderNos[i]}"); + } + } + } + } + catch (Exception e) + { + MyLog.Info("解析[CI0047]消息异常 : " + e.Message); + } + } + } +} diff --git a/MyHosListener/common/DBTools.cs b/MyHosListener/common/DBTools.cs new file mode 100755 index 0000000..bbc65ad --- /dev/null +++ b/MyHosListener/common/DBTools.cs @@ -0,0 +1,299 @@ +using MyHosListener; +using MySqlConnector; +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Data; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MyHosListener.common +{ + public class DBtools + { + + private readonly string ConnString = ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString; + private readonly string LogConnStr = ConfigurationManager.ConnectionStrings["LogConnStr"].ConnectionString; + + /// + /// 0-9,a-z,A-Z生成指定位数的随机数,没有I和i + /// + /// 长度 + /// + public string GetRandomStr(int len) + { + const string chars = "0123456789"; + var random = new Random(); + var result = new StringBuilder(len); + + for (int i = 0; i < len; i++) + { + result.Append(chars[random.Next(chars.Length)]); + } + return result.ToString(); + } + + + /// + /// 执行SQL语句 + /// + /// SQL语句 + /// SQL语句所带的参数 + /// + /// 受影响的行数 + public int ExecSQL(string sql, MySqlParameter[] parameters) + { + using (var connection = new MySqlConnection(ConnString)) + { + connection.Open(); + using (MySqlCommand command = new MySqlCommand()) + { + command.Connection = connection; + command.CommandText = sql; + command.Parameters.AddRange(parameters); + int result = command.ExecuteNonQuery(); + command.Parameters.Clear(); + connection.Close(); + return result; + } + } + } + + /// + ///记录日志 + /// + /// + /// + /// + public int ExecSQLLog(string sql, MySqlParameter[] parameters) + { + using (var connection = new MySqlConnection(LogConnStr)) + { + connection.Open(); + using (MySqlCommand command = new MySqlCommand()) + { + command.Connection = connection; + command.CommandText = sql; + command.Parameters.AddRange(parameters); + int result = command.ExecuteNonQuery(); + command.Parameters.Clear(); + connection.Close(); + return result; + } + } + } + + + /// + /// 执行SQL语句 + /// + /// SQL语句 + /// SQL语句所带的参数 + /// + /// 受影响的行数 + public int ExecSQL(string sql, Dictionary dc) + { + using (var connection = new MySqlConnection(ConnString)) + { + connection.Open(); + using (MySqlCommand command = new MySqlCommand()) + { + command.Connection = connection; + command.CommandText = sql; + command.Parameters.AddRange(sqlparameter_append(dc)); + int result = command.ExecuteNonQuery(); + command.Parameters.Clear(); + connection.Close(); + return result; + } + } + } + + public int ExecSQL(string sql, Dictionary dc) + { + using (var connection = new MySqlConnection(ConnString)) + { + connection.Open(); + using (MySqlCommand command = new MySqlCommand()) + { + command.Connection = connection; + command.CommandText = sql; + command.Parameters.AddRange(sqlparameter_append(dc)); + int result = command.ExecuteNonQuery(); + command.Parameters.Clear(); + connection.Close(); + return result; + } + } + } + + /// + /// 执行SQL语句 + /// + /// SQL语句 + /// 受影响的行数 + public int ExecSQL(string sql) + { + return ExecSQL(sql, new MySqlParameter[0]); + } + + /// + /// 记录日志 + /// + /// + /// + public int Log(string logtext) + { + string sql = "INSERT INTO log(log) VALUES (@log)"; + using (var connection = new MySqlConnection(LogConnStr)) + { + connection.Open(); + using (MySqlCommand command = new MySqlCommand()) + { + MySqlParameter mySqlParameter = new MySqlParameter(); + mySqlParameter.ParameterName = "@log"; + mySqlParameter.Value = logtext; + command.Connection = connection; + command.CommandText = sql; + command.Parameters.Add(mySqlParameter); + int result = command.ExecuteNonQuery(); + command.Parameters.Clear(); + connection.Close(); + return result; + } + } + } + + /// + /// 执行查询 + /// + /// 查询语句 + /// 查询结果表 + public DataTable ExecQuery(string sql) + { + using (MySqlConnection connection = new MySqlConnection(ConnString)) + { + connection.Open(); + using (MySqlCommand command = new MySqlCommand()) + { + command.Connection = connection; + command.CommandText = sql; + using (DataTable dt = new DataTable()) + { + using (MySqlDataAdapter adapter = new MySqlDataAdapter()) + { + adapter.SelectCommand = command; + adapter.Fill(dt); + command.Parameters.Clear(); + connection.Close(); + return dt; + } + } + } + } + + } + + + // + /// 执行查询 + /// + /// 查询语句 + /// 查询结果表 + public DataTable ExecQuery(string sql, MySqlParameter[] parameters) + { + using (MySqlConnection connection = new MySqlConnection(ConnString)) + { + connection.Open(); + using (MySqlCommand command = new MySqlCommand()) + { + command.Connection = connection; + command.CommandText = sql; + using (DataTable dt = new DataTable()) + { + using (MySqlDataAdapter adapter = new MySqlDataAdapter()) + { + adapter.SelectCommand = command; + command.Parameters.AddRange(parameters); + adapter.Fill(dt); + command.Parameters.Clear(); + connection.Close(); + return dt; + } + } + } + } + } + + /// + ///执行sql语句返回databable + /// + /// sql语句 + /// 参数 + /// datatable + public DataTable ExecQuery(string sql, Dictionary dc) + { + + return ExecQuery(sql, sqlparameter_append(dc)); + } + + /// + ///执行sql语句返回databable + /// + /// sql语句 + /// 参数 + /// datatable + public DataTable ExecQuery(string sql, Dictionary dc) + { + + return ExecQuery(sql, sqlparameter_append(dc)); + } + + + + /// + /// 根据Dictionary生成sqlparameter数组 + /// + /// Dictionary + /// sqlparameter数组 + public MySqlParameter[] sqlparameter_append(Dictionary dc) + { + int count = dc.Count; + MySqlParameter[] paralist; + if (count == 0) + paralist = new MySqlParameter[0]; + else + { + paralist = new MySqlParameter[dc.Count]; + int i = 0; + foreach (KeyValuePair kvp in dc) + { + paralist[i] = new MySqlParameter("@" + kvp.Key, kvp.Value); + i++; + } + } + return paralist; + } + + public MySqlParameter[] sqlparameter_append(Dictionary dc) + { + int count = dc.Count; + MySqlParameter[] paralist; + if (count == 0) + paralist = new MySqlParameter[0]; + else + { + paralist = new MySqlParameter[dc.Count]; + int i = 0; + foreach (KeyValuePair kvp in dc) + { + paralist[i] = new MySqlParameter("@" + kvp.Key, kvp.Value); + i++; + } + } + return paralist; + } + + } +} diff --git a/MyHosListener/common/MyLog.cs b/MyHosListener/common/MyLog.cs new file mode 100755 index 0000000..8b220dc --- /dev/null +++ b/MyHosListener/common/MyLog.cs @@ -0,0 +1,18 @@ +using log4net.Util; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MyHosListener.common +{ + public class MyLog + { + private static readonly log4net.ILog log = log4net.LogManager.GetLogger(typeof(MyLog)); + public static void Info(string logStr) + { + log.Info(logStr); + } + } +} diff --git a/MyHosListener/common/Tools.cs b/MyHosListener/common/Tools.cs new file mode 100755 index 0000000..45e7022 --- /dev/null +++ b/MyHosListener/common/Tools.cs @@ -0,0 +1,144 @@ +using System; +using System.Net.Http; +using System.Text; +using System.Threading.Tasks; +using Newtonsoft.Json; + +namespace MyHosListener.common +{ + public class Tools + { + private static System.Timers.Timer _timerNoPay; + private static readonly HttpClient client = new HttpClient(); + + /// + /// 通知医技取消 + /// + public static async Task NoticeEntrustChange(string orderNo) + { + try + { + string url = $"http://192.168.80.76/api/PacsCancelApplyInfo?orderNo={orderNo}"; + var response = await client.GetAsync(url); + response.EnsureSuccessStatusCode(); + + string responseBody = await response.Content.ReadAsStringAsync(); + MyLog.Info(responseBody); + } + catch (Exception e) + { + MyLog.Info($"请求错误 (NoticeEntrustChange): {e.Message}"); + } + } + + /// + /// 未支付自动取消(每5分钟) + /// + private static async void NoPayCancel(object sender, System.Timers.ElapsedEventArgs e) + { + try + { + string url = "http://192.168.80.76/api/admin/NoPayCancel"; + + var response = await client.GetAsync(url); + response.EnsureSuccessStatusCode(); + + string responseBody = await response.Content.ReadAsStringAsync(); + MyLog.Info("[NoPayCancel] " + responseBody); + } + catch (Exception ex) + { + MyLog.Info($"请求错误 (NoPayCancel): {ex.Message}"); + } + } + + /// + /// 夜间任务核心逻辑(每天22点执行) + /// + private static async Task NightlyTaskCore() + { + MyLog.Info(">>> 夜间任务执行:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); + + DateTime targetDate = DateTime.Now.AddDays(15); + string dateStr = targetDate.ToString("yyyy-MM-dd"); + + var postData = new + { + dateRange = new[] { dateStr, dateStr }, + HolidayEnable = 1 + }; + + string jsonContent = JsonConvert.SerializeObject(postData); + var content = new StringContent(jsonContent, Encoding.UTF8, "application/json"); + + string url = "http://192.168.80.76/api/BatchGenerateByDateRange"; + + var response = await client.PostAsync(url, content); + response.EnsureSuccessStatusCode(); + + string responseBody = await response.Content.ReadAsStringAsync(); + + MyLog.Info("<<< 夜间任务成功:" + responseBody); + } + + /// + /// 启动所有定时任务 + /// + public static void StartRound() + { + MyLog.Info("正在初始化定时任务模块..."); + + // ===== 5分钟任务 ===== + if (_timerNoPay == null) + { + _timerNoPay = new System.Timers.Timer(300000); // 5分钟 + _timerNoPay.Elapsed += NoPayCancel; + _timerNoPay.AutoReset = true; + _timerNoPay.Start(); + + MyLog.Info("[OK] 定时任务 [NoPayCancel] 已启动 (每5分钟)"); + } + + // ===== 每天22点任务 ===== + Task.Run(async () => + { + MyLog.Info("[Nightly] 每日22点任务已启动"); + + while (true) + { + try + { + DateTime now = DateTime.Now; + + // 今天22点 + DateTime today22 = new DateTime( + now.Year, now.Month, now.Day, 22, 0, 0 + ); + + // 如果已经过了22点,就安排到明天 + DateTime nextRun = now > today22 ? today22.AddDays(1) : today22; + + TimeSpan delay = nextRun - now; + + MyLog.Info($"[Nightly] 下次执行时间: {nextRun:yyyy-MM-dd HH:mm:ss}"); + + // 等待到指定时间 + await Task.Delay(delay); + + // 执行任务 + await NightlyTaskCore(); + } + catch (Exception ex) + { + MyLog.Info("夜间任务异常:" + ex.Message); + + // 出错后延迟1分钟再重试 + await Task.Delay(TimeSpan.FromMinutes(1)); + } + } + }); + + MyLog.Info("所有定时任务初始化完成。"); + } + } +} \ No newline at end of file diff --git a/MyHosListener/common/listener/BaseListener.cs b/MyHosListener/common/listener/BaseListener.cs new file mode 100755 index 0000000..d77b17a --- /dev/null +++ b/MyHosListener/common/listener/BaseListener.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Web.UI.WebControls; +using System.Xml; +using System.Xml.Linq; + +namespace MyHosListener.common.listener +{ + public class BaseListener + { + public MainWindow caller; + private string FormattedXml(string xmlString) + { + try + { + XDocument xdoc = XDocument.Parse(xmlString); + StringBuilder sb = new StringBuilder(); + using (StringWriter stringWriter = new StringWriter(sb)) + using (XmlWriter xmlWriter = XmlWriter.Create(stringWriter, new XmlWriterSettings + { + Indent = true, // 设置缩进 + IndentChars = " ", // 设置缩进字符 + NewLineChars = "\r\n", // 设置换行字符 + NewLineHandling = NewLineHandling.Replace, // 替换换行符 + Encoding = Encoding.UTF8 // 设置编码 + })) + { + xdoc.WriteTo(xmlWriter); + } + return sb.ToString(); + } + catch (Exception ex) + { + return "xml消息格式化错误:" + ex.Message; + } + } + + public void Save2Log(string tag, string message) + { + string finalStr = FormattedXml(message); + MyLog.Info(tag + "消息:" + Environment.NewLine + finalStr); + System.Threading.Thread.Sleep(100); + if (caller != null) + { + caller.AppendMessage(tag + "消息↓:" + Environment.NewLine + finalStr); + } + } + } +} diff --git a/MyHosListener/common/listener/CD0050Listener.cs b/MyHosListener/common/listener/CD0050Listener.cs new file mode 100755 index 0000000..1efd90c --- /dev/null +++ b/MyHosListener/common/listener/CD0050Listener.cs @@ -0,0 +1,118 @@ +using MyHosListener; +using System; +using System.Collections.Generic; +using System.Data; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace MyHosListener.common.listener +{ + public class CD0050Listener : BaseListener + { + + public CD0050Listener(MainWindow caller) + { + this.caller = caller; + } + + public void OnMessage(string message) + { + Save2Log("[CD0050]", message); + // 解析数据 + ParseMessage(message); + } + + private async void ParseMessage(string message) + { + try + { + XDocument xdoc = XDocument.Parse(message); + // 获取默认命名空间 + XNamespace ns = "urn:hl7-org:v3"; + + // 消息ID + var messageId = xdoc.Descendants(ns + "id") + .FirstOrDefault() // 括号内可以加判定条件 + ?.Attribute("extension")?.Value; + + var visitSqNo = xdoc + .Descendants(ns + "componentOf1") + .Descendants(ns + "encounter") + .Descendants(ns + "id") + .Descendants(ns + "item") + .FirstOrDefault() + ?.Attribute("extension")?.Value; + + var orderNo = xdoc + .Descendants(ns + "observationRequest") + .Descendants(ns + "id") + .Descendants(ns + "item") + .FirstOrDefault() + ?.Attribute("extension")?.Value; + + DBtools db = new DBtools(); + Dictionary dc = new Dictionary(); + string sql_exits = "select id from s_list where entrust_id = @entrust_id and is_del=0 and is_nullify=0"; + dc.Add("entrust_id", orderNo); + DataTable result = db.ExecQuery(sql_exits, dc); + if (result.Rows.Count == 1) + { + // 存在,执行更新操作 is_nullify = 1 + string id = result.Rows[0]["id"].ToString(); // 获取要更新的记录ID + + string sql_update = "UPDATE s_list SET is_nullify = 1 WHERE id = @id"; + Dictionary updateParams = new Dictionary(); + updateParams.Add("id", id); + + int rowsAffected = db.ExecSQL(sql_update, updateParams); + if (rowsAffected > 0) + { + MyLog.Info($"Mq050,医嘱已更新 is_nullify=1, OrderNO: {orderNo}"); + await Tools.NoticeEntrustChange(orderNo); + } + else + { + MyLog.Info($"Mq050,医嘱更新失败, OrderNO: {orderNo}"); + } + } + else + { + MyLog.Info($"Mq050,医嘱不存在,OrderNO:{orderNo}"); + } + + + // 将解析出来的数据入库 + //DBtools db = new DBtools(); + //Dictionary dc = new Dictionary(); + //// 自己构造SQL语句即可 + //string sql_exits = "select id from user_info where user_num = @user_num and user_card_num=@user_card_num"; + //dc.Add("user_num", "1111"); + //dc.Add("user_card_num", "12345"); + //if (db.ExecQuery(sql_exits, dc).Rows.Count == 1) + //{ + // // 执行成功了,可以做其他业务处理 + // return; + //} + + //string sql_insert = @"INSERT INTO user_info(hosid, user_name, user_sex, addtime, unbind) VALUES (@hosid, @user_name, @user_sex, @addtime, @unbind)"; + //dc.Clear(); + //dc.Add("hosid", 1); + //dc.Add("user_name", "testname"); + //dc.Add("user_sex", 1); + //dc.Add("addtime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); + //dc.Add("unbind", false); + //if (db.ExecSQL(sql_insert, dc) == 0) + //{ + // // 执行成功了,可以做其他业务处理 + // MyLog.Info("[CD0050]消息已入库成功--消息ID" + messageId); + //} + } + catch (Exception e) + { + MyLog.Info("解析[CD0050]消息异常 : " + e.Message); + } + } + } +} diff --git a/MyHosListener/common/listener/CI0047Listener.cs b/MyHosListener/common/listener/CI0047Listener.cs new file mode 100755 index 0000000..629f11c --- /dev/null +++ b/MyHosListener/common/listener/CI0047Listener.cs @@ -0,0 +1,480 @@ +using MyHosListener; +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Xml.Linq; + +namespace MyHosListener.common.listener +{ + public class CI0047Listener : BaseListener + { + public CI0047Listener(MainWindow caller) + { + this.caller = caller; + } + + public void OnMessage(string message) + { + Save2Log("[CI0047]", message); + ParseMessage(message); + } + + /// + /// 解析数据 + /// + /// + private void ParseMessage(string message) + { + try + { + XDocument xdoc = XDocument.Parse(message); + // 获取默认命名空间 + XNamespace ns = "urn:hl7-org:v3"; + + // 消息ID + var messageId = xdoc.Descendants(ns + "id") + .FirstOrDefault() // 括号内可以加判定条件 + ?.Attribute("extension")?.Value; + + // 1️ 获取 item[@root='2.16.156.10011.2.5.1.4'] + var cardNo = xdoc + .Descendants(ns + "item") + .FirstOrDefault(x => (string)x.Attribute("root") == "2.16.156.10011.2.5.1.4") + ?.Attribute("extension")?.Value; + + // 2️ 获取 patientPerson/name/item/part 的 value + var patientName = xdoc + .Descendants(ns + "patient") + .Descendants(ns + "patientPerson") + .Descendants(ns + "name") + .Descendants(ns + "item") + .Descendants(ns + "part") + .FirstOrDefault() + ?.Attribute("value")?.Value; + + // 3️ 获取 administrativeGenderCode/displayName 的 value + var patientGenderName = xdoc + .Descendants(ns + "administrativeGenderCode") + .Descendants(ns + "displayName") + .FirstOrDefault() + ?.Attribute("value")?.Value; + + // 4.循环component2获取termCode + var termCodes = xdoc + .Descendants(ns + "controlActProcess") + .Descendants(ns + "subject") + .Descendants(ns + "observationRequest") + .Descendants(ns + "component2") + .Select(component => + component + .Descendants(ns + "observationRequest") + .Descendants(ns + "code") + .FirstOrDefault() + ) + .Where(item => item != null) + .Select(item => (string)item.Attribute("code")) + .ToList(); + + // 循环获取的termCode + foreach (var termCode in termCodes) + { + + } + + // 5 获取 controlActProcess/subject/observationRequest/component2/observationRequest/code/displayName + // 循环component2获取termNames + var termNames = xdoc + .Descendants(ns + "controlActProcess") + .Descendants(ns + "subject") + .Descendants(ns + "observationRequest") + .Descendants(ns + "component2") + .Select(component => + component + .Descendants(ns + "observationRequest") + .Descendants(ns + "code") + .Descendants(ns + "displayName") + .FirstOrDefault() + ) + .Where(item => item != null) + .Select(item => (string)item.Attribute("value")) + .ToList(); + + // 循环获取的termName + foreach (var termName in termNames) + { + + } + + // 6 获取 code[@codeSystem='2.16.156.10011.0.9.2.3.2.95']/displayName + var chargeStatusName = xdoc + .Descendants(ns + "code") + .FirstOrDefault(x => (string)x.Attribute("codeSystem") == "2.16.156.10011.0.9.2.3.2.95") + .Descendants(ns + "displayName") + .FirstOrDefault() + ?.Attribute("value")?.Value; + + // 7 获取 representedOrganization/name/item/part + var orderDeptName = xdoc + .Descendants(ns + "representedOrganization") + .Descendants(ns + "name") + .Descendants(ns + "item") + .Descendants(ns + "part") + .FirstOrDefault() + ?.Attribute("value")?.Value; + + // 8 获取 observationRequest/author/time + var requestDate = xdoc + .Descendants(ns + "controlActProcess") + .Descendants(ns + "subject") + .Descendants(ns + "observationRequest") + .Descendants(ns + "author") + .Descendants(ns + "time") + .FirstOrDefault() + ?.Attribute("value")?.Value; + + // 9 获取 componentOf1/encounter/subject/patient/patientPerson/birthTime + var patientBirthDate = xdoc + .Descendants(ns + "patientPerson") + .Descendants(ns + "birthTime") + .FirstOrDefault() + ?.Attribute("value")?.Value; + + // 10 获取 controlActProcess/subject/observationRequest/author/assignedEntity/assignedPerson/name/item/part + var orderPersonName = xdoc + .Descendants(ns + "controlActProcess") + .Descendants(ns + "subject") + .Descendants(ns + "observationRequest") + .Descendants(ns + "author") + .Descendants(ns + "assignedEntity") + .Descendants(ns + "assignedPerson") + .Descendants(ns + "name") + .Descendants(ns + "item") + .Descendants(ns + "part") + .FirstOrDefault() + ?.Attribute("value")?.Value; + + // 11 获取 componentOf1/encounter/code[code] + var visitTypeCode = xdoc + .Descendants(ns + "componentOf1") + .Descendants(ns + "encounter") + .Descendants(ns + "code") + .FirstOrDefault() + ?.Attribute("code")?.Value; + + // 12 获取 patientPerson/telecom/item + var mobile = xdoc + .Descendants(ns + "patientPerson") + .Descendants(ns + "telecom") + .Descendants(ns + "item") + .FirstOrDefault() + ?.Attribute("value")?.Value; + + // controlActProcess/subject/observationRequest/ + // component2/observationRequest/ + // location/serviceDeliveryLocation/serviceProviderOrganization/name/item/part + // 13 循环获取 serviceProviderOrganization/name/item/part + //var execDeptName1 = xdoc + // .Descendants(ns + "item") + // .FirstOrDefault(x => (string)x.Attribute("root") == "2.16.156.10011.1.28") + // ?.Ancestors(ns + "observationRequest") + // .Descendants(ns + "location") + // .Descendants(ns + "serviceDeliveryLocation") + // .Descendants(ns + "serviceProviderOrganization") + // .Descendants(ns + "name") + // .Descendants(ns + "item") + // .Descendants(ns + "part") + // .FirstOrDefault() + // ?.Attribute("value")?.Value; + var execDeptNames = xdoc + .Descendants(ns + "controlActProcess") + .Descendants(ns + "subject") + .Descendants(ns + "observationRequest") + .Descendants(ns + "component2") + .Select(component => + component + .Descendants(ns + "observationRequest") + .Descendants(ns + "location") + .Descendants(ns + "serviceDeliveryLocation") + .Descendants(ns + "serviceProviderOrganization") + .Descendants(ns + "name") + .Descendants(ns + "item") + .Descendants(ns + "part") + .FirstOrDefault() + ) + .Where(item => item != null) + .Select(item => (string)item.Attribute("value")) + .ToList(); + + // 循环获取的 execDeptName + foreach (var execDeptName in execDeptNames) + { + + } + + // 14 循环component2/observationRequest/id/item[@root='2.16.156.10011.1.28'] + //var orderNo = xdoc + // .Descendants(ns + "item") + // .FirstOrDefault(x => (string)x.Attribute("root") == "2.16.156.10011.1.28") + // ?.Attribute("extension")?.Value; + var orderNos = xdoc + .Descendants(ns + "controlActProcess") + .Descendants(ns + "subject") + .Descendants(ns + "observationRequest") + .Descendants(ns + "component2") + .Select(component => + component + .Descendants(ns + "item") + .FirstOrDefault(x => (string)x.Attribute("root") == "2.16.156.10011.1.28") + ) + .Where(item => item != null) + .Select(item => (string)item.Attribute("extension")) + .ToList(); + + // 循环获取的orderNo + foreach (var orderNo in orderNos) + { + + } + + // 15 获取 item[@root='2.16.156.10011.2.5.1.9'] + var visitSqNo = xdoc + .Descendants(ns + "item") + .FirstOrDefault(x => (string)x.Attribute("root") == "2.16.156.10011.2.5.1.9") + ?.Attribute("extension")?.Value; + + // 16 获取 serviceDeliveryLocation/serviceProviderOrganization/id/item + // controlActProcess/subject/observationRequest/component2/ + // observationRequest/location/serviceDeliveryLocation/serviceProviderOrganization/id/item + //var execDeptCode = xdoc + // .Descendants(ns + "item") + // .FirstOrDefault(x => (string)x.Attribute("root") == "2.16.156.10011.1.26") + // ?.Attribute("extension")?.Value; + var execDeptCodes = xdoc + .Descendants(ns + "controlActProcess") + .Descendants(ns + "subject") + .Descendants(ns + "observationRequest") + .Descendants(ns + "component2") + .Select(component => + component + .Descendants(ns + "observationRequest") + .Descendants(ns + "location") + .Descendants(ns + "serviceDeliveryLocation") + .Descendants(ns + "serviceProviderOrganization") + .Descendants(ns + "id") + .Descendants(ns + "item") + .FirstOrDefault() + ) + .Where(item => item != null) + .Select(item => (string)item.Attribute("extension")) + .ToList(); + + // 循环获取的execDeptCode + foreach (var execDeptCode in execDeptCodes) + { + + } + + // 17 获取 item[@root='2.16.156.10011.0.9.1.64']../../name/item/part + var areaName = xdoc + .Descendants(ns + "item") + .FirstOrDefault(x => (string)x.Attribute("root") == "2.16.156.10011.0.9.1.64") + ?.Ancestors(ns + "location") + .Descendants(ns + "name") + .Descendants(ns + "item") + .Descendants(ns + "part") + .FirstOrDefault() + ?.Attribute("value")?.Value; + + // 18 获取 asOrganizationPartOf/wholeOrganization/id/item + var areaCode = xdoc + .Descendants(ns + "wholeOrganization") + .Descendants(ns + "id") + .Descendants(ns + "item") + .FirstOrDefault() + ?.Attribute("extension")?.Value; + + // 19 获取 serviceDeliveryLocation/location/name/item/part + var bedName = xdoc + .Descendants(ns + "item") + .FirstOrDefault(x => (string)x.Attribute("root") == "2.16.156.10011.1.22") + ?.Ancestors(ns + "location") + .Descendants(ns + "name") + .Descendants(ns + "item") + .Descendants(ns + "part") + .FirstOrDefault() + ?.Attribute("value")?.Value; + + // 20 获取 serviceDeliveryLocation/location/id/item + var bedNo = xdoc + .Descendants(ns + "item") + .FirstOrDefault(x => (string)x.Attribute("root") == "2.16.156.10011.1.22") + ?.Attribute("extension")?.Value; + + // 21 获取 subject/observationRequest/id/item + var requestNo = xdoc + .Descendants(ns + "item") + .FirstOrDefault(x => (string)x.Attribute("root") == "2.16.156.10011.1.24") + ?.Attribute("extension")?.Value; + //22 获取身份证 + var idCardNumber = xdoc + .Descendants(ns + "item") + .FirstOrDefault(x => (string)x.Attribute("root") == "2.16.156.10011.1.3") + ?.Attribute("extension")?.Value; + + DBtools db = new DBtools(); + Dictionary dc = new Dictionary(); + // 循环获取的orderNo,分别入库 + for (int i = 0; i < orderNos.Count; i++) + { + dc.Clear(); + dc.Add("entrust_id", orderNos[i]); + //查询库里是否存在该检医嘱 + string sql_exits = "select id from s_list where entrust_id = @entrust_id"; + if (db.ExecQuery(sql_exits, dc).Rows.Count == 0) + { + //不存在则执行插入操作 + DateTime dateTime; + bool success = DateTime.TryParseExact( + requestDate, + "yyyyMMddHHmmss", + CultureInfo.InvariantCulture, + DateTimeStyles.None, + out dateTime); + var entrust_datePart = ""; + var entrust_timePart = ""; + if (success) + { + // 提取格式化后的日期和时间 + entrust_datePart = dateTime.ToString("yyyy-MM-dd"); + entrust_timePart = dateTime.ToString("HH:mm:ss"); + } + //生日 + DateTime birthdayDate; + bool birthdaySuccess = DateTime.TryParseExact( + patientBirthDate, + "yyyyMMdd", + CultureInfo.InvariantCulture, + DateTimeStyles.None, + out birthdayDate); + var birthday = ""; + if (success) + { + birthday = birthdayDate.ToString("yyyy-MM-dd"); + } + //患者类型 + Dictionary mapping = new Dictionary + { + { "03", 0 }, // 住院 + { "01", 1 }, // 门诊 + { "02", 2 }, // 急诊 + { "04", 3 } // 体检 + }; + int patientType = mapping.TryGetValue(visitTypeCode, out int value) ? value : 9; + string insertSql = @" + INSERT INTO s_list ( + list_status, + reg_num, + user_name, + user_sex, + entrust_code, + entrust, + is_pay, + reservation_department, + entrust_date, + entrust_time, + user_brithday, + docotr, + patient_type, + user_phone, + implement_department, + entrust_id, + episodeid, + RISRAcceptDeptCode, + warddesc, + wardcode, + bedname, + bedno, + app_num, + idCardNumber + ) VALUES ( + @list_status, + @reg_num, + @user_name, + @user_sex, + @entrust_code, + @entrust, + @is_pay, + @reservation_department, + @entrust_date, + @entrust_time, + @user_brithday, + @docotr, + @patient_type, + @user_phone, + @implement_department, + @entrust_id, + @episodeid, + @RISRAcceptDeptCode, + @warddesc, + @wardcode, + @bedname, + @bedno, + @app_num, + @idCardNumber + )"; + dc.Clear(); + dc.Add("list_status", 0); // int + dc.Add("reg_num", cardNo); + dc.Add("user_name", patientName); + // dc.Add("user_sex", patientGenderName == "男" ? 1 : 2); // int + dc.Add("user_sex", patientGenderName?.Contains("男") == true ? 1 : 2); + dc.Add("entrust_code", termCodes[i]); + dc.Add("entrust", termNames[i]); + dc.Add("is_pay", chargeStatusName == "已收费" ? 1 : 0); // int + dc.Add("reservation_department", orderDeptName); + dc.Add("entrust_date", entrust_datePart); + dc.Add("entrust_time", entrust_timePart); + dc.Add("user_brithday", birthday); + dc.Add("docotr", orderPersonName); + dc.Add("patient_type", patientType); + dc.Add("user_phone", mobile); + dc.Add("implement_department", execDeptNames[i]); + dc.Add("entrust_id", orderNos[i]); + dc.Add("episodeid", visitSqNo); + dc.Add("RISRAcceptDeptCode", execDeptCodes[i]); + dc.Add("warddesc", areaName); + dc.Add("wardcode", areaCode); + dc.Add("bedname", bedName); + dc.Add("bedno", bedNo); + dc.Add("app_num", requestNo); + dc.Add("idCardNumber", idCardNumber); + int ins = db.ExecSQL(insertSql, dc); + if (ins > 0) + { + // 执行成功了,可以做其他业务处理 + MyLog.Info($"0047消息已入库成功,orderNo:{orderNos[i]}"); + + } + else + { + MyLog.Info($"0047消息入库失败:{ins},orderNo:{orderNos[i]}"); + } + } + else + { + MyLog.Info("数据库已存在该检医嘱--" + orderNos[i]); + } + } + } + catch (Exception e) + { + MyLog.Info("解析[CI0047]消息异常 : " + e.Message); + } + } + } + +} diff --git a/MyHosListener/common/listener/CI0054Listener.cs b/MyHosListener/common/listener/CI0054Listener.cs new file mode 100755 index 0000000..8aed18b --- /dev/null +++ b/MyHosListener/common/listener/CI0054Listener.cs @@ -0,0 +1,151 @@ +using MyHosListener; +using System; +using System.Collections.Generic; +using System.Data; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace MyHosListener.common.listener +{ + public class CI0054Listener : BaseListener + { + + public CI0054Listener(MainWindow caller) + { + this.caller = caller; + } + + public void OnMessage(string message) + { + Save2Log("[CI0054]", message); + ParseMessage(message); + } + + /// + /// 解析数据 + /// + /// + private async void ParseMessage(string message) + { + try + { + XDocument xdoc = XDocument.Parse(message); + // 获取默认命名空间 + XNamespace ns = "urn:hl7-org:v3"; + + // 消息ID + var messageId = xdoc.Descendants(ns + "id") + .FirstOrDefault() // 括号内可以加判定条件 + ?.Attribute("extension")?.Value; + + var visitSqNo = xdoc + .Descendants(ns + "componentOf1") + .Descendants(ns + "encounter") + .Descendants(ns + "id") + .Descendants(ns + "item") + .FirstOrDefault() + ?.Attribute("extension")?.Value; + + // 循环component2 + var extensions = xdoc + .Descendants(ns + "component2") + .Select(component => + component + .Descendants(ns + "item") + .FirstOrDefault(item => (string)item.Attribute("root") == "2.16.156.10011.1.28") + ) + .Where(item => item != null) + .Select(item => (string)item.Attribute("extension")) + .ToList(); + + + + var codes = xdoc + .Descendants(ns + "component2") + .Select(component => + component + .Descendants(ns + "code") + .FirstOrDefault(item => (string)item.Attribute("codeSystem") == "2.16.156.10011.0.9.2.3.2.88") + ) + .Where(item => item != null) + .Select(item => (string)item.Attribute("code")) + .ToList(); + + // 循环获取的itemCode + foreach (var itemCode in codes) + { + + } + + DBtools db = new DBtools(); + Dictionary dc = new Dictionary(); + // 循环获取的orderNo + foreach (var orderNo in extensions) + { + dc.Clear(); + dc.Add("entrust_id", orderNo); + string sql_exits = "select id from s_list where entrust_id = @entrust_id and is_del=0 and is_nullify=0"; + + DataTable result = db.ExecQuery(sql_exits, dc); + if (result.Rows.Count == 1) + { + // 存在,执行更新操作 is_pay = 1 + string id = result.Rows[0]["id"].ToString(); // 获取要更新的记录ID + + string sql_update = "UPDATE s_list SET is_pay = 1 WHERE id = @id"; + Dictionary updateParams = new Dictionary(); + updateParams.Add("id", id); + + int rowsAffected = db.ExecSQL(sql_update, updateParams); + if (rowsAffected > 0) + { + MyLog.Info($"Mq054申请单缴费,医嘱已更新 is_pay=1, OrderNO: {orderNo}"); + await Tools.NoticeEntrustChange(orderNo); + } + else + { + MyLog.Info($"Mq054申请单缴费,医嘱更新失败, OrderNO: {orderNo}"); + } + } + else + { + MyLog.Info($"Mq054申请单缴费,医嘱不存在,OrderNO:{orderNo}"); + } + + } + + // 将解析出来的数据入库 + //DBtools db = new DBtools(); + //Dictionary dc = new Dictionary(); + //// 自己构造SQL语句即可 + //string sql_exits = "select id from user_info where user_num = @user_num and user_card_num=@user_card_num"; + //dc.Add("user_num", "1111"); + //dc.Add("user_card_num", "12345"); + //if (db.ExecQuery(sql_exits, dc).Rows.Count == 1) + //{ + // // 执行成功了,可以做其他业务处理 + // return; + //} + + //string sql_insert = @"INSERT INTO user_info(hosid, user_name, user_sex, addtime, unbind) VALUES (@hosid, @user_name, @user_sex, @addtime, @unbind)"; + //dc.Clear(); + //dc.Add("hosid", 1); + //dc.Add("user_name", "testname"); + //dc.Add("user_sex", 1); + //dc.Add("addtime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); + //dc.Add("unbind", false); + //if (db.ExecSQL(sql_insert, dc) == 0) + //{ + // // 执行成功了,可以做其他业务处理 + // MyLog.Info("[CI0054]消息已入库成功--消息ID" + messageId); + //} + } + catch (Exception e) + { + MyLog.Info("解析[CI0054]消息异常 : " + e.Message); + } + } + } +} diff --git a/MyHosListener/common/listener/CI0055Listener.cs b/MyHosListener/common/listener/CI0055Listener.cs new file mode 100755 index 0000000..afcac71 --- /dev/null +++ b/MyHosListener/common/listener/CI0055Listener.cs @@ -0,0 +1,148 @@ +using MyHosListener; +using System; +using System.Collections.Generic; +using System.Data; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace MyHosListener.common.listener +{ + public class CI0055Listener : BaseListener + { + + public CI0055Listener(MainWindow caller) + { + this.caller = caller; + } + + public void OnMessage(string message) + { + Save2Log("[CI0055]", message); + ParseMessage(message); + } + + /// + /// 解析数据 + /// + /// + private async void ParseMessage(string message) + { + try + { + XDocument xdoc = XDocument.Parse(message); + // 获取默认命名空间 + XNamespace ns = "urn:hl7-org:v3"; + + // 消息ID + var messageId = xdoc.Descendants(ns + "id") + .FirstOrDefault() // 括号内可以加判定条件 + ?.Attribute("extension")?.Value; + + var requestNo = xdoc + .Descendants(ns + "item") + .FirstOrDefault(x => (string)x.Attribute("root") == "2.16.156.10011.1.24") + ?.Attribute("extension")?.Value; + + // 循环component2 + var extensions = xdoc + .Descendants(ns + "component2") + .Select(component => + component + .Descendants(ns + "item") + .FirstOrDefault(item => (string)item.Attribute("root") == "2.16.156.10011.1.28") + ) + .Where(item => item != null) + .Select(item => (string)item.Attribute("extension")) + .ToList(); + + + + var codes = xdoc + .Descendants(ns + "component2") + .Select(component => + component + .Descendants(ns + "code") + .FirstOrDefault(item => (string)item.Attribute("codeSystem") == "2.16.156.10011.0.9.2.3.2.88") + ) + .Where(item => item != null) + .Select(item => (string)item.Attribute("code")) + .ToList(); + + // 循环获取的itemCode + foreach (var itemCode in codes) + { + + } + + DBtools db = new DBtools(); + Dictionary dc = new Dictionary(); + // 循环获取的orderNo + foreach (var orderNo in extensions) + { + dc.Clear(); + dc.Add("entrust_id", orderNo); + string sql_exits = "select id from s_list where entrust_id = @entrust_id and is_del=0 and is_nullify=0"; + + DataTable result = db.ExecQuery(sql_exits, dc); + if (result.Rows.Count == 1) + { + // 存在,执行更新操作 is_pay = 0 + string id = result.Rows[0]["id"].ToString(); // 获取要更新的记录ID + + string sql_update = "UPDATE s_list SET is_pay = 0 WHERE id = @id"; + Dictionary updateParams = new Dictionary(); + updateParams.Add("id", id); + + int rowsAffected = db.ExecSQL(sql_update, updateParams); + if (rowsAffected > 0) + { + MyLog.Info($"Mq055申请单退费,医嘱已更新 is_pay=0, OrderNO: {orderNo}"); + await Tools.NoticeEntrustChange(orderNo); + } + else + { + MyLog.Info($"Mq055申请单退费,医嘱更新失败, OrderNO: {orderNo}"); + } + } + else + { + MyLog.Info($"Mq055申请单退费,医嘱不存在,OrderNO:{orderNo}"); + } + + } + + // 将解析出来的数据入库 + //DBtools db = new DBtools(); + //Dictionary dc = new Dictionary(); + //// 自己构造SQL语句即可 + //string sql_exits = "select id from user_info where user_num = @user_num and user_card_num=@user_card_num"; + //dc.Add("user_num", "1111"); + //dc.Add("user_card_num", "12345"); + //if (db.ExecQuery(sql_exits, dc).Rows.Count == 1) + //{ + // // 执行成功了,可以做其他业务处理 + // return; + //} + + //string sql_insert = @"INSERT INTO user_info(hosid, user_name, user_sex, addtime, unbind) VALUES (@hosid, @user_name, @user_sex, @addtime, @unbind)"; + //dc.Clear(); + //dc.Add("hosid", 1); + //dc.Add("user_name", "testname"); + //dc.Add("user_sex", 1); + //dc.Add("addtime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); + //dc.Add("unbind", false); + //if (db.ExecSQL(sql_insert, dc) == 0) + //{ + // // 执行成功了,可以做其他业务处理 + // MyLog.Info("[CI0055]消息已入库成功--消息ID" + messageId); + //} + } + catch (Exception e) + { + MyLog.Info("解析[CI0055]消息异常 : " + e.Message); + } + } + } +} diff --git a/MyHosListener/common/listener/MI0150Listener.cs b/MyHosListener/common/listener/MI0150Listener.cs new file mode 100755 index 0000000..dcbcc8a --- /dev/null +++ b/MyHosListener/common/listener/MI0150Listener.cs @@ -0,0 +1,141 @@ +using MyHosListener; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Xml.Linq; + +namespace MyHosListener.common.listener +{ + public class MI0150Listener : BaseListener + { + public MI0150Listener(MainWindow caller) + { + this.caller = caller; + } + + public void OnMessage(string message) + { + Save2Log("[MI0150]", message); + ParseMessage(message); + } + + /// + /// 解析数据 + /// + /// + private void ParseMessage(string message) + { + try + { + XDocument xdoc = XDocument.Parse(message); + // 获取默认命名空间 + XNamespace ns = "urn:hl7-org:v3"; + + // 消息ID + var messageId = xdoc.Descendants(ns + "id") + .FirstOrDefault() // 括号内可以加判定条件 + ?.Attribute("extension")?.Value; + + var itemTypeCode = xdoc + .Descendants(ns + "translation") + .FirstOrDefault(x => (string)x.Attribute("codeSystem") == "2.16.156.10011.0.9.2.3.2.144") + ?.Attribute("code")?.Value; + + var itemTypeName = xdoc + .Descendants(ns + "translation") + .FirstOrDefault(x => (string)x.Attribute("codeSystem") == "2.16.156.10011.0.9.2.3.2.144") + .Descendants(ns + "displayName") + .FirstOrDefault() + ?.Attribute("value")?.Value; + + var itemGrade = xdoc + .Descendants(ns + "translation") + .FirstOrDefault(x => (string)x.Attribute("codeSystem") == "2.16.156.10011.0.9.2.3.2.262") + .Descendants(ns + "displayName") + .FirstOrDefault() + ?.Attribute("value")?.Value; + + var itemCode = xdoc + .Descendants(ns + "billableClinicalService") + .Descendants(ns + "code") + .FirstOrDefault() + ?.Attribute("code")?.Value; + + var itemName = xdoc + .Descendants(ns + "billableClinicalService") + .Descendants(ns + "code") + .Descendants(ns + "displayName") + .FirstOrDefault() + ?.Attribute("value")?.Value; + + DBtools db = new DBtools(); + Dictionary dc = new Dictionary(); + + string sql_exits = "select id from s_check_item where item_code = @item_code"; + dc.Add("item_code", itemCode); + if (db.ExecQuery(sql_exits, dc).Rows.Count == 0) + { + //不存在则执行插入操作 + string insert = @"INSERT INTO s_check_item(sheetType,item_code, item_desc, item_name,reservation_method,limosis,check_time) + VALUES (@sheetType, @item_code, @item_desc, @item_name,@reservation_method,@limosis,@check_time)"; + dc.Clear(); + dc.Add("sheetType", itemGrade); + dc.Add("item_code", itemCode); + dc.Add("item_desc", itemName); + dc.Add("item_name", itemName); + dc.Add("reservation_method", "0,1,2,3,4"); + dc.Add("limosis", 0); + dc.Add("check_time", 0); + int ins = db.ExecSQL(insert, dc); + if (ins > 0) + { + // 执行成功了,可以做其他业务处理 + MyLog.Info("消息已入库成功"); + } + else + { + MyLog.Info($"消息入库失败:{ins}"); + } + MyLog.Info("itemCode:" + itemCode); + + return; + } + + + + // 将解析出来的数据入库 + //DBtools db = new DBtools(); + //Dictionary dc = new Dictionary(); + //// 自己构造SQL语句即可 + //string sql_exits = "select id from user_info where user_num = @user_num and user_card_num=@user_card_num"; + //dc.Add("user_num", "1111"); + //dc.Add("user_card_num", "12345"); + //if (db.ExecQuery(sql_exits, dc).Rows.Count == 1) + //{ + // // 执行成功了,可以做其他业务处理 + // return; + //} + + //string sql_insert = @"INSERT INTO user_info(hosid, user_name, user_sex, addtime, unbind) VALUES (@hosid, @user_name, @user_sex, @addtime, @unbind)"; + //dc.Clear(); + //dc.Add("hosid", 1); + //dc.Add("user_name", "testname"); + //dc.Add("user_sex", 1); + //dc.Add("addtime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); + //dc.Add("unbind", false); + //if (db.ExecSQL(sql_insert, dc) == 0) + //{ + // // 执行成功了,可以做其他业务处理 + // MyLog.Info("[MI0150]消息已入库成功--消息ID" + messageId); + //} + } + catch (Exception e) + { + MyLog.Info("解析[MI0150]消息异常 : " + e.Message); + } + } + } +} diff --git a/MyHosListener/common/listener/MI0164Listener.cs b/MyHosListener/common/listener/MI0164Listener.cs new file mode 100755 index 0000000..0099164 --- /dev/null +++ b/MyHosListener/common/listener/MI0164Listener.cs @@ -0,0 +1,120 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace MyHosListener.common.listener +{ + internal class MI0164Listener : BaseListener + { + public MI0164Listener(MainWindow caller) + { + this.caller = caller; + } + + public void OnMessage(string message) + { + Save2Log("[MI0164]", message); + ParseMessage(message); + } + private void ParseMessage(string message) + { + try + { + XDocument xdoc = XDocument.Parse(message); + // 获取默认命名空间 + XNamespace ns = "urn:hl7-org:v3"; + + // 消息ID + var messageId = xdoc.Descendants(ns + "id") + .FirstOrDefault() // 括号内可以加判定条件 + ?.Attribute("extension")?.Value; + + var termCode = xdoc + .Descendants(ns + "item") + .FirstOrDefault(x => (string)x.Attribute("root") == "2.16.156.10011.0.9.2.3.2.101") + ?.Attribute("extension")?.Value; + + var termName = xdoc + .Descendants(ns + "item") + .FirstOrDefault(x => (string)x.Attribute("root") == "2.16.156.10011.0.9.2.3.2.101") + ?.Attribute("identifierName")?.Value; + + var requestTypeCode = xdoc + .Descendants(ns + "translation") + .FirstOrDefault(x => (string)x.Attribute("code") != null && (string)x.Attribute("codeSystemName") == "申请单类型代码表") + ?.Attribute("code")?.Value; + + DBtools db = new DBtools(); + Dictionary dc = new Dictionary(); + + string sql_exits = "select id from s_check_item where item_code = @item_code"; + dc.Add("item_code", termCode); + if (db.ExecQuery(sql_exits, dc).Rows.Count == 0) + { + //不存在则执行插入操作 + string insert = @"INSERT INTO s_check_item(sheetType,item_code, item_desc, item_name,reservation_method,limosis,check_time) + VALUES (@sheetType, @item_code, @item_desc, @item_name,@reservation_method,@limosis,@check_time)"; + dc.Clear(); + dc.Add("sheetType", requestTypeCode); + dc.Add("item_code", termCode); + dc.Add("item_desc", termName); + dc.Add("item_name", termName); + dc.Add("reservation_method", "0,1,2,3,4"); + dc.Add("limosis", 0); + dc.Add("check_time", 0); + int ins = db.ExecSQL(insert, dc); + if (ins > 0) + { + // 执行成功了,可以做其他业务处理 + MyLog.Info("消息已入库成功"); + } + else + { + MyLog.Info($"消息入库失败:{ins}"); + } + MyLog.Info("itemCode:" + termCode); + + return; + } + else { + MyLog.Info($"Mq164项目已经存在无需入库, itemCode: {termCode}"); + } + + + + // 将解析出来的数据入库 + //DBtools db = new DBtools(); + //Dictionary dc = new Dictionary(); + //// 自己构造SQL语句即可 + //string sql_exits = "select id from user_info where user_num = @user_num and user_card_num=@user_card_num"; + //dc.Add("user_num", "1111"); + //dc.Add("user_card_num", "12345"); + //if (db.ExecQuery(sql_exits, dc).Rows.Count == 1) + //{ + // // 执行成功了,可以做其他业务处理 + // return; + //} + + //string sql_insert = @"INSERT INTO user_info(hosid, user_name, user_sex, addtime, unbind) VALUES (@hosid, @user_name, @user_sex, @addtime, @unbind)"; + //dc.Clear(); + //dc.Add("hosid", 1); + //dc.Add("user_name", "testname"); + //dc.Add("user_sex", 1); + //dc.Add("addtime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); + //dc.Add("unbind", false); + //if (db.ExecSQL(sql_insert, dc) == 0) + //{ + // // 执行成功了,可以做其他业务处理 + // MyLog.Info("[MI0150]消息已入库成功--消息ID" + messageId); + //} + } + catch (Exception e) + { + MyLog.Info("解析[MI0164]消息异常 : " + e.Message); + } + } + } +} diff --git a/MyHosListener/common/listener/MU0151Listener.cs b/MyHosListener/common/listener/MU0151Listener.cs new file mode 100755 index 0000000..dbc2da6 --- /dev/null +++ b/MyHosListener/common/listener/MU0151Listener.cs @@ -0,0 +1,157 @@ +using MyHosListener; +using System; +using System.Collections.Generic; +using System.Data; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace MyHosListener.common.listener +{ + public class MU0151Listener : BaseListener + { + public MU0151Listener(MainWindow caller) + { + this.caller = caller; + } + + public void OnMessage(string message) + { + Save2Log("[MU0151]", message); + ParseMessage(message); + } + + /// + /// 解析数据 + /// + /// + private void ParseMessage(string message) + { + try + { + XDocument xdoc = XDocument.Parse(message); + // 获取默认命名空间 + XNamespace ns = "urn:hl7-org:v3"; + + // 消息ID + var messageId = xdoc.Descendants(ns + "id") + .FirstOrDefault() // 括号内可以加判定条件 + ?.Attribute("extension")?.Value; + + var itemTypCode = xdoc + .Descendants(ns + "translation") + .FirstOrDefault(x => (string)x.Attribute("codeSystem") == "2.16.156.10011.0.9.2.3.2.144") + ?.Attribute("code")?.Value; + + var itemTypeName = xdoc + .Descendants(ns + "translation") + .FirstOrDefault(x => (string)x.Attribute("codeSystem") == "2.16.156.10011.0.9.2.3.2.144") + .Descendants(ns + "displayName") + .FirstOrDefault() + ?.Attribute("value")?.Value; + + var itemGrade = xdoc + .Descendants(ns + "translation") + .FirstOrDefault(x => (string)x.Attribute("codeSystem") == "2.16.156.10011.0.9.2.3.2.262") + .Descendants(ns + "displayName") + .FirstOrDefault() + ?.Attribute("value")?.Value; + + var itemCode = xdoc + .Descendants(ns + "billableClinicalService") + .Descendants(ns + "code") + .FirstOrDefault() + ?.Attribute("code")?.Value; + + var itemName = xdoc + .Descendants(ns + "billableClinicalService") + .Descendants(ns + "code") + .Descendants(ns + "displayName") + .FirstOrDefault() + ?.Attribute("value")?.Value; + + var isEffective = xdoc + .Descendants(ns + "billableClinicalService") + .Descendants(ns + "code") + .FirstOrDefault() + ?.Attribute("validTimeLow")?.Value; + + + DBtools db = new DBtools(); + Dictionary dc = new Dictionary(); + + dc.Add("itemCode", itemCode); + string sql_exits = "select id from s_check_item where item_code = @itemCode"; + + DataTable result = db.ExecQuery(sql_exits, dc); + + if (result.Rows.Count >= 1) + { + var status = "1"; + if (isEffective != "1") + { + status = "0"; + } + // 存在,执行更新操作 + string id = result.Rows[0]["id"].ToString(); // 获取要更新的记录ID + + string sql_update = "UPDATE s_check_item SET item_name = @itemName,item_desc = @itemName ,status=@status WHERE id = @id"; + Dictionary updateParams = new Dictionary(); + updateParams.Add("itemName", itemName); + updateParams.Add("status", status); + updateParams.Add("id", id); + + + int rowsAffected = db.ExecSQL(sql_update, updateParams); + if (rowsAffected > 0) + { + // AppendMessage($"Mq151变更检查项目,项目已更新, itemCode: {itemCode}"); + MyLog.Info($"Mq151变更检查项目,项目已更新, itemCode: {itemCode}"); + } + else + { + // AppendMessage($"Mq151变更检查项目,项目更新失败, itemCode: {itemCode}"); + MyLog.Info($"Mq151变更检查项目,项目更新失败, itemCode: {itemCode}"); + } + } + else + { + // AppendMessage($"Mq151变更检查项目,项目不存在,itemCode:{itemCode}"); + MyLog.Info($"Mq151变更检查项目,项目不存在,itemCode:{itemCode}"); + } + + // 将解析出来的数据入库 + //DBtools db = new DBtools(); + //Dictionary dc = new Dictionary(); + //// 自己构造SQL语句即可 + //string sql_exits = "select id from user_info where user_num = @user_num and user_card_num=@user_card_num"; + //dc.Add("user_num", "1111"); + //dc.Add("user_card_num", "12345"); + //if (db.ExecQuery(sql_exits, dc).Rows.Count == 1) + //{ + // // 执行成功了,可以做其他业务处理 + // return; + //} + + //string sql_insert = @"INSERT INTO user_info(hosid, user_name, user_sex, addtime, unbind) VALUES (@hosid, @user_name, @user_sex, @addtime, @unbind)"; + //dc.Clear(); + //dc.Add("hosid", 1); + //dc.Add("user_name", "testname"); + //dc.Add("user_sex", 1); + //dc.Add("addtime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); + //dc.Add("unbind", false); + //if (db.ExecSQL(sql_insert, dc) == 0) + //{ + // // 执行成功了,可以做其他业务处理 + // MyLog.Info("[MU0151]消息已入库成功--消息ID" + messageId); + //} + } + catch (Exception e) + { + MyLog.Info("解析[MU0151]消息异常 : " + e.Message); + } + } + + } +} diff --git a/MyHosListener/common/listener/MU0165Listener.cs b/MyHosListener/common/listener/MU0165Listener.cs new file mode 100755 index 0000000..5ba938e --- /dev/null +++ b/MyHosListener/common/listener/MU0165Listener.cs @@ -0,0 +1,160 @@ +using System; +using System.Collections.Generic; +using System.Data; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace MyHosListener.common.listener +{ + internal class MU0165Listener : BaseListener + { + public MU0165Listener(MainWindow caller) + { + this.caller = caller; + } + + public void OnMessage(string message) + { + Save2Log("[MU0165]", message); + ParseMessage(message); + } + /// + /// 解析数据 + /// + /// + private void ParseMessage(string message) + { + try + { + XDocument xdoc = XDocument.Parse(message); + // 获取默认命名空间 + XNamespace ns = "urn:hl7-org:v3"; + + // 消息ID + var messageId = xdoc.Descendants(ns + "id") + .FirstOrDefault() // 括号内可以加判定条件 + ?.Attribute("extension")?.Value; + + var termCode = xdoc + .Descendants(ns + "item") + .FirstOrDefault(x => (string)x.Attribute("root") == "2.16.156.10011.0.9.2.3.2.101") + ?.Attribute("extension")?.Value; + + var termName = xdoc + .Descendants(ns + "item") + .FirstOrDefault(x => (string)x.Attribute("root") == "2.16.156.10011.0.9.2.3.2.101") + ?.Attribute("identifierName")?.Value; + + var isEffective = xdoc + .Descendants(ns + "item") + .FirstOrDefault(x => (string)x.Attribute("root") == "2.16.156.10011.0.9.2.3.2.101") + ?.Attribute("validTimeLow")?.Value; + + var requestTypeCode = xdoc + .Descendants(ns + "translation") + .FirstOrDefault(x => (string)x.Attribute("code") != null && (string)x.Attribute("codeSystemName") == "申请单类型代码表") + ?.Attribute("code")?.Value; + + + DBtools db = new DBtools(); + Dictionary dc = new Dictionary(); + + dc.Add("itemCode", termCode); + string sql_exits = "select id from s_check_item where item_code = @itemCode"; + + DataTable result = db.ExecQuery(sql_exits, dc); + + if (result.Rows.Count >= 1) + { + var status = "1"; + if (isEffective != "1") + { + status = "0"; + } + // 存在,执行更新操作 + string id = result.Rows[0]["id"].ToString(); // 获取要更新的记录ID + + string sql_update = "UPDATE s_check_item SET item_name = @itemName,item_desc = @itemName ,status=@status WHERE id = @id"; + Dictionary updateParams = new Dictionary(); + updateParams.Add("itemName", termName); + updateParams.Add("status", status); + updateParams.Add("id", id); + + + int rowsAffected = db.ExecSQL(sql_update, updateParams); + if (rowsAffected > 0) + { + // AppendMessage($"Mq151变更检查项目,项目已更新, itemCode: {itemCode}"); + MyLog.Info($"Mq165变更检查项目,项目已更新, itemCode: {termCode}"); + } + else + { + // AppendMessage($"Mq151变更检查项目,项目更新失败, itemCode: {itemCode}"); + MyLog.Info($"Mq165变更检查项目,项目更新失败, itemCode: {termCode}"); + } + } + else + { + // AppendMessage($"Mq151变更检查项目,项目不存在,itemCode:{itemCode}"); + MyLog.Info($"Mq165变更检查项目,项目不存在,进行添加,itemCode:{termCode}"); + //不存在则执行插入操作 + string insert = @"INSERT INTO s_check_item(sheetType,item_code, item_desc, item_name,reservation_method,limosis,check_time) + VALUES (@sheetType, @item_code, @item_desc, @item_name,@reservation_method,@limosis,@check_time)"; + dc.Clear(); + dc.Add("sheetType", requestTypeCode); + dc.Add("item_code", termCode); + dc.Add("item_desc", termName); + dc.Add("item_name", termName); + dc.Add("reservation_method", "0,1,2,3,4"); + dc.Add("limosis", 0); + dc.Add("check_time", 0); + int ins = db.ExecSQL(insert, dc); + if (ins > 0) + { + // 执行成功了,可以做其他业务处理 + MyLog.Info($"165不存在后,新增检查项目消息已入库成功itemCode:{termCode}"); + } + else + { + MyLog.Info($"165不存在后,新增检查项目,消息入库失败:{ins}"); + } + MyLog.Info("itemCode:" + termCode); + + return; + } + + // 将解析出来的数据入库 + //DBtools db = new DBtools(); + //Dictionary dc = new Dictionary(); + //// 自己构造SQL语句即可 + //string sql_exits = "select id from user_info where user_num = @user_num and user_card_num=@user_card_num"; + //dc.Add("user_num", "1111"); + //dc.Add("user_card_num", "12345"); + //if (db.ExecQuery(sql_exits, dc).Rows.Count == 1) + //{ + // // 执行成功了,可以做其他业务处理 + // return; + //} + + //string sql_insert = @"INSERT INTO user_info(hosid, user_name, user_sex, addtime, unbind) VALUES (@hosid, @user_name, @user_sex, @addtime, @unbind)"; + //dc.Clear(); + //dc.Add("hosid", 1); + //dc.Add("user_name", "testname"); + //dc.Add("user_sex", 1); + //dc.Add("addtime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); + //dc.Add("unbind", false); + //if (db.ExecSQL(sql_insert, dc) == 0) + //{ + // // 执行成功了,可以做其他业务处理 + // MyLog.Info("[MU0151]消息已入库成功--消息ID" + messageId); + //} + } + catch (Exception e) + { + MyLog.Info("解析[MU0165]消息异常 : " + e.Message); + } + } + } +} diff --git a/MyHosListener/common/listener/OD0084Listener.cs b/MyHosListener/common/listener/OD0084Listener.cs new file mode 100755 index 0000000..3919aa9 --- /dev/null +++ b/MyHosListener/common/listener/OD0084Listener.cs @@ -0,0 +1,121 @@ +using MyHosListener; +using System; +using System.Collections.Generic; +using System.Data; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace MyHosListener.common.listener +{ + public class OD0084Listener : BaseListener + { + public OD0084Listener(MainWindow caller) + { + this.caller = caller; + } + + public void OnMessage(string message) + { + Save2Log("[OD0084]", message); + ParseMessage(message); + } + + /// + /// 解析数据 + /// + /// + private void ParseMessage(string message) + { + try + { + XDocument xdoc = XDocument.Parse(message); + // 获取默认命名空间 + XNamespace ns = "urn:hl7-org:v3"; + + // 消息ID + var messageId = xdoc.Descendants(ns + "id") + .FirstOrDefault() // 括号内可以加判定条件 + ?.Attribute("extension")?.Value; + + var orderNo = xdoc + .Descendants(ns + "item") + .FirstOrDefault(x => (string)x.Attribute("root") == "2.16.156.10011.1.28") + ?.Attribute("extension")?.Value; + + var cardNo = xdoc + .Descendants(ns + "item") + .FirstOrDefault(x => (string)x.Attribute("root") == "2.16.156.10011.2.5.1.4") + ?.Attribute("extension")?.Value; + + // controlActProcess/subject/placerGroup/code[code] + var itemCode = xdoc + .Descendants(ns + "controlActProcess") + .Descendants(ns + "subject") + .Descendants(ns + "placerGroup") + .Descendants(ns + "code") + .FirstOrDefault() + ?.Attribute("code")?.Value; + DBtools db = new DBtools(); + Dictionary dc = new Dictionary(); + string sql_exits = "select id from s_list where entrust_id = @entrust_id and is_del=0 and is_nullify=0"; + dc.Add("entrust_id", orderNo); + DataTable result = db.ExecQuery(sql_exits, dc); + if (result.Rows.Count == 1) + { + // 存在,执行更新操作 is_pay = 0 + string id = result.Rows[0]["id"].ToString(); // 获取要更新的记录ID + + string sql_update = "UPDATE s_list SET is_pay = 0 WHERE id = @id"; + Dictionary updateParams = new Dictionary(); + updateParams.Add("id", id); + + int rowsAffected = db.ExecSQL(sql_update, updateParams); + if (rowsAffected > 0) + { + MyLog.Info($"Mq0084,医嘱已更新 is_pay=0, OrderNO: {orderNo}"); + } + else + { + MyLog.Info($"Mq0084,医嘱更新失败, OrderNO: {orderNo}"); + } + } + else + { + MyLog.Info($"Mq0084,医嘱不存在,OrderNO:{orderNo}"); + } + + // 将解析出来的数据入库 + //DBtools db = new DBtools(); + //Dictionary dc = new Dictionary(); + //// 自己构造SQL语句即可 + //string sql_exits = "select id from user_info where user_num = @user_num and user_card_num=@user_card_num"; + //dc.Add("user_num", "1111"); + //dc.Add("user_card_num", "12345"); + //if (db.ExecQuery(sql_exits, dc).Rows.Count == 1) + //{ + // // 执行成功了,可以做其他业务处理 + // return; + //} + + //string sql_insert = @"INSERT INTO user_info(hosid, user_name, user_sex, addtime, unbind) VALUES (@hosid, @user_name, @user_sex, @addtime, @unbind)"; + //dc.Clear(); + //dc.Add("hosid", 1); + //dc.Add("user_name", "testname"); + //dc.Add("user_sex", 1); + //dc.Add("addtime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); + //dc.Add("unbind", false); + //if (db.ExecSQL(sql_insert, dc) == 0) + //{ + // // 执行成功了,可以做其他业务处理 + // MyLog.Info("[OD0084]消息已入库成功--消息ID" + messageId); + //} + } + catch (Exception e) + { + MyLog.Info("解析[OD0084]消息异常 : " + e.Message); + } + } + } +} diff --git a/MyHosListener/common/listener/OI0083Listener.cs b/MyHosListener/common/listener/OI0083Listener.cs new file mode 100755 index 0000000..5f5454f --- /dev/null +++ b/MyHosListener/common/listener/OI0083Listener.cs @@ -0,0 +1,132 @@ +using MyHosListener; +using System; +using System.Collections.Generic; +using System.Data; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace MyHosListener.common.listener +{ + public class OI0083Listener : BaseListener + { + public OI0083Listener(MainWindow caller) + { + this.caller = caller; + } + + public void OnMessage(string message) + { + Save2Log("[OI0083]", message); + ParseMessage(message); + } + + /// + /// 解析数据 + /// + /// + private void ParseMessage(string message) + { + try + { + XDocument xdoc = XDocument.Parse(message); + // 获取默认命名空间 + XNamespace ns = "urn:hl7-org:v3"; + + // 消息ID + var messageId = xdoc.Descendants(ns + "id") + .FirstOrDefault() // 括号内可以加判定条件 + ?.Attribute("extension")?.Value; + + + // 提取医嘱相关 ID + var orderNo = xdoc + .Descendants(ns + "item") + .FirstOrDefault(x => (string)x.Attribute("root") == "2.16.156.10011.1.28") + ?.Attribute("extension")?.Value; + + var cardNo = xdoc + .Descendants(ns + "item") + .FirstOrDefault(x => (string)x.Attribute("root") == "2.16.156.10011.2.5.1.4") + ?.Attribute("extension")?.Value; + + //componentOf1/encounter/id/item + var visitSqNo = xdoc + .Descendants(ns + "componentOf1") + .Descendants(ns + "encounter") + .Descendants(ns + "id") + .Descendants (ns + "item") + .FirstOrDefault() + ?.Attribute("extension")?.Value; + + // controlActProcess/subject/placerGroup/code[code] + var itemCode = xdoc + .Descendants(ns + "controlActProcess") + .Descendants(ns + "subject") + .Descendants(ns + "placerGroup") + .Descendants(ns + "code") + .FirstOrDefault() + ?.Attribute("code")?.Value; + DBtools db = new DBtools(); + Dictionary dc = new Dictionary(); + string sql_exits = "select id from s_list where entrust_id = @entrust_id and is_del=0 and is_nullify=0"; + dc.Add("entrust_id", orderNo); + DataTable result = db.ExecQuery(sql_exits, dc); + if (result.Rows.Count == 1) + { + // 存在,执行更新操作 is_pay = 1 + string id = result.Rows[0]["id"].ToString(); // 获取要更新的记录ID + + string sql_update = "UPDATE s_list SET is_pay = 1 WHERE id = @id"; + Dictionary updateParams = new Dictionary(); + updateParams.Add("id", id); + + int rowsAffected = db.ExecSQL(sql_update, updateParams); + if (rowsAffected > 0) + { + MyLog.Info($"Mq0083,医嘱已更新 is_pay=1, OrderNO: {orderNo}"); + } + else + { + MyLog.Info($"Mq0083,医嘱更新失败, OrderNO: {orderNo}"); + } + } + else + { + MyLog.Info($"Mq0083,医嘱不存在,OrderNO:{orderNo}"); + } + + // 将解析出来的数据入库 + //DBtools db = new DBtools(); + //Dictionary dc = new Dictionary(); + //// 自己构造SQL语句即可 + //string sql_exits = "select id from user_info where user_num = @user_num and user_card_num=@user_card_num"; + //dc.Add("user_num", "1111"); + //dc.Add("user_card_num", "12345"); + //if (db.ExecQuery(sql_exits, dc).Rows.Count == 1) + //{ + // // 执行成功了,可以做其他业务处理 + // return; + //} + + //string sql_insert = @"INSERT INTO user_info(hosid, user_name, user_sex, addtime, unbind) VALUES (@hosid, @user_name, @user_sex, @addtime, @unbind)"; + //dc.Clear(); + //dc.Add("hosid", 1); + //dc.Add("user_name", "testname"); + //dc.Add("user_sex", 1); + //dc.Add("addtime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); + //dc.Add("unbind", false); + //if (db.ExecSQL(sql_insert, dc) == 0) + //{ + // // 执行成功了,可以做其他业务处理 + // MyLog.Info("[OI0083]消息已入库成功--消息ID" + messageId); + //} + } + catch (Exception e) + { + MyLog.Info("解析[OI0083]消息异常 : " + e.Message); + } + } + } +} diff --git a/MyHosListener/images/pwd_checked.png b/MyHosListener/images/pwd_checked.png new file mode 100755 index 0000000..57cdb45 Binary files /dev/null and b/MyHosListener/images/pwd_checked.png differ diff --git a/MyHosListener/images/pwd_uncheck.png b/MyHosListener/images/pwd_uncheck.png new file mode 100755 index 0000000..40d3bdd Binary files /dev/null and b/MyHosListener/images/pwd_uncheck.png differ diff --git a/MyHosListener/log4net.config b/MyHosListener/log4net.config new file mode 100755 index 0000000..9156c35 --- /dev/null +++ b/MyHosListener/log4net.config @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/MyHosListener/packages.config b/MyHosListener/packages.config new file mode 100755 index 0000000..2f57166 --- /dev/null +++ b/MyHosListener/packages.config @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file