4 * phq-9 form using forms api new.php create a new form
7 * @link http://www.open-emr.org
8 * @author Ruth Moulton <moulton ruth@muswell.me.uk>
9 * @copyright Copyright (c) 2021 ruth moulton <ruth@muswell.me.uk>
11 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
14 require_once("../../globals.php");
15 require_once("phq9.inc.php"); //common strings
16 require_once("$srcdir/api.inc.php");
18 use OpenEMR\Common\Csrf\CsrfUtils
;
19 use OpenEMR\Core\Header
;
21 if ($viewmode == 'update') {
22 $obj = formFetch("form_phq9", $_GET["id"]);
29 <title
><?php
echo text($str_form_title); ?
> </title
>
30 <?php Header
::setupHeader(); ?
>
32 <body
class="body_top">
34 //var no_qs = 10; // number of questions in the form
35 var phq9_score
= 0; // total score
40 <script src
="<?php echo $rootdir; ?>/forms/phq9/phq9_javasrc.js"></script
>
43 // stuff that uses embedded php must go here, not in the include javascript file -
44 // it must be executed on server side before page is sent to client. included
45 // javascript is only executed on the client
46 function create_q10(question
, menue
) {
47 // create the 10th question - the second part is italicised. Only displayed if score > 0
48 var text
= document
.createTextNode(jsAttr("10" +
". "+
<?php
echo js_escape($str_q10); ?
>));
49 question
.appendChild(text
);
50 var new_line
= document
.createElement("br");
51 var ital
= document
.createElement("i"); // second part is in italics
52 var question_2
= document
.createTextNode(jsAttr(<?php
echo js_escape($str_q10_2); ?
>));
53 ital
.appendChild(question_2
);
54 question
.name
= "tenth";
55 question
.appendChild(new_line
);
56 question
.appendChild(ital
);
57 // populate the the menue
58 menue
.options
[0] = new Option( <?php
echo js_escape($str_not); ?
>, "0");
59 menue
.options
[1] = new Option( <?php
echo js_escape($str_somewhat); ?
>, "1");
60 menue
.options
[2] = new Option( <?php
echo js_escape($str_very); ?
>, "2");
61 menue
.options
[3] = new Option( <?php
echo js_escape($str_extremely);?
>, "3");
62 menue
.options
[4] = new Option( <?php
echo js_escape($str_default); ?
>, "undef");
66 <h3
><?php
echo text($str_form_name); ?
></h3
>
67 <form method
=post action
="<?php echo $rootdir; ?>/forms/phq9/save.php?mode=<?php echo attr_url($viewmode); ?>&id=<?php echo attr_url($_GET['id'] ?? 0); ?>" name
="my_form"<?php
if (!$obj) {
68 ?
> onSubmit
="return(check_all());"<?php
}?
>>
69 <input type
="hidden" name
="csrf_token_form" value
="<?php echo attr(CsrfUtils::collectCsrfToken()); ?>" />
70 <div
class="title"><?php
echo xlt('How often have you been bothered by the following over the past 2 weeks?'); ?
></div
>
75 <span
class="label"><?php
echo ++
$qno . ". " . xlt('Little interest or pleasure in doing things'); ?
></span
>
76 <select
class="form-input" name
="interest_score" onchange
="update_score(0, my_form.interest_score.value);">
78 <option value
="undef"><?php
echo text($str_default); ?
></option
> <?php
} ?
>
79 <option value
="0"><?php
echo text($str_not); ?
></option
>
80 <option value
="1"><?php
echo text($str_several); ?
></option
>
81 <option value
="2"><?php
echo text($str_more); ?
></option
>
82 <option value
="3"><?php
echo text($str_nearly); ?
></option
>
86 // set the default to the previous value - so it is displayed in the menue box
87 document
.my_form
.interest_score
.options
[<?php
echo attr($obj['interest_score']); ?
>].defaultSelected
=true;
88 var i
= <?php
echo js_escape($obj['interest_score']); ?
>; //the value from last time
89 phq9_score +
= parseInt (i
);
98 <span
class="label"><?php
echo ++
$qno . ". " . xlt('Feeling down, depressed, or hopeless'); ?
></span
>
99 <select
class="input-sm my-1" name
="hopeless_score" onchange
="update_score(1, my_form.hopeless_score.value);">
101 ?
><option value
="undef"><?php
echo text($str_default); ?
></option
><?php
} ?
>
102 <option value
="0"><?php
echo text($str_not); ?
></option
>
103 <option value
="1"><?php
echo text($str_several); ?
></option
>
104 <option value
="2"><?php
echo text($str_more); ?
></option
>
105 <option value
="3"><?php
echo text($str_nearly); ?
></option
>
109 // set the default to the previous value - so it is displayed in the menue box
110 var i
= <?php
echo js_escape($obj['hopeless_score']); ?
>; //the value from last time
111 document
.my_form
.hopeless_score
.options
[i
].defaultSelected
=true;
112 phq9_score +
= parseInt (i
);
121 <span
class="label"><?php
echo ++
$qno . ". " . xlt('Trouble falling or staying asleep, or sleeping too much'); ?
></span
>
122 <select
class="input-sm my-1" name
="sleep_score" onchange
="update_score(2, my_form.sleep_score.value);">
124 ?
><option value
="undef"><?php
echo text($str_default); ?
></option
><?php
} ?
>
125 <option value
="0"><?php
echo text($str_not); ?
></option
>
126 <option value
="1"><?php
echo text($str_several); ?
></option
>
127 <option value
="2"><?php
echo text($str_more); ?
></option
>
128 <option value
="3"><?php
echo text($str_nearly); ?
></option
>
132 // set the previous value to the default - so it is displayed in the menue box
133 var i
= <?php
echo js_escape($obj['sleep_score']); ?
> ; //the value from last time
134 document
.my_form
.sleep_score
.options
[i
].defaultSelected
=true;
135 phq9_score +
= parseInt (i
);
144 <span
class="label"><?php
echo ++
$qno . ". " . xlt('Feeling tired or having little energy'); ?
></span
>
145 <select
class="input-sm my-1" name
="fatigue_score" onchange
="update_score(3, my_form.fatigue_score.value);">
147 ?
><option value
="undef"><?php
echo text($str_default); ?
></option
><?php
} ?
>
148 <option value
="0"><?php
echo text($str_not); ?
></option
>
149 <option value
="1"><?php
echo text($str_several); ?
></option
>
150 <option value
="2"><?php
echo text($str_more); ?
></option
>
151 <option value
="3"><?php
echo text($str_nearly); ?
></option
>
155 // set the previous value to the default - so it is displayed in the menue box
156 var i
= <?php
echo js_escape($obj['fatigue_score']); ?
> ; //the value from last time
157 document
.my_form
.fatigue_score
.options
[i
].defaultSelected
=true;
158 phq9_score +
= parseInt (i
);
167 <span
class="label"><?php
echo ++
$qno . ". " . xlt('Poor appetite or overeating'); ?
></span
>
168 <select
class="input-sm my-1" name
="appetite_score" onchange
="update_score(4, my_form.appetite_score.value);">
170 ?
><option value
="undef"><?php
echo text($str_default); ?
></option
><?php
} ?
>
171 <option value
="0"><?php
echo text($str_not); ?
></option
>
172 <option value
="1"><?php
echo text($str_several); ?
></option
>
173 <option value
="2"><?php
echo text($str_more); ?
></option
>
174 <option value
="3"><?php
echo text($str_nearly); ?
></option
>
178 // set the previous value to the default - so it is displayed in the menue box
179 var i
= <?php
echo js_escape($obj['appetite_score']); ?
> ; //the value from last time
180 document
.my_form
.appetite_score
.options
[i
].defaultSelected
=true;
181 phq9_score +
= parseInt (i
);
190 <span
class="label"><?php
echo ++
$qno . ". " . xlt('Feeling bad about yourself - or that you are a failure or have let yourself or your family down'); ?
></span
>
191 <select
class="input-sm my-1" name
="failure_score" onchange
="update_score(5, my_form.failure_score.value);">
193 ?
><option value
="undef"><?php
echo text($str_default); ?
></option
><?php
} ?
>
194 <option value
="0"><?php
echo text($str_not); ?
></option
>
195 <option value
="1"><?php
echo text($str_several); ?
></option
>
196 <option value
="2"><?php
echo text($str_more); ?
></option
>
197 <option value
="3"><?php
echo text($str_nearly); ?
></option
>
201 // set the previous value to the default - so it is displayed in the menue box
202 var i
= <?php
echo js_escape($obj['failure_score']); ?
> ; //the value from last time
203 document
.my_form
.failure_score
.options
[i
].defaultSelected
=true;
204 phq9_score +
= parseInt (i
);
213 <span
class="label"><?php
echo ++
$qno . ". " . xlt('Trouble concentrating on things, such as reading an article or watching videos'); ?
></span
>
214 <select
class="input-sm my-1" name
="focus_score" onchange
="update_score(6, my_form.focus_score.value);">
216 ?
><option value
="undef"><?php
echo text($str_default); ?
></option
><?php
} ?
>
217 <option value
="0"><?php
echo text($str_not); ?
></option
>
218 <option value
="1"><?php
echo text($str_several); ?
></option
>
219 <option value
="2"><?php
echo text($str_more); ?
></option
>
220 <option value
="3"><?php
echo text($str_nearly); ?
></option
>
224 // set the previous value to the default - so it is displayed in the menue box
225 var i
= <?php
echo js_escape($obj['focus_score']);?
> ; //the value from last time
226 document
.my_form
.focus_score
.options
[i
].defaultSelected
=true;
227 phq9_score +
= parseInt (i
);
236 <span
class="label"><?php
echo ++
$qno . ". " . xlt('Moving or speaking slowly noted by others or fidgety or restless more than usual'); ?
></span
>
237 <select
class="input-sm my-1" name
="psychomotor_score" onchange
="update_score(7, my_form.psychomotor_score.value);">
239 ?
><option value
="undef"><?php
echo text($str_default); ?
></option
><?php
} ?
>
240 <option value
="0"><?php
echo text($str_not); ?
></option
>
241 <option value
="1"><?php
echo text($str_several); ?
></option
>
242 <option value
="2"><?php
echo text($str_more); ?
></option
>
243 <option value
="3"><?php
echo text($str_nearly); ?
></option
>
247 // set the previous value to the default - so it is displayed in the menue box
248 var i
= <?php
echo js_escape($obj['psychomotor_score']);?
> ; //the value from last time
249 document
.my_form
.psychomotor_score
.options
[i
].defaultSelected
=true;
250 phq9_score +
= parseInt (i
);
259 <span
class="label"><?php
echo ++
$qno . ". " . xlt('Thoughts that you would be better off dead, or of hurting yourself'); ?
></span
>
260 <select
class="input-sm my-1" name
="suicide_score" onchange
="update_score(8, my_form.suicide_score.value);">
262 ?
><option value
="undef"><?php
echo text($str_default); ?
></option
><?php
} ?
>
263 <option value
="0"><?php
echo text($str_not); ?
></option
>
264 <option value
="1"><?php
echo text($str_several); ?
></option
>
265 <option value
="2"><?php
echo text($str_more); ?
></option
>
266 <option value
="3"><?php
echo text($str_nearly); ?
></option
>
270 // set the previous value to the default - so it is displayed in the menue box
271 var i
= <?php
echo js_escape($obj['suicide_score']);?
> ; //the value from last time
272 document
.my_form
.suicide_score
.options
[i
].defaultSelected
=true;
273 phq9_score +
= parseInt (i
);
283 <span id
="q10_place" class="label"></span
>
289 function check_all() {
290 // has each question been answered and save scores
293 for (i
= 0; i
< (no_qs
- 1); i++
) { // last questionis optional
294 if (!all_answered
[i
]) {
295 list = list +
Number(i +
1) +
',';
300 list[list.length
- 1] = ' '; /* get rid of trailing comma */
301 alert(xl("Please answer all of the questions") +
": " +
list +
" " +
xl("are unanswered"));
307 // warn if about to exit without saving answers - check that's what the user really wants
308 function nosave_exit() {
309 var conf
= confirm(<?php
echo js_escape($str_nosave_confirm); ?
>);
312 window
.location
.href
= "<?php echo $GLOBALS['form_exit_url']; ?>";
321 <span id
="show_phq9_score"><b
><?php
echo xlt("Total PHQ-9 score"); ?
>:</b
>
326 manage_question_10 (<?php
echo js_escape($obj["difficulty"]); ?
>);
327 update_score("undef", phq9_score
);
332 <button
class="btn btn-primary btn-save my-2" type
="submit" value
="<?php echo xla('Save Form'); ?>"><?php
echo xlt('Save Form'); ?
></button
>
333 <button
class="btn btn-secondary btn-cancel" type
="button" value
="<?php echo xla('Cancel'); ?>" onclick
="top.restoreSession();return( nosave_exit());"><?php
echo xlt('Cancel'); ?
></button
>