cs331 project 2
TRANSCRIPT
-
7/28/2019 CS331 Project 2
1/14
Project # 2
Justin Dragone
ID # 0211
CS 331
November. 28, 2011
-
7/28/2019 CS331 Project 2
2/14
Justin Dragone CS331 November. 28, 2011 Project 2
ER Diagram
-
7/28/2019 CS331 Project 2
3/14
Justin Dragone CS331 November. 28, 2011 Project 2
create table Patient
(pid char(9) primary key,
pfirst varchar(30) not null,plast varchar(30) not null,
cdob Date not null,
gender varchar(7) not null,page varchar(4) not null,
diagnosis varchar(40) not null,
doctor varchar(30) not null,
dov Date not null);
Insert into Patient (pid, pfirst, plast, cdob, gender, page, diagnosis, doctor, dov)
values('123456781', 'Angelina', 'Brown', '10/25/1988', 'female', '23', 'brain tumor', 'Dr.Smith',
'11/26/2011');
Insert into Patient (pid, pfirst, plast, cdob, gender, page, diagnosis, doctor, dov)values('123456782', 'Josephine', 'Lau', '4/3/1988', 'female', '23', 'heart disease', 'Dr.Jones,
'3/12/2011;);
Insert into Patient (pid, pfirst, plast, cdob, gender, page, diagnosis, doctor, dov)
values('123456783', 'Mike', 'Johnson', '12/30/1987', 'male', '24', 'cancer left lung', 'Dr.Singh',
'5/5/2011');
Insert into Patient (pid, pfirst, plast, cdob, gender, page, diagnosis, doctor, dov)
values('123456784', 'James', 'Ford', '3/15/1986', 'male', '25', ' broken bone left toe,' Dr.Bo',
'7/1/2011);
Insert into Patient (pid, pfirst, plast, cdob, gender, page, diagnosis, doctor, dov)
values('123456785', 'Joe', 'Evans', '5/10/1984', 'female', '26', 'leukemia', Dr. Kim', '6/7/2011);
Insert into Patient (pid, pfirst, plast, cdob, gender, page, diagnosis, doctor, dov)
values('123456786', 'Susan', 'Lee', '6/19/1988', 'female', '23', 'cancer skin', Dr. Matt', '3/14/2011');
Insert into Patient (pid, pfirst, plast, cdob, gender, page, diagnosis, doctor, dov)
values('123456787', 'John ', 'Doe', '8/12/1985', 'male', '27', 'kidney stone', 'Dr. Kyle', '1/5/2011');
Insert into Patient(diagnosis)
values(cancer breast, parkinsons, broken bone arm, broken bone leg, cancer prostate, broken
bone finger, emphysema, cancer brain.
create table Staff
(sid char(9) primary key,
-
7/28/2019 CS331 Project 2
4/14
Justin Dragone CS331 November. 28, 2011 Project 2
sfirst varchar(30) not null,slast varchar(30) not null,
sdob Date not null,
sage varchar(4) not null,
title varchar(20) not null);
Insert into Staff (sid, sfirst, slast, title)
values('987654321', 'John','Thomas', 'nurse');
values('987654322', 'Jake','More', 'receptionist');values('987654323', 'Matt','Lake', 'receptionist');
values('987654324', 'Jody','Ve', 'nurse');
values('987654325', 'Jessica','Adams', 'nurse');
values('987654326', 'Adam','Tim', 'surgeon');values('987654327', 'Joey','Reader', 'nurse');
values('987654328', 'Sarah','Gale', 'nurse');values('987654329', 'Heather','Roberts', 'nurse');
values('987654310', 'Tom','Dee', 'nurse');
create table Hospital Location
(hid char(3) primary key,
hname varchar(30) not null,city varchar(20) not null.
zip char(5) not null,
procedure varchar(30) not null,dop Date not null,
cost varchar(4) not null,
revenue carchar(20) not null);
insert into Hospital Location (hid, hname, city, zip, procedure, dop, cost)
values('111', 'Queens Hospital', 'Flushing', '11365');
values('222', 'Manhattan Hospital', 'Manhattan', '11201');values('333', 'Brooklyn Hospital', 'Brooklyn', '11502');
insert into Hospital Location(procedure)values(blood test red cell, xray left toe, surgery broken left toe, surgery heart valve replacement,
examination heart, drug viox, cat scan brain, kidney dialysis, cat scan arm, surgery broken leg,
drug tylenol, xray arm, examination leg, surgery brain tumor, examination hand, surgery bloodtransfusion, xray leg, surgery kidney stone, examination hand);
create table Department
(did char(5) primary key,cardiology varchar(20) not null,
-
7/28/2019 CS331 Project 2
5/14
Justin Dragone CS331 November. 28, 2011 Project 2
radiology varchar(20) not null,oncology varchar(20) not null,
general varchar(20) not null,
emergency varchar(20) not null);
Questions:
1. Identify all patients who visited Dr. Smith yesterday at the Queenshospital.
Display the patient name, date of visit and diagnosis.
select pfirst, plast, dov, diagnosis
from Patient
where pid in
(select pidfrom Patient
where pin = yesterday(), doctor = 'Dr.Smith' and hid in
(select hidfrom hospital location
where hid = 'Queens Hospital');
Patient
pid Pfirst Plast Dov diagnosis
123456781 Angela Brown 11/26/11 Brain tumor
-
7/28/2019 CS331 Project 2
6/14
Justin Dragone CS331 November. 28, 2011 Project 2
2. Identify the number procedures performed by each hospital locationlast year.
Display the hospital name and number of procedures. Display one rowfor each
hospital.
Select hname, procedure
from Hospital Locationwhere hid in
(select hid
from Hospital Locationwhere hin < '2011/11/26' and
hin > '2010/11/26');
Hospital Location
hid hname procedure
111 Queens Hospital 10000
Hospital Location
hid hname procedure
222 Manhattan Hospital 20000
Hospital Location
hid hname procedure
333 Brooklyn Hospital 15000
-
7/28/2019 CS331 Project 2
7/14
Justin Dragone CS331 November. 28, 2011 Project 2
3. Identify the number procedures performed by each department lastyear. Display
the hospital, department name and number of procedures. Display onerow for
each hospital and department.
Select hname, department, procedurefrom Hospital location, department
where hid in
(select hidfrom Hospital Location
where hin < '2011/11/26' and
hin > '2010/11/26');
hid hname department procedure
111 Queens Hospital cardiology 500
radiology 10000
oncology 200
general 1000000
emergency 500000
hid hname department procedure
222 Manhattan Hospital cardiology 5000
radiology 100000
oncology 6000
general 10000000
emergency 8000000
hid hname department procedure
333 Brooklyn Hospital cardiology 50000
-
7/28/2019 CS331 Project 2
8/14
radiology 1000000
oncology 30000
general 40000
emergency 50000
Justin Dragone CS331 November. 28, 2011 Project 2
4. Identify the yesterdays CAT scan results for patient Angelina Brown.Display the
patient name, test and analysis.
Select pfirst, plast, diagnosis
from Patient, Hospital locationwhere pid in
(select pid
from Patientwhere pin = yesterday(), pfirst = 'Angelina, plast = 'Brown', procedure = 'CAT scan');
pid pfirst plast procedure diagnosis
123456781 Angelina Brown CAT scan Brain tumor
-
7/28/2019 CS331 Project 2
9/14
Justin Dragone CS331 November. 28, 2011 Project 2
5. Display the image of the CAT scan from question 4 above.
File textfile 'cs331catscan'/home/justin/desktop/cs331catscan
-
7/28/2019 CS331 Project 2
10/14
Justin Dragone CS331 November. 28, 2011 Project 2
6. Identify the number of procedures each day at the hospital.Display the date and
number of procedures. Display one row for each day.
Select dop, procedure
from Hospital locationwhere hid in(select hidfrom Hospital locationwhere hin < '2011/11/26' and
hin > '2011/11/20');
hid dop procedure
111 11/20/11 20
hid dop procedure
111 11/21/11 30
hid dop procedure
111 11/22/11 40
hid dop procedure
111 11/23/11 10
hid dop procedure
111 11/24/11 50
-
7/28/2019 CS331 Project 2
11/14
hid dop procedure
111 11/25/11 60
hid dop procedure
111 11/26/11 70
Justin Dragone CS331 November. 28, 2011 Project 2
7. Identify the revenue for day last month. Display the date and revenue.Display one row for each day.
Select dop, revenue
from Hospital locationwhere hid in
(select hidfrom Hospital locationwhere hin < '2011/10/30' and
hin > '2011/10/1');
hid dop revenue
111 10/02/11 200000
hid dop revenue
111 10/03/11 300000
hid dop revenue
111 10/04/11 400000
hid dop revenue
111 10/05/11 1000000
hid dop revenue
111 10/06/11 500000
-
7/28/2019 CS331 Project 2
12/14
hid dop revenue
111 10/07/11 6000000
hid dop revenue
111 10/08/11 7000000
Justin Dragone CS331 November. 28, 2011 Project 2
8. Create a bill for patient Josephine Lau for procedures performed duringa hospitalization from June 8 June 14, 2011. Display the patientname, date, procedure name and cost.
Select pfirst, plast, cost, procedurefrom Patient, Hospital locationwhere pid in
(select hidfrom Hospital locationwhere hin < '2011/6/14' and
hin > '2011/6/8');
Pid Pfirst Plast Cost procedure
123456782 Josephine Lau $1,000.00 Surgery heartvalve
-
7/28/2019 CS331 Project 2
13/14
Justin Dragone CS331 November. 28, 2011 Project 2
9. Identify all patients seen last year who received kidney dialysis.
Display the patient name, date of service and doctor who prescribedthe procedure.
Select pfirst, plast, dov, procedure, doctorfrom Patient, Hospital locationwhere pid in
(select hidfrom Hospital locationwhere hin < '2011/11/26' and
hin > '2010/11/26');
Pid Pfirst Plast Dov Procedure Doctor
123456787 John Doe 01/05/11 Kidneydialysis
Dr. Kyle
-
7/28/2019 CS331 Project 2
14/14
Justin Dragone CS331 November. 28, 2011 Project 2
10. Identify all medical procedures performed for patient AngelinaBrown in the last five years. Display the procedure name, date ofservice and assigned doctor.
Select pfirst, plast, procedure, dov, doctorfrom Patient, Hospital location
where pid in
(select pidfrom Patient
where pfirst = 'Angelina, plast = 'Brown')(select hidfrom Hospital locationwhere hin < '2006/11/26' and
hin > '2010/11/26');
pid pfirst plast dov Procedure Doctor
123456781 Angelina Brown 03/05/11 Surgery brain Dr. Smith