Я хочу получить сегменты OBX, а затем поле № 3, идентификатор наблюдения. В настоящее время мой код повторяет все, пытаясь найти решение для вывода только OBX.field3, для набора данных с несколькими сообщениями hl7.
hl7 = open(r"file.txt", "r").read()
try:
msg = parser.parse_message(hl7.replace('\n', '\r'), find_groups=True, validation_level=2)
except UnsupportedVersion:
msg = parser.parse_message(hl7.replace('\n', '\r'), find_groups=True, validation_level=2)
indent = " "
indent_seg = " "
indent_fld = " "
def subgroup (group, indent):
indent = indent + " "
print (indent , group)
for group_segment in group.children:
if isinstance(group_segment, Group):
subgroup (group_segment)
else:
print(indent_seg, indent ,group_segment)
for attribute in group_segment.children:
print(indent_fld, indent ,attribute, attribute.value)
def showmsg (msg):
print(msg.children[1])
for segment in msg.children:
if isinstance(segment, Segment):
print (indent ,segment)
for attribute in segment.children:
print(indent_fld, indent, attribute, attribute.value)
if isinstance(segment, Group):
for group in segment.children:
print (indent,group)
for group_segment in group.children:
if isinstance (group_segment, Group):
subgroup (group_segment, indent)
else:
print(indent_seg, indent ,group_segment)
for attribute in group_segment.children:
print(indent_fld, indent, attribute, attribute.value)
showmsg (msg)`enter code here