Exemple #1
0
        public static void InsertDefaultImages(string prefix, int max, int padding, Configuration configuration)
        {
            MedicalWorkstationConfigurationDemo.UI.MainForm.StoreClientSessionProxy proxy = null;
            InstanceCStoreCommand   cmd   = null;
            IStorageDataAccessAgent agent = DataAccessFactory.GetInstance(new StorageDataAccessConfigurationView(configuration, DicomDemoSettingsManager.ProductNameStorageServer, null)).CreateDataAccessAgent <IStorageDataAccessAgent>();

            string formatString = BuildDefaultImageFormatString(padding);

            for (int i = 1; i < max + 1; i++)
            {
                using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(string.Format(formatString, prefix, i)))
                {
                    using (DicomDataSet ds = new DicomDataSet())
                    {
                        ds.Load(stream, DicomDataSetLoadFlags.None);

                        proxy = new MedicalWorkstationConfigurationDemo.UI.MainForm.StoreClientSessionProxy();
                        cmd   = new InstanceCStoreCommand(proxy, ds, agent);

                        proxy.AffectedSOPInstance = ds.GetValue <string>(DicomTag.SOPInstanceUID, string.Empty);
                        proxy.AbstractClass       = ds.GetValue <string>(DicomTag.SOPClassUID, string.Empty);

                        ds.InsertElementAndSetValue(DicomTag.MediaStorageSOPInstanceUID, proxy.AffectedSOPInstance);
                        cmd.Execute();
                        ImageCountUpdate();
                    }
                }
            }
        }
        public static void InsertDefaultImages(string prefix, int max, Configuration configuration)
        {
            MedicalWorkstationConfigurationDemo.UI.MainForm.StoreClientSessionProxy proxy = null;
            InstanceCStoreCommand   cmd   = null;
            IStorageDataAccessAgent agent = DataAccessFactory.GetInstance(new StorageDataAccessConfigurationView(configuration, DicomDemoSettingsManager.ProductNameStorageServer, null)).CreateDataAccessAgent <IStorageDataAccessAgent>();

            string formatString = Path.Combine(DemosGlobal.ImagesFolder, prefix);

            for (int i = 1; i < max + 1; i++)
            {
                using (DicomDataSet ds = new DicomDataSet())
                {
                    string fileName = string.Format(formatString, i);

                    if (File.Exists(fileName))
                    {
                        ds.Load(fileName, DicomDataSetLoadFlags.None);

                        proxy = new MedicalWorkstationConfigurationDemo.UI.MainForm.StoreClientSessionProxy();
                        cmd   = new InstanceCStoreCommand(proxy, ds, agent);

                        proxy.AffectedSOPInstance = ds.GetValue <string>(DicomTag.SOPInstanceUID, string.Empty);
                        proxy.AbstractClass       = ds.GetValue <string>(DicomTag.SOPClassUID, string.Empty);

                        ds.InsertElementAndSetValue(DicomTag.MediaStorageSOPInstanceUID, proxy.AffectedSOPInstance);
                        cmd.Execute();
                        ImageCountUpdate();
                    }
                }
            }
        }
        static void dbManager_ConfigureStoreCommandExport(object sender, StoreCommandEventArgs e)
        {
            try
            {
                if (ServerState.Instance.ServerService != null)
                {
                    StorageModuleConfigurationManager configManager = ServiceLocator.Retrieve <StorageModuleConfigurationManager>();

                    if (configManager.IsLoaded)
                    {
                        StorageAddInsConfiguration storageSettings = configManager.GetStorageAddInsSettings();

                        StoreCommandInitializationService.ConfigureCStoreCommand(e.Command, storageSettings.StoreAddIn);


                        // StoreCommandInitializationService.ConfigureInstanceCStoreCommand ( e.Command, storageSettings.StoreAddIn ) ;

                        InstanceCStoreCommand instanceStoreCommand = e.Command as InstanceCStoreCommand;
                        if (instanceStoreCommand != null)
                        {
                            instanceStoreCommand.InstanceConfiguration.CreateBackupForDuplicateSop     = false;
                            instanceStoreCommand.InstanceConfiguration.UpdateInstanceData              = false;
                            instanceStoreCommand.InstanceConfiguration.UpdatePatientData               = false;
                            instanceStoreCommand.InstanceConfiguration.UpdateSeriesData                = false;
                            instanceStoreCommand.InstanceConfiguration.UpdateStudyData                 = false;
                            instanceStoreCommand.InstanceConfiguration.ValidateDuplicateSopInstanceUID = false;
                        }

                        CStoreCommand storeCommand = e.Command as CStoreCommand;
                        if (storeCommand != null && storeCommand.Configuration != null)
                        {
                            storeCommand.Configuration.OtherImageFormat.Clear();
                            storeCommand.Configuration.SaveThumbnail = false;
                        }
                    }
                }
            }
            catch { }
        }
