Skip to content

Implementation plan / Session plan / Handover RC-2-S02

Handover RC-2-S02 Build: Runtime decision services (consent directives)

Card: RC-2-S02. Issue: cema-care/his#47. Branch: session/RC-2-S02. Slice: RC-2. Decision record: ADR-HIS-073.

What was built and where

MOD-ESS-003 in services/ess-runtime-decision/mod-ess-003, the consent directive lifecycle of FR-ESS-CNS-001. It serves all seven operations of consent.v1 (IF-ESS-005) at their contract paths, and publishes ConsentChanged (EVT-ESS-002) on his.ess.consentdirective.v1 through the outbox. The aggregate is ConsentDirective, its id the consentDirectiveId, with no facility in the envelope.

  • Versions (part 6.2, BR-ESS-013; ADR-HIS-073 point 1):
  • every change writes a new version: record, new version, activation, expiry, withdrawal, entered-in-error, supersession by another directive, reassignment and restoration;
  • the schema refuses to update or delete a version row;
  • the directive's current version is the ETag, and a stale If-Match answers 412;
  • a version replaced by a later version of the same directive is noted once (version_superseded). The history and ?version= answer it superseded with supersededBy, and ?asAt= answers the status that was in force.
  • The consent model (part 6.1, CFG-ESS-010; ADR-HIS-073 point 2):
  • governed versions arrive as ConfigurationChanged of item type ess.consent-model, key enterprise. They are read from the configuration service, hash-checked, and apply from their effective time, and a rollback is honoured;
  • the unapproved starter consent/consent-model.v1.json holds the five types of DEC-ESS-009 with placeholder purposes, scopes, recipients and legal bases. It is installed only with his.consent.seed-enabled, never in production;
  • without a model, recording answers 503.
  • Validation (part 10, PR-CNS-001-4; ADR-HIS-073 point 3), with the part 10 messages as written:
  • schema errors first;
  • then the model: a purpose, scope, recipient, legal basis or validity the type does not allow is refused on every path;
  • on a direct record, a missing required attribute is refused, with "Select the legal basis." for the legal basis;
  • on a capture (a context from a capturing domain, or the completion of a Proposed directive), missing attributes are listed in outstandingAttributes and the directive is Proposed;
  • a representative without authority is refused ("Record the representative's authority.") or, on a capture, held as outstanding;
  • the patient is resolved through readPerson of patient-identity.v1, a merged identifier to its survivor. An unknown patient gets "Patient could not be identified.", and Domain 1 unavailable is 503.
  • States (section 4.3):
  • Proposed while incomplete, or until a future validity start (Q-RC2-5);
  • the job activateDue makes it Active at that time, and expireDue makes it Expired at its validity end, without user action (AC-03);
  • withdrawal from Active, with an effective time not before it is recorded (AC-02). A withdrawal with a future effective time leaves the directive Active until then: it is kept in mod_ess_003.scheduled_withdrawal, and the job writes the Withdrawn version, with the provenance of the person who withdrew, and publishes ConsentChanged at that time (Directives.withdrawDue, DEC-ESS-009 point 6). Until then the current read shows statusReason "Withdrawal recorded; it takes effect at ...". A directive that expires or is marked entered in error first is not withdrawn;
  • entered in error from Proposed or Active, by a person with privacy officer authority, with a mandatory reason.
  • Supersession and conflicts (PR-CNS-001-1, PR-CNS-001-2; ADR-HIS-073 point 4):
  • a directive becoming Active supersedes the patient's Active ones of the same type, purposes and recipients;
  • two Active directives with opposite decisions that overlap in purposes, recipients, scope and validity are both kept and both carry conflict, and conflict-flagged is published;
  • a task ess.consent-conflict-review in ess.privacy-review is sent after commit (ports/ReviewTasks, Idempotency-Key from the conflict). Its taskId becomes conflict.reviewTaskId;
  • a conflict is resolved when either directive stops being Active.
  • Merge (part 6.8, AC-05): Directives.reassign(mergeRef, retired, survivor) holds every directive of the retired identity under the survivor, with reassignedFrom, and flags the conflicts. Directives.restore(mergeRef) undoes exactly that merge. Both publish (reassigned, restored) and are idempotent.
  • Reads (part 9, part 13): every read needs X-Purpose-Of-Use (else 400), asks the policy and is audited (ess.cns.directive-read, with the directive versions shown). asAt and version are not given together.
  • Audit (part 12): ess.cns.directive on create, new version, supersede, activate, withdraw, expire, entered in error, reassign, restore, and on conflict flagged and resolved. Each carries the patient, author, channel, consent type, before-and-after status, and the decision and policy version where a person or service acted.
  • Policy (ADR-HIS-073 point 6): resource type ess.ConsentDirective and actions ess.cns.directive.create|revise|withdraw|mark-entered-in-error|read|list. The rules cns-* and their resource type are added to the unit's starter policy mod-ess-002/src/main/resources/policy/enterprise-access.v1.json, and the test pack gains TP-36 to TP-49. The rules carry the conditions of part 3 as ADR-HIS-073 point 6 sets them (the answers to Q5 and Q6):
    • a person acts only for a patient who holds a No. RM at the facility the person acts for; Access reads the patient's facilities from Domain 1 (PatientDirectory.read) and sends them as patientFacilities;
    • each recording role records only its consent types, and each caller only its purposes; payment is refused;
    • the privacy officer reads any patient's directives; the role is privileged, so it is in force only with a second factor (aal2), and the rule has no step-up flag of its own;
    • a request without a purpose is never permitted.
  • The content of enterprise-access version 1 was changed in place: it is still unapproved starter content, which no environment has imported through the configuration lifecycle. Its sha256 is now sha256:0ecb6e7c6e03df28243914a0864937ba98333c275bf8785942c199e3ecf3b23e, against sha256:984b867f36afc99759397315e7000292a5c4690f63da55045788ea766185150a on main before this session. That is the hash ess-governance should import and the version's contentHash should show. The unit seeds the starter only into a policy that has no version yet, so an existing environment keeps the old content until it is reset.
  • Metrics: his.consent.changes{change, consentType} and his.consent.review-task.unsent.
  • Migration V1__consent_directives.sql (schema mod_ess_003).
  • No external dependency was added: no lockfile changed. MOD-ESS-003 uses no other module (the module boundary test passes). Two components are named explicitly (consentAccess, consentCommands) because MOD-ESS-001 has classes of the same simple name.
  • The unit README has a MOD-ESS-003 section with the settings his.consent.*.

