コード例 #1
0
        /// <summary>
        /// this is just to re-encode xml format message into hl7 to ceck if the XML is correct or not.
        /// </summary>
        /// <param name="xmlMEssage"></param>
        void testFunction(XmlDocument xmlMEssage)
        {
            NHapi.Model.V23.Message.ORU_R01 orm;
            //  orm = imess as NHapi.Model.V23.Message.ORU_R01;

            NHapi.Base.Parser.DefaultXMLParser dfx = new NHapi.Base.Parser.DefaultXMLParser();
            orm = dfx.ParseDocument(xmlMEssage, "2.3") as NHapi.Model.V23.Message.ORU_R01;

            NHapi.Base.Parser.PipeParser pp = new NHapi.Base.Parser.PipeParser();
            string s = pp.Encode(orm);
        }
コード例 #2
0
ファイル: TcpTransport.cs プロジェクト: santedb/santedb-hl7
        /// <summary>
        /// Receive and process message
        /// </summary>
        private void ReceiveMessage(object client)
        {
            TcpClient     tcpClient = client as TcpClient;
            NetworkStream stream    = tcpClient.GetStream();

            try
            {
                // Now read to a string
                NHapi.Base.Parser.PipeParser parser = new NHapi.Base.Parser.PipeParser();

                StringBuilder messageData = new StringBuilder();
                byte[]        buffer      = new byte[1024];
                while (stream.DataAvailable)
                {
                    int br = stream.Read(buffer, 0, 1024);
                    messageData.Append(Encoding.ASCII.GetString(buffer, 0, br));
                }

                var message        = parser.Parse(messageData.ToString());
                var localEp        = tcpClient.Client.LocalEndPoint as IPEndPoint;
                var remoteEp       = tcpClient.Client.RemoteEndPoint as IPEndPoint;
                Uri localEndpoint  = new Uri(String.Format("tcp://{0}:{1}", localEp.Address, localEp.Port));
                Uri remoteEndpoint = new Uri(String.Format("tcp://{0}:{1}", remoteEp.Address, remoteEp.Port));
                var messageArgs    = new Hl7MessageReceivedEventArgs(message, localEndpoint, remoteEndpoint, DateTime.Now);
                HL7OperationContext.Current = new HL7OperationContext(messageArgs);

                this.MessageReceived(this, messageArgs);

                // Send the response back
                StreamWriter writer = new StreamWriter(stream);
                if (messageArgs.Response != null)
                {
                    writer.Write(parser.Encode(messageArgs.Response));
                    writer.Flush();
                }
            }
            catch (Exception e)
            {
                this.m_traceSource.TraceEvent(EventLevel.Error, e.ToString());
                // TODO: NACK
            }
            finally
            {
                stream.Close();
                HL7OperationContext.Current = null;
            }
        }
