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

Question: Parsed message structure abstraction confusion #108

Open pbrunnen opened 1 year ago

pbrunnen commented 1 year ago

Hello all, I will not purport to be an HL7 guru, but I'm rather confused by the parsed structure that comes out of hl7apy and I'm not clear if this is an error in my understanding of HL7 or in my understanding of hl7apy. I'm not finding any documentation on the structure of messages in hl7apy (and maybe none exists).

For instance, when parsing an ORM_O01 order, I have the Order object with ORC and OBR. When I read the examples and the wiki page by Mr. Michael Sarfati, it seems that I should be able to run the HL7 string into the parse_message function and the output should be structured by groups of MSH, PID, OBR, ORM, etc. so with the example given: "message.pid.pid_3.value" should work, but it does not and I have to use "message.ORM_O01_PATIENT.pid.patient_identifier_list.value" sometimes and "message.ORM_O01_PATIENT.pid.patient_identifier_list.id.value" others.

What I find extremely confusing is the OBR segment where I need to call things like "message.ORM_O01_ORDER.ORM_O01_ORDER_DETAIL.ORM_O01_OBRRQDRQ1RXOODSODT_SUPPGRP.obr" or "message.ORM_O01_ORDER.ORM_O01_ORDER_DETAIL.ORM_O01_CHOICE.obr". To me, the messages seem the same, but I don't understand these extra abstractions... I would assume they mean something, else they wouldn't be there... but how am I programmatically supposed to know when these extra layers are supposed to take effect? I was working with the HAPI library previously and I had not come across this before...

Any pointers or documentation would be most appreciated!

svituz commented 1 year ago

Dear @pbrunnen, HL7apy follows the structures of the HL7 messages. The HL7 messages gather groups of segments into groups, such as ORM_O01_ORDER, which are not directly represented in the serialization of the messages but are logically present. So when you parse an ORM_O01 message, HL7apy creates an instance of the message gathering the segments into the groups according to the official HL7 structure. You can find the structure in the versions' sub-packages (v2_x) starting from messages, groups, segments, fields, and so on. Hope this helps.

PS: ORM_O01_OBRRQDRQ1RXOODSODT_SUPPGRP is definitely weird :)

pbrunnen commented 1 year ago

Hi @svituz Appreciate the follow-up and confirming that this one group is strange...

Yea, I get the basic structure of the interrelationship of objects like OBR being a part of the ORC, but some of the small stuff like PID example where in one message it is "patient_identifier_list.value" and another it is "patient_identifier_list.id.value"... I guess I'm missing the distinction here of why it is "id" one time and not another.

Things like "ORM_O01_ORDER" and "ORM_O01_ORDER_DETAIL" all make sense... but then "ORM_O01_CHOICE" or "ORM_O01_OBRRQDRQ1RXOODSODT_SUPPGRP" don't to me.

I'll look into the structure files to see if I can understand them better. Thanks!