<?php
session_start();
if(!isset($_SESSION['admin'])){
header("Location:index.php");
exit();
}
include "config.php";
include "header.php";
?>

<head>
    <link rel="stylesheet" href="assets/style.css">
    
</head>

<div class="card p-3 shadow">

<a href="add_patient.php" class="btn btn-primary">Add Patient</a>
</div>

<h4>Patients</h4>

<input type="text" id="search" placeholder="Search Patient..." onkeyup="loadData(this.value)">
<div id="result"></div>
<div class="table-reaponsive">


<table class="table table-bordered">
<tr>
<th>ID</th><th>Name</th><th>Age</th><th>Gender</th><th>Mobile</th><th>Action</th>
</tr>

<?php
$r=mysqli_query($conn,"SELECT * FROM patients where is_deleted=0 ");
while($row=mysqli_fetch_assoc($r)){
echo "<tr>";
echo "<td>".$row['id']."</td>";
echo "<td>".$row['name']."</td>";
echo "<td>".$row['age']."</td>";
echo "<td>".$row['gender']."</td>";
echo "<td>".$row['mobile']."</td>";
echo "<td>
<a href='edit_patient.php?id=".$row['id']."' class='btn btn-sm btn-warning'>Edit</a>
<a href='delete_patient.php?id=".$row['id']."' class='btn btn-sm btn-danger'>Delete</a>
<a href='prescription.php?id=".$row['id']."' class='btn btn-sm btn-primary'>Prescription</a>
<a href='patient_history.php?id=".$row['id']."' class='btn btn-info btn-sm'>History</a>
</td>";
echo "</tr>";
}
?>
</table>
</div>


<script>
function loadData(v){
fetch("search_patient.php?q="+v)
.then(res=>res.text())
.then(data=>{
document.getElementById("result").innerHTML=data;
});
}
</script>

<?php include "footer.php"; ?>
