feature: PHI Column Encryption + Access Logging

This commit is contained in:
voltsrage
2026-06-22 23:43:48 +08:00
parent 46db694820
commit 1824e4eef1
15 changed files with 1832 additions and 11 deletions
@@ -0,0 +1,44 @@
using Microsoft.EntityFrameworkCore;
public class PatientPhiMigrationService : IHostedService
{
private readonly IServiceProvider _services;
private readonly ILogger<PatientPhiMigrationService> _logger;
public PatientPhiMigrationService(
IServiceProvider services,
ILogger<PatientPhiMigrationService> logger)
{
_services = services;
_logger = logger;
}
public async Task StartAsync(CancellationToken ct)
{
using var scope = _services.CreateScope();
var db = scope.ServiceProvider.GetRequiredService<AppDbContext>();
var crypto = scope.ServiceProvider.GetRequiredService<IPhiEncryptionService>();
var patients = await db.Patients.ToListAsync(ct);
var migrated = 0;
foreach (var patient in patients)
{
if (patient.NameSearchToken is not null && crypto.IsEncrypted(patient.FirstName))
continue;
patient.NameSearchToken = crypto.ComputeNameSearchToken(
patient.FirstName, patient.LastName);
migrated++;
}
if (migrated > 0)
{
await db.SaveChangesAsync(ct);
_logger.LogInformation(
"PHI migration: updated {Count} patient search tokens", migrated);
}
}
public Task StopAsync(CancellationToken ct) => Task.CompletedTask;
}