コード例 #1
0
ファイル: MediaComposer.cs プロジェクト: sakpung/webstudy
        private CompositeInstanceDataSet GetReferencedCompositeInstancesAndFillInstanceProfiles
        (
            Dictionary <string, string> instanceSopProfileName
        )
        {
            MatchingParameterCollection matchingCollection;
            MatchingParameterList       matchingList;


            matchingCollection = new MatchingParameterCollection( );

            foreach (MediaCreationReferencedSop referencedSop in MediaObject.ReferencedSopSequence)
            {
                matchingList = new MatchingParameterList( );

                matchingCollection.Add(matchingList);

                ICatalogEntity instanceEntity = RegisteredEntities.GetInstanceEntity(referencedSop.SopInstance.ReferencedSopInstanceUid);
                matchingList.Add(instanceEntity);

                instanceSopProfileName.Add(referencedSop.SopInstance.ReferencedSopInstanceUid,
                                           referencedSop.RequestedMediaApplicationProfile);
            }

            return(StorageService.QueryCompositeInstances(matchingCollection).ToCompositeInstanceDataSet());
        }
コード例 #2
0
        MatchingParameterCollection GenerateMatchingParameterCollection(ViewGenerator.ViewDataRow metadataRow, out string rowKeyValue, out string rowKeyName, out string viewName)
        {
            DataRow originalRow = metadataRow.OriginalRow;
            MatchingParameterCollection matchingParamCollection = new MatchingParameterCollection();
            MatchingParameterList       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
            {
                throw new ApplicationException("Row is not a valid DICOM format.");
            }

            return(matchingParamCollection);
        }
コード例 #3
0
      private MatchingParameterCollection GetMatchingParameters(string sopInstanceUID)
      {
         MatchingParameterCollection matchingParamCollection = new MatchingParameterCollection();
         MatchingParameterList matchingParamList = new MatchingParameterList();
         // Instance instance = new Instance(sopInstanceUID);
         ICatalogEntity instance = RegisteredEntities.GetInstanceEntity(sopInstanceUID);

         matchingParamList.Add(instance);
         matchingParamCollection.Add(matchingParamList);
         return matchingParamCollection;
      }
コード例 #4
0
        internal static string FindReferencedFile(
#if LEADTOOLS_V19_OR_LATER
            IExternalStoreDataAccessAgent externalStoreAgent,
#endif // #if LEADTOOLS_V19_OR_LATER
            string sopInstanceUID)
        {
            MatchingParameterCollection          mpc = new MatchingParameterCollection();
            MatchingParameterList                mpl = new MatchingParameterList();
            DataSet /*CompositeInstanceDataSet*/ instanceData;
            IStorageDataAccessAgent              agent = null;
            string referencedFile = string.Empty;

            if (DataAccessServices.IsDataAccessServiceRegistered <IStorageDataAccessAgent>())
            {
                agent = DataAccessServices.GetDataAccessService <IStorageDataAccessAgent>();
            }

            if (agent != null)
            {
                ICatalogEntity instanceEntity = RegisteredEntities.GetInstanceEntity(sopInstanceUID);
                mpl.Add(instanceEntity);
                mpc.Add(mpl);

                instanceData = agent.QueryCompositeInstances(mpc);
                if (instanceData.Tables[DataTableHelper.InstanceTableName].Rows.Count == 1)
                {
                    DataRow row = instanceData.Tables[DataTableHelper.InstanceTableName].Rows[0];
                    referencedFile = RegisteredDataRows.InstanceInfo.ReferencedFile(row);

#if (LEADTOOLS_V19_OR_LATER_MEDICAL_EXTERNAL_STORE) || (LEADTOOLS_V19_OR_LATER)
                    if (string.IsNullOrEmpty(referencedFile))
                    {
                        // If empty, it might be on the cloud
                        // Use DicomInstanceRetrieveExternalStoreCommand with cache set to true to copy it locally
                        if (externalStoreAgent == null)
                        {
                            if (DataAccessServices.IsDataAccessServiceRegistered <IExternalStoreDataAccessAgent>())
                            {
                                externalStoreAgent = DataAccessServices.GetDataAccessService <IExternalStoreDataAccessAgent>();
                            }
                        }

                        DicomInstanceRetrieveExternalStoreCommand c = new DicomInstanceRetrieveExternalStoreCommand(agent, externalStoreAgent, AddInsSession.ServiceDirectory, true);
                        DicomDataSet ds = c.GetDicomDataSet(row, out referencedFile);
                    }
#endif // (LEADTOOLS_V19_OR_LATER_MEDICAL_EXTERNAL_STORE) || (LEADTOOLS_V19_OR_LATER)
                }
            }
            return(referencedFile);
        }
