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