-
Notifications
You must be signed in to change notification settings - Fork 2
/
patient-panel.php
587 lines (539 loc) · 19.3 KB
/
patient-panel.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
<!DOCTYPE html>
<?php
include('function.php');
include('newfunction.php');
$con = mysqli_connect("localhost", "root", "", "hms");
if (!$con) {
die("Connection failed: " . mysqli_connect_error());
}
$pid = $_SESSION['pid'];
$username = $_SESSION['username'];
$email = $_SESSION['email'];
$fname = $_SESSION['fname'];
$gender = $_SESSION['gender'];
$lname = $_SESSION['lname'];
$contact = $_SESSION['contact'];
if (isset($_POST['app-submit'])) {
$pid = $_SESSION['pid'];
$username = $_SESSION['username'];
$email = $_SESSION['email'];
$fname = $_SESSION['fname'];
$lname = $_SESSION['lname'];
$gender = $_SESSION['gender'];
$contact = $_SESSION['contact'];
$doctor = $_POST['doctor'];
$email = $_SESSION['email'];
$docFees = $_POST['docFees'];
$appdate = $_POST['appdate'];
$apptime = $_POST['apptime'];
$cur_date = date("Y-m-d");
date_default_timezone_set('Asia/Kathmandu');
$cur_time = date("H:i:s");
$apptime1 = strtotime($apptime);
$appdate1 = strtotime($appdate);
// Calculate the date one month from now
$oneMonthFromNow = date("Y-m-d", strtotime("+1 month"));
if ($appdate1 < strtotime($oneMonthFromNow)) {
if (date("Y-m-d", $appdate1) >= $cur_date) {
if ((date("Y-m-d", $appdate1) == $cur_date and date("H:i:s", $apptime1) > $cur_time) or date("Y-m-d", $appdate1) > $cur_date) {
$check_query = mysqli_query($con, "SELECT apptime FROM appointment WHERE doctor='$doctor' AND appdate='$appdate' AND apptime='$apptime' AND (userStatus='1' AND doctorStatus='1')");
if (mysqli_num_rows($check_query) == 0) {
$query = mysqli_query($con, "insert into appointment(pid,fname,lname,gender,email,contact,doctor,docFees,appdate,apptime,userStatus,doctorStatus) values($pid,'$fname','$lname','$gender','$email','$contact','$doctor','$docFees','$appdate','$apptime','1','1')");
if ($query) {
echo "<script>alert('Your appointment successfully booked');</script>";
} else {
echo "<script>alert('Unable to process your request. Please try again!');</script>";
}
} else {
echo "<script>alert('We are sorry to inform that the doctor is not available at this time or date. Please choose a different time or date!');</script>";
}
} else {
echo "<script>alert('Select a time or date in the future!');</script>";
}
} else {
echo "<script>alert('Select a time or date in the future!');</script>";
}
} else {
echo "<script>alert('Select a date within one month from now!');</script>";
}
}
if (isset($_GET['cancel'])) {
$query = mysqli_query($con, "update appointment set userStatus='0' where AppID = '" . $_GET['AppID'] . "'");
if ($query) {
echo "<script>alert('Your appointment successfully cancelled');</script>";
}
}
function get_specs()
{
$con = mysqli_connect("localhost", "root", "", "hms");
$query = mysqli_query($con, "select username, spec from doctor");
$docarray = array();
while ($row = mysqli_fetch_assoc($query)) {
$docarray[] = $row;
}
$options = '';
foreach ($docarray as $doc) {
$options .= '<option value="' . $doc['username'] . '">' . $doc['spec'] . '</option>';
}
return $options;
}
if (isset($_POST['submit'])) {
$email = $_POST['email'];
$pwd = $_POST['password'];
$query = "UPDATE patient SET password='$pwd' WHERE email='$email'";
$data = mysqli_query($con, $query);
if ($data) {
echo " <script> alert('password changed')</script>";
} else {
echo "Failed to change password";
}
}
// Function to check if the appointment is prescribed
function isAccepted($id)
{
global $con;
$query = "SELECT * FROM appointment WHERE AppID = '$id' AND doctorStatus=0";
$result = mysqli_query($con, $query);
return mysqli_num_rows($result) > 0;
}
// Function to check if the appointment is cancelled
function isCancelled($id)
{
global $con;
$query = "SELECT * FROM appointment WHERE AppID = '$id' AND userStatus = 0";
$result = mysqli_query($con, $query);
return mysqli_num_rows($result) > 0;
}
?>
<script>
function validateAppointmentForm() {
var spec = document.getElementById('spec').value;
var doctor = document.getElementById('doctor').value;
var docFees = document.getElementById('docFees').value;
var appdate = document.querySelector('[name=appdate]').value;
var apptime = document.getElementById('apptime').value;
if (spec === "" || doctor === "" || docFees === "" || appdate === "" || apptime === "") {
alert("Please select all required fields.");
return false;
}
return true;
}
</script>
<html lang="en">
<head>
<script src="https://kit.fontawesome.com/2323653b3c.js" crossorigin="anonymous"></script>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="style.css">
<link rel="stylesheet" href="style4.css">
<link href='https://unpkg.com/[email protected]/css/boxicons.min.css' rel='stylesheet'>
<style>
.status-prescribed {
color: green;
font-weight: bold;
}
.status-canceled {
color: red;
font-weight: bold;
}
</style>
<body>
<!-- dashboard -->
<div class="sidebar">
<div class="logo-details">
<i class='bx bx-plus-medical'></i>
<span class="logo_name"><a href="#"> MediBook: Appointment Schedule</a></span>
</div>
<ul class="nav-links">
<li>
<a class="active" href="#list-dash">
<i class='bx bx-grid-alt'></i>
<span class="links_name">Dashboard</span>
</a>
</li>
<li>
<a href="#list-doc" id="list-doc-list">
<i class='bx bx-list-ul'></i>
<span class="links_name">Book Appointment</span>
</a>
</li>
<li>
<a href="#list-app" id="list-pat-list" role="tab" data-toggle="list" aria-controls="home">
<i class='bx bx-list-ul'></i>
<span class="links_name">Appointment History</span>
</a>
</li>
<li>
<a href="#list-pres" id="list-pres-list" role="tab" data-toggle="list" aria-controls="home">
<i class='bx bx-detail'></i>
<span class="links_name">Prescriptions</span>
</a>
</li>
<li>
<a href="#list-change-password" id="list-pres-list" role="tab" data-toggle="list" aria-controls="home">
<i class='bx bx-detail'></i>
<span class="links_name">Change Password</span>
</a>
</li>
<li class="log_out">
<a href="logout.php" onclick="logout()">
<i class='bx bx-log-out'></i>
<span class="links_name">Log out</span>
</a>
</li>
</ul>
</div>
<!-- sections -->
<div class="section-container" id="sections">
<!-- navbar -->
<nav>
<div class="welcome">
<i class='bx bx-menu sidebarBtn'></i>
<span class="admin">
<?php
$greeting = "Welcome, " . $username;
echo $greeting;
?>
</span>
</div>
</nav>
<!-- Default contents and dashboard contents -->
<div class="home-content" id="list-dash">
<div class="overview-boxes">
<div class="box">
<div class="right-side">
<span class="fa-stack fa-2x">
<i class="fa fa-square fa-stack-2x text-primary"></i>
<i class="fa fa-users fa-stack-1x fa-inverse"></i>
</span>
<h4>Book My Appointment</h4>
<p class="cl-effect-1">
<a href="#app-hist" onclick="clickDiv('#list-doc-list')">
Book Appointment
</a>
</p>
</div>
</div>
<div class="box">
<div class="right-side">
<span class="fa-stack fa-2x">
<i class="fa fa-square fa-stack-2x text-primary"></i>
<i class="fa fa-paperclip fa-stack-1x fa-inverse"></i>
</span>
<h4>My Appointments</h4>
<p class="cl-effect-1">
<a href="#app-hist" onclick="clickDiv('#list-pat-list')">
View Appointment History
</a>
</p>
</div>
</div>
<div class="box">
<div class="right-side">
<span class="fa-stack fa-2x">
<i class="fa fa-square fa-stack-2x text-primary"></i>
<i class="fa fa-list-ul fa-stack-1x fa-inverse"></i>
</span>
<h4>Prescriptions</h4>
<p>
<a href="#list-pres" onclick="clickDiv('#list-pres-list')">
View Prescriptions List
</a>
</p>
</div>
</div>
</div>
</div>
<!-- Book Appointment section -->
<div class="home-content" id="list-doc">
<div class="hcontent">
<h4>Create an appointment</h4>
<form class="form-group" method="post" action="patient-panel.php" onsubmit="return validateAppointmentForm();">
<div>
<label for="spec">Specialization:</label>
</div>
<div class="selspec">
<select name="spec" class="form-control" id="spec">
<option value="" disabled selected>Select Specialization</option>
<?php
display_specs();
?>
</select>
</div>
<script>
document.getElementById('spec').onchange = function () {
let spec = this.value;
let docs = [...document.getElementById('doctor').options];
docs.forEach((el, ind, arr) => {
arr[ind].setAttribute("style", "");
if (el.getAttribute("data-spec") != spec) {
arr[ind].setAttribute("style", "display: none");
}
});
// Reset doctor selection and fees when specialization changes
document.getElementById('doctor').selectedIndex = 0;
document.getElementById('docFees').value = '';
};
document.getElementById('doctor').onchange = function () {
var selection = document.querySelector(`[value="${this.value}"]`).getAttribute('data-value');
document.getElementById('docFees').value = selection;
};
</script>
<div>
<label for="doctor">Doctors:</label>
</div>
<div class="sdoc">
<select name="doctor" class="form-control" id="doctor">
<option value="" disabled selected>Select Doctor</option>
<?php display_docs(); ?>
</select>
</div>
<script>
document.getElementById('doctor').onchange = function updateFees(e) {
var selection = document.querySelector(`[value="${this.value}"]`).getAttribute('data-value');
document.getElementById('docFees').value = selection;
};
</script>
<div>
<label for="consultancyfees">
Consultancy Fees
</label>
</div>
<div class="Fees">
<input class="form-control" type="text" name="docFees" id="docFees" readonly="readonly" />
</div>
<div>
<label>Appointment Date</label>
</div>
<div class="apdate">
<input type="date" class="form-control datepicker" name="appdate">
</div>
<div>
<label>Appointment Time</label>
</div>
<div class="Stime">
<select name="apptime" class="form-control" id="apptime">
<option value="" disabled selected>Select Time</option>
<option value="08:00:00">8:00 AM</option>
<option value="10:00:00">10:00 AM</option>
<option value="12:00:00">12:00 PM</option>
<option value="14:00:00">2:00 PM</option>
<option value="16:00:00">4:00 PM</option>
</select>
</div><br>
<center>
<div class="btn">
<input type="submit" name="app-submit" value="Create new entry" class="btn btn-primary" id="inputbtn">
</div>
</center>
</form>
</div>
</div>
<!-- Appointment history section -->
<div class="home-content" id="list-app">
<div>
<table class="app-table">
<thead>
<tr>
<th scope="col">Doctor Name</th>
<th scope="col">Consultancy Fees</th>
<th scope="col">Appointment Date</th>
<th scope="col">Appointment Time</th>
<th scope="col">Current Status</th>
<th scope="col">Action</th>
</tr>
</thead>
<tbody>
<?php
$con = mysqli_connect("localhost", "root", "", "hms");
global $con;
$query = "SELECT AppID, doctor, docFees, appdate, apptime, userStatus, doctorStatus FROM appointment WHERE fname ='$fname' AND lname='$lname';";
$result = mysqli_query($con, $query);
while ($row = mysqli_fetch_array($result)) {
$doctor = $row['doctor'];
$docFees = $row['docFees'];
$appdate = $row['appdate'];
$apptime = $row['apptime'];
$userStatus = $row['userStatus'];
$doctorStatus = $row['doctorStatus'];
$AppID = $row['AppID'];
// Check if appointment is prescribed or cancelled
$accepted = isAccepted($AppID);
$cancelled = isCancelled($AppID);
?>
<tr>
<th scope="row">
<?php echo $doctor; ?>
</th>
<td>
<?php echo $docFees; ?>
</td>
<td>
<?php echo $appdate; ?>
</td>
<td>
<?php echo $apptime; ?>
</td>
<td>
<?php
if ($cancelled) {
echo "Cancelled";
} elseif ($accepted) {
echo "Accepted";
} else {
echo "Active";
}
?>
</td>
<td>
<?php if (!$cancelled && !$accepted) { ?>
<a href="doctor-panel.php?AppID=<?php echo $row['AppID'] ?>&cancel=update"
onClick="return confirm('Are you sure you want to cancel this appointment?')"
title="Cancel Appointment">
<button class="btn btn-primary">Cancel</button>
</a>
<?php } ?>
</td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
</div>
<!-- Prescription section -->
<div class="home-content" id="list-pres">
<div>
<table class="pres-table">
<thead>
<tr>
<th scope="col">Doctor Name</th>
<th scope="col">Appointment ID</th>
<th scope="col">Appointment Date</th>
<th scope="col">Appointment Time</th>
<th scope="col">Diseases</th>
<th scope="col">Allergies</th>
<th scope="col">Prescriptions</th>
</tr>
</thead>
<tbody>
<?php
$con = mysqli_connect("localhost", "root", "", "hms");
global $con;
$query = "select doctor,AppID,appdate,apptime,disease,allergy,prescription from prescriptiontable where pid='$pid';";
$result = mysqli_query($con, $query);
if (!$result) {
echo mysqli_error($con);
}
while ($row = mysqli_fetch_array($result)) {
?>
<tr>
<td>
<?php echo $row['doctor']; ?>
</td>
<td>
<?php echo $row['AppID']; ?>
</td>
<td>
<?php echo $row['appdate']; ?>
</td>
<td>
<?php echo $row['apptime']; ?>
</td>
<td>
<?php echo $row['disease']; ?>
</td>
<td>
<?php echo $row['allergy']; ?>
</td>
<td>
<?php echo $row['prescription']; ?>
</td>
</form>
</tr>
<?php }
?>
</tbody>
</table>
<br>
</div>
</div>
<!-- Change Password section -->
<div class="home-content" id="list-change-password">
<div class="change-password-form">
<center>
<h4>Change Password</h4>
</center>
<form class="form-group" method="post" action="patient-panel.php">
<div>
<label for="email">Email:</label>
</div>
<div>
<input type="email" name="email" class="form-control" required>
</div>
<div>
<label for="new-password">New Password:</label>
</div>
<div>
<input type="password" name="password" class="form-control" required>
</div><br>
<div class="btn">
<input type="submit" name="submit" value="Change Password" class="btn btn-primary">
</div>
</form>
</div>
</div>
</div>
<script>
document.addEventListener("DOMContentLoaded", function () {
const sidebarBtn = document.querySelector(".sidebarBtn");
const sidebar = document.querySelector(".sidebar");
const sections = document.querySelector("#sections");
const links = document.querySelectorAll(".nav-links li a");
// Show the dashboard section by default
document.getElementById("list-dash").style.display = "block";
document.getElementById("list-doc").style.display = "none";
document.querySelector(".nav-links li a.active").classList.remove("active");
document.querySelector(".nav-links li a[href='#list-dash']").classList.add("active");
// Hide other sections when the page loads
document.querySelectorAll(".home-content").forEach(function (section) {
if (section.id !== "list-dash") {
section.style.display = "none";
}
});
// Toggle sidebar
sidebarBtn.onclick = function () {
sidebar.classList.toggle("active");
if (sidebar.classList.contains("active")) {
sidebarBtn.classList.replace("bx-menu", "bx-menu-alt-right");
} else {
sidebarBtn.classList.replace("bx-menu-alt-right", "bx-menu");
}
};
// Handle click events for navigation links
links.forEach(function (link) {
link.addEventListener("click", function (event) {
event.preventDefault();
const targetSection = document.querySelector(this.getAttribute("href"));
sections.querySelectorAll(".home-content").forEach(function (section) {
section.style.display = "none";
});
targetSection.style.display = "block";
document.querySelector(".nav-links li a.active").classList.remove("active");
this.classList.add("active");
});
});
});
// logout button code
function logout() {
event.preventDefault();
window.location.href = "logout.php"; // Redirect to logout.php
}
// default page contents js
function clickDiv(id) {
document.querySelector(id).click();
}
</script>
</body>
</html>