diff --git a/app/Config/Routes.php b/app/Config/Routes.php index ad1d3874..953375e6 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -554,6 +554,8 @@ $routes->group("employeeRest", ["filter" => "authJWT"], function ($routes) { $routes->post("ecardRequest", "ApiServiceController::ecardRequest"); + $routes->get("getWellnessURL", "ApiServiceController::getWellnessURL"); + $routes->post("logHrActivity", "RestAuthenticationController::logHrActivity"); $routes->post("getVerifiedUserData", "RestAuthenticationController::getVerifiedUserData"); @@ -589,7 +591,7 @@ $routes->group("employeeRest", ["filter" => "authJWT"], function ($routes) { $routes->get("getEmployeeActiveOrInactivePolicy", "EmployeeRestController::getEmployeeActiveOrInactivePolicy"); $routes->get("getFEContent", "EmployeeRestController::getFEContent"); $routes->get("getAdvertisementImage", "EmployeeRestController::getAdvertisementImage"); - $routes->get("getWellnessURL", "EmployeeRestController::getWellnessURL"); + $routes->get("getEcardURL", "EmployeeRestController::getEcardURL"); //$routes->post('postDataForTicket',"EmployeeRestController::postDataForTicket"); @@ -700,12 +702,14 @@ $routes->get('getEnrollmentBatchStatus','ICICILombardController::getEnrollmentBa $routes->get('fetchUHIDDetails','ICICILombardController::fetchUHIDDetails'); //Third party Vidal Api Call - +$routes->get('fileUpload','VidalApiController::fileUpload'); $routes->post('hospitalNetwork','VidalApiController::hospitalNetwork'); $routes->post('eCardService','VidalApiController::eCardService'); $routes->post('claimStatusCheck','VidalApiController::claimStatusCheck'); -$routes->post('newClaim','VidalApiController::newClaim'); +$routes->get('newClaim','VidalApiController::SubmitClaim'); $routes->post('enrollment','VidalApiController::enrollment'); +$routes->get('fileUploadToVidal','VidalApiController::fileUploadToVidal'); +$routes->get('claimStatus','VidalApiController::claimStatus'); //Third party MediAssist Api Call diff --git a/app/Controllers/ApiServiceController.php b/app/Controllers/ApiServiceController.php index 5b32cec1..ad6a114c 100644 --- a/app/Controllers/ApiServiceController.php +++ b/app/Controllers/ApiServiceController.php @@ -213,6 +213,101 @@ class ApiServiceController extends BaseController } + public function getWellnessUrl() + { + + $emp_id = $this->request->getGet('emp_id'); + $client_policy_id = $this->request->getGet('client_policy_id'); + + $db = \Config\Database::connect(); + + // $data = $db->table('employees e') + // ->select('pt.policy_type, + // e.name, e.email_corporate as email, e.mobile as phone, e.emp_code as memberId, e.gender, e.dob, e.relationship as relation, + // cp.policy_no as policyNumber, cp.policy_no as employeeId, cp.policy_start_date as policyStartDate, cp.policy_end_date as policyEndDate') + // ->join('employee_polices ep', 'e.id = ep.employee_id') + // ->join('client_policy cp', 'ep.client_policy_id = cp.id') + // ->join('policy_type pt', 'cp.policy_type_id = pt.id') + // ->where('e.id', $emp_id) + // ->where('e.emp_status', 'active') + // ->where('ep.status', 'active') + // ->where('e.is_active', 1) + // ->where('ep.is_active', 1) + // ->get() + // ->getResultArray(); + + $data = $db->table('employee_polices ep') + ->select('pt.policy_type, + e.name, e.email_corporate as email, e.mobile as phone, e.emp_code as memberId, e.gender, e.dob, e.relationship as relation, + cp.policy_no as policyNumber, cp.policy_no as employeeId, cp.policy_start_date as policyStartDate, cp.policy_end_date as policyEndDate, cp.wellness_plan_id as planId') + ->join('employees e', 'e.id = ep.employee_id') + ->join('client_policy cp', 'ep.client_policy_id = cp.id') + ->join('policy_type pt', 'cp.policy_type_id = pt.id') + ->where('ep.employee_id', $emp_id) + ->where('ep.client_policy_id', $client_policy_id) + ->where('ep.status', 'active') + ->where('ep.is_active', 1) + ->get() + ->getRow(); + + + + $userParams = []; + if(!empty($data)) + { + $userParams['name'] = $data->name; + $userParams['email'] = $data->email; + $userParams['phone'] = $data->phone; + $userParams['memberId'] = $data->memberId; + $userParams['gender'] = $data->gender; + $userParams['dob'] = $data->dob; + $userParams['relation'] = $data->relation; + $userParams['policyNumber'] = $data->policyNumber; + $userParams['employeeId'] = $data->employeeId; + $userParams['policyStartDate']= $data->policyStartDate; + $userParams['policyEndDate'] = $data->policyEndDate; + $userParams['policyName'] = 'Nhance ' . $data->policy_type; + $userParams['planId'] = $data->planId; + $userParams['moduleName'] = 'home'; + + } + + // dd($userParams); + + if (empty($userParams)) { + return $this->respond(['status' => 'failed','message' => 'Coming soon........!'], 200); + } + + // Derive 32-byte key from SHA256 + $derivedKey = hash('sha256', env('VISIT_SECRET_KEY'), true); + + // Build query string like Node.js + $plainText = ''; + foreach ($userParams as $k => $v) { + $plainText .= "&{$k}={$v}"; + } + $plainText = ltrim($plainText, '&'); + + // Encrypt + $algorithm = "aes-256-cbc"; + $encrypted = openssl_encrypt($plainText, $algorithm, $derivedKey, OPENSSL_RAW_DATA, env('VISIT_IV')); + + // Base64URL encode (same as Node.js output) + $output = rtrim(strtr(base64_encode($encrypted), '+/', '-_'), '='); + + $baseURL = env('VISIT_BASE_URL'); + $clientId = env('VISIT_CLIENT_ID'); + $finalUrl = $baseURL . '/sso?userParams=' . $output . '&clientId=' . $clientId; + + if (!empty($finalUrl)) { + log_message('error', 'VISIT SSO | emp_id: '.$emp_id.' | URL: '.$finalUrl); + return $this->respond(['status' => 'success','data' => $finalUrl], 200); + } else { + return $this->respond(['status' => 'failed','message' => 'Coming soon........!'], 200); + } + } + + diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index e0ea1eb5..afaa2e1c 100755 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -3874,90 +3874,6 @@ class EmployeeRestController extends AdminController return $this->response->setJSON(['ticket_data' => $ticket_data])->setStatusCode(200); } - public function getWellnessUrl() - { - - $emp_id = $this->request->getGet('emp_id'); - - $db = \Config\Database::connect(); - $data = $db->table('employees e') - ->select('pt.policy_type, - e.name, e.email_corporate as email, e.mobile as phone, e.emp_code as memberId, e.gender, e.dob, e.relationship as relation, - cp.policy_no as policyNumber, cp.policy_no as employeeId, cp.policy_start_date as policyStartDate, cp.policy_end_date as policyEndDate') - ->join('employee_polices ep', 'e.id = ep.employee_id') - ->join('client_policy cp', 'ep.client_policy_id = cp.id') - ->join('policy_type pt', 'cp.policy_type_id = pt.id') - ->where('e.id', $emp_id) - ->where('e.emp_status', 'active') - ->where('ep.status', 'active') - ->where('e.is_active', 1) - ->where('ep.is_active', 1) - ->get() - ->getResultArray(); - - // print_r($db->getLastQuery());die(); - // print_r($data);die(); - // Loop through $data and check for policy_type = GMC - $userParams = []; - foreach ($data as $row) { - // if ($row['policy_type'] === 'GMC') { - $userParams['name'] = $row['name']; - $userParams['email'] = $row['email']; - $userParams['phone'] = $row['phone']; - $userParams['memberId'] = $row['memberId']; - $userParams['gender'] = $row['gender']; - $userParams['dob'] = $row['dob']; - $userParams['relation'] = $row['relation']; - $userParams['policyNumber'] = $row['policyNumber']; - $userParams['employeeId'] = $row['employeeId']; - $userParams['policyStartDate']= $row['policyStartDate']; - $userParams['policyEndDate'] = $row['policyEndDate']; - // $userParams['policyName'] = 'Nhance ' . $row['policy_type']; - // $userParams['planId'] = 'NHANCE-PLAN-' . $row['policy_type']; - $userParams['policyName'] = $row['policy_type']; - $userParams['planId'] = env('VISIT_PLAN_ID'); - - $userParams['moduleName'] = 'home'; - break; // stop after first GMC match - // } - } - - if (empty($userParams)) { - return $this->respond(['status' => 'failed','message' => 'Coming soon........!'], 200); - } - - // echo 'coming';die(); - // Derive 32-byte key from SHA256 - $derivedKey = hash('sha256', env('VISIT_SECRET_KEY'), true); - - // Build query string like Node.js - $plainText = ''; - foreach ($userParams as $k => $v) { - $plainText .= "&{$k}={$v}"; - } - $plainText = ltrim($plainText, '&'); - - // Encrypt - $algorithm = "aes-256-cbc"; - $encrypted = openssl_encrypt($plainText, $algorithm, $derivedKey, OPENSSL_RAW_DATA, env('VISIT_IV')); - - // Base64URL encode (same as Node.js output) - $output = rtrim(strtr(base64_encode($encrypted), '+/', '-_'), '='); - - $baseURL = env('VISIT_BASE_URL'); - $clientId = env('VISIT_CLIENT_ID'); - $finalUrl = $baseURL . '/sso?userParams=' . $output . '&clientId=' . $clientId; - - if (!empty($finalUrl)) { - log_message('error', 'VISIT SSO | emp_id: '.$emp_id.' | URL: '.$finalUrl); - return $this->respond(['status' => 'success','data' => $finalUrl], 200); - } else { - return $this->respond(['status' => 'failed','message' => 'Coming soon........!'], 200); - } - } - - - // not in use did for testing function encrypt_for_sso(): string { diff --git a/app/Controllers/VidalApiController.php b/app/Controllers/VidalApiController.php index b7418dbf..3a6e8b56 100644 --- a/app/Controllers/VidalApiController.php +++ b/app/Controllers/VidalApiController.php @@ -12,6 +12,209 @@ class VidalApiController extends BaseController // } + + function fileUploadToVidal() + { + $apiUrl = "https://devapigw.vidalhealthtpa.com/partner-integration/api/files/upload-url"; + $subscriptionKey = getenv('VIDAL_API_SUBSCRIPTION_KEY'); + + // Step 1: Get signed URL from Vidal API + $filePath = '/opt/lampp/htdocs/nhance/writable/uploads/claim_files/1760013019_73d94af7b96ddc2e3d51.png'; + $payload = json_encode(["scope" => 'document type' , 'fileName' => '1760013019_73d94af7b96ddc2e3d51.png']); + $headers = [ + "Content-Type: application/json", + "Ocp-Apim-Subscription-Key: $subscriptionKey" + ]; + + $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)) { + die("Curl error while requesting signed URL: " . curl_error($ch)); + } + curl_close($ch); + + $responseData = json_decode($response, true); + + if (!isset($responseData['data']['signedUrl'])) { + die("Failed to get signed URL. Response: " . $response); + } + + $signedUrl = $responseData['data']['signedUrl']; + $fileId = $responseData['data']['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); + if (curl_errno($ch2)) { + die("Curl error while uploading file: " . curl_error($ch2)); + } + fclose($fileContent); + curl_close($ch2); + + if ($httpCode !== 201 && $httpCode !== 200) { + die("File upload failed. HTTP Code: $httpCode\nResponse: $uploadResponse"); + } + + // Step 3: Return File ID for reference + return $this->response->setJSON( [ + "status" => true, + "message" => "File uploaded successfully", + "fileId" => $fileId, + "signedUrl" => $signedUrl, + "uploadResponse" => json_decode($uploadResponse, true) + ]); + } + + 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 SubmitClaim ($claimId = null) + { + helper('api'); + + $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' => "351500/D0534/PP/20-20/PC", + 'enrollmentId' => "BLR-NC-D0534-004-0000033-A", + 'typeOfClaim' => "Main hospitalization claim", + 'claimSubType' => "Hospitalization", + 'requestedAmount' => "3500", + 'ailmentType' => "Non covid", + 'admissionDate' => "20-07-2023", + 'dischargeDate' => "23-07-2023", + 'hospitalName' => "DELL HOSPITAL PVT LTD", + 'empanelmentNo' => "HOS-BLR-021280", + 'documentType' => "Claim", + 'ailmentName' => "Cold", + 'hospitalAddress' => "abc", + 'hospitalState' => "karnataka", + 'hospitalCity' => "bangalore", + 'hospitalPinCode' => "560036", + 'hospitalPhoneNo' => "7656879899", + 'fileId' => "https://devapigw.vidalhealthtpa.com/doc-storage/api/private/69130dfad1414b35a775480f", + ]; + + + + $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 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); @@ -123,74 +326,6 @@ class VidalApiController extends BaseController } - public function newClaim() - { - $postData = $this->request->getPost(); - - if (empty($postData)) { - return $this->response->setJSON([ - 'status' => false, - 'message' => 'Empty Data Given.', - 'data' => $postData - ]); - } - - helper('api'); - - $url = getenv('VIDAL_API_BASE_URL') . '/submitClaim'; - $method = 'POST'; - - $headers = [ - 'Content-Type: multipart/form-data', - 'Authorization:' .getenv('VIDAL_API_KEY').'', - ]; - - $body = [ - 'username' => getenv('VIDAL_API_USERNAME'), - 'password' => getenv('VIDAL_API_PASSWORD'), - 'policyNo' => $postData['policyNo'] ?? '', - 'enrollmentId' => $postData['enrollmentId'] ?? '', - 'typeOfClaim' => $postData['typeOfClaim'] ?? '', - 'claimSubType' => $postData['claimSubType'] ?? '', - 'requestedAmount' => $postData['requestedAmount'] ?? '', - 'ailmentType' => $postData['ailmentType'] ?? '', - 'admissionDate' => $postData['admissionDate'] ?? '', - 'dischargeDate' => $postData['dischargeDate'] ?? '', - 'hospitalName' => $postData['hospitalName'] ?? '', - 'empanelmentNo' => $postData['empanelmentNo'] ?? '', - 'documentType' => $postData['documentType'] ?? '', - 'ailmentName' => $postData['ailmentName'] ?? '', - 'hospitalAddress' => $postData['hospitalAddress'] ?? '', - 'hospitalState' => $postData['hospitalState'] ?? '', - 'hospitalCity' => $postData['hospitalCity'] ?? '', - 'hospitalPinCode' => $postData['hospitalPinCode'] ?? '', - 'hospitalPhoneNo' => $postData['hospitalPhoneNo'] ?? '', - ]; - - // ✅ Handle file upload - if ($file = $this->request->getFile('File')) { - if ($file->isValid() && !$file->hasMoved()) { - $filePath = $file->getTempName(); - $originalName = $file->getClientName(); - $mimeType = $file->getMimeType(); - - $body['File'] = new \CURLFile($filePath, $mimeType, $originalName); - } - } - - $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() {