
            SELECT
                e.Evn_id AS "Evn_id", 									--Идентификатор(Номер) документа
                COALESCE(e.Evn_insDT, e.Evn_updDT) AS "Evn_insDT",			--Дата создания документа
                e.Lpu_id as "Lpu_id",
                e.Person_id as "Person_id",
                COALESCE(e.Evn_setDT, dbo.tzGetDate()) AS "Evn_setDT", 		--Дата начала консультации
                COALESCE(e.Evn_disDT, dbo.tzGetDate()) AS "Evn_disDT", 		--Дата окончания консультации
                ES.MedStaffFact_id as "MedStaffFact_id",
                ED.Lpu_sid as "Lpu_sid",											--откуда выписали направление
                msfs.MedStaffFact_id as "MedStaffFact_sid",			-- откуда выписали направление должность/персона
                ED.EvnDirection_id as "EvnDirection_id",
                pvp.PersonVitalParam_SistolPress AS "Person_SistolPress", 		--Систолическое давление(верхнее)
                pvp.PersonVitalParam_DiastolPress AS "Person_DiastolPress", 		--Диастолическое давление(нижнее)
                pvp.PersonVitalParam_HeartFrequency AS "Person_HeartFrequency",	--ЧСС (частота сердечных сокращений)
                pvp.PersonVitalParam_BreathFrequency AS "Person_BreathFrequency", --ЧД (частота дыхания)
                TO_CHAR(pvp.PersonVitalParam_insDT, 'YYYYMMDD')  as "Person_insDt",
                dsp.DiagSetPhase_Code AS "DiagSetPhase_Code", 			--Код состояния
                dsp.DiagSetPhase_Name AS "DiagSetPhase_Name", 			--Состояние
                dmkb.Diag_Code AS "Mkb10_Code", 							--Код шифра МКБ-10
                dmkb.Diag_Name AS "Mkb10_Name", 							--Шифр МКБ-10
                dmkb.Diag_FullName AS "Mkb10_FullName", 					--Полный Шифр МКБ-10
                mkbagid.Diag_FullName AS "Patology" 						--Выявленные патологии(сопутствующие диагнозы)*/
            FROM v_EvnXml ex
            INNER JOIN v_Evn e ON ex.Evn_id = e.Evn_id
            LEFT JOIN v_EvnSection ES ON ES.EvnSection_id = e.Evn_id
            LEFT JOIN v_EvnPS EPS ON EPS.EvnPS_id = ES.EvnSection_pid
            LEFT JOIN v_EvnUsluga eupk ON eupk.EvnUsluga_id = e.Evn_id
            LEFT JOIN v_EvnDirection_all ED ON ED.EvnDirection_id = EPS.EvnDirection_id
            LEFT JOIN v_PersonVitalParam pvp ON e.Evn_id = pvp.Evn_id and e.Person_id = pvp.Person_id and pvp.HeightMeasureType_id = 3 /*плановые измерения*/
            LEFT JOIN v_DiagSetPhase dsp ON dsp.DiagSetPhase_id = COALESCE(es.DiagSetPhase_id, eps.DiagSetPhase_pid)
            LEFT JOIN v_Diag dmkb ON dmkb.Diag_id = eupk.Diag_id OR dmkb.Diag_id = es.Diag_id OR dmkb.Diag_id = eps.Diag_id
            LEFT JOIN v_Diag mkbagid ON mkbagid.Diag_id = eps.Diag_aid
            /*тот кто направил*/
            LEFT JOIN v_MedStaffFact msfs on msfs.Lpu_id=ED.Lpu_sid and msfs.LpuSection_id=ED.LpuSection_id and ED.MedPersonal_id=msfs.MedPersonal_id
            WHERE
                EvnXml_id = '890101004395412'
            LIMIT 1
        
