-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathp1-tables.sql
104 lines (102 loc) · 2.62 KB
/
p1-tables.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
-- The following commands drop the tables in case you have them
-- from earlier runs.
-- Note the order we are creating the tables and the order we are removing
-- them due to the foreign key constraints.
DROP TABLE IF EXISTS charts;
DROP TABLE IF EXISTS symptoms;
DROP TABLE IF EXISTS diagnoses;
DROP TABLE IF EXISTS medications;
DROP TABLE IF EXISTS reportedallergies;
DROP TABLE IF EXISTS staff;
DROP TABLE IF EXISTS patients;
DROP TABLE IF EXISTS dosage;
DROP TABLE IF EXISTS inferredallergies;
DROP TABLE IF EXISTS drugs;
CREATE TABLE staff (
staff_id CHAR(5),
role CHAR(1),
name CHAR(15),
login CHAR(8),
password CHAR(30),
PRIMARY KEY (staff_id)
);
CREATE TABLE patients (
hcno CHAR(5),
name CHAR(15),
age_group CHAR(5),
address CHAR(30),
phone CHAR(10),
emg_phone CHAR(10),
PRIMARY KEY (hcno)
);
CREATE TABLE charts (
chart_id CHAR(5),
hcno CHAR(5),
adate DATE,
edate DATE,
PRIMARY KEY (chart_id),
FOREIGN KEY (hcno) REFERENCES patients
);
CREATE TABLE symptoms (
hcno CHAR(5),
chart_id CHAR(5),
staff_id CHAR(5),
obs_date DATE,
symptom CHAR(15),
PRIMARY KEY (hcno, chart_id, staff_id, symptom, obs_date),
FOREIGN KEY (hcno) REFERENCES patients,
FOREIGN KEY (chart_id) REFERENCES charts,
FOREIGN KEY (staff_id) REFERENCES staff
);
CREATE TABLE diagnoses (
hcno CHAR(5),
chart_id CHAR(5),
staff_id CHAR(5),
ddate DATE,
diagnosis CHAR(20),
PRIMARY KEY (hcno, chart_id, staff_id, diagnosis, ddate),
FOREIGN KEY (hcno) REFERENCES patients,
FOREIGN KEY (chart_id) REFERENCES charts,
FOREIGN KEY (staff_id) REFERENCES staff
);
CREATE TABLE drugs (
drug_name CHAR(15),
category CHAR(25),
PRIMARY KEY(drug_name)
);
CREATE TABLE dosage (
drug_name CHAR(15),
age_group CHAR(5),
sug_amount INT,
PRIMARY KEY (drug_name, age_group),
FOREIGN KEY (drug_name) REFERENCES drugs
);
CREATE TABLE medications (
hcno CHAR(5),
chart_id CHAR(5),
staff_id CHAR(5),
mdate DATE,
start_med DATE,
end_med DATE,
amount INT,
drug_name CHAR(15),
PRIMARY KEY (hcno,chart_id,staff_id,mdate,drug_name),
FOREIGN KEY (hcno) REFERENCES patients,
FOREIGN KEY (chart_id) REFERENCES charts,
FOREIGN KEY (staff_id) REFERENCES staff,
FOREIGN KEY (drug_name) REFERENCES drugs
);
CREATE TABLE reportedallergies (
hcno CHAR(5),
drug_name CHAR(15),
PRIMARY KEY(hcno, drug_name),
FOREIGN KEY (hcno) REFERENCES patients,
FOREIGN KEY (drug_name) REFERENCES drugs
);
CREATE TABLE inferredallergies (
alg CHAR(15),
canbe_alg CHAR(15),
PRIMARY KEY(alg, canbe_alg),
FOREIGN KEY (alg) REFERENCES drugs,
FOREIGN KEY (canbe_alg) REFERENCES drugs
);