adjustments to prior commit
[openemr.git] / interface / patient_file / transaction / add_transaction.php
blobc6b39b30b558dd1a211231b7a8b3427f92437868
1 <?php
2 /**
3 * add_transaction is a misnomer, as this script will now also edit
4 * existing transactions.
6 * @package OpenEMR
7 * @link http://www.open-emr.org
8 * @author Rod Roark <rod@sunsetsystems.com>
9 * @author Brady Miller <brady.g.miller@gmail.com>
10 * @copyright Copyright (c) 2017 Brady Miller <brady.g.miller@gmail.com>
11 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
15 require_once("../../globals.php");
16 require_once("$srcdir/transactions.inc");
17 require_once("$srcdir/options.inc.php");
18 require_once("$srcdir/amc.php");
20 use OpenEMR\Core\Header;
22 // This can come from the URL if it's an Add.
23 $title = empty($_REQUEST['title']) ? 'LBTref' : $_REQUEST['title'];
24 $form_id = $title;
26 // Plugin support.
27 $fname = $GLOBALS['OE_SITE_DIR'] . "/LBF/$form_id.plugin.php";
28 if (file_exists($fname)) {
29 include_once($fname);
32 $transid = empty($_REQUEST['transid']) ? 0 : $_REQUEST['transid'] + 0;
33 $mode = empty($_POST['mode' ]) ? '' : $_POST['mode' ];
34 // $inmode = $_GET['inmode'];
35 $body_onload_code = "";
37 // Load array of properties for this layout and its groups.
38 $grparr = array();
39 getLayoutProperties($form_id, $grparr);
41 if ($mode) {
42 $sets = "title = ?, user = ?, groupname = ?, authorized = ?, date = NOW()";
43 $sqlBindArray = array($form_id, $_SESSION['authUser'], $_SESSION['authProvider'], $userauthorized);
45 if ($transid) {
46 array_push($sqlBindArray, $transid);
47 sqlStatement("UPDATE transactions SET $sets WHERE id = ?", $sqlBindArray);
48 } else {
49 array_push($sqlBindArray, $pid);
50 $sets .= ", pid = ?";
51 $newid = sqlInsert("INSERT INTO transactions SET $sets", $sqlBindArray);
54 $fres = sqlStatement("SELECT * FROM layout_options " .
55 "WHERE form_id = ? AND uor > 0 AND field_id != '' " .
56 "ORDER BY group_id, seq", array($form_id));
58 while ($frow = sqlFetchArray($fres)) {
59 $data_type = $frow['data_type'];
60 $field_id = $frow['field_id'];
61 $value = get_layout_form_value($frow);
63 if ($transid) { // existing form
64 if ($value === '') {
65 $query = "DELETE FROM lbt_data WHERE " .
66 "form_id = ? AND field_id = ?";
67 sqlStatement($query, array($transid, $field_id));
68 } else {
69 $query = "REPLACE INTO lbt_data SET field_value = ?, " .
70 "form_id = ?, field_id = ?";
71 sqlStatement($query, array($value, $transid, $field_id));
73 } else { // new form
74 if ($value !== '') {
75 sqlStatement(
76 "INSERT INTO lbt_data " .
77 "( form_id, field_id, field_value ) VALUES ( ?, ?, ? )",
78 array($newid, $field_id, $value)
84 if (!$transid) {
85 $transid = $newid;
88 // Set the AMC sent records flag
89 if (!(empty($_POST['send_sum_flag']))) {
90 // add the sent records flag
91 processAmcCall('send_sum_amc', true, 'add', $pid, 'transactions', $transid);
92 if (!(empty($_POST['send_sum_elec_flag']))) {
93 processAmcCall('send_sum_elec_amc', true, 'add', $pid, 'transactions', $transid);
95 } else {
96 // remove the sent records flags
97 processAmcCall('send_sum_amc', true, 'remove', $pid, 'transactions', $transid);
98 processAmcCall('send_sum_elec_amc', true, 'remove', $pid, 'transactions', $transid);
101 $body_onload_code = "javascript:location.href='transactions.php';";
104 $CPR = 4; // cells per row
106 function end_cell()
108 global $item_count, $cell_count;
109 if ($item_count > 0) {
110 echo "</td>";
111 $item_count = 0;
115 function end_row()
117 global $cell_count, $CPR;
118 end_cell();
119 if ($cell_count > 0) {
120 for (; $cell_count < $CPR;
121 ++$cell_count) {
122 echo "<td></td>";
125 echo "</tr>\n";
126 $cell_count = 0;
130 function end_group()
132 global $last_group;
133 if (strlen($last_group) > 0) {
134 end_row();
135 echo " </table>\n";
136 echo "</div>\n";
140 // If we are editing a transaction, get its ID and data.
141 $trow = $transid ? getTransById($transid) : array();
143 <html>
144 <head>
146 <title><?php echo xlt('Add/Edit Patient Transaction'); ?></title>
148 <?php Header::setupHeader(['common','datetime-picker']); ?>
150 <?php include_once("{$GLOBALS['srcdir']}/options.js.php"); ?>
152 <script type="text/javascript">
153 $(document).ready(function() {
154 if(window.tabbify){
155 tabbify();
157 if (window.checkSkipConditions) {
158 checkSkipConditions();
162 var mypcc = '<?php echo htmlspecialchars($GLOBALS['phone_country_code'], ENT_QUOTES); ?>';
164 $(document).ready(function(){
165 $("#send_sum_flag").click(function() {
166 if ( $('#send_sum_flag').prop('checked') ) {
167 // Enable the send_sum_elec_flag checkbox
168 $("#send_sum_elec_flag").removeAttr("disabled");
170 else {
171 //Disable the send_sum_elec_flag checkbox (also uncheck it if applicable)
172 $("#send_sum_elec_flag").attr("disabled", true);
173 $("#send_sum_elec_flag").prop("checked", false);
177 $('.datepicker').datetimepicker({
178 <?php $datetimepicker_timepicker = false; ?>
179 <?php $datetimepicker_showseconds = false; ?>
180 <?php $datetimepicker_formatInput = true; ?>
181 <?php require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?>
182 <?php // can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
184 $('.datetimepicker').datetimepicker({
185 <?php $datetimepicker_timepicker = true; ?>
186 <?php $datetimepicker_showseconds = false; ?>
187 <?php $datetimepicker_formatInput = true; ?>
188 <?php require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?>
189 <?php // can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
193 function titleChanged() {
194 var sel = document.forms[0].title;
195 // Layouts must not interfere with each other. Reload the document in Add mode.
196 top.restoreSession();
197 location.href = 'add_transaction.php?title=' + sel.value;
198 return true;
201 function divclick(cb, divid) {
202 var divstyle = document.getElementById(divid).style;
203 if (cb.checked) {
204 divstyle.display = 'block';
205 } else {
206 divstyle.display = 'none';
208 return true;
211 // The ID of the input element to receive a found code.
212 var current_sel_name = '';
214 // This is for callback by the find-code popup.
215 // Appends to or erases the current list of related codes.
216 function set_related(codetype, code, selector, codedesc) {
217 var frc = document.forms[0][current_sel_name];
218 var s = frc.value;
219 if (code) {
220 if (s.length > 0) s += ';';
221 s += codetype + ':' + code;
222 } else {
223 s = '';
225 frc.value = s;
228 // This invokes the find-code popup.
229 function sel_related(e) {
230 current_sel_name = e.name;
231 dlgopen('../encounter/find_code_popup.php<?php if ($GLOBALS['ippf_specific']) {
232 echo '?codetype=REF';
233 } ?>', '_blank', 500, 400);
236 // Process click on Delete link.
237 function deleteme() {
238 // onclick='return deleteme()'
239 dlgopen('../deleter.php?transaction=<?php echo htmlspecialchars($transid, ENT_QUOTES); ?>', '_blank', 500, 450);
240 return false;
243 // Called by the deleteme.php window on a successful delete.
244 function imdeleted() {
245 top.restoreSession();
246 location.href = 'transaction/transactions.php';
249 // Compute the length of a string without leading and trailing spaces.
250 function trimlen(s) {
251 var i = 0;
252 var j = s.length - 1;
253 for (; i <= j && s.charAt(i) == ' '; ++i);
254 for (; i <= j && s.charAt(j) == ' '; --j);
255 if (i > j) return 0;
256 return j + 1 - i;
259 // Validation logic for form submission.
260 function validate(f) {
261 var errCount = 0;
262 var errMsgs = new Array();
264 <?php generate_layout_validation($form_id); ?>
266 var msg = "";
267 msg += "<?php echo xla('The following fields are required'); ?>:\n\n";
268 for ( var i = 0; i < errMsgs.length; i++ ) {
269 msg += errMsgs[i] + "\n";
271 msg += "\n<?php echo xla('Please fill them in before continuing.'); ?>";
273 if ( errMsgs.length > 0 ) {
274 alert(msg);
277 return errMsgs.length < 1;
280 function submitme() {
281 var f = document.forms['new_transaction'];
282 if (validate(f)) {
283 top.restoreSession();
284 f.submit();
288 <?php if (function_exists($form_id . '_javascript')) {
289 call_user_func($form_id . '_javascript');
290 } ?>
292 </script>
294 <style type="text/css">
295 .form-control {
296 width: auto;
297 display: inline;
298 height: auto;
300 div.tab {
301 height: auto;
302 width: auto;
304 </style>
306 </head>
307 <body class="body_top" onload="<?php echo $body_onload_code; ?>" >
308 <form name='new_transaction' method='post' action='add_transaction.php?transid=<?php echo attr($transid); ?>' onsubmit='return validate(this)'>
309 <input type='hidden' name='mode' value='add'>
311 <div class="container-fluid">
312 <div class="row">
313 <div class="col-xs-12">
314 <div class="page-header">
315 <h1><?php echo xlt('Add/Edit Patient Transaction');?></h1>
316 </div>
317 </div>
318 <div class="col-xs-12">
319 <div class="btn-group">
320 <a href="#" class="btn btn-default btn-save" onclick="submitme();">
321 <?php echo xlt('Save'); ?>
322 </a>
323 <a href="transactions.php" class="btn btn-link btn-cancel" onclick="top.restoreSession()">
324 <?php echo xlt('Cancel'); ?>
325 </a>
326 </div>
327 <hr>
328 </div>
329 </div>
330 </div>
332 <table class="text">
333 <tr><td>
334 <?php echo xlt('Transaction Type'); ?>:&nbsp;</td><td>
335 <?php
336 $ttres = sqlStatement("SELECT grp_form_id, grp_title " .
337 "FROM layout_group_properties WHERE " .
338 "grp_form_id LIKE 'LBT%' AND grp_group_id = '' ORDER BY grp_seq, grp_title");
339 echo "<select name='title' id='title' onchange='titleChanged()'>\n";
340 while ($ttrow = sqlFetchArray($ttres)) {
341 $thisid = $ttrow['grp_form_id'];
342 echo "<option value='" . attr($thisid) . "'";
343 if ($thisid == $form_id) {
344 echo ' selected';
346 echo ">" . text($ttrow['grp_title']) . "</option>\n";
348 echo "</select>\n";
350 </td></tr>
351 </table>
353 <div id='referdiv'>
355 <?php if ($GLOBALS['enable_amc_prompting'] && 'LBTref' == $form_id) { ?>
356 <div style='float:right;margin-right:25px;border-style:solid;border-width:1px;'>
357 <div style='float:left;margin:5px 5px 5px 5px;'>
359 <?php // Display the send records checkboxes (AMC prompting)
360 $itemAMC = amcCollect("send_sum_amc", $pid, 'transactions', $transid);
361 $itemAMC_elec = amcCollect("send_sum_elec_amc", $pid, 'transactions', $transid);
364 <?php if (!(empty($itemAMC))) { ?>
365 <input type="checkbox" id="send_sum_flag" name="send_sum_flag" checked>
366 <?php } else { ?>
367 <input type="checkbox" id="send_sum_flag" name="send_sum_flag">
368 <?php } ?>
370 <span class="text"><?php echo xlt('Sent Summary of Care?') ?></span><br>
372 <?php if (!(empty($itemAMC)) && !(empty($itemAMC_elec))) { ?>
373 &nbsp;&nbsp;<input type="checkbox" id="send_sum_elec_flag" name="send_sum_elec_flag" checked>
374 <?php } else if (!(empty($itemAMC))) { ?>
375 &nbsp;&nbsp;<input type="checkbox" id="send_sum_elec_flag" name="send_sum_elec_flag">
376 <?php } else { ?>
377 &nbsp;&nbsp;<input type="checkbox" id="send_sum_elec_flag" name="send_sum_elec_flag" disabled>
378 <?php } ?>
380 <span class="text"><?php echo xlt('Sent Summary of Care Electronically?') ?></span><br>
382 </div>
383 </div>
384 <?php } ?>
386 <div id="DEM">
387 <ul class="tabNav">
388 <?php
389 $fres = sqlStatement("SELECT * FROM layout_options " .
390 "WHERE form_id = ? AND uor > 0 " .
391 "ORDER BY group_id, seq", array($form_id));
392 $last_group = '';
394 while ($frow = sqlFetchArray($fres)) {
395 $this_group = $frow['group_id'];
396 // Handle a data category (group) change.
397 if (strcmp($this_group, $last_group) != 0) {
398 $group_seq = substr($this_group, 0, 1);
399 $group_name = $grparr[$this_group]['grp_title'];
400 $last_group = $this_group;
401 if ($group_seq == 1) {
402 echo "<li class='current'>";
403 } else {
404 echo "<li class=''>";
407 $group_seq_esc = attr($group_seq);
408 $group_name_show = text(xl_layout_label($group_name));
409 echo "<a href='#' id='div_$group_seq_esc'>" .
410 "$group_name_show</a></li>";
414 </ul>
415 <div class="tabContainer">
416 <?php
417 $fres = sqlStatement("SELECT * FROM layout_options " .
418 "WHERE form_id = ? AND uor > 0 " .
419 "ORDER BY group_id, seq", array($form_id));
421 $last_group = '';
422 $cell_count = 0;
423 $item_count = 0;
424 $display_style = 'block';
425 $condition_str = '';
427 while ($frow = sqlFetchArray($fres)) {
428 $this_group = $frow['group_id'];
429 $titlecols = $frow['titlecols'];
430 $datacols = $frow['datacols'];
431 $data_type = $frow['data_type'];
432 $field_id = $frow['field_id'];
433 $list_id = $frow['list_id'];
435 // Accumulate action conditions into a JSON expression for the browser side.
436 accumActionConditions($field_id, $condition_str, $frow['conditions']);
438 $currvalue = '';
439 if (isset($trow[$field_id])) {
440 $currvalue = $trow[$field_id];
443 // Handle special-case default values.
444 if (!$currvalue && !$transid && $form_id == 'LBTref') {
445 if ($field_id == 'refer_date') {
446 $currvalue = date('Y-m-d');
447 } else if ($field_id == 'body' && $transid > 0) {
448 $tmp = sqlQuery("SELECT reason FROM form_encounter WHERE " .
449 "pid = ? ORDER BY date DESC LIMIT 1", array($pid));
450 if (!empty($tmp)) {
451 $currvalue = $tmp['reason'];
456 // Handle a data category (group) change.
457 if (strcmp($this_group, $last_group) != 0) {
458 end_group();
459 $group_seq = substr($this_group, 0, 1);
460 $group_name = $grparr[$this_group]['grp_title'];
461 $last_group = $this_group;
462 $group_seq_esc = attr($group_seq);
463 if ($group_seq == 1) {
464 echo "<div class='tab current' id='div_$group_seq_esc'>";
465 } else {
466 echo "<div class='tab' id='div_$group_seq_esc'>";
469 echo " <table border='0' cellpadding='0'>\n";
470 $display_style = 'none';
473 // Handle starting of a new row.
474 if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0) {
475 end_row();
476 echo " <tr>";
479 if ($item_count == 0 && $titlecols == 0) {
480 $titlecols = 1;
483 // Handle starting of a new label cell.
484 if ($titlecols > 0) {
485 end_cell();
486 $titlecols_esc = attr($titlecols);
487 echo "<td width='70' valign='top' colspan='$titlecols_esc'";
488 echo ($frow['uor'] == 2) ? " class='required'" : " class='bold'";
489 if ($cell_count == 2) {
490 echo " style='padding-left:10pt'";
493 // This ID is used by action conditions.
494 echo " id='label_id_" . attr($field_id) . "'";
495 echo ">";
496 $cell_count += $titlecols;
499 ++$item_count;
501 echo "<b>";
503 // Modified 6-09 by BM - Translate if applicable
504 if ($frow['title']) {
505 echo (text(xl_layout_label($frow['title'])) . ":");
506 } else {
507 echo "&nbsp;";
510 echo "</b>";
512 // Handle starting of a new data cell.
513 if ($datacols > 0) {
514 end_cell();
515 $datacols_esc = attr($datacols);
516 echo "<td valign='top' colspan='$datacols_esc' class='text'";
517 // This ID is used by action conditions.
518 echo " id='value_id_" . attr($field_id) . "'";
519 if ($cell_count > 0) {
520 echo " style='padding-left:5pt'";
523 echo ">";
524 $cell_count += $datacols;
527 ++$item_count;
528 generate_form_field($frow, $currvalue);
529 echo "</div>";
532 end_group();
534 </div></div>
535 </div>
536 </form>
537 <p />
539 <!-- include support for the list-add selectbox feature -->
540 <?php include $GLOBALS['fileroot']."/library/options_listadd.inc"; ?>
542 </body>
544 <script language="JavaScript">
546 // Array of action conditions for the checkSkipConditions() function.
547 var skipArray = [
548 <?php echo $condition_str; ?>
551 <?php echo $date_init; ?>
552 // titleChanged();
553 <?php
554 if (function_exists($form_id . '_javascript_onload')) {
555 call_user_func($form_id . '_javascript_onload');
559 </script>
561 </html>