コード例 #3
0
        /// <summary>
        /// Receive a message
        /// </summary>
        protected override void OnReceiveMessage(object client)
        {
            TcpClient tcpClient = client as TcpClient;
            SslStream stream    = new SslStream(tcpClient.GetStream(), false, new RemoteCertificateValidationCallback(RemoteCertificateValidation));

            try
            {
                // Setup local and remote receive endpoint data for auditing
                var localEp        = tcpClient.Client.LocalEndPoint as IPEndPoint;
                var remoteEp       = tcpClient.Client.RemoteEndPoint as IPEndPoint;
                Uri localEndpoint  = new Uri(String.Format("sllp://{0}:{1}", localEp.Address, localEp.Port));
                Uri remoteEndpoint = new Uri(String.Format("sllp://{0}:{1}", remoteEp.Address, remoteEp.Port));
                Trace.TraceInformation("Accepted TCP connection from {0} > {1}", remoteEndpoint, localEndpoint);

                stream.AuthenticateAsServer(this.m_configuration.ServerCertificate, this.m_configuration.EnableClientCertNegotiation, System.Security.Authentication.SslProtocols.Tls, this.m_configuration.CheckCrl);

                // Now read to a string
                NHapi.Base.Parser.PipeParser parser = new NHapi.Base.Parser.PipeParser();

                DateTime lastReceive = DateTime.Now;

                while (this.m_timeout == TimeSpan.Zero || DateTime.Now.Subtract(lastReceive) < this.m_timeout)
                {
                    int llpByte = 0;
                    // Read LLP head byte
                    try
                    {
                        llpByte = stream.ReadByte();
                    }
                    catch (SocketException)
                    {
                        break;
                    }

                    if (llpByte != START_TX) // first byte must be HT
                    {
                        Trace.TraceWarning("Invalid LLP First Byte expected 0x{0:x} got 0x{1:x} from {2}", START_TX, llpByte, remoteEndpoint);
                        break;
                    }
//                        throw new InvalidOperationException("Invalid LLP First Byte");

                    // Standard stream stuff, read until the stream is exhausted
                    StringBuilder messageData = new StringBuilder();
                    byte[]        buffer = new byte[1024];
                    bool          receivedEOF = false, scanForCr = false;

                    while (!receivedEOF)
                    {
                        int br = stream.Read(buffer, 0, 1024);
                        messageData.Append(System.Text.Encoding.UTF8.GetString(buffer, 0, br));

                        // Need to check for CR?
                        if (scanForCr)
                        {
                            receivedEOF = buffer[0] == END_TXNL;
                        }
                        else
                        {
                            // Look for FS
                            int fsPos = Array.IndexOf(buffer, END_TX);

                            if (fsPos == -1) // not found
                            {
                                continue;
                            }
                            else if (fsPos < buffer.Length - 1) // more room to read
                            {
                                receivedEOF = buffer[fsPos + 1] == END_TXNL;
                            }
                            else
                            {
                                scanForCr = true; // Cannot check the end of message for CR because there is no more room in the message buffer
                            }
                            // so need to check on the next loop
                        }

                        // TODO: Timeout for this
                    }


                    // Use the nHAPI parser to process the data
                    Hl7MessageReceivedEventArgs messageArgs = null;
                    try
                    {
                        var message = parser.Parse(messageData.ToString());

#if DEBUG
                        Trace.TraceInformation("Received message from sllp://{0} : {1}", tcpClient.Client.RemoteEndPoint, messageData.ToString());
#endif


                        messageArgs = new Hl7MessageReceivedEventArgs(message, localEndpoint, remoteEndpoint, DateTime.Now);

                        // Call any bound event handlers that there is a message available
                        OnMessageReceived(messageArgs);
                    }
                    finally
                    {
                        // Send the response back
                        using (MemoryStream memoryWriter = new MemoryStream())
                        {
                            using (StreamWriter streamWriter = new StreamWriter(memoryWriter))
                            {
                                memoryWriter.Write(new byte[] { START_TX }, 0, 1); // header
                                if (messageArgs != null && messageArgs.Response != null)
                                {
                                    var strMessage = parser.Encode(messageArgs.Response);
#if DEBUG
                                    Trace.TraceInformation("Sending message to sllp://{0} : {1}", tcpClient.Client.RemoteEndPoint, strMessage);
#endif
                                    // Since nHAPI only emits a string we just send that along the stream
                                    streamWriter.Write(strMessage);
                                    streamWriter.Flush();
                                }
                                memoryWriter.Write(new byte[] { END_TX, END_TXNL }, 0, 2); // Finish the stream with FSCR
                                stream.Write(memoryWriter.ToArray(), 0, (int)memoryWriter.Position);
                                stream.Flush();
                            }
                        }

                        lastReceive = DateTime.Now; // Update the last receive time so the timeout function works
                    }

                    if (this.m_timeout == TimeSpan.Zero)
                    {
                        break;
                    }
                }
            }
            catch (AuthenticationException e)
            {
                // Trace authentication error
                AuditData ad = new AuditData(
                    DateTime.Now,
                    ActionType.Execute,
                    OutcomeIndicator.MinorFail,
                    EventIdentifierType.ApplicationActivity,
                    new CodeValue("110113", "DCM")
                {
                    DisplayName = "Security Alert"
                }
                    );
                ad.Actors = new List <AuditActorData>()
                {
                    new AuditActorData()
                    {
                        NetworkAccessPointId   = Dns.GetHostName(),
                        NetworkAccessPointType = SVC.Core.DataTypes.NetworkAccessPointType.MachineName,
                        UserName        = Environment.UserName,
                        UserIsRequestor = false
                    },
                    new AuditActorData()
                    {
                        NetworkAccessPointId   = String.Format("sllp://{0}", tcpClient.Client.RemoteEndPoint.ToString()),
                        NetworkAccessPointType = NetworkAccessPointType.MachineName,
                        UserIsRequestor        = true
                    }
                };
                ad.AuditableObjects = new List <AuditableObject>()
                {
                    new AuditableObject()
                    {
                        Type       = AuditableObjectType.SystemObject,
                        Role       = AuditableObjectRole.SecurityResource,
                        IDTypeCode = AuditableObjectIdType.Uri,
                        ObjectId   = String.Format("sllp://{0}", this.m_listener.LocalEndpoint)
                    }
                };

                var auditService = ApplicationContext.CurrentContext.GetService(typeof(IAuditorService)) as IAuditorService;
                if (auditService != null)
                {
                    auditService.SendAudit(ad);
                }
                Trace.TraceError(e.ToString());
            }
            catch (Exception e)
            {
                Trace.TraceError(e.ToString());
                // TODO: NACK
            }
            finally
            {
                stream.Close();
                tcpClient.Close();
            }
        }
