
            select
                ED.MedService_id as "MedService_id",
                COUNT(*) as "cnt",
                MIN(EQ.EvnQueue_updDT + interval '14 days') as "EvnQueue_insDT",
                date_part('day', dbo.tzGetDate() - MIN(EQ.EvnQueue_setDT)) as "EvnQueue_Days"
            from v_EvnDirection_all ED
            inner join v_EvnQueue EQ on EQ.EvnDirection_id = ED.EvnDirection_id
            inner join v_MedService MS on MS.MedService_id = ED.MedService_id
            inner join v_Lpu L on L.Lpu_id = MS.Lpu_id
            left join v_DirType DT on DT.DirType_id = ED.DirType_id
            where
                EQ.EvnQueue_IsArchived is null
                and EQ.EvnQueue_recDT is null
                and EQ.EvnQueue_failDT is null
                and coalesce(ED.EvnStatus_id,16) = 10
                and DT.DirType_Code not in (7,14,16)
                 and ED.Lpu_did = '13101853' and MS.MedService_id = '890101000000302'
            group by ED.MedService_id
        
