FIX_TPA_APIS_ICICI_AND_OTHERS

This commit is contained in:
VENKATESHWARAN 2026-04-06 21:49:59 +05:30
parent 931d556a7e
commit bb0501a8b4
6 changed files with 2024 additions and 385 deletions

View File

@ -350,6 +350,15 @@ class ApiServiceController extends BaseController
return $this->respond(['status' => true, 'code' => 200, 'message' => 'Action Triggered','data' => [] ]);
}else if ($tpa_id == $this->icici_primary_key) // ICICI Lombard (EWA)
{
$file_id = $fileModel->insert($data);
log_message('error', "ICICI - Files table inserted successfully, File id : {$file_id}");
$r = Jobs::addJob(['job_name' => 'getEnrollmentBatchStatus', 'payload' => ['client_policy_id' => $policy_id, 'file_id' => $file_id, 'client_policy_id' => $policy_id, 'return_type' => 'job']]);
log_message('error', "ICICI - getEnrollmentBatchStatus job pushed successfully.");
return $this->respond(['status' => true, 'code' => 200, 'message' => 'Action Triggered','data' => [] ]);
}else{
return $this->respond(['status' => false, 'code' => 200,'message' => 'TPA not found ','data' => [] ]);
}
@ -553,7 +562,6 @@ class ApiServiceController extends BaseController
]);
}
// public function getWellnessUrl()
// {
@ -725,7 +733,98 @@ class ApiServiceController extends BaseController
// }
public function sendDataToTPA()
{
$requested_data = $this->request->getPost() ?? [];
log_message('error', "getTPAID payloads :" . json_encode($requested_data));
$tpa_id = $requested_data['tpa_id'] ?? null;
$policy_no = $requested_data['policy_no'] ?? null;
$client_id = $requested_data['client_id'] ?? null;
$branch_id = $requested_data['client_branch_id'] ?? null;
$policy_id = $requested_data['client_policy_id'] ?? null;
$event = $requested_data['event'] ?? null;
$event_mapping = [
'inception' => 'A',
'missed_inception' => 'A',
'addition' => 'A',
'dependent_addition' => 'A',
'deletion' => 'D',
'correction' => 'M',
'si_enhancement' => 'M'
];
$fileModel = new BatchFileModel();
$filesData = $fileModel
->join('client_policy', 'client_policy.id = batch_files.client_policy_id')
->where('client_policy.tpa_id', $tpa_id)
->where('batch_files.is_active', 1)
->where('batch_files.event_type', 'api')
->where('batch_files.icici_status_flag !=', 'COMPLETED')
->countAllResults();
if($filesData > 0){
log_message('error', "TPA initiation is in progress.");
return $this->respond(['status' => false, 'code' => 200,'message' => 'TPA initiation is in progress.','data' => [] ]);
}
$employeePolicyModel = new EmployeePolicyModel();
$employeePolicyData = $employeePolicyModel
->select('
employees.*,
employee_polices.id as emp_policy_id,
employee_polices.client_policy_id,
')
->join('employees', 'employees.id = employee_polices.employee_id')
->where('employee_polices.is_active', 1)
->where('employee_polices.status', 'active')
->where('employees.is_active', 1)
->where('employees.emp_status', 'active')
->where('employee_polices.tpa_id IS NULL')
->where('employee_polices.client_policy_id', $policy_id)
->countAllResults();
if($employeePolicyData == 0){
log_message('error', "No Employee Policy found with null TPA ID. TPA ID is already updated.");
return $this->respond(['status' => false, 'code' => 200,'message' => 'No employee to upload','data' => [] ]);
}
$data = [
'file_name' => "API - Employee data push",
'event_type' => $event,
'actions' => "push",
'insurer_or_tpa' => "tpa",
'batch_code' => generate_random_string(4),
'status' => "inprogress",
'client_id' => $client_id,
'client_policy_id'=> $policy_id,
'client_branch_id'=> $branch_id,
'created_by'=> get_session_userid(),
];
if ($tpa_id == $this->icici_primary_key) // MediAssist
{
$file_id = $fileModel->insert($data);
log_message('error', "Files table inserted successfully, File id : {$file_id}");
$requested_data['file_id'] = $file_id;
$requested_data['return_type'] = 'job';
$requested_data['insurer_or_tpa'] = 'tpa';
$requested_data['flag_status'] = $event_mapping[$event] ?? "A";
$ICICILombardController = new ICICILombardController();
$apiResponse = $ICICILombardController->ICICIPushEmployeeDetails($requested_data);
// $r = Jobs::addJob(['job_name' => 'ICICIPushEmployeeDetails', 'payload' => $requested_data]);
// log_message('error', "ICICIPushEmployeeDetails job pushed successfully.");
return $this->respond(['status' => true, 'code' => 200, 'message' => 'Action Triggered','data' => $apiResponse ]);
}
}

View File

@ -784,6 +784,8 @@ class EmployeeServiceController extends AdminController
//get file name
// check_dob_diff('4-APr-1990');die();
$file_id = $params['file_id'];
$batch_file_id = $params['batch_file_id'] ?? null;
$file = $this->fileModel->find((int)$file_id);
// dd($file);
$return = [];
@ -1063,7 +1065,7 @@ class EmployeeServiceController extends AdminController
//proceed next data level validation in JOB queue
$job_details = new Jobs();
$r = Jobs::addJob(['job_name' => 'excelFileDataValidation','payload' => ['file_id' => $file_id]]);
$r = Jobs::addJob(['job_name' => 'excelFileDataValidation','payload' => ['file_id' => $file_id, 'batch_file_id' => $batch_file_id]]);
// $jobWorker = new JobWorker();
// JobWorker::processJob($r);
@ -1077,6 +1079,8 @@ class EmployeeServiceController extends AdminController
helper('excel_util_helper');
//get file name
$file_id = $params['file_id'];
$batch_file_id = $params['batch_file_id'] ?? null;
$file = $this->fileModel->find((int)$file_id);
// dd($file);
$return = [];
@ -1307,13 +1311,13 @@ class EmployeeServiceController extends AdminController
//proceed next data level validation in JOB queue
$job_details = new Jobs();
$r = Jobs::addJob(['job_name' => 'employeesCorrectionProcess','payload' => ['file_id' => $file_id]]);
$r = Jobs::addJob(['job_name' => 'employeesCorrectionProcess','payload' => ['file_id' => $file_id, 'batch_file_id' => $batch_file_id]]);
}
else if ($file['action'] == 'inception' || $file['action'] == 'missed_inception' || $file['action'] == 'addition' || $file['action'] == 'dependent_addition')//inception OR addition OR dependent addition
{
//proceed next data level validation in JOB queue
// $job_details = new Jobs();
$r = Jobs::addJob(['job_name' => 'employeesOnboardPreprocess','payload' => ['file_id' => $file_id]]);
$r = Jobs::addJob(['job_name' => 'employeesOnboardPreprocess','payload' => ['file_id' => $file_id, 'batch_file_id' => $batch_file_id]]);
// $jobWorker = new JobWorker();
// JobWorker::processJob($r);
}
@ -1333,166 +1337,183 @@ class EmployeeServiceController extends AdminController
{
helper('excel_util_helper');
// dd($params);
if(isset($params['file_id']))//handle data from excel to inception
if (isset($params['file_id'])) //handle data from excel to inception
{
//get file name
$file_id = $params['file_id'];
$file = $this->fileModel->find((int)$file_id);
// dd($file);
$return = [];
if(!isset($file))
{
//file not found in DB
return array('status' => false, 'msg' => 'file not found in DB');
}
$file_name_with_path = WRITEPATH."/uploads/excel/".$file['file_name'];
//check physical file
if(!file_exists($file_name_with_path))
{
//file not found update status and reason
$message = "Physical file not found";
// echo $message;
$this->myLogger->logme('error',($message . ' for file id ' . $file_id));
$this->fileModel->where('id', $file_id)->set(['status' => 'failed','reason' => json_encode(['error_summary' => array_count_values([5]),'error_data' => $message])])->update();
return array('error_summary' => [5], 'error_data' => $message);
}
//get file name
$file_id = $params['file_id'];
$file = $this->fileModel->find((int)$file_id);
// dd($file);
$return = [];
if (!isset($file)) {
//file not found in DB
return array('status' => false, 'msg' => 'file not found in DB');
}
$file_name_with_path = WRITEPATH . "/uploads/excel/" . $file['file_name'];
$columns_to_check = [];
if($file['action'] == 'inception'){ $columns_to_check = $this->inception_excel_columns; }
if($file['action'] == 'addition'){ $columns_to_check = $this->inception_excel_columns; }
if($file['action'] == 'dependent_addition'){ $columns_to_check = $this->inception_excel_columns; }
if($file['action'] == 'deletion'){ $columns_to_check = $this->deletion_excel_columns; }
if($file['action'] == 'correction'){ $columns_to_check = $this->correction_excel_columns; }
if($file['action'] == 'si_enhancement'){ $columns_to_check = $this->si_enhance_excel_columns; }
if($file['action'] == 'missed_inception'){ $columns_to_check = $this->inception_excel_columns; }
//check physical file
if (!file_exists($file_name_with_path)) {
//file not found update status and reason
$message = "Physical file not found";
// echo $message;
$this->myLogger->logme('error', ($message . ' for file id ' . $file_id));
$this->fileModel->where('id', $file_id)->set(['status' => 'failed', 'reason' => json_encode(['error_summary' => array_count_values([5]), 'error_data' => $message])])->update();
return array('error_summary' => [5], 'error_data' => $message);
}
$current_column_action = null;
if($file['action'] == 'inception'){ $current_column_action = 'I'; }
else if($file['action'] == 'addition'){ $current_column_action = 'A'; }
else if($file['action'] == 'dependent_addition'){ $current_column_action = 'DA'; }
else if($file['action'] == 'deletion'){ $current_column_action = 'D'; }
else if($file['action'] == 'correction'){ $current_column_action = 'C'; }
else if($file['action'] == 'si_enhancement'){ $current_column_action = 'SI'; }
else if($file['action'] == 'enrollment'){ $current_column_action = 'I'; }
else if($file['action'] == 'missed_inception'){ $current_column_action = 'MI'; }
$columns_to_check = [];
if ($file['action'] == 'inception') {
$columns_to_check = $this->inception_excel_columns;
}
if ($file['action'] == 'addition') {
$columns_to_check = $this->inception_excel_columns;
}
if ($file['action'] == 'dependent_addition') {
$columns_to_check = $this->inception_excel_columns;
}
if ($file['action'] == 'deletion') {
$columns_to_check = $this->deletion_excel_columns;
}
if ($file['action'] == 'correction') {
$columns_to_check = $this->correction_excel_columns;
}
if ($file['action'] == 'si_enhancement') {
$columns_to_check = $this->si_enhance_excel_columns;
}
if ($file['action'] == 'missed_inception') {
$columns_to_check = $this->inception_excel_columns;
}
// get policy and rack details
$policy_terms = $this->clientPolicyModel->getPolicyDetails($file['client_id'],$file['policy_id']);
$policy_terms = (array) $policy_terms[0];// convert obj to array
// $policy_terms = json_decode($policy_terms[0]->policy_terms);
// dd($policy_terms);
//get excel data
$spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($file_name_with_path);
$sheet = $spreadsheet->getActiveSheet();
$highestRowAndColumn = $sheet->getHighestRowAndColumn();
$allowedHighestColumn = end($columns_to_check);
// dd($allowedHighestColumn);
$excel_data = $sheet->rangeToArray('A1:' . $allowedHighestColumn['col_cell_name'] . $highestRowAndColumn['row']);
unset($excel_data[0]);
$current_column_action = null;
if ($file['action'] == 'inception') {
$current_column_action = 'I';
} else if ($file['action'] == 'addition') {
$current_column_action = 'A';
} else if ($file['action'] == 'dependent_addition') {
$current_column_action = 'DA';
} else if ($file['action'] == 'deletion') {
$current_column_action = 'D';
} else if ($file['action'] == 'correction') {
$current_column_action = 'C';
} else if ($file['action'] == 'si_enhancement') {
$current_column_action = 'SI';
} else if ($file['action'] == 'enrollment') {
$current_column_action = 'I';
} else if ($file['action'] == 'missed_inception') {
$current_column_action = 'MI';
}
// get policy and rack details
$policy_terms = $this->clientPolicyModel->getPolicyDetails($file['client_id'], $file['policy_id']);
$policy_terms = (array) $policy_terms[0]; // convert obj to array
// $policy_terms = json_decode($policy_terms[0]->policy_terms);
//get policy slab rates
$slab_details = $this->policiesModel->getPolicySlabRatesForEmpOnboard($file['policy_id'],$file['client_id']);
// dd($slab_details);
//get existing units in the current branch
$existing_units = $this->clientBranchModel->getExisitingUnits(client_id: $file['client_id'],client_branch_id: $file['client_branch_id']);
// dd($policy_terms);
//get excel data
$spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($file_name_with_path);
$sheet = $spreadsheet->getActiveSheet();
$employee_data_group_by_family = data_group_by_family($excel_data, 'excel', '', $current_column_action);
// dd($employee_data_group_by_family);
$highestRowAndColumn = $sheet->getHighestRowAndColumn();
$allowedHighestColumn = end($columns_to_check);
// dd($allowedHighestColumn);
$excel_data = $sheet->rangeToArray('A1:' . $allowedHighestColumn['col_cell_name'] . $highestRowAndColumn['row']);
unset($excel_data[0]);
// dd($excel_data);
$employee_insert_count = 0;
foreach ($employee_data_group_by_family as $emp_id => $family)
{
//get policy slab rates
$slab_details = $this->policiesModel->getPolicySlabRatesForEmpOnboard($file['policy_id'], $file['client_id']);
// dd($slab_details);
//get existing units in the current branch
$existing_units = $this->clientBranchModel->getExisitingUnits(client_id: $file['client_id'], client_branch_id: $file['client_branch_id']);
//if action is DA then get all familiy members,transfrom them into excel array, addd data source as db or excel
if($file['action'] == 'dependent_addition')
{
$existing_famility_details = $this->employeeModel->getEmpFamilybyEmpCode(emp_code: $emp_id,client_id: $file['client_id'],client_policy_id: $file ['policy_id'],emp_status: ['active'],policy_status:['active'],client_branch_id: [ $file['client_branch_id'] ]);
// dd($existing_famility_details);
//transsform familiy details from db columns to exxcel row with column indexs for checking remaining functionalitites
$existing_famility_details = transform_db_data_to_excel($existing_famility_details,$file);
// Kint::dump($existing_famility_details);
$family = array_merge($family,$existing_famility_details);
$family = data_group_by_family($family, 'excel', 1)[ $emp_id ];// reason to call this again is bring self to first index of the array
// dd($family);
$self = current(array_filter($family, fn($r) => strtolower($r[5] ?? '') === 'self'));
$premium = (int)($self['temp']['rata_premimum'] ?? 0);
foreach ($family as &$r) if (strtolower($r[5] ?? '') !== 'self') $r['self_rata_premium'] = $premium;
}
$employee_data_group_by_family = data_group_by_family($excel_data, 'excel', '', $current_column_action);
// dd($employee_data_group_by_family);
// Kint::dump($family);
$data = calculate_premium_new(family_data:$family,policy_terms: $policy_terms,slab_details : $slab_details,fileArr: $file, existing_units:$existing_units);
// dd($data);
$employee_data_group_by_family[$emp_id] = $data;
$res = $this->employeesOnboardProcess(['familiy_data' => $data,'file' => $file]);
$employee_insert_count = 0;
foreach ($employee_data_group_by_family as $emp_id => $family) {
if($res > 0){
$employee_insert_count++;
}
}
//if action is DA then get all familiy members,transfrom them into excel array, addd data source as db or excel
if ($file['action'] == 'dependent_addition') {
$existing_famility_details = $this->employeeModel->getEmpFamilybyEmpCode(emp_code: $emp_id, client_id: $file['client_id'], client_policy_id: $file['policy_id'], emp_status: ['active'], policy_status: ['active'], client_branch_id: [$file['client_branch_id']]);
// dd($existing_famility_details);
//transsform familiy details from db columns to exxcel row with column indexs for checking remaining functionalitites
$existing_famility_details = transform_db_data_to_excel($existing_famility_details, $file);
// Kint::dump($existing_famility_details);
$family = array_merge($family, $existing_famility_details);
$family = data_group_by_family($family, 'excel', 1)[$emp_id]; // reason to call this again is bring self to first index of the array
// dd($family);
$self = current(array_filter($family, fn($r) => strtolower($r[5] ?? '') === 'self'));
$premium = (int)($self['temp']['rata_premimum'] ?? 0);
foreach ($family as &$r) if (strtolower($r[5] ?? '') !== 'self') $r['self_rata_premium'] = $premium;
}
if($employee_insert_count > 0){
$this->fileModel->where('id', $file_id)->set(['status' => 'success','reason' => ''])->update();
$this->myLogger->logme("error",'{file_id} uploaded success',['file_id' => $file_id]);
}else{
$reason = json_encode([
'error_summary' => [5 => 1],
'error_data' => "Rack rate configuration issue: Please check the slab rates configuration"
], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
$this->fileModel->where('id', $file_id)->set(['status' => 'failed','reason' => $reason])->update();
$this->myLogger->logme("error",'{file_id} uploaded failed with reason: Rack rate configuration issue: Please check the slab rates configuration',['file_id' => $file_id]);
// Kint::dump($family);
$data = calculate_premium_new(family_data: $family, policy_terms: $policy_terms, slab_details: $slab_details, fileArr: $file, existing_units: $existing_units);
// dd($data);
$employee_data_group_by_family[$emp_id] = $data;
// $res = $this->employeesOnboardProcess(['familiy_data' => $data, 'file' => $file]);
}
// if ($res > 0) {
// $employee_insert_count++;
// }
}
$this->setPullNotification($this->getFileMetaDataByFileId($file_id,'success'));
// if ($employee_insert_count > 0) {
// $this->fileModel->where('id', $file_id)->set(['status' => 'success', 'reason' => ''])->update();
// $this->myLogger->logme("error", '{file_id} uploaded success', ['file_id' => $file_id]);
// } else {
// $reason = json_encode([
// 'error_summary' => [5 => 1],
// 'error_data' => "Rack rate configuration issue: Please check the slab rates configuration"
// ], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
// $this->fileModel->where('id', $file_id)->set(['status' => 'failed', 'reason' => $reason])->update();
// $this->myLogger->logme("error", '{file_id} uploaded failed with reason: Rack rate configuration issue: Please check the slab rates configuration', ['file_id' => $file_id]);
// }
}
else if(isset($params['client_policy_id']))//handle data from enrollment to inception
{
// $this->setPullNotification($this->getFileMetaDataByFileId($file_id, 'success'));
} else if (isset($params['client_policy_id'])) //handle data from enrollment to inception
{
$client_policy_id = $params['client_policy_id'];
//get client id
$client_id = ($this->clientPolicyModel->select('client_id')->find((int)$client_policy_id))['client_id'];
// dd($client_id);
// get policy and rack details
$policy_terms = $this->clientPolicyModel->getPolicyDetails($client_id,$client_policy_id);
$policy_terms = (array) $policy_terms[0];// convert obj to array
$policy_terms = $this->clientPolicyModel->getPolicyDetails($client_id, $client_policy_id);
$policy_terms = (array) $policy_terms[0]; // convert obj to array
//get policy slab rates
$slab_details = $this->policiesModel->getPolicySlabRatesForEmpOnboard($client_policy_id,$client_id);
$slab_details = $this->policiesModel->getPolicySlabRatesForEmpOnboard($client_policy_id, $client_id);
$existing_famility_details = $this->employeeModel->getEmpFamilybyEmpCode(client_id: $client_id,client_policy_id: $client_policy_id,emp_status: ['enrolled'],policy_status:['enrolled']);
$existing_famility_details = $this->employeeModel->getEmpFamilybyEmpCode(client_id: $client_id, client_policy_id: $client_policy_id, emp_status: ['enrolled'], policy_status: ['enrolled']);
// $file = ['id' => null,'client_id' => $client_id,'policy_id' => $client_policy_id,'action' => 'inception'];
$file = ['id' => null,'client_id' => $client_id,'policy_id' => $client_policy_id,'action' => 'inception','created_by' => get_session_userid(),'client_branch_id' => $params['client_branch_id']];
$file = ['id' => null, 'client_id' => $client_id, 'policy_id' => $client_policy_id, 'action' => 'inception', 'created_by' => get_session_userid(), 'client_branch_id' => $params['client_branch_id']];
//get existing units in the current branch
$existing_units = $this->clientBranchModel->getExisitingUnits(client_id: $file['client_id'],client_branch_id: $file['client_branch_id']);
$existing_units = $this->clientBranchModel->getExisitingUnits(client_id: $file['client_id'], client_branch_id: $file['client_branch_id']);
// dd($this->employeeModel->getLastQuery());
// Kint::dump($existing_famility_details);die();
$employee_data_group_by_family = data_group_by_family($existing_famility_details,$data_source = 'db');
// dd($employee_data_group_by_family);
foreach ($employee_data_group_by_family as $emp_id => $family)
{
$employee_data_group_by_family = data_group_by_family($existing_famility_details, $data_source = 'db');
// dd($employee_data_group_by_family);
foreach ($employee_data_group_by_family as $emp_id => $family) {
$transformed_famility_details = transform_db_data_to_excel($family);
// $data = calculate_premium_new($transformed_famility_details,$policy_terms,$slab_details,$file);
$data = calculate_premium_new(family_data:$transformed_famility_details,policy_terms: $policy_terms,slab_details : $slab_details,fileArr: $file, existing_units:$existing_units);
// dd($data);
$employee_data_group_by_family[$emp_id] = $data;
$this->employeesOnboardProcess(['familiy_data' => $data,'file' => $file]);
}
// $data = calculate_premium_new($transformed_famility_details,$policy_terms,$slab_details,$file);
$data = calculate_premium_new(family_data: $transformed_famility_details, policy_terms: $policy_terms, slab_details: $slab_details, fileArr: $file, existing_units: $existing_units);
// dd($data);
$employee_data_group_by_family[$emp_id] = $data;
$this->employeesOnboardProcess(['familiy_data' => $data, 'file' => $file]);
}
// dd($employee_data_group_by_family);
}
// dd($employee_data_group_by_family);
}
if(count($employee_data_group_by_family ?? []) && isset($params['batch_file_id'])){
$r = Jobs::addJob(['job_name' => 'updateEmployeeDataFromTpa','payload' => ['file_id' => $file_id, 'batch_file_id' => $params['batch_file_id']]]);
$this->myLogger->logme("info", 'Batch file id {batch_file_id} processed successfully', ['batch_file_id' => $params['batch_file_id']]);
}
// die();
return (count($employee_data_group_by_family));
}
//deletion of emp
@ -1652,6 +1673,7 @@ class EmployeeServiceController extends AdminController
helper('excel_util_helper');
//get file name
$file_id = $params['file_id'];
$batch_file_id = $params['batch_file_id'] ?? null;
$file = $this->fileModel->find((int)$file_id);
// dd($file);
@ -1718,6 +1740,12 @@ class EmployeeServiceController extends AdminController
}
if(!empty($batch_file_id)){
$r = Jobs::addJob(['job_name' => 'updateEmployeeDataFromTpa','payload' => ['file_id' => $file_id, 'batch_file_id' => $batch_file_id]]);
$this->myLogger->logme("error", 'Batch file id {batch_file_id} processed successfully', ['batch_file_id' => $batch_file_id]);
}
$this->fileModel->where('id', $file_id)->set(['status' => 'success','reason' => ''])->update();
$this->myLogger->logme("error",'{file_id} uploaded success',['file_id' => $file_id]);
//set success msg to pull notifications

