diff --git a/app/Config/Routes.php b/app/Config/Routes.php index c95ac24..1f0fecf 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -19,7 +19,7 @@ $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->patch('/api/patient/patid-check/(:any)', 'Patient::patientIdCheck/$1'); +$routes->get('/api/patient/check', 'Patient::patientCheck'); $routes->get('/api/race', 'Race::index'); $routes->get('/api/race/(:num)', 'Race::show/$1'); diff --git a/app/Controllers/Patient.php b/app/Controllers/Patient.php index e11189e..0313bd5 100644 --- a/app/Controllers/Patient.php +++ b/app/Controllers/Patient.php @@ -488,34 +488,47 @@ class Patient extends Controller { } } - public function patientIdCheck($PatientID = null) { + // OK - Done + public function patientCheck() { + try { - if (empty($PatientID)) { - return $this->failValidationError('PatientID is required.'); + + $PatientID = $this->request->getVar('PatientID'); + $EmailAddress1 = $this->request->getVar('EmailAddress1'); + + if ($PatientID!=null){ + $tableName = 'PatientID'; + $searchName = $PatientID; + } + + if ($EmailAddress1!=null){ + $tableName = 'EmailAddress1'; + $searchName = $EmailAddress1; } $patient = $this->db->table('patient') - ->where('PatientID', $PatientID) + ->where($tableName, $searchName) ->get() ->getRowArray(); if (!$patient) { return $this->respond([ 'status' => 'success', - 'message' => "PatientID {$PatientID} not found.", + 'message' => "$tableName not found.", 'data' => true, ], 200); } return $this->respond([ 'status' => 'success', - 'message' => "PatientID {$PatientID} already exists.", + 'message' => "$tableName already exists.", 'data' => false, ], 200); - } catch (\Throwable $e) { - log_message('error', $e->getMessage()); - return $this->failServerError('Something went wrong. Please try again later.'); + + } catch (\Exception $e) { + // Error Server Mengembalikan 500 + return $this->failServerError('Something went wrong.'.$e->getMessage()); } }