creating test seeder

This commit is contained in:
mahdahar 2025-12-16 13:43:06 +07:00
parent 0be8b67895
commit d1d3b261ae
6 changed files with 847 additions and 106 deletions

View File

@ -6,22 +6,6 @@ use CodeIgniter\Database\Migration;
class CreateTestsTable extends Migration {
public function up() {
$this->forge->addField([
'TestID' => ['type' => 'INT', 'auto_increment' => true, 'unsigned' => true],
'Parent' => ['type' => 'INT', 'null' => true],
'TestCode' => ['type' => 'VARCHAR', 'constraint'=> 6, 'null' => false],
'TestName' => ['type' => 'varchar', 'constraint'=> 50, 'null' => false],
'Description' => ['type' => 'VARCHAR', 'constraint'=> 150, 'null' => false],
'DisciplineID' => ['type' => 'INT', 'null' => false],
'Method' => ['type' => 'varchar', 'constraint'=>50, 'null' => true],
'Seq' => ['type' => 'int', 'constraint'=> 15, 'null' => true],
'CountStat' => ['type' => 'int', 'null' => true ],
'CreateDate' => ['type' => 'Datetime', 'null' => true],
'EndDate' => ['type' => 'Datetime', 'null' => true],
]);
$this->forge->addKey('TestID', true);
$this->forge->createTable('testdef');
$this->forge->addField([
'TestSiteID' => ['type' => 'INT', 'auto_increment' => true, 'unsigned' => true],
'SiteID' => ['type' => 'INT', 'null' => false],
@ -117,7 +101,6 @@ class CreateTestsTable extends Migration {
}
public function down() {
$this->forge->dropTable('testdef');
$this->forge->dropTable('testdefsite');
$this->forge->dropTable('testdeftech');
$this->forge->dropTable('testdefcal');

View File

@ -15,126 +15,230 @@ class TestSeeder extends Seeder {
foreach ($rows as $row) {
$vs[$row['VSetID']][$row['VValue']] = $row['VID'];
}
/*
$data = ['SiteID' => '1','TestSiteCode' => 'QTESTNUM', 'TestSiteName' =>'Dummy Test', 'TestType' => $vs[27]['TEST'],'Description' => '',
'SeqScr' => '4','SeqRpt' => '4','VisibleScr' => $vs[2][1],'VisibleRpt' => $vs[2][1],'CountStat' => $vs[2][1],'CreateDate' => "$now"];
// TestType mapping from VSetID=27:
// TEST = $vs[27]['TEST']
// PARAM = $vs[27]['PARAM']
// CALC = $vs[27]['CALC']
// GROUP = $vs[27]['GROUP']
// TITLE = $vs[27]['TITLE']
// ========================================
// TITLE TYPE - Headers/Sections
// ========================================
$data = ['SiteID' => '1', 'TestSiteCode' => 'HDR-HEMA', 'TestSiteName' => 'HEMATOLOGY', 'Type' => $vs[27]['TITLE'], 'Description' => 'Hematology Section Header', 'SeqScr' => '1', 'SeqRpt' => '1', 'IndentLeft' => '0', 'VisibleScr' => $vs[2][1], 'VisibleRpt' => $vs[2][1], 'CountStat' => $vs[2][0], 'CreateDate' => "$now"];
$this->db->table('testdefsite')->insert($data);
$data = ['DisciplineID' => '1', 'DepartmentID' =>'1', 'ResultType'=>$vs[43]['NMRIC'], 'RefType'=>[44]['RANGE'], 'VSet' => '', 'ReqQty'=> '500',
'ReqQtyUnit'=>'mL','Unit1' => 'g/dL','Factor' => '','Unit2' => '', 'CollReq'=>'', 'Method' => '','CreateDate' => "$now"];
$data['TestSiteID']= $this->db->insertID();
$this->db->table('testdeftech')->insert($data);
/*
$data = ['SiteID' => '1','TestSiteCode' => 'HB', 'TestSiteName' =>'Hemoglobin', 'TestType' => $vs[27]['Test'],'Description' => '','SeqScr' => '4','SeqRpt' => '4','VisibleScr' => $vs[2][1],'VisibleRpt' => $vs[2][1],'CountStat' => $vs[2][1],'CreateDate' => "$now"];
$data = ['SiteID' => '1', 'TestSiteCode' => 'HDR-CHEM', 'TestSiteName' => 'CHEMISTRY', 'Type' => $vs[27]['TITLE'], 'Description' => 'Chemistry Section Header', 'SeqScr' => '10', 'SeqRpt' => '10', 'IndentLeft' => '0', 'VisibleScr' => $vs[2][1], 'VisibleRpt' => $vs[2][1], 'CountStat' => $vs[2][0], 'CreateDate' => "$now"];
$this->db->table('testdefsite')->insert($data);
$data = ['DisciplineID' => '1', 'DepartmentID' =>'1', 'VSet' => '','SpcType' => $vs[15]['BLD'] ,'Unit1' => 'g/dL','Factor' => '','Unit2' => '','Method' => '','CreateDate' => "$now"];
$data['TestSiteID']= $this->db->insertID();
$data = ['SiteID' => '1', 'TestSiteCode' => 'HDR-URIN', 'TestSiteName' => 'URINALYSIS', 'Type' => $vs[27]['TITLE'], 'Description' => 'Urinalysis Section Header', 'SeqScr' => '30', 'SeqRpt' => '30', 'IndentLeft' => '0', 'VisibleScr' => $vs[2][1], 'VisibleRpt' => $vs[2][1], 'CountStat' => $vs[2][0], 'CreateDate' => "$now"];
$this->db->table('testdefsite')->insert($data);
// ========================================
// TEST TYPE - Actual Laboratory Tests
// ========================================
// Hematology Tests
$data = ['SiteID' => '1', 'TestSiteCode' => 'HB', 'TestSiteName' => 'Hemoglobin', 'Type' => $vs[27]['TEST'], 'Description' => '', 'SeqScr' => '2', 'SeqRpt' => '2', 'IndentLeft' => '1', 'VisibleScr' => $vs[2][1], 'VisibleRpt' => $vs[2][1], 'CountStat' => $vs[2][1], 'CreateDate' => "$now"];
$this->db->table('testdefsite')->insert($data);
$testSiteID = $this->db->insertID();
$data = ['SiteID' => '1', 'TestSiteID' => $testSiteID, 'DisciplineID' => '1', 'DepartmentID' => '1', 'ResultType' => $vs[43]['NMRIC'], 'RefType' => $vs[44]['RANGE'], 'VSet' => '', 'SpcType' => $vs[15]['BLD'], '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' =>'Hematokrit', 'TestType' => $vs[27]['Test'],'Description' => '','SeqScr' => '5','SeqRpt' => '5','VisibleScr' => $vs[2][1],'VisibleRpt' => $vs[2][1],'CountStat' => $vs[2][1],'CreateDate' => "$now"];
$data = ['SiteID' => '1', 'TestSiteCode' => 'HCT', 'TestSiteName' => 'Hematocrit', 'Type' => $vs[27]['TEST'], 'Description' => '', 'SeqScr' => '3', 'SeqRpt' => '3', 'IndentLeft' => '1', 'VisibleScr' => $vs[2][1], 'VisibleRpt' => $vs[2][1], 'CountStat' => $vs[2][1], 'CreateDate' => "$now"];
$this->db->table('testdefsite')->insert($data);
$data = ['DisciplineID' => '1', 'DepartmentID' =>'1', 'VSet' => '','SpcType' => $vs[15]['BLD'],'Unit1' => '%','Factor' => '','Unit2' => '','Method' => '','CreateDate' => "$now"];
$data['TestSiteID']= $this->db->insertID();
$testSiteID = $this->db->insertID();
$data = ['SiteID' => '1', 'TestSiteID' => $testSiteID, 'DisciplineID' => '1', 'DepartmentID' => '1', 'ResultType' => $vs[43]['NMRIC'], 'RefType' => $vs[44]['RANGE'], 'VSet' => '', 'SpcType' => $vs[15]['BLD'], 'ReqQty' => '500', 'ReqQtyUnit' => 'uL', 'Unit1' => '%', 'Factor' => '', 'Unit2' => '', 'Decimal' => '1', 'Method' => 'CBC Analyzer', 'CreateDate' => "$now"];
$this->db->table('testdeftech')->insert($data);
$data = ['SiteID' => '1','TestSiteCode' => 'ERY', 'TestSiteName' =>'Eritrosit', 'TestType' => $vs[27]['Test'],'Description' => '','SeqScr' => '6','SeqRpt' => '6','VisibleScr' => $vs[2][1],'VisibleRpt' => $vs[2][1],'CountStat' => $vs[2][1],'CreateDate' => "$now"];
$data = ['SiteID' => '1', 'TestSiteCode' => 'RBC', 'TestSiteName' => 'Red Blood Cell', 'Type' => $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"];
$this->db->table('testdefsite')->insert($data);
$data = [ 'DisciplineID' => '1', 'DepartmentID' =>'1', 'VSet' => '','SpcType' => $vs[15]['BLD'], 'Unit1' => '10^6/mL','Factor' => '','Unit2' => '','Method' => '','CreateDate' => "$now"];
$data['TestSiteID']= $this->db->insertID();
$testSiteID = $this->db->insertID();
$data = ['SiteID' => '1', 'TestSiteID' => $testSiteID, 'DisciplineID' => '1', 'DepartmentID' => '1', 'ResultType' => $vs[43]['NMRIC'], 'RefType' => $vs[44]['RANGE'], 'VSet' => '', 'SpcType' => $vs[15]['BLD'], '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' => 'MCV', 'TestSiteName' =>'MCV', 'TestType' => $vs[27]['Test'],'Description' => '','SeqScr' => '8','SeqRpt' => '8','VisibleScr' => $vs[2][1],'VisibleRpt' => $vs[2][1],'CountStat' => $vs[2][1],'CreateDate' => "$now"];
$data = ['SiteID' => '1', 'TestSiteCode' => 'WBC', 'TestSiteName' => 'White Blood Cell', 'Type' => $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"];
$this->db->table('testdefsite')->insert($data);
$data = ['SiteID' => '1','TestSiteCode' => 'MCH', 'TestSiteName' =>'MCH', 'TestType' => $vs[27]['Test'],'Description' => '','SeqScr' => '9','SeqRpt' => '9','VisibleScr' => $vs[2][1],'VisibleRpt' => $vs[2][1],'CountStat' => $vs[2][1],'CreateDate' => "$now"];
$this->db->table('testdefsite')->insert($data);
$data = ['SiteID' => '1','TestSiteCode' => 'MCHC', 'TestSiteName' =>'MCHC', 'TestType' => $vs[27]['Test'],'Description' => '','SeqScr' => '10','SeqRpt' => '10','VisibleScr' => $vs[2][1],'VisibleRpt' => $vs[2][1],'CountStat' => $vs[2][1],'CreateDate' => "$now"];
$this->db->table('testdefsite')->insert($data);
$data = ['SiteID' => '1','TestSiteCode' => 'GLUAR', 'TestSiteName' =>'Glukosa Sewaktu', 'TestType' => $vs[27]['Test'],'Description' => '','SeqScr' => '13','SeqRpt' => '13','VisibleScr' => $vs[2][1],'VisibleRpt' => $vs[2][1],'CountStat' => $vs[2][1],'CreateDate' => "$now"];
$this->db->table('testdefsite')->insert($data);
$data = ['DisciplineID' => '2', 'DepartmentID' =>'3', 'VSet' => '','SpcType' => $vs[15]['SER'],'Unit1' => 'U/L','Factor' => '','Unit2' => '','Method' => 'Hexokinase','CreateDate' => "$now"];
$data['TestSiteID']= $this->db->insertID();
$testSiteID = $this->db->insertID();
$data = ['SiteID' => '1', 'TestSiteID' => $testSiteID, 'DisciplineID' => '1', 'DepartmentID' => '1', 'ResultType' => $vs[43]['NMRIC'], 'RefType' => $vs[44]['RANGE'], 'VSet' => '', 'SpcType' => $vs[15]['BLD'], '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' => 'GLUF', 'TestSiteName' =>'Glukosa Puasa', 'TestType' => $vs[27]['Test'],'Description' => '','SeqScr' => '14','SeqRpt' => '14','VisibleScr' => $vs[2][1],'VisibleRpt' => $vs[2][1],'CountStat' => $vs[2][1],'CreateDate' => "$now"];
$data = ['SiteID' => '1', 'TestSiteCode' => 'PLT', 'TestSiteName' => 'Platelet', 'Type' => $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"];
$this->db->table('testdefsite')->insert($data);
$data = [ 'DisciplineID' => '2', 'DepartmentID' =>'3', 'VSet' => '','SpcType' => $vs[15]['SER'], 'Unit1' => 'U/L','Factor' => '','Unit2' => '','Method' => 'Hexokinase','CreateDate' => "$now"];
$data['TestSiteID']= $this->db->insertID();
$testSiteID = $this->db->insertID();
$data = ['SiteID' => '1', 'TestSiteID' => $testSiteID, 'DisciplineID' => '1', 'DepartmentID' => '1', 'ResultType' => $vs[43]['NMRIC'], 'RefType' => $vs[44]['RANGE'], 'VSet' => '', 'SpcType' => $vs[15]['BLD'], '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' => 'GLU2HPP', 'TestSiteName' =>'Glukosa 2 Jam PP', 'TestType' => $vs[27]['Test'],'Description' => '','SeqScr' => '15','SeqRpt' => '15','VisibleScr' => $vs[2][1],'VisibleRpt' => $vs[2][1],'CountStat' => $vs[2][1],'CreateDate' => "$now"];
$data = ['SiteID' => '1', 'TestSiteCode' => 'MCV', 'TestSiteName' => 'MCV', 'Type' => $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"];
$this->db->table('testdefsite')->insert($data);
$data = ['DisciplineID' => '2', 'DepartmentID' =>'3', 'VSet' => '','SpcType' => $vs[15]['SER'], 'Unit1' => 'mg/dL','Factor' => '','Unit2' => '','Method' => 'Hexokinase','CreateDate' => "$now"];
$data['TestSiteID']= $this->db->insertID();
$testSiteID = $this->db->insertID();
$data = ['SiteID' => '1', 'TestSiteID' => $testSiteID, 'DisciplineID' => '1', 'DepartmentID' => '1', 'ResultType' => $vs[43]['NMRIC'], 'RefType' => $vs[44]['RANGE'], 'VSet' => '', 'SpcType' => $vs[15]['BLD'], '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' => 'TC', 'TestSiteName' =>'Cholesterol Total', 'TestType' => $vs[27]['Test'],'Description' => '','SeqScr' => '17','SeqRpt' => '17','VisibleScr' => $vs[2][1],'VisibleRpt' => $vs[2][1],'CountStat' => $vs[2][1],'CreateDate' => "$now"];
$data = ['SiteID' => '1', 'TestSiteCode' => 'MCH', 'TestSiteName' => 'MCH', 'Type' => $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"];
$this->db->table('testdefsite')->insert($data);
$data = ['SiteID' => '1','TestSiteCode' => 'LDL', 'TestSiteName' =>'Cholesterol LDL Direk', 'TestType' => $vs[27]['Test'],'Description' => '','SeqScr' => '18','SeqRpt' => '18','VisibleScr' => $vs[2][1],'VisibleRpt' => $vs[2][1],'CountStat' => $vs[2][1],'CreateDate' => "$now"];
$this->db->table('testdefsite')->insert($data);
$data = ['SiteID' => '1','TestSiteCode' => 'HDL', 'TestSiteName' =>'Cholesterol HDL', 'TestType' => $vs[27]['Test'],'Description' => '','SeqScr' => '19','SeqRpt' => '19','VisibleScr' => $vs[2][1],'VisibleRpt' => $vs[2][1],'CountStat' => $vs[2][1],'CreateDate' => "$now"];
$this->db->table('testdefsite')->insert($data);
$data = ['SiteID' => '1','TestSiteCode' => 'TG', 'TestSiteName' =>'Trigliserida', 'TestType' => $vs[27]['Test'],'Description' => '','SeqScr' => '20','SeqRpt' => '20','VisibleScr' => $vs[2][1],'VisibleRpt' => $vs[2][1],'CountStat' => $vs[2][1],'CreateDate' => "$now"];
$this->db->table('testdefsite')->insert($data);
$data = ['SiteID' => '1','TestSiteCode' => 'SGOT', 'TestSiteName' =>'Aspartate Aminotransferase', 'TestType' => $vs[27]['Test'],'Description' => '','SeqScr' => '23','SeqRpt' => '23','VisibleScr' => $vs[2][1],'VisibleRpt' => $vs[2][1],'CountStat' => $vs[2][1],'CreateDate' => "$now"];
$this->db->table('testdefsite')->insert($data);
$data = ['DisciplineID' => '2', 'DepartmentID' =>'3', 'VSet' => '','SpcType' => $vs[15]['SER'], 'Unit1' => 'mg/dL','Factor' => '0.017','Unit2' => 'mkat/L','Method' => 'IFCC','CreateDate' => "$now"];
$data['TestSiteID']= $this->db->insertID();
$testSiteID = $this->db->insertID();
$data = ['SiteID' => '1', 'TestSiteID' => $testSiteID, 'DisciplineID' => '1', 'DepartmentID' => '1', 'ResultType' => $vs[43]['NMRIC'], 'RefType' => $vs[44]['RANGE'], 'VSet' => '', 'SpcType' => $vs[15]['BLD'], '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' => 'SGPT', 'TestSiteName' =>'Alanine Aminotransferase', 'TestType' => $vs[27]['Test'],'Description' => '','SeqScr' => '24','SeqRpt' => '24','VisibleScr' => $vs[2][1],'VisibleRpt' => $vs[2][1],'CountStat' => $vs[2][1],'CreateDate' => "$now"];
$data = ['SiteID' => '1', 'TestSiteCode' => 'MCHC', 'TestSiteName' => 'MCHC', 'Type' => $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"];
$this->db->table('testdefsite')->insert($data);
$data = ['DisciplineID' => '2', 'DepartmentID' =>'3', 'VSet' => '','SpcType' => $vs[15]['SER'], 'Unit1' => 'mg/dL','Factor' => '','Unit2' => '','Method' => 'IFCC','CreateDate' => "$now"];
$data['TestSiteID']= $this->db->insertID();
$testSiteID = $this->db->insertID();
$data = ['SiteID' => '1', 'TestSiteID' => $testSiteID, 'DisciplineID' => '1', 'DepartmentID' => '1', 'ResultType' => $vs[43]['NMRIC'], 'RefType' => $vs[44]['RANGE'], 'VSet' => '', 'SpcType' => $vs[15]['BLD'], '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' => 'CREA', 'TestSiteName' =>'Kreatinin', 'TestType' => $vs[27]['Test'],'Description' => '','SeqScr' => '26','SeqRpt' => '26','VisibleScr' => $vs[2][1],'VisibleRpt' => $vs[2][1],'CountStat' => $vs[2][1],'CreateDate' => "$now"];
// Chemistry Tests
$data = ['SiteID' => '1', 'TestSiteCode' => 'GLU', 'TestSiteName' => 'Glucose', 'Type' => $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"];
$this->db->table('testdefsite')->insert($data);
$data = ['DisciplineID' => '2', 'DepartmentID' =>'3', 'VSet' => '','SpcType' => $vs[15]['SER'], 'Unit1' => 'mg/dL','Factor' => '88.4','Unit2' => 'mmol/L','Method' => 'Enzymatic','CreateDate' => "$now"];
$data['TestSiteID']= $this->db->insertID();
$testSiteID = $this->db->insertID();
$data = ['SiteID' => '1', 'TestSiteID' => $testSiteID, 'DisciplineID' => '2', 'DepartmentID' => '2', 'ResultType' => $vs[43]['NMRIC'], 'RefType' => $vs[44]['RANGE'], 'VSet' => '', 'SpcType' => $vs[15]['SER'], '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' => 'CREAU', 'TestSiteName' =>'Kreatinin Urin', 'TestType' => $vs[27]['Test'],'Description' => '','SeqScr' => '27','SeqRpt' => '27','VisibleScr' => $vs[2][1],'VisibleRpt' => $vs[2][1],'CountStat' => $vs[2][1],'CreateDate' => "$now"];
$data = ['SiteID' => '1', 'TestSiteCode' => 'CREA', 'TestSiteName' => 'Creatinine', 'Type' => $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"];
$this->db->table('testdefsite')->insert($data);
$data = ['SiteID' => '1','TestSiteCode' => 'CREAC', 'TestSiteName' =>'Creatinine Clearance', 'TestType' => $vs[27]['CalN'],'Description' => 'Cockcroft-Gault formula','SeqScr' => '28','SeqRpt' => '28','VisibleScr' => $vs[2][1],'VisibleRpt' => $vs[2][1],'CountStat' => $vs[2][0],'CreateDate' => "$now"];
$this->db->table('testdefsite')->insert($data);
$data = ['SiteID' => '1','TestSiteCode' => 'COLOR', 'TestSiteName' =>'Warna', 'TestType' => $vs[27]['Test'],'Description' => '','SeqScr' => '30','SeqRpt' => '30','VisibleScr' => $vs[2][1],'VisibleRpt' => $vs[2][1],'CountStat' => $vs[2][1],'CreateDate' => "$now"];
$this->db->table('testdefsite')->insert($data);
$data = ['DisciplineID' => '4', 'DepartmentID' =>'6', 'VSet' => '1002','SpcType' => $vs[15]['SER'], 'Unit1' => '','Factor' => '','Unit2' => '','Method' => '','CreateDate' => "$now"];
$data['TestSiteID']= $this->db->insertID();
$testSiteID = $this->db->insertID();
$data = ['SiteID' => '1', 'TestSiteID' => $testSiteID, 'DisciplineID' => '2', 'DepartmentID' => '2', 'ResultType' => $vs[43]['NMRIC'], 'RefType' => $vs[44]['RANGE'], 'VSet' => '', 'SpcType' => $vs[15]['SER'], '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' => 'HEIGHT', 'TestSiteName' =>'Tinggi badan', 'TestType' => $vs[27]['PARAM'],'Description' => '','SeqScr' => '31','SeqRpt' => '31','VisibleScr' => $vs[2][1],'VisibleRpt' => $vs[2][1],'CountStat' => $vs[2][0],'CreateDate' => "$now"];
$data = ['SiteID' => '1', 'TestSiteCode' => 'UREA', 'TestSiteName' => 'Blood Urea Nitrogen', 'Type' => $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"];
$this->db->table('testdefsite')->insert($data);
$data = ['DisciplineID' => '10', 'DepartmentID' =>'', 'VSet' => '','SpcType' => '', 'Unit1' => 'm','Factor' => '','Unit2' => '','Method' => '','CreateDate' => "$now"];
$data['TestSiteID']= $this->db->insertID();
$testSiteID = $this->db->insertID();
$data = ['SiteID' => '1', 'TestSiteID' => $testSiteID, 'DisciplineID' => '2', 'DepartmentID' => '2', 'ResultType' => $vs[43]['NMRIC'], 'RefType' => $vs[44]['RANGE'], 'VSet' => '', 'SpcType' => $vs[15]['SER'], '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' => 'WEIGHT', 'TestSiteName' =>'Berat badan', 'TestType' => $vs[27]['PARAM'],'Description' => '','SeqScr' => '32','SeqRpt' => '32','VisibleScr' => $vs[2][1],'VisibleRpt' => $vs[2][1],'CountStat' => $vs[2][0],'CreateDate' => "$now"];
$data = ['SiteID' => '1', 'TestSiteCode' => 'SGOT', 'TestSiteName' => 'AST (SGOT)', 'Type' => $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"];
$this->db->table('testdefsite')->insert($data);
$data = ['DisciplineID' => '10', 'DepartmentID' =>'', 'VSet' => '','SpcType' => '', 'Unit1' => 'Kg','Factor' => '','Unit2' => '','Method' => '','CreateDate' => "$now"];
$data['TestSiteID']= $this->db->insertID();
$testSiteID = $this->db->insertID();
$data = ['SiteID' => '1', 'TestSiteID' => $testSiteID, 'DisciplineID' => '2', 'DepartmentID' => '2', 'ResultType' => $vs[43]['NMRIC'], 'RefType' => $vs[44]['RANGE'], 'VSet' => '', 'SpcType' => $vs[15]['SER'], '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' => 'WAIST', 'TestSiteName' =>'Lingkar pinggang', 'TestType' => $vs[27]['PARAM'],'Description' => '','SeqScr' => '33','SeqRpt' => '33','VisibleScr' => $vs[2][1],'VisibleRpt' => $vs[2][1],'CountStat' => $vs[2][0],'CreateDate' => "$now"];
$data = ['SiteID' => '1', 'TestSiteCode' => 'SGPT', 'TestSiteName' => 'ALT (SGPT)', 'Type' => $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"];
$this->db->table('testdefsite')->insert($data);
$data = ['SiteID' => '1','TestSiteCode' => 'AGE', 'TestSiteName' =>'Usia', 'TestType' => $vs[27]['PARAM'],'Description' => '','SeqScr' => '34','SeqRpt' => '34','VisibleScr' => $vs[2][1],'VisibleRpt' => '0','CountStat' => $vs[2][0],'CreateDate' => "$now"];
$testSiteID = $this->db->insertID();
$data = ['SiteID' => '1', 'TestSiteID' => $testSiteID, 'DisciplineID' => '2', 'DepartmentID' => '2', 'ResultType' => $vs[43]['NMRIC'], 'RefType' => $vs[44]['RANGE'], 'VSet' => '', 'SpcType' => $vs[15]['SER'], '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', 'Type' => $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"];
$this->db->table('testdefsite')->insert($data);
$data = ['SiteID' => '1','TestSiteCode' => 'SISTL', 'TestSiteName' =>'Sistolik', 'TestType' => $vs[27]['PARAM'],'Description' => '','SeqScr' => '35','SeqRpt' => '35','VisibleScr' => $vs[2][1],'VisibleRpt' => $vs[2][1],'CountStat' => $vs[2][0],'CreateDate' => "$now"];
$testSiteID = $this->db->insertID();
$data = ['SiteID' => '1', 'TestSiteID' => $testSiteID, 'DisciplineID' => '2', 'DepartmentID' => '2', 'ResultType' => $vs[43]['NMRIC'], 'RefType' => $vs[44]['THOLD'], 'VSet' => '', 'SpcType' => $vs[15]['SER'], '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', 'Type' => $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"];
$this->db->table('testdefsite')->insert($data);
$data = ['SiteID' => '1','TestSiteCode' => 'DIASTL', 'TestSiteName' =>'Diastolik', 'TestType' => $vs[27]['PARAM'],'Description' => '','SeqScr' => '36','SeqRpt' => '36','VisibleScr' => $vs[2][1],'VisibleRpt' => $vs[2][1],'CountStat' => $vs[2][0],'CreateDate' => "$now"];
$testSiteID = $this->db->insertID();
$data = ['SiteID' => '1', 'TestSiteID' => $testSiteID, 'DisciplineID' => '2', 'DepartmentID' => '2', 'ResultType' => $vs[43]['NMRIC'], 'RefType' => $vs[44]['THOLD'], 'VSet' => '', 'SpcType' => $vs[15]['SER'], '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', 'Type' => $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"];
$this->db->table('testdefsite')->insert($data);
*/
$testSiteID = $this->db->insertID();
$data = ['SiteID' => '1', 'TestSiteID' => $testSiteID, 'DisciplineID' => '2', 'DepartmentID' => '2', 'ResultType' => $vs[43]['NMRIC'], 'RefType' => $vs[44]['THOLD'], 'VSet' => '', 'SpcType' => $vs[15]['SER'], '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', 'Type' => $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"];
$this->db->table('testdefsite')->insert($data);
$testSiteID = $this->db->insertID();
$data = ['SiteID' => '1', 'TestSiteID' => $testSiteID, 'DisciplineID' => '2', 'DepartmentID' => '2', 'ResultType' => $vs[43]['NMRIC'], 'RefType' => $vs[44]['THOLD'], 'VSet' => '', 'SpcType' => $vs[15]['SER'], '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', 'Type' => $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"];
$this->db->table('testdefsite')->insert($data);
$testSiteID = $this->db->insertID();
$data = ['SiteID' => '1', 'TestSiteID' => $testSiteID, 'DisciplineID' => '10', 'DepartmentID' => '', 'ResultType' => $vs[43]['NMRIC'], 'RefType' => '', 'VSet' => '', 'SpcType' => '', 'ReqQty' => '', 'ReqQtyUnit' => '', 'Unit1' => 'cm', 'Factor' => '', 'Unit2' => '', 'Decimal' => '0', 'Method' => '', 'CreateDate' => "$now"];
$this->db->table('testdeftech')->insert($data);
$data = ['SiteID' => '1', 'TestSiteCode' => 'WEIGHT', 'TestSiteName' => 'Weight', 'Type' => $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"];
$this->db->table('testdefsite')->insert($data);
$testSiteID = $this->db->insertID();
$data = ['SiteID' => '1', 'TestSiteID' => $testSiteID, 'DisciplineID' => '10', 'DepartmentID' => '', 'ResultType' => $vs[43]['NMRIC'], 'RefType' => '', 'VSet' => '', 'SpcType' => '', 'ReqQty' => '', 'ReqQtyUnit' => '', 'Unit1' => 'kg', 'Factor' => '', 'Unit2' => '', 'Decimal' => '1', 'Method' => '', 'CreateDate' => "$now"];
$this->db->table('testdeftech')->insert($data);
$data = ['SiteID' => '1', 'TestSiteCode' => 'AGE', 'TestSiteName' => 'Age', 'Type' => $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"];
$this->db->table('testdefsite')->insert($data);
$testSiteID = $this->db->insertID();
$data = ['SiteID' => '1', 'TestSiteID' => $testSiteID, 'DisciplineID' => '10', 'DepartmentID' => '', 'ResultType' => $vs[43]['NMRIC'], 'RefType' => '', 'VSet' => '', 'SpcType' => '', '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', 'Type' => $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"];
$this->db->table('testdefsite')->insert($data);
$testSiteID = $this->db->insertID();
$data = ['SiteID' => '1', 'TestSiteID' => $testSiteID, 'DisciplineID' => '10', 'DepartmentID' => '', 'ResultType' => $vs[43]['NMRIC'], 'RefType' => '', 'VSet' => '', 'SpcType' => '', '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', 'Type' => $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"];
$this->db->table('testdefsite')->insert($data);
$testSiteID = $this->db->insertID();
$data = ['SiteID' => '1', 'TestSiteID' => $testSiteID, 'DisciplineID' => '10', 'DepartmentID' => '', 'ResultType' => $vs[43]['NMRIC'], 'RefType' => '', 'VSet' => '', 'SpcType' => '', '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', 'Type' => $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"];
$this->db->table('testdefsite')->insert($data);
$testSiteID = $this->db->insertID();
$data = ['SiteID' => '1', 'TestSiteID' => $testSiteID, '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)', 'Type' => $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"];
$this->db->table('testdefsite')->insert($data);
$testSiteID = $this->db->insertID();
$data = ['SiteID' => '1', 'TestSiteID' => $testSiteID, '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)', 'Type' => $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"];
$this->db->table('testdefsite')->insert($data);
$testSiteID = $this->db->insertID();
$data = ['SiteID' => '1', 'TestSiteID' => $testSiteID, 'DisciplineID' => '2', 'DepartmentID' => '2', 'FormulaInput' => 'CHOL,HDL,TG', 'FormulaCode' => 'CHOL - HDL - (TG/5)', 'Unit1' => 'mg/dL', 'Factor' => '', 'Unit2' => '', 'Decimal' => '0', 'CreateDate' => "$now"];
$this->db->table('testdefcal')->insert($data);
// ========================================
// GROUP TYPE - Panel/Profile Tests
// ========================================
$data = ['SiteID' => '1', 'TestSiteCode' => 'CBC', 'TestSiteName' => 'Complete Blood Count', 'Type' => $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"];
$this->db->table('testdefsite')->insert($data);
$cbcID = $this->db->insertID();
$data = ['SiteID' => '1', 'TestSiteCode' => 'LIPID', 'TestSiteName' => 'Lipid Profile', 'Type' => $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"];
$this->db->table('testdefsite')->insert($data);
$lipidID = $this->db->insertID();
$data = ['SiteID' => '1', 'TestSiteCode' => 'LFT', 'TestSiteName' => 'Liver Function Test', 'Type' => $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"];
$this->db->table('testdefsite')->insert($data);
$lftID = $this->db->insertID();
$data = ['SiteID' => '1', 'TestSiteCode' => 'RFT', 'TestSiteName' => 'Renal Function Test', 'Type' => $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"];
$this->db->table('testdefsite')->insert($data);
$rftID = $this->db->insertID();
// Urinalysis Tests (with valueset result type)
$data = ['SiteID' => '1', 'TestSiteCode' => 'UCOLOR', 'TestSiteName' => 'Urine Color', 'Type' => $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"];
$this->db->table('testdefsite')->insert($data);
$testSiteID = $this->db->insertID();
$data = ['SiteID' => '1', 'TestSiteID' => $testSiteID, 'DisciplineID' => '4', 'DepartmentID' => '4', 'ResultType' => $vs[43]['VSET'], 'RefType' => $vs[44]['VSET'], 'VSet' => '1001', 'SpcType' => $vs[15]['UR'], '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', 'Type' => $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"];
$this->db->table('testdefsite')->insert($data);
$testSiteID = $this->db->insertID();
$data = ['SiteID' => '1', 'TestSiteID' => $testSiteID, 'DisciplineID' => '4', 'DepartmentID' => '4', 'ResultType' => $vs[43]['VSET'], 'RefType' => $vs[44]['VSET'], 'VSet' => '1002', 'SpcType' => $vs[15]['UR'], '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', 'Type' => $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"];
$this->db->table('testdefsite')->insert($data);
$testSiteID = $this->db->insertID();
$data = ['SiteID' => '1', 'TestSiteID' => $testSiteID, 'DisciplineID' => '4', 'DepartmentID' => '4', 'ResultType' => $vs[43]['VSET'], 'RefType' => $vs[44]['VSET'], 'VSet' => '1003', 'SpcType' => $vs[15]['UR'], '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', 'Type' => $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"];
$this->db->table('testdefsite')->insert($data);
$testSiteID = $this->db->insertID();
$data = ['SiteID' => '1', 'TestSiteID' => $testSiteID, 'DisciplineID' => '4', 'DepartmentID' => '4', 'ResultType' => $vs[43]['NMRIC'], 'RefType' => $vs[44]['RANGE'], 'VSet' => '', 'SpcType' => $vs[15]['UR'], 'ReqQty' => '10', 'ReqQtyUnit' => 'mL', 'Unit1' => '', 'Factor' => '', 'Unit2' => '', 'Decimal' => '1', 'Method' => 'Dipstick', 'CreateDate' => "$now"];
$this->db->table('testdeftech')->insert($data);
}
}

View File

@ -0,0 +1,432 @@
# Database Schema Redesign Proposal: Test, OrderTest & RefRange Modules
**Date:** 2025-12-16
**Status:** Draft / Proposal
**Author:** Development Team
**Purpose:** Propose cleaner, more maintainable table structure
---
## The Problem: Current Design Issues
### 1. Test Module - Confusing Table Split
**Current Structure:**
```
testdefsite → Basic test info (code, name, description)
testdeftech → Technical info (result type, units, specimen)
testdefcal → Calculation formula
testgrp → Test grouping/panels
testmap → External system mapping
```
**Issues:**
| Problem | Description |
|:--------|:------------|
| ❌ Artificial separation | `testdefsite` and `testdeftech` are 1:1 relationship - why separate them? |
| ❌ Confusing naming | "def" prefix is redundant, "site" suffix is misleading |
| ❌ Redundant columns | `SiteID`, `DisciplineID`, `DepartmentID` duplicated across tables |
| ❌ Hard to query | Need multiple JOINs just to get basic test info |
---
### 2. OrderTest Module - Unnecessary Normalization
**Current Structure:**
```
ordertest → Main order
ordercom → Comments (separate table)
orderatt → Attachments (separate table)
orderstatus → Status history (separate table)
```
**Issues:**
| Problem | Description |
|:--------|:------------|
| ❌ Over-normalized | Comments/attachments could be JSON or simpler structure |
| ❌ Status as separate table | If you only need current status, this adds complexity |
| ❌ Missing link | No link between order and actual tests ordered |
---
### 3. RefRange Module - Too Many Similar Tables
**Current Structure:**
```
refnum → Numeric ranges (Low, High, Critical)
refthold → Threshold (single cutoff value)
reftxt → Text reference
refvset → Value set reference
```
**Issues:**
| Problem | Description |
|:--------|:------------|
| ❌ 4 tables for same concept | All are "reference ranges" with slight variations |
| ❌ Duplicated columns | Same columns repeated: TestSiteID, SpcType, Sex, AgeStart, AgeEnd |
| ❌ Hard to maintain | Adding a new field means updating 4 tables |
---
## Proposed Redesign
### Part A: Test Module - Consolidated Design
**BEFORE (5 tables):**
```
testdefsite + testdeftech + testdefcal + testgrp + testmap
```
**AFTER (3 tables):**
```
tests → All test definition in ONE table
test_panels → Panel/group membership
test_mappings → External system mapping
```
#### A1. `tests` (Consolidated Test Definition)
Merge `testdefsite`, `testdeftech`, and `testdefcal` into ONE table:
```
┌─────────────────────────────────────────────────────────────────┐
│ tests │
├─────────────────────────────────────────────────────────────────┤
│ id INT UNSIGNED PK AUTO_INCREMENT │
│ site_id INT UNSIGNED -- Which lab site │
├─────────────────────────────────────────────────────────────────┤
│ -- Basic Info (from testdefsite) -- │
│ code VARCHAR(10) -- Test code │
│ name VARCHAR(100) -- Test name │
│ description VARCHAR(255) │
│ test_type ENUM('single','panel','calculated') │
├─────────────────────────────────────────────────────────────────┤
│ -- Technical Info (from testdeftech) -- │
│ discipline_id INT UNSIGNED -- Chemistry, Hematology │
│ department_id INT UNSIGNED │
│ result_type ENUM('numeric','text','coded') │
│ specimen_type VARCHAR(20) │
│ specimen_qty DECIMAL(10,2) │
│ specimen_unit VARCHAR(20) │
│ unit VARCHAR(20) -- Result unit │
│ decimal_places TINYINT │
│ method VARCHAR(100) │
│ expected_tat INT -- Turnaround time (mins) │
├─────────────────────────────────────────────────────────────────┤
│ -- Calculated Test Info (from testdefcal) -- │
│ formula TEXT -- NULL if not calculated │
│ formula_inputs JSON -- List of input test IDs │
├─────────────────────────────────────────────────────────────────┤
│ -- Display Order -- │
│ sort_order_screen INT │
│ sort_order_report INT │
│ visible_screen BOOLEAN DEFAULT 1 │
│ visible_report BOOLEAN DEFAULT 1 │
├─────────────────────────────────────────────────────────────────┤
│ -- Audit -- │
│ created_at DATETIME │
│ updated_at DATETIME │
│ deleted_at DATETIME -- Soft delete │
└─────────────────────────────────────────────────────────────────┘
```
**Benefits:**
- ✅ One query to get all test info
- ✅ No redundant columns
- ✅ Clear naming
- ✅ `test_type` tells you if it's a panel or calculated test
---
#### A2. `test_panels` (Panel Membership)
For tests that are panels (groups of other tests):
```
┌─────────────────────────────────────────────────────────────────┐
│ test_panels │
├─────────────────────────────────────────────────────────────────┤
│ id INT UNSIGNED PK AUTO_INCREMENT │
│ panel_test_id INT UNSIGNED FK → tests.id -- The panel │
│ member_test_id INT UNSIGNED FK → tests.id -- Member test │
│ sort_order INT │
│ created_at DATETIME │
└─────────────────────────────────────────────────────────────────┘
```
**Example:** CBC panel contains: WBC, RBC, HGB, HCT, PLT
```
panel_test_id=1 (CBC), member_test_id=2 (WBC)
panel_test_id=1 (CBC), member_test_id=3 (RBC)
panel_test_id=1 (CBC), member_test_id=4 (HGB)
...
```
---
#### A3. `test_mappings` (External System Mapping)
Keep this separate (good design):
```
┌─────────────────────────────────────────────────────────────────┐
│ test_mappings │
├─────────────────────────────────────────────────────────────────┤
│ id INT UNSIGNED PK AUTO_INCREMENT │
│ test_id INT UNSIGNED FK → tests.id │
│ external_system VARCHAR(50) -- 'LIS', 'HIS', 'Analyzer'│
│ external_code VARCHAR(50) -- Code in that system │
│ external_name VARCHAR(100) │
│ connection_id INT UNSIGNED -- Which connection/device │
│ direction ENUM('inbound','outbound','both') │
│ created_at DATETIME │
│ updated_at DATETIME │
└─────────────────────────────────────────────────────────────────┘
```
---
### Part B: Reference Range - Unified Design
**BEFORE (4 tables):**
```
refnum + refthold + refvset + reftxt
```
**AFTER (1 table):**
```
reference_ranges → All reference types in ONE table
```
#### B1. `reference_ranges` (Unified)
```
┌─────────────────────────────────────────────────────────────────┐
│ reference_ranges │
├─────────────────────────────────────────────────────────────────┤
│ id INT UNSIGNED PK AUTO_INCREMENT │
│ test_id INT UNSIGNED FK → tests.id │
├─────────────────────────────────────────────────────────────────┤
│ -- Criteria (same across all old tables) -- │
│ specimen_type VARCHAR(20) │
│ sex ENUM('M','F','A') -- A = All/Any │
│ age_min INT -- In days for precision │
│ age_max INT -- In days │
│ age_unit ENUM('days','months','years') │
│ criteria VARCHAR(100) -- Additional criteria │
├─────────────────────────────────────────────────────────────────┤
│ -- Reference Type -- │
│ ref_type ENUM('numeric','threshold','text','coded') │
├─────────────────────────────────────────────────────────────────┤
│ -- Numeric Range (when ref_type = 'numeric') -- │
│ critical_low DECIMAL(15,4) │
│ normal_low DECIMAL(15,4) │
│ normal_high DECIMAL(15,4) │
│ critical_high DECIMAL(15,4) │
├─────────────────────────────────────────────────────────────────┤
│ -- Threshold (when ref_type = 'threshold') -- │
│ threshold_value DECIMAL(15,4) │
│ threshold_operator ENUM('<','<=','>','>=','=') │
│ below_text VARCHAR(50) -- "Negative", "Normal" │
│ above_text VARCHAR(50) -- "Positive", "Abnormal" │
│ gray_zone_low DECIMAL(15,4) │
│ gray_zone_high DECIMAL(15,4) │
│ gray_zone_text VARCHAR(50) -- "Equivocal" │
├─────────────────────────────────────────────────────────────────┤
│ -- Text/Coded (when ref_type = 'text' or 'coded') -- │
│ reference_text TEXT -- Expected values or desc │
│ value_set JSON -- For coded: list of valid│
├─────────────────────────────────────────────────────────────────┤
│ -- Audit -- │
│ created_at DATETIME │
│ updated_at DATETIME │
└─────────────────────────────────────────────────────────────────┘
```
**Benefits:**
- ✅ One table instead of 4
- ✅ Easy to add new reference types
- ✅ Single query with `ref_type` filter
- ✅ No duplicated criteria columns
---
### Part C: OrderTest - Cleaner Design
**BEFORE (4 tables):**
```
ordertest + ordercom + orderatt + orderstatus
```
**AFTER (3 tables):**
```
orders → Main order with current status
order_tests → Individual tests in the order (MISSING before!)
order_history → Status changes + comments combined
```
#### C1. `orders` (Main Order)
```
┌─────────────────────────────────────────────────────────────────┐
│ orders │
├─────────────────────────────────────────────────────────────────┤
│ id INT UNSIGNED PK AUTO_INCREMENT │
│ order_number VARCHAR(30) UNIQUE -- Display order ID │
│ accession_number VARCHAR(30) -- Lab accession │
├─────────────────────────────────────────────────────────────────┤
│ -- Patient & Visit -- │
│ patient_id INT UNSIGNED FK → patients.id │
│ visit_id INT UNSIGNED FK → visits.id │
│ site_id INT UNSIGNED │
├─────────────────────────────────────────────────────────────────┤
│ -- Order Details -- │
│ priority ENUM('routine','urgent','stat') │
│ status ENUM('pending','collected','received', │
│ 'in_progress','completed','cancelled') │
│ ordered_by INT UNSIGNED -- Doctor/User ID │
│ ordered_at DATETIME │
│ collected_at DATETIME │
│ received_at DATETIME │
│ completed_at DATETIME │
├─────────────────────────────────────────────────────────────────┤
│ -- Audit -- │
│ created_at DATETIME │
│ updated_at DATETIME │
│ deleted_at DATETIME │
└─────────────────────────────────────────────────────────────────┘
```
---
#### C2. `order_tests` (Tests in Order) — **NEW TABLE!**
**This was MISSING in original design!** How do you know what tests are in an order?
```
┌─────────────────────────────────────────────────────────────────┐
│ order_tests │
├─────────────────────────────────────────────────────────────────┤
│ id INT UNSIGNED PK AUTO_INCREMENT │
│ order_id INT UNSIGNED FK → orders.id │
│ test_id INT UNSIGNED FK → tests.id │
├─────────────────────────────────────────────────────────────────┤
│ status ENUM('ordered','in_progress','resulted', │
│ 'verified','cancelled') │
│ result_value VARCHAR(255) -- The actual result │
│ result_flag ENUM('N','L','H','LL','HH','A') -- Normal/Abn│
│ result_comment TEXT │
│ resulted_by INT UNSIGNED -- Tech who entered result │
│ resulted_at DATETIME │
│ verified_by INT UNSIGNED -- Supervisor who verified │
│ verified_at DATETIME │
├─────────────────────────────────────────────────────────────────┤
│ created_at DATETIME │
│ updated_at DATETIME │
└─────────────────────────────────────────────────────────────────┘
```
---
#### C3. `order_history` (Combined Audit Trail)
Combine `ordercom`, `orderatt`, `orderstatus` into one audit table:
```
┌─────────────────────────────────────────────────────────────────┐
│ order_history │
├─────────────────────────────────────────────────────────────────┤
│ id INT UNSIGNED PK AUTO_INCREMENT │
│ order_id INT UNSIGNED FK → orders.id │
│ order_test_id INT UNSIGNED FK → order_tests.id (nullable) │
├─────────────────────────────────────────────────────────────────┤
│ event_type ENUM('status_change','comment','attachment', │
│ 'result_edit','verification') │
│ old_value TEXT │
│ new_value TEXT │
│ comment TEXT │
│ attachment_path VARCHAR(255) -- For attachments │
├─────────────────────────────────────────────────────────────────┤
│ created_by INT UNSIGNED │
│ created_at DATETIME │
└─────────────────────────────────────────────────────────────────┘
```
---
## Summary: Before vs After
| Module | Before | After | Change |
|:-------|:-------|:------|:-------|
| **Test** | 5 tables | 3 tables | -2 tables |
| **RefRange** | 4 tables | 1 table | -3 tables |
| **OrderTest** | 4 tables | 3 tables | -1 table, +1 essential table |
| **Total** | 13 tables | 7 tables | **-6 tables** |
### New ERD
```
┌─────────────────────────────────────────────────────────────────────────────┐
│ PROPOSED ERD │
├─────────────────────────────────────────────────────────────────────────────┤
│ │
│ ┌─────────────┐ ┌──────────────┐ ┌─────────────────┐ │
│ │ tests │◄────────│ test_panels │ │ test_mappings │ │
│ │ (All tests) │ │ (Panel→Test) │ │ (Ext. systems) │ │
│ └──────┬──────┘ └──────────────┘ └─────────────────┘ │
│ │ │
│ │ 1:N │
│ ▼ │
│ ┌──────────────────┐ │
│ │ reference_ranges │ (All ref types in one table) │
│ └──────────────────┘ │
│ │
│ │
│ ┌──────────┐ 1:N ┌─────────────┐ 1:N ┌───────────────┐ │
│ │ patients │◄──────────│ orders │◄──────────│ order_history │ │
│ └──────────┘ └──────┬──────┘ └───────────────┘ │
│ │ │
│ │ 1:N │
│ ▼ │
│ ┌─────────────┐ │
│ │ order_tests │ (What tests are in order) │
│ └──────┬──────┘ │
│ │ │
│ │ N:1 │
│ ▼ │
│ ┌─────────────┐ │
│ │ tests │ │
│ └─────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────────────────┘
```
---
## Migration Strategy
Since this is a major restructure:
1. **Create new migration files** (don't modify old ones)
2. **Write data migration script** to move data from old to new tables
3. **Update Models, Controllers, Views** to use new table names
4. **Test thoroughly** before dropping old tables
---
## Questions for Discussion
1. Is storing `formula` as TEXT acceptable, or need a more structured approach?
2. Should `order_history` store ALL changes, or just important ones?
3. Any additional fields needed that I missed?
---
## Next Steps
1. ✅ Review and approve this proposal
2. 🔲 Create new migration files
3. 🔲 Write data migration scripts
4. 🔲 Update Models to use new tables
5. 🔲 Update Controllers and Services
6. 🔲 Deprecate old tables

View File

@ -0,0 +1,222 @@
# Patient Registration API Contract
**Version:** 1.0.0
**Base URL:** `/api/v1`
---
## 1. Patients (`/patients`)
### GET /patients
Retrieve list of patients.
**Query Parameters:**
- `page` (int, default: 1)
- `limit` (int, default: 20)
- `search` (string) - Search by name, MRN (PatientID), or phone.
**Response (200 OK):**
```json
{
"data": [
{
"InternalPID": 1001,
"PatientID": "MRN-2025-0001",
"NameFirst": "John",
"NameLast": "Doe",
"Gender": 1,
"Birthdate": "1990-05-15",
"MobilePhone": "+1234567890",
"EmailAddress1": "john.doe@example.com"
}
]
}
```
---
### POST /patients
Register a new patient.
**Request Body:**
```json
{
"PatientID": "MRN-2025-0002",
"AlternatePID": "ALT-123", // Optional
"Prefix": "Mr.", // Optional
"NameFirst": "Jane",
"NameMiddle": "Marie", // Optional
"NameLast": "Doe",
"NameMaiden": null, // Optional
"Suffix": null, // Optional
"Gender": 2, // 1=Male, 2=Female (example)
"Birthdate": "1992-08-20",
"PlaceOfBirth": "New York", // Optional
"Street_1": "123 Main St",
"Street_2": "Apt 4B", // Optional
"City": "Metropolis",
"Province": "NY",
"ZIP": "10001",
"Phone": "555-0100", // Optional
"MobilePhone": "555-0199",
"EmailAddress1": "jane.doe@example.com",
"MaritalStatus": 1, // 1=Single, 2=Married, etc.
"Religion": 1, // Optional ID
"Race": 1, // Optional ID
"Citizenship": "USA" // Optional
}
```
**Response (201 Created):**
```json
{
"message": "Patient created successfully",
"data": {
"InternalPID": 1002,
"PatientID": "MRN-2025-0002",
"CreateDate": "2025-12-16T10:00:00Z"
}
}
```
---
### GET /patients/{id}
Get full details of a specific patient.
**Response (200 OK):**
```json
{
"data": {
"InternalPID": 1001,
"PatientID": "MRN-2025-0001",
"NameFirst": "John",
"NameLast": "Doe",
"identifiers": [
{
"PatIdtID": 5,
"IdentifierType": "Passport",
"Identifier": "A12345678"
}
],
"relations": [],
"comments": []
}
}
```
---
### PUT /patients/{id}
Update patient demographics.
**Request Body:**
```json
{
"NameLast": "Smith",
"MobilePhone": "555-9999",
"EmailAddress1": "john.smith@example.com"
}
```
**Response (200 OK):**
```json
{
"message": "Patient updated successfully",
"data": { "InternalPID": 1001 }
}
```
---
## 2. Patient Identifiers (`/patients/{id}/identifiers`)
### POST /patients/{id}/identifiers
Add an identifier (SSN, Passport, Driver's License) to a patient.
**Request Body:**
```json
{
"IdentifierType": "SSN",
"Identifier": "000-11-2222",
"EffectiveDate": "2020-01-01", // Optional
"ExpirationDate": "2030-01-01" // Optional
}
```
**Response (201 Created):**
```json
{
"message": "Identifier added",
"data": { "PatIdtID": 15 }
}
```
---
## 3. Patient Comments (`/patients/{id}/comments`)
### POST /patients/{id}/comments
Add a comment to a patient record.
**Request Body:**
```json
{
"Comment": "Patient requests wheelchair assistance upon arrival."
}
```
**Response (201 Created):**
```json
{
"message": "Comment added",
"data": { "PatComID": 42 }
}
```
---
## 4. Patient Relations (`/patients/{id}/relations`)
*Note: Pending Schema Update (Currently `patrelation` is missing columns)*
### POST /patients/{id}/relations
Add a family member or emergency contact.
**Request Body:**
```json
{
"RelatedPID": 1050, // If relation is also a patient
"RelationType": "Spouse", // Requires schema update to store this
"IsEmergency": true // Requires schema update
}
```
**Response (201 Created):**
```json
{
"message": "Relation added",
"data": { "PatRelID": 8 }
}
```
---
## 5. Patient Attachments (`/patients/{id}/attachments`)
### POST /patients/{id}/attachments
Upload a file for a patient (insurance card, ID scan).
**Request (Multipart/Form-Data):**
- `file`: (Binary File)
- `Address`: (string, optional description or file path reference)
**Response (201 Created):**
```json
{
"message": "File uploaded",
"data": {
"PatAttID": 99,
"Address": "/uploads/patients/1001/scan_id.pdf"
}
}
```