コード例 #4
0
        /// <summary>
        /// Receive and process message
        /// </summary>
        protected virtual void OnReceiveMessage(object client)
        {
            TcpClient     tcpClient = client as TcpClient;
            NetworkStream stream    = tcpClient.GetStream();

            try
            {
                // Now read to a string
                NHapi.Base.Parser.PipeParser parser = new NHapi.Base.Parser.PipeParser();

                DateTime lastReceive = DateTime.Now;

                while (DateTime.Now.Subtract(lastReceive) < this.m_timeout)
                {
                    if (!stream.DataAvailable)
                    {
                        Thread.Sleep(10);
                        continue;
                    }

                    // Read LLP head byte
                    int llpByte = stream.ReadByte();
                    if (llpByte != START_TX)                     // first byte must be HT
                    {
                        throw new InvalidOperationException("Invalid LLP First Byte");
                    }

                    // Standard stream stuff, read until the stream is exhausted
                    StringBuilder messageData = new StringBuilder();
                    byte[]        buffer = new byte[1024];
                    bool          receivedEOF = false, scanForCr = false;

                    while (!receivedEOF)
                    {
                        if (DateTime.Now.Subtract(lastReceive) > this.m_timeout)
                        {
                            throw new TimeoutException("Data not received in the specified amount of time. Increase the timeout or check the network connection");
                        }

                        if (!stream.DataAvailable)
                        {
                            Thread.Sleep(10);
                            continue;
                        }

                        int br = stream.Read(buffer, 0, 1024);
                        messageData.Append(System.Text.Encoding.UTF8.GetString(buffer, 0, br));

                        // Need to check for CR?
                        if (scanForCr)
                        {
                            receivedEOF = buffer[0] == END_TXNL;
                        }
                        else
                        {
                            // Look for FS
                            int fsPos = Array.IndexOf(buffer, (byte)END_TX);

                            if (fsPos == -1)                             // not found
                            {
                                continue;
                            }
                            else if (fsPos < buffer.Length - 1)                             // more room to read
                            {
                                receivedEOF = buffer[fsPos + 1] == END_TXNL;
                            }
                            else
                            {
                                scanForCr = true;                                 // Cannot check the end of message for CR because there is no more room in the message buffer
                            }
                            // so need to check on the next loop
                        }
                    }

                    // Use the nHAPI parser to process the data
                    Hl7MessageReceivedEventArgs messageArgs = null;

                    try
                    {
                        // Setup local and remote receive endpoint data for auditing
                        var localEp        = tcpClient.Client.LocalEndPoint as IPEndPoint;
                        var remoteEp       = tcpClient.Client.RemoteEndPoint as IPEndPoint;
                        Uri localEndpoint  = new Uri(String.Format("llp://{0}:{1}", localEp.Address, localEp.Port));
                        Uri remoteEndpoint = new Uri(String.Format("llp://{0}:{1}", remoteEp.Address, remoteEp.Port));

#if DEBUG
                        Trace.TraceInformation("Received message from llp://{0}:{1} : {2}", remoteEp.Address, remoteEp.Port, messageData);
#endif

                        // HACK: nHAPI doesn't like URLs ... Will fix this later
                        string messageString = messageData.ToString().Replace("|URL|", "|ST|");
                        var    message       = parser.Parse(messageString);
                        messageArgs = new Hl7MessageReceivedEventArgs(message, localEndpoint, remoteEndpoint, DateTime.Now);

                        // Call any bound event handlers that there is a message available
                        OnMessageReceived(messageArgs);
                    }
                    finally
                    {
                        // Send the response back
                        using (MemoryStream memoryWriter = new MemoryStream())
                        {
                            using (StreamWriter streamWriter = new StreamWriter(memoryWriter))
                            {
                                memoryWriter.Write(new byte[] { START_TX }, 0, 1);                                 // header
                                if (messageArgs != null && messageArgs.Response != null)
                                {
                                    var strMessage = parser.Encode(messageArgs.Response);
#if DEBUG
                                    Trace.TraceInformation("Sending message to llp://{0} : {1}", tcpClient.Client.RemoteEndPoint, strMessage);
#endif
                                    // Since nHAPI only emits a string we just send that along the stream
                                    streamWriter.Write(strMessage);
                                    streamWriter.Flush();
                                }
                                memoryWriter.Write(new byte[] { END_TX, END_TXNL }, 0, 2);                                 // Finish the stream with FSCR
                                stream.Write(memoryWriter.ToArray(), 0, (int)memoryWriter.Position);
                                stream.Flush();
                            }
                        }
                        lastReceive = DateTime.Now;                         // Update the last receive time so the timeout function works
                    }
                }
            }
            catch (Exception e)
            {
                Trace.TraceError(e.ToString());
            }
            finally
            {
                stream.Close();
                tcpClient.Close();
            }
        }
コード例 #5
0
 /// <summary>
 /// Create a message stream
 /// </summary>
 private System.IO.Stream CreateMessageStream(NHapi.Base.Model.IMessage msg)
 {
     NHapi.Base.Parser.PipeParser pp = new NHapi.Base.Parser.PipeParser();
     return(new MemoryStream(Encoding.ASCII.GetBytes(pp.Encode(msg))));
 }
