Exemple #1
0
        // Note: you may change the name of the 'Apply' method as desired, but be sure to change the
        // corresponding parameter in the MenuAction and ButtonAction attributes

        /// <summary>
        /// Called by the framework when the user clicks the "apply" menu item or toolbar button.
        /// </summary>
        public void Apply()
        {
            _component = new DicomEditorComponent();

            // Loop through all selected studies
            foreach (StudyItem selectedstudy in this.Context.SelectedStudies)
            {
                string studyUID     = selectedstudy.StudyInstanceUid;
                int    numberOfSops = LocalStudyLoader.Start(new StudyLoaderArgs(studyUID, null));

                // Loop through all images in study
                for (int i = 0; i < numberOfSops; ++i)
                {
                    Sop imageSop = LocalStudyLoader.LoadNextSop();
                    ILocalSopDataSource localsource = (ILocalSopDataSource)imageSop.DataSource;
                    // Load images into dicom editor
                    _component.Load(localsource.SourceMessage);
                    // Keep track of file paths for later re-importation
                    _filePaths.Add(localsource.Filename);
                }
                // This code deletes the study from the database, so that when it is re-imported the changed fields
                // will appear
                using (IDataStoreStudyRemover studyRemover = DataAccessLayer.GetIDataStoreStudyRemover())
                {
                    studyRemover.RemoveStudy(selectedstudy.StudyInstanceUid);
                }
            }
            // Launch Dicom Editor Shelf
            if (_shelf != null)
            {
                _shelf.Activate();
            }
            else
            {
                _shelf = ApplicationComponent.LaunchAsShelf(
                    this.Context.DesktopWindow,
                    _component,
                    "Dicom Editor",
                    "Dicom Editor",
                    ShelfDisplayHint.DockRight | ShelfDisplayHint.DockAutoHide);
                _shelf.Closed += OnShelfClosed;
            }

            _component.UpdateComponent();
        }
        private void Rename(IBackgroundTaskContext context)
        {
            try
            {
                _tempPath = String.Format(".\\temp\\{0}", Path.GetRandomFileName());
                Directory.CreateDirectory(_tempPath);
                _tempPath = Path.GetFullPath(_tempPath);

                context.ReportProgress(new BackgroundTaskProgress(0, "Renaming Study"));

                int numberOfSops = LocalStudyLoader.Start(new StudyLoaderArgs(this.Context.SelectedStudy.StudyInstanceUid, null));
                if (numberOfSops <= 0)
                {
                    return;
                }

                for (int i = 0; i < numberOfSops; ++i)
                {
                    string message = String.Format("{0} of {1}", i.ToString(), numberOfSops.ToString());
                    Platform.Log(LogLevel.Info, message);

                    Sop sop = LocalStudyLoader.LoadNextSop();
                    ILocalSopDataSource localsource = (ILocalSopDataSource)sop.DataSource;
                    string    progressMessage       = localsource.Filename.ToString();
                    DicomFile file = ((ILocalSopDataSource)sop.DataSource).File;

                    //renamer.Anonymize(file);

                    StudyData originalData = new StudyData();
                    file.DataSet.LoadDicomFields(originalData);

                    originalData.PatientId         = _component.PatientId;
                    originalData.PatientsBirthDate = _component.PatientsBirthDate;
                    originalData.PatientsNameRaw   = _component.PatientsName;
                    originalData.AccessionNumber   = _component.AccessionNumber;
                    originalData.StudyDate         = _component.StudyDate;
                    originalData.StudyDescription  = _component.StudyDescription;

                    file.DataSet.SaveDicomFields(originalData);

                    file.Save(String.Format("{0}\\{1}.dcm", _tempPath, i));

                    int progressPercent = (int)Math.Floor((i + 1) / (float)numberOfSops * 100);
                    //string progressMessage = String.Format(SR.MessageAnonymizingStudy, _tempPath);

                    context.ReportProgress(new BackgroundTaskProgress(progressPercent, progressMessage));

                    // This code deletes the study from the database, so that when it is re-imported the changed fields
                    // will appear
                }


                using (IDataStoreStudyRemover studyRemover = DataAccessLayer.GetIDataStoreStudyRemover())
                {
                    studyRemover.RemoveStudy(this.Context.SelectedStudy.StudyInstanceUid);
                }

                //trigger an import of the Renamed files.
                LocalDataStoreServiceClient client = new LocalDataStoreServiceClient();
                client.Open();
                try
                {
                    FileImportRequest request = new FileImportRequest();
                    request.BadFileBehaviour    = BadFileBehaviour.Move;
                    request.FileImportBehaviour = FileImportBehaviour.Move;
                    List <string> filePaths = new List <string>();
                    filePaths.Add(_tempPath);
                    request.FilePaths = filePaths;
                    request.Recursive = true;
                    client.Import(request);
                    client.Close();

                    //  Need to refresh study list in order for changed values to appear
                    //  This method doesn't work.  Need to manually click 'Search' again
                    //this.Context.RefreshStudyList();
                }
                catch
                {
                    client.Abort();
                    throw;
                }
                //this.Context.RefreshStudyList();
                context.Complete();
            }
            catch (Exception e)
            {
                context.Error(e);
            }
        }