From bf11e4bf34ac6414998a872d90dd92682f633535 Mon Sep 17 00:00:00 2001 From: Archisman Karmakar <92569441+ArchismanKarmakar@users.noreply.github.com> Date: Sun, 18 Feb 2024 02:19:42 +0530 Subject: [PATCH] Fixed major bugs and added support for courses. --- include/course.hh | 49 ++++++++++ include/employee.hh | 4 +- include/routine.hh | 27 ++++++ include/table_manage.hh | 18 ++-- src/course.cpp | 198 ++++++++++++++++++++++++++++++++++++++++ src/employee.cpp | 51 ++++++----- src/routine.cpp | 180 ++++++++++++++++++++++++++++++++++++ src/table_manage.cpp | 27 ++++-- 8 files changed, 510 insertions(+), 44 deletions(-) create mode 100644 include/course.hh create mode 100644 include/routine.hh create mode 100644 src/course.cpp create mode 100644 src/routine.cpp diff --git a/include/course.hh b/include/course.hh new file mode 100644 index 0000000..a5b821f --- /dev/null +++ b/include/course.hh @@ -0,0 +1,49 @@ +#ifndef COURSE +#define COURSE + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +class Course +{ +public: + // Course(string course, string details); + + void print(); + void addCourse(); + void takeInput(); + void strToAdd(string str); + string addToStr(string str); + void getDetails(int rec=0); + void saveMap(); + void getDetailsFromHistory(); + void removeCourse(); + +protected: + int courseId; + string courseName; + string courseDetails; + +private: + friend class Routine; +}; + +#endif \ No newline at end of file diff --git a/include/employee.hh b/include/employee.hh index 74843df..7b97db6 100644 --- a/include/employee.hh +++ b/include/employee.hh @@ -10,8 +10,8 @@ class Employee : public Person { private: string type; - int appointmentsBooked; - // friend class appointment; + int classesScheduled; + friend class Routine; public: Employee(); diff --git a/include/routine.hh b/include/routine.hh new file mode 100644 index 0000000..ff2437f --- /dev/null +++ b/include/routine.hh @@ -0,0 +1,27 @@ +#ifndef ROUTINE +#define ROUTINE +using namespace std; + +#include "./course.hh" +#include "./employee.hh" +// #include "./person.hh" + +class Routine +{ +private: + int id; + Employee D; + Course P; + int hh; // hh -> start hour in 24 hour format; + +public: + Routine(); + ~Routine(); + void fillMap(); + void saveMap(); + void printDetails(); + void book(); + void fillDetails(); + void getDetails(); +}; +#endif // !ROUTINE \ No newline at end of file diff --git a/include/table_manage.hh b/include/table_manage.hh index 2de8946..bb738ec 100644 --- a/include/table_manage.hh +++ b/include/table_manage.hh @@ -21,11 +21,11 @@ #include #include "./employee.hh" -// #include "./patient.hh" +#include "./course.hh" // #include "./nurse.hh" // #include "./driver.hh" // #include "./ambulance.hh" -// #include "./appointment.hh" +#include "./routine.hh" #define ull unsigned long long @@ -53,34 +53,38 @@ bool classStandardChk(std::string classStandard_fname); class table_manage { private: - //map + // map static map employeeList; // static map patientsList; + static map courseList; // static map nursesList; // static map driversList; // static map ambulancesList; - // static map appointmentsList; + static map appointmentsList; static const int employeeLimit; // static const int nursesLimit; // static const int driversLimit; // static const int ambulancesLimit; - // static const int appointmentsLimit; + static const int appointmentsLimit; friend class Employee; + friend class Course; + friend class Routine; // friend class patient; // friend class nurse; // friend class driver; // friend class ambulance; - // friend class appointment; + friend class appointment; public: static void printEmployees(); // static void printPatients(); + static void printCourses(); // static void printNurses(); // static void printDrivers(); // static void printAmbulances(); - // static void printAppointments(); + static void printAppointments(); }; #endif \ No newline at end of file diff --git a/src/course.cpp b/src/course.cpp new file mode 100644 index 0000000..a7458c9 --- /dev/null +++ b/src/course.cpp @@ -0,0 +1,198 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "./../include/course.hh" +#include "./../include/table_manage.hh" + +using namespace std; + +// Course::Course(string courseId, string coursedetails) +// { +// this->courseId = courseId; +// this->courseDetails = coursedetails; +// } + +void Course::print() +{ + cout << "Course ID: " << courseId << "\n"; + cout << "Course Details: " << courseDetails << "\n"; + return; +} + +void Course::takeInput() +{ + cout << "Enter Course ID: "; + // getline(cin >> ws, courseId); + cin >> courseId; + cout << "Enter Course Details: "; + getline(cin >> ws, courseDetails); + return; +} + +string Course::addToStr(string str) +{ + stringstream s; + s << courseId << "`" << courseDetails; + string addable; + getline(s, addable); + for (auto &i : addable) + if (i == ',') + i = '^'; + return addable; +} + +void Course::strToAdd(string str) +{ + stringstream s(str); + // getline(s, courseId, '`'); + // // getline(s, courseDetails); + // for (auto &i : courseId) + // if (i == '^') + // i = ','; + // return; + cin >> courseId; + getline(s, courseDetails, '`'); +} + +void Course::saveMap() +{ + fstream f; + f.open("./data/temp.csv", ios::out); + // `le first line conataining column headers: + f << "courseId,courseName,courseDetails\n"; + for (auto i : table_manage::courseList) + f << i.second.courseId << "," << i.second.courseName << "," << i.second.courseDetails << endl; + f.close(); + remove("./data/courses.csv"); + rename("./data/temp.csv", "./data/courses.csv"); + return; +} + +void Course::addCourse() +{ + cout << "\nEnter the course name:\n"; + getline(cin >> ws, courseName); + cout << "\nEnter the course details:\n"; + getline(cin >> ws, courseDetails); + fstream f; + f.open("./data/coursesHistory.csv", ios::app); + f << courseId << "," << courseName << "," << courseDetails << "\n"; + f.close(); + + cout << "\n" + << courseId << " " << courseName << " has been successfully!\n"; + cout << "Their ID is: " << courseId << "\n"; + + return; +} + +void Course::getDetails(int rec) +{ + int opt = 0; + cout << "\nOPTIONS:\n[1]: Filter by ID\n[2]: Filter by Name\n\n"; + cin >> opt; + while (opt != 1 && opt != 2) + cout << "option 1 or 2?\n", cin >> opt; + // 1: Filter by ID; + if (opt == 1) + { + int reqId; + cout << "\nEnter ID:\n"; + cin >> reqId; + if (table_manage::courseList.find(reqId) != table_manage::courseList.end()) + *this = table_manage::courseList[reqId]; + else + cout << "\nNo matching record found!\n"; + } + // 2: Filter by name; + else if (opt == 2) + { + string reqFName, reqLName; + cout << "Name:\n"; + getline(cin >> ws, reqFName); + vector matchingRecords; + for (auto i : table_manage::courseList) + { + if (i.second.courseName == reqFName) + matchingRecords.push_back(i.second); + } + cout << "\n"; + cout << matchingRecords.size() << " matching record(s) found!\n"; + for (auto i : matchingRecords) + i.print(); + char tt = 'N'; + if (matchingRecords.size() > rec) + { + do + { + int reqId; + cout << "\nEnter the ID of the required course: "; + cin >> reqId; + if (table_manage::courseList.find(reqId) != table_manage::courseList.end()) + *this = table_manage::courseList[reqId]; + else + { + cout << "\nInvalid ID!\nTry again? (Y = Yes || N = No)\n"; + cin >> tt; + while (tt != 'Y' || tt != 'N') + cout << "Y or N?\n", cin >> tt; + } + } while (tt == 'Y'); + } + } + return; +} + +void Course::removeCourse() +{ + cout << "\nSearch for the patient you want to discharge.\n"; + getDetails(); + if (courseId == -1) + return; + // if (!hospitalized) + // { + // cout << "\nPatient wasn't hospitalized, can't be discharged!\n\n"; + // return; + // } + // hospital::patientsList.erase(id); + string s, temp; + stringstream str; + fstream f, fout; + str << courseId << courseName << "," << courseDetails << "\n"; + getline(str, s); + f.open("./data/coursesHistory.csv", ios::in); + fout.open("./data/temp.csv", ios::out); + while (getline(f, temp)) + { + if (temp == s) + { + fout << courseId << courseName << "," << courseDetails << "\n"; + } + else + fout << temp << "\n"; + } + f.close(); + fout.close(); + s.erase(); + temp.erase(); + remove("./data/coursesHistory.csv"); + rename("./data/temp.csv", "./data/coursesHistory.csv"); + cout << courseId << " " << courseName << " " << courseDetails << " deleted!\n"; + return; +} diff --git a/src/employee.cpp b/src/employee.cpp index cd88046..56a1728 100644 --- a/src/employee.cpp +++ b/src/employee.cpp @@ -1,4 +1,3 @@ -using namespace std; #include #include #include @@ -9,11 +8,13 @@ using namespace std; #include "./../include/employee.hh" #include "./../include/table_manage.hh" +using namespace std; + Employee::Employee() { id = -1; type = ""; - appointmentsBooked = 0; + classesScheduled = 0; cat = "Employee"; category = 1; } @@ -45,8 +46,8 @@ void Employee::fillMap() d.gender = s4[0]; d.age = strToNum(s5); d.addr.strToAdd(s7); - // d.appointmentsBooked = strToNum(s9); - table_manage::doctorsList[d.id] = d; + d.classesScheduled = strToNum(s9); + table_manage::employeeList[d.id] = d; } f.close(); return; @@ -56,11 +57,11 @@ void Employee::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 : table_manage::doctorsList) + f << "doctorId,firstName,lastName,gender,age,mobNumber,address,type,classesScheduled\n"; + for (auto i : table_manage::employeeList) f << i.second.id << "," << i.second.firstName << "," << i.second.lastName << "," << i.second.gender << "," << i.second.age << "," << i.second.mobNumber << "," << i.second.addr.addToStr() - << "," << i.second.type << "," << i.second.appointmentsBooked << endl; + << "," << i.second.type << "," << i.second.classesScheduled << endl; f.close(); remove("./data/Employee.csv"); rename("./data/temp.csv", "./data/Employee.csv"); @@ -68,22 +69,22 @@ void Employee::saveMap() } void Employee::addPerson() { - if (table_manage::doctorsList.size() == table_manage::doctorsLimit) + if (table_manage::employeeList.size() == table_manage::employeeLimit) { cout << "\n\nDoctors limit reached, can't addr more!\n\n"; return; } // 18 and 65 are the age limits for registration of a new Employee; - person::addPerson(18, 65); + Person::addPerson(18, 65); if ((age < 18) || (age > 65)) return; cout << "\nEnter the type of the Employee: \n"; getline(cin >> ws, type); - if (table_manage::doctorsList.rbegin() != table_manage::doctorsList.rend()) - id = ((table_manage::doctorsList.rbegin())->first) + 1; + if (table_manage::employeeList.rbegin() != table_manage::employeeList.rend()) + id = ((table_manage::employeeList.rbegin())->first) + 1; else id = 1; - table_manage::doctorsList[id] = *this; + table_manage::employeeList[id] = *this; // creating a fstream object to read/write from/to files; fstream f; @@ -102,16 +103,16 @@ void Employee::printDetails() { if (id == -1) return; - person::printDetails(); + Person::printDetails(); cout << "Type : " << type << "\n"; - cout << "Appointments : " << appointmentsBooked << "/8 (appointments booked today)\n"; + cout << "Appointments : " << classesScheduled << "/8 (appointments booked today)\n"; return; } void Employee::printDetailsFromHistory(string extraDetails) { if (id == -1) return; - person::printDetailsFromHistory(); + Person::printDetailsFromHistory(); stringstream k(extraDetails); string s1, s2; getline(k, s1, ','); @@ -167,8 +168,8 @@ void Employee::getDetails(int rec) int reqId; cout << "\nEnter ID:\n"; cin >> reqId; - if (table_manage::doctorsList.find(reqId) != table_manage::doctorsList.end()) - *this = table_manage::doctorsList[reqId]; + if (table_manage::employeeList.find(reqId) != table_manage::employeeList.end()) + *this = table_manage::employeeList[reqId]; else cout << "\nNo matching record found!\n"; } @@ -181,7 +182,7 @@ void Employee::getDetails(int rec) cout << "\nLast Name:\n"; getline(cin, reqLName); vector matchingRecords; - for (auto i : table_manage::doctorsList) + for (auto i : table_manage::employeeList) { if (i.second.firstName == reqFName && i.second.lastName == reqLName) matchingRecords.push_back(i.second); @@ -198,8 +199,8 @@ void Employee::getDetails(int rec) int reqId; cout << "\nEnter the ID of the required Employee: "; cin >> reqId; - if (table_manage::doctorsList.find(reqId) != table_manage::doctorsList.end()) - *this = table_manage::doctorsList[reqId]; + if (table_manage::employeeList.find(reqId) != table_manage::employeeList.end()) + *this = table_manage::employeeList[reqId]; else { cout << "\nInvalid ID!\nTry again? (Y = Yes || N = No)\n"; @@ -217,7 +218,7 @@ void Employee::getDetails(int rec) cout << "Enter the type of Employee required:\n"; getline(cin >> ws, reqType); vector matchingRecords; - for (auto i : table_manage::doctorsList) + for (auto i : table_manage::employeeList) { if (i.second.type == reqType) matchingRecords.push_back(i.second); @@ -233,8 +234,8 @@ void Employee::getDetails(int rec) int reqId; cout << "\nEnter the ID of the required Employee: "; cin >> reqId; - if (table_manage::doctorsList.find(reqId) != table_manage::doctorsList.end()) - *this = table_manage::doctorsList[reqId]; + if (table_manage::employeeList.find(reqId) != table_manage::employeeList.end()) + *this = table_manage::employeeList[reqId]; else { cout << "\nInvalid ID!\nTry again? (Y = Yes || N = No)\n"; @@ -355,12 +356,12 @@ void Employee::removePerson() getDetails(); if (id == -1) return; - if (appointmentsBooked > 0) + if (classesScheduled > 0) { cout << "\nSelected Employee has appointments booked for today, can't be removed.\n\n"; return; } - table_manage::doctorsList.erase(id); + table_manage::employeeList.erase(id); string s, temp; stringstream str; diff --git a/src/routine.cpp b/src/routine.cpp new file mode 100644 index 0000000..06341c3 --- /dev/null +++ b/src/routine.cpp @@ -0,0 +1,180 @@ +using namespace std; +#include +#include +#include +#include +#include + +#include "./../include/global.hh" +#include "./../include/routine.hh" +#include "./../include/employee.hh" +#include "./../include/table_manage.hh" + +Routine::Routine() +{ + id = -1; + D.id = -1; + P.courseId = -1; +} +Routine::~Routine() +{ + id = -1; + D.id = -1; + P.courseId = -1; + return; +} +void Routine::fillMap() +{ + fstream f; + f.open("./data/appointments.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)) + { + Routine a; + // creating a string stream object to read from string 'temp'; + stringstream s(temp); + string s1, s2, s3, s4, s5; + // reading from the string stream object 's'; + getline(s, s1, ','); + getline(s, s2, ','); // date is of no use here; + getline(s, s3, ','); + getline(s, s4, ','); + getline(s, s5, ','); + a.id = strToNum(s1); + a.D = table_manage::employeeList[strToNum(s3)]; + a.P = table_manage::courseList[strToNum(s4)]; + a.hh = strToNum(s5); + table_manage::appointmentsList[a.id] = a; + } + f.close(); + return; +} +void Routine::saveMap() +{ + fstream f; + f.open("./data/temp.csv", ios::out); + // `le first line conataining column headers: + f << "appointmentId,date(YYYYMMDD),doctorId,patientId,startTime(in 24-hr format)\n"; + for (auto i : table_manage::appointmentsList) + f << i.second.id << "," << yyyymmdd << "," << i.second.D.id << "," << i.second.P.courseId + << "," << i.second.hh << endl; + f.close(); + remove("./data/appointments.csv"); + rename("./data/temp.csv", "./data/courses.csv"); + return; +} +void Routine::printDetails() +{ + if (id == -1) + return; + cout << "\n\n\nAppointment Details:\nID : " << id << "\n" + << "Course Name : " + P.courseName + " " + P.courseDetails + "(ID = " << P.courseId << ")\n" + << "Employee's Name : " + D.firstName + " " + D.lastName + "(ID = " << D.id << ")\n" + << "Time (24 Hr format): " << hh << ":00 Hrs to " << hh + 1 << ":00 Hrs\n\n"; + return; +} +void Routine::book() +{ + if (table_manage::appointmentsList.size() >= 8 * table_manage::employeeList.size()) + { + cout << "\n\nSorry, no doctor is available for Routine today!\n\n"; + return; + } + cout << "\n\nIs the patient already registered (Y : Yes || N : No)?\n"; + char ans; + cin >> ans; + while (ans != 'Y' && ans != 'N') + { + cout << "Y or N?\n"; + cin >> ans; + } + if (ans == 'N') + { + cout << "Register the patient:\n"; + P.addCourse(); + } + else + { + cout << "Search for the required course:\n\n"; + ans = 'Y'; + while (ans == 'Y') + { + P.getDetails(); + ans = 'K'; + if (P.courseId == -1) + { + cout << "Try again (Y : Yes || N : No)?\n"; + cin >> ans; + while (ans != 'Y' && ans != 'N') + { + cout << "Y or N?\n"; + cin >> ans; + } + } + } + if (ans == 'N') + { + return; + } + } + cout << "\n\nNow, search for the required doctor:\n"; + ans = 'Y'; + while (ans == 'Y') + { + D.getDetails(); + ans = 'K'; + if (D.id == -1) + { + cout << "Try again (Y : Yes || N : No)?\n"; + cin >> ans; + while (ans != 'Y' && ans != 'N') + { + cout << "Y or N?\n"; + cin >> ans; + } + } + else if (D.appointmentsBooked >= 8) + { + cout << "Sorry, selected doctor has no free slot left for the day!\n"; + cout << "Search again (Y : Yes || N : No)?\n"; + cin >> ans; + while (ans != 'Y' && ans != 'N') + { + cout << "Y or N?\n"; + cin >> ans; + } + } + } + if (ans == 'N') + { + return; + } + if (table_manage::appointmentsList.rbegin() != table_manage::appointmentsList.rend()) + id = ((table_manage::appointmentsList.rbegin())->first) + 1; + else + id = 1; + hh = 9 + D.appointmentsBooked; + table_manage::appointmentsList[id] = *this; + + table_manage::doctorsList[D.id].appointmentsBooked++; + cout << "\nAppointment of patient " + P.firstName + " " + P.lastName + " with doctor " + << D.firstName << " " << D.lastName << " booked successfully!\n"; + printDetails(); + return; +} +void Routine::getDetails() +{ + cout << "\nEnter Routine ID:\n"; + cin >> id; + if (table_manage::appointmentsList.find(id) == table_manage::appointmentsList.end()) + { + cout << "\nInvalid Routine ID!\n"; + id = -1; + return; + } + *this = table_manage::appointmentsList[id]; + return; +} \ No newline at end of file diff --git a/src/table_manage.cpp b/src/table_manage.cpp index ef45f96..ecbfaf5 100644 --- a/src/table_manage.cpp +++ b/src/table_manage.cpp @@ -19,11 +19,11 @@ #include "./../include/table_manage.hh" #include "./../include/employee.hh" -// #include "./../include/patient.hh" +#include "./../include/course.hh" // #include "./../include/nurse.hh" // #include "./../include/driver.hh" // #include "./../include/ambulance.hh" -// #include "./../include/appointment.hh" +#include "./../include/routine.hh" // #include "./../include/table_manage.hh" using namespace std; @@ -44,16 +44,17 @@ bool classStandardChk(string classStandard_fname) map table_manage::employeeList; // map table_manage::patientsList; +map table_manage::courseList; // map table_manage::nursesList; // map table_manage::driversList; // map table_manage::ambulancesList; -// map table_manage::appointmentsList; +map table_manage::appointmentsList; const int table_manage::employeeLimit = 30; // const int table_manage::nursesLimit = 50; // const int table_manage::driversLimit = 30; // const int table_manage::ambulancesLimit = 30; -// const int table_manage::appointmentsLimit = 240; //per day; +const int table_manage::appointmentsLimit = 240; //per day; // ummm, patients limit, ummm, no! // appointments limit is kind of a patients limit; // rest hospitalized patients limit must be equal to; @@ -75,6 +76,12 @@ void table_manage::printEmployees() // i.second.printDetails(), cout << "\n"; // return; // } +void table_manage::printCourses() +{ + for (auto i : courseList) + i.second.print(), cout << "\n"; + return; +} // void table_manage::printNurses() // { // for (auto i : nursesList) @@ -93,9 +100,9 @@ void table_manage::printEmployees() // i.second.printDetails(), cout << "\n"; // return; // } -// void table_manage::printAppointments() -// { -// for (auto i : appointmentsList) -// i.second.printDetails(), cout << "\n"; -// return; -// } \ No newline at end of file +void table_manage::printAppointments() +{ + for (auto i : appointmentsList) + i.second.printDetails(), cout << "\n"; + return; +} \ No newline at end of file