public ProcessResult Process(ElementNode node) { var processResult = new ProcessResult(); if (string.IsNullOrEmpty(node?.Value?.ToString())) { return(processResult); } var input = node.Value.ToString(); // Hash the id part for "Reference.reference" node and hash whole input for other node types if (node.IsReferenceStringNode()) { var newReference = ReferenceUtility.TransformReferenceId(input, _cryptoHashFunction); node.Value = newReference; } else { node.Value = _cryptoHashFunction(input); } _logger.LogDebug($"Fhir value '{input}' at '{node.Location}' is hashed to '{node.Value}'."); processResult.AddProcessRecord(AnonymizationOperations.CryptoHash, node); 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); } // prefix the domain, if set var domainPrefix = settings?.GetValueOrDefault("domain-prefix", string.Empty); var domain = settings? .GetValueOrDefault("domain", null)? .ToString(); var input = node.Value.ToString(); // Pseudonymize the id part for "Reference.reference" node and // pseudonymize whole input for other node types if (node.IsReferenceStringNode() || IsReferenceUriNode(node, input)) { // if the domain setting is not set, // create a domain from the reference, ie "Patient/123" -> "Patient" domain ??= ReferenceUtility .GetReferencePrefix(input) .TrimEnd('/'); node.Value = ReferenceUtility.TransformReferenceId( input, x => GetOrCreatePseudonym(x, domainPrefix + domain)); } else { node.Value = GetOrCreatePseudonym(input, domainPrefix + domain); } processResult.AddProcessRecord(AnonymizationOperations.Pseudonymize, node); return(processResult); }