Fix: Revert "Fix: OpenEMR logs sensitive information such as payment details (#7341...
[openemr.git] / interface / orders / qoe.inc.php
blob652fb2a37b4a1f32a05f8afe60a9f1fdfb0a4bff
1 <?php
3 /**
4 * Functions to support questions at order entry that are specific to order type.
6 * @package OpenEMR
7 * @link https://www.open-emr.org
8 * @author Rod Roark <rod@sunsetsystems.com>
9 * @author Jerry Padgett <sjpadgett@gmail.com>
10 * @author Brady Miller <brady.g.miller@gmail.com>
11 * @copyright Copyright (c) 2012 Rod Roark <rod@sunsetsystems.com>
12 * @copyright Copyright (c) 2018 Jerry Padgett <sjpadgett@gmail.com>
13 * @copyright Copyright (c) 2019 Brady Miller <brady.g.miller@gmail.com>
14 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
18 /**
19 * Generate HTML for the QOE form suitable for insertion into a <div>.
20 * This HTML may contain single quotes but not unescaped double quotes.
22 * @param integer $ptid Value matching a procedure_type_id in the procedure_types table.
23 * @param integer $orderid Procedure order ID, if there is an existing order.
24 * @param integer $dbseq Procedure order item sequence number, if there is an existing procedure.
25 * @param string $formseq Zero-relative occurrence number in the form.
26 * @return string The generated HTML.
28 function generate_qoe_html($ptid = 0, $orderid = 0, $dbseq = 0, $formseq = 0)
30 global $rootdir, $qoe_init_javascript;
32 $s = "";
33 $qoe_init_javascript = '';
34 $prefix = 'ans' . $formseq . '_';
36 if (empty($ptid)) {
37 return $s;
39 // container is div in form.
40 $s .= "<table class='table table-sm bg-light qoe-table'>";
42 // Get all the questions for the given procedure order type.
43 $qres = sqlStatement("SELECT " .
44 "q.question_code, q.question_text, q.options, q.required, q.maxsize, " .
45 "q.fldtype, q.tips " .
46 "FROM procedure_type AS t " .
47 "JOIN procedure_questions AS q ON q.lab_id = t.lab_id " .
48 "AND q.procedure_code = t.procedure_code AND q.activity = 1 " .
49 "WHERE t.procedure_type_id = ? " .
50 "ORDER BY q.seq, q.question_text", array($ptid));
52 while ($qrow = sqlFetchArray($qres)) {
53 $options = trim($qrow['options']);
54 $qfieldid = $prefix . trim($qrow['question_code']);
55 $fldtype = $qrow['fldtype'];
56 $maxsize = 0 + $qrow['maxsize'];
57 $qrow['tips'] = str_ireplace("^", " ", $qrow['tips']); // in case of HL7
59 // Get answer value(s) to this question, if any.
60 $answers = array();
61 if ($orderid && $dbseq > 0) {
62 $ares = sqlStatement("SELECT answer FROM procedure_answers WHERE " .
63 "procedure_order_id = ? AND procedure_order_seq = ? AND question_code = ? " .
64 "ORDER BY answer_seq", array($orderid, $dbseq, $qrow['question_code']));
65 while ($arow = sqlFetchArray($ares)) {
66 $answers[] = $arow['answer'];
70 $s .= "<tr>";
71 $s .= "<td valign='top'";
72 if ($qrow['required']) {
73 $s .= " style='color: #880000'"; // TBD: move to stylesheet
76 $s .= ">" . text($qrow['question_text']) . "</td>";
77 $s .= "<td valign='top'>";
79 if ($fldtype == 'T') {
80 // Text Field.
81 $s .= "<input class='input-sm' type='text' name='" . attr($qfieldid) . "'";
82 $s .= " maxlength='" . ($maxsize ? attr($maxsize) : 255) . "'";
83 if (!empty($answers)) {
84 $s .= " value='" . attr($answers[0]) . "'";
87 $s .= " title='" . attr($qrow['tips']) . "' placeholder='" . attr($qrow['tips']) . "' />";
88 } elseif ($fldtype == 'N') {
89 // Numeric text Field.
90 // TBD: Add some JavaScript validation for this.
91 $s .= "<input class='input-sm' type='text' name='" . attr($qfieldid) . "' maxlength='8'";
92 if (!empty($answers)) {
93 $s .= " value='" . attr($answers[0]) . "'";
96 $s .= " title='" . attr($qrow['tips']) . "' placeholder='" . attr($qrow['tips']) . "' />";
97 } elseif ($fldtype == 'D') {
98 // Date Field.
99 $s .= "<input type='text' name='" . attr($qfieldid) . "' id='" . attr($qfieldid) . "'";
100 if (!empty($answers)) {
101 $s .= " value='" . attr($answers[0]) . "'";
104 $s .= " class='datepicker input-sm' title='" . xla('Click here to choose a date') . "' />";
105 /* Legacy calendar removed to update to current calendar 07/20/2018 sjp */
106 } elseif ($fldtype == 'G') {
107 // Gestational age in weeks and days.
108 $currweeks = -1;
109 $currdays = -1;
110 if (!empty($answers)) {
111 $currweeks = intval($answers[0] / 7);
112 $currdays = $answers[0] % 7;
115 $s .= "<select class='input-sm' name='G1_" . attr($qfieldid) . "'>";
116 $s .= "<option value=''></option>";
117 for ($i = 5; $i <= 21; ++$i) {
118 $s .= "<option value='" . attr($i) . "'";
119 if ($i == $currweeks) {
120 $s .= " selected";
123 $s .= ">" . text($i) . "</option>";
126 $s .= "</select>";
127 $s .= " " . xlt('weeks') . " &nbsp;";
128 $s .= "<select class='input-sm' name='G2_" . attr($qfieldid) . "'>";
129 $s .= "<option value=''></option>";
130 for ($i = 0; $i <= 6; ++$i) {
131 $s .= "<option value='" . attr($i) . "'";
132 if ($i == $currdays) {
133 $s .= " selected";
136 $s .= ">" . text($i) . "</option>";
139 $s .= "</select>";
140 $s .= " " . xlt('days');
142 // Possible alternative code instead of radio buttons and checkboxes.
143 // Might use this for cases where the list of choices is large.
144 /*****************************************************************
145 else {
146 // Single- or multi-select list.
147 $multiple = false;
148 if (substr($options, 0, 2) == '+;') {
149 $multiple = true;
150 $options = substr($options, 2);
152 $s .= "<select name='$qfieldid'";
153 if ($multiple) $s .= " multiple";
154 $s .= ">";
155 $a = explode(';', $qrow['options']);
156 foreach ($a as $aval) {
157 list($desc, $code) = explode(':', $aval);
158 if (empty($code)) $code = $desc;
159 $s .= "<option value='" . attr($code) . "'";
160 if (in_array($code, $answers)) $s .= " selected";
161 $s .= ">" . text($desc) . "</option>";
163 $s .= "</select>";
165 *****************************************************************/
166 } elseif ($fldtype == 'M') {
167 // List of checkboxes.
168 $a = explode(';', $qrow['options']);
169 $i = 0;
170 foreach ($a as $aval) {
171 list($desc, $code) = explode(':', $aval);
172 if (empty($code)) {
173 $code = $desc;
176 if ($i) {
177 $s .= "<br />";
180 $s .= "<label class='radio-inline'><input class='input-sm' type='checkbox' name='" . attr($qfieldid[$i]) . "' value='" . attr($code) . "'";
181 if (in_array($code, $answers)) {
182 $s .= " checked";
185 $s .= " />" . text($desc) . "</label>";
186 ++$i;
188 } else {
189 // Radio buttons or drop-list, depending on the number of choices.
190 $a = explode(';', $qrow['options']);
191 if (count($a) > 5) {
192 $s .= "<select class='input-sm' name='" . attr($qfieldid) . "'";
193 $s .= ">";
194 foreach ($a as $aval) {
195 list($desc, $code) = explode(':', $aval);
196 if (empty($code)) {
197 $code = $desc;
200 $s .= "<option value='" . attr($code) . "'";
201 if (in_array($code, $answers)) {
202 $s .= " selected";
205 $s .= ">" . text($desc) . "</option>";
208 $s .= "</select>";
209 } else {
210 $i = 0;
211 foreach ($a as $aval) {
212 list($desc, $code) = explode(':', $aval);
213 if (empty($code)) {
214 $code = $desc;
215 if (empty($code)) {
216 $desc = "No Answer";
220 if ($i) {
221 $s .= "<br />";
224 $s .= "<label class='radio-inline'><input type='radio' name='" . attr($qfieldid) . "' value='" . attr($code) . "'";
225 if (in_array($code, $answers)) {
226 $s .= " checked";
229 $s .= " />" . text($desc) . "</label>";
230 ++$i;
235 $s .= '</td>';
236 $s .= '</tr>';
239 $s .= '</table>';
240 return $s;