age in years – clock scan

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf age in years – clock scan

  • Creator
    Topic
  • #53990

    Can clock scan handle year ‘1900’? I’m have a tcl proc called age_in_yrs which takes DOB(YYYYMMDD) and returns age in years.

    The tcl appers to be working all times expect when getting a “19000101” as DOB.

    Below is the age_in_yrs tcl code:

    set dob [lindex $xlateInVals 0]

    set date1 [clock scan $dob]

    set date2 [clock seconds]

    set elapsedDays [expr {($date2 – $date1) / (60 * 60 * 24)}]

    set elapsedYears [expr {$elapsedDays / 365.25}]

    set xlateOutVals $elapsedYears

Viewing 3 reply threads
  • Author
    Replies
    • #79785
      Brandon Grudt
      Participant

        Do you need the decimal, or just the legal age?  If legal age, simply split MMDD and compare whether or not the current or admit date is greater.  Since my birthday is 1012 and today is 0108, I have yet to have my birthday.  Which would mean you should subtract 1 from the current year minus the DOB year.  Something like:

        set bday [grab the last 4 digits of DOB]

        set today [last 4 digits of current day]

        set age [CURyear – DOByear]

        if { $bday > $today } {

          incr age -1

          }

      • #79786

        Thanks for reply Brandon. I had to add some logic to move around some value within HL7 message for patients less than 8 yrs old. Hence the age_in_years tcl to determine the age from DOB. I don’t need the decimal. I have rounding logic which rounds the returned value(age with decimal).

        Looks like clock scan range is 1902 to 2037. I’ve been searching on the web about clock scan and came across following.  

        I tested it and the information seems to be accurate. I changed the DOB from 1900 to 1902 and it works – no tcl call out error. I get tcl call out error if the 1901 or 1900 or lower.

        “clock scan “dateString” ?-base clockVal? ?-gmt boolean? Convert dateString to an integer clock value. If only a time is specified, current date is assumed. Without time, midnight is assumed. Without time zone uses local zone unless -gmt is specified. If -base is used, the date in clockVal is used for determining the time on a specific day or other date-relative conversions (like daylight savings time for day or greater units). Allowed range of years is 1902 to 2037. DateString consists of zero or more specifications of the following forms: “

      • #79787
        Brandon Grudt
        Participant

          If you are only trying to get the legal age of the patient, there is no need to go through all that work, unless I am missing something.

          Instead of converting lifespan to seconds, then back to years, all you need to do is compare dates.  That will get you your difference.  Also, I would use a date listed as an admit or discharge date in your message, as I am wary of using the current date in any messages.   Your thread could get held up if someone was born on 1/8 and the message was held up since 1/7, your age would be compromised.

          In plain English, subtract the year of birth (1984 in my case) from the current year (2014).  For me, specifically, that would make 30.

          2014 – 1984 = 30

          Now, compare the MMDD of the DOB and the admit/discharge/current date.  For me that would be 10/12 (my birthday) and we will use today’s date of 01/08.  If the birthday is greater than the current date, then subtract one year from the age.

          1012 > 0108, so we would decrease 30 by 1 to get 29.

          I am 29 years old, but will turn 30 on 10/12.  Does that make sense?  So on October 11th, 1012 is still greater than 1011.  But on my birthday 1012 is not greater than 1012.

        • #79788
          Charlie Bursell
          Participant

            There was a bug in Tcl  8.4 clock command for dates prior to 1901.  It has been resolved in Tcl 8.5 which is avaialble with Cloverleaf 6+

        Viewing 3 reply threads
        • The forum ‘Cloverleaf’ is closed to new topics and replies.