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

102 lines
5.5 KiB
PHP

<?php
namespace App\Database\Migrations;
use CodeIgniter\Database\Migration;
class CreateSecurity extends Migration {
public function up() {
$this->forge->addField([
'id' => ['type' => 'INT', 'auto_increment' => true, 'unsigned' => true],
'role_id' => ['type' => 'TINYINT', 'null' => false],
'username' => ['type' => 'VARCHAR', 'constraint' => 50, 'null' => true],
'password' => ['type' => 'VARCHAR', 'constraint' => 255, 'null' => true],
]);
$this->forge->addKey('id', true);
$this->forge->createTable('users');
$this->forge->addField([
'ContactID' => [ 'type' => 'INT', 'constraint' => 11, 'unsigned' => true, 'auto_increment' => true ],
'NameFirst' => [ 'type' => 'VARCHAR', 'constraint' => 100, 'null' => true ],
'NameLast' => [ 'type' => 'VARCHAR', 'constraint' => 100, 'null' => true ],
'Title' => [ 'type' => 'VARCHAR', 'constraint' => 50, 'null' => true ],
'Initial' => [ 'type' => 'VARCHAR', 'constraint' => 10, 'null' => true ],
'Birthdate' => [ 'type' => 'DATE', 'null' => true ],
'EmailAddress1' => [ 'type' => 'VARCHAR', 'constraint' => 150, 'null' => true ],
'EmailAddress2' => [ 'type' => 'VARCHAR', 'constraint' => 150, 'null' => true ],
'Phone' => [ 'type' => 'VARCHAR', 'constraint' => 50, 'null' => true ],
'MobilePhone1' => [ 'type' => 'VARCHAR', 'constraint' => 50, 'null' => true ],
'MobilePhone2' => [ 'type' => 'VARCHAR', 'constraint' => 50, 'null' => true ],
'Specialty' => [ 'type' => 'VARCHAR', 'constraint' => 100, 'null' => true ],
'SubSpecialty' => [ 'type' => 'VARCHAR', 'constraint' => 100, 'null' => true ],
'Password' => [ 'type' => 'VARCHAR', 'constraint' => 255, 'null' => true ],
'LockedAt' => [ 'type' => 'DATETIME', 'null' => true ],
'LockReason' => [ 'type' => 'VARCHAR', 'constraint' => 150, 'null' => true ],
'Role' => [ 'type' => "ENUM('admin','staff','user')", 'default' => 'user', 'null' => false ],
'CreateDate' => ['type' => 'DATETIME', 'null' => true],
'EndDate' => [ 'type' => 'DATETIME', 'null' => true ],
]);
$this->forge->addKey('ContactID', true);
$this->forge->addUniqueKey('EmailAddress1');
$this->forge->createTable('contact');
$this->forge->addField([
'ContactDetID' => [ 'type' => 'INT', 'constraint' => 11, 'unsigned' => true, 'auto_increment' => true ],
'ContactID' => [ 'type' => 'INT', 'constraint' => 11 ],
'SiteID' => [ 'type' => 'INT', 'constraint' => 11, 'null' => true ],
'ContactCode' => [ 'type' => 'varchar', 'constraint' => 11, 'null' => false ],
'ContactEmail' => [ 'type' => 'VARCHAR', 'constraint' => 150, 'null' => true ],
'OccupationID' => [ 'type' => 'VARCHAR', 'constraint' => 50, 'null' => true ],
'JobTitle' => [ 'type' => 'VARCHAR', 'constraint' => 100, 'null' => true ],
'Department' => [ 'type' => 'VARCHAR', 'constraint' => 100, 'null' => true ],
'ContactStartDate' => [ 'type' => 'DATETIME', 'null' => true ],
'ContactEndDate' => [ 'type' => 'DATETIME ', 'null' => true ],
]);
$this->forge->addKey('ContactDetID', true);
$this->forge->addUniqueKey(['SiteID','ContactID']);
$this->forge->createTable('contactdetail');
$this->forge->addField([
'UserDeviceId' => ['type' => 'CHAR', 'constraint' => 36],
'ContactID' => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true],
'DeviceFingerprint' => ['type' => 'CHAR', 'constraint' => 64],
'DeviceLabel' => ['type' => 'VARCHAR', 'constraint' => 100, 'null' => true],
'Browser' => ['type' => 'VARCHAR', 'constraint' => 50, 'null' => true],
'BrowserVersion' => ['type' => 'VARCHAR', 'constraint' => 20, 'null' => true],
'Platform' => ['type' => 'VARCHAR', 'constraint' => 50, 'null' => true],
'Timezone' => ['type' => 'VARCHAR', 'constraint' => 50],
'Language' => ['type' => 'VARCHAR', 'constraint' => 10],
'IpAddress' => ['type' => 'VARCHAR', 'constraint' => 45],
'FirstLoginAt' => ['type' => 'DATETIME'],
'LastLoginAt' => ['type' => 'DATETIME'],
'IsActive' => ['type' => 'TINYINT', 'constraint' => 1, 'default' => 1],
]);
$this->forge->addKey('UserDeviceId', true);
$this->forge->addKey(['ContactID', 'DeviceFingerprint'], false, true);
$this->forge->createTable('userdevices', true);
$this->forge->addField([
'LoginAttemptId' => ['type' => 'BIGINT', 'unsigned' => true, 'auto_increment' => true],
'ContactID' => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true],
'DeviceId' => ['type' => 'CHAR', 'constraint' => 36, 'null' => true],
'IpAddress' => ['type' => 'VARCHAR', 'constraint' => 45],
'AttemptAt' => ['type' => 'DATETIME'],
'IsSuccess' => ['type' => 'TINYINT', 'constraint' => 1],
'FailureReason' => ['type' => 'VARCHAR', 'constraint' => 50, 'null' => true],
]);
$this->forge->addKey('LoginAttemptId', true);
$this->forge->addKey('ContactID');
$this->forge->addKey(['IpAddress', 'AttemptAt']);
$this->forge->addKey(['ContactID', 'AttemptAt']);
$this->forge->createTable('loginattempts', true);
}
public function down() {
$this->forge->dropTable('loginattempts');
$this->forge->dropTable('userdevices');
$this->forge->dropTable('contactdetail');
$this->forge->dropTable('contact');
$this->forge->dropTable('users');
}
}