Exemple #4
0
        public static void AddDefaultImages(Configuration configGlobalPacs)
        {
            ImageCountReset();

            MainForm.StoreClientSessionProxy proxy = null;
            InstanceCStoreCommand            cmd   = null;
            IStorageDataAccessAgent          agent = DataAccessFactory.GetInstance(new StorageDataAccessConfigurationView(configGlobalPacs, DicomDemoSettingsManager.ProductNameStorageServer, null)).CreateDataAccessAgent <IStorageDataAccessAgent>();

            for (int i = 1; i < ImageCountResources + 1; i++)
            {
                using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(string.Format("CSPacsDatabaseConfigurationDemo.Resources.{0}.dcm", i)))
                {
                    using (DicomDataSet ds = new DicomDataSet())
                    {
                        ds.Load(stream, DicomDataSetLoadFlags.None);

                        proxy = new MainForm.StoreClientSessionProxy();
                        cmd   = new InstanceCStoreCommand(proxy, ds, agent);

                        proxy.AffectedSOPInstance = ds.GetValue <string>(DicomTag.SOPInstanceUID, string.Empty);
                        proxy.AbstractClass       = ds.GetValue <string>(DicomTag.SOPClassUID, string.Empty);

                        ds.InsertElementAndSetValue(DicomTag.MediaStorageSOPInstanceUID, proxy.AffectedSOPInstance);
                        cmd.Execute();

                        ImageCountUpdate();
                    }
                }
            }
#if (LEADTOOLS_V19_OR_LATER)
            InsertDefaultImages("mg", ImageCountMG, configGlobalPacs);
            InsertDefaultImages("cr", ImageCountCR, configGlobalPacs);
            InsertDefaultImages("FMX18.de", ImageCountFMX, 2, configGlobalPacs);
#endif

#if (LEADTOOLS_V20_OR_LATER)
            InsertDefaultImages("MRI.mri_", ImageCountMRI, 2, configGlobalPacs);
