0% found this document useful (0 votes)
30 views34 pages

DB Project

The document describes the structure and relationships within a clinical management database system. It includes entities like patients, doctors, medical records, tests, medications, and appointments. Relationships are shown in an ERD diagram and the tables are normalized into 1NF, 2NF and 3NF.

Uploaded by

marwasheikh592
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views34 pages

DB Project

The document describes the structure and relationships within a clinical management database system. It includes entities like patients, doctors, medical records, tests, medications, and appointments. Relationships are shown in an ERD diagram and the tables are normalized into 1NF, 2NF and 3NF.

Uploaded by

marwasheikh592
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 34

Database Project

Clinical Management System

Submitted by:
Marwa-BSEF21M015
Minahil-BSEF21M023

Submitted To:
Sir Asif Sohail
1. Introduction to the working of the system
An introduction to the working of a clinical management system involves
understanding how the system manages information related to patients, doctors,
medical records, appointments, medications, tests, procedures, and more. Here's
a short explanation of how the system typically works:
1. Patient Management:
• Patients are registered in the system with details such as their name, contact
information, date of birth, gender, and address.
• Each patient is assigned a unique identifier (PatientID) for easy reference.
2. Doctor Management:
• Doctors are added to the system with information like their name, contact details,
specialty, and email address.
• Each doctor is assigned a unique identifier (DoctorID).
3. Medical Records:
• Medical records are created for patients, documenting their admissions,
discharges, diagnoses, treatments, and the attending doctors.
• Each medical record is associated with a unique identifier (RecordID).
4. Tests and Procedures:
• The system manages a catalog of available medical tests and procedures,
including details such as test name, description, and cost.
5. Prescriptions and Medications:
• Doctors prescribe medications to patients, specifying dosage, frequency, start
date, and end date.
• The system maintains a list of available medications with details like medication
name and description.
6. Appointments:
• Patients schedule appointments with doctors, and the system records details
such as the appointment date, patient, doctor, and any notes.
7. PatientTestsTable:
• Records the tests conducted for each patient, including the test date,
results, and associated costs.
8. PatientProcedure:
• Tracks the medical procedures undergone by patients, including the procedure
date.
1. ERD of the system
The following Entity-Relationship Diagram (ERD) represents the relationships of different
entities in this database system with respect to their attributes and primary as well as
foreign keys. It also represents the 1:1, 1:M and M: N relationships within this sys
4. Construction of the Relational Schema by using both bottom-up
approach and top-down approach.

Top-Down Approach
1st Normal Form (1NF):

➢ Patients: PatientID, FirstName, LastName, DateOfBirth, Gender, ContactNo,


Address, Blood
➢ Doctors: DoctorID, FirstName, LastName, Speciality, ContactNo, Email
➢ MedicalRecords :RecordID, PatientID, AdmissionDate, DischargeDate, Diagnoses,
Treatment, DoctorID
➢ Tests: TestID, TestName, Description, Cost
➢ PatientTestsTable: PatientTestID, PatientID, TestID, TestDate, Result
➢ Appointement: AppointementID, PatientID, DoctorID, AppointementDate, Notes
➢ Medications: MedicationID, MedicationName, Description
➢ Prescription: PrescriptionID, PatientID, DoctorID, MedicationID, Dosage,
Frequency, StartDate, EndDate
➢ Procedure: ProcedureID, ProcedureName, Description, Cost
➢ PatientProcedure: PatientProcedureID, PatientID, ProcedureID, ProcedureDate

2nd Normal Form (2NF):


• All non-prime attributes are fully functionally dependent on the primary key.
• No changes for 2NF in this case.
3rd Normal Form (3NF):
Eliminate transitive dependencies.
➢ Patients: PatientID (PK), FirstName, LastName, DateOfBirth, Gender, ContactNo,
Address
➢ Doctors: DoctorID (PK), FirstName, LastName, Speciality, ContactNo, Email
➢ MedicalRecords: RecordID (PK), PatientID (FK), AdmissionDate, DischargeDate,
Diagnoses, Treatment, DoctorID (FK)
➢ Tests: TestID (PK), TestName, Description, Cost
➢ PatientTestsTable: PatientTestID (PK), PatientID (FK), TestID (FK), TestDate,
Result
➢ Appointement: AppointementID (PK), PatientID (FK), DoctorID (FK),
AppointementDate, Notes
➢ Medications: MedicationID (PK), MedicationName, Description
➢ Prescription: PrescriptionID (PK), PatientID (FK), DoctorID (FK),
MedicationID(FK), Dosage, Frequency, StartDate, EndDate
➢ Procedure: ProcedureID (PK), ProcedureName, Description, Cost
➢ PatientProcedure: PatientProcedureID (PK), PatientID (FK), ProcedureID (FK),
ProcedureDate

