56 lines
1.8 KiB
PHP
56 lines
1.8 KiB
PHP
<?php
|
|
namespace App\Controllers;
|
|
|
|
use CodeIgniter\API\ResponseTrait;
|
|
use CodeIgniter\Controller;
|
|
use App\Models\PatVisitModel;
|
|
|
|
class PatVisit extends Controller {
|
|
use ResponseTrait;
|
|
|
|
protected $modelPatVisit;
|
|
|
|
public function __construct() {
|
|
$this->modelPatVisit = new PatVisitModel();
|
|
}
|
|
|
|
public function show($PVID = null) {
|
|
try {
|
|
$row = $this->modelPatVisit->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->modelPatVisit->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->modelPatVisit->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->modelPatVisit->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());
|
|
}
|
|
}
|
|
|
|
} |