Enhancement request: xlateStrCalcAge should provide more than years

Homepage Clovertech Forums Cloverleaf Enhancement request: xlateStrCalcAge should provide more than years

Should xlateStrCalcAge provide elapsed Year, Month, Days

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.

You must be logged in to participate.
  • Yes
  • No
  • Creator
    Topic
  • #120314
    Jim Kosloskey
    Participant

    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.

    email: jim.kosloskey@jim-kosloskey.com 29+ years Cloverleaf, 59 years IT - old fart.

Viewing 4 reply threads
  • Author
    Replies
    • #120318
      Levy Lazarre
      Participant

      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.

    • #120345
      Jeff Dinsmore
      Participant

      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.

      Jeff Dinsmore
      Chesapeake Regional Healthcare

      • #120368
        Jim Kosloskey
        Participant

        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.

        email: jim.kosloskey@jim-kosloskey.com 29+ years Cloverleaf, 59 years IT - old fart.

    • #120374
      John Mercogliano
      Participant

      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
      }

       

      John Mercogliano
      Sentara Healthcare
      Hampton Roads, VA

      • #120375
        Jim Kosloskey
        Participant

        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.)

        email: jim.kosloskey@jim-kosloskey.com 29+ years Cloverleaf, 59 years IT - old fart.

    • #120376
      John Mercogliano
      Participant

      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

       

       

      John Mercogliano
      Sentara Healthcare
      Hampton Roads, VA

      • #120377
        Jim Kosloskey
        Participant

        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.

        email: jim.kosloskey@jim-kosloskey.com 29+ years Cloverleaf, 59 years IT - old fart.

    • #120381
      Charlie Bursell
      Participant

      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]
      }

       

Viewing 4 reply threads
  • You must be logged in to reply to this topic.

Forum Statistics

Registered Users
5,117
Forums
28
Topics
9,292
Replies
34,432
Topic Tags
286
Empty Topic Tags
10