Hl7使用c#net编程通过lan发送消息

问题描述 投票:-2回答:2

我正在尝试将Hl7管理添加到我们在c#中开发的HIS系统中。

我们已经使用NHAPI创建一条消息,通过局域网从CBC设备获取血液结果。我配置设备(客户端IP 10.10.60.100主机IP 10.10.60.116:5006)并知道如何创建消息及其详细信息,但我需要通过局域网将其发送到设备以通过我的PC收听设备来获得结果。

底线:有人能举例说明如何通过局域网发送Hl7消息并听取结果吗?

c# asp.net hl7
2个回答
0
投票

这里有一些有用的代码:

using System.Net;
using System.IO;
using System.Net.Sockets;
using System.Threading;
using System.Text;

.......
byte[] Combine(byte[] a1, byte[] a2, byte[] a3)
{
    byte[] ret = new byte[a1.Length + a2.Length + a3.Length];
    Array.Copy(a1, 0, ret, 0, a1.Length);
    Array.Copy(a2, 0, ret, a1.Length, a2.Length);
    Array.Copy(a3, 0, ret, a1.Length + a2.Length, a3.Length);
    return ret;
}
protected void BtnEnviar_Click(object sender, EventArgs e)
{
    string host = "192.168.1.43";
    int port = 6301;
    TcpClient tcpclnt = new TcpClient();
    string str = "MSH|^~\\&||.|||199908180016||ADT^A04|ADT.1.1698593|P|2.5\r\nPID|1||000395122||PEREZ^ADRIAN^C^^^||19880517180606|M|";
    try
    { 
        tcpclnt.Connect(host, port);

        ASCIIEncoding asen = new ASCIIEncoding();
        byte[] b1 =  {0x0B};
        byte[] b2 = {0x1C, 0x0D}; 

        // add header an tail to message string

        byte[] ba = Combine(b1, asen.GetBytes(str), b2);
        Stream stm = tcpclnt.GetStream();
        stm.Write(ba, 0, ba.Length);

        byte[] bb = new byte[600];
        int k = stm.Read(bb, 0, 600);

        string s = System.Text.Encoding.UTF8.GetString(bb, 0, k-1);
        Label1.Text = s;

        tcpclnt.Close();

    }
    catch (Exception ex) 
    {
        Label1.Text = ex.Message;
    }
}

2
投票

这取决于您将要使用的HL7 transport和网络协议(=通信规则)。如果它是MLLP并且您的PC通过TCP连接到设备,发送请求,然后在同一连接上收到回复,然后您

  1. 将您的消息编码为MLLP格式的字节数组,如MLLP specification中所述
  2. 像在MSDN client socket example中那样与设备通信
  3. 以相同的方式解码回复。

代码与MSDN示例中的代码相同(如果要接收的数据小于1千字节),只需使用msg中的数据而不是示例字符串:

var hl7 = "<your message>";
byte[] msg;
{
    //check the encoding your device expects
    int len = Encoding.ASCII.GetByteCount(hl7);
    len += 3;
    msg = new byte[len];
    msg[0] = 0x0b;
    Encoding.ASCII.GetBytes(hl7).CopyTo(msg, 1);
    new byte[] { 0x1c, 0x0d }.CopyTo(msg, len - 2);
}
© www.soinside.com 2019 - 2024. All rights reserved.