update contact index

This commit is contained in:
mahdahar 2025-09-23 13:47:00 +07:00
parent 7faf3b4e57
commit c3ef8a5bc2
4 changed files with 38 additions and 11 deletions

View File

@ -16,10 +16,10 @@ class Contact extends Controller {
} }
public function index() { public function index() {
$sql = $this->db->table('contact'); $sql = $this->db->table('contact c')
$sql->select("*") ->select("c.ContactID, cd.ContactCode, c.NameFirst, c.NameLast, c.Specialty")
->join("contactdetail", "contact.ContactID=contactdetail.ContactID", "left") ->join("contactdetail cd", "c.ContactID=cd.ContactID", "left")
->join("occupation","contactdetail.OccupationID=occupation.OccupationID", "left"); ->join("occupation o","cd.OccupationID=o.OccupationID", "left");
$rows = $sql->get()->getResultArray(); $rows = $sql->get()->getResultArray();
if (empty($rows)) { if (empty($rows)) {

View File

@ -10,8 +10,23 @@ class PatVisit extends Controller {
public function __construct() { public function __construct() {
$this->db = \Config\Database::connect(); $this->db = \Config\Database::connect();
$this->visnum_prefix = "DV";
} }
private function preparePVID($PVID) {
$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++;
// 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);
}
public function show($PVID = null) { public function show($PVID = null) {
try { try {
$row = $this->db->table('patvisit pv') $row = $this->db->table('patvisit pv')
@ -66,15 +81,9 @@ class PatVisit extends Controller {
$this->db->transComplete(); $this->db->transComplete();
if (!empty($dbError['message'])) {
$this->db->transRollback();
return $this->failServerError('Update failed: ' . $dbError['message']);
}
if ($this->db->transStatus() === false) { if ($this->db->transStatus() === false) {
$dbError = $this->db->error(); $dbError = $this->db->error();
return $this->failServerError('Failed to update patient data (transaction rolled back): ' . ($dbError['message'] ?? 'Unknown error')); return $this->failServerError('Failed to create patient data (transaction rolled back): ' . ($dbError ?? 'Unknown error'));
} }
return $this->respond([ return $this->respond([
@ -94,6 +103,7 @@ 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']);
$dataPatVisit = $this->preparePatVisitData($input); $dataPatVisit = $this->preparePatVisitData($input);
$dataPatDiag = $this->preparePatDiagData($input); $dataPatDiag = $this->preparePatDiagData($input);
$dataPatVisitAdt = $this->preparePatVisitAdtData($input); $dataPatVisitAdt = $this->preparePatVisitAdtData($input);

View File

@ -0,0 +1,16 @@
<?php
namespace App\Database\Seeds;
use CodeIgniter\Database\Seeder;
class CounterSeeder extends Seeder {
public function run() {
// counter
$data = [
['CounterID'=>1, 'CounterValue'=>'1', 'CounterStart'=>'1', 'CounterEnd'=>'99999', 'CounterDesc'=>'Counter for Order#', 'CounterReset'=>'Y' ],
['CounterID'=>2, 'CounterValue'=>'1', 'CounterStart'=>'1', 'CounterEnd'=>'9999', 'CounterDesc'=>'Counter for Visit#', 'CounterReset'=>'M' ],
];
$this->db->table('counter')->insertBatch($data);
}
}

View File

@ -9,5 +9,6 @@ class DBSeeder extends Seeder {
$this->call('MainSeeder'); $this->call('MainSeeder');
$this->call('ValueSetSeeder'); $this->call('ValueSetSeeder');
$this->call('DummySeeder'); $this->call('DummySeeder');
$this->call('CounterSeeder');
} }
} }