weno drug sql import fails window (#2470)
[openemr.git] / custom / download_qrda.php
blob13ee4415190fab6873bfd940d636572c30c2e857
1 <?php
2 /**
3 * QRDA Download
5 * @package OpenEMR
6 * @link http://www.open-emr.org
7 * @author Ensoftek
8 * @author Brady Miller <brady.g.miller@gmail.com>
9 * @copyright Copyright (c) 2015 Ensoftek, Inc
10 * @copyright Copyright (c) 2018 Brady Miller <brady.g.miller@gmail.com>
11 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
15 require_once("../interface/globals.php");
16 require_once "$srcdir/report_database.inc";
17 require_once("$srcdir/options.inc.php");
18 require_once("qrda_category1.inc");
20 use OpenEMR\Core\Header;
22 if (!verifyCsrfToken($_GET["csrf_token_form"])) {
23 csrfNotVerified();
26 $report_id = (isset($_GET['report_id'])) ? trim($_GET['report_id']) : "";
27 $provider_id = (isset($_GET['provider_id'])) ? trim($_GET['provider_id']) : "";
29 $report_view = collectReportDatabase($report_id);
30 $dataSheet = json_decode($report_view['data'], true);
31 $type_report = $report_view['type'];
32 $type_report = (($type_report == "amc") || ($type_report == "amc_2011") || ($type_report == "amc_2014") ||
33 ($type_report == "cqm") || ($type_report == "cqm_2011") || ($type_report == "cqm_2014")) ? $type_report : "standard";
36 <html>
38 <head>
39 <?php Header::setupHeader(['no_bootstrap', 'no_fontawesome', 'common', 'opener', 'jquery-ui']); ?>
41 <script language="JavaScript">
42 var reportID = <?php echo js_escape($report_id); ?>;
43 var provider_id = <?php echo js_escape($provider_id);?>;
44 var zipFileArray = new Array();
45 var failureMessage = "";
46 $(function(){
47 $("#checkAll").on("change", function() {
48 var checked = ( $("#checkAll").prop("checked") ) ? true : false;
49 $("#thisForm input:checkbox").each(function() {
50 $(this).prop("checked", checked);
51 });
52 });
53 });
55 function downloadSelected() {
56 zipFileArray.length = 0;
57 var criteriaArray = new Array();
58 $("#thisForm input:checkbox:checked").each(function() {
59 if ( $(this).attr("id") == "checkAll")
60 return;
61 criteriaArray.push($(this).attr("id"));
62 });
63 if ( criteriaArray.length == 0 ) {
64 alert(<?php echo xlj('Please select at least one criteria to download');?>);
65 return false;
67 for( var i=0 ; i < criteriaArray.length ; i++) {
68 var checkBoxCounterArray = criteriaArray[i].split("check");
69 var ruleID = $("#text" + checkBoxCounterArray[1]).val();
70 //console.log(ruleID);
71 var lastOne = ( ( i + 1 ) == criteriaArray.length ) ? 1 : 0;
72 downloadXML(checkBoxCounterArray[1],lastOne,ruleID);
76 function downloadXML(counter,lastOne) {
77 $("#download" + counter).css("display","none");
78 $("#spin" + counter).css("display","inline");
79 $.ajax({
80 type : "POST",
81 url: "ajax_download.php",
82 data : {
83 reportID: reportID,
84 counter: counter,
85 ruleID: $("#text" + counter).val(),
86 provider_id: provider_id,
87 csrf_token_form: <?php echo js_escape(collectCsrfToken()); ?>
89 context: document.body,
90 success :
91 function(data){
92 // Check if download is complete
93 var status = data.substr(0, 8);
94 if ( status == "FAILURE:") {
95 data = data.substr(8);
96 //console.log(data);
97 failureMessage += data + "\n";
98 } else {
99 zipFileArray.push(data);
100 $("#checkmark" + counter).css("display","inline");
102 $("#download" + counter).css("display","inline");
103 $("#spin" + counter).css("display","none");
104 if ( lastOne == 1 ) {
105 if ( zipFileArray.length ) {
106 var zipFiles = zipFileArray.join(",");
107 //console.log(zipFiles);
108 window.location = 'ajax_download.php?fileName=' + encodeURIComponent(zipFiles) + '&csrf_token_form=' + <?php echo js_url(collectCsrfToken()); ?>;
109 zipFileArray.length = 0;
111 if ( failureMessage ) {
112 console.log(failureMessage);
113 alert(failureMessage);
115 failureMessage = "";
121 function closeMe() {
122 window.close();
124 </script>
125 <style>
126 .downloadIcon:hover {
127 cursor: hand;
129 .multiDownload {
132 </style>
133 </head>
135 <body class="body_top">
136 <form id="thisForm" name="thisForm">
137 <table>
138 <tr>
139 <td><span class="title"><?php echo xlt("Generate/Download QRDA I - 2014"); ?>&nbsp;</span></td>
140 <td>
141 <a class="css_button multiDownload" href="#" onclick="downloadSelected();"><span><?php echo xlt("Download"); ?></span></a>
142 <a class="css_button" href="#" onclick="closeMe();"><span><?php echo xlt("Close"); ?></span></a>
143 </td>
144 </tr>
145 </table>
146 <br/>
147 <div id="report_results" style="width:95%">
148 <table class="oemr_list text">
149 <thead>
150 <th scope="col" class="multiDownload">
151 <input type="checkbox" name="checkAll" id="checkAll"/>
152 <div style="display:none" id=downloadAll>
153 <img class="downloadIcon" src="<?php echo $GLOBALS['images_static_relative'];?>/downbtn.gif" onclick=downloadAllXML(); />
154 </div>
155 <div style="display:none" id=spinAll>;
156 <img src="<?php echo $GLOBALS['webroot'];?>/interface/pic/ajax-loader.gif"/>
157 </div>
158 </th>
159 <th scope="col">
160 <?php echo xlt('Title'); ?>
161 </th>
163 <th scope="col">
164 <?php echo xlt('Download'); ?>
165 </th>
166 <th scope="col">&nbsp;&nbsp;&nbsp;</th>
167 </thead>
168 <tbody>
169 <?php
170 $counter = 0;
171 foreach ($dataSheet as $row) {
172 if (isset($row['is_main']) || isset($row['is_sub'])) {
173 if (count($cqmCodes) && in_array($row['cqm_nqf_code'], $cqmCodes)) {
174 continue;
177 echo "<tr>";
178 $cqmCodes[] = $row['cqm_nqf_code'];
179 echo "<td class=multiDownload>";
180 echo "<input id=check" . attr($counter) . " type=checkbox />";
181 echo "</td>";
182 echo "<td class='detail'>";
183 if (isset($row['is_main'])) {
184 echo "<b>".generate_display_field(array('data_type'=>'1','list_id'=>'clinical_rules'), $row['id'])."</b>";
185 $tempCqmAmcString = "";
186 if (($type_report == "cqm") || ($type_report == "cqm_2011") || ($type_report == "cqm_2014")) {
187 if (!empty($row['cqm_pqri_code'])) {
188 $tempCqmAmcString .= " " . xl('PQRI') . ":" . $row['cqm_pqri_code'] . " ";
191 if (!empty($row['cqm_nqf_code'])) {
192 $tempCqmAmcString .= " " . xl('NQF') . ":" . $row['cqm_nqf_code'] . " ";
196 if (!empty($tempCqmAmcString)) {
197 echo "(".text($tempCqmAmcString).")";
199 } else {
200 echo generate_display_field(array('data_type'=>'1','list_id'=>'rule_action_category'), $row['action_category']);
201 echo ": " . generate_display_field(array('data_type'=>'1','list_id'=>'rule_action'), $row['action_item']);
204 echo "<input type=hidden id=text" . attr($counter) . " name=text" . attr($counter) . " value='" . attr($row['cqm_nqf_code']) . "'/>";
205 echo "</td>";
206 echo "<td align=center>";
207 echo "<div id=download" . attr($counter) . ">";
208 echo "<img class='downloadIcon' src='" . $GLOBALS['images_static_relative'] . "/downbtn.gif' onclick=downloadXML(" . attr_js($counter) . ",1); />";
209 echo "</div>";
210 echo "<div style='display:none' id=spin" . attr($counter) . ">";
211 echo "<img src='" . $GLOBALS['webroot'] . "/interface/pic/ajax-loader.gif'/>";
212 echo "</div>";
213 echo "</td>";
214 echo "<td>";
215 echo "<div style='display:none' id=checkmark" . attr($counter) . ">";
216 echo "<img src='" . $GLOBALS['images_static_relative'] . "/checkmark.png' />";
217 echo "</div>";
218 echo "</td>";
219 echo "</tr>";
220 $counter++;
222 } ?>
223 </tbody>
224 </table>
225 </div>
227 </form>
228 </body>
229 </html>