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