crs4 / hl7apy

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

Escape new lines in FT with "\.br\" #85

Closed Denhai closed 3 years ago

Denhai commented 3 years ago
from hl7apy.core import Segment

text = "line 1\nline 2"
text = text.replace('\n', '\\.br\\')

obx = Segment('obx')
obx.obx_1 = '1'
obx.obx_2 = 'FT'
obx.obx_5 = text
print(obx.obx_5.to_er7())
# outputs:
# line 1\E\.br\E\line 2

# expected:
# line 1\.br\line 2

Am I going about this the wrong way?

svituz commented 3 years ago

Hi @Denhai. This is the correct behavior because the "\" is required to be escaped by HL7 with the sequence \E. Your counterpart should understand that that sequence should be interpreted as '\'