java 需要解析HL7消息
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14050402/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Need to parse HL7 message
提问by MaNn
I need to parse HL7 message ,firstly ,validate the message and then parse.
我需要解析 HL7 消息,首先验证消息然后解析。
XMLParser xmlParser = new DefaultXMLParser();
//encode message in XML
String hl7MessageInXML = null;
try {
hl7MessageInXML = xmlParser.encode(message);
} catch (HL7Exception e) {
e.printStackTrace();
}
采纳答案by Sher
Example code:
示例代码:
import ca.uhn.hl7v2.parser.*;
import ca.uhn.hl7v2.model.Message;
import ca.uhn.hl7v2.model.v24.message.ACK;
public class ParserDemo {
public static void main(String args[]) {
//for demo purposes, we just declare a literal message string
String ackMessageString
= "MSH|^~\&|foo|foo||foo|200108151718||ACK^A01^ACK|1|D|2.4|\rMSA|AA\r";
//instantiate a PipeParser, which handles the "traditional encoding"
PipeParser pipeParser = new PipeParser();
try {
//parse the message string into a Message object
Message message = pipeParser.parse(ackMessageString);
//if it is an ACK message (as we know it is), cast it to an
// ACK object so that it is easier to work with, and change a value
if (message instanceof ACK) {
ACK ack = (ACK) message;
ack.getMSH().getProcessingID().getProcessingMode().setValue("P");
}
//instantiate an XML parser
XMLParser xmlParser = new DefaultXMLParser();
//encode message in XML
String ackMessageInXML = xmlParser.encode(message);
//print XML-encoded message to standard out
System.out.println(ackMessageInXML);
} catch (Exception e) {
e.printStackTrace();
}
}
}
回答by ignacio.suay
Try using HAPI Parser api (http://hl7api.sourceforge.net/). Here you can find some examples about parsing HL7 messages:
尝试使用 HAPI Parser api ( http://hl7api.sourceforge.net/)。在这里您可以找到一些有关解析 HL7 消息的示例:
http://ignaciosuay.com/how-to-use-hapi-terser-with-hl7/
http://ignaciosuay.com/how-to-use-hapi-terser-with-hl7/
http://ignaciosuay.com/how-to-set-repetitions-in-hl7-messages-using-hapi-terser/
http://ignaciosuay.com/how-to-set-repetitions-in-hl7-messages-using-hapi-terser/
Hope it helps
希望能帮助到你