dump db version
[openemr.git] / custom / export_registry_xml.php
blob6f0876130db92b743be8620c568feb8c4fc15e5b
1 <?php
2 // Copyright (C) 2011 Ensoftek
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
9 // This program exports report to PQRI 2009 XML format.
15 require_once("../interface/globals.php");
16 require_once("../library/patient.inc");
17 require_once "../library/options.inc.php";
18 require_once("../library/clinical_rules.php");
20 if (!verifyCsrfToken($_GET["csrf_token_form"])) {
21 csrfNotVerified();
24 //To improve performance and not freeze the session when running this
25 // report, turn off session writing. Note that php session variables
26 // can not be modified after the line below. So, if need to do any php
27 // session work in the future, then will need to remove this line.
28 session_write_close();
30 //Remove time limit, since script can take many minutes
31 set_time_limit(0);
33 // Set the "nice" level of the process for these reports. When the "nice" level
34 // is increased, these cpu intensive reports will have less affect on the performance
35 // of other server activities, albeit it may negatively impact the performance
36 // of this report (note this is only applicable for linux).
37 if (!empty($GLOBALS['cdr_report_nice'])) {
38 proc_nice($GLOBALS['cdr_report_nice']);
41 function getLabelNumber($label)
44 if (strlen($label) == 0) {
45 return "1";
48 $tokens = explode(" ", $label);
50 $num_tokens = sizeof($tokens);
51 if ($tokens[$num_tokens-1] != null) {
52 if (is_numeric($tokens[$num_tokens-1])) {
53 return $tokens[$num_tokens-1];
57 return "1";
60 function getMeasureNumber($row)
62 if (!empty($row['cqm_pqri_code']) || !empty($row['cqm_nqf_code'])) {
63 if (!empty($row['cqm_pqri_code'])) {
64 return $row['cqm_pqri_code'];
67 if (!empty($row['cqm_nqf_code'])) {
68 return $row['cqm_nqf_code'];
70 } else {
71 return "";
76 // Collect parameters (set defaults if empty)
77 $target_date = (isset($_GET['target_date'])) ? trim($_GET['target_date']) : date('Y-m-d H:i:s');
78 $nested = (isset($_GET['nested'])) ? trim($_GET['nested']) : 'false';
79 $xml = new PQRIXml();
81 // Add the XML parent tag.
82 $xml->open_submission();
84 // Add the file audit data
85 $xml->add_file_audit_data();
87 // Add the registry entries
88 if ($nested == 'false') {
89 $xml->add_registry('A');
90 } else {
91 $xml->add_registry('E');
95 // Add the measure groups.
96 if ($nested == 'false') {
97 // Collect results (note using the batch method to decrease memory overhead and improve performance)
98 $dataSheet = test_rules_clinic_batch_method('collate_outer', 'cqm_2011', $target_date, 'report', '', '');
99 } else {
100 // Collect results (note using the batch method to decrease memory overhead and improve performance)
101 $dataSheet = test_rules_clinic_batch_method('collate_inner', 'cqm_2011', $target_date, 'report', 'cqm', 'plans');
104 $firstProviderFlag = true;
105 $firstPlanFlag = true;
106 $existProvider = false;
108 if ($nested == 'false') {
109 $xml->open_measure_group('X');
112 foreach ($dataSheet as $row) {
113 //print_r($row);
114 if (isset($row['is_main']) || isset($row['is_sub'])) {
115 if (isset($row['is_main'])) {
116 // Add PQRI measures
117 $pqri_measures = array();
118 $pqri_measures['pqri-measure-number'] = getMeasureNumber($row);
119 $pqri_measures['patient-population'] = getLabelNumber($row['population_label']);
120 $pqri_measures['numerator'] = getLabelNumber($row['numerator_label']);
121 $pqri_measures['eligible-instances'] = $row['pass_filter'];
122 $pqri_measures['meets-performance-instances'] = $row['pass_target'];
123 $pqri_measures['performance-exclusion-instances'] = $row['excluded'];
124 $performance_not_met_instances = (int)$row['pass_filter'] - (int)$row['pass_target'] - (int)$row['excluded'];
125 $pqri_measures['performance-not-met-instances'] = (string)$performance_not_met_instances;
126 $pqri_measures['performance-rate'] = $row['percentage'];
127 $pqri_measures['reporting-rate'] = (($row['pass_filter']-$row['excluded'])/$row['pass_filter'])*100;
128 $pqri_measures['reporting-rate']=$pqri_measures['reporting-rate'].'%';
129 $xml->add_pqri_measures($pqri_measures);
130 } else { // $row[0] == "sub"
132 } else if (isset($row['is_provider'])) {
133 if ($firstProviderFlag == false) {
134 $xml->close_provider();
137 // Add the provider
138 $physician_ids = array();
139 if (!empty($row['npi']) || !empty($row['federaltaxid'])) {
140 if (!empty($row['npi'])) {
141 $physician_ids['npi'] = $row['npi'];
144 if (!empty($row['federaltaxid'])) {
145 $physician_ids['tin'] = $row['federaltaxid'];
149 $physician_ids['encounter-from-date'] = '01-01-' . date('Y', strtotime($target_date));
150 $physician_ids['encounter-to-date'] = '12-31-' . date('Y', strtotime($target_date));
152 $xml->open_provider($physician_ids);
153 $firstProviderFlag = false;
154 $existProvider = true;
155 } 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 html_header_show();?>
188 <script type="text/javascript" src="<?php echo $webroot ?>/interface/main/tabs/js/include_opener.js"></script>
189 <link rel=stylesheet href="<?php echo $css_header;?>" type="text/css">
190 <title><?php echo xlt('Export PQRI Report'); ?></title>
191 </head>
192 <body>
194 <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>
196 <center>
197 <form>
199 <textarea rows='50' cols='500' style='width:95%' readonly>
200 <?php echo $xml->getXml(); ?>
201 </textarea>
203 <p><input type='button' value='<?php echo xla('OK'); ?>' onclick='window.close()' /></p>
204 </form>
205 </center>
207 </body>
208 </html>