You are on page 1of 30

Introduction to CARDIC Hospital:

CARDIC Hospital has recently renovated its building. This has allowed it to
expand its perimeter to include more space for equipment and accommodate more
patients. However, this brings with it an issue of how to store all the necessary data
if the new found patients and work in general. Our team was asked to help suggest
and implement a solution to fix the issue at hand. After much deliberation and
research, we have found that a Database should be build along with a Database
Management System (DBMS). A Database Management System is used to manage
the database along with edit or insert content into it. It’s a software designed to
control a storage of data called a database. Based on our research, the easiest and
most effective programming languages for the job include C, C++, Java, Ruby On
Rails, Python and SQL. After careful consideration, we decided to go with SQL as
it is the most straightforward in its syntax, is fairly human-readable and is
essentially centered around database management, compared to the more diverse
use of the other languages.
Use-Case Diagram
Business Rules:
These are the Business Rules implemented in the database:
1. All Patients must have their name, contact details, current address and next
of kin information registered, regardless of whether they are in or out.

2. Each Patient is categorized as either In-Patient or Out-Patient.

3. Each Ward must have three nurses. One Head Nurse and two General
Nurses.
4. Each Ward must have a telephone extension.

5. Doctors must list their names, speciality and telephone extension.

6. All hospital staff must be given a unique staff number.

7. All appointments must include the examination room used.

8. Each examination room record must contain the name of the doctor in
charge.

9. All Nurses salaries must be recorded.


ER Model:
Relational Schema:
Normalisation Process:

Normalisation is a database design technique that is used to organize data


inside tables to reduce data redundancies and functional dependancies.

1NF:
1NF is the first normal form for any table. There are only two rules:
 Each table cell should contain a single value.
 Each record needs to be unique.

Diagram 2.1 – Ward table (1NF)


1NF is the first form for normalization. In this case, the table is already in
first normal form. There is no additional data in the columns. Each record is both
unique and a single entry of data.
Diagram 2.2 – Nurse Table
The table is in 1NF form. There is no additional value to be added. Each data
is unique and a single entry.

Diagram 2.3 – Doctor Table


Table is in 1NF form. There is no additional value to be added. Each data is
unique and a single entry.

Diagram 2.4 – Patient Table


Table is in 1NF form. There is no additional value to be added. Each data is
unique and a single entry.

Diagram 2.5 – Appointment Table


Table is in 1NF form. There is no additional value to be added. Each data is
unique and a single entry.

Diagram 2.6 – Examination Room Table


Table is in 1NF form. There is no additional value to be added. Each data is
unique and a single entry.

2NF:

Patient Table:
Before:

Diagram – Patient Table Before 2NF

After:

Diagram – Patient Information Table


Diagram – Patient Type Table

Diagram – Bed Table


The Patient table is divided into three tables Patient Information, Patient ID
and Bed table. Patient Information and Patient Types. The primary key for Patient
Information is Patient ID, which exists in both tables. But Patient Type is the
primary key used in the Patient Type table. All the different columns in each tables
are arranges to be functionally dependant on each other. For example, patient
name, addresses, phone numbers of both Patient and Next of Kin, date of birth and
gender are all functionally dependant on each other and can be categorized as
patient information. Whereas, patient type, date of arrival, both actual and expected
date of departure as well as the duration of stay will be dependant on each other,
and can be labelled as related to the patient type. The Bed table has only the ward
number and bed number, which are functionally dependant.
Appointment:

Before:

Diagram – Appointment
After:

Diagram – Doctor_ID
Diagram – Appointment_Num

The appointment table can be broken down into two tables, which are
Appointment Number and Doctor ID. Appointment Number uses the appointment
number as a primary key, whereas Doctor ID uses Staff Number as a primary key.
Both tables have attributes that are functionally dependant on the primary key.
Examination Room:
After:

Diagram – Patient Details


Diagram – Examination Table

Diagram – Doctor Details


The table can be broken down into three tables, Examination Table, Doctor
Details and Patient Details. Room Number is the foreign key in all three tables.
The examination table uses the appointment number as a primary key and all the
attributes are dependant on it. Patient Details uses Room Number as a primary key,
as the only other attribute is patient name, which is dependant on the room number.
The Doctor Details uses the room number as primary key also. All the attributes
are functionally dependant on the primary key.
Ward:
Before:
Diagram – Ward Before 2NF
After:
Diagram – Ward
The ward table can’t be broken down further as it already fits the criteria for
2NF.
Diagram – Doctors
The doctor table is already coherent with characteristics of 2NF.

