refactor valueset
This commit is contained in:
parent
438da92d10
commit
4da2d7a54b
@ -67,18 +67,18 @@ $routes->post('/api/occupation', 'Occupation::create');
|
||||
$routes->patch('/api/occupation', 'Occupation::update');
|
||||
//$routes->delete('/api/occupation', 'Occupation::delete');
|
||||
|
||||
$routes->get('/api/valueset', 'ValueSet::index');
|
||||
$routes->get('/api/valueset/(:num)', 'ValueSet::show/$1');
|
||||
$routes->get('/api/valueset/valuesetdef/(:num)', 'ValueSet::showByValueSetDef/$1');
|
||||
$routes->post('/api/valueset', 'ValueSet::create');
|
||||
$routes->patch('/api/valueset', 'ValueSet::update');
|
||||
$routes->delete('/api/valueset', 'ValueSet::delete');
|
||||
$routes->get('/api/valueset', 'ValueSet\ValueSet::index');
|
||||
$routes->get('/api/valueset/(:num)', 'ValueSet\ValueSet::show/$1');
|
||||
$routes->get('/api/valueset/valuesetdef/(:num)', 'ValueSet\ValueSet::showByValueSetDef/$1');
|
||||
$routes->post('/api/valueset', 'ValueSet\ValueSet::create');
|
||||
$routes->patch('/api/valueset', 'ValueSet\ValueSet::update');
|
||||
$routes->delete('/api/valueset', 'ValueSet\ValueSet::delete');
|
||||
|
||||
$routes->get('/api/valuesetdef/', 'ValueSetDef::index');
|
||||
$routes->get('/api/valuesetdef/(:num)', 'ValueSetDef::show/$1');
|
||||
$routes->post('/api/valuesetdef', 'ValueSetDef::create');
|
||||
$routes->patch('/api/valuesetdef', 'ValueSetDef::update');
|
||||
$routes->delete('/api/valuesetdef', 'ValueSetDef::delete');
|
||||
$routes->get('/api/valuesetdef/', 'ValueSet\ValueSetDef::index');
|
||||
$routes->get('/api/valuesetdef/(:num)', 'ValueSet\ValueSetDef::show/$1');
|
||||
$routes->post('/api/valuesetdef', 'ValueSet\ValueSetDef::create');
|
||||
$routes->patch('/api/valuesetdef', 'ValueSet\ValueSetDef::update');
|
||||
$routes->delete('/api/valuesetdef', 'ValueSet\ValueSetDef::delete');
|
||||
|
||||
$routes->get('/api/counter/', 'Counter::index');
|
||||
$routes->get('/api/counter/(:num)', 'Counter::show/$1');
|
||||
|
||||
@ -1,214 +0,0 @@
|
||||
<?php
|
||||
namespace App\Controllers;
|
||||
|
||||
use CodeIgniter\API\ResponseTrait;
|
||||
use CodeIgniter\Controller;
|
||||
use CodeIgniter\Database\RawSql;
|
||||
|
||||
class ValueSet extends Controller {
|
||||
use ResponseTrait;
|
||||
|
||||
public function __construct() {
|
||||
$this->db = \Config\Database::connect();
|
||||
$this->rulesValueSet = [
|
||||
'VSetID' => 'required',
|
||||
'VValue' => 'required',
|
||||
];
|
||||
}
|
||||
|
||||
public function index() {
|
||||
$builder = $this->db->table('valueset')->select("*");
|
||||
$param = $this->request->getVar('param');
|
||||
if ($param !== null) {
|
||||
$builder->like('VValue', $param, 'both');
|
||||
$builder->orlike('VDesc', $param, 'both');
|
||||
}
|
||||
$rows = $builder->get()->getResultArray();
|
||||
|
||||
if (empty($rows)) {
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message' => "no Data.",
|
||||
'data' => [],
|
||||
], 200);
|
||||
}
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message'=> "Value Set fetched successfully",
|
||||
'data' => $rows,
|
||||
], 200);
|
||||
}
|
||||
|
||||
public function show($VID = null) {
|
||||
$rows = $this->db->table('valueset')
|
||||
->select("valueset.*, valuesetdef.VSName")
|
||||
->join('valuesetdef', 'valuesetdef.VSetID = valueset.VSetID', 'LEFT')
|
||||
->where('valueset.VID', (int) $VID)
|
||||
->get()->getResultArray();
|
||||
|
||||
if (empty($rows)) {
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message' => "ValueSet with ID $VID not found.",
|
||||
'data' => [],
|
||||
], 200);
|
||||
}
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message'=> "Data fetched successfully",
|
||||
'data' => $rows,
|
||||
], 200);
|
||||
}
|
||||
|
||||
public function showByValueSetDef($VSetID = null) {
|
||||
$rows = $this->db->table('valueset')
|
||||
->select("*")
|
||||
->where('VSetID', (int) $VSetID)
|
||||
->get()->getResultArray();
|
||||
|
||||
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() {
|
||||
try {
|
||||
$input = $this->request->getJSON(true);
|
||||
|
||||
$dataValueSet = $this->prepareValueSetData($input);
|
||||
|
||||
if (!$this->validateData($dataValueSet, $this->rulesValueSet)) {
|
||||
return $this->failValidationErrors($this->validator->getErrors());
|
||||
}
|
||||
|
||||
// Start transaction
|
||||
$this->db->transStart();
|
||||
|
||||
// Insert
|
||||
$this->db->table('valueset')->insert($dataValueSet);
|
||||
|
||||
// Complete transaction
|
||||
$this->db->transComplete();
|
||||
|
||||
if ($this->db->transStatus() === false) {
|
||||
$dbError = $this->db->error();
|
||||
return $this->failServerError(
|
||||
'Failed to create data (transaction rolled back): ' . ($dbError['message'] ?? 'Unknown database error')
|
||||
);
|
||||
}
|
||||
|
||||
return $this->respondCreated([
|
||||
'status' => 'success',
|
||||
'message' => 'Data created successfully',
|
||||
'data' => $dataValueSet,
|
||||
], 201);
|
||||
|
||||
} catch (\Throwable $e) {
|
||||
// Ensure rollback if something goes wrong
|
||||
if ($this->db->transStatus() !== false) {
|
||||
$this->db->transRollback();
|
||||
}
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function update() {
|
||||
try {
|
||||
$input = $this->request->getJSON(true);
|
||||
$VID = $input["VID"];
|
||||
if (!$VID) {
|
||||
return $this->failValidationErrors('VID is required.');
|
||||
}
|
||||
|
||||
$dataValueSet = $this->prepareValueSetData($input);
|
||||
|
||||
if (!$this->validateData($dataValueSet, $this->rulesValueSet)) {
|
||||
return $this->failValidationErrors( $this->validator->getErrors() );
|
||||
}
|
||||
|
||||
// Start transaction
|
||||
$this->db->transStart();
|
||||
|
||||
// Insert location
|
||||
$this->db->table('valueset')->where('VID', $VID)->update($dataValueSet);
|
||||
|
||||
// Complete transaction
|
||||
$this->db->transComplete();
|
||||
|
||||
if ($this->db->transStatus() === false) {
|
||||
$dbError = $this->db->error();
|
||||
return $this->failServerError(
|
||||
'Failed to update data (transaction rolled back): ' . ($dbError['message'] ?? 'Unknown database error')
|
||||
);
|
||||
}
|
||||
|
||||
return $this->respondCreated([
|
||||
'status' => 'success',
|
||||
'message' => 'Data updated successfully',
|
||||
'data' => $dataValueSet,
|
||||
], 201);
|
||||
|
||||
} catch (\Throwable $e) {
|
||||
// Ensure rollback if something goes wrong
|
||||
if ($this->db->transStatus() !== false) {
|
||||
$this->db->transRollback();
|
||||
}
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function delete() {
|
||||
try {
|
||||
$input = $this->request->getJSON(true);
|
||||
$VID = $input["VID"];
|
||||
if (!$VID) {
|
||||
return $this->failValidationErrors('VID is required.');
|
||||
}
|
||||
|
||||
$valueset = $this->db->table('valuset')->where('VID', $VID)->get()->getRow();
|
||||
if (!$valueset) {
|
||||
return $this->failNotFound("VID with {$VID} not found.");
|
||||
}
|
||||
|
||||
$this->db->table('valueset')->where('VID', $VID)->update(['EndDate' => $this->now ]);
|
||||
|
||||
return $this->respondDeleted([
|
||||
'status' => 'success',
|
||||
'message' => "Data with ID {$VID} deleted successfully."
|
||||
]);
|
||||
|
||||
} catch (\Throwable $e) {
|
||||
// Ensure rollback if something goes wrong
|
||||
if ($this->db->transStatus() !== false) {
|
||||
$this->db->transRollback();
|
||||
}
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private function prepareValueSetData(array $input): array {
|
||||
$data = [
|
||||
"VSetID" => $input['VSetID'] ?? null,
|
||||
"VOrder" => $input['VOrder'] ?? null,
|
||||
"VValue" => $input['VValue'] ?? null,
|
||||
"VDesc" => $input['VDesc'] ?? null,
|
||||
"VCategory" => $input['VCategory'] ?? null
|
||||
];
|
||||
|
||||
if(!empty($input["VID"])) { $data["VID"]=$input["VID"]; }
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
86
app/Controllers/ValueSet/ValueSet.php
Normal file
86
app/Controllers/ValueSet/ValueSet.php
Normal file
@ -0,0 +1,86 @@
|
||||
<?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');
|
||||
$rows = $this->model->getValueSets($param);
|
||||
if (empty($rows)) { return $this->respond([ 'status' => 'success', 'message' => "no Data.", 'data' => [] ], 200); }
|
||||
return $this->respond([ 'status' => 'success', 'message'=> "Data fetched successfully", 'data' => $rows ], 200);
|
||||
}
|
||||
|
||||
public function show($VID = null) {
|
||||
$rows = $this->model->getValueSet($VID);
|
||||
if (empty($rows)) {
|
||||
return $this->respond([ 'status' => 'success', 'message' => "ValueSet with ID $VID not found.", 'data' => [] ], 200);
|
||||
}
|
||||
return $this->respond([ 'status' => 'success', 'message'=> "Data fetched successfully", 'data' => $rows], 200);
|
||||
}
|
||||
|
||||
public function showByValueSetDef($VSetID = null) {
|
||||
$rows = $this->db->table('valueset')
|
||||
->select("*")
|
||||
->where('VSetID', (int) $VSetID)
|
||||
->get()->getResultArray();
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
73
app/Controllers/ValueSet/ValueSetDef.php
Normal file
73
app/Controllers/ValueSet/ValueSetDef.php
Normal file
@ -0,0 +1,73 @@
|
||||
<?php
|
||||
namespace App\Controllers\ValueSet;
|
||||
|
||||
use CodeIgniter\API\ResponseTrait;
|
||||
use App\Controllers\BaseController;
|
||||
use App\Models\ValueSet\ValueSetDefModel;
|
||||
|
||||
class ValueSetDef extends BaseController {
|
||||
use ResponseTrait;
|
||||
|
||||
protected $db;
|
||||
protected $rules;
|
||||
protected $model;
|
||||
|
||||
public function __construct() {
|
||||
$this->db = \Config\Database::connect();
|
||||
$this->model = new ValueSetDefModel;
|
||||
$this->rules = [
|
||||
'VSName' => 'required',
|
||||
'VSDesc' => 'required'
|
||||
];
|
||||
}
|
||||
|
||||
public function index() {
|
||||
$param = $this->request->getVar('param');
|
||||
$rows = $this->model->getValueSetDefs($param);
|
||||
if (empty($rows)) { return $this->respond([ 'status' => 'success', 'message' => "no Data.", 'data' => [] ], 200); }
|
||||
return $this->respond([ 'status' => 'success', 'message'=> "Data fetched successfully", 'data' => $rows ], 200);
|
||||
}
|
||||
|
||||
public function show($VSetID = null) {
|
||||
$rows = $this->model->find($VSetID);
|
||||
if (empty($rows)) { return $this->respond([ 'status' => 'success', 'message' => "no Data.", '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 {
|
||||
$VSetID = $this->model->insert($input);
|
||||
return $this->respondCreated([ 'status' => 'success', 'message' => "data $VSetID created successfully" ]);
|
||||
} catch (\Exception $e) {
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function update() {
|
||||
$input = $this->request->getJSON(true);
|
||||
$VSetID = $input["VID"];
|
||||
if (!$VSetID) { return $this->failValidationErrors('VSetID is required.'); }
|
||||
if (!$this->validateData($input, $this->rules)) { return $this->failValidationErrors( $this->validator->getErrors() ); }
|
||||
try {
|
||||
$this->model->update($VSetID,$input);
|
||||
return $this->respondCreated([ 'status' => 'success', 'message' => "data $VSetID updated successfully" ]);
|
||||
} catch (\Exception $e) {
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function delete() {
|
||||
$input = $this->request->getJSON(true);
|
||||
$VSetID = $input['VSetID'];
|
||||
if (!$VSetID) { return $this->failValidationErrors('VSetID is required.'); }
|
||||
try {
|
||||
$this->model->delete($VSetID);
|
||||
return $this->respondDeleted(['status' => 'success', 'message' => "Data $VSetID deleted successfully."]);
|
||||
} catch (\Throwable $e) {
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,178 +0,0 @@
|
||||
<?php
|
||||
namespace App\Controllers;
|
||||
|
||||
use CodeIgniter\API\ResponseTrait;
|
||||
use CodeIgniter\Controller;
|
||||
use CodeIgniter\Database\RawSql;
|
||||
|
||||
class ValueSetDef extends Controller {
|
||||
use ResponseTrait;
|
||||
|
||||
public function __construct() {
|
||||
$this->db = \Config\Database::connect();
|
||||
$this->rulesvaluesetdef = [
|
||||
'VSName' => 'required',
|
||||
'VSDesc' => 'required'
|
||||
];
|
||||
}
|
||||
|
||||
public function index() {
|
||||
$builder = $this->db->table('valuesetdef')->select("*");
|
||||
$param = $this->request->getVar('param');
|
||||
if ($param !== null) {
|
||||
$builder->like('VSName', $param, 'both');
|
||||
$builder->orlike('VSDesc', $param, 'both');
|
||||
}
|
||||
$rows = $builder->get()->getResultArray();
|
||||
|
||||
if (empty($rows)) {
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message' => "no Data.",
|
||||
'data' => [],
|
||||
], 200);
|
||||
}
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message'=> "Data fetched successfully",
|
||||
'data' => $rows,
|
||||
], 200);
|
||||
}
|
||||
|
||||
public function show($VSetID = null) {
|
||||
$rows = $this->db->table('valuesetdef')
|
||||
->select("*")
|
||||
->where('VSetID', (int) $VSetID)
|
||||
->get()->getResultArray();
|
||||
|
||||
if (empty($rows)) {
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message' => "data with ID $VSetID not found.",
|
||||
'data' => [],
|
||||
], 200);
|
||||
}
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message'=> "Data fetched successfully",
|
||||
'data' => $rows,
|
||||
], 200);
|
||||
}
|
||||
|
||||
public function create() {
|
||||
try {
|
||||
$input = $this->request->getJSON(true);
|
||||
$datavaluesetdef = $this->preparevaluesetdefData($input);
|
||||
|
||||
if (!$this->validateData($datavaluesetdef, $this->rulesvaluesetdef)) {
|
||||
return $this->failValidationErrors($this->validator->getErrors());
|
||||
}
|
||||
|
||||
$this->db->transStart();
|
||||
$this->db->table('valuesetdef')->insert($datavaluesetdef);
|
||||
$this->db->transComplete();
|
||||
|
||||
if ($this->db->transStatus() === false) {
|
||||
$dbError = $this->db->error();
|
||||
return $this->failServerError(
|
||||
'Failed to create data (transaction rolled back): ' . ($dbError['message'] ?? 'Unknown database error')
|
||||
);
|
||||
}
|
||||
|
||||
return $this->respondCreated([
|
||||
'status' => 'success',
|
||||
'message' => 'Data created successfully',
|
||||
'data' => $datavaluesetdef,
|
||||
], 201);
|
||||
|
||||
} catch (\Throwable $e) {
|
||||
// Ensure rollback if something goes wrong
|
||||
if ($this->db->transStatus() !== false) {
|
||||
$this->db->transRollback();
|
||||
}
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function update() {
|
||||
try {
|
||||
$input = $this->request->getJSON(true);
|
||||
$VSetID = $input["VSetID"];
|
||||
if (!$VSetID) {
|
||||
return $this->failValidationErrors('VSetID is required.');
|
||||
}
|
||||
$datavaluesetdef = $this->preparevaluesetdefData($input);
|
||||
|
||||
if (!$this->validateData($datavaluesetdef, $this->rulesvaluesetdef)) {
|
||||
return $this->failValidationErrors( $this->validator->getErrors());
|
||||
}
|
||||
|
||||
$this->db->transStart();
|
||||
$this->db->table('valuesetdef')->where('VSetID', $VSetID)->update($datavaluesetdef);
|
||||
$this->db->transComplete();
|
||||
|
||||
if ($this->db->transStatus() === false) {
|
||||
$dbError = $this->db->error();
|
||||
return $this->failServerError(
|
||||
'Failed to update data (transaction rolled back): ' . ($dbError['message'] ?? 'Unknown database error')
|
||||
);
|
||||
}
|
||||
|
||||
return $this->respondCreated([
|
||||
'status' => 'success',
|
||||
'message' => 'Data updated successfully',
|
||||
'data' => $datavaluesetdef,
|
||||
], 201);
|
||||
|
||||
} catch (\Throwable $e) {
|
||||
// Ensure rollback if something goes wrong
|
||||
if ($this->db->transStatus() !== false) {
|
||||
$this->db->transRollback();
|
||||
}
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function delete() {
|
||||
try {
|
||||
$input = $this->request->getJSON(true);
|
||||
$VSetID = $input["VSetID"];
|
||||
if (!$VSetID) {
|
||||
return $this->failValidationErrors('VSetID is required.');
|
||||
}
|
||||
|
||||
$valuesetdef = $this->db->table('valuesetdef')->where('VSetID', $VSetID)->get()->getRow();
|
||||
if (!$valuesetdef) {
|
||||
return $this->failNotFound("Data with {$VSetID} not found.");
|
||||
}
|
||||
|
||||
$this->db->table('valuesetdef')->where('VSetID', $VSetID)->update(['EndDate' => $this->now]);
|
||||
|
||||
return $this->respondDeleted([
|
||||
'status' => 'success',
|
||||
'message' => "data with {$VSetID} deleted successfully."
|
||||
]);
|
||||
|
||||
} catch (\Throwable $e) {
|
||||
// Ensure rollback if something goes wrong
|
||||
if ($this->db->transStatus() !== false) {
|
||||
$this->db->transRollback();
|
||||
}
|
||||
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private function preparevaluesetdefData(array $input): array {
|
||||
$data = [
|
||||
"VSName" => $input['VSName'] ?? null,
|
||||
"VSDesc" => $input['VSDesc'] ?? null
|
||||
];
|
||||
|
||||
if(!empty($input["VSetID"])) { $data["VSetID"]=$input["VSetID"]; }
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
}
|
||||
@ -10,7 +10,7 @@ class SpecimenSeeder extends Seeder {
|
||||
// containerdef
|
||||
$data = [
|
||||
['ConCode' => '1','ConName' => 'SST', 'ConDesc' =>'Evacuated blood collection tube, gel separator', 'Additive' => "Gel", 'ConClass' => '1'],
|
||||
['ConCode' => '11','ConName' => 'Plain', 'ConDesc' =>'Evacuated blood collection tube, no additive/metal-free', 'Additive' => "None", 'ConClass' => '1'],
|
||||
['ConCode' => '11','ConName' => 'Plain', 'ConDesc' =>'Evacuated blood collection tube, no additive/metal-free', 'Additive' => null, 'ConClass' => '1'],
|
||||
['ConCode' => '12','ConName' => '2Hr PP', 'ConDesc' =>'Evacuated blood collection tube, untuk Glukosa 2 Jam PP', 'Additive' => "Sodium Fluoride", 'ConClass' => '1'],
|
||||
['ConCode' => '13','ConName' => 'Glukosa Sewaktu', 'ConDesc' =>'Evacuated blood collection tube, untuk Glukosa Sewaktu', 'Additive' => "Sodium Fluoride", 'ConClass' => '1'],
|
||||
['ConCode' => '14','ConName' => 'GTT 30 menit', 'ConDesc' =>'Evacuated blood collection tube, untuk GTT 30 menit', 'Additive' => "Sodium Fluoride", 'ConClass' => '1'],
|
||||
@ -19,10 +19,10 @@ class SpecimenSeeder extends Seeder {
|
||||
['ConCode' => '20','ConName' => 'RST', 'ConDesc' =>'Evacuated blood collection tube, thrombin/clot activator/gel separator', 'Additive' => "Clot activator", 'ConClass' => '1'],
|
||||
['ConCode' => '101','ConName' => 'EDTA - Hematologi', 'ConDesc' =>'Evacuated blood collection tube, K2EDTA/aprotinin', 'Additive' => "K2EDTA", 'ConClass' => '1'],
|
||||
['ConCode' => '150','ConName' => 'Citrate - Koagulasi', 'ConDesc' =>'Evacuated blood collection tube, untuk koagulasi', 'Additive' => "Sodium citrate (substance)", 'ConClass' => '1'],
|
||||
['ConCode' => '200','ConName' => 'Aliquot', 'ConDesc' =>'General specimen container, no additive, non-sterile. Untuk aliquot', 'Additive' => "", 'ConClass' => '1'],
|
||||
['ConCode' => '290','ConName' => 'Pot Urin', 'ConDesc' =>'Non-sterile urine specimen container IVD', 'Additive' => "<null>", 'ConClass' => '1'],
|
||||
['ConCode' => '295','ConName' => 'Urine Container', 'ConDesc' =>'Urine specimen container', 'Additive' => "<null>", 'ConClass' => '1'],
|
||||
['ConCode' => '900','ConName' => 'Packing Pengiriman', 'ConDesc' =>'Specimen Transport Packaging', 'Additive' => "<null>", 'ConClass' => '2']
|
||||
['ConCode' => '200','ConName' => 'Aliquot', 'ConDesc' =>'General specimen container, no additive, non-sterile. Untuk aliquot', 'Additive' => null, 'ConClass' => '1'],
|
||||
['ConCode' => '290','ConName' => 'Pot Urin', 'ConDesc' =>'Non-sterile urine specimen container IVD', 'Additive' => null, 'ConClass' => '1'],
|
||||
['ConCode' => '295','ConName' => 'Urine Container', 'ConDesc' =>'Urine specimen container', 'Additive' => null, 'ConClass' => '1'],
|
||||
['ConCode' => '900','ConName' => 'Packing Pengiriman', 'ConDesc' =>'Specimen Transport Packaging', 'Additive' => null, 'ConClass' => '2']
|
||||
];
|
||||
$this->db->table('containerdef')->insertBatch($data);
|
||||
|
||||
|
||||
37
app/Models/ValueSet/ValueSetDefModel.php
Normal file
37
app/Models/ValueSet/ValueSetDefModel.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\ValueSet;
|
||||
|
||||
use App\Models\BaseUtcModel;
|
||||
|
||||
class ValueSetDefModel extends BaseUtcModel {
|
||||
protected $table = 'valuesetdef';
|
||||
protected $primaryKey = 'VSetID';
|
||||
protected $allowedFields = ['SiteID', 'VSName', 'VSDesc', 'CreateDate', 'EndDate'];
|
||||
|
||||
protected $useTimestamps = true;
|
||||
protected $createdField = 'CreateDate';
|
||||
protected $updatedField = '';
|
||||
protected $useSoftDeletes = true;
|
||||
protected $deletedField = 'EndDate';
|
||||
|
||||
protected $beforeInsert = ['normalizeDatesToUTC'];
|
||||
protected $beforeUpdate = ['normalizeDatesToUTC'];
|
||||
protected $afterFind = ['convertDatesToUTCISO'];
|
||||
protected $afterInsert = ['convertDatesToUTCISO'];
|
||||
protected $afterUpdate = ['convertDatesToUTCISO'];
|
||||
|
||||
public function getValueSetDefs($param = null) {
|
||||
if ($param !== null) {
|
||||
$builder = $this->builder();
|
||||
$builder->like('VSName', $param, 'both');
|
||||
$builder->orlike('VSDesc', $param, 'both');
|
||||
$rows = $builder->get()->getResultArray();
|
||||
} else {
|
||||
$rows = $this->findAll();
|
||||
}
|
||||
return $rows;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
47
app/Models/ValueSet/ValueSetModel.php
Normal file
47
app/Models/ValueSet/ValueSetModel.php
Normal file
@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\ValueSet;
|
||||
|
||||
use App\Models\BaseUtcModel;
|
||||
|
||||
class ValueSetModel extends BaseUtcModel {
|
||||
protected $table = 'valueset';
|
||||
protected $primaryKey = 'VID';
|
||||
protected $allowedFields = ['SiteID', 'VSetID', 'VOrder', 'VValue', 'VDesc', 'VCategory', 'CreateDate', 'EndDate'];
|
||||
|
||||
protected $useTimestamps = true;
|
||||
protected $createdField = 'CreateDate';
|
||||
protected $updatedField = '';
|
||||
protected $useSoftDeletes = true;
|
||||
protected $deletedField = 'EndDate';
|
||||
|
||||
protected $beforeInsert = ['normalizeDatesToUTC'];
|
||||
protected $beforeUpdate = ['normalizeDatesToUTC'];
|
||||
protected $afterFind = ['convertDatesToUTCISO'];
|
||||
protected $afterInsert = ['convertDatesToUTCISO'];
|
||||
protected $afterUpdate = ['convertDatesToUTCISO'];
|
||||
|
||||
public function getValueSets($param = null) {
|
||||
if ($param !== null) {
|
||||
$builder = $this->builder();
|
||||
$builder->groupStart()
|
||||
->like('VValue', $param, 'both')
|
||||
->orlike('VDesc', $param, 'both')
|
||||
->groupEnd();
|
||||
$rows = $builder->get()->getResultArray();
|
||||
|
||||
return $rows;
|
||||
} else {
|
||||
return $this->findAll();
|
||||
}
|
||||
}
|
||||
|
||||
public function getValueSet($VID) {
|
||||
$rows = $this->select("valueset.*, valuesetdef.VSName")
|
||||
->join('valuesetdef', 'valuesetdef.VSetID = valueset.VSetID', 'LEFT')
|
||||
->find($VID);
|
||||
|
||||
return $rows;
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user