sql project

23
INFO 364-002 Blood Drive Database Created By: Michael Miller Jim Quiroz Brittany Wong

Upload: michael-miller

Post on 15-Feb-2017

42 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: SQL Project

INFO 364-002

Blood Drive Database

Created By:Michael Miller

Jim Quiroz

Brittany Wong

Page 2: SQL Project

IntroductionThe database that we will be creating for the new blood bank will be used to replace the old database at Red Cross that was difficult to navigate and hosted a large data management problem. Data redundancy in the current system caused the system to run poorly. Donors and their blood types and donation frequency are being repeated under donors’ information when it could be moved to a separate table. The storage facility that is associated with blood withdrawal is redundant due to its repeated facility information. A lot of space under employees is being wasted due to the fact that there are many different types of employees and putting them all in one table would make it too excessive. There are many types of donors, blood types, and employees that could be separated into different categories that distinguish them specifically.

We are motivated to create a new database for the blood bank so that the staff can accurately catalog and report all of the blood that has been donated. The project designed will be aimed at developing an online Blood Donation Information database. The database will create electronic information about the donor and organization in relation with the blood donation. The database will provide the ability to allow any user who wants to donate blood to register into the system. The database will also allow any organization interested in hosting a blood donation event to register online as well. It would record all the donors that come to Red Cross

Page 3: SQL Project

and track how they created an appointment, whether it be in-person or online. Staff can keep track of these appointments so they know when to expect someone coming in. Employees can also record the blood information from donors and calculate which hospitals need that type now or otherwise store it in a facility. To ensure that we can create an effective database, our team will be utilizing the SDLC (Systems Development Life Cycle). We will first plan the specific blood drive database that is needed. Then, we will analyze which entities and relationships are necessary by creating an EER diagram. We will design the whole database by normalizing data into tables in order to reduce redundancy of data.

Finally, we will execute and implement the database through SQL. When new data concerning the blood drive appears, the database will be accessible to being updated without interfering with referential integrity. Through comprehensive planning with the SDLC, our team will be able to design an effective database that will benefit the blood bank and the community as a whole.

Page 4: SQL Project

Business Rules and User Requirements

Every school year, organizations at Virginia Commonwealth University host blood donation drives. Each organization has attributes of Org_ID, Name, Location (City/Street/Zip), Phone, and Email. Prospective donors will create an Appointment for a designated location and at a designated time. Donors can make zero to many appointments. Appointments can be made online or at the event itself through an employee working the blood drive. Appointments have attributes of Appointment_ID, appointment type, appointment time, and appointment date. Each donation event can have many donors or have no donors present. Each event has attributes of Event_ID, Event_Name, Even_Type, Event_Location, and Event_Date.

There are two groups of donors which include students and faculty members. All donors share common attributes of Donor_ID, Name, Date_of_Birth, Address (City/State/Zip), Phone, Height (cm), Weight, and Blood_Pressure. Donors at VCU belong to only one of these groups at a time. Faculty has an unique attribute of Job_Class. Student has an unique attribute of Major. If a donor has given blood before that information can be stored in the Donation Frequency table. Donation Frequency has the attributes Frequency_ID, Frequency_No, and Last_Donation_Date. All Donors have one and only one Blood Type, but a Blood Type can have many or no Donors. Blood Type has attributes of Blood_Type_ID, Blood_Type_Name, and Blood_Type_Positive and Blood_Type_Negative. Donors can only have a Blood Type of A, B, AB, or O. A has A antigens. B has B antigens. AB has AB antigens. O has no antigens.

Employees are subdivided into Blood Drive Employee and Medical Employee. Blood Drive Employee has an attribute of Location_Assigned. Medical Employee has an attribute of Hospital_Location. All Employees have attributes of Emp_ID, Name, Phone, and Email. Blood Drive Employees compose of Blood Drive Nurse, Volunteer, Administrator, and Technician. A Technician can have various skills. A Volunteer has an attribute of Badge_No. Medical Employees consist of Doctor and Nurse. A Blood Drive Nurse has the attribute Blood Drive Station. A Doctor also has an attribute of Doctor_Type. A Medical Employee Nurse has the attribute Hospital Workstation.