コード例 #6
0
        /// <summary>
        /// 确定手术安排
        /// </summary>
        /// <param name="patid"></param>
        /// <returns></returns>
        private string AppendHL7stringConfig(string patid)
        {
            ORM_O01   orm       = new ORM_O01();
            DataTable dtResult  = dal.GetPaiban(patid);
            DataRow   dr        = dtResult.Rows[0];
            int       ostateNum = UserFunction.ToInt32(dr["Ostate"].ToString());

            LogHelp.SaveLogHL7("状态" + dr["Ostate"].ToString());
            string SCH_1 = "";

            #region 组装消息头
            SCH_1 = "确定手术安排";
            orm.MSH.MessageType.TriggerEvent.Value     = "S18";
            orm.MSH.MessageType.MessageStructure.Value = "SIU_S12";
            //if (ostateNum == 0)
            //{
            //    SCH_1 = "确定手术安排";
            //    orm.MSH.MessageType.TriggerEvent.Value = "S18";
            //    orm.MSH.MessageType.MessageStructure.Value = "SIU_S12";
            //}
            //else
            //{
            //    SCH_1 = "修改手术安排";
            //    orm.MSH.MessageType.TriggerEvent.Value = "S19";
            //    orm.MSH.MessageType.MessageStructure.Value = "SIU_S12";
            //}


            orm.MSH.MessageType.MessageType.Value = "SIU";

            orm.MSH.FieldSeparator.Value = MessageConstant.FieldSeparator;
            orm.MSH.SendingApplication.NamespaceID.Value   = "SSMZ1";
            orm.MSH.SendingFacility.NamespaceID.Value      = "SSMZ1";
            orm.MSH.ReceivingApplication.NamespaceID.Value = "MediII";
            orm.MSH.ReceivingFacility.NamespaceID.Value    = "MediII";
            orm.MSH.EncodingCharacters.Value  = MessageConstant.EncodingCharacters;
            orm.MSH.VersionID.VersionID.Value = MessageConstant.VersionID;
            orm.MSH.DateTimeOfMessage.TimeOfAnEvent.SetLongDateWithSecond(DateTime.Now);
            orm.MSH.MessageControlID.Value          = MediII.Common.GUIDHelper.NewGUID();
            orm.MSH.ProcessingID.ProcessingID.Value = MessageConstant.ProcessingID;

            #endregion

            int Jieguo = dal.UpdatePaibanConfig(patid);//修改成 已排班

            #region SCH|
            String SCH = "SCH||||||^" + SCH_1 + "^^^原因" + "|||||";
            SCH += "^^^" + Convert.ToDateTime(dr["odate"]).AddDays(-1).ToString("yyyyMMdd") + DateTime.Now.ToString("HHmmss") + "|||||";
            SCH += "SZ1168^^缪兰芬" + "|||";
            SCH += "^^^^^^^^" + dr["patdpm"].ToString() + "|";
            SCH += "SZ1168^^缪兰芬" + "||||||";
            SCH += dr["patid"].ToString() + "\n";
            #endregion

            String PID = dr["PidInfo"].ToString();

            String PV1 = dr["Pv1Info"].ToString();
            #region RGS|
            String RGS = "RGS|1" + "\n";
            #endregion

            #region AIS|
            String AIS = "AIS|1||";
            AIS += dr["OperNo"].ToString() + "^" + dr["Oname"].ToString() + "|||||||";
            AIS += dr["Oroom"].ToString() + "^^^" + dr["Second"].ToString() + "|" + "\n";
            #endregion



            #region 手术医生
            String AIP = "AIP|1||";
            AIP += dr["OsNo"].ToString() + "^" + dr["OS"].ToString() + "|主刀医生" + "\n";
            #endregion

            #region 护士
            DataTable dt     = dal.GetUserNoByName(dr["SN1"].ToString());
            string    UserNO = " ";
            if (dt.Rows.Count > 0)
            {
                UserNO = dt.Rows[0][0].ToString();
            }
            AIP += "AIP|2||";
            AIP += UserNO + "^" + dr["SN1"].ToString() + "|4^洗手护士" + "\n";

            dt     = dal.GetUserNoByName(dr["SN2"].ToString());
            UserNO = " ";
            if (dt.Rows.Count > 0)
            {
                UserNO = dt.Rows[0][0].ToString();
            }
            AIP += "AIP|3||";
            AIP += UserNO + "^" + dr["SN2"].ToString() + "|4^洗手护士" + "\n";

            dt     = dal.GetUserNoByName(dr["ON1"].ToString());
            UserNO = " ";
            if (dt.Rows.Count > 0)
            {
                UserNO = dt.Rows[0][0].ToString();
            }
            AIP += "AIP|4||";
            AIP += UserNO + "^" + dr["ON1"].ToString() + "|5^巡回护士" + "\n";

            dt     = dal.GetUserNoByName(dr["ON2"].ToString());
            UserNO = " ";
            if (dt.Rows.Count > 0)
            {
                UserNO = dt.Rows[0][0].ToString();
            }
            AIP += "AIP|5||";
            AIP += UserNO + "^" + dr["ON2"].ToString() + "|5^巡回护士" + "\n";

            dt     = dal.GetUserNoByName(dr["ON3"].ToString());
            UserNO = " ";
            if (dt.Rows.Count > 0)
            {
                UserNO = dt.Rows[0][0].ToString();
            }
            AIP += "AIP|6||";
            AIP += UserNO + "^" + dr["ON3"].ToString() + "|5^巡回护士" + "\n";
            #endregion

            #region 手术助手
            AIP += "AIP|7||";
            AIP += dr["OA1No"].ToString() + "^" + dr["OA1"].ToString() + "|2^助理医生" + "\n";
            AIP += "AIP|8||";
            AIP += dr["OA2No"].ToString() + "^" + dr["OA2"].ToString() + "|2^助理医生" + "\n";
            AIP += "AIP|9||";
            AIP += dr["OA3No"].ToString() + "^" + dr["OA3"].ToString() + "|2^助理医生" + "\n";
            #endregion
            #region 麻醉医生
            dt     = dal.GetUserNoByName(dr["AP1"].ToString());
            UserNO = " ";
            if (dt.Rows.Count > 0)
            {
                UserNO = dt.Rows[0][0].ToString();
            }
            AIP   += "AIP|11||";
            AIP   += UserNO + "^" + dr["AP1"].ToString() + "|麻醉医师" + "\n";
            dt     = dal.GetUserNoByName(dr["AP2"].ToString());
            UserNO = " ";
            if (dt.Rows.Count > 0)
            {
                UserNO = dt.Rows[0][0].ToString();
            }
            AIP   += "AIP|12||";
            AIP   += UserNO + "^" + dr["AP2"].ToString() + "|麻醉医师" + "\n";
            dt     = dal.GetUserNoByName(dr["AP3"].ToString());
            UserNO = " ";
            if (dt.Rows.Count > 0)
            {
                UserNO = dt.Rows[0][0].ToString();
            }
            AIP += "AIP|13||";
            AIP += UserNO + "^" + dr["AP3"].ToString() + "|麻醉医师" + "\n";
            #endregion



            #region 转换消息对象为字符串
            String hl7Message = SCH + PID + PV1 + RGS + AIS + AIP;
            NHapi.Base.Parser.PipeParser parser = new NHapi.Base.Parser.PipeParser();
            string message = parser.Encode(orm) + hl7Message;
            return(message);

            #endregion
        }