#endif
        }
        protected override void OnDoWork(DoWorkEventArgs e)
        {
            int count = 0;
            int imagesToExportCount   = 0;
            InstanceCStoreCommand cmd = null;

            MatchingParameterCollection matchingParamCollection;
            MatchingParameterList       matchingParamList;

            if (this.CancellationPending)
            {
                e.Cancel = true;
                return;
            }

            ExportDicomWorkerArgs args = e.Argument as ExportDicomWorkerArgs;

            if (args == null)
            {
                throw new ArgumentException("Invalid ExportDicom argument");
            }

            if (args.CreateDicomDir)
            {
                DicomDirectory = new DicomDir(args.OutputFolder);
            }

            if (args.Anonymize)
            {
                Anonymizer.BeginBatch();
            }

            try
            {
                ViewGenerator.ViewDataRow[] exportRows = (args.Rows);

                imagesToExportCount = exportRows.Length;

                foreach (ViewGenerator.ViewDataRow exportRow in exportRows)
                {
                    try
                    {
                        string rowKeyValue;
                        string rowKeyName;
                        string viewName;

                        if (this.CancellationPending)
                        {
                            e.Cancel = true;

                            return;
                        }

                        DataRow originalRow = exportRow.OriginalRow;
                        matchingParamCollection = new MatchingParameterCollection( );
                        matchingParamList       = new MatchingParameterList( );

                        matchingParamCollection.Add(matchingParamList);

                        if (string.Compare(originalRow.Table.TableName, DataTableHelper.InstanceTableName) == 0)
                        {
                            string         sSopInstanceUid = RegisteredDataRows.InstanceInfo.GetElementValue(originalRow, DicomTag.SOPInstanceUID);
                            ICatalogEntity imageInstance   = RegisteredEntities.GetInstanceEntity(sSopInstanceUid);

                            rowKeyValue = sSopInstanceUid;
                            rowKeyName  = "SOPInstanceUID";
                            viewName    = "Images";

                            matchingParamList.Add(imageInstance);
                        }
                        else if (string.Compare(originalRow.Table.TableName, DataTableHelper.SeriesTableName) == 0)
                        {
                            string         sSeriesInstanceUid = RegisteredDataRows.SeriesInfo.GetElementValue(originalRow, DicomTag.SeriesInstanceUID);
                            ICatalogEntity seriesEntity       = RegisteredEntities.GetSeriesEntity(sSeriesInstanceUid);

                            rowKeyValue = sSeriesInstanceUid;
                            rowKeyName  = "SeriesInstanceUID";
                            viewName    = "Series";

                            matchingParamList.Add(seriesEntity);
                        }
                        else if (string.Compare(originalRow.Table.TableName, DataTableHelper.StudyTableName) == 0)
                        {
                            string         sStudyInstanceUid = RegisteredDataRows.StudyInfo.GetElementValue(originalRow, DicomTag.StudyInstanceUID);
                            ICatalogEntity studyEntity       = RegisteredEntities.GetStudyEntity(sStudyInstanceUid);

                            rowKeyValue = sStudyInstanceUid;
                            rowKeyName  = "StudyInstanceUID";
                            viewName    = "Studies";

                            matchingParamList.Add(studyEntity);
                        }
                        else if (string.Compare(originalRow.Table.TableName, DataTableHelper.PatientTableName) == 0)
                        {
                            string         sPatientId    = RegisteredDataRows.PatientInfo.GetElementValue(originalRow, DicomTag.PatientID);
                            ICatalogEntity patientEntity = RegisteredEntities.GetPatientEntity(sPatientId);

                            rowKeyValue = sPatientId;
                            rowKeyName  = "PatientId";
                            viewName    = "Patients";

                            matchingParamList.Add(patientEntity);
                        }
                        else if (string.Compare(originalRow.Table.TableName, DataTableHelper.HangingProtocolTableName) == 0)
                        {
                            string         sSopInstanceUid         = RegisteredDataRows.InstanceInfo.GetElementValue(originalRow, DicomTag.SOPInstanceUID);
                            ICatalogEntity hangingProtocolInstance = RegisteredEntities.GetHangingProtocolEntity(sSopInstanceUid);

                            rowKeyValue = sSopInstanceUid;
                            rowKeyName  = "SOPInstanceUID";
                            viewName    = "Hanging Protocol";

                            matchingParamList.Add(hangingProtocolInstance);
                        }
                        else
                        {
                            throw new ApplicationException("Deleted row is not a valid DICOM format.");
                        }

                        DataSet   exportDataSet = null;
                        DataRow[] rows          = null;

                        if (string.Compare(originalRow.Table.TableName, DataTableHelper.HangingProtocolTableName) == 0 && _dataAccessAgent3 != null)
                        {
                            exportDataSet = _dataAccessAgent3.QueryHangingProtocol(matchingParamCollection);
                            rows          = exportDataSet.Tables[DataTableHelper.HangingProtocolTableName].Select();
                        }
                        else
                        {
                            exportDataSet = _dataAccessAgent.QueryCompositeInstances(matchingParamCollection);
                            rows          = exportDataSet.Tables[DataTableHelper.InstanceTableName].Select();
                        }

                        foreach (DataRow row in rows)
                        {
                            DicomDataSet dicomDataSet = RegisteredDataRows.InstanceInfo.LoadDicomDataSet(row);

                            if (args.Anonymize)
                            {
                                Anonymizer.Anonymize(dicomDataSet);
                            }

                            AddDicomBackgroundWorker.StoreClientSessionProxy proxy = new AddDicomBackgroundWorker.StoreClientSessionProxy();
                            proxy.AffectedSOPInstance = dicomDataSet.GetValue <string>(DicomTag.SOPInstanceUID, string.Empty);
                            proxy.AbstractClass       = dicomDataSet.GetValue <string>(DicomTag.SOPClassUID, string.Empty);


                            try
                            {
                                cmd = new InstanceCStoreCommand(proxy, dicomDataSet, _dataAccessAgent);

                                OnStoreCommandCreated(this, new StoreCommandEventArgs(cmd));

                                cmd.Configuration.DataSetStorageLocation = args.OutputFolder;
#if (LEADTOOLS_V19_OR_LATER)
                                cmd.Configuration.HangingProtocolLocation = args.OutputFolder;
#endif

                                string fileLocation = CStoreCommand.GetStorageFullPath(cmd.Configuration, dicomDataSet);
                                if (args.Overwrite || !File.Exists(fileLocation))
                                {
                                    // Only exporting, so do not validate SopInstance and do not add to database
                                    cmd.DoValidateSopInstance      = false;
                                    cmd.DoUpdateDatabase           = false;
                                    cmd.DoUseExternalStoreSettings = false;
                                    cmd.DataSetStored += cmd_DataSetStored;

                                    cmd.Execute();
                                }
                                else
                                {
                                    // File already exists -- it is not overwritten
                                    DataSetStoredEventArgs storedArgs = new DataSetStoredEventArgs(dicomDataSet, string.Empty, string.Empty, fileLocation);
                                    cmd_DataSetStored(this, storedArgs);
                                }
                            }
                            finally
                            {
                                if (cmd != null)
                                {
                                    cmd.DataSetStored -= cmd_DataSetStored;
                                }
                            }
                        }

                        count++;

                        ExportDicomWorkerProgressState state = new ExportDicomWorkerProgressState( );

                        state.Error               = null;
                        state.CurrentCount        = count;
                        state.ExportRow           = exportRow;
                        state.ExportedImagesCount = 1;
                        state.TotalCount          = imagesToExportCount;
                        state.RowKeyValue         = rowKeyValue;
                        state.RowKeyName          = rowKeyName;
                        state.ViewName            = viewName;

                        ReportProgress((count * 100) / exportRows.Length, state);
                    }
                    catch (Exception exception)
                    {
                        ExportDicomWorkerProgressState state = new ExportDicomWorkerProgressState( );

                        count++;

                        state.Error               = exception;
                        state.CurrentCount        = count;
                        state.ExportRow           = exportRow;
                        state.TotalCount          = imagesToExportCount;
                        state.ExportedImagesCount = 0;

                        ReportProgress((count * 100) / exportRows.Length, state);
                    }
                }
            }
            finally
            {
                e.Result = imagesToExportCount;
                if (DicomDirectory != null)
                {
                    DicomDirectory.Save();
                    DicomDirectory = null;
                }

                if (Anonymizer != null)
                {
                    Anonymizer.EndBatch();
                    Anonymizer = null;
                }
            }
        }
