mahdahar a94df3b5f7 **feat: migrate to v2 frontend with Alpine.js pattern**
- Introduce v2 views directory with Alpine.js-based UI components
- Add AuthV2 controller for v2 authentication flow
- Update PagesController for v2 routing
- Refactor ValueSet module with v2 dialogs and nested CRUD views
- Add organization management views (accounts, departments, disciplines, sites, workstations)
- Add specimen management views (containers, preparations)
- Add master views for tests and valuesets
- Migrate patient views to v2 pattern
- Update Routes and Exceptions config for v2 support
- Enhance CORS configuration
- Clean up legacy files (check_db.php, llms.txt, sanity.php, old views)
- Update agent workflow patterns for PHP Alpine.js
2025-12-30 14:30:35 +07:00

97 lines
3.7 KiB
PHP

<?php
namespace App\Controllers\ValueSet;
use CodeIgniter\API\ResponseTrait;
use App\Controllers\BaseController;
use App\Models\ValueSet\ValueSetModel;
class ValueSet extends BaseController {
use ResponseTrait;
protected $db;
protected $model;
protected $rules;
public function __construct() {
$this->db = \Config\Database::connect();
$this->model = new ValueSetModel;
$this->rules = [
'VSetID' => 'required',
'VValue' => 'required',
];
}
public function index() {
$param = $this->request->getVar('param');
$VSetID = $this->request->getVar('VSetID');
$page = $this->request->getVar('page') ?? 1;
$limit = $this->request->getVar('limit') ?? 20;
$result = $this->model->getValueSets($param, $page, $limit, $VSetID);
return $this->respond([
'status' => 'success',
'message'=> "Data fetched successfully",
'data' => $result['data'],
'pagination' => [
'currentPage' => (int)$page,
'totalPages' => $result['pager']->getPageCount(),
'totalItems' => $result['pager']->getTotal(),
'limit' => (int)$limit
]
], 200);
}
public function show($VID = null) {
$row = $this->model->getValueSet($VID);
if (empty($row)) {
return $this->respond([ 'status' => 'success', 'message' => "ValueSet with ID $VID not found.", 'data' => null ], 200);
}
return $this->respond([ 'status' => 'success', 'message'=> "Data fetched successfully", 'data' => $row], 200);
}
public function showByValueSetDef($VSetID = null) {
$rows = $this->model->getValueSetByValueSetDef($VSetID);
if (empty($rows)) {
return $this->respond([ 'status' => 'success', 'message' => "ValueSet not found.", 'data' => [] ], 200);
}
return $this->respond([ 'status' => 'success', 'message'=> "Data fetched successfully", 'data' => $rows ], 200);
}
public function create() {
$input = $this->request->getJSON(true);
if (!$this->validateData($input, $this->rules)) { return $this->failValidationErrors($this->validator->getErrors()); }
try {
$VID = $this->model->insert($input);
return $this->respondCreated([ 'status' => 'success', 'message' => "data $VID created successfully" ]);
} catch (\Exception $e) {
return $this->failServerError('Something went wrong: ' . $e->getMessage());
}
}
public function update() {
$input = $this->request->getJSON(true);
$VID = $input["VID"];
if (!$VID) { return $this->failValidationErrors('VID is required.'); }
if (!$this->validateData($input, $this->rules)) { return $this->failValidationErrors( $this->validator->getErrors() ); }
try {
$this->model->update($VID,$input);
return $this->respondCreated([ 'status' => 'success', 'message' => "data $VID updated successfully" ]);
} catch (\Exception $e) {
return $this->failServerError('Something went wrong: ' . $e->getMessage());
}
}
public function delete() {
$input = $this->request->getJSON(true);
$VID = $input["VID"];
if (!$VID) { return $this->failValidationErrors('VID is required.'); }
try {
$this->model->delete($VID);
return $this->respondDeleted(['status' => 'success', 'message' => "Data $VID deleted successfully."]);
} catch (\Throwable $e) {
return $this->failServerError('Something went wrong: ' . $e->getMessage());
}
}
}