protected virtual IArgumentHintResolver BuildArgumentHints(IEnumerable <IPresentationImage> images) { List <IArgumentHint> hints = new List <IArgumentHint>(); if (images != null) { List <string> filenames = new List <string>(); foreach (IPresentationImage image in images) { if (image is IImageSopProvider) { IImageSopProvider imageSopProvider = (IImageSopProvider)image; hints.Add(new SopArgumentHint(imageSopProvider.Sop)); if (imageSopProvider.Sop.DataSource is ILocalSopDataSource) { ILocalSopDataSource localSopDataSource = (ILocalSopDataSource)imageSopProvider.Sop.DataSource; filenames.Add(localSopDataSource.Filename); } } } hints.Add(new FileSetArgumentHint(filenames)); } return(new ArgumentHintResolver(hints)); }
private void TaskTerminated(object sender, BackgroundTaskTerminatedEventArgs args) { if (_dicomPrintSession != null) { _dicomPrintSession.Dispose(); _dicomPrintSession = null; } if (_selectPresentationsInformations != null) { foreach (var item in _selectPresentationsInformations) { IImageSopProvider imageSopProvider = item.Image as IImageSopProvider; ILocalSopDataSource localSource = null; if (imageSopProvider != null) { localSource = imageSopProvider.ImageSop.DataSource as ILocalSopDataSource; } item.Dispose(); if (localSource != null) { localSource.Dispose(); } } _dicomPrinter = null; } }
public SopDataSourceStudyItem(ILocalSopDataSource sopDataSource) { _filename = sopDataSource.Filename; using (Sop sop = new Sop(sopDataSource)) { _sopReference = sop.CreateTransientReference(); } }
public void Save() { string path; using (FolderBrowserDialog dialog = new FolderBrowserDialog()) { dialog.Description = "Choose destination folder for saving DICOM images"; if (DialogResult.OK == dialog.ShowDialog()) { path = dialog.SelectedPath; } else { return; } } 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; File.Copy(localsource.Filename, path + "\\" + imageSop[DicomTags.SopInstanceUid] + ".dcm"); } } } }
protected virtual IArgumentHintResolver BuildArgumentHints(IPresentationImage image) { List <IArgumentHint> hints = new List <IArgumentHint>(); if (image is IImageSopProvider) { IImageSopProvider imageSopProvider = (IImageSopProvider)image; hints.Add(new SopArgumentHint(imageSopProvider.Sop)); if (imageSopProvider.Sop.DataSource is ILocalSopDataSource) { ILocalSopDataSource localSopDataSource = (ILocalSopDataSource)imageSopProvider.Sop.DataSource; hints.Add(new FileArgumentHint(localSopDataSource.Filename)); } } return(new ArgumentHintResolver(hints)); }
// 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(); }
public void Activate() { if (this.SelectedPresentationImage == null) { return; } IImageSopProvider image = this.SelectedPresentationImage as IImageSopProvider; if (image == null) { return; } ILocalSopDataSource localSource = image.ImageSop.DataSource as ILocalSopDataSource; if (localSource == null) { base.Context.DesktopWindow.ShowMessageBox(SR.MessageUnableToLocateNonLocalImage, MessageBoxActions.Ok); return; } System.Diagnostics.Process.Start("explorer.exe", "/n,/select," + localSource.Filename); }
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; } }