// Learning Management System JavaScript class LearningManagementSystem { constructor() { this.currentUser = this.loadUserData(); this.courseData = this.loadCourseData(); this.aiResponses = this.loadAIResponses(); this.quizBank = this.loadQuizBank(); } init() { this.updateUserInterface(); this.setupEventListeners(); this.loadRecentActivity(); } loadUserData() { // In production, this would come from your backend const savedData = localStorage.getItem('userData'); if (savedData) { return JSON.parse(savedData); } return { name: 'Sarah Johnson', program: 'Healthcare Aide (HCA)', currentModule: 3, overallProgress: 30, moduleProgress: 67, completedModules: [1, 2], certificates: ['Module 1', 'Module 2'], totalStudyTime: '45 hours' }; } loadCourseData() { return { 1: { title: 'Foundations of Healthcare Aide Practice', description: 'Ethics, professionalism, roles, communication, and the healthcare system in Canada.', lessons: [ { id: 1, title: 'Introduction to Healthcare', type: 'video', duration: '15 min', completed: true }, { id: 2, title: 'Professional Ethics', type: 'reading', duration: '20 min', completed: true }, { id: 3, title: 'Communication Skills', type: 'interactive', duration: '25 min', completed: true }, { id: 4, title: 'Healthcare Team Roles', type: 'video', duration: '18 min', completed: true } ], quiz: { id: 1, title: 'Module 1 Assessment', questions: 15, completed: true, score: 89 } }, 2: { title: 'Human Body Basics', description: 'Anatomy, physiology, common illnesses, and the aging process.', lessons: [ { id: 5, title: 'Basic Anatomy Overview', type: 'video', duration: '22 min', completed: true }, { id: 6, title: 'Body Systems', type: 'interactive', duration: '30 min', completed: true }, { id: 7, title: 'Common Health Conditions', type: 'reading', duration: '25 min', completed: true }, { id: 8, title: 'Aging Process', type: 'video', duration: '20 min', completed: true } ], quiz: { id: 2, title: 'Module 2 Assessment', questions: 20, completed: true, score: 94 } }, 3: { title: 'Infection Prevention & Control', description: 'Hand hygiene, PPE, isolation precautions, and preventing healthcare-associated infections.', lessons: [ { id: 9, title: 'Hand Hygiene Fundamentals', type: 'video', duration: '18 min', completed: true }, { id: 10, title: 'Personal Protective Equipment', type: 'interactive', duration: '25 min', completed: true }, { id: 11, title: 'Isolation Precautions', type: 'reading', duration: '20 min', completed: false }, { id: 12, title: 'Cleaning & Disinfection', type: 'video', duration: '22 min', completed: false } ], quiz: { id: 3, title: 'Module 3 Assessment', questions: 18, completed: false, score: null } } }; } loadAIResponses() { return { 'hand hygiene': 'Proper hand hygiene involves washing hands with soap and water for at least 20 seconds, or using alcohol-based hand sanitizer with at least 60% alcohol. Key moments: before patient contact, after patient contact, after contact with patient surroundings, before aseptic tasks, and after body fluid exposure.', 'ppe': 'Personal Protective Equipment (PPE) includes gloves, gowns, masks, and eye protection. Always don the PPE in the correct order: hand hygiene → gown → mask → eye protection → gloves. Remove in reverse order and perform hand hygiene after removal.', 'patient transfer': 'Safe patient transfer requires proper body mechanics: keep your back straight, bend at knees, get close to the patient, use your leg muscles, and always communicate with the patient throughout the transfer. Use transfer aids when available.', 'default': 'I understand you\'re studying healthcare aide concepts. Could you be more specific about what you\'d like to learn? I can help with topics like infection control, patient care, communication, safety procedures, and more.' }; } loadQuizBank() { return [ { id: 1, question: "How long should you wash your hands with soap and water?", options: ["10 seconds", "15 seconds", "20 seconds", "30 seconds"], correct: 2, explanation: "Hands should be washed for at least 20 seconds to effectively remove germs and bacteria." }, { id: 2, question: "What is the correct order for donning PPE?", options: ["Gloves, gown, mask, eye protection", "Gown, mask, eye protection, gloves", "Mask, gown, gloves, eye protection", "Eye protection, mask, gown, gloves"], correct: 1, explanation: "The correct order is: hand hygiene → gown → mask → eye protection → gloves." }, { id: 3, question: "Which precaution prevents the spread of infections transmitted by large droplets?", options: ["Contact precautions", "Droplet precautions", "Airborne precautions", "Standard precautions"], correct: 1, explanation: "Droplet precautions prevent transmission of infections spread by large respiratory droplets." } ]; } updateUserInterface() { // Update user name and current program const nameElement = document.getElementById('student-name'); const programElement = document.getElementById('current-program'); if (nameElement) nameElement.textContent = this.currentUser.name; if (programElement) programElement.textContent = this.currentUser.program; // Update progress indicators this.updateProgressBars(); } updateProgressBars() { const progressBar = document.getElementById('progress-bar'); const progressPercentage = document.getElementById('progress-percentage'); const currentModuleSpan = document.getElementById('current-module'); const moduleProgress = document.getElementById('module-progress'); if (progressBar) progressBar.style.width = `${this.currentUser.overallProgress}%`; if (progressPercentage) progressPercentage.textContent = this.currentUser.overallProgress; if (currentModuleSpan) currentModuleSpan.textContent = this.currentUser.currentModule; if (moduleProgress) moduleProgress.textContent = this.currentUser.moduleProgress; } setupEventListeners() { // AI Tutor enter key const aiInput = document.getElementById('ai-question'); if (aiInput) { aiInput.addEventListener('keypress', (e) => { if (e.key === 'Enter') { this.askAITutor(); } }); } } loadRecentActivity() { const activities = [ { type: 'quiz', title: 'Completed Quiz: PPE Procedures', detail: 'Score: 92% • 2 hours ago', icon: 'fa-check', color: 'green' }, { type: 'video', title: 'Watched: Hand Hygiene Best Practices', detail: '15 min video • Yesterday', icon: 'fa-video', color: 'blue' }, { type: 'ai', title: 'AI Tutor Session', detail: 'Asked about isolation procedures • 2 days ago', icon: 'fa-brain', color: 'purple' } ]; // Activities are already in HTML, but this could be dynamic } } // Module and Learning Functions function continueModule() { const moduleNumber = 3; // Current module openModule(moduleNumber); } function openModule(moduleNumber) { const modal = document.getElementById('learning-modal'); const title = document.getElementById('modal-title'); const content = document.getElementById('modal-content'); const lms = window.lmsInstance; const moduleData = lms.courseData[moduleNumber]; if (!moduleData) { alert('Module content not available yet. Coming soon!'); return; } title.textContent = `Module ${moduleNumber}: ${moduleData.title}`; content.innerHTML = `

