begin: PHI Column Encryption

This commit is contained in:
voltsrage
2026-06-22 21:18:36 +08:00
parent 518cc5b99a
commit 46db694820
21 changed files with 3177 additions and 6 deletions
@@ -10,6 +10,9 @@ public class Patient
public string? Allergies { get; set; }
public string? EmergencyContactName { get; set; }
public string? EmergencyContactPhone { get; set; }
/// <summary>HMAC token for name search. Not PHI — enables lookup without decrypting all rows.</summary>
public string? NameSearchToken { get; set; }
public string Status { get; set; } = "active";
public DateTimeOffset CreatedAt { get; set; }
@@ -0,0 +1,14 @@
public class PhiAccessLog
{
public Guid Id { get; set; }
public PhiAccessType AccessType { get; set; }
public Guid? PatientId { get; set; }
public Guid UserId { get; set; }
public string UserDisplayName { get; set; } = null!;
public string ResourcePath { get; set; } = null!;
public string? SearchQueryHash { get; set; }
public int? ResultCount { get; set; }
public string? IpAddress { get; set; }
public string? CorrelationId { get; set; }
public DateTimeOffset AccessedAt { get; set; }
}
@@ -0,0 +1,31 @@
public enum PhiAccessType
{
View,
List,
Search,
Create,
Update
}
public static class PhiAccessTypeExtensions
{
public static string ToDbString(this PhiAccessType t) => t switch
{
PhiAccessType.View => "VIEW",
PhiAccessType.List => "LIST",
PhiAccessType.Search => "SEARCH",
PhiAccessType.Create => "CREATE",
PhiAccessType.Update => "UPDATE",
_ => throw new ArgumentOutOfRangeException(nameof(t))
};
public static PhiAccessType FromDbString(string v) => v switch
{
"VIEW" => PhiAccessType.View,
"LIST" => PhiAccessType.List,
"SEARCH" => PhiAccessType.Search,
"CREATE" => PhiAccessType.Create,
"UPDATE" => PhiAccessType.Update,
_ => throw new ArgumentOutOfRangeException(nameof(v))
};
}