示例#1
0
        public bool SendHL7v2XMLQuery(string queryXml, out string resultXml)
        {
            resultXml = "";
            bool res = false;

            if (queryXml == null || queryXml.Length < 1)
            {
                return(res);
            }

            string queryText = "";

            _entity.Context.Log.Write("Begin transforming requesting XML to HL7v2.");
            res = _transformer.TransformXmlToHL7v2(queryXml, out queryText);
            _entity.Context.Log.Write(string.Format("End transforming requesting XML to HL7v2. Result: {0}.", res));

            if (!res)
            {
                _entity.Context.Log.Write(LogType.Error, "XML dump:\r\n" + queryXml);
                return(res);
            }

            string resultText = "";

            res = SendMLLPQuery(queryText.Replace("\r\n", "\r"), out resultText);
            if (!res)
            {
                return(res);
            }

            _entity.Context.Log.Write("Begin transforming responsing HL7v2 to XML.");
            res = _transformer.TransformHL7v2ToXml(resultText, out resultXml);
            _entity.Context.Log.Write(string.Format("End transforming responsing HL7v2 to XML. Result: {0}.", res));
            return(res);
        }
示例#2
0
        private void buttonHL7toXML_Click(object sender, EventArgs e)
        {
            if (this.comboBoxType.SelectedItem == null)
            {
                return;
            }
            string type = this.comboBoxType.SelectedItem.ToString();

            int    times  = (int)this.numericUpDownTimes.Value;
            string hl7Msg = this.textBoxHL7Msg.Text.Trim();
            string xmlMsg = "";

            XmlTransformerBase t = XmlTransformerFactory.CreateTransformer(type, _log);

            bool            res    = false;
            List <TimeSpan> tsList = new List <TimeSpan>();

            for (int i = 0; i < times; i++)
            {
                DateTime dtBegin = DateTime.Now;
                res = t.TransformHL7v2ToXml(hl7Msg, out xmlMsg);
                DateTime dtEnd = DateTime.Now;
                if (!res)
                {
                    break;
                }
                tsList.Add(dtEnd.Subtract(dtBegin));
            }

            if (res)
            {
                double totalTime = 0;
                foreach (TimeSpan ts in tsList)
                {
                    totalTime += ts.TotalMilliseconds;
                }
                this.labelPerformHL7toXML.Text = ((double)(totalTime / (double)tsList.Count)).ToString() + "ms";
            }
            else
            {
                this.labelPerformHL7toXML.Text = "error";
            }

            this.textBoxXmlMsg.Text = xmlMsg;
        }
示例#3
0
        private bool ProcessHL7XMLMessage(string filePath, ref string sendData)
        {
            string fileContent = string.Empty;

            if (!ReadFileContent(filePath, ref fileContent))
            {
                return(false);
            }
            string fileName = Path.GetFileName(filePath);
            string strXml   = fileContent;

            if (_transformer.TransformHL7v2ToXml(fileContent, out strXml))
            {
                _publisher.Context.Log.Write(LogType.Debug, "Transformed HL7 xml content is : \r\n" + strXml);
            }
            else
            {
                _publisher.Context.Log.Write(LogType.Error, "Transforming HL7 to xml error.");

                FileHelper.MoveFile(filePath, Path.Combine(_fialedFolder, fileName));
                _publisher.Context.Log.Write(string.Format("Moved file {0}  to {1}", fileName, _fialedFolder));
                return(false);
            }

            bool res = DispatchXMLMessage(strXml);

            if (res)
            {
                sendData = HL7MessageParser.FormatResponseMessage(fileContent,
                                                                  _publisher.Context.ConfigMgr.Config.ReadHL7AckAATemplate());
            }
            else
            {
                sendData = HL7MessageParser.FormatResponseMessage(fileContent,
                                                                  _publisher.Context.ConfigMgr.Config.ReadHL7AckAETemplate());
            }
            return(res);
        }
