clqms-be/app/Database/Migrations/2026-01-01-000008_CreateTestDefinitions.php
mahdahar 4aa9cefc3d refactor: consolidate migrations and reorganize valueset data structure
Major refactoring to clean up database migrations and reorganize static lookup data:
- Consolidated 13 old migrations (2025) into 10 new numbered migrations (2026-01-01)
- Deleted redundant migrations: Location, Users, Contact, ValueSet, Counter, RefRange,
  CRMOrganizations, Organization, AreaGeo, DeviceLogin, EdgeRes
- New consolidated migrations:
  - 2026-01-01-000001_CreateLookups: valueset, counter, containerdef, occupation, specialty
  - 2026-01-01-000002_CreateOrganization: account, site, location, discipline, department
  - 2026-01-01-000003_CreatePatientCore: patient, patidentifier, pataddress, patcontact
  - 2026-01-01-000004_CreateSecurity: contact, contactdetail, userdevices, loginattempts
  - 2026-01-01-000005_CreatePatientVisits: patvisit, patinsurance
  - 2026-01-01-000006_CreateOrders: porder, orderitem
  - 2026-01-01-000007_CreateSpecimens: specimen, specmenactivity, containerdef
  - 2026-01-01-000008_CreateTestDefinitions: testdefinition, testactivity, refnum, reftxt
  - 2026-01-01-000009_CreateResults: patresult, patresultdetail, patresultcomment
  - 2026-01-01-000010_CreateLabInfrastructure: edgeres, edgestatus, edgeack, workstation
- Moved 44 JSON files from valuesets/ subdirectory to app/Libraries/Data/ root
- Added new country.json lookup
- Added _meta.json for valueset metadata
- Deleted old valuesets/_meta.json
- Renamed gender.json to sex.json for consistency with patient.Sex column
- Removed duplicate country.json from valuesets/
- AGENTS.md: Updated Lookups library documentation with new methods
- README.md: Complete rewrite of lookup/valueset documentation
- Renamed MVP_TODO.md to TODO.md
- Added VUE_SPA_IMPLEMENTATION_PLAN.md
- Removed deprecated prj_clinical laboratory quality management system_3a.docx
- ValueSet.php: Enhanced with caching and new lookup methods
- Lookups.php: Removed (functionality merged into ValueSet)
Impact: Prepares codebase for 2026 with cleaner migration history and improved
lookup data organization for the name-based valueset system.
2026-01-13 07:22:25 +07:00

173 lines
9.5 KiB
PHP

