diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 5ad2cf6..1c36a5c 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -67,18 +67,18 @@ $routes->post('/api/occupation', 'Occupation::create'); $routes->patch('/api/occupation', 'Occupation::update'); //$routes->delete('/api/occupation', 'Occupation::delete'); -$routes->get('/api/valueset', 'ValueSet::index'); -$routes->get('/api/valueset/(:num)', 'ValueSet::show/$1'); -$routes->get('/api/valueset/valuesetdef/(:num)', 'ValueSet::showByValueSetDef/$1'); -$routes->post('/api/valueset', 'ValueSet::create'); -$routes->patch('/api/valueset', 'ValueSet::update'); -$routes->delete('/api/valueset', 'ValueSet::delete'); +$routes->get('/api/valueset', 'ValueSet\ValueSet::index'); +$routes->get('/api/valueset/(:num)', 'ValueSet\ValueSet::show/$1'); +$routes->get('/api/valueset/valuesetdef/(:num)', 'ValueSet\ValueSet::showByValueSetDef/$1'); +$routes->post('/api/valueset', 'ValueSet\ValueSet::create'); +$routes->patch('/api/valueset', 'ValueSet\ValueSet::update'); +$routes->delete('/api/valueset', 'ValueSet\ValueSet::delete'); -$routes->get('/api/valuesetdef/', 'ValueSetDef::index'); -$routes->get('/api/valuesetdef/(:num)', 'ValueSetDef::show/$1'); -$routes->post('/api/valuesetdef', 'ValueSetDef::create'); -$routes->patch('/api/valuesetdef', 'ValueSetDef::update'); -$routes->delete('/api/valuesetdef', 'ValueSetDef::delete'); +$routes->get('/api/valuesetdef/', 'ValueSet\ValueSetDef::index'); +$routes->get('/api/valuesetdef/(:num)', 'ValueSet\ValueSetDef::show/$1'); +$routes->post('/api/valuesetdef', 'ValueSet\ValueSetDef::create'); +$routes->patch('/api/valuesetdef', 'ValueSet\ValueSetDef::update'); +$routes->delete('/api/valuesetdef', 'ValueSet\ValueSetDef::delete'); $routes->get('/api/counter/', 'Counter::index'); $routes->get('/api/counter/(:num)', 'Counter::show/$1'); diff --git a/app/Controllers/ValueSet.php b/app/Controllers/ValueSet.php deleted file mode 100644 index 8f58e03..0000000 --- a/app/Controllers/ValueSet.php +++ /dev/null @@ -1,214 +0,0 @@ -db = \Config\Database::connect(); - $this->rulesValueSet = [ - 'VSetID' => 'required', - 'VValue' => 'required', - ]; - } - - public function index() { - $builder = $this->db->table('valueset')->select("*"); - $param = $this->request->getVar('param'); - if ($param !== null) { - $builder->like('VValue', $param, 'both'); - $builder->orlike('VDesc', $param, 'both'); - } - $rows = $builder->get()->getResultArray(); - - if (empty($rows)) { - return $this->respond([ - 'status' => 'success', - 'message' => "no Data.", - 'data' => [], - ], 200); - } - - return $this->respond([ - 'status' => 'success', - 'message'=> "Value Set fetched successfully", - 'data' => $rows, - ], 200); - } - - public function show($VID = null) { - $rows = $this->db->table('valueset') - ->select("valueset.*, valuesetdef.VSName") - ->join('valuesetdef', 'valuesetdef.VSetID = valueset.VSetID', 'LEFT') - ->where('valueset.VID', (int) $VID) - ->get()->getResultArray(); - - if (empty($rows)) { - return $this->respond([ - 'status' => 'success', - 'message' => "ValueSet with ID $VID not found.", - 'data' => [], - ], 200); - } - - return $this->respond([ - 'status' => 'success', - 'message'=> "Data fetched successfully", - 'data' => $rows, - ], 200); - } - - public function showByValueSetDef($VSetID = null) { - $rows = $this->db->table('valueset') - ->select("*") - ->where('VSetID', (int) $VSetID) - ->get()->getResultArray(); - - if (empty($rows)) { - return $this->respond([ - 'status' => 'success', - 'message' => "ValueSet not found.", - 'data' => [], - ], 200); - } - - return $this->respond([ - 'status' => 'success', - 'message'=> "Data fetched successfully", - 'data' => $rows, - ], 200); - } - - public function create() { - try { - $input = $this->request->getJSON(true); - - $dataValueSet = $this->prepareValueSetData($input); - - if (!$this->validateData($dataValueSet, $this->rulesValueSet)) { - return $this->failValidationErrors($this->validator->getErrors()); - } - - // Start transaction - $this->db->transStart(); - - // Insert - $this->db->table('valueset')->insert($dataValueSet); - - // Complete transaction - $this->db->transComplete(); - - if ($this->db->transStatus() === false) { - $dbError = $this->db->error(); - return $this->failServerError( - 'Failed to create data (transaction rolled back): ' . ($dbError['message'] ?? 'Unknown database error') - ); - } - - return $this->respondCreated([ - 'status' => 'success', - 'message' => 'Data created successfully', - 'data' => $dataValueSet, - ], 201); - - } catch (\Throwable $e) { - // Ensure rollback if something goes wrong - if ($this->db->transStatus() !== false) { - $this->db->transRollback(); - } - return $this->failServerError('Something went wrong: ' . $e->getMessage()); - } - } - - public function update() { - try { - $input = $this->request->getJSON(true); - $VID = $input["VID"]; - if (!$VID) { - return $this->failValidationErrors('VID is required.'); - } - - $dataValueSet = $this->prepareValueSetData($input); - - if (!$this->validateData($dataValueSet, $this->rulesValueSet)) { - return $this->failValidationErrors( $this->validator->getErrors() ); - } - - // Start transaction - $this->db->transStart(); - - // Insert location - $this->db->table('valueset')->where('VID', $VID)->update($dataValueSet); - - // Complete transaction - $this->db->transComplete(); - - if ($this->db->transStatus() === false) { - $dbError = $this->db->error(); - return $this->failServerError( - 'Failed to update data (transaction rolled back): ' . ($dbError['message'] ?? 'Unknown database error') - ); - } - - return $this->respondCreated([ - 'status' => 'success', - 'message' => 'Data updated successfully', - 'data' => $dataValueSet, - ], 201); - - } catch (\Throwable $e) { - // Ensure rollback if something goes wrong - if ($this->db->transStatus() !== false) { - $this->db->transRollback(); - } - return $this->failServerError('Something went wrong: ' . $e->getMessage()); - } - } - - public function delete() { - try { - $input = $this->request->getJSON(true); - $VID = $input["VID"]; - if (!$VID) { - return $this->failValidationErrors('VID is required.'); - } - - $valueset = $this->db->table('valuset')->where('VID', $VID)->get()->getRow(); - if (!$valueset) { - return $this->failNotFound("VID with {$VID} not found."); - } - - $this->db->table('valueset')->where('VID', $VID)->update(['EndDate' => $this->now ]); - - return $this->respondDeleted([ - 'status' => 'success', - 'message' => "Data with ID {$VID} deleted successfully." - ]); - - } catch (\Throwable $e) { - // Ensure rollback if something goes wrong - if ($this->db->transStatus() !== false) { - $this->db->transRollback(); - } - return $this->failServerError('Something went wrong: ' . $e->getMessage()); - } - } - - private function prepareValueSetData(array $input): array { - $data = [ - "VSetID" => $input['VSetID'] ?? null, - "VOrder" => $input['VOrder'] ?? null, - "VValue" => $input['VValue'] ?? null, - "VDesc" => $input['VDesc'] ?? null, - "VCategory" => $input['VCategory'] ?? null - ]; - - if(!empty($input["VID"])) { $data["VID"]=$input["VID"]; } - - return $data; - } -} \ No newline at end of file diff --git a/app/Controllers/ValueSet/ValueSet.php b/app/Controllers/ValueSet/ValueSet.php new file mode 100644 index 0000000..f412f0c --- /dev/null +++ b/app/Controllers/ValueSet/ValueSet.php @@ -0,0 +1,86 @@ +db = \Config\Database::connect(); + $this->model = new ValueSetModel; + $this->rules = [ + 'VSetID' => 'required', + 'VValue' => 'required', + ]; + } + + public function index() { + $param = $this->request->getVar('param'); + $rows = $this->model->getValueSets($param); + 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($VID = null) { + $rows = $this->model->getValueSet($VID); + if (empty($rows)) { + return $this->respond([ 'status' => 'success', 'message' => "ValueSet with ID $VID not found.", 'data' => [] ], 200); + } + return $this->respond([ 'status' => 'success', 'message'=> "Data fetched successfully", 'data' => $rows], 200); + } + + public function showByValueSetDef($VSetID = null) { + $rows = $this->db->table('valueset') + ->select("*") + ->where('VSetID', (int) $VSetID) + ->get()->getResultArray(); + if (empty($rows)) { + return $this->respond([ 'status' => 'success', 'message' => "ValueSet not found.", '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 { + $VID = $this->model->insert($input); + return $this->respondCreated([ 'status' => 'success', 'message' => "data $VID created successfully" ]); + } catch (\Exception $e) { + return $this->failServerError('Something went wrong: ' . $e->getMessage()); + } + } + + public function update() { + $input = $this->request->getJSON(true); + $VID = $input["VID"]; + if (!$VID) { return $this->failValidationErrors('VID is required.'); } + if (!$this->validateData($input, $this->rules)) { return $this->failValidationErrors( $this->validator->getErrors() ); } + try { + $this->model->update($VID,$input); + return $this->respondCreated([ 'status' => 'success', 'message' => "data $VID updated successfully" ]); + } catch (\Exception $e) { + return $this->failServerError('Something went wrong: ' . $e->getMessage()); + } + } + + public function delete() { + $input = $this->request->getJSON(true); + $VID = $input["VID"]; + if (!$VID) { return $this->failValidationErrors('VID is required.'); } + try { + $this->model->delete($VID); + return $this->respondDeleted(['status' => 'success', 'message' => "Data $VID deleted successfully."]); + } catch (\Throwable $e) { + return $this->failServerError('Something went wrong: ' . $e->getMessage()); + } + } + +} \ No newline at end of file diff --git a/app/Controllers/ValueSet/ValueSetDef.php b/app/Controllers/ValueSet/ValueSetDef.php new file mode 100644 index 0000000..110cb80 --- /dev/null +++ b/app/Controllers/ValueSet/ValueSetDef.php @@ -0,0 +1,73 @@ +db = \Config\Database::connect(); + $this->model = new ValueSetDefModel; + $this->rules = [ + 'VSName' => 'required', + 'VSDesc' => 'required' + ]; + } + + public function index() { + $param = $this->request->getVar('param'); + $rows = $this->model->getValueSetDefs($param); + 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); + 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 { + $VSetID = $this->model->insert($input); + return $this->respondCreated([ 'status' => 'success', 'message' => "data $VSetID created successfully" ]); + } catch (\Exception $e) { + return $this->failServerError('Something went wrong: ' . $e->getMessage()); + } + } + + public function update() { + $input = $this->request->getJSON(true); + $VSetID = $input["VID"]; + if (!$VSetID) { return $this->failValidationErrors('VSetID 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" ]); + } 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/ValueSetDef.php b/app/Controllers/ValueSetDef.php deleted file mode 100644 index 1bf8b93..0000000 --- a/app/Controllers/ValueSetDef.php +++ /dev/null @@ -1,178 +0,0 @@ -db = \Config\Database::connect(); - $this->rulesvaluesetdef = [ - 'VSName' => 'required', - 'VSDesc' => 'required' - ]; - } - - public function index() { - $builder = $this->db->table('valuesetdef')->select("*"); - $param = $this->request->getVar('param'); - if ($param !== null) { - $builder->like('VSName', $param, 'both'); - $builder->orlike('VSDesc', $param, 'both'); - } - $rows = $builder->get()->getResultArray(); - - 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->db->table('valuesetdef') - ->select("*") - ->where('VSetID', (int) $VSetID) - ->get()->getResultArray(); - - if (empty($rows)) { - return $this->respond([ - 'status' => 'success', - 'message' => "data with ID $VSetID not found.", - 'data' => [], - ], 200); - } - - return $this->respond([ - 'status' => 'success', - 'message'=> "Data fetched successfully", - 'data' => $rows, - ], 200); - } - - public function create() { - try { - $input = $this->request->getJSON(true); - $datavaluesetdef = $this->preparevaluesetdefData($input); - - if (!$this->validateData($datavaluesetdef, $this->rulesvaluesetdef)) { - return $this->failValidationErrors($this->validator->getErrors()); - } - - $this->db->transStart(); - $this->db->table('valuesetdef')->insert($datavaluesetdef); - $this->db->transComplete(); - - if ($this->db->transStatus() === false) { - $dbError = $this->db->error(); - return $this->failServerError( - 'Failed to create data (transaction rolled back): ' . ($dbError['message'] ?? 'Unknown database error') - ); - } - - return $this->respondCreated([ - 'status' => 'success', - 'message' => 'Data created successfully', - 'data' => $datavaluesetdef, - ], 201); - - } catch (\Throwable $e) { - // Ensure rollback if something goes wrong - if ($this->db->transStatus() !== false) { - $this->db->transRollback(); - } - return $this->failServerError('Something went wrong: ' . $e->getMessage()); - } - } - - public function update() { - try { - $input = $this->request->getJSON(true); - $VSetID = $input["VSetID"]; - if (!$VSetID) { - return $this->failValidationErrors('VSetID is required.'); - } - $datavaluesetdef = $this->preparevaluesetdefData($input); - - if (!$this->validateData($datavaluesetdef, $this->rulesvaluesetdef)) { - return $this->failValidationErrors( $this->validator->getErrors()); - } - - $this->db->transStart(); - $this->db->table('valuesetdef')->where('VSetID', $VSetID)->update($datavaluesetdef); - $this->db->transComplete(); - - if ($this->db->transStatus() === false) { - $dbError = $this->db->error(); - return $this->failServerError( - 'Failed to update data (transaction rolled back): ' . ($dbError['message'] ?? 'Unknown database error') - ); - } - - return $this->respondCreated([ - 'status' => 'success', - 'message' => 'Data updated successfully', - 'data' => $datavaluesetdef, - ], 201); - - } catch (\Throwable $e) { - // Ensure rollback if something goes wrong - if ($this->db->transStatus() !== false) { - $this->db->transRollback(); - } - return $this->failServerError('Something went wrong: ' . $e->getMessage()); - } - } - - public function delete() { - try { - $input = $this->request->getJSON(true); - $VSetID = $input["VSetID"]; - if (!$VSetID) { - return $this->failValidationErrors('VSetID is required.'); - } - - $valuesetdef = $this->db->table('valuesetdef')->where('VSetID', $VSetID)->get()->getRow(); - if (!$valuesetdef) { - return $this->failNotFound("Data with {$VSetID} not found."); - } - - $this->db->table('valuesetdef')->where('VSetID', $VSetID)->update(['EndDate' => $this->now]); - - return $this->respondDeleted([ - 'status' => 'success', - 'message' => "data with {$VSetID} deleted successfully." - ]); - - } catch (\Throwable $e) { - // Ensure rollback if something goes wrong - if ($this->db->transStatus() !== false) { - $this->db->transRollback(); - } - return $this->failServerError('Something went wrong: ' . $e->getMessage()); - } - } - - private function preparevaluesetdefData(array $input): array { - $data = [ - "VSName" => $input['VSName'] ?? null, - "VSDesc" => $input['VSDesc'] ?? null - ]; - - if(!empty($input["VSetID"])) { $data["VSetID"]=$input["VSetID"]; } - - return $data; - } - -} \ No newline at end of file diff --git a/app/Database/Seeds/SpecimenSeeder.php b/app/Database/Seeds/SpecimenSeeder.php index de71e8d..a3cbc6b 100644 --- a/app/Database/Seeds/SpecimenSeeder.php +++ b/app/Database/Seeds/SpecimenSeeder.php @@ -10,7 +10,7 @@ class SpecimenSeeder extends Seeder { // containerdef $data = [ ['ConCode' => '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' => '11','ConName' => 'Plain', 'ConDesc' =>'Evacuated blood collection tube, no additive/metal-free', 'Additive' => null, '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'], @@ -19,10 +19,10 @@ class SpecimenSeeder extends Seeder { ['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'] +['ConCode' => '200','ConName' => 'Aliquot', 'ConDesc' =>'General specimen container, no additive, non-sterile. Untuk aliquot', 'Additive' => null, 'ConClass' => '1'], +['ConCode' => '290','ConName' => 'Pot Urin', 'ConDesc' =>'Non-sterile urine specimen container IVD', 'Additive' => null, 'ConClass' => '1'], +['ConCode' => '295','ConName' => 'Urine Container', 'ConDesc' =>'Urine specimen container', 'Additive' => null, 'ConClass' => '1'], +['ConCode' => '900','ConName' => 'Packing Pengiriman', 'ConDesc' =>'Specimen Transport Packaging', 'Additive' => null, 'ConClass' => '2'] ]; $this->db->table('containerdef')->insertBatch($data); diff --git a/app/Models/ValueSet/ValueSetDefModel.php b/app/Models/ValueSet/ValueSetDefModel.php new file mode 100644 index 0000000..0c13ec1 --- /dev/null +++ b/app/Models/ValueSet/ValueSetDefModel.php @@ -0,0 +1,37 @@ +builder(); + $builder->like('VSName', $param, 'both'); + $builder->orlike('VSDesc', $param, 'both'); + $rows = $builder->get()->getResultArray(); + } else { + $rows = $this->findAll(); + } + return $rows; + } + + +} diff --git a/app/Models/ValueSet/ValueSetModel.php b/app/Models/ValueSet/ValueSetModel.php new file mode 100644 index 0000000..44adf44 --- /dev/null +++ b/app/Models/ValueSet/ValueSetModel.php @@ -0,0 +1,47 @@ +builder(); + $builder->groupStart() + ->like('VValue', $param, 'both') + ->orlike('VDesc', $param, 'both') + ->groupEnd(); + $rows = $builder->get()->getResultArray(); + + return $rows; + } else { + return $this->findAll(); + } + } + + public function getValueSet($VID) { + $rows = $this->select("valueset.*, valuesetdef.VSName") + ->join('valuesetdef', 'valuesetdef.VSetID = valueset.VSetID', 'LEFT') + ->find($VID); + + return $rows; + } + +}