如何编写和发送ASTM框架到医疗设备 [英] How to write and send an ASTM frame to medical equipment

查看:202
本文介绍了如何编写和发送ASTM框架到医疗设备的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在研究ASTM协议,以将订单测试请求发送到医疗仪器。但是我无法正确地向设备发送消息。更明确地说,我想例如发送以下帧:

I am currently working on the ASTM protocol to send orders tests request to medical instrument. But I cannot send a message to the equipment correctly. To be more explicit, I want for example to send these frames:

        String h1, s2, s3, s4, s5, s6 = "";
        h1 = "H|@^\\|ODM-IdfDGIWA-36|||GeneXpert PC^GeneXpert^4.8|||||LIS||P|1394-97|20070521100245";
        s2 = "P|1";
        s3 = "O|1|SID-818||^^^TestId-12|S|20070812140500|||||A||||ORH||||||||||Q";
        s4 = "O|2|SID-818||^^^TestId-14|S|20070812140600|||||A||||ORH||||||||||Q";
        s5 = "O|3|SID-818||^^^TestId-16|S|20070812140700|||||A||||ORH||||||||||Q";
        s6 = "L|1|F";

这就是我现在的做法:

    writeMeBytes(outToServer, h1.getBytes());
    writeMeBytes(outToServer, s2.getBytes());
    writeMeBytes(outToServer, s3.getBytes());
    writeMeBytes(outToServer, s4.getBytes());
    writeMeBytes(outToServer, s5.getBytes());
    writeMeBytes(outToServer, s6.getBytes());


public static void writeMeBytes(DataOutputStream dos, byte [] b){
    if (b.length >0){
        int j = 0;
        while (j <= b.length-1) {
            try {
                dos.write(b[j++]);
            } catch (IOException ex) {
                Logger.getLogger(SimpleServer.class.getName()).log(Level.SEVERE, null, ex);
            }

        }
    }
}

我将其转换为字节,然后一个字节一个字节地发送。

I turn it into byte and then send byte after byte.

除了接收方看不到任何变化之外。

Except that I do not see any change on the receiver side.

根据@Muhammad答案进行更新

这就是我向GeneXpert DX系统发送订单的过程

This is what I did to send order to GeneXpert DX System

public class SimpleServer {

private static ServerSocket server;
private static Socket connection;

public static void main(String args[]) throws IOException, InterruptedException {
    server = new ServerSocket(12221);
    boolean stopped = false;

    System.out.println(" start... ");
    connection = server.accept();
    System.out.println("wait for connection");
    BufferedReader inFromClient = new BufferedReader(new InputStreamReader(connection.getInputStream()));
    DataOutputStream outToClient = new DataOutputStream(connection.getOutputStream());
    String currentMsg = "";
    int clientIntMessage;

    String h1, s2, s3, s4, s5, s6 = "";
    h1 = "1H|@^\\|ODM-IdfDGIWA-36|||GeneXpert PC^GeneXpert^4.8|||||LIS||P|1394-97|20070521100245" + ProtocolASCII.LF
            + "P|1" + ProtocolASCII.LF
            + "O|1|SID-818||^^^TestId-12|S|20070812140500|||||A||||ORH||||||||||Q" + ProtocolASCII.LF
            + "L|1|F" + ProtocolASCII.LF;
    s2 = "P|1";
    s3 = "O|1|SID-818||^^^TestId-12|S|20070812140500|||||A||||ORH||||||||||Q";
    //s4 = "O|2|SID-818||^^^TestId-14|S|20070812140600|||||A||||ORH||||||||||Q";
    //s5 = "O|3|SID-818||^^^TestId-16|S|20070812140700|||||A||||ORH||||||||||Q";
    s6 = "L|1|F";

    String retmsg = h1;
    //logException("OrderMessae   :" + retmsg);
    retmsg = ProtocolASCII.STX + retmsg + ProtocolASCII.CR + ProtocolASCII.ETX + ProtocolMessage.getCheckSum(retmsg) + ProtocolASCII.CR + ProtocolASCII.LF;

    clientIntMessage = inFromClient.read();
    //while (clientIntMessage != ProtocolASCII.EOT) {
    while (true) {
        currentMsg += String.valueOf(Character.toChars(clientIntMessage));
        if (clientIntMessage == ProtocolASCII.ENQ) {
            outToClient.writeBytes("" + ProtocolASCII.ACK);
            System.out.println(" <--- LIS [ACK] on DX [ENQ]");
        } else if (clientIntMessage == ProtocolASCII.ACK) {
            System.out.println(" ---> DX [ACK]");
            // Send your order message here
            outToClient.writeBytes(retmsg);
        } else if (clientIntMessage == ProtocolASCII.CR) {
            System.out.println(currentMsg);
            outToClient.writeBytes("" + ProtocolASCII.ACK);
        } else if (clientIntMessage == ProtocolASCII.NAK) {
            System.out.println(" ---> DX sent [NAK] ");
            System.out.println(" --- LIS now wait 10 sec... ");
            Thread.sleep(10000);
            outToClient.writeBytes("" + ProtocolASCII.ENQ);
            System.out.println(" <--- LIS [ENQ] ");
        } else if (clientIntMessage == ProtocolASCII.EOT) {
            System.out.println(" ---> DX END OF TRANSMISSION");
            outToClient.writeBytes("" + ProtocolASCII.ENQ);
            System.out.println(" <--- LIS [ENQ] ");
        }

        if (stopped) {
            break;
        }
        clientIntMessage = inFromClient.read();
    }
    connection.close();
    stopped = true;
}}

