Homepage › Clovertech Forums › Read Only Archives › Cloverleaf › Product Enhancements › Xlate Date Calculation
- This topic has 8 replies, 6 voices, and was last updated 6 years, 6 months ago by
Jeff Dinsmore.
-
CreatorTopic
-
February 19, 2018 at 2:59 pm #55624
Lina Patel
ParticipantI have a request to update VXU (OBX field) for adult immunizations. 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!
-
CreatorTopic
-
AuthorReplies
-
-
February 19, 2018 at 6:29 pm #85945
Steve Williams
ParticipantLina, 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.
-
February 19, 2018 at 6:34 pm #85946
Lina Patel
ParticipantI need to calculate age 18 as adult and younger as children’s for vaccines using PID-7. Is there any existing logic that would be useful to calculate age?
Thank you for your response.
-
February 19, 2018 at 6:50 pm #85947
Steve Williams
ParticipantSorry, I don’t have a script for this task. 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…
-
February 19, 2018 at 6:53 pm #85948
Steve Williams
ParticipantJohn Bass posted some code in this article that might be what you can use. -
February 19, 2018 at 8:15 pm #85949
Paul Bishop
ParticipantWe’ve done something similar for some of our interfaces where they didn’t want a patient younger than X number of years. What I did was take the date of birth from PID-7, pull out only the date portion (in case your source system sends the time portion), and compare it with a calculated value of the current date – X years, formatted the same way. I would then set a flag as the output and use flag in the Xlate (if @underage_flag eq =Y, do something for young patients, else do something else). This code was put in the pre proc of the copy. Code: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 -
February 19, 2018 at 8:59 pm #85950
Jim Kosloskey
ParticipantI have a proc we used which allows you to add (or subtract) a time period from a date/time. 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.
-
February 19, 2018 at 9:42 pm #85951
Brenda Carpenter
ParticipantHi Lina, 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
}
-
February 20, 2018 at 10:47 pm #85952
Jeff Dinsmore
ParticipantFor age in years, can’t you do something like this? 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.
Code: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
-
-
AuthorReplies
- The forum ‘Product Enhancements’ is closed to new topics and replies.