
            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 := '520101196396222',
                Server_id := 520101000000001,
                PersonEvn_id := '520101054991488',
                EvnDirection_setDT := '2022-02-17',
                DirType_id := '10',
                MedicalCareFormType_id := NULL,
                StudyTarget_id := NULL,
                PayType_id := '520101000000009',
                Diag_id := '7294',
                EvnDirection_Num := '3677',
                EvnDirection_Descr := NULL,
                Lpu_did := '520101000000001', --куда направлен
                LpuSection_did := '520101000000022',
                LpuSectionProfile_id := '520101000000047',
                Lpu_id := '520101000000001', -- кто направил
                LpuSection_id := '520101000000002',
                LpuUnit_did := '520101000000002',
                MedPersonal_id := '520101000000003',
                MedStaffFact_id := '520101000000021',
                MedPersonal_zid := NULL,
                MedPersonal_Code := NULL,
                MedService_id := '520101000004439',
                EvnDirection_desDT := NULL,
                EvnDirection_IsAuto := '2',
                EvnDirection_IsCito := '1',
                EvnStatus_id := NULL,
                Post_id := '73',
                Lpu_sid := '520101000000001',
                Org_sid := NULL,
                Org_oid := NULL,
                PrehospDirect_id := '1',
                TimetableGraf_id := NULL,
                TimetableStac_id := NULL,
                TimetableResource_id := '520101000306958',
                TimetableMedService_id := NULL,
                EvnDirection_IsNeedOper := 1,
                EvnQueue_id := NULL,
                ARMType_id := NULL,
                EvnDirection_IsReceive := NULL,
                Resource_id := '520101000001012',
                MedPersonal_did := NULL,
                RemoteConsultCause_id := NULL,
                MedSpec_fid := NULL,
                UslugaComplex_did := '200706',
                FSIDI_id := NULL,
                LpuUnitType_id := NULL,
                EvnDirection_TalonCode := NULL,
                RecMethodType_id := 10,
                ConsultationForm_id := NULL,
                EvnDirection_IsAgreement := NULL,
                RequestConsult_id := NULL,
                 LpuSectionBedProfile_id := NULL,  EvnDirection_IsBiopsy := NULL, 
                pmUser_id := '366469832244'
            )
        
