public ProcessResult Process(ElementNode node, ProcessContext context = null, Dictionary <string, object> settings = null) { if (string.IsNullOrEmpty(node?.Value?.ToString())) { return(new ProcessResult()); } if (node.IsDateNode()) { return(DateTimeUtility.RedactDateNode(node, EnablePartialDatesForRedact)); } if (node.IsDateTimeNode() || node.IsInstantNode()) { return(DateTimeUtility.RedactDateTimeAndInstantNode(node, EnablePartialDatesForRedact)); } if (node.IsAgeDecimalNode()) { return(DateTimeUtility.RedactAgeDecimalNode(node, EnablePartialAgesForRedact)); } if (node.IsPostalCodeNode()) { return(PostalCodeUtility.RedactPostalCode(node, EnablePartialZipCodesForRedact, RestrictedZipCodeTabulationAreas)); } node.Value = null; var result = new ProcessResult(); result.AddProcessRecord(AnonymizationOperations.Redact, node); return(result); }
public static ProcessResult RedactPostalCode(ElementNode node, bool enablePartialZipCodesForRedact = false, List <string> restrictedZipCodeTabulationAreas = null) { var processResult = new ProcessResult(); if (!node.IsPostalCodeNode() || string.IsNullOrEmpty(node?.Value?.ToString())) { return(processResult); } if (enablePartialZipCodesForRedact) { if (restrictedZipCodeTabulationAreas != null && restrictedZipCodeTabulationAreas.Any(x => node.Value.ToString().StartsWith(x))) { node.Value = new string(s_replacementDigit, node.Value.ToString().Length); } else if (node.Value.ToString().Length >= s_initialDigitsCount) { node.Value = $"{node.Value.ToString().Substring(0, s_initialDigitsCount)}{new string(s_replacementDigit, node.Value.ToString().Length - s_initialDigitsCount)}"; } processResult.AddProcessRecord(AnonymizationOperations.Abstract, node); } else { node.Value = null; processResult.AddProcessRecord(AnonymizationOperations.Redact, node); } return(processResult); }
public void Process(ElementNode node) { if (node.IsDateNode()) { DateTimeUtility.RedactDateNode(node, EnablePartialDatesForRedact); } else if (node.IsDateTimeNode() || node.IsInstantNode()) { DateTimeUtility.RedactDateTimeAndInstantNode(node, EnablePartialDatesForRedact); } else if (node.IsAgeDecimalNode()) { DateTimeUtility.RedactAgeDecimalNode(node, EnablePartialAgesForRedact); } else if (node.IsPostalCodeNode()) { PostalCodeUtility.RedactPostalCode(node, EnablePartialZipCodesForRedact, RestrictedZipCodeTabulationAreas); } else { node.Value = null; } }
public static void RedactPostalCode(ElementNode node, bool enablePartialZipCodesForRedact = false, List <string> restrictedZipCodeTabulationAreas = null) { if (!node.IsPostalCodeNode()) { return; } if (enablePartialZipCodesForRedact) { if (restrictedZipCodeTabulationAreas != null && restrictedZipCodeTabulationAreas.Any(x => node.Value.ToString().StartsWith(x))) { node.Value = new string(s_replacementDigit, node.Value.ToString().Length); } else if (node.Value.ToString().Length >= s_initialDigitsCount) { node.Value = $"{node.Value.ToString().Substring(0, s_initialDigitsCount)}{new string(s_replacementDigit, node.Value.ToString().Length - s_initialDigitsCount)}"; } } else { node.Value = null; } }