0% found this document useful (0 votes)
9 views

Dbms Mysql

The document outlines the creation of a patient appointment system using MySQL, including the establishment of various tables such as Doctor, Patient, Appointment, and Feedback. It includes SQL commands for creating the database, tables, and inserting sample data for doctors, patients, appointments, and other related entities. The structure supports functionalities like doctor-patient allocation, scheduling, medical records, notifications, and payment processing.

Uploaded by

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

Dbms Mysql

The document outlines the creation of a patient appointment system using MySQL, including the establishment of various tables such as Doctor, Patient, Appointment, and Feedback. It includes SQL commands for creating the database, tables, and inserting sample data for doctors, patients, appointments, and other related entities. The structure supports functionalities like doctor-patient allocation, scheduling, medical records, notifications, and payment processing.

Uploaded by

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

PATIENT APPOINTMENT

SYSTEM
_________________________________________
MYSQL QUERIES
CREATE DATABASE HospitalDB;
USE HospitalDB;

CREATE TABLE Doctor (


DoctorID INT PRIMARY KEY AUTO_INCREMENT,
DoctorName VARCHAR(100) NOT NULL,
Email VARCHAR(100) UNIQUE NOT NULL,
DepartmentID INT,
FOREIGN KEY (DepartmentID) REFERENCES Department(DepartmentID)
);
INSERT INTO Doctor (DoctorName, Email, DepartmentID)
VALUES
('Dr. John Smith', '[email protected]', 1),
('Dr. Emily Davis', '[email protected]', 2),
('Dr. Robert Brown', '[email protected]', 3);
CREATE TABLE Patient (
PatientID INT PRIMARY KEY AUTO_INCREMENT,
PatientName VARCHAR(100) NOT NULL,
Age INT,
Gender ENUM('Male', 'Female', 'Other'),
ContactNo VARCHAR(15) NOT NULL
);
INSERT INTO Patient (PatientName, Age, Gender, ContactNo)
VALUES
('KOWSHICK', 30, 'Female', '9876543210’),
('PRABHU SAI', 45, 'Male', '8765432109’),
('GANESH', 28, 'Male', '7654321098’),
('Diana Green', 35, 'Female', '6543210987');
CREATE TABLE Appointment (
AppointmentID INT PRIMARY KEY AUTO_INCREMENT,
AppointmentDate DATE NOT NULL,
AppointmentTime TIME,
Status VARCHAR(50), PatientID INT,
FOREIGN KEY (PatientID) REFERENCES Patient(PatientID)
);
INSERT INTO Appointment (AppointmentDate, AppointmentTime, Status, PatientID)
VALUES
('2025-03-10', '10:30:00', 'Scheduled', 13),
('2025-03-11', '14:00:00', 'Completed', 14),
('2025-03-12', '09:45:00', 'Scheduled', 15),
('2025-03-13', '16:15:00', 'Cancelled', 16);
CREATE TABLE Login (
UserID INT NOT NULL,
Password VARCHAR(255) NOT NULL,
UserType ENUM('Doctor', 'Patient') NOT NULL,
PRIMARY KEY (UserID)
);
INSERT INTO Login (UserID, Password, UserType)
VALUES
(1, 'docpassword123', 'Doctor'), -- Doctor Login
(2, 'docsecure456', 'Doctor'),
(3, 'patientpass789', 'Patient'), -- Patient Login
(4, 'patientsecure012', 'Patient');
CREATE TABLE Department (
DepartmentID INT PRIMARY KEY AUTO_INCREMENT,
DepartmentName VARCHAR(100) NOT NULL
);

INSERT INTO Department (DepartmentName)


VALUES
('Cardiology'),
('Neurology'),
('Orthopedics'),
('Pediatrics'),
('Dermatology');
CREATE TABLE Feedback (
FeedbackID INT PRIMARY KEY AUTO_INCREMENT,
PatientID INT,
DoctorID INT,
Comments TEXT,
FOREIGN KEY (PatientID) REFERENCES Patient(PatientID),
FOREIGN KEY (DoctorID) REFERENCES Doctor(DoctorID)
);
INSERT INTO Feedback (PatientID, DoctorID, Comments, Rating)
VALUES
(13, 1, 'Great experience, very professional!', 5),
(14, 2, 'Doctor was kind and explained everything clearly.', 4),
(15, 3, 'Satisfactory treatment, but wait time was long.', 3),
(16, 1, 'Highly recommended!', 5);
CREATE TABLE Staff (
StaffID INT PRIMARY KEY AUTO_INCREMENT,
StaffName VARCHAR(100) NOT NULL,
ContactNumber VARCHAR(15) NOT NULL
);

INSERT INTO Staff (StaffName, ContactNumber)


VALUES
('Alice Johnson', '9876543210'),
('Michael Smith', '8765432109'),
('Sophia Brown', '7654321098'),
('David White', '6543210987');
CREATE TABLE Doctor_Allocation (
AllocationID INT PRIMARY KEY AUTO_INCREMENT,
DoctorID INT,
PatientID INT,
AppointmentID INT,
AllocationDate DATE,
FOREIGN KEY (DoctorID) REFERENCES Doctor(DoctorID),
FOREIGN KEY (PatientID) REFERENCES Patient(PatientID),
FOREIGN KEY (AppointmentID) REFERENCES Appointment(AppointmentID)
);
INSERT INTO DoctorAllocation (DoctorID, PatientID, AppointmentID,
AllocationDate)
VALUES
(1, 1, 1, '2025-03-06'),
(2, 2, 2, '2025-03-06'),
(3, 3, 3, '2025-03-06'),
(1, 4, 4, '2025-03-06');
CREATE TABLE Schedule (
ScheduleID INT PRIMARY KEY AUTO_INCREMENT,
Timings TIME NOT NULL,
UserID INT NOT NULL,
FOREIGN KEY (UserID) REFERENCES Patient(PatientID)
);

INSERT INTO Schedule (Timings, UserID)


VALUES
('08:00:00', 1),
('10:30:00', 2),
('13:00:00', 3),
('15:45:00', 4);
CREATE TABLE Medical_Records (
RecordID INT PRIMARY KEY AUTO_INCREMENT,
PatientID INT,
Diagnosis TEXT,
FOREIGN KEY (PatientID) REFERENCES Patient(PatientID)
);
INSERT INTO Medical_Records (RecordID ,PatientID,Diagnosis)
VALUES
(101,13, 'Flu and fever, prescribed antibiotics’),
(102,14, 'Fractured arm, applied cast’),
(103,15, 'High blood pressure, prescribed medication’),
(104,16, 'Skin allergy, given antihistamines');
CREATE TABLE Notification (
NotificationID INT PRIMARY KEY AUTO_INCREMENT,
Message TEXT NOT NULL,
SentDateTime DATETIME DEFAULT CURRENT_TIMESTAMP
);
INSERT INTO Notification (Message, SentDateTime)
VALUES
('Your appointment has been confirmed.', NOW()),
('Reminder: Your appointment is tomorrow at 10 AM.', NOW()),
('Your medical report is now available online.', NOW()),
('Your feedback has been received. Thank you!', NOW());
CREATE TABLE Payment (
PaymentID INT PRIMARY KEY AUTO_INCREMENT,
TransactionID VARCHAR(255) NOT NULL,
PaymentStatus VARCHAR(50) NOT NULL
);
INSERT INTO Payment (TransactionID, PaymentStatus)
VALUES
('TXN123456', 'Completed'),
('TXN123457', 'Pending'),
('TXN123458', 'Failed'),
('TXN123459', 'Completed');
CREATE TABLE LoginDoctor (
user_id INT,
doctor_id INT,
login_type VARCHAR(50) NOT NULL, -- non-primary key column
PRIMARY KEY (user_id, doctor_id),
FOREIGN KEY (user_id) REFERENCES Login(UserID) ON DELETE CASCADE,
FOREIGN KEY (doctor_id) REFERENCES Doctor(DoctorID) ON DELETE CASCADE
);
USE HospitalDB;
INSERT INTO LoginDoctor (user_id, doctor_id, login_type)
VALUES
(1, 1, 'Doctor’),
(2, 2, 'Doctor’),
(3, 3, 'Doctor');
CREATE TABLE HospitalDB.LoginPatient (
user_id INT,
patient_id INT,
login_type VARCHAR(50) NOT NULL,
PRIMARY KEY (user_id, patient_id),
FOREIGN KEY (user_id) REFERENCES HospitalDB.Login(UserID) ON DELETE CASCADE,
FOREIGN KEY (patient_id) REFERENCES HospitalDB.Patient(PatientID) ON DELETE CASCADE
);
INSERT INTO HospitalDB.LoginPatient (user_id, patient_id, login_type)
VALUES
(3, 1, 'Patient'),
(4, 2, 'Patient');
CREATE TABLE DoctorDepartment ( doctor_id INT,
department_id INT,
departmentName varchar(20),
PRIMARY KEY (doctor_id, department_id),
FOREIGN KEY (doctor_id) REFERENCES Doctor(DoctorID) ON DELETE CASCADE,
FOREIGN KEY (department_id) REFERENCES Department(DepartmentID) ON DELETE CASCADE
);
INSERT INTO DoctorDepartment (doctor_id, department_id,departmentName)
VALUES
(1, 1,'Cardiology’),
(2, 2,'Neurology’),
(3, 3,'Orthopedics');
CREATE TABLE PatientAppointment (
patient_id INT,
appointment_id INT,
appointment_status VARCHAR(50) NOT NULL,
PRIMARY KEY (patient_id, appointment_id),
FOREIGN KEY (patient_id) REFERENCES Patient(PatientID) ON DELETE CASCADE,
FOREIGN KEY (appointment_id) REFERENCES Appointment(AppointmentID) ON DELETE CASCADE
);
INSERT INTO PatientAppointment (patient_id, appointment_id, appointment_status)
VALUES
(1, 9, 'Scheduled'),
(2, 10, 'Completed'),
(3, 12, 'Cancelled');
CREATE TABLE PatientFeedback (
patient_id INT,
feedback_id INT,
feedback_date DATETIME DEFAULT CURRENT_TIMESTAMP, -- To track when feedback was given
PRIMARY KEY (patient_id, feedback_id),
FOREIGN KEY (patient_id) REFERENCES Patient(PatientID) ON DELETE CASCADE,
FOREIGN KEY (feedback_id) REFERENCES Feedback(FeedbackID) ON DELETE CASCADE
);
INSERT INTO PatientFeedback (patient_id, feedback_id)
VALUES
(1, 201),
(2, 202),
(3, 203);
CREATE TABLE HospitalDB.PatientPayment (
patient_id INT,
payment_id INT,
payment_date DATETIME DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (patient_id, payment_id),
FOREIGN KEY (patient_id) REFERENCES HospitalDB.Patient(PatientID) ON DELETE CASCADE,
FOREIGN KEY (payment_id) REFERENCES HospitalDB.Payment(PaymentID) ON DELETE CASCADE
);
INSERT INTO HospitalDB.PatientPayment (patient_id, payment_id)
VALUES
(1, 1),
(2, 4);

You might also like