-
-
Notifications
You must be signed in to change notification settings - Fork 19
Project Documentation
A hospital management system, made using object oriented programming and file handling in C++, that keeps records of doctors & their appointments, patients, staff, ambulances, etc. ...
|
|
|
|
|
|
|
|
CLASS | DESCRIPTION |
---|---|
address |
|
person |
|
appointment |
|
ambulance |
|
hospital |
|
- for data storage details: kindly refer to this link
-
-
these functions are defined in the classes of each and every entity i.e. classes
doctor, patient, nurse, driver, ambulance, appointment
; -it fetches saved data from the class's corresponding CSV file using afstream
object and save it in its correspondingstatic map
for further use by all other methods; -
for example following is the
doctor::fillMap();
function:
void doctor::fillMap() { fstream f; f.open("./data/doctors.csv", ios::in); string temp; //skipping the first row containing column headers; getline(f >> ws, temp); //analyzing each entry afterwards; while (getline(f >> ws, temp)) { doctor d; //reading data from doctors.csv file and //filling it in the doctor class object 'd' //long code - omitted! hospital::doctorsList[d.id] = d; } f.close(); return; }
-
-
-
these functions, again, are defined in the classes of each and every entity i.e. classes
doctor, patient, nurse, driver, ambulance, appointment
; -
it overwrites the changed data, present inside the corresponding
static map
, (changed by the user during the span of the program) to the corresponding CSV file using afstream
object; -
for example following is the
doctor::saveMap();
function:
void doctor::saveMap() { fstream f; f.open("./data/temp.csv", ios::out); // `le first line conataining column headers: f << "doctorId,firstName,lastName,gender,age,mobNumber,address,type,appointmentsBooked\n"; for (auto i : hospital::doctorsList) f << i.second.id << "," << i.second.firstName << "," << i.second.lastName << "," << i.second.gender << "," << i.second.age << "," << i.second.mobNumber << "," << i.second.add.addToStr() << "," << i.second.type << "," << i.second.appointmentsBooked << endl; f.close(); remove("./data/doctors.csv"); rename("./data/temp.csv", "./data/doctors.csv"); return; }
-
-
-
person::addPerson();
: takes the first name, last name, age, gender, mobile number and address as the input; -
class-specific
addPerson();
function : includes a function call to its base class copyperson::addPerson();
and once the basic details are input, the class specific addPerson(); funtion takes class-specific details as input from the user side; -
for example following is the
doctor::addPerson();
function:
void doctor::addPerson() { if (hospital::doctorsList.size() == hospital::doctorsLimit) { cout<<"\n\nDoctors limit reached, can't add more!\n\n"; return; } //18 and 65 are the age limits for registration of a new doctor; person::addPerson(18, 65); //called base class version of addPerson(); to get the basic details as input; if ((age < 18) || (age > 65)) return; cout << "\nEnter the type of the doctor: \n"; //now, getting doctor specific details; getline(cin >> ws, type); if (hospital::doctorsList.rbegin() != hospital::doctorsList.rend()) id = ((hospital::doctorsList.rbegin())->first) + 1; else id = 1; hospital::doctorsList[id] = *this; //creating a fstream object to read/write from/to files; fstream f; //creating a record in doctorsHistory.csv; f.open("./data/doctorsHistory.csv", ios::app); f << firstName << "," << lastName << "," << gender << "," << age << "," << mobNumber << "," << add.addToStr() << "," << type << ",N,NA" << endl; f.close(); cout << "\n" << firstName << " " << lastName << " registered successfully!\n"; cout << "Their ID is: " << id << "\n"; return; }
-
add function of class
ambulance
i.e.addAmbulance();
works in a similar fashion;
-
-
-
person::printDetails();
: prints the first name, last name, age, gender, mobile number and address of the object that invoked the class-specificprintDetails();
function; -
class-specific
printDetails();
function : includes a function call to its base class copyperson::printDetails();
and once the basic details are printed, the class specific printDetails(); funtion prints class-specific details of the object that invoked this function; -
for example following is the
doctor::printDetails();
function:
void doctor::printDetails() { if (id == -1) return; person::printDetails(); //called its base class version, to print the basic details; //now printing class-specific details; cout << "Type : " << type << "\n"; cout << "Appointments : " << appointmentsBooked << "/8 (appointments booked today)\n"; return; }
-
-
-
person::printDetailsFromHistory();
: prints the first name, last name, age, gender, mobile number and address of the object that invoked the class-specificprintDetailsFromHistory();
function; -
class-specific
printDetailsFromHistory();
function : includes a function call to its base class copyperson::printDetailsFromHistory();
and once the basic details are printed, the class specific printDetailsFromHistory(); funtion prints class-specific details of the object that invoked this function; -
the argument
string extraDetails
contains all those details from the class's corresponding*History.csv
file which couldn't be stored inside the object of the class but were required to be printed, for example, the filedoctorsHistory.csv
contains two extra columns,leftWork?
to tell if the doctor is still registered with the hospital or not andreasonForLeaving
to tell (if the doctor has left work) the reason why he/she left the hospital, these two values have no place in the classdoctor
object to be stored, so, the last part (after the second last,
(comma char)) of thedoctorsHistory.csv
file is stored as it is in the stringextraDetails
; -
for example following is the
doctor::printDetailsFromHistory();
function:
void doctor::printDetailsFromHistory(string extraDetails = "") { if (id == -1) return; person::printDetailsFromHistory(); stringstream k(extraDetails); string s1, s2; getline(k, s1, ','); getline(k, s2, ','); if (extraDetails == "") { //in case those extra details are not passed by the calling function, //we get them manually from the CSV file; //long code - omitted! } cout << "Type : " << type << "\n"; cout << "Left Work? : " << s1 << "\n"; if (s1 == "Y") cout << "Reason : " << s2 << "\n"; return; }
-
-
- these functions are defined in the classes of each and every entity i.e. classes
doctor, patient, nurse, driver, ambulance, appointment
; - they let the user search for the required entry in the class's corresponding static map (getDetails();) & class's corresponding
*History.csv
file (getDetailsFromHistory();) (respectively) and then fills the details of the selected entry into the calling object for further use; -
getDetails();
function can directly use the filledstatic map
for the data; butgetDetailsFromHistory();
has to access the History CSV file, as there's no map storing history data;
- these functions are defined in the classes of each and every entity i.e. classes
-
-
these functions are defined in the classes derived from class
person
i.e. classesdoctor, patient, nurse, driver
(has a slightly different meaning for classpatient
, there it rather means "discharge a patient", name of the function is same though); -
funtioning:
- first of all, it gives a call to class's
getDetails();
function to let the user search and select the person to be removed; - once selected, it checks if the selected person can be removed (in case of doctor, checks if the doctor has no appointments booked for the day);
- if can be removed, then it deletes that person's object from the class's corresponding
static map
and in the History CSV file, marks the appropriate column to denote that the person is no longer a part of the hospital;
- first of all, it gives a call to class's
-
for example following is the
doctor::removePerson();
function:
void doctor::removePerson() { cout << "\nSearch for the doctor you want to remove.\n"; getDetails(); if (id == -1) return; if (appointmentsBooked > 0) { cout << "\nSelected doctor has appointments booked for today, can't be removed.\n\n"; return; } hospital::doctorsList.erase(id); //a new file temp.csv is created then each and every line of; //doctorsHistory.csv is copied to temp.csv except for the line; //of the person to be removed, that line is stored in a string; //required changes are made to it and it's pasted in the place of; //original line, in temp.csv file. //long code - omitted! //after that doctorsHistory.csv is removed and temp.csv is renamed. remove("./data/doctorsHistory.csv"); rename("./data/temp.csv", "./data/doctorsHistory.csv"); cout << firstName << " " << lastName << " removed successfully!\n"; return; }
-
remove function of class
ambulance
i.e.removeAmbulance();
works in a similar fashion;
-
-
- these functions are implemented really simply, they just change the values of
patient
class fieldsbool hospitalized, alive;
to TRUE and FALSE respectively - in addition, they also change the values of
patientsHistory.csv
file's columns, namely "was Hospitalized?", "still Alive?" to 'Y' and 'N' respectively;
- these functions are implemented really simply, they just change the values of
-
- it fetches an idle ambulance and an idle driver and then changes their
bool idle;
fields to FALSE, takes the address of the destination location from the user side as input and sends the ambulance to that address; - functioning:
- searches in the map
hospital::ambulancesList
for the first ambulance which has itsbool idle;
field set as TRUE, and if not found prints not found message and returns the control, else moves further; - searches in the map
hospital::driversList
for the first driver which has itsbool idle;
field set as TRUE, and if not found prints not found message and returns the control, else moves further; - takes the address of the location where the ambulance is to be sent as input from the user side;
- adds that address into
address add
field of the ambulance object;
- searches in the map
void ambulance::send() { //*************picking an idle ambulance*************; bool gotOne = 0; for (auto i : hospital::ambulancesList) { if (i.second.idle) { *this = i.second; gotOne = 1; break; } } if (!gotOne) { cout << "No, idle ambulance found!" << "\n"; return; } //************* picking a free driver *************; gotOne = 0; for (auto i : hospital::driversList) { if (i.second.idle) { D = i.second; gotOne = 1; break; } } if (!gotOne) { cout << "No, idle driver found!" << "\n"; return; } idle = 0; cout << "Enter destination address:\n"; add.takeInput(); //updating status of ambulance; hospital::ambulancesList[id] = *this; //updating status of driver; hospital::driversList[D.id].idle = 0; cout << model << " by " << manufacturer << " sent with driver " << D.firstName << " " << D.lastName << " (ID = " << D.id << ") successfully!\n"; return; }
- it fetches an idle ambulance and an idle driver and then changes their
-
- implementation of this function is pretty simple;
- firstly it gives the call to
ambulance::getDetails();
function to let the user select the ambulance whose arrival is to be reported; - once selected, it just changes the
bool idle;
fields of the associated driver and ambulance objects to TRUE;
void ambulance::reportArrival() { getDetails(); //updating status of driver; hospital::driversList[D.id].idle = 1; //updating status of ambulance; hospital::ambulancesList[id].idle = 1; hospital::ambulancesList[id].add.strToAdd("`````"); driver d; hospital::ambulancesList[id].D = d; cout << "\nStatus updated successfully!\n\n"; return; }