From 1db7c05b947a6bed4aa51ae501b4300cf1bc6c66 Mon Sep 17 00:00:00 2001 From: Alharith99 Date: Tue, 21 Jul 2026 16:51:56 +0400 Subject: [PATCH] Add Al Noor Hospital Management SQL scripts. Schema, views, triggers, sample data, and install helpers for the APEX HMS assignment. --- sql/00_drop_tables.sql | 16 + sql/01_schema.sql | 212 ++++++++ sql/02_sample_data.sql | 348 +++++++++++++ sql/03_views.sql | 192 +++++++ sql/04_triggers.sql | 59 +++ sql/05_patient_delete_cascade.sql | 34 ++ sql/99_complete_script.sql | 808 ++++++++++++++++++++++++++++++ sql/install_all.sql | 18 + 8 files changed, 1687 insertions(+) create mode 100644 sql/00_drop_tables.sql create mode 100644 sql/01_schema.sql create mode 100644 sql/02_sample_data.sql create mode 100644 sql/03_views.sql create mode 100644 sql/04_triggers.sql create mode 100644 sql/05_patient_delete_cascade.sql create mode 100644 sql/99_complete_script.sql create mode 100644 sql/install_all.sql diff --git a/sql/00_drop_tables.sql b/sql/00_drop_tables.sql new file mode 100644 index 00000000..d44c6b7c --- /dev/null +++ b/sql/00_drop_tables.sql @@ -0,0 +1,16 @@ +-- Al Noor Hospital Management System +-- Drop objects (run only if re-installing) + +BEGIN + FOR t IN ( + SELECT table_name FROM user_tables + WHERE table_name IN ( + 'PRESCRIPTION_ITEMS', 'PRESCRIPTIONS', 'PATIENT_VISITS', 'ADMISSIONS', + 'APPOINTMENTS', 'MEDICINES', 'DOCTORS', 'PATIENTS', 'ROOMS', + 'APPOINTMENT_STATUSES', 'MEDICINE_CATEGORIES', 'DOCTOR_SPECIALTIES', 'DEPARTMENTS' + ) + ) LOOP + EXECUTE IMMEDIATE 'DROP TABLE ' || t.table_name || ' CASCADE CONSTRAINTS'; + END LOOP; +END; +/ diff --git a/sql/01_schema.sql b/sql/01_schema.sql new file mode 100644 index 00000000..4a248cfb --- /dev/null +++ b/sql/01_schema.sql @@ -0,0 +1,212 @@ +-- ============================================================================= +-- Al Noor Hospital Management System — Database Schema +-- Oracle Database / Oracle APEX compatible +-- ============================================================================= + +-- ----------------------------------------------------------------------------- +-- A. LOOKUP / REFERENCE TABLES +-- ----------------------------------------------------------------------------- + +CREATE TABLE departments ( + department_id NUMBER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, + department_name VARCHAR2(100) NOT NULL, + floor_no NUMBER(3), + status VARCHAR2(20) DEFAULT 'Active' NOT NULL, + CONSTRAINT chk_dept_status CHECK (status IN ('Active', 'Inactive')) +); + +CREATE TABLE doctor_specialties ( + specialty_id NUMBER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, + specialty_name VARCHAR2(100) NOT NULL, + status VARCHAR2(20) DEFAULT 'Active' NOT NULL, + CONSTRAINT chk_spec_status CHECK (status IN ('Active', 'Inactive')) +); + +CREATE TABLE medicine_categories ( + category_id NUMBER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, + category_name VARCHAR2(100) NOT NULL, + status VARCHAR2(20) DEFAULT 'Active' NOT NULL, + CONSTRAINT chk_medcat_status CHECK (status IN ('Active', 'Inactive')) +); + +CREATE TABLE appointment_statuses ( + status_id NUMBER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, + status_name VARCHAR2(50) NOT NULL, + CONSTRAINT uq_appt_status_name UNIQUE (status_name) +); + +-- ----------------------------------------------------------------------------- +-- B. CORE TABLES +-- ----------------------------------------------------------------------------- + +CREATE TABLE patients ( + patient_id NUMBER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, + civil_id VARCHAR2(20) NOT NULL, + full_name VARCHAR2(150) NOT NULL, + gender VARCHAR2(10) NOT NULL, + date_of_birth DATE NOT NULL, + mobile_no VARCHAR2(20) NOT NULL, + email VARCHAR2(100), + blood_group VARCHAR2(5), + address VARCHAR2(300), + emergency_contact_name VARCHAR2(150), + emergency_contact_no VARCHAR2(20), + created_at DATE DEFAULT SYSDATE NOT NULL, + CONSTRAINT uq_patient_civil_id UNIQUE (civil_id), + CONSTRAINT chk_patient_gender CHECK (gender IN ('Male', 'Female')), + CONSTRAINT chk_patient_blood CHECK ( + blood_group IS NULL OR blood_group IN ( + 'A+', 'A-', 'B+', 'B-', 'O+', 'O-', 'AB+', 'AB-' + ) + ) +); + +CREATE TABLE doctors ( + doctor_id NUMBER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, + full_name VARCHAR2(150) NOT NULL, + department_id NUMBER NOT NULL, + specialty_id NUMBER NOT NULL, + mobile_no VARCHAR2(20), + email VARCHAR2(100), + consultation_fee NUMBER(10, 3) DEFAULT 0 NOT NULL, + status VARCHAR2(20) DEFAULT 'Active' NOT NULL, + CONSTRAINT fk_doctor_dept FOREIGN KEY (department_id) + REFERENCES departments (department_id), + CONSTRAINT fk_doctor_spec FOREIGN KEY (specialty_id) + REFERENCES doctor_specialties (specialty_id), + CONSTRAINT chk_doctor_status CHECK (status IN ('Active', 'Inactive')), + CONSTRAINT chk_doctor_fee CHECK (consultation_fee >= 0) +); + +CREATE TABLE medicines ( + medicine_id NUMBER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, + medicine_name VARCHAR2(150) NOT NULL, + category_id NUMBER NOT NULL, + unit VARCHAR2(50) NOT NULL, + current_stock NUMBER(10) DEFAULT 0 NOT NULL, + reorder_level NUMBER(10) DEFAULT 10 NOT NULL, + status VARCHAR2(20) DEFAULT 'Active' NOT NULL, + CONSTRAINT fk_medicine_cat FOREIGN KEY (category_id) + REFERENCES medicine_categories (category_id), + CONSTRAINT chk_medicine_status CHECK (status IN ('Active', 'Inactive')), + CONSTRAINT chk_medicine_stock CHECK (current_stock >= 0), + CONSTRAINT chk_medicine_reorder CHECK (reorder_level >= 0) +); + +CREATE TABLE appointments ( + appointment_id NUMBER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, + patient_id NUMBER NOT NULL, + doctor_id NUMBER NOT NULL, + appointment_date DATE NOT NULL, + appointment_time VARCHAR2(10) NOT NULL, + status_id NUMBER NOT NULL, + reason_for_visit VARCHAR2(500), + created_at DATE DEFAULT SYSDATE NOT NULL, + CONSTRAINT fk_appt_patient FOREIGN KEY (patient_id) + REFERENCES patients (patient_id), + CONSTRAINT fk_appt_doctor FOREIGN KEY (doctor_id) + REFERENCES doctors (doctor_id), + CONSTRAINT fk_appt_status FOREIGN KEY (status_id) + REFERENCES appointment_statuses (status_id) +); + +CREATE TABLE patient_visits ( + visit_id NUMBER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, + appointment_id NUMBER NOT NULL, + patient_id NUMBER NOT NULL, + doctor_id NUMBER NOT NULL, + visit_date DATE DEFAULT SYSDATE NOT NULL, + symptoms VARCHAR2(1000), + diagnosis VARCHAR2(1000), + notes VARCHAR2(2000), + follow_up_date DATE, + CONSTRAINT fk_visit_appt FOREIGN KEY (appointment_id) + REFERENCES appointments (appointment_id), + CONSTRAINT fk_visit_patient FOREIGN KEY (patient_id) + REFERENCES patients (patient_id), + CONSTRAINT fk_visit_doctor FOREIGN KEY (doctor_id) + REFERENCES doctors (doctor_id), + CONSTRAINT uq_visit_appointment UNIQUE (appointment_id) +); + +CREATE TABLE prescriptions ( + prescription_id NUMBER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, + visit_id NUMBER NOT NULL, + patient_id NUMBER NOT NULL, + doctor_id NUMBER NOT NULL, + prescription_date DATE DEFAULT SYSDATE NOT NULL, + notes VARCHAR2(1000), + CONSTRAINT fk_rx_visit FOREIGN KEY (visit_id) + REFERENCES patient_visits (visit_id), + CONSTRAINT fk_rx_patient FOREIGN KEY (patient_id) + REFERENCES patients (patient_id), + CONSTRAINT fk_rx_doctor FOREIGN KEY (doctor_id) + REFERENCES doctors (doctor_id), + CONSTRAINT uq_rx_visit UNIQUE (visit_id) +); + +CREATE TABLE prescription_items ( + prescription_item_id NUMBER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, + prescription_id NUMBER NOT NULL, + medicine_id NUMBER NOT NULL, + dosage VARCHAR2(100), + frequency VARCHAR2(100), + duration_days NUMBER(5), + instructions VARCHAR2(300), + CONSTRAINT fk_rxitem_rx FOREIGN KEY (prescription_id) + REFERENCES prescriptions (prescription_id) ON DELETE CASCADE, + CONSTRAINT fk_rxitem_med FOREIGN KEY (medicine_id) + REFERENCES medicines (medicine_id), + CONSTRAINT chk_rxitem_duration CHECK (duration_days IS NULL OR duration_days > 0) +); + +CREATE TABLE rooms ( + room_id NUMBER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, + room_no VARCHAR2(20) NOT NULL, + room_type VARCHAR2(30) NOT NULL, + daily_rate NUMBER(10, 3) DEFAULT 0 NOT NULL, + status VARCHAR2(20) DEFAULT 'Available' NOT NULL, + CONSTRAINT uq_room_no UNIQUE (room_no), + CONSTRAINT chk_room_type CHECK (room_type IN ('General', 'Private', 'ICU')), + CONSTRAINT chk_room_status CHECK (status IN ('Available', 'Occupied', 'Maintenance')), + CONSTRAINT chk_room_rate CHECK (daily_rate >= 0) +); + +CREATE TABLE admissions ( + admission_id NUMBER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, + patient_id NUMBER NOT NULL, + doctor_id NUMBER NOT NULL, + room_id NUMBER NOT NULL, + admission_date DATE DEFAULT SYSDATE NOT NULL, + discharge_date DATE, + admission_reason VARCHAR2(500), + status VARCHAR2(20) DEFAULT 'Admitted' NOT NULL, + CONSTRAINT fk_adm_patient FOREIGN KEY (patient_id) + REFERENCES patients (patient_id), + CONSTRAINT fk_adm_doctor FOREIGN KEY (doctor_id) + REFERENCES doctors (doctor_id), + CONSTRAINT fk_adm_room FOREIGN KEY (room_id) + REFERENCES rooms (room_id), + CONSTRAINT chk_adm_status CHECK (status IN ('Admitted', 'Discharged')), + CONSTRAINT chk_adm_discharge CHECK ( + (status = 'Admitted' AND discharge_date IS NULL) + OR (status = 'Discharged' AND discharge_date IS NOT NULL) + ) +); + +-- ----------------------------------------------------------------------------- +-- INDEXES for report / lookup performance +-- ----------------------------------------------------------------------------- + +CREATE INDEX idx_doctors_dept ON doctors (department_id); +CREATE INDEX idx_doctors_spec ON doctors (specialty_id); +CREATE INDEX idx_appt_patient ON appointments (patient_id); +CREATE INDEX idx_appt_doctor ON appointments (doctor_id); +CREATE INDEX idx_appt_date ON appointments (appointment_date); +CREATE INDEX idx_visits_patient ON patient_visits (patient_id); +CREATE INDEX idx_visits_doctor ON patient_visits (doctor_id); +CREATE INDEX idx_adm_patient ON admissions (patient_id); +CREATE INDEX idx_adm_status ON admissions (status); +CREATE INDEX idx_med_stock ON medicines (current_stock, reorder_level); + +COMMIT; diff --git a/sql/02_sample_data.sql b/sql/02_sample_data.sql new file mode 100644 index 00000000..c05b12f1 --- /dev/null +++ b/sql/02_sample_data.sql @@ -0,0 +1,348 @@ +-- ============================================================================= +-- Al Noor Hospital — Sample Data +-- Minima: 5+ departments, 10+ doctors, 20+ patients, 20+ medicines, +-- 30+ appointments, 10+ visits with prescriptions +-- ============================================================================= + +-- Appointment statuses +INSERT INTO appointment_statuses (status_name) VALUES ('Scheduled'); +INSERT INTO appointment_statuses (status_name) VALUES ('Completed'); +INSERT INTO appointment_statuses (status_name) VALUES ('Cancelled'); +INSERT INTO appointment_statuses (status_name) VALUES ('No Show'); + +-- Departments (5+) +INSERT INTO departments (department_name, floor_no, status) VALUES ('Cardiology', 2, 'Active'); +INSERT INTO departments (department_name, floor_no, status) VALUES ('Pediatrics', 1, 'Active'); +INSERT INTO departments (department_name, floor_no, status) VALUES ('Emergency', 0, 'Active'); +INSERT INTO departments (department_name, floor_no, status) VALUES ('Orthopedics', 3, 'Active'); +INSERT INTO departments (department_name, floor_no, status) VALUES ('Internal Medicine', 2, 'Active'); +INSERT INTO departments (department_name, floor_no, status) VALUES ('Obstetrics & Gynecology', 4, 'Active'); +INSERT INTO departments (department_name, floor_no, status) VALUES ('Neurology', 3, 'Active'); + +-- Doctor specialties +INSERT INTO doctor_specialties (specialty_name, status) VALUES ('Cardiologist', 'Active'); +INSERT INTO doctor_specialties (specialty_name, status) VALUES ('Pediatrician', 'Active'); +INSERT INTO doctor_specialties (specialty_name, status) VALUES ('Emergency Physician', 'Active'); +INSERT INTO doctor_specialties (specialty_name, status) VALUES ('Orthopedic Surgeon', 'Active'); +INSERT INTO doctor_specialties (specialty_name, status) VALUES ('Internist', 'Active'); +INSERT INTO doctor_specialties (specialty_name, status) VALUES ('Gynecologist', 'Active'); +INSERT INTO doctor_specialties (specialty_name, status) VALUES ('Neurologist', 'Active'); +INSERT INTO doctor_specialties (specialty_name, status) VALUES ('General Surgeon', 'Active'); + +-- Medicine categories +INSERT INTO medicine_categories (category_name, status) VALUES ('Antibiotic', 'Active'); +INSERT INTO medicine_categories (category_name, status) VALUES ('Painkiller', 'Active'); +INSERT INTO medicine_categories (category_name, status) VALUES ('Diabetes', 'Active'); +INSERT INTO medicine_categories (category_name, status) VALUES ('Cardiac', 'Active'); +INSERT INTO medicine_categories (category_name, status) VALUES ('Vitamins', 'Active'); +INSERT INTO medicine_categories (category_name, status) VALUES ('Respiratory', 'Active'); +INSERT INTO medicine_categories (category_name, status) VALUES ('Gastrointestinal', 'Active'); + +-- Doctors (10+) +INSERT INTO doctors (full_name, department_id, specialty_id, mobile_no, email, consultation_fee, status) +VALUES ('Dr. Ahmed Al-Balushi', 1, 1, '96891234501', 'ahmed.balushi@alnoor.om', 25.000, 'Active'); +INSERT INTO doctors (full_name, department_id, specialty_id, mobile_no, email, consultation_fee, status) +VALUES ('Dr. Fatima Al-Hinai', 2, 2, '96891234502', 'fatima.hinai@alnoor.om', 20.000, 'Active'); +INSERT INTO doctors (full_name, department_id, specialty_id, mobile_no, email, consultation_fee, status) +VALUES ('Dr. Omar Al-Riyami', 3, 3, '96891234503', 'omar.riyami@alnoor.om', 30.000, 'Active'); +INSERT INTO doctors (full_name, department_id, specialty_id, mobile_no, email, consultation_fee, status) +VALUES ('Dr. Sara Al-Harthy', 4, 4, '96891234504', 'sara.harthy@alnoor.om', 28.000, 'Active'); +INSERT INTO doctors (full_name, department_id, specialty_id, mobile_no, email, consultation_fee, status) +VALUES ('Dr. Khalid Al-Maawali', 5, 5, '96891234505', 'khalid.maawali@alnoor.om', 22.000, 'Active'); +INSERT INTO doctors (full_name, department_id, specialty_id, mobile_no, email, consultation_fee, status) +VALUES ('Dr. Maryam Al-Siyabi', 6, 6, '96891234506', 'maryam.siyabi@alnoor.om', 25.000, 'Active'); +INSERT INTO doctors (full_name, department_id, specialty_id, mobile_no, email, consultation_fee, status) +VALUES ('Dr. Yousuf Al-Kindi', 7, 7, '96891234507', 'yousuf.kindi@alnoor.om', 35.000, 'Active'); +INSERT INTO doctors (full_name, department_id, specialty_id, mobile_no, email, consultation_fee, status) +VALUES ('Dr. Nasser Al-Abri', 1, 1, '96891234508', 'nasser.abri@alnoor.om', 25.000, 'Active'); +INSERT INTO doctors (full_name, department_id, specialty_id, mobile_no, email, consultation_fee, status) +VALUES ('Dr. Aisha Al-Zadjali', 2, 2, '96891234509', 'aisha.zadjali@alnoor.om', 20.000, 'Active'); +INSERT INTO doctors (full_name, department_id, specialty_id, mobile_no, email, consultation_fee, status) +VALUES ('Dr. Hassan Al-Farsi', 5, 5, '96891234510', 'hassan.farsi@alnoor.om', 22.000, 'Active'); +INSERT INTO doctors (full_name, department_id, specialty_id, mobile_no, email, consultation_fee, status) +VALUES ('Dr. Layla Al-Amri', 3, 3, '96891234511', 'layla.amri@alnoor.om', 30.000, 'Active'); +INSERT INTO doctors (full_name, department_id, specialty_id, mobile_no, email, consultation_fee, status) +VALUES ('Dr. Salim Al-Busaidi', 4, 4, '96891234512', 'salim.busaidi@alnoor.om', 28.000, 'Inactive'); + +-- Patients (20+) +INSERT INTO patients (civil_id, full_name, gender, date_of_birth, mobile_no, email, blood_group, address, emergency_contact_name, emergency_contact_no) +VALUES ('12345671', 'Abdullah Al-Maskari', 'Male', DATE '1985-03-12', '96899110001', 'abdullah.m@email.om', 'O+', 'Al Khuwair, Muscat', 'Fatima Al-Maskari', '96899110002'); +INSERT INTO patients (civil_id, full_name, gender, date_of_birth, mobile_no, email, blood_group, address, emergency_contact_name, emergency_contact_no) +VALUES ('12345672', 'Muna Al-Ghafri', 'Female', DATE '1990-07-22', '96899110003', 'muna.g@email.om', 'A+', 'Qurum, Muscat', 'Ali Al-Ghafri', '96899110004'); +INSERT INTO patients (civil_id, full_name, gender, date_of_birth, mobile_no, email, blood_group, address, emergency_contact_name, emergency_contact_no) +VALUES ('12345673', 'Said Al-Shanfari', 'Male', DATE '1978-11-05', '96899110005', NULL, 'B+', 'Seeb, Muscat', 'Huda Al-Shanfari', '96899110006'); +INSERT INTO patients (civil_id, full_name, gender, date_of_birth, mobile_no, email, blood_group, address, emergency_contact_name, emergency_contact_no) +VALUES ('12345674', 'Nadia Al-Toubi', 'Female', DATE '2001-01-18', '96899110007', 'nadia.t@email.om', 'AB+', 'Bawshar, Muscat', 'Rashid Al-Toubi', '96899110008'); +INSERT INTO patients (civil_id, full_name, gender, date_of_birth, mobile_no, email, blood_group, address, emergency_contact_name, emergency_contact_no) +VALUES ('12345675', 'Ibrahim Al-Ajmi', 'Male', DATE '1965-09-30', '96899110009', 'ibrahim.a@email.om', 'O-', 'Al Amerat, Muscat', 'Salma Al-Ajmi', '96899110010'); +INSERT INTO patients (civil_id, full_name, gender, date_of_birth, mobile_no, email, blood_group, address, emergency_contact_name, emergency_contact_no) +VALUES ('12345676', 'Hanan Al-Mahrouqi', 'Female', DATE '1995-04-08', '96899110011', 'hanan.m@email.om', 'A-', 'Muttrah, Muscat', 'Yahya Al-Mahrouqi', '96899110012'); +INSERT INTO patients (civil_id, full_name, gender, date_of_birth, mobile_no, email, blood_group, address, emergency_contact_name, emergency_contact_no) +VALUES ('12345677', 'Rashid Al-Habsi', 'Male', DATE '1988-12-25', '96899110013', NULL, 'B-', 'Al Khoud, Muscat', 'Amal Al-Habsi', '96899110014'); +INSERT INTO patients (civil_id, full_name, gender, date_of_birth, mobile_no, email, blood_group, address, emergency_contact_name, emergency_contact_no) +VALUES ('12345678', 'Amina Al-Rawahi', 'Female', DATE '2015-06-14', '96899110015', NULL, 'O+', 'Ruwi, Muscat', 'Khalifa Al-Rawahi', '96899110016'); +INSERT INTO patients (civil_id, full_name, gender, date_of_birth, mobile_no, email, blood_group, address, emergency_contact_name, emergency_contact_no) +VALUES ('12345679', 'Tariq Al-Nabhani', 'Male', DATE '1972-02-28', '96899110017', 'tariq.n@email.om', 'A+', 'Sohar', 'Laila Al-Nabhani', '96899110018'); +INSERT INTO patients (civil_id, full_name, gender, date_of_birth, mobile_no, email, blood_group, address, emergency_contact_name, emergency_contact_no) +VALUES ('12345680', 'Zainab Al-Saadi', 'Female', DATE '1998-08-03', '96899110019', 'zainab.s@email.om', 'AB-', 'Nizwa', 'Mohammed Al-Saadi', '96899110020'); +INSERT INTO patients (civil_id, full_name, gender, date_of_birth, mobile_no, email, blood_group, address, emergency_contact_name, emergency_contact_no) +VALUES ('12345681', 'Hamad Al-Jabri', 'Male', DATE '1982-05-17', '96899110021', 'hamad.j@email.om', 'O+', 'Sur', 'Noor Al-Jabri', '96899110022'); +INSERT INTO patients (civil_id, full_name, gender, date_of_birth, mobile_no, email, blood_group, address, emergency_contact_name, emergency_contact_no) +VALUES ('12345682', 'Latifa Al-Shehhi', 'Female', DATE '1993-10-09', '96899110023', 'latifa.s@email.om', 'B+', 'Salalah', 'Sultan Al-Shehhi', '96899110024'); +INSERT INTO patients (civil_id, full_name, gender, date_of_birth, mobile_no, email, blood_group, address, emergency_contact_name, emergency_contact_no) +VALUES ('12345683', 'Majid Al-Kalbani', 'Male', DATE '2005-03-21', '96899110025', NULL, 'A+', 'Ibri', 'Wafa Al-Kalbani', '96899110026'); +INSERT INTO patients (civil_id, full_name, gender, date_of_birth, mobile_no, email, blood_group, address, emergency_contact_name, emergency_contact_no) +VALUES ('12345684', 'Bushra Al-Omairi', 'Female', DATE '1987-07-11', '96899110027', 'bushra.o@email.om', 'O-', 'Barka', 'Fahad Al-Omairi', '96899110028'); +INSERT INTO patients (civil_id, full_name, gender, date_of_birth, mobile_no, email, blood_group, address, emergency_contact_name, emergency_contact_no) +VALUES ('12345685', 'Waleed Al-Dhuhli', 'Male', DATE '1975-11-19', '96899110029', 'waleed.d@email.om', 'B+', 'Al Khuwair, Muscat', 'Rania Al-Dhuhli', '96899110030'); +INSERT INTO patients (civil_id, full_name, gender, date_of_birth, mobile_no, email, blood_group, address, emergency_contact_name, emergency_contact_no) +VALUES ('12345686', 'Reem Al-Ismaili', 'Female', DATE '2010-01-30', '96899110031', NULL, 'A-', 'Qurum, Muscat', 'Juma Al-Ismaili', '96899110032'); +INSERT INTO patients (civil_id, full_name, gender, date_of_birth, mobile_no, email, blood_group, address, emergency_contact_name, emergency_contact_no) +VALUES ('12345687', 'Fahad Al-Qasmi', 'Male', DATE '1991-09-07', '96899110033', 'fahad.q@email.om', 'AB+', 'Seeb, Muscat', 'Maha Al-Qasmi', '96899110034'); +INSERT INTO patients (civil_id, full_name, gender, date_of_birth, mobile_no, email, blood_group, address, emergency_contact_name, emergency_contact_no) +VALUES ('12345688', 'Shaima Al-Aufi', 'Female', DATE '1984-04-26', '96899110035', 'shaima.a@email.om', 'O+', 'Bawshar, Muscat', 'Bader Al-Aufi', '96899110036'); +INSERT INTO patients (civil_id, full_name, gender, date_of_birth, mobile_no, email, blood_group, address, emergency_contact_name, emergency_contact_no) +VALUES ('12345689', 'Nasser Al-Suleimani', 'Male', DATE '1969-12-01', '96899110037', 'nasser.s@email.om', 'A+', 'Al Ghubra, Muscat', 'Huda Al-Suleimani', '96899110038'); +INSERT INTO patients (civil_id, full_name, gender, date_of_birth, mobile_no, email, blood_group, address, emergency_contact_name, emergency_contact_no) +VALUES ('12345690', 'Maryam Al-Hadhrami', 'Female', DATE '1996-06-15', '96899110039', 'maryam.h@email.om', 'B-', 'Muttrah, Muscat', 'Omar Al-Hadhrami', '96899110040'); +INSERT INTO patients (civil_id, full_name, gender, date_of_birth, mobile_no, email, blood_group, address, emergency_contact_name, emergency_contact_no) +VALUES ('12345691', 'Khalifa Al-Yaarubi', 'Male', DATE '2000-02-14', '96899110041', NULL, 'O+', 'Al Khoud, Muscat', 'Asma Al-Yaarubi', '96899110042'); +INSERT INTO patients (civil_id, full_name, gender, date_of_birth, mobile_no, email, blood_group, address, emergency_contact_name, emergency_contact_no) +VALUES ('12345692', 'Asma Al-Kharusi', 'Female', DATE '1979-08-20', '96899110043', 'asma.k@email.om', 'A+', 'Ruwi, Muscat', 'Said Al-Kharusi', '96899110044'); + +-- Medicines (20+) — some below reorder level for low-stock demos +INSERT INTO medicines (medicine_name, category_id, unit, current_stock, reorder_level, status) +VALUES ('Amoxicillin 500mg', 1, 'Tablet', 120, 30, 'Active'); +INSERT INTO medicines (medicine_name, category_id, unit, current_stock, reorder_level, status) +VALUES ('Azithromycin 250mg', 1, 'Tablet', 8, 25, 'Active'); +INSERT INTO medicines (medicine_name, category_id, unit, current_stock, reorder_level, status) +VALUES ('Ceftriaxone 1g', 1, 'Injection', 45, 20, 'Active'); +INSERT INTO medicines (medicine_name, category_id, unit, current_stock, reorder_level, status) +VALUES ('Paracetamol 500mg', 2, 'Tablet', 200, 50, 'Active'); +INSERT INTO medicines (medicine_name, category_id, unit, current_stock, reorder_level, status) +VALUES ('Ibuprofen 400mg', 2, 'Tablet', 15, 40, 'Active'); +INSERT INTO medicines (medicine_name, category_id, unit, current_stock, reorder_level, status) +VALUES ('Diclofenac 50mg', 2, 'Tablet', 90, 30, 'Active'); +INSERT INTO medicines (medicine_name, category_id, unit, current_stock, reorder_level, status) +VALUES ('Metformin 500mg', 3, 'Tablet', 150, 40, 'Active'); +INSERT INTO medicines (medicine_name, category_id, unit, current_stock, reorder_level, status) +VALUES ('Insulin Glargine', 3, 'Injection', 5, 15, 'Active'); +INSERT INTO medicines (medicine_name, category_id, unit, current_stock, reorder_level, status) +VALUES ('Gliclazide 80mg', 3, 'Tablet', 70, 20, 'Active'); +INSERT INTO medicines (medicine_name, category_id, unit, current_stock, reorder_level, status) +VALUES ('Atenolol 50mg', 4, 'Tablet', 100, 25, 'Active'); +INSERT INTO medicines (medicine_name, category_id, unit, current_stock, reorder_level, status) +VALUES ('Amlodipine 5mg', 4, 'Tablet', 12, 30, 'Active'); +INSERT INTO medicines (medicine_name, category_id, unit, current_stock, reorder_level, status) +VALUES ('Aspirin 81mg', 4, 'Tablet', 180, 50, 'Active'); +INSERT INTO medicines (medicine_name, category_id, unit, current_stock, reorder_level, status) +VALUES ('Vitamin D3 1000IU', 5, 'Tablet', 60, 20, 'Active'); +INSERT INTO medicines (medicine_name, category_id, unit, current_stock, reorder_level, status) +VALUES ('Folic Acid 5mg', 5, 'Tablet', 3, 20, 'Active'); +INSERT INTO medicines (medicine_name, category_id, unit, current_stock, reorder_level, status) +VALUES ('Multivitamin Syrup', 5, 'Syrup', 40, 15, 'Active'); +INSERT INTO medicines (medicine_name, category_id, unit, current_stock, reorder_level, status) +VALUES ('Salbutamol Inhaler', 6, 'Inhaler', 55, 20, 'Active'); +INSERT INTO medicines (medicine_name, category_id, unit, current_stock, reorder_level, status) +VALUES ('Ambroxol Syrup', 6, 'Syrup', 7, 25, 'Active'); +INSERT INTO medicines (medicine_name, category_id, unit, current_stock, reorder_level, status) +VALUES ('Montelukast 10mg', 6, 'Tablet', 80, 25, 'Active'); +INSERT INTO medicines (medicine_name, category_id, unit, current_stock, reorder_level, status) +VALUES ('Omeprazole 20mg', 7, 'Capsule', 110, 30, 'Active'); +INSERT INTO medicines (medicine_name, category_id, unit, current_stock, reorder_level, status) +VALUES ('Domperidone 10mg', 7, 'Tablet', 95, 25, 'Active'); +INSERT INTO medicines (medicine_name, category_id, unit, current_stock, reorder_level, status) +VALUES ('ORS Sachets', 7, 'Sachet', 4, 30, 'Active'); +INSERT INTO medicines (medicine_name, category_id, unit, current_stock, reorder_level, status) +VALUES ('Ciprofloxacin 500mg', 1, 'Tablet', 65, 20, 'Active'); + +-- Rooms +-- Room status for active admissions is set by trg_admission_room_status +INSERT INTO rooms (room_no, room_type, daily_rate, status) VALUES ('G-101', 'General', 40.000, 'Available'); +INSERT INTO rooms (room_no, room_type, daily_rate, status) VALUES ('G-102', 'General', 40.000, 'Available'); +INSERT INTO rooms (room_no, room_type, daily_rate, status) VALUES ('G-103', 'General', 40.000, 'Available'); +INSERT INTO rooms (room_no, room_type, daily_rate, status) VALUES ('P-201', 'Private', 80.000, 'Available'); +INSERT INTO rooms (room_no, room_type, daily_rate, status) VALUES ('P-202', 'Private', 80.000, 'Available'); +INSERT INTO rooms (room_no, room_type, daily_rate, status) VALUES ('P-203', 'Private', 90.000, 'Available'); +INSERT INTO rooms (room_no, room_type, daily_rate, status) VALUES ('ICU-01', 'ICU', 200.000, 'Available'); +INSERT INTO rooms (room_no, room_type, daily_rate, status) VALUES ('ICU-02', 'ICU', 200.000, 'Available'); +INSERT INTO rooms (room_no, room_type, daily_rate, status) VALUES ('G-104', 'General', 40.000, 'Maintenance'); +INSERT INTO rooms (room_no, room_type, daily_rate, status) VALUES ('P-204', 'Private', 85.000, 'Available'); + +-- Appointments (30+) — mix of past completed and upcoming scheduled +-- Status: 1=Scheduled, 2=Completed, 3=Cancelled, 4=No Show + +INSERT INTO appointments (patient_id, doctor_id, appointment_date, appointment_time, status_id, reason_for_visit, created_at) +VALUES (1, 1, TRUNC(SYSDATE) - 20, '09:00', 2, 'Chest pain follow-up', TRUNC(SYSDATE) - 25); +INSERT INTO appointments (patient_id, doctor_id, appointment_date, appointment_time, status_id, reason_for_visit, created_at) +VALUES (2, 2, TRUNC(SYSDATE) - 18, '10:00', 2, 'Child fever', TRUNC(SYSDATE) - 20); +INSERT INTO appointments (patient_id, doctor_id, appointment_date, appointment_time, status_id, reason_for_visit, created_at) +VALUES (3, 5, TRUNC(SYSDATE) - 15, '11:00', 2, 'Diabetes review', TRUNC(SYSDATE) - 18); +INSERT INTO appointments (patient_id, doctor_id, appointment_date, appointment_time, status_id, reason_for_visit, created_at) +VALUES (4, 6, TRUNC(SYSDATE) - 14, '09:30', 2, 'Routine checkup', TRUNC(SYSDATE) - 16); +INSERT INTO appointments (patient_id, doctor_id, appointment_date, appointment_time, status_id, reason_for_visit, created_at) +VALUES (5, 1, TRUNC(SYSDATE) - 12, '14:00', 2, 'Hypertension', TRUNC(SYSDATE) - 14); +INSERT INTO appointments (patient_id, doctor_id, appointment_date, appointment_time, status_id, reason_for_visit, created_at) +VALUES (6, 7, TRUNC(SYSDATE) - 10, '15:00', 2, 'Migraine', TRUNC(SYSDATE) - 12); +INSERT INTO appointments (patient_id, doctor_id, appointment_date, appointment_time, status_id, reason_for_visit, created_at) +VALUES (7, 4, TRUNC(SYSDATE) - 9, '10:30', 2, 'Knee pain', TRUNC(SYSDATE) - 11); +INSERT INTO appointments (patient_id, doctor_id, appointment_date, appointment_time, status_id, reason_for_visit, created_at) +VALUES (8, 2, TRUNC(SYSDATE) - 8, '11:30', 2, 'Vaccination', TRUNC(SYSDATE) - 10); +INSERT INTO appointments (patient_id, doctor_id, appointment_date, appointment_time, status_id, reason_for_visit, created_at) +VALUES (9, 10, TRUNC(SYSDATE) - 7, '09:00', 2, 'Abdominal pain', TRUNC(SYSDATE) - 9); +INSERT INTO appointments (patient_id, doctor_id, appointment_date, appointment_time, status_id, reason_for_visit, created_at) +VALUES (10, 5, TRUNC(SYSDATE) - 6, '13:00', 2, 'Fatigue and dizziness', TRUNC(SYSDATE) - 8); +INSERT INTO appointments (patient_id, doctor_id, appointment_date, appointment_time, status_id, reason_for_visit, created_at) +VALUES (11, 8, TRUNC(SYSDATE) - 5, '16:00', 2, 'ECG review', TRUNC(SYSDATE) - 7); +INSERT INTO appointments (patient_id, doctor_id, appointment_date, appointment_time, status_id, reason_for_visit, created_at) +VALUES (12, 9, TRUNC(SYSDATE) - 4, '10:00', 2, 'Growth check', TRUNC(SYSDATE) - 6); +INSERT INTO appointments (patient_id, doctor_id, appointment_date, appointment_time, status_id, reason_for_visit, created_at) +VALUES (13, 3, TRUNC(SYSDATE) - 3, '08:00', 4, 'Minor injury', TRUNC(SYSDATE) - 5); +INSERT INTO appointments (patient_id, doctor_id, appointment_date, appointment_time, status_id, reason_for_visit, created_at) +VALUES (14, 6, TRUNC(SYSDATE) - 2, '12:00', 3, 'Consultation cancelled', TRUNC(SYSDATE) - 4); +INSERT INTO appointments (patient_id, doctor_id, appointment_date, appointment_time, status_id, reason_for_visit, created_at) +VALUES (15, 1, TRUNC(SYSDATE) - 1, '09:00', 2, 'Cardiac follow-up', TRUNC(SYSDATE) - 3); +INSERT INTO appointments (patient_id, doctor_id, appointment_date, appointment_time, status_id, reason_for_visit, created_at) +VALUES (16, 2, TRUNC(SYSDATE), '09:00', 1, 'Cough and cold', TRUNC(SYSDATE) - 1); +INSERT INTO appointments (patient_id, doctor_id, appointment_date, appointment_time, status_id, reason_for_visit, created_at) +VALUES (17, 5, TRUNC(SYSDATE), '10:00', 1, 'Blood pressure check', TRUNC(SYSDATE) - 1); +INSERT INTO appointments (patient_id, doctor_id, appointment_date, appointment_time, status_id, reason_for_visit, created_at) +VALUES (18, 4, TRUNC(SYSDATE), '11:00', 1, 'Back pain', TRUNC(SYSDATE) - 1); +INSERT INTO appointments (patient_id, doctor_id, appointment_date, appointment_time, status_id, reason_for_visit, created_at) +VALUES (19, 7, TRUNC(SYSDATE), '14:00', 1, 'Headache', SYSDATE); +INSERT INTO appointments (patient_id, doctor_id, appointment_date, appointment_time, status_id, reason_for_visit, created_at) +VALUES (20, 3, TRUNC(SYSDATE), '15:00', 1, 'Emergency review', SYSDATE); +INSERT INTO appointments (patient_id, doctor_id, appointment_date, appointment_time, status_id, reason_for_visit, created_at) +VALUES (1, 8, TRUNC(SYSDATE) + 1, '09:30', 1, 'Follow-up cardiology', SYSDATE); +INSERT INTO appointments (patient_id, doctor_id, appointment_date, appointment_time, status_id, reason_for_visit, created_at) +VALUES (2, 9, TRUNC(SYSDATE) + 1, '10:30', 1, 'Pediatric review', SYSDATE); +INSERT INTO appointments (patient_id, doctor_id, appointment_date, appointment_time, status_id, reason_for_visit, created_at) +VALUES (3, 10, TRUNC(SYSDATE) + 2, '11:00', 1, 'Lab results review', SYSDATE); +INSERT INTO appointments (patient_id, doctor_id, appointment_date, appointment_time, status_id, reason_for_visit, created_at) +VALUES (5, 1, TRUNC(SYSDATE) + 2, '14:30', 1, 'ECG appointment', SYSDATE); +INSERT INTO appointments (patient_id, doctor_id, appointment_date, appointment_time, status_id, reason_for_visit, created_at) +VALUES (7, 4, TRUNC(SYSDATE) + 3, '09:00', 1, 'Physio referral', SYSDATE); +INSERT INTO appointments (patient_id, doctor_id, appointment_date, appointment_time, status_id, reason_for_visit, created_at) +VALUES (9, 5, TRUNC(SYSDATE) + 3, '10:00', 1, 'Diabetes education', SYSDATE); +INSERT INTO appointments (patient_id, doctor_id, appointment_date, appointment_time, status_id, reason_for_visit, created_at) +VALUES (11, 8, TRUNC(SYSDATE) + 4, '11:30', 1, 'Medication review', SYSDATE); +INSERT INTO appointments (patient_id, doctor_id, appointment_date, appointment_time, status_id, reason_for_visit, created_at) +VALUES (12, 6, TRUNC(SYSDATE) + 5, '09:00', 1, 'Prenatal visit', SYSDATE); +INSERT INTO appointments (patient_id, doctor_id, appointment_date, appointment_time, status_id, reason_for_visit, created_at) +VALUES (15, 7, TRUNC(SYSDATE) + 5, '15:00', 1, 'Neurology consult', SYSDATE); +INSERT INTO appointments (patient_id, doctor_id, appointment_date, appointment_time, status_id, reason_for_visit, created_at) +VALUES (21, 11, TRUNC(SYSDATE) + 6, '08:30', 1, 'Trauma follow-up', SYSDATE); +INSERT INTO appointments (patient_id, doctor_id, appointment_date, appointment_time, status_id, reason_for_visit, created_at) +VALUES (22, 10, TRUNC(SYSDATE) + 7, '13:00', 1, 'General checkup', SYSDATE); +INSERT INTO appointments (patient_id, doctor_id, appointment_date, appointment_time, status_id, reason_for_visit, created_at) +VALUES (4, 2, TRUNC(SYSDATE) - 25, '09:00', 2, 'Allergy consult', TRUNC(SYSDATE) - 28); +INSERT INTO appointments (patient_id, doctor_id, appointment_date, appointment_time, status_id, reason_for_visit, created_at) +VALUES (8, 9, TRUNC(SYSDATE) - 22, '10:00', 2, 'Ear infection', TRUNC(SYSDATE) - 24); + +-- Patient visits (10+) linked to completed appointments 1-12, 15, 32, 33 +INSERT INTO patient_visits (appointment_id, patient_id, doctor_id, visit_date, symptoms, diagnosis, notes, follow_up_date) +VALUES (1, 1, 1, TRUNC(SYSDATE) - 20, 'Chest discomfort, mild shortness of breath', 'Stable angina', 'Continue current medication. Lifestyle advice given.', TRUNC(SYSDATE) + 10); +INSERT INTO patient_visits (appointment_id, patient_id, doctor_id, visit_date, symptoms, diagnosis, notes, follow_up_date) +VALUES (2, 2, 2, TRUNC(SYSDATE) - 18, 'High fever, cough for 3 days', 'Viral upper respiratory infection', 'Hydration and rest advised.', NULL); +INSERT INTO patient_visits (appointment_id, patient_id, doctor_id, visit_date, symptoms, diagnosis, notes, follow_up_date) +VALUES (3, 3, 5, TRUNC(SYSDATE) - 15, 'Polyuria, fatigue', 'Type 2 Diabetes Mellitus', 'Adjust metformin dose. Diet counseling.', TRUNC(SYSDATE) + 30); +INSERT INTO patient_visits (appointment_id, patient_id, doctor_id, visit_date, symptoms, diagnosis, notes, follow_up_date) +VALUES (4, 4, 6, TRUNC(SYSDATE) - 14, 'Routine antenatal visit', 'Normal pregnancy', 'Next visit in 4 weeks.', TRUNC(SYSDATE) + 28); +INSERT INTO patient_visits (appointment_id, patient_id, doctor_id, visit_date, symptoms, diagnosis, notes, follow_up_date) +VALUES (5, 5, 1, TRUNC(SYSDATE) - 12, 'Elevated BP readings at home', 'Hypertension', 'Started amlodipine. Monitor BP.', TRUNC(SYSDATE) + 14); +INSERT INTO patient_visits (appointment_id, patient_id, doctor_id, visit_date, symptoms, diagnosis, notes, follow_up_date) +VALUES (6, 6, 7, TRUNC(SYSDATE) - 10, 'Severe headache, photophobia', 'Migraine without aura', 'Prescribed acute therapy.', TRUNC(SYSDATE) + 21); +INSERT INTO patient_visits (appointment_id, patient_id, doctor_id, visit_date, symptoms, diagnosis, notes, follow_up_date) +VALUES (7, 7, 4, TRUNC(SYSDATE) - 9, 'Right knee pain after sports', 'Patellar tendinitis', 'Rest, ice, physiotherapy referral.', TRUNC(SYSDATE) + 14); +INSERT INTO patient_visits (appointment_id, patient_id, doctor_id, visit_date, symptoms, diagnosis, notes, follow_up_date) +VALUES (8, 8, 2, TRUNC(SYSDATE) - 8, 'Due for MMR booster', 'Routine immunization', 'Vaccination given. Observe 15 min.', NULL); +INSERT INTO patient_visits (appointment_id, patient_id, doctor_id, visit_date, symptoms, diagnosis, notes, follow_up_date) +VALUES (9, 9, 10, TRUNC(SYSDATE) - 7, 'Epigastric pain after meals', 'Gastritis', 'Avoid spicy food. PPI prescribed.', TRUNC(SYSDATE) + 14); +INSERT INTO patient_visits (appointment_id, patient_id, doctor_id, visit_date, symptoms, diagnosis, notes, follow_up_date) +VALUES (10, 10, 5, TRUNC(SYSDATE) - 6, 'Fatigue, dizziness', 'Iron deficiency anemia', 'Labs ordered. Folic acid started.', TRUNC(SYSDATE) + 21); +INSERT INTO patient_visits (appointment_id, patient_id, doctor_id, visit_date, symptoms, diagnosis, notes, follow_up_date) +VALUES (11, 11, 8, TRUNC(SYSDATE) - 5, 'Palpitations', 'Sinus tachycardia', 'ECG normal. Reduce caffeine.', TRUNC(SYSDATE) + 30); +INSERT INTO patient_visits (appointment_id, patient_id, doctor_id, visit_date, symptoms, diagnosis, notes, follow_up_date) +VALUES (15, 15, 1, TRUNC(SYSDATE) - 1, 'Post-op cardiac review', 'Stable post angioplasty', 'Continue dual antiplatelet therapy.', TRUNC(SYSDATE) + 30); + +-- Prescriptions for visits +INSERT INTO prescriptions (visit_id, patient_id, doctor_id, prescription_date, notes) +VALUES (1, 1, 1, TRUNC(SYSDATE) - 20, 'Cardiac medications'); +INSERT INTO prescriptions (visit_id, patient_id, doctor_id, prescription_date, notes) +VALUES (2, 2, 2, TRUNC(SYSDATE) - 18, 'Symptomatic relief'); +INSERT INTO prescriptions (visit_id, patient_id, doctor_id, prescription_date, notes) +VALUES (3, 3, 5, TRUNC(SYSDATE) - 15, 'Diabetes control'); +INSERT INTO prescriptions (visit_id, patient_id, doctor_id, prescription_date, notes) +VALUES (5, 5, 1, TRUNC(SYSDATE) - 12, 'BP control'); +INSERT INTO prescriptions (visit_id, patient_id, doctor_id, prescription_date, notes) +VALUES (6, 6, 7, TRUNC(SYSDATE) - 10, 'Migraine management'); +INSERT INTO prescriptions (visit_id, patient_id, doctor_id, prescription_date, notes) +VALUES (7, 7, 4, TRUNC(SYSDATE) - 9, 'Pain management'); +INSERT INTO prescriptions (visit_id, patient_id, doctor_id, prescription_date, notes) +VALUES (9, 9, 10, TRUNC(SYSDATE) - 7, 'Gastritis treatment'); +INSERT INTO prescriptions (visit_id, patient_id, doctor_id, prescription_date, notes) +VALUES (10, 10, 5, TRUNC(SYSDATE) - 6, 'Anemia support'); +INSERT INTO prescriptions (visit_id, patient_id, doctor_id, prescription_date, notes) +VALUES (11, 11, 8, TRUNC(SYSDATE) - 5, 'Supportive care'); +INSERT INTO prescriptions (visit_id, patient_id, doctor_id, prescription_date, notes) +VALUES (12, 15, 1, TRUNC(SYSDATE) - 1, 'Post cardiac care'); + +-- Prescription items (multiple medicines per some prescriptions) +INSERT INTO prescription_items (prescription_id, medicine_id, dosage, frequency, duration_days, instructions) +VALUES (1, 10, '50mg', 'Once daily', 30, 'After breakfast'); +INSERT INTO prescription_items (prescription_id, medicine_id, dosage, frequency, duration_days, instructions) +VALUES (1, 12, '81mg', 'Once daily', 30, 'After food'); +INSERT INTO prescription_items (prescription_id, medicine_id, dosage, frequency, duration_days, instructions) +VALUES (2, 4, '500mg', 'Every 6 hours', 5, 'As needed for fever'); +INSERT INTO prescription_items (prescription_id, medicine_id, dosage, frequency, duration_days, instructions) +VALUES (2, 17, '5ml', 'Twice daily', 5, 'After food'); +INSERT INTO prescription_items (prescription_id, medicine_id, dosage, frequency, duration_days, instructions) +VALUES (3, 7, '500mg', 'Twice daily', 30, 'With meals'); +INSERT INTO prescription_items (prescription_id, medicine_id, dosage, frequency, duration_days, instructions) +VALUES (4, 11, '5mg', 'Once daily', 30, 'Morning'); +INSERT INTO prescription_items (prescription_id, medicine_id, dosage, frequency, duration_days, instructions) +VALUES (5, 5, '400mg', 'Twice daily', 7, 'With food'); +INSERT INTO prescription_items (prescription_id, medicine_id, dosage, frequency, duration_days, instructions) +VALUES (5, 4, '500mg', 'As needed', 7, 'For headache'); +INSERT INTO prescription_items (prescription_id, medicine_id, dosage, frequency, duration_days, instructions) +VALUES (6, 6, '50mg', 'Twice daily', 7, 'After food'); +INSERT INTO prescription_items (prescription_id, medicine_id, dosage, frequency, duration_days, instructions) +VALUES (7, 19, '20mg', 'Once daily', 14, 'Before breakfast'); +INSERT INTO prescription_items (prescription_id, medicine_id, dosage, frequency, duration_days, instructions) +VALUES (7, 20, '10mg', 'Three times daily', 7, 'Before meals'); +INSERT INTO prescription_items (prescription_id, medicine_id, dosage, frequency, duration_days, instructions) +VALUES (8, 14, '5mg', 'Once daily', 30, 'With water'); +INSERT INTO prescription_items (prescription_id, medicine_id, dosage, frequency, duration_days, instructions) +VALUES (8, 13, '1000IU', 'Once daily', 30, 'With food'); +INSERT INTO prescription_items (prescription_id, medicine_id, dosage, frequency, duration_days, instructions) +VALUES (9, 4, '500mg', 'As needed', 5, 'For discomfort'); +INSERT INTO prescription_items (prescription_id, medicine_id, dosage, frequency, duration_days, instructions) +VALUES (10, 12, '81mg', 'Once daily', 90, 'Lifelong unless advised'); +INSERT INTO prescription_items (prescription_id, medicine_id, dosage, frequency, duration_days, instructions) +VALUES (10, 10, '50mg', 'Once daily', 30, 'After breakfast'); + +-- Admissions (some current, some discharged) +INSERT INTO admissions (patient_id, doctor_id, room_id, admission_date, discharge_date, admission_reason, status) +VALUES (5, 1, 3, TRUNC(SYSDATE) - 3, NULL, 'Uncontrolled hypertension observation', 'Admitted'); +INSERT INTO admissions (patient_id, doctor_id, room_id, admission_date, discharge_date, admission_reason, status) +VALUES (1, 8, 5, TRUNC(SYSDATE) - 5, NULL, 'Cardiac monitoring', 'Admitted'); +INSERT INTO admissions (patient_id, doctor_id, room_id, admission_date, discharge_date, admission_reason, status) +VALUES (9, 10, 8, TRUNC(SYSDATE) - 2, NULL, 'Severe dehydration / gastritis', 'Admitted'); +INSERT INTO admissions (patient_id, doctor_id, room_id, admission_date, discharge_date, admission_reason, status) +VALUES (3, 5, 1, TRUNC(SYSDATE) - 20, TRUNC(SYSDATE) - 17, 'Diabetes ketoacidosis risk', 'Discharged'); +INSERT INTO admissions (patient_id, doctor_id, room_id, admission_date, discharge_date, admission_reason, status) +VALUES (7, 4, 4, TRUNC(SYSDATE) - 15, TRUNC(SYSDATE) - 12, 'Post knee injury observation', 'Discharged'); +INSERT INTO admissions (patient_id, doctor_id, room_id, admission_date, discharge_date, admission_reason, status) +VALUES (15, 1, 7, TRUNC(SYSDATE) - 30, TRUNC(SYSDATE) - 25, 'Post angioplasty care', 'Discharged'); + +COMMIT; + +-- Quick verification counts +SELECT 'DEPARTMENTS' AS entity, COUNT(*) AS cnt FROM departments +UNION ALL SELECT 'DOCTORS', COUNT(*) FROM doctors +UNION ALL SELECT 'PATIENTS', COUNT(*) FROM patients +UNION ALL SELECT 'MEDICINES', COUNT(*) FROM medicines +UNION ALL SELECT 'APPOINTMENTS', COUNT(*) FROM appointments +UNION ALL SELECT 'VISITS', COUNT(*) FROM patient_visits +UNION ALL SELECT 'PRESCRIPTIONS', COUNT(*) FROM prescriptions +UNION ALL SELECT 'ADMISSIONS', COUNT(*) FROM admissions; diff --git a/sql/03_views.sql b/sql/03_views.sql new file mode 100644 index 00000000..99643b9c --- /dev/null +++ b/sql/03_views.sql @@ -0,0 +1,192 @@ +-- ============================================================================= +-- Al Noor Hospital — Views & reusable queries for Dashboard / Reports +-- Run after schema + sample data +-- ============================================================================= + +-- Patient age helper view +CREATE OR REPLACE VIEW v_patients AS +SELECT + p.*, + TRUNC(MONTHS_BETWEEN(SYSDATE, p.date_of_birth) / 12) AS age +FROM patients p; + +-- Doctors with department & specialty names +CREATE OR REPLACE VIEW v_doctors AS +SELECT + d.doctor_id, + d.full_name, + d.department_id, + dep.department_name, + d.specialty_id, + s.specialty_name, + d.mobile_no, + d.email, + d.consultation_fee, + d.status +FROM doctors d +JOIN departments dep ON dep.department_id = d.department_id +JOIN doctor_specialties s ON s.specialty_id = d.specialty_id; + +-- Medicines with stock status +CREATE OR REPLACE VIEW v_medicines AS +SELECT + m.medicine_id, + m.medicine_name, + m.category_id, + c.category_name, + m.unit, + m.current_stock, + m.reorder_level, + m.status, + CASE + WHEN m.current_stock < m.reorder_level THEN 'Low Stock' + ELSE 'Normal' + END AS stock_status +FROM medicines m +JOIN medicine_categories c ON c.category_id = m.category_id; + +-- Appointments full report view +CREATE OR REPLACE VIEW v_appointments AS +SELECT + a.appointment_id, + a.patient_id, + p.full_name AS patient_name, + p.civil_id, + a.doctor_id, + d.full_name AS doctor_name, + dep.department_id, + dep.department_name, + a.appointment_date, + a.appointment_time, + a.status_id, + st.status_name, + a.reason_for_visit, + a.created_at +FROM appointments a +JOIN patients p ON p.patient_id = a.patient_id +JOIN doctors d ON d.doctor_id = a.doctor_id +JOIN departments dep ON dep.department_id = d.department_id +JOIN appointment_statuses st ON st.status_id = a.status_id; + +-- Patient visits report view +CREATE OR REPLACE VIEW v_patient_visits AS +SELECT + v.visit_id, + v.appointment_id, + v.patient_id, + p.full_name AS patient_name, + v.doctor_id, + d.full_name AS doctor_name, + dep.department_id, + dep.department_name, + v.visit_date, + v.symptoms, + v.diagnosis, + v.notes, + v.follow_up_date +FROM patient_visits v +JOIN patients p ON p.patient_id = v.patient_id +JOIN doctors d ON d.doctor_id = v.doctor_id +JOIN departments dep ON dep.department_id = d.department_id; + +-- Admissions report view +CREATE OR REPLACE VIEW v_admissions AS +SELECT + adm.admission_id, + adm.patient_id, + p.full_name AS patient_name, + adm.doctor_id, + d.full_name AS doctor_name, + adm.room_id, + r.room_no, + r.room_type, + r.daily_rate, + adm.admission_date, + adm.discharge_date, + adm.admission_reason, + adm.status +FROM admissions adm +JOIN patients p ON p.patient_id = adm.patient_id +JOIN doctors d ON d.doctor_id = adm.doctor_id +JOIN rooms r ON r.room_id = adm.room_id; + +-- Prescription with items +CREATE OR REPLACE VIEW v_prescription_items AS +SELECT + pi.prescription_item_id, + pi.prescription_id, + pr.visit_id, + pr.patient_id, + p.full_name AS patient_name, + pr.doctor_id, + d.full_name AS doctor_name, + pr.prescription_date, + pi.medicine_id, + m.medicine_name, + pi.dosage, + pi.frequency, + pi.duration_days, + pi.instructions +FROM prescription_items pi +JOIN prescriptions pr ON pr.prescription_id = pi.prescription_id +JOIN patients p ON p.patient_id = pr.patient_id +JOIN doctors d ON d.doctor_id = pr.doctor_id +JOIN medicines m ON m.medicine_id = pi.medicine_id; + +COMMIT; + +-- ============================================================================= +-- DASHBOARD KPI QUERIES (use in APEX Card / Classic Report regions) +-- ============================================================================= + +-- KPI: Total Patients +-- SELECT COUNT(*) AS total_patients FROM patients; + +-- KPI: Today's Appointments +-- SELECT COUNT(*) AS todays_appointments +-- FROM appointments WHERE appointment_date = TRUNC(SYSDATE); + +-- KPI: Active Doctors +-- SELECT COUNT(*) AS active_doctors FROM doctors WHERE status = 'Active'; + +-- KPI: Current Admissions +-- SELECT COUNT(*) AS current_admissions FROM admissions WHERE status = 'Admitted'; + +-- KPI: Low Stock Medicines +-- SELECT COUNT(*) AS low_stock +-- FROM medicines WHERE current_stock < reorder_level AND status = 'Active'; + +-- Chart 1: Appointments by department +-- SELECT dep.department_name AS label, COUNT(*) AS value +-- FROM appointments a +-- JOIN doctors d ON d.doctor_id = a.doctor_id +-- JOIN departments dep ON dep.department_id = d.department_id +-- GROUP BY dep.department_name +-- ORDER BY value DESC; + +-- Chart 2: Patients by gender +-- SELECT gender AS label, COUNT(*) AS value +-- FROM patients GROUP BY gender; + +-- Chart 3: Medicine stock status +-- SELECT +-- CASE WHEN current_stock < reorder_level THEN 'Low Stock' ELSE 'Normal' END AS label, +-- COUNT(*) AS value +-- FROM medicines WHERE status = 'Active' +-- GROUP BY CASE WHEN current_stock < reorder_level THEN 'Low Stock' ELSE 'Normal' END; + +-- Chart 4: Admissions by room type +-- SELECT r.room_type AS label, COUNT(*) AS value +-- FROM admissions a +-- JOIN rooms r ON r.room_id = a.room_id +-- GROUP BY r.room_type; + +-- Chart 5: Monthly patient visits +-- SELECT TO_CHAR(visit_date, 'YYYY-MM') AS label, COUNT(*) AS value +-- FROM patient_visits +-- GROUP BY TO_CHAR(visit_date, 'YYYY-MM') +-- ORDER BY label; + +-- Available rooms LOV (for admissions) +-- SELECT room_no || ' (' || room_type || ')' AS d, room_id AS r +-- FROM rooms WHERE status = 'Available' ORDER BY room_no; diff --git a/sql/04_triggers.sql b/sql/04_triggers.sql new file mode 100644 index 00000000..33882599 --- /dev/null +++ b/sql/04_triggers.sql @@ -0,0 +1,59 @@ +-- ============================================================================= +-- Al Noor Hospital — Triggers for room status business rules +-- ============================================================================= + +CREATE OR REPLACE TRIGGER trg_admission_room_status +AFTER INSERT OR UPDATE OF status, room_id, discharge_date ON admissions +FOR EACH ROW +BEGIN + -- On admit: mark room Occupied + IF INSERTING AND :NEW.status = 'Admitted' THEN + UPDATE rooms SET status = 'Occupied' WHERE room_id = :NEW.room_id; + END IF; + + -- On status change to Admitted (e.g. re-admit edge case) + IF UPDATING AND :NEW.status = 'Admitted' AND NVL(:OLD.status, 'X') <> 'Admitted' THEN + UPDATE rooms SET status = 'Occupied' WHERE room_id = :NEW.room_id; + END IF; + + -- On discharge: free the room + IF UPDATING AND :NEW.status = 'Discharged' AND :OLD.status = 'Admitted' THEN + UPDATE rooms SET status = 'Available' WHERE room_id = :OLD.room_id; + END IF; + + -- If room changed while still admitted + IF UPDATING AND :NEW.status = 'Admitted' + AND :NEW.room_id <> :OLD.room_id THEN + UPDATE rooms SET status = 'Available' WHERE room_id = :OLD.room_id; + UPDATE rooms SET status = 'Occupied' WHERE room_id = :NEW.room_id; + END IF; +END; +/ + +-- Allow deleting a patient who still has related records +CREATE OR REPLACE TRIGGER trg_patients_bd +BEFORE DELETE ON patients +FOR EACH ROW +BEGIN + UPDATE rooms + SET status = 'Available' + WHERE room_id IN ( + SELECT room_id + FROM admissions + WHERE patient_id = :OLD.patient_id + AND status = 'Admitted' + ); + + DELETE FROM prescriptions + WHERE patient_id = :OLD.patient_id; + + DELETE FROM patient_visits + WHERE patient_id = :OLD.patient_id; + + DELETE FROM appointments + WHERE patient_id = :OLD.patient_id; + + DELETE FROM admissions + WHERE patient_id = :OLD.patient_id; +END; +/ diff --git a/sql/05_patient_delete_cascade.sql b/sql/05_patient_delete_cascade.sql new file mode 100644 index 00000000..a5eb44a6 --- /dev/null +++ b/sql/05_patient_delete_cascade.sql @@ -0,0 +1,34 @@ +-- ============================================================================= +-- Allow deleting a patient who still has related records. +-- Deletes prescriptions, visits, appointments, and admissions first. +-- Also frees rooms that were occupied by that patient's open admissions. +-- ============================================================================= + +CREATE OR REPLACE TRIGGER trg_patients_bd +BEFORE DELETE ON patients +FOR EACH ROW +BEGIN + -- Free rooms for open admissions belonging to this patient + UPDATE rooms + SET status = 'Available' + WHERE room_id IN ( + SELECT room_id + FROM admissions + WHERE patient_id = :OLD.patient_id + AND status = 'Admitted' + ); + + -- Child rows first (prescription_items cascade from prescriptions) + DELETE FROM prescriptions + WHERE patient_id = :OLD.patient_id; + + DELETE FROM patient_visits + WHERE patient_id = :OLD.patient_id; + + DELETE FROM appointments + WHERE patient_id = :OLD.patient_id; + + DELETE FROM admissions + WHERE patient_id = :OLD.patient_id; +END; +/ diff --git a/sql/99_complete_script.sql b/sql/99_complete_script.sql new file mode 100644 index 00000000..8edfbc68 --- /dev/null +++ b/sql/99_complete_script.sql @@ -0,0 +1,808 @@ +-- ============================================================================= +-- Al Noor Hospital Management System — Complete SQL (schema + views + triggers + data) +-- Submit this file as the SQL script deliverable +-- ============================================================================= + +-- Al Noor Hospital Management System +-- Drop objects (run only if re-installing) + +BEGIN + FOR t IN ( + SELECT table_name FROM user_tables + WHERE table_name IN ( + 'PRESCRIPTION_ITEMS', 'PRESCRIPTIONS', 'PATIENT_VISITS', 'ADMISSIONS', + 'APPOINTMENTS', 'MEDICINES', 'DOCTORS', 'PATIENTS', 'ROOMS', + 'APPOINTMENT_STATUSES', 'MEDICINE_CATEGORIES', 'DOCTOR_SPECIALTIES', 'DEPARTMENTS' + ) + ) LOOP + EXECUTE IMMEDIATE 'DROP TABLE ' || t.table_name || ' CASCADE CONSTRAINTS'; + END LOOP; +END; +/ + +-- ============================================================================= +-- Al Noor Hospital Management System — Database Schema +-- Oracle Database / Oracle APEX compatible +-- ============================================================================= + +-- ----------------------------------------------------------------------------- +-- A. LOOKUP / REFERENCE TABLES +-- ----------------------------------------------------------------------------- + +CREATE TABLE departments ( + department_id NUMBER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, + department_name VARCHAR2(100) NOT NULL, + floor_no NUMBER(3), + status VARCHAR2(20) DEFAULT 'Active' NOT NULL, + CONSTRAINT chk_dept_status CHECK (status IN ('Active', 'Inactive')) +); + +CREATE TABLE doctor_specialties ( + specialty_id NUMBER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, + specialty_name VARCHAR2(100) NOT NULL, + status VARCHAR2(20) DEFAULT 'Active' NOT NULL, + CONSTRAINT chk_spec_status CHECK (status IN ('Active', 'Inactive')) +); + +CREATE TABLE medicine_categories ( + category_id NUMBER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, + category_name VARCHAR2(100) NOT NULL, + status VARCHAR2(20) DEFAULT 'Active' NOT NULL, + CONSTRAINT chk_medcat_status CHECK (status IN ('Active', 'Inactive')) +); + +CREATE TABLE appointment_statuses ( + status_id NUMBER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, + status_name VARCHAR2(50) NOT NULL, + CONSTRAINT uq_appt_status_name UNIQUE (status_name) +); + +-- ----------------------------------------------------------------------------- +-- B. CORE TABLES +-- ----------------------------------------------------------------------------- + +CREATE TABLE patients ( + patient_id NUMBER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, + civil_id VARCHAR2(20) NOT NULL, + full_name VARCHAR2(150) NOT NULL, + gender VARCHAR2(10) NOT NULL, + date_of_birth DATE NOT NULL, + mobile_no VARCHAR2(20) NOT NULL, + email VARCHAR2(100), + blood_group VARCHAR2(5), + address VARCHAR2(300), + emergency_contact_name VARCHAR2(150), + emergency_contact_no VARCHAR2(20), + created_at DATE DEFAULT SYSDATE NOT NULL, + CONSTRAINT uq_patient_civil_id UNIQUE (civil_id), + CONSTRAINT chk_patient_gender CHECK (gender IN ('Male', 'Female')), + CONSTRAINT chk_patient_blood CHECK ( + blood_group IS NULL OR blood_group IN ( + 'A+', 'A-', 'B+', 'B-', 'O+', 'O-', 'AB+', 'AB-' + ) + ) +); + +CREATE TABLE doctors ( + doctor_id NUMBER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, + full_name VARCHAR2(150) NOT NULL, + department_id NUMBER NOT NULL, + specialty_id NUMBER NOT NULL, + mobile_no VARCHAR2(20), + email VARCHAR2(100), + consultation_fee NUMBER(10, 3) DEFAULT 0 NOT NULL, + status VARCHAR2(20) DEFAULT 'Active' NOT NULL, + CONSTRAINT fk_doctor_dept FOREIGN KEY (department_id) + REFERENCES departments (department_id), + CONSTRAINT fk_doctor_spec FOREIGN KEY (specialty_id) + REFERENCES doctor_specialties (specialty_id), + CONSTRAINT chk_doctor_status CHECK (status IN ('Active', 'Inactive')), + CONSTRAINT chk_doctor_fee CHECK (consultation_fee >= 0) +); + +CREATE TABLE medicines ( + medicine_id NUMBER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, + medicine_name VARCHAR2(150) NOT NULL, + category_id NUMBER NOT NULL, + unit VARCHAR2(50) NOT NULL, + current_stock NUMBER(10) DEFAULT 0 NOT NULL, + reorder_level NUMBER(10) DEFAULT 10 NOT NULL, + status VARCHAR2(20) DEFAULT 'Active' NOT NULL, + CONSTRAINT fk_medicine_cat FOREIGN KEY (category_id) + REFERENCES medicine_categories (category_id), + CONSTRAINT chk_medicine_status CHECK (status IN ('Active', 'Inactive')), + CONSTRAINT chk_medicine_stock CHECK (current_stock >= 0), + CONSTRAINT chk_medicine_reorder CHECK (reorder_level >= 0) +); + +CREATE TABLE appointments ( + appointment_id NUMBER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, + patient_id NUMBER NOT NULL, + doctor_id NUMBER NOT NULL, + appointment_date DATE NOT NULL, + appointment_time VARCHAR2(10) NOT NULL, + status_id NUMBER NOT NULL, + reason_for_visit VARCHAR2(500), + created_at DATE DEFAULT SYSDATE NOT NULL, + CONSTRAINT fk_appt_patient FOREIGN KEY (patient_id) + REFERENCES patients (patient_id), + CONSTRAINT fk_appt_doctor FOREIGN KEY (doctor_id) + REFERENCES doctors (doctor_id), + CONSTRAINT fk_appt_status FOREIGN KEY (status_id) + REFERENCES appointment_statuses (status_id) +); + +CREATE TABLE patient_visits ( + visit_id NUMBER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, + appointment_id NUMBER NOT NULL, + patient_id NUMBER NOT NULL, + doctor_id NUMBER NOT NULL, + visit_date DATE DEFAULT SYSDATE NOT NULL, + symptoms VARCHAR2(1000), + diagnosis VARCHAR2(1000), + notes VARCHAR2(2000), + follow_up_date DATE, + CONSTRAINT fk_visit_appt FOREIGN KEY (appointment_id) + REFERENCES appointments (appointment_id), + CONSTRAINT fk_visit_patient FOREIGN KEY (patient_id) + REFERENCES patients (patient_id), + CONSTRAINT fk_visit_doctor FOREIGN KEY (doctor_id) + REFERENCES doctors (doctor_id), + CONSTRAINT uq_visit_appointment UNIQUE (appointment_id) +); + +CREATE TABLE prescriptions ( + prescription_id NUMBER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, + visit_id NUMBER NOT NULL, + patient_id NUMBER NOT NULL, + doctor_id NUMBER NOT NULL, + prescription_date DATE DEFAULT SYSDATE NOT NULL, + notes VARCHAR2(1000), + CONSTRAINT fk_rx_visit FOREIGN KEY (visit_id) + REFERENCES patient_visits (visit_id), + CONSTRAINT fk_rx_patient FOREIGN KEY (patient_id) + REFERENCES patients (patient_id), + CONSTRAINT fk_rx_doctor FOREIGN KEY (doctor_id) + REFERENCES doctors (doctor_id), + CONSTRAINT uq_rx_visit UNIQUE (visit_id) +); + +CREATE TABLE prescription_items ( + prescription_item_id NUMBER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, + prescription_id NUMBER NOT NULL, + medicine_id NUMBER NOT NULL, + dosage VARCHAR2(100), + frequency VARCHAR2(100), + duration_days NUMBER(5), + instructions VARCHAR2(300), + CONSTRAINT fk_rxitem_rx FOREIGN KEY (prescription_id) + REFERENCES prescriptions (prescription_id) ON DELETE CASCADE, + CONSTRAINT fk_rxitem_med FOREIGN KEY (medicine_id) + REFERENCES medicines (medicine_id), + CONSTRAINT chk_rxitem_duration CHECK (duration_days IS NULL OR duration_days > 0) +); + +CREATE TABLE rooms ( + room_id NUMBER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, + room_no VARCHAR2(20) NOT NULL, + room_type VARCHAR2(30) NOT NULL, + daily_rate NUMBER(10, 3) DEFAULT 0 NOT NULL, + status VARCHAR2(20) DEFAULT 'Available' NOT NULL, + CONSTRAINT uq_room_no UNIQUE (room_no), + CONSTRAINT chk_room_type CHECK (room_type IN ('General', 'Private', 'ICU')), + CONSTRAINT chk_room_status CHECK (status IN ('Available', 'Occupied', 'Maintenance')), + CONSTRAINT chk_room_rate CHECK (daily_rate >= 0) +); + +CREATE TABLE admissions ( + admission_id NUMBER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, + patient_id NUMBER NOT NULL, + doctor_id NUMBER NOT NULL, + room_id NUMBER NOT NULL, + admission_date DATE DEFAULT SYSDATE NOT NULL, + discharge_date DATE, + admission_reason VARCHAR2(500), + status VARCHAR2(20) DEFAULT 'Admitted' NOT NULL, + CONSTRAINT fk_adm_patient FOREIGN KEY (patient_id) + REFERENCES patients (patient_id), + CONSTRAINT fk_adm_doctor FOREIGN KEY (doctor_id) + REFERENCES doctors (doctor_id), + CONSTRAINT fk_adm_room FOREIGN KEY (room_id) + REFERENCES rooms (room_id), + CONSTRAINT chk_adm_status CHECK (status IN ('Admitted', 'Discharged')), + CONSTRAINT chk_adm_discharge CHECK ( + (status = 'Admitted' AND discharge_date IS NULL) + OR (status = 'Discharged' AND discharge_date IS NOT NULL) + ) +); + +-- ----------------------------------------------------------------------------- +-- INDEXES for report / lookup performance +-- ----------------------------------------------------------------------------- + +CREATE INDEX idx_doctors_dept ON doctors (department_id); +CREATE INDEX idx_doctors_spec ON doctors (specialty_id); +CREATE INDEX idx_appt_patient ON appointments (patient_id); +CREATE INDEX idx_appt_doctor ON appointments (doctor_id); +CREATE INDEX idx_appt_date ON appointments (appointment_date); +CREATE INDEX idx_visits_patient ON patient_visits (patient_id); +CREATE INDEX idx_visits_doctor ON patient_visits (doctor_id); +CREATE INDEX idx_adm_patient ON admissions (patient_id); +CREATE INDEX idx_adm_status ON admissions (status); +CREATE INDEX idx_med_stock ON medicines (current_stock, reorder_level); + +COMMIT; + +-- ============================================================================= +-- Al Noor Hospital — Views & reusable queries for Dashboard / Reports +-- Run after schema + sample data +-- ============================================================================= + +-- Patient age helper view +CREATE OR REPLACE VIEW v_patients AS +SELECT + p.*, + TRUNC(MONTHS_BETWEEN(SYSDATE, p.date_of_birth) / 12) AS age +FROM patients p; + +-- Doctors with department & specialty names +CREATE OR REPLACE VIEW v_doctors AS +SELECT + d.doctor_id, + d.full_name, + d.department_id, + dep.department_name, + d.specialty_id, + s.specialty_name, + d.mobile_no, + d.email, + d.consultation_fee, + d.status +FROM doctors d +JOIN departments dep ON dep.department_id = d.department_id +JOIN doctor_specialties s ON s.specialty_id = d.specialty_id; + +-- Medicines with stock status +CREATE OR REPLACE VIEW v_medicines AS +SELECT + m.medicine_id, + m.medicine_name, + m.category_id, + c.category_name, + m.unit, + m.current_stock, + m.reorder_level, + m.status, + CASE + WHEN m.current_stock < m.reorder_level THEN 'Low Stock' + ELSE 'Normal' + END AS stock_status +FROM medicines m +JOIN medicine_categories c ON c.category_id = m.category_id; + +-- Appointments full report view +CREATE OR REPLACE VIEW v_appointments AS +SELECT + a.appointment_id, + a.patient_id, + p.full_name AS patient_name, + p.civil_id, + a.doctor_id, + d.full_name AS doctor_name, + dep.department_id, + dep.department_name, + a.appointment_date, + a.appointment_time, + a.status_id, + st.status_name, + a.reason_for_visit, + a.created_at +FROM appointments a +JOIN patients p ON p.patient_id = a.patient_id +JOIN doctors d ON d.doctor_id = a.doctor_id +JOIN departments dep ON dep.department_id = d.department_id +JOIN appointment_statuses st ON st.status_id = a.status_id; + +-- Patient visits report view +CREATE OR REPLACE VIEW v_patient_visits AS +SELECT + v.visit_id, + v.appointment_id, + v.patient_id, + p.full_name AS patient_name, + v.doctor_id, + d.full_name AS doctor_name, + dep.department_id, + dep.department_name, + v.visit_date, + v.symptoms, + v.diagnosis, + v.notes, + v.follow_up_date +FROM patient_visits v +JOIN patients p ON p.patient_id = v.patient_id +JOIN doctors d ON d.doctor_id = v.doctor_id +JOIN departments dep ON dep.department_id = d.department_id; + +-- Admissions report view +CREATE OR REPLACE VIEW v_admissions AS +SELECT + adm.admission_id, + adm.patient_id, + p.full_name AS patient_name, + adm.doctor_id, + d.full_name AS doctor_name, + adm.room_id, + r.room_no, + r.room_type, + r.daily_rate, + adm.admission_date, + adm.discharge_date, + adm.admission_reason, + adm.status +FROM admissions adm +JOIN patients p ON p.patient_id = adm.patient_id +JOIN doctors d ON d.doctor_id = adm.doctor_id +JOIN rooms r ON r.room_id = adm.room_id; + +-- Prescription with items +CREATE OR REPLACE VIEW v_prescription_items AS +SELECT + pi.prescription_item_id, + pi.prescription_id, + pr.visit_id, + pr.patient_id, + p.full_name AS patient_name, + pr.doctor_id, + d.full_name AS doctor_name, + pr.prescription_date, + pi.medicine_id, + m.medicine_name, + pi.dosage, + pi.frequency, + pi.duration_days, + pi.instructions +FROM prescription_items pi +JOIN prescriptions pr ON pr.prescription_id = pi.prescription_id +JOIN patients p ON p.patient_id = pr.patient_id +JOIN doctors d ON d.doctor_id = pr.doctor_id +JOIN medicines m ON m.medicine_id = pi.medicine_id; + +COMMIT; + +-- ============================================================================= +-- DASHBOARD KPI QUERIES (use in APEX Card / Classic Report regions) +-- ============================================================================= + +-- KPI: Total Patients +-- SELECT COUNT(*) AS total_patients FROM patients; + +-- KPI: Today's Appointments +-- SELECT COUNT(*) AS todays_appointments +-- FROM appointments WHERE appointment_date = TRUNC(SYSDATE); + +-- KPI: Active Doctors +-- SELECT COUNT(*) AS active_doctors FROM doctors WHERE status = 'Active'; + +-- KPI: Current Admissions +-- SELECT COUNT(*) AS current_admissions FROM admissions WHERE status = 'Admitted'; + +-- KPI: Low Stock Medicines +-- SELECT COUNT(*) AS low_stock +-- FROM medicines WHERE current_stock < reorder_level AND status = 'Active'; + +-- Chart 1: Appointments by department +-- SELECT dep.department_name AS label, COUNT(*) AS value +-- FROM appointments a +-- JOIN doctors d ON d.doctor_id = a.doctor_id +-- JOIN departments dep ON dep.department_id = d.department_id +-- GROUP BY dep.department_name +-- ORDER BY value DESC; + +-- Chart 2: Patients by gender +-- SELECT gender AS label, COUNT(*) AS value +-- FROM patients GROUP BY gender; + +-- Chart 3: Medicine stock status +-- SELECT +-- CASE WHEN current_stock < reorder_level THEN 'Low Stock' ELSE 'Normal' END AS label, +-- COUNT(*) AS value +-- FROM medicines WHERE status = 'Active' +-- GROUP BY CASE WHEN current_stock < reorder_level THEN 'Low Stock' ELSE 'Normal' END; + +-- Chart 4: Admissions by room type +-- SELECT r.room_type AS label, COUNT(*) AS value +-- FROM admissions a +-- JOIN rooms r ON r.room_id = a.room_id +-- GROUP BY r.room_type; + +-- Chart 5: Monthly patient visits +-- SELECT TO_CHAR(visit_date, 'YYYY-MM') AS label, COUNT(*) AS value +-- FROM patient_visits +-- GROUP BY TO_CHAR(visit_date, 'YYYY-MM') +-- ORDER BY label; + +-- Available rooms LOV (for admissions) +-- SELECT room_no || ' (' || room_type || ')' AS d, room_id AS r +-- FROM rooms WHERE status = 'Available' ORDER BY room_no; + +-- ============================================================================= +-- Al Noor Hospital — Triggers for room status business rules +-- ============================================================================= + +CREATE OR REPLACE TRIGGER trg_admission_room_status +AFTER INSERT OR UPDATE OF status, room_id, discharge_date ON admissions +FOR EACH ROW +BEGIN + -- On admit: mark room Occupied + IF INSERTING AND :NEW.status = 'Admitted' THEN + UPDATE rooms SET status = 'Occupied' WHERE room_id = :NEW.room_id; + END IF; + + -- On status change to Admitted (e.g. re-admit edge case) + IF UPDATING AND :NEW.status = 'Admitted' AND NVL(:OLD.status, 'X') <> 'Admitted' THEN + UPDATE rooms SET status = 'Occupied' WHERE room_id = :NEW.room_id; + END IF; + + -- On discharge: free the room + IF UPDATING AND :NEW.status = 'Discharged' AND :OLD.status = 'Admitted' THEN + UPDATE rooms SET status = 'Available' WHERE room_id = :OLD.room_id; + END IF; + + -- If room changed while still admitted + IF UPDATING AND :NEW.status = 'Admitted' + AND :NEW.room_id <> :OLD.room_id THEN + UPDATE rooms SET status = 'Available' WHERE room_id = :OLD.room_id; + UPDATE rooms SET status = 'Occupied' WHERE room_id = :NEW.room_id; + END IF; +END; +/ + +-- ============================================================================= +-- Al Noor Hospital — Sample Data +-- Minima: 5+ departments, 10+ doctors, 20+ patients, 20+ medicines, +-- 30+ appointments, 10+ visits with prescriptions +-- ============================================================================= + +-- Appointment statuses +INSERT INTO appointment_statuses (status_name) VALUES ('Scheduled'); +INSERT INTO appointment_statuses (status_name) VALUES ('Completed'); +INSERT INTO appointment_statuses (status_name) VALUES ('Cancelled'); +INSERT INTO appointment_statuses (status_name) VALUES ('No Show'); + +-- Departments (5+) +INSERT INTO departments (department_name, floor_no, status) VALUES ('Cardiology', 2, 'Active'); +INSERT INTO departments (department_name, floor_no, status) VALUES ('Pediatrics', 1, 'Active'); +INSERT INTO departments (department_name, floor_no, status) VALUES ('Emergency', 0, 'Active'); +INSERT INTO departments (department_name, floor_no, status) VALUES ('Orthopedics', 3, 'Active'); +INSERT INTO departments (department_name, floor_no, status) VALUES ('Internal Medicine', 2, 'Active'); +INSERT INTO departments (department_name, floor_no, status) VALUES ('Obstetrics & Gynecology', 4, 'Active'); +INSERT INTO departments (department_name, floor_no, status) VALUES ('Neurology', 3, 'Active'); + +-- Doctor specialties +INSERT INTO doctor_specialties (specialty_name, status) VALUES ('Cardiologist', 'Active'); +INSERT INTO doctor_specialties (specialty_name, status) VALUES ('Pediatrician', 'Active'); +INSERT INTO doctor_specialties (specialty_name, status) VALUES ('Emergency Physician', 'Active'); +INSERT INTO doctor_specialties (specialty_name, status) VALUES ('Orthopedic Surgeon', 'Active'); +INSERT INTO doctor_specialties (specialty_name, status) VALUES ('Internist', 'Active'); +INSERT INTO doctor_specialties (specialty_name, status) VALUES ('Gynecologist', 'Active'); +INSERT INTO doctor_specialties (specialty_name, status) VALUES ('Neurologist', 'Active'); +INSERT INTO doctor_specialties (specialty_name, status) VALUES ('General Surgeon', 'Active'); + +-- Medicine categories +INSERT INTO medicine_categories (category_name, status) VALUES ('Antibiotic', 'Active'); +INSERT INTO medicine_categories (category_name, status) VALUES ('Painkiller', 'Active'); +INSERT INTO medicine_categories (category_name, status) VALUES ('Diabetes', 'Active'); +INSERT INTO medicine_categories (category_name, status) VALUES ('Cardiac', 'Active'); +INSERT INTO medicine_categories (category_name, status) VALUES ('Vitamins', 'Active'); +INSERT INTO medicine_categories (category_name, status) VALUES ('Respiratory', 'Active'); +INSERT INTO medicine_categories (category_name, status) VALUES ('Gastrointestinal', 'Active'); + +-- Doctors (10+) +INSERT INTO doctors (full_name, department_id, specialty_id, mobile_no, email, consultation_fee, status) +VALUES ('Dr. Ahmed Al-Balushi', 1, 1, '96891234501', 'ahmed.balushi@alnoor.om', 25.000, 'Active'); +INSERT INTO doctors (full_name, department_id, specialty_id, mobile_no, email, consultation_fee, status) +VALUES ('Dr. Fatima Al-Hinai', 2, 2, '96891234502', 'fatima.hinai@alnoor.om', 20.000, 'Active'); +INSERT INTO doctors (full_name, department_id, specialty_id, mobile_no, email, consultation_fee, status) +VALUES ('Dr. Omar Al-Riyami', 3, 3, '96891234503', 'omar.riyami@alnoor.om', 30.000, 'Active'); +INSERT INTO doctors (full_name, department_id, specialty_id, mobile_no, email, consultation_fee, status) +VALUES ('Dr. Sara Al-Harthy', 4, 4, '96891234504', 'sara.harthy@alnoor.om', 28.000, 'Active'); +INSERT INTO doctors (full_name, department_id, specialty_id, mobile_no, email, consultation_fee, status) +VALUES ('Dr. Khalid Al-Maawali', 5, 5, '96891234505', 'khalid.maawali@alnoor.om', 22.000, 'Active'); +INSERT INTO doctors (full_name, department_id, specialty_id, mobile_no, email, consultation_fee, status) +VALUES ('Dr. Maryam Al-Siyabi', 6, 6, '96891234506', 'maryam.siyabi@alnoor.om', 25.000, 'Active'); +INSERT INTO doctors (full_name, department_id, specialty_id, mobile_no, email, consultation_fee, status) +VALUES ('Dr. Yousuf Al-Kindi', 7, 7, '96891234507', 'yousuf.kindi@alnoor.om', 35.000, 'Active'); +INSERT INTO doctors (full_name, department_id, specialty_id, mobile_no, email, consultation_fee, status) +VALUES ('Dr. Nasser Al-Abri', 1, 1, '96891234508', 'nasser.abri@alnoor.om', 25.000, 'Active'); +INSERT INTO doctors (full_name, department_id, specialty_id, mobile_no, email, consultation_fee, status) +VALUES ('Dr. Aisha Al-Zadjali', 2, 2, '96891234509', 'aisha.zadjali@alnoor.om', 20.000, 'Active'); +INSERT INTO doctors (full_name, department_id, specialty_id, mobile_no, email, consultation_fee, status) +VALUES ('Dr. Hassan Al-Farsi', 5, 5, '96891234510', 'hassan.farsi@alnoor.om', 22.000, 'Active'); +INSERT INTO doctors (full_name, department_id, specialty_id, mobile_no, email, consultation_fee, status) +VALUES ('Dr. Layla Al-Amri', 3, 3, '96891234511', 'layla.amri@alnoor.om', 30.000, 'Active'); +INSERT INTO doctors (full_name, department_id, specialty_id, mobile_no, email, consultation_fee, status) +VALUES ('Dr. Salim Al-Busaidi', 4, 4, '96891234512', 'salim.busaidi@alnoor.om', 28.000, 'Inactive'); + +-- Patients (20+) +INSERT INTO patients (civil_id, full_name, gender, date_of_birth, mobile_no, email, blood_group, address, emergency_contact_name, emergency_contact_no) +VALUES ('12345671', 'Abdullah Al-Maskari', 'Male', DATE '1985-03-12', '96899110001', 'abdullah.m@email.om', 'O+', 'Al Khuwair, Muscat', 'Fatima Al-Maskari', '96899110002'); +INSERT INTO patients (civil_id, full_name, gender, date_of_birth, mobile_no, email, blood_group, address, emergency_contact_name, emergency_contact_no) +VALUES ('12345672', 'Muna Al-Ghafri', 'Female', DATE '1990-07-22', '96899110003', 'muna.g@email.om', 'A+', 'Qurum, Muscat', 'Ali Al-Ghafri', '96899110004'); +INSERT INTO patients (civil_id, full_name, gender, date_of_birth, mobile_no, email, blood_group, address, emergency_contact_name, emergency_contact_no) +VALUES ('12345673', 'Said Al-Shanfari', 'Male', DATE '1978-11-05', '96899110005', NULL, 'B+', 'Seeb, Muscat', 'Huda Al-Shanfari', '96899110006'); +INSERT INTO patients (civil_id, full_name, gender, date_of_birth, mobile_no, email, blood_group, address, emergency_contact_name, emergency_contact_no) +VALUES ('12345674', 'Nadia Al-Toubi', 'Female', DATE '2001-01-18', '96899110007', 'nadia.t@email.om', 'AB+', 'Bawshar, Muscat', 'Rashid Al-Toubi', '96899110008'); +INSERT INTO patients (civil_id, full_name, gender, date_of_birth, mobile_no, email, blood_group, address, emergency_contact_name, emergency_contact_no) +VALUES ('12345675', 'Ibrahim Al-Ajmi', 'Male', DATE '1965-09-30', '96899110009', 'ibrahim.a@email.om', 'O-', 'Al Amerat, Muscat', 'Salma Al-Ajmi', '96899110010'); +INSERT INTO patients (civil_id, full_name, gender, date_of_birth, mobile_no, email, blood_group, address, emergency_contact_name, emergency_contact_no) +VALUES ('12345676', 'Hanan Al-Mahrouqi', 'Female', DATE '1995-04-08', '96899110011', 'hanan.m@email.om', 'A-', 'Muttrah, Muscat', 'Yahya Al-Mahrouqi', '96899110012'); +INSERT INTO patients (civil_id, full_name, gender, date_of_birth, mobile_no, email, blood_group, address, emergency_contact_name, emergency_contact_no) +VALUES ('12345677', 'Rashid Al-Habsi', 'Male', DATE '1988-12-25', '96899110013', NULL, 'B-', 'Al Khoud, Muscat', 'Amal Al-Habsi', '96899110014'); +INSERT INTO patients (civil_id, full_name, gender, date_of_birth, mobile_no, email, blood_group, address, emergency_contact_name, emergency_contact_no) +VALUES ('12345678', 'Amina Al-Rawahi', 'Female', DATE '2015-06-14', '96899110015', NULL, 'O+', 'Ruwi, Muscat', 'Khalifa Al-Rawahi', '96899110016'); +INSERT INTO patients (civil_id, full_name, gender, date_of_birth, mobile_no, email, blood_group, address, emergency_contact_name, emergency_contact_no) +VALUES ('12345679', 'Tariq Al-Nabhani', 'Male', DATE '1972-02-28', '96899110017', 'tariq.n@email.om', 'A+', 'Sohar', 'Laila Al-Nabhani', '96899110018'); +INSERT INTO patients (civil_id, full_name, gender, date_of_birth, mobile_no, email, blood_group, address, emergency_contact_name, emergency_contact_no) +VALUES ('12345680', 'Zainab Al-Saadi', 'Female', DATE '1998-08-03', '96899110019', 'zainab.s@email.om', 'AB-', 'Nizwa', 'Mohammed Al-Saadi', '96899110020'); +INSERT INTO patients (civil_id, full_name, gender, date_of_birth, mobile_no, email, blood_group, address, emergency_contact_name, emergency_contact_no) +VALUES ('12345681', 'Hamad Al-Jabri', 'Male', DATE '1982-05-17', '96899110021', 'hamad.j@email.om', 'O+', 'Sur', 'Noor Al-Jabri', '96899110022'); +INSERT INTO patients (civil_id, full_name, gender, date_of_birth, mobile_no, email, blood_group, address, emergency_contact_name, emergency_contact_no) +VALUES ('12345682', 'Latifa Al-Shehhi', 'Female', DATE '1993-10-09', '96899110023', 'latifa.s@email.om', 'B+', 'Salalah', 'Sultan Al-Shehhi', '96899110024'); +INSERT INTO patients (civil_id, full_name, gender, date_of_birth, mobile_no, email, blood_group, address, emergency_contact_name, emergency_contact_no) +VALUES ('12345683', 'Majid Al-Kalbani', 'Male', DATE '2005-03-21', '96899110025', NULL, 'A+', 'Ibri', 'Wafa Al-Kalbani', '96899110026'); +INSERT INTO patients (civil_id, full_name, gender, date_of_birth, mobile_no, email, blood_group, address, emergency_contact_name, emergency_contact_no) +VALUES ('12345684', 'Bushra Al-Omairi', 'Female', DATE '1987-07-11', '96899110027', 'bushra.o@email.om', 'O-', 'Barka', 'Fahad Al-Omairi', '96899110028'); +INSERT INTO patients (civil_id, full_name, gender, date_of_birth, mobile_no, email, blood_group, address, emergency_contact_name, emergency_contact_no) +VALUES ('12345685', 'Waleed Al-Dhuhli', 'Male', DATE '1975-11-19', '96899110029', 'waleed.d@email.om', 'B+', 'Al Khuwair, Muscat', 'Rania Al-Dhuhli', '96899110030'); +INSERT INTO patients (civil_id, full_name, gender, date_of_birth, mobile_no, email, blood_group, address, emergency_contact_name, emergency_contact_no) +VALUES ('12345686', 'Reem Al-Ismaili', 'Female', DATE '2010-01-30', '96899110031', NULL, 'A-', 'Qurum, Muscat', 'Juma Al-Ismaili', '96899110032'); +INSERT INTO patients (civil_id, full_name, gender, date_of_birth, mobile_no, email, blood_group, address, emergency_contact_name, emergency_contact_no) +VALUES ('12345687', 'Fahad Al-Qasmi', 'Male', DATE '1991-09-07', '96899110033', 'fahad.q@email.om', 'AB+', 'Seeb, Muscat', 'Maha Al-Qasmi', '96899110034'); +INSERT INTO patients (civil_id, full_name, gender, date_of_birth, mobile_no, email, blood_group, address, emergency_contact_name, emergency_contact_no) +VALUES ('12345688', 'Shaima Al-Aufi', 'Female', DATE '1984-04-26', '96899110035', 'shaima.a@email.om', 'O+', 'Bawshar, Muscat', 'Bader Al-Aufi', '96899110036'); +INSERT INTO patients (civil_id, full_name, gender, date_of_birth, mobile_no, email, blood_group, address, emergency_contact_name, emergency_contact_no) +VALUES ('12345689', 'Nasser Al-Suleimani', 'Male', DATE '1969-12-01', '96899110037', 'nasser.s@email.om', 'A+', 'Al Ghubra, Muscat', 'Huda Al-Suleimani', '96899110038'); +INSERT INTO patients (civil_id, full_name, gender, date_of_birth, mobile_no, email, blood_group, address, emergency_contact_name, emergency_contact_no) +VALUES ('12345690', 'Maryam Al-Hadhrami', 'Female', DATE '1996-06-15', '96899110039', 'maryam.h@email.om', 'B-', 'Muttrah, Muscat', 'Omar Al-Hadhrami', '96899110040'); +INSERT INTO patients (civil_id, full_name, gender, date_of_birth, mobile_no, email, blood_group, address, emergency_contact_name, emergency_contact_no) +VALUES ('12345691', 'Khalifa Al-Yaarubi', 'Male', DATE '2000-02-14', '96899110041', NULL, 'O+', 'Al Khoud, Muscat', 'Asma Al-Yaarubi', '96899110042'); +INSERT INTO patients (civil_id, full_name, gender, date_of_birth, mobile_no, email, blood_group, address, emergency_contact_name, emergency_contact_no) +VALUES ('12345692', 'Asma Al-Kharusi', 'Female', DATE '1979-08-20', '96899110043', 'asma.k@email.om', 'A+', 'Ruwi, Muscat', 'Said Al-Kharusi', '96899110044'); + +-- Medicines (20+) — some below reorder level for low-stock demos +INSERT INTO medicines (medicine_name, category_id, unit, current_stock, reorder_level, status) +VALUES ('Amoxicillin 500mg', 1, 'Tablet', 120, 30, 'Active'); +INSERT INTO medicines (medicine_name, category_id, unit, current_stock, reorder_level, status) +VALUES ('Azithromycin 250mg', 1, 'Tablet', 8, 25, 'Active'); +INSERT INTO medicines (medicine_name, category_id, unit, current_stock, reorder_level, status) +VALUES ('Ceftriaxone 1g', 1, 'Injection', 45, 20, 'Active'); +INSERT INTO medicines (medicine_name, category_id, unit, current_stock, reorder_level, status) +VALUES ('Paracetamol 500mg', 2, 'Tablet', 200, 50, 'Active'); +INSERT INTO medicines (medicine_name, category_id, unit, current_stock, reorder_level, status) +VALUES ('Ibuprofen 400mg', 2, 'Tablet', 15, 40, 'Active'); +INSERT INTO medicines (medicine_name, category_id, unit, current_stock, reorder_level, status) +VALUES ('Diclofenac 50mg', 2, 'Tablet', 90, 30, 'Active'); +INSERT INTO medicines (medicine_name, category_id, unit, current_stock, reorder_level, status) +VALUES ('Metformin 500mg', 3, 'Tablet', 150, 40, 'Active'); +INSERT INTO medicines (medicine_name, category_id, unit, current_stock, reorder_level, status) +VALUES ('Insulin Glargine', 3, 'Injection', 5, 15, 'Active'); +INSERT INTO medicines (medicine_name, category_id, unit, current_stock, reorder_level, status) +VALUES ('Gliclazide 80mg', 3, 'Tablet', 70, 20, 'Active'); +INSERT INTO medicines (medicine_name, category_id, unit, current_stock, reorder_level, status) +VALUES ('Atenolol 50mg', 4, 'Tablet', 100, 25, 'Active'); +INSERT INTO medicines (medicine_name, category_id, unit, current_stock, reorder_level, status) +VALUES ('Amlodipine 5mg', 4, 'Tablet', 12, 30, 'Active'); +INSERT INTO medicines (medicine_name, category_id, unit, current_stock, reorder_level, status) +VALUES ('Aspirin 81mg', 4, 'Tablet', 180, 50, 'Active'); +INSERT INTO medicines (medicine_name, category_id, unit, current_stock, reorder_level, status) +VALUES ('Vitamin D3 1000IU', 5, 'Tablet', 60, 20, 'Active'); +INSERT INTO medicines (medicine_name, category_id, unit, current_stock, reorder_level, status) +VALUES ('Folic Acid 5mg', 5, 'Tablet', 3, 20, 'Active'); +INSERT INTO medicines (medicine_name, category_id, unit, current_stock, reorder_level, status) +VALUES ('Multivitamin Syrup', 5, 'Syrup', 40, 15, 'Active'); +INSERT INTO medicines (medicine_name, category_id, unit, current_stock, reorder_level, status) +VALUES ('Salbutamol Inhaler', 6, 'Inhaler', 55, 20, 'Active'); +INSERT INTO medicines (medicine_name, category_id, unit, current_stock, reorder_level, status) +VALUES ('Ambroxol Syrup', 6, 'Syrup', 7, 25, 'Active'); +INSERT INTO medicines (medicine_name, category_id, unit, current_stock, reorder_level, status) +VALUES ('Montelukast 10mg', 6, 'Tablet', 80, 25, 'Active'); +INSERT INTO medicines (medicine_name, category_id, unit, current_stock, reorder_level, status) +VALUES ('Omeprazole 20mg', 7, 'Capsule', 110, 30, 'Active'); +INSERT INTO medicines (medicine_name, category_id, unit, current_stock, reorder_level, status) +VALUES ('Domperidone 10mg', 7, 'Tablet', 95, 25, 'Active'); +INSERT INTO medicines (medicine_name, category_id, unit, current_stock, reorder_level, status) +VALUES ('ORS Sachets', 7, 'Sachet', 4, 30, 'Active'); +INSERT INTO medicines (medicine_name, category_id, unit, current_stock, reorder_level, status) +VALUES ('Ciprofloxacin 500mg', 1, 'Tablet', 65, 20, 'Active'); + +-- Rooms +-- Room status for active admissions is set by trg_admission_room_status +INSERT INTO rooms (room_no, room_type, daily_rate, status) VALUES ('G-101', 'General', 40.000, 'Available'); +INSERT INTO rooms (room_no, room_type, daily_rate, status) VALUES ('G-102', 'General', 40.000, 'Available'); +INSERT INTO rooms (room_no, room_type, daily_rate, status) VALUES ('G-103', 'General', 40.000, 'Available'); +INSERT INTO rooms (room_no, room_type, daily_rate, status) VALUES ('P-201', 'Private', 80.000, 'Available'); +INSERT INTO rooms (room_no, room_type, daily_rate, status) VALUES ('P-202', 'Private', 80.000, 'Available'); +INSERT INTO rooms (room_no, room_type, daily_rate, status) VALUES ('P-203', 'Private', 90.000, 'Available'); +INSERT INTO rooms (room_no, room_type, daily_rate, status) VALUES ('ICU-01', 'ICU', 200.000, 'Available'); +INSERT INTO rooms (room_no, room_type, daily_rate, status) VALUES ('ICU-02', 'ICU', 200.000, 'Available'); +INSERT INTO rooms (room_no, room_type, daily_rate, status) VALUES ('G-104', 'General', 40.000, 'Maintenance'); +INSERT INTO rooms (room_no, room_type, daily_rate, status) VALUES ('P-204', 'Private', 85.000, 'Available'); + +-- Appointments (30+) — mix of past completed and upcoming scheduled +-- Status: 1=Scheduled, 2=Completed, 3=Cancelled, 4=No Show + +INSERT INTO appointments (patient_id, doctor_id, appointment_date, appointment_time, status_id, reason_for_visit, created_at) +VALUES (1, 1, TRUNC(SYSDATE) - 20, '09:00', 2, 'Chest pain follow-up', TRUNC(SYSDATE) - 25); +INSERT INTO appointments (patient_id, doctor_id, appointment_date, appointment_time, status_id, reason_for_visit, created_at) +VALUES (2, 2, TRUNC(SYSDATE) - 18, '10:00', 2, 'Child fever', TRUNC(SYSDATE) - 20); +INSERT INTO appointments (patient_id, doctor_id, appointment_date, appointment_time, status_id, reason_for_visit, created_at) +VALUES (3, 5, TRUNC(SYSDATE) - 15, '11:00', 2, 'Diabetes review', TRUNC(SYSDATE) - 18); +INSERT INTO appointments (patient_id, doctor_id, appointment_date, appointment_time, status_id, reason_for_visit, created_at) +VALUES (4, 6, TRUNC(SYSDATE) - 14, '09:30', 2, 'Routine checkup', TRUNC(SYSDATE) - 16); +INSERT INTO appointments (patient_id, doctor_id, appointment_date, appointment_time, status_id, reason_for_visit, created_at) +VALUES (5, 1, TRUNC(SYSDATE) - 12, '14:00', 2, 'Hypertension', TRUNC(SYSDATE) - 14); +INSERT INTO appointments (patient_id, doctor_id, appointment_date, appointment_time, status_id, reason_for_visit, created_at) +VALUES (6, 7, TRUNC(SYSDATE) - 10, '15:00', 2, 'Migraine', TRUNC(SYSDATE) - 12); +INSERT INTO appointments (patient_id, doctor_id, appointment_date, appointment_time, status_id, reason_for_visit, created_at) +VALUES (7, 4, TRUNC(SYSDATE) - 9, '10:30', 2, 'Knee pain', TRUNC(SYSDATE) - 11); +INSERT INTO appointments (patient_id, doctor_id, appointment_date, appointment_time, status_id, reason_for_visit, created_at) +VALUES (8, 2, TRUNC(SYSDATE) - 8, '11:30', 2, 'Vaccination', TRUNC(SYSDATE) - 10); +INSERT INTO appointments (patient_id, doctor_id, appointment_date, appointment_time, status_id, reason_for_visit, created_at) +VALUES (9, 10, TRUNC(SYSDATE) - 7, '09:00', 2, 'Abdominal pain', TRUNC(SYSDATE) - 9); +INSERT INTO appointments (patient_id, doctor_id, appointment_date, appointment_time, status_id, reason_for_visit, created_at) +VALUES (10, 5, TRUNC(SYSDATE) - 6, '13:00', 2, 'Fatigue and dizziness', TRUNC(SYSDATE) - 8); +INSERT INTO appointments (patient_id, doctor_id, appointment_date, appointment_time, status_id, reason_for_visit, created_at) +VALUES (11, 8, TRUNC(SYSDATE) - 5, '16:00', 2, 'ECG review', TRUNC(SYSDATE) - 7); +INSERT INTO appointments (patient_id, doctor_id, appointment_date, appointment_time, status_id, reason_for_visit, created_at) +VALUES (12, 9, TRUNC(SYSDATE) - 4, '10:00', 2, 'Growth check', TRUNC(SYSDATE) - 6); +INSERT INTO appointments (patient_id, doctor_id, appointment_date, appointment_time, status_id, reason_for_visit, created_at) +VALUES (13, 3, TRUNC(SYSDATE) - 3, '08:00', 4, 'Minor injury', TRUNC(SYSDATE) - 5); +INSERT INTO appointments (patient_id, doctor_id, appointment_date, appointment_time, status_id, reason_for_visit, created_at) +VALUES (14, 6, TRUNC(SYSDATE) - 2, '12:00', 3, 'Consultation cancelled', TRUNC(SYSDATE) - 4); +INSERT INTO appointments (patient_id, doctor_id, appointment_date, appointment_time, status_id, reason_for_visit, created_at) +VALUES (15, 1, TRUNC(SYSDATE) - 1, '09:00', 2, 'Cardiac follow-up', TRUNC(SYSDATE) - 3); +INSERT INTO appointments (patient_id, doctor_id, appointment_date, appointment_time, status_id, reason_for_visit, created_at) +VALUES (16, 2, TRUNC(SYSDATE), '09:00', 1, 'Cough and cold', TRUNC(SYSDATE) - 1); +INSERT INTO appointments (patient_id, doctor_id, appointment_date, appointment_time, status_id, reason_for_visit, created_at) +VALUES (17, 5, TRUNC(SYSDATE), '10:00', 1, 'Blood pressure check', TRUNC(SYSDATE) - 1); +INSERT INTO appointments (patient_id, doctor_id, appointment_date, appointment_time, status_id, reason_for_visit, created_at) +VALUES (18, 4, TRUNC(SYSDATE), '11:00', 1, 'Back pain', TRUNC(SYSDATE) - 1); +INSERT INTO appointments (patient_id, doctor_id, appointment_date, appointment_time, status_id, reason_for_visit, created_at) +VALUES (19, 7, TRUNC(SYSDATE), '14:00', 1, 'Headache', SYSDATE); +INSERT INTO appointments (patient_id, doctor_id, appointment_date, appointment_time, status_id, reason_for_visit, created_at) +VALUES (20, 3, TRUNC(SYSDATE), '15:00', 1, 'Emergency review', SYSDATE); +INSERT INTO appointments (patient_id, doctor_id, appointment_date, appointment_time, status_id, reason_for_visit, created_at) +VALUES (1, 8, TRUNC(SYSDATE) + 1, '09:30', 1, 'Follow-up cardiology', SYSDATE); +INSERT INTO appointments (patient_id, doctor_id, appointment_date, appointment_time, status_id, reason_for_visit, created_at) +VALUES (2, 9, TRUNC(SYSDATE) + 1, '10:30', 1, 'Pediatric review', SYSDATE); +INSERT INTO appointments (patient_id, doctor_id, appointment_date, appointment_time, status_id, reason_for_visit, created_at) +VALUES (3, 10, TRUNC(SYSDATE) + 2, '11:00', 1, 'Lab results review', SYSDATE); +INSERT INTO appointments (patient_id, doctor_id, appointment_date, appointment_time, status_id, reason_for_visit, created_at) +VALUES (5, 1, TRUNC(SYSDATE) + 2, '14:30', 1, 'ECG appointment', SYSDATE); +INSERT INTO appointments (patient_id, doctor_id, appointment_date, appointment_time, status_id, reason_for_visit, created_at) +VALUES (7, 4, TRUNC(SYSDATE) + 3, '09:00', 1, 'Physio referral', SYSDATE); +INSERT INTO appointments (patient_id, doctor_id, appointment_date, appointment_time, status_id, reason_for_visit, created_at) +VALUES (9, 5, TRUNC(SYSDATE) + 3, '10:00', 1, 'Diabetes education', SYSDATE); +INSERT INTO appointments (patient_id, doctor_id, appointment_date, appointment_time, status_id, reason_for_visit, created_at) +VALUES (11, 8, TRUNC(SYSDATE) + 4, '11:30', 1, 'Medication review', SYSDATE); +INSERT INTO appointments (patient_id, doctor_id, appointment_date, appointment_time, status_id, reason_for_visit, created_at) +VALUES (12, 6, TRUNC(SYSDATE) + 5, '09:00', 1, 'Prenatal visit', SYSDATE); +INSERT INTO appointments (patient_id, doctor_id, appointment_date, appointment_time, status_id, reason_for_visit, created_at) +VALUES (15, 7, TRUNC(SYSDATE) + 5, '15:00', 1, 'Neurology consult', SYSDATE); +INSERT INTO appointments (patient_id, doctor_id, appointment_date, appointment_time, status_id, reason_for_visit, created_at) +VALUES (21, 11, TRUNC(SYSDATE) + 6, '08:30', 1, 'Trauma follow-up', SYSDATE); +INSERT INTO appointments (patient_id, doctor_id, appointment_date, appointment_time, status_id, reason_for_visit, created_at) +VALUES (22, 10, TRUNC(SYSDATE) + 7, '13:00', 1, 'General checkup', SYSDATE); +INSERT INTO appointments (patient_id, doctor_id, appointment_date, appointment_time, status_id, reason_for_visit, created_at) +VALUES (4, 2, TRUNC(SYSDATE) - 25, '09:00', 2, 'Allergy consult', TRUNC(SYSDATE) - 28); +INSERT INTO appointments (patient_id, doctor_id, appointment_date, appointment_time, status_id, reason_for_visit, created_at) +VALUES (8, 9, TRUNC(SYSDATE) - 22, '10:00', 2, 'Ear infection', TRUNC(SYSDATE) - 24); + +-- Patient visits (10+) linked to completed appointments 1-12, 15, 32, 33 +INSERT INTO patient_visits (appointment_id, patient_id, doctor_id, visit_date, symptoms, diagnosis, notes, follow_up_date) +VALUES (1, 1, 1, TRUNC(SYSDATE) - 20, 'Chest discomfort, mild shortness of breath', 'Stable angina', 'Continue current medication. Lifestyle advice given.', TRUNC(SYSDATE) + 10); +INSERT INTO patient_visits (appointment_id, patient_id, doctor_id, visit_date, symptoms, diagnosis, notes, follow_up_date) +VALUES (2, 2, 2, TRUNC(SYSDATE) - 18, 'High fever, cough for 3 days', 'Viral upper respiratory infection', 'Hydration and rest advised.', NULL); +INSERT INTO patient_visits (appointment_id, patient_id, doctor_id, visit_date, symptoms, diagnosis, notes, follow_up_date) +VALUES (3, 3, 5, TRUNC(SYSDATE) - 15, 'Polyuria, fatigue', 'Type 2 Diabetes Mellitus', 'Adjust metformin dose. Diet counseling.', TRUNC(SYSDATE) + 30); +INSERT INTO patient_visits (appointment_id, patient_id, doctor_id, visit_date, symptoms, diagnosis, notes, follow_up_date) +VALUES (4, 4, 6, TRUNC(SYSDATE) - 14, 'Routine antenatal visit', 'Normal pregnancy', 'Next visit in 4 weeks.', TRUNC(SYSDATE) + 28); +INSERT INTO patient_visits (appointment_id, patient_id, doctor_id, visit_date, symptoms, diagnosis, notes, follow_up_date) +VALUES (5, 5, 1, TRUNC(SYSDATE) - 12, 'Elevated BP readings at home', 'Hypertension', 'Started amlodipine. Monitor BP.', TRUNC(SYSDATE) + 14); +INSERT INTO patient_visits (appointment_id, patient_id, doctor_id, visit_date, symptoms, diagnosis, notes, follow_up_date) +VALUES (6, 6, 7, TRUNC(SYSDATE) - 10, 'Severe headache, photophobia', 'Migraine without aura', 'Prescribed acute therapy.', TRUNC(SYSDATE) + 21); +INSERT INTO patient_visits (appointment_id, patient_id, doctor_id, visit_date, symptoms, diagnosis, notes, follow_up_date) +VALUES (7, 7, 4, TRUNC(SYSDATE) - 9, 'Right knee pain after sports', 'Patellar tendinitis', 'Rest, ice, physiotherapy referral.', TRUNC(SYSDATE) + 14); +INSERT INTO patient_visits (appointment_id, patient_id, doctor_id, visit_date, symptoms, diagnosis, notes, follow_up_date) +VALUES (8, 8, 2, TRUNC(SYSDATE) - 8, 'Due for MMR booster', 'Routine immunization', 'Vaccination given. Observe 15 min.', NULL); +INSERT INTO patient_visits (appointment_id, patient_id, doctor_id, visit_date, symptoms, diagnosis, notes, follow_up_date) +VALUES (9, 9, 10, TRUNC(SYSDATE) - 7, 'Epigastric pain after meals', 'Gastritis', 'Avoid spicy food. PPI prescribed.', TRUNC(SYSDATE) + 14); +INSERT INTO patient_visits (appointment_id, patient_id, doctor_id, visit_date, symptoms, diagnosis, notes, follow_up_date) +VALUES (10, 10, 5, TRUNC(SYSDATE) - 6, 'Fatigue, dizziness', 'Iron deficiency anemia', 'Labs ordered. Folic acid started.', TRUNC(SYSDATE) + 21); +INSERT INTO patient_visits (appointment_id, patient_id, doctor_id, visit_date, symptoms, diagnosis, notes, follow_up_date) +VALUES (11, 11, 8, TRUNC(SYSDATE) - 5, 'Palpitations', 'Sinus tachycardia', 'ECG normal. Reduce caffeine.', TRUNC(SYSDATE) + 30); +INSERT INTO patient_visits (appointment_id, patient_id, doctor_id, visit_date, symptoms, diagnosis, notes, follow_up_date) +VALUES (15, 15, 1, TRUNC(SYSDATE) - 1, 'Post-op cardiac review', 'Stable post angioplasty', 'Continue dual antiplatelet therapy.', TRUNC(SYSDATE) + 30); + +-- Prescriptions for visits +INSERT INTO prescriptions (visit_id, patient_id, doctor_id, prescription_date, notes) +VALUES (1, 1, 1, TRUNC(SYSDATE) - 20, 'Cardiac medications'); +INSERT INTO prescriptions (visit_id, patient_id, doctor_id, prescription_date, notes) +VALUES (2, 2, 2, TRUNC(SYSDATE) - 18, 'Symptomatic relief'); +INSERT INTO prescriptions (visit_id, patient_id, doctor_id, prescription_date, notes) +VALUES (3, 3, 5, TRUNC(SYSDATE) - 15, 'Diabetes control'); +INSERT INTO prescriptions (visit_id, patient_id, doctor_id, prescription_date, notes) +VALUES (5, 5, 1, TRUNC(SYSDATE) - 12, 'BP control'); +INSERT INTO prescriptions (visit_id, patient_id, doctor_id, prescription_date, notes) +VALUES (6, 6, 7, TRUNC(SYSDATE) - 10, 'Migraine management'); +INSERT INTO prescriptions (visit_id, patient_id, doctor_id, prescription_date, notes) +VALUES (7, 7, 4, TRUNC(SYSDATE) - 9, 'Pain management'); +INSERT INTO prescriptions (visit_id, patient_id, doctor_id, prescription_date, notes) +VALUES (9, 9, 10, TRUNC(SYSDATE) - 7, 'Gastritis treatment'); +INSERT INTO prescriptions (visit_id, patient_id, doctor_id, prescription_date, notes) +VALUES (10, 10, 5, TRUNC(SYSDATE) - 6, 'Anemia support'); +INSERT INTO prescriptions (visit_id, patient_id, doctor_id, prescription_date, notes) +VALUES (11, 11, 8, TRUNC(SYSDATE) - 5, 'Supportive care'); +INSERT INTO prescriptions (visit_id, patient_id, doctor_id, prescription_date, notes) +VALUES (12, 15, 1, TRUNC(SYSDATE) - 1, 'Post cardiac care'); + +-- Prescription items (multiple medicines per some prescriptions) +INSERT INTO prescription_items (prescription_id, medicine_id, dosage, frequency, duration_days, instructions) +VALUES (1, 10, '50mg', 'Once daily', 30, 'After breakfast'); +INSERT INTO prescription_items (prescription_id, medicine_id, dosage, frequency, duration_days, instructions) +VALUES (1, 12, '81mg', 'Once daily', 30, 'After food'); +INSERT INTO prescription_items (prescription_id, medicine_id, dosage, frequency, duration_days, instructions) +VALUES (2, 4, '500mg', 'Every 6 hours', 5, 'As needed for fever'); +INSERT INTO prescription_items (prescription_id, medicine_id, dosage, frequency, duration_days, instructions) +VALUES (2, 17, '5ml', 'Twice daily', 5, 'After food'); +INSERT INTO prescription_items (prescription_id, medicine_id, dosage, frequency, duration_days, instructions) +VALUES (3, 7, '500mg', 'Twice daily', 30, 'With meals'); +INSERT INTO prescription_items (prescription_id, medicine_id, dosage, frequency, duration_days, instructions) +VALUES (4, 11, '5mg', 'Once daily', 30, 'Morning'); +INSERT INTO prescription_items (prescription_id, medicine_id, dosage, frequency, duration_days, instructions) +VALUES (5, 5, '400mg', 'Twice daily', 7, 'With food'); +INSERT INTO prescription_items (prescription_id, medicine_id, dosage, frequency, duration_days, instructions) +VALUES (5, 4, '500mg', 'As needed', 7, 'For headache'); +INSERT INTO prescription_items (prescription_id, medicine_id, dosage, frequency, duration_days, instructions) +VALUES (6, 6, '50mg', 'Twice daily', 7, 'After food'); +INSERT INTO prescription_items (prescription_id, medicine_id, dosage, frequency, duration_days, instructions) +VALUES (7, 19, '20mg', 'Once daily', 14, 'Before breakfast'); +INSERT INTO prescription_items (prescription_id, medicine_id, dosage, frequency, duration_days, instructions) +VALUES (7, 20, '10mg', 'Three times daily', 7, 'Before meals'); +INSERT INTO prescription_items (prescription_id, medicine_id, dosage, frequency, duration_days, instructions) +VALUES (8, 14, '5mg', 'Once daily', 30, 'With water'); +INSERT INTO prescription_items (prescription_id, medicine_id, dosage, frequency, duration_days, instructions) +VALUES (8, 13, '1000IU', 'Once daily', 30, 'With food'); +INSERT INTO prescription_items (prescription_id, medicine_id, dosage, frequency, duration_days, instructions) +VALUES (9, 4, '500mg', 'As needed', 5, 'For discomfort'); +INSERT INTO prescription_items (prescription_id, medicine_id, dosage, frequency, duration_days, instructions) +VALUES (10, 12, '81mg', 'Once daily', 90, 'Lifelong unless advised'); +INSERT INTO prescription_items (prescription_id, medicine_id, dosage, frequency, duration_days, instructions) +VALUES (10, 10, '50mg', 'Once daily', 30, 'After breakfast'); + +-- Admissions (some current, some discharged) +INSERT INTO admissions (patient_id, doctor_id, room_id, admission_date, discharge_date, admission_reason, status) +VALUES (5, 1, 3, TRUNC(SYSDATE) - 3, NULL, 'Uncontrolled hypertension observation', 'Admitted'); +INSERT INTO admissions (patient_id, doctor_id, room_id, admission_date, discharge_date, admission_reason, status) +VALUES (1, 8, 5, TRUNC(SYSDATE) - 5, NULL, 'Cardiac monitoring', 'Admitted'); +INSERT INTO admissions (patient_id, doctor_id, room_id, admission_date, discharge_date, admission_reason, status) +VALUES (9, 10, 8, TRUNC(SYSDATE) - 2, NULL, 'Severe dehydration / gastritis', 'Admitted'); +INSERT INTO admissions (patient_id, doctor_id, room_id, admission_date, discharge_date, admission_reason, status) +VALUES (3, 5, 1, TRUNC(SYSDATE) - 20, TRUNC(SYSDATE) - 17, 'Diabetes ketoacidosis risk', 'Discharged'); +INSERT INTO admissions (patient_id, doctor_id, room_id, admission_date, discharge_date, admission_reason, status) +VALUES (7, 4, 4, TRUNC(SYSDATE) - 15, TRUNC(SYSDATE) - 12, 'Post knee injury observation', 'Discharged'); +INSERT INTO admissions (patient_id, doctor_id, room_id, admission_date, discharge_date, admission_reason, status) +VALUES (15, 1, 7, TRUNC(SYSDATE) - 30, TRUNC(SYSDATE) - 25, 'Post angioplasty care', 'Discharged'); + +COMMIT; + +-- Quick verification counts +SELECT 'DEPARTMENTS' AS entity, COUNT(*) AS cnt FROM departments +UNION ALL SELECT 'DOCTORS', COUNT(*) FROM doctors +UNION ALL SELECT 'PATIENTS', COUNT(*) FROM patients +UNION ALL SELECT 'MEDICINES', COUNT(*) FROM medicines +UNION ALL SELECT 'APPOINTMENTS', COUNT(*) FROM appointments +UNION ALL SELECT 'VISITS', COUNT(*) FROM patient_visits +UNION ALL SELECT 'PRESCRIPTIONS', COUNT(*) FROM prescriptions +UNION ALL SELECT 'ADMISSIONS', COUNT(*) FROM admissions; diff --git a/sql/install_all.sql b/sql/install_all.sql new file mode 100644 index 00000000..f2c8b6c8 --- /dev/null +++ b/sql/install_all.sql @@ -0,0 +1,18 @@ +-- ============================================================================= +-- Al Noor Hospital — Install all (run in SQL Workshop / SQL*Plus / SQLcl) +-- ============================================================================= + +@@00_drop_tables.sql +@@01_schema.sql +@@03_views.sql +@@04_triggers.sql +@@02_sample_data.sql + +-- Done. Verify: +SELECT table_name FROM user_tables +WHERE table_name IN ( + 'DEPARTMENTS','DOCTOR_SPECIALTIES','MEDICINE_CATEGORIES','APPOINTMENT_STATUSES', + 'PATIENTS','DOCTORS','MEDICINES','APPOINTMENTS','PATIENT_VISITS', + 'PRESCRIPTIONS','PRESCRIPTION_ITEMS','ROOMS','ADMISSIONS' +) +ORDER BY table_name;