Implementation plan / Session plan / Handover RC-1-S04
Handover RC-1-S04 Build: Audit¶
Card: RC-1-S04. Issue: cema-care/his#18. Branch: session/RC-1-S04. Slice: RC-1. Decision record: ADR-HIS-050.
What was built and where¶
The unit services/ess-audit, made from the service template (new-unit.sh ess-audit MOD-ESS-006), with one module, mod-ess-006 (package care.cema.his.ess.mod006, schema mod_ess_006). Its README.md documents:
- what it does, function by function;
- the export format and the integrity method, for an independent consumer;
- who may do what;
- the settings, and how to build and test.
It serves all 13 operations of audit.v1 (IF-ESS-008), consumes the intake channel his.ess.auditintake.v1 and publishes AuditEventRecorded (EVT-ESS-008) on his.ess.auditevent.v1.
| Part | Files (in mod-ess-006/src/main/) |
|---|---|
| Intake, store, quarantine, announcement | AuditStore, IntakeHandler, SubmissionValidator, EventCatalogue, PrivacyRules, Canonical |
| Reads, report, export | AuditQueries, AuditExports, AccessGuard |
| Integrity verification | IntegrityVerifications |
| Completeness, quarantine list | Completeness, Quarantine, Listing |
| HTTP | AuditController, AuditProblemAdvice, AuditValidationException |
| Jobs, alerts, settings | AuditJobs, AuditAlerts, AuditServiceProperties, Mod006Module |
| Migrations | resources/db/mod_ess_006/V1__audit_store.sql (store, triggers, records of 7.3); V2__event_catalogue.sql (generated: 205 event types of the ten domains' section 9.5, each patient-scoped at its category's default); V3__patient_scoped_registration.sql (the Domain 10 values of D10-ESS 9.5 under GAP-ESS-016, the reason of each departure, and no default for future registrations) |
| Generator | services/ess-audit/scripts/catalogue-migration.py |
How it works (the decisions are in ADR-HIS-050):
- One intake path. The API, the batch, the backbone channel and the service's own events all go through
AuditStore: - the contract's schema file, copied into the jar by the build from
contracts/ess/schemas/; - the catalogue;
- the category fields of D10-ESS 9.5 and DE-ESS-013;
- deduplication on
eventId; - the privacy rules;
- an append to the hash chain, in one transaction with the announcement.
What fails is quarantined byte for byte, with the reason, an alert (his.audit.alerts) and an ess.aud.integrity-failure event of the service's own.
- Append-only.
- The API has no update or delete.
- Database triggers refuse UPDATE, DELETE and TRUNCATE of stored events, of quarantined content and of incident evidence.
- Each event's canonical JSON is digested into a SHA-256 chain (one chain per UTC day).
- Verification, daily and on demand, finds changed content, index columns that disagree with it, gaps, broken links, removals at the end, and reordering. The affected range is marked and the rows found are kept as incident evidence.
- Access.
- Intake: a service identity only, decided locally, so that audit never depends on the decision point.
- Reads: the policy decision point, with queryPurpose and selfReview as attributes. A service identity never reads.
- Every read, permitted or refused, is recorded as ess.aud.access with its criteria and stated purpose before any answer.
This unit's copy of the kit (services/ess-audit/service-kit/, the unit's own code since new-unit.sh):
AuditEmittersends the contract's payload: no JSON nulls,beforeAfterin place ofdetails, noemittedTime, no resource reference with an empty identifier,schemaversion1.0. This is RC-1-S01's T1, T3, T4, T5 and part of T7.AuditPropertiesnames the refusal event types (denied-event-type,unavailable-event-type). Their defaults are the template's.PolicyEnforcer.require(check, RefusalAudit)lets a caller audit its own refusals. The audit service needs the criteria and purpose in them.DomainEventPublisher.publishUnsequencedis for a contract event declaredsequenced: false.build.gradle.ktspinsat.yawk.lz4:lz4-java1.11.4 andorg.xerial.snappy:snappy-java1.1.10.9. They come through kafka-clients, and the dependency scan blocked their earlier versions (CVE-2026-106451, CVE-2026-108106, CVE-2026-93451).
Dependency added: com.networknt:json-schema-validator 3.0.9 (Apache 2.0, Jackson 3, like the kit), for the intake schema. It is declared in gradle/libs.versions.toml and mod-ess-006/build.gradle.kts, and every gradle.lockfile of the unit was rewritten with ./gradlew dependencies --write-locks.
ADR-HIS-050 and its row in the decision record index (50 records). Awaiting approval by the Enterprise Architecture Board (under "Needs a person").
Checks and their result¶
The integration environment ran as HIS_SESSION=RC-1-S04 (his-rc-1-s04), light profile. The host has JDK 21 and Docker but no Node.js. The contract test therefore ran his-contract in the pinned node:22.18-bookworm image.
| Check | Command | Result |
|---|---|---|
| Build and all tests | ./gradlew build in services/ess-audit |
passed: 62 tests (module 32, kit 27, unit 3) |
| Contract test | AuditContractTest (tag contract): his-contract verify contracts/ess --operation <each audit operation> against the unit on a random port; his-contract validate-event on what it published |
verify passed, 9 intake cases with an emitter's token and 22 read cases with a reviewer's token (all 13 operations); validate-event passed, 12 AuditEventRecorded events |
| Dependency scan and SBOM | platform/delivery-pipeline/bin/dependency-scan services/ess-audit |
0 blocking (after the two pinned versions above), 4 medium |
| Image scan and SBOM | platform/delivery-pipeline/bin/image-scan services/ess-audit |
0 blocking; 15 low, 38 medium |
| Static analysis | platform/delivery-pipeline/bin/static-analysis services/ess-audit |
no blocking finding |
| Secret scan | platform/delivery-pipeline/bin/secret-scan code origin/main HEAD, and docs |
no secret found |
| Protected files | platform/delivery-pipeline/bin/protected-files origin/main HEAD |
no exception added |
| Documentation links | python3 docs/implementation_plan/tools/check_links.py |
0 broken, 0 duplicate anchors |
| Documentation site | .venv/bin/mkdocs build |
builds |
How the "Ends when" lines are met:
- Every acceptance criterion of the listed requirements has a passing test: the table below.
- The listed test scenarios pass: TEST-ESS-022 (
AuditIntakeTest), TEST-ESS-023 (AuditIntegrityAndAccessTest) and TEST-ESS-044 (AuditOutageTest), each tagged with its scenario. - The contract tests pass:
AuditContractTest, above. - The change touches only the files of its deployable unit, plus its contract tests and migrations: everything is under
services/ess-audit/. The rest is this handover and ADR-HIS-050 with its index row, as CLAUDE.md section 5 asks. No contract changed.
Requirements and test scenarios¶
Tests are in services/ess-audit/mod-ess-006/src/test/java/care/cema/his/ess/mod006/. Each class is tagged with its requirement and scenario, and each display name starts with them.
| Requirement, criterion | Test (class: method) | Scenario |
|---|---|---|
| FR-ESS-AUD-001 AC-01 (each action type of each domain) | AuditIntakeTest: everyRegisteredTypeOfEveryDomain. A conforming event of each of the 205 registered types of the ten domains, in the nine categories, is stored and found |
TEST-ESS-022 |
| FR-ESS-AUD-001 AC-02 (minimum schema) | AuditIntakeTest: storedEventHasTheMinimumSchema |
TEST-ESS-022 |
| FR-ESS-AUD-001 AC-03 (delivered twice, stored once) | AuditIntakeTest: duplicateStoredOnce, batch |
TEST-ESS-022 |
| FR-ESS-AUD-001 AC-04 (malformed: quarantine, reason, alert) | AuditIntakeTest: malformedQuarantined, backboneChannel |
TEST-ESS-022 |
| FR-ESS-AUD-001 AC-05 (reconciliation mismatch raises an exception) | AuditIntakeTest: completenessReconciliation, completenessPendingThenReconciled |
TEST-ESS-022 |
| FR-ESS-AUD-001 AC-06 (denied attempt audited as denied) | AuditIntakeTest: deniedAttemptAudited; AuditIntegrityAndAccessTest: applicationAdministratorDenied |
TEST-ESS-022 |
| FR-ESS-AUD-001 unregistered type; category fields | AuditIntakeTest: unregisteredTypeQuarantined, categoryFieldsRequired |
TEST-ESS-022 |
| FR-ESS-AUD-001 part 7 (patient-scoped types, GAP-ESS-016) | AuditIntakeTest: patientScopedRegistration (declared per type; points 1 and 2: the category defaults, the Domain 10 values of 9.5, a reason for each departure), patientScopedTypeNeedsPatient (point 3), notPatientScopedTypeStoredEitherWay (points 4 and 5: stored either way; with a patient it is in the access report) |
TEST-ESS-022 |
| FR-ESS-AUD-001 parts 6.4, 6.6, 6.8, 11; PR-AUD-001-4; NFR-ESS-015 | AuditIntakeTest: privacyRules, clockSkewFlagged, recordedAnnouncedForSubscribedCategories, reEmission, emitterCannotRead |
|
| FR-ESS-AUD-001 with BR-ESS-022 (audit outage during clinical activity) | AuditOutageTest: outageBufferedDeliveredReconciled. The kit's emitter buffers in the outbox while the relay fails; a full buffer refuses the protected action of a non-Tier-1 unit (DEC-ESS-018); on recovery all events are stored once and the emitter's count reconciles as matched. The Tier 1 branch is the kit's AuditBufferTest |
TEST-ESS-044 |
| FR-ESS-AUD-002 AC-01 (no function alters or deletes) | AuditIntegrityAndAccessTest: noAlterationOrDeletion |
TEST-ESS-023 |
| FR-ESS-AUD-002 AC-02 (out-of-band tamper detected and alerted) | AuditIntegrityAndAccessTest: tamperDetected (content, index column, removal in the middle and at the end), reorderingDetected |
TEST-ESS-023 |
| FR-ESS-AUD-002 AC-03 (query audited with criteria and purpose) | AuditIntegrityAndAccessTest: queryAudited, verificationAuditedAndListed |
TEST-ESS-023 |
| FR-ESS-AUD-002 AC-04 (application administrator denied) | AuditIntegrityAndAccessTest: applicationAdministratorDenied |
TEST-ESS-023 |
| FR-ESS-AUD-002 AC-05 (export parses, integrity intact) | AuditIntegrityAndAccessTest: exportParses. An independent parser and canonical form recompute each event's digest and the file's digest |
TEST-ESS-023 |
| FR-ESS-AUD-002 PR-AUD-002-2, part 10, parts 6.4 and 6.5 | AuditIntegrityAndAccessTest: purposeAndBoundRequired, patientAccessReport, searchPages |
|
| IF-ESS-008, EVT-ESS-008 | contract/AuditContractTest: verifyAgainstContract |
Non-functional targets, as designed for:
- NFR-ESS-007: reads are decided by the decision point; intake is for service identities only; no secret is stored (secrets are dropped from before-and-after values). The scans are clean. MFA for audit roles is the decision point's and the identity service's (FR-ESS-AUD-002 part 13).
- NFR-ESS-011: the contract test above.
- NFR-ESS-015: UTC throughout, and the 5-second skew flag.
- NFR-ESS-016: the audit service has no user-facing text beyond error messages; display is the screens' (RC-1-S23 to S25).
- NFR-ESS-017: the kit's traces and logs with the correlation identifier. The unit adds the metrics
his.audit.intake(by channel and disposition),his.audit.alerts(quarantine, completeness, integrity) andhis.audit.time_skew_flagged.
Differences from the card or specification¶
- The patient reference is required per event type, as D10-ESS GAP-ESS-016 settles it (closed 25 Nov 2026; the Domain 10 values in section 9.5). It answers this session's question Q1.
- Each type carries
patient_scoped, true by default for Record access, Record change, Disclosure and exchange, and Consent and privacy, and false for the other categories. - The Domain 10 types are registered as section 9.5 lists them: true for
ess.cns.directive,ess.cns.directive-read,ess.cns.decisionandess.auz.label-enforcement, and alsoess.auz.btgandess.auz.btg-activityoutside the four categories; false foress.wfl.task,ess.ntf.escalation,ess.ntf.delivery,ess.cns.dsr,ess.doc.registerandess.doc.resolve, each with its reason. - An event of a true type without a patient reference is quarantined as
schema-invalid(point 3). An event of a false type is stored with or without one (point 4). - The other domains' types are seeded at their category's default. Their domains register departures. Until ADM does so, an
adm.bed.changeoradm.record.exportevent without a patient is quarantined, not lost.
Every other category field of 9.5 and DE-ESS-013 is enforced. A field the table conditions on its use is required only when it applies:
- the emergency reason with an emergency session;
- the signature reference for sign and cosign;
- not the approver ("where the change needed approval").
- A category-field failure is answered 400 and quarantined as schema-invalid, like a schema failure. The contract's quarantine reasons are a closed enum (schema-invalid, unregistered-event-type), and 9.5 is part of the published audit event schema (part 6.1).
- The catalogue is a table of the unit, seeded from all ten domains' section 9.5, not the configuration item CFG-ESS-017. The configuration service (RC-1-S05) is not built, and audit.v1 has no registration operation.
- The export file is kept in the unit's database. The D02 storage channel (RustFS, RC-2) does not exist yet. contentLocation names it, but nothing serves the file there until D02 storage exists.
- AuditEventRecorded is announced for six categories by default (his.audit-service.recorded-categories): the minimum forwarding set of FR-ESS-AUD-003 part 6.2, and disclosure for D06. The forwarding rules of CFG-ESS-019 belong to FR-ESS-AUD-003, outside this card.
- The service's own audit-access events carry the patient in queryCriteria, not in patientRef. Otherwise each run of a patient's access report would appear in the next run as an access to the patient's record. A search by actor or correlation still finds them.
- Purpose codes of the service's own. Where no purpose was stated, the service records:
- audit-administration for administrative views (the quarantine, verification and completeness lists, which the contract gives no queryPurpose), when the caller sent no X-Purpose-Of-Use;
- integrity-verification for verifications;
- audit-intake for a refused intake.
The value set of the audit purpose is not named (RC-1-S01 Q10).
- A quarantine is audited as ess.aud.integrity-failure for both reasons. 9.5 names it for "quarantined event of an unregistered type" and lists no type for a schema-invalid one.
- A refused intake by a person is audited as ess.aud.access (action create, outcome denied). D10 has no event type for a denied call to a D10 service; the decision point outage case is RC-1-S01 Q9.
- A malformed batch wrapper (not 1 to 1000 events) is refused 400, and what was received is still quarantined.
- No archive tier yet: archiveUnavailable is always false. Retention, archive and disposal (part 6.7) need D02 storage and the evidence hold of FR-ESS-AUD-003.
Questions for a person¶
None left. Q1 (which audit event types are patient-scoped) is settled in the specification as GAP-ESS-016 (closed 25 Nov 2026) and is built as above. The approval of ADR-HIS-050 by the Enterprise Architecture Board is listed under "Needs a person" in the pull request.
Follow-ups outside the card¶
- Service template (
services/_template, the next session whose card covers it): - Bring the template's
AuditEmitterto the contract's payload, as this unit's copy does (RC-1-S01 T1, T3 to T5, T7). Until then, every unit made from the template has its audit quarantined asschema-invalidby this service. Nothing is lost, but nothing is stored either. - Give the refusal audit registered codes (RC-1-S01 T6, Q9).
access-denied,access-check-unavailableandrecord-createdare not in any catalogue. - Bring in
PolicyEnforcer.require(check, RefusalAudit)andDomainEventPublisher.publishUnsequenced. - Pin lz4-java 1.11.4 and snappy-java 1.1.10.9. The template's own lockfiles carry the blocked versions, so every new unit's first dependency scan fails.
- Rename
patientandencountertopatientRefandencounterRefinPolicyRequest, and omit nulls (RC-1-S01 T1, T2). This unit still sends the template's names to the decision point. - Each domain's build sessions emit category-conforming events (CONTRACT-POINTS emitter point 4). They register new event types through a migration of
services/ess-audit(scripts/catalogue-migration.py), until the catalogue moves to configuration. Each registration declarespatient_scoped, with a reason when it departs from the category default (GAP-ESS-016 point 2). - ADM build sessions (RC-1-S08, RC-1-S09): register
adm.bed.changeandadm.record.exportas not patient-scoped, with the reason (schedules, boards and beds concern no patient), as GAP-ESS-016 names them. - RC-1-S05 (configuration): an item type for the audit event catalogue (CFG-ESS-017) and the forwarding rules (CFG-ESS-019). The audit unit then reads its catalogue from there.
- RC-1-S26 (integrate): add
ess-audittoe2e/scenarios/RC-1/stack.json. Every unit's audit then reaches it over the backbone. - FR-ESS-AUD-003 (a later slice): forwarding to security monitoring with delivery confirmation and reconciliation, evidence holds, retention and disposal (FR-ESS-AUD-002 part 6.7). Also accepting a quarantined event with an annotation, which needs a contract operation (RC-1-S01 follow-up).
- D02 storage (RC-2): move the export file to RustFS with object lock, behind the existing
contentLocation. - Throughput (NFR-ESS-005, TEST-ESS-039): appends take one lock. Measure at integration, and split the chain by partition if needed (ADR-HIS-050).
- Design system: none from this session.