Hospital management system project in java with source code and project report

Hospital management system project in java using JSP, servlet, Mysql, and eclipse. It uses java as core technology and Mysql as a backend to manage the data records.

It’s following the MVC architecture with the maven tool. A hospital Management System is a web application that helps to manage the activity of a hospital Like Patient management, Doctor management, Manage appointments. Manage the records of patients.

Hospital Management System project ...
Hospital Management System project in java with source code using Jsp, servlet and mysql

Abstract of Hospital Management Project

In this technical world,  humans are trying to convert manual processes into automation in order to save time and money. The hospital Management system is a solution for hospitals there are many employees are working with doctors, nurses, staff members.

This application is a web platform to handle and manage all the activity and maintain and centralize a database about the information that will be easily available with just one click on the web.

Another key part of this application is patient or you can say end-user of the application. So the system provides functionality to manage the end-user as well according to the relation of the work with a patient means Doctors, Staff or Nurse or Admin can manage the patients.

The main objective to develop a Hospital management system in java is to manage the hospital activity online. There will be Three main Actors or Users of the application 1) doctor 2) Admin 3) Receptionist. This project is only for college students who want to complete their Semester projects.

Module and Functionality of Hospital Management

 There are three main actors of the system who going to manage or run the complete application. Let’s discuss it one by one according to the role and readabilities.

working of Admin user in hospital Management

Admin is the main actor who will be responsible for managing Doctors and Receptionists. Below is the task list which will be performed by the admin.

  • Admin can ADD/DELETE/UPDATE a doctor.
  • Admin can VIEW the list of doctors.
  • Admin can ADD/DELETE/UPDATE a receptionist.
  • Admin can VIEW the list of receptionists.
  • Admin can ADD/DELETE/UPDATE a patient.
  • Admin can ADD/DELETE/UPDATE an appointment.

To filter the records on every page you will get the search box on every page or with every table.

Doctor User in HMS

  • A doctor can check the appointment and the patient list.
  • The doctor can VIEW the appointments.
  • The doctor can VIEW the patient list.

Receptionist User in HMS

  • The receptionist can ADD/EDIT/VIEW appointments.
  • The receptionist can ADD/EDIT/VIEW the patient.

Tools And Technologies

Front-End : Jsp, Html, CSS, JS.
Server-side: Servlet.
Back-end: MYSQL.
Server: Tomcat 8.5.

Contact to download source code and configuration

Skype Id: jcodebun
Email: jcodebun@gmail.com
WhatsApp: +91 8827363777
Price: 1500 INR

Hospital Management System in Java with source code

Here is the sample Source code for hospital Management. Below is the source code for the complete source code of the patient module of the library management project in Java.

PatientBean.java

package in.co.hospital.mgt.sys.bean;

import java.util.Date;

public class PatientBean extends BaseBean {

 
 private String firstName;
 /**
  * Last Name of User
  */
 private String lastName;
 /**
  
 
 /**
  * Date of Birth of User
  */
 private Date dob;
 /**
  * MobielNo of User
  */
 private String mobileNo;
 
 /**
  * Gender of User
  */
 private String gender;
 private String age;

 public String getFirstName() {
  return firstName;
 }

 public void setFirstName(String firstName) {
  this.firstName = firstName;
 }

 public String getLastName() {
  return lastName;
 }

 public void setLastName(String lastName) {
  this.lastName = lastName;
 }

 public Date getDob() {
  return dob;
 }

 public void setDob(Date dob) {
  this.dob = dob;
 }

 public String getMobileNo() {
  return mobileNo;
 }

 public void setMobileNo(String mobileNo) {
  this.mobileNo = mobileNo;
 }

 

 public String getGender() {
  return gender;
 }

 public void setGender(String gender) {
  this.gender = gender;
 }

 public String getAge() {
  return age;
 }

 public void setAge(String age) {
  this.age = age;
 }

 public String getBloodGroup() {
  return bloodGroup;
 }

 public void setBloodGroup(String bloodGroup) {
  this.bloodGroup = bloodGroup;
 }

 public String getAddress() {
  return address;
 }

 public void setAddress(String address) {
  this.address = address;
 }

 public String getCity() {
  return city;
 }

