简体   繁体   English

解析HL7 v2并转换为JSON / XML

[英]Parsing HL7 v2 and converting to JSON/XML

I need to process the content of HL7 v2.5 (OUL_R22) messages (scale: 10⁶ single messages and more) using python. 我需要使用python处理HL7 v2.5(OUL_R22)消息的内容 (比例:10个单条消息以及更多)。 To do so, I'm parsing the HL7 messages. 为此,我正在解析HL7消息。 At first I was using the python package HL7apy to convert to JSON (see Stack: HL7 to JSON conversition ). 最初,我使用python包HL7apy转换为JSON(请参阅Stack:从HL7到JSON转换 )。 The output looks good, but some errors/bugs occurred while processing and it's really slow. 输出看起来不错,但是在处理过程中发生了一些错误/错误,而且确实很慢。 So I tried out the java library HAPI to convert to XML (see Stack: Converting HL7 v2 to JSON ). 因此,我尝试了将Java库HAPI转换为XML(请参见堆栈:将HL7 v2转换为JSON )。 The XML files can be read as dict using the package xmltodict . 使用包xmltodict可以将XML文件作为dict读取。 Compared to HL7apy the conversion is 50 times faster. 与HL7apy相比,转换速度快了50倍。 But the structure of the output is inconsistent/heterogeneous. 但是输出的结构不一致/异质。 HAPI somehow wraps segments into new groups like OUL_R22.SPECIMEN / .ORDER / .RESULT . HAPI以某种方式将段包装到新的组中,例如OUL_R22.SPECIMEN / .ORDER / .RESULT The question is: 问题是:

Can HAPI produce a flat output or an array which has a length equal to the unique occurrences of segments of the input? HAPI是否可以产生平面输出或长度等于输入段唯一出现长度的数组? Or can you just add a "keep original structure" somewhere? 还是可以在某个地方添加“保留原始结构”?


To make things clearer: I need to process the content of the OBX-segment. 为了使事情更清楚:我需要处理OBX段的内容。

The input would look like this: 输入如下所示:

MSH|...
PID|...
PV1|...
SPM|...
OBR|...
ORC|...
NTE|...
NTE|...
TQ1|...
OBX|...
OBX|...
...

The structure of the output looks like this (as XML of course): 输出的结构如下所示(当然是XML):

OUL_R22
    MSH
    OUL_R22.PATIENT
    OUL_R22.VISIT
    OUL_R22.SPECIMEN
        OUL_R22.ORDER
            OUL_R22.TIMING_QTY
                ...
            OUL_R22.RESULT
                OBX
            OUL_R22.RESULT
                OBX

Sometimes it's like this: 有时是这样的:

OUL_R22
    ...
    OBX

Or like this: 或像这样:

OUL_R22
    ...
    OUL_R22.SPECIMEN
        OBX

This is really inconsistent. 这确实是不一致的。


What I want is something like this: 我想要的是这样的:

OUL_R22
    MSH
    PID
    ...
    OBX

Or like this: 或像这样:

[
    {
        "MSH": [],
        "PID": [],
        ...
        "OBX": [],
        ...

Solution so far: 到目前为止的解决方案:

Setting up a Mirth Connect Server to receive and transform the HL7 v2.x messages. 设置Mirth Connect服务器以接收和转换HL7 v2.x消息。

Those groups are a fundamental part of the HL7 syntax - I'm perpetually baffled by Mirth and other interface engines who ignore them in their syntax for working with HL7v2. 这些组是HL7语法的基本组成部分-我一直对Mirth和其他接口引擎感到困惑,他们在使用HL7v2的语法中忽略了它们。

OBR/OBX combinations have lots of groups because there is lots of nested relationships between the two. OBR / OBX组合具有很多组,因为两者之间存在很多嵌套关系。 For example, NTEs following OBR apply to the OBR as whole, but NTEs following each OBX apply to that OBX individually. 例如,OBR之后的NTE整体适用于OBR,但每个OBX之后的NTE分别适用于该OBX。

Here's what this looks like in the HL7 spec. 这就是HL7规范中的外观。 这就是HL7规格中的OBR / OBX外观

So referencing something like OBSERVATION[0].NTE[0] gets you exactly what you want. 因此,引用诸如OBSERVATION [0] .NTE [0]之类的东西可以为您提供所需的确切信息。 As far as I can tell, Mirth forces you to write code to solve this problem as well as this one. 据我所知, Mirth强迫您编写代码以解决这一问题

At the end of the day, solve the problem how you see fit, but deviating from the standard may come back to back bite you. 归根结底,解决您认为合适的问题,但是背离标准可能会背对背咬您。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM