clqms-be/app/Controllers/PatVisit.php

56 lines
1.8 KiB
PHP
Raw Normal View History

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-19 16:43:03 +07:00
class PatVisit extends Controller {
use ResponseTrait;
2025-10-03 10:28:59 +07:00
protected $modelPatVisit;
2025-09-19 16:43:03 +07:00
2025-10-03 10:28:59 +07:00
public function __construct() {
$this->modelPatVisit = 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-03 10:28:59 +07:00
$row = $this->modelPatVisit->show($PVID);
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-03 10:28:59 +07:00
$row = $this->modelPatVisit->showByPatient($InternalPID);
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-03 10:28:59 +07:00
$data = $this->modelPatVisit->updatePatVisit($input);
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-03 10:28:59 +07:00
$data = $this->modelPatVisit->createPatVisit($input);
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
}