コード例 #7
0
        /// <summary>
        /// 确定手术安排
        /// </summary>
        /// <param name="id"></param>
        /// <param name="userName">用户名</param>
        /// <param name="uid">用户ID</param>
        /// <returns></returns>
        public static string AppendHL7stringConfig(int id, string userName, string uid)
        {
            ORM_O01 orm       = new ORM_O01();
            var     paiban    = dal.GetPaiban(id);
            int     ostateNum = paiban.Ostate.ToInt32();

            LogHelp.SaveLogHL7("状态" + ostateNum.ToString());
            string SCH_1 = "";

            #region 组装消息头
            if (paiban.IsSend == 0)
            {
                SCH_1 = "确定手术安排";
                orm.MSH.MessageType.TriggerEvent.Value     = "S18";
                orm.MSH.MessageType.MessageStructure.Value = "SIU_S12";
            }
            else
            {
                SCH_1 = "修改手术安排";
                orm.MSH.MessageType.TriggerEvent.Value     = "S19";
                orm.MSH.MessageType.MessageStructure.Value = "SIU_S12";
            }


            orm.MSH.MessageType.MessageType.Value = "SIU";

            orm.MSH.FieldSeparator.Value = MessageConstant.FieldSeparator;
            orm.MSH.SendingApplication.NamespaceID.Value   = "SSMZ";
            orm.MSH.SendingFacility.NamespaceID.Value      = "SSMZ";
            orm.MSH.ReceivingApplication.NamespaceID.Value = "MediII";
            orm.MSH.ReceivingFacility.NamespaceID.Value    = "MediII";
            orm.MSH.EncodingCharacters.Value  = MessageConstant.EncodingCharacters;
            orm.MSH.VersionID.VersionID.Value = MessageConstant.VersionID;
            orm.MSH.DateTimeOfMessage.TimeOfAnEvent.SetLongDateWithSecond(DateTime.Now);
            orm.MSH.MessageControlID.Value          = MediII.Common.GUIDHelper.NewGUID();
            orm.MSH.ProcessingID.ProcessingID.Value = MessageConstant.ProcessingID;

            #endregion

            // int Jieguo = dal.UpdatePaibanConfig(id);//修改成 已排班

            #region SCH|
            String SCH = "SCH||||||^" + SCH_1 + "^^^原因" + "|||||";
            SCH += "^^^" + paiban.Odate.AddDays(-1).ToString("yyyyMMdd") + DateTime.Now.ToString("HHmmss") + "|||||";
            SCH += uid + "^^" + userName + "|||";
            SCH += "^^^^^^^^" + paiban.Patdpm.ToString() + "|";
            SCH += uid + "^^" + userName + "||||||";
            SCH += paiban.ApplyId + "\n";
            #endregion

            string PID = paiban.PidInfo + "\n";
            string PV1 = paiban.Pv1Info + "\n";
            #region RGS|
            String RGS = "RGS|1" + "\n";
            #endregion

            #region AIS|
            String AIS = "AIS|1||";
            AIS += paiban.OperNo + "^" + paiban.Oname + "|||||||";
            AIS += paiban.Oroom + "^^^" + paiban.Second + "|" + "\n";
            #endregion


            #region 手术医生

            String AIP      = "AIP|1||";
            var    listUser = dal.GetUser();
            AIP += paiban.OsNo + "^" + paiban.OS + " |主刀医生" + "\n";

            AIP += "AIP|7||";
            AIP += paiban.Os1No + "^" + paiban.OS1 + "|2^助理医生" + "\n";

            AIP += "AIP|8||";
            AIP += paiban.Os2No + "^" + paiban.OS2 + "|2^助理医生" + "\n";

            AIP += "AIP|9||";
            AIP += paiban.Os3No + "^" + paiban.OS3 + "|2^助理医生" + "\n";
            #endregion

            #region 护士

            string UserNO = string.Empty;
            var    user   = listUser.FirstOrDefault(a => a.User_name == paiban.SN1);
            if (user != null)
            {
                UserNO = user.Uid;
            }
            AIP += "AIP|2||";
            AIP += paiban.SN1No + "^" + paiban.SN1 + "|4^洗手护士" + "\n";

            UserNO = string.Empty;
            user   = listUser.FirstOrDefault(a => a.User_name == paiban.SN2);
            if (user != null)
            {
                UserNO = user.Uid;
            }
            AIP += "AIP|3||";
            AIP += paiban.SN2No + "^" + paiban.SN2 + "|4^洗手护士" + "\n";

            UserNO = string.Empty;
            user   = listUser.FirstOrDefault(a => a.User_name == paiban.ON1);
            if (user != null)
            {
                UserNO = user.Uid;
            }
            AIP   += "AIP|4||";
            AIP   += paiban.ON1No + "^" + paiban.ON1 + "|5^巡回护士" + "\n";
            UserNO = string.Empty;
            user   = listUser.FirstOrDefault(a => a.User_name == paiban.ON2);
            if (user != null)
            {
                UserNO = user.Uid;
            }
            AIP += "AIP|5||";
            AIP += paiban.ON2No + "^" + paiban.ON2 + "|5^巡回护士" + "\n";


            AIP += "AIP|6||";
            AIP += "^" + "" + "|5^巡回护士" + "\n";
            #endregion

            AIP += "AIP|10|||6^体外循环师" + "\n";

            #region 麻醉医生

            UserNO = string.Empty;
            user   = listUser.FirstOrDefault(a => a.User_name == paiban.AP1);
            if (user != null)
            {
                UserNO = user.Uid;
            }
            AIP += "AIP|11||";
            AIP += paiban.AP1No + "^" + paiban.AP1 + "|3^麻醉师" + "\n";

            UserNO = string.Empty;
            user   = listUser.FirstOrDefault(a => a.User_name == paiban.AP2);
            if (user != null)
            {
                UserNO = user.Uid;
            }
            AIP += "AIP|12||";
            AIP += paiban.AP2No + "^" + paiban.AP2 + "|7^助理麻醉师" + "\n";

            UserNO = string.Empty;
            user   = listUser.FirstOrDefault(a => a.User_name == paiban.AP3);
            if (user != null)
            {
                UserNO = user.Uid;
            }
            AIP += "AIP|13||";
            AIP += paiban.AP3No + "^" + paiban.AP3 + "|7^助理麻醉师" + "\n";
            #endregion


            #region 转换消息对象为字符串
            String hl7Message = SCH + PID + PV1 + RGS + AIS + AIP;
            NHapi.Base.Parser.PipeParser parser = new NHapi.Base.Parser.PipeParser();
            string message = parser.Encode(orm) + hl7Message;
            return(message);

            #endregion
        }
