tclproc omitting a segment

Clovertech Forums Read Only Archives Cloverleaf Tcl Library tclproc omitting a segment

  • Creator
    Topic
  • #52880
    Kevin Crist
    Participant

      We have a tclproc that takes a pharmacy credit and based on the quantity will make separate single credits in an hl7 message. So if a quantity of 10 is charged then it sends out 10 DFT credits. But if there is greater than 20 for quantity it just sends message as is. That is done because people would regularly put in a time instead of quantity and we would send out thousands of credits.

      If the quantity is greater than 20 it sends out the message as is, below

      MSH|^~&|HMM|A||A|201201100842||DFT^P03|1|P|2.3

      EVN|P03|201201100842|201201100842

      PID|0001|001832^^^HMM|001832^^^A^MR||DUCK^DONALD||19700828000000|F|||ROUTE 1^^VINCENNES^IN^47591|||||||9000003871|333-99-5858

      PV1|0001|I|4E^404^2||||^CARANDANG^REYNALDO^A|0686^CARANDANG^REYNALDO^A||HIP||||||||I||||||||||||||||||||||||||201108240859

      FT1|1|||20120110|20120110|CR|1516346^EPOGEN^^6346|EPOETIN ALFA|59676032004|20|934.45|46.72|400|||4E^404^2||I||||247.857|12722678

      ZFT|1|59676032004^^NDC|1^ML

      This is what it will send out if the quantity is under 20:

      MSH|^~&|HMM|A||A|201201100842||DFT^P03|1|P|2.3

      EVN|P03|201201100842|201201100842

      PID|0001|001832^^^HMM|001832^^^A^MR||DUCK^DONALD||19700828000000|F|||ROUTE 1^^VINCENNES^IN^47591|||||||9000003871|333-99-5858

      PV1|0001|I|4E^404^2||||^CARANDANG^REYNALDO^A|0686^CARANDANG^REYNALDO^A||HIP||||||||I||||||||||||||||||||||||||201108240859

      FT1|1|||20120110|20120110|CR|1516346^EPOGEN^^6346|EPOETIN ALFA|59676032004|1|934.45|46.72|400|||4E^404^2||I||||247.857|12722678

      The problem is that it cuts off the ZFT segment from the original message when it has to split it out. How do i keep this segment their all the time.

      the proc is below, it is old and done way before my time so i know some of the commands are old.

      Thanks for any help or insight.

      Code:

      ######################################################################
      # Name: tpsRxCreditQtyFix
      # Purpose: This tps tclproc creates, depending on argument criteria,
      # multiple outbound credit messages for each inbound credit
      # message.  It uses the quantity to determine how many messages,
      # each with a quantity of one, to create.  
      #
      # This will partially fix a problem that occurs between
      # STAR Pharmacy and Affinity.  Currently, STAR lumps
      # multiple credits for the same item into one HL7 message
      # where the quantity is the total amount to credit.  Affinity
      # will only apply the credit HL7 message to one charge and the
      # quantity to credit must be less than or equal to the quantity
      # of the individual charge.  If it isn’t, Affinity does not
      # apply the credit and it appears on the exception report for
      # accounting.
      #
      # The MAXMSGS argument puts a limit on the number of credit
      # messages created.  This avoids a huge glut of messages if the
      # quantity to credit is large.
      #
      # UPoC type: tps
      # Args: tps keyedlist containing the following keys:
      #       MODE    run mode (”start”, “run” or “time”)
      #       MSGID   message handle
      #       ARGS    user-supplied arguments:
      #               {MAXMSGS 25}
      #
      # Returns: tps disposition list:
      #          
      #

      proc tpsRxCreditQtyFix { args } {
         keylget args MODE mode               ;# Fetch mode

         # Set default in case user doesn’t enter the argument
         if ![keylget args ARGS.MAXMSGS maxmsgs] {
          set maxmsgs 20
         }
         
         set dispList {} ;# Nothing to return

         switch -exact — $mode {
             start {
                 # Perform special init functions
         # N.B.: there may or may not be a MSGID key in args
             }

             run {
         # ‘run’ mode always has a MSGID; fetch and process it
                 keylget args MSGID mh
                 set msg [msgget $mh] ;# Load the message to variable
                 set fs [crange $msg 3 3] ;# Load the field separator from msg
                 set segments [split $msg r] ;# Load the transaction quantity
                 
                 # Roll through the segments to find the FT1 to process
                 foreach seg $segments {
                  set segtype [crange $seg 0 2] ;# Load the segment name to variable
                 
                  # Check for an FT1 segment
                  if [cequal $segtype “FT1″] {
      set fltseg [split $seg $fs] ;# Load a list from the FT1
      set trantype [lindex $fltseg 6] ;# Load transaction type
      set tranqty [lindex $fltseg 10] ;# Load transaction quantity
      echo tranqty: $tranqty
      # Set flag ON if message is a credit and the quantity field is
      # greater than 1 and less than maximum entered in argument MAXMSGS.
      set okFlag “” ;# Clear the flag
      if [cequal $trantype “CR”] {
      set tranqty [string trim $tranqty]
      if [ctype digit $tranqty] {     ;# Validate quantity is number
      if [expr ($tranqty > 1)] {
      if [expr ($tranqty <= $maxmsgs)] { set okFlag "ON" } } } } # Check flag to determine how to handle message.  If set "ON" # multiple messages get created based on quantity else the # message is passed on unchanged. if [cequal $okFlag "ON"] { # Create duplicate copies of message up to the value of the quantity. # Each message has a quantity of 1. for {set i 0} {$i < $tranqty} {incr i} { # Build new message replacing the quantity with 1. after 500 set newmh [msgcopy $mh] ;# Returns the new msg handle set fltseg [lreplace $fltseg 10 10 1]   ;# Make qty a 1 set newseg [join $fltseg $fs] ;# Put segment back together append tmpmsg $storeseg $newsegr       ;# Add modified segment to message msgset $newmh $tmpmsg ;# Set the message handle with data set tmpmsg "" ;# Clear tmp field lappend dispList "CONTINUE $newmh"      ;# Add message to disp list     } # Dispose of original message since it is no longer needed lappend dispList "KILL $mh" } else { lappend dispList "CONTINUE $mh" ;# Continue original message }             }             append storeseg $segr ;# Append non FT1 segment to stored message            } # Check if the disposition list has been loaded with anything because if it hasn't # then it must not have had an FT1 segment.  Continue the original message. if [cequal $dispList {}] { lappend dispList "CONTINUE $mh" ;# Continue original message }                  }        time {            # Timer-based processing    # N.B.: there may or may not be a MSGID key in args        } shutdown {    # Doing some clean-up work }        default {    error "Unknown mode '$mode' in tpsRxCreditQtyFix"        }    }    return $dispList }

    Viewing 2 reply threads
    • Author
      Replies
      • #75775
        Vince Angulo
        Participant

          I have almost no experience with UPoC’s, but am trying to learn (and this might be something I can use), so I’m going to take a shot @ this…

          The Z-segment never makes it into $newmh for an edited message.

          So couldn’t we just replace these lines:

          Code:

          append tmpmsg $storeseg $newsegr
          msgset $newmh $tmpmsg
          set tmpmsg “”
          lappend dispList “CONTINUE $newmh”


          With:

          Code:

          append storeseg $newsegr


          And after exititng the foreach:

          Code:

          msgset $newmh $storeseg
          lappend dispList “CONTINUE $newmh”

          And if we’re always going to CONTINUE or SEND something, do we need to ?  Or is it just good housekeeping?

        • #75776
          Charlie Bursell
          Participant

            Way too much work!  Try this.  I did not test so I may have fat-fingered something

            ######################################################################

            # Name:      tpsRxCreditQtyFix

            # Purpose:   This tps tclproc creates, depending on argument criteria,

            #      multiple outbound credit messages for each inbound credit

            #      message.  It uses the quantity to determine how many messages,

            #      each with a quantity of one, to create.

            #

            #      This will partially fix a problem that occurs between

            #      STAR Pharmacy and Affinity.  Currently, STAR lumps

            #      multiple credits for the same item into one HL7 message

            #      where the quantity is the total amount to credit.  Affinity

            #      will only apply the credit HL7 message to one charge and the

            #      quantity to credit must be less than or equal to the quantity

            #      of the individual charge.  If it isn’t, Affinity does not

            #      apply the credit and it appears on the exception report for

            #      accounting.

            #

            #      The MAXMSGS argument puts a limit on the number of credit

            #      messages created.  This avoids a huge glut of messages if the

            #      quantity to credit is large.

            #

            # UPoC type:   tps

            # Args:    tps keyedlist containing the following keys:

            #          MODE    run mode (“start”, “run” or “time”)

            #          MSGID   message handle

            #          ARGS    user-supplied arguments:

            #                  {MAXMSGS 25}

            #

            # Returns: tps disposition list:

            #          

            #

            proc tpsRxCreditQtyFix { args } {

               keylget args MODE mode                 ;# Fetch mode

               switch -exact — $mode {

                   start {

                       # Set default in case user doesn’t enter the argument

                       # Set as global so we do it just once

                       if ![keylget args ARGS.MAXMSGS maxmsgs] {

                          set ::maxmsgs 20

                      }

                   }

                   run {

                       keylget args MSGID mh

                       set msg [msgget $mh]                ;# Load the message to variable

                       set fs [string index $msg 3]        ;# Field sep

                       set segments [split $msg r]        ;# List of segments

                       # Get FT1 in list of fields if there (Assume only one)

                       set FT1LOC [lsearch -regexp $segments {^FT1}]

                       # If no FT1 just send as-is

                       if {$FT1LOC < 0} { return "{CONTINUE $mh}"

                       # Get FT1 fields

                       set FTP [split [lindex $segments $FT1LOC] $fs]

                       # Get the number. If > 1 and less than or equal max we process

                       # else send it on

                       set qty [string trim [lindex $FT1 10]]

                       if {![string is digit -strict $qty || $qty $::maxmsgs} {

                           return “{CONTINUE $mh}”

                       }

                       # If here we send multiples

                       # Always KILL Original

                       set dispList

                         # Replace count with a 1 and put nack as a msg

                         set FT1 [lreplace $FT1 10 10 1]

                         set segments [lreplace $segments $FT1LOC $FT1LOC [join $FT1 $fs]]

                         set msg [join $segments r]

                         for {set i 1 } {$i <= $qty} {incr i} {

                             # New mh

                             set nmh [msgcopy $mh]

                             msgset $nmh $msg

                             lappend dispList “CONTINUE $nmh”

                         }

                         # Send them on

                         return $dispList

                     }

                 }

          • #75777
            Tom Rioux
            Participant

              Kevin,

              When the code loops through the segments and hits the FT1 segment, the FT1 logic is performed and it CONTINUEs the message.   The Z segment is never reached.

              I would modify the code to grab the index of the FT1 segment.  Then you can perform an lreplace to a variable where the segments are stored and replace the modified FT1 segment only.  You won’t need loop through all of the segments.  

              Hope this helps…..

              Tom Rioux

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