帮我用python写一下代码,实现检查诊室分诊排号系统
时间: 2024-09-12 12:12:25 浏览: 60
在Python中,我们可以创建一个简单的诊室分诊排号系统的模拟。这里是一个基本的框架,使用了字典来存储患者信息和诊室状态:
```python
class Patient:
def __init__(self, name):
self.name = name
self.waiting = True
class Room:
def __init__(self, id):
self.id = id
self.patients = []
self.free = True
def check_in(patient, rooms):
for room in rooms.values():
if room.free:
room.patients.append(patient)
patient.waiting = False
room.free = False
print(f"{patient.name}已进入房间{room.id}")
break
def check_out(patient_name, rooms):
for room in rooms.values():
if any(p.name == patient_name for p in room.patients):
room.patients = [p for p in room.patients if p.name != patient_name]
room.free = True
print(f"{patient_name}离开房间{room.id}")
break
# 初始化诊室和患者
rooms = {1: Room(1), 2: Room(2)}
patients = ['Patient1', 'Patient2', 'Patient3']
for patient in patients:
check_in(Patient(patient), rooms)
# 模拟就诊过程
for i in range(5): # 假设每个患者需要5分钟就诊
print("当前时间:", i * 5)
for room_id, room in rooms.items():
if not room.free:
for patient in room.patients:
if patient.waiting:
print(f"病房{room_id}: {patient.name}正在就诊")
time.sleep(5) # 模拟就诊时间
check_out(patient.name, rooms)
```
这个代码演示了一个简单的流程:患者挂号、分配到空闲的诊室、就诊并离开。注意,这只是一个基础模型,实际的系统可能会更复杂,包括数据库操作、并发控制等。
阅读全文