diff --git a/app/Controllers/ICICILombardController.php b/app/Controllers/ICICILombardController.php index 3e38230f..8bf81189 100644 --- a/app/Controllers/ICICILombardController.php +++ b/app/Controllers/ICICILombardController.php @@ -4,6 +4,8 @@ namespace App\Controllers; use CodeIgniter\Controller; use Kint; +use Ramsey\Uuid\Uuid; + class ICICILombardController extends AdminController { @@ -40,7 +42,12 @@ class ICICILombardController extends AdminController public function createEnrollmentBatch() { - helper('api'); + + + $client_id = $this->request->getGet('client_id'); + $client_branch_id = $this->request->getGet('client_branch_id'); + $policy_id = $this->request->getGet('policy_id'); + $event = $this->request->getGet('event'); //fetch token $tokenResponse = $this->generateAuthToken(); @@ -52,58 +59,35 @@ class ICICILombardController extends AdminController ]); } $token = $tokenResponse['data']['access_token']; - // dd($token); + $url = 'https://ilesbapigee.insurancearticlez.com/health/ilservices/health/v1/enrollment/batchcreation'; $headers = [ 'Authorization: Bearer ' . $token, 'Content-Type: application/json', - //'Scope: esbgpabatchcreation' ]; - #old policy info start - #"PolicyNumber" => "4016/A/51974976/00/000", - # "CDBGAccountNumber" => "CD-MUM-3344", - #"CorrelationId" => "86383c78-4c67-4e4d-9aa0-8f926fb0d55f", - #old policy inf end - #"EmployeeMemberId" => "EMPID3625556", + //Prepare body data + $db = \Config\Database::connect(); + $data = $db->table('employee_polices ep') + ->select('cp.policy_no as policyNumber, + e.id,e.emp_code as MemberEmpId, e.doj as DOJ, e.name as InsuredName, e.dob as DOB, e.relationship as Relationship, + e.gender as Gender, ep.date_coverage as DOC,ep.basic_cover_si as SumInsured, e.email_corporate as EmailId + ') + ->join('employees e', 'e.id = ep.employee_id') + ->join('client_policy cp', 'ep.client_policy_id = cp.id') + ->where('ep.client_policy_id', $policy_id) + ->where('ep.status', 'active') + ->where('ep.is_active', 1) + // ->where('ep.uhid', null) + ->get() + ->getResultArray(); + + $body = $this->formatPolicyData($data); + dd($body); - $body = [ - "PolicyNumber" => "4016/A/O/53077718/00/000", - "CDBGAccountNumber" => "CD-MUM-0026", - "CorrelationId" => "550e8400-e29b-41d4-a716-446655440001", - "MemberDetails" => [ - [ - "MemberEmpId" => "EMPID3625557", - "DOJ" => "21-MAR-2019", - "InsuredName" => "Kumar", - "DOB" => "7-JUL-1983", - "Relationship" => "SELF", - "Gender" => "MALE", - "DOC" => "08-JUL-2025", - "SumInsured" => "400000", - "EmailId" => "KUMAR@GMAIL.COM", - "FlagStatus" => "A" - ], - [ - "MemberEmpId" => "EMPID3625557", - "DOJ" => "21-MAR-2019", - "InsuredName" => "Saranya", - "DOB" => "8-AUG-1970", - "Relationship" => "MOTHER", - "Gender" => "FEMALE", - "DOC" => "08-JUL-2025", - "SumInsured" => "400000", - "EmailId" => "Saranya@GMAIL.COM", - "FlagStatus" => "A" - ], - ] - ]; - // Kint::dump($body); - // print_rr(json_encode($body)); - // dd(); - $response = call_third_party_api($url, 'POST', $headers, ($body),true); // true = raw body mode + $response = call_third_party_api($url, 'POST', $headers, $body, true); // true = raw body mode // print_rr(json_encode($response));die(); return $this->response->setJSON($response); } @@ -178,5 +162,105 @@ class ICICILombardController extends AdminController } + public function formatPolicyData($data) + { + // Helper to format date + $formatDate = function ($date) { + return strtoupper(date('j-M-Y', strtotime($date))); // Example: 7-JUL-1983 + }; + + // Generate UUID v4 for CorrelationId + $generateUUID = function () { + return sprintf( + '%04x%04x-%04x-%04x-%04x-%04x%04x%04x', + mt_rand(0, 0xffff), + mt_rand(0, 0xffff), + mt_rand(0, 0xffff), + mt_rand(0, 0x0fff) | 0x4000, + mt_rand(0, 0x3fff) | 0x8000, + mt_rand(0, 0xffff), + mt_rand(0, 0xffff), + mt_rand(0, 0xffff) + ); + }; + + // Map MemberDetails + $memberDetails = array_map(function ($row) use ($formatDate) { + return [ + "MemberEmpId" => $row['MemberEmpId'], + "DOJ" => $formatDate($row['DOJ']), + "InsuredName" => $row['InsuredName'], + "DOB" => $formatDate($row['DOB']), + "Relationship" => strtoupper($row['Relationship']), + "Gender" => strtoupper($row['Gender']), + "DOC" => $formatDate($row['DOC']), + "SumInsured" => $row['SumInsured'], + "EmailId" => $row['EmailId'], + "FlagStatus" => "A" // fixed value + ]; + }, $data); + + // Final body + return [ + "PolicyNumber" => $data[0]['policyNumber'] ?? null, + "CDBGAccountNumber" => "CD-MUM-0026", + "CorrelationId" => $generateUUID(), + "MemberDetails" => $memberDetails + ]; + } + + + + + + + + + + + + + + + + + + + + + + + // $body = [ + // "PolicyNumber" => "4016/A/O/53077718/00/000", + // "CDBGAccountNumber" => "CD-MUM-0026", + // "CorrelationId" => "550e8400-e29b-41d4-a716-446655440001", + // "MemberDetails" => [ + // [ + // "MemberEmpId" => "EMPID3625557", + // "DOJ" => "21-MAR-2019", + // "InsuredName" => "Kumar", + // "DOB" => "7-JUL-1983", + // "Relationship" => "SELF", + // "Gender" => "MALE", + // "DOC" => "08-JUL-2025", + // "SumInsured" => "400000", + // "EmailId" => "KUMAR@GMAIL.COM", + // "FlagStatus" => "A" + // ], + // [ + // "MemberEmpId" => "EMPID3625557", + // "DOJ" => "21-MAR-2019", + // "InsuredName" => "Saranya", + // "DOB" => "8-AUG-1970", + // "Relationship" => "MOTHER", + // "Gender" => "FEMALE", + // "DOC" => "08-JUL-2025", + // "SumInsured" => "400000", + // "EmailId" => "Saranya@GMAIL.COM", + // "FlagStatus" => "A" + // ], + // ] + // ]; + } diff --git a/app/Controllers/VidalApiController.php b/app/Controllers/VidalApiController.php index 36dc3f01..54ffba09 100644 --- a/app/Controllers/VidalApiController.php +++ b/app/Controllers/VidalApiController.php @@ -145,7 +145,7 @@ class VidalApiController extends BaseController 'Authorization:' .getenv('VIDAL_API_KEY').'', ]; - $body = [ + $body = [ 'username' => getenv('VIDAL_API_USERNAME'), 'password' => getenv('VIDAL_API_PASSWORD'), 'policyNo' => $postData['policyNo'] ?? '', @@ -191,9 +191,8 @@ class VidalApiController extends BaseController return $this->response->setJSON($response); } - - - public function enrollment(){ + public function enrollment() + { $postData = $this->request->getJSON(true);