2 include_once("../../globals.php");
3 include_once("../../../library/api.inc");
4 include_once("../../../library/sql.inc");
5 formHeader("Form: CAMOS");
15 $previous_encounter_data = '<hr><p>Previous Encounter CAMOS entries</p><hr>';
16 //get data from previous encounter to show at bottom of form for reference
17 $query = "SELECT t1.category, t1.subcategory, t1.item, t1.content FROM form_CAMOS as t1 JOIN forms as t2 on (t1.id = t2.form_id) where t2.encounter=(select max(encounter) from forms where form_name like 'CAMOS%' and encounter < ".$_SESSION['encounter']." and pid=".$_SESSION['pid'].") and t1.pid=".$_SESSION['pid'];
18 $statement = sqlStatement($query);
19 while ($result = sqlFetchArray($statement)) {
20 $previous_encounter_data .= $result['category']." | ".$result['subcategory']." | ".$result['item']."<p><pre>".$result['content']."</pre></p><hr>";
23 //end of get data from previous encounter
24 //variables for preselect section below (after handle database changes):
25 $preselect_category = '';
26 $preselect_subcategory = '';
28 $preselect_category_override = '';
29 $preselect_subcategory_override = '';
30 $preselect_item_override = '';
31 if ($_POST['hidden_category']) {$preselect_category = $_POST['hidden_category'];}
32 if ($_POST['hidden_subcategory']) {$preselect_subcategory = $_POST['hidden_subcategory'];}
33 if ($_POST['hidden_item']) {$preselect_item = $_POST['hidden_item'];}
34 //handle changes to database
35 if ($_POST['hidden_mode'] == 'add') {
36 if ($_POST['hidden_selection'] == 'change_category') {
37 $preselect_category_override = $_POST['change_category'];
38 $query = "INSERT INTO form_CAMOS_category (category) values ('";
39 $query .= $_POST['change_category']."')";
42 else if ($_POST['hidden_selection'] == 'change_subcategory') {
43 $preselect_subcategory_override = $_POST['change_subcategory'];
44 $category_id = $_POST['hidden_category'];
45 if ($category_id >= 0 ) {
46 $query = "INSERT INTO form_CAMOS_subcategory (subcategory, category_id) values ('";
47 $query .= $_POST['change_subcategory']."', '".$category_id."')";
51 else if ($_POST['hidden_selection'] == 'change_item') {
52 $preselect_item_override = $_POST['change_item'];
53 $category_id = $_POST['hidden_category'];
54 $subcategory_id = $_POST['hidden_subcategory'];
55 if (($category_id >= 0 ) && ($subcategory_id >=0)) {
56 $query = "INSERT INTO form_CAMOS_item (item, content, subcategory_id) values ('";
57 $query .= $_POST['change_item']."', '".$_POST['textarea_content']."', '".$subcategory_id."')";
62 else if ($_POST['hidden_selection'] == 'change_content') {
63 $item_id = $_POST['hidden_item'];
64 $content = $_POST['textarea_content'];
66 $query = "UPDATE form_CAMOS_item set content = '".$content."' where id = ".$item_id;
71 else if ($_POST['hidden_mode'] == 'delete') {
72 if ($_POST['hidden_selection'] == 'change_category') {
73 $to_delete_id = $_POST['hidden_category'];
74 $to_delete_from_table = 'form_CAMOS_category';
75 $to_delete_from_subtable = 'form_CAMOS_subcategory';
76 $tablename = 'category';
77 $subtablename = 'subcategory';
79 else if ($_POST['hidden_selection'] == 'change_subcategory') {
80 $to_delete_id = $_POST['hidden_subcategory'];
81 $to_delete_from_table = 'form_CAMOS_subcategory';
82 $to_delete_from_subtable = 'form_CAMOS_item';
83 $tablename = 'subcategory';
84 $subtablename = 'item';
86 else if ($_POST['hidden_selection'] == 'change_item') {
87 $to_delete_id = $_POST['hidden_item'];
88 $to_delete_from_table = 'form_CAMOS_item';
89 $to_delete_from_subtable = '';
94 if ($subtablename == '') {
95 $query = "DELETE FROM ".$to_delete_from_table." WHERE id like '".$to_delete_id."'";
99 $query = "SELECT count(id) FROM ".$to_delete_from_subtable." WHERE ".$tablename."_id like '".$to_delete_id."'";
100 $statement = sqlStatement($query);
101 if ($result = sqlFetchArray($statement)) {
102 if ($result['count(id)'] == 0) {
103 $query = "DELETE FROM ".$to_delete_from_table." WHERE id like '".$to_delete_id."'";
107 $error = $subtablename." not empty!";
112 else if ($_POST['hidden_mode'] == 'alter') {
113 $newval = $_POST[$_POST['hidden_selection']];
114 if ($_POST['hidden_selection'] == 'change_category') {
115 $to_alter_id = $_POST['hidden_category'];
116 $to_alter_table = 'form_CAMOS_category';
117 $to_alter_column = 'category';
119 else if ($_POST['hidden_selection'] == 'change_subcategory') {
120 $to_alter_id = $_POST['hidden_subcategory'];
121 $to_alter_table = 'form_CAMOS_subcategory';
122 $to_alter_column = 'subcategory';
124 else if ($_POST['hidden_selection'] == 'change_item') {
125 $to_alter_id = $_POST['hidden_item'];
126 $to_alter_table = 'form_CAMOS_item';
127 $to_alter_column = 'item';
129 $query = "UPDATE ".$to_alter_table." set ".$to_alter_column." = '".$newval."' where id = ".$to_alter_id;
132 // end handle changes to database
134 //preselect column items
135 //either a database change has been made, so the user should be made to feel that they never left the same CAMOS screen
136 //or, CAMOS has been started freshly, therefore the last entry of the current patient should be selected.
137 $preselect_mode = '';
138 if ($preselect_category == '') {
139 $preselect_mode = 'by name';
140 //at this point, if this variable has not been set, CAMOS must have been start over
141 //so let's get the most recent values from form_CAMOS for this patient's pid
142 $query = "SELECT category, subcategory, item FROM form_CAMOS WHERE id =(SELECT max(id) from form_CAMOS WHERE pid=".$_SESSION['pid'].")";
143 $statement = sqlStatement($query);
144 if ($result = sqlFetchArray($statement)) {
145 $preselect_category = $result['category'];
146 $preselect_subcategory = $result['subcategory'];
147 $preselect_item = $result['item'];
149 else {$preselect_mode = '';}
152 $preselect_mode = 'by number';
155 //end preselect column items
159 <link rel
=stylesheet href
="<?echo $css_header;?>" type
="text/css">
161 <script language
="javascript" type
="text/javascript">
163 var array1
= new Array();
164 var array2
= new Array();
165 var array3
= new Array();
167 var preselect_off
= false;
168 var content_change_flag
= false;
169 var lock_override_flag
= false;
171 //deal with locking of content = prevent accidental overwrite
173 function trimString (str
) {
174 str
= this
!= window? this
: str
;
175 return str
.replace(/^\s+
/g
, '').replace(/\s+$
/g
, '');
177 function isLocked() {
179 if (lock_override_flag
) {
180 lock_override_flag
= false;
183 return /\
/\
*\s
*lock\s
*\
:\
:\s
*\
*\
//.test(f2.textarea_content.value);
185 function lock_content() {
187 if ((trimString(f2
.textarea_content
.value
) != "") && (!isLocked())) {
188 f2
.textarea_content
.value
= f2
.textarea_content
.value +
"\n\n" +
"/*lock::*/";
189 lock_override_flag
= true;
190 js_button('add','change_content');
193 function allSelected() {
194 var f2
= document
.CAMOS
;
195 if ( (f2
.select_category
.selectedIndex
< 0) ||
(f2
.select_subcategory
.selectedIndex
< 0) ||
(f2
.select_item
.selectedIndex
< 0) ) {
196 return false; //one of the columns is not selected
199 return true; //all columns have a selection
203 function content_focus() {
204 if (content_change_flag
== false) {
205 if (!allSelected()) {
206 alert("If you add text to the 'content' box without a selection in each column (category, subcategory, item), you will likely lose your work.")
210 content_change_flag
= true;
212 function content_blur() {
213 if (content_change_flag
== true) {
214 content_change_flag
= false;
220 $query = "SELECT code_text, code FROM billing WHERE encounter=".$_SESSION['encounter'].
221 " AND pid=".$_SESSION['pid']." AND code_type like 'ICD9'";
222 $statement = sqlStatement($query);
223 if ($result = sqlFetchArray($statement)) {
225 echo "icd9_list = \"\\n\\n\\\n";
226 echo $result['code']." ".$result['code_text']."\\n\\\n";
228 while ($result = sqlFetchArray($statement)) {
229 echo $result['code']." ".$result['code_text']."\\n\\\n";
231 if ($icd9_flag) {echo "\";\n";}
233 $query = "SELECT id, category FROM form_CAMOS_category ORDER BY category";
234 $statement = sqlStatement($query);
236 while ($result = sqlFetchArray($statement)) {
237 echo "array1[".$i."] = new Array('".$result['category']."','".$result['id']."', new Array());\n";
241 $query = "SELECT id, subcategory, category_id FROM form_CAMOS_subcategory ORDER BY subcategory";
242 $statement = sqlStatement($query);
243 while ($result = sqlFetchArray($statement)) {
244 echo "array2[".$i."] = new Array('".$result['subcategory']."', '".$result['category_id']."', '".$result['id']."', new Array());\n";
248 $query = "SELECT id, item, content, subcategory_id FROM form_CAMOS_item ORDER BY item";
249 $statement = sqlStatement($query);
250 while ($result = sqlFetchArray($statement)) {
251 echo "array3[".$i."] = new Array('".$result['item']."', '".str_replace(array("\r","\n","'","\""),array("\\r","\\n","\\'","\\\""),strip_tags($result['content'],"<b>,<i>"))."', '".$result['subcategory_id'].
252 "','".$result['id']."');\n";
257 function append_icd9() {
258 var f2
= document
.CAMOS
;
259 f2
.textarea_content
.value
= f2
.textarea_content
.value + icd9_list
;
262 function select_word(mode
, mystring
, myselect
) { //take a string and select it in a select box if present
263 if (preselect_off
) return 0;
264 for (var i
=0;i
<myselect
.length
;i++
) {
266 if (mode
== 'by name') {
267 match
= myselect
.options
[i
].text
;
269 else if (mode
== 'by number') {
270 match
= myselect
.options
[i
].value
;
273 if (match
== mystring
) {
274 myselect
.selectedIndex
= i
;
281 var f2
= document
.CAMOS
;
282 for (i1
=0;i1
<array1
.length
;i1++
) {
283 f2
.select_category
.options
[f2
.select_category
.length
] = new Option(array1
[i1
][0], array1
[i1
][1]);
286 $temp_preselect_mode = $preselect_mode;
287 if ($preselect_category_override != '') {
288 $temp_preselect_mode = "by name";
289 $preselect_category = $preselect_category_override;
292 if (select_word('<? echo $temp_preselect_mode."', '".$preselect_category; ?>' ,f2
.select_category
)) {
297 function click_category() {
298 var f2
= document
.CAMOS
;
299 var category_index
= f2
.select_category
.selectedIndex
;
300 if ((category_index
< 0) ||
(category_index
> f2
.select_category
.length
-1)) {return 0;}
301 var sel
= f2
.select_category
.options
[f2
.select_category
.selectedIndex
].value
;
302 for (var i1
=0;i1
<array1
.length
;i1++
) {
303 if (array1
[i1
][1] == sel
) {
304 f2
.select_subcategory
.length
= 0;
305 f2
.select_item
.length
= 0;
306 f2
.textarea_content
.value
= '';
307 for (var i2
=0;i2
<array2
.length
;i2++
) {
308 if (array1
[i1
][1] == array2
[i2
][1]) {
309 f2
.select_subcategory
.options
[f2
.select_subcategory
.length
] = new Option(array2
[i2
][0], array2
[i2
][2]);
315 $temp_preselect_mode = $preselect_mode;
316 if ($preselect_subcategory_override != '') {
317 $temp_preselect_mode = "by name";
318 $preselect_subcategory = $preselect_subcategory_override;
321 if (select_word('<? echo $temp_preselect_mode."', '".$preselect_subcategory; ?>' ,f2
.select_subcategory
)) {
325 function click_subcategory() {
326 var f2
= document
.CAMOS
;
327 var subcategory_index
= f2
.select_subcategory
.selectedIndex
;
328 if ((subcategory_index
< 0) ||
(subcategory_index
> f2
.select_subcategory
.length
-1)) {return 0;}
329 var sel
= f2
.select_subcategory
.options
[f2
.select_subcategory
.selectedIndex
].value
;
330 for (var i1
=0;i1
<array2
.length
;i1++
) {
331 if (array2
[i1
][2] == sel
) {
332 f2
.select_item
.length
= 0;
333 f2
.textarea_content
.value
= '';
334 for (var i2
=0;i2
<array3
.length
;i2++
) {
335 if (array2
[i1
][2] == array3
[i2
][2]) {
336 f2
.select_item
.options
[f2
.select_item
.length
] = new Option(array3
[i2
][0], array3
[i2
][3]);
342 $temp_preselect_mode = $preselect_mode;
343 if ($preselect_item_override != '') {
344 $temp_preselect_mode = "by name";
345 $preselect_item = $preselect_item_override;
348 if (select_word('<? echo $temp_preselect_mode."', '".$preselect_item; ?>' ,f2
.select_item
)) {
350 preselect_off
= true;
353 function click_item() {
354 var f2
= document
.CAMOS
;
355 var item_index
= f2
.select_item
.selectedIndex
;
356 if ((item_index
< 0) ||
(item_index
> f2
.select_item
.length
-1)) {return 0;}
357 var sel
= f2
.select_item
.options
[item_index
].value
;
358 for (var i1
=0;i1
<array3
.length
;i1++
) {
359 if (array3
[i1
][3] == sel
) {
360 f2
.textarea_content
.value
= array3
[i1
][1];
365 function selectContains(myselect
, str
) {
366 for (var i
=0;i
<myselect
.length
;i++
) {
367 if (myselect
.options
[i
].text
== trimString(str
)) {return true;}
371 function js_button(mode
,selection
) {
372 var f2
= document
.CAMOS
;
374 if ( (mode
== 'add') && (selection
== 'change_content') && (isLocked()) ) {
375 alert("You have attempted to alter content which is locked.\nRemove the lock if you want to do this.\nTo unlock, remove the line, '/*lock::*/'");
380 //check for blank or duplicate submissions
381 if ( (mode
== 'add') ||
(mode
== 'alter') ) {
382 if (selection
== 'change_category') {
383 if (trimString(f2
.change_category
.value
) == "") {
384 alert("You cannot add a blank value for a category!");
387 if (selectContains(f2
.select_category
, trimString(f2
.change_category
.value
))) {
388 alert("There is already a category named "+f2
.change_category
.value+
".");
392 if (selection
== 'change_subcategory') {
393 if (trimString(f2
.change_subcategory
.value
) == "") {
394 alert("You cannot add a blank value for a subcategory!");
397 if (selectContains(f2
.select_subcategory
, trimString(f2
.change_subcategory
.value
))) {
398 alert("There is already a subcategory named "+f2
.change_subcategory
.value+
".");
402 if (selection
== 'change_item') {
403 if (trimString(f2
.change_item
.value
) == "") {
404 alert("You cannot add a blank value for an item!");
407 if (selectContains(f2
.select_item
, trimString(f2
.change_item
.value
))) {
408 alert("There is already an item named "+f2
.change_item
.value+
".");
413 //end of check for blank or duplicate submissions
415 if (mode
== 'delete') {
416 if (!confirm("Are you sure you want to delete this item from the database?")) {
420 var f2
= document
.CAMOS
;
421 var category_index
= f2
.select_category
.selectedIndex
;
423 if (category_index
< 0) {
424 if ((selection
== 'change_subcategory') ||
(selection
== 'change_item') ||
425 (selection
== 'change_content')) {
426 alert ('You have not selected a category!');
432 category
= f2
.select_category
.options
[category_index
].value
;
434 var subcategory_index
= f2
.select_subcategory
.selectedIndex
;
436 if (subcategory_index
< 0) {
437 if ((selection
== 'change_item') ||
(selection
== 'change_content')) {
438 alert ('You have not selected a subcategory!');
444 subcategory
= f2
.select_subcategory
.options
[subcategory_index
].value
;
446 var item_index
= f2
.select_item
.selectedIndex
;
448 if (item_index
< 0) {
449 if (selection
== 'change_content') {
450 alert ('You have not selected an item!');
456 item
= f2
.select_item
.options
[item_index
].value
;
458 if (mode
== 'submit') {
459 f2
.category
.value
= f2
.select_category
.options
[f2
.select_category
.selectedIndex
].text
;
460 f2
.subcategory
.value
= f2
.select_subcategory
.options
[f2
.select_subcategory
.selectedIndex
].text
;
461 f2
.item
.value
= f2
.select_item
.options
[f2
.select_item
.selectedIndex
].text
;
462 if (selection
== 'submit_selection') {
463 f2
.content
.value
= (f2
.textarea_content
.value
).substring(f2
.textarea_content
.selectionStart
, f2
.textarea_content
.selectionEnd
);
465 else {f2
.content
.value
= f2
.textarea_content
.value
;}
466 f2
.action
= '<?echo $rootdir;?>/forms/CAMOS/save.php?mode=new';
470 f2
.hidden_mode
.value
= mode
;
471 f2
.hidden_selection
.value
= selection
;
472 f2
.hidden_category
.value
= category
;
473 f2
.hidden_subcategory
.value
= subcategory
;
474 f2
.hidden_item
.value
= item
;
475 f2
.action
= '<? print $GLOBALS['webroot
'] ?>/interface/patient_file/encounter/load_form.php?formname=CAMOS';
481 function selectItem () {
483 f2
.item
.value
=f2
.select_item
.options
[f2
.select_item
.selectedIndex
].text
;
484 f2
.content
.value
= f2
.textarea_content
.value
;
489 <body
<?
echo $top_bg_line;?
> topmargin
=0 rightmargin
=0 leftmargin
=2 bottommargin
=0 marginwidth
=2 marginheight
=0 onload
="init()">
490 <form method
=post action
="<?echo $rootdir;?>/forms/CAMOS/save.php?mode=new" name
="CAMOS">
494 echo "<h1> error: ".$error."</h1>\n";
515 <select name
=select_category size
=<?
echo $select_size ?
> onchange
="click_category()"></select
><br
>
516 <input type
=text name
=change_category
><br
>
517 <input type
=button name
=add1 value
=add onClick
="js_button('add','change_category')">
518 <input type
=button name
=alter1 value
=alter onClick
="js_button('alter','change_category')">
519 <input type
=button name
=del1 value
=del onClick
="js_button('delete','change_category')"><br
>
522 <select name
=select_subcategory size
=<?
echo $select_size ?
> onchange
="click_subcategory()"></select
><br
>
523 <input type
=text name
=change_subcategory
><br
>
524 <input type
=button name
=add2 value
=add onClick
="js_button('add','change_subcategory')">
525 <input type
=button name
=alter1 value
=alter onClick
="js_button('alter','change_subcategory')">
526 <input type
=button name
=del2 value
=del onClick
="js_button('delete','change_subcategory')"><br
>
529 <select name
=select_item size
=<?
echo $select_size ?
> onchange
="click_item()"></select
><br
>
530 <input type
=text name
=change_item
><br
>
531 <input type
=button name
=add3 value
=add onClick
="js_button('add','change_item')">
532 <input type
=button name
=alter1 value
=alter onClick
="js_button('alter','change_item')">
533 <input type
=button name
=del3 value
=del onClick
="js_button('delete','change_item')"><br
>
536 <textarea name
=textarea_content cols
=<?
echo $textarea_cols ?
> rows
=<?
echo $textarea_rows ?
> onFocus
="content_focus()" onBlur
="content_blur()"></textarea
><br
>
537 <input type
=button name
=add4 value
=add onClick
="js_button('add','change_content')">
538 <input type
=button name
=icd9 value
=icd9 onClick
="append_icd9()">
539 <input type
=button name
=lock value
=lock onClick
="lock_content()">
544 <input type
=hidden name
=hidden_mode
>
545 <input type
=hidden name
=hidden_selection
>
546 <input type
=hidden name
=hidden_category
>
547 <input type
=hidden name
=hidden_subcategory
>
548 <input type
=hidden name
=hidden_item
>
550 <input type
=hidden name
=category
>
551 <input type
=hidden name
=subcategory
>
552 <input type
=hidden name
=item
>
553 <input type
=hidden name
=content
>
554 <input type
=button name
='submit form' value
='submit all content' onClick
="js_button('submit','submit')">
555 <input type
=button name
='submit form' value
='submit selected content' onClick
="js_button('submit','submit_selection')">
557 echo "<a href='".$GLOBALS['webroot'] . "/interface/patient_file/encounter/patient_encounter.php'>[do not save]</a>";
558 echo "<a href='".$GLOBALS['webroot'] . "/interface/forms/CAMOS/help.html' target='new'> | [help]</a>";
559 echo $previous_encounter_data;