Fix for compendium loader.
[openemr.git] / interface / patient_file / transaction / add_transaction.php
blob46e763e93ed5270e1e140a8b0b093d12bcc8cbf9
1 <?php
2 // This program is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU General Public License
4 // as published by the Free Software Foundation; either version 2
5 // of the License, or (at your option) any later version.
7 // add_transaction is a misnomer, as this script will now also edit
8 // existing transactions.
10 //SANITIZE ALL ESCAPES
11 $sanitize_all_escapes=true;
14 //STOP FAKE REGISTER GLOBALS
15 $fake_register_globals=false;
18 require_once("../../globals.php");
19 require_once("$srcdir/transactions.inc");
20 require_once("$srcdir/options.inc.php");
21 require_once("$srcdir/amc.php");
23 // Referral plugin support.
24 $fname = $GLOBALS['OE_SITE_DIR'] . "/LBF/REF.plugin.php";
25 if (file_exists($fname)) include_once($fname);
27 $transid = empty($_REQUEST['transid']) ? 0 : $_REQUEST['transid'] + 0;
28 $mode = empty($_POST['mode' ]) ? '' : $_POST['mode' ];
29 $title = empty($_POST['title']) ? '' : $_POST['title'];
30 $inmode = $_GET['inmode'];
31 $body_onload_code="";
32 if ($inmode) { /* For edit func */
33 $inedit = sqlStatement("SELECT * FROM transactions " .
34 "WHERE id = ?", array($transid) );
35 while ($inmoderow = sqlFetchArray($inedit)) {
36 $body = $inmoderow['body'];
39 if ($mode) {
40 //use sql placemaker
41 $sets = "title=?, user = ?, groupname = ?, authorized = ?, date = NOW()";
42 $sqlBindArray = array($_POST['title'], $_SESSION['authUser'], $_SESSION['authProvider'], $userauthorized);
44 $fres = sqlStatement("SELECT * FROM layout_options " .
45 "WHERE form_id = 'REF' AND uor > 0 AND field_id != '' " .
46 "ORDER BY group_name, seq");
47 while ($frow = sqlFetchArray($fres)) {
48 $data_type = $frow['data_type'];
49 $field_id = $frow['field_id'];
50 $value = $_POST["form_$field_id"];
51 if ($field_id == 'body' && $title != 'Referral') {
52 $value = $_POST["body"];
54 if ($data_type == 4 && empty($value)) {
55 // empty dates should be null (note need to explicitly escape the column label)
56 $sets .= ", " . add_escape_custom($field_id) . " = NULL";
58 else {
59 // use sql placemaker (note need to explicitly escape the column label)
60 $sets .= ", " . add_escape_custom($field_id) . " = ?";
61 array_push($sqlBindArray, $value);
64 if ($transid) {
65 //use sql placemaker
66 array_push($sqlBindArray,$transid);
67 sqlStatement("UPDATE transactions SET $sets WHERE id = ?", $sqlBindArray);
69 else {
70 //use sql placemaker
71 array_push($sqlBindArray,$pid);
72 $sets .= ", pid = ?";
73 $transid = sqlInsert("INSERT INTO transactions SET $sets", $sqlBindArray);
76 // Set the AMC sent records flag
77 if (!(empty($_POST['send_sum_flag']))) {
78 // add the sent records flag
79 processAmcCall('send_sum_amc', true, 'add', $pid, 'transactions', $transid);
81 else {
82 // remove the sent records flag
83 processAmcCall('send_sum_amc', true, 'remove', $pid, 'transactions', $transid);
86 if ($GLOBALS['concurrent_layout'])
87 $body_onload_code = "javascript:location.href='transactions.php';";
88 else
89 $body_onload_code = "javascript:parent.Transactions.location.href='transactions.php';";
92 /************************************
93 //Migrated this to the list_options engine (transactions list)
94 $trans_types = array(
95 'Referral' => xl('Referral'),
96 'Patient Request' => xl('Patient Request'),
97 'Physician Request' => xl('Physician Request'),
98 'Legal' => xl('Legal'),
99 'Billing' => xl('Billing'),
101 ************************************/
103 $CPR = 4; // cells per row
105 function end_cell() {
106 global $item_count, $cell_count;
107 if ($item_count > 0) {
108 echo "</td>";
109 $item_count = 0;
113 function end_row() {
114 global $cell_count, $CPR;
115 end_cell();
116 if ($cell_count > 0) {
117 for (; $cell_count < $CPR; ++$cell_count) echo "<td></td>";
118 echo "</tr>\n";
119 $cell_count = 0;
123 function end_group() {
124 global $last_group;
125 if (strlen($last_group) > 0) {
126 end_row();
127 echo " </table>\n";
128 echo "</div>\n";
132 // If we are editing a transaction, get its ID and data.
133 $trow = $transid ? getTransById($transid) : array();
135 <html>
136 <head>
137 <?php html_header_show(); ?>
139 <link rel='stylesheet' href="<?php echo $css_header;?>" type="text/css">
140 <link rel="stylesheet" type="text/css" href="../../../library/js/fancybox/jquery.fancybox-1.2.6.css" media="screen" />
142 <style type="text/css">@import url(../../../library/dynarch_calendar.css);</style>
143 <script type="text/javascript" src="../../../library/dynarch_calendar.js"></script>
144 <?php include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?>
145 <script type="text/javascript" src="../../../library/dynarch_calendar_setup.js"></script>
146 <script type="text/javascript" src="../../../library/textformat.js"></script>
147 <script type="text/javascript" src="../../../library/dialog.js"></script>
149 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/jquery.js"></script>
150 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/common.js"></script>
151 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/jquery.1.3.2.js"></script>
152 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/fancybox/jquery.fancybox-1.2.6.js"></script>
153 <script type="text/javascript">
154 $(document).ready(function(){
155 tabbify();
156 enable_modals();
158 </script>
159 <script language="JavaScript">
161 var mypcc = '<?php echo htmlspecialchars( $GLOBALS['phone_country_code'], ENT_QUOTES); ?>';
163 function titleChanged() {
164 var sel = document.forms[0].title;
165 var si = (sel.selectedIndex < 0) ? 0 : sel.selectedIndex;
166 if (sel.options[si].value == 'Referral') {
167 document.getElementById('otherdiv').style.display = 'none';
168 document.getElementById('referdiv').style.display = 'block';
169 } else {
170 document.getElementById('referdiv').style.display = 'none';
171 document.getElementById('otherdiv').style.display = 'block';
173 return true;
176 function divclick(cb, divid) {
177 var divstyle = document.getElementById(divid).style;
178 if (cb.checked) {
179 divstyle.display = 'block';
180 } else {
181 divstyle.display = 'none';
183 return true;
186 // The ID of the input element to receive a found code.
187 var current_sel_name = '';
189 // This is for callback by the find-code popup.
190 // Appends to or erases the current list of related codes.
191 function set_related(codetype, code, selector, codedesc) {
192 var frc = document.forms[0][current_sel_name];
193 var s = frc.value;
194 if (code) {
195 if (s.length > 0) s += ';';
196 s += codetype + ':' + code;
197 } else {
198 s = '';
200 frc.value = s;
203 // This invokes the find-code popup.
204 function sel_related(e) {
205 current_sel_name = e.name;
206 dlgopen('../encounter/find_code_popup.php<?php if ($GLOBALS['ippf_specific']) echo '?codetype=REF' ?>', '_blank', 500, 400);
209 // Process click on Delete link.
210 function deleteme() {
211 // onclick='return deleteme()'
212 dlgopen('../deleter.php?transaction=<?php echo htmlspecialchars( $transid, ENT_QUOTES); ?>', '_blank', 500, 450);
213 return false;
216 // Called by the deleteme.php window on a successful delete.
217 function imdeleted() {
218 top.restoreSession();
219 location.href = 'transaction/transactions.php';
222 // Compute the length of a string without leading and trailing spaces.
223 function trimlen(s) {
224 var i = 0;
225 var j = s.length - 1;
226 for (; i <= j && s.charAt(i) == ' '; ++i);
227 for (; i <= j && s.charAt(j) == ' '; --j);
228 if (i > j) return 0;
229 return j + 1 - i;
232 // Validation logic for form submission.
233 function validate(f) {
234 var errCount = 0;
235 var errMsgs = new Array();
237 var sel = f.title;
238 var si = (sel.selectedIndex < 0) ? 0 : sel.selectedIndex;
239 if (sel.options[si].value == 'Referral') {
240 <?php generate_layout_validation('REF'); ?>
243 var msg = "";
244 msg += "<?php echo htmlspecialchars( xl('The following fields are required'), ENT_QUOTES); ?>:\n\n";
245 for ( var i = 0; i < errMsgs.length; i++ ) {
246 msg += errMsgs[i] + "\n";
248 msg += "\n<?php echo htmlspecialchars( xl('Please fill them in before continuing.'), ENT_QUOTES); ?>";
250 if ( errMsgs.length > 0 ) {
251 alert(msg);
254 return errMsgs.length < 1;
257 function submitme() {
258 var f = document.forms['new_transaction'];
259 if (validate(f)) {
260 top.restoreSession();
261 f.submit();
265 <?php if (function_exists('REF_javascript')) call_user_func('REF_javascript'); ?>
267 </script>
270 <style type="text/css">
271 div.tab {
272 height: auto;
273 width: auto;
275 </style>
277 </head>
278 <body class="body_top" onload="<?php echo $body_onload_code; ?>" >
279 <form name='new_transaction' method='post' action='add_transaction.php?transid=<?php echo htmlspecialchars( $transid, ENT_QUOTES); ?>' onsubmit='return validate(this)'>
280 <input type='hidden' name='mode' value='add'>
282 <table>
283 <tr>
284 <td>
285 <b><?php echo htmlspecialchars( xl('Add/Edit Patient Transaction'), ENT_NOQUOTES); ?></b>&nbsp;</td><td>
286 <a href="javascript:;" <?php if (!$GLOBALS['concurrent_layout']) echo "target='Main'"; ?> class="css_button" onclick="submitme();">
287 <span><?php echo htmlspecialchars( xl('Save'), ENT_NOQUOTES); ?></span>
288 </a>
289 </td>
290 <td>
291 <a href="transactions.php" <?php if (!$GLOBALS['concurrent_layout']) echo "target='Main'"; ?> class="css_button" onclick="top.restoreSession()">
292 <span><?php echo htmlspecialchars( xl('Cancel'), ENT_NOQUOTES); ?></span>
293 </a>
294 </td>
295 </tr>
296 </table>
298 <table class="text">
299 <tr><td>
300 <?php echo htmlspecialchars( xl('Transaction Type'), ENT_NOQUOTES); ?>:&nbsp;</td><td>
301 <?php echo generate_select_list('title','transactions',$_REQUEST['title'],'','','','titleChanged()'); ?>
302 </td></tr>
303 </table>
305 <div id='referdiv'>
307 <?php if ($GLOBALS['enable_amc_prompting']) { ?>
308 <div style='float:right;margin-right:25px;border-style:solid;border-width:1px;'>
309 <div style='float:left;margin:5px 5px 5px 5px;'>
310 <?php // Display the send records checkbox (AMC prompting)
311 $itemAMC = amcCollect("send_sum_amc", $pid, 'transactions', $transid);
313 <?php if (!(empty($itemAMC))) { ?>
314 <input type="checkbox" id="send_sum_flag" name="send_sum_flag" checked>
315 <?php } else { ?>
316 <input type="checkbox" id="send_sum_flag" name="send_sum_flag">
317 <?php } ?>
318 <span class="text"><?php echo xl('Sent Medical Records?') ?></span><br>
319 </div>
320 </div>
321 <?php } ?>
323 <div id="DEM">
324 <ul class="tabNav">
325 <?php
326 $fres = sqlStatement("SELECT * FROM layout_options " .
327 "WHERE form_id = 'REF' AND uor > 0 " .
328 "ORDER BY group_name, seq");
329 $last_group = '';
330 $cell_count = 0;
331 $item_count = 0;
332 $display_style = 'block';
334 while ($frow = sqlFetchArray($fres)) {
335 $this_group = $frow['group_name'];
336 $titlecols = $frow['titlecols'];
337 $datacols = $frow['datacols'];
338 $data_type = $frow['data_type'];
339 $field_id = $frow['field_id'];
340 $list_id = $frow['list_id'];
342 $currvalue = '';
343 if (isset($trow[$field_id])) $currvalue = $trow[$field_id];
345 // Handle special-case default values.
346 if (!$currvalue && !$transid) {
347 if ($field_id == 'refer_date') {
348 $currvalue = date('Y-m-d');
350 else if ($field_id == 'body' ) {
351 $tmp = sqlQuery("SELECT reason FROM form_encounter WHERE " .
352 "pid = ? ORDER BY date DESC LIMIT 1", array($pid) );
353 if (!empty($tmp)) $currvalue = $tmp['reason'];
357 // Handle a data category (group) change.
358 if (strcmp($this_group, $last_group) != 0) {
359 $group_seq = substr($this_group, 0, 1);
360 $group_name = substr($this_group, 1);
361 $last_group = $this_group;
362 if($group_seq==1) echo "<li class='current'>";
363 else echo "<li class=''>";
364 $group_seq_esc = htmlspecialchars( $group_seq, ENT_QUOTES);
365 $group_name_show = htmlspecialchars( xl_layout_label($group_name), ENT_NOQUOTES);
366 echo "<a href='/play/javascript-tabbed-navigation/' id='div_$group_seq_esc'>".
367 "$group_name_show</a></li>";
369 ++$item_count;
372 </ul>
373 <div class="tabContainer">
375 <?php
376 $fres = sqlStatement("SELECT * FROM layout_options " .
377 "WHERE form_id = 'REF' AND uor > 0 " .
378 "ORDER BY group_name, seq");
379 $last_group = '';
380 $cell_count = 0;
381 $item_count = 0;
382 $display_style = 'block';
384 while ($frow = sqlFetchArray($fres)) {
385 $this_group = $frow['group_name'];
386 $titlecols = $frow['titlecols'];
387 $datacols = $frow['datacols'];
388 $data_type = $frow['data_type'];
389 $field_id = $frow['field_id'];
390 $list_id = $frow['list_id'];
392 $currvalue = '';
393 if (isset($trow[$field_id])) $currvalue = $trow[$field_id];
395 // Handle special-case default values.
396 if (!$currvalue && !$transid) {
397 if ($field_id == 'refer_date') {
398 $currvalue = date('Y-m-d');
400 else if ($field_id == 'body' && $transid > 0 ) {
401 $tmp = sqlQuery("SELECT reason FROM form_encounter WHERE " .
402 "pid = ? ORDER BY date DESC LIMIT 1", array($pid) );
403 if (!empty($tmp)) $currvalue = $tmp['reason'];
407 // Handle a data category (group) change.
408 if (strcmp($this_group, $last_group) != 0) {
409 end_group();
410 $group_seq = substr($this_group, 0, 1);
411 $group_name = substr($this_group, 1);
412 $last_group = $this_group;
413 $group_seq_esc = htmlspecialchars( $group_seq, ENT_QUOTES);
414 if($group_seq==1) echo "<div class='tab current' id='div_$group_seq_esc'>";
415 else echo "<div class='tab' id='div_$group_seq_esc'>";
416 echo " <table border='0' cellpadding='0'>\n";
417 $display_style = 'none';
420 // Handle starting of a new row.
421 if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0) {
422 end_row();
423 echo " <tr>";
426 if ($item_count == 0 && $titlecols == 0) $titlecols = 1;
428 // Handle starting of a new label cell.
429 if ($titlecols > 0) {
430 end_cell();
431 $titlecols_esc = htmlspecialchars( $titlecols, ENT_QUOTES);
432 echo "<td width='70' valign='top' colspan='$titlecols_esc'";
433 echo ($frow['uor'] == 2) ? " class='required'" : " class='bold'";
434 if ($cell_count == 2) echo " style='padding-left:10pt'";
435 echo ">";
436 $cell_count += $titlecols;
438 ++$item_count;
440 echo "<b>";
442 // Modified 6-09 by BM - Translate if applicable
443 if ($frow['title']) echo (htmlspecialchars( xl_layout_label($frow['title']), ENT_NOQUOTES) . ":"); else echo "&nbsp;";
445 echo "</b>";
447 // Handle starting of a new data cell.
448 if ($datacols > 0) {
449 end_cell();
450 $datacols_esc = htmlspecialchars( $datacols, ENT_QUOTES);
451 echo "<td valign='top' colspan='$datacols_esc' class='text'";
452 if ($cell_count > 0) echo " style='padding-left:5pt'";
453 echo ">";
454 $cell_count += $datacols;
457 ++$item_count;
458 generate_form_field($frow, $currvalue);
459 echo "</div>";
462 end_group();
465 </div></div>
466 </div>
468 <div id='otherdiv' style='display:none'>
469 <span class='bold'><?php echo htmlspecialchars( xl('Details'), ENT_NOQUOTES); ?>:</span><br>
470 <textarea name='body' rows='6' cols='40' wrap='virtual'><?php echo htmlspecialchars( $body, ENT_NOQUOTES); ?>
471 </textarea>
472 </div>
473 </form>
474 </p>
476 <!-- include support for the list-add selectbox feature -->
477 <?php include $GLOBALS['fileroot']."/library/options_listadd.inc"; ?>
479 </body>
481 <script language="JavaScript">
482 <?php echo $date_init; ?>
483 titleChanged();
484 <?php
485 if (function_exists('REF_javascript_onload')) {
486 call_user_func('REF_javascript_onload');
490 </script>
492 </html>