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!
Comments
If you tell us what format you use for date of birth, then we can give you the code you may use
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
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.
That worked. Thank you, @Enrico Parisi
💡 This question is considered a Key Question. More details here.
(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.)
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.