2025-09-19 16:43:03 +07:00
|
|
|
<?php
|
|
|
|
|
namespace App\Controllers;
|
|
|
|
|
|
|
|
|
|
use CodeIgniter\API\ResponseTrait;
|
|
|
|
|
use CodeIgniter\Controller;
|
2025-09-26 13:08:30 +07:00
|
|
|
use App\Models\PatVisitModel;
|
2025-09-23 15:57:19 +07:00
|
|
|
|
2025-09-19 16:43:03 +07:00
|
|
|
class PatVisit extends Controller {
|
|
|
|
|
use ResponseTrait;
|
2025-10-03 10:28:59 +07:00
|
|
|
|
2025-10-13 12:28:09 +07:00
|
|
|
protected $model;
|
2025-09-19 16:43:03 +07:00
|
|
|
|
2025-10-03 10:28:59 +07:00
|
|
|
public function __construct() {
|
2025-10-13 12:28:09 +07:00
|
|
|
$this->model = new PatVisitModel();
|
2025-09-19 16:43:03 +07:00
|
|
|
}
|
|
|
|
|
|
2025-09-22 13:25:31 +07:00
|
|
|
public function show($PVID = null) {
|
|
|
|
|
try {
|
2025-10-13 12:28:09 +07:00
|
|
|
$row = $this->model->show($PVID);
|
2025-10-03 10:28:59 +07:00
|
|
|
return $this->respond([ 'status' => 'success', 'message'=> "data found", 'data' => $row ], 200);
|
2025-09-22 13:25:31 +07:00
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
return $this->failServerError('Something went wrong '.$e->getMessage());
|
|
|
|
|
}
|
2025-09-19 16:43:03 +07:00
|
|
|
}
|
|
|
|
|
|
2025-09-22 13:25:31 +07:00
|
|
|
public function showByPatient($InternalPID = null) {
|
2025-09-19 16:43:03 +07:00
|
|
|
try {
|
2025-10-13 12:28:09 +07:00
|
|
|
$row = $this->model->showByPatient($InternalPID);
|
2025-10-03 10:28:59 +07:00
|
|
|
return $this->respond(['status' => 'success', 'message'=> "data found", 'data' => $row ], 200);
|
2025-09-19 16:43:03 +07:00
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
return $this->failServerError('Something went wrong '.$e->getMessage());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function update() {
|
2025-09-26 15:03:11 +07:00
|
|
|
$input = $this->request->getJSON(true);
|
2025-10-03 10:28:59 +07:00
|
|
|
try {
|
2025-09-19 16:43:03 +07:00
|
|
|
if (!$input["InternalPVID"] || !is_numeric($input["InternalPVID"])) { return $this->respond(['status' => 'error', 'message' => 'Invalid or missing ID'], 400); }
|
2025-10-13 12:28:09 +07:00
|
|
|
$data = $this->model->updatePatVisit($input);
|
2025-10-03 10:28:59 +07:00
|
|
|
return $this->respond(['status' => 'success', 'message' => 'Data updated successfully', 'data' => $data], 201);
|
2025-09-19 16:43:03 +07:00
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function create() {
|
2025-10-03 10:28:59 +07:00
|
|
|
$input = $this->request->getJSON(true);
|
2025-09-19 16:43:03 +07:00
|
|
|
try {
|
2025-10-13 12:28:09 +07:00
|
|
|
$data = $this->model->createPatVisit($input);
|
2025-10-03 10:28:59 +07:00
|
|
|
return $this->respond(['status' => 'success', 'message' => 'Data updated successfully', 'data' => $data], 201);
|
2025-09-19 16:43:03 +07:00
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-09-22 13:25:31 +07:00
|
|
|
|
2025-09-19 16:43:03 +07:00
|
|
|
}
|