load('patientRecord'); $type = $request->query('type', 'prescription'); $labContent = $prescription->lab_content ?? ''; $labLines = []; if ($labContent) { preg_match_all('/]*>(.*?)<\/li>/s', $labContent, $m); $labLines = $m[1] ?? []; if (empty($labLines)) { $cleaned = preg_replace('//i', "\n", $labContent); $labLines = explode("\n", strip_tags($cleaned)); } $labLines = array_values(array_filter( array_map(fn ($l) => html_entity_decode(trim(strip_tags($l)), ENT_QUOTES, 'UTF-8'), $labLines) )); } return view('prints.prescription', [ 'prescription' => $prescription, 'type' => $type, 'labLines' => $labLines, ]); } public function printAdmission(Prescription $prescription) { $prescription->load('patientRecord'); $patient = $prescription->patientRecord; $appointment = $patient?->surgeryAppointment?->load('surgeryCenter'); $centerName = ''; $surgeryDate = ''; if ($appointment) { try { $surgeryDate = Jalalian::fromCarbon($appointment->surgery_date)->format('Y/m/d'); } catch (\Throwable) { $surgeryDate = $appointment->surgery_date?->format('Y-m-d') ?? ''; } $centerName = $appointment->surgeryCenter?->name ?? ''; } return view('prints.prescription-admission', [ 'prescription' => $prescription, 'centerName' => $centerName, 'surgeryDate' => $surgeryDate, ]); } public function printPatientLab(Patient $patient) { return view('prints.patient-lab', [ 'patient' => $patient, 'issueDate' => Jalalian::now()->format('Y/m/d'), ]); } public function printSurgeryAdmission(Patient $patient) { $appointment = $patient->surgeryAppointment?->load('surgeryCenter'); $surgeryDate = ''; $centerName = ''; if ($appointment) { try { $surgeryDate = Jalalian::fromCarbon($appointment->surgery_date)->format('Y/m/d'); } catch (\Throwable) { $surgeryDate = $appointment->surgery_date?->format('Y-m-d') ?? ''; } $centerName = $appointment->surgeryCenter?->name ?? ''; } return view('prints.surgery-admission', [ 'patient' => $patient, 'surgeryDate' => $surgeryDate, 'centerName' => $centerName, ]); } }