IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[SPWEB_DOKTOR]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE SPWEB_DOKTOR
GO

CREATE PROCEDURE [dbo].[SPWEB_DOKTOR]
@doktorno INT
AS
BEGIN


	SELECT DRID as id,
		DRUNVAN AS unvan,
		DRADI AS doktor, 
		MAXRANDEVUGUNSAYI as maxrandevugunsayi,
		WEBMAXRANDEVUGUNSAYI AS webmaxrandevugunsayi,
		ISNULL(ALTYASSINIRI,-1) AS altyassiniri,
		ISNULL(USTYASSINIRI,200) AS ustyassiniri,
		ISNULL(KONTROLLLERIRANDEVUSUZALIR,0) as kontrollerirandevusuzalir,
		SUBEID as subeid,
		WEBRANDEVUVERILIR as webrandevualir,
		ONLINEMUAYENEALIR as onlinemuayeneyapar,
		RANDEVUDAKIKA AS muayenesuresi,
		(SELECT SUBEADI FROM SUBELER WITH(NOLOCK) WHERE SUBEID=TDRKIMLIK.SUBEID) as sube,
		BOLUMID as bolumid,
		(SELECT BOLUMADI FROM TBOLUM WITH(NOLOCK) WHERE TBOLUM.BOLUMID=TDRKIMLIK.BOLUMID) AS bolum
	FROM TDRKIMLIK WITH(NOLOCK)
	WHERE	STATUS = 'A' 
		AND WEBRANDEVUVERILIR = 1
		AND DRID=@doktorno
						
END
GO

IF EXISTS (SELECT [name] FROM [sys].[database_principals] WHERE [type] = N'S' AND [name] = N'mediwebuser')
BEGIN
	BEGIN TRY
		GRANT EXECUTE ON [dbo].[SPWEB_DOKTOR] TO [mediwebuser]
	END TRY
	BEGIN CATCH
	END CATCH
END
GO


