-- phpMyAdmin SQL Dump
-- version 5.2.1
-- https://www.phpmyadmin.net/
--
-- Host: 127.0.0.1
-- Generation Time: Jan 25, 2026 at 04:58 PM
-- Server version: 10.4.32-MariaDB
-- PHP Version: 8.0.30

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
START TRANSACTION;
SET time_zone = "+00:00";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;

--
-- Database: `osce_pro_db`
--

-- --------------------------------------------------------

--
-- Table structure for table `attempts`
--

CREATE TABLE `attempts` (
  `id` int(11) NOT NULL,
  `candidate_id` int(11) NOT NULL,
  `form_id` int(11) NOT NULL,
  `examiner_id` int(11) NOT NULL,
  `station_name` varchar(100) DEFAULT NULL,
  `total_score` int(11) NOT NULL,
  `max_score` int(11) NOT NULL,
  `percentage` decimal(5,2) NOT NULL,
  `final_grade` varchar(100) NOT NULL,
  `global_comment` text DEFAULT NULL,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Table structure for table `attempt_items`
--

CREATE TABLE `attempt_items` (
  `id` int(11) NOT NULL,
  `attempt_id` int(11) NOT NULL,
  `form_item_id` int(11) NOT NULL,
  `score` int(11) NOT NULL,
  `comment` text DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Table structure for table `candidates`
--

CREATE TABLE `candidates` (
  `id` int(11) NOT NULL,
  `facility_id` int(11) NOT NULL,
  `candidate_number` varchar(50) NOT NULL,
  `name` varchar(100) NOT NULL,
  `barcode` varchar(50) NOT NULL,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Dumping data for table `candidates`
--

INSERT INTO `candidates` (`id`, `facility_id`, `candidate_number`, `name`, `barcode`, `created_at`) VALUES
(8, 1, '2024GMD01', 'KHALAF', 'C000008', '2026-01-25 14:17:42'),
(9, 1, '2024gmd02', 'AHMED', 'C000009', '2026-01-25 15:16:03');

-- --------------------------------------------------------

--
-- Table structure for table `facilities`
--

CREATE TABLE `facilities` (
  `id` int(11) NOT NULL,
  `name` varchar(100) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Dumping data for table `facilities`
--

INSERT INTO `facilities` (`id`, `name`) VALUES
(1, 'Default OSCE Centre'),
(2, 'Main OSCE Center'),
(3, 'Main OSCE Centre');

-- --------------------------------------------------------

--
-- Table structure for table `forms`
--

CREATE TABLE `forms` (
  `id` int(11) NOT NULL,
  `facility_id` int(11) DEFAULT NULL,
  `name` varchar(100) NOT NULL,
  `description` text DEFAULT NULL,
  `created_by` int(11) NOT NULL,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Dumping data for table `forms`
--

INSERT INTO `forms` (`id`, `facility_id`, `name`, `description`, `created_by`, `created_at`) VALUES
(1, 1, 'cvs', 'cvs', 1, '2025-11-30 13:09:18'),
(2, 1, 'RNS', 'TEST', 4, '2026-01-25 15:17:46');

-- --------------------------------------------------------

--
-- Table structure for table `form_items`
--

CREATE TABLE `form_items` (
  `id` int(11) NOT NULL,
  `form_id` int(11) NOT NULL,
  `label` text NOT NULL,
  `max_score` int(11) NOT NULL DEFAULT 1,
  `has_comment` tinyint(1) NOT NULL DEFAULT 1,
  `sort_order` int(11) NOT NULL DEFAULT 0
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Dumping data for table `form_items`
--

INSERT INTO `form_items` (`id`, `form_id`, `label`, `max_score`, `has_comment`, `sort_order`) VALUES
(1, 1, 'wash', 4, 1, 1),
(2, 1, 'cpr', 4, 1, 2),
(3, 1, 'bls', 10, 1, 3),
(4, 1, 'b', 4, 0, 4),
(5, 1, 'b', 1, 0, 5),
(6, 2, 'test', 1, 1, 1),
(7, 2, 'rt', 1, 1, 2),
(8, 2, 'rr', 1, 1, 3);

-- --------------------------------------------------------

--
-- Table structure for table `grade_bands`
--

CREATE TABLE `grade_bands` (
  `id` int(11) NOT NULL,
  `form_id` int(11) NOT NULL,
  `label` varchar(100) NOT NULL,
  `min_percent` decimal(5,2) NOT NULL,
  `max_percent` decimal(5,2) NOT NULL,
  `sort_order` int(11) NOT NULL DEFAULT 0
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Dumping data for table `grade_bands`
--

INSERT INTO `grade_bands` (`id`, `form_id`, `label`, `min_percent`, `max_percent`, `sort_order`) VALUES
(11, 1, 'Poor', 0.00, 49.99, 1),
(12, 1, 'Below expectation', 50.00, 64.99, 2),
(13, 1, 'Meets expectation', 65.00, 74.99, 3),
(14, 1, 'Above expectation', 75.00, 84.99, 4),
(15, 1, 'Exceeds expectation', 85.00, 100.00, 5),
(26, 2, 'Poor', 0.00, 49.99, 1),
(27, 2, 'Below expectation', 50.00, 64.99, 2),
(28, 2, 'Meets expectation', 65.00, 74.99, 3),
(29, 2, 'Above expectation', 75.00, 84.99, 4),
(30, 2, 'Exceeds expectation', 85.00, 100.00, 5);

-- --------------------------------------------------------

--
-- Table structure for table `osce_logs`
--

CREATE TABLE `osce_logs` (
  `id` int(11) NOT NULL,
  `event_type` varchar(50) DEFAULT NULL,
  `user_role` enum('candidate','examiner','admin') DEFAULT NULL,
  `user_id` int(11) DEFAULT NULL,
  `message` text DEFAULT NULL,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Table structure for table `osce_sessions`
--

CREATE TABLE `osce_sessions` (
  `id` int(11) NOT NULL,
  `candidate_id` int(11) NOT NULL,
  `station` varchar(100) DEFAULT NULL,
  `examiner_id` int(11) DEFAULT NULL,
  `status` enum('waiting','checked_in','in_progress','submitted','timeout') DEFAULT 'waiting',
  `start_time` datetime DEFAULT NULL,
  `end_time` datetime DEFAULT NULL,
  `duration_minutes` int(11) DEFAULT 10,
  `last_action` varchar(255) DEFAULT NULL,
  `last_update` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Dumping data for table `osce_sessions`
--

INSERT INTO `osce_sessions` (`id`, `candidate_id`, `station`, `examiner_id`, `status`, `start_time`, `end_time`, `duration_minutes`, `last_action`, `last_update`) VALUES
(1, 8, 'cvs', 4, 'checked_in', '2026-01-25 16:54:53', NULL, 2, 'Candidate checked in', '2026-01-25 15:54:53'),
(2, 9, 'cvs', 4, 'checked_in', '2026-01-25 19:16:32', NULL, 8, 'Candidate checked in', '2026-01-25 15:46:20'),
(3, 9, 'RNS', 4, 'checked_in', '2026-01-25 19:18:44', NULL, 8, 'Candidate checked in', '2026-01-25 15:46:34'),
(4, 8, 'RNS', 4, 'checked_in', '2026-01-25 16:31:18', NULL, 2, 'Candidate checked in', '2026-01-25 15:31:18');

-- --------------------------------------------------------

--
-- Table structure for table `users`
--

CREATE TABLE `users` (
  `id` int(11) NOT NULL,
  `username` varchar(50) NOT NULL,
  `password_hash` varchar(255) NOT NULL,
  `full_name` varchar(100) NOT NULL,
  `role` enum('super_admin','facility') NOT NULL DEFAULT 'facility',
  `facility_id` int(11) DEFAULT NULL,
  `active` tinyint(1) NOT NULL DEFAULT 1,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Dumping data for table `users`
--

INSERT INTO `users` (`id`, `username`, `password_hash`, `full_name`, `role`, `facility_id`, `active`, `created_at`) VALUES
(1, 'admin', '$2y$10$XJLJJRhhgJdF/8bx7jGizO.NRLoihNmPkBYmXpn8Uv5UwvW5O0UgW', 'Dr. Almazrouei', 'super_admin', NULL, 1, '2025-11-30 12:53:18'),
(4, 'mkm1971', '$2y$10$N/3WqOfePCyTEPeDwKIoVO71THk.Rnz7nkA.VQbQyulp4bGgBxDfa', 'KHALAF', 'facility', 1, 1, '2025-11-30 13:40:13');

--
-- Indexes for dumped tables
--

--
-- Indexes for table `attempts`
--
ALTER TABLE `attempts`
  ADD PRIMARY KEY (`id`),
  ADD KEY `candidate_id` (`candidate_id`),
  ADD KEY `form_id` (`form_id`),
  ADD KEY `examiner_id` (`examiner_id`);

--
-- Indexes for table `attempt_items`
--
ALTER TABLE `attempt_items`
  ADD PRIMARY KEY (`id`),
  ADD KEY `attempt_id` (`attempt_id`),
  ADD KEY `form_item_id` (`form_item_id`);

--
-- Indexes for table `candidates`
--
ALTER TABLE `candidates`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `barcode` (`barcode`),
  ADD KEY `facility_id` (`facility_id`);

--
-- Indexes for table `facilities`
--
ALTER TABLE `facilities`
  ADD PRIMARY KEY (`id`);

--
-- Indexes for table `forms`
--
ALTER TABLE `forms`
  ADD PRIMARY KEY (`id`),
  ADD KEY `created_by` (`created_by`);

--
-- Indexes for table `form_items`
--
ALTER TABLE `form_items`
  ADD PRIMARY KEY (`id`),
  ADD KEY `form_id` (`form_id`);

--
-- Indexes for table `grade_bands`
--
ALTER TABLE `grade_bands`
  ADD PRIMARY KEY (`id`),
  ADD KEY `form_id` (`form_id`);

--
-- Indexes for table `osce_logs`
--
ALTER TABLE `osce_logs`
  ADD PRIMARY KEY (`id`);

--
-- Indexes for table `osce_sessions`
--
ALTER TABLE `osce_sessions`
  ADD PRIMARY KEY (`id`);

--
-- Indexes for table `users`
--
ALTER TABLE `users`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `username` (`username`),
  ADD KEY `facility_id` (`facility_id`);

--
-- AUTO_INCREMENT for dumped tables
--

--
-- AUTO_INCREMENT for table `attempts`
--
ALTER TABLE `attempts`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=8;

--
-- AUTO_INCREMENT for table `attempt_items`
--
ALTER TABLE `attempt_items`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=31;

--
-- AUTO_INCREMENT for table `candidates`
--
ALTER TABLE `candidates`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=10;

--
-- AUTO_INCREMENT for table `facilities`
--
ALTER TABLE `facilities`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=4;

--
-- AUTO_INCREMENT for table `forms`
--
ALTER TABLE `forms`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=3;

--
-- AUTO_INCREMENT for table `form_items`
--
ALTER TABLE `form_items`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=9;

--
-- AUTO_INCREMENT for table `grade_bands`
--
ALTER TABLE `grade_bands`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=31;

--
-- AUTO_INCREMENT for table `osce_logs`
--
ALTER TABLE `osce_logs`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `osce_sessions`
--
ALTER TABLE `osce_sessions`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=5;

--
-- AUTO_INCREMENT for table `users`
--
ALTER TABLE `users`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=5;

--
-- Constraints for dumped tables
--

--
-- Constraints for table `attempts`
--
ALTER TABLE `attempts`
  ADD CONSTRAINT `attempts_ibfk_1` FOREIGN KEY (`candidate_id`) REFERENCES `candidates` (`id`),
  ADD CONSTRAINT `attempts_ibfk_2` FOREIGN KEY (`form_id`) REFERENCES `forms` (`id`),
  ADD CONSTRAINT `attempts_ibfk_3` FOREIGN KEY (`examiner_id`) REFERENCES `users` (`id`);

--
-- Constraints for table `attempt_items`
--
ALTER TABLE `attempt_items`
  ADD CONSTRAINT `attempt_items_ibfk_1` FOREIGN KEY (`attempt_id`) REFERENCES `attempts` (`id`),
  ADD CONSTRAINT `attempt_items_ibfk_2` FOREIGN KEY (`form_item_id`) REFERENCES `form_items` (`id`);

--
-- Constraints for table `candidates`
--
ALTER TABLE `candidates`
  ADD CONSTRAINT `candidates_ibfk_1` FOREIGN KEY (`facility_id`) REFERENCES `facilities` (`id`);

--
-- Constraints for table `forms`
--
ALTER TABLE `forms`
  ADD CONSTRAINT `forms_ibfk_1` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`);

--
-- Constraints for table `form_items`
--
ALTER TABLE `form_items`
  ADD CONSTRAINT `form_items_ibfk_1` FOREIGN KEY (`form_id`) REFERENCES `forms` (`id`);

--
-- Constraints for table `grade_bands`
--
ALTER TABLE `grade_bands`
  ADD CONSTRAINT `grade_bands_ibfk_1` FOREIGN KEY (`form_id`) REFERENCES `forms` (`id`);

--
-- Constraints for table `users`
--
ALTER TABLE `users`
  ADD CONSTRAINT `users_ibfk_1` FOREIGN KEY (`facility_id`) REFERENCES `facilities` (`id`);
COMMIT;

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
