Explore documentation

Audit Logging

What Esus records, how to query it, and how it protects it

API-key requests identify the key in agent.userId. If your server uses an app-bound key and Esus validates the delegated user, agent.delegatedAppUserId identifies that user. Derive the identity from a session your app has verified.

What Is Recorded

EventDetail
PHI accessReads, searches, creates, updates, and deletes of PHI resources (Patient and patient-linked resources), including access through API keys
Denied accessEach 403 from the authorization layer, as outcome: "failure" with entity.resourceId: "authorization-denied"
Emergency overrideRecorded with entity.resourceType set to Resource[emergency]
Bulk export and filesAccess to /bulk-export/* and /files/*
SMARTCalls to /smart/authorize and /smart/token
App-user authenticationLogin, failed login, logout, MFA, and password or email changes for users of your apps (type: "auth")

What is not recorded today:

  • Access to resources that are not PHI, such as Practitioner, Organization, or Location.
  • Console sign-ins: only MFA changes are recorded.
  • Role changes.

Some events are written while the request is processed. Others go to a persistent queue before the response and a worker writes them to the database, so they can appear a few seconds later. Failed queue jobs are retried and are not discarded.

Querying the Log

/admin/audit endpoints return only your organization’s events. In practice, they require the admin role or an API key with the AuditEvent.read scope.

# Search, with optional filters
curl "https://api.esus.health/admin/audit?outcome=failure&date=ge2026-01-01&_count=50" \
  -H "Authorization: Bearer TOKEN"

# Direct access to a Patient resource (filters by resourceType=Patient + id)
curl "https://api.esus.health/admin/audit/patient/3fa85f64-5717-4562-b3fc-2c963f66afa6" \
  -H "Authorization: Bearer TOKEN"

# Everything done by one user
curl "https://api.esus.health/admin/audit/user/a1b2c3d4-e5f6-7890-abcd-ef1234567890" \
  -H "Authorization: Bearer TOKEN"

Filters: type, outcome, agent (userId or email), entity (resourceType or resourceId), date (with ge/le prefixes, one value per bound), _count, and _offset.

/admin/audit/patient/:id returns only events where the Patient resource was accessed. It does not include that patient’s Observations or Encounters. To see those, filter with entity by resource ID.

The response is { "rows": [...], "total": N }. Each row looks like this:

{
  "id": "e5f6a7b8-c9d0-1234-ef56-78901234abcd",
  "organizationId": "9a8b7c6d-5e4f-3210-9876-543210fedcba",
  "type": "rest",
  "subtype": "read",
  "action": "R",
  "outcome": "success",
  "recorded": "2026-01-15T10:30:00.000Z",
  "agent": {
    "userId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
    "email": "dr.smith@hospital.com",
    "ip": "203.0.113.42",
    "userAgent": "curl/8.4.0"
  },
  "source": { "site": "esus-api" },
  "entity": {
    "resourceType": "Patient",
    "resourceId": "3fa85f64-5717-4562-b3fc-2c963f66afa6"
  }
}
  • type: rest (resource access), auth (authentication), or system.
  • subtype: for rest, read, create, update, delete, or execute; for auth, the event, for example login, failed-login, or mfa-enabled.
  • action: C, R, U, D, or E. Searches use R, with resourceId: "search".
  • outcome: success or failure.
  • agent does not include roles or an emergency flag. Emergency access is identified by the [emergency] suffix on resourceType.

The /admin/stats and /admin/activity endpoints (admin only) provide summaries of organization activity.

Integrity and Retention

  • Append-only for the application: the application’s database role cannot modify or delete audit rows.
  • Tamper-evident: each row stores an HMAC-SHA256 with a server-side key that covers its contents, its position, and the previous row’s hash. This forms a separate chain for each organization. Changing, reordering, or deleting rows breaks the chain, and the verifier detects it. This mechanism detects tampering; it does not prevent it at the infrastructure level.
  • Retention: each organization has a retention policy (6 years by default). Automatic deletion is off by default. If enabled, a daily job deletes older events, and the verifier treats that gap as legitimate.

Real-Time Alerts and Export

Esus does not expose the log as a FHIR AuditEvent resource. That means it is not available through Bulk Export or /fhir/AuditEvent. For monitoring or compliance reports, query /admin/audit periodically and save the results in your own system.