IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sp_Regulator]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[sp_Regulator]
GO
--SET ANSI_NULLS ON
--GO
--SET QUOTED_IDENTIFIER ON
--GO

---- =============================================
---- Author:      Vitacore (с)
---- Create date: 2017-01-11
---- Description: Регулировщик вызовов отправки рецептов.
---- @ForRDS - в РДС,   
---- @ForBur - в РИАC Бурятии
---- =============================================
--CREATE PROCEDURE [dbo].[sp_Regulator]
--	@Xml xml = null
--    ,@ID uniqueidentifier = null
--	,@IsNew bit = 1
--    ,@Deleted bit = 0
--    ,@CancelDeleted bit = 0
--    ,@User uniqueidentifier = null
--	,@ForRDS bit = 0  -- да/нет  в РДС
--	,@ForBur bit = 0   -- да/нет  в РИАЦ Бурятии  
--	,@OperationType  varchar(255) = ''  -- Тип операции при повторе
--AS
--BEGIN

--    SET NOCOUNT ON;

--	Declare 
--	 @QueueName varchar(100) = 'rds.registry'

--	IF ( @ForRDS = 1 )
--		BEGIN
--			---- Для RDS ---
--			 Set  @QueueName = 'RDSSync'
--			 exec [dbo].[sp_RDS_Recipe]  @Xml, @ID, @IsNew, @Deleted, @CancelDeleted, @QueueName,  @User
			
--		END

--	IF ( @ForBur = 1 )
--		BEGIN
--			---- Для РИАЦ Буряти ---
--			Set  @QueueName = 'Bur.RIACSync'
			
--			declare @MKBCode varchar(16) = ''
					
--			select	@MKBCode = r.MKBCode
--			from  [AKUZ].T_RECIPE r 
--			where  r.RecipeID = @ID
	
--			IF   SUBSTRING(@MKBCode,1,3) in ('E10','E11','E12','E13', 'E14')  -- Только диабет
--				BEGIN
--					exec [dbo].[sp_BurRecipe]  @ID, @IsNew, @Deleted, @CancelDeleted , @QueueName,  @User ,@OperationType
--				END
--		END
--END
