From b7efd18571c563b33300a0481ab98014d7ef9ed3 Mon Sep 17 00:00:00 2001 From: Masroor Ehsan Date: Mon, 6 Jan 2025 17:56:09 +0600 Subject: [PATCH] wip - attachments --- app/Models/Study.php | 22 +++ app/helpers.php | 29 ++- resources/imgs/pdf.png | Bin 0 -> 1537 bytes resources/views/staff/history/edit.blade.php | 171 ++++++++++-------- .../partials/_uploaded-studies-list.blade.php | 55 ++++++ 5 files changed, 203 insertions(+), 74 deletions(-) create mode 100644 resources/imgs/pdf.png create mode 100644 resources/views/staff/history/partials/_uploaded-studies-list.blade.php 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 0000000000000000000000000000000000000000..39d5881094ec77cb238542ca8000cd1eba4a39fb GIT binary patch literal 1537 zcmX|Ac{tR082|oe41=7B4mOotc2|0|m9m~S$&`5-M^YKpx>l`o#MCI)53MvwmnK(C zt4Go$Dn;?59672%lN!k|DMEAK$NqYHo_(Irdwt&HpZ9%F1_f+0Gg)c^05Bu@`39pF z{w8=VswLy+l&Ha``jA5Kcs!REIF5$K$$penls)oIpv>2~{V2JFMhvCxq#mHrBU54k zolbX)O^Q#Aj!cemqoy1zpZ8h{0K^U=hYN`{4^rYcY z+x?dI)@RS#I(whL80=+_^bd~o554UldN;s+JvcJP;eOzL;EhjynGet68*Vd6iyaJ_=_R~L{WjF z=pa$_4pB_7IChUXE>s*(5yyv#6T-wv`^D7#;zJSQlt?ixT5>o>a^!&ISezt1L6VUm z$xM=Dp`c20Qlz;wX&y~_{IK*Ny7a_RX~8k+$#f|rQ+g^>R+ud-f@MWHva@-z3;D9* z0vYq9jLDFfo|cyt$;;2kE6>X-FUVOJca@MIB3dw^rG3UD&AGI@|v@@TzvopH+S)E{BC;X}t33MW% zPAt+%P>6L>iB2KcDHM98La$QlRVuw&t=FjaIvu*r>HKT6=mnV5f&+E}XsJ_DR!ze_ zWNKV6hvgzGIu3{1 zcXvK`5pjnlk$9K?rYyGXLF@?*f2>rvWh`)%6fpI3X*qVf^ybZV&kv_RW(?fy!8mhw z)sCF8aP4`q$5EJrbHm|*Ns4JZC_!!^kYkP!7Feb203at9TfYXujM%cESrY-+fGYs$ z7&5#X`UNQhb`e|P1@&%-VW=$&d(%V!+2ZU0$G{6P4fcWE1{uKCAP9-81tu;c2p2@S zYvBT8>UN_p96XP#xpcEWJ9nxYzo~afrFF0PDKS5+7meiz&fe z0Zf7`yuxyU-=YG;tN7#C^SB9!gfRw<1VhB>EXL2K2XewYK@%7XTtZliSoUCjan?{X z;U~wHXH8g`N5J242`i-6(8YY*+knqsWEl`!duL!l4~4YxKxX1r!VkPMRUwRNh4TwR z$0lSs9FPp5^IXIlV=iz*L>|x_7=D=cj?zcGC?5+n}x24xa=ZOPv zH+2TKx!ZZ~H#73+fb!y^S}WMz`r=sH?e2{&iEJ9-3Err%?2aPU!y&=lqHcRrxuntJ zM~BZHP=Ws@ zy?{2P6PN<8L57tf>oTXM&`n|EFW9&i@g}dyu7m`7#)A`&%-tHRgRwiud0r3@5W*QsCGM!LTAG&Z$N3#?+> zbCctW57g4nxR)5PUOGz|1)spOyFr=J;h%p4<+Z`J!qr8?^2V4=onlA0ALSJSma8e~r2C#&jC cY}RK(!&S?(oQv{X(QgGLVu0^$pNQQ50JSq5Y5)KL literal 0 HcmV?d00001 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 + + + +