Highway to PSR2
[openemr.git] / interface / patient_file / transaction / add_transaction.php
blob8672f640505fa64605a5aec0b594a12d0ddc80a0
1 <?php
2 /**
4 * add_transaction is a misnomer, as this script will now also edit
5 * existing transactions.
8 * LICENSE: This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>.
19 * @package OpenEMR
20 * @author Rod Roark <rod@sunsetsystems.com>
21 * @author Brady Miller <brady.g.miller@gmail.com>
22 * @link http://www.open-emr.org
28 require_once("../../globals.php");
29 require_once("$srcdir/transactions.inc");
30 require_once("$srcdir/options.inc.php");
31 require_once("$srcdir/amc.php");
33 // This can come from the URL if it's an Add.
34 $title = empty($_REQUEST['title']) ? 'LBTref' : $_REQUEST['title'];
35 $form_id = $title;
37 // Plugin support.
38 $fname = $GLOBALS['OE_SITE_DIR'] . "/LBF/$form_id.plugin.php";
39 if (file_exists($fname)) {
40 include_once($fname);
43 $transid = empty($_REQUEST['transid']) ? 0 : $_REQUEST['transid'] + 0;
44 $mode = empty($_POST['mode' ]) ? '' : $_POST['mode' ];
45 // $inmode = $_GET['inmode'];
46 $body_onload_code = "";
48 if ($mode) {
49 $sets = "title = ?, user = ?, groupname = ?, authorized = ?, date = NOW()";
50 $sqlBindArray = array($form_id, $_SESSION['authUser'], $_SESSION['authProvider'], $userauthorized);
52 if ($transid) {
53 array_push($sqlBindArray, $transid);
54 sqlStatement("UPDATE transactions SET $sets WHERE id = ?", $sqlBindArray);
55 } else {
56 array_push($sqlBindArray, $pid);
57 $sets .= ", pid = ?";
58 $newid = sqlInsert("INSERT INTO transactions SET $sets", $sqlBindArray);
61 $fres = sqlStatement("SELECT * FROM layout_options " .
62 "WHERE form_id = ? AND uor > 0 AND field_id != '' " .
63 "ORDER BY group_name, seq", array($form_id));
65 while ($frow = sqlFetchArray($fres)) {
66 $data_type = $frow['data_type'];
67 $field_id = $frow['field_id'];
68 $value = get_layout_form_value($frow);
70 if ($transid) { // existing form
71 if ($value === '') {
72 $query = "DELETE FROM lbt_data WHERE " .
73 "form_id = ? AND field_id = ?";
74 sqlStatement($query, array($transid, $field_id));
75 } else {
76 $query = "REPLACE INTO lbt_data SET field_value = ?, " .
77 "form_id = ?, field_id = ?";
78 sqlStatement($query, array($value, $transid, $field_id));
80 } else { // new form
81 if ($value !== '') {
82 sqlStatement(
83 "INSERT INTO lbt_data " .
84 "( form_id, field_id, field_value ) VALUES ( ?, ?, ? )",
85 array($newid, $field_id, $value)
91 if (!$transid) {
92 $transid = $newid;
95 // Set the AMC sent records flag
96 if (!(empty($_POST['send_sum_flag']))) {
97 // add the sent records flag
98 processAmcCall('send_sum_amc', true, 'add', $pid, 'transactions', $transid);
99 if (!(empty($_POST['send_sum_elec_flag']))) {
100 processAmcCall('send_sum_elec_amc', true, 'add', $pid, 'transactions', $transid);
102 } else {
103 // remove the sent records flags
104 processAmcCall('send_sum_amc', true, 'remove', $pid, 'transactions', $transid);
105 processAmcCall('send_sum_elec_amc', true, 'remove', $pid, 'transactions', $transid);
108 $body_onload_code = "javascript:location.href='transactions.php';";
111 $CPR = 4; // cells per row
113 function end_cell()
115 global $item_count, $cell_count;
116 if ($item_count > 0) {
117 echo "</td>";
118 $item_count = 0;
122 function end_row()
124 global $cell_count, $CPR;
125 end_cell();
126 if ($cell_count > 0) {
127 for (; $cell_count < $CPR;
128 ++$cell_count) {
129 echo "<td></td>";
132 echo "</tr>\n";
133 $cell_count = 0;
137 function end_group()
139 global $last_group;
140 if (strlen($last_group) > 0) {
141 end_row();
142 echo " </table>\n";
143 echo "</div>\n";
147 // If we are editing a transaction, get its ID and data.
148 $trow = $transid ? getTransById($transid) : array();
150 <html>
151 <head>
153 <title><?php echo xlt('Add/Edit Patient Transaction'); ?></title>
155 <link rel='stylesheet' href="<?php echo $css_header;?>" type="text/css">
156 <link rel="stylesheet" href="<?php echo $GLOBALS['assets_static_relative'] ?>/bootstrap-3-3-4/dist/css/bootstrap.min.css">
157 <?php if ($_SESSION['language_direction'] == 'rtl') { ?>
158 <link rel="stylesheet" href="<?php echo $GLOBALS['assets_static_relative'] ?>/bootstrap-rtl-3-3-4/dist/css/bootstrap-rtl.min.css">
159 <?php } ?>
160 <link rel="stylesheet" type="text/css" href="../../../library/js/fancybox/jquery.fancybox-1.2.6.css" media="screen" />
161 <link rel="stylesheet" href="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-datetimepicker-2-5-4/build/jquery.datetimepicker.min.css">
163 <script type="text/javascript" src="../../../library/textformat.js?v=<?php echo $v_js_includes; ?>"></script>
164 <script type="text/javascript" src="../../../library/dialog.js?v=<?php echo $v_js_includes; ?>"></script>
165 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-min-1-7-2/index.js"></script>
166 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/common.js?v=<?php echo $v_js_includes; ?>"></script>
167 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/fancybox/jquery.fancybox-1.2.6.js"></script>
168 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-datetimepicker-2-5-4/build/jquery.datetimepicker.full.min.js"></script>
170 <?php include_once("{$GLOBALS['srcdir']}/options.js.php"); ?>
172 <script type="text/javascript">
173 $(document).ready(function() {
174 if (window.enable_modals) {
175 enable_modals();
177 if(window.tabbify){
178 tabbify();
180 if (window.checkSkipConditions) {
181 checkSkipConditions();
185 var mypcc = '<?php echo htmlspecialchars($GLOBALS['phone_country_code'], ENT_QUOTES); ?>';
187 $(document).ready(function(){
188 $("#send_sum_flag").click(function() {
189 if ( $('#send_sum_flag').attr('checked') ) {
190 // Enable the send_sum_elec_flag checkbox
191 $("#send_sum_elec_flag").removeAttr("disabled");
193 else {
194 //Disable the send_sum_elec_flag checkbox (also uncheck it if applicable)
195 $("#send_sum_elec_flag").attr("disabled", true);
196 $("#send_sum_elec_flag").removeAttr("checked");
200 $('.datepicker').datetimepicker({
201 <?php $datetimepicker_timepicker = false; ?>
202 <?php $datetimepicker_showseconds = false; ?>
203 <?php $datetimepicker_formatInput = false; ?>
204 <?php require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?>
205 <?php // can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
207 $('.datetimepicker').datetimepicker({
208 <?php $datetimepicker_timepicker = true; ?>
209 <?php $datetimepicker_showseconds = false; ?>
210 <?php $datetimepicker_formatInput = false; ?>
211 <?php require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?>
212 <?php // can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
216 function titleChanged() {
217 var sel = document.forms[0].title;
218 // Layouts must not interfere with each other. Reload the document in Add mode.
219 top.restoreSession();
220 location.href = 'add_transaction.php?title=' + sel.value;
221 return true;
224 function divclick(cb, divid) {
225 var divstyle = document.getElementById(divid).style;
226 if (cb.checked) {
227 divstyle.display = 'block';
228 } else {
229 divstyle.display = 'none';
231 return true;
234 // The ID of the input element to receive a found code.
235 var current_sel_name = '';
237 // This is for callback by the find-code popup.
238 // Appends to or erases the current list of related codes.
239 function set_related(codetype, code, selector, codedesc) {
240 var frc = document.forms[0][current_sel_name];
241 var s = frc.value;
242 if (code) {
243 if (s.length > 0) s += ';';
244 s += codetype + ':' + code;
245 } else {
246 s = '';
248 frc.value = s;
251 // This invokes the find-code popup.
252 function sel_related(e) {
253 current_sel_name = e.name;
254 dlgopen('../encounter/find_code_popup.php<?php if ($GLOBALS['ippf_specific']) {
255 echo '?codetype=REF';
256 } ?>', '_blank', 500, 400);
259 // Process click on Delete link.
260 function deleteme() {
261 // onclick='return deleteme()'
262 dlgopen('../deleter.php?transaction=<?php echo htmlspecialchars($transid, ENT_QUOTES); ?>', '_blank', 500, 450);
263 return false;
266 // Called by the deleteme.php window on a successful delete.
267 function imdeleted() {
268 top.restoreSession();
269 location.href = 'transaction/transactions.php';
272 // Compute the length of a string without leading and trailing spaces.
273 function trimlen(s) {
274 var i = 0;
275 var j = s.length - 1;
276 for (; i <= j && s.charAt(i) == ' '; ++i);
277 for (; i <= j && s.charAt(j) == ' '; --j);
278 if (i > j) return 0;
279 return j + 1 - i;
282 // Validation logic for form submission.
283 function validate(f) {
284 var errCount = 0;
285 var errMsgs = new Array();
287 <?php generate_layout_validation($form_id); ?>
289 var msg = "";
290 msg += "<?php echo xla('The following fields are required'); ?>:\n\n";
291 for ( var i = 0; i < errMsgs.length; i++ ) {
292 msg += errMsgs[i] + "\n";
294 msg += "\n<?php echo xla('Please fill them in before continuing.'); ?>";
296 if ( errMsgs.length > 0 ) {
297 alert(msg);
300 return errMsgs.length < 1;
303 function submitme() {
304 var f = document.forms['new_transaction'];
305 if (validate(f)) {
306 top.restoreSession();
307 f.submit();
311 <?php if (function_exists($form_id . '_javascript')) {
312 call_user_func($form_id . '_javascript');
313 } ?>
315 </script>
317 <style type="text/css">
318 .form-control {
319 width: auto;
320 display: inline;
321 height: auto;
323 div.tab {
324 height: auto;
325 width: auto;
327 </style>
329 </head>
330 <body class="body_top" onload="<?php echo $body_onload_code; ?>" >
331 <form name='new_transaction' method='post' action='add_transaction.php?transid=<?php echo attr($transid); ?>' onsubmit='return validate(this)'>
332 <input type='hidden' name='mode' value='add'>
334 <div class="container-fluid">
335 <div class="row">
336 <div class="col-xs-12">
337 <div class="page-header">
338 <h1><?php echo xlt('Add/Edit Patient Transaction');?></h1>
339 </div>
340 </div>
341 <div class="col-xs-12">
342 <div class="btn-group">
343 <a href="#" class="btn btn-default btn-save" onclick="submitme();">
344 <?php echo xlt('Save'); ?>
345 </a>
346 <a href="transactions.php" class="btn btn-link btn-cancel" onclick="top.restoreSession()">
347 <?php echo xlt('Cancel'); ?>
348 </a>
349 </div>
350 <hr>
351 </div>
352 </div>
353 </div>
355 <table class="text">
356 <tr><td>
357 <?php echo xlt('Transaction Type'); ?>:&nbsp;</td><td>
358 <?php echo generate_select_list('title', 'transactions', $form_id, '', '', '', 'titleChanged()'); ?>
359 </td></tr>
360 </table>
362 <div id='referdiv'>
364 <?php if ($GLOBALS['enable_amc_prompting'] && 'LBTref' == $form_id) { ?>
365 <div style='float:right;margin-right:25px;border-style:solid;border-width:1px;'>
366 <div style='float:left;margin:5px 5px 5px 5px;'>
368 <?php // Display the send records checkboxes (AMC prompting)
369 $itemAMC = amcCollect("send_sum_amc", $pid, 'transactions', $transid);
370 $itemAMC_elec = amcCollect("send_sum_elec_amc", $pid, 'transactions', $transid);
373 <?php if (!(empty($itemAMC))) { ?>
374 <input type="checkbox" id="send_sum_flag" name="send_sum_flag" checked>
375 <?php } else { ?>
376 <input type="checkbox" id="send_sum_flag" name="send_sum_flag">
377 <?php } ?>
379 <span class="text"><?php echo xlt('Sent Summary of Care?') ?></span><br>
381 <?php if (!(empty($itemAMC)) && !(empty($itemAMC_elec))) { ?>
382 &nbsp;&nbsp;<input type="checkbox" id="send_sum_elec_flag" name="send_sum_elec_flag" checked>
383 <?php } else if (!(empty($itemAMC))) { ?>
384 &nbsp;&nbsp;<input type="checkbox" id="send_sum_elec_flag" name="send_sum_elec_flag">
385 <?php } else { ?>
386 &nbsp;&nbsp;<input type="checkbox" id="send_sum_elec_flag" name="send_sum_elec_flag" disabled>
387 <?php } ?>
389 <span class="text"><?php echo xlt('Sent Summary of Care Electronically?') ?></span><br>
391 </div>
392 </div>
393 <?php } ?>
395 <div id="DEM">
396 <ul class="tabNav">
397 <?php
398 $fres = sqlStatement("SELECT * FROM layout_options " .
399 "WHERE form_id = ? AND uor > 0 " .
400 "ORDER BY group_name, seq", array($form_id));
401 $last_group = '';
403 while ($frow = sqlFetchArray($fres)) {
404 $this_group = $frow['group_name'];
405 // Handle a data category (group) change.
406 if (strcmp($this_group, $last_group) != 0) {
407 $group_seq = substr($this_group, 0, 1);
408 $group_name = substr($this_group, 1);
409 $last_group = $this_group;
410 if ($group_seq == 1) {
411 echo "<li class='current'>";
412 } else {
413 echo "<li class=''>";
416 $group_seq_esc = attr($group_seq);
417 $group_name_show = text(xl_layout_label($group_name));
418 echo "<a href='#' id='div_$group_seq_esc'>" .
419 "$group_name_show</a></li>";
423 </ul>
424 <div class="tabContainer">
426 <?php
427 $fres = sqlStatement("SELECT * FROM layout_options " .
428 "WHERE form_id = ? AND uor > 0 " .
429 "ORDER BY group_name, seq", array($form_id));
431 $last_group = '';
432 $cell_count = 0;
433 $item_count = 0;
434 $display_style = 'block';
435 $condition_str = '';
437 while ($frow = sqlFetchArray($fres)) {
438 $this_group = $frow['group_name'];
439 $titlecols = $frow['titlecols'];
440 $datacols = $frow['datacols'];
441 $data_type = $frow['data_type'];
442 $field_id = $frow['field_id'];
443 $list_id = $frow['list_id'];
445 // Accumulate skip conditions into a JSON expression for the browser side.
446 // Cloned from interface/forms/LBF/new.php.
447 $conditions = empty($frow['conditions']) ? array() : unserialize($frow['conditions']);
448 foreach ($conditions as $condition) {
449 if (empty($condition['id'])) {
450 continue;
453 $andor = empty($condition['andor']) ? '' : $condition['andor'];
454 if ($condition_str) {
455 $condition_str .= ",\n";
458 $condition_str .= "{" .
459 "target:'" . addslashes($field_id) . "', " .
460 "id:'" . addslashes($condition['id']) . "', " .
461 "itemid:'" . addslashes($condition['itemid']) . "', " .
462 "operator:'" . addslashes($condition['operator']) . "', " .
463 "value:'" . addslashes($condition['value']) . "', " .
464 "andor:'" . addslashes($andor) . "'}";
467 $currvalue = '';
468 if (isset($trow[$field_id])) {
469 $currvalue = $trow[$field_id];
472 // Handle special-case default values.
473 if (!$currvalue && !$transid && $form_id == 'LBTref') {
474 if ($field_id == 'refer_date') {
475 $currvalue = date('Y-m-d');
476 } else if ($field_id == 'body' && $transid > 0) {
477 $tmp = sqlQuery("SELECT reason FROM form_encounter WHERE " .
478 "pid = ? ORDER BY date DESC LIMIT 1", array($pid));
479 if (!empty($tmp)) {
480 $currvalue = $tmp['reason'];
485 // Handle a data category (group) change.
486 if (strcmp($this_group, $last_group) != 0) {
487 end_group();
488 $group_seq = substr($this_group, 0, 1);
489 $group_name = substr($this_group, 1);
490 $last_group = $this_group;
491 $group_seq_esc = attr($group_seq);
492 if ($group_seq == 1) {
493 echo "<div class='tab current' id='div_$group_seq_esc'>";
494 } else {
495 echo "<div class='tab' id='div_$group_seq_esc'>";
498 echo " <table border='0' cellpadding='0'>\n";
499 $display_style = 'none';
502 // Handle starting of a new row.
503 if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0) {
504 end_row();
505 echo " <tr>";
508 if ($item_count == 0 && $titlecols == 0) {
509 $titlecols = 1;
512 // Handle starting of a new label cell.
513 if ($titlecols > 0) {
514 end_cell();
515 $titlecols_esc = attr($titlecols);
516 echo "<td width='70' valign='top' colspan='$titlecols_esc'";
517 echo ($frow['uor'] == 2) ? " class='required'" : " class='bold'";
518 if ($cell_count == 2) {
519 echo " style='padding-left:10pt'";
522 // This ID is used by skip conditions.
523 echo " id='label_id_" . attr($field_id) . "'";
524 echo ">";
525 $cell_count += $titlecols;
528 ++$item_count;
530 echo "<b>";
532 // Modified 6-09 by BM - Translate if applicable
533 if ($frow['title']) {
534 echo (text(xl_layout_label($frow['title'])) . ":");
535 } else {
536 echo "&nbsp;";
539 echo "</b>";
541 // Handle starting of a new data cell.
542 if ($datacols > 0) {
543 end_cell();
544 $datacols_esc = attr($datacols);
545 echo "<td valign='top' colspan='$datacols_esc' class='text'";
546 // This ID is used by skip conditions.
547 echo " id='value_id_" . attr($field_id) . "'";
548 if ($cell_count > 0) {
549 echo " style='padding-left:5pt'";
552 echo ">";
553 $cell_count += $datacols;
556 ++$item_count;
557 generate_form_field($frow, $currvalue);
558 echo "</div>";
561 end_group();
564 </div></div>
565 </div>
566 </form>
567 <p />
569 <!-- include support for the list-add selectbox feature -->
570 <?php include $GLOBALS['fileroot']."/library/options_listadd.inc"; ?>
572 </body>
574 <script language="JavaScript">
576 // Array of skip conditions for the checkSkipConditions() function.
577 var skipArray = [
578 <?php echo $condition_str; ?>
581 <?php echo $date_init; ?>
582 // titleChanged();
583 <?php
584 if (function_exists($form_id . '_javascript_onload')) {
585 call_user_func($form_id . '_javascript_onload');
589 </script>
591 </html>