list doesnt contain element error

Homepage Clovertech Forums Read Only Archives Cloverleaf Tcl Library list doesnt contain element error

  • Creator
    Topic
  • #54436
    Kevin Crist
    Participant

    i have a field (ORC.12) that i need to replace but sometimes the HL7 doesnt go that far and i get the ‘list doesn’t contain element 12’ error. I am using lreplace. How do i get around this using tcl?

    Thanks.

Viewing 7 reply threads
  • Author
    Replies
    • #81458
      Jim Kosloskey
      Participant

      Possibly do a llength first to see if the list is as long as you want?

      Then it is up to you what you want to do.

      email: jim.kosloskey@jim-kosloskey.com 29+ years Cloverleaf, 59 years IT - old fart.

    • #81459
      Kevin Crist
      Participant

      Thanks Jim, that helped. I got hopefully one more question.

      After finding the length i put in the below IF statement and realized that it now only works if the ORC is 13 (my daily Monday moment).

      How do I put in that if it needs to be = into the syntax?

      if {[string equal $ORCLength 13]} {

    • #81460
      Jim Kosloskey
      Participant

      if {$ORCLength <= 13} {…}

      email: jim.kosloskey@jim-kosloskey.com 29+ years Cloverleaf, 59 years IT - old fart.

    • #81461
      Kevin Crist
      Participant

      thanks.

    • #81462
      Paul Bishop
      Participant

      a nifty bit of code I picked up in level 2 and 3 classes:

      while {[llength $FT1] <= 26} {lappend FT1 {}}

      where FT1 is the list that you want to add to and 26 is the field you want to add/modify.

      Paul Bishop
      Carle Foundation Hospital
      Urbana, IL

    • #81463
      Steven Siegfried
      Participant

      You could have wrapped your ORC.12 logic in a catch.

      catch {

      set ORC_fields [lreplace $ORC_fields 12 12 with your replacement]

      }

      If ORC fields come inbound shorter, than there is nothing to replace. Having said that, if for some reason you must have something entered in ORC.12, you would go with the field length to build it out.

      😉

    • #81464
      Charlie Bursell
      Participant

      As Paul said above:

      while {[llength $FT1] <= 13} {lappend FT1 {}}

      No need to check length of the segment.  The above code would do nothing if field 12 or above were populated.

      Anytime I am to change a field in a list, unless I know for sure the list will be of adequate length I use this code.  For example you would not need if you were to place a value in MSH.4 because you know the segment must have more fields than that.

      Maybe you picked this up in one of my classes.  I always covered that.

    • #81465
      Steven Siegfried
      Participant

      while {[llength $FT1] <= 13} {lappend FT1 {}}

      101 different ways to write code, having said that, I will absolutely use this logic next time!

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

Forum Statistics

Registered Users
5,117
Forums
28
Topics
9,293
Replies
34,435
Topic Tags
286
Empty Topic Tags
10