How to develop Projects(BDMS) Using PHP and Mysql Part 12

Rashmi Mishra
0

How to develop Projects(BDMS)

 Using PHP and Mysql 

Part 12


Module 4: Blood Inventory Management

🎯 Purpose:
Track and manage the blood stock available in blood banks, ensuring accurate information for both hospitals and donors.

🔧 Functionalities to Implement:

  • 🗂 Add new blood stock (blood group, quantity, collection date, expiry date).
  • Update stock quantities after donations or blood request fulfillment.
  • 🔍 View available stock filtered by blood group and location.
  • ⚠️ Low stock alerts to notify admins or donors.
  • 🧾 Delete expired or used stock.

📁 Suggested File/Folder Structure:

/blood_inventory/

├── add_stock.php           # Add new blood stock

├── update_stock.php        # Update stock quantity or details

├── view_inventory.php      # Display available blood stock

├── delete_stock.php        # Remove expired or used stock

🧮 Suggested Database Table:

CREATE TABLE blood_inventory (

    id INT AUTO_INCREMENT PRIMARY KEY,

    blood_group VARCHAR(10) NOT NULL,

    quantity INT NOT NULL,

    collected_on DATE NOT NULL,

    expiry_date DATE NOT NULL,

    location VARCHAR(255) NOT NULL,

    status ENUM('Available', 'Used', 'Expired') DEFAULT 'Available',

    updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP

);


✅ Module 5: Donor Appointment Scheduling

🎯 Purpose:
Allow donors to book appointments for blood donation at specific blood banks or donation camps.

🔧 Functionalities to Implement:

  • 📅 Book an appointment (date, time, location).
  • 📝 View scheduled appointments.
  • Cancel appointments.
  • 📨 Admin approval or reschedule suggestions.

📁 Suggested File/Folder Structure:

/appointments/

├── book_appointment.php     # Form to book a donation appointment

├── my_appointments.php      # Donor's appointment history

├── manage_appointments.php  # Admin panel to approve/reschedule

🧮 Suggested Database Table:

CREATE TABLE appointments (

    id INT AUTO_INCREMENT PRIMARY KEY,

    donor_id INT NOT NULL,

    appointment_date DATE NOT NULL,

    appointment_time TIME NOT NULL,

    location VARCHAR(255) NOT NULL,

    status ENUM('Pending', 'Confirmed', 'Cancelled') DEFAULT 'Pending',

    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,

    FOREIGN KEY (donor_id) REFERENCES users(id)

);


✅ Module 6: Notification and Alerts System

🎯 Purpose:
Keep users informed about blood request status, appointment reminders, and system alerts via email, SMS, or system messages.

🔧 Functionalities to Implement:

  • 🔔 New request alerts for suitable donors.
  • 📢 Status change notifications for requesters.
  • Appointment reminders for donors.
  • 📬 Low stock warnings for admins.

📁 Suggested File/Folder Structure:

/notifications/

├── send_email.php           # Email sender logic

├── send_sms.php             # SMS sender logic (if applicable)

├── notification_list.php    # Admin view of all notifications

├── user_notifications.php   # User view of received alerts

🧮 Suggested Database Table:

CREATE TABLE notifications (

    id INT AUTO_INCREMENT PRIMARY KEY,

    user_id INT NOT NULL,

    message TEXT NOT NULL,

    type ENUM('Request', 'Appointment', 'Stock', 'General') DEFAULT 'General',

    status ENUM('Unread', 'Read') DEFAULT 'Unread',

    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,

    FOREIGN KEY (user_id) REFERENCES users(id)

);


Code in detail

💉 1 Database Table

First, run this SQL in phpMyAdmin to create the table

CREATE TABLE blood_inventory (
    id INT AUTO_INCREMENT PRIMARY KEY,
    blood_group VARCHAR(10) NOT NULL,
    quantity INT NOT NULL,
    collected_on DATE NOT NULL,
    expiry_date DATE NOT NULL,
    location VARCHAR(255) NOT NULL,
    status ENUM('Available', 'Used', 'Expired') DEFAULT 'Available',
    updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);

💻 2️ add_stock.php

<?php
$conn = new mysqli("localhost", "root", "", "your_database");
 if (isset($_POST['submit'])) {
    $blood_group = $_POST['blood_group'];
    $quantity = $_POST['quantity'];
    $collected_on = $_POST['collected_on'];
    $expiry_date = $_POST['expiry_date'];
    $location = $_POST['location'];
 
    $sql = "INSERT INTO blood_inventory (blood_group, quantity, collected_on, expiry_date, location) 
            VALUES ('$blood_group', '$quantity', '$collected_on', '$expiry_date', '$location')";
 
    if ($conn->query($sql) === TRUE) {
        echo "Blood stock added successfully!";
    } else {
        echo "Error: " . $conn->error;
    }
}
?>
 
<form method="post">
    Blood Group: <input type="text" name="blood_group" required><br>
    Quantity: <input type="number" name="quantity" required><br>
    Collected On: <input type="date" name="collected_on" required><br>
    Expiry Date: <input type="date" name="expiry_date" required><br>
    Location: <input type="text" name="location" required><br>
    <button type="submit" name="submit">Add Stock</button>
