From 95d2f6e507483cb2c46bdba3004d57e30cbfcc21 Mon Sep 17 00:00:00 2001 From: Dwi Swandhana Date: Mon, 9 Mar 2026 07:24:56 +0700 Subject: [PATCH] update --- htdocs/app/CriticalValueSample.php | 12 + .../app/Http/Controllers/DokterController.php | 74 + ...08_create_critical_value_samples_table.php | 42 + .../base/partials/header-plain.blade.php | 58 +- .../views/dokter/pemeriksaan-awal.blade.php | 4235 ----------------- .../views/dokter/pemeriksaan.blade.php | 28 +- htdocs/resources/views/dokter/ppds.blade.php | 28 +- .../notifications/critical-values.blade.php | 125 + htdocs/routes/web.php | 3 + 9 files changed, 340 insertions(+), 4265 deletions(-) create mode 100644 htdocs/app/CriticalValueSample.php create mode 100644 htdocs/database/migrations/2026_03_09_000008_create_critical_value_samples_table.php delete mode 100644 htdocs/resources/views/dokter/pemeriksaan-awal.blade.php create mode 100644 htdocs/resources/views/notifications/critical-values.blade.php diff --git a/htdocs/app/CriticalValueSample.php b/htdocs/app/CriticalValueSample.php new file mode 100644 index 00000000..54d22e37 --- /dev/null +++ b/htdocs/app/CriticalValueSample.php @@ -0,0 +1,12 @@ + 'Selesai', ]; $periksa->update($updateData); + if ($this->shouldMarkAsCritical($request)) { + $this->upsertCriticalValueSample($periksa); + } $surat = self::genSurat($periksa->id, 'dengan kop'); Riwayat::create([ 'nofoto' => $nofoto, @@ -710,6 +714,76 @@ class DokterController extends Controller } } } + protected function shouldMarkAsCritical(Request $request): bool + { + $flag = strtolower((string) $request->input('nilai_kritis', '0')); + + return in_array($flag, ['1', 'true', 'on', 'yes'], true); + } + protected function upsertCriticalValueSample(Periksa $periksa): void + { + $now = Carbon::now(); + $criticalSample = CriticalValueSample::firstOrNew(['periksa_id' => $periksa->id]); + $criticalSample->nofoto = $periksa->nofoto; + $criticalSample->noregister = $periksa->noregister; + $criticalSample->nmpasien = $periksa->nmpasien; + $criticalSample->nm_spesimen = $periksa->nm_spesimen; + + // Keep the first critical timestamp intact on repeated clicks. + if (empty($criticalSample->critical_set_at)) { + $criticalSample->critical_set_at = $now; + $criticalSample->critical_set_by_user_id = Session('id'); + $criticalSample->critical_set_by_name = Session('nama'); + } + + $criticalSample->save(); + } + protected function markCriticalValueAsRead(CriticalValueSample $criticalSample): void + { + if (!empty($criticalSample->followed_up_at)) { + return; + } + + $criticalSample->followed_up_at = Carbon::now(); + $criticalSample->followed_up_by_user_id = Session('id'); + $criticalSample->followed_up_by_name = Session('nama'); + $criticalSample->save(); + } + public function criticalValueNotifications(Request $request) + { + $highlightId = $request->query('highlight'); + $items = CriticalValueSample::whereNull('followed_up_at') + ->orderBy('critical_set_at', 'asc') + ->get(); + $followedItems = CriticalValueSample::whereNotNull('followed_up_at') + ->orderBy('followed_up_at', 'desc') + ->limit(100) + ->get(); + + return view('notifications.critical-values', [ + 'items' => $items, + 'followedItems' => $followedItems, + 'highlightId' => $highlightId, + ]); + } + public function criticalValueNotificationOpen($id) + { + $criticalSample = CriticalValueSample::findOrFail($id); + $this->markCriticalValueAsRead($criticalSample); + + return redirect() + ->route('criticalValueNotifications', ['highlight' => $criticalSample->id]) + ->with('success', 'Sample nilai kritis sudah ditandai sudah ditindaklanjuti.'); + } + public function criticalValueNotificationMarkRead($id) + { + $criticalSample = CriticalValueSample::findOrFail($id); + $this->markCriticalValueAsRead($criticalSample); + + return redirect() + ->route('criticalValueNotifications', ['highlight' => $criticalSample->id]) + ->with('success', 'Sample nilai kritis sudah ditandai sudah ditindaklanjuti.'); + } public function cancelOrder(Request $request) { $val01 = $request->input('alasan'); $getsetting = Setting::where('id', '1')->first(); diff --git a/htdocs/database/migrations/2026_03_09_000008_create_critical_value_samples_table.php b/htdocs/database/migrations/2026_03_09_000008_create_critical_value_samples_table.php new file mode 100644 index 00000000..c695ce36 --- /dev/null +++ b/htdocs/database/migrations/2026_03_09_000008_create_critical_value_samples_table.php @@ -0,0 +1,42 @@ +id(); + $table->unsignedBigInteger('periksa_id')->unique(); + $table->string('nofoto', 50)->nullable(); + $table->string('noregister', 150)->nullable(); + $table->string('nmpasien', 200)->nullable(); + $table->string('nm_spesimen', 255)->nullable(); + $table->timestamp('critical_set_at')->nullable(); + $table->unsignedBigInteger('critical_set_by_user_id')->nullable(); + $table->string('critical_set_by_name', 150)->nullable(); + $table->timestamp('followed_up_at')->nullable(); + $table->unsignedBigInteger('followed_up_by_user_id')->nullable(); + $table->string('followed_up_by_name', 150)->nullable(); + $table->timestamps(); + + $table->index('nofoto'); + $table->index('critical_set_at'); + $table->index('followed_up_at'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('critical_value_samples'); + } +}; diff --git a/htdocs/resources/views/base/partials/header-plain.blade.php b/htdocs/resources/views/base/partials/header-plain.blade.php index 1c69616a..a37508b7 100644 --- a/htdocs/resources/views/base/partials/header-plain.blade.php +++ b/htdocs/resources/views/base/partials/header-plain.blade.php @@ -1,3 +1,14 @@ +@php + $criticalNotificationCount = 0; + $criticalNotificationItems = collect(); + if (Session::get('id') !== null) { + $criticalNotificationCount = \App\CriticalValueSample::whereNull('followed_up_at')->count(); + $criticalNotificationItems = \App\CriticalValueSample::whereNull('followed_up_at') + ->orderBy('critical_set_at', 'asc') + ->limit(8) + ->get(); + } +@endphp
@@ -20,21 +31,40 @@
- @if(Session::get('id') !== null) - @if (isset($antrkrmsitu)) - - @endif +
+ @if($criticalNotificationItems->isEmpty()) + + @else + @foreach($criticalNotificationItems as $criticalItem) + +
+

+ {{ $criticalItem->nofoto ?? '-' }} - {{ $criticalItem->nmpasien ?? 'Tanpa Nama' }} + + Set: {{ $criticalItem->critical_set_at ? \Carbon\Carbon::parse($criticalItem->critical_set_at)->format('d-m-Y H:i:s') : '-' }} + +

+
+ @endforeach + @endif +
+
+ + @if(Session::get('id') !== null)