Implementation plan / Session plan / Handover RC-5-S06
Handover RC-5-S06 Build: Orders (the clinical context, MOD-CLI-012)¶
Card: RC-5-S06. Issue: cema-care/his#181. Branch: session/RC-5-S06. Slice: RC-5. Decision record: ADR-HIS-130.
Comes after RC-5-S02, which wrote clinical-context.v1 and the five RC-5-S06 points of contracts/cli/CONTRACT-POINTS.md. This is the first build session on the unit cli-orders. It makes the unit from the template and builds FR-CLI-RSP-003 on the service side: the clinical context, the check every CLI write asks, and the patient context zone. No contract was changed.
What was built and where¶
All the code is in services/cli-orders. Its README lists the packages, the settings and the checks.
The unit, made with services/_template/new-unit.sh cli-orders MOD-CLI-006 MOD-CLI-007 MOD-CLI-012:
- MOD-CLI-006 and MOD-CLI-007 are the template's empty modules, for slice OR-1.
- The tier is 1 (DEC-CLI-012).
- The kit (service-kit/) is the one of services/adm-patient-administration, not the template's. The template's kit lacks the downstream client (kit/client), the patientRef and encounterRef names of policy-decision.v1, and the audit fields of RC-1-S28-F19 (ADR-HIS-130 point 1).
MOD-CLI-012 (mod-cli-012/src/main/java/care/cema/his/cli/mod012/):
- context/ClinicalContexts serves the six operations:
- selectClinicalContext: a switch when the window has a chart or replaces names one, and the open-chart limit of CFG-CLI-032;
- listClinicalContexts and readClinicalContext;
- closeClinicalContext;
- checkClinicalContext;
- readPatientContextZone.
- context/ContextStore keeps the contexts and the Idempotency-Key records.
- zone/ZoneAssembler builds the zone in the content and order of application shell 4. zone/ZoneCache keeps the last data of each part per user. zone/ZoneEvents handles the D01 events. zone/Ages gives the age.
- sources/ holds the ports and HTTP clients:
- D01: readPerson of adm-identity, readEncounter of adm-patient-administration;
- cli-clinical-record: readAllergyStatus, listAssessments with activeRisksOnly, searchClinicalDocuments by author and state.
Every call passes the user's token on, with the unit's own as the acting service.
- web/ClinicalContextController.
- Mod012Module declares the schema and the subscriptions context-zone-persons (his.adm.person.v1) and context-zone-encounters (his.adm.encounter.v1). The module publishes no event: a context is a session record (D03-CLI 7.3).
- Migration mod-cli-012/src/main/resources/db/mod_cli_012/V1__clinical_context.sql: clinical_context, idempotency_record, zone_part.
- Test stand-ins in mod-cli-012/src/testFixtures (FakePatientSources, FakeClinicalRecordSources, TestClock, Mod012TestDoubles).
How the contract points are met:
| Point | How |
|---|---|
| 1 | The six operations; ProviderContractTest runs his-contract verify on each |
| 2 | A selection in a window with a current context, or naming one in replaces, ends it in the same transaction. The answer's unsignedWork lists the user's draft and saved documents of the earlier patient, which stay where they are. On read and close, unsignedWork is that context's own patient's. When the drafts cannot be read it is left out, never given as empty |
| 3 | checkClinicalContext answers mismatch with unknown, other-user, closed, patient-differs or encounter-differs (also when the write names no encounter, since every write carries its context's encounter, PR-RSP-003-01). Each mismatch is audited as cli.context.mismatch (outcome denied, with the reason and "Patient context changed; action not submitted") and counted (his.cli.context.checks) |
| 4 | The zone: name as recorded, No. RM of the encounter's facility labelled "No. RM", date of birth and age, sex, identity status (merged when D01 resolved a retired identifier), the encounter with CIN, class and location, the allergy status from cli-clinical-record, alerts (identity under review; attribution pending after an unmerge), active risks, restrictedInformation and freshness. When a source does not answer: an earlier allergy status or risk is never shown, and without cli-clinical-record the answer is 503. The person and encounter last read from D01 are shown for up to an hour (his.cli.context.last-data-max-age), with freshness.dataAsOf the time of that data; older, or none, gives 503. A part is never blank or a default. A part from earlier data is not marked as unavailable on its own, which the contract cannot say: see "Done differently" (ADR-HIS-130 point 3) |
| 5 | readEncounter and readPerson through the ADM contracts. PatientMerged, PatientUnmerged and IdentityUpdated make the zone read the identity again; PatientTransferred moves the location; PatientDischarged reads the encounter again |
Cross-cutting duties:
- Policy. Every operation asks the policy decision point:
- view of cli.ClinicalRecord for an answer with a zone, with the encounter's facility as owningFacility;
- view or update of cli.ClinicalContext for the context itself, before it is looked up, so that a facility not permitted is refused.
The obligations applied are elevated-audit and session-marker; any other is refused.
- Audit. cli.context.select (actions select, switch, close), cli.context.mismatch and cli.record.view, each with the decision identifier.
- Facility. Contexts are scoped to the facility of the request.
- Telemetry and correlation. From the kit, with the counters his.cli.context.selections, his.cli.context.checks and his.cli.context.zone.source.
How to run the checks, and their result¶
On the light profile, started under the session's name:
HIS_SESSION=RC-5-S06 platform/dev-environment/his-env start light
cd services/cli-orders
./gradlew build # every module, the kit and the app
./gradlew :mod-cli-012:test --tests '*ContractTest' # his-contract verify of clinical-context.v1; the clients against the ADM and CLI stubs (Docker)
Results on 2026-12-02:
- ./gradlew build: successful. 68 tests, none failing: kit 38 (1 skipped, the Kafka adapter test of the full profile, as in the template), MOD-CLI-012 25, MOD-CLI-006 1, MOD-CLI-007 1, app 3 (start-up and module boundaries).
- ProviderContractTest: his-contract verify of the six operations, 27 cases, none failed. The facility cases are included, and checkClinicalContext is called with the service identity of cli-clinical-record.
- ConsumerContractTest: the clients call the stubs of contracts/adm and contracts/cli, and neither stub recorded a violation.
- platform/delivery-pipeline/bin/secret-scan code origin/main: no finding.
- Documentation: check_links.py and mkdocs build pass.
Requirements and test scenarios¶
Every test is tagged FR-CLI-RSP-003 and TEST-CLI-044, and its display name starts with them.
| Requirement, criterion or part | Test (mod-cli-012/src/test/java/care/cema/his/cli/mod012/) |
|---|---|
| AC-04, PR-RSP-003-01: an action started for A and submitted after the switch to B is refused | ContextCheckTest.switchMidAction, reasons, checkRules |
| PR-RSP-003-02: a context per window; the open-chart limit | ContextSelectionTest.openChartLimit, sameWindowReplaces |
| Part 6.4: the zone's content and order; allergy status "not-assessed" until recorded; age; identity alerts | PatientContextZoneTest.content, allergyStatusAndRisks, ages, identityAlerts |
| Part 6.6: an explicit switch keeps the unsigned work and says so; close; a write after it is refused | ContextSelectionTest.selects, switchKeepsUnsignedWork, closes, unsignedWorkUnknown, selectionRules; ContextCheckTest.reasons |
| Part 6.7, part 10 "stale view": source, status and freshness; a source that does not answer (D01 data for at most an hour; never an earlier allergy status) | PatientContextZoneTest.lastDataWhenUnavailable, noDataNoZone |
| Part 10: identity merged while the chart is open; transfer; discharge | PatientContextZoneTest.domainOneEvents |
| Part 12: selection, switch and rejected submissions audited | ContextSelectionTest.selects, switchKeepsUnsignedWork, closes; ContextCheckTest.switchMidAction; PatientContextZoneTest.zoneRead |
| Part 13: service-side authorization, the facility, no chart for a service identity | ContextSelectionTest.access, ownContextsOnly; ContextCheckTest.checkRules |
| AC-02 as the service gives it: name and an approved identifier in every answer | PatientContextZoneTest.content; every context answer carries the zone (ContextSelectionTest.openChartLimit checks the list) |
| AC-03 as the service gives it: unverified data told apart | PatientContextZoneTest.content (an unconfirmed allergy is "(unverified)"); freshness |
| Idempotency-Key | ContextSelectionTest.idempotent, closes |
| clinical-context.v1, and the clients of the ADM and CLI contracts | contract/ProviderContractTest, contract/ConsumerContractTest |
| TEST-CLI-044 "switch patient mid-action; mismatch rejected; zone always visible" | All of the above |
Not covered by this session's tests, and why:
- AC-01 and the usability parts of AC-02 and AC-03 (persona usability tests) need people (below).
- Parts 6.1 to 6.3, 6.5, 6.8 and 6.9 (the persona workspaces, the zone in dialogs, explicit save, sign and cancel states, and status not by colour alone) are screen behaviour. They belong to the CLI screen sessions RC-5-S11 to RC-5-S14 and the shell, which read this API. The service part of 6.5, the zone for a dialog outside a chart, is readPatientContextZone.
- TEST-CLI-001 (one reconciled timeline) is RC-5-S07's (FR-CLI-EHR-001). TEST-CLI-032 (wrong patient at bedside administration) is slice OR-6's (FR-CLI-MAR-002). Both are listed on the card's safety row; this session's part of that safety function, the service-side context check, is verified by ContextCheckTest.
Non-functional targets:
- NFR-CLI-006 Security: every operation is decided by the policy decision point, and the zone is filtered by each source as the user. The national identifier is not in the zone.
- NFR-CLI-010 Interoperability: the contract tests.
- NFR-CLI-013 Localization: canonical values only (codes, ISO dates, age with its unit). The two alert texts this unit writes are English (follow-up 6).
- NFR-CLI-014 Time integrity: UTC instants from the kit's clock. The age is counted in his.cli.time-zone.
- NFR-CLI-015 Observability: the counters above, and the kit's traces and logs with the correlation identifier.
Safety. This session builds the service-side control of the safety function "Patient and encounter context in clinical workspaces" (D03-CLI 11.1): the persistent identity zone and the rejection of a context mismatch (PR-RSP-003-01). It builds them as specified, and its verification (ContextCheckTest, PatientContextZoneTest) passes. It does not change a control, so the hazard log is not changed. Two choices bear on the hazard, and the clinical safety review should look at them:
- with a source down, the zone never shows an earlier allergy status or risk (503 without cli-clinical-record), and shows the person and encounter last read from D01 for at most 60 minutes, marked only by the zone's freshness.dataAsOf;
- a selection in a window that already shows a chart is a switch, not a refusal (ADR-HIS-130 points 2 and 3).
Done differently, and why¶
One thing differs from the contract points, and is safe in the meantime:
- Contract point 4, in part. It asks that "a source that does not answer is shown as unavailable with the time of the last data".
PatientContextZonehas no field to mark one part as unavailable, and a build session does not change the contract. So the zone never serves an earlier allergy status or risk: these are values used for decisions, which must carry their own date (CUX-49). Without cli-clinical-record the zone answers 503. Only D01's person and encounter are served from earlier data, for at most an hour, under the zone's oldest watermarkfreshness.dataAsOf, as CUX-53 says for a view built from several sources. An optional marker per part is follow-up 9. The first version of this pull request served every part's last data, of any age, and the review refused it.
The open choices are in ADR-HIS-130:
1. The kit is the one of adm-patient-administration (point 1).
2. A selection in a window that already shows a chart is a switch (point 2). The contract's replaces names a switch explicitly; the slice scenario opens charts one after another in window main without it.
3. unsignedWork on the selection's answer is the work the switch leaves for the earlier patient, as contract point 2 says. On read and close it is the work of that context's own patient, as the schema's description says.
4. An earlier allergy status is never shown (point 3, above).
5. readPatientContextZone without an encounter takes the encounter of the user's current context for the patient, and is otherwise refused at /encounter (point 7).
6. The encounter status rules of BR-CLI-001 stay with the writing unit. The context checks only that the encounter is the patient's (point 5).
7. A person checking a context for another user is answered other-user, as is the clinician's context checked for the nurse.
8. A check without an encounter is a mismatch (encounter-differs, point 5). ContextCheck.encounter is optional in the contract, but PR-RSP-003-01 says every write carries the encounter of its context, and every context has one.
Questions for a person¶
None that stops the work.
Needs a person¶
- Clinical safety officer: review the change against the hazard log, on the merged work (the card's "Orders and results" duty; the safety function above, and the two choices it names). In particular, confirm the 60-minute limit on D01 data shown while D01 is down (
his.cli.context.last-data-max-age), or set another. It is configuration, and no code changes with it. - Enterprise Architecture Board: approve ADR-HIS-130.
- Usability tests of AC-01, AC-02 and AC-03 (TEST-CLI-044 "persona usability tasks"): clinical users run them with the screens of RC-5-S11 to RC-5-S14 on this service. The task-success criteria of PRS CLN-007 are to be agreed by the clinical owner.
Follow-ups outside the card¶
- Template kit (
services/_template/service-kit, FN-S03's owner): take over the downstream client, the policy request names and the audit fields of the ADM kit, so that new units start with them (ADR-HIS-130 point 1). - Integrate session RC-5-S16 must configure cli-orders and its sources:
- in
e2e/scenarios/RC-5/stack.json, cli-orders withhis.cli.sources.adm-identity.url,his.cli.sources.adm-patient-administration.urlandhis.cli.sources.clinical-record.url; - in the stack's provisioning, a service identity
cli-orders(client credentials,his.clients.client-idandhis.clients.client-secret). Every source call carries the unit's own token beside the user's, so without that client the zone is unavailable. - Isolation and similar-name alerts (FR-CLI-RSP-003 part 6.4 "configured alerts"). The zone shows identity under review and attribution pending now.
- Isolation in force is on the bed in D01 (
beds.v1), and its source order is a CLI order from slice OR-1. - A similar-name warning needs the unit's census.
- Both need a source the card did not name. The session on cli-orders in OR-1 should add them.
- Break-the-Glass in the zone (D03-CLI 9: "this domain marks the session in the patient context zone"). The emergency session is audited (
session-marker), but the zone has no field for it. That would be a minor version of clinical-context.v1, by a CLI contract session. - Unverified allergies are marked in the zone's allergy strings ("Kodein (unverified)"), because
allergiesis a list of strings. A structuredverificationStatusper allergy would be a minor version of clinical-context.v1. - Alert texts ("Identity under review", "Encounter attribution pending: …") are written by this unit in English. The screens should show their own localized text from
kind. The contract could add a code for the attribution-pending case. - Retention of closed contexts and of the held zone parts: neither is removed yet. A job with a configured retention is needed before production.
- Topic register (
platform/event-backbone/mod-ise-004/src/main/resources/backbone/topic-register.yaml, its session's owner, or RC-5-S16 when the slice runs end to end, as RC-1-S26 did): the consumerscli-orders.context-zone-personsonhis.adm.person.v1andcli-orders.context-zone-encountersonhis.adm.encounter.v1. Unregistered, the backbone reports them. - A marker per part of the zone (CLI contract session, clinical-context.v1 1.1): an optional
unavailableflag with the part'sdataAsOf, for the person, the encounter, the allergy status and the active risks. Contract point 4 asks for it (above). With it, an earlier allergy status could be shown as "Unavailable · as at [time]" rather than refusing the zone; that is the clinical safety officer's call.