Question
· 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
Discussion (7)2
Log in or sign up to continue

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 format
ClassMethod GetAge(DateOfBirth As %String) As %Integer
{
    Quit (($H-$ZDATETIMEH(DateOfBirth,8)) \ 365.25)
}
/// Returns Age in days from DOB in YYYYMMDD format
ClassMethod 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.

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-1
    Quit age
}

Not that complex after all.