266 lines
8.1 KiB
PHP
266 lines
8.1 KiB
PHP
<?php
|
|
|
|
namespace App\Controllers;
|
|
|
|
use CodeIgniter\API\ResponseTrait;
|
|
|
|
|
|
use App\Models\EmployeePolicyModel;
|
|
|
|
|
|
use App\Controllers\BaseController;
|
|
use App\Controllers\VidalApiController;
|
|
use App\Controllers\ICICILombardController;
|
|
use App\Controllers\MediAssistApiController;
|
|
use App\Models\FileModel;
|
|
|
|
class ApiServiceController extends BaseController
|
|
{
|
|
use ResponseTrait;
|
|
// protected $format = 'json';
|
|
protected $db;
|
|
protected $employeePolicyModel;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->db = \Config\Database::connect();
|
|
$this->employeePolicyModel = new EmployeePolicyModel();
|
|
}
|
|
|
|
// Push Claims
|
|
public function pushClaims($claimId)
|
|
{
|
|
|
|
$data = $this->db->table('ticket_master tm')
|
|
->select('tm.id,tm.tpa_id ')->where('tm.id', $claimId)->get()->getRowArray(); // single record
|
|
|
|
if($data){
|
|
|
|
$tpaID = $data['tpa_id'];
|
|
|
|
if ($tpaID == 2) { // MediAssist
|
|
$mediAssistController = new MediAssistApiController();
|
|
return $mediAssistController->SubmitClaim($claimId);
|
|
}else{
|
|
log_message('error', "This ticket id ( {$claimId} ) TPA has no API service enabled. TPA ID : {$tpaID}");
|
|
}
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
// E-Card Request
|
|
public function ecardRequest($params = [], $return_type = 'api')
|
|
{
|
|
try{
|
|
|
|
if(empty($params) && $this->response){
|
|
|
|
$payload = $this->request->getJSON(true);
|
|
$id = $payload['id'] ?? null;
|
|
$emp_code = $payload['emp_code'] ?? null;
|
|
$client_policy_id = $payload['client_policy_id'] ?? null;
|
|
$policy_no = $payload['policy_no'] ?? null;
|
|
$type = $payload['type'] ?? 'download';
|
|
log_message('error', 'Received Payload API : '. json_encode($payload ?? ""));
|
|
|
|
}else{
|
|
|
|
$id = $params['id'] ?? null;
|
|
$emp_code = $params['emp_code'] ?? null;
|
|
$client_policy_id = $params['client_policy_id'] ?? null;
|
|
$policy_no = $params['policy_no'] ?? null;
|
|
$type = $params['type'] ?? 'download';
|
|
|
|
log_message('error', 'Received Payload INTERNAL : '. json_encode($params ?? ""));
|
|
|
|
}
|
|
|
|
$employee_policy = $this->employeePolicyModel
|
|
->select('employees.*, employee_polices.tpa_id , employee_polices.rand_string , employee_polices.uhid as uhid , client_policy.tpa_id as tpa_primary_id ')
|
|
->join('employees', 'employee_polices.employee_id = employees.id', 'left')
|
|
->join('client_policy', 'employee_polices.client_policy_id = client_policy.id', 'left')
|
|
->where('employee_polices.employee_id',$id)
|
|
->where('employee_polices.client_policy_id',$client_policy_id)
|
|
->where('employee_polices.is_active', 1 )->findAll();
|
|
|
|
|
|
if(count($employee_policy) > 0)
|
|
{
|
|
if($employee_policy[0]['tpa_id'] != null)
|
|
{
|
|
if($employee_policy[0]['tpa_primary_id'] == 2)//Medi assist
|
|
{
|
|
$mediAssistController = new MediAssistApiController();
|
|
$data['eCardDownload'] = $mediAssistController->EcardRequest( $emp_code, $policy_no );
|
|
}else{
|
|
|
|
if($type == "download"){
|
|
// direct download
|
|
$data['eCardDownload'] = base_url('download-e-card/') . $employee_policy[0]['rand_string'].'/1';
|
|
}else{
|
|
// view and download
|
|
$data['eCardDownload'] = base_url('download-e-card/') . $employee_policy[0]['rand_string'].'/0/1';
|
|
}
|
|
}
|
|
$data['message'] = "E-card generated";
|
|
|
|
} else {
|
|
$data['eCardDownload'] = null;
|
|
$data['message'] = "E-card not generated";
|
|
log_message('error', 'TPA number is null');
|
|
}
|
|
}else{
|
|
$data['eCardDownload'] = null;
|
|
$data['message'] = "E-card not generated";
|
|
log_message('error', 'Employee not found');
|
|
}
|
|
|
|
if($return_type == 'api'){
|
|
return $this->respond(['status' => true, 'code' => 200, 'message' => '', 'data' => $data]);
|
|
}else{
|
|
return $data;
|
|
}
|
|
|
|
} catch(\Exception $e){
|
|
|
|
}
|
|
}
|
|
|
|
// Get TPAID
|
|
public function getTPAID()
|
|
{
|
|
|
|
log_message('error', "getTPAID payloads :" . json_encode($this->request->getPost() ?? []));
|
|
$tpa_id = $this->request->getPost('tpa_id') ?? null;
|
|
$policy_no = $this->request->getPost('policy_no') ?? null;
|
|
$client_id = $this->request->getPost('client_id') ?? null;
|
|
$branch_id = $this->request->getPost('client_branch_id') ?? null;
|
|
$policy_id = $this->request->getPost('client_policy_id') ?? null;
|
|
|
|
$fileModel = new FileModel();
|
|
$filesData = $fileModel->where('is_active', 1)->where('action', 'api')->where('status', 'inprogress')->countAllResults();
|
|
|
|
if($filesData > 0){
|
|
log_message('error', "TPA GetBenefDetails job is already in process.");
|
|
return $this->respond(['status' => false, 'code' => 200,'message' => 'TPA initiation is in progress.','data' => [] ]);
|
|
}
|
|
|
|
if (empty($policy_no)) {
|
|
log_message('error', 'GetBenefDetails: policy_no missing in request');
|
|
return $this->respond(['status' => false, 'message' => 'policy_no required']);
|
|
}
|
|
|
|
$data = [
|
|
'file_name' => "API",
|
|
'action' => "api",
|
|
'status' => "inprogress",
|
|
'client_id' => $client_id,
|
|
'policy_id' => $policy_id,
|
|
'client_branch_id'=> $branch_id,
|
|
'created_by'=> get_session_userid(),
|
|
];
|
|
|
|
if ($tpa_id == 2) // MediAssist
|
|
{
|
|
$file_id = $fileModel->insert($data);
|
|
log_message('error', "Files table inserted successfully, File id : {$file_id}");
|
|
// $mediAssistController = new MediAssistApiController();
|
|
// $mediAssistController->GetBenefDetails( [ 'polict_no' => $policy_no, 'file_id' =>$file_id ] );
|
|
$r = Jobs::addJob(['job_name' => 'GetBenefDetails', 'payload' => ['policy_no' => $policy_no, 'file_id' => $file_id, 'return_type' => 'job']]);
|
|
log_message('error', "GetBenefDetails job pushed successfully.");
|
|
|
|
return $this->respond(['status' => true, 'code' => 200, 'message' => 'Action Triggered','data' => [] ]);
|
|
|
|
}else{
|
|
return $this->respond(['status' => false, 'code' => 200,'message' => 'TPA not found ','data' => [] ]);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Get Claims
|
|
public function getClaims($id)
|
|
{
|
|
if ($id == 1) {
|
|
$controller = new VidalApiController();
|
|
} elseif ($id == 2) {
|
|
$controller = new ICICILombardController();
|
|
} elseif ($id == 3) {
|
|
$controller = new MediAssistApiController();
|
|
}
|
|
}
|
|
|
|
// Get UHID
|
|
public function getUhid($id)
|
|
{
|
|
if ($id == 1) {
|
|
$controller = new VidalApiController();
|
|
} elseif ($id == 2) {
|
|
$controller = new ICICILombardController();
|
|
} elseif ($id == 3) {
|
|
$controller = new MediAssistApiController();
|
|
}
|
|
}
|
|
|
|
// Push Enrollment
|
|
public function pushEnrollment($id)
|
|
{
|
|
if ($id == 1) {
|
|
$controller = new VidalApiController();
|
|
} elseif ($id == 2) {
|
|
$controller = new ICICILombardController();
|
|
} elseif ($id == 3) {
|
|
$controller = new MediAssistApiController();
|
|
}
|
|
}
|
|
|
|
// Get Hospital Network
|
|
public function getHospitalNetwork($id)
|
|
{
|
|
if ($id == 1) {
|
|
$controller = new VidalApiController();
|
|
} elseif ($id == 2) {
|
|
$controller = new ICICILombardController();
|
|
} elseif ($id == 3) {
|
|
$controller = new MediAssistApiController();
|
|
}
|
|
}
|
|
}
|