Skip to main content

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

table
string
default:"paciente"
Database table name
primaryKey
integer
default:"id_paciente"
Primary key column (auto-incrementing)
timestamps
boolean
default:"true"
Includes created_at and updated_at columns

Fields

Clinic Association

id_clinica
integer
required
Foreign key to the clinic this patient is registered at

Personal Information

nombre
string
required
First name
apellido_paterno
string
required
Paternal surname
apellido_materno
string
Maternal surname (optional)
fecha_nacimiento
date
Date of birth (format: YYYY-MM-DD)
sexo
enum
Biological sex: hombre or mujer

Identification & Contact

curp
string
CURP (Clave Única de Registro de Población) - Mexican national ID. Unique and nullable.
telefono
string
Primary contact phone number

Additional Information

ocupacion
string
Occupation/profession
peso
decimal
Weight in kilograms (precision: 5 digits, 2 decimals)

Address Fields

calle
string
Street name
num_ext
string
External street number
num_int
string
Internal/apartment number
colonia
string
Neighborhood/colony
ciudad
string
City
estado
string
State/province
codigo_postal
string
Postal/ZIP code

Status

estatus
enum
default:"activo"
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'
];

Build docs developers (and LLMs) love