DB Project
DB Project
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):
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 )
2NF
Patients( PatientID(PK), FirstName, LastName, DateOfBirth, Gender, ContactNo,
Address, Blood)
3NF
As no transitive dependency exists in the table. So all the above tables are normalized.
5. Description of the relations:
TABLE NAME: PATIENTS
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,
3.Medical Records:
create table MedicalRecords(
);
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
PatientTestID NUMBER(10),
PatientID NUMBER(10),
TestID NUMBER(10),
TestDate DATE,
Result VARCHAR2(20),
);
6. Appointement
create table Appointement(
AppointementDate DATE,
Notes VARCHAR2(20),
);
7.Medications
create table Medications (
);
8.Perscription
create table perscription(
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(
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,
M.RecordID,
M.AdmissionDate,
M.DischargeDate,
M.Diagnoses,
M.Treatment,
T.TestName,
PT.TestDate,
PT.Result
from
Patients P
2).Doctors View:
CREATE VIEW DoctorAppointmentsView AS
select
D.DoctorID,
A.AppointementID,
A.PatientID,
A.AppointementDate,
A.Notes
from
Doctors D
JOIN Appointement A ON D.DoctorID = A.DoctorID
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.
FROM Patients;
2. Write a query that retrieve the names of all doctors and their specialties
FROM Doctors;
3. Write a query that retreives the schedule of appointments for each doctor
Select
D.DoctorID,
A.AppointementID,
A.PatientID,
A.AppointementDate,
A.Notes
From
Doctors D
5. Write a query that retrieves the count of patients who have undergone a
specific test.
From Tests T
GROUP BY T.TestName;
p_appointID NUMBER,
p_patient_id NUMBER,
p_doctor_id NUMBER,
p_appointment_date DATE,
p_notes VARCHAR2
) AS
BEGIN
END ScheduleAppointment;
0
2)
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
END PrescribeMedication;
Triggers:
1.CREATE OR REPLACE TRIGGER MedicalRecords_BI
BEGIN
IF :NEW.DischargeDate IS NOT NULL AND :NEW.DischargeDate < :NEW.AdmissionDate
THEN
END IF;
END MedicalRecords_BI;
2.
BEGIN
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
RETURN v_speciality;
END GetDoctorSpeciality;
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;