コード例 #8
0
        /// <summary>
        /// 手术消息反馈
        /// </summary>
        /// <returns></returns>
        public static string AppendHL7stringOperConfig(string patzhuyuanId, string userNo, string userName)
        {
            ORM_O01 orm = new ORM_O01();

            #region 组装消息头
            orm.MSH.MessageType.MessageType.Value      = "SIU";
            orm.MSH.MessageType.TriggerEvent.Value     = "S21";
            orm.MSH.MessageType.MessageStructure.Value = "SIU_S12";
            orm.MSH.FieldSeparator.Value = MessageConstant.FieldSeparator;
            orm.MSH.SendingApplication.NamespaceID.Value   = "SSMZ";
            orm.MSH.SendingFacility.NamespaceID.Value      = "SSMZ";
            orm.MSH.ReceivingApplication.NamespaceID.Value = "MediII";
            orm.MSH.ReceivingFacility.NamespaceID.Value    = "MediII";
            orm.MSH.EncodingCharacters.Value  = MessageConstant.EncodingCharacters;
            orm.MSH.VersionID.VersionID.Value = MessageConstant.VersionID;
            orm.MSH.DateTimeOfMessage.TimeOfAnEvent.SetLongDateWithSecond(DateTime.Now);
            orm.MSH.MessageControlID.Value          = MediII.Common.GUIDHelper.NewGUID();
            orm.MSH.ProcessingID.ProcessingID.Value = MessageConstant.ProcessingID;

            #endregion

            var mzjldDto = dal.GetPaibanAndMzjld(patzhuyuanId);

            #region SCH|
            String SCH  = "SCH||1||||";
            string mzff = mzjldDto.Amethod;
            //DataTable dtMzff = dal.GetMzffID(mzff);
            string mzff_No = "00";

            SCH += "SSMZ" + "^^^" + mzff_No + "^" + mzff + "|||||";
            SCH += "^^^" + mzjldDto.sskssj.Value.ToString("yyyyMMddHHmmss") + "^" + mzjldDto.ssjssj.Value.ToString("yyyyMMddHHmmss");
            SCH += "~^^^" + mzjldDto.Otime.Value.ToString("yyyyMMddHHmmss") + "^" + DateTime.Now.ToString("yyyyMMddHHmmss") + "|||||";
            SCH += userNo + "^^" + userName + "||||";
            SCH += userNo + "^^" + userName + "||||||";
            SCH += mzjldDto.ApplyId + "\n";
            #endregion

            #region NTE|
            String NTE = "NTE|1|||~" + "\n";
            #endregion


            string PID = mzjldDto.PidInfo + "\n";
            string PV1 = mzjldDto.Pv1Info + "\n";


            string RGS = "RGS|1" + "\n";

            #region AIS|
            String AIS      = "AIS|1||";
            string OperName = mzjldDto.Oname;

            AIS += mzjldDto.Ocode + "^" + mzjldDto.Oname + "|||||||";
            AIS += mzjldDto.Oroom + "^" + mzjldDto.Second + "\n";
            #endregion

            #region 手术医生

            String AIP      = "AIP|1||";
            var    listUser = dal.GetUser();
            AIP += mzjldDto.OsNo + "^" + mzjldDto.OS + " |主刀医生" + "\n";

            AIP += "AIP|7||";
            AIP += mzjldDto.Os1No + "^" + mzjldDto.OS1 + "|2^助理医生" + "\n";

            AIP += "AIP|8||";
            AIP += mzjldDto.Os2No + "^" + mzjldDto.OS2 + "|2^助理医生" + "\n";

            AIP += "AIP|9||";
            AIP += mzjldDto.Os2No + "^" + mzjldDto.OS3 + "|2^助理医生" + "\n";
            #endregion

            #region 护士

            string UserNO = string.Empty;
            var    user   = listUser.FirstOrDefault(a => a.User_name == mzjldDto.SN1);
            if (user != null)
            {
                UserNO = user.Uid;
            }
            AIP += "AIP|2||";
            AIP += mzjldDto.SN1No + "^" + mzjldDto.SN1 + "|4^洗手护士" + "\n";

            UserNO = string.Empty;
            user   = listUser.FirstOrDefault(a => a.User_name == mzjldDto.SN2);
            if (user != null)
            {
                UserNO = user.Uid;
            }
            AIP += "AIP|3||";
            AIP += mzjldDto.SN2No + "^" + mzjldDto.SN2 + "|4^洗手护士" + "\n";

            UserNO = string.Empty;
            user   = listUser.FirstOrDefault(a => a.User_name == mzjldDto.ON1);
            if (user != null)
            {
                UserNO = user.Uid;
            }
            AIP   += "AIP|4||";
            AIP   += mzjldDto.ON1No + "^" + mzjldDto.ON1 + "|5^巡回护士" + "\n";
            UserNO = string.Empty;
            user   = listUser.FirstOrDefault(a => a.User_name == mzjldDto.ON2);
            if (user != null)
            {
                UserNO = user.Uid;
            }
            AIP += "AIP|5||";
            AIP += mzjldDto.ON2No + "^" + mzjldDto.ON2 + "|5^巡回护士" + "\n";


            AIP += "AIP|6||";
            AIP += "^" + "" + "|5^巡回护士" + "\n";
            #endregion

            AIP += "AIP|10|||6^体外循环师" + "\n";

            #region 麻醉医生

            UserNO = string.Empty;
            user   = listUser.FirstOrDefault(a => a.User_name == mzjldDto.AP1);
            if (user != null)
            {
                UserNO = user.Uid;
            }
            AIP += "AIP|11||";
            AIP += mzjldDto.AP1No + "^" + mzjldDto.AP1 + "|3^麻醉师" + "\n";

            UserNO = string.Empty;
            user   = listUser.FirstOrDefault(a => a.User_name == mzjldDto.AP2);
            if (user != null)
            {
                UserNO = user.Uid;
            }
            AIP += "AIP|12||";
            AIP += mzjldDto.AP2No + "^" + mzjldDto.AP2 + "|7^助理麻醉师" + "\n";

            UserNO = string.Empty;
            user   = listUser.FirstOrDefault(a => a.User_name == mzjldDto.AP3);
            if (user != null)
            {
                UserNO = user.Uid;
            }
            AIP += "AIP|13||";
            AIP += mzjldDto.AP3No + "^" + mzjldDto.AP3 + "|7^助理麻醉师" + "\n";
            #endregion



            #region 转换消息对象为字符串
            String hl7Message = SCH + NTE + PID + PV1 + RGS + AIS + AIP;
            NHapi.Base.Parser.PipeParser parser = new NHapi.Base.Parser.PipeParser();
            string message = parser.Encode(orm) + hl7Message;
            return(message);

            #endregion
        }
