Replacing HL7 segments

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf Replacing HL7 segments

  • Creator
    Topic
  • #47619
    David Harrison
    Participant

      I need to replace the ADT^A31 segment in an HL7 message header with ADT^A28 using tcl.

      MSH|^~&|CLI|CLOPR2^01|ADB|A|20050117141247||ADT^A31|200501171412471057|T|2.3

      Any help would be appreciated.

      Dave Harrison

      Frimley Park Hospital NHS Trust

    Viewing 5 reply threads
    • Author
      Replies
      • #56286
        Dennis Pfeifer
        Participant

          Just curious .. why not perform the modification in an Xlate ..?

          { { OP COPY }

             { ERR 0 }

             { IN =A28 }

             { OUT {{0(0).MSH.#9.[1]}} }

          }

        • #56287
          Alise Blankenship
          Participant

            Hi David,

            We do this for A44s changed to A35s. I am including an attachment of the tcl code we use. Try this.

            Good Luck.

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

            # Name:         Cloverleaf Template

            # Purpose:      

            # UPoC type:    tps

            # Args:         tps keyedlist containing the following keys:

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

            #               MSGID   message handle

            #               ARGS    user-supplied arguments:

            #                      

            #

            # Returns: tps disposition list:

            #          

            #

            proc A44_to_A35 { args } {

               keylget args MODE mode                      ;# Fetch mode

               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

                   }

                   run {

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

                       keylget args MSGID mh

                       set msg [msgget $mh]

                       set addMsg [msgcreate -class engine -type data -recover]

                       set splitMsg [split $msg r]

                       set msgTest [lindex [split [lindex [split [lindex $splitMsg [lsearch

            -glob $splitMsg “MSH|*”]] |] 8] ^] 1]

                         if {$msgTest == “A44”} {

                         set test [lindex [split [lindex $splitMsg [lsearch -glob $splitMsg

            “PV1|*”]] |] 2]

                           foreach seg $splitMsg {

                             set splitSeg [split $seg |]

                             set segID [string range $seg 0 2]

                               switch -exact $segID {

                                   MSH { regsub -all A44 $seg A35 newSeg

                                         regsub -all A44 $seg $type addSeg

                                         append mergeMsg $newSeg[format %c 13]

                                         append adtMsg $addSeg[format %c 13]

                                   }

                                   EVN { regsub -all A44 $seg A35 newSeg

                                         regsub -all A44 $seg $type addSeg

                                         append mergeMsg $newSeg[format %c 13]

                                         append adtMsg $addSeg[format %c 13]

                                   }

                                   PID { append mergeMsg $seg[format %c 13]

                                         append adtMsg $seg[format %c 13]

                                   }

                                   PV1 { append mergeMsg $seg[format %c 13]

                                         append adtMsg $seg[format %c 13]

                                   }

                                   DG1 { append mergeMsg $seg[format %c 13]

                                         append adtMsg $seg[format %c 13]

                                   }

                                   MRG { append mergeMsg $seg[format %c 13]

                                   }

                               }

                           }

                        set mergeMsg [string trimright $mergeMsg r]

                        set adtMsg [string trimright $adtMsg r]

                      #  set fullMsg $adtMsgn$mergeMsgn

                        msgset $mh $adtMsg

                        msgset $addMsg $mergeMsg

                        lappend dispList “CONTINUE $mh”

                        lappend dispList “CONTINUE $addMsg”

                      } else { lappend dispList “CONTINUE $mh” }

                   }

                   time {

                       # Timer-based processing

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

                   }

                   default {

                       error “Unknown mode ‘$mode’ in blank”

                   }

               }

               return $dispList

            }

          • #56288
            Kevin Scantlan
            Participant

              If you want to modify a field in a tcl, use the script replaceHL7Field that comes with the engine.

            • #56289
              David Harrison
              Participant

                It’s ok, I worked out how to do it with regsub — {ADT^A31} $my_msg {ADT^A28} my_msg.

                The reason I’m doing it is that I want to change the message type and resend it if I get a particular error message the first time. I’m modifying one of the recovery procs, validate_reply_38 to achieve this.

              • #56290
                Dennis Pfeifer
                Participant

                  Ahh .. clear .. Thanks David ..

                  Dennis

                • #56291
                  David Harrison
                  Participant

                    Thank you all for your replies and valuable assistance.

                    Dave

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