fix: do up No audit of document access in vigilcare-records-gap-analysis.md
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user