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