fix: do up No audit of document access in vigilcare-records-gap-analysis.md

This commit is contained in:
voltsrage
2026-06-27 15:25:18 +08:00
parent 46c3492bb9
commit 5a2e95c984
12 changed files with 220 additions and 24 deletions
@@ -73,6 +73,18 @@ public class BatchService : IBatchService
// Duplicate detection: same SHA-256 for same patient within 24 hours
if (patientId.HasValue)
{
// Atomic Redis guard prevents concurrent uploads from racing past the DB check
var cache = _redis.GetDatabase();
var dedupKey = $"batch:dedup:{sha256}:{patientId.Value}";
var acquired = await cache.StringSetAsync(dedupKey, "1",
TimeSpan.FromHours(24), When.NotExists);
if (!acquired)
throw new ConflictException(
"A document with the same content was uploaded for this patient within the last 24 hours.",
"DUPLICATE_DOCUMENT");
// DB fallback for dedup entries created before Redis guard was deployed
var cutoff = DateTimeOffset.UtcNow.AddHours(-24);
var duplicate = await _db.DigitizationBatches.AnyAsync(b =>
b.DocumentSha256 == sha256 &&
@@ -80,9 +92,12 @@ public class BatchService : IBatchService
b.CreatedAt >= cutoff);
if (duplicate)
{
await cache.KeyDeleteAsync(dedupKey);
throw new ConflictException(
"A document with the same content was uploaded for this patient within the last 24 hours.",
"DUPLICATE_DOCUMENT");
}
}
var batchId = Guid.NewGuid();