Sidebar

How can I calculate the age of a patient based on date of birth?

0 votes
322 views
asked Aug 17, 2017 by michael-h-5027 (14,390 points)

1 Answer

+1 vote

You can create a "Published Function" in QIE.

function calcAge(dobIn) {
   var dob   = new Date(qie.formatDate('MM/dd/yyyy', qie.deduceDate(dobIn)));
   var year  = dob.getFullYear();
   var month = dob.getMonth();
   var day   = dob.getDate();
   var today = new Date();
   var age   = today.getFullYear()-year;
   if(today.getMonth()<month || (today.getMonth()==month && today.getDate()<day)){age--;}
   return age;
}

From a mapping function in QIE you can call this function and pass in a DOB.

var patientAge = calcAge(source.getNode('PID-7'));

answered Aug 17, 2017 by michael-h-5027 (14,390 points)
...