<?php
namespace App\Database\Migrations;
use CodeIgniter\Database\Migration;
class CreateTestDefinitions extends Migration {
public function up() {
$this->forge->addField([
'TestSiteID' => ['type' => 'INT', 'auto_increment' => true, 'unsigned' => true],
'SiteID' => ['type' => 'INT', 'null' => false],
'TestSiteCode' => ['type' => 'varchar', 'constraint'=> 6, 'null' => false],
'TestSiteName' => ['type' => 'varchar', 'constraint'=> 100, 'null' => false],
'TestType' => ['type' => 'VARCHAR', 'constraint' => 10, 'null' => false],
'Description' => ['type' => 'varchar', 'constraint'=> 255, 'null' => true],
'SeqScr' => ['type' => 'int', 'null' => true],
'SeqRpt' => ['type' => 'int', 'null' => true],
'IndentLeft' => ['type' => 'int', 'null' => true, 'default' => 0],
'FontStyle' => ['type' => 'varchar', 'constraint'=> 50, 'null' => true],
'VisibleScr' => ['type' => 'int', 'null' => true, 'default' => 1],
'VisibleRpt' => ['type' => 'int', 'null' => true, 'default' => 1],
'CountStat' => ['type' => 'int', 'null' => true, 'default' => 1],
'CreateDate' => ['type' => 'Datetime', 'null' => true],
'StartDate' => ['type' => 'Datetime', 'null' => true],
'EndDate' => ['type' => 'Datetime', 'null' => true],
]);
$this->forge->addKey('TestSiteID', true);
$this->forge->createTable('testdefsite');
$this->forge->addField([
'TestTechID' => ['type' => 'INT', 'auto_increment' => true, 'unsigned' => true],
'TestSiteID' => ['type' => 'INT', 'unsigned' => true, 'null' => false],
'DisciplineID' => ['type' => 'INT', 'null' => true],
'DepartmentID' => ['type' => 'INT', 'null' => true],
'ResultType' => ['type' => 'VARCHAR', 'constraint'=> 20, 'null' => true],
'RefType' => ['type' => 'VARCHAR', 'constraint'=> 10, 'null' => true],
'VSet' => ['type' => 'INT', 'null' => true],
'ReqQty' => ['type' => 'DECIMAL', 'constraint'=> '10,2', 'null' => true],
'ReqQtyUnit' => ['type' => 'varchar', 'constraint'=> 20, 'null' => true],
'Unit1' => ['type' => 'varchar', 'constraint'=> 20, 'null' => true],
'Factor' => ['type' => 'DECIMAL', 'constraint'=> '10,4', 'null' => true],
'Unit2' => ['type' => 'varchar', 'constraint'=> 20, 'null' => true],
'Decimal' => ['type' => 'int', 'null' => true, 'default' => 2],
'CollReq' => ['type' => 'varchar', 'constraint'=> 255, 'null' => true],
'Method' => ['type' => 'varchar', 'constraint'=> 50, 'null' => true],
'ExpectedTAT' => ['type' => 'INT', 'null' => true],
'CreateDate' => ['type' => 'Datetime', 'null' => true],
'EndDate' => ['type' => 'Datetime', 'null' => true]
]);
$this->forge->addKey('TestTechID', true);
$this->forge->addForeignKey('TestSiteID', 'testdefsite', 'TestSiteID', 'CASCADE', 'CASCADE');
$this->forge->createTable('testdeftech');
$this->forge->addField([
'TestCalID' => ['type' => 'INT', 'auto_increment' => true, 'unsigned' => true],
'TestSiteID' => ['type' => 'INT', 'unsigned' => true, 'null' => false],
'DisciplineID' => ['type' => 'INT', 'null' => true],
'DepartmentID' => ['type' => 'INT', 'null' => true],
'FormulaInput' => ['type' => 'text', 'null' => true],
'FormulaCode' => ['type' => 'varchar', 'constraint'=> 255, 'null' => true],
'RefType' => ['type' => 'varchar', 'constraint'=> 10, 'null' => true, 'default' => 'NMRC'],
'Unit1' => ['type' => 'varchar', 'constraint'=> 20, 'null' => true],
'Factor' => ['type' => 'DECIMAL', 'constraint'=> '10,4', 'null' => true],
'Unit2' => ['type' => 'varchar', 'constraint'=> 20, 'null' => true],
'Decimal' => ['type' => 'int', 'null' => true, 'default' => 2],
'Method' => ['type' => 'varchar', 'constraint'=> 50, 'null' => true],
'CreateDate' => ['type' => 'Datetime', 'null' => true],
'EndDate' => ['type' => 'Datetime', 'null' => true]
]);
$this->forge->addKey('TestCalID', true);
$this->forge->addForeignKey('TestSiteID', 'testdefsite', 'TestSiteID', 'CASCADE', 'CASCADE');
$this->forge->createTable('testdefcal');
$this->forge->addField([
'TestGrpID' => ['type' => 'INT', 'auto_increment' => true, 'unsigned' => true],
'TestSiteID' => ['type' => 'INT', 'unsigned' => true, 'null' => false],
'Member' => ['type' => 'INT', 'unsigned' => true, 'null' => true],
'CreateDate' => ['type' => 'Datetime', 'null' => true],
'EndDate' => ['type' => 'Datetime', 'null' => true]
]);
$this->forge->addKey('TestGrpID', true);
$this->forge->addForeignKey('TestSiteID', 'testdefsite', 'TestSiteID', 'CASCADE', 'CASCADE');
$this->forge->addForeignKey('Member', 'testdefsite', 'TestSiteID', 'CASCADE', 'CASCADE');
$this->forge->createTable('testdefgrp');
$this->forge->addField([
'TestMapID' => ['type' => 'INT', 'auto_increment' => true, 'unsigned' => true],
'TestSiteID' => ['type' => 'INT', 'unsigned' => true, 'null' => false],
'HostType' => ['type' => 'varchar', 'constraint'=> 20, 'null' => true],
'HostID' => ['type' => 'varchar', 'constraint'=> 50, 'null' => true],
'HostDataSource' => ['type' => 'varchar', 'constraint'=> 50, 'null' => true],
'HostTestCode' => ['type' => 'varchar', 'constraint'=> 10, 'null' => true],
'HostTestName' => ['type' => 'varchar', 'constraint'=> 100, 'null' => true],
'ClientType' => ['type' => 'varchar', 'constraint'=> 20, 'null' => true],
'ClientID' => ['type' => 'varchar', 'constraint'=> 50, 'null' => true],
'ClientDataSource' => ['type' => 'varchar', 'constraint'=> 50, 'null' => true],
'ConDefID' => ['type' => 'INT', 'null' => true],
'ClientTestCode' => ['type' => 'varchar', 'constraint'=> 10, 'null' => true],
'ClientTestName' => ['type' => 'varchar', 'constraint'=> 100, 'null' => true],
'CreateDate' => ['type' => 'Datetime', 'null' => true],
'EndDate' => ['type' => 'Datetime', 'null' => true]
]);
$this->forge->addKey('TestMapID', true);
$this->forge->addForeignKey('TestSiteID', 'testdefsite', 'TestSiteID', 'CASCADE', 'CASCADE');
$this->forge->createTable('testmap');
$this->forge->addField([
'RefNumID' => ['type' => 'INT', 'auto_increment' => true, 'unsigned' => true],
'SiteID' => ['type' => 'INT', 'null' => true],
'TestSiteID' => ['type' => 'INT', 'null' => false],
'SpcType' => ['type' => 'VARCHAR', 'constraint' => 10, 'null' => true],
'Sex' => ['type' => 'VARCHAR', 'constraint' => 10, 'null' => true],
'Criteria' => ['type' => 'varchar', 'constraint'=>100, 'null' => true],
'AgeStart' => ['type' => 'INT', 'null' => true],
'AgeEnd' => ['type' => 'int', 'null' => true],
'NumRefType' => ['type' => 'VARCHAR', 'constraint' => 10, 'null' => true],
'RangeType' => ['type' => 'VARCHAR', 'constraint' => 10, 'null' => true],
'LowSign' => ['type' => 'VARCHAR', 'constraint' => 10, 'null' => true],
'Low' => ['type' => 'DECIMAL', 'constraint' => '10,2', 'null' => true],
'HighSign' => ['type' => 'VARCHAR', 'constraint' => 10, 'null' => true],
'High' => ['type' => 'DECIMAL', 'constraint' => '10,2', 'null' => true],
'Display' => ['type' => 'INT', 'null' => true],
'Flag' => ['type' => 'varchar', 'constraint'=>10, 'null' => true],
'Interpretation' => ['type' => 'varchar', 'constraint'=>255, 'null' => true],
'Notes' => ['type' => 'varchar', 'constraint'=>255, 'null' => true],
'CreateDate' => ['type' => 'Datetime', 'null' => true],
'StartDate' => ['type' => 'Datetime', 'null' => true],
'EndDate' => ['type' => 'Datetime', 'null' => true],
]);
$this->forge->addKey('RefNumID', true);
$this->forge->createTable('refnum');
$this->forge->addField([
'RefTxtID' => ['type' => 'INT', 'auto_increment' => true, 'unsigned' => true],
'SiteID' => ['type' => 'INT', 'null' => true],
'TestSiteID' => ['type' => 'INT', 'null' => false],
'SpcType' => ['type' => 'varchar', 'constraint'=> 10, 'null' => false],
'Sex' => ['type' => 'VARCHAR', 'constraint' => 10, 'null' => true],
'Criteria' => ['type' => 'varchar', 'constraint'=>100, 'null' => true],
'AgeStart' => ['type' => 'INT', 'null' => true],
'AgeEnd' => ['type' => 'int', 'null' => true],
'TxtRefType' => ['type' => 'VARCHAR', 'constraint' => 10, 'null' => true],
'RefTxt' => ['type' => 'varchar', 'constraint'=>255, 'null' => true],
'Flag' => ['type' => 'varchar', 'constraint'=>10, 'null' => true],
'Notes' => ['type' => 'varchar', 'constraint'=>255, 'null' => true],
'CreateDate' => ['type' => 'Datetime', 'null' => true],
'StartDate' => ['type' => 'Datetime', 'null' => true],
'EndDate' => ['type' => 'Datetime', 'null' => true],
]);
$this->forge->addKey('RefTxtID', true);
$this->forge->createTable('reftxt');
$this->forge->addField([
'FlagDefID' => ['type' => 'INT', 'auto_increment' => true],
'InstrumentName' => ['type' => 'varchar', 'constraint' => 100, 'null' => true],
'Flag' => ['type' => 'varchar', 'constraint' => 50, 'null' => true],
]);
$this->forge->addKey('FlagDefID', true);
$this->forge->createTable('flagdef');
}
public function down() {
$this->forge->dropTable('flagdef');
$this->forge->dropTable('reftxt');
$this->forge->dropTable('refnum');
$this->forge->dropTable('testmap');
$this->forge->dropTable('testdefgrp');
$this->forge->dropTable('testdefcal');
$this->forge->dropTable('testdeftech');
$this->forge->dropTable('testdefsite');
}
}