MU2 demographics - Aadd decline to specify to pertinent list and incorporate official...
[openemr.git] / interface / super / edit_list.php
blobb2ee332f4d55a76267faa2e6bf95b6e6a857f9df
1 <?php
2 /**
3 * Administration Lists Module.
5 * Copyright (C) 2007-2011 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 Brady Miller <brady@sparmy.com>
21 * @author Teny <teny@zhservices.com>
22 * @link http://www.open-emr.org
25 require_once("../globals.php");
26 require_once("$srcdir/acl.inc");
27 require_once("$srcdir/formdata.inc.php");
28 require_once("$srcdir/lists.inc");
29 require_once("../../custom/code_types.inc.php");
31 $list_id = empty($_REQUEST['list_id']) ? 'language' : $_REQUEST['list_id'];
33 // Check authorization.
34 $thisauth = acl_check('admin', 'super');
35 if (!$thisauth) die(xl('Not authorized'));
37 // If we are saving, then save.
39 if ($_POST['formaction']=='save' && $list_id) {
40 $opt = $_POST['opt'];
41 if ($list_id == 'feesheet') {
42 // special case for the feesheet list
43 sqlStatement("DELETE FROM fee_sheet_options");
44 for ($lino = 1; isset($opt["$lino"]['category']); ++$lino) {
45 $iter = $opt["$lino"];
46 $category = formTrim($iter['category']);
47 $option = formTrim($iter['option']);
48 $codes = formTrim($iter['codes']);
49 if (strlen($category) > 0 && strlen($option) > 0) {
50 sqlInsert("INSERT INTO fee_sheet_options ( " .
51 "fs_category, fs_option, fs_codes " .
52 ") VALUES ( " .
53 "'$category', " .
54 "'$option', " .
55 "'$codes' " .
56 ")");
60 else if ($list_id == 'code_types') {
61 // special case for code types
62 sqlStatement("DELETE FROM code_types");
63 for ($lino = 1; isset($opt["$lino"]['ct_key']); ++$lino) {
64 $iter = $opt["$lino"];
65 $ct_key = formTrim($iter['ct_key']);
66 $ct_id = formTrim($iter['ct_id']) + 0;
67 $ct_seq = formTrim($iter['ct_seq']) + 0;
68 $ct_mod = formTrim($iter['ct_mod']) + 0;
69 $ct_just = formTrim($iter['ct_just']);
70 $ct_mask = formTrim($iter['ct_mask']);
71 $ct_fee = empty($iter['ct_fee' ]) ? 0 : 1;
72 $ct_rel = empty($iter['ct_rel' ]) ? 0 : 1;
73 $ct_nofs = empty($iter['ct_nofs']) ? 0 : 1;
74 $ct_diag = empty($iter['ct_diag']) ? 0 : 1;
75 $ct_active = empty($iter['ct_active' ]) ? 0 : 1;
76 $ct_label = formTrim($iter['ct_label']);
77 $ct_external = formTrim($iter['ct_external']) + 0;
78 $ct_claim = empty($iter['ct_claim']) ? 0 : 1;
79 $ct_proc = empty($iter['ct_proc']) ? 0 : 1;
80 $ct_term = empty($iter['ct_term']) ? 0 : 1;
81 $ct_problem = empty($iter['ct_problem']) ? 0 : 1;
82 if (strlen($ct_key) > 0 && $ct_id > 0) {
83 sqlInsert("INSERT INTO code_types ( " .
84 "ct_key, ct_id, ct_seq, ct_mod, ct_just, ct_mask, ct_fee, ct_rel, ct_nofs, ct_diag, ct_active, ct_label, ct_external, ct_claim, ct_proc, ct_term, ct_problem " .
85 ") VALUES ( " .
86 "'$ct_key' , " .
87 "'$ct_id' , " .
88 "'$ct_seq' , " .
89 "'$ct_mod' , " .
90 "'$ct_just', " .
91 "'$ct_mask', " .
92 "'$ct_fee' , " .
93 "'$ct_rel' , " .
94 "'$ct_nofs', " .
95 "'$ct_diag', " .
96 "'$ct_active', " .
97 "'$ct_label', " .
98 "'$ct_external', " .
99 "'$ct_claim', " .
100 "'$ct_proc', " .
101 "'$ct_term', " .
102 "'$ct_problem' " .
103 ")");
107 else if ($list_id == 'issue_types') {
108 // special case for issue_types
109 sqlStatement("DELETE FROM issue_types");
110 for ($lino = 1; isset($opt["$lino"]['category']); ++$lino) {
111 $iter = $opt["$lino"];
112 $it_active = formTrim($iter['active']);
113 $it_category = formTrim($iter['category']);
114 $it_ordering = formTrim($iter['ordering']);
115 $it_type = formTrim($iter['type']);
116 $it_plural = formTrim($iter['plural']);
117 $it_singular = formTrim($iter['singular']);
118 $it_abbr = formTrim($iter['abbreviation']);
119 $it_style = formTrim($iter['style']);
120 $it_fshow = formTrim($iter['force_show']);
122 if ( (strlen($it_category) > 0) && (strlen($it_type) > 0) ) {
123 sqlInsert("INSERT INTO issue_types ( " .
124 "`active`,`category`,`ordering`, `type`, `plural`, `singular`, `abbreviation`, `style`, `force_show` " .
125 ") VALUES ( " .
126 "'$it_active' , " .
127 "'$it_category' , " .
128 "'$it_ordering' , " .
129 "'$it_type' , " .
130 "'$it_plural' , " .
131 "'$it_singular' , " .
132 "'$it_abbr' , " .
133 "'$it_style', " .
134 "'$it_fshow' " .
135 ")");
139 else {
140 // all other lists
142 // collect the option toggle if using the 'immunizations' list
143 if ($list_id == 'immunizations') {
144 $ok_map_cvx_codes = isset($_POST['ok_map_cvx_codes']) ? $_POST['ok_map_cvx_codes'] : 0;
146 // erase lists options and recreate them from the submitted form data
147 sqlStatement("DELETE FROM list_options WHERE list_id = '$list_id'");
148 for ($lino = 1; isset($opt["$lino"]['id']); ++$lino) {
149 $iter = $opt["$lino"];
150 $value = empty($iter['value']) ? 0 : (formTrim($iter['value']) + 0);
151 $id = formTrim($iter['id']);
152 if (strlen($id) > 0) {
154 // Special processing for the immunizations list
155 // Map the entered cvx codes into the immunizations table cvx_code
156 // Ensure the following conditions are met to do this:
157 // $list_id == 'immunizations'
158 // $value is an integer and greater than 0
159 // $id is set, not empty and not equal to 0
160 // (note that all these filters are important. Not allowing $id
161 // of zero here is extremely important; never remove this conditional
162 // or you risk corrupting your current immunizations database entries)
163 // $ok_map_cvx_codes is equal to 1
164 if ($list_id == 'immunizations' &&
165 is_int($value) &&
166 $value > 0 &&
167 isset($id) &&
168 !empty($id) &&
169 $id != 0 &&
170 $ok_map_cvx_codes == 1 ) {
171 sqlStatement ("UPDATE `immunizations` " .
172 "SET `cvx_code`='".$value."' " .
173 "WHERE `immunization_id`='".$id."'");
176 // Force List Based Form names to start with LBF.
177 if ($list_id == 'lbfnames' && substr($id,0,3) != 'LBF')
178 $id = "LBF$id";
180 // Insert the list item
181 sqlInsert("INSERT INTO list_options ( " .
182 "list_id, option_id, title, seq, is_default, option_value, mapping, notes, codes " .
183 ") VALUES ( " .
184 "'$list_id', " .
185 "'" . $id . "', " .
186 "'" . formTrim($iter['title']) . "', " .
187 "'" . formTrim($iter['seq']) . "', " .
188 "'" . formTrim($iter['default']) . "', " .
189 "'" . $value . "', " .
190 "'" . formTrim($iter['mapping']) . "', " .
191 "'" . formTrim($iter['notes']) . "', " .
192 "'" . formTrim($iter['codes']) . "' " .
193 ")");
198 else if ($_POST['formaction']=='addlist') {
199 // make a new list ID from the new list name
200 $newlistID = $_POST['newlistname'];
201 $newlistID = preg_replace("/\W/", "_", $newlistID);
203 // determine the position of this new list
204 $row = sqlQuery("SELECT max(seq) as maxseq FROM list_options WHERE list_id= 'lists'");
206 // add the new list to the list-of-lists
207 sqlInsert("INSERT INTO list_options ( " .
208 "list_id, option_id, title, seq, is_default, option_value " .
209 ") VALUES ( " .
210 "'lists',". // the master list-of-lists
211 "'".$newlistID."',".
212 "'".$_POST['newlistname']."', ".
213 "'".($row['maxseq']+1)."',".
214 "'1', '0')"
217 else if ($_POST['formaction']=='deletelist') {
218 // delete the lists options
219 sqlStatement("DELETE FROM list_options WHERE list_id = '".$_POST['list_id']."'");
220 // delete the list from the master list-of-lists
221 sqlStatement("DELETE FROM list_options WHERE list_id = 'lists' and option_id='".$_POST['list_id']."'");
224 $opt_line_no = 0;
226 // Given a string of multiple instances of code_type|code|selector,
227 // make a description for each.
228 // @TODO Instead should use a function from custom/code_types.inc.php and need to remove casing functions
229 function getCodeDescriptions($codes) {
230 global $code_types;
231 $arrcodes = explode('~', $codes);
232 $s = '';
233 foreach ($arrcodes as $codestring) {
234 if ($codestring === '') continue;
235 $arrcode = explode('|', $codestring);
236 $code_type = $arrcode[0];
237 $code = $arrcode[1];
238 $selector = $arrcode[2];
239 $desc = '';
240 if ($code_type == 'PROD') {
241 $row = sqlQuery("SELECT name FROM drugs WHERE drug_id = '$code' ");
242 $desc = "$code:$selector " . $row['name'];
244 else {
245 $row = sqlQuery("SELECT code_text FROM codes WHERE " .
246 "code_type = '" . $code_types[$code_type]['id'] . "' AND " .
247 "code = '$code' ORDER BY modifier LIMIT 1");
248 $desc = "$code_type:$code " . ucfirst(strtolower($row['code_text']));
250 $desc = str_replace('~', ' ', $desc);
251 if ($s) $s .= '~';
252 $s .= $desc;
254 return $s;
257 // Write one option line to the form.
259 function writeOptionLine($option_id, $title, $seq, $default, $value, $mapping='', $notes='', $codes='') {
260 global $opt_line_no, $list_id;
261 ++$opt_line_no;
262 $bgcolor = "#" . (($opt_line_no & 1) ? "ddddff" : "ffdddd");
263 $checked = $default ? " checked" : "";
265 echo " <tr bgcolor='$bgcolor'>\n";
267 echo " <td align='center' class='optcell'>";
268 echo "<input type='text' name='opt[$opt_line_no][id]' value='" .
269 htmlspecialchars($option_id, ENT_QUOTES) . "' size='12' maxlength='63' class='optin' />";
270 echo "</td>\n";
272 echo " <td align='center' class='optcell'>";
273 echo "<input type='text' name='opt[$opt_line_no][title]' value='" .
274 htmlspecialchars($title, ENT_QUOTES) . "' size='20' maxlength='63' class='optin' />";
275 echo "</td>\n";
277 // if not english and translating lists then show the translation
278 if ($GLOBALS['translate_lists'] && $_SESSION['language_choice'] > 1) {
279 echo " <td align='center' class='translation'>" . (htmlspecialchars( xl($title), ENT_QUOTES)) . "</td>\n";
282 echo " <td align='center' class='optcell'>";
283 echo "<input type='text' name='opt[$opt_line_no][seq]' value='" .
284 htmlspecialchars($seq, ENT_QUOTES) . "' size='4' maxlength='10' class='optin' />";
285 echo "</td>\n";
287 echo " <td align='center' class='optcell'>";
288 echo "<input type='checkbox' name='opt[$opt_line_no][default]' value='1' " .
289 "onclick='defClicked($opt_line_no)' class='optin'$checked />";
290 echo "</td>\n";
292 // Tax rates, contraceptive methods and LBF names have an additional attribute.
294 if ($list_id == 'taxrate' || $list_id == 'contrameth' || $list_id == 'lbfnames') {
295 echo " <td align='center' class='optcell'>";
296 echo "<input type='text' name='opt[$opt_line_no][value]' value='" .
297 htmlspecialchars($value, ENT_QUOTES) . "' size='8' maxlength='15' class='optin' />";
298 echo "</td>\n";
301 // Adjustment reasons use option_value as a reason category. This is
302 // needed to distinguish between adjustments that change the invoice
303 // balance and those that just shift responsibility of payment or
304 // are used as comments.
306 else if ($list_id == 'adjreason') {
307 echo " <td align='center' class='optcell'>";
308 echo "<select name='opt[$opt_line_no][value]' class='optin'>";
309 foreach (array(
310 1 => xl('Charge adjustment'),
311 2 => xl('Coinsurance'),
312 3 => xl('Deductible'),
313 4 => xl('Other pt resp'),
314 5 => xl('Comment'),
315 ) as $key => $desc) {
316 echo "<option value='$key'";
317 if ($key == $value) echo " selected";
318 echo ">" . htmlspecialchars($desc) . "</option>";
320 echo "</select>";
321 echo "</td>\n";
324 // Address book categories use option_value to flag category as a
325 // person-centric vs company-centric vs indifferent.
327 else if ($list_id == 'abook_type') {
328 echo " <td align='center' class='optcell'>";
329 echo "<select name='opt[$opt_line_no][value]' class='optin'>";
330 foreach (array(
331 1 => xl('Unassigned'),
332 2 => xl('Person'),
333 3 => xl('Company'),
334 ) as $key => $desc) {
335 echo "<option value='$key'";
336 if ($key == $value) echo " selected";
337 echo ">" . htmlspecialchars($desc) . "</option>";
339 echo "</select>";
340 echo "</td>\n";
343 // Immunization categories use option_value to map list items
344 // to CVX codes.
346 else if ($list_id == 'immunizations') {
347 echo " <td align='center' class='optcell'>";
348 echo "<input type='text' size='10' name='opt[$opt_line_no][value]' " .
349 "value='" . htmlspecialchars($value,ENT_QUOTES) . "' onclick='sel_cvxcode(this)' " .
350 "title='" . htmlspecialchars( xl('Click to select or change CVX code'), ENT_QUOTES) . "'/>";
351 echo "</td>\n";
354 // IPPF includes the ability to map each list item to a "master" identifier.
355 // Sports teams use this for some extra info for fitness levels.
357 if ($GLOBALS['ippf_specific'] || $list_id == 'fitness') {
358 echo " <td align='center' class='optcell'>";
359 echo "<input type='text' name='opt[$opt_line_no][mapping]' value='" .
360 htmlspecialchars($mapping, ENT_QUOTES) . "' size='12' maxlength='15' class='optin' />";
361 echo "</td>\n";
364 echo " <td align='center' class='optcell'>";
365 echo "<input type='text' name='opt[$opt_line_no][notes]' value='" .
366 htmlspecialchars($notes, ENT_QUOTES) . "' size='25' maxlength='255' class='optin' />";
367 echo "</td>\n";
369 echo " <td align='center' class='optcell'>";
370 echo "<input type='text' name='opt[$opt_line_no][codes]' title='" .
371 xla('Clinical Term Code(s)') ."' value='" .
372 htmlspecialchars($codes, ENT_QUOTES) . "' onclick='select_clin_term_code(this)' size='25' maxlength='255' class='optin' />";
373 echo "</td>\n";
375 echo " </tr>\n";
378 // Write a form line as above but for the special case of the Fee Sheet.
380 function writeFSLine($category, $option, $codes) {
381 global $opt_line_no;
383 ++$opt_line_no;
384 $bgcolor = "#" . (($opt_line_no & 1) ? "ddddff" : "ffdddd");
386 $descs = getCodeDescriptions($codes);
388 echo " <tr bgcolor='$bgcolor'>\n";
390 echo " <td align='center' class='optcell'>";
391 echo "<input type='text' name='opt[$opt_line_no][category]' value='" .
392 htmlspecialchars($category, ENT_QUOTES) . "' size='20' maxlength='63' class='optin' />";
393 echo "</td>\n";
395 echo " <td align='center' class='optcell'>";
396 echo "<input type='text' name='opt[$opt_line_no][option]' value='" .
397 htmlspecialchars($option, ENT_QUOTES) . "' size='20' maxlength='63' class='optin' />";
398 echo "</td>\n";
400 echo " <td align='left' class='optcell'>";
401 echo " <div id='codelist_$opt_line_no'>";
402 if (strlen($descs)) {
403 $arrdescs = explode('~', $descs);
404 $i = 0;
405 foreach ($arrdescs as $desc) {
406 echo "<a href='' onclick='return delete_code($opt_line_no,$i)' title='" . xl('Delete') . "'>";
407 echo "[x]&nbsp;</a>$desc<br />";
408 ++$i;
411 echo "</div>";
412 echo "<a href='' onclick='return select_code($opt_line_no)'>";
413 echo "[" . xl('Add') . "]</a>";
415 echo "<input type='hidden' name='opt[$opt_line_no][codes]' value='" .
416 htmlspecialchars($codes, ENT_QUOTES) . "' />";
417 echo "<input type='hidden' name='opt[$opt_line_no][descs]' value='" .
418 htmlspecialchars($descs, ENT_QUOTES) . "' />";
419 echo "</td>\n";
421 echo " </tr>\n";
426 * Helper functions for writeITLine() and writeCTLine().
428 function ctGenCell($opt_line_no, $data_array, $name, $size, $maxlength, $title='') {
429 $value = isset($data_array[$name]) ? $data_array[$name] : '';
430 $s = " <td align='center' class='optcell'";
431 if ($title) $s .= " title='" . attr($title) . "'";
432 $s .= ">";
433 $s .= "<input type='text' name='opt[$opt_line_no][$name]' value='";
434 $s .= attr($value);
435 $s .= "' size='$size' maxlength='$maxlength' class='optin' />";
436 $s .= "</td>\n";
437 return $s;
440 function ctGenCbox($opt_line_no, $data_array, $name, $title='') {
441 $checked = empty($data_array[$name]) ? '' : 'checked ';
442 $s = " <td align='center' class='optcell'";
443 if ($title) $s .= " title='" . attr($title) . "'";
444 $s .= ">";
445 $s .= "<input type='checkbox' name='opt[$opt_line_no][$name]' value='1' ";
446 $s .= "$checked/>";
447 $s .= "</td>\n";
448 return $s;
451 function ctSelector($opt_line_no, $data_array, $name, $option_array, $title='') {
452 $value = isset($data_array[$name]) ? $data_array[$name] : '';
453 $s = " <td title='" . attr($title) . "' align='center' class='optcell'>";
454 $s .= "<select name='opt[$opt_line_no][$name]' class='optin'>";
455 foreach ( $option_array as $key => $desc) {
456 $s .= "<option value='" . attr($key) . "'";
457 if ($key == $value) $s .= " selected";
458 $s .= ">" . text($desc) . "</option>";
460 $s .= "</select>";
461 $s .= "</td>\n";
462 return $s;
465 // Write a form line as above but for the special case of Code Types.
467 function writeCTLine($ct_array) {
468 global $opt_line_no,$cd_external_options;
470 ++$opt_line_no;
471 $bgcolor = "#" . (($opt_line_no & 1) ? "ddddff" : "ffdddd");
473 echo " <tr bgcolor='$bgcolor'>\n";
475 echo ctGenCBox($opt_line_no, $ct_array, 'ct_active',
476 xl('Is this code type active?'));
477 echo ctGenCell($opt_line_no, $ct_array, 'ct_key' , 6, 15,
478 xl('Unique human-readable identifier for this type'));
479 echo ctGenCell($opt_line_no, $ct_array, 'ct_id' , 2, 11,
480 xl('Unique numeric identifier for this type'));
481 echo ctGenCell($opt_line_no, $ct_array, 'ct_label' , 6, 30,
482 xl('Label for this type'));
483 // if not english and translating lists then show the translation
484 if ($GLOBALS['translate_lists'] && $_SESSION['language_choice'] > 1) {
485 echo " <td align='center' class='translation'>" . xlt($ct_array['ct_label']) . "</td>\n";
487 echo ctGenCell($opt_line_no, $ct_array, 'ct_seq' , 2, 3,
488 xl('Numeric display order'));
489 echo ctGenCell($opt_line_no, $ct_array, 'ct_mod' , 1, 2,
490 xl('Length of modifier, 0 if none'));
491 echo ctGenCell($opt_line_no, $ct_array, 'ct_just', 4, 15,
492 xl('If billing justification is used enter the name of the diagnosis code type.'));
493 echo ctGenCell($opt_line_no, $ct_array, 'ct_mask', 6, 9,
494 xl('Specifies formatting for codes. # = digit, @ = alpha, * = any character. Empty if not used.'));
495 echo ctGenCBox($opt_line_no, $ct_array, 'ct_claim',
496 xl('Is this code type used in claims?'));
497 echo ctGenCBox($opt_line_no, $ct_array, 'ct_fee',
498 xl('Are fees charged for this type?'));
499 echo ctGenCBox($opt_line_no, $ct_array, 'ct_rel',
500 xl('Does this type allow related codes?'));
501 echo ctGenCBox($opt_line_no, $ct_array, 'ct_nofs',
502 xl('Is this type hidden in the fee sheet?'));
503 echo ctGenCBox($opt_line_no, $ct_array, 'ct_proc',
504 xl('Is this a procedure/service type?'));
505 echo ctGenCBox($opt_line_no, $ct_array, 'ct_diag',
506 xl('Is this a diagnosis type?'));
507 echo ctGenCBox($opt_line_no, $ct_array, 'ct_term',
508 xl('Is this a Clinical Term code type?'));
509 echo ctGenCBox($opt_line_no, $ct_array, 'ct_problem',
510 xl('Is this a Medical Problem code type?'));
511 echo ctSelector($opt_line_no, $ct_array, 'ct_external',
512 $cd_external_options, xl('Is this using external sql tables? If it is, then choose the format.'));
513 echo " </tr>\n";
517 * Special case of Issue Types
519 function writeITLine($it_array) {
520 global $opt_line_no,$ISSUE_TYPE_CATEGORIES,$ISSUE_TYPE_STYLES;
521 ++$opt_line_no;
522 $bgcolor = "#" . (($opt_line_no & 1) ? "ddddff" : "ffdddd");
523 echo " <tr bgcolor='$bgcolor'>\n";
524 echo ctSelector($opt_line_no, $it_array, 'category', $ISSUE_TYPE_CATEGORIES, xl('OpenEMR Application Category'));
525 echo ctGenCBox($opt_line_no, $it_array, 'active', xl('Is this active?'));
526 echo ctGenCell($opt_line_no, $it_array, 'ordering' , 10, 10, xl('Order'));
527 echo ctGenCell($opt_line_no, $it_array, 'type' , 20, 75, xl('Issue Type'));
528 echo ctGenCell($opt_line_no, $it_array, 'plural' , 20, 75, xl('Plural'));
529 // if not english and translating lists then show the translation
530 if ($GLOBALS['translate_lists'] && $_SESSION['language_choice'] > 1) {
531 echo " <td align='center' class='translation'>" . xlt($it_array['plural']) . "</td>\n";
533 echo ctGenCell($opt_line_no, $it_array, 'singular' , 20, 75, xl('Singular'));
534 // if not english and translating lists then show the translation
535 if ($GLOBALS['translate_lists'] && $_SESSION['language_choice'] > 1) {
536 echo " <td align='center' class='translation'>" . xlt($it_array['singular']) . "</td>\n";
538 echo ctGenCell($opt_line_no, $it_array, 'abbreviation' , 10, 10, xl('Abbreviation'));
539 // if not english and translating lists then show the translation
540 if ($GLOBALS['translate_lists'] && $_SESSION['language_choice'] > 1) {
541 echo " <td align='center' class='translation'>" . xlt($it_array['abbreviation']) . "</td>\n";
543 echo ctSelector($opt_line_no, $it_array, 'style', $ISSUE_TYPE_STYLES, xl('Standard; Simplified: only title, start date, comments and an Active checkbox;no diagnosis, occurrence, end date, referred-by or sports fields. ; Football Injury'));
544 echo ctGenCBox($opt_line_no, $it_array, 'force_show', xl('Show this category on the patient summary screen even if no issues have been entered for this category.'));
545 echo " </tr>\n";
549 <html>
551 <head>
552 <?php html_header_show();?>
554 <!-- supporting javascript code -->
555 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/jquery.js"></script>
557 <link rel="stylesheet" href='<?php echo $css_header ?>' type='text/css'>
558 <title><?php xl('List Editor','e'); ?></title>
560 <style>
561 tr.head { font-size:10pt; background-color:#cccccc; text-align:center; }
562 tr.detail { font-size:10pt; }
563 td { font-size:10pt; }
564 input { font-size:10pt; }
565 a, a:visited, a:hover { color:#0000cc; }
566 .optcell { }
567 .optin { background-color:transparent; }
568 .help { cursor:help; }
569 .translation { color:green; }
570 </style>
572 <script type="text/javascript" src="../../library/dialog.js"></script>
574 <script language="JavaScript">
576 var current_lino = 0;
578 // Helper function to set the contents of a div.
579 // This is for Fee Sheet administration.
580 function setDivContent(id, content) {
581 if (document.getElementById) {
582 var x = document.getElementById(id);
583 x.innerHTML = '';
584 x.innerHTML = content;
586 else if (document.all) {
587 var x = document.all[id];
588 x.innerHTML = content;
592 // Given a line number, redisplay its descriptive list of codes.
593 // This is for Fee Sheet administration.
594 function displayCodes(lino) {
595 var f = document.forms[0];
596 var s = '';
597 var descs = f['opt[' + lino + '][descs]'].value;
598 if (descs.length) {
599 var arrdescs = descs.split('~');
600 for (var i = 0; i < arrdescs.length; ++i) {
601 s += "<a href='' onclick='return delete_code(" + lino + "," + i + ")' title='<?php xl('Delete','e'); ?>'>";
602 s += "[x]&nbsp;</a>" + arrdescs[i] + "<br />";
605 setDivContent('codelist_' + lino, s);
608 // Helper function to remove a Fee Sheet code.
609 function dc_substring(s, i) {
610 var r = '';
611 var j = s.indexOf('~', i);
612 if (j < 0) { // deleting last segment
613 if (i > 0) r = s.substring(0, i-1); // omits trailing ~
615 else { // not last segment
616 r = s.substring(0, i) + s.substring(j + 1);
618 return r;
621 // Remove a generated Fee Sheet code.
622 function delete_code(lino, seqno) {
623 var f = document.forms[0];
624 var celem = f['opt[' + lino + '][codes]'];
625 var delem = f['opt[' + lino + '][descs]'];
626 var ci = 0;
627 var di = 0;
628 for (var i = 0; i < seqno; ++i) {
629 ci = celem.value.indexOf('~', ci) + 1;
630 di = delem.value.indexOf('~', di) + 1;
632 celem.value = dc_substring(celem.value, ci);
633 delem.value = dc_substring(delem.value, di);
634 displayCodes(lino);
635 return false;
638 // This invokes the find-code popup.
639 // For Fee Sheet administration.
640 function select_code(lino) {
641 current_lino = lino;
642 dlgopen('../patient_file/encounter/find_code_popup.php', '_blank', 700, 400);
643 return false;
646 // This invokes the find-code popup.
647 // For CVX/immunization code administration.
648 function sel_cvxcode(e) {
649 current_sel_name = e.name;
650 dlgopen('../patient_file/encounter/find_code_popup.php?codetype=CVX', '_blank', 500, 400);
653 // This invokes the find-code popup.
654 // For CVX/immunization code administration.
655 function select_clin_term_code(e) {
656 current_sel_clin_term = e.name;
657 dlgopen('../patient_file/encounter/find_code_popup.php?codetype=<?php echo attr(collect_codetypes("clinical_term","csv")) ?>', '_blank', 500, 400);
660 // This is for callback by the find-code popup.
661 function set_related(codetype, code, selector, codedesc) {
662 if (typeof(current_sel_name) == 'undefined' && typeof(current_sel_clin_term) == 'undefined')
664 // Coming from Fee Sheet edit
665 var f = document.forms[0];
666 var celem = f['opt[' + current_lino + '][codes]'];
667 var delem = f['opt[' + current_lino + '][descs]'];
668 var i = 0;
669 while ((i = codedesc.indexOf('~')) >= 0) {
670 codedesc = codedesc.substring(0, i) + ' ' + codedesc.substring(i+1);
672 if (code) {
673 if (celem.value) {
674 celem.value += '~';
675 delem.value += '~';
677 celem.value += codetype + '|' + code + '|' + selector;
678 if (codetype == 'PROD') delem.value += code + ':' + selector + ' ' + codedesc;
679 else delem.value += codetype + ':' + code + ' ' + codedesc;
680 } else {
681 celem.value = '';
682 delem.value = '';
684 displayCodes(current_lino);
686 else if (typeof(current_sel_name) == 'undefined') {
687 // Coming from the Clinical Terms Code(s) edit
688 var f = document.forms[0][current_sel_clin_term];
689 var s = f.value;
690 if (code) {
691 if (s.length > 0) s += ';';
692 s += codetype + ':' + code;
694 else {
695 s = '';
697 f.value = s;
699 else {
700 // Coming from Immunizations edit
701 var f = document.forms[0][current_sel_name];
702 var s = f.value;
703 if (code) {
704 s = code;
706 else {
707 s = '0';
709 f.value = s;
713 // Called when a "default" checkbox is clicked. Clears all the others.
714 function defClicked(lino) {
715 var f = document.forms[0];
716 for (var i = 1; f['opt[' + i + '][default]']; ++i) {
717 if (i != lino) f['opt[' + i + '][default]'].checked = false;
721 // Form validation and submission.
722 // This needs more validation.
723 function mysubmit() {
724 var f = document.forms[0];
725 if (f.list_id.value == 'code_types') {
726 for (var i = 1; f['opt[' + i + '][ct_key]'].value; ++i) {
727 var ikey = 'opt[' + i + ']';
728 for (var j = i+1; f['opt[' + j + '][ct_key]'].value; ++j) {
729 var jkey = 'opt[' + j + ']';
730 if (f[ikey+'[ct_key]'].value == f[jkey+'[ct_key]'].value) {
731 alert('<?php echo xl('Error: duplicated name on line') ?>' + ' ' + j);
732 return;
734 if (parseInt(f[ikey+'[ct_id]'].value) == parseInt(f[jkey+'[ct_id]'].value)) {
735 alert('<?php echo xl('Error: duplicated ID on line') ?>' + ' ' + j);
736 return;
741 f.submit();
744 </script>
746 </head>
748 <body class="body_top">
750 <form method='post' name='theform' id='theform' action='edit_list.php'>
751 <input type="hidden" name="formaction" id="formaction">
753 <p><b><?php xl('Edit list','e'); ?>:</b>&nbsp;
754 <select name='list_id' id="list_id">
755 <?php
757 // List order depends on language translation options.
758 $lang_id = empty($_SESSION['language_choice']) ? '1' : $_SESSION['language_choice'];
760 if (($lang_id == '1' && !empty($GLOBALS['skip_english_translation'])) ||
761 !$GLOBALS['translate_lists'])
763 $res = sqlStatement("SELECT option_id, title FROM list_options WHERE " .
764 "list_id = 'lists' ORDER BY title, seq");
766 else {
767 // Use and sort by the translated list name.
768 $res = sqlStatement("SELECT lo.option_id, " .
769 "IF(LENGTH(ld.definition),ld.definition,lo.title) AS title " .
770 "FROM list_options AS lo " .
771 "LEFT JOIN lang_constants AS lc ON lc.constant_name = lo.title " .
772 "LEFT JOIN lang_definitions AS ld ON ld.cons_id = lc.cons_id AND " .
773 "ld.lang_id = '$lang_id' " .
774 "WHERE lo.list_id = 'lists' " .
775 "ORDER BY IF(LENGTH(ld.definition),ld.definition,lo.title), lo.seq");
778 while ($row = sqlFetchArray($res)) {
779 $key = $row['option_id'];
780 echo "<option value='$key'";
781 if ($key == $list_id) echo " selected";
782 echo ">" . $row['title'] . "</option>\n";
786 </select>
787 <input type="button" id="<?php echo $list_id; ?>" class="deletelist" value=<?php xl('Delete List','e','\'','\''); ?>>
788 <input type="button" id="newlist" class="newlist" value=<?php xl('New List','e','\'','\''); ?>>
789 </p>
791 <center>
793 <table cellpadding='2' cellspacing='0'>
794 <tr class='head'>
795 <?php if ($list_id == 'feesheet') { ?>
796 <td><b><?php xl('Group' ,'e'); ?></b></td>
797 <td><b><?php xl('Option' ,'e'); ?></b></td>
798 <td><b><?php xl('Generates','e'); ?></b></td>
799 <?php } else if ($list_id == 'code_types') { ?>
800 <td><b><?php xl('Active' ,'e'); ?></b></td>
801 <td><b><?php xl('Key' ,'e'); ?></b></td>
802 <td><b><?php xl('ID' ,'e'); ?></b></td>
803 <td><b><?php xl('Label' ,'e'); ?></b></td>
804 <?php //show translation column if not english and the translation lists flag is set
805 if ($GLOBALS['translate_lists'] && $_SESSION['language_choice'] > 1) {
806 echo "<td><b>".xl('Translation')."</b><span class='help' title='".xl('The translated Title that will appear in current language')."'> (?)</span></td>";
807 } ?>
808 <td><b><?php xl('Seq' ,'e'); ?></b></td>
809 <td><b><?php xl('ModLength' ,'e'); ?></b></td>
810 <td><b><?php xl('Justify' ,'e'); ?></b></td>
811 <td><b><?php xl('Mask' ,'e'); ?></b></td>
812 <td><b><?php xl('Claims' ,'e'); ?></b></td>
813 <td><b><?php xl('Fees' ,'e'); ?></b></td>
814 <td><b><?php xl('Relations' ,'e'); ?></b></td>
815 <td><b><?php xl('Hide' ,'e'); ?></b></td>
816 <td><b><?php xl('Procedure' ,'e'); ?></b></td>
817 <td><b><?php xl('Diagnosis' ,'e'); ?></b></td>
818 <td><b><?php xl('Clinical Term','e'); ?></b></td>
819 <td><b><?php xl('Medical Problem' ,'e'); ?></b></td>
820 <td><b><?php xl('External' ,'e'); ?></b></td>
821 <?php } else if ($list_id == 'issue_types') { ?>
822 <td><b><?php echo xlt('OpenEMR Application Category'); ?></b></td>
823 <td><b><?php echo xlt('Active'); ?></b></td>
824 <td><b><?php echo xlt('Order'); ?></b></td>
825 <td><b><?php echo xlt('Type'); ?></b></td>
826 <td><b><?php echo xlt('Plural'); ?></b></td>
827 <?php //show translation column if not english and the translation lists flag is set
828 if ($GLOBALS['translate_lists'] && $_SESSION['language_choice'] > 1) {
829 echo "<td><b>".xl('Translation')."</b><span class='help' title='".xl('The translated Title that will appear in current language')."'> (?)</span></td>";
830 } ?>
831 <td><b><?php echo xlt('Singular'); ?></b></td>
832 <?php //show translation column if not english and the translation lists flag is set
833 if ($GLOBALS['translate_lists'] && $_SESSION['language_choice'] > 1) {
834 echo "<td><b>".xl('Translation')."</b><span class='help' title='".xl('The translated Title that will appear in current language')."'> (?)</span></td>";
835 } ?>
836 <td><b><?php echo xlt('Abbreviation'); ?></b></td>
837 <?php //show translation column if not english and the translation lists flag is set
838 if ($GLOBALS['translate_lists'] && $_SESSION['language_choice'] > 1) {
839 echo "<td><b>".xl('Translation')."</b><span class='help' title='".xl('The translated Title that will appear in current language')."'> (?)</span></td>";
840 } ?>
841 <td><b><?php echo xlt('Style'); ?></b></td>
842 <td><b><?php echo xlt('Force Show'); ?></b></td>
843 <?php } else { ?>
844 <td title=<?php xl('Click to edit','e','\'','\''); ?>><b><?php xl('ID','e'); ?></b></td>
845 <td><b><?php xl('Title' ,'e'); ?></b></td>
846 <?php //show translation column if not english and the translation lists flag is set
847 if ($GLOBALS['translate_lists'] && $_SESSION['language_choice'] > 1) {
848 echo "<td><b>".xl('Translation')."</b><span class='help' title='".xl('The translated Title that will appear in current language')."'> (?)</span></td>";
849 } ?>
850 <td><b><?php xl('Order' ,'e'); ?></b></td>
851 <td><b><?php xl('Default','e'); ?></b></td>
852 <?php if ($list_id == 'taxrate') { ?>
853 <td><b><?php xl('Rate' ,'e'); ?></b></td>
854 <?php } else if ($list_id == 'contrameth') { ?>
855 <td><b><?php xl('Effectiveness','e'); ?></b></td>
856 <?php } else if ($list_id == 'lbfnames') { ?>
857 <td title='<?php xl('Number of past history columns','e'); ?>'><b><?php xl('Repeats','e'); ?></b></td>
858 <?php } else if ($list_id == 'fitness') { ?>
859 <td><b><?php xl('Color:Abbr','e'); ?></b></td>
860 <?php } else if ($list_id == 'adjreason' || $list_id == 'abook_type') { ?>
861 <td><b><?php xl('Type','e'); ?></b></td>
862 <?php } else if ($list_id == 'immunizations') { ?>
863 <td><b>&nbsp;&nbsp;&nbsp;&nbsp;<?php xl('CVX Code Mapping','e'); ?></b></td>
864 <?php } if ($GLOBALS['ippf_specific']) { ?>
865 <td><b><?php xl('Global ID','e'); ?></b></td>
866 <?php } ?>
867 <td><b><?php
868 if ($list_id == 'language') {
869 xl('ISO 639-2 Code','e');
870 } else {
871 xl('Notes','e');
873 ?></b></td>
874 <td><b><?php xl('Code(s)','e'); ?></b></td>
875 <?php } // end not fee sheet ?>
876 </tr>
878 <?php
879 // Get the selected list's elements.
880 if ($list_id) {
881 if ($list_id == 'feesheet') {
882 $res = sqlStatement("SELECT * FROM fee_sheet_options " .
883 "ORDER BY fs_category, fs_option");
884 while ($row = sqlFetchArray($res)) {
885 writeFSLine($row['fs_category'], $row['fs_option'], $row['fs_codes']);
887 for ($i = 0; $i < 3; ++$i) {
888 writeFSLine('', '', '');
891 else if ($list_id == 'code_types') {
892 $res = sqlStatement("SELECT * FROM code_types " .
893 "ORDER BY ct_seq, ct_key");
894 while ($row = sqlFetchArray($res)) {
895 writeCTLine($row);
897 for ($i = 0; $i < 3; ++$i) {
898 writeCTLine(array());
901 else if ($list_id == 'issue_types') {
902 $res = sqlStatement("SELECT * FROM issue_types " .
903 "ORDER BY category, ordering ASC");
904 while ($row = sqlFetchArray($res)) {
905 writeITLine($row);
907 for ($i = 0; $i < 3; ++$i) {
908 writeITLine(array());
911 else {
912 $res = sqlStatement("SELECT * FROM list_options WHERE " .
913 "list_id = '$list_id' ORDER BY seq,title");
914 while ($row = sqlFetchArray($res)) {
915 writeOptionLine($row['option_id'], $row['title'], $row['seq'],
916 $row['is_default'], $row['option_value'], $row['mapping'],
917 $row['notes'],$row['codes']);
919 for ($i = 0; $i < 3; ++$i) {
920 writeOptionLine('', '', '', '', 0);
926 </table>
928 <?php if ($list_id == 'immunizations') { ?>
929 <p> <?php echo xlt('Is it ok to map these CVX codes to already existent immunizations?') ?>
930 <input type='checkbox' name='ok_map_cvx_codes' id='ok_map_cvx_codes' value='1' />
931 </p>
932 <?php } // end if($list_id == 'immunizations') ?>
935 <input type='button' name='form_save' id='form_save' value='<?php xl('Save','e'); ?>' />
936 </p>
937 </center>
939 </form>
941 <!-- template DIV that appears when user chooses to make a new list -->
942 <div id="newlistdetail" style="border: 1px solid black; padding: 3px; display: none; visibility: hidden; background-color: lightgrey;">
943 <?php xl('List Name','e'); ?>: <input type="textbox" size="20" maxlength="30" name="newlistname" id="newlistname">
944 <br>
945 <input type="button" class="savenewlist" value=<?php xl('Save New List','e','\'','\''); ?>>
946 <input type="button" class="cancelnewlist" value=<?php xl('Cancel','e','\'','\''); ?>>
947 </div>
948 </body>
949 <script language="javascript">
950 // jQuery stuff to make the page a little easier to use
952 $(document).ready(function(){
953 $("#form_save").click(function() { SaveChanges(); });
954 $("#list_id").change(function() { $('#theform').submit(); });
956 $(".newlist").click(function() { NewList(this); });
957 $(".savenewlist").click(function() { SaveNewList(this); });
958 $(".deletelist").click(function() { DeleteList(this); });
959 $(".cancelnewlist").click(function() { CancelNewList(this); });
961 var SaveChanges = function() {
962 $("#formaction").val("save");
963 // $('#theform').submit();
964 mysubmit();
967 // show the DIV to create a new list
968 var NewList = function(btnObj) {
969 // show the field details DIV
970 $('#newlistdetail').css('visibility', 'visible');
971 $('#newlistdetail').css('display', 'block');
972 $(btnObj).parent().append($("#newlistdetail"));
973 $('#newlistdetail > #newlistname').focus();
975 // save the new list
976 var SaveNewList = function() {
977 // the list name can only have letters, numbers, spaces and underscores
978 // AND it cannot start with a number
979 if ($("#newlistname").val().match(/^\d+/)) {
980 alert("<?php xl('List names cannot start with numbers.','e'); ?>");
981 return false;
983 var validname = $("#newlistname").val().replace(/[^A-za-z0-9 -]/g, "_"); // match any non-word characters and replace them
984 if (validname != $("#newlistname").val()) {
985 if (! confirm("<?php xl('Your list name has been changed to meet naming requirements.','e','','\n') . xl('Please compare the new name','e','',', \''); ?>"+validname+"<?php xl('with the old name','e','\' ',', \''); ?>"+$("#newlistname").val()+"<?php xl('Do you wish to continue with the new name?','e','\'.\n',''); ?>"))
987 return false;
990 $("#newlistname").val(validname);
992 // submit the form to add a new field to a specific group
993 $("#formaction").val("addlist");
994 $("#theform").submit();
996 // actually delete an entire list from the database
997 var DeleteList = function(btnObj) {
998 var listid = $(btnObj).attr("id");
999 if (confirm("<?php xl('WARNING','e','',' - ') . xl('This action cannot be undone.','e','','\n') . xl('Are you sure you wish to delete the entire list','e',' ','('); ?>"+listid+")?")) {
1000 // submit the form to add a new field to a specific group
1001 $("#formaction").val("deletelist");
1002 $("#deletelistname").val(listid);
1003 $("#theform").submit();
1007 // just hide the new list DIV
1008 var CancelNewList = function(btnObj) {
1009 // hide the list details DIV
1010 $('#newlistdetail').css('visibility', 'hidden');
1011 $('#newlistdetail').css('display', 'none');
1012 // reset the new group values to a default
1013 $('#newlistdetail > #newlistname').val("");
1017 </script>
1019 </html>