这是我从控制台获得的结果:

And this is the result I get from the console:

start... 
wait for connection
 <--- LIS [ACK] on DX [ENQ]
1H|@^\|ODM-rQTcjIWA-66||GeneXpert PC^GeneXpert^4.8|||||LIS||P|1394-97|20180314003724
Q|1|ALL||||||||||O@N
L|1|N
B5
 ---> DX [EOT] 
 <--- LIS [ENQ] 
 ---> DX [ACK]
 ---> DX sent [NAK] 
 --- LIS now wait 10 sec... 

DX是机器软件,而LIS是主机。
每当我尝试发送ENQ时,机器都会用NAK回答我。

DX is the machine software and LIS is the host. Whenever I try to send the ENQ, the machine answers me with NAK.

更新2

似乎有效。但是现在Windows事件向我显示了一个错误,说明为什么我的记录订单未出现在GeneXpert DX主机记录列表中。头记录已被首先发送。

UPDATE 2
It seem to be working. But now windows events shows me an error about why my records orders don't appear in the GeneXpert DX host record list. The header record have been sent first.

推荐答案

在回答之前,让我们讨论一下双向的机器机制。

Before answering, lets discuss machine mechanism for Bidirectional.

String h1, s2, s3, s4, s5, s6 = "";
    h1 = "H|@^\\|ODM-IdfDGIWA-36|||GeneXpert PC^GeneXpert^4.8|||||LIS||P|1394-97|20070521100245";
    s2 = "P|1";
    s3 = "O|1|SID-818||^^^TestId-12|S|20070812140500|||||A||||ORH||||||||||Q";
    s4 = "O|2|SID-818||^^^TestId-14|S|20070812140600|||||A||||ORH||||||||||Q";
    s5 = "O|3|SID-818||^^^TestId-16|S|20070812140700|||||A||||ORH||||||||||Q";
    s6 = "L|1|F";

第一,在字符串消息上方查看,没有任何标签编号因为到目前为止我做过的每台机器都需要标签号。例如:

First, viewing above String message, there isn't any tag numbering as every machine I have done so far requires Tag number. For example:

1H|\^&|||CS-2500^00-08^22029^^^CP^BV981798||||||||E1394-97
2P|1|||00000152556|^JOHN^ABC||19440601|M|||||^Dr.Shaukat Khanum Hospital|||||||||^^^EAST
3O|1|000038^01^0012586236^B||^^^051^^100.00¥^^^044^^100.00|R|201803081225236|||||N
4L|1|N

因此,您必须具有编号 >每个标签。

So, you must have NUMBERING for each tag.

第二,计算机在第一时间发送以下查询:

Second, Machine sends following query at first time:

1H|\^&|||CS-2500^^22029^^^CP^BV981798||||||||E1394-9711
2Q|1|000038^01^   0012365845B||^^^040^PT-INN\^^^050^APTT-FS|0|201803081227007F
3L|1|NF9

输入,查询(2Q)标签, 000038 机架ID, 01 机架序列号, 001H18074618 样品ID(从条形码读取),可以从主机或机器供应商提供的LIS手册中验证更多信息。

In, Query(2Q) Tag, 000038 rack id, 01 rack sequence number, 001H18074618 sample id (read from Barcode), further information can be verified from host or LIS manual provided by machine vendor.

第三,当我们收到此消息时,我们将为我上面已经描述过的机器(在下面再次写出)加上另外的校验和信息。同样,该校验和可以在计算机的主机或LIS手册中找到。

Third, When we receive this message, we will make message for machine that I have described above (writing again below) with additional checksum information. Again, this checksum can be found in host or LIS manual of machine.

