web stats
Convert PDF as HL7 gives different format - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 06-24-2019, 03:45 AM
Kogan20 Kogan20 is offline
Mirth Newb
 
Join Date: Mar 2019
Location: Sydney, Australia
Posts: 8
Kogan20 is on a distinguished road
Question Convert PDF as HL7 gives different format

The HL7 message coming out of my application usually has the PDF content as Base64 and will be embedded in a single line.

I am using the below code to manually convert an existing PDF as HL7 but this comes as multiple line (like word wrapped in notepad).

Code:
function Base64 (myfile)
{
var fileread = FileUtil.readBytes(myfile);
var encodedb64 = FileUtil.encode(fileread);

return encodedb64;
}
Could anyone help on this.

Output:
Code:
OBX|1|ED|PDF^Display format in PDF^AUSPDI|1|Application^TX^PDF^BASE64^JVBERi0xLjQKJeLjz9MKMyAwIG9iago8PC9UeXBlL1hPYmplY3QvU3VidHlwZS9JbWFnZS9XaWR0
aCA1NzgvSGVpZ2h0IDYzL0xlbmd0aCAzMDY2L0NvbG9yU3BhY2UvRGV2aWNlR3JheS9CaXRzUGVy
Q29tcG9uZW50IDgvRmlsdGVyL0ZsYXRlRGVjb2RlPj5zdHJlYW0KeJztnAt0FNUZx29IwkuCjCAE
sIrD0wIWWDHQCgSYIojQGFhqFSsqZ9FyoKWcMlQ4VtJKl1eFI6ArR6XIw64t0jaQhOFhW6AUloe1
SJK6hFdCoDBASHgnt9/33ZndBZYsBNzA5v4PZ+fe7947s7P3l3u/784dGJOSkpKSkpKSkpKSkpKS
kpKSkpKSkpKSilE5NE1zqAokqvubSN1+uXSU88YbqLquUULXXZZJ03UV7U6rXNg1t2G4NXENv+7S
PUwxldv4zaXuDBmc5LvhvtU41ynBuWGZdM41tJuqKEe7ap3YoBODRfdqHo92u7++VLXL6ugADRFV

Expected Output:
Code:
OBX|1|ED|PDF^Display format in PDF^AUSPDI|1|Application^TX^PDF^BASE64^JVBERi0xLjQKJeLjz9MKMyAwIG9iago8PC9UeXBlL1hPYmplY3QvU3VidHlwZS9JbWFnZS9XaWR0aCA1NzgvSGV
Reply With Quote
  #2  
Old 06-24-2019, 05:24 AM
Jeff Drumm Jeff Drumm is offline
Mirth Newb
 
Join Date: Jun 2019
Posts: 23
Jeff Drumm is on a distinguished road
Default

I'm new to Mirth but I've worked with base64 in other integration engines.


Are you sure that the PDF was in valid format before you attempted to encode it, i.e. can you view it in Acrobat Reader? If yes, have you tried stripping out anything that's not a valid base64 character?
Code:
function Base64(myfile)
{
    var fileread = FileUtil.readBytes(myfile);
    var encodedb64 = String(FileUtil.encode(fileread)).valueOf();
    return encodedb64.replace(/[\x00-\x1F\x7F-\x9F]/g, "");
}
Reply With Quote
  #3  
Old 06-24-2019, 06:27 AM
Jeff Drumm Jeff Drumm is offline
Mirth Newb
 
Join Date: Jun 2019
Posts: 23
Jeff Drumm is on a distinguished road
Default

As it turns out, EOL characters are ignored by most base64 decoders, so it's not usually a problem to have them in the encoded result. Of course HL7 is a special case, since the carriage return is a segment delimiter. You'll need to strip the EOL character(s) out if you want the entire base64-encoded payload in a single segment. My solution probably goes a bit overboard, but it should be platform independent.
Reply With Quote
  #4  
Old 06-24-2019, 10:54 AM
agermano agermano is offline
Mirth Guru
 
Join Date: Apr 2017
Location: Indiana, USA
Posts: 967
agermano is on a distinguished road
Default

This question looked so familiar Someone else just resurrected an old thread with the answer. You can either do a replace like Jeff has done, or you can generate it without the new lines there in the first place.

https://www.mirthcorp.com/community/...7876#post47876
Reply With Quote
  #5  
Old 06-24-2019, 03:37 PM
Kogan20 Kogan20 is offline
Mirth Newb
 
