clqms-be/app/Database/Migrations/2026-01-01-000002_CreateOrganization.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

112 lines
5.6 KiB
PHP

<?php
namespace App\Database\Migrations;
use CodeIgniter\Database\Migration;
class CreateOrganization extends Migration {
public function up() {
$this->forge->addField([
'AccountID' => ['type' => 'INT', 'unsigned' => true, 'auto_increment' => true],
'Parent' => ['type' => 'INT', 'null' => true],
'AccountName' => ['type' => 'VARCHAR', 'constraint' => 100, 'null' => false],
'Initial' => ['type' => 'VARCHAR', 'constraint' => 10, 'null' => false],
'Street_1' => ['type' => 'VARCHAR', 'constraint' => 150, 'null' => true],
'Street_2' => ['type' => 'VARCHAR', 'constraint' => 150, 'null' => true],
'Street_3' => ['type' => 'VARCHAR', 'constraint' => 150, 'null' => true],
'City' => ['type' => 'varchar', 'constraint' => 150, 'null' => true],
'Province' => ['type' => 'varchar', 'constraint' => 150, 'null' => true],
'ZIP' => ['type' => 'VARCHAR', 'constraint' => 10, 'null' => true],
'Country' => ['type' => 'VARCHAR', 'constraint' => 10, 'null' => true],
'AreaCode' => ['type' => 'VARCHAR', 'constraint' => 50, 'null' => true],
'EmailAddress1' => ['type' => 'VARCHAR', 'constraint' => 50, 'null' => true],
'EmailAddress2' => ['type' => 'VARCHAR', 'constraint' => 50, 'null' => true],
'Phone' => ['type' => 'VARCHAR', 'constraint' => 50, 'null' => true],
'Fax' => ['type' => 'VARCHAR', 'constraint' => 50, 'null' => true],
'CreateDate' => ['type' => 'datetime', 'null'=> true],
'EndDate' => ['type' => 'datetime', 'null'=> true]
]);
$this->forge->addKey('AccountID', true);
$this->forge->createTable('account');
$this->forge->addField([
'SiteID' => ['type' => 'INT', 'unsigned' => true, 'auto_increment' => true],
'SiteCode' => ['type' => 'VARCHAR', 'constraint' => 10, 'null' => false],
'SiteName' => ['type' => 'VARCHAR', 'constraint' => 100, 'null' => false],
'AccountID' => ['type' => 'int', 'null' => true],
'SiteTypeID' => ['type' => 'VARCHAR', 'constraint' => 10, 'null' => true],
'Parent' => ['type' => 'int', 'null' => true],
'SiteClassID' => ['type' => 'VARCHAR', 'constraint' => 50, 'null' => true],
'ME' => ['type' => 'VARCHAR', 'constraint' => 50, 'null' => true],
'CreateDate' => ['type' => 'datetime', 'null'=> true],
'EndDate' => ['type' => 'datetime', 'null'=> true]
]);
$this->forge->addKey('SiteID', true);
$this->forge->createTable('site');
$this->forge->addField([
'LocationID' => ['type' => 'INT', 'auto_increment' => true, 'unsigned' => true],
'SiteID' => ['type' => 'INT', 'null' => true],
'LocCode' => ['type' => 'VARCHAR', 'constraint' => 6, 'null' => false],
'Parent' => ['type' => 'INT', 'null' => true],
'LocFull' => ['type' => 'varchar', 'constraint' => 255, 'null' => true],
'Description' => ['type' => 'varchar', 'constraint' => 255, 'null' => true],
'LocType' => ['type' => 'VARCHAR', 'constraint' => 10, 'null' => true],
'CreateDate' => ['type' => 'DATETIME', 'null' => true],
'EndDate' => ['type' => 'DATETIME', 'null' => true]
]);
$this->forge->addKey('LocationID', true);
$this->forge->createTable('location');
$this->forge->addField([
'LocationID' => ['type' => 'INT', 'unsigned' => true],
'Street1' => ['type' => 'Varchar', 'constraint' => 255, 'null' => true],
'Street2' => ['type' => 'VARCHAR', 'constraint' => 255, 'null' => true],
'City' => ['type' => 'int', 'null' => true],
'Province' => ['type' => 'int', 'null' => true],
'PostCode' => ['type' => 'varchar', 'constraint' => 255, 'null' => true],
'GeoLocationSystem' => ['type' => 'varchar', 'constraint' => 255, 'null' => true],
'GeoLocationData' => ['type' => 'varchar', 'constraint' => 255, 'null' => true],
'Phone' => ['type' => 'varchar', 'constraint' => 100, 'null' => true],
'Email' => ['type' => 'varchar', 'constraint' => 150, 'null' => true],
'CreateDate' => ['type' => 'DATETIME', 'null' => true],
'EndDate' => ['type' => 'DATETIME', 'null' => true]
]);
$this->forge->addKey('LocationID', true);
$this->forge->createTable('locationaddress');
$this->forge->addField([
'DisciplineID' => ['type' => 'int', 'unsigned' => true, 'auto_increment'=> true],
'SiteID' => ['type' => 'int', 'null'=> false],
'DisciplineCode' => ['type' => 'varchar', 'constraint'=> 10, 'null'=> false],
'DisciplineName' => ['type' => 'varchar', 'constraint'=> 150, 'null'=> true],
'Parent' => ['type' => 'int', 'null'=> true],
'CreateDate' => ['type'=>'DATETIME', 'null' => true],
'EndDate' => ['type'=>'DATETIME', 'null' => true]
]);
$this->forge->addKey('DisciplineID', true);
$this->forge->createTable('discipline');
$this->forge->addField([
'DepartmentID' => ['type' => 'int', 'unsigned' => true, 'auto_increment'=> true],
'DisciplineID' => ['type' => 'int', 'null'=> false],
'SiteID' => ['type' => 'int', 'null'=> false],
'DepartmentCode' => ['type' => 'varchar', 'constraint'=>10, 'null'=> false],
'DepartmentName' => ['type' => 'varchar', 'constraint'=> 150, 'null'=> true],
'CreateDate' => ['type'=>'DATETIME', 'null' => true],
'EndDate' => ['type'=>'DATETIME', 'null' => true]
]);
$this->forge->addKey('DepartmentID', true);
$this->forge->createTable('department');
}
public function down() {
$this->forge->dropTable('department');
$this->forge->dropTable('discipline');
$this->forge->dropTable('locationaddress');
$this->forge->dropTable('location');
$this->forge->dropTable('site');
$this->forge->dropTable('account');
}
}