0% found this document useful (0 votes)
21 views

Hospital Management System_FUNCTIONS

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)
21 views

Hospital Management System_FUNCTIONS

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 - function

#include <stdio.h>

#include <string.h>

#include <stdlib.h>

// Constants

#define MAX_DOCTORS 5

#define MAX_PATIENTS 10

#define MAX_NAME_LEN 100

// Function Prototypes

void displayMenu();

void viewDoctors(char doctors[][MAX_NAME_LEN], char specializations[][MAX_NAME_LEN], int


availableSlots[], int doctorCount);

void makeAppointment(char doctors[][MAX_NAME_LEN], char specializations[][MAX_NAME_LEN], int


availableSlots[], int doctorCount, char patients[][MAX_NAME_LEN], char patientDoctors[]
[MAX_NAME_LEN], int patientSlots[], int *patientCount);

void viewAppointments(char patients[][MAX_NAME_LEN], char patientDoctors[][MAX_NAME_LEN], int


patientSlots[], int patientCount);

void addPatient(char patients[][MAX_NAME_LEN], int *patientCount);

void viewPatient(char patients[][MAX_NAME_LEN], char patientDoctors[][MAX_NAME_LEN], int


patientSlots[], int patientCount);

void handleUserChoice(int choice, char doctors[][MAX_NAME_LEN], char specializations[]


[MAX_NAME_LEN], int availableSlots[], int doctorCount, char patients[][MAX_NAME_LEN], char
patientDoctors[][MAX_NAME_LEN], int patientSlots[], int *patientCount);

