private void OnShelfClosed(object sender, ClosedEventArgs e) { // We need to cache the owner DesktopWindow (_desktopWindow) because this tool is an // ImageViewer tool, disposed when the viewer component is disposed. Shelves, however, // exist at the DesktopWindow level and there can only be one of each type of shelf // open at the same time per DesktopWindow (otherwise things look funny). Because of // this, we need to allow this event handling method to be called after this tool has // already been disposed (e.g. viewer workspace closed), which is why we store the // _desktopWindow variable. //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; request.FilePaths = _filePaths; request.Recursive = false; client.Import(request); client.Close(); } catch { client.Abort(); throw; } _shelf.Closed -= OnShelfClosed; _shelf = null; }
private void ImportFiles() { LocalDataStoreServiceClient client = new LocalDataStoreServiceClient(); try { client.Open(); FileImportRequest request = new FileImportRequest(); request.FilePaths = new string[] { _tempFileDirectory }; request.Recursive = true; request.FileImportBehaviour = FileImportBehaviour.Move; client.Import(request); client.Close(); } catch { client.Abort(); throw; } }
/// <summary> /// Imports the given dicom files into the local storage /// </summary> /// <param name="dicomFiles"></param> protected void ImportDicomFiles(IEnumerable <string> dicomFiles) { try { LocalDataStoreServiceClient client = new LocalDataStoreServiceClient(); client.Open(); try { FileImportRequest request = new FileImportRequest(); request.BadFileBehaviour = BadFileBehaviour.Move; request.FileImportBehaviour = FileImportBehaviour.Move; request.FilePaths = dicomFiles; request.Recursive = false; request.IsBackground = true; client.Import(request); client.Close(); } catch (Exception ex) { client.Abort(); Platform.Log(LogLevel.Error, ex, "Failed to import Grid files into the local storage"); throw; } } catch (Exception e) { Platform.Log(LogLevel.Error, e, "Failed to import Grid files into the local storage"); try { foreach (string file in dicomFiles) { File.Delete(file); } } catch (Exception ex) { Platform.Log(LogLevel.Error, ex, "Failed to remove temp Grid files"); } throw; } }
protected void ImportDicomFiles(IEnumerable<string> dicomFiles) { try { LocalDataStoreServiceClient client = new LocalDataStoreServiceClient(); client.Open(); try { FileImportRequest request = new FileImportRequest(); request.BadFileBehaviour = BadFileBehaviour.Move; request.FileImportBehaviour = FileImportBehaviour.Move; request.FilePaths = dicomFiles; request.Recursive = false; request.IsBackground = true; client.Import(request); client.Close(); } catch (Exception) { client.Abort(); throw; } } catch (Exception e) { Platform.Log(LogLevel.Error, e, "Failed to import Grid files into the local storage"); try { foreach (string file in dicomFiles) { File.Delete(file); } } catch (Exception ex) { Platform.Log(LogLevel.Error, ex, "Failed to remove temp Grid files"); } throw; } }
private bool SendAnnotationsToLocalStorageAndPacs(List <aim_dotnet.Annotation> annotations) { var model = new DcmModel(); var instanceInfos = new Dictionary <string, string>(); foreach (var annotation in annotations) { var tempFileName = System.IO.Path.GetTempFileName(); try { model.WriteAnnotationToFile(annotation, tempFileName); } catch (Exception ex) { Platform.Log(LogLevel.Error, "Failed to save annotation to temp file.", ex); try { System.IO.File.Delete(tempFileName); } catch { } continue; } var annFile = new DicomFile(tempFileName); annFile.Load(DicomReadOptions.Default | DicomReadOptions.DoNotStorePixelDataInDataSet); var annSopInstanceUid = annFile.DataSet[DicomTags.SopInstanceUid].GetString(0, string.Empty); annFile = null; instanceInfos.Add(annSopInstanceUid, tempFileName); } model = null; if (instanceInfos.Count < 1) { return(false); } var imageAeTitle = string.Empty; var imageSopProvider = ImageViewer.SelectedPresentationImage as IImageSopProvider; if (imageSopProvider != null) { var localSopDataSource = imageSopProvider.ImageSop.DataSource as ILocalSopDataSource; //NativeDicomObject as DicomFile; if (localSopDataSource != null) { imageAeTitle = localSopDataSource.File.SourceApplicationEntityTitle.Trim("\n\r".ToCharArray()); } } using (var localClient = new LocalDataStoreServiceClient()) { try { localClient.Open(); var request = new FileImportRequest(); request.BadFileBehaviour = BadFileBehaviour.Delete; request.FileImportBehaviour = FileImportBehaviour.Move; var filePaths = new List <string>(); foreach (var instanceInfo in instanceInfos) { var annSopInstanceUid = instanceInfo.Key; var tempFileName = instanceInfo.Value; filePaths.Add(tempFileName); if (!string.IsNullOrEmpty(imageAeTitle)) { lock (_mapLock) _sopInstanceUidToAeTitle.Add(annSopInstanceUid, imageAeTitle); } } request.FilePaths = filePaths.ToArray(); request.IsBackground = true; request.Recursive = false; localClient.Import(request); localClient.Close(); } catch (Exception ex) { localClient.Abort(); Platform.Log(LogLevel.Error, ex); DesktopWindow.ShowMessageBox("Failed to store your annotation(s).", "Annotation Import Error", MessageBoxActions.Ok); return(false); } } return(true); }
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); } }
private bool SendAnnotationsToLocalStorageAndPacs(List <aim_dotnet.Annotation> annotations) { // NOTE: This code assumes that all images came from the same server. // 0. Save each annotation to a temp DICOM file DcmModel model = new DcmModel(); // Map of InstanceUID=>fileName Dictionary <string, string> instanceInfos = new Dictionary <string, string>(); foreach (aim_dotnet.Annotation annotation in annotations) { // Save annotation to a temp file first string tempFileName = System.IO.Path.GetTempFileName(); try { model.WriteAnnotationToFile(annotation, tempFileName); } catch (Exception ex) { Platform.Log(LogLevel.Error, "Failed to save annotation to temp file.", ex); try { System.IO.File.Delete(tempFileName); } catch { } continue; } // Get SOP Instance UID of our annotation DicomFile annFile = new DicomFile(tempFileName); annFile.Load(DicomReadOptions.Default | DicomReadOptions.DoNotStorePixelDataInDataSet); string annSopInstanceUid = annFile.DataSet[DicomTags.SopInstanceUid].GetString(0, string.Empty); annFile = null; instanceInfos.Add(annSopInstanceUid, tempFileName); } model = null; if (instanceInfos.Count < 1) { return(false); // Save failed } // Get AE Title for remote storage. NOTE: we use AE Title of the first image for all images string imageAeTitle = string.Empty; IImageSopProvider imageSopProvider = this.ImageViewer.SelectedPresentationImage as IImageSopProvider; if (imageSopProvider != null) { //imageAeTitle = imageSopProvider.ImageSop[DicomTags.SourceApplicationEntityTitle].GetString(0, string.Empty); ILocalSopDataSource localSopDataSource = imageSopProvider.ImageSop.DataSource as ILocalSopDataSource; //NativeDicomObject as DicomFile; if (localSopDataSource != null) { imageAeTitle = localSopDataSource.File.SourceApplicationEntityTitle.Trim("\n\r".ToCharArray()); } } // 1. Import into the local storage using (LocalDataStoreServiceClient localClient = new LocalDataStoreServiceClient()) { try { localClient.Open(); FileImportRequest request = new FileImportRequest(); request.BadFileBehaviour = BadFileBehaviour.Delete; request.FileImportBehaviour = FileImportBehaviour.Move; List <string> filePaths = new List <string>(); foreach (KeyValuePair <string, string> instanceInfo in instanceInfos) { string annSopInstanceUid = instanceInfo.Key; string tempFileName = instanceInfo.Value; filePaths.Add(tempFileName); // Store destination AE title for the annotaion if (!string.IsNullOrEmpty(imageAeTitle)) { lock (_mapLock) _sopInstanceUidToAeTitle.Add(annSopInstanceUid, imageAeTitle); } } request.FilePaths = filePaths.ToArray(); request.IsBackground = true; request.Recursive = false; localClient.Import(request); localClient.Close(); } catch (Exception ex) { localClient.Abort(); Platform.Log(LogLevel.Error, ex); this.DesktopWindow.ShowMessageBox("Failed to store your annotation(s).", "Annotation Import Error", MessageBoxActions.Ok); return(false); } } // 2. Saving to PACS happens after the SOP Instance is imported (OnSopInstanceImported) return(true); }
/// <summary> /// Called by the framework when the user clicks the "apply" menu item or toolbar button. /// </summary> public void Edit() { _component = new DicomEditorComponent(); List<string> filePaths = new List<string>(); // Loop through all items in clipboard (code from CC forum) foreach (IClipboardItem item in this.Context.SelectedClipboardItems) { List<IPresentationImage> queue = new List<IPresentationImage>(); if (item.Item is IPresentationImage) Enqueue(queue, (IPresentationImage)item.Item); else if (item.Item is IDisplaySet) Enqueue(queue, (IDisplaySet)item.Item); else if (item.Item is IImageSet) Enqueue(queue, (IImageSet)item.Item); foreach (IPresentationImage image in queue) { if (image is IImageSopProvider) { ImageSop imageSop = ((IImageSopProvider)image).ImageSop; ILocalSopDataSource localsource = (ILocalSopDataSource)imageSop.DataSource; // Load each image path into dicom editor, and record path in array for later, re-import _component.Load(localsource.SourceMessage); filePaths.Add(localsource.Filename); } } } //common to both contexts 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(); //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; request.FilePaths = filePaths; request.Recursive = false; client.Import(request); client.Close(); } catch { client.Abort(); throw; } }
/// <summary> /// Called by the framework when the user clicks the "apply" menu item or toolbar button. /// </summary> public void Edit() { _component = new DicomEditorComponent(); List <string> filePaths = new List <string>(); // Loop through all items in clipboard (code from CC forum) foreach (IClipboardItem item in this.Context.SelectedClipboardItems) { List <IPresentationImage> queue = new List <IPresentationImage>(); if (item.Item is IPresentationImage) { Enqueue(queue, (IPresentationImage)item.Item); } else if (item.Item is IDisplaySet) { Enqueue(queue, (IDisplaySet)item.Item); } else if (item.Item is IImageSet) { Enqueue(queue, (IImageSet)item.Item); } foreach (IPresentationImage image in queue) { if (image is IImageSopProvider) { ImageSop imageSop = ((IImageSopProvider)image).ImageSop; ILocalSopDataSource localsource = (ILocalSopDataSource)imageSop.DataSource; // Load each image path into dicom editor, and record path in array for later, re-import _component.Load(localsource.SourceMessage); filePaths.Add(localsource.Filename); } } } //common to both contexts 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(); //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; request.FilePaths = filePaths; request.Recursive = false; client.Import(request); client.Close(); } catch { client.Abort(); throw; } }