1. /* Attention MaTTHEW!! AS you will observe, it took me until
the table
Related_Persons to finally hit my stride on this SQL table
creation. Up until
Related_Persons I was codeing table defines the hard way. */
/* Location_type used in Address table. Combines Latitude and
Longitude */
create type Location_type as object
(Latitude number(9,6)
,Longitude number(9,6)
);
/
/* Phone_type used in Physician and Employee tables. */
create type Phone_type as object
(area_code number(3)
,exchange number(3)
,last_four number(4)
);
/
create table Address
(addressID number primary key
,street_adr varchar(20)
,city varchar(20)
,state varchar(2)
,zip number(5)
,location Location_type
);
DESCRIBE Address;
alter table Address
modify (zip not null);
alter table Address
modify (location not null);
alter table Address
modify (state not null);
alter table Address
modify (city not null);
alter table Address
modify (street_adr not null);
create table Person
(PERSONID NUMBER(7) NOT NULL
,LAST_NAME VARCHAR2(20) not null
,FIRST_NAME VARCHAR2(20) not null
,ADDRESSID NUMBER(7) not null
,PERS_IS_REL CHAR(1) not null
2. ,PERS_IS_PAT CHAR(1) not null
,PERS_IS_PHY CHAR(1) not null
,PERS_IS_EMP CHAR(1) not null
);
ALTER table Person
add constraint Person_addressID_fk FOREIGN KEY (addressID)
references Address (addressID);
create table Related_Persons
(related_person_ID number
,PersonID number(7)
,relationship varchar(20) not null
,constraint related_person_ID_pk PRIMARY KEY
(related_person_ID)
,constraint PersonID_fk FOREIGN KEY (PersonID)
references Person (PersonID)
);
create table Patient
(patient_id number
,PersonID number(7) not null
,date_of_birth date not null
,gender char(1) not null
,ethnicity char(1) not null
,occupation varchar(20)
,constraint patient_id_pk PRIMARY KEY (patient_id)
,constraint Patient_PersonID_fk FOREIGN KEY (PersonID)
references Person (PersonID)
);
drop table Physician;
create table Physician
(physician_id number
,phone Phone_type not null
,PersonID number(7) not null
,fax number(7)
,constraint Physician_physician_id_pk PRIMARY KEY
(physician_id)
,constraint Physician_PersonID_fk FOREIGN KEY (PersonID)
references Person (PersonID)
);
create table Contact
(contact_id number(7)
,patientID number(7) not null
,related_person_id number(7) not null
,type_of_contact varchar(10) not null
,category varchar(10) not null
,length_of_time interval day to second not null
3. ,addressID number
,constraint Contact_contact_id_pk PRIMARY KEY (contact_id)
,constraint Contact_addressID_fk FOREIGN KEY (addressID)
references Address(addressID)
);
create table Employee
(employee_id number
,PersonID number(7) not null
,phone Phone_type not null
,constraint Employee_employee_id_pk PRIMARY KEY (employee_id)
,constraint Employee_PersonID_fk FOREIGN KEY (PersonID)
references Person (PersonID)
);
create table Test
(test_id number(7)
,patientID number(7) not null
,physician_id number(7) not null
,test_name varchar(10) not null
,test_date date not null
,lab_name varchar(10) not null
,type varchar(10) not null
,measure number(3,6) not null
,result varchar(10) not null
,benchmark varchar(10)
,interpretation varchar(10)
,constraint Test_test_id_pk PRIMARY KEY (test_id)
,constraint Test_patientID_fk FOREIGN KEY (patientID)
references Patient(patient_id)
,constraint Test_physician_id_fk FOREIGN KEY (physician_id)
references Physician(physician_id)
);
drop table Incident;
create table Incident
(incident_id number(7)
,date_time_occured timestamp not null
,diagnosis_probability number(3,3) not null
,disease_id number not null
,patient_id number not null
,physician_id number not null
,region_id number not null
,employee_id number not null
,date_received date not null
,date_recorded date not null
,date_confirmed date
,constraint Incident_incident_id_pk PRIMARY KEY
(incident_id)
,constraint Incident_disease_id_fk FOREIGN KEY
(disease_id)
4. references Disease(disease_id)
,constraint Incident_patient_id_fk FOREIGN KEY
(patient_id)
references Patient(patient_id)
,constraint Incident_physician_id_fk FOREIGN KEY
(physician_id)
references Physician(physician_id)
/*,constraint Incident_region_id_fk FOREIGN KEY
(region_id)
references Region(region_id) */
,constraint Incident_employee_id_fk FOREIGN KEY
(employee_id)
references Employee(employee_id)
);
create table Disease
(disease_id number
,disease_name varchar(20) not null
,discovery_date date not null
,discovered_by number not null
,source varchar(10) not null
,germination_period timestamp not null
,constraint Disease_disease_id_pk PRIMARY KEY (disease_id)
);
create table Transmission_Mechanism
(mechanism_id number(7)
,category number(7) not null
,probability_of_transfer number(3,3) not null
,comments varchar(256)
,disease_id number not null
,constraint Transmission_mechanism_id_pk PRIMARY KEY
(mechanism_id)
,constraint Transmission_disease_id_fk FOREIGN KEY
(disease_id)
references Disease(disease_id)
);
create table Symptom
(symptom_id number
,description varchar(64) not null
,severity integer not null
,percent_of_cases number(6,3) not null
,time_to_appear INTERVAL DAY(2) TO SECOND
,disease_id number not null
,constraint Symptom_symptom_id_pk PRIMARY KEY (symptom_id)
,constraint Symptom_disease_id_fk FOREIGN KEY (disease_id)
references Disease(disease_id)
);
create table Observed_Symptom
(incident_id number
5. ,symptom_num number not null
,description varchar(64) not null
,severity number not null
,length_of_time INTERVAL DAY(2) TO SECOND not
null
,constraint Observed_incident_id_pk PRIMARY KEY
(incident_id,symptom_num)
,constraint Observed_incident_id_fk Foreign KEY
(incident_id)
References Incident(incident_id)
);
create table Region
(region_id number
,name varchar(20) not null
,description varchar(64) not null
,population number(7) not null
,constraint Region_region_id_pk PRIMARY KEY (region_id)
);
Describe Observed_Symptom;
6. ,symptom_num number not null
,description varchar(64) not null
,severity number not null
,length_of_time INTERVAL DAY(2) TO SECOND not
null
,constraint Observed_incident_id_pk PRIMARY KEY
(incident_id,symptom_num)
,constraint Observed_incident_id_fk Foreign KEY
(incident_id)
References Incident(incident_id)
);
create table Region
(region_id number
,name varchar(20) not null
,description varchar(64) not null
,population number(7) not null
,constraint Region_region_id_pk PRIMARY KEY (region_id)
);
Describe Observed_Symptom;