Hospital Management System Project Structure
Hospital Management System Project Structure
Below is the complete code for the Hospital Management System, including all the necessary
classes such as Patient, Doctor, Appointment, and the client-side implementation.
Project Structure:
HospitalManagementSystem
├── src
│ └── com
│ └── acc
│ ├── model
│ │ ├── Patient.java
│ │ ├── Doctor.java
│ │ └── Appointment.java
│ ├── deo
│ ├── service
│ ├── util
1. Patient.java
package com.acc.model;
this.id = id;
this.name = name;
this.age = age;
this.disease = disease;
return id;
return name;
return age;
return disease;
@Override
return "Patient ID: " + id + ", Name: " + name + ", Age: " + age + ", Disease: " + disease;
2. Doctor.java
package com.acc.model;
this.id = id;
this.name = name;
this.specialization = specialization;
return id;
return name;
return specialization;
@Override
return "Doctor ID: " + id + ", Name: " + name + ", Specialization: " + specialization;
3. Appointment.java
package com.acc.model;
import java.util.Date;
this.id = id;
this.patient = patient;
this.doctor = doctor;
this.appointmentDate = appointmentDate;
return id;
return patient;
return doctor;
return appointmentDate;
}
@Override
return "Appointment ID: " + id + ", Patient: " + patient.getName() + ", Doctor: " +
doctor.getName() + ", Date: " + appointmentDate;
package com.acc.service;
import com.acc.model.Patient;
import com.acc.model.Doctor;
import com.acc.model.Appointment;
import java.util.List;
List<Patient> findAllPatients();
List<Doctor> findAllDoctors();
package com.acc.deo;
import com.acc.model.Patient;
import com.acc.model.Doctor;
import com.acc.model.Appointment;
import com.acc.util.DBConnection;
import com.acc.service.Operable;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;
@Override
ResultSet rs = stmt.executeQuery(query)) {
while (rs.next()) {
} catch (SQLException e) {
e.printStackTrace();
return patients;
@Override
ResultSet rs = stmt.executeQuery(query)) {
while (rs.next()) {
} catch (SQLException e) {
e.printStackTrace();
return doctors;
@Override
String query = "INSERT INTO patient(id, name, age, disease) VALUES(?, ?, ?, ?)";
stmt.setInt(1, patient.getId());
stmt.setString(2, patient.getName());
stmt.setInt(3, patient.getAge());
stmt.setString(4, patient.getDisease());
stmt.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
}
}
@Override
stmt.setInt(1, doctor.getId());
stmt.setString(2, doctor.getName());
stmt.setString(3, doctor.getSpecialization());
stmt.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
@Override
stmt.setInt(1, appointment.getId());
stmt.setInt(2, appointment.getPatient().getId());
stmt.setInt(3, appointment.getDoctor().getId());
stmt.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
@Override
stmt.setInt(1, id);
stmt.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
@Override
stmt.setInt(1, id);
stmt.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
}
}
@Override
stmt.setInt(1, age);
stmt.setInt(2, id);
stmt.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
package com.acc.util;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
try {
Class.forName("com.mysql.cj.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/hospital_management",
"root", "password"); // replace with your database credentials
e.printStackTrace();
return con;
package com.acc;
import com.acc.model.Patient;
import com.acc.model.Doctor;
import com.acc.model.Appointment;
import com.acc.deo.OperableImpl;
import java.util.Scanner;
while (true) {
System.out.println("9. Exit");
switch (choice) {
case 1:
break;
case 2:
case 3:
operable.addAppointment(appointment);
break;
case 4:
operable.updatePatientAge(updateId, newAge);
break;
case 5:
operable.deletePatient(deletePatientId);
break;
case 6:
operable.deleteDoctor(deleteDoctorId);
break;
case 7:
System.out.println("All Patients:");
operable.findAllPatients().forEach(System.out::println);
break;
case 8:
System.out.println("All Doctors:");
operable.findAllDoctors().forEach(System.out::println);
break;
case 9:
System.out.println("Exiting...");
sc.close();
return;
default:
Database Setup
name VARCHAR(100),
age INT,
disease VARCHAR(100)
);
2. Doctors Table:
name VARCHAR(100),
specialization VARCHAR(100)
);
3. Appointments Table:
patient_id INT,
doctor_id INT,
appointment_date DATE,
);
Final Remarks
With this setup, the project is ready to run, and you can interact with the program through the
console to manage hospital-related data. You can add patients, doctors, and appointments, update
and delete records, and view all patients and doctors.
Make sure your database is set up correctly, and the DBConnection.java class contains the proper
credentials (e.g., database name, username, and password).