-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathWICPS.cpp
More file actions
183 lines (155 loc) · 5.52 KB
/
WICPS.cpp
File metadata and controls
183 lines (155 loc) · 5.52 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
#include <iostream>
#include "Patient.h"
#include "List.h"
using namespace std;
// Adds a new Patient to the system
void add(List& patients){
string input = "";
cout << "Please enter a 10-digit care-card number for the new patient" << endl;
cout << ">> ";
cin >> input;
Patient newPat = Patient(input);
bool check = patients.insert(newPat);
if (!check) {
cout << "Something went wrong!" << endl;
} else {
cout << "Patient added successfully!" << endl;
patients.printList();
}
}
void remove(List& patients){
string input;
cout << "Please enter the 10-digit care-card number of the patient to be removed" << endl;
cout << ">> ";
cin >> input;
Patient patToRemove = Patient(input);
bool check = patients.remove(patToRemove);
if (!check) {
cout << "Something went wrong!" << endl;
} else {
cout << "Patient removed successfully!" << endl;
patients.printList();
}
}
void update(List& patients){
// first find the patient
string input;
cout << "Please enter a 10-digit care-card number" << endl;
cout << ">> ";
cin >> input;
Patient patToFind = Patient(input);
Patient * patient = patients.search(patToFind);
// Now deal with if the user was found or not
if (patient == NULL) {
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;
}
}
}
}
void search(List& patients){
string input;
cout << "Please enter a 10-digit care-card number to find the patient" << endl;
cout << ">> ";
cin >> input;
Patient patToFind = Patient(input);
Patient * patient = patients.search(patToFind);
if (patient == NULL) {
cout << "Unable to find patient in the database" << endl;
} else {
cout << "This patient does exist in the database" << endl;
}
}
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();
}
}
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;
// 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 'x': cout << "\n----Bye!\n" << endl; done = true; break;
default: cout << "Not sure what you mean! Please, try again!" << endl;
}
}
return 0;
}