Easy way to check if a field exists?

Homepage Clovertech Forums Read Only Archives Cloverleaf Tcl Library Easy way to check if a field exists?

  • Creator
    Topic
  • #51425
    Mike Campbell
    Participant

    I’m working on a tcl preproc to fail any ADT messages where the PID_7 AND PID_8 are not present.

Viewing 4 reply threads
  • Author
    Replies
    • #70234

      If field eq @null should work I think?

      Code:

      0(0).MSH(0).#10(0).[0]  eq @null

      -- Max Drown (Infor)

    • #70235
      Mike Campbell
      Participant

      We are trying to do this in a tcl pre-proc so the messages won’t get to the xlt.  I have added echo statements and can see where the values are being returned.  When I execute the code in the testing tool:

      #


      MOD 1


                  set EMPTY 1

             # Get PID segment fields

                  set PID [split [lindex $segList 2] $fldSep]

                  set PID_7 [split [lindex $PID 7] $subSep]

                  set PID_8 [split [lindex $PID 8] $subSep]

                  set Len_PID_7 [llength $PID_7]

                  set Len_PID_8 [llength $PID_8]

                if {[$Len_PID_7] < [$EMPTY] && [$Len_PID_8] < [$EMPTY]} {

                    return KILL}

                               

             #


      end of MOD 1


      …it errors with:

      [0:TEST] Tcl error:

      msgId = message0

      proc = ‘ID_ADT_Cerner_To_CarePricer’

      args = ”

      result = ‘invalid command name “1”‘

      errorInfo: ‘

      invalid command name “1”

         while executing

      “$Len_PID_7”

         (procedure “dbSubs::parseHL7” line 41)

      I’m sure it is something really dumb, but everything I’ve tried doesn’t seem to work.

    • #70236
      Steve Carter
      Participant

      Change your IF statement to this:

      if {($Len_PID_7 < $EMPTY) && ($Len_PID_8 < $EMPTY)} {

      The brackets that you had around the variables were causing them to be treated as commands.

      Hope this helps.

      Thanks.

      Steve

    • #70237
      Mike Campbell
      Participant

      Thanks.  Always seem to get the dang brackets off somewhere!

    • #70238
      David Barr
      Participant

      You don’t need llength for this.

      Code:

               set PID [split [lindex $segList 2] $fldSep]
               set PID_7 [split [lindex $PID 7] $subSep]
               set PID_8 [split [lindex $PID 8] $subSep]
               if { $PID_7 eq “” && $PID_8 eq “” } {
                   return KILL
               }

      Assuming that the PID segment will always be the 3rd one seems dangerous. I’d recommend using a library or utility function to look up fields in a message by segment name and number rather than splitting and lindexing all over the place.

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

Forum Statistics

Registered Users
5,126
Forums
28
Topics
9,296
Replies
34,439
Topic Tags
287
Empty Topic Tags
10