Bottom-up Approach
Normalization with Bottom-up approach
R( PatientID, FirstName, LastName, DateOfBirth, Gender, ContactNo, Address, Blood,
DoctorID, DoctorFirstName, DoctorLastName, Speciality, DoctorContactNo, DoctorEmail
RecordID, AdmissionDate, DischargeDate, Diagnoses, Treatment , TestID, TestName,
TestDescription, TestCost , PatientTestID, TestDate, TestResult , AppointmentID,
AppointmentDate, AppointmentNotes , MedicationID, MedicationName,
MedicationDescription , PrescriptionID, Dosage, Frequency, StartDate, EndDate ,
ProcedureID, ProcedureName, ProcedureDescription, ProcedureCost ,
PatientProcedureID, ProcedureDate )

R( PatientID, FirstName, LastName, DateOfBirth, Gender, ContactNo, Address, Blood,


DoctorID, DoctorFirstName, DoctorLastName, Speciality, DoctorContactNo, DoctorEmail
RecordID, AdmissionDate, DischargeDate, Diagnoses, Treatment , TestID, TestName,
TestDescription, TestCost , PatientTestID, TestDate, TestResult , AppointmentID,
AppointmentDate, AppointmentNotes , MedicationID, MedicationName,
MedicationDescription , PrescriptionID, Dosage, Frequency, StartDate, EndDate ,
ProcedureID, ProcedureName, ProcedureDescription, ProcedureCost ,
PatientProcedureID, ProcedureDate )

2NF
Patients( PatientID(PK), FirstName, LastName, DateOfBirth, Gender, ContactNo,
Address, Blood)

Doctors( DoctorID (PK), FirstName, LastName, Speciality, ContactNo, Email )

MedicalRecords ( RecordID (PK), PatientID(FK), AdmissionDate, DischargeDate,


Diagnoses, Treatment, DoctorID (FK))

Tests( TestID (PK), TestName, Description, Cost)

PatientTests ( PatientTestID (PK), PatientID (FK), TestID (FK), TestDate, Result)

Appointments( AppointmentID (PK), PatientID (FK), DoctorID (FK), AppointmentDate,


Notes)

Medications( MedicationID (PK), MedicationName, Description)

Prescription( PrescriptionID (PK), PatientID (FK), DoctorID (FK), MedicationID (FK),


Dosage, Frequency, StartDate, EndDate )

Procedure( ProcedureID (PK), ProcedureName, Description, Cost)

PatientProcedure( PatientProcedureID (PK), PatientID (FK), ProcedureID (FK),


ProcedureDate )

3NF
As no transitive dependency exists in the table. So all the above tables are normalized.
5. Description of the relations:
TABLE NAME: PATIENTS

ATTRIBUTES SIZE DATA TYPE CONSTRAINT


PATIENTID 10 NUMBER PRIMARY KEY
FIRST NAME 10 VARCHAR2 NOT NULL
LAST NAME 10 VARCHAR2 NOT NULL
DATEOFBIRTH DATE
GENDER 5 CHAR NOT NULL
CONTACT NO 10 VARCHAR2 NOT NULL
ADDRESS 20 VARCHAR2
BLOOD 5 CHAR

TABLE NAME: DOCTORS

ATTRIBUTE SIZE DATA TYPE CONSTRAINT


DOCTOR ID 10 NUMBER PRIMARY KEY
FIRST NAME 10 VARCHAR2 NOT NULL
LAST NAME 10 VARCHAR2 NOT NULL
SPECIALITY 10 VARCHAR2
CONTACT 15 NUMBER NOT NULL
NO
EMAIL 30 VARCHAR2

