private static AnonymizerRule TryCreateRule <TItem, TResult>(
            string tagContent,
            string method,
            string description,
            IAnonymizerProcessorFactory processorFactory,
            JObject ruleSetting)
        {
            object outputTag;

            try
            {
                outputTag = (TItem)typeof(TItem).GetMethod("Parse", new Type[] { typeof(string) }).Invoke(null, new object[] { tagContent });
            }
            catch
            {
                return(null);
            }

            try
            {
                return((AnonymizerRule)Activator.CreateInstance(
                           typeof(TResult),
                           new object[] { outputTag, method, description, processorFactory, ruleSetting }));
            }
            catch (Exception ex)
            {
                throw ex.InnerException;
            }
        }
Beispiel #2
0
        public AnonymizerTagRule(DicomTag tag, string method, string description, IAnonymizerProcessorFactory processorFactory, JObject ruleSetting = null)
            : base(method, description, processorFactory, ruleSetting)
        {
            EnsureArg.IsNotNull(tag, nameof(tag));

            Tag = tag;
        }
Beispiel #3
0
        public AnonymizerVRRule(DicomVR vr, string method, string description, IAnonymizerProcessorFactory processorFactory, JObject ruleSetting = null)
            : base(method, description, processorFactory, ruleSetting)
        {
            EnsureArg.IsNotNull(vr, nameof(vr));

            VR = vr;
        }
        public AnonymizerRuleFactory(AnonymizerConfiguration configuration, IAnonymizerProcessorFactory processorFactory)
        {
            EnsureArg.IsNotNull(configuration, nameof(configuration));
            EnsureArg.IsNotNull(processorFactory, nameof(processorFactory));

            _defaultSettings  = configuration.DefaultSettings;
            _customSettings   = configuration.CustomSettings;
            _processorFactory = processorFactory;
        }
        public AnonymizerEngine(AnonymizerConfigurationManager configurationManager, IAnonymizerProcessorFactory customProcessorFactory = null)
        {
            _configurationManager = configurationManager;
            _processors           = new Dictionary <string, IAnonymizerProcessor>();

            _customProcessorFactory = customProcessorFactory;

            InitializeProcessors(_configurationManager);

            _rules = _configurationManager.FhirPathRules;
            _logger.LogDebug("AnonymizerEngine initialized successfully");
        }
Beispiel #6
0
        public AnonymizerRule(string method, string description, IAnonymizerProcessorFactory processorFactory, JObject ruleSetting = null)
        {
            EnsureArg.IsNotNull(method, nameof(method));
            EnsureArg.IsNotNull(description, nameof(description));
            EnsureArg.IsNotNull(processorFactory, nameof(processorFactory));

            Description = description;
            processorFactory ??= new DicomProcessorFactory();
            _processor = processorFactory.CreateProcessor(method, ruleSetting);

            if (_processor == null)
            {
                throw new AnonymizerConfigurationException(DicomAnonymizationErrorCode.UnsupportedAnonymizationRule, $"Anonymization method '{method}' is not supported.");
            }
        }
        public AnonymizerEngine(AnonymizerConfigurationManager configurationManager, AnonymizerEngineOptions anonymizerSettings = null, IAnonymizerRuleFactory ruleFactory = null, IAnonymizerProcessorFactory processorFactory = null)
        {
            EnsureArg.IsNotNull(configurationManager, nameof(configurationManager));

            _anonymizerSettings = anonymizerSettings ?? new AnonymizerEngineOptions();

            ruleFactory ??= new AnonymizerRuleFactory(configurationManager.Configuration, processorFactory ?? new DicomProcessorFactory());
            _rules = ruleFactory.CreateDicomAnonymizationRules(configurationManager.Configuration.RuleContent);
            _logger.LogDebug("Successfully initialized anonymizer engine.");
        }
 public AnonymizerEngine(string configFilePath = "configuration.json", AnonymizerEngineOptions anonymizerSettings = null, IAnonymizerRuleFactory ruleFactory = null, IAnonymizerProcessorFactory processorFactory = null)
     : this(AnonymizerConfigurationManager.CreateFromJsonFile(configFilePath), anonymizerSettings, ruleFactory, processorFactory)
 {
 }
        private static AnonymizerRule TryCreateTagNameRule(string tagContent, string method, string description, IAnonymizerProcessorFactory processorFactory, JObject ruleSetting)
        {
            var nameField = typeof(DicomTag).GetField(tagContent);

            if (nameField != null)
            {
                var tag = (DicomTag)nameField.GetValue(null);
                return(new AnonymizerTagRule(tag, method, description, processorFactory, ruleSetting));
            }

            var retiredNameField = typeof(DicomTag).GetField(tagContent + "RETIRED");

            if (retiredNameField != null)
            {
                var tag = (DicomTag)retiredNameField.GetValue(null);
                return(new AnonymizerTagRule(tag, method, description, processorFactory, ruleSetting));
            }

            return(null);
        }
        public static AnonymizerEngine CreateWithFileContext(string configFilePath, string fileName, string inputFolderName, IAnonymizerProcessorFactory customProcessorFactory = null)
        {
            var configurationManager = AnonymizerConfigurationManager.CreateFromConfigurationFile(configFilePath);
            var dateShiftScope       = configurationManager.GetParameterConfiguration().DateShiftScope;
            var dateShiftKeyPrefix   = dateShiftScope switch
            {
                DateShiftScope.File => Path.GetFileName(fileName),
                DateShiftScope.Folder => Path.GetFileName(inputFolderName.TrimEnd('\\', '/')),
                _ => string.Empty
            };

            configurationManager.SetDateShiftKeyPrefix(dateShiftKeyPrefix);
            return(new AnonymizerEngine(configurationManager, customProcessorFactory));
        }
 public AnonymizerEngine(string configFilePath, IAnonymizerProcessorFactory customProcessorFactory = null) : this(AnonymizerConfigurationManager.CreateFromConfigurationFile(configFilePath), customProcessorFactory)
 {
 }