|
| 1 | +// Geriatric Depression Score Calculator |
| 2 | +// Javascript to load a bootstrap-styled calculator on a page |
| 3 | +// created 27/Oct/2017 Dean Jenkins |
| 4 | + |
| 5 | +// The original scale is in the public domain due to it being partly the result of Federal support. |
| 6 | +// See https://web.stanford.edu/~yesavage/GDS.html for more information. |
| 7 | + |
| 8 | +// This code has been released under the following license. |
| 9 | +// Creative Commons Attribution 4.0 International (CC BY 4.0) |
| 10 | +// https://creativecommons.org/licenses/by/4.0/ |
| 11 | + |
| 12 | +function getvaluefromcheckbox(id) { |
| 13 | + if (document.getElementById(id).checked) { |
| 14 | + return parseFloat(document.getElementById(id).value); |
| 15 | + } else { |
| 16 | + return 0; |
| 17 | + } |
| 18 | +} |
| 19 | + |
| 20 | +// getvaluefromradio() for getting radio values |
| 21 | +function getvaluefromradio(name) { // radio buttons work if they have the same name! |
| 22 | + var radios = document.getElementsByName(name); |
| 23 | + |
| 24 | + for (var i = 0, length = radios.length; i < length; i++) { |
| 25 | + if (radios[i].checked) { |
| 26 | + return parseFloat(radios[i].value); |
| 27 | + // only one radio can be logically checked, don't check the rest |
| 28 | + break; |
| 29 | + } |
| 30 | + } |
| 31 | + return null; // we may get here if no radio is checked |
| 32 | +} |
| 33 | + |
| 34 | +function getvaluefromyndkradio(name,positive) { |
| 35 | + value = getvaluefromradio(name); |
| 36 | + if (value == positive) { |
| 37 | + return 1; |
| 38 | + } |
| 39 | + if (value == 0) { |
| 40 | + return null; |
| 41 | + } else { |
| 42 | + return 0; |
| 43 | + } |
| 44 | +} |
| 45 | + |
| 46 | +function uncheck(id) { |
| 47 | + document.getElementById(id).checked = false; |
| 48 | +} |
| 49 | + |
| 50 | +//uncheckradio() for unchecking radio buttons |
| 51 | +function uncheckradio(name) { // radio buttons work if they have the same name! |
| 52 | + var radios = document.getElementsByName(name); |
| 53 | + |
| 54 | + for (var i = 0, length = radios.length; i < length; i++) { |
| 55 | + radios[i].checked = false; |
| 56 | + } |
| 57 | +} |
| 58 | + |
| 59 | +//checkradio() for checking radio buttons |
| 60 | +function checkradio(id) { // specific radio button options have different id's |
| 61 | + document.getElementById(id).checked = true; |
| 62 | +} |
| 63 | + |
| 64 | + |
| 65 | +function GDS() |
| 66 | +{ |
| 67 | + var totalquestions = 15; |
| 68 | + var skipped = 0; |
| 69 | + var gds1=getvaluefromyndkradio("tblable_calc_form_GDS1","-1"); |
| 70 | + if (gds1==null) { skipped = skipped + 1; } |
| 71 | + var gds2=getvaluefromyndkradio("tblable_calc_form_GDS2","1"); |
| 72 | + if (gds2==null) { skipped = skipped + 1; } |
| 73 | + var gds3=getvaluefromyndkradio("tblable_calc_form_GDS3","1"); |
| 74 | + if (gds3==null) { skipped = skipped + 1; } |
| 75 | + var gds4=getvaluefromyndkradio("tblable_calc_form_GDS4","1"); |
| 76 | + if (gds4==null) { skipped = skipped + 1; } |
| 77 | + var gds5=getvaluefromyndkradio("tblable_calc_form_GDS5","-1"); |
| 78 | + if (gds5==null) { skipped = skipped + 1; } |
| 79 | + var gds6=getvaluefromyndkradio("tblable_calc_form_GDS6","1"); |
| 80 | + if (gds6==null) { skipped = skipped + 1; } |
| 81 | + var gds7=getvaluefromyndkradio("tblable_calc_form_GDS7","-1"); |
| 82 | + if (gds7==null) { skipped = skipped + 1; } |
| 83 | + var gds8=getvaluefromyndkradio("tblable_calc_form_GDS8","1"); |
| 84 | + if (gds8==null) { skipped = skipped + 1; } |
| 85 | + var gds9=getvaluefromyndkradio("tblable_calc_form_GDS9","1"); |
| 86 | + if (gds9==null) { skipped = skipped + 1; } |
| 87 | + var gds10=getvaluefromyndkradio("tblable_calc_form_GDS10","1"); |
| 88 | + if (gds10==null) { skipped = skipped + 1; } |
| 89 | + var gds11=getvaluefromyndkradio("tblable_calc_form_GDS11","-1"); |
| 90 | + if (gds11==null) { skipped = skipped + 1; } |
| 91 | + var gds12=getvaluefromyndkradio("tblable_calc_form_GDS12","1"); |
| 92 | + if (gds12==null) { skipped = skipped + 1; } |
| 93 | + var gds13=getvaluefromyndkradio("tblable_calc_form_GDS13","-1"); |
| 94 | + if (gds13==null) { skipped = skipped + 1; } |
| 95 | + var gds14=getvaluefromyndkradio("tblable_calc_form_GDS14","1"); |
| 96 | + if (gds14==null) { skipped = skipped + 1; } |
| 97 | + var gds15=getvaluefromyndkradio("tblable_calc_form_GDS15","1"); |
| 98 | + if (gds15==null) { skipped = skipped + 1; } |
| 99 | + |
| 100 | + if (skipped == totalquestions) { |
| 101 | + var score = 0; |
| 102 | + } else { |
| 103 | + var score = parseFloat(gds1 + gds2 + gds3 + gds4 + gds5 + gds6 + gds7 + gds8 + gds9 + gds10 + gds11 + gds12 + gds13 + gds14 + gds15); |
| 104 | + } |
| 105 | + if (skipped < 8 && skipped > 0) { // correct score as 'few' questions missed |
| 106 | + // see https://web.stanford.edu/~yesavage/GDS.html for the logic |
| 107 | + var rawscore = score; |
| 108 | + console.log("raw score = " + rawscore); |
| 109 | + console.log("skipped = " + skipped); |
| 110 | + var totalanswered = totalquestions - skipped; |
| 111 | + console.log("total answered = " + totalanswered); |
| 112 | + console.log("score = " + rawscore + " + " + skipped + " *(" + rawscore + "/" + totalanswered + ")"); |
| 113 | + score = rawscore + skipped * (rawscore / (totalquestions - skipped)); |
| 114 | + score = Math.round(score + 0.5); |
| 115 | + if (score>15) { score=15; } // don't give a score of 16 by rounding up |
| 116 | + console.log("score = " + score); |
| 117 | + } |
| 118 | + document.getElementById("tblable_calc_form_score").innerHTML = score.toString(); |
| 119 | + |
| 120 | + var summaryhtml=""; |
| 121 | + |
| 122 | + if (score<5) { |
| 123 | + summaryhtml = summaryhtml + "Normal, depending on age, education, complaints"; |
| 124 | + $('#result').removeClass(); |
| 125 | + $('#result').addClass("alert alert-success"); |
| 126 | + } |
| 127 | + if (score>4 && score<9) { |
| 128 | + summaryhtml = summaryhtml + "Mild depression"; |
| 129 | + $('#result').removeClass(); |
| 130 | + $('#result').addClass("alert alert-warning"); |
| 131 | + } |
| 132 | + if (score>8 && score<12) { |
| 133 | + summaryhtml = summaryhtml + "Moderate depression"; |
| 134 | + $('#result').removeClass(); |
| 135 | + $('#result').addClass("alert alert-danger"); |
| 136 | + } |
| 137 | + if (score>11) { |
| 138 | + summaryhtml = summaryhtml + "Severe depression"; |
| 139 | + $('#result').removeClass(); |
| 140 | + $('#result').addClass("alert alert-danger"); |
| 141 | + } |
| 142 | + |
| 143 | + if (skipped < 8 && skipped > 0 && score != rawscore) { |
| 144 | + if (skipped==1) { |
| 145 | + summaryhtml = summaryhtml + ". (Score of " + rawscore + " corrected assuming the 1 missed question would indicate depression.)"; |
| 146 | + } else { |
| 147 | + summaryhtml = summaryhtml + ". (Score of " + rawscore + " corrected assuming " + parseFloat(score - rawscore) + " of the " + skipped + " missed questions would indicate depression.)"; |
| 148 | + } |
| 149 | + } |
| 150 | + document.getElementById("tblable_calc_form_comment").innerHTML = summaryhtml; |
| 151 | +} |
| 152 | + |
| 153 | +function resetCalc() { |
| 154 | + uncheckradio("tblable_calc_form_GDS1"); |
| 155 | + checkradio("tblable_calc_form_GDS1dk"); |
| 156 | + |
| 157 | + uncheckradio("tblable_calc_form_GDS2"); |
| 158 | + checkradio("tblable_calc_form_GDS2dk"); |
| 159 | + |
| 160 | + uncheckradio("tblable_calc_form_GDS3"); |
| 161 | + checkradio("tblable_calc_form_GDS3dk"); |
| 162 | + |
| 163 | + uncheckradio("tblable_calc_form_GDS4"); |
| 164 | + checkradio("tblable_calc_form_GDS4dk"); |
| 165 | + |
| 166 | + uncheckradio("tblable_calc_form_GDS5"); |
| 167 | + checkradio("tblable_calc_form_GDS5dk"); |
| 168 | + |
| 169 | + uncheckradio("tblable_calc_form_GDS6"); |
| 170 | + checkradio("tblable_calc_form_GDS6dk"); |
| 171 | + |
| 172 | + uncheckradio("tblable_calc_form_GDS7"); |
| 173 | + checkradio("tblable_calc_form_GDS7dk"); |
| 174 | + |
| 175 | + uncheckradio("tblable_calc_form_GDS8"); |
| 176 | + checkradio("tblable_calc_form_GDS8dk"); |
| 177 | + |
| 178 | + uncheckradio("tblable_calc_form_GDS9"); |
| 179 | + checkradio("tblable_calc_form_GDS9dk"); |
| 180 | + |
| 181 | + uncheckradio("tblable_calc_form_GDS10"); |
| 182 | + checkradio("tblable_calc_form_GDS10dk"); |
| 183 | + |
| 184 | + uncheckradio("tblable_calc_form_GDS11"); |
| 185 | + checkradio("tblable_calc_form_GDS11dk"); |
| 186 | + |
| 187 | + uncheckradio("tblable_calc_form_GDS12"); |
| 188 | + checkradio("tblable_calc_form_GDS12dk"); |
| 189 | + |
| 190 | + uncheckradio("tblable_calc_form_GDS13"); |
| 191 | + checkradio("tblable_calc_form_GDS13dk"); |
| 192 | + |
| 193 | + uncheckradio("tblable_calc_form_GDS14"); |
| 194 | + checkradio("tblable_calc_form_GDS14dk"); |
| 195 | + |
| 196 | + uncheckradio("tblable_calc_form_GDS15"); |
| 197 | + checkradio("tblable_calc_form_GDS15dk"); |
| 198 | +} |
| 199 | + |
| 200 | +function unckeck(varname) { |
| 201 | + document.getElementById(varname).checked = false; |
| 202 | +} |
| 203 | + |
| 204 | +function headerBlurb(title,oneliner,instruction) { |
| 205 | + var html='<h2>' + title + '</h2>' + |
| 206 | +'<p>' + oneliner + '</p>' + |
| 207 | +'<p class="font-italic">' + instruction + '</p>' |
| 208 | + return html; |
| 209 | +} |
| 210 | + |
| 211 | +function simplecheckbox(varname,value,labeltext,onclick) { |
| 212 | + var html = ' <div class="row1">' + |
| 213 | +' <div class="col1">' + |
| 214 | +' <input id="' + varname + '" value="'+ value +'" onclick="'+ onclick +'" type="checkbox">' + |
| 215 | +' <label for="' + varname + '">' + labeltext + '</label>' + |
| 216 | +' </div>' + |
| 217 | +' </div>' |
| 218 | + return html; |
| 219 | +} |
| 220 | + |
| 221 | +function simpleradio(varid,varname,value,labeltext,onclick) { |
| 222 | + var html = ' <div class="row1">' + |
| 223 | +' <div class="col1">' + |
| 224 | +' <input id="' + varid + '" name="' + varname + '" value="'+ value +'" onclick="'+ onclick +'" type="radio">' + |
| 225 | +' <label for="' + varid + '">' + labeltext + '</label>' + |
| 226 | +' </div>' + |
| 227 | +' </div>' |
| 228 | + return html; |
| 229 | +} |
| 230 | + |
| 231 | +function yndkradio(varidy,varidn,variddk,varname,question,onclick) { |
| 232 | + var html = ' <div>' + |
| 233 | +' <div>' + |
| 234 | +' <p>' + question + '</p>' + |
| 235 | +' </div>' + |
| 236 | +' <div class="col1 yndk">' + |
| 237 | +' <input id="' + varidy + '" name="' + varname + '" value="1" onclick="'+ onclick +'" type="radio">' + |
| 238 | +' <label for="' + varidy + '">Yes</label>' + |
| 239 | +' <input id="' + varidn + '" name="' + varname + '" value="-1" onclick="'+ onclick +'" type="radio">' + |
| 240 | +' <label for="' + varidn + '">No</label>' + |
| 241 | +' <input id="' + variddk + '" name="' + varname + '" value="0" onclick="'+ onclick +'" type="radio">' + |
| 242 | +' <label for="' + variddk + '">skip</label>' + |
| 243 | +' </div>' + |
| 244 | +' </div>' |
| 245 | + return html; |
| 246 | +} |
| 247 | + |
| 248 | + |
| 249 | +var calculatorHTML = '' + |
| 250 | +'<div class="calculator" id="tblable_calc">' + |
| 251 | + |
| 252 | +' <div name="hform" id="tblable_calc_form">' + |
| 253 | + |
| 254 | +headerBlurb("Geriatric Depression Scale","Screening tool for depression (short version)","Select all that apply. Score may be corrected for skipped questions.") + |
| 255 | + |
| 256 | +yndkradio("tblable_calc_form_GDS1y","tblable_calc_form_GDS1n","tblable_calc_form_GDS1dk","tblable_calc_form_GDS1","Are you basically satisfied with your life?","GDS();") + |
| 257 | +yndkradio("tblable_calc_form_GDS2y","tblable_calc_form_GDS2n","tblable_calc_form_GDS2dk","tblable_calc_form_GDS2","Have you dropped many of your activities and interests?","GDS();") + |
| 258 | +yndkradio("tblable_calc_form_GDS3y","tblable_calc_form_GDS3n","tblable_calc_form_GDS3dk","tblable_calc_form_GDS3","Do you feel that your life is empty?","GDS();") + |
| 259 | +yndkradio("tblable_calc_form_GDS4y","tblable_calc_form_GDS4n","tblable_calc_form_GDS4dk","tblable_calc_form_GDS4","Do you often get bored?","GDS();") + |
| 260 | +yndkradio("tblable_calc_form_GDS5y","tblable_calc_form_GDS5n","tblable_calc_form_GDS5dk","tblable_calc_form_GDS5","Are you in good spirits most of the time?","GDS();") + |
| 261 | +yndkradio("tblable_calc_form_GDS6y","tblable_calc_form_GDS6n","tblable_calc_form_GDS6dk","tblable_calc_form_GDS6","Are you afraid that something bad is going to happen to you?","GDS();") + |
| 262 | +yndkradio("tblable_calc_form_GDS7y","tblable_calc_form_GDS7n","tblable_calc_form_GDS7dk","tblable_calc_form_GDS7","Do you feel happy most of the time?","GDS();") + |
| 263 | +yndkradio("tblable_calc_form_GDS8y","tblable_calc_form_GDS8n","tblable_calc_form_GDS8dk","tblable_calc_form_GDS8","Do you often feel helpless?","GDS();") + |
| 264 | +yndkradio("tblable_calc_form_GDS9y","tblable_calc_form_GDS9n","tblable_calc_form_GDS9dk","tblable_calc_form_GDS9","Do you prefer to stay at home, rather than going out and doing new things?","GDS();") + |
| 265 | +yndkradio("tblable_calc_form_GDS10y","tblable_calc_form_GDS10n","tblable_calc_form_GDS10dk","tblable_calc_form_GDS10","Do you feel you have more problems with memory than most?","GDS();") + |
| 266 | +yndkradio("tblable_calc_form_GD11y","tblable_calc_form_GDS11n","tblable_calc_form_GDS11dk","tblable_calc_form_GDS11","Do you think it is wonderful to be alive now?","GDS();") + |
| 267 | +yndkradio("tblable_calc_form_GDS12y","tblable_calc_form_GDS12n","tblable_calc_form_GDS12dk","tblable_calc_form_GDS12","Do you feel pretty worthless the way you are now?","GDS();") + |
| 268 | +yndkradio("tblable_calc_form_GDS13y","tblable_calc_form_GDS13n","tblable_calc_form_GDS13dk","tblable_calc_form_GDS13","Do you feel full of energy?","GDS();") + |
| 269 | +yndkradio("tblable_calc_form_GDS14y","tblable_calc_form_GDS14n","tblable_calc_form_GDS14dk","tblable_calc_form_GDS14","Do you feel that your situation is hopeless?","GDS();") + |
| 270 | +yndkradio("tblable_calc_form_GDS15y","tblable_calc_form_GDS15n","tblable_calc_form_GDS15dk","tblable_calc_form_GDS15","Do you think that most people are better off than you are?","GDS();") + |
| 271 | + |
| 272 | +' <div id="result" class="alert alert-success">' + |
| 273 | +' <div><b>GDS score = <span id="tblable_calc_form_score"></span></b>. ' + |
| 274 | +' <span id="tblable_calc_form_comment"></span></div>' + |
| 275 | +' </div>' + |
| 276 | + |
| 277 | +' <div class="reset">' + |
| 278 | +' <input value="Reset" class="btn btn-secondary" onclick="resetCalc(); GDS(); return false;" type="reset">' + |
| 279 | +' </div>' + |
| 280 | + |
| 281 | +' </div><!-- end hform -->' + |
| 282 | + |
| 283 | +'</div><!-- end calculator -->' + |
| 284 | +'<p class="small">Source <a href="https://web.stanford.edu/~yesavage/GDS.html">Sheik et al. (1986)</a></p>' + |
| 285 | +''; |
| 286 | + |
| 287 | +function calcHTML() { |
| 288 | + document.write('<div id="calc"></div>'); |
| 289 | + |
| 290 | + document.getElementById("calc").innerHTML = calculatorHTML; |
| 291 | +} |
| 292 | + |
| 293 | +calcHTML(); |
| 294 | +resetCalc(); // required to set the default radio button |
| 295 | +GDS(); |
0 commit comments