'Chemistry'], ['dept_name' => 'Hematology'], ['dept_name' => 'Immunology'], ['dept_name' => 'Urinalysis'], ]; $this->db->table('master_depts')->insertBatch($depts); $deptIds = $this->db->table('master_depts')->select('dept_id')->get()->getResultArray(); $deptIdMap = array_column($deptIds, 'dept_id'); // 2. Insert Controls with long expiry dates (2027-12-31) $controls = [ ['dept_id' => $deptIdMap[0], 'control_name' => 'QC Normal Chemistry', 'lot' => 'QC2026001', 'producer' => 'BioRad', 'exp_date' => '2027-12-31'], ['dept_id' => $deptIdMap[0], 'control_name' => 'QC High Chemistry', 'lot' => 'QC2026002', 'producer' => 'BioRad', 'exp_date' => '2027-12-31'], ['dept_id' => $deptIdMap[1], 'control_name' => 'QC Normal Hema', 'lot' => 'QC2026003', 'producer' => 'Streck', 'exp_date' => '2027-11-30'], ['dept_id' => $deptIdMap[1], 'control_name' => 'QC Low Hema', 'lot' => 'QC2026004', 'producer' => 'Streck', 'exp_date' => '2027-11-30'], ['dept_id' => $deptIdMap[2], 'control_name' => 'QC Normal Immuno', 'lot' => 'QC2026005', 'producer' => 'Roche', 'exp_date' => '2027-10-31'], ['dept_id' => $deptIdMap[3], 'control_name' => 'QC Normal Urine', 'lot' => 'QC2026006', 'producer' => 'Siemens', 'exp_date' => '2027-09-30'], ]; $this->db->table('master_controls')->insertBatch($controls); $controlIds = $this->db->table('master_controls')->select('control_id')->get()->getResultArray(); $controlIdMap = array_column($controlIds, 'control_id'); // 3. Insert Tests (10 entries) $tests = [ ['dept_id' => $deptIdMap[0], 'test_name' => 'Glucose', 'test_unit' => 'mg/dL', 'test_method' => 'GOD-PAP', 'cva' => 5, 'ba' => 3, 'tea' => 10], ['dept_id' => $deptIdMap[0], 'test_name' => 'Creatinine', 'test_unit' => 'mg/dL', 'test_method' => 'Jaffe', 'cva' => 4, 'ba' => 2, 'tea' => 8], ['dept_id' => $deptIdMap[0], 'test_name' => 'Urea Nitrogen', 'test_unit' => 'mg/dL', 'test_method' => 'UREASE', 'cva' => 5, 'ba' => 3, 'tea' => 12], ['dept_id' => $deptIdMap[0], 'test_name' => 'Cholesterol', 'test_unit' => 'mg/dL', 'test_method' => 'CHOD-PAP', 'cva' => 6, 'ba' => 4, 'tea' => 15], ['dept_id' => $deptIdMap[1], 'test_name' => 'WBC', 'test_unit' => 'x10^3/uL', 'test_method' => 'Impedance', 'cva' => 8, 'ba' => 5, 'tea' => 20], ['dept_id' => $deptIdMap[1], 'test_name' => 'RBC', 'test_unit' => 'x10^6/uL', 'test_method' => 'Impedance', 'cva' => 3, 'ba' => 2, 'tea' => 8], ['dept_id' => $deptIdMap[1], 'test_name' => 'Hemoglobin', 'test_unit' => 'g/dL', 'test_method' => 'Cyanmethemoglobin', 'cva' => 2, 'ba' => 1, 'tea' => 5], ['dept_id' => $deptIdMap[2], 'test_name' => 'TSH', 'test_unit' => 'mIU/L', 'test_method' => 'ECLIA', 'cva' => 10, 'ba' => 6, 'tea' => 25], ['dept_id' => $deptIdMap[2], 'test_name' => 'Free T4', 'test_unit' => 'ng/dL', 'test_method' => 'ECLIA', 'cva' => 8, 'ba' => 5, 'tea' => 20], ['dept_id' => $deptIdMap[3], 'test_name' => 'Urine Protein', 'test_unit' => 'mg/dL', 'test_method' => 'Dipstick', 'cva' => 10, 'ba' => 8, 'tea' => 30], ]; $this->db->table('master_tests')->insertBatch($tests); $testIds = $this->db->table('master_tests')->select('test_id')->get()->getResultArray(); $testIdMap = array_column($testIds, 'test_id'); // 4. Insert Control-Tests (15 entries - 3 per control for first 5 controls) $controlTests = [ ['control_id' => $controlIdMap[0], 'test_id' => $testIdMap[0], 'mean' => 95, 'sd' => 5], ['control_id' => $controlIdMap[0], 'test_id' => $testIdMap[1], 'mean' => 1.0, 'sd' => 0.05], ['control_id' => $controlIdMap[0], 'test_id' => $testIdMap[2], 'mean' => 15, 'sd' => 1.2], ['control_id' => $controlIdMap[1], 'test_id' => $testIdMap[0], 'mean' => 180, 'sd' => 12], ['control_id' => $controlIdMap[1], 'test_id' => $testIdMap[1], 'mean' => 2.5, 'sd' => 0.15], ['control_id' => $controlIdMap[1], 'test_id' => $testIdMap[3], 'mean' => 200, 'sd' => 15], ['control_id' => $controlIdMap[2], 'test_id' => $testIdMap[4], 'mean' => 7.5, 'sd' => 0.6], ['control_id' => $controlIdMap[2], 'test_id' => $testIdMap[5], 'mean' => 4.8, 'sd' => 0.2], ['control_id' => $controlIdMap[2], 'test_id' => $testIdMap[6], 'mean' => 14.5, 'sd' => 0.5], ['control_id' => $controlIdMap[3], 'test_id' => $testIdMap[4], 'mean' => 3.5, 'sd' => 0.3], ['control_id' => $controlIdMap[3], 'test_id' => $testIdMap[5], 'mean' => 2.5, 'sd' => 0.15], ['control_id' => $controlIdMap[4], 'test_id' => $testIdMap[7], 'mean' => 2.5, 'sd' => 0.3], ['control_id' => $controlIdMap[4], 'test_id' => $testIdMap[8], 'mean' => 1.2, 'sd' => 0.1], ['control_id' => $controlIdMap[5], 'test_id' => $testIdMap[9], 'mean' => 10, 'sd' => 1.5], ['control_id' => $controlIdMap[0], 'test_id' => $testIdMap[3], 'mean' => 150, 'sd' => 10], ]; $this->db->table('control_tests')->insertBatch($controlTests); $ctRows = $this->db->table('control_tests')->select('control_test_id, control_id, test_id, mean, sd')->get()->getResultArray(); // 5. Insert Results (90 entries - 6 per control-test, daily data spanning ~3 months) $results = []; $faker = \Faker\Factory::create(); // Start date: 3 months ago, generate daily entries $startDate = date('2025-10-01'); $daysToGenerate = 90; // ~3 months of daily data foreach ($ctRows as $ct) { // Generate 6 results per control-test, spread across the date range for ($i = 0; $i < 6; $i++) { // Distribute results across the 90-day period $dayOffset = floor(($i * $daysToGenerate) / 6) + $faker->numberBetween(0, 5); $resDate = date('Y-m-d', strtotime($startDate . ' +' . $dayOffset . ' days')); // Generate value within +/- 2.5 SD $value = $ct['mean'] + ($faker->randomFloat(2, -2.5, 2.5) * $ct['sd']); $results[] = [ 'control_id' => $ct['control_id'], 'test_id' => $ct['test_id'], 'res_date' => $resDate, 'res_value' => round($value, 2), 'res_comment' => null, 'created_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s'), ]; } } $this->db->table('results')->insertBatch($results); // 6. Insert Result Comments (60 entries - monthly comments for all control-test combos) $resultComments = []; $months = ['2025-10', '2025-11', '2025-12', '2026-01']; $commentTemplates = [ '2025-10' => [ ['control_id' => 0, 'test_id' => 0, 'text' => 'QC performance stable, all parameters within range for October'], ['control_id' => 0, 'test_id' => 1, 'text' => 'Creatinine controls stable, no issues observed'], ['control_id' => 0, 'test_id' => 2, 'text' => 'BUN QC within acceptable limits'], ['control_id' => 1, 'test_id' => 0, 'text' => 'High glucose QC showed slight elevation, monitoring continued'], ['control_id' => 1, 'test_id' => 3, 'text' => 'Cholesterol lot QC2026002 performs within specifications'], ['control_id' => 2, 'test_id' => 4, 'text' => 'WBC counts consistent throughout the month'], ['control_id' => 2, 'test_id' => 5, 'text' => 'RBC QC stable, no drift detected'], ['control_id' => 2, 'test_id' => 6, 'text' => 'Hemoglobin controls within expected range'], ['control_id' => 3, 'test_id' => 4, 'text' => 'Low WBC QC verified, precision acceptable'], ['control_id' => 3, 'test_id' => 5, 'text' => 'Low RBC controls passed QC checks'], ['control_id' => 4, 'test_id' => 7, 'text' => 'TSH assay calibration verified on 10/15'], ['control_id' => 4, 'test_id' => 8, 'text' => 'Free T4 controls stable, no maintenance required'], ['control_id' => 5, 'test_id' => 9, 'text' => 'Urine protein dipstick QC performing well'], ['control_id' => 0, 'test_id' => 3, 'text' => 'Normal cholesterol QC within target range'], ], '2025-11' => [ ['control_id' => 0, 'test_id' => 0, 'text' => 'Glucose QC showed minor drift, recalibration performed 11/10'], ['control_id' => 0, 'test_id' => 1, 'text' => 'November creatinine QC results acceptable'], ['control_id' => 0, 'test_id' => 2, 'text' => 'BUN controls stable after reagent lot change'], ['control_id' => 1, 'test_id' => 0, 'text' => 'High glucose QC consistent after recalibration'], ['control_id' => 1, 'test_id' => 3, 'text' => 'Cholesterol QC performance improved after maintenance'], ['control_id' => 2, 'test_id' => 4, 'text' => 'WBC QC acceptable, precision within specifications'], ['control_id' => 2, 'test_id' => 5, 'text' => 'RBC controls verified, no issues'], ['control_id' => 2, 'test_id' => 6, 'text' => 'Hemoglobin QC stable, Levey-Jenkins chart within limits'], ['control_id' => 3, 'test_id' => 4, 'text' => 'Low WBC QC passed all QC checks for November'], ['control_id' => 3, 'test_id' => 5, 'text' => 'Low RBC controls stable throughout month'], ['control_id' => 4, 'test_id' => 7, 'text' => 'TSH controls within range, no action required'], ['control_id' => 4, 'test_id' => 8, 'text' => 'Free T4 assay verification complete'], ['control_id' => 5, 'test_id' => 9, 'text' => 'Urine protein QC lot QC2026006 performing well'], ['control_id' => 0, 'test_id' => 3, 'text' => 'Normal cholesterol lot QC2026001 verified'], ], '2025-12' => [ ['control_id' => 0, 'test_id' => 0, 'text' => 'December glucose QC stable, no issues'], ['control_id' => 0, 'test_id' => 1, 'text' => 'Creatinine QC performance acceptable for year-end'], ['control_id' => 0, 'test_id' => 2, 'text' => 'BUN controls within range, holiday period monitoring'], ['control_id' => 1, 'test_id' => 0, 'text' => 'High glucose QC stable after lot stabilization'], ['control_id' => 1, 'test_id' => 3, 'text' => 'Cholesterol QC trending well, within 2SD'], ['control_id' => 2, 'test_id' => 4, 'text' => 'WBC QC stable, year-end verification complete'], ['control_id' => 2, 'test_id' => 5, 'text' => 'RBC controls verified, all parameters acceptable'], ['control_id' => 2, 'test_id' => 6, 'text' => 'Hemoglobin QC within expected range'], ['control_id' => 3, 'test_id' => 4, 'text' => 'Low WBC QC passed December checks'], ['control_id' => 3, 'test_id' => 5, 'text' => 'Low RBC controls stable'], ['control_id' => 4, 'test_id' => 7, 'text' => 'TSH controls within specifications'], ['control_id' => 4, 'test_id' => 8, 'text' => 'Free T4 QC acceptable for December'], ['control_id' => 5, 'test_id' => 9, 'text' => 'Urine protein QC no issues reported'], ['control_id' => 0, 'test_id' => 3, 'text' => 'Cholesterol QC lot QC2026001 verified'], ], '2026-01' => [ ['control_id' => 0, 'test_id' => 0, 'text' => 'January glucose QC started well, new year verification'], ['control_id' => 0, 'test_id' => 1, 'text' => 'Creatinine QC performance consistent'], ['control_id' => 0, 'test_id' => 2, 'text' => 'BUN controls within expected parameters'], ['control_id' => 1, 'test_id' => 0, 'text' => 'High glucose QC stable start to new year'], ['control_id' => 1, 'test_id' => 3, 'text' => 'Cholesterol QC lot QC2026002 verified'], ['control_id' => 2, 'test_id' => 4, 'text' => 'WBC QC started new year within specifications'], ['control_id' => 2, 'test_id' => 5, 'text' => 'RBC controls performing as expected'], ['control_id' => 2, 'test_id' => 6, 'text' => 'Hemoglobin QC acceptable'], ['control_id' => 3, 'test_id' => 4, 'text' => 'Low WBC QC passed January checks'], ['control_id' => 3, 'test_id' => 5, 'text' => 'Low RBC controls verified'], ['control_id' => 4, 'test_id' => 7, 'text' => 'TSH controls within range'], ['control_id' => 4, 'test_id' => 8, 'text' => 'Free T4 QC stable'], ['control_id' => 5, 'test_id' => 9, 'text' => 'Urine protein QC performing well'], ['control_id' => 0, 'test_id' => 3, 'text' => 'Cholesterol QC lot QC2026001 verified'], ], ]; foreach ($months as $month) { if (isset($commentTemplates[$month])) { foreach ($commentTemplates[$month] as $comment) { $resultComments[] = [ 'control_id' => $controlIdMap[$comment['control_id']], 'test_id' => $testIdMap[$comment['test_id']], 'comment_month' => $month, 'com_text' => $comment['text'], ]; } } } $this->db->table('result_comments')->insertBatch($resultComments); } }