Consider the following information about the pharmacies, patients and drugs: ● (1) Patients are identified by an SSN, and their names, addresses, and ages must be recorded. ● (2) Doctors are identified by an SSN. For each doctor, the name, specialty, and years of experience must be recorded. ● (3) Each pharmaceutical company (制药公司) is identified by name and has a phone number. ● (4) For each drug, the trade name and formula(成份)must be recorded. Each drug is produced by a given pharmaceutical company, and the trade name identifies a drug uniquely from among the products of that company. ● (5) Each pharmacy(药房) has a name, address, and phone number. Each pharmacy is identified by ID. ●(6) Every patient has a primary doctor. Every doctor has at least one patient. ● (7) Each pharmacy sells several drugs and has a price for each. A drug could be sold at several pharmacies, and the price could vary from one pharmacy to another. ● (8) Doctors prescribe drugs for patients. A doctor could prescribe one or more drugs for several patients, and a patient could obtain prescriptions from several doctors. Each prescription has a date and a quantity associated with it. ●(9) Pharmaceutical companies have long term contracts with pharmacies. A pharmaceutical company can contract with several pharmacies, and a pharmacy can contract with several pharmaceutical companies. For each contract, you have to store a start date, an end date. 用ER图进行描述用python代码表示
时间: 2023-07-02 10:11:50 浏览: 193
根据上述信息,可以设计以下实体和关系:
实体:
- Patient (SSN, Name, Address, Age)
- Doctor (SSN, Name, Specialty, Years of Experience)
- Pharmaceutical Company (Name, Phone Number)
- Drug (Trade Name, Formula)
- Pharmacy (ID, Name, Address, Phone Number)
关系:
- Produces (Pharmaceutical Company, Trade Name)
- Sells (Pharmacy, Trade Name, Price)
- Prescribes (Doctor, SSN, Trade Name, Patient, SSN, Date, Quantity)
- Contracts (Pharmaceutical Company, Pharmacy, Start Date, End Date)
- Has Primary Doctor (Patient, SSN, Doctor, SSN)
以下是用Python代码表示的实体和关系:
```python
# 实体类
class Patient:
def __init__(self, ssn, name, address, age):
self.ssn = ssn
self.name = name
self.address = address
self.age = age
class Doctor:
def __init__(self, ssn, name, specialty, years_of_experience):
self.ssn = ssn
self.name = name
self.specialty = specialty
self.years_of_experience = years_of_experience
class PharmaceuticalCompany:
def __init__(self, name, phone_number):
self.name = name
self.phone_number = phone_number
class Drug:
def __init__(self, trade_name, formula, pharmaceutical_company):
self.trade_name = trade_name
self.formula = formula
self.pharmaceutical_company = pharmaceutical_company
class Pharmacy:
def __init__(self, id, name, address, phone_number):
self.id = id
self.name = name
self.address = address
self.phone_number = phone_number
# 关系类
class Produces:
def __init__(self, pharmaceutical_company, drug):
self.pharmaceutical_company = pharmaceutical_company
self.drug = drug
class Sells:
def __init__(self, pharmacy, drug, price):
self.pharmacy = pharmacy
self.drug = drug
self.price = price
class Prescribes:
def __init__(self, doctor, patient, drug, date, quantity):
self.doctor = doctor
self.patient = patient
self.drug = drug
self.date = date
self.quantity = quantity
class Contracts:
def __init__(self, pharmaceutical_company, pharmacy, start_date, end_date):
self.pharmaceutical_company = pharmaceutical_company
self.pharmacy = pharmacy
self.start_date = start_date
self.end_date = end_date
class HasPrimaryDoctor:
def __init__(self, patient, doctor):
self.patient = patient
self.doctor = doctor
```
注意:上述代码只是一种示例实现,具体实现方式可能会因具体情况而有所不同。
阅读全文