GWM : get wellness changes

This commit is contained in:
Gowtham M 2025-12-11 18:23:01 +05:30
parent 053341b4a0
commit bf6c3ddce7
4 changed files with 269 additions and 258 deletions

View File

@ -276,76 +276,65 @@ class ApiServiceController extends BaseController
}
public function getWellnessUrl()
//wellness sso url generator landing
public function getWellnessUrl($emp_id)
{
$emp_id = $this->request->getGet('emp_id');
$client_policy_id = $this->request->getGet('client_policy_id');
// $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();
$data = $db->table('employee_polices ep')
$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, e.id as employeeId
cp.policy_no as policyNumber, 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')
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, ep.employee_id as employeeId, cp.policy_start_date as policyStartDate, cp.policy_end_date as policyEndDate , cp.wellness_plan_id as planId , cp.wellness_vendor_id')
->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('ep.employee_id', $emp_id)
->where('ep.client_policy_id', $client_policy_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()
->getRow();
->getResultArray();
$userParams = [];
if(!empty($data))
{
$userParams['name'] = $data->name;
$userParams['email'] = $data->email;
$userParams['phone'] = $data->phone;
$userParams['memberId'] = $data->employeeId; // memberId is unique primary key.
$userParams['gender'] = $data->gender;
$userParams['dob'] = $data->dob;
$userParams['relation'] = $data->relation;
$userParams['policyNumber'] = $data->policyNumber;
$userParams['employeeId'] = $data->memberId;
$userParams['policyStartDate']= $data->policyStartDate;
$userParams['policyEndDate'] = $data->policyEndDate;
$userParams['policyName'] = 'Nhance ' . $data->policy_type;
$userParams['planId'] = $data->planId;
$userParams['moduleName'] = 'home';
foreach ($data as $row) {
if($row['wellness_vendor_id'] != null)
{
$vidalApiController = new VidalApiController();
return $vidalApiController->getWellnessSSORedirectUrl($row['email']);
}
else if ($row['planId'] != null) // VISIT
{
$userParams['name'] = $row['name'];
$userParams['email'] = $row['email'];
$userParams['phone'] = $row['phone'];
$userParams['memberId'] = $row['employeeId']; // memberId is unique primary key.
$userParams['gender'] = $row['gender'];
$userParams['dob'] = $row['dob'];
$userParams['relation'] = $row['relation'];
$userParams['policyNumber'] = $row['policyNumber'];
$userParams['employeeId'] = $row['memberId'];
$userParams['policyStartDate']= $row['policyStartDate'];
$userParams['policyEndDate'] = $row['policyEndDate'];
$userParams['policyName'] = $row['policy_type'];
$userParams['planId'] = $row['planId'];
$userParams['moduleName'] = 'home';
break; // stop after first GMC match
}
}
// dd($userParams);
if (empty($userParams)) {
return $this->respond(['status' => 'failed','message' => 'Coming soon........!'], 200);
return ['status' => 'failed','message' => 'Coming soon........!'];
}
// 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) {
@ -359,153 +348,114 @@ class ApiServiceController extends BaseController
// 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);
return ['status' => 'success','data' => $finalUrl];
} else {
return $this->respond(['status' => 'failed','message' => 'Coming soon........!'], 200);
return ['status' => 'failed','message' => 'Coming soon........!'];
}
}
function getSSORedirectUrl($email = 'test@getvisitapp.com')
{
log_message('info', "SSO: Starting authentication for email: $email");
// ---------- CONFIG ----------
$authUrl = env('VIDAL_WELLNESS_BASE_URL');
$subscriptionKey = env('VIDAL_WELLNESS_SUBSCRIPTION_KEY');
$apiVersion = "1";
// Provided Base64 AES key
$base64Key = env('VIDAL_WELLNESS_BASE64_KEY');
$key = base64_decode($base64Key);
log_message('info', "SSO: Config loaded, Auth URL: $authUrl");
// ---------- STEP 1: Build plaintext payload ----------
$plainPayload = json_encode([
"email" => $email,
// "corporateId" => env('VIDAL_WELLNESS_CORPORATE_ID'),
"urlIdentifier" => env('VIDAL_WELLNESS_URL_IDENTIFIER')
]);
// public function getWellnessUrl()
// {
// ---------- STEP 2: Encrypt payload ----------
$iv = random_bytes(16);
$encryptedRaw = openssl_encrypt($plainPayload, "AES-256-CBC", $key, OPENSSL_RAW_DATA, $iv);
// $emp_id = $this->request->getGet('emp_id');
// $client_policy_id = $this->request->getGet('client_policy_id');
$encryptedPayload = base64_encode($iv) . ":" . base64_encode($encryptedRaw);
log_message('info', "SSO: Payload encrypted successfully");
// $db = \Config\Database::connect();
// ---------- STEP 3: Call Authentication API ----------
$requestBody = json_encode([
"payload" => $encryptedPayload,
"source" => env('VIDAL_WELLNESS_SUB_PARTNER_ID'),
"subPartnerId" => env('VIDAL_WELLNESS_SUB_PARTNER_ID')
]);
// // $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();
$headers = [
"Ocp-Apim-Subscription-Key: $subscriptionKey",
"apiver: $apiVersion",
"mode: encrypt",
"Content-Type: application/json"
];
// $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, e.id as employeeId
// cp.policy_no as policyNumber, 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();
$ch = curl_init($authUrl);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $requestBody);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// $userParams = [];
// if(!empty($data))
// {
// $userParams['name'] = $data->name;
// $userParams['email'] = $data->email;
// $userParams['phone'] = $data->phone;
// $userParams['memberId'] = $data->employeeId; // memberId is unique primary key.
// $userParams['gender'] = $data->gender;
// $userParams['dob'] = $data->dob;
// $userParams['relation'] = $data->relation;
// $userParams['policyNumber'] = $data->policyNumber;
// $userParams['employeeId'] = $data->memberId;
// $userParams['policyStartDate']= $data->policyStartDate;
// $userParams['policyEndDate'] = $data->policyEndDate;
// $userParams['policyName'] = 'Nhance ' . $data->policy_type;
// $userParams['planId'] = $data->planId;
// $userParams['moduleName'] = 'home';
$apiResponse = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$curlError = curl_error($ch);
curl_close($ch);
log_message('info', "SSO: API response received, HTTP Code: $httpCode");
// }
// // dd($userParams);
// Check for cURL errors
if ($curlError) {
log_message('error', "SSO: cURL error - $curlError");
return ["error" => "cURL error: $curlError"];
}
// if (empty($userParams)) {
// return $this->respond(['status' => 'failed','message' => 'Coming soon........!'], 200);
// }
// Check HTTP status
if ($httpCode !== 200) {
log_message('error', "SSO: HTTP error - Code: $httpCode, Response: $apiResponse");
return ["error" => "HTTP error: $httpCode", "response" => $apiResponse];
}
// // Derive 32-byte key from SHA256
// $derivedKey = hash('sha256', env('VISIT_SECRET_KEY'), true);
$jsonResponse = json_decode($apiResponse, true);
// Check JSON decode error
if (json_last_error() !== JSON_ERROR_NONE) {
log_message('error', "SSO: JSON decode error - " . json_last_error_msg());
return ["error" => "JSON decode error: " . json_last_error_msg(), "response" => $apiResponse];
}
// Check API response status
if (!isset($jsonResponse["status"]) || $jsonResponse["status"] !== "success") {
log_message('error', "SSO: API error - " . json_encode($jsonResponse));
return ["error" => "API error", "response" => $jsonResponse];
}
if (!isset($jsonResponse["data"])) {
log_message('error', "SSO: Missing data field in response");
return ["error" => "Invalid API response - missing data field", "response" => $jsonResponse];
}
log_message('info', "SSO: API response validated successfully");
// ---------- STEP 4: Decrypt response ----------
log_message('info', "SSO: Starting response decryption");
$dataParts = explode(":", $jsonResponse["data"]);
if (count($dataParts) !== 2) {
log_message('error', "SSO: Invalid encrypted data format");
return ["error" => "Invalid encrypted data format", "data" => $jsonResponse["data"]];
}
list($ivBase64, $cipherBase64) = $dataParts;
$respIv = base64_decode($ivBase64);
$respCipher = base64_decode($cipherBase64);
if ($respIv === false || $respCipher === false) {
log_message('error', "SSO: Base64 decode error");
return ["error" => "Base64 decode error"];
}
$decryptedJson = openssl_decrypt($respCipher, "AES-256-CBC", $key, OPENSSL_RAW_DATA, $respIv);
if ($decryptedJson === false) {
log_message('error', "SSO: Decryption failed");
return ["error" => "Decryption failed"];
}
$decryptedData = json_decode($decryptedJson, true);
if (json_last_error() !== JSON_ERROR_NONE) {
log_message('error', "SSO: Decrypted JSON decode error - " . json_last_error_msg());
return ["error" => "Decrypted JSON decode error: " . json_last_error_msg()];
}
if (!isset($decryptedData["redirectUrl"])) {
log_message('error', "SSO: redirectUrl missing in decrypted data");
return ["error" => "redirectUrl missing", "decrypted" => $decryptedData];
}
// ---------- FINAL ----------
log_message('info', "SSO: Authentication successful, redirectUrl obtained");
return $decryptedData["redirectUrl"];
}
// // 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);
// }
// }
// function getSSORedirectUrl($email = 'user@example.com')

