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

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


--if (not exists (select * from [AKUZ].T_OBSTETRICS_PRINT_DOCUMENTS osd where osd.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('OBSTETRICS_PRINT_DOCUMENTS')	
--		)
--end

--select @ContentEncoding = 'utf-8'
--	   ,@Type = 'OBSTETRICS_PRINT_DOCUMENTS'
--	   ,@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'		
--		,@OperationType			as 'header/TYPE'	
--		,osd.DeliveryAndPostpartumPeriod	as 'header/ID_PASSPORT'
--		,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'
--		,f.Name					as 'body/FILE_NAME'
--		,@Content				as 'body/CONTENT' 
--		,osd.TemplateType as 'body/TEMPLATE_TYPE'
--		from [AKUZ].T_OBSTETRICS_PRINT_DOCUMENTS osd
--		join [AKUZ].T_MEDICAL_RECORDS_PRINT mrp on mrp.FileID = osd.FileID 
--		join [AKUZ].T_POST p on p.ResourceID = mrp.Post
--		join [AKUZ].T_WORKER w on w.WorkerID = p.Worker
--		join [VCLib].T_FILE f on f.FileID = mrp.FileID
--		join [AKUZ].T_DELIVERY_AND_POSTPARTUM_PERIOD dpp on dpp.MedicalRecordId = osd.DeliveryAndPostpartumPeriod
--		where mrp.FileID = @ID
--		FOR XML PATH(''),
--		ROOT('OBSTETRICS_PRINT_DOCUMENTS')
--	) 
--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