minor changes to prior commit
[openemr.git] / interface / patient_file / summary / add_edit_amendments.php
blob03ac4250032d4352ffffd2011601fa3465c5be85
1 <?php
2 /**
3 * Add/Edit Amendments
5 * Copyright (C) 2014 Ensoftek
6 * Copyright (C) 2017 Brady Miller <brady.g.miller@gmail.com>
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 3
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>;.
19 * @package OpenEMR
20 * @author Hema Bandaru <hemab@drcloudemr.com>
21 * @author Brady Miller <brady.g.miller@gmail.com>
22 * @link http://www.open-emr.org
27 include_once("../../globals.php");
28 include_once("$srcdir/options.inc.php");
30 if (isset($_POST['mode'])) {
31 $currentUser = $_SESSION['authUserID'];
32 $created_time = date('Y-m-d H:i');
33 if ($_POST["amendment_id"] == "") {
34 // New. Insert
35 $query = "INSERT INTO amendments SET
36 amendment_date = ?,
37 amendment_by = ?,
38 amendment_status = ?,
39 pid = ?,
40 amendment_desc = ?,
41 created_by = ?,
42 created_time = ?";
43 $sqlBindArray = array(
44 DateToYYYYMMDD($_POST['amendment_date']),
45 $_POST['form_amendment_by'],
46 $_POST['form_amendment_status'],
47 $pid,
48 $_POST['desc'],
49 $currentUser,
50 $created_time
53 $amendment_id = sqlInsert($query, $sqlBindArray);
54 } else {
55 $amendment_id = $_POST['amendment_id'];
56 // Existing. Update
57 $query = "UPDATE amendments SET
58 amendment_date = ?,
59 amendment_by = ?,
60 amendment_status = ?,
61 amendment_desc = ?,
62 modified_by = ?,
63 modified_time = ?
64 WHERE amendment_id = ?";
65 $sqlBindArray = array(
66 DateToYYYYMMDD($_POST['amendment_date']),
67 $_POST['form_amendment_by'],
68 $_POST['form_amendment_status'],
69 $_POST['desc'],
70 $currentUser,
71 $created_time,
72 $_POST['amendment_id']
74 sqlStatement($query, $sqlBindArray);
77 // Insert into amendments_history
78 $query = "INSERT INTO amendments_history SET
79 amendment_id = ? ,
80 amendment_note = ?,
81 amendment_status = ?,
82 created_by = ?,
83 created_time = ?";
84 $sqlBindArray = array(
85 $amendment_id,
86 $_POST['note'],
87 $_POST["form_amendment_status"],
88 $currentUser,
89 $created_time
91 sqlStatement($query, $sqlBindArray);
92 header("Location:add_edit_amendments.php?id=$amendment_id");
93 exit;
96 $amendment_id = ( $amendment_id ) ? $amendment_id : $_REQUEST['id'];
97 if ($amendment_id) {
98 $query = "SELECT * FROM amendments WHERE amendment_id = ? ";
99 $resultSet = sqlQuery($query, array($amendment_id));
100 $amendment_date = $resultSet['amendment_date'];
101 $amendment_status = $resultSet['amendment_status'];
102 $amendment_by = $resultSet['amendment_by'];
103 $amendment_desc = $resultSet['amendment_desc'];
105 $query = "SELECT * FROM amendments_history ah INNER JOIN users u ON ah.created_by = u.id WHERE amendment_id = ? ";
106 $resultSet = sqlStatement($query, array($amendment_id));
109 // Check the ACL
110 $haveAccess = acl_check('patients', 'trans');
111 $onlyRead = ( $haveAccess ) ? 0 : 1;
112 $onlyRead = ( $onlyRead || $amendment_status ) ? 1 : 0;
113 $customAttributes = ( $onlyRead ) ? array("disabled" => "true") : null;
117 <html>
118 <head>
119 <?php html_header_show();?>
121 <!-- supporting javascript code -->
122 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery/dist/jquery.min.js"></script>
123 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/textformat.js?v=<?php echo $v_js_includes; ?>"></script>
124 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/dialog.js?v=<?php echo $v_js_includes; ?>"></script>
125 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-datetimepicker/build/jquery.datetimepicker.full.min.js"></script>
127 <!-- page styles -->
128 <link rel="stylesheet" href="<?php echo $css_header;?>" type="text/css">
129 <link rel="stylesheet" href="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-datetimepicker/build/jquery.datetimepicker.min.css">
131 <style>
132 .highlight {
133 color: green;
135 tr.selected {
136 background-color: white;
138 .historytbl {
139 border-collapse: collapse;
141 .historytbl td th{
142 border: 1px solid #000;
144 </style>
146 <script type="text/javascript">
148 function formValidation() {
149 if ( $("#amendment_date").val() == "" ) {
150 alert("<?php echo xls('Select Amendment Date'); ?>");
151 return;
152 } else if ( $("#form_amendment_by").val() == "" ) {
153 alert("<?php echo xls('Select Requested By'); ?>");
154 return;
157 var statusText = $("#form_amendment_status option:selected").text();
158 $("#note").val($("#note").val() + ' ' + statusText);
160 $("#add_edit_amendments").submit();
163 $(document).ready(function() {
164 $('.datepicker').datetimepicker({
165 <?php $datetimepicker_timepicker = false; ?>
166 <?php $datetimepicker_showseconds = false; ?>
167 <?php $datetimepicker_formatInput = true; ?>
168 <?php require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?>
169 <?php // can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
173 </script>
175 </head>
177 <body class="body_top">
179 <form action="add_edit_amendments.php" name="add_edit_amendments" id="add_edit_amendments" method="post" onsubmit='return top.restoreSession()'>
181 <table>
182 <tr>
183 <td>
184 <span class="title"><?php echo xlt('Amendments'); ?></span>&nbsp;
185 </td>
186 <?php if (! $onlyRead) { ?>
187 <td>
188 <a href=# onclick="formValidation()" class="css_button_small"><span><?php echo xlt('Save');?></span></a>
189 </td>
190 <?php } ?>
191 <td>
192 <a href="list_amendments.php" class="css_button_small"><span><?php echo xlt('Back');?></span></a>
193 </td>
194 </tr>
195 </table>
197 <br>
198 <table border=0 cellpadding=1 cellspacing=1>
199 <tr>
200 <td><span class=text ><?php echo xlt('Requested Date'); ?></span></td>
201 <td>
202 <?php if (! $onlyRead) { ?>
203 <input type='text' size='10' class='datepicker' name="amendment_date" id="amendment_date"
204 value='<?php echo $amendment_date ? htmlspecialchars(oeFormatShortDate($amendment_date), ENT_QUOTES) : oeFormatShortDate(); ?>'
206 <?php } else { ?>
207 <input type='text' size='10' name="amendment_date" id="amendment_date" readonly
208 value='<?php echo $amendment_date ? htmlspecialchars(oeFormatShortDate($amendment_date), ENT_QUOTES) : oeFormatShortDate(); ?>'
210 <?php } ?>
211 </td>
212 </tr>
214 <tr>
215 <td><span class=text ><?php echo xlt('Requested By'); ?></span></td>
216 <td>
217 <?php echo generate_select_list("form_amendment_by", "amendment_from", $amendment_by, 'Amendment Request By', ' ', '', '', '', $customAttributes); ?>
218 </td>
219 </tr>
221 <tr>
222 <td><span class=text ><?php echo xlt('Request Description'); ?></span></td>
223 <td><textarea <?php echo ( $onlyRead ) ? "readonly" : ""; ?> id="desc" name="desc" rows="4" cols="30"><?php
224 if ($amendment_id) {
225 echo text($amendment_desc);
226 } else {
227 echo "";
228 } ?></textarea></td>
229 </tr>
231 <tr>
232 <td><span class=text ><?php echo xlt('Request Status'); ?></span></td>
233 <td>
234 <?php echo generate_select_list("form_amendment_status", "amendment_status", $amendment_status, 'Amendment Status', ' ', '', '', '', $customAttributes); ?>
235 </td>
236 </tr>
238 <tr>
239 <td><span class=text ><?php echo xlt('Comments'); ?></span></td>
240 <td><textarea <?php echo ( $onlyRead ) ? "readonly" : ""; ?> id="note" name="note" rows="4" cols="30"><?php
241 if ($amendment_id) {
242 echo "";
243 } else {
244 echo xlt('New amendment request');
245 } ?></textarea></td>
246 </tr>
247 </table>
249 <?php if ($amendment_id) { ?>
250 <hr>
252 <span class="title"><?php echo xlt("History") ; ?></span>
254 <table border="1" cellpadding=3 cellspacing=0 class="historytbl">
256 <!-- some columns are sortable -->
257 <tr class='text bold'>
258 <th align="left" style="width:15%"><?php echo xlt('Date'); ?></th>
259 <th align="left" style="width:25%"><?php echo xlt('By'); ?></th>
260 <th align="left" style="width:15%"><?php echo xlt('Status'); ?></th>
261 <th align="left"><?php echo xlt('Comments'); ?></th>
262 </tr>
264 <?php
265 if (sqlNumRows($resultSet)) {
266 while ($row = sqlFetchArray($resultSet)) {
267 $created_date = date('Y-m-d', strtotime($row['created_time']));
268 echo "<tr>";
269 $userName = $row['lname'] . ", " . $row['fname'];
270 echo "<td align=left class=text>" . text(oeFormatShortDate($created_date)) . "</td>";
271 echo "<td align=left class=text>" . text($userName) . "</td>";
272 echo "<td align=left class=text>" . ( ( $row['amendment_status'] ) ? generate_display_field(array('data_type'=>'1','list_id'=>'amendment_status'), $row['amendment_status']) : '') . "</td>";
273 echo "<td align=left class=text>" . text($row['amendment_note']) . "</td>";
274 echo "<tr>";
278 </table>
279 <?php } ?>
281 <input type="hidden" id="mode" name="mode" value=""/>
282 <input type="hidden" id="amendment_id" name="amendment_id" value="<?php echo attr($amendment_id); ?>"/>
283 </form>
284 </body>
285 </html>