예제 #1
0
        private void InitDicomPrint(
            IDesktopWindow deskTopWindow,
            List <ISelectPresentationsInformation> selectPresentations,
            int tilecount,
            bool isAllPages,
            bool isDelete)
        {
            try
            {
                if (_dicomPrintManager == null)
                {
                    _dicomPrintManager             = new DicomPrintManager(deskTopWindow, this);
                    _dicomPrintManager.CloseShelf += ClosePrintManager;
                }

                if (_dicomPrintManager.IsPrinting)
                {
                    DesktopWindow.ShowMessageBox("正在打印....,请稍后", MessageBoxActions.Ok);
                    return;
                }
                _dicomPrintManager.Show();
                _dicomPrintManager.Print(selectPresentations, this.DicomPrinter.Item, tilecount, isAllPages, isDelete);
            }
            catch (Exception exception)
            {
                ExceptionHandler.Report(exception, deskTopWindow);
            }
        }
        private bool SendAnnotationsToGrid(List <aim_dotnet.Annotation> annotations)
        {
            if (annotations == null || annotations.Count == 0)
            {
                return(true);
            }

            var xmlAnnotations = new Dictionary <string, string>();
            var xmlModel       = new XmlModel();

            foreach (var annotation in annotations)
            {
                try
                {
                    xmlAnnotations.Add(annotation.UniqueIdentifier, xmlModel.WriteAnnotationToXmlString(annotation));
                }
                catch (Exception ex)
                {
                    Platform.Log(LogLevel.Error, ex, "Failed to convert annotation to xml.");
                }
            }
            xmlModel = null;

            // Send Annotations to AIM Service
            if (xmlAnnotations.Count > 0)
            {
                BackgroundTask task = null;
                try
                {
                    task = new BackgroundTask(BackgroundSendAnnotationsToAimService, false, xmlAnnotations);
                    ProgressDialog.Show(task, DesktopWindow, true);
                    return(true);
                }
                catch (Exception e)
                {
                    Platform.Log(LogLevel.Error, e, "Failed to send annotation(s) to the AIM data service");
                    DesktopWindow.ShowMessageBox("Failed to send annotation(s) to the AIM data service. See log for details.", MessageBoxActions.Ok);
                }
                finally
                {
                    if (task != null)
                    {
                        task.Dispose();
                    }
                }
            }

            return(false);
        }
예제 #3
0
        public void Accept(IDisplaySet displaySet, TileCollection tiles, bool isAllPage, bool printedDeleteImage)
        {
            if (_dicomPrinter == null)
            {
                DesktopWindow.ShowMessageBox("请选择打印机", MessageBoxActions.Ok);
                return;
            }

            if (displaySet != null && displaySet.PresentationImages.Count != 0)
            {
                List <ISelectPresentationsInformation> selectPresentations =
                    new List <ISelectPresentationsInformation>();
                if (isAllPage)
                {
                    for (int i = 0; i < displaySet.PresentationImages.Count; i++)
                    {
                        var image = ClonePresentationImage(displaySet.PresentationImages[i]);

                        int       index           = i % tiles.Count;
                        Rectangle clientRectangle = tiles[index].ClientRectangle;
                        var       select          = new SelectPresentionInformation(image, clientRectangle);
                        select.NormalizedRectangle = tiles[index].NormalizedRectangle;
                        selectPresentations.Add(select);
                    }
                }
                else
                {
                    foreach (PrintViewTile tile in tiles)
                    {
                        if (tile.PresentationImage == null)
                        {
                            continue;
                        }
                        var       image           = ClonePresentationImage(tile.PresentationImage);
                        Rectangle clientRectangle = tile.ClientRectangle;
                        var       select          = new SelectPresentionInformation(image, clientRectangle);
                        select.NormalizedRectangle = tile.NormalizedRectangle;
                        selectPresentations.Add(select);
                    }
                }

                InitDicomPrint(DesktopWindow, selectPresentations, tiles.Count, isAllPage, printedDeleteImage);
            }
        }
        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);
        }
        public void CreateAnnotation()
        {
            if (!CreateAnnotationEnabled)
            {
                return;
            }

            if (base.HasValidationErrors)
            {
                Platform.Log(LogLevel.Info, "Cannot create annotation. Validation error(s): " + Validation.GetErrorsString(this));
                ShowValidation(true);
                return;
            }

            if (!LocalDataStoreActivityMonitor.IsConnected)
            {
                DesktopWindow.ShowMessageBox("Failed to save annotation. Not connected to the local data store. Is workstation service running?", MessageBoxActions.Ok);
                return;
            }

            // Get new annotations
            List <IGraphic> annotationsGraphic;
            var             annotations = CreateAnnotationsFromUserInput(out annotationsGraphic);

            _annotationGraphics = annotationsGraphic;
            if (annotations.Count == 0)
            {
                Platform.Log(LogLevel.Warn, "CreateAnnotation resulted in no annotations being created");
                return;
            }

            EventsHelper.Fire(AnnotationCreating, this, EventArgs.Empty);

            var isAnyOperationPerformed = false;

            if (AimSettings.Default.StoreXmlAnnotationsLocally)
            {
                var destinationFolder = AimSettings.Default.ActualAnnotationStoreFolder;
                try
                {
                    if (!System.IO.Directory.Exists(destinationFolder))
                    {
                        System.IO.Directory.CreateDirectory(destinationFolder);
                    }

                    var annFiles = AimHelpers.WriteXmlAnnotationsToFolder(annotations, destinationFolder);
                    if (annotations.Count != annFiles.Length)
                    {
                        Platform.Log(LogLevel.Error, "Only {0} annotations(s) out of {1} written to \"{0}\"", annFiles.Length, annotations.Count, destinationFolder);
                    }

                    isAnyOperationPerformed = annFiles.Length > 0;
                }
                catch (Exception ex)
                {
                    Platform.Log(LogLevel.Error, ex, "Failed to store annotations to local folder \"{0}\"", destinationFolder);
                }
            }

            if (AimSettings.Default.SendNewXmlAnnotationsToGrid)
            {
                if (SendAnnotationsToGrid(annotations))
                {
                    isAnyOperationPerformed = true;
                }
                else
                {
                    Platform.Log(LogLevel.Error, "Failed to send annotations to the caGrid");
                }
            }

            if (LocalDataStoreActivityMonitor.IsConnected)
            {
                isAnyOperationPerformed = SendAnnotationsToLocalStorageAndPacs(annotations) || isAnyOperationPerformed;
            }
            else
            {
                DesktopWindow.ShowMessageBox("Failed to save annotation. Not connected to the local data store. Is workstation service running?", MessageBoxActions.Ok);
            }

            if (isAnyOperationPerformed)
            {
                UpdateImagesWithProperAimGraphic(annotations, annotationsGraphic);

                // Reset all controls on the template
                //ResetAnnotationData();
            }
        }