Is there a way to convert HL7 MDM encoded base64 PDF data to text?

Clovertech Forums Cloverleaf Is there a way to convert HL7 MDM encoded base64 PDF data to text?

  • Creator
    Topic
  • #117027
    Jerry Sawa
    Participant

      We are on Cloverleaf 6.1.1.  Our EMR sends outgoing HL7 MDM messages outbound as base64 encoded PDFs.  A possible new vendor can not accept base64 encoded messages.  Is there a way to convert the encoded base64 data to text?

      If so,

      1. How would I convert it?
      2. The base64 encoded data is all contained within one OBX segment.  Once converted, would the text report just look like one huge unformatted paragraph?

      Thanks in advance.

    Viewing 6 reply threads
    • Author
      Replies
      • #117028
        David Barr
        Participant

          Here’s some code that translates from PDF to both RTF and TXT.

          https://pastebin.com/vJ4czmpq

          You can use “pdftotext” to convert to text, but there may be additional formatting tweaks required to get it to look nice. This code does some stuff like replacing windows extended characters with ascii equivalents for some characters (non-blocking space and hypen).

        • #117029
          Jim Kosloskey
          Participant

            It is quite possible your receiving system could choke on the non-encoded data as HL/7 separators could now be exposed.

            email: jim.kosloskey@jim-kosloskey.com 29+ years Cloverleaf, 59 years IT - old fart.

          • #117231
            Brian Duncan
            Participant

              To answer your question and for anyone else who happens to read this, I do not think you should ever want to do this because the amount of support effort and risk of corrupting data is far outweighed by having this handled on the sending side, which should be an easy task as it is probably just some reconfiguration at most. You really should have your sender send non-encoded and HL7 escaped data if that is how you want to forward it on.

              I feel like by doing it within Cloverleaf code, even when you get it working it is just a bandaid compared to having your sender do it.

              With that said, to get your incoming data out of base64 is pretty simple in TCL… simply add this command (to any scripting location you want, probably even within an Xlate copy?):

              set unencodedData [decode $base64encodedinput ]

              That is the easy part. If you were to dump $unencodedData into a file, say “output.pdf” you would see your document.

              However, as Jim says above, continuing that data as HL7 is another story. You will now have a document that needs to be prepared/escaped for HL7 before it can be forwarded (escape ampersands, backslashes, handle spacing, etc). Pretty much all of David’s code above is to handle this piece.

              Good luck!

            • #117232
              Jim Kosloskey
              Participant

                Personally I would have the receiving system become compliant with the standard. That should not be too difficult for them to do and it will make them more marketable as this is a common way to transfer data.

                Since you indicate this is a prospective system to be acquired, now is the time to negotiate that change in order to be acceptable to your organization I would think. This is when you have the most leverage to get the receiving system doing what it should.

                The sending system is following the standard and thus I don’t think should be enjoined to do anything.

                But you have options.

                email: jim.kosloskey@jim-kosloskey.com 29+ years Cloverleaf, 59 years IT - old fart.

              • #117550
                Scott Caldwell
                Participant

                  Turns out I am trying to do something similar – the PDF is encoded and I want to extract it into a file structure.

                  This is the code I am using, and it does create a file, but the PDF reader I am using (Adobe) says the file is “damaged”.

                  Up to this point, I have isolated the field into a variable then decode the variable and write to file:

                  set unencodedData [decode $OBX5_4 ]
                  echo unencodedData:$unencodedData

                  set outfilename $OBX3_4
                  set fileId [open $outfilename “w”]
                  puts $fileId $unencodedData
                  close $fileId

                  So…what am I doing wrong?  I have taken the value in $OBX5_4 and pasted it into a BASE64 to PDF converter (https://base64.guru/converter/decode/pdf) and it created the document just fine.

                  Thanks,

                  Scott

                   

                   

                • #117551
                  Jim Kosloskey
                  Participant

                    Perhaps you need to do a fconfigure on the file using the -translation switch with binary as its argument.

                    email: jim.kosloskey@jim-kosloskey.com 29+ years Cloverleaf, 59 years IT - old fart.

                  • #117552
                    Scott Caldwell
                    Participant

                      Adding this line did the trick.  Thank you for the help!

                      set outfilename $OBX3_4
                      set fileId [open $outfilename “w”]
                      fconfigure $fileId -encoding binary -translation binary
                      puts $fileId $unencodedData
                      close $fileId

                  Viewing 6 reply threads
                  • You must be logged in to reply to this topic.