private IDataStoreReader GetIDataStoreReader()
			{
				if (_dataStoreReader == null)
					_dataStoreReader = DataAccessLayer.GetIDataStoreReader();

				return _dataStoreReader;
			}
            public void RemoveStudies(IEnumerable <string> studyInstanceUids)
            {
                try
                {
                    using (IDataStoreReader reader = GetIDataStoreReader())
                    {
                        foreach (string studyUid in studyInstanceUids)
                        {
                            Study study = (Study)reader.GetStudy(studyUid);
                            File.Delete(study.StudyXmlUri.LocalDiskPath);
                        }
                    }

                    SessionManager.BeginWriteTransaction();
                    foreach (string uid in studyInstanceUids)
                    {
                        Session.Delete("from Study where StudyInstanceUid_ = ?", uid, NHibernateUtil.String);
                    }

                    SessionManager.Commit();
                }
                catch (Exception e)
                {
                    SessionManager.Rollback();
                    throw new DataStoreException("Failed to clear specified studies from the data store.", e);
                }
            }
 protected CrmGenericImporter(ILogger logger, IDataStoreReader <Entity, EntityWrapper> storeReader, DataCrmStoreWriter storeWriter, ICrmGenericImporterConfig config, CancellationToken token)
     : base(logger, storeReader, storeWriter, token)
 {
     this.config   = config;
     targetEntRepo = storeWriter?.GetEntityRepository;
     AddCustomProcessors();
 }
Exemple #4
0
        IEnumerator <ISopInstance> IEnumerable <ISopInstance> .GetEnumerator()
        {
            using (IDataStoreReader reader = DataAccessLayer.GetIDataStoreReader())
            {
                foreach (string studyUID in _studyDictionary.Keys)
                {
                    Dictionary <string, Dictionary <string, string> > studyInfo = _studyDictionary[studyUID];
                    Debug.Assert(studyInfo != null);
                    foreach (string seriesInstanceUID in studyInfo.Keys)
                    {
                        Dictionary <string, string> seriesInfo = studyInfo[seriesInstanceUID];
                        Debug.Assert(seriesInfo != null);
                        foreach (string sopInstanceUID in seriesInfo.Keys)
                        {
                            foreach (ISopInstance sopInstance in reader.GetStudy(studyUID).GetSopInstances())
                            {
                                if (sopInstance.SopInstanceUid != sopInstanceUID)
                                {
                                    continue;
                                }
                                yield return(sopInstance);

                                break;
                            }
                        }
                    }
                }
            }
        }
Exemple #5
0
 public TestCrmGenericImporter(
     ILogger logger,
     IDataStoreReader <Entity, EntityWrapper> storeReader,
     DataCrmStoreWriter storeWriter,
     ICrmGenericImporterConfig config)
     : base(logger, storeReader, storeWriter, config)
 {
 }
            private IDataStoreReader GetIDataStoreReader()
            {
                if (_dataStoreReader == null)
                {
                    _dataStoreReader = DataAccessLayer.GetIDataStoreReader();
                }

                return(_dataStoreReader);
            }
        public AnonymizeStudyOutput AnonymizeStudy(AnonymizeStudyInput input)
        {
            // load study to anonymize
            IDataStoreReader    reader = DataAccessLayer.GetIDataStoreReader();
            IStudy              study  = reader.GetStudy(input.StudyInstanceUID);
            List <ISopInstance> sops   = new List <ISopInstance>(study.GetSopInstances());

            // ensure there is a valid output location
            if (string.IsNullOrEmpty(input.OutputDirectory))
            {
                // create temp dir
            }

            string fullPath = Path.GetFullPath(input.OutputDirectory);

            if (!Directory.Exists(fullPath))
            {
                Directory.CreateDirectory(fullPath);
            }

            // set up anonymization data
            StudyData studyData = new StudyData();

            studyData.PatientId         = input.PatientId;
            studyData.PatientsNameRaw   = input.PatientsName;
            studyData.PatientsBirthDate = input.PatientsBirthDate;
            studyData.PatientsSex       = input.PatientsSex;
            studyData.AccessionNumber   = input.AccessionNumber;
            studyData.StudyDescription  = input.StudyDescription;
            studyData.StudyDate         = input.StudyDate;

            DicomAnonymizer anonymizer = new DicomAnonymizer();

            anonymizer.StudyDataPrototype = studyData;

            //The default anonymizer removes the series data, so we just clone the original.
            anonymizer.AnonymizeSeriesDataDelegate =
                delegate(SeriesData original) { return(original.Clone()); };

            // anonymize each image in the study
            for (int i = 0; i < sops.Count; ++i)
            {
                ISopInstance sop  = sops[i];
                DicomFile    file = new DicomFile(sop.GetLocationUri().LocalDiskPath);

                anonymizer.Anonymize(file);

                file.Save(string.Format("{0}\\{1}.dcm", fullPath, i));
            }

            return(new AnonymizeStudyOutput(sops.Count));
        }
        public GenericDataMigrator(ILogger logger, IDataStoreReader <TMigrationEntity, TMigrationEntityWrapper> storeReader, IDataStoreWriter <TMigrationEntity, TMigrationEntityWrapper> storeWriter)
        {
            logger.ThrowIfNull <ArgumentNullException>(nameof(logger));
            storeReader.ThrowIfNull <ArgumentNullException>(nameof(storeReader));
            storeWriter.ThrowIfNull <ArgumentNullException>(nameof(storeWriter));

            this.storeReader = storeReader;
            this.storeWriter = storeWriter;
            this.Logger      = logger;

            cancellationToken = new CancellationTokenSource().Token;
            processors        = new List <IEntityProcessor <TMigrationEntity, TMigrationEntityWrapper> >();
        }
 private void DisposeReader()
 {
     try
     {
         if (_dataStoreReader != null)
         {
             _dataStoreReader.Dispose();
         }
     }
     finally
     {
         _dataStoreReader = null;
     }
 }