 public void setCity(String city) {
  this.city = city;
 }

 public String getCNIC() {
  return CNIC;
 }

 public void setCNIC(String cNIC) {
  CNIC = cNIC;
 }

 public String getMaritialStatus() {
  return maritialStatus;
 }

 public void setMaritialStatus(String maritialStatus) {
  this.maritialStatus = maritialStatus;
 }

 public Date getJoiningDate() {
  return joiningDate;
 }

 public void setJoiningDate(Date joiningDate) {
  this.joiningDate = joiningDate;
 }

 public String getEmailId() {
  return emailId;
 }

 public void setEmailId(String emailId) {
  this.emailId = emailId;
 }

 public String getDoctorName() {
  return doctorName;
 }

 public void setDoctorName(String doctorName) {
  this.doctorName = doctorName;
 }

 public String getDeceased() {
  return deceased;
 }

 public void setDeceased(String deceased) {
  this.deceased = deceased;
 }

 private String bloodGroup;
 private String address;
 private String city;
 private String CNIC;
 private String maritialStatus;
 private Date joiningDate;

 private String emailId;
 private String doctorName;
 private String deceased;
 private long doctorId;
 
 
 
 public long getDoctorId() {
  return doctorId;
 }

 public void setDoctorId(long doctorId) {
  this.doctorId = doctorId;
 }

 @Override
 public String getKey() {
  // TODO Auto-generated method stub
  return null;
 }

 @Override
 public String getValue() {
  // TODO Auto-generated method stub
  return null;
 }

}

Patient List Controller

package in.co.hospital.mgt.sys.controller;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;

import in.co.hospital.mgt.sys.bean.BaseBean;
import in.co.hospital.mgt.sys.bean.PatientBean;
import in.co.hospital.mgt.sys.bean.UserBean;
import in.co.hospital.mgt.sys.exception.ApplicationException;
import in.co.hospital.mgt.sys.model.PatientModel;
import in.co.hospital.mgt.sys.model.UserModel;
import in.co.hospital.mgt.sys.util.DataUtility;
import in.co.hospital.mgt.sys.util.PropertyReader;
import in.co.hospital.mgt.sys.util.ServletUtility;

/**
 * Servlet implementation class PatientListCtl
 */
@WebServlet(name = "PatientListCtl", urlPatterns = { "/ctl/PatientListCtl" })
public class PatientListCtl extends BaseCtl {
 private static final long serialVersionUID = 1L;
       
 private static Logger log = Logger.getLogger(PatientListCtl.class);

 /**
  * Populates bean object from request parameters
  * 
  * @param request
  * @return
  */
 @Override
 protected BaseBean populateBean(HttpServletRequest request) {
  log.debug("PatientListCtl populateBean method start");
  PatientBean bean = new PatientBean();
  bean.setFirstName(DataUtility.getString(request.getParameter("fName")));
  bean.setEmailId(DataUtility.getString(request.getParameter("emailId")));
  log.debug("PatientListCtl populateBean method end");
  return bean;
 }


 /**
  * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
  */
 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  log.debug("PatientListCtl doGet method start");
  List list = null;
  int pageNo = 1;
  int pageSize = DataUtility.getInt(PropertyReader.getValue("page.size"));

