'document type' , 'fileName' => $filename]); $headers = [ "Content-Type: application/json", "Ocp-Apim-Subscription-Key: $subscriptionKey" ]; log_message('error', "Requesting signed URL from Vidal API: $apiUrl | Payload: $payload"); $ch = curl_init($apiUrl); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $payload); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); $response = curl_exec($ch); if (curl_errno($ch)) { log_message('error', "Curl error while requesting signed URL: " . curl_error($ch)); return ["status" => false, "message" => curl_error($ch)]; } curl_close($ch); $responseData = json_decode($response, true); if (!isset($responseData['data']['signedUrl']) || !isset($responseData['data']['fileId'])) { log_message('error', "Invalid signed URL response received: " . json_encode($responseData)); return ["status" => false, "message" => "Invalid signed URL response", "response" => $responseData]; } $signedUrl = $responseData['data']['signedUrl']; $fileId = $responseData['data']['fileId']; log_message('error', "Received signed URL & fileId. fileId: $fileId"); // Step 2: Upload file to signed URL using PUT (Azure Blob) $fileSize = filesize($filePath); $fileContent = fopen($filePath, 'r'); $ch2 = curl_init($signedUrl); curl_setopt($ch2, CURLOPT_PUT, true); curl_setopt($ch2, CURLOPT_INFILE, $fileContent); curl_setopt($ch2, CURLOPT_INFILESIZE, $fileSize); curl_setopt($ch2, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch2, CURLOPT_HTTPHEADER, [ "x-ms-blob-type: BlockBlob", "Content-Length: $fileSize" ]); $uploadResponse = curl_exec($ch2); $httpCode = curl_getinfo($ch2, CURLINFO_HTTP_CODE); $curlErr = curl_error($ch2); fclose($fileContent); curl_close($ch2); if ($curlErr) { log_message('error', "Curl error during file upload: $curlErr"); return ["status" => false, "message" => "File upload failed", "data" => $curlErr]; } if ($httpCode !== 200 && $httpCode !== 201) { log_message('error', "File upload failed with HTTP Code: $httpCode | Response: $uploadResponse"); return [ "status" => false, "message" => "File upload failed", "httpCode" => $httpCode, "response" => $uploadResponse ]; } // Step 3: Return File ID for reference return [ "status" => true, "message" => "File uploaded successfully", "fileId" => $fileId, "signedUrl" => $signedUrl, "uploadResponse" => json_decode($uploadResponse, true) ]; } public function SubmitClaim ($claimId = 515) { helper('api'); //Prepare body data $db = \Config\Database::connect(); // Fetch the data from DB $data = $db->table('ticket_master tm') ->select(' tm.id, tm.emp_mobile as mobileNo, tm.emp_mail as emailId, tm.doa as admissionDate, tm.dod as dischargeDate, tm.hospital_name as hospitalName, tm.claim_amount as requestedAmount, cp.policy_no as policyNo, e.id as dependentUniqueId, e.emp_code as memberId, tn.note as disease, tn.note as reasonForHospitalization, cf.url as fileName, cf.url as filePath, pt.policy_type as typeOfClaim, ep.tpa_id as empanelmentNo, ') ->join('employees e', 'e.id = tm.emp_id', 'left') ->join('client_policy cp', 'tm.client_policy_id = cp.id', 'left') ->join('policy_type pt', 'pt.id = cp.policy_type_id', 'left') ->join('employee_polices ep', 'ep.employee_id = e.id AND ep.client_policy_id = cp.id', 'left') ->join('ticket_notes tn', 'tn.ticket_id = tm.id', 'left') ->join('claim_files cf', "cf.ticket_id = tm.id AND cf.file_type = 2 and cf.mime_type = 'application/pdf'", 'left') ->where('tm.id', $claimId) ->get() ->getRowArray(); // single record if (count($data) && $data['filePath'] == null) { log_message('error', "Submit claim failed - Claim or File Missing"); return $this->response->setJSON(['status' => false,'message' => 'Claim or File Missing', ]); } $filePath = $data['filePath'] ?? ''; $filename = basename($filePath); $filePath = WRITEPATH . 'uploads/claim_files/'.$filename; // dd($data); // Upload file first $upload = $this->uploadFileToVidal($filePath,$filename); if ($upload['status'] !== true) { log_message('error', "Submit claim failed - File upload failed"); return $this->response->setJSON([ 'status' => false, 'message' => 'File upload failed', 'data' => $upload ]); } $fileId = $upload['fileId']; // $url = 'https://devapigw.vidalhealthtpa.com/partner-integration/api/claims/submit'; $url = getenv('VIDAL_API_BASE_URL').'/claims/submit'; $method = 'POST'; $headers = [ 'Content-Type: application/json', 'Ocp-Apim-Subscription-Key:' .getenv('VIDAL_API_SUBSCRIPTION_KEY').'', ]; $body = [ 'policyNo' => $data['policyNo'], 'dependentUniqueId' => $data['dependentUniqueId'], 'typeOfClaim' => $data['typeOfClaim'], 'claimSubType' => "Test", 'requestedAmount' => $data['requestedAmount'], 'ailmentType' => "Non covid", 'admissionDate' => change_date_format($data['admissionDate'], 'Y-m-d', 'd-m-Y'), 'dischargeDate' => change_date_format($data['dischargeDate'], 'Y-m-d', 'd-m-Y'), 'hospitalName' => $data['hospitalName'], 'empanelmentNo' => $data['empanelmentNo'], "ailmentName" => "Fever", "hospitalAddress" => "No. 6, Officers Colony, Puthur.,dfgdfgdfg,dfgdfg,560058", "hospitalState" => "karnataka", "hospitalCity" => "bangalore", "hospitalPinCode" => "560036", "hospitalPhoneNo" => "1234567890", "fileId" => $fileId, "bankDetails" => [ "accountHolderName" =>"Testing claim", "accountType" =>"savings", "accountNo" =>"1234567890", "ifscCode" =>"ICICI098768" ], ]; // dd($body); log_message('error', "Submit claim failed - payload ". json_encode($body )); // $body = [ // 'policyNo' => "351500/D0534/PP/20-20/PC", // 'dependentUniqueId' => "EN000000182-C-41", // 'typeOfClaim' => "Main hospitalization claim", // 'claimSubType' => "Hospitalization", // 'requestedAmount' => "2500", // 'ailmentType' => "Non covid", // 'admissionDate' => "01-12-2025", // 'dischargeDate' => "01-12-2025", // 'hospitalName' => "AKSHAY SUPER SPECIALITY HOSPITAL", // 'empanelmentNo' => "HOS-MUM-031423", // "ailmentName" => "Cold", // "hospitalAddress" => "No. 6, Officers Colony, Puthur.,dfgdfgdfg,dfgdfg,560058", // "hospitalState" => "karnataka", // "hospitalCity" => "bangalore", // "hospitalPinCode" => "560036", // "hospitalPhoneNo" => "1234567890", // "bankDetails" => [ // "accountHolderName" =>"Testing claim", // "accountType" =>"savings", // "accountNo" =>"1234567890", // "ifscCode" =>"ICICI098768" // ], // "fileId" => "https://devapigw.vidalhealthtpa.com/doc-storage/api/private/691eda388973c60b83f80568" // ]; $response = call_third_party_api($url, $method, $headers, $body); if($response['status'] != true){ return $this->response->setJSON([ 'status' => false, 'message' => 'failed.', 'data' => $response ]); } return $this->response->setJSON($response); } public function fileUpload() { helper('api'); $url = getenv('VIDAL_API_BASE_URL') . '/files/upload-url'; $method = 'POST'; $headers = [ 'Content-Type: application/json', 'x-ms-blob-type: BlockBlob', 'Ocp-Apim-Subscription-Key:' .getenv('VIDAL_API_SUBSCRIPTION_KEY').'', ]; $body = [ 'scope' => 'application/pdf', 'fileName' => '1760013019_73d94af7b96ddc2e3d51.png', 'file' => '/opt/lampp/htdocs/nhance/writable/uploads/claim_files/1760013019_73d94af7b96ddc2e3d51.png', ]; $response = call_third_party_api($url, $method, $headers, $body); if($response['status'] != true){ return $this->response->setJSON([ 'status' => false, 'message' => 'failed.', 'data' => $response ]); } return $this->response->setJSON($response); // { // "status": true, // "data": { // "status": "SUCCESS", // "data": { // "signedUrl": "https://devapigw.vidalhealthtpa.com/doc-storage/api/deeplink/6912d37a9f09fc3f6be4cd9c/56fb8e76-39a4-4e4b-99f2-4748e224e4a7?se=2025-11-18T06:11:06.304Z", // "expiresAt": "2025-11-18T06:11:06.304Z", // "fileId": "https://devapigw.vidalhealthtpa.com/doc-storage/api/private/6912d37a9f09fc3f6be4cd9c" // }, // "trace": "T_ID_a09327df-ea34-4874-9e3f-05ac5c0a2c68", // "successful": true // }, // "code": 200 // } } public function claimStatus ($claimId = null) { helper('api'); $url = getenv('VIDAL_API_BASE_URL').'/claims/claim-dependent-info'; $method = 'POST'; $headers = [ 'Content-Type: application/json', 'Ocp-Apim-Subscription-Key:' .getenv('VIDAL_API_SUBSCRIPTION_KEY').'', ]; $body = [ 'empNO' => "", 'tpaCardID' => "", 'claimID' => "BLR-0284-CL-9349459", 'emailID' => "", 'mobileNO' => "", ]; $response = call_third_party_api($url, $method, $headers, $body); if($response['status'] != true){ return $this->response->setJSON([ 'status' => false, 'message' => 'failed.', 'data' => $response ]); } return $this->response->setJSON($response); } public function hospitalNetwork(){ $postData = $this->request->getJSON(true); helper('api'); $url = ''. getenv('VIDAL_API_BASE_URL').'/hospitalnetwork'; $method = 'POST'; $headers = [ 'Content-Type: application/json', 'Authorization:'. getenv('VIDAL_API_KEY').'', 'username:'. getenv('VIDAL_API_USERNAME').'', 'password:'. getenv('VIDAL_API_PASSWORD').'', 'policynumber:'. $postData['policyNo'] ?? '', ]; $body = []; $response = call_third_party_api($url, $method, $headers, $body); if($response['status'] != true){ return $this->response->setJSON([ 'status' => false, 'message' => 'Token generation failed.', 'data' => $response ]); } return $this->response->setJSON($response); } public function eCardService(){ $postData = $this->request->getJSON(true); helper('api'); $url = ''. getenv('VIDAL_API_BASE_URL').'/ecardservice'; $method = 'POST'; $headers = [ 'Content-Type: application/json', 'Authorization:'.getenv('VIDAL_API_KEY').'', 'username:' .getenv('VIDAL_API_USERNAME').'', 'password:' .getenv('VIDAL_API_PASSWORD').'', 'PolicyNo:' .$postData['PolicyNo'] ?? '', 'enrollmentNo:' .$postData['enrollmentNo'] ?? '', ]; $body = [ ]; $response = call_third_party_api($url, $method, $headers, $body); if($response['status'] != true){ return $this->response->setJSON([ 'status' => false, 'message' => 'Token generation failed.', 'data' => $response ]); } return $this->response->setJSON($response); } public function claimStatusCheck(){ $postData = $this->request->getJSON(true); helper('api'); $url = ''. getenv('VIDAL_API_BASE_URL').'/claimpreauthservice'; $method = 'POST'; $headers = [ 'Content-Type: application/json', 'Authorization:' .getenv('VIDAL_API_KEY').'', 'username:' .getenv('VIDAL_API_USERNAME').'', 'password:' .getenv('VIDAL_API_PASSWORD').'', 'PolicyNo:' .$postData['policyNo'] ?? '', 'enrollmentNo:' .$postData['enrollmentNo'] ?? '', 'empNo:' .$postData['empNo'] ?? '', 'startdate:' .$postData['startdate'] ?? '', 'enddate:' .$postData['enddate'] ?? '', 'tpaclaimNo:' .$postData['tpaclaimNo'] ?? '' ]; $body = []; $response = call_third_party_api($url, $method, $headers, $body); if($response['status'] != true){ return $this->response->setJSON([ 'status' => false, 'message' => 'Token generation failed.', 'data' => $response ]); } return $this->response->setJSON($response); } public function enrollment() { $postData = $this->request->getJSON(true); helper('api'); $url = getenv('VIDAL_API_BASE_URL').'/enrollmendataservice'; $method = 'POST'; $headers = [ 'Content-Type: application/json', 'Authorization:'. getenv('VIDAL_API_KEY').'', 'username:' . getenv('VIDAL_API_USERNAME').'', 'password:' . getenv('VIDAL_API_PASSWORD').'', 'policyNo:' .$postData['policyNo'] ?? '', 'startindex:' .$postData['startindex'] ?? '', 'endindex:' .$postData['endindex'] ?? '' ]; $body = [ ]; $response = call_third_party_api($url, $method, $headers, $body); if($response['status'] != true){ return $this->response->setJSON([ 'status' => false, 'message' => 'Token generation failed.', 'data' => $response ]); } return $this->response->setJSON($response); } }