1H|\^&|||CS-2500^00-08^22029^^^CP^BV981798||||||||E1394-97
2P|1|||00000152556|^JOHN^ABC||19440601|M|||||^Dr.Shaukat Khanum Hospital|||||||||^^^EAST
3O|1|000038^01^12345678^B||^^^051^^100.00¥^^^044^^100.00|R|201803081225236|||||N
4L|1|N

校验和计算示例。请注意,它可能因机器而异。

Example of Checksum calculation. Note that it may vary from machine to machine.

  public static String getCheckSum(String msg) {
    int sum = 0;
    for (int i = 0; i < msg.length(); i++) {
        sum += msg.charAt(i);
    }
    sum += 16; //adding CR and ETX AND ETB
    sum = sum % 256;
    String checksum = Integer.toHexString(sum).toUpperCase();
    if (checksum.length() == 1) {
        checksum = "0" + checksum;
    }
    //System.out.println("\n Check Sum is ="+checksum);
    return checksum;
}

这是将发送到计算机的完整消息:

And here is our complete message that will be sent to machine:

String retmsg = "3O|1|" + rackId + "^" + positionNumber + "^" + sampleId + "^B||" + testIds + "|" + priority + "|" + sysDate + "|||||" + orderType + "";
    logException("OrderMessae   :" + retmsg);
    retmsg = ProtocolASCII.STX + retmsg + ProtocolASCII.CR + ProtocolASCII.ETX + ProtocolMessage.getCheckSum(retmsg) + ProtocolASCII.CR + ProtocolASCII.LF;

最后但并非最不重要,我不知道这是什么机器因为我没有手册,但我觉得您不需要一一发送每封邮件。您可以一次发送所有邮件。

Last but not least, I don't know what is the machine as I don't have manual but I sense that you don't need to send every message one by one. You can send all at once.

这是在计算机之间收发消息的代码段。

here is the code snippet of sending and receiving message to and from machine.

while (clientIntMessage != ProtocolASCII.EOT) {
                    clientIntMessage = inFromClient.read();
                    currentMsg += String.valueOf(Character.toChars(clientIntMessage));
                    // System.out.println(currentMsg);
                    if (clientIntMessage == ProtocolASCII.ENQ) {
                        outToClient.writeBytes("" + ProtocolASCII.ACK);
                        System.out.println("[ACK] on Analyzer [ENQ]");
                    } else if (clientIntMessage == ProtocolASCII.ACK) {                        
                        System.out.println("Analyzer [ACK]");
                        // Send your order message here
                         outToClient.writeBytes(retmsg);
                        }
                    } else if (clientIntMessage == ProtocolASCII.LF) {
                        outToClient.writeBytes("" + ProtocolASCII.ACK);
                    } else if (clientIntMessage == ProtocolASCII.NAK) {
                        System.out.println(" Analyzer sent [NAK] ");
                    }

                }

其中 ProtocolASCII.ACK '\006' ProtocolASCII.ENQ '\005' ProtocolASCII.EOT '\004'

代码几乎可以自我解释,我正在生产中使用它。

The code is pretty much self explanatory and I am using it in production.

您能告诉我们您正在连接哪台计算机吗?如果我已经集成,它可能会对您有所帮助。

Can you tell us which machine you are interfacing? It may help you if I have already integrated.

谢谢。如果需要进一步的帮助,请告诉我。

Thanks . If further assistance is required, let me know.

供您参考:

public class ProtocolASCII {

  public static char STX = '\002';
  public static char ETX = '\003';
  public static char ETB = '\027';
  public static char EOT = '\004';
  public static char ENQ = '\005';
  public static char ACK = '\006';
  public static char NAK = '\025';
  public static char CR = '\r';
  public static char LF = '\n';
  public static char MOR = '>';
  public static char FS = '\034';
  public static char GS = '\035';
  public static char RS = '\036';
  public static char SFS = '\027';
  public static char VT = 0x0B; //END OF BLOCK 011


}

更新:

根据您的评论:

字符串retmsg = 3O | 1 | + rackId + ^ + positionNumber + ^ + sampleId + ^ B || + testIds + | +优先级+ | + sysDate + ||||| + orderType +; 其中 testIds 是要执行的测试的列表。

String retmsg = "3O|1|" + rackId + "^" + positionNumber + "^" + sampleId + "^B||" + testIds + "|" + priority + "|" + sysDate + "|||||" + orderType + ""; Where testIds is the list of tests to perform.

