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

question(2.3): escaping fields of type `varies` #82

Closed r1b closed 3 years ago

r1b commented 3 years ago

We find that the caret (^) is not escaped in fields of type varies when using version 2.3. All other reserved characters appear to be escaped - is this the expected behavior?

e.g:

f = Field("OBX_5")
f.value = "foobar^baz"
print(f.to_er7())  # "foobar^baz"
r1b commented 3 years ago

We figured out the problem here - we needed to set the type of OBX_5 at runtime to match OBX_2 like so:

obx_5 = Field("OBX_5", datatype="TX")
obx_5.value = TX("foobar^baz")
print(f.to_er7()) # "foobar\S\baz
# now add the field to the observation
obx.add(obx_5)

If you don't explicitly define the type of obx_5, e.g doing something like this:

obx.obx_5 = "foobar^baz"

then the type of obx_5 is 'varies' and the caret will not be escaped.


This could be a nice documentation item but otherwise the behavior of hl7apy seems correct, closing accordingly.