Exemple #1
0
        /// <summary>
        /// 消息达到后交个Biz处理
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void SocketHelper_MessageReviced(object sender, MessageRevicedEventArgs e)
        {
            string sendingApp = AppSettingString.SendingApp;
            string recvApp    = AppSettingString.RecvApp; //System.Configuration.ConfigurationManager.AppSettings["recvApp"];

            try
            {
                DBConn     dbcon  = new DBConn();
                PipeParser parser = new PipeParser();
                //解析出消息类型,创建对应的Biz进行处理
                string message = System.Text.Encoding.UTF8.GetString(e.Contents);
                message = MediII.Common.MLLPHelper.TrimMLLP(message, true, false);
                LogHelp.WriteLog(message);

                ////手术字典
                //if (message.Contains(_AcceptTitleOperDic))
                //{
                //    OperDicModel dic = HL7ToXmlConverter.ToOperDic(message);
                //    dbcon.InsertOperDic(dic);
                //}


                if (message.Contains(_NewOperApply))
                {
                    OTypesetting paiban = null;
                    paiban = HL7ToXmlConverter.toDataBae(message, paiban);
                    if (dbcon.GetPaiban(paiban.PatZhuYuanID) == null)
                    {
                        dbcon.InsertPaiban(paiban);
                    }
                }

                //修改
                else if (message.Contains(_UpdateOperApply))
                {
                    string       zhuyuanid = HL7ToXmlConverter.GetZhuyuanId(message);
                    OTypesetting paiban    = dbcon.GetPaiban(zhuyuanid);
                    paiban = HL7ToXmlConverter.toDataBae(message, paiban);

                    if (paiban != null)
                    {
                        if (paiban.Ostate == 0)
                        {
                            dbcon.UpdatePaiban(paiban);
                        }
                    }
                }

                else if (message.Contains(_CancelOperApply))
                {
                    string zhuyuanid = "";
                    message = message.Replace("ARQ", "\nARQ");
                    string[] sList = message.Split('\n');
                    foreach (string str in sList)
                    {
                        if (str.Contains("ARQ|"))
                        {
                            zhuyuanid = str.Split('|')[1].Replace("^", "");
                        }
                    }
                    dbcon.UpdatePaibanOstate(zhuyuanid, -1);
                }

                //string mesStruct = parser.GetMessageStructure(message).Substring(0, 3);
                string ackMsg = MediII.Common.MessageHelper.SetACK("ACK", "", "", recvApp, recvApp, sendingApp, sendingApp,
                                                                   Guid.NewGuid().ToString("N"));
                LogHelp.WriteLog(ackMsg);
                SocketHelper.SendAck(MediII.Common.MLLPHelper.AddMLLP(ackMsg), e.SocketHandler);
            }
            catch (Exception ex)
            {
                //出现异常需要返回,避免队列堵塞
                string ackMsg = MediII.Common.MessageHelper.SetACK("ACK", "", "", recvApp, recvApp, sendingApp, sendingApp,
                                                                   Guid.NewGuid().ToString("N"), ex.Message);
                LogHelp.WriteErrorLog(ackMsg);
                SocketHelper.SendAck(MediII.Common.MLLPHelper.AddMLLP(ackMsg), e.SocketHandler);
                MediII.Common.LogHelper.LogError(ex, Common.LogCatagories.AdapterBiz);
            }
        }
 /// <summary>
 /// 消息达到后交个Biz处理
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 void SocketHelper_MessageReviced(object sender, MessageRevicedEventArgs e)
 {
     try
     {
         DBConn     dbcon  = new DBConn();
         PipeParser parser = new PipeParser();
         //解析出消息类型,创建对应的Biz进行处理
         string message = System.Text.Encoding.UTF8.GetString(e.Contents);
         message = MediII.Common.MLLPHelper.TrimMLLP(message, true, false);
         LogTxt.WriteError("接收到信息:", message, EventLogEntryType.Information);
         if (message.Contains(ConfigurationManager.AppSettings["AcceptTitle"]))
         {
             paibanModel paiban    = HL7ToXmlConverter.toDataBae(message);
             string      tableName = System.Configuration.ConfigurationManager.AppSettings["PaibanTableName"];
             if (dbcon.GetPaiban(paiban, tableName).Rows.Count == 0)
             {
                 dbcon.InsertPaiban(paiban, tableName);
             }
         }
         if (message.Contains(ConfigurationManager.AppSettings["AcceptTitleConfig"]))
         {
             paibanModel paiban    = HL7ToXmlConverter.toDataBae(message);
             string      tableName = System.Configuration.ConfigurationManager.AppSettings["PaibanTableName"];
             if (dbcon.GetPaiban(paiban, tableName).Rows.Count == 1)
             {
                 dbcon.UpdatePaibanAll(paiban, tableName);
             }
         }
         if (message.Contains(ConfigurationManager.AppSettings["AcceptTitleCancel"]))
         {
             string PatID = "";
             message = message.Replace("ARQ", "\nARQ");
             string[] sList = message.Split('\n');
             foreach (string str in sList)
             {
                 if (str.Contains("ARQ|"))
                 {
                     PatID = str.Split('|')[1].Replace("^", "");
                 }
             }
             string tableName = System.Configuration.ConfigurationManager.AppSettings["PaibanTableName"];
             dbcon.UpdatePaiban(tableName, PatID);
         }
         string mesStruct  = parser.GetMessageStructure(message).Substring(0, 3);
         string sendingApp = System.Configuration.ConfigurationManager.AppSettings["sendingApp"];
         string recvApp    = System.Configuration.ConfigurationManager.AppSettings["recvApp"];
         string ackMsg     = MediII.Common.MessageHelper.SetACK("ACK", "", "", sendingApp, sendingApp,
                                                                recvApp, recvApp, "123456789");
         DBConn.SaveLog(ackMsg);
         SocketHelper.SendAck(MediII.Common.MLLPHelper.AddMLLP(ackMsg), e.SocketHandler);
     }
     catch (Exception ex)
     {
         //出现异常需要返回,避免队列堵塞
         string sendingApp = System.Configuration.ConfigurationManager.AppSettings["SedingApplication"];
         string recvApp    = "SSMZ";
         string ackMsg     = MediII.Common.MessageHelper.SetACK("ACK", "", "", sendingApp, sendingApp,
                                                                recvApp, recvApp, "123456789", ex.Message);
         SocketHelper.SendAck(MediII.Common.MLLPHelper.AddMLLP(ackMsg), e.SocketHandler);
         MediII.Common.LogHelper.LogError(ex, Common.LogCatagories.AdapterBiz);
     }
 }