create database HospitalSystem;
create table person(
National_ID int PRIMARY key,
FirstName varchar(50) check(FirstName like '^[A-Za-z]+$') not null,
LastName varchar(50) check(LastName like '^[A-Za-z]+$') not null,
BirthDate date not null,
City varchar(50) not null,
street varchar(50) not null,
gender char check(gender in ('M','F')),
state varchar(50) not null
)
create table Contact(
National_ID int ,
Contact varchar(15) check(Contact like '^[0-9]+$'),
PRIMARY KEY (National_ID, Contact),
FOREIGN KEY (National_ID) REFERENCES person(National_ID)
)
create table Email(
National_ID int,
email varchar(50) check(email like '^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$')
PRIMARY KEY (National_ID,email)
FOREIGN KEY (National_ID) REFERENCES person(National_ID)
)
create table Employee(
National_ID int ,
Employee_ID int PRIMARY key,
Salary money not null,
Hire_Date date not null,
Resign_Date date null,
FOREIGN KEY (National_ID) REFERENCES person(National_ID)
)
create table Nurse(
Nurse_ID int PRIMARY key,
Employee_ID int,
shift varchar(50),
FOREIGN KEY (Employee_ID) REFERENCES Employee(Employee_ID)
)
create table Department(
Department_Name varchar(50) PRIMARY key,
Department_Floor int not null,
Department_Building int not null
)
create table Nurse_Department(
Nurse_ID int,
Department_Name varchar(50),
PRIMARY KEY (Nurse_ID,Department_Name),
FOREIGN KEY (Nurse_ID) REFERENCES Nurse(Nurse_ID),
FOREIGN KEY (Department_Name) REFERENCES Department(Department_Name)
)
create table Doctor(
Doctor_ID int PRIMARY KEY,
Department_Name varchar(50),
Employee_ID int,
Year_Of_Experience int DEFAULT 0,
FOREIGN KEY (Department_Name) REFERENCES Department(Department_Name),
FOREIGN KEY (Employee_ID) REFERENCES Employee(Employee_ID)
)
create table Doctor_Qualification(
Doctor_ID int,
Qualification varchar(50),
PRIMARY KEY(Doctor_ID,Qualification),
FOREIGN KEY (Doctor_ID) REFERENCES Doctor(Doctor_ID)
)
create table NonScientific_Employee(
NSE_ID INT PRIMARY KEY,
NSE_ROLE varchar(50),
Department_Name varchar(50),
Employee_ID int,
FOREIGN KEY (Department_Name) REFERENCES Department(Department_Name),
FOREIGN KEY (Employee_ID) REFERENCES Employee(Employee_ID)
)
create table Device(
Device_ID int PRIMARY KEY,
Device_Name varchar(50) not null,
Device_Type varchar(50) not null
)
create table Room(
Room_ID int PRIMARY KEY,
Room_Type varchar(50) not null,
Room_Capacity int not null,
Department_Name varchar(50),
Device_ID int,
FOREIGN KEY (Department_Name) REFERENCES Department(Department_Name),
FOREIGN KEY (Device_ID) REFERENCES Device(Device_ID),
)
create table Nurse_AssignedRoom(
Room_ID int,
Nurse_ID int
PRIMARY KEY(Room_ID,Nurse_ID),
FOREIGN KEY (Room_ID) REFERENCES Room(Room_ID),
FOREIGN KEY (Nurse_ID) REFERENCES Nurse(Nurse_ID),
)
create table Patient(
Patient_ID int PRIMARY KEY,
Residency_Start_Date date not null,
Residency_End_Date date null,
Room_ID int,
National_ID int,
FOREIGN KEY (Room_ID) REFERENCES Room(Room_ID),
FOREIGN KEY (National_ID) REFERENCES person(National_ID)
)
create table Prescription(
Prescription_ID int PRIMARY KEY,
Prescription_Date date not null,
Instructions varchar(50),
Diagnosis_Code varchar(50) not null,
Patient_ID int
FOREIGN KEY (Patient_ID) REFERENCES Patient(Patient_ID)
)
create table Medicine(
Medicine_ID int PRIMARY KEY,
Medicine_Name varchar(50),
Expiry_Date date
)
create table Prescription_Medicine(
Prescription_ID int,
Medicine_ID int,
Quantity int not null,
Dosage varchar(50) check(Dosage like '^\d+(\.\d+)?(mg|ml|g|L)$') not null,
Frequency int not null,
PRIMARY KEY(Prescription_ID,Medicine_ID),
FOREIGN KEY (Prescription_ID) REFERENCES Prescription(Prescription_ID),
FOREIGN KEY (Medicine_ID) REFERENCES Medicine(Medicine_ID)
)
create table Appointment(
Appointment_ID int PRIMARY KEY,
Appointment_Status varchar(50)
check(Appointment_Status in('Pending','Confirme','Complete','Canceled','Reschedule','No Show')),
Room_ID int,
Appointment_Date datetime2 not null,
Patient_ID int,
Doctor_ID int ,
FOREIGN KEY (Patient_ID) REFERENCES Patient(Patient_ID),
FOREIGN KEY (Room_ID) REFERENCES Room(Room_ID),
FOREIGN KEY (Doctor_ID) REFERENCES Doctor(Doctor_ID)
)
create table Bill(
Appointment_ID int PRIMARY KEY,
amount money not null,
Tax money not null ,
Discount decimal(4,2)
FOREIGN KEY (Appointment_ID) REFERENCES Appointment(Appointment_ID)
)
Y3JlYXRlIGRhdGFiYXNlIEhvc3BpdGFsU3lzdGVtOwpjcmVhdGUgdGFibGUgcGVyc29uKApOYXRpb25hbF9JRCBpbnQgUFJJTUFSWSBrZXksCkZpcnN0TmFtZSB2YXJjaGFyKDUwKSBjaGVjayhGaXJzdE5hbWUgbGlrZSAnXltBLVphLXpdKyQnKSBub3QgbnVsbCwKTGFzdE5hbWUgIHZhcmNoYXIoNTApIGNoZWNrKExhc3ROYW1lICBsaWtlICdeW0EtWmEtel0rJCcpIG5vdCBudWxsLApCaXJ0aERhdGUgZGF0ZSBub3QgbnVsbCwKQ2l0eSB2YXJjaGFyKDUwKSBub3QgbnVsbCwKc3RyZWV0IHZhcmNoYXIoNTApIG5vdCBudWxsLApnZW5kZXIgY2hhciBjaGVjayhnZW5kZXIgaW4gKCdNJywnRicpKSwKc3RhdGUgdmFyY2hhcig1MCkgbm90IG51bGwKKQpjcmVhdGUgdGFibGUgQ29udGFjdCgKTmF0aW9uYWxfSUQgaW50ICwKQ29udGFjdCB2YXJjaGFyKDE1KSBjaGVjayhDb250YWN0IGxpa2UgJ15bMC05XSskJyksCiBQUklNQVJZIEtFWSAoTmF0aW9uYWxfSUQsIENvbnRhY3QpLAogRk9SRUlHTiBLRVkgKE5hdGlvbmFsX0lEKSBSRUZFUkVOQ0VTIHBlcnNvbihOYXRpb25hbF9JRCkKKQpjcmVhdGUgdGFibGUgRW1haWwoCk5hdGlvbmFsX0lEIGludCwKZW1haWwgdmFyY2hhcig1MCkgY2hlY2soZW1haWwgbGlrZSAnXlthLXpBLVowLTkuXyUrLV0rQFthLXpBLVowLTkuLV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