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 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'];
27 $fname = $GLOBALS['OE_SITE_DIR'] . "/LBF/$form_id.plugin.php";
28 if (file_exists($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.
39 getLayoutProperties($form_id, $grparr);
42 $sets = "title = ?, user = ?, groupname = ?, authorized = ?, date = NOW()";
43 $sqlBindArray = array($form_id, $_SESSION['authUser'], $_SESSION['authProvider'], $userauthorized);
46 array_push($sqlBindArray, $transid);
47 sqlStatement("UPDATE transactions SET $sets WHERE id = ?", $sqlBindArray);
49 array_push($sqlBindArray, $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
65 $query = "DELETE FROM lbt_data WHERE " .
66 "form_id = ? AND field_id = ?";
67 sqlStatement($query, array($transid, $field_id));
69 $query = "REPLACE INTO lbt_data SET field_value = ?, " .
70 "form_id = ?, field_id = ?";
71 sqlStatement($query, array($value, $transid, $field_id));
76 "INSERT INTO lbt_data " .
77 "( form_id, field_id, field_value ) VALUES ( ?, ?, ? )",
78 array($newid, $field_id, $value)
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);
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
108 global $item_count, $cell_count;
109 if ($item_count > 0) {
117 global $cell_count, $CPR;
119 if ($cell_count > 0) {
120 for (; $cell_count < $CPR;
133 if (strlen($last_group) > 0) {
140 // If we are editing a transaction, get its ID and data.
141 $trow = $transid ?
getTransById($transid) : array();
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() {
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");
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
;
201 function divclick(cb
, divid
) {
202 var divstyle
= document
.getElementById(divid
).style
;
204 divstyle
.display
= 'block';
206 divstyle
.display
= 'none';
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
];
220 if (s
.length
> 0) s +
= ';';
221 s +
= codetype +
':' + code
;
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);
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
) {
252 var j
= s
.length
- 1;
253 for (; i
<= j
&& s
.charAt(i
) == ' '; ++i
);
254 for (; i
<= j
&& s
.charAt(j
) == ' '; --j
);
259 // Validation logic for form submission.
260 function validate(f
) {
262 var errMsgs
= new Array();
264 <?php
generate_layout_validation($form_id); ?
>
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 ) {
277 return errMsgs
.length
< 1;
280 function submitme() {
281 var f
= document
.forms
['new_transaction'];
283 top
.restoreSession();
288 <?php
if (function_exists($form_id . '_javascript')) {
289 call_user_func($form_id . '_javascript');
294 <style type
="text/css">
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">
313 <div
class="col-xs-12">
314 <div
class="page-header">
315 <h1
><?php
echo xlt('Add/Edit Patient Transaction');?
></h1
>
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'); ?
>
323 <a href
="transactions.php" class="btn btn-link btn-cancel" onclick
="top.restoreSession()">
324 <?php
echo xlt('Cancel'); ?
>
334 <?php
echo xlt('Transaction Type'); ?
>: 
;</td
><td
>
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) {
346 echo ">" . text($ttrow['grp_title']) . "</option>\n";
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
>
367 <input type
="checkbox" id
="send_sum_flag" name
="send_sum_flag">
370 <span
class="text"><?php
echo xlt('Sent Summary of Care?') ?
></span
><br
>
372 <?php
if (!(empty($itemAMC)) && !(empty($itemAMC_elec))) { ?
>
373  
; 
;<input type
="checkbox" id
="send_sum_elec_flag" name
="send_sum_elec_flag" checked
>
374 <?php
} else if (!(empty($itemAMC))) { ?
>
375  
; 
;<input type
="checkbox" id
="send_sum_elec_flag" name
="send_sum_elec_flag">
377  
; 
;<input type
="checkbox" id
="send_sum_elec_flag" name
="send_sum_elec_flag" disabled
>
380 <span
class="text"><?php
echo xlt('Sent Summary of Care Electronically?') ?
></span
><br
>
389 $fres = sqlStatement("SELECT * FROM layout_options " .
390 "WHERE form_id = ? AND uor > 0 " .
391 "ORDER BY group_id, seq", array($form_id));
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'>";
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>";
415 <div
class="tabContainer">
417 $fres = sqlStatement("SELECT * FROM layout_options " .
418 "WHERE form_id = ? AND uor > 0 " .
419 "ORDER BY group_id, seq", array($form_id));
424 $display_style = 'block';
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']);
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));
451 $currvalue = $tmp['reason'];
456 // Handle a data category (group) change.
457 if (strcmp($this_group, $last_group) != 0) {
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'>";
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) {
479 if ($item_count == 0 && $titlecols == 0) {
483 // Handle starting of a new label cell.
484 if ($titlecols > 0) {
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) . "'";
496 $cell_count +
= $titlecols;
503 // Modified 6-09 by BM - Translate if applicable
504 if ($frow['title']) {
505 echo (text(xl_layout_label($frow['title'])) . ":");
512 // Handle starting of a new data 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'";
524 $cell_count +
= $datacols;
528 generate_form_field($frow, $currvalue);
539 <!-- include support
for the
list-add selectbox feature
-->
540 <?php
include $GLOBALS['fileroot']."/library/options_listadd.inc"; ?
>
544 <script language
="JavaScript">
546 // Array of action conditions for the checkSkipConditions() function.
548 <?php
echo $condition_str; ?
>
551 <?php
echo $date_init; ?
>
554 if (function_exists($form_id . '_javascript_onload')) {
555 call_user_func($form_id . '_javascript_onload');