Fix - a default value for pubpid is not written to the database when the External...
[openemr.git] / custom / export_qrda_xml.php
blob700f2f1c43075750d3f898cd00e1c7828997ae08
1 <?php
2 /**
4 * EXPORT QRDA
6 * Copyright (C) 2015 Ensoftek, Inc
8 * LICENSE: This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>;.
19 * @package OpenEMR
20 * @author Ensoftek
21 * @link http://www.open-emr.org
25 //SANITIZE ALL ESCAPES
26 $sanitize_all_escapes=true;
28 //STOP FAKE REGISTER GLOBALS
29 $fake_register_globals=false;
31 require_once("../interface/globals.php");
32 require_once("../ccr/uuid.php");
33 require_once("../library/patient.inc");
34 require_once "../library/options.inc.php";
35 require_once("../library/clinical_rules.php");
36 require_once("../library/classes/QRDAXml.class.php");
37 require_once "$srcdir/report_database.inc";
38 require_once("$srcdir/sanitize.inc.php");
39 require_once "qrda_functions.php";
41 //Remove time limit, since script can take many minutes
42 set_time_limit(0);
44 //DENEXCEP NOT NEEDED rules
45 $denExcepNotNeedRules = array('0002', '0018', '0024', '0038', '0043', '0384', '0421');
47 //Predefined QRDA HQMF ID's for CQM rules
48 $preDefinedUniqIDRules = array();
49 $preDefPopIdArr = array();
50 //CMS139v3/0101 - Falls: Screening for Future Fall Risk: HQMF_ID: 40280381-4555-E1C1-0145-672613970D15
51 $preDefinedUniqIDRules['0101'] = '40280381-4555-E1C1-0145-672613970D15';
52 $preDefPopIdArr['0101']['IPP'] = '2448B0C6-6848-4DCB-AA6D-F199337A2C5C';
53 $preDefPopIdArr['0101']['DENOM'] = 'EC400908-35BE-439B-92A9-231D99CEA9DF';
54 $preDefPopIdArr['0101']['NUMER'] = '663FB12B-0FF4-49AB-80A3-624C5E7DF892';
55 $preDefPopIdArr['0101']['DENEXCEP'] = 'FEC7251A-BF8D-4472-97D8-E2A9C0A42176';
57 //CMS127v3/0043 - Pneumonia Vaccination Status for Older Adults: HQMF_ID: 40280381-4555-E1C1-0145-762578A81C4C
58 $preDefinedUniqIDRules['0043'] = '40280381-4555-E1C1-0145-762578A81C4C';
59 $preDefPopIdArr['0043']['IPP'] = '873AECC7-E15B-49E7-8391-D73A46201E2E';
60 $preDefPopIdArr['0043']['DENOM'] = 'FF7016E1-E8C7-43BA-9D56-2BEF649F36FA';
61 $preDefPopIdArr['0043']['NUMER'] = '201F5A6E-4DDE-43A2-BDFC-CE85A98560DA';
63 //CMS69v3/0421 - Preventive Care and Screening: Body Mass Index (BMI) Screening and Follow-Up Plan: HQMF_ID: 40280381-4555-E1C1-0145-D2B36DBB3FE6
64 $preDefinedUniqIDRules['0421']['Numerator 2'] = '40280381-4555-E1C1-0145-D2B36DBB3FE6';
65 $preDefPopIdArr['0421']['Numerator 2']['IPP'] = '1C936855-E644-44C0-B264-49A28756FDB1';
66 $preDefPopIdArr['0421']['Numerator 2']['DENOM'] = '27F1591C-2060-462C-B5D7-7FE86A44B534';
67 $preDefPopIdArr['0421']['Numerator 2']['DENEX'] = '9B0C3C26-D621-4EA3-81FB-A839A3012044';
68 $preDefPopIdArr['0421']['Numerator 2']['NUMER'] = '3095531C-24D7-4AFB-9BCB-F1901FF0FF69';
70 $preDefinedUniqIDRules['0421']['Numerator 1'] = '40280381-4555-E1C1-0145-D2B36DBB3FE6';
71 $preDefPopIdArr['0421']['Numerator 1']['IPP'] = '6E701B1C-6CA5-4AD5-98C9-5F766745EA89';
72 $preDefPopIdArr['0421']['Numerator 1']['DENOM'] = 'E4DC29B8-EB26-4A01-ABB0-4F99FC03BA39';
73 $preDefPopIdArr['0421']['Numerator 1']['DENEX'] = 'BB1B4301-C275-4BAC-87C9-6E960B1601DA';
74 $preDefPopIdArr['0421']['Numerator 1']['NUMER'] = '7669026D-3683-44CC-A2C5-3D62EB2F8A33';
76 //CMS117v3/0038 - Childhood Immunization Status: HQMF_ID: 40280381-4555-E1C1-0145-D7C003364261
77 $preDefinedUniqIDRules['0038'] = '40280381-4555-E1C1-0145-D7C003364261';
78 $preDefPopIdArr['0038']['IPP'] = '6ED6A787-C871-49B9-825C-70A0DB898977';
79 $preDefPopIdArr['0038']['DENOM'] = '545DA813-89ED-4DCD-BDDF-4B33D93DCD84';
80 $preDefPopIdArr['0038']['NUMER'] = '00193FC7-AEE4-4507-A20F-D25A7BB214AD';
82 //CMS138v3/0028 - Preventive Care and Screening: Tobacco Use: Screening and Cessation Intervention: HQMF_ID: 40280381-4600-425F-0146-1F5867D40E82
83 $preDefinedUniqIDRules['0028'] = '40280381-4600-425F-0146-1F5867D40E82';
84 $preDefPopIdArr['0028']['IPP'] = '4E118B62-2AF8-4F51-9355-6FD3F2427D9F';
85 $preDefPopIdArr['0028']['DENOM'] = 'FA1B3953-AE58-4541-BF7B-84D0EB1B0713';
86 $preDefPopIdArr['0028']['NUMER'] = '35B1A6DF-1871-4633-A74B-BCAE371BC030';
87 $preDefPopIdArr['0028']['DENEXCEP'] = '3EE6DFF5-AB17-482F-A147-E6D1E46DBB79';
89 //CMS157v3/0384 - Oncology: Medical and Radiation – Pain Intensity Quantified: HQMF_ID: 40280381-4600-425F-0146-1F620BDF0EB0
90 $preDefinedUniqIDRules['0384'] = '40280381-4600-425F-0146-1F620BDF0EB0';
91 $preDefPopIdArr['0384']['IPP'] = 'C29B6555-3BC7-416F-B61A-FCACD637594F';
92 $preDefPopIdArr['0384']['DENOM'] = 'E5F80C25-6816-4992-92E2-A735B17F8D4F';
93 $preDefPopIdArr['0384']['NUMER'] = 'C948D0D2-D6E9-4099-9CD4-870F2F83A14C';
95 //CMS146v3/0002 - Appropriate Testing for Children with Pharyngitis: HQMF_ID: 40280381-4600-425F-0146-1F6E280C0F09
96 $preDefinedUniqIDRules['0002'] = '40280381-4600-425F-0146-1F6E280C0F09';
97 $preDefPopIdArr['0002']['IPP'] = '9D1135EA-BA90-45E7-8EED-F7335D1CC934';
98 $preDefPopIdArr['0002']['DENOM'] = 'D04EFECB-A901-4565-BDDB-826510499092';
99 $preDefPopIdArr['0002']['NUMER'] = '3F4CDE57-1C5C-4250-A338-55FED6775F57';
100 $preDefPopIdArr['0002']['DENEX'] = '0525FBA2-F068-4706-ADB5-E345852DC55B';
102 //CMS165v3/0018 - Controlling High Blood Pressure: HQMF_ID: 40280381-4600-425F-0146-1F6F722B0F17
103 $preDefinedUniqIDRules['0018'] = '40280381-4600-425F-0146-1F6F722B0F17';
104 $preDefPopIdArr['0018']['IPP'] = 'A72855CE-3C60-41F9-AEE2-64D4F584DDD4';
105 $preDefPopIdArr['0018']['DENOM'] = '26046A5C-E2CC-4A27-B480-FF7E3575691F';
106 $preDefPopIdArr['0018']['NUMER'] = '0899A359-0CD8-4977-AA29-666892AA3AD4';
107 $preDefPopIdArr['0018']['DENEX'] = '4327D845-6194-410D-A48D-D6E1802CAD55';
109 //CMS155v3/0024 - Weight Assessment and Counseling for Nutrition and Physical Activity for Children and Adolescents: HQMF_ID: 40280381-4555-E1C1-0145-85C7311720F5
110 $preDefinedUniqIDRules['0024']['Population Criteria 1']['Numerator 1'] = '40280381-4555-E1C1-0145-85C7311720F5';
111 $preDefPopIdArr['0024']['Population Criteria 1']['Numerator 1']['IPP'] = '10127790-AE94-4070-9DD3-1D3776D08D7C';
112 $preDefPopIdArr['0024']['Population Criteria 1']['Numerator 1']['DENOM'] = '3B3C1568-F875-49B1-9090-E2F494EECBB6';
113 $preDefPopIdArr['0024']['Population Criteria 1']['Numerator 1']['DENEX'] = 'B288D5A4-D573-4FAA-92D6-0B01E1B35C7A';
114 $preDefPopIdArr['0024']['Population Criteria 1']['Numerator 1']['NUMER'] = 'FD4649BD-B962-4CBE-BF4A-C2F95F3EA08E';
116 $preDefinedUniqIDRules['0024']['Population Criteria 1']['Numerator 2'] = '40280381-4555-E1C1-0145-85C7311720F5';
117 $preDefPopIdArr['0024']['Population Criteria 1']['Numerator 2']['IPP'] = '10127790-AE94-4070-9DD3-1D3776D08D7C';
118 $preDefPopIdArr['0024']['Population Criteria 1']['Numerator 2']['DENOM'] = '3B3C1568-F875-49B1-9090-E2F494EECBB6';
119 $preDefPopIdArr['0024']['Population Criteria 1']['Numerator 2']['DENEX'] = 'B288D5A4-D573-4FAA-92D6-0B01E1B35C7A';
120 $preDefPopIdArr['0024']['Population Criteria 1']['Numerator 2']['NUMER'] = '52FBD726-4DD1-48F5-98B9-7175754923E1';
122 $preDefinedUniqIDRules['0024']['Population Criteria 1']['Numerator 3'] = '40280381-4555-E1C1-0145-85C7311720F5';
123 $preDefPopIdArr['0024']['Population Criteria 1']['Numerator 3']['IPP'] = '10127790-AE94-4070-9DD3-1D3776D08D7C';
124 $preDefPopIdArr['0024']['Population Criteria 1']['Numerator 3']['DENOM'] = '3B3C1568-F875-49B1-9090-E2F494EECBB6';
125 $preDefPopIdArr['0024']['Population Criteria 1']['Numerator 3']['DENEX'] = 'B288D5A4-D573-4FAA-92D6-0B01E1B35C7A';
126 $preDefPopIdArr['0024']['Population Criteria 1']['Numerator 3']['NUMER'] = 'C43CE779-C5EE-4C15-A4CC-AF1C446CFB09';
128 $preDefinedUniqIDRules['0024']['Population Criteria 2']['Numerator 1'] = '40280381-4555-E1C1-0145-85C7311720F5';
129 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 1']['IPP'] = '10127790-AE94-4070-9DD3-1D3776D08D7C';
130 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 1']['DENOM'] = '3B3C1568-F875-49B1-9090-E2F494EECBB6';
131 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 1']['DENEX'] = 'B288D5A4-D573-4FAA-92D6-0B01E1B35C7A';
132 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 1']['NUMER'] = 'FD4649BD-B962-4CBE-BF4A-C2F95F3EA08E';
133 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 1']['STRAT'] = '40280381-3D61-56A7-013E-5D53298E6DA3';
134 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 1']['DISPLAY_TEXT'] = 'BMI Recorded, RS1: 3-11';
136 $preDefinedUniqIDRules['0024']['Population Criteria 2']['Numerator 2'] = '40280381-4555-E1C1-0145-85C7311720F5';
137 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 2']['IPP'] = '10127790-AE94-4070-9DD3-1D3776D08D7C';
138 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 2']['DENOM'] = '3B3C1568-F875-49B1-9090-E2F494EECBB6';
139 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 2']['DENEX'] = 'B288D5A4-D573-4FAA-92D6-0B01E1B35C7A';
140 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 2']['NUMER'] = '52FBD726-4DD1-48F5-98B9-7175754923E1';
141 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 2']['STRAT'] = '40280381-3D61-56A7-013E-5D53298E6DA3';
142 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 2']['DISPLAY_TEXT'] = 'BMI Recorded, RS2: 12-17';
144 $preDefinedUniqIDRules['0024']['Population Criteria 2']['Numerator 3'] = '40280381-4555-E1C1-0145-85C7311720F5';
145 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 3']['IPP'] = '10127790-AE94-4070-9DD3-1D3776D08D7C';
146 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 3']['DENOM'] = '3B3C1568-F875-49B1-9090-E2F494EECBB6';
147 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 3']['DENEX'] = 'B288D5A4-D573-4FAA-92D6-0B01E1B35C7A';
148 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 3']['NUMER'] = 'C43CE779-C5EE-4C15-A4CC-AF1C446CFB09';
149 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 3']['STRAT'] = '40280381-3D61-56A7-013E-5D53298E6DA3';
150 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 3']['DISPLAY_TEXT'] = 'Nutrition Counseling, RS1: 3-11';
152 $preDefinedUniqIDRules['0024']['Population Criteria 3']['Numerator 1'] = '40280381-4555-E1C1-0145-85C7311720F5';
153 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 1']['IPP'] = '10127790-AE94-4070-9DD3-1D3776D08D7C';
154 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 1']['DENOM'] = '3B3C1568-F875-49B1-9090-E2F494EECBB6';
155 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 1']['DENEX'] = 'B288D5A4-D573-4FAA-92D6-0B01E1B35C7A';
156 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 1']['NUMER'] = 'FD4649BD-B962-4CBE-BF4A-C2F95F3EA08E';
157 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 1']['STRAT'] = '40280381-3D61-56A7-013E-5D532AF06DA5';
158 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 1']['DISPLAY_TEXT'] = 'Nutrition Counseling, RS2: 12-17';
160 $preDefinedUniqIDRules['0024']['Population Criteria 3']['Numerator 2'] = '40280381-4555-E1C1-0145-85C7311720F5';
161 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 2']['IPP'] = '10127790-AE94-4070-9DD3-1D3776D08D7C';
162 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 2']['DENOM'] = '3B3C1568-F875-49B1-9090-E2F494EECBB6';
163 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 2']['DENEX'] = 'B288D5A4-D573-4FAA-92D6-0B01E1B35C7A';
164 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 2']['NUMER'] = '52FBD726-4DD1-48F5-98B9-7175754923E1';
165 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 2']['STRAT'] = '40280381-3D61-56A7-013E-5D532AF06DA5';
166 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 2']['DISPLAY_TEXT'] = 'Physical Activity Counseling, RS1: 3-11';
168 $preDefinedUniqIDRules['0024']['Population Criteria 3']['Numerator 3'] = '40280381-4555-E1C1-0145-85C7311720F5';
169 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 3']['IPP'] = '10127790-AE94-4070-9DD3-1D3776D08D7C';
170 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 3']['DENOM'] = '3B3C1568-F875-49B1-9090-E2F494EECBB6';
171 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 3']['DENEX'] = 'B288D5A4-D573-4FAA-92D6-0B01E1B35C7A';
172 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 3']['NUMER'] = 'C43CE779-C5EE-4C15-A4CC-AF1C446CFB09';
173 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 3']['STRAT'] = '40280381-3D61-56A7-013E-5D532AF06DA5';
174 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 3']['DISPLAY_TEXT'] = 'Physical Activity Counseling, RS2: 12-17';
176 $preDefPopIdArr['0024']['STRAT1'] = '40280381-3D61-56A7-013E-5D53298E6DA3';
177 $preDefPopIdArr['0024']['STRAT2'] = '40280381-3D61-56A7-013E-5D532AF06DA5';
179 //Multiple Numerator NQF# Array declaration
180 $multNumNQFArr = array('0421', '0024');
181 $countNumNQFArr = array();
182 $countNumNQFArr['0421'] = 2;//two Numerators
183 $countNumNQFArr['0024'] = 9;//Nine Numerators
185 //Initiation of all QRDA needed elements
186 $CQMeausesArr = array();
187 $CQMeausesArr['init_patients'] = "Initial Patient Population";
188 $CQMeausesArr['exclude_patients'] = "Denominator Exclusions";
189 $CQMeausesArr['denom_patients'] = "Denominator";
190 $CQMeausesArr['numer_patients'] = "Numerator";
191 $CQMeausesArr['exception_patients'] = "Denominator Exceptions";
193 $cqmItemizedArr = array();
194 $cqmItemizedArr['init_patients'] = "init_patients";
195 $cqmItemizedArr['exclude_patients'] = "exclude";
196 $cqmItemizedArr['denom_patients'] = "all";
197 $cqmItemizedArr['numer_patients'] = "pass";
198 $cqmItemizedArr['exception_patients'] = "exception";
200 //QRDA Needed Ethnicity
201 $mainEthiArr = array(0=>'Not Hispanic or Latino', 1=>'Hispanic or Latino');
202 $mainEthiCodeArr = array(0=>'2186-5', 1=>'2135-2');
204 //QRDA Needed Race
205 $mainQrdaRaceArr = array(0=>'American Indian or Alaska Native', 1=>'Asian', 2=>'Black or African American', 3=>'Native Hawaiian or Other Pacific Islander', 4=>'White', 5=>'Other');
206 $mainQrdaRaceCodeArr = array(0=>'1002-5', 1=>'2028-9', 2=>'2054-5', 3=>'2076-8', 4=>'2106-3', 5=>'2131-1');
208 $mainQrdaPopulationIncArr = array();
209 $mainQrdaPopulationIncArr['init_patients'] = "IPP";
210 $mainQrdaPopulationIncArr['exclude_patients'] = "DENEX";
211 $mainQrdaPopulationIncArr['denom_patients'] = "DENOM";
212 $mainQrdaPopulationIncArr['numer_patients'] = "NUMER";
213 $mainQrdaPopulationIncArr['exception_patients'] = "DENEXCEP";
214 $mainQrdaPopulationIncArr['measure_population'] = "MSRPOPL";
215 $mainQrdaPopulationIncArr['numer_exclusion'] = "NUMEX";
217 //QRDA Needed Gender
218 $mainQrdaGenderCodeArr = array();
219 $mainQrdaGenderCodeArr['F'] = "Female";
220 $mainQrdaGenderCodeArr['M'] = "Male";
221 $mainQrdaGenderCodeArr['UN'] = "Unknown";
223 //QRDA Needed Payer Info
224 $mainQrdaPayerCodeArr = array();
225 $mainQrdaPayerCodeArr['A'] = "Medicare";
226 $mainQrdaPayerCodeArr['B'] = "Medicaid";
227 $mainQrdaPayerCodeArr['C'] = "Private Health Insurance";
228 $mainQrdaPayerCodeArr['D'] = "Other";
230 //Payer Codes According to Cypress Codes
231 $mainQrdaPayerCodeSendArr = array();
232 $mainQrdaPayerCodeSendArr['A'] = "1";
233 $mainQrdaPayerCodeSendArr['B'] = "2";
234 $mainQrdaPayerCodeSendArr['C'] = "5";
235 $mainQrdaPayerCodeSendArr['D'] = "349";
237 //Provider selection
238 $form_provider = $_GET['form_provider'];
240 //Get Report Information
241 $report_id = $_GET['report_id'];
242 $report_view = collectReportDatabase($report_id);
243 $target_date = $report_view['date_target'];
244 $dataSheet = json_decode($report_view['data'],TRUE);
246 //Needed array for Rule NQF#0024 Stratification
247 $stratumCheckArr = array();
248 if(count($dataSheet) > 0){
249 //Inner Data Loop
250 foreach ($dataSheet as $row) {
251 $itemized_test_id = $row['itemized_test_id'];
252 $numerator_label = $row['numerator_label'];
253 if($row['cqm_nqf_code'] == "0024"){
254 if( $row['population_label'] == "Population Criteria 2" ){
255 if($row['numerator_label'] == "Numerator 1"){
256 $firstElement = count($row['init_patients']);
257 $thirdElement = count($row['exclude_patients']);
258 $fifthElement = count($row['denom_patients']);
259 $seventhElement = count($row['numer_patients']);
260 }else if($row['numerator_label'] == "Numerator 2"){
261 $fifteenElement = count($row['numer_patients']);
262 }else if($row['numerator_label'] == "Numerator 3"){
263 $twentyThreeElement = count($row['numer_patients']);
265 }else if( $row['population_label'] == "Population Criteria 3" ){
266 if($row['numerator_label'] == "Numerator 1"){
267 $secondElement = count($row['init_patients']);
268 $sixElement = count($row['exclude_patients']);
269 $fouthElement = count($row['denom_patients']);
270 $eigthElement = count($row['numer_patients']);
271 }else if($row['numerator_label'] == "Numerator 2"){
272 $sixteenElement = count($row['numer_patients']);
273 }else if($row['numerator_label'] == "Numerator 3"){
274 $twentyFourElement = count($row['numer_patients']);
279 //Stratum Array for Cypress Version 2.6.0 acceptable format for NQF 0024 rule
280 $stratumCheckArr[1] = array('1'=> $firstElement, '2' => $secondElement);
281 $stratumCheckArr[2] = array('1'=> $thirdElement, '2' => $fouthElement);
282 $stratumCheckArr[3] = array('1'=> $fifthElement, '2' => $sixElement);
283 $stratumCheckArr[4] = array('1'=> $seventhElement, '2' => $eigthElement);
284 $stratumCheckArr[5] = array('1'=>'0', '2' =>'0');//Always 0
285 $stratumCheckArr[6] = array('1'=>'0', '2' =>'0');//Always 0
286 $stratumCheckArr[7] = array('1'=>'0', '2' =>'0');//Always 0
287 $stratumCheckArr[8] = array('1'=> $fifteenElement, '2' => $sixteenElement);
288 $stratumCheckArr[9] = array('1'=>'0', '2' =>'0');//Always 0
289 $stratumCheckArr[10] = array('1'=>'0', '2' =>'0');//Always 0
290 $stratumCheckArr[11] = array('1'=>'0', '2' =>'0');//Always 0
291 $stratumCheckArr[12] = array('1'=> $twentyThreeElement, '2' => $twentyFourElement);
295 $from_date = date('Y', strtotime($target_date ))."-01-01";
296 $to_date = date('Y', strtotime($target_date ))."-12-31";
297 $xml = new QRDAXml();
299 #################################################################################################
300 ####################### HEADER ELEMENTS START #####################################################
301 #################################################################################################
302 //Open Main Clinical Document
303 $xml->open_clinicaldocument();
305 $xml->self_realmcode();
307 $xml->self_typeid();
309 $tempId = '2.16.840.1.113883.10.20.27.1.1';
310 $xml->self_templateid($tempId);
312 $xml->unique_id = getUuid();
313 $xml->self_id();
314 $xml->self_code();
316 //Main Title Display to XML
317 $main_title = "QRDA Calculated Summary Report";
318 $xml->add_title($main_title);
320 //Effective date and time
321 $eff_datetime = date('Ymdhis', strtotime($target_date));
322 $xml->self_efftime($eff_datetime);
324 $xml->self_confidentcode();
326 //Language
327 $xml->self_lang();
329 $setidVal =getUuid();
330 $xml->self_setid($setidVal);
332 //Version
333 $xml->self_version();
335 //Record Target Elements
336 $xml->open_recordTarget();
337 $xml->add_patientRole();
338 $xml->close_recordTarget();
340 ############### Author Info #######################
341 $xml->open_author();
342 //Author time
343 $auth_dtime = date('Ymdhis', strtotime(date('Y-m-d H:i:s')));
344 $xml->self_authorTime($auth_dtime);
345 //Assigned Author
346 $xml->open_assignAuthor();
347 $authorsetid = getUuid();
348 $xml->self_customId($authorsetid);
349 if($form_provider != ""){
350 $userRow = sqlQuery("SELECT facility, facility_id, federaltaxid, npi, phone,fname, lname FROM users WHERE id=?", array($form_provider));
351 $facility_name = $userRow['facility'];
352 $facility_id = $userRow['facility_id'];
354 //$xml->self_customTag('telecom', array('value' => $userRow['phone'], 'use'=>'WP'));
356 //assignedAuthoringDevice Start
357 $xml->open_customTag('assignedAuthoringDevice');
359 $xml->element('softwareName', 'CYPRESS');
361 //assignedAuthoringDevice Close
362 $xml->close_customTag();
364 //Facility Address
365 $facilResRow = sqlQuery("SELECT name, street,city,state,postal_code, country_code, phone from facility WHERE id = ?", array($facility_id));
366 $xml->add_authReprestOrginisation($facilResRow);
367 //$xml->add_facilAddress($facilResRow);
368 $xml->close_assignAuthor();
369 $xml->close_author();
371 ############### Custodian Info #######################
372 $xml->open_custodian();
373 $xml->open_assgnCustodian();
374 $xml->add_represtCustodianOrginisation($facilResRow);
375 $xml->close_assgnCustodian();
376 $xml->close_custodian();
379 ############### Information Recipient #######################
380 $xml->open_infoRecipient();
381 $xml->add_indententRecipient();
382 $xml->close_infoRecipient();
385 ############### Legal Authenticator #######################
386 $xml->open_legalAuthenticator();
387 $auth_dtime = date('Ymdhis', strtotime(date('Y-m-d H:i:s')));
388 $xml->self_authorTime($auth_dtime);
389 $xml->self_legalSignCode();
391 $xml->open_assignedEntity();
392 $assignedEntityId = getUuid();
393 $xml->self_customId($assignedEntityId);
395 $xml->open_customTag('assignedPerson');
397 //Provider Name
398 $userNameArr = array('fname' =>$userRow['fname'], 'lname'=>$userRow['lname']);
399 $xml->add_providerName($userNameArr);
401 //assignedPerson Close
402 $xml->close_customTag();
404 //Represent Origination Name
405 $xml->add_authReprestOrginisation($facilResRow);
406 $xml->close_assignedEntity();
408 $xml->close_legalAuthenticator();
411 ############### Participant is Device(optional) #######################
412 $participentDevArr = array();
413 $xml->open_participant_data('DEV');//DEV -- Device
414 $xml->open_assocEntityData('RGPR');//RGPR -- Regulated Product
415 $participentDevArr['root'] = '2.16.840.1.113883.3.2074.1';
416 $participentDevArr['extension'] = '1a2b3c';
417 $xml->self_particpantIdInfo($participentDevArr);
418 $xml->self_participantCodeDevice();
419 $xml->close_assocEntityData();
420 $xml->close_participant_data();
422 ############### Participant is Location(optional) #######################
423 $participentLocArr = array();
424 $xml->open_participant_data('LOC');//LOC -- Location
425 $xml->open_assocEntityData('SDLOC');//SDLOC -- Service Delivery Location
426 $participentLocArr['root'] = '2.16.840.1.113883.3.249.5.1';
427 $participentLocArr['extension'] = 'OK666333';
428 $xml->self_particpantIdInfo($participentLocArr);
429 $xml->self_participantCodeLocation();
431 $xml->add_facilAddress($facilResRow);
432 $xml->close_assocEntityData();
433 $xml->close_participant_data();
436 ############### documentationOf START #######################
437 $xml->open_customTag('documentationOf');
439 $xml->open_customTag('serviceEvent', array('classCode'=>'PCPR'));
441 $timeArr = array('low'=>date('Ymd', strtotime($from_date)), 'high'=>date('Ymd', strtotime($to_date)));
442 $xml->add_entryEffectTime($timeArr);
444 $xml->open_customTag('performer', array('typeCode'=>'PRF'));
446 $xml->open_customTag('assignedEntity');
448 $npi_provider = $userRow['npi'];
449 $xml->self_customTag('id', array('root' => '2.16.840.1.113883.4.6', 'extension' =>$npi_provider));
451 if($userRow['phone'] != ""){
452 $xml->self_customTag('telecom', array('value' => $userRow['phone'], 'use'=>'WP'));
455 $xml->open_customTag('assignedPerson');
457 //Provider Name
458 $userNameArr = array('fname' =>$userRow['fname'], 'lname'=>$userRow['lname']);
459 $xml->add_providerName($userNameArr);
461 //assignedPerson Close
462 $xml->close_customTag();
464 $xml->open_customTag('representedOrganization');
466 $tin_provider = $userRow['federaltaxid'];
467 if($tin_provider != ""){
468 $xml->self_customTag('id', array('root' => '2.16.840.1.113883.4.2', 'extension' =>$tin_provider));
471 $xml->add_facilName($facility_name);
473 $xml->add_facilAddress($facilResRow);
475 //representedOrganization Close
476 $xml->close_customTag();
478 //assignedEntity Close
479 $xml->close_customTag();
481 //performer Close
482 $xml->close_customTag();
484 //serviceEvent Close
485 $xml->close_customTag();
487 //documentationOf Close
488 $xml->close_customTag();
489 ############### documentationOf END #######################
492 ############### authorization (optional) #########################
494 #################################################################################################
495 ####################### HEADER ELEMENTS END #####################################################
496 #################################################################################################
500 #################################################################################################
501 ######################### Main Component Open ###################################################
502 $xml->open_mainComponent();
504 ############### Structure Body Open #######################
505 $xml->open_structuredBody();
507 ##################### LOOP Component(s) START ########################
509 ###################### Report Parameters Open #####################
510 //QRDA Category III Reporting Parameters Section (CMS EP) [section: templateId 2.16.840.1.113883.10.20.27.2.6
511 $xml->open_loopComponent();
513 $xml->open_section();
515 $tempID = '2.16.840.1.113883.10.20.17.2.1';
516 $xml->self_templateid($tempID);
518 $tempID = '2.16.840.1.113883.10.20.27.2.2';
519 $xml->self_templateid($tempID);
521 $tempID = '2.16.840.1.113883.10.20.27.2.6';
522 $xml->self_templateid($tempID);
523 $arr = array('code'=>'55187-9', 'codeSystem'=>'2.16.840.1.113883.6.1');
524 $xml->self_codeCustom($arr);
525 $title = "Reporting Parameters";
526 $xml->add_title($title);
528 $xml->open_text();
529 $xml->open_list();
530 $item_title = "Reporting period: ".date('d M Y', strtotime($from_date))." - ".date('d M Y', strtotime($to_date));
531 $xml->add_item($item_title);
532 $xml->close_list();
533 $xml->close_text();
535 $typeCode = 'DRIV';
536 $xml->open_entry($typeCode);
537 $arr = array('classCode'=>'ACT', 'moodCode'=>'EVN');
538 $xml->open_act($arr);
540 $tempID = '2.16.840.1.113883.10.20.17.3.8';
541 $xml->self_templateid($tempID);
543 $tempID = '2.16.840.1.113883.10.20.27.3.23';
544 $xml->self_templateid($tempID);
546 $actId = getUuid();
547 $xml->self_customId($actId);
549 $arr = array('code'=>'252116004', 'codeSystem'=>'2.16.840.1.113883.6.96', 'displayName'=>'Observation Parameters');
550 $xml->self_codeCustom($arr);
552 $timeArr = array('low'=>date('Ymd', strtotime($from_date)), 'high'=>date('Ymd', strtotime($to_date)));
553 $xml->add_entryEffectTime($timeArr);
555 $xml->close_act();
556 $xml->close_entry();
558 $xml->close_section();
560 $xml->close_loopComponent();
561 ###################### Report Parameters Close #####################
563 ###################### Measure Section Open #####################
564 $xml->open_loopComponent();
566 $xml->open_section();
568 $tempID = '2.16.840.1.113883.10.20.27.2.1';
569 $xml->self_templateid($tempID);
571 $tempID = '2.16.840.1.113883.10.20.24.2.2';
572 $xml->self_templateid($tempID);
574 $tempID = '2.16.840.1.113883.10.20.27.2.3';
575 $xml->self_templateid($tempID);
577 $arr = array('code'=>'55186-1', 'codeSystem'=>'2.16.840.1.113883.6.1');
578 $xml->self_codeCustom($arr);
579 $title = "Measure Section";
580 $xml->add_title($title);
582 $xml->open_text();
583 $cnt=1;
585 $tabArr = array('border'=>1, 'width'=>'100%');
586 if(count($dataSheet) > 0){
587 $uniqIdArr = array();
589 //Inner Data Loop
590 foreach ($dataSheet as $row) {
591 $itemized_test_id = $row['itemized_test_id'];
592 $numerator_label = $row['numerator_label'];
594 //CQM Rules 2014 set, 0013 is 0018
595 if($row['cqm_nqf_code'] == "0013") $row['cqm_nqf_code'] = "0018";
597 //Table Start
598 $xml->open_customTag('table', $tabArr);
599 //THEAD Start
600 $xml->open_customTag('thead');
601 //TR Start
602 $xml->open_customTag('tr');
604 $xml->add_trElementsTitles();
606 //TR close
607 $xml->close_customTag();
609 //THEAD close
610 $xml->close_customTag();
611 //TBOBY START
612 $xml->open_customTag('tbody');
613 $xml->open_customTag('tr');
615 $tdTitle = generate_display_field(array('data_type'=>'1','list_id'=>'clinical_rules'),$row['id']);
617 if (!empty($row['cqm_pqri_code'])) {
618 $tdTitle .= " " . htmlspecialchars( xl('PQRI') . ":" . $row['cqm_pqri_code'], ENT_NOQUOTES) . " ";
620 if (!empty($row['cqm_nqf_code'])) {
621 $tdTitle .= " " . htmlspecialchars( xl('NQF') . ":" . $row['cqm_nqf_code'], ENT_NOQUOTES) . " ";
624 if ( !(empty($row['concatenated_label'])) ) {
625 $tdTitle .= ", " . htmlspecialchars( xl( $row['concatenated_label'] ), ENT_NOQUOTES) . " ";
628 $tdVersionNeutral = getUuid();
630 if($preDefinedUniqIDRules[$row['cqm_nqf_code']] != ""){
631 if( ($row['cqm_nqf_code'] == "0421" ) )
632 $tdVersionSpecific = $preDefinedUniqIDRules[$row['cqm_nqf_code']][$row['numerator_label']];
633 else if($row['cqm_nqf_code'] == "0024")
634 $tdVersionSpecific = $preDefinedUniqIDRules[$row['cqm_nqf_code']][$row['population_label']][$row['numerator_label']];
635 else
636 $tdVersionSpecific = $preDefinedUniqIDRules[$row['cqm_nqf_code']];
638 $uniqIdArr[] = $tdVersionSpecific;
639 }else{
640 $tdVersionSpecific = getUuid();
641 $uniqIdArr[] = $tdVersionSpecific;
644 $dataArr = array(0=>$tdTitle, 1=>$tdVersionNeutral, 2=>$tdVersionSpecific);
645 $xml->add_trElementsValues($dataArr);
647 //TR close
648 $xml->close_customTag();
649 //TBODY close
650 $xml->close_customTag();
651 //Table Close
652 $xml->close_customTag();
654 //Open List Item Wise
655 $xml->open_list();
657 //Performance Rate
658 $xml->open_customTag('item');
659 $arrContent = array('name'=>'Performance Rate', 'value'=>$row['percentage']);
660 $xml->innerContent($arrContent);
661 $xml->close_customTag();
664 //All CQM Measures taken here
665 foreach($CQMeausesArr as $cqmKey => $cqmVal){
667 //DENEXCEP(Denominator Exception not needed for some rules are skipping here)
668 if( (in_array($row['cqm_nqf_code'], $denExcepNotNeedRules) ) && ($cqmKey == "exception_patients") ) continue;
670 //get Itemized Data
671 if($cqmKey == "init_patients")
672 $itemPatArr = collectItemizedPatientsCdrReport($report_id,$itemized_test_id,$cqmItemizedArr[$cqmKey]);
673 else
674 $itemPatArr = collectItemizedPatientsCdrReport($report_id,$itemized_test_id,$cqmItemizedArr[$cqmKey], $numerator_label);
675 $fullPatArr = array();
676 foreach($itemPatArr as $itemPatInfo){
677 $fullPatArr[] = $itemPatInfo['pid'];
680 //Initial Patient Population
681 $xml->open_customTag('item');
682 $arrContent = array('name'=>$cqmVal, 'value'=>count($fullPatArr));
683 $xml->innerContent($arrContent);
685 $detailsArr = getQRDAPatientNeedInfo($fullPatArr);
687 //Open Sub List
688 $xml->open_list();
690 //Gender Section Display
691 foreach($mainQrdaGenderCodeArr as $GKey => $GVal){
692 $xml->open_customTag('item');
693 $genderInfo = $detailsArr['gender'][$GVal];
694 $arrContent = array('name'=>$GVal, 'value'=>$genderInfo);
695 $xml->innerContent($arrContent);
696 $xml->close_customTag();
699 //Ethnicity Section Display
700 foreach($mainEthiArr as $ethKey => $ethVal){
701 $ethnicity_data = $detailsArr['ethnicity'][$ethVal];
702 $xml->open_customTag('item');
703 $arrContent = array('name'=>'Ethnicity - '.$ethVal, 'value'=>$ethnicity_data);
704 $xml->innerContent($arrContent);
705 $xml->close_customTag();
708 //Race Section Display
709 foreach($mainQrdaRaceArr as $RKey => $RVal){
710 $race_data = $detailsArr['race'][$RVal];
711 $xml->open_customTag('item');
712 $arrContent = array('name'=>'Race - '.$RVal, 'value'=>$race_data);
713 $xml->innerContent($arrContent);
714 $xml->close_customTag();
717 //Payer Type Section Display
718 $payerCheckArr = getQRDAPayerInfo($fullPatArr);
719 foreach($mainQrdaPayerCodeArr as $PKey => $PVal){
720 $xml->open_customTag('item');
721 $arrContent = array('name'=>'Payer - '.$PVal, 'value'=>$payerCheckArr[$PVal]);
722 $xml->innerContent($arrContent);
723 $xml->close_customTag();
726 //close Sub List
727 $xml->close_list();
728 $xml->close_customTag();
730 $xml->close_list();
734 $xml->close_text();
736 #######################################################################
737 ######################### QUALITY MEASURES START ######################
738 #######################################################################
739 if(count($dataSheet) > 0){
740 $innrCnt = 0;
741 $skipMultNumArr = array();
742 $dataChkArr = array();
743 foreach($multNumNQFArr as $multNumVal){
744 $skipMultNumArr[$multNumVal] = false;
745 $dataChkArr[$multNumVal] = 0;
748 //Inner Data Loop
749 foreach ($dataSheet as $row) {
750 $itemized_test_id = $row['itemized_test_id'];
751 $numerator_label = $row['numerator_label'];
752 //Skip section
753 //if($row['cqm_nqf_code'] == "0028a") continue;
755 //if($row['cqm_nqf_code'] == "0038"){
756 // if(in_array($row['numerator_label'], $NQF38NumArr)) continue;
759 if(in_array($row['cqm_nqf_code'], $multNumNQFArr)){
760 $dataChkArr[$row['cqm_nqf_code']]++;
763 //CQM Rules 2014 set, 0013 is 0018
764 if($row['cqm_nqf_code'] == "0013") $row['cqm_nqf_code'] = "0018";
766 $tdTitle = generate_display_field(array('data_type'=>'1','list_id'=>'clinical_rules'),$row['id']);
767 if (!empty($row['cqm_pqri_code'])) {
768 $tdTitle .= " " . text( xl('PQRI') . ":" . $row['cqm_pqri_code']) . " ";
770 if (!empty($row['cqm_nqf_code'])) {
771 $tdTitle .= " " . text( xl('NQF') . ":" . $row['cqm_nqf_code']) . " ";
774 if ( !(empty($row['concatenated_label'])) ) {
775 $tdTitle .= ", " . text( xl( $row['concatenated_label'] )) . " ";
778 ###########################################################
779 if( ( !isset($skipMultNumArr[$row['cqm_nqf_code']]) ) || ($skipMultNumArr[$row['cqm_nqf_code']] == false) ){
781 //Entry open
782 $xml->open_entry();
784 //Organizer Start
785 $arr = array('classCode'=>'CLUSTER', 'moodCode'=>'EVN');
786 $xml->open_customTag('organizer', $arr);
788 $tempID = "2.16.840.1.113883.10.20.24.3.98";
789 $xml->self_templateid($tempID);
791 $tempID = "2.16.840.1.113883.10.20.27.3.1";
792 $xml->self_templateid($tempID);
794 //$tempID = "2.16.840.1.113883.10.20.27.3.17";
795 //$xml->self_templateid($tempID);
796 $actId = getUuid();
797 $xml->self_customId($actId);
799 $arr = array('code'=>'completed');
800 $xml->self_customTag('statusCode', $arr);
802 //reference Start
803 $arr = array('typeCode'=>'REFR');
804 $xml->open_customTag('reference', $arr);
806 //externalDocument Start
807 $arr = array('classCode'=>'DOC', 'moodCode'=>'EVN');
808 $xml->open_customTag('externalDocument', $arr);
810 //$exDocID = getUuid();
811 $exDocID = $uniqIdArr[$innrCnt];
812 //$xml->self_customId($exDocID);
813 $xml->self_customTag('id', array('root' => '2.16.840.1.113883.4.738', 'extension' =>$exDocID));
815 $arr = array('code'=>'57024-2', 'displayName'=>'Health Quality Measure Document', 'codeSystem'=>'2.16.840.1.113883.6.1', 'codeSystemName'=>'LOINC');
816 $xml->self_codeCustom($arr);
818 $dispContntTitle = str_replace("&", '', $tdTitle);
819 $xml->textDispContent($dispContntTitle);
821 //externalDocument Close
822 $xml->close_customTag();
824 //reference Close
825 $xml->close_customTag();
828 ############### Performance Rate for Proportion Measure template START###################
829 $xml->open_loopComponent();
831 //observation Open
832 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
834 $tempID = "2.16.840.1.113883.10.20.27.3.14";
835 $xml->self_templateid($tempID);
837 $tempID = "2.16.840.1.113883.10.20.27.3.25";
838 $xml->self_templateid($tempID);
840 $arr = array('code'=>'72510-1', 'displayName'=>'Performance Rate', 'codeSystem'=>'2.16.840.1.113883.6.1', 'codeSystemName'=>'SNOMED-CT');
841 $xml->self_codeCustom($arr);
843 $arr = array('code'=>'completed');
844 $xml->self_customTag('statusCode', $arr);
846 $percentage = str_replace("%", '', $row['percentage']);
847 $arr = array('xsi:type'=>'REAL', 'value'=>$percentag/100);
848 $xml->self_customTag('value', $arr);
850 //reference Start
851 $arr = array('typeCode'=>'REFR');
852 $xml->open_customTag('reference', $arr);
854 //externalObservation Start
855 $arr = array('classCode'=>'OBS', 'moodCode'=>'EVN');
856 $xml->open_customTag('externalObservation', $arr);
858 //Modified HQMF_ID
859 //$exDocID = getUuid();
862 if( ($row['cqm_nqf_code'] == "0421" )){
863 $exDocID = $preDefPopIdArr[$row['cqm_nqf_code']][$row['numerator_label']]["NUMER"];
864 }else if(($row['cqm_nqf_code'] == "0024")){
865 $exDocID = $preDefPopIdArr[$row['cqm_nqf_code']][$row['population_label']][$row['numerator_label']]["NUMER"];
866 }else{
867 if($preDefPopIdArr[$row['cqm_nqf_code']]["NUMER"] != "")
868 $exDocID = $preDefPopIdArr[$row['cqm_nqf_code']]["NUMER"];
869 else
870 $exDocID = getUuid();
873 $xml->self_customId($exDocID);
875 $arr = array('code'=>'NUMER', 'displayName'=>'Numerator', 'codeSystem'=>'2.16.840.1.113883.5.1063', 'codeSystemName'=>'ObservationValue');
876 $xml->self_codeCustom($arr);
878 //externalObservation Close
879 $xml->close_customTag();
881 //reference Close
882 $xml->close_customTag();
884 //observation Close
885 $xml->close_customTag();
887 $xml->close_loopComponent();
888 ############### Performance Rate for Proportion Measure template END ###################
892 //All CQM Measures taken here
893 foreach($CQMeausesArr as $cqmKey => $cqmVal){
895 //DENEXCEP(Denominator Exception not needed for some rules are skipping here)
896 if( (in_array($row['cqm_nqf_code'], $denExcepNotNeedRules) ) && ($cqmKey == "exception_patients") ) continue;
898 //get Itemized Data
899 if($cqmKey == "init_patients")
900 $itemPatArr = collectItemizedPatientsCdrReport($report_id,$itemized_test_id,$cqmItemizedArr[$cqmKey]);
901 else
902 $itemPatArr = collectItemizedPatientsCdrReport($report_id,$itemized_test_id,$cqmItemizedArr[$cqmKey], $numerator_label);
904 $fullPatArr = array();
905 foreach($itemPatArr as $itemPatInfo){
906 $fullPatArr[] = $itemPatInfo['pid'];
909 $detailsArr = getQRDAPatientNeedInfo($fullPatArr);
910 ############### Initial patient population template START###################
911 $xml->open_loopComponent();
913 //observation Open
914 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
916 $tempID = "2.16.840.1.113883.10.20.27.3.5";
917 $xml->self_templateid($tempID);
919 $tempID = "2.16.840.1.113883.10.20.27.3.16";
920 $xml->self_templateid($tempID);
922 $arr = array('code'=>'ASSERTION', 'displayName'=>'Assertion', 'codeSystem'=>'2.16.840.1.113883.5.4', 'codeSystemName'=>'ActCode');
923 $xml->self_codeCustom($arr);
925 $arr = array('code'=>'completed');
926 $xml->self_customTag('statusCode', $arr);
928 $arr = array('xsi:type'=>'CD', 'code'=>$mainQrdaPopulationIncArr[$cqmKey], 'displayName'=>$cqmVal, 'codeSystem' =>'2.16.840.1.113883.5.1063', 'codeSystemName'=>'ObservationValue');
929 $xml->self_customTag('value', $arr);
931 //entryRelationship Open
932 $xml->open_customTag('entryRelationship', array('typeCode'=>'SUBJ', 'inversionInd'=>'true'));
934 //observation Open
935 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
937 $tempID = "2.16.840.1.113883.10.20.27.3.3";
938 $xml->self_templateid($tempID);
940 $tempID = "2.16.840.1.113883.10.20.27.3.24";
941 $xml->self_templateid($tempID);
943 $arr = array('code'=>'MSRAGG', 'displayName'=>'rate aggregation', 'codeSystem'=>'2.16.840.1.113883.5.4', 'codeSystemName'=>'ActCode');
944 $xml->self_codeCustom($arr);
946 //$arr = array('code'=>'completed');
947 //$xml->self_customTag('statusCode', $arr);
949 $arr = array('xsi:type'=>'INT', 'value'=>count($fullPatArr));
950 $xml->self_customTag('value', $arr);
952 $arr = array('code'=>'COUNT', 'displayName'=>'Count', 'codeSystem'=>'2.16.840.1.113883.5.84', 'codeSystemName'=>'ObservationMethod');
953 $xml->self_customTag('methodCode', $arr);
955 //observation Close
956 $xml->close_customTag();
958 //entryRelationship Close
959 $xml->close_customTag();
961 #### Stratum Start (Stratification)#####
962 if( ($row['cqm_nqf_code'] == "0024") && ( $row['population_label'] == "Population Criteria 1" || $row['population_label'] == "Population Criteria 2" || $row['population_label'] == "Population Criteria 3") ){
964 if($cnt <= 12){
965 $stratumCheckArrSub = $stratumCheckArr[$cnt];
966 for($i=1;$i<=2;$i++){
967 //entryRelationship Open
968 $xml->open_customTag('entryRelationship', array('typeCode'=>'COMP'));
970 //observation Open
971 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
973 $tempID = "2.16.840.1.113883.10.20.27.3.4";
974 $xml->self_templateid($tempID);
976 $tempID = "2.16.840.1.113883.10.20.27.3.20";
977 $xml->self_templateid($tempID);
979 $arr = array('code'=>'ASSERTION', 'displayName'=>'Assertion', 'codeSystem'=>'2.16.840.1.113883.5.4', 'codeSystemName'=>'ActCode');
980 $xml->self_codeCustom($arr);
982 $arr = array('code'=>'completed');
983 $xml->self_customTag('statusCode', $arr);
985 //value open
986 $xml->open_customTag('value', array('xsi:type'=>'CD', 'nullFlavor'=>'OTH'));
988 $stratumText = $preDefPopIdArr[$row['cqm_nqf_code']][$row['population_label']][$row['numerator_label']]['DISPLAY_TEXT'];
989 $xml->element('originalText', "Stratum".$i);
991 //value Close
992 $xml->close_customTag();
994 //entryRelationship Open
995 $xml->open_customTag('entryRelationship', array('typeCode'=>'SUBJ', 'inversionInd' => 'true'));
997 //observation Open
998 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
1000 $tempID = "2.16.840.1.113883.10.20.27.3.3";
1001 $xml->self_templateid($tempID);
1003 $arr = array('code'=>'MSRAGG', 'displayName'=>'rate aggregation', 'codeSystem'=>'2.16.840.1.113883.5.4', 'codeSystemName'=>'ActCode');
1004 $xml->self_codeCustom($arr);
1006 $arr = array('xsi:type'=>'INT', 'value'=>$stratumCheckArrSub[$i]);
1007 $xml->self_customTag('value', $arr);
1009 $arr = array('code'=>'COUNT', 'displayName'=>'Count', 'codeSystem'=>'2.16.840.1.113883.5.84', 'codeSystemName'=>'ObservationMethod');
1010 $xml->self_customTag('methodCode', $arr);
1012 //observation Close
1013 $xml->close_customTag();
1015 //entryRelationship Close
1016 $xml->close_customTag();
1018 //reference Start
1019 $arr = array('typeCode'=>'REFR');
1020 $xml->open_customTag('reference', $arr);
1022 //externalObservation Start
1023 $arr = array('classCode'=>'OBS', 'moodCode'=>'EVN');
1024 $xml->open_customTag('externalObservation', $arr);
1026 //Modified HQMF_ID for CQM IDS
1027 //$refID = $preDefPopIdArr[$row['cqm_nqf_code']][$row['population_label']][$row['numerator_label']]['STRAT'];
1028 $refID = $preDefPopIdArr[$row['cqm_nqf_code']]['STRAT'.$i];
1030 $xml->self_customId($refID);
1032 //externalObservation Close
1033 $xml->close_customTag();
1035 //reference Close
1036 $xml->close_customTag();
1038 //observation Close
1039 $xml->close_customTag();
1041 //entryRelationship Close
1042 $xml->close_customTag();
1045 $cnt++;
1047 #### Stratum END #####
1049 ####################################################
1050 ####################################################
1051 //Sex Supplemental Data Element START
1052 ####################################################
1053 ####################################################
1055 foreach($mainQrdaGenderCodeArr as $GKey => $GVal){
1056 //entryRelationship Open
1057 $xml->open_customTag('entryRelationship', array('typeCode'=>'COMP'));
1059 //observation Open
1060 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
1062 $tempID = "2.16.840.1.113883.10.20.27.3.6";
1063 $xml->self_templateid($tempID);
1065 $tempID = "2.16.840.1.113883.10.20.27.3.21";
1066 $xml->self_templateid($tempID);
1068 $arr = array('code'=>'184100006', 'displayName'=>'patient sex', 'codeSystem'=>'2.16.840.1.113883.6.96', 'codeSystemName'=>'SNOMED-CT');
1069 $xml->self_codeCustom($arr);
1071 $arr = array('code'=>'completed');
1072 $xml->self_customTag('statusCode', $arr);
1074 $arr = array('xsi:type'=>'CD', 'code'=>$GKey, 'codeSystem' =>'2.16.840.1.113883.5.1', 'codeSystemName'=>'AdministrativeGenderCode');
1075 $xml->self_customTag('value', $arr);
1077 //entryRelationship Open
1078 $xml->open_customTag('entryRelationship', array('typeCode'=>'SUBJ', 'inversionInd'=>'true'));
1080 //observation Open
1081 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
1083 $tempID = "2.16.840.1.113883.10.20.27.3.3";
1084 $xml->self_templateid($tempID);
1086 $tempID = "2.16.840.1.113883.10.20.27.3.24";
1087 $xml->self_templateid($tempID);
1089 $arr = array('code'=>'MSRAGG', 'displayName'=>'rate aggregation', 'codeSystem'=>'2.16.840.1.113883.5.4', 'codeSystemName'=>'ActCode');
1090 $xml->self_codeCustom($arr);
1092 //$arr = array('code'=>'completed');
1093 //$xml->self_customTag('statusCode', $arr);
1095 $arr = array('xsi:type'=>'INT', 'value'=>$detailsArr['gender'][$GVal]);
1096 $xml->self_customTag('value', $arr);
1098 $arr = array('code'=>'COUNT', 'displayName'=>'Count', 'codeSystem'=>'2.16.840.1.113883.5.84', 'codeSystemName'=>'ObservationMethod');
1099 $xml->self_customTag('methodCode', $arr);
1101 //observation Close
1102 $xml->close_customTag();
1104 //entryRelationship Close
1105 $xml->close_customTag();
1108 //observation Close
1109 $xml->close_customTag();
1111 //entryRelationship Close
1112 $xml->close_customTag();
1114 ####################################################
1115 ####################################################
1116 //Sex Supplemental Data Element END
1117 ####################################################
1118 ####################################################
1120 ####################################################
1121 ####################################################
1122 //Ethnicity Supplemental Data Element (CMS EP) START
1123 ####################################################
1124 ####################################################
1126 foreach($mainEthiArr as $ethKey => $ethVal){
1127 //entryRelationship Open
1128 $xml->open_customTag('entryRelationship', array('typeCode'=>'COMP'));
1130 //observation Open
1131 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
1133 $tempID = "2.16.840.1.113883.10.20.27.3.7";
1134 $xml->self_templateid($tempID);
1136 $tempID = "2.16.840.1.113883.10.20.27.3.22";
1137 $xml->self_templateid($tempID);
1139 $arr = array('code'=>'364699009', 'displayName'=>'Ethnic Group', 'codeSystem'=>'2.16.840.1.113883.6.96', 'codeSystemName'=>'SNOMED-CT');
1140 $xml->self_codeCustom($arr);
1142 $arr = array('code'=>'completed');
1143 $xml->self_customTag('statusCode', $arr);
1145 $arr = array('xsi:type'=>'CD', 'code'=>$mainEthiCodeArr[$ethKey], 'displayName'=>$ethVal, 'codeSystem' =>'2.16.840.1.113883.6.238', 'codeSystemName'=>'Race &amp; Ethnicity - CDC');
1146 $xml->self_customTag('value', $arr);
1148 //entryRelationship Open
1149 $xml->open_customTag('entryRelationship', array('typeCode'=>'SUBJ', 'inversionInd'=>'true'));
1151 //observation Open
1152 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
1154 $tempID = "2.16.840.1.113883.10.20.27.3.3";
1155 $xml->self_templateid($tempID);
1157 $tempID = "2.16.840.1.113883.10.20.27.3.24";
1158 $xml->self_templateid($tempID);
1160 $arr = array('code'=>'MSRAGG', 'displayName'=>'rate aggregation', 'codeSystem'=>'2.16.840.1.113883.5.4', 'codeSystemName'=>'ActCode');
1161 $xml->self_codeCustom($arr);
1163 //$arr = array('code'=>'completed');
1164 //$xml->self_customTag('statusCode', $arr);
1166 $arr = array('xsi:type'=>'INT', 'value'=>$detailsArr['ethnicity'][$ethVal]);
1167 $xml->self_customTag('value', $arr);
1169 $arr = array('code'=>'COUNT', 'displayName'=>'Count', 'codeSystem'=>'2.16.840.1.113883.5.84', 'codeSystemName'=>'ObservationMethod');
1170 $xml->self_customTag('methodCode', $arr);
1172 //observation Close
1173 $xml->close_customTag();
1175 //entryRelationship Close
1176 $xml->close_customTag();
1179 //observation Close
1180 $xml->close_customTag();
1182 //entryRelationship Close
1183 $xml->close_customTag();
1186 ####################################################
1187 ####################################################
1188 //Ethnicity Supplemental Data Element (CMS EP) END
1189 ####################################################
1190 ####################################################
1193 ####################################################
1194 ####################################################
1195 //Race Supplemental Data Element (CMS EP) START
1196 ####################################################
1197 ####################################################
1199 foreach($mainQrdaRaceArr as $RKey => $RVal){
1200 //entryRelationship Open
1201 $xml->open_customTag('entryRelationship', array('typeCode'=>'COMP'));
1203 //observation Open
1204 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
1206 $tempID = "2.16.840.1.113883.10.20.27.3.8";
1207 $xml->self_templateid($tempID);
1209 $tempID = "2.16.840.1.113883.10.20.27.3.19";
1210 $xml->self_templateid($tempID);
1212 $arr = array('code'=>'103579009', 'displayName'=>'Race', 'codeSystem'=>'2.16.840.1.113883.6.96', 'codeSystemName'=>'SNOMED-CT');
1213 $xml->self_codeCustom($arr);
1215 $arr = array('code'=>'completed');
1216 $xml->self_customTag('statusCode', $arr);
1218 $arr = array('xsi:type'=>'CD', 'code'=>$mainQrdaRaceCodeArr[$RKey], 'displayName'=>$RVal, 'codeSystem' =>'2.16.840.1.113883.6.238', 'codeSystemName'=>'Race &amp; Ethnicity - CDC');
1219 $xml->self_customTag('value', $arr);
1221 //entryRelationship Open
1222 $xml->open_customTag('entryRelationship', array('typeCode'=>'SUBJ', 'inversionInd'=>'true'));
1224 //observation Open
1225 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
1227 $tempID = "2.16.840.1.113883.10.20.27.3.3";
1228 $xml->self_templateid($tempID);
1230 $tempID = "2.16.840.1.113883.10.20.27.3.24";
1231 $xml->self_templateid($tempID);
1233 $arr = array('code'=>'MSRAGG', 'displayName'=>'rate aggregation', 'codeSystem'=>'2.16.840.1.113883.5.4', 'codeSystemName'=>'ActCode');
1234 $xml->self_codeCustom($arr);
1236 //$arr = array('code'=>'completed');
1237 //$xml->self_customTag('statusCode', $arr);
1239 $arr = array('xsi:type'=>'INT', 'value'=>$detailsArr['race'][$RVal]);
1240 $xml->self_customTag('value', $arr);
1242 $arr = array('code'=>'COUNT', 'displayName'=>'Count', 'codeSystem'=>'2.16.840.1.113883.5.84', 'codeSystemName'=>'ObservationMethod');
1243 $xml->self_customTag('methodCode', $arr);
1245 //observation Close
1246 $xml->close_customTag();
1248 //entryRelationship Close
1249 $xml->close_customTag();
1252 //observation Close
1253 $xml->close_customTag();
1255 //entryRelationship Close
1256 $xml->close_customTag();
1259 ####################################################
1260 ####################################################
1261 //Race Supplemental Data Element (CMS EP) END
1262 ####################################################
1263 ####################################################
1266 ####################################################
1267 ####################################################
1268 //Payer Supplemental Data Element (CMS EP) START
1269 ####################################################
1270 ####################################################
1271 $payerCheckArr = getQRDAPayerInfo($fullPatArr);
1272 foreach($mainQrdaPayerCodeArr as $PKey => $PVal){
1273 //entryRelationship Open
1274 $xml->open_customTag('entryRelationship', array('typeCode'=>'COMP'));
1276 //observation Open
1277 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
1279 $tempID = "2.16.840.1.113883.10.20.27.3.9";
1280 $xml->self_templateid($tempID);
1282 $tempID = "2.16.840.1.113883.10.20.24.3.55";
1283 $xml->self_templateid($tempID);
1285 $tempID = "2.16.840.1.113883.10.20.27.3.18";
1286 $xml->self_templateid($tempID);
1288 $xml->self_setpatientRoleid();
1290 $arr = array('code'=>'48768-6', 'displayName'=>'Payment source', 'codeSystem'=>'2.16.840.1.113883.6.1', 'codeSystemName'=>'SNOMED-CT');
1291 $xml->self_codeCustom($arr);
1293 $arr = array('code'=>'completed');
1294 $xml->self_customTag('statusCode', $arr);
1296 $timeArr = array('low'=>date('Ymd', strtotime($from_date)));
1297 $xml->add_entryEffectTime($timeArr);
1300 //Value Tag Open
1301 $xml->open_customTag('value', array('xsi:type'=>'CD', 'nullFlavor'=>'OTH'));
1303 $xml->self_customTag('translation', array('code'=>$PKey, 'displayName'=>$PVal, 'codeSystem'=>'2.16.840.1.113883.3.249.12', 'codeSystemName'=>'CMS Clinical Codes'));
1305 //Value Tag Close
1306 $xml->close_customTag();
1309 //Value Tag
1310 $xml->self_customTag('value', array('xsi:type'=>'CD', 'code'=>$mainQrdaPayerCodeSendArr[$PKey], 'codeSystem'=>'2.16.840.1.113883.3.221.5' , 'codeSystemName'=>'SOP', 'displayName'=>$PVal));
1312 //entryRelationship Open
1313 $xml->open_customTag('entryRelationship', array('typeCode'=>'SUBJ', 'inversionInd'=>'true'));
1315 //observation Open
1316 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
1318 $tempID = "2.16.840.1.113883.10.20.27.3.3";
1319 $xml->self_templateid($tempID);
1321 $tempID = "2.16.840.1.113883.10.20.27.3.24";
1322 $xml->self_templateid($tempID);
1324 $arr = array('code'=>'MSRAGG', 'displayName'=>'rate aggregation', 'codeSystem'=>'2.16.840.1.113883.5.4', 'codeSystemName'=>'ActCode');
1325 $xml->self_codeCustom($arr);
1327 //$arr = array('code'=>'completed');
1328 //$xml->self_customTag('statusCode', $arr);
1330 $arr = array('xsi:type'=>'INT', 'value'=>$payerCheckArr[$PVal]);
1331 $xml->self_customTag('value', $arr);
1333 $arr = array('code'=>'COUNT', 'displayName'=>'Count', 'codeSystem'=>'2.16.840.1.113883.5.84', 'codeSystemName'=>'ObservationMethod');
1334 $xml->self_customTag('methodCode', $arr);
1336 //observation Close
1337 $xml->close_customTag();
1339 //entryRelationship Close
1340 $xml->close_customTag();
1343 //observation Close
1344 $xml->close_customTag();
1346 //entryRelationship Close
1347 $xml->close_customTag();
1350 ####################################################
1351 ####################################################
1352 //Payer Supplemental Data Element (CMS EP) END
1353 ####################################################
1354 ####################################################
1356 ######################################################################
1357 //reference Start
1358 $arr = array('typeCode'=>'REFR');
1359 $xml->open_customTag('reference', $arr);
1361 //externalObservation Start
1362 $arr = array('classCode'=>'OBS', 'moodCode'=>'EVN');
1363 $xml->open_customTag('externalObservation', $arr);
1365 //Modified HQMF_ID for CQM IDS
1366 if( ($row['cqm_nqf_code'] == "0421" ) ){
1367 $refID = $preDefPopIdArr[$row['cqm_nqf_code']][$row['numerator_label']][$mainQrdaPopulationIncArr[$cqmKey]];
1368 }else if( ($row['cqm_nqf_code'] == "0024") ){
1369 $refID = $preDefPopIdArr[$row['cqm_nqf_code']][$row['population_label']][$row['numerator_label']][$mainQrdaPopulationIncArr[$cqmKey]];
1370 }else{
1371 $refID = $preDefPopIdArr[$row['cqm_nqf_code']][$mainQrdaPopulationIncArr[$cqmKey]];
1373 if($refID == ""){
1374 $refID = getUuid();
1376 $xml->self_customId($refID);
1378 //externalObservation Close
1379 $xml->close_customTag();
1381 //reference Close
1382 $xml->close_customTag();
1383 ########################################################################
1385 //observation Close
1386 $xml->close_customTag();
1388 $xml->close_loopComponent();
1389 ############### Initial patient population template END#####################
1392 //Multiple Numerator Handling
1393 if(in_array($row['cqm_nqf_code'], $multNumNQFArr)){
1394 //Skipping Multiple Numerator(s)
1395 if(in_array($row['cqm_nqf_code'], $multNumNQFArr)){
1396 $skipMultNumArr[$row['cqm_nqf_code']] = true;
1398 if($dataChkArr[$row['cqm_nqf_code']] == $countNumNQFArr[$row['cqm_nqf_code']]){
1399 //Organizer Close
1400 $xml->close_customTag();
1401 $xml->close_entry();
1403 }else{
1404 //Organizer Close
1405 $xml->close_customTag();
1406 $xml->close_entry();
1409 ###########################################################
1411 $innrCnt++;
1415 #######################################################################
1416 ######################### QUALITY MEASURES END ########################
1417 #######################################################################
1420 $xml->close_section();
1422 $xml->close_loopComponent();
1424 ##################### LOOP Component(s) END ########################
1426 $xml->close_structuredBody();
1427 ############### Structure Body Close #######################
1429 $xml->close_mainComponent();
1430 ############### Main Component Close #######################
1432 //Close Main Clinical Document
1433 $xml->close_clinicaldocument();
1436 //QRDA File Download Folder in site/cqm_qrda folder
1437 $qrda_fname = "QRDA_III_".date("YmdHis").".xml";
1438 $qrda_file_path = $GLOBALS['OE_SITE_DIR'] . "/documents/cqm_qrda/";
1439 if(!file_exists($qrda_file_path)){
1440 mkdir($qrda_file_path, 0777, true);
1442 $qrda_file_name = $qrda_file_path.$qrda_fname;
1443 $fileQRDAOPen = fopen($qrda_file_name, "w");
1444 fwrite($fileQRDAOPen, trim($xml->getXml()));
1445 fclose($fileQRDAOPen);
1448 <html>
1449 <head>
1450 <?php html_header_show();?>
1451 <link rel=stylesheet href="<?php echo $css_header;?>" type="text/css">
1452 <title><?php echo xlt('Export QRDA Report'); ?></title>
1454 <script type="text/javascript">
1455 //Close Me function
1456 function closeme() {
1457 window.close();
1459 </script>
1460 </head>
1461 <body>
1463 <p class="text"><?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 (or) download the below link.'); ?></p>
1465 <center>
1466 <form>
1467 <p class="text">
1468 <a href="qrda_download.php?qrda_fname=<?php echo attr($qrda_fname);?>"><?php echo xlt("Download QRDA Category III File");?></a>
1469 </p>
1470 <textarea rows='50' cols='500' style='width:95%' readonly>
1471 <?php echo trim($xml->getXml()); ?>
1472 </textarea>
1474 <p><input type='button' value='<?php echo xla('Close'); ?>' onclick='closeme();' /></p>
1475 </form>
1476 </center>
1479 </body>
1480 </html>