make this codes (<?php
session_start();
require_once '../db_connect.php';

// Include Dompdf library
require '../dompdf/autoload.inc.php';

// Use Dompdf namespaces
use Dompdf\Dompdf;
use Dompdf\Options;

// Check if the admin is logged in
if (!isset($_SESSION['admin_id'])) {
    header("Location: ../admin_login.php");
    exit();
}

// Get the prescription ID from the URL
if (!isset($_GET['id'])) {
    echo "Prescription ID not provided.";
    exit();
}

$id = $_GET['id'];

// Fetch prescription details along with patient and doctor information
$stmt = $pdo->prepare("
    SELECT p.*,
           pat.name AS patient_name, pat.age AS patient_age, pat.gender AS patient_gender, pat.date_of_birth AS patient_dob,
           doc.name AS doctor_name, doc.specialization AS doctor_specialization, doc.phone AS doctor_phone, doc.email AS doctor_email, doc.profile_picture AS doctor_profile_picture
    FROM prescriptions p
    LEFT JOIN patients pat ON p.patient_id = pat.id
    LEFT JOIN doctors doc ON p.doctor_id = doc.id
    WHERE p.id = ?
");
$stmt->execute([$id]);
$prescription = $stmt->fetch(PDO::FETCH_ASSOC);

if (!$prescription) {
    echo "Prescription not found.";
    exit();
}

// Escape and format output data
$prescription_id = htmlspecialchars($prescription['id']);
$prescription_date = date('m/d/Y', strtotime($prescription['date_prescribed']));
$patient_name = htmlspecialchars($prescription['patient_name']);
$patient_age = htmlspecialchars($prescription['patient_age']);
$patient_gender = htmlspecialchars($prescription['patient_gender']);
$patient_dob = date('m/d/Y', strtotime($prescription['patient_dob']));
$doctor_name = htmlspecialchars($prescription['doctor_name']);
$doctor_specialization = htmlspecialchars($prescription['doctor_specialization']);
$doctor_phone = htmlspecialchars($prescription['doctor_phone']);
$doctor_email = htmlspecialchars($prescription['doctor_email']);
$doctor_profile_picture = htmlspecialchars($prescription['doctor_profile_picture']);
$instructions = htmlspecialchars_decode(nl2br(htmlspecialchars($prescription['instructions'])));

// Prepare medications
$medications = json_decode($prescription['medications'], true);

// Convert images to data URIs
function getImageDataUri($filePath) {
    if (file_exists($filePath)) {
        $imageData = base64_encode(file_get_contents($filePath));
        $mimeType = mime_content_type($filePath);
        return 'data:' . $mimeType . ';base64,' . $imageData;
    }
    return '';
}

$logo_src = getImageDataUri('../images/gold-logo.png');
$signature_src = getImageDataUri('../images/signature.png');
$stamp_src = getImageDataUri('../images/stamp.png');
$doctor_profile_picture_src = getImageDataUri('../uploads/' . $doctor_profile_picture);

// Start output buffering to capture HTML content
ob_start();
?>

<!DOCTYPE html>
<html>
<head>
    <title>Prescription</title>
    <style>
        body {
            background-color: #f8f9fa;
            font-family: Arial, sans-serif;
            margin: 0;
            padding: 0;
        }
        .container {
            width: 100%;
            max-width: 800px;
            margin: 0 auto;
            padding: 20px;
            background-color: #fff;
            border-radius: 8px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
        }
        .header {
            text-align: center;
            margin-bottom: 20px;
        }
        .header img {
            max-width: 100px;
            margin-bottom: 10px;
        }
        .header h1 {
            margin: 0;
            font-size: 24px;
            color: #4F3F02;
        }
        .header p {
            margin: 5px 0;
            color: #666;
        }
        .patient-info, .medications, .footer {
            margin-bottom: 20px;
        }
        .patient-info p, .medications p, .footer p {
            margin: 5px 0;
        }
        .medications table {
            width: 100%;
            border-collapse: collapse;
            margin-top: 10px;
        }
        .medications table, .medications th, .medications td {
            border: 1px solid #ddd;
        }
        .medications th, .medications td {
            padding: 8px;
            text-align: left;
        }
        .signature-section {
            display: flex;
            justify-content: space-between;
            align-items: center;
        }
        .signature img, .stamp img {
            max-width: 100px;
        }
        .footer {
            text-align: center;
            font-size: 12px;
            color: #666;
        }
    </style>
</head>
<body>

<div class="container">
    <div class="header">
        <?php if ($logo_src): ?>
            <img src="<?php echo $logo_src; ?>" alt="Logo">
        <?php endif; ?>
        <h1>Dr. <?php echo $doctor_name; ?></h1>
        <p><?php echo $doctor_specialization; ?></p>
        <p>Phone: <?php echo $doctor_phone; ?> | Email: <?php echo $doctor_email; ?></p>
    </div>

    <div class="patient-info">
        <p><strong>Patient Name:</strong> <?php echo $patient_name; ?></p>
        <p><strong>Age:</strong> <?php echo $patient_age; ?> | <strong>Date of Birth:</strong> <?php echo $patient_dob; ?></p>
        <p><strong>Gender:</strong> <?php echo $patient_gender; ?></p>
        <p><strong>Date:</strong> <?php echo $prescription_date; ?></p>
        <p><strong>Prescription ID:</strong> <?php echo $prescription_id; ?></p>
    </div>

    <div class="medications">
        <h2>Medications</h2>
        <?php if ($medications && is_array($medications)): ?>
            <table>
                <thead>
                    <tr>
                        <th>Medicine Name</th>
                        <th>Dosage</th>
                        <th>Frequency</th>
                        <th>Duration</th>
                        <th>Instructions</th>
                    </tr>
                </thead>
                <tbody>
                    <?php foreach ($medications as $med): ?>
                        <tr>
                            <td><?php echo htmlspecialchars($med['name']); ?></td>
                            <td><?php echo htmlspecialchars($med['dosage']); ?></td>
                            <td><?php echo htmlspecialchars($med['frequency']); ?></td>
                            <td><?php echo htmlspecialchars($med['duration']); ?></td>
                            <td><?php echo htmlspecialchars($med['instructions']); ?></td>
                        </tr>
                    <?php endforeach; ?>
                </tbody>
            </table>
        <?php else: ?>
            <p><?php echo nl2br(htmlspecialchars($prescription['medications'])); ?></p>
        <?php endif; ?>
    </div>

    <div class="signature-section">
        <div class="signature">
            <?php if ($signature_src): ?>
                <img src="<?php echo $signature_src; ?>" alt="Signature">
            <?php endif; ?>
            <p>Doctor's Signature</p>
        </div>
        <div class="stamp">
            <?php if ($stamp_src): ?>
                <img src="<?php echo $stamp_src; ?>" alt="Stamp">
            <?php endif; ?>
        </div>
    </div>

    <div class="footer">
        <p>Contact Us<br>
        Email: info@longevacare.com<br>
        Phone: +971 528 863 600<br>
        WhatsApp: +1 (702) 526-2050<br>
        Location: HDS Tower, Cluster M, JLT, Dubai</p>
    </div>
</div>

</body>
</html>

<?php
// Capture the HTML content into a variable
$html = ob_get_clean();

// Initialize Dompdf with options
$options = new Options();
$options->set('isHtml5ParserEnabled', true);
$options->set('isRemoteEnabled', true); // Enable loading of images
$dompdf = new Dompdf($options);

// Load HTML content
$dompdf->loadHtml($html);

// Set paper size and orientation
$dompdf->setPaper('A4', 'portrait');

// Render the HTML as PDF
$dompdf->render();

// Output the generated PDF to browser
$dompdf->stream('Prescription_' . $prescription_id . '.pdf', array("Attachment" => 0));
?>) more cool and add shapes Like DNA and CEll and add more codes to mkae it prescription professioanl and type full codes