(
                select
                    mouc.MesOldUslugaComplex_id as "MesOldUslugaComplex_id"
                from
                    v_MesOldUslugaComplex mouc
                    inner join v_MesOld mo on mo.Mes_id = mouc.Mes_id
                where
                    mouc.Diag_id = '2347'
                    and mouc.MesOldUslugaComplex_SofaScalePoints is not null
                    and mouc.MesOldUslugaComplex_begDT <= '2022-02-19'
                    and (coalesce(mouc.MesOldUslugaComplex_endDT, '2022-02-19') >= '2022-02-19')
                    and mo.MesType_id IN (10,14)
                limit 1
            ) union (
                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 = '890101018723570'
                    and edps.DiagSetClass_id = 2
                    and mouc.MesOldUslugaComplex_SofaScalePoints is not null
                    and mouc.MesOldUslugaComplex_begDT <= '2022-02-19'
                    and (coalesce(mouc.MesOldUslugaComplex_endDT, '2022-02-19') >= '2022-02-19')
                    and mo.MesType_id IN (10,14)
                limit 1
            )
