
            with curDT as (select cast(localtimestamp as TIMESTAMP WITH TIME ZONE) as curDate)
            select distinct
                ELR.EvnLabRequest_id as "Evn_id",
                MST.MedServiceType_SysNick as "MedServiceType_SysNick"
            from v_EvnLabRequest ELR
                inner join v_EvnLabSample ELS on ELR.EvnLabRequest_id = ELS.EvnLabRequest_id
                inner join dbo.v_MedService MS on ELR.MedService_id = MS.MedService_id
                inner join dbo.v_MedServiceType MST on MS.MedServiceType_id = MST.MedServiceType_id
            where ELR.EvnLabRequest_IsExecutionPeriodMissed is null
                and ELR.SampleStatusType_id not in (8,9,10)
                and ELR.EvnLabRequest_PlanDT is not null
                and ELR.EvnLabRequest_PlanDT <= (select curDate from curDT)
                and (ELS.EvnLabSample_setDate >= ((select curDate from curDT) - interval '1 day' * 21)::date)
        
