nhance/app/Controllers/VidalApiController.php

368 lines
11 KiB
PHP

<?php
namespace App\Controllers;
use App\Controllers\BaseController;
use CodeIgniter\HTTP\ResponseInterface;
class VidalApiController extends BaseController
{
public function index()
{
//
}
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);
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);
}
}