How to create scalar function of SQL Server in order to calculate GNRI?

Pocket

Malnutrition in elder people increases the risk of death. Geriatric Nutrition Risk Index (GNRI) is the tool to detect malnutrition easily in hemodialysis patients, too. The definition is as following;

\displaystyle \mathrm{GNRI} = 14.89\times\mathrm{Albumin (g/dL)} + 41.7\times\frac{\mathrm{Body Weight}}{\mathrm{Ideal Body Weight}}

where ideal body weight is given by multiplying 22 the square of height. But body weight should be replaced with ideal body weight if body weight is greater than ideal body weight. Then the second term is equal to 1.

Table is defined as following procedure. It is based on the survey list of the Japanese Society for Dialysis Therapy in 2013.

CREATE TABLE dbo.T_JSDT(
	ID nchar(8) NOT NULL,
	DATE_Survey date NOT NULL,
	Diabetes nchar(1) NOT NULL,
	Myocardial_Infarction nchar(1) NOT NULL,
	Cerebral_Hemorrhage nchar(1) NOT NULL,
	Cerebral_Infarction nchar(1) NOT NULL,
	Amputation nchar(1) NOT NULL,
	Femoral_Fracture nchar(1) NOT NULL,
	EPS nchar(1) NOT NULL,
	Hypertensive_Agents nchar(1) NOT NULL,
	Smoke nchar(1) NOT NULL,
	Therapy_Mode nchar(10) NOT NULL,
	Combination_PD nchar(1) NOT NULL,
	History_PD nchar(1) NOT NULL,
	Transplantation_COUNT nchar(1) NOT NULL,
	DIalysis_COUNT int NULL,
	Dialysis_Duration int NULL,
	QB int NULL,
	Height decimal(4, 1) NOT NULL,
	preWeight decimal(4, 1) NOT NULL,
	postWeight decimal(4, 1) NULL,
	preBUN decimal(4, 1) NOT NULL,
	postBUN decimal(4, 1) NULL,
	preCre decimal(5, 2) NOT NULL,
	postCre decimal(5, 2) NULL,
	Albumin decimal(3, 1) NOT NULL,
	CRP decimal(4, 2) NOT NULL,
	Ca decimal(3, 1) NOT NULL,
	IP decimal(3, 1) NOT NULL,
	Hemoglobin decimal(3, 1) NOT NULL,
	TIBC decimal(3, 0) NULL,
	Fe decimal(3, 0) NULL,
	Ferritin decimal(5, 1) NULL,
	TCHO decimal(3, 0) NOT NULL,
	HDLC decimal(3, 0) NOT NULL,
	PTH_mode nchar(1) NOT NULL,
	PTH decimal(4, 0) NULL,
	HbA1c decimal(3, 1) NULL,
	GA decimal(3, 1) NULL,
	SBP decimal(3, 0) NOT NULL,
	DBP decimal(3, 0) NOT NULL,
	HR decimal(3, 0) NOT NULL,
	KtV_JSDT decimal(3, 2) NULL,
	nPCR_JSDT decimal(3, 2) NULL,
	[%CRE] decimal(4, 1) NULL,
 CONSTRAINT PK_T_JSDT PRIMARY KEY (ID, DATE_Survey)

We need height, body weight and albumin in the table. Execute following procedure to create function.

CREATE FUNCTION Function_GNRI 
(@Albumin dec(3, 1), @Height dec(4, 1), @Weight dec(4, 1))
RETURNS DEC(5, 2)
AS
BEGIN
	DECLARE @GNRI DEC(5,2)
	SELECT @GNRI = 14.89 * @Albumin + 41.7 * CASE WHEN @Weight > ( 22 * POWER(@Height/100, 2)) THEN ( 22 * POWER(@Height/100, 2)) ELSE @Weight END / ( 22 * POWER(@Height/100, 2))
	RETURN @GNRI
END

Execute following query to calculate GNRI.

WITH	CTE	AS
(SELECT	J.ID		AS ID
	,	J.DATE_Survey	AS DATE_Survey
	,	J.Albumin	AS ALB
	,	J.Height	AS Height
	,	CASE WHEN J.postWeight IS NULL THEN J.preWeight ELSE J.postWeight END	AS Weight
   FROM	dbo.T_JSDT AS J
),	CTE_GNRI AS
(SELECT	CTE.ID		AS ID
	,	CTE.DATE_Survey	AS DATE_Survey
	,	dbo.Function_GNRI(CTE.ALB, CTE.Height, CTE.Weight)	AS GNRI
FROM	CTE)
SELECT	*	FROM	CTE_GNRI;

Reference: Simplified nutritional screening tools for patients on maintenance hemodialysis

Pocket

投稿者: admin

趣味:写真撮影とデータベース. カメラ:TOYO FIELD, Hasselblad 500C/M, Leica M6. SQL Server 2008 R2, MySQL, Microsoft Access.

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です