Viewing File: /home/assersoft/public_html/audiogramnew/app/Models/PatientsModel.php
<?php
namespace App\Models;
use CodeIgniter\Model;
class PatientsModel extends Model
{
protected $table = 'patients';
protected $primaryKey = 'patient_id';
protected $useAutoIncrement = true;
protected $returnType = 'array';
protected $useSoftDeletes = false;
protected $protectFields = true;
protected $allowedFields = [
'clinic_id',
'patient_name',
'patient_phone',
'patient_sex',
'patient_dob',
];
protected bool $allowEmptyInserts = false;
protected bool $updateOnlyChanged = true;
protected array $casts = [];
protected array $castHandlers = [];
// Dates
protected $useTimestamps = true;
protected $dateFormat = 'datetime';
protected $createdField = 'created_at';
protected $updatedField = 'updated_at';
// Validation
protected $validationRules = [];
protected $validationMessages = [];
protected $skipValidation = false;
protected $cleanValidationRules = true;
// Callbacks
protected $allowCallbacks = true;
protected $beforeInsert = [];
protected $afterInsert = [];
protected $beforeUpdate = [];
protected $afterUpdate = [];
protected $beforeFind = [];
protected $afterFind = [];
protected $beforeDelete = [];
protected $afterDelete = [];
/**
* Get paginated patient list with optional search
*/
public function getPagination($clinicId, $perPage, $search = null)
{
// Set up base query conditions
$this->where('clinic_id', $clinicId)
->orderBy('created_at', 'DESC');
// Add search if provided
if (!empty($search)) {
$this->groupStart()
->like('patient_name', $search)
->orLike('patient_phone', $search)
->groupEnd();
}
// // Simple pagination with one line
// return [
// 'patients' => $this->paginate($perPage),
// 'pager' => $this->pager
// ];
$patients = $this->paginate($perPage);
// Get pager details
$pager = $this->pager->getDetails();
return [
'patients' => $patients,
'pager' => $pager
];
}
}
Back to Directory
File Manager