Skip to content

Commit

Permalink
Revert "Create patient resource using a deterministic id (#183)" (#186)
Browse files Browse the repository at this point in the history
This reverts commit 0600d80.
  • Loading branch information
dustinburson authored Apr 22, 2022
1 parent 27ee606 commit 62d1eca
Showing 1 changed file with 1 addition and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
// -------------------------------------------------------------------------------------------------

using System;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using EnsureThat;
using Hl7.Fhir.Model;
Expand Down Expand Up @@ -71,36 +69,13 @@ protected async Task<TResource> CreateResourceByIdentityAsync<TResource>(Model.I

propertySetter?.Invoke(resource, identifier);

// Generate id programatically and issue an update to FHIR service
// The resource will be created if the resource with the given id does not already exist.
resource.Id = ComputeSha256(identifier);
return await FhirService.UpdateResourceAsync<TResource>(resource).ConfigureAwait(false);
return await FhirService.CreateResourceAsync(resource).ConfigureAwait(false);
}

private static Model.Identifier BuildIdentifier(string value, string system)
{
var identifier = new Model.Identifier { Value = value, System = string.IsNullOrWhiteSpace(system) ? null : system };
return identifier;
}

private static string ComputeSha256(Model.Identifier identifier)
{
EnsureArg.IsNotNullOrWhiteSpace(identifier.Value, nameof(identifier.Value));

string plainTextSystemAndId = $"{identifier.System}_{identifier.Value}";

using (SHA256 hashAlgorithm = SHA256.Create())
{
byte[] bytes = hashAlgorithm.ComputeHash(Encoding.UTF8.GetBytes(plainTextSystemAndId));

StringBuilder sb = new StringBuilder();
for (int i = 0; i < bytes.Length; i++)
{
sb.Append(bytes[i].ToString("x2"));
}

return sb.ToString();
}
}
}
}

0 comments on commit 62d1eca

Please sign in to comment.