WorklistView CreateExamListView(WorklistViewModel viewModel)
        {
            WorklistView view = new WorklistView(viewModel);

            TabItem ti = new TabItem { Content = view };
            ti.DataContext = viewModel;
            this.tabExamList.Items.Add(ti);

            return view;
        }
        public static WorklistViewModel Create(ExamListViewType examListViewType, IWorkListDataSource dataSource)
        {
            WorklistViewModel viewModel = new WorklistViewModel(examListViewType, dataSource);

            switch (examListViewType)
            {
                case ExamListViewType.Read: viewModel.Title = "Readlist"; break;
                case ExamListViewType.Unread: viewModel.Title = "Results"; break;
                case ExamListViewType.Patient: viewModel.Title = "Patient"; break;
            }

            return viewModel;
        }
 private void saveOldSelectedNodes(WorklistViewModel viewModel)
 {
     if (viewModel.SelectedItems.Count > 0)
     {
         _oldSelectedItems = new ObservableCollection<CaseListItem>();
         foreach (CaseListItem selectedItem in viewModel.SelectedItems)
         {
             _oldSelectedItems.Add(selectedItem);
         }
     }
 }
        public WorklistView(WorklistViewModel viewModel)
        {
            DataContext = viewModel;
            viewModel.PropertyChanged += new PropertyChangedEventHandler(viewModel_PropertyChanged);
            viewModel.CasesUpdated += new CasesUpdatedHandler(viewModel_CasesUpdated);

            InitializeComponent();

            AppMessages.WorklistFilterChangeMessage.Register(
                    this,
                    (action) => DispatcherHelper.CheckBeginInvokeOnUI(() => this.ApplyFilter(action.Content, action.Sender)));

            this._tree.RowExpanded += new RowExpandedEventHandler(_tree_RowExpanded);

            // notification of column reorder event
            //GridView gridView = (GridView)this._tree.View;
            //gridView.Columns.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(Columns_CollectionChanged);
        }
        void OnViewConsultationStatus(CaseListItem item, WorklistViewModel worklist)
        {
            MainViewModel viewModel = (MainViewModel)DataContext;

            // check to see if the case already have an interpretation entry,
            // if there is no entry, create one
            if ((item.ConsultationList == null) || (item.ConsultationList.ConsultationList == null)
                || (item.ConsultationList.ConsultationList.Count == 0))
            {
                if (!viewModel.DataSource.RequestInterpretation(item.CaseURN, UserContext.LocalSite.PrimarySiteStationNUmber))
                {
                    MessageBox.Show("Case doesn't have an interpretation entry. Cannot proceed.", "Information", MessageBoxButton.OK, MessageBoxImage.Information);
                    return;
                }
            }

            // retrieve a list of reading sites that read for the site own the case
            // this way, only sites that are in agreement with the acquisition can access the data
            ReadingSiteList readSites = viewModel.DataSource.GetReadingSites(item.SiteCode);

            foreach (ReadingSiteInfo readSite in readSites.Items)
            {
                // if the user site is a consultation site, the user can't request more consultation on remote item,
                // however he/she must be able to refuse one that was just requested (report status id "Pending Verification")
                if ((readSite.SiteStationNumber == UserContext.LocalSite.PrimarySiteStationNUmber) && (readSite.SiteType == ReadingSiteType.consultation))
                {
                    MessageBox.Show("Your site is configured as a consultation site at " + item.AcquisitionSite + ".\r\nOnly primary interpreting site can request consultations.");

                    if (item.ReportStatus == "Pending Verification")
                    {
                        MessageBoxResult result = MessageBox.Show("From site " + item.AcquisitionSite + " for Case <" + item.AccessionNumber +
                                        "> Consultation is requested.\r\nDo you want to Decline this request?", "Choice", MessageBoxButton.YesNo, MessageBoxImage.Information, MessageBoxResult.No /* default to No */);
                        if (result == MessageBoxResult.Yes)
                        {
                            // update Consult status to refused!
                            ConsultationStatusViewModel consultSVM = new ConsultationStatusViewModel(item, readSites);
                            consultSVM.SelectedSites = new ObservableCollection<SiteConsultationStatusViewModel>();
                            SiteConsultationStatusViewModel itemVM = new SiteConsultationStatusViewModel();
                            itemVM.Item = item;
                            itemVM.SiteInfo = readSite; // ReadingSiteInfo
                            itemVM.IsCurrentSite = false;
                            itemVM.CanRefuseConsultation = true;
                            itemVM.CanRequestConsultation = false;
                            itemVM.IsRecalled = false;
                            // Consultations are returned from originating DB if we got here
                            int lastConsultIndex = item.ConsultationList.ConsultationList.Count;
                            itemVM.ConsultationID = item.ConsultationList.ConsultationList[lastConsultIndex-1].ConsultationID;
                            itemVM.IsPending = true;
                            consultSVM.SelectedSites.Add(itemVM);

                            consultSVM.RefuseConsultation();
                            return;
                        }
                    }
                    return;
                }
            }

            ConsultationStatusViewModel dialogViewModel = new ConsultationStatusViewModel(item, readSites);
            ConsultationStatusView dialog = new ConsultationStatusView(dialogViewModel);
            dialog.Owner = this;
            dialog.ShowDialog();
        }
        void OnEditReport(CaseListItem item, WorklistViewModel worklist)
        {
            try
            {
                MainViewModel viewModel = (MainViewModel)DataContext;

                // see what reading site type
                ReadingSiteType currentSiteType = GetReadingSiteType(item);
                if (currentSiteType == ReadingSiteType.undefined)
                {
                    MessageBox.Show("Current site is undefined from the case's acquisition site's reading list.", "Information", MessageBoxButton.OK, MessageBoxImage.Information);
                    return;
                }

                // check to see if the patient is restricted
                bool canProceed = CanUserViewPatientData(item.SiteCode, item.PatientICN);
                if (!canProceed)
                {
                    MessageBox.Show("You cannot view information on this patient.", "Information", MessageBoxButton.OK, MessageBoxImage.Information);
                    return;
                }

                // check to see if the patient is available at the local site
                // if the patient is not registered then always read only report
                bool patientRegistered = viewModel.DataSource.IsPatientRegisteredAtSite(UserContext.LocalSite.PrimarySiteStationNUmber, item.PatientICN);
                if (!patientRegistered)
                {
                    MessageBox.Show("This patient is not registered at this site. Report Editor will open as read only.", "Information", MessageBoxButton.OK, MessageBoxImage.Information);
                }

                // everything is readonly if it's the patient tab
                bool isPatientTab = viewModel.WorklistsViewModel.CurrentWorkList.Type == ExamListViewType.Patient ? true : false;
                bool isTotalReadOnly = !patientRegistered || isPatientTab;

                // lock the case to prevent other people from accessing the report
                PathologyCaseUpdateAttributeResultType locked = viewModel.DataSource.LockCaseForEditing(item.CaseURN, true);

                ReportView window;
                if (locked.BoolSuccess)
                {
                    // open the report normally
                    window = new ReportView(new ReportViewModel(viewModel.DataSource, item, isTotalReadOnly, currentSiteType));

                    ViewModelLocator.ContextManager.IsBusy = true;
                    window.ShowDialog();

                    // unlock the case once the user has closed the report GUI
                    locked = viewModel.DataSource.LockCaseForEditing(item.CaseURN, false);
                }
                else
                {
                    // some one else is editing the report
                    string message = String.Format("{0}. Do you want to open it as read only?", locked.ErrorMessage);
                    MessageBoxResult result = MessageBox.Show(message, "Confirmation", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No);
                    if (result == MessageBoxResult.Yes)
                    {
                        // open the report as read only
                        window = new ReportView(new ReportViewModel(viewModel.DataSource, item, true, currentSiteType));

                        ViewModelLocator.ContextManager.IsBusy = true;
                        window.ShowDialog();
                    }
                }
            }
            finally
            {
                ViewModelLocator.ContextManager.IsBusy = false;
            }
        }