Menambahkan Endpoint patientIdCheck
This commit is contained in:
parent
fdb539ecbb
commit
e7f568f8fa
@ -19,6 +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/race', 'Race::index');
|
||||
$routes->get('/api/race/(:num)', 'Race::show/$1');
|
||||
|
||||
@ -488,6 +488,38 @@ class Patient extends Controller {
|
||||
}
|
||||
}
|
||||
|
||||
public function patientIdCheck($PatientID = null) {
|
||||
try {
|
||||
if (empty($PatientID)) {
|
||||
return $this->failValidationError('PatientID is required.');
|
||||
}
|
||||
|
||||
$patient = $this->db->table('patient')
|
||||
->where('PatientID', $PatientID)
|
||||
->get()
|
||||
->getRowArray();
|
||||
|
||||
if (!$patient) {
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message' => "PatientID {$PatientID} not found.",
|
||||
'data' => true,
|
||||
], 200);
|
||||
}
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message' => "PatientID {$PatientID} already exists.",
|
||||
'data' => false,
|
||||
], 200);
|
||||
|
||||
} catch (\Throwable $e) {
|
||||
log_message('error', $e->getMessage());
|
||||
return $this->failServerError('Something went wrong. Please try again later.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Ubah ke format Years Months Days
|
||||
private function calculateAgeFromBirthdate($birthdate) {
|
||||
$dob = new \DateTime($birthdate);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user