gpt4 book ai didi

java - 使用java套接字和HAPI的HL7消息解析错误

转载 作者:行者123 更新时间:2023-12-02 05:30:05 26 4
gpt4 key购买 nike

我正在使用自动血液分析仪,它生成 HL7 消息并通过 TCP/IP 发送到连接的 PC。我正在使用 java 套接字来接收 HL7 消息/数据。但是当我尝试解析 HL7 消息(字符串)时,它显示错误消息:

ca.uhn.hl7v2.parser.EncodingNotSupportedException: Determine encoding for message.

以下是消息的前 50 个字符供引用,尽管这可能不是问题所在:

.MSH|^~\&|DH3x|Dymind|||20190421171520||ORU^R01|20`

我正在尝试使用 HAPI 解析消息

public static void main(String[] args) {

try {
//When using file
//String messageString = readHL7MessageFromFileAsString(filePath);

String messageString = ".MSH|^~\\&|DH3x|Dymind|||20190421171520||ORU^R01|20190421_140443_220|P|2.3.1||||||UNICODE\r\n" +
"PID|1\r\n" +
"PV1|1\r\n" +
"OBR|1||275|01001^Automated Count^99MRC||20190421140443|20190421140443|||||||20190421140443||||||||||HM||||||||admin\r\n" +
"OBX|1|IS|02001^Take Mode^99MRC||O||||||F\r\n" +
"OBX|2|IS|02002^Blood Mode^99MRC||W||||||F\r\n" +
"OBX|3|IS|02003^Test Mode^99MRC||||||||F\r\n" +
"OBX|4|NM|30525-0^Age^LN||||||||F\r\n" +
"OBX|5|IS|09001^Remark^99MRC||||||||F\r\n" +
"OBX|6|IS|03001^Ref Group^99MRC||||||||F\r\n" +
"OBX|7|NM|6690-2^WBC^LN||7.94|10*3/uL|4.00-10.00|~N|||F\r\n" +
"OBX|8|NM|736-9^LYM%^LN||34.4|%|20.0-40.0|~N|||F\r\n" +
"OBX|9|NM|20482-6^GRAN%^LN||52.5|%|50.0-70.0|~N|||F\r\n" +
"OBX|10|NM|32155-4^MID%^LN||13.1|%|3.0-9.0|H~A|||F\r\n" +
"OBX|11|NM|731-0^LYM#^LN||2.73|10*3/uL|0.80-4.00|~N|||F\r\n" +
"OBX|12|NM|19023-1^GRAN#^LN||4.17|10*3/uL|2.00-7.00|~N|||F\r\n" +
"OBX|13|NM|32154-7^MID#^LN||1.04|10*3/uL|0.10-0.90|H~A|||F\r\n" +
"OBX|14|NM|789-8^RBC^LN||4.71|10*6/uL|3.50-5.50|~N|||F\r\n" +
"OBX|15|NM|718-7^HGB^LN||13.7|g/dL|11.0-16.0|~N|||F\r\n" +
"OBX|16|NM|4544-3^HCT^LN||40.7|%|37.0-50.0|~N|||F\r\n" +
"OBX|17|NM|787-2^MCV^LN||86.4|fL|82.0-95.0|~N|||F\r\n" +
"OBX|18|NM|785-6^MCH^LN||29.2|pg|27.0-31.0|~N|||F\r\n" +
"OBX|19|NM|786-4^MCHC^LN||33.8|g/dL|32.0-36.0|~N|||F\r\n" +
"OBX|20|NM|788-0^RDW-CV^LN||13.5|%|11.5-14.5|~N|||F\r\n" +
"OBX|21|NM|21000-5^RDW-SD^LN||47.1|fL|35.0-56.0|~N|||F\r\n" +
"OBX|22|NM|777-3^PLT^LN||255|10*3/uL|100-300|~N|||F\r\n" +
"OBX|23|NM|32623-1^MPV^LN||9.9|fL|7.0-11.0|~N|||F\r\n" +
"OBX|24|NM|32207-3^PDW^LN||16.1||15.0-17.0|~N|||F\r\n" +
"OBX|25|NM|11003^PCT^99MRC||0.251|%|0.108-0.282|~N|||F\r\n" +
"OBX|26|NM|12001^WBC Histogram. Left Line^99MRC||15||||||F\r\n" +
"OBX|27|NM|12004^WBC Histogram. Middle Line^99MRC||43||||||F\r\n" +
"OBX|28|NM|12002^WBC Histogram. Right Line^99MRC||66||||||F\r\n" +
"OBX|29|ED|12003^WBC Histogram. BMP^99MRC||^Image^PNG^Base64^iVBORw0KGgoAAAANSUhEUgAAAJwAAABvCAIAAACW3D6tAAAAA3NCSVQICAjb4U/gAAAACXBIWXMAAAsTAAALEwEAmpwYAAAGr0lEQVR4nO2db2gTZxzHf3F5cYy+eF70xQUsa8QJEWE9KG5hE2nEgS2+MKJCSycjCJPgQFOFrezNVjcY7cCaDnSt0hf1hZKUCYlgyfnCcREyLi8qyaCSK2RwQ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Q8yNxQKhhMVAwAAAABJRU5ErkJggg==||||||F\r\n" +
"OBX|30|NM|12051^RBC Histogram. Left Line^99MRC||28||||||F\r\n" +
"OBX|31|NM|12052^RBC Histogram. Right Line^99MRC||230||||||F\r\n" +
"OBX|32|ED|12053^RBC Histogram. BMP^99MRC||^Image^PNG^Base64^iVBORw0KGgoAAAANSUhEUgAAAJwAAABvCAIAAACW3D6tAAAAA3NCSVQICAjb4U/gAAAACXBIWXMAAAsTAAALEwEAmpwYAAAGD0lEQVR4nO3bUWgTdxwH8L9bHv6MPpyQhztoWU+c7ERYD8q2sg0x4sAUH4yoYBGRsuEIPmiK4Ap72OqedKC2AzdEROrDpFfmaAUl54PjInRcBi3JoJIrRLhChQtbsPcQyB6uhi6NMeTu/snuvh9KuVzT/+/f+93/7pu0JQQAAAAAAAAAAAAAQoPv5c2i6XwUjIKW0WIHYoQQ6X2ptlPP6smvks7zKaWT1ybNommtWfqCLg/KHZ0+NCLuFK01a+NBhCQOJ9b/WaeUygNyYbnAcRzHcdIeySyaTv/SD9OT1yYppYSQxOGEZVlclOvg/MMs0tKzKkT5TSERUutTqVRyPufyOUEQyCDZLe3e//l+56vKrEJ7KI1Qf+YMb9CsqZTSjatrhMQPxtXH6urzVSEqbI9un7w2SQgRegW7Ys8/mB89PapltM3fe/fOXT+nDc281eyLESIIgiiKE99MZP/MDseHnd22bWsLmragaU80SZLiB+JYlP8Pm++p0h7Jsix5QCaEOPfU2tNGT4/Ozc8NfTy0eSchZPzi+NCnQywnDDVNV+or+aX8xPcT03em66/WETL02ZCxYmSeZkrlUupcytktD8pjF8ZWn696PVtw5z/plxASIXpWH784Lg/I1WrVsixrzbIsa+7+nJOe+F5ey2gFo6Av6GbRjB+Kd2zq4C2O4/hevtOzAAAAAPBDtVrt9BTArZZepzbkpv0hPHFYrpb2m9q2EHaUsQ40FfzWsaZivbLD4NJfffUBPmG9UtFLBjqTfkMo4OkX/NbJpmKl+wQrNYDab+q2bds8nEfgsTxcWKkBxDT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Jqbh2JTd/SL0bn7c872zC8zqXOpVurSHmpZFiGuglL9Ss0v5ecfzOtZnVSI+kTN/pFtb9xWNKzlefXU+RTP8+oj1Xl4+YfLl767xKDuzVs3E4cSWkajEWoYxpXrV0ilQZW6PbSH1kYQd4pOgwkh6iPV5Y2WcBzHcZyrIVzUYlOdTV0uytVelLOsC0HzL5TJiblafcURAAAAAElFTkSuQmCC||||||F\r\n" +
"OBX|33|NM|12101^PLT Histogram. Left Line^99MRC||5||||||F\r\n" +
"OBX|34|NM|12102^PLT Histogram. Right Line^99MRC||56||||||F\r\n" +
"OBX|35|ED|12103^PLT Histogram. BMP^99MRC||^Image^PNG^Base64^iVBORw0KGgoAAAANSUhEUgAAAJwAAABvCAIAAACW3D6tAAAAA3NCSVQICAjb4U/gAAAACXBIWXMAAAsTAAALEwEAmpwYAAAFkUlEQVR4nO3csWsbVxwH8Oeg4Q0eXkDDeSjowEMEHXzB/4A9JniwTDrYZDIdishgy3QomVKnU9IlcYcQN0ORhhTJUIgzBF0Gl9OQIg02UsHhLqDCGWzQDQLfYLgOlwjXtSWd7z3du9P3gwm++Pi95/e739NP57MJAQAAAAAAAAAAAICxoWZUu23bbdu0TPPQLJaKLM2yt7JVvdo7p1gq+uf0PgprhQjnDANkb2Vt22a+NHv568tiqajNaOah2TuHUsoY02a03pmU0gjnDL5U/y87juN/Uvqt9PyX5xe+6rqu67pO1zl/JkRuQFLVjEoIoZO0sFYw9oyRTAnC6pdUJa2Ud8rkjLiua9SMh48eZqezI5sZXFu/pB6dHN3Wbo9sKsDLjagnAPwFTqo6rXa+KL8ui5gTAAAAAMBoeJ4nICj/kNBHsLc010m59+XfsUytkCIZZMC937C8qw8nxI48zqK7ozSWhTsaIpM6MG3IqxjBkjoxgU0zmEhWTFilDlmFKFYBxHe/4y2SFRNTqYG+EVwnvOHnqQkkIKmovKjJ0f0m9zpIVvcL0eHd/Sa35q4nQd0vRIprUsNclChxflCpCSRH9+tLYrGi+wU++HW/XOosccWaxCcfrg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trb3G/6nxs1Q5vVBA1kt22/UeI7oppR7bZ9Pgjf+KvfrvZe6sqvy4W1gogVo5O00+kQwqFRShFCWget3be79UadnBF9T2/81Qg/xf74jlhYLyiKor/T/cMnPz95/ONjjvG3X23nFnJGzaApalnW02dPyRkRumLqtOonmBCiv9Ov/0LLGGOMcZuXBCPyjc/SrPcmW0R8gH7+BYsGvMZlr90tAAAAAElFTkSuQmCC||||||F\r\n" +
".\r\n" +
".MSH|^~\\&|DH3x|Dymind|||20190421171520||ACK^R01|20190421_140443_220|P|2.3.1||||||UNICODE\r\n" +
"MSA|AA|20190421_140443_220\r\n" +
".\r\n" +
"";

// instantiate a PipeParser, which handles the "traditional or default encoding"
PipeParser ourPipeParser = new PipeParser();

// parse the message string into a Java message object
Message orderResultsHl7Message = ourPipeParser.parse(messageString);

// create a terser object instance by wrapping it around the message object
Terser terser = new Terser(orderResultsHl7Message);

// now, let us do various operations on the message
TerserHelper teFrserDemonstrator = new TerserHelper(terser);

String terserExpression = "/.OBSERVATION(1)/OBX-3";
String dataRetrieved = teFrserDemonstrator.getData(terserExpression);
System.out.printf("Observation group's 2nd OBX segment's second field using expression '%s' was: '%s' \n\n",
terserExpression, dataRetrieved);

terserExpression = "/.OBSERVATION(1)/NTE(1)-3";
dataRetrieved = teFrserDemonstrator.getData(terserExpression);
System.out.printf("Observation group's 2nd NTE segment's second field using expression '%s' was: '%s' \n\n",
terserExpression, dataRetrieved);

terserExpression = "/.RESPONSE/ORDER_OBSERVATION/OBSERVATION(0)/OBX(0)-16-2";
dataRetrieved = teFrserDemonstrator.getData(terserExpression);
System.out.printf(
"Observation group's First OBX segment's 16th Field and its Second component using expression '%s' was: '%s' \n\n",
terserExpression, dataRetrieved);

// let us now try a set operation using the terser
terserExpression = "/.OBSERVATION(1)/NTE-3";
teFrserDemonstrator.setData(terserExpression, "This is our override value using the setter");
System.out.printf("Setting the data for second repetition of the NTE segment and its third field\n",
terserExpression, dataRetrieved);

System.out.println("\nWill display our modified message below \n");
System.out.println(ourPipeParser.encode(orderResultsHl7Message));

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

}

public static String readHL7MessageFromFileAsString(String fileName) throws Exception {
return new String(Files.readAllBytes(Paths.get(fileName)));
}

我期望消息对象。但输出给了我一条错误消息:

ca.uhn.hl7v2.parser.EncodingNotSupportedException: Determine encoding for message.

以下是消息的前 50 个字符供引用,尽管这可能不是问题所在:

.MSH|^~\&|DH3x|Dymind|||20190421171520||ORU^R01|20

最佳答案

我认为这是因为消息字符串中的前导点和尾随点。此外,您还有一个 ORU^R01 及其在同一消息字符串中的响应。这与点相结合可能会导致解析错误。

您可能需要显式调用 msh.getEncodingCharacters() 并检查其返回值(或检查异常堆栈跟踪)

关于java - 使用java套接字和HAPI的HL7消息解析错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56206702/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com