IS there any way we can calculate the age based on the DOB

Clovertech Forums Read Only Archives Cloverleaf Tcl Library IS there any way we can calculate the age based on the DOB

  • Creator
    Topic
  • #51924
    Ganesan Murali
    Participant

      Hi IS there any way we can calculate the age ( based on the system date – DOB ) PID-7 value and put it PID-10 ?

      Thanks in advance.

    Viewing 7 reply threads
    • Author
      Replies
      • #72321

        Check out the tcl clock command.

        -- Max Drown (Infor)

      • #72322
        Ganesan Murali
        Participant

          Pls enlighten me how too use the clock command and get the age based on PID-7 in a HL7 message?

        • #72323
          Keith McLeod
          Participant

            set dob 19550405073000

            regsub — {(d{8})(d*)} $dob {1 2} dob

            set age_seconds [expr [clock scan now]-[clock scan $dob]]

            set age_years [expr $age_seconds/86400/366]

            echo $age_years

            If you want to take this to a more exact, you may need to adjust your calculation of the variable age_seconds.  The clock scan command returns the number of seconds from I beleive sometime in 1969.  Not sure I have to check each time.

          • #72324
            Keith McLeod
            Participant

              If you are just checking for greater or less than an age you can do something like:

              set dob 19550405073000

              regsub — {(d{8})(d*)} $dob {1 2} dob

              if {[clock scan $dob] > [clock scan “30 years ago”]} {

              # do something amazing here, the person is under 30 years of age

              } else {

              # They are 30 or over

              }

            • #72325
              Chris Williams
              Participant

                This will work for most patients. Depending on your enviornment, the clock function may not process dates prior to Jan 1, 1902.

              • #72326
                David Barr
                Participant

                  Keith McLeod wrote:

                  set dob 19550405073000

                  regsub — {(d{8})(d*)} $dob {1 2} dob

                  set age_seconds [expr [clock scan now]-[clock scan $dob]]

                  set age_years [expr $age_seconds/86400/366]

                  echo $age_years

                  I think that patients over 68 years old will have lived more than 2^31 seconds and overflow a signed integer. On TCL 8.5 this wouldn’t be a problem, but Cloverleaf is still on TCL 8.4 and age_seconds will be a negative number. I had to do something like this:

                  Code:

                  return [expr ([clock seconds]/(24*60*60)-[clock scan $dob]/(24*60*60))/365.25]

                • #72327
                  Joe Grathoff
                  Participant

                    Adapted this to an Xlate TCL Fragment to calculate whole years of age.  Thanks for Posts.

                    regsub — {(d{8})(d*)} $xlateInVals {1 2} dob

                    set age_years [expr ([clock seconds]/(24*60*60)-[clock scan $dob]/(24*60*60))/365.25]

                    set xlateOutVals [expr {int($age_years)}]

                    echo Patient age is $xlateOutVals years.

                  • #72328
                    Russ Ross
                    Participant

                      If you dont have cloverleaf 6+ and TCL 8.5, there is another approach by Brandon Grudt at this URL to get around the 1902 clock scan problem:

                      <a href="https://usspvlclovertch2.infor.com/viewtopic.php?t=6815&#8243; class=”bbcode_url”>https://usspvlclovertch2.infor.com/viewtopic.php?t=6815

                      Russ Ross
                      RussRoss318@gmail.com

                  Viewing 7 reply threads
                  • The forum ‘Tcl Library’ is closed to new topics and replies.