Checks and their result

The integration environment ran as HIS_SESSION=RC-2-S02 (his-rc-2-s02), light profile. OPA and the contract tools ran in their pinned images through the tests' own Docker calls. The first his-env start hit the PostgreSQL first-start race recorded in RC-1-S17's handover; a second start passed, and smoke passed 4 of 4.

Check Command Result
Build and every test of the unit ./gradlew build in services/ess-runtime-decision passed: 248 tests. MOD-ESS-003 39, MOD-ESS-002 84 (70 before, plus TP-36 to TP-49), MOD-ESS-001 89, kit 31, app 5. 4 skipped on the light profile, as before: the 3 Keycloak adapter tests and the Kafka adapter test
Provider contract test ./gradlew :mod-ess-003:test --tests '*ConsentContractTest' passed. his-contract verify contracts/ess for each of the seven operations, 17 cases, none failed. The 17 ConsentChanged events published pass his-contract validate-event. They cover all eight kinds of change: activated, superseded, conflict-flagged, expired, withdrawn, entered-in-error, reassigned, restored
Policy test pack ./gradlew :mod-ess-002:test --tests '*PolicyTestPackTest' passed: 49 cases (TP-01 to TP-49 as numbered in the pack) and the coverage check
Dependency scan and SBOM platform/delivery-pipeline/bin/dependency-scan services/ess-runtime-decision 0 blocking (6 medium, as before)
Image scan platform/delivery-pipeline/bin/image-scan services/ess-runtime-decision 0 blocking (15 low, 116 medium, as before)
Static analysis platform/delivery-pipeline/bin/static-analysis services/ess-runtime-decision no blocking finding
Secret scan platform/delivery-pipeline/bin/secret-scan code origin/main HEAD, and docs no secret; no exception file added
Documentation check_links.py; mkdocs build 0 broken links, 0 duplicate anchors; the site builds

