clqms-be/app/Controllers/PatVisit.php

84 lines
3.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-23 12:16:52 +07:00
use App\Models\PatVisit\PatVisitADTModel;
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-23 12:16:52 +07:00
if($row == []) { $message = "data not found"; }
else { $message = "data found"; }
2025-10-20 14:09:09 +07:00
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-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());
}
}
2025-09-19 16:43:03 +07:00
}