Skip to content

Commit

Permalink
gad-7 form (openemr#4266)
Browse files Browse the repository at this point in the history
  • Loading branch information
ruthkonyn authored Apr 23, 2021
1 parent f071c67 commit 6552c4e
Show file tree
Hide file tree
Showing 8 changed files with 791 additions and 0 deletions.
35 changes: 35 additions & 0 deletions interface/forms/gad7/gad7.inc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

/**
* gad-7.inc - common includes and constants for the gad-7 form
* version 1.0.0 July 2020
*
* @package OpenEMR
* @link https://www.open-emr.org
* @author Ruth Moulton <moulton [email protected]>
* @copyright Copyright (c) 2021 ruth moulton <[email protected]>
*
* @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
*/

require_once("../../globals.php");
require_once("$srcdir/api.inc");

// menu strings
$str_default = xl('Please select an answer');
$str_not = xl('Not at all');
$str_several = xl('Several days');
$str_more = xl('More than half the days');
$str_nearly = xl('Nearly every day');
$str_somewhat = xl('Somewhat difficult');
$str_very = xl('Very difficult');
$str_extremely = xl('Extremely difficult');

$str_nosave_exit = xl("Close form without saving answers");
$str_nosave_confirm = xl("Are you sure you'd like to quit without saving your answers?");

$str_form_name = xl("General Anxiety Disorder 7 (GAD-7)");
$str_form_title = xl("GAD-7");

$str_q8 = xl('How difficult have these problems made it to do work, take care of things at home, or get along with other people?');
$str_q8_2 = '(' . xl('This question is optional and not included in the final score') . ') ';
123 changes: 123 additions & 0 deletions interface/forms/gad7/gad7_javasrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
// GAD-7 form
// @package OpenEMR
// @link https://www.open-emr.org
// @author ruth moulton
// @author Ruth Moulton <moulton [email protected]>
// @copyright Copyright (c) 2021 ruth moulton <[email protected]>
//
// java script routines, must be before any html lines that might trigger events.
// Keep the score and manage question 8 - which is only visible when score > 0

var no_qs = 8; // number of questions in the form

// php code isn't executed from an included js file, so put these in the calling file.
// 'cause the server side doesn't parse this file and execute the php before sending to client

var all_scores = [0,0,0,0,0,0,0,0];
var q8_gone = true; // if question 8 has been removed - or on startup when it's not displayed automatically
var question = null; //the element that holds the 8th question
var all_answered = [false, false, false, false, false, false, false];
var place = null; // where stuff should go on the form
var the_total_text = null; //where the total itself is displayed
var total_digits = null; //element to hold the displayed digits
var view_start = true; // edit is starting up, we need to read in the previous scores from DB
var str_score_analysis = [" " + xl("No anxiety disorder"), " " + xl("Mild anxiety disorder"), " " + xl("Severe anxiety disorder")];
/**
* manage question 8 - it is only be displayed when the score is not zero. It's answer is not
* included in the score.
* If necessary create and display question 8, needs to be done on startup or when score changes
* Default value of it's menu is either 'please select answer' or previous value selected
* If score has gone to zero then remove question 8 from the display if necessary
* @param int value - index of previous answer to question 8
* 'undef' (please select answer) if first time q8 being displayed
* @return undefined
*/
function manage_question_8 (value) {
if ((gad7_score > 0 ) && q8_gone){
question = document.createElement("small"); // create the node to hold question 8
question.class="text";
var menue = document.createElement("select"); // create 'select' element, to hold the menue
// set some of the parameters
menue.name = "difficulty";
menue.onchange = "record_score_q8(my_form.difficulty.value);" ;
menue.length=5;
create_q8 (question, menue); // populate question 8 and menue - do in main page as it requires php
// set the default value - if new it's 'select answer', else it's previous value
if (value == "undef") {menue.options[4].defaultSelected = true;}
// else we can use value as an index
else {menue.options[Number(value)].defaultSelected = true;}
// display the question and menue in the reservered place
place = document.getElementById("q8_place");
place.parentNode.appendChild( question, place);
place.parentNode.appendChild( menue, place);
q8_gone = false;
}
else if (gad7_score == 0 && !q8_gone) { //take question 8 off the displayed form
document.my_form.difficulty.remove();
question.remove();
q8_gone = true;
}
// nothing to do as
// score > 0 but the question is already there -
// or score == 0 and this is at startup
}

// function update_score - display new total score - check if question 8 should be displayed
// @param int index question being answered, is 'undef' if we simply want to display the score, e.g. on startup
// @param int new_score is 'undef' if it's from clicking 'please select an answer' in a new form - treat as zero.
// @return true|false
function update_score(index, new_score){ //index is the number of the question, score it's score
var score = new_score;
var explanation ='';
var total_string = '';

if (index == 'undef'){
// display score - called from view on startup - 'new_score' is previous total
gad7_score = score;
}

if (index != "undef"){
// replace score for each question - could just save it and add them all up again in a loop of course
if (score != 'undef'){
all_answered[index]=true;
}
else {
score = 0; /* for the purposes of calculating total - if question reset to 'please input..' */
all_answered[index]=false;
}
if (score != 'undef' ){ // undef is default value, i.e. no answer chosen - for new forms
gad7_score = gad7_score - Number(all_scores[index]);
all_scores[index] = Number (score);
gad7_score = gad7_score + Number(all_scores[index]) ;
}
}
// decide which explanatory string to dispay for the new score
if (gad7_score < 5 ) explanation = str_score_analysis[0];
else if (gad7_score <15) explanation = str_score_analysis[1];
else explanation = str_score_analysis[2];
// create string to be display - the score plus the explanation
total_string = gad7_score+" - "+explanation;
if (total_digits) {// replace previous total with new one
total_digits.innerText = total_string;
}
else{ //or create a visible total
total_digits = document.createElement("b");
the_total_text = document.createTextNode(total_string);
total_digits.appendChild(the_total_text);
exp = document.createElement("span");
exptext = document.createTextNode(explanation);
exp.appendChild(exptext);
place = document.getElementById("show_gad7_score");
place.parentNode.appendChild( total_digits, place);
}
//when the total is larger than zero if necessary create and display the 8th questions as well
// - else delete it from the display
manage_question_8("undef"); // if the question is regenerated then use the 'please select an answer' value
return true;
}
// record the answer to question 8
// the final question (index == 7) is not included in the sccore itself and is optional
function record_score_q8 (score) {
all_scores[7] = Number(score); // record the scores for a review/edit of the form
}

3 changes: 3 additions & 0 deletions interface/forms/gad7/info.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
GAD-7
Clinical

216 changes: 216 additions & 0 deletions interface/forms/gad7/new.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
<?php

/**
* gad-7 form using forms api new.php create a new form
*
* @package OpenEMR
* @link https://www.open-emr.org
* @author Ruth Moulton <moulton [email protected]>
* @copyright Copyright (c) 2021 ruth moulton <[email protected]>
*
* @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
*/

require_once("gad7.inc.php"); //common strings, require_once(globals.php), other includes etc

use OpenEMR\Common\Csrf\CsrfUtils; // security module
use OpenEMR\Core\Header;
?>
<html>
<head>
<title><?php echo text($string_form_title); ?> </title>
<?php Header::setupHeader(); ?>
</head>
<body class="body_top">

<script>
var no_qs = 8; // number of questions in the form
var gad7_score = 0; // total score
</script>

<SCRIPT
src="<?php echo $rootdir;?>/forms/gad7/gad7_javasrc.js">
</script>

<script>
// stuff that uses embedded php must go here, not in the include javascript file -
// it must be executed on server side before page is sent to client. included
// javascript is only executed on the client
function create_q8(question, menue){
// create the 8th question - the second part is italicised. Only displayed if score > 0
var text = document.createTextNode(jsAttr(<?php echo js_escape($str_q8); ?>));
question.appendChild(text);
var new_line = document.createElement("br"); // second part is in italics
var ital = document.createElement("i"); // second part is in italics
var question_2 = document.createTextNode(jsAttr(<?php echo js_escape($str_q8_2); ?>));
ital.appendChild(question_2);
question.name = "eighth";
question.appendChild(new_line);
question.appendChild(ital);
// populate the the menue
menue.options[0] = new Option ( <?php echo js_escape($str_not); ?>, "0");
menue.options[1] = new Option ( <?php echo js_escape($str_somewhat); ?>, "1");
menue.options[2] = new Option ( <?php echo js_escape($str_very); ?>, "2");
menue.options[3] = new Option ( <?php echo js_escape($str_extremely);?>, "3");
menue.options[4] = new Option ( <?php echo js_escape($str_default); ?>, "undef");
}
</script>
<form method=post action="<?php echo $rootdir;?>/forms/gad7/save.php?mode=new" name="my_form" onSubmit="return(check_all());" >
<input type="hidden" name="csrf_token_form" value="<?php echo attr(CsrfUtils::collectCsrfToken()); ?>" />
<br></br>
<span><font size=4><?php echo text($str_form_name); ?></font></span>
<br></br>
<input type="Submit" value="<?php echo xla('Save Form'); ?>" style="color: #483D8B" >
&nbsp &nbsp
<input type="button" value="<?php echo attr($str_nosave_exit);?>" onclick="top.restoreSession();return( nosave_exit());" style="color: #483D8B">
<br></br>
<span class="text"> <h2><?php echo xlt('How often have you been bothered by the following over the past 2 weeks?'); ?></h2> </span>
<table><tr>
<td>
<span class="text" ><?php echo xlt('Feeling nervous, anxious, or on edge'); ?></span>
<select name="nervous_score" onchange="update_score(0, my_form.nervous_score.value);">
<option selected value="undef"><?php echo text($str_default); ?></option>
<option value="0"><?php echo text($str_not); ?></option>
<option value="1"><?php echo text($str_several); ?></option>
<option value="2"><?php echo text($str_more); ?></option>
<option value="3"><?php echo text($str_nearly); ?></option>
</select>
<br>
</br>
</tr>
</table>
<table>
<tr>
<td>
<span class="text" ><?php echo xlt('Not being able to stop or control worrying'); ?></span>
<select name="control_worry_score" onchange="update_score(1, my_form.control_worry_score.value);" >
<option selected value="undef"><?php echo text($str_default); ?></option>
<option value="0"><?php echo text($str_not); ?></option>
<option value="1"><?php echo text($str_several); ?></option>
<option value="2"><?php echo text($str_more); ?></option>
<option value="3"><?php echo text($str_nearly); ?></option>
</select>
<br></br>
</tr>
</table>
<tr>
<td>
<table>
<span class=text ><?php echo xlt('Worrying too much about different things'); ?></span>
<select name="worry_score" onchange="update_score(2, my_form.worry_score.value);" >
<option selected value="undef" ><?php echo text($str_default); ?></option>
<option value="0"><?php echo text($str_not); ?></option>
<option value="1"><?php echo text($str_several); ?></option>
<option value="2"><?php echo text($str_more); ?></option>
<option value="3"><?php echo text($str_nearly); ?></option>
</select>
<br></br>
</tr>
</table>
<table>
<tr>
<td>
<span class="text" ><?php echo xlt('Trouble relaxing'); ?></span>
<select name="relax_score" onchange="update_score(3, my_form.relax_score.value);">
<option selected value="undef" ><?php echo text($str_default); ?></option>
<option value="0"><?php echo text($str_not); ?></option>
<option value="1"><?php echo text($str_several); ?></option>
<option value="2"><?php echo text($str_more); ?></option>
<option value="3"><?php echo text($str_nearly); ?></option>
</select>
<br></br>
</tr>
</table>
<table>
<tr>
<td>
<span class="text"><?php echo xlt('Being so restless that it\'s hard to sit still'); ?></span>
<select name="restless_score" onchange="update_score(4, my_form.restless_score.value);">
<option selected value="undef" ><?php echo text($str_default); ?></option>
<option value="0"><?php echo text($str_not); ?></option>
<option value="1"><?php echo text($str_several); ?></option>
<option value="2"><?php echo text($str_more); ?></option>
<option value="3"><?php echo text($str_nearly); ?></option>
</select>
<br></br>
</tr>
</table>
<table>
<tr>
<td>
<span class="text"><?php echo xlt('Becoming easily annoyed or irritable'); ?></span>
<select name="irritable_score" onchange="update_score(5, my_form.irritable_score.value);">
<option selected value="undef" ><?php echo text($str_default); ?></option>
<option value="0"><?php echo text($str_not); ?></option>
<option value="1"><?php echo text($str_several); ?></option>
<option value="2"><?php echo text($str_more); ?></option>
<option value="3"><?php echo text($str_nearly); ?></option>
</select>
<br></br>
</table>
</tr>
<table>
<tr>
<td>
<span class="text"><?php echo xlt('Feeling afraid as if something awful might happen'); ?></span>
<select name="fear_score" onchange="update_score(6, my_form.fear_score.value);">
<option selected value="undef" ><?php echo text($str_default); ?></option>
<option value="0"><?php echo text($str_not); ?></option>
<option value="1"><?php echo text($str_several); ?></option>
<option value="2"><?php echo text($str_more); ?></option>
<option value="3"><?php echo text($str_nearly); ?></option>
</select>
<br><br>
</tr>
</table>
<table frame = above>
<tr><td>
<span id="q8_place" class="text"><br></span>
</table>
<br></br>
<SCRIPT>
function check_all() {
// has each question been answered and save scores
var flag=false;
var list='';
for (i=0; i<(no_qs-1); i++) { // last questionis optional
if ( !all_answered[i] ){
list = list+Number(i+1) + ',';
flag=true;
}
}
if (flag) {
list[list.length-1] = ' '; /* get rid of trailing comma */
alert(xl("Please answer all of the questions") + ": " + list + " " + xl("are unanswered"));
return false;
}
return true;
}
// warn if about to exit without saving answers - check that's what the user really wants
function nosave_exit() {
var conf = confirm (<?php echo js_escape($str_nosave_confirm) ; ?>);

if (conf) {
window.location.href="<?php echo $GLOBALS['form_exit_url']; ?>";
}
return ( conf );
}
</script>
<table frame=hsides><tr><td>
<span id="show_gad7_score"><b><?php echo xlt("Total GAD-7 score"); ?>:</b> </td>
</table>
<script>
update_score("undef",gad7_score);
</script>
<br></br>
<table>
<tr><td>
<input type="Submit" value="<?php echo xla('Save Form'); ?>" style="color: #483D8B">
&nbsp &nbsp
<input type="button" value="<?php echo attr($str_nosave_exit); ?>" onclick="top.restoreSession();return(nosave_exit());" style="color: #483D8B">
<br><br>
</table>
</form>
<?php
formFooter();
?>
Loading

0 comments on commit 6552c4e

Please sign in to comment.