A concrete .NET architecture for immutable healthcare audit logs with user attribution, versioning, and regulator-friendly query patterns.
Compliance requirement
Audit logs in healthcare systems must be complete, tamper-evident, and queryable by patient, test, operator, and time window.
Event envelope pattern
csharp
public sealed record AuditEvent(
Guid Id,
string AggregateType,
string AggregateId,
string Action,
string ActorId,
DateTimeOffset OccurredAt,
string PayloadJson,
string Hash
);Write pipeline
- application command commits domain write
- transaction outbox emits audit event
- append-only audit store persists event
- hash chain validator checks integrity nightly
Query pattern for inspectors
sql
SELECT aggregate_id, action, actor_id, occurred_at
FROM audit_events
WHERE aggregate_type = 'LabResult'
AND occurred_at BETWEEN :from AND :to
ORDER BY occurred_at DESC;Final takeaway
If auditability is designed from day one, compliance reporting becomes a query problem instead of a reconstruction project.