Example #1
0
        private void HL7ApplySampleProcess()
        {
            string receiveString = string.Empty;

            //while ((!ProcessHL7Cancel.IsCancellationRequested && GlobalVariable.IsSocketRun) || hl7Manager.IsHL7ApplySampleAvailable)
            while ((!ProcessHL7Cancel.IsCancellationRequested && GlobalVariable.IsSocketRun))
            {
                //进行之前接收到的样本数据处理
                hl7Manager.HL7ApplySampleSignal.WaitOne();
                if (!hl7Manager.IsHL7ApplySampleAvailable)
                {
                    hl7Manager.HL7ApplySampleSignal.Reset();
                    Statusbar.SBar.SoftStatus = GlobalVariable.miniWaiting;
                }
                else
                {
                    //队列里存在数据
                    receiveString = hl7Manager.GetHL7ApplySample();
                    if (receiveString.IndexOf("DSR") != -1)
                    {
                        //判断传回来数据为DSR数据
                        //解析DSR
                        //解析完DSR数据就要回复ACKQ03消息,此时设备信息传出去
                        PipeParser parserActiveDSR = new PipeParser();
                        IMessage   mActiveDSR      = parserActiveDSR.Parse(receiveString);
                        DSR_Q03    dsr             = mActiveDSR as DSR_Q03;
                        if (dsr.MSH.AcceptAcknowledgmentType.Value == "P" && dsr.QAK.QueryResponseStatus.Value == "OK")
                        {
                            //双重判断,既判断是否为LIS主动发送样本信息,也要判断是否OK
                            Statusbar.SBar.SoftStatus = GlobalVariable.miniBusy;// mini mode

                            HL7Manager.HL7SampleInfo hl7info = HL7_ParserSampleInfo(receiveString);
                            RequestSampleData.Invoke(hl7info);
                            //接收成功后就要发送应答信号
                            Connect.sendSocket(CreatACKQ03(dsr.MSH.ReceivingFacility.NamespaceID.Value));
                            ProcessHL7Message.Invoke(hl7info.SampleID + "LIS服务器主动发送样本申请信息\r\n", "LIS");
                            log.Info("Lis initiative request sample " + hl7info.SampleID);

                            //Statusbar.SBar.SoftStatus = GlobalVariable.miniWaiting;// mini mode
                            Statusbar.SBar.SampleId = hl7info.SampleID;//mini mode
                        }
                    }
                    Statusbar.SBar.SoftStatus = GlobalVariable.miniBusy;// mini mode
                }
            }
        }