consent.v1 is enterprise-scoped (x-his-facility: enterprise), so verify has no facility cases. The facility of a request is kept as provenance.facility (ac01RecordedAndRetrievable) and sent to the policy as requestFacility.

Requirements and test scenarios

Tests are in services/ess-runtime-decision/mod-ess-003/src/test/java/care/cema/his/ess/mod003/. Each class carries @Tag("FR-ESS-CNS-001") @Tag("TEST-ESS-012"), and every display name starts with them.

Requirement, criterion Test
AC-01 a valid directive is retrievable with subject, purpose, scope, recipient, validity, status, legal basis and provenance ConsentDirectiveTest.ac01RecordedAndRetrievable
AC-02 a withdrawal emits ConsentChanged; current status Withdrawn; prior version retrievable ConsentDirectiveTest.ac02Withdrawal; a future effective time: futureWithdrawal, futureWithdrawalOverAClosedOne, expiryBeforeScheduledWithdrawal
AC-03 Expired at the validity end without user action (PR-CNS-001-3) ConsentDirectiveTest.ac03Expiry
AC-04 the versions in force at a past time ConsentDirectiveTest.ac04AsAt
AC-05 a merge holds both identities' directives under the survivor and flags the conflict (and an unmerge restores them) ConsentDirectiveTest.ac05Merge (service level; see below)
PR-CNS-001-1 supersession, history kept ConsentDirectiveTest.pr1Supersedes
PR-CNS-001-2 conflict kept, flagged, privacy review task ConsentDirectiveTest.pr2Conflict
PR-CNS-001-4 a reference without the required attributes is Proposed, never used to permit ConsentDirectiveTest.pr4ProposedReference
Section 4.3, Q-RC2-5: future start Proposed, then Active ConsentDirectiveTest.futureStart
Section 4.3: entered in error ConsentDirectiveTest.enteredInError
Part 10: type and scope; legal basis; patient; representative ConsentDirectiveTest.part10Scope, part10LegalBasis, part10Patient, part10Representative
Part 7: validity, withdrawal time, malformed request ConsentDirectiveTest.part7Validation
BR-ESS-013: no version changed or deleted ConsentDirectiveTest.versionsImmutable
IF-ESS-005: If-Match, Idempotency-Key ConsentDirectiveTest.concurrencyAndIdempotency
Part 12: audit of writes and reads ConsentDirectiveTest.audited
Part 13: purpose required, policy decides, an outage is not a refusal ConsentDirectiveTest.security
Part 6.1, CFG-ESS-010: governed model, effective time, rollback, hash; no model 503 ConsentModelTest.governedModel, hashMismatch, noModelNoRecording
Part 13: the starter model is never used in production ConsentStarterInProductionTest.starterIgnoredInProduction
IF-ESS-005, EVT-ESS-002 contract/ConsentContractTest
Policy rules of ess.ConsentDirective mod-ess-002 PolicyTestPackTest TP-36 to TP-49: role, action, purpose (TP-41, TP-42, TP-47, TP-48), patient relationship (TP-43, TP-44), consent type (TP-45, TP-46), privacy officer (TP-49); ConsentDirectiveTest.authorizedForThePatient, HttpPatientDirectoryTest

TEST-ESS-012 (record, supersede, withdraw, expire; as-of query; patient merge; versions retained, events emitted, correct as-of result, conflicts flagged) is ConsentDirectiveTest. All pass.