View File

@ -3028,7 +3028,8 @@ class EmployeeRestController extends AdminController
}
$emp_reatail_policy_data = $this->getEmpRetailPolicy($employeeSelfData);
$emp_wellness_data = $this->getWellnessUrl($employeeSelfData->id ?? null);
$apiServiceController = new ApiServiceController;
$emp_wellness_data = $apiServiceController->getWellnessUrl($employeeSelfData->id ?? null);
return $this->respond(['status' => 'success', 'code' => 200, 'data' => $result, 'emp_name' => $employeeName, 'pre_policy_count' => $prePolicyCount, 'emp_not_enrolled_count' => $empNotEnrolledCount, 'retail_policy_data' => $emp_reatail_policy_data, 'wellness_data' => $emp_wellness_data], 200);
} else {
@ -5012,81 +5013,7 @@ class EmployeeRestController extends AdminController
}
}
public function getWellnessUrl($emp_id)
{
// $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, ep.employee_id as employeeId, cp.policy_start_date as policyStartDate, cp.policy_end_date as policyEndDate , cp.wellness_plan_id as planId')
->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();
$userParams = [];
foreach ($data as $row) {
if ($row['planId'] != null) {
$userParams['name'] = $row['name'];
$userParams['email'] = $row['email'];
$userParams['phone'] = $row['phone'];
$userParams['memberId'] = $row['employeeId']; // memberId is unique primary key.
$userParams['gender'] = $row['gender'];
$userParams['dob'] = $row['dob'];
$userParams['relation'] = $row['relation'];
$userParams['policyNumber'] = $row['policyNumber'];
$userParams['employeeId'] = $row['memberId'];
$userParams['policyStartDate']= $row['policyStartDate'];
$userParams['policyEndDate'] = $row['policyEndDate'];
$userParams['policyName'] = $row['policy_type'];
$userParams['planId'] = $row['planId'];
$userParams['moduleName'] = 'home';
break; // stop after first GMC match
}
}
if (empty($userParams)) {
return ['status' => 'failed','message' => 'Coming soon........!'];
}
// 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 ['status' => 'success','data' => $finalUrl];
} else {
return ['status' => 'failed','message' => 'Coming soon........!'];
}
}
public function getPolicyTypeAndInsurer()
{

View File

@ -632,10 +632,10 @@ class MediAssistApiController extends BaseController
if (!$ticket || empty($ticket['ClaimID'])) {
log_message('error', "IRSubmission FAILED → ClaimID NOT FOUND for ticket_id={$claimId}");
return $this->response->setJSON([
'status' => false,
'message' => "ClaimID not found for ticket {$claimId}"
]);
return [
'status' => false,
'message' => "ClaimID not found for ticket {$claimId}"
];
}
// 2. FETCH IR ATTACHMENTS

View File

@ -266,6 +266,140 @@ class VidalApiController extends BaseController
}
}
function getWellnessSSORedirectUrl($email = 'test@getvisitapp.com')
{
log_message('info', "SSO: Starting authentication for email: $email");
// ---------- CONFIG ----------
$authUrl = env('VIDAL_WELLNESS_BASE_URL');
$subscriptionKey = env('VIDAL_WELLNESS_SUBSCRIPTION_KEY');
$apiVersion = "1";
// Provided Base64 AES key
$base64Key = env('VIDAL_WELLNESS_BASE64_KEY');
$key = base64_decode($base64Key);
log_message('info', "SSO: Config loaded, Auth URL: $authUrl");
// ---------- STEP 1: Build plaintext payload ----------
$plainPayload = json_encode([
"email" => $email,
// "corporateId" => env('VIDAL_WELLNESS_CORPORATE_ID'),
"urlIdentifier" => env('VIDAL_WELLNESS_URL_IDENTIFIER')
]);
// ---------- STEP 2: Encrypt payload ----------
$iv = random_bytes(16);
$encryptedRaw = openssl_encrypt($plainPayload, "AES-256-CBC", $key, OPENSSL_RAW_DATA, $iv);
$encryptedPayload = base64_encode($iv) . ":" . base64_encode($encryptedRaw);
log_message('info', "SSO: Payload encrypted successfully");
// ---------- STEP 3: Call Authentication API ----------
$requestBody = json_encode([
"payload" => $encryptedPayload,
"source" => env('VIDAL_WELLNESS_SUB_PARTNER_ID'),
"subPartnerId" => env('VIDAL_WELLNESS_SUB_PARTNER_ID')
]);
$headers = [
"Ocp-Apim-Subscription-Key: $subscriptionKey",
"apiver: $apiVersion",
"mode: encrypt",
"Content-Type: application/json"
];
$ch = curl_init($authUrl);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $requestBody);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$apiResponse = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$curlError = curl_error($ch);
curl_close($ch);
log_message('info', "SSO: API response received, HTTP Code: $httpCode");
// Check for cURL errors
if ($curlError) {
log_message('error', "SSO: cURL error - $curlError");
return ['status' => 'failed','message' => $curlError];
}
// Check HTTP status
if ($httpCode !== 200) {
log_message('error', "SSO: HTTP error - Code: $httpCode, Response: $apiResponse");
return ['status' => 'failed','message' => "HTTP error: $httpCode" , "response" => $apiResponse ];
}
$jsonResponse = json_decode($apiResponse, true);
// Check JSON decode error
if (json_last_error() !== JSON_ERROR_NONE) {
log_message('error', "SSO: JSON decode error - " . json_last_error_msg());
return ['status' => 'failed','message' => "JSON decode error: " . json_last_error_msg(), "response" => $apiResponse];
}
// Check API response status
if (!isset($jsonResponse["status"]) || $jsonResponse["status"] !== "success") {
log_message('error', "SSO: API error - " . json_encode($jsonResponse));
return ['status' => 'failed','message' => "API error", "response" => $jsonResponse];
}
if (!isset($jsonResponse["data"])) {
log_message('error', "SSO: Missing data field in response");
return ['status' => 'failed','message' => "Invalid API response - missing data field", "response" => $jsonResponse];
}
log_message('info', "SSO: API response validated successfully");
// ---------- STEP 4: Decrypt response ----------
log_message('info', "SSO: Starting response decryption");
$dataParts = explode(":", $jsonResponse["data"]);
if (count($dataParts) !== 2) {
log_message('error', "SSO: Invalid encrypted data format");
return ['status' => 'failed','message' => "Invalid encrypted data format", "data" => $jsonResponse["data"]];
}
list($ivBase64, $cipherBase64) = $dataParts;
$respIv = base64_decode($ivBase64);
$respCipher = base64_decode($cipherBase64);
if ($respIv === false || $respCipher === false) {
log_message('error', "SSO: Base64 decode error");
return ['status' => 'failed','message' => "Base64 decode error"];
}
$decryptedJson = openssl_decrypt($respCipher, "AES-256-CBC", $key, OPENSSL_RAW_DATA, $respIv);
if ($decryptedJson === false) {
log_message('error', "SSO: Decryption failed");
return ['status' => 'failed','message' => "Decryption failed"];
}
$decryptedData = json_decode($decryptedJson, true);
if (json_last_error() !== JSON_ERROR_NONE) {
log_message('error', "SSO: Decrypted JSON decode error - " . json_last_error_msg());
return ['status' => 'failed','message' => "Decrypted JSON decode error: " . json_last_error_msg()];
}
if (!isset($decryptedData["redirectUrl"])) {
log_message('error', "SSO: redirectUrl missing in decrypted data");
return ['status' => 'failed','message' => "redirectUrl missing", "decrypted" => $decryptedData];
}
// ---------- FINAL ----------
log_message('info', "SSO: Authentication successful, redirectUrl obtained");
return ['status' => 'success','data' => $decryptedData["redirectUrl"]];
}
//----------yet to start only submit claim given