<?php
include "config.php";

$id = $_GET['id'];

/* Fetch prescription + patient */
$p=mysqli_fetch_assoc(mysqli_query($conn,"
SELECT prescriptions.*,patients.name,patients.age,patients.gender,patients.mobile
FROM prescriptions
JOIN patients ON prescriptions.patient_id=patients.id
WHERE prescriptions.id='$id'
"));

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

/* Dynamic PDF link (no storage required) */
$pdf_link = "https://kolhapurairport.com/clinic/view_prescription.php?id=".$id;


/* Professional WhatsApp message */

$msg = "🏥 *".$doc['clinic_name']."*\n";
$msg .= "🌐 https://kolhapurairport.com\n\n";

$msg .= "👨‍⚕ *".$doc['doctor_name']."*\n";
$msg .= $doc['qualification']."\n\n";

$msg .= "━━━━━━━━━━━━━━━\n";

$msg .= "👤 *Patient:* ".$p['name']."\n";
$msg .= "🎂 *Age:* ".$p['age']." | ".$p['gender']."\n";
$msg .= "📅 *Date:* ".date("d-m-Y",strtotime($p['created_at']))."\n\n";

$msg .= "📄 *Prescription PDF*\n";

$msg .= $pdf_link;


/* Encode */
$msg = urlencode($msg);

/* Redirect to WhatsApp */
header("Location: https://wa.me/91".$p['mobile']."?text=".$msg);
exit;
?>