trouble with tcl proc to change total exercise time format

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf trouble with tcl proc to change total exercise time format

  • Creator
    Topic
  • #49385
    Joseph Paquette
    Participant

      having problems changeing the total exercise time from seconds to minutes and seconds,  Here is my code..

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

      # Name: tps_fixexertime

      # Purpose: to change the total exercise time from seconds to minutes and seconds

      # UPoC type: tps

      # Args: tps keyedlist containing the following keys:

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

      #       MSGID   message handle

      #       ARGS    user-supplied arguments:

      #               no args.

      #

      #

      proc tps_fixexertime { args } {

         keylget args MODE mode               ;# Fetch mode

         set dispList {} ;# Nothing to return

         switch -exact — $mode  {

             start {

             }

             run {

      keylget args MSGID mh

      set msg [msgget $mh] ;# get message

      set msgList [split $msg r]

      set nlist $msgList

      set mshseg [lindex $msgList 0]

            set field_sep [cindex $mshseg 3]

      set sub_sep [cindex $mshseg 4]

      set rep_char [cindex $mshseg 5]

      set segctr 0

      foreach seg $msgList { ;# start loop through segments

      set segtype [csubstr $seg 0 3]

      incr segctr 1

      if [cequal $segtype OBX] { ;# check for OBX seg

      set obxfields [split $seg $field_sep]

      set obx3 [lindex $obxfields 3]

      if [cequal $obx3 STRESSMEASANDDIAG] { ;# check for stressmeasanddiag

      set newctr $segctr

      incr newctr -1

      set obx5 [lindex $obxfields 5]

      set fields [split $obx5 $rep_char]

      set totalextime [lindex $fields 1]

      set len [string length $totalextime]

      set unitpos [expr $len – 4]

      set pos [expr $unitpos – 1]

      set units [string range $totalextime $unitpos $len]

      if [cequal $units secs] {

      set secs [string range $totalextime 21 $pos]

      set minutes [expr $secs / 60]

      set remainder [fmod $secs 60]

      set seconds [string trim $remainder .0]

      set newtotextim “Total Exercise Time: $minutes Minutes $seconds seconds”

      set newfields [lreplace $fields 1 1 $newtotextim]

      set newobx5 [join $newfields $rep_char]

      set newobx [lreplace $obxfields 4 4 $newobx5]

      set newobxseg [join $newobx $field_sep]

      set newmsg [lreplace $nlist $newctr $newctr $newobxseg]

      } ;# end if units = secs

      } ;#  end stressanddiag

      } ;# end OBX seg

      } ;# end for each

      set new [join $newmsg r]

      echo “new: ” $new

      keylget args MSGID mh

               lappend dispList “CONTINUE $mh”

      msgset $mh [join $newmsg r]

      }

             time {

                 # Timer-based processing

         # N.B.: there may or may not be a MSGID key in args

             }

             

             shutdown {

         # Doing some clean-up work

      }

         }

         return $dispList

      }

      here is the test file i am using in the testing tool in QDX 5.3.1

      MSH|^~&|Stress Result|HL7 Result|quovadx Result|QDX|20070702183245||ORU^R01|20070702183245|P|2.4

      PID|1|123456789|||PATIENT^TEST||19490728|M||C|^^^^^|||||||1111111111|

      PV1|1||(213)^^^SITE0001^^^^213^||||^^^^^^^^^^^|^HOMBURG^NANCY^^^^^^^^^|^^^^^^^^^^^||||||||^^^^^^^^^^^|||||||||||||||||||||||||||||||||

      OBR|1|123456789||^^^^Stress Test||20070702183245|200707033083637||||||^|||^GELLER^KENNETH^^^^^^^^481^||||26||20070702183245|||C||||||FU HTN FAM HX|^MuseAdmin^MuseAdmin^^^^^^^^20001^|^^^^^^^^^^^|^BARANY^JANE^^^^^^^^^^235^||^MuseAdmin^MuseAdmin^^^^^^^^^^20001^|||

      DG1|1|||

      DG1|2||

      DG1|3||

      NTE|1||

      ZEX|1|^^^|^^^|^^^|

      OBX|1|FT|STRESSMEASANDDIAG||Acquisition Time: 2001-07-23  08:36:37~Total Exercise Time: 630 secs~Test Indications: FU HTN FAM HX~Medications:~Protocol: BRUCE           ~Max HR: 129 BPM  76% of  Pred: 169 BPM~Max BP: 204/088 mmHG~Max Work Load: 12.5 METS~~NORMAL STRESS TEST BUT TO LESS THAN MAXIMAL PREDICTED HEART RATE SECONDARY TO~ ATENOLOL~NO SYMPTOMS AND NO ISCHEMIA WITH WELL PRESERVED  EXERCISE CAPACITY~~Referred By: NANCY HOMBURG           Overread By: MuseAdmin MuseAdmin||||||D|

      I am getting very weird results,  in the testing tool i seem to get the right values in the obx segment when viewing in the testiing tool using the echo cmd,  however it will not allow me to get the right values out in the message.  I do get some mixed results in the testing tool,  they are listed below

      Please Wait ……

      Command Issued: hcitpstest -r run -a -f eof -c sms_ib_data -e “broadcaster ” c:/gehc-it/ccg/quovadx/qdx5.3/integrator/muse_prod/stress1.txt “tps_fixexertime”Command output:

      new:  MSH|^~&|Stress Result|HL7 Result|quovadx Result|QDX|20070702183245||ORU^R01|20070702183245|P|2.4PID|1|123456789|||PATIENT^TEST||19490728|M||C|^^^^^|||||||1111111111|PV1|1||(213)^^^SITE0001^^^^213^||||^^^^^^^^^^^|^HOMBURG^NANCY^^^^^^^^^|^^^^^^^^^^^||||||||^^^^^^^^^^^|||||||||||||||||||||||||||||||||OBR|1|123456789||^^^^Stress Test||20070702183245|200707033083637||||||^|||^GELLER^KENNETH^^^^^^^^481^||||26||20070702183245|||C||||||FU HTN FAM HX|^MuseAdmin^MuseAdmin^^^^^^^^20001^|^^^^^^^^^^^|^BARANY^JANE^^^^^^^^^^235^||^MuseAdmin^MuseAdmin^^^^^^^^^^20001^|||DG1|1|||DG1|2||DG1|3||NTE|1||ZEX|1|^^^|^^^|^^^|OBX|1|FT|STRESSMEASANDDIAG|Acquisition Time: 2001-07-23  08:36:37~Total Exercise Time: 10 Minutes 3 seconds~Test Indications: FU HTN FAM HX~Medications:~Protocol: BRUCE           ~Max HR: 129 BPM  76% of  Pred: 169 BPM~Max BP: 204/088 mmHG~Max Work Load: 12.5 METS~~NORMAL STRESS TEST BUT TO LESS THAN MAXIMAL PREDICTED HEART RATE SECONDARY TO~ ATENOLOL~NO SYMPTOMS AND NO ISCHEMIA WITH WELL PRESERVED  EXERCISE CAPACITY~~Referred By: NANCY HOMBURG           Overread By: MuseAdmin MuseAdmin|Acquisition Time: 2001-07-23  08:36:37~Total Exercise Time: 630 secs~Test Indications: FU HTN FAM HX~Medications:~Protocol: BRUCE           ~Max HR: 129 BPM  76% of  Pred: 169 BPM~Max BP: 204/088 mmHG~Max Work Load: 12.5 METS~~NORMAL STRESS TEST BUT TO LESS THAN MAXIMAL PREDICTED HEART RATE SECONDARY TO~ ATENOLOL~NO SYMPTOMS AND NO ISCHEMIA WITH WELL PRESERVED  EXERCISE CAPACITY~~Referred By: NANCY HOMBURG           Overread By: MuseAdmin MuseAdmin||||||D| can’t read “mode”: no such variable    while executing”switch -exact — $mode { start { # Perform special init functions # N.B.: there may or may not be a MSGID key in args } run { # ‘run’ mo…”    (procedure “broadcaster” line 8)    invoked from within”broadcaster   { MSGID message0 } { DISP CONTINUE } { ARGS {} }”

      and sometimes i get this by re-running the same process..  I am very confused on why this is not fucntioning properly.

      Please Wait ……

      Command Issued: hcitpstest -r run -a -f eof -c sms_ib_data -e “broadcaster ” c:/gehc-it/ccg/quovadx/qdx5.3/integrator/muse_prod/stress1.txt “tps_fixexertime”Command output:

      can’t read “mode”: no such variable    while executing”switch -exact — $mode { start { # Perform special init functions # N.B.: there may or may not be a MSGID key in args } run { # ‘run’ mo…”    (procedure “broadcaster” line 8)    invoked from within”broadcaster   { MSGID message0 } { DISP CONTINUE } { ARGS {} }”new:  MSH|^~&|Stress Result|HL7 Result|quovadx Result|QDX|20070702183245||ORU^R01|20070702183245|P|2.4PID|1|123456789|||PATIENT^TEST||19490728|M||C|^^^^^|||||||1111111111|PV1|1||(213)^^^SITE0001^^^^213^||||^^^^^^^^^^^|^HOMBURG^NANCY^^^^^^^^^|^^^^^^^^^^^||||||||^^^^^^^^^^^|||||||||||||||||||||||||||||||||OBR|1|123456789||^^^^Stress Test||20070702183245|200707033083637||||||^|||^GELLER^KENNETH^^^^^^^^481^||||26||20070702183245|||C||||||FU HTN FAM HX|^MuseAdmin^MuseAdmin^^^^^^^^20001^|^^^^^^^^^^^|^BARANY^JANE^^^^^^^^^^235^||^MuseAdmin^MuseAdmin^^^^^^^^^^20001^|||DG1|1|||DG1|2||DG1|3||NTE|1||ZEX|1|^^^|^^^|^^^|OBX|1|FT|STRESSMEASANDDIAG|Acquisition Time: 2001-07-23  08:36:37~Total Exercise Time: 10 Minutes 3 seconds~Test Indications: FU HTN FAM HX~Medications:~Protocol: BRUCE           ~Max HR: 129 BPM  76% of  Pred: 169 BPM~Max BP: 204/088 mmHG~Max Work Load: 12.5 METS~~NORMAL STRESS TEST BUT TO LESS THAN MAXIMAL PREDICTED HEART RATE SECONDARY TO~ ATENOLOL~NO SYMPTOMS AND NO ISCHEMIA WITH WELL PRESERVED  EXERCISE CAPACITY~~Referred By: NANCY HOMBURG           Overread By: MuseAdmin MuseAdmin|Acquisition Time: 2001-07-23  08:36:37~Total Exercise Time: 630 secs~Test Indications: FU HTN FAM HX~Medications:~Protocol: BRUCE           ~Max HR: 129 BPM  76% of  Pred: 169 BPM~Max BP: 204/088 mmHG~Max Work Load: 12.5 METS~~NORMAL STRESS TEST BUT TO LESS THAN MAXIMAL PREDICTED HEART RATE SECONDARY TO~ ATENOLOL~NO SYMPTOMS AND NO ISCHEMIA WITH WELL PRESERVED  EXERCISE CAPACITY~~Referred By: NANCY HOMBURG           Overread By: MuseAdmin MuseAdmin||||||D|

    Viewing 1 reply thread
    • Author
      Replies
      • #61734
        Charlie Bursell
        Participant

          You make it way too complicated for me.  Try this:

          run {

             keylget args MSGID mh

             set msg [msgget $mh]

             # Get separators

             set fldSep [string index $msg 3]

             set subSep [string index $msg 4]

             set subSep [string index $msg 4]

             set repSep [string index $msg 5]

             # Get segments

             set segments [split $msg r]

             # Get a list of all OBX segments – Get rid of one half of the if

             # statement depending on which version of Tcl you are on

             # If on Tcl 8.4 CL 8.4.1+  or Tcl 8.3

             if {![string equal [info tclversion] 8.3]} {

                 # Tcl 8.4+

                 set obxLoc [lsearch -all -regexp $segments {^OBX}]

             } else {

                 # If on Tcl 8.3

                 set tmpLst $segments

                 set obxLoc {}

                 set loc [lsearch -regexp $tmpLst {^OBX}]

                 while {$loc >= 0} {

                     lappend obxLoc $loc

                     lvarpop tmpLst $loc XXXXXX

                     set loc [lsearch -regexp $tmpLst {^OBX}]

                 }

             }

             foreach loc $obxLoc {

                 set obxFlds [split [lindex $segments $loc] $fldSep]

                 if {![string equal [lindex $obxFlds 3] STRESSMEASANDDIAG]} {

                     continue

                 }

                 set obx5Reps [split [lindex $obxFlds 5] $repSep]

                 set exercise [lindex $obx5Reps 1]

                 if {![regexp -nocase — {^Total Exercise Time: (d+) secs}

                             $exercise {} seconds]} {continue}

                 set min [expr {$seconds / 60}]

                 set secs [expr {$seconds % 60}]

                 set exercise “Total Exercise Time: $min Minutes $secs Seconds”

                 set obx5Reps [lreplace $obx5Reps 1 1 $exercise]

                 set obxFlds [lreplace $obxFlds 5 5 [join $obx5Reps $repSep]]

                 set segments [lreplace $segments $loc $loc

                                         [join $obxFlds $fldSep]]

             }

              msgset $mh [join $segments r]

              return “{CONTINUE $mh}”

          }

        • #61735
          Michael Hertel
          Participant

            Joseph,

            Your first problem is that you are using the testing tool wrong.

            In the “send to proc” box, do not choose “broadcaster”.

            Choose “hcitpstestshowbydisp”.

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