From 8ff71a27fc6ec50a2ce93704bb40bd18b62d560d Mon Sep 17 00:00:00 2001 From: mahdahar <89adham@gmail.com> Date: Tue, 16 Sep 2025 15:33:22 +0700 Subject: [PATCH] refactor remove id from url when update an delete --- app/Config/Routes.php | 16 +-- app/Controllers/Location.php | 63 ++++----- app/Controllers/Patient.php | 123 ++++++------------ app/Controllers/ValueSet.php | 38 +++--- app/Controllers/ValueSetField.php | 47 +++---- .../2025-09-02-070522_Patient_master.php | 8 +- .../2025-09-02-070826_Patient_Reg.php | 12 +- .../2025-09-09-155526_Patient_Vst.php | 8 +- .../Migrations/2025-09-10-141522_Location.php | 4 +- .../2025-09-12-011643_DoctorMaster.php | 8 +- .../Migrations/2025-09-12-100001_Orders.php | 8 +- .../Migrations/2025-09-15-130122_ValueSet.php | 4 +- 12 files changed, 135 insertions(+), 204 deletions(-) diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 12a7e98..aae5859 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -33,8 +33,8 @@ $routes->post('/api/auth/logout', 'Auth::logout'); $routes->get('/api/patient', 'Patient::index'); $routes->post('/api/patient', 'Patient::create'); $routes->get('/api/patient/(:num)', 'Patient::show/$1'); -$routes->delete('/api/patient/(:num)', 'Patient::delete/$1'); -$routes->patch('/api/patient/(:num)', 'Patient::update/$1'); +$routes->delete('/api/patient', 'Patient::delete'); +$routes->patch('/api/patient', 'Patient::update'); $routes->get('/api/patient/check', 'Patient::patientCheck'); $routes->get('/api/race', 'Race::index'); @@ -52,17 +52,17 @@ $routes->get('/api/ethnic/(:num)', 'Ethnic::show/$1'); $routes->get('/api/location', 'Location::index'); $routes->get('/api/location/(:num)', 'Location::show/$1'); $routes->post('/api/location', 'Location::create'); -$routes->patch('/api/location/(:num)', 'Location::update/$1'); -$routes->delete('/api/location/(:num)', 'Patient::delete/$1'); +$routes->patch('/api/location', 'Location::update'); +$routes->delete('/api/location', 'Patient::delete'); $routes->get('/api/valueset', 'ValueSet::index'); $routes->get('/api/valueset/(:num)', 'ValueSet::show/$1'); $routes->post('/api/valueset', 'ValueSet::create'); -$routes->patch('/api/valueset/(:num)', 'ValueSet::update/$1'); -$routes->delete('/api/valueset/(:num)', 'ValueSet::delete/$1'); +$routes->patch('/api/valueset', 'ValueSet::update'); +$routes->delete('/api/valueset', 'ValueSet::delete'); $routes->get('/api/valuesetfield/', 'ValueSetField::index'); $routes->get('/api/valuesetfield/(:num)', 'ValueSetField::show/$1'); $routes->post('/api/valuesetfield', 'ValueSetField::create'); -$routes->patch('/api/valuesetfield/(:num)', 'ValueSetField::update/$1'); -$routes->delete('/api/valuesetfield/(:num)', 'ValueSetField::delete/$1'); \ No newline at end of file +$routes->patch('/api/valuesetfield', 'ValueSetField::update'); +$routes->delete('/api/valuesetfield', 'ValueSetField::delete'); \ No newline at end of file diff --git a/app/Controllers/Location.php b/app/Controllers/Location.php index 9ae4358..9ded094 100644 --- a/app/Controllers/Location.php +++ b/app/Controllers/Location.php @@ -10,7 +10,10 @@ class Location extends Controller { public function __construct() { $this->db = \Config\Database::connect(); - $this->now = date('Y-m-d H:i:s'); + $this->rules = [ + 'LocCode' => 'required|max_length[6]', + 'LocFull' => 'required', + ]; } public function index() { @@ -59,19 +62,12 @@ class Location extends Controller { public function create() { try { $input = $this->request->getJSON(true); - $now = date('Y-m-d H:i:s'); // Prepare data - $dataLocation = $this->prepareLocationData($input, $now, 'create'); - $dataLocationAddress = $this->prepareLocationAddressData($input, $now, 'create'); + $dataLocation = $this->prepareLocationData($input); + $dataLocationAddress = $this->prepareLocationAddressData($input); - // Validation rules - $rulesLocation = [ - 'LocCode' => 'required|is_unique[location.LocCode]|max_length[6]', - 'LocFull' => 'required', - ]; - - if (!$this->validateData($dataLocation, $rulesLocation)) { + if (!$this->validateData($dataLocation, $this->rules)) { return $this->failValidationErrors($this->validator->getErrors()); } @@ -101,7 +97,7 @@ class Location extends Controller { return $this->respondCreated([ 'status' => 'success', 'message' => 'Location created successfully', - 'data' => $newLocationID, + 'data' => $dataLocation, ], 201); } catch (\Throwable $e) { @@ -113,22 +109,15 @@ class Location extends Controller { } } - public function update($LocationID = null) { + public function update() { try { $input = $this->request->getJSON(true); - $now = $this->now; // Prepare data - $dataLocation = $this->prepareLocationData($input, $now, 'update'); - $dataLocationAddress = $this->prepareLocationAddressData($input, $now, 'update'); + $dataLocation = $this->prepareLocationData($input); + $dataLocationAddress = $this->prepareLocationAddressData($input); - // Validation rules - $rulesLocation = [ - 'LocCode' => 'required|is_unique[location.LocCode]|max_length[6]', - 'LocFull' => 'required', - ]; - - if (!$this->validateData($dataLocation, $rulesLocation)) { + if (!$this->validateData($dataLocation, $this->rules)) { return $this->failValidationErrors( $this->validator->getErrors()); } @@ -136,11 +125,11 @@ class Location extends Controller { $this->db->transStart(); // Insert location - $this->db->table('location')->where('LocationID', $LocationID)->update($dataLocation); + $this->db->table('location')->where('LocationID', $dataLocation["LocationID"])->update($dataLocation); // Insert address if available if (!empty($dataLocationAddress)) { - $dataLocationAddress['LocationID'] = $LocationID; + $dataLocationAddress['LocationID'] = $input["LocationID"]; $this->db->table('locationaddress')->upsert($dataLocationAddress); } @@ -157,7 +146,7 @@ class Location extends Controller { return $this->respondCreated([ 'status' => 'success', 'message' => 'Location updated successfully', - 'data' => $LocationID, + 'data' => $dataLocation, ], 201); } catch (\Throwable $e) { @@ -169,8 +158,10 @@ class Location extends Controller { } } - public function delete($LocationID = null) { - try { + public function delete() { + try { + $input = $this->request->getJSON(true); + $LocationID = $input["LocationID"]; if (!$LocationID) { return $this->failValidationError('LocationID is required.'); } @@ -181,7 +172,7 @@ class Location extends Controller { return $this->failNotFound("LocationID with {$LocationID} not found."); } - $this->db->table('location')->where('LocationID', $LocationID)->update(['DelDate' => $this->now()]); + $this->db->table('location')->where('LocationID', $LocationID)->update(['DelDate' => NOW()]); return $this->respondDeleted([ 'status' => 'success', @@ -197,7 +188,7 @@ class Location extends Controller { } } - private function prepareLocationData(array $input, string $now, string $mode = 'create'): array { + private function prepareLocationData(array $input): array { $LinkTo = null; if (!empty($input['LinkTo'])) { $ids = array_column($input['LinkTo'], 'InternalPID'); @@ -211,14 +202,12 @@ class Location extends Controller { "Description" => $input['Description'] ?? null, ]; - if ($mode === 'create') { - $data["CreateDate"] = $now; - } + if(!empty($input["LocationID"])) { $data["LocationID"] = $input["LocationID"]; } return $data; } - private function prepareLocationAddressData(array $input, string $now, string $mode = 'create'): array { + private function prepareLocationAddressData(array $input): array { $data = [ "LocationID" => $input['LocationID'] ?? null, "Street1" => $input['Street1'] ?? null, @@ -229,11 +218,7 @@ class Location extends Controller { "GeoLocationSystem" => $input['GeoLocationSystem'] ?? null, "GeoLocationData" => $input['GeoLocationData'] ?? null, ]; - - if ($mode === 'create') { - $data["CreateDate"] = $now; - } - + return $data; } } \ No newline at end of file diff --git a/app/Controllers/Patient.php b/app/Controllers/Patient.php index 609dad0..3522027 100644 --- a/app/Controllers/Patient.php +++ b/app/Controllers/Patient.php @@ -10,7 +10,14 @@ class Patient extends Controller { public function __construct() { $this->db = \Config\Database::connect(); - $this->now = date('Y-m-d H:i:s'); + $this->rulesPatient = [ + 'PatientID' => 'required|is_unique[patient.PatientID]|max_length[50]', + 'AlternatePID' => 'permit_empty|max_length[50]', + 'NameFirst' => 'required|min_length[1]|max_length[255]', + 'EmailAddress1' => 'required|is_unique[patient.EmailAddress1]', + 'Gender' => 'required' + ]; + $this->rulesPatIdt = ['Identifier' => 'required|is_unique[patidt.Identifier]']; } // OK - Done @@ -172,28 +179,21 @@ class Patient extends Controller { $now = date('Y-m-d H:i:s'); // Prepare data - $dataPatient = $this->preparePatientData($input, $now, 'create'); - $dataPatidt = $this->preparePatidtData($input, $now, 'create'); - $dataPatatt = $this->preparePatattData($input, $now, 'create'); - $dataPatcom = $this->preparePatcomData($input, $now, 'create'); + $dataPatient = $this->preparePatientData($input); + $dataPatidt = $this->preparePatidtData($input); + $dataPatatt = $this->preparePatattData($input); + $dataPatcom = $this->preparePatcomData($input); // Validation rules - $rulesPatient = [ - 'PatientID' => 'required|is_unique[patient.PatientID]|max_length[50]', - 'AlternatePID' => 'permit_empty|max_length[50]', - 'NameFirst' => 'required|min_length[1]|max_length[255]', - 'EmailAddress1' => 'required|is_unique[patient.EmailAddress1]', - 'Gender' => 'required' - ]; - $rulesPatidt = ['Identifier' => 'required|is_unique[patidt.Identifier]']; + //$rulesPatidt = ['Identifier' => 'required|is_unique[patidt.Identifier]']; //$rulesPatatt = ['Address' => 'required|is_unique[patatt.Address]']; // Validate patient - if (!$this->validateData($dataPatient, $rulesPatient)) { + if (!$this->validateData($dataPatient, $this->rulesPatient)) { return $this->validationError('patient', $this->validator->getErrors()); } // Validate patidt - if (!$this->validateData($dataPatidt, $rulesPatidt)) { + if (!$this->validateData($dataPatidt, $this->rulesPatIdt)) { return $this->validationError('patidt', $this->validator->getErrors()); } /* Validate patatt (if exists, validate only the first row) @@ -204,7 +204,6 @@ class Patient extends Controller { $this->db->transStart(); - $this->db->table('patient')->insert($dataPatient); $newInternalPatientId = $this->db->insertID(); @@ -212,7 +211,6 @@ class Patient extends Controller { $dataPatidt['InternalPID'] = $newInternalPatientId; $this->db->table('patidt')->insert($dataPatidt); - if (!empty($dataPatatt)) { foreach ($dataPatatt as &$row) { @@ -297,58 +295,43 @@ class Patient extends Controller { "LinkTo" => $LinkTo ]; - // Only set CreateDate when creating - if ($mode === 'create') { - $data["CreateDate"] = $now; - } + if(!empty($input['InternalPID'])) { $data["InternalPID"] = $input["InternalPID"]; } return $data; } - private function preparePatidtData(array $input, string $now, string $mode = 'create'): array { + private function preparePatidtData(array $input ): array { $data = [ "IdentifierType" => $input['Identity']['IdentifierType'] ?? null, "Identifier" => $input['Identity']['Identifier'] ?? null, ]; - if ($mode === 'create') { - $data["CreateDate"] = $now; - } - return $data; } - private function preparePatattData(array $input, string $now, string $mode = 'create'): array { + private function preparePatattData(array $input): array { if (empty($input['Attachments'])) { return []; } - return array_map(function ($attachment) use ($now, $mode) { + return array_map(function ($attachment) { $row = [ "Address" => $attachment['Address'] ?? null, ]; - if ($mode === 'create') { - $row["CreateDate"] = $now; - } return $row; }, $input['Attachments']); } - private function preparePatcomData(array $input, string $now, string $mode = 'create'): array { + private function preparePatcomData(array $input): array { $data = [ "Comment" => $input['Comment'] ?? null, ]; - if ($mode === 'create') { - $data["CreateDate"] = $now; - } - return $data; } - private function validationError(string $context, array $errors) - { + private function validationError(string $context, array $errors) { return $this->respond([ 'status' => 'error', 'message' => "Validation failed ({$context})", @@ -356,39 +339,23 @@ class Patient extends Controller { ], 400); } - - // OK - Done - public function update($InternalPID = null) { + public function update() { try { - $now = $this->now; - if (!$InternalPID || !is_numeric($InternalPID)) { return $this->respond(['status' => 'error', 'message' => 'Invalid or missing InternalPID'], 400); } - $input = $this->request->getJSON(true); if (!$input) { return $this->respond(['status' => 'error', 'message' => 'Invalid JSON input'], 400); } - + if (!$input["InternalPID"] || !is_numeric($input["InternalPID"])) { return $this->respond(['status' => 'error', 'message' => 'Invalid or missing InternalPID'], 400); } + + $InternalPID = $input["InternalPID"]; $patient = $this->db->table('patient')->where('InternalPID', $InternalPID)->get()->getRowArray(); if (!$patient) { return $this->respond(['status' => 'error', 'message' => 'Patient not found'], 404); } - $dataPatient = $this->preparePatientData($input, $now, 'update'); - $dataPatidt = $this->preparePatidtData($input, $now, 'update'); - $dataPatcom = $this->preparePatcomData($input, $now, 'update'); - $dataPatatt = $this->preparePatattData($input, $now, 'update'); - - // Atur aturan validasi dengan pengecualian is_unique untuk InternalPID ini - $rulesDataPatient = [ - 'PatientID' => "required|max_length[50]|is_unique[patient.PatientID,InternalPID,{$InternalPID}]", - 'AlternatePID' => 'permit_empty|max_length[50]', - 'NameFirst' => 'required|min_length[1]|max_length[255]', - 'EmailAddress1' => "required|is_unique[patient.EmailAddress1,InternalPID,{$InternalPID}]", - 'Gender' => 'required' - ]; - - $rulesDataPatidt = [ - 'Identifier' => "required|is_unique[patidt.Identifier,InternalPID,{$InternalPID}]" - ]; + $dataPatient = $this->preparePatientData($input); + $dataPatIdt = $this->preparePatidtData($input); + $dataPatCom = $this->preparePatcomData($input); + $dataPatAtt = $this->preparePatattData($input); // Validasi - if (!$this->validateData($dataPatient, $rulesDataPatient)) { + if (!$this->validateData($dataPatient, $this->rulesPatient)) { return $this->respond([ 'status' => 'error', 'message' => 'Validation failed (patient)', @@ -396,7 +363,7 @@ class Patient extends Controller { ], 400); } - if (!$this->validateData($dataPatidt, $rulesDataPatidt)) { + if (!$this->validateData($dataPatIdt, $this->rulesPatIdt)) { return $this->respond([ 'status' => 'error', 'message' => 'Validation failed (patidt)', @@ -413,19 +380,19 @@ class Patient extends Controller { return $this->failServerError('Update patient failed: ' . $dbError['message']); } - $this->db->table('patidt')->where('InternalPID', $InternalPID)->update($dataPatidt); + $this->db->table('patidt')->where('InternalPID', $InternalPID)->update($dataPatIdt); $dbError = $this->db->error(); if (!empty($dbError['message'])) { $this->db->transRollback(); return $this->failServerError('Update patidt failed: ' . $dbError['message']); } - if (!empty($dataPatatt)) { - foreach ($dataPatatt as &$row) { + if (!empty($dataPatAtt)) { + foreach ($dataPatAtt as &$row) { $row['InternalPID'] = $InternalPID; } - $this->db->table('patatt')->upsertBatch($dataPatatt); - $addresses = array_column($dataPatatt, 'Address'); + $this->db->table('patatt')->upsertBatch($dataPatAtt); + $addresses = array_column($dataPatAtt, 'Address'); $this->db->table('patatt')->where('InternalPID', $InternalPID)->WhereNotIn('Address', $addresses)->update(['DelDate' => date('Y-m-d H:i:s')]); } else { $this->db->table('patatt')->where('InternalPID', $InternalPID)->update(['DelDate' => date('Y-m-d H:i:s')]); @@ -433,8 +400,7 @@ class Patient extends Controller { if(!empty($dataPatcom['Comment'])) { $dataPatcom['InternalPID'] = $InternalPID; - $dataPatcom['CreateDate'] = $this->now; - $this->db->table('patcom')->upsert($dataPatcom); + $this->db->table('patcom')->upsert($dataPatCom); } $this->db->transComplete(); @@ -447,7 +413,7 @@ class Patient extends Controller { return $this->respond([ 'status' => 'success', 'message' => 'Patient updated successfully', - 'data' => $InternalPID + 'data' => $dataPatient ], 200); } catch (\Exception $e) { @@ -456,28 +422,23 @@ class Patient extends Controller { } } - // OK - Done - public function delete($InternalPID = null) { - + public function delete() { try { - - $InternalPID = (int) $InternalPID; + $input = $this->request->getJSON(true); + $InternalPID = $input["InternalPID"]; if (!$InternalPID) { return $this->failValidationError('Patient ID is required.'); } - // Cari data pasien $patient = $this->db->table('patient')->where('InternalPID', $InternalPID)->get()->getRow(); if (!$patient) { return $this->failNotFound("Patient ID with {$InternalPID} not found."); } - // Update kolom DelDate sebagai soft delete $this->db->table('patient')->where('InternalPID', $InternalPID)->update(['DelDate' => date('Y-m-d H:i:s')]); - // Mengembalikan 200 return $this->respondDeleted([ 'status' => 'success', 'message' => "Patient ID with {$InternalPID} deleted successfully." @@ -490,9 +451,7 @@ class Patient extends Controller { // OK - Done public function patientCheck() { - try { - $PatientID = $this->request->getVar('PatientID'); $EmailAddress1 = $this->request->getVar('EmailAddress1'); diff --git a/app/Controllers/ValueSet.php b/app/Controllers/ValueSet.php index 6fca919..3b30740 100644 --- a/app/Controllers/ValueSet.php +++ b/app/Controllers/ValueSet.php @@ -10,8 +10,7 @@ class ValueSet extends Controller { public function __construct() { $this->db = \Config\Database::connect(); - $this->now = date('Y-m-d H:i:s'); - $this->rules = [ + $this->rulesValueSet = [ 'VSet' => 'required', 'VValue' => 'required', ]; @@ -61,12 +60,10 @@ class ValueSet extends Controller { public function create() { try { $input = $this->request->getJSON(true); - $now = date('Y-m-d H:i:s'); - // Prepare data - $data = $this->prepareData($input, $now, 'create'); + $dataValueSet = $this->prepareDataValueSet($input); - if (!$this->validateData($data, $this->rules)) { + if (!$this->validateData($data, $this->rulesValueSet)) { return $this->failValidationErrors($this->validator->getErrors()); } @@ -89,7 +86,7 @@ class ValueSet extends Controller { return $this->respondCreated([ 'status' => 'success', 'message' => 'Data created successfully', - 'data' => $data, + 'data' => $dataValueSet, ], 201); } catch (\Throwable $e) { @@ -101,14 +98,17 @@ class ValueSet extends Controller { } } - public function update($VID = null) { + public function update() { try { $input = $this->request->getJSON(true); - $now = $this->now; + $VID = $input["VID"]; + if (!$VID) { + return $this->failValidationErrors('VID is required.'); + } - $data = $this->prepareData($input, $now, 'update'); + $dataValueSet = $this->prepareValueSetData($input); - if (!$this->validateData($data, $this->rules)) { + if (!$this->validateData($dataValueSet, $this->rulesValueSet)) { return $this->failValidationErrors( $this->validator->getErrors() ); } @@ -116,7 +116,7 @@ class ValueSet extends Controller { $this->db->transStart(); // Insert location - $this->db->table('valueset')->where('VID', $VID)->update($data); + $this->db->table('valueset')->where('VID', $VID)->update($dataValueSet); // Complete transaction $this->db->transComplete(); @@ -131,7 +131,7 @@ class ValueSet extends Controller { return $this->respondCreated([ 'status' => 'success', 'message' => 'Data updated successfully', - 'data' => $data, + 'data' => $dataValueSet, ], 201); } catch (\Throwable $e) { @@ -143,8 +143,10 @@ class ValueSet extends Controller { } } - public function delete($VID = null) { - try { + public function delete() { + try { + $input = $this->request->getJSON(true); + $VID = $input["VID"]; if (!$VID) { return $this->failValidationErrors('VID is required.'); } @@ -170,7 +172,7 @@ class ValueSet extends Controller { } } - private function prepareData(array $input, string $now, string $mode = 'create'): array { + private function prepareValueSetData(array $input): array { $data = [ "VSet" => $input['VSet'] ?? null, "VOrder" => $input['VOrder'] ?? null, @@ -179,9 +181,7 @@ class ValueSet extends Controller { "VCategory" => $input['VCategory'] ?? null ]; - if ($mode === 'create') { - $data["CreateDate"] = $now; - } + if(!empty($input["VID"])) { $data["VID"]=$input["VID"]; } return $data; } diff --git a/app/Controllers/ValueSetField.php b/app/Controllers/ValueSetField.php index 11eec20..75f33eb 100644 --- a/app/Controllers/ValueSetField.php +++ b/app/Controllers/ValueSetField.php @@ -10,8 +10,7 @@ class ValueSetField extends Controller { public function __construct() { $this->db = \Config\Database::connect(); - $this->now = date('Y-m-d H:i:s'); - $this->rules = [ + $this->rulesValueSetFld = [ 'VSet' => 'required', 'VSName' => 'required', 'VSDesc' => 'required' @@ -62,21 +61,14 @@ class ValueSetField extends Controller { public function create() { try { $input = $this->request->getJSON(true); - $now = date('Y-m-d H:i:s'); + $dataValueSetFld = $this->prepareData($input); - $data = $this->prepareData($input, $now, 'create'); - - if (!$this->validateData($data, $this->rules)) { + if (!$this->validateData($dataValueSetFld, $this->rulesValueSetFld)) { return $this->failValidationErrors($this->validator->getErrors()); } - // Start transaction $this->db->transStart(); - - // Insert - $this->db->table('valuesetfld')->insert($data); - - // Complete transaction + $this->db->table('valuesetfld')->insert($dataValueSetFld); $this->db->transComplete(); if ($this->db->transStatus() === false) { @@ -89,7 +81,7 @@ class ValueSetField extends Controller { return $this->respondCreated([ 'status' => 'success', 'message' => 'Data created successfully', - 'data' => $data, + 'data' => $dataValueSetFld, ], 201); } catch (\Throwable $e) { @@ -101,24 +93,21 @@ class ValueSetField extends Controller { } } - public function update($VSFldID = null) { + public function update() { try { $input = $this->request->getJSON(true); - $now = $this->now; + $VSFldID = $input["VSFldID"]; + if (!$VSFldID) { + return $this->failValidationErrors('VSFldID is required.'); + } + $dataValueSetFld = $this->prepareData($input); - $data = $this->prepareData($input, $now, 'update'); - - if (!$this->validateData($data, $this->rules)) { + if (!$this->validateData($data, $this->rulesValueSetFld)) { return $this->failValidationErrors( $this->validator->getErrors()); } - // Start transaction $this->db->transStart(); - - // Insert location $this->db->table('valuesetfld')->where('VSFldID', $VSFldID)->update($data); - - // Complete transaction $this->db->transComplete(); if ($this->db->transStatus() === false) { @@ -131,7 +120,7 @@ class ValueSetField extends Controller { return $this->respondCreated([ 'status' => 'success', 'message' => 'Data updated successfully', - 'data' => $data, + 'data' => $dataValueSetFld, ], 201); } catch (\Throwable $e) { @@ -143,8 +132,10 @@ class ValueSetField extends Controller { } } - public function delete($VSFldID = null) { - try { + public function delete() { + try { + $input = $this->request->getJSON(true); + $VSFldID = $input["VSFldID"]; if (!$VSFldID) { return $this->failValidationErrors('VSFldID is required.'); } @@ -177,10 +168,6 @@ class ValueSetField extends Controller { "VSDesc" => $input['VSDesc'] ?? null ]; - if ($mode === 'create') { - $data["CreateDate"] = $now; - } - return $data; } diff --git a/app/Database/Migrations/2025-09-02-070522_Patient_master.php b/app/Database/Migrations/2025-09-02-070522_Patient_master.php index 98a8f1b..ff7ac2b 100644 --- a/app/Database/Migrations/2025-09-02-070522_Patient_master.php +++ b/app/Database/Migrations/2025-09-02-070522_Patient_master.php @@ -13,9 +13,9 @@ class CreatePatMasterTables extends Migration { 'IntCountryID' => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true, 'auto_increment' => true], 'CountryID' => ['type' => 'VARCHAR', 'constraint' => 10], 'Country' => ['type' => 'VARCHAR', 'constraint' => 255, 'null' => true], - 'CreateDate' => ['type' => 'DATETIME', 'null' => true], 'EndDate' => ['type' => 'DATETIME', 'null' => true], ]); + $this->forge->addField('CreateDate DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP'); $this->forge->addKey('IntCountryID', true); $this->forge->addUniqueKey('CountryID'); $this->forge->createTable('country'); @@ -26,9 +26,9 @@ class CreatePatMasterTables extends Migration { 'CodingSysID' => ['type' => 'INT', 'constraint' => 11, 'null' => true], 'EthnicID' => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true, 'auto_increment' => true], 'Ethnic' => ['type' => 'VARCHAR', 'constraint' => 255, 'null' => true], - 'CreateDate' => ['type' => 'DATETIME', 'null' => true], 'EndDate' => ['type' => 'DATETIME', 'null' => true], ]); + $this->forge->addField('CreateDate DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP'); $this->forge->addKey('EthnicID', true); $this->forge->createTable('ethnic'); @@ -38,9 +38,9 @@ class CreatePatMasterTables extends Migration { 'CodingSysID' => ['type' => 'INT', 'constraint' => 11, 'null' => true], 'RaceID' => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true, 'auto_increment' => true], 'Race' => ['type' => 'VARCHAR', 'constraint' => 255, 'null' => true], - 'CreateDate' => ['type' => 'DATETIME', 'null' => true], 'EndDate' => ['type' => 'DATETIME', 'null' => true], ]); + $this->forge->addField('CreateDate DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP'); $this->forge->addKey('RaceID', true); $this->forge->createTable('race'); @@ -50,9 +50,9 @@ class CreatePatMasterTables extends Migration { 'CodingSysID' => ['type' => 'INT', 'constraint' => 11, 'null' => true], 'ReligionID' => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true, 'auto_increment' => true], 'Religion' => ['type' => 'VARCHAR', 'constraint' => 255, 'null' => true], - 'CreateDate' => ['type' => 'DATETIME', 'null' => true], 'EndDate' => ['type' => 'DATETIME', 'null' => true], ]); + $this->forge->addField('CreateDate DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP'); $this->forge->addKey('ReligionID', true); $this->forge->createTable('religion'); } diff --git a/app/Database/Migrations/2025-09-02-070826_Patient_Reg.php b/app/Database/Migrations/2025-09-02-070826_Patient_Reg.php index 4307a39..2db4552 100644 --- a/app/Database/Migrations/2025-09-02-070826_Patient_Reg.php +++ b/app/Database/Migrations/2025-09-02-070826_Patient_Reg.php @@ -12,9 +12,9 @@ class CreatePatientRegTables extends Migration { 'InternalPID'=> ['type' => 'INT', 'constraint' => 11, 'null' => true], 'Address' => ['type' => 'VARCHAR', 'constraint' => 255, 'null' => true], 'UserID' => ['type' => 'INT', 'constraint' => 11, 'null' => true], - 'CreateDate' => ['type' => 'DATETIME', 'null' => true], 'DelDate' => ['type' => 'DATETIME', 'null' => true], ]); + $this->forge->addField('CreateDate DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP'); $this->forge->addKey('PatAttID', true); $this->forge->addUniqueKey('Address'); $this->forge->createTable('patatt'); @@ -24,9 +24,9 @@ class CreatePatientRegTables extends Migration { 'PatComID' => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true, 'auto_increment' => true], 'InternalPID'=> ['type' => 'INT', 'constraint' => 11, 'null' => true], 'Comment' => ['type' => 'TEXT', 'null' => true], - 'CreateDate' => ['type' => 'DATETIME', 'null' => true], 'EndDate' => ['type' => 'DATETIME', 'null' => true], ]); + $this->forge->addField('CreateDate DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP'); $this->forge->addKey('PatComID', true); $this->forge->addUniqueKey('InternalPID'); $this->forge->createTable('patcom'); @@ -39,9 +39,9 @@ class CreatePatientRegTables extends Migration { 'Identifier' => ['type' => 'VARCHAR', 'constraint' => 255, 'null' => true], 'EffectiveDate' => ['type' => 'DATETIME', 'null' => true], 'ExpirationDate'=> ['type' => 'DATETIME', 'null' => true], - 'CreateDate' => ['type' => 'DATETIME', 'null' => true], 'DelDate' => ['type' => 'DATETIME', 'null' => true], ]); + $this->forge->addField('CreateDate DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP'); $this->forge->addKey('PatIdtID', true); $this->forge->createTable('patidt'); @@ -81,9 +81,9 @@ class CreatePatientRegTables extends Migration { 'DeathIndicator'=> ['type' => 'BIT', 'constraint' => 1, 'null' => true], 'DeathDateTime' => ['type' => 'DATETIME', 'null' => true], 'LinkTo' => ['type' => 'VARCHAR', 'constraint' => 255, 'null' => true], - 'CreateDate' => ['type' => 'DATETIME', 'null' => true], 'DelDate' => ['type' => 'DATETIME', 'null' => true], ]); + $this->forge->addField('CreateDate DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP'); $this->forge->addKey('InternalPID', true); $this->forge->addUniqueKey('PatientID'); $this->forge->addUniqueKey('AlternatePID'); @@ -109,8 +109,8 @@ class CreatePatientRegTables extends Migration { 'EventID' => ['type' => 'VARCHAR', 'constraint' => 255, 'null' => true], 'ActivityID' => ['type' => 'VARCHAR', 'constraint' => 255, 'null' => true], 'Reason' => ['type' => 'VARCHAR', 'constraint' => 255, 'null' => true], - 'LogDate' => ['type' => 'DATETIME', 'null' => true], ]); + $this->forge->addField('LogDate DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP'); $this->forge->addKey('PatRegLogID', true); $this->forge->createTable('patreglog'); @@ -118,9 +118,9 @@ class CreatePatientRegTables extends Migration { $this->forge->addField([ 'PatRelID' => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true, 'auto_increment' => true], 'InternalPID'=> ['type' => 'INT', 'constraint' => 11, 'null' => true], - 'CreateDate' => ['type' => 'DATETIME', 'null' => true], 'EndDate' => ['type' => 'DATETIME', 'null' => true], ]); + $this->forge->addField('CreateDate DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP'); $this->forge->addKey('PatRelID', true); $this->forge->createTable('patrelation'); } diff --git a/app/Database/Migrations/2025-09-09-155526_Patient_Vst.php b/app/Database/Migrations/2025-09-09-155526_Patient_Vst.php index 50d111e..0dc8894 100644 --- a/app/Database/Migrations/2025-09-09-155526_Patient_Vst.php +++ b/app/Database/Migrations/2025-09-09-155526_Patient_Vst.php @@ -13,11 +13,11 @@ class CreatePVTables extends Migration { 'PVID' => ['type' => 'VARCHAR', 'constraint' => 20, 'null' => true], 'InternalPID' => ['type' => 'INT', 'constraint' => 11, 'null' => true], 'Episode' => ['type' => 'VARCHAR', 'constraint' => 255, 'null' => true], - 'CreateDate' => ['type' => 'DATETIME', 'null' => true], 'EndDate' => ['type' => 'DATETIME', 'null' => true], 'ArchivedDate'=> ['type' => 'DATETIME', 'null' => true], 'DelDate' => ['type' => 'DATETIME', 'null' => true], ]); + $this->forge->addField('CreateDate DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP'); $this->forge->addKey('InternalPVID', true); $this->forge->createTable('patvisit'); @@ -27,11 +27,11 @@ class CreatePVTables extends Migration { 'InternalPID' => ['type' => 'INT', 'constraint' => 11, 'null' => true], 'DiagCode' => ['type' => 'VARCHAR', 'constraint' => 255, 'null' => true], 'Diagnosis' => ['type' => 'TEXT', 'null' => true], - 'CreateDate' => ['type' => 'DATETIME', 'null' => true], 'EndDate' => ['type' => 'DATETIME', 'null' => true], 'ArchivedDate' => ['type' => 'DATETIME', 'null' => true], 'DelDate' => ['type' => 'DATETIME', 'null' => true], ]); + $this->forge->addField('CreateDate DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP'); $this->forge->addKey('InternalPVID', true); $this->forge->createTable('patdiag'); @@ -45,11 +45,11 @@ class CreatePVTables extends Migration { 'ReffDoc' => ['type' => 'INT', 'constraint' => 11, 'null' => true], 'AdmDoc' => ['type' => 'INT', 'constraint' => 11, 'null' => true], 'CnsDoc' => ['type' => 'INT', 'constraint' => 11, 'null' => true], - 'CreateDate' => ['type' => 'DATETIME', 'null' => true], 'EndDate' => ['type' => 'DATETIME', 'null' => true], 'ArchivedDate'=> ['type' => 'DATETIME', 'null' => true], 'DelDate' => ['type' => 'DATETIME', 'null' => true], ]); + $this->forge->addField('CreateDate DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP'); $this->forge->addKey('PVADTID', true); $this->forge->createTable('patvisitadt'); @@ -73,8 +73,8 @@ class CreatePVTables extends Migration { 'EventID' => ['type' => 'VARCHAR', 'constraint' => 255, 'null' => true], 'ActivityID' => ['type' => 'VARCHAR', 'constraint' => 255, 'null' => true], 'Reason' => ['type' => 'VARCHAR', 'constraint' => 255, 'null' => true], - 'LogDate' => ['type' => 'DATETIME', 'null' => true], ]); + $this->forge->addField('LogDate DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP'); $this->forge->addKey('PatVisLogID', true); $this->forge->createTable('patvisitlog'); } diff --git a/app/Database/Migrations/2025-09-10-141522_Location.php b/app/Database/Migrations/2025-09-10-141522_Location.php index 1ea6a88..0a9d639 100644 --- a/app/Database/Migrations/2025-09-10-141522_Location.php +++ b/app/Database/Migrations/2025-09-10-141522_Location.php @@ -14,9 +14,9 @@ class CreateLocationTable extends Migration { 'Parent' => ['type' => 'INT', 'null' => true], 'LocFull' => ['type' => 'varchar', 'constraint' => 255, 'null' => true], 'Description' => ['type' => 'varchar', 'constraint' => 255, 'null' => true], - 'CreateDate' => ['type' => 'DATETIME', 'null' => true], 'EndDate' => ['type' => 'DATETIME', 'null' => true] ]); + $this->forge->addField('CreateDate DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP'); $this->forge->addKey('LocationID', true); $this->forge->createTable('location'); @@ -29,9 +29,9 @@ class CreateLocationTable extends Migration { 'PostCode' => ['type' => 'varchar', 'constraint' => 255, 'null' => true], 'GeoLocationSystem' => ['type' => 'varchar', 'constraint' => 255, 'null' => true], 'GeoLocationData' => ['type' => 'varchar', 'constraint' => 255, 'null' => true], - 'CreateDate' => ['type' => 'DATETIME', 'null' => true], 'EndDate' => ['type' => 'DATETIME', 'null' => true] ]); + $this->forge->addField('CreateDate DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP'); $this->forge->addKey('LocationID', true); $this->forge->createTable('locationaddress'); } diff --git a/app/Database/Migrations/2025-09-12-011643_DoctorMaster.php b/app/Database/Migrations/2025-09-12-011643_DoctorMaster.php index 14ff1c5..766c283 100644 --- a/app/Database/Migrations/2025-09-12-011643_DoctorMaster.php +++ b/app/Database/Migrations/2025-09-12-011643_DoctorMaster.php @@ -14,8 +14,8 @@ class DoctorMaster extends Migration 'AbbTex' => [ 'type' => 'VARCHAR', 'constraint' => 5, 'null' => true ], 'FullText' => [ 'type' => 'VARCHAR', 'constraint' => 255, 'null' => true ], 'Description' => [ 'type' => 'TEXT', 'null' => true ], - 'CreateDate' => [ 'type' => 'DATETIME'], ]); + $this->forge->addField('CreateDate DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP'); $this->forge->addKey('OccupationID', true); $this->forge->createTable('Occupation'); @@ -34,9 +34,9 @@ class DoctorMaster extends Migration 'MobilePhone2' => [ 'type' => 'VARCHAR', 'constraint' => 50, 'null' => true ], 'Specialty' => [ 'type' => 'VARCHAR', 'constraint' => 100, 'null' => true ], 'SubSpecialty' => [ 'type' => 'VARCHAR', 'constraint' => 100, 'null' => true ], - 'CreateDate' => [ 'type' => 'DATETIME'], 'EndDate' => [ 'type' => 'DATETIME', 'null' => true ], ]); + $this->forge->addField('CreateDate DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP'); $this->forge->addKey('ContactID', true); $this->forge->createTable('Contact'); @@ -64,8 +64,8 @@ class DoctorMaster extends Migration 'EndDate' => [ 'type' => 'DATETIME', 'null' => true ], 'Facilitator' => [ 'type' => 'VARCHAR', 'constraint' => 150, 'null' => true ], 'CertificateLocation'=> [ 'type' => 'VARCHAR', 'constraint' => 255, 'null' => true ], - 'CreateDate' => [ 'type' => 'DATETIME'], ]); + $this->forge->addField('CreateDate DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP'); // $this->forge->addKey('ContactID', true); $this->forge->createTable('ContactTraining'); @@ -75,9 +75,9 @@ class DoctorMaster extends Migration 'SpecialtyText' => [ 'type' => 'VARCHAR', 'constraint' => 255, 'null' => true ], 'Parent' => [ 'type' => 'VARCHAR', 'constraint' => 50, 'null' => true ], 'Title' => [ 'type' => 'VARCHAR', 'constraint' => 50, 'null' => true ], - 'CreateDate' => [ 'type' => 'DATETIME'], 'EndDate' => [ 'type' => 'DATETIME', 'null' => true ], ]); + $this->forge->addField('CreateDate DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP'); $this->forge->addKey('SpecialtyID', true); $this->forge->createTable('MedicalSpecialty'); } diff --git a/app/Database/Migrations/2025-09-12-100001_Orders.php b/app/Database/Migrations/2025-09-12-100001_Orders.php index a94b01f..3e7658d 100644 --- a/app/Database/Migrations/2025-09-12-100001_Orders.php +++ b/app/Database/Migrations/2025-09-12-100001_Orders.php @@ -18,11 +18,11 @@ class CreateOrdersTable extends Migration { 'Priority' => ['type' => 'VARCHAR', 'constraint' => 50, 'null' => true], 'TrnDate' => ['type' => 'Datetime', 'null' => true], 'EffDate' => ['type' => 'Datetime', 'null' => true], - 'CreateDate' => ['type' => 'Datetime', 'null' => true], 'EndDate' => ['type' => 'Datetime', 'null' => true], 'ArchiveDate' => ['type' => 'Datetime', 'null' => true], 'DelDate' => ['type' => 'Datetime', 'null' => true] ]); + $this->forge->addField('CreateDate DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP'); $this->forge->addKey('InternalOID', true); $this->forge->addUniqueKey('OrderID'); $this->forge->createTable('ordertest'); @@ -32,11 +32,11 @@ class CreateOrdersTable extends Migration { 'OrderComID' => ['type' => 'INT', 'auto_increment' => true, 'unsigned' => true], 'Comment' => ['type' => 'text', 'null' => true], 'UserID' => ['type' => 'INT', 'null' => false], - 'CreateDate' => ['type' => 'Datetime', 'null' => true], 'EndDate' => ['type' => 'Datetime', 'null' => true], 'ArchiveDate' => ['type' => 'Datetime', 'null' => true], 'DelDate' => ['type' => 'Datetime', 'null' => true] ]); + $this->forge->addField('CreateDate DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP'); $this->forge->addKey('OrderComID', true); $this->forge->createTable('ordercom'); @@ -45,11 +45,11 @@ class CreateOrdersTable extends Migration { 'OrderAttID' => ['type' => 'INT', 'auto_increment' => true, 'unsigned' => true], 'Address' => ['type' => 'varchar', 'constraint'=>255, 'null' => true], 'UserID' => ['type' => 'INT', 'null' => false], - 'CreateDate' => ['type' => 'Datetime', 'null' => true], 'EndDate' => ['type' => 'Datetime', 'null' => true], 'ArchiveDate' => ['type' => 'Datetime', 'null' => true], 'DelDate' => ['type' => 'Datetime', 'null' => true] ]); + $this->forge->addField('CreateDate DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP'); $this->forge->addKey('OrderAttID', true); $this->forge->createTable('orderatt'); @@ -57,11 +57,11 @@ class CreateOrdersTable extends Migration { 'InternalOID' => ['type' => 'INT', 'null' => false], 'OrderStatID' => ['type' => 'INT', 'auto_increment' => true, 'unsigned' => true], 'OrderStatus' => ['type' => 'varchar', 'constraint'=>2, 'null' => false], - 'CreateDate' => ['type' => 'Datetime', 'null' => true], 'EndDate' => ['type' => 'Datetime', 'null' => true], 'ArchiveDate' => ['type' => 'Datetime', 'null' => true], 'DelDate' => ['type' => 'Datetime', 'null' => true] ]); + $this->forge->addField('CreateDate DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP'); $this->forge->addKey('OrderStatID', true); $this->forge->createTable('orderstatus'); diff --git a/app/Database/Migrations/2025-09-15-130122_ValueSet.php b/app/Database/Migrations/2025-09-15-130122_ValueSet.php index 8153844..47b9e2a 100644 --- a/app/Database/Migrations/2025-09-15-130122_ValueSet.php +++ b/app/Database/Migrations/2025-09-15-130122_ValueSet.php @@ -15,9 +15,9 @@ class CreateValueSetTable extends Migration { 'VValue' => ['type' => 'varchar', 'constraint' => 10], 'VDesc' => ['type' => 'varchar', 'constraint' => 255, 'null' => true], 'VCategory' => ['type' => 'int', 'null' => true], - 'CreateDate' => ['type' => 'DATETIME', 'null' => true], 'EndDate' => ['type' => 'DATETIME', 'null' => true] ]); + $this->forge->addField('CreateDate DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP'); $this->forge->addKey('VID', true); $this->forge->createTable('valueset'); @@ -27,9 +27,9 @@ class CreateValueSetTable extends Migration { 'VSet' => ['type' => 'INT', 'null' => false], 'VSName' => ['type' => 'VARCHAR', 'constraint' => 255, 'null' => false], 'VSDesc' => ['type' => 'VARCHAR', 'constraint' => 255, 'null' => false], - 'CreateDate' => ['type' => 'DATETIME', 'null' => true], 'EndDate' => ['type' => 'DATETIME', 'null' => true] ]); + $this->forge->addField('CreateDate DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP'); $this->forge->addKey('VSFldID', true); $this->forge->createTable('valuesetfld'); }