Adding the ability to delete a drug from patient chart (#3520)
[openemr.git] / custom / export_registry_xml.php
blob38dd3d65cda0998f0dc3cdfffdc7a82b07b8e3ff
1 <?php
3 // Copyright (C) 2011 Ensoftek
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program exports report to PQRI 2009 XML format.
13 require_once("../interface/globals.php");
14 require_once("../library/patient.inc");
15 require_once "../library/options.inc.php";
16 require_once("../library/clinical_rules.php");
18 use OpenEMR\Common\Csrf\CsrfUtils;
19 use OpenEMR\Core\Header;
21 if (!CsrfUtils::verifyCsrfToken($_GET["csrf_token_form"])) {
22 CsrfUtils::csrfNotVerified();
25 //To improve performance and not freeze the session when running this
26 // report, turn off session writing. Note that php session variables
27 // can not be modified after the line below. So, if need to do any php
28 // session work in the future, then will need to remove this line.
29 session_write_close();
31 //Remove time limit, since script can take many minutes
32 set_time_limit(0);
34 // Set the "nice" level of the process for these reports. When the "nice" level
35 // is increased, these cpu intensive reports will have less affect on the performance
36 // of other server activities, albeit it may negatively impact the performance
37 // of this report (note this is only applicable for linux).
38 if (!empty($GLOBALS['cdr_report_nice'])) {
39 proc_nice($GLOBALS['cdr_report_nice']);
42 function getLabelNumber($label)
45 if (strlen($label) == 0) {
46 return "1";
49 $tokens = explode(" ", $label);
51 $num_tokens = sizeof($tokens);
52 if ($tokens[$num_tokens - 1] != null) {
53 if (is_numeric($tokens[$num_tokens - 1])) {
54 return $tokens[$num_tokens - 1];
58 return "1";
61 function getMeasureNumber($row)
63 if (!empty($row['cqm_pqri_code']) || !empty($row['cqm_nqf_code'])) {
64 if (!empty($row['cqm_pqri_code'])) {
65 return $row['cqm_pqri_code'];
68 if (!empty($row['cqm_nqf_code'])) {
69 return $row['cqm_nqf_code'];
71 } else {
72 return "";
77 // Collect parameters (set defaults if empty)
78 $target_date = (isset($_GET['target_date'])) ? trim($_GET['target_date']) : date('Y-m-d H:i:s');
79 $nested = (isset($_GET['nested'])) ? trim($_GET['nested']) : 'false';
80 $xml = new PQRIXml();
82 // Add the XML parent tag.
83 $xml->open_submission();
85 // Add the file audit data
86 $xml->add_file_audit_data();
88 // Add the registry entries
89 if ($nested == 'false') {
90 $xml->add_registry('A');
91 } else {
92 $xml->add_registry('E');
96 // Add the measure groups.
97 if ($nested == 'false') {
98 // Collect results (note using the batch method to decrease memory overhead and improve performance)
99 $dataSheet = test_rules_clinic_batch_method('collate_outer', 'cqm_2011', $target_date, 'report', '', '');
100 } else {
101 // Collect results (note using the batch method to decrease memory overhead and improve performance)
102 $dataSheet = test_rules_clinic_batch_method('collate_inner', 'cqm_2011', $target_date, 'report', 'cqm', 'plans');
105 $firstProviderFlag = true;
106 $firstPlanFlag = true;
107 $existProvider = false;
109 if ($nested == 'false') {
110 $xml->open_measure_group('X');
113 foreach ($dataSheet as $row) {
114 //print_r($row);
115 if (isset($row['is_main']) || isset($row['is_sub'])) {
116 if (isset($row['is_main'])) {
117 // Add PQRI measures
118 $pqri_measures = array();
119 $pqri_measures['pqri-measure-number'] = getMeasureNumber($row);
120 $pqri_measures['patient-population'] = getLabelNumber($row['population_label']);
121 $pqri_measures['numerator'] = getLabelNumber($row['numerator_label']);
122 $pqri_measures['eligible-instances'] = $row['pass_filter'];
123 $pqri_measures['meets-performance-instances'] = $row['pass_target'];
124 $pqri_measures['performance-exclusion-instances'] = $row['excluded'];
125 $performance_not_met_instances = (int)$row['pass_filter'] - (int)$row['pass_target'] - (int)$row['excluded'];
126 $pqri_measures['performance-not-met-instances'] = (string)$performance_not_met_instances;
127 $pqri_measures['performance-rate'] = $row['percentage'];
128 $pqri_measures['reporting-rate'] = (($row['pass_filter'] - $row['excluded']) / $row['pass_filter']) * 100;
129 $pqri_measures['reporting-rate'] = $pqri_measures['reporting-rate'] . '%';
130 $xml->add_pqri_measures($pqri_measures);
131 } else { // $row[0] == "sub"
133 } elseif (isset($row['is_provider'])) {
134 if ($firstProviderFlag == false) {
135 $xml->close_provider();
138 // Add the provider
139 $physician_ids = array();
140 if (!empty($row['npi']) || !empty($row['federaltaxid'])) {
141 if (!empty($row['npi'])) {
142 $physician_ids['npi'] = $row['npi'];
145 if (!empty($row['federaltaxid'])) {
146 $physician_ids['tin'] = $row['federaltaxid'];
150 $physician_ids['encounter-from-date'] = '01-01-' . date('Y', strtotime($target_date));
151 $physician_ids['encounter-to-date'] = '12-31-' . date('Y', strtotime($target_date));
153 $xml->open_provider($physician_ids);
154 $firstProviderFlag = false;
155 $existProvider = true;
156 } else { // isset($row['is_plan'])
157 if ($firstPlanFlag == false) {
158 if ($firstProviderFlag == false) {
159 $xml->close_provider();
162 if ($nested == 'true') {
163 $xml->close_measure_group();
167 if ($nested == 'true') {
168 $xml->open_measure_group($row['cqm_measure_group']);
171 $firstPlanFlag = false;
172 $firstProviderFlag = true; // Reset the provider flag
176 if ($existProvider == true) {
177 $xml->close_provider();
178 $xml->close_measure_group();
181 $xml->close_submission();
185 <html>
186 <head>
187 <?php Header::setupHeader('opener'); ?>
188 <title><?php echo xlt('Export PQRI Report'); ?></title>
189 </head>
190 <body>
192 <p><?php echo xlt('The exported data appears in the text area below. You can copy and paste this into an email or to any other desired destination.'); ?></p>
194 <center>
195 <form>
197 <textarea rows='50' cols='500' style='width:95%' readonly>
198 <?php echo $xml->getXml(); ?>
199 </textarea>
201 <p><input type='button' value='<?php echo xla('OK'); ?>' onclick='window.close()' /></p>
202 </form>
203 </center>
205 </body>
206 </html>