数据结构接种疫苗信息管理系统
时间: 2023-12-30 09:24:43 浏览: 107
新冠疫苗接种信息系统数据采集内容.docx
数据结构在接种疫苗信息管理系统中起着重要的作用。它可以帮助我们有效地组织和管理大量的数据,以便快速地进行查询和操作。以下是一个简单的数据结构示例,用于管理接种疫苗的信息:
```python
class Vaccine:
def __init__(self, name, manufacturer, dosage):
self.name = name
self.manufacturer = manufacturer
self.dosage = dosage
class VaccinationRecord:
def __init__(self, user_id, vaccine, date):
self.user_id = user_id
self.vaccine = vaccine
self.date = date
class VaccinationSystem:
def __init__(self):
self.vaccines = []
self.records = []
def add_vaccine(self, name, manufacturer, dosage):
vaccine = Vaccine(name, manufacturer, dosage)
self.vaccines.append(vaccine)
def add_vaccination_record(self, user_id, vaccine_name, date):
vaccine = next((v for v in self.vaccines if v.name == vaccine_name), None)
if vaccine:
record = VaccinationRecord(user_id, vaccine, date)
self.records.append(record)
def get_vaccination_records(self, user_id):
return [r for r in self.records if r.user_id == user_id]
```
使用上述数据结构,我们可以进行以下操作:
1. 添加疫苗信息:
```python
system = VaccinationSystem()
system.add_vaccine("COVID-19", "Pfizer", "2 doses")
system.add_vaccine("Flu", "AstraZeneca", "1 dose")
```
2. 添加接种记录:
```python
system.add_vaccination_record("user1", "COVID-19", "2021-01-01")
system.add_vaccination_record("user2", "Flu", "2021-02-01")
```
3. 获取某个用户的接种记录:
```python
records = system.get_vaccination_records("user1")
for record in records:
print(f"User ID: {record.user_id}, Vaccine: {record.vaccine.name}, Date: {record.date}")
```
这样,我们就可以使用数据结构来管理接种疫苗的信息,并进行相应的操作。
阅读全文