hospital management system database design- project report
TRANSCRIPT
Project for Database Design—Phase IV Dec-9-2013
Page 1 of 41
Database Design Project
Phase 4: Final Report
Charlie Chen [email protected]
Harichandan Roy [email protected]
Trung Pham [email protected]
Project for Database Design—Phase IV Dec-9-2013
Page 2 of 41
0. Pre-Illumination In this project report we will follow the requirement of Phase IV directly. In Section 1, we give problem description copied from Web site. In Section 2, we answer 3 questions listed in the project and justified our solution. In Section 3, we exhibit the EER diagram with all assumptions In Section 4, we show our relational schema after normalization. In Section 5, we give all requested SQL statements for both views and queries In Section 6 we give dependency diagram induced from relational schemas. Finally, a short summary is given at the end of this report.
Project for Database Design—Phase IV Dec-9-2013
Page 3 of 41
1. Problem Description Design, develop, and test Hospital Management System to maintain the records of various departments, staff, and patients in the hospital based on combined database. The project is in four parts: conceptual database design (Phase I), logical database design (Phase II), Oracle relational database implementation (Phase III), and final report &demo (Phase IV). MM hospital is a full-service medical facility with numbers of staff including doctors, nurses, receptionists, pharmacists, and support staff. Patients having different kinds of ailments come to the hospital and get checkup done from the concerned doctors. They can also schedule treatment either online or by calling the receptionists. If required they are admitted as in-patients in the hospital and discharged after all services.
1) Each employee’s information contains ID, Name, SSN, Gender, Age, Title, Department(s), Date of Join, Salary, Address (address line 1, address line 2, city, state, zipcode), Phone_Number (one individual may have more than one phone number) and Email.
Doctors write prescriptions (including RX#, Description for drug uses) for all patients. For each doctor, the system records Level (1-5), Medical School, Language(s), and Specialty (Cardiology, Family Practice, Nephrology, Infertility, etc.). One doctor may know multiple languages and have multiple specialties. The language that each nurse speaks is also recorded respectively. Doctors and nurses are responsible for all patients’ surgery and test treatments (see details in (4)).
Receptionists are responsible for calling treatment appointments for all patients.
Pharmacists are responsible for dispensing prescribed medications to patients. The system records the Degree for each pharmacist, and tracks the Dispense_Date for each filling service.
Support staffs in the hospital are divided into part-time staff and full-time staff. For part-time staff, the number of work hours per week is recorded. One support staff can also be a volunteer. For all volunteers, their available weekday and time-slots should be recorded. For safety, the age of each volunteer cannot be over 75.
2) Information describing the department of the hospital is recorded: Department ID,
Department Name, Locations, and Phone number. Each department has at least one manager who works in this department.
3) Patients of the hospital can be divided into in-patients and out-patients (or both). For
each patient, the system keeps track of the following information: ID (like "mxl000001", unique), Last Name, First Name, DOB, Gender, Chief Reason for Visit, Name of driver to transport home,
Telephone Number(s), Address (address line 1, address line 2, city, state, zipcode), Email, Language(s), and Medical History. Particularly, SSNs are required for all in-patients.
The system will assign a unique ID to each patient generated by picking out the first letter of the first name and the last name with a randomly generated letter in the middle, then, putting a randomly generated integer with six digits at the end. For example, for the person named Mary Lee, the id can be "mxl000001", where x and 000001 are randomly generated.
Project for Database Design—Phase IV Dec-9-2013
Page 4 of 41
Receptionists serve all patients then arrange the corresponding doctors or nurses for the patients in need. All treatments must be given by either doctors, nurses, or both. The system records the fee and the result for each treatment. A Patient may visit the hospital many times for different reasons, and the system tracks the corresponding receptionist and doctor (or nurse, if any), the date and the time for each visit. The system also keeps track of the insurance information (Policy#, Company Name, Phone, and Expired Data) for all insured patients. It is assumed that for different companies the policy# may be the same, and one particular insurance record may cover different patients. Each patient can be insured by maximum 3 insurance companies.
4) For all patients, the hospital offers treatment scheduling either online or by calling the
receptionists. For each calling appointment, the system keeps track of the receptionist information along with the calling date as well. For each appointment, Name of ordering doctors (if known), Treatment_type (can only be "surgery" or "test"), Scheduled_Date, and Scheduled_Time are recorded. The patient in need, the Scheduled_Date, and Scheduled_Time together determine one unique appointment.
5) Ambulances service is provided for all patients. Each ambulance has a unique License
Number, a Stored-In Date, and a Location. DL # of an ambulance driver who belongs to support staff is recorded. For each detachment, the system keeps track of Start-time, End-time, along with the carried patient (s) (no more than 5).
6) Medicines stored in the hospital can be tracked in the system also. Each kind of
medicine's information contains ID, Name, Price, Stored-In Date, Quantity, and Type (Rx or Non-prescription). Pharmacists fill all prescriptions for the patients, and the corresponding dates are recorded.
7) Each in-patient is assigned one particular bed during unique time period. Each Bed has
an ID_no, a Room_no (not unique). The value of ID_no is between “001” and “500”. The specified start time and end time for each bed assignment can be tracked.
8) After his/her visit, a patient may receive bills from several providers, such as prescription,
treatment, ambulances, ward (Bed), and pharmacy. Besides the patient information in (3), the hospital also needs the following financial information for all billed patients: Account Number, Account Holder, Bank Name, Billing-Address, and Expired Date. The system tracks the status (Paid, Unpaid) for all billing information.
9) The hospital often holds special events of different themes for its patients, like cancer
support, childbirth class etc. Each event has a unique Name, Held time, and a Description. The event holders can be employees or volunteers. An event may be held in different cities. Thus, the system needs to record the holders, city (or cities) for each event. All patients including their relatives can attend any event they are interested in, while a relative is an individual attendee. And the attendees need evaluate the events they attend. The evaluation score varies from 0 to 100. The system only records the Names of all relatives. For different patients their relatives’ names may be the same.
Project for Database Design—Phase IV Dec-9-2013
Page 5 of 41
2. Phase 4 Questions
2.1 Is the ability to model super-class/subclass relationships likely to be important in such environment? Why or why not? Modeling super-class/subclass relationships is very important in this project, as multiple entities exercise the IS-A relationship. Specifically, in this project the entities Managers, Doctors, Nurses, Pharmacist, Receptionists, and Support Staffs are all subclasses of the entity Employee, because they all exercise the IS-A relation with Employee. For the same reason, Part-Time Staff, Full-Time Staff, Volunteer, and Driver are subclasses of Support Staff. Without the use of super-class/subclass relationships, the database systems will be extremely redundant. For examples, in the absence of the super-class/subclass relationships, the relations Manager, Doctors, Nurse, Pharmacist, Receptionists, and Support Staffs must then all contain the attributes name, ssn, gender, age, title, and all other attributes that Employee once contained. This is a poor inconsistent design with a waste of memory space.
2.2 Can you think 5 more rules (other than the one explicitly described above) that are likely to be used in a hospital.
1. All doctors with less than 5 years of working experience cannot do more than 3 surgeries per week.
2. Reputation of a doctor is evaluated by the satisfaction of the patients who they service and any doctor after 3 years period of experience can be considered for a promotion package.
3. Patients have the option to finance their payment on the credit level. 4. Only doctors with a certain degree of specializations can do certain surgery treatment
types. 5. Maximum duration for any bed service is dependent on the level of treatment type of its
patient.
2.3 Justify using a Relational DBMS like Oracle for this project. We have implemented our database system using the concept of relations. Since Oracle is a relational database system, it is perfectly justified to be the DBMS for project implementation.
Project for Database Design—Phase IV Dec-9-2013
Page 6 of 41
3. EER diagram with all assumptions This section presents the final relational schema in 3NF as well as any assumptions made when constructing the schema. The formats for all relations are also resented.
Project for Database Design—Phase IV Dec-9-2013
Page 7 of 41
3.1 EER Diagram
← See Next Page for EER Diagram →
Project for Database Design—Phase IV Dec-9-2013
Page 8 of 41
Project for Database Design—Phase IV Dec-9-2013
Page 9 of 41
3.2 Assumptions, Explanations and Limitations
In this section, we discuss all the assumptions, explanations and limitations in this project to illuminate our EER diagram, based on both the project description and real life experiences.
3.2.1 Assumption
All employees must belong to any department
All departments must have at least one manager
One manager can manage at most one department
Each doctor can give multiple treatments
Patient can have multiple treatments
Each treatment can be assisted by multiple nurses or no nurse
Each nurse can assist multiple treatments
An Ambulance can be driven by multiple drivers
Each detachment must carry at least 1 patient
Patient can have no prescription
All events are held by employees or volunteers or both
An individual attendee might not be a relative
Each employee can host multiple events
Each event is hosted by at least 1 employee or 1 volunteer
3.2.2 Explanation
Subclasses of “Employee”: Doctor, Nurse, Support Staff, Receptionist, Manager, Pharmacist
Subclasses of “Patient”: In-Patient, Out-Patient
Subclasses of “Support Staff”: Part-time, Full-time
Subclasses of “Treatment”: Online, Phone
3.2.3 Limitations
Value constraint for attribute cannot be represented such as, age of volunteer is less or equal 75
ID format for patients cannot be represented
Bed ID cannot be represented
Evaluation score range cannot be represented
Level of doctors cannot be expressed
Project for Database Design—Phase IV Dec-9-2013
Page 10 of 41
4. Relational Schema in Third Normal Form
This section presents the final relational schema in 3NF as well as any assumptions made when constructing the schema. The formats for all relations are also resented.
Project for Database Design—Phase IV Dec-9-2013
Page 11 of 41
4.1 Relational Schema
← See Next Page for Relational Schema →
Project for Database Design—Phase IV Dec-9-2013
Page 12 of 41
Project for Database Design—Phase IV Dec-9-2013
Page 13 of 41
4.2 Format design The rules for formatting data are shown as follows:
1. For all ID, with the exception of Patient IDs, the format is as follows:
XXXXXXXXXX
Where
o X is a randomly generated integer ⊆ [0-9]
2. For Patient IDs, the format is as follows:
FMLXXXXXXX
Where o F is the first letter of the patient’s first name o M is the first letter of the patient’s initials o L is the first letter of the patient’s last name
o X is a randomly generated integer ⊆ [0-9]
3. For all license#, the format is as follow:
XXXXXXXX
Where
o X is a randomly generated integer ⊆ [0-9]
4. For all phone number, the format is as follows:
XXX-XXX-XXXX
Where o X is a randomly generated integer ⊆ [0-9]
5. For all date, the format is as follow,
6. MONTH-DAY-YEAR
a. MONTH can be any standard abbreviation for any given month. b. DAY is a valid day for the month given. c. YEAR is a valid year.
7. For all time, the format is as follow,
8. HOUR:MIN:SECOND
a. HOUR ⊆ [1, 24].
b. MIN ⊆ [0, 60].
c. SECOND ⊆ [1, 60].
Project for Database Design—Phase IV Dec-9-2013
Page 14 of 41
4.3 Format for Every Relation
EMPLOYEE
emp_id varchar(10)
emp_name varchar(30) NOT NULL
emp_ssn varchar(11)
emp_gender varchar(1)
emp_age int check (emp_age<=75)
emp_title varchar(30)
emp_date date
emp_salary number
emp_email varchar(50)
emp_address1 varchar(30)
emp_address2 varchar(30)
emp_city varchar(20)
emp_state varchar(20)
emp_zip number(5)
DEPARTMENT
dept_id varchar(10)
dept_name varchar(50) NOT NULL
dept_phn varchar(12)
DEPARTMENT_LOCATION
dept_id varchar(10)
dept_location varchar(50)
DEPARTMENT_EMPLOYEES
dept_id varchar(10)
emp_id varchar(10)
EMPLOYEE_PHONE
emp_id varchar(10)
emp_phn varchar(12)
MANAGER
mngr_id varchar(10)
dept_id varchar(10)
PHARMACIST
pharm_id varchar(10)
pharm_degree varchar(20)
RECEPTIONIST
recp_id varchar(10)
DOCTOR
doc_id varchar(10)
Project for Database Design—Phase IV Dec-9-2013
Page 15 of 41
doc_level int check (doc_level>=1 AND doc_level<=5)
doc_school varchar(50)
DOCTOR_LANGUAGE
doc_id varchar(10)
doc_lan varchar(30)
DOCTOR_SPECIALITY
doc_id varchar(10)
doc_spec varchar(30)
NURSE
nurse_id varchar(10)
NURSE_LANGUAGE
nurse_id varchar(10)
nurse_lan varchar(30)
SUPPORT_STAFF
staff_id varchar(10)
PART_TIME_STAFF
staff_id varchar(10)
FULL_TIME_STAFF
staff_id varchar(10)
HOURLY_WORKING
staff_id varchar(10)
hours_worked number check (hours_worked>=0)
VOLUNTEER
volun_id varchar(10)
AVAILABLE_DAYTIME
volun_id varchar(10)
volun_day date
volun_time varchar(15)
DRIVER
driver_id varchar(10)
driver_license number(8)
AMBULANCE_DRIVER
driver_id varchar(10)
a_license_num varchar(8)
Project for Database Design—Phase IV Dec-9-2013
Page 16 of 41
PRESCRIPTION
pres_id varchar(10)
written_by varchar(10)
dispensed_by varchar(10)
dispensed_date date
PRESCRIPTION_MEDICINE
pres_id varchar(10)
med_id varchar(10)
MEDICINE
med_id varchar(10)
med_name varchar(30)
med_price number
med_stored_date date
med_quantity number check (med_quantity>=0)
med_type varchar(30) check (med_type='Rx' OR med_type='Non-prescription')
PATIENT_ACCOUNT
patient_id varchar(9)
account# varchar(9)
account_holder varchar(50)
bank_name varchar(50)
bank_address varchar(50)
BILL
bill_id varchar(10)
amount number
status varchar(50) check (status='Paid' OR status='Unpaid')
exp_date date
PRESCIPTION_BILL
bill_id varchar(10)
prescription_id varchar(10)
PATIENT_BILL
patient_id varchar(9)
bill_id varchar(10)
TREATMENT_BILL
bill_id varchar(10)
treatment_id varchar(10)
AMBULANCE_BILL
bill_id varchar(10)
detac_id varchar(10)
Project for Database Design—Phase IV Dec-9-2013
Page 17 of 41
PHARMACY_BILL
bill_id varchar(10)
pharmacy_id varchar(10)
AMBULANCE
license# varchar(8)
stored_in_date date
location varchar(50)
DETACHMENT
detac_id varchar(10)
license# varchar(8)
start_time date
end_time date
PHARMACY
pharmacy_id varchar(10)
PHARMACY_BUY_FROM
pharmacy_id varchar(10)
patient_id varchar(9)
TREATMENT
treatment_id varchar(10)
patient_id varchar(9)
fee varchar(50)
result varchar(50)
TREATMENT_DOCTORS
treatment_id varchar(10)
doctor_id varchar(10)
TREATMENT_NURSES
treatment_id varchar(10)
nurse_id varchar(10)
TREATMENT_APPOINTMENT
treatment_id varchar(10)
app_id varchar(10)
APPOINTMENT
appointment_id varchar(10)
treatment_type varchar(50) check(treatment_type='surgery' OR treatment_type='test')
app_day date
app_time varchar(10)
APPOINTMENT_DOCTORS
Project for Database Design—Phase IV Dec-9-2013
Page 18 of 41
appointment_id varchar(10)
doctor_id varchar(10
ONLINE_APPOINTMENTS
app_id varchar(10)
PHONE_APPOINTMENTS
app_id varchar(10)
recept_id varchar(10)
EVENT_PATIENT
event_name varchar(50)
patient_id varchar(9)
EVENT_HOSTED_BY
event_name varchar(50)
emp_id varchar(10)
EVENT_CITY
event_name varchar(50)
city_name varchar(10)
EVENT
event_name varchar(50)
hold_time varchar(10)
description varchar(50)
event_language varchar(20)
THEME
theme varchar(20)
EVENT_THEME
event_name varchar(50)
theme varchar(20)
EVAL_FORM
att_ssn varchar(11)
score int check(score>=1 AND score<=100)
event_name varchar(50)
RELATIVES
att_ssn varchar(11)
patient_id varchar(9)
relative_name varchar(30)
EVENT_ATT
att_ssn varchar(11)
event_name varchar(50)
Project for Database Design—Phase IV Dec-9-2013
Page 19 of 41
ATTENDEE
att_ssn varchar(11)
att_name varchar(30) NOT NULL
PATIENT_VISIT
patient_visit_id varchar(10)
patient_id varchar(9)
patient_ssn varchar(11)
pv_date date
pv_time varchar(10)
gender char(1)
reason varchar(50)
age int
doctor_id varchar(10)
nurse_id varchar(10)
PATIENT_PHARMACY
patient_id varchar(9)
pharmacy_id varchar(10)
INSURANCE
patient_id varchar(9)
policy_number varchar(20)
company_name varchar(30)
expired_date date
BED_RESERVATION
patient_id varchar(9)
bed_no int
start_time date
end_time date
bill_id varchar(10)
PATIENT_LANGUAGE
patient_id varchar(10)
languages varchar(30)
PATIENT_PHONE
patient_id varchar(9)
phone varchar(12)
OUT_PATIENT
patient_id varchar(9)
IN_PATIENT
patient_id varchar(9)
patient_ssn varchar(11)
BED
Project for Database Design—Phase IV Dec-9-2013
Page 20 of 41
bed_no int check (bed_no>=1 AND bed_no<=500)
room_no number
PATIENT_DETACHMENT
patient_id varchar(9)
detach_id varchar(10)
PATIENT
patient_id varchar(9)
last_name varchar(30)
first_name varchar(30)
dob date
gender char(1)
reason varchar(50)
home_driver varchar(50)
email varchar(20)
medical_history varchar(50)
addr1 varchar(20)
addr2 varchar(20)
city varchar(15)
patient_state varchar(10)
zip varchar(5)
COMPANY_PHONE
company_name varchar(50)
company_phone varchar(14)
Project for Database Design—Phase IV Dec-9-2013
Page 21 of 41
5. SQL Statements for Database Implementation This section presents all SQL commands for the creation of each table as well as SQL commands for demonstrating the insertion of data. We create all separate relation tables first and then we update foreign keys for all relations.
Project for Database Design—Phase IV Dec-9-2013
Page 22 of 41
5.1 Creation of Database with SQL Statements The following SQL statements are used to create all tables.
CREATE TABLE EMPLOYEE ( emp_id varchar(10), emp_name varchar(30) NOT NULL, emp_ssn varchar(11), emp_gender varchar(1), emp_age int check (emp_age<=75), emp_title varchar(30), emp_date date, emp_salary number, emp_email varchar(50), emp_address1 varchar(30), emp_address2 varchar(30), emp_city varchar(20), emp_state varchar(20), emp_zip number(5), PRIMARY KEY(emp_id), UNIQUE(emp_ssn) ); CREATE TABLE DEPARTMENT( dept_id varchar(10), dept_name varchar(50) NOT NULL, dept_phn varchar(12), PRIMARY KEY(dept_id) ); CREATE TABLE DEPARTMENT_LOCATION( dept_id varchar(10), dept_location varchar(50), PRIMARY KEY(dept_id, dept_location) ); CREATE TABLE DEPARTMENT_EMPLOYEES( dept_id varchar(10), emp_id varchar(10), PRIMARY KEY(dept_id, emp_id) ); CREATE TABLE EMPLOYEE_PHONE( emp_id varchar(10), emp_phn varchar(12), PRIMARY KEY(emp_id, emp_phn) ); CREATE TABLE MANAGER( mngr_id varchar(10), dept_id varchar(10), PRIMARY KEY(mngr_id, dept_id) ); CREATE TABLE PHARMACIST( pharm_id varchar(10), pharm_degree varchar(20), PRIMARY KEY(pharm_id) ); CREATE TABLE RECEPTIONIST( recp_id varchar(10), PRIMARY KEY(recp_id) ); CREATE TABLE DOCTOR( doc_id varchar(10), doc_level int check (doc_level>=1 AND doc_level<=5), doc_school varchar(50), PRIMARY KEY(doc_id) ); CREATE TABLE DOCTOR_LANGUAGE( doc_id varchar(10), doc_lan varchar(30), PRIMARY KEY(doc_id, doc_lan) ); CREATE TABLE DOCTOR_SPECIALITY( doc_id varchar(10), doc_spec varchar(30), PRIMARY KEY(doc_id, doc_spec) ); CREATE TABLE NURSE( nurse_id varchar(10), PRIMARY KEY(nurse_id) ); CREATE TABLE NURSE_LANGUAGE( nurse_id varchar(10), nurse_lan varchar(30), PRIMARY KEY(nurse_id, nurse_lan) ); CREATE TABLE SUPPORT_STAFF( staff_id varchar(10), PRIMARY KEY(staff_id) ); CREATE TABLE PART_TIME_STAFF( staff_id varchar(10), PRIMARY KEY(staff_id) ); CREATE TABLE FULL_TIME_STAFF(
staff_id varchar(10), PRIMARY KEY(staff_id) ); CREATE TABLE HOURLY_WORKING( staff_id varchar(10), hours_worked number check (hours_worked>=0), PRIMARY KEY(staff_id) ); CREATE TABLE VOLUNTEER( volun_id varchar(10), PRIMARY KEY(volun_id) ); CREATE TABLE AVAILABLE_DAYTIME( volun_id varchar(10), volun_day date, volun_time varchar(15), PRIMARY KEY(volun_id, volun_day, volun_time) ); CREATE TABLE DRIVER( driver_id varchar(10), driver_license number(8), PRIMARY KEY(driver_id) ); CREATE TABLE AMBULANCE_DRIVER( driver_id varchar(10), a_license_num varchar(8), PRIMARY KEY(driver_id, a_license_num) ); CREATE TABLE PRESCRIPTION( pres_id varchar(10), written_by varchar(10), dispensed_by varchar(10), dispensed_date date, PRIMARY KEY(pres_id) ); CREATE TABLE PRESCRIPTION_MEDICINE( pres_id varchar(10), med_id varchar(10), PRIMARY KEY(pres_id, med_id) ); CREATE TABLE MEDICINE( med_id varchar(10), med_name varchar(30), med_price number, med_stored_date date, med_quantity number check (med_quantity>=0), med_type varchar(30) check (med_type='Rx' OR med_type='Non-prescription'), PRIMARY KEY(med_id) ); CREATE TABLE PATIENT_ACCOUNT( patient_id varchar(9), account# varchar(9), account_holder varchar(50), bank_name varchar(50), bank_address varchar(50), PRIMARY KEY(patient_id, account#) ); CREATE TABLE BILL( bill_id varchar(10), amount number, status varchar(50) check (status='Paid' OR status='Unpaid'), exp_date date, PRIMARY KEY(bill_id) ); CREATE TABLE PRESCIPTION_BILL( bill_id varchar(10), prescription_id varchar(10), PRIMARY KEY(bill_id, prescription_id) ); CREATE TABLE PATIENT_BILL( patient_id varchar(9), bill_id varchar(10), PRIMARY KEY(patient_id, bill_id) ); CREATE TABLE TREATMENT_BILL( bill_id varchar(10), treatment_id varchar(10), PRIMARY KEY(bill_id, treatment_id) ); CREATE TABLE AMBULANCE_BILL( bill_id varchar(10), detac_id varchar(10), PRIMARY KEY(bill_id, detac_id) ); CREATE TABLE PHARMACY_BILL( bill_id varchar(10), pharmacy_id varchar(10),
Project for Database Design—Phase IV Dec-9-2013
Page 23 of 41
PRIMARY KEY(bill_id, pharmacy_id) ); CREATE TABLE AMBULANCE( license# varchar(8), stored_in_date date, location varchar(50), PRIMARY KEY(license#) ); CREATE TABLE DETACHMENT( detac_id varchar(10), license# varchar(8), start_time date, end_time date, PRIMARY KEY(detac_id) ); CREATE TABLE PHARMACY( pharmacy_id varchar(10), PRIMARY KEY(pharmacy_id) ); CREATE TABLE PHARMACY_BUY_FROM( pharmacy_id varchar(10), patient_id varchar(9), PRIMARY KEY(pharmacy_id, patient_id) ); CREATE TABLE TREATMENT( treatment_id varchar(10), patient_id varchar(9), fee varchar(50), result varchar(50), PRIMARY KEY(treatment_id) ); CREATE TABLE TREATMENT_DOCTORS( treatment_id varchar(10), doctor_id varchar(10), PRIMARY KEY(treatment_id, doctor_id) ); CREATE TABLE TREATMENT_NURSES( treatment_id varchar(10), nurse_id varchar(10), PRIMARY KEY(treatment_id, nurse_id) ); CREATE TABLE TREATMENT_APPOINTMENT( treatment_id varchar(10), app_id varchar(10), PRIMARY KEY(treatment_id, app_id) ); CREATE TABLE APPOINTMENT( appointment_id varchar(10), treatment_type varchar(50) check(treatment_type='surgery' OR treatment_type='test'), app_day date, app_time varchar(10), PRIMARY KEY(appointment_id) ); CREATE TABLE APPOINTMENT_DOCTORS( appointment_id varchar(10), doctor_id varchar(10), PRIMARY KEY(appointment_id, doctor_id) ); CREATE TABLE ONLINE_APPOINTMENTS( app_id varchar(10), PRIMARY KEY(app_id) ); CREATE TABLE PHONE_APPOINTMENTS( app_id varchar(10), recept_id varchar(10), PRIMARY KEY(app_id, recept_id) ); CREATE TABLE EVENT_PATIENT( event_name varchar(50), patient_id varchar(9), PRIMARY KEY(event_name, patient_id) ); CREATE TABLE EVENT_HOSTED_BY( event_name varchar(50), emp_id varchar(10), PRIMARY KEY(emp_id, event_name) ); CREATE TABLE EVENT_CITY( event_name varchar(50), city_name varchar(10), PRIMARY KEY(event_name) ); CREATE TABLE EVENT( event_name varchar(50), hold_time varchar(10), description varchar(50), event_language varchar(20), PRIMARY KEY(event_name) ); CREATE TABLE THEME ( theme varchar(20), PRIMARY KEY(theme) );
CREATE TABLE EVENT_THEME ( event_name varchar(50), theme varchar(20), PRIMARY KEY(event_name, theme) ); CREATE TABLE EVAL_FORM( att_ssn varchar(11), score int check(score>=1 AND score<=100), event_name varchar(50), PRIMARY KEY(att_ssn) ); CREATE TABLE RELATIVES( att_ssn varchar(11), patient_id varchar(9), relative_name varchar(30), PRIMARY KEY(patient_id, relative_name) ); CREATE TABLE EVENT_ATT( att_ssn varchar(11), event_name varchar(50), PRIMARY KEY(att_ssn, event_name) ); CREATE TABLE ATTENDEE( att_ssn varchar(11), att_name varchar(30) NOT NULL, PRIMARY KEY(att_ssn) ); CREATE TABLE PATIENT_VISIT( patient_visit_id varchar(10), patient_id varchar(9), patient_ssn varchar(11), pv_date date, pv_time varchar(10), gender char(1), reason varchar(50), age int, doctor_id varchar(10), nurse_id varchar(10), PRIMARY KEY(patient_visit_id) ); CREATE TABLE PATIENT_PHARMACY( patient_id varchar(9), pharmacy_id varchar(10), PRIMARY KEY(patient_id, pharmacy_id) ); CREATE TABLE INSURANCE( patient_id varchar(9), policy_number varchar(20), company_name varchar(30), expired_date date, PRIMARY KEY(patient_id, policy_number, company_name) ); CREATE TABLE BED_RESERVATION( patient_id varchar(9), bed_no int, start_time date, end_time date, bill_id varchar(10), PRIMARY KEY(patient_id, bed_no, start_time, end_time) ); CREATE TABLE PATIENT_LANGUAGE( patient_id varchar(10), languages varchar(30), PRIMARY KEY(patient_id, languages) ); CREATE TABLE PATIENT_PHONE( patient_id varchar(9), phone varchar(12), PRIMARY KEY(patient_id, phone) ); CREATE TABLE OUT_PATIENT( patient_id varchar(9), PRIMARY KEY(patient_id) ); CREATE TABLE IN_PATIENT( patient_id varchar(9), patient_ssn varchar(11), PRIMARY KEY(patient_id) ); CREATE TABLE BED( bed_no int check (bed_no>=1 AND bed_no<=500), room_no number, PRIMARY KEY(bed_no) ); CREATE TABLE PATIENT_DETACHMENT( patient_id varchar(9), detach_id varchar(10), PRIMARY KEY(patient_id, detach_id) ); CREATE TABLE PATIENT( patient_id varchar(9), last_name varchar(30), first_name varchar(30), dob date, gender char(1), reason varchar(50), home_driver varchar(50),
Project for Database Design—Phase IV Dec-9-2013
Page 24 of 41
email varchar(20), medical_history varchar(50), addr1 varchar(20), addr2 varchar(20), city varchar(15), patient_state varchar(10), zip varchar(5), PRIMARY KEY(patient_id)
); CREATE TABLE COMPANY_PHONE( company_name varchar(50), company_phone varchar(14), PRIMARY KEY(company_name) );
Project for Database Design—Phase III Dec-2-2013
Page 25 of 41
5.2 Assigning Foreign Keys with SQL Statements The following SQL statements are used to create all foreign keys for all relations.
ALTER TABLE DEPARTMENT_LOCATION ADD CONSTRAINT fk_dept_loc_did FOREIGN KEY(dept_id) REFERENCES DEPARTMENT(dept_id); ALTER TABLE DEPARTMENT_EMPLOYEES ADD CONSTRAINT fk_dept_emp_did FOREIGN KEY(dept_id) REFERENCES DEPARTMENT(dept_id); ALTER TABLE DEPARTMENT_EMPLOYEES ADD CONSTRAINT fk_dept_emp_eid FOREIGN KEY(emp_id) REFERENCES EMPLOYEE(emp_id); ALTER TABLE EMPLOYEE_PHONE ADD CONSTRAINT fk_emp_phn_eid FOREIGN KEY(emp_id) REFERENCES EMPLOYEE(emp_id); ALTER TABLE MANAGER ADD CONSTRAINT fk_mngr_mid FOREIGN KEY(mngr_id) REFERENCES EMPLOYEE(emp_id); ALTER TABLE MANAGER ADD CONSTRAINT fk_mngr_did FOREIGN KEY(dept_id) REFERENCES DEPARTMENT(dept_id); ALTER TABLE PHARMACIST ADD CONSTRAINT fk_pharm_pid FOREIGN KEY(pharm_id) REFERENCES EMPLOYEE(emp_id); ALTER TABLE RECEPTIONIST ADD CONSTRAINT fk_recep_rid FOREIGN KEY(recp_id) REFERENCES EMPLOYEE(emp_id); ALTER TABLE DOCTOR ADD CONSTRAINT fk_doc_did FOREIGN KEY(doc_id) REFERENCES EMPLOYEE(emp_id); ALTER TABLE DOCTOR_LANGUAGE ADD CONSTRAINT fk_doc_lan_did FOREIGN KEY(doc_id) REFERENCES DOCTOR(doc_id); ALTER TABLE DOCTOR_SPECIALITY ADD CONSTRAINT fk_doc_spec_did FOREIGN KEY(doc_id) REFERENCES DOCTOR(doc_id); ALTER TABLE NURSE ADD CONSTRAINT fk_nurse_nid FOREIGN KEY(nurse_id) REFERENCES EMPLOYEE(emp_id); ALTER TABLE NURSE_LANGUAGE ADD CONSTRAINT fk_nurse_lan_nid FOREIGN KEY(nurse_id) REFERENCES NURSE(nurse_id); ALTER TABLE SUPPORT_STAFF ADD CONSTRAINT fk_staff_sid FOREIGN KEY(staff_id) REFERENCES EMPLOYEE(emp_id); ALTER TABLE PART_TIME_STAFF ADD CONSTRAINT fk_pstaff_pid FOREIGN KEY(staff_id) REFERENCES SUPPORT_STAFF(staff_id); ALTER TABLE FULL_TIME_STAFF ADD CONSTRAINT fk_fstaff_fid FOREIGN KEY(staff_id) REFERENCES SUPPORT_STAFF(staff_id); ALTER TABLE HOURLY_WORKING ADD CONSTRAINT fk_pstaff_work_sid FOREIGN KEY(staff_id) REFERENCES PART_TIME_STAFF(staff_id); ALTER TABLE VOLUNTEER ADD CONSTRAINT fk_vol_vid FOREIGN KEY(volun_id) REFERENCES SUPPORT_STAFF(staff_id); ALTER TABLE AVAILABLE_DAYTIME ADD CONSTRAINT fk_aval_dt_vid FOREIGN KEY(volun_id) REFERENCES VOLUNTEER(volun_id); ALTER TABLE DRIVER ADD CONSTRAINT fk_driver_did FOREIGN KEY(driver_id) REFERENCES SUPPORT_STAFF(staff_id); ALTER TABLE AMBULANCE_DRIVER ADD CONSTRAINT fk_amb_driver_did FOREIGN KEY(driver_id) REFERENCES DRIVER(driver_id); ALTER TABLE PRESCRIPTION ADD CONSTRAINT fk_pres_did FOREIGN KEY(pres_id) REFERENCES PATIENT(patient_id); ALTER TABLE PRESCRIPTION ADD CONSTRAINT fk_pres_wby FOREIGN KEY(written_by) REFERENCES DOCTOR(doc_id); ALTER TABLE PRESCRIPTION ADD CONSTRAINT fk_pres_dby FOREIGN KEY(dispensed_by) REFERENCES PHARMACIST(pharm_id); ALTER TABLE PRESCRIPTION_MEDICINE ADD CONSTRAINT fk_pres_med_pid FOREIGN KEY(pres_id) REFERENCES PRESCRIPTION(pres_id); ALTER TABLE PRESCRIPTION_MEDICINE ADD CONSTRAINT fk_pres_med_mid FOREIGN KEY(med_id) REFERENCES MEDICINE(med_id); ALTER TABLE PATIENT_ACCOUNT ADD CONSTRAINT fk_pat_acc_pid FOREIGN KEY(patient_id) REFERENCES PATIENT(patient_id); ALTER TABLE PRESCIPTION_BILL ADD CONSTRAINT fk_pres_bill_pid FOREIGN KEY(prescription_id) REFERENCES PRESCRIPTION(pres_id); ALTER TABLE PRESCIPTION_BILL ADD CONSTRAINT fk_pres_bill_bid FOREIGN KEY(bill_id) REFERENCES BILL(bill_id); ALTER TABLE PATIENT_BILL ADD CONSTRAINT fk_pt_bill_pid FOREIGN KEY(patient_id) REFERENCES PATIENT(patient_id); ALTER TABLE PATIENT_BILL ADD CONSTRAINT fk_pt_bill_bid FOREIGN KEY(bill_id) REFERENCES BILL(bill_id); ALTER TABLE TREATMENT_BILL ADD CONSTRAINT fk_treat_bill_tid FOREIGN KEY(treatment_id) REFERENCES TREATMENT(treatment_id); ALTER TABLE TREATMENT_BILL ADD CONSTRAINT fk_treat_bill_bid FOREIGN KEY(bill_id) REFERENCES BILL(bill_id); ALTER TABLE AMBULANCE_BILL ADD CONSTRAINT fk_amb_bill_pid FOREIGN KEY(detac_id) REFERENCES DETACHMENT(detac_id); ALTER TABLE AMBULANCE_BILL ADD CONSTRAINT fk_amb_bill_bid FOREIGN KEY(bill_id) REFERENCES BILL(bill_id); ALTER TABLE PHARMACY_BILL ADD CONSTRAINT fk_phar_bill_pid FOREIGN KEY(pharmacy_id) REFERENCES PHARMACY(pharmacy_id); ALTER TABLE PHARMACY_BILL ADD CONSTRAINT fk_phar_bill_bid FOREIGN KEY(bill_id) REFERENCES BILL(bill_id); ALTER TABLE DETACHMENT ADD CONSTRAINT fk_detach_did FOREIGN KEY(license#) REFERENCES AMBULANCE(license#); ALTER TABLE PHARMACY_BUY_FROM ADD CONSTRAINT fk_pharm_buy_pid FOREIGN KEY(pharmacy_id) REFERENCES PHARMACY(pharmacy_id); ALTER TABLE PHARMACY_BUY_FROM ADD CONSTRAINT fk_pharm_buy_ptid FOREIGN KEY(patient_id) REFERENCES PATIENT(patient_id); ALTER TABLE TREATMENT ADD CONSTRAINT fk_treat_tid FOREIGN KEY(patient_id) REFERENCES PATIENT(patient_id); ALTER TABLE INSURANCE ADD CONSTRAINT fk_com_com FOREIGN KEY(company_name) REFERENCES COMPANY_PHONE(company_name); ALTER TABLE TREATMENT ADD CONSTRAINT fk_pat_treat FOREIGN KEY(patient_id) REFERENCES PATIENT(patient_id); ALTER TABLE PRESCRIPTION ADD CONSTRAINT fk_pat_pres FOREIGN KEY(pres_id) REFERENCES PATIENT(patient_id); ALTER TABLE PATIENT_DETACHMENT ADD CONSTRAINT fk_patDet_pat FOREIGN KEY(patient_id) REFERENCES PATIENT(patient_id); ALTER TABLE PATIENT_DETACHMENT ADD CONSTRAINT fk_patDet_Det FOREIGN KEY(detach_id) REFERENCES DETACHMENT(detac_id); ALTER TABLE IN_PATIENT ADD CONSTRAINT fk_inPat_pat FOREIGN KEY(patient_id) REFERENCES PATIENT(patient_id); ALTER TABLE OUT_PATIENT ADD CONSTRAINT fk_outPat_pat FOREIGN KEY(patient_id) REFERENCES PATIENT(patient_id); ALTER TABLE PATIENT_PHONE ADD CONSTRAINT fk_patPhone_pat FOREIGN KEY(patient_id) REFERENCES PATIENT(patient_id); ALTER TABLE PATIENT_LANGUAGE ADD CONSTRAINT fk_patLanguage_pat FOREIGN KEY(patient_id) REFERENCES PATIENT(patient_id); ALTER TABLE BED_RESERVATION ADD CONSTRAINT fk_bedRes_inPat FOREIGN KEY(patient_id) REFERENCES IN_PATIENT(patient_id); ALTER TABLE BED_RESERVATION ADD CONSTRAINT fk_bedRes_bed FOREIGN KEY(bed_no) REFERENCES BED(bed_no); ALTER TABLE BED_RESERVATION ADD CONSTRAINT fk_bedRes_bill FOREIGN KEY(bill_id) REFERENCES BILL(bill_id); ALTER TABLE INSURANCE ADD CONSTRAINT fk_ins_pat FOREIGN KEY(patient_id) REFERENCES PATIENT(patient_id); ALTER TABLE PATIENT_PHARMACY ADD CONSTRAINT fk_patPhar_pat FOREIGN KEY(patient_id) REFERENCES PATIENT(patient_id); ALTER TABLE PATIENT_PHARMACY ADD CONSTRAINT fk_patPhar_phar FOREIGN KEY(pharmacy_id) REFERENCES PHARMACY(pharmacy_id); ALTER TABLE PATIENT_VISIT ADD CONSTRAINT fk_patVisit_pat FOREIGN KEY(patient_id) REFERENCES PATIENT(patient_id); ALTER TABLE PATIENT_VISIT ADD CONSTRAINT fk_patVisit_doc FOREIGN KEY(doctor_id) REFERENCES DOCTOR(doc_id); ALTER TABLE PATIENT_VISIT ADD CONSTRAINT fk_patVisit_nur FOREIGN KEY(nurse_id) REFERENCES NURSE(nurse_id); ALTER TABLE EVENT_ATT ADD CONSTRAINT fk_eventAtt_att FOREIGN KEY(att_ssn) REFERENCES ATTENDEE(att_ssn); ALTER TABLE RELATIVES ADD CONSTRAINT fk_rel_pat FOREIGN KEY(patient_id) REFERENCES PATIENT(patient_id); ALTER TABLE EVAL_FORM ADD CONSTRAINT fk_evalForm_att FOREIGN KEY(att_ssn) REFERENCES ATTENDEE(att_ssn); ALTER TABLE EVAL_FORM ADD CONSTRAINT fk_evalForm_event FOREIGN KEY(event_name) REFERENCES EVENT(event_name); ALTER TABLE EVENT_THEME ADD CONSTRAINT fk_eventTheme_event FOREIGN KEY(event_name) REFERENCES EVENT(event_name); ALTER TABLE EVENT_THEME ADD CONSTRAINT fk_eventTheme_theme FOREIGN KEY(theme) REFERENCES THEME(theme); ALTER TABLE EVENT_CITY ADD CONSTRAINT fk_eventCity_event FOREIGN KEY(event_name) REFERENCES EVENT(event_name); ALTER TABLE EVENT_HOSTED_BY ADD CONSTRAINT fk_eventHost_event FOREIGN KEY(event_name) REFERENCES EVENT(event_name); ALTER TABLE EVENT_HOSTED_BY ADD CONSTRAINT fk_eventHost_emp FOREIGN KEY(emp_id) REFERENCES EMPLOYEE(emp_id); ALTER TABLE EVENT_PATIENT ADD CONSTRAINT fk_eventPat_event FOREIGN KEY(event_name) REFERENCES EVENT(event_name); ALTER TABLE EVENT_PATIENT ADD CONSTRAINT fk_eventPat_pat FOREIGN KEY(patient_id ) REFERENCES PATIENT(patient_id); ALTER TABLE PHONE_APPOINTMENTS ADD CONSTRAINT fk_phoneApp_app FOREIGN KEY(app_id) REFERENCES APPOINTMENT(appointment_id ); ALTER TABLE PHONE_APPOINTMENTS ADD CONSTRAINT fk_phoneApp_rep FOREIGN KEY( recept_id) REFERENCES RECEPTIONIST(recp_id); ALTER TABLE ONLINE_APPOINTMENTS ADD CONSTRAINT fk_onlineApp_app FOREIGN KEY( app_id ) REFERENCES APPOINTMENT(appointment_id ); ALTER TABLE APPOINTMENT_DOCTORS ADD CONSTRAINT fk_appDoc_app FOREIGN KEY( appointment_id ) REFERENCES APPOINTMENT(appointment_id ); ALTER TABLE APPOINTMENT_DOCTORS ADD CONSTRAINT fk_appDoc_doc FOREIGN KEY( doctor_id ) REFERENCES DOCTOR(doc_id); ALTER TABLE APPOINTMENT ADD CONSTRAINT fk_app_pat FOREIGN KEY(appointment_id ) REFERENCES PATIENT(patient_id); ALTER TABLE TREATMENT_APPOINTMENT ADD CONSTRAINT fk_treatApp_treat FOREIGN KEY(treatment_id ) REFERENCES TREATMENT( treatment_id); ALTER TABLE TREATMENT_APPOINTMENT ADD CONSTRAINT fk_treatApp_app FOREIGN KEY(app_id) REFERENCES APPOINTMENT( appointment_id); ALTER TABLE TREATMENT_NURSES ADD CONSTRAINT fk_treatNurse_treat FOREIGN KEY(treatment_id) REFERENCES TREATMENT( treatment_id); ALTER TABLE TREATMENT_NURSES ADD CONSTRAINT fk_treatNurse_nurse FOREIGN KEY(nurse_id ) REFERENCES NURSE(nurse_id ); ALTER TABLE TREATMENT_DOCTORS ADD CONSTRAINT fk_treatDoc_treat FOREIGN KEY(treatment_id ) REFERENCES TREATMENT( treatment_id);
Project for Database Design—Phase III Dec-2-2013
Page 26 of 41
5.3 Database State For this project, we wrote a JAVA program to generate random database states for all relations. This program will be demonstrated during the demo. In addition, we manually wrote the following SQL commands to insert relevant data for employees of the hospital. INSERT INTO EVENT VALUES ('Marathon','2 Hours','Event','English'); INSERT INTO EVENT VALUES ('Cookies','4 Hours','Event','English'); INSERT INTO EVENT VALUES ('Yoga','1 Hours','Event','English');
Event_Name Hold_Time Description Language
Marathon 2 Hours Event English
Cookies 4 Hours Event English
Yoga 1 Hour Event English
INSERT INTO EMPLOYEE VALUES ('1111111111','Bob','125-98-6634','M',21,'Mr',to_date('110213', 'MMDDYY'),100000,'[email protected]','5123 A Rd','n/a','Dallas','Texas',75362,'Marathon'); INSERT INTO EMPLOYEE VALUES ('2222222222','Charlie','625-88-9632','M',23,'Mr',to_date('022111', 'MMDDYY'),10000,'[email protected]','6521 B Rd','n/a','Dallas','Texas',75362,''); INSERT INTO EMPLOYEE VALUES ('3333333333','Terry','748-55-6984','M',40,'Dr',to_date('012193', 'MMDDYY'),200000,'[email protected]','1331 C Rd','n/a','Dallas','Texas',75362,'Cookies'); INSERT INTO EMPLOYEE VALUES ('4444444444','Roy','221-33-6681','M',26,'Mr',to_date('081111', 'MMDDYY'),100000,'[email protected]','6324 D Rd','n/a','Dallas','Texas',75362,''); INSERT INTO EMPLOYEE VALUES ('5555555555','Allan','665-85-8874','M',23,'Mr',to_date('050812', 'MMDDYY'),90000,'[email protected]','7461 E Rd','n/a','Dallas','Texas',75362,''); INSERT INTO EMPLOYEE VALUES ('6666666666','Mary','642-86-3311','F',25,'Mrs',to_date('091313', 'MMDDYY'),90000,'[email protected]','1236 F Rd','n/a','Dallas','Texas',75362,''); INSERT INTO EMPLOYEE VALUES ('7777777777','Ashley','332-54-5546','F',26,'Mrs',to_date('071207', 'MMDDYY'),120000,'[email protected]','6345 G Rd','n/a','Dallas','Texas',75362,''); INSERT INTO EMPLOYEE VALUES ('8888888888','Paul','154-12-4478','M',61,'Dr',to_date('050280', 'MMDDYY'),500000,'[email protected]','7424 H Rd','n/a','Dallas','Texas',75362,'Yoga'); INSERT INTO EMPLOYEE VALUES ('9999999999','Raymond','541-69-9987','M',29,'Mr',to_date('011205', 'MMDDYY'),100000,'[email protected]','7352 H Rd','n/a','Dallas','Texas',75362,''); INSERT INTO EMPLOYEE VALUES ('1234567890','Dick','666-66-6666','M',17,'Mr',to_date('111913', 'MMDDYY'),5000,'[email protected]','1203 I Rd','n/a','Dallas','Texas',75362,''); INSERT INTO EMPLOYEE VALUES ('9876543210','Ron','666-66-6665','M',17,'Mr',to_date('111913', 'MMDDYY'),5000,'[email protected]','1203 I Rd','n/a','Dallas','Texas',75362,''); INSERT INTO EMPLOYEE VALUES ('9416876415','George','666-62-1231','M',17,'Mr',to_date('111913', 'MMDDYY'),200,'[email protected]','1023 I Rd','n/a','Dallas','Texas',75362,''); INSERT INTO EMPLOYEE VALUES ('1564984168','Harry','666-12-1248','M',17,'Mr',to_date('111913', 'MMDDYY'),0,'[email protected]','1031 I Rd','n/a','Dallas','Texas',75362,'');
EmployeeID Name SSN Gender Age Title Date-Joined Salary Email Address1 Address2 City State Zip Event_Host
1111111111 Bob 125-98-6634 M 21 Mr 11/02/13 100000 [email protected] 5123 A Rd n/a Dallas Texas 75362 Marathon
2222222222 Charlie 625-88-9632 M 23 Mr 02/21/11 100000 [email protected] 6521 B Rd n/a Dallas Texas 75362
3333333333 Terry 748-55-6984 M 40 Dr 01/21/93 200000 [email protected] 1331 C Rd n/a Dallas Texas 75362 Cookies
4444444444 Roy 221-33-6681 M 26 Mr 08/11/11 100000 [email protected] 6324 D Rd n/a Dallas Texas 75362
5555555555 Allan 665-85-8874 M 23 Mr 05/08/12 90000 [email protected] 7461 E Rd n/a Dallas Texas 75362
6666666666 Mary 642-86-3311 F 25 Mrs 09/13/13 90000 [email protected] 1236 F Rd n/a Dallas Texas 75362
7777777777 Ashley 332-542-5546 F 26 Mrs 07/12/07 120000 [email protected] 6345 G Rd n/a Dallas Texas 75362
8888888888 Paul 154-12-4478 M 61 Dr 05/02/80 500000 [email protected] 7424 H Rd n/a Dallas Texas 75362 Yoga
9999999999 Raymond 541-69-9987 M 29 Mr 01/12/05 100000 [email protected] 7352 H Rd n/a Dallas Texas 75362
1234567890 Dick 666-66-6666 M 17 Mr 11/19/13 5000 [email protected] 1203 I Rd n/a Dallas Texas 75362
9876543210 Ron 666-66-6665 M 17 Mr 11/19/13 5000 [email protected] 1203 I Rd n/a Dallas Texas 75362
9416876415 George 666-62-1231 M 17 Mr 11/19/13 200 [email protected] 1023 I Rd n/a Dallas Texas 75362
1564984168 Harry 666-12-1245 M 17 Mr 11/19/13 0 [email protected] 1031 I Rd n/a Dallas Texas 75362
INSERT INTO EMPLOYEE_PHONE VALUES ('1111111111','123-124-7522'); INSERT INTO EMPLOYEE_PHONE VALUES ('2222222222','345-124-4563'); INSERT INTO EMPLOYEE_PHONE VALUES ('3333333333','234-157-2342'); INSERT INTO EMPLOYEE_PHONE VALUES ('4444444444','952-423-5782'); INSERT INTO EMPLOYEE_PHONE VALUES ('5555555555','972-752-0992'); INSERT INTO EMPLOYEE_PHONE VALUES ('6666666666','234-997-2062'); INSERT INTO EMPLOYEE_PHONE VALUES ('7777777777','124-523-7744'); INSERT INTO EMPLOYEE_PHONE VALUES ('8888888888','123-362-7567'); INSERT INTO EMPLOYEE_PHONE VALUES ('9999999999','275-144-7740');
Employee_ID Phone_#
1111111111 123-124-7522
2222222222 345-124-4563
3333333333 234-157-2342
4444444444 952-423-5782
5555555555 972-752-0992
6666666666 234-997-2062
7777777777 124-523-7744
8888888888 123-362-7567
9999999999 275-144-7740
INSERT INTO DEPARTMENT VALUES ('1212121212','dept1','693-633-8852'); INSERT INTO DEPARTMENT VALUES ('1313131313','dept2','913-234-1233'); INSERT INTO DEPARTMENT VALUES ('1414141414','dept3','552-312-0643'); INSERT INTO DEPARTMENT VALUES ('1515151515','dept4','666-552-2244');
Dept_ID Name Phone_num
1212121212 dept1 693-633-8852
1313131313 dept2 913-234-1233
1414141414 dept3 552-312-0643
Project for Database Design—Phase III Dec-2-2013
Page 27 of 41
1515151515 dept4 662-552-2244
INSERT INTO DEPARTMENT_LOCATION VALUES ('1212121212','Dallas'); INSERT INTO DEPARTMENT_LOCATION VALUES ('1313131313','Dallas'); INSERT INTO DEPARTMENT_LOCATION VALUES ('1414141414','Dallas'); INSERT INTO DEPARTMENT_LOCATION VALUES ('1515151515','Dallas');
Dept_ID Location
1212121212 Dallas
1313131313 Dallas
1414141414 Dallas
1515151515 Dallas
INSERT INTO DEPARTMENT_EMPLOYEES VALUES ('1212121212','1111111111'); INSERT INTO DEPARTMENT_EMPLOYEES VALUES ('1212121212','2222222222'); INSERT INTO DEPARTMENT_EMPLOYEES VALUES ('1212121212','3333333333'); INSERT INTO DEPARTMENT_EMPLOYEES VALUES ('1212121212','4444444444'); INSERT INTO DEPARTMENT_EMPLOYEES VALUES ('1313131313','5555555555'); INSERT INTO DEPARTMENT_EMPLOYEES VALUES ('1313131313','6666666666'); INSERT INTO DEPARTMENT_EMPLOYEES VALUES ('1414141414','7777777777'); INSERT INTO DEPARTMENT_EMPLOYEES VALUES ('1414141414','8888888888'); INSERT INTO DEPARTMENT_EMPLOYEES VALUES ('1515151515','9999999999');
Dept_ID Emp_ID
1212121212 1111111111
1212121212 2222222222
1212121212 3333333333
1212121212 4444444444
1313131313 5555555555
1313131313 6666666666
1414141414 7777777777
1414141414 8888888888
1515151515 9999999999
INSERT INTO MANAGER VALUES ('9999999999','1212121212'); INSERT INTO MANAGER VALUES ('9999999999','1313131313'); INSERT INTO MANAGER VALUES ('9999999999','1414141414'); INSERT INTO MANAGER VALUES ('9999999999','1515151515');
Mngr_ID Dept_ID
9999999999 1212121212
9999999999 1313131313
9999999999 1414141414
9999999999 1515151515 INSERT INTO PHARMACIST VALUES ('1111111111','M.D'); INSERT INTO PHARMACIST VALUES ('2222222222','M.D'); INSERT INTO PHARMACIST VALUES ('3333333333','M.D'); INSERT INTO PHARMACIST VALUES ('4444444444','M.D');
Pharm_ID Degree
1111111111 M.D
2222222222 M.D
3333333333 M.D
4444444444 M.D
INSERT INTO RECEPTIONIST VALUES ('6666666666');
Recp_ID
6666666666
INSERT INTO DOCTOR VALUES ('8888888888',4,'Baylor');
Doctor_ID Level School
8888888888 10 Baylor
INSERT INTO DOCTOR_LANGUAGE VALUES ('8888888888','English'); INSERT INTO DOCTOR_LANGUAGE VALUES ('8888888888','Spanish');
Doctor_ID Language
8888888888 English
8888888888 Spanish
INSERT INTO DOCTOR_SPECIALITY VALUES ('8888888888','Surgeon'); INSERT INTO DOCTOR_SPECIALITY VALUES ('8888888888',' Diagnostician');
Project for Database Design—Phase III Dec-2-2013
Page 28 of 41
Doctor_ID Specialty
8888888888 Surgeon
8888888888 Diagnostician
INSERT INTO NURSE VALUES ('7777777777');
Nurse
7777777777
INSERT INTO NURSE_LANGUAGE VALUES ('7777777777','English'); INSERT INTO NURSE_LANGUAGE VALUES ('7777777777','Spanish');
Nurse Language
7777777777 English
7777777777 Spanish
INSERT INTO SUPPORT_STAFF VALUES ('1234567890'); INSERT INTO SUPPORT_STAFF VALUES ('9876543210');
Staff_ID
1234567890
9876543210
INSERT INTO PART_TIME_STAFF VALUES ('1234567890');
Part_ID
1234567890
INSERT INTO FULL_TIME_STAFF VALUES ('9876543210');
Full_ID
9876543210
INSERT INTO HOURLY_WORKING VALUES ('1234567890',20);
Part_ID Hours_Worked
1234567890 20
INSERT INTO VOLUNTEER VALUES ('1234567890');
Vol_ID
1564984168
INSERT INTO AVAILABLE_DAYTIME VALUES ('1234567890',to_date('112513', 'MMDDYY'),'5:00-7:00pm');
Vol_ID Days Time
1564984168 12/25/2013 7:00pm
INSERT INTO DRIVER VALUES ('9876543210','12345678');
Driv_ID DL#
9416876415 12345678
Project for Database Design—Phase III Dec-2-2013
Page 29 of 41
5.4 Creation of Views (Answer for Question d - Phase III) The following are the views required for phase 3. View 1 CREATE OR REPLACE VIEW VIEW1_PATIENT_TREATMENT AS SELECT distinct P.patient_id, P.first_name, P.last_name FROM PATIENT P, TREATMENT T WHERE P.patient_id =T.patient_id;
View 2 CREATE OR REPLACE VIEW VIEW2_PATIENT_BILL AS SELECT P.patient_id, P.first_name, P.last_name FROM PATIENT P WHERE P.patient_id in ( SELECT PB.patient_id FROM PATIENT_BILL PB,BILL B WHERE (PB.bill_id=B.bill_id) GROUP BY PB.patient_id HAVING SUM(B.amount)>10000);
View 3 CREATE OR REPLACE VIEW VIEW3_EVENTS_DALLAS AS SELECT E.event_name, E.hold_time, E.description, E.event_language FROM EVENT E, EVENT_CITY EC WHERE E.event_name = EC.event_name AND EC.city_name = 'Dallas';
View 4 CREATE OR REPLACE VIEW VIEW4_DOCTORS_SURGERY AS SELECT E.emp_name, D.doc_id FROM EMPLOYEE E, DOCTOR D, APPOINTMENT_DOCTORS AD, APPOINTMENT A WHERE A.appointment_id = AD.appointment_id AND AD.doctor_id = D.doc_id AND D.doc_id = E.emp_id AND D.doc_level >=4 AND A.treatment_type = 'surgery' AND A.app_day >= to_date('010113', 'MMDDYY');
Project for Database Design—Phase III Dec-2-2013
Page 30 of 41
5.5 Creation of SQL Queries (Answer for Question e - Phase III) The following are the queries required for phase 3. Query 1 SELECT E.emp_id, E.emp_name FROM EMPLOYEE E, NURSE N WHERE E.emp_id = N.nurse_id AND E.emp_city = 'Dallas';
Query 2 SELECT P.first_name, P.last_name, P.addr1, P.addr2, P.city, P.patient_state, P.zip FROM PATIENT P, IN_PATIENT IP, BED B, BED_ RESERVATION BR WHERE P.patient_id = IP.patient_id AND IP.patient_id = BR.patient_id AND BR.bed_no = B.bed_no AND B.room_no = 20 AND BR.start_time >= to_date('010113', 'MMDDYY') AND BR.end_time <= to_date('033113', 'MMDDYY');
Query 3 SELECT E.emp_id, E.emp_name FROM DEPARTMENT D, EMPLOYEE E WHERE E.emp_salary > ( SELECT avg(E.emp_salary) FROM DEPARTMENT_EMPLOYEES DE, EMPLOYEE E, DEPARTMENT D WHERE E.emp_id =DE.emp_id AND DE.dept_id=D.dept_id ) AND ( E.emp_id IN ( SELECT DE.emp_id FROM DEPARTMENT_EMPLOYEES DE WHERE D.dept_id =DE.dept_id ) );
Query 4 SELECT DISTINCT P.first_name, P.last_name FROM PATIENT P, APPOINTMENT A WHERE P.patient_id = A.appointment_id AND A.treatment_type = 'surgery' AND A.app_day = to_date('010113', 'MMDDYY') AND A.appointment_id IN ( SELECT A.appointment_id FROM APPOINTMENT_DOCTORS AD, EMPLOYEE E, DOCTOR D WHERE E.emp_name='Gregory House' AND E.emp_id = D.doc_id AND D.doc_id = AD.doctor_id AND AD.appointment_id = A.appointment_id );
Query 5 SELECT E.emp_name, D.driver_license FROM EMPLOYEE E, DRIVER D
Project for Database Design—Phase III Dec-2-2013
Page 31 of 41
WHERE E.emp_id = D.driver_id AND E.emp_age > 50;
Query 6 SELECT COUNT(distinct A.license#) FROM AMBULANCE A, DETACHMENT D WHERE D.start_time >= to_date('010112', 'MMDDYY') AND D.end_time < to_date('010113', 'MMDDYY') AND A.license# = D.license#;
Query 7 INSERT INTO PATIENT VALUES ('mxl123456','Miles','Long',to_date('090787', 'MMDDYY'),'F','reason','driver','[email protected]','medHistory','3811 GLFAXQWXRDRD','-','someCity','someState',79972); INSERT INTO BILL VALUES ('3539732991','94','Unpaid',to_date('122513', 'MMDDYY')); INSERT INTO PATIENT_BILL VALUES('mxl123456', '3539732991');
Query 8 SELECT I.patient_ssn, P.addr1 FROM IN_PATIENT I, PATIENT P, INSURANCE N WHERE I.patient_id = P.patient_id AND N.patient_id = P.patient_id AND N.expired_date <= CURRENT_DATE;
Query 9 Select X.med_id, X.med_name, X.counts FROM ( SELECT M.med_id AS med_id, M.med_name AS med_name, Count(M.med_id) AS counts FROM PRESCRIPTION P, PRESCRIPTION_MEDICINE PM, MEDICINE M, DOCTOR Doct, DEPARTMENT D, DEPARTMENT_EMPLOYEES DE, EMPLOYEE E WHERE Doct.doc_id = P.written_by AND P.pres_id = PM.pres_id AND PM.med_id = M.med_id AND M.med_type = 'Non-prescription' AND D.dept_id = DE.dept_id AND DE.emp_id = E.emp_id AND E.emp_id = Doct.doc_id AND Doct.doc_level = 5 AND D.dept_name = 'Department: OCABD' GROUP BY M.med_id, M.med_name ORDER BY Count(M.med_id) DESC ) X WHERE ROWNUM = 1;
Query 10 SELECT I.patient_ssn, P.first_name, P.last_name, P.email FROM PATIENT P, IN_PATIENT I, BILL B, PATIENT_BILL PB WHERE I.patient_id = P.patient_id AND P.patient_id = PB.patient_id AND PB.bill_id = B.bill_id GROUP BY I.patient_ssn, P.first_name, P.last_name, P.email HAVING SUM(B.amount) > 10000;
Query 11 SELECT P.last_name, P.first_name, PN.Phone FROM PATIENT P, PATIENT_PHONE PN, ( SELECT P.last_name, P.first_name,
Project for Database Design—Phase III Dec-2-2013
Page 32 of 41
COUNT(DISTINCT NU.nurse_id) FROM PATIENT P, APPOINTMENT A, TREATMENT_APPOINTMENT TA, TREATMENT T, TREATMENT_NURSES TN, NURSE NU, EMPLOYEE E, DEPARTMENT_EMPLOYEES DE, DEPARTMENT D WHERE P.patient_id = A.appointment_id AND A.appointment_id = TA.app_id AND TA.treatment_id = T.treatment_id AND T.treatment_id = TN.treatment_id AND TN.nurse_id = NU.nurse_id AND NU.nurse_id = E.emp_id AND E.emp_id = DE.emp_id AND DE.dept_id = D.dept_id AND D.dept_name = 'Department: CYYPL' GROUP BY P.last_name, P.first_name HAVING COUNT(DISTINCT NU.nurse_id) = ( SELECT COUNT(*) FROM DEPARTMENT D2, DEPARTMENT_EMPLOYEES DE2, EMPLOYEE E2, NURSE NU2 WHERE D2.dept_id = DE2.dept_id AND DE2.emp_id = E2.emp_id AND E2.emp_id = NU2.nurse_id AND D2.dept_name = ‘Diagnostic Medicine’ ) ) X WHERE P.patient_id = PN.patient_id AND P.last_name = X.last_name AND P.first_name = X.first_name;
Query 12 ALTER TABLE BILL ADD issue_date date; SELECT (B.total_bill - S.total_salary) as grossProfit FROM ( SELECT SUM(amount) as total_bill FROM BILL WHERE issue_date >= to_date('010112', 'MMDDYY') AND issue_date < to_date('010113', 'MMDDYY')) B, ( SELECT SUM(emp_salary) as total_salary FROM EMPLOYEE ) S;
Query 13 SELECT B.YEAR2, A.VISIT_DATE, B.MAX_COUNT FROM ( SELECT EXTRACT(YEAR FROM PV.pv_date) AS YEAR1, PV.pv_date AS VISIT_DATE, COUNT(PV.patient_id) as VISIT_COUNT FROM PATIENT_VISIT PV GROUP BY EXTRACT(YEAR FROM PV.pv_date), PV.pv_date ) A, ( SELECT Y.YEAR AS YEAR2, MAX(Y.VISIT_COUNT) AS MAX_COUNT FROM ( SELECT EXTRACT(YEAR FROM PV.pv_date) AS YEAR, PV.pv_date AS VISIT_DATE, COUNT(PV.patient_id) as VISIT_COUNT FROM PATIENT_VISIT PV GROUP BY EXTRACT(YEAR FROM PV.pv_date), PV.pv_date ) Y GROUP BY Y.YEAR ) B WHERE B.YEAR2 = A.YEAR1 AND A.VISIT_COUNT = B.MAX_COUNT;
Query 14 SELECT AVG((trunc(sysdate) - P.dob)/365) FROM PATIENT P, TREATMENT T, TREATMENT_APPOINTMENT TA, ONLINE_APPOINTMENTS O WHERE O.app_id = TA.app_id AND TA.treatment_id = T.treatment_id AND T.patient_id = P.patient_id;
Project for Database Design—Phase III Dec-2-2013
Page 33 of 41
Query 15 ALTER TABLE ATTENDEE DROP COLUMN att_name; ALTER TABLE ATTENDEE ADD att_fname varchar(30); ALTER TABLE ATTENDEE ADD att_lname varchar(30); SELECT A.att_ fname, A.att_lname FROM ATTENDEE A WHERE NOT EXISTS ( SELECT T1.theme FROM THEME T1 MINUS SELECT T.theme FROM EVENT E, EVENT_THEME ET, EVENT_CITY EC, EVAL_FORM VF, THEME T WHERE E.event_name = ET.event_name AND ET.theme = T.theme AND E.event_name = EC.event_name AND E.event_name = VF.event_name AND VF.att_ssn = A.att_ssn AND EC.city_name='Dallas' AND VF.score >=80 );
Project for Database Design—Phase III Dec-2-2013
Page 34 of 41
6. Dependency Diagrams This section presents all dependency diagrams for each applicable table. A final diagram displaying all relations and their functional dependency is also shown.
Project for Database Design—Phase III Dec-2-2013
Page 35 of 41
6.1 Individual Diagram The follow is a list of all relations and their functional dependencies.
1. Employee
Employee_ID Name, SSN, Gender, Age, Title, Date_Joined, Salary, Email, Address1, Adddress 2, City, State, Zip, Event_Host
2. Pharmacist
Pharm_ID Degree
3. Doctor
Doctor_ID Level, School
4. Driver
Driv_ID DL#
5. Department
Dept_ID Name, Phone_Num
6. Patient_Account
Patient_ID Acct_#, Acct_Holder, Bank_Name, Billing_Address
7. Bill
Bill_ID Status, Exp_Date, Amount
8. Ambulance
License_# Stored_In_Date, Location
Project for Database Design—Phase III Dec-2-2013
Page 36 of 41
9. Detachment
Detach_ID License_#, Start_Time End_Time
10. Prescription
Prescription_ID Dispenced_By, Written_By, Dispence_Date
11. Medicine
Med_ID Name, Price, Stored_In_Date, Quantity, Type
12. Treatment
Treatment_ID Fee, Result
13. Appointment
App_ID, Date, Time Treatment_Type
14. Patient
Patient_ID Last_Name, First_Name, DoB, Gender, Reason, Home_Driver, Email, Medical_History, Addr1, Addr2, City, State, Zip
15. Insurance
Patient_ID, Policy#, Company_Name Exp_Date
Project for Database Design—Phase III Dec-2-2013
Page 37 of 41
16. In-Patient
Patient_ID SSN
17. Bed
Bed_No Room_No
18. Bed_Reservation
Patient_ID Bed_No, Start_Time, End_Time, Bill_ID
19. Company_Phone
Company_Name Company_Phone
20. Patient_Visit
Patient_ID SSN, Date, Time, Gender, Reason, Age, Recept_ID, Doctor_ID, Nurse_ID
21. Attendee
Att_SSN Att_Name
22. Relative
Patient_ID, Relative_Name Att_SSN
23. Eval_Form
Att_SSN Score, Event_Name
Project for Database Design—Phase III Dec-2-2013
Page 38 of 41
24. Event
Event_Name Hold_Time, Description, Language
The following relations have no functional dependencies.
1. Employee_Phone_Number 2. Manager 3. Receptionist 4. Doctor_Language 5. Doctor_Specialty 6. Nurse 7. Nurse_Language 8. Support_Staff 9. Part_Time_Staff 10. Full_Time_Staff 11. Volunteer 12. Hours_Worked 13. Available_Days 14. Ambulance_Driver 15. Department_Location 16. Department_Employees 17. Prescription_Bill 18. Patient_Bill 19. Treatment_bill 20. Ambulance_Bill 21. Pharmacy_Bill 22. Pharmacy 23. Pharmacy_Buy_From 24. Presc_Medicines 25. Treatment_Doctors 26. Treatment_Nurses 27. Treatment_Appointment 28. Appointment_Doctor 29. Online 30. Phone 31. Patient_Phone_Number 32. Patient_Language 33. Out_Patient 34. Patient_Detachment 35. Patient_Pharm 36. Event_Atten 37. Event_City 38. Event_Theme 39. Theme 40. Event_Patient 41. Event_Hosted_By
Project for Database Design—Phase III Dec-2-2013
Page 39 of 41
6.2 Final Results
← See Next Page for Functional Dependency Diagram →
Project for Database Design—Phase III Dec-2-2013
Page 40 of 41
Project for Database Design—Phase III Dec-2-2013
Page 41 of 41
7. Conclusion In this final report we summarized all the necessary descriptions and solutions for the hospital database. This includes the design process, the result of EER diagrams, the result of the relational schemas in third normal form, and the result of the functional dependency diagrams. Furthermore we document the SQL statements needed to create the database, to create the view and to solve corresponding queries. We implemented the entire database in Oracle and as well as a JAVA program to create database states to test every query. In addition, in Section 2, we explained our though process on why we use superclass/subclass relationship to build relational schema, why we choose a Relational DBMS to implement our database, as well as five additional business rules that can be implemented.