Usha Mittal Institute of Technology: Blood Bank Management System
Usha Mittal Institute of Technology: Blood Bank Management System
Submitted by:
6 - Saanvi Bijgarnikar
7 - Dipali Budhwat
8 - Gargi Chaudhari
9 - Janhavi Chavan
10 - Amoli Dhuri
Guided by:
Mrs. Iffat Kazi
1
INDEX
INTRODUCTION ........................................................................................................... 3
PROBLEM STATEMENT ................................................................................................4
OBJECTIVE ................................................................................................................... 5
ADVANTAGE ..................................................................................................................5
ER- DIAGRAM ............................................................................................................... 6
TABLES ..........................................................................................................................7
QUERIES ........................................................................................................................8
2
INTRODUCTION
3
PROBLEM STATEMENT
Blood banks play a crucial role in the healthcare system, but they often face
challenges in managing blood inventories, donor information, and patient
requests. Manual systems for tracking donations, requests, and stock levels can
lead to errors, inefficiencies, and delays.
Blood shortages, expired blood products, and mismatched blood types can also
occur due to poor management. Therefore, there is a need for a comprehensive
system that can address these issues by automating and organizing the blood
bank’s operations.
4
OBJECTIVE
ADVANTAGE
➢ Improved Patient Care: Ensures timely access to safe blood for patients,
particularly in emergencies, thereby improving overall healthcare outcomes.
5
ER- DIAGRAM
6
TABLES
1. DONORS
2. BLOOD BANK
7
3. BLOOD INVENTORY
4. PATIENTS
8
5. BLOOD REQUESTS
6. DONATIONS
9
7. TRANSACTIONS
10
QUERIES
2. Get the total quantity of a specific blood group available in a blood bank
Query :
SELECT SUM(quantity) AS total_quantity FROM Blood_Inventory WHERE blood_group
= 'A+' AND blood_bank_id = 1;
11
5. Get all blood requests that are still pending.
Query :
SELECT * FROM Blood_Requests WHERE status = 'Pending';
12
8. Get the total number of blood requests made by a specific patient.
Query :
SELECT COUNT(*) AS total_requests FROM Blood_Requests WHERE patient_id = 402;
10. Find the total number of blood requests made in each blood group
Query :
SELECT blood_group, COUNT(*) AS total_requests FROM Blood_Requests GROUP BY
blood_group;
11. Get the total quantity of each blood group requested by patients
Query :
SELECT blood_group, SUM(required_quantity) AS total_requested FROM
Blood_Requests GROUP BY blood_group;
13
12. Find blood that is about to expire in the next 7 days
Query :
SELECT * FROM Blood_Inventory WHERE expiration_date <= DATE_ADD(CURDATE(),
INTERVAL 7 DAY);
14
15. Get the contact details of the manager of a specific blood bank
Query :
SELECT manager_name, contact FROM Blood_Banks WHERE blood_bank_id = 2;
16. Find all patients with blood group O- who have requested blood
Query :
SELECT * FROM Patients p JOIN Blood_Requests br ON p.patient_id =
br.patient_id WHERE p.blood_group = 'O-' AND br.blood_group = 'O-';
15
SELECT donor_id, SUM(quantity) AS total_quantity FROM Donations GROUP BY
donor_id;
19. Get a summary of total blood donated in each month of the current year
Query :
SELECT MONTH(donation_date) AS month, SUM(quantity) AS total_quantity FROM
Donations WHERE YEAR(donation_date) = YEAR(CURDATE()) GROUP BY month;
16
21. Get All Blood Requests with Corresponding Patient Details
Query :
SELECT BR.request_id, P.name AS patient_name, BR.blood_group,
BR.required_quantity, BR.status, BR.request_date
FROM Blood_Requests BR
INNER JOIN Patients P
ON BR.patient_id = P.patient_id;
22. List All Donors with the Blood Bank They Last Donated To, Including Donors
Who Haven't Donated Yet
Query :
SELECT Donors.name AS donor_name, Donations.donation_date, Blood_Banks.name
AS blood_bank_name
FROM Donors
LEFT JOIN Donations ON Donors.donor_id = Donations.donor_id
LEFT JOIN Blood_Banks ON Donations.blood_bank_id = Blood_Banks.blood_bank_id;
23. Show All Blood Banks with Details of Donors Who Have Donated, Including
Blood Banks with No Donations
Query :
17
SELECT Blood_Banks.name AS blood_bank_name, Donors.name AS donor_name,
Donations.donation_date
FROM Donations
RIGHT JOIN Blood_Banks ON Donations.blood_bank_id = Blood_Banks.blood_bank_id
LEFT JOIN Donors ON Donations.donor_id = Donors.donor_id;
24. Find compatible donors for each patient in the Patients table
Query :
SELECT p.patient_id, p.name AS patient_name, p.blood_group AS
patient_blood_group, d.donor_id, d.name AS donor_name, d.blood_group AS
donor_blood_group
FROM Patients p
JOIN Donors d ON (
(p.blood_group = 'O-' AND d.blood_group = 'O-') OR
(p.blood_group = 'O+' AND d.blood_group IN ('O-', 'O+')) OR
(p.blood_group = 'A-' AND d.blood_group IN ('O-', 'A-')) OR
(p.blood_group = 'A+' AND d.blood_group IN ('O-', 'O+', 'A-', 'A+')) OR
(p.blood_group = 'B-' AND d.blood_group IN ('O-', 'B-')) OR
(p.blood_group = 'B+' AND d.blood_group IN ('O-', 'O+', 'B-', 'B+')) OR
(p.blood_group = 'AB-' AND d.blood_group IN ('O-', 'A-', 'B-', 'AB-')) OR
(p.blood_group = 'AB+' AND d.blood_group IN ('O-', 'O+', 'A-', 'A+',
'B-', 'B+', 'AB-', 'AB+'))
)
ORDER BY p.patient_id;
18
19
25. Retrieve the Details of Blood Requests That Are Still Pending
Query :
SELECT Blood_Requests.request_id, Patients.name AS patient_name,
Blood_Requests.blood_group, Blood_Requests.required_quantity,
Blood_Requests.request_date
FROM Blood_Requests
JOIN Patients ON Blood_Requests.patient_id = Patients.patient_id
WHERE Blood_Requests.status = 'Pending';
26. Display the List of Blood Banks and the Total Quantity of Blood They Have
Available
Query :
20
SELECT Blood_Banks.name AS blood_bank_name, SUM(Blood_Inventory.quantity) AS
total_quantity
FROM Blood_Banks
JOIN Blood_Inventory ON Blood_Banks.blood_bank_id =
Blood_Inventory.blood_bank_id
GROUP BY Blood_Banks.blood_bank_id;
28. Find Blood Banks in Cities Where a Specific Blood Group is Stored
Query :
SELECT name, location FROM Blood_Banks WHERE blood_bank_id
IN (SELECT blood_bank_id FROM Blood_Inventory WHERE blood_group = 'O+');
21
29. Find Patients Who Have the Same Blood Group as a Donor
Query :
SELECT name, blood_group FROM Patients WHERE blood_group
IN (SELECT blood_group FROM Donors);
30. Find Most Recent Donors and Their Last Donation Date
Query :
SELECT donor_id,name,blood_group, last_donation_date
FROM Donors
ORDER BY last_donation_date DESC;
22
31.List all donors and patients in a combined list with their name, blood group,
and contact information.
Query:
SELECT name, blood_group, contact FROM Donors
UNION
SELECT name, blood_group, contact FROM Patients;
32.List all pending blood requests for patients with blood group 'A-':
Query:
SELECT Patients.name, Blood_Requests.required_quantity,
Blood_Requests.request_date
FROM Blood_Requests
JOIN Patients ON Blood_Requests.patient_id = Patients.patient_id
WHERE Blood_Requests.status = 'Pending' AND Blood_Requests.blood_group =
'A-';
23
33.Query to Get Donors or Patients Who Share the Same Blood Group
Query:
SELECT name, blood_group
FROM Donors
WHERE blood_group IN (SELECT blood_group FROM Patients);
34. Identify blood banks with less than 6 units of 'A+' blood in stock:
Query:
SELECT Blood_Banks.name, Blood_Inventory.quantity
FROM Blood_Inventory
JOIN Blood_Banks ON Blood_Inventory.blood_bank_id = Blood_Banks.blood_bank_id
WHERE Blood_Inventory.blood_group = 'A+' AND Blood_Inventory.quantity < 6;
24
36. Retrieve all transactions that occurred in the month of September 2024:
Query:
SELECT Transactions.transaction_id, Blood_Banks.name AS blood_bank,
Blood_Requests.request_id, Transactions.quantity_transferred
FROM Transactions
JOIN Blood_Banks ON Transactions.blood_bank_id = Blood_Banks.blood_bank_id
JOIN Blood_Requests ON Transactions.request_id = Blood_Requests.request_id
WHERE MONTH(Transactions.transaction_date) = 9 AND
YEAR(Transactions.transaction_date) = 2024;
37. Find the blood banks that has fulfilled the most blood requests:
Query:
SELECT Blood_Banks.name, COUNT(Transactions.transaction_id) AS
fulfilled_requests
FROM Transactions
JOIN Blood_Banks ON Transactions.blood_bank_id = Blood_Banks.blood_bank_id
GROUP BY Blood_Banks.name
ORDER BY fulfilled_requests DESC;
25
CREATE TABLE Inventory_Update_log (
log_id INT AUTO_INCREMENT PRIMARY KEY,
blood_inventory_id INT,
old_quantity DECIMAL(5, 2),
new_quantity DECIMAL(5, 2)
);
DELIMITER $$
CREATE TRIGGER after_blood_inventory_update
AFTER UPDATE ON Blood_Inventory
FOR EACH ROW
BEGIN
INSERT INTO Inventory_Update_Log (blood_inventory_id, old_quantity,
new_quantity)
VALUES (OLD.blood_inventory_id, OLD.quantity, NEW.quantity);
END $$
DELIMITER ;
update blood_inventory
set quantity=10
where blood_inventory_id=306;
select * from Inventory_Update_log;
39. List all patients who have requested more than 3 units of blood:
Query:
SELECT Patients.name, Blood_Requests.required_quantity
FROM Blood_Requests
JOIN Patients ON Blood_Requests.patient_id = Patients.patient_id
WHERE Blood_Requests.required_quantity > 3;
26
JOIN Donors ON Donations.donor_id = Donors.donor_id
GROUP BY blood_group
ORDER BY donation_count DESC;
27