(
                select
                    mouc.MesOldUslugaComplex_id as "MesOldUslugaComplex_id"
                from
                    v_EvnDiagPS edps
                    inner join v_MesOldUslugaComplex mouc on mouc.Diag_oid = edps.Diag_id
                    inner join v_MesOld mo on mo.Mes_id = mouc.Mes_id
                where
                    edps.EvnDiagPS_pid = '890101022179873'
                    and edps.DiagSetClass_id = 2
                    and mouc.MesOldUslugaComplex_SofaScalePoints is not null
                    and mouc.MesOldUslugaComplex_begDT <= '2022-03-18'
                    and (coalesce(mouc.MesOldUslugaComplex_endDT, '2022-03-18') >= '2022-03-18')
                    and mo.MesType_id IN (10,14)
                limit 1
            )