Exemple #10
0
        protected void InitializeAnnotationList(string studyInstanceUID)
        {
            if (_annotationDictionary.ContainsStudy(studyInstanceUID))
            {
                return;
            }

            StudyItemList studyAnnotations = GetAnnotationsList(studyInstanceUID);             // TODO - switch to using SR IOD when we have it

            if (studyAnnotations == null || studyAnnotations.Count == 0)
            {
                return;
            }

            using (IDataStoreReader reader = DataAccessLayer.GetIDataStoreReader())
            {
                foreach (StudyItem studyItem in studyAnnotations)
                {
                    ClearCanvas.Dicom.DataStore.Study study = reader.GetStudy(studyItem.StudyInstanceUid) as ClearCanvas.Dicom.DataStore.Study;
                    if (study != null)
                    {
                        IEnumerable <ISeries> allSeries = study.GetSeries();
                        foreach (ISeries series in allSeries)
                        {
                            if (series != null && series.Modality == "SR")
                            {
                                IEnumerable <ISopInstance> sopInstances = series.GetSopInstances();
                                foreach (ISopInstance sopInstance in sopInstances)
                                {
                                    if (sopInstance != null)
                                    {
                                        DicomUri fileUri = sopInstance.GetLocationUri();
                                        if (fileUri.IsFile)
                                        {
                                            _annotationDictionary.Add(study.StudyInstanceUid, series.SeriesInstanceUid, sopInstance.SopInstanceUid, fileUri.LocalDiskPath);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                // TODO:
                // 1. Find and load all annotations (read-only?)
                //      LocalDataStoreActivityMonitor.Instance.
            }
        }
            public void ClearAllStudies()
            {
                try
                {
                    using (IDataStoreReader reader = GetIDataStoreReader())
                    {
                        foreach (Study study in reader.GetStudies())
                        {
                            File.Delete(study.StudyXmlUri.LocalDiskPath);
                        }
                    }

                    SessionManager.BeginWriteTransaction();
                    Session.Delete("from Study");
                    SessionManager.Commit();
                }
                catch (Exception e)
                {
                    SessionManager.Rollback();
                    throw new DataStoreException("Failed to clear all studies from the data store.", e);
                }
            }
 public GenericDataMigrator(ILogger logger, IDataStoreReader <TMigrationEntity, TMigrationEntityWrapper> storeReader, IDataStoreWriter <TMigrationEntity, TMigrationEntityWrapper> storeWriter, CancellationToken cancellationToken)
     : this(logger, storeReader, storeWriter)
 {
     this.cancellationToken = cancellationToken;
 }
 /// <summary>
 /// Deserializes the specified xml log file.
 /// </summary>
 /// <param name="reader">The <see cref="IDataStoreReader"/> to use.</param>
 /// <returns>The deserialized log entries.</returns>
 public static List<LogEntry> Deserialize( IDataStoreReader reader )
 {
     var list = new List<LogEntry>();
     reader.Read(
         "LogEntries",
         () =>
         {
             while( reader.Read()
                 && reader.Token == DataStoreToken.ObjectStart )
                 list.Add(reader.Deserialize(LogEntry.Serializer.Default));
         });
     return list;
 }
Exemple #14
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="reader"></param>
 public DataStoreInfo(IDataStoreReader reader)
 {
     this.Name = reader.GetName();
     this.Description = reader.GetDescription();
     this.IsFdoEnabled = reader.GetIsFdoEnabled();
 }
			private void DisposeReader()
			{
				try
				{
					if (_dataStoreReader != null)
						_dataStoreReader.Dispose();
				}
				finally
				{
					_dataStoreReader = null;
				}
			}
Exemple #16
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="reader"></param>
 public DataStoreInfo(IDataStoreReader reader)
 {
     this.Name         = reader.GetName();
     this.Description  = reader.GetDescription();
     this.IsFdoEnabled = reader.GetIsFdoEnabled();
 }
 public GenericCrmDataMigrator(ILogger logger, IDataStoreReader <Entity, EntityWrapper> storeReader, IDataStoreWriter <Entity, EntityWrapper> storeWriter)
     : base(logger, storeReader, storeWriter)
 {
 }
 public GenericCrmDataMigrator(ILogger logger, IDataStoreReader <Entity, EntityWrapper> storeReader, IDataStoreWriter <Entity, EntityWrapper> storeWriter, CancellationToken cancellationToken)
     : base(logger, storeReader, storeWriter, cancellationToken)
 {
 }