2025-09-19 16:43:03 +07:00
|
|
|
<?php
|
|
|
|
|
namespace App\Controllers;
|
|
|
|
|
|
|
|
|
|
use CodeIgniter\API\ResponseTrait;
|
2025-10-16 12:55:55 +07:00
|
|
|
use App\Controllers\BaseController;
|
|
|
|
|
use App\Models\PatVisit\PatVisitModel;
|
2025-10-23 12:16:52 +07:00
|
|
|
use App\Models\PatVisit\PatVisitADTModel;
|
2025-09-23 15:57:19 +07:00
|
|
|
|
2026-01-05 16:55:34 +07:00
|
|
|
class PatVisitController extends BaseController {
|
2025-09-19 16:43:03 +07:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2026-02-12 07:24:17 +07:00
|
|
|
public function index() {
|
|
|
|
|
try {
|
|
|
|
|
$page = $this->request->getVar('page') ?? 1;
|
|
|
|
|
$perPage = $this->request->getVar('per_page') ?? 50;
|
|
|
|
|
$rows = $this->model->paginate($perPage, 'default', $page);
|
|
|
|
|
$total = $this->model->countAllResults(false);
|
|
|
|
|
if($rows == []) { $message = "data not found"; }
|
|
|
|
|
else { $message = "data found"; }
|
|
|
|
|
return $this->respond(['status' => 'success', 'message'=> $message, 'data' => $rows, 'total' => $total, 'page' => $page, 'per_page' => $perPage ], 200);
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
return $this->failServerError('Something went wrong '.$e->getMessage());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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-12-29 12:55:31 +07:00
|
|
|
if (empty($row)) {
|
|
|
|
|
return $this->respond([ 'status' => 'success', 'message'=> "data not found", 'data' => null ], 200);
|
|
|
|
|
}
|
|
|
|
|
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-21 09:55:28 +07:00
|
|
|
$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);
|
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-20 14:09:09 +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-13 13:59:52 +07:00
|
|
|
return $this->respond(['status' => 'success', 'message' => 'Data created 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-10-23 12:16:52 +07:00
|
|
|
public function createADT() {
|
|
|
|
|
$input = $this->request->getJSON(true);
|
|
|
|
|
if (!$input["InternalPVID"] || !is_numeric($input["InternalPVID"])) { return $this->respond(['status' => 'error', 'message' => 'Invalid or missing ID'], 400); }
|
|
|
|
|
$modelPVA = new PatVisitADTModel();
|
|
|
|
|
try {
|
|
|
|
|
$data = $modelPVA->insert($input, true);
|
|
|
|
|
return $this->respond(['status' => 'success', 'message' => 'Data created successfully', 'data' => $data], 201);
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function updateADT() {
|
|
|
|
|
$input = $this->request->getJSON(true);
|
|
|
|
|
if (!$input["PVADTID"] || !is_numeric($input["PVADTID"])) { return $this->respond(['status' => 'error', 'message' => 'Invalid or missing ID'], 400); }
|
|
|
|
|
$modelPVA = new PatVisitADTModel();
|
|
|
|
|
try {
|
|
|
|
|
$data = $modelPVA->update($input['PVADTID'], $input);
|
|
|
|
|
return $this->respond(['status' => 'success', 'message' => 'Data updated successfully', 'data' => $data], 201);
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-01-05 16:55:34 +07:00
|
|
|
}
|