Beispiel #1
0
 public OnCompleteDicomFileEventArgs(string filename, ResultDicomFile resultDicomFile, bool isMatched, int searchedFileCount, int matchedFileCount)
 {
     this.Filename          = filename;
     this.ResultDicomFile   = resultDicomFile;
     this.IsMatched         = isMatched;
     this.SearchedFileCount = searchedFileCount;
     this.MatchedFileCount  = matchedFileCount;
 }
Beispiel #2
0
        private void DoSearch(bool searchInResults = false)
        {
            SearchCriteria criteria = new SearchCriteria
            {
                SearchPath        = SearchPath,
                FileTypes         = FileTypes,
                SearchSopClassUid = SopClassUid,
                SearchTag         = Tag,
                SearchText        = SearchText,
                CaseSensitive     = CaseSensitive,
                WholeWord         = WholeWord,
                IncludeSubfolders = IncludeSubfolders,
                SearchInResults   = searchInResults, // from parameter
                SearchThreads     = SearchThreads
            };

            Util.PushToList(SearchPath, SearchPathHistory, CurrentConfiguration.HistoryCapacity);
            Util.PushToList(FileTypes, FileTypesHistory, CurrentConfiguration.HistoryCapacity);
            Util.PushToList(SopClassUid, SopClassUidHistory, CurrentConfiguration.HistoryCapacity);
            Util.PushToList(Tag, DicomTagHistory, CurrentConfiguration.HistoryCapacity);
            Util.PushToList(SearchText, SearchTextHistory, CurrentConfiguration.HistoryCapacity);

            CurrentConfiguration.SearchCriteria     = criteria;
            CurrentConfiguration.SearchPathHistory  = new List <string>(SearchPathHistory);
            CurrentConfiguration.FileTypesHistory   = new List <string>(FileTypesHistory);
            CurrentConfiguration.SopClassUidHistory = new List <string>(SopClassUidHistory);
            CurrentConfiguration.DicomTagHistory    = new List <string>(DicomTagHistory);
            CurrentConfiguration.SearchTextHistory  = new List <string>(SearchTextHistory);

            configurationService.Save();

            MatchedFileList.Clear();
            SelectedMatchedFile = null;

            this.TotalFileCount    = 0;
            this.SearchedFileCount = 0;
            this.MatchedFileCount  = 0;

            this.CanCancel = true;
            this.CanSearch = false;
            this.CanExport = false;

            tokenSource = new CancellationTokenSource();

            // todo: move to SearchAsync()
            Task.Run(() =>
            {
                this.searchService.Search(criteria, tokenSource);
            }, tokenSource.Token);
        }
Beispiel #3
0
        private void SearchInDicomFile(string filePath)
        {
            ResultDicomFile resultDicomFile = null;
            bool            isMatched       = false;

            try
            {
                OnLoadDicomFile?.Invoke(this, new OnLoadDicomFileEventArgs(filePath));

                DicomFile dicomFile = DicomFile.Open(filePath, FileReadOption.ReadLargeOnDemand, 16 * 1024);

                IList <ResultDicomItem> resultDicomItems = null;
                //new DicomDatasetWalker(dicomFile.Dataset).Walk(new DatasetWalker());

                string   patientName  = string.Empty;
                string   sopClassName = string.Empty;
                DicomUID sopClassUID  = null;


                if (dicomFile.Dataset.TryGetSingleValue <DicomUID>(DicomTag.SOPClassUID, out sopClassUID))
                {
                    // compare the sop class uid
                    if (!string.IsNullOrWhiteSpace(criteria.SearchSopClassUid) && sopClassUID.UID != criteria.SearchSopClassUid)
                    {
                        return;
                    }
                    sopClassName = sopClassUID?.Name;
                }
                dicomFile.Dataset.TryGetString(DicomTag.PatientName, out patientName);

                CompareDicomTagAndValue(dicomFile.FileMetaInfo, ref resultDicomItems);
                CompareDicomTagAndValue(dicomFile.Dataset, ref resultDicomItems);

                resultDicomFile = new ResultDicomFile(filePath, sopClassName, sopClassUID?.UID, patientName,
                                                      resultDicomItems);
                isMatched = resultDicomItems?.Count > 0;
                if (isMatched)
                {
                    matchedFilenameList.Add(filePath);
                    Interlocked.Increment(ref matchedFileCount);
                }
            }
            catch (Exception ex)
            {
                //event for error logging
                //throw;

                if (ex is DicomDataException) // normally caused by incorrect Dicom file format
                {
                    logger.Error(ex, $"'{filePath}' is not a valid DICOM file.");
                }
                else
                {
                    logger.Warn(ex);
                }
            }
            finally
            {
                Interlocked.Increment(ref searchedFileCount);
                OnCompletDicomFile?.Invoke(this,
                                           new OnCompleteDicomFileEventArgs(filePath, resultDicomFile, isMatched, searchedFileCount,
                                                                            matchedFileCount));
            }
        }