CS331
Project 2
Justin Dragone
CS331
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,
Justin Dragone
CS331
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 blood transfusion, xray leg, surgery kidney stone, examination hand); create table Department (did char(5) primary key, cardiology varchar(20) not null,
Justin Dragone
CS331
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 Queens hospital. Display the patient name, date of visit and diagnosis.
select pfirst, plast, dov, diagnosis from Patient where pid in (select pid from Patient where pin = yesterday(), doctor = 'Dr.Smith' and hid in (select hid from hospital location where hid = 'Queens Hospital');
Pfirst Angela
Plast Brown
Dov 11/26/11
Justin Dragone
CS331
Project 2
2. Identify the number procedures performed by each hospital location last year. Display the hospital name and number of procedures. Display one row for each hospital. Select hname, procedure from Hospital Location where hid in (select hid from Hospital Location where hin < '2011/11/26' and hin > '2010/11/26');
procedure 10000
procedure 20000
procedure 15000
Justin Dragone
CS331
Project 2
3. Identify the number procedures performed by each department last year. Display the hospital, department name and number of procedures. Display one row for each hospital and department. Select hname, department, procedure from Hospital location, department where hid in (select hid from Hospital Location where hin < '2011/11/26' and hin > '2010/11/26');
hid 111
hid 222
hid 333
department cardiology
procedure 50000
radiology oncology general Justin Dragone CS331 emergency 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 location where pid in (select pid from Patient where pin = yesterday(), pfirst = 'Angelina, plast = 'Brown', procedure = 'CAT scan');
pid 123456781
pfirst Angelina
plast Brown
Justin Dragone 5.
CS331
Project 2
Justin Dragone
CS331
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 location where hid in (select hid from Hospital location where hin < '2011/11/26' and hin > '2011/11/20');
hid 111
dop 11/20/11
procedure 20
hid 111
dop 11/21/11
procedure 30
hid 111
dop 11/22/11
procedure 40
hid 111
dop 11/23/11
procedure 10
hid 111
dop 11/24/11
procedure 50
7. Identify the revenue for day last month. Display the date and revenue. Display one row for each day. Select dop, revenue from Hospital location where hid in (select hid from Hospital location where hin < '2011/10/30' and hin > '2011/10/1');
hid 111
dop 10/02/11
revenue 200000
hid 111
dop 10/03/11
revenue 300000
hid 111
dop 10/04/11
revenue 400000
hid 111
dop 10/05/11
revenue 1000000
hid 111
dop 10/06/11
revenue 500000
8. Create a bill for patient Josephine Lau for procedures performed during a hospitalization from June 8 June 14, 2011. Display the patient name, date, procedure name and cost.
Select pfirst, plast, cost, procedure from Patient, Hospital location where pid in (select hid from Hospital location where hin < '2011/6/14' and hin > '2011/6/8');
Pid 123456782
Pfirst Josephine
Plast Lau
Cost $1,000.00
Justin Dragone
CS331
Project 2
9. Identify all patients seen last year who received kidney dialysis. Display the patient name, date of service and doctor who prescribed the procedure.
Select pfirst, plast, dov, procedure, doctor from Patient, Hospital location where pid in (select hid from Hospital location where hin < '2011/11/26' and hin > '2010/11/26');
Pid
Pfirst
Plast Doe
Dov 01/05/11
123456787 John
Justin Dragone
CS331
Project 2
10. Identify all medical procedures performed for patient Angelina Brown in the last five years. Display the procedure name, date of service and assigned doctor.
Select pfirst, plast, procedure, dov, doctor from Patient, Hospital location where pid in (select pid from Patient where pfirst = 'Angelina, plast = 'Brown') (select hid from Hospital location where hin < '2006/11/26' and hin > '2010/11/26');
pid
pfirst
plast Brown
dov 03/05/11
123456781 Angelina