PVID counter done
This commit is contained in:
parent
c3ef8a5bc2
commit
cfd791ddaf
@ -13,18 +13,19 @@ class PatVisit extends Controller {
|
|||||||
$this->visnum_prefix = "DV";
|
$this->visnum_prefix = "DV";
|
||||||
}
|
}
|
||||||
|
|
||||||
private function preparePVID($PVID) {
|
private function preparePVID() {
|
||||||
$row = $this->db->table('counter')->select('*')->where('CounterID','2')->get()->getResultArray();
|
$row = $this->db->table('counter')->select('*')->where('CounterID','2')->get()->getResultArray();
|
||||||
$cValue = $row[0]['CounterValue'];
|
$cValue = $row[0]['CounterValue'];
|
||||||
$cStart = $row[0]['CounterStart'];
|
$cStart = $row[0]['CounterStart'];
|
||||||
$cEnd = $row[0]['CounterEnd'];
|
$cEnd = $row[0]['CounterEnd'];
|
||||||
$cReset = $row[0]['CounterReset'];
|
$cReset = $row[0]['CounterReset'];
|
||||||
$cPad = strlen((string)$cEnd);
|
$cPad = strlen((string)$cEnd);
|
||||||
$cValue_next = $cValue++;
|
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
|
// next value > end, back to start
|
||||||
if($cValue_next > $cEnd) { $cValue_next = $cStart; }
|
$this->db->table('counter')->set('CounterValue', $cValue_next)->where('CounterID','2')->update();
|
||||||
$row = $this->db->table('counter')->set('CounterValue', $cValue_next)->where('CounterID','2');
|
return $cnum;
|
||||||
return $this->visnum_prefix.str_pad($cValue, $cPad, "0", STR_PAD_LEFT);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function show($PVID = null) {
|
public function show($PVID = null) {
|
||||||
@ -103,7 +104,10 @@ class PatVisit extends Controller {
|
|||||||
$input = $this->request->getJSON(true);
|
$input = $this->request->getJSON(true);
|
||||||
if (!$input) { return $this->respond(['status' => 'error', 'message' => 'Invalid JSON input'], 400); }
|
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);
|
$dataPatVisit = $this->preparePatVisitData($input);
|
||||||
$dataPatDiag = $this->preparePatDiagData($input);
|
$dataPatDiag = $this->preparePatDiagData($input);
|
||||||
$dataPatVisitAdt = $this->preparePatVisitAdtData($input);
|
$dataPatVisitAdt = $this->preparePatVisitAdtData($input);
|
||||||
@ -140,7 +144,6 @@ class PatVisit extends Controller {
|
|||||||
'message' => 'Data insert success',
|
'message' => 'Data insert success',
|
||||||
'data' => $dataPatVisit
|
'data' => $dataPatVisit
|
||||||
], 201);
|
], 201);
|
||||||
|
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$this->db->transRollback();
|
$this->db->transRollback();
|
||||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||||
|
|||||||
@ -19,6 +19,7 @@ class CreatePVTables extends Migration {
|
|||||||
]);
|
]);
|
||||||
$this->forge->addField('CreateDate DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP');
|
$this->forge->addField('CreateDate DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP');
|
||||||
$this->forge->addKey('InternalPVID', true);
|
$this->forge->addKey('InternalPVID', true);
|
||||||
|
$this->forge->addUniqueKey('PVID', true);
|
||||||
$this->forge->createTable('patvisit');
|
$this->forge->createTable('patvisit');
|
||||||
|
|
||||||
// patdiag
|
// patdiag
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user