コード例 #5
0
        private static string GetPatientName(MediaCreationManagement mediaObject)
        {
            string patientName;
            IStorageDataAccessAgent     dataAccess;
            MatchingParameterCollection matchingCollection;
            MatchingParameterList       matchingList;
            CompositeInstanceDataSet    compositeInstance;


            patientName        = string.Empty;
            dataAccess         = DataAccessServices.GetDataAccessService <IStorageDataAccessAgent> ( );
            matchingCollection = new MatchingParameterCollection( );
            matchingList       = new MatchingParameterList( );
            // Instance matchingInstance   = new Instance ( mediaObject.ReferencedSopSequence [ 0 ].SopInstance.ReferencedSopInstanceUid ) ;
            ICatalogEntity matchingInstance = RegisteredEntities.GetInstanceEntity(mediaObject.ReferencedSopSequence [0].SopInstance.ReferencedSopInstanceUid);

            if (null == dataAccess)
            {
                dataAccess = DataAccessFactory.GetInstance(new StorageDataAccessConfigurationView( )).CreateDataAccessAgent <IStorageDataAccessAgent> ( );
            }

            matchingCollection.Add(matchingList);
            matchingList.Add(matchingInstance);

            compositeInstance = dataAccess.QueryCompositeInstances(matchingCollection).ToCompositeInstanceDataSet();

            if (!string.IsNullOrEmpty(compositeInstance.Patient [0].FamilyName))
            {
                patientName += compositeInstance.Patient [0].FamilyName;
            }

            if (!string.IsNullOrEmpty(compositeInstance.Patient [0].GivenName))
            {
                if (!string.IsNullOrEmpty(patientName))
                {
                    patientName += ", ";
                }

                patientName += compositeInstance.Patient [0].GivenName;
            }

            return(patientName);
        }
コード例 #6
0
        private static DicomDataSet GetFirstReferencedInstanceDataSet
        (
            IStorageDataAccessAgent dataAccess,
            MediaCreationManagement mediaObject)
        {
            MatchingParameterCollection matchingCollection;
            MatchingParameterList       matchingList;
            CompositeInstanceDataSet    compositeInstance;


            matchingCollection = new MatchingParameterCollection( );
            matchingList       = new MatchingParameterList( );
            // Instance instance           = new Instance ( mediaObject.ReferencedSopSequence [ 0 ].SopInstance.ReferencedSopInstanceUid ) ;
            ICatalogEntity instance = RegisteredEntities.GetInstanceEntity(mediaObject.ReferencedSopSequence [0].SopInstance.ReferencedSopInstanceUid);


            matchingCollection.Add(matchingList);
            matchingList.Add(instance);

            compositeInstance = dataAccess.QueryCompositeInstances(matchingCollection).ToCompositeInstanceDataSet();

            if (compositeInstance.Instance.Count > 0)
            {
                DicomDataSet ds;


                ds = new DicomDataSet( );

                ds.Load(compositeInstance.Instance [0].ReferencedFile, DicomDataSetLoadFlags.None);

                return(ds);
            }
            else
            {
                return(null);
            }
        }
