demographics_dashboard_part_2 (#1903)
[openemr.git] / interface / patient_file / transaction / add_transaction.php
blob8d348664506f22107b02cf01f70a257cfc446dfe
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-2018 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");
19 require_once("$srcdir/patient.inc");
21 use OpenEMR\Core\Header;
23 // This can come from the URL if it's an Add.
24 $title = empty($_REQUEST['title']) ? 'LBTref' : $_REQUEST['title'];
25 $form_id = $title;
27 // Plugin support.
28 $fname = $GLOBALS['OE_SITE_DIR'] . "/LBF/" . convert_safe_file_dir_name($form_id) . ".plugin.php";
29 if (file_exists($fname)) {
30 include_once($fname);
33 $transid = empty($_REQUEST['transid']) ? 0 : $_REQUEST['transid'] + 0;
34 $mode = empty($_POST['mode' ]) ? '' : $_POST['mode' ];
35 // $inmode = $_GET['inmode'];
36 $body_onload_code = "";
38 // Load array of properties for this layout and its groups.
39 $grparr = array();
40 getLayoutProperties($form_id, $grparr);
42 if ($mode) {
43 $sets = "title = ?, user = ?, groupname = ?, authorized = ?, date = NOW()";
44 $sqlBindArray = array($form_id, $_SESSION['authUser'], $_SESSION['authProvider'], $userauthorized);
46 if ($transid) {
47 array_push($sqlBindArray, $transid);
48 sqlStatement("UPDATE transactions SET $sets WHERE id = ?", $sqlBindArray);
49 } else {
50 array_push($sqlBindArray, $pid);
51 $sets .= ", pid = ?";
52 $newid = sqlInsert("INSERT INTO transactions SET $sets", $sqlBindArray);
55 $fres = sqlStatement("SELECT * FROM layout_options " .
56 "WHERE form_id = ? AND uor > 0 AND field_id != '' " .
57 "ORDER BY group_id, seq", array($form_id));
59 while ($frow = sqlFetchArray($fres)) {
60 $data_type = $frow['data_type'];
61 $field_id = $frow['field_id'];
62 $value = get_layout_form_value($frow);
64 if ($transid) { // existing form
65 if ($value === '') {
66 $query = "DELETE FROM lbt_data WHERE " .
67 "form_id = ? AND field_id = ?";
68 sqlStatement($query, array($transid, $field_id));
69 } else {
70 $query = "REPLACE INTO lbt_data SET field_value = ?, " .
71 "form_id = ?, field_id = ?";
72 sqlStatement($query, array($value, $transid, $field_id));
74 } else { // new form
75 if ($value !== '') {
76 sqlStatement(
77 "INSERT INTO lbt_data " .
78 "( form_id, field_id, field_value ) VALUES ( ?, ?, ? )",
79 array($newid, $field_id, $value)
85 if (!$transid) {
86 $transid = $newid;
89 // Set the AMC sent records flag
90 if (!(empty($_POST['send_sum_flag']))) {
91 // add the sent records flag
92 processAmcCall('send_sum_amc', true, 'add', $pid, 'transactions', $transid);
93 if (!(empty($_POST['send_sum_elec_flag']))) {
94 processAmcCall('send_sum_elec_amc', true, 'add', $pid, 'transactions', $transid);
96 } else {
97 // remove the sent records flags
98 processAmcCall('send_sum_amc', true, 'remove', $pid, 'transactions', $transid);
99 processAmcCall('send_sum_elec_amc', true, 'remove', $pid, 'transactions', $transid);
102 $body_onload_code = "javascript:location.href='transactions.php';";
105 $CPR = 4; // cells per row
107 function end_cell()
109 global $item_count, $cell_count;
110 if ($item_count > 0) {
111 echo "</td>";
112 $item_count = 0;
116 function end_row()
118 global $cell_count, $CPR;
119 end_cell();
120 if ($cell_count > 0) {
121 for (; $cell_count < $CPR;
122 ++$cell_count) {
123 echo "<td></td>";
126 echo "</tr>\n";
127 $cell_count = 0;
131 function end_group()
133 global $last_group;
134 if (strlen($last_group) > 0) {
135 end_row();
136 echo " </table>\n";
137 echo "</div>\n";
141 // If we are editing a transaction, get its ID and data.
142 $trow = $transid ? getTransById($transid) : array();
144 <html>
145 <head>
147 <title><?php echo xlt('Add/Edit Patient Transaction'); ?></title>
149 <?php Header::setupHeader(['common','datetime-picker']); ?>
151 <?php include_once("{$GLOBALS['srcdir']}/options.js.php"); ?>
153 <script type="text/javascript">
154 $(document).ready(function() {
155 if(window.tabbify){
156 tabbify();
158 if (window.checkSkipConditions) {
159 checkSkipConditions();
163 var mypcc = '<?php echo htmlspecialchars($GLOBALS['phone_country_code'], ENT_QUOTES); ?>';
165 $(document).ready(function(){
166 $("#send_sum_flag").click(function() {
167 if ( $('#send_sum_flag').prop('checked') ) {
168 // Enable the send_sum_elec_flag checkbox
169 $("#send_sum_elec_flag").removeAttr("disabled");
171 else {
172 //Disable the send_sum_elec_flag checkbox (also uncheck it if applicable)
173 $("#send_sum_elec_flag").attr("disabled", true);
174 $("#send_sum_elec_flag").prop("checked", false);
178 $('.datepicker').datetimepicker({
179 <?php $datetimepicker_timepicker = false; ?>
180 <?php $datetimepicker_showseconds = false; ?>
181 <?php $datetimepicker_formatInput = true; ?>
182 <?php require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?>
183 <?php // can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
185 $('.datetimepicker').datetimepicker({
186 <?php $datetimepicker_timepicker = true; ?>
187 <?php $datetimepicker_showseconds = false; ?>
188 <?php $datetimepicker_formatInput = true; ?>
189 <?php require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?>
190 <?php // can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
194 function titleChanged() {
195 var sel = document.forms[0].title;
196 // Layouts must not interfere with each other. Reload the document in Add mode.
197 top.restoreSession();
198 location.href = 'add_transaction.php?title=' + sel.value;
199 return true;
202 function divclick(cb, divid) {
203 var divstyle = document.getElementById(divid).style;
204 if (cb.checked) {
205 divstyle.display = 'block';
206 } else {
207 divstyle.display = 'none';
209 return true;
212 // The ID of the input element to receive a found code.
213 var current_sel_name = '';
215 // This is for callback by the find-code popup.
216 // Appends to or erases the current list of related codes.
217 function set_related(codetype, code, selector, codedesc) {
218 var frc = document.forms[0][current_sel_name];
219 var s = frc.value;
220 if (code) {
221 if (s.length > 0) s += ';';
222 s += codetype + ':' + code;
223 } else {
224 s = '';
226 frc.value = s;
229 // This invokes the find-code popup.
230 function sel_related(e) {
231 current_sel_name = e.name;
232 dlgopen('../encounter/find_code_popup.php<?php
233 if ($GLOBALS['ippf_specific']) {
234 echo '?codetype=REF';
235 } ?>', '_blank', 500, 400);
238 // Process click on $view link.
239 function deleteme() {
240 // onclick='return deleteme()'
241 dlgopen('../deleter.php?transaction=<?php echo htmlspecialchars($transid, ENT_QUOTES); ?>', '_blank', 500, 450);
242 return false;
245 // Called by the deleteme.php window on a successful delete.
246 function imdeleted() {
247 top.restoreSession();
248 location.href = 'transaction/transactions.php';
251 // Compute the length of a string without leading and trailing spaces.
252 function trimlen(s) {
253 var i = 0;
254 var j = s.length - 1;
255 for (; i <= j && s.charAt(i) == ' '; ++i);
256 for (; i <= j && s.charAt(j) == ' '; --j);
257 if (i > j) return 0;
258 return j + 1 - i;
261 // Validation logic for form submission.
262 function validate(f) {
263 var errCount = 0;
264 var errMsgs = new Array();
266 <?php generate_layout_validation($form_id); ?>
268 var msg = "";
269 msg += "<?php echo xla('The following fields are required'); ?>:\n\n";
270 for ( var i = 0; i < errMsgs.length; i++ ) {
271 msg += errMsgs[i] + "\n";
273 msg += "\n<?php echo xla('Please fill them in before continuing.'); ?>";
275 if ( errMsgs.length > 0 ) {
276 alert(msg);
279 return errMsgs.length < 1;
282 function submitme() {
283 var f = document.forms['new_transaction'];
284 if (validate(f)) {
285 top.restoreSession();
286 f.submit();
290 <?php if (function_exists($form_id . '_javascript')) {
291 call_user_func($form_id . '_javascript');
292 } ?>
294 </script>
296 <style type="text/css">
297 .form-control {
298 width: auto;
299 display: inline;
300 height: auto;
302 div.tab {
303 height: auto;
304 width: auto;
306 </style>
308 </head>
309 <body class="body_top" onload="<?php echo $body_onload_code; ?>" >
310 <div class="container">
311 <form name='new_transaction' method='post' action='add_transaction.php?transid=<?php echo attr($transid); ?>' onsubmit='return validate(this)'>
312 <input type='hidden' name='mode' value='add'>
313 <?php $header_title = xl('Add/Edit Patient Transaction of');?>
314 <div class="row">
315 <div class="col-sm-12">
316 <?php
317 $go_back_href = "transactions.php";
318 require_once("../summary/dashboard_header_simple_return.php");
320 </div>
321 </div>
322 <div class="row">
323 <div class="col-sm-12">
324 <div class="btn-group">
325 <a href="#" class="btn btn-default btn-save" onclick="submitme();">
326 <?php echo xlt('Save'); ?>
327 </a>
328 <a href="transactions.php" class="btn btn-link btn-cancel" onclick="top.restoreSession()">
329 <?php echo xlt('Cancel'); ?>
330 </a>
331 </div>
332 </div>
333 </div>
334 <br>
335 <br>
336 <div class="row">
337 <div class="col-sm-12">
338 <fieldset>
339 <legend><?php echo xlt('Select Transaction Type'); ?></legend>
340 <div class="forms col-sm-8">
341 <label class="control-label" for="title"><?php echo xlt('Transaction Type'); ?>:</label>
342 <?php
343 $ttres = sqlStatement("SELECT grp_form_id, grp_title " .
344 "FROM layout_group_properties WHERE " .
345 "grp_form_id LIKE 'LBT%' AND grp_group_id = '' ORDER BY grp_seq, grp_title");
346 echo "<select name='title' id='title' class='form-control' onchange='titleChanged()'>\n";
347 while ($ttrow = sqlFetchArray($ttres)) {
348 $thisid = $ttrow['grp_form_id'];
349 echo "<option value='" . attr($thisid) . "'";
350 if ($thisid == $form_id) {
351 echo ' selected';
353 echo ">" . text($ttrow['grp_title']) . "</option>\n";
355 echo "</select>\n";
357 </div>
358 <div class="forms col-sm-4">
359 <?php
360 if ($GLOBALS['enable_amc_prompting'] && 'LBTref' == $form_id) { ?>
361 <div class='oe-pull-away' style='margin-right:25px;border-style:solid;border-width:1px;'>
362 <div style='margin:5px 5px 5px 5px;'>
364 <?php // Display the send records checkboxes (AMC prompting)
365 $itemAMC = amcCollect("send_sum_amc", $pid, 'transactions', $transid);
366 $itemAMC_elec = amcCollect("send_sum_elec_amc", $pid, 'transactions', $transid);
369 <?php if (!(empty($itemAMC))) { ?>
370 <input type="checkbox" id="send_sum_flag" name="send_sum_flag" checked>
371 <?php } else { ?>
372 <input type="checkbox" id="send_sum_flag" name="send_sum_flag">
373 <?php } ?>
375 <span class="text"><?php echo xlt('Sent Summary of Care?') ?></span><br>
377 <?php if (!(empty($itemAMC)) && !(empty($itemAMC_elec))) { ?>
378 &nbsp;&nbsp;<input type="checkbox" id="send_sum_elec_flag" name="send_sum_elec_flag" checked>
379 <?php } elseif (!(empty($itemAMC))) { ?>
380 &nbsp;&nbsp;<input type="checkbox" id="send_sum_elec_flag" name="send_sum_elec_flag">
381 <?php } else { ?>
382 &nbsp;&nbsp;<input type="checkbox" id="send_sum_elec_flag" name="send_sum_elec_flag" disabled>
383 <?php } ?>
385 <span class="text"><?php echo xlt('Sent Summary of Care Electronically?') ?></span><br>
387 </div>
388 </div>
389 <?php
390 } ?>
391 </div>
392 </fieldset>
393 </div>
394 </div>
395 <div id='referdiv'>
398 <div id="DEM">
399 <ul class="tabNav">
400 <?php
401 $fres = sqlStatement("SELECT * FROM layout_options " .
402 "WHERE form_id = ? AND uor > 0 " .
403 "ORDER BY group_id, seq", array($form_id));
404 $last_group = '';
406 while ($frow = sqlFetchArray($fres)) {
407 $this_group = $frow['group_id'];
408 // Handle a data category (group) change.
409 if (strcmp($this_group, $last_group) != 0) {
410 $group_seq = substr($this_group, 0, 1);
411 $group_name = $grparr[$this_group]['grp_title'];
412 $last_group = $this_group;
413 if ($group_seq == 1) {
414 echo "<li class='current'>";
415 } else {
416 echo "<li class=''>";
419 $group_seq_esc = attr($group_seq);
420 $group_name_show = text(xl_layout_label($group_name));
421 echo "<a href='#' id='div_$group_seq_esc'>" .
422 "$group_name_show</a></li>";
426 </ul>
427 <div class="tabContainer">
428 <?php
429 $fres = sqlStatement("SELECT * FROM layout_options " .
430 "WHERE form_id = ? AND uor > 0 " .
431 "ORDER BY group_id, seq", array($form_id));
433 $last_group = '';
434 $cell_count = 0;
435 $item_count = 0;
436 $display_style = 'block';
437 $condition_str = '';
439 while ($frow = sqlFetchArray($fres)) {
440 $this_group = $frow['group_id'];
441 $titlecols = $frow['titlecols'];
442 $datacols = $frow['datacols'];
443 $data_type = $frow['data_type'];
444 $field_id = $frow['field_id'];
445 $list_id = $frow['list_id'];
447 // Accumulate action conditions into a JSON expression for the browser side.
448 accumActionConditions($field_id, $condition_str, $frow['conditions']);
450 $currvalue = '';
451 if (isset($trow[$field_id])) {
452 $currvalue = $trow[$field_id];
455 // Handle special-case default values.
456 if (!$currvalue && !$transid && $form_id == 'LBTref') {
457 if ($field_id == 'refer_date') {
458 $currvalue = date('Y-m-d');
459 } elseif ($field_id == 'body' && $transid > 0) {
460 $tmp = sqlQuery("SELECT reason FROM form_encounter WHERE " .
461 "pid = ? ORDER BY date DESC LIMIT 1", array($pid));
462 if (!empty($tmp)) {
463 $currvalue = $tmp['reason'];
468 // Handle a data category (group) change.
469 if (strcmp($this_group, $last_group) != 0) {
470 end_group();
471 $group_seq = substr($this_group, 0, 1);
472 $group_name = $grparr[$this_group]['grp_title'];
473 $last_group = $this_group;
474 $group_seq_esc = attr($group_seq);
475 if ($group_seq == 1) {
476 echo "<div class='tab current' id='div_$group_seq_esc'>";
477 } else {
478 echo "<div class='tab' id='div_$group_seq_esc'>";
481 echo " <table border='0' cellpadding='0'>\n";
482 $display_style = 'none';
485 // Handle starting of a new row.
486 if (($titlecols > 0 && $cell_count >= $CPR) || $cell_count == 0) {
487 end_row();
488 echo " <tr>";
491 if ($item_count == 0 && $titlecols == 0) {
492 $titlecols = 1;
495 // Handle starting of a new label cell.
496 if ($titlecols > 0) {
497 end_cell();
498 $titlecols_esc = attr($titlecols);
499 echo "<td width='70' valign='top' colspan='$titlecols_esc'";
500 echo ($frow['uor'] == 2) ? " class='required'" : " class='bold'";
501 if ($cell_count == 2) {
502 echo " style='padding-left:10pt'";
505 // This ID is used by action conditions.
506 echo " id='label_id_" . attr($field_id) . "'";
507 echo ">";
508 $cell_count += $titlecols;
511 ++$item_count;
513 echo "<b>";
515 // Modified 6-09 by BM - Translate if applicable
516 if ($frow['title']) {
517 echo (text(xl_layout_label($frow['title'])) . ":");
518 } else {
519 echo "&nbsp;";
522 echo "</b>";
524 // Handle starting of a new data cell.
525 if ($datacols > 0) {
526 end_cell();
527 $datacols_esc = attr($datacols);
528 echo "<td valign='top' colspan='$datacols_esc' class='text'";
529 // This ID is used by action conditions.
530 echo " id='value_id_" . attr($field_id) . "'";
531 if ($cell_count > 0) {
532 echo " style='padding-left:5pt'";
535 echo ">";
536 $cell_count += $datacols;
539 ++$item_count;
540 generate_form_field($frow, $currvalue);
541 echo "</div>";
544 end_group();
546 </div><!-- end of tabContainer div -->
547 </div><!-- end of DEM div -->
548 </div><!-- end of referdiv -->
549 </form>
550 <p />
552 <!-- include support for the list-add selectbox feature -->
553 <?php include $GLOBALS['fileroot']."/library/options_listadd.inc"; ?>
554 </div> <!--end of container div-->
555 <?php
556 //home of the help modal ;)
557 //$GLOBALS['enable_help'] = 0; // Please comment out line if you want help modal to function on this page
558 if ($GLOBALS['enable_help'] == 1) {
559 echo "<script>var helpFile = 'add_edit_transactions_dashboard_help.php'</script>";
560 //help_modal.php lives in interface, set path accordingly
561 require "../../help_modal.php";
564 </body>
566 <script language="JavaScript">
568 // Array of action conditions for the checkSkipConditions() function.
569 var skipArray = [
570 <?php echo $condition_str; ?>
573 <?php echo $date_init; ?>
574 // titleChanged();
575 <?php
576 if (function_exists($form_id . '_javascript_onload')) {
577 call_user_func($form_id . '_javascript_onload');
581 </script>
583 </html>