public ProcessResult ProcessNodeRecursive(ElementNode node, IAnonymizerProcessor processor, ProcessContext context, Dictionary <string, object> settings) { var result = new ProcessResult(); if (_visitedNodes.Contains(node)) { return(result); } result = processor.Process(node, context, settings); _visitedNodes.Add(node); foreach (var child in node.Children().CastElementNodes()) { if (child.IsFhirResource()) { continue; } result.Update(ProcessNodeRecursive(child, processor, context, settings)); } return(result); }
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 ProcessResult ProcessNodeRecursive(ElementNode node, IAnonymizerProcessor processor, HashSet <ElementNode> visitedNodes) { ProcessResult result = new ProcessResult(); if (visitedNodes.Contains(node)) { return(result); } result = processor.Process(node); visitedNodes.Add(node); foreach (var child in node.Children().Cast <ElementNode>()) { if (child.IsFhirResource()) { continue; } result.Update(ProcessNodeRecursive(child, processor, visitedNodes)); } return(result); }
public void GivenADicomMaskedTagRuleWithSubstitution_WhenCreateAnonymizerRule_DicomMaskedTagRuleShouldBeCreateCorrectly(string config, DicomMaskedTag expectedMaskedTag, IAnonymizerProcessor expectedProcessor) { var rule = _ruleFactory.CreateDicomAnonymizationRule(JsonConvert.DeserializeObject <JObject>(config)); var processor = typeof(AnonymizerRule).GetField("_processor", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(rule); Assert.Equal(expectedMaskedTag.ToString(), ((AnonymizerMaskedTagRule)rule).MaskedTag.ToString()); Assert.Equal(expectedProcessor.GetType(), processor.GetType()); var expectedReplaceString = expectedProcessor.GetType().GetField("_replaceString", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(expectedProcessor); var outputReplaceString = processor.GetType().GetField("_replaceString", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(processor); Assert.Equal(expectedReplaceString, outputReplaceString); }
public void GivenADicomMaskedTagRuleWithCryptoHash_WhenCreateAnonymizerRule_DicomMaskedTagRuleShouldBeCreateCorrectly(string config, DicomMaskedTag expectedMaskedTag, IAnonymizerProcessor expectedProcessor) { var rule = _ruleFactory.CreateDicomAnonymizationRule(JsonConvert.DeserializeObject <JObject>(config)); var processor = typeof(AnonymizerRule).GetField("_processor", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(rule); Assert.Equal(expectedMaskedTag.ToString(), ((AnonymizerMaskedTagRule)rule).MaskedTag.ToString()); Assert.Equal(expectedProcessor.GetType(), processor.GetType()); var expectedFunction = expectedProcessor.GetType().GetField("_cryptoHashFunction", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(expectedProcessor); var outputFunction = processor.GetType().GetField("_cryptoHashFunction", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(processor); foreach (var prop in outputFunction.GetType().GetProperties()) { Assert.Equal(expectedFunction.GetType().GetProperty(prop.Name).GetValue(expectedFunction), outputFunction.GetType().GetProperty(prop.Name).GetValue(outputFunction)); } }
public void GivenADicomVRRuleWithDateShift_WhenCreateAnonymizerRule_DicomVRRuleShouldBeCreateCorrectly(string config, DicomVR expectedVR, IAnonymizerProcessor expectedProcessor) { var rule = _ruleFactory.CreateDicomAnonymizationRule(JsonConvert.DeserializeObject <JObject>(config)); var processor = typeof(AnonymizerRule).GetField("_processor", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(rule); Assert.Equal(expectedVR, ((AnonymizerVRRule)rule).VR); Assert.Equal(expectedProcessor.GetType(), processor.GetType()); var expectedFunction = expectedProcessor.GetType().GetField("_dateShiftFunction", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(expectedProcessor); var expectedSetting = expectedFunction.GetType().GetField("_dateShiftSetting", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(expectedFunction); var outputFunction = processor.GetType().GetField("_dateShiftFunction", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(processor); var outputSetting = outputFunction.GetType().GetField("_dateShiftSetting", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(outputFunction); foreach (var prop in outputSetting.GetType().GetProperties()) { Assert.Equal(expectedSetting.GetType().GetProperty(prop.Name).GetValue(expectedSetting), outputSetting.GetType().GetProperty(prop.Name).GetValue(outputSetting)); } }
public void GivenADicomRuleWithMethodsDoNotNeedSetting_WhenCreateAnonymizerRule_DicomRuleShouldBeCreateCorrectly(string config, DicomTag expectedTag, IAnonymizerProcessor expectedProcessor) { var rule = _ruleFactory.CreateDicomAnonymizationRule(JsonConvert.DeserializeObject <JObject>(config)); var processor = typeof(AnonymizerRule).GetField("_processor", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(rule); Assert.Equal(expectedTag, ((AnonymizerTagRule)rule).Tag); Assert.Equal(expectedProcessor.GetType(), processor.GetType()); }
public void AddProcessor(string key, IAnonymizerProcessor processor) { _processors[key.ToUpperInvariant()] = processor; }