-
Notifications
You must be signed in to change notification settings - Fork 0
/
ermodel.py
74 lines (55 loc) · 1.95 KB
/
ermodel.py
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
"""
File: ermodel.py
Author: Ken Lambert
Editor: Leigh Stauffer
Project 7
Defines the classes ERModel, Patient, and Condition for an
emergency room scheduler.
"""
from linkedpriorityqueue import LinkedPriorityQueue
class Condition(object):
"""Represents a condition."""
def __init__(self, rank):
self._rank = rank
def __eq__(self, other):
return self._rank == other._rank
def __lt__(self, other):
return self._rank < other._rank
def __le__(self, other):
return self._rank <= other._rank
def __str__(self):
"""Returns the string rep of a condition."""
if self._rank == 1: return "critical"
elif self._rank == 2: return "serious"
else: return "fair"
class Patient(object):
"""Represents a patient with a name and a condition."""
def __init__(self, name, condition):
self._name = name
self._condition = condition
def __eq__(self, other):
return self._condition == other._condition
def __lt__(self, other):
return self._condition < other._condition
def __le__(self, other):
return self._condition <= other._condition
def __str__(self):
"""Returns the string rep of a patient."""
return self._name + " / " + str(self._condition)
class ERModel(object):
"""Model of a scheduler."""
def __init__(self):
self._patients = LinkedPriorityQueue()
def isEmpty(self):
"""Returns True if there are patients in the model
or False otherwise."""
return self._patients.isEmpty()
def schedule(self, p):
"""Adds a patient to the schedule."""
self._patients.add(p)
def treatNext(self):
"""Returns the patient treated or None if there are none."""
if self._patients.isEmpty():
return None
else:
return self._patients.pop()