Add remain services and fixes

This commit is contained in:
voltsrage
2026-06-18 23:33:39 +08:00
parent 4b46c09f90
commit e2d40331b7
9 changed files with 291 additions and 40 deletions
@@ -1,6 +1,7 @@
using FluentAssertions;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using StackExchange.Redis;
[Collection("Integration")]
@@ -206,4 +207,40 @@ public class SepsisBundleTests : IAsyncLifetime
updated.ComplianceStatus.Should().Be(SepsisBundleComplianceStatus.NonCompliant);
updated.CompletedAt.Should().NotBeNull();
}
[Fact]
public async Task DeadlinePassed_MonitorMarksNonCompliant()
{
using var scope = _fixture.Services.CreateScope();
var detector = scope.ServiceProvider.GetRequiredService<QsofaDetector>();
var db = scope.ServiceProvider.GetRequiredService<AppDbContext>();
await detector.ProcessObservationAsync(_encounterId, _patientId, "RESP_RATE", 24m);
await detector.ProcessObservationAsync(_encounterId, _patientId, "SYSTOLIC_BP", 95m);
var bundle = await db.SepsisBundles.SingleAsync();
bundle.DeadlineAt = DateTimeOffset.UtcNow.AddHours(-1);
await db.SaveChangesAsync();
var monitor = new SepsisBundleMonitorService(
_fixture.Services,
_fixture.Services.GetRequiredService<ClinicalMetrics>(),
_fixture.Services.GetRequiredService<ILogger<SepsisBundleMonitorService>>());
await monitor.ScanOverdueBundlesAsync(CancellationToken.None);
var updated = await db.SepsisBundles.AsNoTracking().SingleAsync();
updated.ComplianceStatus.Should().Be(SepsisBundleComplianceStatus.NonCompliant);
updated.CompletedAt.Should().BeNull(
"the monitor marks overdue bundles non-compliant without setting CompletedAt — " +
"elements are still incomplete");
var elements = await db.SepsisBundleElements
.AsNoTracking()
.Where(e => e.BundleId == updated.Id)
.ToListAsync();
elements.Should().AllSatisfy(e =>
e.Status.Should().Be(SepsisBundleElementStatus.Pending,
"the monitor does not complete individual elements"));
}
}