TCL scripting question

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf TCL scripting question

  • Creator
    Topic
  • #50909
    Tom Arrowsmith
    Participant

      I am trying to write a tcl script which will kill a message if two arguments match (if the ORC-1 = NW and the ORC-2.2 = IBEX)

      I am having some trouble getting it to work. I’d really appreciate it if any of you can take a look. I have the Script placed on the route with arguments defined as {ORIGIN IBEX} and {ORDCONTROL NW}

      I am running Cloverleaf 5.4.1 which I believe limits me to an older tcl version….(8.3.1)

      Here’s the script:

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

      # Name:         kill_IbexNW-ORM

      # UPoC type:    tps

      # Args:         tps keyedlist containing the following keys:

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

      #               MSGID   message handle

      #               ARGS    user-supplied arguments:

      #               ORIGIN Order Origination (ORC-2.2)

      # ORDCONTROL Indicates if order is new (NW) or otherwise (ORC-1)

      # Description:  Kills message if the ORIGIN argument = value in ORC-2.2  AND the ORDCONTROL argument = value in ORC-1

      # Returns: tps disposition list:

      #          $CONTINUE

      #          $KILL

      proc kill_IbexNW-ORM { 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]                                ;# Get message

                 keylget args ARGS.ORIGIN origin  ;# Fetch the origin arg

                 keylget args ARGS.ORDCONTROL ordcontrol  ;# Fetch the order control arg

                 set field_sep [csubstr $msg 3 1]      ;# HL7 field separator

                 set sub_sep [csubstr $msg 4 1]        ;# HL7 subfield separator

                 set rep_sep [csubstr $msg 5 1]        ;# HL7 field repetition separator

                 set subsub_sep [csubstr $msg 7 1]     ;# HL7 sub subfield separator

                 set segmentList [split $msg r]

      # Now we iterate over each segment in our list.

      foreach segment $segmentList {

      if {[cequal [crange $segment 0 2] ORC]} {

      set fieldList [split $segment $field_sep]

      set orc_1 [lindex $fieldList 0]

      set orc_2 [lindex $fieldList 1]

      set orc_2_2 [crange $orc_2 1 0]

      if {[cequal $orc_1 $ordcontrol] && [cequal $orc_2_2 $origin]} {

      lappend dispList “KILL $mh”

                       

                  } else {

                        lappend dispList “CONTINUE $mh”

                 }

             }

             time {

                 # Timer-based processing

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

             }

      shutdown {

         # Shutdown mode

      echo “kill_IbexNW-ORM is shutting down”

      }

             default {

                 error “Unknown mode ‘$mode’ in kill_IbexNW-ORM”

             }

         }

         return $dispList

      }

    Viewing 2 reply threads
    • Author
      Replies
      • #67985
        Tom Rioux
        Participant

          Tom,

          Check out how you are getting your orc_2_2 variable.  The set statement there doesn’t appear to be right.  You will need to do a split or something to be able to grab the subcomponents.

          Tom

        • #67986
          Tom Arrowsmith
          Participant

            I thought that’s where it might be – I’m at a bit of a loss here on how to properly set this vairiable to get ORC-2.2

            ……..

          • #67987
            Tom Rioux
            Participant

              Here is one way of cleaning it up a bit.  There might be others who have even a cleaner way of doing it.  

              Hope this helps…Tom

              set ORCseg [lsearch -inline -regexp $segmentList ^ORC]

              set fieldList [split $ORCseg $field_sep]

              set orc_1 [lindex $fieldList 0]

              set orc_2 [lindex $fieldList 1]

              set orc_2_2 [lindex [split $orc_2 $sub_sep] 1]

              if {[cequal $orc_1 $ordcontrol] && [cequal $orc_2_2 $origin]} {

                  lappend dispList “KILL $mh”

              } else {

                   lappend dispList “CONTINUE $mh”

              }

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