feature: Outbox Relay and Kafka Pipeline

This commit is contained in:
voltsrage
2026-06-16 22:12:46 +08:00
parent de603df151
commit 84d259d10c
18 changed files with 1277 additions and 6 deletions
@@ -1,3 +1,4 @@
using System.Text.Json;
using Microsoft.EntityFrameworkCore;
public class EncounterService : IEncounterService
@@ -41,11 +42,29 @@ public class EncounterService : IEncounterService
throw new ConflictException(
$"Transition to '{targetStatus}' is not permitted from the current status.",
"ILLEGAL_STATUS_TRANSITION");
var previousStatus = encounter.Status;
encounter.Status = targetStatus;
if (targetStatus == EncounterStatus.Discharged)
encounter.DischargedAt = DateTimeOffset.UtcNow;
_db.OutboxEvents.Add(new OutboxEvent
{
Id = Guid.NewGuid(),
Topic = "encounter.status.changed",
Payload = JsonSerializer.Serialize(new
{
encounterId,
patientId = encounter.PatientId,
previousStatus = previousStatus.ToDbString(),
newStatus = targetStatus.ToDbString(),
changedAt = DateTimeOffset.UtcNow
}),
PartitionKey = encounterId.ToString(),
CreatedAt = DateTimeOffset.UtcNow
});
await _db.SaveChangesAsync();
return new EncounterStatusTransitionResult(encounterId, targetStatus);
}