From 677504e225c3902e075af0649d286d96417dbc4f Mon Sep 17 00:00:00 2001 From: mahdahar <89adham@gmail.com> Date: Tue, 14 Oct 2025 10:48:20 +0700 Subject: [PATCH] add specimen --- app/Config/Routes.php | 8 ++- app/Controllers/Specimen/ContainerDef.php | 65 +++++++++++++++++++++++ app/Database/Seeds/SpecimenSeeder.php | 32 +++++++++++ app/Models/PatientModel.php | 3 +- app/Models/Specimen/ContainerDefModel.php | 23 ++++++++ 5 files changed, 129 insertions(+), 2 deletions(-) create mode 100644 app/Controllers/Specimen/ContainerDef.php create mode 100644 app/Database/Seeds/SpecimenSeeder.php create mode 100644 app/Models/Specimen/ContainerDefModel.php diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 22a01b9..5ad2cf6 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -84,4 +84,10 @@ $routes->get('/api/counter/', 'Counter::index'); $routes->get('/api/counter/(:num)', 'Counter::show/$1'); $routes->post('/api/counter', 'Counter::create'); $routes->patch('/api/counter', 'Counter::update'); -$routes->delete('/api/counter', 'Counter::delete'); \ No newline at end of file +$routes->delete('/api/counter', 'Counter::delete'); + +$routes->get('/api/containerdef/', 'Specimen\ContainerDef::index'); +$routes->get('/api/containerdef/(:num)', 'Specimen\ContainerDef::show/$1'); +$routes->post('/api/containerdef', 'Specimen\ContainerDef::create'); +$routes->patch('/api/containerdef', 'Specimen\ContainerDef::update'); +$routes->delete('/api/containerdef', 'Specimen\ContainerDef::delete'); \ No newline at end of file diff --git a/app/Controllers/Specimen/ContainerDef.php b/app/Controllers/Specimen/ContainerDef.php new file mode 100644 index 0000000..81ade9e --- /dev/null +++ b/app/Controllers/Specimen/ContainerDef.php @@ -0,0 +1,65 @@ +db = \Config\Database::connect(); + $this->model = new ContainerDefModel(); + $this->rules = [ + 'ConCode' => 'required|max_length[50]', + 'ConName' => 'required|max_length[50]' + ]; + } + + 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($ConDefID) { + try { + $rows = $this->model->find($ConDefID); + 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 { + $ConDefID = $this->model->insert($input); + return $this->respondCreated([ 'status' => 'success', 'message' => "data $ConDefID 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 { + $ConDefID = $this->model->update($input['ConDefID'], $input); + return $this->respondCreated([ 'status' => 'success', 'message' => "data $ConDefID updated successfully" ]); + } catch (\Exception $e) { + return $this->failServerError('Something went wrong: ' . $e->getMessage()); + } + } + +} \ No newline at end of file diff --git a/app/Database/Seeds/SpecimenSeeder.php b/app/Database/Seeds/SpecimenSeeder.php new file mode 100644 index 0000000..de71e8d --- /dev/null +++ b/app/Database/Seeds/SpecimenSeeder.php @@ -0,0 +1,32 @@ + '1','ConName' => 'SST', 'ConDesc' =>'Evacuated blood collection tube, gel separator', 'Additive' => "Gel", 'ConClass' => '1'], +['ConCode' => '11','ConName' => 'Plain', 'ConDesc' =>'Evacuated blood collection tube, no additive/metal-free', 'Additive' => "None", 'ConClass' => '1'], +['ConCode' => '12','ConName' => '2Hr PP', 'ConDesc' =>'Evacuated blood collection tube, untuk Glukosa 2 Jam PP', 'Additive' => "Sodium Fluoride", 'ConClass' => '1'], +['ConCode' => '13','ConName' => 'Glukosa Sewaktu', 'ConDesc' =>'Evacuated blood collection tube, untuk Glukosa Sewaktu', 'Additive' => "Sodium Fluoride", 'ConClass' => '1'], +['ConCode' => '14','ConName' => 'GTT 30 menit', 'ConDesc' =>'Evacuated blood collection tube, untuk GTT 30 menit', 'Additive' => "Sodium Fluoride", 'ConClass' => '1'], +['ConCode' => '15','ConName' => 'GTT 60 menit', 'ConDesc' =>'Evacuated blood collection tube, untuk GTT 60 menit', 'Additive' => "Sodium Fluoride", 'ConClass' => '1'], +['ConCode' => '16','ConName' => 'GTT 120 menit', 'ConDesc' =>'Evacuated blood collection tube, untuk GTT 90 menit', 'Additive' => "Sodium Fluoride", 'ConClass' => '1'], +['ConCode' => '20','ConName' => 'RST', 'ConDesc' =>'Evacuated blood collection tube, thrombin/clot activator/gel separator', 'Additive' => "Clot activator", 'ConClass' => '1'], +['ConCode' => '101','ConName' => 'EDTA - Hematologi', 'ConDesc' =>'Evacuated blood collection tube, K2EDTA/aprotinin', 'Additive' => "K2EDTA", 'ConClass' => '1'], +['ConCode' => '150','ConName' => 'Citrate - Koagulasi', 'ConDesc' =>'Evacuated blood collection tube, untuk koagulasi', 'Additive' => "Sodium citrate (substance)", 'ConClass' => '1'], +['ConCode' => '200','ConName' => 'Aliquot', 'ConDesc' =>'General specimen container, no additive, non-sterile. Untuk aliquot', 'Additive' => "", 'ConClass' => '1'], +['ConCode' => '290','ConName' => 'Pot Urin', 'ConDesc' =>'Non-sterile urine specimen container IVD', 'Additive' => "", 'ConClass' => '1'], +['ConCode' => '295','ConName' => 'Urine Container', 'ConDesc' =>'Urine specimen container', 'Additive' => "", 'ConClass' => '1'], +['ConCode' => '900','ConName' => 'Packing Pengiriman', 'ConDesc' =>'Specimen Transport Packaging', 'Additive' => "", 'ConClass' => '2'] + ]; + $this->db->table('containerdef')->insertBatch($data); + + + } +} + diff --git a/app/Models/PatientModel.php b/app/Models/PatientModel.php index 6679310..04d952c 100644 --- a/app/Models/PatientModel.php +++ b/app/Models/PatientModel.php @@ -13,7 +13,8 @@ class PatientModel extends BaseUtcModel { protected $useTimestamps = true; protected $createdField = 'CreateDate'; protected $updatedField = ''; - + protected $useSoftDeletes = true; + protected $deletedField = 'DelDate'; public function getPatients($filters = []) { $qname = "LOWER(CONCAT_WS(' ', IFNULL(Prefix,''), IFNULL(NameFirst,''), IFNULL(NameMiddle,''), IFNULL(NameLast,''), IFNULL(NameMaiden,''), IFNULL(Suffix,'')))"; diff --git a/app/Models/Specimen/ContainerDefModel.php b/app/Models/Specimen/ContainerDefModel.php new file mode 100644 index 0000000..88cec28 --- /dev/null +++ b/app/Models/Specimen/ContainerDefModel.php @@ -0,0 +1,23 @@ +