FEAT_INSURER_CLAIM_FORM_AND_DECRYPT_VISIT_SSO
This commit is contained in:
parent
396d9a2949
commit
c065836b70
3
.gitignore
vendored
3
.gitignore
vendored
@ -28,6 +28,9 @@ writable/**/*.sqlite
|
||||
writable/tmp/*
|
||||
!writable/tmp/.gitkeep
|
||||
|
||||
writable/insurer_claim_form/*
|
||||
!writable/insurer_claim_form/Claim_Form_IRDAI.pdf
|
||||
|
||||
vendor/
|
||||
build/
|
||||
composer.lock
|
||||
|
||||
@ -133,3 +133,4 @@ define('UPLOAD_EXT_EXCEL', ['xls', 'xlsx', 'ods', 'csv']);
|
||||
define('UPLOAD_EXT_MAIL_ATTACHMENTS', ['pdf', 'jpg', 'jpeg', 'png', 'doc', 'docx', 'xls', 'xlsx']);
|
||||
define('UPLOAD_EXT_NON_EB_RACK_RATE', ['pdf', 'xls', 'xlsx']);
|
||||
define('UPLOAD_EXT_ASSET_FILES', ['pdf', 'xls', 'xlsx', 'csv']);
|
||||
define('UPLOAD_EXT_INSURER_CLAIM_FORM', ['pdf', 'doc', 'docx']);
|
||||
|
||||
@ -257,6 +257,7 @@ $routes->group("/master", ["filter" => "authMVC"], function ($routes) {
|
||||
$routes->get("create", "MasterController::insurerOnboarding");
|
||||
$routes->post("createpost", "MasterController::createInsurerGeneralInfo");
|
||||
$routes->post("edit", "MasterController::editInsurerGeneralInfo");
|
||||
$routes->get("download-claim-form/(:num)", "MasterController::downloadInsurerClaimForm/$1");
|
||||
$routes->get("list/(:any)", "MasterController::editInsurerOnboarding/$1");
|
||||
|
||||
$routes->group("branch", ["filter" => "authMVC"], function ($routes) {
|
||||
@ -464,6 +465,7 @@ $routes->group("/util", ["filter" => "authMVC"], function ($routes) {
|
||||
$routes->get('insertSampleTpaApiData/(:any)', 'TestingController::insertSampleTpaApiData/$1');
|
||||
$routes->get('listEmployeeCountByClientPolicy', 'TestingController::listEmployeeCountByClientPolicy');
|
||||
$routes->get('testMediAssistWellness','TestingController::testMediAssistWellness');
|
||||
$routes->match(['get', 'post'], 'decryptVisitSso', 'ApiServiceController::decryptVisitSso'); // disabled for now do not remove this
|
||||
|
||||
$routes->group('claims-collection-v2', static function ($routes) {
|
||||
$routes->get('preview', 'ClaimsCollectionV2DashboardController::preview');
|
||||
|
||||
@ -580,6 +580,86 @@ class ApiServiceController extends BaseController
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Decrypt Visit SSO userParams (reverse of Visit encryption in getWellnessUrl).
|
||||
* Accepts encrypted string or full SSO URL via POST/GET as userParams or encrypted_sso.
|
||||
*/
|
||||
public function decryptVisitSso()
|
||||
{
|
||||
$encrypted = $this->request->getGet('encrypted_sso');
|
||||
|
||||
if (empty($encrypted)) {
|
||||
return $this->response->setJSON([
|
||||
'status' => false,
|
||||
'message' => 'userParams or encrypted_sso is required',
|
||||
]);
|
||||
}
|
||||
|
||||
$result = $this->decryptVisitSsoParams($encrypted);
|
||||
|
||||
if ($result === false) {
|
||||
return $this->response->setJSON([
|
||||
'status' => false,
|
||||
'message' => 'Decryption failed. Check encrypted value and VISIT_SECRET_KEY / VISIT_IV.',
|
||||
]);
|
||||
}
|
||||
|
||||
return $this->response->setJSON([
|
||||
'status' => true,
|
||||
'data' => $result['params'],
|
||||
'plainText' => $result['plainText'],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Decrypt Visit SSO payload using the same key/IV as getWellnessUrl Visit branch.
|
||||
*
|
||||
* @param string $encrypted Base64URL userParams value or full SSO URL containing userParams=
|
||||
* @return array{plainText: string, params: array}|false
|
||||
*/
|
||||
private function decryptVisitSsoParams(string $encrypted)
|
||||
{
|
||||
if (strpos($encrypted, 'userParams=') !== false) {
|
||||
$query = [];
|
||||
parse_str(parse_url($encrypted, PHP_URL_QUERY) ?? '', $query);
|
||||
$encrypted = $query['userParams'] ?? '';
|
||||
}
|
||||
|
||||
$encrypted = trim($encrypted);
|
||||
if ($encrypted === '') {
|
||||
return false;
|
||||
}
|
||||
|
||||
$base64 = strtr($encrypted, '-_', '+/');
|
||||
$base64 .= str_repeat('=', (4 - strlen($base64) % 4) % 4);
|
||||
|
||||
$cipherRaw = base64_decode($base64, true);
|
||||
if ($cipherRaw === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$derivedKey = hash('sha256', env('VISIT_SECRET_KEY'), true);
|
||||
$plainText = openssl_decrypt(
|
||||
$cipherRaw,
|
||||
'aes-256-cbc',
|
||||
$derivedKey,
|
||||
OPENSSL_RAW_DATA,
|
||||
env('VISIT_IV')
|
||||
);
|
||||
|
||||
if ($plainText === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$params = [];
|
||||
parse_str($plainText, $params);
|
||||
|
||||
return [
|
||||
'plainText' => $plainText,
|
||||
'params' => $params,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Manual TPA Claim Push - accepts claim_id via POST and delegates to pushClaims().
|
||||
* Returns the response from pushClaims() as the API response.
|
||||
|
||||
@ -331,6 +331,13 @@ class MasterController extends AdminController
|
||||
'ext_in' => 'Allowed file types: jpg, jpeg, png',
|
||||
]
|
||||
],
|
||||
'insurer_claim_form' => [
|
||||
'rules' => 'if_exist|max_size[insurer_claim_form,5120]|ext_in[insurer_claim_form,pdf,doc,docx]',
|
||||
'errors' => [
|
||||
'max_size' => 'Claim form file size should not exceed 5 MB',
|
||||
'ext_in' => 'Allowed file types: pdf, doc, docx',
|
||||
]
|
||||
],
|
||||
];
|
||||
// $rules = [
|
||||
// 'name' => [
|
||||
@ -368,6 +375,14 @@ class MasterController extends AdminController
|
||||
|
||||
$uploadFilePath = ROOTPATH . 'public/uploads/logo/';
|
||||
$file_name = file_Upload($this->request->getFile('insurer_logo'), $uploadFilePath, UPLOAD_EXT_IMAGES);
|
||||
|
||||
$claimFormUploadPath = WRITEPATH . 'insurer_claim_form/';
|
||||
if (!is_dir($claimFormUploadPath)) {
|
||||
mkdir($claimFormUploadPath, 0777, true);
|
||||
}
|
||||
$insurerShortName = trim((string) ($this->request->getPost('short_name') ?? ''));
|
||||
$claimFormUpload = file_Upload_random_name($this->request->getFile('insurer_claim_form'), $claimFormUploadPath, UPLOAD_EXT_INSURER_CLAIM_FORM, $insurerShortName);
|
||||
|
||||
$data = $this->request->getPost();
|
||||
$sanitized_post_data = sanitizeInputArrayAdvanced($data);
|
||||
|
||||
@ -376,6 +391,10 @@ class MasterController extends AdminController
|
||||
$sanitized_post_data['is_multi_event'] = (!empty($sanitized_post_data['is_multi_event'])) ? 1 : 0;
|
||||
$sanitized_post_data['created_by'] = get_session_userid();
|
||||
$sanitized_post_data['insurer_logo'] = $file_name;
|
||||
if (!empty($claimFormUpload['stored_name'])) {
|
||||
$sanitized_post_data['insurer_claim_form'] = $claimFormUpload['stored_name'];
|
||||
$sanitized_post_data['insurer_claim_form_original_name'] = $claimFormUpload['original_name'];
|
||||
}
|
||||
|
||||
$insert = $this->insurerModel->insert($sanitized_post_data);
|
||||
|
||||
@ -573,6 +592,13 @@ class MasterController extends AdminController
|
||||
'ext_in' => 'Only JPG, JPEG, and PNG files are allowed.',
|
||||
]
|
||||
],
|
||||
'insurer_claim_form' => [
|
||||
'rules' => 'permit_empty|max_size[insurer_claim_form,5120]|ext_in[insurer_claim_form,pdf,doc,docx]',
|
||||
'errors' => [
|
||||
'max_size' => 'Claim form file size should not exceed 5 MB',
|
||||
'ext_in' => 'Allowed file types: pdf, doc, docx',
|
||||
]
|
||||
],
|
||||
];
|
||||
|
||||
if (!$this->validateData($postData, $rules)) {
|
||||
@ -594,6 +620,18 @@ class MasterController extends AdminController
|
||||
|
||||
$uploadFilePath = ROOTPATH . 'public/uploads/logo/';
|
||||
$file_name = file_Upload($this->request->getFile('insurer_logo'), $uploadFilePath, UPLOAD_EXT_IMAGES);
|
||||
|
||||
$claimFormUploadPath = WRITEPATH . 'insurer_claim_form/';
|
||||
if (!is_dir($claimFormUploadPath)) {
|
||||
mkdir($claimFormUploadPath, 0777, true);
|
||||
}
|
||||
$insurerShortName = trim((string) ($this->request->getPost('short_name') ?? ''));
|
||||
if ($insurerShortName === '' && !empty($this->request->getPost('PrimaryKey'))) {
|
||||
$existingInsurerForShortName = $this->insurerModel->find($this->request->getPost('PrimaryKey'));
|
||||
$insurerShortName = trim((string) ($existingInsurerForShortName['short_name'] ?? ''));
|
||||
}
|
||||
$claimFormUpload = file_Upload_random_name($this->request->getFile('insurer_claim_form'), $claimFormUploadPath, UPLOAD_EXT_INSURER_CLAIM_FORM, $insurerShortName);
|
||||
|
||||
$data = $this->request->getPost();
|
||||
$sanitized_post_data = sanitizeInputArrayAdvanced($data);
|
||||
$id = $sanitized_post_data['PrimaryKey'];
|
||||
@ -607,6 +645,18 @@ class MasterController extends AdminController
|
||||
$sanitized_post_data['insurer_logo'] = $file_name;
|
||||
}
|
||||
|
||||
if (!empty($claimFormUpload['stored_name'])) {
|
||||
$existingInsurer = $this->insurerModel->find($id);
|
||||
if (!empty($existingInsurer['insurer_claim_form'])) {
|
||||
$oldClaimFormPath = $claimFormUploadPath . $existingInsurer['insurer_claim_form'];
|
||||
if (is_file($oldClaimFormPath)) {
|
||||
unlink($oldClaimFormPath);
|
||||
}
|
||||
}
|
||||
$sanitized_post_data['insurer_claim_form'] = $claimFormUpload['stored_name'];
|
||||
$sanitized_post_data['insurer_claim_form_original_name'] = $claimFormUpload['original_name'];
|
||||
}
|
||||
|
||||
$update = $this->insurerModel->update($id,$sanitized_post_data);
|
||||
|
||||
if($update){
|
||||
@ -616,6 +666,27 @@ class MasterController extends AdminController
|
||||
}
|
||||
}
|
||||
|
||||
public function downloadInsurerClaimForm($id = null)
|
||||
{
|
||||
$insurer = $this->insurerModel->where(['id' => (int) $id, 'is_active' => 1])->first();
|
||||
|
||||
if (empty($insurer) || empty($insurer['insurer_claim_form'])) {
|
||||
throw \CodeIgniter\Exceptions\PageNotFoundException::forPageNotFound('Claim form file not found');
|
||||
}
|
||||
|
||||
$storedFileName = basename($insurer['insurer_claim_form']);
|
||||
$downloadFileName = !empty($insurer['insurer_claim_form_original_name'])
|
||||
? basename($insurer['insurer_claim_form_original_name'])
|
||||
: $storedFileName;
|
||||
$filePath = WRITEPATH . 'insurer_claim_form/' . $storedFileName;
|
||||
|
||||
if (!is_file($filePath)) {
|
||||
throw \CodeIgniter\Exceptions\PageNotFoundException::forPageNotFound('Claim form file not found');
|
||||
}
|
||||
|
||||
return $this->response->download($filePath, null)->setFileName($downloadFileName);
|
||||
}
|
||||
|
||||
public function editInsurerGet($id = null)
|
||||
{
|
||||
$this->myLogger->logme('error','Edit TPA Onboarding function called');
|
||||
@ -3084,6 +3155,7 @@ class MasterController extends AdminController
|
||||
'files' => WRITEPATH . 'uploads/commission/files',
|
||||
'rules' => WRITEPATH . 'uploads/commission/rules',
|
||||
'claim_sample_forms' => ROOTPATH . 'public/claim_sample_forms/',
|
||||
'insurer_claim_form' => WRITEPATH . 'insurer_claim_form/',
|
||||
'tmp' => ROOTPATH . 'public/tmp/',
|
||||
'bds_dump_excel' => WRITEPATH . 'uploads/bds_dump_excel/',
|
||||
'claims_mis' => WRITEPATH . 'uploads/claims_mis/',
|
||||
|
||||
@ -3405,18 +3405,31 @@ class TicketController extends BaseController
|
||||
}
|
||||
|
||||
public function downloadClaimForm($insurer_id)
|
||||
{
|
||||
{
|
||||
$insurerModel = new InsurerModel();
|
||||
$insurer_data = $insurerModel->where('MD5(id)', $insurer_id)->where('is_active', 1)->first();
|
||||
|
||||
|
||||
if (!$insurer_data) {
|
||||
$data['message'] = 'The Physical File Not Found';
|
||||
echo view('errors/404', $data);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (!empty($insurer_data['insurer_claim_form'])) {
|
||||
$storedFileName = basename($insurer_data['insurer_claim_form']);
|
||||
$downloadFileName = !empty($insurer_data['insurer_claim_form_original_name'])
|
||||
? basename($insurer_data['insurer_claim_form_original_name'])
|
||||
: $storedFileName;
|
||||
$filePath = WRITEPATH . 'insurer_claim_form/' . $storedFileName;
|
||||
|
||||
if (is_file($filePath)) {
|
||||
return $this->response->download($filePath, null)->setFileName($downloadFileName);
|
||||
}
|
||||
}
|
||||
|
||||
$fileName = $insurer_data['short_name'] . '.pdf';
|
||||
$filePath = ROOTPATH . 'public/claim_sample_forms/' . $fileName;
|
||||
|
||||
|
||||
try {
|
||||
if (file_exists($filePath)) {
|
||||
return $this->response->download($filePath, null);
|
||||
|
||||
5
app/Database/insurers_add_claim_form_column.sql
Normal file
5
app/Database/insurers_add_claim_form_column.sql
Normal file
@ -0,0 +1,5 @@
|
||||
ALTER TABLE insurers
|
||||
ADD COLUMN insurer_claim_form VARCHAR(255) NULL DEFAULT NULL AFTER insurer_logo;
|
||||
|
||||
ALTER TABLE insurers
|
||||
ADD COLUMN insurer_claim_form_original_name VARCHAR(255) NULL DEFAULT NULL AFTER insurer_claim_form;
|
||||
@ -99,6 +99,30 @@ if (! function_exists('file_Upload')) {
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('file_Upload_random_name')) {
|
||||
function file_Upload_random_name($fileToUpload, $filepath, array $allowedExtensions = UPLOAD_ALLOWED_EXTENSIONS, string $namePrefix = ''): array
|
||||
{
|
||||
$empty = ['stored_name' => '', 'original_name' => ''];
|
||||
|
||||
if ($fileToUpload === null || ! $fileToUpload->isValid() || $fileToUpload->hasMoved()) {
|
||||
return $empty;
|
||||
}
|
||||
|
||||
if (! validate_upload_extension($fileToUpload, $allowedExtensions)) {
|
||||
return $empty;
|
||||
}
|
||||
|
||||
$originalName = sanitize_upload_filename($fileToUpload->getClientName() ?: $fileToUpload->getName());
|
||||
$ext = strtolower($fileToUpload->getClientExtension() ?: pathinfo($originalName, PATHINFO_EXTENSION));
|
||||
$namePrefix = preg_replace('/[^a-zA-Z0-9\-_]/', '', $namePrefix);
|
||||
$prefix = $namePrefix !== '' ? $namePrefix . '_' : '';
|
||||
$storedName = $prefix . time() . '_' . bin2hex(random_bytes(8)) . ($ext !== '' ? '.' . $ext : '');
|
||||
$fileToUpload->move($filepath, $storedName);
|
||||
|
||||
return ['stored_name' => $storedName, 'original_name' => $originalName];
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('file_Upload_for_lead')) {
|
||||
function file_Upload_for_lead($fileToUpload, $filepath, array $allowedExtensions = UPLOAD_ALLOWED_EXTENSIONS)
|
||||
{
|
||||
|
||||
@ -15,6 +15,8 @@ class InsurerModel extends Model
|
||||
"name",
|
||||
"short_name",
|
||||
"insurer_logo",
|
||||
"insurer_claim_form",
|
||||
"insurer_claim_form_original_name",
|
||||
"created_by",
|
||||
"updated_by",
|
||||
"is_active",
|
||||
|
||||
@ -187,6 +187,33 @@ input:checked + .slider:before {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Insurer Claim Form -->
|
||||
<div class="form-group row">
|
||||
<label for="insurer_claim_form" class="col-md-4 col-form-label">Insurer Claim Form</label>
|
||||
<div class="col-md-5">
|
||||
<div class="input-icon">
|
||||
<input type="file" class="form-control" id="insurer_claim_form" name="insurer_claim_form"
|
||||
accept=".pdf,.doc,.docx,application/pdf,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document"
|
||||
data-parsley-insurer-claim-max-file-size="5120"
|
||||
data-parsley-insurer-claim-file-extension="pdf,doc,docx"
|
||||
data-parsley-insurer-claim-max-file-size-message="File size should not exceed 5MB."
|
||||
data-parsley-insurer-claim-file-extension-message="Only PDF, DOC, and DOCX files are allowed."
|
||||
data-parsley-errors-container="#claim_form_error_container">
|
||||
<i class="mdi mdi-upload additional-icon"></i>
|
||||
</div>
|
||||
<div id="claim_form_error_container"></div>
|
||||
<small class="text-muted">Allowed: PDF, DOC, DOCX. Max size: 5MB.</small>
|
||||
<?php if (!empty($insurer['insurer_claim_form']) && !empty($insurer['id'])): ?>
|
||||
<div class="mt-2">
|
||||
<a href="<?= base_url('master/insurer/download-claim-form/' . $insurer['id']) ?>" class="btn btn-sm btn-outline-primary" target="_blank">
|
||||
<i class="mdi mdi-download"></i> Download Claim Form
|
||||
</a>
|
||||
<small class="text-muted d-block mt-1"><?= esc($insurer['insurer_claim_form_original_name'] ?? $insurer['insurer_claim_form']) ?></small>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Buttons -->
|
||||
<div class="form-group row">
|
||||
<div class="col-md-12 text-right">
|
||||
@ -240,10 +267,47 @@ input:checked + .slider:before {
|
||||
}
|
||||
});
|
||||
|
||||
// Custom Parsley validator for insurer claim form file size
|
||||
window.Parsley.addValidator('insurerClaimMaxFileSize', {
|
||||
validateString: function(value, maxSize, parsleyInstance) {
|
||||
if (!window.FileReader) {
|
||||
return true;
|
||||
}
|
||||
var files = parsleyInstance.$element[0].files;
|
||||
if (files.length == 0) {
|
||||
return true;
|
||||
}
|
||||
return files[0].size <= maxSize * 1024;
|
||||
},
|
||||
requirementType: 'integer',
|
||||
messages: {
|
||||
en: 'This file should not be larger than %s KB.'
|
||||
}
|
||||
});
|
||||
|
||||
// Custom Parsley validator for insurer claim form file extension
|
||||
window.Parsley.addValidator('insurerClaimFileExtension', {
|
||||
validateString: function(value, requirement, parsleyInstance) {
|
||||
var file = parsleyInstance.$element[0].files[0];
|
||||
if (!file) { return true; }
|
||||
var extensions = requirement.split(',').map(function(ext) { return ext.trim().toLowerCase(); });
|
||||
var fileExtension = file.name.split('.').pop().toLowerCase();
|
||||
return extensions.indexOf(fileExtension) !== -1;
|
||||
},
|
||||
requirementType: 'string',
|
||||
messages: {
|
||||
en: 'Allowed extensions are: %s.'
|
||||
}
|
||||
});
|
||||
|
||||
$('#insurer_logo').on('change', function() {
|
||||
PreviewImage();
|
||||
});
|
||||
|
||||
$('#insurer_claim_form').on('change', function() {
|
||||
validateInsurerClaimFormFile(true);
|
||||
});
|
||||
|
||||
$("#insurer_general_form").submit(function(events) {
|
||||
|
||||
events.preventDefault();
|
||||
@ -251,6 +315,10 @@ input:checked + .slider:before {
|
||||
if (!validateInsurerLogoFile(true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!validateInsurerClaimFormFile(true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// var isValid = $('#insurer_General_PrimaryKey').parsley().validate();
|
||||
var isValid = $('#insurer_general_form').parsley().validate();
|
||||
@ -430,6 +498,45 @@ input:checked + .slider:before {
|
||||
$('#logo_error_container').empty();
|
||||
return true;
|
||||
}
|
||||
|
||||
function resetInsurerClaimFormInput() {
|
||||
var fileInput = document.getElementById("insurer_claim_form");
|
||||
fileInput.value = "";
|
||||
$('#claim_form_error_container').empty();
|
||||
}
|
||||
|
||||
function validateInsurerClaimFormFile(showToastr) {
|
||||
var fileInput = document.getElementById("insurer_claim_form");
|
||||
if (!fileInput.files || !fileInput.files[0]) {
|
||||
return true;
|
||||
}
|
||||
|
||||
var file = fileInput.files[0];
|
||||
var fileName = file.name.toLowerCase();
|
||||
var parts = fileName.split('.');
|
||||
var allowedExtensions = /(\.pdf|\.doc|\.docx)$/i;
|
||||
|
||||
if (!allowedExtensions.exec(fileName) || parts.length > 2) {
|
||||
$('#claim_form_error_container').html('<ul class="parsley-errors-list filled"><li class="parsley-required">Only PDF, DOC, and DOCX files are allowed.</li></ul>');
|
||||
if (showToastr) {
|
||||
toastr.warning("Only PDF, DOC, and DOCX files are allowed.", "Invalid file type");
|
||||
}
|
||||
resetInsurerClaimFormInput();
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((file.size / 1024) > 5120) {
|
||||
$('#claim_form_error_container').html('<ul class="parsley-errors-list filled"><li class="parsley-required">File size should not exceed 5MB.</li></ul>');
|
||||
if (showToastr) {
|
||||
toastr.warning("File size should not exceed 5MB.", "Invalid file size");
|
||||
}
|
||||
resetInsurerClaimFormInput();
|
||||
return false;
|
||||
}
|
||||
|
||||
$('#claim_form_error_container').empty();
|
||||
return true;
|
||||
}
|
||||
//-----------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
BIN
writable/insurer_claim_form/Claim_Form_IRDAI.pdf
Normal file
BIN
writable/insurer_claim_form/Claim_Form_IRDAI.pdf
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user