test phase 23 verification script
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
using FluentAssertions;
|
||||
|
||||
public class DataLakeEventParserTests
|
||||
{
|
||||
[Fact]
|
||||
public void ParseObservationRow_LegacyMinimalPayload_UsesFallbackFields()
|
||||
{
|
||||
var encounterId = Guid.NewGuid();
|
||||
var payload = $$"""{"code":"HEART_RATE","value":80,"encounterId":"{{encounterId}}"}""";
|
||||
|
||||
var row = DataLakeEventParser.ParseObservationRow(payload, offset: 42, partition: 2);
|
||||
|
||||
row.EncounterId.Should().Be(encounterId.ToString());
|
||||
row.ObservationCode.Should().Be("HEART_RATE");
|
||||
row.Value.Should().Be(80);
|
||||
row.ObservationId.Should().Be($"legacy:{encounterId}:42");
|
||||
row.PatientId.Should().BeEmpty();
|
||||
row.Unit.Should().BeEmpty();
|
||||
row.Source.Should().BeEmpty();
|
||||
row.RecordedAt.Should().BeEmpty();
|
||||
row.KafkaPartition.Should().Be(2);
|
||||
row.KafkaOffset.Should().Be(42);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ParseObservationRow_FullPayload_ParsesAllFields()
|
||||
{
|
||||
var payload = """
|
||||
{
|
||||
"observationId": "20facb3e-3dcb-46dd-8b81-0fa98cf097e6",
|
||||
"encounterId": "d4a0bfa6-3f3c-4dc3-a0d5-f08b574a7cb4",
|
||||
"patientId": "eff74ea8-8b02-4a45-8c85-e28604247cc0",
|
||||
"mrn": "MRN-000001",
|
||||
"observationCode": "HEART_RATE",
|
||||
"value": 165,
|
||||
"unit": "bpm",
|
||||
"source": "DEVICE",
|
||||
"recordedAt": "2026-06-23T17:08:20+00:00"
|
||||
}
|
||||
""";
|
||||
|
||||
var row = DataLakeEventParser.ParseObservationRow(payload, offset: 99, partition: 0);
|
||||
|
||||
row.ObservationId.Should().Be("20facb3e-3dcb-46dd-8b81-0fa98cf097e6");
|
||||
row.Mrn.Should().Be("MRN-000001");
|
||||
row.Unit.Should().Be("bpm");
|
||||
row.RecordedAt.Should().Be("2026-06-23T17:08:20+00:00");
|
||||
}
|
||||
}
|
||||
@@ -116,6 +116,25 @@ public class TrendDetectorTests : IAsyncLifetime
|
||||
(await redis.GetDatabase().KeyExistsAsync(key)).Should().BeFalse();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task UnknownEncounter_SkipsAlert()
|
||||
{
|
||||
using var scope = _fixture.Services.CreateScope();
|
||||
var detector = scope.ServiceProvider.GetRequiredService<TrendDetector>();
|
||||
var unknownEncounterId = Guid.NewGuid();
|
||||
|
||||
await detector.ProcessObservationAsync(
|
||||
unknownEncounterId, _patientId, "HEART_RATE", 72m, BaseTime);
|
||||
var result = await detector.ProcessObservationAsync(
|
||||
unknownEncounterId, _patientId, "HEART_RATE", 95m, BaseTime.AddMinutes(10));
|
||||
|
||||
result.Outcome.Should().Be(TrendOutcome.EncounterNotFound);
|
||||
result.AlertCreated.Should().BeFalse();
|
||||
|
||||
var db = scope.ServiceProvider.GetRequiredService<AppDbContext>();
|
||||
(await db.ClinicalAlerts.CountAsync()).Should().Be(0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task DuplicateTrendAlert_Idempotent()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user