Overview
DentControl implements a robust multi-tenant architecture where each clinic operates as an independent tenant with its own data, users, and patients. The system ensures complete data isolation while providing centralized management capabilities.Multi-Tenant
Complete isolation between clinics with dedicated data spaces
Centralized Admin
Manage multiple clinics from a single administrative interface
Status Control
Activate or deactivate clinics without data loss
Custom Branding
Upload custom logos for each clinic
Data Model
TheClinica model is the core tenant entity in the system. Each clinic has complete ownership of its associated data.
Database Schema
Model Attributes
See the complete model definition at~/workspace/source/app/Models/Clinica.php:17-30
| Field | Type | Description |
|---|---|---|
id_clinica | bigint | Primary key |
nombre | string(50) | Clinic name (alphanumeric, supports accents) |
rfc | string(12-13) | Mexican tax ID (unique, validated format) |
calle | string | Street address |
numero_ext | string(10) | External number |
numero_int | string(10) | Internal number |
colonia | string | Neighborhood/colony |
ciudad | string | City |
estado | string | State |
codigo_postal | string(5) | Postal code |
telefono | string(10) | 10-digit phone number (unique) |
logo_ruta | string | Path to clinic logo image |
estatus | enum | Status: activo or baja |
The RFC (Registro Federal de Contribuyentes) must follow the Mexican tax ID format: 3-4 uppercase letters followed by 6 digits and 3 alphanumeric characters (e.g., ABCD123456EF7).
Relationships
The Clinica model establishes one-to-many relationships with dependent entities:Entity Relationships
Usuarios (Users)
All staff members (dentists, admins) belong to a specific clinic
Pacientes (Patients)
Patient records are scoped to their clinic
Tratamientos
Treatments are linked to clinics via patients
Catálogos
Service and treatment catalogs are clinic-specific
Creating a Clinic
The clinic creation process includes comprehensive validation to ensure data integrity.Controller Implementation
See~/workspace/source/app/Http/Controllers/Admin/ClinicaController.php:21-56
Validation Rules
Name Validation
Name Validation
- Maximum 50 characters
- Allows: letters (including Spanish accents), numbers, spaces, ampersand (&), apostrophe (’), hyphen (-)
- Pattern:
/^[a-zA-Z0-9ñÑáéíóúÁÉÍÓÚ\s&'\-]+$/u
RFC Validation
RFC Validation
- Must be uppercase
- Format: 3-4 letters + 6 digits + 3 alphanumeric characters
- Length: 12-13 characters
- Must be unique across all clinics
Phone Validation
Phone Validation
- Exactly 10 numeric digits
- Must be unique across all clinics
Logo Upload
Logo Upload
- Accepts: JPEG, PNG, JPG formats
- Maximum size: 2MB (2048KB)
- Stored in
public/images/logos/with timestamp prefix
Updating a Clinic
The update process maintains referential integrity while allowing modifications to clinic information.Update Method
See~/workspace/source/app/Http/Controllers/Admin/ClinicaController.php:66-117
When updating a clinic with a new logo, the system automatically deletes the old logo file to prevent storage bloat.
Status Management
Clinics can be toggled between active and inactive states without deleting any data.Toggle Status Method
See~/workspace/source/app/Http/Controllers/Admin/ClinicaController.php:120-132
Status States
Activo
Clinic is operational and accessible to users. All features enabled.
Baja
Clinic is deactivated. Data preserved but access restricted.
Listing Clinics
Clinics are displayed in reverse chronological order (newest first).Multi-Tenant Architecture
DentControl’s multi-tenant design ensures:- Data Isolation: Each clinic only sees its own patients, appointments, and treatments
- Cascade Deletion: When a clinic is deleted, all associated records are removed
- Unique Identifiers: RFC and phone numbers are unique across the entire system
- Scoped Queries: All queries filter by
id_clinicato prevent data leakage
Cascade Relationships
When a clinic is deleted from the database (hard delete), the following entities are automatically removed:- All patients (
paciente) - All users/staff (
usuario) - All appointments (
citas) - All treatments (
tratamiento) - Service catalogs (
catalogo_servicios) - Treatment catalogs (
catalogo_tratamientos)
Best Practices
Always Validate RFC Format
Always Validate RFC Format
The RFC is a critical identifier in Mexico. Use the provided regex pattern to ensure compliance with SAT (tax authority) requirements.
Unique Phone Numbers
Unique Phone Numbers
Phone numbers must be unique across all clinics to prevent confusion and enable global patient search by phone.
Logo File Management
Logo File Management
Always delete old logos when updating to prevent disk space waste. Logos are stored in
public/images/logos/ with timestamp prefixes.Use Status Toggle Over Deletion
Use Status Toggle Over Deletion
Prefer setting
estatus = 'baja' over hard deleting clinics to maintain historical records and referential integrity.Related Features
Patient Management
Manage patients within clinics
Appointments
Schedule appointments for clinic patients
Treatments
Track treatments within clinics