clqms-be/app/Controllers/PatVisit.php
2025-10-13 12:28:09 +07:00

56 lines
1.7 KiB
PHP

<?php
namespace App\Controllers;
use CodeIgniter\API\ResponseTrait;
use CodeIgniter\Controller;
use App\Models\PatVisitModel;
class PatVisit extends Controller {
use ResponseTrait;
protected $model;
public function __construct() {
$this->model = new PatVisitModel();
}
public function show($PVID = null) {
try {
$row = $this->model->show($PVID);
return $this->respond([ 'status' => 'success', 'message'=> "data found", 'data' => $row ], 200);
} catch (\Exception $e) {
return $this->failServerError('Something went wrong '.$e->getMessage());
}
}
public function showByPatient($InternalPID = null) {
try {
$row = $this->model->showByPatient($InternalPID);
return $this->respond(['status' => 'success', 'message'=> "data found", 'data' => $row ], 200);
} catch (\Exception $e) {
return $this->failServerError('Something went wrong '.$e->getMessage());
}
}
public function update() {
$input = $this->request->getJSON(true);
try {
if (!$input["InternalPVID"] || !is_numeric($input["InternalPVID"])) { return $this->respond(['status' => 'error', 'message' => 'Invalid or missing ID'], 400); }
$data = $this->model->updatePatVisit($input);
return $this->respond(['status' => 'success', 'message' => 'Data updated successfully', 'data' => $data], 201);
} catch (\Exception $e) {
return $this->failServerError('Something went wrong: ' . $e->getMessage());
}
}
public function create() {
$input = $this->request->getJSON(true);
try {
$data = $this->model->createPatVisit($input);
return $this->respond(['status' => 'success', 'message' => 'Data updated successfully', 'data' => $data], 201);
} catch (\Exception $e) {
return $this->failServerError('Something went wrong: ' . $e->getMessage());
}
}
}