  PatientModel model = new PatientModel();
  PatientBean bean = (PatientBean) populateBean(request);
  try {
   HttpSession session=request.getSession();
   UserBean uBean=(UserBean)session.getAttribute("user");
   
   if(uBean.getRoleId()==2) {
    bean.setDoctorId(uBean.getId());
   }
   list = model.search(bean, pageNo, pageSize);
   if (list == null || list.size() == 0) {
    ServletUtility.setErrorMessage("No Record Found", request);
   }
   ServletUtility.setList(list, request);
   ServletUtility.setPageNo(pageNo, request);
   ServletUtility.setPageSize(pageSize, request);
   ServletUtility.forward(getView(), request, response);

  } catch (ApplicationException e) {
   ServletUtility.handleException(e, request, response);
   e.printStackTrace();
   return;
  }
  log.debug("PatientListCtl doGet method end");
  
 }

 /**
  * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
  */
 protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  log.debug("PatientListCtl doPost method start");
  List list = null;

  int pageNo = DataUtility.getInt(request.getParameter("pageNo"));

  int pageSize = DataUtility.getInt(request.getParameter("pageSize"));

  pageNo = (pageNo == 0) ? 1 : pageNo;

  pageSize = (pageSize == 0) ? DataUtility.getInt(PropertyReader.getValue("page.size")) : pageSize;

  PatientBean bean = (PatientBean) populateBean(request);

  PatientModel model = new PatientModel();
  String[] ids = request.getParameterValues("ids");
  String op = DataUtility.getString(request.getParameter("operation"));

  if (OP_SEARCH.equalsIgnoreCase(op) || OP_NEXT.equalsIgnoreCase(op) || OP_PREVIOUS.equalsIgnoreCase(op)) {

   if (OP_SEARCH.equalsIgnoreCase(op)) {

    pageNo = 1;

   } else if (OP_NEXT.equalsIgnoreCase(op)) {

    pageNo++;
   } else if (OP_PREVIOUS.equalsIgnoreCase(op) && pageNo > 1) {

    pageNo--;
   }
  } else if (OP_NEW.equalsIgnoreCase(op)) {
   ServletUtility.redirect(HMSView.PATIENT_CTL, request, response);
   return;
  } else if (OP_DELETE.equalsIgnoreCase(op)) {
   pageNo = 1;
   if (ids != null && ids.length > 0) {
    PatientBean deletebean = new PatientBean();
    for (String id : ids) {
     deletebean.setId(DataUtility.getInt(id));
     try {
      model.delete(deletebean);
     } catch (ApplicationException e) {
      ServletUtility.handleException(e, request, response);
      e.printStackTrace();
      return;
     }
    }
    ServletUtility.setSuccessMessage("Data Deleted Successfully", request);
   } else {
    ServletUtility.setErrorMessage("Select at least one record", request);
   }
  } else if (OP_RESET.equalsIgnoreCase(op)) {
   ServletUtility.redirect(HMSView.PATIENT_LIST_CTL, request, response);
   return;

  }

  try {
   HttpSession session=request.getSession();
   UserBean uBean=(UserBean)session.getAttribute("user");
   
   if(uBean.getRoleId()==2) {
    bean.setDoctorId(uBean.getId());
   }
   list = model.search(bean, pageNo, pageSize);
   if (list == null || list.size() == 0) {
    ServletUtility.setErrorMessage("NO Record Found", request);
   }
   ServletUtility.setList(list, request);
   ServletUtility.setPageNo(pageNo, request);
   ServletUtility.setPageSize(pageSize, request);
   ServletUtility.forward(getView(), request, response);
  } catch (ApplicationException e) {
   ServletUtility.handleException(e, request, response);
   e.printStackTrace();
   return;
  }

  log.debug("PatientListCtl doPost method end");
 }

 @Override
 protected String getView() {
  // TODO Auto-generated method stub
  return HMSView.PATIENT_LIST_VIEW;
 }

}

Patient Model(Database code)

package in.co.hospital.mgt.sys.model;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;

import in.co.hospital.mgt.sys.bean.PatientBean;
import in.co.hospital.mgt.sys.bean.UserBean;
import in.co.hospital.mgt.sys.exception.ApplicationException;
import in.co.hospital.mgt.sys.exception.DatabaseException;
import in.co.hospital.mgt.sys.exception.DuplicateRecordException;
import in.co.hospital.mgt.sys.util.JDBCDataSource;

public class PatientModel {

 private static Logger log = Logger.getLogger(PatientModel.class);

 public Integer nextPK() throws DatabaseException {
  log.debug("Model nextPK Started");
  Connection conn = null;
  int pk = 0;

  try {
   conn = JDBCDataSource.getConnection();
   PreparedStatement pstmt = conn.prepareStatement("SELECT MAX(ID) FROM H_PATIENT");
   ResultSet rs = pstmt.executeQuery();
   while (rs.next()) {
    pk = rs.getInt(1);
   }
   rs.close();

  } catch (Exception e) {
   log.error("Database Exception..", e);
   throw new DatabaseException("Exception : Exception in getting PK");
  } finally {
   JDBCDataSource.closeConnection(conn);
  }
  log.debug("Model nextPK End");
  return pk + 1;
 }