Join Date: Mar 2019
Location: Sydney, Australia
Posts: 8
Kogan20 is on a distinguished road
Smile

Thanks Jeff and Tony for the prompt response.
Sorry for the repeated post.
I have tried this now, and it comes in a single line.
Waiting for confirmation from the EMR if it shows the PDF content correctly.
Reply With Quote
  #6  
Old 06-24-2019, 06:07 PM
Jeff Drumm Jeff Drumm is offline
Mirth Newb
 
Join Date: Jun 2019
Posts: 23
Jeff Drumm is on a distinguished road
Default

Quote:
Originally Posted by Kogan20 View Post
Thanks Jeff and Tony for the prompt response.
Sorry for the repeated post.
I have tried this now, and it comes in a single line.
Waiting for confirmation from the EMR if it shows the PDF content correctly.

Well, I tested the function I posted against a couple of different PDFs and they looked just fine when converted back. So if the EMR isn't showing it correctly it's probably their fault
Reply With Quote
  #7  
Old 06-24-2019, 07:53 PM
Kogan20 Kogan20 is offline
Mirth Newb
 
Join Date: Mar 2019
Location: Sydney, Australia
Posts: 8
Kogan20 is on a distinguished road
Unhappy



Looks like the PDF appears correctly.
But, the problem is I have a text box inserted in PDF that is not visible in the EMR.

Should I insert the text box in any other way, so that it gets retained while converting it as HL7?
Reply With Quote
  #8  
Old 06-25-2019, 03:01 AM
Jeff Drumm Jeff Drumm is offline
Mirth Newb
 
Join Date: Jun 2019
Posts: 23
Jeff Drumm is on a distinguished road
Default

Quote:
Originally Posted by Kogan20 View Post


Looks like the PDF appears correctly.
But, the problem is I have a text box inserted in PDF that is not visible in the EMR.

Should I insert the text box in any other way, so that it gets retained while converting it as HL7?

I'm quite certain tha the text box isn't going missing due to the base64 encode/decode. You can verify this yourself with the code snippet below:


Code:
function Base64(myfile)
{
    var fileread = FileUtil.readBytes(myfile);
    var encodedb64 = String(FileUtil.encode(fileread)).valueOf();
    return encodedb64.replace(/[\x00-\x1F\x7F-\x9F]/g, "");
}

FileUtil.write("/path/to/target.pdf",false,FileUtil.decode((Base64("/path/to/source.pdf"))))
The source.pdf file is the original, and target.pdf is the result of conversion to base64 and back again. If they look the same in Adobe Acrobat Reader, the missing box is absolutely the vendor's fault.


If the vendor won't fix it, there may be a couple of other options:
  • Try different line widths and colors for the bounding box.
  • Render the box and the text it bounds as an image (tiff, png or jpeg) and incorporate that in the generated PDF. I don't know how you're composing the PDF document so that may not be a possibility.
  • See if the vendor supports any non-PDF file/image formats; TIFF is common for FAXes and might be supported.
Reply With Quote
  #9  
Old 06-25-2019, 10:38 PM
Kogan20 Kogan20 is offline
Mirth Newb
 
Join Date: Mar 2019
Location: Sydney, Australia
Posts: 8
Kogan20 is on a distinguished road
Cool

Thanks Jeff,
Sorry that was a false alarm, I just got confirmation that they are able to view the text Box comment in EMR without any issues.

In the meantime, I tried the file write function to check but it took sooo much time and Mirth was stuck. So I exited it and couldn't check if that works or not.
But thanks for your immediate response, really very helpful
Reply With Quote
  #10  
Old 06-26-2019, 03:11 AM
Jeff Drumm Jeff Drumm is offline
Mirth Newb
 
Join Date: Jun 2019
Posts: 23
Jeff Drumm is on a distinguished road
Default

Quote:
Originally Posted by Kogan20 View Post
Thanks Jeff,
Sorry that was a false alarm, I just got confirmation that they are able to view the text Box comment in EMR without any issues.

In the meantime, I tried the file write function to check but it took sooo much time and Mirth was stuck. So I exited it and couldn't check if that works or not.
But thanks for your immediate response, really very helpful

Good news!


I'm a bit surprised that you weren't able to run my code snippet. I had tested it myself in the NotePad++ NppExec script I set up to interactively test and debug Mirth/Rhino Javascript and it worked fine.


Was it a large PDF? The ones I tested with were relatively small.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -8. The time now is 08:50 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2019, vBulletin Solutions, Inc.
Mirth Corporation