
                select distinct
                    
            EM.EvnMse_id as "EvnMse_id",
            EM.Person_id as "Person_id",
            '890101000002908' as "MedPersonal_id",
            EM.Server_id as "Server_id",
            EM.MedService_id as "MedService_id",
            EM.MedServiceMedPersonal_id as "MedServiceMedPersonal_id",
            coalesce(to_char(EM.EvnMse_ReExamDate, 'yyyy-mm-dd'), '') as "EvnMse_ReExamDate",
            coalesce(to_char(EM.EvnMse_ProfDisabilityEndDate, 'yyyy-mm-dd'), '') as "EvnMse_ProfDisabilityEndDate",
            EM.ProfDisabilityPeriod_id as "ProfDisabilityPeriod_id",
            coalesce(to_char(EM.EvnMse_ProfDisabilityStartDate, 'yyyy-mm-dd'), '') as "EvnMse_ProfDisabilityStartDate",
            coalesce(PN.PersonNotice_count, 0) as "PersonNotice_count",
            PN.PersonNotice_lastDT as "PersonNotice_lastDT",
            MS.MedService_Name as "MedService_Name",
            PA.Person_Fio as "Person_Fio",
            coalesce(to_char(PA.Person_BirthDay, 'dd.mm.yyyy'), '') as "Person_BirthDay"
        
                from
                    v_EvnMse EM
                    inner join (
                        select
                            evpl.person_id
                        from
                            v_EvnVizitPL EVPL
                            inner join v_EvnPL EPL on EVPL.EvnVizitPL_pid = EPL.EvnPL_id
                        where
                            EVPL.Lpu_id = '13101857'
                            and EVPL.MedPersonal_id = '890101000002908'
                            and EPL.EvnPL_IsFinish != 2
                    ) EVPL on EVPL.person_id = EM.Person_id
                    left join lateral (
                        select
                            Person_Fio,
                            Person_BirthDay
                        from
                            v_Person_all PA
                        where
                            PA.Server_id = EM.Server_id
                            and PA.PersonEvn_id = EM.PersonEvn_id
                        limit 1
                    ) PA on true
                    left join lateral (
                        select
                            MedService_Name
                        from
                            v_MedService MS
                        where
                            MS.MedService_id = EM.MedService_id
                        limit 1
                    ) MS on true
                    
            left join lateral (
                select
                    Person_id as "person_id",
                    count(PersonNotice_id) as "personnotice_count",
                    max(PersonNotice_insDT) as "personnotice_lastdt"
                from v_PersonNotice
                where Person_id = EM.Person_id and pmUser_insID = '379519479536'
                group by Person_id
            ) as PN on true
        
            
