-- =============================================
-- Author:		Marat Zigangaraev
-- Create date: 2014-03-06
-- Description:	Возвращает справочник EHR_RUS_M00002
-- =============================================
CREATE OR REPLACE FUNCTION fn_GetEhrRusM00002("PatientBenefitsDirectionDrugsID" UUID)
RETURNS UUID AS
 $$
 Begin
	return
	(
		Select e.EhrRusID
		From akuz.T_PATIENT_BENEFITS_DIRECTION_DRUGS d
		inner join
			ehr.T_EHR_RUS_M00002 e 
			on e.CodeEHR = d.CodeLS
		Where d.PatientBenefitsDirectionDrugsID = "PatientBenefitsDirectionDrugsID"
		Limit 1
	);	
END $$
language plpgsql stable;