From cbf4f7a486bba465cc010da9481280446bf53fea Mon Sep 17 00:00:00 2001 From: mahdahar <89adham@gmail.com> Date: Fri, 1 Aug 2025 11:37:03 +0700 Subject: [PATCH] fix race religion ethnic country --- app/Config/Routes.php | 15 ++++++++------- app/Controllers/Country.php | 22 ++++++++++++++++------ app/Controllers/Ethnic.php | 28 ++++++++++++++++++++++++++++ app/Controllers/Patient.php | 1 - app/Controllers/Race.php | 29 +++++++++++++++++++---------- app/Controllers/Religion.php | 19 ++++++++++++++----- public/.htaccess | 1 + 7 files changed, 86 insertions(+), 29 deletions(-) create mode 100644 app/Controllers/Ethnic.php diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 6039a11..b9e7374 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -14,11 +14,12 @@ $routes->post('/auth/login/', 'Auth::login'); $routes->post('/auth/change_pass/', 'Auth::change_pass'); $routes->post('/auth/register/', 'Auth::register'); -$routes->get('/patient', 'Patient::index'); -$routes->post('/patient', 'Patient::create'); -$routes->delete('/patient/(:any)', 'Patient::delete/$1'); -$routes->patch('/patient/(:num)', 'Patient::update/$1'); +$routes->get('/api/patient', 'Patient::index'); +$routes->post('/api/patient', 'Patient::create'); +$routes->delete('/api/patient/(:any)', 'Patient::delete/$1'); +$routes->patch('/api/patient/(:num)', 'Patient::update/$1'); -$routes->get('/patient/race', 'PatientRace::index'); -$routes->get('/patient/country', 'PatientCountry::index'); -$routes->get('/patient/religion', 'PatientReligion::index'); \ No newline at end of file +$routes->get('/api/race', 'Race::index'); +$routes->get('/api/country', 'Country::index'); +$routes->get('/api/religion', 'Religion::index'); +$routes->get('/api/ethnic', 'Ethnic::index'); \ No newline at end of file diff --git a/app/Controllers/Country.php b/app/Controllers/Country.php index 38268ac..690f8e4 100644 --- a/app/Controllers/Country.php +++ b/app/Controllers/Country.php @@ -3,16 +3,26 @@ namespace App\Controllers; use CodeIgniter\API\ResponseTrait; use CodeIgniter\Controller; -use CodeIgniter\Database\RawSql; class Country extends Controller { use ResponseTrait; - public function index() { + public function __construct() { + $this->db = \Config\Database::connect(); + } - return $this->respond([ - 'status' => 'success', - 'data' => $data, - ]); + public function index() { + try { + $sql = "select * from country"; + $data = $this->db->query($sql)->getResultArray(); + + return $this->respond([ + 'status' => 'success', + 'message'=> "Country fetched successfully", + 'data' => $data, + ], 200); + } catch (\Exception $e) { + return $this->failServerError('Something went wrong'); + } } } \ No newline at end of file diff --git a/app/Controllers/Ethnic.php b/app/Controllers/Ethnic.php new file mode 100644 index 0000000..a3e7a9d --- /dev/null +++ b/app/Controllers/Ethnic.php @@ -0,0 +1,28 @@ +db = \Config\Database::connect(); + } + + public function index() { + try { + $sql = "select * from ethnic"; + $data = $this->db->query($sql)->getResultArray(); + + return $this->respond([ + 'status' => 'success', + 'message'=> "Ethnic fetched successfully", + 'data' => $data, + ], 200); + } catch (\Exception $e) { + return $this->failServerError('Something went wrong'); + } + } +} \ No newline at end of file diff --git a/app/Controllers/Patient.php b/app/Controllers/Patient.php index 755b20d..c32f913 100644 --- a/app/Controllers/Patient.php +++ b/app/Controllers/Patient.php @@ -14,7 +14,6 @@ class Patient extends Controller { // OK public function index() { - try { $pat_num = $this->request->getVar('pat_num'); $pat_altnum = $this->request->getVar('pat_altnum'); diff --git a/app/Controllers/Race.php b/app/Controllers/Race.php index 121eb28..4de87be 100644 --- a/app/Controllers/Race.php +++ b/app/Controllers/Race.php @@ -3,17 +3,26 @@ namespace App\Controllers; use CodeIgniter\API\ResponseTrait; use CodeIgniter\Controller; -use CodeIgniter\Database\RawSql; -class PatientRace extends Controller { - use ResponseTrait; +class Race extends Controller { + use ResponseTrait; - public function index() { - - - return $this->respond([ - 'status' => 'success', - 'data' => $data, - ]); + public function __construct() { + $this->db = \Config\Database::connect(); + } + + public function index() { + try { + $sql = "select * from race"; + $data = $this->db->query($sql)->getResultArray(); + + return $this->respond([ + 'status' => 'success', + 'message'=> "Race fetched successfully", + 'data' => $data, + ], 200); + } catch (\Exception $e) { + return $this->failServerError('Something went wrong'); } + } } \ No newline at end of file diff --git a/app/Controllers/Religion.php b/app/Controllers/Religion.php index faa5c15..29fbd89 100644 --- a/app/Controllers/Religion.php +++ b/app/Controllers/Religion.php @@ -3,17 +3,26 @@ namespace App\Controllers; use CodeIgniter\API\ResponseTrait; use CodeIgniter\Controller; -use CodeIgniter\Database\RawSql; -class PatientReligion extends Controller { +class Religion extends Controller { use ResponseTrait; + public function __construct() { + $this->db = \Config\Database::connect(); + } + public function index() { - - + try { + $sql = "select * from religion"; + $data = $this->db->query($sql)->getResultArray(); + return $this->respond([ 'status' => 'success', + 'message'=> "Religion fetched successfully", 'data' => $data, - ]); + ], 200); + } catch (\Exception $e) { + return $this->failServerError('Something went wrong'); + } } } \ No newline at end of file diff --git a/public/.htaccess b/public/.htaccess index abac3cb..d589002 100644 --- a/public/.htaccess +++ b/public/.htaccess @@ -15,6 +15,7 @@ Options -Indexes # change the following line to match the subfolder you need. # http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewritebase # RewriteBase / + RewriteBase /clqms01/ # Redirect Trailing Slashes... RewriteCond %{REQUEST_FILENAME} !-d