forked from openemr/openemr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ajax_download.php
120 lines (109 loc) · 3.86 KB
/
ajax_download.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
<?php
/**
*
* QRDA Ajax Download
*
* Copyright (C) 2015 Ensoftek, Inc
*
* LICENSE: This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http:https://opensource.org/licenses/gpl-license.php>;.
*
* @package OpenEMR
* @author Ensoftek
* @link http:https://www.open-emr.org
*/
$sanitize_all_escapes=true;
$fake_register_globals=false;
require_once("../interface/globals.php");
require_once("$srcdir/report_database.inc");
require_once("$srcdir/sanitize.inc.php");
require_once("../library/classes/QRDAXml.class.php");
require_once("../ccr/uuid.php");
require_once("qrda_category1_functions.php");
require_once("qrda_category1.inc");
require_once("qrda_functions.php");
$reportID = $_POST['reportID'];
$ruleID = $_POST['ruleID'];
$counter = $_POST['counter'];
$fileName = ( isset($_GET['fileName']) ) ? $_GET['fileName'] : "";
$provider_id = $_POST['provider_id'];
if ( $fileName ) {
$fileList = explode(",",$fileName);
//if ( strpos($fileName,",") !== FALSE ) {
if ( count($fileList) > 1 ) {
// Multiple files, zip them together
$zip = new ZipArchive;
$currentTime = date("Y-m-d-H-i-s");
global $qrda_file_path;
$finalZip = $qrda_file_path . "QRDA_2014_1_" . $currentTime . ".zip";
if ($zip->open($finalZip, ZIPARCHIVE::CREATE) != TRUE) {
echo xlt("FAILURE: Couldn't create the zip");
}
foreach ( $fileList as $eachFile ) {
check_file_dir_name($eachFile);
$zip->addFile($qrda_file_path.$eachFile,$eachFile);
}
$zip->close();
foreach ( $fileList as $eachFile ) {
unlink($qrda_file_path.$eachFile);
}
} else {
$finalZip = $qrda_file_path.$fileList[0];
}
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/force-download");
header("Content-Length: " . filesize($finalZip));
header("Content-Disposition: attachment; filename=" . basename($finalZip) . ";");
header("Content-Description: File Transfer");
readfile($finalZip);
unlink($finalZip);
exit(0);
}
$report_view = collectReportDatabase($reportID);
$dataSheet = json_decode($report_view['data'],TRUE);
$target_date = $report_view['date_target'];
$criteriaPatients = getCombinePatients($dataSheet, $reportID);
$patients = $criteriaPatients[$ruleID];
//var_dump($dataSheet);
$from_date = date('Y', strtotime($target_date))."-01-01";
$to_date = date('Y', strtotime($target_date))."-12-31";
if ( count($patients) ) {
$zip = new ZipArchive;
global $qrda_file_path;
$currentTime = date("Y-m-d-H-i-s");
$zipFile = $reportID . "_NQF_" . $ruleID . "_" . $currentTime . ".zip";
$zipFileFullPath = $qrda_file_path . $zipFile;
if(file_exists($zipFileFullPath))
unlink($zipFileFullPath);
foreach ( $patients as $patient ) {
$xml = new QRDAXml($ruleID);
$fileName = mainQrdaCatOneGenerate($xml, $patient, $ruleID, $provider_id);
$files[] = $fileName;
}
if ($zip->open($zipFileFullPath, ZIPARCHIVE::CREATE) != TRUE) {
echo xlt("FAILURE: Couldn't create the zip");
}
foreach ( $files as $eachFile ) {
$filePath = $qrda_file_path . $eachFile;
$zip->addFile($filePath,$eachFile);
}
$zip->close();
//Deleting the files after closing the zip
foreach ( $files as $eachFile ) {
$filePath = $qrda_file_path . $eachFile;
unlink($filePath);
}
echo $zipFile;
} else
echo xlt("FAILURE: No patients for measure") . " " . text($ruleID);
?>