</form>

💻 3️ update_stock.php

<?php
$conn = new mysqli("localhost", "root", "", "your_database");
 
if (isset($_POST['update'])) {
    $id = $_POST['id'];
    $quantity = $_POST['quantity'];
    $status = $_POST['status'];
 
    $sql = "UPDATE blood_inventory SET quantity = '$quantity', status = '$status' WHERE id = '$id'";
 
    if ($conn->query($sql) === TRUE) {
        echo "Stock updated successfully!";
    } else {
        echo "Error: " . $conn->error;
    }
}
?>
 
<form method="post">
    Stock ID: <input type="number" name="id" required><br>
    New Quantity: <input type="number" name="quantity" required><br>
    Status:
    <select name="status">
        <option value="Available">Available</option>
        <option value="Used">Used</option>
        <option value="Expired">Expired</option>
    </select><br>
    <button type="submit" name="update">Update Stock</button>
</form>

💻 4️ view_inventory.php

<?php
$conn = new mysqli("localhost", "root", "", "your_database");
 
$result = $conn->query("SELECT * FROM blood_inventory");
 
echo "<table border='1'>
<tr>
<th>ID</th>
<th>Blood Group</th>
<th>Quantity</th>
<th>Collected On</th>
<th>Expiry Date</th>
<th>Location</th>
<th>Status</th>
</tr>";
 
while ($row = $result->fetch_assoc()) {
    echo "<tr>
    <td>{$row['id']}</td>
    <td>{$row['blood_group']}</td>
    <td>{$row['quantity']}</td>
    <td>{$row['collected_on']}</td>
    <td>{$row['expiry_date']}</td>
    <td>{$row['location']}</td>
    <td>{$row['status']}</td>
    </tr>";
}
echo "</table>";
?>

💻 5️ delete_stock.php

<?php
$conn = new mysqli("localhost", "root", "", "your_database");
 
if (isset($_POST['delete'])) {
    $id = $_POST['id'];
 
    $sql = "DELETE FROM blood_inventory WHERE id = '$id'";
 
    if ($conn->query($sql) === TRUE) {
        echo "Stock entry deleted!";
    } else {
        echo "Error: " . $conn->error;
    }
}
?>
 
<form method="post">
    Stock ID to Delete: <input type="number" name="id" required><br>
    <button type="submit" name="delete">Delete Stock</button>
</form>

Notes:

  • Replace your_database with your real DB name.
  • Add Bootstrap for better design.
  • Add validation for production (to prevent SQL injection).

💾 Database Table: appointments

CREATE TABLE appointments (

    id INT AUTO_INCREMENT PRIMARY KEY,
    donor_id INT NOT NULL,
    appointment_date DATE NOT NULL,
    appointment_time TIME NOT NULL,
    location VARCHAR(255) NOT NULL,
    status ENUM('Pending', 'Confirmed', 'Cancelled') DEFAULT 'Pending',
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    FOREIGN KEY (donor_id) REFERENCES users(id)
);

💻 1️ book_appointment.php

