IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[SPWEB_TETKIKRAPOR]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE SPWEB_TETKIKRAPOR
GO
--  SPWEB_TETKIKRAPOR 254074,339036,0
CREATE PROCEDURE [dbo].[SPWEB_TETKIKRAPOR] @kisino NVARCHAR(30), @tetkikid INT, @tumu BIT
AS
BEGIN
  declare @strtetkikid varchar(20) = convert(varchar,@tetkikid)+' numaralı tetkik detay görüldü'
  DECLARE @HKIMLIKID INT = dbo.FN_BASIT_ID_SIFRE_AC(@kisino)
  EXEC SPWEB_LOGLA 'tetkikdetay',@HKIMLIKID,@strtetkikid,''
  
  SELECT TOP 1 TETKIKTURADI as turadi, ITEMADI as tetkik, HTRAPORU as htraporu,
		 HTSONUC as htsonuc,LTCKIMLIKNO as hastatc,LADISOYADI as adsoyad,LDTARIHI as dtarih,LHYASI as yas,HCINSIYETI as cinsiyet,
		 LBOLUM as bolum,LDOKTOR as doktor,LUYGDRADI as uygdoktor,UYGDRUNVAN as uygunvan,UYGDRUZMANLIKADI as uyguzmanlik,SONUCTARIH as sonuctarih,
		 (SELECT SUBEADI FROM SUBELER WITH(NOLOCK) WHERE SUBELER.SUBEID=VWTETKIK.SUBEID) as sube
	FROM VWTETKIK WITH(NOLOCK) 
	WHERE HKIMLIKID=@HKIMLIKID AND  HTETKIKID=@tetkikid AND WEBGORUNSUN=1
  
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_TETKIKRAPOR] TO [mediwebuser]
	END TRY
	BEGIN CATCH
	END CATCH
END
GO




