forked from thundi3/thairisfree
-
Notifications
You must be signed in to change notification settings - Fork 0
/
export-report.php
201 lines (187 loc) · 6.89 KB
/
export-report.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
<?php
############################################
# ThaiRIS (Thai Radiology Information System)
# Version: 1.0
# File last modified: 8 Nov 2016
# File name:
# Description :
# http://www.thairis.net
# Email : info.xraythai@gmail.com
############################################
include "connectdb.php";
include "session.php";
$timenow = time();
$datestart = $_POST['date7'];
$dateend = $_POST['date8'];
///// Check total search days /////
if ($datestart == '' OR $dateend == '')
{
echo "Please input date";
exit;
}
$daterange1 = strtotime($datestart);
$daterange2 = strtotime($dateend);
$daterange1 = date('Ymd',$daterange1);
$daterange2 = date('Ymd',$daterange2);
$daterange = $daterange2 - $daterange1;
echo "Total date search : ".$daterange." days<br >";
if ($daterange > 1800000)
{
echo "Don't serch date more than 6 months </br>";
echo "System will slow down </br>";
echo "<a href=query.php>Back to Query </a>";
exit;
}
////////////////////////////////
$strExcelFileName="Export-Report-ThaiRIS_".time().".xls";
header("Content-Type: application/x-msexcel; name=\"$strExcelFileName\"");
header("Content-Disposition: inline; filename=\"$strExcelFileName\"");
header("Pragma:no-cache");
$sql_select = "
SELECT
xray_request_detail.ACCESSION,
xray_patient_info.MRN,
xray_patient_info.PREFIX AS PAT_PREFIX,
xray_patient_info.NAME AS PAT_NAME,
xray_patient_info.LASTNAME AS PAT_LASTNAME,
xray_patient_info.SEX AS PAT_SEX,
xray_request_detail.REQUEST_DATE,
xray_request_detail.REQUEST_TIME,
xray_request_detail.ARRIVAL_TIME AS ARRIVAL,
xray_request_detail.APPROVED_TIME AS APPROVE,
xray_request_detail.XRAY_CODE,
xray_code.DESCRIPTION,
xray_code.XRAY_TYPE_CODE,
xray_department.NAME_THAI AS DEP,
xray_report.REPORT,
xray_report.APPROVE_DATE,
xray_report.APPROVE_TIME,
xray_user.CODE AS USERCODE,
xray_user.NAME AS DOCTOR_NAME,
xray_user.LASTNAME AS DOCTOR_LASTNAME,
xray_referrer.REFERRER_ID,
xray_referrer.NAME AS REF_NAME,
xray_referrer.LASTNAME AS REF_LASTNAME
FROM
xray_report
Left Join xray_user ON xray_user.ID = xray_report.APPROVE_BY
Left Join xray_request ON xray_request.REQUEST_NO = xray_report.ACCESSION
Left Join xray_request_detail ON xray_request_detail.ACCESSION = xray_report.ACCESSION
Left Join xray_patient_info ON xray_patient_info.MRN = xray_request.MRN
Left Join xray_code ON xray_code.XRAY_CODE = xray_request_detail.XRAY_CODE
LEFT JOIN xray_department ON xray_department.DEPARTMENT_ID = xray_request.DEPARTMENT_ID
LEFT JOIN xray_referrer ON xray_referrer.REFERRER_ID = xray_request.REFERRER
WHERE
(xray_report.APPROVE_DATE BETWEEN '$datestart' AND '$dateend')
";
$sql = mysql_query($sql_select);
$num = mysql_num_rows($sql);
function timeDiff($firstTime,$lastTime)
{
// convert to unix timestamps
$firstTime=strtotime($firstTime);
$lastTime=strtotime($lastTime);
// perform subtraction to get the difference (in seconds) between times
$timeDiff=$lastTime-$firstTime;
// return the difference
return $timeDiff;
}
?>
<html xmlns:o="urn:schemas-microsoft-com:office:office"xmlns:x="urn:schemas-microsoft-com:office:excel"xmlns="http://www.w3.org/TR/REC-html40">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<strong>รายงาน วันที่ <?php echo date("d/m/Y");?> ทั้งหมด <?php echo number_format($num);?> รายการ</strong><br>
<br>
<div id="SiXhEaD_Excel" align=center x:publishsource="Excel">
<table x:str border=1 cellpadding=0 cellspacing=1 width=100% style="border-collapse:collapse">
<tr>
<td><strong>ACCESSION</strong></td>
<td><strong>MRN</strong></td>
<td><strong>PREFIX</strong></td>
<td><strong>NAME</strong></td>
<td><strong>LASTNAME</strong></td>
<td><strong>SEX</strong></td>
<td><strong>REQUEST DATE</strong></td>
<td><strong>REQUEST TIME</strong></td>
<td><strong>XRAY CODE</strong></td>
<td><strong>XRAY TYPE</strong></td>
<td><strong>DESCRIPTION</strong></td>
<td><strong>Referrer ID</strong></td>
<td><strong>Referrer Name</strong></td>
<td><strong>Department</strong></td>
<td><strong>APPROVE DATE</strong></td>
<td><strong>APPROVE TIME</strong></td>
<td><strong>User Code</strong></td>
<td><strong>Radiologist</strong></td>
<td><strong>Report</strong></td>
</tr>
<?php
if($num>0)
{
while($row=mysql_fetch_array($sql))
{
$time_arrival = $row['ARRIVAL'];
$time_approve = $row['APPROVE'];
$time_diff = timeDiff($time_arrival,$time_approve);
// Convert to text
$years = abs(floor($time_diff / 31536000));
$days = abs(floor(($time_diff-($years * 31536000))/86400));
$hours = abs(floor(($time_diff-($years * 31536000)-($days * 86400))/3600));
$mins = abs(floor(($time_diff-($years * 31536000)-($days * 86400)-($hours * 3600))/60));#floor($time_diff / 60);
$TEXTREPORT = $row['REPORT'];
$allow = '<br />,<br>,<br/>,<div>,</p>';
$result= strip_tags($TEXTREPORT,$allow);
$result1 = trim(preg_replace('/\s+/', ' ', $result));
$result1= preg_replace('#<div\s*/?>#i', '', $result1); // Replace <br > with new line \n
$result1= preg_replace('#<p\s*/?>#i', '', $result1); // Replace <br > with new line \n
$result1= preg_replace('#</p\s*/?>#i', '\.br\\', $result1); // Replace <br > with new line \n
$result1= preg_replace('#<br\s*/?>#i', '\.br\\', $result1); // Replace <br > with new line \n
$result1= preg_replace('#</div\s*/?>#i', '\.br\\', $result1); // Replace <br > with new line \n
$result1= preg_replace('/[\n\r\t]/', '\.br\\', $result1);
$result1= preg_replace('/<[^>]*>/', '', $result1);
$result1 = str_replace(" ", " ", $result1);
$result1 = str_replace("&", "&", $result1);
$result1 = str_replace("<", "<", $result1);
$result1 = str_replace(">", ">", $result1);
$REPORT = $result1;
?>
<tr>
<td><?php echo $row['ACCESSION'];?></td>
<td><?php echo $row['MRN'];?></td>
<td><?php echo $row['PAT_PREFIX'];?></td>
<td><?php echo $row['PAT_NAME'];?></td>
<td><?php echo $row['PAT_LASTNAME'];?></td>
<td><?php echo $row['PAT_SEX'];?></td>
<td><?php echo $row['REQUEST_DATE'];?></td>
<td><?php echo $row['REQUEST_TIME'];?></td>
<td><?php echo $row['XRAY_CODE'];?></td>
<td><?php echo $row['XRAY_TYPE_CODE'];?></td>
<td><?php echo $row['DESCRIPTION'];?></td>
<td><?php echo $row['REFERRER_ID'];?></td>
<td><?php echo $row['REF_NAME']." ".$row['REF_LASTNAME'];?></td>
<td><?php echo $row['DEP'];?></td>
<td><?php echo $row['APPROVE_DATE'];?></td>
<td><?php echo $row['APPROVE_TIME'];?></td>
<td><?php echo $row['USERCODE'];?></td>
<td><?php echo $row['DOCTOR_NAME']." ".$row['DOCTOR_LASTNAME'];?></td>
<td><?php echo $REPORT;?></td>
</tr>
<?php
}
$IP=getenv(REMOTE_ADDR);
$URL=$_SERVER["HTTP_REFERER"];
mysql_query("insert into xray_log (USER,IP,EVENT,URL)VALUES ('$userlogin','$IP','Export Report','$URL')");
}
?>
</table>
</div>
<script>
window.onbeforeunload = function(){return false;};
setTimeout(function(){window.close();}, 10000);
</script>
</body>
</html>