OEM seeder: lab & radiology report templates for fresh installs
This commit is contained in:
parent
fd28d6a01e
commit
f79d7f50c9
13
app/Database/Seeds/LabOemData/01_lab_rgroups.sql
Normal file
13
app/Database/Seeds/LabOemData/01_lab_rgroups.sql
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
CREATE TABLE IF NOT EXISTS `lab_rgroups` (
|
||||
`mstRGrpKey` int NOT NULL AUTO_INCREMENT,
|
||||
`RepoGrp` varchar(100) NOT NULL,
|
||||
`PreFix` varchar(3) NOT NULL DEFAULT '0',
|
||||
`Suffix` varchar(3) NOT NULL DEFAULT '0',
|
||||
`LastNo` int NOT NULL DEFAULT '0',
|
||||
`sort_order` int NOT NULL DEFAULT '0',
|
||||
`Notes` varchar(50) NOT NULL DEFAULT '0',
|
||||
PRIMARY KEY (`mstRGrpKey`),
|
||||
UNIQUE KEY `RepoGrp` (`RepoGrp`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb3 ROW_FORMAT=DYNAMIC;
|
||||
|
||||
INSERT IGNORE INTO `lab_rgroups` (`mstRGrpKey`, `RepoGrp`, `PreFix`, `Suffix`, `LastNo`, `sort_order`, `Notes`) VALUES (1,'BIO CHEMISTRY','BIO','',0,2,''),(2,'Biopsy','BP','',0,3,''),(3,'CLINICAL PATHOLOGY','CP','',0,4,''),(4,'MICRO BIOLOGY','CUL','',0,5,''),(5,'General','GEN','',1,6,''),(6,'HAEMATOLOGY','HAE','',0,1,''),(8,'Urine','US','',0,8,''),(9,'Fluid Examination','FE','0',0,9,'0'),(10,'CYTO-PATHOLOGY','CYP','0',0,10,'0'),(11,'HISTOPATHOLOGY','HP','0',0,11,'0'),(12,'IMMUNOLOGY-SEROLOGY','IS','0',0,12,'0'),(13,'ENDOCRINOLOGY','ELO','0',0,13,'0'),(15,'','0','0',0,14,'0');
|
||||
14
app/Database/Seeds/LabOemData/02_hc_items_lab.sql
Normal file
14
app/Database/Seeds/LabOemData/02_hc_items_lab.sql
Normal file
File diff suppressed because one or more lines are too long
16
app/Database/Seeds/LabOemData/03_lab_repo.sql
Normal file
16
app/Database/Seeds/LabOemData/03_lab_repo.sql
Normal file
File diff suppressed because one or more lines are too long
19
app/Database/Seeds/LabOemData/04_lab_tests.sql
Normal file
19
app/Database/Seeds/LabOemData/04_lab_tests.sql
Normal file
File diff suppressed because one or more lines are too long
14
app/Database/Seeds/LabOemData/05_lab_tests_option.sql
Normal file
14
app/Database/Seeds/LabOemData/05_lab_tests_option.sql
Normal file
File diff suppressed because one or more lines are too long
11
app/Database/Seeds/LabOemData/06_lab_repotests.sql
Normal file
11
app/Database/Seeds/LabOemData/06_lab_repotests.sql
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
CREATE TABLE IF NOT EXISTS `lab_repotests` (
|
||||
`id` int NOT NULL AUTO_INCREMENT,
|
||||
`mstRepoKey` int NOT NULL,
|
||||
`mstTestKey` int NOT NULL,
|
||||
`EOrder` tinyint unsigned NOT NULL DEFAULT '0',
|
||||
PRIMARY KEY (`mstRepoKey`,`mstTestKey`),
|
||||
UNIQUE KEY `id` (`id`),
|
||||
UNIQUE KEY `mstRepoKey_EOrder` (`mstRepoKey`,`EOrder`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb3;
|
||||
INSERT IGNORE INTO `lab_repotests` (`id`, `mstRepoKey`, `mstTestKey`, `EOrder`) VALUES (1,1,1,1),(2,1,2,2),(4,1,4,4),(5,1,5,5),(7,1,7,8),(10,1,10,12),(11,1,11,17),(12,1,12,14),(13,1,13,15),(14,1,14,16),(15,1,15,13),(278,1,26,18),(270,1,182,7),(276,1,188,11),(16,2,16,1),(27,2,27,4),(28,2,28,5),(29,2,29,6),(30,2,30,7),(31,2,31,8),(32,2,32,9),(180,2,80,2),(181,2,81,3),(275,2,187,10),(17,3,17,1),(18,3,18,2),(19,3,19,3),(20,3,20,5),(21,3,21,6),(22,3,22,4),(33,4,33,1),(286,4,195,2),(34,5,34,1),(35,6,35,1),(36,6,36,2),(160,7,108,1),(37,8,37,1),(38,9,38,1),(39,10,39,1),(40,11,40,1),(41,11,41,2),(42,11,42,4),(43,11,43,5),(44,11,44,6),(46,11,46,10),(47,11,47,11),(48,11,48,12),(49,11,49,13),(285,11,148,14),(280,11,191,3),(281,11,192,15),(282,11,193,7),(283,11,194,9),(50,12,50,1),(51,12,51,2),(52,13,52,1),(451,13,200,2),(53,14,53,1),(54,14,54,2),(55,14,55,3),(56,14,56,4),(57,15,57,3),(58,15,58,2),(273,15,185,1),(59,16,59,1),(60,16,60,2),(61,17,61,1),(62,18,62,1),(63,18,63,2),(64,18,64,3),(65,18,65,4),(66,18,66,5),(67,18,67,6),(68,18,68,7),(69,18,69,8),(70,18,70,9),(71,18,71,10),(72,18,72,11),(73,18,73,12),(74,18,74,13),(89,19,76,1),(90,19,77,2),(91,19,78,3),(75,20,62,1),(76,20,63,2),(77,20,64,3),(78,20,65,4),(79,20,66,5),(80,20,67,6),(81,20,68,7),(82,20,69,8),(84,20,71,12),(86,20,73,13),(87,20,74,14),(88,20,75,10),(92,21,79,1),(93,21,80,2),(94,21,81,3),(95,22,82,1),(96,23,83,1),(97,24,84,1),(98,25,16,1),(99,26,27,1),(100,27,28,1),(165,28,112,1),(102,29,4,2),(103,29,5,3),(105,29,7,6),(106,29,8,7),(107,29,9,8),(269,29,182,5),(113,30,4,1),(114,31,5,1),(116,33,10,1),(117,34,11,1),(118,35,12,1),(119,36,13,1),(120,37,14,1),(121,38,15,1),(122,39,17,1),(123,40,18,1),(124,41,19,1),(125,42,20,1),(126,43,21,1),(127,44,22,1),(128,45,24,1),(129,46,25,1),(130,47,26,1),(131,48,29,1),(133,50,73,1),(134,51,76,1),(135,52,77,1),(136,54,1,1),(137,55,85,1),(138,55,86,2),(139,55,87,4),(140,55,88,5),(141,55,89,6),(145,55,93,9),(146,55,94,10),(147,55,95,11),(148,55,96,13),(149,55,97,3),(151,55,99,12),(279,55,190,14),(152,56,100,1),(153,56,101,5),(154,56,102,2),(155,56,103,3),(156,56,104,4),(157,57,105,1),(158,57,106,2),(159,58,107,1),(161,59,78,1),(164,62,111,1),(234,63,152,1),(235,63,153,2),(236,63,154,3),(237,63,155,4),(238,63,156,5),(239,63,157,6),(240,63,158,7),(241,63,159,8),(242,63,160,9),(243,63,161,10),(244,63,162,11),(245,63,163,12),(246,63,164,13),(247,63,165,14),(248,63,166,15),(249,63,167,16),(250,63,168,17),(251,63,169,18),(252,63,170,19),(162,64,109,1),(163,65,110,1),(166,66,113,1),(167,67,114,1),(168,68,115,1),(169,68,116,2),(170,69,117,1),(224,70,142,1),(225,70,143,2),(226,70,144,3),(227,70,145,4),(228,70,146,5),(229,70,147,6),(230,70,148,7),(231,70,149,8),(232,70,150,9),(233,70,151,10),(173,71,120,3),(174,71,121,2),(172,72,119,1),(175,73,122,1),(177,74,124,1),(176,75,123,1),(178,76,125,1),(187,77,132,1),(179,78,126,1),(182,79,127,1),(183,79,128,2),(184,79,129,3),(185,80,130,1),(186,81,131,1),(188,82,133,1),(189,83,134,1),(190,86,135,1),(192,87,137,1),(223,88,141,1),(257,91,175,1),(193,92,1,1),(194,92,2,2),(195,92,4,3),(196,92,5,4),(197,92,6,5),(198,92,7,6),(199,92,8,7),(200,92,9,8),(201,92,10,9),(202,92,11,10),(203,92,12,11),(204,92,13,12),(205,92,14,13),(206,92,15,14),(207,92,26,15),(208,93,138,1),(209,95,139,1),(211,97,62,1),(212,97,63,2),(213,97,64,3),(214,97,65,4),(215,97,66,5),(216,97,67,6),(217,97,68,7),(218,97,69,8),(220,97,71,10),(221,97,73,11),(222,97,74,12),(219,97,75,9),(253,98,171,1),(254,99,172,1),(255,100,173,1),(256,101,174,1),(258,102,176,1),(259,103,177,1),(264,128,178,1),(265,128,179,2),(266,128,180,3),(267,128,181,4),(271,129,183,1),(272,130,184,1),(274,131,186,1),(421,132,1,1),(422,132,2,2),(423,132,4,3),(424,132,5,4),(426,132,7,6),(428,132,10,8),(433,132,11,13),(430,132,12,10),(431,132,13,11),(432,132,14,12),(429,132,15,9),(434,132,26,14),(437,132,39,17),(435,132,59,15),(436,132,60,16),(443,132,76,23),(444,132,77,24),(445,132,78,25),(438,132,100,18),(442,132,101,22),(439,132,102,19),(440,132,103,20),(441,132,104,21),(425,132,182,5),(427,132,188,7),(379,133,1,1),(380,133,2,2),(381,133,4,3),(382,133,5,4),(384,133,7,6),(386,133,10,8),(391,133,11,13),(388,133,12,10),(389,133,13,11),(390,133,14,12),(387,133,15,9),(404,133,16,26),(414,133,17,36),(415,133,18,37),(416,133,19,38),(418,133,20,40),(419,133,21,41),(417,133,22,39),(392,133,26,14),(407,133,27,29),(408,133,28,30),(409,133,29,31),(410,133,30,32),(411,133,31,33),(412,133,32,34),(420,133,38,42),(395,133,39,17),(393,133,59,15),(394,133,61,16),(401,133,76,23),(402,133,77,24),(403,133,78,25),(405,133,80,27),(406,133,81,28),(396,133,100,18),(400,133,101,22),(397,133,102,19),(398,133,103,20),(399,133,104,21),(383,133,182,5),(413,133,187,35),(385,133,188,7),(447,133,196,43),(446,134,196,1),(448,135,197,1),(449,136,198,1),(450,137,199,1);
|
||||
|
||||
File diff suppressed because one or more lines are too long
126
app/Database/Seeds/LabTemplateSeeder.php
Normal file
126
app/Database/Seeds/LabTemplateSeeder.php
Normal file
|
|
@ -0,0 +1,126 @@
|
|||
<?php
|
||||
|
||||
namespace App\Database\Seeds;
|
||||
|
||||
use CodeIgniter\CLI\CLI;
|
||||
use CodeIgniter\Database\Seeder;
|
||||
|
||||
/**
|
||||
* OEM Lab Template Seeder
|
||||
*
|
||||
* Seeds all pathology and radiology report template data for a fresh
|
||||
* hospital installation. Safe to re-run — all inserts use INSERT IGNORE.
|
||||
*
|
||||
* Tables populated (in FK dependency order):
|
||||
* 1. lab_rgroups — Report group names (Haematology, BioChemistry …)
|
||||
* 2. hc_items (itype 5,6 only) — Billing charge items linked to lab reports
|
||||
* 3. lab_repo — Pathology report template master
|
||||
* 4. lab_tests — Individual test/parameter definitions
|
||||
* 5. lab_tests_option — Dropdown options for test parameters
|
||||
* 6. lab_repotests — Junction: tests per report + sort order
|
||||
* 7. radiology_ultrasound_template — US / MRI / CT / Xray / Echo templates
|
||||
*
|
||||
* Usage:
|
||||
* php spark db:seed LabTemplateSeeder
|
||||
*/
|
||||
class LabTemplateSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Ordered list of SQL files to execute.
|
||||
* Each file contains CREATE TABLE IF NOT EXISTS + INSERT IGNORE statements.
|
||||
*/
|
||||
private const SQL_FILES = [
|
||||
'01_lab_rgroups.sql',
|
||||
'02_hc_items_lab.sql',
|
||||
'03_lab_repo.sql',
|
||||
'04_lab_tests.sql',
|
||||
'05_lab_tests_option.sql',
|
||||
'06_lab_repotests.sql',
|
||||
'07_radiology_ultrasound_template.sql',
|
||||
];
|
||||
|
||||
public function run(): void
|
||||
{
|
||||
$sqlDir = __DIR__ . DIRECTORY_SEPARATOR . 'LabOemData' . DIRECTORY_SEPARATOR;
|
||||
|
||||
$this->db->query('SET FOREIGN_KEY_CHECKS = 0');
|
||||
$this->db->query('SET SQL_MODE = ""'); // silence STRICT for legacy MyISAM data
|
||||
|
||||
foreach (self::SQL_FILES as $file) {
|
||||
$path = $sqlDir . $file;
|
||||
|
||||
if (! is_file($path)) {
|
||||
CLI::write(" [SKIP] Missing SQL file: $file", 'yellow');
|
||||
continue;
|
||||
}
|
||||
|
||||
$sql = file_get_contents($path);
|
||||
if ($sql === false || trim($sql) === '') {
|
||||
CLI::write(" [SKIP] Empty SQL file: $file", 'yellow');
|
||||
continue;
|
||||
}
|
||||
|
||||
// Strip UTF-8 BOM if present (PowerShell 5.1 Set-Content adds it)
|
||||
if (str_starts_with($sql, "\xEF\xBB\xBF")) {
|
||||
$sql = substr($sql, 3);
|
||||
}
|
||||
|
||||
// Split on statement boundaries (semicolons not inside quotes)
|
||||
$statements = $this->splitSqlStatements($sql);
|
||||
|
||||
foreach ($statements as $stmt) {
|
||||
$stmt = trim($stmt);
|
||||
if ($stmt === '') {
|
||||
continue;
|
||||
}
|
||||
$this->db->query($stmt);
|
||||
}
|
||||
|
||||
CLI::write(" [OK] $file", 'green');
|
||||
}
|
||||
|
||||
$this->db->query('SET FOREIGN_KEY_CHECKS = 1');
|
||||
$this->db->query('SET SQL_MODE = DEFAULT');
|
||||
|
||||
CLI::write('Lab template seeder complete.', 'green');
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple SQL splitter: splits on semicolons that are not inside
|
||||
* single-quoted or double-quoted strings.
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
private function splitSqlStatements(string $sql): array
|
||||
{
|
||||
$statements = [];
|
||||
$current = '';
|
||||
$inSingle = false;
|
||||
$inDouble = false;
|
||||
$len = strlen($sql);
|
||||
|
||||
for ($i = 0; $i < $len; $i++) {
|
||||
$char = $sql[$i];
|
||||
$prev = ($i > 0) ? $sql[$i - 1] : '';
|
||||
|
||||
if ($char === "'" && ! $inDouble && $prev !== '\\') {
|
||||
$inSingle = ! $inSingle;
|
||||
} elseif ($char === '"' && ! $inSingle && $prev !== '\\') {
|
||||
$inDouble = ! $inDouble;
|
||||
}
|
||||
|
||||
if ($char === ';' && ! $inSingle && ! $inDouble) {
|
||||
$statements[] = trim($current);
|
||||
$current = '';
|
||||
} else {
|
||||
$current .= $char;
|
||||
}
|
||||
}
|
||||
|
||||
if (trim($current) !== '') {
|
||||
$statements[] = trim($current);
|
||||
}
|
||||
|
||||
return $statements;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user