clqms-be/app/Controllers/PatVisit.php

68 lines
2.1 KiB
PHP
Raw Normal View History

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-16 12:55:55 +07:00
class PatVisit 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
}
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-20 14:09:09 +07:00
if($row == []) {
$message = "data not found";
} else {
$message = "data found";
}
return $this->respond([ 'status' => 'success', 'message'=> $message, '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-20 14:09:09 +07:00
if($row == []) {
$message = "data not found";
} else {
$message = "data found";
}
return $this->respond(['status' => 'success', 'message'=> $message, '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-20 14:09:09 +07:00
try {
2025-10-20 15:12:52 +07:00
// if(empty($input)){throw new \Exception('Input data is empty or invalid');}
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-20 15:12:52 +07:00
// if(empty($input)){throw new \Exception('Input data is empty or invalid');}
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-09-19 16:43:03 +07:00
}