-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathappointment.php
More file actions
168 lines (153 loc) · 7.27 KB
/
Copy pathappointment.php
File metadata and controls
168 lines (153 loc) · 7.27 KB
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
<?php
session_start();
require_once('db_connection.php');
// Check if user is logged in as a doctor
if (!isset($_SESSION['user_id']) || $_SESSION['user_type'] !== 'doctor') {
header("Location: index.php");
exit();
}
function sanitize_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
// Fetch doctor's first name
$doctorId = $_SESSION['user_id'];
$queryDoctor = "SELECT fname FROM staff WHERE id = ?";
$stmtDoctor = $conn->prepare($queryDoctor);
$stmtDoctor->bind_param("i", $doctorId);
$stmtDoctor->execute();
$resultDoctor = $stmtDoctor->get_result();
$rowDoctor = $resultDoctor->fetch_assoc();
$doctorFirstName = $rowDoctor['fname'];
$stmtDoctor->close();
// Initialize variables for form values and errors
$prescription = $doctorsNote = $diagnosis = $allergies = '';
$prescriptionErr = '';
// Process form submissions
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// Handle appointment and patient updates together
if (isset($_POST['finishAppointment'])) {
$appointmentId = $_POST['appointment_id'];
$prescription = sanitize_input($_POST['prescription']);
$doctorsNote = sanitize_input($_POST['doctors_note']);
$diagnosis = sanitize_input($_POST['diagnosis']);
$allergies = sanitize_input($_POST['allergies']);
$patientId = $_POST['patient_id'];
// Validate prescription (optional based on your needs)
if (empty($prescription)) {
$prescriptionErr = 'Prescription is required';
} else {
// Update appointment table
$updateAppointmentQuery = "UPDATE appointment SET prescription = ?, doctors_note = ?, diagnosis = ?, status = 'finished' WHERE id = ?";
$stmtUpdateAppointment = $conn->prepare($updateAppointmentQuery);
$stmtUpdateAppointment->bind_param("sssi", $prescription, $doctorsNote, $diagnosis, $appointmentId);
$appointmentUpdated = $stmtUpdateAppointment->execute();
$stmtUpdateAppointment->close();
// Update patient allergies
$updatePatientQuery = "UPDATE patients SET allergies = ? WHERE id = ?";
$stmtUpdatePatient = $conn->prepare($updatePatientQuery);
$stmtUpdatePatient->bind_param("si", $allergies, $patientId);
$patientUpdated = $stmtUpdatePatient->execute();
$stmtUpdatePatient->close();
if ($appointmentUpdated && $patientUpdated) {
// Success message or redirect to another page
header("Location: doctordash.php");
exit();
} else {
echo "Error updating appointment or patient information";
}
}
}
}
// Fetch appointment and patient information
if (isset($_GET['id'])) {
$appointmentId = $_GET['id'];
// Fetch appointment details including patient information
$queryAppointment = "SELECT appointment.id, appointment.pref_schedule, appointment.prescription, appointment.doctors_note, appointment.diagnosis,
users.fname AS patient_fname, users.lname AS patient_lname, appointment.patientID,
patients.height, patients.weight
FROM appointment
INNER JOIN patients ON appointment.patientID = patients.id
INNER JOIN users ON patients.usersID = users.id
WHERE appointment.id = ?";
$stmt = $conn->prepare($queryAppointment);
$stmt->bind_param("i", $appointmentId);
$stmt->execute();
$resultAppointment = $stmt->get_result();
$appointment = $resultAppointment->fetch_assoc();
$stmt->close();
// Fetch patient allergies
$queryPatient = "SELECT allergies FROM patients WHERE id = ?";
$stmt = $conn->prepare($queryPatient);
$stmt->bind_param("i", $appointment['patientID']);
$stmt->execute();
$resultPatient = $stmt->get_result();
$patient = $resultPatient->fetch_assoc();
$stmt->close();
} else {
// Redirect if appointment ID is not provided
header("Location: doctordash.php");
exit();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Appointment Details</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
</head>
<body>
<nav class="navbar navbar-light bg-light">
<a class="navbar-brand">Doctor Dashboard</a>
<p class="mr-3 mt-2">Welcome, <?php echo $doctorFirstName; ?></p>
<form method="post" class="form-inline">
<a href="patientlist.php" class="nav-item nav-link">Patients</a>
<button type="submit" class="btn btn-outline-danger my-2 my-sm-0" name="logout">Logout</button>
</form>
</nav>
<div class="container mt-3">
<a href="doctordash.php" class="btn btn-secondary">Back to Dashboard</a>
</div>
<div class="container mt-3">
<div class="card">
<div class="card-header">
Appointment Details
</div>
<div class="card-body">
<h5 class="card-title">Patient: <?php echo $appointment['patient_fname'] . ' ' . $appointment['patient_lname']; ?></h5>
<p class="card-text">Preferred Schedule: <?php echo $appointment['pref_schedule']; ?></p>
<p class="card-text">Height: <?php echo $appointment['height']; ?> cm</p>
<p class="card-text">Weight: <?php echo $appointment['weight']; ?> kg</p>
<hr>
<!-- Update Form -->
<form method="post">
<input type="hidden" name="appointment_id" value="<?php echo $appointment['id']; ?>">
<input type="hidden" name="patient_id" value="<?php echo $appointment['patientID']; ?>">
<div class="form-group">
<label for="prescription">Prescription:</label>
<textarea class="form-control" id="prescription" name="prescription" rows="3"><?php echo $appointment['prescription']; ?></textarea>
<small class="text-danger"><?php echo $prescriptionErr; ?></small>
</div>
<div class="form-group">
<label for="doctors_note">Doctor's Note:</label>
<textarea class="form-control" id="doctors_note" name="doctors_note" rows="3"><?php echo $appointment['doctors_note']; ?></textarea>
</div>
<div class="form-group">
<label for="diagnosis">Diagnosis:</label>
<input type="text" class="form-control" id="diagnosis" name="diagnosis" value="<?php echo $appointment['diagnosis']; ?>">
</div>
<div class="form-group">
<label for="allergies">Allergies:</label>
<textarea class="form-control" id="allergies" name="allergies" rows="3"><?php echo $patient['allergies']; ?></textarea>
</div>
<button type="submit" class="btn btn-primary" name="finishAppointment">Finish Appointment</button>
</form>
</div>
</div>
</div>
</body>
</html>