示例#4
0
        private bool ProcessHL7Message(string receiveData, ref string sendData)
        {
            try
            {
                _entity.Context.Log.Write("Begin processing HL7v2 text message");

                string hl7msgType = HL7MessageParser.GetField(receiveData, "MSH", 9);
                _entity.Context.Log.Write("Dispatching message according to message type: " + hl7msgType);

                if (hl7msgType.IndexOf("QBP") >= 0)
                {
                    Message req = new Message();
                    //req.Header.Type = MessageRegistry.HL7V2_QueryRequestMessageType;
                    req.Header.Type = MessageRegistry.GENERIC_RequestMessageType;
                    HYS.IM.Messaging.Registry.HL7MessageHelper.SetHL7V2PayLoad(req, receiveData);

                    Message rsp;
                    _entity.Context.Log.Write("Begin sending request to responser.");
                    bool ret = _entity.NotifyMessageRequest(req, out rsp);
                    _entity.Context.Log.Write("End sending request to responser. Result: " + ret.ToString());
                    _entity.Context.ConfigMgr.Config.DumpMessage(req, receiveData, false, ret);

                    if (ret)
                    {
                        sendData = HYS.IM.Messaging.Registry.HL7MessageHelper.GetHL7V2PayLoad(rsp);
                        return(true);
                    }
                    else
                    {
                        sendData = "";
                        return(false);
                    }
                }
                else
                {
                    Message notify = new Message();
                    //notify.Header.Type = MessageRegistry.HL7V2_NotificationMessageType;
                    notify.Header.Type = MessageRegistry.GENERIC_NotificationMessageType;
                    HYS.IM.Messaging.Registry.HL7MessageHelper.SetHL7V2PayLoad(notify, receiveData);

                    _entity.Context.Log.Write("Begin sending notification to subscriber.");
                    bool ret = _entity.NotifyMessagePublish(notify);
                    _entity.Context.Log.Write("End sending notification to subscriber. Result: " + ret.ToString());
                    _entity.Context.ConfigMgr.Config.DumpMessage(notify, receiveData, false, ret);

                    //if (ret)
                    //{
                    //    sendData = HL7MessageParser.FormatResponseMessage(receiveData,
                    //        _entity.Context.ConfigMgr.Config.ReadHL7AckAATemplate());
                    //}
                    //else
                    //{
                    //    sendData = HL7MessageParser.FormatResponseMessage(receiveData,
                    //        _entity.Context.ConfigMgr.Config.ReadHL7AckAETemplate());
                    //}

                    string xsltFileName = ret ? HL7InboundConfig.PublishingSuccessXSLTFileName : HL7InboundConfig.PublishingFailureXSLTFileName;
                    string reqXml       = null;
                    string rspXml       = null;
                    sendData = "";
                    ret      = false;

                    if (_transformer.TransformHL7v2ToXml(receiveData, out reqXml))
                    {
                        if (_entity.Context.ConfigMgr.Config.XSLTTransform(reqXml, ref rspXml, xsltFileName,
                                                                           _entity.Context.ConfigMgr.Config.InboundMessageDispatching.GenerateResponseXmlMLLPPayloadWithXSLTExtensions) &&
                            (!string.IsNullOrEmpty(rspXml)))
                        {
                            if (_transformer.TransformXmlToHL7v2(rspXml, out sendData) &&
                                (!string.IsNullOrEmpty(sendData)))
                            {
                                sendData = sendData.Replace("\r\n", "\r");
                                ret      = true;
                            }
                            else
                            {
                                _entity.Context.Log.Write(LogType.Error, "Transform outgoing XML to outgoing HL7v2 text failed.\r\n" + rspXml);
                            }
                        }
                        else
                        {
                            _entity.Context.Log.Write(LogType.Error, "Transform incoming XML to outgoing XML failed.\r\n" + reqXml);
                        }
                    }
                    else
                    {
                        _entity.Context.Log.Write(LogType.Error, "Transform incoming HL7v2 text to incoming XML failed.");
                    }

                    _entity.Context.Log.Write("End processing HL7v2 text message. Result: " + ret.ToString());
                    return(ret);
                }
            }
            catch (Exception err)
            {
                _entity.Context.Log.Write(err);
                return(false);
            }
        }