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
+269 -3
View File
@@ -133,12 +133,10 @@ @media (max-width: 639px) {
}
}
/* Hide FilePond dropzone in view-only file upload fields */
[data-hide-dropzone] .filepond--drop-label {
display: none !important;
}
/* Re-enable pointer events for media player controls inside disabled fields */
[data-hide-dropzone] .filepond--item,
[data-hide-dropzone] .filepond--file-wrapper,
[data-hide-dropzone] .filepond--media-preview-wrapper,
@@ -150,7 +148,6 @@ [data-hide-dropzone] .audioplayer {
pointer-events: auto !important;
}
/* Lift speed button above any overlay */
[data-hide-dropzone] .filepond--media-player-button-playbackrate {
position: relative !important;
z-index: 10 !important;
@@ -199,3 +196,272 @@ .fi-pagination .fi-pagination-records-per-page-select-ctn {
display: flex !important;
justify-content: flex-end !important;
}
.ProseMirror p {
margin-top: 0;
margin-bottom: 0;
min-height: 1.4em;
}
.fi-modal-content .prose p,
[dir="rtl"] .prose p {
margin-top: 0.1em;
margin-bottom: 0.1em;
}
.fi-photo-gallery .filepond--root {
min-height: 60px !important;
margin-top: 8px !important;
overflow: visible !important;
}
.fi-photo-gallery-view .filepond--root,
[data-hide-dropzone] .filepond--root {
background-color: transparent !important;
border: none !important;
box-shadow: none !important;
}
.fi-photo-gallery .filepond--list {
position: relative !important;
transform: none !important;
display: flex !important;
flex-wrap: wrap !important;
gap: 6px !important;
padding: 8px !important;
height: auto !important;
}
.fi-photo-gallery .filepond--item {
display: block !important;
position: relative !important;
transform: none !important;
width: 100px !important;
height: 56px !important;
margin: 0 !important;
overflow: hidden !important;
border-radius: 6px !important;
flex-shrink: 0 !important;
}
.fi-photo-gallery .filepond--image-preview-wrapper {
position: absolute !important;
top: 0 !important;
left: 0 !important;
width: 100% !important;
height: 100% !important;
max-height: none !important;
margin-top: 0 !important;
}
.fi-photo-gallery .filepond--image-preview-overlay,
.fi-photo-gallery .filepond--image-preview {
height: 56px !important;
max-height: 56px !important;
}
.fi-photo-gallery .filepond--image-preview canvas {
width: 100% !important;
height: 100% !important;
object-fit: cover !important;
}
.fi-photo-gallery .filepond--panel-root,
.fi-photo-gallery .filepond--panel-top,
.fi-photo-gallery .filepond--panel-center,
.fi-photo-gallery .filepond--panel-bottom,
.fi-photo-gallery .filepond--item .filepond--panel {
background-color: transparent !important;
border: none !important;
box-shadow: none !important;
}
.fi-photo-gallery .filepond--file {
padding: 0 !important;
}
.fi-photo-gallery .filepond--file-action-button {
width: 1.4rem !important;
height: 1.4rem !important;
}
.fi-photo-gallery .filepond--file-info {
display: none !important;
}
.fi-photo-gallery .filepond--drop-label {
margin-top: 10px !important;
}
.fi-video-gallery .filepond--root {
min-height: 60px !important;
margin-top: 8px !important;
overflow: visible !important;
}
.fi-video-gallery .filepond--list {
position: relative !important;
transform: none !important;
display: flex !important;
flex-wrap: wrap !important;
gap: 6px !important;
padding: 8px !important;
height: auto !important;
}
.fi-video-gallery .filepond--item {
display: block !important;
position: relative !important;
transform: none !important;
width: 160px !important;
height: 90px !important;
margin: 0 !important;
overflow: hidden !important;
border-radius: 6px !important;
flex-shrink: 0 !important;
background-color: #111 !important;
}
.fi-video-gallery .filepond--media-preview-wrapper,
.fi-video-gallery .filepond--media-preview {
width: 100% !important;
height: 100% !important;
position: absolute !important;
top: 0 !important;
left: 0 !important;
}
.fi-video-gallery .filepond--media-preview video {
width: 100% !important;
height: 100% !important;
object-fit: cover !important;
}
.fi-video-gallery .filepond--item .filepond--panel {
background-color: transparent !important;
border: none !important;
box-shadow: none !important;
}
.fi-video-gallery .filepond--file {
padding: 0 !important;
}
.fi-video-gallery .filepond--file-info {
display: none !important;
}
.fi-video-gallery .filepond--file-action-button {
width: 1.4rem !important;
height: 1.4rem !important;
}
.fi-video-gallery .filepond--drop-label {
margin-top: 10px !important;
}
.fi-photo-gallery-view .filepond--file-action-button.filepond--action-remove-item,
.fi-photo-gallery-view .filepond--file-action-button.filepond--action-revert-item-processing,
.fi-photo-gallery-view .filepond--file-action-button.filepond--action-abort-item-load,
[data-hide-dropzone] .filepond--file-action-button.filepond--action-remove-item,
[data-hide-dropzone] .filepond--file-action-button.filepond--action-revert-item-processing,
[data-hide-dropzone] .filepond--file-action-button.filepond--action-abort-item-load {
display: none !important;
}
#fi-lightbox {
position: fixed;
inset: 0;
z-index: 9999;
display: flex;
align-items: center;
justify-content: center;
background: rgba(0, 0, 0, 0.92);
opacity: 0;
pointer-events: none;
transition: opacity 0.25s ease;
direction: ltr;
}
#fi-lightbox.lb-open {
opacity: 1;
pointer-events: all;
}
#fi-lb-wrap {
position: relative;
display: flex;
align-items: center;
justify-content: center;
width: 100%;
height: 100%;
overflow: hidden;
}
#fi-lb-img {
max-width: 90vw;
max-height: 90vh;
object-fit: contain;
border-radius: 4px;
transition: opacity 0.15s ease, transform 0.2s ease;
transform-origin: center center;
user-select: none;
pointer-events: none;
cursor: default;
}
#fi-lb-img.lb-zoomed {
pointer-events: auto;
cursor: grab;
}
#fi-lb-img.lb-zoomed.lb-dragging {
cursor: grabbing;
transition: opacity 0.15s ease;
}
#fi-lb-close {
position: absolute;
top: 1rem;
right: 1rem;
z-index: 10;
width: 2.5rem;
height: 2.5rem;
border-radius: 50%;
background: rgba(255, 255, 255, 0.15);
border: none;
color: white;
font-size: 1.25rem;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
transition: background 0.2s;
line-height: 1;
}
#fi-lb-close:hover {
background: rgba(255, 255, 255, 0.35);
}
#fi-lb-prev,
#fi-lb-next {
position: absolute;
top: 50%;
transform: translateY(-50%);
z-index: 10;
width: 3rem;
height: 3rem;
border-radius: 50%;
background: rgba(255, 255, 255, 0.15);
border: none;
color: white;
font-size: 1.75rem;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
transition: background 0.2s;
line-height: 1;
}
#fi-lb-prev { left: 1rem; }
#fi-lb-next { right: 1rem; }
#fi-lb-prev:hover,
#fi-lb-next:hover {
background: rgba(255, 255, 255, 0.35);
}
#fi-lb-counter {
position: absolute;
bottom: 1.25rem;
left: 50%;
transform: translateX(-50%);
color: rgba(255, 255, 255, 0.85);
font-size: 0.875rem;
background: rgba(0, 0, 0, 0.45);
padding: 0.2rem 0.75rem;
border-radius: 9999px;
pointer-events: none;
white-space: nowrap;
}
#fi-lb-hint {
position: absolute;
bottom: 1.25rem;
right: 1.5rem;
color: rgba(255, 255, 255, 0.35);
font-size: 0.7rem;
pointer-events: none;
direction: rtl;
}
@@ -62,6 +62,13 @@
'url' => \App\Filament\Resources\MedicationResource::getUrl('index'),
'permission' => 'ViewAny:Medication',
],
[
'title' => __('navigation.lab_tests.title'),
'description' => __('navigation.lab_tests.description'),
'icon' => 'heroicon-o-beaker',
'url' => \App\Filament\Resources\LabTestResource::getUrl('index'),
'permission' => 'ViewAny:LabTest',
],
],
],
[
@@ -51,6 +51,125 @@
</div>
</x-filament::card>
<x-filament::card>
<div
x-data="{
dragging: false,
fileName: '',
fileSize: '',
uploading: false,
uploaded: false,
uploadProgress: 0,
setFile(file) {
this.fileName = file.name;
this.fileSize = (file.size / 1024 / 1024).toFixed(2) + ' MB';
this.uploading = true;
this.uploaded = false;
this.uploadProgress = 0;
$wire.upload(
'sqlFile',
file,
() => { this.uploading = false; this.uploaded = true; this.uploadProgress = 100; },
() => { this.uploading = false; this.uploaded = false; this.fileName = ''; this.uploadProgress = 0; },
(event) => { if (event && event.detail) this.uploadProgress = event.detail.progress; }
);
}
}"
class="space-y-4"
>
<div class="flex items-center gap-2">
<x-heroicon-o-arrow-up-tray class="w-5 h-5 text-amber-500" />
<h3 class="font-semibold text-base text-gray-800 dark:text-gray-200">
{{ __('navigation.import.label') }}
</h3>
</div>
<p class="text-sm text-gray-500 dark:text-gray-400">
{{ __('navigation.import.confirm_description') }}
</p>
{{-- File drop zone --}}
<div
@dragover.prevent="dragging = true"
@dragleave.prevent="dragging = false"
@drop.prevent="
dragging = false;
const file = $event.dataTransfer.files[0];
if (file) setFile(file);
"
class="relative border-2 border-dashed rounded-xl p-6 text-center transition-colors"
:class="dragging
? 'border-amber-400 bg-amber-50 dark:bg-amber-900/20'
: 'border-gray-300 dark:border-gray-600 hover:border-amber-400 dark:hover:border-amber-500'"
>
<input
x-ref="fileInput"
type="file"
accept=".sql,.txt"
class="absolute inset-0 opacity-0 cursor-pointer w-full h-full"
x-on:change="
const file = $event.target.files[0];
if (file) setFile(file);
"
/>
{{-- Idle state --}}
<div x-show="!fileName" class="space-y-2">
<x-heroicon-o-document-arrow-up class="w-10 h-10 text-gray-400 mx-auto" />
<p class="text-sm font-medium text-gray-600 dark:text-gray-300">
{{ __('navigation.import.drop_or_click') }}
</p>
<p class="text-xs text-gray-400">{{ __('navigation.import.file_hint') }}</p>
</div>
{{-- File selected state --}}
<div x-show="fileName" class="space-y-1">
<x-heroicon-o-document-check class="w-10 h-10 text-amber-500 mx-auto" />
<p class="text-sm font-semibold text-gray-700 dark:text-gray-200" x-text="fileName"></p>
<p class="text-xs text-gray-400" x-text="fileSize"></p>
<p class="text-xs" :class="uploading ? 'text-blue-500' : 'text-amber-600 dark:text-amber-400'">
<span x-show="uploading">{{ __('navigation.import.uploading') }}</span>
<span x-show="!uploading && uploaded">{{ __('navigation.import.file_ready') }}</span>
</p>
</div>
</div>
@error('sqlFile')
<p class="text-sm text-red-600 dark:text-red-400">{{ $message }}</p>
@enderror
{{-- Upload progress bar --}}
<div x-show="uploading" class="space-y-1">
<div class="w-full bg-gray-200 dark:bg-gray-700 rounded-full h-2">
<div
class="bg-amber-500 h-2 rounded-full transition-all"
:style="'width: ' + uploadProgress + '%'"
></div>
</div>
</div>
{{-- Submit button --}}
<div class="flex justify-end">
<x-filament::button
wire:click="startImport"
wire:loading.attr="disabled"
wire:target="startImport"
color="warning"
icon="heroicon-o-arrow-up-tray"
:disabled="$importing"
x-bind:disabled="!uploaded || uploading"
>
<span wire:loading.remove wire:target="startImport">
{{ __('navigation.import.confirm_button') }}
</span>
<span wire:loading wire:target="startImport">
{{ __('navigation.import.processing') }}
</span>
</x-filament::button>
</div>
</div>
</x-filament::card>
@if($report)
<x-filament::card>
<h3 class="font-semibold text-base mb-2">{{ __('navigation.sync.last_report') }}</h3>
@@ -58,4 +177,11 @@
</x-filament::card>
@endif
@if($importReport)
<x-filament::card>
<h3 class="font-semibold text-base mb-2">{{ __('navigation.import.last_report') }}</h3>
<pre class="bg-gray-50 dark:bg-gray-900 border rounded p-3 text-xs leading-loose max-h-64 overflow-y-auto whitespace-pre-wrap">{{ $importReport }}</pre>
</x-filament::card>
@endif
</x-filament-panels::page>
@@ -21,11 +21,15 @@
@if($photosBefore->isNotEmpty())
<div>
<h3 class="text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">{{ __('patients.fields.photos_before') }}</h3>
<div class="grid grid-cols-3 gap-2">
@foreach($photosBefore as $url)
<a href="{{ $url }}" target="_blank">
<img src="{{ $url }}" class="w-full h-32 object-cover rounded-lg border border-gray-200 dark:border-gray-700 hover:opacity-80 transition" />
</a>
<div class="fi-lb-gallery" style="display:flex;flex-wrap:wrap;gap:6px;">
@foreach($photosBefore as $i => $url)
<div class="relative rounded-lg overflow-hidden bg-gray-800 cursor-pointer group" style="width:80px;height:45px;flex-shrink:0;"
data-lb-group="modal-before-{{ $record->id }}"
data-lb-idx="{{ $i }}"
data-lb-src="{{ $url }}">
<img src="{{ $url }}" class="w-full h-full object-cover transition group-hover:scale-105 duration-200" loading="lazy" />
<div class="absolute inset-0 bg-black/0 group-hover:bg-black/25 transition duration-200"></div>
</div>
@endforeach
</div>
</div>
@@ -35,11 +39,15 @@
@if($photosAfter->isNotEmpty())
<div>
<h3 class="text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">{{ __('patients.fields.photos_after') }}</h3>
<div class="grid grid-cols-3 gap-2">
@foreach($photosAfter as $url)
<a href="{{ $url }}" target="_blank">
<img src="{{ $url }}" class="w-full h-32 object-cover rounded-lg border border-gray-200 dark:border-gray-700 hover:opacity-80 transition" />
</a>
<div class="fi-lb-gallery" style="display:flex;flex-wrap:wrap;gap:6px;">
@foreach($photosAfter as $i => $url)
<div class="relative rounded-lg overflow-hidden bg-gray-800 cursor-pointer group" style="width:80px;height:45px;flex-shrink:0;"
data-lb-group="modal-after-{{ $record->id }}"
data-lb-idx="{{ $i }}"
data-lb-src="{{ $url }}">
<img src="{{ $url }}" class="w-full h-full object-cover transition group-hover:scale-105 duration-200" loading="lazy" />
<div class="absolute inset-0 bg-black/0 group-hover:bg-black/25 transition duration-200"></div>
</div>
@endforeach
</div>
</div>
@@ -52,7 +60,7 @@
<div class="space-y-3">
@foreach($videos as $i => $url)
@php $vid = 'patient-video-'.$i.'-'.uniqid(); @endphp
<div class="rounded-lg overflow-hidden border border-gray-200 dark:border-gray-700 bg-black">
<div class="rounded-lg overflow-hidden">
<video id="{{ $vid }}" src="{{ $url }}" controls class="w-full max-h-64"></video>
<div class="flex items-center gap-2 bg-gray-900 px-3 py-1">
<span class="text-xs text-gray-400">سرعت:</span>
@@ -82,7 +90,7 @@ class="text-xs px-2 py-0.5 rounded {{ $speed == 1 ? 'bg-blue-600 text-white' : '
<div class="space-y-2">
@foreach($audios as $i => $url)
@php $aid = 'patient-audio-'.$i.'-'.uniqid(); @endphp
<div class="rounded-lg border border-gray-200 dark:border-gray-700 bg-gray-50 dark:bg-gray-800 p-3">
<div class="rounded-lg p-3">
<audio id="{{ $aid }}" src="{{ $url }}" controls class="w-full mb-2"></audio>
<div class="flex items-center gap-2">
<span class="text-xs text-gray-500 dark:text-gray-400">سرعت:</span>
@@ -0,0 +1,7 @@
<div style="width:100%;height:80vh;overflow:hidden;border-radius:8px;">
<iframe
src="{{ $url }}"
style="width:100%;height:100%;border:none;display:block;"
allowfullscreen
></iframe>
</div>
@@ -112,14 +112,15 @@ class="flex items-center gap-3 px-4 py-2.5 text-sm text-gray-700 dark:text-gray-
{{ __('navigation.sync.details') }}
</a>
<a
href="{{ route('backup.download') }}"
<button
type="button"
@click="open = false"
class="flex items-center gap-3 px-4 py-2.5 text-sm text-gray-700 dark:text-gray-300 hover:bg-gray-50 dark:hover:bg-gray-700 transition"
wire:click="runBackup"
class="flex items-center gap-3 px-4 py-2.5 text-sm text-gray-700 dark:text-gray-300 hover:bg-gray-50 dark:hover:bg-gray-700 transition w-full"
>
<x-heroicon-o-arrow-down-tray class="w-4 h-4 text-success-500 shrink-0" />
{{ __('navigation.backup.label') }}
</a>
</button>
</div>
<template x-teleport="body">
+355 -80
View File
@@ -3,7 +3,12 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{ $type === 'lab' ? 'آزمایش' : 'نسخه' }} - {{ $prescription->patientRecord?->full_name ?? '' }}</title>
<title>
@if($type === 'both') نسخه و آزمایش
@elseif($type === 'lab') آزمایش
@else نسخه
@endif - {{ $prescription->patientRecord?->full_name ?? '' }}
</title>
<style>
* {
margin: 0;
@@ -54,8 +59,63 @@
.btn-admission{ background: #d97706; color: #fff; }
.btn-lab { background: #6b7280; color: #fff; }
.btn-back { background: #374151; color: #d1d5db; }
.btn-both { background: #7c3aed; color: #fff; }
.btn-edit { background: #0f766e; color: #fff; }
.toolbar-divider { flex: 1; }
.edit-modal-overlay {
display: none;
position: fixed;
inset: 0;
background: rgba(0,0,0,0.7);
z-index: 9999;
align-items: center;
justify-content: center;
}
.edit-modal-overlay.open { display: flex; }
.edit-modal {
background: #fff;
border-radius: 12px;
width: 92vw;
max-width: 1000px;
height: 90vh;
display: flex;
flex-direction: column;
overflow: hidden;
box-shadow: 0 25px 60px rgba(0,0,0,0.5);
}
.edit-modal-header {
background: #1f2937;
color: #fff;
padding: 10px 20px;
display: flex;
align-items: center;
justify-content: space-between;
direction: rtl;
flex-shrink: 0;
font-family: Tahoma, Arial, sans-serif;
font-size: 14px;
font-weight: bold;
}
.edit-modal-close {
background: #374151;
border: none;
color: #d1d5db;
width: 30px;
height: 30px;
border-radius: 6px;
cursor: pointer;
font-size: 20px;
line-height: 1;
display: flex;
align-items: center;
justify-content: center;
}
.edit-modal-close:hover { background: #ef4444; color: #fff; }
.edit-modal iframe { flex: 1; border: none; width: 100%; }
@media print { .edit-modal-overlay { display: none !important; } }
.page-body {
padding: 20px;
display: flex;
@@ -64,6 +124,38 @@
min-height: calc(100vh - 52px);
}
.page-body-both {
padding: 20px;
display: flex;
flex-direction: row;
align-items: flex-start;
justify-content: center;
gap: 20px;
flex-wrap: wrap;
}
.print-section {
width: auto;
}
.section-toolbar {
background: #374151;
color: #fff;
padding: 8px 16px;
display: flex;
align-items: center;
justify-content: space-between;
border-radius: 6px 6px 0 0;
font-size: 13px;
font-family: Tahoma, Arial, sans-serif;
direction: rtl;
}
.section-label {
font-weight: bold;
color: #e5e7eb;
}
.prescription-container {
width: 210mm;
height: 148mm;
@@ -138,6 +230,7 @@
}
.print-toolbar { display: none !important; }
.section-toolbar { display: none !important; }
html, body {
width: 210mm !important;
@@ -155,6 +248,18 @@
margin: 0 !important;
min-height: unset !important;
}
.page-body-both {
display: block !important;
padding: 0 !important;
margin: 0 !important;
gap: 0 !important;
}
.print-section {
width: 210mm !important;
}
.prescription-container {
width: 210mm !important;
height: 148mm !important;
@@ -176,6 +281,9 @@
width: 210mm !important;
height: 148mm !important;
}
body.printing-prescription .section-lab { display: none !important; }
body.printing-lab .section-prescription { display: none !important; }
}
</style>
</head>
@@ -184,7 +292,21 @@
<div class="print-toolbar">
<span>نوع پرینت:</span>
@if ($type === 'prescription')
@if ($type === 'both')
<a class="toolbar-btn btn-print"
href="{{ route('prescription.print', $prescription) }}">
نسخه تنها
</a>
<a class="toolbar-btn btn-lab"
href="{{ route('prescription.print', ['prescription' => $prescription, 'type' => 'lab']) }}">
آزمایش تنها
</a>
<span class="toolbar-btn btn-active">✓ نسخه + آزمایش</span>
<a class="toolbar-btn btn-admission"
href="{{ route('prescription.print.admission', $prescription) }}">
پرینت نسخه پذیرش
</a>
@elseif ($type === 'prescription')
<span class="toolbar-btn btn-active">✓ پرینت نسخه</span>
<a class="toolbar-btn btn-admission"
href="{{ route('prescription.print.admission', $prescription) }}">
@@ -194,6 +316,10 @@
href="{{ route('prescription.print', ['prescription' => $prescription, 'type' => 'lab']) }}">
پرینت آزمایش
</a>
<a class="toolbar-btn btn-both"
href="{{ route('prescription.print', ['prescription' => $prescription, 'type' => 'both']) }}">
نسخه + آزمایش
</a>
@else
<a class="toolbar-btn btn-print"
href="{{ route('prescription.print', $prescription) }}">
@@ -204,99 +330,216 @@
پرینت نسخه پذیرش
</a>
<span class="toolbar-btn btn-active">✓ پرینت آزمایش</span>
<a class="toolbar-btn btn-both"
href="{{ route('prescription.print', ['prescription' => $prescription, 'type' => 'both']) }}">
نسخه + آزمایش
</a>
@endif
<div class="toolbar-divider"></div>
<button class="toolbar-btn btn-print" onclick="window.print()">🖨 پرینت</button>
@if ($type === 'both')
<button class="toolbar-btn btn-print" onclick="printSection('prescription')">🖨 پرینت نسخه</button>
<button class="toolbar-btn btn-lab" onclick="printSection('lab')">🖨 پرینت آزمایش</button>
<button class="toolbar-btn btn-edit" onclick="openEditModal()"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="width:14px;height:14px;flex-shrink:0;"><path d="M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"/><path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"/></svg> ویرایش نسخه</button>
@else
<button class="toolbar-btn btn-print" onclick="window.print()">🖨 پرینت</button>
<button class="toolbar-btn btn-edit" onclick="openEditModal()"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="width:14px;height:14px;flex-shrink:0;"><path d="M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"/><path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"/></svg> ویرایش نسخه</button>
@endif
<a class="toolbar-btn btn-back"
href="{{ route('filament.admin.resources.prescriptions.index') }}">
← بازگشت به لیست
</a>
</div>
{{-- ─── Print area ───────────────────────────────────────────── --}}
<div class="page-body">
<div class="prescription-container">
<img src="{{ asset('images/prescription_bg.jpg') }}" alt="نسخه" class="prescription-bg">
<div class="content-overlay">
@php
$patientName = $prescription->patientRecord?->full_name ?? '';
$nameLength = mb_strlen($patientName, 'UTF-8');
$nameClass = 'patient-name';
if ($nameLength > 20) {
$nameClass .= ' very-long-name';
} elseif ($nameLength > 14) {
$nameClass .= ' long-name';
}
$dateStr = $prescription->issue_date ?? '';
if ($dateStr && preg_match('/^\d{4}-\d{2}-\d{2}/', $dateStr)) {
try {
$dateStr = \Morilog\Jalali\Jalalian::fromCarbon(\Carbon\Carbon::parse($dateStr))->format('Y/m/d');
} catch (\Exception $e) {}
}
@endphp
<div class="{{ $nameClass }}">{{ $patientName }}</div>
<div class="patient-date">{{ $dateStr }}</div>
<div class="prescription-content">
@if ($type === 'lab')
<table style="width:100%;direction:ltr;font-size:20px;color:#333;table-layout:fixed;">
@foreach (['CBC','PT/PTT/INR','BS','HIV/Ab &nbsp;&nbsp;&nbsp; HBS/Ag &nbsp;&nbsp;&nbsp; Hcv/Ab'] as $test)
<tr>
<td style="padding:8px 2px 8px 0;width:3%;font-weight:bold;">-</td>
<td style="padding:8px 5px;width:97%;">{!! $test !!}</td>
</tr>
@endforeach
</table>
@else
@php
$content = $prescription->content ?? '';
preg_match_all('/<li[^>]*>(.*?)<\/li>/s', $content, $m);
$lines = $m[1] ?? [];
if (empty($lines)) {
$cleaned = preg_replace('/<br\s*\/?>/i', "\n", $content);
$lines = explode("\n", strip_tags($cleaned));
}
$lines = array_values(array_filter(
array_map(fn ($l) => html_entity_decode(trim(strip_tags($l)), ENT_QUOTES, 'UTF-8'), $lines)
));
@endphp
<table style="width:100%;direction:ltr;font-size:20px;color:#333;border-collapse:collapse;table-layout:fixed;">
@foreach ($lines as $line)
@php
$parts = preg_split('/\s+/', trim($line));
$type_str = array_shift($parts);
$freq = !empty($parts) ? array_pop($parts) : '';
$count = $dose = '';
$nameParts = [];
foreach ($parts as $p) {
if (str_starts_with($p, '#') && $count === '') { $count = $p; }
elseif (preg_match('/^\d+(mg|g|ml|mcg|iu)$/i', $p) && $dose === '') { $dose = $p; }
else { $nameParts[] = $p; }
}
$drugName = implode(' ', $nameParts);
@endphp
<tr>
<td style="padding:8px 2px 8px 10px;width:3%;font-weight:bold;">-</td>
<td style="padding:8px 10px 8px 5px;width:12%;white-space:nowrap;">{{ $type_str }}</td>
<td style="padding:8px 5px;width:33%;">{{ $drugName }}</td>
<td style="padding:8px 5px;width:18%;">{{ $dose }}</td>
<td style="padding:8px 5px;width:12%;">{{ $count }}</td>
<td style="padding:8px 0 8px 5px;width:10%;">{{ $freq }}</td>
</tr>
@endforeach
</table>
@endif
</div>
<div class="edit-modal-overlay" id="editModalOverlay" onclick="if(event.target===this)closeEditModal()">
<div class="edit-modal">
<div class="edit-modal-header">
<span><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="width:14px;height:14px;flex-shrink:0;"><path d="M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"/><path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"/></svg> ویرایش نسخه — {{ $prescription->patientRecord?->full_name ?? '' }}</span>
<button class="edit-modal-close" onclick="closeEditModal()">×</button>
</div>
<iframe
id="editModalFrame"
src=""
data-src="{{ route('filament.admin.resources.prescriptions.edit', $prescription) }}"
></iframe>
</div>
</div>
@php
$patientName = $prescription->patientRecord?->full_name ?? '';
$nameLength = mb_strlen($patientName, 'UTF-8');
$nameClass = 'patient-name';
if ($nameLength > 20) {
$nameClass .= ' very-long-name';
} elseif ($nameLength > 14) {
$nameClass .= ' long-name';
}
$dateStr = $prescription->issue_date ?? '';
if ($dateStr && preg_match('/^\d{4}-\d{2}-\d{2}/', $dateStr)) {
try {
$dateStr = \Morilog\Jalali\Jalalian::fromCarbon(\Carbon\Carbon::parse($dateStr))->format('Y/m/d');
} catch (\Exception $e) {}
}
$content = $prescription->content ?? '';
preg_match_all('/<li[^>]*>(.*?)<\/li>/s', $content, $m);
$lines = $m[1] ?? [];
if (empty($lines)) {
$cleaned = preg_replace('/<br\s*\/?>/i', "\n", $content);
$lines = explode("\n", strip_tags($cleaned));
}
$lines = array_values(array_filter(
array_map(fn ($l) => html_entity_decode(trim(strip_tags($l)), ENT_QUOTES, 'UTF-8'), $lines)
));
@endphp
@if ($type === 'both')
<div class="page-body-both">
{{-- Prescription section --}}
<div class="print-section section-prescription">
<div class="section-toolbar">
<span class="section-label">📋 نسخه دارویی</span>
<div style="display:flex;gap:6px;">
<button class="toolbar-btn btn-print" onclick="printSection('prescription')" style="font-size:12px;padding:5px 12px;">🖨 پرینت نسخه</button>
<button class="toolbar-btn btn-edit" onclick="openEditModal()" style="font-size:12px;padding:5px 12px;"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="width:14px;height:14px;flex-shrink:0;"><path d="M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"/><path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"/></svg> ویرایش نسخه</button>
</div>
</div>
<div class="prescription-container">
<img src="{{ asset('images/prescription_bg.jpg') }}" alt="نسخه" class="prescription-bg">
<div class="content-overlay">
<div class="{{ $nameClass }}">{{ $patientName }}</div>
<div class="patient-date">{{ $dateStr }}</div>
<div class="prescription-content">
<table style="width:100%;direction:ltr;font-size:20px;color:#333;border-collapse:collapse;table-layout:fixed;">
@foreach ($lines as $line)
@php
$parts = preg_split('/\s+/', trim($line));
$type_str = array_shift($parts);
$freq = !empty($parts) ? array_pop($parts) : '';
$count = $dose = '';
$nameParts = [];
foreach ($parts as $p) {
if (str_starts_with($p, '#') && $count === '') { $count = $p; }
elseif (preg_match('/^\d+(mg|g|ml|mcg|iu)$/i', $p) && $dose === '') { $dose = $p; }
else { $nameParts[] = $p; }
}
$drugName = implode(' ', $nameParts);
@endphp
<tr>
<td style="padding:8px 2px 8px 10px;width:3%;font-weight:bold;">-</td>
<td style="padding:8px 10px 8px 5px;width:12%;white-space:nowrap;">{{ $type_str }}</td>
<td style="padding:8px 5px;width:33%;">{{ $drugName }}</td>
<td style="padding:8px 5px;width:18%;">{{ $dose }}</td>
<td style="padding:8px 5px;width:12%;">{{ $count }}</td>
<td style="padding:8px 0 8px 5px;width:10%;">{{ $freq }}</td>
</tr>
@endforeach
</table>
</div>
</div>
</div>
</div>
{{-- Lab section --}}
<div class="print-section section-lab">
<div class="section-toolbar">
<span class="section-label">🧪 درخواست آزمایش</span>
<div style="display:flex;gap:6px;">
<button class="toolbar-btn btn-lab" onclick="printSection('lab')" style="font-size:12px;padding:5px 12px;">🖨 پرینت آزمایش</button>
<button class="toolbar-btn btn-edit" onclick="openEditModal()" style="font-size:12px;padding:5px 12px;"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="width:14px;height:14px;flex-shrink:0;"><path d="M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"/><path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"/></svg> ویرایش آزمایش</button>
</div>
</div>
<div class="prescription-container">
<img src="{{ asset('images/prescription_bg.jpg') }}" alt="آزمایش" class="prescription-bg">
<div class="content-overlay">
<div class="{{ $nameClass }}">{{ $patientName }}</div>
<div class="patient-date">{{ $dateStr }}</div>
<div class="prescription-content">
<table style="width:100%;direction:ltr;font-size:20px;color:#333;table-layout:fixed;">
@forelse ($labLines as $line)
<tr>
<td style="padding:8px 2px 8px 0;width:3%;font-weight:bold;">-</td>
<td style="padding:8px 5px;width:97%;">{{ $line }}</td>
</tr>
@empty
<tr>
<td colspan="2" style="padding:8px 5px;color:#999;font-size:14px;">آزمایشی انتخاب نشده است.</td>
</tr>
@endforelse
</table>
</div>
</div>
</div>
</div>
</div>
@else
<div class="page-body">
<div class="prescription-container">
<img src="{{ asset('images/prescription_bg.jpg') }}" alt="نسخه" class="prescription-bg">
<div class="content-overlay">
<div class="{{ $nameClass }}">{{ $patientName }}</div>
<div class="patient-date">{{ $dateStr }}</div>
<div class="prescription-content">
@if ($type === 'lab')
<table style="width:100%;direction:ltr;font-size:20px;color:#333;table-layout:fixed;">
@forelse ($labLines as $line)
<tr>
<td style="padding:8px 2px 8px 0;width:3%;font-weight:bold;">-</td>
<td style="padding:8px 5px;width:97%;">{{ $line }}</td>
</tr>
@empty
<tr>
<td colspan="2" style="padding:8px 5px;color:#999;font-size:14px;">آزمایشی انتخاب نشده است.</td>
</tr>
@endforelse
</table>
@else
<table style="width:100%;direction:ltr;font-size:20px;color:#333;border-collapse:collapse;table-layout:fixed;">
@foreach ($lines as $line)
@php
$parts = preg_split('/\s+/', trim($line));
$type_str = array_shift($parts);
$freq = !empty($parts) ? array_pop($parts) : '';
$count = $dose = '';
$nameParts = [];
foreach ($parts as $p) {
if (str_starts_with($p, '#') && $count === '') { $count = $p; }
elseif (preg_match('/^\d+(mg|g|ml|mcg|iu)$/i', $p) && $dose === '') { $dose = $p; }
else { $nameParts[] = $p; }
}
$drugName = implode(' ', $nameParts);
@endphp
<tr>
<td style="padding:8px 2px 8px 10px;width:3%;font-weight:bold;">-</td>
<td style="padding:8px 10px 8px 5px;width:12%;white-space:nowrap;">{{ $type_str }}</td>
<td style="padding:8px 5px;width:33%;">{{ $drugName }}</td>
<td style="padding:8px 5px;width:18%;">{{ $dose }}</td>
<td style="padding:8px 5px;width:12%;">{{ $count }}</td>
<td style="padding:8px 0 8px 5px;width:10%;">{{ $freq }}</td>
</tr>
@endforeach
</table>
@endif
</div>
</div>
</div>
</div>
@endif
<script>
@if ($type === 'both')
function printSection(section) {
document.body.classList.remove('printing-prescription', 'printing-lab');
document.body.classList.add('printing-' + section);
window.print();
document.body.classList.remove('printing-prescription', 'printing-lab');
}
@else
window.onload = function () {
const userConfirmed = confirm(
'لطفاً تنظیمات پرینت را به این صورت انجام دهید:\n\n' +
@@ -311,6 +554,38 @@
window.print();
}
};
@endif
const overlay = document.getElementById('editModalOverlay');
const frame = document.getElementById('editModalFrame');
let frameLoaded = false;
function openEditModal() {
if (!frameLoaded) {
frame.src = frame.dataset.src;
frameLoaded = true;
}
overlay.classList.add('open');
document.body.style.overflow = 'hidden';
}
function closeEditModal() {
overlay.classList.remove('open');
document.body.style.overflow = '';
}
frame.addEventListener('load', function () {
if (!frameLoaded) return;
try {
const url = frame.contentWindow.location.href;
if (url.includes('/prescriptions') && !url.includes('/edit')) {
closeEditModal();
window.location.reload();
}
} catch (e) {}
});
document.addEventListener('keydown', e => { if (e.key === 'Escape') closeEditModal(); });
</script>
</body>
</html>