-
Notifications
You must be signed in to change notification settings - Fork 0
/
erapp1.py
87 lines (72 loc) · 2.6 KB
/
erapp1.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
75
76
77
78
79
80
81
82
83
84
85
86
87
"""
File: erapp1.py
Author: Ken Lambert
Editor: Leigh Stauffer
Project 7
A terminal-based view for an emergency room scheduler.
"""
from ermodel import ERModel, Patient, Condition
class ERView(object):
"""The view class for the ER application."""
def __init__(self, model):
self.model = model
def run(self):
"""Menu-driven command loop for the app."""
menu = "Main menu\n" + \
" 1 Schedule a patient\n" + \
" 2 Treat the next patient\n" + \
" 3 Treat all patients\n" \
" 4 Exit the program\n"
while True:
command = self.getCommand(4, menu)
if command == 1: self.schedule()
elif command == 2: self.treatNext()
elif command == 3: self.treatAll()
else: break
def treatNext(self):
"""Treats one patient if there is one."""
if self.model.isEmpty():
print("No patients available to treat")
else:
patient = self.model.treatNext()
print(patient, "is being treated")
def treatAll(self):
"""Treats all the remaining patients."""
if self.model.isEmpty():
print("No patients available to treat")
else:
while not self.model.isEmpty():
self.treatNext()
def schedule(self):
"""Obtains patient info and schedules patient."""
name = input("\nEnter the patient's name: ")
condition = self.getCondition()
self.model.schedule(Patient(name, condition))
print(name, "is added to the", condition, "list\n")
def getCondition(self):
"""Obtains condition info."""
menu = "Patient's condition:\n" + \
" 1 Critical\n" + \
" 2 Serious\n" + \
" 3 Fair\n"
number = self.getCommand(3, menu)
return Condition(number)
def getCommand(self, high, menu):
"""Obtains and returns a command number."""
prompt = "Enter a number [1-" + str(high) + "]: "
commandRange = list(map(str, range(1, high + 1)))
error = "Error, number must be 1 to " + str(high)
while True:
print(menu)
command = input(prompt)
if command in commandRange:
return int(command)
else:
print(error)
# Main function to start up the application
def main():
model = ERModel()
view = ERView(model)
view.run()
if __name__ == "__main__":
main()