Fixed php short tags
[openemr.git] / interface / forms / CAMOS / new.php
blob56ca26b92124556a10056ee5e47dd6f2004e3053
1 <?php
2 include_once("../../globals.php");
3 include_once("../../../library/api.inc");
4 include_once("../../../library/sql.inc");
5 include_once("../../../library/formdata.inc.php");
6 $out_of_encounter = false;
7 if ( (($_SESSION['encounter'] == '') || ($_SESSION['pid'] == '')) || ($_GET['mode'] == 'external')) {
8 $out_of_encounter = true;
10 // formHeader("Form: CAMOS");
11 $returnurl = $GLOBALS['concurrent_layout'] ? 'encounter_top.php' : 'patient_encounter.php';
12 function myauth() {
13 return 1;
18 <?php
20 $break = "/* ---------------------------------- */"; //break between clone items
21 $delete_subdata = true; //true means allowing the deletion of subdata. If you delete a category, all subcategories and items go too.
22 $limit = 100;
23 $select_size = 20;
24 $textarea_rows = 20;
25 $textarea_cols = 80;
26 $debug = '';
27 $error = '';
29 $preselect_category = '';
30 $preselect_subcategory = '';
31 $preselect_item = '';
32 $preselect_category_override = '';
33 $preselect_subcategory_override = '';
34 $preselect_item_override = '';
36 $quote_search = array("\r","\n");
37 $quote_replace = array("\\r","\\n");
38 $quote_search_content = array("\r","\n");
39 $quote_replace_content = array("\\r","\\n");
40 $category = str_replace($quote_search,$quote_replace,$_POST['change_category']);
41 $subcategory = str_replace($quote_search,$quote_replace,$_POST['change_subcategory']);
42 $item = str_replace($quote_search,$quote_replace,$_POST['change_item']);
43 $content = str_replace($quote_search_content,$quote_replace_content,$_POST['textarea_content']);
44 if ($_POST['hidden_category']) {$preselect_category = $_POST['hidden_category'];}
45 if ($_POST['hidden_subcategory']) {$preselect_subcategory = $_POST['hidden_subcategory'];}
46 if ($_POST['hidden_item']) {$preselect_item = $_POST['hidden_item'];}
47 //handle changes to database
48 if (substr($_POST['hidden_mode'],0,3) == 'add') {
49 if ($_POST['hidden_selection'] == 'change_category') {
50 $preselect_category_override = $_POST['change_category'];
52 $category = formDataCore($category);
54 $query = "INSERT INTO form_CAMOS_category (user, category) values ('".$_SESSION['authUser']."', '";
55 $query .= $category."')";
56 sqlInsert($query);
58 elseif ($_POST['hidden_selection'] == 'change_subcategory') {
59 $preselect_subcategory_override = $_POST['change_subcategory'];
60 $category_id = $_POST['hidden_category'];
61 if ($category_id >= 0 ) {
63 $subcategory = formDataCore($subcategory);
65 $query = "INSERT INTO form_CAMOS_subcategory (user, subcategory, category_id) values ('".$_SESSION['authUser']."', '";
66 $query .= $subcategory."', '".$category_id."')";
67 sqlInsert($query);
70 elseif ($_POST['hidden_selection'] == 'change_item') {
71 $preselect_item_override = $_POST['change_item'];
72 $category_id = $_POST['hidden_category'];
73 $subcategory_id = $_POST['hidden_subcategory'];
74 if (($category_id >= 0 ) && ($subcategory_id >=0)) {
76 $item = formDataCore($item);
78 $query = "INSERT INTO form_CAMOS_item (user, item, content, subcategory_id) values ('".$_SESSION['authUser']."', '";
79 $query .= $item."', '".$content."', '".$subcategory_id."')";
80 sqlInsert($query);
84 elseif ($_POST['hidden_selection'] == 'change_content') {
85 $item_id = $_POST['hidden_item'];
86 if ($item_id >= 0) {
87 if ($_POST['hidden_mode'] == 'add to') {
88 $tmp = sqlQuery("SELECT content from form_CAMOS_item where id = ".$item_id);
89 if (isset($tmp)) {
90 $content .= "\n".$tmp['content'];
94 // Not stripping slashes, unclear why, but will keep same functionality
95 // below just adds the escapes.
96 $content = add_escape_custom($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="<?php 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;
253 <?php
255 if (substr($_POST['hidden_mode'],0,5) == 'clone') {
256 echo "clone_mode = true;\n";
260 function clear_box(obj) {
261 var hold = obj.value;
262 obj.value = buffer[obj] ? buffer[obj] : '';
263 buffer[obj] = hold;
266 function showit() {
267 var log = document.getElementById('log');
268 var content = document.testform.testarea;
269 specialSelect(content,'/*','*/');
272 function specialSelect(t_area, delim_1, delim_2) {
273 if (crop_buffer != '') {
274 t_area.value = crop_buffer;
275 crop_buffer = '';
276 return;
278 var cv = t_area.value;
279 var start = t_area.selectionStart;
280 var end = t_area.selectionEnd;
281 var newstart = cv.lastIndexOf(delim_1, start);
282 var newend = cv.indexOf(delim_2, end);
283 if ((newstart == -1) || (newend == -1)) {return;}
284 if ((newstart == special_select_start) && (newend == special_select_end)) {
285 cropToSelect(t_area, delim_2);
287 if (newstart >= 0 && newend >= 0) {
288 t_area.selectionStart = newstart;
289 t_area.selectionEnd = newend+delim_2.length;
291 special_select_start = newstart;
292 special_select_end = newend;
295 function cropToSelect(t_area, delim_2) {
296 var cv = t_area.value;
297 crop_buffer = cv;
298 var start = special_select_start;
299 var end = special_select_end+delim_2.length;
300 var length = end-start;
301 t_area.value = cv.substr(start,length);
304 function hide_columns() {
305 var column01 = document.getElementById('id_category_column');
306 var column02 = document.getElementById('id_subcategory_column');
307 var column03 = document.getElementById('id_item_column');
308 var columnheader01 = document.getElementById('id_category_column_header');
309 var columnheader02 = document.getElementById('id_subcategory_column_header');
310 var columnheader03 = document.getElementById('id_item_column_header');
312 if (columns_status == 'show') {
313 columns_status = 'hide';
314 column01.style.display = 'none';
315 column02.style.display = 'none';
316 column03.style.display = 'none';
317 columnheader01.style.display = 'none';
318 columnheader02.style.display = 'none';
319 columnheader03.style.display = 'none';
321 else {
322 columns_status = 'show';
323 column01.style.display = 'inline';
324 column02.style.display = 'inline';
325 column03.style.display = 'inline';
326 columnheader01.style.display = 'inline';
327 columnheader02.style.display = 'inline';
328 columnheader03.style.display = 'inline';
330 resize_content();
332 function resize_content() {
333 f2 = document.CAMOS;
334 f4 = f2.textarea_content
335 if (f4.cols == <?php echo $textarea_cols ?>) {
336 f4.cols = <?php echo $textarea_cols ?>*2;
337 f4.rows = <?php echo $textarea_rows?>;
338 } else {
339 f4.cols = <?php echo $textarea_cols ?>;
340 f4.rows = <?php echo $textarea_rows?>;
343 //function hs_button() {
344 // f2 = document.CAMOS;
345 // if (hs_status) {
346 // hide_columns();
347 // f2.textarea_content.cols /= 3;
348 // f2.textarea_content02.cols /= 3;
349 // hs_status = false;
350 // } else {
351 // hide_columns();
352 //// f2.textarea_content.cols *= 3;
353 // f2.textarea_content02.cols *= 3;
354 // hs_status = true;
355 // }
360 //deal with locking of content = prevent accidental overwrite
362 function trimString (str) {
363 str = this != window? this : str;
364 return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
366 function isLocked() {
367 f2 = document.CAMOS;
368 if (lock_override_flag) {
369 lock_override_flag = false;
370 return false;
372 return /\/\*\s*lock\s*\:\:\s*\*\//.test(f2.textarea_content.value);
374 function lock_content() {
375 f2 = document.CAMOS;
376 if ((trimString(f2.textarea_content.value) != "") && (!isLocked())) {
377 f2.textarea_content.value = f2.textarea_content.value + "\n\n" + "/*lock::*/";
378 lock_override_flag = true;
379 js_button('add','change_content');
382 function allSelected() {
383 var f2 = document.CAMOS;
384 if ( (f2.select_category.selectedIndex < 0) || (f2.select_subcategory.selectedIndex < 0) || (f2["select_item[]"].selectedIndex < 0) ) {
385 return false; //one of the columns is not selected
387 else {
388 return true; //all columns have a selection
392 function content_focus() {
393 if (content_change_flag == false) {
394 if (!allSelected()) {
395 // alert("If you add text to the 'content' box without a selection in each column (category, subcategory, item), you will likely lose your work.")
398 else {return;}
399 content_change_flag = true;
401 function content_blur() {
402 if (content_change_flag == true) {
403 content_change_flag = false;
406 <?php
408 if (!$out_of_encounter) { //do not do stuff that is encounter specific if not in an encounter
409 //ICD9
410 $icd9_flag = false;
411 $query = "SELECT code_text, code FROM billing WHERE encounter=".$_SESSION['encounter'].
412 " AND pid=".$_SESSION['pid']." AND code_type like 'ICD9' AND activity=1";
413 $statement = sqlStatement($query);
414 if ($result = sqlFetchArray($statement)) {
415 $icd9_flag = true;
416 echo "icd9_list = \"\\n\\n\\\n";
417 echo $result['code']." ".$result['code_text']."\\n\\\n";
419 while ($result = sqlFetchArray($statement)) {
420 echo $result['code']." ".$result['code_text']."\\n\\\n";
422 if ($icd9_flag) {echo "\";\n";}
425 $query = "SELECT id, category FROM form_CAMOS_category ORDER BY category";
426 $statement = sqlStatement($query);
427 $i = 0;
428 while ($result = sqlFetchArray($statement)) {
429 echo "array1[".$i."] = new Array(\"".fixquotes($result['category'])."\",\"".$result['id']."\", new Array());\n";
430 $i++;
432 $i=0;
433 $query = "SELECT id, subcategory, category_id FROM form_CAMOS_subcategory ORDER BY subcategory";
434 $statement = sqlStatement($query);
435 while ($result = sqlFetchArray($statement)) {
436 echo "array2[".$i."] = new Array(\"".fixquotes($result['subcategory'])."\", \"".$result['category_id']."\", \"".$result['id']."\", new Array());\n";
437 $i++;
439 $i=0;
440 $query = "SELECT id, item, content, subcategory_id FROM form_CAMOS_item ORDER BY item";
441 $statement = sqlStatement($query);
442 while ($result = sqlFetchArray($statement)) {
443 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'].
444 "\",\"".$result['id']."\");\n";
445 $i++;
449 function append_icd9() {
450 var f2 = document.CAMOS;
451 f2.textarea_content.value = f2.textarea_content.value + icd9_list;
454 function select_word(mode, mystring, myselect) { //take a string and select it in a select box if present
455 if (preselect_off) return 0;
456 for (var i=0;i<myselect.length;i++) {
457 var match = '';
458 if (mode == 'by name') {
459 match = myselect.options[i].text;
461 else if (mode == 'by number') {
462 match = myselect.options[i].value;
464 else {return 0;}
465 if (match == mystring) {
466 myselect.selectedIndex = i;
469 return 1;
471 <?php
473 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.
474 //if (!$out_of_encounter) { //do not do stuff that is encounter specific if not in an encounter
475 //cloning - similar process to preselect set to first time starting CAMOS
476 //as above
477 $clone_category = '';
478 $clone_subcategory = '';
479 $clone_item = '';
480 $clone_content = '';
481 $clone_data1 = '';
482 $clone_data2 = '';
483 $clone_data_array = array();
484 if (substr($_POST['hidden_mode'],0,5) == 'clone') {
485 $clone_category = $_POST['category'] ? $_POST['category'] : '';
486 $clone_category_term = '';
487 if ($clone_category != '') {
488 $clone_category_term = " where category like '".$clone_category."'";
490 $clone_subcategory = $_POST['subcategory'] ? $_POST['subcategory'] : '';
491 $clone_subcategory_term = '';
492 if ($clone_subcategory != '') {
493 $clone_subcategory_term = " and subcategory like '".$_POST['subcategory']."'";
495 $clone_item = $_POST['item'] ? $_POST['item'] : '';
496 $clone_item_term = '';
497 if ($clone_item != '') {
498 $clone_item_term = " and item like '".$_POST['item']."'";
500 $clone_search = trim($_POST['clone_others_search']);
502 $name_data_flag = false; //flag to see if we are going to use patient names in search result of clone others.
503 $show_phone_flag = false; //if we do show patient names, flag to see if we show phone numbers too
504 $pid_clause = ''; //if name search, will return a limited list of names to search for.
505 if (strpos($clone_search, "::") !== false) {
506 $name_data_flag = true;
507 $show_phone_flag = true;
508 $split = preg_split('/\s*::\s*/', $clone_search);
509 $clone_search = $split[1];
510 $pid_clause = searchName($split[0]);
512 elseif (strpos($clone_search, ":") !== false) {
513 $name_data_flag = true;
514 $split = preg_split('/\s*:\s*/', $clone_search);
515 $clone_search = $split[1];
516 $pid_clause = searchName($split[0]);
519 $clone_search_term = '';
520 if ($clone_search != '') {
521 $clone_search = preg_replace('/\s+/', '%', $clone_search);
522 if (substr($clone_search,0,1) == "`") {
523 $clone_subcategory_term = '';
524 $clone_item_term = '';
525 $clone_search = substr($clone_search,1);
527 $clone_search_term = " and content like '%$clone_search%'";
529 if (substr($_POST['hidden_mode'],0,12) == 'clone others') { //clone from search box
531 if (preg_match('/^(export)(.*)/',$clone_search,$matches)) {
532 $query1 = "select id, category from form_CAMOS_category";
533 $statement1 = sqlStatement($query1);
534 while ($result1 = sqlFetchArray($statement1)) {
535 $tmp = $result1['category'];
536 $tmp = "/*import::category::$tmp*/"."\n";
537 $clone_data_array[$tmp] = $tmp;
538 $query2 = "select id,subcategory from form_CAMOS_subcategory where category_id=".$result1['id'];
539 $statement2 = sqlStatement($query2);
540 while ($result2 = sqlFetchArray($statement2)) {
541 $tmp = $result2['subcategory'];
542 $tmp = "/*import::subcategory::$tmp*/"."\n";
543 $clone_data_array[$tmp] = $tmp;
544 $query3 = "select item, content from form_CAMOS_item where subcategory_id=".$result2['id'];
545 $statement3 = sqlStatement($query3);
546 while ($result3 = sqlFetchArray($statement3)) {
547 $tmp = $result3['item'];
548 $tmp = "/*import::item::$tmp*/"."\n";
549 $clone_data_array[$tmp] = $tmp;
550 $tmp = $result3['content'];
551 $tmp = "/*import::content::$tmp*/"."\n";
552 $clone_data_array[$tmp] = $tmp;
556 $clone_data_array = array();
558 elseif ((preg_match('/^(billing)(.*)/',$clone_search,$matches)) ||
559 (preg_match('/^(codes)(.*)/',$clone_search,$matches))) {
560 $table = $matches[1];
561 $line = $matches[2];
562 $line = '%'.trim($line).'%';
563 $search_term = preg_replace('/\s+/','%',$line);
564 $query = "select code, code_type,code_text,modifier,units,fee from $table where code_text like '$search_term' limit $limit";
565 $statement = sqlStatement($query);
566 while ($result = sqlFetchArray($statement)) {
567 $code_type = $result['code_type'];
568 if ($code_type == 1) {$code_type = 'CPT4';}
569 if ($code_type == 2) {$code_type = 'ICD9';}
570 if ($code_type == 3) {$code_type = 'OTHER';}
571 $code = $result['code'];
572 $code_text = $result['code_text'];
573 $modifier = $result['modifier'];
574 $units = $result['units'];
575 $fee = $result['fee'];
576 $tmp = "/*billing::$code_type::$code::$code_text::$modifier::$units::$fee*/";
577 $clone_data_array[$tmp] = $tmp;
579 } else {
580 //$clone_data_array['others'] = '/*'.$clone_category.'::'.$clone_subcategory.'::'.
581 // $clone_item.'*/';
582 //See the two lines commented out just below:
583 //I am trying out searching all content regardless of category, subcategory, item...
584 //because of this, we have to limit results more. There may be a few lines
585 //above that should be deleted if this becomes the normal way of doing these searches.
586 //Consider making the two queries below by encounter instead of camos id.
587 //This may be a little tricky.
588 if ($_POST['hidden_mode'] == 'clone others selected') { //clone from search box
589 $query = "select id, category, subcategory, item, content from form_CAMOS" .
590 $clone_category_term.$clone_subcategory_term.$clone_item_term.
591 $clone_search_term.$pid_clause." order by id desc limit $limit";
592 } else {
593 $query = "select id, category, subcategory, item, content from form_CAMOS" .
594 " where " .
595 //"category like '%$clone_search%' or" .
596 //" subcategory like '%$clone_search%' or" .
597 //" item like '%$clone_search%' or" .
598 " content like '%$clone_search%'".$pid_clause." order by id desc limit $limit";
600 $statement = sqlStatement($query);
601 while ($result = sqlFetchArray($statement)) {
602 $tmp = '/*camos::'.$result['category'].'::'.$result['subcategory'].
603 '::'.$result['item'].'::'.$result['content'].'*/';
604 if ($name_data_flag === true) {
605 $tmp = getMyPatientData($result['id'],$show_phone_flag)."\n$break\n".$tmp;
607 $key_tmp = preg_replace('/\W+/','',$tmp);
608 $key_tmp = preg_replace('/\W+/','',$tmp);
609 $clone_data_array[$key_tmp] = $tmp;
612 } else {//end of clone others
613 $query = "SELECT date(date) as date, subcategory, item, content FROM form_CAMOS WHERE category like '".
614 $clone_category."' and pid=".$_SESSION['pid']." order by id desc";
616 if ($_POST['hidden_mode'] == 'clone last visit') {
617 //go back $stepback # of encounters...
618 //This has been changed to clone last visit based on actual last encounter rather than as it was
619 //only looking at most recent BILLED encounters. To go back to billed encounters, change the following
620 //two queries to the 'billing' table rather than form_encounter and make sure to add in 'and activity=1'
621 //OK, now I have tried tracking last encounter from billing, then form_encounter. Now, we are going to
622 //try from forms where form_name like 'CAMOS%' so we will not bother with encounters that have no CAMOS entries...
623 $stepback = $_POST['stepback'] ? $_POST['stepback'] : 1;
624 $tmp = sqlQuery("SELECT max(encounter) as max FROM forms where encounter < " .
625 $_SESSION['encounter'] . " and form_name like 'CAMOS%' and pid= " . $_SESSION['pid']);
626 $last_encounter_id = $tmp['max'] ? $tmp['max'] : 0;
627 for ($i=0;$i<$stepback-1;$i++) {
628 $tmp = sqlQuery("SELECT max(encounter) as max FROM forms where encounter < " .
629 $last_encounter_id . " and form_name like 'CAMOS%' and pid= " . $_SESSION['pid']);
630 $last_encounter_id = $tmp['max'] ? $tmp['max'] : 0;
632 $query = "SELECT category, subcategory, item, content FROM form_CAMOS " .
633 "join forms on (form_CAMOS.id = forms.form_id) where " .
634 "forms.encounter = '$last_encounter_id' and form_CAMOS.pid=" .
635 $_SESSION['pid']." order by form_CAMOS.id";
637 $statement = sqlStatement($query);
638 while ($result = sqlFetchArray($statement)) {
639 if (preg_match('/^[\s\r\n]*$/',$result['content']) == 0) {
640 if ($_POST['hidden_mode'] == 'clone last visit') {
641 $clone_category = $result['category'];
643 $clone_subcategory = $result['subcategory'];
644 $clone_item = $result['item'];
645 $clone_content = $result['content'];
646 $clone_data1 = "/* camos :: $clone_category :: $clone_subcategory :: $clone_item :: ";
647 $clone_data2 = "$clone_content */";
648 $clone_data3 = $clone_data1 . $clone_data2;
649 if ($_POST['hidden_mode'] == 'clone last visit') {
650 $clone_data1 = $clone_data3; //make key include whole entry so all 'last visit' data gets recorded and shown
652 if (!$clone_data_array[$clone_data1]) { //if does not exist, don't overwrite.
653 $clone_data_array[$clone_data1] = "";
654 if ($_POST['hidden_mode'] == 'clone') {
655 $clone_data_array[$clone_data1] = "/* ------ ".$result['date']." --------- */\n"; //break between clone items
657 $clone_data_array[$clone_data1] .= $clone_data3;
661 if ($_POST['hidden_mode'] == 'clone last visit') {
662 $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'";
663 $statement = sqlStatement($query);
664 if ($result = sqlFetchArray($statement)) {
665 $weight = $result['weight'];
666 $height = $result['height'];
667 $bps = $result['bps'];
668 $bpd = $result['bpd'];
669 $pulse = $result['pulse'];
670 $temperature = $result['temperature'];
671 // $clone_vitals = "/* vitals_key:: weight :: height :: systolic :: diastolic :: pulse :: temperature */\n";
672 $clone_vitals = "";
673 $clone_vitals .= "/* vitals\n :: $weight\n :: $height\n :: $bps\n :: $bpd\n :: $pulse\n :: $temperature\n */";
674 $clone_data_array[$clone_vitals] = $clone_vitals;
676 $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";
677 $statement = sqlStatement($query);
678 while ($result = sqlFetchArray($statement)) {
679 $clone_code_type = $result['code_type'];
680 $clone_code = $result['code'];
681 $clone_code_text = $result['code_text'];
682 $clone_modifier = $result['modifier'];
683 $clone_units = $result['units'];
684 $clone_fee = $result['fee'];
686 //added ability to grab justifications also - bm
687 $clone_justify = "";
688 $clone_justify_raw = $result['justify'];
689 $clone_justify_array = explode(":",$clone_justify_raw);
690 foreach ($clone_justify_array as $temp_justify) {
691 trim($temp_justify);
692 if ($temp_justify != "") {
693 $clone_justify .= ":: ".$temp_justify." ";
697 $clone_billing_data = "/* billing :: $clone_code_type :: $clone_code :: $clone_code_text :: $clone_modifier :: $clone_units :: $clone_fee $clone_justify*/";
698 $clone_data_array[$clone_billing_data] = $clone_billing_data;
701 } //end else (not clone others)
702 }//end of clone stuff
703 //end preselect column items
706 function init() {
707 var f2 = document.CAMOS;
708 if (clone_mode) {
709 clone_mode = false;
711 for (i1=0;i1<array1.length;i1++) {
712 f2.select_category.options[f2.select_category.length] = new Option(array1[i1][0], array1[i1][1]);
714 <?php
716 $temp_preselect_mode = $preselect_mode;
717 if ($preselect_category_override != '') {
718 $temp_preselect_mode = "by name";
719 $preselect_category = $preselect_category_override;
722 if (select_word("<?php echo fixquotes($temp_preselect_mode)."\", \"".fixquotes($preselect_category); ?>" ,f2.select_category)) {
723 click_category();
725 <?php
727 if (substr($_POST['hidden_mode'],0,5) == 'clone') {
728 echo "f2.textarea_content.value = '';\n";
729 // echo "f2.textarea_content.value += '/* count = ".count($clone_data_array)."*/\\n$break\\n';";
730 echo "f2.textarea_content.value += '/* count = ".count($clone_data_array)."*/\\n$break\\n';";
731 foreach($clone_data_array as $key => $val) {
732 echo "f2.textarea_content.value = f2.textarea_content.value + \"".fixquotes(str_replace($quote_search,$quote_replace,$val))."\\n$break\\n\"\n";
739 function click_category() {
740 var f2 = document.CAMOS;
741 var category_index = f2.select_category.selectedIndex;
742 if ((category_index < 0) || (category_index > f2.select_category.length-1)) {return 0;}
743 var sel = f2.select_category.options[f2.select_category.selectedIndex].value;
744 for (var i1=0;i1<array1.length;i1++) {
745 if (array1[i1][1] == sel) {
746 f2.select_subcategory.length = 0;
747 f2["select_item[]"].length = 0;
748 f2.textarea_content.value = '';
749 for (var i2=0;i2<array2.length;i2++) {
750 if (array1[i1][1] == array2[i2][1]) {
751 f2.select_subcategory.options[f2.select_subcategory.length] = new Option(array2[i2][0], array2[i2][2]);
756 <?php
758 $temp_preselect_mode = $preselect_mode;
759 if ($preselect_subcategory_override != '') {
760 $temp_preselect_mode = "by name";
761 $preselect_subcategory = $preselect_subcategory_override;
764 if (select_word("<?php echo fixquotes($temp_preselect_mode)."\", \"".fixquotes($preselect_subcategory); ?>" ,f2.select_subcategory)) {
765 click_subcategory();
768 function click_subcategory() {
769 var f2 = document.CAMOS;
770 var subcategory_index = f2.select_subcategory.selectedIndex;
771 if ((subcategory_index < 0) || (subcategory_index > f2.select_subcategory.length-1)) {return 0;}
772 var sel = f2.select_subcategory.options[f2.select_subcategory.selectedIndex].value;
773 for (var i1=0;i1<array2.length;i1++) {
774 if (array2[i1][2] == sel) {
775 f2["select_item[]"].length = 0;
776 f2.textarea_content.value = '';
777 for (var i2=0;i2<array3.length;i2++) {
778 if (array2[i1][2] == array3[i2][2]) {
779 f2["select_item[]"].options[f2["select_item[]"].length] = new Option(array3[i2][0], array3[i2][3]);
784 <?php
786 $temp_preselect_mode = $preselect_mode;
787 if ($preselect_item_override != '') {
788 $temp_preselect_mode = "by name";
789 $preselect_item = $preselect_item_override;
792 if (select_word("<?php echo fixquotes($temp_preselect_mode)."\", \"".fixquotes($preselect_item); ?>" ,f2["select_item[]"])) {
793 click_item();
794 preselect_off = true;
797 function click_item() {
798 var f2 = document.CAMOS;
799 var item_index = f2["select_item[]"].selectedIndex;
800 if ((item_index < 0) || (item_index > f2["select_item[]"].length-1)) {return 0;}
801 var sel = f2["select_item[]"].options[item_index].value;
802 for (var i1=0;i1<array3.length;i1++) {
803 if (array3[i1][3] == sel) {
804 //diplay text in content box
805 f2.textarea_content.value= array3[i1][1].replace(/\\/g,'');
810 function selectContains(myselect, str) {
811 for (var i=0;i<myselect.length;i++) {
812 if (myselect.options[i].text == trimString(str)) {return true;}
816 function insert_content(direction) {
817 var f2 = document.CAMOS;
818 var source_box = f2.textarea_content;
819 var target_box = f2.textarea_content02;
820 if (direction == 'up') {
821 source_box = f2.textarea_content02;
822 target_box = f2.textarea_content;
824 var sba = source_box.selectionStart;
825 var sbb = source_box.selectionEnd;
826 var tba = target_box.selectionStart;
827 var tbb = target_box.selectionEnd;
828 if (sbb-sba == 0) {
829 sba = 0;
830 sbb = source_box.value.length;
832 var insert_text = (source_box.value).
833 substring(sba, sbb);
834 target_box.value = (target_box.value).
835 substring(0,tba) + insert_text +
836 (target_box.value).substring(tba,target_box.value.length);
839 //AJAX FUNCTIONS
840 //Function to create an XMLHttp Object.
841 function getxmlhttp (){
842 //Create a boolean variable to check for a valid microsoft active X instance.
843 var xmlhttp = false;
845 //Check if we are using internet explorer.
846 try {
847 //If the javascript version is greater than 5.
848 xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
849 } catch (e) {
850 //If not, then use the older active x object.
851 try {
852 //If we are using internet explorer.
853 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
854 } catch (E) {
855 //Else we must be using a non-internet explorer browser.
856 xmlhttp = false;
860 //If we are using a non-internet explorer browser, create a javascript instance of the object.
861 if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
862 xmlhttp = new XMLHttpRequest();
865 return xmlhttp;
868 //Function to process an XMLHttpRequest.
869 function processajax (serverPage, obj, getOrPost, str){
870 //Get an XMLHttpRequest object for use.
871 xmlhttp = getxmlhttp ();
872 if (getOrPost == "get"){
873 xmlhttp.open("GET", serverPage);
874 xmlhttp.onreadystatechange = function() {
875 if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
876 obj.innerHTML = xmlhttp.responseText;
879 xmlhttp.send(null);
880 } else {
881 xmlhttp.open("POST", serverPage, true);
882 xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
883 xmlhttp.onreadystatechange = function() {
884 if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
885 obj.innerHTML = xmlhttp.responseText;
888 xmlhttp.send(str);
893 function setformvalues(form_array){
895 //Run through a list of all objects
896 var str = '';
897 for(key in form_array) {
898 str += key + "=" + encodeURIComponent(form_array[key]) + "&";
900 //Then return the string values.
901 return str;
904 //END OF AJAX RELATED FUNCTIONS
906 function js_button(mode,selection) {
907 var f2 = document.CAMOS;
908 //check lock next
909 if ( (mode == 'add') && (selection == 'change_content') && (isLocked()) ) {
910 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"); ?>");
911 return;
913 //end check lock
915 //check for blank or duplicate submissions
916 if ( (mode == 'add') || (mode == 'alter') ) {
917 if (selection == 'change_category') {
918 if (trimString(f2.change_category.value) == "") {
919 alert("<?php xl("You cannot add a blank value for a category!","e"); ?>");
920 return;
922 if (selectContains(f2.select_category, trimString(f2.change_category.value))) {
923 alert("<?php xl("There is already a category named","e"); ?>"+" "+f2.change_category.value+".");
924 return;
927 if (selection == 'change_subcategory') {
928 if (trimString(f2.change_subcategory.value) == "") {
929 alert("<?php xl("You cannot add a blank value for a subcategory!","e"); ?>");
930 return;
932 if (selectContains(f2.select_subcategory, trimString(f2.change_subcategory.value))) {
933 alert("<?php xl("There is already a subcategory named","e"); ?>"+" "+f2.change_subcategory.value+".");
934 return;
937 if (selection == 'change_item') {
938 if (trimString(f2.change_item.value) == "") {
939 alert("<?php xl("You cannot add a blank value for an item!","e"); ?>");
940 return;
942 if (selectContains(f2["select_item[]"], trimString(f2.change_item.value))) {
943 alert("<?php xl("There is already an item named","e"); ?>"+" "+f2.change_item.value+".");
944 return;
948 //end of check for blank or duplicate submissions
950 if (mode == 'delete') {
951 if (!confirm("<?php xl("Are you sure you want to delete this item from the database?","e"); ?>")) {
952 return;
955 //check selections and assign variable values
956 var f2 = document.CAMOS;
957 var category_index = f2.select_category.selectedIndex;
958 var category_value;
959 var category_text;
960 if (category_index < 0) {
961 if ((selection == 'change_subcategory') || (selection == 'change_item') ||
962 (selection == 'change_content')) {
963 // alert ('You have not selected a category!');
964 return;
966 category_value = -1;
967 category_text = '';
969 else {
970 category_value = f2.select_category.options[category_index].value;
971 category_text = f2.select_category.options[category_index].text;
973 var subcategory_index = f2.select_subcategory.selectedIndex;
974 var subcategory_value;
975 var subcategory_text;
976 if (subcategory_index < 0) {
977 if ((selection == 'change_item') || (selection == 'change_content')) {
978 // alert ('You have not selected a subcategory!');
979 return;
981 subcategory_value = -1;
982 subcategory_text = '';
984 else {
985 subcategory_value = f2.select_subcategory.options[subcategory_index].value;
986 subcategory_text = f2.select_subcategory.options[subcategory_index].text;
988 var item_index = f2["select_item[]"].selectedIndex;
989 var item_value;
990 var item_text;
991 if (item_index < 0) {
992 if (selection == 'change_content') {
993 // alert ('You have not selected an item!');
994 return;
996 item_value = -1;
997 item_text = '';
999 else {
1000 item_value = f2["select_item[]"].options[item_index].value;
1001 item_text = f2["select_item[]"].options[item_index].text;
1003 f2.category.value = category_text;
1004 f2.subcategory.value = subcategory_text;
1005 f2.item.value = item_text;
1006 //end of setting values relating to selections
1008 //deal with clone buttons or add, alter, delete.
1009 if ( (mode.substr(0,5) == 'clone') || (mode == 'add') || (mode == 'add to') ||
1010 (mode == 'alter') || (mode =='delete') ) {
1011 f2.hidden_mode.value = mode;
1012 f2.hidden_selection.value = selection;
1013 f2.hidden_category.value = category_value;
1014 f2.hidden_subcategory.value = subcategory_value;
1015 f2.hidden_item.value = item_value;
1016 <?php
1017 if (!$out_of_encounter) {
1019 f2.action = '<?php print $GLOBALS['webroot'] ?>/interface/patient_file/encounter/load_form.php?formname=CAMOS';
1020 <?php
1021 } else {
1023 f2.action = '<?php print $GLOBALS['webroot'] ?>/interface/forms/CAMOS/new.php?mode=external';
1024 <?php
1027 f2.target = '_self';
1028 f2.submit();
1029 return;
1031 //ajax code
1032 var myobj = document.getElementById('id_info');
1033 myarray = new Array();
1034 myarray['category'] = category_text;
1035 myarray['subcategory'] = subcategory_text;
1036 myarray['item'] = item_text;
1037 myarray['content']
1038 if (selection == 'submit_selection') {
1039 myarray['content'] = (f2.textarea_content.value).substring(f2.textarea_content.selectionStart, f2.textarea_content.selectionEnd);
1041 else {myarray['content'] = f2.textarea_content.value;}
1042 var str = setformvalues(myarray);
1043 // alert(str);
1044 processajax ('<?php print $GLOBALS['webroot'] ?>/interface/forms/CAMOS/ajax_save.php', myobj, "post", str);
1045 // alert("submitted!");
1046 //ajax code
1049 function selectItem () {
1050 f2 = document.CAMOS;
1051 f2.item.value=f2["select_item[]"].options[f2["select_item[]"].selectedIndex].text;
1052 f2.content.value = f2.textarea_content.value;
1054 function getKey(e) { //process keypresses with getKeyPress
1055 var keynum;
1056 if(window.event) { //IE
1057 keynum = e.keyCode;
1058 } else if(e.which) { // Netscape/Firefox/Opera
1059 keynum = e.which;
1061 return keynum;
1063 function gotoOne(e) {
1064 if (getKey(e) == 96) {
1065 document.CAMOS.clone_others_search.focus();
1068 function processEnter(e,message) {
1069 if (getKey(e) == 13) {
1070 if (message == "clone_others_search") {
1071 js_button('clone others', 'clone others');
1076 </script>
1077 </head>
1078 <body <?php echo $top_bg_line;?> topmargin=0 rightmargin=0 leftmargin=2 bottommargin=0 marginwidth=2 marginheight=0 onload="init()">
1079 <div name="form_container" onKeyPress="gotoOne(event)">
1080 <form method=post action="<?php echo $rootdir;?>/forms/CAMOS/save.php?mode=new" name="CAMOS">
1081 <?php
1082 if (!$out_of_encounter) {
1083 // echo "<h1>$out_of_encounter</h1>\n";
1085 <input type=button name=clone value='<?php xl('Clone','e'); ?>' onClick="js_button('clone', 'clone')">
1086 <input type=button name=clone_visit value='<?php xl('Clone Past Visit','e'); ?>' onClick="js_button('clone last visit', 'clone last visit')">
1087 <select name=stepback>
1088 <option value=1><?php xl('Back one visit','e'); ?></option>
1089 <option value=2><?php xl('Back two visits','e'); ?></option>
1090 <option value=3><?php xl('Back three visits','e'); ?></option>
1091 <option value=4><?php xl('Back four visits','e'); ?></option>
1092 <option value=5><?php xl('Back five visits','e'); ?></option>
1093 <option value=6><?php xl('Back six visits','e'); ?></option>
1094 <option value=7><?php xl('Back seven visits','e'); ?></option>
1095 <option value=8><?php xl('Back eight visits','e'); ?></option>
1096 <option value=9><?php xl('Back nine visits','e'); ?></option>
1097 <option value=10><?php xl('Back ten visits','e'); ?></option>
1098 <option value=11><?php xl('Back eleven visits','e'); ?></option>
1099 <option value=12><?php xl('Back twelve visits','e'); ?></option>
1100 </select>
1101 <?php
1102 echo "<a href='".$GLOBALS['webroot'] . "/interface/patient_file/encounter/$returnurl' onclick='top.restoreSession()'>[".xl('Leave The Form')."]</a>";
1104 <input type=button name='hide columns' value='<?php xl('Hide/Show Columns','e'); ?>' onClick="hide_columns()">
1105 <input type=button name='submit form' value='<?php xl('Submit Selected Content','e'); ?>' onClick="js_button('submit','submit_selection')">
1106 <?php
1107 } //end of if !$out_of_encounter
1109 <div id=id_info style="display:inline">
1110 <!-- supposedly where ajax induced php pages can print their output to... -->
1111 </div>
1112 <div id=id_mainbox style="display:inline">
1113 <?php
1114 if ($error != '') {
1115 echo "<h1> error: ".$error."</h1>\n";
1118 <table border=1>
1119 <tr>
1120 <td>
1121 <div id=id_category_column_header style="display:inline">
1122 <?php xl('Category',e)?>
1123 </div> <!-- end of id_category_column_header -->
1124 </td>
1125 <td>
1126 <div id=id_subcategory_column_header style="display:inline">
1127 <?php xl('Subcategory',e)?>
1128 </div> <!-- end of id_subcategory_column_header -->
1129 </td>
1130 <td>
1131 <div id=id_item_column_header style="display:inline">
1132 <?php xl('Item',e)?>
1133 </div> <!-- end of id_item_column_header -->
1134 </td>
1135 <td>
1136 <?php xl('Content',e)?>
1137 </td>
1138 </tr>
1140 <tr>
1141 <td>
1142 <div id=id_category_column style="display:inline">
1143 <select name=select_category size=<?php echo $select_size ?> onchange="click_category()"></select><br>
1144 <?php
1146 if (myAuth() == 1) {//root user only can see administration option
1148 <input type=text name=change_category><br>
1149 <input type=button name=add1 value='<?php xl('add','e'); ?>' onClick="js_button('add','change_category')">
1150 <input type=button name=alter1 value='<?php xl('alter','e'); ?>' onClick="js_button('alter','change_category')">
1151 <input type=button name=del1 value='<?php xl('del','e'); ?>' onClick="js_button('delete','change_category')"><br>
1152 <?php
1156 </div> <!-- end of id_category_column -->
1157 </td>
1158 <td>
1159 <div id=id_subcategory_column style="display:inline">
1160 <select name=select_subcategory size=<?php echo $select_size ?> onchange="click_subcategory()"></select><br>
1161 <?php
1163 if (myAuth() == 1) {//root user only can see administration option
1165 <input type=text name=change_subcategory><br>
1166 <input type=button name=add2 value='<?php xl('add','e'); ?>' onClick="js_button('add','change_subcategory')">
1167 <input type=button name=alter1 value='<?php xl('alter','e'); ?>' onClick="js_button('alter','change_subcategory')">
1168 <input type=button name=del2 value='<?php xl('del','e'); ?>' onClick="js_button('delete','change_subcategory')"><br>
1169 <?php
1173 </div> <!-- end of id_subcategory_column -->
1174 </td>
1175 <td>
1176 <div id=id_item_column style="display:inline">
1177 <select name=select_item[] size=<?php echo $select_size ?> onchange="click_item()" multiple="multiple"></select><br>
1178 <?php
1180 if (myAuth() == 1) {//root user only can see administration option
1182 <input type=text name=change_item><br>
1183 <input type=button name=add3 value='<?php xl('add','e'); ?>' onClick="js_button('add','change_item')">
1184 <input type=button name=alter1 value='<?php xl('alter','e'); ?>' onClick="js_button('alter','change_item')">
1185 <input type=button name=del3 value='<?php xl('del','e'); ?>' onClick="js_button('delete','change_item')"><br>
1186 <?php
1190 </div> <!-- end of id_item_column -->
1191 </td>
1192 <td>
1193 <div id=id_textarea_content style="display:inline">
1194 <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>
1195 <br/>
1196 <input type=text size=35 name=clone_others_search value='<?php echo $_POST['clone_others_search'] ?>' tabindex=1 onKeyPress="processEnter(event,'clone_others_search')"/>
1197 <input type=button name=clone_others_search_button value='<?php xl('Search','e'); ?>' onClick="js_button('clone others', 'clone others')"/>
1198 <input type=button name=clone_others_selected_search_button value='<?php xl('Search Selected','e'); ?>' onClick="js_button('clone others selected', 'clone others selected')"/>
1199 <?php
1201 if (myAuth() == 1) {//root user only can see administration option
1203 <div id=id_main_content_buttons style="display:block">
1204 <input type=button name=add4 value='<?php xl('Add','e'); ?>' onClick="js_button('add','change_content')">
1205 <input type=button name=add4 value='<?php xl('Add to','e'); ?>' onClick="js_button('add to','change_content')">
1206 <input type=button name=lock value='<?php xl('Lock','e'); ?>' onClick="lock_content()">
1207 <?php
1209 if (!$out_of_encounter) { //do not do stuff that is encounter specific if not in an encounter
1211 <input type=button name=icd9 value='<?php xl('ICD9','e'); ?>' onClick="append_icd9()">
1212 </div> <!-- end of id_main_content_buttons-->
1213 <?php
1217 <?php
1221 </td>
1222 </td>
1223 </tr>
1224 </table>
1226 <input type=hidden name=hidden_mode>
1227 <input type=hidden name=hidden_selection>
1228 <input type=hidden name=hidden_category>
1229 <input type=hidden name=hidden_subcategory>
1230 <input type=hidden name=hidden_item>
1232 <input type=hidden name=category>
1233 <input type=hidden name=subcategory>
1234 <input type=hidden name=item>
1235 <input type=hidden name=content>
1236 <?php
1238 if (!$out_of_encounter) { //do not do stuff that is encounter specific if not in an encounter
1240 <input type=button name='submit form' value='<?php xl('Submit All Content','e'); ?>' onClick="js_button('submit','submit')">
1241 <input type=button name='submit form' value='<?php xl('Submit Selected Content','e'); ?>' onClick="js_button('submit','submit_selection')">
1242 <?php
1246 <?php
1248 if (!$out_of_encounter) { //do not do stuff that is encounter specific if not in an encounter
1249 echo "<a href='".$GLOBALS['webroot'] . "/interface/patient_file/encounter/$returnurl' onclick='top.restoreSession()'>[".xl('Leave The Form')."]</a>";
1250 echo "<a href='".$GLOBALS['webroot'] . "/interface/forms/CAMOS/help.html' target='new'> | [".xl('Help')."]</a>";
1251 // echo $previous_encounter_data; //probably don't need anymore now that we have clone last visit
1254 </div>
1255 </form>
1256 </div>
1257 <?php
1258 formFooter();
1260 //PHP FUNCTIONS
1262 function fixquotes ($string) {
1263 // this function is needed to treat a string before php echos it in the process of generating javascript.
1264 // 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'.
1265 // $string = preg_replace('/([\\\])*\'/', "\\\'", $string);
1266 $string = preg_replace('/([\\\])*\"/', "\\\"", $string);
1267 return $string;
1270 function searchName($string) { //match one or more names and return clause for query of pids
1271 $string = trim($string);
1272 if ($string == 'this') {
1273 return " and (pid = ".$_SESSION['pid'].") ";
1275 global $limit;
1276 $ret = '';
1277 $data = array();
1278 $fname = '';
1279 $lname = '';
1280 if ($string == '') {return $ret;}
1281 $split = preg_split('/\s+/',$string);
1282 $name1 = $split[1];
1283 $name2 = $split[0];
1284 if ($name1 != '') {$name1 = "%".$name1."%";}
1285 if ($name2 != '') {$name1 = "%".$name2."%";}
1286 $query = sqlStatement("select pid from patient_data where fname like '$name1' or fname like '$name2' or " .
1287 "lname like '$name1' or lname like '$name2' limit $limit");
1288 while ($results = mysql_fetch_array($query, MYSQL_ASSOC)) {
1289 array_push($data,$results['pid']);
1291 if (count($data) > 0) {
1292 $ret = join(" or pid = ",$data);
1293 $ret = " and (pid = ".$ret.") ";
1295 return $ret;
1297 function getMyPatientData($form_id, $show_phone_flag) {//return a string of patient data and encounter data based on the form_CAMOS id
1298 $ret = '';
1299 $name = '';
1300 $dob = '';
1301 $enc_date = '';
1302 $phone_list = '';
1303 $pid = '';
1304 $query = sqlStatement("select t1.pid, t1.fname, t1.mname, t1.lname, " .
1305 "t1.phone_home, t1.phone_biz, t1.phone_contact, t1.phone_cell, " .
1306 "date_format(t1.DOB,'%m-%d-%y') as DOB, date_format(t2.date,'%m-%d-%y') as date, " .
1307 "datediff(current_date(),t2.date) as days " .
1308 "from patient_data as t1 join forms as t2 on (t1.pid = t2.pid) where t2.form_id=$form_id " .
1309 "and form_name like 'CAMOS%'");
1310 if ($results = mysql_fetch_array($query, MYSQL_ASSOC)) {
1311 $pid = $results['pid'];
1312 $fname = $results['fname'];
1313 $mname = $results['mname'];
1314 $lname = $results['lname'];
1315 if ($mname) {$name = $fname.' '.$mname.' '.$lname;}
1316 else {$name = $fname.' '.$lname;}
1317 $dob = $results['DOB'];
1318 $enc_date = $results['date'];
1319 $days_ago = $results['days'];
1320 $phone_list =
1321 "/* Home: ".$results['phone_home']." | ".
1322 "Cell: ".$results['phone_cell']." | ".
1323 "Bus: ".$results['phone_biz']." | ".
1324 "Contact: ".$results['phone_contact']." */";
1326 $ret = "/*$pid, $name, DOB: $dob, Enc: $enc_date, $days_ago days ago. */";
1327 if ($show_phone_flag === true) {
1328 $ret .= "\n".$phone_list;
1330 return $ret;