updates to make oauth2/api compatible with php8 (#4069)
[openemr.git] / custom / ajax_download.php
bloba5a0c84cc35485c80df8433bb134990324090721
1 <?php
3 /**
5 * QRDA Ajax Download
7 * @package OpenEMR
8 * @link https://www.open-emr.org
9 * @author Ensoftek
10 * @author Stephen Waite <stephen.waite@cmsvt.com
11 * @copyright Copyright (c) 2015 Ensoftek, Inc
12 * @copyright Copyright (c) 2019 Stephen Waite <stephen.waite@cmsvt.com>
13 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
16 require_once("../interface/globals.php");
17 require_once("$srcdir/report_database.inc");
18 require_once("../ccr/uuid.php");
19 require_once("qrda_category1_functions.php");
20 require_once("qrda_category1.inc");
21 require_once("qrda_functions.php");
23 use OpenEMR\Common\Csrf\CsrfUtils;
25 if (!CsrfUtils::verifyCsrfToken($_REQUEST["csrf_token_form"])) {
26 CsrfUtils::csrfNotVerified();
29 $reportID = $_POST['reportID'];
30 $ruleID = $_POST['ruleID'];
31 $counter = $_POST['counter'];
32 $fileName = ( isset($_GET['fileName']) ) ? $_GET['fileName'] : "";
33 $provider_id = $_POST['provider_id'];
35 if ($fileName) {
36 $fileList = explode(",", $fileName);
37 //if ( strpos($fileName,",") !== FALSE ) {
38 if (count($fileList) > 1) {
39 // Multiple files, zip them together
40 $zip = new ZipArchive();
41 $currentTime = date("Y-m-d-H-i-s");
42 global $qrda_file_path;
43 $finalZip = $qrda_file_path . "QRDA_2014_1_" . $currentTime . ".zip";
44 if ($zip->open($finalZip, ZipArchive::CREATE) != true) {
45 echo xlt("FAILURE: Couldn't create the zip");
48 foreach ($fileList as $eachFile) {
49 check_file_dir_name($eachFile);
50 $zip->addFile($qrda_file_path . $eachFile, $eachFile);
53 $zip->close();
54 foreach ($fileList as $eachFile) {
55 unlink($qrda_file_path . $eachFile);
57 } else {
58 check_file_dir_name($fileList[0]);
59 $finalZip = $qrda_file_path . $fileList[0];
62 header("Pragma: public");
63 header("Expires: 0");
64 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
65 header("Content-Type: application/force-download");
66 header("Content-Length: " . filesize($finalZip));
67 header("Content-Disposition: attachment; filename=" . basename($finalZip) . ";");
68 header("Content-Description: File Transfer");
69 readfile($finalZip);
70 unlink($finalZip);
71 exit(0);
74 $report_view = collectReportDatabase($reportID);
75 $dataSheet = json_decode($report_view['data'], true);
76 $target_date = $report_view['date_target'];
78 $criteriaPatients = getCombinePatients($dataSheet, $reportID);
79 $patients = $criteriaPatients[$ruleID];
81 //var_dump($dataSheet);
83 $from_date = date('Y', strtotime($target_date)) . "-01-01";
84 $to_date = date('Y', strtotime($target_date)) . "-12-31";
86 if (count($patients)) {
87 $zip = new ZipArchive();
88 global $qrda_file_path;
89 $currentTime = date("Y-m-d-H-i-s");
90 $zipFile = $reportID . "_NQF_" . $ruleID . "_" . $currentTime . ".zip";
91 $zipFileFullPath = $qrda_file_path . $zipFile;
92 if (file_exists($zipFileFullPath)) {
93 unlink($zipFileFullPath);
96 foreach ($patients as $patient) {
97 $xml = new QRDAXml($ruleID);
98 $fileName = mainQrdaCatOneGenerate($xml, $patient, $ruleID, $provider_id);
99 $files[] = $fileName;
102 if ($zip->open($zipFileFullPath, ZipArchive::CREATE) != true) {
103 echo xlt("FAILURE: Couldn't create the zip");
106 foreach ($files as $eachFile) {
107 $filePath = $qrda_file_path . $eachFile;
108 $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);
118 echo $zipFile;
119 } else {
120 echo xlt("FAILURE: No patients for measure") . " " . text($ruleID);