jarbled UTF-8 bug fix
[openemr.git] / interface / forms / CAMOS / new.php
blobf4a46f553f7c5e9e6d791c42871bb89c45a1ae91
1 <?php
2 include_once("../../globals.php");
3 include_once("../../../library/api.inc");
4 include_once("../../../library/sql.inc");
5 $out_of_encounter = false;
6 if ( (($_SESSION['encounter'] == '') || ($_SESSION['pid'] == '')) || ($_GET['mode'] == 'external')) {
7 $out_of_encounter = true;
9 // formHeader("Form: CAMOS");
10 $returnurl = $GLOBALS['concurrent_layout'] ? 'encounter_top.php' : 'patient_encounter.php';
11 function myauth() {
12 return 1;
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 if (get_magic_quotes_gpc()) {$category = stripslashes($category);}
51 $category = mysql_real_escape_string($category);
53 $query = "INSERT INTO form_CAMOS_category (user, category) values ('".$_SESSION['authUser']."', '";
54 $query .= $category."')";
55 sqlInsert($query);
57 elseif ($_POST['hidden_selection'] == 'change_subcategory') {
58 $preselect_subcategory_override = $_POST['change_subcategory'];
59 $category_id = $_POST['hidden_category'];
60 if ($category_id >= 0 ) {
62 if (get_magic_quotes_gpc()) {$subcategory = stripslashes($subcategory);}
63 $subcategory = mysql_real_escape_string($subcategory);
65 $query = "INSERT INTO form_CAMOS_subcategory (user, subcategory, category_id) values ('".$_SESSION['authUser']."', '";
66 $query .= $subcategory."', '".$category_id."')";
67 sqlInsert($query);
70 elseif ($_POST['hidden_selection'] == 'change_item') {
71 $preselect_item_override = $_POST['change_item'];
72 $category_id = $_POST['hidden_category'];
73 $subcategory_id = $_POST['hidden_subcategory'];
74 if (($category_id >= 0 ) && ($subcategory_id >=0)) {
76 if (get_magic_quotes_gpc()) {$item = stripslashes($item);}
77 $item = mysql_real_escape_string($item);
79 $query = "INSERT INTO form_CAMOS_item (user, item, content, subcategory_id) values ('".$_SESSION['authUser']."', '";
80 $query .= $item."', '".$content."', '".$subcategory_id."')";
81 sqlInsert($query);
85 elseif ($_POST['hidden_selection'] == 'change_content') {
86 $item_id = $_POST['hidden_item'];
87 if ($item_id >= 0) {
88 if ($_POST['hidden_mode'] == 'add to') {
89 $tmp = sqlQuery("SELECT content from form_CAMOS_item where id = ".$item_id);
90 if (isset($tmp)) {
91 $content .= "\n".$tmp['content'];
95 // if (get_magic_quotes_gpc()) {$content = stripslashes($content);}
96 $content = mysql_real_escape_string($content);
98 $query = "UPDATE form_CAMOS_item set content = '".$content."' where id = ".$item_id;
99 sqlInsert($query);
103 elseif ($_POST['hidden_mode'] == 'delete') {
104 if ($delete_subdata) { //if set, allow for the deletion of all subdata
105 if ($_POST['hidden_selection'] == 'change_category') {
106 $to_delete_id = $_POST['hidden_category'];
107 //first, look for associated subcategories, if any
108 $statement1 = sqlStatement("select id from form_CAMOS_subcategory where category_id = $to_delete_id");
109 while ($result1 = sqlFetchArray($statement1)) {
110 $query = "DELETE FROM form_CAMOS_item WHERE subcategory_id = " . $result1['id'];
111 sqlInsert($query);
113 $query = "DELETE FROM form_CAMOS_subcategory WHERE category_id = $to_delete_id";
114 sqlInsert($query);
115 $query = "DELETE FROM form_CAMOS_category WHERE id = $to_delete_id";
116 sqlInsert($query);
118 elseif ($_POST['hidden_selection'] == 'change_subcategory') {
119 $to_delete_id = $_POST['hidden_subcategory'];
120 $query = "DELETE FROM form_CAMOS_item WHERE subcategory_id = $to_delete_id";
121 sqlInsert($query);
122 $query = "DELETE FROM form_CAMOS_subcategory WHERE id = $to_delete_id";
123 sqlInsert($query);
125 elseif ($_POST['hidden_selection'] == 'change_item') {
126 if ((isset($_POST['select_item'])) && (count($_POST['select_item'])>1)) {
127 foreach($_POST['select_item'] as $v) {
128 $to_delete_id = $v;
129 $query = "DELETE FROM form_CAMOS_item WHERE id = " .$to_delete_id;
130 sqlInsert($query);
132 } else {
133 $to_delete_id = $_POST['hidden_item'];
134 $query = "DELETE FROM form_CAMOS_item WHERE id = " .$to_delete_id;
135 sqlInsert($query);
138 } else { //delete only if subdata is empty, 'the old way'.
139 if ($_POST['hidden_selection'] == 'change_category') {
140 $to_delete_id = $_POST['hidden_category'];
141 $to_delete_from_table = 'form_CAMOS_category';
142 $to_delete_from_subtable = 'form_CAMOS_subcategory';
143 $to_delete_from_subsubtable = 'form_CAMOS_item';
144 $tablename = 'category';
145 $subtablename = 'subcategory';
146 $subsubtablename = 'item';
148 elseif ($_POST['hidden_selection'] == 'change_subcategory') {
149 $to_delete_id = $_POST['hidden_subcategory'];
150 $to_delete_from_table = 'form_CAMOS_subcategory';
151 $to_delete_from_subtable = 'form_CAMOS_item';
152 $tablename = 'subcategory';
153 $subtablename = 'item';
155 elseif ($_POST['hidden_selection'] == 'change_item') {
156 $to_delete_id = $_POST['hidden_item'];
157 $to_delete_from_table = 'form_CAMOS_item';
158 $to_delete_from_subtable = '';
159 $tablename = 'item';
160 $subtablename = '';
163 if ($subtablename == '') { //deleting an item. The simple case.
164 $query = "DELETE FROM ".$to_delete_from_table." WHERE id like '".$to_delete_id."'";
165 sqlInsert($query);
167 else { //deleting a category or subcategory, check to see if related data below is empty first
168 $query = "SELECT count(id) FROM ".$to_delete_from_subtable." WHERE ".$tablename."_id like '".$to_delete_id."'";
169 $statement = sqlStatement($query);
170 if ($result = sqlFetchArray($statement)) {
171 if ($result['count(id)'] == 0) {
172 $query = "DELETE FROM ".$to_delete_from_table." WHERE id like '".$to_delete_id."'";
173 sqlInsert($query);
175 else {
176 $error = $subtablename." not empty!";
180 } //end of delete only if subdata is empty
182 elseif ($_POST['hidden_mode'] == 'alter') {
183 $newval = $_POST[$_POST['hidden_selection']];
184 if ($_POST['hidden_selection'] == 'change_category') {
185 $to_alter_id = $_POST['hidden_category'];
186 $to_alter_table = 'form_CAMOS_category';
187 $to_alter_column = 'category';
189 elseif ($_POST['hidden_selection'] == 'change_subcategory') {
190 $to_alter_id = $_POST['hidden_subcategory'];
191 $to_alter_table = 'form_CAMOS_subcategory';
192 $to_alter_column = 'subcategory';
194 elseif ($_POST['hidden_selection'] == 'change_item') {
195 $to_alter_id = $_POST['hidden_item'];
196 $to_alter_table = 'form_CAMOS_item';
197 $to_alter_column = 'item';
199 $query = "UPDATE ".$to_alter_table." set ".$to_alter_column." = '".$newval."' where id = ".$to_alter_id;
200 sqlInsert($query);
202 // end handle changes to database
204 //preselect column items
205 //either a database change has been made, so the user should be made to feel that they never left the same CAMOS screen
206 //or, CAMOS has been started freshly, therefore the last entry of the current patient should be selected.
207 $preselect_mode = '';
208 if ($preselect_category == '' && !$out_of_encounter) {
209 $preselect_mode = 'by name';
210 //at this point, if this variable has not been set, CAMOS must have been start over
211 //so let's get the most recent values from form_CAMOS for this patient's pid
212 $tmp = sqlQuery("SELECT max(id) AS max FROM form_CAMOS WHERE " .
213 "pid = '" . $_SESSION['pid'] . "'");
214 $maxid = $tmp['max'] ? $tmp['max'] : 0;
216 $query = "SELECT category, subcategory, item FROM form_CAMOS WHERE id = $maxid";
217 $statement = sqlStatement($query);
218 if ($result = sqlFetchArray($statement)) {
219 $preselect_category = $result['category'];
220 $preselect_subcategory = $result['subcategory'];
221 $preselect_item = $result['item'];
223 else {$preselect_mode = '';}
225 else {
226 $preselect_mode = 'by number';
230 <html><head>
231 <link rel=stylesheet href="<?echo $css_header;?>" type="text/css">
233 <script language="javascript" type="text/javascript">
235 var array1 = new Array();
236 var array2 = new Array();
237 var array3 = new Array();
238 var buffer = new Array();
239 var icd9_list = '';
240 var preselect_off = false;
241 var content_change_flag = false;
242 var lock_override_flag = false;
243 var columns_status = 'show';
244 var hs_status = false;
245 var vs_status = false;
246 var hide_tc02_status = false;
247 var clone_mode = false;
249 var crop_buffer = '';
250 var special_select_start = 0;
251 var special_select_end = 0;
254 if (substr($_POST['hidden_mode'],0,5) == 'clone') {
255 echo "clone_mode = true;\n";
259 function clear_box(obj) {
260 var hold = obj.value;
261 obj.value = buffer[obj] ? buffer[obj] : '';
262 buffer[obj] = hold;
265 function showit() {
266 var log = document.getElementById('log');
267 var content = document.testform.testarea;
268 specialSelect(content,'/*','*/');
271 function specialSelect(t_area, delim_1, delim_2) {
272 if (crop_buffer != '') {
273 t_area.value = crop_buffer;
274 crop_buffer = '';
275 return;
277 var cv = t_area.value;
278 var start = t_area.selectionStart;
279 var end = t_area.selectionEnd;
280 var newstart = cv.lastIndexOf(delim_1, start);
281 var newend = cv.indexOf(delim_2, end);
282 if ((newstart == -1) || (newend == -1)) {return;}
283 if ((newstart == special_select_start) && (newend == special_select_end)) {
284 cropToSelect(t_area, delim_2);
286 if (newstart >= 0 && newend >= 0) {
287 t_area.selectionStart = newstart;
288 t_area.selectionEnd = newend+delim_2.length;
290 special_select_start = newstart;
291 special_select_end = newend;
294 function cropToSelect(t_area, delim_2) {
295 var cv = t_area.value;
296 crop_buffer = cv;
297 var start = special_select_start;
298 var end = special_select_end+delim_2.length;
299 var length = end-start;
300 t_area.value = cv.substr(start,length);
303 function hide_columns() {
304 var column01 = document.getElementById('id_category_column');
305 var column02 = document.getElementById('id_subcategory_column');
306 var column03 = document.getElementById('id_item_column');
307 var columnheader01 = document.getElementById('id_category_column_header');
308 var columnheader02 = document.getElementById('id_subcategory_column_header');
309 var columnheader03 = document.getElementById('id_item_column_header');
311 if (columns_status == 'show') {
312 columns_status = 'hide';
313 column01.style.display = 'none';
314 column02.style.display = 'none';
315 column03.style.display = 'none';
316 columnheader01.style.display = 'none';
317 columnheader02.style.display = 'none';
318 columnheader03.style.display = 'none';
320 else {
321 columns_status = 'show';
322 column01.style.display = 'inline';
323 column02.style.display = 'inline';
324 column03.style.display = 'inline';
325 columnheader01.style.display = 'inline';
326 columnheader02.style.display = 'inline';
327 columnheader03.style.display = 'inline';
329 resize_content();
331 function resize_content() {
332 f2 = document.CAMOS;
333 f4 = f2.textarea_content
334 if (f4.cols == <?php echo $textarea_cols ?>) {
335 f4.cols = <?php echo $textarea_cols ?>*2;
336 f4.rows = <?php echo $textarea_rows?>;
337 } else {
338 f4.cols = <?php echo $textarea_cols ?>;
339 f4.rows = <?php echo $textarea_rows?>;
342 //function hs_button() {
343 // f2 = document.CAMOS;
344 // if (hs_status) {
345 // hide_columns();
346 // f2.textarea_content.cols /= 3;
347 // f2.textarea_content02.cols /= 3;
348 // hs_status = false;
349 // } else {
350 // hide_columns();
351 //// f2.textarea_content.cols *= 3;
352 // f2.textarea_content02.cols *= 3;
353 // hs_status = true;
354 // }
359 //deal with locking of content = prevent accidental overwrite
361 function trimString (str) {
362 str = this != window? this : str;
363 return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
365 function isLocked() {
366 f2 = document.CAMOS;
367 if (lock_override_flag) {
368 lock_override_flag = false;
369 return false;
371 return /\/\*\s*lock\s*\:\:\s*\*\//.test(f2.textarea_content.value);
373 function lock_content() {
374 f2 = document.CAMOS;
375 if ((trimString(f2.textarea_content.value) != "") && (!isLocked())) {
376 f2.textarea_content.value = f2.textarea_content.value + "\n\n" + "/*lock::*/";
377 lock_override_flag = true;
378 js_button('add','change_content');
381 function allSelected() {
382 var f2 = document.CAMOS;
383 if ( (f2.select_category.selectedIndex < 0) || (f2.select_subcategory.selectedIndex < 0) || (f2["select_item[]"].selectedIndex < 0) ) {
384 return false; //one of the columns is not selected
386 else {
387 return true; //all columns have a selection
391 function content_focus() {
392 if (content_change_flag == false) {
393 if (!allSelected()) {
394 // alert("If you add text to the 'content' box without a selection in each column (category, subcategory, item), you will likely lose your work.")
397 else {return;}
398 content_change_flag = true;
400 function content_blur() {
401 if (content_change_flag == true) {
402 content_change_flag = false;
406 if (!$out_of_encounter) { //do not do stuff that is encounter specific if not in an encounter
407 //ICD9
408 $icd9_flag = false;
409 $query = "SELECT code_text, code FROM billing WHERE encounter=".$_SESSION['encounter'].
410 " AND pid=".$_SESSION['pid']." AND code_type like 'ICD9' AND activity=1";
411 $statement = sqlStatement($query);
412 if ($result = sqlFetchArray($statement)) {
413 $icd9_flag = true;
414 echo "icd9_list = \"\\n\\n\\\n";
415 echo $result['code']." ".$result['code_text']."\\n\\\n";
417 while ($result = sqlFetchArray($statement)) {
418 echo $result['code']." ".$result['code_text']."\\n\\\n";
420 if ($icd9_flag) {echo "\";\n";}
423 $query = "SELECT id, category FROM form_CAMOS_category ORDER BY category";
424 $statement = sqlStatement($query);
425 $i = 0;
426 while ($result = sqlFetchArray($statement)) {
427 echo "array1[".$i."] = new Array(\"".fixquotes($result['category'])."\",\"".$result['id']."\", new Array());\n";
428 $i++;
430 $i=0;
431 $query = "SELECT id, subcategory, category_id FROM form_CAMOS_subcategory ORDER BY subcategory";
432 $statement = sqlStatement($query);
433 while ($result = sqlFetchArray($statement)) {
434 echo "array2[".$i."] = new Array(\"".fixquotes($result['subcategory'])."\", \"".$result['category_id']."\", \"".$result['id']."\", new Array());\n";
435 $i++;
437 $i=0;
438 $query = "SELECT id, item, content, subcategory_id FROM form_CAMOS_item ORDER BY item";
439 $statement = sqlStatement($query);
440 while ($result = sqlFetchArray($statement)) {
441 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'].
442 "\",\"".$result['id']."\");\n";
443 $i++;
447 function append_icd9() {
448 var f2 = document.CAMOS;
449 f2.textarea_content.value = f2.textarea_content.value + icd9_list;
452 function select_word(mode, mystring, myselect) { //take a string and select it in a select box if present
453 if (preselect_off) return 0;
454 for (var i=0;i<myselect.length;i++) {
455 var match = '';
456 if (mode == 'by name') {
457 match = myselect.options[i].text;
459 else if (mode == 'by number') {
460 match = myselect.options[i].value;
462 else {return 0;}
463 if (match == mystring) {
464 myselect.selectedIndex = i;
467 return 1;
470 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.
471 //if (!$out_of_encounter) { //do not do stuff that is encounter specific if not in an encounter
472 //cloning - similar process to preselect set to first time starting CAMOS
473 //as above
474 $clone_category = '';
475 $clone_subcategory = '';
476 $clone_item = '';
477 $clone_content = '';
478 $clone_data1 = '';
479 $clone_data2 = '';
480 $clone_data_array = array();
481 if (substr($_POST['hidden_mode'],0,5) == 'clone') {
482 $clone_category = $_POST['category'] ? $_POST['category'] : '';
483 $clone_category_term = '';
484 if ($clone_category != '') {
485 $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']."'";
492 $clone_item = $_POST['item'] ? $_POST['item'] : '';
493 $clone_item_term = '';
494 if ($clone_item != '') {
495 $clone_item_term = " and item like '".$_POST['item']."'";
497 $clone_search = trim($_POST['clone_others_search']);
499 $name_data_flag = false; //flag to see if we are going to use patient names in search result of clone others.
500 $show_phone_flag = false; //if we do show patient names, flag to see if we show phone numbers too
501 $pid_clause = ''; //if name search, will return a limited list of names to search for.
502 if (strpos($clone_search, "::") !== false) {
503 $name_data_flag = true;
504 $show_phone_flag = true;
505 $split = preg_split('/\s*::\s*/', $clone_search);
506 $clone_search = $split[1];
507 $pid_clause = searchName($split[0]);
509 elseif (strpos($clone_search, ":") !== false) {
510 $name_data_flag = true;
511 $split = preg_split('/\s*:\s*/', $clone_search);
512 $clone_search = $split[1];
513 $pid_clause = searchName($split[0]);
516 $clone_search_term = '';
517 if ($clone_search != '') {
518 $clone_search = preg_replace('/\s+/', '%', $clone_search);
519 if (substr($clone_search,0,1) == "`") {
520 $clone_subcategory_term = '';
521 $clone_item_term = '';
522 $clone_search = substr($clone_search,1);
524 $clone_search_term = " and content like '%$clone_search%'";
526 if (substr($_POST['hidden_mode'],0,12) == 'clone others') { //clone from search box
528 if (preg_match('/^(export)(.*)/',$clone_search,$matches)) {
529 $query1 = "select id, category from form_CAMOS_category";
530 $statement1 = sqlStatement($query1);
531 while ($result1 = sqlFetchArray($statement1)) {
532 $tmp = $result1['category'];
533 $tmp = "/*import::category::$tmp*/"."\n";
534 $clone_data_array[$tmp] = $tmp;
535 $query2 = "select id,subcategory from form_CAMOS_subcategory where category_id=".$result1['id'];
536 $statement2 = sqlStatement($query2);
537 while ($result2 = sqlFetchArray($statement2)) {
538 $tmp = $result2['subcategory'];
539 $tmp = "/*import::subcategory::$tmp*/"."\n";
540 $clone_data_array[$tmp] = $tmp;
541 $query3 = "select item, content from form_CAMOS_item where subcategory_id=".$result2['id'];
542 $statement3 = sqlStatement($query3);
543 while ($result3 = sqlFetchArray($statement3)) {
544 $tmp = $result3['item'];
545 $tmp = "/*import::item::$tmp*/"."\n";
546 $clone_data_array[$tmp] = $tmp;
547 $tmp = $result3['content'];
548 $tmp = "/*import::content::$tmp*/"."\n";
549 $clone_data_array[$tmp] = $tmp;
553 $clone_data_array = array();
555 elseif ((preg_match('/^(billing)(.*)/',$clone_search,$matches)) ||
556 (preg_match('/^(codes)(.*)/',$clone_search,$matches))) {
557 $table = $matches[1];
558 $line = $matches[2];
559 $line = '%'.trim($line).'%';
560 $search_term = preg_replace('/\s+/','%',$line);
561 $query = "select code, code_type,code_text,modifier,units,fee from $table where code_text like '$search_term' limit $limit";
562 $statement = sqlStatement($query);
563 while ($result = sqlFetchArray($statement)) {
564 $code_type = $result['code_type'];
565 if ($code_type == 1) {$code_type = 'CPT4';}
566 if ($code_type == 2) {$code_type = 'ICD9';}
567 if ($code_type == 3) {$code_type = 'OTHER';}
568 $code = $result['code'];
569 $code_text = $result['code_text'];
570 $modifier = $result['modifier'];
571 $units = $result['units'];
572 $fee = $result['fee'];
573 $tmp = "/*billing::$code_type::$code::$code_text::$modifier::$units::$fee*/";
574 $clone_data_array[$tmp] = $tmp;
576 } else {
577 //$clone_data_array['others'] = '/*'.$clone_category.'::'.$clone_subcategory.'::'.
578 // $clone_item.'*/';
579 //See the two lines commented out just below:
580 //I am trying out searching all content regardless of category, subcategory, item...
581 //because of this, we have to limit results more. There may be a few lines
582 //above that should be deleted if this becomes the normal way of doing these searches.
583 //Consider making the two queries below by encounter instead of camos id.
584 //This may be a little tricky.
585 if ($_POST['hidden_mode'] == 'clone others selected') { //clone from search box
586 $query = "select id, category, subcategory, item, content from form_CAMOS" .
587 $clone_category_term.$clone_subcategory_term.$clone_item_term.
588 $clone_search_term.$pid_clause." order by id desc limit $limit";
589 } else {
590 $query = "select id, category, subcategory, item, content from form_CAMOS" .
591 " where " .
592 //"category like '%$clone_search%' or" .
593 //" subcategory like '%$clone_search%' or" .
594 //" item like '%$clone_search%' or" .
595 " content like '%$clone_search%'".$pid_clause." order by id desc limit $limit";
597 $statement = sqlStatement($query);
598 while ($result = sqlFetchArray($statement)) {
599 $tmp = '/*camos::'.$result['category'].'::'.$result['subcategory'].
600 '::'.$result['item'].'::'.$result['content'].'*/';
601 if ($name_data_flag === true) {
602 $tmp = getMyPatientData($result['id'],$show_phone_flag)."\n$break\n".$tmp;
604 $key_tmp = preg_replace('/\W+/','',$tmp);
605 $key_tmp = preg_replace('/\W+/','',$tmp);
606 $clone_data_array[$key_tmp] = $tmp;
609 } else {//end of clone others
610 $query = "SELECT date(date) as date, subcategory, item, content FROM form_CAMOS WHERE category like '".
611 $clone_category."' and pid=".$_SESSION['pid']." order by id desc";
613 if ($_POST['hidden_mode'] == 'clone last visit') {
614 //go back $stepback # of encounters...
615 //This has been changed to clone last visit based on actual last encounter rather than as it was
616 //only looking at most recent BILLED encounters. To go back to billed encounters, change the following
617 //two queries to the 'billing' table rather than form_encounter and make sure to add in 'and activity=1'
618 //OK, now I have tried tracking last encounter from billing, then form_encounter. Now, we are going to
619 //try from forms where form_name like 'CAMOS%' so we will not bother with encounters that have no CAMOS entries...
620 $stepback = $_POST['stepback'] ? $_POST['stepback'] : 1;
621 $tmp = sqlQuery("SELECT max(encounter) as max FROM forms where encounter < " .
622 $_SESSION['encounter'] . " and form_name like 'CAMOS%' and pid= " . $_SESSION['pid']);
623 $last_encounter_id = $tmp['max'] ? $tmp['max'] : 0;
624 for ($i=0;$i<$stepback-1;$i++) {
625 $tmp = sqlQuery("SELECT max(encounter) as max FROM forms where encounter < " .
626 $last_encounter_id . " and form_name like 'CAMOS%' and pid= " . $_SESSION['pid']);
627 $last_encounter_id = $tmp['max'] ? $tmp['max'] : 0;
629 $query = "SELECT category, subcategory, item, content FROM form_CAMOS " .
630 "join forms on (form_CAMOS.id = forms.form_id) where " .
631 "forms.encounter = '$last_encounter_id' and form_CAMOS.pid=" .
632 $_SESSION['pid']." order by form_CAMOS.id";
634 $statement = sqlStatement($query);
635 while ($result = sqlFetchArray($statement)) {
636 if (preg_match('/^[\s\r\n]*$/',$result['content']) == 0) {
637 if ($_POST['hidden_mode'] == 'clone last visit') {
638 $clone_category = $result['category'];
640 $clone_subcategory = $result['subcategory'];
641 $clone_item = $result['item'];
642 $clone_content = $result['content'];
643 $clone_data1 = "/* camos :: $clone_category :: $clone_subcategory :: $clone_item :: ";
644 $clone_data2 = "$clone_content */";
645 $clone_data3 = $clone_data1 . $clone_data2;
646 if ($_POST['hidden_mode'] == 'clone last visit') {
647 $clone_data1 = $clone_data3; //make key include whole entry so all 'last visit' data gets recorded and shown
649 if (!$clone_data_array[$clone_data1]) { //if does not exist, don't overwrite.
650 $clone_data_array[$clone_data1] = "";
651 if ($_POST['hidden_mode'] == 'clone') {
652 $clone_data_array[$clone_data1] = "/* ------ ".$result['date']." --------- */\n"; //break between clone items
654 $clone_data_array[$clone_data1] .= $clone_data3;
658 if ($_POST['hidden_mode'] == 'clone last visit') {
659 $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'";
660 $statement = sqlStatement($query);
661 if ($result = sqlFetchArray($statement)) {
662 $weight = $result['weight'];
663 $height = $result['height'];
664 $bps = $result['bps'];
665 $bpd = $result['bpd'];
666 $pulse = $result['pulse'];
667 $temperature = $result['temperature'];
668 // $clone_vitals = "/* vitals_key:: weight :: height :: systolic :: diastolic :: pulse :: temperature */\n";
669 $clone_vitals = "";
670 $clone_vitals .= "/* vitals\n :: $weight\n :: $height\n :: $bps\n :: $bpd\n :: $pulse\n :: $temperature\n */";
671 $clone_data_array[$clone_vitals] = $clone_vitals;
673 $query = "SELECT code_type, code, code_text, modifier, units, fee FROM billing WHERE encounter = '$last_encounter_id' and pid=".$_SESSION['pid']." and activity=1 order by id";
674 $statement = sqlStatement($query);
675 while ($result = sqlFetchArray($statement)) {
676 $clone_code_type = $result['code_type'];
677 $clone_code = $result['code'];
678 $clone_code_text = $result['code_text'];
679 $clone_modifier = $result['modifier'];
680 $clone_units = $result['units'];
681 $clone_fee = $result['fee'];
682 $clone_billing_data = "/* billing :: $clone_code_type :: $clone_code :: $clone_code_text :: $clone_modifier :: $clone_units :: $clone_fee */";
683 $clone_data_array[$clone_billing_data] = $clone_billing_data;
686 } //end else (not clone others)
687 }//end of clone stuff
688 //end preselect column items
691 function init() {
692 var f2 = document.CAMOS;
693 if (clone_mode) {
694 clone_mode = false;
696 for (i1=0;i1<array1.length;i1++) {
697 f2.select_category.options[f2.select_category.length] = new Option(array1[i1][0], array1[i1][1]);
700 $temp_preselect_mode = $preselect_mode;
701 if ($preselect_category_override != '') {
702 $temp_preselect_mode = "by name";
703 $preselect_category = $preselect_category_override;
706 if (select_word("<? echo fixquotes($temp_preselect_mode)."\", \"".fixquotes($preselect_category); ?>" ,f2.select_category)) {
707 click_category();
710 if (substr($_POST['hidden_mode'],0,5) == 'clone') {
711 echo "f2.textarea_content.value = '';\n";
712 // echo "f2.textarea_content.value += '/* count = ".count($clone_data_array)."*/\\n$break\\n';";
713 echo "f2.textarea_content.value += '/* count = ".count($clone_data_array)."*/\\n$break\\n';";
714 foreach($clone_data_array as $key => $val) {
715 echo "f2.textarea_content.value = f2.textarea_content.value + \"".fixquotes(str_replace($quote_search,$quote_replace,$val))."\\n$break\\n\"\n";
722 function click_category() {
723 var f2 = document.CAMOS;
724 var category_index = f2.select_category.selectedIndex;
725 if ((category_index < 0) || (category_index > f2.select_category.length-1)) {return 0;}
726 var sel = f2.select_category.options[f2.select_category.selectedIndex].value;
727 for (var i1=0;i1<array1.length;i1++) {
728 if (array1[i1][1] == sel) {
729 f2.select_subcategory.length = 0;
730 f2["select_item[]"].length = 0;
731 f2.textarea_content.value = '';
732 for (var i2=0;i2<array2.length;i2++) {
733 if (array1[i1][1] == array2[i2][1]) {
734 f2.select_subcategory.options[f2.select_subcategory.length] = new Option(array2[i2][0], array2[i2][2]);
740 $temp_preselect_mode = $preselect_mode;
741 if ($preselect_subcategory_override != '') {
742 $temp_preselect_mode = "by name";
743 $preselect_subcategory = $preselect_subcategory_override;
746 if (select_word("<? echo fixquotes($temp_preselect_mode)."\", \"".fixquotes($preselect_subcategory); ?>" ,f2.select_subcategory)) {
747 click_subcategory();
750 function click_subcategory() {
751 var f2 = document.CAMOS;
752 var subcategory_index = f2.select_subcategory.selectedIndex;
753 if ((subcategory_index < 0) || (subcategory_index > f2.select_subcategory.length-1)) {return 0;}
754 var sel = f2.select_subcategory.options[f2.select_subcategory.selectedIndex].value;
755 for (var i1=0;i1<array2.length;i1++) {
756 if (array2[i1][2] == sel) {
757 f2["select_item[]"].length = 0;
758 f2.textarea_content.value = '';
759 for (var i2=0;i2<array3.length;i2++) {
760 if (array2[i1][2] == array3[i2][2]) {
761 f2["select_item[]"].options[f2["select_item[]"].length] = new Option(array3[i2][0], array3[i2][3]);
767 $temp_preselect_mode = $preselect_mode;
768 if ($preselect_item_override != '') {
769 $temp_preselect_mode = "by name";
770 $preselect_item = $preselect_item_override;
773 if (select_word("<? echo fixquotes($temp_preselect_mode)."\", \"".fixquotes($preselect_item); ?>" ,f2["select_item[]"])) {
774 click_item();
775 preselect_off = true;
778 function click_item() {
779 var f2 = document.CAMOS;
780 var item_index = f2["select_item[]"].selectedIndex;
781 if ((item_index < 0) || (item_index > f2["select_item[]"].length-1)) {return 0;}
782 var sel = f2["select_item[]"].options[item_index].value;
783 for (var i1=0;i1<array3.length;i1++) {
784 if (array3[i1][3] == sel) {
785 //diplay text in content box
786 f2.textarea_content.value= array3[i1][1].replace(/\\/g,'');
791 function selectContains(myselect, str) {
792 for (var i=0;i<myselect.length;i++) {
793 if (myselect.options[i].text == trimString(str)) {return true;}
797 function insert_content(direction) {
798 var f2 = document.CAMOS;
799 var source_box = f2.textarea_content;
800 var target_box = f2.textarea_content02;
801 if (direction == 'up') {
802 source_box = f2.textarea_content02;
803 target_box = f2.textarea_content;
805 var sba = source_box.selectionStart;
806 var sbb = source_box.selectionEnd;
807 var tba = target_box.selectionStart;
808 var tbb = target_box.selectionEnd;
809 if (sbb-sba == 0) {
810 sba = 0;
811 sbb = source_box.value.length;
813 var insert_text = (source_box.value).
814 substring(sba, sbb);
815 target_box.value = (target_box.value).
816 substring(0,tba) + insert_text +
817 (target_box.value).substring(tba,target_box.value.length);
820 //AJAX FUNCTIONS
821 //Function to create an XMLHttp Object.
822 function getxmlhttp (){
823 //Create a boolean variable to check for a valid microsoft active X instance.
824 var xmlhttp = false;
826 //Check if we are using internet explorer.
827 try {
828 //If the javascript version is greater than 5.
829 xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
830 } catch (e) {
831 //If not, then use the older active x object.
832 try {
833 //If we are using internet explorer.
834 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
835 } catch (E) {
836 //Else we must be using a non-internet explorer browser.
837 xmlhttp = false;
841 //If we are using a non-internet explorer browser, create a javascript instance of the object.
842 if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
843 xmlhttp = new XMLHttpRequest();
846 return xmlhttp;
849 //Function to process an XMLHttpRequest.
850 function processajax (serverPage, obj, getOrPost, str){
851 //Get an XMLHttpRequest object for use.
852 xmlhttp = getxmlhttp ();
853 if (getOrPost == "get"){
854 xmlhttp.open("GET", serverPage);
855 xmlhttp.onreadystatechange = function() {
856 if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
857 obj.innerHTML = xmlhttp.responseText;
860 xmlhttp.send(null);
861 } else {
862 xmlhttp.open("POST", serverPage, true);
863 xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
864 xmlhttp.onreadystatechange = function() {
865 if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
866 obj.innerHTML = xmlhttp.responseText;
869 xmlhttp.send(str);
874 function setformvalues(form_array){
876 //Run through a list of all objects
877 var str = '';
878 for(key in form_array) {
879 str += key + "=" + encodeURIComponent(form_array[key]) + "&";
881 //Then return the string values.
882 return str;
885 //END OF AJAX RELATED FUNCTIONS
887 function js_button(mode,selection) {
888 var f2 = document.CAMOS;
889 //check lock next
890 if ( (mode == 'add') && (selection == 'change_content') && (isLocked()) ) {
891 alert("You have attempted to alter content which is locked.\nRemove the lock if you want to do this.\nTo unlock, remove the line, '/*lock::*/'");
892 return;
894 //end check lock
896 //check for blank or duplicate submissions
897 if ( (mode == 'add') || (mode == 'alter') ) {
898 if (selection == 'change_category') {
899 if (trimString(f2.change_category.value) == "") {
900 alert("You cannot add a blank value for a category!");
901 return;
903 if (selectContains(f2.select_category, trimString(f2.change_category.value))) {
904 alert("There is already a category named "+f2.change_category.value+".");
905 return;
908 if (selection == 'change_subcategory') {
909 if (trimString(f2.change_subcategory.value) == "") {
910 alert("You cannot add a blank value for a subcategory!");
911 return;
913 if (selectContains(f2.select_subcategory, trimString(f2.change_subcategory.value))) {
914 alert("There is already a subcategory named "+f2.change_subcategory.value+".");
915 return;
918 if (selection == 'change_item') {
919 if (trimString(f2.change_item.value) == "") {
920 alert("You cannot add a blank value for an item!");
921 return;
923 if (selectContains(f2["select_item[]"], trimString(f2.change_item.value))) {
924 alert("There is already an item named "+f2.change_item.value+".");
925 return;
929 //end of check for blank or duplicate submissions
931 if (mode == 'delete') {
932 if (!confirm("Are you sure you want to delete this item from the database?")) {
933 return;
936 //check selections and assign variable values
937 var f2 = document.CAMOS;
938 var category_index = f2.select_category.selectedIndex;
939 var category_value;
940 var category_text;
941 if (category_index < 0) {
942 if ((selection == 'change_subcategory') || (selection == 'change_item') ||
943 (selection == 'change_content')) {
944 // alert ('You have not selected a category!');
945 return;
947 category_value = -1;
948 category_text = '';
950 else {
951 category_value = f2.select_category.options[category_index].value;
952 category_text = f2.select_category.options[category_index].text;
954 var subcategory_index = f2.select_subcategory.selectedIndex;
955 var subcategory_value;
956 var subcategory_text;
957 if (subcategory_index < 0) {
958 if ((selection == 'change_item') || (selection == 'change_content')) {
959 // alert ('You have not selected a subcategory!');
960 return;
962 subcategory_value = -1;
963 subcategory_text = '';
965 else {
966 subcategory_value = f2.select_subcategory.options[subcategory_index].value;
967 subcategory_text = f2.select_subcategory.options[subcategory_index].text;
969 var item_index = f2["select_item[]"].selectedIndex;
970 var item_value;
971 var item_text;
972 if (item_index < 0) {
973 if (selection == 'change_content') {
974 // alert ('You have not selected an item!');
975 return;
977 item_value = -1;
978 item_text = '';
980 else {
981 item_value = f2["select_item[]"].options[item_index].value;
982 item_text = f2["select_item[]"].options[item_index].text;
984 f2.category.value = category_text;
985 f2.subcategory.value = subcategory_text;
986 f2.item.value = item_text;
987 //end of setting values relating to selections
989 //deal with clone buttons or add, alter, delete.
990 if ( (mode.substr(0,5) == 'clone') || (mode == 'add') || (mode == 'add to') ||
991 (mode == 'alter') || (mode =='delete') ) {
992 f2.hidden_mode.value = mode;
993 f2.hidden_selection.value = selection;
994 f2.hidden_category.value = category_value;
995 f2.hidden_subcategory.value = subcategory_value;
996 f2.hidden_item.value = item_value;
997 <?php
998 if (!$out_of_encounter) {
1000 f2.action = '<? print $GLOBALS['webroot'] ?>/interface/patient_file/encounter/load_form.php?formname=CAMOS';
1001 <?php
1002 } else {
1004 f2.action = '<? print $GLOBALS['webroot'] ?>/interface/forms/CAMOS/new.php?mode=external';
1005 <?php
1008 f2.target = '_self';
1009 f2.submit();
1010 return;
1012 //ajax code
1013 var myobj = document.getElementById('id_info');
1014 myarray = new Array();
1015 myarray['category'] = category_text;
1016 myarray['subcategory'] = subcategory_text;
1017 myarray['item'] = item_text;
1018 myarray['content']
1019 if (selection == 'submit_selection') {
1020 myarray['content'] = (f2.textarea_content.value).substring(f2.textarea_content.selectionStart, f2.textarea_content.selectionEnd);
1022 else {myarray['content'] = f2.textarea_content.value;}
1023 var str = setformvalues(myarray);
1024 // alert(str);
1025 processajax ('<? print $GLOBALS['webroot'] ?>/interface/forms/CAMOS/ajax_save.php', myobj, "post", str);
1026 // alert("submitted!");
1027 //ajax code
1030 function selectItem () {
1031 f2 = document.CAMOS;
1032 f2.item.value=f2["select_item[]"].options[f2["select_item[]"].selectedIndex].text;
1033 f2.content.value = f2.textarea_content.value;
1035 function getKey(e) { //process keypresses with getKeyPress
1036 var keynum;
1037 if(window.event) { //IE
1038 keynum = e.keyCode;
1039 } else if(e.which) { // Netscape/Firefox/Opera
1040 keynum = e.which;
1042 return keynum;
1044 function gotoOne(e) {
1045 if (getKey(e) == 96) {
1046 document.CAMOS.clone_others_search.focus();
1049 function processEnter(e,message) {
1050 if (getKey(e) == 13) {
1051 if (message == "clone_others_search") {
1052 js_button('clone others', 'clone others');
1057 </script>
1058 </head>
1059 <body <?echo $top_bg_line;?> topmargin=0 rightmargin=0 leftmargin=2 bottommargin=0 marginwidth=2 marginheight=0 onload="init()">
1060 <div name="form_container" onKeyPress="gotoOne(event)">
1061 <form method=post action="<?echo $rootdir;?>/forms/CAMOS/save.php?mode=new" name="CAMOS">
1062 <?php
1063 if (!$out_of_encounter) {
1064 // echo "<h1>$out_of_encounter</h1>\n";
1066 <input type=button name=clone value=clone onClick="js_button('clone', 'clone')">
1067 <input type=button name=clone_visit value='clone past visit' onClick="js_button('clone last visit', 'clone last visit')">
1068 <select name=stepback>
1069 <option value=1>back one visit</option>
1070 <option value=2>back two visits</option>
1071 <option value=3>back three visits</option>
1072 <option value=4>back four visits</option>
1073 <option value=5>back five visits</option>
1074 <option value=6>back six visits</option>
1075 <option value=7>back seven visits</option>
1076 <option value=8>back eight visits</option>
1077 <option value=9>back nine visits</option>
1078 <option value=10>back ten visits</option>
1079 <option value=11>back eleven visits</option>
1080 <option value=12>back twelve visits</option>
1081 </select>
1083 echo "<a href='".$GLOBALS['webroot'] . "/interface/patient_file/encounter/$returnurl' onclick='top.restoreSession()'>[".xl('Leave The Form')."]</a>";
1085 <input type=button name='hide columns' value='hide/show columns' onClick="hide_columns()">
1086 <input type=button name='submit form' value='submit selected content' onClick="js_button('submit','submit_selection')">
1087 <?php
1088 } //end of if !$out_of_encounter
1090 <div id=id_info style="display:inline">
1091 <!-- supposedly where ajax induced php pages can print their output to... -->
1092 </div>
1093 <div id=id_mainbox style="display:inline">
1095 if ($error != '') {
1096 echo "<h1> error: ".$error."</h1>\n";
1099 <table border=1>
1100 <tr>
1101 <td>
1102 <div id=id_category_column_header style="display:inline">
1103 <?php xl('Category',e)?>
1104 </div> <!-- end of id_category_column_header -->
1105 </td>
1106 <td>
1107 <div id=id_subcategory_column_header style="display:inline">
1108 <?php xl('Subcategory',e)?>
1109 </div> <!-- end of id_subcategory_column_header -->
1110 </td>
1111 <td>
1112 <div id=id_item_column_header style="display:inline">
1113 <?php xl('Item',e)?>
1114 </div> <!-- end of id_item_column_header -->
1115 </td>
1116 <td>
1117 <?php xl('Content',e)?>
1118 </td>
1119 </tr>
1121 <tr>
1122 <td>
1123 <div id=id_category_column style="display:inline">
1124 <select name=select_category size=<? echo $select_size ?> onchange="click_category()"></select><br>
1126 if (myAuth() == 1) {//root user only can see administration option
1128 <input type=text name=change_category><br>
1129 <input type=button name=add1 value=add onClick="js_button('add','change_category')">
1130 <input type=button name=alter1 value=alter onClick="js_button('alter','change_category')">
1131 <input type=button name=del1 value=del onClick="js_button('delete','change_category')"><br>
1135 </div> <!-- end of id_category_column -->
1136 </td>
1137 <td>
1138 <div id=id_subcategory_column style="display:inline">
1139 <select name=select_subcategory size=<? echo $select_size ?> onchange="click_subcategory()"></select><br>
1141 if (myAuth() == 1) {//root user only can see administration option
1143 <input type=text name=change_subcategory><br>
1144 <input type=button name=add2 value=add onClick="js_button('add','change_subcategory')">
1145 <input type=button name=alter1 value=alter onClick="js_button('alter','change_subcategory')">
1146 <input type=button name=del2 value=del onClick="js_button('delete','change_subcategory')"><br>
1150 </div> <!-- end of id_subcategory_column -->
1151 </td>
1152 <td>
1153 <div id=id_item_column style="display:inline">
1154 <select name=select_item[] size=<? echo $select_size ?> onchange="click_item()" multiple="multiple"></select><br>
1156 if (myAuth() == 1) {//root user only can see administration option
1158 <input type=text name=change_item><br>
1159 <input type=button name=add3 value=add onClick="js_button('add','change_item')">
1160 <input type=button name=alter1 value=alter onClick="js_button('alter','change_item')">
1161 <input type=button name=del3 value=del onClick="js_button('delete','change_item')"><br>
1165 </div> <!-- end of id_item_column -->
1166 </td>
1167 <td>
1168 <div id=id_textarea_content style="display:inline">
1169 <textarea name=textarea_content cols=<? echo $textarea_cols ?> rows=<? echo $textarea_rows ?> onFocus="content_focus()" onBlur="content_blur()" onDblClick="specialSelect(this,'/*','*/')" tabindex=2></textarea>
1170 <br/>
1171 <input type=text size=35 name=clone_others_search value='<? echo $_POST['clone_others_search'] ?>' tabindex=1 onKeyPress="processEnter(event,'clone_others_search')"/>
1172 <input type=button name=clone_others_search_button value=search onClick="js_button('clone others', 'clone others')"/>
1173 <input type=button name=clone_others_selected_search_button value='search selected' onClick="js_button('clone others selected', 'clone others selected')"/>
1175 if (myAuth() == 1) {//root user only can see administration option
1177 <div id=id_main_content_buttons style="display:block">
1178 <input type=button name=add4 value=add onClick="js_button('add','change_content')">
1179 <input type=button name=add4 value='add to' onClick="js_button('add to','change_content')">
1180 <input type=button name=lock value=lock onClick="lock_content()">
1182 if (!$out_of_encounter) { //do not do stuff that is encounter specific if not in an encounter
1184 <input type=button name=icd9 value=icd9 onClick="append_icd9()">
1185 </div> <!-- end of id_main_content_buttons-->
1192 </td>
1193 </td>
1194 </tr>
1195 </table>
1197 <input type=hidden name=hidden_mode>
1198 <input type=hidden name=hidden_selection>
1199 <input type=hidden name=hidden_category>
1200 <input type=hidden name=hidden_subcategory>
1201 <input type=hidden name=hidden_item>
1203 <input type=hidden name=category>
1204 <input type=hidden name=subcategory>
1205 <input type=hidden name=item>
1206 <input type=hidden name=content>
1208 if (!$out_of_encounter) { //do not do stuff that is encounter specific if not in an encounter
1210 <input type=button name='submit form' value='submit all content' onClick="js_button('submit','submit')">
1211 <input type=button name='submit form' value='submit selected content' onClick="js_button('submit','submit_selection')">
1216 if (!$out_of_encounter) { //do not do stuff that is encounter specific if not in an encounter
1217 echo "<a href='".$GLOBALS['webroot'] . "/interface/patient_file/encounter/$returnurl' onclick='top.restoreSession()'>[".xl('Leave The Form')."]</a>";
1218 echo "<a href='".$GLOBALS['webroot'] . "/interface/forms/CAMOS/help.html' target='new'> | [".xl('help')."]</a>";
1219 // echo $previous_encounter_data; //probably don't need anymore now that we have clone last visit
1222 </div>
1223 </form>
1224 </div>
1225 <?php
1226 formFooter();
1228 //PHP FUNCTIONS
1230 function fixquotes ($string) {
1231 // this function is needed to treat a string before php echos it in the process of generating javascript.
1232 // 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'.
1233 // $string = preg_replace('/([\\\])*\'/', "\\\'", $string);
1234 $string = preg_replace('/([\\\])*\"/', "\\\"", $string);
1235 return $string;
1238 function searchName($string) { //match one or more names and return clause for query of pids
1239 $string = trim($string);
1240 if ($string == 'this') {
1241 return " and (pid = ".$_SESSION['pid'].") ";
1243 global $limit;
1244 $ret = '';
1245 $data = array();
1246 $fname = '';
1247 $lname = '';
1248 if ($string == '') {return $ret;}
1249 $split = preg_split('/\s+/',$string);
1250 $name1 = $split[1];
1251 $name2 = $split[0];
1252 if ($name1 != '') {$name1 = "%".$name1."%";}
1253 if ($name2 != '') {$name1 = "%".$name2."%";}
1254 $query = sqlStatement("select pid from patient_data where fname like '$name1' or fname like '$name2' or " .
1255 "lname like '$name1' or lname like '$name2' limit $limit");
1256 while ($results = mysql_fetch_array($query, MYSQL_ASSOC)) {
1257 array_push($data,$results['pid']);
1259 if (count($data) > 0) {
1260 $ret = join(" or pid = ",$data);
1261 $ret = " and (pid = ".$ret.") ";
1263 return $ret;
1265 function getMyPatientData($form_id, $show_phone_flag) {//return a string of patient data and encounter data based on the form_CAMOS id
1266 $ret = '';
1267 $name = '';
1268 $dob = '';
1269 $enc_date = '';
1270 $phone_list = '';
1271 $pid = '';
1272 $query = sqlStatement("select t1.pid, t1.fname, t1.mname, t1.lname, " .
1273 "t1.phone_home, t1.phone_biz, t1.phone_contact, t1.phone_cell, " .
1274 "date_format(t1.DOB,'%m-%d-%y') as DOB, date_format(t2.date,'%m-%d-%y') as date, " .
1275 "datediff(current_date(),t2.date) as days " .
1276 "from patient_data as t1 join forms as t2 on (t1.pid = t2.pid) where t2.form_id=$form_id " .
1277 "and form_name like 'CAMOS%'");
1278 if ($results = mysql_fetch_array($query, MYSQL_ASSOC)) {
1279 $pid = $results['pid'];
1280 $fname = $results['fname'];
1281 $mname = $results['mname'];
1282 $lname = $results['lname'];
1283 if ($mname) {$name = $fname.' '.$mname.' '.$lname;}
1284 else {$name = $fname.' '.$lname;}
1285 $dob = $results['DOB'];
1286 $enc_date = $results['date'];
1287 $days_ago = $results['days'];
1288 $phone_list =
1289 "/* Home: ".$results['phone_home']." | ".
1290 "Cell: ".$results['phone_cell']." | ".
1291 "Bus: ".$results['phone_biz']." | ".
1292 "Contact: ".$results['phone_contact']." */";
1294 $ret = "/*$pid, $name, DOB: $dob, Enc: $enc_date, $days_ago days ago. */";
1295 if ($show_phone_flag === true) {
1296 $ret .= "\n".$phone_list;
1298 return $ret;