fix: Update patient_tracker.php (#6595)
[openemr.git] / interface / forms / phq9 / common.php
blobcf9d13dd7807ad71f68e83e3b92725aa9c3c4cb0
1 <?php
3 /**
4 * phq-9 form using forms api new.php create a new form
6 * @package OpenEMR
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"]);
23 } else {
24 $obj = null;
27 <html>
28 <head>
29 <title><?php echo text($str_form_title); ?> </title>
30 <?php Header::setupHeader(); ?>
31 </head>
32 <body class="body_top">
33 <script>
34 //var no_qs = 10; // number of questions in the form
35 var phq9_score = 0; // total score
37 </script>
38 <?php $qno = 0; ?>
40 <script src="<?php echo $rootdir; ?>/forms/phq9/phq9_javasrc.js"></script>
42 <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");
64 </script>
65 <div class="col-12">
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>
71 <hr />
72 <table>
73 <tr>
74 <td>
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);">
77 <?php if (!$obj) { ?>
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>
83 </select>
84 <?php if ($obj) { ?>
85 <script>
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);
90 all_scores[0] = i;
91 </script><?php } ?>
92 </td>
93 </tr>
94 </table>
95 <table>
96 <tr>
97 <td>
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);">
100 <?php if (!$obj) {
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>
106 </select>
107 <?php if ($obj) { ?>
108 <script>
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);
113 all_scores[1] = i;
114 </script><?php } ?>
115 </td>
116 </tr>
117 </table>
118 <table>
119 <tr>
120 <td>
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);">
123 <?php if (!$obj) {
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>
129 </select>
130 <?php if ($obj) { ?>
131 <script>
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);
136 all_scores[2] = i;
137 </script><?php } ?>
138 </td>
139 </tr>
140 </table>
141 <table>
142 <tr>
143 <td>
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);">
146 <?php if (!$obj) {
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>
152 </select>
153 <?php if ($obj) { ?>
154 <script>
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);
159 all_scores[3] = i;
160 </script><?php } ?>
161 </td>
162 </tr>
163 </table>
164 <table>
165 <tr>
166 <td>
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);">
169 <?php if (!$obj) {
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>
175 </select>
176 <?php if ($obj) { ?>
177 <script>
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);
182 all_scores[4] = i;
183 </script><?php } ?>
184 </td>
185 </tr>
186 </table>
187 <table>
188 <tr>
189 <td>
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);">
192 <?php if (!$obj) {
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>
198 </select>
199 <?php if ($obj) { ?>
200 <script>
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);
205 all_scores[5] = i;
206 </script><?php } ?>
207 </td>
208 </table>
209 </tr>
210 <table>
211 <tr>
212 <td>
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);">
215 <?php if (!$obj) {
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>
221 </select>
222 <?php if ($obj) { ?>
223 <script>
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);
228 all_scores[6] = i;
229 </script><?php } ?>
230 </td>
231 </tr>
232 </table>
233 <table>
234 <tr>
235 <td>
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);">
238 <?php if (!$obj) {
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>
244 </select>
245 <?php if ($obj) { ?>
246 <script>
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);
251 all_scores[7] = i;
252 </script><?php } ?>
253 </td>
254 </tr>
255 </table>
256 <table>
257 <tr>
258 <td>
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);">
261 <?php if (!$obj) {
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>
267 </select>
268 <?php if ($obj) { ?>
269 <script>
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);
274 all_scores[8] = i;
275 </script><?php } ?>
276 </td>
277 </tr>
278 </table>
279 <table>
280 <tr>
281 <td>
282 <br>
283 <span id="q10_place" class="label"></span>
284 </td>
285 </tr>
286 </table>
288 <script>
289 function check_all() {
290 // has each question been answered and save scores
291 var flag = false;
292 var list = '';
293 for (i = 0; i < (no_qs - 1); i++) { // last questionis optional
294 if (!all_answered[i]) {
295 list = list + Number(i + 1) + ',';
296 flag = true;
299 if (flag) {
300 list[list.length - 1] = ' '; /* get rid of trailing comma */
301 alert(xl("Please answer all of the questions") + ": " + list + " " + xl("are unanswered"));
302 return false;
304 return true;
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); ?>);
311 if (conf) {
312 window.location.href = "<?php echo $GLOBALS['form_exit_url']; ?>";
314 return (conf);
316 </script>
317 <table>
318 <tr>
319 <td>
320 <hr />
321 <span id="show_phq9_score"><b><?php echo xlt("Total PHQ-9 score"); ?>:</b>
322 </td>
323 </tr>
324 </table>
325 <script>
326 manage_question_10 (<?php echo js_escape($obj["difficulty"]); ?>);
327 update_score("undef", phq9_score);
328 </script>
329 <table>
330 <tr>
331 <td>
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>
334 </td>
335 </tr>
336 </table>
337 </form>
338 </div>
339 <?php
340 formFooter();