CHANGE_TPA_API_CHANGES
This commit is contained in:
parent
887f3cfb6f
commit
957cc1f2d1
@ -276,7 +276,7 @@ class Acl
|
||||
|
||||
// ===================== INTERNAL TEST =====================
|
||||
'#^/test#' => [
|
||||
'roles' => [ADMIN_ROLE_ID],
|
||||
'roles' => [ADMIN_ROLE_ID, HEAD_ROLE_ID],
|
||||
'teams' => []
|
||||
],
|
||||
|
||||
|
||||
@ -887,6 +887,8 @@ $routes->get('HealthIndiaGetBenefDetails','HealthIndiaApiController::HealthIndia
|
||||
$routes->post("ecardRequest", "ApiServiceController::ecardRequest");
|
||||
$routes->post("getTPAID", "ApiServiceController::getTPAID");
|
||||
$routes->post("sendDataToTPA", "ApiServiceController::sendDataToTPA");
|
||||
$routes->get("jobStatus", "TestingController::jobStatus");
|
||||
$routes->post("jobStatus", "TestingController::jobStatus");
|
||||
$routes->get('fileDownload','MediAssistApiController::fileDownload');
|
||||
|
||||
|
||||
@ -928,6 +930,8 @@ $routes->group('test', function($routes) {
|
||||
$routes->get('testingquerys','TestingController::testingquerys');
|
||||
$routes->get('thzReminderCrone','ThzController::getOpenTicketsOlderThan24HoursAndAssignNextLevel');
|
||||
$routes->get('chartbrewDashboardDemo','TestingController::chartbrewDashboardDemo');
|
||||
$routes->get('getVidalEnrollmentInfo','TestingController::getVidalEnrollmentInfo');
|
||||
|
||||
// $routes->get('createDefaultMailTempalteInDB','TestingController::createDefaultMailTempalteInCrossDB');
|
||||
// $routes->get('createDefaultMailTempalteInSameDB','TestingController::createDefaultMailTempalteInSameDB');
|
||||
});
|
||||
|
||||
@ -2601,6 +2601,7 @@ class EmployeeController extends AdminController
|
||||
|
||||
$employeeRest = new EmployeeRestController();
|
||||
$tpa_api_service_status = $employeeRest->checkTpaApiEnable($client_policy_id, 'getTPAID', 'internel');
|
||||
$tpa_push_api_service_status = $employeeRest->checkTpaApiEnable($client_policy_id, 'sendDataToTPA', 'internel');
|
||||
|
||||
$slab_details = $this->policiesModel->getPolicySlabRatesForEmpOnboard($client_policy_id,$policy_details['client_id']);
|
||||
|
||||
@ -2620,7 +2621,7 @@ class EmployeeController extends AdminController
|
||||
$message = isset($message) ? ($message . ' The policy does not have a CD account number.') : null;
|
||||
}
|
||||
|
||||
return $this->respond(['dataStatus' => true, 'code' => 200, 'message' => $message, 'si_enhancement' => $si_enhancement_true_or_false, 'insurer_multi_event' => $insurer_details['is_multi_event'], 'tpa_api_service_status' => $tpa_api_service_status], 200);
|
||||
return $this->respond(['dataStatus' => true, 'code' => 200, 'message' => $message, 'si_enhancement' => $si_enhancement_true_or_false, 'insurer_multi_event' => $insurer_details['is_multi_event'], 'tpa_api_service_status' => $tpa_api_service_status, 'tpa_push_api_service_status' => $tpa_push_api_service_status], 200);
|
||||
|
||||
}
|
||||
|
||||
@ -4074,39 +4075,33 @@ class EmployeeController extends AdminController
|
||||
// d($not_in_nhance);die();
|
||||
|
||||
if (!empty($not_in_tpa) || !empty($not_in_nhance) || !empty($emp_data_wo_tpa_id)) {
|
||||
if ($type === 'download') {
|
||||
|
||||
$response = [
|
||||
'not_in_tpa' => $not_in_tpa,
|
||||
'not_in_nhance' => $not_in_nhance,
|
||||
'mismatch_data' => $emp_data_wo_tpa_id,
|
||||
];
|
||||
|
||||
|
||||
if ($type === 'internal') {
|
||||
return $response;
|
||||
}else if ($type === 'download') {
|
||||
$this->exportVariationReportExcel($not_in_tpa, $not_in_nhance, $emp_data_wo_tpa_id);
|
||||
} else {
|
||||
$response = [
|
||||
'not_in_tpa' => $not_in_tpa,
|
||||
'not_in_nhance' => $not_in_nhance,
|
||||
'mismatch_data' => $emp_data_wo_tpa_id,
|
||||
];
|
||||
|
||||
return $this->respond(
|
||||
[
|
||||
'status' => true,
|
||||
'code' => 200,
|
||||
'message' => '',
|
||||
'data' => $response,
|
||||
],
|
||||
200
|
||||
);
|
||||
return $this->respond(['status' => true,'code' => 200,'message' => '','data' => $response,],200);
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
if ($type === 'internal') {
|
||||
return [];
|
||||
}
|
||||
|
||||
if ($type === 'download') {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->respond(
|
||||
[
|
||||
'status' => false,
|
||||
'code' => 202,
|
||||
'message' => 'No data found',
|
||||
'data' => [],
|
||||
],
|
||||
200
|
||||
);
|
||||
return $this->respond(['status' => false,'code' => 202,'message' => 'No data found','data' => [],],200);
|
||||
}
|
||||
}
|
||||
|
||||
@ -4161,14 +4156,15 @@ class EmployeeController extends AdminController
|
||||
} elseif ($tab === 'need_to_review') {
|
||||
// For the "Need to Review" tab, generate a Correction Excel
|
||||
// using the same overall pipeline as the Not in Nhance implementation.
|
||||
$generationResult = $this->generateCorrectionUploadFromNeedToReview((int) $file_id, $file);
|
||||
// $generationResult = $this->generateCorrectionUploadFromNeedToReview((int) $file_id, $file);
|
||||
$generationResult = $this->updateEmployeeDataFromTpa([$file_id]);
|
||||
|
||||
if (!$generationResult['status']) {
|
||||
return $this->respond(
|
||||
[
|
||||
'status' => false,
|
||||
'code' => 422,
|
||||
'message' => $generationResult['message'] ?? 'Unable to generate correction upload file from Need to Review data.',
|
||||
'message' => $generationResult['message'] ?? 'Unable to process the data from Need to Review tab.',
|
||||
'data' => $generationResult['data'] ?? [],
|
||||
],
|
||||
200
|
||||
@ -4178,12 +4174,13 @@ class EmployeeController extends AdminController
|
||||
|
||||
$this->myLogger->logme(
|
||||
'error',
|
||||
'TPA variation review completed and proceed to next clicked',
|
||||
[
|
||||
'file_id' => $file_id,
|
||||
'user_id' => get_session_userid(),
|
||||
'tab' => $tab,
|
||||
]
|
||||
'TPA variation review completed and proceed to next clicked' . json_encode(
|
||||
[
|
||||
'file_id' => $file_id,
|
||||
'user_id' => get_session_userid(),
|
||||
'tab' => $tab,
|
||||
]
|
||||
)
|
||||
);
|
||||
|
||||
return $this->respond(
|
||||
@ -4193,7 +4190,7 @@ class EmployeeController extends AdminController
|
||||
'message' => $tab === 'not_in_nhance'
|
||||
? 'Employee upload file generated from Not in Nhance data and queued for processing.'
|
||||
: ($tab === 'need_to_review'
|
||||
? 'Correction upload file generated from Need to Review data and queued for processing.'
|
||||
? 'Review data update successfully.'
|
||||
: 'Proceed to next step recorded successfully.'),
|
||||
'data' => [],
|
||||
],
|
||||
@ -4246,13 +4243,7 @@ class EmployeeController extends AdminController
|
||||
$TpaApiDataModel = new TpaApiDataModel();
|
||||
|
||||
// Get master emp codes from Nhance for this client & policy
|
||||
$masterEmpRows = $this->employeePolicyModel->getTPADataVariationReport(
|
||||
$clientId,
|
||||
$clientPolicyId,
|
||||
$batchFileId,
|
||||
[],
|
||||
true
|
||||
);
|
||||
$masterEmpRows = $this->employeePolicyModel->getTPADataVariationReport($clientId,$clientPolicyId,$batchFileId,[],true);
|
||||
if (!is_array($masterEmpRows)) {
|
||||
$masterEmpRows = [];
|
||||
}
|
||||
@ -4450,7 +4441,7 @@ class EmployeeController extends AdminController
|
||||
|
||||
|
||||
// Run the same format validation used for manual uploads.
|
||||
$validationResult = $empServiceController->excelFileFormatValidation(['file_id' => $newFileId]);
|
||||
$validationResult = $empServiceController->excelFileFormatValidation(['file_id' => $newFileId, 'batch_file_id' => $batchFileId]);
|
||||
|
||||
if (isset($validationResult['error_summary']) && count($validationResult['error_summary'])) {
|
||||
return [
|
||||
@ -4465,6 +4456,7 @@ class EmployeeController extends AdminController
|
||||
'message' => 'Employee upload file generated from Not in Nhance data and queued for processing.',
|
||||
'data' => ['file_id' => $newFileId],
|
||||
];
|
||||
|
||||
} catch (\Throwable $e) {
|
||||
$this->myLogger->logme(
|
||||
'error',
|
||||
@ -4763,6 +4755,352 @@ class EmployeeController extends AdminController
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply TPA values to `employees` for rows in the same "Need to Review" set as
|
||||
* {@see generateCorrectionUploadFromNeedToReview}: same `getTPADataVariationReport` slice,
|
||||
* same `reconcileDbWithTpa` matching, then persist mismatched fields from TPA instead of
|
||||
* generating a correction Excel.
|
||||
*
|
||||
* Updatable fields mirror the correction Excel allow-list where they exist on TPA rows:
|
||||
* `name`, `dob`, `gender`, `relationship` (from TPA `relation`), `email_corporate` (if present on TPA).
|
||||
* Note: {@see reconcileDbWithTpa} only pairs rows when DB `relationship` matches TPA `relation`,
|
||||
* so `relationship` rarely appears in `not_matching`; name/dob/gender are the usual diffs.
|
||||
*
|
||||
* @param array $params Expects `batch_file_id` (int, required).
|
||||
*
|
||||
* @return array{success:bool,message:string,data:array}
|
||||
*/
|
||||
public function updateEmployeeDataFromTpa(array $params)
|
||||
{
|
||||
try {
|
||||
|
||||
$batchFileId = (int) ($params['batch_file_id'] ?? 0);
|
||||
|
||||
if ($batchFileId <= 0) {
|
||||
return [
|
||||
'success' => false,
|
||||
'message' => 'batch_file_id is required and must be a positive integer.',
|
||||
'data' => [],
|
||||
];
|
||||
}
|
||||
|
||||
$batchFile = $this->batchFileModel->find($batchFileId);
|
||||
|
||||
if (!$batchFile) {
|
||||
return [
|
||||
'success' => false,
|
||||
'message' => 'Batch file not found.',
|
||||
'data' => ['batch_file_id' => $batchFileId],
|
||||
];
|
||||
}
|
||||
|
||||
$clientId = (int) ($batchFile['client_id'] ?? 0);
|
||||
$clientPolicyId = (int) ($batchFile['client_policy_id'] ?? 0);
|
||||
$clientBranchId = (int) ($batchFile['client_branch_id'] ?? 0);
|
||||
|
||||
if (!$clientId || !$clientPolicyId || !$clientBranchId) {
|
||||
return [
|
||||
'success' => false,
|
||||
'message' => 'Incomplete batch file information. Client / policy / branch missing.',
|
||||
'data' => [],
|
||||
];
|
||||
}
|
||||
|
||||
$TpaApiDataModel = new TpaApiDataModel();
|
||||
|
||||
$dbRows = $this->employeePolicyModel->getTPADataVariationReport(
|
||||
$clientId,
|
||||
$clientPolicyId,
|
||||
$batchFileId
|
||||
);
|
||||
|
||||
if (!is_array($dbRows) || $dbRows === []) {
|
||||
return [
|
||||
'success' => false,
|
||||
'message' => 'No employee data found for this TPA variation batch.',
|
||||
'data' => [],
|
||||
];
|
||||
}
|
||||
|
||||
$allowedFields = ['name', 'dob', 'relationship', 'email_corporate', 'gender'];
|
||||
|
||||
$employeeModel = new EmployeeModel();
|
||||
$employeesUpdated = 0;
|
||||
$rowsSkippedNoDiff = 0;
|
||||
$rowsSkippedNoEmployee = 0;
|
||||
|
||||
foreach ($dbRows as $dbRow) {
|
||||
$tpaRows = $TpaApiDataModel->select('*')
|
||||
->where('emp_code', $dbRow['emp_code'] ?? '')
|
||||
->where('file_id', $batchFileId)
|
||||
->where('is_active', 1)
|
||||
->findAll();
|
||||
|
||||
if ($tpaRows === []) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$match = $this->reconcileDbWithTpa($dbRow, $tpaRows);
|
||||
|
||||
if (($match['status'] ?? '') !== 'matched') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$tpaRecord = $match['tpa_record'] ?? [];
|
||||
$notMatching = $match['not_matching'] ?? [];
|
||||
|
||||
if (!is_array($notMatching) || $notMatching === []) {
|
||||
$rowsSkippedNoDiff++;
|
||||
continue;
|
||||
}
|
||||
|
||||
$employeeId = (int) ($dbRow['employee_id'] ?? 0);
|
||||
|
||||
if ($employeeId <= 0) {
|
||||
$rowsSkippedNoEmployee++;
|
||||
continue;
|
||||
}
|
||||
|
||||
$employeeRow = $employeeModel->find($employeeId);
|
||||
|
||||
if (
|
||||
!$employeeRow
|
||||
|| (int) ($employeeRow['client_id'] ?? 0) !== $clientId
|
||||
) {
|
||||
$rowsSkippedNoEmployee++;
|
||||
continue;
|
||||
}
|
||||
|
||||
$updateData = [];
|
||||
|
||||
foreach ($notMatching as $field) {
|
||||
if (!in_array($field, $allowedFields, true)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($field === 'relationship') {
|
||||
$val = $tpaRecord['relation'] ?? null;
|
||||
if ($val !== null && $val !== '') {
|
||||
$updateData['relationship'] = $val;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($field === 'email_corporate') {
|
||||
$val = $tpaRecord['email_corporate'] ?? $tpaRecord['email'] ?? null;
|
||||
if ($val !== null && $val !== '') {
|
||||
$updateData['email_corporate'] = $val;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
$val = $tpaRecord[$field] ?? null;
|
||||
if ($val !== null && $val !== '') {
|
||||
$updateData[$field] = $val;
|
||||
}
|
||||
}
|
||||
|
||||
if ($updateData === []) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($employeeModel->update($employeeId, $updateData)) {
|
||||
$employeesUpdated++;
|
||||
}
|
||||
}
|
||||
|
||||
if ($employeesUpdated === 0) {
|
||||
$this->myLogger->logme(
|
||||
'error',
|
||||
'updateEmployeeDataFromTpa: zero employee rows updated',
|
||||
[
|
||||
'batch_file_id' => $batchFileId,
|
||||
'rows_skipped_no_diff' => $rowsSkippedNoDiff,
|
||||
'rows_skipped_no_employee' => $rowsSkippedNoEmployee,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
return [
|
||||
'success' => true,
|
||||
'message' => 'TPA-aligned employee updates applied where mismatches were reconciled.',
|
||||
'data' => [
|
||||
'batch_file_id' => $batchFileId,
|
||||
'employees_updated' => $employeesUpdated,
|
||||
'rows_skipped_no_diff' => $rowsSkippedNoDiff,
|
||||
'rows_skipped_no_employee' => $rowsSkippedNoEmployee,
|
||||
],
|
||||
];
|
||||
} catch (\Throwable $e) {
|
||||
$this->myLogger->logme(
|
||||
'error',
|
||||
'updateEmployeeDataFromTpa failed: ' . json_encode([
|
||||
'message' => $e->getMessage(),
|
||||
'file' => $e->getFile(),
|
||||
'line' => $e->getLine(),
|
||||
], JSON_PRETTY_PRINT)
|
||||
);
|
||||
|
||||
return [
|
||||
'success' => false,
|
||||
'message' => 'Unable to process the data from Need to Review tab.',
|
||||
'data' => [],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param array $params batch_file_id (required), file_id (optional, >0 filters employee_polices.file_id)
|
||||
* @param mixed $jobId Optional queue job id when invoked from JobWorker (ignored).
|
||||
*
|
||||
* @return array{success:bool,message:string,data:array}
|
||||
*/
|
||||
public function updateTpaIdForNotInNhance($params, $jobId = null): array
|
||||
{
|
||||
try {
|
||||
if (!is_array($params)) {
|
||||
return [
|
||||
'success' => false,
|
||||
'message' => 'Invalid parameters.',
|
||||
'data' => [],
|
||||
];
|
||||
}
|
||||
|
||||
$TpaApiDataModel = new TpaApiDataModel();
|
||||
|
||||
$fileId = (int) ($params['file_id'] ?? 0);
|
||||
$batchFileId = (int) ($params['batch_file_id'] ?? 0);
|
||||
|
||||
if ($batchFileId <= 0) {
|
||||
$this->myLogger->logme('error', 'Batch file ID missing in updateTpaIdForNotInNhance', ['params' => $params]);
|
||||
|
||||
return [
|
||||
'success' => false,
|
||||
'message' => 'Batch file ID is required.',
|
||||
'data' => [],
|
||||
];
|
||||
}
|
||||
|
||||
$batchFileData = db_connect()->table('batch_files')->where('id', $batchFileId)->get()->getRowArray();
|
||||
|
||||
if (empty($batchFileData) || empty($batchFileData['client_policy_id'])) {
|
||||
$this->myLogger->logme('error', 'Batch file not found or missing client_policy_id in updateTpaIdForNotInNhance', ['batch_file_id' => $batchFileId]);
|
||||
|
||||
return [
|
||||
'success' => false,
|
||||
'message' => 'Batch file not found or missing client policy.',
|
||||
'data' => [],
|
||||
];
|
||||
}
|
||||
|
||||
$client_policy_data = $this->clientPolicyModel->where('id', $batchFileData['client_policy_id'])->first();
|
||||
|
||||
if (empty($client_policy_data)) {
|
||||
$this->myLogger->logme('error', 'Client policy not found in updateTpaIdForNotInNhance', ['client_policy_id' => $batchFileData['client_policy_id']]);
|
||||
|
||||
return [
|
||||
'success' => false,
|
||||
'message' => 'Client policy not found.',
|
||||
'data' => [],
|
||||
];
|
||||
}
|
||||
|
||||
// Get master emp codes from Nhance for this client & policy
|
||||
$masterEmpRows = $this->employeePolicyModel->getTPADataVariationReport(
|
||||
$batchFileData['client_id'],
|
||||
$batchFileData['client_policy_id'],
|
||||
$batchFileId,
|
||||
[],
|
||||
true
|
||||
);
|
||||
if (!is_array($masterEmpRows)) {
|
||||
$masterEmpRows = [];
|
||||
}
|
||||
$masterEmpCodes = array_values(array_filter(
|
||||
array_unique(array_column($masterEmpRows, 'emp_code')),
|
||||
static fn ($code) => $code !== null && $code !== ''
|
||||
));
|
||||
|
||||
// Fetch Not in Nhance rows for this batch file
|
||||
$notInNhanceQuery = $TpaApiDataModel->select('*')
|
||||
->where('is_active', 1)
|
||||
->where('file_id', $batchFileId);
|
||||
|
||||
if ($masterEmpCodes !== []) {
|
||||
$notInNhanceQuery->whereNotIn('emp_code', $masterEmpCodes);
|
||||
}
|
||||
|
||||
$notInNhance = $notInNhanceQuery->findAll();
|
||||
|
||||
$uhidValue = $client_policy_data['policy_no'] ?? null;
|
||||
|
||||
$empPolicyIds = [];
|
||||
foreach ($notInNhance as $tpaRow) {
|
||||
$builder = $this->employeePolicyModel
|
||||
->select('employee_polices.id')
|
||||
->join('employees e', 'e.id = employee_polices.employee_id')
|
||||
->where('e.name', $tpaRow['name'] ?? '')
|
||||
->where('e.emp_code', $tpaRow['emp_code'] ?? '')
|
||||
->where('e.dob', $tpaRow['dob'] ?? null)
|
||||
->where('e.relationship', $tpaRow['relation'] ?? null)
|
||||
->where('e.gender', $tpaRow['gender'] ?? null)
|
||||
->where('employee_polices.client_policy_id', (int) $batchFileData['client_policy_id'])
|
||||
->where('e.client_id', (int) $batchFileData['client_id']);
|
||||
|
||||
if ($fileId > 0) {
|
||||
$builder->where('employee_polices.file_id', $fileId);
|
||||
}
|
||||
|
||||
$empPolicyRow = $builder->first();
|
||||
|
||||
if (empty($empPolicyRow['id'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$epId = (int) $empPolicyRow['id'];
|
||||
if ($this->employeePolicyModel->update($epId, [
|
||||
'tpa_id' => $tpaRow['tpa_id'] ?? null,
|
||||
'uhid' => $uhidValue,
|
||||
])) {
|
||||
$empPolicyIds[] = $epId;
|
||||
}
|
||||
}
|
||||
|
||||
if ($empPolicyIds === []) {
|
||||
$this->myLogger->logme(
|
||||
'warning',
|
||||
'updateTpaIdForNotInNhance: zero employee_policy rows updated',
|
||||
[
|
||||
'batch_file_id' => $batchFileId,
|
||||
'not_in_nhance_count' => count($notInNhance),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
return [
|
||||
'success' => true,
|
||||
'message' => 'TPA id / UHID applied on matching employee policies for Not in Nhance rows.',
|
||||
'data' => [
|
||||
'employee_policies_updated' => count($empPolicyIds),
|
||||
'employee_policy_ids' => $empPolicyIds,
|
||||
],
|
||||
];
|
||||
} catch (\Throwable $e) {
|
||||
$this->myLogger->logme(
|
||||
'error',
|
||||
'updateTpaIdForNotInNhance exception: ' . $e->getMessage(),
|
||||
['params' => $params, 'trace' => $e->getTraceAsString()]
|
||||
);
|
||||
|
||||
return [
|
||||
'success' => false,
|
||||
'message' => 'Unexpected error while updating TPA id from Not in Nhance data.',
|
||||
'data' => [],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// not in use once all functionality workes well in this funciton then remvoe this function
|
||||
function compareDbWithTpa(array $db, array $tpaRows): array
|
||||
|
||||
@ -254,6 +254,26 @@ class JobWorker extends AdminController
|
||||
'ICICIPushEmployeeDetails' => [
|
||||
'type' => 'CC', // Handler Category
|
||||
'handler' => 'App\Controllers\ICICILombardController',
|
||||
],
|
||||
'getEnrollmentBatchStatus' => [
|
||||
'type' => 'CC', // Handler Category
|
||||
'handler' => 'App\Controllers\ICICILombardController',
|
||||
],
|
||||
'fetchUHIDDetails' => [
|
||||
'type' => 'CC', // Handler Category
|
||||
'handler' => 'App\Controllers\ICICILombardController',
|
||||
],
|
||||
'saveICICILombardAPIData' => [
|
||||
'type' => 'CC', // Handler Category
|
||||
'handler' => 'App\Controllers\ICICILombardController',
|
||||
],
|
||||
'updateEmployeeDataFromTpa' => [
|
||||
'type' => 'CC', // Handler Category
|
||||
'handler' => 'App\Controllers\EmployeeController',
|
||||
],
|
||||
'updateTpaIdForNotInNhance' => [
|
||||
'type' => 'CC', // Handler Category
|
||||
'handler' => 'App\Controllers\EmployeeController',
|
||||
]
|
||||
];
|
||||
|
||||
|
||||
@ -10,6 +10,7 @@ use App\Models\BatchFileModel;
|
||||
use App\Models\InsurerBranchModel;
|
||||
use App\Models\RFQModel;
|
||||
use App\Models\EmployeeModel;
|
||||
use App\Libraries\JobStatusService;
|
||||
use CodeIgniter\HTTP\ResponseInterface;
|
||||
use CodeIgniter\API\ResponseTrait;
|
||||
use Dompdf\Dompdf;
|
||||
@ -48,6 +49,110 @@ class TestingController extends BaseController
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get latest job status by job name.
|
||||
* Supports:
|
||||
* - GET -> ?job_name=...
|
||||
* - POST -> job_name in form/json payload
|
||||
*/
|
||||
public function jobStatus()
|
||||
{
|
||||
$jobName = trim((string) ($this->request->getGet('job_name') ?? ''));
|
||||
|
||||
if ($jobName === '') {
|
||||
$jobName = trim((string) ($this->request->getPost('job_name') ?? ''));
|
||||
}
|
||||
|
||||
if ($jobName === '') {
|
||||
$jsonPayload = $this->request->getJSON(true);
|
||||
if (is_array($jsonPayload)) {
|
||||
$jobName = trim((string) ($jsonPayload['job_name'] ?? ''));
|
||||
}
|
||||
}
|
||||
|
||||
$service = new JobStatusService();
|
||||
$result = $service->getJobStatusByName($jobName);
|
||||
|
||||
$httpCode = 200;
|
||||
if (($result['success'] ?? false) !== true) {
|
||||
if ($jobName === '') {
|
||||
$httpCode = 422;
|
||||
} elseif (($result['message'] ?? '') === 'No job record found for given name.') {
|
||||
$httpCode = 404;
|
||||
} else {
|
||||
$httpCode = 500;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->response->setStatusCode($httpCode)->setJSON($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* QA-only: invokes EmployeeController::updateTpaIdForNotInNhance.
|
||||
* Routed under /util with authMVC — must be logged into the admin app.
|
||||
*
|
||||
* GET or POST: batch_file_id (required), file_id (optional, omit or 0 to skip file_id filter).
|
||||
*/
|
||||
public function qaUpdateTpaIdForNotInNhance()
|
||||
{
|
||||
$batchFileId = $this->request->getGet('batch_file_id');
|
||||
if ($batchFileId === null || $batchFileId === '') {
|
||||
$batchFileId = $this->request->getPost('batch_file_id');
|
||||
}
|
||||
|
||||
$fileId = $this->request->getGet('file_id');
|
||||
if ($fileId === null || $fileId === '') {
|
||||
$fileId = $this->request->getPost('file_id');
|
||||
}
|
||||
|
||||
if ($batchFileId === null || $batchFileId === '') {
|
||||
return $this->response->setStatusCode(422)->setJSON([
|
||||
'success' => false,
|
||||
'message' => 'batch_file_id is required (query string or POST).',
|
||||
]);
|
||||
}
|
||||
|
||||
$params = [
|
||||
'batch_file_id' => (int) $batchFileId,
|
||||
'file_id' => ($fileId !== null && $fileId !== '') ? (int) $fileId : 0,
|
||||
];
|
||||
|
||||
$employeeController = new EmployeeController();
|
||||
$employeeController->initController($this->request, $this->response, service('logger'));
|
||||
$result = $employeeController->updateTpaIdForNotInNhance($params);
|
||||
|
||||
return $this->response->setJSON(array_merge($result, ['params' => $params]));
|
||||
}
|
||||
|
||||
/**
|
||||
* QA-only: invokes EmployeeController::updateEmployeeDataFromTpa (Need to Review → DB updates, no Excel).
|
||||
* Routed under /util with authMVC.
|
||||
*
|
||||
* GET or POST: batch_file_id (required).
|
||||
*/
|
||||
public function qaUpdateEmployeeDataFromTpa()
|
||||
{
|
||||
$batchFileId = $this->request->getGet('batch_file_id');
|
||||
if ($batchFileId === null || $batchFileId === '') {
|
||||
$batchFileId = $this->request->getPost('batch_file_id');
|
||||
}
|
||||
|
||||
if ($batchFileId === null || $batchFileId === '') {
|
||||
return $this->response->setStatusCode(422)->setJSON([
|
||||
'success' => false,
|
||||
'message' => 'batch_file_id is required (query string or POST).',
|
||||
]);
|
||||
}
|
||||
|
||||
$employeeController = new EmployeeController();
|
||||
$employeeController->initController($this->request, $this->response, service('logger'));
|
||||
$result = $employeeController->updateEmployeeDataFromTpa([
|
||||
'batch_file_id' => (int) $batchFileId,
|
||||
]);
|
||||
|
||||
return $this->response->setJSON($result);
|
||||
}
|
||||
|
||||
public function testcli()
|
||||
{
|
||||
echo "hi";
|
||||
@ -1609,4 +1714,66 @@ class TestingController extends BaseController
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function getVidalEnrollmentInfo()
|
||||
{
|
||||
helper('api');
|
||||
|
||||
$url = 'https://devapigw.vidalhealthtpa.com/partner-integration/enrollment/enrollment-info';
|
||||
|
||||
$subscriptionKey = getenv('VIDAL_API_SUBSCRIPTION_KEY');
|
||||
if (empty($subscriptionKey)) {
|
||||
return $this->response->setStatusCode(500)->setJSON([
|
||||
'error' => 'Missing VIDAL_SUBSCRIPTION_KEY/VIDAL_API_SUBSCRIPTION_KEY in env',
|
||||
]);
|
||||
}
|
||||
|
||||
// Allow overriding payload via query/post/json; fall back to existing defaults.
|
||||
$jsonPayload = $this->request->getJSON(true);
|
||||
|
||||
$policyNo = (string) (
|
||||
($this->request->getGet('policyNo') ?? '')
|
||||
?: ($this->request->getPost('policyNo') ?? '')
|
||||
?: ($jsonPayload['policyNo'] ?? '')
|
||||
?: '000/VZXSY'
|
||||
);
|
||||
|
||||
$startIndex = (int) (
|
||||
($this->request->getGet('startIndex') ?? null)
|
||||
?? ($this->request->getPost('startIndex') ?? null)
|
||||
?? ($jsonPayload['startIndex'] ?? 1)
|
||||
);
|
||||
|
||||
$endIndex = (int) (
|
||||
($this->request->getGet('endIndex') ?? null)
|
||||
?? ($this->request->getPost('endIndex') ?? null)
|
||||
?? ($jsonPayload['endIndex'] ?? 5)
|
||||
);
|
||||
|
||||
$body = [
|
||||
'policyNo' => $policyNo,
|
||||
'startIndex' => $startIndex,
|
||||
'endIndex' => $endIndex,
|
||||
];
|
||||
|
||||
$headers = [
|
||||
'Content-Type: application/json',
|
||||
'Ocp-Apim-Subscription-Key: ' . $subscriptionKey,
|
||||
];
|
||||
|
||||
$method = "POST";
|
||||
|
||||
$rawResponse = call_third_party_api($url, $method, $headers, json_encode($body));
|
||||
|
||||
return $this->response->setStatusCode(200)->setJSON([
|
||||
'request' => [
|
||||
'url' => $url,
|
||||
'method' => $method,
|
||||
'headers' => $headers,
|
||||
'body' => $body,
|
||||
],
|
||||
'raw_response' => $rawResponse,
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
100
app/Libraries/JobStatusService.php
Normal file
100
app/Libraries/JobStatusService.php
Normal file
@ -0,0 +1,100 @@
|
||||
<?php
|
||||
|
||||
namespace App\Libraries;
|
||||
|
||||
use App\Models\JobModel;
|
||||
|
||||
class JobStatusService
|
||||
{
|
||||
protected JobModel $jobModel;
|
||||
|
||||
public function __construct(?JobModel $jobModel = null)
|
||||
{
|
||||
$this->jobModel = $jobModel ?? new JobModel();
|
||||
}
|
||||
|
||||
public function getJobStatusByName(string $jobName): array
|
||||
{
|
||||
$jobName = trim($jobName);
|
||||
|
||||
if ($jobName === '') {
|
||||
return $this->buildResponse(false, $jobName, 'Job name is required.');
|
||||
}
|
||||
|
||||
try {
|
||||
$job = $this->jobModel
|
||||
->where('name', $jobName)
|
||||
->orderBy('id', 'DESC')
|
||||
->first();
|
||||
|
||||
if (!$job) {
|
||||
return $this->buildResponse(false, $jobName, 'No job record found for given name.');
|
||||
}
|
||||
|
||||
return [
|
||||
'success' => true,
|
||||
'job_name' => $jobName,
|
||||
'status' => $job['status'] ?? null,
|
||||
'response' => $this->normalizeResponse($job['response'] ?? null),
|
||||
'job_id' => isset($job['id']) ? (int) $job['id'] : null,
|
||||
'uuid' => $job['uuid'] ?? null,
|
||||
'run_time' => $this->normalizeRunTime($job['run_time'] ?? null),
|
||||
'message' => 'Job status fetched successfully.',
|
||||
];
|
||||
} catch (\Throwable $e) {
|
||||
log_message('error', 'JobStatusService failed for job "{job}": {message}', [
|
||||
'job' => $jobName,
|
||||
'message' => $e->getMessage(),
|
||||
]);
|
||||
|
||||
return $this->buildResponse(false, $jobName, 'Unable to fetch job status right now.');
|
||||
}
|
||||
}
|
||||
|
||||
protected function normalizeResponse($rawResponse)
|
||||
{
|
||||
// dd($rawResponse);
|
||||
if ($rawResponse === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (is_string($rawResponse)) {
|
||||
$trimmed = trim($rawResponse);
|
||||
if ($trimmed === '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
$decoded = json_decode($trimmed, true);
|
||||
if (json_last_error() === JSON_ERROR_NONE) {
|
||||
return $decoded;
|
||||
}
|
||||
|
||||
return $rawResponse;
|
||||
}
|
||||
|
||||
return $rawResponse;
|
||||
}
|
||||
|
||||
protected function normalizeRunTime($runTime)
|
||||
{
|
||||
if ($runTime === null || $runTime === '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
return is_numeric($runTime) ? (float) $runTime : null;
|
||||
}
|
||||
|
||||
protected function buildResponse(bool $success, string $jobName, string $message): array
|
||||
{
|
||||
return [
|
||||
'success' => $success,
|
||||
'job_name' => $jobName,
|
||||
'status' => null,
|
||||
'response' => null,
|
||||
'job_id' => null,
|
||||
'uuid' => null,
|
||||
'run_time' => null,
|
||||
'message' => $message,
|
||||
];
|
||||
}
|
||||
}
|
||||
@ -460,6 +460,15 @@ if (isset($selected_lead_type)) {
|
||||
let shortNameTimer;
|
||||
|
||||
$('#client_name').on('input', function() {
|
||||
let lead_type = $('#lead_type').val();
|
||||
let exixting_client = $('#existing_client').is(':checked');
|
||||
|
||||
console.log(`Lead Type: ${lead_type}, Existing Client: ${exixting_client}`);
|
||||
|
||||
if(lead_type == 1 || exixting_client == true){
|
||||
return false;
|
||||
}
|
||||
|
||||
clearTimeout(shortNameTimer);
|
||||
shortNameTimer = setTimeout(generateShortName, 200);
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue
Block a user