From a00bec8130185bd79b71f9e3e9dcea8a980ad4bc Mon Sep 17 00:00:00 2001 From: Gowtham M Date: Fri, 2 Jan 2026 13:06:25 +0530 Subject: [PATCH] TPA : ecard , claim status , tpa pull --- app/Config/Routes.php | 27 +- app/Controllers/ApiServiceController.php | 26 + app/Controllers/MediAssistApiController.php | 1 + app/Controllers/VidalApiController.php | 698 ++++++++++++++------ 4 files changed, 537 insertions(+), 215 deletions(-) diff --git a/app/Config/Routes.php b/app/Config/Routes.php index c091eaf1..5658762b 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -527,8 +527,10 @@ $routes->cli('cli/update-emp-policy-status', 'ClientController::updateEmpAndPoli $routes->cli('cli/update-emp-policy-status', 'ClientController::updateEmpAndPolicyStatus'); $routes->cli('cli/insurerRFQRemainder', 'LeadsController::remainderForQcr'); $routes->cli('cli/sendMailWithAutoQuery','TicketController::sendMailWithAutoQuery'); -$routes->cli('cli/ClaimStatusUpdate','MediAssistApiController::ClaimStatusUpdate'); -$routes->cli('cli/syncTpaClaimToNhance','MediAssistApiController::syncTpaClaimToNhance'); +$routes->cli('cli/MediAssit-ClaimStatusUpdate','MediAssistApiController::ClaimStatusUpdate'); +$routes->cli('cli/Vidal-ClaimStatusUpdate','VidalApiController::ClaimStatusUpdate'); +$routes->cli('cli/MediAssit-syncTpaClaimToNhance','MediAssistApiController::syncTpaClaimToNhance'); + @@ -756,22 +758,14 @@ $routes->get('createEnrollmentBatch','ICICILombardController::createEnrollmentBa $routes->get('getEnrollmentBatchStatus','ICICILombardController::getEnrollmentBatchStatus'); $routes->get('fetchUHIDDetails','ICICILombardController::fetchUHIDDetails'); -//Third party Vidal Api Call -$routes->get('fileUpload','VidalApiController::fileUpload'); -$routes->post('hospitalNetwork','VidalApiController::hospitalNetwork'); -$routes->post('eCardService','VidalApiController::eCardService'); -$routes->post('claimStatusCheck','VidalApiController::claimStatusCheck'); -$routes->get('newClaim','VidalApiController::SubmitClaim'); -$routes->post('enrollment','VidalApiController::enrollment'); -$routes->get('fileUploadToVidal','VidalApiController::fileUploadToVidal'); -$routes->get('claimStatus','VidalApiController::claimStatus'); -//Third party MediAssist Api Call -$routes->get('EcardRequest','MediAssistApiController::EcardRequest'); +//Third party - testing route + +$routes->get('EcardRequest','VidalApiController::EcardRequest'); $routes->get('HospitalNetwork','MediAssistApiController::HospitalNetwork'); -$routes->get('GetBenefDetails','MediAssistApiController::GetBenefDetails'); -$routes->get('ClaimDetail','MediAssistApiController::ClaimDetail'); +$routes->get('GetBenefDetails','VidalApiController::GetBenefDetails'); +$routes->get('ClaimDetail','VidalApiController::ClaimDetail'); $routes->get('SubmitClaim','MediAssistApiController::SubmitClaim'); $routes->get('IntimateClaim','MediAssistApiController::IntimateClaim'); $routes->get('IRSubmission','MediAssistApiController::IRSubmission'); @@ -779,10 +773,9 @@ $routes->get('ClaimStatusUpdate','MediAssistApiController::ClaimStatusUpdate'); $routes->get('syncTpaClaimToNhance','MediAssistApiController::syncTpaClaimToNhance'); -// API service +// API service (Don't delete) $routes->post("ecardRequest", "ApiServiceController::ecardRequest"); $routes->post("getTPAID", "ApiServiceController::getTPAID"); -// $routes->get("getTPAID", "ApiServiceController::getTPAID"); $routes->get('fileDownload','MediAssistApiController::fileDownload'); diff --git a/app/Controllers/ApiServiceController.php b/app/Controllers/ApiServiceController.php index e1858c95..8b2fa691 100644 --- a/app/Controllers/ApiServiceController.php +++ b/app/Controllers/ApiServiceController.php @@ -119,8 +119,16 @@ class ApiServiceController extends BaseController { if($employee_policy[0]['tpa_primary_id'] == $this->medi_assist_primary_key)//Medi assist { + $mediAssistController = new MediAssistApiController(); $data['eCardDownload'] = $mediAssistController->EcardRequest( $emp_code, $policy_no ); + + }else if($employee_policy[0]['tpa_primary_id'] == $this->vidal_primary_key)// Vidal + { + + $vidalApiController = new VidalApiController; + $data['eCardDownload'] = $vidalApiController->EcardRequest( $emp_code, $policy_no , $employee_policy[0]['tpa_id'] ); + }else{ if($type == "download"){ @@ -246,6 +254,17 @@ class ApiServiceController extends BaseController return $this->respond(['status' => true, 'code' => 200, 'message' => 'Action Triggered','data' => [] ]); + }else if ($tpa_id == $this->vidal_primary_key) // Vidal + { + $file_id = $fileModel->insert($data); + log_message('error', "Files table inserted successfully, File id : {$file_id}"); + // $vidalApiController = new VidalApiController; + // $vidalApiController->GetBenefDetails( [ 'polict_no' => $policy_no, 'file_id' =>$file_id ] ); + $r = Jobs::addJob(['job_name' => 'GetBenefDetails', 'payload' => ['policy_no' => $policy_no, 'file_id' => $file_id, 'client_policy_id' => $policy_id, 'return_type' => 'job']]); + log_message('error', "GetBenefDetails 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' => [] ]); } @@ -265,8 +284,15 @@ class ApiServiceController extends BaseController $tpaID = $data['tpa_id']; if ($tpaID == $this->medi_assist_primary_key) { // MediAssist + $mediAssistController = new MediAssistApiController(); return $mediAssistController->ClaimDetail($claimId); + + }else if ($tpaID == $this->vidal_primary_key) { // vidal + + $vidalApiController = new VidalApiController; + return $vidalApiController->ClaimDetail($claimId); + }else{ log_message('error', "This ticket id ( {$claimId} ) TPA has no API service enabled. TPA ID : {$tpaID}"); $message = "This TPA has no API service enabled"; diff --git a/app/Controllers/MediAssistApiController.php b/app/Controllers/MediAssistApiController.php index df595bb5..d4be65c0 100644 --- a/app/Controllers/MediAssistApiController.php +++ b/app/Controllers/MediAssistApiController.php @@ -1139,6 +1139,7 @@ class MediAssistApiController extends BaseController "Payment - Refunded to Insurer" => 14, "Processed - Processing Payment" => 10, "Processed - Physical Documents Awaited" => 9, + "Pre-Auth Processed" => 8, // Extra Mappings (based on your DB list) "NON ID" => 1, diff --git a/app/Controllers/VidalApiController.php b/app/Controllers/VidalApiController.php index 3fb32afe..68992611 100644 --- a/app/Controllers/VidalApiController.php +++ b/app/Controllers/VidalApiController.php @@ -2,16 +2,24 @@ namespace App\Controllers; +use App\Models\BatchFileModel; +use App\Models\EmployeePolicyModel; +use App\Models\TpaApiDataModel; + use App\Controllers\BaseController; use CodeIgniter\HTTP\ResponseInterface; +use CodeIgniter\API\ResponseTrait; class VidalApiController extends BaseController { + use ResponseTrait; protected $db; + protected $vidal_primary_key; public function __construct() { $this->db = \Config\Database::connect(); + $this->vidal_primary_key = getenv('VIDAL_PRIMARY_KEY_CONSTANT'); } @@ -400,7 +408,7 @@ class VidalApiController extends BaseController return ['status' => 'success','data' => $decryptedData["redirectUrl"]]; } - public function ClaimDetail($claimId = null) + public function ClaimDetail($claimId = null) //234 { helper('api'); @@ -418,6 +426,7 @@ class VidalApiController extends BaseController tm.id, tm.tpa_no as memberId, tm.tpa_claim_push_reference_no as claimRefNo, + tm.tpa_claim_id as claimID, cp.policy_no as policyNo, cp.policy_start_date as startDate, cp.policy_end_date as endDate, @@ -429,230 +438,523 @@ class VidalApiController extends BaseController ->get() ->getRowArray(); - $body = [ + if (!$ticket) { + return $this->response->setJSON(['status' => false,'message' => 'Invalid Claim ID' ]); + } + + $body = []; + + // REQUEST BODY + if($ticket['claimID'] != null) + { + $body = [ + 'empNO' => "", + 'tpaCardID' => "", + 'claimID' => $ticket['claimID'], + 'emailID' => "", + 'mobileNO' => "", + ]; + + } + + $response = call_third_party_api($url, $method, $headers, $body); + + // dd($response); + + if ($response['status'] != true || empty($response['data']['data']['claims'][0])) { + log_message('error', 'CLAIM STATUS FAILED | for ticket ID: ' . $claimId.' | response: '.json_encode($response)); + + return $this->response->setJSON([ + 'status' => false, + 'message' => 'API call failed.', + 'data' => $response + ]); + } + + // Extract claim status + $claimData = $response['data']['data']['claims'][0]; + $currentStatus = $claimData['status'] ?? ''; + + + // VALID STATUS LIST + $validStatuses = [ + + "In-Progress" => 5, + "Required Information" => 4, + "Paid" => 11, + "Rejected" => 8, + "Approved" => 8, + ]; + + + // Maping tpa claim status with local claim Status + if (isset($validStatuses[$currentStatus])) + { + $updateArray = ['claim_status_id' => $validStatuses[$currentStatus] , 'tpa_claim_status' => $currentStatus , 'updated_at' => date('Y-m-d H:i:s')]; + }else{ + $updateArray = ['tpa_claim_status' => $currentStatus , 'updated_at' => date('Y-m-d H:i:s')]; + } + + // UPDATE ticket_master + $this->db->table('ticket_master')->where('id', $claimId)->update($updateArray); + + // LOG UPDATE + log_message('error', "CLAIM STATUS SUCCESS | Updated ticket ID $claimId with claim status: $currentStatus"); + + return $this->response->setJSON([ + 'status' => true, + 'message' => 'Claim status updated.', + 'updated_status' => $currentStatus, + 'api_response' => $response + ]); + } + + public function ClaimStatusUpdate() + { + helper('api'); + + $url = getenv('VIDAL_API_BASE_URL').'/claims/claim-dependent-info'; + $method = 'POST'; + + $headers = [ + 'Content-Type: application/json', + 'Ocp-Apim-Subscription-Key:' .getenv('VIDAL_API_SUBSCRIPTION_KEY').'', + ]; + + // Fetch ticket master details + $TicketData = $this->db->table('ticket_master tm') + ->select(" + tm.id, + tm.tpa_no as memberId, + tm.tpa_claim_push_reference_no as claimRefNo, + tm.tpa_claim_id as claimNo, + cp.policy_no as policyNo, + cp.policy_start_date as startDate, + cp.policy_end_date as endDate, + e.emp_code as employeeCode + ") + ->join('employees e', 'e.id = tm.emp_id', 'left') + ->join('client_policy cp', 'tm.client_policy_id = cp.id', 'left') + ->where('tm.tpa_claim_push_reference_no IS NOT NULL') + ->where('tm.is_active', 1) + ->whereNotIn('tm.claim_status_id', [8, 11, 12, 13, 66, 22, 24, 47, 49, 32, 34, 53, 55, 42, 44, 58, 60]) + ->where('tm.tpa_id', $this->vidal_primary_key) + ->get() + ->getResultArray(); + + // dd($TicketData); + + if (!$TicketData) { + log_message('error', "Claims not found to update status"); + return $this->response->setJSON(['status' => false,'message' => 'Claims not found' ]); + } + + $error_data = []; + $status_updated_count = 0; + + foreach ($TicketData as $key => $ticket) + { + $claimId = $ticket['id']; + + $body = []; + + // REQUEST BODY + if($ticket['claimNo'] != null) + { + $body = [ + 'empNO' => "", + 'tpaCardID' => "", + 'claimID' => $ticket['claimNo'], + 'emailID' => "", + 'mobileNO' => "", + ]; + + } + + // CALL API + $response = call_third_party_api($url, $method, $headers, $body); + + if ($response['status'] != true || empty($response['data']['data']['claims'][0])) { + log_message('error', 'CLAIM STATUS FAILED | for ticket ID: ' . $claimId.' | response: '.json_encode($response)); + $error_data[$claimId][['status' => false,'message' => 'API call failed.','data' => $response]]; + } + + // Extract claim status + $claimData = $response['data']['data']['claims'][0]; + $currentStatus = $claimData['status'] ?? ''; + + + // VALID STATUS LIST + $validStatuses = [ + + "In-Progress" => 5, + "Required Information" => 4, + "Paid" => 11, + "Rejected" => 8, + "Approved" => 8, + ]; + + + // Maping tpa claim status with local claim Status + if (isset($validStatuses[$currentStatus])) + { + $updateArray = ['claim_status_id' => $validStatuses[$currentStatus] , 'tpa_claim_status' => $currentStatus , 'updated_at' => date('Y-m-d H:i:s')]; + }else{ + $updateArray = ['tpa_claim_status' => $currentStatus , 'updated_at' => date('Y-m-d H:i:s')]; + } + + // UPDATE ticket_master + $this->db->table('ticket_master')->where('id', $claimId)->update($updateArray); + + // LOG UPDATE + log_message('error', "CLAIM STATUS SUCCESS | Updated ticket ID $claimId with claim status: $currentStatus"); + + $status_updated_count ++; + + } + + return $this->response->setJSON([ + 'status' => true, + 'message' => 'Claim status updated.', + 'updated_status' => $currentStatus, + 'api_response' => $response, + 'count' => $status_updated_count, + 'error_data' => $error_data, + ]); + } + + public function EcardRequest($employeeId = null, $policyNo = null , $tpaNo = null) + { + + helper('api'); + + $url = getenv('VIDAL_API_BASE_URL').'/claims/claim-dependent-info'; + $method = 'POST'; + + $headers = [ + 'Content-Type: application/json', + 'Ocp-Apim-Subscription-Key:' .getenv('VIDAL_API_SUBSCRIPTION_KEY').'', + ]; + + $body = [ 'empNO' => "", - 'tpaCardID' => "", - 'claimID' => "BLR-0284-CL-9349459", + 'tpaCardID' => $tpaNo, + 'claimID' => "", 'emailID' => "", 'mobileNO' => "", ]; + // $body = [ + // 'empNO' => "", + // 'tpaCardID' => "BLR-NI-H0351-03925-0030320-A", + // 'claimID' => "", + // 'emailID' => "", + // 'mobileNO' => "", + // ]; + $response = call_third_party_api($url, $method, $headers, $body); + // dd($response); + if($response['status'] != true){ - return $this->response->setJSON([ - 'status' => false, - 'message' => 'failed.', - 'data' => $response - ]); + log_message('error', 'Ecard Request FAILED | employeeId: '.$employeeId.' | policyNo: '.$policyNo.' | response: '.json_encode($response)); + return null; + } + + $ecardUrl = $response['data']['data']['dependents'][0]['ecardLink'] ?? null; + + if(!empty($ecardUrl)){ + log_message('error', 'Ecard Request PUSH SUCCESS | employeeId: '.$employeeId.' | policyNo: '.$policyNo.' | ecardUrl: '.$ecardUrl); + return $ecardUrl; + } else { + log_message('error', 'Ecard Request SUCCESS BUT ecardUrl EMPTY | employeeId: '.$employeeId.' | policyNo: '.$policyNo.' | response: '.json_encode($response)); + return null; } - return $this->response->setJSON($response); } - - - //----------yet to start only submit claim given - - public function fileUpload() + public function GetBenefDetails($requestData) { - helper('api'); - $url = getenv('VIDAL_API_BASE_URL') . '/files/upload-url'; - $method = 'POST'; + $function_calling_type = $requestData['return_type'] ?? 'job'; - $headers = [ - 'Content-Type: application/json', - 'x-ms-blob-type: BlockBlob', - 'Ocp-Apim-Subscription-Key:' .getenv('VIDAL_API_SUBSCRIPTION_KEY').'', - ]; + try { - $body = [ - 'scope' => 'application/pdf', - 'fileName' => '1760013019_73d94af7b96ddc2e3d51.png', - 'file' => '/opt/lampp/htdocs/nhance/writable/uploads/claim_files/1760013019_73d94af7b96ddc2e3d51.png', - ]; + helper('api'); - $response = call_third_party_api($url, $method, $headers, $body); + $url = getenv('VIDAL_API_BASE_URL').'/claims/claim-dependent-info'; + $method = 'POST'; - if($response['status'] != true){ - return $this->response->setJSON([ - 'status' => false, - 'message' => 'failed.', - 'data' => $response - ]); + $headers = [ + 'Content-Type: application/json', + 'Ocp-Apim-Subscription-Key:' .getenv('VIDAL_API_SUBSCRIPTION_KEY').'', + ]; + + + $policyNo = $requestData['policy_no'] ?? null; + $client_policy_id = $requestData['client_policy_id'] ?? null; + + if (empty($policyNo)) { + log_message('error', 'TPA ID PULL | policy_no missing in request'); + if($function_calling_type == "job"){ + return ['status' => false, 'message' => 'policy_no required']; + }else{ + return $this->respond(['status' => false, 'message' => 'policy_no required']); + } + } + + if (empty($client_policy_id)) { + log_message('error', 'TPA ID PULL | client_policy_id missing in request'); + if($function_calling_type == "job"){ + return ['status' => false, 'message' => 'client_policy_id required']; + }else{ + return $this->respond(['status' => false, 'message' => 'client_policy_id required']); + } + } + + log_message('error', "TPA ID PULL | called for policy_no: {$policyNo} , client_policy_id: {$client_policy_id}"); + + // Fetch file download dates + $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(); + + // dd($batchFiles); + + if (empty($batchFiles)) { + log_message('error', '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']; + }else{ + return $this->respond(['status' => false, 'message' => 'batchFiles not found']); + } + } + + + $allBenef = []; + foreach ($batchFiles as $key => $value) + { + + $createdAt = new \DateTime($value['created_at']); + $startDate = $createdAt->format('d/m/Y'); + $endDateObj = clone $createdAt; + $endDateObj->modify('+2 days'); + $endDate = $endDateObj->format('d/m/Y'); + $body = [ + 'policyNO' => $policyNo, + 'startDate' => $startDate, + 'endDate' => $endDate + ]; + + // $body = [ 'empNO' => "Mem 1" ]; + + log_message('error', "TPA ID PULL | API parems " . json_encode([$url, $method, $headers, $body])); + + $response = call_third_party_api($url, $method, $headers, $body); + + if ($response['status'] != true) { + + // update file table status after the tpa id failed to update + 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', "Files table status updated for the file id : {$requestData['file_id']}"); + } else { + log_message('error', "Failed to update file table status."); + } + + log_message('error', 'TPA ID PULL API FAILED | API failed: ' . json_encode($response)); + + if($function_calling_type == "job"){ + return ['status' => false, 'message' => 'API call failed', 'data' => $response]; + }else{ + return $this->respond(['status' => false, 'message' => 'API call failed', 'data' => $response]); + } + } + + $data = $response['data']['data'] ?? []; + + if (!isset($data['dependents'])) { + log_message('error', "TPA ID PULL FAILED |: 'benefDetails' missing in API response: " . json_encode($data)); + break; + } + + $fetchedCount = count($data['dependents']); + log_message('error', "Fetched {$fetchedCount} records "); + $allBenef = array_merge($allBenef, $data['dependents']); + + } + + // dd($allBenef ); + + //save API data as JSON for analysis + $json = json_encode($allBenef, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); + // $filename = time() . '.json'; + $filePath = WRITEPATH . 'tmp/'.time().'_'.$requestData['file_id'].'.json'; + file_put_contents($filePath, $json); + + //call a job for dump JSON data to DB + $job_details = new Jobs(); + $r = Jobs::addJob(['job_name' => 'saveMediAssitAPIData', 'payload' => [ 'file_id' => $requestData['file_id'],'json_file_path' => $filePath ]]); + + + // now update DB + $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; + + // log_message('error', "✅ Match found: emp_code={$row['empNo']} policy={$row['policyNumber']}"); + + $sql = "UPDATE employee_polices + SET tpa_id = ? + WHERE id = ?"; + $this->db->query($sql, [$row['enrollmentId'], $policy_data['emp_policy_id']]); + + // for e-card send + if(strtolower(trim($policy_data['relationship'])) == 'self'){ + $employee_policy_ids[] = $policy_data['emp_policy_id']; + } + + if ($this->db->affectedRows() > 0) { + $updated++; + log_message('error', "✅ Updated tpa_id={$row['enrollmentId']} for emp_code={$row['empNo']} policy={$row['policyNumber']}"); + } else { + log_message('error', "⚠️ No update (already set or not matched) for emp_code={$row['empNo']} policy={$row['policyNumber']}"); + } + + } + + } + + // Handle NO MATCH for this policy + 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', + "❌ No match for Nhance = " . json_encode($nhanceSideData) + ); + } + + } + + + + // send e-card + if(!empty($employee_policy_ids)){ + log_message('error', "sendMailForDownloadingECard JOB PUSHED."); + Jobs::addJob(['job_name' => 'sendMailForDownloadingECard', 'payload' => ['ids' => $employee_policy_ids, 'client_policy_id' => $client_policy_id]]); + } + + // update file table status after the tpa id successfully updated + 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', "Files table status updated for the file id : {$requestData['file_id']}"); + } else { + log_message('error', "Failed to update file table status."); + } + + + log_message('error', "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 + ]; + }else{ + return $this->respond([ + 'status' => true, + 'message' => 'Updated successfully', + 'total_fetched' => $totalCount, + 'total_updated' => $updated + ]); + } + + } catch (\Throwable $th) { + + // update file table status after the tpa id failed to update + 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', "Files table status updated for the file id : {$requestData['file_id']}"); + } else { + log_message('error', "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(), // full array version (optional) + 'function' => $th->getTrace()[0]['function'] ?? null, + 'class' => $th->getTrace()[0]['class'] ?? null, + ]; + + log_message('error', 'Exception thrown while calling GetBenefDetails API: ' . json_encode($errorData)); + if($function_calling_type == "job"){ + return ['status' => false, 'message' => 'API call failed', 'data' => $errorData]; + }else{ + return $this->respond(['status' => false, 'message' => 'API call failed', 'data' => $errorData]); + } } - - return $this->response->setJSON($response); - - // { - // "status": true, - // "data": { - // "status": "SUCCESS", - // "data": { - // "signedUrl": "https://devapigw.vidalhealthtpa.com/doc-storage/api/deeplink/6912d37a9f09fc3f6be4cd9c/56fb8e76-39a4-4e4b-99f2-4748e224e4a7?se=2025-11-18T06:11:06.304Z", - // "expiresAt": "2025-11-18T06:11:06.304Z", - // "fileId": "https://devapigw.vidalhealthtpa.com/doc-storage/api/private/6912d37a9f09fc3f6be4cd9c" - // }, - // "trace": "T_ID_a09327df-ea34-4874-9e3f-05ac5c0a2c68", - // "successful": true - // }, - // "code": 200 - // } - } - public function hospitalNetwork(){ - - $postData = $this->request->getJSON(true); - helper('api'); - - $url = ''. getenv('VIDAL_API_BASE_URL').'/hospitalnetwork'; - $method = 'POST'; - - $headers = [ - 'Content-Type: application/json', - 'Authorization:'. getenv('VIDAL_API_KEY').'', - 'username:'. getenv('VIDAL_API_USERNAME').'', - 'password:'. getenv('VIDAL_API_PASSWORD').'', - 'policynumber:'. $postData['policyNo'] ?? '', - ]; - - - - $body = []; - - $response = call_third_party_api($url, $method, $headers, $body); - - - if($response['status'] != true){ - return $this->response->setJSON([ - 'status' => false, - 'message' => 'Token generation failed.', - 'data' => $response - ]); - } - - return $this->response->setJSON($response); - - } - - public function eCardService(){ - - $postData = $this->request->getJSON(true); - - helper('api'); - - $url = ''. getenv('VIDAL_API_BASE_URL').'/ecardservice'; - $method = 'POST'; - - - $headers = [ - 'Content-Type: application/json', - 'Authorization:'.getenv('VIDAL_API_KEY').'', - 'username:' .getenv('VIDAL_API_USERNAME').'', - 'password:' .getenv('VIDAL_API_PASSWORD').'', - 'PolicyNo:' .$postData['PolicyNo'] ?? '', - 'enrollmentNo:' .$postData['enrollmentNo'] ?? '', - ]; - - $body = [ - ]; - - $response = call_third_party_api($url, $method, $headers, $body); - - if($response['status'] != true){ - return $this->response->setJSON([ - 'status' => false, - 'message' => 'Token generation failed.', - 'data' => $response - ]); - } - - return $this->response->setJSON($response); - - } - - public function claimStatusCheck(){ - - $postData = $this->request->getJSON(true); - - helper('api'); - - $url = ''. getenv('VIDAL_API_BASE_URL').'/claimpreauthservice'; - $method = 'POST'; - - $headers = [ - 'Content-Type: application/json', - 'Authorization:' .getenv('VIDAL_API_KEY').'', - 'username:' .getenv('VIDAL_API_USERNAME').'', - 'password:' .getenv('VIDAL_API_PASSWORD').'', - 'PolicyNo:' .$postData['policyNo'] ?? '', - 'enrollmentNo:' .$postData['enrollmentNo'] ?? '', - 'empNo:' .$postData['empNo'] ?? '', - 'startdate:' .$postData['startdate'] ?? '', - 'enddate:' .$postData['enddate'] ?? '', - 'tpaclaimNo:' .$postData['tpaclaimNo'] ?? '' - ]; - - $body = []; - - $response = call_third_party_api($url, $method, $headers, $body); - - if($response['status'] != true){ - return $this->response->setJSON([ - 'status' => false, - 'message' => 'Token generation failed.', - 'data' => $response - ]); - } - - return $this->response->setJSON($response); - - } - - public function enrollment() - { - - $postData = $this->request->getJSON(true); - - helper('api'); - - $url = getenv('VIDAL_API_BASE_URL').'/enrollmendataservice'; - $method = 'POST'; - - $headers = [ - 'Content-Type: application/json', - 'Authorization:'. getenv('VIDAL_API_KEY').'', - 'username:' . getenv('VIDAL_API_USERNAME').'', - 'password:' . getenv('VIDAL_API_PASSWORD').'', - 'policyNo:' .$postData['policyNo'] ?? '', - 'startindex:' .$postData['startindex'] ?? '', - 'endindex:' .$postData['endindex'] ?? '' - ]; - - $body = [ - ]; - - $response = call_third_party_api($url, $method, $headers, $body); - - - if($response['status'] != true){ - return $this->response->setJSON([ - 'status' => false, - 'message' => 'Token generation failed.', - 'data' => $response - ]); - } - - return $this->response->setJSON($response); - } + }