PVID counter done

This commit is contained in:
mahdahar 2025-09-23 14:20:09 +07:00
parent c3ef8a5bc2
commit cfd791ddaf
2 changed files with 12 additions and 8 deletions

View File

@ -13,18 +13,19 @@ class PatVisit extends Controller {
$this->visnum_prefix = "DV";
}
private function preparePVID($PVID) {
private function preparePVID() {
$row = $this->db->table('counter')->select('*')->where('CounterID','2')->get()->getResultArray();
$cValue = $row[0]['CounterValue'];
$cStart = $row[0]['CounterStart'];
$cEnd = $row[0]['CounterEnd'];
$cReset = $row[0]['CounterReset'];
$cPad = strlen((string)$cEnd);
$cValue_next = $cValue++;
$cPad = strlen((string)$cEnd);
if($cValue > $cEnd) { $cValue = $cStart; }
$cnum = $this->visnum_prefix.str_pad($cValue, $cPad, "0", STR_PAD_LEFT);
$cValue_next = $cValue+1;
// next value > end, back to start
if($cValue_next > $cEnd) { $cValue_next = $cStart; }
$row = $this->db->table('counter')->set('CounterValue', $cValue_next)->where('CounterID','2');
return $this->visnum_prefix.str_pad($cValue, $cPad, "0", STR_PAD_LEFT);
$this->db->table('counter')->set('CounterValue', $cValue_next)->where('CounterID','2')->update();
return $cnum;
}
public function show($PVID = null) {
@ -103,7 +104,10 @@ class PatVisit extends Controller {
$input = $this->request->getJSON(true);
if (!$input) { return $this->respond(['status' => 'error', 'message' => 'Invalid JSON input'], 400); }
$input['PVID'] = $this->preparePVID($input['PVID']);
if($input['PVID'] =='' || !isset($input['PVID'])) {
$input['PVID'] = $this->preparePVID();
}
$dataPatVisit = $this->preparePatVisitData($input);
$dataPatDiag = $this->preparePatDiagData($input);
$dataPatVisitAdt = $this->preparePatVisitAdtData($input);
@ -140,7 +144,6 @@ class PatVisit extends Controller {
'message' => 'Data insert success',
'data' => $dataPatVisit
], 201);
} catch (\Exception $e) {
$this->db->transRollback();
return $this->failServerError('Something went wrong: ' . $e->getMessage());

View File

@ -19,6 +19,7 @@ class CreatePVTables extends Migration {
]);
$this->forge->addField('CreateDate DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP');
$this->forge->addKey('InternalPVID', true);
$this->forge->addUniqueKey('PVID', true);
$this->forge->createTable('patvisit');
// patdiag