コード例 #7
0
ファイル: AutoCopyQueue.cs プロジェクト: sakpung/webstudy
        private void SendCopy(AutoCopyItem item)
        {
            AeInfoExtended[] aes   = _aeManagementAgent.GetRelatedAeTitles(item.SourceAE, Module.AUTOCOPY_RELATION);
            StoreScu         store = new StoreScu();

            Module.InitializeDicomSecurity(false);
            StoreScu storeSecure = null;

            DicomOpenSslVersion dicomOpenSslVersion = DicomNet.GetOpenSslVersion();

            if (dicomOpenSslVersion.IsAvailable)
            {
                storeSecure = new StoreScu(Module._Server.TemporaryDirectory, DicomNetSecurityMode.Tls, Module._openSslOptions);
                Module.SetCiphers(storeSecure);
            }

            DicomScp scp = null;

            string[] sopInstances = item.Datasets.ToArray();

            if (aes == null || aes.Length == 0)
            {
                return;
            }

            string clientAe = Module.Options.UseCustomAE ? Module.Options.AutoCopyAE : item.ClientAE;

            AddEventHandlers(store, clientAe);
            AddEventHandlers(storeSecure, clientAe);

            foreach (AeInfoExtended ae in aes)
            {
#if LEADTOOLS_V20_OR_LATER
                // Update dbo.AeInfo.LastAccessDate to Date.Now
                ae.LastAccessDate = DateTime.Now;
                _aeManagementAgent.Update(ae.AETitle, ae);
#endif

                bool useTls = ae.ClientPortUsage == ClientPortUsageType.Secure || ((ae.ClientPortUsage == ClientPortUsageType.SameAsServer) && (Module._Server.Secure));
                useTls = (useTls && dicomOpenSslVersion.IsAvailable);

                foreach (string sopInstance in sopInstances)
                {
                    MatchingParameterCollection mpc = new MatchingParameterCollection();
                    MatchingParameterList       mpl = new MatchingParameterList();

                    ICatalogEntity instanceEntity = RegisteredEntities.GetInstanceEntity(sopInstance);
                    mpl.Add(instanceEntity);
                    mpc.Add(mpl);

                    DataSet instanceData = _StorageAgent.QueryCompositeInstances(mpc);
                    // if (instanceData.Instance.Rows.Count == 1)
                    if (instanceData.Tables[DataTableHelper.InstanceTableName].Rows.Count == 1)
                    {
                        // string file = instanceData.Instance[0].ReferencedFile;
                        DataRow instanceRow = instanceData.Tables[DataTableHelper.InstanceTableName].Rows[0];
                        string  file        = RegisteredDataRows.InstanceInfo.ReferencedFile(instanceRow);

                        scp = new DicomScp(IPAddress.Parse(ae.Address), ae.AETitle, ae.Port);
                        try
                        {
                            if (useTls)
                            {
                                storeSecure.Store(scp, file);
                            }
                            else
                            {
                                store.Store(scp, file);
                            }
                        }
                        catch (ClientAssociationException ce)
                        {
                            string message = string.Format("[Auto Copy] Failed to establish association with server: {0}.", ce.Reason);

                            LogEvent(LogType.Error, MessageDirection.None, message, DicomCommandType.Undefined, null, store, null);
                        }
                        catch (DicomException de)
                        {
                            string message = string.Format("[Auto Copy] Error: {0}.", de.Message);

                            LogEvent(LogType.Error, MessageDirection.Input, message, DicomCommandType.Undefined, null, store, null);
                        }
                        catch (Exception e)
                        {
                            string message = "[Auto Copy] " + e.Message;

                            Logger.Global.Log(string.Empty, string.Empty, -1, string.Empty, string.Empty, -1, DicomCommandType.Undefined,
                                              DateTime.Now, LogType.Error, MessageDirection.None, message, null, null);
                        }
                    }
                }
            }

            RemoveEventHandlers(store);
            RemoveEventHandlers(storeSecure);

            foreach (string sopInstance in sopInstances)
            {
                item.Datasets.Remove(sopInstance);
            }
        }
