IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sp_RDS_NewbornPatientXml]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[sp_RDS_NewbornPatientXml]
GO
--SET ANSI_NULLS ON
--GO
--SET QUOTED_IDENTIFIER ON
--GO
---- =============================================
---- Author:		Vitacore (с)
---- Create date: 2020-04-20
---- Description:	Выгрузка Истории развития новорожденного
---- =============================================
--CREATE PROCEDURE [dbo].[sp_RDS_NewbornPatientXml]
--	@LpuCode varchar(max) = null
--	,@ID uniqueidentifier = null
--	,@QueueName varchar(255) = 'RDSMotherhood'
--AS
--BEGIN

--declare @Result varchar(max)
--		,@ContentEncoding varchar(255)
--		,@Type varchar(255)
--		,@OperationType varchar(255)
--		,@OwnerID uniqueidentifier



--if (exists (select * from [AKUZ].T_INCOMING_NEWBORN_INFORMATION ndh where ndh.IncomingNewbornInformationID = @ID))
--begin
--	select @OperationType = 'Report'
--	select @Result = (
--		select 
--		@LpuCode					as 'header/LPU'
--		,@OperationType				as 'header/TYPE'
--		,@ID						as 'header/EXPORT_ID'	 
--		,ndh.ID						as 'header/ID'	 
--		from [AKUZ].T_INCOMING_NEWBORN_INFORMATION ndh
--		where ndh.IncomingNewbornInformationID = @ID
--		FOR XML PATH(''),
--		ROOT('NEWBORN_DEVELOPMENT_HISTORY')
--	) end

--select @ContentEncoding = 'utf-8'
--	   ,@Type = 'NEWBORN_DEVELOPMENT_HISTORY'
--	   ,@OwnerID = @ID

--SET NOCOUNT ON;
	
--INSERT INTO [AKUZ].[T_RABBIT_SEND_OBJECT]
--		   ([RabbitSendObjectID]
--		   ,[QueueName]
--		   ,[Content]
--		   ,[MessageID]
--		   ,[Headers]
--		   ,[ContentEncoding]
--		   ,[Type]
--		   ,[UserID]
--		   ,[State]
--		   ,[CreateDateTime]
--		   ,[OwnerID])
--select
--		   NewID()--(<RabbitSendObjectID, uniqueidentifier,>
--		   ,@QueueName--,<QueueName, varchar(255),>
--		   ,dbo.ConvertTextToBinaryZip(@Result, '')--,<Content, text,>
--		   ,null--,<MessageID, varchar(255),>
--		   ,null--,<Headers, varchar(255),>
--		   ,@ContentEncoding--,<ContentEncoding, varchar(255),>
--		   ,@Type--,<Type, varchar(255),>
--		   ,null--,<UserID, varchar(255),>
--		   ,0--,<State, int,>)
--		   ,GETDATE()
--		   ,@OwnerID
--END
--GO