Fix - a default value for pubpid is not written to the database when the External...
[openemr.git] / custom / ajax_download.php
blob9754d55552996f7d4a6f171b5eb5b86439b1394b
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
24 $sanitize_all_escapes=true;
25 $fake_register_globals=false;
27 require_once("../interface/globals.php");
28 require_once("$srcdir/report_database.inc");
29 require_once("$srcdir/sanitize.inc.php");
30 require_once("../library/classes/QRDAXml.class.php");
31 require_once("../ccr/uuid.php");
32 require_once("qrda_category1_functions.php");
33 require_once("qrda_category1.inc");
34 require_once("qrda_functions.php");
36 $reportID = $_POST['reportID'];
37 $ruleID = $_POST['ruleID'];
38 $counter = $_POST['counter'];
39 $fileName = ( isset($_GET['fileName']) ) ? $_GET['fileName'] : "";
40 $provider_id = $_POST['provider_id'];
42 if ( $fileName ) {
43 $fileList = explode(",",$fileName);
44 //if ( strpos($fileName,",") !== FALSE ) {
45 if ( count($fileList) > 1 ) {
46 // Multiple files, zip them together
47 $zip = new ZipArchive;
48 $currentTime = date("Y-m-d-H-i-s");
49 global $qrda_file_path;
50 $finalZip = $qrda_file_path . "QRDA_2014_1_" . $currentTime . ".zip";
51 if ($zip->open($finalZip, ZIPARCHIVE::CREATE) != TRUE) {
52 echo xlt("FAILURE: Couldn't create the zip");
54 foreach ( $fileList as $eachFile ) {
55 check_file_dir_name($eachFile);
56 $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);
99 foreach ( $patients as $patient ) {
100 $xml = new QRDAXml();
101 $fileName = mainQrdaCatOneGenerate($xml, $patient, $ruleID, $provider_id);
102 $files[] = $fileName;
104 if ($zip->open($zipFileFullPath, ZIPARCHIVE::CREATE) != TRUE) {
105 echo xlt("FAILURE: Couldn't create the zip");
107 foreach ( $files as $eachFile ) {
108 $filePath = $qrda_file_path . $eachFile;
109 $zip->addFile($filePath,$eachFile);
111 $zip->close();
112 //Deleting the files after closing the zip
113 foreach ( $files as $eachFile ) {
114 $filePath = $qrda_file_path . $eachFile;
115 unlink($filePath);
117 echo $zipFile;
118 } else
119 echo xlt("FAILURE: No patients for measure") . " " . text($ruleID);