Module Overview

${moduleData.description}

Lessons

${moduleData.lessons.map(lesson => `
${lesson.completed ? '' : ``}

${lesson.title}

${lesson.type.charAt(0).toUpperCase() + lesson.type.slice(1)} • ${lesson.duration}
${lesson.completed ? '' : ''}
`).join('')}

${moduleData.quiz.title}

${moduleData.quiz.questions} questions • ${moduleData.quiz.completed ? `Score: ${moduleData.quiz.score}%` : 'Not completed'}
`; modal.classList.remove('hidden'); } function openLesson(lessonId) { // Simulate opening a lesson const lessons = { 9: { title: 'Hand Hygiene Fundamentals', type: 'video', content: `

Key Learning Points

` }, 10: { title: 'Personal Protective Equipment', type: 'interactive', content: `

Interactive PPE Training

Learn the correct sequence for putting on and removing PPE.

Donning PPE (Putting On)

  1. 1 Hand hygiene
  2. 2 Gown
  3. 3 Mask or respirator
  4. 4 Eye protection
  5. 5 Gloves

Doffing PPE (Removing)

  1. 1 Gloves
  2. 2 Hand hygiene
  3. 3 Eye protection
  4. 4 Gown
  5. 5 Mask
  6. 6 Hand hygiene
` } }; const lesson = lessons[lessonId]; if (lesson) { const content = document.getElementById('modal-content'); content.innerHTML = lesson.content; } else { // Default lesson content const content = document.getElementById('modal-content'); content.innerHTML = `

Lesson Content Coming Soon

This lesson will be available in the full version of the platform.

`; } } function markLessonComplete(lessonId) { alert('Lesson marked as complete! 🎉'); // In production, this would update the backend closeLearningModal(); } function openNextLesson(lessonId) { openLesson(lessonId + 1); } function startModuleQuiz(moduleNumber) { closeLearningModal(); openQuizModal(moduleNumber); } function openQuizModal(moduleNumber = null) { const modal = document.getElementById('quiz-modal'); const content = document.getElementById('quiz-content'); const lms = window.lmsInstance; const questions = lms.quizBank.slice(0, 3); // Show 3 sample questions content.innerHTML = `
Question 1 of ${questions.length} Time: 05:00
${renderQuestion(questions[0], 0)}
`; // Initialize quiz state window.quizState = { currentQuestion: 0, questions: questions, answers: {}, timeRemaining: 300 // 5 minutes }; startQuizTimer(); modal.classList.remove('hidden'); } function renderQuestion(question, index) { return `

${question.question}

