› Clovertech Forums › Read Only Archives › Cloverleaf › Product Enhancements › Xlate Date Calculation
Is there a way to add logic in Xlate utilizing PID-7 (DOB)?
Also – I was not able to identify Adult vs Children in VXU field.
Thank you!
There are two general ways to add Logic to Xlates. The first is to use code snippets (scripts) in TCL (or Java, if you must) as an Xlate statement Pre-Proc. The other is to write it as a series of Xlate statements using the various Xlate command statements.
‘IF’ statements and simple MATH statements are pretty straight forward to perform basic logic points, even if the syntax is a bit bizarre. More complicated logic should be done in TCL as it can be well contained and commented with a single Xlate ‘COPY’ statement.
Regarding your question, you can have multiple source elements in a COPY statement, such as PID:7 and OBX:5. Then use TCL ‘lindex’ commands to pull out the values from the $xlateInVals variable list and perform your logic. At the end, you’d put the resulting value(s) into the $xlateOutVals variable list.
Hope this helps.
Is there any existing logic that would be useful to calculate age?
Thank you for your response.
There are a half dozen or so CloverTech articles on this subject that have some basic code to get you in the ball park. Try searching “calculate age” while checking the “all” box on the CloverTech search screen.
You will find that age calculations using CLOCK SCAN can be difficult and inaccurate do to leap years, 32 bit variables, etc.
If you want to get some longer starter code on the subject, take a look at this web page:
For even more, do a Google search for TCL calculate age…
lassign $xlateInVals dob_date
# get yr, m and day only
set temp_date [string range $dob_date 0 7]
# todays date minus 11 years
set calc_date [clock format [clock scan ” – 11 years”] -format “%Y%m%d”]
# compare dates – if birthdate less than calculated date, use patient
if {$dob_date < $calc_date} {
set out_flag N
} else {
set out_flag Y
}
set xlateOutVals [list $out_flag]
Paul Bishop
Carle Foundation Hospital
Urbana, IL
So what we did is to condition the DOB properly to submit to the proc (some systems do not build that correctly). Depending on your Cloverleaf release you may or may not need some Tcl to do the conditioning.
Then we invoked the proc to add 18 Yrs to the DOB (the offset is an argument so one could add virtually any time period) giving a resultant date. The proc allows specifying how the result date should be formatted.
Then as I recall a simple Xlate IF Action will determine the relationship of today’s date to the DOB vis-
email: jim.kosloskey@jim-kosloskey.com 29+ years Cloverleaf, 59 years IT - old fart.
We also submit VXU for 19 yr olds and under (unless Rabies – then all Rabies vaccines must be sent to DOH) and it seems to be working fine for us, has been in place quite some time. You would just have to adjust your days to be 18 yr old.
Pre proc filter calls another proc below:
if {[getAgeDays $birthdate $admitdate] > 6935} {
lappend dispList “KILL $mh”
if {$debug} {echo “$module KILL msg ecd $ecd age greater than 19”}
} else {
continue
###############################################
# Name: getAgeDays
# Purpose: Get number of days old at time of admission
# UPoC type: upoc
# Args: none
#
proc getAgeDays {dob admitdate} {
set admitdays [expr [clock scan [string range $admitdate 0 7]] / 60 / 60 / 24]
set dobdays [expr [clock scan $dob] / 60 / 60 / 24]
set ageDays [expr $admitdays – $dobdays]
return $ageDays
}
Calculate the average number of seconds in a year – taking leap years into account.
Scan DOB
Scan Admit date (or whatever date is of interest)
Subtract DOB seconds from admit seconds, divide by average seconds per year and cast it as an integer.
set avgYearSec [expr 365.25 * 24 * 60 * 60]
set birthDate 20000229
set birthSec [clock scan $birthDate]
set admitDate 20180228
set admitSec [clock scan $admitDate]
set yrsOld [expr int(($admitSec – $birthSec) / $avgYearSec)]
The above calculation produces “17”.
If we roll the admit date forward to 20180301, it produces “18”.
We, of course, need to massage dates from messages into a form that clock scan likes.
Feel free to poke holes in this algorithm. I haven’t calculated age like this before, but it seems like it should work.
Jeff Dinsmore
Chesapeake Regional Healthcare