TABLE NAME: MEDICAL RECORD


ATTRIBUTES SIZE DATA TYPE CONSTRAINT

RECORD ID 10 NUMBER PRIMARY KEY


PATIENT ID 10 NUMBER FOREIGN KEY
(REFERENCE
DOCTOR ID)
ADMISSION DATE
DATE
DISCHARGE DATE
DATE
DOCTOR ID 20 VARCHAR2 FOREIGN KEY
(REFERENCE
PATIENTS ID)
DIAGNOSIS 20 VARCHAR2
TREATMENT 10 NUMBER

Table name: TESTS


ATTRIBUTE SIZE DATA TYPE CONSTRAINT
TEST ID 10 NUMBER PRIMARY KEY
TEST NAME 20 VARCHAR2 NOT NULL
DESCRIPTION 10 VARCHAR2 NOT NULL
COST 10 NUMBER

Table name: Patient Tests Table

ATTRIBUTE SIZE DATA TYPE CONSTRAINT


PATIENT 10 NUMBER PRIMARY KEY
TEST ID
PATIENT ID 10 VARCHAR2 FOREIGN KEY
TEST ID 10 VARCHAR2 FOREIGN KEY
TEST DATE 10 DATE
RESULT 20 VARCHAR2
Table name: Appointment

ATTRIBUTE SIZE DATA TYPE CONSTRAINT


APPOINTEMENT 10 NUMBER PRIMARY KEY
ID
PATIENT ID 10 NUMBER FOREIGN KEY
DOCTOR ID 10 NUMBER FOREIGN KEY
APPOINTEMENT DATE
DATE
NOTES 20 VARCHAR2

Table name: Medications

ATTRIBUTE SIZE DATA TYPE CONSTRAINT


MEDICATION 10 NUMBER PRIMARY KEY
ID
MEDICATION 20 VARCHAR2 NOT NULL
NAME
DESCRIPTION 20 VARCHAR2 NOT NULL

Table name: Perscription


ATTRIBUTE SIZE DATA TYPE CONSTRAINT
PERCRIPTIONS 10 NUMBER PRIMARY KEY
ID
PATIENT ID 10 NUMBER FOREIGN
KEY(references
patients)
DOCTOR ID 10 NUMBER FOREIGN
KEY(references
doctors)
MEDICATION 10 NUMBER Foreign key
ID references
medications
MEDICATIONS 20 VARCHAR2
DOSAGE 20 VARCHAR2
START DATE DATE
END DATE DATE

Table name: PROCEDURE

ATTRIBUTE SIZE DATA TYPE CONSTRAINT


Procedure ID 10 NUMBER PRIMARY KEY
procedure 10 VARCHAR2 NOT NULL
NAME
DESCRIPTION 20 VARCHAR2 NOT NULL
COST 10 NUMBER

Table name: Patient Procedure

ATTRIBUTE SIZE DATA TYPE CONSTRAINT


