---- =============================================
---- Author:		Anatoliy.Pokus
---- Create date: 08.09.2017
---- =============================================
--CREATE OR REPLACE FUNCTION fn_GetCommentDrugRequestList("ID" UUID)
--	RETURNS UUID AS
-- $$
-- Begin
--	RETURN 
--	(
--		Select 
--		(	
--			Select drl.BaseDrugRequestItemID 
--			From akuz.T_BASE_DRUG_REQUEST_ITEM drl
--			Left Join AKUZ.T_REQUEST_CATALOG rc ON rc.BaseDrugRequestItemID = drl.BaseDrugRequestItemID
--			Where drl.RequestCode = dd.RequestCode
--			AND drl.AppListBeginDate <= bdr.BeginPeriod
--			AND drl.AppListEndDate >= bdr.EndPeriod
--			AND (rc.BaseDrugRequestItemID IS NULL OR dr.RequestType = rc.BenefitType)
--			Limit 1
--		)
--		From akuz.T_DRUG_REQUEST_COMMENTS dd
--		Inner Join 
--			akuz.T_DRUG_REQUEST dr 
--			On dd.DrugRequest = dr.DrugRequestID
--		Inner Join 
--			AKUZ.T_BASE_DRUG_REQUEST bdr 
--			ON dd.DrugRequest = bdr.DrugRequestID
--		Where dd.DrugRequestCommentsID = "ID"
--	);
--END $$
--language plpgsql stable;