-
Notifications
You must be signed in to change notification settings - Fork 0
/
Appointment_add.cpp
91 lines (79 loc) · 2.25 KB
/
Appointment_add.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include "Appointment.hpp"
void Appointment::add() {
bool success;
string input;
DateTime startTime = DateTime();
DateTime endTime = DateTime();
do {
do {
cout << "Input start time (YYYY/MM/DD HH:MM): ";
getline(cin, input);
success = startTime.setTime(input);
if (success)
continue;
cout << "Error: Inputted date is invalid, please try again.\n";
} while (!success);
do {
cout << "Input end time (YYYY/MM/DD HH:MM): ";
getline(cin, input);
success = endTime.setTime(input) && endTime.getTime() > startTime.getTime();
if (success)
continue;
cout << "Error: Inputted date is invalid, please try again.\n";
} while (!success);
} while (!checkConflict(startTime, endTime));
// Check time conflict before continuing
int doctorID;
string doctorName;
string patientID;
string patientName;
string description;
do {
cout << "Input Doctor ID: ";
getline(std::cin, input);
success = regex_match(input, regex("^[0-9]+$"));
if (success) {
doctorID = stoi(input);
continue;
}
cout << "Error: Invalid input, please try again.\n\n";
} while (!success);
do {
cout << "Input Doctor Name: ";
getline(std::cin, doctorName);
success = !(doctorName.empty());
if (success)
continue;
cout << "Error: Invalid input, please try again.\n\n";
} while (!success);
do {
cout << "Input Patient NRIC (without symbols): ";
getline(std::cin, patientID);
success = regex_match(patientID, regex("^[0-9]{12}$"));
if (success)
continue;
cout << "Error: Invalid input, please try again.\n\n";
} while (!success);
do {
cout << "Input Patient Name: ";
getline(std::cin, patientName);
success = !(patientName.empty());
if (success)
continue;
cout << "Error: Invalid input, please try again.\n\n";
} while (!success);
do {
cout << "Input Description: ";
getline(std::cin, description);
success = !(description.empty());
if (success)
continue;
cout << "Error: Invalid input, please try again.\n\n";
} while (!success);
AppointmentEntry newAppointment = AppointmentEntry(startTime, endTime, patientID, patientName, doctorID, doctorName, description);
addAppointmentMode(newAppointment);
save();
cout << "Appointment added successfully.\n"
<< "Press any key to continue.";
cin.ignore();
}