当前位置:网站首页>HL7Exception: Can‘t XML-encode a GenericMessage. Message must have a recognized struct
HL7Exception: Can‘t XML-encode a GenericMessage. Message must have a recognized struct
2022-06-26 02:44:00 【book多得】
目录
今天使用Hapi解析一个hl7v2并尝试转为xml格式时碰到了这样的错误
Exception in thread "main" ca.uhn.hl7v2.HL7Exception: Can't XML-encode a GenericMessage. Message must have a recognized structure.
at ca.uhn.hl7v2.parser.XMLParser.doEncode(XMLParser.java:237)
at ca.uhn.hl7v2.parser.Parser.encode(Parser.java:276)
at com.cr.hesb.hl7v2.HL7Helper.hl72xml(HL7Helper.java:164)
at com.cr.hesb.hl7v2.HL7Helper.main(HL7Helper.java:25)
百度了个半天,毫无收获,只能跑去看源码了。
一、示例代码
public static String hl72xml() throws HL7Exception {
String message = "MSH|^~\\&|UMC||ZZJ||20220105101052||ADT^A01^ADT^A01|a8f662b8-6e7a|P|2.6^^&&&&D56D2C42401AAC6F36&&V1.0|||NE|AL||utf-8\n" +
"EVN|REG|20220121235249|||01970836\n" +
"PID||201532012|6521011986122213xx^^^^01||马x明^^^MA ZHI MING||19861222000000|1|||&华容文化路 179 号^华容^岳阳^湖南|||||^^2|||652101198612221332|||^汉族^1||||||86^中国\n" +
"PV1||1|311403^126^^&H002^^^^^^儿科急诊\\T\\急诊科\\T\\专科代码||123||08311056\\S\\朱X峰|||2||||2|2|3|1056\\S\\朱熙峰||1||||||||||||||||||||H0002|0||||20220105100100||||||03-01970836-100^123456^124512^1&4513&2412^^&9:00\\R\\12:00|0|0^1123&20220105100100&245\\S\\张小^^^^\n" +
"IN1|1|A|自费";
HapiContext context = new DefaultHapiContext();
GenericParser normalParse = new GenericParser();
normalParse.getParserConfiguration().setValidating(false);
Message hapiMessage = normalParse.parse(message);
Parser xmlParser = context.getXMLParser();
return xmlParser.encode(hapiMessage);
}二、发现报错的地方

三、为什么会进入报错判断呢?
直接来到 ca.uhn.hl7v2.parser.PipeParser 下的getStructure(String message)方法
1.如下图所示,先获取hl7v2到实现类的那一栏数据。
2.根据获取的数据分割成数组
2.1.若数组长度大于或等于3则直接使用数组的下标为2的数据
2.2.若数组长度小于或等于0&&或为ACK,则直接赋值为ACK
2.3.若数组长度等于2则将两个数据用“_”进行拼接
3.最后根据变量messageStructure的值去找寻对应的Message实现类,若为空则使用GenericMessage类进行实现

四、总结
原因:
所以报错是因为XMLParser.doEncode(Message source)方法不可将实现类为 GenericMessage的转化为xml格式
解决方法:
1.更改数据的messageStructure值(hl7v2实现类的那一栏数据),使其找到对应的实体。
2.继承抽象类AbstractMessage,重写一个对应的实体!
边栏推荐
- 关于#sql#的问题:SQL问题--账号多地登录的SQL代码
- What can Arthas do for you?
- Oracle connectivity issues and Solutions
- R language survival analysis
- Learn Tai Chi Maker - mqtt (IV) server connection operation
- DF reports an error stale file handle
- OpenAPI 3.0 specification - Food Guide
- 【读点论文】FBNetV3: Joint Architecture-Recipe Search using Predictor Pretraining 网络结构和超参数全当训练参数给训练了
- Mysql常用sql语句之修改表名、删除表、获取表信息、删除指定日期的表记录
- 少儿编程对国内传统学科的推进作用
猜你喜欢

Fresh graduates talk about their graduation stories

Learn Tai Chi Maker - mqtt (IV) server connection operation

Win10 computer power management turns on excellence mode

学习太极创客 — MQTT(五)发布、订阅和取消订阅
![[机器翻译]—BLEU值的计算](/img/c3/8f98db33eb0ab5a016621d21d971e4.png)
[机器翻译]—BLEU值的计算

如何提词条

OpenAPI 3.0 specification - Food Guide

The difference between like,%, - in database query SQL

GD32 ADC采集电压

On virtual memory and oom in project development
随机推荐
[solution] the blue screen restart problem of the virtual machine started by the VMware of Lenovo Savior
How to default that an app is not restricted by traffic
应届毕业生谈毕业的故事
R语言 生存分析
【flask入门系列】flask处理请求和处理响应
Leetcode 176 The second highest salary (June 25, 2022)
A few simple ways for programmers to exercise their waist
Utonmos adheres to the principle of "collection and copyright" to help the high-quality development of traditional culture
The difference between like,%, - in database query SQL
Possible values for @supply in kotlin
Can the main RF circuit be removed for projects that do not need the main RF?
文献阅读---优化RNA-seq研究以研究除草剂耐药性(综述)
图扑软件数字孪生海上风电 | 向海图强,奋楫争先
附加:HikariCP连接池简述;(并没有深究,只是对HikariCP连接池有个基本认识)
P2483-[模板]k短路/[SDOI2010]魔法猪学院【主席树,堆】
MySQL增删查改(进阶)
Scratch returns 400
Limit the input character length to 1 character in English and 2 characters in Chinese
PCA and automatic encoder for dimension reduction of R language
golang--channal与select