Spaces:
Sleeping
Sleeping
Update script.js
Browse files
script.js
CHANGED
|
@@ -1,18 +1,129 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
|
|
|
|
|
|
| 4 |
});
|
| 5 |
-
|
|
|
|
|
|
|
| 6 |
}
|
| 7 |
|
|
|
|
| 8 |
function handleSubmit() {
|
| 9 |
-
const
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
showScreen(4);
|
| 18 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Function to switch between screens
|
| 2 |
+
function showScreen(screenNumber) {
|
| 3 |
+
// Hide all screens
|
| 4 |
+
document.querySelectorAll('.screen').forEach(screen => {
|
| 5 |
+
screen.classList.remove('active');
|
| 6 |
});
|
| 7 |
+
|
| 8 |
+
// Show the requested screen
|
| 9 |
+
document.getElementById('screen' + screenNumber).classList.add('active');
|
| 10 |
}
|
| 11 |
|
| 12 |
+
// Handle form submission
|
| 13 |
function handleSubmit() {
|
| 14 |
+
const response = document.getElementById('response').value.trim();
|
| 15 |
+
|
| 16 |
+
if (response.length < 10) {
|
| 17 |
+
alert('Please provide a more detailed response.');
|
| 18 |
+
return;
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
// Analyze the response and provide feedback
|
| 22 |
+
const feedback = analyzeResponse(response);
|
| 23 |
+
|
| 24 |
+
// Display feedback
|
| 25 |
+
document.getElementById('feedbackText').innerHTML = feedback;
|
| 26 |
+
|
| 27 |
+
// Show feedback screen
|
| 28 |
showScreen(4);
|
| 29 |
}
|
| 30 |
+
|
| 31 |
+
// Function to analyze caregiver response
|
| 32 |
+
function analyzeResponse(response) {
|
| 33 |
+
// Convert to lowercase for easier matching
|
| 34 |
+
const lowercaseResponse = response.toLowerCase();
|
| 35 |
+
|
| 36 |
+
// Initialize score and feedback
|
| 37 |
+
let score = 0;
|
| 38 |
+
let positiveFeedback = [];
|
| 39 |
+
let improvementFeedback = [];
|
| 40 |
+
|
| 41 |
+
// Check for positive approaches
|
| 42 |
+
if (lowercaseResponse.includes('calm') || lowercaseResponse.includes('gentle')) {
|
| 43 |
+
score += 1;
|
| 44 |
+
positiveFeedback.push('β Using a calm and gentle approach');
|
| 45 |
+
} else {
|
| 46 |
+
improvementFeedback.push('β Consider using a calm and gentle tone');
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
if (lowercaseResponse.includes('distract') || lowercaseResponse.includes('redirect')) {
|
| 50 |
+
score += 2;
|
| 51 |
+
positiveFeedback.push('β Good use of redirection or distraction techniques');
|
| 52 |
+
} else {
|
| 53 |
+
improvementFeedback.push('β Consider using redirection or distraction');
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
if (lowercaseResponse.includes('reassure') || lowercaseResponse.includes('comfort')) {
|
| 57 |
+
score += 1;
|
| 58 |
+
positiveFeedback.push('β Providing reassurance and comfort');
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
if (lowercaseResponse.includes('listen') || lowercaseResponse.includes('understand')) {
|
| 62 |
+
score += 1;
|
| 63 |
+
positiveFeedback.push('β Taking time to listen and understand concerns');
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
if (lowercaseResponse.includes('routine') || lowercaseResponse.includes('familiar')) {
|
| 67 |
+
score += 1;
|
| 68 |
+
positiveFeedback.push('β Recognizing the importance of routine or familiarity');
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
// Check for approaches to avoid
|
| 72 |
+
if (lowercaseResponse.includes('force') || lowercaseResponse.includes('insist')) {
|
| 73 |
+
score -= 1;
|
| 74 |
+
improvementFeedback.push('β Avoid forcing or insisting when someone with dementia is agitated');
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
if (lowercaseResponse.includes('argue') || lowercaseResponse.includes('reason with')) {
|
| 78 |
+
score -= 1;
|
| 79 |
+
improvementFeedback.push('β Avoid arguing or using complex reasoning');
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
// Generate feedback based on score
|
| 83 |
+
let feedbackHTML = '';
|
| 84 |
+
|
| 85 |
+
if (score >= 3) {
|
| 86 |
+
feedbackHTML += '<h3 class="feedback-positive">Great approach!</h3>';
|
| 87 |
+
} else if (score >= 1) {
|
| 88 |
+
feedbackHTML += '<h3 class="feedback-neutral">Good start, with room for improvement</h3>';
|
| 89 |
+
} else {
|
| 90 |
+
feedbackHTML += '<h3 class="feedback-negative">Consider a different approach</h3>';
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
// Add detailed feedback
|
| 94 |
+
feedbackHTML += '<div class="feedback-details">';
|
| 95 |
+
|
| 96 |
+
if (positiveFeedback.length > 0) {
|
| 97 |
+
feedbackHTML += '<div class="feedback-section"><h4>What you did well:</h4><ul>';
|
| 98 |
+
positiveFeedback.forEach(item => {
|
| 99 |
+
feedbackHTML += `<li>${item}</li>`;
|
| 100 |
+
});
|
| 101 |
+
feedbackHTML += '</ul></div>';
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
if (improvementFeedback.length > 0) {
|
| 105 |
+
feedbackHTML += '<div class="feedback-section"><h4>Suggestions for improvement:</h4><ul>';
|
| 106 |
+
improvementFeedback.forEach(item => {
|
| 107 |
+
feedbackHTML += `<li>${item}</li>`;
|
| 108 |
+
});
|
| 109 |
+
feedbackHTML += '</ul></div>';
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
// Add expert tips
|
| 113 |
+
feedbackHTML += `
|
| 114 |
+
<div class="feedback-section">
|
| 115 |
+
<h4>Expert tips:</h4>
|
| 116 |
+
<ul>
|
| 117 |
+
<li>Approach from the front, maintain eye contact</li>
|
| 118 |
+
<li>Use simple language and short sentences</li>
|
| 119 |
+
<li>Allow extra time for responses</li>
|
| 120 |
+
<li>Consider unmet needs (hunger, thirst, pain, toilet)</li>
|
| 121 |
+
<li>Create a calm environment (reduce noise, appropriate lighting)</li>
|
| 122 |
+
</ul>
|
| 123 |
+
</div>
|
| 124 |
+
`;
|
| 125 |
+
|
| 126 |
+
feedbackHTML += '</div>';
|
| 127 |
+
|
| 128 |
+
return feedbackHTML;
|
| 129 |
+
}
|