From 6c4d18bb9928abb20c7f13f077a6848a2a4918f7 Mon Sep 17 00:00:00 2001 From: Manvitha Dungi Date: Wed, 11 Mar 2026 12:53:50 +0530 Subject: [PATCH 1/2] fixed appointment bug --- DB/reset_and_reseed.sql | 865 ------------------ DB/seed_users.sql | 416 +++++++++ .../controller/AppointmentController.java | 12 +- .../backend/service/AppointmentService.java | 37 +- .../controller/AppointmentControllerTest.java | 5 +- .../service/AppointmentServiceTest.java | 3 +- .../admin/AppointmentApprovalQueue.jsx | 40 +- .../app/src/pages/patient/Appointments.jsx | 10 +- frontend/app/src/services/api.js | 22 + 9 files changed, 480 insertions(+), 930 deletions(-) delete mode 100644 DB/reset_and_reseed.sql create mode 100644 DB/seed_users.sql diff --git a/DB/reset_and_reseed.sql b/DB/reset_and_reseed.sql deleted file mode 100644 index e9d59704..00000000 --- a/DB/reset_and_reseed.sql +++ /dev/null @@ -1,865 +0,0 @@ --- ================================================================================= --- PATIENT MANAGEMENT SYSTEM - Entity-Aligned Reset and Reseed --- Source of truth: backend JPA entities under backend/Backend/src/main/java/.../model --- ================================================================================= - --- 1. CLEANUP -DROP TABLE IF EXISTS consent_log CASCADE; -DROP TABLE IF EXISTS doctor_working_days CASCADE; -DROP TABLE IF EXISTS patient_consents CASCADE; -DROP TABLE IF EXISTS nurse_tasks CASCADE; -DROP TABLE IF EXISTS handover_notes CASCADE; -DROP TABLE IF EXISTS archived_users CASCADE; -DROP TABLE IF EXISTS password_reset_tokens CASCADE; -DROP TABLE IF EXISTS password_history CASCADE; -DROP TABLE IF EXISTS audit_logs CASCADE; -DROP TABLE IF EXISTS lab_tests CASCADE; -DROP TABLE IF EXISTS vital_signs CASCADE; -DROP TABLE IF EXISTS prescriptions CASCADE; -DROP TABLE IF EXISTS medical_records CASCADE; -DROP TABLE IF EXISTS appointments CASCADE; -DROP TABLE IF EXISTS doctor_profiles CASCADE; -DROP TABLE IF EXISTS patient_profiles CASCADE; -DROP TABLE IF EXISTS sessions CASCADE; -DROP TABLE IF EXISTS login CASCADE; - -DROP TYPE IF EXISTS request_status CASCADE; -DROP TYPE IF EXISTS user_role_type CASCADE; - --- 2. ENUMS (optional app-level compatibility) -CREATE TYPE request_status AS ENUM ('PENDING', 'APPROVED', 'REJECTED'); -CREATE TYPE user_role_type AS ENUM ('PATIENT', 'DOCTOR', 'NURSE', 'ADMIN', 'LAB_TECHNICIAN'); - --- ================================================================================= --- CORE IDENTITY & SECURITY --- ================================================================================= - -CREATE TABLE login ( - user_id BIGSERIAL PRIMARY KEY, - two_factor_enabled BOOLEAN DEFAULT FALSE, - otp VARCHAR(10), - otp_expiry TIMESTAMP, - email VARCHAR(255) UNIQUE NOT NULL, - password_hash VARCHAR(255) NOT NULL, - role VARCHAR(50) NOT NULL, - failed_attempts INT DEFAULT 0, - is_locked BOOLEAN DEFAULT FALSE, - lockout_until TIMESTAMP, - created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - last_login_at TIMESTAMP, - archived BOOLEAN DEFAULT FALSE, - is_active BOOLEAN DEFAULT TRUE, - is_verified BOOLEAN DEFAULT FALSE, - otp_secret VARCHAR(255) -); - -CREATE TABLE sessions ( - id BIGSERIAL PRIMARY KEY, - user_id BIGINT NOT NULL REFERENCES login(user_id) ON DELETE CASCADE, - refresh_token_hash VARCHAR(255) UNIQUE NOT NULL, - ip_address VARCHAR(45), - user_agent TEXT, - expires_at TIMESTAMP NOT NULL, - revoked BOOLEAN NOT NULL DEFAULT FALSE, - created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP -); - -CREATE TABLE password_history ( - id BIGSERIAL PRIMARY KEY, - user_id BIGINT NOT NULL REFERENCES login(user_id) ON DELETE CASCADE, - password_hash VARCHAR(255) NOT NULL, - created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP -); - -CREATE TABLE password_reset_tokens ( - id BIGSERIAL PRIMARY KEY, - user_id BIGINT NOT NULL REFERENCES login(user_id) ON DELETE CASCADE, - token_hash VARCHAR(255) UNIQUE NOT NULL, - expires_at TIMESTAMP NOT NULL, - used BOOLEAN DEFAULT FALSE, - created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP -); - -CREATE TABLE archived_users ( - id BIGSERIAL PRIMARY KEY, - original_user_id BIGINT NOT NULL, - email VARCHAR(255) NOT NULL, - role VARCHAR(50) NOT NULL, - last_active_at TIMESTAMP, - archived_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, - reason TEXT -); - -CREATE TABLE audit_logs ( - id BIGSERIAL PRIMARY KEY, - email VARCHAR(255) NOT NULL, - action VARCHAR(255) NOT NULL, - ip_address VARCHAR(45), - user_agent TEXT, - details TEXT, - timestamp TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP -); - --- ================================================================================= --- CLINICAL PROFILES --- ================================================================================= - -CREATE TABLE patient_profiles ( - profile_id BIGSERIAL PRIMARY KEY, - user_id BIGINT UNIQUE NOT NULL REFERENCES login(user_id) ON DELETE CASCADE, - assigned_doctor_id BIGINT REFERENCES login(user_id), - assigned_nurse_id BIGINT REFERENCES login(user_id), - first_name VARCHAR(100) NOT NULL, - last_name VARCHAR(100) NOT NULL, - date_of_birth DATE NOT NULL, - gender VARCHAR(20), - contact_number VARCHAR(20), - address TEXT, - medical_history TEXT, - created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP -); - -CREATE TABLE doctor_profiles ( - profile_id BIGSERIAL PRIMARY KEY, - user_id BIGINT UNIQUE NOT NULL REFERENCES login(user_id) ON DELETE CASCADE, - first_name VARCHAR(100) NOT NULL, - last_name VARCHAR(100) NOT NULL, - specialty VARCHAR(100) NOT NULL, - contact_number VARCHAR(20), - department VARCHAR(100), - shift_start_time TIME NOT NULL DEFAULT '09:00:00', - shift_end_time TIME NOT NULL DEFAULT '17:00:00', - slot_duration_minutes INT NOT NULL DEFAULT 30 -); - -CREATE TABLE doctor_working_days ( - doctor_profile_id BIGINT NOT NULL REFERENCES doctor_profiles(profile_id) ON DELETE CASCADE, - working_days VARCHAR(20) NOT NULL -); - --- ================================================================================= --- CLINICAL WORKFLOW --- ================================================================================= - -CREATE TABLE appointments ( - appointment_id BIGSERIAL PRIMARY KEY, - patient_profile_id BIGINT NOT NULL REFERENCES patient_profiles(profile_id) ON DELETE CASCADE, - doctor_id BIGINT NOT NULL REFERENCES login(user_id) ON DELETE CASCADE, - appointment_date TIMESTAMP NOT NULL, - status VARCHAR(50) NOT NULL DEFAULT 'PENDING_APPROVAL', - reason_for_visit TEXT, - doctor_notes TEXT, - created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP -); - -CREATE TABLE medical_records ( - record_id BIGSERIAL PRIMARY KEY, - patient_profile_id BIGINT NOT NULL REFERENCES patient_profiles(profile_id) ON DELETE CASCADE, - doctor_id BIGINT NOT NULL REFERENCES login(user_id) ON DELETE CASCADE, - diagnosis VARCHAR(255) NOT NULL, - symptoms TEXT, - treatment_provided TEXT, - attachment_url VARCHAR(255), - created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, - updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP -); - -CREATE TABLE prescriptions ( - prescription_id BIGSERIAL PRIMARY KEY, - patient_profile_id BIGINT NOT NULL REFERENCES patient_profiles(profile_id) ON DELETE CASCADE, - doctor_id BIGINT NOT NULL REFERENCES login(user_id) ON DELETE CASCADE, - medication_name VARCHAR(255) NOT NULL, - dosage VARCHAR(100) NOT NULL, - frequency VARCHAR(100) NOT NULL, - duration VARCHAR(100) NOT NULL, - special_instructions TEXT, - issued_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - start_date TIMESTAMP, - end_date TIMESTAMP, - refills_remaining INT DEFAULT 0, - status VARCHAR(50) DEFAULT 'ACTIVE' -); - -CREATE TABLE vital_signs ( - vital_id BIGSERIAL PRIMARY KEY, - patient_profile_id BIGINT NOT NULL REFERENCES patient_profiles(profile_id) ON DELETE CASCADE, - nurse_id BIGINT NOT NULL REFERENCES login(user_id) ON DELETE CASCADE, - blood_pressure VARCHAR(20), - heart_rate INT, - temperature DOUBLE PRECISION, - respiratory_rate INT, - oxygen_saturation INT, - weight DOUBLE PRECISION, - height DOUBLE PRECISION, - recorded_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP -); - -CREATE TABLE lab_tests ( - test_id BIGSERIAL PRIMARY KEY, - patient_profile_id BIGINT NOT NULL REFERENCES patient_profiles(profile_id) ON DELETE CASCADE, - ordered_by_id BIGINT NOT NULL REFERENCES login(user_id) ON DELETE CASCADE, - test_name VARCHAR(255), - test_category VARCHAR(100), - result_value VARCHAR(255), - unit VARCHAR(50), - reference_range VARCHAR(100), - remarks TEXT, - status VARCHAR(50), - file_url VARCHAR(255), - ordered_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP -); - -CREATE TABLE patient_consents ( - id BIGSERIAL PRIMARY KEY, - patient_id BIGINT NOT NULL REFERENCES patient_profiles(profile_id) ON DELETE CASCADE, - granted_to_id BIGINT NOT NULL REFERENCES login(user_id) ON DELETE CASCADE, - consent_type VARCHAR(100) NOT NULL, - status VARCHAR(20) NOT NULL DEFAULT 'ACTIVE', - granted_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, - expires_at TIMESTAMP, - revoked_at TIMESTAMP, - reason TEXT -); - -CREATE TABLE handover_notes ( - id BIGSERIAL PRIMARY KEY, - author_id BIGINT NOT NULL REFERENCES login(user_id) ON DELETE CASCADE, - patient_id BIGINT REFERENCES patient_profiles(profile_id) ON DELETE SET NULL, - type VARCHAR(50) NOT NULL DEFAULT 'general', - priority VARCHAR(20) NOT NULL DEFAULT 'normal', - content TEXT NOT NULL, - is_read BOOLEAN DEFAULT FALSE, - timestamp TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, - shift_direction VARCHAR(50) -); - -CREATE TABLE nurse_tasks ( - id BIGSERIAL PRIMARY KEY, - assigned_nurse_id BIGINT NOT NULL REFERENCES login(user_id) ON DELETE CASCADE, - patient_id BIGINT REFERENCES patient_profiles(profile_id) ON DELETE SET NULL, - title VARCHAR(255) NOT NULL, - description TEXT, - category VARCHAR(100) NOT NULL, - priority VARCHAR(20) NOT NULL, - due_time TIMESTAMP NOT NULL, - completed BOOLEAN DEFAULT FALSE, - status VARCHAR(50) DEFAULT 'upcoming', - previous_status VARCHAR(50) -); - --- Legacy compatibility table still used by older code paths/scripts. -CREATE TABLE consent_log ( - log_id BIGSERIAL PRIMARY KEY, - user_id BIGINT REFERENCES login(user_id), - consent_type VARCHAR(50) NOT NULL, - is_granted BOOLEAN NOT NULL, - ip_address VARCHAR(45), - changed_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP -); - --- ================================================================================= --- PART 3: SEED FRESH TEST DATA --- ================================================================================= --- Admin User (password: SecurePassword2024 - 19 chars) -INSERT INTO login (email, password_hash, role, is_active, is_verified, two_factor_enabled) -VALUES ('admin@securehealth.com', '$argon2id$v=19$m=4096,t=3,p=1$Vhabqz80TH4fFH9ehhbWKw$wBgy4sxJmmj3WLPlzGQLbqK9dEJbnslWc/J7xbwVmQ0', 'ADMIN', TRUE, TRUE, TRUE); - --- Doctor Users (password: SecurePassword2024 - 19 chars) -INSERT INTO login (email, password_hash, role, is_active, is_verified, two_factor_enabled) -VALUES -('doctor1@securehealth.com', '$argon2id$v=19$m=4096,t=3,p=1$Vhabqz80TH4fFH9ehhbWKw$wBgy4sxJmmj3WLPlzGQLbqK9dEJbnslWc/J7xbwVmQ0', 'DOCTOR', TRUE, TRUE, TRUE), -('doctor2@securehealth.com', '$argon2id$v=19$m=4096,t=3,p=1$Vhabqz80TH4fFH9ehhbWKw$wBgy4sxJmmj3WLPlzGQLbqK9dEJbnslWc/J7xbwVmQ0', 'DOCTOR', TRUE, TRUE, TRUE); - --- Doctor Profiles (updated to match new schema) -INSERT INTO doctor_profiles (user_id, first_name, last_name, specialty, department, contact_number) -SELECT user_id, 'John', 'Smith', 'General Practice', 'Internal Medicine', '555-0201' -FROM login WHERE email = 'doctor1@securehealth.com'; - -INSERT INTO doctor_profiles (user_id, first_name, last_name, specialty, department, contact_number) -SELECT user_id, 'Sarah', 'Johnson', 'Cardiology', 'Cardiology', '555-0202' -FROM login WHERE email = 'doctor2@securehealth.com'; - --- Working days for doctors -INSERT INTO doctor_working_days (doctor_profile_id, working_days) -SELECT dp.profile_id, 'MONDAY' -FROM doctor_profiles dp -JOIN login l ON dp.user_id = l.user_id -WHERE l.email = 'doctor1@securehealth.com'; - -INSERT INTO doctor_working_days (doctor_profile_id, working_days) -SELECT dp.profile_id, 'TUESDAY' -FROM doctor_profiles dp -JOIN login l ON dp.user_id = l.user_id -WHERE l.email = 'doctor1@securehealth.com'; - -INSERT INTO doctor_working_days (doctor_profile_id, working_days) -SELECT dp.profile_id, 'WEDNESDAY' -FROM doctor_profiles dp -JOIN login l ON dp.user_id = l.user_id -WHERE l.email = 'doctor1@securehealth.com'; - -INSERT INTO doctor_working_days (doctor_profile_id, working_days) -SELECT dp.profile_id, 'THURSDAY' -FROM doctor_profiles dp -JOIN login l ON dp.user_id = l.user_id -WHERE l.email = 'doctor1@securehealth.com'; - -INSERT INTO doctor_working_days (doctor_profile_id, working_days) -SELECT dp.profile_id, 'FRIDAY' -FROM doctor_profiles dp -JOIN login l ON dp.user_id = l.user_id -WHERE l.email = 'doctor1@securehealth.com'; - --- Nurse Users (password: SecurePassword2024 - 19 chars) -INSERT INTO login (email, password_hash, role, is_active, is_verified, two_factor_enabled) -VALUES -('nurse1@securehealth.com', '$argon2id$v=19$m=4096,t=3,p=1$Vhabqz80TH4fFH9ehhbWKw$wBgy4sxJmmj3WLPlzGQLbqK9dEJbnslWc/J7xbwVmQ0', 'NURSE', TRUE, TRUE, FALSE), -('nurse2@securehealth.com', '$argon2id$v=19$m=4096,t=3,p=1$Vhabqz80TH4fFH9ehhbWKw$wBgy4sxJmmj3WLPlzGQLbqK9dEJbnslWc/J7xbwVmQ0', 'NURSE', TRUE, TRUE, FALSE); - --- Lab Technician Users (password: SecurePassword2024 - 19 chars) -INSERT INTO login (email, password_hash, role, is_active, is_verified) -VALUES -('lab1@securehealth.com', '$argon2id$v=19$m=4096,t=3,p=1$Vhabqz80TH4fFH9ehhbWKw$wBgy4sxJmmj3WLPlzGQLbqK9dEJbnslWc/J7xbwVmQ0', 'LAB_TECHNICIAN', TRUE, TRUE), -('lab2@securehealth.com', '$argon2id$v=19$m=4096,t=3,p=1$Vhabqz80TH4fFH9ehhbWKw$wBgy4sxJmmj3WLPlzGQLbqK9dEJbnslWc/J7xbwVmQ0', 'LAB_TECHNICIAN', TRUE, TRUE); - --- Patient Users (password: SecurePassword2024 - 19 chars) -INSERT INTO login (email, password_hash, role, is_active, is_verified) -VALUES -('patient1@securehealth.com', '$argon2id$v=19$m=4096,t=3,p=1$Vhabqz80TH4fFH9ehhbWKw$wBgy4sxJmmj3WLPlzGQLbqK9dEJbnslWc/J7xbwVmQ0', 'PATIENT', TRUE, TRUE), -('patient2@securehealth.com', '$argon2id$v=19$m=4096,t=3,p=1$Vhabqz80TH4fFH9ehhbWKw$wBgy4sxJmmj3WLPlzGQLbqK9dEJbnslWc/J7xbwVmQ0', 'PATIENT', TRUE, TRUE), -('patient3@securehealth.com', '$argon2id$v=19$m=4096,t=3,p=1$Vhabqz80TH4fFH9ehhbWKw$wBgy4sxJmmj3WLPlzGQLbqK9dEJbnslWc/J7xbwVmQ0', 'PATIENT', TRUE, TRUE), -('patient4@securehealth.com', '$argon2id$v=19$m=4096,t=3,p=1$Vhabqz80TH4fFH9ehhbWKw$wBgy4sxJmmj3WLPlzGQLbqK9dEJbnslWc/J7xbwVmQ0', 'PATIENT', TRUE, TRUE), -('patient5@securehealth.com', '$argon2id$v=19$m=4096,t=3,p=1$Vhabqz80TH4fFH9ehhbWKw$wBgy4sxJmmj3WLPlzGQLbqK9dEJbnslWc/J7xbwVmQ0', 'PATIENT', TRUE, TRUE); - --- Patient Profiles (updated to match new schema) -INSERT INTO patient_profiles (user_id, first_name, last_name, date_of_birth, gender, contact_number, address) -SELECT user_id, 'Alice', 'Williams', '1985-03-15', 'Female', '555-0101', '123 Main St' -FROM login WHERE email = 'patient1@securehealth.com'; - -INSERT INTO patient_profiles (user_id, first_name, last_name, date_of_birth, gender, contact_number, address) -SELECT user_id, 'Bob', 'Brown', '1990-07-22', 'Male', '555-0102', '456 Oak Ave' -FROM login WHERE email = 'patient2@securehealth.com'; - -INSERT INTO patient_profiles (user_id, first_name, last_name, date_of_birth, gender, contact_number, address) -SELECT user_id, 'Carol', 'Davis', '1988-11-10', 'Female', '555-0103', '789 Pine Rd' -FROM login WHERE email = 'patient3@securehealth.com'; - -INSERT INTO patient_profiles (user_id, first_name, last_name, date_of_birth, gender, contact_number, address) -SELECT user_id, 'David', 'Miller', '1992-05-30', 'Male', '555-0104', '321 Elm St' -FROM login WHERE email = 'patient4@securehealth.com'; - -INSERT INTO patient_profiles (user_id, first_name, last_name, date_of_birth, gender, contact_number, address) -SELECT user_id, 'Emma', 'Wilson', '1987-09-18', 'Female', '555-0105', '654 Maple Dr' -FROM login WHERE email = 'patient5@securehealth.com'; - --- Sample Appointments (3 per patient) -INSERT INTO appointments (patient_profile_id, doctor_id, appointment_date, status, reason_for_visit) -SELECT pp.profile_id, l.user_id, NOW() + INTERVAL '7 days', 'SCHEDULED', 'Regular Checkup' -FROM patient_profiles pp, login l -WHERE l.email = 'doctor1@securehealth.com' -LIMIT 5; - -INSERT INTO appointments (patient_profile_id, doctor_id, appointment_date, status, reason_for_visit) -SELECT pp.profile_id, l.user_id, NOW() + INTERVAL '14 days', 'PENDING_APPROVAL', 'Follow-up Visit' -FROM patient_profiles pp, login l -WHERE l.email = 'doctor2@securehealth.com' -LIMIT 5; - -INSERT INTO appointments (patient_profile_id, doctor_id, appointment_date, status, reason_for_visit) -SELECT pp.profile_id, l.user_id, NOW() + INTERVAL '21 days', 'COMPLETED', 'Consultation' -FROM patient_profiles pp, login l -WHERE l.email = 'doctor1@securehealth.com' -LIMIT 5; - --- Sample Prescriptions -INSERT INTO prescriptions (patient_profile_id, doctor_id, medication_name, dosage, frequency, duration, status) -SELECT pp.profile_id, l.user_id, 'Lisinopril', '10mg', 'Once daily', '30 days', 'ACTIVE' -FROM patient_profiles pp, login l -WHERE l.email = 'doctor1@securehealth.com' -LIMIT 5; - -INSERT INTO prescriptions (patient_profile_id, doctor_id, medication_name, dosage, frequency, duration, status) -SELECT pp.profile_id, l.user_id, 'Metformin', '500mg', 'Twice daily', '90 days', 'ACTIVE' -FROM patient_profiles pp, login l -WHERE l.email = 'doctor2@securehealth.com' -LIMIT 5; - -INSERT INTO prescriptions (patient_profile_id, doctor_id, medication_name, dosage, frequency, duration, status) -SELECT pp.profile_id, l.user_id, 'Aspirin', '100mg', 'Once daily', '60 days', 'ACTIVE' -FROM patient_profiles pp, login l -WHERE l.email = 'doctor1@securehealth.com' -LIMIT 5; - --- Sample Vital Signs -INSERT INTO vital_signs (patient_profile_id, nurse_id, blood_pressure, heart_rate, temperature, respiratory_rate, oxygen_saturation, weight, height, recorded_at) -SELECT pp.profile_id, l.user_id, '120/80', 72, 98.6, 16, 98, 70.5, 175, NOW() -FROM patient_profiles pp, login l -WHERE l.email = 'nurse1@securehealth.com' -LIMIT 5; - -INSERT INTO vital_signs (patient_profile_id, nurse_id, blood_pressure, heart_rate, temperature, respiratory_rate, oxygen_saturation, weight, height, recorded_at) -SELECT pp.profile_id, l.user_id, '118/78', 70, 98.4, 16, 99, 68.0, 172, NOW() - INTERVAL '1 day' -FROM patient_profiles pp, login l -WHERE l.email = 'nurse2@securehealth.com' -LIMIT 5; - -INSERT INTO vital_signs (patient_profile_id, nurse_id, blood_pressure, heart_rate, temperature, respiratory_rate, oxygen_saturation, weight, height, recorded_at) -SELECT pp.profile_id, l.user_id, '122/82', 74, 98.7, 17, 98, 72.0, 178, NOW() - INTERVAL '2 days' -FROM patient_profiles pp, login l -WHERE l.email = 'nurse1@securehealth.com' -LIMIT 5; - --- Sample Lab Tests --- Completed tests (with results) -INSERT INTO lab_tests (patient_profile_id, ordered_by_id, test_name, test_category, result_value, unit, status, ordered_at) -SELECT pp.profile_id, l.user_id, 'Blood Glucose', 'Chemistry', '95', 'mg/dL', 'Completed', NOW() - INTERVAL '7 days' -FROM patient_profiles pp, login l -WHERE l.email = 'doctor1@securehealth.com' -LIMIT 5; - -INSERT INTO lab_tests (patient_profile_id, ordered_by_id, test_name, test_category, result_value, unit, status, ordered_at) -SELECT pp.profile_id, l.user_id, 'Hemoglobin A1C', 'Chemistry', '5.8', '%', 'Completed', NOW() - INTERVAL '5 days' -FROM patient_profiles pp, login l -WHERE l.email = 'doctor2@securehealth.com' -LIMIT 5; - -INSERT INTO lab_tests (patient_profile_id, ordered_by_id, test_name, test_category, result_value, unit, status, ordered_at) -SELECT pp.profile_id, l.user_id, 'Complete Blood Count', 'Hematology', 'Normal', 'cells/uL', 'Completed', NOW() - INTERVAL '3 days' -FROM patient_profiles pp, login l -WHERE l.email = 'doctor1@securehealth.com' -LIMIT 5; - --- Pending tests (awaiting sample collection) -INSERT INTO lab_tests (patient_profile_id, ordered_by_id, test_name, test_category, status, ordered_at) -SELECT pp.profile_id, l.user_id, 'Lipid Panel', 'Chemistry', 'Pending', NOW() - INTERVAL '1 day' -FROM patient_profiles pp, login l -WHERE l.email = 'doctor1@securehealth.com' -LIMIT 3; - -INSERT INTO lab_tests (patient_profile_id, ordered_by_id, test_name, test_category, status, ordered_at) -SELECT pp.profile_id, l.user_id, 'Thyroid Function Test', 'Endocrinology', 'Pending', NOW() - INTERVAL '2 hours' -FROM patient_profiles pp, login l -WHERE l.email = 'doctor2@securehealth.com' -LIMIT 2; - --- Collected tests (sample received, awaiting analysis) -INSERT INTO lab_tests (patient_profile_id, ordered_by_id, test_name, test_category, status, ordered_at) -SELECT pp.profile_id, l.user_id, 'Urinalysis', 'Microbiology', 'Collected', NOW() - INTERVAL '4 hours' -FROM patient_profiles pp, login l -WHERE l.email = 'doctor1@securehealth.com' -LIMIT 2; - --- Results Pending tests (analysis done, awaiting upload) -INSERT INTO lab_tests (patient_profile_id, ordered_by_id, test_name, test_category, status, ordered_at) -SELECT pp.profile_id, l.user_id, 'Liver Function Test', 'Chemistry', 'Results Pending', NOW() - INTERVAL '6 hours' -FROM patient_profiles pp, login l -WHERE l.email = 'doctor2@securehealth.com' -LIMIT 2; - --- Sample Medical Records (updated to use created_at instead of recorded_at) -INSERT INTO medical_records (patient_profile_id, doctor_id, diagnosis, symptoms, treatment_provided) -SELECT pp.profile_id, l.user_id, 'Hypertension', 'Elevated blood pressure', 'Prescribed Lisinopril' -FROM patient_profiles pp, login l -WHERE l.email = 'doctor1@securehealth.com' -LIMIT 5; - -INSERT INTO medical_records (patient_profile_id, doctor_id, diagnosis, symptoms, treatment_provided) -SELECT pp.profile_id, l.user_id, 'Type 2 Diabetes', 'High glucose levels', 'Prescribed Metformin' -FROM patient_profiles pp, login l -WHERE l.email = 'doctor2@securehealth.com' -LIMIT 5; - --- ================================================================================= --- PATIENT ASSIGNMENTS --- ================================================================================= --- Assign doctor1 and nurse1 to patients 1-3 -UPDATE patient_profiles -SET - assigned_doctor_id = (SELECT user_id FROM login WHERE email = 'doctor1@securehealth.com'), - assigned_nurse_id = (SELECT user_id FROM login WHERE email = 'nurse1@securehealth.com') -WHERE user_id IN ( - SELECT user_id FROM login WHERE email IN ( - 'patient1@securehealth.com', - 'patient2@securehealth.com', - 'patient3@securehealth.com' - ) -); - --- Assign doctor2 and nurse2 to patients 4-5 -UPDATE patient_profiles -SET - assigned_doctor_id = (SELECT user_id FROM login WHERE email = 'doctor2@securehealth.com'), - assigned_nurse_id = (SELECT user_id FROM login WHERE email = 'nurse2@securehealth.com') -WHERE user_id IN ( - SELECT user_id FROM login WHERE email IN ( - 'patient4@securehealth.com', - 'patient5@securehealth.com' - ) -); - --- ================================================================================= --- DOCTOR 2 WORKING DAYS --- ================================================================================= -INSERT INTO doctor_working_days (doctor_profile_id, working_days) -SELECT dp.profile_id, day -FROM doctor_profiles dp -JOIN login l ON dp.user_id = l.user_id, -LATERAL (VALUES ('MONDAY'), ('TUESDAY'), ('WEDNESDAY'), ('THURSDAY'), ('FRIDAY')) AS days(day) -WHERE l.email = 'doctor2@securehealth.com'; - --- ================================================================================= --- CONSENT MANAGEMENT --- ================================================================================= --- Patient 1 (Alice): active consent for VIEW_RECORDS granted to doctor1 -INSERT INTO patient_consents (patient_id, granted_to_id, consent_type, status, granted_at, expires_at, reason) -SELECT pp.profile_id, l.user_id, 'VIEW_RECORDS', 'ACTIVE', NOW() - INTERVAL '30 days', NOW() + INTERVAL '335 days', 'Routine care access' -FROM patient_profiles pp -JOIN login pl ON pp.user_id = pl.user_id AND pl.email = 'patient1@securehealth.com', -login l WHERE l.email = 'doctor1@securehealth.com'; - --- Patient 2 (Bob): active consent for PRESCRIPTIONS granted to doctor1 -INSERT INTO patient_consents (patient_id, granted_to_id, consent_type, status, granted_at, expires_at, reason) -SELECT pp.profile_id, l.user_id, 'PRESCRIPTIONS', 'ACTIVE', NOW() - INTERVAL '20 days', NOW() + INTERVAL '345 days', 'Medication management' -FROM patient_profiles pp -JOIN login pl ON pp.user_id = pl.user_id AND pl.email = 'patient2@securehealth.com', -login l WHERE l.email = 'doctor1@securehealth.com'; - --- Patient 3 (Carol): active consent for VITAL_SIGNS granted to nurse1 -INSERT INTO patient_consents (patient_id, granted_to_id, consent_type, status, granted_at, expires_at, reason) -SELECT pp.profile_id, l.user_id, 'VITAL_SIGNS', 'ACTIVE', NOW() - INTERVAL '15 days', NOW() + INTERVAL '350 days', 'Nursing monitoring' -FROM patient_profiles pp -JOIN login pl ON pp.user_id = pl.user_id AND pl.email = 'patient3@securehealth.com', -login l WHERE l.email = 'nurse1@securehealth.com'; - --- Patient 4 (David): revoked consent for VIEW_RECORDS granted to doctor2 -INSERT INTO patient_consents (patient_id, granted_to_id, consent_type, status, granted_at, revoked_at, reason) -SELECT pp.profile_id, l.user_id, 'VIEW_RECORDS', 'REVOKED', NOW() - INTERVAL '60 days', NOW() - INTERVAL '10 days', 'Patient withdrew consent' -FROM patient_profiles pp -JOIN login pl ON pp.user_id = pl.user_id AND pl.email = 'patient4@securehealth.com', -login l WHERE l.email = 'doctor2@securehealth.com'; - --- Patient 5 (Emma): expiring soon consent for VIEW_RECORDS granted to doctor2 -INSERT INTO patient_consents (patient_id, granted_to_id, consent_type, status, granted_at, expires_at, reason) -SELECT pp.profile_id, l.user_id, 'VIEW_RECORDS', 'ACTIVE', NOW() - INTERVAL '355 days', NOW() + INTERVAL '10 days', 'Annual care access' -FROM patient_profiles pp -JOIN login pl ON pp.user_id = pl.user_id AND pl.email = 'patient5@securehealth.com', -login l WHERE l.email = 'doctor2@securehealth.com'; - --- Patient 1 (Alice): active consent for PRESCRIPTIONS granted to doctor2 -INSERT INTO patient_consents (patient_id, granted_to_id, consent_type, status, granted_at, expires_at, reason) -SELECT pp.profile_id, l.user_id, 'PRESCRIPTIONS', 'ACTIVE', NOW() - INTERVAL '25 days', NOW() + INTERVAL '340 days', 'Specialist prescription review' -FROM patient_profiles pp -JOIN login pl ON pp.user_id = pl.user_id AND pl.email = 'patient1@securehealth.com', -login l WHERE l.email = 'doctor2@securehealth.com'; - --- Patient 1 (Alice): active consent for VITAL_SIGNS granted to nurse1 -INSERT INTO patient_consents (patient_id, granted_to_id, consent_type, status, granted_at, expires_at, reason) -SELECT pp.profile_id, l.user_id, 'VITAL_SIGNS', 'ACTIVE', NOW() - INTERVAL '18 days', NOW() + INTERVAL '347 days', 'Nursing monitoring and follow-up' -FROM patient_profiles pp -JOIN login pl ON pp.user_id = pl.user_id AND pl.email = 'patient1@securehealth.com', -login l WHERE l.email = 'nurse1@securehealth.com'; - --- Patient 1 (Alice): active consent for LAB_RESULTS granted to lab1 -INSERT INTO patient_consents (patient_id, granted_to_id, consent_type, status, granted_at, expires_at, reason) -SELECT pp.profile_id, l.user_id, 'LAB_RESULTS', 'ACTIVE', NOW() - INTERVAL '10 days', NOW() + INTERVAL '355 days', 'Lab technician result access' -FROM patient_profiles pp -JOIN login pl ON pp.user_id = pl.user_id AND pl.email = 'patient1@securehealth.com', -login l WHERE l.email = 'lab1@securehealth.com'; - --- Patient 1 (Alice): revoked consent for VIEW_RECORDS previously granted to doctor2 -INSERT INTO patient_consents (patient_id, granted_to_id, consent_type, status, granted_at, revoked_at, reason) -SELECT pp.profile_id, l.user_id, 'VIEW_RECORDS', 'REVOKED', NOW() - INTERVAL '90 days', NOW() - INTERVAL '45 days', 'Withdrew after treatment ended' -FROM patient_profiles pp -JOIN login pl ON pp.user_id = pl.user_id AND pl.email = 'patient1@securehealth.com', -login l WHERE l.email = 'doctor2@securehealth.com'; - --- Patient 1 (Alice): active consent for ALL granted to doctor1 -INSERT INTO patient_consents (patient_id, granted_to_id, consent_type, status, granted_at, expires_at, reason) -SELECT pp.profile_id, l.user_id, 'ALL', 'ACTIVE', NOW() - INTERVAL '5 days', NOW() + INTERVAL '360 days', 'Full access for primary care physician' -FROM patient_profiles pp -JOIN login pl ON pp.user_id = pl.user_id AND pl.email = 'patient1@securehealth.com', -login l WHERE l.email = 'doctor1@securehealth.com'; - --- Consent audit log -INSERT INTO consent_log (user_id, consent_type, is_granted, ip_address, changed_at) -SELECT user_id, 'VIEW_RECORDS', TRUE, '192.168.1.10', NOW() - INTERVAL '30 days' -FROM login WHERE email = 'patient1@securehealth.com'; - -INSERT INTO consent_log (user_id, consent_type, is_granted, ip_address, changed_at) -SELECT user_id, 'PRESCRIPTIONS', TRUE, '192.168.1.12', NOW() - INTERVAL '20 days' -FROM login WHERE email = 'patient2@securehealth.com'; - -INSERT INTO consent_log (user_id, consent_type, is_granted, ip_address, changed_at) -SELECT user_id, 'VIEW_RECORDS', FALSE, '192.168.1.14', NOW() - INTERVAL '10 days' -FROM login WHERE email = 'patient4@securehealth.com'; - --- ================================================================================= --- ADMIN DASHBOARD DATA --- ================================================================================= - --- Audit Logs (25 rows covering login events, clinical actions, admin actions) -INSERT INTO audit_logs (email, action, ip_address, user_agent, details, timestamp) -VALUES ('admin@securehealth.com', 'LOGIN_SUCCESS', '192.168.1.10', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)', 'method=password', NOW() - INTERVAL '1 hour'); - -INSERT INTO audit_logs (email, action, ip_address, user_agent, details, timestamp) -VALUES ('doctor1@securehealth.com', 'LOGIN_SUCCESS', '192.168.1.11', 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7)', 'method=password', NOW() - INTERVAL '2 hours'); - -INSERT INTO audit_logs (email, action, ip_address, user_agent, details, timestamp) -VALUES ('doctor2@securehealth.com', 'LOGIN_SUCCESS', '192.168.1.12', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)', 'method=password', NOW() - INTERVAL '3 hours'); - -INSERT INTO audit_logs (email, action, ip_address, user_agent, details, timestamp) -VALUES ('patient1@securehealth.com', 'LOGIN_FAILED', '10.0.0.5', 'Mozilla/5.0', 'reason=wrong_password attempt=2', NOW() - INTERVAL '4 hours'); - -INSERT INTO audit_logs (email, action, ip_address, user_agent, details, timestamp) -VALUES ('patient1@securehealth.com', 'LOGIN_FAILED', '10.0.0.5', 'Mozilla/5.0', 'reason=wrong_password attempt=3', NOW() - INTERVAL '4 hours'); - -INSERT INTO audit_logs (email, action, ip_address, user_agent, details, timestamp) -VALUES ('patient1@securehealth.com', 'ACCOUNT_LOCKED', '10.0.0.5', 'Mozilla/5.0', 'reason=max_attempts_exceeded lockout_minutes=30', NOW() - INTERVAL '4 hours'); - -INSERT INTO audit_logs (email, action, ip_address, user_agent, details, timestamp) -VALUES ('nurse1@securehealth.com', 'LOGIN_SUCCESS', '192.168.1.13', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) Chrome/120', 'method=password', NOW() - INTERVAL '5 hours'); - -INSERT INTO audit_logs (email, action, ip_address, user_agent, details, timestamp) -VALUES ('nurse2@securehealth.com', 'LOGIN_SUCCESS', '192.168.1.14', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) Chrome/120', 'method=password', NOW() - INTERVAL '6 hours'); - -INSERT INTO audit_logs (email, action, ip_address, user_agent, details, timestamp) -VALUES ('lab1@securehealth.com', 'LOGIN_SUCCESS', '192.168.1.15', 'Mozilla/5.0 (X11; Linux x86_64) Firefox/121', 'method=password', NOW() - INTERVAL '7 hours'); - -INSERT INTO audit_logs (email, action, ip_address, user_agent, details, timestamp) -VALUES ('lab1@securehealth.com', 'LOGOUT', '192.168.1.15', 'Mozilla/5.0 (X11; Linux x86_64) Firefox/121', 'session_duration_minutes=45', NOW() - INTERVAL '6 hours'); - -INSERT INTO audit_logs (email, action, ip_address, user_agent, details, timestamp) -VALUES ('admin@securehealth.com', 'USER_CREATED', '192.168.1.10', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)', 'created_email=patient5@securehealth.com role=PATIENT', NOW() - INTERVAL '10 days'); - -INSERT INTO audit_logs (email, action, ip_address, user_agent, details, timestamp) -VALUES ('admin@securehealth.com', 'USER_DEACTIVATED', '192.168.1.10', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)', 'target=oldpatient@securehealth.com reason=policy_violation', NOW() - INTERVAL '5 days'); - -INSERT INTO audit_logs (email, action, ip_address, user_agent, details, timestamp) -VALUES ('admin@securehealth.com', 'ROLE_CHANGED', '192.168.1.10', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)', 'target=lab2@securehealth.com old_role=LAB_TECHNICIAN new_role=DOCTOR', NOW() - INTERVAL '8 days'); - -INSERT INTO audit_logs (email, action, ip_address, user_agent, details, timestamp) -VALUES ('doctor1@securehealth.com', 'PRESCRIPTION_CREATED', '192.168.1.11', 'Mozilla/5.0', 'medication=Lisinopril patient_id=1', NOW() - INTERVAL '2 days'); - -INSERT INTO audit_logs (email, action, ip_address, user_agent, details, timestamp) -VALUES ('doctor1@securehealth.com', 'APPOINTMENT_SCHEDULED', '192.168.1.11', 'Mozilla/5.0', 'patient_id=1 date=next_week', NOW() - INTERVAL '1 day'); - -INSERT INTO audit_logs (email, action, ip_address, user_agent, details, timestamp) -VALUES ('nurse1@securehealth.com', 'VITAL_SIGNS_RECORDED', '192.168.1.13', 'Mozilla/5.0', 'bp=120/80 hr=72 patient_id=1', NOW() - INTERVAL '3 hours'); - -INSERT INTO audit_logs (email, action, ip_address, user_agent, details, timestamp) -VALUES ('doctor1@securehealth.com', 'LAB_TEST_ORDERED', '192.168.1.11', 'Mozilla/5.0', 'test=Blood Glucose patient_id=1', NOW() - INTERVAL '7 days'); - -INSERT INTO audit_logs (email, action, ip_address, user_agent, details, timestamp) -VALUES ('lab1@securehealth.com', 'LAB_TEST_RESULT_UPLOADED', '192.168.1.15', 'Mozilla/5.0', 'test=Blood Glucose result=95mg/dL', NOW() - INTERVAL '6 days'); - -INSERT INTO audit_logs (email, action, ip_address, user_agent, details, timestamp) -VALUES ('patient1@securehealth.com', 'CONSENT_GRANTED', '192.168.1.20', 'Mozilla/5.0 (iPhone; CPU iPhone OS 17)', 'consent_type=VIEW_RECORDS granted_to=doctor1@securehealth.com', NOW() - INTERVAL '30 days'); - -INSERT INTO audit_logs (email, action, ip_address, user_agent, details, timestamp) -VALUES ('patient4@securehealth.com', 'CONSENT_REVOKED', '192.168.1.24', 'Mozilla/5.0', 'consent_type=VIEW_RECORDS revoked_from=doctor2@securehealth.com', NOW() - INTERVAL '10 days'); - -INSERT INTO audit_logs (email, action, ip_address, user_agent, details, timestamp) -VALUES ('doctor2@securehealth.com', 'PASSWORD_CHANGED', '192.168.1.12', 'Mozilla/5.0', 'method=user_initiated', NOW() - INTERVAL '15 days'); - -INSERT INTO audit_logs (email, action, ip_address, user_agent, details, timestamp) -VALUES ('doctor1@securehealth.com', 'TWO_FACTOR_ENABLED', '192.168.1.11', 'Mozilla/5.0', 'method=totp', NOW() - INTERVAL '20 days'); - -INSERT INTO audit_logs (email, action, ip_address, user_agent, details, timestamp) -VALUES ('admin@securehealth.com', 'SUSPICIOUS_LOGIN_ATTEMPT', '185.220.101.5', 'curl/7.82.0', 'country=Unknown blocked=true', NOW() - INTERVAL '2 days'); - -INSERT INTO audit_logs (email, action, ip_address, user_agent, details, timestamp) -VALUES ('admin@securehealth.com', 'DATA_EXPORT', '192.168.1.10', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)', 'report_type=patient_summary records=150', NOW() - INTERVAL '3 days'); - -INSERT INTO audit_logs (email, action, ip_address, user_agent, details, timestamp) -VALUES ('admin@securehealth.com', 'SESSION_REVOKED', '192.168.1.10', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)', 'reason=suspicious_activity source_ip=185.220.101.5', NOW() - INTERVAL '2 days'); - --- Archived Users (4 rows — original_user_id uses placeholder IDs for non-existent archived accounts) -INSERT INTO archived_users (original_user_id, email, role, last_active_at, archived_at, reason) -VALUES (999901, 'former.patient@securehealth.com', 'PATIENT', NOW() - INTERVAL '200 days', NOW() - INTERVAL '30 days', 'Account inactive >180 days'); - -INSERT INTO archived_users (original_user_id, email, role, last_active_at, archived_at, reason) -VALUES (999902, 'dr.retired@securehealth.com', 'DOCTOR', NOW() - INTERVAL '90 days', NOW() - INTERVAL '60 days', 'Retired — left institution'); - -INSERT INTO archived_users (original_user_id, email, role, last_active_at, archived_at, reason) -VALUES (999903, 'nurse.resigned@securehealth.com', 'NURSE', NOW() - INTERVAL '60 days', NOW() - INTERVAL '45 days', 'Voluntary resignation'); - -INSERT INTO archived_users (original_user_id, email, role, last_active_at, archived_at, reason) -VALUES (999904, 'lab.terminated@securehealth.com', 'LAB_TECHNICIAN', NOW() - INTERVAL '30 days', NOW() - INTERVAL '20 days', 'Policy violation — access revoked'); - --- Active Sessions (5 active + 1 suspicious/revoked) -INSERT INTO sessions (user_id, refresh_token_hash, ip_address, user_agent, expires_at, revoked, created_at) -SELECT user_id, - encode(sha256(('admin-tok-1')::bytea), 'hex'), - '192.168.1.10', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36', - NOW() + INTERVAL '1 hour', FALSE, NOW() - INTERVAL '30 minutes' -FROM login WHERE email = 'admin@securehealth.com'; - -INSERT INTO sessions (user_id, refresh_token_hash, ip_address, user_agent, expires_at, revoked, created_at) -SELECT user_id, - encode(sha256(('doctor1-tok-1')::bytea), 'hex'), - '192.168.1.11', 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36', - NOW() + INTERVAL '2 hours', FALSE, NOW() - INTERVAL '1 hour' -FROM login WHERE email = 'doctor1@securehealth.com'; - -INSERT INTO sessions (user_id, refresh_token_hash, ip_address, user_agent, expires_at, revoked, created_at) -SELECT user_id, - encode(sha256(('nurse1-tok-1')::bytea), 'hex'), - '192.168.1.13', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) Chrome/120.0.0.0', - NOW() + INTERVAL '90 minutes', FALSE, NOW() - INTERVAL '45 minutes' -FROM login WHERE email = 'nurse1@securehealth.com'; - -INSERT INTO sessions (user_id, refresh_token_hash, ip_address, user_agent, expires_at, revoked, created_at) -SELECT user_id, - encode(sha256(('lab1-tok-1')::bytea), 'hex'), - '192.168.1.15', 'Mozilla/5.0 (X11; Linux x86_64) Firefox/121.0', - NOW() + INTERVAL '3 hours', FALSE, NOW() - INTERVAL '20 minutes' -FROM login WHERE email = 'lab1@securehealth.com'; - -INSERT INTO sessions (user_id, refresh_token_hash, ip_address, user_agent, expires_at, revoked, created_at) -SELECT user_id, - encode(sha256(('patient1-tok-1')::bytea), 'hex'), - '192.168.1.20', 'Mozilla/5.0 (iPhone; CPU iPhone OS 17_0 like Mac OS X) Safari/604.1', - NOW() + INTERVAL '1 hour', FALSE, NOW() - INTERVAL '10 minutes' -FROM login WHERE email = 'patient1@securehealth.com'; - --- Suspicious / revoked session -INSERT INTO sessions (user_id, refresh_token_hash, ip_address, user_agent, expires_at, revoked, created_at) -SELECT user_id, - encode(sha256(('suspicious-tok-1')::bytea), 'hex'), - '185.220.101.5', 'curl/7.82.0', - NOW() - INTERVAL '1 hour', TRUE, NOW() - INTERVAL '2 days' -FROM login WHERE email = 'admin@securehealth.com'; - --- Password Reset Tokens (1 pending + 1 used) -INSERT INTO password_reset_tokens (user_id, token_hash, expires_at, used, created_at) -SELECT user_id, - encode(sha256(('reset-pending-patient2-v1')::bytea), 'hex'), - NOW() + INTERVAL '30 minutes', FALSE, NOW() - INTERVAL '5 minutes' -FROM login WHERE email = 'patient2@securehealth.com'; - -INSERT INTO password_reset_tokens (user_id, token_hash, expires_at, used, created_at) -SELECT user_id, - encode(sha256(('reset-used-patient3-v1')::bytea), 'hex'), - NOW() - INTERVAL '1 day', TRUE, NOW() - INTERVAL '2 days' -FROM login WHERE email = 'patient3@securehealth.com'; - --- ================================================================================= --- NURSE DASHBOARD DATA --- ================================================================================= - --- Handover Notes (6 rows) -INSERT INTO handover_notes (author_id, patient_id, type, priority, content, is_read, timestamp, shift_direction) -SELECT l.user_id, pp.profile_id, 'patient', 'urgent', - 'Patient Alice Williams – BP spiked to 160/100 at 14:30. Administered Lisinopril 10mg. Needs BP check every 30 min. Doctor Smith notified.', - FALSE, NOW() - INTERVAL '2 hours', 'outgoing' -FROM login l, - patient_profiles pp JOIN login pl ON pp.user_id = pl.user_id AND pl.email = 'patient1@securehealth.com' -WHERE l.email = 'nurse1@securehealth.com'; - -INSERT INTO handover_notes (author_id, patient_id, type, priority, content, is_read, timestamp, shift_direction) -SELECT l.user_id, pp.profile_id, 'patient', 'high', - 'Bob Brown – Lab results for Lipid Panel pending. Patient fasting since midnight, do not administer morning meds until results are back.', - FALSE, NOW() - INTERVAL '3 hours', 'outgoing' -FROM login l, - patient_profiles pp JOIN login pl ON pp.user_id = pl.user_id AND pl.email = 'patient2@securehealth.com' -WHERE l.email = 'nurse1@securehealth.com'; - -INSERT INTO handover_notes (author_id, patient_id, type, priority, content, is_read, timestamp, shift_direction) -SELECT l.user_id, pp.profile_id, 'patient', 'normal', - 'Carol Davis – Routine post-op wound check completed. Dressing changed. Patient comfortable, no signs of infection. Next dressing change in 24h.', - TRUE, NOW() - INTERVAL '8 hours', 'incoming' -FROM login l, - patient_profiles pp JOIN login pl ON pp.user_id = pl.user_id AND pl.email = 'patient3@securehealth.com' -WHERE l.email = 'nurse2@securehealth.com'; - -INSERT INTO handover_notes (author_id, patient_id, type, priority, content, is_read, timestamp, shift_direction) -SELECT l.user_id, pp.profile_id, 'patient', 'high', - 'David Miller – Blood glucose monitoring required every 2 hours. Insulin sliding scale ordered by Dr. Johnson. Last reading 8.4 mmol/L at 16:00.', - FALSE, NOW() - INTERVAL '4 hours', 'outgoing' -FROM login l, - patient_profiles pp JOIN login pl ON pp.user_id = pl.user_id AND pl.email = 'patient4@securehealth.com' -WHERE l.email = 'nurse2@securehealth.com'; - -INSERT INTO handover_notes (author_id, patient_id, type, priority, content, is_read, timestamp, shift_direction) -SELECT l.user_id, pp.profile_id, 'patient', 'normal', - 'Emma Wilson – Discharged at 15:45. All medications and follow-up instructions provided. Follow-up with Dr. Johnson scheduled in 2 weeks.', - TRUE, NOW() - INTERVAL '6 hours', 'incoming' -FROM login l, - patient_profiles pp JOIN login pl ON pp.user_id = pl.user_id AND pl.email = 'patient5@securehealth.com' -WHERE l.email = 'nurse1@securehealth.com'; - -INSERT INTO handover_notes (author_id, patient_id, type, priority, content, is_read, timestamp, shift_direction) -SELECT user_id, NULL, 'general', 'normal', - 'Night shift report: All patients stable. Crash cart checked and restocked. Medication cabinet inventory completed. ICU beds 3 and 5 deep-cleaned and ready.', - TRUE, NOW() - INTERVAL '12 hours', 'incoming' -FROM login WHERE email = 'nurse2@securehealth.com'; - --- Nurse Tasks (8 rows: 4 upcoming, 2 overdue, 2 completed) -INSERT INTO nurse_tasks (assigned_nurse_id, patient_id, title, description, category, priority, due_time, completed, status) -SELECT l.user_id, pp.profile_id, - 'Administer Morning Medications', 'Give Lisinopril 10mg and Aspirin 100mg with food', - 'medication', 'high', NOW() + INTERVAL '1 hour', FALSE, 'upcoming' -FROM login l, - patient_profiles pp JOIN login pl ON pp.user_id = pl.user_id AND pl.email = 'patient1@securehealth.com' -WHERE l.email = 'nurse1@securehealth.com'; - -INSERT INTO nurse_tasks (assigned_nurse_id, patient_id, title, description, category, priority, due_time, completed, status) -SELECT l.user_id, pp.profile_id, - 'Record Vital Signs', 'BP, HR, temp, O2 sat – record in system and note any abnormalities', - 'vitals', 'high', NOW() + INTERVAL '30 minutes', FALSE, 'upcoming' -FROM login l, - patient_profiles pp JOIN login pl ON pp.user_id = pl.user_id AND pl.email = 'patient2@securehealth.com' -WHERE l.email = 'nurse1@securehealth.com'; - -INSERT INTO nurse_tasks (assigned_nurse_id, patient_id, title, description, category, priority, due_time, completed, status) -SELECT l.user_id, pp.profile_id, - 'Collect Blood Sample for Lipid Panel', 'Patient fasting. Collect venous sample and send to lab immediately.', - 'lab', 'urgent', NOW() + INTERVAL '15 minutes', FALSE, 'upcoming' -FROM login l, - patient_profiles pp JOIN login pl ON pp.user_id = pl.user_id AND pl.email = 'patient2@securehealth.com' -WHERE l.email = 'nurse1@securehealth.com'; - -INSERT INTO nurse_tasks (assigned_nurse_id, patient_id, title, description, category, priority, due_time, completed, status) -SELECT l.user_id, pp.profile_id, - 'Blood Glucose Check', 'Capillary blood glucose – apply insulin sliding scale. Document result.', - 'vitals', 'urgent', NOW() + INTERVAL '30 minutes', FALSE, 'upcoming' -FROM login l, - patient_profiles pp JOIN login pl ON pp.user_id = pl.user_id AND pl.email = 'patient4@securehealth.com' -WHERE l.email = 'nurse2@securehealth.com'; - -INSERT INTO nurse_tasks (assigned_nurse_id, patient_id, title, description, category, priority, due_time, completed, status) -SELECT l.user_id, pp.profile_id, - 'Wound Dressing Change', 'Change post-op wound dressing using sterile technique. Document wound condition.', - 'care', 'high', NOW() - INTERVAL '1 hour', FALSE, 'overdue' -FROM login l, - patient_profiles pp JOIN login pl ON pp.user_id = pl.user_id AND pl.email = 'patient3@securehealth.com' -WHERE l.email = 'nurse2@securehealth.com'; - -INSERT INTO nurse_tasks (assigned_nurse_id, patient_id, title, description, category, priority, due_time, completed, status) -SELECT l.user_id, pp.profile_id, - 'Discharge Documentation', 'Complete discharge summary and patient education checklist before 15:00.', - 'administrative', 'high', NOW() - INTERVAL '45 minutes', FALSE, 'overdue' -FROM login l, - patient_profiles pp JOIN login pl ON pp.user_id = pl.user_id AND pl.email = 'patient5@securehealth.com' -WHERE l.email = 'nurse1@securehealth.com'; - -INSERT INTO nurse_tasks (assigned_nurse_id, patient_id, title, description, category, priority, due_time, completed, status) -SELECT l.user_id, pp.profile_id, - 'Morning Vital Signs', 'Routine morning vital signs recorded and documented.', - 'vitals', 'normal', NOW() - INTERVAL '4 hours', TRUE, 'completed' -FROM login l, - patient_profiles pp JOIN login pl ON pp.user_id = pl.user_id AND pl.email = 'patient1@securehealth.com' -WHERE l.email = 'nurse1@securehealth.com'; - -INSERT INTO nurse_tasks (assigned_nurse_id, patient_id, title, description, category, priority, due_time, completed, status) -SELECT l.user_id, pp.profile_id, - 'IV Line Check and Flush', 'Checked IV patency, flushed with saline, site clean and intact.', - 'care', 'normal', NOW() - INTERVAL '3 hours', TRUE, 'completed' -FROM login l, - patient_profiles pp JOIN login pl ON pp.user_id = pl.user_id AND pl.email = 'patient3@securehealth.com' -WHERE l.email = 'nurse2@securehealth.com'; - --- ================================================================================= --- VERIFICATION --- ================================================================================= -SELECT 'Reset and reseed completed successfully' AS status; diff --git a/DB/seed_users.sql b/DB/seed_users.sql new file mode 100644 index 00000000..11442710 --- /dev/null +++ b/DB/seed_users.sql @@ -0,0 +1,416 @@ +-- ================================================================================= +-- CUSTOM USER SEED — PatientManagementSystem +-- Run against: healthcare_auth_db (live PostgreSQL) +-- SAFE: insert-only, no DROP/CREATE — schema already managed by JPA/Hibernate +-- +-- Password for ALL users: SecurePassword2024 +-- Hash: argon2id $argon2id$v=19$m=4096,t=3,p=1$Vhabqz80TH4fFH9ehhbWKw$wBgy4sxJmmj3WLPlzGQLbqK9dEJbnslWc/J7xbwVmQ0 +-- ================================================================================= + +-- --------------------------------------------------------------------------------- +-- 1. LOGIN ACCOUNTS +-- --------------------------------------------------------------------------------- + +-- Admin (2FA enabled) +INSERT INTO login (email, password_hash, role, is_active, is_verified, two_factor_enabled) +VALUES ( + 'manvitha3626@gmail.com', + '$argon2id$v=19$m=4096,t=3,p=1$Vhabqz80TH4fFH9ehhbWKw$wBgy4sxJmmj3WLPlzGQLbqK9dEJbnslWc/J7xbwVmQ0', + 'ADMIN', TRUE, TRUE, TRUE +); + +-- Doctors (2FA enabled) +INSERT INTO login (email, password_hash, role, is_active, is_verified, two_factor_enabled) +VALUES + ('riyomen.mikey@gmail.com', + '$argon2id$v=19$m=4096,t=3,p=1$Vhabqz80TH4fFH9ehhbWKw$wBgy4sxJmmj3WLPlzGQLbqK9dEJbnslWc/J7xbwVmQ0', + 'DOCTOR', TRUE, TRUE, TRUE), + ('2004arjunk@gmail.com', + '$argon2id$v=19$m=4096,t=3,p=1$Vhabqz80TH4fFH9ehhbWKw$wBgy4sxJmmj3WLPlzGQLbqK9dEJbnslWc/J7xbwVmQ0', + 'DOCTOR', TRUE, TRUE, TRUE); + +-- Nurse (no 2FA) +INSERT INTO login (email, password_hash, role, is_active, is_verified, two_factor_enabled) +VALUES ( + 'abhirambikkina@gmail.com', + '$argon2id$v=19$m=4096,t=3,p=1$Vhabqz80TH4fFH9ehhbWKw$wBgy4sxJmmj3WLPlzGQLbqK9dEJbnslWc/J7xbwVmQ0', + 'NURSE', TRUE, TRUE, FALSE +); + +-- Lab Technician (no 2FA) +INSERT INTO login (email, password_hash, role, is_active, is_verified, two_factor_enabled) +VALUES ( + 'abhiramamrita@gmail.com', + '$argon2id$v=19$m=4096,t=3,p=1$Vhabqz80TH4fFH9ehhbWKw$wBgy4sxJmmj3WLPlzGQLbqK9dEJbnslWc/J7xbwVmQ0', + 'LAB_TECHNICIAN', TRUE, TRUE, FALSE +); + +-- Patients (no 2FA) +INSERT INTO login (email, password_hash, role, is_active, is_verified, two_factor_enabled) +VALUES + ('diyabhat2005@gmail.com', + '$argon2id$v=19$m=4096,t=3,p=1$Vhabqz80TH4fFH9ehhbWKw$wBgy4sxJmmj3WLPlzGQLbqK9dEJbnslWc/J7xbwVmQ0', + 'PATIENT', TRUE, TRUE, FALSE), + ('editzzz.ani@gmail.com', + '$argon2id$v=19$m=4096,t=3,p=1$Vhabqz80TH4fFH9ehhbWKw$wBgy4sxJmmj3WLPlzGQLbqK9dEJbnslWc/J7xbwVmQ0', + 'PATIENT', TRUE, TRUE, FALSE); + +-- --------------------------------------------------------------------------------- +-- 2. DOCTOR PROFILES +-- --------------------------------------------------------------------------------- + +INSERT INTO doctor_profiles (user_id, first_name, last_name, specialty, department, contact_number, shift_start_time, shift_end_time, slot_duration_minutes) +SELECT user_id, 'Mikey', 'Riyomen', 'General Practice', 'Internal Medicine', '555-1001', '09:00:00', '17:00:00', 30 +FROM login WHERE email = 'riyomen.mikey@gmail.com'; + +INSERT INTO doctor_profiles (user_id, first_name, last_name, specialty, department, contact_number, shift_start_time, shift_end_time, slot_duration_minutes) +SELECT user_id, 'Arjun', 'Kumar', 'Cardiology', 'Cardiology', '555-1002', '09:00:00', '17:00:00', 30 +FROM login WHERE email = '2004arjunk@gmail.com'; + +-- Working days — both doctors: Mon–Fri +INSERT INTO doctor_working_days (doctor_profile_id, working_days) +SELECT dp.profile_id, day +FROM doctor_profiles dp +JOIN login l ON dp.user_id = l.user_id, +LATERAL (VALUES ('MONDAY'), ('TUESDAY'), ('WEDNESDAY'), ('THURSDAY'), ('FRIDAY')) AS days(day) +WHERE l.email IN ('riyomen.mikey@gmail.com', '2004arjunk@gmail.com'); + +-- --------------------------------------------------------------------------------- +-- 3. PATIENT PROFILES +-- --------------------------------------------------------------------------------- + +-- Diya Bhat → assigned to doctor Mikey, nurse Abhiram Bikkina +INSERT INTO patient_profiles (user_id, first_name, last_name, date_of_birth, gender, contact_number, address, medical_history, assigned_doctor_id, assigned_nurse_id) +SELECT + pl.user_id, + 'Diya', 'Bhat', + '2005-04-12', 'Female', '555-2001', '12 Rose Lane, Sydney', + 'No known chronic conditions. Seasonal allergies (pollen).', + (SELECT user_id FROM login WHERE email = 'riyomen.mikey@gmail.com'), + (SELECT user_id FROM login WHERE email = 'abhirambikkina@gmail.com') +FROM login pl WHERE pl.email = 'diyabhat2005@gmail.com'; + +-- Ani → assigned to doctor Arjun, nurse Abhiram Bikkina +INSERT INTO patient_profiles (user_id, first_name, last_name, date_of_birth, gender, contact_number, address, medical_history, assigned_doctor_id, assigned_nurse_id) +SELECT + pl.user_id, + 'Ani', 'Edit', + '1998-09-25', 'Female', '555-2002', '78 Blue St, Melbourne', + 'Mild hypertension — monitored. No medication currently.', + (SELECT user_id FROM login WHERE email = '2004arjunk@gmail.com'), + (SELECT user_id FROM login WHERE email = 'abhirambikkina@gmail.com') +FROM login pl WHERE pl.email = 'editzzz.ani@gmail.com'; + +-- --------------------------------------------------------------------------------- +-- 4. APPOINTMENTS +-- --------------------------------------------------------------------------------- + +-- Diya with Dr. Mikey — upcoming SCHEDULED +INSERT INTO appointments (patient_profile_id, doctor_id, appointment_date, status, reason_for_visit) +SELECT pp.profile_id, l.user_id, NOW() + INTERVAL '5 days', 'SCHEDULED', 'Routine annual checkup' +FROM patient_profiles pp +JOIN login pl ON pp.user_id = pl.user_id AND pl.email = 'diyabhat2005@gmail.com', +login l WHERE l.email = 'riyomen.mikey@gmail.com'; + +-- Diya with Dr. Mikey — past COMPLETED +INSERT INTO appointments (patient_profile_id, doctor_id, appointment_date, status, reason_for_visit, doctor_notes) +SELECT pp.profile_id, l.user_id, NOW() - INTERVAL '14 days', 'COMPLETED', 'Follow-up for seasonal allergies', 'Prescribed antihistamines. Patient improving.' +FROM patient_profiles pp +JOIN login pl ON pp.user_id = pl.user_id AND pl.email = 'diyabhat2005@gmail.com', +login l WHERE l.email = 'riyomen.mikey@gmail.com'; + +-- Ani with Dr. Arjun — upcoming PENDING_APPROVAL +INSERT INTO appointments (patient_profile_id, doctor_id, appointment_date, status, reason_for_visit) +SELECT pp.profile_id, l.user_id, NOW() + INTERVAL '3 days', 'PENDING_APPROVAL', 'Blood pressure review' +FROM patient_profiles pp +JOIN login pl ON pp.user_id = pl.user_id AND pl.email = 'editzzz.ani@gmail.com', +login l WHERE l.email = '2004arjunk@gmail.com'; + +-- Ani with Dr. Arjun — past COMPLETED +INSERT INTO appointments (patient_profile_id, doctor_id, appointment_date, status, reason_for_visit, doctor_notes) +SELECT pp.profile_id, l.user_id, NOW() - INTERVAL '21 days', 'COMPLETED', 'Initial hypertension assessment', 'BP 138/88. Lifestyle changes recommended. Schedule 3-week follow-up.' +FROM patient_profiles pp +JOIN login pl ON pp.user_id = pl.user_id AND pl.email = 'editzzz.ani@gmail.com', +login l WHERE l.email = '2004arjunk@gmail.com'; + +-- --------------------------------------------------------------------------------- +-- 5. VITAL SIGNS (recorded by Abhiram Bikkina - nurse) +-- --------------------------------------------------------------------------------- + +-- Diya — 3 readings over last 3 days +INSERT INTO vital_signs (patient_profile_id, nurse_id, blood_pressure, heart_rate, temperature, respiratory_rate, oxygen_saturation, weight, height, recorded_at) +SELECT pp.profile_id, l.user_id, '118/76', 68, 98.4, 15, 99, 55.0, 162, NOW() - INTERVAL '2 days' +FROM patient_profiles pp +JOIN login pl ON pp.user_id = pl.user_id AND pl.email = 'diyabhat2005@gmail.com', +login l WHERE l.email = 'abhirambikkina@gmail.com'; + +INSERT INTO vital_signs (patient_profile_id, nurse_id, blood_pressure, heart_rate, temperature, respiratory_rate, oxygen_saturation, weight, height, recorded_at) +SELECT pp.profile_id, l.user_id, '116/74', 70, 98.6, 16, 99, 55.0, 162, NOW() - INTERVAL '1 day' +FROM patient_profiles pp +JOIN login pl ON pp.user_id = pl.user_id AND pl.email = 'diyabhat2005@gmail.com', +login l WHERE l.email = 'abhirambikkina@gmail.com'; + +INSERT INTO vital_signs (patient_profile_id, nurse_id, blood_pressure, heart_rate, temperature, respiratory_rate, oxygen_saturation, weight, height, recorded_at) +SELECT pp.profile_id, l.user_id, '120/78', 72, 98.5, 16, 98, 55.0, 162, NOW() +FROM patient_profiles pp +JOIN login pl ON pp.user_id = pl.user_id AND pl.email = 'diyabhat2005@gmail.com', +login l WHERE l.email = 'abhirambikkina@gmail.com'; + +-- Ani — 3 readings (elevated BP trend) +INSERT INTO vital_signs (patient_profile_id, nurse_id, blood_pressure, heart_rate, temperature, respiratory_rate, oxygen_saturation, weight, height, recorded_at) +SELECT pp.profile_id, l.user_id, '140/90', 78, 98.8, 17, 97, 62.0, 165, NOW() - INTERVAL '2 days' +FROM patient_profiles pp +JOIN login pl ON pp.user_id = pl.user_id AND pl.email = 'editzzz.ani@gmail.com', +login l WHERE l.email = 'abhirambikkina@gmail.com'; + +INSERT INTO vital_signs (patient_profile_id, nurse_id, blood_pressure, heart_rate, temperature, respiratory_rate, oxygen_saturation, weight, height, recorded_at) +SELECT pp.profile_id, l.user_id, '138/88', 75, 98.6, 16, 97, 62.0, 165, NOW() - INTERVAL '1 day' +FROM patient_profiles pp +JOIN login pl ON pp.user_id = pl.user_id AND pl.email = 'editzzz.ani@gmail.com', +login l WHERE l.email = 'abhirambikkina@gmail.com'; + +INSERT INTO vital_signs (patient_profile_id, nurse_id, blood_pressure, heart_rate, temperature, respiratory_rate, oxygen_saturation, weight, height, recorded_at) +SELECT pp.profile_id, l.user_id, '136/86', 74, 98.5, 16, 98, 62.0, 165, NOW() +FROM patient_profiles pp +JOIN login pl ON pp.user_id = pl.user_id AND pl.email = 'editzzz.ani@gmail.com', +login l WHERE l.email = 'abhirambikkina@gmail.com'; + +-- --------------------------------------------------------------------------------- +-- 6. PRESCRIPTIONS (ordered by respective doctors) +-- --------------------------------------------------------------------------------- + +-- Diya — antihistamine for allergies (Dr. Mikey) +INSERT INTO prescriptions (patient_profile_id, doctor_id, medication_name, dosage, frequency, duration, special_instructions, status, start_date, end_date, refills_remaining) +SELECT pp.profile_id, l.user_id, + 'Cetirizine', '10mg', 'Once daily at night', '30 days', + 'Take with water. Avoid alcohol.', + 'ACTIVE', NOW() - INTERVAL '14 days', NOW() + INTERVAL '16 days', 1 +FROM patient_profiles pp +JOIN login pl ON pp.user_id = pl.user_id AND pl.email = 'diyabhat2005@gmail.com', +login l WHERE l.email = 'riyomen.mikey@gmail.com'; + +-- Ani — antihypertensive (Dr. Arjun) +INSERT INTO prescriptions (patient_profile_id, doctor_id, medication_name, dosage, frequency, duration, special_instructions, status, start_date, end_date, refills_remaining) +SELECT pp.profile_id, l.user_id, + 'Amlodipine', '5mg', 'Once daily in the morning', '90 days', + 'Monitor BP weekly. Report any swelling in legs.', + 'ACTIVE', NOW() - INTERVAL '21 days', NOW() + INTERVAL '69 days', 2 +FROM patient_profiles pp +JOIN login pl ON pp.user_id = pl.user_id AND pl.email = 'editzzz.ani@gmail.com', +login l WHERE l.email = '2004arjunk@gmail.com'; + +-- --------------------------------------------------------------------------------- +-- 7. MEDICAL RECORDS +-- --------------------------------------------------------------------------------- + +-- Diya — allergy visit (Dr. Mikey) +INSERT INTO medical_records (patient_profile_id, doctor_id, diagnosis, symptoms, treatment_provided) +SELECT pp.profile_id, l.user_id, + 'Seasonal Allergic Rhinitis', + 'Sneezing, nasal congestion, itchy eyes — worse in spring.', + 'Prescribed Cetirizine 10mg daily. Advised to avoid outdoor exposure during high pollen days.' +FROM patient_profiles pp +JOIN login pl ON pp.user_id = pl.user_id AND pl.email = 'diyabhat2005@gmail.com', +login l WHERE l.email = 'riyomen.mikey@gmail.com'; + +-- Ani — hypertension (Dr. Arjun) +INSERT INTO medical_records (patient_profile_id, doctor_id, diagnosis, symptoms, treatment_provided) +SELECT pp.profile_id, l.user_id, + 'Stage 1 Hypertension', + 'Headaches, occasional dizziness. BP consistently 138-142/88-92 over 3 readings.', + 'Prescribed Amlodipine 5mg. Lifestyle advice: reduce sodium, moderate exercise, reduce caffeine.' +FROM patient_profiles pp +JOIN login pl ON pp.user_id = pl.user_id AND pl.email = 'editzzz.ani@gmail.com', +login l WHERE l.email = '2004arjunk@gmail.com'; + +-- --------------------------------------------------------------------------------- +-- 8. LAB TESTS +-- --------------------------------------------------------------------------------- + +-- Diya — allergy panel (COMPLETED), ordered by Dr. Mikey, resulted by lab tech Abhiramamrita +INSERT INTO lab_tests (patient_profile_id, ordered_by_id, test_name, test_category, result_value, unit, reference_range, remarks, status, ordered_at) +SELECT pp.profile_id, l.user_id, + 'Serum IgE (Total)', 'Immunology', + '245', 'IU/mL', '0–100 IU/mL', + 'Elevated IgE consistent with allergic sensitisation.', + 'COMPLETED', NOW() - INTERVAL '13 days' +FROM patient_profiles pp +JOIN login pl ON pp.user_id = pl.user_id AND pl.email = 'diyabhat2005@gmail.com', +login l WHERE l.email = 'riyomen.mikey@gmail.com'; + +-- Diya — CBC pending (Dr. Mikey) +INSERT INTO lab_tests (patient_profile_id, ordered_by_id, test_name, test_category, remarks, status, ordered_at) +SELECT pp.profile_id, l.user_id, + 'Complete Blood Count', 'Hematology', + 'Baseline CBC before follow-up visit.', + 'PENDING', NOW() - INTERVAL '1 day' +FROM patient_profiles pp +JOIN login pl ON pp.user_id = pl.user_id AND pl.email = 'diyabhat2005@gmail.com', +login l WHERE l.email = 'riyomen.mikey@gmail.com'; + +-- Ani — lipid panel (COMPLETED), ordered by Dr. Arjun +INSERT INTO lab_tests (patient_profile_id, ordered_by_id, test_name, test_category, result_value, unit, reference_range, remarks, status, ordered_at) +SELECT pp.profile_id, l.user_id, + 'Lipid Panel', 'Chemistry', + 'LDL 128 / HDL 52 / TG 160', 'mg/dL', 'LDL <130 / HDL >40 / TG <150', + 'LDL borderline. HDL acceptable. Lifestyle modification advised.', + 'COMPLETED', NOW() - INTERVAL '20 days' +FROM patient_profiles pp +JOIN login pl ON pp.user_id = pl.user_id AND pl.email = 'editzzz.ani@gmail.com', +login l WHERE l.email = '2004arjunk@gmail.com'; + +-- Ani — renal function (PENDING, for upcoming review) +INSERT INTO lab_tests (patient_profile_id, ordered_by_id, test_name, test_category, remarks, status, ordered_at) +SELECT pp.profile_id, l.user_id, + 'Renal Function Test', 'Chemistry', + 'Monitor kidney function given antihypertensive therapy.', + 'PENDING', NOW() - INTERVAL '2 hours' +FROM patient_profiles pp +JOIN login pl ON pp.user_id = pl.user_id AND pl.email = 'editzzz.ani@gmail.com', +login l WHERE l.email = '2004arjunk@gmail.com'; + +-- --------------------------------------------------------------------------------- +-- 9. NURSE TASKS (assigned to Abhiram Bikkina) +-- --------------------------------------------------------------------------------- + +-- Diya tasks +INSERT INTO nurse_tasks (assigned_nurse_id, patient_id, title, description, category, priority, due_time, completed, status) +SELECT l.user_id, pp.profile_id, + 'Record Morning Vitals — Diya Bhat', + 'Record BP, HR, temperature, SpO2 before 9 AM.', + 'vitals', 'medium', NOW() + INTERVAL '20 hours', FALSE, 'upcoming' +FROM login l, + patient_profiles pp JOIN login pl ON pp.user_id = pl.user_id AND pl.email = 'diyabhat2005@gmail.com' +WHERE l.email = 'abhirambikkina@gmail.com'; + +INSERT INTO nurse_tasks (assigned_nurse_id, patient_id, title, description, category, priority, due_time, completed, status) +SELECT l.user_id, pp.profile_id, + 'Administer Cetirizine — Diya Bhat', + 'Administer Cetirizine 10mg at night as prescribed by Dr. Riyomen.', + 'medication', 'medium', NOW() + INTERVAL '8 hours', FALSE, 'upcoming' +FROM login l, + patient_profiles pp JOIN login pl ON pp.user_id = pl.user_id AND pl.email = 'diyabhat2005@gmail.com' +WHERE l.email = 'abhirambikkina@gmail.com'; + +-- Ani tasks +INSERT INTO nurse_tasks (assigned_nurse_id, patient_id, title, description, category, priority, due_time, completed, status) +SELECT l.user_id, pp.profile_id, + 'Record Morning Vitals — Ani Edit', + 'Record BP, HR, temperature, SpO2. Pay attention to BP — patient is hypertensive.', + 'vitals', 'high', NOW() + INTERVAL '19 hours', FALSE, 'upcoming' +FROM login l, + patient_profiles pp JOIN login pl ON pp.user_id = pl.user_id AND pl.email = 'editzzz.ani@gmail.com' +WHERE l.email = 'abhirambikkina@gmail.com'; + +INSERT INTO nurse_tasks (assigned_nurse_id, patient_id, title, description, category, priority, due_time, completed, status) +SELECT l.user_id, pp.profile_id, + 'Administer Amlodipine — Ani Edit', + 'Administer Amlodipine 5mg in the morning as prescribed by Dr. Kumar.', + 'medication', 'high', NOW() + INTERVAL '1 hour', FALSE, 'due-soon' +FROM login l, + patient_profiles pp JOIN login pl ON pp.user_id = pl.user_id AND pl.email = 'editzzz.ani@gmail.com' +WHERE l.email = 'abhirambikkina@gmail.com'; + +INSERT INTO nurse_tasks (assigned_nurse_id, patient_id, title, description, category, priority, due_time, completed, status) +SELECT l.user_id, pp.profile_id, + 'Collect Blood Sample for Renal Function Test — Ani Edit', + 'Coordinate with lab for sample collection. Ensure patient is fasting.', + 'assessment', 'high', NOW() + INTERVAL '4 hours', FALSE, 'upcoming' +FROM login l, + patient_profiles pp JOIN login pl ON pp.user_id = pl.user_id AND pl.email = 'editzzz.ani@gmail.com' +WHERE l.email = 'abhirambikkina@gmail.com'; + +-- --------------------------------------------------------------------------------- +-- 10. HANDOVER NOTES (from Abhiram Bikkina - nurse) +-- --------------------------------------------------------------------------------- + +INSERT INTO handover_notes (author_id, patient_id, type, priority, content, shift_direction) +SELECT l.user_id, pp.profile_id, + 'clinical', 'high', + 'Ani Edit (hypertension) — BP was 136/86 this morning, down from 140/90 two days ago. Amlodipine seems to be working. Renal function test sample due today — ensure the next shift collects it.', + 'FOR_NEXT' +FROM login l, + patient_profiles pp JOIN login pl ON pp.user_id = pl.user_id AND pl.email = 'editzzz.ani@gmail.com' +WHERE l.email = 'abhirambikkina@gmail.com'; + +INSERT INTO handover_notes (author_id, patient_id, type, priority, content, shift_direction) +SELECT l.user_id, pp.profile_id, + 'general', 'normal', + 'Diya Bhat — presented mild nasal congestion this morning but otherwise comfortable. Cetirizine administered on schedule. CBC test result still pending.', + 'FOR_NEXT' +FROM login l, + patient_profiles pp JOIN login pl ON pp.user_id = pl.user_id AND pl.email = 'diyabhat2005@gmail.com' +WHERE l.email = 'abhirambikkina@gmail.com'; + +-- --------------------------------------------------------------------------------- +-- 11. AUDIT LOGS +-- --------------------------------------------------------------------------------- + +INSERT INTO audit_logs (email, action, ip_address, details, timestamp) +VALUES + ('manvitha3626@gmail.com', 'LOGIN_SUCCESS', '203.0.113.10', 'method=password', NOW() - INTERVAL '2 hours'), + ('riyomen.mikey@gmail.com', 'LOGIN_SUCCESS', '203.0.113.11', 'method=password+2fa', NOW() - INTERVAL '3 hours'), + ('2004arjunk@gmail.com', 'LOGIN_SUCCESS', '203.0.113.12', 'method=password+2fa', NOW() - INTERVAL '4 hours'), + ('abhirambikkina@gmail.com','LOGIN_SUCCESS', '203.0.113.13', 'method=password', NOW() - INTERVAL '5 hours'), + ('abhiramamrita@gmail.com', 'LOGIN_SUCCESS', '203.0.113.14', 'method=password', NOW() - INTERVAL '5 hours'), + ('diyabhat2005@gmail.com', 'LOGIN_SUCCESS', '203.0.113.15', 'method=password', NOW() - INTERVAL '6 hours'), + ('editzzz.ani@gmail.com', 'LOGIN_SUCCESS', '203.0.113.16', 'method=password', NOW() - INTERVAL '6 hours'), + ('abhirambikkina@gmail.com','VITAL_SIGNS_RECORDED','203.0.113.13', 'bp=120/78 hr=72 patient=diyabhat2005@gmail.com', NOW() - INTERVAL '1 hour'), + ('abhirambikkina@gmail.com','VITAL_SIGNS_RECORDED','203.0.113.13', 'bp=136/86 hr=74 patient=editzzz.ani@gmail.com', NOW() - INTERVAL '1 hour'), + ('riyomen.mikey@gmail.com', 'PRESCRIPTION_CREATED','203.0.113.11', 'medication=Cetirizine patient=diyabhat2005@gmail.com', NOW() - INTERVAL '14 days'), + ('2004arjunk@gmail.com', 'PRESCRIPTION_CREATED','203.0.113.12', 'medication=Amlodipine patient=editzzz.ani@gmail.com', NOW() - INTERVAL '21 days'), + ('riyomen.mikey@gmail.com', 'LAB_TEST_ORDERED', '203.0.113.11', 'test=Serum IgE patient=diyabhat2005@gmail.com', NOW() - INTERVAL '13 days'), + ('2004arjunk@gmail.com', 'LAB_TEST_ORDERED', '203.0.113.12', 'test=Lipid Panel patient=editzzz.ani@gmail.com', NOW() - INTERVAL '20 days'); + +-- --------------------------------------------------------------------------------- +-- 12. PATIENT CONSENTS +-- Grant staff access to patient data so dashboards are not blocked. +-- consent_type values: MEDICAL_RECORDS | LAB_RESULTS | PRESCRIPTIONS | VITAL_SIGNS | ALL +-- status values: ACTIVE | REVOKED +-- --------------------------------------------------------------------------------- + +-- Dr. Mikey → Diya (ALL access — treating physician) +INSERT INTO patient_consents (patient_id, granted_to_id, consent_type, status, granted_at) +SELECT pp.profile_id, l.user_id, 'ALL', 'ACTIVE', NOW() - INTERVAL '14 days' +FROM patient_profiles pp +JOIN login pl ON pp.user_id = pl.user_id AND pl.email = 'diyabhat2005@gmail.com', +login l WHERE l.email = 'riyomen.mikey@gmail.com'; + +-- Dr. Arjun → Ani (ALL access — treating physician) +INSERT INTO patient_consents (patient_id, granted_to_id, consent_type, status, granted_at) +SELECT pp.profile_id, l.user_id, 'ALL', 'ACTIVE', NOW() - INTERVAL '21 days' +FROM patient_profiles pp +JOIN login pl ON pp.user_id = pl.user_id AND pl.email = 'editzzz.ani@gmail.com', +login l WHERE l.email = '2004arjunk@gmail.com'; + +-- Nurse Abhiram → Diya (VITAL_SIGNS + MEDICAL_RECORDS access) +INSERT INTO patient_consents (patient_id, granted_to_id, consent_type, status, granted_at) +SELECT pp.profile_id, l.user_id, unnested.consent_type, 'ACTIVE', NOW() - INTERVAL '14 days' +FROM patient_profiles pp +JOIN login pl ON pp.user_id = pl.user_id AND pl.email = 'diyabhat2005@gmail.com', +login l, +(VALUES ('VITAL_SIGNS'), ('MEDICAL_RECORDS'), ('PRESCRIPTIONS')) AS unnested(consent_type) +WHERE l.email = 'abhirambikkina@gmail.com'; + +-- Nurse Abhiram → Ani (VITAL_SIGNS + MEDICAL_RECORDS access) +INSERT INTO patient_consents (patient_id, granted_to_id, consent_type, status, granted_at) +SELECT pp.profile_id, l.user_id, unnested.consent_type, 'ACTIVE', NOW() - INTERVAL '21 days' +FROM patient_profiles pp +JOIN login pl ON pp.user_id = pl.user_id AND pl.email = 'editzzz.ani@gmail.com', +login l, +(VALUES ('VITAL_SIGNS'), ('MEDICAL_RECORDS'), ('PRESCRIPTIONS')) AS unnested(consent_type) +WHERE l.email = 'abhirambikkina@gmail.com'; + +-- Lab Tech Abhiramamrita → Diya (LAB_RESULTS access) +INSERT INTO patient_consents (patient_id, granted_to_id, consent_type, status, granted_at) +SELECT pp.profile_id, l.user_id, 'LAB_RESULTS', 'ACTIVE', NOW() - INTERVAL '13 days' +FROM patient_profiles pp +JOIN login pl ON pp.user_id = pl.user_id AND pl.email = 'diyabhat2005@gmail.com', +login l WHERE l.email = 'abhiramamrita@gmail.com'; + +-- Lab Tech Abhiramamrita → Ani (LAB_RESULTS access) +INSERT INTO patient_consents (patient_id, granted_to_id, consent_type, status, granted_at) +SELECT pp.profile_id, l.user_id, 'LAB_RESULTS', 'ACTIVE', NOW() - INTERVAL '20 days' +FROM patient_profiles pp +JOIN login pl ON pp.user_id = pl.user_id AND pl.email = 'editzzz.ani@gmail.com', +login l WHERE l.email = 'abhiramamrita@gmail.com'; diff --git a/backend/Backend/src/main/java/com/securehealth/backend/controller/AppointmentController.java b/backend/Backend/src/main/java/com/securehealth/backend/controller/AppointmentController.java index 1ee4ce59..43fdcc09 100644 --- a/backend/Backend/src/main/java/com/securehealth/backend/controller/AppointmentController.java +++ b/backend/Backend/src/main/java/com/securehealth/backend/controller/AppointmentController.java @@ -80,8 +80,7 @@ public ResponseEntity approveAppointment(@PathVariable Long id, Authenticatio } try { - Appointment approved = appointmentService.approveAppointment(id); - return ResponseEntity.ok(approved); + return ResponseEntity.ok(appointmentService.approveAppointment(id)); } catch (RuntimeException e) { return ResponseEntity.badRequest().body(e.getMessage()); } @@ -98,8 +97,7 @@ public ResponseEntity rejectAppointment(@PathVariable Long id, @RequestBody(r } try { - Appointment rejected = appointmentService.rejectAppointment(id, reason); - return ResponseEntity.ok(rejected); + return ResponseEntity.ok(appointmentService.rejectAppointment(id, reason)); } catch (RuntimeException e) { return ResponseEntity.badRequest().body(e.getMessage()); } @@ -111,6 +109,12 @@ public ResponseEntity getAllAppointments() { return ResponseEntity.ok(appointmentService.getAllAppointments()); } + @GetMapping("/pending") + @PreAuthorize("hasAuthority('ADMIN')") + public ResponseEntity getPendingAppointments() { + return ResponseEntity.ok(appointmentService.getPendingAppointments()); + } + @GetMapping("/{id}") public ResponseEntity getById(@PathVariable Long id, Authentication auth) { return appointmentRepository.findById(id) diff --git a/backend/Backend/src/main/java/com/securehealth/backend/service/AppointmentService.java b/backend/Backend/src/main/java/com/securehealth/backend/service/AppointmentService.java index a1e16cc2..d9a3a9d7 100644 --- a/backend/Backend/src/main/java/com/securehealth/backend/service/AppointmentService.java +++ b/backend/Backend/src/main/java/com/securehealth/backend/service/AppointmentService.java @@ -115,7 +115,7 @@ public Appointment createAppointment(AppointmentRequest request, String requeste * ADMIN ONLY: Approves a pending appointment request. */ @Transactional - public Appointment approveAppointment(Long appointmentId) { + public AppointmentDTO approveAppointment(Long appointmentId) { Appointment appointment = appointmentRepository.findById(appointmentId) .orElseThrow(() -> new RuntimeException("404: Appointment not found")); @@ -124,14 +124,15 @@ public Appointment approveAppointment(Long appointmentId) { } appointment.setStatus(com.securehealth.backend.model.AppointmentStatus.SCHEDULED); - return appointmentRepository.save(appointment); + Appointment saved = appointmentRepository.save(appointment); + return toDTO(saved); } /** * ADMIN ONLY: Rejects a pending appointment request, freeing up the slot. */ @Transactional - public Appointment rejectAppointment(Long appointmentId, String rejectionReason) { + public AppointmentDTO rejectAppointment(Long appointmentId, String rejectionReason) { Appointment appointment = appointmentRepository.findById(appointmentId) .orElseThrow(() -> new RuntimeException("404: Appointment not found")); @@ -140,25 +141,27 @@ public Appointment rejectAppointment(Long appointmentId, String rejectionReason) } appointment.setStatus(com.securehealth.backend.model.AppointmentStatus.REJECTED); - // Optional: If you added a 'adminNotes' column, you could save the reason here - // appointment.setDoctorNotes("Rejected by Admin: " + rejectionReason); + Appointment saved = appointmentRepository.save(appointment); + return toDTO(saved); + } - return appointmentRepository.save(appointment); + private AppointmentDTO toDTO(Appointment app) { + AppointmentDTO dto = new AppointmentDTO(); + dto.setAppointmentId(app.getAppointmentId()); + dto.setDoctorId(app.getDoctor().getUserId()); + dto.setDoctorName(app.getDoctor().getEmail()); + dto.setPatientName(app.getPatient().getFirstName() + " " + app.getPatient().getLastName()); + dto.setAppointmentDate(app.getAppointmentDate()); + dto.setStatus(app.getStatus()); + dto.setReasonForVisit(app.getReasonForVisit()); + return dto; } @Transactional(readOnly = true) public List getPendingAppointments() { - return appointmentRepository.findByStatus(com.securehealth.backend.model.AppointmentStatus.PENDING_APPROVAL).stream().map(app -> { - AppointmentDTO dto = new AppointmentDTO(); - dto.setAppointmentId(app.getAppointmentId()); - dto.setDoctorId(app.getDoctor().getUserId()); - dto.setDoctorName(app.getDoctor().getEmail()); - dto.setPatientName(app.getPatient().getFirstName() + " " + app.getPatient().getLastName()); - dto.setAppointmentDate(app.getAppointmentDate()); - dto.setStatus(app.getStatus()); - dto.setReasonForVisit(app.getReasonForVisit()); - return dto; - }).collect(Collectors.toList()); + return appointmentRepository.findByStatus(com.securehealth.backend.model.AppointmentStatus.PENDING_APPROVAL).stream() + .map(this::toDTO) + .collect(Collectors.toList()); } @Transactional diff --git a/backend/Backend/src/test/java/com/securehealth/backend/controller/AppointmentControllerTest.java b/backend/Backend/src/test/java/com/securehealth/backend/controller/AppointmentControllerTest.java index 8d32db2a..1160514c 100644 --- a/backend/Backend/src/test/java/com/securehealth/backend/controller/AppointmentControllerTest.java +++ b/backend/Backend/src/test/java/com/securehealth/backend/controller/AppointmentControllerTest.java @@ -1,5 +1,6 @@ package com.securehealth.backend.controller; +import com.securehealth.backend.dto.AppointmentDTO; import com.securehealth.backend.model.AppointmentStatus; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.core.authority.SimpleGrantedAuthority; @@ -106,7 +107,7 @@ void getAppointmentsByPatient_ReturnsList() throws Exception { @Test void approveAppointment_AsAdmin_Returns200() throws Exception { // Arrange - Appointment approved = new Appointment(); + AppointmentDTO approved = new AppointmentDTO(); approved.setStatus(AppointmentStatus.SCHEDULED); when(appointmentService.approveAppointment(10L)).thenReturn(approved); @@ -138,7 +139,7 @@ void approveAppointment_AsPatient_Returns403() throws Exception { @Test void rejectAppointment_AsAdmin_Returns200() throws Exception { - Appointment rejected = new Appointment(); + AppointmentDTO rejected = new AppointmentDTO(); rejected.setStatus(AppointmentStatus.REJECTED); when(appointmentService.rejectAppointment(eq(10L), any())).thenReturn(rejected); diff --git a/backend/Backend/src/test/java/com/securehealth/backend/service/AppointmentServiceTest.java b/backend/Backend/src/test/java/com/securehealth/backend/service/AppointmentServiceTest.java index 748ce16d..7e79f334 100644 --- a/backend/Backend/src/test/java/com/securehealth/backend/service/AppointmentServiceTest.java +++ b/backend/Backend/src/test/java/com/securehealth/backend/service/AppointmentServiceTest.java @@ -1,5 +1,6 @@ package com.securehealth.backend.service; +import com.securehealth.backend.dto.AppointmentDTO; import com.securehealth.backend.dto.AppointmentRequest; import com.securehealth.backend.model.Appointment; import com.securehealth.backend.model.AppointmentStatus; @@ -109,7 +110,7 @@ void approveAppointment_ChangesStatusToScheduled() { when(appointmentRepository.findById(anyLong())).thenReturn(Optional.of(pendingAppointment)); when(appointmentRepository.save(any(Appointment.class))).thenAnswer(i -> i.getArguments()[0]); - Appointment approved = appointmentService.approveAppointment(10L); + AppointmentDTO approved = appointmentService.approveAppointment(10L); assertEquals(AppointmentStatus.SCHEDULED, approved.getStatus()); } diff --git a/frontend/app/src/components/admin/AppointmentApprovalQueue.jsx b/frontend/app/src/components/admin/AppointmentApprovalQueue.jsx index 723c2337..02c40e7f 100644 --- a/frontend/app/src/components/admin/AppointmentApprovalQueue.jsx +++ b/frontend/app/src/components/admin/AppointmentApprovalQueue.jsx @@ -22,50 +22,20 @@ const AppointmentApprovalQueue = () => { setIsLoading(true); setError(null); try { - // Mock pending appointments for now - setMockPendingAppointments(); + const data = await api.appointments.getPending(); + setPendingAppointments(Array.isArray(data) ? data : []); } catch (err) { console.error('Failed to fetch appointments:', err); setError('Failed to load pending appointments'); - setMockPendingAppointments(); } finally { setIsLoading(false); } }; - const setMockPendingAppointments = () => { - setPendingAppointments([ - { - appointmentId: 1, - patientName: 'John Smith', - patientId: 1, - doctorName: 'Dr. Sarah Johnson', - doctorId: 10, - appointmentDate: new Date(Date.now() + 3600000).toISOString(), - reasonForVisit: 'Regular check-up', - status: 'PENDING_APPROVAL', - requestedAt: new Date().toISOString() - }, - { - appointmentId: 2, - patientName: 'Alice Brown', - patientId: 2, - doctorName: 'Dr. Michael Davis', - doctorId: 11, - appointmentDate: new Date(Date.now() + 7200000).toISOString(), - reasonForVisit: 'Follow-up consultation', - status: 'PENDING_APPROVAL', - requestedAt: new Date().toISOString() - } - ]); - }; - const handleApprove = async (appointmentId) => { try { await api.appointments.approve(appointmentId); - setPendingAppointments(prev => - prev.filter(apt => apt.appointmentId !== appointmentId) - ); + await fetchPendingAppointments(); setConfirmModal({ isOpen: false, action: null }); setSelectedAppt(null); alert('Appointment approved successfully!'); @@ -78,9 +48,7 @@ const AppointmentApprovalQueue = () => { const handleReject = async (appointmentId, reason) => { try { await api.appointments.reject(appointmentId, reason); - setPendingAppointments(prev => - prev.filter(apt => apt.appointmentId !== appointmentId) - ); + await fetchPendingAppointments(); setConfirmModal({ isOpen: false, action: null }); setSelectedAppt(null); setRejectionReason(''); diff --git a/frontend/app/src/pages/patient/Appointments.jsx b/frontend/app/src/pages/patient/Appointments.jsx index 8c6b741c..dab20486 100644 --- a/frontend/app/src/pages/patient/Appointments.jsx +++ b/frontend/app/src/pages/patient/Appointments.jsx @@ -118,11 +118,11 @@ const PatientAppointments = () => { const filteredAppointments = useMemo(() => { return appointments.filter(a => { if (activeTab === 'upcoming') { - return !['COMPLETED', 'CANCELLED'].includes(a.statusRaw || 'PENDING_APPROVAL'); + return !['COMPLETED', 'CANCELLED', 'REJECTED'].includes(a.statusRaw || 'PENDING_APPROVAL'); } else if (activeTab === 'past') { return a.statusRaw === 'COMPLETED'; } else if (activeTab === 'cancelled') { - return a.statusRaw === 'CANCELLED'; + return ['CANCELLED', 'REJECTED'].includes(a.statusRaw); } return true; }); @@ -131,7 +131,7 @@ const PatientAppointments = () => { // Get next 3 upcoming appointments for reminder sidebar const upcomingReminders = useMemo(() => { return appointments - .filter(a => !['COMPLETED', 'CANCELLED'].includes(a.statusRaw || '')) + .filter(a => !['COMPLETED', 'CANCELLED', 'REJECTED'].includes(a.statusRaw || '')) .sort((a, b) => new Date(a.startTime) - new Date(b.startTime)) .slice(0, 3); }, [appointments]); @@ -568,9 +568,9 @@ const PatientAppointments = () => { { appointments.filter(a => { - if (tab.key === 'upcoming') return !['COMPLETED', 'CANCELLED'].includes(a.statusRaw); + if (tab.key === 'upcoming') return !['COMPLETED', 'CANCELLED', 'REJECTED'].includes(a.statusRaw); if (tab.key === 'past') return a.statusRaw === 'COMPLETED'; - if (tab.key === 'cancelled') return a.statusRaw === 'CANCELLED'; + if (tab.key === 'cancelled') return ['CANCELLED', 'REJECTED'].includes(a.statusRaw); return false; }).length } diff --git a/frontend/app/src/services/api.js b/frontend/app/src/services/api.js index e0bfadaf..f8b3b0f4 100644 --- a/frontend/app/src/services/api.js +++ b/frontend/app/src/services/api.js @@ -196,6 +196,28 @@ export const appointmentAPI = { }); }, + // Get all pending-approval appointments (ADMIN only) + getPending: async () => { + return apiCall('/appointments/pending', { + method: 'GET', + }); + }, + + // Approve a pending appointment (ADMIN only) + approve: async (id) => { + return apiCall(`/appointments/${id}/approve`, { + method: 'PUT', + }); + }, + + // Reject a pending appointment with optional reason (ADMIN only) + reject: async (id, reason = '') => { + return apiCall(`/appointments/${id}/reject`, { + method: 'PUT', + body: JSON.stringify(reason), + }); + }, + // Delete appointment delete: async (id) => { return apiCall(`/appointments/${id}`, { From cb457964b8fcb4731857f133316905b0aa7fea76 Mon Sep 17 00:00:00 2001 From: Manvitha Dungi Date: Wed, 11 Mar 2026 13:07:45 +0530 Subject: [PATCH 2/2] fixed failing tests --- .../backend/service/AppointmentServiceTest.java | 2 ++ frontend/app/src/pages/ForgotPassword.test.jsx | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/backend/Backend/src/test/java/com/securehealth/backend/service/AppointmentServiceTest.java b/backend/Backend/src/test/java/com/securehealth/backend/service/AppointmentServiceTest.java index 7e79f334..62c1b3a9 100644 --- a/backend/Backend/src/test/java/com/securehealth/backend/service/AppointmentServiceTest.java +++ b/backend/Backend/src/test/java/com/securehealth/backend/service/AppointmentServiceTest.java @@ -61,6 +61,8 @@ void setUp() { pendingAppointment = new Appointment(); pendingAppointment.setAppointmentId(10L); pendingAppointment.setStatus(AppointmentStatus.PENDING_APPROVAL); + pendingAppointment.setDoctor(doctorLogin); + pendingAppointment.setPatient(patientProfile); } @Test diff --git a/frontend/app/src/pages/ForgotPassword.test.jsx b/frontend/app/src/pages/ForgotPassword.test.jsx index ba799391..b31efcab 100644 --- a/frontend/app/src/pages/ForgotPassword.test.jsx +++ b/frontend/app/src/pages/ForgotPassword.test.jsx @@ -51,7 +51,7 @@ describe('ForgotPassword Page', () => { render(); const emailInput = screen.getByPlaceholderText(/email/i); - await userEvent.type(emailInput, 'invalidemail'); + fireEvent.change(emailInput, { target: { value: 'invalidemail' } }); fireEvent.blur(emailInput); await waitFor(() => { @@ -65,7 +65,7 @@ describe('ForgotPassword Page', () => { render(); const emailInput = screen.getByPlaceholderText(/email/i); - await userEvent.type(emailInput, 'test@example.com'); + fireEvent.change(emailInput, { target: { value: 'test@example.com' } }); const submitButton = screen.getByRole('button', { name: /send reset link/i }); fireEvent.click(submitButton); @@ -81,7 +81,7 @@ describe('ForgotPassword Page', () => { render(); const emailInput = screen.getByPlaceholderText(/email/i); - await userEvent.type(emailInput, 'test@example.com'); + fireEvent.change(emailInput, { target: { value: 'test@example.com' } }); const submitButton = screen.getByRole('button', { name: /send reset link/i }); fireEvent.click(submitButton); @@ -118,7 +118,7 @@ describe('ForgotPassword Page', () => { render(); const emailInput = screen.getByPlaceholderText(/email/i); - await userEvent.type(emailInput, 'test@example.com'); + fireEvent.change(emailInput, { target: { value: 'test@example.com' } }); const submitButton = screen.getByRole('button', { name: /send reset link/i }); expect(submitButton).not.toBeDisabled();