feature: Outbox Relay and Kafka Pipeline
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user