129 lines
3.6 KiB
PHP
129 lines
3.6 KiB
PHP
<?php
|
|
/**
|
|
* Smoke test: Medi Assist Portfolio Analysis MIS.
|
|
* Run: php tests/smoke_medi_assist_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_medi_assist'
|
|
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 Medi Assist claim_report linkage found.\n";
|
|
exit(1);
|
|
}
|
|
|
|
$service = new \App\Libraries\MediAssistMisReportService();
|
|
$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', 'index_policies', 'portfolio_summary', 'policy_lives', 'policy_premium',
|
|
'claim_status_rows', 'claim_type_sections', 'savings', 'top_providers', 'top_ailments',
|
|
'beneficiary', 'age_bands', 'utilization_employees', 'utilization_dependents',
|
|
'amount_bands_cashless', 'amount_bands_reimbursement', 'glossary',
|
|
];
|
|
|
|
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";
|
|
echo 'Claims: ' . ($vm['portfolio_summary']['claims_count'] ?? 0) . "\n";
|
|
|
|
$html = view('claims_mis_medi_assist', [
|
|
'report' => $data,
|
|
'view_model' => $vm,
|
|
'policy_id' => $policyId,
|
|
'pdf_url' => '',
|
|
'embed' => true,
|
|
]);
|
|
|
|
$markers = [
|
|
'Portfolio Analysis Report',
|
|
'Portfolio Report',
|
|
'Savings Summary',
|
|
'Top 10 Distribution Across Providers',
|
|
'Distribution Across Beneficiary',
|
|
'Utilization Report for Employees',
|
|
'Distribution Across Amount Bands',
|
|
'Glossary',
|
|
];
|
|
|
|
foreach ($markers as $m) {
|
|
if (stripos($html, $m) === false) {
|
|
echo "FAIL: HTML missing '{$m}'\n";
|
|
exit(1);
|
|
}
|
|
}
|
|
|
|
if (stripos($html, 'medi_assist.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\MediAssistMisPdfService())->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'] ?? 'MA_MIS_smoke.pdf');
|
|
file_put_contents($outFile, $pdf['content']);
|
|
echo 'OK PDF: ' . $outFile . ' (' . strlen((string) $pdf['content']) . " bytes)\n";
|
|
|
|
exit(0);
|