我正在使用版本 2.3 的HAPI hapi-structures-v25 库来解析HL7v2消息并将其转换为FHIR资源。在通过TCP监听器使用HAPI接收和解析HL7V2消息时,我遇到一个奇怪的问题。
Determine encoding for message. The following is the first 50 chars of the message for reference, although this may not be where the issue is: MSH|^~\&|OPENEMR|DrJhonDoe|TEST|UNKNOWN|20210216190432||ADT^A01^ADT_A01|60b647d4-b5a5-4fae-a928-d4a3849de3c8|T|2.5
奇怪的是,当我尝试在主函数中以字符串形式发送此消息时,我没有收到此错误。仅当我通过TCP/IP接收到Java函数的数据时,才出现此错误。我尝试使用Mirth以及外部工具将HL7消息发送到接收TCP端口,结果是相同的。
这是我正在尝试处理的HL7v2消息的示例
MSH|^~\\&|OPENEMR|Dr.JhonDoe|TEST|UNKNOWN|20210216190432.7||ADT^A01^ADT_A01|60b647d4b5a54faea928d4a3849de3c8|T|2.5
EVN||20210216|20210216|
PID||29||TEST|Chander^Vibin||19940401||||Alrand street, 4th main road, buckingham street^^Georgia^IL^678890^USA||Georgia|IL
PV1||Inpatient|^89^1AD^Inpatient^^^Odani Building^5th Floor|||||||||||||||Inpatient
我解析传入的HL7消息的Java代码public static String getPv1SegmentData(String hl7Message) throws HL7Exception {
String configs = "";
try {
// printing getPath gives correct value (JSON parsed correctly)
HapiContext context = new DefaultHapiContext();
context.getParserConfiguration().setValidating(false);
CanonicalModelClassFactory mcf = new CanonicalModelClassFactory("2.5");
context.setModelClassFactory(mcf);
PipeParser parser = context.getPipeParser();
// Till this it works fine
// this is the portion where its causing error
ADT_A01 v25Message = (ADT_A01) parser.parse(hl7Message);
Terser t25 = new Terser(v25Message);
// value im passing here is getData.split(",")[0] = PV1-3-3
String getPid = t25.get("/.PV1-3-3");
// value im passing here is getData.split(",")[1] = PV1-3-4
String getBed = t25.get("/.PV1-3-4");
// value im passing here is getData.split(",")[2] = PV1-3-2
String getRoom = t25.get("/.PV1-3-2");
// value im passing here is getData.split(",")[1] = PV1-3-7
String getBuilding = t25.get("/.PV1-3-7");
// Parse HL7 and create String
configs = "Bed:"+getBed+"@"+"Room:"+getRoom+"@"+"Building:"+getBuilding+"@"+"Floor:"+getFloor+"@";
System.out.println(configs);
}catch(Exception e) {
System.out.println("get Exception -->"+e);
}
return configs;
}
从tcp/ip接收数据时,im使用UTF-8字符集将字节转换为字符串。InputStream in = connection.getInputStream();
OutputStream out = connection.getOutputStream();
receivedMessageSize = in.read(receivedByeBuffer);
String incomingHl7Message = new String(receivedByeBuffer, StandardCharsets.UTF_8);
即时消息正确。但不确定为什么会出现错误。
最佳答案
正如您提到的那样,您正确地获取了消息,我认为这与HL7没有关系。我的第一个猜测是这可能是与字节到字符串转换有关的问题。
但是,在评论中与您讨论时,您说字符串中存在MLLP字符,这导致了问题。
我知道一些MLLP解析器会删除MLLP字符(<VT>
,<FS>
,<CR>
);但是有些没有。应用程序应将其删除。
在将字节转换为字符串之后并在调用parser.parse(hl7Message)
之前,只需使用Java中的某些字符串替换方法删除这些字符。
我不知道Java,但是像hl7Message.replace(...., "")
这样的东西应该可以工作。
关于java - 通过TCP/IP接收数据时HL7V2 HAPI解析器异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66230745/