コード例 #8
0
ファイル: RestoreProcess.cs プロジェクト: sakpung/webstudy
        public void RunThread(IExternalStoreDataAccessAgent externalStoreAgent, IStorageDataAccessAgent storageAgent, DateRange range)
        {
            DicomUtilities.DebugString(DebugStringOptions.ShowCounter, "RestoreProcess.Run");

            lock (_restoreLock)
            {
                ExternalStoreInstance[] instances = externalStoreAgent.GetRestoreList(range);
                string message = string.Format("{0} {1} found to restore", instances.Length, "dataset(s)");
                MatchingParameterCollection mpc = new MatchingParameterCollection();

                Logger.Global.SystemMessage(LogType.Information, message, _serviceName);

                CStoreCommandConfiguration storeConfig = new CStoreCommandConfiguration();
                storeConfig.DicomFileExtension = _storageAddinsConfiguration.StoreAddIn.StoreFileExtension;
                FillStoreCommandDefaultSettings(storeConfig, _storageAddinsConfiguration);

                foreach (ExternalStoreInstance instance in instances)
                {
                    if (_cancelRestore)
                    {
                        _cancelRestore = false;
                        Logger.Global.SystemMessage(LogType.Information, "Cancelling Restore Process", _serviceName);
                        break;
                    }

                    MatchingParameterList mpl = new MatchingParameterList();

                    ICatalogEntity instanceEntity = RegisteredEntities.GetInstanceEntity(instance.SOPInstanceUID);
                    mpl.Add(instanceEntity);
                    mpc.Add(mpl);
                    try
                    {
                        DataSet ds = storageAgent.QueryCompositeInstances(mpc);

                        DataRow[] rows = ds.Tables[DataTableHelper.InstanceTableName].Select();
                        foreach (DataRow row in rows)
                        {
                            // Get the ICrud that the file was originally stored with
                            ICrud crud = DataAccessServiceLocator.Retrieve <ICrud>(instance.ExternalStoreGuid);
                            if (crud != null)
                            {
                                DicomDataSet dicomDataSet = null;
                                Exception    ex           = crud.RetrieveDicom(row, DicomDataSetLoadFlags.None, out dicomDataSet);
                                if (ex == null)
                                {
                                    string storageLocation   = CStoreCommand.GetStorageLocation(storeConfig, dicomDataSet);
                                    string dicomInstancePath = Path.Combine(storageLocation,
                                                                            instance.SOPInstanceUID) + "." + storeConfig.DicomFileExtension;

                                    ex = crud.RetrieveFile(row, dicomInstancePath);
                                    if (ex != null)
                                    {
                                        throw ex;
                                    }

                                    externalStoreAgent.SetReferencedFile(instance.SOPInstanceUID, dicomInstancePath);
                                    Logger.Global.SystemMessage(LogType.Information, string.Format("File Restored: {0} ", dicomInstancePath), _serviceName);
                                }
                            }
                            else
                            {
                                Logger.Global.SystemMessage(LogType.Information, string.Format("Error:  File Not Restored -- Store Token: {0}.  The Addin that for ExternalStoreGuid '{1}' cannot be found.", instance.StoreToken, instance.ExternalStoreGuid), _serviceName);
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        message = string.Format("Error ({0}) restoring instance: {1}", e.Message, instance.SOPInstanceUID);
                        Logger.Global.SystemMessage(LogType.Error, message, _serviceName);
                    }
                    finally
                    {
                        mpc.Clear();
                    }
                }
            }
        }
コード例 #9
0
      public void RunThread(IForwardDataAccessAgent forwardAgent, IStorageDataAccessAgent storageAgent)
      {
         lock (cleanLock)
         {
            ForwardInstance[] instances = forwardAgent.GetCleanList();
            StorageAddInsConfiguration storageSettings = Module.StorageConfigManager.GetStorageAddInsSettings();
            string message = string.Format("[Forwarder] {0} {1} found to clean", instances.Length, instances.Length == 1 ? "dataset" : "datasets");
            DicomFileDeleter deleter = new DicomFileDeleter();
            MatchingParameterCollection mpc = new MatchingParameterCollection();

            deleter.DicomFileDeleted += new EventHandler<Leadtools.Medical.Winforms.EventBrokerArgs.DicomFileDeletedEventArgs>(deleter_DicomFileDeleted);
            deleter.DicomFileDeleteFailed += new EventHandler<Leadtools.Medical.Winforms.EventBrokerArgs.DicomFileDeletedEventArgs>(deleter_DicomFileDeleteFailed);
            if (storageSettings != null)
            {
               deleter.DeleteFilesOnDatabaseDelete = storageSettings.StoreAddIn.DeleteFiles;
               deleter.BackupFilesOnDatabaseDelete = storageSettings.StoreAddIn.BackupFilesOnDelete;
               deleter.BackupFilesOnDeleteFolder = storageSettings.StoreAddIn.DeleteBackupLocation;
            }

            Logger.Global.SystemMessage(LogType.Debug, message, _ServerAE);
            foreach (ForwardInstance instance in instances)
            {
#if LEADTOOLS_V18_OR_LATER
               if (_cancelClean)
               {
                  _cancelClean = false;
                  Logger.Global.SystemMessage(LogType.Information, string.Format("Cancelling Clean Process"), _ServerAE);
                  break;
               }
#endif // #if LEADTOOLS_V18_OR_LATER
               MatchingParameterList mpl = new MatchingParameterList();

               ICatalogEntity instanceEntity = RegisteredEntities.GetInstanceEntity(instance.SOPInstanceUID);
               mpl.Add(instanceEntity);
               mpc.Add(mpl);
               try
               {
                  DataSet ds = storageAgent.QueryCompositeInstances(mpc);

                  //
                  // Find the instance to delete
                  //
                  storageAgent.DeleteInstance(GetMatchingParameters(instance.SOPInstanceUID));
                  if (ds != null)
                  {                     
                     deleter.Delete(null, ds.Tables[DataTableHelper.InstanceTableName].Select());
                  }
               }
               catch (Exception e)
               {
                  message = string.Format("[Forwarder] Error ({0}) deleting instance: {1}", e.Message, instance.SOPInstanceUID);
                  Logger.Global.SystemMessage(LogType.Error, message, _ServerAE);
               }
               finally
               {
                  mpc.Clear();
               }
            }
            deleter.DicomFileDeleted -= deleter_DicomFileDeleted;
            deleter.DicomFileDeleteFailed -= deleter_DicomFileDeleteFailed;
         }
      }
コード例 #10
0
        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;
                }
            }
        }
