From a450392cfc9b54614657a7de924bac0399b5ff7a Mon Sep 17 00:00:00 2001 From: mahdahar <89adham@gmail.com> Date: Mon, 10 Nov 2025 16:02:52 +0700 Subject: [PATCH] standard crud for specimen and test --- app/Config/Routes.php | 59 ++++++++++++++++++ app/Controllers/Specimen/Specimen.php | 62 +++++++++++++++++++ .../Specimen/SpecimenCollection.php | 62 +++++++++++++++++++ app/Controllers/Specimen/SpecimenPrep.php | 62 +++++++++++++++++++ app/Controllers/Specimen/SpecimenStatus.php | 62 +++++++++++++++++++ .../Test/{ValueSetDef.php => TestDef.php} | 33 +++------- app/Controllers/Test/TestDefCal.php | 56 +++++++++++++++++ app/Controllers/Test/TestDefSite.php | 56 +++++++++++++++++ app/Controllers/Test/TestDefTech.php | 56 +++++++++++++++++ app/Controllers/Test/TestGrp.php | 56 +++++++++++++++++ app/Controllers/Test/TestMap.php | 56 +++++++++++++++++ .../Migrations/2025-10-07-132705_Specimen.php | 18 +++--- .../Migrations/2025-10-11-100001_Test.php | 30 ++++++--- app/Models/Specimen/ContainerDefModel.php | 5 -- .../Specimen/SpecimenCollectionModel.php | 18 ++++++ app/Models/Specimen/SpecimenLogModel.php | 16 +++++ app/Models/Specimen/SpecimenModel.php | 18 ++++++ app/Models/Specimen/SpecimenPrepModel.php | 17 +++++ app/Models/Specimen/SpecimenStatusModel.php | 18 ++++++ app/Models/Test/TestDefCalModel.php | 2 +- app/Models/Test/TestDefModel.php | 2 +- app/Models/Test/TestDefTechModel.php | 3 +- app/Models/Test/TestMapModel.php | 19 ++++++ 23 files changed, 738 insertions(+), 48 deletions(-) create mode 100644 app/Controllers/Specimen/Specimen.php create mode 100644 app/Controllers/Specimen/SpecimenCollection.php create mode 100644 app/Controllers/Specimen/SpecimenPrep.php create mode 100644 app/Controllers/Specimen/SpecimenStatus.php rename app/Controllers/Test/{ValueSetDef.php => TestDef.php} (62%) create mode 100644 app/Controllers/Test/TestDefCal.php create mode 100644 app/Controllers/Test/TestDefSite.php create mode 100644 app/Controllers/Test/TestDefTech.php create mode 100644 app/Controllers/Test/TestGrp.php create mode 100644 app/Controllers/Test/TestMap.php create mode 100644 app/Models/Specimen/SpecimenCollectionModel.php create mode 100644 app/Models/Specimen/SpecimenLogModel.php create mode 100644 app/Models/Specimen/SpecimenModel.php create mode 100644 app/Models/Specimen/SpecimenPrepModel.php create mode 100644 app/Models/Specimen/SpecimenStatusModel.php create mode 100644 app/Models/Test/TestMapModel.php diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 398871f..4323717 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -126,6 +126,65 @@ $routes->post('/api/organization/workstation', 'Organization\Workstation::create $routes->patch('/api/organization/workstation', 'Organization\Workstation::update'); $routes->delete('/api/organization/workstation', 'Organization\Workstation::delete'); +$routes->group('api/specimen', function($routes) { + $routes->get('/containerdef/(:num)', 'Specimen\ContainerDef::show/$1'); + $routes->post('/containerdef', 'Specimen\ContainerDef::create'); + $routes->patch('/containerdef', 'Specimen\ContainerDef::update'); + $routes->get('/containerdef', 'Specimen\ContainerDef::index'); + + $routes->get('/prep/(:num)', 'Specimen\Prep::show/$1'); + $routes->post('/prep', 'Specimen\Prep::create'); + $routes->patch('/prep', 'Specimen\Prep::update'); + $routes->get('/prep', 'Specimen\Prep::index'); + + $routes->get('/status/(:num)', 'Specimen\Status::show/$1'); + $routes->post('/status', 'Specimen\Status::create'); + $routes->patch('/status', 'Specimen\Status::update'); + $routes->get('/status', 'Specimen\Status::index'); + + $routes->get('/collection/(:num)', 'Specimen\Collection::show/$1'); + $routes->post('/collection', 'Specimen\Collection::create'); + $routes->patch('/collection', 'Specimen\Collection::update'); + $routes->get('/collection', 'Specimen\Collection::index'); + + $routes->get('(:num)', 'Specimen\Specimen::show/$1'); + $routes->post('', 'Specimen\Specimen::create'); + $routes->patch('', 'Specimen\Specimen::update'); + $routes->get('', 'Specimen\Specimen::index'); +}); + +$routes->group('api/test', function($routes) { + $routes->get('testdeftech/(:num)', 'Test\TestDefTech::show/$1'); + $routes->post('testdeftech', 'Test\TestDefTech::create'); + $routes->patch('testdeftech', 'Test\TestDefTech::update'); + $routes->get('testdeftech/', 'Test\TestDefTech::index'); + + $routes->get('testdefcal/(:num)', 'Test\TestDefCal::show/$1'); + $routes->post('testdefcal', 'Test\TestDefCal::create'); + $routes->patch('testdefcal', 'Test\TestDefCal::update'); + $routes->get('testdefcal/', 'Test\TestDefCal::index'); + + $routes->get('testgrp/(:num)', 'Test\TestGrp::show/$1'); + $routes->post('testgrp', 'Test\TestGrp::create'); + $routes->patch('testgrp', 'Test\TestGrp::update'); + $routes->get('testgrp/', 'Test\TestGrp::index'); + + $routes->get('testdefsite/(:num)', 'Test\TestDefSite::show/$1'); + $routes->post('testdefsite', 'Test\TestDefSite::create'); + $routes->patch('testdefsite', 'Test\TestDefSite::update'); + $routes->get('testdefsite/', 'Test\TestDefSite::index'); + + $routes->get('testmap/(:num)', 'Test\TestMap::show/$1'); + $routes->post('testmap', 'Test\TestMap::create'); + $routes->patch('testmap', 'Test\TestMap::update'); + $routes->get('testmap/', 'Test\TestMap::index'); + + $routes->get('testdef/(:num)', 'Test\TestDef::show/$1'); + $routes->post('testdef', 'Test\TestDef::create'); + $routes->patch('testdef', 'Test\TestDef::update'); + $routes->get('testdef', 'Test\TestDef::index'); +}); + // Khusus $routes->get('/api/zones', 'Zones::index'); $routes->get('/api/zones/synchronize', 'Zones::synchronize'); diff --git a/app/Controllers/Specimen/Specimen.php b/app/Controllers/Specimen/Specimen.php new file mode 100644 index 0000000..b7ff7ee --- /dev/null +++ b/app/Controllers/Specimen/Specimen.php @@ -0,0 +1,62 @@ +db = \Config\Database::connect(); + $this->model = new SpecimenModel(); + $this->rules = []; + } + + public function index() { + try { + $rows = $this->model->findAll(); + return $this->respond([ 'status' => 'success', 'message'=> "data fetched successfully", 'data' => $rows ], 200); + } catch (\Exception $e) { + return $this->failServerError('Exception : '.$e->getMessage()); + } + } + + public function show($id) { + try { + $rows = $this->model->where('SID',$id)->findAll(); + return $this->respond([ 'status' => 'success', 'message'=> "data fetched successfully", 'data' => $rows ], 200); + } catch (\Exception $e) { + return $this->failServerError('Exception : '.$e->getMessage()); + } + } + + public function create() { + $input = $this->request->getJSON(true); + if (!$this->validateData($input, $this->rules)) { return $this->failValidationErrors($this->validator->getErrors()); } + try { + $id = $this->model->insert($input); + return $this->respondCreated([ 'status' => 'success', 'message' => "data $id created successfully" ]); + } catch (\Exception $e) { + return $this->failServerError('Something went wrong: ' . $e->getMessage()); + } + } + + public function update() { + $input = $this->request->getJSON(true); + if (!$this->validateData($input, $this->rules)) { return $this->failValidationErrors($this->validator->getErrors()); } + try { + $id = $this->model->update($input['SID'], $input); + return $this->respondCreated([ 'status' => 'success', 'message' => "data $id updated successfully" ]); + } catch (\Exception $e) { + return $this->failServerError('Something went wrong: ' . $e->getMessage()); + } + } + +} \ No newline at end of file diff --git a/app/Controllers/Specimen/SpecimenCollection.php b/app/Controllers/Specimen/SpecimenCollection.php new file mode 100644 index 0000000..edcf5af --- /dev/null +++ b/app/Controllers/Specimen/SpecimenCollection.php @@ -0,0 +1,62 @@ +db = \Config\Database::connect(); + $this->model = new SpecimenCollectionModel(); + $this->rules = []; + } + + public function index() { + try { + $rows = $this->model->findAll(); + return $this->respond([ 'status' => 'success', 'message'=> "data fetched successfully", 'data' => $rows ], 200); + } catch (\Exception $e) { + return $this->failServerError('Exception : '.$e->getMessage()); + } + } + + public function show($id) { + try { + $rows = $this->model->where('SpcColID', $id)->findAll(); + return $this->respond([ 'status' => 'success', 'message'=> "data fetched successfully", 'data' => $rows ], 200); + } catch (\Exception $e) { + return $this->failServerError('Exception : '.$e->getMessage()); + } + } + + public function create() { + $input = $this->request->getJSON(true); + if (!$this->validateData($input, $this->rules)) { return $this->failValidationErrors($this->validator->getErrors()); } + try { + $id = $this->model->insert($input); + return $this->respondCreated([ 'status' => 'success', 'message' => "data $id created successfully" ]); + } catch (\Exception $e) { + return $this->failServerError('Something went wrong: ' . $e->getMessage()); + } + } + + public function update() { + $input = $this->request->getJSON(true); + if (!$this->validateData($input, $this->rules)) { return $this->failValidationErrors($this->validator->getErrors()); } + try { + $id = $this->model->update($input['SpcColID'], $input); + return $this->respondCreated([ 'status' => 'success', 'message' => "data $id updated successfully" ]); + } catch (\Exception $e) { + return $this->failServerError('Something went wrong: ' . $e->getMessage()); + } + } + +} \ No newline at end of file diff --git a/app/Controllers/Specimen/SpecimenPrep.php b/app/Controllers/Specimen/SpecimenPrep.php new file mode 100644 index 0000000..ac9608c --- /dev/null +++ b/app/Controllers/Specimen/SpecimenPrep.php @@ -0,0 +1,62 @@ +db = \Config\Database::connect(); + $this->model = new SpecimenPrepModel(); + $this->rules = []; + } + + public function index() { + try { + $rows = $this->model->findAll(); + return $this->respond([ 'status' => 'success', 'message'=> "data fetched successfully", 'data' => $rows ], 200); + } catch (\Exception $e) { + return $this->failServerError('Exception : '.$e->getMessage()); + } + } + + public function show($id) { + try { + $rows = $this->model->where('SpcPrpID', $id)->findAll(); + return $this->respond([ 'status' => 'success', 'message'=> "data fetched successfully", 'data' => $rows ], 200); + } catch (\Exception $e) { + return $this->failServerError('Exception : '.$e->getMessage()); + } + } + + public function create() { + $input = $this->request->getJSON(true); + if (!$this->validateData($input, $this->rules)) { return $this->failValidationErrors($this->validator->getErrors()); } + try { + $id = $this->model->insert($input); + return $this->respondCreated([ 'status' => 'success', 'message' => "data $id created successfully" ]); + } catch (\Exception $e) { + return $this->failServerError('Something went wrong: ' . $e->getMessage()); + } + } + + public function update() { + $input = $this->request->getJSON(true); + if (!$this->validateData($input, $this->rules)) { return $this->failValidationErrors($this->validator->getErrors()); } + try { + $id = $this->model->update($input['SpcPrpID'], $input); + return $this->respondCreated([ 'status' => 'success', 'message' => "data $id updated successfully" ]); + } catch (\Exception $e) { + return $this->failServerError('Something went wrong: ' . $e->getMessage()); + } + } + +} \ No newline at end of file diff --git a/app/Controllers/Specimen/SpecimenStatus.php b/app/Controllers/Specimen/SpecimenStatus.php new file mode 100644 index 0000000..f94f263 --- /dev/null +++ b/app/Controllers/Specimen/SpecimenStatus.php @@ -0,0 +1,62 @@ +db = \Config\Database::connect(); + $this->model = new SpecimenStatusModel(); + $this->rules = []; + } + + public function index() { + try { + $rows = $this->model->findAll(); + return $this->respond([ 'status' => 'success', 'message'=> "data fetched successfully", 'data' => $rows ], 200); + } catch (\Exception $e) { + return $this->failServerError('Exception : '.$e->getMessage()); + } + } + + public function show($id) { + try { + $rows = $this->model->where('SpcStaID', $id)->findAll(); + return $this->respond([ 'status' => 'success', 'message'=> "data fetched successfully", 'data' => $rows ], 200); + } catch (\Exception $e) { + return $this->failServerError('Exception : '.$e->getMessage()); + } + } + + public function create() { + $input = $this->request->getJSON(true); + if (!$this->validateData($input, $this->rules)) { return $this->failValidationErrors($this->validator->getErrors()); } + try { + $id = $this->model->insert($input); + return $this->respondCreated([ 'status' => 'success', 'message' => "data $id created successfully" ]); + } catch (\Exception $e) { + return $this->failServerError('Something went wrong: ' . $e->getMessage()); + } + } + + public function update() { + $input = $this->request->getJSON(true); + if (!$this->validateData($input, $this->rules)) { return $this->failValidationErrors($this->validator->getErrors()); } + try { + $id = $this->model->update($input['SpcStaID'], $input); + return $this->respondCreated([ 'status' => 'success', 'message' => "data $id updated successfully" ]); + } catch (\Exception $e) { + return $this->failServerError('Something went wrong: ' . $e->getMessage()); + } + } + +} \ No newline at end of file diff --git a/app/Controllers/Test/ValueSetDef.php b/app/Controllers/Test/TestDef.php similarity index 62% rename from app/Controllers/Test/ValueSetDef.php rename to app/Controllers/Test/TestDef.php index bea445c..477660f 100644 --- a/app/Controllers/Test/ValueSetDef.php +++ b/app/Controllers/Test/TestDef.php @@ -1,5 +1,5 @@ request->getVar('param'); - $rows = $this->model->getValueSetDefs($param); + $rows = $this->model->findAll(); if (empty($rows)) { return $this->respond([ 'status' => 'success', 'message' => "no Data.", 'data' => [] ], 200); } return $this->respond([ 'status' => 'success', 'message'=> "Data fetched successfully", 'data' => $rows ], 200); } - public function show($VSetID = null) { - $rows = $this->model->find($VSetID); + public function show($id = null) { + $rows = $this->model->where('TestID',$id)->findAll(); if (empty($rows)) { return $this->respond([ 'status' => 'success', 'message' => "no Data.", 'data' => [] ], 200); } return $this->respond([ 'status' => 'success', 'message'=> "Data fetched successfully", 'data' => $rows ], 200); } @@ -34,8 +33,8 @@ class TestDef extends BaseController { $input = $this->request->getJSON(true); if (!$this->validateData($input, $this->rules)) { return $this->failValidationErrors($this->validator->getErrors()); } try { - $VSetID = $this->model->insert($input); - return $this->respondCreated([ 'status' => 'success', 'message' => "data $VSetID created successfully" ]); + $id = $this->model->insert($input); + return $this->respondCreated([ 'status' => 'success', 'message' => "data $id created successfully" ]); } catch (\Exception $e) { return $this->failServerError('Something went wrong: ' . $e->getMessage()); } @@ -43,27 +42,15 @@ class TestDef extends BaseController { public function update() { $input = $this->request->getJSON(true); - $VSetID = $input["VID"]; - if (!$VSetID) { return $this->failValidationErrors('VSetID is required.'); } + $id = $input["TestID"]; + if (!$id) { return $this->failValidationErrors('TestID is required.'); } if (!$this->validateData($input, $this->rules)) { return $this->failValidationErrors( $this->validator->getErrors() ); } try { - $this->model->update($VSetID,$input); - return $this->respondCreated([ 'status' => 'success', 'message' => "data $VSetID updated successfully" ]); + $this->model->update($id,$input); + return $this->respondCreated([ 'status' => 'success', 'message' => "data $id updated successfully" ]); } catch (\Exception $e) { return $this->failServerError('Something went wrong: ' . $e->getMessage()); } } - public function delete() { - $input = $this->request->getJSON(true); - $VSetID = $input['VSetID']; - if (!$VSetID) { return $this->failValidationErrors('VSetID is required.'); } - try { - $this->model->delete($VSetID); - return $this->respondDeleted(['status' => 'success', 'message' => "Data $VSetID deleted successfully."]); - } catch (\Throwable $e) { - return $this->failServerError('Something went wrong: ' . $e->getMessage()); - } - } - } \ No newline at end of file diff --git a/app/Controllers/Test/TestDefCal.php b/app/Controllers/Test/TestDefCal.php new file mode 100644 index 0000000..ffa7451 --- /dev/null +++ b/app/Controllers/Test/TestDefCal.php @@ -0,0 +1,56 @@ +db = \Config\Database::connect(); + $this->model = new TestDefCalModel; + } + + public function index() { + $rows = $this->model->findAll(); + if (empty($rows)) { return $this->respond([ 'status' => 'success', 'message' => "no Data.", 'data' => [] ], 200); } + return $this->respond([ 'status' => 'success', 'message'=> "Data fetched successfully", 'data' => $rows ], 200); + } + + public function show($id = null) { + $rows = $this->model->where('TestCalID',$id)->findAll(); + if (empty($rows)) { return $this->respond([ 'status' => 'success', 'message' => "no Data.", 'data' => [] ], 200); } + return $this->respond([ 'status' => 'success', 'message'=> "Data fetched successfully", 'data' => $rows ], 200); + } + + public function create() { + $input = $this->request->getJSON(true); + if (!$this->validateData($input, $this->rules)) { return $this->failValidationErrors($this->validator->getErrors()); } + try { + $id = $this->model->insert($input); + return $this->respondCreated([ 'status' => 'success', 'message' => "data $id created successfully" ]); + } catch (\Exception $e) { + return $this->failServerError('Something went wrong: ' . $e->getMessage()); + } + } + + public function update() { + $input = $this->request->getJSON(true); + $id = $input["TestCalID"]; + if (!$id) { return $this->failValidationErrors('TestCalID is required.'); } + if (!$this->validateData($input, $this->rules)) { return $this->failValidationErrors( $this->validator->getErrors() ); } + try { + $this->model->update($id,$input); + return $this->respondCreated([ 'status' => 'success', 'message' => "data $id updated successfully" ]); + } catch (\Exception $e) { + return $this->failServerError('Something went wrong: ' . $e->getMessage()); + } + } + +} \ No newline at end of file diff --git a/app/Controllers/Test/TestDefSite.php b/app/Controllers/Test/TestDefSite.php new file mode 100644 index 0000000..7ed6a3a --- /dev/null +++ b/app/Controllers/Test/TestDefSite.php @@ -0,0 +1,56 @@ +db = \Config\Database::connect(); + $this->model = new TestDefSiteModel; + } + + public function index() { + $rows = $this->model->findAll(); + if (empty($rows)) { return $this->respond([ 'status' => 'success', 'message' => "no Data.", 'data' => [] ], 200); } + return $this->respond([ 'status' => 'success', 'message'=> "Data fetched successfully", 'data' => $rows ], 200); + } + + public function show($id = null) { + $rows = $this->model->where('TestSiteID',$id)->findAll(); + if (empty($rows)) { return $this->respond([ 'status' => 'success', 'message' => "no Data.", 'data' => [] ], 200); } + return $this->respond([ 'status' => 'success', 'message'=> "Data fetched successfully", 'data' => $rows ], 200); + } + + public function create() { + $input = $this->request->getJSON(true); + if (!$this->validateData($input, $this->rules)) { return $this->failValidationErrors($this->validator->getErrors()); } + try { + $id = $this->model->insert($input); + return $this->respondCreated([ 'status' => 'success', 'message' => "data $id created successfully" ]); + } catch (\Exception $e) { + return $this->failServerError('Something went wrong: ' . $e->getMessage()); + } + } + + public function update() { + $input = $this->request->getJSON(true); + $id = $input["TestSiteID"]; + if (!$id) { return $this->failValidationErrors('TestSiteID is required.'); } + if (!$this->validateData($input, $this->rules)) { return $this->failValidationErrors( $this->validator->getErrors() ); } + try { + $this->model->update($id,$input); + return $this->respondCreated([ 'status' => 'success', 'message' => "data $id updated successfully" ]); + } catch (\Exception $e) { + return $this->failServerError('Something went wrong: ' . $e->getMessage()); + } + } + +} \ No newline at end of file diff --git a/app/Controllers/Test/TestDefTech.php b/app/Controllers/Test/TestDefTech.php new file mode 100644 index 0000000..d7e0cc4 --- /dev/null +++ b/app/Controllers/Test/TestDefTech.php @@ -0,0 +1,56 @@ +db = \Config\Database::connect(); + $this->model = new TestDefTechModel; + } + + public function index() { + $rows = $this->model->findAll(); + if (empty($rows)) { return $this->respond([ 'status' => 'success', 'message' => "no Data.", 'data' => [] ], 200); } + return $this->respond([ 'status' => 'success', 'message'=> "Data fetched successfully", 'data' => $rows ], 200); + } + + public function show($id = null) { + $rows = $this->model->where('TestTechID',$id)->findAll(); + if (empty($rows)) { return $this->respond([ 'status' => 'success', 'message' => "no Data.", 'data' => [] ], 200); } + return $this->respond([ 'status' => 'success', 'message'=> "Data fetched successfully", 'data' => $rows ], 200); + } + + public function create() { + $input = $this->request->getJSON(true); + if (!$this->validateData($input, $this->rules)) { return $this->failValidationErrors($this->validator->getErrors()); } + try { + $id = $this->model->insert($input); + return $this->respondCreated([ 'status' => 'success', 'message' => "data $id created successfully" ]); + } catch (\Exception $e) { + return $this->failServerError('Something went wrong: ' . $e->getMessage()); + } + } + + public function update() { + $input = $this->request->getJSON(true); + $id = $input["TestTechID"]; + if (!$id) { return $this->failValidationErrors('TestTechID is required.'); } + if (!$this->validateData($input, $this->rules)) { return $this->failValidationErrors( $this->validator->getErrors() ); } + try { + $this->model->update($id,$input); + return $this->respondCreated([ 'status' => 'success', 'message' => "data $id updated successfully" ]); + } catch (\Exception $e) { + return $this->failServerError('Something went wrong: ' . $e->getMessage()); + } + } + +} \ No newline at end of file diff --git a/app/Controllers/Test/TestGrp.php b/app/Controllers/Test/TestGrp.php new file mode 100644 index 0000000..dea1606 --- /dev/null +++ b/app/Controllers/Test/TestGrp.php @@ -0,0 +1,56 @@ +db = \Config\Database::connect(); + $this->model = new TestGrpModel; + } + + public function index() { + $rows = $this->model->findAll(); + if (empty($rows)) { return $this->respond([ 'status' => 'success', 'message' => "no Data.", 'data' => [] ], 200); } + return $this->respond([ 'status' => 'success', 'message'=> "Data fetched successfully", 'data' => $rows ], 200); + } + + public function show($id = null) { + $rows = $this->model->where('TestGrpID',$id)->findAll(); + if (empty($rows)) { return $this->respond([ 'status' => 'success', 'message' => "no Data.", 'data' => [] ], 200); } + return $this->respond([ 'status' => 'success', 'message'=> "Data fetched successfully", 'data' => $rows ], 200); + } + + public function create() { + $input = $this->request->getJSON(true); + if (!$this->validateData($input, $this->rules)) { return $this->failValidationErrors($this->validator->getErrors()); } + try { + $id = $this->model->insert($input); + return $this->respondCreated([ 'status' => 'success', 'message' => "data $id created successfully" ]); + } catch (\Exception $e) { + return $this->failServerError('Something went wrong: ' . $e->getMessage()); + } + } + + public function update() { + $input = $this->request->getJSON(true); + $id = $input["TestGrpID"]; + if (!$id) { return $this->failValidationErrors('TestGrpID is required.'); } + if (!$this->validateData($input, $this->rules)) { return $this->failValidationErrors( $this->validator->getErrors() ); } + try { + $this->model->update($id,$input); + return $this->respondCreated([ 'status' => 'success', 'message' => "data $id updated successfully" ]); + } catch (\Exception $e) { + return $this->failServerError('Something went wrong: ' . $e->getMessage()); + } + } + +} \ No newline at end of file diff --git a/app/Controllers/Test/TestMap.php b/app/Controllers/Test/TestMap.php new file mode 100644 index 0000000..bfe90ff --- /dev/null +++ b/app/Controllers/Test/TestMap.php @@ -0,0 +1,56 @@ +db = \Config\Database::connect(); + $this->model = new TestMapModel; + } + + public function index() { + $rows = $this->model->findAll(); + if (empty($rows)) { return $this->respond([ 'status' => 'success', 'message' => "no Data.", 'data' => [] ], 200); } + return $this->respond([ 'status' => 'success', 'message'=> "Data fetched successfully", 'data' => $rows ], 200); + } + + public function show($id = null) { + $rows = $this->model->where('TestMapID',$id)->findAll(); + if (empty($rows)) { return $this->respond([ 'status' => 'success', 'message' => "no Data.", 'data' => [] ], 200); } + return $this->respond([ 'status' => 'success', 'message'=> "Data fetched successfully", 'data' => $rows ], 200); + } + + public function create() { + $input = $this->request->getJSON(true); + if (!$this->validateData($input, $this->rules)) { return $this->failValidationErrors($this->validator->getErrors()); } + try { + $id = $this->model->insert($input); + return $this->respondCreated([ 'status' => 'success', 'message' => "data $id created successfully" ]); + } catch (\Exception $e) { + return $this->failServerError('Something went wrong: ' . $e->getMessage()); + } + } + + public function update() { + $input = $this->request->getJSON(true); + $id = $input["TestMapID"]; + if (!$id) { return $this->failValidationErrors('TestMapID is required.'); } + if (!$this->validateData($input, $this->rules)) { return $this->failValidationErrors( $this->validator->getErrors() ); } + try { + $this->model->update($id,$input); + return $this->respondCreated([ 'status' => 'success', 'message' => "data $id updated successfully" ]); + } catch (\Exception $e) { + return $this->failServerError('Something went wrong: ' . $e->getMessage()); + } + } + +} \ No newline at end of file diff --git a/app/Database/Migrations/2025-10-07-132705_Specimen.php b/app/Database/Migrations/2025-10-07-132705_Specimen.php index 8035d97..20fe325 100644 --- a/app/Database/Migrations/2025-10-07-132705_Specimen.php +++ b/app/Database/Migrations/2025-10-07-132705_Specimen.php @@ -29,7 +29,7 @@ class CreateSpecimenTable extends Migration { 'SiteID' => ['type' => 'INT', 'null' => true], 'OrderID' => ['type' => 'INT', 'null' => true], 'ConDefID' => ['type' => 'INT', 'null' => true], - 'Parent' => ['type' => 'int', 'null' => true], + 'Parent' => ['type' => 'varchar', 'constraint' => 30, 'null' => true], 'Qty' => ['type' => 'INT', 'null' => true], 'Unit' => ['type' => 'varchar', 'constraint'=> 30, 'null' => true], 'GenerateBy' => ['type' => 'int', 'null' => true], @@ -40,11 +40,12 @@ class CreateSpecimenTable extends Migration { ]); $this->forge->addKey('InternalSID', true); $this->forge->addUniqueKey('SID'); - $this->forge->createTable('specimens'); + $this->forge->createTable('specimen'); $this->forge->addField([ 'SpcStaID' => ['type' => 'INT', 'auto_increment' => true, 'unsigned' => true], 'SID' => ['type' => 'VARCHAR', 'constraint' => 30, 'null' => false], + 'OrderID' => ['type' => 'int', 'null' => false], 'SpcAct' => ['type' => 'varchar', 'constraint' => 15, 'null' => true], 'ActRes' => ['type' => 'INT', 'null' => true], 'SpcStatus' => ['type' => 'int', 'null' => true], @@ -59,6 +60,7 @@ class CreateSpecimenTable extends Migration { 'GeoLocationData' => ['type' => 'varchar', 'constraint'=>10, 'null' => true ], 'DIDType' => ['type' => 'varchar', 'constraint'=>10, 'null' => true ], 'DID' => ['type' => 'varchar', 'constraint'=>10, 'null' => true ], + 'UserID' => ['type' => 'int', 'null' => true ], 'CreateDate' => ['type' => 'Datetime', 'null' => true], 'EndDate' => ['type' => 'DATETIME', 'null' => true], 'ArchiveDate' => ['type' => 'DATETIME', 'null' => true] @@ -69,9 +71,9 @@ class CreateSpecimenTable extends Migration { $this->forge->addField([ 'SpcColID' => ['type' => 'INT', 'auto_increment' => true, 'unsigned' => true], 'SpcStaID' => ['type' => 'INT', 'unsigned' => true], - 'SpcRole' => ['type' => 'varchar', 'constraint' => 15, 'null' => true], - 'ColMethod' => ['type' => 'varchar', 'constraint' => 15, 'null' => true], - 'BodySite' => ['type' => 'varchar', 'constraint' => 15, 'null' => true], + 'SpcRole' => ['type' => 'int', 'null' => true], + 'ColMethod' => ['type' => 'int', 'null' => true], + 'BodySite' => ['type' => 'int', 'null' => true], 'CntSize' => ['type' => 'INT', 'null' => true], 'FastingVolume' => ['type' => 'varchar', 'constraint'=> 2, 'null' => true], 'ColStart' => ['type' => 'datetime', 'null' => true], @@ -87,10 +89,10 @@ class CreateSpecimenTable extends Migration { 'SpcPrpID' => ['type' => 'INT', 'auto_increment' => true, 'unsigned' => true], 'SpcStaID' => ['type' => 'INT', 'unsigned' => true], 'Description' => ['type' => 'varchar', 'constraint' => 150, 'null' => true], - 'Method' => ['type' => 'varchar', 'constraint' => 15, 'null' => true], - 'Additive' => ['type' => 'varchar', 'constraint' => 15, 'null' => true], + 'Method' => ['type' => 'int', 'null' => true], + 'Additive' => ['type' => 'int', 'null' => true], 'AddQty' => ['type' => 'float', 'null' => true], - 'AddUnit' => ['type' => 'varchar', 'constraint'=> 15, 'null' => true], + 'AddUnit' => ['type' => 'int', 'null' => true], 'PrepStart' => ['type' => 'datetime', 'null' => true], 'PrepEnd' => ['type' => 'datetime', 'null' => true], 'CreateDate' => ['type' => 'Datetime', 'null' => true], diff --git a/app/Database/Migrations/2025-10-11-100001_Test.php b/app/Database/Migrations/2025-10-11-100001_Test.php index eab0ac1..884d8f2 100644 --- a/app/Database/Migrations/2025-10-11-100001_Test.php +++ b/app/Database/Migrations/2025-10-11-100001_Test.php @@ -8,7 +8,7 @@ class CreateTestsTable extends Migration { public function up() { $this->forge->addField([ 'TestID' => ['type' => 'INT', 'auto_increment' => true, 'unsigned' => true], - 'ParentTest' => ['type' => 'INT', 'null' => true], + 'Parent' => ['type' => 'INT', 'null' => true], 'TestCode' => ['type' => 'VARCHAR', 'constraint'=> 6, 'null' => false], 'TestName' => ['type' => 'varchar', 'constraint'=> 50, 'null' => false], 'Description' => ['type' => 'VARCHAR', 'constraint'=> 150, 'null' => false], @@ -27,7 +27,7 @@ class CreateTestsTable extends Migration { 'SiteID' => ['type' => 'INT', 'null' => false], 'TestSiteCode' => ['type' => 'varchar', 'constraint'=> 6, 'null' => false], 'TestSiteName' => ['type' => 'varchar', 'constraint'=> 50, 'null' => false], - 'Type' => ['type' => 'int', 'null' => false], + 'Type' => ['type' => 'int', 'null' => false], 'Description' => ['type' => 'varchar', 'constraint'=> 150, 'null' => true], 'SeqScr' => ['type' => 'int', 'null' => false], 'SeqRpt' => ['type' => 'int', 'null' => false], @@ -57,11 +57,7 @@ class CreateTestsTable extends Migration { 'Factor' => ['type' => 'int', 'null' => true], 'Unit2' => ['type' => 'varchar', 'constraint'=>20, 'null' => true], 'Decimal' => ['type' => 'int', 'null' => true], - 'Collreq' => ['type' => 'varchar', 'constraint'=>50, 'null' => true], - 'ConDefID' => ['type' => 'int', 'null' => true], - 'TestTechCode' => ['type' => 'varchar', 'constraint'=>6, 'null' => true], - 'TestTechAbb' => ['type' => 'varchar', 'constraint'=>50, 'null' => true], - 'TestTechName' => ['type' => 'varchar', 'constraint'=>150, 'null' => true], + 'CollReq' => ['type' => 'varchar', 'constraint'=>50, 'null' => true], 'Method' => ['type' => 'varchar', 'constraint'=>50, 'null' => true], 'ExpectedTAT' => ['type' => 'INT', 'null' => true], 'CreateDate' => ['type' => 'Datetime', 'null' => true], @@ -74,8 +70,9 @@ class CreateTestsTable extends Migration { 'TestCalID' => ['type' => 'INT', 'auto_increment' => true, 'unsigned' => true], 'SiteID' => ['type' => 'INT', 'null' => true], 'TestSiteID' => ['type' => 'INT', 'null' => true], + 'DisciplineID' => ['type' => 'INT', 'null' => true], + 'DepartmentID' => ['type' => 'INT', 'null' => true], 'FormulaCode' => ['type' => 'varchar', 'constraint'=>150, 'null' => true], - 'FormulaLang' => ['type' => 'varchar', 'constraint'=>20, 'null' => true], 'FormulaInput' => ['type' => 'varchar', 'constraint'=>20, 'null' => true], 'Unit1' => ['type' => 'varchar', 'constraint'=>20, 'null' => true], 'Factor' => ['type' => 'int', 'null' => true], @@ -98,6 +95,22 @@ class CreateTestsTable extends Migration { $this->forge->addKey('TestGrpID', true); $this->forge->createTable('testgrp'); + $this->forge->addField([ + 'TestMapID' => ['type' => 'INT', 'auto_increment' => true, 'unsigned' => true], + 'HostType' => ['type' => 'int', 'null' => true], + 'HostID' => ['type' => 'int', 'null' => true], + 'HostDataSource' => ['type' => 'varchar', 'constraint'=>50, 'null' => true], + 'HostTestCode' => ['type' => 'varchar', 'constraint'=>10, 'null' => true], + 'HostTestName' => ['type' => 'varchar', 'constraint'=>50, 'null' => true], + 'ClientType' => ['type' => 'int', 'null' => true], + 'ClientID' => ['type' => 'int', 'null' => true], + 'ClientTestCode' => ['type' => 'varchar', 'constraint'=>10, 'null' => true], + 'ClientTestName' => ['type' => 'varchar', 'constraint'=>50, 'null' => true], + 'CreateDate' => ['type' => 'Datetime', 'null' => true], + 'EndDate' => ['type' => 'Datetime', 'null' => true] + ]); + $this->forge->addKey('TestMapID', true); + $this->forge->createTable('testmap'); } public function down() { @@ -106,5 +119,6 @@ class CreateTestsTable extends Migration { $this->forge->dropTable('testdeftech'); $this->forge->dropTable('testdefcal'); $this->forge->dropTable('testgrp'); + $this->forge->dropTable('testmap'); } } \ No newline at end of file diff --git a/app/Models/Specimen/ContainerDefModel.php b/app/Models/Specimen/ContainerDefModel.php index df83524..bec4a8f 100644 --- a/app/Models/Specimen/ContainerDefModel.php +++ b/app/Models/Specimen/ContainerDefModel.php @@ -14,11 +14,6 @@ class ContainerDefModel extends BaseModel { protected $useSoftDeletes = true; protected $deletedField = 'EndDate'; - protected $beforeInsert = ['normalizeDatesToUTC']; - protected $beforeUpdate = ['normalizeDatesToUTC']; - protected $afterFind = ['convertDatesToUTCISO']; - protected $afterInsert = ['convertDatesToUTCISO']; - protected $afterUpdate = ['convertDatesToUTCISO']; public function getContainer($ConDefID) { $rows = $this->select('containerdef.*, vscol.VValue as ColorTxt, vscla.VValue as ConClassTxt, vsadd.VValue as AdditiveTxt') diff --git a/app/Models/Specimen/SpecimenCollectionModel.php b/app/Models/Specimen/SpecimenCollectionModel.php new file mode 100644 index 0000000..13a5a4f --- /dev/null +++ b/app/Models/Specimen/SpecimenCollectionModel.php @@ -0,0 +1,18 @@ +