continued bug fixes (#1862)
[openemr.git] / custom / ajax_download.php
blob986ee8288996a57364ecb25c6b0be86e664e1dcf
1 <?php
2 /**
4 * QRDA Ajax Download
6 * Copyright (C) 2015 Ensoftek, Inc
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 2
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 Ensoftek
21 * @link http://www.open-emr.org
27 require_once("../interface/globals.php");
28 require_once("$srcdir/report_database.inc");
29 require_once("../ccr/uuid.php");
30 require_once("qrda_category1_functions.php");
31 require_once("qrda_category1.inc");
32 require_once("qrda_functions.php");
34 if (!verifyCsrfToken($_REQUEST["csrf_token_form"])) {
35 die(xlt('Authentication Error'));
38 $reportID = $_POST['reportID'];
39 $ruleID = $_POST['ruleID'];
40 $counter = $_POST['counter'];
41 $fileName = ( isset($_GET['fileName']) ) ? $_GET['fileName'] : "";
42 $provider_id = $_POST['provider_id'];
44 if ($fileName) {
45 $fileList = explode(",", $fileName);
46 //if ( strpos($fileName,",") !== FALSE ) {
47 if (count($fileList) > 1) {
48 // Multiple files, zip them together
49 $zip = new ZipArchive;
50 $currentTime = date("Y-m-d-H-i-s");
51 global $qrda_file_path;
52 $finalZip = $qrda_file_path . "QRDA_2014_1_" . $currentTime . ".zip";
53 if ($zip->open($finalZip, ZIPARCHIVE::CREATE) != true) {
54 echo xlt("FAILURE: Couldn't create the zip");
57 foreach ($fileList as $eachFile) {
58 check_file_dir_name($eachFile);
59 $zip->addFile($qrda_file_path.$eachFile, $eachFile);
62 $zip->close();
63 foreach ($fileList as $eachFile) {
64 unlink($qrda_file_path.$eachFile);
66 } else {
67 $finalZip = $qrda_file_path.$fileList[0];
70 header("Pragma: public");
71 header("Expires: 0");
72 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
73 header("Content-Type: application/force-download");
74 header("Content-Length: " . filesize($finalZip));
75 header("Content-Disposition: attachment; filename=" . basename($finalZip) . ";");
76 header("Content-Description: File Transfer");
77 readfile($finalZip);
78 unlink($finalZip);
79 exit(0);
82 $report_view = collectReportDatabase($reportID);
83 $dataSheet = json_decode($report_view['data'], true);
84 $target_date = $report_view['date_target'];
86 $criteriaPatients = getCombinePatients($dataSheet, $reportID);
87 $patients = $criteriaPatients[$ruleID];
89 //var_dump($dataSheet);
91 $from_date = date('Y', strtotime($target_date))."-01-01";
92 $to_date = date('Y', strtotime($target_date))."-12-31";
94 if (count($patients)) {
95 $zip = new ZipArchive;
96 global $qrda_file_path;
97 $currentTime = date("Y-m-d-H-i-s");
98 $zipFile = $reportID . "_NQF_" . $ruleID . "_" . $currentTime . ".zip";
99 $zipFileFullPath = $qrda_file_path . $zipFile;
100 if (file_exists($zipFileFullPath)) {
101 unlink($zipFileFullPath);
104 foreach ($patients as $patient) {
105 $xml = new QRDAXml($ruleID);
106 $fileName = mainQrdaCatOneGenerate($xml, $patient, $ruleID, $provider_id);
107 $files[] = $fileName;
110 if ($zip->open($zipFileFullPath, ZIPARCHIVE::CREATE) != true) {
111 echo xlt("FAILURE: Couldn't create the zip");
114 foreach ($files as $eachFile) {
115 $filePath = $qrda_file_path . $eachFile;
116 $zip->addFile($filePath, $eachFile);
119 $zip->close();
120 //Deleting the files after closing the zip
121 foreach ($files as $eachFile) {
122 $filePath = $qrda_file_path . $eachFile;
123 unlink($filePath);
126 echo $zipFile;
127 } else {
128 echo xlt("FAILURE: No patients for measure") . " " . text($ruleID);