unable to convert date-time string question

Homepage Clovertech Forums Read Only Archives Cloverleaf Tcl Library unable to convert date-time string question

  • Creator
    Topic
  • #51722
    Kevin Crist
    Participant

    i have a question about an error. The below tclproc has been running since last thursday. This morning i had one error,  ‘unable to convert date-time string “20100428 0035″‘. The following messages seemed to have worked so i am not real sure why this one errored.

    Here is the segment and field i am working with: Is there something in my code i need to change so this doesnt happen again? Or can someone explain why this errored. Thanks for any info.

    OBR|1||201004280035-70^RI|ABS^CLIN ABSTRACT PDF^INPC||201004280035|

    OBX|1|ED|ABS^CLIN ABSTRACT PDF^INPC||INPCDOC^application^^BASE64^JVBERi0xLjQKJ

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

    # Name: tpsBDI_OBX

    # Purpose: This tclproc is for the INPC Clinical Abstact. It fixes the

    # OBX-5 issue.

    #

    # UPoC type: tps

    # Args: tps keyedlist containing the following keys:

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

    #       MSGID   message handle

    #       ARGS    user-supplied arguments:

    #

    #

    #

    # Returns: tps disposition list:

    #          Continues the messages

    # or

    # Errors message if OBR, ORC is missing

    #

    # Created: Kevin Crist, John Zalesak 05/27/2009

    #

    #

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

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

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

    proc tpsBDI_OBX { args } {

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

    # Get the Connection/Proc Name for Error/Debug Messages

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

    global HciConnName

    set myname “$HciConnName/[lindex [info level 1] 0]”

    set nowis [clock format [clock scan now] -format “%D – %T”]

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

    # Initialize Variables Used

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

    set dispList

  • ;# Disposition List Returned to Engine

    set fldSep “” ;# Field Seperator – get from MSH

    set subSep “” ;# SubField Seperator – get from MSH

    set repSep “” ;# Repeating Field Seperator – get from MSH

           

    set OBRpos -1 ;# Position of OBR Segment in msg

    set OBRList

  • ;# OBR Segment Fields in List Form

    set OBXpos -1 ;# Position of OBX Segment in msg

    set OBXList

  • ;# OBX Segment Fields in List Form

     set OBXPDF 5 ;# Field in the OBX that the PDF encoding is in

     

     set OBRDateTime 6  ;# Field in the OBR that the date/time is in

     set OBRTestCode 4 ;# Field in the OBR that the test code is in

     

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

    # Switch based on what mode the engine was in when it called the procedure

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

    keylget args MODE mode             ;# The mode the engine called from

     switch -exact — $mode {

      start { }

       run {

        set mh [keylget args MSGID] ;# Get message handle from args

       set dispList

      ;# Initialize to good message

           set msg [msgget $mh] ;# Get a copy of the message

           set fldSep [string index $msg 3] ;# Field Seperator

           set subSep [string index $msg 4] ;# Sub-Field Seperator

           set repSep [string index $msg 5] ;# Repeating Field Seperator

      set segList [split $msg r] ;# Split message into segList

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

      # Find Position of Segements – If missing -> Error out Message and Return

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

      set OBRpos [lsearch -regexp $segList {^OBR}]

      set OBXpos [lsearch -regexp $segList {^OBX}]

      if {$OBXpos < 0} {      msgmetaset $mh USERDATA “Required Segment OBX Missing!”  echo n n n  echo “:WARN – $OBXpos Segment Missing !”  echo “:WARN – Sending Message to error db.”  echo “:WARN – Here Is: $myname”  echo “:WARN – Now Is: $nowis”  echo $msg  echo n n n            set dispList

             return $dispList

      }

         

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

      # Split out the OBR and get the OBR-7 date/time so that it can be reformatted

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

      set OBRList [split [lindex $segList $OBRpos] $fldSep]

      #echo OBRList: $OBRList

           set datetime [lindex $OBRList $OBRDateTime]

         #The below regsub formats the date so that the following clock scan can be performed.

          regsub — {(d{8})(d+)} $datetime {1 2} datetime

          set datetime [clock format [clock scan $datetime] -format “%m/%d/%Y %H:%M”]

      #echo datetime: $datetime

       

      #  set newdatetime [string map {{ {}} $datetime]

      #echo newdatetime: $newdatetime  

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

      # Get the OBR-4 so that we can append that date and time to it.

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

        set testcode [lindex [split [lindex $OBRList $OBRTestCode] $subSep] 0]

      #echo testcode: $testcode

         lappend newtestcode $testcode $datetime

      #echo newtestcode: $newtestcode

           set newtestcode [string map {{ {} } {}} $newtestcode]

      set OBRList [lreplace $OBRList 4 4 $newtestcode]

       

         

         

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

      # Split out the OBX and get the OBX-5 and fill in the field with the .

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

       

         set OBXList [split [lindex $segList $OBXpos] $fldSep]

       

         set pdfcode [lindex [split [lindex $OBXList $OBXPDF] $subSep] 4]

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

      # Replacing the OBR DXCode code in the OBR-19

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

      set OBXList [lreplace $OBXList 5 5 $pdfcode]

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

      # Putting the OBR segment back together with the DXCode code in the OBR-19

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

         lset segList $OBRpos [join $OBRList $fldSep]

           lset segList $OBXpos [join $OBXList $fldSep]

           msgset $mh [join $segList r]

         

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

      # Rebuild msg and store at mh for engine

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

      }

         time { }

         shutdown { }

      } ;# End Switch

      return $dispList

      } ;# End Proc

