diff --git a/app/Http/Controllers/Guest/ViewSharedStudyController.php b/app/Http/Controllers/Guest/ViewSharedStudyController.php new file mode 100644 index 0000000..7211534 --- /dev/null +++ b/app/Http/Controllers/Guest/ViewSharedStudyController.php @@ -0,0 +1,29 @@ +decodeKeys(); + $share = SharedStudy::findOrFail($this->key); + abort_if($share->hasExpired(), 404); + + if ($share->isPasswordProtected()) { + return view('guest.shared-study.auth', compact('share')); + } + + return view('guest.shared-study.show', compact('share')); + } + + public function auth(SharedStudyPasswordRequest $request) + { + $this->decodeKeys(); + $share = SharedStudy::findOrFail($this->key); + abort_if(! $share->attempt($request->password), 403); + } +} diff --git a/app/Http/Controllers/HashidActionControllerBase.php b/app/Http/Controllers/HashidActionControllerBase.php new file mode 100644 index 0000000..82c10a3 --- /dev/null +++ b/app/Http/Controllers/HashidActionControllerBase.php @@ -0,0 +1,30 @@ +hashid = request('hashid'); + + try { + $this->key = unhash_it($this->hashid); + } catch (Throwable $exception) { + captureException($exception); + abort(404); + } + + return $this->handle(); + } + + abstract protected function handle(); +} diff --git a/app/Http/Requests/Guest/SharedStudyPasswordRequest.php b/app/Http/Requests/Guest/SharedStudyPasswordRequest.php new file mode 100644 index 0000000..96050e6 --- /dev/null +++ b/app/Http/Requests/Guest/SharedStudyPasswordRequest.php @@ -0,0 +1,20 @@ + 'required|string|min:4', + ]; + } + + public function authorize(): bool + { + return true; + } +} diff --git a/app/Models/SharedStudy.php b/app/Models/SharedStudy.php index 45a7a0e..51f0179 100644 --- a/app/Models/SharedStudy.php +++ b/app/Models/SharedStudy.php @@ -29,4 +29,27 @@ protected function casts(): array 'access_flags' => StudyAccessFlags::class, ]; } + + public function isPasswordProtected(): bool + { + return ! blank($this->access_password); + } + + public function attempt(string $password): bool + { + if (! $this->isPasswordProtected()) { + return true; + } + + return strcmp($this->access_password, $password) === 0; + } + + public function hasExpired(): bool + { + if (blank($this->expires_at)) { + return false; + } + + return $this->expires_at->isPast(); + } } diff --git a/app/helpers.php b/app/helpers.php index 9a86598..1689725 100644 --- a/app/helpers.php +++ b/app/helpers.php @@ -1,7 +1,7 @@ - Accession Number - Patient ID - Patient Name - Patient Sex - Patient Birth Date - Modality - Study Date - Receive Date - Series - Institute Name -   + + Accession Number + + + Patient ID + + + Patient Name + + + Patient Sex + + + Patient Birth Date + + + Modality + + Study + Date + + + Receive Date + + + Series + + + Institute Name + + +   + @@ -30,29 +63,38 @@ {{ $study->accession_number }} {{ $study->patient_id }} - {{ $study->patient_name }} + {{ $study->patient_name }} + {{ $study->patient_sex }} {{ $study->patient_birthdate }} {{ $study->study_modality }} {{ $study->study_date }} {{ $study->receive_date }} - {{ $study->image_count }} / {{ $study->series_count }} + {{ $study->image_count }} + / {{ $study->series_count }} {{ $study->institution_name }} - St + St | - OHF + OHF @if($study->image_count > 1 && $study->study_modality != 'CR') | - MPR + MPR | - SEG + SEG @endif | - ZIP + ZIP | - TXT + TXT diff --git a/routes/web.php b/routes/web.php index 91196c6..16d034b 100644 --- a/routes/web.php +++ b/routes/web.php @@ -1,5 +1,6 @@ 'shares', 'as' => 'shares.'], function () { + Route::get('study/{hashid}', [ViewSharedStudyController::class, 'show'])->name('show'); + Route::post('auth/{hashid}', [ViewSharedStudyController::class, 'auth'])->name('auth'); +}); + Route::view('/ck', 'ck');