-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHealthcare_7.sql
210 lines (192 loc) · 4.77 KB
/
Healthcare_7.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
create database Health;
use Health;
create table Userr
(UID int ,
UName varchar(20) NOT NULL,
Age int NOT null,
Gender char(1) NOT NULL,
Phone varchar(20) NOT NULL Unique,
EmailID varchar(100) NOT NULL UNIQUE,
StreetAdress varchar(100)not null,
city varchar(50)not null,
PostalCode varchar(20)not null,
primary key(UID),
CHECK (Gender in ('M','F','O')),
CHECK (Phone not like '%[^0-9-]%'),
check (EmailID not like '%[^A-Za-z0-9@._]%'));
create table Doctor
(DID int UNIQUE,
DName varchar(20) NOT NULL,
Age int NOT NULL,
Gender char(1)NOT NULL,
StreetAdress varchar(100) NOT NULL,
city varchar(50)NOT NULL,
PostalCode varchar(20)NOT NULL,
Phone varchar(20)NOT NULL UNIQUE,
Qualifications varchar(20)NOT NULL,
Specialization varchar(20)NOT NULL,
primary key(DID),
CHECK (Gender in ('M','F','O')),
CHECK (Phone not like '%[^0-9-]%'),
check (PostalCode not like '%[^A-Za-z0-9- ]%'));
create table Lab
(
LabID int,
LName varchar(40)NOT NULL,
Phone varchar(20)NOT NULL UNIQUE,
StreetAdress varchar(100)NOT NULL,
city varchar(50)NOT NULL,
PostalCode varchar(20)NOT NULL,
Tests varchar(100)NOT NULL,
primary key(LabID),
CHECK (Phone not like '%[^0-9-]%'),
check (PostalCode not like '%[^A-Za-z0-9- ]%'));
create table Company
( CID int,
CName varchar(40)not null,
Phone varchar(40)not null unique,
StreetAdress varchar(100)not null,
city varchar(50)not null,
PostalCode varchar(20)not null,
primary key(CID),
CHECK (Phone not like '%[^0-9-]%'),
check (PostalCode not like '%[^A-Za-z0-9- ]%'));
create table Drug
(DrID int,
DrName varchar(100) not null,
Prescription_req boolean not null,
Quantity int not null,
Sickness varchar(100)not null,
Symptoms varchar(80)not null,
CID int not null,
Price decimal(10,3) not null,
primary key (DrID),
foreign key(CID) references Company(CID) on delete cascade);
create table DeliveryAgency
(
DAID int,
DAName varchar(40)not null,
Phone varchar(20)not null unique,
StreetAdress varchar(100)not null,
city varchar(50)not null,
PostalCode varchar(20)not null,
primary key(DAID),
CHECK (Phone not like '%[^0-9-]%'),
check (PostalCode not like '%[^A-Za-z0-9- ]%'));
create table OpenSlots
(
SID int,
DID int not null,
STime time not null,
SDate date not null,
primary key(SID),
foreign key(DID) references Doctor(DID) on delete cascade);
create table Appointment
(
AID int,
SID int not null,
UID int not null,
primary key (AID),
foreign key(SID) references OpenSlots(SID),
foreign key (UID) references Userr(UID) on delete cascade);
create Table Test
(
TID int,
UID int not null,
DID int not null,
LabID int not null,
TTime time not null,
TDate date not null,
Tests varchar(50) not null,
primary key(TID),
foreign key(UID) references Userr(UID),
foreign key(DID) references Doctor(DID),
foreign key(LabID) references Lab(LabID) on delete cascade);
create table DiagnosticReports
(
DiRID int,
TID int not null,
DiRDate date not null,
Remarks varchar(30) not null,
primary key(DiRID),
foreign key(TID) references Test(TID));
create table Prescription
(
PrID int,
DrID int not null,
UID int not null,
DID int not null,
primary key(PrID),
foreign key(DrID) references Drug(DrID),
foreign key(UID) references Userr(UID) on delete cascade,
foreign key(DID) references Doctor(DID));
create table DeliveryArea
(
DeAID int,
DAID int not null,
PostalCode varchar(20) not null,
primary key(DeAID),
foreign key(DAID) references DeliveryAgency(DAID) on delete cascade,
check (PostalCode not like '%[^A-Za-z0-9- ]%'));
create table Orderr
(
OID int,
UID int not null,
DrID int not null,
OTime time not null,
ODate date not null,
StreetAdress varchar(100) not null,
city varchar(50)not null,
PostalCode varchar(20)not null,
price float(0)not null,
primary key(OID),
foreign key(UID) references Userr(UID),
foreign key(DrID) references Drug(DrID),
check (PostalCode not like '%[^A-Za-z0-9- ]%'));
create table Delivery
(
DeID int,
OID int not null,
DAID int null,
DeStatus varchar(30)not null,
ETA date not null,
primary key(DeID),
foreign key(OID) references Orderr(OID),
foreign key(DAID) references DeliveryAgency(DAID));
create table DoctorReviews
(
DReID int,
AID int not null,
Rating float(0)not null,
Review varchar(500),
primary key(DReID),
foreign key(AID) references Appointment(AID),
Check (Rating<=5 and Rating>=0));
create table DrugReviews
(
DrReID int,
OID int not null,
Rating float(0)not null,
Review varchar(500),
primary key(DrReID),
foreign key(OID) references Orderr(OID),
Check (Rating<=5 and Rating>=0));
create table DeliveryReviews
(
DeReID int,
DeID int not null,
Rating float(0)not null,
Review varchar(500),
primary key(DeReID),
foreign key(DeID) references Delivery(DeID),
Check (Rating<=5 and Rating>=0));
create table LabReviews
(
LRID int,
TID int not null,
Rating float(0)not null,
Review varchar(500),
primary key(LRID),
foreign key(TID) references Test(TID),
Check (Rating<=5 and Rating>=0));
-- drop database health;