Exemple #6
0
        public DicomCommandStatusType OnStore
        (
            DicomClient client,
            byte presentationId,
            int messageId,
            string affectedClass,
            string instance,
            DicomCommandPriorityType priority,
            string moveAE,
            int moveMessageId,
            DicomDataSet request
        )
        {
            try
            {
                CStoreClientSessionProxy sessionProxy;
                DicomCommand             command;


                if (request != null && !CanStore(client, instance))
                {
                    return(DicomCommandStatusType.DuplicateInstance);
                }

                if (!ValidateLicense(client, request))
                {
                    return(DicomCommandStatusType.ProcessingFailure);
                }

                _messageId      = messageId;
                _presentationId = presentationId;
                _clientSession  = new ClientSession(client);

                sessionProxy = new CStoreClientSessionProxy(_clientSession, presentationId, messageId, affectedClass, instance, moveAE, moveMessageId);

                if (AddInsSession.DataAccess == null)
                {
                    if (null == DicomCommandFactory.GetInitializationService(typeof(CStoreCommand)))
                    {
                        DicomCommandFactory.RegisterCommandInitializationService(typeof(CStoreCommand),
                                                                                 new StoreCommandInitializationService( ));
                    }

                    command = DicomCommandFactory.GetInstance( ).CreateCStoreCommand(sessionProxy, request);
                }
                else
                {
                    StoreCommandInitializationService service;


                    service = ServiceLocator.Retrieve <StoreCommandInitializationService> ( );
                    command = new InstanceCStoreCommand(sessionProxy, request, AddInsSession.DataAccess);

                    service.ConfigureCommand(command);
                }

                _clientSession.CStoreResponse += new EventHandler <CStoreResponseEventArgs> (_clientSession_CStoreResponse);

                byte[] value = new byte[] { 0x00, 0x01 };

                request.InsertElementAndSetValue(DicomTag.FileMetaInformationVersion, value);
                request.InsertElementAndSetValue(DicomTag.MediaStorageSOPClassUID, affectedClass);
                request.InsertElementAndSetValue(DicomTag.MediaStorageSOPInstanceUID, instance);

                if (request.FindFirstElement(null, DicomTag.ImplementationClassUID, true) == null)
                {
                    request.InsertElementAndSetValue(DicomTag.ImplementationClassUID, (string.IsNullOrEmpty(client.Server.ImplementationClass) ? "1.2.840.114257.1123456" : client.Server.ImplementationClass));
                }

                if (request.FindFirstElement(null, DicomTag.ImplementationVersionName, true) == null)
                {
                    request.InsertElementAndSetValue(DicomTag.ImplementationVersionName, (string.IsNullOrEmpty(client.Server.ImplementationVersionName) ? "LTPACSF V19" : client.Server.ImplementationVersionName));
                }

                _clientSession.ProcessCStoreRequestSync(presentationId, messageId, affectedClass, instance, priority, moveAE, moveMessageId, command);

                if (_status != DicomCommandStatusType.Success)
                {
                    SaveFailedStoreRequest(request, _status.ToString( ), client);
                }

                return(_status);
            }
            catch (Exception exception)
            {
                SaveFailedStoreRequest(request, exception.Message, client);

                throw;
            }
            finally
            {
                if (null != request)
                {
                    request.Dispose( );
                }
            }
        }
        protected override void OnDoWork(DoWorkEventArgs e)
        {
            List <string> dicomFiles;
            int           count             = 0;
            int           successCount      = 0;
            int           failureCount      = 0;
            int           selectedFileCount = 0;
            int           totalFileCount    = 0;

            string[] selectedFileArray = e.Argument as string[];
            if (selectedFileArray != null)
            {
                selectedFileCount = selectedFileArray.Length;
            }

            if (this.CancellationPending)
            {
                // e.Cancel = true;
                e.Result = GetCancelResult(selectedFileCount, successCount, failureCount);
                return;
            }


            dicomFiles = GetDicomFiles(e);

            if (dicomFiles != null)
            {
                totalFileCount = dicomFiles.Count;
            }

            if (this.CancellationPending)
            {
                // e.Cancel = true;
                e.Result = GetCancelResult(totalFileCount, successCount, failureCount);
                return;
            }

            MultiDicomImportEventArgs args = new MultiDicomImportEventArgs(totalFileCount);

            EventBroker.Instance.PublishEvent <MultiDicomImportEventArgs>(this, args);


            foreach (string file in dicomFiles)
            {
                if (this.CancellationPending)
                {
                    // e.Cancel = true;
                    e.Result = GetCancelResult(totalFileCount, successCount, failureCount);
                    return;
                }

                using (DicomDataSet ds = new DicomDataSet( ))
                {
                    DicomCommandStatusType status;
                    string message        = string.Empty;
                    bool   successfulLoad = true;

                    try
                    {
                        ds.Load(file, DicomDataSetLoadFlags.None);
                    }
                    catch (Exception ex)
                    {
                        successfulLoad = false;
                        message        = ex.Message;
                        if (!File.Exists(file))
                        {
                            message = string.Format(@"File does not exist");

                            // This is needed for the following case
                            // If importing a DICOMDIR references a large number of files that do not exist, processing occurs so quickly that the import cannot be cancelled.
                            // So in the case that a file does not exists (i.e. abnormal condition), sleep for 100 ms to give the user time to cancel
                            Thread.Sleep(100);
                        }
                    }

                    count++;

                    AddDicomWorkerProgressState state;
                    StoreClientSessionProxy     proxy;
                    InstanceCStoreCommand       cmd;

                    if (successfulLoad && !OnCancelStore(ds, out message))
                    {
                        proxy = new StoreClientSessionProxy();
                        cmd   = new InstanceCStoreCommand(proxy, ds, _DataAccess);


                        proxy.AffectedSOPInstance = ds.GetValue <string>(DicomTag.SOPInstanceUID, string.Empty);
                        proxy.AbstractClass       = ds.GetValue <string>(DicomTag.SOPClassUID, string.Empty);
                        proxy.ServerName          = _AETitle;
                        proxy.ClientName          = _AETitle;


                        ds.InsertElementAndSetValue(DicomTag.MediaStorageSOPInstanceUID, proxy.AffectedSOPInstance);
                        ds.InsertElementAndSetValue(DicomTag.ImplementationClassUID, _ImplementationClassUID);

                        state = new AddDicomWorkerProgressState();

                        OnStoreCommandCreated(this, new StoreCommandEventArgs(cmd));

                        cmd.Execute();

                        status  = proxy.LastStatus;
                        message = proxy.LastStatusDescriptionMessage;
                    }
                    else
                    {
                        state  = new AddDicomWorkerProgressState();
                        status = DicomCommandStatusType.ProcessingFailure;
                    }

                    if (status == DicomCommandStatusType.Success)
                    {
                        successCount++;

                        state.CurrentCount = successCount;
                    }
                    else
                    {
                        failureCount++;

                        state.CurrentCount = failureCount;
                    }

                    state.Status        = status;
                    state.TotalCount    = dicomFiles.Count;
                    state.File          = file;
                    state.LoadedDataSet = ds;
                    state.Description   = message;

                    ReportProgress((count * 100) / dicomFiles.Count, state);
                }
            }

            AddDicomWorkerResultState resultState = new AddDicomWorkerResultState();

            resultState.SuccessCount = successCount;
            resultState.FailedCount  = failureCount;
            e.Result = resultState;
        }
Exemple #8
0
 public StoreCommandEventArgs(InstanceCStoreCommand command)
 {
     Command = command;
 }