Administrators register many or no Donors at the blood drive. Donors get their blood taken from Blood Drive Nurses. A Donor is assigned to only one Nurse, but a Nurse can be assigned to zero or many Donors. After the blood is taken, the Technician stores it in the Blood Inventory, which has attributes of Blood_Inv_ID, Blood_Type, Quantity, and Date. The Blood Inventory can have one or many Technicians storing blood in it, but a Technician may or may not be assigned to store blood in the Blood Inventory. The Donor is also offered Refreshments after donating, where they are allowed to take many or no refreshments. Refreshments have attributes of Refreshment_ID, Refreshment_Name, and Refreshment_Type.

After the blood drive event, the Blood Inventory is transported to a Storage Facility, where it will be stored for future use. Storage facility has attributes of Storage_ID, Name, and Location.

Page 5: SQL Project

If any blood from the Blood Inventory is needed, it is then transported from the Storage Facility to a hospital. A hospital may need a large quantity of blood from the inventory or none at all. Attributes of a hospital include Hospital_ID, Name, and Location (Street, City, Zip Code.

Page 6: SQL Project

EER Diagram DefinitionsEmployee:

Attributes: Emp_ID (Primary), Name, Phone, Email Employee is a supertype and has subtypes of Medical Employee and Blood Drive

Employee Employees are not limited to these two subtypes An Employee can be a Medical Employee and Blood Drive Employee at the same time

Doctor Subtype of Medical Employees Attributes: Doctor Type

Nurse: Attributes: Hospital_Workstation Subtype of Medical Employees

Blood Drive Nurse: Attributes: Blood_Drive_Workstation Subtype of Blood Drive Employees A Nurse takes blood from zero to many Donors

Volunteer: Subtype of Blood Drive Employees Attributes: Badge_No

Blood Drive Employee: Subtype of Employees Attributes: Location_Assigned Blood Drive Employee has subtypes of Technician, Volunteer, Administrator, and Blood

Drive Nurse A Blood Drive Employee can only be one of these subtypes and cannot be both at the

same time

Appointment: Attributes: Appointment_ID (Primary), Appointment_Type, Date, Time An Appointment can be assigned for one and only one Organization and Event at a time An Appointment can be assigned to one and only one Donor

Donor: Attributes: Donor_ID (Primary), Name, DOB, Address (street, city, zip code), Phone

Number, Height (cm), Weight, Blood Pressure Donor is a supertype and has subtypes of Student and Faculty

Page 7: SQL Project

A Donor has to be either a Student or a Faculty member and cannot be both at the same time

A Donor can be a part of zero to many Events A Donor is registered by one and only one Administrator A Donor gets his/her blood drawn from one and only Nurse A Donor has one and only one Blood Type A Donor can have zero or many Refreshments A Donor zero or many Donation Frequency recorded A Donor can make zero to many Appointments

Blood Type: Partial Specialization Attributes: Blood_Type_ID (Primary), Blood_Type_Name, Blood_Type_Decription

(Positive, Negative) Blood Type is a supertype and has subtypes of A, B, AB, and O. Blood Type can only be A, B, AB, or O at a single instance in time A Blood Type can have zero to many Donors

Blood Type A: Subtype of Blood Type Attributes: A antigens

Blood Type B: Subtype of Blood Type Attributes: B antigens

Blood Type AB: Subtype of Blood Type Attributes: AB antigens

Blood Type O: Subtype of Blood Type Attributes: no antigens

Donation Frequency: Attributes: Frequency_ID (Primary), Frequency_No, Last_Donation_Date Donation Frequency belongs to one and only one Donor

Blood_Inventory: Attributes: Blood_Type, Blood_Inventory_ID (Primary), Quantity, Date Blood Inventory can have zero or many Technicians A Blood Inventory can have Blood Withdrawn from zero to many Storage Facilities and

Hospitals.

Page 8: SQL Project

Hospital: Attributes: Hospital_ID (Primary), Hospital Name, Hospital Location (City, Street, Zip

Code) A Hospital can have Blood Withdrawn from zero to many Blood Inventories and Storage

Facilities.

Technician: Attributes: Technician_Name, Skills (MultiValued) Technician stores one or many of Donor’s blood in the Blood Inventory Subtype of Blood Drive Employees

Medical Employee: Medical Employee is a supertype for Doctor and Nurse A Medical Employee must be a Doctor or Nurse and cannot be both at the same time Attributes: Hospital_Location

Storage Facility: Attributes: Storage_ID (Primary), Storage_Name, Storage_Location (City, Street, Zip

Code) A Storage Facility can have Blood Withdrawn from zero to many Blood Inventories and

Hospitals.

Administrator: Subtype of Blood Drive Employees An Administrator can register zero or many Donors

Organization: Attributes: Org ID (Primary), Org Name, Org Location (City, Street, Zip code), Phone,

Email An Organization can have zero to many Appointments for an Event

Refreshment: Attributes: Refreshment_ID (Primary), Refreshment_Type, Refreshment_Name Refreshments can have zero or many Donors

Event: Attributes: Event_ID, Event_Name, Event_Location, Event_Type, Event_Date An Event can have zero to many Donors An Event can have zero to many Appointments for an Organization

Blood Withdrawal: Blood Withdrawal can be done from one and only one Hospital, Storage Facility, or

Blood Inventory.

Page 9: SQL Project

Create Tables Commands

create table Organization_T(Organization_ID int NOT NULL,Organization_Name varchar(45),Organization_Location varchar(45),Organization_City varchar(30),Organization_Street varchar(30),Organization_Zip number NOT NULL,Organization_Phone number NOT NULL,Organization_Email varchar(45),Constraint Organization_PK primary key (Organization_ID));

create table Blood_Type_T(Blood_Type_ID int NOT NULL,Blood_Type_Name varchar(30),Blood_Type_Description varchar(45),Blood_Type_Positive varchar(15),Blood_Type_Negativevarchar(15),Constraint Blood_Tyblope_PK primary key (Blood_Type_ID));

create table Employee_T(Emp_ID int NOT NULL,Emp_Name varchar(45),Emp_Phone number NOT NULL,Emp_Email varchar(45),Constraint Employee_PK primary key (Emp_ID));

create table Blood_Drive_Employee_T(Blood_Drive_Emp_IDint NOT NULL,Location_Assigned varchar(30),Constraint Blood_Drive_Employee_PK primary key (Blood_Drive_Emp_ID),Constraint blood_drive_employee_fk foreign key (blood_drive_emp_id) references Employee_T (Emp_ID));

create table Blood_Drive_Nurse_T(Blood_Drive_Nurse_ID int NOT NULL,Blood_Drive_Work_Station varchar(45),

Page 10: SQL Project

Constraint Blood_Drive_Nurse_PK primary key (Blood_Drive_Nurse_ID),Constraint Blood_Drive_Nurse_FK foreign key (Blood_Drive_Nurse_ID) references Blood_Drive_Employee_T (Blood_Drive_Emp_ID));

create table Donor_T(Donor_ID int NOT NULL,Donor_Name varchar(45),Donor_DOB number NOT NULL,Donor_Street varchar(45),Donor_City varchar(25),Donor_Zip number NOT NULL,Donor_Phone number NOT NULL,Donor_Height_cm number NOT NULL,Donor_Weightnumber NOT NULL,Donor_Blood_Pressure number NOT NULL,Blood_Type_ID int NOT NULL,Blood_Drive_Nurse_ID int NOT NULL,Constraint Donor_PK primary key (Donor_ID),Constraint Donor_FK1 foreign key (Blood_type_ID)

references Blood_Type_T(Blood_type_ID),Constraint Donor_FK2 foreign key (Blood_Drive_Nurse_ID)

references Blood_Drive_Nurse_T(Blood_Drive_Nurse_ID));

create table Appointment_T(Appointment_ID int NOT NULL,Appointment_type varchar(45),Appointment_date varchar(20),Appointment_Time varchar(15),Organization_ID int,Donor_ID int,Constraint Appointment_PK primary key (Appointment_ID),Constraint Appointment_FK1 foreign key (Organization_ID) References Organization_T(Organization_ID),Constraint Appointment_FK2 foreign key (Donor_ID)

References Donor_T(Donor_ID));

create table Event_T(Event_ID int NOT NULL,Event_Name varchar(45),Event_Location varchar(45),Event_Type varchar(25),

Page 11: SQL Project

Event_Date number NOT NULL,Appointment_ID int,Constraint Event_PK primary key (Event_ID),Constraint Event_FK1 foreign key (Appointment_ID)

References Appointment_T(Appointment_ID));

create table Assigned_Event_T(Event_ID int NOT NULL,Donor_ID int NOT NULL,Constraint Assigned_Event_PK primary key (Event_ID, Donor_ID),Constraint Assigned_Event_FK1 foreign key (event_id) references event_t(event_id),Constraint Assigned_Event_FK2 foreign key (donor_id) references donor_t(donor_id));

create table Refreshment_T(Refreshment_ID int NOT NULL,Refreshment_Type varchar(45),Refreshment_Name varchar(45),Donor_ID int NOT NULL,Constraint Refreshment_PK primary key (Refreshment_ID),Constraint Refreshment_FK1 foreign key (Donor_ID)

References Donor_T(Donor_ID));

create table Student_T(Student_ID int NOT NULL,Student_Major varchar(20),Constraint Student_PK primary key (Student_ID),Constraint Student_FK foreign key (Student_ID) references Donor_T(Donor_ID));

create table Faculty_T(Faculty_ID int NOT NULL,Faculty_Job_Class varchar(45),Constraint Faculty_PK primary key (Faculty_ID),Constraint Faculty_FK foreign key (Faculty_ID) references Donor_T(Donor_ID));

create table Donation_Frequency_T(Frequency_IDint NOT NULL,Frequency_Nonumber NOT NULL,Last_Donation_Date number NOT NULL,Donor_ID int NOT NULL,

Page 12: SQL Project

Constraint Donation_Frequency_PK primary key (Frequency_ID),Constraint Donation_Frequency_FK1 foreign key (Donor_ID)

References Donor_T(Donor_ID));

create table Blood_Type_A_T(A_ID int NOT NULL,A_antigens varchar(20),Constraint Blood_Type_A_PK primary key (A_ID),Constraint Blood_Type_A_FK foreign key (A_ID) references Blood_Type_T(Blood_Type_ID));

create table Blood_Type_B_T(B_ID int NOT NULL,B_antigens varchar(20),Constraint Blood_Type_B_PK primary key (B_ID),Constraint Blood_Type_B_FK foreign key (B_ID) references Blood_Type_T(Blood_Type_ID));

create table Blood_Type_AB_T(AB_ID int NOT NULL,AB_antigens varchar(20),Constraint Blood_Type_AB_PK primary key (AB_ID),Constraint Blood_Type_AB_FK foreign key (AB_ID) references Blood_Type_T(Blood_Type_ID));

create table Blood_Type_O_T(O_ID int NOT NULL,No_antigens varchar(20),Constraint Blood_Type_O_PK primary key (O_ID),Constraint Blood_Type_O_FK foreign key (O_ID) references Blood_Type_T(Blood_Type_ID));

create table Admin_T(Admin_ID int NOT NULL,Admin_Number number NOT NULL,Constraint Admin_PK primary key (Admin_ID),Constraint Admin_FK foreign key (Admin_ID) references Blood_Drive_Employee_T (Blood_Drive_Emp_ID));

create table Donor_Admin_T(Donor_ID int NOT NULL,Admin_ID int NOT NULL,

Page 13: SQL Project

Constraint Donor_Admin_PK primary key (Donor_ID, Admin_ID),Constraint Donor_Admin_FK1 foreign key (Donor_ID) references Donor_T(Donor_ID),Constraint Donor_Admin_FK2 foreign key (Admin_ID) references Admin_T (Admin_ID));

create table Volunteer_T(Volunteer_ID int NOT NULL,Badge_No number NOT NULL,Constraint Volunteer_PK primary key (Volunteer_ID),Constraint Volunteer_FK foreign key (Volunteer_ID) references Blood_Drive_Employee_T (Blood_Drive_Emp_ID));

create table Technician_T(Technician_ID int NOT NULL,Constraint Technician_PK primary key (Technician_ID),Constraint Technician_FK foreign key (Technician_ID) references Blood_Drive_Employee_T (Blood_Drive_Emp_ID));

create table Technician_Skill_T(Technician_ID int NOT NULL,Technician_Skill varchar(45),Constraint Technician_Skill_PK primary key (Technician_ID),Constraint Technician_Skill_FK foreign key (Technician_ID) references Technician_T (Technician_ID));

create table Medical_Employee_T(Medical_Employee_ID int NOT NULL,Location_Assigned varchar(45),Constraint Medical_Employee_PK primary key (Medical_Employee_ID),Constraint Medical_Employee_FK foreign key (Medical_Employee_ID) references Employee_T (Emp_ID));

create table Doctor_T(Doctor_ID int NOT NULL,Doctor_Type varchar(45),Constraint Doctor_PK primary key (Doctor_ID),Constraint Doctor_FK foreign key (Doctor_ID) references Medical_Employee_T (Medical_Employee_ID));

Page 14: SQL Project

create table Nurse_T(Nurse_ID int NOT NULL,Hospital_Work_Station varchar(45),Constraint Nurse_PK primary key (Nurse_ID),Constraint Nurse_FK foreign key (Nurse_ID) references Medical_Employee_T (Medical_Employee_ID));

create table Blood_Inventory_T(Blood_Inventory_ID int NOT NULL,Blood_Type varchar(25),Blood_Quantity varchar(45),Blood_Inventory_Date number NOT NULL,Constraint Blood_Inventory_PK primary key (Blood_Inventory_ID));

create table Technician_Inventory_T(Technician_ID int NOT NULL,Blood_Inventory_ID int NOT NULL,Constraint Technician_inv_PK primary key (Technician_ID, Blood_Inventory_ID),Constraint Technician__Inv_FK1 foreign key (Technician_ID) references Technician_T (Technician_ID),Constraint Technician__Inv_FK2 foreign key (Blood_Inventory_ID) references Blood_Inventory_T (Blood_Inventory_ID));

create table Storage_Facility_T(Storage_ID int NOT NULL,Storage_Name varchar(45),Storage_City varchar(45),Storage_State varchar(20),Storage_Zip number NOT NULL,Constraint Storage_PK primary key (Storage_ID));

create table Hospital_T(Hospital_ID int NOT NULL,Hospital_Name varchar(45),Hospital_City varchar(20),Hospital_Street varchar(30),Hospital_Zip number NOT NULL,Constraint Hospital_PK primary key (Hospital_ID));

Page 15: SQL Project

create table Blood_Withdrawal_T(Storage_ID int NOT NULL,Hospital_ID int NOT NULL,Blood_Inventory_ID int NOT NULL,Blood_Withdrawal_No int NOT NULL,Blood_Withdrawal_Location varchar(45),Constraint Blood_Withdrawal_PK primary key (Storage_ID, Hospital_ID, Blood_Inventory_ID, Blood_Withdrawal_No),Constraint Blood_withdrawal_FK1 foreign key (Storage_ID) references Storage_Facility_T (Storage_ID),Constraint Blood_Withdrawal_FK2 foreign key (Hospital_ID) references Hospital_T (Hospital_ID),Constraint Blood_Withdrawal_FK3 foreign key (Blood_Inventory_ID) references Blood_Inventory_T (Blood_Inventory_ID));

Page 16: SQL Project

Select Commands

select donor_name from donor_t, refreshment_t where refreshment_t.donor_id = donor_t.donor_id;

select appointment_typefrom donor_t, appointment_twhere donor_t.donor_id = appointment_t.donor_idand donor_name = 'Henry';

select emp_namefrom employee_t, donor_t, blood_drive_nurse_twhere donor_t.blood_drive_nurse_id = blood_drive_nurse_t.blood_drive_nurse_idand blood_drive_nurse_t.blood_drive_nurse_id = employee_t.emp_idand donor_name = 'Jamie';

select faculty_job_classfrom faculty_t, donor_twhere faculty_t.faculty_id = donor_t.donor_idand donor_blood_pressure > 70;

select hospital_namefrom hospital_t, blood_withdrawal_t, storage_facility_twhere hospital_t.hospital_id = blood_withdrawal_t.hospital_id

Page 17: SQL Project

and blood_withdrawal_t.storage_id = storage_facility_t.storage_idand storage_name = 'Richmond Storage';

select donor_namefrom donor_t, blood_type_twhere donor_t.blood_type_id = blood_type_t.blood_type_idand blood_type_name = 'AB';

select appointment_id, appointment_type, appointment_t.donor_id, donor_namefrom appointment_t left outer join donor_ton appointment_t.donor_id = donor_t.donor_id;

select appointment_typefrom appointment_t, event_twhere appointment_t.appointment_id = event_t.appointment_idand event_name = 'VSA Blood Drive';

select refreshment_namefrom refreshment_t, donor_twhere refreshment_t.donor_id = donor_t.donor_idand donor_name = 'Kate';

Page 18: SQL Project

select donor_name, student_major, donor_weightfrom student_t, donor_twhere student_t.student_id = donor_t.donor_idand donor_weight < 150;

select faculty_id, donor_name, donor_height_cmfrom faculty_t left outer join donor_ton faculty_t.faculty_id = donor_t.donor_id;

select hospital_city, hospital_street, hospital_zipfrom hospital_t, storage_facility_t, blood_withdrawal_twhere storage_facility_t.storage_id = blood_withdrawal_t.storage_idand blood_withdrawal_t.hospital_id = hospital_t.hospital_idand hospital_name = 'Retreat Hospital';

select student_majorfrom student_t, donor_t, blood_type_twhere student_t.student_id = donor_t.donor_idand donor_t.blood_type_id = blood_type_t.blood_type_idand blood_type_name = 'B';

select avg(donor_blood_pressure)from student_t, donor_twhere student_t.student_id = donor_t.donor_id;

Page 19: SQL Project

select emp_phone, emp_emailfrom employee_t, blood_drive_employee_twhere employee_t.emp_id = blood_drive_employee_t.blood_drive_emp_idand location_assigned = 'Henrico';

select location_assignedfrom blood_drive_employee_t, donor_admin_t, admin_twhere blood_drive_employee_t.blood_drive_emp_id = admin_t.admin_idand admin_t.admin_id = donor_admin_t.admin_idand donor_id = 9889;

select technician_skillfrom technician_skill_t, technician_t, blood_drive_employee_t, employee_twhere technician_skill_t.technician_id = technician_t.technician_idand technician_t.technician_id = blood_drive_employee_t.blood_drive_emp_idand blood_drive_employee_t.blood_drive_emp_id = employee_t.emp_idand emp_name = 'Carrie';

select blood_type_positive, blood_type_negativefrom blood_type_t, donor_twhere blood_type_t.blood_type_id = donor_t.blood_type_idand donor_name = 'Jamie';

Page 20: SQL Project

select count(donor_weight)from donor_t, faculty_twhere donor_t.donor_id = faculty_t.faculty_idand donor_weight < 160;

select event_locationfrom event_t, appointment_twhere event_t.appointment_id = appointment_t.appointment_idand appointment_date = '05/04/16';

select *from donor_twhere donor_height_cm < 170;

select blood_drive_emp_idfrom blood_drive_employee_twhere location_assigned = 'Richmond';

select event_namefrom event_t

Page 21: SQL Project

where event_location = 'Hibbs';