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