コード例 #11
0
        protected override void OnDoWork(DoWorkEventArgs e)
        {
            int count;
            int totalDeletedImagesCount;

            ViewGenerator.ViewDataRow [] deleteRows;


            count = 0;
            totalDeletedImagesCount = 0;

            try
            {
                MatchingParameterCollection matchingParamCollection;
                MatchingParameterList       matchingParamList;


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

                    return;
                }

                if (!(e.Argument is ViewGenerator.ViewDataRow []))
                {
                    throw new ArgumentException("Invalid RemoveDicom argument");
                }

                deleteRows = (e.Argument as ViewGenerator.ViewDataRow []);

                foreach (ViewGenerator.ViewDataRow deletedRow in deleteRows)
                {
                    try
                    {
                        DataRow originalRow;
                        int     deletedImagesCount;
                        string  rowKeyValue;
                        string  rowKeyName;
                        string  viewName;


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

                            return;
                        }

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

                        matchingParamCollection.Add(matchingParamList);

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


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

                            matchingParamList.Add(imageInstance);
                        }
                        // else if ( originalRow is CompositeInstanceDataSet.SeriesRow )
                        else if (string.Compare(originalRow.Table.TableName, DataTableHelper.SeriesTableName) == 0)
                        {
                            // ICatalogEntity seriesEntity ;


                            // seriesEntity = new Series ( ( ( CompositeInstanceDataSet.SeriesRow ) originalRow ).SeriesInstanceUID ) ;
                            string         sSeriesInstanceUid = RegisteredDataRows.SeriesInfo.GetElementValue(originalRow, DicomTag.SeriesInstanceUID);
                            ICatalogEntity seriesEntity       = RegisteredEntities.GetSeriesEntity(sSeriesInstanceUid);
                            // seriesEntity = new Series ( ( ( CompositeInstanceDataSet.SeriesRow ) originalRow ).SeriesInstanceUID ) ;


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

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

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

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

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

                            matchingParamList.Add(patientEntity);
                        }
#if (LEADTOOLS_V19_OR_LATER)
                        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);
                        }
#endif
                        else
                        {
                            throw new ApplicationException("Deleted row is not a valid DICOM format.");
                        }

#if (LEADTOOLS_V19_OR_LATER)
                        if (string.Compare(originalRow.Table.TableName, DataTableHelper.HangingProtocolTableName) == 0 && _dataAccessAgent3 != null)
                        {
                            deletedImagesCount = _dataAccessAgent3.DeleteHangingProtocol(matchingParamCollection);
                        }
                        else
                        {
                            deletedImagesCount = _dataAccessAgent.DeleteInstance(matchingParamCollection);
                        }
#else
                        deletedImagesCount = _dataAccessAgent.DeleteInstance(matchingParamCollection);
