consolidated reviewMode in forms.php (this can then be used for view only acl users...
[openemr.git] / custom / ajax_download.php
blob9e05a8978daaf030af37889663835984b1c1d97e
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 $reportID = $_POST['reportID'];
35 $ruleID = $_POST['ruleID'];
36 $counter = $_POST['counter'];
37 $fileName = ( isset($_GET['fileName']) ) ? $_GET['fileName'] : "";
38 $provider_id = $_POST['provider_id'];
40 if ( $fileName ) {
41 $fileList = explode(",",$fileName);
42 //if ( strpos($fileName,",") !== FALSE ) {
43 if ( count($fileList) > 1 ) {
44 // Multiple files, zip them together
45 $zip = new ZipArchive;
46 $currentTime = date("Y-m-d-H-i-s");
47 global $qrda_file_path;
48 $finalZip = $qrda_file_path . "QRDA_2014_1_" . $currentTime . ".zip";
49 if ($zip->open($finalZip, ZIPARCHIVE::CREATE) != TRUE) {
50 echo xlt("FAILURE: Couldn't create the zip");
52 foreach ( $fileList as $eachFile ) {
53 check_file_dir_name($eachFile);
54 $zip->addFile($qrda_file_path.$eachFile,$eachFile);
56 $zip->close();
57 foreach ( $fileList as $eachFile ) {
58 unlink($qrda_file_path.$eachFile);
60 } else {
61 $finalZip = $qrda_file_path.$fileList[0];
64 header("Pragma: public");
65 header("Expires: 0");
66 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
67 header("Content-Type: application/force-download");
68 header("Content-Length: " . filesize($finalZip));
69 header("Content-Disposition: attachment; filename=" . basename($finalZip) . ";");
70 header("Content-Description: File Transfer");
71 readfile($finalZip);
72 unlink($finalZip);
73 exit(0);
76 $report_view = collectReportDatabase($reportID);
77 $dataSheet = json_decode($report_view['data'],TRUE);
78 $target_date = $report_view['date_target'];
80 $criteriaPatients = getCombinePatients($dataSheet, $reportID);
81 $patients = $criteriaPatients[$ruleID];
83 //var_dump($dataSheet);
85 $from_date = date('Y', strtotime($target_date))."-01-01";
86 $to_date = date('Y', strtotime($target_date))."-12-31";
88 if ( count($patients) ) {
89 $zip = new ZipArchive;
90 global $qrda_file_path;
91 $currentTime = date("Y-m-d-H-i-s");
92 $zipFile = $reportID . "_NQF_" . $ruleID . "_" . $currentTime . ".zip";
93 $zipFileFullPath = $qrda_file_path . $zipFile;
94 if(file_exists($zipFileFullPath))
95 unlink($zipFileFullPath);
97 foreach ( $patients as $patient ) {
98 $xml = new QRDAXml($ruleID);
99 $fileName = mainQrdaCatOneGenerate($xml, $patient, $ruleID, $provider_id);
100 $files[] = $fileName;
102 if ($zip->open($zipFileFullPath, ZIPARCHIVE::CREATE) != TRUE) {
103 echo xlt("FAILURE: Couldn't create the zip");
105 foreach ( $files as $eachFile ) {
106 $filePath = $qrda_file_path . $eachFile;
107 $zip->addFile($filePath,$eachFile);
109 $zip->close();
110 //Deleting the files after closing the zip
111 foreach ( $files as $eachFile ) {
112 $filePath = $qrda_file_path . $eachFile;
113 unlink($filePath);
115 echo $zipFile;
116 } else
117 echo xlt("FAILURE: No patients for measure") . " " . text($ruleID);