private async void LoadingModel(object sender, DoWorkEventArgs e)
        {
            try
            {
                using (me = new MedicalModel(ConfigurationManager.Connect()))
                {
                    await me.Database.Connection.OpenAsync();

                    if (ExaminationViewM.Imported)
                    {
                        me.examinationdatadocuments.Where(ex => me.importedexaminationdatadocuments_st.Where
                                                              (iex => iex.IdIEX == ExaminationViewM.Id).Select(iex => iex.IdEXD).ToList().Any(c => c == ex.IdEXD)).ToList().ForEach
                            (p => DocumentControlVM.Add(p.TypeEXD, p.FileTypeEXD, p.IdEXD, new MemoryStream(p.DataEXD)));

                        ExaminationViewM.ExaminationCode = me.importedexaminationdata.Where(iex => iex.IdIEX == ExaminationViewM.Id).Single().CodeIEX;
                        ExaminationViewM.ExaminationName = me.importedexaminationdata.Where(iex => iex.IdIEX == ExaminationViewM.Id).Single().NameIEX;
                        ExaminationViewM.ExaminationDate = me.importedexaminationdata.Where(iex => iex.IdIEX == ExaminationViewM.Id).Single().DateTimeIEX;
                    }

                    else
                    {
                        me.examinationdatadocuments.Where(ex => me.examinationdatadocuments_st.Where
                                                              (iex => iex.IdEX == ExaminationViewM.Id).Select(iex => iex.IdEXD).ToList().Any(c => c == ex.IdEXD)).ToList().ForEach
                            (p => DocumentControlVM.Add(p.TypeEXD, p.FileTypeEXD, p.IdEXD, new MemoryStream(p.DataEXD)));

                        ExaminationViewM.ExaminationCode = me.examinationdata.Where(iex => iex.IdEX == ExaminationViewM.Id).Single().CodeEX;
                        ExaminationViewM.ExaminationName = me.servicesdata.Where(t => t.IdTD == me.examinationdata.
                                                                                 Where(iex => iex.IdEX == ExaminationViewM.Id).FirstOrDefault().ServiceIdEX).Single().NameTD;
                        ExaminationViewM.ExaminationDate = me.examinationdata.Where(iex => iex.IdEX == ExaminationViewM.Id).Single().DateTimeEX;
                    }
                }
                workingConn = true;
            }
            catch (Exception ex)
            {
                Log.WriteException(ex);
                workingConn = false;
            }
        }
        private async void LoadingModel(object sender, DoWorkEventArgs e)
        {
            try
            {
                using (me = new MedicalModel(ConfigurationManager.Connect()))
                {
                    await me.Database.Connection.OpenAsync();

                    if (ViewEvidenceM.Imported)
                    {
                        me.evidencedatadocuments.Where(ex => me.importedevidencedatadocuments_st.Where
                                                           (iex => iex.IdIED == ViewEvidenceM.Id).Select(iex => iex.IdEDD).ToList().Any(c => c == ex.IdEDD)).ToList().ForEach
                            (p => DocumentControlVM.Add(p.TypeEDD, p.FileTypeEDD, p.IdEDD, new MemoryStream(p.DataEDD)));

                        ViewEvidenceM.Code = me.importedevidencedata.Where(iex => iex.IdIED == ViewEvidenceM.Id).Single().CodeIED;
                        ViewEvidenceM.Date = me.importedevidencedata.Where(iex => iex.IdIED == ViewEvidenceM.Id).Single().DateTimeIED;

                        foreach (SelectedPatientM.ExaminationItem item in me.examinationdata.Where(ed => ed.IdEX == me.examinationeachimportedevidence_st
                                                                                                   .Where(eeie => eeie.IdIED == ViewEvidenceM.Id).Select(eeie => eeie.IdEX).FirstOrDefault()).ToList()
                                 .Select(s => new SelectedPatientM.ExaminationItem()
                        {
                            Imported = false,
                            Id = s.IdEX,
                            Name = me.servicesdata.Where(t => t.IdTD == s.ServiceIdEX).Select(t => t.NameTD).FirstOrDefault(),
                            Code = s.CodeEX,
                            Date = s.DateTimeEX
                        }))
                        {
                            AddList(item);
                        }

                        foreach (SelectedPatientM.ExaminationItem item in me.importedexaminationdata.Where(ed => ed.IdIEX == me.importedexaminationeachimportedevidence_st
                                                                                                           .Where(eeie => eeie.IdIED == ViewEvidenceM.Id).Select(eeie => eeie.IdIEX).FirstOrDefault()).ToList()
                                 .Select(s => new SelectedPatientM.ExaminationItem()
                        {
                            Imported = true,
                            Id = s.IdIEX,
                            Name = s.NameIEX,
                            Code = s.CodeIEX,
                            Date = s.DateTimeIEX
                        }))
                        {
                            AddList(item);
                        }
                    }

                    else
                    {
                        me.evidencedatadocuments.Where(ex => me.evidencedatadocuments_st.Where
                                                           (iex => iex.IdED == ViewEvidenceM.Id).Select(iex => iex.IdEDD).ToList().Any(c => c == ex.IdEDD)).ToList().ForEach
                            (p => DocumentControlVM.Add(p.TypeEDD, p.FileTypeEDD, p.IdEDD, new MemoryStream(p.DataEDD)));

                        ViewEvidenceM.Code = me.evidencedata.Where(iex => iex.IdED == ViewEvidenceM.Id).Single().CodeED;
                        ViewEvidenceM.Date = me.evidencedata.Where(iex => iex.IdED == ViewEvidenceM.Id).Single().DateTimeED;

                        foreach (SelectedPatientM.ExaminationItem item in me.examinationdata.Where(ed => ed.IdEX == me.examinationeachevidence_st
                                                                                                   .Where(eeie => eeie.IdED == ViewEvidenceM.Id).Select(eeie => eeie.IdEX).FirstOrDefault()).ToList()
                                 .Select(s => new SelectedPatientM.ExaminationItem()
                        {
                            Imported = false,
                            Id = s.IdEX,
                            Name = me.servicesdata.Where(t => t.IdTD == s.ServiceIdEX).Select(t => t.NameTD).FirstOrDefault(),
                            Code = s.CodeEX,
                            Date = s.DateTimeEX
                        }))
                        {
                            AddList(item);
                        }

                        foreach (SelectedPatientM.ExaminationItem item in me.importedexaminationdata.Where(ed => ed.IdIEX == me.importedexaminationeachevidence_st
                                                                                                           .Where(eeie => eeie.IdED == ViewEvidenceM.Id).Select(eeie => eeie.IdIEX).FirstOrDefault()).ToList()
                                 .Select(s => new SelectedPatientM.ExaminationItem()
                        {
                            Imported = true,
                            Id = s.IdIEX,
                            Name = s.NameIEX,
                            Code = s.CodeIEX,
                            Date = s.DateTimeIEX
                        }))
                        {
                            AddList(item);
                        }
                    }
                }
                workingConn = true;
            }
            catch (Exception ex)
            {
                Log.WriteException(ex);
                workingConn = false;
            }
        }