-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTaskManager.cpp
More file actions
145 lines (128 loc) · 4.4 KB
/
Copy pathTaskManager.cpp
File metadata and controls
145 lines (128 loc) · 4.4 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
#include "TaskManager.hpp"
#include "HashMap.h"
#include "Patient.cpp"
bool TaskManager::patientExists(int id) const
{
Patient *result = patientMap.searchDouble(id);
return result != nullptr; // Check if the pointer is valid
}
void TaskManager::addPatient(const string &name, int id, int age, int urgencyScore, const string &description)
{
if (patientExists(id))
{
cerr << "Patient with ID " << id << " already exists.\n";
return;
}
Patient *newPatient = new Patient(name, id, age, urgencyScore, description);
patientHeap.insert(*newPatient); // Insert by value into the heap
patientMap.insertDouble(newPatient->getId(), newPatient);
listAllPatients(); // Store the pointer in the map
cout << "Patient added successfully!\n";
}
void TaskManager::processNextPatient()
{
if (patientHeap.isEmpty())
{
cerr << "No patients in the queue.\n";
return;
}
Patient nextPatient = patientHeap.extractMin(); // Extract by value
patientMap.removeDouble(nextPatient.getId()); // Remove from map
cout << "Processing next patient:\n"
<< nextPatient << "\n";
listAllPatients();
}
void TaskManager::viewTopPatient()
{
if (patientHeap.isEmpty())
{
cerr << "No patients in the queue.\n";
return;
}
cout << "Next patient to be treated:\n"
<< patientHeap.getMin() << "\n";
}
void TaskManager::listAllPatients()
{
if (patientHeap.isEmpty())
{
cerr << "No patients in the queue.\n";
return;
}
cout << "All patients in the queue:\n";
patientHeap.print();
}
void TaskManager::findPatient(int id) const
{
if (!patientExists(id))
{
cerr << "Patient with ID " << id << " not found.\n";
return;
}
Patient *patient = patientMap.searchDouble(id); // Access the pointer from the map
cout << "Patient found:\n"
<< *patient << "\n";
}
void TaskManager::deletePatient(int id)
{
if (!patientExists(id))
{
cerr << "Patient with ID " << id << " not found.\n";
return;
}
Patient *patient = patientMap.searchDouble(id);
patientMap.removeDouble(patient->getId()); // Remove from the map
delete patient; // Free the memory
cout << "Patient with ID " << id << " deleted successfully.\n";
listAllPatients();
}
void TaskManager::increaseUrgency(int id, int newUrgencyScore)
{
if (!patientExists(id))
{
cerr << "Patient with ID " << id << " not found.\n";
return;
}
Patient *patient = patientMap.searchDouble(id);
Patient updatedPatient(*patient); // Create a copy for updating
if (newUrgencyScore <= updatedPatient.getUrgencyScore())
{
cerr << "New urgency score must be higher than the current urgency score.\n";
return;
}
updatedPatient.updateUrgencyScore(newUrgencyScore); // Update urgency score
patientHeap.decreaseKey(*patient, updatedPatient); // Update in heap
cout << "Urgency score for patient ID " << id << " increased successfully.\n";
listAllPatients();
}
// int main()
// {
// TaskManager tm;
// // Add patients
// tm.addPatient("John Doe", 10001, 90, 5, "Flu");
// tm.addPatient("Jane Smith", 10002, 25, 2, "Cold");
// tm.addPatient("Alice Johnson", 10003, 40, 4, "Broken leg");
// tm.addPatient("Bob Brown", 10004, 50, 2, "Heart attack");
// tm.addPatient("Eve Davis", 10005, 60, 4, "Stroke");
// // List all patients
// cout << "Listing all patients:\n";
// tm.listAllPatients();
// // // cout << "\nViewing top patient:\n";
// // // tm.viewTopPatient();
// // // cout << "\nProcessing next patient:\n";
// // // tm.processNextPatient();
// // // cout << "\nListing all patients after processing one:\n";
// // // tm.listAllPatients();
// // // cout << "\nFinding a specific patient with ID 10001:\n";
// // // tm.findPatient(10002);
// cout << "\nIncreasing urgency score of patient with ID 10002:\n";
// tm.increaseUrgency(10002, 5);
// // // cout << "\nViewing top patient after increasing urgency score:\n";
// // // tm.viewTopPatient();
// // // cout << "\nDeleting patient with ID 10003:\n";
// // // tm.deletePatient(10003);
// cout << "\nListing all patients after deletion:\n";
// tm.listAllPatients();
// // return 0;
// //
// }