public ViewModelHirurgOverview(NavigationController controller) : base(controller)
        {
            IsAnalizeLoadedVisibility = Visibility.Hidden;
            ButtonName = "К Пациенту";//SetCurrentPatientIDRealyThisTime
            MessageBus.Default.Subscribe("SetAccIDForHirurgOverview", SetAccID);
            MessageBus.Default.Subscribe("GetHirurgOverviewForHirurgOverview", SetCurrentPatientID);
            MessageBus.Default.Subscribe("SetCurrentPatientIDRealyThisTime", SetCurrentPatientIDRealyThisTime);
            // MessageBus.Default.Subscribe("GetAnalizeForAnalizeOverview", SetCurrentAnalizeID);
            HasNavigation          = false;
            Controller             = controller;
            ToCurrentObsledCommand = new DelegateCommand(
                () =>
            {
                if (!string.IsNullOrWhiteSpace(FileName))
                {
                    MessageBoxResult dialogResult = MessageBox.Show("Вы сохранили изменения в документе?", "", MessageBoxButton.YesNo);
                    if (dialogResult == MessageBoxResult.Yes)
                    {
                        Controller.NavigateTo <ViewModelAddPhysical>();
                        FileName = "";
                    }
                }
                else
                {
                    Controller.NavigateTo <ViewModelAddPhysical>();
                    FileName = "";
                }
            }
                );
            CurrentSavePanelViewModel = new SclerozPanelViewModel(this);
            OpenAddSaveCommand        = new DelegateCommand(() =>
            {
                if (!string.IsNullOrWhiteSpace(FileName))
                {
                    CurrentSavePanelViewModel.ClearPanel();
                    CurrentSavePanelViewModel.PanelOpened = true;
                }
                else
                {
                    MessageBox.Show("Сначала откройте документ");
                }
            });
            CurrentSelectDoctorPanelViewModel = new SclerozPanelViewModel(this);

            RevertSelectDoctorCommand = new DelegateCommand(() =>
            {
                CurrentSelectDoctorPanelViewModel.PanelOpened = false;
            });
            OpenSelectDoctorCommand = new DelegateCommand(() =>
            {
                CurrentSelectDoctorPanelViewModel.ClearPanel();
                CurrentSelectDoctorPanelViewModel.PanelOpened = true;
            });


            RevertSaveCommand = new DelegateCommand(() =>
            {
                CurrentSavePanelViewModel.PanelOpened = false;
            });

            OpenWordDocument = new DelegateCommand(
                () =>
            {
                int togle = 0;

                FileName      = System.IO.Path.GetTempPath() + "Осмотр_хирурга.docx";
                _fileNameOnly = "Осмотр_хирурга.docx";
                byte[] bte    = CurrentDocument.DocTemplate;

                for (; ;)
                {
                    try
                    {
                        File.WriteAllBytes(FileName, bte);

                        break;
                    }
                    catch
                    {
                        togle        += 1;
                        FileName      = System.IO.Path.GetTempPath() + "Осмотр_хирурга" + togle + ".docx";
                        _fileNameOnly = "Осмотр_хирурга" + togle + ".docx";
                    }
                }
                TextForDoWhat = "Был открыт документ " + _fileNameOnly + ". Для сохранения изменений в документе сохраните данные в Word, закройте документ и нажмите кнопку \"Сохранить изменения\".";

                Process.Start("WINWORD.EXE", FileName);
            }
                );
            MessageBus.Default.Subscribe("GetHirurgOverviewtForHirurgOverviewFILENAME", GetStatementForStatementFILENAME);
            SetNewOverview = new DelegateCommand(
                () =>
            {
                if (Doctors != null && Doctors.Count != 0)
                {
                    if (DoctorSelectedId == -1)
                    {
                        MessageBus.Default.Call("CreateHirurgOverview", "", null);
                    }
                    else
                    {
                        MessageBus.Default.Call("CreateHirurgOverview", Doctors[DoctorSelectedId].ToString(), Doctors[DoctorSelectedId].doc.Id);
                    }
                    TextForDoWhat = "Вы создали новый документ " + _fileNameOnly;
                    CurrentSelectDoctorPanelViewModel.PanelOpened = false;
                }
            }
                );
            SaveWordDocument = new DelegateCommand(
                () =>
            {
                try
                {
                    if (!string.IsNullOrWhiteSpace(FileName))
                    {
                        byte[] bteToBD    = File.ReadAllBytes(FileName);
                        HirurgOverview Hv = new HirurgOverview();
                        //bool tester = true;

                        if (CurrentDocument.Id != 0)
                        {
                            Hv = Data.HirurgOverview.Get(CurrentDocument.Id);
                            CurrentDocument.DocTemplate = bteToBD;
                            Hv.DocTemplate = bteToBD;
                            Hv.DoctorId    = Doctors[DoctorSelectedId].doc.Id;
                            Data.Complete();
                        }
                        else
                        {
                            Hv.DocTemplate = bteToBD;
                            Hv.DoctorId    = Doctors[DoctorSelectedId].doc.Id;
                            CurrentDocument.DocTemplate = bteToBD;
                            Data.HirurgOverview.Add(Hv);

                            Data.Complete();
                            CurrentDocument.Id = Hv.Id;
                            MessageBus.Default.Call("SetIdOfOverview", null, CurrentDocument.Id);
                        }

                        CurrentSavePanelViewModel.PanelOpened = false;
                        TextForDoWhat = "Изменения в " + _fileNameOnly + " были сохранены";
                    }
                }
                catch
                {
                    MessageBox.Show("Закройте документ");
                }
            }
                );
            OpenFile = new DelegateCommand(
                () =>
            {
                OpenFileDialog openFileDialog = new OpenFileDialog();
                openFileDialog.Filter         = "Word Documents (.docx)|*.docx|All Files (*.*)|*.*";
                openFileDialog.ValidateNames  = true;
                openFileDialog.FilterIndex    = 1;
                if (openFileDialog.ShowDialog() == true)
                {
                    _fileNameOnly     = openFileDialog.SafeFileName;
                    FileName          = openFileDialog.FileName;
                    byte[] bteToBD    = File.ReadAllBytes(FileName);
                    HirurgOverview Hv = new HirurgOverview();

                    if (CurrentDocument.Id != 0)
                    {
                        Hv = Data.HirurgOverview.Get(CurrentDocument.Id);

                        Hv.DocTemplate = bteToBD;
                        Hv.DoctorId    = Doctors[DoctorSelectedId].doc.Id;
                        Data.Complete();
                    }
                    else
                    {
                        Hv.DocTemplate = bteToBD;
                        Hv.DoctorId    = Doctors[DoctorSelectedId].doc.Id;
                        Data.HirurgOverview.Add(Hv);

                        Data.Complete();
                        CurrentDocument.Id = Hv.Id;
                        MessageBus.Default.Call("SetIdOfOverview", null, CurrentDocument.Id);
                    }

                    MessageBus.Default.Call("GetHirurgOverviewForHirurgOverview", null, CurrentDocument.Id);
                    TextForDoWhat = "Был загружен документ " + _fileNameOnly;
                }

                //var img = ByteToImage(Analize.ImageByte);
                //int width = Convert.ToInt32(img.Width);
                //int height = Convert.ToInt32(img.Height);
                //Bitmap TestBitmap = new Bitmap(width, height);
                //TestBitmap.Save("TempImage.Bmp");
                //TestBitmap.Dispose();
                //File.WriteAllBytes("TempImage.Bmp", Analize.ImageByte);
                //Process.Start("TempImage.Bmp");
            }
                );

            ToCurrentPatientCommand = new DelegateCommand(
                () =>
            {
                MessageBus.Default.Call("GetCurrentPatientId", this, CurrentPatient.Id);
                Controller.NavigateTo <ViewModelCurrentPatient>();
            }
                );
        }
        public ViewModelCreateStatement(NavigationController controller) : base(controller)
        {
            LeftOrRight = new List <string>();
            LeftOrRight.Add("Правая нижняя конечность");
            LeftOrRight.Add("Левая нижняя конечность");

            MessageBus.Default.Subscribe("GetOperationResultForCreateStatement", GetOperationid);
            HasNavigation    = false;
            SaveWordDocument = new DelegateCommand(
                () =>
            {
                try
                {
                    if (!string.IsNullOrWhiteSpace(FileName))
                    {
                        byte[] bteToBD        = File.ReadAllBytes(FileName);
                        StatementOperation Hv = new StatementOperation();
                        //bool tester = true;

                        if (CurrentDocument.Id != 0)
                        {
                            Hv = Data.StatementOperation.Get(CurrentDocument.Id);
                            CurrentDocument.DocTemplate = bteToBD;
                            Hv.DocTemplate        = bteToBD;
                            Hv.FirstIsRightIfNull = SelectedLeg;
                            Hv.CountDays          = Days;
                            Hv.DoctorId           = Doctors[SelectedDoctor].doc.Id;
                            Data.Complete();
                        }
                        else
                        {
                            Hv.FirstIsRightIfNull       = SelectedLeg;
                            Hv.CountDays                = Days;
                            Hv.DocTemplate              = bteToBD;
                            Hv.DoctorId                 = Doctors[SelectedDoctor].doc.Id;
                            CurrentDocument.DocTemplate = bteToBD;
                            Data.StatementOperation.Add(Hv);

                            Data.Complete();
                            Operation             = Data.Operation.Get(Operation.Id);
                            Operation.StatementId = Hv.Id;
                            //    Operation.StatementId = Hv.Id;
                            CurrentDocument.Id = Hv.Id;
                            Data.Complete();
                            //   MessageBus.Default.Call("SetIdOfOverview", null, CurrentDocument.Id);
                        }

                        TextForDoWhat = "Изменения в " + _fileNameOnly + " были сохранены";
                        CurrentSavePanelViewModel.PanelOpened = false;
                    }
                }
                catch
                {
                    MessageBox.Show("Закройте документ");
                }
            }
                );



            CurrentSelectDoctorPanelViewModel = new SclerozPanelViewModel(this);
            RevertSelectDoctorCommand         = new DelegateCommand(() =>
            {
                CurrentSelectDoctorPanelViewModel.PanelOpened = false;
            });
            OpenSelectDoctorCommand = new DelegateCommand(() =>
            {
                CurrentSelectDoctorPanelViewModel.ClearPanel();
                CurrentSelectDoctorPanelViewModel.PanelOpened = true;
            });
            OpenFile = new DelegateCommand(
                () =>
            {
                OpenFileDialog openFileDialog = new OpenFileDialog();
                openFileDialog.Filter         = "Word Documents (.docx)|*.docx|Word Template (.dotx)|*.dotx|All Files (*.*)|*.*";
                openFileDialog.ValidateNames  = true;
                openFileDialog.FilterIndex    = 1;
                if (openFileDialog.ShowDialog() == true)
                {
                    _fileNameOnly         = openFileDialog.SafeFileName;
                    FileName              = openFileDialog.FileName;
                    byte[] bteToBD        = File.ReadAllBytes(FileName);
                    StatementOperation Hv = new StatementOperation();

                    if (CurrentDocument.Id != 0)
                    {
                        Hv = Data.StatementOperation.Get(CurrentDocument.Id);

                        Hv.DocTemplate        = bteToBD;
                        Hv.DoctorId           = Doctors[SelectedDoctor].doc.Id;
                        Hv.FirstIsRightIfNull = SelectedLeg;
                        Hv.CountDays          = Days;
                        Data.Complete();
                        CurrentDocument.Id = Hv.Id;
                    }
                    else
                    {
                        Hv.DocTemplate        = bteToBD;
                        Hv.DoctorId           = Doctors[SelectedDoctor].doc.Id;
                        Hv.FirstIsRightIfNull = SelectedLeg;
                        Hv.CountDays          = Days;
                        Data.StatementOperation.Add(Hv);

                        Data.Complete();
                        CurrentDocument.Id    = Hv.Id;
                        Operation             = Data.Operation.Get(Operation.Id);
                        Operation.StatementId = Hv.Id;
                        Data.Complete();
                    }
                    GetOperationid(null, Operation.Id);

                    TextForDoWhat = "Был загружен документ " + _fileNameOnly;
                }
            }
                );
            OpenWordDocument = new DelegateCommand(
                () =>
            {
                int togle = 0;

                FileName = System.IO.Path.GetTempPath() + "Выписка_заготовка.docx";

                _fileNameOnly = "Выписка_заготовка.docx";

                byte[] bte = CurrentDocument.DocTemplate;

                for (; ;)
                {
                    try
                    {
                        File.WriteAllBytes(FileName, bte);

                        break;
                    }
                    catch
                    {
                        togle        += 1;
                        FileName      = System.IO.Path.GetTempPath() + "Выписка_заготовка" + togle + ".docx";
                        _fileNameOnly = "Выписка_заготовка" + togle + ".docx";
                    }
                }
                TextForDoWhat = "Был открыт документ " + _fileNameOnly + ". Для сохранения изменений в документе сохраните данные в Word, закройте документ и нажмите кнопку \"Сохранить изменения\".";

                Process.Start("WINWORD.EXE", FileName);
            }
                );


            LostFocus = new DelegateCommand <object>(
                (sender) =>
            {
                if (string.IsNullOrWhiteSpace(((TextBox)sender).Text))
                {
                    ((TextBox)sender).Text = "0";
                    Days = 0;
                }
            }
                ); ClickOnWeight = new DelegateCommand <object>(
                (sender) =>
            {
                if (((TextBox)sender).Text == "0")
                {
                    ((TextBox)sender).Text = "";
                }
            }
                );


            ToCreateStatementCommand = new DelegateCommand(
                () =>
            {
                int togle     = 0;
                _fileNameOnly = "";
                // string fileName = System.IO.Path.GetTeWmpPath() + Guid.NewGuid().ToString() + ".docx";
                _fileNameOnly   = "Выписка_заготовка.docx";
                string fileName = System.IO.Path.GetTempPath() + "Выписка_заготовка.docx";
                byte[] bte      = Data.doc_template.Get(1).DocTemplate;
                //File.WriteAllBytes(fileName, bte);
                for (; ;)
                {
                    try
                    {
                        if (togle == 0)
                        {
                            File.WriteAllBytes(System.IO.Path.GetTempPath() + "Выписка_заготовка.docx", bte);
                            _fileNameOnly = "Выписка_заготовка.docx";
                        }
                        else
                        {
                            File.WriteAllBytes(System.IO.Path.GetTempPath() + "Выписка_заготовка" + togle + ".docx", bte);
                            _fileNameOnly = "Выписка_заготовка" + togle + ".docx";
                        }
                        break;
                    }
                    catch
                    {
                        togle        += 1;
                        fileName      = System.IO.Path.GetTempPath() + "Выписка_заготовка" + togle + ".docx";
                        _fileNameOnly = "Выписка_заготовка" + togle + ".docx";
                    }
                }


                using (DocX document = DocX.Load(fileName))
                {
                    FileName = fileName;
                    document.ReplaceText("«ФИО»", CurrentPatient.Sirname + " " + CurrentPatient.Name + " " + CurrentPatient.Patronimic);
                    string day1  = "0";
                    string day2  = "0";
                    string mnth1 = "0";
                    string mnth2 = "0";
                    string year1 = CurrentPatient.Birthday.Year.ToString();
                    string year2 = CurrentPatient.Birthday.Year.ToString();
                    if (CurrentPatient.Birthday.Day.ToString().ToCharArray().Length == 1)
                    {
                        day1 = "0";
                        day2 = CurrentPatient.Birthday.Day.ToString().ToCharArray()[0].ToString();
                    }
                    else
                    {
                        day1 = CurrentPatient.Birthday.Day.ToString().ToCharArray()[0].ToString();
                        day2 = CurrentPatient.Birthday.Day.ToString().ToCharArray()[1].ToString();
                    }    //«сутки»
                    if (CurrentPatient.Birthday.Month.ToString().ToCharArray().Length == 1)
                    {
                        mnth1 = "0";
                        mnth2 = CurrentPatient.Birthday.Month.ToString().ToCharArray()[0].ToString();
                    }
                    else
                    {
                        mnth1 = CurrentPatient.Birthday.Month.ToString().ToCharArray()[0].ToString();
                        mnth2 = CurrentPatient.Birthday.Month.ToString().ToCharArray()[1].ToString();
                    }
                    try
                    {
                        year1 = CurrentPatient.Birthday.Year.ToString().ToCharArray()[2].ToString();
                        year2 = CurrentPatient.Birthday.Year.ToString().ToCharArray()[3].ToString();
                        document.ReplaceText("Г1", year1);
                        document.ReplaceText("Г2", year2);
                    }
                    catch
                    {
                        document.ReplaceText("Г1", CurrentPatient.Birthday.Year.ToString());
                    }

                    document.ReplaceText("Ч1", day1);
                    document.ReplaceText("Ч2", day2);
                    document.ReplaceText("М1", mnth1);
                    document.ReplaceText("М2", mnth2);

                    document.ReplaceText("область", "область " + Data.Regions.Get(CurrentPatient.Region).Str);
                    if (CurrentPatient.District != null)
                    {
                        document.ReplaceText("район", "район " + Data.Districts.Get(CurrentPatient.District.Value).Str);
                    }
                    else
                    {
                        document.ReplaceText("район,", "");
                    }
                    document.ReplaceText("місто(село)", "місто(село) " + Data.Cities.Get(CurrentPatient.City).Str);
                    document.ReplaceText("вулиця", "вулиця " + Data.Streets.Get(CurrentPatient.Street).Str);
                    document.ReplaceText("будинок", "будинок " + CurrentPatient.House);
                    document.ReplaceText("кв.", "кв. " + CurrentPatient.Flat.ToString());
                    if (CurrentPatient.Work != null)
                    {
                        document.ReplaceText("МестоРаботы", CurrentPatient.Work);
                    }
                    else
                    {
                        document.ReplaceText("МестоРаботы", "-");
                    }


                    string patologis    = "";
                    string diabet       = "";
                    string lettersLeft  = "";
                    string lettersRight = "";
                    string leftDiag     = "", rightDiag = "";

                    List <DiagnosisType> LeftDiagnosisList = new List <DiagnosisType>();

                    foreach (var diag in Data.Diagnosis.GetAll.Where(s => s.isLeft == true && s.id_operation == Operation.Id).ToList())
                    {
                        LeftDiagnosisList.Add(Data.DiagnosisTypes.Get(diag.id_diagnosis.Value));
                    }

                    List <DiagnosisType> RightDiagnosisList = new List <DiagnosisType>();



                    foreach (var diag in Data.Diagnosis.GetAll.Where(s => s.isLeft == false && s.id_operation == Operation.Id).ToList())
                    {
                        RightDiagnosisList.Add(Data.DiagnosisTypes.Get(diag.id_diagnosis.Value));
                    }


                    var PatologysOfCurrPatient = Data.Patology.GetAll.ToList().Where(s => s.id_пациента == CurrentPatient.Id && s.isArchivatied == false).ToList();

                    int zz = 0;
                    foreach (var x in PatologysOfCurrPatient)
                    {
                        //zz++;
                        if (zz != PatologysOfCurrPatient.Count - 1)
                        {
                            patologis += GetStrFixedForDocumemnt(Data.PatologyType.Get(x.id_патологии).Str) + ", ";
                        }
                        else
                        {
                            patologis += GetStrFixedForDocumemnt(Data.PatologyType.Get(x.id_патологии).Str);
                        }
                        zz++;
                    }

                    char[] chararrbuF12 = patologis.ToCharArray();

                    if (chararrbuF12.Length != 0 && chararrbuF12[0] == ' ')
                    {
                        patologis = patologis.Remove(0, 1);
                    }
                    if (chararrbuF12.Length != 0 && chararrbuF12[chararrbuF12.Length - 1] == '.')
                    {
                    }
                    else
                    {
                        patologis += ".";
                    }
                    if (!string.IsNullOrWhiteSpace(patologis) && patologis != ".")
                    {
                        document.ReplaceText("Патологии", "Патологии: " + patologis + "\n");
                    }
                    else
                    {
                        document.ReplaceText("Патологии", "");
                    }
                    //if(patologis == ".")
                    //{
                    //    document.ReplaceText("Патологии", "");
                    //}
                    diabet += CurrentPatient.Sugar;
                    if (!string.IsNullOrWhiteSpace(diabet))
                    {
                        document.ReplaceText("Диабет", "Сахарный диабет: " + diabet + "\n");
                    }
                    else
                    {
                        document.ReplaceText("Диабет", "");
                    }

                    var ExamsOfCurrPatient = Data.Examination.GetAll.ToList().Where(s => s.PatientId == CurrentPatient.Id).ToList();

                    if (ExamsOfCurrPatient.Count > 0)
                    {
                        DateTime MaxExam                   = ExamsOfCurrPatient.Max(s => s.Date);
                        var ExamsOfCurrPatientLatest       = ExamsOfCurrPatient.Where(s => s.Date == MaxExam).ToList();
                        ExaminationLeg leftLegExam         = Data.ExaminationLeg.Get(ExamsOfCurrPatientLatest[0].idLeftLegExamination.Value);
                        ExaminationLeg rightLegExam        = Data.ExaminationLeg.Get(ExamsOfCurrPatientLatest[0].idRightLegExamination.Value);
                        List <ComplainsType> ComplainsList = new List <ComplainsType>();

                        foreach (var diag in Data.ComplanesObs.GetAll.Where(s => s.id_Examination == ExamsOfCurrPatientLatest[0].Id).ToList())
                        {
                            ComplainsList.Add(Data.ComplainsTypes.Get(diag.id_Complains));
                        }
                        string complanes = "";
                        if (ComplainsList != null)
                        {
                            int xxx = 0;
                            foreach (var rec in ComplainsList)
                            {
                                if (xxx == 0)
                                {
                                    complanes += GetStrFixedForDocumemnt(rec.Str);
                                }
                                else
                                {
                                    complanes += ", " + GetStrFixedForDocumemnt(rec.Str);
                                }
                                xxx++;
                            }
                            char[] chararrbuF1 = complanes.ToCharArray();
                            if (chararrbuF1.Length != 0 && chararrbuF1[0] == ' ')
                            {
                                complanes = complanes.Remove(0, 1);
                            }
                            if (chararrbuF1.Length != 0 && chararrbuF1[chararrbuF1.Length - 1] == '.')
                            {
                            }
                            else
                            {
                                complanes += ".";
                            }
                        }
                        document.ReplaceText("«Жалобы»", complanes);



                        //document.ReplaceText("«Жалобы»", complanes);



                        Letters bufLetter = new Letters();
                        if (leftLegExam.C != null)
                        {
                            bufLetter    = Data.Letters.Get(leftLegExam.C.Value);
                            lettersLeft += bufLetter.Leter + bufLetter.Text1 + " ";
                        }
                        if (leftLegExam.A != null)
                        {
                            bufLetter    = Data.Letters.Get(leftLegExam.A.Value);
                            lettersLeft += bufLetter.Leter + bufLetter.Text1 + " ";
                        }
                        if (leftLegExam.E != null)
                        {
                            bufLetter    = Data.Letters.Get(leftLegExam.E.Value);
                            lettersLeft += bufLetter.Leter + bufLetter.Text1 + " ";
                        }
                        if (leftLegExam.P != null)
                        {
                            bufLetter    = Data.Letters.Get(leftLegExam.P.Value);
                            lettersLeft += bufLetter.Leter + bufLetter.Text1 + " ";
                        }

                        if (rightLegExam.C != null)
                        {
                            bufLetter     = Data.Letters.Get(rightLegExam.C.Value);
                            lettersRight += bufLetter.Leter + bufLetter.Text1 + " ";
                        }
                        if (rightLegExam.A != null)
                        {
                            bufLetter     = Data.Letters.Get(rightLegExam.A.Value);
                            lettersRight += bufLetter.Leter + bufLetter.Text1 + " ";
                        }
                        if (rightLegExam.E != null)
                        {
                            bufLetter     = Data.Letters.Get(rightLegExam.E.Value);
                            lettersRight += bufLetter.Leter + bufLetter.Text1 + " ";
                        }
                        if (rightLegExam.P != null)
                        {
                            bufLetter     = Data.Letters.Get(rightLegExam.P.Value);
                            lettersRight += bufLetter.Leter + bufLetter.Text1 + " ";
                        }
                    }
                    else
                    {
                        document.ReplaceText("«Жалобы»", "");
                    }


                    int day12       = Data.OperationDateTime.Get(Operation.Datetime_id.Value).Datetime.Day;
                    int mnth12      = Data.OperationDateTime.Get(Operation.Datetime_id.Value).Datetime.Month;
                    string mnthStr1 = "";
                    string dayStr1  = "";
                    if (mnth12 < 10)
                    {
                        mnthStr1 += "0" + mnth12.ToString();
                    }
                    else
                    {
                        mnthStr1 = mnth12.ToString();
                    }

                    if (day12 < 10)
                    {
                        dayStr1 += "0" + day12.ToString();
                    }
                    else
                    {
                        dayStr1 = day12.ToString();
                    }
                    document.ReplaceText("«Дата»", dayStr1 + "." + mnthStr1 + "." + Data.OperationDateTime.Get(Operation.Datetime_id.Value).Datetime.Year.ToString());
                    int xx = 0;
                    foreach (var x in LeftDiagnosisList)
                    {
                        if (xx == 0)
                        {
                            leftDiag += GetStrFixedForDocumemnt(x.Str);
                        }
                        else
                        {
                            leftDiag += ", " + GetStrFixedForDocumemnt(x.Str);
                        }
                        xx++;
                    }
                    char[] chararrbuF = leftDiag.ToCharArray();
                    if (chararrbuF.Length != 0 && chararrbuF[0] == ' ')
                    {
                        leftDiag = leftDiag.Remove(0, 1);
                    }
                    //if (chararrbuF.Length != 0 && chararrbuF[chararrbuF.Length - 1] == '.')
                    //{ }
                    //else
                    //{
                    //    leftDiag += ".";
                    //}
                    leftDiag += " левой нижней конечности.";

                    xx = 0;
                    foreach (var x in RightDiagnosisList)
                    {
                        if (xx == 0)
                        {
                            rightDiag += GetStrFixedForDocumemnt(x.Str);
                        }
                        else
                        {
                            rightDiag += ", " + GetStrFixedForDocumemnt(x.Str);
                        }
                        xx++;
                    }
                    chararrbuF = rightDiag.ToCharArray();
                    if (chararrbuF.Length != 0 && chararrbuF[0] == ' ')
                    {
                        rightDiag = rightDiag.Remove(0, 1);
                    }
                    //if (chararrbuF.Length != 0 && chararrbuF[chararrbuF.Length - 1] == '.')
                    //{ }
                    //else
                    //{
                    //    rightDiag += ".";
                    //}

                    rightDiag += " правой нижней конечности.";



                    int day        = Data.OperationDateTime.Get(Operation.Datetime_id.Value).Datetime.Day;
                    int mnth       = Data.OperationDateTime.Get(Operation.Datetime_id.Value).Datetime.Month;
                    string mnthStr = "";
                    string dayStr  = "";
                    if (mnth < 10)
                    {
                        mnthStr += "0" + mnth.ToString();
                    }
                    else
                    {
                        mnthStr = mnth.ToString();
                    }

                    if (day < 10)
                    {
                        dayStr += "0" + day.ToString();
                    }
                    else
                    {
                        dayStr = day.ToString();
                    }
                    document.ReplaceText("«Дата_операции»", dayStr + "." + mnthStr + "." + Data.OperationDateTime.Get(Operation.Datetime_id.Value).Datetime.Year.ToString());

                    string leftP = "", rightP = "", operationType = "";
                    int i1       = 0, i2 = 0;

                    foreach (var Diagnosis in Data.OperationTypeOperations.GetAll)
                    {
                        if (Diagnosis.id_operation == Operation.Id)
                        {
                            if (Diagnosis.isLeft == true)
                            {
                                if (i1 != 0)
                                {
                                    leftP += ", " + Data.OperationType.Get(Diagnosis.id_operation_type.Value).Str;
                                }
                                else
                                {
                                    leftP += Data.OperationType.Get(Diagnosis.id_operation_type.Value).Str;
                                }
                                i1++;
                            }
                            else
                            {
                                if (i2 != 0)
                                {
                                    rightP += ", " + Data.OperationType.Get(Diagnosis.id_operation_type.Value).Str;
                                }
                                else
                                {
                                    rightP += Data.OperationType.Get(Diagnosis.id_operation_type.Value).Str;
                                }
                                i2++;
                            }
                        }
                    }

                    //if (Operation.OnWhatLegOp == "0")
                    //{
                    // document.ReplaceText("буквы_2Ж", lettersLeft);
                    //  document.ReplaceText("буквы_1Ж", "");
                    document.ReplaceText("«Заключение_11»", rightDiag + "\n");
                    document.ReplaceText("«Заключение_22»", "Диагноз: " + leftDiag + "\n");
                    //document.ReplaceText("«Заключение_1»", rightDiag + "\n");

                    //document.ReplaceText("«Заключение_2»", "");

                    document.ReplaceText(" буквы_1", lettersRight);
                    document.ReplaceText(" буквы_2", lettersLeft);

                    //}
                    //if (Operation.OnWhatLegOp == "1")
                    //{
                    //  //  document.ReplaceText("буквы_1Ж", lettersRight);
                    ////    document.ReplaceText("буквы_2Ж", "");
                    //    document.ReplaceText("«Заключение_11Ж»", rightDiag + "\n");

                    //    document.ReplaceText("«Заключение_22Ж»", "");
                    //    document.ReplaceText("«Заключение_2»", leftDiag + "\n");
                    //    document.ReplaceText("«Заключение_1»", "");

                    //    document.ReplaceText(" буквы_1", "");

                    //    document.ReplaceText(" буквы_2", lettersLeft);
                    //}
                    //if (Operation.OnWhatLegOp == "2")
                    //{
                    //    document.ReplaceText("«Заключение_11Ж»", rightDiag + "\n");
                    //   // document.ReplaceText("буквы_1Ж", lettersRight);
                    //    document.ReplaceText("«Заключение_22Ж»", leftDiag + "\n");
                    //   // document.ReplaceText("буквы_2Ж", lettersLeft);
                    //    document.ReplaceText("«Заключение_1»", "");
                    //    document.ReplaceText("«Заключение_2»", "");
                    //    document.ReplaceText(" буквы_1", "");
                    //    document.ReplaceText(" буквы_2", "");
                    //}
                    if (SelectedLeg == 0)
                    {
                        if (Operation.OnWhatLegOp == "0")
                        {
                            document.ReplaceText(" «Заключение_11Ж»", "");
                            document.ReplaceText(" «Заключение_22Ж»", leftDiag + "\n");
                            document.ReplaceText("«Заключение_1»", rightDiag + "\n");
                            document.ReplaceText("«Заключение_2»", "");
                        }
                        if (Operation.OnWhatLegOp == "1")
                        {
                            document.ReplaceText(" «Заключение_11Ж»", rightDiag + "\n");

                            document.ReplaceText(" «Заключение_22Ж»", "");
                            document.ReplaceText("«Заключение_2»", "Диагноз: " + leftDiag + "\n");
                            document.ReplaceText("«Заключение_1»", "");
                        }
                        if (Operation.OnWhatLegOp == "2")
                        {
                            document.ReplaceText(" «Заключение_11Ж»", rightDiag + "\n");
                            // document.ReplaceText("буквы_1Ж", lettersRight);
                            document.ReplaceText(" «Заключение_22Ж»", leftDiag + "\n");
                            // document.ReplaceText("буквы_2Ж", lettersLeft);
                            document.ReplaceText("«Заключение_1»", "");
                            document.ReplaceText("«Заключение_2»", "");
                        }
                    }
                    else
                    {
                        if (Operation.OnWhatLegOp == "0")
                        {
                            document.ReplaceText(" «Заключение_11Ж»", leftDiag + "\n");
                            document.ReplaceText(" «Заключение_22Ж»", "");
                            document.ReplaceText("«Заключение_1»", "");
                            document.ReplaceText("«Заключение_2»", "Диагноз: " + rightDiag + "\n");
                        }
                        if (Operation.OnWhatLegOp == "1")
                        {
                            document.ReplaceText(" «Заключение_11Ж»", "");

                            document.ReplaceText(" «Заключение_22Ж»", rightDiag + "\n");
                            document.ReplaceText("«Заключение_2»", "");
                            document.ReplaceText("«Заключение_1»", leftDiag + "\n");
                        }
                        if (Operation.OnWhatLegOp == "2")
                        {
                            document.ReplaceText(" «Заключение_11Ж»", leftDiag + "\n");
                            // document.ReplaceText("буквы_1Ж", lettersRight);
                            document.ReplaceText(" «Заключение_22Ж»", rightDiag + "\n");
                            // document.ReplaceText("буквы_2Ж", lettersLeft);
                            document.ReplaceText("«Заключение_1»", "");
                            document.ReplaceText("«Заключение_2»", "");
                        }
                        //document.ReplaceText("«Заключение_1»", leftDiag);
                        //document.ReplaceText("«Заключение_2»", rightDiag);
                        //document.ReplaceText("буквы_1", lettersLeft);
                        //document.ReplaceText("буквы_2", lettersRight);
                    }

                    if (Operation.OnWhatLegOp == "0")
                    {
                        operationType = "На левую нижнюю конечность :" + leftP;
                        document.ReplaceText("«IsLeft»", "ЛЕВАЯ");
                    }
                    if (Operation.OnWhatLegOp == "1")
                    {
                        operationType = "На правую нижнюю конечность :" + rightP;
                        document.ReplaceText("«IsLeft»", "ПРАВАЯ");
                    }
                    if (Operation.OnWhatLegOp == "2")
                    {
                        operationType = "На левую нижнюю конечность :" + leftP + " " + "На правую нижнюю конечность :" + rightP;
                    }

                    document.ReplaceText("«Операция2»", operationType);
                    //if (!string.IsNullOrWhiteSpace(Data.OperationType.Get(Operation.OperationTypeId).ShortName))
                    //    document.ReplaceText("«Операция2»", Data.OperationType.Get(Operation.OperationTypeId).ShortName);
                    //else
                    //    document.ReplaceText("«Операция2»", Data.OperationType.Get(Operation.OperationTypeId).LongName);

                    day     = DateTime.Now.Day;
                    mnth    = DateTime.Now.Month;
                    mnthStr = "";
                    dayStr  = "";
                    if (mnth < 10)
                    {
                        mnthStr += "0" + mnth.ToString();
                    }
                    else
                    {
                        mnthStr = mnth.ToString();
                    }

                    if (day < 10)
                    {
                        dayStr += "0" + day.ToString();
                    }
                    else
                    {
                        dayStr = day.ToString();
                    }
                    document.ReplaceText("«сутки»", Days.ToString());
                    //document.ReplaceText("сутки", "суток");
                    document.ReplaceText("“сегодняшнеечисломесяц”  ", dayStr + "." + mnthStr);
                    document.ReplaceText("«год»", DateTime.Now.Year.ToString());
                    document.ReplaceText("«Врач»", Doctors[SelectedDoctor].ToString());

                    //область

                    document.Save();
                    byte[] bteToBD        = File.ReadAllBytes(fileName);
                    StatementOperation Hv = new StatementOperation();
                    if (Operation.StatementId != null && Operation.StatementId != 0)
                    {
                        Hv = Data.StatementOperation.Get(Operation.StatementId.Value);
                        Hv.FirstIsRightIfNull = SelectedLeg;
                        Hv.CountDays          = Days;
                        Hv.DocTemplate        = bteToBD;
                        Hv.DoctorId           = Doctors[SelectedDoctor].doc.Id;
                        Data.Complete();
                    }
                    else
                    {
                        Hv.DocTemplate        = bteToBD;
                        Hv.DoctorId           = Doctors[SelectedDoctor].doc.Id;
                        Hv.CountDays          = Days;
                        Hv.FirstIsRightIfNull = SelectedLeg;
                        Data.StatementOperation.Add(Hv);

                        Data.Complete();
                        Operation             = Data.Operation.Get(Operation.Id);
                        Operation.StatementId = Hv.Id;
                        Data.Complete();
                    }
                    //Release this document from memory.
                    IsDocAdded = Visibility.Visible;

                    Process.Start("WINWORD.EXE", fileName);
                    GetOperationid(null, Operation.Id);
                    TextForDoWhat = "Вы создали новый документ " + _fileNameOnly;
                }
                CurrentSelectDoctorPanelViewModel.PanelOpened = false;
                //MessageBus.Default.Call("GetOperationResultForCreateStatement", this, operationId);
                // Controller.NavigateTo<ViewModelCreateStatement>();
            }
                );
            ToOperationOverviewCommand = new DelegateCommand(
                () =>
            {
                if (!string.IsNullOrWhiteSpace(FileName))
                {
                    MessageBoxResult dialogResult = MessageBox.Show("Вы сохранили изменения в документе?", "", MessageBoxButton.YesNo);
                    if (dialogResult == MessageBoxResult.Yes)
                    {
                        MessageBus.Default.Call("GetOperationForOverwiev", this, operationId);
                        //GetObsForOverview
                        Controller.NavigateTo <ViewModelOperationOverview>();
                        FileName = "";
                    }
                }
                else
                {
                    MessageBus.Default.Call("GetOperationForOverwiev", this, operationId);
                    //GetObsForOverview
                    Controller.NavigateTo <ViewModelOperationOverview>();
                    FileName = "";
                }
            }
                );
            CurrentSavePanelViewModel = new SclerozPanelViewModel(this);

            OpenAddSaveCommand = new DelegateCommand(() =>
            {
                if (!string.IsNullOrWhiteSpace(FileName))
                {
                    CurrentSavePanelViewModel.ClearPanel();
                    CurrentSavePanelViewModel.PanelOpened = true;
                }
                else
                {
                    MessageBox.Show("Сначала откройте документ");
                }
            });

            RevertSaveCommand = new DelegateCommand(() =>
            {
                CurrentSavePanelViewModel.PanelOpened = false;
                // Handled = false;
            });
        }
        public ViewModelStatementForObsled(NavigationController controller) : base(controller)
        {
            IsAnalizeLoadedVisibility = Visibility.Hidden;
            ButtonName = "К Пациенту";//SetCurrentPatientIDRealyThisTime
            MessageBus.Default.Subscribe("SetAccIDForExaminationStatement", SetAccID);
            MessageBus.Default.Subscribe("GetStatementForStatementFILENAME", GetStatementForStatementFILENAME);
            MessageBus.Default.Subscribe("GetStatementForStatement", SetCurrentPatientID);
            MessageBus.Default.Subscribe("SetCurrentPatientIDRealyThisTimeStatement", SetCurrentPatientIDRealyThisTime);
            // MessageBus.Default.Subscribe("GetAnalizeForAnalizeOverview", SetCurrentAnalizeID);
            HasNavigation = false;
            Controller    = controller;

            CurrentSelectDoctorPanelViewModel = new SclerozPanelViewModel(this);

            RevertSelectDoctorCommand = new DelegateCommand(() =>
            {
                CurrentSelectDoctorPanelViewModel.PanelOpened = false;
            });

            OpenSelectDoctorCommand = new DelegateCommand(() =>
            {
                CurrentSelectDoctorPanelViewModel.ClearPanel();
                CurrentSelectDoctorPanelViewModel.PanelOpened = true;
            });

            ToCurrentObsledCommand = new DelegateCommand(
                () =>
            {
                if (!string.IsNullOrWhiteSpace(FileName))
                {
                    MessageBoxResult dialogResult = MessageBox.Show("Вы сохранили изменения в документе?", "", MessageBoxButton.YesNo);
                    if (dialogResult == MessageBoxResult.Yes)
                    {
                        Controller.NavigateTo <ViewModelAddPhysical>();
                        FileName = "";
                    }
                }
                else
                {
                    Controller.NavigateTo <ViewModelAddPhysical>();
                    FileName = "";
                }
            }
                );

            OpenWordDocument = new DelegateCommand(
                () =>
            {
                int togle = 0;

                FileName      = System.IO.Path.GetTempPath() + "Консультативное_заключение.docx";
                _fileNameOnly = "Консультативное_заключение.docx";
                byte[] bte    = CurrentDocument.DocTemplate;

                for (; ;)
                {
                    try
                    {
                        File.WriteAllBytes(FileName, bte);

                        break;
                    }
                    catch
                    {
                        togle        += 1;
                        FileName      = System.IO.Path.GetTempPath() + "Консультативное_заключение" + togle + ".docx";
                        _fileNameOnly = "Консультативное_заключение" + togle + ".docx";
                    }
                }
                TextForDoWhat = "Был открыт документ " + _fileNameOnly + ". Для сохранения изменений в документе сохраните данные в Word, закройте документ и нажмите кнопку \"Сохранить изменения\".";
                Process.Start("WINWORD.EXE", FileName);
            }
                );
            SetNewOverview = new DelegateCommand(
                () =>
            {
                //if (Doctors != null && Doctors.Count != 0)
                //{
                //    if (DoctorSelectedId == -1)
                //    {
                if (Doctors != null && Doctors.Count != 0)
                {
                    if (DoctorSelectedId == -1)
                    {
                        MessageBus.Default.Call("CreateStatement", "", null);
                    }
                    else
                    {
                        MessageBus.Default.Call("CreateStatement", Doctors[DoctorSelectedId].ToString(), Doctors[DoctorSelectedId].doc.Id);
                    }
                    TextForDoWhat = "Вы создали новый документ " + _fileNameOnly;
                    CurrentSelectDoctorPanelViewModel.PanelOpened = false;
                }



                //}
                //else
                //{
                //    MessageBus.Default.Call("CreateStatement", Doctors[DoctorSelectedId].ToString(), Doctors[DoctorSelectedId].doc.Id);
                ////}


                //}

                //OpenFileDialog op = new OpenFileDialog();
                //op.Title = "Выберите фотографию анализа";
                //op.Filter = "All supported graphics|*.jpg;*.jpeg;*.png|" +
                //  "JPEG (*.jpg;*.jpeg)|*.jpg;*.jpeg|" +
                //  "Portable Network Graphic (*.png)|*.png";
                //if (op.ShowDialog() == true)
                //{
                //    Analize.ImageByte = ImageToByte(new BitmapImage(new Uri(op.FileName)));
                //    IsAnalizeLoadedVisibility = Visibility.Visible;
                //    Data.Complete();
                //}
            }
                );
            SaveWordDocument = new DelegateCommand(
                () =>
            {
                try
                {
                    if (!string.IsNullOrWhiteSpace(FileName))
                    {
                        byte[] bteToBD  = File.ReadAllBytes(FileName);
                        StatementObs Hv = new StatementObs();
                        //HirurgOverviewRepository HirurgOverviewRep = new HirurgOverviewRepository(context);
                        //StatementObs Hv = new StatementObs();
                        //bool tester = true;

                        if (CurrentDocument.Id != 0)
                        {
                            Hv = Data.StatementObs.Get(CurrentDocument.Id);
                            CurrentDocument.DocTemplate = bteToBD;
                            Hv.DocTemplate = bteToBD;
                            //Hv.DoctorId = DoctorSelectedId;
                            Data.Complete();
                        }
                        else
                        {
                            Hv.DocTemplate = bteToBD;
                            //  Hv.DoctorId = DoctorSelectedId;
                            CurrentDocument.DocTemplate = bteToBD;
                            Data.StatementObs.Add(Hv);

                            Data.Complete();
                            CurrentDocument.Id = Hv.Id;
                            MessageBus.Default.Call("SetIdOfStatement", null, CurrentDocument.Id);
                        }
                        //foreach (var x in HirurgOverviewRep.GetAll)
                        //{

                        //    if (x.PatientId == CurrentPatient.Id)
                        //    {
                        //        tester = false;
                        //        Hv = x;
                        //        Hv.DocTemplate = bteToBD;
                        //        Data.Complete();
                        //        break;
                        //    }

                        //    // StatementObs Hv = new StatementObs();
                        //}
                        //if (tester)
                        //{
                        //    Hv.PatientId = CurrentPatient.Id;
                        //    Hv.DocTemplate = bteToBD;
                        //    Data.StatementObs.Add(Hv);
                        //    Data.Complete();
                        //}

                        //int bff = 0;
                        //if (CurrentDocument.DoctorId > 0)
                        //    bff = CurrentDocument.DoctorId;

                        //MessageBus.Default.Call("GetHirurgOverviewForHirurgOverview", null, null);
                        //if (DoctorSelectedId <= 0)
                        //    DoctorSelectedId = bff;
                        CurrentSavePanelViewModel.PanelOpened = false;
                        TextForDoWhat = "Изменения в " + _fileNameOnly + " были сохранены";
                    }
                }
                catch
                {
                    MessageBox.Show("Закройте документ");
                }
            }
                );

            CurrentSavePanelViewModel = new SclerozPanelViewModel(this);

            OpenAddSaveCommand = new DelegateCommand(() =>
            {
                if (!string.IsNullOrWhiteSpace(FileName))
                {
                    CurrentSavePanelViewModel.ClearPanel();
                    CurrentSavePanelViewModel.PanelOpened = true;
                }
                else
                {
                    MessageBox.Show("Сначала откройте документ");
                }
            });

            RevertSaveCommand = new DelegateCommand(() =>
            {
                CurrentSavePanelViewModel.PanelOpened = false;
            });
            OpenFile = new DelegateCommand(
                () =>
            {
                OpenFileDialog openFileDialog = new OpenFileDialog();
                openFileDialog.Filter         = "Word Documents (.docx)|*.docx|Word Template (.dotx)|*.dotx|All Files (*.*)|*.*";
                openFileDialog.ValidateNames  = true;
                openFileDialog.FilterIndex    = 1;
                if (openFileDialog.ShowDialog() == true)
                {
                    _fileNameOnly  = openFileDialog.SafeFileName;
                    FileName       = openFileDialog.FileName;
                    byte[] bteToBD = File.ReadAllBytes(FileName);
                    //StatementObsRepository HirurgOverviewRep = new StatementObsRepository(context);
                    StatementObs Hv = new StatementObs();

                    if (CurrentDocument.Id != 0)
                    {
                        Hv = Data.StatementObs.Get(CurrentDocument.Id);

                        Hv.DocTemplate = bteToBD;
                        //Hv.DoctorId = DoctorSelectedId;
                        Data.Complete();
                    }
                    else
                    {
                        Hv.DocTemplate = bteToBD;
                        //Hv.DoctorId = DoctorSelectedId;
                        Data.StatementObs.Add(Hv);

                        Data.Complete();
                        CurrentDocument.Id = Hv.Id;
                        MessageBus.Default.Call("SetIdOfOverview", null, CurrentDocument.Id);
                    }
                    //bool tester = true;
                    //foreach (var x in HirurgOverviewRep.GetAll)
                    //{

                    //    if (x.PatientId == CurrentPatient.Id)
                    //    {
                    //        tester = false;
                    //        Hv = Data.StatementObs.Get(x.Id);
                    //        Hv.DocTemplate = bteToBD;
                    //        Data.Complete();
                    //        break;
                    //    }

                    //    // StatementObs Hv = new StatementObs();
                    //}
                    //if (tester)
                    //{
                    //    Hv.PatientId = CurrentPatient.Id;
                    //    Hv.DocTemplate = bteToBD;
                    //    Data.StatementObs.Add(Hv);
                    //    Data.Complete();
                    //}

                    MessageBus.Default.Call("GetStatementForStatement", null, CurrentDocument.Id);
                    TextForDoWhat = "Был загружен документ " + _fileNameOnly;
                }

                //var img = ByteToImage(Analize.ImageByte);
                //int width = Convert.ToInt32(img.Width);
                //int height = Convert.ToInt32(img.Height);
                //Bitmap TestBitmap = new Bitmap(width, height);
                //TestBitmap.Save("TempImage.Bmp");
                //TestBitmap.Dispose();
                //File.WriteAllBytes("TempImage.Bmp", Analize.ImageByte);
                //Process.Start("TempImage.Bmp");
            }
                );

            //ToCurrentPatientCommand = new DelegateCommand(
            //     () =>
            //     {

            //         MessageBus.Default.Call("GetCurrentPatientId", this, CurrentPatient.Id);
            //         Controller.NavigateTo<ViewModelCurrentPatient>();
            //     }
            // );
        }
