Immunization CVX mapping bug fix
[openemr.git] / interface / super / edit_list.php
blobc73103226a0369f7bb9d51c60de22fe75dbeb485
1 <?php
2 /**
3 * library/sql_upgrade_fx.php Upgrading and patching functions of database.
5 * Functions to allow safe database modifications
6 * during upgrading and patches.
8 * Copyright (C) 2007-2011 Rod Roark <rod@sunsetsystems.com>
10 * LICENSE: This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>;.
21 * @package OpenEMR
22 * @author Rod Roark <rod@sunsetsystems.com>
23 * @author Brady Miller <brady@sparmy.com>
24 * @author Teny <teny@zhservices.com>
25 * @link http://www.open-emr.org
28 require_once("../globals.php");
29 require_once("$srcdir/acl.inc");
30 require_once("$srcdir/formdata.inc.php");
31 require_once("$srcdir/lists.inc");
32 require_once("../../custom/code_types.inc.php");
34 $list_id = empty($_REQUEST['list_id']) ? 'language' : $_REQUEST['list_id'];
36 // Check authorization.
37 $thisauth = acl_check('admin', 'super');
38 if (!$thisauth) die(xl('Not authorized'));
40 // If we are saving, then save.
42 if ($_POST['formaction']=='save' && $list_id) {
43 $opt = $_POST['opt'];
44 if ($list_id == 'feesheet') {
45 // special case for the feesheet list
46 sqlStatement("DELETE FROM fee_sheet_options");
47 for ($lino = 1; isset($opt["$lino"]['category']); ++$lino) {
48 $iter = $opt["$lino"];
49 $category = formTrim($iter['category']);
50 $option = formTrim($iter['option']);
51 $codes = formTrim($iter['codes']);
52 if (strlen($category) > 0 && strlen($option) > 0) {
53 sqlInsert("INSERT INTO fee_sheet_options ( " .
54 "fs_category, fs_option, fs_codes " .
55 ") VALUES ( " .
56 "'$category', " .
57 "'$option', " .
58 "'$codes' " .
59 ")");
63 else if ($list_id == 'code_types') {
64 // special case for code types
65 sqlStatement("DELETE FROM code_types");
66 for ($lino = 1; isset($opt["$lino"]['ct_key']); ++$lino) {
67 $iter = $opt["$lino"];
68 $ct_key = formTrim($iter['ct_key']);
69 $ct_id = formTrim($iter['ct_id']) + 0;
70 $ct_seq = formTrim($iter['ct_seq']) + 0;
71 $ct_mod = formTrim($iter['ct_mod']) + 0;
72 $ct_just = formTrim($iter['ct_just']);
73 $ct_mask = formTrim($iter['ct_mask']);
74 $ct_fee = empty($iter['ct_fee' ]) ? 0 : 1;
75 $ct_rel = empty($iter['ct_rel' ]) ? 0 : 1;
76 $ct_nofs = empty($iter['ct_nofs']) ? 0 : 1;
77 $ct_diag = empty($iter['ct_diag']) ? 0 : 1;
78 $ct_active = empty($iter['ct_active' ]) ? 0 : 1;
79 $ct_label = formTrim($iter['ct_label']);
80 $ct_external = formTrim($iter['ct_external']) + 0;
81 $ct_claim = empty($iter['ct_claim']) ? 0 : 1;
82 $ct_proc = empty($iter['ct_proc']) ? 0 : 1;
83 $ct_term = empty($iter['ct_term']) ? 0 : 1;
84 $ct_problem = empty($iter['ct_problem']) ? 0 : 1;
85 if (strlen($ct_key) > 0 && $ct_id > 0) {
86 sqlInsert("INSERT INTO code_types ( " .
87 "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 " .
88 ") VALUES ( " .
89 "'$ct_key' , " .
90 "'$ct_id' , " .
91 "'$ct_seq' , " .
92 "'$ct_mod' , " .
93 "'$ct_just', " .
94 "'$ct_mask', " .
95 "'$ct_fee' , " .
96 "'$ct_rel' , " .
97 "'$ct_nofs', " .
98 "'$ct_diag', " .
99 "'$ct_active', " .
100 "'$ct_label', " .
101 "'$ct_external', " .
102 "'$ct_claim', " .
103 "'$ct_proc', " .
104 "'$ct_term', " .
105 "'$ct_problem' " .
106 ")");
110 else if ($list_id == 'issue_types') {
111 // special case for issue_types
112 sqlStatement("DELETE FROM issue_types");
113 for ($lino = 1; isset($opt["$lino"]['category']); ++$lino) {
114 $iter = $opt["$lino"];
115 $it_active = formTrim($iter['active']);
116 $it_category = formTrim($iter['category']);
117 $it_ordering = formTrim($iter['ordering']);
118 $it_type = formTrim($iter['type']);
119 $it_plural = formTrim($iter['plural']);
120 $it_singular = formTrim($iter['singular']);
121 $it_abbr = formTrim($iter['abbreviation']);
122 $it_style = formTrim($iter['style']);
123 $it_fshow = formTrim($iter['force_show']);
125 if ( (strlen($it_category) > 0) && (strlen($it_type) > 0) ) {
126 sqlInsert("INSERT INTO issue_types ( " .
127 "`active`,`category`,`ordering`, `type`, `plural`, `singular`, `abbreviation`, `style`, `force_show` " .
128 ") VALUES ( " .
129 "'$it_active' , " .
130 "'$it_category' , " .
131 "'$it_ordering' , " .
132 "'$it_type' , " .
133 "'$it_plural' , " .
134 "'$it_singular' , " .
135 "'$it_abbr' , " .
136 "'$it_style', " .
137 "'$it_fshow' " .
138 ")");
142 else {
143 // all other lists
145 // collect the option toggle if using the 'immunizations' list
146 if ($list_id == 'immunizations') {
147 $ok_map_cvx_codes = isset($_POST['ok_map_cvx_codes']) ? $_POST['ok_map_cvx_codes'] : 0;
149 // erase lists options and recreate them from the submitted form data
150 sqlStatement("DELETE FROM list_options WHERE list_id = '$list_id'");
151 for ($lino = 1; isset($opt["$lino"]['id']); ++$lino) {
152 $iter = $opt["$lino"];
153 $value = empty($iter['value']) ? 0 : (formTrim($iter['value']) + 0);
154 $id = formTrim($iter['id']);
155 if (strlen($id) > 0) {
157 // Special processing for the immunizations list
158 // Map the entered cvx codes into the immunizations table cvx_code
159 // Ensure the following conditions are met to do this:
160 // $list_id == 'immunizations'
161 // $value is an integer and greater than 0
162 // $id is set, not empty and not equal to 0
163 // (note that all these filters are important. Not allowing $id
164 // of zero here is extremely important; never remove this conditional
165 // or you risk corrupting your current immunizations database entries)
166 // $ok_map_cvx_codes is equal to 1
167 if ($list_id == 'immunizations' &&
168 is_int($value) &&
169 $value > 0 &&
170 isset($id) &&
171 !empty($id) &&
172 $id != 0 &&
173 $ok_map_cvx_codes == 1 ) {
174 sqlStatement ("UPDATE `immunizations` " .
175 "SET `cvx_code`='".$value."' " .
176 "WHERE `immunization_id`='".$id."'");
179 // Force List Based Form names to start with LBF.
180 if ($list_id == 'lbfnames' && substr($id,0,3) != 'LBF')
181 $id = "LBF$id";
183 // Insert the list item
184 sqlInsert("INSERT INTO list_options ( " .
185 "list_id, option_id, title, seq, is_default, option_value, mapping, notes, codes " .
186 ") VALUES ( " .
187 "'$list_id', " .
188 "'" . $id . "', " .
189 "'" . formTrim($iter['title']) . "', " .
190 "'" . formTrim($iter['seq']) . "', " .
191 "'" . formTrim($iter['default']) . "', " .
192 "'" . $value . "', " .
193 "'" . formTrim($iter['mapping']) . "', " .
194 "'" . formTrim($iter['notes']) . "', " .
195 "'" . formTrim($iter['codes']) . "' " .
196 ")");
201 else if ($_POST['formaction']=='addlist') {
202 // make a new list ID from the new list name
203 $newlistID = $_POST['newlistname'];
204 $newlistID = preg_replace("/\W/", "_", $newlistID);
206 // determine the position of this new list
207 $row = sqlQuery("SELECT max(seq) as maxseq FROM list_options WHERE list_id= 'lists'");
209 // add the new list to the list-of-lists
210 sqlInsert("INSERT INTO list_options ( " .
211 "list_id, option_id, title, seq, is_default, option_value " .
212 ") VALUES ( " .
213 "'lists',". // the master list-of-lists
214 "'".$newlistID."',".
215 "'".$_POST['newlistname']."', ".
216 "'".($row['maxseq']+1)."',".
217 "'1', '0')"
220 else if ($_POST['formaction']=='deletelist') {
221 // delete the lists options
222 sqlStatement("DELETE FROM list_options WHERE list_id = '".$_POST['list_id']."'");
223 // delete the list from the master list-of-lists
224 sqlStatement("DELETE FROM list_options WHERE list_id = 'lists' and option_id='".$_POST['list_id']."'");
227 $opt_line_no = 0;
229 // Given a string of multiple instances of code_type|code|selector,
230 // make a description for each.
231 // @TODO Instead should use a function from custom/code_types.inc.php and need to remove casing functions
232 function getCodeDescriptions($codes) {
233 global $code_types;
234 $arrcodes = explode('~', $codes);
235 $s = '';
236 foreach ($arrcodes as $codestring) {
237 if ($codestring === '') continue;
238 $arrcode = explode('|', $codestring);
239 $code_type = $arrcode[0];
240 $code = $arrcode[1];
241 $selector = $arrcode[2];
242 $desc = '';
243 if ($code_type == 'PROD') {
244 $row = sqlQuery("SELECT name FROM drugs WHERE drug_id = '$code' ");
245 $desc = "$code:$selector " . $row['name'];
247 else {
248 $row = sqlQuery("SELECT code_text FROM codes WHERE " .
249 "code_type = '" . $code_types[$code_type]['id'] . "' AND " .
250 "code = '$code' ORDER BY modifier LIMIT 1");
251 $desc = "$code_type:$code " . ucfirst(strtolower($row['code_text']));
253 $desc = str_replace('~', ' ', $desc);
254 if ($s) $s .= '~';
255 $s .= $desc;
257 return $s;
260 // Write one option line to the form.
262 function writeOptionLine($option_id, $title, $seq, $default, $value, $mapping='', $notes='', $codes='') {
263 global $opt_line_no, $list_id;
264 ++$opt_line_no;
265 $bgcolor = "#" . (($opt_line_no & 1) ? "ddddff" : "ffdddd");
266 $checked = $default ? " checked" : "";
268 echo " <tr bgcolor='$bgcolor'>\n";
270 echo " <td align='center' class='optcell'>";
271 echo "<input type='text' name='opt[$opt_line_no][id]' value='" .
272 htmlspecialchars($option_id, ENT_QUOTES) . "' size='12' maxlength='63' class='optin' />";
273 echo "</td>\n";
275 echo " <td align='center' class='optcell'>";
276 echo "<input type='text' name='opt[$opt_line_no][title]' value='" .
277 htmlspecialchars($title, ENT_QUOTES) . "' size='20' maxlength='63' class='optin' />";
278 echo "</td>\n";
280 // if not english and translating lists then show the translation
281 if ($GLOBALS['translate_lists'] && $_SESSION['language_choice'] > 1) {
282 echo " <td align='center' class='translation'>" . (htmlspecialchars( xl($title), ENT_QUOTES)) . "</td>\n";
285 echo " <td align='center' class='optcell'>";
286 echo "<input type='text' name='opt[$opt_line_no][seq]' value='" .
287 htmlspecialchars($seq, ENT_QUOTES) . "' size='4' maxlength='10' class='optin' />";
288 echo "</td>\n";
290 echo " <td align='center' class='optcell'>";
291 echo "<input type='checkbox' name='opt[$opt_line_no][default]' value='1' " .
292 "onclick='defClicked($opt_line_no)' class='optin'$checked />";
293 echo "</td>\n";
295 // Tax rates, contraceptive methods and LBF names have an additional attribute.
297 if ($list_id == 'taxrate' || $list_id == 'contrameth' || $list_id == 'lbfnames') {
298 echo " <td align='center' class='optcell'>";
299 echo "<input type='text' name='opt[$opt_line_no][value]' value='" .
300 htmlspecialchars($value, ENT_QUOTES) . "' size='8' maxlength='15' class='optin' />";
301 echo "</td>\n";
304 // Adjustment reasons use option_value as a reason category. This is
305 // needed to distinguish between adjustments that change the invoice
306 // balance and those that just shift responsibility of payment or
307 // are used as comments.
309 else if ($list_id == 'adjreason') {
310 echo " <td align='center' class='optcell'>";
311 echo "<select name='opt[$opt_line_no][value]' class='optin'>";
312 foreach (array(
313 1 => xl('Charge adjustment'),
314 2 => xl('Coinsurance'),
315 3 => xl('Deductible'),
316 4 => xl('Other pt resp'),
317 5 => xl('Comment'),
318 ) as $key => $desc) {
319 echo "<option value='$key'";
320 if ($key == $value) echo " selected";
321 echo ">" . htmlspecialchars($desc) . "</option>";
323 echo "</select>";
324 echo "</td>\n";
327 // Address book categories use option_value to flag category as a
328 // person-centric vs company-centric vs indifferent.
330 else if ($list_id == 'abook_type') {
331 echo " <td align='center' class='optcell'>";
332 echo "<select name='opt[$opt_line_no][value]' class='optin'>";
333 foreach (array(
334 1 => xl('Unassigned'),
335 2 => xl('Person'),
336 3 => xl('Company'),
337 ) as $key => $desc) {
338 echo "<option value='$key'";
339 if ($key == $value) echo " selected";
340 echo ">" . htmlspecialchars($desc) . "</option>";
342 echo "</select>";
343 echo "</td>\n";
346 // Immunization categories use option_value to map list items
347 // to CVX codes.
349 else if ($list_id == 'immunizations') {
350 echo " <td align='center' class='optcell'>";
351 echo "<input type='text' size='10' name='opt[$opt_line_no][value]' " .
352 "value='" . htmlspecialchars($value,ENT_QUOTES) . "' onclick='sel_cvxcode(this)' " .
353 "title='" . htmlspecialchars( xl('Click to select or change CVX code'), ENT_QUOTES) . "'/>";
354 echo "</td>\n";
357 // IPPF includes the ability to map each list item to a "master" identifier.
358 // Sports teams use this for some extra info for fitness levels.
360 if ($GLOBALS['ippf_specific'] || $list_id == 'fitness') {
361 echo " <td align='center' class='optcell'>";
362 echo "<input type='text' name='opt[$opt_line_no][mapping]' value='" .
363 htmlspecialchars($mapping, ENT_QUOTES) . "' size='12' maxlength='15' class='optin' />";
364 echo "</td>\n";
367 echo " <td align='center' class='optcell'>";
368 echo "<input type='text' name='opt[$opt_line_no][notes]' value='" .
369 htmlspecialchars($notes, ENT_QUOTES) . "' size='25' maxlength='255' class='optin' />";
370 echo "</td>\n";
372 echo " <td align='center' class='optcell'>";
373 echo "<input type='text' name='opt[$opt_line_no][codes]' title='" .
374 xla('Clinical Term Code(s)') ."' value='" .
375 htmlspecialchars($codes, ENT_QUOTES) . "' onclick='select_clin_term_code(this)' size='25' maxlength='255' class='optin' />";
376 echo "</td>\n";
378 echo " </tr>\n";
381 // Write a form line as above but for the special case of the Fee Sheet.
383 function writeFSLine($category, $option, $codes) {
384 global $opt_line_no;
386 ++$opt_line_no;
387 $bgcolor = "#" . (($opt_line_no & 1) ? "ddddff" : "ffdddd");
389 $descs = getCodeDescriptions($codes);
391 echo " <tr bgcolor='$bgcolor'>\n";
393 echo " <td align='center' class='optcell'>";
394 echo "<input type='text' name='opt[$opt_line_no][category]' value='" .
395 htmlspecialchars($category, ENT_QUOTES) . "' size='20' maxlength='63' class='optin' />";
396 echo "</td>\n";
398 echo " <td align='center' class='optcell'>";
399 echo "<input type='text' name='opt[$opt_line_no][option]' value='" .
400 htmlspecialchars($option, ENT_QUOTES) . "' size='20' maxlength='63' class='optin' />";
401 echo "</td>\n";
403 echo " <td align='left' class='optcell'>";
404 echo " <div id='codelist_$opt_line_no'>";
405 if (strlen($descs)) {
406 $arrdescs = explode('~', $descs);
407 $i = 0;
408 foreach ($arrdescs as $desc) {
409 echo "<a href='' onclick='return delete_code($opt_line_no,$i)' title='" . xl('Delete') . "'>";
410 echo "[x]&nbsp;</a>$desc<br />";
411 ++$i;
414 echo "</div>";
415 echo "<a href='' onclick='return select_code($opt_line_no)'>";
416 echo "[" . xl('Add') . "]</a>";
418 echo "<input type='hidden' name='opt[$opt_line_no][codes]' value='" .
419 htmlspecialchars($codes, ENT_QUOTES) . "' />";
420 echo "<input type='hidden' name='opt[$opt_line_no][descs]' value='" .
421 htmlspecialchars($descs, ENT_QUOTES) . "' />";
422 echo "</td>\n";
424 echo " </tr>\n";
429 * Helper functions for writeITLine() and writeCTLine().
431 function ctGenCell($opt_line_no, $data_array, $name, $size, $maxlength, $title='') {
432 $value = isset($data_array[$name]) ? $data_array[$name] : '';
433 $s = " <td align='center' class='optcell'";
434 if ($title) $s .= " title='" . attr($title) . "'";
435 $s .= ">";
436 $s .= "<input type='text' name='opt[$opt_line_no][$name]' value='";
437 $s .= attr($value);
438 $s .= "' size='$size' maxlength='$maxlength' class='optin' />";
439 $s .= "</td>\n";
440 return $s;
443 function ctGenCbox($opt_line_no, $data_array, $name, $title='') {
444 $checked = empty($data_array[$name]) ? '' : 'checked ';
445 $s = " <td align='center' class='optcell'";
446 if ($title) $s .= " title='" . attr($title) . "'";
447 $s .= ">";
448 $s .= "<input type='checkbox' name='opt[$opt_line_no][$name]' value='1' ";
449 $s .= "$checked/>";
450 $s .= "</td>\n";
451 return $s;
454 function ctSelector($opt_line_no, $data_array, $name, $option_array, $title='') {
455 $value = isset($data_array[$name]) ? $data_array[$name] : '';
456 $s = " <td title='" . attr($title) . "' align='center' class='optcell'>";
457 $s .= "<select name='opt[$opt_line_no][$name]' class='optin'>";
458 foreach ( $option_array as $key => $desc) {
459 $s .= "<option value='" . attr($key) . "'";
460 if ($key == $value) $s .= " selected";
461 $s .= ">" . text($desc) . "</option>";
463 $s .= "</select>";
464 $s .= "</td>\n";
465 return $s;
468 // Write a form line as above but for the special case of Code Types.
470 function writeCTLine($ct_array) {
471 global $opt_line_no,$cd_external_options;
473 ++$opt_line_no;
474 $bgcolor = "#" . (($opt_line_no & 1) ? "ddddff" : "ffdddd");
476 echo " <tr bgcolor='$bgcolor'>\n";
478 echo ctGenCBox($opt_line_no, $ct_array, 'ct_active',
479 xl('Is this code type active?'));
480 echo ctGenCell($opt_line_no, $ct_array, 'ct_key' , 6, 15,
481 xl('Unique human-readable identifier for this type'));
482 echo ctGenCell($opt_line_no, $ct_array, 'ct_id' , 2, 11,
483 xl('Unique numeric identifier for this type'));
484 echo ctGenCell($opt_line_no, $ct_array, 'ct_label' , 6, 30,
485 xl('Label for this type'));
486 // if not english and translating lists then show the translation
487 if ($GLOBALS['translate_lists'] && $_SESSION['language_choice'] > 1) {
488 echo " <td align='center' class='translation'>" . xlt($ct_array['ct_label']) . "</td>\n";
490 echo ctGenCell($opt_line_no, $ct_array, 'ct_seq' , 2, 3,
491 xl('Numeric display order'));
492 echo ctGenCell($opt_line_no, $ct_array, 'ct_mod' , 1, 2,
493 xl('Length of modifier, 0 if none'));
494 echo ctGenCell($opt_line_no, $ct_array, 'ct_just', 4, 15,
495 xl('If billing justification is used enter the name of the diagnosis code type.'));
496 echo ctGenCell($opt_line_no, $ct_array, 'ct_mask', 6, 9,
497 xl('Specifies formatting for codes. # = digit, @ = alpha, * = any character. Empty if not used.'));
498 echo ctGenCBox($opt_line_no, $ct_array, 'ct_claim',
499 xl('Is this code type used in claims?'));
500 echo ctGenCBox($opt_line_no, $ct_array, 'ct_fee',
501 xl('Are fees charged for this type?'));
502 echo ctGenCBox($opt_line_no, $ct_array, 'ct_rel',
503 xl('Does this type allow related codes?'));
504 echo ctGenCBox($opt_line_no, $ct_array, 'ct_nofs',
505 xl('Is this type hidden in the fee sheet?'));
506 echo ctGenCBox($opt_line_no, $ct_array, 'ct_proc',
507 xl('Is this a procedure/service type?'));
508 echo ctGenCBox($opt_line_no, $ct_array, 'ct_diag',
509 xl('Is this a diagnosis type?'));
510 echo ctGenCBox($opt_line_no, $ct_array, 'ct_term',
511 xl('Is this a Clinical Term code type?'));
512 echo ctGenCBox($opt_line_no, $ct_array, 'ct_problem',
513 xl('Is this a Medical Problem code type?'));
514 echo ctSelector($opt_line_no, $ct_array, 'ct_external',
515 $cd_external_options, xl('Is this using external sql tables? If it is, then choose the format.'));
516 echo " </tr>\n";
520 * Special case of Issue Types
522 function writeITLine($it_array) {
523 global $opt_line_no,$ISSUE_TYPE_CATEGORIES,$ISSUE_TYPE_STYLES;
524 ++$opt_line_no;
525 $bgcolor = "#" . (($opt_line_no & 1) ? "ddddff" : "ffdddd");
526 echo " <tr bgcolor='$bgcolor'>\n";
527 echo ctSelector($opt_line_no, $it_array, 'category', $ISSUE_TYPE_CATEGORIES, xl('OpenEMR Application Category'));
528 echo ctGenCBox($opt_line_no, $it_array, 'active', xl('Is this active?'));
529 echo ctGenCell($opt_line_no, $it_array, 'ordering' , 10, 10, xl('Order'));
530 echo ctGenCell($opt_line_no, $it_array, 'type' , 20, 75, xl('Issue Type'));
531 echo ctGenCell($opt_line_no, $it_array, 'plural' , 20, 75, xl('Plural'));
532 // if not english and translating lists then show the translation
533 if ($GLOBALS['translate_lists'] && $_SESSION['language_choice'] > 1) {
534 echo " <td align='center' class='translation'>" . xlt($it_array['plural']) . "</td>\n";
536 echo ctGenCell($opt_line_no, $it_array, 'singular' , 20, 75, xl('Singular'));
537 // if not english and translating lists then show the translation
538 if ($GLOBALS['translate_lists'] && $_SESSION['language_choice'] > 1) {
539 echo " <td align='center' class='translation'>" . xlt($it_array['singular']) . "</td>\n";
541 echo ctGenCell($opt_line_no, $it_array, 'abbreviation' , 10, 10, xl('Abbreviation'));
542 // if not english and translating lists then show the translation
543 if ($GLOBALS['translate_lists'] && $_SESSION['language_choice'] > 1) {
544 echo " <td align='center' class='translation'>" . xlt($it_array['abbreviation']) . "</td>\n";
546 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'));
547 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.'));
548 echo " </tr>\n";
552 <html>
554 <head>
555 <?php html_header_show();?>
557 <!-- supporting javascript code -->
558 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/jquery.js"></script>
560 <link rel="stylesheet" href='<?php echo $css_header ?>' type='text/css'>
561 <title><?php xl('List Editor','e'); ?></title>
563 <style>
564 tr.head { font-size:10pt; background-color:#cccccc; text-align:center; }
565 tr.detail { font-size:10pt; }
566 td { font-size:10pt; }
567 input { font-size:10pt; }
568 a, a:visited, a:hover { color:#0000cc; }
569 .optcell { }
570 .optin { background-color:transparent; }
571 .help { cursor:help; }
572 .translation { color:green; }
573 </style>
575 <script type="text/javascript" src="../../library/dialog.js"></script>
577 <script language="JavaScript">
579 var current_lino = 0;
581 // Helper function to set the contents of a div.
582 // This is for Fee Sheet administration.
583 function setDivContent(id, content) {
584 if (document.getElementById) {
585 var x = document.getElementById(id);
586 x.innerHTML = '';
587 x.innerHTML = content;
589 else if (document.all) {
590 var x = document.all[id];
591 x.innerHTML = content;
595 // Given a line number, redisplay its descriptive list of codes.
596 // This is for Fee Sheet administration.
597 function displayCodes(lino) {
598 var f = document.forms[0];
599 var s = '';
600 var descs = f['opt[' + lino + '][descs]'].value;
601 if (descs.length) {
602 var arrdescs = descs.split('~');
603 for (var i = 0; i < arrdescs.length; ++i) {
604 s += "<a href='' onclick='return delete_code(" + lino + "," + i + ")' title='<?php xl('Delete','e'); ?>'>";
605 s += "[x]&nbsp;</a>" + arrdescs[i] + "<br />";
608 setDivContent('codelist_' + lino, s);
611 // Helper function to remove a Fee Sheet code.
612 function dc_substring(s, i) {
613 var r = '';
614 var j = s.indexOf('~', i);
615 if (j < 0) { // deleting last segment
616 if (i > 0) r = s.substring(0, i-1); // omits trailing ~
618 else { // not last segment
619 r = s.substring(0, i) + s.substring(j + 1);
621 return r;
624 // Remove a generated Fee Sheet code.
625 function delete_code(lino, seqno) {
626 var f = document.forms[0];
627 var celem = f['opt[' + lino + '][codes]'];
628 var delem = f['opt[' + lino + '][descs]'];
629 var ci = 0;
630 var di = 0;
631 for (var i = 0; i < seqno; ++i) {
632 ci = celem.value.indexOf('~', ci) + 1;
633 di = delem.value.indexOf('~', di) + 1;
635 celem.value = dc_substring(celem.value, ci);
636 delem.value = dc_substring(delem.value, di);
637 displayCodes(lino);
638 return false;
641 // This invokes the find-code popup.
642 // For Fee Sheet administration.
643 function select_code(lino) {
644 current_lino = lino;
645 dlgopen('../patient_file/encounter/find_code_popup.php', '_blank', 700, 400);
646 return false;
649 // This invokes the find-code popup.
650 // For CVX/immunization code administration.
651 function sel_cvxcode(e) {
652 current_sel_name = e.name;
653 dlgopen('../patient_file/encounter/find_code_popup.php?codetype=CVX', '_blank', 500, 400);
656 // This invokes the find-code popup.
657 // For CVX/immunization code administration.
658 function select_clin_term_code(e) {
659 current_sel_clin_term = e.name;
660 dlgopen('../patient_file/encounter/find_code_popup.php?codetype=<?php echo attr(collect_codetypes("clinical_term","csv")) ?>', '_blank', 500, 400);
663 // This is for callback by the find-code popup.
664 function set_related(codetype, code, selector, codedesc) {
665 if (typeof(current_sel_name) == 'undefined' && typeof(current_sel_clin_term) == 'undefined')
667 // Coming from Fee Sheet edit
668 var f = document.forms[0];
669 var celem = f['opt[' + current_lino + '][codes]'];
670 var delem = f['opt[' + current_lino + '][descs]'];
671 var i = 0;
672 while ((i = codedesc.indexOf('~')) >= 0) {
673 codedesc = codedesc.substring(0, i) + ' ' + codedesc.substring(i+1);
675 if (code) {
676 if (celem.value) {
677 celem.value += '~';
678 delem.value += '~';
680 celem.value += codetype + '|' + code + '|' + selector;
681 if (codetype == 'PROD') delem.value += code + ':' + selector + ' ' + codedesc;
682 else delem.value += codetype + ':' + code + ' ' + codedesc;
683 } else {
684 celem.value = '';
685 delem.value = '';
687 displayCodes(current_lino);
689 else if (typeof(current_sel_name) == 'undefined') {
690 // Coming from the Clinical Terms Code(s) edit
691 var f = document.forms[0][current_sel_clin_term];
692 var s = f.value;
693 if (code) {
694 if (s.length > 0) s += ';';
695 s += codetype + ':' + code;
697 else {
698 s = '';
700 f.value = s;
702 else {
703 // Coming from Immunizations edit
704 var f = document.forms[0][current_sel_name];
705 var s = f.value;
706 if (code) {
707 s = code;
709 else {
710 s = '0';
712 f.value = s;
716 // Called when a "default" checkbox is clicked. Clears all the others.
717 function defClicked(lino) {
718 var f = document.forms[0];
719 for (var i = 1; f['opt[' + i + '][default]']; ++i) {
720 if (i != lino) f['opt[' + i + '][default]'].checked = false;
724 // Form validation and submission.
725 // This needs more validation.
726 function mysubmit() {
727 var f = document.forms[0];
728 if (f.list_id.value == 'code_types') {
729 for (var i = 1; f['opt[' + i + '][ct_key]'].value; ++i) {
730 var ikey = 'opt[' + i + ']';
731 for (var j = i+1; f['opt[' + j + '][ct_key]'].value; ++j) {
732 var jkey = 'opt[' + j + ']';
733 if (f[ikey+'[ct_key]'].value == f[jkey+'[ct_key]'].value) {
734 alert('<?php echo xl('Error: duplicated name on line') ?>' + ' ' + j);
735 return;
737 if (parseInt(f[ikey+'[ct_id]'].value) == parseInt(f[jkey+'[ct_id]'].value)) {
738 alert('<?php echo xl('Error: duplicated ID on line') ?>' + ' ' + j);
739 return;
744 f.submit();
747 </script>
749 </head>
751 <body class="body_top">
753 <form method='post' name='theform' id='theform' action='edit_list.php'>
754 <input type="hidden" name="formaction" id="formaction">
756 <p><b><?php xl('Edit list','e'); ?>:</b>&nbsp;
757 <select name='list_id' id="list_id">
758 <?php
760 // List order depends on language translation options.
761 $lang_id = empty($_SESSION['language_choice']) ? '1' : $_SESSION['language_choice'];
763 if (($lang_id == '1' && !empty($GLOBALS['skip_english_translation'])) ||
764 !$GLOBALS['translate_lists'])
766 $res = sqlStatement("SELECT option_id, title FROM list_options WHERE " .
767 "list_id = 'lists' ORDER BY title, seq");
769 else {
770 // Use and sort by the translated list name.
771 $res = sqlStatement("SELECT lo.option_id, " .
772 "IF(LENGTH(ld.definition),ld.definition,lo.title) AS title " .
773 "FROM list_options AS lo " .
774 "LEFT JOIN lang_constants AS lc ON lc.constant_name = lo.title " .
775 "LEFT JOIN lang_definitions AS ld ON ld.cons_id = lc.cons_id AND " .
776 "ld.lang_id = '$lang_id' " .
777 "WHERE lo.list_id = 'lists' " .
778 "ORDER BY IF(LENGTH(ld.definition),ld.definition,lo.title), lo.seq");
781 while ($row = sqlFetchArray($res)) {
782 $key = $row['option_id'];
783 echo "<option value='$key'";
784 if ($key == $list_id) echo " selected";
785 echo ">" . $row['title'] . "</option>\n";
789 </select>
790 <input type="button" id="<?php echo $list_id; ?>" class="deletelist" value=<?php xl('Delete List','e','\'','\''); ?>>
791 <input type="button" id="newlist" class="newlist" value=<?php xl('New List','e','\'','\''); ?>>
792 </p>
794 <center>
796 <table cellpadding='2' cellspacing='0'>
797 <tr class='head'>
798 <?php if ($list_id == 'feesheet') { ?>
799 <td><b><?php xl('Group' ,'e'); ?></b></td>
800 <td><b><?php xl('Option' ,'e'); ?></b></td>
801 <td><b><?php xl('Generates','e'); ?></b></td>
802 <?php } else if ($list_id == 'code_types') { ?>
803 <td><b><?php xl('Active' ,'e'); ?></b></td>
804 <td><b><?php xl('Key' ,'e'); ?></b></td>
805 <td><b><?php xl('ID' ,'e'); ?></b></td>
806 <td><b><?php xl('Label' ,'e'); ?></b></td>
807 <?php //show translation column if not english and the translation lists flag is set
808 if ($GLOBALS['translate_lists'] && $_SESSION['language_choice'] > 1) {
809 echo "<td><b>".xl('Translation')."</b><span class='help' title='".xl('The translated Title that will appear in current language')."'> (?)</span></td>";
810 } ?>
811 <td><b><?php xl('Seq' ,'e'); ?></b></td>
812 <td><b><?php xl('ModLength' ,'e'); ?></b></td>
813 <td><b><?php xl('Justify' ,'e'); ?></b></td>
814 <td><b><?php xl('Mask' ,'e'); ?></b></td>
815 <td><b><?php xl('Claims' ,'e'); ?></b></td>
816 <td><b><?php xl('Fees' ,'e'); ?></b></td>
817 <td><b><?php xl('Relations' ,'e'); ?></b></td>
818 <td><b><?php xl('Hide' ,'e'); ?></b></td>
819 <td><b><?php xl('Procedure' ,'e'); ?></b></td>
820 <td><b><?php xl('Diagnosis' ,'e'); ?></b></td>
821 <td><b><?php xl('Clinical Term','e'); ?></b></td>
822 <td><b><?php xl('Medical Problem' ,'e'); ?></b></td>
823 <td><b><?php xl('External' ,'e'); ?></b></td>
824 <?php } else if ($list_id == 'issue_types') { ?>
825 <td><b><?php echo xlt('OpenEMR Application Category'); ?></b></td>
826 <td><b><?php echo xlt('Active'); ?></b></td>
827 <td><b><?php echo xlt('Order'); ?></b></td>
828 <td><b><?php echo xlt('Type'); ?></b></td>
829 <td><b><?php echo xlt('Plural'); ?></b></td>
830 <?php //show translation column if not english and the translation lists flag is set
831 if ($GLOBALS['translate_lists'] && $_SESSION['language_choice'] > 1) {
832 echo "<td><b>".xl('Translation')."</b><span class='help' title='".xl('The translated Title that will appear in current language')."'> (?)</span></td>";
833 } ?>
834 <td><b><?php echo xlt('Singular'); ?></b></td>
835 <?php //show translation column if not english and the translation lists flag is set
836 if ($GLOBALS['translate_lists'] && $_SESSION['language_choice'] > 1) {
837 echo "<td><b>".xl('Translation')."</b><span class='help' title='".xl('The translated Title that will appear in current language')."'> (?)</span></td>";
838 } ?>
839 <td><b><?php echo xlt('Abbreviation'); ?></b></td>
840 <?php //show translation column if not english and the translation lists flag is set
841 if ($GLOBALS['translate_lists'] && $_SESSION['language_choice'] > 1) {
842 echo "<td><b>".xl('Translation')."</b><span class='help' title='".xl('The translated Title that will appear in current language')."'> (?)</span></td>";
843 } ?>
844 <td><b><?php echo xlt('Style'); ?></b></td>
845 <td><b><?php echo xlt('Force Show'); ?></b></td>
846 <?php } else { ?>
847 <td title=<?php xl('Click to edit','e','\'','\''); ?>><b><?php xl('ID','e'); ?></b></td>
848 <td><b><?php xl('Title' ,'e'); ?></b></td>
849 <?php //show translation column if not english and the translation lists flag is set
850 if ($GLOBALS['translate_lists'] && $_SESSION['language_choice'] > 1) {
851 echo "<td><b>".xl('Translation')."</b><span class='help' title='".xl('The translated Title that will appear in current language')."'> (?)</span></td>";
852 } ?>
853 <td><b><?php xl('Order' ,'e'); ?></b></td>
854 <td><b><?php xl('Default','e'); ?></b></td>
855 <?php if ($list_id == 'taxrate') { ?>
856 <td><b><?php xl('Rate' ,'e'); ?></b></td>
857 <?php } else if ($list_id == 'contrameth') { ?>
858 <td><b><?php xl('Effectiveness','e'); ?></b></td>
859 <?php } else if ($list_id == 'lbfnames') { ?>
860 <td title='<?php xl('Number of past history columns','e'); ?>'><b><?php xl('Repeats','e'); ?></b></td>
861 <?php } else if ($list_id == 'fitness') { ?>
862 <td><b><?php xl('Color:Abbr','e'); ?></b></td>
863 <?php } else if ($list_id == 'adjreason' || $list_id == 'abook_type') { ?>
864 <td><b><?php xl('Type','e'); ?></b></td>
865 <?php } else if ($list_id == 'immunizations') { ?>
866 <td><b>&nbsp;&nbsp;&nbsp;&nbsp;<?php xl('CVX Code Mapping','e'); ?></b></td>
867 <?php } if ($GLOBALS['ippf_specific']) { ?>
868 <td><b><?php xl('Global ID','e'); ?></b></td>
869 <?php } ?>
870 <td><b><?php xl('Notes','e'); ?></b></td>
871 <td><b><?php xl('Code(s)','e'); ?></b></td>
872 <?php } // end not fee sheet ?>
873 </tr>
875 <?php
876 // Get the selected list's elements.
877 if ($list_id) {
878 if ($list_id == 'feesheet') {
879 $res = sqlStatement("SELECT * FROM fee_sheet_options " .
880 "ORDER BY fs_category, fs_option");
881 while ($row = sqlFetchArray($res)) {
882 writeFSLine($row['fs_category'], $row['fs_option'], $row['fs_codes']);
884 for ($i = 0; $i < 3; ++$i) {
885 writeFSLine('', '', '');
888 else if ($list_id == 'code_types') {
889 $res = sqlStatement("SELECT * FROM code_types " .
890 "ORDER BY ct_seq, ct_key");
891 while ($row = sqlFetchArray($res)) {
892 writeCTLine($row);
894 for ($i = 0; $i < 3; ++$i) {
895 writeCTLine(array());
898 else if ($list_id == 'issue_types') {
899 $res = sqlStatement("SELECT * FROM issue_types " .
900 "ORDER BY category, ordering ASC");
901 while ($row = sqlFetchArray($res)) {
902 writeITLine($row);
904 for ($i = 0; $i < 3; ++$i) {
905 writeITLine(array());
908 else {
909 $res = sqlStatement("SELECT * FROM list_options WHERE " .
910 "list_id = '$list_id' ORDER BY seq,title");
911 while ($row = sqlFetchArray($res)) {
912 writeOptionLine($row['option_id'], $row['title'], $row['seq'],
913 $row['is_default'], $row['option_value'], $row['mapping'],
914 $row['notes'],$row['codes']);
916 for ($i = 0; $i < 3; ++$i) {
917 writeOptionLine('', '', '', '', 0);
923 </table>
925 <?php if ($list_id == 'immunizations') { ?>
926 <p> <?php echo xlt('Is it ok to map these CVX codes to already existent immunizations?') ?>
927 <input type='checkbox' name='ok_map_cvx_codes' id='ok_map_cvx_codes' value='1' />
928 </p>
929 <?php } // end if($list_id == 'immunizations') ?>
932 <input type='button' name='form_save' id='form_save' value='<?php xl('Save','e'); ?>' />
933 </p>
934 </center>
936 </form>
938 <!-- template DIV that appears when user chooses to make a new list -->
939 <div id="newlistdetail" style="border: 1px solid black; padding: 3px; display: none; visibility: hidden; background-color: lightgrey;">
940 <?php xl('List Name','e'); ?>: <input type="textbox" size="20" maxlength="30" name="newlistname" id="newlistname">
941 <br>
942 <input type="button" class="savenewlist" value=<?php xl('Save New List','e','\'','\''); ?>>
943 <input type="button" class="cancelnewlist" value=<?php xl('Cancel','e','\'','\''); ?>>
944 </div>
945 </body>
946 <script language="javascript">
947 // jQuery stuff to make the page a little easier to use
949 $(document).ready(function(){
950 $("#form_save").click(function() { SaveChanges(); });
951 $("#list_id").change(function() { $('#theform').submit(); });
953 $(".newlist").click(function() { NewList(this); });
954 $(".savenewlist").click(function() { SaveNewList(this); });
955 $(".deletelist").click(function() { DeleteList(this); });
956 $(".cancelnewlist").click(function() { CancelNewList(this); });
958 var SaveChanges = function() {
959 $("#formaction").val("save");
960 // $('#theform').submit();
961 mysubmit();
964 // show the DIV to create a new list
965 var NewList = function(btnObj) {
966 // show the field details DIV
967 $('#newlistdetail').css('visibility', 'visible');
968 $('#newlistdetail').css('display', 'block');
969 $(btnObj).parent().append($("#newlistdetail"));
970 $('#newlistdetail > #newlistname').focus();
972 // save the new list
973 var SaveNewList = function() {
974 // the list name can only have letters, numbers, spaces and underscores
975 // AND it cannot start with a number
976 if ($("#newlistname").val().match(/^\d+/)) {
977 alert("<?php xl('List names cannot start with numbers.','e'); ?>");
978 return false;
980 var validname = $("#newlistname").val().replace(/[^A-za-z0-9 -]/g, "_"); // match any non-word characters and replace them
981 if (validname != $("#newlistname").val()) {
982 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',''); ?>"))
984 return false;
987 $("#newlistname").val(validname);
989 // submit the form to add a new field to a specific group
990 $("#formaction").val("addlist");
991 $("#theform").submit();
993 // actually delete an entire list from the database
994 var DeleteList = function(btnObj) {
995 var listid = $(btnObj).attr("id");
996 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+")?")) {
997 // submit the form to add a new field to a specific group
998 $("#formaction").val("deletelist");
999 $("#deletelistname").val(listid);
1000 $("#theform").submit();
1004 // just hide the new list DIV
1005 var CancelNewList = function(btnObj) {
1006 // hide the list details DIV
1007 $('#newlistdetail').css('visibility', 'hidden');
1008 $('#newlistdetail').css('display', 'none');
1009 // reset the new group values to a default
1010 $('#newlistdetail > #newlistname').val("");
1014 </script>
1016 </html>