From 862e5fd03de01e18a4c5c85416a871ae98e383bc Mon Sep 17 00:00:00 2001 From: mahdahar <89adham@gmail.com> Date: Mon, 22 Sep 2025 13:25:31 +0700 Subject: [PATCH] patvisit --- app/Config/Routes.php | 1 + app/Controllers/Contact.php | 2 +- app/Controllers/PatVisit.php | 120 +++++++++++------- ...st.php => 2025-09-09-155526_Pat_Visit.php} | 4 +- .../Migrations/2025-09-12-011643_Contact.php | 18 +-- 5 files changed, 84 insertions(+), 61 deletions(-) rename app/Database/Migrations/{2025-09-09-155526_Patient_Vst.php => 2025-09-09-155526_Pat_Visit.php} (96%) diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 91a46dc..669cb56 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -30,6 +30,7 @@ $routes->get('/api/patient/check', 'Patient::patientCheck'); //$routes->get('/api/patvisit', 'Patient::index'); $routes->post('/api/patvisit', 'PatVisit::create'); $routes->get('/api/patvisit/(:num)', 'PatVisit::show/$1'); +$routes->get('/api/patvisit/patient/(:num)', 'PatVisit::showByPatient/$1'); $routes->delete('/api/patvisit', 'PatVisit::delete'); $routes->patch('/api/patvisit', 'PatVisit::update'); diff --git a/app/Controllers/Contact.php b/app/Controllers/Contact.php index e940851..96aa9db 100644 --- a/app/Controllers/Contact.php +++ b/app/Controllers/Contact.php @@ -208,7 +208,7 @@ class Contact extends Controller { private function prepareContactDetailData(array $input): array { $data = [ - "Code" => $input['Code'] ?? null, + "ContactCode" => $input['ContactCode'] ?? null, "ContactEmail" => $input['ContactEmail'] ?? null, "OccupationID" => $input['OccupationID'] ?? null, "JobTitle" => $input['JobTitle'] ?? null, diff --git a/app/Controllers/PatVisit.php b/app/Controllers/PatVisit.php index 8628fee..dd5d112 100644 --- a/app/Controllers/PatVisit.php +++ b/app/Controllers/PatVisit.php @@ -12,48 +12,27 @@ class PatVisit extends Controller { $this->db = \Config\Database::connect(); } - private function preparePatVisitData(array $input): array { - $data = [ - "PVID" => $input['PVID'] ?? null, - "InternalPID" => $input['InternalPID'] ?? null, - "EpisodeID" => $input['EpisodeID'] ?? null - ]; - - if(!empty($input['InternalPVID'])) { $data["InternalPVID"] = $input["InternalPVID"]; } - - return $data; - } - - private function preparePatDiagData(array $input): array { - $data = [ - "InternalPVID" => $input['InternalPVID'] ?? null, - "InternalPID" => $input['InternalPID'] ?? null, - "DiagCode" => $input['DiagCode'] ?? null, - "Diagnosis" => $input['Diagnosis'] ?? null - ]; - - return $data; - } - - private function preparePatVisitAdtData(array $input): array { - $data = [ - "InternalPVID" => $input['InternalPVID'] ?? null, - "InternalPID" => $input['InternalPID'] ?? null, - "ADTCode" => $input['ADTCode'] ?? null, - "LocationID" => $input['LocationID'] ?? null, - "AttDoc" => $input['AttDoc'] ?? null, - "RefDoc" => $input['RefDoc'] ?? null, - "AdmDoc" => $input['AdmDoc'] ?? null, - "CnsDoc" => $input['CnsDoc'] ?? null - ]; - - return $data; - } - public function show($PVID = null) { try { $row = $this->db->table('patvisit pv') - ->join('patdiag pd', 'pd.InternalPVID=pv.Internal.PVID', 'left') + ->join('patdiag pd', 'pd.InternalPVID=pv.InternalPVID', 'left') + ->join('patvisitadt pva', 'pd.InternalPVID=pva.InternalPVID', 'left') + ->get()->getResultArray(); + + return $this->respond([ + 'status' => 'success', + 'message'=> "data found", + 'data' => $row, + ], 200); + } catch (\Exception $e) { + return $this->failServerError('Something went wrong '.$e->getMessage()); + } + } + + public function showByPatient($InternalPID = null) { + try { + $row = $this->db->table('patvisit pv') + ->join('patdiag pd', 'pd.InternalPVID=pv.InternalPVID', 'left') ->join('patvisitadt pva', 'pd.InternalPVID=pva.InternalPVID', 'left') ->get()->getResultArray(); @@ -74,9 +53,9 @@ class PatVisit extends Controller { if (!$input["InternalPVID"] || !is_numeric($input["InternalPVID"])) { return $this->respond(['status' => 'error', 'message' => 'Invalid or missing ID'], 400); } $InternalPVID = $input["InternalPVID"]; - $dataPatVisit = preparePatVisitData($input); - $dataPatDiag = preparePatDiagData($input); - $dataPatVisitAdt = preparePatVisitAdtData($input); + $dataPatVisit = $this->preparePatVisitData($input); + $dataPatDiag = $this->preparePatDiagData($input); + $dataPatVisitAdt = $this->preparePatVisitAdtData($input); $this->db->transStart(); $this->db->table('patvisit')->where('InternalPVID', $InternalPVID)->update($dataPatVisit); @@ -115,15 +94,21 @@ class PatVisit extends Controller { $input = $this->request->getJSON(true); if (!$input) { return $this->respond(['status' => 'error', 'message' => 'Invalid JSON input'], 400); } - $InternalPVID = $input["InternalPVID"]; - $dataPatVisit = preparePatVisitData($input); - $dataPatDiag = preparePatDiagData($input); - $dataPatVisitAdt = preparePatVisitAdtData($input); + $dataPatVisit = $this->preparePatVisitData($input); + $dataPatDiag = $this->preparePatDiagData($input); + $dataPatVisitAdt = $this->preparePatVisitAdtData($input); $this->db->transStart(); $this->db->table('patvisit')->insert($dataPatVisit); - if(!empty($dataPatDiag)) { $this->db->table('patdiag')->insert($dataPatDiag); } - if(!empty($dataPatVisitAdt)) {$this->db->table('patvisitadt')->insert($dataPatVisitAdt); } + $newInternalPVID = $this->db->insertID(); + if(!empty($dataPatDiag)) { + $dataPatDiag['InternalPVID'] = $newInternalPVID; + $this->db->table('patdiag')->insert($dataPatDiag); + } + if(!empty($dataPatVisitAdt)) { + $dataPatVisitAdt['InternalPVID'] = $newInternalPVID; + $this->db->table('patvisitadt')->insert($dataPatVisitAdt); + } $dbError = $this->db->error(); @@ -131,7 +116,7 @@ class PatVisit extends Controller { if (!empty($dbError['message'])) { $this->db->transRollback(); - return $this->failServerError('Update failed: ' . $dbError['message']); + return $this->failServerError('create failed: ' . $dbError['message']); } @@ -151,4 +136,41 @@ class PatVisit extends Controller { return $this->failServerError('Something went wrong: ' . $e->getMessage()); } } + + private function preparePatVisitData(array $input): array { + $data = [ + "PVID" => $input['PVID'] ?? null, + "InternalPID" => $input['InternalPID'] ?? null, + "EpisodeID" => $input['EpisodeID'] ?? null + ]; + + if(!empty($input['InternalPVID'])) { $data["InternalPVID"] = $input["InternalPVID"]; } + + return $data; + } + + private function preparePatDiagData(array $input): array { + $data = [ + "InternalPVID" => $input['InternalPVID'] ?? null, + "InternalPID" => $input['InternalPID'] ?? null, + "DiagCode" => $input['DiagCode'] ?? null, + "Diagnosis" => $input['Diagnosis'] ?? null + ]; + + return $data; + } + + private function preparePatVisitAdtData(array $input): array { + $data = [ + "InternalPVID" => $input['InternalPVID'] ?? null, + "ADTCode" => $input['ADTCode'] ?? null, + "LocationID" => $input['LocationID'] ?? null, + "AttDoc" => $input['AttDoc'] ?? null, + "RefDoc" => $input['RefDoc'] ?? null, + "AdmDoc" => $input['AdmDoc'] ?? null, + "CnsDoc" => $input['CnsDoc'] ?? null + ]; + + return $data; + } } \ No newline at end of file diff --git a/app/Database/Migrations/2025-09-09-155526_Patient_Vst.php b/app/Database/Migrations/2025-09-09-155526_Pat_Visit.php similarity index 96% rename from app/Database/Migrations/2025-09-09-155526_Patient_Vst.php rename to app/Database/Migrations/2025-09-09-155526_Pat_Visit.php index 0dc8894..4ae0d88 100644 --- a/app/Database/Migrations/2025-09-09-155526_Patient_Vst.php +++ b/app/Database/Migrations/2025-09-09-155526_Pat_Visit.php @@ -12,7 +12,7 @@ class CreatePVTables extends Migration { 'InternalPVID'=> ['type' => 'INT', 'constraint' => 11, 'unsigned' => true, 'auto_increment' => true], 'PVID' => ['type' => 'VARCHAR', 'constraint' => 20, 'null' => true], 'InternalPID' => ['type' => 'INT', 'constraint' => 11, 'null' => true], - 'Episode' => ['type' => 'VARCHAR', 'constraint' => 255, 'null' => true], + 'EpisodeID' => ['type' => 'VARCHAR', 'constraint' => 255, 'null' => true], 'EndDate' => ['type' => 'DATETIME', 'null' => true], 'ArchivedDate'=> ['type' => 'DATETIME', 'null' => true], 'DelDate' => ['type' => 'DATETIME', 'null' => true], @@ -42,7 +42,7 @@ class CreatePVTables extends Migration { 'ADTCode' => ['type' => 'VARCHAR', 'constraint' => 255, 'null' => true], 'LocationID' => ['type' => 'INT', 'constraint' => 11, 'null' => true], 'AttDoc' => ['type' => 'INT', 'constraint' => 11, 'null' => true], - 'ReffDoc' => ['type' => 'INT', 'constraint' => 11, 'null' => true], + 'RefDoc' => ['type' => 'INT', 'constraint' => 11, 'null' => true], 'AdmDoc' => ['type' => 'INT', 'constraint' => 11, 'null' => true], 'CnsDoc' => ['type' => 'INT', 'constraint' => 11, 'null' => true], 'EndDate' => ['type' => 'DATETIME', 'null' => true], diff --git a/app/Database/Migrations/2025-09-12-011643_Contact.php b/app/Database/Migrations/2025-09-12-011643_Contact.php index 3b6eb45..7799dde 100644 --- a/app/Database/Migrations/2025-09-12-011643_Contact.php +++ b/app/Database/Migrations/2025-09-12-011643_Contact.php @@ -29,16 +29,16 @@ class CreateContactTable extends Migration { // ContactDetail $this->forge->addField([ - 'ContactDetID' => [ 'type' => 'INT', 'constraint' => 11, 'unsigned' => true, 'auto_increment' => true ], - 'ContactID' => [ 'type' => 'INT', 'constraint' => 11 ], - 'SiteID' => [ 'type' => 'INT', 'constraint' => 11, 'null' => true ], - 'Code' => [ 'type' => 'varchar', 'constraint' => 11, 'null' => false ], - 'ContactEmail' => [ 'type' => 'VARCHAR', 'constraint' => 150, 'null' => true ], - 'OccupationID' => [ 'type' => 'VARCHAR', 'constraint' => 50, 'null' => true ], - 'JobTitle' => [ 'type' => 'VARCHAR', 'constraint' => 100, 'null' => true ], - 'Department' => [ 'type' => 'VARCHAR', 'constraint' => 100, 'null' => true ], + 'ContactDetID' => [ 'type' => 'INT', 'constraint' => 11, 'unsigned' => true, 'auto_increment' => true ], + 'ContactID' => [ 'type' => 'INT', 'constraint' => 11 ], + 'SiteID' => [ 'type' => 'INT', 'constraint' => 11, 'null' => true ], + 'ContactCode' => [ 'type' => 'varchar', 'constraint' => 11, 'null' => false ], + 'ContactEmail' => [ 'type' => 'VARCHAR', 'constraint' => 150, 'null' => true ], + 'OccupationID' => [ 'type' => 'VARCHAR', 'constraint' => 50, 'null' => true ], + 'JobTitle' => [ 'type' => 'VARCHAR', 'constraint' => 100, 'null' => true ], + 'Department' => [ 'type' => 'VARCHAR', 'constraint' => 100, 'null' => true ], 'ContactStartDate' => [ 'type' => 'DATE', 'null' => true ], - 'ContactEndDate' => [ 'type' => 'DATE', 'null' => true ], + 'ContactEndDate' => [ 'type' => 'DATE', 'null' => true ], ]); $this->forge->addKey('ContactDetID', true); $this->forge->createTable('contactdetail');