Skip to content

Audit Trails & HIPAA WORM Compliance

Operational traceability and healthcare regulatory compliance require knowing both how records changed and who viewed or disclosed protected records — stored on an isolated append-only ledger guarded against silent tampering.


1. Operational Traceability: Auditable, SoftDelete & State History

General operational entities track full mutation provenance automatically via built-in platform traits:

  • Auditable Trait: Injects indexed createdAt (DateTime) and updatedAt (DateTime) timestamps maintained automatically across creates and updates.
  • SoftDelete Trait: Appends nullable deletedAt (DateTime?) so record removals preserve referential audit continuity across contracts, invoices, and completed work orders.
  • State Machine Audit Trails: Transitions (AssignTechnician, CompleteWorkOrder, ConfirmAppointment) log structured actor, timestamp, and prior-to-next status transitions cleanly on domain workflows.

2. Dedicated ePHIAudited Access Logging Microservice

Regulated clinical and financial entities attach the ePHIAudited trait (retentionYears: 7, logAccessViews: true). Whenever a generated controller executes READ_QUERY (list/view), READ_VIEW (findOne), CREATE, UPDATE, or DELETE, it dispatches an asynchronous audit event via AuditClientService.logAccess(...) to the dedicated perlite-audit-service sidecar microservice:

  1. Authenticated Sidecar Dispatch: Sends POST ${AUDIT_SERVICE_URL}/api/audit/events carrying an x-audit-service-token shared secret validated with constant-time crypto.timingSafeEqual comparison.
  2. Fail-Safe Resilience: If the sidecar endpoint experiences transient pressure or timeout (1,500 ms budget), AuditClientService logs structured warnings cleanly so emergency clinical reads remain responsive.
  3. Structured Identity Metadata: Every event records actorId, actorRole, targetEntity, recordId, patientId, actionType, and forwarded clientIp.

3. Cryptographic HMAC-SHA256 Hash Chaining & WORM Archival

Inside perlite-audit-service, AuditStore maintains an append-only tamper-evident ledger:

  • Linked Hash Chain (prevHash → eventHash): Each persisted event authenticates its normalized JSON payload together with the preceding event’s eventHash using keyed HMAC-SHA256 (AUDIT_HMAC_SECRET) before appending to hipaa-audit.jsonl, exposing GET /api/audit/verify to prove zero historical gaps or edits.
  • Immutable S3 WORM Archives (ArchiverService): Nightly batch archival computes a batch sha256Checksum (AuditArchiveManifest) and writes compliance archives into immutable S3 Object Lock (COMPLIANCE mode) buckets configured for 2,555 days (7 years) under the hipaa-sox-prod compliance policy.

4. Guided Example — Operational Ledgers vs HIPAA Hash-Chained Auditing

Security & Operations · Guide 4 of 5
Auditable Lifecycles, ePHIAudited Dispatch & HMAC-SHA256 Hash-Chained WORM Archival
Previously in this build: In Guide 3, Customer protected siteAccessPin with AES-256-GCM envelopes while dispatchers logged WorkOrder updates.
✅ Checkpoint:WorkOrder retains continuous timestamp, soft-delete, and actor custody across every dispatch transition.
Primary TrackTrack WorkOrder creation, SLA mutations, soft deletions, and state transitions through Auditable, SoftDelete, and hash-chained AuditStore integrity guarantees.
  1. Compose MultiTenant, SoftDelete & Auditable on WorkOrder: Inspect WorkOrder to confirm createdAt, updatedAt, and deletedAt timestamps track full operational custody across customer dispatches.
  2. Guard CreateOne With @RequirePermission & Context User: Verify WorkOrderController.create injects verified req.user identity into the service pipeline so every record mutation attributes cleanly.
  3. Inspect Cryptographic Event Chaining: Review AuditStore hash-chain calculation below showing how every recorded ledger entry seals with keyed HMAC-SHA256 (AUDIT_HMAC_SECRET) over the previous chain hash.