Centralized formatting.inc.php include
[openemr.git] / interface / main / display_documents.php
blobcc510a6d0b95319350cb4ba0ef5d16b22c12512b
1 <?php
2 /**
3 * Displays the documents
4 * Only Lab documents for now.
6 * Copyright (C) 2014 Ensoftek
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 * @link http://www.open-emr.org
24 //SANITIZE ALL ESCAPES
25 $sanitize_all_escapes=true;
26 //STOP FAKE REGISTER GLOBALS
27 $fake_register_globals=false;
29 require_once('../globals.php');
30 require_once("$srcdir/patient.inc");
31 require_once("$srcdir/payment_jav.inc.php");
33 $DateFormat = DateFormatRead();
34 $curdate = date_create(date("Y-m-d"));
35 date_sub($curdate, date_interval_create_from_date_string("7 days"));
36 $sub_date = date_format($curdate, 'Y-m-d');
38 // Set the default dates for Lab document search
39 $form_from_doc_date = ( $_GET['form_from_doc_date'] ) ? $_GET['form_from_doc_date'] : oeFormatShortDate(fixDate($_GET['form_from_doc_date'],$sub_date));
40 $form_to_doc_date = ( $_GET['form_to_doc_date'] ) ? $_GET['form_to_doc_date'] : oeFormatShortDate(fixDate($_GET['form_to_doc_date'],date("Y-m-d")));
42 if($GLOBALS['date_display_format'] == 1) {
43 $title_tooltip = "MM/DD/YYYY";
44 } elseif($GLOBALS['date_display_format'] == 2) {
45 $title_tooltip = "DD/MM/YYYY";
46 } else {
47 $title_tooltip = "YYYY-MM-DD";
50 $display_div = "style='display:block;'";
51 $display_expand_msg = "display:none;";
52 $display_collapse_msg = "display:inline;";
56 <html>
57 <head>
59 <?php html_header_show();?>
60 <link rel="stylesheet" href="<?php echo $css_header;?>" type="text/css">
61 <link rel="stylesheet" href='<?php echo $GLOBALS['assets_static_relative'] ?>/qtip2-2-2-1/jquery.qtip.min.css' type='text/css'>
62 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/dialog.js?v=<?php echo $v_js_includes; ?>"></script>
63 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/textformat.js"></script>
64 <!-- stuff for the popup calendar -->
65 <style type="text/css">@import url(<?php echo $GLOBALS['webroot'] ?>/library/dynarch_calendar.css);</style>
66 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/dynarch_calendar.js"></script>
67 <?php include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); ?>
68 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/dynarch_calendar_setup.js"></script>
69 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/common.js"></script>
70 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-min-1-7-2/index.js"></script>
71 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/jquery-ui-1.8.6.custom.min.js"></script>
72 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative'] ?>/qtip2-2-2-1/jquery.qtip.js"></script>
74 <script type="text/javascript">
75 var global_date_format = '<?php echo $DateFormat; ?>';
76 $(document).ready(function() {
77 $("#docdiv a").each(function() {
78 $(this).qtip({
79 content : '<iframe class="qtip-box" src="' + $(this).attr('title') + '" />',
80 hide : {
81 delay : 20,
82 fixed : true
84 position : {
85 at : 'bottom left',
86 viewport : $(window),
87 adjust: {
88 x: 20
91 style: 'qtip-style'
94 });
96 function validateDate(fromDate,toDate){
97 var frmdate = $("#" + fromDate).val();
98 var todate = $("#" + toDate).val();
99 if ( (frmdate.length > 0) && (todate.length > 0) ) {
100 if ( DateCheckGreater(frmdate, todate, global_date_format) == false ){
101 alert("<?php xl('To date must be later than From date!','e'); ?>");
102 return false;
105 document.location='<?php echo $GLOBALS['webroot']; ?>/interface/main/display_documents.php?' + fromDate + '='+frmdate+'&' + toDate + '='+todate;
108 function expandOrCollapse(type,prefixString) {
109 if(type == 1 ) {
110 $("#" + prefixString + "filterdiv").show();
111 $("#" + prefixString + "div").show();
112 $("#" + prefixString + "collapse").show();
113 $("#" + prefixString + "expand").hide();
114 } else {
115 $("#" + prefixString + "filterdiv").hide();
116 $("#" + prefixString + "div").hide();
117 $("#" + prefixString + "collapse").hide();
118 $("#" + prefixString + "expand").show();
122 </script>
124 <style type="text/css">
125 .qtip-box{
126 width : 100%;
127 height : 95%;
130 .qtip-style {
131 width: 75%;
132 max-width: 75%;
133 height: 50%;
134 max-height: 50%;
136 .qtip {
137 max-width : 100%;
140 .linkcell {
141 max-width: 250px ;
142 text-overflow: ellipsis;
143 overflow: hidden;
144 valign : absbottom;
147 </style>
148 </head>
150 <body class="body_top">
152 <div>
153 <span class='title'><?php echo text('Lab Documents'); ?></span>
154 <span id='docexpand' onclick='expandOrCollapse(1,"doc")' style='cursor:pointer;<?php echo $display_expand_msg ?>'>(expand)</span>
155 <span id='doccollapse' onclick='expandOrCollapse(2,"doc")' style='cursor:pointer;<?php echo $display_collapse_msg ?>'>(collapse)</span>
156 <br><br>
157 <div id='docfilterdiv'<?php echo $display_div; ?>>
158 <table style="margin-left:10px; " width='40%'>
159 <tr>
160 <td scope="row" class='label'><?php echo xlt('From'); ?>:</td>
161 <td><input type='text' name='form_from_doc_date' id="form_from_doc_date"
162 size='10' value='<?php echo attr($form_from_doc_date) ?>' readonly="readonly" title='<?php echo attr($title_tooltip) ?>'>
163 <img alt="<?php echo xla("Date Selector"); ?>" src='../pic/show_calendar.gif' align='absbottom' width='24' height='22' id='img_from_doc_date'
164 border='0' alt='[?]' style='cursor: pointer' title='<?php echo xla('Click here to choose a date'); ?>'></td>
165 <script>
166 Calendar.setup({inputField:"form_from_doc_date", ifFormat:global_date_format, button:"img_from_doc_date"});
167 </script>
168 <td class='label'><?php echo xlt('To'); ?>:</td>
169 <td><input type='text' name='form_to_doc_date' id="form_to_doc_date"
170 size='10' value='<?php echo attr($form_to_doc_date) ?>' readonly="readonly" title='<?php echo attr($title_tooltip) ?>'>
171 <img alt="<?php xla("Date Selector"); ?>" src='../pic/show_calendar.gif' align='absbottom' width='24' height='22' id='img_to_doc_date'
172 border='0' alt='[?]' style='cursor: pointer' title='<?php echo xla('Click here to choose a date'); ?>'></td>
173 <script>
174 Calendar.setup({inputField:"form_to_doc_date", ifFormat:global_date_format, button:"img_to_doc_date"});
175 </script>
176 <td>
177 <span style='float: left;' id="docrefresh">
178 <a href='#' class='css_button' onclick='return validateDate("form_from_doc_date","form_to_doc_date")'> <span><?php echo xlt('Refresh'); ?> </span></a>
179 </span>
180 </td>
181 </tr>
182 </table>
183 </div>
184 </div>
186 <div id='docdiv' <?php echo $display_div; ?>>
187 <?php
188 $current_user = $_SESSION["authId"];
189 $date_filter = '';
190 $query_array = array();
191 if ($form_from_doc_date) {
192 $form_from_doc_date = DateToYYYYMMDD($form_from_doc_date);
193 $date_filter = " DATE(d.date) >= ? ";
194 array_push($query_array,$form_from_doc_date);
196 if ($form_to_doc_date) {
197 $form_to_doc_date = DateToYYYYMMDD($form_to_doc_date);
198 $date_filter .= " AND DATE(d.date) <= ? ";
199 array_push($query_array,$form_to_doc_date);
201 // Get the category ID for lab reports.
202 $query = "SELECT rght FROM categories WHERE name = ?";
203 $catIDRs = sqlQuery($query,array($GLOBALS['lab_results_category_name']));
204 $catID = $catIDRs['rght'];
206 $query = "SELECT d.*,CONCAT(pd.fname,' ',pd.lname) AS pname,GROUP_CONCAT(n.note ORDER BY n.date DESC SEPARATOR '|') AS docNotes,
207 GROUP_CONCAT(n.date ORDER BY n.date DESC SEPARATOR '|') AS docDates FROM documents d
208 INNER JOIN patient_data pd ON d.foreign_id = pd.pid
209 INNER JOIN categories_to_documents ctd ON d.id = ctd.document_id AND ctd.category_id = ?
210 LEFT JOIN notes n ON d.id = n.foreign_id
211 WHERE " . $date_filter . " GROUP BY d.id ORDER BY date DESC";
212 array_unshift($query_array,$catID);
213 $resultSet = sqlStatement($query,$query_array);
216 <table border="1" cellpadding=3 cellspacing=0>
217 <tr class='text bold'>
218 <th align="left" width="10%"><?php echo xlt('Date'); ?></th>
219 <th align="left" class="linkcell" width="20%" ><?php echo xlt('Name'); ?></th>
220 <th align="left" width="20%"><?php echo xlt('Patient'); ?></th>
221 <th align="left" width="30%"><?php echo xlt('Note'); ?></th>
222 <th width="10%"><?php echo xlt('Encounter ID'); ?></th>
223 </tr>
224 <?php
225 if (sqlNumRows($resultSet)) {
226 while ( $row = sqlFetchArray($resultSet) ) {
227 $url = $GLOBALS['webroot'] . "/controller.php?document&retrieve&patient_id=" . attr($row["foreign_id"]) . "&document_id=" . attr($row["id"]) . '&as_file=false';
228 // Get the notes for this document.
229 $notes = array();
230 $note = '';
231 if ( $row['docNotes'] ) {
232 $notes = explode("|",$row['docNotes']);
233 $dates = explode("|", $row['docDates']);
235 for ( $i = 0 ; $i < count($notes) ; $i++ )
236 $note .= oeFormatShortDate(date('Y-m-d', strtotime($dates[$i]))) . " : " . text($notes[$i]) . "<br />";
238 <tr class="text">
239 <td><?php echo oeFormatShortDate(date('Y-m-d', strtotime($row['date']))); ?> </td>
240 <td class="linkcell">
241 <a id="<?php echo attr($row['id']); ?>" title='<?php echo $url; ?>' onclick='top.restoreSession()'><?php echo text(basename($row['url'])); ?></a>
242 </td>
243 <td><?php echo text($row['pname']); ?> </td>
244 <td><?php echo $note; ?> &nbsp;</td>
245 <td align="center"><?php echo ( $row['encounter_id'] ) ? text($row['encounter_id']) : ''; ?> </td>
246 </tr>
247 <?php } ?>
248 <?php } ?>
249 </table>
250 </div>
251 </body>
252 </html>