Viewing 5 reply threads
  • Author
    Replies
    • #71449
      John Mercogliano
      Participant

      This is actually a bug that is not fixed till tcl version 8.5.  

       This link talks about the problem and has some regsub commands you can use:

      <a href="http://clovertech.infor.com/viewtopic.php?t=2613&highlight=&#8221; class=”bbcode_url”>http://clovertech.infor.com/viewtopic.php?t=2613&highlight=

      John Mercogliano
      Sentara Healthcare
      Hampton Roads, VA

    • #71450
      Kevin Crist
      Participant

      very cool, thanks John.

      I will tinker with that for a while.

    • #71451
      Tom Rioux
      Participant

      Kevin,

      We ran into a similar issue when doing a date comparison in a script here.  The clock scan command expects the hours, minutes, and seconds when parsing the command.   If you don’t specify the seconds, you will get an error if the minutes are anything over 23.   Here is why.   Take the two expressions below:

      hcitcl>clock scan “20100427 002300”

      1272345780

      hcitcl>clock scan “20100427 0023”

      1272427200

      The first one is correct because it has the hours, minutes, and seconds.  If you specify it as the second one, the clock scan command will treat that as if you had specified it as “20100427 230000”.  See the command below:

      hcitcl>clock scan “20100427 230000”

      1272427200

      The numbers match!

      What we have done here in our date comparison (since seconds aren’t vital to what we are trying to accomplish), is to default the seconds in the clock scan for a all dates to 00.   This should get you what you want without generating any errors.

      Hope this helps….

      Tom Rioux

    • #71452
      Kevin Crist
      Participant

      Thanks Tom, John

      I have the fix and a better understanding.

    • #71453
      Chris Williams
      Participant

      Can it be a bug if it’s behaving as designed? If you RTFM for the clock command you see the following:

      Quote:

      ISO 8601 point-in-time:

      An ISO 8601 point-in-time specification, such as CCyymmddThhmmss,  where  T is the literal T, CCyymmdd hhmmss, or CCyymmddThh:mm:ss.  Note that only  these  three  formats are accepted.  The command does not accept the full range of point-in-time  specifications  specified  in  ISO8601. Other formats can be recognized by using commands such as regexp to extract their fields and reorganize them into a form accepted by the clock scan command.

    • #71454
      John Mercogliano
      Participant

      Chris,

       Please look at the sourceforge link I posted.  Yes this is a bug that has been fixed in 8.5.  In any case you are misreading the man page.  The ISO specification is one of 4 ways that you can call the command.  Either with just the Time, Date, ISO, or relative.  The text you posted is only valid when trying to pass an ISO value to the clock command.

       The bug is specific to how the Time value is parsed.

      John Mercogliano
      Sentara Healthcare
      Hampton Roads, VA

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

Forums

Forum Statistics

Registered Users
5,129
Forums
28
Topics
9,301
Replies
34,448
Topic Tags
288
Empty Topic Tags
10