RehaBridge — Product, Domain & Engineering Documentation
How to read this document (Progressive Disclosure Format):
This documentation is structured into three depth levels aligned with Domain-Driven Design (DDD) and the C4 (Levels 1–4) + UML modeling approach:
- Level 1 (Visible below): Executive, clinical, and product overview — what RehaBridge does, why it exists, its Ubiquitous Language, and its Bounded Contexts (C4 Level 1: System Context).
- Level 2 (Click to expand): Full functional specification, user journeys, product trade-offs, domain invariants, C4 Level 2 (Containers), and UML Sequence Diagram (streaming SSE ingestion + live /admin compliance telemetry).
- Level 3 (Click to expand): Exhaustive Developer & Engineering Reference — C4 Level 3 (Components), C4 Level 4 (Code: UML Class & ER Diagrams), API contracts, PII regex pipeline, Gemini + heuristic fallback rules, HL7 FHIR R4 mapping, security hardening, and quality gates.
Level 1 — Product Overview & Ubiquitous Language
1.1 What RehaBridge Does & Why It Exists
Rehabilitation clinics receive dense, unstructured clinical documents every day: post-operative surgical discharge letters (Entlassungsberichte), neurological progress notes, and handwritten or dictated physical therapy orders. Turning those free-text notes into actionable, standardized therapy plans creates three recurring operational problems:
- Manual clinical overhead: Therapists spend significant time extracting diagnosis codes (ICD-10), recovery phases, exercise dosages, contraindications, and emergency red flags from unstructured prose.
- EU DSGVO / German privacy barrier to AI: Clinics cannot paste raw patient letters containing names, birthdates, addresses, or German health insurance IDs (Versichertennummer) directly into external cloud LLMs without violating EU GDPR (DSGVO Art. 9) and German medical secrecy (§ 203 StGB).
- Lack of interoperability & clinic isolation: Clinical plans remain trapped in PDFs or clinic-specific text formats instead of structured HL7 FHIR R4 resources, while multi-clinic platforms must guarantee strict tenant partitioning (Mandantentrennung) so one clinic's protocols never bleed into another's workspace.
RehaBridge solves all three in a single workflow:
- Sanitizes PII deterministically on the server before any external AI call or database write.
- Extracts structured clinical protocols via Google Gemini 2.5 Flash (with an automatic, zero-downtime deterministic clinical fallback when offline or in mock mode).
- Maps every protocol to HL7 FHIR R4
CarePlanJSON with SNOMED-CT terminology for downstream EHR integration. - Delivers strictly tenant-isolated clinic portals built with Next.js App Router (SSR/ISR) and instant cache revalidation.
1.2 Core Capabilities at a Glance
| Capability | User Value | Key Guarantee |
|---|---|---|
| Multi-Tenant Clinic Directory | Clear entry point for each independent rehabilitation clinic. | Strict Mandantentrennung: no cross-clinic protocol feeds or shared queries. |
| Isolated Clinic Catalog & Phase Filters | Therapists browse protocols scoped strictly to their clinic and filter by clinical phase (Acute, Subacute, Return-to-Sport, Maintenance). | Database- and route-level tenant scoping (tenant_slug). |
| Pre-LLM DSGVO PII Sanitization (Live SSE) | Clinicians paste raw German or English clinical notes and watch an immediate DSGVO Redaction Receipt stream live before AI extraction. | Deterministic regex scrubbing strips PII into [REDACTED] over a POST SSE stream (never query params) before LLM calls or storage. |
| Structured Clinical Extraction | Converts free text into ICD-10 code, rehab phase, duration, exercise table (dosage + contraindications), and red-flag warnings. | Gemini 2.5 Flash JSON-schema extraction with seamless rule-based fallback. |
HL7 FHIR R4 CarePlan Export | Enables immediate interoperability with hospital EHRs and therapy software. | One-click inspect, copy, and .json download with SNOMED-CT coding. |
| Instant Portal Publication | Newly parsed protocols appear in the clinic catalog immediately. | Next.js Server Actions trigger targeted on-demand ISR cache revalidation. |
Zero-PII Compliance Console (/admin) | Platform operators monitor DSGVO Art. 32 PII-scrubbing proof, LLM vs. fallback usage, and pipeline latency live across clinics. | Streams only aggregate counts & metadata via SSE — zero patient data or clinical text ever crosses tenant boundaries. |
1.3 Ubiquitous Language (DDD Glossary)
All stakeholders — clinicians, product managers, compliance officers, and engineers — use these exact terms consistently across UI labels, API routes, database models, and tests:
| Term | Domain Definition | Codebase Anchor |
|---|---|---|
Clinic Tenant (Tenant) | An independent rehabilitation institution (e.g., Berlin Reha-Zentrum Mitte, Alpen Reha-Klinik Bad Tölz) acting as its own DSGVO Data Controller. Identified by a unique tenant_slug. | Tenant, /clinics/[tenant] |
| Mandantentrennung (Tenant Isolation) | The strict architectural and legal boundary ensuring protocols belonging to one Clinic Tenant cannot be queried, listed, or resolved under another tenant's scope. | CurrentTenant, UniqueConstraint(tenant_slug, slug) |
| Raw Clinical Note | Unstructured medical text (discharge summary, progress report, therapy order) submitted during ingestion. Transient only — never persisted or transmitted raw. | ParseProtocolRequest.raw_text |
| PII-Sanitized Note | The clinical note after deterministic DSGVO redaction replaces detected personal identifiers with [REDACTED]. Safe to send to the extraction engine and store for auditability. | Protocol.raw_anonymized_text, anonymize_clinical_text() |
Clinical Protocol (Protocol) | The core domain aggregate: a structured, tenant-scoped rehabilitation plan extracted from a sanitized note, containing diagnosis coding, phase, duration, interventions, and safety warnings. | Protocol, ProtocolResponse |
| Condition Code | Primary ICD-10 diagnosis identifier classifying the underlying pathology (e.g., M23.2 ACL/meniscus tear, I69.3 post-stroke hemiparesis, M75.1 rotator cuff tear). | Protocol.condition_code |
| Rehab Phase | One of four canonical stages of rehabilitation progression: Acute, Subacute, Return-to-Sport, or Maintenance. | Protocol.rehab_phase |
| Exercise Intervention | A structured physical therapy activity prescribing what to do (name), how often (frequency), how much (sets_reps), and what to avoid (contraindications). | ExerciseSchema, ExerciseTable |
| Clinical Red Flag | A high-severity safety warning (e.g., DVT signs, fever > 38.5°C, FAST stroke symptoms) requiring immediate therapy cessation or physician notification. | Protocol.red_flags, RedFlagsAlert |
| FHIR CarePlan | An HL7 FHIR R4 CarePlan JSON representation of a Clinical Protocol using SNOMED-CT activity and category codes for EHR interoperability. | build_fhir_care_plan(), FhirDrawer |
| Heuristic Fallback | The deterministic German/English clinical rule engine that takes over automatically when MOCK_LLM=true, no API key is configured, or the Gemini API fails. | extract_fallback_heuristic() |
1.4 Bounded Contexts (Strategic DDD)
RehaBridge is organized around five cohesive Bounded Contexts:
- Clinic Tenancy Context: Manages clinic identities (
Tenant), specialties, tenant existence validation, and strict partition boundaries (tenant_slug). - Privacy & PII Sanitization Context: Owns deterministic German/English PII detection,
[REDACTED]masking, and entity audit counting (inspect_pii_entities) prior to any external processing. - Clinical Extraction Context: Translates sanitized prose into structured rehabilitation protocols using either Google Gemini 2.5 Flash (structured JSON output) or the deterministic clinical heuristic rule engine, streamed live over
POSTSSE. - FHIR Interoperability & Portal Delivery Context: Projects stored protocols into HL7 FHIR R4
CarePlanresources and serves SEO-ready, tenant-scoped clinic catalogs and protocol views via Next.js SSR/ISR. - Zero-PII Compliance Telemetry Context: Publishes strictly aggregate,
extra="forbid"operational audit metrics (ComplianceAuditEvent) to an async pub/sub event bus powering the live/adminDSGVO Art. 32 compliance console via SSE.