private void UpdateConfigurationsAsync(object state)
        {
            var asyncState = (AsyncState)state;
            //This stuff can actually add up over time because it's hitting the database so frequently.
            //Better to do it asynchronously.
            var storageConfiguration     = StudyStore.GetConfiguration();
            var dicomServerConfiguration = DicomServer.GetConfiguration();

            if (!Equals(asyncState.CurrentDicomServerConfiguration, dicomServerConfiguration))
            {
                asyncState.SynchronizationContext.Post(ignore => NotifyDicomServerConfigurationChanged(dicomServerConfiguration), null);
            }

            var storageConfigurationChanged = HasStorageConfigurationChanged(asyncState.CurrentStorageConfiguration, storageConfiguration);
            //Access all the disk usage properties here, since they can take some time.
            bool diskUsageChanged = HasDiskUsageChanged(asyncState.CurrentStorageConfiguration, storageConfiguration);

            if (storageConfigurationChanged)
            {
                asyncState.SynchronizationContext.Post(ignore => NotifyStorageConfigurationChanged(storageConfiguration), null);
            }
            else if (diskUsageChanged)
            {
                asyncState.SynchronizationContext.Post(ignore => NotifyDiskUsageChanged(storageConfiguration), null);
            }
        }
Example #2
0
        private void Anonymize(IBackgroundTaskContext context)
        {
            //TODO (Marmot) This probably should be its own WorkItem type and have it done in the background there.
            var study = (StudyTableItem)context.UserState;
            var anonymizedInstances = new AuditedInstances();

            try
            {
                context.ReportProgress(new BackgroundTaskProgress(0, SR.MessageAnonymizingStudy));

                var loader       = study.Server.GetService <IStudyLoader>();
                int numberOfSops = loader.Start(new StudyLoaderArgs(study.StudyInstanceUid, null));
                if (numberOfSops <= 0)
                {
                    return;
                }

                var anonymizer = new DicomAnonymizer {
                    StudyDataPrototype = _component.AnonymizedData
                };

                if (_component.PreserveSeriesData)
                {
                    //The default anonymizer removes the series data, so we just clone the original.
                    anonymizer.AnonymizeSeriesDataDelegate = original => original.Clone();
                }

                // Setup the ImportFilesUtility to perform the import
                var configuration = DicomServer.GetConfiguration();

                // setup auditing information
                var result = EventResult.Success;

                string patientsSex = null;

                for (int i = 0; i < numberOfSops; ++i)
                {
                    using (var sop = loader.LoadNextSop())
                    {
                        if (sop != null &&
                            (_component.KeepReportsAndAttachments || !IsReportOrAttachmentSopClass(sop.SopClassUid)))
                        {
                            //preserve the patient sex.
                            if (patientsSex == null)
                            {
                                anonymizer.StudyDataPrototype.PatientsSex = patientsSex = sop.PatientsSex ?? "";
                            }

                            var localSopDataSource = sop.DataSource as ILocalSopDataSource;
                            if (localSopDataSource != null)
                            {
                                string    filename = string.Format("{0}.dcm", i);
                                DicomFile file     = (localSopDataSource).File;

                                // make sure we anonymize a new instance, not the same instance that the Sop cache holds!!
                                file = new DicomFile(filename, file.MetaInfo.Copy(), file.DataSet.Copy());
                                anonymizer.Anonymize(file);

                                // TODO (CR Jun 2012): Importing each file separately?
                                Platform.GetService((IPublishFiles w) => w.PublishLocal(new List <DicomFile> {
                                    file
                                }));

                                string studyInstanceUid = file.DataSet[DicomTags.StudyInstanceUid].ToString();
                                string patientId        = file.DataSet[DicomTags.PatientId].ToString();
                                string patientsName     = file.DataSet[DicomTags.PatientsName].ToString();
                                anonymizedInstances.AddInstance(patientId, patientsName, studyInstanceUid);

                                var progressPercent = (int)Math.Floor((i + 1) / (float)numberOfSops * 100);
                                var progressMessage = String.Format(SR.MessageAnonymizingStudy, file.MediaStorageSopInstanceUid);
                                context.ReportProgress(new BackgroundTaskProgress(progressPercent, progressMessage));
                            }
                        }
                    }
                }

                AuditHelper.LogCreateInstances(new[] { configuration.AETitle }, anonymizedInstances, EventSource.CurrentUser, result);

                context.Complete();
            }
            catch (Exception e)
            {
                AuditHelper.LogCreateInstances(new[] { string.Empty }, anonymizedInstances, EventSource.CurrentUser, EventResult.MajorFailure);
                context.Error(e);
            }
        }
Example #3
0
 public void Refresh()
 {
     _dicomServerConfiguration = DicomServer.GetConfiguration();
     _storageConfiguration     = StudyStore.GetConfiguration();
 }
 protected static DicomServerConfiguration GetServerConfiguration()
 {
     return(DicomServer.GetConfiguration());
 }