-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWICPS.cpp
More file actions
251 lines (210 loc) · 7.82 KB
/
WICPS.cpp
File metadata and controls
251 lines (210 loc) · 7.82 KB
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
/*
* WICPS.cpp
*
* Description: Manages Patients with a database
*
* Last modified on: May 2017
* Author: Brendin Green
*/
#include <iostream>
#include "Patient.h"
#include "List.h"
using namespace std;
// Adds a new Patient to the system
void add(List& patients){
bool correctlyEntered = false;
while (!correctlyEntered) {
string input = "";
cout << "Please enter a 10-digit care-card number for the new patient" << endl;
cout << ">> ";
cin >> input;
if (input.length() != 10) {
cout << "Please make sure your care card number is ten (10) digits long. " << endl;
} else {
Patient newPat = Patient(input);
bool check = patients.insert(newPat);
if (!check) {
cout << "Something went wrong!" << endl;
} else {
cout << "Patient added successfully!" << endl;
patients.printList();
}
correctlyEntered = true;
}
}
}
void remove(List& patients){
bool correctlyEntered = false;
while (!correctlyEntered) {
string input = "";
cout << "Please enter the 10-digit care-card number of the patient to be removed" << endl;
cout << ">> ";
cin >> input;
if (input.length() != 10) {
cout << "Please make sure your care card number is ten (10) digits long. " << endl;
} else {
Patient patToRemove = Patient(input);
bool check = patients.remove(patToRemove);
if (!check) {
cout << "Something went wrong!" << endl;
} else {
cout << "Patient removed successfully!" << endl;
patients.printList();
}
correctlyEntered = true;
}
}
}
// updates patient
void update(List& patients){
bool enteredCorrectly = false;
while (not enteredCorrectly) {
// first find the patient
string input = "";
cout << "Please enter a 10-digit care-card number" << endl;
cout << ">> ";
cin >> input;
if (input.length() != 10){
cout << "Please make sure your care card number is ten (10) digits long. " << endl;
} else {
Patient patToFind = Patient(input);
Patient * patient = patients.search(patToFind);
enteredCorrectly = true;
// Now deal with if the user was found or not
if (!patient) {
cout << "Unable to find patient in the database, try again\n" << endl;
} else {
// Deal with updating the patient
bool editDone = false;
while (not editDone) {
char editInput = 0;
string inputValue = "";
cout << "What would you like to change?" << endl;
cout << "(n) Name" << endl;
cout << "(e) Email" << endl;
cout << "(p) Phone" << endl;
cout << "(a) Address" << endl;
cout << "(x) End editing patient" << endl;
cout << ">>";
cin >> editInput;
cin.ignore();
switch (tolower(editInput)) {
case 'n' :
cout << "Enter a new name" << endl;
cout << ">>";
getline(cin, inputValue);
patient->setName(inputValue);
break;
case 'e':
cout << "Enter a new email" << endl;
cout << ">>";
cin >> inputValue;
patient->setEmail(inputValue);
break;
case 'p':
cout << "Enter a new phone number" << endl;
cout << ">>";
getline(cin, inputValue);
patient->setPhone(inputValue);
break;
case 'a':
cout << "Enter a new address" << endl;
cout << ">>";
getline(cin, inputValue);
patient->setAddress(inputValue);
break;
case 'x':
cout << "The patient is now: ";
patient->printPatient();
editDone = true;
break;
default:
cout << "That is not one of the options, try again" << endl;
}
}
}
}
}
}
// finds patient
void search(List& patients){
bool enteredCorrectly = false;
while (not enteredCorrectly) {
string input = "";
cout << "Please enter a 10-digit care-card number to find the patient" << endl;
cout << ">> ";
cin >> input;
if (input.length() != 10){
cout << "Please make sure your care card number is ten (10) digits long. " << endl;
} else {
Patient patToFind = Patient(input);
Patient * patient = patients.search(patToFind);
if (!patient) {
cout << "Unable to find patient in the database" << endl;
} else {
cout << "This patient does exist in the database" << endl;
}
enteredCorrectly = true;
}
}
}
// prints all patients
void print(List& patients){
if (patients.getElementCount() == 0){
cout << "There are currently no patients within the database" << endl;
} else {
cout << "Our database includes: " << endl;
patients.printList();
}
}
// deletes all entries
void drop(List& patients) {
if (patients.getElementCount() == 0){
cout << "Database is already empty" << endl;
} else {
patients.removeAll();
cout << "Database dropped!" << endl;
}
}
int main() {
// Variables declaration
List patients = List();
bool done = false;
char input = 0;
// Print menu to user
cout << "\n----Welcome to the Walk in Clinic Patient Service!\n" << endl;
// Keep doing what the user selects until the user exits
while (not done) {
cout << "--------------------------------------------------------" << endl;
// Add a patient
cout << "To add a patient to the database, enter: a" << endl;
// Remove a patient
cout << "To remove a patient from the database, enter: r" << endl;
// Edit a patient
cout << "To update a patient's details, enter: u" << endl;
// Search for a patient
cout << "To check to see if a patient exists, enter: s" << endl;
// print all
cout << "To show all patients in the database, enter: p" << endl;
// print all
cout << "To drop patients from database, enter: d" << endl;
// to leave
cout << "To exit, enter: x" << endl;
cout << "--------------------------------------------------------" << endl;
cout << "Your choice" << endl;
cout << ">>";
cin >> input;
cout << "--------------------------------------------------------" << endl;
switch(tolower(input)) {
case 'a': add(patients); break;
case 'r': remove(patients); break;
case 'u': update(patients); break;
case 's': search(patients); break;
case 'p': print(patients); break;
case 'd': drop(patients); break;
case 'x': cout << "\n----Bye!\n" << endl; done = true; break;
default: cout << "Not sure what you mean! Please, try again!" << endl;
}
}
return 0;
}