› Clovertech Forums › Read Only Archives › Cloverleaf › Cloverleaf › Filter msg by comparing dates
1. Is this the best route to take? I
Convert the two dates into seconds with clock scan.
You can then compare the dates as integers.
Jeff Dinsmore
Chesapeake Regional Healthcare
I would like to take this opportunity to thank Jim Kosloskey for having written so many nice generic argument driven procs like ( oth_chk_time_span ).
Since many of the generic argument driven procs Jim has written are extensive in capability they may seem overwhelming at a glance, but once you understand how to use the proc arguments, you find it was worth the effort.
Also, the more widely a set of generic procs is used, the bugs can be discovered and the proc can evolve to a more robust version.
Jim is very receptive to getting feedback about bugs to his procs and fixing it if time allows.
You may have guessed by now, I would see if our callable generic proc ( oth_chk_time_span.tcl ) would work for what you are wanting to do.
It is posted at this URL
https://usspvlclovertch2.infor.com/viewtopic.php?p=11392#11392
Also, a search of clovertech will likely yield many useful examples as I recall posts about this topic over the years.
Russ Ross
RussRoss318@gmail.com
Thank you both for the information.
Going off of Jeff’s suggestion, we obtain the date values, convert those values to Julian date, then determine if the admit date is greater than the message date, and if it is, then block the message. I realized the Julian date does not calculate from an epoch, but from January 1st of the given year. That
A typical date/time value is something like this:
set ds 20110518102344
Try something like:
set cs [clock scan “[string range $ds 4 5]/[string range $ds 6 7]/[string range $ds 0 3] [string range $ds 8 9]:[string range $ds 10 11]”]
cs in this case will be 1305728580
then use this as a base reference to get relative time – for example: $cs + 60 hours like this:
set xs [clock scan “60 hours” -base $cs]
1305944580
You can get the difference between two dates
puts “difference= [expr ($xs – $cs) / 60.0] minutes”
difference= 3600.0 minutes
puts “difference= [expr ($xs – $cs) / (60.0 * 60)] hours”
difference= 60.0 hours
puts “difference= [expr ($xs – $cs) / (60.0 * 60 * 24)] days”
difference= 2.5 days
This method doesn’t care about day/month/year boundaries.
I usually use catch for the clock scan execution in case you get an unexpected value – something like this:
if { [catch {set cs [clock scan “[string range $ds 4 5]/[string range $ds 6 7]/[string range $ds 0 3] [string range $ds 8 9]:[string range $ds 10 11]”]} err] } { puts “something bad happened (err= $err) }
Jeff Dinsmore
Chesapeake Regional Healthcare
Thanks Jeff.
I’ll give it a try as soon as I have time. This is my first time working with the clock command and I was not clear on the syntax.
I really appreciate everyone’s help!!!
One way to do it Jeff. To make an HL7 timstamp scanable I usually do something like
set TS 20110519134040 ;# HL7 Time stamp
regsub — {(d{8})(.*)} $TS {1 2} TS
set CS {clock scan $TS]
==> 1305830440
Not better just different 🙂
Yep. Many different ways to skin a cat.
As I recall, I have had occasional scan problems with formats that don’t include explicit slashes and/or colons in the date/time. Perhaps no longer necessary with current Tcl versions, but I still err on the side of caution.
Jeff Dinsmore
Chesapeake Regional Healthcare
Thanks to everyone for all of your suggestions. Sorry it took so long to respond, I have it working almost as expected. If PV1.44 (admit date) is older than the timestamp of the message, the message is passed. This appears to work even if PV1.44 is blank. The issue I am currently having is I need to check to see if the messag is an A08 first. If it is not an A08, then pass the message, if it is an A08, then I need to run it against the proc.
Below is the full proc (which probably could be done in a much simpler form), and any suggestions on how to first check if the message is an A08 would be greatly appreciated. Thanks again for all of your suggestions.
proc filter_time { args } {
keylget args MODE mode ;# Fetch mode
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]
set segments [split $msg r]
set msh_loc [lsearch -regexp $segments “^MSH”]
set msh_seg [lindex $segments $msh_loc]
set msh_fld7 [lindex [split $msh_seg |] 6]
set msg_type [lindex [split $msh_seg |] 8]
set msg_time [csubstr $msh_fld7 0 14]
regsub — {(d{8})(.*)} $msg_time {1} msg_time
set TS [clock scan $msg_time]
set pv1_loc [lsearch -regexp $segments “^PV1”]
set pv1_seg [lindex $segments $pv1_loc]
set pv1_44 [lindex [split $pv1_seg |] 44]
set admit_time [csubstr $pv1_44 0 14]
regsub — {(d{8})(.*)} $admit_time {1} admit_time
set ATS [clock scan $admit_time]
set x [expr {$TS – $ATS}]
puts “msg_type: $msg_type”
puts “MSH Time: $msg_time”
puts “PV1_44 Time: $admit_time”
puts “TS: $TS”
puts “ATS: $ATS”
puts “x= $x”
# If message type is ADT^A08
# and PV1 field-44.1 is blank, pass message
# If PV1.44 is not blank, and MSH Timestamp is greater
# than admit timestamp pass message
if {[expr {$TS – $ATS} < 0]} {
lappend dispList “KILL $mh”
} else {
lappend dispList “CONTINUE $mh”
}
}
shutdown {
# Doing some clean-up work
}
default {
error “Unknown mode ‘$mode’ in filter_time”
}
}
return $dispList
}
set triggerEvent [lindex [split [lindex [split $msh_seg |] 8] ^] 1]
Jeff Dinsmore
Chesapeake Regional Healthcare
Jeff,
Thanks, but I have the following code in the proc to pull the message type:
set msg_type [lindex [split $msh_seg |] 8]
Result: ADT^A08
Either way works, although I like your suggestion better. But I’m having trouble with the syntax of how to pass the message if it is not an A08 before it runs through the entire proc.
Any suggestionshelp is appreciated.
I’ve been clawing my way up this hill which is turning into a mountain. I found in one case where PV1.44 was blank, that it killed the message. The value of $ATS = 1302066000
Test message is below. The only way I can think of to resolve that issue is if the message is an A08 and PV1.44 is null, then pass the message. Added to that my previous comment of passing all messages that are not A08s.
I may be overlooking something simple, but hopefully someone out there in Clovertech land can point me in the right direction. Thanks.
MSH|^~&|REG|RMC||RMC|20110520000430||ADT^A08|2200765|D|2.2|
EVN|A08|20110520000430|||OO
PID|||0600644|116599|HSM^TEST3^^^^||19540503|M||W|1234 MAIN STREET^^KANKAKEE^IL^60901^^|KANK|(815)933-1671||EA|M||003101602|632-33-6699|||E2||||||
PV1||O|SDS|3|||321^OLOFSSON^BRIAN^P^^MD|||SDS||||1J|||321^OLOFSSON^BRIAN^P^^MD|SDS|706|COMMERCIAL|||||||||N|||||||01|||||D|||||||||||||
PV2|||HSM TESTING||Y|||||
IN1|1|099|C5856|AFLAC OPEN ACCESS|1444 N FARNSWORTH AVE ^STE 302^AURORA^IL^60505^^|||||||||||HSM^TEST3^|18|19540503|1234 MAIN STREET^^KANKAKEE^IL^60901^^||||||||||||||||||||||||M||
IN2||632-33-6699|^||||||||||||||||||||||||||||
IN1|2||123|SELF PAY – E|^^^^^^|||||||||||HSM^TEST3^|18|19540503|^^^^^^||||||||||||||||||||||||M||
IN2||632-33-6699|^||||||||||||||||||||||||||||
ZCN|T123456|HS|TN|
Shaun,
Passing the message if it’s not an A08, before it runs through the entire proc, can be accomplished in the following way. Right after you pull the message type, if it’s not an A08, you just set the disposition to “CONTINUE” and return the disposition:
if {![string equal $msg_type ADT^A08]} {
# Not an ADT^A08, just send it on and exit the procedure
set dispList [list “CONTINUE $mh”]
return $dispList
}
# If you get here, the message is definitely an A08 and you can run the
# rest of your code. The added advantage is that you no longer have to
# issue ‘if’ statements against the message type.
Shawn:
I though I gave you copies of example procs when you were in my class.
Here is one of them again. Should answer your question
Charlie
Charlie,
You did give me a copy, and I have it…somewhere.
Thanks.