示例多重测试订单发送 4O | 1 || 4 ^ 1 ^ 12345678 ^ B | ^^^^ WBC\ ^^^^ RBC \ ^^^^ HGB\ ^^^^ HCT\ ^^^^^ MCV\ ^^^^ MCH\ ^^^^^ MCHC\ ^^^^ PLT\ ^^^^ RDW- SD\ ^^^^ RDW-CV\ ^^^^ PDW\ ^^^^ MPV\ ^^^^ P-LCR\ ^^^^^ PCT\ ^^^^ NEUT#\ ^^^^ LYMPH#\ ^^^^^ MONO#\ ^^^^^ EO#\ ^^^^^ BASO#\ ^^^^^ NEUT%\ ^^^^ LYMPH%\ ^^ ^^ MONO%\ ^^^^ EO%\ ^^^^^ BASO%\ ^^^^ NRBC#\ ^^^^^ NRBC%\ ^^^^ IG#\ ^^^^^ IG%|||||||| N |||||||||||||| F

example multitest order send 4O|1||4^1^ 12345678^B|^^^^WBC\^^^^RBC\^^^^HGB\^^^^HCT\^^^^MCV\^^^^MCH\^^^^MCHC\^^^^PLT\^^^^RDW-SD\^^^^RDW-CV\^^^^PDW\^^^^MPV\^^^^P-LCR\^^^^PCT\^^^^NEUT#\^^^^LYMPH#\^^^^MONO#\^^^^EO#\^^^^BASO#\^^^^NEUT%\^^^^LYMPH%\^^^^MONO%\^^^^EO%\^^^^BASO%\^^^^NRBC#\^^^^NRBC%\^^^^IG#\^^^^IG%|||||||N||||||||||||||F

获取测试代码

更新2

Socket clientSocket = null;
public static char STX = '\002';
public static char ETX = '\003';
public static char ETB = '\027';
public static char EOT = '\004';
public static char ENQ = '\005';
public static char ACK = '\006';
public static char NAK = '\025';
public static char CR = '\r';
public static char LF = '\n';
public static char MOR = '>';
public static char FS = '\034';
public static char GS = '\035';
public static char RS = '\036';
public static char SFS = '\027';
public static char VT = 0x0B; //END OF BLOCK 011
public static Vector<String> vecMessages = new Vector<String>();
private static int currentMsgCount = 0;
private static ServerSocket server;
private static Socket connection;
Message mes = new Message();

