示例代码:
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();
}
}
}
这适用于: MSH | ^〜\&|梅格| XYZHospC | SurOE | XYCtr | 20060529090131-050 || ADT^A01^ADT_A01 | 01052901 | P | 2.5 EVN || 200605290901 |||| 200605290900 PID ||| 56782445 ^^^ UAReg^PI || KLEINSAMPLE^BARRY^Q^JR || 19620910 | M || 2-9 ^^ HL70005^RA93 ^^ XYZ | 260 GOODWIN CREST DRIVE ^^ BIRMINGHAM^AL^35 209 ^^ M〜NELLELL'S SQUARE^10000 W 100TH AVE^B IRMINGHAM^AL^35 ^^ O ||||||| 0105I30001 ^^^ 99DEF^AN PV1 || I | W^389^1^UABH ^^^^ 3 |||| 12345^MORGAN^REX^J ^^^ MD^0010^UAMC^L^678 90^GRAINGER^LUCY^X ^^^ MD^0010^UAMC^L | MED ||||| A0 || 13579^POTTER^SHER MAN^T^^^MD^0010^UAMC^L ||||||||||||||||||||||||||||||||||||||||||| 200605290900 OBX | 1 | NM | ^身高|| 1.80 | m ^米^ ISO + ||||| F – MaNn
[你有什么试过?](http://mattgemmell.com/2008/12/08/what-have-you-tried/) – xyz
对你有好处,哪里有这个问题? –