internal void FillCaseDetails(CaseListItem item)
 {
     CaseSpecimenList specimenData = _dataSource.GetCaseDetail(item.CaseURN);
     item.CreateChildren(specimenData);
 }
Пример #2
0
        /// <summary>
        /// Retrieve report data for a case
        /// </summary>
        /// <param name="item">Case item</param>
        /// <returns>Report data for the case in question</returns>
        public Report GetReport(CaseListItem item)
        {
            Log.Debug("Retrieving report data...");

            // Always return a valid object for binding
            Report rep = new Report();

            if (item == null)
            {
                Log.Error("Missing parameter: caselistitem.");
                return rep;
            }

            // first we need to get the report template based on the type indicate in the accession number
            AccessionNumber accNum = new AccessionNumber(item.AccessionNumber);
            VixReportTemplateObject templateObj = GetReportTemplate(item.SiteCode, accNum.Type);

            // in case there is an error in the tranmission
            if (templateObj.TemplateXML == string.Empty)
            {
                Log.Error("Failed to get template.");
                return rep;
            }

            // retrieve a list of fields to grab data from the template
            rep.ReportTemplate = templateObj.GetReportTemplate();
            //List<string> fields = rep.GetFieldList();
            List<string> fields = rep.GetAllFieldList();

            string URI = String.Format("pathology/case/template/{0}", item.CaseURN);
            IRestResponse response;
            try
            {
                PathologyCaseTemplateInputFieldsType fieldList = new PathologyCaseTemplateInputFieldsType(fields);
                string xml = ResponseParser.SerializeToXml<PathologyCaseTemplateInputFieldsType>(fieldList);
                response = ExecutePost(URI, VixServiceTypes.Pathology, xml);
                ValidateRestResponse(response);
                PathologyCaseTemplateType rawRep = ResponseParser.ParseGetReport(response.Content);
                rep.LoadReportData(rawRep);
            }
            catch (MagResponseParsingFailureException rpf)
            {
                Log.Error("Failed to parse report fields.", rpf);
            }
            catch (MagVixFailureException vfe)
            {
                Log.Error("Unexpected response.", vfe);
            }
            catch (Exception ex)
            {
                Log.Error("Could not complete request to retrieve report data.", ex);
            }

            return rep;
        }
        public void Sort(CaseListItem parent, string field, bool ascending)
        {
            CaseListColumnType column = (CaseListColumnType)Enum.Parse(typeof(CaseListColumnType), field);

            parent.Slides.Sort(delegate(CaseListItem item1, CaseListItem item2)
            {
                return CaseListItemComparer.Compare(item1, item2, column, ascending);
            });

            foreach (CaseListItem child in parent.Slides)
            {
                Sort(child, field, ascending);
            }
        }
Пример #4
0
        public void CreateChildren(CaseSpecimenList specimenData)
        {
            // clear speciment list
            this.Slides.Clear();

            // group by specimens first
            List<List<CaseSpecimen>> specimens = specimenData.Items.GroupBy(item => item.Specimen).Select(group => new List<CaseSpecimen>(group).Where(spec => !string.IsNullOrEmpty(spec.Specimen)).ToList()).ToList();
            foreach (List<CaseSpecimen> specimenGroup in specimens)
            {
                if (specimenGroup.Count == 0) continue;

                // add specimen node
                CaseListItem specimenRoot = new CaseListItem(specimenGroup[0], this, CaseListItemKind.Specimen);

                // group by smear prep
                List<List<CaseSpecimen>> smearPreps = specimenGroup.GroupBy(item => item.SmearPrep).Select(group => new List<CaseSpecimen>(group).Where(spec => !string.IsNullOrEmpty(spec.SmearPrep)).ToList()).ToList();
                foreach (List<CaseSpecimen> smearPrepGroup in smearPreps)
                {
                    if (smearPrepGroup.Count == 0) continue;

                    // add smear prep node
                    CaseListItem smearPrepRoot = new CaseListItem(smearPrepGroup[0], specimenRoot, CaseListItemKind.SmearPrep);

                    // add remaining stains
                    foreach (CaseSpecimen stain in smearPrepGroup)
                    {
                        if (string.IsNullOrEmpty(stain.Stain)) continue;

                        CaseListItem stainNode = new CaseListItem(stain, smearPrepRoot, CaseListItemKind.Stain);

                        smearPrepRoot.Slides.Add(stainNode);
                    }

                    specimenRoot.Slides.Add(smearPrepRoot);
        }

                this.Slides.Add(specimenRoot);
            }
        }
