diff --git a/app/Models/Study.php b/app/Models/Study.php index 7d88ccb..7fb1141 100644 --- a/app/Models/Study.php +++ b/app/Models/Study.php @@ -15,6 +15,7 @@ use Illuminate\Support\Str; use Spatie\MediaLibrary\HasMedia; use Spatie\MediaLibrary\InteractsWithMedia; +use Spatie\MediaLibrary\MediaCollections\Models\Media; class Study extends BaseModel implements HasMedia { @@ -22,6 +23,7 @@ class Study extends BaseModel implements HasMedia use InteractsWithMedia; public const string MEDIA_COLLECTION = 'attachments'; + public const string FALLBACK_IMAGE = 'imgs/pdf.png'; public function details(): HasOne { @@ -265,6 +267,26 @@ public function getPriorityIcon(): string }; } + public function registerMediaConversions(?Media $media = null): void + { + // $media->extension + $this->addMediaConversion('tn') + ->width(48) + ->height(48) + ->sharpen(10) + ->performOnCollections(Study::MEDIA_COLLECTION) + ->nonQueued(); + } + + public function registerMediaCollections(): void + { + $this->addMediaCollection(self::MEDIA_COLLECTION) + ->useFallbackUrl(asset(self::FALLBACK_IMAGE)) + ->useFallbackUrl(asset(self::FALLBACK_IMAGE), 'tn') + ->useFallbackPath(public_path(self::FALLBACK_IMAGE)) + ->useFallbackPath(public_path(self::FALLBACK_IMAGE), 'tn'); + } + protected function casts(): array { return [ diff --git a/app/helpers.php b/app/helpers.php index d24fc58..ad826bc 100644 --- a/app/helpers.php +++ b/app/helpers.php @@ -2,6 +2,7 @@ use App\Models\User; use App\Services\AuditTrail\ActivityLogger; +use Spatie\MediaLibrary\MediaCollections\Models\Media; if (! function_exists('_h')) { function _h(int $key): string @@ -72,10 +73,11 @@ function may(BackedEnum|iterable|string $perm): bool return auth()->user()->can($perm); } } + if (! function_exists('human_filesize')) { function human_filesize(int $bytes, $dec = 0): string { - $size = ['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']; + $size = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']; $factor = floor((strlen($bytes) - 1) / 3); if ($factor == 0) { $dec = 0; @@ -84,3 +86,28 @@ function human_filesize(int $bytes, $dec = 0): string return sprintf("%.{$dec}f %s", $bytes / (1024 ** $factor), $size[$factor]); } } + +if (! function_exists('chomp')) { + function chomp(string $s, int $len, int $right = 6): string + { + $length = strlen($s); + if ($length <= ($len + $right)) { + return $s; + } + $start = substr($s, 0, $len); + $end = substr($s, -$right); + + return $start . '...' . $end; + } +} + +if (! function_exists('thumb_url')) { + function thumb_url(Media $media): string + { + if ($media->mime_type === 'application/pdf') { + return asset('imgs/pdf.png'); + } + + return $media->getUrl('tn') ?? asset('imgs/pdf.png'); + } +} diff --git a/resources/imgs/pdf.png b/resources/imgs/pdf.png new file mode 100644 index 0000000..39d5881 Binary files /dev/null and b/resources/imgs/pdf.png differ diff --git a/resources/views/staff/history/edit.blade.php b/resources/views/staff/history/edit.blade.php index c0ec7bb..c0cb7ae 100644 --- a/resources/views/staff/history/edit.blade.php +++ b/resources/views/staff/history/edit.blade.php @@ -12,12 +12,13 @@ @extends('layouts.layoutMaster') -@section('title', 'Worklist') +@section('title', 'Info') @section('vendor-style') @vite([ 'resources/fontawesome/scss/fontawesome.scss', 'resources/fontawesome/scss/light.scss', + 'resources/assets/vendor/libs/dropzone/dropzone.scss' ]) - + @endsection @section('page-script') @endsection @section('content') -

- {{ __('History') }} -

-

Clinical Information

+
+
-
- @csrf - -
Clinical History
-
- -
- +

+ {{ __('History') }} +

-
surgical history
-
- -
- +

Clinical Information

-
lab results
-
- -
- + + @csrf + +
Clinical History
+
+
{!! $details->clinical_history !!}
+
+ -
clinical diagnosis
-
- +
surgical history
+
+
{!! $details->surgical_history !!}
+
+ + +
lab results
+
+
{!! $details->lab_results !!}
+
+ + +
clinical diagnosis
+
+
{!! $details->clinical_diagnosis !!}
+
+ + +
- - -
-

Upload Files

+
+

Attachments

+ + +
+ @csrf +
+ Drop attachments here or click to upload + Allowed files: JPG, PNG, PDF +
+
+ +
+
+ + + + @include('staff.history.partials._uploaded-studies-list', ['study' => $study]) +
- -
-

Uploaded Files

-
    - @foreach ($study->getMedia(\App\Models\Study::MEDIA_COLLECTION) as $media) -
  • - - {{ $media->file_name }} - ({{ $media->human_readable_size }}) - Uploaded on {{ $media->created_at->format('Y-m-d H:i') }} -
    - @csrf - @method('DELETE') - -
    -
  • - @endforeach -
- -
- @csrf -
- @endsection diff --git a/resources/views/staff/history/partials/_uploaded-studies-list.blade.php b/resources/views/staff/history/partials/_uploaded-studies-list.blade.php new file mode 100644 index 0000000..6aa7b48 --- /dev/null +++ b/resources/views/staff/history/partials/_uploaded-studies-list.blade.php @@ -0,0 +1,55 @@ +
+ + + + + + + + + + + + @foreach ($study->getMedia(\App\Models\Study::MEDIA_COLLECTION) as $media) + + + + + + + + + + @endforeach + + + +