feat: add lab tests, patient file management, and prescription improvements

This commit is contained in:
SajjadMahmoody
2026-04-17 20:15:38 +03:30
parent 6a301c5529
commit bf0ada051f
53 changed files with 3201 additions and 387 deletions
+23
View File
@@ -0,0 +1,23 @@
<?php
declare(strict_types=1);
namespace App\Observers;
use App\Models\PatientIllness;
use Illuminate\Support\Facades\Cache;
class PatientIllnessObserver
{
public function saved(PatientIllness $patientIllness): void
{
Cache::forget('illness_options_1');
Cache::forget('illness_options_2');
}
public function deleted(PatientIllness $patientIllness): void
{
Cache::forget('illness_options_1');
Cache::forget('illness_options_2');
}
}
+40
View File
@@ -0,0 +1,40 @@
<?php
declare(strict_types=1);
namespace App\Observers;
use App\Models\Patient;
use Illuminate\Support\Facades\Storage;
class PatientObserver
{
private const FILE_FIELDS = ['photos_before', 'photos_after', 'videos', 'audio_files'];
public function updating(Patient $patient): void
{
foreach (self::FILE_FIELDS as $field) {
$rawOld = $patient->getRawOriginal($field);
$oldFiles = ! empty($rawOld) ? (json_decode($rawOld, true) ?? []) : [];
$newFiles = array_values((array) ($patient->getAttribute($field) ?? []));
$removed = array_diff($oldFiles, $newFiles);
foreach ($removed as $path) {
if (! empty(trim((string) $path))) {
Storage::disk('public')->delete($path);
}
}
}
}
public function deleting(Patient $patient): void
{
foreach (self::FILE_FIELDS as $field) {
$files = $patient->getAttribute($field) ?? [];
foreach ((array) $files as $path) {
Storage::disk('public')->delete($path);
}
}
}
}