Appearance
ADR-054: Clinical Query Workflow and Role Authorization
NOTE
Superseded by ADR-2622. Execution's own ClinicalQuery stack was retired (#5461): a query is now a FormQuery in the Execution module about one revision of a kernel value, stated as kernel Queried and QueryAnswered assertions, and who may raise, answer and manage it comes from kernel grants (execution.query.raise, .answer, .manage).
- Status: Superseded by ADR-2622
- Date: 2026-07-24
- Authors: @fderuiter
- Deciders: @fderuiter
1. Context & Problem Statement
To meet security and regulatory compliance requirements for clinical trials (e.g., FDA 21 CFR Part 11, EU Annex 11), the eClinical platform must implement a highly secure, reliable, and auditable manually-raised clinical query workflow. The core issues addressed by this decision are:
- Authorizing actions cleanly based on roles propagated from Keycloak tokens.
- Handling potential role claim variances (case sensitivity, whitespace, synonym mapping) safely.
- Centralizing query lifecycle validation to prevent invalid state transitions or data corruption.
- Correctly capturing GxP audit metadata utilizing a session commit-then-reselect pattern.
This decision implements requirements under Trace-8.
2. Decision Drivers & Constraints
- Driver 1 (Compliance): Enforce allow-list-based role gates (e.g., CRAs/Data Managers can raise/close, Site Investigators can answer).
- Driver 2 (Reliability): Guard against token claim mismatches across tenant directories.
- Driver 3 (Traceability): Ensure all mutations are persisted with robust 21 CFR Part 11 audit fields.
3. Options Considered
Option 1: Ad-hoc Role Gate checks in Endpoint Handlers
- Overview: Validate user roles directly inside each endpoint function using local conditions.
- Pros:
- ✅ Quick to implement initially.
- Cons:
- ❌ Easy to miss security gates on new/cloned endpoints.
- ❌ No role normalization logic, leading to subtle access issues due to claim formatting discrepancies.
Option 2: Declarative Allow-List Dependency & Centralized Lifecycle Engine
- Overview: Implement a generic, reusable FastAPI dependency
require_roles(...)alongside a dedicated query state transition machine (QueryService). - Pros:
- ✅ Secure-by-default architecture utilizing allow-lists.
- ✅ Centralized role normalization (normalizes case, trims whitespace, maps synonym roles).
- ✅ Guarantees state transition validation and transactional consistency across all entrypoints.
- Cons:
- ❌ Introduces a small amount of abstraction and upfront boilerplate.
4. Decision Outcome
- Chosen Option: Option 2
- Justification: Option 2 provides a standard, secure-by-default framework for eClinical action-level RBAC. Implementing centralized role normalization prevents environment-specific discrepancies from bypassing or breaking authentication gates.
4.1 Client-Side Role-Aware Visualization Layer
To ensure optimal usability and guide user actions contextually without violating strict database schema and audit trail requirements, a dynamic client-side role-aware visualization layer has been implemented in the web portal (ClinicalQueryPanel.vue):
- Contextual Label Mapping:
OPEN/REOPENEDStatus:- Site Coordinators and Investigators (
site_investigator,crc) resolve this to"Awaiting Site Action". - CRAs and Monitors (
cra,monitor) resolve this to"Awaiting Site Response".
- Site Coordinators and Investigators (
ANSWEREDStatus:- Site Coordinators and Investigators (
site_investigator,crc) resolve this to"Submitted to CRA". - CRAs and Monitors (
cra,monitor) resolve this to"Awaiting CRA Review".
- Site Coordinators and Investigators (
CLOSEDStatus:- Universally mapped to
"CLOSED"for all roles to preserve audit trail visibility and avoid post-closure ambiguity.
- Universally mapped to
- Robust Fallback Mechanism:
- When Pinia or OIDC state is inactive/uninitialized, or if the user is unauthenticated, or has no explicitly assigned roles, the layer cleanly falls back to the database-persisted statuses (
OPEN,REOPENED,ANSWERED,CLOSED). This guarantees graceful degradation and continuous operability of the interface under all client-side OIDC states.
- When Pinia or OIDC state is inactive/uninitialized, or if the user is unauthenticated, or has no explicitly assigned roles, the layer cleanly falls back to the database-persisted statuses (
5. Consequences & Trade-offs
- Positive Impact: Highly robust security verification, completely deterministic query workflows, and clean GxP audit trails.
- Negative Impact / Technical Debt: Requires keeping role synonym mappings up-to-date if external OIDC claims change drastically.
- Mitigation Strategy: Role configurations are kept as explicit constants inside the security package for clear visibility and maintenance.
6. Implementation & Verification
- Affected Repositories / Services:
packages/security/- Shared allow-list validator and normalization patterns.apps/execution/- Core clinical query lifecycle service, schema binding, and endpoints.
- Verification Plan: Full automated coverage in
tests/test_clinical_queries.pyandtests/test_rbac.py.