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>.
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'];
35 $fname = $GLOBALS['OE_SITE_DIR'] . "/LBF/$form_id.plugin.php";
36 if (file_exists($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.
47 getLayoutProperties($form_id, $grparr);
50 $sets = "title = ?, user = ?, groupname = ?, authorized = ?, date = NOW()";
51 $sqlBindArray = array($form_id, $_SESSION['authUser'], $_SESSION['authProvider'], $userauthorized);
54 array_push($sqlBindArray, $transid);
55 sqlStatement("UPDATE transactions SET $sets WHERE id = ?", $sqlBindArray);
57 array_push($sqlBindArray, $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
73 $query = "DELETE FROM lbt_data WHERE " .
74 "form_id = ? AND field_id = ?";
75 sqlStatement($query, array($transid, $field_id));
77 $query = "REPLACE INTO lbt_data SET field_value = ?, " .
78 "form_id = ?, field_id = ?";
79 sqlStatement($query, array($value, $transid, $field_id));
84 "INSERT INTO lbt_data " .
85 "( form_id, field_id, field_value ) VALUES ( ?, ?, ? )",
86 array($newid, $field_id, $value)
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);
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
116 global $item_count, $cell_count;
117 if ($item_count > 0) {
125 global $cell_count, $CPR;
127 if ($cell_count > 0) {
128 for (; $cell_count < $CPR;
141 if (strlen($last_group) > 0) {
148 // If we are editing a transaction, get its ID and data.
149 $trow = $transid ?
getTransById($transid) : array();
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">
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
) {
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");
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
;
225 function divclick(cb
, divid
) {
226 var divstyle
= document
.getElementById(divid
).style
;
228 divstyle
.display
= 'block';
230 divstyle
.display
= 'none';
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
];
244 if (s
.length
> 0) s +
= ';';
245 s +
= codetype +
':' + code
;
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);
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
) {
276 var j
= s
.length
- 1;
277 for (; i
<= j
&& s
.charAt(i
) == ' '; ++i
);
278 for (; i
<= j
&& s
.charAt(j
) == ' '; --j
);
283 // Validation logic for form submission.
284 function validate(f
) {
286 var errMsgs
= new Array();
288 <?php
generate_layout_validation($form_id); ?
>
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 ) {
301 return errMsgs
.length
< 1;
304 function submitme() {
305 var f
= document
.forms
['new_transaction'];
307 top
.restoreSession();
312 <?php
if (function_exists($form_id . '_javascript')) {
313 call_user_func($form_id . '_javascript');
318 <style type
="text/css">
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">
337 <div
class="col-xs-12">
338 <div
class="page-header">
339 <h1
><?php
echo xlt('Add/Edit Patient Transaction');?
></h1
>
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'); ?
>
347 <a href
="transactions.php" class="btn btn-link btn-cancel" onclick
="top.restoreSession()">
348 <?php
echo xlt('Cancel'); ?
>
358 <?php
echo xlt('Transaction Type'); ?
>: 
;</td
><td
>
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) {
370 echo ">" . text($ttrow['grp_title']) . "</option>\n";
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
>
391 <input type
="checkbox" id
="send_sum_flag" name
="send_sum_flag">
394 <span
class="text"><?php
echo xlt('Sent Summary of Care?') ?
></span
><br
>
396 <?php
if (!(empty($itemAMC)) && !(empty($itemAMC_elec))) { ?
>
397  
; 
;<input type
="checkbox" id
="send_sum_elec_flag" name
="send_sum_elec_flag" checked
>
398 <?php
} else if (!(empty($itemAMC))) { ?
>
399  
; 
;<input type
="checkbox" id
="send_sum_elec_flag" name
="send_sum_elec_flag">
401  
; 
;<input type
="checkbox" id
="send_sum_elec_flag" name
="send_sum_elec_flag" disabled
>
404 <span
class="text"><?php
echo xlt('Sent Summary of Care Electronically?') ?
></span
><br
>
413 $fres = sqlStatement("SELECT * FROM layout_options " .
414 "WHERE form_id = ? AND uor > 0 " .
415 "ORDER BY group_id, seq", array($form_id));
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'>";
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>";
439 <div
class="tabContainer">
441 $fres = sqlStatement("SELECT * FROM layout_options " .
442 "WHERE form_id = ? AND uor > 0 " .
443 "ORDER BY group_id, seq", array($form_id));
448 $display_style = 'block';
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']);
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));
475 $currvalue = $tmp['reason'];
480 // Handle a data category (group) change.
481 if (strcmp($this_group, $last_group) != 0) {
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'>";
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) {
503 if ($item_count == 0 && $titlecols == 0) {
507 // Handle starting of a new label cell.
508 if ($titlecols > 0) {
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) . "'";
520 $cell_count +
= $titlecols;
527 // Modified 6-09 by BM - Translate if applicable
528 if ($frow['title']) {
529 echo (text(xl_layout_label($frow['title'])) . ":");
536 // Handle starting of a new data 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'";
548 $cell_count +
= $datacols;
552 generate_form_field($frow, $currvalue);
563 <!-- include support
for the
list-add selectbox feature
-->
564 <?php
include $GLOBALS['fileroot']."/library/options_listadd.inc"; ?
>
568 <script language
="JavaScript">
570 // Array of action conditions for the checkSkipConditions() function.
572 <?php
echo $condition_str; ?
>
575 <?php
echo $date_init; ?
>
578 if (function_exists($form_id . '_javascript_onload')) {
579 call_user_func($form_id . '_javascript_onload');