Skip to content

Sds218/CSE-project

Repository files navigation

Lifeline Donors

Lifeline Donors Logo

"A donation today, a life saved tomorrow"


Introduction

Lifeline Donors is a terminal-based blood donation ecosystem that connects donors with recipients through a secure database. This C application implements core healthcare management features while prioritizing accessibility in low-resource environments. The system currently supports donor registration with medical history screening and lays the foundation for future recipient matching capabilities.

Project Description

This system aims to streamline the workflow for both donors and blood center administrators by providing:

  • Automated Donor Registration: Ensures eligibility and generates unique IDs.
  • Appointment Scheduling and Management: Prevents double-booking and displays available slots in real-time.
  • Donor Record Maintenance: Allows for safe updates and persistent storage of donor details.

All donor and appointment data are stored in plain text files (records.txt and appointments.txt), making the system lightweight and easy to deploy in resource-constrained environments.


Architecture

The system is organized into distinct modules for clarity and maintainability:

.
├── main.c                # Main program loop and user interface
├── customer_utils.h/c    # Donor ID generation, info display, and updating
├── appointments.h/c      # Appointment scheduling, changing, and slot management
├── records.txt           # Persistent donor records
├── appointments.txt      # Persistent appointment records
└── test.c                # Basic test routines for core functions

Data Flow:

  • Users interact with the menu in main.c.
  • Donor operations are handled by customer_utils.
  • Appointment logic is contained in appointments.
  • All persistent data is read from and written to text files.

Programming Concepts Used

  • Modular Programming: Functions are organized into header/source files for separation of concerns.
  • File I/O: Donor and appointment data are managed using standard file operations (fopen, fprintf, fgets, etc.).
  • Structs and Enums: Used for representing donors, appointments, genders, and blood groups.
  • Input Validation: Ensures only eligible donors can register and only valid data is accepted (e.g., age, blood group, gender).
  • Error Handling: User feedback is given for invalid inputs or file access errors.
  • ANSI Escape Codes: Used for colorful, readable terminal output.
  • Testing: Simple test routines provided in test.c.

Key Features (with Sample Code)

1. Donor Registration with Auto-ID Generation

When a user registers, the system generates a unique 4-digit ID and validates all inputs:

int generateCustomerId() {
    srand(time(NULL));
    int size = 0;
    char **ids = getExistingCustomerIds(&size);
    int customer_id;
    while (1) {
        customer_id = (rand() % (9999 - 1000 + 1)) + 1000;
        if (!isDuplicate(ids, customer_id, size)) break;
    }
    for (int i = 0; i < size; i++) free(ids[i]);
    free(ids);
    return customer_id;
}

Ensures each donor receives a unique ID and prevents duplicates.


2. Appointment Scheduling and Slot Selection

Donors can schedule appointments at their preferred center, with real-time slot availability:

void schedule_appointment(int customer_id) {
    // ... (validation and center selection)
    char *appointment = showAppointments(appointment_center);
    if (appointment == NULL) return;
    show_progress();
    fprintf(APPOINTMENTS, "\n%d %s %s", customer_id, appointment_center, appointment);
    fclose(APPOINTMENTS);
    print_success_message("Appointment scheduled successfully at center");
    free(appointment);
}

Prevents double-booking and allows users to pick from open slots.


3. Donor Information Update

Donors can safely update their details. The system ensures atomic updates using a temporary file:

void update_customer_info(int customer_id) {
    // ... (find and display current info)
    // Prompt for new values, validate, and update
    fprintf(TEMP, "%d %s %d %s %s\n", id, name, age, gender, blood_group);
    // ... (finalize update)
    fclose(RECORD);
    fclose(TEMP);
    remove("records.txt");
    rename("temp_appointments.txt", "records.txt");
}

Ensures data consistency and prevents accidental data loss during updates.


4. Pointer-Based Data Handling

  • Double Pointer ID Validation
char **getExistingCustomerIds(int *size) {
    char **ids = malloc(...);  // Pointer-to-pointer
    while (fgets(...)) {
        ids[i] = malloc(...);  // Nested allocation
    }
    return ids;
}

Execution Guide

Compilation

gcc main.c customer_utils.c appointments.c -o lifesaver

Runtime Operations

# Register donor
./lifesaver 
1. Enter name: John Doe
2. Age: 19
3. Blood Type: O+

# Schedule appointment
./lifesaver
2. Enter Customer ID: 2293
3. Select Center: Arlington
4. Choose Slot: 2025-04-20 10:00

Sample Data Files

records.txt

1539 John 18 Unspecified O+
2293 Doe 18 Female B-

appointments.txt

2293 Arlington 2025-04-20 10:00 open
1539 FortWorth 2025-04-21 09:00 open

Each line represents a donor or appointment record.


Conclusion

This project demonstrates how classic C programming techniques can be applied to build a reliable, user-friendly system for managing blood donations. The modular structure, robust validation, and clear terminal interface make it suitable for small clinics and educational use.


Future Works

  • Network Integration: Add web API support for online donor registration and appointment booking.
  • Graphical User Interface: Develop a GUI (using GTK+ or Qt) for improved usability.
  • Advanced Reporting: Implement analytics for donor retention and blood inventory forecasting.

Contribution Guidelines

We welcome community contributions through:

  1. GitHub Issues (bug reports)
  2. Pull Requests (feature additions)
  3. Documentation improvements

"Every blood drop is a lifeline - handle with care."

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages