Source Code
Source Code
Admin Module
Doctor Module
Patient Module
Admin Module:
Doctor Module
Patient Module
index.php
dashboard.php
top_menus.php
doctor.php
patient.php
appointment.php
User.php: A class contains users methods.
Doctor.php: A class contains methods related to doctor.
Patient.php: A class contains methods related to patient.
Appointment.php: A class contains methods related to
appointment.
<div class="col-md-6">
</div>
<?php } ?>
<span class="input-group-addon"><i
class="glyphicon glyphicon-user"></i></span>
</div>
<span class="input-group-addon"><i
class="glyphicon glyphicon-lock"></i></span>
</div>
<label class="radio-inline">
</label>
<label class="radio-inline">
<input type="radio" name="loginType"
value="doctor">Doctor
</label>
<label class="radio-inline">
</label>
</div>
</div>
</form>
</div>
</div>
</div>
$user->email = $_POST["email"];
$user->password = $_POST["password"];
$user->loginType = $_POST["loginType"];
if($user->login()) {
header("Location: dashboard.php");
} else {
} else {
$loginTable = '';
if($this->loginType == 'admin') {
$loginTable = "hms_users";
$loginTable = "hms_doctor";
$loginTable = "hms_patients";
$sqlQuery = "
$stmt = $this->conn->prepare($sqlQuery);
$password = md5($this->password);
$stmt->execute();
$result = $stmt->get_result();
$user = $result->fetch_assoc();
$_SESSION["userid"] = $user['id'];
$_SESSION["role"] = $this->loginType;
$_SESSION["name"] = $user['email'];
return 1;
} else {
return 0;
} else {
return 0;
<div class="panel-heading">
<div class="row">
<div class="col-md-10">
<h3 class="panel-title"></h3>
</div>
</div>
</div>
</div>
<thead>
<tr>
<th>#</th>
<th>Name</th>
<th>Address</th>
<th>Mobile</th>
<th>Fee</th>
<th>Specialization</th>
<th></th>
<th></th>
<th></th>
</tr>
</thead>
</table>
</div>
"lengthChange": false,
"processing":true,
"serverSide":true,
"bFilter": false,
'serverMethod': 'post',
"order":[],
"ajax":{
url:"doctor_action.php",
type:"POST",
data:{action:'listDoctors'},
dataType:"json"
},
"columnDefs":[
"targets":[0, 6, 7, 8],
"orderable":false,
},
],
"pageLength": 10
});
$sqlWhere = '';
if($_SESSION["role"] == 'doctor') {
if(!empty($_POST["search"]["value"])){
if(!empty($_POST["order"])){
} else {
if($_POST["length"] != -1){
$stmt = $this->conn->prepare($sqlQuery);
$stmt->execute();
$result = $stmt->get_result();
$stmtTotal->execute();
$allResult = $stmtTotal->get_result();
$allRecords = $allResult->num_rows;
$displayRecords = $result->num_rows;
$records = array();
$rows = array();
$rows[] = $doctor['id'];
$rows[] = ucfirst($doctor['name']);
$rows[] = $doctor['address'];
$rows[] = $doctor['mobile'];
$rows[] = $doctor['fee'];
$rows[] = $doctor['specialization'];
$records[] = $rows;
}
$output = array(
);
echo json_encode($output);
if($this->name) {
$stmt = $this->conn->prepare("
VALUES(?,?,?,?,?,?,?)");
$this->name = htmlspecialchars(strip_tags($this->name));
$this->email = htmlspecialchars(strip_tags($this->email));
$this->mobile = htmlspecialchars(strip_tags($this->mobile));
$this->address = htmlspecialchars(strip_tags($this->address));
$this->fee = htmlspecialchars(strip_tags($this->fee));
$this->specialization = htmlspecialchars(strip_tags($this-
>specialization));
$this->password = md5($this->password);
return true;
if($this->id) {
$passwordField = '';
if($this->password){
$stmt = $this->conn->prepare("
UPDATE ".$this->doctorTable."
WHERE id = ?");
$this->id = htmlspecialchars(strip_tags($this->id));
$this->name = htmlspecialchars(strip_tags($this->name));
$this->email = htmlspecialchars(strip_tags($this->email));
$this->mobile = htmlspecialchars(strip_tags($this->mobile));
$this->address = htmlspecialchars(strip_tags($this->address));
$this->fee = htmlspecialchars(strip_tags($this->fee));
$this->specialization = htmlspecialchars(strip_tags($this-
>specialization));
return true;
<div class="panel-heading">
<div class="row">
<div class="col-md-10">
<h3 class="panel-title"></h3>
</div>
</div>
<?php } ?>
</div>
</div>
<thead>
<tr>
<th>#</th>
<th>Name</th>
<th>Gender</th>
<th>Age</th>
<th>Email</th>
<th>Mobile</th>
<th>Address</th>
<th>Medical History</th>
<th></th>
<th></th>
<th></th>
</tr>
</thead>
</table>
</div>
"lengthChange": false,
"processing":true,
"serverSide":true,
"bFilter": false,
'serverMethod': 'post',
"order":[],
"ajax":{
url:"patient_action.php",
type:"POST",
data:{action:'listPatient'},
dataType:"json"
},
"columnDefs":[
"targets":[0, 8, 9, 10],
"orderable":false,
},
],
"pageLength": 10
});
$patient->listPatients();
$sqlWhere = '';
if($_SESSION["role"] == 'patient') {
if(!empty($_POST["search"]["value"])){
if(!empty($_POST["order"])){
} else {
$sqlQuery .= 'ORDER BY id DESC ';
if($_POST["length"] != -1){
$stmt = $this->conn->prepare($sqlQuery);
$stmt->execute();
$result = $stmt->get_result();
$stmtTotal->execute();
$allResult = $stmtTotal->get_result();
$allRecords = $allResult->num_rows;
$displayRecords = $result->num_rows;
$records = array();
$rows = array();
$rows[] = $patient['id'];
$rows[] = ucfirst($patient['name']);
$rows[] = $patient['gender'];
$rows[] = $patient['age'];
$rows[] = $patient['email'];
$rows[] = $patient['mobile'];
$rows[] = $patient['address'];
$rows[] = $patient['medical_history'];
if($_SESSION["role"] != 'patient') {
} else {
$rows[] = '';
$records[] = $rows;
$output = array(
);
echo json_encode($output);
We will add the new patient record with method insert() from
class Patient.php
public function insert(){
if($this->name) {
$stmt = $this->conn->prepare("
VALUES(?,?,?,?,?,?,?,?)");
$this->name = htmlspecialchars(strip_tags($this->name));
$this->email = htmlspecialchars(strip_tags($this->email));
$this->gender = htmlspecialchars(strip_tags($this->gender));
$this->mobile = htmlspecialchars(strip_tags($this->mobile));
$this->address = htmlspecialchars(strip_tags($this->address));
$this->age = htmlspecialchars(strip_tags($this->age));
$this->medical_history = htmlspecialchars(strip_tags($this-
>medical_history));
$this->password = md5($this->password);
if($stmt->execute()){
return true;
if($this->id) {
$passwordField = '';
if($this->password){
$stmt = $this->conn->prepare("
UPDATE ".$this->patientTable."
SET name= ?, email = ?, gender = ?, mobile = ?, address = ?, age
= ?, medical_history = ? $passwordField
WHERE id = ?");
$this->id = htmlspecialchars(strip_tags($this->id));
$this->name = htmlspecialchars(strip_tags($this->name));
$this->email = htmlspecialchars(strip_tags($this->email));
$this->gender = htmlspecialchars(strip_tags($this->gender));
$this->mobile = htmlspecialchars(strip_tags($this->mobile));
$this->address = htmlspecialchars(strip_tags($this->address));
$this->age = htmlspecialchars(strip_tags($this->age));
$this->medical_history = htmlspecialchars(strip_tags($this-
>medical_history));
if($stmt->execute()){
return true;
<div class="panel-heading">
<div class="row">
<div class="col-md-10">
<h3 class="panel-title"></h3>
</div>
</div>
<?php } ?>
</div>
</div>
<thead>
<tr>
<th>#</th>
<th>Patient</th>
<th>Doctor</th>
<th>Specialization</th>
<th>Fee</th>
<th>Apointment Time</th>
<th>Apointment Date</th>
<th>Status</th>
<th></th>
<th></th>
<th></th>
</tr>
</thead>
</table>
</div>
"lengthChange": false,
"processing":true,
"serverSide":true,
"bFilter": false,
'serverMethod': 'post',
"order":[],
"ajax":{
url:"appointment_action.php",
type:"POST",
data:{action:'listAppointment'},
dataType:"json"
},
"columnDefs":[
"targets":[0, 8, 9, 10],
"orderable":false,
},
],
"pageLength": 10
});
$appointment->listAppointment();
if($_SESSION["role"] == 'patient') {
FROM ".$this->appointmentTable." a
if(!empty($_POST["search"]["value"])){
if(!empty($_POST["order"])){
} else {
}
if($_POST["length"] != -1){
$stmt = $this->conn->prepare($sqlQuery);
$stmt->execute();
$result = $stmt->get_result();
$stmtTotal->execute();
$allResult = $stmtTotal->get_result();
$allRecords = $allResult->num_rows;
$displayRecords = $result->num_rows;
$records = array();
$rows = array();
$rows[] = $appointment['id'];
$rows[] = ucfirst($appointment['patient_name']);
$rows[] = ucfirst($appointment['doctor_name']);
$rows[] = $appointment['specialization'];
$rows[] = $appointment['consultancy_fee'];
$rows[] = $appointment['appointment_time'];
$rows[] = $appointment['appointment_date'];
$rows[] = $appointment['status'];
} else {
$rows[] = '';
$rows[] = '';
$rows[] = '';
$records[] = $rows;
$output = array(
);
echo json_encode($output);
$stmt = $this->conn->prepare("
VALUES(?,?,?,?,?,?,?)");
$this->doctor_id = htmlspecialchars(strip_tags($this->doctor_id));
$this->specialization_id = htmlspecialchars(strip_tags($this-
>specialization_id));
$this->fee = htmlspecialchars(strip_tags($this->fee));
$this->appointment_date = htmlspecialchars(strip_tags($this-
>appointment_date));
$this->appointment_time = htmlspecialchars(strip_tags($this-
>appointment_time));
$this->status = htmlspecialchars(strip_tags($this->status));
if($stmt->execute()){
return true;
if($this->id) {
$stmt = $this->conn->prepare("
UPDATE ".$this->appointmentTable."
WHERE id = ?");
$this->id = htmlspecialchars(strip_tags($this->id));
$this->doctor_id = htmlspecialchars(strip_tags($this->doctor_id));
$this->specialization_id = htmlspecialchars(strip_tags($this-
>specialization_id));
$this->fee = htmlspecialchars(strip_tags($this->fee));
$this->appointment_date = htmlspecialchars(strip_tags($this-
>appointment_date));
$this->appointment_time = htmlspecialchars(strip_tags($this-
>appointment_time));
$this->status = htmlspecialchars(strip_tags($this->status));
if($stmt->execute()){
return true;
Step6: Conclusion
In this tutorial, we have implement Hospital management system
with Ajax, PHP and MySQL. We have covered Admin, Doctors,
Patients and Appointment section. You can download the project
and can customize and enhance according to your requirement.