Highway to PSR2
[openemr.git] / interface / forms / CAMOS / new.php
blobfb7c4250b690e1411b72a2577f65d564105a717a
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;
9 // formHeader("Form: CAMOS");
10 $returnurl = 'encounter_top.php';
11 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']) {
45 $preselect_category = $_POST['hidden_category'];
48 if ($_POST['hidden_subcategory']) {
49 $preselect_subcategory = $_POST['hidden_subcategory'];
52 if ($_POST['hidden_item']) {
53 $preselect_item = $_POST['hidden_item'];
56 //handle changes to database
57 if (substr($_POST['hidden_mode'], 0, 3) == 'add') {
58 if ($_POST['hidden_selection'] == 'change_category') {
59 $preselect_category_override = $_POST['change_category'];
61 $category = formDataCore($category);
63 $query = "INSERT INTO ".mitigateSqlTableUpperCase("form_CAMOS_category")." (user, category) values ('".$_SESSION['authUser']."', '";
64 $query .= $category."')";
65 sqlInsert($query);
66 } elseif ($_POST['hidden_selection'] == 'change_subcategory') {
67 $preselect_subcategory_override = $_POST['change_subcategory'];
68 $category_id = $_POST['hidden_category'];
69 if ($category_id >= 0) {
70 $subcategory = formDataCore($subcategory);
72 $query = "INSERT INTO ".mitigateSqlTableUpperCase("form_CAMOS_subcategory")." (user, subcategory, category_id) values ('".$_SESSION['authUser']."', '";
73 $query .= $subcategory."', '".$category_id."')";
74 sqlInsert($query);
76 } elseif ($_POST['hidden_selection'] == 'change_item') {
77 $preselect_item_override = $_POST['change_item'];
78 $category_id = $_POST['hidden_category'];
79 $subcategory_id = $_POST['hidden_subcategory'];
80 if (($category_id >= 0 ) && ($subcategory_id >=0)) {
81 $item = formDataCore($item);
83 $query = "INSERT INTO ".mitigateSqlTableUpperCase("form_CAMOS_item")." (user, item, content, subcategory_id) values ('".$_SESSION['authUser']."', '";
84 $query .= $item."', '".$content."', '".$subcategory_id."')";
85 sqlInsert($query);
87 } elseif ($_POST['hidden_selection'] == 'change_content') {
88 $item_id = $_POST['hidden_item'];
89 if ($item_id >= 0) {
90 if ($_POST['hidden_mode'] == 'add to') {
91 $tmp = sqlQuery("SELECT content from ".mitigateSqlTableUpperCase("form_CAMOS_item")." where id = ".$item_id);
92 if (isset($tmp)) {
93 $content .= "\n".$tmp['content'];
97 $content = add_escape_custom($content);
99 $query = "UPDATE ".mitigateSqlTableUpperCase("form_CAMOS_item")." set content = '".$content."' where id = ".$item_id;
100 sqlInsert($query);
103 } elseif ($_POST['hidden_mode'] == 'delete') {
104 if ($delete_subdata) {
105 if ($_POST['hidden_selection'] == 'change_category') {
106 $to_delete_id = $_POST['hidden_category'];
107 $statement1 = sqlStatement("select id from ".mitigateSqlTableUpperCase("form_CAMOS_subcategory")." where category_id = ?", array($to_delete_id));
108 while ($result1 = sqlFetchArray($statement1)) {
109 $query = "DELETE FROM ".mitigateSqlTableUpperCase("form_CAMOS_item")." WHERE subcategory_id = ?";
110 sqlInsert($query, array($result1['id']));
113 $query = "DELETE FROM ".mitigateSqlTableUpperCase("form_CAMOS_subcategory")." WHERE category_id = ?";
114 sqlInsert($query, array($to_delete_id));
115 $query = "DELETE FROM ".mitigateSqlTableUpperCase("form_CAMOS_category")." WHERE id = ?";
116 sqlInsert($query, array($to_delete_id));
117 } elseif ($_POST['hidden_selection'] == 'change_subcategory') {
118 $to_delete_id = $_POST['hidden_subcategory'];
119 $query = "DELETE FROM ".mitigateSqlTableUpperCase("form_CAMOS_item")." WHERE subcategory_id = ?";
120 sqlInsert($query, array($to_delete_id));
121 $query = "DELETE FROM ".mitigateSqlTableUpperCase("form_CAMOS_subcategory")." WHERE id = ?";
122 sqlInsert($query, array($to_delete_id));
123 } elseif ($_POST['hidden_selection'] == 'change_item') {
124 if ((isset($_POST['select_item'])) && (count($_POST['select_item'])>1)) {
125 foreach ($_POST['select_item'] as $v) {
126 $to_delete_id = $v;
127 $query = "DELETE FROM ".mitigateSqlTableUpperCase("form_CAMOS_item")." WHERE id = ?";
128 sqlInsert($query, array($to_delete_id));
130 } else {
131 $to_delete_id = $_POST['hidden_item'];
132 $query = "DELETE FROM ".mitigateSqlTableUpperCase("form_CAMOS_item")." WHERE id = ?";
133 sqlInsert($query, array($to_delete_id));
136 } else {
137 if ($_POST['hidden_selection'] == 'change_category') {
138 $to_delete_id = $_POST['hidden_category'];
139 $to_delete_from_table = 'form_CAMOS_category';
140 $to_delete_from_subtable = 'form_CAMOS_subcategory';
141 $to_delete_from_subsubtable = 'form_CAMOS_item';
142 $tablename = 'category';
143 $subtablename = 'subcategory';
144 $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';
151 } elseif ($_POST['hidden_selection'] == 'change_item') {
152 $to_delete_id = $_POST['hidden_item'];
153 $to_delete_from_table = 'form_CAMOS_item';
154 $to_delete_from_subtable = '';
155 $tablename = 'item';
156 $subtablename = '';
159 if ($subtablename == '') {
160 $query = "DELETE FROM ".escape_table_name($to_delete_from_table)." WHERE id like ?";
161 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));
169 } else {
170 $error = $subtablename." not empty!";
175 } elseif ($_POST['hidden_mode'] == 'alter') {
176 $newval = $_POST[$_POST['hidden_selection']];
177 if ($_POST['hidden_selection'] == 'change_category') {
178 $to_alter_id = $_POST['hidden_category'];
179 $to_alter_table = 'form_CAMOS_category';
180 $to_alter_column = 'category';
181 } elseif ($_POST['hidden_selection'] == 'change_subcategory') {
182 $to_alter_id = $_POST['hidden_subcategory'];
183 $to_alter_table = 'form_CAMOS_subcategory';
184 $to_alter_column = 'subcategory';
185 } elseif ($_POST['hidden_selection'] == 'change_item') {
186 $to_alter_id = $_POST['hidden_item'];
187 $to_alter_table = 'form_CAMOS_item';
188 $to_alter_column = 'item';
191 sqlInsert("UPDATE ".escape_table_name($to_alter_table)." set ".$to_alter_column." = ? where id = ?", array($newval, $to_alter_id));
194 //preselect column items
195 //either a database change has been made, so the user should be made to feel that they never left the same CAMOS screen
196 //or, CAMOS has been started freshly, therefore the last entry of the current patient should be selected.
197 $preselect_mode = '';
198 if ($preselect_category == '' && !$out_of_encounter) {
199 $preselect_mode = 'by name';
200 //at this point, if this variable has not been set, CAMOS must have been start over
201 //so let's get the most recent values from form_CAMOS for this patient's pid
202 $tmp = sqlQuery("SELECT max(id) AS max FROM ".mitigateSqlTableUpperCase("form_CAMOS")." WHERE " .
203 "pid = '" . $_SESSION['pid'] . "'");
204 $maxid = $tmp['max'] ? $tmp['max'] : 0;
206 $query = "SELECT category, subcategory, item FROM ".mitigateSqlTableUpperCase("form_CAMOS")." WHERE id = $maxid";
207 $statement = sqlStatement($query);
208 if ($result = sqlFetchArray($statement)) {
209 $preselect_category = $result['category'];
210 $preselect_subcategory = $result['subcategory'];
211 $preselect_item = $result['item'];
212 } else {
213 $preselect_mode = '';
215 } else {
216 $preselect_mode = 'by number';
220 <html><head>
221 <link rel=stylesheet href="<?php echo $css_header;?>" type="text/css">
223 <script language="javascript" type="text/javascript">
225 var array1 = new Array();
226 var array2 = new Array();
227 var array3 = new Array();
228 var buffer = new Array();
229 var icd9_list = '';
230 var preselect_off = false;
231 var content_change_flag = false;
232 var lock_override_flag = false;
233 var columns_status = 'show';
234 var hs_status = false;
235 var vs_status = false;
236 var hide_tc02_status = false;
237 var clone_mode = false;
239 var crop_buffer = '';
240 var special_select_start = 0;
241 var special_select_end = 0;
243 <?php
245 if (substr($_POST['hidden_mode'], 0, 5) == 'clone') {
246 echo "clone_mode = true;\n";
250 function clear_box(obj) {
251 var hold = obj.value;
252 obj.value = buffer[obj] ? buffer[obj] : '';
253 buffer[obj] = hold;
256 function showit() {
257 var log = document.getElementById('log');
258 var content = document.testform.testarea;
259 specialSelect(content,'/*','*/');
262 function specialSelect(t_area, delim_1, delim_2) {
263 if (crop_buffer != '') {
264 t_area.value = crop_buffer;
265 crop_buffer = '';
266 return;
268 var cv = t_area.value;
269 var start = t_area.selectionStart;
270 var end = t_area.selectionEnd;
271 var newstart = cv.lastIndexOf(delim_1, start);
272 var newend = cv.indexOf(delim_2, end);
273 if ((newstart == -1) || (newend == -1)) {return;}
274 if ((newstart == special_select_start) && (newend == special_select_end)) {
275 cropToSelect(t_area, delim_2);
277 if (newstart >= 0 && newend >= 0) {
278 t_area.selectionStart = newstart;
279 t_area.selectionEnd = newend+delim_2.length;
281 special_select_start = newstart;
282 special_select_end = newend;
285 function cropToSelect(t_area, delim_2) {
286 var cv = t_area.value;
287 crop_buffer = cv;
288 var start = special_select_start;
289 var end = special_select_end+delim_2.length;
290 var length = end-start;
291 t_area.value = cv.substr(start,length);
294 function hide_columns() {
295 var column01 = document.getElementById('id_category_column');
296 var column02 = document.getElementById('id_subcategory_column');
297 var column03 = document.getElementById('id_item_column');
298 var columnheader01 = document.getElementById('id_category_column_header');
299 var columnheader02 = document.getElementById('id_subcategory_column_header');
300 var columnheader03 = document.getElementById('id_item_column_header');
302 if (columns_status == 'show') {
303 columns_status = 'hide';
304 column01.style.display = 'none';
305 column02.style.display = 'none';
306 column03.style.display = 'none';
307 columnheader01.style.display = 'none';
308 columnheader02.style.display = 'none';
309 columnheader03.style.display = 'none';
311 else {
312 columns_status = 'show';
313 column01.style.display = 'inline';
314 column02.style.display = 'inline';
315 column03.style.display = 'inline';
316 columnheader01.style.display = 'inline';
317 columnheader02.style.display = 'inline';
318 columnheader03.style.display = 'inline';
320 resize_content();
322 function resize_content() {
323 f2 = document.CAMOS;
324 f4 = f2.textarea_content
325 if (f4.cols == <?php echo $textarea_cols ?>) {
326 f4.cols = <?php echo $textarea_cols ?>*2;
327 f4.rows = <?php echo $textarea_rows?>;
328 } else {
329 f4.cols = <?php echo $textarea_cols ?>;
330 f4.rows = <?php echo $textarea_rows?>;
333 //function hs_button() {
334 // f2 = document.CAMOS;
335 // if (hs_status) {
336 // hide_columns();
337 // f2.textarea_content.cols /= 3;
338 // f2.textarea_content02.cols /= 3;
339 // hs_status = false;
340 // } else {
341 // hide_columns();
342 //// f2.textarea_content.cols *= 3;
343 // f2.textarea_content02.cols *= 3;
344 // hs_status = true;
345 // }
350 //deal with locking of content = prevent accidental overwrite
352 function trimString (str) {
353 str = this != window? this : str;
354 return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
356 function isLocked() {
357 f2 = document.CAMOS;
358 if (lock_override_flag) {
359 lock_override_flag = false;
360 return false;
362 return /\/\*\s*lock\s*\:\:\s*\*\//.test(f2.textarea_content.value);
364 function lock_content() {
365 f2 = document.CAMOS;
366 if ((trimString(f2.textarea_content.value) != "") && (!isLocked())) {
367 f2.textarea_content.value = f2.textarea_content.value + "\n\n" + "/*lock::*/";
368 lock_override_flag = true;
369 js_button('add','change_content');
372 function allSelected() {
373 var f2 = document.CAMOS;
374 if ( (f2.select_category.selectedIndex < 0) || (f2.select_subcategory.selectedIndex < 0) || (f2["select_item[]"].selectedIndex < 0) ) {
375 return false; //one of the columns is not selected
377 else {
378 return true; //all columns have a selection
382 function content_focus() {
383 if (content_change_flag == false) {
384 if (!allSelected()) {
385 // alert("If you add text to the 'content' box without a selection in each column (category, subcategory, item), you will likely lose your work.")
388 else {return;}
389 content_change_flag = true;
391 function content_blur() {
392 if (content_change_flag == true) {
393 content_change_flag = false;
396 <?php
398 if (!$out_of_encounter) { //do not do stuff that is encounter specific if not in an encounter
399 //ICD9
400 $icd9_flag = false;
401 $query = "SELECT code_text, code FROM billing WHERE encounter=".$_SESSION['encounter'].
402 " AND pid=".$_SESSION['pid']." AND code_type like 'ICD9' AND activity=1";
403 $statement = sqlStatement($query);
404 if ($result = sqlFetchArray($statement)) {
405 $icd9_flag = true;
406 echo "icd9_list = \"\\n\\n\\\n";
407 echo $result['code']." ".$result['code_text']."\\n\\\n";
410 while ($result = sqlFetchArray($statement)) {
411 echo $result['code']." ".$result['code_text']."\\n\\\n";
414 if ($icd9_flag) {
415 echo "\";\n";
419 $query = "SELECT id, category FROM ".mitigateSqlTableUpperCase("form_CAMOS_category")." ORDER BY category";
420 $statement = sqlStatement($query);
421 $i = 0;
422 while ($result = sqlFetchArray($statement)) {
423 echo "array1[".$i."] = new Array(\"".fixquotes($result['category'])."\",\"".$result['id']."\", new Array());\n";
424 $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++;
435 $i=0;
436 $query = "SELECT id, item, content, subcategory_id FROM ".mitigateSqlTableUpperCase("form_CAMOS_item")." ORDER BY item";
437 $statement = sqlStatement($query);
438 while ($result = sqlFetchArray($statement)) {
439 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'].
440 "\",\"".$result['id']."\");\n";
441 $i++;
445 function append_icd9() {
446 var f2 = document.CAMOS;
447 f2.textarea_content.value = f2.textarea_content.value + icd9_list;
450 function select_word(mode, mystring, myselect) { //take a string and select it in a select box if present
451 if (preselect_off) return 0;
452 for (var i=0;i<myselect.length;i++) {
453 var match = '';
454 if (mode == 'by name') {
455 match = myselect.options[i].text;
457 else if (mode == 'by number') {
458 match = myselect.options[i].value;
460 else {return 0;}
461 if (match == mystring) {
462 myselect.selectedIndex = i;
465 return 1;
467 <?php
469 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.
470 //if (!$out_of_encounter) { //do not do stuff that is encounter specific if not in an encounter
471 //cloning - similar process to preselect set to first time starting CAMOS
472 //as above
473 $clone_category = '';
474 $clone_subcategory = '';
475 $clone_item = '';
476 $clone_content = '';
477 $clone_data1 = '';
478 $clone_data2 = '';
479 $clone_data_array = array();
480 if (substr($_POST['hidden_mode'], 0, 5) == 'clone') {
481 $clone_category = $_POST['category'] ? $_POST['category'] : '';
482 $clone_category_term = '';
483 if ($clone_category != '') {
484 $clone_category_term = " where category like '".$clone_category."'";
487 $clone_subcategory = $_POST['subcategory'] ? $_POST['subcategory'] : '';
488 $clone_subcategory_term = '';
489 if ($clone_subcategory != '') {
490 $clone_subcategory_term = " and subcategory like '".$_POST['subcategory']."'";
493 $clone_item = $_POST['item'] ? $_POST['item'] : '';
494 $clone_item_term = '';
495 if ($clone_item != '') {
496 $clone_item_term = " and item like '".$_POST['item']."'";
499 $clone_search = trim($_POST['clone_others_search']);
501 $name_data_flag = false; //flag to see if we are going to use patient names in search result of clone others.
502 $show_phone_flag = false; //if we do show patient names, flag to see if we show phone numbers too
503 $pid_clause = ''; //if name search, will return a limited list of names to search for.
504 if (strpos($clone_search, "::") !== false) {
505 $name_data_flag = true;
506 $show_phone_flag = true;
507 $split = preg_split('/\s*::\s*/', $clone_search);
508 $clone_search = $split[1];
509 $pid_clause = searchName($split[0]);
510 } elseif (strpos($clone_search, ":") !== false) {
511 $name_data_flag = true;
512 $split = preg_split('/\s*:\s*/', $clone_search);
513 $clone_search = $split[1];
514 $pid_clause = searchName($split[0]);
517 $clone_search_term = '';
518 if ($clone_search != '') {
519 $clone_search = preg_replace('/\s+/', '%', $clone_search);
520 if (substr($clone_search, 0, 1) == "`") {
521 $clone_subcategory_term = '';
522 $clone_item_term = '';
523 $clone_search = substr($clone_search, 1);
526 $clone_search_term = " and content like '%$clone_search%'";
529 if (substr($_POST['hidden_mode'], 0, 12) == 'clone others') {
530 if (preg_match('/^(export)(.*)/', $clone_search, $matches)) {
531 $query1 = "select id, category from ".mitigateSqlTableUpperCase("form_CAMOS_category");
532 $statement1 = sqlStatement($query1);
533 while ($result1 = sqlFetchArray($statement1)) {
534 $tmp = $result1['category'];
535 $tmp = "/*import::category::$tmp*/"."\n";
536 $clone_data_array[$tmp] = $tmp;
537 $query2 = "select id,subcategory from ".mitigateSqlTableUpperCase("form_CAMOS_subcategory")." where category_id= ?";
538 $statement2 = sqlStatement($query2, $result1['id']);
539 while ($result2 = sqlFetchArray($statement2)) {
540 $tmp = $result2['subcategory'];
541 $tmp = "/*import::subcategory::$tmp*/"."\n";
542 $clone_data_array[$tmp] = $tmp;
543 $query3 = "select item, content from ".mitigateSqlTableUpperCase("form_CAMOS_item")." where subcategory_id=".$result2['id'];
544 $statement3 = sqlStatement($query3);
545 while ($result3 = sqlFetchArray($statement3)) {
546 $tmp = $result3['item'];
547 $tmp = "/*import::item::$tmp*/"."\n";
548 $clone_data_array[$tmp] = $tmp;
549 $tmp = $result3['content'];
550 $tmp = "/*import::content::$tmp*/"."\n";
551 $clone_data_array[$tmp] = $tmp;
556 $clone_data_array = array();
557 } elseif ((preg_match('/^(billing)(.*)/', $clone_search, $matches)) ||
558 (preg_match('/^(codes)(.*)/', $clone_search, $matches))) {
559 $table = $matches[1];
560 $line = $matches[2];
561 $line = '%'.trim($line).'%';
562 $search_term = preg_replace('/\s+/', '%', $line);
563 $query = "select code, code_type,code_text,modifier,units,fee from $table where code_text like ? limit $limit";
564 $statement = sqlStatement($query, array($search_term));
565 while ($result = sqlFetchArray($statement)) {
566 $code_type = $result['code_type'];
567 if ($code_type == 1) {
568 $code_type = 'CPT4';
571 if ($code_type == 2) {
572 $code_type = 'ICD9';
575 if ($code_type == 3) {
576 $code_type = 'OTHER';
579 $code = $result['code'];
580 $code_text = $result['code_text'];
581 $modifier = $result['modifier'];
582 $units = $result['units'];
583 $fee = $result['fee'];
584 $tmp = "/*billing::$code_type::$code::$code_text::$modifier::$units::$fee*/";
585 $clone_data_array[$tmp] = $tmp;
587 } else {
588 //$clone_data_array['others'] = '/*'.$clone_category.'::'.$clone_subcategory.'::'.
589 // $clone_item.'*/';
590 //See the two lines commented out just below:
591 //I am trying out searching all content regardless of category, subcategory, item...
592 //because of this, we have to limit results more. There may be a few lines
593 //above that should be deleted if this becomes the normal way of doing these searches.
594 //Consider making the two queries below by encounter instead of camos id.
595 //This may be a little tricky.
596 if ($_POST['hidden_mode'] == 'clone others selected') { //clone from search box
597 $query = "select id, category, subcategory, item, content from ".mitigateSqlTableUpperCase("form_CAMOS")." ".
598 $clone_category_term.$clone_subcategory_term.$clone_item_term.
599 $clone_search_term.$pid_clause." order by id desc limit $limit";
600 } else {
601 $query = "select id, category, subcategory, item, content from ".mitigateSqlTableUpperCase("form_CAMOS")." ".
602 " where " .
603 //"category like '%$clone_search%' or" .
604 //" subcategory like '%$clone_search%' or" .
605 //" item like '%$clone_search%' or" .
606 " content like '%$clone_search%'".$pid_clause." order by id desc limit $limit";
609 $statement = sqlStatement($query);
610 while ($result = sqlFetchArray($statement)) {
611 $tmp = '/*camos::'.$result['category'].'::'.$result['subcategory'].
612 '::'.$result['item'].'::'.$result['content'].'*/';
613 if ($name_data_flag === true) {
614 $tmp = getMyPatientData($result['id'], $show_phone_flag)."\n$break\n".$tmp;
617 $key_tmp = preg_replace('/\W+/', '', $tmp);
618 $key_tmp = preg_replace('/\W+/', '', $tmp);
619 $clone_data_array[$key_tmp] = $tmp;
622 } else {//end of clone others
623 $query = "SELECT date(date) as date, subcategory, item, content FROM ".mitigateSqlTableUpperCase("form_CAMOS")." WHERE category like '".
624 $clone_category."' and pid=".$_SESSION['pid']." order by id desc";
626 if ($_POST['hidden_mode'] == 'clone last visit') {
627 //go back $stepback # of encounters...
628 //This has been changed to clone last visit based on actual last encounter rather than as it was
629 //only looking at most recent BILLED encounters. To go back to billed encounters, change the following
630 //two queries to the 'billing' table rather than form_encounter and make sure to add in 'and activity=1'
631 //OK, now I have tried tracking last encounter from billing, then form_encounter. Now, we are going to
632 //try from forms where form_name like 'CAMOS%' so we will not bother with encounters that have no CAMOS entries...
633 $stepback = $_POST['stepback'] ? $_POST['stepback'] : 1;
634 $tmp = sqlQuery("SELECT max(encounter) as max FROM forms where encounter < " .
635 $_SESSION['encounter'] . " and form_name like 'CAMOS%' and pid= " . $_SESSION['pid']);
636 $last_encounter_id = $tmp['max'] ? $tmp['max'] : 0;
637 for ($i=0; $i<$stepback-1; $i++) {
638 $tmp = sqlQuery("SELECT max(encounter) as max FROM forms where encounter < " .
639 $last_encounter_id . " and form_name like 'CAMOS%' and pid= " . $_SESSION['pid']);
640 $last_encounter_id = $tmp['max'] ? $tmp['max'] : 0;
643 $query = "SELECT category, subcategory, item, content FROM ".mitigateSqlTableUpperCase("form_CAMOS")." " .
644 "join forms on (".mitigateSqlTableUpperCase("form_CAMOS").".id = forms.form_id) where " .
645 "forms.encounter = '$last_encounter_id' and ".mitigateSqlTableUpperCase("form_CAMOS").".pid=" .
646 $_SESSION['pid']." order by ".mitigateSqlTableUpperCase("form_CAMOS").".id";
649 $statement = sqlStatement($query);
650 while ($result = sqlFetchArray($statement)) {
651 if (preg_match('/^[\s\r\n]*$/', $result['content']) == 0) {
652 if ($_POST['hidden_mode'] == 'clone last visit') {
653 $clone_category = $result['category'];
656 $clone_subcategory = $result['subcategory'];
657 $clone_item = $result['item'];
658 $clone_content = $result['content'];
659 $clone_data1 = "/* camos :: $clone_category :: $clone_subcategory :: $clone_item :: ";
660 $clone_data2 = "$clone_content */";
661 $clone_data3 = $clone_data1 . $clone_data2;
662 if ($_POST['hidden_mode'] == 'clone last visit') {
663 $clone_data1 = $clone_data3; //make key include whole entry so all 'last visit' data gets recorded and shown
666 if (!$clone_data_array[$clone_data1]) { //if does not exist, don't overwrite.
667 $clone_data_array[$clone_data1] = "";
668 if ($_POST['hidden_mode'] == 'clone') {
669 $clone_data_array[$clone_data1] = "/* ------ ".$result['date']." --------- */\n"; //break between clone items
672 $clone_data_array[$clone_data1] .= $clone_data3;
677 if ($_POST['hidden_mode'] == 'clone last visit') {
678 $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'";
679 $statement = sqlStatement($query);
680 if ($result = sqlFetchArray($statement)) {
681 $weight = $result['weight'];
682 $height = $result['height'];
683 $bps = $result['bps'];
684 $bpd = $result['bpd'];
685 $pulse = $result['pulse'];
686 $temperature = $result['temperature'];
687 // $clone_vitals = "/* vitals_key:: weight :: height :: systolic :: diastolic :: pulse :: temperature */\n";
688 $clone_vitals = "";
689 $clone_vitals .= "/* vitals\n :: $weight\n :: $height\n :: $bps\n :: $bpd\n :: $pulse\n :: $temperature\n */";
690 $clone_data_array[$clone_vitals] = $clone_vitals;
693 $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";
694 $statement = sqlStatement($query);
695 while ($result = sqlFetchArray($statement)) {
696 $clone_code_type = $result['code_type'];
697 $clone_code = $result['code'];
698 $clone_code_text = $result['code_text'];
699 $clone_modifier = $result['modifier'];
700 $clone_units = $result['units'];
701 $clone_fee = $result['fee'];
703 //added ability to grab justifications also - bm
704 $clone_justify = "";
705 $clone_justify_raw = $result['justify'];
706 $clone_justify_array = explode(":", $clone_justify_raw);
707 foreach ($clone_justify_array as $temp_justify) {
708 trim($temp_justify);
709 if ($temp_justify != "") {
710 $clone_justify .= ":: ".$temp_justify." ";
714 $clone_billing_data = "/* billing :: $clone_code_type :: $clone_code :: $clone_code_text :: $clone_modifier :: $clone_units :: $clone_fee $clone_justify*/";
715 $clone_data_array[$clone_billing_data] = $clone_billing_data;
718 } //end else (not clone others)
719 }//end of clone stuff
720 //end preselect column items
723 function init() {
724 var f2 = document.CAMOS;
725 if (clone_mode) {
726 clone_mode = false;
728 for (i1=0;i1<array1.length;i1++) {
729 f2.select_category.options[f2.select_category.length] = new Option(array1[i1][0], array1[i1][1]);
731 <?php
733 $temp_preselect_mode = $preselect_mode;
734 if ($preselect_category_override != '') {
735 $temp_preselect_mode = "by name";
736 $preselect_category = $preselect_category_override;
739 if (select_word("<?php echo fixquotes($temp_preselect_mode)."\", \"".fixquotes($preselect_category); ?>" ,f2.select_category)) {
740 click_category();
742 <?php
744 if (substr($_POST['hidden_mode'], 0, 5) == 'clone') {
745 echo "f2.textarea_content.value = '';\n";
746 // echo "f2.textarea_content.value += '/* count = ".count($clone_data_array)."*/\\n$break\\n';";
747 echo "f2.textarea_content.value += '/* count = ".count($clone_data_array)."*/\\n$break\\n';";
748 foreach ($clone_data_array as $key => $val) {
749 echo "f2.textarea_content.value = f2.textarea_content.value + \"".fixquotes(str_replace($quote_search, $quote_replace, $val))."\\n$break\\n\"\n";
756 function click_category() {
757 var f2 = document.CAMOS;
758 var category_index = f2.select_category.selectedIndex;
759 if ((category_index < 0) || (category_index > f2.select_category.length-1)) {return 0;}
760 var sel = f2.select_category.options[f2.select_category.selectedIndex].value;
761 for (var i1=0;i1<array1.length;i1++) {
762 if (array1[i1][1] == sel) {
763 f2.select_subcategory.length = 0;
764 f2["select_item[]"].length = 0;
765 f2.textarea_content.value = '';
766 for (var i2=0;i2<array2.length;i2++) {
767 if (array1[i1][1] == array2[i2][1]) {
768 f2.select_subcategory.options[f2.select_subcategory.length] = new Option(array2[i2][0], array2[i2][2]);
773 <?php
775 $temp_preselect_mode = $preselect_mode;
776 if ($preselect_subcategory_override != '') {
777 $temp_preselect_mode = "by name";
778 $preselect_subcategory = $preselect_subcategory_override;
781 if (select_word("<?php echo fixquotes($temp_preselect_mode)."\", \"".fixquotes($preselect_subcategory); ?>" ,f2.select_subcategory)) {
782 click_subcategory();
785 function click_subcategory() {
786 var f2 = document.CAMOS;
787 var subcategory_index = f2.select_subcategory.selectedIndex;
788 if ((subcategory_index < 0) || (subcategory_index > f2.select_subcategory.length-1)) {return 0;}
789 var sel = f2.select_subcategory.options[f2.select_subcategory.selectedIndex].value;
790 for (var i1=0;i1<array2.length;i1++) {
791 if (array2[i1][2] == sel) {
792 f2["select_item[]"].length = 0;
793 f2.textarea_content.value = '';
794 for (var i2=0;i2<array3.length;i2++) {
795 if (array2[i1][2] == array3[i2][2]) {
796 f2["select_item[]"].options[f2["select_item[]"].length] = new Option(array3[i2][0], array3[i2][3]);
801 <?php
803 $temp_preselect_mode = $preselect_mode;
804 if ($preselect_item_override != '') {
805 $temp_preselect_mode = "by name";
806 $preselect_item = $preselect_item_override;
809 if (select_word("<?php echo fixquotes($temp_preselect_mode)."\", \"".fixquotes($preselect_item); ?>" ,f2["select_item[]"])) {
810 click_item();
811 preselect_off = true;
814 function click_item() {
815 var f2 = document.CAMOS;
816 var item_index = f2["select_item[]"].selectedIndex;
817 if ((item_index < 0) || (item_index > f2["select_item[]"].length-1)) {return 0;}
818 var sel = f2["select_item[]"].options[item_index].value;
819 for (var i1=0;i1<array3.length;i1++) {
820 if (array3[i1][3] == sel) {
821 //diplay text in content box
822 f2.textarea_content.value= array3[i1][1].replace(/\\/g,'');
827 function selectContains(myselect, str) {
828 for (var i=0;i<myselect.length;i++) {
829 if (myselect.options[i].text == trimString(str)) {return true;}
833 function insert_content(direction) {
834 var f2 = document.CAMOS;
835 var source_box = f2.textarea_content;
836 var target_box = f2.textarea_content02;
837 if (direction == 'up') {
838 source_box = f2.textarea_content02;
839 target_box = f2.textarea_content;
841 var sba = source_box.selectionStart;
842 var sbb = source_box.selectionEnd;
843 var tba = target_box.selectionStart;
844 var tbb = target_box.selectionEnd;
845 if (sbb-sba == 0) {
846 sba = 0;
847 sbb = source_box.value.length;
849 var insert_text = (source_box.value).
850 substring(sba, sbb);
851 target_box.value = (target_box.value).
852 substring(0,tba) + insert_text +
853 (target_box.value).substring(tba,target_box.value.length);
856 //AJAX FUNCTIONS
857 //Function to create an XMLHttp Object.
858 function getxmlhttp (){
859 //Create a boolean variable to check for a valid microsoft active X instance.
860 var xmlhttp = false;
862 //Check if we are using internet explorer.
863 try {
864 //If the javascript version is greater than 5.
865 xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
866 } catch (e) {
867 //If not, then use the older active x object.
868 try {
869 //If we are using internet explorer.
870 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
871 } catch (E) {
872 //Else we must be using a non-internet explorer browser.
873 xmlhttp = false;
877 //If we are using a non-internet explorer browser, create a javascript instance of the object.
878 if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
879 xmlhttp = new XMLHttpRequest();
882 return xmlhttp;
885 //Function to process an XMLHttpRequest.
886 function processajax (serverPage, obj, getOrPost, str){
887 //Get an XMLHttpRequest object for use.
888 xmlhttp = getxmlhttp ();
889 if (getOrPost == "get"){
890 xmlhttp.open("GET", serverPage);
891 xmlhttp.onreadystatechange = function() {
892 if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
893 obj.innerHTML = xmlhttp.responseText;
896 xmlhttp.send(null);
897 } else {
898 xmlhttp.open("POST", serverPage, true);
899 xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
900 xmlhttp.onreadystatechange = function() {
901 if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
902 obj.innerHTML = xmlhttp.responseText;
905 xmlhttp.send(str);
910 function setformvalues(form_array){
912 //Run through a list of all objects
913 var str = '';
914 for(key in form_array) {
915 str += key + "=" + encodeURIComponent(form_array[key]) + "&";
917 //Then return the string values.
918 return str;
921 //END OF AJAX RELATED FUNCTIONS
923 function js_button(mode,selection) {
924 var f2 = document.CAMOS;
925 //check lock next
926 if ( (mode == 'add') && (selection == 'change_content') && (isLocked()) ) {
927 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"); ?>");
928 return;
930 //end check lock
932 //check for blank or duplicate submissions
933 if ( (mode == 'add') || (mode == 'alter') ) {
934 if (selection == 'change_category') {
935 if (trimString(f2.change_category.value) == "") {
936 alert("<?php xl("You cannot add a blank value for a category!", "e"); ?>");
937 return;
939 if (selectContains(f2.select_category, trimString(f2.change_category.value))) {
940 alert("<?php xl("There is already a category named", "e"); ?>"+" "+f2.change_category.value+".");
941 return;
944 if (selection == 'change_subcategory') {
945 if (trimString(f2.change_subcategory.value) == "") {
946 alert("<?php xl("You cannot add a blank value for a subcategory!", "e"); ?>");
947 return;
949 if (selectContains(f2.select_subcategory, trimString(f2.change_subcategory.value))) {
950 alert("<?php xl("There is already a subcategory named", "e"); ?>"+" "+f2.change_subcategory.value+".");
951 return;
954 if (selection == 'change_item') {
955 if (trimString(f2.change_item.value) == "") {
956 alert("<?php xl("You cannot add a blank value for an item!", "e"); ?>");
957 return;
959 if (selectContains(f2["select_item[]"], trimString(f2.change_item.value))) {
960 alert("<?php xl("There is already an item named", "e"); ?>"+" "+f2.change_item.value+".");
961 return;
965 //end of check for blank or duplicate submissions
967 if (mode == 'delete') {
968 if (!confirm("<?php xl("Are you sure you want to delete this item from the database?", "e"); ?>")) {
969 return;
972 //check selections and assign variable values
973 var f2 = document.CAMOS;
974 var category_index = f2.select_category.selectedIndex;
975 var category_value;
976 var category_text;
977 if (category_index < 0) {
978 if ((selection == 'change_subcategory') || (selection == 'change_item') ||
979 (selection == 'change_content')) {
980 // alert ('You have not selected a category!');
981 return;
983 category_value = -1;
984 category_text = '';
986 else {
987 category_value = f2.select_category.options[category_index].value;
988 category_text = f2.select_category.options[category_index].text;
990 var subcategory_index = f2.select_subcategory.selectedIndex;
991 var subcategory_value;
992 var subcategory_text;
993 if (subcategory_index < 0) {
994 if ((selection == 'change_item') || (selection == 'change_content')) {
995 // alert ('You have not selected a subcategory!');
996 return;
998 subcategory_value = -1;
999 subcategory_text = '';
1001 else {
1002 subcategory_value = f2.select_subcategory.options[subcategory_index].value;
1003 subcategory_text = f2.select_subcategory.options[subcategory_index].text;
1005 var item_index = f2["select_item[]"].selectedIndex;
1006 var item_value;
1007 var item_text;
1008 if (item_index < 0) {
1009 if (selection == 'change_content') {
1010 // alert ('You have not selected an item!');
1011 return;
1013 item_value = -1;
1014 item_text = '';
1016 else {
1017 item_value = f2["select_item[]"].options[item_index].value;
1018 item_text = f2["select_item[]"].options[item_index].text;
1020 f2.category.value = category_text;
1021 f2.subcategory.value = subcategory_text;
1022 f2.item.value = item_text;
1023 //end of setting values relating to selections
1025 //deal with clone buttons or add, alter, delete.
1026 if ( (mode.substr(0,5) == 'clone') || (mode == 'add') || (mode == 'add to') ||
1027 (mode == 'alter') || (mode =='delete') ) {
1028 f2.hidden_mode.value = mode;
1029 f2.hidden_selection.value = selection;
1030 f2.hidden_category.value = category_value;
1031 f2.hidden_subcategory.value = subcategory_value;
1032 f2.hidden_item.value = item_value;
1033 <?php
1034 if (!$out_of_encounter) {
1036 f2.action = '<?php print $GLOBALS['webroot'] ?>/interface/patient_file/encounter/load_form.php?formname=CAMOS';
1037 <?php
1038 } else {
1040 f2.action = '<?php print $GLOBALS['webroot'] ?>/interface/forms/CAMOS/new.php?mode=external';
1041 <?php
1044 f2.target = '_self';
1045 f2.submit();
1046 return;
1048 //ajax code
1049 var myobj = document.getElementById('id_info');
1050 myarray = new Array();
1051 myarray['category'] = category_text;
1052 myarray['subcategory'] = subcategory_text;
1053 myarray['item'] = item_text;
1054 myarray['content']
1055 if (selection == 'submit_selection') {
1056 myarray['content'] = (f2.textarea_content.value).substring(f2.textarea_content.selectionStart, f2.textarea_content.selectionEnd);
1058 else {myarray['content'] = f2.textarea_content.value;}
1059 var str = setformvalues(myarray);
1060 // alert(str);
1061 processajax ('<?php print $GLOBALS['webroot'] ?>/interface/forms/CAMOS/ajax_save.php', myobj, "post", str);
1062 // alert("submitted!");
1063 //ajax code
1066 function selectItem () {
1067 f2 = document.CAMOS;
1068 f2.item.value=f2["select_item[]"].options[f2["select_item[]"].selectedIndex].text;
1069 f2.content.value = f2.textarea_content.value;
1071 function getKey(e) { //process keypresses with getKeyPress
1072 var keynum;
1073 if(window.event) { //IE
1074 keynum = e.keyCode;
1075 } else if(e.which) { // Netscape/Firefox/Opera
1076 keynum = e.which;
1078 return keynum;
1080 function gotoOne(e) {
1081 if (getKey(e) == 96) {
1082 document.CAMOS.clone_others_search.focus();
1085 function processEnter(e,message) {
1086 if (getKey(e) == 13) {
1087 if (message == "clone_others_search") {
1088 js_button('clone others', 'clone others');
1093 </script>
1094 </head>
1095 <body <?php echo $top_bg_line;?> topmargin=0 rightmargin=0 leftmargin=2 bottommargin=0 marginwidth=2 marginheight=0 onload="init()">
1096 <div name="form_container" onKeyPress="gotoOne(event)">
1097 <form method=post action="<?php echo $rootdir;?>/forms/CAMOS/save.php?mode=new" name="CAMOS">
1098 <?php
1099 if (!$out_of_encounter) {
1100 // echo "<h1>$out_of_encounter</h1>\n";
1102 <input type=button name=clone value='<?php xl('Clone', 'e'); ?>' onClick="js_button('clone', 'clone')">
1103 <input type=button name=clone_visit value='<?php xl('Clone Past Visit', 'e'); ?>' onClick="js_button('clone last visit', 'clone last visit')">
1104 <select name=stepback>
1105 <option value=1><?php xl('Back one visit', 'e'); ?></option>
1106 <option value=2><?php xl('Back two visits', 'e'); ?></option>
1107 <option value=3><?php xl('Back three visits', 'e'); ?></option>
1108 <option value=4><?php xl('Back four visits', 'e'); ?></option>
1109 <option value=5><?php xl('Back five visits', 'e'); ?></option>
1110 <option value=6><?php xl('Back six visits', 'e'); ?></option>
1111 <option value=7><?php xl('Back seven visits', 'e'); ?></option>
1112 <option value=8><?php xl('Back eight visits', 'e'); ?></option>
1113 <option value=9><?php xl('Back nine visits', 'e'); ?></option>
1114 <option value=10><?php xl('Back ten visits', 'e'); ?></option>
1115 <option value=11><?php xl('Back eleven visits', 'e'); ?></option>
1116 <option value=12><?php xl('Back twelve visits', 'e'); ?></option>
1117 </select>
1118 <?php
1119 echo "<a href='".$GLOBALS['webroot'] . "/interface/patient_file/encounter/$returnurl' onclick='top.restoreSession()'>[".xl('Leave The Form')."]</a>";
1121 <input type=button name='hide columns' value='<?php xl('Hide/Show Columns', 'e'); ?>' onClick="hide_columns()">
1122 <input type=button name='submit form' value='<?php xl('Submit Selected Content', 'e'); ?>' onClick="js_button('submit','submit_selection')">
1123 <?php
1124 } //end of if !$out_of_encounter
1126 <div id=id_info style="display:inline">
1127 <!-- supposedly where ajax induced php pages can print their output to... -->
1128 </div>
1129 <div id=id_mainbox style="display:inline">
1130 <?php
1131 if ($error != '') {
1132 echo "<h1> error: ".$error."</h1>\n";
1135 <table border=1>
1136 <tr>
1137 <td>
1138 <div id=id_category_column_header style="display:inline">
1139 <?php xl('Category', e)?>
1140 </div> <!-- end of id_category_column_header -->
1141 </td>
1142 <td>
1143 <div id=id_subcategory_column_header style="display:inline">
1144 <?php xl('Subcategory', e)?>
1145 </div> <!-- end of id_subcategory_column_header -->
1146 </td>
1147 <td>
1148 <div id=id_item_column_header style="display:inline">
1149 <?php xl('Item', e)?>
1150 </div> <!-- end of id_item_column_header -->
1151 </td>
1152 <td>
1153 <?php xl('Content', e)?>
1154 </td>
1155 </tr>
1157 <tr>
1158 <td>
1159 <div id=id_category_column style="display:inline">
1160 <select name=select_category size=<?php echo $select_size ?> onchange="click_category()"></select><br>
1161 <?php
1163 if (myAuth() == 1) {//root user only can see administration option
1165 <input type=text name=change_category><br>
1166 <input type=button name=add1 value='<?php xl('add', 'e'); ?>' onClick="js_button('add','change_category')">
1167 <input type=button name=alter1 value='<?php xl('alter', 'e'); ?>' onClick="js_button('alter','change_category')">
1168 <input type=button name=del1 value='<?php xl('del', 'e'); ?>' onClick="js_button('delete','change_category')"><br>
1169 <?php
1172 </div> <!-- end of id_category_column -->
1173 </td>
1174 <td>
1175 <div id=id_subcategory_column style="display:inline">
1176 <select name=select_subcategory size=<?php echo $select_size ?> onchange="click_subcategory()"></select><br>
1177 <?php
1179 if (myAuth() == 1) {//root user only can see administration option
1181 <input type=text name=change_subcategory><br>
1182 <input type=button name=add2 value='<?php xl('add', 'e'); ?>' onClick="js_button('add','change_subcategory')">
1183 <input type=button name=alter1 value='<?php xl('alter', 'e'); ?>' onClick="js_button('alter','change_subcategory')">
1184 <input type=button name=del2 value='<?php xl('del', 'e'); ?>' onClick="js_button('delete','change_subcategory')"><br>
1185 <?php
1188 </div> <!-- end of id_subcategory_column -->
1189 </td>
1190 <td>
1191 <div id=id_item_column style="display:inline">
1192 <select name=select_item[] size=<?php echo $select_size ?> onchange="click_item()" multiple="multiple"></select><br>
1193 <?php
1195 if (myAuth() == 1) {//root user only can see administration option
1197 <input type=text name=change_item><br>
1198 <input type=button name=add3 value='<?php xl('add', 'e'); ?>' onClick="js_button('add','change_item')">
1199 <input type=button name=alter1 value='<?php xl('alter', 'e'); ?>' onClick="js_button('alter','change_item')">
1200 <input type=button name=del3 value='<?php xl('del', 'e'); ?>' onClick="js_button('delete','change_item')"><br>
1201 <?php
1204 </div> <!-- end of id_item_column -->
1205 </td>
1206 <td>
1207 <div id=id_textarea_content style="display:inline">
1208 <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>
1209 <br/>
1210 <input type=text size=35 name=clone_others_search value='<?php echo $_POST['clone_others_search'] ?>' tabindex=1 onKeyPress="processEnter(event,'clone_others_search')"/>
1211 <input type=button name=clone_others_search_button value='<?php xl('Search', 'e'); ?>' onClick="js_button('clone others', 'clone others')"/>
1212 <input type=button name=clone_others_selected_search_button value='<?php xl('Search Selected', 'e'); ?>' onClick="js_button('clone others selected', 'clone others selected')"/>
1213 <?php
1215 if (myAuth() == 1) {//root user only can see administration option
1217 <div id=id_main_content_buttons style="display:block">
1218 <input type=button name=add4 value='<?php xl('Add', 'e'); ?>' onClick="js_button('add','change_content')">
1219 <input type=button name=add4 value='<?php xl('Add to', 'e'); ?>' onClick="js_button('add to','change_content')">
1220 <input type=button name=lock value='<?php xl('Lock', 'e'); ?>' onClick="lock_content()">
1221 <?php
1223 if (!$out_of_encounter) { //do not do stuff that is encounter specific if not in an encounter
1225 <input type=button name=icd9 value='<?php xl('ICD9', 'e'); ?>' onClick="append_icd9()">
1226 </div> <!-- end of id_main_content_buttons-->
1227 <?php
1230 <?php
1233 </td>
1234 </td>
1235 </tr>
1236 </table>
1238 <input type=hidden name=hidden_mode>
1239 <input type=hidden name=hidden_selection>
1240 <input type=hidden name=hidden_category>
1241 <input type=hidden name=hidden_subcategory>
1242 <input type=hidden name=hidden_item>
1244 <input type=hidden name=category>
1245 <input type=hidden name=subcategory>
1246 <input type=hidden name=item>
1247 <input type=hidden name=content>
1248 <?php
1250 if (!$out_of_encounter) { //do not do stuff that is encounter specific if not in an encounter
1252 <input type=button name='submit form' value='<?php xl('Submit All Content', 'e'); ?>' onClick="js_button('submit','submit')">
1253 <input type=button name='submit form' value='<?php xl('Submit Selected Content', 'e'); ?>' onClick="js_button('submit','submit_selection')">
1254 <?php
1257 <?php
1259 if (!$out_of_encounter) { //do not do stuff that is encounter specific if not in an encounter
1260 echo "<a href='".$GLOBALS['webroot'] . "/interface/patient_file/encounter/$returnurl' onclick='top.restoreSession()'>[".xl('Leave The Form')."]</a>";
1261 echo "<a href='".$GLOBALS['webroot'] . "/interface/forms/CAMOS/help.html' target='new'> | [".xl('Help')."]</a>";
1262 // echo $previous_encounter_data; //probably don't need anymore now that we have clone last visit
1265 </div>
1266 </form>
1267 </div>
1268 <?php
1269 formFooter();
1271 //PHP FUNCTIONS
1273 function fixquotes($string)
1275 // this function is needed to treat a string before php echos it in the process of generating javascript.
1276 // 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'.
1277 // $string = preg_replace('/([\\\])*\'/', "\\\'", $string);
1278 $string = preg_replace('/([\\\])*\"/', "\\\"", $string);
1279 return $string;
1282 function searchName($string)
1284 //match one or more names and return clause for query of pids
1285 $string = trim($string);
1286 if ($string == 'this') {
1287 return " and (pid = ".$_SESSION['pid'].") ";
1290 global $limit;
1291 $ret = '';
1292 $data = array();
1293 $fname = '';
1294 $lname = '';
1295 if ($string == '') {
1296 return $ret;
1299 $split = preg_split('/\s+/', $string);
1300 $name1 = $split[1];
1301 $name2 = $split[0];
1302 if ($name1 != '') {
1303 $name1 = "%".$name1."%";
1306 if ($name2 != '') {
1307 $name1 = "%".$name2."%";
1310 $query = sqlStatement("select pid from patient_data where fname like '$name1' or fname like '$name2' or " .
1311 "lname like '$name1' or lname like '$name2' limit $limit");
1312 while ($results = sqlFetchArray($query)) {
1313 array_push($data, $results['pid']);
1316 if (count($data) > 0) {
1317 $ret = join(" or pid = ", $data);
1318 $ret = " and (pid = ".$ret.") ";
1321 return $ret;
1323 function getMyPatientData($form_id, $show_phone_flag)
1325 //return a string of patient data and encounter data based on the form_CAMOS id
1326 $ret = '';
1327 $name = '';
1328 $dob = '';
1329 $enc_date = '';
1330 $phone_list = '';
1331 $pid = '';
1332 $query = sqlStatement("select t1.pid, t1.fname, t1.mname, t1.lname, " .
1333 "t1.phone_home, t1.phone_biz, t1.phone_contact, t1.phone_cell, " .
1334 "date_format(t1.DOB,'%m-%d-%y') as DOB, date_format(t2.date,'%m-%d-%y') as date, " .
1335 "datediff(current_date(),t2.date) as days " .
1336 "from patient_data as t1 join forms as t2 on (t1.pid = t2.pid) where t2.form_id=$form_id " .
1337 "and form_name like 'CAMOS%'");
1338 if ($results = sqlFetchArray($query)) {
1339 $pid = $results['pid'];
1340 $fname = $results['fname'];
1341 $mname = $results['mname'];
1342 $lname = $results['lname'];
1343 if ($mname) {
1344 $name = $fname.' '.$mname.' '.$lname;
1345 } else {
1346 $name = $fname.' '.$lname;
1349 $dob = $results['DOB'];
1350 $enc_date = $results['date'];
1351 $days_ago = $results['days'];
1352 $phone_list =
1353 "/* Home: ".$results['phone_home']." | ".
1354 "Cell: ".$results['phone_cell']." | ".
1355 "Bus: ".$results['phone_biz']." | ".
1356 "Contact: ".$results['phone_contact']." */";
1359 $ret = "/*$pid, $name, DOB: $dob, Enc: $enc_date, $days_ago days ago. */";
1360 if ($show_phone_flag === true) {
1361 $ret .= "\n".$phone_list;
1364 return $ret;