Admission
A patient arrives at the hospital. They are registered with a unique identifier, name, age, and date of birth, then assigned to one of the available rooms.
A relational schema for hospital administration. Patients, doctors, rooms, medication, and billing.
A coursework project for Database Applications and Information Systems. The brief was to design and document a relational schema for a hospital management system, then describe the application functions that would operate on top of it. Eight tables cover patient admission, room allocation, diagnoses, medicament inventory, and billing.
Eight tables with foreign-key relationships. Click any table to see what it connects to. Click again to clear.
The schema in action. Four stages of a typical hospital visit, with the tables and queries that support each one.
A patient arrives at the hospital. They are registered with a unique identifier, name, age, and date of birth, then assigned to one of the available rooms.
A doctor examines the patient and records a diagnosis. Each diagnosis is linked to the attending physician, so the system can later report which doctor is treating which patient.
Treatment requires checking the medicament inventory. The hospital tracks stock levels and expiration dates so that expired or out-of-stock items are not prescribed.
Once treatment is complete, a bill is generated and attached to the patient. The total amount covers the treatment and any medications used.
The schema is loaded with the sample data already inserted. Write your own query or pick one from the samples below, then use Cmd/Ctrl + Enter to run.
Five queries that exercise the schema across joins, aggregations, and conditional expressions.
SELECT
P.Pname,
P.Age,
R.Room_no,
R.Type
FROM
PATIENT P
JOIN ROOM R ON P.Room_no = R.Room_no
ORDER BY
P.Pname;
SELECT
P.Pname,
ROUND(SUM(B.Amount), 2) AS Total
FROM
PATIENT P
JOIN BILLS B ON P.Patient_no = B.Patient_no
GROUP BY
P.Patient_no
ORDER BY
Total DESC;
SELECT
D.Dname,
D.Gender,
DG.Diagnosis_name
FROM
DOCTOR D
JOIN DIAGNOSIS DG ON D.Doctor_no = DG.Doctor_no
ORDER BY
D.Dname;
SELECT
Mname,
Quantity_in_inventory,
Expiration_date,
CASE
WHEN Expiration_date < '2025-01-01' THEN 'Expiring soon'
WHEN Expiration_date < '2026-01-01' THEN 'This year'
ELSE 'Future'
END AS Status
FROM
MEDICAMENTS
ORDER BY
Expiration_date;
SELECT
COUNT(*) AS Bills,
ROUND(SUM(Amount), 2) AS Total,
ROUND(AVG(Amount), 2) AS Average,
ROUND(MIN(Amount), 2) AS Lowest,
ROUND(MAX(Amount), 2) AS Highest
FROM
BILLS;