clqms-be/app/Models/PatVisitModel.php
2025-09-26 13:08:30 +07:00

40 lines
1.2 KiB
PHP

<?php
namespace App\Models;
use CodeIgniter\Model;
class PatVisitModel extends Model {
protected $table = 'patvisit';
protected $primaryKey = 'InternalPVID';
protected $allowedFields = ['PVID', 'InternalPID', 'EpisodeID', 'EndDate'];
protected $useTimestamps = true;
protected $dateFormat = 'datetime';
protected $createdField = 'CreateDate';
protected $deletedField = 'EndDate';
public function show($PVID) {
$rows = $this->join('patdiag pd', 'pd.InternalPVID=pv.InternalPVID', 'left')
->join('patvisitadt pva', 'pd.InternalPVID=pva.InternalPVID', 'left')
->where('PVID',$PVID)->get()->getResultArray();
return $rows;
}
public function use($CounterID) {
$row = $this->where('CounterID',$CounterID)->get()->getResultArray();
$cValue = $row[0]['CounterValue'];
$cStart = $row[0]['CounterStart'];
$cEnd = $row[0]['CounterEnd'];
$cReset = $row[0]['CounterReset'];
$cPad = strlen((string)$cEnd);
// next value > end, back to start
if($cValue > $cEnd) { $cValue = $cStart; }
$cnum = str_pad($cValue, $cPad, "0", STR_PAD_LEFT);
$cValue_next = $cValue+1;
$this->set('CounterValue', $cValue_next)->where('CounterID',$CounterID)->update();
return $cnum;
}
}