<?php
error_reporting(E_ALL);
ini_set('display_errors',1);
require 'dompdf/autoload.inc.php';
use Dompdf\Dompdf;

include "config.php";

$pid = $_GET['pid'];
$pres_id = $_GET['prescription_id'];

$patient = mysqli_fetch_assoc(mysqli_query($conn,"
SELECT * FROM patients WHERE id='$pid'
"));

$pres = mysqli_fetch_assoc(mysqli_query($conn,"
SELECT * FROM prescriptions WHERE id='$pres_id'
"));

$doc = mysqli_fetch_assoc(mysqli_query($conn,"
SELECT * FROM doctor_profile LIMIT 1
"));

$html = "
<div style='text-align:center'>
<h2>{$doc['clinic_name']}</h2>
<b>Dr. {$doc['doctor_name']}</b><br>
{$doc['qualification']}<br>
Reg No: {$doc['reg_no']}<br>
Mobile: {$doc['mobile']}
</div>
<hr>

<h3 style='text-align:center;text-decoration:underline'>MEDICAL CERTIFICATE</h3>

<p>
This is to certify that <b>{$patient['name']}</b>,
Age <b>{$patient['age']}</b> years,
was under my treatment on
<b>".date("d-m-Y",strtotime($pres['created_at']))."</b>.
</p>

<p>
He / She was suffering from:
<b>{$pres['diagnosis']}</b>.
</p>

<p>
He / She is advised rest from
<b>".date("d-m-Y")."</b>
to
<b>".date("d-m-Y", strtotime("+3 days"))."</b>.
</p>

<p>
In my opinion, the patient is fit to resume duties thereafter.
</p>

<br><br>
<img src='uploads/{$doc['signature']}' width='120'><br>
<b>Doctor Signature</b><br>
Date: ".date("d-m-Y")."
";

$pdf = new Dompdf();
$pdf->loadHtml($html);
$pdf->setPaper('A4','portrait');
$pdf->render();

$pdf->stream("medical_certificate.pdf",["Attachment"=>true]);