clqms-be/tests/unit/ValueSet/ValueSetTest.php

383 lines
13 KiB
PHP
Raw Normal View History

feat(valueset): refactor from ID-based to name-based lookups Complete overhaul of the valueset system to use human-readable names instead of numeric IDs for improved maintainability and API consistency. - PatientController: Renamed 'Gender' field to 'Sex' in validation rules - ValuesetController: Changed API endpoints from ID-based (/:num) to name-based (/:any) - TestsController: Refactored to use ValueSet library instead of direct valueset queries - Added ValueSet library (app/Libraries/ValueSet.php) with static lookup methods: - getOptions() - returns dropdown format [{value, label}] - getLabel(, ) - returns label for a value - transformLabels(, ) - batch transform records - get() and getRaw() for Lookups compatibility - Added ValueSetApiController for public valueset API endpoints - Added ValueSet refresh endpoint (POST /api/valueset/refresh) - Added DemoOrderController for testing order creation without auth - 2026-01-12-000001: Convert valueset references from VID to VValue - 2026-01-12-000002: Rename patient.Gender column to Sex - OrderTestController: Now uses OrderTestModel with proper model pattern - TestsController: Uses ValueSet library for all lookup operations - ValueSetController: Simplified to use name-based lookups - Updated all organization (account/site/workstation) dialogs and index views - Updated specimen container dialogs and index views - Updated tests_index.php with ValueSet integration - Updated patient dialog form and index views - Removed .factory/config.json and CLAUDE.md (replaced by AGENTS.md) - Consolidated lookups in Lookups.php (removed inline valueset constants) - Updated all test files to match new field names - 32 modified files, 17 new files, 2 deleted files - Net: +661 insertions, -1443 deletions (significant cleanup)
2026-01-12 16:53:41 +07:00
<?php
namespace Tests\Unit\ValueSet;
use CodeIgniter\Test\CIUnitTestCase;
use App\Libraries\ValueSet;
class ValueSetTest extends CIUnitTestCase
{
protected function setUp(): void
{
parent::setUp();
ValueSet::clearCache();
}
public function testGetPatientSexReturnsFormattedArray()
{
$result = ValueSet::get('sex');
feat(valueset): refactor from ID-based to name-based lookups Complete overhaul of the valueset system to use human-readable names instead of numeric IDs for improved maintainability and API consistency. - PatientController: Renamed 'Gender' field to 'Sex' in validation rules - ValuesetController: Changed API endpoints from ID-based (/:num) to name-based (/:any) - TestsController: Refactored to use ValueSet library instead of direct valueset queries - Added ValueSet library (app/Libraries/ValueSet.php) with static lookup methods: - getOptions() - returns dropdown format [{value, label}] - getLabel(, ) - returns label for a value - transformLabels(, ) - batch transform records - get() and getRaw() for Lookups compatibility - Added ValueSetApiController for public valueset API endpoints - Added ValueSet refresh endpoint (POST /api/valueset/refresh) - Added DemoOrderController for testing order creation without auth - 2026-01-12-000001: Convert valueset references from VID to VValue - 2026-01-12-000002: Rename patient.Gender column to Sex - OrderTestController: Now uses OrderTestModel with proper model pattern - TestsController: Uses ValueSet library for all lookup operations - ValueSetController: Simplified to use name-based lookups - Updated all organization (account/site/workstation) dialogs and index views - Updated specimen container dialogs and index views - Updated tests_index.php with ValueSet integration - Updated patient dialog form and index views - Removed .factory/config.json and CLAUDE.md (replaced by AGENTS.md) - Consolidated lookups in Lookups.php (removed inline valueset constants) - Updated all test files to match new field names - 32 modified files, 17 new files, 2 deleted files - Net: +661 insertions, -1443 deletions (significant cleanup)
2026-01-12 16:53:41 +07:00
$this->assertIsArray($result);
$this->assertNotEmpty($result);
$this->assertArrayHasKey('value', $result[0]);
$this->assertArrayHasKey('label', $result[0]);
}
public function testGetPatientSexContainsExpectedValues()
{
$result = ValueSet::get('sex');
feat(valueset): refactor from ID-based to name-based lookups Complete overhaul of the valueset system to use human-readable names instead of numeric IDs for improved maintainability and API consistency. - PatientController: Renamed 'Gender' field to 'Sex' in validation rules - ValuesetController: Changed API endpoints from ID-based (/:num) to name-based (/:any) - TestsController: Refactored to use ValueSet library instead of direct valueset queries - Added ValueSet library (app/Libraries/ValueSet.php) with static lookup methods: - getOptions() - returns dropdown format [{value, label}] - getLabel(, ) - returns label for a value - transformLabels(, ) - batch transform records - get() and getRaw() for Lookups compatibility - Added ValueSetApiController for public valueset API endpoints - Added ValueSet refresh endpoint (POST /api/valueset/refresh) - Added DemoOrderController for testing order creation without auth - 2026-01-12-000001: Convert valueset references from VID to VValue - 2026-01-12-000002: Rename patient.Gender column to Sex - OrderTestController: Now uses OrderTestModel with proper model pattern - TestsController: Uses ValueSet library for all lookup operations - ValueSetController: Simplified to use name-based lookups - Updated all organization (account/site/workstation) dialogs and index views - Updated specimen container dialogs and index views - Updated tests_index.php with ValueSet integration - Updated patient dialog form and index views - Removed .factory/config.json and CLAUDE.md (replaced by AGENTS.md) - Consolidated lookups in Lookups.php (removed inline valueset constants) - Updated all test files to match new field names - 32 modified files, 17 new files, 2 deleted files - Net: +661 insertions, -1443 deletions (significant cleanup)
2026-01-12 16:53:41 +07:00
$values = array_column($result, 'value');
$labels = array_column($result, 'label');
$this->assertContains('1', $values);
$this->assertContains('2', $values);
$this->assertContains('3', $values);
$this->assertContains('Female', $labels);
$this->assertContains('Male', $labels);
$this->assertContains('Unknown', $labels);
}
public function testGetRawReturnsArrayOfKeyValuePairs()
{
$result = ValueSet::getRaw('sex');
feat(valueset): refactor from ID-based to name-based lookups Complete overhaul of the valueset system to use human-readable names instead of numeric IDs for improved maintainability and API consistency. - PatientController: Renamed 'Gender' field to 'Sex' in validation rules - ValuesetController: Changed API endpoints from ID-based (/:num) to name-based (/:any) - TestsController: Refactored to use ValueSet library instead of direct valueset queries - Added ValueSet library (app/Libraries/ValueSet.php) with static lookup methods: - getOptions() - returns dropdown format [{value, label}] - getLabel(, ) - returns label for a value - transformLabels(, ) - batch transform records - get() and getRaw() for Lookups compatibility - Added ValueSetApiController for public valueset API endpoints - Added ValueSet refresh endpoint (POST /api/valueset/refresh) - Added DemoOrderController for testing order creation without auth - 2026-01-12-000001: Convert valueset references from VID to VValue - 2026-01-12-000002: Rename patient.Gender column to Sex - OrderTestController: Now uses OrderTestModel with proper model pattern - TestsController: Uses ValueSet library for all lookup operations - ValueSetController: Simplified to use name-based lookups - Updated all organization (account/site/workstation) dialogs and index views - Updated specimen container dialogs and index views - Updated tests_index.php with ValueSet integration - Updated patient dialog form and index views - Removed .factory/config.json and CLAUDE.md (replaced by AGENTS.md) - Consolidated lookups in Lookups.php (removed inline valueset constants) - Updated all test files to match new field names - 32 modified files, 17 new files, 2 deleted files - Net: +661 insertions, -1443 deletions (significant cleanup)
2026-01-12 16:53:41 +07:00
$this->assertIsArray($result);
$this->assertNotEmpty($result);
$this->assertArrayHasKey('key', $result[0]);
$this->assertArrayHasKey('value', $result[0]);
}
public function testGetRawPatientSexContainsExpectedData()
{
$result = ValueSet::getRaw('sex');
feat(valueset): refactor from ID-based to name-based lookups Complete overhaul of the valueset system to use human-readable names instead of numeric IDs for improved maintainability and API consistency. - PatientController: Renamed 'Gender' field to 'Sex' in validation rules - ValuesetController: Changed API endpoints from ID-based (/:num) to name-based (/:any) - TestsController: Refactored to use ValueSet library instead of direct valueset queries - Added ValueSet library (app/Libraries/ValueSet.php) with static lookup methods: - getOptions() - returns dropdown format [{value, label}] - getLabel(, ) - returns label for a value - transformLabels(, ) - batch transform records - get() and getRaw() for Lookups compatibility - Added ValueSetApiController for public valueset API endpoints - Added ValueSet refresh endpoint (POST /api/valueset/refresh) - Added DemoOrderController for testing order creation without auth - 2026-01-12-000001: Convert valueset references from VID to VValue - 2026-01-12-000002: Rename patient.Gender column to Sex - OrderTestController: Now uses OrderTestModel with proper model pattern - TestsController: Uses ValueSet library for all lookup operations - ValueSetController: Simplified to use name-based lookups - Updated all organization (account/site/workstation) dialogs and index views - Updated specimen container dialogs and index views - Updated tests_index.php with ValueSet integration - Updated patient dialog form and index views - Removed .factory/config.json and CLAUDE.md (replaced by AGENTS.md) - Consolidated lookups in Lookups.php (removed inline valueset constants) - Updated all test files to match new field names - 32 modified files, 17 new files, 2 deleted files - Net: +661 insertions, -1443 deletions (significant cleanup)
2026-01-12 16:53:41 +07:00
$keys = array_column($result, 'key');
$values = array_column($result, 'value');
$this->assertContains('1', $keys);
$this->assertContains('2', $keys);
$this->assertContains('Female', $values);
$this->assertContains('Male', $values);
}
public function testGetLabelConvertsCodeToLabel()
{
$this->assertEquals('Female', ValueSet::getLabel('sex', '1'));
$this->assertEquals('Male', ValueSet::getLabel('sex', '2'));
$this->assertEquals('Unknown', ValueSet::getLabel('sex', '3'));
feat(valueset): refactor from ID-based to name-based lookups Complete overhaul of the valueset system to use human-readable names instead of numeric IDs for improved maintainability and API consistency. - PatientController: Renamed 'Gender' field to 'Sex' in validation rules - ValuesetController: Changed API endpoints from ID-based (/:num) to name-based (/:any) - TestsController: Refactored to use ValueSet library instead of direct valueset queries - Added ValueSet library (app/Libraries/ValueSet.php) with static lookup methods: - getOptions() - returns dropdown format [{value, label}] - getLabel(, ) - returns label for a value - transformLabels(, ) - batch transform records - get() and getRaw() for Lookups compatibility - Added ValueSetApiController for public valueset API endpoints - Added ValueSet refresh endpoint (POST /api/valueset/refresh) - Added DemoOrderController for testing order creation without auth - 2026-01-12-000001: Convert valueset references from VID to VValue - 2026-01-12-000002: Rename patient.Gender column to Sex - OrderTestController: Now uses OrderTestModel with proper model pattern - TestsController: Uses ValueSet library for all lookup operations - ValueSetController: Simplified to use name-based lookups - Updated all organization (account/site/workstation) dialogs and index views - Updated specimen container dialogs and index views - Updated tests_index.php with ValueSet integration - Updated patient dialog form and index views - Removed .factory/config.json and CLAUDE.md (replaced by AGENTS.md) - Consolidated lookups in Lookups.php (removed inline valueset constants) - Updated all test files to match new field names - 32 modified files, 17 new files, 2 deleted files - Net: +661 insertions, -1443 deletions (significant cleanup)
2026-01-12 16:53:41 +07:00
}
public function testGetLabelForOrderPriority()
{
$this->assertEquals('Stat', ValueSet::getLabel('order_priority', 'S'));
$this->assertEquals('ASAP', ValueSet::getLabel('order_priority', 'A'));
$this->assertEquals('Routine', ValueSet::getLabel('order_priority', 'R'));
$this->assertEquals('Preop', ValueSet::getLabel('order_priority', 'P'));
}
public function testGetLabelReturnsNullForInvalidKey()
{
$this->assertNull(ValueSet::getLabel('sex', '99'));
$this->assertNull(ValueSet::getLabel('sex', 'invalid'));
feat(valueset): refactor from ID-based to name-based lookups Complete overhaul of the valueset system to use human-readable names instead of numeric IDs for improved maintainability and API consistency. - PatientController: Renamed 'Gender' field to 'Sex' in validation rules - ValuesetController: Changed API endpoints from ID-based (/:num) to name-based (/:any) - TestsController: Refactored to use ValueSet library instead of direct valueset queries - Added ValueSet library (app/Libraries/ValueSet.php) with static lookup methods: - getOptions() - returns dropdown format [{value, label}] - getLabel(, ) - returns label for a value - transformLabels(, ) - batch transform records - get() and getRaw() for Lookups compatibility - Added ValueSetApiController for public valueset API endpoints - Added ValueSet refresh endpoint (POST /api/valueset/refresh) - Added DemoOrderController for testing order creation without auth - 2026-01-12-000001: Convert valueset references from VID to VValue - 2026-01-12-000002: Rename patient.Gender column to Sex - OrderTestController: Now uses OrderTestModel with proper model pattern - TestsController: Uses ValueSet library for all lookup operations - ValueSetController: Simplified to use name-based lookups - Updated all organization (account/site/workstation) dialogs and index views - Updated specimen container dialogs and index views - Updated tests_index.php with ValueSet integration - Updated patient dialog form and index views - Removed .factory/config.json and CLAUDE.md (replaced by AGENTS.md) - Consolidated lookups in Lookups.php (removed inline valueset constants) - Updated all test files to match new field names - 32 modified files, 17 new files, 2 deleted files - Net: +661 insertions, -1443 deletions (significant cleanup)
2026-01-12 16:53:41 +07:00
}
public function testGetLabelReturnsNullForInvalidLookup()
{
$this->assertNull(ValueSet::getLabel('nonexistent_lookup', '1'));
}
public function testGetReturnsNullForInvalidLookup()
{
$result = ValueSet::get('nonexistent_lookup');
$this->assertNull($result);
}
public function testGetAllReturnsMultipleLookups()
{
$result = ValueSet::getAll();
$this->assertIsArray($result);
$this->assertArrayHasKey('sex', $result);
feat(valueset): refactor from ID-based to name-based lookups Complete overhaul of the valueset system to use human-readable names instead of numeric IDs for improved maintainability and API consistency. - PatientController: Renamed 'Gender' field to 'Sex' in validation rules - ValuesetController: Changed API endpoints from ID-based (/:num) to name-based (/:any) - TestsController: Refactored to use ValueSet library instead of direct valueset queries - Added ValueSet library (app/Libraries/ValueSet.php) with static lookup methods: - getOptions() - returns dropdown format [{value, label}] - getLabel(, ) - returns label for a value - transformLabels(, ) - batch transform records - get() and getRaw() for Lookups compatibility - Added ValueSetApiController for public valueset API endpoints - Added ValueSet refresh endpoint (POST /api/valueset/refresh) - Added DemoOrderController for testing order creation without auth - 2026-01-12-000001: Convert valueset references from VID to VValue - 2026-01-12-000002: Rename patient.Gender column to Sex - OrderTestController: Now uses OrderTestModel with proper model pattern - TestsController: Uses ValueSet library for all lookup operations - ValueSetController: Simplified to use name-based lookups - Updated all organization (account/site/workstation) dialogs and index views - Updated specimen container dialogs and index views - Updated tests_index.php with ValueSet integration - Updated patient dialog form and index views - Removed .factory/config.json and CLAUDE.md (replaced by AGENTS.md) - Consolidated lookups in Lookups.php (removed inline valueset constants) - Updated all test files to match new field names - 32 modified files, 17 new files, 2 deleted files - Net: +661 insertions, -1443 deletions (significant cleanup)
2026-01-12 16:53:41 +07:00
$this->assertArrayHasKey('specimen_type', $result);
$this->assertArrayHasKey('order_priority', $result);
$this->assertArrayHasKey('specimen_status', $result);
}
public function testGetAllContainsValuesKey()
{
$result = ValueSet::getAll();
$this->assertIsArray($result['sex']['values']);
$this->assertNotEmpty($result['sex']['values']);
feat(valueset): refactor from ID-based to name-based lookups Complete overhaul of the valueset system to use human-readable names instead of numeric IDs for improved maintainability and API consistency. - PatientController: Renamed 'Gender' field to 'Sex' in validation rules - ValuesetController: Changed API endpoints from ID-based (/:num) to name-based (/:any) - TestsController: Refactored to use ValueSet library instead of direct valueset queries - Added ValueSet library (app/Libraries/ValueSet.php) with static lookup methods: - getOptions() - returns dropdown format [{value, label}] - getLabel(, ) - returns label for a value - transformLabels(, ) - batch transform records - get() and getRaw() for Lookups compatibility - Added ValueSetApiController for public valueset API endpoints - Added ValueSet refresh endpoint (POST /api/valueset/refresh) - Added DemoOrderController for testing order creation without auth - 2026-01-12-000001: Convert valueset references from VID to VValue - 2026-01-12-000002: Rename patient.Gender column to Sex - OrderTestController: Now uses OrderTestModel with proper model pattern - TestsController: Uses ValueSet library for all lookup operations - ValueSetController: Simplified to use name-based lookups - Updated all organization (account/site/workstation) dialogs and index views - Updated specimen container dialogs and index views - Updated tests_index.php with ValueSet integration - Updated patient dialog form and index views - Removed .factory/config.json and CLAUDE.md (replaced by AGENTS.md) - Consolidated lookups in Lookups.php (removed inline valueset constants) - Updated all test files to match new field names - 32 modified files, 17 new files, 2 deleted files - Net: +661 insertions, -1443 deletions (significant cleanup)
2026-01-12 16:53:41 +07:00
}
public function testGetAllContainsMetadata()
{
$result = ValueSet::getAll();
$this->assertArrayHasKey('name', $result['sex']);
$this->assertArrayHasKey('VSName', $result['sex']);
$this->assertArrayHasKey('VCategory', $result['sex']);
$this->assertArrayHasKey('values', $result['sex']);
feat(valueset): refactor from ID-based to name-based lookups Complete overhaul of the valueset system to use human-readable names instead of numeric IDs for improved maintainability and API consistency. - PatientController: Renamed 'Gender' field to 'Sex' in validation rules - ValuesetController: Changed API endpoints from ID-based (/:num) to name-based (/:any) - TestsController: Refactored to use ValueSet library instead of direct valueset queries - Added ValueSet library (app/Libraries/ValueSet.php) with static lookup methods: - getOptions() - returns dropdown format [{value, label}] - getLabel(, ) - returns label for a value - transformLabels(, ) - batch transform records - get() and getRaw() for Lookups compatibility - Added ValueSetApiController for public valueset API endpoints - Added ValueSet refresh endpoint (POST /api/valueset/refresh) - Added DemoOrderController for testing order creation without auth - 2026-01-12-000001: Convert valueset references from VID to VValue - 2026-01-12-000002: Rename patient.Gender column to Sex - OrderTestController: Now uses OrderTestModel with proper model pattern - TestsController: Uses ValueSet library for all lookup operations - ValueSetController: Simplified to use name-based lookups - Updated all organization (account/site/workstation) dialogs and index views - Updated specimen container dialogs and index views - Updated tests_index.php with ValueSet integration - Updated patient dialog form and index views - Removed .factory/config.json and CLAUDE.md (replaced by AGENTS.md) - Consolidated lookups in Lookups.php (removed inline valueset constants) - Updated all test files to match new field names - 32 modified files, 17 new files, 2 deleted files - Net: +661 insertions, -1443 deletions (significant cleanup)
2026-01-12 16:53:41 +07:00
}
public function testGetPatientSex()
{
$result = ValueSet::get('sex');
feat(valueset): refactor from ID-based to name-based lookups Complete overhaul of the valueset system to use human-readable names instead of numeric IDs for improved maintainability and API consistency. - PatientController: Renamed 'Gender' field to 'Sex' in validation rules - ValuesetController: Changed API endpoints from ID-based (/:num) to name-based (/:any) - TestsController: Refactored to use ValueSet library instead of direct valueset queries - Added ValueSet library (app/Libraries/ValueSet.php) with static lookup methods: - getOptions() - returns dropdown format [{value, label}] - getLabel(, ) - returns label for a value - transformLabels(, ) - batch transform records - get() and getRaw() for Lookups compatibility - Added ValueSetApiController for public valueset API endpoints - Added ValueSet refresh endpoint (POST /api/valueset/refresh) - Added DemoOrderController for testing order creation without auth - 2026-01-12-000001: Convert valueset references from VID to VValue - 2026-01-12-000002: Rename patient.Gender column to Sex - OrderTestController: Now uses OrderTestModel with proper model pattern - TestsController: Uses ValueSet library for all lookup operations - ValueSetController: Simplified to use name-based lookups - Updated all organization (account/site/workstation) dialogs and index views - Updated specimen container dialogs and index views - Updated tests_index.php with ValueSet integration - Updated patient dialog form and index views - Removed .factory/config.json and CLAUDE.md (replaced by AGENTS.md) - Consolidated lookups in Lookups.php (removed inline valueset constants) - Updated all test files to match new field names - 32 modified files, 17 new files, 2 deleted files - Net: +661 insertions, -1443 deletions (significant cleanup)
2026-01-12 16:53:41 +07:00
$this->assertEquals('1', $result[0]['value']);
$this->assertEquals('Female', $result[0]['label']);
$this->assertEquals('2', $result[1]['value']);
$this->assertEquals('Male', $result[1]['label']);
}
public function testGetSpecimenStatus()
{
$result = ValueSet::getRaw('specimen_status');
$keys = array_column($result, 'key');
$values = array_column($result, 'value');
$this->assertContains('STC', $keys);
$this->assertContains('SCtd', $keys);
$this->assertContains('STran', $keys);
$this->assertContains('SArrv', $keys);
$this->assertContains('SRejc', $keys);
$this->assertContains('SRcvd', $keys);
$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 testGetOrderPriority()
{
$result = ValueSet::getRaw('order_priority');
$keys = array_column($result, 'key');
$values = array_column($result, 'value');
$this->assertContains('S', $keys);
$this->assertContains('A', $keys);
$this->assertContains('R', $keys);
$priorityMap = array_combine($keys, $values);
$this->assertEquals('Stat', $priorityMap['S']);
$this->assertEquals('ASAP', $priorityMap['A']);
$this->assertEquals('Routine', $priorityMap['R']);
$this->assertEquals('Preop', $priorityMap['P']);
}
public function testGetSpecimenType()
{
$result = ValueSet::getRaw('specimen_type');
$keys = array_column($result, 'key');
$values = array_column($result, 'value');
$typeMap = array_combine($keys, $values);
$this->assertEquals('Whole blood', $typeMap['BLD']);
$this->assertEquals('Serum', $typeMap['SER']);
$this->assertEquals('Plasma', $typeMap['PLAS']);
$this->assertEquals('Urine', $typeMap['UR']);
}
public function testGetMaritalStatus()
{
$result = ValueSet::getRaw('marital_status');
$keys = array_column($result, 'key');
$values = array_column($result, 'value');
$statusMap = array_combine($keys, $values);
$this->assertEquals('Separated', $statusMap['A']);
$this->assertEquals('Divorced', $statusMap['D']);
$this->assertEquals('Married', $statusMap['M']);
$this->assertEquals('Single', $statusMap['S']);
$this->assertEquals('Widowed', $statusMap['W']);
}
public function testGetPatientReligion()
{
$result = ValueSet::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']);
$this->assertEquals('Hindu', $religionMap['HINDU']);
$this->assertEquals('Budha', $religionMap['BUDHA']);
}
public function testGetResultType()
{
$result = ValueSet::getRaw('result_type');
$keys = array_column($result, 'key');
$values = array_column($result, 'value');
$typeMap = array_combine($keys, $values);
$this->assertEquals('Numeric', $typeMap['NMRIC']);
$this->assertEquals('Range', $typeMap['RANGE']);
$this->assertEquals('Text', $typeMap['TEXT']);
$this->assertEquals('Value set', $typeMap['VSET']);
}
public function testClearCacheDoesNotThrowError()
{
ValueSet::getAll();
$result = ValueSet::clearCache();
$this->assertTrue($result);
}
public function testGetOrderPriorityFromAlias()
{
$result = ValueSet::getRaw('priority');
$keys = array_column($result, 'key');
$values = array_column($result, 'value');
$priorityMap = array_combine($keys, $values);
$this->assertEquals('Stat', $priorityMap['S']);
$this->assertEquals('Routine', $priorityMap['R']);
}
public function testGetTestStatus()
{
$result = ValueSet::getRaw('test_status');
$keys = array_column($result, 'key');
$values = array_column($result, 'value');
$statusMap = array_combine($keys, $values);
$this->assertEquals('Waiting for Results', $statusMap['PENDING']);
$this->assertEquals('Analyzing', $statusMap['IN_PROCESS']);
$this->assertEquals('Verified & Signed', $statusMap['VERIFIED']);
}
public function testGetOrderRequestStatus()
{
$result = ValueSet::getRaw('request_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']);
}
public function testGetResultResultStatus()
{
$result = ValueSet::getRaw('result_status');
$keys = array_column($result, 'key');
$values = array_column($result, 'value');
$statusMap = array_combine($keys, $values);
$this->assertEquals('Preliminary', $statusMap['PRELIMINARY']);
$this->assertEquals('Final', $statusMap['FINAL']);
$this->assertEquals('Corrected', $statusMap['CORRECTED']);
}
public function testGetReturnsFormattedValues()
{
$result = ValueSet::get('sex');
feat(valueset): refactor from ID-based to name-based lookups Complete overhaul of the valueset system to use human-readable names instead of numeric IDs for improved maintainability and API consistency. - PatientController: Renamed 'Gender' field to 'Sex' in validation rules - ValuesetController: Changed API endpoints from ID-based (/:num) to name-based (/:any) - TestsController: Refactored to use ValueSet library instead of direct valueset queries - Added ValueSet library (app/Libraries/ValueSet.php) with static lookup methods: - getOptions() - returns dropdown format [{value, label}] - getLabel(, ) - returns label for a value - transformLabels(, ) - batch transform records - get() and getRaw() for Lookups compatibility - Added ValueSetApiController for public valueset API endpoints - Added ValueSet refresh endpoint (POST /api/valueset/refresh) - Added DemoOrderController for testing order creation without auth - 2026-01-12-000001: Convert valueset references from VID to VValue - 2026-01-12-000002: Rename patient.Gender column to Sex - OrderTestController: Now uses OrderTestModel with proper model pattern - TestsController: Uses ValueSet library for all lookup operations - ValueSetController: Simplified to use name-based lookups - Updated all organization (account/site/workstation) dialogs and index views - Updated specimen container dialogs and index views - Updated tests_index.php with ValueSet integration - Updated patient dialog form and index views - Removed .factory/config.json and CLAUDE.md (replaced by AGENTS.md) - Consolidated lookups in Lookups.php (removed inline valueset constants) - Updated all test files to match new field names - 32 modified files, 17 new files, 2 deleted files - Net: +661 insertions, -1443 deletions (significant cleanup)
2026-01-12 16:53:41 +07:00
$this->assertEquals('1', $result[0]['value']);
$this->assertEquals('Female', $result[0]['label']);
$this->assertEquals('2', $result[1]['value']);
$this->assertEquals('Male', $result[1]['label']);
}
public function testGetWithSpecialCharactersInKey()
{
$result = ValueSet::get('result_unit');
$values = array_column($result, 'value');
$this->assertContains('g/dL', $values);
$this->assertContains('mg/dL', $values);
$this->assertContains('x106/mL', $values);
}
public function testGetMathSigns()
{
$result = ValueSet::getRaw('math_sign');
$keys = array_column($result, 'key');
$values = array_column($result, 'value');
$signMap = array_combine($keys, $values);
$this->assertEquals('Equal', $signMap['=']);
$this->assertEquals('Less than', $signMap['<']);
$this->assertEquals('Greater than', $signMap['>']);
$this->assertEquals('Less than or equal to', $signMap['<=']);
$this->assertEquals('Greater than or equal to', $signMap['>=']);
}
public function testGetContainerCapColor()
{
$result = ValueSet::getRaw('container_cap_color');
$keys = array_column($result, 'key');
$values = array_column($result, 'value');
$colorMap = array_combine($keys, $values);
$this->assertEquals('Purple', $colorMap['PRPL']);
$this->assertEquals('Red', $colorMap['RED']);
$this->assertEquals('Yellow', $colorMap['YLLW']);
$this->assertEquals('Green', $colorMap['GRN']);
}
public function testGetOrganizationSiteType()
{
$result = ValueSet::getRaw('site_type');
$keys = array_column($result, 'key');
$values = array_column($result, 'value');
$siteMap = array_combine($keys, $values);
$this->assertEquals('Government Hospital', $siteMap['GH']);
$this->assertEquals('Private Hospital', $siteMap['PH']);
$this->assertEquals('Government Lab', $siteMap['GL']);
$this->assertEquals('Private Lab', $siteMap['PL']);
}
public function testGetPatEntityType()
{
$result = ValueSet::getRaw('entity_type');
$keys = array_column($result, 'key');
$values = array_column($result, 'value');
$entityMap = array_combine($keys, $values);
$this->assertEquals('HIS', $entityMap['HIS']);
$this->assertEquals('Site', $entityMap['SITE']);
$this->assertEquals('Workstation', $entityMap['WST']);
$this->assertEquals('Equipment/Instrument', $entityMap['INST']);
}
public function testGetTestType()
{
$result = ValueSet::get('test_type');
$this->assertIsArray($result);
$this->assertNotEmpty($result);
$values = array_column($result, 'value');
$this->assertContains('TEST', $values);
$this->assertContains('PARAM', $values);
$this->assertContains('CALC', $values);
$this->assertContains('GROUP', $values);
$this->assertContains('TITLE', $values);
}
public function testTransformLabels()
{
$data = [
['Gender' => '1', 'Country' => 'IDN'],
['Gender' => '2', 'Country' => 'USA']
feat(valueset): refactor from ID-based to name-based lookups Complete overhaul of the valueset system to use human-readable names instead of numeric IDs for improved maintainability and API consistency. - PatientController: Renamed 'Gender' field to 'Sex' in validation rules - ValuesetController: Changed API endpoints from ID-based (/:num) to name-based (/:any) - TestsController: Refactored to use ValueSet library instead of direct valueset queries - Added ValueSet library (app/Libraries/ValueSet.php) with static lookup methods: - getOptions() - returns dropdown format [{value, label}] - getLabel(, ) - returns label for a value - transformLabels(, ) - batch transform records - get() and getRaw() for Lookups compatibility - Added ValueSetApiController for public valueset API endpoints - Added ValueSet refresh endpoint (POST /api/valueset/refresh) - Added DemoOrderController for testing order creation without auth - 2026-01-12-000001: Convert valueset references from VID to VValue - 2026-01-12-000002: Rename patient.Gender column to Sex - OrderTestController: Now uses OrderTestModel with proper model pattern - TestsController: Uses ValueSet library for all lookup operations - ValueSetController: Simplified to use name-based lookups - Updated all organization (account/site/workstation) dialogs and index views - Updated specimen container dialogs and index views - Updated tests_index.php with ValueSet integration - Updated patient dialog form and index views - Removed .factory/config.json and CLAUDE.md (replaced by AGENTS.md) - Consolidated lookups in Lookups.php (removed inline valueset constants) - Updated all test files to match new field names - 32 modified files, 17 new files, 2 deleted files - Net: +661 insertions, -1443 deletions (significant cleanup)
2026-01-12 16:53:41 +07:00
];
feat(valueset): refactor from ID-based to name-based lookups Complete overhaul of the valueset system to use human-readable names instead of numeric IDs for improved maintainability and API consistency. - PatientController: Renamed 'Gender' field to 'Sex' in validation rules - ValuesetController: Changed API endpoints from ID-based (/:num) to name-based (/:any) - TestsController: Refactored to use ValueSet library instead of direct valueset queries - Added ValueSet library (app/Libraries/ValueSet.php) with static lookup methods: - getOptions() - returns dropdown format [{value, label}] - getLabel(, ) - returns label for a value - transformLabels(, ) - batch transform records - get() and getRaw() for Lookups compatibility - Added ValueSetApiController for public valueset API endpoints - Added ValueSet refresh endpoint (POST /api/valueset/refresh) - Added DemoOrderController for testing order creation without auth - 2026-01-12-000001: Convert valueset references from VID to VValue - 2026-01-12-000002: Rename patient.Gender column to Sex - OrderTestController: Now uses OrderTestModel with proper model pattern - TestsController: Uses ValueSet library for all lookup operations - ValueSetController: Simplified to use name-based lookups - Updated all organization (account/site/workstation) dialogs and index views - Updated specimen container dialogs and index views - Updated tests_index.php with ValueSet integration - Updated patient dialog form and index views - Removed .factory/config.json and CLAUDE.md (replaced by AGENTS.md) - Consolidated lookups in Lookups.php (removed inline valueset constants) - Updated all test files to match new field names - 32 modified files, 17 new files, 2 deleted files - Net: +661 insertions, -1443 deletions (significant cleanup)
2026-01-12 16:53:41 +07:00
$result = ValueSet::transformLabels($data, [
'Gender' => 'sex',
feat(valueset): refactor from ID-based to name-based lookups Complete overhaul of the valueset system to use human-readable names instead of numeric IDs for improved maintainability and API consistency. - PatientController: Renamed 'Gender' field to 'Sex' in validation rules - ValuesetController: Changed API endpoints from ID-based (/:num) to name-based (/:any) - TestsController: Refactored to use ValueSet library instead of direct valueset queries - Added ValueSet library (app/Libraries/ValueSet.php) with static lookup methods: - getOptions() - returns dropdown format [{value, label}] - getLabel(, ) - returns label for a value - transformLabels(, ) - batch transform records - get() and getRaw() for Lookups compatibility - Added ValueSetApiController for public valueset API endpoints - Added ValueSet refresh endpoint (POST /api/valueset/refresh) - Added DemoOrderController for testing order creation without auth - 2026-01-12-000001: Convert valueset references from VID to VValue - 2026-01-12-000002: Rename patient.Gender column to Sex - OrderTestController: Now uses OrderTestModel with proper model pattern - TestsController: Uses ValueSet library for all lookup operations - ValueSetController: Simplified to use name-based lookups - Updated all organization (account/site/workstation) dialogs and index views - Updated specimen container dialogs and index views - Updated tests_index.php with ValueSet integration - Updated patient dialog form and index views - Removed .factory/config.json and CLAUDE.md (replaced by AGENTS.md) - Consolidated lookups in Lookups.php (removed inline valueset constants) - Updated all test files to match new field names - 32 modified files, 17 new files, 2 deleted files - Net: +661 insertions, -1443 deletions (significant cleanup)
2026-01-12 16:53:41 +07:00
'Country' => 'country'
]);
$this->assertEquals('Female', $result[0]['Gender']);
$this->assertEquals('1', $result[0]['GenderKey']);
$this->assertEquals('Male', $result[1]['Gender']);
$this->assertEquals('2', $result[1]['GenderKey']);
feat(valueset): refactor from ID-based to name-based lookups Complete overhaul of the valueset system to use human-readable names instead of numeric IDs for improved maintainability and API consistency. - PatientController: Renamed 'Gender' field to 'Sex' in validation rules - ValuesetController: Changed API endpoints from ID-based (/:num) to name-based (/:any) - TestsController: Refactored to use ValueSet library instead of direct valueset queries - Added ValueSet library (app/Libraries/ValueSet.php) with static lookup methods: - getOptions() - returns dropdown format [{value, label}] - getLabel(, ) - returns label for a value - transformLabels(, ) - batch transform records - get() and getRaw() for Lookups compatibility - Added ValueSetApiController for public valueset API endpoints - Added ValueSet refresh endpoint (POST /api/valueset/refresh) - Added DemoOrderController for testing order creation without auth - 2026-01-12-000001: Convert valueset references from VID to VValue - 2026-01-12-000002: Rename patient.Gender column to Sex - OrderTestController: Now uses OrderTestModel with proper model pattern - TestsController: Uses ValueSet library for all lookup operations - ValueSetController: Simplified to use name-based lookups - Updated all organization (account/site/workstation) dialogs and index views - Updated specimen container dialogs and index views - Updated tests_index.php with ValueSet integration - Updated patient dialog form and index views - Removed .factory/config.json and CLAUDE.md (replaced by AGENTS.md) - Consolidated lookups in Lookups.php (removed inline valueset constants) - Updated all test files to match new field names - 32 modified files, 17 new files, 2 deleted files - Net: +661 insertions, -1443 deletions (significant cleanup)
2026-01-12 16:53:41 +07:00
}
public function testGetOptions()
{
$result = ValueSet::getOptions('sex');
feat(valueset): refactor from ID-based to name-based lookups Complete overhaul of the valueset system to use human-readable names instead of numeric IDs for improved maintainability and API consistency. - PatientController: Renamed 'Gender' field to 'Sex' in validation rules - ValuesetController: Changed API endpoints from ID-based (/:num) to name-based (/:any) - TestsController: Refactored to use ValueSet library instead of direct valueset queries - Added ValueSet library (app/Libraries/ValueSet.php) with static lookup methods: - getOptions() - returns dropdown format [{value, label}] - getLabel(, ) - returns label for a value - transformLabels(, ) - batch transform records - get() and getRaw() for Lookups compatibility - Added ValueSetApiController for public valueset API endpoints - Added ValueSet refresh endpoint (POST /api/valueset/refresh) - Added DemoOrderController for testing order creation without auth - 2026-01-12-000001: Convert valueset references from VID to VValue - 2026-01-12-000002: Rename patient.Gender column to Sex - OrderTestController: Now uses OrderTestModel with proper model pattern - TestsController: Uses ValueSet library for all lookup operations - ValueSetController: Simplified to use name-based lookups - Updated all organization (account/site/workstation) dialogs and index views - Updated specimen container dialogs and index views - Updated tests_index.php with ValueSet integration - Updated patient dialog form and index views - Removed .factory/config.json and CLAUDE.md (replaced by AGENTS.md) - Consolidated lookups in Lookups.php (removed inline valueset constants) - Updated all test files to match new field names - 32 modified files, 17 new files, 2 deleted files - Net: +661 insertions, -1443 deletions (significant cleanup)
2026-01-12 16:53:41 +07:00
$this->assertIsArray($result);
$this->assertNotEmpty($result);
$this->assertArrayHasKey('key', $result[0]);
$this->assertArrayHasKey('value', $result[0]);
}
}