From 17b8d2702b33d28ae5e625db1af47f56659699a6 Mon Sep 17 00:00:00 2001 From: Venkatesh Date: Thu, 30 Apr 2026 11:15:23 +0530 Subject: [PATCH 1/5] FIX_LIVE_ISSUES_STATEMENT_UPLOAD_AND_VIDAL_DOA --- app/Controllers/PolicyTransactionController.php | 6 +++--- app/Controllers/VidalApiController.php | 3 +++ app/Models/PTCOShareDetailsModel.php | 11 ++++++++--- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/app/Controllers/PolicyTransactionController.php b/app/Controllers/PolicyTransactionController.php index a2ff2325..1c4c347b 100644 --- a/app/Controllers/PolicyTransactionController.php +++ b/app/Controllers/PolicyTransactionController.php @@ -4168,7 +4168,7 @@ class PolicyTransactionController extends BaseController //get no of line items and update in DB $line_items = 0; // get uploaded month transactions data - $source_data = $this->PTCOShareDetailsModel->getNonReconcileredPolicyTransactions(insurer_id: $file['insurer_id'], insurer_branch_id: $file['branch_id']); + $source_data = $this->PTCOShareDetailsModel->getNonReconcileredPolicyTransactions(insurer_id: $file['insurer_id'], insurer_branch_id: $file['branch_id'], month: $file['month']); // var_dump($source_data);die(); // Kint::dump($source_data);die(); @@ -4291,7 +4291,7 @@ class PolicyTransactionController extends BaseController $line_items = 0; // get uploaded month transactions data - $source_data = $this->PTCOShareDetailsModel->getNonReconcileredPolicyTransactions(insurer_id: $file['insurer_id'], insurer_branch_id: $file['branch_id']); + $source_data = $this->PTCOShareDetailsModel->getNonReconcileredPolicyTransactions(insurer_id: $file['insurer_id'], insurer_branch_id: $file['branch_id'], month: $file['month']); // dd($source_data); // check policy no,insurer and etc in DB for this month @@ -4439,7 +4439,7 @@ class PolicyTransactionController extends BaseController //get no of line items and update in DB $line_items = count($excel_data); // get uploaded month transactions data - $source_data = $this->PTCOShareDetailsModel->getNonReconcileredPolicyTransactions(insurer_id: $file['insurer_id'], insurer_branch_id: $file['branch_id']); + $source_data = $this->PTCOShareDetailsModel->getNonReconcileredPolicyTransactions(insurer_id: $file['insurer_id'], insurer_branch_id: $file['branch_id'], month: $file['month']); // Kint::dump($source_data);//die; // Kint::dump($excel_data); // die; diff --git a/app/Controllers/VidalApiController.php b/app/Controllers/VidalApiController.php index e09fc9fb..2e6fa28f 100644 --- a/app/Controllers/VidalApiController.php +++ b/app/Controllers/VidalApiController.php @@ -476,6 +476,7 @@ class VidalApiController extends BaseController $ticket = $this->db->table('ticket_master tm') ->select(" tm.id, + tm.doa, tm.tpa_no as memberId, tm.tpa_claim_push_reference_no as claimRefNo, tm.tpa_claim_id as claimID, @@ -592,6 +593,7 @@ class VidalApiController extends BaseController $TicketData = $this->db->table('ticket_master tm') ->select(" tm.id, + tm.doa, tm.tpa_no as memberId, tm.tpa_claim_push_reference_no as claimRefNo, tm.tpa_claim_id as claimNo, @@ -1650,6 +1652,7 @@ class VidalApiController extends BaseController $ticket = $this->db->table('ticket_master tm') ->select(" tm.id, + tm.doa, tm.tpa_no as memberId, tm.tpa_claim_push_reference_no as claimInwardNO, tm.tpa_claim_id as claimNO, diff --git a/app/Models/PTCOShareDetailsModel.php b/app/Models/PTCOShareDetailsModel.php index dc4e9953..59d53c9c 100644 --- a/app/Models/PTCOShareDetailsModel.php +++ b/app/Models/PTCOShareDetailsModel.php @@ -72,11 +72,14 @@ class PTCOShareDetailsModel extends Model 'file_id', ]; - public function getNonReconcileredPolicyTransactions(string $insurer_id,string $insurer_branch_id) + public function getNonReconcileredPolicyTransactions(string $insurer_id,string $insurer_branch_id, string $month) { $currentDate = date('Y-m-d'); $sixMonthsAgo = date('Y-m-01', strtotime('-6 months')); + $startDate = $month; + $endDate = date('Y-m-t', strtotime($startDate)); + return $this->db->table('pt_co_share_details pt_co') ->select(' pt_co.id, @@ -109,8 +112,10 @@ class PTCOShareDetailsModel extends Model ->where('pt_co.insurer_branch_id', $insurer_branch_id) // ->where('pt_co.statement_id is null') ->where('pt.status','completed') - ->where('DATE(pt.created_at) >=', $sixMonthsAgo) - ->where('DATE(pt.created_at) <=', $currentDate) + // ->where('DATE(pt.created_at) >=', $sixMonthsAgo) + // ->where('DATE(pt.created_at) <=', $currentDate) + ->where('pt_co.pt_policy_issue_date >=', $startDate) + ->where('pt_co.pt_policy_issue_date <=', $endDate) // ->where('pt_co.exp_amt', 0.00) // ->orWhere('pt_co.exp_amt is null') ->get() From 3853bc0b27de8a6422a4e850d97aa06e50955b59 Mon Sep 17 00:00:00 2001 From: Venkatesh Date: Thu, 30 Apr 2026 12:45:40 +0530 Subject: [PATCH 2/5] CHANGE_MOBILE_NUMBER_VALIDATION --- app/Controllers/EmployeeServiceController.php | 31 +++++++++++++------ app/Helpers/excel_util_helper.php | 5 ++- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/app/Controllers/EmployeeServiceController.php b/app/Controllers/EmployeeServiceController.php index d49e6609..b5d73432 100755 --- a/app/Controllers/EmployeeServiceController.php +++ b/app/Controllers/EmployeeServiceController.php @@ -226,8 +226,8 @@ class EmployeeServiceController extends AdminController 'col_cell_name' => 'M', 'col_name' => 'Phone', 'is_mandatory' => false, - 'data_type' => 'str', - 'format' => null, + 'data_type' => 'mobile', + 'format' => 'mobile', 'allowed_values' => null, 'custom' => 'check_dup_mobileno', 'params' => ['row', 'existing_mobilenos'] @@ -940,6 +940,7 @@ class EmployeeServiceController extends AdminController { $is_mandatory = $columns_to_check[$keys[$col_key]]['is_mandatory']; $format = $columns_to_check[$keys[$col_key]]['format']; + $data_type = $columns_to_check[$keys[$col_key]]['data_type']; $allowed_values = $columns_to_check[$keys[$col_key]]['allowed_values']; $custom_function = isset($columns_to_check[$keys[$col_key]]['custom']) ? $columns_to_check[$keys[$col_key]]['custom'] : null; $binding_params = isset($columns_to_check[$keys[$col_key]]['params']) ? $columns_to_check[$keys[$col_key]]['params'] : null; @@ -986,15 +987,25 @@ class EmployeeServiceController extends AdminController //format check if(isset($format)) - { - $format_error = check_excel_date_format($col,$format); - if(!$format_error['status']) - { - array_push($result['error_summary'],2); - $result['error_data'][$row_key][$keys[$col_key]]['col_name'] = $column_dispaly_name; //push column name - $result['error_data'][$row_key][$keys[$col_key]]['col_idx'] = $column_index; //push column index - $result['error_data'][$row_key][$keys[$col_key]]['error'][] = $format_error['error']; + { + + $validation = validate_excel_value($col, $data_type, $format, $allowed_values); + if (!$validation['status']) { + array_push($result['error_summary'], 2); + + $result['error_data'][$row_key][$keys[$col_key]]['col_name'] = $column_dispaly_name; + $result['error_data'][$row_key][$keys[$col_key]]['col_idx'] = $column_index; + $result['error_data'][$row_key][$keys[$col_key]]['error'][] = $validation['error']; } + + // $format_error = check_excel_date_format($col,$format); + // if(!$format_error['status']) + // { + // array_push($result['error_summary'],2); + // $result['error_data'][$row_key][$keys[$col_key]]['col_name'] = $column_dispaly_name; //push column name + // $result['error_data'][$row_key][$keys[$col_key]]['col_idx'] = $column_index; //push column index + // $result['error_data'][$row_key][$keys[$col_key]]['error'][] = $format_error['error']; + // } } // Kint::dump($is_mandatory); //allowed values check diff --git a/app/Helpers/excel_util_helper.php b/app/Helpers/excel_util_helper.php index f4540849..788ddc20 100755 --- a/app/Helpers/excel_util_helper.php +++ b/app/Helpers/excel_util_helper.php @@ -3014,6 +3014,9 @@ if (!function_exists('validate_excel_value')) { case 'date': return validate_date_value($value, $format); + case 'str': + return check_excel_date_format($value, $format); + case 'mobile': return validate_mobile_value($value); @@ -3064,7 +3067,7 @@ if (!function_exists('validate_mobile_value')) { return [ 'status' => false, - 'error' => "Invalid mobile number. Expected 10 digits." + 'error' => "Invalid mobile number. It must be exactly 10 digits, with no spaces and no +91 prefix." ]; } } From 9912aa747f3c4dec2de1e3a9e072926c283eb43b Mon Sep 17 00:00:00 2001 From: velz Date: Thu, 30 Apr 2026 15:29:46 +0530 Subject: [PATCH 3/5] FIX_MEDIASSIT_TPA_API --- app/Controllers/FhplApiController.php | 1 + app/Controllers/HealthIndiaApiController.php | 1 + app/Controllers/MediAssistApiController.php | 439 ++++++++++++++++++- 3 files changed, 435 insertions(+), 6 deletions(-) diff --git a/app/Controllers/FhplApiController.php b/app/Controllers/FhplApiController.php index 1d280ea5..9d8851c5 100644 --- a/app/Controllers/FhplApiController.php +++ b/app/Controllers/FhplApiController.php @@ -992,6 +992,7 @@ class FhplApiController extends BaseController 'claim_created_by' => 'TPA', 'created_at' => date('Y-m-d H:i:s'), + 'tpa_claim_push_reference_no' => $row['ClaimID'] ?? null, ]; $this->db->table('ticket_master')->insert($claimData); diff --git a/app/Controllers/HealthIndiaApiController.php b/app/Controllers/HealthIndiaApiController.php index f498f039..3e19caf4 100644 --- a/app/Controllers/HealthIndiaApiController.php +++ b/app/Controllers/HealthIndiaApiController.php @@ -1028,6 +1028,7 @@ class HealthIndiaApiController extends BaseController 'claim_created_by' => 'TPA', 'created_at' => date('Y-m-d H:i:s'), + 'tpa_claim_push_reference_no' => $row['ccn'].'-'.$row['ccN_EXT'] ?? null, ]; $this->db->table('ticket_master')->insert($claimData); diff --git a/app/Controllers/MediAssistApiController.php b/app/Controllers/MediAssistApiController.php index 65a8992a..536015d0 100644 --- a/app/Controllers/MediAssistApiController.php +++ b/app/Controllers/MediAssistApiController.php @@ -503,7 +503,7 @@ class MediAssistApiController extends BaseController } } - public function ClaimDetail($claimId = null) // 585 this id for test + public function ClaimDetailOLD($claimId = null) // 585 this id for test { helper('api'); @@ -523,7 +523,7 @@ class MediAssistApiController extends BaseController tm.tpa_no as memberId, tm.tpa_claim_push_reference_no as claimRefNo, tm.tpa_claim_id,tm.doa, - tm.claim_number, + tm.claim_number,tm.claim_amount, cp.policy_no as policyNo, cp.policy_start_date as startDate, cp.policy_end_date as endDate, @@ -661,7 +661,8 @@ class MediAssistApiController extends BaseController } - if($ticket['doa'] == $this->mediDate($claimData['datE_OF_ADMISSION'] ?? null) || $ticket['claim_number'] == $tpa_claim_no){ + if((isset($ticket['claim_number']) && $ticket['claim_number'] == $tpa_claim_no) || ($ticket['doa'] == $this->mediDate($claimData['datE_OF_ADMISSION'] ?? null) && $ticket['claimRefNo'] == $claimData['clM_COMP_REFNO'])) + { // UPDATE ticket_master $this->db->table('ticket_master')->where('id', $claimId)->update($updateArray); @@ -674,6 +675,210 @@ class MediAssistApiController extends BaseController } return ['status' => true,'message' => 'Claim Status updated.','updated_status' => $currentStatus,'api_response' => $response]; + } + + public function ClaimDetail($claimId = null) // 585 this id for test + { + helper('api'); + + $url = getenv('MEDI_ASSIST_API_BASE_URL_CLAIMSTATUS'); + $method = 'POST'; + + $headers = [ + 'Content-Type: application/json', + 'Username:' . getenv('MEDI_ASSIST_API_USERNAME'), + 'Password:' . getenv('MEDI_ASSIST_API_PASSWORD'), + ]; + + // Fetch ticket master details + $ticket = $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,tm.doa, + tm.claim_number,tm.claim_amount, + 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.id', $claimId) + ->get() + ->getRowArray(); + + // print_rr($ticket);die; + if (!$ticket) { + return ['status' => false,'message' => 'Invalid Claim ID' ]; + } + + + // REQUEST BODY + if($ticket['claimRefNo'] != null) + { + $body = [ + "policyNo" => $ticket['policyNo'] ?? "", + "startDate" => "", + "endDate" => "", + "employeeCode" => $ticket['employeeCode'] ?? "", + "memberID" => "", + "claimNo" => "", + "claimRefNo" => $ticket['claimRefNo'] ?? "", + ]; + + }else{ + + $body = [ + "policyNo" => $ticket['policyNo'] ?? "", + "startDate" => "", + "endDate" => "", + "employeeCode" => $ticket['employeeCode'] ?? "", + "memberID" => "", + "claimNo" => "", + "claimRefNo" => "", + ]; + + } + + // $body = [ + // "policyNo" => "97000063250400000031", + // "startDate" => "01/11/2025", + // "endDate" => "05/11/2025", + // "employeeCode" => "", + // "memberID" => "", + // "claimNo" => "", + // "claimRefNo" => "" + // ]; + + // CALL API + $response = call_third_party_api($url, $method, $headers, $body); + + + + if ($response['status'] != true || empty($response['data']['claimsData'][0])) { + log_message('error','MEDI_ASSIST - Claim Status FAILED | for ticket ID: ' . $claimId.' | response: '.json_encode($response)); + + return ['status' => false,'message' => 'API call failed.','data' => $response ]; + } + + // Extract Claim Status + $allClaimData = $response['data']['claimsData']; + + $matched = false; // 🔥 Track if anything matched + + foreach ($allClaimData as $claimData) { + + $currentStatus = $claimData['claim_Current_Status'] ?? ''; + $tpa_claim_no = $claimData['tpA_CLAIM_NO'] ?? ''; + $tpa_claim_type = $claimData['typE_OF_CLAIM'] ?? ''; + $tpa_ailments = ($claimData['ailment'] ?? '') . ' - ' . ($claimData['ailmenT_DESC'] ?? ''); + + $claimRefNo = $claimData['clM_COMP_REFNO'] ?? ''; + $doa = $this->mediDate($claimData['datE_OF_ADMISSION'] ?? null); + + $isMatch = false; + + // ------------------------------- + // ✅ Matching Logic + // ------------------------------- + + // Case 1: Claim number exists → match by claim number + if (!empty($ticket['claim_number'])) { + if ($ticket['claim_number'] == $tpa_claim_no) { + $isMatch = true; + } + } + // Case 2: No claim number → match by DOA + claimRefNo + else { + if ( + $ticket['claimRefNo'] == $claimRefNo && + $ticket['doa'] == $doa + ) { + $isMatch = true; + } + } + + if (!$isMatch) { + continue; + } + + // ✅ Mark matched + $matched = true; + + // ------------------------------- + // ✅ Prepare update + // ------------------------------- + $updateArray = [ + 'tpa_claim_status' => $currentStatus, + 'updated_at' => date('Y-m-d H:i:s'), + 'last_updated_by' => 'API', + ]; + + if (isset($validStatuses[$currentStatus])) { + $updateArray['claim_status_id'] = $validStatuses[$currentStatus]; + } + + // Set claim number when first received + if (empty($ticket['claim_number']) && !empty($tpa_claim_no)) { + $updateArray['claim_number'] = $tpa_claim_no; + $updateArray['tpa_claim_id'] = $tpa_claim_no; + } + + if (!empty($tpa_claim_type)) { + $updateArray['tpa_claim_type'] = $tpa_claim_type; + } + + if (!empty($tpa_ailments)) { + $updateArray['tpa_ailments'] = $tpa_ailments; + } + + // ------------------------------- + // ✅ Update DB + // ------------------------------- + $this->db->table('ticket_master') + ->where('id', $claimId) + ->update($updateArray); + + log_message( + 'error', + "MEDI_ASSIST Claim Status SUCCESS | Updated ticket ID ={$claimId} | Status={$currentStatus} | ClaimNo={$tpa_claim_no} | RefNo={$claimRefNo}" + ); + + // Stop after first valid match + break; + } + + if ($matched) { + return [ + 'status' => true, + 'message' => 'Claim Status updated.', + 'updated_status' => $currentStatus, + 'api_response' => $response + ]; + } + + // ----------------------------------- + // ❌ If nothing matched → log failure + // ----------------------------------- + if (!$matched) { + + log_message( + 'error', + "MEDI_ASSIST | Fetch Claim Status | Claim Status NOT UPDATED | | TicketID={$claimId} | TicketDOA={$ticket['doa']} | ClaimDOA={$claimData['datE_OF_ADMISSION']} | Status={$currentStatus}" + ); + + return [ + 'status' => true, + 'message' => 'No matching claim found.', + 'updated_status' => null, + 'api_response' => $response + ]; + } + + + } public function IRSubmission($claimId = null) // 585 this id for test @@ -860,7 +1065,7 @@ class MediAssistApiController extends BaseController // unlink($file_array['json_file_path']); // delete temp json file } - public function ClaimStatusUpdate() + public function ClaimStatusUpdateOLD() { helper('api'); @@ -879,7 +1084,7 @@ class MediAssistApiController extends BaseController tm.id, tm.tpa_no as memberId, tm.tpa_claim_push_reference_no as claimRefNo, - tm.doa,tm.claim_no, + tm.doa,tm.claim_number, cp.policy_no as policyNo, cp.policy_start_date as startDate, cp.policy_end_date as endDate, @@ -1026,7 +1231,8 @@ class MediAssistApiController extends BaseController $updateArray['tpa_ailments'] = $tpa_ailments; } - if($ticket['doa'] == $this->mediDate($claimData['datE_OF_ADMISSION'] ?? null) || $ticket['claim_number'] == $tpa_claim_no){ + if((isset($ticket['claim_number']) && $ticket['claim_number'] == $tpa_claim_no) || ($ticket['doa'] == $this->mediDate($claimData['datE_OF_ADMISSION'] ?? null) && $ticket['claimRefNo'] == $claimData['clM_COMP_REFNO'])) + { // UPDATE ticket_master $this->db->table('ticket_master')->where('id', $claimId)->update($updateArray); $status_updated_count ++; @@ -1051,6 +1257,227 @@ class MediAssistApiController extends BaseController ]); } + public function ClaimStatusUpdate() + { + helper('api'); + + $url = getenv('MEDI_ASSIST_API_BASE_URL_CLAIMSTATUS'); + $method = 'POST'; + + $headers = [ + 'Content-Type: application/json', + 'Username:' . getenv('MEDI_ASSIST_API_USERNAME'), + 'Password:' . getenv('MEDI_ASSIST_API_PASSWORD'), + ]; + + $TicketData = $this->db->table('ticket_master tm') + ->select(" + tm.id, + tm.tpa_no as memberId, + tm.tpa_claim_push_reference_no as claimRefNo, + tm.doa, + tm.claim_number, + tm.tpa_claim_id, + 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->mediAssistTpaId) + ->get() + ->getResultArray(); + + log_message('error','MEDI_ASSIST - Claim Status started | for ticket count: ' . count($TicketData)); + + if (!$TicketData) { + log_message('error',"MEDI_ASSIST - Claims not found to update Claim Status"); + return $this->response->setJSON([ + 'status' => false, + 'message' => 'Claims not found' + ]); + } + + $error_data = []; + $status_updated_count = 0; + + // ✅ Move outside loop (performance) + $validStatuses = [ + "Claim Received" => 1, + "In Progress" => 5, + "Processed" => 11, + "Claim Paid" => 11, + "Denied" => 13, + "Cancelled" => 13, + "Information Awaited" => 4, + "Confirmation Awaited" => 4, + "Information Awaited Reminder" => 4, + "Information Awaited Final Reminder" => 4, + "Insurer Concurrence Awaited" => 7, + "Closed" => 12, + "Physical Documents Awaited" => 9, + "Processed - Payment Initiated" => 10, + "Processed - Transaction Failed" => 10, + "Processed - Account Details Updated" => 10, + "Processed - Debit Note Raised With Insurer for Payment" => 10, + "Processed - Payment Initiated by Insurer" => 10, + "Payment - Refunded to Insurer" => 14, + "Processed - Processing Payment" => 10, + "Processed - Physical Documents Awaited" => 9, + "NON ID" => 1, + "ID NOT GENERATED" => 2, + "CDA" => 3, + "REJECTED" => 8, + "APPROVED" => 9, + "PAYMENT INITIATED" => 10, + "SETTLED" => 11, + "RETURNED" => 14, + "UNDER PROCESS - TPA" => 61, + "DENIAL REVIEW AWAITED" => 66, + ]; + + foreach ($TicketData as $ticket) { + + $claimId = $ticket['id']; + $matched = false; + + $body = [ + "policyNo" => $ticket['policyNo'] ?? "", + "startDate" => "", + "endDate" => "", + "employeeCode" => $ticket['employeeCode'] ?? "", + "memberID" => "", + "claimNo" => "", + "claimRefNo" => $ticket['claimRefNo'] ?? "", + ]; + + $response = call_third_party_api($url, $method, $headers, $body); + + log_message('error','MEDI_ASSIST - 2 hours Claim Status API Response: ' . json_encode($response)); + + if ($response['status'] != true || empty($response['data']['claimsData'])) { + log_message('error','MEDI_ASSIST - Claim Status FAILED | for ticket ID: ' . $claimId.' | response: '.json_encode($response)); + $error_data[$claimId] = [ + 'response' => $response, + 'body' => $body + ]; + continue; + } + + $allClaimData = $response['data']['claimsData']; + + foreach ($allClaimData as $claimData) { + + $currentStatus = $claimData['claim_Current_Status'] ?? ''; + $tpa_claim_no = $claimData['tpA_CLAIM_NO'] ?? ''; + $tpa_claim_type = $claimData['typE_OF_CLAIM'] ?? ''; + $tpa_ailments = ($claimData['ailment'] ?? '') . ' - ' . ($claimData['ailmenT_DESC'] ?? ''); + $claimRefNo = $claimData['clM_COMP_REFNO'] ?? ''; + + // ✅ Normalize dates (critical fix) + $claimDOA = !empty($claimData['datE_OF_ADMISSION']) + ? date('Y-m-d', strtotime($claimData['datE_OF_ADMISSION'])) + : null; + + $ticketDOA = !empty($ticket['doa']) + ? date('Y-m-d', strtotime($ticket['doa'])) + : null; + + $isMatch = false; + + // ================================ + // ✅ STRICT MATCHING (NO LOOPHOLE) + // ================================ + + // Case 1: claim number exists → ONLY match by claim number + if (!empty($ticket['claim_number'])) { + + if ($ticket['claim_number'] == $tpa_claim_no) { + $isMatch = true; + } + + } + // Case 2: claim number empty → match by DOA + claimRefNo ONLY + else { + + if ( + !empty($ticket['claimRefNo']) && + $ticket['claimRefNo'] == $claimRefNo && + $ticketDOA == $claimDOA + ) { + $isMatch = true; + } + } + + // ❌ No fallback allowed + + if (!$isMatch) { + continue; + } + + // ================================ + // ✅ MATCH FOUND + // ================================ + $matched = true; + + $updateArray = [ + 'tpa_claim_status' => $currentStatus, + 'updated_at' => date('Y-m-d H:i:s'), + 'last_updated_by' => 'API', + ]; + + if (isset($validStatuses[$currentStatus])) { + $updateArray['claim_status_id'] = $validStatuses[$currentStatus]; + } + + // Set claim number only if empty + if (empty($ticket['claim_number']) && !empty($tpa_claim_no)) { + $updateArray['claim_number'] = $tpa_claim_no; + $updateArray['tpa_claim_id'] = $tpa_claim_no; + } + + if (!empty($tpa_claim_type)) { + $updateArray['tpa_claim_type'] = $tpa_claim_type; + } + + if (!empty($tpa_ailments)) { + $updateArray['tpa_ailments'] = $tpa_ailments; + } + + // UPDATE DB + $this->db->table('ticket_master') + ->where('id', $claimId) + ->update($updateArray); + + $status_updated_count++; + + log_message('error',"MEDI_ASSIST - Claim Status SUCCESS | Updated ticket ID $claimId with Claim Status: $currentStatus"); + + break; // ✅ only inner loop + } + + // ================================ + // ❌ UNMATCHED LOG (once per ticket) + // ================================ + if (!$matched) { + log_message('error', "MEDI_ASSIST | 2 hours | Claim Status NOT UPDATED | TicketID={$claimId} | TicketDOA={$ticket['doa']} | ClaimRefNo={$ticket['claimRefNo']}"); + } + } + + log_message('error',"MEDI_ASSIST - Claim Status ENDED | 2 hours | Total Tickets={".count($TicketData)."} | Status Updated={$status_updated_count} | Errors={".count($error_data)."}"); + + return $this->response->setJSON([ + 'status' => true, + 'message' => 'Claim Status updated.', + 'count' => $status_updated_count, + 'error_data' => $error_data, + ]); + } + public function syncTpaClaimToNhance() { helper(['api', 'date']); From 6d4e8ff72abfacbd5a78180e8376795024fcc08a Mon Sep 17 00:00:00 2001 From: Venkatesh Date: Sat, 2 May 2026 09:18:56 +0530 Subject: [PATCH 4/5] FIX_FHPL_KEY_MISSMATCH_ISSUE_AND_SHOW_THE ERROR_MSG --- app/Controllers/FhplApiController.php | 12 ++++++++++-- app/Controllers/HealthIndiaApiController.php | 8 ++++++++ app/Controllers/VidalApiController.php | 16 ++++++++++++++++ app/Views/batch_list.php | 2 +- 4 files changed, 35 insertions(+), 3 deletions(-) diff --git a/app/Controllers/FhplApiController.php b/app/Controllers/FhplApiController.php index 1d280ea5..b2ec8b1c 100644 --- a/app/Controllers/FhplApiController.php +++ b/app/Controllers/FhplApiController.php @@ -418,6 +418,14 @@ class FhplApiController extends BaseController if (empty($batchFiles)) { log_message('error', 'FHPL - TPA ID Pull FAILED | batchFiles is empty for this tpa id pull request'); + + $file_model = new BatchFileModel(); + $bfData = [ + 'error_data' => json_encode(['error_data' => 'No trace found for TPA member download (export).']), + 'status' => 'failed-7', + ]; + $file_model->where('id', $requestData['file_id'])->set($bfData)->update(); + if($function_calling_type == "job"){ return ['status' => false, 'message' => 'batchFiles not found']; }else{ @@ -543,7 +551,7 @@ class FhplApiController extends BaseController $sql = "UPDATE employee_polices SET tpa_id = ? WHERE id = ?"; - $this->db->query($sql, [$m['TPA_TPADETAIL_ID'], $policy['emp_policy_id']]); + $this->db->query($sql, [$m['TPA_TPADetailID'], $policy['emp_policy_id']]); // for e-card send if(strtolower(trim($policy['relationship'])) == 'self'){ @@ -552,7 +560,7 @@ class FhplApiController extends BaseController if ($this->db->affectedRows() > 0) { $updated++; - log_message('error', "FHPL - TPA ID Pull Updated tpa_id={$m['TPA_TPADETAIL_ID']} for emp_policy_id={$policy['emp_policy_id']} policy={$policyNo}"); + log_message('error', "FHPL - TPA ID Pull Updated tpa_id={$m['TPA_TPADetailID']} for emp_policy_id={$policy['emp_policy_id']} policy={$policyNo}"); } else { log_message('error', "FHPL - TPA ID Pull No update (already set or not matched) for emp_policy_id={$policy['emp_policy_id']} policy={$policyNo}"); } diff --git a/app/Controllers/HealthIndiaApiController.php b/app/Controllers/HealthIndiaApiController.php index f498f039..49a573bd 100644 --- a/app/Controllers/HealthIndiaApiController.php +++ b/app/Controllers/HealthIndiaApiController.php @@ -490,6 +490,14 @@ class HealthIndiaApiController extends BaseController if (empty($batchFiles)) { log_message('error', 'HEALTH_INDIA - TPA ID Pull FAILED | batchFiles is empty for this tpa id pull request'); + + $file_model = new BatchFileModel(); + $bfData = [ + 'error_data' => json_encode(['error_data' => 'No trace found for TPA member download (export).']), + 'status' => 'failed-7', + ]; + $file_model->where('id', $requestData['file_id'])->set($bfData)->update(); + if ($function_calling_type == "job") { return ['status' => false, 'message' => 'batchFiles not found']; } else { diff --git a/app/Controllers/VidalApiController.php b/app/Controllers/VidalApiController.php index 2e6fa28f..d1fd6b40 100644 --- a/app/Controllers/VidalApiController.php +++ b/app/Controllers/VidalApiController.php @@ -828,6 +828,14 @@ class VidalApiController extends BaseController if (empty($batchFiles)) { log_message('error', 'VIDAL - TPA ID Pull FAILED | batchFiles is empty for this tpa id pull request'); + + $file_model = new BatchFileModel(); + $bfData = [ + 'error_data' => json_encode(['error_data' => 'No trace found for TPA member download (export).']), + 'status' => 'failed-7', + ]; + $file_model->where('id', $requestData['file_id'])->set($bfData)->update(); + if($function_calling_type == "job"){ return ['status' => false, 'message' => 'batchFiles not found']; }else{ @@ -1109,6 +1117,14 @@ class VidalApiController extends BaseController if (empty($batchFiles)) { log_message('error', 'VIDAL V2 - TPA ID Pull FAILED | batchFiles is empty for this tpa id pull request'); + + $file_model = new BatchFileModel(); + $bfData = [ + 'error_data' => json_encode(['error_data' => 'No trace found for TPA member download (export).']), + 'status' => 'failed-7', + ]; + $file_model->where('id', $requestData['file_id'])->set($bfData)->update(); + if ($function_calling_type === 'job') { return ['status' => false, 'message' => 'batchFiles not found']; } diff --git a/app/Views/batch_list.php b/app/Views/batch_list.php index c7618915..8849f24f 100755 --- a/app/Views/batch_list.php +++ b/app/Views/batch_list.php @@ -373,7 +373,7 @@ for ($i = 0; $i < $batch_col_count; $i++) { failed + data-placement="top" title=""> From b2f490a60dc86fc6b4676428f44150e9fd1575f5 Mon Sep 17 00:00:00 2001 From: velz Date: Sat, 2 May 2026 16:53:17 +0530 Subject: [PATCH 5/5] FIX_TPA_DEL&RECON --- app/Controllers/EmployeeController.php | 10 +++++----- app/Controllers/EmployeeServiceController.php | 2 ++ app/Controllers/JobWorker.php | 8 ++++++++ 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/app/Controllers/EmployeeController.php b/app/Controllers/EmployeeController.php index 812e6f28..3c1d1940 100755 --- a/app/Controllers/EmployeeController.php +++ b/app/Controllers/EmployeeController.php @@ -4305,7 +4305,7 @@ class EmployeeController extends AdminController } // this will match tpa api data with emp/emp policy table and update ref in tpa api data once - $this->reconTpaApiDataWithEmployeepolicies($file_id); + $this->reconTpaApiDataWithEmployeepolicies(['file_id' => $file_id]); } else { // echo 'else';die; // Cached mode: @@ -4449,10 +4449,10 @@ class EmployeeController extends AdminController { sleep(1); //initiate update references b/w tpa_api_data and employess (pk update) - $this->reconTpaApiDataWithEmployeepolicies($file_id); + // $this->reconTpaApiDataWithEmployeepolicies(['file_id' => $file_id]); sleep(1); //initiate deleteion if any - $this->initializeDeletionProcessForTpaApiData($file_id); + // $this->initializeDeletionProcessForTpaApiData(['file_id' => $file_id]); } else @@ -6523,7 +6523,7 @@ class EmployeeController extends AdminController public function reconTpaApiDataWithEmployeepolicies($file_id): array { try { - $fileId = (int) $file_id; + $fileId = (int) $file_id['file_id']; if ($fileId <= 0) { return [ 'status' => false, @@ -6716,7 +6716,7 @@ class EmployeeController extends AdminController { // echo 'DELETION'; try { - $fileId = (int) $file_id; + $fileId = (int) $file_id['file_id']; if ($fileId <= 0) { return [ 'status' => false, diff --git a/app/Controllers/EmployeeServiceController.php b/app/Controllers/EmployeeServiceController.php index b5d73432..faf98a6a 100755 --- a/app/Controllers/EmployeeServiceController.php +++ b/app/Controllers/EmployeeServiceController.php @@ -1754,6 +1754,8 @@ 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]]); + $r = Jobs::addJob(['job_name' => 'reconTpaApiDataWithEmployeepolicies','payload' => ['file_id' => $batch_file_id]]); + $r = Jobs::addJob(['job_name' => 'initializeDeletionProcessForTpaApiData','payload' => ['file_id' => $batch_file_id]]); $this->myLogger->logme("error", 'Batch file id {batch_file_id} processed successfully', ['batch_file_id' => $batch_file_id]); } diff --git a/app/Controllers/JobWorker.php b/app/Controllers/JobWorker.php index f6d9f2eb..466cbf82 100755 --- a/app/Controllers/JobWorker.php +++ b/app/Controllers/JobWorker.php @@ -278,6 +278,14 @@ class JobWorker extends AdminController 'updateTpaIdForNotInNhance' => [ 'type' => 'CC', // Handler Category 'handler' => 'App\Controllers\EmployeeController', + ], + 'initializeDeletionProcessForTpaApiData' => [ + 'type' => 'CC', // Handler Category + 'handler' => 'App\Controllers\EmployeeController', + ], + 'reconTpaApiDataWithEmployeepolicies' => [ + 'type' => 'CC', // Handler Category + 'handler' => 'App\Controllers\EmployeeController', ] ];