refactor: consolidate ValueSet API and simplify seeders

- Consolidate ValueSet routes from multiple nested groups to flat structure
- Delete deprecated ValueSet\ namespaced controllers (ValueSetController, ValueSetDefController)
- Remove ValueSetSeeder and ValueSetCountrySeeder from DBSeeder
- Simplify seeders (LocationSeeder, OrganizationSeeder, PatientSeeder, TestSeeder)
  to use literal string values instead of ValueSet lookups
- Add new ValueSetController and ValueSetDefController in root namespace
- Update test files for new controller structure
The key changes are:
1. Routes: Consolidated from nested ValueSet\ namespace routes to flat ValueSetController routes with /items sub-endpoints
2. Controllers: Deleted old app/Controllers/ValueSet/ directory, created new root-level controllers
3. Seeders: Removed ValueSet dependencies, using literal values like 'ROOM', '1', 'TEST' instead of [12]['ROOM'] etc.
4. Tests: Updated tests to match new controller structure
This commit is contained in:
mahdahar 2026-01-13 16:48:43 +07:00
parent 4aa9cefc3d
commit e36e390f71
19 changed files with 616 additions and 713 deletions

View File

@ -146,33 +146,24 @@ $routes->group('api', function ($routes) {
$routes->patch('/', 'Contact\MedicalSpecialtyController::update');
});
// ValueSet
$routes->group('valueset', function ($routes) {
$routes->get('/', 'ValueSet\ValueSetController::index');
$routes->get('(:any)', 'ValueSet\ValueSetController::showByName/$1');
$routes->post('/', 'ValueSet\ValueSetController::create');
$routes->patch('/', 'ValueSet\ValueSetController::update');
$routes->delete('/', 'ValueSet\ValueSetController::delete');
$routes->post('refresh', 'ValueSet\ValueSetController::refresh');
$routes->get('/', 'ValueSetController::index');
$routes->get('(:any)', 'ValueSetController::index/$1');
$routes->post('refresh', 'ValueSetController::refresh');
$routes->get('items', 'ValueSetController::items');
$routes->get('items/(:num)', 'ValueSetController::showItem/$1');
$routes->post('items', 'ValueSetController::createItem');
$routes->put('items/(:num)', 'ValueSetController::updateItem/$1');
$routes->delete('items/(:num)', 'ValueSetController::deleteItem/$1');
});
$routes->group('valuesetdef', function ($routes) {
$routes->get('/', 'ValueSet\ValueSetDefController::index');
$routes->get('(:segment)', 'ValueSet\ValueSetDefController::show/$1');
$routes->post('/', 'ValueSet\ValueSetDefController::create');
$routes->patch('/', 'ValueSet\ValueSetDefController::update');
$routes->delete('/', 'ValueSet\ValueSetDefController::delete');
});
$routes->group('valuesets', function ($routes) {
$routes->get('/', 'ValueSet\ValueSetApiController::index');
$routes->post('refresh', 'ValueSet\ValueSetApiController::refresh');
});
$routes->group('valueset', function ($routes) {
$routes->get('/', 'ValueSetApiController::index');
$routes->get('all', 'ValueSetApiController::all');
$routes->get('(:segment)', 'ValueSetApiController::index/$1');
$routes->get('/', 'ValueSetDefController::index');
$routes->get('(:num)', 'ValueSetDefController::show/$1');
$routes->post('/', 'ValueSetDefController::create');
$routes->put('(:num)', 'ValueSetDefController::update/$1');
$routes->delete('(:num)', 'ValueSetDefController::delete/$1');
});
// Counter

View File

@ -169,7 +169,7 @@ class TestsController extends BaseController
];
}, $refnumData ?? []);
$row['numRefTypeOptions'] = ValueSet::getOptions('numeric_ref_type');
// $row['numRefTypeOptions'] = ValueSet::getOptions('numeric_ref_type');
$row['rangeTypeOptions'] = ValueSet::getOptions('range_type');
}
@ -194,14 +194,14 @@ class TestsController extends BaseController
];
}, $reftxtData ?? []);
$row['txtRefTypeOptions'] = ValueSet::getOptions('text_ref_type');
// $row['txtRefTypeOptions'] = ValueSet::getOptions('text_ref_type');
}
}
}
$row['refTypeOptions'] = ValueSet::getOptions('reference_type');
$row['sexOptions'] = ValueSet::getOptions('gender');
$row['mathSignOptions'] = ValueSet::getOptions('math_sign');
// $row['refTypeOptions'] = ValueSet::getOptions('reference_type');
// $row['sexOptions'] = ValueSet::getOptions('gender');
// $row['mathSignOptions'] = ValueSet::getOptions('math_sign');
return $this->respond(['status' => 'success', 'message' => "Data fetched successfully", 'data' => $row], 200);
}

View File

@ -1,82 +0,0 @@
<?php
namespace App\Controllers\ValueSet;
use CodeIgniter\API\ResponseTrait;
use App\Controllers\BaseController;
use App\Libraries\ValueSet;
class ValueSetController extends BaseController {
use ResponseTrait;
public function index() {
$param = $this->request->getVar('param');
if ($param) {
$all = ValueSet::getAll();
$filtered = array_filter($all, function($item) use ($param) {
return stripos($item['VSName'] ?? '', $param) !== false ||
stripos($item['name'] ?? '', $param) !== false;
});
return $this->respond([
'status' => 'success',
'data' => array_values($filtered)
], 200);
}
return $this->respond([
'status' => 'success',
'data' => ValueSet::getAll()
], 200);
}
public function showByName(string $name = null) {
if (!$name) {
return $this->respond([
'status' => 'error',
'message' => 'Name is required'
], 400);
}
$data = ValueSet::get($name);
if (!$data) {
return $this->respond([
'status' => 'error',
'message' => "ValueSet '$name' not found"
], 404);
}
return $this->respond([
'status' => 'success',
'data' => $data
], 200);
}
public function create() {
return $this->respond([
'status' => 'error',
'message' => 'CRUD operations on value sets are disabled. Edit JSON files directly.'
], 403);
}
public function update() {
return $this->respond([
'status' => 'error',
'message' => 'CRUD operations on value sets are disabled. Edit JSON files directly.'
], 403);
}
public function delete() {
return $this->respond([
'status' => 'error',
'message' => 'CRUD operations on value sets are disabled. Edit JSON files directly.'
], 403);
}
public function refresh() {
ValueSet::clearCache();
return $this->respond([
'status' => 'success',
'message' => 'Cache cleared'
], 200);
}
}

View File

@ -1,73 +0,0 @@
<?php
namespace App\Controllers\ValueSet;
use CodeIgniter\API\ResponseTrait;
use App\Controllers\BaseController;
use App\Models\ValueSet\ValueSetDefModel;
class ValueSetDefController 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) {
$row = $this->model->find($VSetID);
if (empty($row)) { return $this->respond([ 'status' => 'success', 'message' => "no Data.", 'data' => null ], 200); }
return $this->respond([ 'status' => 'success', 'message'=> "Data fetched successfully", 'data' => $row ], 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["VSetID"];
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());
}
}
}

View File

@ -1,38 +0,0 @@
<?php
namespace App\Controllers;
use App\Libraries\ValueSet;
class ValueSetApiController extends \CodeIgniter\Controller
{
use \CodeIgniter\API\ResponseTrait;
public function index(string $lookupName)
{
$data = ValueSet::getOptions($lookupName);
return $this->respond([
'status' => 'success',
'data' => $data
], 200);
}
public function all()
{
$dir = APPPATH . 'Libraries/Data/valuesets/';
$files = glob($dir . '*.json');
$result = [];
foreach ($files as $file) {
$name = basename($file, '.json');
if ($name[0] === '_') continue;
$result[] = [
'name' => $name,
'options' => ValueSet::getOptions($name)
];
}
return $this->respond([
'status' => 'success',
'data' => $result
], 200);
}
}

View File

@ -0,0 +1,181 @@
<?php
namespace App\Controllers;
use App\Libraries\ValueSet;
use App\Models\ValueSet\ValueSetModel;
use CodeIgniter\API\ResponseTrait;
class ValueSetController extends \CodeIgniter\Controller
{
use ResponseTrait;
protected $dbModel;
public function __construct()
{
$this->dbModel = new ValueSetModel();
}
public function index(?string $lookupName = null)
{
if ($lookupName === null) {
$all = ValueSet::getAll();
$result = [];
foreach ($all as $name => $entry) {
$count = count($entry['values'] ?? []);
$result[$name] = $count;
}
return $this->respond([
'status' => 'success',
'data' => $result
], 200);
}
$data = ValueSet::get($lookupName);
if (!$data) {
return $this->respond([
'status' => 'error',
'message' => "ValueSet '$lookupName' not found"
], 404);
}
return $this->respond([
'status' => 'success',
'data' => $data
], 200);
}
public function refresh()
{
ValueSet::clearCache();
return $this->respond([
'status' => 'success',
'message' => 'Cache cleared'
], 200);
}
public function items()
{
$search = $this->request->getGet('search') ?? $this->request->getGet('param') ?? null;
$VSetID = $this->request->getGet('VSetID') ?? null;
$rows = $this->dbModel->getValueSets($search, $VSetID);
return $this->respond([
'status' => 'success',
'data' => $rows
], 200);
}
public function showItem($id = null)
{
$row = $this->dbModel->getValueSet($id);
if (!$row) {
return $this->failNotFound("ValueSet item not found: $id");
}
return $this->respond([
'status' => 'success',
'data' => $row
], 200);
}
public function createItem()
{
$input = $this->request->getJSON(true);
if (!$input) {
return $this->failValidationErrors(['Invalid JSON input']);
}
$data = [
'SiteID' => $input['SiteID'] ?? 1,
'VSetID' => $input['VSetID'] ?? null,
'VOrder' => $input['VOrder'] ?? 0,
'VValue' => $input['VValue'] ?? '',
'VDesc' => $input['VDesc'] ?? ''
];
if ($data['VSetID'] === null) {
return $this->failValidationErrors(['VSetID is required']);
}
try {
$id = $this->dbModel->insert($data, true);
if (!$id) {
return $this->failValidationErrors($this->dbModel->errors());
}
$newRow = $this->dbModel->getValueSet($id);
return $this->respondCreated([
'status' => 'success',
'message' => 'ValueSet item created',
'data' => $newRow
]);
} catch (\Exception $e) {
return $this->failServerError('Failed to create: ' . $e->getMessage());
}
}
public function updateItem($id = null)
{
$input = $this->request->getJSON(true);
if (!$input) {
return $this->failValidationErrors(['Invalid JSON input']);
}
$existing = $this->dbModel->getValueSet($id);
if (!$existing) {
return $this->failNotFound("ValueSet item not found: $id");
}
$data = [];
if (isset($input['VSetID'])) $data['VSetID'] = $input['VSetID'];
if (isset($input['VOrder'])) $data['VOrder'] = $input['VOrder'];
if (isset($input['VValue'])) $data['VValue'] = $input['VValue'];
if (isset($input['VDesc'])) $data['VDesc'] = $input['VDesc'];
if (isset($input['SiteID'])) $data['SiteID'] = $input['SiteID'];
if (empty($data)) {
return $this->respond([
'status' => 'success',
'message' => 'No changes to update',
'data' => $existing
], 200);
}
try {
$updated = $this->dbModel->update($id, $data);
if (!$updated) {
return $this->failValidationErrors($this->dbModel->errors());
}
$newRow = $this->dbModel->getValueSet($id);
return $this->respond([
'status' => 'success',
'message' => 'ValueSet item updated',
'data' => $newRow
], 200);
} catch (\Exception $e) {
return $this->failServerError('Failed to update: ' . $e->getMessage());
}
}
public function deleteItem($id = null)
{
$existing = $this->dbModel->getValueSet($id);
if (!$existing) {
return $this->failNotFound("ValueSet item not found: $id");
}
try {
$this->dbModel->delete($id);
return $this->respond([
'status' => 'success',
'message' => 'ValueSet item deleted'
], 200);
} catch (\Exception $e) {
return $this->failServerError('Failed to delete: ' . $e->getMessage());
}
}
}

View File

@ -0,0 +1,152 @@
<?php
namespace App\Controllers;
use App\Models\ValueSet\ValueSetDefModel;
use CodeIgniter\API\ResponseTrait;
class ValueSetDefController extends \CodeIgniter\Controller
{
use ResponseTrait;
protected $model;
public function __construct()
{
$this->model = new ValueSetDefModel();
}
public function index()
{
$search = $this->request->getGet('search') ?? null;
$limit = (int) ($this->request->getGet('limit') ?? 100);
$page = (int) ($this->request->getGet('page') ?? 1);
$offset = ($page - 1) * $limit;
$rows = $this->model->getValueSetDefs($search);
$paged = array_slice($rows, $offset, $limit);
return $this->respond([
'status' => 'success',
'data' => $paged,
'meta' => [
'total' => count($rows),
'page' => $page,
'limit' => $limit
]
], 200);
}
public function show($id = null)
{
$row = $this->model->find($id);
if (!$row) {
return $this->failNotFound("ValueSet definition not found: $id");
}
$itemCount = $this->model->db->table('valueset')
->select('COUNT(*) as ItemCount')
->where('VSetID', $id)
->where('EndDate IS NULL')
->get()
->getRowArray()['ItemCount'] ?? 0;
$row['ItemCount'] = (int) $itemCount;
return $this->respond([
'status' => 'success',
'data' => $row
], 200);
}
public function create()
{
$input = $this->request->getJSON(true);
if (!$input) {
return $this->failValidationErrors(['Invalid JSON input']);
}
$data = [
'SiteID' => $input['SiteID'] ?? 1,
'VSName' => $input['VSName'] ?? '',
'VSDesc' => $input['VSDesc'] ?? ''
];
try {
$id = $this->model->insert($data, true);
if (!$id) {
return $this->failValidationErrors($this->model->errors());
}
$newRow = $this->model->find($id);
return $this->respondCreated([
'status' => 'success',
'message' => 'ValueSet definition created',
'data' => $newRow
]);
} catch (\Exception $e) {
return $this->failServerError('Failed to create: ' . $e->getMessage());
}
}
public function update($id = null)
{
$input = $this->request->getJSON(true);
if (!$input) {
return $this->failValidationErrors(['Invalid JSON input']);
}
$existing = $this->model->find($id);
if (!$existing) {
return $this->failNotFound("ValueSet definition not found: $id");
}
$data = [];
if (isset($input['VSName'])) $data['VSName'] = $input['VSName'];
if (isset($input['VSDesc'])) $data['VSDesc'] = $input['VSDesc'];
if (isset($input['SiteID'])) $data['SiteID'] = $input['SiteID'];
if (empty($data)) {
return $this->respond([
'status' => 'success',
'message' => 'No changes to update',
'data' => $existing
], 200);
}
try {
$updated = $this->model->update($id, $data);
if (!$updated) {
return $this->failValidationErrors($this->model->errors());
}
$newRow = $this->model->find($id);
return $this->respond([
'status' => 'success',
'message' => 'ValueSet definition updated',
'data' => $newRow
], 200);
} catch (\Exception $e) {
return $this->failServerError('Failed to update: ' . $e->getMessage());
}
}
public function delete($id = null)
{
$existing = $this->model->find($id);
if (!$existing) {
return $this->failNotFound("ValueSet definition not found: $id");
}
try {
$this->model->delete($id);
return $this->respond([
'status' => 'success',
'message' => 'ValueSet definition deleted'
], 200);
} catch (\Exception $e) {
return $this->failServerError('Failed to delete: ' . $e->getMessage());
}
}
}

