使用hl7apy分析HL7时出错

2024-03-29 14:52:25 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用hl7apy来解析python中的hl7文件,并遵循this链接。当我使用样品.hl7我得到了预期的结果,但当我使用我自己的hl7文件,我得到了下面的错误

Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
  File "hl7apy/parser.py", line 82, in parse_message
    m.structure_by_name)
  File "hl7apy/parser.py", line 144, in parse_segments
    reference))
  File "hl7apy/parser.py", line 189, in parse_segment
    reference=reference)
  File "hl7apy/core.py", line 1564, in __init__
    validation_level, traversal_parent)
  File "hl7apy/core.py", line 632, in __init__
    self._find_structure(reference)
  File "hl7apy/core.py", line 808, in _find_structure
    structure = ElementFinder.get_structure(self, reference)
  File "hl7apy/core.py", line 524, in get_structure
    raise InvalidName(element.classname, element.name)
  hl7apy.exceptions.InvalidName: Invalid name for Segment: 

我不明白我做错了什么。在

编辑: 这是我正在使用的样品。在

^{pr2}$

代码:这是我用来解析hl7文件的代码,也是我在分析上面链接中提到的示例hl7文件时使用的代码。在

from hl7apy import parser
from hl7apy.exceptions import UnsupportedVersion

hl7 = open('ICD9.hl7', 'r').read()

try:
    m = parser.parse_message(hl7)
except UnsupportedVersion:
    m = parser.parse_message(hl7.replace("n", "r"))

Tags: 文件代码nameinpycoreparsermessage
1条回答
网友
1楼 · 发布于 2024-03-29 14:52:25

你应该在这里显示你的文件中的信息,以获得明确的答案。在

但最可能的原因是,您的文件内容不遵循HL7规则。是否确定使用了正确的段分隔符(ASCII 13或HEX 0D)?您是否使用非标准段名称?在

只要检查一下Free Online HL7 Messages Validation就可以得到这些

ID  ELEMENT_TYPE POSITION   LINE_NO VALIDATION ERROR
1   Field        MSH.9.3    1       Component required
2   Field        PID.7      2       Invalid date time format : '1957009'
3   Component    PID.9.7    2       Invalid table entry value : '3216' for table Name Type
4   Component    PID.9.7    2       Value '3216' length (4) exceed limit (1)
5   Component    PID.11.6   2       Invalid table entry value : 'INDIA' for table Country Code
6   Component    PID.11.6   2       Value 'INDIA' length (5) exceed limit (3)
7   Field        PID.12     2       Field should not contain component(s)
8   Component    PID.18.1   2       Field required but has no value.
9   Field        ORC.5      4       Invalid table entry value : 'D' for table Order status
10  Component    ORC.7.4    4       Invalid date time format : '20103102300'
11  Component    ORC.7.5    4       Invalid date time format : '216061102300'
12  Field        ORC.15     4       Invalid date time format : '201606310230'
13  Field        OBR.14     5       Invalid date time format : '201208056'
14  Field        OBR.22     5       Invalid date time format : '201280058'
15  SubComponent OBR.27.1.1 5       Invalid numeric format : 'R'
16  Component    OBR.27.4   5       Invalid date time format : '2012070957'
17  Component    OBR.32.2   5       Invalid date time format : 'VRNEY,SCT'

但这并不能解释您的错误信息。你确定你读了邮件文件并分析了内容吗?在

您的代码有错误。应该是的

^{pr2}$

如果要替换错误的段分隔符。在

相关问题 更多 >