65 lines
2.1 KiB
PHP
65 lines
2.1 KiB
PHP
<?php
|
|
namespace App\Controllers;
|
|
|
|
use CodeIgniter\API\ResponseTrait;
|
|
use App\Controllers\BaseController;
|
|
use App\Models\PatVisit\PatVisitModel;
|
|
|
|
class PatVisit extends BaseController {
|
|
use ResponseTrait;
|
|
|
|
protected $model;
|
|
|
|
public function __construct() {
|
|
$this->model = new PatVisitModel();
|
|
}
|
|
|
|
public function show($PVID = null) {
|
|
try {
|
|
$row = $this->model->show($PVID);
|
|
if($row == []) {
|
|
$message = "data not found";
|
|
} else {
|
|
$message = "data found";
|
|
}
|
|
return $this->respond([ 'status' => 'success', 'message'=> $message, 'data' => $row ], 200);
|
|
} catch (\Exception $e) {
|
|
return $this->failServerError('Something went wrong '.$e->getMessage());
|
|
}
|
|
}
|
|
|
|
public function showByPatient($InternalPID = null) {
|
|
try {
|
|
$rows = $this->model->showByPatient($InternalPID);
|
|
if($rows == []) { $message = "data not found"; }
|
|
else { $message = "data found"; }
|
|
return $this->respond(['status' => 'success', 'message'=> $message, 'data' => $rows ], 200);
|
|
} catch (\Exception $e) {
|
|
return $this->failServerError('Something went wrong '.$e->getMessage());
|
|
}
|
|
}
|
|
|
|
public function update() {
|
|
$input = $this->request->getJSON(true);
|
|
try {
|
|
// if(empty($input)){throw new \Exception('Input data is empty or invalid');}
|
|
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 {
|
|
// if(empty($input)){throw new \Exception('Input data is empty or invalid');}
|
|
$data = $this->model->createPatVisit($input);
|
|
return $this->respond(['status' => 'success', 'message' => 'Data created successfully', 'data' => $data], 201);
|
|
} catch (\Exception $e) {
|
|
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
|
}
|
|
}
|
|
|
|
} |