 /**
  * Find User by Login
  * 
  * @param login
  *            : get parameter
  * @return bean
  * @throws DatabaseException
  */

 public PatientBean findByLogin(String login) throws ApplicationException {
  log.debug("Model findByLogin Started");
  StringBuffer sql = new StringBuffer("SELECT * FROM H_PAtient WHERE emailId=?");
  PatientBean bean = null;
  Connection conn = null;
  System.out.println("sql" + sql);

  try {
   conn = JDBCDataSource.getConnection();
   PreparedStatement pstmt = conn.prepareStatement(sql.toString());
   pstmt.setString(1, login);
   ResultSet rs = pstmt.executeQuery();
   while (rs.next()) {
    bean = new PatientBean();
    bean.setId(rs.getLong(1));
    bean.setFirstName(rs.getString(2));
    bean.setLastName(rs.getString(3));
    bean.setDob(rs.getDate(4));
    bean.setMobileNo(rs.getString(5));
    bean.setGender(rs.getString(6));
    bean.setAge(rs.getString(7));
    bean.setBloodGroup(rs.getString(8));
    bean.setAddress(rs.getString(9));
    bean.setCity(rs.getString(10));
    bean.setCNIC(rs.getString(11));
    bean.setMaritialStatus(rs.getString(12));
    bean.setEmailId(rs.getString(13));
    bean.setDoctorName(rs.getString(14));
    bean.setDeceased(rs.getString(15));
    bean.setCreatedBy(rs.getString(16));
    bean.setModifiedBy(rs.getString(17));
    bean.setCreatedDatetime(rs.getTimestamp(18));
    bean.setModifiedDatetime(rs.getTimestamp(19));
    bean.setDoctorId(rs.getLong(20));
   }
   rs.close();
  } catch (Exception e) {
   e.printStackTrace();
   log.error("Database Exception..", e);
   throw new ApplicationException("Exception : Exception in getting User by login");
  } finally {
   JDBCDataSource.closeConnection(conn);
  }
  log.debug("Model findByLogin End");
  return bean;
 }

 public PatientBean findByPk(long id) throws ApplicationException {
  log.debug("Model findByLogin Started");
  StringBuffer sql = new StringBuffer("SELECT * FROM H_PAtient WHERE Id=?");
  PatientBean bean = null;
  Connection conn = null;
  System.out.println("sql" + sql);

  try {
   conn = JDBCDataSource.getConnection();
   PreparedStatement pstmt = conn.prepareStatement(sql.toString());
   pstmt.setLong(1, id);
   ResultSet rs = pstmt.executeQuery();
   while (rs.next()) {
    bean = new PatientBean();
    bean.setId(rs.getLong(1));
    bean.setFirstName(rs.getString(2));
    bean.setLastName(rs.getString(3));
    bean.setDob(rs.getDate(4));
    bean.setMobileNo(rs.getString(5));
    bean.setGender(rs.getString(6));
    bean.setAge(rs.getString(7));
    bean.setBloodGroup(rs.getString(8));
    bean.setAddress(rs.getString(9));
    bean.setCity(rs.getString(10));
    bean.setCNIC(rs.getString(11));
    bean.setMaritialStatus(rs.getString(12));
    bean.setEmailId(rs.getString(13));
    bean.setDoctorName(rs.getString(14));
    bean.setDeceased(rs.getString(15));
    bean.setCreatedBy(rs.getString(16));
    bean.setModifiedBy(rs.getString(17));
    bean.setCreatedDatetime(rs.getTimestamp(18));
    bean.setModifiedDatetime(rs.getTimestamp(19));
    bean.setDoctorId(rs.getLong(20));

   }
   rs.close();
  } catch (Exception e) {
   e.printStackTrace();
   log.error("Database Exception..", e);
   throw new ApplicationException("Exception : Exception in getting User by login");
  } finally {
   JDBCDataSource.closeConnection(conn);
  }
  log.debug("Model findByLogin End");
  return bean;
 }