View File

@ -11,8 +11,8 @@ class AreaGeoSeeder extends Seeder
/**
* API configuration for fetching zones data
*/
// protected string $apiUrl = 'https://services-summit.my.id/api/zones'; //DEV
protected string $apiUrl = 'http://services-summit.my.id/api/zones'; //PROD
protected string $apiUrl = 'https://services-summit.my.id/api/zones'; //DEV
//protected string $apiUrl = 'http://services-summit.my.id/api/zones'; //PROD
// public function run()
// {

View File

@ -8,8 +8,6 @@ class DBSeeder extends Seeder
{
public function run()
{
$this->call('ValueSetSeeder');
$this->call('ValueSetCountrySeeder');
$this->call('OrganizationSeeder');
$this->call('CounterSeeder');
$this->call('ContactSeeder');

View File

@ -3,25 +3,17 @@
namespace App\Database\Seeds;
use CodeIgniter\Database\Seeder;
use App\Models\ValueSet\ValueSetModel;
class LocationSeeder extends Seeder {
protected array $map = [];
public function run() {
class LocationSeeder extends Seeder
{
public function run()
{
$now = date('Y-m-d H:i:s');
$vsModel = new ValueSetModel();
$rows = $vsModel->select("VID, VSetID, VValue")->findAll();
$vs = [];
foreach ($rows as $row) {
$vs[$row['VSetID']][$row['VValue']] = $row['VID'];
}
// location
$data = [
['LocationID' => 1, 'LocCode' => 'QLOC', 'LocFull' => 'Dummy Location', 'LocType' => $vs[12]['ROOM'], 'Description' => 'Location made for dummy testing', 'CreateDate' => "$now" ],
['LocationID' => 2, 'LocCode' => 'DEFLOC', 'LocFull' => 'Default Location', 'LocType' => $vs[12]['ROOM'], 'Description' => 'Default location', 'CreateDate' => "$now" ]
['LocationID' => 1, 'LocCode' => 'QLOC', 'LocFull' => 'Dummy Location', 'LocType' => 'ROOM', 'Description' => 'Location made for dummy testing', 'CreateDate' => "$now" ],
['LocationID' => 2, 'LocCode' => 'DEFLOC', 'LocFull' => 'Default Location', 'LocType' => 'ROOM', 'Description' => 'Default location', 'CreateDate' => "$now" ]
];
$this->db->table('location')->insertBatch($data);
$data = [
@ -29,6 +21,5 @@ class LocationSeeder extends Seeder {
['LocationID' => 2, 'Street1' => 'Jalan ', 'Street2' => 'Jalan jalan', 'City' => 'Depok', 'Province' => 'DKI Jakarta', 'PostCode' => '10123', 'CreateDate' => "$now"]
];
$this->db->table('locationaddress')->insertBatch($data);
}
}

View File

@ -3,20 +3,13 @@
namespace App\Database\Seeds;
use CodeIgniter\Database\Seeder;
use App\Models\ValueSet\ValueSetModel;
use App\Libraries\ValueSet;
class OrganizationSeeder extends Seeder {
protected array $map = [];
public function run() {
class OrganizationSeeder extends Seeder
{
public function run()
{
$now = date('Y-m-d H:i:s');
$vsModel = new ValueSetModel();
$rows = $vsModel->select("VID, VSetID, VValue")->findAll();
$vs = [];
foreach ($rows as $row) {
$vs[$row['VSetID']][$row['VValue']] = $row['VID'];
}
// Organization
$data = [
@ -60,15 +53,14 @@ class OrganizationSeeder extends Seeder {
$this->db->table('department')->insertBatch($data);
$data = [
['WorkstationID' => '1', 'DepartmentID' => '1', 'WorkstationCode' => 'HAUTO', 'WorkstationName' => 'Hematologi Auto', 'Type' => $vs[1][0], 'LinkTo' => '', 'Enable' => $vs[2][1], 'CreateDate' => "$now"],
['WorkstationID' => '2', 'DepartmentID' => '1', 'WorkstationCode' => 'HBACK', 'WorkstationName' => 'Hematologi Backup', 'Type' => $vs[1][1], 'LinkTo' => '1', 'Enable' => $vs[2][1], 'CreateDate' => "$now"],
['WorkstationID' => '3', 'DepartmentID' => '3', 'WorkstationCode' => 'CAUTO', 'WorkstationName' => 'Kimia Auto', 'Type' => $vs[1][0], 'LinkTo' => '', 'Enable' => $vs[2][1], 'CreateDate' => "$now"],
['WorkstationID' => '4', 'DepartmentID' => '3', 'WorkstationCode' => 'CBACK', 'WorkstationName' => 'Kimia Backup', 'Type' => $vs[1][1], 'LinkTo' => '3', 'Enable' => $vs[2][1], 'CreateDate' => "$now"],
['WorkstationID' => '5', 'DepartmentID' => '3', 'WorkstationCode' => 'CMAN', 'WorkstationName' => 'Kimia Manual', 'Type' => $vs[1][0], 'LinkTo' => '', 'Enable' => $vs[2][1], 'CreateDate' => "$now"],
['WorkstationID' => '6', 'DepartmentID' => '4', 'WorkstationCode' => 'IAUTO', 'WorkstationName' => 'Imunologi Auto', 'Type' => $vs[1][0], 'LinkTo' => '', 'Enable' => $vs[2][1], 'CreateDate' => "$now"],
['WorkstationID' => '7', 'DepartmentID' => '4', 'WorkstationCode' => 'IMAN', 'WorkstationName' => 'Imunologi Manual', 'Type' => $vs[1][0], 'LinkTo' => '', 'Enable' => $vs[2][1], 'CreateDate' => "$now"],
['WorkstationID' => '1', 'DepartmentID' => '1', 'WorkstationCode' => 'HAUTO', 'WorkstationName' => 'Hematologi Auto', 'Type' => '0', 'LinkTo' => '', 'Enable' => '1', 'CreateDate' => "$now"],
['WorkstationID' => '2', 'DepartmentID' => '1', 'WorkstationCode' => 'HBACK', 'WorkstationName' => 'Hematologi Backup', 'Type' => '1', 'LinkTo' => '1', 'Enable' => '1', 'CreateDate' => "$now"],
['WorkstationID' => '3', 'DepartmentID' => '3', 'WorkstationCode' => 'CAUTO', 'WorkstationName' => 'Kimia Auto', 'Type' => '0', 'LinkTo' => '', 'Enable' => '1', 'CreateDate' => "$now"],
['WorkstationID' => '4', 'DepartmentID' => '3', 'WorkstationCode' => 'CBACK', 'WorkstationName' => 'Kimia Backup', 'Type' => '1', 'LinkTo' => '3', 'Enable' => '1', 'CreateDate' => "$now"],
['WorkstationID' => '5', 'DepartmentID' => '3', 'WorkstationCode' => 'CMAN', 'WorkstationName' => 'Kimia Manual', 'Type' => '0', 'LinkTo' => '', 'Enable' => '1', 'CreateDate' => "$now"],
['WorkstationID' => '6', 'DepartmentID' => '4', 'WorkstationCode' => 'IAUTO', 'WorkstationName' => 'Imunologi Auto', 'Type' => '0', 'LinkTo' => '', 'Enable' => '1', 'CreateDate' => "$now"],
['WorkstationID' => '7', 'DepartmentID' => '4', 'WorkstationCode' => 'IMAN', 'WorkstationName' => 'Imunologi Manual', 'Type' => '0', 'LinkTo' => '', 'Enable' => '1', 'CreateDate' => "$now"],
];
$this->db->table('workstation')->insertBatch($data);
}
}

View File

@ -4,15 +4,6 @@ namespace App\Database\Seeds;
use CodeIgniter\Database\Seeder;
/**
* PatientTestSeeder
*
* Seeds test data for Patient-related tables for PHPUnit testing.
* This includes: patient, patatt, patcom, patidt, valueset, areageo
*
* Run with: php spark db:seed PatientTestSeeder
* Or for test DB: php spark db:seed PatientTestSeeder --all --n tests
*/
class PatientSeeder extends Seeder
{
public function run()
@ -20,61 +11,7 @@ class PatientSeeder extends Seeder
$now = date('Y-m-d H:i:s');
// ========================================
// 1. VALUESET - Required for joins
// ========================================
$valuesets = [
// Gender (VSetID = 1)
['VID' => 5, 'SiteID' => 1, 'VSetID' => 1, 'VOrder' => 1, 'VValue' => 'M', 'VDesc' => 'Male', 'CreateDate' => $now],
['VID' => 6, 'SiteID' => 1, 'VSetID' => 1, 'VOrder' => 2, 'VValue' => 'F', 'VDesc' => 'Female', 'CreateDate' => $now],
['VID' => 7, 'SiteID' => 1, 'VSetID' => 1, 'VOrder' => 3, 'VValue' => 'O', 'VDesc' => 'Other', 'CreateDate' => $now],
// Marital Status (VSetID = 3)
['VID' => 8, 'SiteID' => 1, 'VSetID' => 3, 'VOrder' => 1, 'VValue' => 'S', 'VDesc' => 'Single', 'CreateDate' => $now],
['VID' => 9, 'SiteID' => 1, 'VSetID' => 3, 'VOrder' => 2, 'VValue' => 'M', 'VDesc' => 'Married', 'CreateDate' => $now],
['VID' => 10, 'SiteID' => 1, 'VSetID' => 3, 'VOrder' => 3, 'VValue' => 'D', 'VDesc' => 'Divorced', 'CreateDate' => $now],
['VID' => 11, 'SiteID' => 1, 'VSetID' => 3, 'VOrder' => 4, 'VValue' => 'W', 'VDesc' => 'Widowed', 'CreateDate' => $now],
// Death Indicator (VSetID = 4)
['VID' => 16, 'SiteID' => 1, 'VSetID' => 4, 'VOrder' => 1, 'VValue' => 'Y', 'VDesc' => 'Deceased', 'CreateDate' => $now],
['VID' => 17, 'SiteID' => 1, 'VSetID' => 4, 'VOrder' => 2, 'VValue' => 'N', 'VDesc' => 'Alive', 'CreateDate' => $now],
// Race (VSetID = 5)
['VID' => 175, 'SiteID' => 1, 'VSetID' => 5, 'VOrder' => 1, 'VValue' => 'AS', 'VDesc' => 'Asian', 'CreateDate' => $now],
['VID' => 176, 'SiteID' => 1, 'VSetID' => 5, 'VOrder' => 2, 'VValue' => 'WH', 'VDesc' => 'White', 'CreateDate' => $now],
// Religion (VSetID = 6)
['VID' => 206, 'SiteID' => 1, 'VSetID' => 6, 'VOrder' => 1, 'VValue' => 'IS', 'VDesc' => 'Islam', 'CreateDate' => $now],
['VID' => 207, 'SiteID' => 1, 'VSetID' => 6, 'VOrder' => 2, 'VValue' => 'CH', 'VDesc' => 'Christian', 'CreateDate' => $now],
['VID' => 208, 'SiteID' => 1, 'VSetID' => 6, 'VOrder' => 3, 'VValue' => 'CA', 'VDesc' => 'Catholic', 'CreateDate' => $now],
['VID' => 209, 'SiteID' => 1, 'VSetID' => 6, 'VOrder' => 4, 'VValue' => 'HI', 'VDesc' => 'Hindu', 'CreateDate' => $now],
['VID' => 210, 'SiteID' => 1, 'VSetID' => 6, 'VOrder' => 5, 'VValue' => 'BU', 'VDesc' => 'Buddha', 'CreateDate' => $now],
// Ethnic (VSetID = 7)
['VID' => 213, 'SiteID' => 1, 'VSetID' => 7, 'VOrder' => 1, 'VValue' => 'JV', 'VDesc' => 'Javanese', 'CreateDate' => $now],
['VID' => 214, 'SiteID' => 1, 'VSetID' => 7, 'VOrder' => 2, 'VValue' => 'SD', 'VDesc' => 'Sundanese', 'CreateDate' => $now],
['VID' => 215, 'SiteID' => 1, 'VSetID' => 7, 'VOrder' => 3, 'VValue' => 'BT', 'VDesc' => 'Batak', 'CreateDate' => $now],
// Country (VSetID = 8)
['VID' => 221, 'SiteID' => 1, 'VSetID' => 8, 'VOrder' => 1, 'VValue' => 'ID', 'VDesc' => 'Indonesia', 'CreateDate' => $now],
['VID' => 222, 'SiteID' => 1, 'VSetID' => 8, 'VOrder' => 2, 'VValue' => 'MY', 'VDesc' => 'Malaysia', 'CreateDate' => $now],
['VID' => 223, 'SiteID' => 1, 'VSetID' => 8, 'VOrder' => 3, 'VValue' => 'SG', 'VDesc' => 'Singapore', 'CreateDate' => $now],
// Link Type (VSetID = 9)
['VID' => 2, 'SiteID' => 1, 'VSetID' => 9, 'VOrder' => 1, 'VValue' => 'F', 'VDesc' => 'Family', 'CreateDate' => $now],
['VID' => 3, 'SiteID' => 1, 'VSetID' => 9, 'VOrder' => 2, 'VValue' => 'S', 'VDesc' => 'Spouse', 'CreateDate' => $now],
];
// Insert valuesets (ignore duplicates)
foreach ($valuesets as $vs) {
$exists = $this->db->table('valueset')->where('VID', $vs['VID'])->get()->getRow();
if (!$exists) {
$this->db->table('valueset')->insert($vs);
}
}
echo "Valueset data seeded.\n";
// ========================================
// 2. PATIENT - Main patient data
// PATIENT - Main patient data
// ========================================
$patients = [
[
@ -88,7 +25,7 @@ class PatientSeeder extends Seeder
'NameLast' => 'Patient',
'Suffix' => 'S.Kom',
'NameAlias' => 'DummyTest',
'Sex' => 5,
'Sex' => '1',
'PlaceOfBirth' => 'Jakarta',
'Birthdate' => '1990-05-15',
'Street_1' => 'Jl. Sudirman No. 123',
@ -103,13 +40,13 @@ class PatientSeeder extends Seeder
'MobilePhone' => '081234567890',
'Custodian' => null,
'AccountNumber' => null,
'Country' => 221,
'Race' => 175,
'MaritalStatus' => 9,
'Religion' => 206,
'Ethnic' => 213,
'Country' => 'IDN',
'Race' => 'JAWA',
'MaritalStatus' => 'M',
'Religion' => 'ISLAM',
'Ethnic' => 'TNGHA',
'Citizenship' => 'WNI',
'DeathIndicator' => 17,
'DeathIndicator' => 'N',
'TimeOfDeath' => null,
'LinkTo' => null,
'CreateDate' => $now,
@ -126,14 +63,14 @@ class PatientSeeder extends Seeder
'NameLast' => 'Doe',
'Suffix' => null,
'NameAlias' => 'JaneDoe',
'Sex' => 6, // Female
'Sex' => '2',
'PlaceOfBirth' => 'Bandung',
'Birthdate' => '1985-10-20',
'Street_1' => 'Jl. Asia Afrika No. 456',
'Street_2' => 'RT 03 RW 04',
'Street_3' => null,
'City' => '8', // Bandung
'Province' => '7', // Jawa Barat
'City' => '8',
'Province' => '7',
'ZIP' => '40112',
'EmailAddress1' => 'jane.doe@test.com',
'EmailAddress2' => null,
@ -141,13 +78,13 @@ class PatientSeeder extends Seeder
'MobilePhone' => '089876543210',
'Custodian' => null,
'AccountNumber' => null,
'Country' => 221,
'Race' => 175,
'MaritalStatus' => 8, // Single
'Religion' => 207, // Christian
'Ethnic' => 214, // Sundanese
'Country' => 'IDN',
'Race' => 'JAWA',
'MaritalStatus' => 'S',
'Religion' => 'KRSTN',
'Ethnic' => 'TNGHA',
'Citizenship' => 'WNI',
'DeathIndicator' => 17,
'DeathIndicator' => 'N',
'TimeOfDeath' => null,
'LinkTo' => null,
'CreateDate' => $now,
@ -164,7 +101,7 @@ class PatientSeeder extends Seeder
'NameLast' => 'Wijaya',
'Suffix' => null,
'NameAlias' => 'BudiW',
'Sex' => 5,
'Sex' => '1',
'PlaceOfBirth' => 'Surabaya',
'Birthdate' => '2000-01-01',
'Street_1' => 'Jl. Pahlawan No. 789',
@ -179,13 +116,13 @@ class PatientSeeder extends Seeder
'MobilePhone' => '081111222333',
'Custodian' => 1,
'AccountNumber' => null,
'Country' => 221,
'Race' => 175,
'MaritalStatus' => 8,
'Religion' => 206,
'Ethnic' => 213,
'Country' => 'IDN',
'Race' => 'JAWA',
'MaritalStatus' => 'S',
'Religion' => 'ISLAM',
'Ethnic' => 'TNGHA',
'Citizenship' => 'WNI',
'DeathIndicator' => 17,
'DeathIndicator' => 'N',
'TimeOfDeath' => null,
'LinkTo' => '1,2',
'CreateDate' => $now,
@ -202,7 +139,7 @@ class PatientSeeder extends Seeder
echo "Patient data seeded (3 patients).\n";
// ========================================
// 4. PATIDT - Patient Identifiers (KTP, etc.)
// PATIDT - Patient Identifiers (KTP, etc.)
// ========================================
$patidts = [
[
@ -236,7 +173,7 @@ class PatientSeeder extends Seeder
echo "PatIdt data seeded (2 identifiers).\n";
// ========================================
// 5. PATATT - Patient Attachments
// PATATT - Patient Attachments
// ========================================
$patatts = [
[
@ -274,7 +211,7 @@ class PatientSeeder extends Seeder
echo "PatAtt data seeded (3 attachments).\n";
// ========================================
// 6. PATCOM - Patient Comments
// PATCOM - Patient Comments
// ========================================
$patcoms = [
[

View File

@ -3,177 +3,184 @@
namespace App\Database\Seeds;
use CodeIgniter\Database\Seeder;
use App\Models\ValueSet\ValueSetModel;
use App\Libraries\ValueSet;
class TestSeeder extends Seeder {
public function run() {
$now = date('Y-m-d H:i:s');
$vsModel = new ValueSetModel();
$rows = $vsModel->select("VID, VSetID, VValue")->findAll();
$vs = [];
foreach ($rows as $row) {
$vs[$row['VSetID']][$row['VValue']] = $row['VID'];
class TestSeeder extends Seeder
{
private function getKey(string $lookupName, string $key): ?string
{
$data = ValueSet::getRaw($lookupName);
if ($data === null) return null;
foreach ($data as $item) {
if (($item['key'] ?? '') === $key) {
return $item['key'];
}
}
return null;
}
$tIDs = []; // Array to store Test IDs for grouping
public function run()
{
$now = date('Y-m-d H:i:s');
$tIDs = [];
// ========================================
// TEST TYPE - Actual Laboratory Tests
// ========================================
// Hematology Tests
$data = ['SiteID' => '1', 'TestSiteCode' => 'HB', 'TestSiteName' => 'Hemoglobin', 'TestType' => $vs[27]['TEST'], 'Description' => '', 'SeqScr' => '2', 'SeqRpt' => '2', 'IndentLeft' => '1', 'VisibleScr' => $vs[2][1], 'VisibleRpt' => $vs[2][1], 'CountStat' => $vs[2][1], 'CreateDate' => "$now"];
$data = ['SiteID' => '1', 'TestSiteCode' => 'HB', 'TestSiteName' => 'Hemoglobin', 'TestType' => 'TEST', 'Description' => '', 'SeqScr' => '2', 'SeqRpt' => '2', 'IndentLeft' => '1', 'VisibleScr' => '1', 'VisibleRpt' => '1', 'CountStat' => '1', 'CreateDate' => "$now"];
$this->db->table('testdefsite')->insert($data);
$tIDs['HB'] = $this->db->insertID();
$data = ['TestSiteID' => $tIDs['HB'], 'DisciplineID' => '1', 'DepartmentID' => '1', 'ResultType' => $vs[43]['NMRIC'], 'RefType' => $vs[44]['NMRC'], 'VSet' => '', 'ReqQty' => '500', 'ReqQtyUnit' => 'uL', 'Unit1' => 'g/dL', 'Factor' => '', 'Unit2' => '', 'Decimal' => '1', 'Method' => 'CBC Analyzer', 'CreateDate' => "$now"];
$data = ['TestSiteID' => $tIDs['HB'], 'DisciplineID' => '1', 'DepartmentID' => '1', 'ResultType' => 'NMRIC', 'RefType' => 'NMRC', 'VSet' => '', 'ReqQty' => '500', 'ReqQtyUnit' => 'uL', 'Unit1' => 'g/dL', 'Factor' => '', 'Unit2' => '', 'Decimal' => '1', 'Method' => 'CBC Analyzer', 'CreateDate' => "$now"];
$this->db->table('testdeftech')->insert($data);
$data = ['SiteID' => '1', 'TestSiteCode' => 'HCT', 'TestSiteName' => 'Hematocrit', 'TestType' => $vs[27]['TEST'], 'Description' => '', 'SeqScr' => '3', 'SeqRpt' => '3', 'IndentLeft' => '1', 'VisibleScr' => $vs[2][1], 'VisibleRpt' => $vs[2][1], 'CountStat' => $vs[2][1], 'CreateDate' => "$now"];
$data = ['SiteID' => '1', 'TestSiteCode' => 'HCT', 'TestSiteName' => 'Hematocrit', 'TestType' => 'TEST', 'Description' => '', 'SeqScr' => '3', 'SeqRpt' => '3', 'IndentLeft' => '1', 'VisibleScr' => '1', 'VisibleRpt' => '1', 'CountStat' => '1', 'CreateDate' => "$now"];
$this->db->table('testdefsite')->insert($data);
$tIDs['HCT'] = $this->db->insertID();
$data = ['TestSiteID' => $tIDs['HCT'], 'DisciplineID' => '1', 'DepartmentID' => '1', 'ResultType' => $vs[43]['NMRIC'], 'RefType' => $vs[44]['NMRC'], 'VSet' => '', 'ReqQty' => '500', 'ReqQtyUnit' => 'uL', 'Unit1' => '%', 'Factor' => '', 'Unit2' => '', 'Decimal' => '1', 'Method' => 'CBC Analyzer', 'CreateDate' => "$now"];
$data = ['TestSiteID' => $tIDs['HCT'], 'DisciplineID' => '1', 'DepartmentID' => '1', 'ResultType' => 'NMRIC', 'RefType' => 'NMRC', 'VSet' => '', 'ReqQty' => '500', 'ReqQtyUnit' => 'uL', 'Unit1' => '%', 'Factor' => '', 'Unit2' => '', 'Decimal' => '1', 'Method' => 'CBC Analyzer', 'CreateDate' => "$now"];
$this->db->table('testdeftech')->insert($data);
$data = ['SiteID' => '1', 'TestSiteCode' => 'RBC', 'TestSiteName' => 'Red Blood Cell', 'TestType' => $vs[27]['TEST'], 'Description' => 'Eritrosit', 'SeqScr' => '4', 'SeqRpt' => '4', 'IndentLeft' => '1', 'VisibleScr' => $vs[2][1], 'VisibleRpt' => $vs[2][1], 'CountStat' => $vs[2][1], 'CreateDate' => "$now"];
$data = ['SiteID' => '1', 'TestSiteCode' => 'RBC', 'TestSiteName' => 'Red Blood Cell', 'TestType' => 'TEST', 'Description' => 'Eritrosit', 'SeqScr' => '4', 'SeqRpt' => '4', 'IndentLeft' => '1', 'VisibleScr' => '1', 'VisibleRpt' => '1', 'CountStat' => '1', 'CreateDate' => "$now"];
$this->db->table('testdefsite')->insert($data);
$tIDs['RBC'] = $this->db->insertID();
$data = ['TestSiteID' => $tIDs['RBC'], 'DisciplineID' => '1', 'DepartmentID' => '1', 'ResultType' => $vs[43]['NMRIC'], 'RefType' => $vs[44]['NMRC'], 'VSet' => '', 'ReqQty' => '500', 'ReqQtyUnit' => 'uL', 'Unit1' => 'x10^6/uL', 'Factor' => '', 'Unit2' => '', 'Decimal' => '2', 'Method' => 'CBC Analyzer', 'CreateDate' => "$now"];
$data = ['TestSiteID' => $tIDs['RBC'], 'DisciplineID' => '1', 'DepartmentID' => '1', 'ResultType' => 'NMRIC', 'RefType' => 'NMRC', 'VSet' => '', 'ReqQty' => '500', 'ReqQtyUnit' => 'uL', 'Unit1' => 'x10^6/uL', 'Factor' => '', 'Unit2' => '', 'Decimal' => '2', 'Method' => 'CBC Analyzer', 'CreateDate' => "$now"];
$this->db->table('testdeftech')->insert($data);
$data = ['SiteID' => '1', 'TestSiteCode' => 'WBC', 'TestSiteName' => 'White Blood Cell', 'TestType' => $vs[27]['TEST'], 'Description' => 'Leukosit', 'SeqScr' => '5', 'SeqRpt' => '5', 'IndentLeft' => '1', 'VisibleScr' => $vs[2][1], 'VisibleRpt' => $vs[2][1], 'CountStat' => $vs[2][1], 'CreateDate' => "$now"];
$data = ['SiteID' => '1', 'TestSiteCode' => 'WBC', 'TestSiteName' => 'White Blood Cell', 'TestType' => 'TEST', 'Description' => 'Leukosit', 'SeqScr' => '5', 'SeqRpt' => '5', 'IndentLeft' => '1', 'VisibleScr' => '1', 'VisibleRpt' => '1', 'CountStat' => '1', 'CreateDate' => "$now"];
$this->db->table('testdefsite')->insert($data);
$tIDs['WBC'] = $this->db->insertID();
$data = ['TestSiteID' => $tIDs['WBC'], 'DisciplineID' => '1', 'DepartmentID' => '1', 'ResultType' => $vs[43]['NMRIC'], 'RefType' => $vs[44]['NMRC'], 'VSet' => '', 'ReqQty' => '500', 'ReqQtyUnit' => 'uL', 'Unit1' => 'x10^3/uL', 'Factor' => '', 'Unit2' => '', 'Decimal' => '2', 'Method' => 'CBC Analyzer', 'CreateDate' => "$now"];
$data = ['TestSiteID' => $tIDs['WBC'], 'DisciplineID' => '1', 'DepartmentID' => '1', 'ResultType' => 'NMRIC', 'RefType' => 'NMRC', 'VSet' => '', 'ReqQty' => '500', 'ReqQtyUnit' => 'uL', 'Unit1' => 'x10^3/uL', 'Factor' => '', 'Unit2' => '', 'Decimal' => '2', 'Method' => 'CBC Analyzer', 'CreateDate' => "$now"];
$this->db->table('testdeftech')->insert($data);
$data = ['SiteID' => '1', 'TestSiteCode' => 'PLT', 'TestSiteName' => 'Platelet', 'TestType' => $vs[27]['TEST'], 'Description' => 'Trombosit', 'SeqScr' => '6', 'SeqRpt' => '6', 'IndentLeft' => '1', 'VisibleScr' => $vs[2][1], 'VisibleRpt' => $vs[2][1], 'CountStat' => $vs[2][1], 'CreateDate' => "$now"];
$data = ['SiteID' => '1', 'TestSiteCode' => 'PLT', 'TestSiteName' => 'Platelet', 'TestType' => 'TEST', 'Description' => 'Trombosit', 'SeqScr' => '6', 'SeqRpt' => '6', 'IndentLeft' => '1', 'VisibleScr' => '1', 'VisibleRpt' => '1', 'CountStat' => '1', 'CreateDate' => "$now"];
$this->db->table('testdefsite')->insert($data);
$tIDs['PLT'] = $this->db->insertID();
$data = ['TestSiteID' => $tIDs['PLT'], 'DisciplineID' => '1', 'DepartmentID' => '1', 'ResultType' => $vs[43]['NMRIC'], 'RefType' => $vs[44]['NMRC'], 'VSet' => '', 'ReqQty' => '500', 'ReqQtyUnit' => 'uL', 'Unit1' => 'x10^3/uL', 'Factor' => '', 'Unit2' => '', 'Decimal' => '0', 'Method' => 'CBC Analyzer', 'CreateDate' => "$now"];
$data = ['TestSiteID' => $tIDs['PLT'], 'DisciplineID' => '1', 'DepartmentID' => '1', 'ResultType' => 'NMRIC', 'RefType' => 'NMRC', 'VSet' => '', 'ReqQty' => '500', 'ReqQtyUnit' => 'uL', 'Unit1' => 'x10^3/uL', 'Factor' => '', 'Unit2' => '', 'Decimal' => '0', 'Method' => 'CBC Analyzer', 'CreateDate' => "$now"];
$this->db->table('testdeftech')->insert($data);
$data = ['SiteID' => '1', 'TestSiteCode' => 'MCV', 'TestSiteName' => 'MCV', 'TestType' => $vs[27]['TEST'], 'Description' => 'Mean Corpuscular Volume', 'SeqScr' => '7', 'SeqRpt' => '7', 'IndentLeft' => '1', 'VisibleScr' => $vs[2][1], 'VisibleRpt' => $vs[2][1], 'CountStat' => $vs[2][1], 'CreateDate' => "$now"];
$data = ['SiteID' => '1', 'TestSiteCode' => 'MCV', 'TestSiteName' => 'MCV', 'TestType' => 'TEST', 'Description' => 'Mean Corpuscular Volume', 'SeqScr' => '7', 'SeqRpt' => '7', 'IndentLeft' => '1', 'VisibleScr' => '1', 'VisibleRpt' => '1', 'CountStat' => '1', 'CreateDate' => "$now"];
$this->db->table('testdefsite')->insert($data);
$tIDs['MCV'] = $this->db->insertID();
$data = ['TestSiteID' => $tIDs['MCV'], 'DisciplineID' => '1', 'DepartmentID' => '1', 'ResultType' => $vs[43]['NMRIC'], 'RefType' => $vs[44]['NMRC'], 'VSet' => '', 'ReqQty' => '500', 'ReqQtyUnit' => 'uL', 'Unit1' => 'fL', 'Factor' => '', 'Unit2' => '', 'Decimal' => '1', 'Method' => 'CBC Analyzer', 'CreateDate' => "$now"];
$data = ['TestSiteID' => $tIDs['MCV'], 'DisciplineID' => '1', 'DepartmentID' => '1', 'ResultType' => 'NMRIC', 'RefType' => 'NMRC', 'VSet' => '', 'ReqQty' => '500', 'ReqQtyUnit' => 'uL', 'Unit1' => 'fL', 'Factor' => '', 'Unit2' => '', 'Decimal' => '1', 'Method' => 'CBC Analyzer', 'CreateDate' => "$now"];
$this->db->table('testdeftech')->insert($data);
$data = ['SiteID' => '1', 'TestSiteCode' => 'MCH', 'TestSiteName' => 'MCH', 'TestType' => $vs[27]['TEST'], 'Description' => 'Mean Corpuscular Hemoglobin', 'SeqScr' => '8', 'SeqRpt' => '8', 'IndentLeft' => '1', 'VisibleScr' => $vs[2][1], 'VisibleRpt' => $vs[2][1], 'CountStat' => $vs[2][1], 'CreateDate' => "$now"];
$data = ['SiteID' => '1', 'TestSiteCode' => 'MCH', 'TestSiteName' => 'MCH', 'TestType' => 'TEST', 'Description' => 'Mean Corpuscular Hemoglobin', 'SeqScr' => '8', 'SeqRpt' => '8', 'IndentLeft' => '1', 'VisibleScr' => '1', 'VisibleRpt' => '1', 'CountStat' => '1', 'CreateDate' => "$now"];
$this->db->table('testdefsite')->insert($data);
$tIDs['MCH'] = $this->db->insertID();
$data = ['TestSiteID' => $tIDs['MCH'], 'DisciplineID' => '1', 'DepartmentID' => '1', 'ResultType' => $vs[43]['NMRIC'], 'RefType' => $vs[44]['NMRC'], 'VSet' => '', 'ReqQty' => '500', 'ReqQtyUnit' => 'uL', 'Unit1' => 'pg', 'Factor' => '', 'Unit2' => '', 'Decimal' => '1', 'Method' => 'CBC Analyzer', 'CreateDate' => "$now"];
$data = ['TestSiteID' => $tIDs['MCH'], 'DisciplineID' => '1', 'DepartmentID' => '1', 'ResultType' => 'NMRIC', 'RefType' => 'NMRC', 'VSet' => '', 'ReqQty' => '500', 'ReqQtyUnit' => 'uL', 'Unit1' => 'pg', 'Factor' => '', 'Unit2' => '', 'Decimal' => '1', 'Method' => 'CBC Analyzer', 'CreateDate' => "$now"];
$this->db->table('testdeftech')->insert($data);
$data = ['SiteID' => '1', 'TestSiteCode' => 'MCHC', 'TestSiteName' => 'MCHC', 'TestType' => $vs[27]['TEST'], 'Description' => 'Mean Corpuscular Hemoglobin Concentration', 'SeqScr' => '9', 'SeqRpt' => '9', 'IndentLeft' => '1', 'VisibleScr' => $vs[2][1], 'VisibleRpt' => $vs[2][1], 'CountStat' => $vs[2][1], 'CreateDate' => "$now"];
$data = ['SiteID' => '1', 'TestSiteCode' => 'MCHC', 'TestSiteName' => 'MCHC', 'TestType' => 'TEST', 'Description' => 'Mean Corpuscular Hemoglobin Concentration', 'SeqScr' => '9', 'SeqRpt' => '9', 'IndentLeft' => '1', 'VisibleScr' => '1', 'VisibleRpt' => '1', 'CountStat' => '1', 'CreateDate' => "$now"];
$this->db->table('testdefsite')->insert($data);
$tIDs['MCHC'] = $this->db->insertID();
$data = ['TestSiteID' => $tIDs['MCHC'], 'DisciplineID' => '1', 'DepartmentID' => '1', 'ResultType' => $vs[43]['NMRIC'], 'RefType' => $vs[44]['NMRC'], 'VSet' => '', 'ReqQty' => '500', 'ReqQtyUnit' => 'uL', 'Unit1' => 'g/dL', 'Factor' => '', 'Unit2' => '', 'Decimal' => '1', 'Method' => 'CBC Analyzer', 'CreateDate' => "$now"];
$data = ['TestSiteID' => $tIDs['MCHC'], 'DisciplineID' => '1', 'DepartmentID' => '1', 'ResultType' => 'NMRIC', 'RefType' => 'NMRC', 'VSet' => '', 'ReqQty' => '500', 'ReqQtyUnit' => 'uL', 'Unit1' => 'g/dL', 'Factor' => '', 'Unit2' => '', 'Decimal' => '1', 'Method' => 'CBC Analyzer', 'CreateDate' => "$now"];
$this->db->table('testdeftech')->insert($data);
// Chemistry Tests
$data = ['SiteID' => '1', 'TestSiteCode' => 'GLU', 'TestSiteName' => 'Glucose', 'TestType' => $vs[27]['TEST'], 'Description' => 'Glukosa Sewaktu', 'SeqScr' => '11', 'SeqRpt' => '11', 'IndentLeft' => '1', 'VisibleScr' => $vs[2][1], 'VisibleRpt' => $vs[2][1], 'CountStat' => $vs[2][1], 'CreateDate' => "$now"];
$data = ['SiteID' => '1', 'TestSiteCode' => 'GLU', 'TestSiteName' => 'Glucose', 'TestType' => 'TEST', 'Description' => 'Glukosa Sewaktu', 'SeqScr' => '11', 'SeqRpt' => '11', 'IndentLeft' => '1', 'VisibleScr' => '1', 'VisibleRpt' => '1', 'CountStat' => '1', 'CreateDate' => "$now"];
$this->db->table('testdefsite')->insert($data);
$tIDs['GLU'] = $this->db->insertID();
$data = ['TestSiteID' => $tIDs['GLU'], 'DisciplineID' => '2', 'DepartmentID' => '2', 'ResultType' => $vs[43]['NMRIC'], 'RefType' => $vs[44]['NMRC'], 'VSet' => '', 'ReqQty' => '300', 'ReqQtyUnit' => 'uL', 'Unit1' => 'mg/dL', 'Factor' => '0.0555', 'Unit2' => 'mmol/L', 'Decimal' => '0', 'Method' => 'Hexokinase', 'CreateDate' => "$now"];
$data = ['TestSiteID' => $tIDs['GLU'], 'DisciplineID' => '2', 'DepartmentID' => '2', 'ResultType' => 'NMRIC', 'RefType' => 'NMRC', 'VSet' => '', 'ReqQty' => '300', 'ReqQtyUnit' => 'uL', 'Unit1' => 'mg/dL', 'Factor' => '0.0555', 'Unit2' => 'mmol/L', 'Decimal' => '0', 'Method' => 'Hexokinase', 'CreateDate' => "$now"];
$this->db->table('testdeftech')->insert($data);
$data = ['SiteID' => '1', 'TestSiteCode' => 'CREA', 'TestSiteName' => 'Creatinine', 'TestType' => $vs[27]['TEST'], 'Description' => 'Kreatinin', 'SeqScr' => '12', 'SeqRpt' => '12', 'IndentLeft' => '1', 'VisibleScr' => $vs[2][1], 'VisibleRpt' => $vs[2][1], 'CountStat' => $vs[2][1], 'CreateDate' => "$now"];
$data = ['SiteID' => '1', 'TestSiteCode' => 'CREA', 'TestSiteName' => 'Creatinine', 'TestType' => 'TEST', 'Description' => 'Kreatinin', 'SeqScr' => '12', 'SeqRpt' => '12', 'IndentLeft' => '1', 'VisibleScr' => '1', 'VisibleRpt' => '1', 'CountStat' => '1', 'CreateDate' => "$now"];
$this->db->table('testdefsite')->insert($data);
$tIDs['CREA'] = $this->db->insertID();
$data = ['TestSiteID' => $tIDs['CREA'], 'DisciplineID' => '2', 'DepartmentID' => '2', 'ResultType' => $vs[43]['NMRIC'], 'RefType' => $vs[44]['NMRC'], 'VSet' => '', 'ReqQty' => '300', 'ReqQtyUnit' => 'uL', 'Unit1' => 'mg/dL', 'Factor' => '88.4', 'Unit2' => 'umol/L', 'Decimal' => '2', 'Method' => 'Enzymatic', 'CreateDate' => "$now"];
$data = ['TestSiteID' => $tIDs['CREA'], 'DisciplineID' => '2', 'DepartmentID' => '2', 'ResultType' => 'NMRIC', 'RefType' => 'NMRC', 'VSet' => '', 'ReqQty' => '300', 'ReqQtyUnit' => 'uL', 'Unit1' => 'mg/dL', 'Factor' => '88.4', 'Unit2' => 'umol/L', 'Decimal' => '2', 'Method' => 'Enzymatic', 'CreateDate' => "$now"];
$this->db->table('testdeftech')->insert($data);
$data = ['SiteID' => '1', 'TestSiteCode' => 'UREA', 'TestSiteName' => 'Blood Urea Nitrogen', 'TestType' => $vs[27]['TEST'], 'Description' => 'BUN', 'SeqScr' => '13', 'SeqRpt' => '13', 'IndentLeft' => '1', 'VisibleScr' => $vs[2][1], 'VisibleRpt' => $vs[2][1], 'CountStat' => $vs[2][1], 'CreateDate' => "$now"];
$data = ['SiteID' => '1', 'TestSiteCode' => 'UREA', 'TestSiteName' => 'Blood Urea Nitrogen', 'TestType' => 'TEST', 'Description' => 'BUN', 'SeqScr' => '13', 'SeqRpt' => '13', 'IndentLeft' => '1', 'VisibleScr' => '1', 'VisibleRpt' => '1', 'CountStat' => '1', 'CreateDate' => "$now"];
$this->db->table('testdefsite')->insert($data);
$tIDs['UREA'] = $this->db->insertID();
$data = ['TestSiteID' => $tIDs['UREA'], 'DisciplineID' => '2', 'DepartmentID' => '2', 'ResultType' => $vs[43]['NMRIC'], 'RefType' => $vs[44]['NMRC'], 'VSet' => '', 'ReqQty' => '300', 'ReqQtyUnit' => 'uL', 'Unit1' => 'mg/dL', 'Factor' => '', 'Unit2' => '', 'Decimal' => '1', 'Method' => 'Urease-GLDH', 'CreateDate' => "$now"];
$data = ['TestSiteID' => $tIDs['UREA'], 'DisciplineID' => '2', 'DepartmentID' => '2', 'ResultType' => 'NMRIC', 'RefType' => 'NMRC', 'VSet' => '', 'ReqQty' => '300', 'ReqQtyUnit' => 'uL', 'Unit1' => 'mg/dL', 'Factor' => '', 'Unit2' => '', 'Decimal' => '1', 'Method' => 'Urease-GLDH', 'CreateDate' => "$now"];
$this->db->table('testdeftech')->insert($data);
$data = ['SiteID' => '1', 'TestSiteCode' => 'SGOT', 'TestSiteName' => 'AST (SGOT)', 'TestType' => $vs[27]['TEST'], 'Description' => 'Aspartate Aminotransferase', 'SeqScr' => '14', 'SeqRpt' => '14', 'IndentLeft' => '1', 'VisibleScr' => $vs[2][1], 'VisibleRpt' => $vs[2][1], 'CountStat' => $vs[2][1], 'CreateDate' => "$now"];
$data = ['SiteID' => '1', 'TestSiteCode' => 'SGOT', 'TestSiteName' => 'AST (SGOT)', 'TestType' => 'TEST', 'Description' => 'Aspartate Aminotransferase', 'SeqScr' => '14', 'SeqRpt' => '14', 'IndentLeft' => '1', 'VisibleScr' => '1', 'VisibleRpt' => '1', 'CountStat' => '1', 'CreateDate' => "$now"];
$this->db->table('testdefsite')->insert($data);
$tIDs['SGOT'] = $this->db->insertID();
$data = ['TestSiteID' => $tIDs['SGOT'], 'DisciplineID' => '2', 'DepartmentID' => '2', 'ResultType' => $vs[43]['NMRIC'], 'RefType' => $vs[44]['NMRC'], 'VSet' => '', 'ReqQty' => '300', 'ReqQtyUnit' => 'uL', 'Unit1' => 'U/L', 'Factor' => '0.017', 'Unit2' => 'ukat/L', 'Decimal' => '0', 'Method' => 'IFCC', 'CreateDate' => "$now"];
$data = ['TestSiteID' => $tIDs['SGOT'], 'DisciplineID' => '2', 'DepartmentID' => '2', 'ResultType' => 'NMRIC', 'RefType' => 'NMRC', 'VSet' => '', 'ReqQty' => '300', 'ReqQtyUnit' => 'uL', 'Unit1' => 'U/L', 'Factor' => '0.017', 'Unit2' => 'ukat/L', 'Decimal' => '0', 'Method' => 'IFCC', 'CreateDate' => "$now"];
$this->db->table('testdeftech')->insert($data);
$data = ['SiteID' => '1', 'TestSiteCode' => 'SGPT', 'TestSiteName' => 'ALT (SGPT)', 'TestType' => $vs[27]['TEST'], 'Description' => 'Alanine Aminotransferase', 'SeqScr' => '15', 'SeqRpt' => '15', 'IndentLeft' => '1', 'VisibleScr' => $vs[2][1], 'VisibleRpt' => $vs[2][1], 'CountStat' => $vs[2][1], 'CreateDate' => "$now"];
$data = ['SiteID' => '1', 'TestSiteCode' => 'SGPT', 'TestSiteName' => 'ALT (SGPT)', 'TestType' => 'TEST', 'Description' => 'Alanine Aminotransferase', 'SeqScr' => '15', 'SeqRpt' => '15', 'IndentLeft' => '1', 'VisibleScr' => '1', 'VisibleRpt' => '1', 'CountStat' => '1', 'CreateDate' => "$now"];
$this->db->table('testdefsite')->insert($data);
$tIDs['SGPT'] = $this->db->insertID();
$data = ['TestSiteID' => $tIDs['SGPT'], 'DisciplineID' => '2', 'DepartmentID' => '2', 'ResultType' => $vs[43]['NMRIC'], 'RefType' => $vs[44]['NMRC'], 'VSet' => '', 'ReqQty' => '300', 'ReqQtyUnit' => 'uL', 'Unit1' => 'U/L', 'Factor' => '0.017', 'Unit2' => 'ukat/L', 'Decimal' => '0', 'Method' => 'IFCC', 'CreateDate' => "$now"];
$data = ['TestSiteID' => $tIDs['SGPT'], 'DisciplineID' => '2', 'DepartmentID' => '2', 'ResultType' => 'NMRIC', 'RefType' => 'NMRC', 'VSet' => '', 'ReqQty' => '300', 'ReqQtyUnit' => 'uL', 'Unit1' => 'U/L', 'Factor' => '0.017', 'Unit2' => 'ukat/L', 'Decimal' => '0', 'Method' => 'IFCC', 'CreateDate' => "$now"];
$this->db->table('testdeftech')->insert($data);
$data = ['SiteID' => '1', 'TestSiteCode' => 'CHOL', 'TestSiteName' => 'Total Cholesterol', 'TestType' => $vs[27]['TEST'], 'Description' => 'Kolesterol Total', 'SeqScr' => '16', 'SeqRpt' => '16', 'IndentLeft' => '1', 'VisibleScr' => $vs[2][1], 'VisibleRpt' => $vs[2][1], 'CountStat' => $vs[2][1], 'CreateDate' => "$now"];
$data = ['SiteID' => '1', 'TestSiteCode' => 'CHOL', 'TestSiteName' => 'Total Cholesterol', 'TestType' => 'TEST', 'Description' => 'Kolesterol Total', 'SeqScr' => '16', 'SeqRpt' => '16', 'IndentLeft' => '1', 'VisibleScr' => '1', 'VisibleRpt' => '1', 'CountStat' => '1', 'CreateDate' => "$now"];
$this->db->table('testdefsite')->insert($data);
$tIDs['CHOL'] = $this->db->insertID();
$data = ['TestSiteID' => $tIDs['CHOL'], 'DisciplineID' => '2', 'DepartmentID' => '2', 'ResultType' => $vs[43]['NMRIC'], 'RefType' => $vs[44]['NMRC'], 'VSet' => '', 'ReqQty' => '300', 'ReqQtyUnit' => 'uL', 'Unit1' => 'mg/dL', 'Factor' => '', 'Unit2' => '', 'Decimal' => '0', 'Method' => 'Enzymatic', 'CreateDate' => "$now"];
$data = ['TestSiteID' => $tIDs['CHOL'], 'DisciplineID' => '2', 'DepartmentID' => '2', 'ResultType' => 'NMRIC', 'RefType' => 'NMRC', 'VSet' => '', 'ReqQty' => '300', 'ReqQtyUnit' => 'uL', 'Unit1' => 'mg/dL', 'Factor' => '', 'Unit2' => '', 'Decimal' => '0', 'Method' => 'Enzymatic', 'CreateDate' => "$now"];
$this->db->table('testdeftech')->insert($data);
$data = ['SiteID' => '1', 'TestSiteCode' => 'TG', 'TestSiteName' => 'Triglycerides', 'TestType' => $vs[27]['TEST'], 'Description' => 'Trigliserida', 'SeqScr' => '17', 'SeqRpt' => '17', 'IndentLeft' => '1', 'VisibleScr' => $vs[2][1], 'VisibleRpt' => $vs[2][1], 'CountStat' => $vs[2][1], 'CreateDate' => "$now"];
$data = ['SiteID' => '1', 'TestSiteCode' => 'TG', 'TestSiteName' => 'Triglycerides', 'TestType' => 'TEST', 'Description' => 'Trigliserida', 'SeqScr' => '17', 'SeqRpt' => '17', 'IndentLeft' => '1', 'VisibleScr' => '1', 'VisibleRpt' => '1', 'CountStat' => '1', 'CreateDate' => "$now"];
$this->db->table('testdefsite')->insert($data);
$tIDs['TG'] = $this->db->insertID();
$data = ['TestSiteID' => $tIDs['TG'], 'DisciplineID' => '2', 'DepartmentID' => '2', 'ResultType' => $vs[43]['NMRIC'], 'RefType' => $vs[44]['NMRC'], 'VSet' => '', 'ReqQty' => '300', 'ReqQtyUnit' => 'uL', 'Unit1' => 'mg/dL', 'Factor' => '', 'Unit2' => '', 'Decimal' => '0', 'Method' => 'GPO-PAP', 'CreateDate' => "$now"];
$data = ['TestSiteID' => $tIDs['TG'], 'DisciplineID' => '2', 'DepartmentID' => '2', 'ResultType' => 'NMRIC', 'RefType' => 'NMRC', 'VSet' => '', 'ReqQty' => '300', 'ReqQtyUnit' => 'uL', 'Unit1' => 'mg/dL', 'Factor' => '', 'Unit2' => '', 'Decimal' => '0', 'Method' => 'GPO-PAP', 'CreateDate' => "$now"];
$this->db->table('testdeftech')->insert($data);
$data = ['SiteID' => '1', 'TestSiteCode' => 'HDL', 'TestSiteName' => 'HDL Cholesterol', 'TestType' => $vs[27]['TEST'], 'Description' => 'Kolesterol HDL', 'SeqScr' => '18', 'SeqRpt' => '18', 'IndentLeft' => '1', 'VisibleScr' => $vs[2][1], 'VisibleRpt' => $vs[2][1], 'CountStat' => $vs[2][1], 'CreateDate' => "$now"];
$data = ['SiteID' => '1', 'TestSiteCode' => 'HDL', 'TestSiteName' => 'HDL Cholesterol', 'TestType' => 'TEST', 'Description' => 'Kolesterol HDL', 'SeqScr' => '18', 'SeqRpt' => '18', 'IndentLeft' => '1', 'VisibleScr' => '1', 'VisibleRpt' => '1', 'CountStat' => '1', 'CreateDate' => "$now"];
$this->db->table('testdefsite')->insert($data);
$tIDs['HDL'] = $this->db->insertID();
$data = ['TestSiteID' => $tIDs['HDL'], 'DisciplineID' => '2', 'DepartmentID' => '2', 'ResultType' => $vs[43]['NMRIC'], 'RefType' => $vs[44]['NMRC'], 'VSet' => '', 'ReqQty' => '300', 'ReqQtyUnit' => 'uL', 'Unit1' => 'mg/dL', 'Factor' => '', 'Unit2' => '', 'Decimal' => '0', 'Method' => 'Direct', 'CreateDate' => "$now"];
$data = ['TestSiteID' => $tIDs['HDL'], 'DisciplineID' => '2', 'DepartmentID' => '2', 'ResultType' => 'NMRIC', 'RefType' => 'NMRC', 'VSet' => '', 'ReqQty' => '300', 'ReqQtyUnit' => 'uL', 'Unit1' => 'mg/dL', 'Factor' => '', 'Unit2' => '', 'Decimal' => '0', 'Method' => 'Direct', 'CreateDate' => "$now"];
$this->db->table('testdeftech')->insert($data);
$data = ['SiteID' => '1', 'TestSiteCode' => 'LDL', 'TestSiteName' => 'LDL Cholesterol', 'TestType' => $vs[27]['TEST'], 'Description' => 'Kolesterol LDL', 'SeqScr' => '19', 'SeqRpt' => '19', 'IndentLeft' => '1', 'VisibleScr' => $vs[2][1], 'VisibleRpt' => $vs[2][1], 'CountStat' => $vs[2][1], 'CreateDate' => "$now"];
$data = ['SiteID' => '1', 'TestSiteCode' => 'LDL', 'TestSiteName' => 'LDL Cholesterol', 'TestType' => 'TEST', 'Description' => 'Kolesterol LDL', 'SeqScr' => '19', 'SeqRpt' => '19', 'IndentLeft' => '1', 'VisibleScr' => '1', 'VisibleRpt' => '1', 'CountStat' => '1', 'CreateDate' => "$now"];
$this->db->table('testdefsite')->insert($data);
$tIDs['LDL'] = $this->db->insertID();
$data = ['TestSiteID' => $tIDs['LDL'], 'DisciplineID' => '2', 'DepartmentID' => '2', 'ResultType' => $vs[43]['NMRIC'], 'RefType' => $vs[44]['NMRC'], 'VSet' => '', 'ReqQty' => '300', 'ReqQtyUnit' => 'uL', 'Unit1' => 'mg/dL', 'Factor' => '', 'Unit2' => '', 'Decimal' => '0', 'Method' => 'Direct', 'CreateDate' => "$now"];
$data = ['TestSiteID' => $tIDs['LDL'], 'DisciplineID' => '2', 'DepartmentID' => '2', 'ResultType' => 'NMRIC', 'RefType' => 'NMRC', 'VSet' => '', 'ReqQty' => '300', 'ReqQtyUnit' => 'uL', 'Unit1' => 'mg/dL', 'Factor' => '', 'Unit2' => '', 'Decimal' => '0', 'Method' => 'Direct', 'CreateDate' => "$now"];
$this->db->table('testdeftech')->insert($data);
// ========================================
// PARAM TYPE - Parameters (non-lab values)
// ========================================
$data = ['SiteID' => '1', 'TestSiteCode' => 'HEIGHT', 'TestSiteName' => 'Height', 'TestType' => $vs[27]['PARAM'], 'Description' => 'Tinggi Badan', 'SeqScr' => '40', 'SeqRpt' => '40', 'IndentLeft' => '0', 'VisibleScr' => $vs[2][1], 'VisibleRpt' => $vs[2][0], 'CountStat' => $vs[2][0], 'CreateDate' => "$now"];
$data = ['SiteID' => '1', 'TestSiteCode' => 'HEIGHT', 'TestSiteName' => 'Height', 'TestType' => 'PARAM', 'Description' => 'Tinggi Badan', 'SeqScr' => '40', 'SeqRpt' => '40', 'IndentLeft' => '0', 'VisibleScr' => '1', 'VisibleRpt' => '0', 'CountStat' => '0', 'CreateDate' => "$now"];
$this->db->table('testdefsite')->insert($data);
$tIDs['HEIGHT'] = $this->db->insertID();
$data = ['TestSiteID' => $tIDs['HEIGHT'], 'DisciplineID' => '10', 'DepartmentID' => '', 'ResultType' => $vs[43]['NMRIC'], 'RefType' => '', 'VSet' => '', 'ReqQty' => '', 'ReqQtyUnit' => '', 'Unit1' => 'cm', 'Factor' => '', 'Unit2' => '', 'Decimal' => '0', 'Method' => '', 'CreateDate' => "$now"];
$data = ['TestSiteID' => $tIDs['HEIGHT'], 'DisciplineID' => '10', 'DepartmentID' => '', 'ResultType' => 'NMRIC', 'RefType' => '', 'VSet' => '', 'ReqQty' => '', 'ReqQtyUnit' => '', 'Unit1' => 'cm', 'Factor' => '', 'Unit2' => '', 'Decimal' => '0', 'Method' => '', 'CreateDate' => "$now"];
$this->db->table('testdeftech')->insert($data);
$data = ['SiteID' => '1', 'TestSiteCode' => 'WEIGHT', 'TestSiteName' => 'Weight', 'TestType' => $vs[27]['PARAM'], 'Description' => 'Berat Badan', 'SeqScr' => '41', 'SeqRpt' => '41', 'IndentLeft' => '0', 'VisibleScr' => $vs[2][1], 'VisibleRpt' => $vs[2][0], 'CountStat' => $vs[2][0], 'CreateDate' => "$now"];
$data = ['SiteID' => '1', 'TestSiteCode' => 'WEIGHT', 'TestSiteName' => 'Weight', 'TestType' => 'PARAM', 'Description' => 'Berat Badan', 'SeqScr' => '41', 'SeqRpt' => '41', 'IndentLeft' => '0', 'VisibleScr' => '1', 'VisibleRpt' => '0', 'CountStat' => '0', 'CreateDate' => "$now"];
$this->db->table('testdefsite')->insert($data);
$tIDs['WEIGHT'] = $this->db->insertID();
$data = ['TestSiteID' => $tIDs['WEIGHT'], 'DisciplineID' => '10', 'DepartmentID' => '', 'ResultType' => $vs[43]['NMRIC'], 'RefType' => '', 'VSet' => '', 'ReqQty' => '', 'ReqQtyUnit' => '', 'Unit1' => 'kg', 'Factor' => '', 'Unit2' => '', 'Decimal' => '1', 'Method' => '', 'CreateDate' => "$now"];
$data = ['TestSiteID' => $tIDs['WEIGHT'], 'DisciplineID' => '10', 'DepartmentID' => '', 'ResultType' => 'NMRIC', 'RefType' => '', 'VSet' => '', 'ReqQty' => '', 'ReqQtyUnit' => '', 'Unit1' => 'kg', 'Factor' => '', 'Unit2' => '', 'Decimal' => '1', 'Method' => '', 'CreateDate' => "$now"];
$this->db->table('testdeftech')->insert($data);
$data = ['SiteID' => '1', 'TestSiteCode' => 'AGE', 'TestSiteName' => 'Age', 'TestType' => $vs[27]['PARAM'], 'Description' => 'Usia', 'SeqScr' => '42', 'SeqRpt' => '42', 'IndentLeft' => '0', 'VisibleScr' => $vs[2][1], 'VisibleRpt' => $vs[2][0], 'CountStat' => $vs[2][0], 'CreateDate' => "$now"];
$data = ['SiteID' => '1', 'TestSiteCode' => 'AGE', 'TestSiteName' => 'Age', 'TestType' => 'PARAM', 'Description' => 'Usia', 'SeqScr' => '42', 'SeqRpt' => '42', 'IndentLeft' => '0', 'VisibleScr' => '1', 'VisibleRpt' => '0', 'CountStat' => '0', 'CreateDate' => "$now"];
$this->db->table('testdefsite')->insert($data);
$tIDs['AGE'] = $this->db->insertID();
$data = ['TestSiteID' => $tIDs['AGE'], 'DisciplineID' => '10', 'DepartmentID' => '', 'ResultType' => $vs[43]['NMRIC'], 'RefType' => '', 'VSet' => '', 'ReqQty' => '', 'ReqQtyUnit' => '', 'Unit1' => 'years', 'Factor' => '', 'Unit2' => '', 'Decimal' => '0', 'Method' => '', 'CreateDate' => "$now"];
$data = ['TestSiteID' => $tIDs['AGE'], 'DisciplineID' => '10', 'DepartmentID' => '', 'ResultType' => 'NMRIC', 'RefType' => '', 'VSet' => '', 'ReqQty' => '', 'ReqQtyUnit' => '', 'Unit1' => 'years', 'Factor' => '', 'Unit2' => '', 'Decimal' => '0', 'Method' => '', 'CreateDate' => "$now"];
$this->db->table('testdeftech')->insert($data);
$data = ['SiteID' => '1', 'TestSiteCode' => 'SYSTL', 'TestSiteName' => 'Systolic BP', 'TestType' => $vs[27]['PARAM'], 'Description' => 'Tekanan Darah Sistolik', 'SeqScr' => '43', 'SeqRpt' => '43', 'IndentLeft' => '0', 'VisibleScr' => $vs[2][1], 'VisibleRpt' => $vs[2][0], 'CountStat' => $vs[2][0], 'CreateDate' => "$now"];
$data = ['SiteID' => '1', 'TestSiteCode' => 'SYSTL', 'TestSiteName' => 'Systolic BP', 'TestType' => 'PARAM', 'Description' => 'Tekanan Darah Sistolik', 'SeqScr' => '43', 'SeqRpt' => '43', 'IndentLeft' => '0', 'VisibleScr' => '1', 'VisibleRpt' => '0', 'CountStat' => '0', 'CreateDate' => "$now"];
$this->db->table('testdefsite')->insert($data);
$tIDs['SYSTL'] = $this->db->insertID();
$data = ['TestSiteID' => $tIDs['SYSTL'], 'DisciplineID' => '10', 'DepartmentID' => '', 'ResultType' => $vs[43]['NMRIC'], 'RefType' => '', 'VSet' => '', 'ReqQty' => '', 'ReqQtyUnit' => '', 'Unit1' => 'mmHg', 'Factor' => '', 'Unit2' => '', 'Decimal' => '0', 'Method' => '', 'CreateDate' => "$now"];
$data = ['TestSiteID' => $tIDs['SYSTL'], 'DisciplineID' => '10', 'DepartmentID' => '', 'ResultType' => 'NMRIC', 'RefType' => '', 'VSet' => '', 'ReqQty' => '', 'ReqQtyUnit' => '', 'Unit1' => 'mmHg', 'Factor' => '', 'Unit2' => '', 'Decimal' => '0', 'Method' => '', 'CreateDate' => "$now"];
$this->db->table('testdeftech')->insert($data);
$data = ['SiteID' => '1', 'TestSiteCode' => 'DIASTL', 'TestSiteName' => 'Diastolic BP', 'TestType' => $vs[27]['PARAM'], 'Description' => 'Tekanan Darah Diastolik', 'SeqScr' => '44', 'SeqRpt' => '44', 'IndentLeft' => '0', 'VisibleScr' => $vs[2][1], 'VisibleRpt' => $vs[2][0], 'CountStat' => $vs[2][0], 'CreateDate' => "$now"];
$data = ['SiteID' => '1', 'TestSiteCode' => 'DIASTL', 'TestSiteName' => 'Diastolic BP', 'TestType' => 'PARAM', 'Description' => 'Tekanan Darah Diastolik', 'SeqScr' => '44', 'SeqRpt' => '44', 'IndentLeft' => '0', 'VisibleScr' => '1', 'VisibleRpt' => '0', 'CountStat' => '0', 'CreateDate' => "$now"];
$this->db->table('testdefsite')->insert($data);
$tIDs['DIASTL'] = $this->db->insertID();
$data = ['TestSiteID' => $tIDs['DIASTL'], 'DisciplineID' => '10', 'DepartmentID' => '', 'ResultType' => $vs[43]['NMRIC'], 'RefType' => '', 'VSet' => '', 'ReqQty' => '', 'ReqQtyUnit' => '', 'Unit1' => 'mmHg', 'Factor' => '', 'Unit2' => '', 'Decimal' => '0', 'Method' => '', 'CreateDate' => "$now"];
$data = ['TestSiteID' => $tIDs['DIASTL'], 'DisciplineID' => '10', 'DepartmentID' => '', 'ResultType' => 'NMRIC', 'RefType' => '', 'VSet' => '', 'ReqQty' => '', 'ReqQtyUnit' => '', 'Unit1' => 'mmHg', 'Factor' => '', 'Unit2' => '', 'Decimal' => '0', 'Method' => '', 'CreateDate' => "$now"];
$this->db->table('testdeftech')->insert($data);
// ========================================
// CALC TYPE - Calculated Tests
// ========================================
$data = ['SiteID' => '1', 'TestSiteCode' => 'BMI', 'TestSiteName' => 'Body Mass Index', 'TestType' => $vs[27]['CALC'], 'Description' => 'Indeks Massa Tubuh - weight/(height^2)', 'SeqScr' => '45', 'SeqRpt' => '45', 'IndentLeft' => '0', 'VisibleScr' => $vs[2][1], 'VisibleRpt' => $vs[2][1], 'CountStat' => $vs[2][0], 'CreateDate' => "$now"];
$data = ['SiteID' => '1', 'TestSiteCode' => 'BMI', 'TestSiteName' => 'Body Mass Index', 'TestType' => 'CALC', 'Description' => 'Indeks Massa Tubuh - weight/(height^2)', 'SeqScr' => '45', 'SeqRpt' => '45', 'IndentLeft' => '0', 'VisibleScr' => '1', 'VisibleRpt' => '1', 'CountStat' => '0', 'CreateDate' => "$now"];
$this->db->table('testdefsite')->insert($data);
$tIDs['BMI'] = $this->db->insertID();
$data = ['TestSiteID' => $tIDs['BMI'], 'DisciplineID' => '10', 'DepartmentID' => '', 'FormulaInput' => 'WEIGHT,HEIGHT', 'FormulaCode' => 'WEIGHT / ((HEIGHT/100) * (HEIGHT/100))', 'Unit1' => 'kg/m2', 'Factor' => '', 'Unit2' => '', 'Decimal' => '1', 'CreateDate' => "$now"];
$this->db->table('testdefcal')->insert($data);
$data = ['SiteID' => '1', 'TestSiteCode' => 'EGFR', 'TestSiteName' => 'eGFR (CKD-EPI)', 'TestType' => $vs[27]['CALC'], 'Description' => 'Estimated Glomerular Filtration Rate', 'SeqScr' => '20', 'SeqRpt' => '20', 'IndentLeft' => '1', 'VisibleScr' => $vs[2][1], 'VisibleRpt' => $vs[2][1], 'CountStat' => $vs[2][0], 'CreateDate' => "$now"];
$data = ['SiteID' => '1', 'TestSiteCode' => 'EGFR', 'TestSiteName' => 'eGFR (CKD-EPI)', 'TestType' => 'CALC', 'Description' => 'Estimated Glomerular Filtration Rate', 'SeqScr' => '20', 'SeqRpt' => '20', 'IndentLeft' => '1', 'VisibleScr' => '1', 'VisibleRpt' => '1', 'CountStat' => '0', 'CreateDate' => "$now"];
$this->db->table('testdefsite')->insert($data);
$tIDs['EGFR'] = $this->db->insertID();
$data = ['TestSiteID' => $tIDs['EGFR'], 'DisciplineID' => '2', 'DepartmentID' => '2', 'FormulaInput' => 'CREA,AGE,GENDER', 'FormulaCode' => 'CKD_EPI(CREA,AGE,GENDER)', 'Unit1' => 'mL/min/1.73m2', 'Factor' => '', 'Unit2' => '', 'Decimal' => '0', 'CreateDate' => "$now"];
$this->db->table('testdefcal')->insert($data);
$data = ['SiteID' => '1', 'TestSiteCode' => 'LDLCALC', 'TestSiteName' => 'LDL Cholesterol (Calculated)', 'TestType' => $vs[27]['CALC'], 'Description' => 'Friedewald formula: TC - HDL - (TG/5)', 'SeqScr' => '21', 'SeqRpt' => '21', 'IndentLeft' => '1', 'VisibleScr' => $vs[2][1], 'VisibleRpt' => $vs[2][1], 'CountStat' => $vs[2][0], 'CreateDate' => "$now"];
$data = ['SiteID' => '1', 'TestSiteCode' => 'LDLCALC', 'TestSiteName' => 'LDL Cholesterol (Calculated)', 'TestType' => 'CALC', 'Description' => 'Friedewald formula: TC - HDL - (TG/5)', 'SeqScr' => '21', 'SeqRpt' => '21', 'IndentLeft' => '1', 'VisibleScr' => '1', 'VisibleRpt' => '1', 'CountStat' => '0', 'CreateDate' => "$now"];
$this->db->table('testdefsite')->insert($data);
$tIDs['LDLCALC'] = $this->db->insertID();
$data = ['TestSiteID' => $tIDs['LDLCALC'], 'DisciplineID' => '2', 'DepartmentID' => '2', 'FormulaInput' => 'CHOL,HDL,TG', 'FormulaCode' => 'CHOL - HDL - (TG/5)', 'Unit1' => 'mg/dL', 'Factor' => '', 'Unit2' => '', 'Decimal' => '0', 'CreateDate' => "$now"];
@ -182,7 +189,7 @@ class TestSeeder extends Seeder {
// ========================================
// GROUP TYPE - Panel/Profile Tests
// ========================================
$data = ['SiteID' => '1', 'TestSiteCode' => 'CBC', 'TestSiteName' => 'Complete Blood Count', 'TestType' => $vs[27]['GROUP'], 'Description' => 'Darah Lengkap', 'SeqScr' => '50', 'SeqRpt' => '50', 'IndentLeft' => '0', 'VisibleScr' => $vs[2][1], 'VisibleRpt' => $vs[2][1], 'CountStat' => $vs[2][1], 'CreateDate' => "$now"];
$data = ['SiteID' => '1', 'TestSiteCode' => 'CBC', 'TestSiteName' => 'Complete Blood Count', 'TestType' => 'GROUP', 'Description' => 'Darah Lengkap', 'SeqScr' => '50', 'SeqRpt' => '50', 'IndentLeft' => '0', 'VisibleScr' => '1', 'VisibleRpt' => '1', 'CountStat' => '1', 'CreateDate' => "$now"];
$this->db->table('testdefsite')->insert($data);
$tIDs['CBC'] = $this->db->insertID();
$this->db->table('testdefgrp')->insertBatch([
@ -196,7 +203,7 @@ class TestSeeder extends Seeder {
['TestSiteID' => $tIDs['CBC'], 'Member' => $tIDs['MCHC'], 'CreateDate' => "$now"]
]);
$data = ['SiteID' => '1', 'TestSiteCode' => 'LIPID', 'TestSiteName' => 'Lipid Profile', 'TestType' => $vs[27]['GROUP'], 'Description' => 'Profil Lipid', 'SeqScr' => '51', 'SeqRpt' => '51', 'IndentLeft' => '0', 'VisibleScr' => $vs[2][1], 'VisibleRpt' => $vs[2][1], 'CountStat' => $vs[2][1], 'CreateDate' => "$now"];
$data = ['SiteID' => '1', 'TestSiteCode' => 'LIPID', 'TestSiteName' => 'Lipid Profile', 'TestType' => 'GROUP', 'Description' => 'Profil Lipid', 'SeqScr' => '51', 'SeqRpt' => '51', 'IndentLeft' => '0', 'VisibleScr' => '1', 'VisibleRpt' => '1', 'CountStat' => '1', 'CreateDate' => "$now"];
$this->db->table('testdefsite')->insert($data);
$tIDs['LIPID'] = $this->db->insertID();
$this->db->table('testdefgrp')->insertBatch([
@ -207,7 +214,7 @@ class TestSeeder extends Seeder {
['TestSiteID' => $tIDs['LIPID'], 'Member' => $tIDs['LDLCALC'], 'CreateDate' => "$now"]
]);
$data = ['SiteID' => '1', 'TestSiteCode' => 'LFT', 'TestSiteName' => 'Liver Function Test', 'TestType' => $vs[27]['GROUP'], 'Description' => 'Fungsi Hati', 'SeqScr' => '52', 'SeqRpt' => '52', 'IndentLeft' => '0', 'VisibleScr' => $vs[2][1], 'VisibleRpt' => $vs[2][1], 'CountStat' => $vs[2][1], 'CreateDate' => "$now"];
$data = ['SiteID' => '1', 'TestSiteCode' => 'LFT', 'TestSiteName' => 'Liver Function Test', 'TestType' => 'GROUP', 'Description' => 'Fungsi Hati', 'SeqScr' => '52', 'SeqRpt' => '52', 'IndentLeft' => '0', 'VisibleScr' => '1', 'VisibleRpt' => '1', 'CountStat' => '1', 'CreateDate' => "$now"];
$this->db->table('testdefsite')->insert($data);
$tIDs['LFT'] = $this->db->insertID();
$this->db->table('testdefgrp')->insertBatch([
@ -215,7 +222,7 @@ class TestSeeder extends Seeder {
['TestSiteID' => $tIDs['LFT'], 'Member' => $tIDs['SGPT'], 'CreateDate' => "$now"]
]);
$data = ['SiteID' => '1', 'TestSiteCode' => 'RFT', 'TestSiteName' => 'Renal Function Test', 'TestType' => $vs[27]['GROUP'], 'Description' => 'Fungsi Ginjal', 'SeqScr' => '53', 'SeqRpt' => '53', 'IndentLeft' => '0', 'VisibleScr' => $vs[2][1], 'VisibleRpt' => $vs[2][1], 'CountStat' => $vs[2][1], 'CreateDate' => "$now"];
$data = ['SiteID' => '1', 'TestSiteCode' => 'RFT', 'TestSiteName' => 'Renal Function Test', 'TestType' => 'GROUP', 'Description' => 'Fungsi Ginjal', 'SeqScr' => '53', 'SeqRpt' => '53', 'IndentLeft' => '0', 'VisibleScr' => '1', 'VisibleRpt' => '1', 'CountStat' => '1', 'CreateDate' => "$now"];
$this->db->table('testdefsite')->insert($data);
$tIDs['RFT'] = $this->db->insertID();
$this->db->table('testdefgrp')->insertBatch([
@ -225,29 +232,28 @@ class TestSeeder extends Seeder {
]);
// Urinalysis Tests (with valueset result type)
$data = ['SiteID' => '1', 'TestSiteCode' => 'UCOLOR', 'TestSiteName' => 'Urine Color', 'TestType' => $vs[27]['TEST'], 'Description' => 'Warna Urine', 'SeqScr' => '31', 'SeqRpt' => '31', 'IndentLeft' => '1', 'VisibleScr' => $vs[2][1], 'VisibleRpt' => $vs[2][1], 'CountStat' => $vs[2][1], 'CreateDate' => "$now"];
$data = ['SiteID' => '1', 'TestSiteCode' => 'UCOLOR', 'TestSiteName' => 'Urine Color', 'TestType' => 'TEST', 'Description' => 'Warna Urine', 'SeqScr' => '31', 'SeqRpt' => '31', 'IndentLeft' => '1', 'VisibleScr' => '1', 'VisibleRpt' => '1', 'CountStat' => '1', 'CreateDate' => "$now"];
$this->db->table('testdefsite')->insert($data);
$tIDs['UCOLOR'] = $this->db->insertID();
$data = ['TestSiteID' => $tIDs['UCOLOR'], 'DisciplineID' => '4', 'DepartmentID' => '4', 'ResultType' => $vs[43]['VSET'], 'RefType' => $vs[44]['TEXT'], 'VSet' => '1001', 'ReqQty' => '10', 'ReqQtyUnit' => 'mL', 'Unit1' => '', 'Factor' => '', 'Unit2' => '', 'Decimal' => '', 'Method' => 'Visual', 'CreateDate' => "$now"];
$data = ['TestSiteID' => $tIDs['UCOLOR'], 'DisciplineID' => '4', 'DepartmentID' => '4', 'ResultType' => 'VSET', 'RefType' => 'TEXT', 'VSet' => '1001', 'ReqQty' => '10', 'ReqQtyUnit' => 'mL', 'Unit1' => '', 'Factor' => '', 'Unit2' => '', 'Decimal' => '', 'Method' => 'Visual', 'CreateDate' => "$now"];
$this->db->table('testdeftech')->insert($data);
$data = ['SiteID' => '1', 'TestSiteCode' => 'UGLUC', 'TestSiteName' => 'Urine Glucose', 'TestType' => $vs[27]['TEST'], 'Description' => 'Glukosa Urine', 'SeqScr' => '32', 'SeqRpt' => '32', 'IndentLeft' => '1', 'VisibleScr' => $vs[2][1], 'VisibleRpt' => $vs[2][1], 'CountStat' => $vs[2][1], 'CreateDate' => "$now"];
$data = ['SiteID' => '1', 'TestSiteCode' => 'UGLUC', 'TestSiteName' => 'Urine Glucose', 'TestType' => 'TEST', 'Description' => 'Glukosa Urine', 'SeqScr' => '32', 'SeqRpt' => '32', 'IndentLeft' => '1', 'VisibleScr' => '1', 'VisibleRpt' => '1', 'CountStat' => '1', 'CreateDate' => "$now"];
$this->db->table('testdefsite')->insert($data);
$tIDs['UGLUC'] = $this->db->insertID();
$data = ['TestSiteID' => $tIDs['UGLUC'], 'DisciplineID' => '4', 'DepartmentID' => '4', 'ResultType' => $vs[43]['VSET'], 'RefType' => $vs[44]['TEXT'], 'VSet' => '1002', 'ReqQty' => '10', 'ReqQtyUnit' => 'mL', 'Unit1' => '', 'Factor' => '', 'Unit2' => '', 'Decimal' => '', 'Method' => 'Dipstick', 'CreateDate' => "$now"];
$data = ['TestSiteID' => $tIDs['UGLUC'], 'DisciplineID' => '4', 'DepartmentID' => '4', 'ResultType' => 'VSET', 'RefType' => 'TEXT', 'VSet' => '1002', 'ReqQty' => '10', 'ReqQtyUnit' => 'mL', 'Unit1' => '', 'Factor' => '', 'Unit2' => '', 'Decimal' => '', 'Method' => 'Dipstick', 'CreateDate' => "$now"];
$this->db->table('testdeftech')->insert($data);
$data = ['SiteID' => '1', 'TestSiteCode' => 'UPROT', 'TestSiteName' => 'Urine Protein', 'TestType' => $vs[27]['TEST'], 'Description' => 'Protein Urine', 'SeqScr' => '33', 'SeqRpt' => '33', 'IndentLeft' => '1', 'VisibleScr' => $vs[2][1], 'VisibleRpt' => $vs[2][1], 'CountStat' => $vs[2][1], 'CreateDate' => "$now"];
$data = ['SiteID' => '1', 'TestSiteCode' => 'UPROT', 'TestSiteName' => 'Urine Protein', 'TestType' => 'TEST', 'Description' => 'Protein Urine', 'SeqScr' => '33', 'SeqRpt' => '33', 'IndentLeft' => '1', 'VisibleScr' => '1', 'VisibleRpt' => '1', 'CountStat' => '1', 'CreateDate' => "$now"];
$this->db->table('testdefsite')->insert($data);
$tIDs['UPROT'] = $this->db->insertID();
$data = ['TestSiteID' => $tIDs['UPROT'], 'DisciplineID' => '4', 'DepartmentID' => '4', 'ResultType' => $vs[43]['VSET'], 'RefType' => $vs[44]['TEXT'], 'VSet' => '1003', 'ReqQty' => '10', 'ReqQtyUnit' => 'mL', 'Unit1' => '', 'Factor' => '', 'Unit2' => '', 'Decimal' => '', 'Method' => 'Dipstick', 'CreateDate' => "$now"];
$data = ['TestSiteID' => $tIDs['UPROT'], 'DisciplineID' => '4', 'DepartmentID' => '4', 'ResultType' => 'VSET', 'RefType' => 'TEXT', 'VSet' => '1003', 'ReqQty' => '10', 'ReqQtyUnit' => 'mL', 'Unit1' => '', 'Factor' => '', 'Unit2' => '', 'Decimal' => '', 'Method' => 'Dipstick', 'CreateDate' => "$now"];
$this->db->table('testdeftech')->insert($data);
$data = ['SiteID' => '1', 'TestSiteCode' => 'PH', 'TestSiteName' => 'Urine pH', 'TestType' => $vs[27]['TEST'], 'Description' => 'pH Urine', 'SeqScr' => '34', 'SeqRpt' => '34', 'IndentLeft' => '1', 'VisibleScr' => $vs[2][1], 'VisibleRpt' => $vs[2][1], 'CountStat' => $vs[2][1], 'CreateDate' => "$now"];
$data = ['SiteID' => '1', 'TestSiteCode' => 'PH', 'TestSiteName' => 'Urine pH', 'TestType' => 'TEST', 'Description' => 'pH Urine', 'SeqScr' => '34', 'SeqRpt' => '34', 'IndentLeft' => '1', 'VisibleScr' => '1', 'VisibleRpt' => '1', 'CountStat' => '1', 'CreateDate' => "$now"];
$this->db->table('testdefsite')->insert($data);
$tIDs['PH'] = $this->db->insertID();
$data = ['TestSiteID' => $tIDs['PH'], 'DisciplineID' => '4', 'DepartmentID' => '4', 'ResultType' => $vs[43]['NMRIC'], 'RefType' => $vs[44]['NMRC'], 'VSet' => '', 'ReqQty' => '10', 'ReqQtyUnit' => 'mL', 'Unit1' => '', 'Factor' => '', 'Unit2' => '', 'Decimal' => '1', 'Method' => 'Dipstick', 'CreateDate' => "$now"];
$data = ['TestSiteID' => $tIDs['PH'], 'DisciplineID' => '4', 'DepartmentID' => '4', 'ResultType' => 'NMRIC', 'RefType' => 'NMRC', 'VSet' => '', 'ReqQty' => '10', 'ReqQtyUnit' => 'mL', 'Unit1' => '', 'Factor' => '', 'Unit2' => '', 'Decimal' => '1', 'Method' => 'Dipstick', 'CreateDate' => "$now"];
$this->db->table('testdeftech')->insert($data);
}
}

View File

@ -5,7 +5,7 @@
"valuesets": [
{"file": "ws_type.json","VSName": "Workstation Type"},
{"file": "enable_disable.json","VSName": "Enable/Disable"},
{"file": "gender.json","VSName": "Gender"},
{"file": "sex.json","VSName": "Sex"},
{"file": "marital_status.json","VSName": "Marital Status"},
{"file": "death_indicator.json","VSName": "Death Indicator"},
{"file": "identifier_type.json","VSName": "Identifier Type"},

View File

@ -198,9 +198,10 @@ function valueSetItems() {
try {
const params = new URLSearchParams();
params.append('VSetID', this.selectedDef.VSetID);
if (this.keyword) params.append('param', this.keyword);
if (this.keyword) params.append('search', this.keyword);
if (this.selectedDef) params.append('VSetID', this.selectedDef.VSetID);
const res = await fetch(`${BASEURL}api/valueset?${params}`, {
const res = await fetch(`${BASEURL}api/valueset/items?${params}`, {
credentials: 'include'
});
if (!res.ok) throw new Error("HTTP error");
@ -259,7 +260,7 @@ function valueSetItems() {
this.isEditing = true;
this.errors = {};
try {
const res = await fetch(`${BASEURL}api/valueset/${id}`, {
const res = await fetch(`${BASEURL}api/valueset/items/${id}`, {
credentials: 'include'
});
const data = await res.json();
@ -291,8 +292,8 @@ function valueSetItems() {
this.saving = true;
try {
const method = this.isEditing ? 'PATCH' : 'POST';
const url = this.isEditing ? `${BASEURL}api/valueset/${this.form.VID}` : `${BASEURL}api/valueset`;
const method = this.isEditing ? 'PUT' : 'POST';
const url = this.isEditing ? `${BASEURL}api/valueset/items/${this.form.VID}` : `${BASEURL}api/valueset/items`;
const res = await fetch(url, {
method: method,
@ -328,7 +329,7 @@ function valueSetItems() {
this.deleting = true;
try {
const res = await fetch(`${BASEURL}api/valueset/${this.deleteTarget.VID}`, {
const res = await fetch(`${BASEURL}api/valueset/items/${this.deleteTarget.VID}`, {
method: 'DELETE',
headers: { 'Content-Type': 'application/json' },
credentials: 'include'

View File

@ -368,7 +368,7 @@ function valueSetManager() {
this.defLoading = true;
try {
const params = new URLSearchParams();
if (this.defKeyword) params.append('param', this.defKeyword);
if (this.defKeyword) params.append('search', this.defKeyword);
const res = await fetch(`${BASEURL}api/valuesetdef?${params}`, {
credentials: 'include'
@ -377,7 +377,6 @@ function valueSetManager() {
const data = await res.json();
this.defList = data.data || [];
// Update selected def in list if exists
if (this.selectedDef) {
const updated = this.defList.find(d => d.VSetID === this.selectedDef.VSetID);
if (updated) {
@ -440,7 +439,7 @@ function valueSetManager() {
this.savingDef = true;
try {
const method = this.isEditingDef ? 'PATCH' : 'POST';
const method = this.isEditingDef ? 'PUT' : 'POST';
const url = this.isEditingDef ? `${BASEURL}api/valuesetdef/${this.defForm.VSetID}` : `${BASEURL}api/valuesetdef`;
const res = await fetch(url, {
@ -517,9 +516,9 @@ function valueSetManager() {
try {
const params = new URLSearchParams();
params.append('VSetID', this.selectedDef.VSetID);
if (this.valueKeyword) params.append('param', this.valueKeyword);
if (this.valueKeyword) params.append('search', this.valueKeyword);
const res = await fetch(`${BASEURL}api/valueset?${params}`, {
const res = await fetch(`${BASEURL}api/valueset/items?${params}`, {
credentials: 'include'
});
if (!res.ok) throw new Error("HTTP error");
@ -571,7 +570,7 @@ function valueSetManager() {
this.isEditingValue = true;
this.valueErrors = {};
try {
const res = await fetch(`${BASEURL}api/valueset/${id}`, {
const res = await fetch(`${BASEURL}api/valueset/items/${id}`, {
credentials: 'include'
});
const data = await res.json();
@ -603,8 +602,8 @@ function valueSetManager() {
this.savingValue = true;
try {
const method = this.isEditingValue ? 'PATCH' : 'POST';
const url = this.isEditingValue ? `${BASEURL}api/valueset/${this.valueForm.VID}` : `${BASEURL}api/valueset`;
const method = this.isEditingValue ? 'PUT' : 'POST';
const url = this.isEditingValue ? `${BASEURL}api/valueset/items/${this.valueForm.VID}` : `${BASEURL}api/valueset/items`;
const res = await fetch(url, {
method: method,
@ -616,7 +615,7 @@ function valueSetManager() {
if (res.ok) {
this.closeValueModal();
await this.fetchValues();
await this.fetchDefs(); // Refresh item counts
await this.fetchDefs();
this.showToast(this.isEditingValue ? 'Item updated successfully' : 'Item created successfully', 'success');
} else {
const errorData = await res.json().catch(() => ({ message: 'Unknown error' }));
@ -641,7 +640,7 @@ function valueSetManager() {
this.deletingValue = true;
try {
const res = await fetch(`${BASEURL}api/valueset/${this.deleteValueTarget.VID}`, {
const res = await fetch(`${BASEURL}api/valueset/items/${this.deleteValueTarget.VID}`, {
method: 'DELETE',
headers: { 'Content-Type': 'application/json' },
credentials: 'include'
@ -650,7 +649,7 @@ function valueSetManager() {
if (res.ok) {
this.showDeleteValueModal = false;
await this.fetchValues();
await this.fetchDefs(); // Refresh item counts
await this.fetchDefs();
this.showToast('Item deleted successfully', 'success');
} else {
this.showToast('Failed to delete item', 'error');

View File

@ -6,7 +6,7 @@ use CodeIgniter\Test\FeatureTestTrait;
use CodeIgniter\Test\CIUnitTestCase;
use App\Libraries\ValueSet;
class ValueSetApiControllerTest extends CIUnitTestCase
class ValueSetControllerTest extends CIUnitTestCase
{
use FeatureTestTrait;
@ -16,7 +16,7 @@ class ValueSetApiControllerTest extends CIUnitTestCase
ValueSet::clearCache();
}
public function testIndexReturnsAllLookups()
public function testIndexReturnsAllLookupsWithCounts()
{
$result = $this->call('get', 'api/valueset');
@ -26,15 +26,18 @@ class ValueSetApiControllerTest extends CIUnitTestCase
$data = json_decode($json, true);
$this->assertEquals('success', $data['status']);
$this->assertArrayHasKey('gender', $data['data']);
$this->assertIsArray($data['data']);
$this->assertArrayHasKey('sex', $data['data']);
$this->assertArrayHasKey('specimen_type', $data['data']);
$this->assertArrayHasKey('order_priority', $data['data']);
$this->assertArrayHasKey('specimen_status', $data['data']);
$this->assertIsInt($data['data']['sex']);
$this->assertGreaterThan(0, $data['data']['sex']);
}
public function testShowByNameReturnsSingleLookup()
{
$result = $this->call('get', 'api/valueset/gender');
$result = $this->call('get', 'api/valueset/sex');
$result->assertStatus(200);
@ -48,9 +51,9 @@ class ValueSetApiControllerTest extends CIUnitTestCase
$this->assertArrayHasKey('label', $data['data'][0]);
}
public function testShowByNameGenderReturnsCorrectValues()
public function testShowByNameSexReturnsCorrectValues()
{
$result = $this->call('get', 'api/valueset/gender');
$result = $this->call('get', 'api/valueset/sex');
$result->assertStatus(200);
@ -96,56 +99,11 @@ class ValueSetApiControllerTest extends CIUnitTestCase
$this->assertContains('Routine', $labels);
}
public function testCreateReturns403()
public function testRefreshClearsCache()
{
$result = $this->call('post', 'api/valueset', [
'name' => 'test',
'values' => []
]);
ValueSet::getAll();
$result->assertStatus(403);
$json = $result->getJSON();
$data = json_decode($json, true);
$this->assertEquals('error', $data['status']);
$this->assertStringContainsString('disabled', $data['message']);
}
public function testUpdateReturns403()
{
$result = $this->call('patch', 'api/valueset', [
'name' => 'gender',
'values' => []
]);
$result->assertStatus(403);
$json = $result->getJSON();
$data = json_decode($json, true);
$this->assertEquals('error', $data['status']);
$this->assertStringContainsString('disabled', $data['message']);
}
public function testDeleteReturns403()
{
$result = $this->call('delete', 'api/valueset', [
'name' => 'gender'
]);
$result->assertStatus(403);
$json = $result->getJSON();
$data = json_decode($json, true);
$this->assertEquals('error', $data['status']);
$this->assertStringContainsString('disabled', $data['message']);
}
public function testIndexWithParamFiltersResults()
{
$result = $this->call('get', 'api/valueset', ['param' => 'gender']);
$result = $this->call('post', 'api/valueset/refresh');
$result->assertStatus(200);
@ -153,7 +111,7 @@ class ValueSetApiControllerTest extends CIUnitTestCase
$data = json_decode($json, true);
$this->assertEquals('success', $data['status']);
$this->assertIsArray($data['data']);
$this->assertEquals('Cache cleared', $data['message']);
}
public function testShowByNameSpecimenStatus()

View File

@ -1,110 +0,0 @@
<?php
namespace Tests\Unit\Lookups;
use CodeIgniter\Test\CIUnitTestCase;
use App\Libraries\Lookups;
class LookupsBackwardCompatibilityTest extends CIUnitTestCase
{
protected function setUp(): void
{
parent::setUp();
\App\Libraries\ValueSet::clearCache();
}
public function testLookupsGetMethodWorks()
{
$result = Lookups::get('gender');
$this->assertIsArray($result);
$this->assertNotEmpty($result);
$this->assertArrayHasKey('value', $result[0]);
$this->assertArrayHasKey('label', $result[0]);
}
public function testLookupsGetRawMethodWorks()
{
$result = Lookups::getRaw('gender');
$this->assertIsArray($result);
$this->assertNotEmpty($result);
$this->assertArrayHasKey('key', $result[0]);
$this->assertArrayHasKey('value', $result[0]);
}
public function testLookupsGetRawGenderContainsExpectedData()
{
$result = Lookups::getRaw('gender');
$keys = array_column($result, 'key');
$values = array_column($result, 'value');
$genderMap = array_combine($keys, $values);
$this->assertEquals('Female', $genderMap['1']);
$this->assertEquals('Male', $genderMap['2']);
}
public function testLookupsGetLabelMethodWorks()
{
$this->assertEquals('Female', Lookups::getLabel('gender', '1'));
$this->assertEquals('Male', Lookups::getLabel('gender', '2'));
$this->assertEquals('Stat', Lookups::getLabel('order_priority', 'S'));
}
public function testLookupsGetAllMethodWorks()
{
$result = Lookups::getAll();
$this->assertIsArray($result);
$this->assertArrayHasKey('gender', $result);
$this->assertArrayHasKey('specimen_type', $result);
$this->assertArrayHasKey('order_priority', $result);
}
public function testLookupsClearCacheMethodWorks()
{
Lookups::getAll();
$result = Lookups::clearCache();
$this->assertTrue($result);
}
public function testLookupsSameAsValueSet()
{
$lookupResult = Lookups::get('gender');
$valueSetResult = \App\Libraries\ValueSet::get('gender');
$this->assertEquals($lookupResult, $valueSetResult);
}
public function testLookupsBackwardCompatWithSpecimenStatus()
{
$result = Lookups::getRaw('specimen_status');
$keys = array_column($result, 'key');
$values = array_column($result, 'value');
$statusMap = array_combine($keys, $values);
$this->assertEquals('To be collected', $statusMap['STC']);
$this->assertEquals('Collected', $statusMap['SCtd']);
$this->assertEquals('In-transport', $statusMap['STran']);
}
public function testLookupsBackwardCompatWithMaritalStatus()
{
$result = Lookups::getRaw('marital_status');
$keys = array_column($result, 'key');
$values = array_column($result, 'value');
$statusMap = array_combine($keys, $values);
$this->assertEquals('Married', $statusMap['M']);
$this->assertEquals('Single', $statusMap['S']);
$this->assertEquals('Divorced', $statusMap['D']);
}
public function testLookupsBackwardCompatWithReligion()
{
$result = Lookups::getRaw('religion');
$keys = array_column($result, 'key');
$values = array_column($result, 'value');
$religionMap = array_combine($keys, $values);
$this->assertEquals('Islam', $religionMap['ISLAM']);
$this->assertEquals('Kristen', $religionMap['KRSTN']);
$this->assertEquals('Katolik', $religionMap['KTLIK']);
}
}

View File

@ -15,7 +15,7 @@ class ValueSetTest extends CIUnitTestCase
public function testGetPatientSexReturnsFormattedArray()
{
$result = ValueSet::get('gender');
$result = ValueSet::get('sex');
$this->assertIsArray($result);
$this->assertNotEmpty($result);
$this->assertArrayHasKey('value', $result[0]);
@ -24,7 +24,7 @@ class ValueSetTest extends CIUnitTestCase
public function testGetPatientSexContainsExpectedValues()
{
$result = ValueSet::get('gender');
$result = ValueSet::get('sex');
$values = array_column($result, 'value');
$labels = array_column($result, 'label');
@ -38,7 +38,7 @@ class ValueSetTest extends CIUnitTestCase
public function testGetRawReturnsArrayOfKeyValuePairs()
{
$result = ValueSet::getRaw('gender');
$result = ValueSet::getRaw('sex');
$this->assertIsArray($result);
$this->assertNotEmpty($result);
$this->assertArrayHasKey('key', $result[0]);
@ -47,7 +47,7 @@ class ValueSetTest extends CIUnitTestCase
public function testGetRawPatientSexContainsExpectedData()
{
$result = ValueSet::getRaw('gender');
$result = ValueSet::getRaw('sex');
$keys = array_column($result, 'key');
$values = array_column($result, 'value');
@ -59,9 +59,9 @@ class ValueSetTest extends CIUnitTestCase
public function testGetLabelConvertsCodeToLabel()
{
$this->assertEquals('Female', ValueSet::getLabel('gender', '1'));
$this->assertEquals('Male', ValueSet::getLabel('gender', '2'));
$this->assertEquals('Unknown', ValueSet::getLabel('gender', '3'));
$this->assertEquals('Female', ValueSet::getLabel('sex', '1'));
$this->assertEquals('Male', ValueSet::getLabel('sex', '2'));
$this->assertEquals('Unknown', ValueSet::getLabel('sex', '3'));
}
public function testGetLabelForOrderPriority()
@ -74,8 +74,8 @@ class ValueSetTest extends CIUnitTestCase
public function testGetLabelReturnsNullForInvalidKey()
{
$this->assertNull(ValueSet::getLabel('gender', '99'));
$this->assertNull(ValueSet::getLabel('gender', 'invalid'));
$this->assertNull(ValueSet::getLabel('sex', '99'));
$this->assertNull(ValueSet::getLabel('sex', 'invalid'));
}
public function testGetLabelReturnsNullForInvalidLookup()
@ -93,7 +93,7 @@ class ValueSetTest extends CIUnitTestCase
{
$result = ValueSet::getAll();
$this->assertIsArray($result);
$this->assertArrayHasKey('gender', $result);
$this->assertArrayHasKey('sex', $result);
$this->assertArrayHasKey('specimen_type', $result);
$this->assertArrayHasKey('order_priority', $result);
$this->assertArrayHasKey('specimen_status', $result);
@ -102,22 +102,22 @@ class ValueSetTest extends CIUnitTestCase
public function testGetAllContainsValuesKey()
{
$result = ValueSet::getAll();
$this->assertIsArray($result['gender']['values']);
$this->assertNotEmpty($result['gender']['values']);
$this->assertIsArray($result['sex']['values']);
$this->assertNotEmpty($result['sex']['values']);
}
public function testGetAllContainsMetadata()
{
$result = ValueSet::getAll();
$this->assertArrayHasKey('VSetID', $result['gender']);
$this->assertArrayHasKey('VSName', $result['gender']);
$this->assertArrayHasKey('VCategory', $result['gender']);
$this->assertArrayHasKey('values', $result['gender']);
$this->assertArrayHasKey('name', $result['sex']);
$this->assertArrayHasKey('VSName', $result['sex']);
$this->assertArrayHasKey('VCategory', $result['sex']);
$this->assertArrayHasKey('values', $result['sex']);
}
public function testGetPatientSex()
{
$result = ValueSet::get('gender');
$result = ValueSet::get('sex');
$this->assertEquals('1', $result[0]['value']);
$this->assertEquals('Female', $result[0]['label']);
$this->assertEquals('2', $result[1]['value']);
@ -269,7 +269,7 @@ class ValueSetTest extends CIUnitTestCase
public function testGetReturnsFormattedValues()
{
$result = ValueSet::get('gender');
$result = ValueSet::get('sex');
$this->assertEquals('1', $result[0]['value']);
$this->assertEquals('Female', $result[0]['label']);
$this->assertEquals('2', $result[1]['value']);
@ -360,7 +360,7 @@ class ValueSetTest extends CIUnitTestCase
];
$result = ValueSet::transformLabels($data, [
'Gender' => 'gender',
'Gender' => 'sex',
'Country' => 'country'
]);
@ -370,7 +370,7 @@ class ValueSetTest extends CIUnitTestCase
public function testGetOptions()
{
$result = ValueSet::getOptions('gender');
$result = ValueSet::getOptions('sex');
$this->assertIsArray($result);
$this->assertNotEmpty($result);
$this->assertArrayHasKey('key', $result[0]);