PATIENT 10 NUMBER PRIMARY KEY
procedure ID
PATIENT ID 10 Number FOREIGN KEY
references
patients
Procedure ID 10 Number FOREIGN KEY
references
procedures
procedure DATE
DATE
6. CREATE TABLE statements for all the relations of your
system.
1. Patients
create Table Patients (
PatientID NUMBER(10),constraints p_pk primary key(PatientID),
FirstName VARCHAR2(10) NOT NULL,

LastName VARCHAR2(10) NOT NULL,


DateOfBirth DATE,

Gender VARCHAR2(5) NOT NULL,


ContactNo CHAR(10) NOT NULL,

Address VARCHAR2(20),
Blood CHAR(5)

)
2.DOCTORS:
create Table Doctors(
DoctorID NUMBER(10) ,constraints d_pk primary key(DoctorID),
FirstName VARCHAR2(10) NOT NULL,

LastName VARCHAR2(10) NOT NULL,


Speciality VARCHAR2(10),

ContactNo NUMBER(15) NOT NULL,


Email VARCHAR2(30)

3.Medical Records:
create table MedicalRecords(

RecordID NUMBER(10), constraint r_pk primary key (RecordID),


PatientID NUMBER(10),
AdmissionDate DATE,
DischargeDate DATE,
Diagnoses VARCHAR2(20),
Treatment VARCHAR2(20),
DoctorID NUMBER(10),
constraint d_fk foreign key (DoctorID) references Doctors(DoctorID),
constraint p_fk foreign key (PatientID) references Patients(PatientID)

);

4.Tests
create table Tests(
TestID NUMBER(10),constraints t_pk primary key(TestID),
TestName VARCHAR2(20) NOT NULL,
Description VARCHAR2(10) NOT NULL,
Cost NUMBER(10)
);

5.PatientTestsTable

create table PatientTestsTable (

PatientTestID NUMBER(10),

PatientID NUMBER(10),

TestID NUMBER(10),

TestDate DATE,

Result VARCHAR2(20),

constraint pt_pk primary key (PatientTestID),

constraint k_fk foreign key (PatientID) references Patients(PatientID),

constraint t_fk foreign key (TestID) references Tests(TestID)

);
6. Appointement
create table Appointement(

AppointementID NUMBER(10),constraints a_pk primary key (AppointementID),

PatientID NUMBER (10),

DoctorID NUMBER (10),

AppointementDate DATE,

Notes VARCHAR2(20),

constraints pp_fk foreign key(PatientID) references Patients(PatientID),

constraints dd_fk foreign key(DoctorID) references Doctors(DoctorID)

);
7.Medications
create table Medications (

MedicationID NUMBER (10), constraints mm_pk primary key (MedicationID),

MedicationName VARCHAR2(20) NOT NULL,

Description VARCHAR2(20) NOT NULL

);

8.Perscription
create table perscription(

PrescriptionID NUMBER(10),constraints es_pk primary key(PrescriptionID),

PatientID NUMBER(10),constraints ppp_fk foreign key(PatientID) references


Patients(PatientID),
DoctorID NUMBER(10),constraints ddd_fk foreign key(DoctorID) references
Doctors(DoctorID),

MedicationID NUMBER(10), constraints mmm_fk foreign key(MedicationID) references


Medications(MedicationID),

Dosage VARCHAR2(20),

Frequency VARCHAR2(10),

StartDate DATE,

EndDate DATE

);

9.Procedure
create table procedure(
procedureID NUMBER (10), constraints pro_pk primary
key(procedureID),
ProcedureName VARCHAR2(10) NOT NULL,
Description VARCHAR2(20) NOT NULL,
Cost NUMBER(10)
);

10.PatientProcedure
create table PatientProcedure(

PatientProcedureID NUMBER(10),constraint proo_pk primary key (PatientProcedureID),

PatientID NUMBER (10), constraints pppp_fk foreign key (PatientID) references


Patients(PatientID),

ProcedureID NUMBER(10), constraint prooo_fk foreign key(ProcedureID) references


Procedure(ProcedureID),

ProcedureDate DATE

);
7. Design at least two VIEWS that you feel are the most
important.
1) Medical History View
CREATE VIEW PatientMedicalHistoryView AS

select

P.PatientID,

P.FirstName || ' ' || P.LastName AS PatientName,

M.RecordID,

M.AdmissionDate,

M.DischargeDate,

M.Diagnoses,

M.Treatment,

T.TestName,

PT.TestDate,

PT.Result

from

Patients P

JOIN MedicalRecords M ON P.PatientID = M.PatientID

LEFT JOIN PatientTestsTable PT ON M.PatientID = PT.PatientID

LEFT JOIN Tests T ON PT.TestID = T.TestID;


Medical History View:

2).Doctors View:
CREATE VIEW DoctorAppointmentsView AS

select

D.DoctorID,

D.FirstName || ' ' || D.LastName AS DoctorName,

A.AppointementID,

A.PatientID,

P.FirstName || ' ' || P.LastName AS PatientName,

A.AppointementDate,

A.Notes

from

Doctors D
JOIN Appointement A ON D.DoctorID = A.DoctorID

JOIN Patients P ON A.PatientID = P.PatientID;

View:
8. Relational data model showing the association among different
relations of the relational schema.
9. SELECT statement for at least five common reports to be generated by the

System.

1. Write a query that retrieves patient List with Contact Information

SELECT PatientID, FirstName || ' ' || LastName AS PatientName, ContactNo, Address