(Donor's form to request an appointment)


<?php
$conn = new mysqli("localhost", "root", "", "your_database");
if (isset($_POST['submit'])) {
    $donor_id = $_POST['donor_id'];  // In real life, use $_SESSION!
    $appointment_date = $_POST['appointment_date'];
    $appointment_time = $_POST['appointment_time'];
    $location = $_POST['location'];
 
    $sql = "INSERT INTO appointments (donor_id, appointment_date, appointment_time, location) 
            VALUES ('$donor_id', '$appointment_date', '$appointment_time', '$location')";
 
    if ($conn->query($sql) === TRUE) {
        echo "Appointment booked! Await admin confirmation.";
    } else {
        echo "Error: " . $conn->error;
    }
}
?>
 
<form method="post">
    Donor ID: <input type="number" name="donor_id" required><br>
    Date: <input type="date" name="appointment_date" required><br>
    Time: <input type="time" name="appointment_time" required><br>
    Location: <input type="text" name="location" required><br>
    <button type="submit" name="submit">Book Appointment</button>
</form>

💻 2️ my_appointments.php

(Donor's appointment history)

<?php
$conn = new mysqli("localhost", "root", "", "your_database");
$donor_id = 1; // Ideally, fetch from session
 
$result = $conn->query("SELECT * FROM appointments WHERE donor_id = '$donor_id'");
 
echo "<h2>My Appointments</h2>";
echo "<table border='1'>
<tr>
<th>Date</th>
<th>Time</th>
<th>Location</th>
<th>Status</th>
<th>Booked On</th>
</tr>";
 
while ($row = $result->fetch_assoc()) {
    echo "<tr>
    <td>{$row['appointment_date']}</td>
    <td>{$row['appointment_time']}</td>
    <td>{$row['location']}</td>
    <td>{$row['status']}</td>
    <td>{$row['created_at']}</td>
    </tr>";
}
echo "</table>";
?>

💻 3️ manage_appointments.php

(Admin: approve / reschedule / cancel)

<?php
$conn = new mysqli("localhost", "root", "", "your_database");
if (isset($_POST['update'])) {
    $id = $_POST['id'];
    $status = $_POST['status'];
 
    $sql = "UPDATE appointments SET status = '$status' WHERE id = '$id'";
    if ($conn->query($sql) === TRUE) {
        echo "Appointment updated!";
    } else {
        echo "Error: " . $conn->error;
    }
}
 
$result = $conn->query("SELECT * FROM appointments");
 
echo "<h2>Manage Appointments</h2>";
echo "<table border='1'>
<tr>
<th>ID</th>
<th>Donor ID</th>
<th>Date</th>
<th>Time</th>
<th>Location</th>
<th>Status</th>
<th>Update</th>
</tr>";
 
while ($row = $result->fetch_assoc()) {
    echo "<tr>
    <form method='post'>
        <td>{$row['id']}<input type='hidden' name='id' value='{$row['id']}'></td>
        <td>{$row['donor_id']}</td>
        <td>{$row['appointment_date']}</td>
        <td>{$row['appointment_time']}</td>
        <td>{$row['location']}</td>
        <td>
            <select name='status'>
                <option value='Pending' " . ($row['status'] == 'Pending' ? 'selected' : '') . ">Pending</option>
                <option value='Confirmed' " . ($row['status'] == 'Confirmed' ? 'selected' : '') . ">Confirmed</option>
                <option value='Cancelled' " . ($row['status'] == 'Cancelled' ? 'selected' : '') . ">Cancelled</option>
            </select>
        </td>
        <td><button type='submit' name='update'>Update</button></td>
    </form>
    </tr>";
}
echo "</table>";
?>

Summary:

  • book_appointment.php — Donor books an appointment.
  • my_appointments.php — Donor sees their bookings.
  • manage_appointments.php — Admin can approve, cancel, reschedule.

💾 Database Table: notifications

First, create this table in phpMyAdmin:

CREATE TABLE notifications (
    id INT AUTO_INCREMENT PRIMARY KEY,
    user_id INT NOT NULL,
    message TEXT NOT NULL,
    type ENUM('Request', 'Appointment', 'Stock', 'General') DEFAULT 'General',
    status ENUM('Unread', 'Read') DEFAULT 'Unread',
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    FOREIGN KEY (user_id) REFERENCES users(id)
);

💻 1️ send_email.php

(Sending an email notification)

<?php
$to = "user@example.com";  // Replace with recipient's email
$subject = "Blood Donation Notification";
$message = "Your blood donation appointment has been confirmed!";
$headers = "From: admin@bloodbank.com";
 
if (mail($to, $subject, $message, $headers)) {
    echo "Email sent successfully to $to.";
} else {
    echo "Email sending failed.";
}
?>

💻 2️ send_sms.php

(Assuming you're simulating SMS or using an API like Twilio — simple example here)

<?php
function sendSMS($phoneNumber, $message) {
    // Replace this with real SMS API integration (Twilio, MSG91, etc.)
    echo "Sending SMS to $phoneNumber: $message";
}
 
$phoneNumber = "+911234567890"; // Example number
$message = "Your blood donation appointment is confirmed!";
sendSMS($phoneNumber, $message);
?>

💻 3️ notification_list.php

(Admin: View all notifications)

<?php
$conn = new mysqli("localhost", "root", "", "your_database");
$result = $conn->query("SELECT * FROM notifications");
 
echo "<h2>All Notifications</h2>";
echo "<table border='1'>
<tr>
<th>ID</th>
<th>User ID</th>
<th>Message</th>
<th>Type</th>
<th>Status</th>
<th>Date</th>
</tr>";
 
while ($row = $result->fetch_assoc()) {
    echo "<tr>
        <td>{$row['id']}</td>
        <td>{$row['user_id']}</td>
        <td>{$row['message']}</td>
        <td>{$row['type']}</td>
        <td>{$row['status']}</td>
        <td>{$row['created_at']}</td>
    </tr>";
}
echo "</table>";
?>

💻 4️ user_notifications.php

(User: View their own notifications)

<?php
$conn = new mysqli("localhost", "root", "", "your_database");
$user_id = 1;  // Replace with session-based user ID
 
$result = $conn->query("SELECT * FROM notifications WHERE user_id = '$user_id' ORDER BY created_at DESC");
 
echo "<h2>Your Notifications</h2>";
echo "<ul>";
 
while ($row = $result->fetch_assoc()) {
    echo "<li><strong>[{$row['type']}]</strong> {$row['message']} - {$row['status']} ({$row['created_at']})</li>";
}
echo "</ul>";
?>

Summary:

send_email.php

Send notification via email.

send_sms.php

Simulate/send SMS notifications.

notification_list.php

Admin can view all notifications.

user_notifications.php

User can view their own notifications.


 


Tags

Post a Comment

0Comments

Post a Comment (0)