From 4cf9ff02b46e11eb363698c1ebc60349b6e3073e Mon Sep 17 00:00:00 2001 From: "venkatesh.r" Date: Thu, 5 Mar 2026 15:19:11 +0530 Subject: [PATCH] FIX_TPA_RELATED_ISSUE_AND_OTHERS --- app/Config/Routes.php | 10 + app/Controllers/ApiServiceController.php | 29 +++ app/Controllers/FhplApiController.php | 216 +++++++++++++++- app/Controllers/HealthIndiaApiController.php | 230 +++++++++++++++++- app/Controllers/MediAssistApiController.php | 6 +- .../PolicyTransactionController.php | 40 +-- app/Controllers/TicketController.php | 2 + app/Controllers/VidalApiController.php | 11 +- app/Helpers/excel_util_helper.php | 21 ++ app/Models/TicketMasterModel.php | 15 ++ app/Views/ticket_edit_onbording.php | 62 +++++ 11 files changed, 597 insertions(+), 45 deletions(-) diff --git a/app/Config/Routes.php b/app/Config/Routes.php index cf5fe44e..2c4d629c 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -552,9 +552,18 @@ $routes->cli("cli/sendCroneRemainderMail", "DashboardController::sendCroneRemain $routes->cli('cli/update-emp-policy-status', 'ClientController::updateEmpAndPolicyStatus'); $routes->cli('cli/insurerRFQRemainder', 'LeadsController::remainderForQcr'); $routes->cli('cli/sendMailWithAutoQuery','TicketController::sendMailWithAutoQuery'); + +// Claim Status Update every 2 hours $routes->cli('cli/MediAssit-ClaimStatusUpdate','MediAssistApiController::ClaimStatusUpdate'); $routes->cli('cli/Vidal-ClaimStatusUpdate','VidalApiController::ClaimStatusUpdate'); +$routes->cli('cli/Fhpl-ClaimStatusUpdate','FhplApiController::ClaimStatusUpdate'); +$routes->cli('cli/HealthIndia-ClaimStatusUpdate','HealthIndiaApiController::ClaimStatusUpdate'); + +// Sync TPA Claims to Nhance $routes->cli('cli/MediAssit-syncTpaClaimToNhance','MediAssistApiController::syncTpaClaimToNhance'); +$routes->cli('cli/Fhpl-syncTpaClaimToNhance','FhplApiController::syncFhplClaimsToNhance'); +$routes->cli('cli/HealthIndia-syncTpaClaimToNhance','HealthIndiaApiController::syncHealthIndiaClaimsToNhance'); + $routes->cli('cli/thzReminderCrone','ThzController::getOpenTicketsOlderThan24HoursAndAssignNextLevel'); @@ -771,6 +780,7 @@ $routes->group("/ticket", ["filter" => "authMVC"], function ($routes) { $routes->get('fetchVehiclePolicy/(:any)','TicketController::fetchVehiclePolicy/$1'); $routes->post('saveIRDocsJson',"TicketController::saveIRDocsJson"); $routes->get('getTpaClaimStatus',"ApiServiceController::getClaimStatus"); + $routes->post('manualTpaClaimPush',"ApiServiceController::manualTpaClaimPush"); }); $routes->group("/claim_mis", ["filter" => "authMVC"], function ($routes) { diff --git a/app/Controllers/ApiServiceController.php b/app/Controllers/ApiServiceController.php index 28b2aec6..16a650a0 100644 --- a/app/Controllers/ApiServiceController.php +++ b/app/Controllers/ApiServiceController.php @@ -476,6 +476,35 @@ class ApiServiceController extends BaseController } } + /** + * Manual TPA Claim Push - accepts claim_id via POST and delegates to pushClaims(). + * Returns the response from pushClaims() as the API response. + */ + public function manualTpaClaimPush() + { + $claimId = $this->request->getPost('claim_id'); + + if (empty($claimId)) { + return $this->response->setJSON([ + 'status' => false, + 'message' => 'claim_id is required' + ]); + } + + $result = $this->pushClaims($claimId); + + if ($result !== null && is_array($result)) { + return $this->response->setJSON([ + 'status' => $result['status'] ?? false, + 'message' => $result['message'] ?? ($result['status'] ? 'Claim pushed successfully' : 'Claim push failed') + ]); + } + + return $this->response->setJSON([ + 'status' => false, + 'message' => 'Claim push failed or TPA has no API service enabled for this ticket.' + ]); + } // public function getWellnessUrl() diff --git a/app/Controllers/FhplApiController.php b/app/Controllers/FhplApiController.php index 734bb438..8c3e76e1 100644 --- a/app/Controllers/FhplApiController.php +++ b/app/Controllers/FhplApiController.php @@ -99,7 +99,7 @@ class FhplApiController extends BaseController if (count($data) && $data['filePath'] == null) { log_message('error', "FHPL - Claim Push FAILED | claimId: '.$claimId.' - Claim or File Missing"); - return; + return ['status' => false, 'message' => 'Claim Push FAILED | Claim or File Missing']; } // Build absolute file path @@ -108,7 +108,7 @@ class FhplApiController extends BaseController if (!file_exists($pdfPath)) { log_message('error', "FHPL - Claim Push FAILED | claimId: '.$claimId.' - PDF not found on server"); - return; + return ['status' => false, 'message' => 'Claim Push FAILED | PDF not found on server']; } // Convert PDF to Base64 @@ -118,7 +118,7 @@ class FhplApiController extends BaseController $tokenResponse = json_decode($this->generateAuthToken()->getBody(), true); if (empty($tokenResponse['data']['access_token'])) { log_message('error', "FHPL - Claim Push FAILED | claimId: '.$claimId.' - FHPL Token generation failed"); - return; + return ['status' => false, 'message' => 'Claim Push FAILED | FHPL Token generation failed']; } $token = $tokenResponse['data']['access_token']; @@ -163,7 +163,7 @@ class FhplApiController extends BaseController $this->db->table('ticket_master') ->where('id',$claimId) ->update([ 'tpa_push_response' => json_encode($response) ]); - return; + return ['status' => false, 'message' => 'Claim Push FAILED | API call failed']; } @@ -185,14 +185,14 @@ class FhplApiController extends BaseController ]); log_message('error', 'FHPL - Claim Push SUCCESS | claimId: '.$claimId.' | claimNO: '.$fhplClaimNo); - + return ['status' => true, 'message' => 'Claim Push SUCCESS', 'response' => $response]; }else { log_message('error', 'FHPL - Claim Push API SUCCESS BUT claimsInfo EMPTY | response: '.json_encode($response)); - return; + return ['status' => false, 'message' => 'Claim Push API SUCCESS BUT claimsInfo EMPTY']; } } - return; + return ['status' => false, 'message' => 'Claim Push API SUCCESS BUT claimsInfo EMPTY']; // return $this->response->setJSON($response); } @@ -288,7 +288,10 @@ class FhplApiController extends BaseController $tickets = $this->db->table('ticket_master tm') ->select("tm.id,tm.tpa_claim_id,cp.policy_no") ->join('client_policy cp','tm.client_policy_id=cp.id') - ->where('tm.tpa_claim_id IS NOT NULL') + ->where('tm.tpa_claim_push_reference_no IS NOT NULL') + ->whereNotIn('tm.claim_status_id', [8, 11, 12, 13, 66, 22, 24, 47, 49, 32, 34, 53, 55, 42, 44, 58, 60]) + ->where('tm.is_active', 1) + ->where('cp.tpa_id', $this->fhplTpaId) ->get()->getResultArray(); $count=0; @@ -714,7 +717,7 @@ class FhplApiController extends BaseController // ]; // } - public function syncFhplClaimsToNhance() + public function syncFhplClaimsToNhanceOld() { helper('api'); @@ -790,6 +793,201 @@ class FhplApiController extends BaseController return ['status'=>true,'total'=>count($finalResult)]; } + public function syncFhplClaimsToNhance() + { + helper('api'); + + try { + + // Generate FHPL Token + $tokenResponse = json_decode($this->generateAuthToken()->getBody(), true); + + if (empty($tokenResponse['data']['access_token'])) { + return $this->response->setJSON(['status' => false,'message' => 'FHPL Token generation failed']); + } + + $token = $tokenResponse['data']['access_token']; + + $url = getenv('FHPL_BASE_URL')."/api/GetTPA_ClaimsDetails"; + + $headers = [ + "Authorization: Bearer ".$token, + "Content-Type: application/json" + ]; + + $policies = $this->db->table('client_policy') + ->where('tpa_id',$this->fhplTpaId) + ->get()->getResultArray(); + + $finalResult=[]; + foreach($policies as $policy){ + + $body = [ + "UserName" => getenv('FHPL_USER_NAME'), + "Password" => getenv('FHPL_PASSWORD'), + "PolicyNumber" => $policy['policy_no'], + "Fromdate" => $policy['policy_start_date'], + "Todate" => $policy['policy_end_date'] + ]; + + $response = call_third_party_api($url,'POST',$headers,$body); + + if(!empty($response['data'])){ + log_message('error', 'FHPL - Sync TPA Claims | Exception thrown while calling GetTPA_ClaimsDetails API: ' . json_encode($response)); + $finalResult = array_merge($finalResult,$response['data']); + } + } + + $insertedCount = 0; + + // Insert into ticket_master with mandatory columns (reference: MediAssist syncTpaClaimToNhance) + foreach($finalResult as $row){ + + $status = $row['CLAIM_STATUS'] ?? null; + + $map = [ + "Under Process"=>5, + "Paid"=>11, + "Rejected"=>8, + "Approved"=>8 + ]; + + $claimStatus = $map[$status] ?? 61; + + // Derive relationship (default to self) + $relationship = map_relationship(trim($row['RELATION'] ?? 'self')); + + // Fetch client policy details + $clientpolicy = $this->db->table('client_policy cp') + ->select(" + cp.id as client_policy_id, + cp.client_id , + cp.insurer_id , + cp.tpa_id , + client_rm.id as acm_id + ") + ->join('client_rm', 'client_rm.client_id = cp.client_id AND client_rm.level = 3', 'left') + ->where('cp.policy_no', $row['POLICY_NO'] ?? null) + ->orderBy('client_rm.id','DESC') + ->get() + ->getRowArray(); + + if (!$clientpolicy) { + log_message( + 'error', + 'FHPL - Sync TPA Claims | Client policy not found for policy_no: ' . ($row['POLICY_NO'] ?? 'N/A') + ); + continue; + } + + // Fetch employee / insured details + $employee = $this->db->table('employees e') + ->select(" + e.id as emp_id, + e.emp_code , + e.name as emp_name, + e2.id as insured_emp_id, + e2.name as insured_emp_name, + ep.tpa_id as tpa_no + ") + ->join( + 'employees e2', + "e2.emp_code = e.emp_code AND e2.relationship = ".$this->db->escape($relationship), + 'left' + ) + ->join( 'employee_polices ep', "ep.employee_id = e2.id ", 'left' ) + ->where('e.emp_code', $row['EMPLOYEE_NO'] ?? null) + ->where('e.client_id', $clientpolicy['client_id'] ?? null) + ->where('e.relationship', 'self') + ->where('e.is_active', 1) + ->where('e2.is_active', 1) + ->where('ep.is_active', 1) + ->get() + ->getRowArray(); + + if (!$employee) { + log_message( + 'error', + 'FHPL - Sync TPA Claims | Employee data not found for emp_code: ' . ($row['EMPLOYEE_NO'] ?? 'N/A') . + ' | policy_no: ' . ($row['POLICY_NO'] ?? 'N/A') . + ' | relationship: ' . $relationship + ); + continue; + } + + $claimData = [ + // Core + 'ticket_type_id' => 1, + 'claim_status_id' => $claimStatus, + 'policy_no' => $row['POLICY_NO'] ?? null, + 'claim_number' => $row['CLAIM_ID'] ?? null, + 'tpa_claim_id' => $row['CLAIM_ID'] ?? null, + + // local primary ids + 'tpa_id' => $clientpolicy['tpa_id'] ?? $this->fhplTpaId, + 'insurer_id' => $clientpolicy['insurer_id'] ?? null, + 'client_policy_id' => $clientpolicy['client_policy_id'] ?? null, + 'client_id' => $clientpolicy['client_id'] ?? null, + 'acm_id' => $clientpolicy['acm_id'] ?? null, + + // Employee / Insured + 'emp_id' => $employee['emp_id'] ?? null, + 'insured_emp_id' => $employee['insured_emp_id'] ?? null, + 'tpa_no' => $employee['tpa_no'] ?? null, + 'emp_code' => $row['EMPLOYEE_NO'] ?? null, + 'emp_name' => $employee['emp_name'] ?? null, + 'insured_name' => $row['insured_emp_name'] ?? null, + 'relationship' => $relationship, + + // Claim info + 'claim_type' => 1, + 'mode_of_intimation' => 5, + 'claim_amount' => $row['CLAIM_AMOUNT'] ?? null, + + // Dates + 'doa' => change_date_format($row['DATE_OF_ADMISSION'] ?? '', null, 'Y-m-d') ?? null, + 'dod' => change_date_format($row['DATE_OF_DISCHARGE'] ?? '', null, 'Y-m-d') ?? null, + + // Hospital + 'hospital_name' => $row['HOSPITAL_NAME'] ?? null, + 'hospital_state' => $row['HOSPITAL_STATE'] ?? null, + 'hospital_city' => $row['HOSPITAL_CITY'] ?? null, + 'hospital_address' => $row['Hospital Address'] ?? null, + 'hospital_pincode' => $row['Hospital Pincode'] ?? null, + + 'registration_date' => $row['CLAIM_REGISTERED_DATE'] ?? null, + + // Others + 'tpa_claim_type' => $row['CLAIM_TYPE'] ?? null, + 'tpa_ailments' => $row['AILMENT'] ?? null, + + 'created_at' => date('Y-m-d H:i:s'), + ]; + + $this->db->table('ticket_master')->insert($claimData); + + $insertedCount++; + } + + log_message('error', 'FHPL - Sync TPA Claims | Fetched Data | Inserted Data: ' . count($finalResult) . ' | Inserted: ' . $insertedCount); + return ['status'=>true,'total'=>count($finalResult), 'inserted'=>$insertedCount]; + + } catch (\Throwable $th) { + $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', 'FHPL - Sync TPA Claims | Exception thrown: ' . json_encode($errorData)); + return ['status'=>false,'message'=>$th->getMessage()]; + } + } + public function saveFhplAPIData($array) { $file_id = $array['file_id']; diff --git a/app/Controllers/HealthIndiaApiController.php b/app/Controllers/HealthIndiaApiController.php index 13bc10c3..66e6d543 100644 --- a/app/Controllers/HealthIndiaApiController.php +++ b/app/Controllers/HealthIndiaApiController.php @@ -123,12 +123,12 @@ class HealthIndiaApiController extends BaseController if (!$data) { log_message('error', "HEALTH_INDIA - Claim Push FAILED | claimId: {$claimId} - Claim not found"); - return; + return ['status' => false, 'message' => 'Claim Push FAILED | Claim not found']; } if ($data['filePath'] == null) { log_message('error', "HEALTH_INDIA - Claim Push FAILED | claimId: {$claimId} - File Missing"); - return; + return ['status' => false, 'message' => 'Claim Push FAILED | File Missing']; } // Build absolute file path @@ -137,7 +137,7 @@ class HealthIndiaApiController extends BaseController if (!file_exists($pdfPath)) { log_message('error', "HEALTH_INDIA - Claim Push FAILED | claimId: {$claimId} - PDF not found on server at path: {$pdfPath}"); - return; + return ['status' => false, 'message' => 'Claim Push FAILED | PDF not found on server']; } // Convert PDF to Base64 @@ -217,7 +217,7 @@ class HealthIndiaApiController extends BaseController $this->db->table('ticket_master') ->where('id', $claimId) ->update(['tpa_push_response' => json_encode($response)]); - return; + return ['status' => false, 'message' => 'Claim Push FAILED | API call failed']; } if ($response['status'] === true && !empty($response['data']['result'][0]['ccn'])) { @@ -234,12 +234,13 @@ class HealthIndiaApiController extends BaseController ]); log_message('error', 'HEALTH_INDIA - Claim Push SUCCESS | claimId: ' . $claimId . ' | CCN: ' . $ccn . ' | CCN_EXT: ' . $ccnExt); + return ['status' => true, 'message' => 'Claim Push SUCCESS', 'response' => $response]; } else { log_message('error', 'HEALTH_INDIA - Claim Push API SUCCESS BUT CCN EMPTY | claimId: ' . $claimId . ' | response: ' . json_encode($response)); - return; + return ['status' => false, 'message' => 'Claim Push API SUCCESS BUT CCN EMPTY']; } - return; + return ['status' => false, 'message' => 'Claim Push API SUCCESS BUT CCN EMPTY']; } public function ClaimDetail($claimId = null) @@ -355,7 +356,9 @@ class HealthIndiaApiController extends BaseController $tickets = $this->db->table('ticket_master tm') ->select("tm.id, tm.tpa_claim_id, cp.policy_no") ->join('client_policy cp', 'tm.client_policy_id=cp.id') - ->where('tm.tpa_claim_id IS NOT NULL') + ->where('tm.tpa_claim_push_reference_no IS NOT NULL') + ->whereNotIn('tm.claim_status_id', [8, 11, 12, 13, 66, 22, 24, 47, 49, 32, 34, 53, 55, 42, 44, 58, 60]) + ->where('tm.is_active', 1) ->where('cp.tpa_id', $this->healthIndiaTpaId) ->get()->getResultArray(); @@ -722,7 +725,7 @@ class HealthIndiaApiController extends BaseController } } - public function syncHealthIndiaClaimsToNhance() + public function syncHealthIndiaClaimsToNhanceOld() { helper('api'); @@ -820,6 +823,217 @@ class HealthIndiaApiController extends BaseController ]); } + public function syncHealthIndiaClaimsToNhance() + { + helper('api'); + + log_message('error', 'HEALTH_INDIA - Sync TPA Claims | Started'); + + // Generate Health India Token + $tokenResponse = json_decode($this->generateAuthToken()->getBody(), true); + + if (empty($tokenResponse['data']['result'][0]['access_token'])) { + log_message('error', 'HEALTH_INDIA - Sync TPA Claims FAILED | Token generation failed'); + return $this->response->setJSON(['status' => false, 'message' => 'Token generation failed']); + } + + $token = $tokenResponse['data']['result'][0]['access_token']; + + $url = getenv('HEALTH_INDIA_BASE_URL') . "/ClaimsMIS/GetClaimsMIS"; + + $headers = [ + "Authorization: Bearer " . $token, + "Content-Type: application/json" + ]; + + $policies = $this->db->table('client_policy') + ->where('tpa_id', $this->healthIndiaTpaId) + ->get()->getResultArray(); + + $finalResult = []; + + foreach ($policies as $policy) { + $body = [ + "policY_NUMBER" => $policy['policy_no'] + ]; + + log_message('error', 'HEALTH_INDIA - Sync TPA Claims | Fetching for policy: ' . $policy['policy_no']); + + $response = call_third_party_api($url, 'POST', $headers, $body); + + if (!empty($response['data']['result'])) { + $finalResult = array_merge($finalResult, $response['data']['result']); + log_message('error', 'HEALTH_INDIA - Sync TPA Claims | Fetched ' . count($response['data']['result']) . ' claims for policy: ' . $policy['policy_no']); + } + } + + log_message('error', 'HEALTH_INDIA - Sync TPA Claims | Total claims fetched: ' . count($finalResult)); + + $insertedCount = 0; + + foreach ($finalResult as $row) { + $status = $row['Claim_Status'] ?? 'Under Process'; + + $map = [ + "Under Process" => 5, + "Pending for Bill Entry" => 5, + "Paid" => 11, + "Rejected" => 8, + "Approved" => 8, + "Outstanding" => 5, + ]; + + $claimStatus = $map[$status] ?? 1; + + // Check if claim already exists + $existing = $this->db->table('ticket_master') + ->where('tpa_claim_id', $row['CLAIM_NUMBER']) + ->get()->getRowArray(); + + if ($existing) { + log_message('error', 'HEALTH_INDIA - Sync TPA Claims | Skipped existing claim: ' . ($row['CLAIM_NUMBER'] ?? 'N/A')); + continue; + } + + // Derive relationship (default to self) + $relationship = 'self'; + $rawRelation = $row['RELATION_NAME'] ?? null; + if (!empty($rawRelation)) { + if ($rawRelation === 'Employee') { + $relationship = 'self'; + } elseif (strtoupper($rawRelation) === 'WIFE') { + $relationship = 'spouse'; + } else { + $relationship = strtolower($rawRelation); + } + } + + // Fetch client policy details + $clientpolicy = $this->db->table('client_policy cp') + ->select(" + cp.id as client_policy_id, + cp.client_id, + cp.insurer_id, + cp.tpa_id, + client_rm.id as acm_id + ") + ->join('client_rm', 'client_rm.client_id = cp.client_id AND client_rm.level = 3', 'left') + ->where('cp.policy_no', $row['Policy_No'] ?? null) + ->orderBy('client_rm.id', 'DESC') + ->get() + ->getRowArray(); + + if (!$clientpolicy) { + log_message( + 'error', + 'HEALTH_INDIA - Sync TPA Claims | Client policy not found for policy_no: ' . ($row['Policy_No'] ?? 'N/A') + ); + continue; + } + + // Fetch employee / insured details + $employee = $this->db->table('employees e') + ->select(" + e.id as emp_id, + e.emp_code, + e.name as emp_name, + e2.id as insured_emp_id, + e2.name as insured_emp_name, + ep.tpa_id as tpa_no, + e.mobile as emp_mobile, + e.email_corporate as emp_mail + ") + ->join( + 'employees e2', + "e2.emp_code = e.emp_code AND e2.relationship = " . $this->db->escape($relationship), + 'left' + ) + ->join('employee_polices ep', "ep.employee_id = e2.id ", 'left') + ->where('e.emp_code', $row['Employee_Code'] ?? null) + ->where('e.client_id', $clientpolicy['client_id'] ?? null) + ->where('e.relationship', 'self') + ->where('e.is_active', 1) + ->where('e2.is_active', 1) + ->where('ep.is_active', 1) + ->get() + ->getRowArray(); + + if (!$employee) { + log_message( + 'error', + 'HEALTH_INDIA - Sync TPA Claims | Employee data not found for emp_code: ' . ($row['Employee_Code'] ?? 'N/A') . + ' | policy_no: ' . ($row['Policy_No'] ?? 'N/A') . + ' | relationship: ' . $relationship + ); + continue; + } + + $claimData = [ + // Core + 'ticket_type_id' => 1, + 'claim_status_id' => $claimStatus, + 'policy_no' => $row['Policy_No'] ?? null, + 'claim_number' => $row['CLAIM_NUMBER'] ?? null, + 'tpa_claim_id' => $row['CLAIM_NUMBER'] ?? null, + + // Local primary/foreign keys + 'tpa_id' => $clientpolicy['tpa_id'] ?? $this->healthIndiaTpaId, + 'insurer_id' => $clientpolicy['insurer_id'] ?? null, + 'client_policy_id' => $clientpolicy['client_policy_id'] ?? null, + 'client_id' => $clientpolicy['client_id'] ?? null, + 'acm_id' => $clientpolicy['acm_id'] ?? null, + + // Employee / Insured + 'emp_id' => $employee['emp_id'] ?? null, + 'insured_emp_id' => $employee['insured_emp_id'] ?? null, + 'tpa_no' => $employee['tpa_no'] ?? null, + 'emp_code' => $row['Employee_Code'] ?? null, + 'emp_name' => $employee['emp_name'] ?? null, + 'insured_name' => $employee['insured_emp_name'] ?? ($row['PATIENT_NAME'] ?? null), + 'relationship' => $relationship, + 'emp_mobile' => $employee['emp_mobile'] ?? null, + 'emp_mail' => $employee['emp_mail'] ?? null, + + // Claim info + 'claim_type' => 1, + 'mode_of_intimation' => 5, + 'claim_amount' => $row['INTIMATED_AMOUNT'] ?? 0, + + // Dates + 'doa' => !empty($row['DATEOF_ADMISSION']) ? date('Y-m-d', strtotime($row['DATEOF_ADMISSION'])) : null, + 'dod' => !empty($row['DATEOF_DISCHARGE']) ? date('Y-m-d', strtotime($row['DATEOF_DISCHARGE'])) : null, + + // Hospital + 'hospital_name' => $row['HOSPITAL_NAME'] ?? null, + 'hospital_address' => $row['Hospital_address'] ?? null, + 'hospital_pincode' => $row['HOSPITAL_Pincode'] ?? null, + 'hospital_state' => $row['HOSPITAL_STATE'] ?? null, + 'hospital_city' => $row['HOSPITAL_CITY'] ?? null, + + // TPA extras + 'tpa_claim_status' => $status, + + 'created_at' => date('Y-m-d H:i:s'), + ]; + + $this->db->table('ticket_master')->insert($claimData); + $insertedCount++; + + log_message( + 'error', + 'HEALTH_INDIA - Sync TPA Claims | Inserted claim: ' . ($row['CLAIM_NUMBER'] ?? 'N/A') + ); + } + + log_message('error', 'HEALTH_INDIA - Sync TPA Claims | Completed | Total: ' . count($finalResult) . ' | Inserted: ' . $insertedCount); + + return $this->response->setJSON([ + 'status' => true, + 'total' => count($finalResult), + 'inserted' => $insertedCount + ]); + } + public function saveHealthIndiaAPIData($array) { $file_id = $array['file_id']; diff --git a/app/Controllers/MediAssistApiController.php b/app/Controllers/MediAssistApiController.php index a59c2637..05770e6f 100644 --- a/app/Controllers/MediAssistApiController.php +++ b/app/Controllers/MediAssistApiController.php @@ -141,7 +141,7 @@ class MediAssistApiController extends BaseController $this->db->table('ticket_master') ->where('id',$claimId) ->update([ 'tpa_push_response' => json_encode($response) ]); - return; + return ['status' => false, 'message' => 'Claim Push FAILED', 'response' => $response]; } // return $this->response->setJSON($response); @@ -156,11 +156,11 @@ class MediAssistApiController extends BaseController ->where('id',$claimId) ->update([ 'tpa_claim_push_reference_no' => $claimRef ]); - return; + return ['status' => true, 'message' => 'Claim Push SUCCESS', 'response' => $response]; } else { log_message('error','MEDI_ASSIST - Claim Push API Failed | claimReferenceNo EMPTY | claimId: '.$claimId.' | response: '.json_encode($response)); - return; + return ['status' => false, 'message' => 'Claim Push API Failed', 'response' => $response]; } } diff --git a/app/Controllers/PolicyTransactionController.php b/app/Controllers/PolicyTransactionController.php index 44ed315b..c762866e 100644 --- a/app/Controllers/PolicyTransactionController.php +++ b/app/Controllers/PolicyTransactionController.php @@ -317,8 +317,8 @@ class PolicyTransactionController extends BaseController 'col_cell_name' => 'Q', 'col_name' => 'Base Premium', 'is_mandatory' => false, - 'data_type' => '', - 'format' => null, + 'data_type' => 'positive_number', + 'format' => 'positive_number', 'allowed_values' => null, 'custom' => null, 'params' => null @@ -329,8 +329,8 @@ class PolicyTransactionController extends BaseController 'col_cell_name' => 'R', 'col_name' => 'Non commission permium Amount', 'is_mandatory' => false, - 'data_type' => '', - 'format' => null, + 'data_type' => 'positive_number', + 'format' => 'positive_number', 'allowed_values' => null, 'custom' => null, 'params' => null @@ -341,8 +341,8 @@ class PolicyTransactionController extends BaseController 'col_cell_name' => 'S', 'col_name' => 'TP Premium', 'is_mandatory' => false, - 'data_type' => '', - 'format' => null, + 'data_type' => 'positive_number', + 'format' => 'positive_number', 'allowed_values' => null, 'custom' => null, 'params' => null @@ -353,8 +353,8 @@ class PolicyTransactionController extends BaseController 'col_cell_name' => 'T', 'col_name' => 'IGST', 'is_mandatory' => false, - 'data_type' => '', - 'format' => null, + 'data_type' => 'positive_number', + 'format' => 'positive_number', 'allowed_values' => null, 'custom' => 'check_gst_percentage', 'params' => ['row'] @@ -365,8 +365,8 @@ class PolicyTransactionController extends BaseController 'col_cell_name' => 'U', 'col_name' => 'CGST', 'is_mandatory' => false, - 'data_type' => '', - 'format' => null, + 'data_type' => 'positive_number', + 'format' => 'positive_number', 'allowed_values' => null, 'custom' => 'check_gst_percentage', 'params' => ['row'] @@ -377,8 +377,8 @@ class PolicyTransactionController extends BaseController 'col_cell_name' => 'V', 'col_name' => 'SGST', 'is_mandatory' => false, - 'data_type' => '', - 'format' => null, + 'data_type' => 'positive_number', + 'format' => 'positive_number', 'allowed_values' => null, 'custom' => 'check_gst_percentage', 'params' => ['row'] @@ -390,8 +390,8 @@ class PolicyTransactionController extends BaseController 'col_cell_name' => 'W', 'col_name' => 'Stamp Duty', 'is_mandatory' => false, - 'data_type' => '', - 'format' => null, + 'data_type' => 'positive_number', + 'format' => 'positive_number', 'allowed_values' => null, 'custom' => null, 'params' => null @@ -414,8 +414,8 @@ class PolicyTransactionController extends BaseController 'col_cell_name' => 'X', 'col_name' => 'Agreed Amount', 'is_mandatory' => false, - 'data_type' => '', - 'format' => null, + 'data_type' => 'positive_number', + 'format' => 'positive_number', 'allowed_values' => null, 'custom' => null, 'params' => null @@ -426,8 +426,8 @@ class PolicyTransactionController extends BaseController 'col_cell_name' => 'Y', 'col_name' => 'Agreed BP Percentage', 'is_mandatory' => false, - 'data_type' => '', - 'format' => null, + 'data_type' => 'positive_number', + 'format' => 'positive_number', 'allowed_values' => null, 'custom' => null, 'params' => null @@ -438,8 +438,8 @@ class PolicyTransactionController extends BaseController 'col_cell_name' => 'Z', 'col_name' => 'Agreed TP Percentage', 'is_mandatory' => false, - 'data_type' => '', - 'format' => null, + 'data_type' => 'positive_number', + 'format' => 'positive_number', 'allowed_values' => null, 'custom' => null, 'params' => null diff --git a/app/Controllers/TicketController.php b/app/Controllers/TicketController.php index 7c70ec06..c3d5e86e 100644 --- a/app/Controllers/TicketController.php +++ b/app/Controllers/TicketController.php @@ -959,6 +959,8 @@ class TicketController extends BaseController // Redirect or show a 404 to prevent "Undefined array key" errors return redirect()->to(base_url('ticket/list'))->with('error', 'Ticket not found'); } + + $ticket_data['is_tpa_api_service_enabled'] = $this->ticketMasterModel->isTpaApiServiceEnabled($ticket_id); $ticket_data = $this->formatDateForClaim($ticket_data, 'd/m/Y'); diff --git a/app/Controllers/VidalApiController.php b/app/Controllers/VidalApiController.php index 3836cb4b..d4674302 100644 --- a/app/Controllers/VidalApiController.php +++ b/app/Controllers/VidalApiController.php @@ -164,7 +164,7 @@ class VidalApiController extends BaseController if (count($data) && $data['filePath'] == null) { log_message('error', "VIDAL - Claim Push | Submit claim failed - Claim or File Missing"); - return $this->response->setJSON(['status' => false,'message' => 'Claim or File Missing', ]); + return ['status' => false, 'message' => 'Claim Push FAILED | Claim or File Missing']; } $filePath = $data['filePath'] ?? ''; @@ -271,7 +271,7 @@ class VidalApiController extends BaseController $this->db->table('ticket_master') ->where('id',$claimId) ->update([ 'tpa_push_response' => json_encode($response) ]); - return; + return ['status' => false, 'message' => 'Claim Push FAILED | API call failed']; } // return $this->response->setJSON($response); @@ -289,16 +289,17 @@ class VidalApiController extends BaseController ->where('id',$claimId) ->update([ 'tpa_claim_push_reference_no' => $claimInwardNO , 'tpa_claim_id' => $claimNO , 'claim_number' => $claimNO ]); - return; + return ['status' => true, 'message' => 'Claim Push SUCCESS']; } else { log_message('error', 'VIDAL - Claim Push API SUCCESS BUT claimNO,claimInwardNO EMPTY | claimId: '.$claimId.' | response: '.json_encode($response)); - return; + return ['status' => false, 'message' => 'Claim Push API SUCCESS BUT claimNO,claimInwardNO EMPTY']; } }else{ log_message('error', 'VIDAL - Claim Push API FAILED | claimId: '.$claimId.' | response: '.json_encode($response)); - return; + return ['status' => false, 'message' => 'Claim Push API FAILED']; } + } function getWellnessSSORedirectUrl($email = 'test@getvisitapp.com') diff --git a/app/Helpers/excel_util_helper.php b/app/Helpers/excel_util_helper.php index 5b5d6b7b..9419d6e1 100755 --- a/app/Helpers/excel_util_helper.php +++ b/app/Helpers/excel_util_helper.php @@ -3023,6 +3023,9 @@ if (!function_exists('validate_excel_value')) { case 'vehicle': return validate_indian_vehicle_number($value); + case 'positive_number': + return validate_positive_number_value($value); + default: return [ 'status' => true, @@ -3066,6 +3069,24 @@ if (!function_exists('validate_mobile_value')) { } } +if (!function_exists('validate_positive_number_value')) { + function validate_positive_number_value($value) + { + if ($value === "" || $value === null) { + return ['status' => true, 'error' => null]; + } + + if (is_numeric($value) && $value >= 0) { + return ['status' => true, 'error' => null]; + } + + return [ + 'status' => false, + 'error' => "Value must be a positive number" + ]; + } +} + if (!function_exists('validate_email_value')) { function validate_email_value($value) { diff --git a/app/Models/TicketMasterModel.php b/app/Models/TicketMasterModel.php index 14101188..13682edb 100644 --- a/app/Models/TicketMasterModel.php +++ b/app/Models/TicketMasterModel.php @@ -1218,6 +1218,21 @@ class TicketMasterModel extends Model } + public function isTpaApiServiceEnabled($ticket_id) + { + $result = $this->db->table('ticket_master tm') + ->select('tas.*') + ->join('client_policy cp', 'tm.client_policy_id = cp.id') + ->join('tpa_api_services tas', 'cp.tpa_id = tas.tpa_id') + ->where('tm.id', $ticket_id) + ->where('tm.is_active', 1) + ->where('cp.is_active', 1) + ->where('tas.is_active', 1) + ->get()->getRowArray(); + + return count($result ?? []) > 0 ? true : false; // true if any API service is enabled, false if no API service is enabled + } + // ----------------------------------------------------------------------------------------------------- } diff --git a/app/Views/ticket_edit_onbording.php b/app/Views/ticket_edit_onbording.php index 45eabbc3..a84dcf12 100644 --- a/app/Views/ticket_edit_onbording.php +++ b/app/Views/ticket_edit_onbording.php @@ -46,6 +46,17 @@
+ + + + Manual TPA Claim Push + + + Fetch Claim Status @@ -385,6 +396,57 @@ }); } + function manualTpaClaimPush() { + let ticket_master_id = $('#ticket_master_id').val(); + if (!ticket_master_id) { + toastr.warning('Claim ID not found. Please ensure the form is loaded.', 'Warning'); + return; + } + + Swal.fire({ + title: 'Manual TPA Claim Push', + text: 'Do you want to push this claim to the TPA now?', + icon: 'question', + showCancelButton: true, + confirmButtonColor: '#00999E', + cancelButtonColor: '#6c757d', + confirmButtonText: 'Yes, push claim', + cancelButtonText: 'Cancel' + }).then((result) => { + if (result.isConfirmed) { + $('.loader').fadeIn(); + $('.loader-mask').fadeIn(); + + let requestData = { claim_id: ticket_master_id }; + let url = ''; + + sendAjaxRequestForGlobal(url, 'POST', requestData, function(response) { + $('.loader').fadeOut(); + $('.loader-mask').delay(350).fadeOut('slow'); + console.log('Manual TPA claim push response:', response); + if (response.status) { + toastr.success(response.message || 'Claim pushed to TPA successfully', 'Success'); + window.location.reload(true); + } else { + toastr.warning(response.message || 'Claim push failed', 'Warning'); + } + }, function(xhr, status, error) { + $('.loader').fadeOut(); + $('.loader-mask').delay(350).fadeOut('slow'); + console.error('Error pushing claim:', error); + console.error(xhr.responseText); + let msg = 'An error occurred while pushing the claim to TPA.'; + if (xhr.responseJSON && xhr.responseJSON.message) { + msg = xhr.responseJSON.message; + } else if (xhr.status === 404) { + msg = 'Manual TPA Claim Push endpoint is not configured. Please contact support.'; + } + toastr.error(msg, 'Error'); + }); + } + }); + } + function fetchTpaClaimStatus(){ let ticket_master_id = $('#ticket_master_id').val();