Overview
The Paciente model represents patient records in the DentControl system. It stores comprehensive demographic information, contact details, and address data for patients registered at dental clinics.
Table Schema
primaryKey
integer
default:"id_paciente"
Primary key column (auto-incrementing)
Includes created_at and updated_at columns
Fields
Clinic Association
Foreign key to the clinic this patient is registered at
Maternal surname (optional)
Date of birth (format: YYYY-MM-DD)
Biological sex: hombre or mujer
CURP (Clave Única de Registro de Población) - Mexican national ID. Unique and nullable.
Primary contact phone number
Weight in kilograms (precision: 5 digits, 2 decimals)
Address Fields
Internal/apartment number
Status
Patient status: activo or baja
Relationships
clinica
Type: belongsTo
A patient belongs to one clinic.
$paciente->clinica; // Clinica model instance
Foreign Key: id_clinica
citas
Type: hasMany
A patient has many appointments.
$paciente->citas; // Collection of Cita models
Foreign Key: id_paciente on citas table
expediente
Type: hasOne
A patient has one clinical record.
$paciente->expediente; // ExpedienteClinico model instance
Foreign Key: id_paciente on expediente_clinico table
accesoMovil
Type: hasOne
A patient may have mobile app access.
$paciente->accesoMovil; // AccesoMovil model instance
Foreign Key: id_paciente on acceso_movil table
Example Usage
Creating a New Patient
use App\Models\Paciente;
$paciente = Paciente::create([
'id_clinica' => 1,
'nombre' => 'María',
'apellido_paterno' => 'González',
'apellido_materno' => 'Hernández',
'fecha_nacimiento' => '1985-06-15',
'sexo' => 'mujer',
'telefono' => '5555551234',
'curp' => 'GOHM850615MDFLRR01',
'ocupacion' => 'Ingeniera',
'peso' => 65.50,
'calle' => 'Insurgentes Sur',
'num_ext' => '456',
'colonia' => 'Del Valle',
'ciudad' => 'Ciudad de México',
'estado' => 'CDMX',
'codigo_postal' => '03100',
'estatus' => 'activo'
]);
Retrieving Patient with Relationships
// Get patient with all appointments
$paciente = Paciente::with('citas')->find($id);
// Get patient with clinic and clinical record
$paciente = Paciente::with(['clinica', 'expediente'])
->find($id);
// Get patient with upcoming appointments
$paciente = Paciente::with(['citas' => function ($query) {
$query->where('fecha', '>=', now())
->orderBy('fecha', 'asc');
}])->find($id);
Searching Patients
// Search by name
$pacientes = Paciente::where('id_clinica', $clinicaId)
->where(function ($query) use ($searchTerm) {
$query->where('nombre', 'like', "%{$searchTerm}%")
->orWhere('apellido_paterno', 'like', "%{$searchTerm}%")
->orWhere('apellido_materno', 'like', "%{$searchTerm}%");
})
->where('estatus', 'activo')
->get();
// Find by CURP
$paciente = Paciente::where('curp', $curp)->first();
Calculating Age
use Carbon\Carbon;
$paciente = Paciente::find($id);
$edad = Carbon::parse($paciente->fecha_nacimiento)->age;
Model Definition
Location: app/Models/Paciente.php
protected $fillable = [
'id_clinica',
'nombre',
'apellido_paterno',
'apellido_materno',
'fecha_nacimiento',
'sexo',
'telefono',
'curp',
'ocupacion',
'peso',
'calle',
'num_ext',
'num_int',
'colonia',
'ciudad',
'estado',
'codigo_postal',
'estatus'
];