Import Claim Request
This commit is contained in:
@@ -19,7 +19,7 @@ class ClaimRequestController extends Controller
|
||||
* Display a listing of the resource.
|
||||
* @return Renderable
|
||||
*/
|
||||
private static $code_prefix = 'CP';
|
||||
private static $code_prefix = 'CLAIM';
|
||||
public function index()
|
||||
{
|
||||
return view('client::index');
|
||||
@@ -224,10 +224,6 @@ class ClaimRequestController extends Controller
|
||||
|
||||
public static function getNextCode()
|
||||
{
|
||||
// $last_number = ClaimRequest::max('code');
|
||||
// $next_number = empty($last_number) ? 1 : ((int) explode('-', $last_number)[2] + 1);
|
||||
// return self::makeCode($next_number);
|
||||
|
||||
$last_numeric_code = ClaimRequest::select(DB::raw('MAX(CAST(SUBSTRING_INDEX(code, "-", -1) AS SIGNED)) as max_numeric_code'))
|
||||
->whereRaw('SUBSTRING_INDEX(code, "-", -1) REGEXP "^[0-9]+$"')
|
||||
->value('max_numeric_code');
|
||||
@@ -247,8 +243,14 @@ class ClaimRequestController extends Controller
|
||||
{
|
||||
// Pastikan $next_number adalah integer positif
|
||||
$next_number = max(1, (int) $next_number);
|
||||
|
||||
$requestLogData = RequestLog::where('id', $request_log_id)->first();
|
||||
$organization = Organization::where(['id' => $requestLogData->organization_id, 'type' => 'hospital'])->first('code');
|
||||
$provideCode = $organization ? $organization->code : '';
|
||||
$member = Member::with('currentCorporate')->where(['id' => $requestLogData->member_id])->first();
|
||||
$sparator = '.';
|
||||
$date = date('ymd');
|
||||
// Menghasilkan kode dengan format yang diinginkan
|
||||
return self::$code_prefix . '-' . str_pad($next_number, 5, '0', STR_PAD_LEFT);
|
||||
return self::$code_prefix . $sparator. 'H' . $sparator. $provideCode . $sparator. $date. $sparator . $member->currentPolicy->code . $sparator. $member->member_id . $sparator. str_pad($next_number, 6, '0', STR_PAD_LEFT);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -276,7 +276,6 @@ class ClaimRequestController extends Controller
|
||||
$date = date('ymd');
|
||||
// Menghasilkan kode dengan format yang diinginkan
|
||||
return self::$code_prefix . $sparator. 'H' . $sparator. $provideCode . $sparator. $date. $sparator . $member->currentPolicy->code . $sparator. $member->member_id . $sparator. str_pad($next_number, 5, '0', STR_PAD_LEFT);
|
||||
return self::$code_prefix . '.' . str_pad($next_number, 6, '0', STR_PAD_LEFT);
|
||||
}
|
||||
|
||||
public function get_claim_requests(Request $request)
|
||||
|
||||
@@ -25,7 +25,7 @@ use App\Models\Member;
|
||||
|
||||
class ClaimRequestController extends Controller
|
||||
{
|
||||
private static $code_prefix = 'CRQ-C';
|
||||
private static $code_prefix = 'CLAIM';
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
@@ -429,6 +429,7 @@ class ClaimRequestController extends Controller
|
||||
$import = new ImportService();
|
||||
$import->read($fileRead);
|
||||
$import->write($fileWrite, 'xsls');
|
||||
|
||||
foreach ($import->sheetsIterator() as $sheetIndex => $sheet) {
|
||||
if ($sheetIndex == 1) { // Rename First Sheet to Writer
|
||||
$firstWriterSheet = $import->writer->getCurrentSheet();
|
||||
@@ -445,6 +446,8 @@ class ClaimRequestController extends Controller
|
||||
$result_headers = array_merge($result_headers, ['Ingest Code', 'Ingest Note']);
|
||||
|
||||
$import->addArrayToRow($result_headers);
|
||||
|
||||
|
||||
$doc_headers_indexes = [];
|
||||
foreach ($sheet->getRowIterator() as $index => $row) {
|
||||
if ($index == 1) { // First Row Must be Header
|
||||
@@ -465,21 +468,20 @@ class ClaimRequestController extends Controller
|
||||
}
|
||||
try { // Process the Row Data
|
||||
$claimRequestService = new ClaimRequestService();
|
||||
|
||||
$claimRequestService->handleClaimRequestRow($row_data);
|
||||
|
||||
// Write Success Result to File
|
||||
// $import->read($fileRead);
|
||||
// $import->write($fileWrite, 'xsls');
|
||||
$result_headers = array_merge($row_data, ['Ingest Code' =>200, 'Ingest Note' => 'Success']);
|
||||
|
||||
// Mengambil tanggal dari objek DateTime
|
||||
$dateSubmission = Helper::dateParser($result_headers['date_submission']); // Format tanggal sesuai kebutuhan
|
||||
// Mengubah nilai date_submission menjadi string tanggal
|
||||
$result_headers['date_submission'] = $dateSubmission;
|
||||
$import->addArrayToRow($result_headers, $sheet->getName());
|
||||
|
||||
} catch (ImportRowException $e) {
|
||||
// Write Data Validation Error to File
|
||||
// $import->read($fileRead);
|
||||
// $import->write($fileWrite, 'xsls');
|
||||
|
||||
$import->addArrayToRow(array_merge($row_data, [
|
||||
'Ingest Code' => $e->getCode(),
|
||||
'Ingest Note' => $e->getMessage(),
|
||||
@@ -620,10 +622,6 @@ class ClaimRequestController extends Controller
|
||||
|
||||
public static function getNextCode()
|
||||
{
|
||||
// $last_number = ClaimRequest::max('code');
|
||||
// $next_number = empty($last_number) ? 1 : ((int) explode('-', $last_number)[2] + 1);
|
||||
// return self::makeCode($next_number);
|
||||
|
||||
$last_numeric_code = ClaimRequest::select(DB::raw('MAX(CAST(SUBSTRING_INDEX(code, "-", -1) AS SIGNED)) as max_numeric_code'))
|
||||
->whereRaw('SUBSTRING_INDEX(code, "-", -1) REGEXP "^[0-9]+$"')
|
||||
->value('max_numeric_code');
|
||||
@@ -641,11 +639,17 @@ class ClaimRequestController extends Controller
|
||||
|
||||
public static function makeCode($next_number)
|
||||
{
|
||||
// Pastikan $next_number adalah integer positif
|
||||
$next_number = max(1, (int) $next_number);
|
||||
|
||||
// Menghasilkan kode dengan format yang diinginkan
|
||||
return self::$code_prefix . '-' . str_pad($next_number, 5, '0', STR_PAD_LEFT);
|
||||
// Pastikan $next_number adalah integer positif
|
||||
$next_number = max(1, (int) $next_number);
|
||||
$requestLogData = RequestLog::where('id', $request_log_id)->first();
|
||||
$organization = Organization::where(['id' => $requestLogData->organization_id, 'type' => 'hospital'])->first('code');
|
||||
$provideCode = $organization ? $organization->code : '';
|
||||
$member = Member::with('currentCorporate')->where(['id' => $requestLogData->member_id])->first();
|
||||
$sparator = '.';
|
||||
$date = date('ymd');
|
||||
// Menghasilkan kode dengan format yang diinginkan
|
||||
return self::$code_prefix . $sparator. 'H' . $sparator. $provideCode . $sparator. $date. $sparator . $member->currentPolicy->code . $sparator. $member->member_id . $sparator. str_pad($next_number, 6, '0', STR_PAD_LEFT);
|
||||
|
||||
}
|
||||
|
||||
public function requestFiles(Request $request, $claim_id)
|
||||
|
||||
@@ -11,6 +11,7 @@ use Illuminate\Support\Facades\DB;
|
||||
use App\Models\Member;
|
||||
use App\Models\User;
|
||||
use App\Models\Service;
|
||||
use DateTime;
|
||||
|
||||
class Helper
|
||||
{
|
||||
@@ -426,4 +427,20 @@ class Helper
|
||||
ini_set('memory_limit', '256M');
|
||||
}
|
||||
|
||||
public static function dateParser($date_from_row) {
|
||||
if ($date_from_row instanceof DateTime) {
|
||||
return $date_from_row->format('Y-m-d');
|
||||
} else if ($date_from_row != null) {
|
||||
if (strtotime($date_from_row)){
|
||||
return date('Y-m-d', strtotime($date_from_row));
|
||||
} else {
|
||||
// throw new ImportRowException(__('Format Date Invalid'), 0, null, $date_from_row);
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
// throw new ImportRowException(__('Format Date Invalid'), 0, null, $date_from_row);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -52,69 +52,27 @@ class ClaimRequest extends Model
|
||||
];
|
||||
|
||||
public static $doc_headers_to_field_map = [
|
||||
"PAYOR ID" => "payor_id",
|
||||
"CORPORATE ID" => "corporate_id",
|
||||
"POLICY NUMBER" => "policy_number",
|
||||
"MEMBER ID" => "member_id",
|
||||
"MEMBER NAME" => "member_name",
|
||||
"RECORD TYPE (P/D)" => "record_type",
|
||||
"BENEFIT CODE" => "benefit_code",
|
||||
"BENEFIT DESC" => "benefit_desc",
|
||||
"CLAIM TYPE" => "claim_type",
|
||||
"CLAIM PROCESS STATUS" => "status",
|
||||
"CLIENT CLAIM ID" => "client_claim_id",
|
||||
"REFERENCE NO" => "reference_no",
|
||||
"ADMEDIKA CLAIM ID" => "admika_claim_id",
|
||||
"PROVIDER CODE" => "provider_code",
|
||||
"ADMISSION DATE" => "admission_date",
|
||||
"DISCUTRGE DATE" => "discutrge_date",
|
||||
"DURATION DAYS" => "duration_days",
|
||||
"COVERAGE TYPE" => "coverage_type",
|
||||
"PLAN ID" => "plan_id",
|
||||
"DIAGNOSIS CODE" => "diagnosis_code",
|
||||
"DIAGNOSIS DESC" => "diagnosis_desc",
|
||||
"TOT AMT INCURRED" => "tot_amt_insurred",
|
||||
"TOT AMT APPROVED" => "tot_amt_approved",
|
||||
"TOT AMT NOT APPROVED" => "tot_amt_not_approved",
|
||||
"TOT EXCESS PAID" => "tot_excess_paid",
|
||||
"REMARKS" => "remarks",
|
||||
"SECONDARY DIAGNOSIS CODE" => "secondary_diagnosis",
|
||||
"APPROVED DATE" => "approved_date",
|
||||
"APPROVED BY" => "approved_by",
|
||||
"DATE RECEIVED" => "data_received",
|
||||
"HOSPITAL INVOICE DATE" => "hospital_invoice_date",
|
||||
"Code" => "code",
|
||||
"Date Submission" => "date_submission",
|
||||
"Total Billing" => "total_billing",
|
||||
"Benefit Code" => "benefit_code",
|
||||
"Amt Incurred" => "amount_incurred",
|
||||
"Amt Approved" => "amount_apporve",
|
||||
"Amt Not Approved" => "amount_not_apporve",
|
||||
"Excess Paid" => "excess_paid",
|
||||
"QC" => "qc",
|
||||
];
|
||||
|
||||
public static $listing_doc_headers = [
|
||||
"PAYOR ID",
|
||||
"CORPORATE ID",
|
||||
"POLICY NUMBER",
|
||||
"MEMBER ID",
|
||||
"MEMBER NAME",
|
||||
"RECORD TYPE (P/D)",
|
||||
"CLAIM TYPE",
|
||||
"CLAIM PROCESS STATUS",
|
||||
"CLIENT CLAIM ID",
|
||||
"REFERENCE NO",
|
||||
"ADMEDIKA CLAIM ID",
|
||||
"PROVIDER CODE",
|
||||
"ADMISSION DATE",
|
||||
"DISCUTRGE DATE",
|
||||
"DURATION DAYS",
|
||||
"COVERAGE TYPE",
|
||||
"PLAN ID",
|
||||
"DIAGNOSIS CODE",
|
||||
"DIAGNOSIS DESC",
|
||||
"TOT AMT INCURRED",
|
||||
"TOT AMT APPROVED",
|
||||
"TOT AMT NOT APPROVED",
|
||||
"TOT EXCESS PAID",
|
||||
"REMARKS",
|
||||
"SECONDARY DIAGNOSIS CODE",
|
||||
"APPROVED DATE",
|
||||
"APPROVED BY",
|
||||
"DATE RECEIVED",
|
||||
"HOSPITAL INVOICE DATE",
|
||||
"Code",
|
||||
"Date Submission",
|
||||
"Total Billing",
|
||||
"Benefit Code",
|
||||
"Amt Incurred",
|
||||
"Amt Approved",
|
||||
"Amt Not Approved",
|
||||
"Excess Paid",
|
||||
"QC",
|
||||
];
|
||||
|
||||
|
||||
|
||||
@@ -6,6 +6,9 @@ use App\Events\ClaimApproved;
|
||||
use App\Events\ClaimRequested;
|
||||
use App\Models\Claim;
|
||||
use App\Models\ClaimRequest;
|
||||
use App\Models\RequestLog;
|
||||
use App\Models\Benefit;
|
||||
use App\Models\RequestLogBenefit;
|
||||
use App\Models\Organization;
|
||||
use App\Helpers\Helper;
|
||||
use App\Models\Icd;
|
||||
@@ -20,6 +23,7 @@ use Str;
|
||||
|
||||
class ClaimRequestService{
|
||||
|
||||
private static $code_prefix = 'CLAIM';
|
||||
public static function storeClaimRequest($row = null, $code, $member, $paymentType, $serviceCode, $requestLogID = null, $submissionDate = null, $status = 'requested', $organization_code = null)
|
||||
{
|
||||
// try {
|
||||
@@ -36,20 +40,49 @@ class ClaimRequestService{
|
||||
|
||||
DB::beginTransaction();
|
||||
|
||||
if ($status == 'submission'){
|
||||
$claimManagement = 1;
|
||||
$submissionDateClaimManagement = $submissionDate;
|
||||
$submissionByClaimManagement = auth()->user()->id;
|
||||
$statusClaim = 'received';
|
||||
} else {
|
||||
$claimManagement = 0;
|
||||
$submissionDateClaimManagement = null;
|
||||
$submissionByClaimManagement = null;
|
||||
$statusClaim = null;
|
||||
}
|
||||
|
||||
$claimRequestData = [
|
||||
'code' => $code,
|
||||
'request_log_id' => $requestLogID ?? 0,
|
||||
'member_id' => $member->id,
|
||||
'submission_date' => $submissionDate ?? now(),
|
||||
'status' => $status,
|
||||
'claim_management' => $claimManagement,
|
||||
'status_claim_management' => $statusClaim,
|
||||
'submission_date_claim_management' => $submissionDateClaimManagement,
|
||||
'submission_by_claim_management' => $submissionByClaimManagement,
|
||||
'payment_type' => $paymentType,
|
||||
'service_code' => $serviceCode,
|
||||
'policy_id' => $member->currentPolicy->id ?? null,
|
||||
'organization_id' => $organization ? $organization->id : 0,
|
||||
];
|
||||
|
||||
$claimRequest = ClaimRequest::create($claimRequestData);
|
||||
|
||||
$claimRequest = ClaimRequest::updateOrCreate(['request_log_id' => $requestLogID],$claimRequestData);
|
||||
$benefitData = Benefit::where('code', $row['benefit_code'])->first();
|
||||
$requestLogData = RequestLogBenefit::updateOrCreate(
|
||||
[
|
||||
'request_log_id' => $requestLogID,
|
||||
'benefit_id' => $benefitData->id,
|
||||
],[
|
||||
'request_log_id' => $requestLogID,
|
||||
'benefit_id' => $benefitData->id,
|
||||
'amount_incurred' => $row['amount_incurred'],
|
||||
'amount_approved' => $row['amount_apporve'],
|
||||
'amount_not_approved' => $row['amount_not_apporve'],
|
||||
'excess_paid' => $row['excess_paid'],
|
||||
]);
|
||||
|
||||
DB::commit();
|
||||
|
||||
return $claimRequest;
|
||||
@@ -60,8 +93,6 @@ class ClaimRequestService{
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static function storeClaimManagement($row, $member, $claim_request_id){
|
||||
try {
|
||||
$organization = 0;
|
||||
@@ -130,26 +161,49 @@ class ClaimRequestService{
|
||||
}
|
||||
}
|
||||
|
||||
protected function validatePlanRow($row)
|
||||
{
|
||||
if (empty($row['member_id'])) {
|
||||
throw new ImportRowException(__('Member ID Required'), 0, null, $row);
|
||||
}
|
||||
}
|
||||
|
||||
public function handleClaimRequestRow($row)
|
||||
{
|
||||
try {
|
||||
$member = Member::where('member_id', $row['member_id'])->with(['currentPlan'])->first();
|
||||
if(!$member){
|
||||
throw new ImportRowException(__('Member Tidak ditemukan'), 0, null, $row);
|
||||
$requestLog = RequestLog::where('code', $row['code'])->first();
|
||||
if(!$requestLog){
|
||||
throw new ImportRowException(__('LOG Tidak ditemukan'), 0, null, $row);
|
||||
};
|
||||
$code = $row['client_claim_id'];
|
||||
$organization_id = $row['provider_code'];
|
||||
$submissionDate = Helper::formatDateDB($row['admission_date']);
|
||||
$paymentType = $row['claim_type'];
|
||||
$status = $row['status'];
|
||||
$serviceCode = $row['coverage_type'];
|
||||
|
||||
if ($requestLog->status != 'approved' && $requestLog != 'approved'){
|
||||
throw new ImportRowException(__('Request LOG / Final LOG Belum di Approved'), 0, null, $row);
|
||||
}
|
||||
$organization = Organization::where('id', $requestLog->organization_id)->first();
|
||||
|
||||
// Create Code
|
||||
$last_numeric_code = ClaimRequest::select(DB::raw('MAX(CAST(SUBSTRING_INDEX(code, ".", -1) AS SIGNED)) as max_numeric_code'))
|
||||
->whereRaw('SUBSTRING_INDEX(code, ".", -1) REGEXP "^[0-9]+$"')
|
||||
->value('max_numeric_code');
|
||||
// $next_number = 1;
|
||||
if ($last_numeric_code) {
|
||||
// // Jika ada kode sebelumnya, pecah kode dan tambahkan 1 ke angka terakhir
|
||||
// $parts = explode('-', $last_code);
|
||||
// $last_number = (int) end($parts);
|
||||
$next_number = $last_numeric_code + 1;
|
||||
} else {
|
||||
$next_number = 1;
|
||||
}
|
||||
// make code
|
||||
$member = Member::with('currentCorporate')->where(['id' => $requestLog->member_id])->first();
|
||||
$sparator = '.';
|
||||
$date = date('ymd');
|
||||
// Menghasilkan kode dengan format yang diinginkan
|
||||
$code = 'CLAIM' . $sparator. 'I' . $sparator. $organization->code . $sparator. $date. $sparator . $member->currentPolicy->code . $sparator. $member->member_id . $sparator. str_pad($next_number, 5, '0', STR_PAD_LEFT);
|
||||
|
||||
// $code = $row['client_claim_id'];
|
||||
// dd($row['date_submission']);
|
||||
$submissionDate = Helper::dateParser($row['date_submission']);
|
||||
$paymentType = $requestLog->payment_type;
|
||||
if ($row['qc'] == 'Y'){
|
||||
$status = 'submission';
|
||||
} else {
|
||||
$status = 'requested';
|
||||
}
|
||||
$serviceCode = $requestLog->service_code;
|
||||
|
||||
$newClaimRequest = $this->storeClaimRequest(
|
||||
row: $row,
|
||||
@@ -157,26 +211,21 @@ class ClaimRequestService{
|
||||
member: $member,
|
||||
paymentType: $paymentType,
|
||||
serviceCode: $serviceCode,
|
||||
requestLogID: $requestLog->id,
|
||||
submissionDate: $submissionDate,
|
||||
status: $status,
|
||||
organization_code: $organization_id
|
||||
organization_code: $organization->code
|
||||
);
|
||||
|
||||
$newlyCreatedID = $newClaimRequest->id;
|
||||
|
||||
$newClaimManangement = $this->storeClaimManagement($row, $member, $newlyCreatedID);
|
||||
ClaimRequested::dispatch($newClaimRequest);
|
||||
// Log History
|
||||
$newClaimRequest->histories()->create([
|
||||
'title' => 'New Claim Requested',
|
||||
'description' => "Claim Requested for Member : {$member->member_id} - ({$member->full_name})",
|
||||
'type' => 'info',
|
||||
'system_origin' => 'import-internal-aso'
|
||||
]);
|
||||
|
||||
$claim_request_data = $row;
|
||||
$this->validatePlanRow($claim_request_data);
|
||||
|
||||
// $newClaimManangement = $this->storeClaimManagement($row, $member, $newlyCreatedID);
|
||||
// ClaimRequested::dispatch($newClaimRequest);
|
||||
// // Log History
|
||||
// $newClaimRequest->histories()->create([
|
||||
// 'title' => 'New Claim Requested',
|
||||
// 'description' => "Claim Requested for Member : {$member->member_id} - ({$member->full_name})",
|
||||
// 'type' => 'info',
|
||||
// 'system_origin' => 'import-internal-aso'
|
||||
// ]);
|
||||
return $newClaimRequest;
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
|
||||
Reference in New Issue
Block a user