Example #2
0
        private HL7Manager.HL7SampleInfo HL7_ParserSampleInfo(string hl7data)
        {
            HL7Manager.HL7SampleInfo hl7info = new HL7Manager.HL7SampleInfo();
            hl7info.ExtraInfo = new List <HL7Manager.HL7ExtraInfo>();

            PipeParser parser = new PipeParser();
            IMessage   m      = parser.Parse(hl7data);
            DSR_Q03    dsr    = m as DSR_Q03;

            #region 解析HL7申请样本信息
            hl7info.AdmissionNumber = dsr.GetDSP(0).DataLine.Value;
            hl7info.BedNumber       = dsr.GetDSP(1).DataLine.Value;
            hl7info.PatientName     = dsr.GetDSP(2).DataLine.Value;
            try
            {
                hl7info.DateOfBirth = DateTime.ParseExact(dsr.GetDSP(3).DataLine.Value, "yyyyMMddHHmmss", System.Globalization.CultureInfo.CurrentCulture);
            }
            catch
            {
                hl7info.DateOfBirth = GlobalVariable.DefalutTime;
            }
            hl7info.Sex                  = dsr.GetDSP(4).DataLine.Value;
            hl7info.PatientAlias         = dsr.GetDSP(5).DataLine.Value;
            hl7info.Race                 = dsr.GetDSP(6).DataLine.Value;
            hl7info.PatientAddress       = dsr.GetDSP(7).DataLine.Value;
            hl7info.CountryCode          = dsr.GetDSP(8).DataLine.Value;
            hl7info.HomePhoneNumber      = dsr.GetDSP(9).DataLine.Value;
            hl7info.BusinessPhoneNumber  = dsr.GetDSP(10).DataLine.Value;
            hl7info.PrimaryLanguage      = dsr.GetDSP(11).DataLine.Value;
            hl7info.MaritalStatus        = dsr.GetDSP(12).DataLine.Value;
            hl7info.Religion             = dsr.GetDSP(13).DataLine.Value;
            hl7info.PatientAccoutNumber  = dsr.GetDSP(14).DataLine.Value;
            hl7info.SocialSecurityNumber = dsr.GetDSP(15).DataLine.Value;
            hl7info.DriverLicenseNumber  = dsr.GetDSP(16).DataLine.Value;
            hl7info.EthnicGroup          = dsr.GetDSP(17).DataLine.Value;
            hl7info.BirthPlace           = dsr.GetDSP(18).DataLine.Value;
            hl7info.Nationality          = dsr.GetDSP(19).DataLine.Value;
            hl7info.BarCode              = dsr.GetDSP(20).DataLine.Value;
            hl7info.SampleID             = dsr.GetDSP(21).DataLine.Value;
            try
            {
                hl7info.SampleTime = DateTime.ParseExact(dsr.GetDSP(22).DataLine.Value, "yyyyMMddHHmmss", System.Globalization.CultureInfo.CurrentCulture);
            }
            catch
            {
                hl7info.SampleTime = GlobalVariable.DefalutTime;
            }
            hl7info.IsEmergency      = dsr.GetDSP(23).DataLine.Value == null ? "N" : dsr.GetDSP(23).DataLine.Value;
            hl7info.CollcetionVolume = dsr.GetDSP(24).DataLine.Value;
            hl7info.SampleType       = dsr.GetDSP(25).DataLine.Value;
            hl7info.SampleType       = null;
            hl7info.FetchDoctor      = dsr.GetDSP(26).DataLine.Value;
            hl7info.FetchDepartment  = dsr.GetDSP(27).DataLine.Value;
            hl7info.Device           = dsr.MSH.ReceivingFacility.NamespaceID.Value;
            hl7info.ExtraInfo        = new List <HL7Manager.HL7ExtraInfo>();
            for (int num = 28; (dsr.DSPRepetitionsUsed > 28) && (num < dsr.DSPRepetitionsUsed); ++num)
            {
                HL7Manager.HL7ExtraInfo temp = new HL7Manager.HL7ExtraInfo();
                string   tempString          = dsr.GetDSP(num).DataLine.Value;
                string[] split = tempString.Split(new char[] { '^' });
                temp.TextID   = split[0];
                temp.TextName = split[1];
                temp.Unit     = split[2];
                temp.Normal   = split[3];
                hl7info.ExtraInfo.Add(temp);
            }
            #endregion

            return(hl7info);
        }
