Rest API for Hospital Management in Spring boot, JPA, MYSQL, Postman

Rest API for Hospital Management in Spring boot, JPA, MYSQL, and Postman.

In this article, we will build the backend part of the Hospital Management System. As we know to communicate between frontend and backend, we need REST API and to develop REST API, we are using Spring Boot framework.

So, in this article, we will be creating API to perform operations on Hospital Management System. Those APIs would be for user management, appointment management, and doctor and patient management.

How to get Started?

To get started with creating the backend part we will be using Spring Boot which is a popular framework to create REST API with minimal configuration. We will use the following layers in the application:

  • Repository Layer: It is a Data Access Layer where we will use the JPARepository interface to connect with the database.
  • Service Layer: This layer will interact with the above layer to perform business logic.
  • Controller Layer: This is the layer where the request will come from the client and the controller will process it and generate a response with HTTP Status.
  • Security Layer: To implement Security in the application, Spring Security is used along with JWT.
  • Exception Layer: Any exception thrown would be handled at this layer.

Tools & Technologies

  • Java 8
  • Eclipse/STS/IntelliJ IDEA
  • Postman
  • MYSQL
  • JSON

Abstract of Hospital Management System

The main objective of the Hospital Management System is to automate the healthcare system. It includes the registration of patients, generating bills, assigning doctors to patients along with allowing room. It consists of four main users i.e the Admin, Receptionist, Patient, Doctor and the last one is Receptionist.

Admin is the main user who will manage the whole application. It can manage Doctors, Receptionists, and Rooms. Doctors can view the list of patients and the Appointment list and add a summary.

Another role in this application is that of a Receptionist who will add patients and assign doctors. Also, it can allow room and generate Bills. Patients can view their appointment details, doctor details, and so on.

REST API of Hospital Management in Spring Boot

Following are the created APIs according to the user roles.

Common APIs:

  • Login & generate JWT Token
  • Post Request for Patient Signup

Rest APIs after login as an Admin User

  • POST request to add a new doctor.
  • GET request to find the list of doctors.
  • PUT request to update a doctor’s information by id.
  • DELETE request to remove doctor information by id.
  • GET request to find doctors by first_name and email_id.
  • POST request to add a new receptionist.
  • GET request to find the list of receptionists.
  • PUT request to update receptionist information.
  • DELETE request to remove receptionist information by id.
  • GET request to find receptionist by first_name and email_Id.
  • POST request to add a new room.
  • GET request to find the list of rooms.
  • PUT request to update room information.
  • DELETE request to remove room information by id.
  • GET request to find room by room number.

Rest APIs after login as a Doctor User

  • GET request to find the list of patients.
  • GET request to find patient by first_name and email_Id.
  • GET request to find the list of appointments.
  • GET request to find the appointment by patient name.
  • POST request to add summary/treatment.
  • GET request to find the list of summary details.
  • PUT request to update the summary by id.
  • DELETE request to remove the summary by id.

Rest APIs after login as a Receptionist User

  • GET request to find the list of doctors.
  • GET request to find the list of doctors by first_name and email_Id.
  • POST request to add patients and assign doctors.
  • GET request to find the list of patients.
  • PUT request to update patient information by id.
  • DELETE request to remove patient information by id.
  • GET request to find the list of patients by id.
  • POST request to add an appointment.
  • PUT request to update appointment information by id.
  • DELETE request to remove appointment detail by id.
  • GET request to find the list of appointments.
  • GET request to find the list of appointments by patient name.
  • POST request to allot rooms and doctors to patients.
  • PUT request to update allot room information by id.
  • DELETE request to remove alloted room detail by id.
  • GET request to find the list of rooms allotted.
  • POST request to generate the bill.
  • GET request to find the list of bills.
  • PUT request to update the bill detail by id.

After login as a Patient User

  • GET request to find their bills.
  • GET request to find the list of doctors.
  • GET request to find the appointments list of users.

It uses JWT and Spring security authentication, to access the API. So before accessing any API, you have to log in and generate the auth token as a key.

API Validations

When creating any API, it is important for a developer to create Validation. So, we have performed the following validation in this project.

  • Login Id(Email Id) should be unique.
  • All fields are mandatory.
  • API should not allow duplicate doctors, patients, or receptionists.
  • The phone number should be an integer value. It should not contain text-type of data. It should have a valid format or pattern.
  • Bill Amount should be valid and should not contain text or null values.
  • A proper Validation message is shown instead of ‘Internal Server Error’.

Thus, in this way, we can develop the backend part of the Hospital Management System using REST API, Spring Boot, Spring Security, and JWT.

Leave a Comment

Your email address will not be published. Required fields are marked *