Non-functional targets designed for: - NFR-ESS-007 Security: - deny by default through the policy decision point; - entered in error is for a person only, a privacy officer with step-up; - the starter model is never used in production; - versions are immutable in the schema; - every read needs a purpose and is audited; - no patient data in events beyond the enterprise person identifier. - NFR-ESS-011 Interoperability: every operation passes his-contract verify, and ConsentChanged passes validate-event. FHIR Consent (part 6.10) is not in version 1 of the contract. - NFR-ESS-015 Time integrity: - UTC to the millisecond; - recorded time and effective time are kept apart. The effective time of an activation or expiry is the validity start or end, not the time the job ran. - NFR-ESS-016 Localization: the user messages are the specification's part 10 wording; the codes are configuration. - NFR-ESS-017 Observability: the metrics above; logs with correlation; traces from the kit.

Done differently from the specification or contract, and why

  • AC-05 is tested at the service level. PatientMerged and PatientUnmerged (EVT-ADM-005, -006) are not in contracts/adm yet; contract point 8 defers them to RC-3. reassign and restore are built and tested; only the subscription that calls them waits for those events (follow-up).
  • A new version of an Active directive with a later validity start is refused (400 on /validityStart, "A new version of an active directive applies when it is recorded. Record a new directive for a later start."). Otherwise the directive would leave force before its replacement starts, and for a deny that widens access. The new directive then supersedes the old one when it becomes Active (ADR-HIS-073 point 3).
  • A withdrawal with a future effective time answers 200 with the directive still Active (its statusReason names the time), not a Withdrawn version. The contract says a withdrawal "affects decisions after its effective time only" and DEC-ESS-009 point 6 that it applies from its timestamp onward, so the Withdrawn version and ConsentChanged are written at that time by the job. No contract field was added.
  • A capture versus a direct record decides between Proposed and refusal (ADR-HIS-073 point 3). The contract says only "where policy allows".
  • Listing by a retired identifier after a merge answers nothing. The directives are held under the survivor, and readConsentDirective by identifier answers them there. Resolving the list's patient through Domain 1 on every read would make consent reads depend on adm-identity.
  • The directive source in provenance is /his/<domain>/<unit> for a calling service and /his/ess/ess-runtime-decision for a person. The API does not know which screen a person used (the contract's example shows /his/ess/ui-ess-006).
  • The starter policy content enterprise-access version 1 changed (the cns-* rules). It has not been approved yet, so the import into ess-governance takes the content as it is now.
  • The contract was not changed.

Brought up to date with main

Main took ADR-HIS-071 (RC-1-S25) and then ADR-HIS-072 (the self-hosted pipeline runners) while this pull request was open, so this session's record is now ADR-HIS-073. Every reference was renumbered each time, and the index has 73 records. Main changed nothing under services/ or contracts/. After that merge, ./gradlew build passed again with the same 233 tests the branch had then (the current total is in the checks table). A first forced full rerun put 4 MOD-ESS-002 tests at 503: OPA was slower than its 200 ms timeout while every module's tests ran at once on this host. All 75 tests of the module passed when it was run alone, and the full build passed after.

A third merge brought in ADR-HIS-074 (RC-2-S03), which left 073 free, so the record keeps its number and the index has 74 records. It also brought in the PostgreSQL first-start fix to platform/dev-environment (#157): the health check now runs over TCP, and his-env retries creating the unit databases. The pipeline failed twice on this race before the fix.

A fourth merge brought in ADR-HIS-078 and ADR-HIS-079 (RC-2-S07, RC-2-S08). 073 was still free, so the record keeps its number, and the index has 76 records. Main changed nothing under services/ or contracts/.

A fifth merge brought in ADR-HIS-077 and ADR-HIS-080. 073 was still free, so the record keeps its number, and the index has 78 records. Main changed services/adm-scheduling-flow and the scheduling contract of contracts/adm, neither of which this unit uses.

Questions for a person

Q5 and Q6: the session proposed answers following common practice, on the repository owner's instruction, and the repository owner adopted them as built on 2026-11-27 ("adopt what is already built in the branch"). The adoption is recorded on issue #47; the cns-* rules and ADR-HIS-073 point 6 carry it. The owner of D10-ESS and the privacy officer may change the conditions as policy content. Q7 is settled by the specification (review round 3). Each is listed under "Needs a person" in the pull request.

# Question Owner What the unit does now
Q1 The consent model content: for each of the five types, the permitted purposes, scope categories and labels, recipient kinds, legal-basis codes and maximum validity, and which attributes a directive needs before it is Active (CFG-ESS-010, part 13 "validated by legal advice") Privacy officer, with legal advice Unapproved starter content in non-production only; production answers 503 until a governed version is active
Q2 The privacy review task of a conflict: its priority and due time Privacy officer Starter routine, due in 3 days
Q3 Which roles are consent recording users (ACT-ESS-012 names registration clerk, HIM officer, clinician) Owner of D10-ESS, Security and Privacy Office patient-access-and-flow, him-staff, physician, nurse-and-midwife; the privacy officer reads and marks entered in error
Q4 Whether a representative without recorded authority is refused or held as Proposed (part 10 "per policy") Privacy officer Refused on a direct record, Proposed on a capture
Q5 What makes a consent recording user "authorized for the patient and consent type in the consuming domain" (part 3, D10-ESS 9.2): a care relationship, an encounter or registration at the user's facility, the user's facility scope alone, or something else; and whether a role may record only some consent types (for example the registration clerk general consent only) Owner of D10-ESS, privacy officer Adopted as built by the repository owner, 2026-11-27 (ADR-HIS-073 point 6): the patient holds a No. RM at the user's facility; consent types by role
Q6 Which purposes of use permit a directive read or change: for consent recording users, the privacy officer and calling services (part 3 "purpose-limited"; D10-ESS 9.3); and whether a service is limited to the patients it holds a relationship with Privacy officer Adopted as built by the repository owner, 2026-11-27 (ADR-HIS-073 point 6): TREAT, ETREAT, HOPERAT by caller, payment refused; services not limited by patient, every read audited
Q7 A withdrawal with a future effectiveAt: Withdrawn from when it is recorded, or from its effective time? Privacy officer Settled by the specification (review round 3): DEC-ESS-009 point 6, FR-ESS-CNS-002 step 5 and the contract apply it from its effective time. The directive stays Active until then; the job writes the Withdrawn version and the event

Follow-ups outside the card

  • RC-3 contract session (D01-ADM) and the next build session on this unit:
  • subscribe MOD-ESS-003 to PatientMerged and PatientUnmerged once contracts/adm carries them, calling Directives.reassign and restore with the merge record as mergeRef;
  • TEST-ESS-012's merge part then runs end to end.
  • ess-governance:
  • register the configuration item type ess.consent-model, key enterprise;
  • import consent-model.v1.json for the privacy officer to review;
  • grant this unit ess.cfg.version.read;
  • also import the changed enterprise-access.v1.json.
  • ess-coordination (RC-2-S03):
  • register the task type ess.consent-conflict-review and the queue ess.privacy-review;
  • accept this unit's service identity for createTask.
  • adm-identity: accept this unit's service identity for readPerson (purpose HOPERAT).
  • RC-2-S10 (integrate) and the harness:
  • set HIS_CONSENT_SEED_ENABLED=true (his.consent.seed-enabled) in the end-to-end stack;
  • set his.consent.patient-identity-url, his.consent.workflow-url and his.consent.configuration-url for the unit.

RC-2-E2E-001 step 3 records a reference with context and gets a Proposed directive back. - RC-2-S03 (notification): the starter model names channels in a communication-preference directive as recipients of kind application (sms, whatsapp, email, push, patient-channel), for its reading of "a preference excluding a channel". - FR-ESS-CNS-002 (later slice): - the consent-aware decision reads the version in force (asAt) and applies the most restrictive of conflicting directives; - the kit's outage cache drops on ConsentChanged. - REP-ESS-006 (consent status report: by type and status, expiring, conflicts) is an output of FR-ESS-CNS-001 part 9 for the reporting slice; the data is in mod_ess_003. - FHIR Consent representation (part 6.10, SEC-017): a later minor version of consent.v1. - Design system (RC-1-S21): none from this session.