Example #3
0
        private void sendSocket()
        {
            string     HL7Message = string.Empty;
            string     receiveString;
            PipeParser parser;
            IMessage   m;
            int        SendNum = 0;

            log.Info("HL7 send socket start.");
            while (!ProcessHL7Cancel.IsCancellationRequested && GlobalVariable.IsSocketRun)
            {
                if (hl7Manager.IsHL7Available)
                {
                    #region 向HL7发送样本测试结果
                    if (SendNum == GlobalVariable.ReSendNum)
                    {
                        //连续发送失败超过规定次数,不再发送
                        hl7Manager.RemoveHL7();//移除队列中开始处的HL7
                        SendNum = 0;
                        continue;
                    }
                    Statusbar.SBar.SoftStatus = GlobalVariable.miniBusy;// mini mode
                    try
                    {
                        HL7Message = hl7Manager.GetHL7Message();
                        Connect.sendSocket(HL7Message);
                        log.Info("HL7 send" + hl7Manager.GetHL7Sample_ID());
                        if (SendNum == 0)
                        {
                            ++Statusbar.SBar.SendNum;
                        }
                        ++SendNum;
                    }
                    catch
                    {
                        Statusbar.SBar.SoftStatus = GlobalVariable.miniError;// mini mode
                        ProcessHL7Message.Invoke(hl7Manager.GetHL7Sample_ID() + "Lis服务器发送失败\r\n请重新打开软件\r\n", "LIS");
                        break;
                    }
                    if (!GlobalVariable.IsOneWay)//双向
                    {
                        receiveString = Connect.receiveSocket();
                        if (receiveString.Substring(0, 3) == "MSH")//相当于一个判断
                        {
                            parser = new PipeParser();
                            m      = parser.Parse(receiveString);
                            ACK ack = m as ACK;
                            if (ack.MSA.AcknowledgementCode.Value == "AA")
                            {
                                ProcessHL7Message.Invoke(hl7Manager.GetHL7Sample_ID() + "Lis服务器接收成功\r\n", "LIS");
                                log.Info("LIS receive success" + hl7Manager.GetHL7Sample_ID());
                                Statusbar.SBar.SoftStatus = GlobalVariable.miniWaiting;   // mini mode
                                Statusbar.SBar.SampleId   = hl7Manager.GetHL7Sample_ID(); //mini mode
                                ++Statusbar.SBar.ReplyNum;
                                SendNum = 0;
                                UpdateDB.Invoke(hl7Manager.GetHL7Sample_ID(), hl7Manager.GetHL7Item(), hl7Manager.GetHL7Device(), hl7Manager.GetHL7Sample_SendTime());
                                hl7Manager.RemoveHL7();//移除队列中开始处的HL7
                            }
                            else
                            {
                                Statusbar.SBar.SoftStatus = GlobalVariable.miniError;// mini mode
                                ProcessHL7Message.Invoke(hl7Manager.GetHL7Sample_ID() + "Lis服务器第" + SendNum.ToString() + "次接收失败\r\n", "LIS");
                                log.Info("LIS " + SendNum + " receive fail");
                            }
                        }
                        else
                        {
                            //接收异常
                            Statusbar.SBar.SoftStatus = GlobalVariable.miniError;// mini mode
                            ProcessHL7Message.Invoke(hl7Manager.GetHL7Sample_ID() + "Lis服务器第" + SendNum.ToString() + "次接收失败\r\n", "LIS");
                            log.Info("LIS " + SendNum + " receive fail");
                        }
                    }
                    else//单向
                    {
                        Statusbar.SBar.SoftStatus = GlobalVariable.miniWaiting;// mini mode
                        Statusbar.SBar.SampleId   = hl7Manager.GetHL7Sample_ID();//mini mode

                        ProcessHL7Message.Invoke(hl7Manager.GetHL7Sample_ID() + "Lis服务器发送成功\r\n", "LIS");
                        log.Info("LIS receive success" + hl7Manager.GetHL7Sample_ID());
                        UpdateDB.Invoke(hl7Manager.GetHL7Sample_ID(), hl7Manager.GetHL7Item(), hl7Manager.GetHL7Device(), hl7Manager.GetHL7Sample_SendTime()); //直接回调
                        hl7Manager.RemoveHL7();                                                                                                                //移除队列中开始处的HL7
                    }
                    #endregion
                }
                else if (hl7Manager.IsHL7RequestSampleDataAvailable)
                {
                    #region 向LIS请求样本信息
                    Statusbar.SBar.SoftStatus = GlobalVariable.miniBusy;// mini mode
                    string HL7Apply;
                    //申请信息发送
                    try
                    {
                        HL7Apply = hl7Manager.GetHL7RequestSampleDataMessage();
                        Connect.sendSocket(HL7Apply);
                        ++Statusbar.SBar.SendNum;
                    }
                    catch
                    {
                        Statusbar.SBar.SoftStatus = GlobalVariable.miniError;// mini mode
                        ProcessHL7Message.Invoke(hl7Manager.GetHL7Sample_ID() + "Lis服务器发送失败\r\n请重新打开软件\r\n", "LIS");
                        break;
                    }
                    receiveString = Connect.receiveSocket();
                    if (receiveString.Substring(0, 3) == "MSH")
                    {
                        //传回为标准消息
                        parser = new PipeParser();
                        m      = parser.Parse(receiveString);
                        QCK_Q02 qck = m as QCK_Q02;
                        if (qck.QAK.QueryResponseStatus.Value == "OK")//代表有样本数据
                        {
                            string receiveStringDSR;
                            int    DSRIndex = receiveString.IndexOf("DSR");
                            if (DSRIndex == -1)                             //如果刚才接收过来的没有DSR数据
                            {
                                receiveStringDSR = Connect.receiveSocket(); //重新来接受DSR数据
                            }
                            else
                            {
                                receiveStringDSR = receiveString.Substring(DSRIndex);//截取后面一部分得为DSR数据
                            }
                            //解析DSR
                            //解析完DSR数据就要回复ACKQ03消息,此时设备信息传出去
                            PipeParser parserDSR = new PipeParser();
                            IMessage   mDSR      = parserDSR.Parse(receiveStringDSR);
                            DSR_Q03    dsr       = mDSR as DSR_Q03;
                            if (dsr.QAK.QueryResponseStatus.Value == "OK") //相当于再做了一层判断
                            {
                                HL7Manager.HL7SampleInfo hl7info = HL7_ParserSampleInfo(receiveStringDSR);
                                //接收成功后就要发送应答信号
                                RequestSampleData.BeginInvoke(hl7info, null, null);
                                Connect.sendSocket(CreatACKQ03(dsr.MSH.ReceivingFacility.NamespaceID.Value));
                                Statusbar.SBar.SoftStatus = GlobalVariable.miniWaiting;                    // mini mode
                                Statusbar.SBar.SampleId   = hl7Manager.GetHL7RequestSampleDataSample_ID(); //mini mode
                                ProcessHL7Message.Invoke(hl7Manager.GetHL7RequestSampleDataSample_ID() + "LIS服务器申请样本成功\r\n", "LIS");
                                log.Info("Lis request sample success " + hl7Manager.GetHL7RequestSampleDataSample_ID());
                            }
                            else
                            {
                                Statusbar.SBar.SoftStatus = GlobalVariable.miniError;// mini mode
                                ProcessHL7Message.Invoke(hl7Manager.GetHL7RequestSampleDataSample_ID() + "LIS服务器申请样本异常\r\n", "LIS");
                                log.Info("Lis request sample fail " + hl7Manager.GetHL7RequestSampleDataSample_ID());
                            }
                        }
                        else if (qck.QAK.QueryResponseStatus.Value == "NF")//代表没有样本数据
                        {
                            //此时不再回复消息
                            //结束
                            Statusbar.SBar.SoftStatus = GlobalVariable.miniError;// mini mode
                            ProcessHL7Message.Invoke(hl7Manager.GetHL7RequestSampleDataSample_ID() + "LIS服务器无相关样本信息\r\n", "LIS");
                            log.Info("Lis no request sample " + hl7Manager.GetHL7RequestSampleDataSample_ID());
                        }
                    }
                    #endregion
                    hl7Manager.RemoveHL7RequestSampleData();//移除掉队列中的申请信息
                }
                else
                {
                    #region LIS主动发送样本信息
                    //hl7Manager.HL7Signal.Reset();
                    //持续监听LIS服务器
                    receiveString = Connect.receiveSocket();
                    if (receiveString.Length > 10 && receiveString.Substring(0, 3) == "MSH")
                    {
                        //传回来为标准信息
                        hl7Manager.AddHL7ApplySample(receiveString); //扔给队列交给线程处理
                        hl7Manager.HL7ApplySampleSignal.Set();       //唤醒线程
                    }
                    #endregion
                }
            }
        }