From 77fdb46c46103b30e78bf882dc244853d1692e4c Mon Sep 17 00:00:00 2001 From: ivan-sim Date: Thu, 16 Nov 2023 09:24:31 +0700 Subject: [PATCH] Update pengecekan hospital corporate --- .../Controllers/Api/HospitalController.php | 42 ++++++++++++++----- 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/Modules/Internal/Http/Controllers/Api/HospitalController.php b/Modules/Internal/Http/Controllers/Api/HospitalController.php index 9d2be239..5c9a09e9 100644 --- a/Modules/Internal/Http/Controllers/Api/HospitalController.php +++ b/Modules/Internal/Http/Controllers/Api/HospitalController.php @@ -172,23 +172,45 @@ class HospitalController extends Controller $failedRows = []; foreach ($processedData as $row) { + $q_check = DB::table('corporate_hospitals') + ->where('code', '=', $row['code']) + ->select('code') + ->first(); $q = DB::table('organizations') ->where('code', '=', $row['code']) ->where('type', '=', 'hospital') ->where('status', '=', 'active') ->select('id', 'code', 'name') - ->limit(1) ->first(); try { - CorporateHospital::create( - [ - 'corporate_id' => $corporate_id, - 'code' => $q->code, - 'name' => $q->name, - 'organization_id' => $q->id, - 'description' => $request->description ? $request->description : null, - ] - ); + if($q_check) + { + DB::table('corporate_hospitals') + ->where('code','=', $q_check->code) + ->update( + [ + 'corporate_id' => $corporate_id, + 'code' => $q->code, + 'name' => $q->name, + 'organization_id' => $q->id, + 'description' => $request->description ? $request->description : null, + 'updated_by' =>auth()->user()->id, + 'updated_at' => date('Y-m-d H:i:s'), + ] + ); + } + else + { + CorporateHospital::create( + [ + 'corporate_id' => $corporate_id, + 'code' => $q->code, + 'name' => $q->name, + 'organization_id' => $q->id, + 'description' => $request->description ? $request->description : null, + ] + ); + } $importedRows++; } catch (\Exception $e) { $failedRows[] = $row;