Written by

Senior Integration Engineer at Cambridge University Hospitals NHS Foundation Trust
Question Saju Abraham · May 9

Age Calculator in BPL

Hello All,

No matter what I try in Business Process Logic (BPL), I am unable to calculate the patient's age in days or years.

Has anyone ever built logic in a Business Process (BPL) to calculate a person's age in days?

Thank you!

Product version: IRIS 2023.1

Comments

Enrico Parisi · May 9

If you tell us what format you use for date of birth, then we can give you the code you may use

0
Saju Abraham  May 9 to Enrico Parisi

Hello Enrico, The input comes out in YYYYMMDD format and is from a Standard HL7 PID07 field. Ex: 19830121.

In order to determine whether the patient is over 16, the logic is meant to output the patient's age in either days or years. If the condition is met, the next set of logic is supposed to be executed.

Many thanks

0
Enrico Parisi  May 9 to Saju Abraham

I'd implement a custom function, create a class like:

Class Community.CustomFunctions Extends Ens.Rule.FunctionSet
{

/// Returns Age in years from DOB in YYYYMMDD formatClassMethod GetAge(DateOfBirth As%String) As%Integer
{
    Quit (($H-$ZDATETIMEH(DateOfBirth,8)) \ 365.25)
}
/// Returns Age in days from DOB in YYYYMMDD formatClassMethod GetAgeDays(DateOfBirth As%String) As%Integer
{
	Quit ($H-$ZDATETIMEH(DateOfBirth,8))
}

}

Then from any Rule or DTL transformation you can use these two function as any other built in function.

Make sure DOB is not null ("") before calling the function.

0
Mike.W · Jun 11

(It's probably obvious, but if you want an accurate value on or around the actual birthday, then it's a lot more complex than dividing by 365.25. You have to go down to splitting and comparing months and days, especially in a leap year.)

0
Enrico Parisi  Jun 11 to Mike.W

Fixed for you:

/// Returns Age in years from DOB in YYYYMMDD format/// Make sure DOB is not null ("") before calling the function.ClassMethod GetAge(DateOfBirth As%String) As%Integer
{
    Set today=$zd($h,8)	
    Set age=$e(today,1,4)-$e(DateOfBirth,1,4)
    If$e(today,5,8) < $e(DateOfBirth,5,8) Set age=age-1Quit age
}

Not that complex after all.

0