Determines if an appointment is after 5pm for enhanced billing
USE [myvisionexpress]
GO
/****** Object: UserDefinedFunction [dbo].[fn_GetPatientApptIsAfter5PMFlag] Script Date: 7/24/2016 5:34:36 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[fn_GetPatientApptIsAfter5PMFlag]
(
@ContactID int
)
RETURNS varchar(100)
AS
BEGIN
DECLARE @RetVal varchar(50)
IF EXISTS(select top 1 DATEPART(hour, start_time)
from calendar
where CONVERT(varchar(10), GETDATE(), 101) = CONVERT(varchar(10), calendar_date, 101)
and DATEPART(hour, start_time) between 16 and 24
and (subjectid = '300' or subjectid = '308' or subjectid = '652' or subjectid = '653' or subjectid = '10177')
and patientid = @ContactID
order by start_time desc)
BEGIN
SET @RetVal = 'X'
END
ELSE
BEGIN
SET @RetVal = ''
END
RETURN @RetVal
END
GO