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 RedactDateTimeAndInstantNode(ElementNode node, bool enablePartialDatesForRedact = false) { var processResult = new ProcessResult(); if ((!node.IsDateTimeNode() && !node.IsInstantNode()) || string.IsNullOrEmpty(node?.Value?.ToString())) { return(processResult); } if (enablePartialDatesForRedact) { var matchedGroups = s_dateTimeRegex.Match(node.Value.ToString()).Groups; if (matchedGroups[s_yearIndex].Captures.Any()) { string yearOfDateTime = matchedGroups[s_yearIndex].Value; node.Value = IndicateAgeOverThreshold(matchedGroups) ? null : yearOfDateTime; } } else { node.Value = null; } processResult.AddProcessRecord(AnonymizationOperations.Redact, node); return(processResult); }
public static void ShiftDateTimeAndInstantNode(ElementNode node, string dateShiftKey, string dateShiftKeyPrefix, bool enablePartialDatesForRedact = false) { if (!node.IsDateTimeNode() && !node.IsInstantNode()) { return; } var matchedGroups = s_dateTimeRegex.Match(node.Value.ToString()).Groups; if (matchedGroups[s_dayIndex].Captures.Any() && !IndicateAgeOverThreshold(matchedGroups)) { int offset = GetDateShiftValue(node, dateShiftKey, dateShiftKeyPrefix); if (matchedGroups[s_timeIndex].Captures.Any()) { var newDate = DateTimeOffset.Parse(node.Value.ToString()).AddDays(offset).ToString(s_dateFormat); var timestamp = matchedGroups[s_timeIndex].Value; var timeMatch = s_timeRegex.Match(timestamp); if (timeMatch.Captures.Any()) { string time = timeMatch.Captures.First().Value; string newTime = Regex.Replace(time, @"\d", "0"); timestamp = timestamp.Replace(time, newTime); } node.Value = $"{newDate}{timestamp}"; } else { node.Value = DateTime.Parse(node.Value.ToString()).AddDays(offset).ToString(s_dateFormat); } } else { RedactDateTimeAndInstantNode(node, enablePartialDatesForRedact); } }
public void Process(ElementNode node) { if (node.IsDateNode()) { DateTimeUtility.ShiftDateNode(node, DateShiftKey, DateShiftKeyPrefix, EnablePartialDatesForRedact); } else if (node.IsDateTimeNode() || node.IsInstantNode()) { DateTimeUtility.ShiftDateTimeAndInstantNode(node, DateShiftKey, DateShiftKeyPrefix, EnablePartialDatesForRedact); } }
public static ProcessResult ShiftDateTimeAndInstantNode(ElementNode node, string dateShiftKey, string dateShiftKeyPrefix, bool enablePartialDatesForRedact = false) { var processResult = new ProcessResult(); if ((!node.IsDateTimeNode() && !node.IsInstantNode()) || string.IsNullOrEmpty(node?.Value?.ToString())) { return(processResult); } var matchedGroups = s_dateTimeRegex.Match(node.Value.ToString()).Groups; if (matchedGroups[s_dayIndex].Captures.Any() && !IndicateAgeOverThreshold(matchedGroups)) { var offset = GetDateShiftValue(node, dateShiftKey, dateShiftKeyPrefix); if (matchedGroups[s_timeIndex].Captures.Any()) { var newDate = DateTimeOffset.Parse(node.Value.ToString()).AddDays(offset).ToString(s_dateFormat); var timestamp = matchedGroups[s_timeIndex].Value; var timeMatch = s_timeRegex.Match(timestamp); if (timeMatch.Captures.Any()) { var time = timeMatch.Captures.First().Value; var newTime = Regex.Replace(time, @"\d", "0"); timestamp = timestamp.Replace(time, newTime); } node.Value = $"{newDate}{timestamp}"; } else { node.Value = DateTime.Parse(node.Value.ToString()).AddDays(offset).ToString(s_dateFormat); } processResult.AddProcessRecord(AnonymizationOperations.Perturb, node); } else { processResult = RedactDateTimeAndInstantNode(node, enablePartialDatesForRedact); } return(processResult); }
public ProcessResult Process(ElementNode node, ProcessContext context = null, Dictionary <string, object> settings = null) { var processResult = new ProcessResult(); if (string.IsNullOrEmpty(node?.Value?.ToString())) { return(processResult); } if (node.IsDateNode()) { return(DateTimeUtility.ShiftDateNode(node, DateShiftKey, DateShiftKeyPrefix, EnablePartialDatesForRedact)); } else if (node.IsDateTimeNode() || node.IsInstantNode()) { return(DateTimeUtility.ShiftDateTimeAndInstantNode(node, DateShiftKey, DateShiftKeyPrefix, EnablePartialDatesForRedact)); } return(processResult); }
public static void RedactDateTimeAndInstantNode(ElementNode node, bool enablePartialDatesForRedact = false) { if (!node.IsDateTimeNode() && !node.IsInstantNode()) { return; } if (enablePartialDatesForRedact) { var matchedGroups = s_dateTimeRegex.Match(node.Value.ToString()).Groups; if (matchedGroups[s_yearIndex].Captures.Any()) { string yearOfDateTime = matchedGroups[s_yearIndex].Value; node.Value = IndicateAgeOverThreshold(matchedGroups) ? null : yearOfDateTime; } } else { node.Value = null; } }
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; } }