コード例 #9
0
ファイル: OperConfig.cs プロジェクト: JourneyChen88/SSMZ
        /// <summary>
        /// 手术消息反馈
        /// </summary>
        /// <returns></returns>
        private string AppendHL7stringOperConfig(string patID, string userNo, string userName)
        {
            ORM_O01 orm = new ORM_O01();

            #region 组装消息头
            orm.MSH.MessageType.MessageType.Value      = "SIU";
            orm.MSH.MessageType.TriggerEvent.Value     = "S21";
            orm.MSH.MessageType.MessageStructure.Value = "SIU_S12";
            orm.MSH.FieldSeparator.Value = MessageConstant.FieldSeparator;
            orm.MSH.SendingApplication.NamespaceID.Value   = "SSMZ1";
            orm.MSH.SendingFacility.NamespaceID.Value      = "SSMZ1";
            orm.MSH.ReceivingApplication.NamespaceID.Value = "MediII";
            orm.MSH.ReceivingFacility.NamespaceID.Value    = "MediII";
            orm.MSH.EncodingCharacters.Value  = MessageConstant.EncodingCharacters;
            orm.MSH.VersionID.VersionID.Value = MessageConstant.VersionID;
            orm.MSH.DateTimeOfMessage.TimeOfAnEvent.SetLongDateWithSecond(DateTime.Now);
            orm.MSH.MessageControlID.Value          = MediII.Common.GUIDHelper.NewGUID();
            orm.MSH.ProcessingID.ProcessingID.Value = MessageConstant.ProcessingID;

            #endregion

            DataTable dtResult = dal.GetPaibanAndMZJLD(patID);
            DataRow   dr       = dtResult.Rows[0];

            #region SCH|
            String    SCH     = "SCH||1||||";
            string    mzff    = dr["Amethod"].ToString();
            DataTable dtMzff  = dal.GetMzffID(mzff);
            string    mzff_No = "00";
            if (dtMzff.Rows.Count > 0)
            {
                mzff_No = dtMzff.Rows[0][0].ToString();
            }
            SCH += "SSMZ" + "^^^" + mzff_No + "^" + mzff + "|||||";
            SCH += "^^^" + Convert.ToDateTime(dr["sskssj"]).ToString("yyyyMMddHHmmss") + "^" + Convert.ToDateTime(dr["ssjssj"]).ToString("yyyyMMddHHmmss");
            SCH += "~^^^" + Convert.ToDateTime(dr["otime"]).ToString("yyyyMMddHHmmss") + "^" + DateTime.Now.ToString("yyyyMMddHHmmss") + "|||||";
            SCH += userNo + "^^" + userName + "||||";
            SCH += userNo + "^^" + userName + "||||||";
            SCH += dr["patid"].ToString() + "\n";
            #endregion

            #region NTE|
            String NTE = "NTE|1|||~" + "\n";
            #endregion


            string PID = dr["PidInfo"].ToString();
            string PV1 = dr["Pv1Info"].ToString();


            string RGS = "RGS|1" + "\n";

            #region AIS|
            String    AIS      = "AIS|1||";
            string    OperName = dr["Oname"].ToString();
            DataTable dtSSSS   = dal.GetOperNo(OperName);
            string    OperCode = "00";
            if (dtSSSS.Rows.Count > 0)
            {
                OperCode = dtSSSS.Rows[0]["OperCode"].ToString();
            }
            AIS += OperCode + "^" + OperName + "||||||";
            AIS += dr["GL"].ToString() + "|";
            AIS += dr["Oroom"].ToString() + "^" + dr["Second"].ToString() + "\n";
            #endregion

            #region 手术医生

            String    AIP    = "AIP|1||";
            DataTable dtOsNo = dal.GetShoushuYishengNo(dr["OS"].ToString());
            string    OsNO   = "";
            if (dtOsNo.Rows.Count > 0)
            {
                OsNO = dtOsNo.Rows[0]["nameNo"].ToString();
            }
            AIP += OsNO + "^" + dr["OS"].ToString() + "|主刀医生" + "\n";

            AIP   += "AIP|7||";
            dtOsNo = dal.GetShoushuYishengNo(dr["OA1"].ToString());
            OsNO   = "";
            if (dtOsNo.Rows.Count > 0)
            {
                OsNO = dtOsNo.Rows[0]["nameNo"].ToString();
            }
            AIP += OsNO + "^" + dr["OA1"].ToString() + "|2^助理医生" + "\n";

            AIP   += "AIP|8||";
            dtOsNo = dal.GetShoushuYishengNo(dr["OA2"].ToString());
            OsNO   = "";
            if (dtOsNo.Rows.Count > 0)
            {
                OsNO = dtOsNo.Rows[0]["nameNo"].ToString();
            }
            AIP += OsNO + "^" + dr["OA2"].ToString() + "|2^助理医生" + "\n";

            AIP   += "AIP|9||";
            dtOsNo = dal.GetShoushuYishengNo(dr["OA3"].ToString());
            OsNO   = "";
            if (dtOsNo.Rows.Count > 0)
            {
                OsNO = dtOsNo.Rows[0]["nameNo"].ToString();
            }
            AIP += OsNO + "^" + dr["OA3"].ToString() + "|2^助理医生" + "\n";
            #endregion

            #region 护士
            DataTable dt     = dal.GetUserNoByName(dr["SN1"].ToString());
            string    UserNO = string.Empty;
            if (dt.Rows.Count > 0)
            {
                UserNO = dt.Rows[0][0].ToString();
            }
            AIP   += "AIP|2||";
            AIP   += UserNO + "^" + dr["SN1"].ToString() + "|4^洗手护士" + "\n";
            dt     = dal.GetUserNoByName(dr["SN2"].ToString());
            UserNO = string.Empty;
            if (dt.Rows.Count > 0)
            {
                UserNO = dt.Rows[0][0].ToString();
            }
            AIP   += "AIP|3||";
            AIP   += UserNO + "^" + dr["SN2"].ToString() + "|4^洗手护士" + "\n";
            dt     = dal.GetUserNoByName(dr["ON1"].ToString());
            UserNO = string.Empty;
            if (dt.Rows.Count > 0)
            {
                UserNO = dt.Rows[0][0].ToString();
            }
            AIP   += "AIP|4||";
            AIP   += UserNO + "^" + dr["ON1"].ToString() + "|5^巡回护士" + "\n";
            dt     = dal.GetUserNoByName(dr["ON2"].ToString());
            UserNO = string.Empty;
            if (dt.Rows.Count > 0)
            {
                UserNO = dt.Rows[0][0].ToString();
            }
            AIP += "AIP|5||";
            AIP += UserNO + "^" + dr["ON2"].ToString() + "|5^巡回护士" + "\n";

            dt     = dal.GetUserNoByName(dr["ON3"].ToString());
            UserNO = string.Empty;
            if (dt.Rows.Count > 0)
            {
                UserNO = dt.Rows[0][0].ToString();
            }
            AIP += "AIP|6||";
            AIP += UserNO + "^" + dr["ON3"].ToString() + "|5^巡回护士" + "\n";
            #endregion

            AIP += "AIP|10|||6^体外循环师" + "\n";

            #region 麻醉医生
            dt     = dal.GetUserNoByName(dr["AP1"].ToString());
            UserNO = string.Empty;
            if (dt.Rows.Count > 0)
            {
                UserNO = dt.Rows[0][0].ToString();
            }
            AIP   += "AIP|11||";
            AIP   += UserNO + "^" + dr["AP1"].ToString() + "|3^麻醉师" + "\n";
            dt     = dal.GetUserNoByName(dr["AP2"].ToString());
            UserNO = string.Empty;
            if (dt.Rows.Count > 0)
            {
                UserNO = dt.Rows[0][0].ToString();
            }
            AIP   += "AIP|12||";
            AIP   += UserNO + "^" + dr["AP2"].ToString() + "|7^助理麻醉师" + "\n";
            dt     = dal.GetUserNoByName(dr["AP3"].ToString());
            UserNO = string.Empty;
            if (dt.Rows.Count > 0)
            {
                UserNO = dt.Rows[0][0].ToString();
            }
            AIP += "AIP|13||";
            AIP += UserNO + "^" + dr["AP3"].ToString() + "|7^助理麻醉师" + "\n";
            #endregion



            #region 转换消息对象为字符串
            String hl7Message = SCH + NTE + PID + PV1 + RGS + AIS + AIP;
            NHapi.Base.Parser.PipeParser parser = new NHapi.Base.Parser.PipeParser();
            string message = parser.Encode(orm) + hl7Message;
            return(message);

            #endregion
        }