diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 1531645b..15c4aa0a 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -560,6 +560,8 @@ $routes->cli('cli/send_mail_cli', 'MasterController::testGmailAPIViaCLI'); $routes->cli('cli/sendZeptoMail', 'MasterController::testZeptoSMTP'); $routes->cli('cli/check_bounce_mail_cli', 'MasterController::testCheckBounceMails'); $routes->cli('cli/app_check_list', 'MasterController::appCheckList'); +$routes->cli('cli/reset-token-timeout', 'RestAuthenticationController::resetTokenTimeOut'); +$routes->cli('cli/reset-token-timeout/(:num)', 'RestAuthenticationController::resetTokenTimeOut/$1'); $routes->cli('cli/new_gdrive_token', 'GoogleDriveController::generateNewGoogleDriveAccessToken'); $routes->cli('cli/list-sheet-folder-files', 'GoogleSheetController::listFolderSheetFilesCli'); $routes->cli('cli/list-sheet-folder-files/(:any)', 'GoogleSheetController::listFolderSheetFilesCli/$1'); diff --git a/app/Controllers/ApiServiceController.php b/app/Controllers/ApiServiceController.php index ea3103e9..2c28bb6c 100644 --- a/app/Controllers/ApiServiceController.php +++ b/app/Controllers/ApiServiceController.php @@ -446,6 +446,9 @@ class ApiServiceController extends BaseController if ($tpaID == $this->medi_assist_primary_key) { // MediAssist $mediAssistController = new MediAssistApiController(); return $mediAssistController->IRSubmission($claimId); + }else if ($tpaID == $this->vidal_primary_key) { // Vidal + $vidalApiController = new VidalApiController(); + return $vidalApiController->IRSubmission($claimId); }else{ log_message('error', "This ticket id ( {$claimId} ) TPA has no API service enabled. TPA ID : {$tpaID}"); } diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index d7d81683..7d5e4c97 100755 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -2409,13 +2409,16 @@ class EmployeeRestController extends AdminController $client_id = $this->request->getGet('client_id') ?? null; - $data['claim_status'] = $this->claimStatusModel - ->select('id,ticket_type, display_name as claim_status') - ->where('is_active', 1) - ->where('display_name IS NOT NULL OR display_name <> ""') - ->whereIn('claim_status_id',[1,2,3,4]) - ->groupBy('display_name') - ->findAll(); + $data['claim_status'] = $this->claimStatusModel + ->select('id, ticket_type, display_name as claim_status') + ->where('is_active', 1) + ->groupStart() + ->where('display_name IS NOT NULL') + ->orWhere('display_name <>', '') + ->groupEnd() + ->whereIn('ticket_type', [1,2,3,4]) + ->groupBy('display_name') + ->findAll(); if (!empty($client_id)) { diff --git a/app/Controllers/FhplApiController.php b/app/Controllers/FhplApiController.php index 532776ff..1d280ea5 100644 --- a/app/Controllers/FhplApiController.php +++ b/app/Controllers/FhplApiController.php @@ -85,6 +85,8 @@ class FhplApiController extends BaseController cp.policy_no as policyNo, e.emp_code as memberId, tn.note as disease, + cf.id as fileId, + cf.url as filePath, cf.url as filePath ') ->join('employees e', 'e.id = tm.emp_id', 'left') @@ -102,6 +104,7 @@ class FhplApiController extends BaseController } // Build absolute file path + $file_id = $data['fileId'] ?? null; $filename = basename($data['filePath']); $pdfPath = WRITEPATH . 'uploads/claim_files/' . $filename; @@ -182,6 +185,18 @@ class FhplApiController extends BaseController 'tpa_claim_push_reference_no' => $fhplClaimNo, 'updated_at' => date('Y-m-d H:i:s') ]); + + // Update claim files table that file is sent to tpa for this claim + if(!empty($file_id)){ + + $this->db->table('claim_files') + ->where('id', $file_id) + ->update([ 'is_file_sent_to_tpa' => 1 ]); + + log_message('error','HEALTH_INDIA - Claim Push | Updating claim_files table for file_id: '.$file_id); + }else{ + log_message('error','HEALTH_INDIA - Claim Push | No file_id found to update claim_files table.'); + } log_message('error', 'FHPL - Claim Push SUCCESS | claimId: '.$claimId.' | claimNO: '.$fhplClaimNo); return ['status' => true, 'message' => 'Claim Push SUCCESS', 'response' => $response]; diff --git a/app/Controllers/HealthIndiaApiController.php b/app/Controllers/HealthIndiaApiController.php index 0552700a..f498f039 100644 --- a/app/Controllers/HealthIndiaApiController.php +++ b/app/Controllers/HealthIndiaApiController.php @@ -105,6 +105,7 @@ class HealthIndiaApiController extends BaseController cp.policy_no as policyNumber, e.emp_code as employeeCode, tn.note as disease, + cf.id as fileId, cf.url as filePath, tm.claim_type as claimType, tm.claim_type as benefitType @@ -130,6 +131,7 @@ class HealthIndiaApiController extends BaseController } // Build absolute file path + $file_id = $data['fileId'] ?? null; $filename = basename($data['filePath']); $pdfPath = WRITEPATH . 'uploads/claim_files/' . $filename; @@ -231,6 +233,18 @@ class HealthIndiaApiController extends BaseController 'updated_at' => date('Y-m-d H:i:s') ]); + // Update claim files table that file is sent to tpa for this claim + if(!empty($file_id)){ + + $this->db->table('claim_files') + ->where('id', $file_id) + ->update([ 'is_file_sent_to_tpa' => 1 ]); + + log_message('error','HEALTH_INDIA - Claim Push | Updating claim_files table for file_id: '.$file_id); + }else{ + log_message('error','HEALTH_INDIA - Claim Push | No file_id found to update claim_files table.'); + } + 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 { diff --git a/app/Controllers/MediAssistApiController.php b/app/Controllers/MediAssistApiController.php index f4ceaff6..65a8992a 100644 --- a/app/Controllers/MediAssistApiController.php +++ b/app/Controllers/MediAssistApiController.php @@ -42,8 +42,9 @@ class MediAssistApiController extends BaseController 'Password:'. getenv('MEDI_ASSIST_API_PASSWORD').'', ]; + $file_id = null; + //Prepare body data - // Fetch the data from DB $data = $this->db->table('ticket_master tm') ->select(' @@ -59,6 +60,7 @@ class MediAssistApiController extends BaseController tm.tpa_no as memberId, tn.note as disease, tn.note as reasonForHospitalization, + cf.id as fileId, cf.url as fileName, cf.url as filePath ') @@ -83,6 +85,7 @@ class MediAssistApiController extends BaseController if ($fileDir) { $downloadUrl = base_url('fileDownload?file_path=').$fileDir; + $file_id = $data['fileId'] ?? null; } else { $downloadUrl = ''; } @@ -152,10 +155,23 @@ class MediAssistApiController extends BaseController log_message('error','MEDI_ASSIST - Claim Push SUCCESS | claimId: '.$claimId.' | claimReferenceNo: '.$claimRef); + // Update claim reference number in ticket_master $this->db->table('ticket_master') ->where('id',$claimId) ->update([ 'tpa_claim_push_reference_no' => $claimRef ]); + // Update claim files table that file is sent to tpa for this claim + if(!empty($file_id)){ + + $this->db->table('claim_files') + ->where('id', $file_id) + ->update([ 'is_file_sent_to_tpa' => 1 ]); + + log_message('error','MEDI_ASSIST - Claim Push | Updating claim_files table for file_id: '.$file_id); + }else{ + log_message('error','MEDI_ASSIST - Claim Push | No file_id found to update claim_files table.'); + } + return ['status' => true, 'message' => 'Claim Push SUCCESS', 'response' => $response]; } else { @@ -695,16 +711,19 @@ class MediAssistApiController extends BaseController $fileData = $this->db->table('claim_files f') ->where('f.ticket_id', $claimId) ->where('f.docs_for_ir', 1) + ->where('f.file_type', 2) + ->where('f.is_file_sent_to_tpa', 0) ->get() ->getResultArray(); $Attachments = []; + $tpaSentFileIds = []; if (count($fileData)) { foreach ($fileData as $file) { - if (!empty($file['url'])) { + if (!empty($file['url']) && $file['file_type'] == 2) { $filename = basename($file['url']); $fileDir = WRITEPATH . 'uploads/claim_files/' . $filename; @@ -721,6 +740,9 @@ class MediAssistApiController extends BaseController "AttachmentName" => $filename, "AttachmentPath" => $downloadUrl ]; + + $tpaSentFileIds[] = $file['id']; // Collect file IDs to update later + } else { log_message('error',"MEDI_ASSIST - IR Submission Missing File URL → file_id={$file['id']}"); } @@ -767,6 +789,18 @@ class MediAssistApiController extends BaseController log_message('error',"MEDI_ASSIST - IR Submission SUCCESS → ClaimID={$ticket['ClaimID']}"); + // 6. UPDATE FILES AS SENT TO TPA + if(count($tpaSentFileIds) > 0){ + + $this->db->table('claim_files') + ->whereIn('id', $tpaSentFileIds) + ->update(['is_file_sent_to_tpa' => 1]); + + log_message('error',"MEDI_ASSIST - IR Submission | Updating claim_files for file IDs: " . implode(', ', $tpaSentFileIds)); + } else { + log_message('error',"MEDI_ASSIST - IR Submission | No files to update as sent to TPA"); + } + return [ 'status' => true, 'message' => 'IR Submitted successfully', diff --git a/app/Controllers/RestAuthenticationController.php b/app/Controllers/RestAuthenticationController.php index 14600e38..ae85137b 100755 --- a/app/Controllers/RestAuthenticationController.php +++ b/app/Controllers/RestAuthenticationController.php @@ -2326,6 +2326,10 @@ class RestAuthenticationController extends AdminController public function logout() { + return $this->respond([ + 'status' => true, + 'message' => 'Logged out successfully' + ], 200); $authHeader = $this->request->getHeaderLine('Authorization'); if (!$authHeader) { @@ -2373,4 +2377,52 @@ class RestAuthenticationController extends AdminController ], 200); } + public function resetTokenTimeOut($bufferSeconds = null) + { + if (!is_cli()) { + return $this->respond([ + 'status' => false, + 'message' => 'This endpoint is CLI only.' + ], 403); + } + + $envBuffer = (int) (getenv('TOKEN_TIMEOUT_RESET_BUFFER_SECONDS') ?: 300); + $buffer = is_numeric($bufferSeconds) ? (int) $bufferSeconds : $envBuffer; + if ($buffer < 0) { + $buffer = 0; + } + + $cutoffEpoch = time() - $buffer; + $db = db_connect(); + + $db->table('level_contacts') + ->where('token_time_out IS NOT NULL', null, false) + ->where('token_time_out <=', $cutoffEpoch) + ->set(['token_time_out' => null]) + ->update(); + $levelContactsUpdated = $db->affectedRows(); + + $db->table('employees') + ->where('token_time_out IS NOT NULL', null, false) + ->where('token_time_out <=', $cutoffEpoch) + ->set(['token_time_out' => null]) + ->update(); + $employeesUpdated = $db->affectedRows(); + + $result = [ + 'status' => true, + 'message' => 'Token timeout reset completed.', + 'buffer_seconds' => $buffer, + 'cutoff_epoch' => $cutoffEpoch, + 'updated' => [ + 'level_contacts' => $levelContactsUpdated, + 'employees' => $employeesUpdated, + 'total' => $levelContactsUpdated + $employeesUpdated, + ], + ]; + + echo json_encode($result, JSON_UNESCAPED_SLASHES) . PHP_EOL; + return; + } + } \ No newline at end of file diff --git a/app/Controllers/TicketController.php b/app/Controllers/TicketController.php index 32a3eeb9..7aacb3a8 100644 --- a/app/Controllers/TicketController.php +++ b/app/Controllers/TicketController.php @@ -539,6 +539,7 @@ class TicketController extends BaseController 'tm.emp_personal_mail', 'tm.mode_of_intimation', 'tm.claim_type', + 'tm.tpa_claim_type', 'tm.hospital_name', 'tm.doa', 'tm.dod', @@ -673,6 +674,7 @@ class TicketController extends BaseController 'tm.emp_personal_mail', 'tm.mode_of_intimation', 'tm.claim_type', + 'tm.tpa_claim_type', 'tm.hospital_name', 'tm.doa', 'tm.dod', @@ -1140,6 +1142,8 @@ class TicketController extends BaseController public function createTicket() { $request_data = $this->request->getPost(); + $approvedLetterFile = $this->request->getFile('approved_letter_file'); + $settleLetterFile = $this->request->getFile('settle_letter_file'); $selected_ticket_type = $this->request->getPost('ticket_type_id'); // 1. Initialize an empty rules array @@ -1455,6 +1459,84 @@ class TicketController extends BaseController $request_data = $this->request->getPost(); $sanitized_data = sanitizeInputArrayAdvanced($request_data); $ticket_data = $this->formatDateForClaim($sanitized_data); + $approvedLetterUrl = trim((string) ($ticket_data['approved_letter'] ?? '')); + $settleLetterUrl = trim((string) ($ticket_data['settle_letter'] ?? '')); + $hasApprovedLetterFile = $approvedLetterFile !== null + && $approvedLetterFile->isValid() + && $approvedLetterFile->getError() !== UPLOAD_ERR_NO_FILE; + $hasSettleLetterFile = $settleLetterFile !== null + && $settleLetterFile->isValid() + && $settleLetterFile->getError() !== UPLOAD_ERR_NO_FILE; + + if ($approvedLetterUrl !== '' && $hasApprovedLetterFile) { + return $this->response->setStatusCode(400)->setJSON([ + 'status' => false, + 'message' => 'Input validation failed', + 'code' => 400, + 'errors' => ['approved_letter' => 'Provide either Approved Letter URL or Approved Letter PDF file, not both.'], + ]); + } + + if ($approvedLetterUrl !== '' && ! $this->isClaimUploadUrl($approvedLetterUrl)) { + return $this->response->setStatusCode(400)->setJSON([ + 'status' => false, + 'message' => 'Input validation failed', + 'code' => 400, + 'errors' => ['approved_letter' => 'Approved Letter URL format is invalid.'], + ]); + } + + if ($settleLetterUrl !== '' && $hasSettleLetterFile) { + return $this->response->setStatusCode(400)->setJSON([ + 'status' => false, + 'message' => 'Input validation failed', + 'code' => 400, + 'errors' => ['settle_letter' => 'Provide either Settle Letter URL or Settle Letter PDF file, not both.'], + ]); + } + + if ($settleLetterUrl !== '' && ! $this->isClaimUploadUrl($settleLetterUrl)) { + return $this->response->setStatusCode(400)->setJSON([ + 'status' => false, + 'message' => 'Input validation failed', + 'code' => 400, + 'errors' => ['settle_letter' => 'Settle Letter URL format is invalid.'], + ]); + } + + $uploadedApprovedLetter = null; + if ($hasApprovedLetterFile) { + $uploadResult = $this->uploadApprovedLetterPdf($approvedLetterFile, 'Approved Letter'); + if (! ($uploadResult['status'] ?? false)) { + return $this->response->setStatusCode(400)->setJSON([ + 'status' => false, + 'message' => 'Input validation failed', + 'code' => 400, + 'errors' => ['approved_letter_file' => $uploadResult['message'] ?? 'Invalid Approved Letter file.'], + ]); + } + $uploadedApprovedLetter = $uploadResult['data']; + $ticket_data['approved_letter'] = ''; + } else { + $ticket_data['approved_letter'] = $approvedLetterUrl; + } + + $uploadedSettleLetter = null; + if ($hasSettleLetterFile) { + $uploadResult = $this->uploadApprovedLetterPdf($settleLetterFile, 'Settle Letter'); + if (! ($uploadResult['status'] ?? false)) { + return $this->response->setStatusCode(400)->setJSON([ + 'status' => false, + 'message' => 'Input validation failed', + 'code' => 400, + 'errors' => ['settle_letter_file' => $uploadResult['message'] ?? 'Invalid Settle Letter file.'], + ]); + } + $uploadedSettleLetter = $uploadResult['data']; + $ticket_data['settle_letter'] = ''; + } else { + $ticket_data['settle_letter'] = $settleLetterUrl; + } // $ticket_data = $this->getLastMatchedStatus($ticket_data, ); // print_rr($ticket_data); die; @@ -1499,6 +1581,37 @@ class TicketController extends BaseController $ticket_data['claim_created_by'] = "CRM"; $return_value = $this->ticketMasterModel->insert($ticket_data); if ($return_value) { + if ($uploadedApprovedLetter !== null) { + $approvedLetterDownloadUrl = $this->createApprovedLetterFileUrl( + (int) $return_value, + (int) ($ticket_data['ticket_type_id'] ?? 1), + $uploadedApprovedLetter, + 'APPROVED_LETTER_PDF' + ); + $ticket_data['approved_letter'] = $approvedLetterDownloadUrl; + } + + if ($uploadedSettleLetter !== null) { + $settleLetterDownloadUrl = $this->createApprovedLetterFileUrl( + (int) $return_value, + (int) ($ticket_data['ticket_type_id'] ?? 1), + $uploadedSettleLetter, + 'SETTLE_LETTER_PDF' + ); + $ticket_data['settle_letter'] = $settleLetterDownloadUrl; + } + + if ($uploadedApprovedLetter !== null || $uploadedSettleLetter !== null) { + $updateUploadedLetterData = []; + if (isset($ticket_data['approved_letter'])) { + $updateUploadedLetterData['approved_letter'] = $ticket_data['approved_letter']; + } + if (isset($ticket_data['settle_letter'])) { + $updateUploadedLetterData['settle_letter'] = $ticket_data['settle_letter']; + } + $this->ticketMasterModel->where('id', $return_value)->set($updateUploadedLetterData)->update(); + } + //mail trigger part $this->putHistoryAfterInsert($ticket_data, $return_value); $mail_responce = $this->sendAutoMailTrigger($return_value); @@ -1517,6 +1630,8 @@ class TicketController extends BaseController { $request_data = $this->request->getPost(); + $approvedLetterFile = $this->request->getFile('approved_letter_file'); + $settleLetterFile = $this->request->getFile('settle_letter_file'); $selected_ticket_type = $this->request->getPost('ticket_type_id'); // 1. Initialize an empty rules array @@ -1832,6 +1947,85 @@ class TicketController extends BaseController $sanitized_data = sanitizeInputArrayAdvanced($request_data); $ticket_data = $this->formatDateForClaim($sanitized_data); $ticket_id = $this->request->getPost('ticket_master_id'); + $approvedLetterUrl = trim((string) ($ticket_data['approved_letter'] ?? '')); + $settleLetterUrl = trim((string) ($ticket_data['settle_letter'] ?? '')); + $hasApprovedLetterFile = $approvedLetterFile !== null + && $approvedLetterFile->isValid() + && $approvedLetterFile->getError() !== UPLOAD_ERR_NO_FILE; + $hasSettleLetterFile = $settleLetterFile !== null + && $settleLetterFile->isValid() + && $settleLetterFile->getError() !== UPLOAD_ERR_NO_FILE; + + if ($approvedLetterUrl !== '' && $hasApprovedLetterFile) { + return $this->response->setStatusCode(400)->setJSON([ + 'status' => false, + 'message' => 'Input validation failed', + 'code' => 400, + 'errors' => ['approved_letter' => 'Provide either Approved Letter URL or Approved Letter PDF file, not both.'], + ]); + } + + if ($approvedLetterUrl !== '' && ! $this->isClaimUploadUrl($approvedLetterUrl)) { + return $this->response->setStatusCode(400)->setJSON([ + 'status' => false, + 'message' => 'Input validation failed', + 'code' => 400, + 'errors' => ['approved_letter' => 'Approved Letter URL format is invalid.'], + ]); + } + + if ($settleLetterUrl !== '' && $hasSettleLetterFile) { + return $this->response->setStatusCode(400)->setJSON([ + 'status' => false, + 'message' => 'Input validation failed', + 'code' => 400, + 'errors' => ['settle_letter' => 'Provide either Settle Letter URL or Settle Letter PDF file, not both.'], + ]); + } + + if ($settleLetterUrl !== '' && ! $this->isClaimUploadUrl($settleLetterUrl)) { + return $this->response->setStatusCode(400)->setJSON([ + 'status' => false, + 'message' => 'Input validation failed', + 'code' => 400, + 'errors' => ['settle_letter' => 'Settle Letter URL format is invalid.'], + ]); + } + + $uploadedApprovedLetter = null; + if ($hasApprovedLetterFile) { + $uploadResult = $this->uploadApprovedLetterPdf($approvedLetterFile, 'Approved Letter'); + if (! ($uploadResult['status'] ?? false)) { + return $this->response->setStatusCode(400)->setJSON([ + 'status' => false, + 'message' => 'Input validation failed', + 'code' => 400, + 'errors' => ['approved_letter_file' => $uploadResult['message'] ?? 'Invalid Approved Letter file.'], + ]); + } + $uploadedApprovedLetter = $uploadResult['data']; + $ticket_data['approved_letter'] = ''; + } else { + $ticket_data['approved_letter'] = $approvedLetterUrl; + } + + $uploadedSettleLetter = null; + if ($hasSettleLetterFile) { + $uploadResult = $this->uploadApprovedLetterPdf($settleLetterFile, 'Settle Letter'); + if (! ($uploadResult['status'] ?? false)) { + return $this->response->setStatusCode(400)->setJSON([ + 'status' => false, + 'message' => 'Input validation failed', + 'code' => 400, + 'errors' => ['settle_letter_file' => $uploadResult['message'] ?? 'Invalid Settle Letter file.'], + ]); + } + $uploadedSettleLetter = $uploadResult['data']; + $ticket_data['settle_letter'] = ''; + } else { + $ticket_data['settle_letter'] = $settleLetterUrl; + } + $old_ticket_data = $this->ticketMasterModel->where('id', $ticket_id)->where('is_active', 1)->first(); $ticket_data['claim_status_id'] = $this->getLastMatchedStatus($ticket_data, $old_ticket_data); $ticket_data['last_updated_by'] = 'USER'; @@ -1842,6 +2036,24 @@ class TicketController extends BaseController $this->myLogger->logme('error', "[UPDATE_CLAIM] New Ticket Data: {data}", ['data' => json_encode($ticket_data, JSON_PRETTY_PRINT)]); if ($ticket_data) { + if ($uploadedApprovedLetter !== null) { + $ticket_data['approved_letter'] = $this->createApprovedLetterFileUrl( + (int) $ticket_id, + (int) ($ticket_data['ticket_type_id'] ?? 1), + $uploadedApprovedLetter, + 'APPROVED_LETTER_PDF' + ); + } + + if ($uploadedSettleLetter !== null) { + $ticket_data['settle_letter'] = $this->createApprovedLetterFileUrl( + (int) $ticket_id, + (int) ($ticket_data['ticket_type_id'] ?? 1), + $uploadedSettleLetter, + 'SETTLE_LETTER_PDF' + ); + } + $return_value = $this->ticketMasterModel->where('id', $ticket_id)->set($ticket_data)->update(); if ($return_value) { @@ -3264,6 +3476,55 @@ class TicketController extends BaseController return strpos($host, '.') !== false; } + private function uploadApprovedLetterPdf($file, string $documentLabel = 'Approved Letter'): array + { + if ($file === null || ! $file->isValid() || $file->getError() === UPLOAD_ERR_NO_FILE) { + return ['status' => false, 'message' => $documentLabel . ' file is missing.']; + } + + $ext = strtolower((string) $file->getClientExtension()); + $mime = strtolower((string) $file->getMimeType()); + $allowedMime = ['application/pdf', 'application/x-pdf']; + + if ($ext !== 'pdf' || (! empty($mime) && ! in_array($mime, $allowedMime, true))) { + return ['status' => false, 'message' => 'Only PDF files are allowed for ' . $documentLabel . ' upload.']; + } + + $uploadPath = WRITEPATH . 'uploads/claim_files/'; + if (! is_dir($uploadPath)) { + mkdir($uploadPath, 0755, true); + } + + $diskFileName = file_Upload_for_lead($file, $uploadPath, ['pdf']); + if (empty($diskFileName)) { + return ['status' => false, 'message' => 'Failed to upload ' . $documentLabel . ' file.']; + } + + return [ + 'status' => true, + 'data' => [ + 'file_name' => $diskFileName, + 'mime_type' => $mime ?: 'application/pdf', + ], + ]; + } + + private function createApprovedLetterFileUrl(int $ticketId, int $ticketTypeId, array $uploadedFile, string $docName = 'APPROVED_LETTER_PDF'): string + { + $fileId = $this->claimFilesModel->insert([ + 'ticket_id' => $ticketId, + 'ticket_type' => $ticketTypeId, + 'file_type' => 3, + 'doc_name' => $docName, + 'file_name' => $uploadedFile['file_name'], + 'url' => $uploadedFile['file_name'], + 'mime_type' => $uploadedFile['mime_type'] ?? 'application/pdf', + 'is_active' => 1, + ]); + + return base_url('downloadClaimFile/' . $fileId); + } + public function upload_url() { @@ -3379,6 +3640,7 @@ class TicketController extends BaseController } } + //get the claim file list data against the ticket id public function getUrlDataByTicketId() { $ticket_id = $this->request->getPost('ticket_id'); @@ -3401,6 +3663,7 @@ class TicketController extends BaseController END AS url ") ->where('ticket_id', $ticket_id) + ->where('file_type !=', 3) // Assuming you want to fetch both URL and file uploads ->where('is_active', 1) ->findAll(); diff --git a/app/Controllers/VidalApiController.php b/app/Controllers/VidalApiController.php index 06a78a57..e09fc9fb 100644 --- a/app/Controllers/VidalApiController.php +++ b/app/Controllers/VidalApiController.php @@ -156,6 +156,7 @@ class VidalApiController extends BaseController e.emp_code as memberId, tn.note as disease, tn.note as reasonForHospitalization, + cf.id as cfFileId, cf.url as fileName, cf.url as filePath, pt.policy_type as typeOfClaim, @@ -195,6 +196,7 @@ class VidalApiController extends BaseController } $fileId = $upload['fileId']; + $tpa_sent_file_id = $data['cfFileId'] ?? null; // $url = 'https://devapigw.vidalhealthtpa.com/partner-integration/api/claims/submit'; $url = getenv('VIDAL_API_BASE_URL').'/claims/submit'; $method = 'POST'; @@ -299,6 +301,18 @@ class VidalApiController extends BaseController ->where('id',$claimId) ->update([ 'tpa_claim_push_reference_no' => $claimInwardNO , 'tpa_claim_id' => $claimNO , 'claim_number' => $claimNO ]); + // Update claim files table that file is sent to tpa for this claim + if(!empty($tpa_sent_file_id)){ + + $this->db->table('claim_files') + ->where('id', $tpa_sent_file_id) + ->update([ 'is_file_sent_to_tpa' => 1 ]); + + log_message('error','MEDI_ASSIST - Claim Push | Updating claim_files table for file_id: '.$tpa_sent_file_id); + }else{ + log_message('error','MEDI_ASSIST - Claim Push | No file_id found to update claim_files table.'); + } + return ['status' => true, 'message' => 'Claim Push SUCCESS']; } else { @@ -1664,6 +1678,8 @@ class VidalApiController extends BaseController $fileData = $this->db->table('claim_files f') ->where('f.ticket_id', $claimId) ->where('f.docs_for_ir', 1) + ->where('f.file_type', 2) + ->where('f.is_file_sent_to_tpa', 0) ->get() ->getResultArray(); @@ -1678,6 +1694,7 @@ class VidalApiController extends BaseController // 3. UPLOAD FILES TO VIDAL $fileIdList = []; + $tpaSentFileIds = []; foreach ($fileData as $file) { @@ -1701,6 +1718,7 @@ class VidalApiController extends BaseController } $fileIdList[] = $upload['fileId']; // deeplink URL + $tpaSentFileIds[] = $file['id']; // local file ID for updating } if (empty($fileIdList)) { @@ -1756,6 +1774,18 @@ class VidalApiController extends BaseController log_message('error', "VIDAL - IR Submission SUCCESS → ClaimNO={$ticket['claimNO']}"); + // 6. UPDATE FILES AS SENT TO TPA + if(count($tpaSentFileIds) > 0){ + + $this->db->table('claim_files') + ->whereIn('id', $tpaSentFileIds) + ->update(['is_file_sent_to_tpa' => 1]); + + log_message('error',"VIDAL - IR Submission | Updating claim_files for file IDs: " . implode(', ', $tpaSentFileIds)); + } else { + log_message('error',"VIDAL - IR Submission | No files to update as sent to TPA"); + } + return [ 'status' => true, 'message' => 'IR Submitted successfully', diff --git a/app/Controllers/VoloApiController.php b/app/Controllers/VoloApiController.php index 79320a2b..63e63c6d 100644 --- a/app/Controllers/VoloApiController.php +++ b/app/Controllers/VoloApiController.php @@ -692,6 +692,7 @@ class VoloApiController extends BaseController tm.claim_amount as requestedAmount, tm.tpa_no as memberId, cp.policy_no as policyNo, + cf.id as fileId, cf.url as filePath ') ->join('client_policy cp', 'tm.client_policy_id = cp.id', 'left') @@ -710,6 +711,7 @@ class VoloApiController extends BaseController return ['status' => false, 'message' => 'Claim Push FAILED | File Missing']; } + $file_id = $data['fileId'] ?? null; $filename = basename($data['filePath']); $pdfPath = WRITEPATH . 'uploads/claim_files/' . $filename; if (!is_readable($pdfPath)) { @@ -781,6 +783,18 @@ class VoloApiController extends BaseController ]); log_message('error', 'VOLO - Claim Push SUCCESS | claimId: ' . $claimId . ' | ref: ' . $ref); + // Update claim files table that file is sent to tpa for this claim + if(!empty($file_id)){ + + $this->db->table('claim_files') + ->where('id', $file_id) + ->update([ 'is_file_sent_to_tpa' => 1 ]); + + log_message('error','VOLO - Claim Push | Updating claim_files table for file_id: '.$file_id); + }else{ + log_message('error','VOLO - Claim Push | No file_id found to update claim_files table.'); + } + return ['status' => true, 'message' => 'Claim Push SUCCESS', 'response' => $response]; } diff --git a/app/Models/ClaimFilesModel.php b/app/Models/ClaimFilesModel.php index 0d48ce05..055b9b3b 100644 --- a/app/Models/ClaimFilesModel.php +++ b/app/Models/ClaimFilesModel.php @@ -24,6 +24,7 @@ class ClaimFilesModel extends Model 'file_name', 'mime_type', 'docs_for_ir', + 'is_file_sent_to_tpa', ]; // Callbacks diff --git a/app/Views/ticket_edit_onbording.php b/app/Views/ticket_edit_onbording.php index 493735b3..857a2796 100644 --- a/app/Views/ticket_edit_onbording.php +++ b/app/Views/ticket_edit_onbording.php @@ -465,15 +465,23 @@ let ticket_master_id = $('#ticket_master_id').val(); console.log({ticket_master_id}); + if (!ticket_master_id) { + toastr.warning('Claim ID not found. Please ensure the form is loaded.', 'Warning'); + return; + } let requestData = { claim_id: ticket_master_id, }; let url = ''; + $('.loader').fadeIn(); + $('.loader-mask').fadeIn(); // Send AJAX request sendAjaxRequestForGlobal(url, 'GET', requestData, function(response) { + $('.loader').fadeOut(); + $('.loader-mask').delay(350).fadeOut('slow'); console.log('Data fetched successfully:', response); @@ -485,6 +493,8 @@ } }, function(xhr, status, error) { + $('.loader').fadeOut(); + $('.loader-mask').delay(350).fadeOut('slow'); console.error('Error fetching data:', error); console.error(xhr.responseText); toastr.error('An error occurred while saving docs.', 'Error'); diff --git a/app/Views/ticket_form_gmc.php b/app/Views/ticket_form_gmc.php index 4db28f7d..003e4c3b 100644 --- a/app/Views/ticket_form_gmc.php +++ b/app/Views/ticket_form_gmc.php @@ -429,10 +429,26 @@ value="" name="approved_date"> -