crs4 / hl7apy

Python library to parse, create and handle HL7 v2 messages.
http://crs4.github.io/hl7apy/
MIT License
224 stars 88 forks source link

HL7 message type parsing issue #73

Closed chrisrana closed 3 years ago

chrisrana commented 4 years ago

I am getting below hl7 message from hospital.

msg='MSH|^~\\&|||||20200402130324.9500+0530||ORU^R01^ORU_R01|2u9csdvk3j4dx047|P|2.6|||AL|NE|||||IHE_PCD_001^IHE PCD^1.3.6.1.4.1.19376.1.6.1.1.1^ISO\rPID|||16242008^^^GHERN MRN^MR||hvans^hexandria^^^^^L||19651210|||||||||||1622009651210\rPV1||I|SICU^6^1^Aiid Hospital^^^hermann||||^Smith^John||||||||||^Nora^John\r'

t1=parse_message(t) t1._get_children() [(,), (,)]

I doesnot parse properly. I feel issue is because of ORU^R01^ORU_R01. It doesnot support ORU^R01^ORU_R01.If i replace ORU_R01 it works fine. Let me know how to address this issue

chrisrana commented 4 years ago

I just found that there is already one question similar to this ORU_R01 not validating correctly below line solves the problem.

msg_object = parse_message(msg_num, find_groups=False)

Anyway i want to know what find_groups=False does ?

svituz commented 3 years ago

Hi @chrisrana, sorry for the (very) late response. I could parse the message correctly, probably I already solved that bug in the new commits. I'm planning a new release today or tomorrow. Regarding the find_groups flag: when True the parser creates the groups for the message as wanted by the structure. This means that, when traversing the message, you need to access the group. When the flag is False, the parser doesn't create the groups and you can access the segments directly. Notice that the validation fails in the second case because the validator requires the correct hierarchy Here is a snippet showing the differences:

>>> msg = \ 
       'MSH|^~\\&|||||20200402130324.9500+0530||ORU^R01^ORU_R01|2u9csdvk3j4dx047|P|2.6|||AL|NE|||||IHE_PCD_001^IHE PCD^1.3.6.1.4.1.19376.1.6.1.1.1^ISO\r' \
       'PID|||16242008^^^GHERN MRN^MR||hvans^hexandria^^^^^L||19651210|||||||||||1622009651210\r' \
       'PV1||I|SICU^6^1^Aiid Hospital^^^hermann||||^Smith^John||||||||||^Nora^John\r'
>>> m = parse_message(msg, find_groups=False)
>>> print(m.children)
[<Segment MSH>, <Group ORU_R01_PATIENT_RESULT>]

>>> m = parse_message(msg, find_groups=True)
>>> print(m.children)
[<Segment MSH>, <Segment PID>, <Segment PV1>]