Multiple improvements from IPPF related to layouts. (#1081)
[openemr.git] / interface / patient_file / transaction / add_transaction.php
blob2e3d10c3fc44e8e9771a171bf039a0dbd50df481
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
25 require_once("../../globals.php");
26 require_once("$srcdir/transactions.inc");
27 require_once("$srcdir/options.inc.php");
28 require_once("$srcdir/amc.php");
30 // This can come from the URL if it's an Add.
31 $title = empty($_REQUEST['title']) ? 'LBTref' : $_REQUEST['title'];
32 $form_id = $title;
34 // Plugin support.
35 $fname = $GLOBALS['OE_SITE_DIR'] . "/LBF/$form_id.plugin.php";
36 if (file_exists($fname)) {
37 include_once($fname);
40 $transid = empty($_REQUEST['transid']) ? 0 : $_REQUEST['transid'] + 0;
41 $mode = empty($_POST['mode' ]) ? '' : $_POST['mode' ];
42 // $inmode = $_GET['inmode'];
43 $body_onload_code = "";
45 // Load array of properties for this layout and its groups.
46 $grparr = array();
47 getLayoutProperties($form_id, $grparr);
49 if ($mode) {
50 $sets = "title = ?, user = ?, groupname = ?, authorized = ?, date = NOW()";
51 $sqlBindArray = array($form_id, $_SESSION['authUser'], $_SESSION['authProvider'], $userauthorized);
53 if ($transid) {
54 array_push($sqlBindArray, $transid);
55 sqlStatement("UPDATE transactions SET $sets WHERE id = ?", $sqlBindArray);
56 } else {
57 array_push($sqlBindArray, $pid);
58 $sets .= ", pid = ?";
59 $newid = sqlInsert("INSERT INTO transactions SET $sets", $sqlBindArray);
62 $fres = sqlStatement("SELECT * FROM layout_options " .
63 "WHERE form_id = ? AND uor > 0 AND field_id != '' " .
64 "ORDER BY group_id, seq", array($form_id));
66 while ($frow = sqlFetchArray($fres)) {
67 $data_type = $frow['data_type'];
68 $field_id = $frow['field_id'];
69 $value = get_layout_form_value($frow);
71 if ($transid) { // existing form
72 if ($value === '') {
73 $query = "DELETE FROM lbt_data WHERE " .
74 "form_id = ? AND field_id = ?";
75 sqlStatement($query, array($transid, $field_id));
76 } else {
77 $query = "REPLACE INTO lbt_data SET field_value = ?, " .
78 "form_id = ?, field_id = ?";
79 sqlStatement($query, array($value, $transid, $field_id));
81 } else { // new form
82 if ($value !== '') {
83 sqlStatement(
84 "INSERT INTO lbt_data " .
85 "( form_id, field_id, field_value ) VALUES ( ?, ?, ? )",
86 array($newid, $field_id, $value)
92 if (!$transid) {
93 $transid = $newid;
96 // Set the AMC sent records flag
97 if (!(empty($_POST['send_sum_flag']))) {
98 // add the sent records flag
99 processAmcCall('send_sum_amc', true, 'add', $pid, 'transactions', $transid);
100 if (!(empty($_POST['send_sum_elec_flag']))) {
101 processAmcCall('send_sum_elec_amc', true, 'add', $pid, 'transactions', $transid);
103 } else {
104 // remove the sent records flags
105 processAmcCall('send_sum_amc', true, 'remove', $pid, 'transactions', $transid);
106 processAmcCall('send_sum_elec_amc', true, 'remove', $pid, 'transactions', $transid);
109 $body_onload_code = "javascript:location.href='transactions.php';";
112 $CPR = 4; // cells per row
114 function end_cell()
116 global $item_count, $cell_count;
117 if ($item_count > 0) {
118 echo "</td>";
119 $item_count = 0;
123 function end_row()
125 global $cell_count, $CPR;
126 end_cell();
127 if ($cell_count > 0) {
128 for (; $cell_count < $CPR;
129 ++$cell_count) {
130 echo "<td></td>";
133 echo "</tr>\n";
134 $cell_count = 0;
138 function end_group()
140 global $last_group;
141 if (strlen($last_group) > 0) {
142 end_row();
143 echo " </table>\n";
144 echo "</div>\n";
148 // If we are editing a transaction, get its ID and data.
149 $trow = $transid ? getTransById($transid) : array();
151 <html>
152 <head>
154 <title><?php echo xlt('Add/Edit Patient Transaction'); ?></title>
156 <link rel='stylesheet' href="<?php echo $css_header;?>" type="text/css">
157 <link rel="stylesheet" href="<?php echo $GLOBALS['assets_static_relative'] ?>/bootstrap-3-3-4/dist/css/bootstrap.min.css">
158 <?php if ($_SESSION['language_direction'] == 'rtl') { ?>
159 <link rel="stylesheet" href="<?php echo $GLOBALS['assets_static_relative'] ?>/bootstrap-rtl-3-3-4/dist/css/bootstrap-rtl.min.css">
160 <?php } ?>
161 <link rel="stylesheet" type="text/css" href="../../../library/js/fancybox/jquery.fancybox-1.2.6.css" media="screen" />
162 <link rel="stylesheet" href="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-datetimepicker-2-5-4/build/jquery.datetimepicker.min.css">
164 <script type="text/javascript" src="../../../library/textformat.js?v=<?php echo $v_js_includes; ?>"></script>
165 <script type="text/javascript" src="../../../library/dialog.js?v=<?php echo $v_js_includes; ?>"></script>
166 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-min-1-7-2/index.js"></script>
167 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/common.js?v=<?php echo $v_js_includes; ?>"></script>
168 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/fancybox/jquery.fancybox-1.2.6.js"></script>
169 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-datetimepicker-2-5-4/build/jquery.datetimepicker.full.min.js"></script>
171 <?php include_once("{$GLOBALS['srcdir']}/options.js.php"); ?>
173 <script type="text/javascript">
174 $(document).ready(function() {
175 if (window.enable_modals) {
176 enable_modals();
178 if(window.tabbify){
179 tabbify();
181 if (window.checkSkipConditions) {
182 checkSkipConditions();
186 var mypcc = '<?php echo htmlspecialchars($GLOBALS['phone_country_code'], ENT_QUOTES); ?>';
188 $(document).ready(function(){
189 $("#send_sum_flag").click(function() {
190 if ( $('#send_sum_flag').attr('checked') ) {
191 // Enable the send_sum_elec_flag checkbox
192 $("#send_sum_elec_flag").removeAttr("disabled");
194 else {
195 //Disable the send_sum_elec_flag checkbox (also uncheck it if applicable)
196 $("#send_sum_elec_flag").attr("disabled", true);
197 $("#send_sum_elec_flag").removeAttr("checked");
201 $('.datepicker').datetimepicker({
202 <?php $datetimepicker_timepicker = false; ?>
203 <?php $datetimepicker_showseconds = false; ?>
204 <?php $datetimepicker_formatInput = false; ?>
205 <?php require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?>
206 <?php // can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
208 $('.datetimepicker').datetimepicker({
209 <?php $datetimepicker_timepicker = true; ?>
210 <?php $datetimepicker_showseconds = false; ?>
211 <?php $datetimepicker_formatInput = false; ?>
212 <?php require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?>
213 <?php // can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
217 function titleChanged() {
218 var sel = document.forms[0].title;
219 // Layouts must not interfere with each other. Reload the document in Add mode.
220 top.restoreSession();
221 location.href = 'add_transaction.php?title=' + sel.value;
222 return true;
225 function divclick(cb, divid) {
226 var divstyle = document.getElementById(divid).style;
227 if (cb.checked) {
228 divstyle.display = 'block';
229 } else {
230 divstyle.display = 'none';
232 return true;
235 // The ID of the input element to receive a found code.
236 var current_sel_name = '';
238 // This is for callback by the find-code popup.
239 // Appends to or erases the current list of related codes.
240 function set_related(codetype, code, selector, codedesc) {
241 var frc = document.forms[0][current_sel_name];
242 var s = frc.value;
243 if (code) {
244 if (s.length > 0) s += ';';
245 s += codetype + ':' + code;
246 } else {
247 s = '';
249 frc.value = s;
252 // This invokes the find-code popup.
253 function sel_related(e) {
254 current_sel_name = e.name;
255 dlgopen('../encounter/find_code_popup.php<?php if ($GLOBALS['ippf_specific']) {
256 echo '?codetype=REF';
257 } ?>', '_blank', 500, 400);
260 // Process click on Delete link.
261 function deleteme() {
262 // onclick='return deleteme()'
263 dlgopen('../deleter.php?transaction=<?php echo htmlspecialchars($transid, ENT_QUOTES); ?>', '_blank', 500, 450);
264 return false;
267 // Called by the deleteme.php window on a successful delete.
268 function imdeleted() {
269 top.restoreSession();
270 location.href = 'transaction/transactions.php';
273 // Compute the length of a string without leading and trailing spaces.
274 function trimlen(s) {
275 var i = 0;
276 var j = s.length - 1;
277 for (; i <= j && s.charAt(i) == ' '; ++i);
278 for (; i <= j && s.charAt(j) == ' '; --j);
279 if (i > j) return 0;
280 return j + 1 - i;
283 // Validation logic for form submission.
284 function validate(f) {
285 var errCount = 0;
286 var errMsgs = new Array();
288 <?php generate_layout_validation($form_id); ?>
290 var msg = "";
291 msg += "<?php echo xla('The following fields are required'); ?>:\n\n";
292 for ( var i = 0; i < errMsgs.length; i++ ) {
293 msg += errMsgs[i] + "\n";
295 msg += "\n<?php echo xla('Please fill them in before continuing.'); ?>";
297 if ( errMsgs.length > 0 ) {
298 alert(msg);
301 return errMsgs.length < 1;
304 function submitme() {
305 var f = document.forms['new_transaction'];
306 if (validate(f)) {
307 top.restoreSession();
308 f.submit();
312 <?php if (function_exists($form_id . '_javascript')) {
313 call_user_func($form_id . '_javascript');
314 } ?>
316 </script>
318 <style type="text/css">
319 .form-control {
320 width: auto;
321 display: inline;
322 height: auto;
324 div.tab {
325 height: auto;
326 width: auto;
328 </style>
330 </head>
331 <body class="body_top" onload="<?php echo $body_onload_code; ?>" >
332 <form name='new_transaction' method='post' action='add_transaction.php?transid=<?php echo attr($transid); ?>' onsubmit='return validate(this)'>
333 <input type='hidden' name='mode' value='add'>
335 <div class="container-fluid">
336 <div class="row">
337 <div class="col-xs-12">
338 <div class="page-header">
339 <h1><?php echo xlt('Add/Edit Patient Transaction');?></h1>
340 </div>
341 </div>
342 <div class="col-xs-12">
343 <div class="btn-group">
344 <a href="#" class="btn btn-default btn-save" onclick="submitme();">
345 <?php echo xlt('Save'); ?>
346 </a>
347 <a href="transactions.php" class="btn btn-link btn-cancel" onclick="top.restoreSession()">
348 <?php echo xlt('Cancel'); ?>
349 </a>
350 </div>
351 <hr>
352 </div>
353 </div>
354 </div>
356 <table class="text">
357 <tr><td>
358 <?php echo xlt('Transaction Type'); ?>:&nbsp;</td><td>
359 <?php
360 $ttres = sqlStatement("SELECT grp_form_id, grp_title " .
361 "FROM layout_group_properties WHERE " .
362 "grp_form_id LIKE 'LBT%' AND grp_group_id = '' ORDER BY grp_seq, grp_title");
363 echo "<select name='title' id='title' onchange='titleChanged()'>\n";
364 while ($ttrow = sqlFetchArray($ttres)) {
365 $thisid = $ttrow['grp_form_id'];
366 echo "<option value='" . attr($thisid) . "'";
367 if ($thisid == $form_id) {
368 echo ' selected';
370 echo ">" . text($ttrow['grp_title']) . "</option>\n";
372 echo "</select>\n";
374 </td></tr>
375 </table>
377 <div id='referdiv'>
379 <?php if ($GLOBALS['enable_amc_prompting'] && 'LBTref' == $form_id) { ?>
380 <div style='float:right;margin-right:25px;border-style:solid;border-width:1px;'>
381 <div style='float:left;margin:5px 5px 5px 5px;'>
383 <?php // Display the send records checkboxes (AMC prompting)
384 $itemAMC = amcCollect("send_sum_amc", $pid, 'transactions', $transid);
385 $itemAMC_elec = amcCollect("send_sum_elec_amc", $pid, 'transactions', $transid);
388 <?php if (!(empty($itemAMC))) { ?>
389 <input type="checkbox" id="send_sum_flag" name="send_sum_flag" checked>
390 <?php } else { ?>
391 <input type="checkbox" id="send_sum_flag" name="send_sum_flag">
392 <?php } ?>
394 <span class="text"><?php echo xlt('Sent Summary of Care?') ?></span><br>
396 <?php if (!(empty($itemAMC)) && !(empty($itemAMC_elec))) { ?>
397 &nbsp;&nbsp;<input type="checkbox" id="send_sum_elec_flag" name="send_sum_elec_flag" checked>
398 <?php } else if (!(empty($itemAMC))) { ?>
399 &nbsp;&nbsp;<input type="checkbox" id="send_sum_elec_flag" name="send_sum_elec_flag">
400 <?php } else { ?>
401 &nbsp;&nbsp;<input type="checkbox" id="send_sum_elec_flag" name="send_sum_elec_flag" disabled>
402 <?php } ?>
404 <span class="text"><?php echo xlt('Sent Summary of Care Electronically?') ?></span><br>
406 </div>
407 </div>
408 <?php } ?>
410 <div id="DEM">
411 <ul class="tabNav">
412 <?php
413 $fres = sqlStatement("SELECT * FROM layout_options " .
414 "WHERE form_id = ? AND uor > 0 " .
415 "ORDER BY group_id, seq", array($form_id));
416 $last_group = '';
418 while ($frow = sqlFetchArray($fres)) {
419 $this_group = $frow['group_id'];
420 // Handle a data category (group) change.
421 if (strcmp($this_group, $last_group) != 0) {
422 $group_seq = substr($this_group, 0, 1);
423 $group_name = $grparr[$this_group]['grp_title'];
424 $last_group = $this_group;
425 if ($group_seq == 1) {
426 echo "<li class='current'>";
427 } else {
428 echo "<li class=''>";
431 $group_seq_esc = attr($group_seq);
432 $group_name_show = text(xl_layout_label($group_name));
433 echo "<a href='#' id='div_$group_seq_esc'>" .
434 "$group_name_show</a></li>";
438 </ul>
439 <div class="tabContainer">
440 <?php
441 $fres = sqlStatement("SELECT * FROM layout_options " .
442 "WHERE form_id = ? AND uor > 0 " .
443 "ORDER BY group_id, seq", array($form_id));
445 $last_group = '';
446 $cell_count = 0;
447 $item_count = 0;
448 $display_style = 'block';
449 $condition_str = '';
451 while ($frow = sqlFetchArray($fres)) {
452 $this_group = $frow['group_id'];
453 $titlecols = $frow['titlecols'];
454 $datacols = $frow['datacols'];
455 $data_type = $frow['data_type'];
456 $field_id = $frow['field_id'];
457 $list_id = $frow['list_id'];
459 // Accumulate action conditions into a JSON expression for the browser side.
460 accumActionConditions($field_id, $condition_str, $frow['conditions']);
462 $currvalue = '';
463 if (isset($trow[$field_id])) {
464 $currvalue = $trow[$field_id];
467 // Handle special-case default values.
468 if (!$currvalue && !$transid && $form_id == 'LBTref') {
469 if ($field_id == 'refer_date') {
470 $currvalue = date('Y-m-d');
471 } else if ($field_id == 'body' && $transid > 0) {
472 $tmp = sqlQuery("SELECT reason FROM form_encounter WHERE " .
473 "pid = ? ORDER BY date DESC LIMIT 1", array($pid));
474 if (!empty($tmp)) {
475 $currvalue = $tmp['reason'];
480 // Handle a data category (group) change.
481 if (strcmp($this_group, $last_group) != 0) {
482 end_group();
483 $group_seq = substr($this_group, 0, 1);
484 $group_name = $grparr[$this_group]['grp_title'];
485 $last_group = $this_group;
486 $group_seq_esc = attr($group_seq);
487 if ($group_seq == 1) {
488 echo "<div class='tab current' id='div_$group_seq_esc'>";
489 } else {
490 echo "<div class='tab' id='div_$group_seq_esc'>";
493 echo " <table border='0' cellpadding='0'>\n";
494 $display_style = 'none';
497 // Handle starting of a new row.
498 if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0) {
499 end_row();
500 echo " <tr>";
503 if ($item_count == 0 && $titlecols == 0) {
504 $titlecols = 1;
507 // Handle starting of a new label cell.
508 if ($titlecols > 0) {
509 end_cell();
510 $titlecols_esc = attr($titlecols);
511 echo "<td width='70' valign='top' colspan='$titlecols_esc'";
512 echo ($frow['uor'] == 2) ? " class='required'" : " class='bold'";
513 if ($cell_count == 2) {
514 echo " style='padding-left:10pt'";
517 // This ID is used by action conditions.
518 echo " id='label_id_" . attr($field_id) . "'";
519 echo ">";
520 $cell_count += $titlecols;
523 ++$item_count;
525 echo "<b>";
527 // Modified 6-09 by BM - Translate if applicable
528 if ($frow['title']) {
529 echo (text(xl_layout_label($frow['title'])) . ":");
530 } else {
531 echo "&nbsp;";
534 echo "</b>";
536 // Handle starting of a new data cell.
537 if ($datacols > 0) {
538 end_cell();
539 $datacols_esc = attr($datacols);
540 echo "<td valign='top' colspan='$datacols_esc' class='text'";
541 // This ID is used by action conditions.
542 echo " id='value_id_" . attr($field_id) . "'";
543 if ($cell_count > 0) {
544 echo " style='padding-left:5pt'";
547 echo ">";
548 $cell_count += $datacols;
551 ++$item_count;
552 generate_form_field($frow, $currvalue);
553 echo "</div>";
556 end_group();
558 </div></div>
559 </div>
560 </form>
561 <p />
563 <!-- include support for the list-add selectbox feature -->
564 <?php include $GLOBALS['fileroot']."/library/options_listadd.inc"; ?>
566 </body>
568 <script language="JavaScript">
570 // Array of action conditions for the checkSkipConditions() function.
571 var skipArray = [
572 <?php echo $condition_str; ?>
575 <?php echo $date_init; ?>
576 // titleChanged();
577 <?php
578 if (function_exists($form_id . '_javascript_onload')) {
579 call_user_func($form_id . '_javascript_onload');
583 </script>
585 </html>