#endif

                        count++;

                        RemoveDiconWorkerProgressState state;


                        state = new RemoveDiconWorkerProgressState( );

                        totalDeletedImagesCount += deletedImagesCount;

                        state.Error              = null;
                        state.CurrentCount       = count;
                        state.DeletedRow         = deletedRow;
                        state.RemovedImagesCount = deletedImagesCount;
                        state.TotalCount         = totalDeletedImagesCount;
                        state.RowKeyValue        = rowKeyValue;
                        state.RowKeyName         = rowKeyName;
                        state.ViewName           = viewName;

                        ReportProgress((count * 100) / deleteRows.Length, state);
                    }
                    catch (Exception exception)
                    {
                        RemoveDiconWorkerProgressState state;


                        state = new RemoveDiconWorkerProgressState( );

                        count++;

                        state.Error              = exception;
                        state.CurrentCount       = count;
                        state.DeletedRow         = deletedRow;
                        state.TotalCount         = totalDeletedImagesCount;
                        state.RemovedImagesCount = 0;

                        ReportProgress((count * 100) / deleteRows.Length, state);
                    }
                }
            }
            finally
            {
                e.Result = totalDeletedImagesCount;
            }
        }
コード例 #12
0
ファイル: CleanProcess.cs プロジェクト: sakpung/webstudy
        public void Run(IExternalStoreDataAccessAgent externalStoreAgent, IStorageDataAccessAgent storageAgent, int expirationDays)
        {
            DicomUtilities.DebugString(DebugStringOptions.ShowCounter, "CleanProcess.Run");
            lock (cleanLock)
            {
                ExternalStoreInstance[] instances = externalStoreAgent.GetClearList(expirationDays);
                // StorageAddInsConfiguration storageSettings = Module.StorageConfigManager.GetStorageAddInsSettings();

                if (instances.Length > 0)
                {
                    string message = string.Format("{0} {1} found to clear", instances.Length, "local dataset(s)");
                    Logger.Global.SystemMessage(LogType.Information, message, _serviceName);

                    DicomFileDeleter            deleter = new DicomFileDeleter();
                    MatchingParameterCollection mpc     = new MatchingParameterCollection();

                    deleter.DicomFileDeleted      += new EventHandler <Leadtools.Medical.Winforms.EventBrokerArgs.DicomFileDeletedEventArgs>(deleter_DicomFileDeleted);
                    deleter.DicomFileDeleteFailed += new EventHandler <Leadtools.Medical.Winforms.EventBrokerArgs.DicomFileDeletedEventArgs>(deleter_DicomFileDeleteFailed);
                    if (_storageSettings != null)
                    {
                        deleter.DeleteFilesOnDatabaseDelete = _storageSettings.StoreAddIn.DeleteFiles;
                        deleter.BackupFilesOnDatabaseDelete = _storageSettings.StoreAddIn.BackupFilesOnDelete;
                        deleter.BackupFilesOnDeleteFolder   = _storageSettings.StoreAddIn.DeleteBackupLocation;

                        deleter.DeleteAnnotationsOnImageDelete      = false;
                        deleter.DeleteReferencedImagesOnImageDelete = false;
                    }

                    foreach (ExternalStoreInstance instance in instances)
                    {
                        MatchingParameterList mpl = new MatchingParameterList();

                        ICatalogEntity instanceEntity = RegisteredEntities.GetInstanceEntity(instance.SOPInstanceUID);
                        mpl.Add(instanceEntity);
                        mpc.Add(mpl);
                        try
                        {
                            DataSet ds = storageAgent.QueryCompositeInstances(mpc);

                            //
                            // Find the instance to delete
                            ////
                            deleter.Delete(null, ds.Tables[DataTableHelper.InstanceTableName].Select());

                            externalStoreAgent.SetReferencedFile(instance.SOPInstanceUID, string.Empty);
                        }
                        catch (Exception e)
                        {
                            message = string.Format("Error ({0}) deleting instance: {1}", e.Message, instance.SOPInstanceUID);
                            Logger.Global.SystemMessage(LogType.Error, message, _serviceName);
                        }
                        finally
                        {
                            mpc.Clear();
                        }
                    }
                    deleter.DicomFileDeleted      -= deleter_DicomFileDeleted;
                    deleter.DicomFileDeleteFailed -= deleter_DicomFileDeleteFailed;
                }
            }
        }