Update ReqLogAwal
This commit is contained in:
@@ -246,4 +246,160 @@ class RequestLogController extends Controller
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function requestLogAwal(Request $request)
|
||||
{
|
||||
$data = [
|
||||
'member_id' => $request->member_id,
|
||||
'service_code' => $request->service_code,
|
||||
'organization_id' => $request->organization_id,
|
||||
'organization_name' => !empty($request->organization_name) ? $request->organization_name : null,
|
||||
'address_provider' => !empty($request->address_provider) ? $request->address_provider : null,
|
||||
'submission_date' => $request->submission_date,
|
||||
'corporate_id_partner' => !empty($request->corporate_id_partner) ? $request->corporate_id_partner : [],
|
||||
'specialities_id' => $request->specialities_id,
|
||||
'dppj' => $request->dppj
|
||||
];
|
||||
$validator = Validator::make($request->all(), [
|
||||
'member_id' => 'required',
|
||||
'service_code' => 'required',
|
||||
'submission_date' => 'required',
|
||||
'specialities_id' => 'required',
|
||||
'dppj' => 'required',
|
||||
], [
|
||||
'member_id.required' => trans('Validation.required',['attribute' => 'Member ID']),
|
||||
'service_code.required' => trans('Validation.required',['attribute' => 'Service Code']),
|
||||
'submission_date.required' => trans('Validation.required',['attribute' => 'Submission Date']),
|
||||
'specialities_id.required' => trans('Validation.required',['attribute' => 'Specialities']),
|
||||
'dppj.required' => trans('Validation.required',['attribute' => 'DPJP']),
|
||||
]);
|
||||
if(!empty($request->organization_id))
|
||||
{
|
||||
$validator = Validator::make($request->all(), [
|
||||
'organization_id' => 'required',
|
||||
'member_id' => 'required',
|
||||
'service_code' => 'required',
|
||||
'submission_date' => 'required',
|
||||
'specialities_id' => 'required',
|
||||
'dppj' => 'required',
|
||||
], [
|
||||
'organization_id.required' => trans('Validation.required',['attribute' => 'Provider ID']),
|
||||
'member_id.required' => trans('Validation.required',['attribute' => 'Member ID']),
|
||||
'service_code.required' => trans('Validation.required',['attribute' => 'Service Code']),
|
||||
'submission_date.required' => trans('Validation.required',['attribute' => 'Submission Date']),
|
||||
'specialities_id.required' => trans('Validation.required',['attribute' => 'Specialities']),
|
||||
'dppj.required' => trans('Validation.required',['attribute' => 'DPJP']),
|
||||
]);
|
||||
}
|
||||
if ($validator->fails())
|
||||
{
|
||||
return ApiResponse::apiResponse('Bad Request', $data, $validator->errors(), 400);
|
||||
}
|
||||
else
|
||||
{
|
||||
//insert data to organization
|
||||
try {
|
||||
if (!empty($request->organization_name) && !empty($request->address_provider))
|
||||
{
|
||||
// Memulai transaksi
|
||||
DB::beginTransaction();
|
||||
|
||||
// Membuat singkatan dari nama rumah sakit
|
||||
$singkatan = "";
|
||||
$words = explode(' ', $request->organization_name);
|
||||
|
||||
foreach ($words as $word) {
|
||||
$singkatan .= strtoupper(substr($word, 0, 2));
|
||||
}
|
||||
|
||||
// Membuat kode organisasi
|
||||
$kodeOrganisasi = "ORG000" . $singkatan;
|
||||
|
||||
// Insert data ke tabel organizations
|
||||
$organization_id = DB::table('organizations')
|
||||
->insertGetId([
|
||||
'name' => $request->organization_name,
|
||||
'code' => $kodeOrganisasi,
|
||||
'type' => 'hospital',
|
||||
'corporate_id_partner' => $request->corporate_id_partner ? implode(',', $request->corporate_id_partner) : null,
|
||||
'created_at' => now(),
|
||||
// 'created_by' => auth()->user()->id
|
||||
]);
|
||||
|
||||
// Insert data ke tabel addresses
|
||||
$address_id = DB::table('addresses')
|
||||
->insertGetId([
|
||||
'text'=> $request->address_provider,
|
||||
'addressable_type' => 'App\Models\Organization',
|
||||
'addressable_id' => $organization_id,
|
||||
'type' => 'hospital',
|
||||
'created_at' => now(),
|
||||
// 'created_by' => auth()->user()->id
|
||||
]);
|
||||
|
||||
// Update main_address_id di tabel organizations
|
||||
DB::table('organizations')
|
||||
->where('organizations.id', '=', $organization_id)
|
||||
->update(['main_address_id' => $address_id]);
|
||||
|
||||
// Commit transaksi
|
||||
DB::commit();
|
||||
$request->merge(['organization_id' => $organization_id]);
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
DB::beginTransaction();
|
||||
|
||||
$requestLogControllerInstance = new PrimeCenterRequestLog();
|
||||
$code = $requestLogControllerInstance->getNextCode($request);
|
||||
|
||||
$member = Member::find($request->member_id);
|
||||
|
||||
$requestLogData = [
|
||||
'code' => $code,
|
||||
'member_id' => $request->member_id,
|
||||
'submission_date' => $request->submission_date ?? now(),
|
||||
'status' => 'requested',
|
||||
'payment_type' => 'cashless',
|
||||
'service_code' => $request->service_code,
|
||||
'policy_id' => $member->currentPolicy->id ?? null,
|
||||
'organization_id' => $request->organization_id ?? 0,
|
||||
'source' => $request->source,
|
||||
'specialities_id' => $request->specialities_id,
|
||||
'dppj' => $request->dppj
|
||||
];
|
||||
|
||||
// SIMPAN LOG
|
||||
$requestLog = RequestLog::create($requestLogData);
|
||||
|
||||
DB::commit();
|
||||
|
||||
return ApiResponse::apiResponse(
|
||||
'Success Create Log',
|
||||
$requestLog,
|
||||
'Berhasil create LOG dan Benefit',
|
||||
200
|
||||
);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
|
||||
DB::rollBack();
|
||||
|
||||
return ApiResponse::apiResponse(
|
||||
'Server Error Create Log',
|
||||
$data,
|
||||
$e->getMessage(),
|
||||
500
|
||||
);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
// Rollback transaksi jika terjadi kesalahan
|
||||
DB::rollBack();
|
||||
|
||||
// Handle error, bisa di-log atau dikembalikan sebagai response
|
||||
return ApiResponse::apiResponse('Server Error 3', $data, $e->getMessage(), 500);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +37,10 @@ Route::prefix('v1')->group(function () {
|
||||
|
||||
// Request LOG
|
||||
Route::controller(RequestLogController::class)->group(function () {
|
||||
//Final
|
||||
Route::post('request-log', 'requestLog');
|
||||
//Awal
|
||||
Route::post('request-log-awal', 'requestLogAwal');
|
||||
});
|
||||
|
||||
Route::post('calculate-benefit', [MemberController::class, 'calculateBenefit']);
|
||||
|
||||
Reference in New Issue
Block a user