begin: PHI Column Encryption
This commit is contained in:
@@ -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)));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user