My first attempt at editing tcl, not working.

Clovertech Forums Read Only Archives Cloverleaf Tcl Library My first attempt at editing tcl, not working.

  • Creator
    Topic
  • #53701
    Thomas McManus
    Participant

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

      # filterADT_3M

      #

      # Type:    tps proc

      #

      # Args:    tps keyedlist containing:

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

      #          MSGID   message handle

      #

      # Returns: Filter out ADT’s to 3M CDIS with location of SSCP and ARU

      # and PRE IN and SCH.  Also, filters out status of Observation.

      #

      # Notes:  Filters out any ADT’s with the value in PV1.3.0 of SSCP, ARU

      # and PRE IN and SCH.

      #         Filters out any ADT’s with the value in PV1.18.0 of INO.

      #    

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

      proc filterADT_3M { args } {

          set mode [keylget args MODE]

         switch -exact — $mode {

      start {

         return “” ;# Nothing specific

      }

      run {

         set mh [keylget args MSGID]    ;# Message header

         set msg [msgget $mh]           ;# The message

         # Field and subfield separators

         set fldSep [string range $msg 3 3]

         set subSep [string range $msg 4 4]

         # List of HL7 segments

         set segments [split $msg r]

                         

                   # Get PV1 fields.  Value needed is in PV1.3.0

                   set PV1 [lindex [lregexp $segments {^PV1}] 0]

         echo PV1: $PV1

         set PV1_3flds [lindex [split $PV1 $fldSep] 3]

         echo PV1_3flds: $PV1_3flds

         set PV1_3 [lindex [split $PV1_3flds $subSep] 0]

                   echo PV1_3: $PV1_3

         # Get PV1Ino fields.  Value needed is in PV1.18.0

                   set PV1Ino [lindex [lregexp $segments {^PV1}] 0]

         echo PV1Ino: $PV1Ino

         set PV1_18flds [lindex [split $PV1Ino $fldSepIno] 3]

         echo PV1_18flds: $PV1_18flds

         set PV1_18 [lindex [split $PV1_18flds $subSepIno] 0]

                   echo PV1_18: $PV1_18

                   # IF PATIENT IS ACCOUNT TYPE IS “INO”

                   if {($PV1_18 == “INO”)} {

      echo “Message killed!”

      return “{KILL $mh}”

                   } else

      {

      #echo “Message sent!”

      #return “{CONTINUE $mh}”

         

        # IF PATIENT IS AT LOCATION “SSCP” OR “ARU”

                   if {($PV1_3 == “SSCP”)||($PV1_3 == “ARU”)||($PV1_41 == “SCH”)||($PV1_41 == “PRE”)} {

      echo “Message killed!”

      return “{KILL $mh}”

                   } else {

      echo “Message sent!”

      return “{CONTINUE $mh}”

                   }

      }

         }

      }

    Viewing 4 reply threads
    • Author
      Replies
      • #78618
        David Harrison
        Participant

          I would do this kind of filtering in an Xlate. With a SUPPRESS at the top of the Xlate you can use the IF statements and CONTINUE if the condtions are satisfied.

        • #78619
          David Barr
          Participant

            This part looks wrong.

            Code:

            # Get PV1Ino fields.  Value needed is in PV1.18.0
            set PV1Ino [lindex [lregexp $segments {^PV1}] 0]
            echo PV1Ino: $PV1Ino
            set PV1_18flds [lindex [split $PV1Ino $fldSepIno] 3]

            You don’t need to do an lregexp search to find PV1 again; it’s already in your PV1 variable. And your lindex should be getting field 18, not field 3 again.

            It’s easier to look for problems with your code if you use proper indentation. Everything should stay at the same level of indentation until you get to the body of an if statement or a case in a switch statement, then you should indent a few extra spaces.

            Also it’s better to use eq for string comparison.

            Code:

                        if {($PV1_18 == “INO”)} {

            should be

            Code:

                        if { $PV1_18 eq “INO” } {

            I think the main issue is you need to replace the “lindex … 3” with “lindex … 18”. The other issues are just cosmetic and optimization.

          • #78620
            David Barr
            Participant

              I also noticed that you’re referencing $PV1_41. You need to set that using the same method that you use for PV1_3 and PV1_18.

            • #78621
              Charlie Bursell
              Participant

                It would also be better to replace lregexp with lsearch since lsearch is core Tcl and does not always return a list as lregexp does

                Also you can split at the same time

                Assume fldsep is |

                set PV1 [split [lsearch -inline -regexp $segments {^PV1}] $fldSep]

                Now you acn get any field you want out of the list of PV1 fields above

                When you use the -all option of lsearch it returns a list, else a string

              • #78622
                Thomas McManus
                Participant

                  Hi,

                  Thank you all so much for all your help.  I was able to get this going and learned alot along the way.

                  Tom

              Viewing 4 reply threads
              • The forum ‘Tcl Library’ is closed to new topics and replies.