temp variable in an IF statement

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf temp variable in an IF statement

  • Creator
    Topic
  • #49375
    Beth Palmateer
    Participant

      We are 5.2.1 on AIX 5.1.  I am using a translate for ADT records and want to do a simple field copy based on the length of a field.

      I have a copy statement using EVN.#2 with the pre-tcl fragment to get the length of that field and save it to a temp field @evn_length:

      set xlateOutVals

        ]]

        This seems to work okay; an echo of xlateOutVals shows the correct length.  So next I add an IF statement:

        IF @evn_length < =12  copy MSH.#7 to outbound EVN.#2. I can’t get this to work.  Everything I’ve tried indicates that the temp variable just isn’t being recognized by the IF statement; the copy never seems to take place even when @evn_length is 8.  The temp variable shows up when I display the list.  Is there something else I need to do?  I even tried stopping/starting my ADT process and just sending a test record thinking that maybe it was a problem with the testing tool.  It still didn’t work. Any ideas on what I’m missing or doing wrong? Beth

      Viewing 7 reply threads
      • Author
        Replies
        • #61690

          Beth, can you give us some sample data?

          -- Max Drown (Infor)

        • #61691

          This works for me …

          Code:

          COPY 12345678 @tmp
          COPY @tmp –> “set xlateOutVals [list [clength [lindex $xlateInVals 0]]]” –> @evn_length
          IF @evn_length < =12 THEN print "eureka!"


          … and (change value of @tmp) …

          Code:

          COPY 1234567890000 @tmp
          COPY @tmp –> “set xlateOutVals [list [clength [lindex $xlateInVals 0]]]” –> @evn_length
          IF @evn_length < =12 THEN print "eureka!"

          -- Max Drown (Infor)

        • #61692
          John Hamilton
          Participant

            If Max’s code fragments did not help you. Let us know.  This type of thing always seems to get me with syntax. So if you could post you code that would help. If the problem is not already fixed.

          • #61693
            Chris Williams
            Participant
            • #61694
              Beth Palmateer
              Participant

                Thanks, Chris.  I had tried using the string compare (lt) instead of < and it still didn't work.  I talked to Jim Koslowskey yesterday and tried several of his suggestions, including stripping down the xlate to include only my copy and IF statements for this temp field.  Still no luck. This morning I tried zero-filling the temp field and the copy still isn’t working. Following is my test xlate.  If anyone can find what’s wrong, great.  But don’t waste too much time on it; I am ready to just do a hard copy of the MSH date field to this field and be done with it!! prologue    xlt_infile: hl7 2.3 adt_fr_meditech ADT_A01    who: bpalmate    date: June 28, 2007 8:03:09 AM CDT    xlt_outfile: hl7 2.3 adt_to_maxsys ADT_A01    type: xlt    version: 5.0 end_prologue { { OP DATECOPYOPT }    { ADDPREC 0 }    { FABRICATE 1 }    { USECURTM 1 }    { RANGE {49 20 19} }    { TMDEFS {01 01 00 00 00 0000 +0000} }    { DELIMIT {/ :} } } { { OP PATHCOPY }    { ERR 0 }    { IN {0(0).MSH 0(0).EVN 0(0).PID 0(0).PD1 0(0).NK1 0(0).PV1 0(0).PV2 0(0).OBX 0(0).AL1 0(0).DG1 0(0).DRG 2(0).GT1 2(0).IN1 2(0).IN2 2(0).IN3 2(0).ACC 2(0).UB1 2(0).UB2} }    { OUT {0(0).MSH 0(0).EVN 0(0).PID 0(0).PD1 0(0).NK1 0(0).PV1 0(0).PV2 0(0).OBX 0(0).AL1 0(0).DG1 0(0).DRG 2(0).GT1 3(0).0(0).IN1 3(0).0(0).IN2 3(0).0(0).IN3 4(0).ACC 4(0).UB1 4(0).UB2} } } { { OP COMMENT }    { COMMENT {Maxsys has to have the time in addition to the date in the EVN segment.  So, if this field is less than 12 characters, copy the date/time field from MSH.} } } { { OP COMMENT }    { COMMENT {  first – find the length of the data and save this number to a temp file} } } { { OP COPY }    { ERR 0 }    { PRE {        set xlateOutVals

                  ]]

                     }}

                     { IN {{0(0).EVN.#2.[0]}} }

                     { OUT @evn_length }

                  }

                  { { OP COMMENT }

                     { COMMENT {make sure the 2-digit field is zero-filled, so 8 won’t be seen as greater than 12.} }

                  }

                  { { OP COPY }

                     { ERR 0 }

                     { PRE {

                         set xlateOutVals

                    ]]

                           echo $xlateOutVals

                       }}

                       { IN @evn_length }

                       { OUT @evn_length }

                    }

                    { { OP COMMENT }

                       { COMMENT {  then – check the length of the temp variable and if less than 12, perform the copy} }

                    }

                    { { OP IF }

                       { ERR 0 }

                       { COND {@evn_length < =12} }    { THENBODY {        { { OP COMMENT }            { COMMENT {TODO: Insert new actions here} }        }        { { OP COPY }            { ERR 0 }            { IN =BETH }            { OUT {{0(0).EVN.#2.[0]}} }        }    }}    { ELSEBODY {    }} }

                  1. #61695
                    Michael Hertel
                    Participant

                      How about:

                      if {[clength [lindex $xlateInVals 0]] < 13} {    set xlateOutVals

                    • } else {

                         set xlateOutVals

                    • }

                      Then copy based on Y or N.

                1. #61696
                  Beth Palmateer
                  Participant

                    Michael, this works!!  It is looking like maybe the problem was with clength and/or the way I was using it??  Anyway, this resolution is perfect.  Thanks!

                  • #61697
                    Beth Palmateer
                    Participant

                      One final update:  Jim Kosloskey came upon another way to fix this.  After adding a dummy math statement right after the copy proc that created the temp variable, the IF statement worked just fine.  We are surmising that although the string or clength command returns a decimal value, the temp variable has a string attribute.  So tcl didn’t work quite as expected.  But when we added zero to the temp variable, the context was converted so the IF statement worked.

                      My thanks again for everyone’s help.

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