134 lines
3.5 KiB
PHP
134 lines
3.5 KiB
PHP
<?php
|
|
/**
|
|
* Smoke test: Vidal Corporate Analysis MIS.
|
|
* Run: php tests/smoke_vidal_mis_report.php [policy_id]
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
define('FCPATH', __DIR__ . '/../public/');
|
|
chdir(FCPATH);
|
|
|
|
require FCPATH . '../app/Config/Paths.php';
|
|
$paths = new Config\Paths();
|
|
require rtrim($paths->systemDirectory, '\\/ ') . DIRECTORY_SEPARATOR . 'bootstrap.php';
|
|
require_once SYSTEMPATH . 'Config/DotEnv.php';
|
|
(new CodeIgniter\Config\DotEnv(ROOTPATH))->load();
|
|
|
|
defined('ENVIRONMENT') || define('ENVIRONMENT', env('CI_ENVIRONMENT', 'development'));
|
|
|
|
$boot = APPPATH . 'Config/Boot/' . ENVIRONMENT . '.php';
|
|
if (is_file($boot)) {
|
|
require_once $boot;
|
|
}
|
|
|
|
require_once APPPATH . 'Config/Constants.php';
|
|
|
|
$policyId = (int) ($argv[1] ?? 0);
|
|
$db = \Config\Database::connect();
|
|
|
|
if ($policyId <= 0) {
|
|
$row = $db->query(
|
|
"SELECT cr.client_policy_id, COUNT(*) AS cnt
|
|
FROM claim_report cr
|
|
WHERE cr.source_table = 'claims_dump_vidal'
|
|
AND cr.is_active = 1
|
|
AND cr.source_row_id IS NOT NULL
|
|
GROUP BY cr.client_policy_id
|
|
ORDER BY cnt DESC
|
|
LIMIT 1"
|
|
)->getRowArray();
|
|
$policyId = (int) ($row['client_policy_id'] ?? 0);
|
|
echo "Auto-selected policy_id: {$policyId}\n";
|
|
}
|
|
|
|
if ($policyId <= 0) {
|
|
echo "FAIL: No policy with Vidal claim_report linkage found.\n";
|
|
exit(1);
|
|
}
|
|
|
|
$service = new \App\Libraries\VidalMisReportService();
|
|
$built = $service->build($policyId);
|
|
|
|
if (!$built['status']) {
|
|
echo 'FAIL: ' . ($built['message'] ?? 'unknown') . "\n";
|
|
exit(1);
|
|
}
|
|
|
|
$data = $built['data'];
|
|
$vm = $data['view_model'] ?? [];
|
|
|
|
$required = [
|
|
'meta', 'header', 'toc', 'icr', 'hospitalization', 'member_gender', 'member_age',
|
|
'claims_age', 'claims_amount', 'ailments', 'hospitals', 'cashless_member_summary',
|
|
'tat', 'month_on_month', 'payout', 'chart_gender', 'chart_age',
|
|
];
|
|
|
|
foreach ($required as $key) {
|
|
if (!array_key_exists($key, $vm)) {
|
|
echo "FAIL: missing view_model.{$key}\n";
|
|
exit(1);
|
|
}
|
|
}
|
|
|
|
echo "OK policy_id={$policyId}\n";
|
|
echo 'Policy: ' . ($data['header']['policy_number'] ?? '') . "\n";
|
|
echo 'Dump rows: ' . ($data['dump_row_count'] ?? 0) . "\n";
|
|
|
|
$html = view('claims_mis_vidal', [
|
|
'report' => $data,
|
|
'view_model' => $vm,
|
|
'policy_id' => $policyId,
|
|
'pdf_url' => '',
|
|
'embed' => true,
|
|
]);
|
|
|
|
$markers = [
|
|
'Corporate Analysis Report',
|
|
'Incurred Claims Ratio',
|
|
'Hospitalisation Type Details',
|
|
'Member Details - Relationship',
|
|
'Claims Approved - Age Band',
|
|
'Claims Approved - Amount Band',
|
|
'Ailment',
|
|
'Hospital',
|
|
'Turn Around Time',
|
|
'Month on Month',
|
|
'Payout Ratio',
|
|
'DISCLAIMER',
|
|
];
|
|
|
|
foreach ($markers as $m) {
|
|
if (stripos($html, $m) === false) {
|
|
echo "FAIL: HTML missing '{$m}'\n";
|
|
exit(1);
|
|
}
|
|
}
|
|
|
|
if (
|
|
stripos($html, 'vidal.png') === false
|
|
&& stripos($html, 'vidal_mis.png') === false
|
|
&& stripos($html, 'data:image') === false
|
|
) {
|
|
echo "FAIL: logo missing\n";
|
|
exit(1);
|
|
}
|
|
|
|
echo 'OK HTML (' . strlen($html) . " bytes)\n";
|
|
|
|
$pdf = (new \App\Libraries\VidalMisPdfService())->generateFromReport($data, $policyId);
|
|
if (!$pdf['status']) {
|
|
echo 'FAIL PDF: ' . ($pdf['message'] ?? '') . "\n";
|
|
exit(1);
|
|
}
|
|
|
|
$outDir = WRITEPATH . 'uploads/';
|
|
if (!is_dir($outDir)) {
|
|
@mkdir($outDir, 0775, true);
|
|
}
|
|
$outFile = $outDir . ($pdf['filename'] ?? 'VIDAL_MIS_smoke.pdf');
|
|
file_put_contents($outFile, $pdf['content']);
|
|
echo 'OK PDF: ' . $outFile . ' (' . strlen((string) $pdf['content']) . " bytes)\n";
|
|
|
|
exit(0);
|