${question.options.map((option, optionIndex) => ` `).join('')}
`; } function selectAnswer(questionId, answerIndex) { window.quizState.answers[questionId] = answerIndex; } function nextQuestion() { const state = window.quizState; if (state.currentQuestion < state.questions.length - 1) { state.currentQuestion++; updateQuizDisplay(); } else { finishQuiz(); } } function previousQuestion() { const state = window.quizState; if (state.currentQuestion > 0) { state.currentQuestion--; updateQuizDisplay(); } } function updateQuizDisplay() { const state = window.quizState; const question = state.questions[state.currentQuestion]; document.getElementById('current-question').textContent = state.currentQuestion + 1; document.getElementById('question-container').innerHTML = renderQuestion(question, state.currentQuestion); document.getElementById('quiz-progress').style.width = `${((state.currentQuestion + 1) / state.questions.length) * 100}%`; // Update buttons document.getElementById('prev-btn').disabled = state.currentQuestion === 0; document.getElementById('next-btn').textContent = state.currentQuestion === state.questions.length - 1 ? 'Finish Quiz' : 'Next Question'; } function finishQuiz() { const state = window.quizState; let score = 0; Object.keys(state.answers).forEach(questionId => { const question = state.questions.find(q => q.id == questionId); if (question && state.answers[questionId] === question.correct) { score++; } }); const percentage = Math.round((score / state.questions.length) * 100); document.getElementById('quiz-content').innerHTML = `

Quiz Complete!

Your Score: ${percentage}%

You got ${score} out of ${state.questions.length} questions correct.

${percentage >= 80 ? '

Excellent work! You\'ve mastered this material.

' : '

Good effort! Review the material and try again to improve your score.

' }
`; } function startQuizTimer() { const timer = setInterval(() => { const state = window.quizState; if (state.timeRemaining <= 0) { clearInterval(timer); finishQuiz(); return; } state.timeRemaining--; const minutes = Math.floor(state.timeRemaining / 60); const seconds = state.timeRemaining % 60; const timerElement = document.getElementById('quiz-timer'); if (timerElement) { timerElement.textContent = `${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}`; } }, 1000); } // AI Tutor Functions function askAITutor() { const input = document.getElementById('ai-question'); const question = input.value.trim(); if (!question) return; addChatMessage('user', question); input.value = ''; // Simulate AI response setTimeout(() => { const response = getAIResponse(question); addChatMessage('ai', response); }, 1000); } function askQuickQuestion(question) { document.getElementById('ai-question').value = question; askAITutor(); } function getAIResponse(question) { const lms = window.lmsInstance; const lowercaseQuestion = question.toLowerCase(); for (const [key, response] of Object.entries(lms.aiResponses)) { if (lowercaseQuestion.includes(key)) { return response; } } return lms.aiResponses.default; } function addChatMessage(sender, message) { const chatContainer = document.getElementById('ai-chat'); const messageDiv = document.createElement('div'); messageDiv.className = `text-sm mb-3 ${sender === 'user' ? 'text-right' : ''}`; messageDiv.innerHTML = `
${sender === 'ai' ? 'AI Tutor: ' : ''}${message}
`; chatContainer.appendChild(messageDiv); chatContainer.scrollTop = chatContainer.scrollHeight; } // Study Tools Functions function openQuizBank() { openQuizModal(); } function openStudyNotes() { alert('Study Notes feature coming soon! 📝'); } function openCertificates() { alert('Certificates section coming soon! 🏆'); } function openJobPortal() { alert('Job Portal coming soon! 💼'); } // Modal Functions function closeLearningModal() { document.getElementById('learning-modal').classList.add('hidden'); } function closeQuizModal() { document.getElementById('quiz-modal').classList.add('hidden'); } function retakeQuiz() { window.quizState.currentQuestion = 0; window.quizState.answers = {}; window.quizState.timeRemaining = 300; const content = document.getElementById('quiz-content'); content.innerHTML = ''; // Clear and reload quiz closeQuizModal(); setTimeout(() => openQuizModal(), 100); } // Initialize LMS let lmsInstance; export function init() { lmsInstance = new LearningManagementSystem(); window.lmsInstance = lmsInstance; lmsInstance.init(); // Make functions globally available window.continueModule = continueModule; window.openModule = openModule; window.openLesson = openLesson; window.markLessonComplete = markLessonComplete; window.openNextLesson = openNextLesson; window.startModuleQuiz = startModuleQuiz; window.askAITutor = askAITutor; window.askQuickQuestion = askQuickQuestion; window.openQuizBank = openQuizBank; window.openStudyNotes = openStudyNotes; window.openCertificates = openCertificates; window.openJobPortal = openJobPortal; window.closeLearningModal = closeLearningModal; window.closeQuizModal = closeQuizModal; window.nextQuestion = nextQuestion; window.previousQuestion = previousQuestion; window.selectAnswer = selectAnswer; window.retakeQuiz = retakeQuiz; } export function teardown() { // Clean up any intervals or event listeners if (window.lmsInstance) { delete window.lmsInstance; } }