Tracker id: 2707687 Age off by 1 year in Cal

tmccormi wrote on Monday, March 23, 2009:

From my own internal bug tracker … A customer of mine posted this:
Bug #92 - The patient age is off by one year on Calendar Display

   The patient age is off by one year. (Age shows when you roll over  the name in the calendar program.) Patients have one year added to their age.

Anyone know it this was fixed in 3.0+ ?

Tony

whimmel wrote on Tuesday, March 24, 2009:

It’s not fixed in 3.0 but I fixed it a while ago for our practices.  Make the following change to interface/main/calendar/modules/PostCalendar/pnuserapi.php around line 1146:

change:

    $events[$i][‘patient_age’] = date(“Y”) - substr(($tmp[‘patient_dob’]),0,4);
   
to:

   $dob = explode("-", $tmp[‘patient_dob’]);
    $events[$i][‘patient_age’] = floor((unixtojd(time()) - gregoriantojd($dob[1], $dob[2], $dob[0]))/365.242199);

The old way cheated with the patient’s birth year, so it’s a year off if the birthday hasn’t occurred yet.

tmccormi wrote on Tuesday, March 24, 2009:

Thanks,
  Any reason this can’t get checked into source code control at least?
–Tony “SCM” guy …

tmccormi wrote on Tuesday, March 24, 2009:

This from tracker … yea! tracker works :slight_smile:

Comment By: bradymiller (bradymiller)
Date: 2009-03-24 00:36

Message:
A fix has been posted. Will commit it after the 3.0.1 release.

bradymiller wrote on Tuesday, March 24, 2009:

Was playing around with tracker system last night.  I think Rod needs to assign tracker privileges to use this so we can assign to ourselves and change status etc.
-brady

tmccormi wrote on Tuesday, March 24, 2009:

I would certainly support that!
–Tony

sunsetsystems wrote on Tuesday, March 24, 2009:

OK I assigned tracker access to Brady and Mark and Jason.  Let’s see what that does.

Rod
www.sunsetsystems.com

markleeds wrote on Tuesday, March 24, 2009:

Bill,

I copied that original code for use in a form to calculate age and I noticed it was wrong while testing.  I changed it to this:

function patient_age($birthday, $date) { //calculate age from birthdate and a given later date
    list($birth_year,$birth_month,$birth_day) = explode("-",$birthday);
    list($date_year,$date_month,$date_day) = explode("-",$date);
    $year_diff  = $date_year - $birth_year;
    $month_diff = $date_month - $birth_month;
    $day_diff   = $date_day - $birth_day;
    if ($month_diff < 0) $year_diff–;
    elseif (($month_diff==0) && ($day_diff < 0)) $year_diff–;
    return $year_diff;
}

Is this wrong?  I just followed the thought process of how I figure out someone’s age in my head, given their birthdate and the current date.  Pediatricians will need something that can give an age in months as well.

Mark

cfapress wrote on Wednesday, March 25, 2009:

Hi,

There is already a function that determines a patient’s age in <oemr>/library/patient.inc and it’s called, aptly enough, getPatientAge.

It takes a DOB in the format YYYYMMDD and returns a string. The string comes back in two different formats:
"## month" - if the patient is less than two years old
"##" - if the patient is older than two years

The PostNuke API file could include the patient.inc file or the code could be copied from that file and pasted into the pnuserapi.php file. Both solutions are good but I think the preferred method is to include the library file. That way we only have one function to repair, if needed, in the future.

Jason

rayaz wrote on Tuesday, March 31, 2009:

Hi,

Did we get the age fix in 3.0.1?

Rayaz

bradymiller wrote on Tuesday, March 31, 2009:

hey,

nope.

I vote for Jason’s plan, though.

-brady

cfapress wrote on Friday, May 08, 2009:

A fix has been made and committed to CVS. The date-math has been changed in library/patient.inc to reflect the recommentation by Mark Leeds. Also, the calendar code pnuserapi.php has been changed so the patient’s age is calculated using the corrected library function.

Please, somebody take a look and confirm my code corrections.

Jason

tmccormi wrote on Friday, May 08, 2009:

Jason I posted your update notes in Tracker on Bug: 2707687

Let’s try and keep track of these things a little more formally if we can.  Forums are good for discussion, not so good for figuring out current status.
::slight_smile:

–Tony

tmccormi wrote on Friday, May 08, 2009:

Jason,
  I apologize, looks like you had done that already and I somehow didn’t see the note … mea culpa.

–Tony

cfapress wrote on Friday, May 08, 2009:

No worries. I’m trying to keep all bugs and feature requests funneled through the tracking system too. It makes it *much* easier to tackle a development task.

Jason