3 // Copyright (C) 2011 Ensoftek
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 //Remove time limit, since script can take many minutes
28 // Set the "nice" level of the process for these reports. When the "nice" level
29 // is increased, these cpu intensive reports will have less affect on the performance
30 // of other server activities, albeit it may negatively impact the performance
31 // of this report (note this is only applicable for linux).
32 if (!empty($GLOBALS['cdr_report_nice'])) {
33 proc_nice($GLOBALS['cdr_report_nice']);
36 function getLabelNumber($label)
39 if (strlen($label) == 0) {
43 $tokens = explode(" ", $label);
45 $num_tokens = sizeof($tokens);
46 if ($tokens[$num_tokens - 1] != null) {
47 if (is_numeric($tokens[$num_tokens - 1])) {
48 return $tokens[$num_tokens - 1];
55 function getMeasureNumber($row)
57 if (!empty($row['cqm_pqri_code']) ||
!empty($row['cqm_nqf_code'])) {
58 if (!empty($row['cqm_pqri_code'])) {
59 return $row['cqm_pqri_code'];
62 if (!empty($row['cqm_nqf_code'])) {
63 return $row['cqm_nqf_code'];
71 // Collect parameters (set defaults if empty)
72 $target_date = (isset($_GET['target_date'])) ?
trim($_GET['target_date']) : date('Y-m-d H:i:s');
73 $nested = (isset($_GET['nested'])) ?
trim($_GET['nested']) : 'false';
76 // Add the XML parent tag.
77 $xml->open_submission();
79 // Add the file audit data
80 $xml->add_file_audit_data();
82 // Add the registry entries
83 if ($nested == 'false') {
84 $xml->add_registry('A');
86 $xml->add_registry('E');
90 // Add the measure groups.
91 if ($nested == 'false') {
92 // Collect results (note using the batch method to decrease memory overhead and improve performance)
93 $dataSheet = test_rules_clinic_batch_method('collate_outer', 'cqm_2011', $target_date, 'report', '', '');
95 // Collect results (note using the batch method to decrease memory overhead and improve performance)
96 $dataSheet = test_rules_clinic_batch_method('collate_inner', 'cqm_2011', $target_date, 'report', 'cqm', 'plans');
99 $firstProviderFlag = true;
100 $firstPlanFlag = true;
101 $existProvider = false;
103 if ($nested == 'false') {
104 $xml->open_measure_group('X');
107 foreach ($dataSheet as $row) {
109 if (isset($row['is_main']) ||
isset($row['is_sub'])) {
110 if (isset($row['is_main'])) {
112 $pqri_measures = array();
113 $pqri_measures['pqri-measure-number'] = getMeasureNumber($row);
114 $pqri_measures['patient-population'] = getLabelNumber($row['population_label']);
115 $pqri_measures['numerator'] = getLabelNumber($row['numerator_label']);
116 $pqri_measures['eligible-instances'] = $row['pass_filter'];
117 $pqri_measures['meets-performance-instances'] = $row['pass_target'];
118 $pqri_measures['performance-exclusion-instances'] = $row['excluded'];
119 $performance_not_met_instances = (int)$row['pass_filter'] - (int)$row['pass_target'] - (int)$row['excluded'];
120 $pqri_measures['performance-not-met-instances'] = (string)$performance_not_met_instances;
121 $pqri_measures['performance-rate'] = $row['percentage'];
122 $pqri_measures['reporting-rate'] = (($row['pass_filter'] - $row['excluded']) / $row['pass_filter']) * 100;
123 $pqri_measures['reporting-rate'] = $pqri_measures['reporting-rate'] . '%';
124 $xml->add_pqri_measures($pqri_measures);
125 } else { // $row[0] == "sub"
127 } elseif (isset($row['is_provider'])) {
128 if ($firstProviderFlag == false) {
129 $xml->close_provider();
133 $physician_ids = array();
134 if (!empty($row['npi']) ||
!empty($row['federaltaxid'])) {
135 if (!empty($row['npi'])) {
136 $physician_ids['npi'] = $row['npi'];
139 if (!empty($row['federaltaxid'])) {
140 $physician_ids['tin'] = $row['federaltaxid'];
144 $physician_ids['encounter-from-date'] = '01-01-' . date('Y', strtotime($target_date));
145 $physician_ids['encounter-to-date'] = '12-31-' . date('Y', strtotime($target_date));
147 $xml->open_provider($physician_ids);
148 $firstProviderFlag = false;
149 $existProvider = true;
150 } else { // isset($row['is_plan'])
151 if ($firstPlanFlag == false) {
152 if ($firstProviderFlag == false) {
153 $xml->close_provider();
156 if ($nested == 'true') {
157 $xml->close_measure_group();
161 if ($nested == 'true') {
162 $xml->open_measure_group($row['cqm_measure_group']);
165 $firstPlanFlag = false;
166 $firstProviderFlag = true; // Reset the provider flag
170 if ($existProvider == true) {
171 $xml->close_provider();
172 $xml->close_measure_group();
175 $xml->close_submission();
181 <?php Header
::setupHeader('opener'); ?
>
182 <title
><?php
echo xlt('Export PQRI Report'); ?
></title
>
186 <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
>
191 <textarea rows
='50' cols
='500' style
='width:95%' readonly
>
192 <?php
echo $xml->getXml(); ?
>
195 <p
><input type
='button' value
='<?php echo xla('OK
'); ?>' onclick
='window.close()' /></p
>