
			select
				to_char(EPS.EvnPS_setDate, 'DD.MM.YYYY') as "EvnPS_setDate",
				to_char(EPS.EvnPS_disDate, 'DD.MM.YYYY') as "EvnPS_disDate",
				EPS.EvnPS_NumCard as "EvnPS_NumCard",
				case
					when EPS.Lpu_id = '13100979' then 'inner'
					when EPS.Lpu_id <> '13100979' then 'outer'
				end as "intersect_type",
				LSP.LpuSectionProfile_Name as "LpuSectionProfile_Name",
				RTRIM(COALESCE(Lpu.Lpu_Nick, '')) as "Lpu_Nick"
			from
				v_EvnPS EPS 
				inner join v_Lpu Lpu on Lpu.Lpu_id = EPS.Lpu_id
				left join v_EvnSection ES on ES.EvnSection_rid = EPS.EvnPS_id
				left join v_LpuSectionProfile LSP on ES.LpuSectionProfile_id = LSP.LpuSectionProfile_id
				
			where
				EPS.EvnPS_id <> COALESCE(NULL::bigint, 0) and EPS.Person_id = '5571921' and EPS.PrehospWaifRefuseCause_id is null and COALESCE(ES.EvnSection_IsPriem, 1) = 1 and 
				(
					(
						EPS.EvnPS_setDT <= CAST('2022-01-22 03:25' as timestamp) -- дата начала до текущего
						and (
							EPS.EvnPS_disDT is null -- и дата конца не задана
							or EPS.EvnPS_disDT > CAST('2022-01-22 03:25' as timestamp) -- либо дата конца после начала текущего
						)
					)
					or
					(
						EPS.EvnPS_setDT >= CAST('2022-01-22 03:25' as timestamp) -- дата начала до
						and (
							'2022-01-22 03:27:00' is null -- и дата конца не задана
							or CAST('2022-01-22 03:27:00' as timestamp) > EPS.EvnPS_setDT -- либо дата конца после начала
						)
					)
				)
			
		
