No announcement yet.

Multiple Base64 decoding

  • Filter
  • Time
  • Show
Clear All
new posts

  • Multiple Base64 decoding

    I'm trying to decode multiple base64 lines in a single HL7 message into individual files, although I'm only getting the last one. The filename is derived from OBX.3.1 and the report from OBX.5.1


    The code i'm using:

    for each (obx in msg.OBX)
    var obx31 = obx['OBX.3']['OBX.3.1'].toString();
    var obx51 = obx['OBX.5']['OBX.5.1'].toString();

    Any tips on how to accomplish this would be greatly appreciated!

    Thank you,
    Last edited by mhaase; 02-20-2019, 09:10 AM. Reason: typo

  • #2
    You're overwriting the report variable every time. Use a different variable for each iteration of the loop
    Jon Bartels

    Zen is hiring!!!!
    Talented healthcare IT professionals wanted. Engineers to sales to management.
    Good benefits, great working environment, genuinely interesting work.


    • #3
      My initial post of the code had a typo: $gc('report',obx31) --> $gc('fn',obx31)

      The issue is that the first two lines don't appear to be processed when a message is received.


      • #4
        Like he said, you're using the same globalChannelMap key (which isn't the appropriate map in this case, anyway) on every iteration of the loop. When the loop is finished, the value of the key holds the last thing that was stored to that key.

        You're likely going to run into issues once you get your loop figured out. If you are trying to use a File Writer, you can only write one file per message. You'll either want to write the files (using java/javscript) in the same place where your are doing your loop (either a transformer or javascript writer) or route the files as separate message to a second channel that can use a File Writer to write 1 file at a time.

        Either way, you shouldn't need to store the pdfs in a mirth Map at all. If writing the files in the loop itself, you don't need to store them. If routing to a second channel, it would be better to store them in attachments in the first channel and pass the extended attachment id to the second channel if you are using mirth 3.5+. Otherwise, the pdf should be the message body. You can include the filename and path as sourceMap variables in the new message.