File diff suppressed because it is too large Load Diff

View File

@ -19,6 +19,14 @@ class VidalApiController extends BaseController
protected $claim_type_array;
protected $ticketController;
/**
* Vidal `relation` (lowercase) Nhance relation (lowercase).
* Populated once from {@see self::vidalRelationshipReferenceMap()} (values match public/tmp/relationship.csv; that file is reference only, not read at runtime).
*
* @var array<string, string>
*/
protected array $vidalRelationshipMap = [];
public function __construct()
{
$this->db = \Config\Database::connect();
@ -26,6 +34,8 @@ class VidalApiController extends BaseController
$this->ticketController = new TicketController();
$this->claim_type_array = $this->ticketController->claimType;
$this->vidalRelationshipMap = self::vidalRelationshipReferenceMap();
}
@ -1022,6 +1032,522 @@ class VidalApiController extends BaseController
}
}
public function VidalGetBenefDetailsV2($requestData = null)
{
$requestData = is_array($requestData) ? $requestData : [];
$function_calling_type = $requestData['return_type'] ?? 'job';
try {
helper('api');
$url = $this->vidalEnrollmentInfoApiUrl();
$method = 'POST';
$subscriptionKey = getenv('VIDAL_API_SUBSCRIPTION_KEY');
if (empty($subscriptionKey)) {
log_message('error', 'VIDAL V2 - TPA ID Pull | VIDAL_API_SUBSCRIPTION_KEY missing');
if ($function_calling_type === 'job') {
return ['status' => false, 'message' => 'VIDAL_API_SUBSCRIPTION_KEY required'];
}
return $this->respond(['status' => false, 'message' => 'VIDAL_API_SUBSCRIPTION_KEY required']);
}
$headers = [
'Content-Type: application/json',
'ocp-apim-subscription-key: ' . $subscriptionKey,
];
$policyNo = $requestData['policy_no'] ?? null;
$client_policy_id = $requestData['client_policy_id'] ?? null;
if (empty($policyNo)) {
log_message('error', 'VIDAL V2 - TPA ID Pull | policy_no missing in request');
if ($function_calling_type === 'job') {
return ['status' => false, 'message' => 'policy_no required'];
}
return $this->respond(['status' => false, 'message' => 'policy_no required']);
}
if (empty($client_policy_id)) {
log_message('error', 'VIDAL V2 - TPA ID Pull | client_policy_id missing in request');
if ($function_calling_type === 'job') {
return ['status' => false, 'message' => 'client_policy_id required'];
}
return $this->respond(['status' => false, 'message' => 'client_policy_id required']);
}
log_message('error', "VIDAL V2 - TPA ID Pull | called for policy_no: {$policyNo} , client_policy_id: {$client_policy_id}");
$batchFiles = $this->db->table('batch_files f')
->select('f.created_at')
->where('f.client_policy_id', $client_policy_id)
->where('f.insurer_or_tpa', 'tpa')
->where('f.actions', 'export')
->get()
->getResultArray();
if (empty($batchFiles)) {
log_message('error', 'VIDAL V2 - TPA ID Pull FAILED | batchFiles is empty for this tpa id pull request');
if ($function_calling_type === 'job') {
return ['status' => false, 'message' => 'batchFiles not found'];
}
return $this->respond(['status' => false, 'message' => 'batchFiles not found']);
}
$pageSize = 100;
$startIndex = 1;
$allBenef = [];
while (true) {
$endIndex = $startIndex + $pageSize - 1;
$body = [
'policyNo' => $policyNo,
'startIndex' => $startIndex,
'endIndex' => $endIndex,
];
log_message('error', 'VIDAL V2 - TPA ID Pull | API params ' . json_encode([$url, $method, $headers, $body]));
$response = call_third_party_api($url, $method, $headers, $body);
if ($response['status'] !== true) {
if (isset($requestData['file_id']) && !empty($requestData['file_id'])) {
$file_model = new BatchFileModel();
$file_model->where('id', $requestData['file_id'])->set('status', 'failed-8')->update();
log_message('error', "VIDAL V2 - TPA ID Pull | Files table status updated for the file id : {$requestData['file_id']}");
} else {
log_message('error', 'VIDAL V2 - TPA ID Pull | Failed to update file table status.');
}
log_message('error', 'VIDAL V2 - TPA ID Pull API FAILED | API failed: ' . json_encode($response));
if ($function_calling_type === 'job') {
return ['status' => false, 'message' => 'API call failed', 'data' => $response];
}
return $this->respond(['status' => false, 'message' => 'API call failed', 'data' => $response]);
}
$apiRoot = $response['data'] ?? [];
if (($apiRoot['status'] ?? '') !== 'SUCCESS'
|| (array_key_exists('successful', $apiRoot) && $apiRoot['successful'] === false)) {
log_message('error', 'VIDAL V2 - TPA ID Pull API FAILED | envelope: ' . json_encode($apiRoot));
if (isset($requestData['file_id']) && !empty($requestData['file_id'])) {
$file_model = new BatchFileModel();
$file_model->where('id', $requestData['file_id'])->set('status', 'failed-8')->update();
}
if ($function_calling_type === 'job') {
return ['status' => false, 'message' => 'API call failed', 'data' => $apiRoot];
}
return $this->respond(['status' => false, 'message' => 'API call failed', 'data' => $apiRoot]);
}
$chunk = $apiRoot['data'] ?? null;
if (!is_array($chunk)) {
log_message('error', 'VIDAL V2 - TPA ID Pull FAILED | data is not an array: ' . json_encode($apiRoot));
break;
}
if (count($chunk) === 0) {
if ($startIndex === 1) {
log_message('error', "VIDAL V2 - TPA ID Pull FAILED | empty data on first page");
if (isset($requestData['file_id']) && !empty($requestData['file_id'])) {
$file_model = new BatchFileModel();
$file_model->where('id', $requestData['file_id'])->set('status', 'failed-8')->update();
}
if ($function_calling_type === 'job') {
return ['status' => false, 'message' => 'No enrollment records returned', 'data' => $apiRoot];
}
return $this->respond(['status' => false, 'message' => 'No enrollment records returned', 'data' => $apiRoot]);
}
break;
}
foreach ($chunk as $rec) {
if (is_array($rec)) {
$allBenef[] = $this->normalizeVidalEnrollmentRecordToDependentFormat($rec);
}
}
log_message('error', 'VIDAL V2 - TPA ID Pull | Fetched ' . count($chunk) . ' records (page startIndex=' . $startIndex . ')');
if (count($chunk) < $pageSize) {
break;
}
$startIndex += $pageSize;
}
$json = json_encode($allBenef, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
$filePath = WRITEPATH . 'tmp/' . time() . '_' . $requestData['file_id'] . '.json';
file_put_contents($filePath, $json);
Jobs::addJob(['job_name' => 'saveVidalAPIData', 'payload' => ['file_id' => $requestData['file_id'], 'json_file_path' => $filePath]]);
$employeePolicyModel = new EmployeePolicyModel();
$employeePolicyData = $employeePolicyModel
->select('
employees.*,
employee_polices.id as emp_policy_id,
employee_polices.client_policy_id,
')
->join('employees', 'employees.id = employee_polices.employee_id')
->where('employee_polices.is_active', 1)
->where('employee_polices.status', 'active')
->where('employees.is_active', 1)
->where('employees.emp_status', 'active')
->where('employee_polices.tpa_id IS NULL')
->where('employee_polices.client_policy_id', $client_policy_id)
->findAll();
$batch_file_success = 'success';
$updated = 0;
$totalCount = count($employeePolicyData);
$employee_policy_ids = [];
foreach ($employeePolicyData as $policy_data) {
$hasMatchForThisPolicy = false;
foreach ($allBenef as $row) {
if (
strtolower(trim($policy_data['name'] ?? '')) === strtolower(trim($row['name'] ?? '')) &&
($policy_data['emp_code'] ?? '') === ($row['empNo'] ?? '') &&
strtolower(trim($policy_data['relationship'] ?? '')) === strtolower(trim(str_replace('-', ' ', $row['relationship'] ?? ''))) &&
($policy_data['gender'] ?? '') === ($row['gender'] ?? '') &&
($policy_data['dob'] ?? '') === (change_date_format($row['dob'], 'Y-m-d H:i:s') ?? '')
) {
$hasMatchForThisPolicy = true;
$sql = 'UPDATE employee_polices
SET tpa_id = :tpa_id:
WHERE id = :emp_policy_id:';
$this->db->query($sql, ['tpa_id' => $row['enrollmentId'], 'emp_policy_id' => $policy_data['emp_policy_id']]);
if (strtolower(trim($policy_data['relationship'])) === 'self') {
$employee_policy_ids[] = $policy_data['emp_policy_id'];
}
if ($this->db->affectedRows() > 0) {
$updated++;
log_message('error', "VIDAL V2 - TPA ID Pull | Updated tpa_id={$row['enrollmentId']} for emp_code={$row['empNo']} policy={$row['policyNumber']}");
} else {
log_message('error', "VIDAL V2 - TPA ID Pull | No update (already set or not matched) for emp_code={$row['empNo']} policy={$row['policyNumber']}");
}
}
}
if (!$hasMatchForThisPolicy) {
$nhanceSideData = [
'name' => $policy_data['name'] ?? null,
'emp_code' => $policy_data['emp_code'] ?? null,
'relationship' => $policy_data['relationship'] ?? null,
'gender' => $policy_data['gender'] ?? null,
'dob' => $policy_data['dob'] ?? null,
];
$batch_file_success = 'partially success';
log_message(
'error',
'VIDAL V2 - TPA ID Pull | No match for Nhance = ' . json_encode($nhanceSideData)
);
}
}
if (!empty($employee_policy_ids)) {
log_message('error', 'sendMailForDownloadingECard JOB PUSHED (V2).');
Jobs::addJob(['job_name' => 'sendMailForDownloadingECard', 'payload' => ['ids' => $employee_policy_ids, 'client_policy_id' => $client_policy_id]]);
}
if (isset($requestData['file_id']) && !empty($requestData['file_id'])) {
$file_model = new BatchFileModel();
$file_model->where('id', $requestData['file_id'])->set('status', $batch_file_success)->update();
log_message('error', "VIDAL V2 - Files table status updated for the file id : {$requestData['file_id']}");
} else {
log_message('error', 'VIDAL V2 - Failed to update file table status.');
}
log_message('error', "VIDAL V2 - TPA ID Pull SUCCESS | completed. Total fetched={$totalCount}, updated={$updated}");
if ($function_calling_type === 'job') {
return [
'status' => true,
'message' => 'Updated successfully',
'total_fetched' => $totalCount,
'total_updated' => $updated,
];
}
return $this->respond([
'status' => true,
'message' => 'Updated successfully',
'total_fetched' => $totalCount,
'total_updated' => $updated,
]);
} catch (\Throwable $th) {
if (isset($requestData['file_id']) && !empty($requestData['file_id'])) {
$file_model = new BatchFileModel();
$file_model->where('id', $requestData['file_id'])->set('status', 'failed-8')->update();
log_message('error', "VIDAL V2 - Files table status updated for the file id : {$requestData['file_id']}");
} else {
log_message('error', 'VIDAL V2 - Failed to update file table status.');
}
$errorData = [
'message' => $th->getMessage(),
'file' => $th->getFile(),
'line' => $th->getLine(),
'code' => $th->getCode(),
'trace' => $th->getTraceAsString(),
'trace_array' => $th->getTrace(),
'function' => $th->getTrace()[0]['function'] ?? null,
'class' => $th->getTrace()[0]['class'] ?? null,
];
log_message('error', 'VIDAL V2 - Exception thrown while calling GetBenefDetailsV2 API: ' . json_encode($errorData));
if ($function_calling_type === 'job') {
return ['status' => false, 'message' => 'API call failed', 'data' => $errorData];
}
return $this->respond(['status' => false, 'message' => 'API call failed', 'data' => $errorData]);
}
}
/**
* Nhance relationship => list of Vidal `relation` labels (any case). Edit the grouped list only; the flat map is built here.
* Reference: public/tmp/relationship.csv (documentation only).
*
* @return array<string, string> lowercase Vidal label (and hyphen/space variant) => Nhance relation key
*/
private static function vidalRelationshipReferenceMap(): array
{
$relationshipGrouped = [
'self' => [
'SELF',
'EMPLOYER',
'EMPLOYEE',
'EMPLOYEES',
],
'spouse' => [
'SPOUSE',
'PARTNER',
'HUSBAND',
'HUSBAND (2)',
'HUSBAND (3)',
'HUSBAND (4)',
'HUSBAND (5)',
'WIFE',
'WIFE (2)',
'WIFE (3)',
'WIFE (4)',
'WIFE (5)',
],
'father' => [
'FATHER',
'FATHER (2)',
'FATHER (3)',
'FATHER (4)',
'FATHER (5)',
],
'mother' => [
'MOTHER',
'MOTHER (2)',
'MOTHER (3)',
'MOTHER (4)',
'MOTHER (5)',
],
'son' => [
'SON',
'SON (2)',
'SON (3)',
'SON (4)',
'SON (5)',
],
'daughter' => [
'DAUGHTER',
'DAUGHTER (2)',
'DAUGHTER (3)',
'DAUGHTER (4)',
'DAUGHTER (5)',
],
'father in law' => [
'FATHER-IN-LAW',
'FATHER-IN-LAW (2)',
],
'mother in law' => [
'MOTHER-IN-LAW',
'MOTHER-IN-LAW (2)',
],
];
return self::flattenVidalRelationshipGroupedToLookupMap($relationshipGrouped);
}
/**
* @param array<string, list<string>> $grouped
*
* @return array<string, string>
*/
private static function flattenVidalRelationshipGroupedToLookupMap(array $grouped): array
{
$map = [];
foreach ($grouped as $nhanceRelation => $vidalLabels) {
foreach ($vidalLabels as $label) {
$label = trim((string) $label);
if ($label === '') {
continue;
}
$variants = [
strtolower($label),
strtolower(str_replace('-', ' ', $label)),
];
foreach (array_unique($variants) as $key) {
$key = trim(preg_replace('/\s+/', ' ', $key));
if ($key === '') {
continue;
}
$map[$key] = $nhanceRelation;
}
}
}
return $map;
}
/**
* Map Vidal enrollment `relation` text to Nhance `employees.relationship` / `tpa_api_data.relation` style (lowercase).
*/
private function mapVidalRelationshipToNhance(?string $vidalRelationDescription): string
{
$raw = trim((string) $vidalRelationDescription);
if ($raw === '') {
return '';
}
foreach (self::vidalRelationLookupKeyVariants($raw) as $key) {
if (isset($this->vidalRelationshipMap[$key])) {
return $this->vidalRelationshipMap[$key];
}
}
if (strcasecmp($raw, 'Employee') === 0 || strcasecmp($raw, 'Employees') === 0) {
return 'self';
}
return strtolower(str_replace('-', ' ', $raw));
}
/**
* Keys must stay in sync with {@see self::flattenVidalRelationshipGroupedToLookupMap()}.
*
* @return list<string>
*/
private static function vidalRelationLookupKeyVariants(string $raw): array
{
$base = strtolower(trim($raw));
$withHyphensAsSpaces = strtolower(str_replace('-', ' ', $base));
$collapsed = trim(preg_replace('/\s+/', ' ', $withHyphensAsSpaces));
return array_values(array_unique(array_filter([$base, $collapsed])));
}
private function normalizeVidalEnrollmentDateToYmd($value): ?string
{
if ($value === null || $value === '') {
return null;
}
if (is_numeric($value)) {
return null;
}
$s = trim((string) $value);
$ts = strtotime(str_replace('/', '-', $s));
return $ts ? date('Y-m-d', $ts) : null;
}
/**
* Map Enrollment Dump API row (see public/tmp/Enrollment Dump API.docx) to the dependent
* shape used by VidalGetBenefDetailsV2 matching and saveVidalAPIData.
*/
private function normalizeVidalEnrollmentRecordToDependentFormat(array $row): array
{
$rel = trim((string) ($row['relation'] ?? ''));
$relationship = $this->mapVidalRelationshipToNhance($rel);
$si = $row['baseSumInsured'] ?? null;
$si = $si !== null && $si !== '' ? trim((string) $si) : null;
return [
'name' => trim((string) ($row['beneficiaryName'] ?? '')),
'empNo' => trim((string) ($row['employeeNo'] ?? '')),
'relationship' => $relationship,
'vidal_relation_raw' => $rel,
'gender' => $row['gender'] ?? '',
'dob' => $row['dateOfBirth'] ?? null,
'enrollmentId' => trim((string) ($row['membershipNo'] ?? '')),
'policyNumber' => trim((string) ($row['policyNumber'] ?? '')),
'age' => $row['age'] ?? null,
'si' => $si,
'doj' => $this->normalizeVidalEnrollmentDateToYmd($row['dateOfJoining'] ?? null),
'desc' => $this->buildVidalEnrollmentDescForTpaRow($row),
];
}
/**
* Fills tpa_api_data.desc from enrollment fields (product / remarks / insured name).
*/
private function buildVidalEnrollmentDescForTpaRow(array $row): ?string
{
$chunks = array_filter([
trim((string) ($row['productName'] ?? '')),
trim((string) ($row['remarks'] ?? '')),
trim((string) ($row['insuredName'] ?? '')),
], static fn ($v) => $v !== '');
if ($chunks === []) {
return null;
}
return substr(implode(' | ', $chunks), 0, 65000);
}
private function vidalEnrollmentInfoApiUrl(): string
{
$base = rtrim((string) getenv('VIDAL_API_BASE_URL'), '/');
if ($base !== '' && preg_match('#/api$#', $base)) {
return preg_replace('#/api$#', '', $base) . '/enrollment/info';
}
return 'https://devapigw.vidalhealthtpa.com/partner-integration/enrollment/info';
}
public function saveVidalAPIData($array)
{
$file_id = $array['file_id'];
@ -1045,20 +1571,49 @@ class VidalApiController extends BaseController
foreach ($records as $row) {
$rawVidalRel = trim((string) ($row['vidal_relation_raw'] ?? ''));
if ($rawVidalRel !== '') {
$relation = $this->mapVidalRelationshipToNhance($rawVidalRel);
} else {
$relation = trim(strtolower((string) ($row['relationship'] ?? '')));
}
$si = $row['si'] ?? null;
$si = $si !== null && $si !== '' ? trim((string) $si) : null;
$doj = null;
if (!empty($row['doj'])) {
$dojRaw = $row['doj'];
if (is_string($dojRaw) && preg_match('/^\d{4}-\d{2}-\d{2}/', $dojRaw)) {
$doj = substr($dojRaw, 0, 10);
} else {
$doj = $this->normalizeVidalEnrollmentDateToYmd($dojRaw);
}
}
$descPieces = [];
if ($rawVidalRel !== '') {
$descPieces[] = 'Vidal relation: ' . $rawVidalRel;
}
$jsonDesc = trim((string) ($row['desc'] ?? ''));
if ($jsonDesc !== '') {
$descPieces[] = $jsonDesc;
}
$desc = $descPieces !== [] ? substr(implode(' | ', $descPieces), 0, 65000) : null;
$mappedRows[] = [
'file_id' => $file_id, // ← pass from controller
'emp_code' => trim($row['empNo'] ?? ''),
'name' => trim($row['name'] ?? ''),
'dob' => !empty($row['dob'] ?? null) ? date('Y-m-d', strtotime(str_replace('/', '-', $row['dob']))) : null,
'relation' => trim(strtolower($row['relationship'] ?? '')),
'gender' => format_gender_v2($row['gender'] ?? null),
'self' => strtolower($row['relationship'] ?? '') === 'self' ? 1 : 0,
'tpa_id' => trim($row['enrollmentId'] ?? null),
'age' => is_numeric($row['age'] ?? null) ? (int) $row['age'] : null,
'file_id' => $file_id,
'emp_code' => trim($row['empNo'] ?? ''),
'name' => trim($row['name'] ?? ''),
'dob' => !empty($row['dob'] ?? null) ? date('Y-m-d', strtotime(str_replace('/', '-', $row['dob']))) : null,
'relation' => $relation,
'gender' => format_gender_v2($row['gender'] ?? null),
'self' => $relation === 'self' ? 1 : 0,
'tpa_id' => trim($row['enrollmentId'] ?? null),
'age' => is_numeric($row['age'] ?? null) ? (int) $row['age'] : null,
'desc' => $desc,
'si' => $si,
'doj' => $doj,
'is_active' => 1,
'created_by' => $file_info[0]['created_by'] ?? null,
];

View File

@ -176,6 +176,7 @@ var client_id_param = 0;
var client_branch_id_param = 0;
var client_policy_param = 0;
var tpa_api_sevice = 0;
var tpa_push_api_sevice = 0;
$('#file_upload').hide();
@ -1018,11 +1019,18 @@ function checkPolicyTermsAndRackRatesHasDefiend(event)
$('#event_type_data').val(response.insurer_multi_event);
console.log('response.tpa_api_service_status', response.tpa_api_service_status);
console.log('response.tpa_push_api_service_status', response.tpa_push_api_service_status);
console.log('tpa_api_sevice 1', tpa_api_sevice);
if(response.tpa_api_service_status){
tpa_api_sevice = 1;
}else{
tpa_api_sevice = 0;
}
if(response.tpa_push_api_service_status){
tpa_push_api_sevice = 1;
}else{
tpa_push_api_sevice = 0;
}
$('.fetch_tpa').hide();
$('#action_type').val('').change();

View File

@ -503,6 +503,9 @@
<button id="emp_form_submit_button_2" type="submit" class="btn btn-primary waves-effect waves-light justify-content-end">Download</button>
</div>
</div>
<div class="form-group col-md-4 push_tpa" style="margin-top: 18px;">
<a id="fetch_tpa_btn" class="btn btn-primary waves-effect waves-light justify-content-end" onclick="sendDataToTPA(this)">Upload Employees to TPA</a>
</div>
</div>
<div class="form-row" id="onboard_div" style="display:none;">
<a href="#"><span id="on_board_btn_txt" onclick="initiateWellnessOnboard(this)"></span></a>
@ -928,7 +931,7 @@
var insurer_or_tpa = $('#insurer_or_tpa').val()
var action_type = $('#action_type').val()
console.log({tpa_api_sevice, selectedVal, insurer_or_tpa, action_type});
console.log({tpa_api_sevice, selectedVal, insurer_or_tpa, action_type, tpa_push_api_sevice});
if (tpa_api_sevice == 0 || action_type == 'export' || insurer_or_tpa == "insurer" || (selectedVal == 'correction' || selectedVal == 'deletion' || selectedVal == 'si_enhancement')) {
$('.fetch_tpa').hide();
@ -936,6 +939,12 @@
$('.fetch_tpa').show();
}
if (tpa_push_api_sevice == 0 || action_type == 'import' || insurer_or_tpa == "insurer") {
$('.push_tpa').hide();
} else {
$('.push_tpa').show();
}
if (selectedVal === 'correction') {
$('#policy').prop('required', false);
$('#policy_danger').hide();
@ -944,8 +953,6 @@
$('#policy_danger').show();
}
console.log('tpa_api_sevice', tpa_api_sevice);
console.log('tpa_api_sevice type', typeof tpa_api_sevice);
});
$('#action_type').on('change', function() {
@ -974,6 +981,12 @@
} else {
$('.fetch_tpa').show();
}
if (tpa_push_api_sevice == 0 || action_type == 'import' || insurer_or_tpa == "insurer") {
$('.push_tpa').hide();
} else {
$('.push_tpa').show();
}
});
$('#insurer_or_tpa').on('change', function() {
@ -984,7 +997,7 @@
var action_type = $('#action_type').val()
var event_string = $('#event_type').val();
console.log({tpa_api_sevice, insurer_or_tpa, policy_value, event_type_data, action_type, event_string});
console.log({tpa_api_sevice, insurer_or_tpa, policy_value, event_type_data, action_type, event_string, tpa_push_api_sevice});
if (tpa_api_sevice == 0 || action_type == 'export' || insurer_or_tpa == "insurer" || (event_string == 'correction' || event_string == 'deletion' || event_string == 'si_enhancement')) {
$('.fetch_tpa').hide();
@ -992,6 +1005,12 @@
$('.fetch_tpa').show();
}
if (tpa_push_api_sevice == 0 || action_type == 'import' || insurer_or_tpa == "insurer") {
$('.push_tpa').hide();
} else {
$('.push_tpa').show();
}
// if(insurer_or_tpa == 'tpa' || event_type_data == 0){
if(insurer_or_tpa == 'tpa'){
@ -1034,7 +1053,7 @@
var event_string = $('#event_type').val();
var event_type_data = $('#event_type_data').val();
console.log({tpa_api_sevice, action_type, policy_value, insurer_or_tpa, event_string, event_type_data})
console.log({tpa_api_sevice, action_type, policy_value, insurer_or_tpa, event_string, event_type_data, tpa_push_api_sevice})
if (tpa_api_sevice == 0 || action_type == 'export' || insurer_or_tpa == "insurer" || (event_string == 'correction' || event_string == 'deletion' || event_string == 'si_enhancement')) {
$('.fetch_tpa').hide();
@ -1042,6 +1061,12 @@
$('.fetch_tpa').show();
}
if (tpa_push_api_sevice == 0 || action_type == 'import' || insurer_or_tpa == "insurer") {
$('.push_tpa').hide();
} else {
$('.push_tpa').show();
}
if(action_type == 'import'){
$("#event_type").removeAttr("multiple");
@ -1342,6 +1367,69 @@
}
function sendDataToTPA(){
let user_confirm = confirm('Are you sure you want to initiate the TPA Employee Push? This may take a while.');
if(!user_confirm)
{
return false;
}
let event = $('#event_type').val();
let client_id = $('#client').val();
let branch_id = $('#client_branch_id').val();
let policy_id = $('#policy').val();
let tpa_id = $('#policy option:selected').data('tid');
let policy_no = $('#policy option:selected').data('pno');
let checks = [
{val: client_id, msg: 'Please select the client'},
{val: branch_id, msg: 'Please select the client branch'},
{val: policy_id, msg: 'Please select the policy'},
{val: event, msg: 'Please select the event'},
{val: tpa_id, msg: 'TPA id empty'},
{val: policy_no, msg: 'Policy No empty'},
];
for (let c of checks) {
if (!c.val || c.val == 0) {
toastr.warning(c.msg, 'Warning');
return;
}
}
let url = '<?= base_url('sendDataToTPA') ?>';
// Data to send in the AJAX request
let requestData = {
policy_no: policy_no,
tpa_id: tpa_id,
client_id: client_id,
client_branch_id: branch_id,
client_policy_id: policy_id,
event: event,
};
// Send AJAX request
sendAjaxRequestForGlobal(url, 'POST', requestData, function(response) {
console.log('Data fetched successfully:', response);
if (response.status == true) {
toastr.success(response.message || 'Initiating successafully', 'Success');
} else {
toastr.error(response.message || 'Unable to fetch data', 'Error');
}
}, function(xhr, status, error) {
console.error('Error fetching data:', error);
console.error(xhr.responseText);
toastr.error('An error occurred while pushing.', 'Error');
});
}
</script>
<script>