-
Notifications
You must be signed in to change notification settings - Fork 0
/
hospital-schema.sql
120 lines (107 loc) · 3.12 KB
/
hospital-schema.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
DROP DATABASE IF EXISTS hospital;
CREATE DATABASE hospital;
USE hospital;
CREATE TABLE Person (
ID INT PRIMARY KEY,
name VARCHAR(255),
address VARCHAR(255),
phone_number VARCHAR(20)
);
CREATE TABLE Physician (
physician_ID INT PRIMARY KEY,
expertise VARCHAR(255),
certification_number VARCHAR(255),
person_ID INT,
FOREIGN KEY (person_ID) REFERENCES Person (ID)
);
CREATE TABLE Nurse (
nurse_ID INT PRIMARY KEY,
certification_number VARCHAR(255),
person_ID INT,
FOREIGN KEY (person_ID) REFERENCES Person (ID)
);
CREATE TABLE Payable_Items (
payable_ID INT PRIMARY KEY,
fee DECIMAL(10,2)
);
CREATE TABLE Room (
capacity INT,
number INT PRIMARY KEY,
payable_ID INT,
fee DECIMAL(10,2),
FOREIGN KEY (payable_ID) REFERENCES Payable_Items (payable_ID)
);
CREATE TABLE Patient (
patient_id INT PRIMARY KEY,
person_ID INT,
room_number INT,
FOREIGN KEY (person_ID) REFERENCES Person (ID),
FOREIGN KEY (room_number) REFERENCES Room (number)
);
CREATE TABLE Monitors (
physician_id INT,
patient_id INT,
duration INT,
PRIMARY KEY (physician_id, patient_id),
FOREIGN KEY (physician_id) REFERENCES Physician (physician_ID),
FOREIGN KEY (patient_id) REFERENCES Patient (patient_id)
);
CREATE TABLE Health_Record (
record_ID INT PRIMARY KEY,
disease VARCHAR(50),
status VARCHAR(50),
date DATE,
patient_ID INT,
FOREIGN KEY (patient_ID) REFERENCES Patient (patient_id)
);
CREATE TABLE Invoice (
invoice_ID INT PRIMARY KEY,
patient_ID INT,
date_issued DATE,
total_fee DECIMAL(10,2),
date_paid DATE,
amount_paid DECIMAL(10,2),
FOREIGN KEY (patient_ID) REFERENCES Patient (patient_id)
);
CREATE TABLE Instruction (
code INT PRIMARY KEY,
Description VARCHAR(50),
physician_ID INT,
patient_ID INT,
fee DECIMAL(10,2),
payable_ID INT,
FOREIGN KEY (physician_ID) REFERENCES Physician (physician_ID),
FOREIGN KEY (payable_ID) REFERENCES Payable_Items (payable_ID),
FOREIGN KEY (patient_ID) REFERENCES Patient (patient_id)
);
CREATE TABLE OrdersInstruction (
instruction_code INT,
physician_ID INT,
patient_ID INT,
date DATE,
PRIMARY KEY (instruction_code, physician_ID, patient_ID),
FOREIGN KEY (physician_ID) REFERENCES Physician (physician_ID),
FOREIGN KEY (patient_ID) REFERENCES Patient (patient_id),
FOREIGN KEY (instruction_code) REFERENCES Instruction (code)
);
CREATE TABLE ExecutesInstruction (
instruction_code INT,
date DATE,
status VARCHAR(50),
nurse_ID INT,
patient_ID INT,
PRIMARY KEY (instruction_code, nurse_ID, patient_ID),
FOREIGN KEY (nurse_ID) REFERENCES Nurse (nurse_ID),
FOREIGN KEY (patient_ID) REFERENCES Patient (patient_id),
FOREIGN KEY (instruction_code) REFERENCES Instruction (code)
);
CREATE TABLE AdministerMedicine (
medication_name VARCHAR(50),
nurse_ID INT,
patient_ID INT,
amount INT,
date DATE,
PRIMARY KEY (medication_name, nurse_ID, patient_ID),
FOREIGN KEY (nurse_ID) REFERENCES Nurse (nurse_ID),
FOREIGN KEY (patient_ID) REFERENCES Patient (patient_id)
);