dump db version
[openemr.git] / interface / orders / qoe.inc.php
blob769fd37f760b64add114e09b9c35e9b98324e974
1 <?php
2 /**
3 * Functions to support questions at order entry that are specific to order type.
5 * Copyright (C) 2012 Rod Roark <rod@sunsetsystems.com>
7 * LICENSE: This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>.
18 * @package OpenEMR
19 * @author Rod Roark <rod@sunsetsystems.com>
20 * @author Jerry Padgett <sjpadgett@gmail.com>
22 // updated 07/20/2018 sjpadgett
23 /**
24 * Generate HTML for the QOE form suitable for insertion into a <div>.
25 * This HTML may contain single quotes but not unescaped double quotes.
27 * @param integer $ptid Value matching a procedure_type_id in the procedure_types table.
28 * @param integer $orderid Procedure order ID, if there is an existing order.
29 * @param integer $dbseq Procedure order item sequence number, if there is an existing procedure.
30 * @param string $formseq Zero-relative occurrence number in the form.
31 * @return string The generated HTML.
34 function generate_qoe_html($ptid = 0, $orderid = 0, $dbseq = 0, $formseq = 0)
36 global $rootdir, $qoe_init_javascript;
38 $s = "";
39 $qoe_init_javascript = '';
40 $prefix = 'ans' . $formseq . '_';
42 if (empty($ptid)) {
43 return $s;
45 // container is div in form.
46 $s .= "<table class='table table-condensed bg-light qoe-table'>";
48 // Get all the questions for the given procedure order type.
49 $qres = sqlStatement("SELECT " .
50 "q.question_code, q.question_text, q.options, q.required, q.maxsize, " .
51 "q.fldtype, q.tips " .
52 "FROM procedure_type AS t " .
53 "JOIN procedure_questions AS q ON q.lab_id = t.lab_id " .
54 "AND q.procedure_code = t.procedure_code AND q.activity = 1 " .
55 "WHERE t.procedure_type_id = ? " .
56 "ORDER BY q.seq, q.question_text", array($ptid));
58 while ($qrow = sqlFetchArray($qres)) {
59 $options = trim($qrow['options']);
60 $qfieldid = $prefix . attr(trim($qrow['question_code']));
61 $fldtype = $qrow['fldtype'];
62 $maxsize = 0 + $qrow['maxsize'];
63 $qrow['tips'] = text(str_ireplace("^", " ", $qrow['tips'])); // in case of HL7
65 // Get answer value(s) to this question, if any.
66 $answers = array();
67 if ($orderid && $dbseq > 0) {
68 $ares = sqlStatement("SELECT answer FROM procedure_answers WHERE " .
69 "procedure_order_id = ? AND procedure_order_seq = ? AND question_code = ? " .
70 "ORDER BY answer_seq", array($orderid, $dbseq, $qrow['question_code']));
71 while ($arow = sqlFetchArray($ares)) {
72 $answers[] = $arow['answer'];
76 $s .= "<tr>";
77 $s .= "<td valign='top'";
78 if ($qrow['required']) {
79 $s .= " style='color:#880000'"; // TBD: move to stylesheet
82 $s .= ">" . attr($qrow['question_text']) . "</td>";
83 $s .= "<td valign='top'>";
85 if ($fldtype == 'T') {
86 // Text Field.
87 $s .= "<input class='input-sm' type='text' name='$qfieldid'";
88 $s .= " maxlength='" . ($maxsize ? $maxsize : 255) . "'";
89 if (!empty($answers)) {
90 $s .= " value='" . attr($answers[0]) . "'";
93 $s .= " title='" . $qrow['tips'] . "' placeholder='" . $qrow['tips'] . "' />";
94 } else if ($fldtype == 'N') {
95 // Numeric text Field.
96 // TBD: Add some JavaScript validation for this.
97 $s .= "<input class='input-sm' type='text' name='$qfieldid' maxlength='8'";
98 if (!empty($answers)) {
99 $s .= " value='" . attr($answers[0]) . "'";
102 $s .= " title='" . $qrow['tips'] . "' placeholder='" . $qrow['tips'] . "' />";
103 } else if ($fldtype == 'D') {
104 // Date Field.
105 $s .= "<input type='text' name='$qfieldid' id='$qfieldid'";
106 if (!empty($answers)) {
107 $s .= " value='" . attr($answers[0]) . "'";
110 $s .= " class='datepicker input-sm' title='" . htmlspecialchars(xl('Click here to choose a date'), ENT_QUOTES) . "' />";
111 /* Legacy calendar removed to update to current calendar 07/20/2018 sjp */
112 } else if ($fldtype == 'G') {
113 // Gestational age in weeks and days.
114 $currweeks = -1;
115 $currdays = -1;
116 if (!empty($answers)) {
117 $currweeks = intval($answers[0] / 7);
118 $currdays = $answers[0] % 7;
121 $s .= "<select class='input-sm' name='G1_$qfieldid'>";
122 $s .= "<option value=''></option>";
123 for ($i = 5; $i <= 21; ++$i) {
124 $s .= "<option value='$i'";
125 if ($i == $currweeks) {
126 $s .= " selected";
129 $s .= ">$i</option>";
132 $s .= "</select>";
133 $s .= " " . xlt('weeks') . " &nbsp;";
134 $s .= "<select class='input-sm' name='G2_$qfieldid'>";
135 $s .= "<option value=''></option>";
136 for ($i = 0; $i <= 6; ++$i) {
137 $s .= "<option value='$i'";
138 if ($i == $currdays) {
139 $s .= " selected";
142 $s .= ">$i</option>";
145 $s .= "</select>";
146 $s .= " " . xlt('days');
147 } // Possible alternative code instead of radio buttons and checkboxes.
148 // Might use this for cases where the list of choices is large.
149 /*****************************************************************
150 else {
151 // Single- or multi-select list.
152 $multiple = false;
153 if (substr($options, 0, 2) == '+;') {
154 $multiple = true;
155 $options = substr($options, 2);
157 $s .= "<select name='$qfieldid'";
158 if ($multiple) $s .= " multiple";
159 $s .= ">";
160 $a = explode(';', $qrow['options']);
161 foreach ($a as $aval) {
162 list($desc, $code) = explode(':', $aval);
163 if (empty($code)) $code = $desc;
164 $s .= "<option value='" . attr($code) . "'";
165 if (in_array($code, $answers)) $s .= " selected";
166 $s .= ">" . text($desc) . "</option>";
168 $s .= "</select>";
170 *****************************************************************/
172 else if ($fldtype == 'M') {
173 // List of checkboxes.
174 $a = explode(';', $qrow['options']);
175 $i = 0;
176 foreach ($a as $aval) {
177 list($desc, $code) = explode(':', $aval);
178 if (empty($code)) {
179 $code = $desc;
182 if ($i) {
183 $s .= "<br />";
186 $s .= "<label class='radio-inline'><input class='input-sm' type='checkbox' name='$qfieldid[$i]' value='" . attr($code) . "'";
187 if (in_array($code, $answers)) {
188 $s .= " checked";
191 $s .= " />" . text($desc) . "</label>";
192 ++$i;
194 } else {
195 // Radio buttons or drop-list, depending on the number of choices.
196 $a = explode(';', $qrow['options']);
197 if (count($a) > 5) {
198 $s .= "<select class='input-sm' name='$qfieldid'";
199 $s .= ">";
200 foreach ($a as $aval) {
201 list($desc, $code) = explode(':', $aval);
202 if (empty($code)) {
203 $code = $desc;
206 $s .= "<option value='" . attr($code) . "'";
207 if (in_array($code, $answers)) {
208 $s .= " selected";
211 $s .= ">" . text($desc) . "</option>";
214 $s .= "</select>";
215 } else {
216 $i = 0;
217 foreach ($a as $aval) {
218 list($desc, $code) = explode(':', $aval);
219 if (empty($code)) {
220 $code = $desc;
221 if (empty($code)) {
222 $desc = "No Answer";
226 if ($i) {
227 $s .= "<br />";
230 $s .= "<label class='radio-inline'><input type='radio' name='$qfieldid' value='" . attr($code) . "'";
231 if (in_array($code, $answers)) {
232 $s .= " checked";
235 $s .= " />" . text($desc) . "</label>";
236 ++$i;
241 $s .= '</td>';
242 $s .= '</tr>';
245 $s .= '</table>';
246 return $s;