Пример #5
0
        public static void CreateNodes(CaseList caseList, CaseListItem root, WorkListFilter filter)
        {
            CaseListItem caseNode = null;

            root.Slides.Clear();

            foreach (Case caseItem in caseList.Cases)
            {
                caseNode = null;

                if (filter == null)
                {
                    caseNode = new CaseListItem(caseItem);
                }
                else
                {
                    if (filter.MatchCase(caseItem) != WorkListFilterParameter.FilterMatchType.NotMatch)
                    {
                        caseNode = new CaseListItem(caseItem);
                    }
                }

                if (caseNode != null)
                {
                    // todo: add children using cached data

                    // create place holder if no children
                    if (caseNode.Slides.Count == 0)
                    {
                        caseNode.Slides.Add(new CaseListItem { Kind = CaseListItemKind.PlaceHolder });
                    }

                    root.Slides.Add(caseNode);
                }

            }
        }
        private ReadingSiteType GetReadingSiteType(CaseListItem item)
        {
            if ((item == null) || (string.IsNullOrWhiteSpace(item.SiteCode)))
                return ReadingSiteType.undefined;

            // if the user's site is the same as the case's site, the user's site is interpretation
            if (UserContext.LocalSite.PrimarySiteStationNUmber == item.SiteCode)
            {
                return ReadingSiteType.interpretation;
            }

            MainViewModel viewModel = (MainViewModel)DataContext;

            // retrieve a list of reading sites that read for the case's site
            // this way, only sites that are in agreement with the acquisition can access the data
            ReadingSiteList readSites = viewModel.DataSource.GetReadingSites(item.SiteCode);
            var readSite = readSites.Items.Where(site => site.SiteStationNumber == UserContext.LocalSite.SiteStationNumber).FirstOrDefault();
            if (readSite == null)
            {
                // current site is not on the agreement list
                return ReadingSiteType.undefined;
            }
            else
            {
                if (readSite.SiteType == ReadingSiteType.consultation)
                    return ReadingSiteType.consultation;
                else if (readSite.SiteType == ReadingSiteType.interpretation)
                    return ReadingSiteType.interpretation;
                else if (readSite.SiteType == ReadingSiteType.both)
                    return ReadingSiteType.interpretation;
                else
                    return ReadingSiteType.undefined;
            }
        }
