64 lines
2.5 KiB
PHP
64 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace App\Commands;
|
|
|
|
use App\Libraries\ClaimReportSyncService;
|
|
use CodeIgniter\CLI\BaseCommand;
|
|
use CodeIgniter\CLI\CLI;
|
|
|
|
/**
|
|
* Copy linked TPA dump (+ optional ticket_master) claims into claim_report.
|
|
*
|
|
* Usage:
|
|
* php spark claim:sync-report
|
|
* php spark claim:sync-report --phase1
|
|
* php spark claim:sync-report --policy=12 --phase1
|
|
* php spark claim:sync-report --tpa=mediassist --policy=12
|
|
* php spark claim:sync-report --ticket-only
|
|
*/
|
|
class SyncClaimReportFromDump extends BaseCommand
|
|
{
|
|
protected $group = 'Claims';
|
|
protected $name = 'claim:sync-report';
|
|
protected $description = 'Sync claim_report from TPA dump tables + ticket_master';
|
|
protected $usage = 'claim:sync-report [--policy=ID] [--tpa=NAME|all] [--limit=N] [--phase1] [--ticket-only]';
|
|
protected $options = [
|
|
'--policy' => 'Optional client_policy_id',
|
|
'--tpa' => 'icici|abhi|mediassist|fhpl|rcare|vidal|all (default: all)',
|
|
'--limit' => 'Batch size per dump query (default 500)',
|
|
'--phase1' => 'TPA dump tables only (skip ticket_master)',
|
|
'--ticket-only' => 'Skip dump tables; copy only from ticket_master',
|
|
];
|
|
|
|
public function run(array $params)
|
|
{
|
|
$policyId = (int) ($params['policy'] ?? CLI::getOption('policy') ?? 0);
|
|
$limit = (int) ($params['limit'] ?? CLI::getOption('limit') ?? 500);
|
|
$ticketOnly = array_key_exists('ticket-only', $params) || CLI::getOption('ticket-only') !== null;
|
|
$phase1Only = array_key_exists('phase1', $params) || CLI::getOption('phase1') !== null;
|
|
$tpaOpt = strtolower(trim((string) ($params['tpa'] ?? CLI::getOption('tpa') ?? 'all')));
|
|
|
|
if ($limit <= 0) {
|
|
$limit = 500;
|
|
}
|
|
|
|
$result = (new ClaimReportSyncService())->sync($policyId, $tpaOpt, $limit, $ticketOnly, $phase1Only);
|
|
|
|
foreach ($result['logs'] as $line) {
|
|
$color = 'white';
|
|
if (str_starts_with($line, '[FAIL]')) {
|
|
$color = 'red';
|
|
} elseif (str_starts_with($line, '[DONE]') || str_starts_with($line, 'Done.')) {
|
|
$color = 'green';
|
|
} elseif (str_starts_with($line, '[SKIP]') || str_starts_with($line, 'Phase') || str_starts_with($line, 'Skipping')) {
|
|
$color = 'yellow';
|
|
} elseif (str_starts_with($line, ' ')) {
|
|
$color = 'green';
|
|
}
|
|
CLI::write($line, $color);
|
|
}
|
|
|
|
return ! empty($result['status']) ? EXIT_SUCCESS : EXIT_ERROR;
|
|
}
|
|
}
|