increment database counter for prior commits
[openemr.git] / custom / ajax_download.php
blob970dd638ff07c5a40953ab91a377679da9858293
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");
53 foreach ($fileList as $eachFile) {
54 check_file_dir_name($eachFile);
55 $zip->addFile($qrda_file_path.$eachFile, $eachFile);
58 $zip->close();
59 foreach ($fileList as $eachFile) {
60 unlink($qrda_file_path.$eachFile);
62 } else {
63 $finalZip = $qrda_file_path.$fileList[0];
66 header("Pragma: public");
67 header("Expires: 0");
68 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
69 header("Content-Type: application/force-download");
70 header("Content-Length: " . filesize($finalZip));
71 header("Content-Disposition: attachment; filename=" . basename($finalZip) . ";");
72 header("Content-Description: File Transfer");
73 readfile($finalZip);
74 unlink($finalZip);
75 exit(0);
78 $report_view = collectReportDatabase($reportID);
79 $dataSheet = json_decode($report_view['data'], true);
80 $target_date = $report_view['date_target'];
82 $criteriaPatients = getCombinePatients($dataSheet, $reportID);
83 $patients = $criteriaPatients[$ruleID];
85 //var_dump($dataSheet);
87 $from_date = date('Y', strtotime($target_date))."-01-01";
88 $to_date = date('Y', strtotime($target_date))."-12-31";
90 if (count($patients)) {
91 $zip = new ZipArchive;
92 global $qrda_file_path;
93 $currentTime = date("Y-m-d-H-i-s");
94 $zipFile = $reportID . "_NQF_" . $ruleID . "_" . $currentTime . ".zip";
95 $zipFileFullPath = $qrda_file_path . $zipFile;
96 if (file_exists($zipFileFullPath)) {
97 unlink($zipFileFullPath);
100 foreach ($patients as $patient) {
101 $xml = new QRDAXml($ruleID);
102 $fileName = mainQrdaCatOneGenerate($xml, $patient, $ruleID, $provider_id);
103 $files[] = $fileName;
106 if ($zip->open($zipFileFullPath, ZIPARCHIVE::CREATE) != true) {
107 echo xlt("FAILURE: Couldn't create the zip");
110 foreach ($files as $eachFile) {
111 $filePath = $qrda_file_path . $eachFile;
112 $zip->addFile($filePath, $eachFile);
115 $zip->close();
116 //Deleting the files after closing the zip
117 foreach ($files as $eachFile) {
118 $filePath = $qrda_file_path . $eachFile;
119 unlink($filePath);
122 echo $zipFile;
123 } else {
124 echo xlt("FAILURE: No patients for measure") . " " . text($ruleID);