Пример #7
0
        public CaseListItem(CaseSpecimen caseSpecimen, CaseListItem parent, CaseListItemKind kind)
        {
            this.Kind = kind;

            // parent level attributes
            this.PatientICN = parent.PatientICN;
            this.CaseURN = parent.CaseURN;
            this.AccessionNumber = parent.AccessionNumber;
            this.SiteCode = parent.SiteCode;

            switch (this.Kind)
            {
                case CaseListItemKind.Specimen:
                    this.Specimen = caseSpecimen.Specimen.Trim();
                    break;

                case CaseListItemKind.SmearPrep:
                    this.SmearPrep = caseSpecimen.SmearPrep.Trim();
                    break;

                case CaseListItemKind.Stain:
                    this.Stain = caseSpecimen.Stain;
                    this.StainDateTime = caseSpecimen.StainDate.Trim();
                    break;
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ConsultationStatusViewModel"/> class with cases
        /// </summary>
        /// <param name="readSites">list of known reading sites</param>
        public ConsultationStatusViewModel(CaseListItem item, ReadingSiteList sitelist)
        {
            this.Sites = new ObservableCollection<SiteConsultationStatusViewModel>();
            this.SelectedSites = new ObservableCollection<SiteConsultationStatusViewModel>();

            this.CancelConsultationCommand = new RelayCommand(CancelConsultation, () => CanCancelConsultation());
            this.RequestConsultationCommand = new RelayCommand(RequestConsultation, () => CanRequestConsultation());
            this.RefuseConsultationCommand = new RelayCommand(RefuseConsultation, () => CanRefuseConsultation());

            this.AccessionNr = item.AccessionNumber;
            this.PatientName = item.PatientName;
            this.PatientID = item.PatientID;

            bool canRequestConsultation = true;
            foreach (ReadingSiteInfo readingSiteInfo in sitelist.Items)
            {
                if ((readingSiteInfo.SiteStationNumber == UserContext.LocalSite.PrimarySiteStationNUmber) && (readingSiteInfo.SiteType == ReadingSiteType.consultation))
                {
                    canRequestConsultation = false;
                    break;
                }
            }

            // process consultation sites
            foreach (ReadingSiteInfo siteInfo in sitelist.Items)
            {
                SiteConsultationStatusViewModel itemVM = new SiteConsultationStatusViewModel();
                itemVM.Item = item;
                itemVM.SiteInfo = siteInfo;
                Site localSite = UserContext.LocalSite;
                itemVM.CanRequestConsultation = canRequestConsultation;

                foreach (CaseConsultation consult in item.ConsultationList.ConsultationList)
                {
                    if ((siteInfo.SiteStationNumber == consult.SiteID) && (consult.Type == "CONSULTATION"))
                    {
                        itemVM.ConsultationID = consult.ConsultationID;

                        if (consult.Status == "PENDING")
                        {
                            itemVM.IsPending = true;

                            // if request pending for current site
                            if ((siteInfo.SiteStationNumber == UserContext.LocalSite.PrimarySiteStationNUmber) &&
                                (consult.SiteID == UserContext.LocalSite.PrimarySiteStationNUmber))
                            {
                                itemVM.CanRefuseConsultation = true;
                            }
                        }
                        else if (consult.Status == "REFUSED")
                        {
                            itemVM.IsRefused = true;
                        }
                        else if (consult.Status == "COMPLETED")
                        {
                            itemVM.IsCompleted = true;
                        }
                    }
                }

                if (!itemVM.IsPending && !itemVM.IsCompleted && !siteInfo.Active)
                {
                    // not active and not pending. ignore this site
                    continue;
                }

                this.Sites.Add(itemVM);
            }

            // process consultation requests for current site
            foreach (CaseConsultation consult in item.ConsultationList.ConsultationList)
            {
                if ((consult.SiteID == UserContext.LocalSite.PrimarySiteStationNUmber) &&
                    (consult.Type == "CONSULTATION") && (consult.Status == "PENDING"))
                {
                    SiteConsultationStatusViewModel itemVM = new SiteConsultationStatusViewModel();
                    itemVM.Item = item;
                    itemVM.SiteInfo = new ReadingSiteInfo
                    {
                        SiteStationNumber = UserContext.LocalSite.PrimarySiteStationNUmber,
                        SiteAbr = UserContext.LocalSite.SiteAbbreviation,
                        SiteName = UserContext.LocalSite.SiteName,
                        Active = true
                    };
                    itemVM.IsCurrentSite = true;
                    itemVM.ConsultationID = consult.ConsultationID;
                    itemVM.IsPending = true;

                    this.Sites.Add(itemVM);
                }
            }
        }
Пример #9
0
 /// <summary>
 /// Retrieve report data for a case
 /// </summary>
 /// <param name="item">Case item</param>
 /// <returns>Report data for the case in question</returns>
 public Report GetReport(CaseListItem caseObject)
 {
     if (vixClient != null)
     {
         return vixClient.GetReport(caseObject);
     }
     else
     {
         Log.Error("VIX client is null.");
         return new Report();
     }
 }
        void OnViewReport(CaseListItem item)
        {
            try
            {
                // retrieve the released report from VistA
                MainViewModel viewModel = (MainViewModel)DataContext;

                // 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;
                }

                string releasedReport = viewModel.DataSource.GetCPRSReport(viewModel.WorklistsViewModel.CurrentWorkList.SelectedItems[0].CaseURN);

                // open new window
                ReleasedCPRSReportView view = new ReleasedCPRSReportView();
                view.Title = item.SiteAbbr + " " + item.AccessionNumber;
                view.ReleasedReport = releasedReport;

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

                Log.Info("View released report for case " + item.AccessionNumber + " at site " + item.SiteCode);
            }
            catch (Exception ex)
            {
                Log.Error("Unknown exception.", ex);
            }
            finally
            {
                ViewModelLocator.ContextManager.IsBusy = false;
            }
        }
        void OnViewSnapshots(CaseListItem item)
        {
            // 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;
            }
            ////**** This try-catch clause is for slide-atlas demo only *****
            //try
            //{
            //    Uri newUri = null;
            //    if (item.IsNoteAttached.Equals("Yes"))
            //        newUri = new Uri("https://slide-atlas.org/webgl-viewer?db=53468ebc0a3ee10dd6b81ca5&view=544f92fbdd98b51542be1f9c");
            //    else
            //        newUri = new Uri("https://slide-atlas.org/webgl-viewer?db=5074589002e31023d4292d83&view=544f92d6dd98b515418f3302");
            //    // A.
            //    // ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(AcceptAllCertifications);
            //    // WebRequest webRequest = WebRequest.Create(newUri.ToString());
            //    // WebResponse webResponse = webRequest.GetResponse();
            //    // // webRequest.Timeout = 3500;

            //    // B. WebClient webClient = new WebClient(); // /*System.Net.WebClient is other choice
            //    //    webClient.DownloadStringAsync(newUri, string.Empty);

            //    // C. Thread myThread = new Thread(new ThreadStart(myHttpMethod(newUri);
            //    // myThread.Start();

            //    // D.
            //    System.Diagnostics.Process.Start(newUri.ToString());

            //}
            //catch (Exception ex)
            //{
            //    Log.Error("Could not start web link.", ex);
            //}

            //**** This is for Vendor system integration getting/displaying (invoking vendor application) list of slides based on HL7 feed from scanner system *****.
            ViewCaseSlides(item);

            /* **** This section is commented out for not using MagImageDisplay *****

            // sync the context and open display to view snapshot images.
            try
            {
                MainViewModel viewModel = (MainViewModel)DataContext;

                Patient curPatient = viewModel.DataSource.GetPatient(item.SiteCode, item.PatientICN);

                // CCOW set patient context
                ViewModelLocator.ContextManager.SetCurrentPatient(curPatient);
                ViewModelLocator.ContextManager.IsBusy = true;

                string progPath = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86);
                string exePath = @"\VistA\Imaging\MagImageDisplay.exe";

                Process[] processes = Process.GetProcessesByName("MagImageDisplay");
                if ((processes != null) && (processes.Length > 0))
                {
                    // should switch focus to display here
                    IntPtr hwnd = processes[0].MainWindowHandle;
                    ShowWindowAsync(hwnd, SW_RESTORE);
                    SetForegroundWindow(hwnd);
                }
                else
                {
                    // should open new instance of display
                    Process magDisplay = new Process();
                    magDisplay.StartInfo.FileName = progPath + exePath;
                    magDisplay.StartInfo.Arguments = string.Format("s={0} p={1}", UserContext.ServerName, UserContext.ServerPort);
                    magDisplay.Start();
                }

                Log.Info("View snapshots for case " + item.SiteAbbr + " " + item.AccessionNumber);
            }
            catch (Exception ex)
            {
                Log.Error("Could not change patient and launch VI Display.", ex);
                MessageBox.Show("Could not launch VistA Imaging Clinical Display.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            finally
            {
                ViewModelLocator.ContextManager.IsBusy = false;
            } */
        }
        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;
            }
        }
        /// <summary>
        /// Check to see what kind of site is the current user at
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        private bool IsSiteInterpretingForCase(CaseListItem item)
        {
            // if the user site is the same as the case's site, user can interpretate
            if (UserContext.LocalSite.PrimarySiteStationNUmber == item.SiteCode)
            {
                return true;
            }

            MainViewModel viewModel = (MainViewModel)DataContext;

            // 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 an interpretation site, then they can interpretate
                if ((readSite.SiteStationNumber == UserContext.LocalSite.PrimarySiteStationNUmber) && (readSite.SiteType != ReadingSiteType.consultation))
                {
                    return true;
                }
            }

            return false;
        }
        public WorklistViewModel(ExamListViewType examlistType, IWorkListDataSource dataSource)
        {
            this.Type = examlistType;
            this._dataSource = dataSource;
            Root = new CaseListItem();
            IsActive = false;

            this.RefreshCommand = new RelayCommand(Refresh);

            this.ReserveCaseCommand = new RelayCommand(ReserveCases, () => CanReserveCases());

            this.UnreserveCaseCommand = new RelayCommand(UnreserveCases, () => CanUnreserveCases());

            this.RequestConsultationCommand = new RelayCommand(RequestConsultation, () => CanRequestConsultation());

            this.EditReportCommand = new RelayCommand(EditReport, () => CanEditReport());

            this.ViewReportCommand = new RelayCommand(ViewReport, () => CanViewReport());

            this.ViewSnapshotsCommand = new RelayCommand(ViewSnapshots, () => CanViewSnapshots());

            this.ViewNotesCommand = new RelayCommand(ViewNotes, () => CanViewNotes());

            this.ViewInCaptureCommand = new RelayCommand(ViewInCapture, () => CanViewInCapture());

            //this.DoubleClickCommand = new RelayCommand(this.ReserveCases, () => CanReserveCases());

            this.ViewDefaultHealthSummaryCommand = new RelayCommand(ViewDefaultHealthSummary, () => CanViewDefaultHealthSummary());

            this.ViewHealthSummaryListCommand = new RelayCommand(ViewHealthSummaryList, () => CanViewHealthSummaryList());

            this.WorklistFilterViewModel = new WorklistFilterViewModel(this.Type);
            this.WorklistFilterViewModel.PropertyChanged += new PropertyChangedEventHandler(WorklistFilterViewModel_PropertyChanged);

            // configure periodic refresh, periodically refreshes active worklist
            _refreshTimer = new DispatcherTimer();
            _refreshTimer.Interval = TimeSpan.FromMilliseconds(3000);
            _refreshTimer.Tick += new EventHandler(_timer_Tick);
            _refreshTimer.Start();
        }
 public Report GetReport(CaseListItem caseObject)
 {
     return vistaClient.GetReport(caseObject);
 }
        public ReportViewModel(IWorkListDataSource dataSource, CaseListItem caseItem, bool isGlobalReadOnly = false, ReadingSiteType siteType = ReadingSiteType.interpretation)
        {
            DataSource = dataSource;

            // editor property
            this.IsEditorReadOnly = isGlobalReadOnly;
            this.CurrentSiteType = siteType;

            // case's properties
            this.CaseURN = caseItem.CaseURN;
            this.SiteAbbr = caseItem.SiteAbbr;
            this.SiteCode = caseItem.SiteCode;
            this.AccessionNumber = caseItem.AccessionNumber;
            ChangeList = new PathologyCaseReportFieldsType();

            // patient's info
            this.PatientName = caseItem.PatientName;
            this.PatientID = caseItem.PatientID;
            this.Patient = DataSource.GetPatient(caseItem.SiteCode, caseItem.PatientICN);

            // retrieve the Esignature status at the case's primary site
            GetESignatureStatus();

            // consultations
            this.ConsultationList = caseItem.ConsultationList;

            // CCOW set patient context
            IContextManager contextManager = ViewModelLocator.ContextManager;
            contextManager.SetCurrentPatient(this.Patient);
            this.CCOWContextState = contextManager.GetPatientContextState(this.Patient);

            // get notified of CCOW context state change events
            contextManager.PropertyChanged += new PropertyChangedEventHandler(contextManager_PropertyChanged);

            // retrieve report data
            report = dataSource.GetReport(caseItem);

            // retrieve supplementary reports
            DateTime srDisplayDateStart;
            if (!DateTime.TryParse(DateSpecReceived, out srDisplayDateStart))
            {
                srDisplayDateStart = DateTime.Today;
            }
            SRViewModel = new SupplementaryReportViewModel(DataSource, SiteCode, AccessionNumber, this.CaseURN, this.ConsultationList, this.IsEditorReadOnly, this.CurrentSiteType);
            SRViewModel.SRDateStart = srDisplayDateStart;
            SRViewModel.Practitioner = Practitioner;
            SRViewModel.EsigStatus = this.EsigStatus;
            //srViewModel.LocalEsigStatus = this.LocalEsigStatus;

            // initialized codeing tab
            ReportCodingVM = new ReportCodingViewModel(this.DataSource, this.CaseURN, this.SiteCode, this.IsEditorReadOnly, this.CurrentSiteType);

            LaunchCPRSReportCommand = new RelayCommand(LaunchCPRSReport, () => this.State == ReportState.Verified);
            SaveReportCommand = new RelayCommand(SaveMainReportToDatabase, () => CanSaveMainReport);
            CompleteReportCommand = new RelayCommand(CompleteReport, () => CanCompleteMainReport);
            VerifyReportCommand = new RelayCommand(VerifyReport, () => CanVerifyMainReport);
            SearchUserCommand = new RelayCommand<string>((s) => SearchUser(s), (s) => CanSearchUser);

            if ((this.report == null) || (this.report.FieldList == null) || (this.report.FieldList.Count <= 0))
            {
                Log.Error("Missing report template.");
                MessageBox.Show("Cannot retrieve data fields for the main report. Please contact system administrator.",
                                "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }

            // check the condition and set the GUI as read only or not
            SetMainReportReadOnly();
        }
        public void ViewCaseSlides(CaseListItem item)
        {
            // This must be called only if Item has slides
            //
            // This try-catch clause is for Aperio system integration getting/displaying (invoking ImageScope.exe) list of slides based on HL7 feed from scanner system.
            // Note: .sys extension must be assigned to ImageScope in Windows Explorer
            try
            {
                // set constants
                // string progPath = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86);
                string fileSpec; // = "\\Vista\\Imaging\\Telepathology\\Vendor\\Aperio\\CaseSlides.sis";
                string filePathToInvokeExe;
                string slideTitle = "";

                    // show case slides (if any) in viewer application
                    fileSpec = "C:\\Temp\\CaseSlides.sis";

                    slideTitle = "    <Title>";
                    slideTitle += item.PatientSensitive ? "<Sensitive Patient>," : (item.PatientName + "," + item.PatientID + ",");
                    slideTitle += item.AccessionNumber + "," + item.StudyDateTime + "; @";

                    // get Slides info
                    MainViewModel viewModel = (MainViewModel)DataContext;
                    CaseSlideList slideList = viewModel.DataSource.GetCaseSlidesInfo(item.CaseURN);
                    if (slideList.Items.Count > 0)
                    {
                        string dotSisTxt = "<SIS>\n  <CloseAllImages />\n";

                        foreach (CaseSlide cSlide in slideList.Items)
                        {
                            // compose one image entry
                            dotSisTxt += "  <Image>\n" + "    <URL>" + cSlide.Url + "</URL>\n";
                            dotSisTxt += slideTitle + cSlide.SlideNumber + " " + cSlide.ZoomFactor + "</Title>\n";
                            dotSisTxt += "    <Authtok>Basic VmlzdEE6VGVsZXBhdGgxMjMh</Authtok>\n  </Image>\n";
                        }
                        dotSisTxt += "</SIS>\n";

                        // (over)write .sis file for ImageScope
                        try
                        {
                            if (File.Exists(fileSpec))
                            {
                                File.Delete(fileSpec);
                            }

                            // Create a file to write to.
                            using (StreamWriter sw = File.CreateText(fileSpec))
                            {
                                sw.Write(dotSisTxt);
                                sw.Close();
                            }

                        }
                        catch (Exception ex)
                        {
                            Log.Error("Error writing Slide info for case " + item.CaseURN + " of site: " + item.SiteAbbr + ", acc#: " + item.AccessionNumber + " -- " + ex);
                            throw new Exception("Error writing " + fileSpec + " to local storage.");
                        }
                        // invoke ImageScope with .sys file
                        filePathToInvokeExe = @fileSpec;
                        System.Diagnostics.Process.Start(filePathToInvokeExe);

                        Log.Info("Viewing slides for case " + item.CaseURN + " of site: " + item.SiteAbbr + ", acc#: " + item.AccessionNumber);
                        ActiveViewer = true;
                    }

            }
            catch (Exception ex)
            {
                Log.Error("Could not process patient/case data and launch Aperio ImageScope.", ex);
                MessageBox.Show("Could not process case slide data and launch Aperio ImageScope.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }