remove one repeating field based on certain condition

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf remove one repeating field based on certain condition

  • Creator
    Topic
  • #54279
    Shu Chen
    Participant

      Hi clovertech:

      I need to remove one repeating field based on a condition.

      for example:

      PID:3 field is repeating field.

      1^T~2^V~3^D~4^F

      if PID:3.2 is V, I need to drop this repeating field and still output the rest of value.

      I try to set this field is empty, the output will be displayed as

      1^T~~3^D~4^F

      I don’t have extra “~” in here. is there anyway that can be displayed

      as  

      1^T~3^D~4^F?

      thanks a lot

    Viewing 8 reply threads
    • Author
      Replies
      • #80842
        Charlie Bursell
        Participant

          There is no straight forward way of doing this in Xlate that I know of unless you want to implement some really convoluted XPM code.  It would be easy in a Tcl Preproc like:

          This assumes you are checking the second subfield of the second iteration.  Feel free to modify if my assumptions are wrong

          run {

             # Get message

             set mh [keylget args MSGID]

             set msg [msgget $mh]

             # Field separators

             set fldSep [string index $msg 3]    ;# Normally |

             set subSep [string index $msg 4]    ;# Normally ^

             set iterSep [string index $msg 5]   ;# Normally ~

             # Segments

             set segList [split $msg r]

             # Need location to change

             set pidLoc [lsearch -regexp $segList {^PID}]

             # PID fields

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

             # Field 3 split into iterations

             set fld3 [split [lindex $PID 3] $iterSep]

             # PID.3.2 split into subfields

             set fld3_2 [split [lindex $fld3 1] $subSep]

             # Check for V in PID.3.2.2

             # If not there we are done just send the message on

             if {[lindex $fld3_2 1] ne “V”} { return “{CONTINUE $mh}” }

             # If here delete second iteration and modify PID

             lvarpop fld3 1

             set PID [lreplace $PID 3 3 [join $fld3 $iterSep]]

             set segList [lreplace $segList $pidLoc $pidLoc [join $PID $fldSep]]

             msgset $mh [join $segList r]

             # Send it on

             return “{CONTINUE $mh}”

          }

        • #80843
          Jim Kosloskey
          Participant

            I think this can be done in an Xlate with no Tcl.

            You will need to maintain your own field (%fx) counter for the outbound. Something like %f99. Initialize %f99 at the beginning of your Xlate (COPY =0 –> $%f99 (note the $).

            As you ITERATE through the field repetitions (specifying a counter like %f1) add one to your outbound counter (using MATH ADD =1 $%f99 –> $%f99 – again note the $) UNLESS (using an IF Action) the condition you specify is true. Then make sure you use the %f1 in the inbound address path and the %f99 in the outbound address path when you COPY the field.

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

          • #80844

            The ~ is the default HL7 field repetition delimiter. ITERATE on the field (%f1), use IF and PATHCOPY to only copy the desired fields across to the destination. If you used BULKCOPY or PATHCOPY on the segment earlier in the xlate, you will need to first empty out the field with a PATHCOPY (source: @null, destination: path to field).

            -- Max Drown (Infor)

          • #80845
            Shu Chen
            Participant

              Max Drown wrote:

              The ~ is the default HL7 field repetition delimiter. ITERATE on the field (%f1), use IF and PATHCOPY to only copy the desired fields across to the destination. If you used BULKCOPY or PATHCOPY on the segment earlier in the xlate, you will need to first empty out the field with a PATHCOPY (source: @null, destination: path to field).

              hi max,

              thanks for you reply. I am a new user for cloverleaf engine. I actually did setup the way you suggested it and please see my screenshot attached. however, it still shows default repeating field delimiter”~”. I need to remove it. I am not too sure what is proper way to only display the part I need it in cloverleaf.

              [/img][/b][/code]

            • #80846
              Shu Chen
              Participant

                Hi Jim,

                thanks for you reply. I am a new user for cloverleaf and haven’t use math function before. is there any sample that I could follow your suggestion?

                I am really appreciated your time and help.

                thank you

                Jim Kosloskey wrote:

                I think this can be done in an Xlate with no Tcl.

                You will need to maintain your own field (%fx) counter for the outbound. Something like %f99. Initialize %f99 at the beginning of your Xlate (COPY =0 –> $%f99 (note the $).

                As you ITERATE through the field repetitions (specifying a counter like %f1) add one to your outbound counter (using MATH ADD =1 $%f99 –> $%f99 – again note the $) UNLESS (using an IF Action) the condition you specify is true. Then make sure you use the %f1 in the inbound address path and the %f99 in the outbound address path when you COPY the field.

              • #80847
                Jim Kosloskey
                Participant

                  MATH ADD

                  Source              Destination

                  =1                     $%f99

                  $%f99

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

                • #80848
                  Charlie Bursell
                  Participant

                    Yeah Jim I would like to that also  ðŸ˜€   I sent you an e-mail

                  • #80849
                    Jim Kosloskey
                    Participant

                      Charlie,

                      I just sent you an email with an example.

                      Su I would have copied you but you don’t have your email exposed on your profile.

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

                    • #80850
                      Charlie Bursell
                      Participant

                        Still a bit confused about the requirement.  My understanding was we were to look at the only the second subfield in the second iteration.  Is that correct or could this “V” be in any iteration?

                        What Jim sent me works fine but it looks at all iterations.  Maybe that is what is wanted?

                        I yield to Jim and his Xlate tricks.  Since I eat sleep and breath Tcl perhaps I jump in that direction too quickly sometimes  ðŸ˜€

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