コード例 #1
0
        private bool WriteHL7v2XmlLMessage(HYS.IM.Messaging.Objects.Message msg)
        {
            try
            {
                string hl7Msg = string.Empty;
                if (_transformer.TransformXmlToHL7v2(msg.Body, out hl7Msg))
                {
                    _context.Log.Write("Transform xml to hl7 v2 text success.");
                }
                else
                {
                    _context.Log.Write("Transform xml to hl7 v2 text failure.");
                    return(false);
                }

                string relativePath = PathHelper.GetRelativePathByMode(_context.ConfigMgr.Config.OrganizationMode);
                string filePath     = _context.ConfigMgr.Config.OutputFileFolder;
                if (!string.IsNullOrEmpty(relativePath))
                {
                    filePath = Path.Combine(filePath, relativePath);
                }
                filePath = Path.Combine(filePath, msg.Header.ID.ToString() + _context.ConfigMgr.Config.FileExtension);

                FileHelper.WriteFile(filePath, hl7Msg, _context.ConfigMgr.Config.CodePageName);
                _context.Log.Write(string.Format("Write message to file {0} success.", filePath));
                return(true);
            }
            catch (Exception err)
            {
                _context.Log.Write(err);
                return(false);
            }
        }
コード例 #2
0
        public bool SendHL7v2XMLNotification(string hl7xml)
        {
            bool res = false;

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

            string hl7text = "";

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

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

            res = SendMLLPNotification(hl7text.Replace("\r\n", "\r"));
            return(res);
        }
コード例 #3
0
        private void buttonXMLtoHL7_Click(object sender, EventArgs e)
        {
            if (this.comboBoxType.SelectedItem == null)
            {
                return;
            }
            string type = this.comboBoxType.SelectedItem.ToString();

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

            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.TransformXmlToHL7v2(xmlMsg, out hl7Msg);
                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.labelPerformXMLtoHL7.Text = ((double)(totalTime / (double)tsList.Count)).ToString() + "ms";
            }
            else
            {
                this.labelPerformXMLtoHL7.Text = "error";
            }

            this.textBoxTransHL7Msg.Text = hl7Msg;
        }
コード例 #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);
            }
        }