Esempio n. 4
0
        public ViewModelCreateAdditionalInfoDocuments(NavigationController controller) : base(controller)
        {
            CurrentSelectDoctorPanelViewModel = new SclerozPanelViewModel(this);

            RevertSelectDoctorCommand = new DelegateCommand(() =>
            {
                CurrentSelectDoctorPanelViewModel.PanelOpened = false;
            });
            OpenSelectDoctorCommand = new DelegateCommand(() =>
            {
                CurrentSelectDoctorPanelViewModel.ClearPanel();
                CurrentSelectDoctorPanelViewModel.PanelOpened = true;
            });
            MessageBus.Default.Subscribe("GetAdditionalInfoDocForHirurgOverview", SetCurrentPatientID);
            MessageBus.Default.Subscribe("SetCurrentPatientIDRealyThisTimeForAdditionalInfo", SetCurrentPatientIDRealyThisTime);
            // MessageBus.Default.Subscribe("GetAnalizeForAnalizeOverview", SetCurrentAnalizeID);
            HasNavigation          = false;
            Controller             = controller;
            ToCurrentObsledCommand = new DelegateCommand(
                () =>
            {
                if (!string.IsNullOrWhiteSpace(FileName))
                {
                    MessageBoxResult dialogResult = MessageBox.Show("Вы сохранили изменения в документе?", "", MessageBoxButton.YesNo);
                    if (dialogResult == MessageBoxResult.Yes)
                    {
                        //        MessageBus.Default.Call("GetOperationForOverwiev", this, operationId);
                        //GetObsForOverview
                        Controller.NavigateTo <ViewModelAdditionalInfoPatient>();
                        FileName = "";
                    }
                }
                else
                {
                    //       MessageBus.Default.Call("GetOperationForOverwiev", this, operationId);
                    //GetObsForOverview
                    Controller.NavigateTo <ViewModelAdditionalInfoPatient>();
                    FileName = "";
                }
                // Controller.NavigateTo<ViewModelAdditionalInfoPatient>();
            }
                );

            OpenWordDocument = new DelegateCommand(
                () =>
            {
                int togle = 0;

                FileName      = System.IO.Path.GetTempPath() + "Амбулаторная_карта.docx";
                _fileNameOnly = "Амбулаторная_карта.docx";
                byte[] bte    = CurrentDocument.DocTemplate;

                for (; ;)
                {
                    try
                    {
                        File.WriteAllBytes(FileName, bte);

                        break;
                    }
                    catch
                    {
                        togle        += 1;
                        FileName      = System.IO.Path.GetTempPath() + "Амбулаторная_карта" + togle + ".docx";
                        _fileNameOnly = "Амбулаторная_карта" + togle + ".docx";
                    }
                }
                TextForDoWhat = "Был открыт документ " + _fileNameOnly + ". Для сохранения изменений в документе сохраните данные в Word, закройте документ и нажмите кнопку \"Сохранить изменения\".";

                Process.Start("WINWORD.EXE", FileName);
            }
                );
            MessageBus.Default.Subscribe("GeAdditionalInfoDocFILENAME", GetStatementForStatementFILENAME);
            CurrentSavePanelViewModel = new SclerozPanelViewModel(this);

            OpenAddSaveCommand = new DelegateCommand(() =>
            {
                if (!string.IsNullOrWhiteSpace(FileName))
                {
                    CurrentSavePanelViewModel.ClearPanel();
                    CurrentSavePanelViewModel.PanelOpened = true;
                }
                else
                {
                    MessageBox.Show("Сначала откройте документ");
                }
            });

            RevertSaveCommand = new DelegateCommand(() =>
            {
                CurrentSavePanelViewModel.PanelOpened = false;
            });
            SetNewOverview = new DelegateCommand(
                () =>
            {
                if (Doctors != null && Doctors.Count != 0)
                {
                    if (DoctorSelectedId == -1)
                    {
                        MessageBus.Default.Call("CreateDocumentAdditionalInfo", "", null);
                    }
                    else
                    {
                        MessageBus.Default.Call("CreateDocumentAdditionalInfo", Doctors[DoctorSelectedId].ToString(), Doctors[DoctorSelectedId].doc.Id);
                    }
                    TextForDoWhat = "Вы создали новый документ " + _fileNameOnly;
                    CurrentSavePanelViewModel.PanelOpened = false;
                }
            }
                );
            SaveWordDocument = new DelegateCommand(
                () =>
            {
                try
                {
                    if (!string.IsNullOrWhiteSpace(FileName))
                    {
                        byte[] bteToBD            = File.ReadAllBytes(FileName);
                        AdditionalInfoDocument Hv = new AdditionalInfoDocument();

                        //bool tester = true;

                        if (CurrentDocument.Id != 0)
                        {
                            Hv = Data.AdditionalInfoDocument.Get(CurrentDocument.Id);
                            CurrentDocument.DocTemplate = bteToBD;
                            Hv.DocTemplate = bteToBD;
                            Hv.DoctorId    = Doctors[DoctorSelectedId].doc.Id;
                            Data.Complete();
                        }
                        else
                        {
                            Hv.DocTemplate = bteToBD;
                            Hv.DoctorId    = Doctors[DoctorSelectedId].doc.Id;
                            CurrentDocument.DocTemplate = bteToBD;
                            Data.AdditionalInfoDocument.Add(Hv);

                            Data.Complete();
                            CurrentDocument.Id = Hv.Id;
                            MessageBus.Default.Call("SetIdOfAdditionalInfoDoc", null, CurrentDocument.Id);
                        }
                        CurrentSavePanelViewModel.PanelOpened = false;
                        TextForDoWhat = "Изменения в " + _fileNameOnly + " были сохранены";
                    }
                }
                catch
                {
                    MessageBox.Show("Закройте документ");
                }
            }
                );
            OpenFile = new DelegateCommand(
                () =>
            {
                OpenFileDialog openFileDialog = new OpenFileDialog();
                openFileDialog.Filter         = "Word Documents (.docx)|*.docx|Word Template (.dotx)|*.dotx|All Files (*.*)|*.*";
                openFileDialog.ValidateNames  = true;
                openFileDialog.FilterIndex    = 1;
                if (openFileDialog.ShowDialog() == true)
                {
                    _fileNameOnly             = openFileDialog.SafeFileName;
                    FileName                  = openFileDialog.FileName;
                    byte[] bteToBD            = File.ReadAllBytes(FileName);
                    AdditionalInfoDocument Hv = new AdditionalInfoDocument();

                    if (CurrentDocument.Id != 0)
                    {
                        Hv = Data.AdditionalInfoDocument.Get(CurrentDocument.Id);

                        Hv.DocTemplate = bteToBD;
                        Hv.DoctorId    = Doctors[DoctorSelectedId].doc.Id;
                        Data.Complete();
                    }
                    else
                    {
                        Hv.DocTemplate = bteToBD;
                        Hv.DoctorId    = Doctors[DoctorSelectedId].doc.Id;
                        Data.AdditionalInfoDocument.Add(Hv);

                        Data.Complete();
                        CurrentDocument.Id = Hv.Id;
                        MessageBus.Default.Call("SetIdOfAdditionalInfoDoc", null, CurrentDocument.Id);
                    }

                    MessageBus.Default.Call("GetAdditionalInfoDocForHirurgOverview", null, CurrentDocument.Id);
                    TextForDoWhat = "Был загружен документ " + _fileNameOnly;
                }
            }
                );

            ToCurrentPatientCommand = new DelegateCommand(
                () =>
            {
                MessageBus.Default.Call("GetCurrentPatientId", this, CurrentPatient.Id);
                Controller.NavigateTo <ViewModelCurrentPatient>();
            }
                );
        }