Lokasi:
/
home
/
u847703118
/
domains
/
alphamed.cloud
/
public_html
/
Ubah: print_result.php
<?php require('includes/auth_session.php'); require('db_connect.php'); require('includes/result_helper.php'); if (!function_exists('tableHasColumn')) { function tableHasColumn(PDO $pdo, string $table, string $column): bool { try { $stmt = $pdo->query("SHOW COLUMNS FROM `$table` LIKE " . $pdo->quote($column)); return $stmt && $stmt->fetch() ? true : false; } catch (Exception $e) { return false; } } } if (!function_exists('tableExists')) { function tableExists(PDO $pdo, string $table): bool { try { $stmt = $pdo->query("SHOW TABLES LIKE " . $pdo->quote($table)); return $stmt && $stmt->fetch() ? true : false; } catch (Exception $e) { return false; } } } // Restrict to authorized roles if (!userCanAccess('results', ['admin', 'med_tech', 'chief_med_tech', 'rad_tech', 'doctor'])) { die("Access Denied"); } if (!isset($_GET['id']) && !isset($_GET['invoice_id']) && (!isset($_GET['patient_id']) || !isset($_GET['date']))) { die("Invalid Request"); } $showRemarks = !isset($_GET['show_remarks']) || (string)$_GET['show_remarks'] !== '0'; // Fetch Company Settings $company_sql = "SELECT * FROM company_settings LIMIT 1"; $company_stmt = $pdo->query($company_sql); $company = $company_stmt->fetch(); $company_name = $company['company_name'] ?? 'Diagnostic Center'; $company_address = $company['company_address'] ?? ''; $company_logo = $company['company_logo'] ?? ''; $company_email = $company['company_email'] ?? ''; $company_phone = $company['company_phone'] ?? ''; $system_id = $company['system_id'] ?? ''; $theme_color = $company['theme_color'] ?? '#2c3e50'; $pathologist_name = $company['pathologist_name'] ?? ''; $pathologist_license = $company['pathologist_license'] ?? ''; $pathologist_signature = $company['pathologist_signature'] ?? ''; // Prepare Query $hasTestDefaultRemark = tableHasColumn($pdo, 'lab_tests', 'default_remark_id') && tableExists($pdo, 'remarks_components'); $remarksSelect = $hasTestDefaultRemark ? ", COALESCE(NULLIF(tr.remarks,''), rc_test.remarks) AS remarks" : ""; $remarksJoin = $hasTestDefaultRemark ? " LEFT JOIN remarks_components rc_test ON rc_test.id = t.default_remark_id " : ""; $sql = "SELECT tr.*, COALESCE(tr.test_name_snapshot, t.test_name) AS test_name, t.test_type, t.category, t.unit, t.normal_range{$remarksSelect}, p.first_name, p.last_name, p.dob, p.gender, p.patient_code, p.access_code, p.address, u.full_name as entered_by_name, u.signature as entered_by_sig, v.full_name as validated_by_name, v.signature as validated_by_sig, v.role as validated_by_role, d.name as doctor_name, i.branch_id FROM test_results tr JOIN patients p ON tr.patient_id = p.id JOIN lab_tests t ON tr.test_id = t.id {$remarksJoin} LEFT JOIN users u ON tr.entered_by = u.id LEFT JOIN users v ON tr.validated_by = v.id LEFT JOIN doctors d ON p.doctor_id = d.id LEFT JOIN invoices i ON tr.invoice_id = i.id WHERE "; $params = []; // No category restriction, we want ALL tests for the given ID/Invoice if (isset($_GET['id'])) { $sql .= "tr.id = ?"; $params[] = $_GET['id']; } elseif (isset($_GET['invoice_id'])) { $sql .= "tr.invoice_id = ? AND tr.status = 'Completed'"; $params[] = $_GET['invoice_id']; } else { $sql .= "tr.patient_id = ? AND DATE(tr.created_at) = ? AND tr.status = 'Completed'"; $params[] = $_GET['patient_id']; $params[] = $_GET['date']; } // Order by category and resolved test name $sql .= " ORDER BY t.category, COALESCE(tr.test_name_snapshot, t.test_name)"; $stmt = $pdo->prepare($sql); $stmt->execute($params); $results_data = $stmt->fetchAll(); if (empty($results_data)) { die("No completed results found."); } // Resolve "Physician" from requested physician per test (invoice_items.requested_doctor_*) try { $hasReqDocCols = function_exists('tableHasColumn') && tableHasColumn($pdo, 'invoice_items', 'requested_doctor_id') && tableHasColumn($pdo, 'invoice_items', 'requested_doctor_name'); $invIds = []; foreach ($results_data as $r) { $iid = (int)($r['invoice_id'] ?? 0); if ($iid > 0) $invIds[$iid] = true; } $invIds = array_keys($invIds); if ($hasReqDocCols && tableExists($pdo, 'invoice_items') && tableExists($pdo, 'doctors') && count($invIds) === 1) { $invoiceIdForPhys = (int)$invIds[0]; $testIds = []; foreach ($results_data as $r) { $tid = (int)($r['test_id'] ?? 0); if ($tid > 0) $testIds[$tid] = true; } $testIds = array_keys($testIds); if ($invoiceIdForPhys > 0 && !empty($testIds)) { $ph = implode(',', array_fill(0, count($testIds), '?')); $sqlDoc = " SELECT ii.test_id, COALESCE(d.name, ii.requested_doctor_name) AS physician_name FROM invoice_items ii LEFT JOIN doctors d ON d.id = ii.requested_doctor_id WHERE ii.invoice_id = ? AND ii.item_type = 'lab' AND ii.test_id IN ($ph) "; $stDoc = $pdo->prepare($sqlDoc); $stDoc->execute(array_merge([$invoiceIdForPhys], $testIds)); $doctorByTest = []; while ($row = $stDoc->fetch(PDO::FETCH_ASSOC)) { $tid = (int)($row['test_id'] ?? 0); $nm = trim((string)($row['physician_name'] ?? '')); if ($tid > 0 && $nm !== '' && !isset($doctorByTest[$tid])) { $doctorByTest[$tid] = $nm; } } foreach ($results_data as &$r) { $tid = (int)($r['test_id'] ?? 0); if ($tid > 0 && isset($doctorByTest[$tid])) { $r['doctor_name'] = $doctorByTest[$tid]; } } unset($r); } } } catch (Exception $e) { } // Branch Override Logic if (!empty($results_data) && isset($results_data[0]['branch_id'])) { $branch_id = $results_data[0]['branch_id']; if ($branch_id) { $stmt = $pdo->prepare("SELECT * FROM branches WHERE id = ?"); $stmt->execute([$branch_id]); $branch = $stmt->fetch(PDO::FETCH_ASSOC); if ($branch) { if (!empty($branch['branch_name'])) $company_name = $branch['branch_name']; if (!empty($branch['branch_address'])) $company_address = $branch['branch_address']; if (!empty($branch['branch_contact'])) $company_phone = $branch['branch_contact']; if (!empty($branch['email'])) $company_email = $branch['email']; if (!empty($branch['pathologist_name'])) $pathologist_name = $branch['pathologist_name']; if (!empty($branch['pathologist_license'])) $pathologist_license = $branch['pathologist_license']; if (!empty($branch['pathologist_signature'])) $pathologist_signature = $branch['pathologist_signature']; } } } // Determine Report Format - A5 Landscape $page_size = 'A5'; $orientation = 'landscape'; $container_width = '210mm'; $container_min_height = 'auto'; // Ancillary Categories for check $ancillary_cats_arr = ['X-Ray', 'Ultrasound', 'ECG', '2D Echo', 'Cardiology', 'Endoscopy']; ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Medical Report</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet"> <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" rel="stylesheet"> <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500;700&family=Merriweather:wght@300;400;700&display=swap" rel="stylesheet"> <script src="https://cdnjs.cloudflare.com/ajax/libs/html2pdf.js/0.10.1/html2pdf.bundle.min.js"></script> <style> @page { size: <?php echo $page_size . ' ' . $orientation; ?>; margin: 1.2mm 0 0.1mm 0; } body { background-color: #f4f6f9; font-family: 'Roboto', sans-serif; color: #212529; margin: 0; padding-top: 50px; font-size: 8pt; } :root { --primary-color: <?php echo $theme_color; ?>; --accent-color: #e74c3c; --text-muted: #6c757d; --border-color: #dee2e6; } .toolbar { position: fixed; top: 0; left: 0; right: 0; background: linear-gradient(135deg, var(--primary-color), #2c3e50); padding: 10px; color: white; display: flex; justify-content: space-between; align-items: center; z-index: 1000; box-shadow: 0 2px 5px rgba(0,0,0,0.2); } .report-container { width: <?php echo $container_width; ?>; min-height: <?php echo $container_min_height; ?>; margin: 20px auto; background: white; padding: 0; box-shadow: 0 5px 15px rgba(0,0,0,0.1); position: relative; box-sizing: border-box; display: block; } /* Header */ header { border-bottom: none; padding-bottom: 0; margin-bottom: 5px; display: flex; align-items: center; justify-content: space-between; } .logo-section { width: 80px; height: 80px; display: flex; align-items: center; justify-content: center; background: #b71c1c; color: white; border-radius: 4px; overflow: hidden; } .logo-section img { max-height: 70px; max-width: 70px; object-fit: contain; } .company-info { flex: 1; padding: 0 15px; text-align: left; } .company-name { font-family: 'Merriweather', serif; font-weight: 700; color: #1a237e; text-transform: uppercase; margin: 0; line-height: 1.1; letter-spacing: 0.5px; } .company-details { font-size: 7.5pt; margin-top: 5px; color: var(--text-muted); } .badge-report { display: inline-block; background-color: #1a237e; color: white; padding: 4px 12px; font-size: 8pt; font-weight: bold; border-radius: 4px; margin-top: 8px; text-transform: uppercase; letter-spacing: 1px; } .qr-section { width: 80px; text-align: center; } .qr-section img { width: 70px; height: 70px; } .qr-label { font-size: 6pt; text-transform: uppercase; color: var(--text-muted); margin-top: 2px; } /* Patient Banner */ .patient-banner { border: 1px solid #1a237e; border-radius: 4px; padding: 0; margin-bottom: 5px; overflow: hidden; display: flex; background: #fff; } .banner-column { flex: 1; padding: 4px 8px; display: flex; flex-direction: column; gap: 1px; } .banner-column:first-child { border-right: 1px solid #dee2e6; background: #f8f9fa; } .patient-row { display: flex; align-items: baseline; justify-content: space-between; line-height: 1.2; } .label { font-weight: 500; color: var(--text-muted); text-transform: uppercase; font-size: 7pt; width: 90px; } .value { font-weight: 700; color: #212529; font-size: 8pt; flex: 1; text-align: left; } .value.highlight { color: #0d6efd; } /* Content */ .test-page-wrapper { display: flex; flex-direction: column; width: 100%; height: 135mm; page-break-inside: avoid; padding: 0 5mm 15mm 5mm; box-sizing: border-box; position: relative; } .test-name-header { font-family: 'Roboto', sans-serif; font-size: 9pt; font-weight: 700; color: #212529; margin-bottom: 5px; text-transform: uppercase; padding-left: 2px; } /* Table */ .table-results { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 8pt; margin-bottom: 10px; } .table-results th { background-color: #f1f3f5; color: #495057; font-weight: 700; text-transform: uppercase; font-size: 7pt; padding: 3px 5px; border-bottom: 2px solid #dee2e6; border-top: 1px solid #dee2e6; } .table-results td { padding: 1px 4px; border-bottom: 1px solid #e9ecef; vertical-align: top; color: #343a40; line-height: 1.1; } .table-results tr:last-child td { border-bottom: 1px solid #dee2e6; } .result-cell { font-weight: 700; } /* Signatures */ .signatures-section { margin-top: auto; padding-top: 2px; display: flex; justify-content: space-between; padding-left: 50px; padding-right: 50px; } .sig-box { text-align: center; width: 200px; } .sig-label { font-size: 7pt; color: var(--text-muted); text-transform: uppercase; margin-bottom: 5px; letter-spacing: 1px; } .sig-image-container { height: 40px; display: flex; align-items: flex-end; justify-content: center; margin-bottom: 2px; } .sig-image-container img { max-height: 100%; max-width: 100%; } .sig-line { border-top: 1px solid #495057; width: 100%; margin: 2px auto 4px; } .sig-name { font-weight: 700; font-size: 8.5pt; text-transform: uppercase; color: #212529; } .sig-role { font-size: 7.5pt; font-style: italic; color: var(--text-muted); } /* Footer */ .footer-fixed { border-top: 1px solid #e9ecef; padding-top: 2px; margin-top: 2px; text-align: center; font-size: 6pt; color: #868e96; line-height: 1.2; } @media print { body { background: white; -webkit-print-color-adjust: exact; print-color-adjust: exact; } .no-print { display: none !important; } .print-only { display: block !important; } .report-container { box-shadow: none; border: none; margin: 0; padding: 0; width: 100%; min-height: 0 !important; } .test-page-wrapper { break-inside: avoid; page-break-inside: avoid; } } #pdf-overlay { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(255,255,255,0.95); z-index: 2000; display: none; justify-content: center; align-items: center; flex-direction: column; } .spinner { width: 50px; height: 50px; border: 5px solid #e9ecef; border-top: 5px solid var(--primary-color); border-radius: 50%; animation: spin 1s linear infinite; } @keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } } </style> <script> function generatePDF() { document.getElementById('pdf-overlay').style.display = 'flex'; const element = document.getElementById('report-content'); const opt = { margin: [1.2, 0, 0.1, 0], filename: 'Medical_Report_<?php echo $results_data[0]['patient_code']; ?>_<?php echo date('Ymd'); ?>.pdf', image: { type: 'jpeg', quality: 0.98 }, html2canvas: { scale: 2, useCORS: true, logging: false }, jsPDF: { unit: 'mm', format: 'a5', orientation: 'landscape' }, pagebreak: { mode: ['css', 'legacy'] } }; html2pdf().set(opt).from(element).save().then(function(){ document.getElementById('pdf-overlay').style.display = 'none'; }).catch(function(err){ console.error(err); alert('Error generating PDF.'); document.getElementById('pdf-overlay').style.display = 'none'; }); } function toggleRemarks(show) { var url = new URL(window.location.href); url.searchParams.set('show_remarks', show ? '1' : '0'); window.location.href = url.toString(); } </script> </head> <body> <div class="toolbar no-print"> <div><strong>Report Viewer</strong></div> <div> <div class="form-check form-check-inline me-3" style="color: #fff;"> <input class="form-check-input" type="checkbox" id="toggleShowRemarks" <?php echo $showRemarks ? 'checked' : ''; ?> onchange="toggleRemarks(this.checked)"> <label class="form-check-label" for="toggleShowRemarks">Remarks</label> </div> <button onclick="generatePDF()" class="btn btn-sm btn-light text-dark fw-bold me-2"><i class="fa-solid fa-file-pdf me-1"></i> Download PDF</button> <button onclick="window.print()" class="btn btn-sm btn-outline-light me-2"><i class="fa-solid fa-print me-1"></i> Print</button> <button onclick="window.close()" class="btn btn-sm btn-outline-light">Close</button> </div> </div> <div id="pdf-overlay"> <div class="spinner mb-3"></div> <h5>Generating PDF...</h5> </div> <div class="report-container" id="report-content"> <?php foreach ($results_data as $index => $result): // Calculate Age $age = 'N/A'; if (!empty($result['dob'])) { $dob = new DateTime($result['dob']); $now = new DateTime(); $age = $now->diff($dob)->y; } // Attachments $attachments = json_decode($result['attachments'] ?? '[]', true); if (!is_array($attachments)) $attachments = []; // Determine Report Type Label & Style $is_imaging = ($result['category'] == 'Imaging' || $result['test_type'] == 'Imaging' || in_array($result['category'], $ancillary_cats_arr)); $report_label = $is_imaging ? 'Imaging Report' : 'Laboratory Report'; // Check if Multi-Component (Lab) $resVal = trim($result['result_value']); $comps = json_decode($resVal, true); $is_multi = (json_last_error() === JSON_ERROR_NONE && is_array($comps) && !$is_imaging); $dropdownCompSet = []; if ($is_multi && tableExists($pdo, 'test_components') && tableHasColumn($pdo, 'test_components', 'type')) { try { $stD = $pdo->prepare("SELECT name FROM test_components WHERE test_id = ? AND LOWER(TRIM(type)) = 'dropdown'"); $stD->execute([(int)($result['test_id'] ?? 0)]); $names = $stD->fetchAll(PDO::FETCH_COLUMN) ?: []; foreach ($names as $n) { $k = strtolower(trim(preg_replace('/\s+/', ' ', (string)$n) ?? '')); if ($k !== '') $dropdownCompSet[$k] = true; } } catch (Exception $e) { $dropdownCompSet = []; } } // Prepare Header HTML for re-use ob_start(); ?> <header> <div class="logo-section"> <?php if (!empty($company_logo) && file_exists($company_logo)): ?> <img src="<?php echo $company_logo; ?>" alt="Logo"> <?php else: ?> <i class="fa-solid fa-hospital fa-3x text-white"></i> <?php endif; ?> </div> <div class="company-info"> <?php $name_len = strlen($company_name ?? ''); $font_size = '1.4rem'; if ($name_len > 50) $font_size = '1rem'; elseif ($name_len > 35) $font_size = '1.2rem'; ?> <h1 class="company-name" style="font-size: <?php echo $font_size; ?>;"><?php echo htmlspecialchars($company_name ?? 'Diagnostic Center'); ?></h1> <div class="company-details"> <?php echo htmlspecialchars($company_address ?? ''); ?><br> <?php if(!empty($company_phone)) echo '<i class="fa-solid fa-phone me-1"></i> ' . htmlspecialchars($company_phone); ?> <?php if(!empty($company_email)) echo ' | <i class="fa-solid fa-envelope me-1"></i> ' . htmlspecialchars($company_email); ?> </div> <div class="badge-report"><?php echo $report_label; ?></div> </div> <div class="qr-section"> <?php $validation_url = (isset($_SERVER['HTTPS']) ? "https" : "http") . "://$_SERVER[HTTP_HOST]/patient_login.php"; $qr_api = "https://api.qrserver.com/v1/create-qr-code/?size=100x100&data=" . urlencode($validation_url); ?> <img src="<?php echo $qr_api; ?>" alt="QR Code" style="width: 80px; height: 80px; border: 1px solid #ddd; padding: 2px;"> <div class="qr-label">Patient Access</div> </div> </header> <div class="patient-banner"> <div class="banner-column"> <div class="patient-row"> <span class="label">Patient Name:</span> <span class="value" style="font-size: 1rem;"><?php echo htmlspecialchars($result['first_name'] . ' ' . $result['last_name']); ?></span> </div> <div class="patient-row"> <span class="label">Age / Gender:</span> <span class="value"><?php echo $age; ?> Yrs / <?php echo $result['gender']; ?></span> </div> <div class="patient-row"> <span class="label">Access Code:</span> <span class="value highlight"><?php echo htmlspecialchars($result['access_code']); ?></span> </div> </div> <div class="banner-column"> <div class="patient-row"> <span class="label">Date:</span> <span class="value"><?php echo date('F d, Y', strtotime($result['created_at'])); ?></span> </div> <div class="patient-row"> <span class="label">Physician:</span> <span class="value"><?php echo htmlspecialchars($result['doctor_name'] ?? 'Walk-in'); ?></span> </div> <div class="patient-row"> <span class="label">Invoice No:</span> <span class="value">#<?php echo str_pad($result['invoice_id'], 6, '0', STR_PAD_LEFT); ?></span> </div> </div> </div> <?php $header_html = ob_get_clean(); // Prepare Footer HTML ob_start(); ?> <div class="footer-fixed"> This report is electronically verified and authorized. Valid without physical signature. | CONFIDENTIALITY NOTICE: This report contains confidential information intended only for the use of the patient and the physician. <?php if(!empty($system_id)): ?><br>System ID: <?php echo htmlspecialchars($system_id); ?><?php endif; ?> </div> <?php $footer_html = ob_get_clean(); ?> <!-- Main Result Page --> <div class="test-page-wrapper" style="<?php echo ($index === count($results_data) - 1 && empty($attachments)) ? 'page-break-after: avoid;' : 'page-break-after: always;'; ?>"> <?php echo $header_html; ?> <div style="flex-grow: 1;"> <div class="test-name-header"><?php echo htmlspecialchars($result['test_name']); ?></div> <table class="table-results"> <thead> <?php if ($is_multi): ?> <tr> <th width="16%">Component</th> <th width="10%">Result</th> <th width="8%">Unit</th> <th width="15%">Ref. Range</th> <th width="2%"></th> <th width="16%">Component</th> <th width="10%">Result</th> <th width="8%">Unit</th> <th width="15%">Ref. Range</th> </tr> <?php else: ?> <tr> <th width="30%">Result</th> <th width="5%"></th> <th width="20%">Unit</th> <th width="20%">Ref. Range</th> <th width="25%">Remarks</th> </tr> <?php endif; ?> </thead> <tbody> <?php $impression = trim($result['impression'] ?? ''); if ($is_multi): $total = count($comps); $half = ceil($total / 2); for ($i = 0; $i < $half; $i++): $c1 = $comps[$i]; $c2 = isset($comps[$i + $half]) ? $comps[$i + $half] : null; ?> <tr> <!-- Column 1 --> <td class="test-name-cell"><?php echo htmlspecialchars($c1['name']); ?></td> <td class="result-cell"><?php echo htmlspecialchars($c1['result']); ?></td> <td><?php echo htmlspecialchars($c1['unit']); ?></td> <?php $r1 = (string)($c1['range'] ?? ''); $k1 = strtolower(trim(preg_replace('/\s+/', ' ', (string)($c1['name'] ?? '')) ?? '')); if ($k1 !== '' && isset($dropdownCompSet[$k1])) { $r1 = ''; } elseif (preg_match('/^\[?\s*dropdown\s*\]?$/i', trim($r1))) { $r1 = ''; } ?> <td><?php echo htmlspecialchars(getApplicableRange($r1, $result['gender'], $age)); ?></td> <td></td> <!-- Column 2 --> <?php if ($c2): ?> <td class="test-name-cell"><?php echo htmlspecialchars($c2['name']); ?></td> <td class="result-cell"><?php echo htmlspecialchars($c2['result']); ?></td> <td><?php echo htmlspecialchars($c2['unit']); ?></td> <?php $r2 = (string)($c2['range'] ?? ''); $k2 = strtolower(trim(preg_replace('/\s+/', ' ', (string)($c2['name'] ?? '')) ?? '')); if ($k2 !== '' && isset($dropdownCompSet[$k2])) { $r2 = ''; } elseif (preg_match('/^\[?\s*dropdown\s*\]?$/i', trim($r2))) { $r2 = ''; } ?> <td><?php echo htmlspecialchars(getApplicableRange($r2, $result['gender'], $age)); ?></td> <?php else: ?> <td colspan="4"></td> <?php endif; ?> </tr> <?php endfor; ?> <?php elseif (is_array($comps) && !empty($comps) && $is_imaging): // Imaging with Components (rare but possible) ?> <?php foreach ($comps as $c): ?> <tr> <td class="result-cell"><?php echo htmlspecialchars($c['result']); ?></td> <td></td> <td><?php echo htmlspecialchars($c['unit']); ?></td> <?php $rImg = (string)($c['range'] ?? ''); if (preg_match('/^\[?\s*dropdown\s*\]?$/i', trim($rImg))) { $rImg = ''; } ?> <td><?php echo htmlspecialchars(getApplicableRange($rImg, $result['gender'], $age)); ?></td> <td><?php echo htmlspecialchars($c['name']); ?></td> </tr> <?php endforeach; ?> <?php else: // Single Result or Impression Only ?> <tr> <td class="result-cell">See Impression</td> <td></td> <td><?php echo htmlspecialchars($result['unit']); ?></td> <td><?php echo htmlspecialchars(getApplicableRange($result['normal_range'] ?? '', $result['gender'], $age)); ?></td> <td><?php echo $showRemarks ? htmlspecialchars((string)($result['remarks'] ?? '')) : ''; ?></td> </tr> <?php endif; ?> <?php if (!empty($impression)): ?> <tr> <td colspan="<?php echo $is_multi ? '9' : '5'; ?>" class="p-2"> <strong>IMPRESSION:</strong><br> <div class="ps-2" style="white-space: pre-wrap;"><?php echo htmlspecialchars($impression); ?></div> </td> </tr> <?php endif; ?> <?php if ($showRemarks && !empty(trim((string)($result['remarks'] ?? '')))): ?> <tr> <td colspan="<?php echo $is_multi ? '9' : '5'; ?>" class="p-2"> <strong>REMARKS:</strong><br> <div class="ps-2" style="white-space: pre-wrap;"><?php echo htmlspecialchars((string)$result['remarks']); ?></div> </td> </tr> <?php endif; ?> </tbody> </table> </div> <!-- Signatures --> <?php $enteredById = (int)($result['entered_by'] ?? 0); $validatedById = (int)($result['validated_by'] ?? 0); $isSelfValidated = $enteredById > 0 && $validatedById > 0 && $enteredById === $validatedById; ?> <div class="signatures-section"> <div class="sig-box"> <div class="sig-label">PERFORMED BY:</div> <div class="sig-image-container"> <?php if (!empty($result['entered_by_sig']) && file_exists($result['entered_by_sig'])): ?> <img src="<?php echo $result['entered_by_sig']; ?>"> <?php endif; ?> </div> <div class="sig-line"></div> <div class="sig-name"><?php echo htmlspecialchars($result['entered_by_name'] ?? 'Authorized Personnel'); ?></div> <div class="sig-role">Medical Technologist / Rad. Tech</div> </div> <?php if (!$isSelfValidated): ?> <div class="sig-box"> <div class="sig-label">VALIDATED BY:</div> <div class="sig-image-container"> <?php if (!empty($result['validated_by_sig']) && file_exists($result['validated_by_sig'])): ?> <img src="<?php echo $result['validated_by_sig']; ?>"> <?php endif; ?> </div> <div class="sig-line"></div> <div class="sig-name"><?php echo htmlspecialchars($result['validated_by_name'] ?? 'Authorized Validator'); ?></div> <div class="sig-role"><?php echo htmlspecialchars($result['validated_by_role'] ?? 'Pathologist / Radiologist'); ?></div> </div> <?php endif; ?> <div class="sig-box"> <div class="sig-label">VERIFIED BY:</div> <div class="sig-image-container"> <?php if(!empty($pathologist_signature) && file_exists($pathologist_signature)): ?> <img src="<?php echo htmlspecialchars($pathologist_signature); ?>"> <?php endif; ?> </div> <div class="sig-line"></div> <div class="sig-name"><?php echo htmlspecialchars($pathologist_name !== '' ? $pathologist_name : ($result['validated_by_name'] ?? '_______________________')); ?></div> <div class="sig-role">Pathologist</div> <?php if(!empty($pathologist_license)): ?> <div class="sig-role" style="font-size: 6pt;">Lic. No. <?php echo htmlspecialchars($pathologist_license); ?></div> <?php endif; ?> </div> </div> <?php echo $footer_html; ?> </div> <!-- Attachment Pages --> <?php if (!empty($attachments)): ?> <?php foreach ($attachments as $att): ?> <?php $ext = strtolower(pathinfo($att, PATHINFO_EXTENSION)); if (in_array($ext, ['jpg', 'jpeg', 'png', 'gif'])): // Check if this is the very last page of the entire document $is_last_page = ($index === count($results_data) - 1 && $att === end($attachments)); ?> <div class="test-page-wrapper" style="justify-content: center; align-items: center; <?php echo $is_last_page ? 'page-break-after: avoid;' : 'page-break-after: always;'; ?>"> <?php echo $header_html; ?> <div style="flex: 1; display: flex; flex-direction: column; justify-content: center; align-items: center; width: 100%;"> <h5 class="mb-3">Attached Image</h5> <img src="uploads/results/<?php echo $att; ?>" style="max-width: 100%; max-height: 90mm; object-fit: contain; border: 1px solid #ddd;"> </div> <?php echo $footer_html; ?> </div> <?php endif; ?> <?php endforeach; ?> <?php endif; ?> <?php endforeach; ?> </div> </body> </html>
Batal