public static void main(String args[]) throws IOException, InterruptedException {
    server = new ServerSocket(12221);
    boolean stopped = false;

    System.out.println(" start... ");
    connection = server.accept();
    System.out.println("wait for connection");
    BufferedReader inFromClient = new BufferedReader(new InputStreamReader(connection.getInputStream()));
    DataOutputStream outToClient = new DataOutputStream(connection.getOutputStream());
    String currentMsg = "";
    int clientIntMessage;

//    String h1, s2, s3, s4, s5, s6 = "";
//    h1 = "1H|@^\\|ODM-IdfDGIWA-36|||GeneXpert     PC^GeneXpert^4.8|||||LIS||P|1394-97|20070521100245" + ProtocolASCII.LF
//            + "P|1" + ProtocolASCII.LF
//            + "O|1|SID-818||^^^TestId-12|S|20070812140500|||||A||||ORH||||||||||Q" + ProtocolASCII.LF
//            + "L|1|F" + ProtocolASCII.LF;
//    s2 = "P|1";
//    s3 = "O|1|SID-818||^^^TestId-12|S|20070812140500|||||A||||ORH||||||||||Q";
//    //s4 = "O|2|SID-818||^^^TestId-14|S|20070812140600|||||A||||ORH||||||||||Q";
//    //s5 = "O|3|SID-818||^^^TestId-16|S|20070812140700|||||A||||ORH||||||||||Q";
//    s6 = "L|1|F";
//
//    String retmsg = h1;
//    //logException("OrderMessae   :" + retmsg);
//    retmsg = ProtocolASCII.STX + retmsg + ProtocolASCII.CR + ProtocolASCII.ETX + ProtocolMessage.getCheckSum(retmsg) + ProtocolASCII.CR + ProtocolASCII.LF;



    clientIntMessage = inFromClient.read();
        //while (clientIntMessage != ProtocolASCII.EOT) {
        while (true) {

            while (clientIntMessage != EOT) {
                clientIntMessage = inFromClient.read();
                currentMsg += String.valueOf(Character.toChars(clientIntMessage));
                // System.out.println(currentMsg);
                if (clientIntMessage == ENQ) {
                    outToClient.writeBytes("" + ACK);
                    System.out.println("[ACK] on Analyzer [ENQ]");
                } else if (clientIntMessage == ACK) {

                    System.out.println("Analyzer [ACK]");
                    if (vecMessages.size() == currentMsgCount) {
                        vecMessages.clear();
                        currentMsgCount = 0;
                        outToClient.writeBytes("" + EOT);
                        System.out.println("Host [EOT]");
                    } else {
                        String msg = (String) vecMessages.get(currentMsgCount++);

                        outToClient.writeBytes(msg);
//                                System.out.println("Msg " + msg.substring(0, msg.length() - 4));
                    }
                } else if (clientIntMessage == LF) {
                    outToClient.writeBytes("" + ACK);
                } else if (clientIntMessage == NAK) {
                    System.out.println(" Analyzer sent [NAK] ");
                }

            }

            System.out.println(currentMsg);
            mes.parser(currentMsg);

            clientIntMessage = 0;
            currentMsg = "";

        }
//        connection.close();
//        stopped = true;
    }

    public static class Message {
//        machine Send This Query   ==>6.3.2.1.5 Example of Upload Message – Instrument System Sends Host Query
//        H|@^\|b4a88d9adab947a7b3dca2b534119c25||ICU^GeneXpert^1.0|||||LIS||P|1394-97|20070521100245 
//        Q|1|PatientID-556^SpecimenID-888||||||||||O@N 
//        L|1|N 

        public static Vector<String> vecMessages = new Vector<String>();
//        make message for machine

        public String HeaderMessage() {
            String retmsg = "H|@^\\|ccc6ade20d3623314sffa3e287f2314ad||LIS|||||ICU^GeneXpert^1.0||P|1394-97|20070521100245";
//        System.out.println("HeaderMessage  :" + retmsg);
            retmsg = STX + retmsg + CR + ETX + getCheckSum(retmsg) + CR + LF;

            return retmsg;
        }
        //  P|1       
        //      6.3.1.3.3 Patient Information Record     Find in Document and make it as per document

        public String PatientMessage(Patient pat) {  //(Patient pat)

            String retmsg = "P|1|||" + pat.getMRNO() + "|^" + pat.getPatientName() + "||" + pat.getDOB() + "|" + pat.getGender() + "|||||^Dr.SKM-LAS||||||||||||^^^EAST";

            retmsg = STX + retmsg + CR + ETX + getCheckSum(retmsg) + CR + LF;

            return retmsg;
        }
//                6.3.1.3.4 Test Order Record      Find in Document

        public String orderMessage(String sampleId, String testIds, String orderType, String rackId, String positionNumber, String priority) {
            DateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmSS");
            String sysDate = dateFormat.format(new Date());

            String retmsg = "3O|1|" + rackId + "^" + positionNumber + "^" + sampleId + "^B||" + testIds + "|" + priority + "|" + sysDate + "|||||" + orderType + "";

            retmsg = STX + retmsg + CR + ETX + getCheckSum(retmsg) + CR + LF;

            return retmsg;
        }

//        6.3.1.3.5 Message Terminator Record    Find in Document
        public String terminatorMessage(String type) {
            String retmsg = "L|1|" + type;

            retmsg = STX + retmsg + CR + ETX + getCheckSum(retmsg) + CR + LF;
            return retmsg;
        }

        public String getCheckSum(String msg) {
            int sum = 0;
            for (int i = 0; i < msg.length(); i++) {
                sum += msg.charAt(i);
            }
            sum += 16; //adding CR and ETX AND ETB
            sum = sum % 256;
            String checksum = Integer.toHexString(sum).toUpperCase();
            if (checksum.length() == 1) {
                checksum = "0" + checksum;
            }
            //System.out.println("\n Check Sum is ="+checksum);
            return checksum;
        }

        public void parser(String input) {
//        Use StringTokenizer for split or split

            if (input.charAt(1) == 'Q' || input.charAt(2) == 'Q') {

                //Q|1|PatientID-556^SpecimenID-888||||||||||O@N 
//                        Split it and get information which machine send in Query SampleId and other
                String rackId = "get from Query to check document";
                String positionNumber = "get from Query to check document";
                String sampleId = "get from Query to check document";

//                        this.FetchOrders1(machineId, sampleId);     // for dummy Sample Run
                this.FetchOrders1("abc", sampleId);
                this.setMesType("Q");

            }

        }

        public void FetchOrders1(String machineId, String sampleId) {
            try {
                this.vecMessages.add(HeaderMessage());
                this.vecMessages.add(PatientMessage()); //Define patient information
                this.vecMessages.add(orderMessage(sampleId, "test", "N", "rackId", "positionNumber", "R"));
                this.vecMessages.add(terminatorMessage("N"));

            } catch (Exception e) {
                e.printStackTrace();
            }
        }

    }`

这篇关于如何编写和发送ASTM框架到医疗设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