leveraging base 64 encoding on outbound messages

Homepage Clovertech Forums Read Only Archives Cloverleaf General leveraging base 64 encoding on outbound messages

  • Creator
    Topic
  • #55064
    Andres Alvarez
    Participant

    I have a need to base64 encode outbound messages for a particular interface. How would I best accomplish this? Ive been told that Cloverleaf allows you to leverage a built in base 64 encoder.

    The script I am working with is below. I have to encode the hl7 message, not the soapware wrapper.  Guidance is much appreciated.  

    ######################################################################

    # Name:      tps_batch_bos_imm

    # Purpose:  

    # UPoC type: tps

    # Args:      tps keyedlist containing the following keys:

    #            MODE    run mode (“start”, “run”, “time” or “shutdown”)

    #            MSGID   message handle

    #            CONTEXT tps caller context

    #            ARGS    user-supplied arguments:

    #                    

    #

    # Returns:   tps disposition list:

    #            

    #

    # Notes:     1: Add seg BHS and BTS

    #

    # History:  

    #                

    proc tps_batch_bos_imm { args } {

       global HciConnName                             ;# Name of thread

       

       keylget args MODE mode                         ;# Fetch mode

       set ctx “”   ; keylget args CONTEXT ctx        ;# Fetch tps caller context

       set uargs {} ; keylget args ARGS uargs         ;# Fetch user-supplied args

       set debug 0  ;                                 ;# Fetch user argument DEBUG and

       catch {keylget uargs DEBUG debug}              ;# assume uargs is a keyed list

       set module “tpsChangeHL7/$HciConnName/$ctx” ;# Use this before every echo/puts,

                                                      ;# it describes where the text came from

       set dispList {}                                ;# Nothing to return

       switch -exact — $mode {

           start {

               # Perform special init functions

               # N.B.: there may or may not be a MSGID key in args

               

               if { $debug } {

                   puts stdout “$module: Starting in debug mode…”

               }

           }

           run {

               # ‘run’ mode always has a MSGID; fetch and process it

               

               keylget args MSGID mh

               lappend dispList “CONTINUE $mh”

    set msg [msgget $mh]

    set seglist [split $msg r]

    #echo seglist $seglist

    set bhs {http://www.w3.org/2003/05/soap-envelope”xmlns:urn=”urn:cdc:iisb:2011″> xmlns:wsse=”http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd”> wsu:Id=”UsernameToken-100″ xmlns:wsu=”http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd”>ccghlsevenqa ENGINE=”

    Creator
    Topic
Viewing 3 reply threads
  • Author
    Replies
    • #83964

      Code:

      proc test_encode_pdf { args } {
         package require base64
         global HciRoot HciConnName
         keylget args MODE mode
         set module “test_encode_pdf”
         set dispList {}

         switch -exact — $mode {
             start {}

             run {
                 keylget args MSGID mh
                 set msg [msgget $mh]

                 # Encode the PDF file
                 set fileName test_in.pdf ;# In the process directory
                 set fh [open $fileName r]
                 fconfigure $fh -translation binary
                 set pdf [base64::encode [read $fh]]
                 close $fh

                 # Insert the encoded PDF into the message
                 set segs [split $msg r]
                 set obxLoc [lsearch $segs OBX*]
                 set obx [split [lindex $segs $obxLoc] |]
                 set obx [join [lreplace $obx 5 5 $pdf] |]
                 set segs [lreplace $segs $obxLoc $obxLoc $obx]

                 msgset $mh [join $segs r]
                 set dispList “{CONTINUE $mh}”
             }

             shutdown {}
             time {}
             default {}
         }
         return $dispList
      }

      Code:

      proc test_decode_pdf { args } {
         package require base64
         global HciRoot HciConnName
         keylget args MODE mode
         set module “test_decode_pdf”
         set dispList {}

         switch -exact — $mode {
             start {}

             run {
                 keylget args MSGID mh
                 set msg [msgget $mh]

                 # Get the encoded PDF from the message
                 set segs [split $msg r]
                 #set obx [lsearch -inline -all $segs OBX*]
                 #set pdf [lindex [split [lindex $obx 1] |] 5]
                 set obx [lsearch -inline $segs OBX*]
                 set pdf [lindex [split $obx |] 5]

                 # Create a unique filename for the output
                 set midList [msgmetaget $mh MID]
                 keylget midList NUM msgId
                 set dateTime [clock format [clock seconds] -format %Y%m%d%H%M%S]
                 set fileName “test-$dateTime-$msgId.pdf”

                 # Base64 decode the PDF
                 set fh [open $fileName w] ;# In the process directory
                 fconfigure $fh -translation binary
                 puts $fh [base64::decode $pdf]
                 close $fh

                 set dispList “{CONTINUE $mh}”
             }

             shutdown {}
             time {}
             default {}
         }
         return $dispList
      }

      -- Max Drown (Infor)

    • #83965
      John Stafford
      Participant

      Max, thanks so much for these scripts. Where should these procs be placed? On the inbound/outbound tps? On the route?

      Specifically, I am looking to take a message with a base64 encoded PDF and write the PDF file out to a directory using the decode function.

    • #83966

      These are TPS procs. The can be used as Inbound TPS, Xlate pre-procs or post-procs, or Outbound TPS procs. You will need to modify the procs to work in the proper context and for your exact needs. These procs are only examples of how the encoding and decoding can be done.

      -- Max Drown (Infor)

    • #83967
      Christopher Wells
      Participant

      Thanks for posting the template procs.

      Christopher Wells

Viewing 3 reply threads
  • The forum ‘General’ is closed to new topics and replies.

Forum Statistics

Registered Users
5,115
Forums
28
Topics
9,290
Replies
34,422
Topic Tags
286
Empty Topic Tags
10