Nested IF statements

Homepage Clovertech Forums Read Only Archives Cloverleaf Tcl Library Nested IF statements

  • Creator
    Topic
  • #54478
    Robert Denny
    Participant

    I have a script and need to convert NTE segments to OBXs along with other mods. When I hit the NTE 3 segment I need to do some logic on the data following in the -> characters. For some reason I am not able to build the OBX segment from within the IF statement in which I am checking the condistion of the data following the -> characters. Here is the inbound NTEs. (some of the variables are from other trials, this did work, but now we have changed the ORM message, which is why I need to do this logic)

    NTE|1||Length of Study->30 Days||

    NTE|2||Special instructions (if applicable):->Test eCardio order||

    NTE|3||Service/Device Type->Mobile Cardiac Telemetry||

    NTE|4||Serial Number->serial #||

    Here is my logic I am trying to use.

    if { ($segID == “NTE”) } {

                          set mct “Mobile Cardiac Telemetry”

                          set cem “Cardiac Event Monitor”

                          set MCT MCT

                          set CEM CEM

                         

                         

                          set fieldList [split $segment $fldSep]

                          set NTE3 [lindex $fieldList 3]

                          set NTE3ran [string range $NTE3 0 3]

    echo “NTE3ran = $NTE3ran”

                         

                         

                        if {[cequal $NTE3ran “Leng”]} {                                

                              set nteCnt 1                                  

                              set lenList [split $segment |]

                              set NTElen3 [lindex $lenList 3]

                              set nte31 [string range $NTElen3 16 end]

                              set obxSeg “OBX|$nteCnt|ST|12918^Deploy Duration (In Days)||$nte31”

                              incr nteCnt                                  

                              lvarpop segList $count

                              set count [incr count -1]

                        }

                        if {[cequal $NTE3ran “Spec”]} {

                              lvarpop segList $count

                              set count [incr count -1]

                        }

                        if {[cequal $NTE3ran “Serv”]} {

                               set nte3 [lindex $fieldList 3]  

    echo “nte3 = $nte3”                                            

                               

                               set nte3serv [string range $nte3 20 end]

    echo “nte3serv = $nte3serv”

                               if {[cequal $nte3serv “Mobile Cardiac Telemetry”]} {

                               set obxSeg2 “OBX|$nteCnt|ST|12916^Service/Device Type||$MCT”

                               incr nteCnt

                               lvarpop segList $count

                               set count [incr count -1]

                               }                                      

                        }

                        #      set obxSeg2 “OBX|$nteCnt|ST|12916^Service/Device Type||$CEM”

       #echo “obxSeg2 = $obxSeg2”                                      

                                               

            #                  incr nteCnt

            #                  lvarpop segList $count

            #                  set count [incr count -1]

                       

                        if {[cequal $NTE3ran “Seri”]} {

                              set seriList [split $segment |]

    #echo “seriList = $seriList”

                              set NTEseri3 [lindex $seriList 3]

    #echo “nteseri3 = $NTEseri3”

                              set nte3 [string range $NTEseri3 21 end]

    #echo “nte3 = $nte3”              

                              set obxSeg3 “OBX|$nteCnt|ST|12917^Hookup Location||Office”

                              incr nteCnt

                              set obxSeg4  “OBX|$nteCnt|ST|12919^Ssrial Number||$nte3”                

                              set newNTESeg [concat $obxSegr$obxSeg2r$obxSeg3r$obxSeg4]

                              set segList [lreplace $segList $count $count $newNTESeg]                        

                               

                        }

                   }

Viewing 4 reply threads
  • Author
    Replies
    • #81633
      Robert Kersemakers
      Participant

      Hi Robert,

      What is going wrong exactly?

      I see some things that I would do differently (like splitting the NTE-value on ‘->’, so there is no need to use a specific ‘string range’ for each NTE segment), but that won’t help fix your problem. Is there an error? Are the extra OBX-segments not included in your result?

      Zuyderland Medisch Centrum; Heerlen/Sittard; The Netherlands

    • #81634
      Robert Denny
      Participant

      Yes, when testing I get the error that nteSeg2 is not found, or available?

    • #81635
      Robert Kersemakers
      Participant

      I can’t see a variable called ‘nteSeg2’ in this code. So this either means that you are using this variable somewhere without it being initialized. Or somewhere another variable is used in such a way that it is not clear which variable it is.

      For example, you are using the variables $nte3 and $nte3serv, which can lead to problems. If you then do something like this:

      Code:

      set output “$nteserv3”

      will output contain the value of $nteserv3, or the value of $nte followed by the text “serv3”?

      To be sure what you mean, just use braces on variable names:

      Code:

      set output “${nteserv3}”

      or

      Code:

      set output “${nte}serv3”

      I suspect this happens somewhere else as well. Not sure though.

      Zuyderland Medisch Centrum; Heerlen/Sittard; The Netherlands

    • #81636
      Robert Denny
      Participant

      It was my mistake. I need something that helps me see better.

      Your pointer about the > character helped. I was not stripping that off and so it would never match my variable.

      Thank you for your time and help with this.

    • #81637
      Robert Kersemakers
      Participant

      No problem. Glad you solved it.

      Zuyderland Medisch Centrum; Heerlen/Sittard; The Netherlands

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

Forum Statistics

Registered Users
5,129
Forums
28
Topics
9,301
Replies
34,448
Topic Tags
288
Empty Topic Tags
10