2 sec time delay

Clovertech Forums Cloverleaf 2 sec time delay

  • Creator
    Topic
  • #113444
    Alison Benecchi
    Participant

      I have a script where I am creating 2 A31 msgs from an A05 and need to put in a 2sec delay after the A05 message but I can’t seem to get the delay working.  Where do I put in the 2 sec. delay and what is the syntax?  Here’s my script.

      if {[cequal $msgTRIG “A05”] && [regexp {BABY} $sysBABY]} {
      set babyFlag 1
      #puts “the value of sysBABY is: $sysBABY”
      #puts “the value of PV2_12 is: $PV2_12″
      regsub -all {\-} $PV2_12 { } PV2_12
      set PV2_12_list [split $PV2_12 ” “]
      set mother_mrn [getField $msg GT1 2 0]
      set mother_mrn [lindex $PV2_12_list 1]
      #set mother_name [lindex $PV2_12_list 2]
      #regsub -all {,} $mother_name {^} mother_name
      set mother_name [getField $msg GT1 3]

      set nk1cnt [countSegments $msg “NK1”]
      for {set i 0} {$i < $nk1cnt} {incr i} {
      set nk1_3_2 [getField $msg NK1<$i>.3.1]

      if {[cequal $nk1_3_2 “MOTHER”]} {
      set msg [setField $mother_mrn $msg NK1<$i> 33]}
      }
      #puts “the value of nk1_3_2 is: $nk1_3_2”
      $oldmsg setMessage “$msg”

      #Build the A31 message mother and add a 2 second delay
      $newmsg setMessage [$oldmsg getSegment MSH]
      after 2000
      $newmsg appendSegment “EVN”
      $newmsg setField EVN.1 A31
      $newmsg setField EVN.2 [$oldmsg getField MSH.6]
      $newmsg appendSegment “PID”
      $newmsg setField PID.3 “$mother_mrn^^^ST01A^MR”
      $newmsg setField PID.5 $mother_name
      $newmsg appendSegment “NK1”
      $newmsg setField NK1.1 “1”
      $newmsg setField NK1.3 “D”
      $newmsg setField NK1.7 “F”
      $newmsg setField NK1.2 [$oldmsg getField PID.5]
      $newmsg setField NK1.33 [$oldmsg getField PID.3.0]
      $newmsg appendSegment “PV1”
      $newmsg setField PV1.1 “1”
      $newmsg setField PV1.2 “N”
      after 2000
      $newmsg setField MSH.8 “ADT^A31”
      #Build the A31 message baby and add a 2 second delay
      set babyname [$oldmsg getField PID.5]
      set babymrn [$oldmsg getField PID.3.0]
      $newmsg2 setMessage [$oldmsg getSegment MSH]
      $newmsg2 appendSegment “EVN”
      $newmsg2 setField EVN.1 A31
      $newmsg2 setField EVN.2 [$oldmsg getField MSH.6]
      $newmsg2 appendSegment “PID”
      $newmsg2 setField PID.3 “$babymrn^^^ST01A^MR”
      $newmsg2 setField PID.5 $babyname
      $newmsg2 appendSegment “NK1”
      $newmsg2 setField NK1.1 “1”
      $newmsg2 setField NK1.3 “R”
      $newmsg2 setField NK1.7 “F”
      $newmsg2 setField NK1.2 $mother_name
      $newmsg2 setField NK1.33 $mother_mrn
      $newmsg2 appendSegment “PV1”
      $newmsg2 setField PV1.1 “1”
      $newmsg2 setField PV1.2 “N”
      $newmsg2 setField MSH.8 “ADT^A31”

      }

      msgset $mh $msg
      lappend dispList “CONTINUE $mh”
      #puts “the confirms babyFlag is: $babyFlag”
      if {$babyFlag == 1} {

      set mh2 [msgcopy $mh]
      msgset $mh2 [$newmsg getMessage]
      lappend dispList “CONTINUE $mh2”

      set mh3 [msgcopy $mh]
      msgset $mh3 [$newmsg2 getMessage]
      lappend dispList “CONTINUE $mh3”
      }

    Viewing 7 reply threads
    • Author
      Replies
      • #113445
        Ab Lugtenburg
        Participant

          Hi  I think best way is to use sleep (is in seconds), there is also an command after (in miliseconds) but this is in tcl mainly used before starting a proc

        • #113460
          Anonymous

            I don’t think the 3 messages will CONTINUE until the script finishes, so pausing in the middle of the script isn’t going do what you need. Also, I think “after” and “sleep” will both pause the entire process, which will impact everything else running in that process.

            May I ask why you need the pause?

          • #113464
            Charlie Bursell
            Participant

              Unless things have changed you cannot put the engine to sleep as that would cause a myriad of other problems.

              Tell us what you are trying to do.  There must be a better solution.

            • #113465
              Alison Benecchi
              Participant

                I need the pauses in the message because the vendor system can’t handle the messages in quick succession (.001 apart) and is processing the messages out of order.  The A31’s need to be processed after the A05s.

              • #113466

                Adding a sleep to a process is typically not a good practice because it blocks the process and all of messages in the flow queue up. What I tend to do instead when I need to introduce a delay is to ether right the messages to a file and use a second pair of threads with a fileset-local with a TPS Dir Proc to wait on the message to be a certain age and/or type before processing them, or, when more complex processing rules are needed, I’ve written messages to a SQLite database instead of a file and used SQL queries to select the messages. For example, the database could have a column for date/time and a column for the HL7 trigger (ex. ADT^A05).

                -- Max Drown (Infor)

              • #113476
                Anonymous

                  Alison, when creating multiple messages from a single inbound you can dictate the order that those messages leave Cloverleaf. I use chain for that. But nothing built into the Cloverleaf real-time engine for pausing. I think most people do what Max suggests with a fileset-local since that type of thread can be configures with a delay between message reads.

                • #113477
                  Jim Kosloskey
                  Participant

                    It might also be useful to investigate the re-route capability for the A31s. The A05 would be CONTINUED as normal but the A31s Re-routed.

                    That will send those messages back through the route processing which by itself might introduce sufficient delay.

                    You would set a new TrxID with the re-route then a new routing for that TrxID.

                    I have re-routed within an Xlate (really quite simple) but not in a Tcl proc although as I recall it is fairly straightforward and pretty well documented in help.

                    I think re-routing was introduced in Cloverleaf 6.0.

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

                  • #113480
                    Jim Kosloskey
                    Participant

                      Another option is to find out if the receiving system can delay sending acknowledgments. I would not go to high (2 seconds may be too much especially during peak demand period). Too high and you might end up with an undesirable pending situation during peak demand period.

                      That way, they can control the pace.

                      I would think nothing more than 1 second. If they can determine some time less than 1 second which will give their system time to process that would be better.

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

                  Viewing 7 reply threads
                  • You must be logged in to reply to this topic.