From 51c369ebe5a1b212cdea250f26b391b1f2d53e7f Mon Sep 17 00:00:00 2001 From: mahdahar <89adham@gmail.com> Date: Mon, 13 Oct 2025 13:59:52 +0700 Subject: [PATCH] add internalpvid to pv creation --- app/Controllers/Contact.php | 9 +++++---- app/Controllers/Counter.php | 6 ++++-- app/Controllers/PatVisit.php | 2 +- app/Models/PatVisitModel.php | 8 +++++--- app/Models/PatientModel.php | 12 +++--------- 5 files changed, 18 insertions(+), 19 deletions(-) diff --git a/app/Controllers/Contact.php b/app/Controllers/Contact.php index 00058b9..e4dcbf4 100644 --- a/app/Controllers/Contact.php +++ b/app/Controllers/Contact.php @@ -11,18 +11,19 @@ class Contact extends Controller { use ResponseTrait; protected $db; - protected $contactRule; + protected $model; + protected $rule; public function __construct() { $this->db = \Config\Database::connect(); - $this->contactRule = [ 'NameFirst' => 'required' ]; + $this->model = new ContactModel(); + $this->rule = [ 'NameFirst' => 'required' ]; } public function index() { $ContactName = $this->request->getVar('ContactName'); $Specialty = $this->request->getVar('Specialty'); - $model = new ContactModel(); - $rows = $model->getContacts($ContactName, $Specialty); + $rows = $this->model->getContacts($ContactName, $Specialty); //$rows = $model->getContacts(); if (empty($rows)) { diff --git a/app/Controllers/Counter.php b/app/Controllers/Counter.php index e64995d..025ca27 100644 --- a/app/Controllers/Counter.php +++ b/app/Controllers/Counter.php @@ -8,6 +8,8 @@ use CodeIgniter\Database\RawSql; class Counter extends Controller { use ResponseTrait; + protected $db; + protected $model; public function __construct() { $this->db = \Config\Database::connect(); } @@ -85,7 +87,7 @@ class Counter extends Controller { $dataCounter = $this->prepareCounterData($input); $this->db->transStart(); - $this->db->table('counter')->where('CounterID', $dataCounter["CounterID"])->update($dataCounterID); + $this->db->table('counter')->where('CounterID', $dataCounter["CounterID"])->update($dataCounter); $this->db->transComplete(); if ($this->db->transStatus() === false) { @@ -115,7 +117,7 @@ class Counter extends Controller { $input = $this->request->getJSON(true); $CounterID = $input["CounterID"]; if (!$CounterID) { - return $this->failValidationError('CounterID is required.'); + return $this->failValidationErrors('CounterID is required.'); } diff --git a/app/Controllers/PatVisit.php b/app/Controllers/PatVisit.php index 5536824..e968106 100644 --- a/app/Controllers/PatVisit.php +++ b/app/Controllers/PatVisit.php @@ -47,7 +47,7 @@ class PatVisit extends Controller { $input = $this->request->getJSON(true); try { $data = $this->model->createPatVisit($input); - return $this->respond(['status' => 'success', 'message' => 'Data updated successfully', 'data' => $data], 201); + return $this->respond(['status' => 'success', 'message' => 'Data created successfully', 'data' => $data], 201); } catch (\Exception $e) { return $this->failServerError('Something went wrong: ' . $e->getMessage()); } diff --git a/app/Models/PatVisitModel.php b/app/Models/PatVisitModel.php index 46a6fa4..e92c331 100644 --- a/app/Models/PatVisitModel.php +++ b/app/Models/PatVisitModel.php @@ -51,7 +51,8 @@ class PatVisitModel extends BaseUtcModel { $this->db->transStart(); $this->insert($input); - /* + $InternalPVID = $this->getInsertID(); + if(!empty($input['PatDiag'])) { $input['PatDiag']['InternalPVID'] = $InternalPVID; $this->db->table('patdiag')->insert($input['PatDiag']); @@ -60,9 +61,10 @@ class PatVisitModel extends BaseUtcModel { $input['PatVisitADT']['InternalPVID'] = $InternalPVID; $this->db->table('patvisitadt')->insert($input['PatVisitADT']); } - */ + $this->db->transComplete(); - return $input['PVID']; + $data = [ "PVID"=>$input['PVID'], "InternalPVID"=>$InternalPVID ]; + return $data; } catch (\Exception $e) { $this->db->transRollback(); diff --git a/app/Models/PatientModel.php b/app/Models/PatientModel.php index 6346497..ae9a771 100644 --- a/app/Models/PatientModel.php +++ b/app/Models/PatientModel.php @@ -6,18 +6,12 @@ use CodeIgniter\Database\RawSql; class PatientModel extends BaseUtcModel { protected $table = 'patient'; protected $primaryKey = 'InternalPID'; + protected $useTimestamps = true; protected $allowedFields = ['PatientID', 'AlternatePID', 'Prefix', 'NameFirst', 'NameMiddle', 'NameMaiden', 'NameLast', 'Suffix', 'NameAlias', 'Gender', 'Birthdate', 'PlaceOfBirth', 'Street_1', 'Street_2', 'Street_3', 'City', 'Province', 'ZIP', 'EmailAddress1', 'EmailAddress2', 'Phone', 'MobilePhone', 'Custodian', 'AccountNumber', 'Country', 'Race', 'MaritalStatus', 'Religion', 'Ethnic', 'Citizenship', 'DeathIndicator', 'DeathDateTime', 'LinkTo', 'CreateDate', 'DelDate' ]; - protected $useTimestamps = true; - protected $createdField = 'CreateDate'; - protected $updatedField = ''; - - protected $beforeInsert = ['normalizeDatesToUTC']; - protected $beforeUpdate = ['normalizeDatesToUTC']; - protected $afterFind = ['convertDatesToUTCISO']; - protected $afterInsert = ['convertDatesToUTCISO']; - protected $afterUpdate = ['convertDatesToUTCISO']; + + public function getPatients($filters = []) { $qname = "LOWER(CONCAT_WS(' ', IFNULL(Prefix,''), IFNULL(NameFirst,''), IFNULL(NameMiddle,''), IFNULL(NameLast,''), IFNULL(NameMaiden,''), IFNULL(Suffix,'')))";