bug fix march continued (#1921)
[openemr.git] / custom / download_qrda.php
bloba15fa7c52563229c74db73aa0d65b0729210d56a
1 <?php
2 /**
4 * QRDA 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
28 require_once("../interface/globals.php");
29 require_once "$srcdir/report_database.inc";
30 require_once("$srcdir/options.inc.php");
31 require_once("qrda_category1.inc");
33 if (!verifyCsrfToken($_GET["csrf_token_form"])) {
34 csrfNotVerified();
37 $report_id = (isset($_GET['report_id'])) ? trim($_GET['report_id']) : "";
38 $provider_id = (isset($_GET['provider_id'])) ? trim($_GET['provider_id']) : "";
40 $report_view = collectReportDatabase($report_id);
41 $dataSheet = json_decode($report_view['data'], true);
42 $type_report = $report_view['type'];
43 $type_report = (($type_report == "amc") || ($type_report == "amc_2011") || ($type_report == "amc_2014") ||
44 ($type_report == "cqm") || ($type_report == "cqm_2011") || ($type_report == "cqm_2014")) ? $type_report : "standard";
48 <html>
50 <head>
51 <?php html_header_show();?>
53 <link rel="stylesheet" href="<?php echo $css_header;?>" type="text/css">
54 <script type="text/javascript" src="<?php echo $webroot ?>/interface/main/tabs/js/include_opener.js"></script>
55 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/textformat.js"></script>
56 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/dialog.js?v=<?php echo $v_js_includes; ?>"></script>
57 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-1-4-3/jquery.js"></script>
58 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/jquery-ui-1.8.5.custom.min.js"></script>
59 <script type="text/javascript" src="<?php echo $GLOBALS['webroot'] ?>/library/js/common.js"></script>
60 <script language="JavaScript">
61 var reportID = '<?php echo attr($report_id); ?>';
62 var provider_id = '<?php echo attr($provider_id);?>';
63 var zipFileArray = new Array();
64 var failureMessage = "";
65 $(document).ready(function(){
66 $("#checkAll").change(function() {
67 var checked = ( $("#checkAll").attr("checked") ) ? true : false;
68 $("#thisForm input:checkbox").each(function() {
69 $(this).attr("checked", checked);
70 });
71 });
72 });
74 function downloadSelected() {
75 zipFileArray.length = 0;
76 var criteriaArray = new Array();
77 $("#thisForm input:checkbox:checked").each(function() {
78 if ( $(this).attr("id") == "checkAll")
79 return;
80 criteriaArray.push($(this).attr("id"));
81 });
82 if ( criteriaArray.length == 0 ) {
83 alert("<?php echo xls('Please select at least one criteria to download');?>");
84 return false;
86 for( var i=0 ; i < criteriaArray.length ; i++) {
87 var checkBoxCounterArray = criteriaArray[i].split("check");
88 var ruleID = $("#text" + checkBoxCounterArray[1]).val();
89 //console.log(ruleID);
90 var lastOne = ( ( i + 1 ) == criteriaArray.length ) ? 1 : 0;
91 downloadXML(checkBoxCounterArray[1],lastOne,ruleID);
95 function downloadXML(counter,lastOne) {
96 $("#download" + counter).css("display","none");
97 $("#spin" + counter).css("display","inline");
98 $.ajax({
99 type : "POST",
100 url: "ajax_download.php",
101 data : {
102 reportID: reportID,
103 counter: counter,
104 ruleID: $("#text" + counter).val(),
105 provider_id: provider_id,
106 csrf_token_form: '<?php echo attr(collectCsrfToken()); ?>'
108 context: document.body,
109 success :
110 function(data){
111 // Check if download is complete
112 var status = data.substr(0, 8);
113 if ( status == "FAILURE:") {
114 data = data.substr(8);
115 //console.log(data);
116 failureMessage += data + "\n";
117 } else {
118 zipFileArray.push(data);
119 $("#checkmark" + counter).css("display","inline");
121 $("#download" + counter).css("display","inline");
122 $("#spin" + counter).css("display","none");
123 if ( lastOne == 1 ) {
124 if ( zipFileArray.length ) {
125 var zipFiles = zipFileArray.join(",");
126 //console.log(zipFiles);
127 window.location = 'ajax_download.php?fileName=' + encodeURIComponent(zipFiles) + '&csrf_token_form=' + '<?php echo attr(urlencode($_SESSION['csrf_token'])); ?>';
128 zipFileArray.length = 0;
130 if ( failureMessage ) {
131 console.log(failureMessage);
132 alert(failureMessage);
134 failureMessage = "";
140 function closeMe() {
141 window.close();
143 </script>
144 <style>
145 .downloadIcon:hover {
146 cursor: hand;
148 .multiDownload {
151 </style>
152 </head>
154 <body class="body_top">
155 <form id="thisForm" name="thisForm">
156 <table>
157 <tr>
158 <td><span class="title"><?php echo xlt("Generate/Download QRDA I - 2014"); ?>&nbsp;</span></td>
159 <td>
160 <a class="css_button multiDownload" href="#" onclick="downloadSelected();"><span><?php echo xlt("Download"); ?></span></a>
161 <a class="css_button" href="#" onclick="closeMe();"><span><?php echo xlt("Close"); ?></span></a>
162 </td>
163 </tr>
164 </table>
165 <br/>
166 <div id="report_results" style="width:95%">
167 <table class="oemr_list text">
168 <thead>
169 <th scope="col" class="multiDownload">
170 <input type="checkbox" name="checkAll" id="checkAll"/>
171 <div style="display:none" id=downloadAll>
172 <img class='downloadIcon' src='<?php echo $GLOBALS['webroot'];?>/images/downbtn.gif' onclick=downloadAllXML(); />
173 </div>
174 <div style='display:none' id=spinAll>;
175 <img src='<?php echo $GLOBALS['webroot'];?>/interface/pic/ajax-loader.gif'/>
176 </div>
177 </th>
178 <th scope="col">
179 <?php echo xlt('Title'); ?>
180 </th>
182 <th scope="col">
183 <?php echo xlt('Download'); ?>
184 </th>
185 <th scope="col">&nbsp;&nbsp;&nbsp;</th>
186 </thead>
187 <tbody>
188 <?php
189 $counter = 0;
190 foreach ($dataSheet as $row) {
191 if (isset($row['is_main']) || isset($row['is_sub'])) {
192 if (count($cqmCodes) && in_array($row['cqm_nqf_code'], $cqmCodes)) {
193 continue;
196 echo "<tr>";
197 $cqmCodes[] = $row['cqm_nqf_code'];
198 echo "<td class=multiDownload>";
199 echo "<input id=check" . attr($counter) . " type=checkbox />";
200 echo "</td>";
201 echo "<td class='detail'>";
202 if (isset($row['is_main'])) {
203 echo "<b>".generate_display_field(array('data_type'=>'1','list_id'=>'clinical_rules'), $row['id'])."</b>";
204 $tempCqmAmcString = "";
205 if (($type_report == "cqm") || ($type_report == "cqm_2011") || ($type_report == "cqm_2014")) {
206 if (!empty($row['cqm_pqri_code'])) {
207 $tempCqmAmcString .= " " . xl('PQRI') . ":" . $row['cqm_pqri_code'] . " ";
210 if (!empty($row['cqm_nqf_code'])) {
211 $tempCqmAmcString .= " " . xl('NQF') . ":" . $row['cqm_nqf_code'] . " ";
215 if (!empty($tempCqmAmcString)) {
216 echo "(".text($tempCqmAmcString).")";
218 } else {
219 echo generate_display_field(array('data_type'=>'1','list_id'=>'rule_action_category'), $row['action_category']);
220 echo ": " . generate_display_field(array('data_type'=>'1','list_id'=>'rule_action'), $row['action_item']);
223 echo "<input type=hidden id=text" . attr($counter) . " name=text" . attr($counter) . " value='" . attr($row['cqm_nqf_code']) . "'/>";
224 echo "</td>";
225 echo "<td align=center>";
226 echo "<div id=download" . attr($counter) . ">";
227 echo "<img class='downloadIcon' src='" . $GLOBALS['webroot'] . "/images/downbtn.gif' onclick=downloadXML(" . attr($counter) . ",1); />";
228 echo "</div>";
229 echo "<div style='display:none' id=spin" . attr($counter) . ">";
230 echo "<img src='" . $GLOBALS['webroot'] . "/interface/pic/ajax-loader.gif'/>";
231 echo "</div>";
232 echo "</td>";
233 echo "<td>";
234 echo "<div style='display:none' id=checkmark" . attr($counter) . ">";
235 echo "<img src='" . $GLOBALS['webroot'] . "/images/checkmark.png' />";
236 echo "</div>";
237 echo "</td>";
238 echo "</tr>";
239 $counter++;
241 } ?>
242 </tbody>
243 </table>
244 </div>
246 </form>
247 </body>
248 </html>