-
Notifications
You must be signed in to change notification settings - Fork 0
/
PatientQueue.java
203 lines (166 loc) · 6.42 KB
/
PatientQueue.java
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
import java.util.Queue;
import java.util.PriorityQueue;
import java.util.*;
public class PatientQueue {
private int max_number_of_users;
private int current_user_count;
private int total_wait_time;
//private Queue<User> users;
private PriorityQueue<User> users = new PriorityQueue<>();
public PatientQueue() {
this.max_number_of_users = Integer.MAX_VALUE;
this.current_user_count = 0;
this.total_wait_time = 0;
}
public PatientQueue(int max_number_of_users) {
this.max_number_of_users = max_number_of_users;
this.current_user_count = 0;
this.total_wait_time = 0;
}
public PatientQueue(int max_number_of_users, int current_user_count, int total_wait_time, PriorityQueue<User> users) {
this.max_number_of_users = max_number_of_users;
this.current_user_count = current_user_count;
this.total_wait_time = total_wait_time;
this.users = users;
}
public int getMax_number_of_users() {
return max_number_of_users;
}
public void setMax_number_of_users(int max_number_of_users) {
this.max_number_of_users = max_number_of_users;
}
public int getCurrent_user_count() {
return current_user_count;
}
public void setCurrent_user_count(int current_user_count) {
this.current_user_count = current_user_count;
}
public int getTotal_wait_time() {
return total_wait_time;
}
public void setTotal_wait_time(int total_wait_time) {
this.total_wait_time = total_wait_time;
}
public Queue<User> getUsers() {
return users;
}
public void setUsers(PriorityQueue<User> users) {
this.users = users;
}
// ------------------------------------------------------------
public boolean room_for_more_patients() {
return this.current_user_count < this.max_number_of_users;
}
public void add_user(User u) {
/**
* New patient arrives in this queue, updating the current variables accordingly
*
* @Param User: new user to be added to the queue
*/
this.users.add(u);
this.current_user_count += 1;
this.total_wait_time += u.getService_time();
}
public User get_next_user() {
/**
* Take the next user waiting in line. Since patients are non-critical, it is a FIFO system queue.
*
* @return User: User object of next person in line
*/
User next_user = this.users.peek();
if (next_user != null){
this.users.remove();
this.current_user_count -= 1;
this.total_wait_time -= next_user.getService_time();
return next_user;
} else {
return null;
}
}
private long getTotalWaitTime() {
long total_wait_times = 0;
for (User usr: users) {
total_wait_times += usr.getTime_waited();
}
return total_wait_times;
}
private long getTotalInterarrivalTime() {
long total_interarrival_time = 0;
for (User usr: users) {
total_interarrival_time += usr.getInterarrivalTime();
}
return total_interarrival_time;
}
// Calculates total service time in of the queue given a severity.
// If severity = 0, returns total service time of the entire queue
private long getTotalServiceTime(int severity) {
long total_service_times = 0;
for (User usr: users) {
if (severity == 0 || severity == usr.getSeverity()) {
total_service_times += usr.getTime_serviced();
}
}
return total_service_times;
}
// Calculates total time to doctor of the queue given a severity.
// If severity = 0, returns total service time of the entire queue
private long getTotalTimeToDoctor(int severity) {
long total_time_to_doctor = 0;
for (User usr: users) {
if (severity == 0 || severity == usr.getSeverity()) {
total_time_to_doctor += usr.getTimeToDoctor();
}
}
return total_time_to_doctor;
}
// Calculates total time in the ED of the queue given a severity.
// If severity = 0, returns total service time of the entire queue
private long getTotalTimeInED(int severity) {
long total_time_in_ED = 0;
for (User usr: users) {
if (severity == 0 || severity == usr.getSeverity()) {
total_time_in_ED += usr.getTimeInED();
}
}
return total_time_in_ED;
}
// Gets user count in of the queue given a severity.
// If severity = 0, returns user count of the entire queue
private long getUserCount(int severity) {
long usr_count = 0;
for (User usr: users) {
if (severity == 0 || severity == usr.getSeverity()) {
usr_count++;
}
}
return usr_count;
}
public String toString() {
String msg = "";
if (getUserCount(0) != 0) {
msg += "Total User Data:\n";
msg += String.format(" Users Served: %s\n", getUserCount(0));
msg += String.format(" Average Time To Doctor: %s\n", getTotalTimeToDoctor(0)/getUserCount(0));
msg += String.format(" Average Time in ED: %s\n", getTotalTimeInED(0)/getUserCount(0));
msg += String.format(" Average Interarrival Time: %s\n", getTotalInterarrivalTime()/getUserCount(0));
msg += String.format(" Average Wait Time: %s\n", getTotalWaitTime()/getUserCount(0));
msg += String.format(" Average Service Time: %s\n\n", getTotalServiceTime(0)/getUserCount(0));
}
else {
msg += String.format(" No Users Were Served\n\n");
}
for (int i = 1; i <= 5; i++) {
if (getUserCount(i) != 0) {
msg += String.format("CTAS %s User Data:\n", i);
msg += String.format(" Users Served: %s\n", getUserCount(i));
msg += String.format(" Average Time To Doctor: %s\n", getTotalTimeToDoctor(i)/getUserCount(i));
msg += String.format(" Average Time in ED: %s\n", getTotalTimeInED(i)/getUserCount(i));
msg += String.format(" Average Service Time: %s\n\n", getTotalServiceTime(i)/getUserCount(i));
}
else {
msg += String.format("No users at CTAS %s were served\n\n", i);
}
}
return msg;
}
}