 public long add(PatientBean bean) throws ApplicationException, DuplicateRecordException {

  Connection conn = null;
  int pk = 0;

  PatientBean existbean = findByLogin(bean.getEmailId());

  if (existbean != null) {
   throw new DuplicateRecordException("Email Id already exists");
  }
  
  UserBean uBean=new UserModel().findByPK(bean.getDoctorId());
  bean.setDoctorName(uBean.getFirstName()+" "+uBean.getLastName());

  try {
   conn = JDBCDataSource.getConnection();
   pk = nextPK();
   // Get auto-generated next primary key
   System.out.println(pk + " in ModelJDBC");
   conn.setAutoCommit(false); // Begin transaction
   PreparedStatement pstmt = conn
     .prepareStatement("INSERT INTO H_Patient VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
   pstmt.setInt(1, pk);
   pstmt.setString(2, bean.getFirstName());
   pstmt.setString(3, bean.getLastName());
   pstmt.setDate(4, new java.sql.Date(bean.getDob().getTime()));
   pstmt.setString(5, bean.getMobileNo());
   pstmt.setString(6, bean.getGender());
   pstmt.setString(7, bean.getAge());
   pstmt.setString(8, bean.getBloodGroup());
   pstmt.setString(9, bean.getAddress());
   pstmt.setString(10, bean.getCity());
   pstmt.setString(11, bean.getCNIC());
   pstmt.setString(12, bean.getMaritialStatus());
   pstmt.setString(13, bean.getEmailId());
   pstmt.setString(14, bean.getDoctorName());
   pstmt.setString(15, bean.getDeceased());
   pstmt.setString(16, bean.getCreatedBy());
   pstmt.setString(17, bean.getModifiedBy());
   pstmt.setTimestamp(18, bean.getCreatedDatetime());
   pstmt.setTimestamp(19, bean.getModifiedDatetime());
   pstmt.setLong(20, bean.getDoctorId());
   pstmt.executeUpdate();
   conn.commit(); // End transaction
   pstmt.close();
  } catch (Exception e) {
   e.printStackTrace();
   try {
    conn.rollback();
   } catch (Exception ex) {
    ex.printStackTrace();
    throw new ApplicationException("Exception : add rollback exception " + ex.getMessage());
   }
   throw new ApplicationException("Exception : Exception in add User");
  } finally {
   JDBCDataSource.closeConnection(conn);
  }

  return pk;
 }

 public void delete(PatientBean bean) throws ApplicationException {

  Connection conn = null;
  try {
   conn = JDBCDataSource.getConnection();
   conn.setAutoCommit(false); // Begin transaction
   PreparedStatement pstmt = conn.prepareStatement("DELETE FROM H_Patient WHERE ID=?");
   pstmt.setLong(1, bean.getId());
   pstmt.executeUpdate();
   conn.commit(); // End transaction
   pstmt.close();

  } catch (Exception e) {

   try {
    conn.rollback();
   } catch (Exception ex) {
    throw new ApplicationException("Exception : Delete rollback exception " + ex.getMessage());
   }
   throw new ApplicationException("Exception : Exception in delete User");
  } finally {
   JDBCDataSource.closeConnection(conn);
  }

 }
 
 public List search(PatientBean bean) throws ApplicationException {
  return search(bean, 0, 0);
 }

 /**
  * Search User with pagination
  * 
  * @return list : List of Users
  * @param bean
  *            : Search Parameters
  * @param pageNo
  *            : Current Page No.
  * @param pageSize
  *            : Size of Page
  * 
  * @throws DatabaseException
  */

 public List search(PatientBean bean, int pageNo, int pageSize) throws ApplicationException {
  log.debug("Model search Started");
  StringBuffer sql = new StringBuffer("SELECT * FROM H_Patient WHERE 1=1");

  if (bean != null) {
   if (bean.getId() > 0) {
    sql.append(" AND id = " + bean.getId());
   }
   if (bean.getId() > 0) {
    sql.append(" AND doctorId = " + bean.getDoctorId());
   }
   if (bean.getFirstName() != null && bean.getFirstName().length() > 0) {
    sql.append(" AND FIRSTNAME like '" + bean.getFirstName() + "%'");
   }
   if (bean.getLastName() != null && bean.getLastName().length() > 0) {
    sql.append(" AND LASTNAME like '" + bean.getLastName() + "%'");
   }
   if (bean.getEmailId() != null && bean.getEmailId().length() > 0) {
    sql.append(" AND emailId like '" + bean.getEmailId() + "%'");
   }
   
   if (bean.getDob() != null && bean.getDob().getDate() > 0) {
    sql.append(" AND DOB = " + bean.getGender());
   }
   if (bean.getMobileNo() != null && bean.getMobileNo().length() > 0) {
    sql.append(" AND MOBILENO = " + bean.getMobileNo());
   }
   
   if (bean.getDoctorName() != null && bean.getDoctorName().length() > 0) {
    sql.append(" AND DoctorName = " + bean.getDoctorName());
   }
   
   

  }

  // if page size is greater than zero then apply pagination
  if (pageSize > 0) {
   // Calculate start record index
   pageNo = (pageNo - 1) * pageSize;

   sql.append(" Limit " + pageNo + ", " + pageSize);
   // sql.append(" limit " + pageNo + "," + pageSize);
  }

  System.out.println("user model search  :"+sql);
  ArrayList list = new ArrayList();
  Connection conn = null;
  try {
   conn = JDBCDataSource.getConnection();
   PreparedStatement pstmt = conn.prepareStatement(sql.toString());
   ResultSet rs = pstmt.executeQuery();
   while (rs.next()) {
    bean = new PatientBean();
    bean.setId(rs.getLong(1));
    bean.setFirstName(rs.getString(2));
    bean.setLastName(rs.getString(3));
    bean.setDob(rs.getDate(4));
    bean.setMobileNo(rs.getString(5));
    bean.setGender(rs.getString(6));
    bean.setAge(rs.getString(7));
    bean.setBloodGroup(rs.getString(8));
    bean.setAddress(rs.getString(9));
    bean.setCity(rs.getString(10));
    bean.setCNIC(rs.getString(11));
    bean.setMaritialStatus(rs.getString(12));
    bean.setEmailId(rs.getString(13));
    bean.setDoctorName(rs.getString(14));
    bean.setDeceased(rs.getString(15));
    bean.setCreatedBy(rs.getString(16));
    bean.setModifiedBy(rs.getString(17));
    bean.setCreatedDatetime(rs.getTimestamp(18));
    bean.setModifiedDatetime(rs.getTimestamp(19));
    bean.setDoctorId(rs.getLong(20));

    list.add(bean);
   }
   rs.close();
  } catch (Exception e) {
   log.error("Database Exception..", e);
   throw new ApplicationException("Exception : Exception in search user");
  } finally {
   JDBCDataSource.closeConnection(conn);
  }

  log.debug("Model search End");
  return list;
 }
 
 public List list() throws ApplicationException {
  return list(0, 0);
 }

 /**
  * Get List of User with pagination
  * 
  * @return list : List of users
  * @param pageNo
  *            : Current Page No.
  * @param pageSize
  *            : Size of Page
  * @throws DatabaseException
  */

 public List list(int pageNo, int pageSize) throws ApplicationException {
  log.debug("Model list Started");
  ArrayList list = new ArrayList();
  StringBuffer sql = new StringBuffer("select * from H_Patient");
  // if page size is greater than zero then apply pagination
  if (pageSize > 0) {
   // Calculate start record index
   pageNo = (pageNo - 1) * pageSize;
   sql.append(" limit " + pageNo + "," + pageSize);
  }

  
  System.out.println("sql in list user :"+sql);
  Connection conn = null;

  try {
   conn = JDBCDataSource.getConnection();
   PreparedStatement pstmt = conn.prepareStatement(sql.toString());
   ResultSet rs = pstmt.executeQuery();
   while (rs.next()) {
    PatientBean bean = new PatientBean();
    bean.setId(rs.getLong(1));
    bean.setFirstName(rs.getString(2));
    bean.setLastName(rs.getString(3));
    bean.setDob(rs.getDate(4));
    bean.setMobileNo(rs.getString(5));
    bean.setGender(rs.getString(6));
    bean.setAge(rs.getString(7));
    bean.setBloodGroup(rs.getString(8));
    bean.setAddress(rs.getString(9));
    bean.setCity(rs.getString(10));
    bean.setCNIC(rs.getString(11));
    bean.setMaritialStatus(rs.getString(12));
    bean.setEmailId(rs.getString(13));
    bean.setDoctorName(rs.getString(14));
    bean.setDeceased(rs.getString(15));
    bean.setCreatedBy(rs.getString(16));
    bean.setModifiedBy(rs.getString(17));
    bean.setCreatedDatetime(rs.getTimestamp(18));
    bean.setModifiedDatetime(rs.getTimestamp(19));
    bean.setDoctorId(rs.getLong(20));
   }
   rs.close();
  } catch (Exception e) {
   log.error("Database Exception..", e);
   throw new ApplicationException("Exception : Exception in getting list of users");
  } finally {
   JDBCDataSource.closeConnection(conn);
  }

  log.debug("Model list End");
  return list;

 }
 
 
 public void update(PatientBean bean) throws ApplicationException, DuplicateRecordException {
  log.debug("Model update Started");
  Connection conn = null;

  PatientBean beanExist = findByLogin(bean.getEmailId());
  // Check if updated LoginId already exist
  if (beanExist != null && !(beanExist.getId() == bean.getId())) {
   throw new DuplicateRecordException("EmailId is already exist");
  }
  
  UserBean uBean=new UserModel().findByPK(bean.getDoctorId());
  bean.setDoctorName(uBean.getFirstName()+" "+uBean.getLastName());

  try {
   conn = JDBCDataSource.getConnection();
   conn.setAutoCommit(false); // Begin transaction
   PreparedStatement pstmt = conn.prepareStatement(
     "UPDATE H_Patient SET FIRSTNAME=?,LASTNAME=?,DOB=?,MOBILENO=?,"
     + "GENDER=?,age=?,BloodGroup=?,Address=?,city=?,CNIC=?,MaritialStatus=?,emailId=?,DoctorName=?,Deceased=?,"
     + "CREATEDBY=?,MODIFIEDBY=?,CREATEDDATETIME=?,MODIFIEDDATETIME=?,doctorId=? WHERE ID=?");
   pstmt.setString(1, bean.getFirstName());
   pstmt.setString(2, bean.getLastName());
   pstmt.setDate(3, new java.sql.Date(bean.getDob().getTime()));
   pstmt.setString(4, bean.getMobileNo());
   pstmt.setString(5, bean.getGender());
   pstmt.setString(6, bean.getAge());
   pstmt.setString(7, bean.getBloodGroup());
   pstmt.setString(8, bean.getAddress());
   pstmt.setString(9, bean.getCity());
   pstmt.setString(10, bean.getCNIC());
   pstmt.setString(11, bean.getMaritialStatus());
   pstmt.setString(12, bean.getEmailId());
   pstmt.setString(13, bean.getDoctorName());
   pstmt.setString(14, bean.getDeceased());
   pstmt.setString(15, bean.getCreatedBy());
   pstmt.setString(16, bean.getModifiedBy());
   pstmt.setTimestamp(17, bean.getCreatedDatetime());
   pstmt.setTimestamp(18, bean.getModifiedDatetime());
   pstmt.setLong(19, bean.getDoctorId());
   pstmt.setLong(20, bean.getId());
   
   pstmt.executeUpdate();
   conn.commit(); // End transaction
   pstmt.close();
  } catch (Exception e) {
   e.printStackTrace();
   log.error("Database Exception..", e);
   try {
    conn.rollback();
   } catch (Exception ex) {
    throw new ApplicationException("Exception : Delete rollback exception " + ex.getMessage());
   }
   throw new ApplicationException("Exception in updating User ");
  } finally {
   JDBCDataSource.closeConnection(conn);
  }
  log.debug("Model update End");
 }

}

Note: If you need the source code you can contact us. We will provide complete source code and all the required things like Database. We have created a STEP by STEP configuration tutorial to help you in the configuration process.

Step by Step Tutorial to configure Java project

Viva Questions and answers for java project

Check new projects in java

If you find any kind of difficulties during the configuration. We will also provide configuration forms remotely. You can contact me at jcodebun@gmail.com

1 thought on “Hospital management system project in java with source code and project report”

  1. greetings to you all
    Thank you for providing educational materials that serve programmers
    Please, I want the source code for an educational purpose for students in the field of information technology
    Hospital management system project in java with source code

Leave a Comment

Your email address will not be published.