SQL DR - Calculate Current Patient Age | Forum

Topic location: Forum home » Reporting » DR Reporting
Jun 3 '15
2015-06-03 16:31:58
Does anyone have a SQL function or statement they can share to calculate the current patient age from the birthdate?
Thanks,
Doug Hall | Freeman Health System
Sr. IT Coordinator
Ph: 417.347.3733| Fax: 417.347.0146
dahall@freemanhealth.com<mailto:dahall@freemanhealth.com>

______________________________________________________________________
--FHSDisclaimer-- This email originated from Freeman Health System. This email contains confidential information which is intended only for the use of the individual or entity named above. If the reader of this email is not the intended recipient or agent responsible for delivering it to the intended recipient, he/she is hereby notified that you are in possession of confidential and privileged information. If you have received this email in error, please notify the sender immediately. State and federal law prohibits you from making further disclosure of this information without specific written consent of the person to whom it pertains, or as otherwise permitted by law.
Freeman Health System is ranked the top hospital in southwest Missouri and #4 in the state by US News & World Report.
Jun 3 '15
2015-06-03 16:50:58
Hi Doug,
Here is what we are using as a Scalar Function:
CREATE FUNCTION [dbo].[GetAge]
(
@DOB AS DATE,
@EndDate as DATE = getdate -- Default is today's date (see below) but any date can be used here
)
RETURNS TINYINT
AS
BEGIN
DECLARE @Result as TINYINT
-- IF DEFAULT VALUE (marked as 2999-01-01 as it doesn't accept functions) IS USED THEN USE TODAY'S DATE
IF @DOB >= @EndDate -- trap errors
SET @Result = 0
ELSE
BEGIN
-- check if the person had its birthday in the specified year and calculate age
IF (MONTH(@EndDate)*100)+DAY(@EndDate) >= (MONTH(@DOB)*100)+DAY(@DOB)
SET @Result = DATEDIFF(Year,@DOB,@EndDate)
ELSE
SET @Result = DATEDIFF(Year,@DOB,@EndDate)-1
END
RETURN @Result
END

Let me know if you have any questions.
Jamie Paolino
Developer
CharterCARE Health Partners
200 High Service Ave
North Providence, RI 02904
401-456-3096
Jun 3 '15
2015-06-03 16:54:35
Hi Doug,
I've attached a user-defined function you can use to calculate an age based on 2 dates of interest: the date of birth, and the "check date," which can be based on any datetime field in the DR (or current age, using the GETDATE system function.)
Let me know if you have any questions.
Ian Proffer | 781.329.4300 x202 | Acmeware, Inc.<http://www.acmeware.com/>;
Jun 3 '15
2015-06-03 17:38:34
Tom Harlan of my staff did a session at MUSE called "Z meets SQL" and showed SQL equivalents of most of the Z library that is useful in reporting. Some were done with sql code and some were done as procedures.
The link to the powerpoint and the Sql code is here:
http://new.iatric.com/muse-info
The sql code to look at is in MUSE2015-IatricGetAge.sql
The function returns months/days or years/months if age is under 6 years, just like the Z program does.
Joe Cocuzzo
Sr. Vice President
Reporting Services
Iatric Systems, Inc.
Phone/Fax: (978) 805-4115
Email: Joe.Cocuzzo@iatric.com<mailto:Joe.Cocuzzo@iatric.com>
Web: www.iatric.com<http://www.iatric.com>;