当前位置:网站首页>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,重写一个对应的实体!
边栏推荐
- Wealth freedom skills: commercialize yourself
- Arduino string to hexadecimal number for large color serial port screen.
- 【解决】CMake was unable to find a build program corresponding to “Unix Makefiles“.
- How to prompt
- OpenAPI 3.0 规范-食用指南
- 解析社交机器人中的技术变革
- Utonmos adheres to the principle of "collection and copyright" to help the high-quality development of traditional culture
- Notes on the 3rd harmonyos training in the studio
- 力扣(LeetCode)175. 组合两个表(2022.06.24)
- 校园创客空间的硬件造物原理
猜你喜欢

Authorization of database

Business process diagram design

双碳红利+基建大年 | 图扑深耕水利水电绿色智能装备领域

Camtasia 2022 nouvelle vidéo d'ordinateur d'enregistrement ultra - clair

解析创客空间机制建设的多样化

Lumen Analysis and Optimization of ue5 global Lighting System

Notes on the 3rd harmonyos training in the studio

Google recommends using kotlin flow in MVVM architecture

Install development cross process communication

解析少儿编程的多元评价体系
随机推荐
Translation notes of orb-slam series papers
GStreamer allocator and pool
Analysis on the diversification of maker space mechanism construction
How to prompt
GD32 ADC采集电压
The "more" option of Spreadtrum platform dearmcamera2 is removed
arduino字符串转16进制数 大彩串口屏用。
[QT] custom control - switch
Problems encountered in project deployment - production environment
Limit the input character length to 1 character in English and 2 characters in Chinese
数据库查询语句SQL中like、%、-的区别
How to adjust face input size
Analysis of the multiple evaluation system of children's programming
浅谈虚拟内存与项目开发中的OOM问题
[reading papers] fbnetv3: joint architecture recipe search using predictor training network structure and super parameters are all trained by training parameters
【论文笔记】Deep Reinforcement Learning Control of Hand-Eye Coordination with a Software Retina
Learn from Taiji makers - mqtt (V) publish, subscribe and unsubscribe
《你不可不知的人性》經典語錄
The difference between like,%, - in database query SQL
Question about SQL: SQL question -- SQL code for multiple account logins