more organization of autoloaded files (#424)
[openemr.git] / interface / forms / CAMOS / new.php
blob9ee15e3c32b8d67afccddc81cf93320ea35a2d04
1 <?php
2 include_once("../../globals.php");
3 include_once("../../../library/api.inc");
4 $out_of_encounter = false;
5 if ( (($_SESSION['encounter'] == '') || ($_SESSION['pid'] == '')) || ($_GET['mode'] == 'external')) {
6 $out_of_encounter = true;
8 // formHeader("Form: CAMOS");
9 $returnurl = 'encounter_top.php';
10 function myauth() {
11 return 1;
16 <?php
18 $break = "/* ---------------------------------- */"; //break between clone items
19 $delete_subdata = true; //true means allowing the deletion of subdata. If you delete a category, all subcategories and items go too.
20 $limit = 100;
21 $select_size = 20;
22 $textarea_rows = 20;
23 $textarea_cols = 80;
24 $debug = '';
25 $error = '';
27 $preselect_category = '';
28 $preselect_subcategory = '';
29 $preselect_item = '';
30 $preselect_category_override = '';
31 $preselect_subcategory_override = '';
32 $preselect_item_override = '';
34 $quote_search = array("\r","\n");
35 $quote_replace = array("\\r","\\n");
36 $quote_search_content = array("\r","\n");
37 $quote_replace_content = array("\\r","\\n");
38 $category = str_replace($quote_search,$quote_replace,$_POST['change_category']);
39 $subcategory = str_replace($quote_search,$quote_replace,$_POST['change_subcategory']);
40 $item = str_replace($quote_search,$quote_replace,$_POST['change_item']);
41 $content = str_replace($quote_search_content,$quote_replace_content,$_POST['textarea_content']);
42 if ($_POST['hidden_category']) {$preselect_category = $_POST['hidden_category'];}
43 if ($_POST['hidden_subcategory']) {$preselect_subcategory = $_POST['hidden_subcategory'];}
44 if ($_POST['hidden_item']) {$preselect_item = $_POST['hidden_item'];}
45 //handle changes to database
46 if (substr($_POST['hidden_mode'],0,3) == 'add') {
47 if ($_POST['hidden_selection'] == 'change_category') {
48 $preselect_category_override = $_POST['change_category'];
50 $category = formDataCore($category);
52 $query = "INSERT INTO ".mitigateSqlTableUpperCase("form_CAMOS_category")." (user, category) values ('".$_SESSION['authUser']."', '";
53 $query .= $category."')";
54 sqlInsert($query);
56 elseif ($_POST['hidden_selection'] == 'change_subcategory') {
57 $preselect_subcategory_override = $_POST['change_subcategory'];
58 $category_id = $_POST['hidden_category'];
59 if ($category_id >= 0 ) {
61 $subcategory = formDataCore($subcategory);
63 $query = "INSERT INTO ".mitigateSqlTableUpperCase("form_CAMOS_subcategory")." (user, subcategory, category_id) values ('".$_SESSION['authUser']."', '";
64 $query .= $subcategory."', '".$category_id."')";
65 sqlInsert($query);
68 elseif ($_POST['hidden_selection'] == 'change_item') {
69 $preselect_item_override = $_POST['change_item'];
70 $category_id = $_POST['hidden_category'];
71 $subcategory_id = $_POST['hidden_subcategory'];
72 if (($category_id >= 0 ) && ($subcategory_id >=0)) {
74 $item = formDataCore($item);
76 $query = "INSERT INTO ".mitigateSqlTableUpperCase("form_CAMOS_item")." (user, item, content, subcategory_id) values ('".$_SESSION['authUser']."', '";
77 $query .= $item."', '".$content."', '".$subcategory_id."')";
78 sqlInsert($query);
82 elseif ($_POST['hidden_selection'] == 'change_content') {
83 $item_id = $_POST['hidden_item'];
84 if ($item_id >= 0) {
85 if ($_POST['hidden_mode'] == 'add to') {
86 $tmp = sqlQuery("SELECT content from ".mitigateSqlTableUpperCase("form_CAMOS_item")." where id = ".$item_id);
87 if (isset($tmp)) {
88 $content .= "\n".$tmp['content'];
92 $content = add_escape_custom($content);
94 $query = "UPDATE ".mitigateSqlTableUpperCase("form_CAMOS_item")." set content = '".$content."' where id = ".$item_id;
95 sqlInsert($query);
99 elseif ($_POST['hidden_mode'] == 'delete') {
100 if ($delete_subdata) {
101 if ($_POST['hidden_selection'] == 'change_category') {
102 $to_delete_id = $_POST['hidden_category'];
103 $statement1 = sqlStatement("select id from ".mitigateSqlTableUpperCase("form_CAMOS_subcategory")." where category_id = ?", array($to_delete_id));
104 while ($result1 = sqlFetchArray($statement1)) {
105 $query = "DELETE FROM ".mitigateSqlTableUpperCase("form_CAMOS_item")." WHERE subcategory_id = ?";
106 sqlInsert($query, array($result1['id']));
108 $query = "DELETE FROM ".mitigateSqlTableUpperCase("form_CAMOS_subcategory")." WHERE category_id = ?";
109 sqlInsert($query, array($to_delete_id));
110 $query = "DELETE FROM ".mitigateSqlTableUpperCase("form_CAMOS_category")." WHERE id = ?";
111 sqlInsert($query, array($to_delete_id));
113 elseif ($_POST['hidden_selection'] == 'change_subcategory') {
114 $to_delete_id = $_POST['hidden_subcategory'];
115 $query = "DELETE FROM ".mitigateSqlTableUpperCase("form_CAMOS_item")." WHERE subcategory_id = ?";
116 sqlInsert($query, array($to_delete_id));
117 $query = "DELETE FROM ".mitigateSqlTableUpperCase("form_CAMOS_subcategory")." WHERE id = ?";
118 sqlInsert($query, array($to_delete_id));
120 elseif ($_POST['hidden_selection'] == 'change_item') {
121 if ((isset($_POST['select_item'])) && (count($_POST['select_item'])>1)) {
122 foreach($_POST['select_item'] as $v) {
123 $to_delete_id = $v;
124 $query = "DELETE FROM ".mitigateSqlTableUpperCase("form_CAMOS_item")." WHERE id = ?";
125 sqlInsert($query, array($to_delete_id));
127 } else {
128 $to_delete_id = $_POST['hidden_item'];
129 $query = "DELETE FROM ".mitigateSqlTableUpperCase("form_CAMOS_item")." WHERE id = ?";
130 sqlInsert($query, array($to_delete_id));
133 } else {
134 if ($_POST['hidden_selection'] == 'change_category') {
135 $to_delete_id = $_POST['hidden_category'];
136 $to_delete_from_table = 'form_CAMOS_category';
137 $to_delete_from_subtable = 'form_CAMOS_subcategory';
138 $to_delete_from_subsubtable = 'form_CAMOS_item';
139 $tablename = 'category';
140 $subtablename = 'subcategory';
141 $subsubtablename = 'item';
143 elseif ($_POST['hidden_selection'] == 'change_subcategory') {
144 $to_delete_id = $_POST['hidden_subcategory'];
145 $to_delete_from_table = 'form_CAMOS_subcategory';
146 $to_delete_from_subtable = 'form_CAMOS_item';
147 $tablename = 'subcategory';
148 $subtablename = 'item';
150 elseif ($_POST['hidden_selection'] == 'change_item') {
151 $to_delete_id = $_POST['hidden_item'];
152 $to_delete_from_table = 'form_CAMOS_item';
153 $to_delete_from_subtable = '';
154 $tablename = 'item';
155 $subtablename = '';
158 if ($subtablename == '') {
159 $query = "DELETE FROM ".escape_table_name($to_delete_from_table)." WHERE id like ?";
160 sqlInsert($query, array($to_delete_id));
162 else {
163 $query = "SELECT count(id) FROM ".escape_table_name($to_delete_from_subtable)." WHERE ".$tablename."_id like ?";
164 $statement = sqlStatement($query, array($to_delete_id));
165 if ($result = sqlFetchArray($statement)) {
166 if ($result['count(id)'] == 0) {
167 $query = "DELETE FROM ".escape_table_name($to_delete_from_table)." WHERE id like ?";
168 sqlInsert($query, array($to_delete_id));
170 else {
171 $error = $subtablename." not empty!";
177 elseif ($_POST['hidden_mode'] == 'alter') {
178 $newval = $_POST[$_POST['hidden_selection']];
179 if ($_POST['hidden_selection'] == 'change_category') {
180 $to_alter_id = $_POST['hidden_category'];
181 $to_alter_table = 'form_CAMOS_category';
182 $to_alter_column = 'category';
184 elseif ($_POST['hidden_selection'] == 'change_subcategory') {
185 $to_alter_id = $_POST['hidden_subcategory'];
186 $to_alter_table = 'form_CAMOS_subcategory';
187 $to_alter_column = 'subcategory';
189 elseif ($_POST['hidden_selection'] == 'change_item') {
190 $to_alter_id = $_POST['hidden_item'];
191 $to_alter_table = 'form_CAMOS_item';
192 $to_alter_column = 'item';
194 sqlInsert("UPDATE ".escape_table_name($to_alter_table)." set ".$to_alter_column." = ? where id = ?", array($newval, $to_alter_id));
197 //preselect column items
198 //either a database change has been made, so the user should be made to feel that they never left the same CAMOS screen
199 //or, CAMOS has been started freshly, therefore the last entry of the current patient should be selected.
200 $preselect_mode = '';
201 if ($preselect_category == '' && !$out_of_encounter) {
202 $preselect_mode = 'by name';
203 //at this point, if this variable has not been set, CAMOS must have been start over
204 //so let's get the most recent values from form_CAMOS for this patient's pid
205 $tmp = sqlQuery("SELECT max(id) AS max FROM ".mitigateSqlTableUpperCase("form_CAMOS")." WHERE " .
206 "pid = '" . $_SESSION['pid'] . "'");
207 $maxid = $tmp['max'] ? $tmp['max'] : 0;
209 $query = "SELECT category, subcategory, item FROM ".mitigateSqlTableUpperCase("form_CAMOS")." WHERE id = $maxid";
210 $statement = sqlStatement($query);
211 if ($result = sqlFetchArray($statement)) {
212 $preselect_category = $result['category'];
213 $preselect_subcategory = $result['subcategory'];
214 $preselect_item = $result['item'];
216 else {$preselect_mode = '';}
218 else {
219 $preselect_mode = 'by number';
223 <html><head>
224 <link rel=stylesheet href="<?php echo $css_header;?>" type="text/css">
226 <script language="javascript" type="text/javascript">
228 var array1 = new Array();
229 var array2 = new Array();
230 var array3 = new Array();
231 var buffer = new Array();
232 var icd9_list = '';
233 var preselect_off = false;
234 var content_change_flag = false;
235 var lock_override_flag = false;
236 var columns_status = 'show';
237 var hs_status = false;
238 var vs_status = false;
239 var hide_tc02_status = false;
240 var clone_mode = false;
242 var crop_buffer = '';
243 var special_select_start = 0;
244 var special_select_end = 0;
246 <?php
248 if (substr($_POST['hidden_mode'],0,5) == 'clone') {
249 echo "clone_mode = true;\n";
253 function clear_box(obj) {
254 var hold = obj.value;
255 obj.value = buffer[obj] ? buffer[obj] : '';
256 buffer[obj] = hold;
259 function showit() {
260 var log = document.getElementById('log');
261 var content = document.testform.testarea;
262 specialSelect(content,'/*','*/');
265 function specialSelect(t_area, delim_1, delim_2) {
266 if (crop_buffer != '') {
267 t_area.value = crop_buffer;
268 crop_buffer = '';
269 return;
271 var cv = t_area.value;
272 var start = t_area.selectionStart;
273 var end = t_area.selectionEnd;
274 var newstart = cv.lastIndexOf(delim_1, start);
275 var newend = cv.indexOf(delim_2, end);
276 if ((newstart == -1) || (newend == -1)) {return;}
277 if ((newstart == special_select_start) && (newend == special_select_end)) {
278 cropToSelect(t_area, delim_2);
280 if (newstart >= 0 && newend >= 0) {
281 t_area.selectionStart = newstart;
282 t_area.selectionEnd = newend+delim_2.length;
284 special_select_start = newstart;
285 special_select_end = newend;
288 function cropToSelect(t_area, delim_2) {
289 var cv = t_area.value;
290 crop_buffer = cv;
291 var start = special_select_start;
292 var end = special_select_end+delim_2.length;
293 var length = end-start;
294 t_area.value = cv.substr(start,length);
297 function hide_columns() {
298 var column01 = document.getElementById('id_category_column');
299 var column02 = document.getElementById('id_subcategory_column');
300 var column03 = document.getElementById('id_item_column');
301 var columnheader01 = document.getElementById('id_category_column_header');
302 var columnheader02 = document.getElementById('id_subcategory_column_header');
303 var columnheader03 = document.getElementById('id_item_column_header');
305 if (columns_status == 'show') {
306 columns_status = 'hide';
307 column01.style.display = 'none';
308 column02.style.display = 'none';
309 column03.style.display = 'none';
310 columnheader01.style.display = 'none';
311 columnheader02.style.display = 'none';
312 columnheader03.style.display = 'none';
314 else {
315 columns_status = 'show';
316 column01.style.display = 'inline';
317 column02.style.display = 'inline';
318 column03.style.display = 'inline';
319 columnheader01.style.display = 'inline';
320 columnheader02.style.display = 'inline';
321 columnheader03.style.display = 'inline';
323 resize_content();
325 function resize_content() {
326 f2 = document.CAMOS;
327 f4 = f2.textarea_content
328 if (f4.cols == <?php echo $textarea_cols ?>) {
329 f4.cols = <?php echo $textarea_cols ?>*2;
330 f4.rows = <?php echo $textarea_rows?>;
331 } else {
332 f4.cols = <?php echo $textarea_cols ?>;
333 f4.rows = <?php echo $textarea_rows?>;
336 //function hs_button() {
337 // f2 = document.CAMOS;
338 // if (hs_status) {
339 // hide_columns();
340 // f2.textarea_content.cols /= 3;
341 // f2.textarea_content02.cols /= 3;
342 // hs_status = false;
343 // } else {
344 // hide_columns();
345 //// f2.textarea_content.cols *= 3;
346 // f2.textarea_content02.cols *= 3;
347 // hs_status = true;
348 // }
353 //deal with locking of content = prevent accidental overwrite
355 function trimString (str) {
356 str = this != window? this : str;
357 return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
359 function isLocked() {
360 f2 = document.CAMOS;
361 if (lock_override_flag) {
362 lock_override_flag = false;
363 return false;
365 return /\/\*\s*lock\s*\:\:\s*\*\//.test(f2.textarea_content.value);
367 function lock_content() {
368 f2 = document.CAMOS;
369 if ((trimString(f2.textarea_content.value) != "") && (!isLocked())) {
370 f2.textarea_content.value = f2.textarea_content.value + "\n\n" + "/*lock::*/";
371 lock_override_flag = true;
372 js_button('add','change_content');
375 function allSelected() {
376 var f2 = document.CAMOS;
377 if ( (f2.select_category.selectedIndex < 0) || (f2.select_subcategory.selectedIndex < 0) || (f2["select_item[]"].selectedIndex < 0) ) {
378 return false; //one of the columns is not selected
380 else {
381 return true; //all columns have a selection
385 function content_focus() {
386 if (content_change_flag == false) {
387 if (!allSelected()) {
388 // alert("If you add text to the 'content' box without a selection in each column (category, subcategory, item), you will likely lose your work.")
391 else {return;}
392 content_change_flag = true;
394 function content_blur() {
395 if (content_change_flag == true) {
396 content_change_flag = false;
399 <?php
401 if (!$out_of_encounter) { //do not do stuff that is encounter specific if not in an encounter
402 //ICD9
403 $icd9_flag = false;
404 $query = "SELECT code_text, code FROM billing WHERE encounter=".$_SESSION['encounter'].
405 " AND pid=".$_SESSION['pid']." AND code_type like 'ICD9' AND activity=1";
406 $statement = sqlStatement($query);
407 if ($result = sqlFetchArray($statement)) {
408 $icd9_flag = true;
409 echo "icd9_list = \"\\n\\n\\\n";
410 echo $result['code']." ".$result['code_text']."\\n\\\n";
412 while ($result = sqlFetchArray($statement)) {
413 echo $result['code']." ".$result['code_text']."\\n\\\n";
415 if ($icd9_flag) {echo "\";\n";}
418 $query = "SELECT id, category FROM ".mitigateSqlTableUpperCase("form_CAMOS_category")." ORDER BY category";
419 $statement = sqlStatement($query);
420 $i = 0;
421 while ($result = sqlFetchArray($statement)) {
422 echo "array1[".$i."] = new Array(\"".fixquotes($result['category'])."\",\"".$result['id']."\", new Array());\n";
423 $i++;
425 $i=0;
426 $query = "SELECT id, subcategory, category_id FROM ".mitigateSqlTableUpperCase("form_CAMOS_subcategory")." ORDER BY subcategory";
427 $statement = sqlStatement($query);
428 while ($result = sqlFetchArray($statement)) {
429 echo "array2[".$i."] = new Array(\"".fixquotes($result['subcategory'])."\", \"".$result['category_id']."\", \"".$result['id']."\", new Array());\n";
430 $i++;
432 $i=0;
433 $query = "SELECT id, item, content, subcategory_id FROM ".mitigateSqlTableUpperCase("form_CAMOS_item")." ORDER BY item";
434 $statement = sqlStatement($query);
435 while ($result = sqlFetchArray($statement)) {
436 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'].
437 "\",\"".$result['id']."\");\n";
438 $i++;
442 function append_icd9() {
443 var f2 = document.CAMOS;
444 f2.textarea_content.value = f2.textarea_content.value + icd9_list;
447 function select_word(mode, mystring, myselect) { //take a string and select it in a select box if present
448 if (preselect_off) return 0;
449 for (var i=0;i<myselect.length;i++) {
450 var match = '';
451 if (mode == 'by name') {
452 match = myselect.options[i].text;
454 else if (mode == 'by number') {
455 match = myselect.options[i].value;
457 else {return 0;}
458 if (match == mystring) {
459 myselect.selectedIndex = i;
462 return 1;
464 <?php
466 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.
467 //if (!$out_of_encounter) { //do not do stuff that is encounter specific if not in an encounter
468 //cloning - similar process to preselect set to first time starting CAMOS
469 //as above
470 $clone_category = '';
471 $clone_subcategory = '';
472 $clone_item = '';
473 $clone_content = '';
474 $clone_data1 = '';
475 $clone_data2 = '';
476 $clone_data_array = array();
477 if (substr($_POST['hidden_mode'],0,5) == 'clone') {
478 $clone_category = $_POST['category'] ? $_POST['category'] : '';
479 $clone_category_term = '';
480 if ($clone_category != '') {
481 $clone_category_term = " where category like '".$clone_category."'";
483 $clone_subcategory = $_POST['subcategory'] ? $_POST['subcategory'] : '';
484 $clone_subcategory_term = '';
485 if ($clone_subcategory != '') {
486 $clone_subcategory_term = " and subcategory like '".$_POST['subcategory']."'";
488 $clone_item = $_POST['item'] ? $_POST['item'] : '';
489 $clone_item_term = '';
490 if ($clone_item != '') {
491 $clone_item_term = " and item like '".$_POST['item']."'";
493 $clone_search = trim($_POST['clone_others_search']);
495 $name_data_flag = false; //flag to see if we are going to use patient names in search result of clone others.
496 $show_phone_flag = false; //if we do show patient names, flag to see if we show phone numbers too
497 $pid_clause = ''; //if name search, will return a limited list of names to search for.
498 if (strpos($clone_search, "::") !== false) {
499 $name_data_flag = true;
500 $show_phone_flag = true;
501 $split = preg_split('/\s*::\s*/', $clone_search);
502 $clone_search = $split[1];
503 $pid_clause = searchName($split[0]);
505 elseif (strpos($clone_search, ":") !== false) {
506 $name_data_flag = true;
507 $split = preg_split('/\s*:\s*/', $clone_search);
508 $clone_search = $split[1];
509 $pid_clause = searchName($split[0]);
512 $clone_search_term = '';
513 if ($clone_search != '') {
514 $clone_search = preg_replace('/\s+/', '%', $clone_search);
515 if (substr($clone_search,0,1) == "`") {
516 $clone_subcategory_term = '';
517 $clone_item_term = '';
518 $clone_search = substr($clone_search,1);
520 $clone_search_term = " and content like '%$clone_search%'";
522 if (substr($_POST['hidden_mode'],0,12) == 'clone others') {
524 if (preg_match('/^(export)(.*)/',$clone_search,$matches)) {
525 $query1 = "select id, category from ".mitigateSqlTableUpperCase("form_CAMOS_category");
526 $statement1 = sqlStatement($query1);
527 while ($result1 = sqlFetchArray($statement1)) {
528 $tmp = $result1['category'];
529 $tmp = "/*import::category::$tmp*/"."\n";
530 $clone_data_array[$tmp] = $tmp;
531 $query2 = "select id,subcategory from ".mitigateSqlTableUpperCase("form_CAMOS_subcategory")." where category_id= ?";
532 $statement2 = sqlStatement($query2, $result1['id']);
533 while ($result2 = sqlFetchArray($statement2)) {
534 $tmp = $result2['subcategory'];
535 $tmp = "/*import::subcategory::$tmp*/"."\n";
536 $clone_data_array[$tmp] = $tmp;
537 $query3 = "select item, content from ".mitigateSqlTableUpperCase("form_CAMOS_item")." where subcategory_id=".$result2['id'];
538 $statement3 = sqlStatement($query3);
539 while ($result3 = sqlFetchArray($statement3)) {
540 $tmp = $result3['item'];
541 $tmp = "/*import::item::$tmp*/"."\n";
542 $clone_data_array[$tmp] = $tmp;
543 $tmp = $result3['content'];
544 $tmp = "/*import::content::$tmp*/"."\n";
545 $clone_data_array[$tmp] = $tmp;
549 $clone_data_array = array();
551 elseif ((preg_match('/^(billing)(.*)/',$clone_search,$matches)) ||
552 (preg_match('/^(codes)(.*)/',$clone_search,$matches))) {
553 $table = $matches[1];
554 $line = $matches[2];
555 $line = '%'.trim($line).'%';
556 $search_term = preg_replace('/\s+/','%',$line);
557 $query = "select code, code_type,code_text,modifier,units,fee from $table where code_text like ? limit $limit";
558 $statement = sqlStatement($query, array($search_term));
559 while ($result = sqlFetchArray($statement)) {
560 $code_type = $result['code_type'];
561 if ($code_type == 1) {$code_type = 'CPT4';}
562 if ($code_type == 2) {$code_type = 'ICD9';}
563 if ($code_type == 3) {$code_type = 'OTHER';}
564 $code = $result['code'];
565 $code_text = $result['code_text'];
566 $modifier = $result['modifier'];
567 $units = $result['units'];
568 $fee = $result['fee'];
569 $tmp = "/*billing::$code_type::$code::$code_text::$modifier::$units::$fee*/";
570 $clone_data_array[$tmp] = $tmp;
572 } else {
573 //$clone_data_array['others'] = '/*'.$clone_category.'::'.$clone_subcategory.'::'.
574 // $clone_item.'*/';
575 //See the two lines commented out just below:
576 //I am trying out searching all content regardless of category, subcategory, item...
577 //because of this, we have to limit results more. There may be a few lines
578 //above that should be deleted if this becomes the normal way of doing these searches.
579 //Consider making the two queries below by encounter instead of camos id.
580 //This may be a little tricky.
581 if ($_POST['hidden_mode'] == 'clone others selected') { //clone from search box
582 $query = "select id, category, subcategory, item, content from ".mitigateSqlTableUpperCase("form_CAMOS")." ".
583 $clone_category_term.$clone_subcategory_term.$clone_item_term.
584 $clone_search_term.$pid_clause." order by id desc limit $limit";
585 } else {
586 $query = "select id, category, subcategory, item, content from ".mitigateSqlTableUpperCase("form_CAMOS")." ".
587 " where " .
588 //"category like '%$clone_search%' or" .
589 //" subcategory like '%$clone_search%' or" .
590 //" item like '%$clone_search%' or" .
591 " content like '%$clone_search%'".$pid_clause." order by id desc limit $limit";
593 $statement = sqlStatement($query);
594 while ($result = sqlFetchArray($statement)) {
595 $tmp = '/*camos::'.$result['category'].'::'.$result['subcategory'].
596 '::'.$result['item'].'::'.$result['content'].'*/';
597 if ($name_data_flag === true) {
598 $tmp = getMyPatientData($result['id'],$show_phone_flag)."\n$break\n".$tmp;
600 $key_tmp = preg_replace('/\W+/','',$tmp);
601 $key_tmp = preg_replace('/\W+/','',$tmp);
602 $clone_data_array[$key_tmp] = $tmp;
605 } else {//end of clone others
606 $query = "SELECT date(date) as date, subcategory, item, content FROM ".mitigateSqlTableUpperCase("form_CAMOS")." WHERE category like '".
607 $clone_category."' and pid=".$_SESSION['pid']." order by id desc";
609 if ($_POST['hidden_mode'] == 'clone last visit') {
610 //go back $stepback # of encounters...
611 //This has been changed to clone last visit based on actual last encounter rather than as it was
612 //only looking at most recent BILLED encounters. To go back to billed encounters, change the following
613 //two queries to the 'billing' table rather than form_encounter and make sure to add in 'and activity=1'
614 //OK, now I have tried tracking last encounter from billing, then form_encounter. Now, we are going to
615 //try from forms where form_name like 'CAMOS%' so we will not bother with encounters that have no CAMOS entries...
616 $stepback = $_POST['stepback'] ? $_POST['stepback'] : 1;
617 $tmp = sqlQuery("SELECT max(encounter) as max FROM forms where encounter < " .
618 $_SESSION['encounter'] . " and form_name like 'CAMOS%' and pid= " . $_SESSION['pid']);
619 $last_encounter_id = $tmp['max'] ? $tmp['max'] : 0;
620 for ($i=0;$i<$stepback-1;$i++) {
621 $tmp = sqlQuery("SELECT max(encounter) as max FROM forms where encounter < " .
622 $last_encounter_id . " and form_name like 'CAMOS%' and pid= " . $_SESSION['pid']);
623 $last_encounter_id = $tmp['max'] ? $tmp['max'] : 0;
625 $query = "SELECT category, subcategory, item, content FROM ".mitigateSqlTableUpperCase("form_CAMOS")." " .
626 "join forms on (".mitigateSqlTableUpperCase("form_CAMOS").".id = forms.form_id) where " .
627 "forms.encounter = '$last_encounter_id' and ".mitigateSqlTableUpperCase("form_CAMOS").".pid=" .
628 $_SESSION['pid']." order by ".mitigateSqlTableUpperCase("form_CAMOS").".id";
630 $statement = sqlStatement($query);
631 while ($result = sqlFetchArray($statement)) {
632 if (preg_match('/^[\s\r\n]*$/',$result['content']) == 0) {
633 if ($_POST['hidden_mode'] == 'clone last visit') {
634 $clone_category = $result['category'];
636 $clone_subcategory = $result['subcategory'];
637 $clone_item = $result['item'];
638 $clone_content = $result['content'];
639 $clone_data1 = "/* camos :: $clone_category :: $clone_subcategory :: $clone_item :: ";
640 $clone_data2 = "$clone_content */";
641 $clone_data3 = $clone_data1 . $clone_data2;
642 if ($_POST['hidden_mode'] == 'clone last visit') {
643 $clone_data1 = $clone_data3; //make key include whole entry so all 'last visit' data gets recorded and shown
645 if (!$clone_data_array[$clone_data1]) { //if does not exist, don't overwrite.
646 $clone_data_array[$clone_data1] = "";
647 if ($_POST['hidden_mode'] == 'clone') {
648 $clone_data_array[$clone_data1] = "/* ------ ".$result['date']." --------- */\n"; //break between clone items
650 $clone_data_array[$clone_data1] .= $clone_data3;
654 if ($_POST['hidden_mode'] == 'clone last visit') {
655 $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'";
656 $statement = sqlStatement($query);
657 if ($result = sqlFetchArray($statement)) {
658 $weight = $result['weight'];
659 $height = $result['height'];
660 $bps = $result['bps'];
661 $bpd = $result['bpd'];
662 $pulse = $result['pulse'];
663 $temperature = $result['temperature'];
664 // $clone_vitals = "/* vitals_key:: weight :: height :: systolic :: diastolic :: pulse :: temperature */\n";
665 $clone_vitals = "";
666 $clone_vitals .= "/* vitals\n :: $weight\n :: $height\n :: $bps\n :: $bpd\n :: $pulse\n :: $temperature\n */";
667 $clone_data_array[$clone_vitals] = $clone_vitals;
669 $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";
670 $statement = sqlStatement($query);
671 while ($result = sqlFetchArray($statement)) {
672 $clone_code_type = $result['code_type'];
673 $clone_code = $result['code'];
674 $clone_code_text = $result['code_text'];
675 $clone_modifier = $result['modifier'];
676 $clone_units = $result['units'];
677 $clone_fee = $result['fee'];
679 //added ability to grab justifications also - bm
680 $clone_justify = "";
681 $clone_justify_raw = $result['justify'];
682 $clone_justify_array = explode(":",$clone_justify_raw);
683 foreach ($clone_justify_array as $temp_justify) {
684 trim($temp_justify);
685 if ($temp_justify != "") {
686 $clone_justify .= ":: ".$temp_justify." ";
690 $clone_billing_data = "/* billing :: $clone_code_type :: $clone_code :: $clone_code_text :: $clone_modifier :: $clone_units :: $clone_fee $clone_justify*/";
691 $clone_data_array[$clone_billing_data] = $clone_billing_data;
694 } //end else (not clone others)
695 }//end of clone stuff
696 //end preselect column items
699 function init() {
700 var f2 = document.CAMOS;
701 if (clone_mode) {
702 clone_mode = false;
704 for (i1=0;i1<array1.length;i1++) {
705 f2.select_category.options[f2.select_category.length] = new Option(array1[i1][0], array1[i1][1]);
707 <?php
709 $temp_preselect_mode = $preselect_mode;
710 if ($preselect_category_override != '') {
711 $temp_preselect_mode = "by name";
712 $preselect_category = $preselect_category_override;
715 if (select_word("<?php echo fixquotes($temp_preselect_mode)."\", \"".fixquotes($preselect_category); ?>" ,f2.select_category)) {
716 click_category();
718 <?php
720 if (substr($_POST['hidden_mode'],0,5) == 'clone') {
721 echo "f2.textarea_content.value = '';\n";
722 // echo "f2.textarea_content.value += '/* count = ".count($clone_data_array)."*/\\n$break\\n';";
723 echo "f2.textarea_content.value += '/* count = ".count($clone_data_array)."*/\\n$break\\n';";
724 foreach($clone_data_array as $key => $val) {
725 echo "f2.textarea_content.value = f2.textarea_content.value + \"".fixquotes(str_replace($quote_search,$quote_replace,$val))."\\n$break\\n\"\n";
732 function click_category() {
733 var f2 = document.CAMOS;
734 var category_index = f2.select_category.selectedIndex;
735 if ((category_index < 0) || (category_index > f2.select_category.length-1)) {return 0;}
736 var sel = f2.select_category.options[f2.select_category.selectedIndex].value;
737 for (var i1=0;i1<array1.length;i1++) {
738 if (array1[i1][1] == sel) {
739 f2.select_subcategory.length = 0;
740 f2["select_item[]"].length = 0;
741 f2.textarea_content.value = '';
742 for (var i2=0;i2<array2.length;i2++) {
743 if (array1[i1][1] == array2[i2][1]) {
744 f2.select_subcategory.options[f2.select_subcategory.length] = new Option(array2[i2][0], array2[i2][2]);
749 <?php
751 $temp_preselect_mode = $preselect_mode;
752 if ($preselect_subcategory_override != '') {
753 $temp_preselect_mode = "by name";
754 $preselect_subcategory = $preselect_subcategory_override;
757 if (select_word("<?php echo fixquotes($temp_preselect_mode)."\", \"".fixquotes($preselect_subcategory); ?>" ,f2.select_subcategory)) {
758 click_subcategory();
761 function click_subcategory() {
762 var f2 = document.CAMOS;
763 var subcategory_index = f2.select_subcategory.selectedIndex;
764 if ((subcategory_index < 0) || (subcategory_index > f2.select_subcategory.length-1)) {return 0;}
765 var sel = f2.select_subcategory.options[f2.select_subcategory.selectedIndex].value;
766 for (var i1=0;i1<array2.length;i1++) {
767 if (array2[i1][2] == sel) {
768 f2["select_item[]"].length = 0;
769 f2.textarea_content.value = '';
770 for (var i2=0;i2<array3.length;i2++) {
771 if (array2[i1][2] == array3[i2][2]) {
772 f2["select_item[]"].options[f2["select_item[]"].length] = new Option(array3[i2][0], array3[i2][3]);
777 <?php
779 $temp_preselect_mode = $preselect_mode;
780 if ($preselect_item_override != '') {
781 $temp_preselect_mode = "by name";
782 $preselect_item = $preselect_item_override;
785 if (select_word("<?php echo fixquotes($temp_preselect_mode)."\", \"".fixquotes($preselect_item); ?>" ,f2["select_item[]"])) {
786 click_item();
787 preselect_off = true;
790 function click_item() {
791 var f2 = document.CAMOS;
792 var item_index = f2["select_item[]"].selectedIndex;
793 if ((item_index < 0) || (item_index > f2["select_item[]"].length-1)) {return 0;}
794 var sel = f2["select_item[]"].options[item_index].value;
795 for (var i1=0;i1<array3.length;i1++) {
796 if (array3[i1][3] == sel) {
797 //diplay text in content box
798 f2.textarea_content.value= array3[i1][1].replace(/\\/g,'');
803 function selectContains(myselect, str) {
804 for (var i=0;i<myselect.length;i++) {
805 if (myselect.options[i].text == trimString(str)) {return true;}
809 function insert_content(direction) {
810 var f2 = document.CAMOS;
811 var source_box = f2.textarea_content;
812 var target_box = f2.textarea_content02;
813 if (direction == 'up') {
814 source_box = f2.textarea_content02;
815 target_box = f2.textarea_content;
817 var sba = source_box.selectionStart;
818 var sbb = source_box.selectionEnd;
819 var tba = target_box.selectionStart;
820 var tbb = target_box.selectionEnd;
821 if (sbb-sba == 0) {
822 sba = 0;
823 sbb = source_box.value.length;
825 var insert_text = (source_box.value).
826 substring(sba, sbb);
827 target_box.value = (target_box.value).
828 substring(0,tba) + insert_text +
829 (target_box.value).substring(tba,target_box.value.length);
832 //AJAX FUNCTIONS
833 //Function to create an XMLHttp Object.
834 function getxmlhttp (){
835 //Create a boolean variable to check for a valid microsoft active X instance.
836 var xmlhttp = false;
838 //Check if we are using internet explorer.
839 try {
840 //If the javascript version is greater than 5.
841 xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
842 } catch (e) {
843 //If not, then use the older active x object.
844 try {
845 //If we are using internet explorer.
846 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
847 } catch (E) {
848 //Else we must be using a non-internet explorer browser.
849 xmlhttp = false;
853 //If we are using a non-internet explorer browser, create a javascript instance of the object.
854 if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
855 xmlhttp = new XMLHttpRequest();
858 return xmlhttp;
861 //Function to process an XMLHttpRequest.
862 function processajax (serverPage, obj, getOrPost, str){
863 //Get an XMLHttpRequest object for use.
864 xmlhttp = getxmlhttp ();
865 if (getOrPost == "get"){
866 xmlhttp.open("GET", serverPage);
867 xmlhttp.onreadystatechange = function() {
868 if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
869 obj.innerHTML = xmlhttp.responseText;
872 xmlhttp.send(null);
873 } else {
874 xmlhttp.open("POST", serverPage, true);
875 xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
876 xmlhttp.onreadystatechange = function() {
877 if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
878 obj.innerHTML = xmlhttp.responseText;
881 xmlhttp.send(str);
886 function setformvalues(form_array){
888 //Run through a list of all objects
889 var str = '';
890 for(key in form_array) {
891 str += key + "=" + encodeURIComponent(form_array[key]) + "&";
893 //Then return the string values.
894 return str;
897 //END OF AJAX RELATED FUNCTIONS
899 function js_button(mode,selection) {
900 var f2 = document.CAMOS;
901 //check lock next
902 if ( (mode == 'add') && (selection == 'change_content') && (isLocked()) ) {
903 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"); ?>");
904 return;
906 //end check lock
908 //check for blank or duplicate submissions
909 if ( (mode == 'add') || (mode == 'alter') ) {
910 if (selection == 'change_category') {
911 if (trimString(f2.change_category.value) == "") {
912 alert("<?php xl("You cannot add a blank value for a category!","e"); ?>");
913 return;
915 if (selectContains(f2.select_category, trimString(f2.change_category.value))) {
916 alert("<?php xl("There is already a category named","e"); ?>"+" "+f2.change_category.value+".");
917 return;
920 if (selection == 'change_subcategory') {
921 if (trimString(f2.change_subcategory.value) == "") {
922 alert("<?php xl("You cannot add a blank value for a subcategory!","e"); ?>");
923 return;
925 if (selectContains(f2.select_subcategory, trimString(f2.change_subcategory.value))) {
926 alert("<?php xl("There is already a subcategory named","e"); ?>"+" "+f2.change_subcategory.value+".");
927 return;
930 if (selection == 'change_item') {
931 if (trimString(f2.change_item.value) == "") {
932 alert("<?php xl("You cannot add a blank value for an item!","e"); ?>");
933 return;
935 if (selectContains(f2["select_item[]"], trimString(f2.change_item.value))) {
936 alert("<?php xl("There is already an item named","e"); ?>"+" "+f2.change_item.value+".");
937 return;
941 //end of check for blank or duplicate submissions
943 if (mode == 'delete') {
944 if (!confirm("<?php xl("Are you sure you want to delete this item from the database?","e"); ?>")) {
945 return;
948 //check selections and assign variable values
949 var f2 = document.CAMOS;
950 var category_index = f2.select_category.selectedIndex;
951 var category_value;
952 var category_text;
953 if (category_index < 0) {
954 if ((selection == 'change_subcategory') || (selection == 'change_item') ||
955 (selection == 'change_content')) {
956 // alert ('You have not selected a category!');
957 return;
959 category_value = -1;
960 category_text = '';
962 else {
963 category_value = f2.select_category.options[category_index].value;
964 category_text = f2.select_category.options[category_index].text;
966 var subcategory_index = f2.select_subcategory.selectedIndex;
967 var subcategory_value;
968 var subcategory_text;
969 if (subcategory_index < 0) {
970 if ((selection == 'change_item') || (selection == 'change_content')) {
971 // alert ('You have not selected a subcategory!');
972 return;
974 subcategory_value = -1;
975 subcategory_text = '';
977 else {
978 subcategory_value = f2.select_subcategory.options[subcategory_index].value;
979 subcategory_text = f2.select_subcategory.options[subcategory_index].text;
981 var item_index = f2["select_item[]"].selectedIndex;
982 var item_value;
983 var item_text;
984 if (item_index < 0) {
985 if (selection == 'change_content') {
986 // alert ('You have not selected an item!');
987 return;
989 item_value = -1;
990 item_text = '';
992 else {
993 item_value = f2["select_item[]"].options[item_index].value;
994 item_text = f2["select_item[]"].options[item_index].text;
996 f2.category.value = category_text;
997 f2.subcategory.value = subcategory_text;
998 f2.item.value = item_text;
999 //end of setting values relating to selections
1001 //deal with clone buttons or add, alter, delete.
1002 if ( (mode.substr(0,5) == 'clone') || (mode == 'add') || (mode == 'add to') ||
1003 (mode == 'alter') || (mode =='delete') ) {
1004 f2.hidden_mode.value = mode;
1005 f2.hidden_selection.value = selection;
1006 f2.hidden_category.value = category_value;
1007 f2.hidden_subcategory.value = subcategory_value;
1008 f2.hidden_item.value = item_value;
1009 <?php
1010 if (!$out_of_encounter) {
1012 f2.action = '<?php print $GLOBALS['webroot'] ?>/interface/patient_file/encounter/load_form.php?formname=CAMOS';
1013 <?php
1014 } else {
1016 f2.action = '<?php print $GLOBALS['webroot'] ?>/interface/forms/CAMOS/new.php?mode=external';
1017 <?php
1020 f2.target = '_self';
1021 f2.submit();
1022 return;
1024 //ajax code
1025 var myobj = document.getElementById('id_info');
1026 myarray = new Array();
1027 myarray['category'] = category_text;
1028 myarray['subcategory'] = subcategory_text;
1029 myarray['item'] = item_text;
1030 myarray['content']
1031 if (selection == 'submit_selection') {
1032 myarray['content'] = (f2.textarea_content.value).substring(f2.textarea_content.selectionStart, f2.textarea_content.selectionEnd);
1034 else {myarray['content'] = f2.textarea_content.value;}
1035 var str = setformvalues(myarray);
1036 // alert(str);
1037 processajax ('<?php print $GLOBALS['webroot'] ?>/interface/forms/CAMOS/ajax_save.php', myobj, "post", str);
1038 // alert("submitted!");
1039 //ajax code
1042 function selectItem () {
1043 f2 = document.CAMOS;
1044 f2.item.value=f2["select_item[]"].options[f2["select_item[]"].selectedIndex].text;
1045 f2.content.value = f2.textarea_content.value;
1047 function getKey(e) { //process keypresses with getKeyPress
1048 var keynum;
1049 if(window.event) { //IE
1050 keynum = e.keyCode;
1051 } else if(e.which) { // Netscape/Firefox/Opera
1052 keynum = e.which;
1054 return keynum;
1056 function gotoOne(e) {
1057 if (getKey(e) == 96) {
1058 document.CAMOS.clone_others_search.focus();
1061 function processEnter(e,message) {
1062 if (getKey(e) == 13) {
1063 if (message == "clone_others_search") {
1064 js_button('clone others', 'clone others');
1069 </script>
1070 </head>
1071 <body <?php echo $top_bg_line;?> topmargin=0 rightmargin=0 leftmargin=2 bottommargin=0 marginwidth=2 marginheight=0 onload="init()">
1072 <div name="form_container" onKeyPress="gotoOne(event)">
1073 <form method=post action="<?php echo $rootdir;?>/forms/CAMOS/save.php?mode=new" name="CAMOS">
1074 <?php
1075 if (!$out_of_encounter) {
1076 // echo "<h1>$out_of_encounter</h1>\n";
1078 <input type=button name=clone value='<?php xl('Clone','e'); ?>' onClick="js_button('clone', 'clone')">
1079 <input type=button name=clone_visit value='<?php xl('Clone Past Visit','e'); ?>' onClick="js_button('clone last visit', 'clone last visit')">
1080 <select name=stepback>
1081 <option value=1><?php xl('Back one visit','e'); ?></option>
1082 <option value=2><?php xl('Back two visits','e'); ?></option>
1083 <option value=3><?php xl('Back three visits','e'); ?></option>
1084 <option value=4><?php xl('Back four visits','e'); ?></option>
1085 <option value=5><?php xl('Back five visits','e'); ?></option>
1086 <option value=6><?php xl('Back six visits','e'); ?></option>
1087 <option value=7><?php xl('Back seven visits','e'); ?></option>
1088 <option value=8><?php xl('Back eight visits','e'); ?></option>
1089 <option value=9><?php xl('Back nine visits','e'); ?></option>
1090 <option value=10><?php xl('Back ten visits','e'); ?></option>
1091 <option value=11><?php xl('Back eleven visits','e'); ?></option>
1092 <option value=12><?php xl('Back twelve visits','e'); ?></option>
1093 </select>
1094 <?php
1095 echo "<a href='".$GLOBALS['webroot'] . "/interface/patient_file/encounter/$returnurl' onclick='top.restoreSession()'>[".xl('Leave The Form')."]</a>";
1097 <input type=button name='hide columns' value='<?php xl('Hide/Show Columns','e'); ?>' onClick="hide_columns()">
1098 <input type=button name='submit form' value='<?php xl('Submit Selected Content','e'); ?>' onClick="js_button('submit','submit_selection')">
1099 <?php
1100 } //end of if !$out_of_encounter
1102 <div id=id_info style="display:inline">
1103 <!-- supposedly where ajax induced php pages can print their output to... -->
1104 </div>
1105 <div id=id_mainbox style="display:inline">
1106 <?php
1107 if ($error != '') {
1108 echo "<h1> error: ".$error."</h1>\n";
1111 <table border=1>
1112 <tr>
1113 <td>
1114 <div id=id_category_column_header style="display:inline">
1115 <?php xl('Category',e)?>
1116 </div> <!-- end of id_category_column_header -->
1117 </td>
1118 <td>
1119 <div id=id_subcategory_column_header style="display:inline">
1120 <?php xl('Subcategory',e)?>
1121 </div> <!-- end of id_subcategory_column_header -->
1122 </td>
1123 <td>
1124 <div id=id_item_column_header style="display:inline">
1125 <?php xl('Item',e)?>
1126 </div> <!-- end of id_item_column_header -->
1127 </td>
1128 <td>
1129 <?php xl('Content',e)?>
1130 </td>
1131 </tr>
1133 <tr>
1134 <td>
1135 <div id=id_category_column style="display:inline">
1136 <select name=select_category size=<?php echo $select_size ?> onchange="click_category()"></select><br>
1137 <?php
1139 if (myAuth() == 1) {//root user only can see administration option
1141 <input type=text name=change_category><br>
1142 <input type=button name=add1 value='<?php xl('add','e'); ?>' onClick="js_button('add','change_category')">
1143 <input type=button name=alter1 value='<?php xl('alter','e'); ?>' onClick="js_button('alter','change_category')">
1144 <input type=button name=del1 value='<?php xl('del','e'); ?>' onClick="js_button('delete','change_category')"><br>
1145 <?php
1149 </div> <!-- end of id_category_column -->
1150 </td>
1151 <td>
1152 <div id=id_subcategory_column style="display:inline">
1153 <select name=select_subcategory size=<?php echo $select_size ?> onchange="click_subcategory()"></select><br>
1154 <?php
1156 if (myAuth() == 1) {//root user only can see administration option
1158 <input type=text name=change_subcategory><br>
1159 <input type=button name=add2 value='<?php xl('add','e'); ?>' onClick="js_button('add','change_subcategory')">
1160 <input type=button name=alter1 value='<?php xl('alter','e'); ?>' onClick="js_button('alter','change_subcategory')">
1161 <input type=button name=del2 value='<?php xl('del','e'); ?>' onClick="js_button('delete','change_subcategory')"><br>
1162 <?php
1166 </div> <!-- end of id_subcategory_column -->
1167 </td>
1168 <td>
1169 <div id=id_item_column style="display:inline">
1170 <select name=select_item[] size=<?php echo $select_size ?> onchange="click_item()" multiple="multiple"></select><br>
1171 <?php
1173 if (myAuth() == 1) {//root user only can see administration option
1175 <input type=text name=change_item><br>
1176 <input type=button name=add3 value='<?php xl('add','e'); ?>' onClick="js_button('add','change_item')">
1177 <input type=button name=alter1 value='<?php xl('alter','e'); ?>' onClick="js_button('alter','change_item')">
1178 <input type=button name=del3 value='<?php xl('del','e'); ?>' onClick="js_button('delete','change_item')"><br>
1179 <?php
1183 </div> <!-- end of id_item_column -->
1184 </td>
1185 <td>
1186 <div id=id_textarea_content style="display:inline">
1187 <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>
1188 <br/>
1189 <input type=text size=35 name=clone_others_search value='<?php echo $_POST['clone_others_search'] ?>' tabindex=1 onKeyPress="processEnter(event,'clone_others_search')"/>
1190 <input type=button name=clone_others_search_button value='<?php xl('Search','e'); ?>' onClick="js_button('clone others', 'clone others')"/>
1191 <input type=button name=clone_others_selected_search_button value='<?php xl('Search Selected','e'); ?>' onClick="js_button('clone others selected', 'clone others selected')"/>
1192 <?php
1194 if (myAuth() == 1) {//root user only can see administration option
1196 <div id=id_main_content_buttons style="display:block">
1197 <input type=button name=add4 value='<?php xl('Add','e'); ?>' onClick="js_button('add','change_content')">
1198 <input type=button name=add4 value='<?php xl('Add to','e'); ?>' onClick="js_button('add to','change_content')">
1199 <input type=button name=lock value='<?php xl('Lock','e'); ?>' onClick="lock_content()">
1200 <?php
1202 if (!$out_of_encounter) { //do not do stuff that is encounter specific if not in an encounter
1204 <input type=button name=icd9 value='<?php xl('ICD9','e'); ?>' onClick="append_icd9()">
1205 </div> <!-- end of id_main_content_buttons-->
1206 <?php
1210 <?php
1214 </td>
1215 </td>
1216 </tr>
1217 </table>
1219 <input type=hidden name=hidden_mode>
1220 <input type=hidden name=hidden_selection>
1221 <input type=hidden name=hidden_category>
1222 <input type=hidden name=hidden_subcategory>
1223 <input type=hidden name=hidden_item>
1225 <input type=hidden name=category>
1226 <input type=hidden name=subcategory>
1227 <input type=hidden name=item>
1228 <input type=hidden name=content>
1229 <?php
1231 if (!$out_of_encounter) { //do not do stuff that is encounter specific if not in an encounter
1233 <input type=button name='submit form' value='<?php xl('Submit All Content','e'); ?>' onClick="js_button('submit','submit')">
1234 <input type=button name='submit form' value='<?php xl('Submit Selected Content','e'); ?>' onClick="js_button('submit','submit_selection')">
1235 <?php
1239 <?php
1241 if (!$out_of_encounter) { //do not do stuff that is encounter specific if not in an encounter
1242 echo "<a href='".$GLOBALS['webroot'] . "/interface/patient_file/encounter/$returnurl' onclick='top.restoreSession()'>[".xl('Leave The Form')."]</a>";
1243 echo "<a href='".$GLOBALS['webroot'] . "/interface/forms/CAMOS/help.html' target='new'> | [".xl('Help')."]</a>";
1244 // echo $previous_encounter_data; //probably don't need anymore now that we have clone last visit
1247 </div>
1248 </form>
1249 </div>
1250 <?php
1251 formFooter();
1253 //PHP FUNCTIONS
1255 function fixquotes ($string) {
1256 // this function is needed to treat a string before php echos it in the process of generating javascript.
1257 // 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'.
1258 // $string = preg_replace('/([\\\])*\'/', "\\\'", $string);
1259 $string = preg_replace('/([\\\])*\"/', "\\\"", $string);
1260 return $string;
1263 function searchName($string) { //match one or more names and return clause for query of pids
1264 $string = trim($string);
1265 if ($string == 'this') {
1266 return " and (pid = ".$_SESSION['pid'].") ";
1268 global $limit;
1269 $ret = '';
1270 $data = array();
1271 $fname = '';
1272 $lname = '';
1273 if ($string == '') {return $ret;}
1274 $split = preg_split('/\s+/',$string);
1275 $name1 = $split[1];
1276 $name2 = $split[0];
1277 if ($name1 != '') {$name1 = "%".$name1."%";}
1278 if ($name2 != '') {$name1 = "%".$name2."%";}
1279 $query = sqlStatement("select pid from patient_data where fname like '$name1' or fname like '$name2' or " .
1280 "lname like '$name1' or lname like '$name2' limit $limit");
1281 while ($results = sqlFetchArray($query)) {
1282 array_push($data,$results['pid']);
1284 if (count($data) > 0) {
1285 $ret = join(" or pid = ",$data);
1286 $ret = " and (pid = ".$ret.") ";
1288 return $ret;
1290 function getMyPatientData($form_id, $show_phone_flag) {//return a string of patient data and encounter data based on the form_CAMOS id
1291 $ret = '';
1292 $name = '';
1293 $dob = '';
1294 $enc_date = '';
1295 $phone_list = '';
1296 $pid = '';
1297 $query = sqlStatement("select t1.pid, t1.fname, t1.mname, t1.lname, " .
1298 "t1.phone_home, t1.phone_biz, t1.phone_contact, t1.phone_cell, " .
1299 "date_format(t1.DOB,'%m-%d-%y') as DOB, date_format(t2.date,'%m-%d-%y') as date, " .
1300 "datediff(current_date(),t2.date) as days " .
1301 "from patient_data as t1 join forms as t2 on (t1.pid = t2.pid) where t2.form_id=$form_id " .
1302 "and form_name like 'CAMOS%'");
1303 if ($results = sqlFetchArray($query)) {
1304 $pid = $results['pid'];
1305 $fname = $results['fname'];
1306 $mname = $results['mname'];
1307 $lname = $results['lname'];
1308 if ($mname) {$name = $fname.' '.$mname.' '.$lname;}
1309 else {$name = $fname.' '.$lname;}
1310 $dob = $results['DOB'];
1311 $enc_date = $results['date'];
1312 $days_ago = $results['days'];
1313 $phone_list =
1314 "/* Home: ".$results['phone_home']." | ".
1315 "Cell: ".$results['phone_cell']." | ".
1316 "Bus: ".$results['phone_biz']." | ".
1317 "Contact: ".$results['phone_contact']." */";
1319 $ret = "/*$pid, $name, DOB: $dob, Enc: $enc_date, $days_ago days ago. */";
1320 if ($show_phone_flag === true) {
1321 $ret .= "\n".$phone_list;
1323 return $ret;