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
@@ -0,0 +1,42 @@
using Microsoft.EntityFrameworkCore;
public static class PatientPhiConverterConfigurator
{
public static void ConfigurePhiConverters(
this ModelBuilder modelBuilder,
IPhiEncryptionService crypto)
{
var entity = modelBuilder.Entity<Patient>();
entity.Property(p => p.FirstName)
.HasConversion(
v => crypto.Encrypt(v),
v => crypto.Decrypt(v));
entity.Property(p => p.LastName)
.HasConversion(
v => crypto.Encrypt(v),
v => crypto.Decrypt(v));
entity.Property(p => p.Allergies)
.HasConversion(
v => v == null ? null! : crypto.Encrypt(v),
v => v == null ? null : crypto.Decrypt(v));
entity.Property(p => p.EmergencyContactName)
.HasConversion(
v => v == null ? null! : crypto.Encrypt(v),
v => v == null ? null : crypto.Decrypt(v));
entity.Property(p => p.EmergencyContactPhone)
.HasConversion(
v => v == null ? null! : crypto.Encrypt(v),
v => v == null ? null : crypto.Decrypt(v));
// DateOfBirth stored as encrypted ISO string
entity.Property(p => p.DateOfBirth)
.HasConversion(
v => crypto.Encrypt(v.ToString("yyyy-MM-dd")),
v => DateOnly.Parse(crypto.Decrypt(v)));
}
}