FROM Patients;
2. Write a query that retrieve the names of all doctors and their specialties

SELECT DoctorID, FirstName || ' ' || LastName AS DoctorName, Speciality

FROM Doctors;

3. Write a query that retreives the schedule of appointments for each doctor

Select

D.DoctorID,

D.FirstName || ' ' || D.LastName AS DoctorName,

A.AppointementID,

A.PatientID,

P.FirstName || ' ' || P.LastName AS PatientName,

A.AppointementDate,

A.Notes

From

Doctors D

JOIN Appointement A ON D.DoctorID = A.DoctorID

JOIN Patients P ON A.PatientID = P.PatientID;


4. Write a query to insert a new record in patient Table

INSERT INTO Patients (PatientID, FirstName, LastName, DateOfBirth, Gender, ContactNo,


Address, Blood)

VALUES (106, 'Minahil', 'Asad', TO_DATE('1990-01-01', 'YYYY-MM-DD'), 'Male',


'1234567890', '123 Main St', 'O+');

5. Write a query that retrieves the count of patients who have undergone a
specific test.

Select T.TestName, COUNT(DISTINCT PT.PatientID) AS PatientsCount

From Tests T

LEFT JOIN PatientTestsTable PT ON T.TestID = PT.TestID

GROUP BY T.TestName;

10.Demonstration of at least two functions, two stored procedures, and


two
database triggers.
Procedures:
1).

CREATE OR REPLACE PROCEDURE ScheduleAppointment(

p_appointID NUMBER,

p_patient_id NUMBER,

p_doctor_id NUMBER,

p_appointment_date DATE,

p_notes VARCHAR2

) AS

BEGIN

INSERT INTO Appointement (appointementID,PatientID, DoctorID, AppointementDate,


Notes)

VALUES ( p_appointID,p_patient_id, p_doctor_id, p_appointment_date, p_notes);

END ScheduleAppointment;
0

2)

CREATE OR REPLACE PROCEDURE PrescribeMedication(

p_PrescriptionID NUMBER,

p_patient_id NUMBER,

p_doctor_id NUMBER,

p_medication_id NUMBER,

p_dosage VARCHAR2,

p_frequency VARCHAR2,

p_start_date DATE,

p_end_date DATE
) AS

BEGIN

INSERT INTO perscription (PrescriptionID ,PatientID, DoctorID, MedicationID, Dosage,


Frequency, StartDate, EndDate)

VALUES (p_PrescriptionID ,p_patient_id, p_doctor_id, p_medication_id, p_dosage,


p_frequency, p_start_date, p_end_date);

END PrescribeMedication;

Triggers:
1.CREATE OR REPLACE TRIGGER MedicalRecords_BI

BEFORE INSERT ON MedicalRecords

FOR EACH ROW

BEGIN
IF :NEW.DischargeDate IS NOT NULL AND :NEW.DischargeDate < :NEW.AdmissionDate
THEN

RAISE_APPLICATION_ERROR(-20001, 'Discharge date cannot be before admission date.');

END IF;

END MedicalRecords_BI;

2.

CREATE OR REPLACE TRIGGER CheckTestDate

BEFORE INSERT OR UPDATE ON PatientTestsTable

FOR EACH ROW

BEGIN

IF :NEW.TestDate IS NOT NULL AND :NEW.TestDate < SYSDATE THEN

RAISE_APPLICATION_ERROR(-20002, 'Test date must be in the future.');

END IF;

END CheckTestDate;
Functions:
1)CREATE OR REPLACE FUNCTION GetDoctorSpeciality(p_doctor_id NUMBER)

RETURN VARCHAR2

IS

v_speciality VARCHAR2(50);

BEGIN

SELECT Speciality

INTO v_speciality

FROM Doctors

WHERE DoctorID = p_doctor_id;

RETURN v_speciality;
END GetDoctorSpeciality;

2)CREATE OR REPLACE FUNCTION GetLatestAppointmentDate(p_patient_id NUMBER)

RETURN DATE

IS

v_latest_date DATE;

BEGIN

SELECT MAX(AppointementDate)

INTO v_latest_date

FROM Appointement
WHERE PatientID = p_patient_id;

RETURN v_latest_date;

END GetLatestAppointmentDate;

You might also like