Remove concurrent_layout and clarify layout and themes selections (#272)
[openemr.git] / interface / forms / CAMOS / new.php
blobafea26bb37a05b10595005eb41db454240f033d2
1 <?php
2 include_once("../../globals.php");
3 include_once("../../../library/api.inc");
4 include_once("../../../library/sql.inc");
5 include_once("../../../library/formdata.inc.php");
6 $out_of_encounter = false;
7 if ( (($_SESSION['encounter'] == '') || ($_SESSION['pid'] == '')) || ($_GET['mode'] == 'external')) {
8 $out_of_encounter = true;
10 // formHeader("Form: CAMOS");
11 $returnurl = 'encounter_top.php';
12 function myauth() {
13 return 1;
18 <?php
20 $break = "/* ---------------------------------- */"; //break between clone items
21 $delete_subdata = true; //true means allowing the deletion of subdata. If you delete a category, all subcategories and items go too.
22 $limit = 100;
23 $select_size = 20;
24 $textarea_rows = 20;
25 $textarea_cols = 80;
26 $debug = '';
27 $error = '';
29 $preselect_category = '';
30 $preselect_subcategory = '';
31 $preselect_item = '';
32 $preselect_category_override = '';
33 $preselect_subcategory_override = '';
34 $preselect_item_override = '';
36 $quote_search = array("\r","\n");
37 $quote_replace = array("\\r","\\n");
38 $quote_search_content = array("\r","\n");
39 $quote_replace_content = array("\\r","\\n");
40 $category = str_replace($quote_search,$quote_replace,$_POST['change_category']);
41 $subcategory = str_replace($quote_search,$quote_replace,$_POST['change_subcategory']);
42 $item = str_replace($quote_search,$quote_replace,$_POST['change_item']);
43 $content = str_replace($quote_search_content,$quote_replace_content,$_POST['textarea_content']);
44 if ($_POST['hidden_category']) {$preselect_category = $_POST['hidden_category'];}
45 if ($_POST['hidden_subcategory']) {$preselect_subcategory = $_POST['hidden_subcategory'];}
46 if ($_POST['hidden_item']) {$preselect_item = $_POST['hidden_item'];}
47 //handle changes to database
48 if (substr($_POST['hidden_mode'],0,3) == 'add') {
49 if ($_POST['hidden_selection'] == 'change_category') {
50 $preselect_category_override = $_POST['change_category'];
52 $category = formDataCore($category);
54 $query = "INSERT INTO ".mitigateSqlTableUpperCase("form_CAMOS_category")." (user, category) values ('".$_SESSION['authUser']."', '";
55 $query .= $category."')";
56 sqlInsert($query);
58 elseif ($_POST['hidden_selection'] == 'change_subcategory') {
59 $preselect_subcategory_override = $_POST['change_subcategory'];
60 $category_id = $_POST['hidden_category'];
61 if ($category_id >= 0 ) {
63 $subcategory = formDataCore($subcategory);
65 $query = "INSERT INTO ".mitigateSqlTableUpperCase("form_CAMOS_subcategory")." (user, subcategory, category_id) values ('".$_SESSION['authUser']."', '";
66 $query .= $subcategory."', '".$category_id."')";
67 sqlInsert($query);
70 elseif ($_POST['hidden_selection'] == 'change_item') {
71 $preselect_item_override = $_POST['change_item'];
72 $category_id = $_POST['hidden_category'];
73 $subcategory_id = $_POST['hidden_subcategory'];
74 if (($category_id >= 0 ) && ($subcategory_id >=0)) {
76 $item = formDataCore($item);
78 $query = "INSERT INTO ".mitigateSqlTableUpperCase("form_CAMOS_item")." (user, item, content, subcategory_id) values ('".$_SESSION['authUser']."', '";
79 $query .= $item."', '".$content."', '".$subcategory_id."')";
80 sqlInsert($query);
84 elseif ($_POST['hidden_selection'] == 'change_content') {
85 $item_id = $_POST['hidden_item'];
86 if ($item_id >= 0) {
87 if ($_POST['hidden_mode'] == 'add to') {
88 $tmp = sqlQuery("SELECT content from ".mitigateSqlTableUpperCase("form_CAMOS_item")." where id = ".$item_id);
89 if (isset($tmp)) {
90 $content .= "\n".$tmp['content'];
94 $content = add_escape_custom($content);
96 $query = "UPDATE ".mitigateSqlTableUpperCase("form_CAMOS_item")." set content = '".$content."' where id = ".$item_id;
97 sqlInsert($query);
101 elseif ($_POST['hidden_mode'] == 'delete') {
102 if ($delete_subdata) {
103 if ($_POST['hidden_selection'] == 'change_category') {
104 $to_delete_id = $_POST['hidden_category'];
105 $statement1 = sqlStatement("select id from ".mitigateSqlTableUpperCase("form_CAMOS_subcategory")." where category_id = ?", array($to_delete_id));
106 while ($result1 = sqlFetchArray($statement1)) {
107 $query = "DELETE FROM ".mitigateSqlTableUpperCase("form_CAMOS_item")." WHERE subcategory_id = ?";
108 sqlInsert($query, array($result1['id']));
110 $query = "DELETE FROM ".mitigateSqlTableUpperCase("form_CAMOS_subcategory")." WHERE category_id = ?";
111 sqlInsert($query, array($to_delete_id));
112 $query = "DELETE FROM ".mitigateSqlTableUpperCase("form_CAMOS_category")." WHERE id = ?";
113 sqlInsert($query, array($to_delete_id));
115 elseif ($_POST['hidden_selection'] == 'change_subcategory') {
116 $to_delete_id = $_POST['hidden_subcategory'];
117 $query = "DELETE FROM ".mitigateSqlTableUpperCase("form_CAMOS_item")." WHERE subcategory_id = ?";
118 sqlInsert($query, array($to_delete_id));
119 $query = "DELETE FROM ".mitigateSqlTableUpperCase("form_CAMOS_subcategory")." WHERE id = ?";
120 sqlInsert($query, array($to_delete_id));
122 elseif ($_POST['hidden_selection'] == 'change_item') {
123 if ((isset($_POST['select_item'])) && (count($_POST['select_item'])>1)) {
124 foreach($_POST['select_item'] as $v) {
125 $to_delete_id = $v;
126 $query = "DELETE FROM ".mitigateSqlTableUpperCase("form_CAMOS_item")." WHERE id = ?";
127 sqlInsert($query, array($to_delete_id));
129 } else {
130 $to_delete_id = $_POST['hidden_item'];
131 $query = "DELETE FROM ".mitigateSqlTableUpperCase("form_CAMOS_item")." WHERE id = ?";
132 sqlInsert($query, array($to_delete_id));
135 } else {
136 if ($_POST['hidden_selection'] == 'change_category') {
137 $to_delete_id = $_POST['hidden_category'];
138 $to_delete_from_table = 'form_CAMOS_category';
139 $to_delete_from_subtable = 'form_CAMOS_subcategory';
140 $to_delete_from_subsubtable = 'form_CAMOS_item';
141 $tablename = 'category';
142 $subtablename = 'subcategory';
143 $subsubtablename = 'item';
145 elseif ($_POST['hidden_selection'] == 'change_subcategory') {
146 $to_delete_id = $_POST['hidden_subcategory'];
147 $to_delete_from_table = 'form_CAMOS_subcategory';
148 $to_delete_from_subtable = 'form_CAMOS_item';
149 $tablename = 'subcategory';
150 $subtablename = 'item';
152 elseif ($_POST['hidden_selection'] == 'change_item') {
153 $to_delete_id = $_POST['hidden_item'];
154 $to_delete_from_table = 'form_CAMOS_item';
155 $to_delete_from_subtable = '';
156 $tablename = 'item';
157 $subtablename = '';
160 if ($subtablename == '') {
161 $query = "DELETE FROM ".escape_table_name($to_delete_from_table)." WHERE id like ?";
162 sqlInsert($query, array($to_delete_id));
164 else {
165 $query = "SELECT count(id) FROM ".escape_table_name($to_delete_from_subtable)." WHERE ".$tablename."_id like ?";
166 $statement = sqlStatement($query, array($to_delete_id));
167 if ($result = sqlFetchArray($statement)) {
168 if ($result['count(id)'] == 0) {
169 $query = "DELETE FROM ".escape_table_name($to_delete_from_table)." WHERE id like ?";
170 sqlInsert($query, array($to_delete_id));
172 else {
173 $error = $subtablename." not empty!";
179 elseif ($_POST['hidden_mode'] == 'alter') {
180 $newval = $_POST[$_POST['hidden_selection']];
181 if ($_POST['hidden_selection'] == 'change_category') {
182 $to_alter_id = $_POST['hidden_category'];
183 $to_alter_table = 'form_CAMOS_category';
184 $to_alter_column = 'category';
186 elseif ($_POST['hidden_selection'] == 'change_subcategory') {
187 $to_alter_id = $_POST['hidden_subcategory'];
188 $to_alter_table = 'form_CAMOS_subcategory';
189 $to_alter_column = 'subcategory';
191 elseif ($_POST['hidden_selection'] == 'change_item') {
192 $to_alter_id = $_POST['hidden_item'];
193 $to_alter_table = 'form_CAMOS_item';
194 $to_alter_column = 'item';
196 sqlInsert("UPDATE ".escape_table_name($to_alter_table)." set ".$to_alter_column." = ? where id = ?", array($newval, $to_alter_id));
199 //preselect column items
200 //either a database change has been made, so the user should be made to feel that they never left the same CAMOS screen
201 //or, CAMOS has been started freshly, therefore the last entry of the current patient should be selected.
202 $preselect_mode = '';
203 if ($preselect_category == '' && !$out_of_encounter) {
204 $preselect_mode = 'by name';
205 //at this point, if this variable has not been set, CAMOS must have been start over
206 //so let's get the most recent values from form_CAMOS for this patient's pid
207 $tmp = sqlQuery("SELECT max(id) AS max FROM ".mitigateSqlTableUpperCase("form_CAMOS")." WHERE " .
208 "pid = '" . $_SESSION['pid'] . "'");
209 $maxid = $tmp['max'] ? $tmp['max'] : 0;
211 $query = "SELECT category, subcategory, item FROM ".mitigateSqlTableUpperCase("form_CAMOS")." WHERE id = $maxid";
212 $statement = sqlStatement($query);
213 if ($result = sqlFetchArray($statement)) {
214 $preselect_category = $result['category'];
215 $preselect_subcategory = $result['subcategory'];
216 $preselect_item = $result['item'];
218 else {$preselect_mode = '';}
220 else {
221 $preselect_mode = 'by number';
225 <html><head>
226 <link rel=stylesheet href="<?php echo $css_header;?>" type="text/css">
228 <script language="javascript" type="text/javascript">
230 var array1 = new Array();
231 var array2 = new Array();
232 var array3 = new Array();
233 var buffer = new Array();
234 var icd9_list = '';
235 var preselect_off = false;
236 var content_change_flag = false;
237 var lock_override_flag = false;
238 var columns_status = 'show';
239 var hs_status = false;
240 var vs_status = false;
241 var hide_tc02_status = false;
242 var clone_mode = false;
244 var crop_buffer = '';
245 var special_select_start = 0;
246 var special_select_end = 0;
248 <?php
250 if (substr($_POST['hidden_mode'],0,5) == 'clone') {
251 echo "clone_mode = true;\n";
255 function clear_box(obj) {
256 var hold = obj.value;
257 obj.value = buffer[obj] ? buffer[obj] : '';
258 buffer[obj] = hold;
261 function showit() {
262 var log = document.getElementById('log');
263 var content = document.testform.testarea;
264 specialSelect(content,'/*','*/');
267 function specialSelect(t_area, delim_1, delim_2) {
268 if (crop_buffer != '') {
269 t_area.value = crop_buffer;
270 crop_buffer = '';
271 return;
273 var cv = t_area.value;
274 var start = t_area.selectionStart;
275 var end = t_area.selectionEnd;
276 var newstart = cv.lastIndexOf(delim_1, start);
277 var newend = cv.indexOf(delim_2, end);
278 if ((newstart == -1) || (newend == -1)) {return;}
279 if ((newstart == special_select_start) && (newend == special_select_end)) {
280 cropToSelect(t_area, delim_2);
282 if (newstart >= 0 && newend >= 0) {
283 t_area.selectionStart = newstart;
284 t_area.selectionEnd = newend+delim_2.length;
286 special_select_start = newstart;
287 special_select_end = newend;
290 function cropToSelect(t_area, delim_2) {
291 var cv = t_area.value;
292 crop_buffer = cv;
293 var start = special_select_start;
294 var end = special_select_end+delim_2.length;
295 var length = end-start;
296 t_area.value = cv.substr(start,length);
299 function hide_columns() {
300 var column01 = document.getElementById('id_category_column');
301 var column02 = document.getElementById('id_subcategory_column');
302 var column03 = document.getElementById('id_item_column');
303 var columnheader01 = document.getElementById('id_category_column_header');
304 var columnheader02 = document.getElementById('id_subcategory_column_header');
305 var columnheader03 = document.getElementById('id_item_column_header');
307 if (columns_status == 'show') {
308 columns_status = 'hide';
309 column01.style.display = 'none';
310 column02.style.display = 'none';
311 column03.style.display = 'none';
312 columnheader01.style.display = 'none';
313 columnheader02.style.display = 'none';
314 columnheader03.style.display = 'none';
316 else {
317 columns_status = 'show';
318 column01.style.display = 'inline';
319 column02.style.display = 'inline';
320 column03.style.display = 'inline';
321 columnheader01.style.display = 'inline';
322 columnheader02.style.display = 'inline';
323 columnheader03.style.display = 'inline';
325 resize_content();
327 function resize_content() {
328 f2 = document.CAMOS;
329 f4 = f2.textarea_content
330 if (f4.cols == <?php echo $textarea_cols ?>) {
331 f4.cols = <?php echo $textarea_cols ?>*2;
332 f4.rows = <?php echo $textarea_rows?>;
333 } else {
334 f4.cols = <?php echo $textarea_cols ?>;
335 f4.rows = <?php echo $textarea_rows?>;
338 //function hs_button() {
339 // f2 = document.CAMOS;
340 // if (hs_status) {
341 // hide_columns();
342 // f2.textarea_content.cols /= 3;
343 // f2.textarea_content02.cols /= 3;
344 // hs_status = false;
345 // } else {
346 // hide_columns();
347 //// f2.textarea_content.cols *= 3;
348 // f2.textarea_content02.cols *= 3;
349 // hs_status = true;
350 // }
355 //deal with locking of content = prevent accidental overwrite
357 function trimString (str) {
358 str = this != window? this : str;
359 return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
361 function isLocked() {
362 f2 = document.CAMOS;
363 if (lock_override_flag) {
364 lock_override_flag = false;
365 return false;
367 return /\/\*\s*lock\s*\:\:\s*\*\//.test(f2.textarea_content.value);
369 function lock_content() {
370 f2 = document.CAMOS;
371 if ((trimString(f2.textarea_content.value) != "") && (!isLocked())) {
372 f2.textarea_content.value = f2.textarea_content.value + "\n\n" + "/*lock::*/";
373 lock_override_flag = true;
374 js_button('add','change_content');
377 function allSelected() {
378 var f2 = document.CAMOS;
379 if ( (f2.select_category.selectedIndex < 0) || (f2.select_subcategory.selectedIndex < 0) || (f2["select_item[]"].selectedIndex < 0) ) {
380 return false; //one of the columns is not selected
382 else {
383 return true; //all columns have a selection
387 function content_focus() {
388 if (content_change_flag == false) {
389 if (!allSelected()) {
390 // alert("If you add text to the 'content' box without a selection in each column (category, subcategory, item), you will likely lose your work.")
393 else {return;}
394 content_change_flag = true;
396 function content_blur() {
397 if (content_change_flag == true) {
398 content_change_flag = false;
401 <?php
403 if (!$out_of_encounter) { //do not do stuff that is encounter specific if not in an encounter
404 //ICD9
405 $icd9_flag = false;
406 $query = "SELECT code_text, code FROM billing WHERE encounter=".$_SESSION['encounter'].
407 " AND pid=".$_SESSION['pid']." AND code_type like 'ICD9' AND activity=1";
408 $statement = sqlStatement($query);
409 if ($result = sqlFetchArray($statement)) {
410 $icd9_flag = true;
411 echo "icd9_list = \"\\n\\n\\\n";
412 echo $result['code']." ".$result['code_text']."\\n\\\n";
414 while ($result = sqlFetchArray($statement)) {
415 echo $result['code']." ".$result['code_text']."\\n\\\n";
417 if ($icd9_flag) {echo "\";\n";}
420 $query = "SELECT id, category FROM ".mitigateSqlTableUpperCase("form_CAMOS_category")." ORDER BY category";
421 $statement = sqlStatement($query);
422 $i = 0;
423 while ($result = sqlFetchArray($statement)) {
424 echo "array1[".$i."] = new Array(\"".fixquotes($result['category'])."\",\"".$result['id']."\", new Array());\n";
425 $i++;
427 $i=0;
428 $query = "SELECT id, subcategory, category_id FROM ".mitigateSqlTableUpperCase("form_CAMOS_subcategory")." ORDER BY subcategory";
429 $statement = sqlStatement($query);
430 while ($result = sqlFetchArray($statement)) {
431 echo "array2[".$i."] = new Array(\"".fixquotes($result['subcategory'])."\", \"".$result['category_id']."\", \"".$result['id']."\", new Array());\n";
432 $i++;
434 $i=0;
435 $query = "SELECT id, item, content, subcategory_id FROM ".mitigateSqlTableUpperCase("form_CAMOS_item")." ORDER BY item";
436 $statement = sqlStatement($query);
437 while ($result = sqlFetchArray($statement)) {
438 echo "array3[".$i."] = new Array(\"".fixquotes($result['item'])."\", \"".fixquotes(str_replace($quote_search_content,$quote_replace_content,strip_tags($result['content'],"<b>,<i>")))."\", \"".$result['subcategory_id'].
439 "\",\"".$result['id']."\");\n";
440 $i++;
444 function append_icd9() {
445 var f2 = document.CAMOS;
446 f2.textarea_content.value = f2.textarea_content.value + icd9_list;
449 function select_word(mode, mystring, myselect) { //take a string and select it in a select box if present
450 if (preselect_off) return 0;
451 for (var i=0;i<myselect.length;i++) {
452 var match = '';
453 if (mode == 'by name') {
454 match = myselect.options[i].text;
456 else if (mode == 'by number') {
457 match = myselect.options[i].value;
459 else {return 0;}
460 if (match == mystring) {
461 myselect.selectedIndex = i;
464 return 1;
466 <?php
468 if (1) { //we are hiding the clone buttons and still need 'search others' so this is not to be removed if out of encounter anymore.
469 //if (!$out_of_encounter) { //do not do stuff that is encounter specific if not in an encounter
470 //cloning - similar process to preselect set to first time starting CAMOS
471 //as above
472 $clone_category = '';
473 $clone_subcategory = '';
474 $clone_item = '';
475 $clone_content = '';
476 $clone_data1 = '';
477 $clone_data2 = '';
478 $clone_data_array = array();
479 if (substr($_POST['hidden_mode'],0,5) == 'clone') {
480 $clone_category = $_POST['category'] ? $_POST['category'] : '';
481 $clone_category_term = '';
482 if ($clone_category != '') {
483 $clone_category_term = " where category like '".$clone_category."'";
485 $clone_subcategory = $_POST['subcategory'] ? $_POST['subcategory'] : '';
486 $clone_subcategory_term = '';
487 if ($clone_subcategory != '') {
488 $clone_subcategory_term = " and subcategory like '".$_POST['subcategory']."'";
490 $clone_item = $_POST['item'] ? $_POST['item'] : '';
491 $clone_item_term = '';
492 if ($clone_item != '') {
493 $clone_item_term = " and item like '".$_POST['item']."'";
495 $clone_search = trim($_POST['clone_others_search']);
497 $name_data_flag = false; //flag to see if we are going to use patient names in search result of clone others.
498 $show_phone_flag = false; //if we do show patient names, flag to see if we show phone numbers too
499 $pid_clause = ''; //if name search, will return a limited list of names to search for.
500 if (strpos($clone_search, "::") !== false) {
501 $name_data_flag = true;
502 $show_phone_flag = true;
503 $split = preg_split('/\s*::\s*/', $clone_search);
504 $clone_search = $split[1];
505 $pid_clause = searchName($split[0]);
507 elseif (strpos($clone_search, ":") !== false) {
508 $name_data_flag = true;
509 $split = preg_split('/\s*:\s*/', $clone_search);
510 $clone_search = $split[1];
511 $pid_clause = searchName($split[0]);
514 $clone_search_term = '';
515 if ($clone_search != '') {
516 $clone_search = preg_replace('/\s+/', '%', $clone_search);
517 if (substr($clone_search,0,1) == "`") {
518 $clone_subcategory_term = '';
519 $clone_item_term = '';
520 $clone_search = substr($clone_search,1);
522 $clone_search_term = " and content like '%$clone_search%'";
524 if (substr($_POST['hidden_mode'],0,12) == 'clone others') {
526 if (preg_match('/^(export)(.*)/',$clone_search,$matches)) {
527 $query1 = "select id, category from ".mitigateSqlTableUpperCase("form_CAMOS_category");
528 $statement1 = sqlStatement($query1);
529 while ($result1 = sqlFetchArray($statement1)) {
530 $tmp = $result1['category'];
531 $tmp = "/*import::category::$tmp*/"."\n";
532 $clone_data_array[$tmp] = $tmp;
533 $query2 = "select id,subcategory from ".mitigateSqlTableUpperCase("form_CAMOS_subcategory")." where category_id= ?";
534 $statement2 = sqlStatement($query2, $result1['id']);
535 while ($result2 = sqlFetchArray($statement2)) {
536 $tmp = $result2['subcategory'];
537 $tmp = "/*import::subcategory::$tmp*/"."\n";
538 $clone_data_array[$tmp] = $tmp;
539 $query3 = "select item, content from ".mitigateSqlTableUpperCase("form_CAMOS_item")." where subcategory_id=".$result2['id'];
540 $statement3 = sqlStatement($query3);
541 while ($result3 = sqlFetchArray($statement3)) {
542 $tmp = $result3['item'];
543 $tmp = "/*import::item::$tmp*/"."\n";
544 $clone_data_array[$tmp] = $tmp;
545 $tmp = $result3['content'];
546 $tmp = "/*import::content::$tmp*/"."\n";
547 $clone_data_array[$tmp] = $tmp;
551 $clone_data_array = array();
553 elseif ((preg_match('/^(billing)(.*)/',$clone_search,$matches)) ||
554 (preg_match('/^(codes)(.*)/',$clone_search,$matches))) {
555 $table = $matches[1];
556 $line = $matches[2];
557 $line = '%'.trim($line).'%';
558 $search_term = preg_replace('/\s+/','%',$line);
559 $query = "select code, code_type,code_text,modifier,units,fee from $table where code_text like ? limit $limit";
560 $statement = sqlStatement($query, array($search_term));
561 while ($result = sqlFetchArray($statement)) {
562 $code_type = $result['code_type'];
563 if ($code_type == 1) {$code_type = 'CPT4';}
564 if ($code_type == 2) {$code_type = 'ICD9';}
565 if ($code_type == 3) {$code_type = 'OTHER';}
566 $code = $result['code'];
567 $code_text = $result['code_text'];
568 $modifier = $result['modifier'];
569 $units = $result['units'];
570 $fee = $result['fee'];
571 $tmp = "/*billing::$code_type::$code::$code_text::$modifier::$units::$fee*/";
572 $clone_data_array[$tmp] = $tmp;
574 } else {
575 //$clone_data_array['others'] = '/*'.$clone_category.'::'.$clone_subcategory.'::'.
576 // $clone_item.'*/';
577 //See the two lines commented out just below:
578 //I am trying out searching all content regardless of category, subcategory, item...
579 //because of this, we have to limit results more. There may be a few lines
580 //above that should be deleted if this becomes the normal way of doing these searches.
581 //Consider making the two queries below by encounter instead of camos id.
582 //This may be a little tricky.
583 if ($_POST['hidden_mode'] == 'clone others selected') { //clone from search box
584 $query = "select id, category, subcategory, item, content from ".mitigateSqlTableUpperCase("form_CAMOS")." ".
585 $clone_category_term.$clone_subcategory_term.$clone_item_term.
586 $clone_search_term.$pid_clause." order by id desc limit $limit";
587 } else {
588 $query = "select id, category, subcategory, item, content from ".mitigateSqlTableUpperCase("form_CAMOS")." ".
589 " where " .
590 //"category like '%$clone_search%' or" .
591 //" subcategory like '%$clone_search%' or" .
592 //" item like '%$clone_search%' or" .
593 " content like '%$clone_search%'".$pid_clause." order by id desc limit $limit";
595 $statement = sqlStatement($query);
596 while ($result = sqlFetchArray($statement)) {
597 $tmp = '/*camos::'.$result['category'].'::'.$result['subcategory'].
598 '::'.$result['item'].'::'.$result['content'].'*/';
599 if ($name_data_flag === true) {
600 $tmp = getMyPatientData($result['id'],$show_phone_flag)."\n$break\n".$tmp;
602 $key_tmp = preg_replace('/\W+/','',$tmp);
603 $key_tmp = preg_replace('/\W+/','',$tmp);
604 $clone_data_array[$key_tmp] = $tmp;
607 } else {//end of clone others
608 $query = "SELECT date(date) as date, subcategory, item, content FROM ".mitigateSqlTableUpperCase("form_CAMOS")." WHERE category like '".
609 $clone_category."' and pid=".$_SESSION['pid']." order by id desc";
611 if ($_POST['hidden_mode'] == 'clone last visit') {
612 //go back $stepback # of encounters...
613 //This has been changed to clone last visit based on actual last encounter rather than as it was
614 //only looking at most recent BILLED encounters. To go back to billed encounters, change the following
615 //two queries to the 'billing' table rather than form_encounter and make sure to add in 'and activity=1'
616 //OK, now I have tried tracking last encounter from billing, then form_encounter. Now, we are going to
617 //try from forms where form_name like 'CAMOS%' so we will not bother with encounters that have no CAMOS entries...
618 $stepback = $_POST['stepback'] ? $_POST['stepback'] : 1;
619 $tmp = sqlQuery("SELECT max(encounter) as max FROM forms where encounter < " .
620 $_SESSION['encounter'] . " and form_name like 'CAMOS%' and pid= " . $_SESSION['pid']);
621 $last_encounter_id = $tmp['max'] ? $tmp['max'] : 0;
622 for ($i=0;$i<$stepback-1;$i++) {
623 $tmp = sqlQuery("SELECT max(encounter) as max FROM forms where encounter < " .
624 $last_encounter_id . " and form_name like 'CAMOS%' and pid= " . $_SESSION['pid']);
625 $last_encounter_id = $tmp['max'] ? $tmp['max'] : 0;
627 $query = "SELECT category, subcategory, item, content FROM ".mitigateSqlTableUpperCase("form_CAMOS")." " .
628 "join forms on (".mitigateSqlTableUpperCase("form_CAMOS").".id = forms.form_id) where " .
629 "forms.encounter = '$last_encounter_id' and ".mitigateSqlTableUpperCase("form_CAMOS").".pid=" .
630 $_SESSION['pid']." order by ".mitigateSqlTableUpperCase("form_CAMOS").".id";
632 $statement = sqlStatement($query);
633 while ($result = sqlFetchArray($statement)) {
634 if (preg_match('/^[\s\r\n]*$/',$result['content']) == 0) {
635 if ($_POST['hidden_mode'] == 'clone last visit') {
636 $clone_category = $result['category'];
638 $clone_subcategory = $result['subcategory'];
639 $clone_item = $result['item'];
640 $clone_content = $result['content'];
641 $clone_data1 = "/* camos :: $clone_category :: $clone_subcategory :: $clone_item :: ";
642 $clone_data2 = "$clone_content */";
643 $clone_data3 = $clone_data1 . $clone_data2;
644 if ($_POST['hidden_mode'] == 'clone last visit') {
645 $clone_data1 = $clone_data3; //make key include whole entry so all 'last visit' data gets recorded and shown
647 if (!$clone_data_array[$clone_data1]) { //if does not exist, don't overwrite.
648 $clone_data_array[$clone_data1] = "";
649 if ($_POST['hidden_mode'] == 'clone') {
650 $clone_data_array[$clone_data1] = "/* ------ ".$result['date']." --------- */\n"; //break between clone items
652 $clone_data_array[$clone_data1] .= $clone_data3;
656 if ($_POST['hidden_mode'] == 'clone last visit') {
657 $query = "SELECT t1.* FROM form_vitals as t1 join forms as t2 on (t1.id = t2.form_id) WHERE t2.encounter = '$last_encounter_id' and t1.pid=".$_SESSION['pid']." and t2.form_name like 'Vitals'";
658 $statement = sqlStatement($query);
659 if ($result = sqlFetchArray($statement)) {
660 $weight = $result['weight'];
661 $height = $result['height'];
662 $bps = $result['bps'];
663 $bpd = $result['bpd'];
664 $pulse = $result['pulse'];
665 $temperature = $result['temperature'];
666 // $clone_vitals = "/* vitals_key:: weight :: height :: systolic :: diastolic :: pulse :: temperature */\n";
667 $clone_vitals = "";
668 $clone_vitals .= "/* vitals\n :: $weight\n :: $height\n :: $bps\n :: $bpd\n :: $pulse\n :: $temperature\n */";
669 $clone_data_array[$clone_vitals] = $clone_vitals;
671 $query = "SELECT code_type, code, code_text, modifier, units, fee, justify FROM billing WHERE encounter = '$last_encounter_id' and pid=".$_SESSION['pid']." and activity=1 order by id";
672 $statement = sqlStatement($query);
673 while ($result = sqlFetchArray($statement)) {
674 $clone_code_type = $result['code_type'];
675 $clone_code = $result['code'];
676 $clone_code_text = $result['code_text'];
677 $clone_modifier = $result['modifier'];
678 $clone_units = $result['units'];
679 $clone_fee = $result['fee'];
681 //added ability to grab justifications also - bm
682 $clone_justify = "";
683 $clone_justify_raw = $result['justify'];
684 $clone_justify_array = explode(":",$clone_justify_raw);
685 foreach ($clone_justify_array as $temp_justify) {
686 trim($temp_justify);
687 if ($temp_justify != "") {
688 $clone_justify .= ":: ".$temp_justify." ";
692 $clone_billing_data = "/* billing :: $clone_code_type :: $clone_code :: $clone_code_text :: $clone_modifier :: $clone_units :: $clone_fee $clone_justify*/";
693 $clone_data_array[$clone_billing_data] = $clone_billing_data;
696 } //end else (not clone others)
697 }//end of clone stuff
698 //end preselect column items
701 function init() {
702 var f2 = document.CAMOS;
703 if (clone_mode) {
704 clone_mode = false;
706 for (i1=0;i1<array1.length;i1++) {
707 f2.select_category.options[f2.select_category.length] = new Option(array1[i1][0], array1[i1][1]);
709 <?php
711 $temp_preselect_mode = $preselect_mode;
712 if ($preselect_category_override != '') {
713 $temp_preselect_mode = "by name";
714 $preselect_category = $preselect_category_override;
717 if (select_word("<?php echo fixquotes($temp_preselect_mode)."\", \"".fixquotes($preselect_category); ?>" ,f2.select_category)) {
718 click_category();
720 <?php
722 if (substr($_POST['hidden_mode'],0,5) == 'clone') {
723 echo "f2.textarea_content.value = '';\n";
724 // echo "f2.textarea_content.value += '/* count = ".count($clone_data_array)."*/\\n$break\\n';";
725 echo "f2.textarea_content.value += '/* count = ".count($clone_data_array)."*/\\n$break\\n';";
726 foreach($clone_data_array as $key => $val) {
727 echo "f2.textarea_content.value = f2.textarea_content.value + \"".fixquotes(str_replace($quote_search,$quote_replace,$val))."\\n$break\\n\"\n";
734 function click_category() {
735 var f2 = document.CAMOS;
736 var category_index = f2.select_category.selectedIndex;
737 if ((category_index < 0) || (category_index > f2.select_category.length-1)) {return 0;}
738 var sel = f2.select_category.options[f2.select_category.selectedIndex].value;
739 for (var i1=0;i1<array1.length;i1++) {
740 if (array1[i1][1] == sel) {
741 f2.select_subcategory.length = 0;
742 f2["select_item[]"].length = 0;
743 f2.textarea_content.value = '';
744 for (var i2=0;i2<array2.length;i2++) {
745 if (array1[i1][1] == array2[i2][1]) {
746 f2.select_subcategory.options[f2.select_subcategory.length] = new Option(array2[i2][0], array2[i2][2]);
751 <?php
753 $temp_preselect_mode = $preselect_mode;
754 if ($preselect_subcategory_override != '') {
755 $temp_preselect_mode = "by name";
756 $preselect_subcategory = $preselect_subcategory_override;
759 if (select_word("<?php echo fixquotes($temp_preselect_mode)."\", \"".fixquotes($preselect_subcategory); ?>" ,f2.select_subcategory)) {
760 click_subcategory();
763 function click_subcategory() {
764 var f2 = document.CAMOS;
765 var subcategory_index = f2.select_subcategory.selectedIndex;
766 if ((subcategory_index < 0) || (subcategory_index > f2.select_subcategory.length-1)) {return 0;}
767 var sel = f2.select_subcategory.options[f2.select_subcategory.selectedIndex].value;
768 for (var i1=0;i1<array2.length;i1++) {
769 if (array2[i1][2] == sel) {
770 f2["select_item[]"].length = 0;
771 f2.textarea_content.value = '';
772 for (var i2=0;i2<array3.length;i2++) {
773 if (array2[i1][2] == array3[i2][2]) {
774 f2["select_item[]"].options[f2["select_item[]"].length] = new Option(array3[i2][0], array3[i2][3]);
779 <?php
781 $temp_preselect_mode = $preselect_mode;
782 if ($preselect_item_override != '') {
783 $temp_preselect_mode = "by name";
784 $preselect_item = $preselect_item_override;
787 if (select_word("<?php echo fixquotes($temp_preselect_mode)."\", \"".fixquotes($preselect_item); ?>" ,f2["select_item[]"])) {
788 click_item();
789 preselect_off = true;
792 function click_item() {
793 var f2 = document.CAMOS;
794 var item_index = f2["select_item[]"].selectedIndex;
795 if ((item_index < 0) || (item_index > f2["select_item[]"].length-1)) {return 0;}
796 var sel = f2["select_item[]"].options[item_index].value;
797 for (var i1=0;i1<array3.length;i1++) {
798 if (array3[i1][3] == sel) {
799 //diplay text in content box
800 f2.textarea_content.value= array3[i1][1].replace(/\\/g,'');
805 function selectContains(myselect, str) {
806 for (var i=0;i<myselect.length;i++) {
807 if (myselect.options[i].text == trimString(str)) {return true;}
811 function insert_content(direction) {
812 var f2 = document.CAMOS;
813 var source_box = f2.textarea_content;
814 var target_box = f2.textarea_content02;
815 if (direction == 'up') {
816 source_box = f2.textarea_content02;
817 target_box = f2.textarea_content;
819 var sba = source_box.selectionStart;
820 var sbb = source_box.selectionEnd;
821 var tba = target_box.selectionStart;
822 var tbb = target_box.selectionEnd;
823 if (sbb-sba == 0) {
824 sba = 0;
825 sbb = source_box.value.length;
827 var insert_text = (source_box.value).
828 substring(sba, sbb);
829 target_box.value = (target_box.value).
830 substring(0,tba) + insert_text +
831 (target_box.value).substring(tba,target_box.value.length);
834 //AJAX FUNCTIONS
835 //Function to create an XMLHttp Object.
836 function getxmlhttp (){
837 //Create a boolean variable to check for a valid microsoft active X instance.
838 var xmlhttp = false;
840 //Check if we are using internet explorer.
841 try {
842 //If the javascript version is greater than 5.
843 xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
844 } catch (e) {
845 //If not, then use the older active x object.
846 try {
847 //If we are using internet explorer.
848 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
849 } catch (E) {
850 //Else we must be using a non-internet explorer browser.
851 xmlhttp = false;
855 //If we are using a non-internet explorer browser, create a javascript instance of the object.
856 if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
857 xmlhttp = new XMLHttpRequest();
860 return xmlhttp;
863 //Function to process an XMLHttpRequest.
864 function processajax (serverPage, obj, getOrPost, str){
865 //Get an XMLHttpRequest object for use.
866 xmlhttp = getxmlhttp ();
867 if (getOrPost == "get"){
868 xmlhttp.open("GET", serverPage);
869 xmlhttp.onreadystatechange = function() {
870 if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
871 obj.innerHTML = xmlhttp.responseText;
874 xmlhttp.send(null);
875 } else {
876 xmlhttp.open("POST", serverPage, true);
877 xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
878 xmlhttp.onreadystatechange = function() {
879 if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
880 obj.innerHTML = xmlhttp.responseText;
883 xmlhttp.send(str);
888 function setformvalues(form_array){
890 //Run through a list of all objects
891 var str = '';
892 for(key in form_array) {
893 str += key + "=" + encodeURIComponent(form_array[key]) + "&";
895 //Then return the string values.
896 return str;
899 //END OF AJAX RELATED FUNCTIONS
901 function js_button(mode,selection) {
902 var f2 = document.CAMOS;
903 //check lock next
904 if ( (mode == 'add') && (selection == 'change_content') && (isLocked()) ) {
905 alert("<?php xl("You have attempted to alter content which is locked. Remove the lock if you want to do this. To unlock, remove the line, '/*lock::*/'","e"); ?>");
906 return;
908 //end check lock
910 //check for blank or duplicate submissions
911 if ( (mode == 'add') || (mode == 'alter') ) {
912 if (selection == 'change_category') {
913 if (trimString(f2.change_category.value) == "") {
914 alert("<?php xl("You cannot add a blank value for a category!","e"); ?>");
915 return;
917 if (selectContains(f2.select_category, trimString(f2.change_category.value))) {
918 alert("<?php xl("There is already a category named","e"); ?>"+" "+f2.change_category.value+".");
919 return;
922 if (selection == 'change_subcategory') {
923 if (trimString(f2.change_subcategory.value) == "") {
924 alert("<?php xl("You cannot add a blank value for a subcategory!","e"); ?>");
925 return;
927 if (selectContains(f2.select_subcategory, trimString(f2.change_subcategory.value))) {
928 alert("<?php xl("There is already a subcategory named","e"); ?>"+" "+f2.change_subcategory.value+".");
929 return;
932 if (selection == 'change_item') {
933 if (trimString(f2.change_item.value) == "") {
934 alert("<?php xl("You cannot add a blank value for an item!","e"); ?>");
935 return;
937 if (selectContains(f2["select_item[]"], trimString(f2.change_item.value))) {
938 alert("<?php xl("There is already an item named","e"); ?>"+" "+f2.change_item.value+".");
939 return;
943 //end of check for blank or duplicate submissions
945 if (mode == 'delete') {
946 if (!confirm("<?php xl("Are you sure you want to delete this item from the database?","e"); ?>")) {
947 return;
950 //check selections and assign variable values
951 var f2 = document.CAMOS;
952 var category_index = f2.select_category.selectedIndex;
953 var category_value;
954 var category_text;
955 if (category_index < 0) {
956 if ((selection == 'change_subcategory') || (selection == 'change_item') ||
957 (selection == 'change_content')) {
958 // alert ('You have not selected a category!');
959 return;
961 category_value = -1;
962 category_text = '';
964 else {
965 category_value = f2.select_category.options[category_index].value;
966 category_text = f2.select_category.options[category_index].text;
968 var subcategory_index = f2.select_subcategory.selectedIndex;
969 var subcategory_value;
970 var subcategory_text;
971 if (subcategory_index < 0) {
972 if ((selection == 'change_item') || (selection == 'change_content')) {
973 // alert ('You have not selected a subcategory!');
974 return;
976 subcategory_value = -1;
977 subcategory_text = '';
979 else {
980 subcategory_value = f2.select_subcategory.options[subcategory_index].value;
981 subcategory_text = f2.select_subcategory.options[subcategory_index].text;
983 var item_index = f2["select_item[]"].selectedIndex;
984 var item_value;
985 var item_text;
986 if (item_index < 0) {
987 if (selection == 'change_content') {
988 // alert ('You have not selected an item!');
989 return;
991 item_value = -1;
992 item_text = '';
994 else {
995 item_value = f2["select_item[]"].options[item_index].value;
996 item_text = f2["select_item[]"].options[item_index].text;
998 f2.category.value = category_text;
999 f2.subcategory.value = subcategory_text;
1000 f2.item.value = item_text;
1001 //end of setting values relating to selections
1003 //deal with clone buttons or add, alter, delete.
1004 if ( (mode.substr(0,5) == 'clone') || (mode == 'add') || (mode == 'add to') ||
1005 (mode == 'alter') || (mode =='delete') ) {
1006 f2.hidden_mode.value = mode;
1007 f2.hidden_selection.value = selection;
1008 f2.hidden_category.value = category_value;
1009 f2.hidden_subcategory.value = subcategory_value;
1010 f2.hidden_item.value = item_value;
1011 <?php
1012 if (!$out_of_encounter) {
1014 f2.action = '<?php print $GLOBALS['webroot'] ?>/interface/patient_file/encounter/load_form.php?formname=CAMOS';
1015 <?php
1016 } else {
1018 f2.action = '<?php print $GLOBALS['webroot'] ?>/interface/forms/CAMOS/new.php?mode=external';
1019 <?php
1022 f2.target = '_self';
1023 f2.submit();
1024 return;
1026 //ajax code
1027 var myobj = document.getElementById('id_info');
1028 myarray = new Array();
1029 myarray['category'] = category_text;
1030 myarray['subcategory'] = subcategory_text;
1031 myarray['item'] = item_text;
1032 myarray['content']
1033 if (selection == 'submit_selection') {
1034 myarray['content'] = (f2.textarea_content.value).substring(f2.textarea_content.selectionStart, f2.textarea_content.selectionEnd);
1036 else {myarray['content'] = f2.textarea_content.value;}
1037 var str = setformvalues(myarray);
1038 // alert(str);
1039 processajax ('<?php print $GLOBALS['webroot'] ?>/interface/forms/CAMOS/ajax_save.php', myobj, "post", str);
1040 // alert("submitted!");
1041 //ajax code
1044 function selectItem () {
1045 f2 = document.CAMOS;
1046 f2.item.value=f2["select_item[]"].options[f2["select_item[]"].selectedIndex].text;
1047 f2.content.value = f2.textarea_content.value;
1049 function getKey(e) { //process keypresses with getKeyPress
1050 var keynum;
1051 if(window.event) { //IE
1052 keynum = e.keyCode;
1053 } else if(e.which) { // Netscape/Firefox/Opera
1054 keynum = e.which;
1056 return keynum;
1058 function gotoOne(e) {
1059 if (getKey(e) == 96) {
1060 document.CAMOS.clone_others_search.focus();
1063 function processEnter(e,message) {
1064 if (getKey(e) == 13) {
1065 if (message == "clone_others_search") {
1066 js_button('clone others', 'clone others');
1071 </script>
1072 </head>
1073 <body <?php echo $top_bg_line;?> topmargin=0 rightmargin=0 leftmargin=2 bottommargin=0 marginwidth=2 marginheight=0 onload="init()">
1074 <div name="form_container" onKeyPress="gotoOne(event)">
1075 <form method=post action="<?php echo $rootdir;?>/forms/CAMOS/save.php?mode=new" name="CAMOS">
1076 <?php
1077 if (!$out_of_encounter) {
1078 // echo "<h1>$out_of_encounter</h1>\n";
1080 <input type=button name=clone value='<?php xl('Clone','e'); ?>' onClick="js_button('clone', 'clone')">
1081 <input type=button name=clone_visit value='<?php xl('Clone Past Visit','e'); ?>' onClick="js_button('clone last visit', 'clone last visit')">
1082 <select name=stepback>
1083 <option value=1><?php xl('Back one visit','e'); ?></option>
1084 <option value=2><?php xl('Back two visits','e'); ?></option>
1085 <option value=3><?php xl('Back three visits','e'); ?></option>
1086 <option value=4><?php xl('Back four visits','e'); ?></option>
1087 <option value=5><?php xl('Back five visits','e'); ?></option>
1088 <option value=6><?php xl('Back six visits','e'); ?></option>
1089 <option value=7><?php xl('Back seven visits','e'); ?></option>
1090 <option value=8><?php xl('Back eight visits','e'); ?></option>
1091 <option value=9><?php xl('Back nine visits','e'); ?></option>
1092 <option value=10><?php xl('Back ten visits','e'); ?></option>
1093 <option value=11><?php xl('Back eleven visits','e'); ?></option>
1094 <option value=12><?php xl('Back twelve visits','e'); ?></option>
1095 </select>
1096 <?php
1097 echo "<a href='".$GLOBALS['webroot'] . "/interface/patient_file/encounter/$returnurl' onclick='top.restoreSession()'>[".xl('Leave The Form')."]</a>";
1099 <input type=button name='hide columns' value='<?php xl('Hide/Show Columns','e'); ?>' onClick="hide_columns()">
1100 <input type=button name='submit form' value='<?php xl('Submit Selected Content','e'); ?>' onClick="js_button('submit','submit_selection')">
1101 <?php
1102 } //end of if !$out_of_encounter
1104 <div id=id_info style="display:inline">
1105 <!-- supposedly where ajax induced php pages can print their output to... -->
1106 </div>
1107 <div id=id_mainbox style="display:inline">
1108 <?php
1109 if ($error != '') {
1110 echo "<h1> error: ".$error."</h1>\n";
1113 <table border=1>
1114 <tr>
1115 <td>
1116 <div id=id_category_column_header style="display:inline">
1117 <?php xl('Category',e)?>
1118 </div> <!-- end of id_category_column_header -->
1119 </td>
1120 <td>
1121 <div id=id_subcategory_column_header style="display:inline">
1122 <?php xl('Subcategory',e)?>
1123 </div> <!-- end of id_subcategory_column_header -->
1124 </td>
1125 <td>
1126 <div id=id_item_column_header style="display:inline">
1127 <?php xl('Item',e)?>
1128 </div> <!-- end of id_item_column_header -->
1129 </td>
1130 <td>
1131 <?php xl('Content',e)?>
1132 </td>
1133 </tr>
1135 <tr>
1136 <td>
1137 <div id=id_category_column style="display:inline">
1138 <select name=select_category size=<?php echo $select_size ?> onchange="click_category()"></select><br>
1139 <?php
1141 if (myAuth() == 1) {//root user only can see administration option
1143 <input type=text name=change_category><br>
1144 <input type=button name=add1 value='<?php xl('add','e'); ?>' onClick="js_button('add','change_category')">
1145 <input type=button name=alter1 value='<?php xl('alter','e'); ?>' onClick="js_button('alter','change_category')">
1146 <input type=button name=del1 value='<?php xl('del','e'); ?>' onClick="js_button('delete','change_category')"><br>
1147 <?php
1151 </div> <!-- end of id_category_column -->
1152 </td>
1153 <td>
1154 <div id=id_subcategory_column style="display:inline">
1155 <select name=select_subcategory size=<?php echo $select_size ?> onchange="click_subcategory()"></select><br>
1156 <?php
1158 if (myAuth() == 1) {//root user only can see administration option
1160 <input type=text name=change_subcategory><br>
1161 <input type=button name=add2 value='<?php xl('add','e'); ?>' onClick="js_button('add','change_subcategory')">
1162 <input type=button name=alter1 value='<?php xl('alter','e'); ?>' onClick="js_button('alter','change_subcategory')">
1163 <input type=button name=del2 value='<?php xl('del','e'); ?>' onClick="js_button('delete','change_subcategory')"><br>
1164 <?php
1168 </div> <!-- end of id_subcategory_column -->
1169 </td>
1170 <td>
1171 <div id=id_item_column style="display:inline">
1172 <select name=select_item[] size=<?php echo $select_size ?> onchange="click_item()" multiple="multiple"></select><br>
1173 <?php
1175 if (myAuth() == 1) {//root user only can see administration option
1177 <input type=text name=change_item><br>
1178 <input type=button name=add3 value='<?php xl('add','e'); ?>' onClick="js_button('add','change_item')">
1179 <input type=button name=alter1 value='<?php xl('alter','e'); ?>' onClick="js_button('alter','change_item')">
1180 <input type=button name=del3 value='<?php xl('del','e'); ?>' onClick="js_button('delete','change_item')"><br>
1181 <?php
1185 </div> <!-- end of id_item_column -->
1186 </td>
1187 <td>
1188 <div id=id_textarea_content style="display:inline">
1189 <textarea name=textarea_content cols=<?php echo $textarea_cols ?> rows=<?php echo $textarea_rows ?> onFocus="content_focus()" onBlur="content_blur()" onDblClick="specialSelect(this,'/*','*/')" tabindex=2></textarea>
1190 <br/>
1191 <input type=text size=35 name=clone_others_search value='<?php echo $_POST['clone_others_search'] ?>' tabindex=1 onKeyPress="processEnter(event,'clone_others_search')"/>
1192 <input type=button name=clone_others_search_button value='<?php xl('Search','e'); ?>' onClick="js_button('clone others', 'clone others')"/>
1193 <input type=button name=clone_others_selected_search_button value='<?php xl('Search Selected','e'); ?>' onClick="js_button('clone others selected', 'clone others selected')"/>
1194 <?php
1196 if (myAuth() == 1) {//root user only can see administration option
1198 <div id=id_main_content_buttons style="display:block">
1199 <input type=button name=add4 value='<?php xl('Add','e'); ?>' onClick="js_button('add','change_content')">
1200 <input type=button name=add4 value='<?php xl('Add to','e'); ?>' onClick="js_button('add to','change_content')">
1201 <input type=button name=lock value='<?php xl('Lock','e'); ?>' onClick="lock_content()">
1202 <?php
1204 if (!$out_of_encounter) { //do not do stuff that is encounter specific if not in an encounter
1206 <input type=button name=icd9 value='<?php xl('ICD9','e'); ?>' onClick="append_icd9()">
1207 </div> <!-- end of id_main_content_buttons-->
1208 <?php
1212 <?php
1216 </td>
1217 </td>
1218 </tr>
1219 </table>
1221 <input type=hidden name=hidden_mode>
1222 <input type=hidden name=hidden_selection>
1223 <input type=hidden name=hidden_category>
1224 <input type=hidden name=hidden_subcategory>
1225 <input type=hidden name=hidden_item>
1227 <input type=hidden name=category>
1228 <input type=hidden name=subcategory>
1229 <input type=hidden name=item>
1230 <input type=hidden name=content>
1231 <?php
1233 if (!$out_of_encounter) { //do not do stuff that is encounter specific if not in an encounter
1235 <input type=button name='submit form' value='<?php xl('Submit All Content','e'); ?>' onClick="js_button('submit','submit')">
1236 <input type=button name='submit form' value='<?php xl('Submit Selected Content','e'); ?>' onClick="js_button('submit','submit_selection')">
1237 <?php
1241 <?php
1243 if (!$out_of_encounter) { //do not do stuff that is encounter specific if not in an encounter
1244 echo "<a href='".$GLOBALS['webroot'] . "/interface/patient_file/encounter/$returnurl' onclick='top.restoreSession()'>[".xl('Leave The Form')."]</a>";
1245 echo "<a href='".$GLOBALS['webroot'] . "/interface/forms/CAMOS/help.html' target='new'> | [".xl('Help')."]</a>";
1246 // echo $previous_encounter_data; //probably don't need anymore now that we have clone last visit
1249 </div>
1250 </form>
1251 </div>
1252 <?php
1253 formFooter();
1255 //PHP FUNCTIONS
1257 function fixquotes ($string) {
1258 // this function is needed to treat a string before php echos it in the process of generating javascript.
1259 // commented out below line because I have replaced single quotes around php that generates javascript with double quotes so single quotes don't have to be 'fixed'.
1260 // $string = preg_replace('/([\\\])*\'/', "\\\'", $string);
1261 $string = preg_replace('/([\\\])*\"/', "\\\"", $string);
1262 return $string;
1265 function searchName($string) { //match one or more names and return clause for query of pids
1266 $string = trim($string);
1267 if ($string == 'this') {
1268 return " and (pid = ".$_SESSION['pid'].") ";
1270 global $limit;
1271 $ret = '';
1272 $data = array();
1273 $fname = '';
1274 $lname = '';
1275 if ($string == '') {return $ret;}
1276 $split = preg_split('/\s+/',$string);
1277 $name1 = $split[1];
1278 $name2 = $split[0];
1279 if ($name1 != '') {$name1 = "%".$name1."%";}
1280 if ($name2 != '') {$name1 = "%".$name2."%";}
1281 $query = sqlStatement("select pid from patient_data where fname like '$name1' or fname like '$name2' or " .
1282 "lname like '$name1' or lname like '$name2' limit $limit");
1283 while ($results = sqlFetchArray($query)) {
1284 array_push($data,$results['pid']);
1286 if (count($data) > 0) {
1287 $ret = join(" or pid = ",$data);
1288 $ret = " and (pid = ".$ret.") ";
1290 return $ret;
1292 function getMyPatientData($form_id, $show_phone_flag) {//return a string of patient data and encounter data based on the form_CAMOS id
1293 $ret = '';
1294 $name = '';
1295 $dob = '';
1296 $enc_date = '';
1297 $phone_list = '';
1298 $pid = '';
1299 $query = sqlStatement("select t1.pid, t1.fname, t1.mname, t1.lname, " .
1300 "t1.phone_home, t1.phone_biz, t1.phone_contact, t1.phone_cell, " .
1301 "date_format(t1.DOB,'%m-%d-%y') as DOB, date_format(t2.date,'%m-%d-%y') as date, " .
1302 "datediff(current_date(),t2.date) as days " .
1303 "from patient_data as t1 join forms as t2 on (t1.pid = t2.pid) where t2.form_id=$form_id " .
1304 "and form_name like 'CAMOS%'");
1305 if ($results = sqlFetchArray($query)) {
1306 $pid = $results['pid'];
1307 $fname = $results['fname'];
1308 $mname = $results['mname'];
1309 $lname = $results['lname'];
1310 if ($mname) {$name = $fname.' '.$mname.' '.$lname;}
1311 else {$name = $fname.' '.$lname;}
1312 $dob = $results['DOB'];
1313 $enc_date = $results['date'];
1314 $days_ago = $results['days'];
1315 $phone_list =
1316 "/* Home: ".$results['phone_home']." | ".
1317 "Cell: ".$results['phone_cell']." | ".
1318 "Bus: ".$results['phone_biz']." | ".
1319 "Contact: ".$results['phone_contact']." */";
1321 $ret = "/*$pid, $name, DOB: $dob, Enc: $enc_date, $days_ago days ago. */";
1322 if ($show_phone_flag === true) {
1323 $ret .= "\n".$phone_list;
1325 return $ret;