Passing list for argument

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf Passing list for argument

  • Creator
    Topic
  • #50354
    Rick Pritchett
    Participant

      Im passing a list of arguments and trying to check if my variable is in the list if it is i set my variable.  for some reason i am getting the opposite of what is expected and ideas?  here is the code.

      proc filter_pttype_ptloc_ptserv_midas_4 { 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

              #get the arguments

              keylget args ARGS uargs

      keylget args ARGS.types types

              #split the argument list

               set argList [split $types ” “]

       

               set mh [keylget args MSGID]

               set dispList

                 set msg [msgget $mh]

                 set ptclassflag “N”  ;#  Declare and set vaiables

                 set pttypeflag “N”

                 set locflag “N”

                 set killflag “N”

         

                 set fldSep [string index $msg 3]  ;#  Field seperator.

                 set subSep [string index $msg 4]  ;#  Sub-Field seperator.

                 set segList [split $msg r]       ;#  Create segment list using carriage return.

           

                 set PV1 [lindex [lregexp $segList {^PV1}] 0]  ;#  Find PV-1 segment.

                 set PV1flds [split $PV1 $fldSep]  ;#  Split PV-1 segment up into fields.

                 set pttype [lindex $PV1flds 18]   ;#  Set variables to desired fileds.

                 set ptlocationflds [lindex $PV1flds 3]

                     set ptlocationsub [split $ptlocationflds $subSep]  ;#  Split field 3 into subfileds.

                     set ptlocation [lindex $ptlocationsub 0]  ;#  set variable to desired sub-filed.

                 #Check to see if patient class inpatient, newborn, emergency, SDOP

                            foreach value $argList {

                            if {[cequal $pttype $value]} {

                               set killflag “N”

                     

          } else {

                          set killflag “Y”

                            } ;#end if

                               }

                          echo $pttype

                          echo $killflag

                          echo $ptlocation

                 #Check to see if patient location is in midas_locations.tbl

                 #go through the midas_locations table and see if it finds a match

                 set locflag [tbllookup -side input midas_locations.tbl $ptlocation]

                 # Check to see if Pt Locations is “N” and Pt type is “CL”.

                       if {[string equal $locflag “N”] && [string equal $pttype “CL”]} {

                              set killflag “Y”

                       

        } else {

                          set killflag “N”

                              } ;#

           

                          echo $killflag

                  # continue or kill the message

                          echo “Kill: $killflag”

                          echo “loc_flag $locflag”

                 if { $killflag == “Y” } {

                   set dispList

               return $dispList

             

               } else {

                         return $dispList

                     } ;#end if

               }

               time {

                   # Timer-based processing

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

               }

               

               shutdown {

           # Doing some clean-up work

        }

           }

           return $dispList

        }

    Viewing 2 reply threads
    • Author
      Replies
      • #65729

        Can you post an example of how you’re calling the proc? So we can see the list you’re passing?

        -- Max Drown (Infor)

      • #65730
        Steve Carter
        Participant

          Without knowing how you’ve actually setup the args, this is what it would need to look like based on the code:

          {types {type1 type2 type3}}

          Also, you don’t need:

          keylget args ARGS uargs ;# this isn’t used anywhere.

          If the types are separated by spaces, then you don’t necessarily have to have the split since it’s already a list:

          set argList [split $types ” “]

          If you do decide to keep the split, you can omit the ” ” as the split defaults to a space.

          I would also change the code where you’re looping over the argList. You can shorten it by doing this (assuming you don’t use the split):

          if { [lcontain $types $pttype] } {

             set killflag “N”

          } else {

             set killflag “Y”

          }

          or (if you keep the split):

          if { [lcontain $argList $pttype] } {

             set killflag “N”

          } else {

             set killflag “Y”

          }

          Hope this helps.

          Steve

        • #65731
          Rick Pritchett
          Participant

            I am passing it this way:   {types {IN N OPB OP ER}}

            Thanks for the help guys.  With your help not only is it working its a little less code and confusion.

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