IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sp_RDS_PerenatalCardXml]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[sp_RDS_PerenatalCardXml]
GO
--SET ANSI_NULLS ON
--GO
--SET QUOTED_IDENTIFIER ON
--GO
---- =============================================
---- Author:		Vitacore (с)
---- Create date: 2014-08-11
---- Description:	Выгрузка информации об обменных картах
---- =============================================
--CREATE PROCEDURE [dbo].[sp_RDS_PerenatalCardXml]
--	@LpuCode varchar(max) = null
--	,@ID uniqueidentifier = null
--	,@Content image = null
--	,@OperationType varchar(255) = 'Insert'
--	,@QueueName varchar(255) = 'RDSMotherhood'
	
--AS
--BEGIN

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

--if (not exists (select * from [AKUZ].T_PERINATAL_CARD pc where pc.FileID = @ID))
--begin
--select @OperationType = 'Delete'

--select @Result = (select 
--		@LpuCode				as 'header/LPU'
--		,@ID					as 'header/ID'			
--		,@OperationType			as 'header/TYPE'
--		FOR XML PATH(''),
--		ROOT('PERINATAL_CARD')
--		)
--end

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

----select @Content = @Content FOR XML AUTO, BINARY BASE64

--SET NOCOUNT ON;
--if(@OperationType <> 'Delete')
--BEGIN
--	select @Result = (
--		select 
--		@LpuCode				as 'header/LPU'
--		,@ID					as 'header/ID'			
--		,pc.MotherhoodEvent		as 'header/ID_PASSPORT'
--		,@OperationType			as 'header/TYPE'

--		,convert(varchar(20), mrp.IssueDate, 20) as 'body/ISSUE_DATE'
--		,convert(varchar(20), mrp.CreateDate, 20) as 'body/CREATION_DATE'
--		,p.Code + ' ' + w.LastName + ' ' + w.FirstName + ' ' + w.FatherName as 'body/POST'
--		,lp.LpuCode as 'body/CONSULTATION'
--		,f.Name as 'body/FILE_NAME'
--		,@Content as 'body/CONTENT' 
--		from [AKUZ].T_PERINATAL_CARD pc 
--		join [AKUZ].T_MEDICAL_RECORDS_PRINT mrp on mrp.FileID = pc.FileID 
--		join [AKUZ].T_POST p on p.ResourceID = mrp.Post
--		join [AKUZ].T_WORKER w on w.WorkerID = p.Worker
--		left join [AKUZ].T_LPU_MAIN lp on lp.LpuID = pc.LpuMain
--		join [VCLib].T_FILE f on f.FileID = pc.FileID
--		where pc.FileID = @ID
--		FOR XML PATH(''),
--		ROOT('PERINATAL_CARD')
--	) 
--END 
	
--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