Internationalization Project: added Amharic language.
[openemr.git] / interface / forms / CAMOS / new.php
blob7ad372f81e5e32ed3050c7a2af87962ec8c779aa
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;
19 $break = "/* ---------------------------------- */"; //break between clone items
20 $delete_subdata = true; //true means allowing the deletion of subdata. If you delete a category, all subcategories and items go too.
21 $limit = 100;
22 $select_size = 20;
23 $textarea_rows = 20;
24 $textarea_cols = 80;
25 $debug = '';
26 $error = '';
28 $preselect_category = '';
29 $preselect_subcategory = '';
30 $preselect_item = '';
31 $preselect_category_override = '';
32 $preselect_subcategory_override = '';
33 $preselect_item_override = '';
35 $quote_search = array("\r","\n");
36 $quote_replace = array("\\r","\\n");
37 $quote_search_content = array("\r","\n");
38 $quote_replace_content = array("\\r","\\n");
39 $category = str_replace($quote_search,$quote_replace,$_POST['change_category']);
40 $subcategory = str_replace($quote_search,$quote_replace,$_POST['change_subcategory']);
41 $item = str_replace($quote_search,$quote_replace,$_POST['change_item']);
42 $content = str_replace($quote_search_content,$quote_replace_content,$_POST['textarea_content']);
43 if ($_POST['hidden_category']) {$preselect_category = $_POST['hidden_category'];}
44 if ($_POST['hidden_subcategory']) {$preselect_subcategory = $_POST['hidden_subcategory'];}
45 if ($_POST['hidden_item']) {$preselect_item = $_POST['hidden_item'];}
46 //handle changes to database
47 if (substr($_POST['hidden_mode'],0,3) == 'add') {
48 if ($_POST['hidden_selection'] == 'change_category') {
49 $preselect_category_override = $_POST['change_category'];
51 $category = formDataCore($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 $subcategory = formDataCore($subcategory);
64 $query = "INSERT INTO form_CAMOS_subcategory (user, subcategory, category_id) values ('".$_SESSION['authUser']."', '";
65 $query .= $subcategory."', '".$category_id."')";
66 sqlInsert($query);
69 elseif ($_POST['hidden_selection'] == 'change_item') {
70 $preselect_item_override = $_POST['change_item'];
71 $category_id = $_POST['hidden_category'];
72 $subcategory_id = $_POST['hidden_subcategory'];
73 if (($category_id >= 0 ) && ($subcategory_id >=0)) {
75 $item = formDataCore($item);
77 $query = "INSERT INTO form_CAMOS_item (user, item, content, subcategory_id) values ('".$_SESSION['authUser']."', '";
78 $query .= $item."', '".$content."', '".$subcategory_id."')";
79 sqlInsert($query);
83 elseif ($_POST['hidden_selection'] == 'change_content') {
84 $item_id = $_POST['hidden_item'];
85 if ($item_id >= 0) {
86 if ($_POST['hidden_mode'] == 'add to') {
87 $tmp = sqlQuery("SELECT content from form_CAMOS_item where id = ".$item_id);
88 if (isset($tmp)) {
89 $content .= "\n".$tmp['content'];
93 // Not stripping slashes, unclear why, but will keep same functionality
94 // below just adds the escapes.
95 $content = add_escape_custom($content);
97 $query = "UPDATE form_CAMOS_item set content = '".$content."' where id = ".$item_id;
98 sqlInsert($query);
102 elseif ($_POST['hidden_mode'] == 'delete') {
103 if ($delete_subdata) { //if set, allow for the deletion of all subdata
104 if ($_POST['hidden_selection'] == 'change_category') {
105 $to_delete_id = $_POST['hidden_category'];
106 //first, look for associated subcategories, if any
107 $statement1 = sqlStatement("select id from form_CAMOS_subcategory where category_id = $to_delete_id");
108 while ($result1 = sqlFetchArray($statement1)) {
109 $query = "DELETE FROM form_CAMOS_item WHERE subcategory_id = " . $result1['id'];
110 sqlInsert($query);
112 $query = "DELETE FROM form_CAMOS_subcategory WHERE category_id = $to_delete_id";
113 sqlInsert($query);
114 $query = "DELETE FROM form_CAMOS_category WHERE id = $to_delete_id";
115 sqlInsert($query);
117 elseif ($_POST['hidden_selection'] == 'change_subcategory') {
118 $to_delete_id = $_POST['hidden_subcategory'];
119 $query = "DELETE FROM form_CAMOS_item WHERE subcategory_id = $to_delete_id";
120 sqlInsert($query);
121 $query = "DELETE FROM form_CAMOS_subcategory WHERE id = $to_delete_id";
122 sqlInsert($query);
124 elseif ($_POST['hidden_selection'] == 'change_item') {
125 if ((isset($_POST['select_item'])) && (count($_POST['select_item'])>1)) {
126 foreach($_POST['select_item'] as $v) {
127 $to_delete_id = $v;
128 $query = "DELETE FROM form_CAMOS_item WHERE id = " .$to_delete_id;
129 sqlInsert($query);
131 } else {
132 $to_delete_id = $_POST['hidden_item'];
133 $query = "DELETE FROM form_CAMOS_item WHERE id = " .$to_delete_id;
134 sqlInsert($query);
137 } else { //delete only if subdata is empty, 'the old way'.
138 if ($_POST['hidden_selection'] == 'change_category') {
139 $to_delete_id = $_POST['hidden_category'];
140 $to_delete_from_table = 'form_CAMOS_category';
141 $to_delete_from_subtable = 'form_CAMOS_subcategory';
142 $to_delete_from_subsubtable = 'form_CAMOS_item';
143 $tablename = 'category';
144 $subtablename = 'subcategory';
145 $subsubtablename = 'item';
147 elseif ($_POST['hidden_selection'] == 'change_subcategory') {
148 $to_delete_id = $_POST['hidden_subcategory'];
149 $to_delete_from_table = 'form_CAMOS_subcategory';
150 $to_delete_from_subtable = 'form_CAMOS_item';
151 $tablename = 'subcategory';
152 $subtablename = 'item';
154 elseif ($_POST['hidden_selection'] == 'change_item') {
155 $to_delete_id = $_POST['hidden_item'];
156 $to_delete_from_table = 'form_CAMOS_item';
157 $to_delete_from_subtable = '';
158 $tablename = 'item';
159 $subtablename = '';
162 if ($subtablename == '') { //deleting an item. The simple case.
163 $query = "DELETE FROM ".$to_delete_from_table." WHERE id like '".$to_delete_id."'";
164 sqlInsert($query);
166 else { //deleting a category or subcategory, check to see if related data below is empty first
167 $query = "SELECT count(id) FROM ".$to_delete_from_subtable." WHERE ".$tablename."_id like '".$to_delete_id."'";
168 $statement = sqlStatement($query);
169 if ($result = sqlFetchArray($statement)) {
170 if ($result['count(id)'] == 0) {
171 $query = "DELETE FROM ".$to_delete_from_table." WHERE id like '".$to_delete_id."'";
172 sqlInsert($query);
174 else {
175 $error = $subtablename." not empty!";
179 } //end of delete only if subdata is empty
181 elseif ($_POST['hidden_mode'] == 'alter') {
182 $newval = $_POST[$_POST['hidden_selection']];
183 if ($_POST['hidden_selection'] == 'change_category') {
184 $to_alter_id = $_POST['hidden_category'];
185 $to_alter_table = 'form_CAMOS_category';
186 $to_alter_column = 'category';
188 elseif ($_POST['hidden_selection'] == 'change_subcategory') {
189 $to_alter_id = $_POST['hidden_subcategory'];
190 $to_alter_table = 'form_CAMOS_subcategory';
191 $to_alter_column = 'subcategory';
193 elseif ($_POST['hidden_selection'] == 'change_item') {
194 $to_alter_id = $_POST['hidden_item'];
195 $to_alter_table = 'form_CAMOS_item';
196 $to_alter_column = 'item';
198 $query = "UPDATE ".$to_alter_table." set ".$to_alter_column." = '".$newval."' where id = ".$to_alter_id;
199 sqlInsert($query);
201 // end handle changes to database
203 //preselect column items
204 //either a database change has been made, so the user should be made to feel that they never left the same CAMOS screen
205 //or, CAMOS has been started freshly, therefore the last entry of the current patient should be selected.
206 $preselect_mode = '';
207 if ($preselect_category == '' && !$out_of_encounter) {
208 $preselect_mode = 'by name';
209 //at this point, if this variable has not been set, CAMOS must have been start over
210 //so let's get the most recent values from form_CAMOS for this patient's pid
211 $tmp = sqlQuery("SELECT max(id) AS max FROM form_CAMOS WHERE " .
212 "pid = '" . $_SESSION['pid'] . "'");
213 $maxid = $tmp['max'] ? $tmp['max'] : 0;
215 $query = "SELECT category, subcategory, item FROM form_CAMOS WHERE id = $maxid";
216 $statement = sqlStatement($query);
217 if ($result = sqlFetchArray($statement)) {
218 $preselect_category = $result['category'];
219 $preselect_subcategory = $result['subcategory'];
220 $preselect_item = $result['item'];
222 else {$preselect_mode = '';}
224 else {
225 $preselect_mode = 'by number';
229 <html><head>
230 <link rel=stylesheet href="<?echo $css_header;?>" type="text/css">
232 <script language="javascript" type="text/javascript">
234 var array1 = new Array();
235 var array2 = new Array();
236 var array3 = new Array();
237 var buffer = new Array();
238 var icd9_list = '';
239 var preselect_off = false;
240 var content_change_flag = false;
241 var lock_override_flag = false;
242 var columns_status = 'show';
243 var hs_status = false;
244 var vs_status = false;
245 var hide_tc02_status = false;
246 var clone_mode = false;
248 var crop_buffer = '';
249 var special_select_start = 0;
250 var special_select_end = 0;
253 if (substr($_POST['hidden_mode'],0,5) == 'clone') {
254 echo "clone_mode = true;\n";
258 function clear_box(obj) {
259 var hold = obj.value;
260 obj.value = buffer[obj] ? buffer[obj] : '';
261 buffer[obj] = hold;
264 function showit() {
265 var log = document.getElementById('log');
266 var content = document.testform.testarea;
267 specialSelect(content,'/*','*/');
270 function specialSelect(t_area, delim_1, delim_2) {
271 if (crop_buffer != '') {
272 t_area.value = crop_buffer;
273 crop_buffer = '';
274 return;
276 var cv = t_area.value;
277 var start = t_area.selectionStart;
278 var end = t_area.selectionEnd;
279 var newstart = cv.lastIndexOf(delim_1, start);
280 var newend = cv.indexOf(delim_2, end);
281 if ((newstart == -1) || (newend == -1)) {return;}
282 if ((newstart == special_select_start) && (newend == special_select_end)) {
283 cropToSelect(t_area, delim_2);
285 if (newstart >= 0 && newend >= 0) {
286 t_area.selectionStart = newstart;
287 t_area.selectionEnd = newend+delim_2.length;
289 special_select_start = newstart;
290 special_select_end = newend;
293 function cropToSelect(t_area, delim_2) {
294 var cv = t_area.value;
295 crop_buffer = cv;
296 var start = special_select_start;
297 var end = special_select_end+delim_2.length;
298 var length = end-start;
299 t_area.value = cv.substr(start,length);
302 function hide_columns() {
303 var column01 = document.getElementById('id_category_column');
304 var column02 = document.getElementById('id_subcategory_column');
305 var column03 = document.getElementById('id_item_column');
306 var columnheader01 = document.getElementById('id_category_column_header');
307 var columnheader02 = document.getElementById('id_subcategory_column_header');
308 var columnheader03 = document.getElementById('id_item_column_header');
310 if (columns_status == 'show') {
311 columns_status = 'hide';
312 column01.style.display = 'none';
313 column02.style.display = 'none';
314 column03.style.display = 'none';
315 columnheader01.style.display = 'none';
316 columnheader02.style.display = 'none';
317 columnheader03.style.display = 'none';
319 else {
320 columns_status = 'show';
321 column01.style.display = 'inline';
322 column02.style.display = 'inline';
323 column03.style.display = 'inline';
324 columnheader01.style.display = 'inline';
325 columnheader02.style.display = 'inline';
326 columnheader03.style.display = 'inline';
328 resize_content();
330 function resize_content() {
331 f2 = document.CAMOS;
332 f4 = f2.textarea_content
333 if (f4.cols == <?php echo $textarea_cols ?>) {
334 f4.cols = <?php echo $textarea_cols ?>*2;
335 f4.rows = <?php echo $textarea_rows?>;
336 } else {
337 f4.cols = <?php echo $textarea_cols ?>;
338 f4.rows = <?php echo $textarea_rows?>;
341 //function hs_button() {
342 // f2 = document.CAMOS;
343 // if (hs_status) {
344 // hide_columns();
345 // f2.textarea_content.cols /= 3;
346 // f2.textarea_content02.cols /= 3;
347 // hs_status = false;
348 // } else {
349 // hide_columns();
350 //// f2.textarea_content.cols *= 3;
351 // f2.textarea_content02.cols *= 3;
352 // hs_status = true;
353 // }
358 //deal with locking of content = prevent accidental overwrite
360 function trimString (str) {
361 str = this != window? this : str;
362 return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
364 function isLocked() {
365 f2 = document.CAMOS;
366 if (lock_override_flag) {
367 lock_override_flag = false;
368 return false;
370 return /\/\*\s*lock\s*\:\:\s*\*\//.test(f2.textarea_content.value);
372 function lock_content() {
373 f2 = document.CAMOS;
374 if ((trimString(f2.textarea_content.value) != "") && (!isLocked())) {
375 f2.textarea_content.value = f2.textarea_content.value + "\n\n" + "/*lock::*/";
376 lock_override_flag = true;
377 js_button('add','change_content');
380 function allSelected() {
381 var f2 = document.CAMOS;
382 if ( (f2.select_category.selectedIndex < 0) || (f2.select_subcategory.selectedIndex < 0) || (f2["select_item[]"].selectedIndex < 0) ) {
383 return false; //one of the columns is not selected
385 else {
386 return true; //all columns have a selection
390 function content_focus() {
391 if (content_change_flag == false) {
392 if (!allSelected()) {
393 // alert("If you add text to the 'content' box without a selection in each column (category, subcategory, item), you will likely lose your work.")
396 else {return;}
397 content_change_flag = true;
399 function content_blur() {
400 if (content_change_flag == true) {
401 content_change_flag = false;
405 if (!$out_of_encounter) { //do not do stuff that is encounter specific if not in an encounter
406 //ICD9
407 $icd9_flag = false;
408 $query = "SELECT code_text, code FROM billing WHERE encounter=".$_SESSION['encounter'].
409 " AND pid=".$_SESSION['pid']." AND code_type like 'ICD9' AND activity=1";
410 $statement = sqlStatement($query);
411 if ($result = sqlFetchArray($statement)) {
412 $icd9_flag = true;
413 echo "icd9_list = \"\\n\\n\\\n";
414 echo $result['code']." ".$result['code_text']."\\n\\\n";
416 while ($result = sqlFetchArray($statement)) {
417 echo $result['code']." ".$result['code_text']."\\n\\\n";
419 if ($icd9_flag) {echo "\";\n";}
422 $query = "SELECT id, category FROM form_CAMOS_category ORDER BY category";
423 $statement = sqlStatement($query);
424 $i = 0;
425 while ($result = sqlFetchArray($statement)) {
426 echo "array1[".$i."] = new Array(\"".fixquotes($result['category'])."\",\"".$result['id']."\", new Array());\n";
427 $i++;
429 $i=0;
430 $query = "SELECT id, subcategory, category_id FROM form_CAMOS_subcategory ORDER BY subcategory";
431 $statement = sqlStatement($query);
432 while ($result = sqlFetchArray($statement)) {
433 echo "array2[".$i."] = new Array(\"".fixquotes($result['subcategory'])."\", \"".$result['category_id']."\", \"".$result['id']."\", new Array());\n";
434 $i++;
436 $i=0;
437 $query = "SELECT id, item, content, subcategory_id FROM form_CAMOS_item ORDER BY item";
438 $statement = sqlStatement($query);
439 while ($result = sqlFetchArray($statement)) {
440 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'].
441 "\",\"".$result['id']."\");\n";
442 $i++;
446 function append_icd9() {
447 var f2 = document.CAMOS;
448 f2.textarea_content.value = f2.textarea_content.value + icd9_list;
451 function select_word(mode, mystring, myselect) { //take a string and select it in a select box if present
452 if (preselect_off) return 0;
453 for (var i=0;i<myselect.length;i++) {
454 var match = '';
455 if (mode == 'by name') {
456 match = myselect.options[i].text;
458 else if (mode == 'by number') {
459 match = myselect.options[i].value;
461 else {return 0;}
462 if (match == mystring) {
463 myselect.selectedIndex = i;
466 return 1;
469 if (1) { //we are hiding the clone buttons and still need 'search others' so this is not to be removed if out of encounter anymore.
470 //if (!$out_of_encounter) { //do not do stuff that is encounter specific if not in an encounter
471 //cloning - similar process to preselect set to first time starting CAMOS
472 //as above
473 $clone_category = '';
474 $clone_subcategory = '';
475 $clone_item = '';
476 $clone_content = '';
477 $clone_data1 = '';
478 $clone_data2 = '';
479 $clone_data_array = array();
480 if (substr($_POST['hidden_mode'],0,5) == 'clone') {
481 $clone_category = $_POST['category'] ? $_POST['category'] : '';
482 $clone_category_term = '';
483 if ($clone_category != '') {
484 $clone_category_term = " where category like '".$clone_category."'";
486 $clone_subcategory = $_POST['subcategory'] ? $_POST['subcategory'] : '';
487 $clone_subcategory_term = '';
488 if ($clone_subcategory != '') {
489 $clone_subcategory_term = " and subcategory like '".$_POST['subcategory']."'";
491 $clone_item = $_POST['item'] ? $_POST['item'] : '';
492 $clone_item_term = '';
493 if ($clone_item != '') {
494 $clone_item_term = " and item like '".$_POST['item']."'";
496 $clone_search = trim($_POST['clone_others_search']);
498 $name_data_flag = false; //flag to see if we are going to use patient names in search result of clone others.
499 $show_phone_flag = false; //if we do show patient names, flag to see if we show phone numbers too
500 $pid_clause = ''; //if name search, will return a limited list of names to search for.
501 if (strpos($clone_search, "::") !== false) {
502 $name_data_flag = true;
503 $show_phone_flag = true;
504 $split = preg_split('/\s*::\s*/', $clone_search);
505 $clone_search = $split[1];
506 $pid_clause = searchName($split[0]);
508 elseif (strpos($clone_search, ":") !== false) {
509 $name_data_flag = true;
510 $split = preg_split('/\s*:\s*/', $clone_search);
511 $clone_search = $split[1];
512 $pid_clause = searchName($split[0]);
515 $clone_search_term = '';
516 if ($clone_search != '') {
517 $clone_search = preg_replace('/\s+/', '%', $clone_search);
518 if (substr($clone_search,0,1) == "`") {
519 $clone_subcategory_term = '';
520 $clone_item_term = '';
521 $clone_search = substr($clone_search,1);
523 $clone_search_term = " and content like '%$clone_search%'";
525 if (substr($_POST['hidden_mode'],0,12) == 'clone others') { //clone from search box
527 if (preg_match('/^(export)(.*)/',$clone_search,$matches)) {
528 $query1 = "select id, category from form_CAMOS_category";
529 $statement1 = sqlStatement($query1);
530 while ($result1 = sqlFetchArray($statement1)) {
531 $tmp = $result1['category'];
532 $tmp = "/*import::category::$tmp*/"."\n";
533 $clone_data_array[$tmp] = $tmp;
534 $query2 = "select id,subcategory from form_CAMOS_subcategory where category_id=".$result1['id'];
535 $statement2 = sqlStatement($query2);
536 while ($result2 = sqlFetchArray($statement2)) {
537 $tmp = $result2['subcategory'];
538 $tmp = "/*import::subcategory::$tmp*/"."\n";
539 $clone_data_array[$tmp] = $tmp;
540 $query3 = "select item, content from form_CAMOS_item where subcategory_id=".$result2['id'];
541 $statement3 = sqlStatement($query3);
542 while ($result3 = sqlFetchArray($statement3)) {
543 $tmp = $result3['item'];
544 $tmp = "/*import::item::$tmp*/"."\n";
545 $clone_data_array[$tmp] = $tmp;
546 $tmp = $result3['content'];
547 $tmp = "/*import::content::$tmp*/"."\n";
548 $clone_data_array[$tmp] = $tmp;
552 $clone_data_array = array();
554 elseif ((preg_match('/^(billing)(.*)/',$clone_search,$matches)) ||
555 (preg_match('/^(codes)(.*)/',$clone_search,$matches))) {
556 $table = $matches[1];
557 $line = $matches[2];
558 $line = '%'.trim($line).'%';
559 $search_term = preg_replace('/\s+/','%',$line);
560 $query = "select code, code_type,code_text,modifier,units,fee from $table where code_text like '$search_term' limit $limit";
561 $statement = sqlStatement($query);
562 while ($result = sqlFetchArray($statement)) {
563 $code_type = $result['code_type'];
564 if ($code_type == 1) {$code_type = 'CPT4';}
565 if ($code_type == 2) {$code_type = 'ICD9';}
566 if ($code_type == 3) {$code_type = 'OTHER';}
567 $code = $result['code'];
568 $code_text = $result['code_text'];
569 $modifier = $result['modifier'];
570 $units = $result['units'];
571 $fee = $result['fee'];
572 $tmp = "/*billing::$code_type::$code::$code_text::$modifier::$units::$fee*/";
573 $clone_data_array[$tmp] = $tmp;
575 } else {
576 //$clone_data_array['others'] = '/*'.$clone_category.'::'.$clone_subcategory.'::'.
577 // $clone_item.'*/';
578 //See the two lines commented out just below:
579 //I am trying out searching all content regardless of category, subcategory, item...
580 //because of this, we have to limit results more. There may be a few lines
581 //above that should be deleted if this becomes the normal way of doing these searches.
582 //Consider making the two queries below by encounter instead of camos id.
583 //This may be a little tricky.
584 if ($_POST['hidden_mode'] == 'clone others selected') { //clone from search box
585 $query = "select id, category, subcategory, item, content from form_CAMOS" .
586 $clone_category_term.$clone_subcategory_term.$clone_item_term.
587 $clone_search_term.$pid_clause." order by id desc limit $limit";
588 } else {
589 $query = "select id, category, subcategory, item, content from form_CAMOS" .
590 " where " .
591 //"category like '%$clone_search%' or" .
592 //" subcategory like '%$clone_search%' or" .
593 //" item like '%$clone_search%' or" .
594 " content like '%$clone_search%'".$pid_clause." order by id desc limit $limit";
596 $statement = sqlStatement($query);
597 while ($result = sqlFetchArray($statement)) {
598 $tmp = '/*camos::'.$result['category'].'::'.$result['subcategory'].
599 '::'.$result['item'].'::'.$result['content'].'*/';
600 if ($name_data_flag === true) {
601 $tmp = getMyPatientData($result['id'],$show_phone_flag)."\n$break\n".$tmp;
603 $key_tmp = preg_replace('/\W+/','',$tmp);
604 $key_tmp = preg_replace('/\W+/','',$tmp);
605 $clone_data_array[$key_tmp] = $tmp;
608 } else {//end of clone others
609 $query = "SELECT date(date) as date, subcategory, item, content FROM form_CAMOS WHERE category like '".
610 $clone_category."' and pid=".$_SESSION['pid']." order by id desc";
612 if ($_POST['hidden_mode'] == 'clone last visit') {
613 //go back $stepback # of encounters...
614 //This has been changed to clone last visit based on actual last encounter rather than as it was
615 //only looking at most recent BILLED encounters. To go back to billed encounters, change the following
616 //two queries to the 'billing' table rather than form_encounter and make sure to add in 'and activity=1'
617 //OK, now I have tried tracking last encounter from billing, then form_encounter. Now, we are going to
618 //try from forms where form_name like 'CAMOS%' so we will not bother with encounters that have no CAMOS entries...
619 $stepback = $_POST['stepback'] ? $_POST['stepback'] : 1;
620 $tmp = sqlQuery("SELECT max(encounter) as max FROM forms where encounter < " .
621 $_SESSION['encounter'] . " and form_name like 'CAMOS%' and pid= " . $_SESSION['pid']);
622 $last_encounter_id = $tmp['max'] ? $tmp['max'] : 0;
623 for ($i=0;$i<$stepback-1;$i++) {
624 $tmp = sqlQuery("SELECT max(encounter) as max FROM forms where encounter < " .
625 $last_encounter_id . " and form_name like 'CAMOS%' and pid= " . $_SESSION['pid']);
626 $last_encounter_id = $tmp['max'] ? $tmp['max'] : 0;
628 $query = "SELECT category, subcategory, item, content FROM form_CAMOS " .
629 "join forms on (form_CAMOS.id = forms.form_id) where " .
630 "forms.encounter = '$last_encounter_id' and form_CAMOS.pid=" .
631 $_SESSION['pid']." order by form_CAMOS.id";
633 $statement = sqlStatement($query);
634 while ($result = sqlFetchArray($statement)) {
635 if (preg_match('/^[\s\r\n]*$/',$result['content']) == 0) {
636 if ($_POST['hidden_mode'] == 'clone last visit') {
637 $clone_category = $result['category'];
639 $clone_subcategory = $result['subcategory'];
640 $clone_item = $result['item'];
641 $clone_content = $result['content'];
642 $clone_data1 = "/* camos :: $clone_category :: $clone_subcategory :: $clone_item :: ";
643 $clone_data2 = "$clone_content */";
644 $clone_data3 = $clone_data1 . $clone_data2;
645 if ($_POST['hidden_mode'] == 'clone last visit') {
646 $clone_data1 = $clone_data3; //make key include whole entry so all 'last visit' data gets recorded and shown
648 if (!$clone_data_array[$clone_data1]) { //if does not exist, don't overwrite.
649 $clone_data_array[$clone_data1] = "";
650 if ($_POST['hidden_mode'] == 'clone') {
651 $clone_data_array[$clone_data1] = "/* ------ ".$result['date']." --------- */\n"; //break between clone items
653 $clone_data_array[$clone_data1] .= $clone_data3;
657 if ($_POST['hidden_mode'] == 'clone last visit') {
658 $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'";
659 $statement = sqlStatement($query);
660 if ($result = sqlFetchArray($statement)) {
661 $weight = $result['weight'];
662 $height = $result['height'];
663 $bps = $result['bps'];
664 $bpd = $result['bpd'];
665 $pulse = $result['pulse'];
666 $temperature = $result['temperature'];
667 // $clone_vitals = "/* vitals_key:: weight :: height :: systolic :: diastolic :: pulse :: temperature */\n";
668 $clone_vitals = "";
669 $clone_vitals .= "/* vitals\n :: $weight\n :: $height\n :: $bps\n :: $bpd\n :: $pulse\n :: $temperature\n */";
670 $clone_data_array[$clone_vitals] = $clone_vitals;
672 $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";
673 $statement = sqlStatement($query);
674 while ($result = sqlFetchArray($statement)) {
675 $clone_code_type = $result['code_type'];
676 $clone_code = $result['code'];
677 $clone_code_text = $result['code_text'];
678 $clone_modifier = $result['modifier'];
679 $clone_units = $result['units'];
680 $clone_fee = $result['fee'];
682 //added ability to grab justifications also - bm
683 $clone_justify = "";
684 $clone_justify_raw = $result['justify'];
685 $clone_justify_array = explode(":",$clone_justify_raw);
686 foreach ($clone_justify_array as $temp_justify) {
687 trim($temp_justify);
688 if ($temp_justify != "") {
689 $clone_justify .= ":: ".$temp_justify." ";
693 $clone_billing_data = "/* billing :: $clone_code_type :: $clone_code :: $clone_code_text :: $clone_modifier :: $clone_units :: $clone_fee $clone_justify*/";
694 $clone_data_array[$clone_billing_data] = $clone_billing_data;
697 } //end else (not clone others)
698 }//end of clone stuff
699 //end preselect column items
702 function init() {
703 var f2 = document.CAMOS;
704 if (clone_mode) {
705 clone_mode = false;
707 for (i1=0;i1<array1.length;i1++) {
708 f2.select_category.options[f2.select_category.length] = new Option(array1[i1][0], array1[i1][1]);
711 $temp_preselect_mode = $preselect_mode;
712 if ($preselect_category_override != '') {
713 $temp_preselect_mode = "by name";
714 $preselect_category = $preselect_category_override;
717 if (select_word("<? echo fixquotes($temp_preselect_mode)."\", \"".fixquotes($preselect_category); ?>" ,f2.select_category)) {
718 click_category();
721 if (substr($_POST['hidden_mode'],0,5) == 'clone') {
722 echo "f2.textarea_content.value = '';\n";
723 // echo "f2.textarea_content.value += '/* count = ".count($clone_data_array)."*/\\n$break\\n';";
724 echo "f2.textarea_content.value += '/* count = ".count($clone_data_array)."*/\\n$break\\n';";
725 foreach($clone_data_array as $key => $val) {
726 echo "f2.textarea_content.value = f2.textarea_content.value + \"".fixquotes(str_replace($quote_search,$quote_replace,$val))."\\n$break\\n\"\n";
733 function click_category() {
734 var f2 = document.CAMOS;
735 var category_index = f2.select_category.selectedIndex;
736 if ((category_index < 0) || (category_index > f2.select_category.length-1)) {return 0;}
737 var sel = f2.select_category.options[f2.select_category.selectedIndex].value;
738 for (var i1=0;i1<array1.length;i1++) {
739 if (array1[i1][1] == sel) {
740 f2.select_subcategory.length = 0;
741 f2["select_item[]"].length = 0;
742 f2.textarea_content.value = '';
743 for (var i2=0;i2<array2.length;i2++) {
744 if (array1[i1][1] == array2[i2][1]) {
745 f2.select_subcategory.options[f2.select_subcategory.length] = new Option(array2[i2][0], array2[i2][2]);
751 $temp_preselect_mode = $preselect_mode;
752 if ($preselect_subcategory_override != '') {
753 $temp_preselect_mode = "by name";
754 $preselect_subcategory = $preselect_subcategory_override;
757 if (select_word("<? echo fixquotes($temp_preselect_mode)."\", \"".fixquotes($preselect_subcategory); ?>" ,f2.select_subcategory)) {
758 click_subcategory();
761 function click_subcategory() {
762 var f2 = document.CAMOS;
763 var subcategory_index = f2.select_subcategory.selectedIndex;
764 if ((subcategory_index < 0) || (subcategory_index > f2.select_subcategory.length-1)) {return 0;}
765 var sel = f2.select_subcategory.options[f2.select_subcategory.selectedIndex].value;
766 for (var i1=0;i1<array2.length;i1++) {
767 if (array2[i1][2] == sel) {
768 f2["select_item[]"].length = 0;
769 f2.textarea_content.value = '';
770 for (var i2=0;i2<array3.length;i2++) {
771 if (array2[i1][2] == array3[i2][2]) {
772 f2["select_item[]"].options[f2["select_item[]"].length] = new Option(array3[i2][0], array3[i2][3]);
778 $temp_preselect_mode = $preselect_mode;
779 if ($preselect_item_override != '') {
780 $temp_preselect_mode = "by name";
781 $preselect_item = $preselect_item_override;
784 if (select_word("<? echo fixquotes($temp_preselect_mode)."\", \"".fixquotes($preselect_item); ?>" ,f2["select_item[]"])) {
785 click_item();
786 preselect_off = true;
789 function click_item() {
790 var f2 = document.CAMOS;
791 var item_index = f2["select_item[]"].selectedIndex;
792 if ((item_index < 0) || (item_index > f2["select_item[]"].length-1)) {return 0;}
793 var sel = f2["select_item[]"].options[item_index].value;
794 for (var i1=0;i1<array3.length;i1++) {
795 if (array3[i1][3] == sel) {
796 //diplay text in content box
797 f2.textarea_content.value= array3[i1][1].replace(/\\/g,'');
802 function selectContains(myselect, str) {
803 for (var i=0;i<myselect.length;i++) {
804 if (myselect.options[i].text == trimString(str)) {return true;}
808 function insert_content(direction) {
809 var f2 = document.CAMOS;
810 var source_box = f2.textarea_content;
811 var target_box = f2.textarea_content02;
812 if (direction == 'up') {
813 source_box = f2.textarea_content02;
814 target_box = f2.textarea_content;
816 var sba = source_box.selectionStart;
817 var sbb = source_box.selectionEnd;
818 var tba = target_box.selectionStart;
819 var tbb = target_box.selectionEnd;
820 if (sbb-sba == 0) {
821 sba = 0;
822 sbb = source_box.value.length;
824 var insert_text = (source_box.value).
825 substring(sba, sbb);
826 target_box.value = (target_box.value).
827 substring(0,tba) + insert_text +
828 (target_box.value).substring(tba,target_box.value.length);
831 //AJAX FUNCTIONS
832 //Function to create an XMLHttp Object.
833 function getxmlhttp (){
834 //Create a boolean variable to check for a valid microsoft active X instance.
835 var xmlhttp = false;
837 //Check if we are using internet explorer.
838 try {
839 //If the javascript version is greater than 5.
840 xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
841 } catch (e) {
842 //If not, then use the older active x object.
843 try {
844 //If we are using internet explorer.
845 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
846 } catch (E) {
847 //Else we must be using a non-internet explorer browser.
848 xmlhttp = false;
852 //If we are using a non-internet explorer browser, create a javascript instance of the object.
853 if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
854 xmlhttp = new XMLHttpRequest();
857 return xmlhttp;
860 //Function to process an XMLHttpRequest.
861 function processajax (serverPage, obj, getOrPost, str){
862 //Get an XMLHttpRequest object for use.
863 xmlhttp = getxmlhttp ();
864 if (getOrPost == "get"){
865 xmlhttp.open("GET", serverPage);
866 xmlhttp.onreadystatechange = function() {
867 if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
868 obj.innerHTML = xmlhttp.responseText;
871 xmlhttp.send(null);
872 } else {
873 xmlhttp.open("POST", serverPage, true);
874 xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
875 xmlhttp.onreadystatechange = function() {
876 if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
877 obj.innerHTML = xmlhttp.responseText;
880 xmlhttp.send(str);
885 function setformvalues(form_array){
887 //Run through a list of all objects
888 var str = '';
889 for(key in form_array) {
890 str += key + "=" + encodeURIComponent(form_array[key]) + "&";
892 //Then return the string values.
893 return str;
896 //END OF AJAX RELATED FUNCTIONS
898 function js_button(mode,selection) {
899 var f2 = document.CAMOS;
900 //check lock next
901 if ( (mode == 'add') && (selection == 'change_content') && (isLocked()) ) {
902 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"); ?>");
903 return;
905 //end check lock
907 //check for blank or duplicate submissions
908 if ( (mode == 'add') || (mode == 'alter') ) {
909 if (selection == 'change_category') {
910 if (trimString(f2.change_category.value) == "") {
911 alert("<?php xl("You cannot add a blank value for a category!","e"); ?>");
912 return;
914 if (selectContains(f2.select_category, trimString(f2.change_category.value))) {
915 alert("<?php xl("There is already a category named","e"); ?>"+" "+f2.change_category.value+".");
916 return;
919 if (selection == 'change_subcategory') {
920 if (trimString(f2.change_subcategory.value) == "") {
921 alert("<?php xl("You cannot add a blank value for a subcategory!","e"); ?>");
922 return;
924 if (selectContains(f2.select_subcategory, trimString(f2.change_subcategory.value))) {
925 alert("<?php xl("There is already a subcategory named","e"); ?>"+" "+f2.change_subcategory.value+".");
926 return;
929 if (selection == 'change_item') {
930 if (trimString(f2.change_item.value) == "") {
931 alert("<?php xl("You cannot add a blank value for an item!","e"); ?>");
932 return;
934 if (selectContains(f2["select_item[]"], trimString(f2.change_item.value))) {
935 alert("<?php xl("There is already an item named","e"); ?>"+" "+f2.change_item.value+".");
936 return;
940 //end of check for blank or duplicate submissions
942 if (mode == 'delete') {
943 if (!confirm("<?php xl("Are you sure you want to delete this item from the database?","e"); ?>")) {
944 return;
947 //check selections and assign variable values
948 var f2 = document.CAMOS;
949 var category_index = f2.select_category.selectedIndex;
950 var category_value;
951 var category_text;
952 if (category_index < 0) {
953 if ((selection == 'change_subcategory') || (selection == 'change_item') ||
954 (selection == 'change_content')) {
955 // alert ('You have not selected a category!');
956 return;
958 category_value = -1;
959 category_text = '';
961 else {
962 category_value = f2.select_category.options[category_index].value;
963 category_text = f2.select_category.options[category_index].text;
965 var subcategory_index = f2.select_subcategory.selectedIndex;
966 var subcategory_value;
967 var subcategory_text;
968 if (subcategory_index < 0) {
969 if ((selection == 'change_item') || (selection == 'change_content')) {
970 // alert ('You have not selected a subcategory!');
971 return;
973 subcategory_value = -1;
974 subcategory_text = '';
976 else {
977 subcategory_value = f2.select_subcategory.options[subcategory_index].value;
978 subcategory_text = f2.select_subcategory.options[subcategory_index].text;
980 var item_index = f2["select_item[]"].selectedIndex;
981 var item_value;
982 var item_text;
983 if (item_index < 0) {
984 if (selection == 'change_content') {
985 // alert ('You have not selected an item!');
986 return;
988 item_value = -1;
989 item_text = '';
991 else {
992 item_value = f2["select_item[]"].options[item_index].value;
993 item_text = f2["select_item[]"].options[item_index].text;
995 f2.category.value = category_text;
996 f2.subcategory.value = subcategory_text;
997 f2.item.value = item_text;
998 //end of setting values relating to selections
1000 //deal with clone buttons or add, alter, delete.
1001 if ( (mode.substr(0,5) == 'clone') || (mode == 'add') || (mode == 'add to') ||
1002 (mode == 'alter') || (mode =='delete') ) {
1003 f2.hidden_mode.value = mode;
1004 f2.hidden_selection.value = selection;
1005 f2.hidden_category.value = category_value;
1006 f2.hidden_subcategory.value = subcategory_value;
1007 f2.hidden_item.value = item_value;
1008 <?php
1009 if (!$out_of_encounter) {
1011 f2.action = '<? print $GLOBALS['webroot'] ?>/interface/patient_file/encounter/load_form.php?formname=CAMOS';
1012 <?php
1013 } else {
1015 f2.action = '<? print $GLOBALS['webroot'] ?>/interface/forms/CAMOS/new.php?mode=external';
1016 <?php
1019 f2.target = '_self';
1020 f2.submit();
1021 return;
1023 //ajax code
1024 var myobj = document.getElementById('id_info');
1025 myarray = new Array();
1026 myarray['category'] = category_text;
1027 myarray['subcategory'] = subcategory_text;
1028 myarray['item'] = item_text;
1029 myarray['content']
1030 if (selection == 'submit_selection') {
1031 myarray['content'] = (f2.textarea_content.value).substring(f2.textarea_content.selectionStart, f2.textarea_content.selectionEnd);
1033 else {myarray['content'] = f2.textarea_content.value;}
1034 var str = setformvalues(myarray);
1035 // alert(str);
1036 processajax ('<? print $GLOBALS['webroot'] ?>/interface/forms/CAMOS/ajax_save.php', myobj, "post", str);
1037 // alert("submitted!");
1038 //ajax code
1041 function selectItem () {
1042 f2 = document.CAMOS;
1043 f2.item.value=f2["select_item[]"].options[f2["select_item[]"].selectedIndex].text;
1044 f2.content.value = f2.textarea_content.value;
1046 function getKey(e) { //process keypresses with getKeyPress
1047 var keynum;
1048 if(window.event) { //IE
1049 keynum = e.keyCode;
1050 } else if(e.which) { // Netscape/Firefox/Opera
1051 keynum = e.which;
1053 return keynum;
1055 function gotoOne(e) {
1056 if (getKey(e) == 96) {
1057 document.CAMOS.clone_others_search.focus();
1060 function processEnter(e,message) {
1061 if (getKey(e) == 13) {
1062 if (message == "clone_others_search") {
1063 js_button('clone others', 'clone others');
1068 </script>
1069 </head>
1070 <body <?echo $top_bg_line;?> topmargin=0 rightmargin=0 leftmargin=2 bottommargin=0 marginwidth=2 marginheight=0 onload="init()">
1071 <div name="form_container" onKeyPress="gotoOne(event)">
1072 <form method=post action="<?echo $rootdir;?>/forms/CAMOS/save.php?mode=new" name="CAMOS">
1073 <?php
1074 if (!$out_of_encounter) {
1075 // echo "<h1>$out_of_encounter</h1>\n";
1077 <input type=button name=clone value='<?php xl('Clone','e'); ?>' onClick="js_button('clone', 'clone')">
1078 <input type=button name=clone_visit value='<?php xl('Clone Past Visit','e'); ?>' onClick="js_button('clone last visit', 'clone last visit')">
1079 <select name=stepback>
1080 <option value=1><?php xl('Back one visit','e'); ?></option>
1081 <option value=2><?php xl('Back two visits','e'); ?></option>
1082 <option value=3><?php xl('Back three visits','e'); ?></option>
1083 <option value=4><?php xl('Back four visits','e'); ?></option>
1084 <option value=5><?php xl('Back five visits','e'); ?></option>
1085 <option value=6><?php xl('Back six visits','e'); ?></option>
1086 <option value=7><?php xl('Back seven visits','e'); ?></option>
1087 <option value=8><?php xl('Back eight visits','e'); ?></option>
1088 <option value=9><?php xl('Back nine visits','e'); ?></option>
1089 <option value=10><?php xl('Back ten visits','e'); ?></option>
1090 <option value=11><?php xl('Back eleven visits','e'); ?></option>
1091 <option value=12><?php xl('Back twelve visits','e'); ?></option>
1092 </select>
1094 echo "<a href='".$GLOBALS['webroot'] . "/interface/patient_file/encounter/$returnurl' onclick='top.restoreSession()'>[".xl('Leave The Form')."]</a>";
1096 <input type=button name='hide columns' value='<?php xl('Hide/Show Columns','e'); ?>' onClick="hide_columns()">
1097 <input type=button name='submit form' value='<?php xl('Submit Selected Content','e'); ?>' onClick="js_button('submit','submit_selection')">
1098 <?php
1099 } //end of if !$out_of_encounter
1101 <div id=id_info style="display:inline">
1102 <!-- supposedly where ajax induced php pages can print their output to... -->
1103 </div>
1104 <div id=id_mainbox style="display:inline">
1106 if ($error != '') {
1107 echo "<h1> error: ".$error."</h1>\n";
1110 <table border=1>
1111 <tr>
1112 <td>
1113 <div id=id_category_column_header style="display:inline">
1114 <?php xl('Category',e)?>
1115 </div> <!-- end of id_category_column_header -->
1116 </td>
1117 <td>
1118 <div id=id_subcategory_column_header style="display:inline">
1119 <?php xl('Subcategory',e)?>
1120 </div> <!-- end of id_subcategory_column_header -->
1121 </td>
1122 <td>
1123 <div id=id_item_column_header style="display:inline">
1124 <?php xl('Item',e)?>
1125 </div> <!-- end of id_item_column_header -->
1126 </td>
1127 <td>
1128 <?php xl('Content',e)?>
1129 </td>
1130 </tr>
1132 <tr>
1133 <td>
1134 <div id=id_category_column style="display:inline">
1135 <select name=select_category size=<? echo $select_size ?> onchange="click_category()"></select><br>
1137 if (myAuth() == 1) {//root user only can see administration option
1139 <input type=text name=change_category><br>
1140 <input type=button name=add1 value='<?php xl('add','e'); ?>' onClick="js_button('add','change_category')">
1141 <input type=button name=alter1 value='<?php xl('alter','e'); ?>' onClick="js_button('alter','change_category')">
1142 <input type=button name=del1 value='<?php xl('del','e'); ?>' onClick="js_button('delete','change_category')"><br>
1146 </div> <!-- end of id_category_column -->
1147 </td>
1148 <td>
1149 <div id=id_subcategory_column style="display:inline">
1150 <select name=select_subcategory size=<? echo $select_size ?> onchange="click_subcategory()"></select><br>
1152 if (myAuth() == 1) {//root user only can see administration option
1154 <input type=text name=change_subcategory><br>
1155 <input type=button name=add2 value='<?php xl('add','e'); ?>' onClick="js_button('add','change_subcategory')">
1156 <input type=button name=alter1 value='<?php xl('alter','e'); ?>' onClick="js_button('alter','change_subcategory')">
1157 <input type=button name=del2 value='<?php xl('del','e'); ?>' onClick="js_button('delete','change_subcategory')"><br>
1161 </div> <!-- end of id_subcategory_column -->
1162 </td>
1163 <td>
1164 <div id=id_item_column style="display:inline">
1165 <select name=select_item[] size=<? echo $select_size ?> onchange="click_item()" multiple="multiple"></select><br>
1167 if (myAuth() == 1) {//root user only can see administration option
1169 <input type=text name=change_item><br>
1170 <input type=button name=add3 value='<?php xl('add','e'); ?>' onClick="js_button('add','change_item')">
1171 <input type=button name=alter1 value='<?php xl('alter','e'); ?>' onClick="js_button('alter','change_item')">
1172 <input type=button name=del3 value='<?php xl('del','e'); ?>' onClick="js_button('delete','change_item')"><br>
1176 </div> <!-- end of id_item_column -->
1177 </td>
1178 <td>
1179 <div id=id_textarea_content style="display:inline">
1180 <textarea name=textarea_content cols=<? echo $textarea_cols ?> rows=<? echo $textarea_rows ?> onFocus="content_focus()" onBlur="content_blur()" onDblClick="specialSelect(this,'/*','*/')" tabindex=2></textarea>
1181 <br/>
1182 <input type=text size=35 name=clone_others_search value='<? echo $_POST['clone_others_search'] ?>' tabindex=1 onKeyPress="processEnter(event,'clone_others_search')"/>
1183 <input type=button name=clone_others_search_button value='<?php xl('Search','e'); ?>' onClick="js_button('clone others', 'clone others')"/>
1184 <input type=button name=clone_others_selected_search_button value='<?php xl('Search Selected','e'); ?>' onClick="js_button('clone others selected', 'clone others selected')"/>
1186 if (myAuth() == 1) {//root user only can see administration option
1188 <div id=id_main_content_buttons style="display:block">
1189 <input type=button name=add4 value='<?php xl('Add','e'); ?>' onClick="js_button('add','change_content')">
1190 <input type=button name=add4 value='<?php xl('Add to','e'); ?>' onClick="js_button('add to','change_content')">
1191 <input type=button name=lock value='<?php xl('Lock','e'); ?>' onClick="lock_content()">
1193 if (!$out_of_encounter) { //do not do stuff that is encounter specific if not in an encounter
1195 <input type=button name=icd9 value='<?php xl('ICD9','e'); ?>' onClick="append_icd9()">
1196 </div> <!-- end of id_main_content_buttons-->
1203 </td>
1204 </td>
1205 </tr>
1206 </table>
1208 <input type=hidden name=hidden_mode>
1209 <input type=hidden name=hidden_selection>
1210 <input type=hidden name=hidden_category>
1211 <input type=hidden name=hidden_subcategory>
1212 <input type=hidden name=hidden_item>
1214 <input type=hidden name=category>
1215 <input type=hidden name=subcategory>
1216 <input type=hidden name=item>
1217 <input type=hidden name=content>
1219 if (!$out_of_encounter) { //do not do stuff that is encounter specific if not in an encounter
1221 <input type=button name='submit form' value='<?php xl('Submit All Content','e'); ?>' onClick="js_button('submit','submit')">
1222 <input type=button name='submit form' value='<?php xl('Submit Selected Content','e'); ?>' onClick="js_button('submit','submit_selection')">
1227 if (!$out_of_encounter) { //do not do stuff that is encounter specific if not in an encounter
1228 echo "<a href='".$GLOBALS['webroot'] . "/interface/patient_file/encounter/$returnurl' onclick='top.restoreSession()'>[".xl('Leave The Form')."]</a>";
1229 echo "<a href='".$GLOBALS['webroot'] . "/interface/forms/CAMOS/help.html' target='new'> | [".xl('Help')."]</a>";
1230 // echo $previous_encounter_data; //probably don't need anymore now that we have clone last visit
1233 </div>
1234 </form>
1235 </div>
1236 <?php
1237 formFooter();
1239 //PHP FUNCTIONS
1241 function fixquotes ($string) {
1242 // this function is needed to treat a string before php echos it in the process of generating javascript.
1243 // 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'.
1244 // $string = preg_replace('/([\\\])*\'/', "\\\'", $string);
1245 $string = preg_replace('/([\\\])*\"/', "\\\"", $string);
1246 return $string;
1249 function searchName($string) { //match one or more names and return clause for query of pids
1250 $string = trim($string);
1251 if ($string == 'this') {
1252 return " and (pid = ".$_SESSION['pid'].") ";
1254 global $limit;
1255 $ret = '';
1256 $data = array();
1257 $fname = '';
1258 $lname = '';
1259 if ($string == '') {return $ret;}
1260 $split = preg_split('/\s+/',$string);
1261 $name1 = $split[1];
1262 $name2 = $split[0];
1263 if ($name1 != '') {$name1 = "%".$name1."%";}
1264 if ($name2 != '') {$name1 = "%".$name2."%";}
1265 $query = sqlStatement("select pid from patient_data where fname like '$name1' or fname like '$name2' or " .
1266 "lname like '$name1' or lname like '$name2' limit $limit");
1267 while ($results = mysql_fetch_array($query, MYSQL_ASSOC)) {
1268 array_push($data,$results['pid']);
1270 if (count($data) > 0) {
1271 $ret = join(" or pid = ",$data);
1272 $ret = " and (pid = ".$ret.") ";
1274 return $ret;
1276 function getMyPatientData($form_id, $show_phone_flag) {//return a string of patient data and encounter data based on the form_CAMOS id
1277 $ret = '';
1278 $name = '';
1279 $dob = '';
1280 $enc_date = '';
1281 $phone_list = '';
1282 $pid = '';
1283 $query = sqlStatement("select t1.pid, t1.fname, t1.mname, t1.lname, " .
1284 "t1.phone_home, t1.phone_biz, t1.phone_contact, t1.phone_cell, " .
1285 "date_format(t1.DOB,'%m-%d-%y') as DOB, date_format(t2.date,'%m-%d-%y') as date, " .
1286 "datediff(current_date(),t2.date) as days " .
1287 "from patient_data as t1 join forms as t2 on (t1.pid = t2.pid) where t2.form_id=$form_id " .
1288 "and form_name like 'CAMOS%'");
1289 if ($results = mysql_fetch_array($query, MYSQL_ASSOC)) {
1290 $pid = $results['pid'];
1291 $fname = $results['fname'];
1292 $mname = $results['mname'];
1293 $lname = $results['lname'];
1294 if ($mname) {$name = $fname.' '.$mname.' '.$lname;}
1295 else {$name = $fname.' '.$lname;}
1296 $dob = $results['DOB'];
1297 $enc_date = $results['date'];
1298 $days_ago = $results['days'];
1299 $phone_list =
1300 "/* Home: ".$results['phone_home']." | ".
1301 "Cell: ".$results['phone_cell']." | ".
1302 "Bus: ".$results['phone_biz']." | ".
1303 "Contact: ".$results['phone_contact']." */";
1305 $ret = "/*$pid, $name, DOB: $dob, Enc: $enc_date, $days_ago days ago. */";
1306 if ($show_phone_flag === true) {
1307 $ret .= "\n".$phone_list;
1309 return $ret;