with Lpu_W as
(
  select 
  L.Lpu_id
  from dbo.v_Lpu L
  where 
    coalesce(L.Lpu_IsTest, 1) = 1 
)
select
*
from Lpu_W as Lpu 
inner join dbo.v_EvnPS as EPS on Lpu.Lpu_id =EPS.lpu_id
inner join dbo.v_EvnSection as ES on ES.EvnSection_pid = EPS.EvnPS_id
  and ES.EvnSection_Count-1 = ES.EvnSection_index  
  and EPS.PrehospWaifRefuseCause_id is null
inner join dbo.v_lpusection as lpusection on lpusection.lpusection_id =ES.lpusection_id
inner join dbo.v_LpuUnit LU on LU.LpuUnit_id = lpusection.LpuUnit_id
and LU.LpuUnitType_SysNick in ('stac')
inner join dbo.v_PersonState as PS on EPS.Person_id = PS.Person_id
where EPS.EvnPS_disDate::date <= current_date
and EPS.EvnPS_setDate::date >= '2020-01-01'::date 
and PS.person_birthday::date = '1951-09-14'