Diagram – Nurses
The Nurses table is already coherent with the characteristics for 2NF.
3NF:

Ward:

Diagram – Ward
No adjustments are made as it fits the criteria for 3NF.
Nurse:
Before:

Diagram – Nurse
After:

Diagram – Salary

Diagram – Nurse Information


The table is split into a salary table and nurse information. The table

SQL Statements:

a) 1. Ward
create table Ward (No int, Name VARCHAR(255), Number_of_Beds
VARCHAR(255), Gender VARCHAR(255), Tel_Extension
VARCHAR(255));

insert into Ward(No, Name, Number_of_beds, Gender,


Tel_Extension)

values(1, 'Obstetrics','14', 'F', 'Ext 001'),(2, 'Pediatrics', '14', 'Mix', 'Ext


002'),
(3, 'Gynaecology', '14', 'F', 'Ext 003'), (4, 'Pathology', '14', 'Mix', 'Ext
004'),
(5, 'Cardiology', '14', 'Mix', 'Ext 005'), (6, 'Neurosurgery', '14', 'Mix',
'Ext 006'),
(7, 'Neurology', '14', 'Mix', 'Ext 007'), (8, 'Family Medicine', '14',
'Mix', 'Ext 008'),

(9, 'Otorhinolaryngology', '14', 'Mix', 'Ext 009'),


(10, 'Orthopedics', '14', 'Mix', 'Ext 010'), (11, 'Radiology', '14', 'Mix',
'Ext 011'), (12, 'Gastrology', '14', 'Mix', 'Ext 012'),

(13, 'Urology', '14', 'M', 'Ext 013'), (14, 'Ophtamology', '14', 'Mix', 'Ext
014'),
(15, 'Obstetric Gynaecology', '14', 'F', 'Ext 015'), (16, 'Oncology', '14',
'Mix' , 'Ext 016'),

(17, 'Psychiatry', '16', 'Mix', 'Ext 017');

select * from Ward;


Diagram 1.1 – Table for Wards

2. Nurse
create table Nurse(Name VARCHAR(255), Staff_Num int, Tel_Num
VARCHAR(255), DoB VARCHAR(255), Gender VARCHAR(255),
Position VARCHAR(255), Salary int);

insert into Nurse(Name, Staff_Num, Tel_Num, DoB, Gender, Position,


Salary)

values( 'Jamie Foster', 2111, '0102506991', '18/03/1997', 'F', 'Head Nurse',


2000),('Ken Norton', 2112, '0123628229', '29/09/1987', 'M', 'General Nurse',
2000),
('Jaime Reyes', 2113, '0102536991', '16/03/1997', 'F', 'Head Nurse', 2000),
('Kent Nelson', 2112, '0123638239', '27/09/1984', 'M', 'General Nurse',
2000),
('James Thornton', 2115, '0101406991', '14/03/1997', 'M', 'Head Nurse',
2000),('Kelly Steele', 2116, '0123623229', '18/06/1997', 'F', 'General Nurse',
2000),
('Jessica Simpson', 2117, '0141506991', '15/03/1997', 'F', 'Head Nurse',
2000),('John Steel ', 2118, '0121623229', '29/04/1997', 'M', 'General Nurse',
2000),
('Reuben Barnes', 2119, '0127373881', '18/09/1992', 'M', 'Head Nurse',
2000),('James Bond', 2120, '0122455627', '12/04/1993', 'F', 'General Nurse',
2000);

select * from Nurse;

Diagram 1.2 – Table of Nurses

3. Doctors
create table Doctor(Name VARCHAR(255), Staff_Num int, Specialty
VARCHAR(255), Tel_Ext VARCHAR(255));

insert into Doctor(Name, Staff_Num, Specialty, Tel_Ext)

values('Helen Cho', 1111, 'Cardiology', 'Ext 101'), ('Jack Jones', 1112,


'Pediatrics', 'Ext 102'),
('James Chin', 1113, 'Psychiatry', 'Ext 103'), ('Immanuel Kendricks', 1114,
'Pathology', 'Ext 104'),
('Alex Rodgers', 1115, 'Oncology', 'Ext 105'), ('Rodrick Gautz', 1116,
'Neurosurgery', 'Ext 106'),
('Jim Carrey', 1117, 'Radiology', 'Ext 107'), ('Heaven Canters', 1118,
'Gastrology', 'Ext 108'),
('Rick Feynman', 1119, 'Neurology', 'Ext 109'), ('Jimmy Seers', 1120,
'Gynaecology', 'Ext 110');

select * from Doctor;

Diagram 1.3 - Table for Doctors

4. Patients
create table patient(Patient_Type VARCHAR(255),Name VARCHAR(255),
Address1 VARCHAR(255), Tel_Num1 VARCHAR(255), DoB
VARCHAR(255), Gender VARCHAR(255), Date_Of_Regist
VARCHAR(255), Name_of_Kin VARCHAR(255), Relationship
VARCHAR(255), Address VARCHAR(255), Tel_Num int, Ward Int, Bed
int, Duration_of_Stay VARCHAR(255), Date_of_Arrival VARCHAR(255),
Date_of_Departure VARCHAR(255), Actual_Date_of_Departure
VARCHAR(255));
insert into patient(Patient_Type, Name, Address1, Tel_Num1 , DoB,
Gender, Date_Of_Regist, Name_of_Kin, Relationship, Address, Tel_Num,
Ward, Bed, Duration_of_Stay, Date_of_Arrival, Date_of_Departure,
Actual_Date_of_Departure)

values('In', 'James Bond', '12, Jameson Street, New York', '0102738382',


'12/03/1982', 'M', '12/05/2001', 'Mary Bloomfield', 'Mother', '12, Jameson
Street, New York', '0123337838', 1, 12, '2 weeks', '03/03/2020', '17/03/2020',
'18/03/2020'),

('Out', 'Jessica Jones', '12 Wicker Way, New Jersey', '0101334322',


'12/02/1982', 'F', '13/02/1992', 'Trish Walker', 'Sister', '42, Wallaby Way,
Sydney', '0101032433', 2, 2, '2 weeks', '03/03/2020', '17/03/2020',
'18/03/2020'),

('In','Jeniffer Bond', '12, Jameson Street, New York', '0112738382',


'12/03/1982', 'M', '12/06/2001', 'Mary Bloomfield', 'Mother', '12, Jameson
Street, New York', '0123337838', 2, 13, '2 weeks', '09/03/2020',
'26/03/2020', '27/03/2020'),

('Out', 'Jane Fonda', '13 Wicker Way, New Jersey', '0111334322',


'12/02/1982', 'F', '13/02/1992', 'Trisha Park', 'Sister', '42, Wallaby Way,
Sydney', '0101032433', 2, 3, '2 weeks', '09/03/2020', '26/03/2020',
'27/03/2020'),

('In','Larry Bloom', '13, Jameson Street, New York', '0102748382',


'11/03/1992', 'M', '13/05/2001', 'Marysol Bloom', 'Mother', '12, Jameson
Street, New York', '0123339838', 3, 13, '2 weeks', '14/03/2020',
'28/04/2020', '12/04/2020'),
('Out', 'Jeniffer Jones', '12 Wicker Street, New Jersey', '0101344322',
'12/02/1982', 'F', '13/02/1992', 'Patricia Walker', 'Sister', '43, Wallaby Way,
New Hampsire', '0121032433', 1, 1, '2 weeks', '14/03/2020', '28/04/2020',
'12/04/2020'),

('In', 'Herriot Bloom', '13, Jameson Street, New York', '0102848382',


'15/04/1994', 'M', '12/07/2001', 'Marysol Bloom', 'Mother', '12, Jameson
Street, New York', '0123339848', 2, 11, '2 months', '23/05/2020',
'23/07/2020', '24/07/2020'),

('Out', 'Jeniffer Walker', '14 Wicker Street, New Jersey', '0101344322',


'12/02/1982', 'F', '13/02/1992', 'Patty Walker', 'Sister', '47, Kingsley Road,
New Hampsire', '0121032433', 1, 1, '2 months', '23/05/2020', '23/07/2020',
'24/07/2020'),

('In', 'John Bond', '15, Jameson Street, New York', '0112738382',


'14/03/1982', 'M', '12/06/2001', 'Mary Bloomfield', 'Mother', '12, Jameson
Street, New York', '0133337838', 1, 11, '2 weeks', '03/03/2020',
'17/03/2020', '18/03/2020'),

('Out', 'Jessica Jones', '12 Wicker Way, New Jersey', '0101334322',


'12/02/1982', 'F', '13/02/1992', 'Trish Walker', 'Sister', '42, Wallaby Way,
New Hampshire', '0121012433', 3, 2, '2 weeks', '03/03/2020', '17/03/2020',
'18/03/2020'),

('In', 'Issac Newton', '14, Jameson Street, New Jersey', '010273382',


'13/09/1992','M', '12/06/2003', 'Mary Newton', 'Mother', '14, Jameson Street,
New York', '0123337838', 1, 14, '1 weeks', '01/02/2020', '07/02/2020',
'08/02/2020'),
('Out', 'Jessica Jones', '12 Wicker Way, New Jersey', '0101334322',
'12/02/1982', 'F', '13/02/1992', 'Trish Walker', 'Sister', '42, Wallaby Way,
Sydney', '0101032433', 1, 9, '1 weeks', '01/02/2020', '07/02/2020',
'08/02/2020'),

('In', 'Jamie Lannister', '14, Jameson Street, New Jersey', '010273382',


'19/04/1992', 'M', '19/06/2002', 'Mary Bloom', 'Mother', '14, Jameson Street,
New York', '0123337838', 1, 13, '1 weeks', '01/08/2020', '07/08/2020',
'08/08/2020'),

('Out', 'Jessica Jones', '12 Wicker Way, New Jersey', '0101334322',


'12/02/1982', 'F', '13/02/1992', 'Trish Walker', 'Sister', '42, Wallaby Way,
Sydney', '0101032433', 1, 8, '1 weeks', '01/08/2020', '07/08/2020',
'08/08/2020');

select * from patient;

Diagram 1.4 – Table for Patients


5. Appointments
create table Appointments(App_Num int, Patient_Num VARCHAR(255),
Name_of_Staff VARCHAR(255), Staff_Number int, Appointment_Date
varchar(255), App_Time VARCHAR(255), examination_room
Varchar(255), recommendation VARCHAR(255));
insert into Appointments(App_Num, Patient_Num, Name_of_Staff,
Staff_Number, Appointment_Date, App_Time, examination_room,
recommendation)
values(1, '121', 'Helen Cho', 1111, '14/02/2020','17:50 pm', 'E102', ''), (2,
'132', 'Immanuel Kendricks', 1114, '14/05/2020', '12:30 pm','L890', ''),
(3, '143', 'James Chin', 1113, '19/02/2020', '10:15 am', 'I102', ''), (4, '152',
'Rodrick Gautz', 1116, '16/02/2020', '16:20 pm', 'F121', ''),
(4, '162', 'Alex Rodgers', 1115, '20/02/2020', '12:15 pm', 'N02', ''), (5, '162',
'Heaven Canters', 1118, '17/02/2020', '14:20 pm', 'E768', ''),
(6, '929', 'Jim Carrey', 1117, '19/02/2020', '19:20 pm', 'E102', ''), (7, '182',
'Jimmy Seers', 1120, '19/10/2020', '10:10 am', 'B29', ''),
(8, '928', 'Rick Feynman', 1119, '18/02/2020', '15:20 pm', 'E102', ''), (9, '102',
'Jack Jones', 1112, '10/02/2020', '12:20 pm', 'B29', ''),
(10, '928', 'Jack Jones', 1112, '10/03/2020', '14:10 pm', 'I102', '');

select * from Appointments;

Diagram 1.5 – Table for Appointments


6. Examination Room
create table examination_room (Room_number varchar(255),
Doctor_in_charge varchar(255), Specialty varchar(255),
Appointment_number int, Appointment_Date varchar(255),
Appointment_Time varchar(255),Appointment_Duration varchar(255),
Appointment_Patient_Name varchar(255));
insert into examination_room (Room_number,Doctor_in_charge,
Specialty,Appointment_number, Appointment_date,
Appointment_time,Appointment_Duration, Appointment_Patient_Name)

values( 'E102', ' Dr Richard Feynman', 'Neurology', 1, '17/3/2020', '6:50a.m.',


'60 minutes', 'Sicky'),
( 'F121', 'Dr Helen Cho ', 'Cardiology', 8, '27/5/2020', '9:30a.m.', '20
minutes', 'VBF'),
('GH12', 'Dr James Chin ', 'Psychiatry', 23, '20/4/2020', '7:12a.m.', '40
minutes', 'TYU'),
('N02', 'Dr Rick Feynman ', 'Neurology', 7, '12/4/2020', '11:55p.m.', '50
minutes', 'NFBF'),
('E102', 'Dr Rick Feynman ', 'Neurology', 19, '1/4/2020', '1:09p.m.', '150
minutes', 'VVV'),
('E102', 'Dr Rick Feynman ', 'Neurology', 18, '5/4/2020', '1:45p.m.', '80
minutes', 'CCC'),
('L890', 'Dr Rick Feynman ', 'Neurology', 91, '19/4/2020', '8:30a.m.', '25
minutes', 'BBB'),
('E768', 'Dr HYJ', 'Kids', 10, '17/4/2020', '5:10p.m.', '90 minutes', 'AAA'),
('E102', 'Dr Alex Rodgers ', 'Oncology', 111, '15/4/2020', '10:00a.m.', '30
minutes', 'WEA'),
('E102', 'Dr ', 'Radiology', 13, '9/4/2020', '9:00a.m.', '20 minutes', 'BDD'),
('I102', 'Dr Helen Cho ', 'Cardiology', 14, '7/4/2020', '8:15a.m.', '15 minutes',
'RTE'),
('B29', 'Dr Rick Feynman ', 'Neurology', 17, '3/4/2020', '9:30a.m.', '45
minutes', 'JGD');

select * from examination_room;


Diagram 1.6 – Table for Examination Room
b)
i. List the details of patients that were allocated at the cardiology ward.
select* from patients where ward=5;

ii. Identify the total number patients allocated at each ward, categorised
by gender.
select count(Patient_Number) as Male_Ward1 from Patients where
Ward = 1 and Gender = 'M';
select count(Patient_Number) as Female_Ward1 from Patients where
Ward = 1 and Gender = 'F';
select count(Patient_Number) as Male_Ward2 from Patients where
Ward = 2 and Gender = 'M';
select count(Patient_Number) as Female_Ward2 from Patients where
Ward = 2 and Gender = 'F';
select count(Patient_Number) as Male_Ward3 from Patients where
Ward = 3 and Gender = 'M';
select count(Patient_Number) as Female_Ward3 from Patients where
Ward = 3 and Gender = 'F';
select count(Patient_Number) as Male_Ward4 from Patients where
Ward = 4 and Gender = 'M';
select count(Patient_Number) as Female_Ward4 from Patients where
Ward = 4 and Gender = 'F';
select count(Patient_Number) as Male_Ward5 from Patients where
Ward = 5 and Gender = 'M';
select count(Patient_Number) as Female_Ward5 from Patients where
Ward = 5 and Gender = 'F';
select count(Patient_Number) as Male_Ward6 from Patients where
Ward = 6 and Gender = 'M';
select count(Patient_Number) as Female_Ward6 from Patients where
Ward = 6 and Gender = 'F';
select count(Patient_Number) as Male_Ward7 from Patients where
Ward = 7 and Gender = 'M';
select count(Patient_Number) as Female_Ward7 from Patients where
Ward = 7 and Gender = 'F';
select count(Patient_Number) as Male_Ward8 from Patients where
Ward = 8 and Gender = 'M';
select count(Patient_Number) as Female_Ward8 from Patients where
Ward = 8 and Gender = 'F';
select count(Patient_Number) as Male_Ward9 from Patients where
Ward = 9 and Gender = 'M';
select count(Patient_Number) as Female_Ward9 from Patients where
Ward = 9 and Gender = 'F';
select count(Patient_Number) as Male_Ward10 from Patients where
Ward = 10 and Gender = 'M';
select count(Patient_Number) as Female_Ward10 from Patients where
Ward = 10 and Gender = 'F';
select count(Patient_Number) as Male_Ward11 from Patients where
Ward = 11 and Gender = 'M';
select count(Patient_Number) as Female_Ward11 from Patients where
Ward = 11 and Gender = 'F';
select count(Patient_Number) as Male_Ward12 from Patients where
Ward = 12 and Gender = 'M';
select count(Patient_Number) as Female_Ward12 from Patients where
Ward = 12 and Gender = 'F';
select count(Patient_Number) as Male_Ward13 from Patients where
Ward = 13 and Gender = 'M';
select count(Patient Number) as Female Ward13 from Patients where
Ward = 13 and Gender = 'F';
select count(Patient_Number) as Male_Ward16 from Patients where
Ward = 16 and Gender = 'M';
select count(Patient_Number) as Male_Ward17 from Patients where
Ward = 17 and Gender = 'M';

iii. List the number of currently available beds that are allocated in the
neurology ward.

select count(Ward) as Available_Beds_Neurology from Ward where


First_Name is null and Ward = 10;

iv. List the details of patients whose stays at the hospital exceed the
expected duration of stays at the ward, ordered by patient’s name.
select *from Patients where date_of_departure
>actual_date_of_departure order by Name ASC;

v. List the total number of patient who had an appointment with Dr


Helen Cho.
select *from Appointments where Name_of_staff='Helen Cho';

You might also like