infor.com
concierge
infor u
developer portal
documentation central
customer center
Posts
Categories
Groups
ERPs
CSD
FSM/HRT
LN
M3
Syteline/ CSI
Hubs
Developer
Healthcare
Hospitality
Public Sector
Onboarding
Release Center
CloudSuites
Aerospace & Defense (LN)
Automotive (LN)
Chemicals (M3)
Corporate (FSM/HRT)
Distribution (Sx.e/CSD)
Distribution Enterprise (M3)
Engineering & Construction (LN)
Fashion (M3)
Food & Beverage (M3)
Healthcare (FSM/HRT)
Industrial (Syteline/CSI)
Industrial Enterprise (LN)
Manufacturing (M3)
Public Sector (FSM/HRT)
Solutions
Supply Chain Management (SCM)
Human Capital Management (HCM)
Events
Groups
User Groups
Your Groups
About
Email Community Support
Infor News
Migrated Forums
Home
Clovertech
Clovertech Archive
Cloverleaf
Enhancement request: xlateStrCalcAge should provide more than years
Jim Kosloskey
The Cloverleaf provided STRING Action Function xlateStrCalcAge provides only the number of elapsed years between dates. The proc actually has the Months and Days. It would be helpful if all 3 time frames were provided. Ideally, the results would be placed in the Destination list provided but in a single element separated by a separator (comma perhaps) would work as well.
I added a poll so as a Cloverleaf user and clovertech participant you can vote.
Also if you have any comments or additions to this request please respond with those.
Find more posts tagged with
Clovertech
Comments
System
Originally posted by Levy Lazarre
I agree with this request. Sometimes there is a need to calculate the age of a newborn (for example to filter an ADT or Results feed) and this can only be expressed in days. So there is a legitimate need to calculate the age in days.
Jeff Dinsmore
A bigger concern for me is that xlateStrCalcAge does not seem to account for leap years.
It's dividing days old by 365, so the older the patient's age, the greater the calculation error will be.
For example, if a patient was born 3/15/1950, and it's currently 2023, the patient's age in years will be calculated as 73 as early as 2/25/2023 - 18 days early.
Jim Kosloskey
Good point Jeff. I don't think it covers the situation noted below...
Note it is unknown if this compensates for the anomaly where: If the year can also be evenly divided by 100, it is not a leap year; unless... the year is also evenly divisible by 400.
Perhaps there is a need for a general re-write of this Function.
John Mercogliano
Hi Jim,
I found this code ages ago at
https://wiki.tcl-lang.org/page/clock
for calculating age at least.
It expects the date to be YYYYMMDD
proc calculateAge { strDOB } {
set dtDOB [clock scan $strDOB]
# Date-of-birth (in seconds relative to epoch) in $dob
foreach {Ynow CMPnow} [clock format [clock seconds] -format "%Y 1%m%d"] {}
foreach {Ydob CMPdob} [clock format $dtDOB -format "%Y 1%m%d"] {}
set ageInYears [expr { $Ynow-$Ydob-($CMPnow<$CMPdob) }]
return $ageInYears
}
Jim Kosloskey
I see that takes care of traditional leap years but I am not so sure that accommodates the years century years also divisible by 400 per the leap year rules:
<li class="va-top ov-h">Here are the <b>rules</b> of <b>leap</b> <b>years</b>: A <b>year</b> may be a <b>leap</b> <b>year</b> if it is<b> evenly divisible by 4</b>. <b>Years</b> that are divisible by 100 (century <b>years</b> such as 1900 or 2000) cannot be <b>leap</b> <b>years</b> unless they are also divisible by 400. (For this reason, the <b>years</b> 1700, 1800, and 1900 were not <b>leap</b> <b>years</b>, but the <b>years</b> 1600 and 2000 were.)
John Mercogliano
Actually, it seems to. But maybe only on a 64 bit system. I seem to remember issues on AIX with clock and 8.4 with a couple of patients over 100 way back when but have not seen anything since we moved to redhat.
I ran the following and received correct results so it seems to cover whatever clock can handle.
Assuming current date of 20230310
hcitcl>calculateAge 15230310
500
hcitcl>calculateAge 15230309
500
hcitcl>calculateAge 15230311
499
Jim Kosloskey
Very good - thanks for that.
Now I think the enhancement request needs to be expanded to require the age calculation to be leap year sensitive as well as provide day and months as well as age.
I hope someone at Infor is seeing this.
Charlie Bursell
A simple proc to calculate elapsed days. You could put this in your tclprocs directory and then just source in Xlate or wherever like:
source $::Hcisitedir/tclprocs/numberOfDays
set days [numberOfDays $date
date must be in foramt YYYYMMDD
You could also put in a common package if you have one.
Do not add .tcl suffix if in tclprocs directory, it would wind up in your tcl index file
You also add the code to an existing proc.
proc numberOfDays {date} {
# Expects date in form of YYYYMMDD
# Since date time is assumed to be midnight set now time to same
# Get number of seconds now
set nowSec [clock scan [clock format [clock scan now] -format %y%m%d]]
# Number of seconds in date
set dateSec [clock scan $date]
# Take difference in seconds and divide by number of seconds in day
# and return that value
return [expr ($nowSec - $dateSec) / 86400]
}