Implement new security model in LBF forms.
[openemr.git] / custom / export_registry_xml.php
blob39dab49f301fe456791aee40ae1fb6b10fdac2e5
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.
11 //SANITIZE ALL ESCAPES
12 $sanitize_all_escapes=true;
15 //STOP FAKE REGISTER GLOBALS
16 $fake_register_globals=false;
20 require_once("../interface/globals.php");
21 require_once("../library/patient.inc");
22 require_once "../library/options.inc.php";
23 require_once("../library/clinical_rules.php");
24 require_once("../library/classes/PQRIXml.class.php");
26 //To improve performance and not freeze the session when running this
27 // report, turn off session writing. Note that php session variables
28 // can not be modified after the line below. So, if need to do any php
29 // session work in the future, then will need to remove this line.
30 session_write_close();
32 //Remove time limit, since script can take many minutes
33 set_time_limit(0);
35 // Set the "nice" level of the process for these reports. When the "nice" level
36 // is increased, these cpu intensive reports will have less affect on the performance
37 // of other server activities, albeit it may negatively impact the performance
38 // of this report (note this is only applicable for linux).
39 if (!empty($GLOBALS['cdr_report_nice'])) {
40 proc_nice($GLOBALS['cdr_report_nice']);
43 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";
62 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'];
67 if (!empty($row['cqm_nqf_code'])) {
68 return $row['cqm_nqf_code'];
71 else
73 return "";
78 // Collect parameters (set defaults if empty)
79 $target_date = (isset($_GET['target_date'])) ? trim($_GET['target_date']) : date('Y-m-d H:i:s');
80 $nested = (isset($_GET['nested'])) ? trim($_GET['nested']) : 'false';
81 $xml = new PQRIXml();
83 // Add the XML parent tag.
84 $xml->open_submission();
86 // Add the file audit data
87 $xml->add_file_audit_data();
89 // Add the registry entries
90 if ( $nested == 'false') {
91 $xml->add_registry('A');
93 else {
94 $xml->add_registry('E');
98 // Add the measure groups.
99 if ( $nested == 'false' ) {
100 // Collect results (note using the batch method to decrease memory overhead and improve performance)
101 $dataSheet = test_rules_clinic_batch_method('collate_outer','cqm',$target_date,'report','','');
103 else {
104 // Collect results (note using the batch method to decrease memory overhead and improve performance)
105 $dataSheet = test_rules_clinic_batch_method('collate_inner','cqm',$target_date,'report','cqm','plans');
108 $firstProviderFlag = TRUE;
109 $firstPlanFlag = TRUE;
110 $existProvider = FALSE;
112 if ( $nested == 'false' ){
113 $xml->open_measure_group('X');
116 foreach ($dataSheet as $row) {
117 //print_r($row);
118 if (isset($row['is_main']) || isset($row['is_sub'])) {
119 if (isset($row['is_main'])) {
120 // Add PQRI measures
121 $pqri_measures = array();
122 $pqri_measures['pqri-measure-number'] = getMeasureNumber($row);
123 $pqri_measures['patient-population'] = getLabelNumber($row['population_label']);
124 $pqri_measures['numerator'] = getLabelNumber($row['numerator_label']);
125 $pqri_measures['eligible-instances'] = $row['pass_filter'];
126 $pqri_measures['meets-performance-instances'] = $row['pass_target'];
127 $pqri_measures['performance-exclusion-instances'] = $row['excluded'];
128 $performance_not_met_instances = (int)$row['pass_filter'] - (int)$row['pass_target'] - (int)$row['excluded'];
129 $pqri_measures['performance-not-met-instances'] = (string)$performance_not_met_instances;
130 $pqri_measures['performance-rate'] = $row['percentage'];
131 $pqri_measures['reporting-rate'] = (($row['pass_filter']-$row['excluded'])/$row['pass_filter'])*100;
132 $pqri_measures['reporting-rate']=$pqri_measures['reporting-rate'].'%';
133 $xml->add_pqri_measures($pqri_measures);
135 else { // $row[0] == "sub"
139 else if (isset($row['is_provider'])) {
140 if ( $firstProviderFlag == FALSE ){
141 $xml->close_provider();
143 // Add the provider
144 $physician_ids = array();
145 if (!empty($row['npi']) || !empty($row['federaltaxid'])) {
146 if (!empty($row['npi'])) {
147 $physician_ids['npi'] = $row['npi'];
149 if (!empty($row['federaltaxid'])) {
150 $physician_ids['tin'] = $row['federaltaxid'];
153 $physician_ids['encounter-from-date'] = '01-01-' . date('Y', strtotime($target_date ));
154 $physician_ids['encounter-to-date'] = '12-31-' . date('Y', strtotime($target_date ));
156 $xml->open_provider($physician_ids);
157 $firstProviderFlag = FALSE;
158 $existProvider = TRUE;
160 else { // isset($row['is_plan'])
162 if ( $firstPlanFlag == FALSE ) {
163 if ( $firstProviderFlag == FALSE ) {
164 $xml->close_provider();
166 if ( $nested == 'true' ) {
167 $xml->close_measure_group();
171 if ( $nested == 'true' ){
172 $xml->open_measure_group($row['cqm_measure_group']);
174 $firstPlanFlag = FALSE;
175 $firstProviderFlag = TRUE; // Reset the provider flag
180 if ( $existProvider == TRUE ){
181 $xml->close_provider();
182 $xml->close_measure_group();
185 $xml->close_submission();
189 <html>
190 <head>
191 <?php html_header_show();?>
192 <link rel=stylesheet href="<?php echo $css_header;?>" type="text/css">
193 <title><?php echo htmlspecialchars( xl('Export PQRI Report'), ENT_NOQUOTES); ?></title>
194 </head>
195 <body>
197 <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>
199 <center>
200 <form>
202 <textarea rows='50' cols='500' style='width:95%' readonly>
203 <?php echo $xml->getXml(); ?>
204 </textarea>
206 <p><input type='button' value='<?php echo htmlspecialchars( xl('OK'), ENT_QUOTES); ?>' onclick='window.close()' /></p>
207 </form>
208 </center>
210 </body>
211 </html>