/
display_documents.php
246 lines (213 loc) · 9.79 KB
/
display_documents.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
<?php
/**
* Displays the documents
* Only Lab documents for now.
*
* @package OpenEMR
* @link http://www.open-emr.org
* @author Hema Bandaru <hemab@drcloudemr.com>
* @author Brady Miller <brady.g.miller@gmail.com>
* @author Harshal Lele <harshallele97@gmail.com>
* @copyright Copyright (c) 2014 Ensoftek
* @copyright Copyright (c) 2017-2018 Brady Miller <brady.g.miller@gmail.com>
* @copyright Copyright (c) 2018 Harshal Lele <harshallele97@gmail.com>
* @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
*/
require_once('../globals.php');
require_once("$srcdir/patient.inc");
use OpenEMR\Common\Acl\AclMain;
use OpenEMR\Common\Twig\TwigContainer;
use OpenEMR\Core\Header;
if (!AclMain::aclCheckCore('patients', 'lab')) {
echo (new TwigContainer(null, $GLOBALS['kernel']))->getTwig()->render('core/unauthorized.html.twig', ['pageTitle' => xl("Lab Documents")]);
exit;
}
$curdate = date_create(date("Y-m-d"));
date_sub($curdate, date_interval_create_from_date_string("7 days"));
$sub_date = date_format($curdate, 'Y-m-d');
// Set the default dates for Lab document search
$form_from_doc_date = ($_GET['form_from_doc_date'] ?? oeFormatShortDate($sub_date));
$form_to_doc_date = ($_GET['form_to_doc_date'] ?? oeFormatShortDate(date("Y-m-d")));
if ($GLOBALS['date_display_format'] == 1) {
$title_tooltip = "MM/DD/YYYY";
} elseif ($GLOBALS['date_display_format'] == 2) {
$title_tooltip = "DD/MM/YYYY";
} else {
$title_tooltip = "YYYY-MM-DD";
}
$display_div = "style='display:block;'";
?>
<html>
<head>
<?php
Header::setupHeader(['datetime-picker', 'common']);
require_once("$srcdir/payment_jav.inc.php");
?>
<script>
var global_date_format = '<?php echo DateFormatRead(); ?>';
$(function () {
$("#docdiv a").each(function() {
let name = $(this).get(0);
let tooltip = document.getElementsByClassName('tooltip_container')[0];
let tooltipDoc = document.getElementsByClassName('tooltip_doc')[0];
let tooltipVisible = false;
name.addEventListener('mouseenter',() => {
//check if the document is already visible
if(!tooltipVisible){
//set the position of tooltip to that of the table cell
let rect = name.getBoundingClientRect();
let nameTop = rect.top + window.pageYOffset;
let nameLeft = rect.left + window.pageXOffset;
tooltip.style.left = nameLeft;
tooltip.style.top = nameTop;
tooltipDoc.src = $(this).attr('title');
tooltip.style.display = 'block';
tooltipDoc.style.maxHeight = '100%';
tooltipVisible = true;
}
});
//hide the tooltip when the cursor goes out of the image
tooltip.addEventListener('mouseleave',() => {
tooltip.style.display = 'none';
tooltipVisible = false;
});
})
$('.datepicker').datetimepicker({
<?php $datetimepicker_timepicker = false; ?>
<?php $datetimepicker_showseconds = false; ?>
<?php $datetimepicker_formatInput = true; ?>
<?php require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?>
<?php // can add any additional javascript settings to datetimepicker here; need to prepend first setting with a comma ?>
});
});
function validateDate(fromDate,toDate){
var frmdate = $("#" + fromDate).val();
var todate = $("#" + toDate).val();
if ( (frmdate.length > 0) && (todate.length > 0) ) {
if ( DateCheckGreater(frmdate, todate, global_date_format) == false ){
alert(<?php echo xlj('To date must be later than From date!'); ?>);
return false;
}
}
document.location='<?php echo $GLOBALS['webroot']; ?>/interface/main/display_documents.php?form_from_doc_date=' + encodeURIComponent(frmdate) + '&form_to_doc_date=' + encodeURIComponent(todate);
}
</script>
<style>
.linkcell {
max-width: 250px;
text-overflow: ellipsis;
overflow: hidden;
}
.tooltip_container{
background-color: var(--gray);
width: 75%;
height: 50%;
z-index: 1;
display: none;
position: absolute;
box-sizing: border-box;
border: 10px solid var(--gray);
}
.tooltip_doc {
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<div class="container mt-3">
<div class="row">
<div class="col-12">
<h2 class='title'><?php echo xlt('Lab Documents'); ?></h2>
<br />
<div id='docfilterdiv'<?php echo $display_div; ?>>
<div class="form-inline mb-2">
<label for='form_from_doc_date' class='label_custom mx-1'><?php echo xlt('From'); ?>:</label>
<input type='text' class='form-control datepicker mx-1' name='form_from_doc_date' id="form_from_doc_date" size='10' value='<?php echo attr($form_from_doc_date) ?>' title='<?php echo attr($title_tooltip) ?>' />
<label for='form_to_doc_date' class='label_custom mx-1'><?php echo xlt('To{{Range}}'); ?>:</label>
<input type='text' class='form-control datepicker mx-1' name='form_to_doc_date' id="form_to_doc_date" size='10' value='<?php echo attr($form_to_doc_date) ?>' title='<?php echo attr($title_tooltip) ?>' />
<span id="docrefresh" class="mx-1">
<button type="button" class="btn btn-primary btn-refresh" onclick='return validateDate("form_from_doc_date","form_to_doc_date")'>
<?php echo xlt('Refresh'); ?>
</button>
</span>
</div>
</div>
</div>
</div>
<div class='col-12' id='docdiv' <?php echo $display_div; ?>>
<?php
$current_user = $_SESSION['authUserID'];
$date_filter = '';
$query_array = array();
if ($form_from_doc_date) {
$form_from_doc_date = DateToYYYYMMDD($form_from_doc_date);
$date_filter = " DATE(d.date) >= ? ";
array_push($query_array, $form_from_doc_date);
}
if ($form_to_doc_date) {
$form_to_doc_date = DateToYYYYMMDD($form_to_doc_date);
$date_filter .= " AND DATE(d.date) <= ? ";
array_push($query_array, $form_to_doc_date);
}
// Get the category ID for lab reports.
$query = "SELECT rght FROM categories WHERE name = ?";
$catIDRs = sqlQuery($query, array($GLOBALS['lab_results_category_name']));
$catID = $catIDRs['rght'];
$query = "SELECT d.*,CONCAT(pd.fname,' ',pd.lname) AS pname,GROUP_CONCAT(n.note ORDER BY n.date DESC SEPARATOR '|') AS docNotes,
GROUP_CONCAT(n.date ORDER BY n.date DESC SEPARATOR '|') AS docDates FROM documents d
INNER JOIN patient_data pd ON d.foreign_id = pd.pid
INNER JOIN categories_to_documents ctd ON d.id = ctd.document_id AND ctd.category_id = ?
LEFT JOIN notes n ON d.id = n.foreign_id
WHERE " . $date_filter . " GROUP BY d.id ORDER BY date DESC";
array_unshift($query_array, $catID);
$resultSet = sqlStatement($query, $query_array);
?>
<div class="table-responsive">
<table class="table table-bordered">
<thead class='thead-light'>
<tr class='text font-weight-bold text-left'>
<th width="10%"><?php echo xlt('Date'); ?></th>
<th class="linkcell" width="20%"><?php echo xlt('Name'); ?></th>
<th><?php echo xlt('Patient'); ?></th>
<th><?php echo xlt('Note'); ?></th>
<th width="10%"><?php echo xlt('Encounter ID'); ?></th>
</tr>
</thead>
<?php
if (sqlNumRows($resultSet)) {
while ($row = sqlFetchArray($resultSet)) {
$url = $GLOBALS['webroot'] . "/controller.php?document&retrieve&patient_id=" . attr_url($row["foreign_id"]) . "&document_id=" . attr_url($row["id"]) . '&as_file=false';
// Get the notes for this document.
$notes = array();
$note = '';
if ($row['docNotes']) {
$notes = explode("|", $row['docNotes']);
$dates = explode("|", $row['docDates']);
}
for ($i = 0; $i < count($notes); $i++) {
$note .= text(oeFormatShortDate(date('Y-m-d', strtotime($dates[$i])))) . " : " . text($notes[$i]) . "<br />";
}
?>
<tr class="text">
<td><?php echo text(oeFormatShortDate(date('Y-m-d', strtotime($row['date'])))); ?> </td>
<td class="linkcell">
<a id="<?php echo attr($row['id']); ?>" title='<?php echo $url; ?>' onclick='top.restoreSession()'><?php echo text(basename($row['url'])); ?></a>
</td>
<td><?php echo text($row['pname']); ?> </td>
<td><?php echo $note; ?> </td>
<td class="text-center"><?php echo ( $row['encounter_id'] ) ? text($row['encounter_id']) : ''; ?> </td>
</tr>
<?php
} ?>
<?php
} ?>
</table>
</div>
</div>
<div class="tooltip_container">
<iframe class="tooltip_doc"></iframe>
</div>
</div>
</body>
</html>