Copy out proc

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf Copy out proc

  • Creator
    Topic
  • #50294
    Mark Perschbacher
    Participant

      I have a fairly simple proc I wrote that extracts data from incoming ADT or ORM’s, creates a file name with a time stamp, and copies the data out to it.  When I run it through the tester, route test, and tps with show by dest, it works fine.  When I place it in the inbound thread, route messages, xlate prop., preproc or post proc, it creates the file, but it is 0 bytes, any ideas.  Here is the proc

      proc insurance_sheet { args } {

         set mode [keylget args MODE]

         switch -exact — $mode {

      start {

      }

               

                run {  

      set mh [keylget args MSGID]

      set msg [msgget $mh]

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

      set seg_list [split $msg r]

      foreach seg $seg_list {

      set name [lindex [lregexp $seg_list {^MSH}] 0]

      set ID [lindex [split $name $fldSep] 6]

        set patient [lindex [lregexp $seg_list {^PID}] 0]

      #set ID [lindex [split $seg $fldSep] 5]

      set obr [lindex [lregexp $seg_list {^OBR}] 0]

      set doctor [lindex [split $obr $fldSep] 16]

      set test [lindex [split $obr $fldSep] 4]

      set time [clock format [clock seconds] -format “%Y%m%d%H%M%S”]

      set insur [lindex [lregexp $seg_list {^IN1}] 0]

      set gurant [lindex [lregexp $seg_list {^GT1}] 0]

      set insur2 [lindex [lregexp $seg_list {^IN1}] 1]

      set data “{$patient}rnnn{$doctor}rnnn{$test}rnnn{$insur}rnnn{$insur2}rnnn{$gurant}”

      set file [open $time w]

      puts $file $data

      #exec lpr -S 192.168.160.26 -P HP LaserJet 4000 Series PCL on SKAGIT_PATHOLOG $file

      #exec print $file

         return “{CONTINUE $mh}”

            }

       

                                   

      }          

      }

      }

      time {

      }

    Viewing 7 reply threads
    • Author
      Replies
      • #65515
        Steve Carter
        Participant

          Could it be as simple as the fact that you’re not closing the file handle after you write to it?  Add ‘close $file’ after the puts and see if that fixes your problem.

          Steve

        • #65516
          Mark Perschbacher
          Participant

            I had the close statement in their originally, but I was getting a file access error in the tester, so I took it out.  I just added it back in, and it looks like it worked.  Thanks for the obvious suggestion.

          • #65517
            Steve Carter
            Participant

              Another one of the wonderful quirks of the testing tool.  My guess is that if you had shutdown the process, it would have flushed/closed the handle and your data would have appeared.

              Steve

            • #65518
              Dinakar Desai
              Participant

                Your code had few problems. I have fixed them. Please try it with following code.

                proc insurance_sheet { args } {

                set mode [keylget args MODE]

                switch -exact — $mode {

                start {

                }

                run {  

                set mh [keylget args MSGID]

                set msg [msgget $mh]

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

                set seg_list [split $msg r]

                set data “”

                set time [clock format [clock seconds] -format “%Y%m%d%H%M%S”]

                foreach seg $seg_list {

                set name [lindex [lregexp $seg_list {^MSH}] 0]

                set ID [lindex [split $name $fldSep] 6]

                set patient [lindex [lregexp $seg_list {^PID}] 0]

                #set ID [lindex [split $seg $fldSep] 5]

                set obr [lindex [lregexp $seg_list {^OBR}] 0]

                set doctor [lindex [split $obr $fldSep] 16]

                set test [lindex [split $obr $fldSep] 4]

                set insur [lindex [lregexp $seg_list {^IN1}] 0]

                set gurant [lindex [lregexp $seg_list {^GT1}] 0]

                set insur2 [lindex [lregexp $seg_list {^IN1}] 1]

                append data “{$patient}rnnn{$doctor}rnnn{$test}rnnn{$insur}rnnn{$insur2}rnnn{$gurant}”

                #exec lpr -S 192.168.160.26 -P HP LaserJet 4000 Series PCL on SKAGIT_PATHOLOG $file

                #exec print $file

                }

                set file [open $time w]

                puts $file $data

                close $file

                return “{CONTINUE $mh}”

                }          

                time {

                }

              • #65519
                Mark Perschbacher
                Participant

                  Thanks Denakar, I will give it a try.  Did you go to Cloverleaf Level 1 training back in April of 2005?

                • #65520
                  Mark Perschbacher
                  Participant

                    Got one last piece I am trying to code.  For the IN1 and DG1, they are repeating segments, and I am trying to get the code to iterate.  I can get the first pass of lregexp to pull the repeating segments by using lrange.  It is the lindex split statement that I am having trouble getting to work.  The basic issue is that I am designating a field separator for the first segment, but need an expression that will grab the second, something link lindex a and b.  Any ideas?

                  • #65521
                    Dinakar Desai
                    Participant

                      make use of that foreach loop over segment with switch.

                      Dinakar

                    • #65522
                      Mark Perschbacher
                      Participant

                        can you provide a sample of the switch you are referring to?

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