clqms-be/app/Controllers/Location.php
mahdahar 118d490bbd refactor: update TestSeeder to use dynamic ValueSet lookups
- Implemented dynamic VID retrieval from ValueSetModel for all test definitions
- Aligned ResultType, RefType, and SpcType with the valueset table
- Updated sample data for Hematology, Chemistry, and Urinalysis tests
- Ensured consistency between ValueSetSeeder and TestSeeder data
2025-12-29 12:55:31 +07:00

75 lines
2.8 KiB
PHP

<?php
namespace App\Controllers;
use CodeIgniter\API\ResponseTrait;
use App\Controllers\BaseController;
use App\Models\Location\LocationModel;
class Location extends BaseController {
use ResponseTrait;
protected $model;
protected $rules;
public function __construct() {
$this->model = new LocationModel();
$this->rules = [
'LocCode' => 'required|max_length[6]',
'LocFull' => 'required',
];
}
public function index() {
$LocName = $this->request->getVar('LocName');
$LocCode = $this->request->getVar('LocCode');
$rows = $this->model->getLocations($LocCode,$LocName);
if (empty($rows)) {
return $this->respond([ 'status' => 'success', 'message' => "no Data.", 'data' => [] ], 200);
}
return $this->respond([ 'status' => 'success', 'message'=> "fetch success", 'data' => $rows ], 200);
}
public function show($LocationID = null) {
$row = $this->model->getLocation($LocationID);
if (empty($row)) {
return $this->respond([ 'status' => 'success', 'message' => "no Data.", 'data' => null ], 200);
}
return $this->respond([ 'status' => 'success', 'message'=> "fetch success", 'data' => $row ], 200);
}
public function create() {
$input = $this->request->getJSON(true);
if (!$this->validateData($input, $this->rules)) { return $this->failValidationErrors($this->validator->getErrors()); }
try {
$id = $this->model->saveLocation($input);
return $this->respondCreated([ 'status' => 'success', 'message' => 'data created successfully', 'data' => $id ], 201);
} catch (\Throwable $e) {
return $this->failServerError('Something went wrong: ' . $e->getMessage());
}
}
public function update() {
$input = $this->request->getJSON(true);
try {
if (!$this->validateData($input, $this->rules)) { return $this->failValidationErrors( $this->validator->getErrors()); }
$id = $this->model->saveLocation($input, true);
return $this->respondCreated([ 'status' => 'success', 'message' => 'data updated successfully', 'data' => $id ], 201);
} catch (\Throwable $e) {
return $this->failServerError('Something went wrong: ' . $e->getMessage());
}
}
public function delete() {
$input = $this->request->getJSON(true);
try {
$LocationID = $input["LocationID"];
$this->model->deleteLocation($LocationID);
return $this->respondDeleted([ 'status' => 'success', 'message' => "Location with {$LocationID} deleted successfully." ]);
} catch (\Throwable $e) {
return $this->failServerError('Something went wrong: ' . $e->getMessage());
}
}
}