0% found this document useful (0 votes)
18 views18 pages

Hospital Management System Complex Structures

Uploaded by

arun prabu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views18 pages

Hospital Management System Complex Structures

Uploaded by

arun prabu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 18

HOSPITAL MANAGEMENT SYSTEM – UNIT 4 – COMPLEX STRUCTURES

PROGRAM

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

// Structure for patient information

struct Patient {

int patientID;

char name[100];

int age;

char gender[10];

char diagnosis[200];

float totalBill;

struct Appointment *appointments; // Linked list for appointments

struct Patient *next;

};

// Structure for appointment information

struct Appointment {

char doctorName[100];

char date[20]; // Date format "dd-mm-yyyy"

char time[10]; // Time format "hh:mm"

struct Appointment *next;

};

// Structure for hospital management system

struct Hospital {

struct Patient *patientList;

};
// Function to create a new appointment node

struct Appointment* createAppointment(char* doctorName, char* date, char* time) {

struct Appointment *newAppointment = (struct Appointment*) malloc(sizeof(struct


Appointment));

strcpy(newAppointment->doctorName, doctorName);

strcpy(newAppointment->date, date);

strcpy(newAppointment->time, time);

newAppointment->next = NULL;

return newAppointment;

// Function to create a new patient node

struct Patient* createPatient(int patientID, char* name, int age, char* gender, char* diagnosis) {

struct Patient *newPatient = (struct Patient*) malloc(sizeof(struct Patient));

newPatient->patientID = patientID;

strcpy(newPatient->name, name);

newPatient->age = age;

strcpy(newPatient->gender, gender);

strcpy(newPatient->diagnosis, diagnosis);

newPatient->totalBill = 0; // Initially set total bill to 0

newPatient->appointments = NULL; // No appointments initially

newPatient->next = NULL;

return newPatient;

// Function to add a patient to the hospital list

void addPatient(struct Hospital *hospital, int patientID, char* name, int age, char* gender, char*
diagnosis) {

struct Patient *newPatient = createPatient(patientID, name, age, gender, diagnosis);

if (hospital->patientList == NULL) {

hospital->patientList = newPatient;
} else {

struct Patient *temp = hospital->patientList;

while (temp->next != NULL) {

temp = temp->next;

temp->next = newPatient;

// Function to display patient details

void displayPatients(struct Hospital *hospital) {

if (hospital->patientList == NULL) {

printf("No patients in the hospital.\n");

return;

struct Patient *temp = hospital->patientList;

printf("Patient Details:\n");

printf("ID\tName\tAge\tGender\tDiagnosis\n");

while (temp != NULL) {

printf("%d\t%s\t%d\t%s\t%s\n", temp->patientID, temp->name, temp->age, temp->gender,


temp->diagnosis);

temp = temp->next;

// Function to generate a bill for a patient

void generateBill(struct Hospital *hospital, int patientID) {

struct Patient *temp = hospital->patientList;

while (temp != NULL) {

if (temp->patientID == patientID) {

float consultationFee, treatmentFee, medicationFee, roomCharges;


printf("\nGenerating bill for patient: %s (ID: %d)\n", temp->name, patientID);

// Ask for various fees

printf("Enter consultation fee: ");

scanf("%f", &consultationFee);

printf("Enter treatment fee: ");

scanf("%f", &treatmentFee);

printf("Enter medication fee: ");

scanf("%f", &medicationFee);

printf("Enter room charges: ");

scanf("%f", &roomCharges);

// Calculate the total bill

temp->totalBill = consultationFee + treatmentFee + medicationFee + roomCharges;

// Display the bill

printf("\n--- Bill Summary ---\n");

printf("Consultation Fee: %.2f\n", consultationFee);

printf("Treatment Fee: %.2f\n", treatmentFee);

printf("Medication Fee: %.2f\n", medicationFee);

printf("Room Charges: %.2f\n", roomCharges);

printf("Total Bill: %.2f\n", temp->totalBill);

return;

temp = temp->next;

printf("Patient with ID %d not found.\n", patientID);


}

// Function to schedule an appointment for a patient

void scheduleAppointment(struct Hospital *hospital, int patientID) {

struct Patient *temp = hospital->patientList;

while (temp != NULL) {

if (temp->patientID == patientID) {

char doctorName[100], date[20], time[10];

// Get appointment details

printf("Enter doctor's name: ");

getchar(); // To consume newline left by previous input

fgets(doctorName, sizeof(doctorName), stdin);

doctorName[strcspn(doctorName, "\n")] = 0; // Remove newline

printf("Enter appointment date (dd-mm-yyyy): ");

fgets(date, sizeof(date), stdin);

date[strcspn(date, "\n")] = 0; // Remove newline

printf("Enter appointment time (hh:mm): ");

fgets(time, sizeof(time), stdin);

time[strcspn(time, "\n")] = 0; // Remove newline

// Create and add new appointment to patient's list

struct Appointment* newAppointment = createAppointment(doctorName, date, time);

if (temp->appointments == NULL) {

temp->appointments = newAppointment;

} else {

struct Appointment* appointmentTemp = temp->appointments;

while (appointmentTemp->next != NULL) {

appointmentTemp = appointmentTemp->next;
}

appointmentTemp->next = newAppointment;

printf("Appointment scheduled successfully for patient %s.\n", temp->name);

return;

temp = temp->next;

printf("Patient with ID %d not found.\n", patientID);

// Function to display appointments of a patient

void displayAppointments(struct Hospital *hospital, int patientID) {

struct Patient *temp = hospital->patientList;

while (temp != NULL) {

if (temp->patientID == patientID) {

if (temp->appointments == NULL) {

printf("No appointments found for patient %s.\n", temp->name);

return;

struct Appointment *appointmentTemp = temp->appointments;

printf("Appointments for patient %s (ID: %d):\n", temp->name, patientID);

printf("Doctor Name\tDate\tTime\n");

while (appointmentTemp != NULL) {

printf("%s\t%s\t%s\n", appointmentTemp->doctorName, appointmentTemp->date,


appointmentTemp->time);

appointmentTemp = appointmentTemp->next;

return;

temp = temp->next;
}

printf("Patient with ID %d not found.\n", patientID);

// Main function to run the hospital management system

int main() {

struct Hospital hospital = {NULL}; // Initialize the hospital with no patients

int choice, patientID, age;

char name[100], gender[10], diagnosis[200];

while (1) {

printf("\nHospital Management System\n");

printf("1. Add Patient\n");

printf("2. Display Patients\n");

printf("3. Generate Bill for Patient\n");

printf("4. Schedule Appointment\n");

printf("5. Display Appointments\n");

printf("6. Exit\n");

printf("Enter your choice: ");

scanf("%d", &choice);

getchar(); // To consume newline character after entering choice

switch (choice) {

case 1:

// Adding a patient

printf("Enter Patient ID: ");

scanf("%d", &patientID);

getchar(); // Consume newline

printf("Enter Patient Name: ");

fgets(name, sizeof(name), stdin);


name[strcspn(name, "\n")] = 0; // Remove newline character

printf("Enter Age: ");

scanf("%d", &age);

getchar(); // Consume newline

printf("Enter Gender: ");

fgets(gender, sizeof(gender), stdin);

gender[strcspn(gender, "\n")] = 0; // Remove newline

printf("Enter Diagnosis: ");

fgets(diagnosis, sizeof(diagnosis), stdin);

diagnosis[strcspn(diagnosis, "\n")] = 0; // Remove newline

addPatient(&hospital, patientID, name, age, gender, diagnosis);

break;

case 2:

// Displaying all patients

displayPatients(&hospital);

break;

case 3:

// Generating bill for a patient

printf("Enter Patient ID to generate bill: ");

scanf("%d", &patientID);

generateBill(&hospital, patientID);

break;

case 4:

// Scheduling an appointment for a patient

printf("Enter Patient ID to schedule appointment: ");

scanf("%d", &patientID);

scheduleAppointment(&hospital, patientID);

break;
case 5:

// Displaying appointments for a patient

printf("Enter Patient ID to display appointments: ");

scanf("%d", &patientID);

displayAppointments(&hospital, patientID);

break;

case 6:

// Exit the system

printf("Exiting the system...\n");

exit(0);

break;

default:

printf("Invalid choice, please try again.\n");

return 0;

}
OUTPUT

Hospital Management System

1. Add Patient

2. Display Patients

3. Generate Bill for Patient

4. Schedule Appointment

5. Display Appointments

6. Exit

Enter your choice: 1

Enter Patient ID: 1

Enter Patient Name: arun

Enter Age: 18

Enter Gender: male

Enter Diagnosis: fever

Hospital Management System

1. Add Patient

2. Display Patients

3. Generate Bill for Patient

4. Schedule Appointment

5. Display Appointments

6. Exit

Enter your choice: 1

Enter Patient ID: 2

Enter Patient Name: aadhi

Enter Age: 18

Enter Gender: male

Enter Diagnosis: cold

Hospital Management System

1. Add Patient
2. Display Patients

3. Generate Bill for Patient

4. Schedule Appointment

5. Display Appointments

6. Exit

Enter your choice: 2

Patient Details:

ID Name Age Gender Diagnosis

1 arun 18 male fever

2 aadhi 18 male cold

Hospital Management System

1. Add Patient

2. Display Patients

3. Generate Bill for Patient

4. Schedule Appointment

5. Display Appointments

6. Exit

Enter your choice: 4

Enter Patient ID to schedule appointment: 2

Enter doctor's name: john

Enter appointment date (dd-mm-yyyy): 22-11-2024

Enter appointment time (hh:mm): 11:22

Appointment scheduled successfully for patient aadhi.

Hospital Management System

1. Add Patient

2. Display Patients

3. Generate Bill for Patient

4. Schedule Appointment

5. Display Appointments
6. Exit

Enter your choice: 5

Enter Patient ID to display appointments: 2

Appointments for patient aadhi (ID: 2):

Doctor Name Date Time

john 22-11-2024 11:22

Hospital Management System

1. Add Patient

2. Display Patients

3. Generate Bill for Patient

4. Schedule Appointment

5. Display Appointments

6. Exit

Enter your choice: 3

Enter Patient ID to generate bill: 2

Generating bill for patient: aadhi (ID: 2)

Enter consultation fee: 10000

Enter treatment fee: 1000000

Enter medication fee: 254111

Enter room charges: 444466

--- Bill Summary ---

Consultation Fee: 10000.00

Treatment Fee: 1000000.00

Medication Fee: 254111.00

Room Charges: 444466.00

Total Bill: 1708577.00

Medication Fee: 254111.00


Room Charges: 444466.00

Total Bill: 1708577.00

Room Charges: 444466.00

Total Bill: 1708577.00

Total Bill: 1708577.00

Hospital Management System

Hospital Management System

1. Add Patient

1. Add Patient

2. Display Patients

2. Display Patients

3. Generate Bill for Patient

4. Schedule Appointment

5. Display Appointments

6. Exit

Enter your choice: 6

Exiting the system...


Algorithm for the Hospital Management System

1. Start the program.

2. Initialize the hospital system (empty list of patients).

3. Display Menu with options:

o Add Patient

o Display Patients

o Generate Bill for Patient

o Schedule Appointment for Patient

o Display Appointments of a Patient

o Exit

4. Option 1: Add Patient:

o Prompt the user to enter patient details (ID, name, age, gender, diagnosis).

o Create a new patient node and add it to the list of patients.

o Return to the menu.

5. Option 2: Display Patients:

o Loop through the list of patients and display their details.

o Return to the menu.

6. Option 3: Generate Bill for Patient:

o Prompt the user for the patient ID.

o Search for the patient in the list.

o If found, ask for fee details (consultation, treatment, medication, room charges) and
calculate the total bill.

o Display the bill details.

o Return to the menu.

7. Option 4: Schedule Appointment for Patient:

o Prompt the user for the patient ID.

o Search for the patient in the list.

o If found, ask for appointment details (doctor's name, date, time).

o Create a new appointment node and add it to the patient's list of appointments.

o Return to the menu.

8. Option 5: Display Appointments of a Patient:


o Prompt the user for the patient ID.

o Search for the patient in the list.

o If found, display all their appointments (doctor's name, date, time).

o Return to the menu.

9. Option 6: Exit:

o Terminate the program.

10. End.

PSEUDOCODE

START

Initialize hospital with no patients

WHILE true

Display Menu with options:

1. Add Patient

2. Display Patients

3. Generate Bill

4. Schedule Appointment

5. Display Appointments

6. Exit

Read choice

SWITCH choice:

CASE 1:

Prompt for patient details (ID, name, age, gender, diagnosis)

Create a new patient node

Add the patient to the hospital list

CASE 2:

IF hospital has no patients

Display "No patients found"


ELSE

Display all patients

CASE 3:

Prompt for patient ID

Search for the patient in the list

IF patient found

Prompt for fee details (consultation, treatment, medication, room charges)

Calculate total bill

Display bill details

ELSE

Display "Patient not found"

CASE 4:

Prompt for patient ID

Search for the patient in the list

IF patient found

Prompt for appointment details (doctor's name, date, time)

Create a new appointment node

Add appointment to the patient's appointment list

ELSE

Display "Patient not found"

CASE 5:

Prompt for patient ID

Search for the patient in the list

IF patient found

Display all appointments for the patient

ELSE

Display "Patient not found"

CASE 6:

Exit the program

END WHILE

END
FLOWCHART

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy