crs4 / hl7apy

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

ED data type with (long) base64 data #45

Closed ThomasWaldmann closed 3 years ago

ThomasWaldmann commented 5 years ago

I'm currently looking at parsing data that looks like this:

OBX|22|ED||HGRAM|eyJQTFQiOiB7ImNvdW50IjogODAsICJtaW4iOiAwLCAibWF4IjogMzAsICJmaWx0ZXIiOiA3LCAiZGlzYyI
6IFs2Nl0sICJ2YWx1ZXMiOiB7IlBMVCI6IFswLCAwLCAwLCAwLCAwLCAwLCAwLCAxLCAxLCAyLCAzLCA0LCA1LCA3LCA4LCAxMSw
gMTMsIDE2LCAxOSwgMjIsIDI1LCAyOCwgMzEsIDMzLCAzNCwgMzUsIDM1LCAzNCwgMzMsIDMyLCAzMCwgMjgsIDI3LCAyNSwgMjM
sIDIxLCAyMCwgMTgsIDE2LCAxNCwgMTMsIDEyLCAxMSwgOSwgOCwgOCwgNywgNiwgNSwgNCwgNCwgMywgMywgMiwgMiwgMiwgMiw
gMiwgMiwgMiwgMiwgMSwgMSwgMSwgMSwgMSwgMSwgMSwgMSwgMSwgMSwgMSwgMSwgMSwgMSwgMSwgMSwgMSwgMSwgMV19fSwgIlJ
CQyI6IHsiY291bnQiOiA4MCwgIm1pbiI6IDAsICJtYXgiOiAyNTAsICJmaWx0ZXIiOiAyLCAiZGlzYyI6IFsxMF0sICJ2YWx1ZXM
iOiB7IlJCQyI6IFswLCAzLCAxOCwgNDQsIDU4LCA0OCwgMjcsIDEzLCA2LCAzLCAyLCAyLCA1LCAxMSwgMjQsIDQ3LCA4MCwgMTE
4LCAxNTksIDE5NCwgMjI0LCAyNDUsIDI1NCwgMjQ3LCAyMjYsIDE5OSwgMTc4LCAxNjMsIDE0NCwgMTIzLCAxMDcsIDk4LCA5Myw
gODcsIDc5LCA2OCwgNjMsIDU4LCA0OSwgNDEsIDM1LCAyOSwgMjQsIDIwLCAxNiwgMTMsIDEwLCA4LCA3LCA2LCA2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DIsIDIsIDIsIDMsIDQsIDUsIDcsIDksIDEyLCAxNCwgMTcsIDE5LCAyMCwgMjEsIDIxLCAyMSwgMjAsIDI
wLCAxOSwgMTgsIDE2LCAxNSwgMTQsIDEzLCAxMSwgMTAsIDksIDgsIDgsIDcsIDcsIDYsIDUsIDUsIDQsIDQsIDQsIDQsIDQsIDQ
sIDMsIDMsIDMsIDMsIDIsIDIsIDIsIDIsIDIsIDIsIDIsIDIsIDIsIDJdfX19||||||P

This is a base64-encoded json string. I got this from a data sheet, not sure what character there should be at the line ends.

If I feed this into the hl7apy parser, it only yields data from the first line in the result and ignores all the subsequent lines' encoded data.

Not sure right now if I am doing something wrong or whether this is just not supported?

ThomasWaldmann commented 5 years ago

I also tried feeding this as a single line (removing all line endings), but then it complains about a too long string.

svituz commented 5 years ago

Hi @ThomasWaldmann, sorry for the late answer. I tried to parse your segment and I succeeded. This is the code I used:

from hl7apy.parser import parse_segment
obx = "OBX|22|ED||HGRAM|eyJQTFQiOiB7ImNvdW50IjogODAsICJtaW4iOiAwLCAibWF4IjogMzAsICJmaWx0ZXIiOiA3LCAiZGlzYyI"\
      "6IFs2Nl0sICJ2YWx1ZXMiOiB7IlBMVCI6IFswLCAwLCAwLCAwLCAwLCAwLCAwLCAxLCAxLCAyLCAzLCA0LCA1LCA3LCA4LCAxMSw"\
      "gMTMsIDE2LCAxOSwgMjIsIDI1LCAyOCwgMzEsIDMzLCAzNCwgMzUsIDM1LCAzNCwgMzMsIDMyLCAzMCwgMjgsIDI3LCAyNSwgMjM"\
      "sIDIxLCAyMCwgMTgsIDE2LCAxNCwgMTMsIDEyLCAxMSwgOSwgOCwgOCwgNywgNiwgNSwgNCwgNCwgMywgMywgMiwgMiwgMiwgMiw"\
      "gMiwgMiwgMiwgMiwgMSwgMSwgMSwgMSwgMSwgMSwgMSwgMSwgMSwgMSwgMSwgMSwgMSwgMSwgMSwgMSwgMSwgMSwgMV19fSwgIlJ"\
      "CQyI6IHsiY291bnQiOiA4MCwg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AsIDAsIDAsIDAsIDAsIDAsIDAsIDAsIDAsIDAsIDAsIDAsIDEsIDIsIDQsIDUsIDUsIDUsIDQsIDQsIDMsIDM"\
      "sIDMsIDIsIDIsIDIsIDEsIDEsIDEsIDAsIDAsIDAsIDAsIDAsIDAsIDAsIDAsIDAsIDAsIDAsIDAsIDAsIDAsIDAsIDAsIDAsIDA"\
      "sIDAsIDAsIDAsIDAsIDAsIDAsIDAsIDAsIDAsIDAsIDAsIDAsIDAsIDAsIDAsIDAsIDAsIDAsIDAsIDAsIDAsIDAsIDAsIDAsIDB"\
      "dLCAiR1JBIjogWzAsIDAsIDAsIDAsIDAsIDAsIDAsIDAsIDAsIDAsIDAsIDAsIDAsIDAsIDAsIDAsIDAsIDAsIDAsIDAsIDAsIDA"\
      "sIDAsIDEsIDEsIDEsIDIsIDIsIDIsIDMsIDQsIDUsIDcsIDksIDEyLCAxNCwgMTcsIDE5LCAyMCwgMjEsIDIxLCAyMSwgMjAsIDI"\
      "wLCAxOSwgMTgsIDE2LCAxNSwgMTQsIDEzLCAxMSwgMTAsIDksIDgsIDgsIDcsIDcsIDYsIDUsIDUsIDQsIDQsIDQsIDQsIDQsIDQ"\
      "sIDMsIDMsIDMsIDMsIDIsIDIsIDIsIDIsIDIsIDIsIDIsIDIsIDIsIDJdfX19||||||P"
obx_s = parse_segment(obx)
print(obx_s.obx_5.to_er7())

Can you explain more precisely the problem you're experiencing?

Vittorio

svituz commented 3 years ago

I closed the issue since I haven't gotten any other comments for a long time