int main() {

// Initialize doctor details (Name, Specialization, Available Slots)


char doctors[MAX_DOCTORS][MAX_NAME_LEN] = {

"Dr. Smith", "Dr. Johnson", "Dr. Lee", "Dr. Brown", "Dr. White"

};

char specializations[MAX_DOCTORS][MAX_NAME_LEN] = {

"Cardiologist", "Neurologist", "Orthopedic", "Pediatrician", "Dermatologist"

};

int availableSlots[MAX_DOCTORS] = {5, 3, 4, 2, 6};

// Initialize patient details (Name, Doctor's Name, Appointment Slot)

char patients[MAX_PATIENTS][MAX_NAME_LEN] = {0};

char patientDoctors[MAX_PATIENTS][MAX_NAME_LEN] = {0};

int patientSlots[MAX_PATIENTS] = {0};

int patientCount = 0;

// Start the menu system

displayMenu();

handleUserChoice(0, doctors, specializations, availableSlots, MAX_DOCTORS, patients, patientDoctors,


patientSlots, &patientCount);

return 0;

// Function to display the menu

void displayMenu() {
printf("\nHospital Management System\n");

printf("1. View Doctor Details\n");

printf("2. Make Appointment\n");

printf("3. View Appointments\n");

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

printf("5. View Patient\n");

printf("6. Exit\n");

printf("Enter your choice: ");

// Function to view available doctors

void viewDoctors(char doctors[][MAX_NAME_LEN], char specializations[][MAX_NAME_LEN], int


availableSlots[], int doctorCount) {

printf("\nList of Available Doctors:\n");

for (int i = 0; i < doctorCount; i++) {

printf("Doctor: %s\n", doctors[i]);

printf("Specialization: %s\n", specializations[i]);

printf("Available Slots: %d\n", availableSlots[i]);

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

// Function to make an appointment

void makeAppointment(char doctors[][MAX_NAME_LEN], char specializations[][MAX_NAME_LEN], int


availableSlots[], int doctorCount, char patients[][MAX_NAME_LEN], char patientDoctors[]
[MAX_NAME_LEN], int patientSlots[], int *patientCount) {

char doctorName[MAX_NAME_LEN];
char patientName[MAX_NAME_LEN];

int slot;

// Ask for doctor and patient details

printf("\nEnter Your Name: ");

getchar(); // To consume newline character

fgets(patientName, sizeof(patientName), stdin);

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

printf("Enter Doctor's Name for Appointment: ");

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

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

printf("Enter Appointment Slot (1 to 5): ");

scanf("%d", &slot);

// Check if doctor exists and has available slots

int doctorIndex = -1;

for (int i = 0; i < doctorCount; i++) {

if (strcmp(doctors[i], doctorName) == 0) {

doctorIndex = i;

break;

}
if (doctorIndex == -1) {

printf("Doctor not found.\n");

return;

if (slot < 1 || slot > availableSlots[doctorIndex]) {

printf("Invalid slot. Please choose a valid slot.\n");

return;

// Make the appointment

strcpy(patients[*patientCount], patientName);

strcpy(patientDoctors[*patientCount], doctorName);

patientSlots[*patientCount] = slot;

(*patientCount)++;

// Update the available slot for the doctor

availableSlots[doctorIndex]--;

printf("\nAppointment successful for %s with Dr. %s on Slot %d.\n", patientName, doctorName, slot);

// Function to view all appointments

void viewAppointments(char patients[][MAX_NAME_LEN], char patientDoctors[][MAX_NAME_LEN], int


patientSlots[], int patientCount) {

printf("\nList of Appointments:\n");
if (patientCount == 0) {

printf("No appointments scheduled.\n");

} else {

for (int i = 0; i < patientCount; i++) {

printf("Patient: %s\n", patients[i]);

printf("Doctor: %s\n", patientDoctors[i]);

printf("Appointment Slot: %d\n", patientSlots[i]);

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

// Function to add a new patient

void addPatient(char patients[][MAX_NAME_LEN], int *patientCount) {

if (*patientCount >= MAX_PATIENTS) {

printf("\nPatient list is full. Cannot add more patients.\n");

return;

char patientName[MAX_NAME_LEN];

printf("\nEnter Patient Name: ");

getchar(); // Consume the newline character

fgets(patientName, sizeof(patientName), stdin);

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


// Add patient to the list

strcpy(patients[*patientCount], patientName);

(*patientCount)++;

printf("\nPatient %s added successfully.\n", patientName);

// Function to view a specific patient's details

void viewPatient(char patients[][MAX_NAME_LEN], char patientDoctors[][MAX_NAME_LEN], int


patientSlots[], int patientCount) {

char patientName[MAX_NAME_LEN];

printf("\nEnter Patient Name to View: ");

getchar(); // Consume the newline character

fgets(patientName, sizeof(patientName), stdin);

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

int found = 0;

for (int i = 0; i < patientCount; i++) {

if (strcmp(patients[i], patientName) == 0) {

printf("\nPatient: %s\n", patients[i]);

printf("Doctor: %s\n", patientDoctors[i]);

printf("Appointment Slot: %d\n", patientSlots[i]);

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

found = 1;

break;

}
if (!found) {

printf("\nPatient %s not found.\n", patientName);

// Function to handle the user's choice and recursion

void handleUserChoice(int choice, char doctors[][MAX_NAME_LEN], char specializations[]


[MAX_NAME_LEN], int availableSlots[], int doctorCount, char patients[][MAX_NAME_LEN], char
patientDoctors[][MAX_NAME_LEN], int patientSlots[], int *patientCount) {

if (choice == 1) {

viewDoctors(doctors, specializations, availableSlots, doctorCount);

} else if (choice == 2) {

makeAppointment(doctors, specializations, availableSlots, doctorCount, patients, patientDoctors,


patientSlots, patientCount);

} else if (choice == 3) {

viewAppointments(patients, patientDoctors, patientSlots, *patientCount);

} else if (choice == 4) {

addPatient(patients, patientCount);

} else if (choice == 5) {

viewPatient(patients, patientDoctors, patientSlots, *patientCount);

} else if (choice == 6) {

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

return; // Exit the recursion

} else {

printf("Invalid choice! Please try again.\n");

}
// Recursively call the menu to allow another action

displayMenu();

int newChoice;

scanf("%d", &newChoice);

handleUserChoice(newChoice, doctors, specializations, availableSlots, doctorCount, patients,


patientDoctors, patientSlots, patientCount);

Output
Hospital Management System

1. View Doctor Details

2. Make Appointment

3. View Appointments

4. Add Patient

5. View Patient

6. Exit

Enter your choice: 1

List of Available Doctors:

Doctor: Dr. Smith

Specialization: Cardiologist

Available Slots: 5

----------------------------

Doctor: Dr. Johnson

Specialization: Neurologist

Available Slots: 3

----------------------------

Doctor: Dr. Lee

Specialization: Orthopedic

Available Slots: 4

----------------------------

Doctor: Dr. Brown

Specialization: Pediatrician

Available Slots: 2
----------------------------

Doctor: Dr. White

Specialization: Dermatologist

Available Slots: 6

----------------------------

Hospital Management System

1. View Doctor Details

2. Make Appointment

3. View Appointments

4. Add Patient

5. View Patient

6. Exit

Enter your choice: 2

Enter Your Name: John Doe

Enter Doctor's Name for Appointment: Dr. Smith

Enter Appointment Slot (1 to 5): 2

Appointment successful for John Doe with Dr. Smith on Slot 2.

Hospital Management System

1. View Doctor Details

2. Make Appointment

3. View Appointments
4. Add Patient

5. View Patient

6. Exit

Enter your choice: 3

List of Appointments:

Patient: John Doe

Doctor: Dr. Smith

Appointment Slot: 2

----------------------------

Hospital Management System

1. View Doctor Details

2. Make Appointment

3. View Appointments

4. Add Patient

5. View Patient

6. Exit

Enter your choice: 4

Enter Patient Name: Alice

Patient Alice added successfully.

Hospital Management System


1. View Doctor Details

2. Make Appointment

3. View Appointments

4. Add Patient

5. View Patient

6. Exit

Enter your choice: 5

Enter Patient Name to View: Alice

Patient: Alice

Doctor: (No appointment yet)

Appointment Slot: 0

----------------------------

Hospital Management System

1. View Doctor Details

2. Make Appointment

3. View Appointments

4. Add Patient

5. View Patient

6. Exit

Enter your choice: 6

Exiting the system...


Algorithm

 Start

 Initialize the doctors, specializations, and availableSlots arrays.

 Initialize the patients, patientDoctors, and patientSlots arrays.

 Display Menu with options:

1. View Doctor Details

2. Make Appointment

3. View Appointments

4. Add Patient

5. View Patient

6. Exit

 Handle User Choice:

 If choice is 1:

o Call viewDoctors() to display all doctors and their details.

 If choice is 2:

o Call makeAppointment() to allow the user to make an appointment.

o Ask for patient's name, doctor's name, and preferred appointment slot.
o Check if the doctor exists and if the slot is valid.

o Update the appointment details and the doctor's available slots.

 If choice is 3:

o Call viewAppointments() to show all scheduled appointments.

 If choice is 4:

o Call addPatient() to add a new patient to the system.

 If choice is 5:

o Call viewPatient() to display the details of a specific patient.

 If choice is 6:

o Exit the program.

 Repeat until the user selects the option to exit.

Pseudocode

START

Initialize doctors array with names

Initialize specializations array with doctor specialties

Initialize availableSlots array with available slots for each doctor

Initialize patients array

Initialize patientDoctors array

Initialize patientSlots array

Initialize patientCount = 0
DISPLAY MENU

PRINT "1. View Doctor Details"

PRINT "2. Make Appointment"

PRINT "3. View Appointments"

PRINT "4. Add Patient"

PRINT "5. View Patient"

PRINT "6. Exit"

ASK for user choice

IF user chooses option 1 (View Doctor Details):

CALL viewDoctors() with doctors, specializations, availableSlots

IF user chooses option 2 (Make Appointment):

ASK for patient name

ASK for doctor name

ASK for appointment slot

FIND doctor by name in doctors array

IF doctor is found:

IF slot is valid and available:

MAKE appointment by updating patient arrays and doctor available slots

PRINT appointment success message

ELSE:

PRINT "Invalid slot or no available slots"

ELSE:

PRINT "Doctor not found"


IF user chooses option 3 (View Appointments):

CALL viewAppointments() with patients, patientDoctors, patientSlots

IF user chooses option 4 (Add Patient):

ASK for patient name

ADD patient to patients array

INCREMENT patientCount

PRINT "Patient added successfully"

IF user chooses option 5 (View Patient):

ASK for patient name

FIND patient in patients array

IF patient is found:

PRINT patient details

ELSE:

PRINT "Patient not found"

IF user chooses option 6 (Exit):

PRINT "Exiting the system..."

EXIT program

REPEAT menu until user chooses exit

END
Flowchart

You might also like