incr xlateInVals

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf incr xlateInVals

  • Creator
    Topic
  • #54613
    Dustin Sayes
    Participant

      I want to append .001, .002, .003 to a value on repeating OBR and ORC

      I was thinking that it would be easiest to do this using an xltp and the incr command.

      I have attempted a few things but haven’t gotten it quite right.

      My idea is something like this:

      The value in ORC|3 xlateInVals is the same for each repeating segment.

      Increment a value i, for each repeating ORC|3 segment/field.

      For the first ORC|3 I would have the xlateInVals of 81253 (for example), then use incr and append to have 81253.001

      Then for the next repeating ORC|3, I would have 81253.002 then 81253.003 for the 3 repetition and so on…

      Is using xlate with incr my best option? If not what is a better option? Code examples would be appreciated!

    Viewing 5 reply threads
    • Author
      Replies
      • #82220
        Robert Milfajt
        Participant

          You should already have some iteration variable, since you would be using an Xlate.  I’m assuming you’ll be iteraring over a group, so your variable might be something like %g1.  Your copy command would look something like this:

          ASSUME-Value is the field with value you want to move and Destination is field to where it will move.

          COPY Value $%g1 -> Destination

          Xltp (Pre Proc)

          Code:

          set invalue [lindex $xlateInVals 0]
          set itervar [lindex $xlateInVals 1]
          incr itervar
          set dec [expr “$itervar.000” / 1000]
          set xlateOutVals [list “$invalue$dec”]

          Of course you could take TCL out of the equation and do this.

          MATH ADD $%g1 =1 -> @var

          MATH DIV @var 1000 -> @var

          CONCAT value @var -> Destination

          Good luck

          Robert Milfajt
          Northwestern Medicine
          Chicago, IL

        • #82221
          Dustin Sayes
          Participant

            Hi Robert, thanks for the info.

            A couple of questions.

            Why do we initialize the value that we plan to incr on lindex 1 of the InVals?

            I like your idea to use the math functions in the xlate tool. Can you be more specific on that?

          • #82222
            Robert Milfajt
            Participant

              Since you have multiple ORC messages in the message, the assumption is that you must loop over all of them, using the ITERATE Xlate command.  One of the things you specifiy in the ITERATE is a variable, which keeps track of which group you are processing.  The solutions defined below take advantage of the fact that you have this built in variable, and use it as your counter, allowing the ITERATE to initialize it.  However, the variable, %g1, starts its count at 0, so it will always be one behind what you want it to be for adding to your value.

              In my example, xlateInVals is a list of the arguments on the Source side of the COPY statement.  The first element (index=0) in the list is the field from which you get the value 81253, and the second element (index=1) in the list is the value of %g1 on the first iteration, which is always 0.

              lindex grabs the values from that list, based off their index.  For example, if you were in the first iteration on the group, your xlateInVals list would look like:

              xlateInVals={81253 0}

              Code:

              set invalue [lindex $xlateInVals 0]
              set itervar [lindex $xlateInVals 1]

              sets the values of the variables to:

              invalue=81253

              itervar=0

              You need to increment itervar to be 1, so the first time through you concatenate .001 to your result.  The second time through the iteration, %g1 will be 1, so you need to increment it again, so you concatenate .002 to your result.  Basically, %g1 is always one behind what you want to concatenate.

              For the second solution, you would again be using the iteration variable, %g1, as the basis for counter, but since the iteration variable starts at 0, and you want to start your concatenation at 1, you need to increment the iteration variable, MATH ADD, to a temporary variable @var, then divide that variable by 1000, MATH DIV, before concatenating it to your value using CONCAT.

              Hope this helps,

              Robert Milfajt
              Northwestern Medicine
              Chicago, IL

            • #82223
              Dustin Sayes
              Participant

                For what ever reason I only get 1 increment of the value.

                I am iterating, and all of the ORC segments are being processed because .001 is getting appended to each repetition.

                i notice if i do xlateInList i get the entire “2(%g1).0(0).ORC(0).#2(%f1)”, from my copy statement. When i run a test the %g1 is incrementing with each segment like this:

                2(0).0(0).ORC(0)

                2(1).0(0).ORC(0)

                2(2).0(0).ORC(0)

                2(3).0(0).ORC(0)

                So I am thinking if I could get the value of %g1 into the xltp then it would increment correctly?

                As is, if doing

                set itervar [lindex $xlateInVals 1]

                I get errorCode: “TCL Value Number”

                I think that is because index 1 of my message on this segment is null.

                if i set itervar to 0 or 1 or any number it does incr once, as stated above.

              • #82224
                Robert Milfajt
                Participant

                  Your copy statement should have two items on the Inbound, and one item on the outbound.  Something like the attachment.

                  Hope this helps,

                  Robert Milfajt
                  Northwestern Medicine
                  Chicago, IL

                • #82225
                  Dustin Sayes
                  Participant

                    HA!

                    I wasnt passing the $%g1 on the inbound… no wonder it wouldnt incr.

                    Robert, thank you a ton! This little bit of knowledge will really help me out in the future!

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