1

I was trying to create segment MSH in a HL7 message

from hl7apy.core import Message, Segment, Field

def create_msh():
    msh = Segment("MSH")
    msh_2 = Field("msh_2")
    msh_2.value = "^~\&"
    msh.add(msh_2)
    print(msh.value)
    return msh

create_msh()

The print result is:

MSH|^~\

Do not know why the last symbol ampersand & is NOT added to the second field in MSH segment. How to fix this issue? Your help is appreciated.

Regards, Arthur

Arthur
  • 171
  • 1
  • 10
  • I have probably spent too much time looking at this, but I think when you are adding the value, it is treating the `&` as a subcomponent separator and not as part of the value defining the subcomponent separator. I haven't been able to figure out how to escape it. If you make a Message that includes the MSH segment such as Message("ADT_A01"), then the MSH segment is automatically created for you with the 2nd field automatically set as expected. I suspect there is some special handling based on the traversal_parent but I have not untangled it all yet. – nigh_anxiety May 06 '23 at 13:39

0 Answers0