/// <summary>
 /// Clears all data related to the active study.
 /// </summary>
 private void Clear()
 {
     _tags         = "";
     _originalTags = "";
     _activeStudy  = null;
     _searchResults.Items.Clear();
     _selectedSearchResult = null;
 }
        /// <summary>
        /// Queries local datastore for studies based on specified search function.
        /// </summary>
        private void QueryStudies(string query, Converter <string, KeyValuePair <string, double>[]> searchFunc)
        {
            // if there is a previous task that may still be running, disconnect it so we effectively abandon it
            if (_queryStudiesTask != null)
            {
                _queryStudiesTask.ProgressUpdated -= OnQueryStudiesProgressUpdate;
            }

            // clear existing items
            _searchResults.Items.Clear();

            // create new task to query similar studies asynchronously so as not to block UI
            _queryStudiesTask = new BackgroundTask(
                delegate(IBackgroundTaskContext ctx)
            {
                KeyValuePair <string, double>[] similarStudyUids = searchFunc(query);
                foreach (KeyValuePair <string, double> kvp in similarStudyUids)
                {
                    string studyUid = kvp.Key;
                    double score    = kvp.Value;

                    QueryParameters queryParams = new QueryParameters();
                    queryParams.Add("PatientsName", "");
                    queryParams.Add("PatientId", "");
                    queryParams.Add("AccessionNumber", "");
                    queryParams.Add("StudyDescription", "");
                    queryParams.Add("ModalitiesInStudy", "");
                    queryParams.Add("StudyDate", "");
                    queryParams.Add("StudyInstanceUid", studyUid);

                    // currently only the local dicom store is supported
                    StudyItemList similarStudyItems = ImageViewerComponent.FindStudy(queryParams, null, "DICOM_LOCAL");

                    // should only ever be one result at most
                    // if zero results, it means the study exists in the tag database but not in the local dicom store
                    StudyItem studyItem = CollectionUtils.FirstElement(similarStudyItems);
                    if (studyItem != null)
                    {
                        StudyTableEntry entry = new StudyTableEntry(studyItem, MakeTagsString(_database.GetTagsForStudy(studyUid)), score);
                        ctx.ReportProgress(new StudyQueryProgress(entry));
                    }
                }
            }, false);

            _queryStudiesTask.ProgressUpdated += OnQueryStudiesProgressUpdate;
            _queryStudiesTask.Run();
        }
 public StudyQueryProgress(StudyTableEntry entry)
 {
     _entry = entry;
 }