Skip to main content

ADR-033 — Multi-tenant Pattern (idEmpresa + codalmacen)

Status: Approved | Date: 2026-06-20 | Scope: All plugins

Context

obeliOmed targets both solo clinics and multi-clinic healthcare groups. The data model must ensure strict data isolation between tenants (companies) and between clinic centers within the same company. FacturaScripts already provides two native concepts for this.

Decision

Use FacturaScripts native fields as the two-level multi-tenant key:

LevelFieldFS conceptobeliOmed meaning
Tenantidempresa (INT)FS companyHealthcare group or solo clinic
Centercodalmacen (VARCHAR 4)FS warehousePhysical clinic location

Every obeliOmed table must include both columns. See database conventions.

Why reuse codalmacen? FacturaScripts already filters list views, reports, and document forms by the active warehouse. Mapping clinic center to warehouse gives us multi-clinic filtering for free across all FS built-in controllers.

Opening hours are stored as RRULE strings (RFC 5545) in obelio_core_settings, one setting per day-of-week or exception. This allows modelling complex schedules (varying hours, holidays) without a separate schedule table.

AdminClinicCenter

ObelioCore extends the FS EditAlmacen controller as AdminClinicCenter, adding clinic-specific configuration (specialty list, OR configuration, default durations, etc.) without modifying FS core.

Consequences

  • Every query must filter by idempresa AND codalmacen where applicable
  • Patient entities belong to idempresa only (patients can visit multiple centers)
  • Appointment, Document, Surgery entities belong to idempresa + codalmacen
  • All configurable values (durations, limits) live in obelio_<plugin>_settings, keyed by idempresa
  • No cross-tenant data leakage possible if the mandatory column rule is enforced