
            with cte as (
                select
                    case when EvnDirection_IsSigned = 2 then 1 else EvnDirection_IsSigned end as EvnDirection_IsSigned,
                    pmUser_signID,
                    EvnDirection_signDT
                from
                    v_EvnDirection_all
                where
                    EvnDirection_id = NULL
                limit 1
            )

            SELECT
                EvnDirection_id as "EvnDirection_id",
                NULL as "EvnDirection_TalonCode",
                error_code as "Error_Code",
                error_message as "Error_Msg"
            FROM dbo.p_EvnDirection_ins(
                ConsultingForm_id := NULL,
                EvnDirection_id := NULL,
                EvnDirection_pid := NULL,
                Server_id := 140101000000017,
                PersonEvn_id := '140101011663116',
                EvnDirection_setDT := '2022-02-07',
                DirType_id := '16',
                MedicalCareFormType_id := NULL,
                StudyTarget_id := NULL,
                PayType_id := NULL,
                Diag_id := NULL,
                EvnDirection_Num := '75527',
                EvnDirection_Descr := NULL,
                Lpu_did := '140101000000017', --куда направлен
                LpuSection_did := '140101000003093',
                LpuSectionProfile_id := '140101000000016',
                Lpu_id := '140101000000017', -- кто направил
                LpuSection_id := NULL,
                LpuUnit_did := '140101000001887',
                MedPersonal_id := '140101000001987',
                MedStaffFact_id := NULL,
                MedPersonal_zid := NULL,
                MedPersonal_Code := NULL,
                MedService_id := NULL,
                EvnDirection_desDT := NULL,
                EvnDirection_IsAuto := '2',
                EvnDirection_IsCito := '1',
                EvnStatus_id := NULL,
                Post_id := NULL,
                Lpu_sid := '140101000000017',
                Org_sid := '140101000029937',
                Org_oid := NULL,
                PrehospDirect_id := NULL,
                TimetableGraf_id := '140101003600605',
                TimetableStac_id := NULL,
                TimetableResource_id := NULL,
                TimetableMedService_id := NULL,
                EvnDirection_IsNeedOper := 1,
                EvnQueue_id := NULL,
                ARMType_id := '647',
                EvnDirection_IsReceive := '1',
                Resource_id := NULL,
                MedPersonal_did := '140101000009519',
                RemoteConsultCause_id := NULL,
                MedSpec_fid := NULL,
                UslugaComplex_did := NULL,
                FSIDI_id := NULL,
                LpuUnitType_id := NULL,
                EvnDirection_TalonCode := NULL,
                RecMethodType_id := '16',
                ConsultationForm_id := NULL,
                EvnDirection_IsAgreement := NULL,
                RequestConsult_id := NULL,
                 LpuSectionBedProfile_id := NULL,  EvnDirection_IsBiopsy := NULL, 
                pmUser_id := '366566343305'
            )
        
