3 * add_transaction is a misnomer, as this script will now also edit
4 * existing transactions.
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'];
28 $fname = $GLOBALS['OE_SITE_DIR'] . "/LBF/" . convert_safe_file_dir_name($form_id) . ".plugin.php";
29 if (file_exists($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.
40 getLayoutProperties($form_id, $grparr);
43 $sets = "title = ?, user = ?, groupname = ?, authorized = ?, date = NOW()";
44 $sqlBindArray = array($form_id, $_SESSION['authUser'], $_SESSION['authProvider'], $userauthorized);
47 array_push($sqlBindArray, $transid);
48 sqlStatement("UPDATE transactions SET $sets WHERE id = ?", $sqlBindArray);
50 array_push($sqlBindArray, $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
66 $query = "DELETE FROM lbt_data WHERE " .
67 "form_id = ? AND field_id = ?";
68 sqlStatement($query, array($transid, $field_id));
70 $query = "REPLACE INTO lbt_data SET field_value = ?, " .
71 "form_id = ?, field_id = ?";
72 sqlStatement($query, array($value, $transid, $field_id));
77 "INSERT INTO lbt_data " .
78 "( form_id, field_id, field_value ) VALUES ( ?, ?, ? )",
79 array($newid, $field_id, $value)
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);
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
109 global $item_count, $cell_count;
110 if ($item_count > 0) {
118 global $cell_count, $CPR;
120 if ($cell_count > 0) {
121 for (; $cell_count < $CPR;
134 if (strlen($last_group) > 0) {
141 // If we are editing a transaction, get its ID and data.
142 $trow = $transid ?
getTransById($transid) : array();
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() {
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");
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
;
202 function divclick(cb
, divid
) {
203 var divstyle
= document
.getElementById(divid
).style
;
205 divstyle
.display
= 'block';
207 divstyle
.display
= 'none';
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
];
221 if (s
.length
> 0) s +
= ';';
222 s +
= codetype +
':' + code
;
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);
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
) {
254 var j
= s
.length
- 1;
255 for (; i
<= j
&& s
.charAt(i
) == ' '; ++i
);
256 for (; i
<= j
&& s
.charAt(j
) == ' '; --j
);
261 // Validation logic for form submission.
262 function validate(f
) {
264 var errMsgs
= new Array();
266 <?php
generate_layout_validation($form_id); ?
>
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 ) {
279 return errMsgs
.length
< 1;
282 function submitme() {
283 var f
= document
.forms
['new_transaction'];
285 top
.restoreSession();
290 <?php
if (function_exists($form_id . '_javascript')) {
291 call_user_func($form_id . '_javascript');
296 <style type
="text/css">
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');?
>
315 <div
class="col-sm-12">
317 $go_back_href = "transactions.php";
318 require_once("../summary/dashboard_header_simple_return.php");
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'); ?
>
328 <a href
="transactions.php" class="btn btn-link btn-cancel" onclick
="top.restoreSession()">
329 <?php
echo xlt('Cancel'); ?
>
337 <div
class="col-sm-12">
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
>
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) {
353 echo ">" . text($ttrow['grp_title']) . "</option>\n";
358 <div
class="forms col-sm-4">
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
>
372 <input type
="checkbox" id
="send_sum_flag" name
="send_sum_flag">
375 <span
class="text"><?php
echo xlt('Sent Summary of Care?') ?
></span
><br
>
377 <?php
if (!(empty($itemAMC)) && !(empty($itemAMC_elec))) { ?
>
378  
; 
;<input type
="checkbox" id
="send_sum_elec_flag" name
="send_sum_elec_flag" checked
>
379 <?php
} elseif (!(empty($itemAMC))) { ?
>
380  
; 
;<input type
="checkbox" id
="send_sum_elec_flag" name
="send_sum_elec_flag">
382  
; 
;<input type
="checkbox" id
="send_sum_elec_flag" name
="send_sum_elec_flag" disabled
>
385 <span
class="text"><?php
echo xlt('Sent Summary of Care Electronically?') ?
></span
><br
>
401 $fres = sqlStatement("SELECT * FROM layout_options " .
402 "WHERE form_id = ? AND uor > 0 " .
403 "ORDER BY group_id, seq", array($form_id));
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'>";
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>";
427 <div
class="tabContainer">
429 $fres = sqlStatement("SELECT * FROM layout_options " .
430 "WHERE form_id = ? AND uor > 0 " .
431 "ORDER BY group_id, seq", array($form_id));
436 $display_style = 'block';
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']);
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));
463 $currvalue = $tmp['reason'];
468 // Handle a data category (group) change.
469 if (strcmp($this_group, $last_group) != 0) {
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'>";
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) {
491 if ($item_count == 0 && $titlecols == 0) {
495 // Handle starting of a new label cell.
496 if ($titlecols > 0) {
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) . "'";
508 $cell_count +
= $titlecols;
515 // Modified 6-09 by BM - Translate if applicable
516 if ($frow['title']) {
517 echo (text(xl_layout_label($frow['title'])) . ":");
524 // Handle starting of a new data 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'";
536 $cell_count +
= $datacols;
540 generate_form_field($frow, $currvalue);
546 </div
><!-- end of tabContainer div
-->
547 </div
><!-- end of DEM div
-->
548 </div
><!-- end of referdiv
-->
552 <!-- include support
for the
list-add selectbox feature
-->
553 <?php
include $GLOBALS['fileroot']."/library/options_listadd.inc"; ?
>
554 </div
> <!--end of container div
-->
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";
566 <script language
="JavaScript">
568 // Array of action conditions for the checkSkipConditions() function.
570 <?php
echo $condition_str; ?
>
573 <?php
echo $date_init; ?
>
576 if (function_exists($form_id . '_javascript_onload')) {
577 call_user_func($form_id . '_javascript_onload');