Improved Code Sniffing (#928)
[openemr.git] / custom / export_registry_xml.php
blob5cce66700ebc42cf5b7afd1a12f4eb78f7fdcf1e
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 //To improve performance and not freeze the session when running this
21 // report, turn off session writing. Note that php session variables
22 // can not be modified after the line below. So, if need to do any php
23 // session work in the future, then will need to remove this line.
24 session_write_close();
26 //Remove time limit, since script can take many minutes
27 set_time_limit(0);
29 // Set the "nice" level of the process for these reports. When the "nice" level
30 // is increased, these cpu intensive reports will have less affect on the performance
31 // of other server activities, albeit it may negatively impact the performance
32 // of this report (note this is only applicable for linux).
33 if (!empty($GLOBALS['cdr_report_nice'])) {
34 proc_nice($GLOBALS['cdr_report_nice']);
37 function getLabelNumber($label)
40 if ( strlen($label) == 0) {
41 return "1";
44 $tokens = explode(" ", $label);
46 $num_tokens = sizeof($tokens);
47 if ( $tokens[$num_tokens-1] != null ) {
48 if ( is_numeric($tokens[$num_tokens-1])) {
49 return $tokens[$num_tokens-1];
53 return "1";
57 function getMeasureNumber($row)
59 if (!empty($row['cqm_pqri_code']) || !empty($row['cqm_nqf_code']) ) {
60 if (!empty($row['cqm_pqri_code'])) {
61 return $row['cqm_pqri_code'];
63 if (!empty($row['cqm_nqf_code'])) {
64 return $row['cqm_nqf_code'];
67 else
69 return "";
74 // Collect parameters (set defaults if empty)
75 $target_date = (isset($_GET['target_date'])) ? trim($_GET['target_date']) : date('Y-m-d H:i:s');
76 $nested = (isset($_GET['nested'])) ? trim($_GET['nested']) : 'false';
77 $xml = new PQRIXml();
79 // Add the XML parent tag.
80 $xml->open_submission();
82 // Add the file audit data
83 $xml->add_file_audit_data();
85 // Add the registry entries
86 if ( $nested == 'false') {
87 $xml->add_registry('A');
89 else {
90 $xml->add_registry('E');
94 // Add the measure groups.
95 if ( $nested == 'false' ) {
96 // Collect results (note using the batch method to decrease memory overhead and improve performance)
97 $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);
131 else { // $row[0] == "sub"
135 else if (isset($row['is_provider'])) {
136 if ( $firstProviderFlag == false ){
137 $xml->close_provider();
139 // Add the provider
140 $physician_ids = array();
141 if (!empty($row['npi']) || !empty($row['federaltaxid'])) {
142 if (!empty($row['npi'])) {
143 $physician_ids['npi'] = $row['npi'];
145 if (!empty($row['federaltaxid'])) {
146 $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;
156 else { // isset($row['is_plan'])
158 if ( $firstPlanFlag == false ) {
159 if ( $firstProviderFlag == false ) {
160 $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']);
170 $firstPlanFlag = false;
171 $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 htmlspecialchars( xl('Export PQRI Report'), ENT_NOQUOTES); ?></title>
191 </head>
192 <body>
194 <p><?php echo htmlspecialchars( xl('The exported data appears in the text area below. You can copy and paste this into an email or to any other desired destination.'), ENT_NOQUOTES); ?></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 htmlspecialchars( xl('OK'), ENT_QUOTES); ?>' onclick='window.close()' /></p>
204 </form>
205 </center>
207 </body>
208 </html>