Skip to main content

Multi-tenant and Clinic Center Pattern

obeliOmed supports multiple companies (tenants) and multiple clinic centers per company on a single installation. This pattern is built on two FacturaScripts native concepts.

The two dimensions

DimensionFS conceptobeliOmed meaningType
TenantidEmpresa — FS companyA healthcare group or solo clinicINT NOT NULL
Clinic centercodalmacen — FS warehouseA physical clinic locationVARCHAR(4) NOT NULL

FacturaScripts was designed for multi-warehouse ERP. obeliOmed reuses this as multi-clinic: each "warehouse" in FS is a clinic center in the obeliOmed domain.

Why reuse codalmacen instead of a custom column?

FacturaScripts core already filters most views by codalmacen. Controllers, list views, and document forms all understand and respect codalmacen. By mapping clinic center to warehouse:

  • All FS built-in filtering works out of the box
  • The admin already knows how to manage "almacenes" (warehouses = clinics)
  • No custom multi-center logic needed in core FS controllers
  • The AdminClinicCenter extension (ObelioCore) extends the FS warehouse admin with clinic-specific fields

Data model requirement

Every obeliOmed table must include both multi-tenant columns:

CREATE TABLE `obelio_scheduling_appointment` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`idempresa` INT NOT NULL, -- tenant
`codalmacen` VARCHAR(4) NOT NULL, -- clinic center
`id_patient` INT UNSIGNED NOT NULL,
`appointment_date` DATE NOT NULL,
-- ...
CONSTRAINT pk_obelio_scheduling_appointment PRIMARY KEY (`id`),
CONSTRAINT fk_obelio_scheduling_appointment_idempresa
FOREIGN KEY (`idempresa`) REFERENCES `empresas` (`idempresa`),
CONSTRAINT idx_obelio_scheduling_appointment_center
INDEX (`idempresa`, `codalmacen`, `appointment_date`)
);

Filtering in controllers

FacturaScripts ListController and EditController automatically filter by codalmacen when the user selects a clinic. Plugin models must declare the codalmacen column so FS picks it up:

<!-- Table XML: Table/ObelioSchedulingAppointment.xml -->
<table name="obelio_scheduling_appointment">
<column name="codalmacen" type="varchar" length="4" null="NO" />
<!-- ... other columns -->
</table>

Cross-center scenarios

Some entities span centers (e.g. a patient who visits multiple clinics):

  • Patient belongs to idEmpresa only (not a specific center)
  • Appointment, Surgery, Document belong to idEmpresa + codalmacen
  • Reports aggregate across centers when the user has multi-center access

AdminClinicCenter

ObelioCore extends the FS warehouse admin (EditAlmacen) with clinic-specific fields:

  • Clinic address and contact info
  • Opening hours (RRULE-based — ADR-033)
  • Specialties available at this center
  • Default appointment duration
  • OR configuration (for ObelioSurgery)

See the ObelioCore plugin page for the full data model.