Add native CodeIgniter 4 report generation functionality replacing legacy spooler_db system. Provides centralized report generation with audit logging and multi-language support. New Features: - Report generation with Indonesian and English language support - Role-based access control (Lab, Admin, Superuser: generate; CS: print only) - Preview mode for validation workflow - Print audit logging to AUDIT_REQUESTS table - Multi-page report support with proper pagination - Dual unit system (Conventional and International units) Controllers: - ReportController: Main controller for report generation, preview, and print - generate(): Full report with audit logging - preview(): Preview mode without audit logging - print(): Print-only access for CS role - Home::printReport(): Route handler redirecting based on user role Libraries: - ReportHelper: Comprehensive report data retrieval - Patient information (name, MR number, demographics, referral) - Test results with reference ranges and unit conversions - Collection and reception data with timestamps - Validation status and validator information - Special handling for pending samples and Chinese translations Routes: - /report/(:num) - Generate report (Lab, Admin, Superuser) - /report/(:num)/preview - Preview without audit logging - /report/(:num)/eng - English language report - /report/print/(:num) - Print-only access (CS role) - /print/(:num) - Redirect based on role (all roles) Views: - report/template.php: Professional lab report template with Gleneagles branding - Header and footer images - Patient information table - Test results with dual unit columns - Collection and reception timestamps - Authorization signature area - Preview watermark Role Index Views: - Removed dialog_preview.php inclusion from all role dashboards - Consolidated print button directly linking to new report routes Assets: - Report-specific CSS files (normalize.min.css, style.css, pdf.css, style_qr.css) - Gleneagles header and footer images - Legacy spooler_db files preserved in public/spooler_db/ for reference Tests: - ReportTest.php: Unit tests for report generation functionality Database: - Uses existing tables: REQUESTS, TESTS, DICT_TESTS, SP_REQUESTS, PATIENTS - Inserts print audit records into AUDIT_REQUESTS table Security: - Parameterized queries throughout (SQL injection prevention) - Role-based access control enforced at route level - Proper output escaping with esc() in views
72 lines
2.2 KiB
PHP
72 lines
2.2 KiB
PHP
<?php
|
|
|
|
use Tests\Support\DatabaseTestCase;
|
|
|
|
class ReportTest extends DatabaseTestCase
|
|
{
|
|
protected $migrate = false;
|
|
protected $refresh = false;
|
|
protected $db;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
$this->db = \Config\Database::connect();
|
|
}
|
|
|
|
public function testReportHelperInitialization()
|
|
{
|
|
$helper = new \App\Libraries\ReportHelper($this->db);
|
|
$this->assertInstanceOf(\App\Libraries\ReportHelper::class, $helper);
|
|
}
|
|
|
|
public function testCutDataFunction()
|
|
{
|
|
$helper = new \App\Libraries\ReportHelper($this->db);
|
|
|
|
$shortText = "This is short";
|
|
$result = $this->invokeMethod($helper, 'cutData', [$shortText]);
|
|
$this->assertEquals($shortText, $result);
|
|
|
|
$longText = "This is a very long text that should be cut into two parts because it exceeds ninety five characters in total length";
|
|
$result = $this->invokeMethod($helper, 'cutData', [$longText]);
|
|
$this->assertStringContainsString("\r\n", $result);
|
|
}
|
|
|
|
public function testGetHost()
|
|
{
|
|
$helper = new \App\Libraries\ReportHelper($this->db);
|
|
$result = $this->invokeMethod($helper, 'getHost', ['INVALID123']);
|
|
$this->assertIsString($result);
|
|
}
|
|
|
|
public function testGetNotes()
|
|
{
|
|
$helper = new \App\Libraries\ReportHelper($this->db);
|
|
$result = $this->invokeMethod($helper, 'getNotes', ['INVALID123']);
|
|
$this->assertIsString($result);
|
|
}
|
|
|
|
public function testGetStatus()
|
|
{
|
|
$helper = new \App\Libraries\ReportHelper($this->db);
|
|
$result = $this->invokeMethod($helper, 'getStatus', ['INVALID123']);
|
|
$this->assertIsString($result);
|
|
}
|
|
|
|
public function testGetValBy()
|
|
{
|
|
$helper = new \App\Libraries\ReportHelper($this->db);
|
|
$result = $this->invokeMethod($helper, 'getValBy', ['INVALID123']);
|
|
$this->assertIsString($result);
|
|
}
|
|
|
|
protected function invokeMethod(&$object, $methodName, array $parameters = [])
|
|
{
|
|
$reflection = new \ReflectionClass(get_class($object));
|
|
$method = $reflection->getMethod($methodName);
|
|
$method->setAccessible(true);
|
|
return $method->invokeArgs($object, $parameters);
|
|
}
|
|
}
|