minor improvement to tabs style
[openemr.git] / custom / export_qrda_xml.php
blob3ef940c5d39e2b106cd3790611c371d7f892dcc6
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
26 require_once("../interface/globals.php");
27 require_once("../ccr/uuid.php");
28 require_once("../library/patient.inc");
29 require_once "../library/options.inc.php";
30 require_once("../library/clinical_rules.php");
31 require_once "$srcdir/report_database.inc";
32 require_once "qrda_functions.php";
34 $facilityService = new \services\FacilityService();
36 //Remove time limit, since script can take many minutes
37 set_time_limit(0);
39 //DENEXCEP NOT NEEDED rules
40 $denExcepNotNeedRules = array('0002', '0018', '0024', '0038', '0043', '0059', '0421');
42 //Predefined QRDA HQMF ID's for CQM rules
43 $preDefinedUniqIDRules = array();
44 $preDefPopIdArr = array();
46 // CMS147v4/0041 - Preventive Care and Screening: Influenza Immunization HQMF ID: 40280381-4600-425F-0146-EE66F0005509
47 $preDefinedUniqIDRules['0041'] = '40280381-4600-425F-0146-EE66F0005509';
48 $preDefPopIdArr['0041']['IPP'] = 'F48702E6-D39A-49D8-BE3C-8FAB5C6AADDA';
49 $preDefPopIdArr['0041']['DENOM'] = 'B61EC2DC-0841-4906-A84B-5BE5024DA7F1';
50 $preDefPopIdArr['0041']['NUMER'] = '0ED7B212-369B-489A-A5B5-07BC146FA557';
51 $preDefPopIdArr['0041']['DENEXCEP'] = 'B5C9EC50-3011-43DC-AD07-CED2D3B770B2';
53 // CMS122v3/0059 - Diabetes: Hemoglobin A1c Poor Control: HQMF_ID: 40280381-4555-E1C1-0145-90AC70DE2C73
54 $preDefinedUniqIDRules['0059'] = '40280381-4555-E1C1-0145-90AC70DE2C73';
55 $preDefPopIdArr['0059']['IPP'] = 'EDED90E9-E4FE-47E6-90AC-29D9AA3E861A';
56 $preDefPopIdArr['0059']['DENOM'] = '6721D6DA-E87D-4E42-A34A-C8490686598C';
57 $preDefPopIdArr['0059']['NUMER'] = '7549BA9E-1841-4231-8CAA-095BDF0AB8A1';
60 //CMS139v3/0101 - Falls: Screening for Future Fall Risk: HQMF_ID: 40280381-4555-E1C1-0145-672613970D15
61 $preDefinedUniqIDRules['0101'] = '40280381-4555-E1C1-0145-672613970D15';
62 $preDefPopIdArr['0101']['IPP'] = '2448B0C6-6848-4DCB-AA6D-F199337A2C5C';
63 $preDefPopIdArr['0101']['DENOM'] = 'EC400908-35BE-439B-92A9-231D99CEA9DF';
64 $preDefPopIdArr['0101']['NUMER'] = '663FB12B-0FF4-49AB-80A3-624C5E7DF892';
65 $preDefPopIdArr['0101']['DENEXCEP'] = 'FEC7251A-BF8D-4472-97D8-E2A9C0A42176';
67 //CMS127v3/0043 - Pneumonia Vaccination Status for Older Adults: HQMF_ID: 40280381-4555-E1C1-0145-762578A81C4C
68 $preDefinedUniqIDRules['0043'] = '40280381-4555-E1C1-0145-762578A81C4C';
69 $preDefPopIdArr['0043']['IPP'] = '873AECC7-E15B-49E7-8391-D73A46201E2E';
70 $preDefPopIdArr['0043']['DENOM'] = 'FF7016E1-E8C7-43BA-9D56-2BEF649F36FA';
71 $preDefPopIdArr['0043']['NUMER'] = '201F5A6E-4DDE-43A2-BDFC-CE85A98560DA';
73 //CMS69v3/0421 - Preventive Care and Screening: Body Mass Index (BMI) Screening and Follow-Up Plan: HQMF_ID: 40280381-4555-E1C1-0145-D2B36DBB3FE6
74 $preDefinedUniqIDRules['0421']['Numerator 1'] = '40280381-4555-E1C1-0145-D2B36DBB3FE6';
75 $preDefPopIdArr['0421']['Numerator 1']['IPP'] = '1C936855-E644-44C0-B264-49A28756FDB1';
76 $preDefPopIdArr['0421']['Numerator 1']['DENOM'] = '27F1591C-2060-462C-B5D7-7FE86A44B534';
77 $preDefPopIdArr['0421']['Numerator 1']['DENEX'] = '9B0C3C26-D621-4EA3-81FB-A839A3012044';
78 $preDefPopIdArr['0421']['Numerator 1']['NUMER'] = '3095531C-24D7-4AFB-9BCB-F1901FF0FF69';
80 $preDefinedUniqIDRules['0421']['Numerator 2'] = '40280381-4555-E1C1-0145-D2B36DBB3FE6';
81 $preDefPopIdArr['0421']['Numerator 2']['IPP'] = '6E701B1C-6CA5-4AD5-98C9-5F766745EA89';
82 $preDefPopIdArr['0421']['Numerator 2']['DENOM'] = 'E4DC29B8-EB26-4A01-ABB0-4F99FC03BA39';
83 $preDefPopIdArr['0421']['Numerator 2']['DENEX'] = 'BB1B4301-C275-4BAC-87C9-6E960B1601DA';
84 $preDefPopIdArr['0421']['Numerator 2']['NUMER'] = '7669026D-3683-44CC-A2C5-3D62EB2F8A33';
86 //CMS117v3/0038 - Childhood Immunization Status: HQMF_ID: 40280381-4555-E1C1-0145-D7C003364261
87 $preDefinedUniqIDRules['0038'] = '40280381-4555-E1C1-0145-D7C003364261';
88 $preDefPopIdArr['0038']['IPP'] = '6ED6A787-C871-49B9-825C-70A0DB898977';
89 $preDefPopIdArr['0038']['DENOM'] = '545DA813-89ED-4DCD-BDDF-4B33D93DCD84';
90 $preDefPopIdArr['0038']['NUMER'] = '00193FC7-AEE4-4507-A20F-D25A7BB214AD';
92 //CMS138v3/0028 - Preventive Care and Screening: Tobacco Use: Screening and Cessation Intervention: HQMF_ID: 40280381-4600-425F-0146-1F5867D40E82
93 $preDefinedUniqIDRules['0028'] = '40280381-4600-425F-0146-1F5867D40E82';
94 $preDefPopIdArr['0028']['IPP'] = '4E118B62-2AF8-4F51-9355-6FD3F2427D9F';
95 $preDefPopIdArr['0028']['DENOM'] = 'FA1B3953-AE58-4541-BF7B-84D0EB1B0713';
96 $preDefPopIdArr['0028']['NUMER'] = '35B1A6DF-1871-4633-A74B-BCAE371BC030';
97 $preDefPopIdArr['0028']['DENEXCEP'] = '3EE6DFF5-AB17-482F-A147-E6D1E46DBB79';
99 //CMS157v3/0384 - Oncology: Medical and Radiation – Pain Intensity Quantified: HQMF_ID: 40280381-4600-425F-0146-1F620BDF0EB0
100 $preDefinedUniqIDRules['0384'] = '40280381-4600-425F-0146-1F620BDF0EB0';
101 $preDefPopIdArr['0384']['IPP'] = 'C29B6555-3BC7-416F-B61A-FCACD637594F';
102 $preDefPopIdArr['0384']['DENOM'] = 'E5F80C25-6816-4992-92E2-A735B17F8D4F';
103 $preDefPopIdArr['0384']['NUMER'] = 'C948D0D2-D6E9-4099-9CD4-870F2F83A14C';
105 //CMS146v3/0002 - Appropriate Testing for Children with Pharyngitis: HQMF_ID: 40280381-4600-425F-0146-1F6E280C0F09
106 $preDefinedUniqIDRules['0002'] = '40280381-4600-425F-0146-1F6E280C0F09';
107 $preDefPopIdArr['0002']['IPP'] = '9D1135EA-BA90-45E7-8EED-F7335D1CC934';
108 $preDefPopIdArr['0002']['DENOM'] = 'D04EFECB-A901-4565-BDDB-826510499092';
109 $preDefPopIdArr['0002']['NUMER'] = '3F4CDE57-1C5C-4250-A338-55FED6775F57';
110 $preDefPopIdArr['0002']['DENEX'] = '0525FBA2-F068-4706-ADB5-E345852DC55B';
112 //CMS165v3/0018 - Controlling High Blood Pressure: HQMF_ID: 40280381-4600-425F-0146-1F6F722B0F17
113 $preDefinedUniqIDRules['0018'] = '40280381-4600-425F-0146-1F6F722B0F17';
114 $preDefPopIdArr['0018']['IPP'] = 'A72855CE-3C60-41F9-AEE2-64D4F584DDD4';
115 $preDefPopIdArr['0018']['DENOM'] = '26046A5C-E2CC-4A27-B480-FF7E3575691F';
116 $preDefPopIdArr['0018']['NUMER'] = '0899A359-0CD8-4977-AA29-666892AA3AD4';
117 $preDefPopIdArr['0018']['DENEX'] = '4327D845-6194-410D-A48D-D6E1802CAD55';
119 //CMS155v3/0024 - Weight Assessment and Counseling for Nutrition and Physical Activity for Children and Adolescents: HQMF_ID: 40280381-4555-E1C1-0145-85C7311720F5
120 $preDefinedUniqIDRules['0024']['Population Criteria 1']['Numerator 1'] = '40280381-4555-E1C1-0145-85C7311720F5';
121 $preDefPopIdArr['0024']['Population Criteria 1']['Numerator 1']['IPP'] = '10127790-AE94-4070-9DD3-1D3776D08D7C';
122 $preDefPopIdArr['0024']['Population Criteria 1']['Numerator 1']['DENOM'] = '3B3C1568-F875-49B1-9090-E2F494EECBB6';
123 $preDefPopIdArr['0024']['Population Criteria 1']['Numerator 1']['DENEX'] = 'B288D5A4-D573-4FAA-92D6-0B01E1B35C7A';
124 $preDefPopIdArr['0024']['Population Criteria 1']['Numerator 1']['NUMER'] = 'FD4649BD-B962-4CBE-BF4A-C2F95F3EA08E';
126 $preDefinedUniqIDRules['0024']['Population Criteria 1']['Numerator 2'] = '40280381-4555-E1C1-0145-85C7311720F5';
127 $preDefPopIdArr['0024']['Population Criteria 1']['Numerator 2']['IPP'] = '10127790-AE94-4070-9DD3-1D3776D08D7C';
128 $preDefPopIdArr['0024']['Population Criteria 1']['Numerator 2']['DENOM'] = '3B3C1568-F875-49B1-9090-E2F494EECBB6';
129 $preDefPopIdArr['0024']['Population Criteria 1']['Numerator 2']['DENEX'] = 'B288D5A4-D573-4FAA-92D6-0B01E1B35C7A';
130 $preDefPopIdArr['0024']['Population Criteria 1']['Numerator 2']['NUMER'] = '52FBD726-4DD1-48F5-98B9-7175754923E1';
132 $preDefinedUniqIDRules['0024']['Population Criteria 1']['Numerator 3'] = '40280381-4555-E1C1-0145-85C7311720F5';
133 $preDefPopIdArr['0024']['Population Criteria 1']['Numerator 3']['IPP'] = '10127790-AE94-4070-9DD3-1D3776D08D7C';
134 $preDefPopIdArr['0024']['Population Criteria 1']['Numerator 3']['DENOM'] = '3B3C1568-F875-49B1-9090-E2F494EECBB6';
135 $preDefPopIdArr['0024']['Population Criteria 1']['Numerator 3']['DENEX'] = 'B288D5A4-D573-4FAA-92D6-0B01E1B35C7A';
136 $preDefPopIdArr['0024']['Population Criteria 1']['Numerator 3']['NUMER'] = 'C43CE779-C5EE-4C15-A4CC-AF1C446CFB09';
138 $preDefinedUniqIDRules['0024']['Population Criteria 2']['Numerator 1'] = '40280381-4555-E1C1-0145-85C7311720F5';
139 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 1']['IPP'] = '10127790-AE94-4070-9DD3-1D3776D08D7C';
140 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 1']['DENOM'] = '3B3C1568-F875-49B1-9090-E2F494EECBB6';
141 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 1']['DENEX'] = 'B288D5A4-D573-4FAA-92D6-0B01E1B35C7A';
142 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 1']['NUMER'] = 'FD4649BD-B962-4CBE-BF4A-C2F95F3EA08E';
143 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 1']['STRAT'] = '40280381-3D61-56A7-013E-5D53298E6DA3';
144 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 1']['DISPLAY_TEXT'] = 'BMI Recorded, RS1: 3-11';
146 $preDefinedUniqIDRules['0024']['Population Criteria 2']['Numerator 2'] = '40280381-4555-E1C1-0145-85C7311720F5';
147 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 2']['IPP'] = '10127790-AE94-4070-9DD3-1D3776D08D7C';
148 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 2']['DENOM'] = '3B3C1568-F875-49B1-9090-E2F494EECBB6';
149 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 2']['DENEX'] = 'B288D5A4-D573-4FAA-92D6-0B01E1B35C7A';
150 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 2']['NUMER'] = '52FBD726-4DD1-48F5-98B9-7175754923E1';
151 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 2']['STRAT'] = '40280381-3D61-56A7-013E-5D53298E6DA3';
152 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 2']['DISPLAY_TEXT'] = 'BMI Recorded, RS2: 12-17';
154 $preDefinedUniqIDRules['0024']['Population Criteria 2']['Numerator 3'] = '40280381-4555-E1C1-0145-85C7311720F5';
155 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 3']['IPP'] = '10127790-AE94-4070-9DD3-1D3776D08D7C';
156 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 3']['DENOM'] = '3B3C1568-F875-49B1-9090-E2F494EECBB6';
157 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 3']['DENEX'] = 'B288D5A4-D573-4FAA-92D6-0B01E1B35C7A';
158 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 3']['NUMER'] = 'C43CE779-C5EE-4C15-A4CC-AF1C446CFB09';
159 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 3']['STRAT'] = '40280381-3D61-56A7-013E-5D53298E6DA3';
160 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 3']['DISPLAY_TEXT'] = 'Nutrition Counseling, RS1: 3-11';
162 $preDefinedUniqIDRules['0024']['Population Criteria 3']['Numerator 1'] = '40280381-4555-E1C1-0145-85C7311720F5';
163 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 1']['IPP'] = '10127790-AE94-4070-9DD3-1D3776D08D7C';
164 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 1']['DENOM'] = '3B3C1568-F875-49B1-9090-E2F494EECBB6';
165 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 1']['DENEX'] = 'B288D5A4-D573-4FAA-92D6-0B01E1B35C7A';
166 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 1']['NUMER'] = 'FD4649BD-B962-4CBE-BF4A-C2F95F3EA08E';
167 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 1']['STRAT'] = '40280381-3D61-56A7-013E-5D532AF06DA5';
168 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 1']['DISPLAY_TEXT'] = 'Nutrition Counseling, RS2: 12-17';
170 $preDefinedUniqIDRules['0024']['Population Criteria 3']['Numerator 2'] = '40280381-4555-E1C1-0145-85C7311720F5';
171 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 2']['IPP'] = '10127790-AE94-4070-9DD3-1D3776D08D7C';
172 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 2']['DENOM'] = '3B3C1568-F875-49B1-9090-E2F494EECBB6';
173 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 2']['DENEX'] = 'B288D5A4-D573-4FAA-92D6-0B01E1B35C7A';
174 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 2']['NUMER'] = '52FBD726-4DD1-48F5-98B9-7175754923E1';
175 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 2']['STRAT'] = '40280381-3D61-56A7-013E-5D532AF06DA5';
176 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 2']['DISPLAY_TEXT'] = 'Physical Activity Counseling, RS1: 3-11';
178 $preDefinedUniqIDRules['0024']['Population Criteria 3']['Numerator 3'] = '40280381-4555-E1C1-0145-85C7311720F5';
179 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 3']['IPP'] = '10127790-AE94-4070-9DD3-1D3776D08D7C';
180 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 3']['DENOM'] = '3B3C1568-F875-49B1-9090-E2F494EECBB6';
181 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 3']['DENEX'] = 'B288D5A4-D573-4FAA-92D6-0B01E1B35C7A';
182 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 3']['NUMER'] = 'C43CE779-C5EE-4C15-A4CC-AF1C446CFB09';
183 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 3']['STRAT'] = '40280381-3D61-56A7-013E-5D532AF06DA5';
184 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 3']['DISPLAY_TEXT'] = 'Physical Activity Counseling, RS2: 12-17';
186 $preDefPopIdArr['0024']['STRAT1'] = '40280381-3D61-56A7-013E-5D53298E6DA3';
187 $preDefPopIdArr['0024']['STRAT2'] = '40280381-3D61-56A7-013E-5D532AF06DA5';
189 //Multiple Numerator NQF# Array declaration
190 $multNumNQFArr = array('0421', '0024');
191 $countNumNQFArr = array();
192 $countNumNQFArr['0421'] = 2;//two Numerators
193 $countNumNQFArr['0024'] = 9;//Nine Numerators
195 //Initiation of all QRDA needed elements
196 $CQMeausesArr = array();
197 $CQMeausesArr['init_patients'] = "Initial Patient Population";
198 $CQMeausesArr['exclude_patients'] = "Denominator Exclusions";
199 $CQMeausesArr['denom_patients'] = "Denominator";
200 $CQMeausesArr['numer_patients'] = "Numerator";
201 $CQMeausesArr['exception_patients'] = "Denominator Exceptions";
203 $cqmItemizedArr = array();
204 $cqmItemizedArr['init_patients'] = "init_patients";
205 $cqmItemizedArr['exclude_patients'] = "exclude";
206 $cqmItemizedArr['denom_patients'] = "all";
207 $cqmItemizedArr['numer_patients'] = "pass";
208 $cqmItemizedArr['exception_patients'] = "exception";
210 //QRDA Needed Ethnicity
211 $mainEthiArr = array(0=>'Not Hispanic or Latino', 1=>'Hispanic or Latino');
212 $mainEthiCodeArr = array(0=>'2186-5', 1=>'2135-2');
214 //QRDA Needed Race
215 $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');
216 $mainQrdaRaceCodeArr = array(0=>'1002-5', 1=>'2028-9', 2=>'2054-5', 3=>'2076-8', 4=>'2106-3', 5=>'2131-1');
218 $mainQrdaPopulationIncArr = array();
219 $mainQrdaPopulationIncArr['init_patients'] = "IPP";
220 $mainQrdaPopulationIncArr['exclude_patients'] = "DENEX";
221 $mainQrdaPopulationIncArr['denom_patients'] = "DENOM";
222 $mainQrdaPopulationIncArr['numer_patients'] = "NUMER";
223 $mainQrdaPopulationIncArr['exception_patients'] = "DENEXCEP";
224 $mainQrdaPopulationIncArr['measure_population'] = "MSRPOPL";
225 $mainQrdaPopulationIncArr['numer_exclusion'] = "NUMEX";
227 //QRDA Needed Gender
228 $mainQrdaGenderCodeArr = array();
229 $mainQrdaGenderCodeArr['F'] = "Female";
230 $mainQrdaGenderCodeArr['M'] = "Male";
231 $mainQrdaGenderCodeArr['UN'] = "Unknown";
233 //QRDA Needed Payer Info
234 $mainQrdaPayerCodeArr = array();
235 $mainQrdaPayerCodeArr['A'] = "Medicare";
236 $mainQrdaPayerCodeArr['B'] = "Medicaid";
237 $mainQrdaPayerCodeArr['C'] = "Private Health Insurance";
238 $mainQrdaPayerCodeArr['D'] = "Other";
240 //Payer Codes According to Cypress Codes
241 $mainQrdaPayerCodeSendArr = array();
242 $mainQrdaPayerCodeSendArr['A'] = "1";
243 $mainQrdaPayerCodeSendArr['B'] = "2";
244 $mainQrdaPayerCodeSendArr['C'] = "5";
245 $mainQrdaPayerCodeSendArr['D'] = "349";
247 //Provider selection
248 $form_provider = $_GET['form_provider'];
250 //Get Report Information
251 $report_id = $_GET['report_id'];
252 $report_view = collectReportDatabase($report_id);
253 $target_date = $report_view['date_target'];
254 $dataSheet = json_decode($report_view['data'],TRUE);
256 //Needed array for Rule NQF#0024 Stratification
257 $stratumCheckArr = array();
258 if(count($dataSheet) > 0){
259 //Inner Data Loop
260 foreach ($dataSheet as $row) {
261 $itemized_test_id = $row['itemized_test_id'];
262 $numerator_label = $row['numerator_label'];
263 if($row['cqm_nqf_code'] == "0024"){
264 if( $row['population_label'] == "Population Criteria 2" ){
265 if($row['numerator_label'] == "Numerator 1"){
266 $stratum_1_ipp = $row['initial_population'];
267 $stratum_1_exclude = $row['excluded'];
268 $stratum_1_denom = $row['pass_filter'];
269 $stratum_1_numer1 = $row['pass_target'];
270 }else if($row['numerator_label'] == "Numerator 2"){
271 $stratum_1_numer2 = $row['pass_target'];
272 }else if($row['numerator_label'] == "Numerator 3"){
273 $stratum_1_numer3 = $row['pass_target'];
275 }else if( $row['population_label'] == "Population Criteria 3" ){
276 if($row['numerator_label'] == "Numerator 1"){
277 $stratum_2_ipp = $row['initial_population'];
278 $stratum_2_exclude = $row['excluded'];
279 $stratum_2_denom = $row['pass_filter'];
280 $stratum_2_numer1 = $row['pass_target'];
281 }else if($row['numerator_label'] == "Numerator 2"){
282 $stratum_2_numer2 = $row['pass_target'];
283 }else if($row['numerator_label'] == "Numerator 3"){
284 $stratum_2_numer3 = $row['pass_target'];
289 $stratum = array();
290 $stratum[1] = array('init_patients' => $stratum_1_ipp,
291 'exclude_patients' => $stratum_1_exclude,
292 'denom_patients' => $stratum_1_denom,
293 'numer_patients' => $stratum_1_numer1,
294 'numer2' => $stratum_1_numer2,
295 'numer3' => $stratum_1_numer3);
297 $stratum[2] = array('init_patients' => $stratum_2_ipp,
298 'exclude_patients' => $stratum_2_exclude,
299 'denom_patients' => $stratum_2_denom,
300 'numer_patients' => $stratum_2_numer1,
301 'numer2' => $stratum_2_numer2,
302 'numer3' => $stratum_2_numer3);
307 $from_date = date('Y', strtotime($target_date ))."-01-01";
308 $to_date = date('Y', strtotime($target_date ))."-12-31";
309 $xml = new QRDAXml();
311 #################################################################################################
312 ####################### HEADER ELEMENTS START #####################################################
313 #################################################################################################
314 //Open Main Clinical Document
315 $xml->open_clinicaldocument();
317 $xml->self_realmcode();
319 $xml->self_typeid();
321 $tempId = '2.16.840.1.113883.10.20.27.1.1';
322 $xml->self_templateid($tempId);
324 $xml->unique_id = getUuid();
325 $xml->self_id();
326 $xml->self_code();
328 //Main Title Display to XML
329 $main_title = "QRDA Calculated Summary Report";
330 $xml->add_title($main_title);
332 //Effective date and time
333 $eff_datetime = date('Ymdhis', strtotime($target_date));
334 $xml->self_efftime($eff_datetime);
336 $xml->self_confidentcode();
338 //Language
339 $xml->self_lang();
341 $setidVal =getUuid();
342 $xml->self_setid($setidVal);
344 //Version
345 $xml->self_version();
347 //Record Target Elements
348 $xml->open_recordTarget();
349 $xml->add_patientRole();
350 $xml->close_recordTarget();
352 ############### Author Info #######################
353 $xml->open_author();
354 //Author time
355 $auth_dtime = date('Ymdhis', strtotime(date('Y-m-d H:i:s')));
356 $xml->self_authorTime($auth_dtime);
357 //Assigned Author
358 $xml->open_assignAuthor();
359 $authorsetid = getUuid();
360 $xml->self_customId($authorsetid);
361 if($form_provider != ""){
362 $userRow = sqlQuery("SELECT facility, facility_id, federaltaxid, npi, phone,fname, lname FROM users WHERE id=?", array($form_provider));
363 $facility_name = $userRow['facility'];
364 $facility_id = $userRow['facility_id'];
366 //$xml->self_customTag('telecom', array('value' => $userRow['phone'], 'use'=>'WP'));
368 //assignedAuthoringDevice Start
369 $xml->open_customTag('assignedAuthoringDevice');
371 $xml->element('softwareName', 'CYPRESS');
373 //assignedAuthoringDevice Close
374 $xml->close_customTag();
376 //Facility Address
377 $facilResRow = $facilityService->getById($facility_id);
378 $xml->add_authReprestOrginisation($facilResRow);
379 //$xml->add_facilAddress($facilResRow);
380 $xml->close_assignAuthor();
381 $xml->close_author();
383 ############### Custodian Info #######################
384 $xml->open_custodian();
385 $xml->open_assgnCustodian();
386 $xml->add_represtCustodianOrginisation($facilResRow);
387 $xml->close_assgnCustodian();
388 $xml->close_custodian();
391 ############### Information Recipient #######################
392 $xml->open_infoRecipient();
393 $xml->add_indententRecipient();
394 $xml->close_infoRecipient();
397 ############### Legal Authenticator #######################
398 $xml->open_legalAuthenticator();
399 $auth_dtime = date('Ymdhis', strtotime(date('Y-m-d H:i:s')));
400 $xml->self_authorTime($auth_dtime);
401 $xml->self_legalSignCode();
403 $xml->open_assignedEntity();
404 $assignedEntityId = getUuid();
405 $xml->self_customId($assignedEntityId);
407 $xml->open_customTag('assignedPerson');
409 //Provider Name
410 $userNameArr = array('fname' =>$userRow['fname'], 'lname'=>$userRow['lname']);
411 $xml->add_providerName($userNameArr);
413 //assignedPerson Close
414 $xml->close_customTag();
416 //Represent Origination Name
417 $xml->add_authReprestOrginisation($facilResRow);
418 $xml->close_assignedEntity();
420 $xml->close_legalAuthenticator();
423 ############### Participant is Device(optional) #######################
424 $participentDevArr = array();
425 $xml->open_participant_data('DEV');//DEV -- Device
426 $xml->open_assocEntityData('RGPR');//RGPR -- Regulated Product
427 $participentDevArr['root'] = '2.16.840.1.113883.3.2074.1';
428 $participentDevArr['extension'] = '1a2b3c';
429 $xml->self_particpantIdInfo($participentDevArr);
430 $xml->self_participantCodeDevice();
431 $xml->close_assocEntityData();
432 $xml->close_participant_data();
434 ############### Participant is Location(optional) #######################
435 $participentLocArr = array();
436 $xml->open_participant_data('LOC');//LOC -- Location
437 $xml->open_assocEntityData('SDLOC');//SDLOC -- Service Delivery Location
438 $participentLocArr['root'] = '2.16.840.1.113883.3.249.5.1';
439 $participentLocArr['extension'] = 'OK666333';
440 $xml->self_particpantIdInfo($participentLocArr);
441 $xml->self_participantCodeLocation();
443 $xml->add_facilAddress($facilResRow);
444 $xml->close_assocEntityData();
445 $xml->close_participant_data();
448 ############### documentationOf START #######################
449 $xml->open_customTag('documentationOf');
451 $xml->open_customTag('serviceEvent', array('classCode'=>'PCPR'));
453 $timeArr = array('low'=>date('Ymd', strtotime($from_date)), 'high'=>date('Ymd', strtotime($to_date)));
454 $xml->add_entryEffectTime($timeArr);
456 $xml->open_customTag('performer', array('typeCode'=>'PRF'));
458 $xml->open_customTag('assignedEntity');
460 $npi_provider = !empty($userRow['npi']) ? $userRow['npi'] : '123456789';
461 $xml->self_customTag('id', array('root' => '2.16.840.1.113883.4.6', 'extension' =>$npi_provider));
463 if($userRow['phone'] != ""){
464 $xml->self_customTag('telecom', array('value' => $userRow['phone'], 'use'=>'WP'));
467 $xml->open_customTag('assignedPerson');
469 //Provider Name
470 $userNameArr = array('fname' =>$userRow['fname'], 'lname'=>$userRow['lname']);
471 $xml->add_providerName($userNameArr);
473 //assignedPerson Close
474 $xml->close_customTag();
476 $xml->open_customTag('representedOrganization');
478 $tin_provider = $userRow['federaltaxid'];
479 if($tin_provider != ""){
480 $xml->self_customTag('id', array('root' => '2.16.840.1.113883.4.2', 'extension' =>$tin_provider));
483 $xml->add_facilName($facility_name);
485 $xml->add_facilAddress($facilResRow);
487 //representedOrganization Close
488 $xml->close_customTag();
490 //assignedEntity Close
491 $xml->close_customTag();
493 //performer Close
494 $xml->close_customTag();
496 //serviceEvent Close
497 $xml->close_customTag();
499 //documentationOf Close
500 $xml->close_customTag();
501 ############### documentationOf END #######################
504 ############### authorization (optional) #########################
506 #################################################################################################
507 ####################### HEADER ELEMENTS END #####################################################
508 #################################################################################################
512 #################################################################################################
513 ######################### Main Component Open ###################################################
514 $xml->open_mainComponent();
516 ############### Structure Body Open #######################
517 $xml->open_structuredBody();
519 ##################### LOOP Component(s) START ########################
521 ###################### Report Parameters Open #####################
522 //QRDA Category III Reporting Parameters Section (CMS EP) [section: templateId 2.16.840.1.113883.10.20.27.2.6
523 $xml->open_loopComponent();
525 $xml->open_section();
527 $tempID = '2.16.840.1.113883.10.20.17.2.1';
528 $xml->self_templateid($tempID);
530 $tempID = '2.16.840.1.113883.10.20.27.2.2';
531 $xml->self_templateid($tempID);
533 $tempID = '2.16.840.1.113883.10.20.27.2.6';
534 $xml->self_templateid($tempID);
535 $arr = array('code'=>'55187-9', 'codeSystem'=>'2.16.840.1.113883.6.1');
536 $xml->self_codeCustom($arr);
537 $title = "Reporting Parameters";
538 $xml->add_title($title);
540 $xml->open_text();
541 $xml->open_list();
542 $item_title = "Reporting period: ".date('d M Y', strtotime($from_date))." - ".date('d M Y', strtotime($to_date));
543 $xml->add_item($item_title);
544 $xml->close_list();
545 $xml->close_text();
547 $typeCode = 'DRIV';
548 $xml->open_entry($typeCode);
549 $arr = array('classCode'=>'ACT', 'moodCode'=>'EVN');
550 $xml->open_act($arr);
552 $tempID = '2.16.840.1.113883.10.20.17.3.8';
553 $xml->self_templateid($tempID);
555 $tempID = '2.16.840.1.113883.10.20.27.3.23';
556 $xml->self_templateid($tempID);
558 $actId = getUuid();
559 $xml->self_customId($actId);
561 $arr = array('code'=>'252116004', 'codeSystem'=>'2.16.840.1.113883.6.96', 'displayName'=>'Observation Parameters');
562 $xml->self_codeCustom($arr);
564 $timeArr = array('low'=>date('Ymd', strtotime($from_date)), 'high'=>date('Ymd', strtotime($to_date)));
565 $xml->add_entryEffectTime($timeArr);
567 $xml->close_act();
568 $xml->close_entry();
570 $xml->close_section();
572 $xml->close_loopComponent();
573 ###################### Report Parameters Close #####################
575 ###################### Measure Section Open #####################
576 $xml->open_loopComponent();
578 $xml->open_section();
580 $tempID = '2.16.840.1.113883.10.20.27.2.1';
581 $xml->self_templateid($tempID);
583 $tempID = '2.16.840.1.113883.10.20.24.2.2';
584 $xml->self_templateid($tempID);
586 $tempID = '2.16.840.1.113883.10.20.27.2.3';
587 $xml->self_templateid($tempID);
589 $arr = array('code'=>'55186-1', 'codeSystem'=>'2.16.840.1.113883.6.1');
590 $xml->self_codeCustom($arr);
591 $title = "Measure Section";
592 $xml->add_title($title);
594 $xml->open_text();
595 $cnt=1;
597 $tabArr = array('border'=>1, 'width'=>'100%');
598 if(count($dataSheet) > 0){
599 $uniqIdArr = array();
601 //Inner Data Loop
602 foreach ($dataSheet as $row) {
603 $itemized_test_id = $row['itemized_test_id'];
604 $numerator_label = $row['numerator_label'];
606 //CQM Rules 2014 set, 0013 is 0018
607 if($row['cqm_nqf_code'] == "0013") $row['cqm_nqf_code'] = "0018";
609 //Table Start
610 $xml->open_customTag('table', $tabArr);
611 //THEAD Start
612 $xml->open_customTag('thead');
613 //TR Start
614 $xml->open_customTag('tr');
616 $xml->add_trElementsTitles();
618 //TR close
619 $xml->close_customTag();
621 //THEAD close
622 $xml->close_customTag();
623 //TBOBY START
624 $xml->open_customTag('tbody');
625 $xml->open_customTag('tr');
627 $tdTitle = generate_display_field(array('data_type'=>'1','list_id'=>'clinical_rules'),$row['id']);
629 if (!empty($row['cqm_pqri_code'])) {
630 $tdTitle .= " " . htmlspecialchars( xl('PQRI') . ":" . $row['cqm_pqri_code'], ENT_NOQUOTES) . " ";
632 if (!empty($row['cqm_nqf_code'])) {
633 $tdTitle .= " " . htmlspecialchars( xl('NQF') . ":" . $row['cqm_nqf_code'], ENT_NOQUOTES) . " ";
636 if ( !(empty($row['concatenated_label'])) ) {
637 $tdTitle .= ", " . htmlspecialchars( xl( $row['concatenated_label'] ), ENT_NOQUOTES) . " ";
640 $tdVersionNeutral = getUuid();
642 if($preDefinedUniqIDRules[$row['cqm_nqf_code']] != ""){
643 if( ($row['cqm_nqf_code'] == "0421" ) )
644 $tdVersionSpecific = $preDefinedUniqIDRules[$row['cqm_nqf_code']][$row['numerator_label']];
645 else if($row['cqm_nqf_code'] == "0024")
646 $tdVersionSpecific = $preDefinedUniqIDRules[$row['cqm_nqf_code']][$row['population_label']][$row['numerator_label']];
647 else
648 $tdVersionSpecific = $preDefinedUniqIDRules[$row['cqm_nqf_code']];
650 $uniqIdArr[] = $tdVersionSpecific;
651 }else{
652 $tdVersionSpecific = getUuid();
653 $uniqIdArr[] = $tdVersionSpecific;
656 $dataArr = array(0=>$tdTitle, 1=>$tdVersionNeutral, 2=>$tdVersionSpecific);
657 $xml->add_trElementsValues($dataArr);
659 //TR close
660 $xml->close_customTag();
661 //TBODY close
662 $xml->close_customTag();
663 //Table Close
664 $xml->close_customTag();
666 //Open List Item Wise
667 $xml->open_list();
669 //Performance Rate
670 $xml->open_customTag('item');
671 $arrContent = array('name'=>'Performance Rate', 'value'=>$row['percentage']);
672 $xml->innerContent($arrContent);
673 $xml->close_customTag();
676 //All CQM Measures taken here
677 foreach($CQMeausesArr as $cqmKey => $cqmVal){
679 //DENEXCEP(Denominator Exception not needed for some rules are skipping here)
680 if( (in_array($row['cqm_nqf_code'], $denExcepNotNeedRules) ) && ($cqmKey == "exception_patients") ) continue;
682 //get Itemized Data
683 if($cqmKey == "init_patients")
684 $itemPatArr = collectItemizedPatientsCdrReport($report_id,$itemized_test_id,$cqmItemizedArr[$cqmKey]);
685 else
686 $itemPatArr = collectItemizedPatientsCdrReport($report_id,$itemized_test_id,$cqmItemizedArr[$cqmKey], $numerator_label);
687 $fullPatArr = array();
688 foreach($itemPatArr as $itemPatInfo){
689 $fullPatArr[] = $itemPatInfo['pid'];
692 //Initial Patient Population
693 $xml->open_customTag('item');
694 $arrContent = array('name'=>$cqmVal, 'value'=>count($fullPatArr));
695 $xml->innerContent($arrContent);
697 $detailsArr = getQRDAPatientNeedInfo($fullPatArr);
699 //Open Sub List
700 $xml->open_list();
702 //Gender Section Display
703 foreach($mainQrdaGenderCodeArr as $GKey => $GVal){
704 $xml->open_customTag('item');
705 $genderInfo = $detailsArr['gender'][$GVal];
706 $arrContent = array('name'=>$GVal, 'value'=>$genderInfo);
707 $xml->innerContent($arrContent);
708 $xml->close_customTag();
711 //Ethnicity Section Display
712 foreach($mainEthiArr as $ethKey => $ethVal){
713 $ethnicity_data = $detailsArr['ethnicity'][$ethVal];
714 $xml->open_customTag('item');
715 $arrContent = array('name'=>'Ethnicity - '.$ethVal, 'value'=>$ethnicity_data);
716 $xml->innerContent($arrContent);
717 $xml->close_customTag();
720 //Race Section Display
721 foreach($mainQrdaRaceArr as $RKey => $RVal){
722 $race_data = $detailsArr['race'][$RVal];
723 $xml->open_customTag('item');
724 $arrContent = array('name'=>'Race - '.$RVal, 'value'=>$race_data);
725 $xml->innerContent($arrContent);
726 $xml->close_customTag();
729 //Payer Type Section Display
730 $payerCheckArr = getQRDAPayerInfo($fullPatArr);
731 foreach($mainQrdaPayerCodeArr as $PKey => $PVal){
732 $xml->open_customTag('item');
733 $arrContent = array('name'=>'Payer - '.$PVal, 'value'=>$payerCheckArr[$PVal]);
734 $xml->innerContent($arrContent);
735 $xml->close_customTag();
738 //close Sub List
739 $xml->close_list();
740 $xml->close_customTag();
742 $xml->close_list();
746 $xml->close_text();
748 #######################################################################
749 ######################### QUALITY MEASURES START ######################
750 #######################################################################
751 if(count($dataSheet) > 0){
752 $innrCnt = 0;
753 $skipMultNumArr = array();
754 $dataChkArr = array();
755 foreach($multNumNQFArr as $multNumVal){
756 $skipMultNumArr[$multNumVal] = false;
757 $dataChkArr[$multNumVal] = 0;
760 //Inner Data Loop
761 foreach ($dataSheet as $row) {
762 $itemized_test_id = $row['itemized_test_id'];
763 $numerator_label = $row['numerator_label'];
764 //Skip section
765 //if($row['cqm_nqf_code'] == "0028a") continue;
767 //if($row['cqm_nqf_code'] == "0038"){
768 // if(in_array($row['numerator_label'], $NQF38NumArr)) continue;
771 if(in_array($row['cqm_nqf_code'], $multNumNQFArr)){
772 $dataChkArr[$row['cqm_nqf_code']]++;
775 //CQM Rules 2014 set, 0013 is 0018
776 if($row['cqm_nqf_code'] == "0013") $row['cqm_nqf_code'] = "0018";
778 $tdTitle = generate_display_field(array('data_type'=>'1','list_id'=>'clinical_rules'),$row['id']);
779 if (!empty($row['cqm_pqri_code'])) {
780 $tdTitle .= " " . text( xl('PQRI') . ":" . $row['cqm_pqri_code']) . " ";
782 if (!empty($row['cqm_nqf_code'])) {
783 $tdTitle .= " " . text( xl('NQF') . ":" . $row['cqm_nqf_code']) . " ";
786 if ( !(empty($row['concatenated_label'])) ) {
787 $tdTitle .= ", " . text( xl( $row['concatenated_label'] )) . " ";
790 ###########################################################
791 if( ( !isset($skipMultNumArr[$row['cqm_nqf_code']]) ) || ($skipMultNumArr[$row['cqm_nqf_code']] == false) ){
793 //Entry open
794 $xml->open_entry();
796 //Organizer Start
797 $arr = array('classCode'=>'CLUSTER', 'moodCode'=>'EVN');
798 $xml->open_customTag('organizer', $arr);
800 $tempID = "2.16.840.1.113883.10.20.24.3.98";
801 $xml->self_templateid($tempID);
803 $tempID = "2.16.840.1.113883.10.20.27.3.1";
804 $xml->self_templateid($tempID);
806 //$tempID = "2.16.840.1.113883.10.20.27.3.17";
807 //$xml->self_templateid($tempID);
808 $actId = getUuid();
809 $xml->self_customId($actId);
811 $arr = array('code'=>'completed');
812 $xml->self_customTag('statusCode', $arr);
814 //reference Start
815 $arr = array('typeCode'=>'REFR');
816 $xml->open_customTag('reference', $arr);
818 //externalDocument Start
819 $arr = array('classCode'=>'DOC', 'moodCode'=>'EVN');
820 $xml->open_customTag('externalDocument', $arr);
822 //$exDocID = getUuid();
823 $exDocID = $uniqIdArr[$innrCnt];
824 //$xml->self_customId($exDocID);
825 $xml->self_customTag('id', array('root' => '2.16.840.1.113883.4.738', 'extension' =>$exDocID));
827 $arr = array('code'=>'57024-2', 'displayName'=>'Health Quality Measure Document', 'codeSystem'=>'2.16.840.1.113883.6.1', 'codeSystemName'=>'LOINC');
828 $xml->self_codeCustom($arr);
830 $dispContntTitle = str_replace("&", '', $tdTitle);
831 $xml->textDispContent($dispContntTitle);
833 //externalDocument Close
834 $xml->close_customTag();
836 //reference Close
837 $xml->close_customTag();
840 ############### Performance Rate for Proportion Measure template START###################
841 $xml->open_loopComponent();
843 //observation Open
844 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
846 $tempID = "2.16.840.1.113883.10.20.27.3.14";
847 $xml->self_templateid($tempID);
849 $tempID = "2.16.840.1.113883.10.20.27.3.25";
850 $xml->self_templateid($tempID);
852 $arr = array('code'=>'72510-1', 'displayName'=>'Performance Rate', 'codeSystem'=>'2.16.840.1.113883.6.1', 'codeSystemName'=>'SNOMED-CT');
853 $xml->self_codeCustom($arr);
855 $arr = array('code'=>'completed');
856 $xml->self_customTag('statusCode', $arr);
858 $percentage = str_replace("%", '', $row['percentage']);
859 $arr = array('xsi:type'=>'REAL', 'value'=>$percentage/100);
860 $xml->self_customTag('value', $arr);
862 //reference Start
863 $arr = array('typeCode'=>'REFR');
864 $xml->open_customTag('reference', $arr);
866 //externalObservation Start
867 $arr = array('classCode'=>'OBS', 'moodCode'=>'EVN');
868 $xml->open_customTag('externalObservation', $arr);
870 //Modified HQMF_ID
871 //$exDocID = getUuid();
874 if( ($row['cqm_nqf_code'] == "0421" )){
875 $exDocID = $preDefPopIdArr[$row['cqm_nqf_code']][$row['numerator_label']]["NUMER"];
876 }else if(($row['cqm_nqf_code'] == "0024")){
877 $exDocID = $preDefPopIdArr[$row['cqm_nqf_code']][$row['population_label']][$row['numerator_label']]["NUMER"];
878 }else{
879 if($preDefPopIdArr[$row['cqm_nqf_code']]["NUMER"] != "")
880 $exDocID = $preDefPopIdArr[$row['cqm_nqf_code']]["NUMER"];
881 else
882 $exDocID = getUuid();
885 $xml->self_customId($exDocID);
887 $arr = array('code'=>'NUMER', 'displayName'=>'Numerator', 'codeSystem'=>'2.16.840.1.113883.5.1063', 'codeSystemName'=>'ObservationValue');
888 $xml->self_codeCustom($arr);
890 //externalObservation Close
891 $xml->close_customTag();
893 //reference Close
894 $xml->close_customTag();
896 //observation Close
897 $xml->close_customTag();
899 $xml->close_loopComponent();
900 ############### Performance Rate for Proportion Measure template END ###################
904 //All CQM Measures taken here
905 foreach($CQMeausesArr as $cqmKey => $cqmVal){
907 //DENEXCEP(Denominator Exception not needed for some rules are skipping here)
908 if( (in_array($row['cqm_nqf_code'], $denExcepNotNeedRules) ) && ($cqmKey == "exception_patients") ) continue;
910 //cqm 0024 alllowing only nuemerator 2 and numerator 3 for ipp1,ipp2 and 1pp3 to avoid repeatation
911 if($row['cqm_nqf_code'] == '0024' && ($row['numerator_label'] == "Numerator 2" || $row['numerator_label'] == "Numerator 3") && $cqmKey != 'numer_patients') continue;
912 if($row['cqm_nqf_code'] == '0024' && ($row['population_label'] == "Population Criteria 2" || $row['population_label'] == "Population Criteria 3")) continue;
915 //get Itemized Data
916 if($cqmKey == "init_patients")
917 $itemPatArr = collectItemizedPatientsCdrReport($report_id,$itemized_test_id,$cqmItemizedArr[$cqmKey]);
918 else
919 $itemPatArr = collectItemizedPatientsCdrReport($report_id,$itemized_test_id,$cqmItemizedArr[$cqmKey], $numerator_label);
921 $fullPatArr = array();
922 foreach($itemPatArr as $itemPatInfo){
923 $fullPatArr[] = $itemPatInfo['pid'];
926 $detailsArr = getQRDAPatientNeedInfo($fullPatArr);
927 ############### Initial patient population template START###################
928 $xml->open_loopComponent();
930 //observation Open
931 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
933 $tempID = "2.16.840.1.113883.10.20.27.3.5";
934 $xml->self_templateid($tempID);
936 $tempID = "2.16.840.1.113883.10.20.27.3.16";
937 $xml->self_templateid($tempID);
939 $arr = array('code'=>'ASSERTION', 'displayName'=>'Assertion', 'codeSystem'=>'2.16.840.1.113883.5.4', 'codeSystemName'=>'ActCode');
940 $xml->self_codeCustom($arr);
942 $arr = array('code'=>'completed');
943 $xml->self_customTag('statusCode', $arr);
945 $arr = array('xsi:type'=>'CD', 'code'=>$mainQrdaPopulationIncArr[$cqmKey], 'displayName'=>$cqmVal, 'codeSystem' =>'2.16.840.1.113883.5.1063', 'codeSystemName'=>'ObservationValue');
946 $xml->self_customTag('value', $arr);
948 //entryRelationship Open
949 $xml->open_customTag('entryRelationship', array('typeCode'=>'SUBJ', 'inversionInd'=>'true'));
951 //observation Open
952 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
954 $tempID = "2.16.840.1.113883.10.20.27.3.3";
955 $xml->self_templateid($tempID);
957 $tempID = "2.16.840.1.113883.10.20.27.3.24";
958 $xml->self_templateid($tempID);
960 $arr = array('code'=>'MSRAGG', 'displayName'=>'rate aggregation', 'codeSystem'=>'2.16.840.1.113883.5.4', 'codeSystemName'=>'ActCode');
961 $xml->self_codeCustom($arr);
963 //$arr = array('code'=>'completed');
964 //$xml->self_customTag('statusCode', $arr);
966 $arr = array('xsi:type'=>'INT', 'value'=>count($fullPatArr));
967 $xml->self_customTag('value', $arr);
969 $arr = array('code'=>'COUNT', 'displayName'=>'Count', 'codeSystem'=>'2.16.840.1.113883.5.84', 'codeSystemName'=>'ObservationMethod');
970 $xml->self_customTag('methodCode', $arr);
972 //observation Close
973 $xml->close_customTag();
975 //entryRelationship Close
976 $xml->close_customTag();
978 #### Stratum Start (Stratification)#####
979 if($row['cqm_nqf_code'] == '0024'){
980 $strat_count = 1;
981 for(;$strat_count <= 2;$strat_count++){
983 $strata_value = $stratum[$strat_count][$cqmKey];
985 if($row['numerator_label'] == "Numerator 2") $strata_value = $stratum[$strat_count]['numer2'];
987 else if($row['numerator_label'] == "Numerator 3") $strata_value = $stratum[$strat_count]['numer3'];
989 //entryRelationship Open
990 $xml->open_customTag('entryRelationship', array('typeCode'=>'COMP'));
992 //observation Open
993 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
995 $tempID = "2.16.840.1.113883.10.20.27.3.4";
996 $xml->self_templateid($tempID);
998 $tempID = "2.16.840.1.113883.10.20.27.3.20";
999 $xml->self_templateid($tempID);
1001 $arr = array('code'=>'ASSERTION', 'displayName'=>'Assertion', 'codeSystem'=>'2.16.840.1.113883.5.4', 'codeSystemName'=>'ActCode');
1002 $xml->self_codeCustom($arr);
1004 $arr = array('code'=>'completed');
1005 $xml->self_customTag('statusCode', $arr);
1007 //value open
1008 $xml->open_customTag('value', array('xsi:type'=>'CD', 'nullFlavor'=>'OTH'));
1010 $stratumText = $preDefPopIdArr[$row['cqm_nqf_code']][$row['population_label']][$row['numerator_label']]['DISPLAY_TEXT'];
1011 $xml->element('originalText', "Stratum ".$strat_count);
1013 //value Close
1014 $xml->close_customTag();
1016 //entryRelationship Open
1017 $xml->open_customTag('entryRelationship', array('typeCode'=>'SUBJ', 'inversionInd' => 'true'));
1019 //observation Open
1020 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
1022 $tempID = "2.16.840.1.113883.10.20.27.3.3";
1023 $xml->self_templateid($tempID);
1025 $arr = array('code'=>'MSRAGG', 'displayName'=>'rate aggregation', 'codeSystem'=>'2.16.840.1.113883.5.4', 'codeSystemName'=>'ActCode');
1026 $xml->self_codeCustom($arr);
1028 $arr = array('xsi:type'=>'INT', 'value'=>$strata_value);
1029 $xml->self_customTag('value', $arr);
1031 $arr = array('code'=>'COUNT', 'displayName'=>'Count', 'codeSystem'=>'2.16.840.1.113883.5.84', 'codeSystemName'=>'ObservationMethod');
1032 $xml->self_customTag('methodCode', $arr);
1034 //observation Close
1035 $xml->close_customTag();
1037 //entryRelationship Close
1038 $xml->close_customTag();
1040 //reference Start
1041 $arr = array('typeCode'=>'REFR');
1042 $xml->open_customTag('reference', $arr);
1044 //externalObservation Start
1045 $arr = array('classCode'=>'OBS', 'moodCode'=>'EVN');
1046 $xml->open_customTag('externalObservation', $arr);
1048 //Modified HQMF_ID for CQM IDS
1049 //$refID = $preDefPopIdArr[$row['cqm_nqf_code']][$row['population_label']][$row['numerator_label']]['STRAT'];
1050 $refID = $preDefPopIdArr[$row['cqm_nqf_code']]['STRAT'.$strat_count];
1052 $xml->self_customId($refID);
1054 //externalObservation Close
1055 $xml->close_customTag();
1057 //reference Close
1058 $xml->close_customTag();
1060 //observation Close
1061 $xml->close_customTag();
1063 //entryRelationship Close
1064 $xml->close_customTag();
1068 #### Stratum END #####
1070 ####################################################
1071 ####################################################
1072 //Sex Supplemental Data Element START
1073 ####################################################
1074 ####################################################
1076 foreach($mainQrdaGenderCodeArr as $GKey => $GVal){
1077 //entryRelationship Open
1078 $xml->open_customTag('entryRelationship', array('typeCode'=>'COMP'));
1080 //observation Open
1081 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
1083 $tempID = "2.16.840.1.113883.10.20.27.3.6";
1084 $xml->self_templateid($tempID);
1086 $tempID = "2.16.840.1.113883.10.20.27.3.21";
1087 $xml->self_templateid($tempID);
1089 $arr = array('code'=>'184100006', 'displayName'=>'patient sex', 'codeSystem'=>'2.16.840.1.113883.6.96', 'codeSystemName'=>'SNOMED-CT');
1090 $xml->self_codeCustom($arr);
1092 $arr = array('code'=>'completed');
1093 $xml->self_customTag('statusCode', $arr);
1095 $arr = array('xsi:type'=>'CD', 'code'=>$GKey, 'codeSystem' =>'2.16.840.1.113883.5.1', 'codeSystemName'=>'AdministrativeGenderCode');
1096 $xml->self_customTag('value', $arr);
1098 //entryRelationship Open
1099 $xml->open_customTag('entryRelationship', array('typeCode'=>'SUBJ', 'inversionInd'=>'true'));
1101 //observation Open
1102 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
1104 $tempID = "2.16.840.1.113883.10.20.27.3.3";
1105 $xml->self_templateid($tempID);
1107 $tempID = "2.16.840.1.113883.10.20.27.3.24";
1108 $xml->self_templateid($tempID);
1110 $arr = array('code'=>'MSRAGG', 'displayName'=>'rate aggregation', 'codeSystem'=>'2.16.840.1.113883.5.4', 'codeSystemName'=>'ActCode');
1111 $xml->self_codeCustom($arr);
1113 //$arr = array('code'=>'completed');
1114 //$xml->self_customTag('statusCode', $arr);
1116 $arr = array('xsi:type'=>'INT', 'value'=>$detailsArr['gender'][$GVal]);
1117 $xml->self_customTag('value', $arr);
1119 $arr = array('code'=>'COUNT', 'displayName'=>'Count', 'codeSystem'=>'2.16.840.1.113883.5.84', 'codeSystemName'=>'ObservationMethod');
1120 $xml->self_customTag('methodCode', $arr);
1122 //observation Close
1123 $xml->close_customTag();
1125 //entryRelationship Close
1126 $xml->close_customTag();
1129 //observation Close
1130 $xml->close_customTag();
1132 //entryRelationship Close
1133 $xml->close_customTag();
1135 ####################################################
1136 ####################################################
1137 //Sex Supplemental Data Element END
1138 ####################################################
1139 ####################################################
1141 ####################################################
1142 ####################################################
1143 //Ethnicity Supplemental Data Element (CMS EP) START
1144 ####################################################
1145 ####################################################
1147 foreach($mainEthiArr as $ethKey => $ethVal){
1148 //entryRelationship Open
1149 $xml->open_customTag('entryRelationship', array('typeCode'=>'COMP'));
1151 //observation Open
1152 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
1154 $tempID = "2.16.840.1.113883.10.20.27.3.7";
1155 $xml->self_templateid($tempID);
1157 $tempID = "2.16.840.1.113883.10.20.27.3.22";
1158 $xml->self_templateid($tempID);
1160 $arr = array('code'=>'364699009', 'displayName'=>'Ethnic Group', 'codeSystem'=>'2.16.840.1.113883.6.96', 'codeSystemName'=>'SNOMED-CT');
1161 $xml->self_codeCustom($arr);
1163 $arr = array('code'=>'completed');
1164 $xml->self_customTag('statusCode', $arr);
1166 $arr = array('xsi:type'=>'CD', 'code'=>$mainEthiCodeArr[$ethKey], 'displayName'=>$ethVal, 'codeSystem' =>'2.16.840.1.113883.6.238', 'codeSystemName'=>'Race &amp; Ethnicity - CDC');
1167 $xml->self_customTag('value', $arr);
1169 //entryRelationship Open
1170 $xml->open_customTag('entryRelationship', array('typeCode'=>'SUBJ', 'inversionInd'=>'true'));
1172 //observation Open
1173 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
1175 $tempID = "2.16.840.1.113883.10.20.27.3.3";
1176 $xml->self_templateid($tempID);
1178 $tempID = "2.16.840.1.113883.10.20.27.3.24";
1179 $xml->self_templateid($tempID);
1181 $arr = array('code'=>'MSRAGG', 'displayName'=>'rate aggregation', 'codeSystem'=>'2.16.840.1.113883.5.4', 'codeSystemName'=>'ActCode');
1182 $xml->self_codeCustom($arr);
1184 //$arr = array('code'=>'completed');
1185 //$xml->self_customTag('statusCode', $arr);
1187 $arr = array('xsi:type'=>'INT', 'value'=>$detailsArr['ethnicity'][$ethVal]);
1188 $xml->self_customTag('value', $arr);
1190 $arr = array('code'=>'COUNT', 'displayName'=>'Count', 'codeSystem'=>'2.16.840.1.113883.5.84', 'codeSystemName'=>'ObservationMethod');
1191 $xml->self_customTag('methodCode', $arr);
1193 //observation Close
1194 $xml->close_customTag();
1196 //entryRelationship Close
1197 $xml->close_customTag();
1200 //observation Close
1201 $xml->close_customTag();
1203 //entryRelationship Close
1204 $xml->close_customTag();
1207 ####################################################
1208 ####################################################
1209 //Ethnicity Supplemental Data Element (CMS EP) END
1210 ####################################################
1211 ####################################################
1214 ####################################################
1215 ####################################################
1216 //Race Supplemental Data Element (CMS EP) START
1217 ####################################################
1218 ####################################################
1220 foreach($mainQrdaRaceArr as $RKey => $RVal){
1221 //entryRelationship Open
1222 $xml->open_customTag('entryRelationship', array('typeCode'=>'COMP'));
1224 //observation Open
1225 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
1227 $tempID = "2.16.840.1.113883.10.20.27.3.8";
1228 $xml->self_templateid($tempID);
1230 $tempID = "2.16.840.1.113883.10.20.27.3.19";
1231 $xml->self_templateid($tempID);
1233 $arr = array('code'=>'103579009', 'displayName'=>'Race', 'codeSystem'=>'2.16.840.1.113883.6.96', 'codeSystemName'=>'SNOMED-CT');
1234 $xml->self_codeCustom($arr);
1236 $arr = array('code'=>'completed');
1237 $xml->self_customTag('statusCode', $arr);
1239 $arr = array('xsi:type'=>'CD', 'code'=>$mainQrdaRaceCodeArr[$RKey], 'displayName'=>$RVal, 'codeSystem' =>'2.16.840.1.113883.6.238', 'codeSystemName'=>'Race &amp; Ethnicity - CDC');
1240 $xml->self_customTag('value', $arr);
1242 //entryRelationship Open
1243 $xml->open_customTag('entryRelationship', array('typeCode'=>'SUBJ', 'inversionInd'=>'true'));
1245 //observation Open
1246 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
1248 $tempID = "2.16.840.1.113883.10.20.27.3.3";
1249 $xml->self_templateid($tempID);
1251 $tempID = "2.16.840.1.113883.10.20.27.3.24";
1252 $xml->self_templateid($tempID);
1254 $arr = array('code'=>'MSRAGG', 'displayName'=>'rate aggregation', 'codeSystem'=>'2.16.840.1.113883.5.4', 'codeSystemName'=>'ActCode');
1255 $xml->self_codeCustom($arr);
1257 //$arr = array('code'=>'completed');
1258 //$xml->self_customTag('statusCode', $arr);
1260 $arr = array('xsi:type'=>'INT', 'value'=>$detailsArr['race'][$RVal]);
1261 $xml->self_customTag('value', $arr);
1263 $arr = array('code'=>'COUNT', 'displayName'=>'Count', 'codeSystem'=>'2.16.840.1.113883.5.84', 'codeSystemName'=>'ObservationMethod');
1264 $xml->self_customTag('methodCode', $arr);
1266 //observation Close
1267 $xml->close_customTag();
1269 //entryRelationship Close
1270 $xml->close_customTag();
1273 //observation Close
1274 $xml->close_customTag();
1276 //entryRelationship Close
1277 $xml->close_customTag();
1280 ####################################################
1281 ####################################################
1282 //Race Supplemental Data Element (CMS EP) END
1283 ####################################################
1284 ####################################################
1287 ####################################################
1288 ####################################################
1289 //Payer Supplemental Data Element (CMS EP) START
1290 ####################################################
1291 ####################################################
1292 $payerCheckArr = getQRDAPayerInfo($fullPatArr);
1293 foreach($mainQrdaPayerCodeArr as $PKey => $PVal){
1294 //entryRelationship Open
1295 $xml->open_customTag('entryRelationship', array('typeCode'=>'COMP'));
1297 //observation Open
1298 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
1300 $tempID = "2.16.840.1.113883.10.20.27.3.9";
1301 $xml->self_templateid($tempID);
1303 $tempID = "2.16.840.1.113883.10.20.24.3.55";
1304 $xml->self_templateid($tempID);
1306 $tempID = "2.16.840.1.113883.10.20.27.3.18";
1307 $xml->self_templateid($tempID);
1309 $xml->self_setpatientRoleid();
1311 $arr = array('code'=>'48768-6', 'displayName'=>'Payment source', 'codeSystem'=>'2.16.840.1.113883.6.1', 'codeSystemName'=>'SNOMED-CT');
1312 $xml->self_codeCustom($arr);
1314 $arr = array('code'=>'completed');
1315 $xml->self_customTag('statusCode', $arr);
1317 $timeArr = array('low'=>date('Ymd', strtotime($from_date)));
1318 $xml->add_entryEffectTime($timeArr);
1321 //Value Tag Open
1322 $xml->open_customTag('value', array('xsi:type'=>'CD', 'nullFlavor'=>'OTH'));
1324 $xml->self_customTag('translation', array('code'=>$PKey, 'displayName'=>$PVal, 'codeSystem'=>'2.16.840.1.113883.3.249.12', 'codeSystemName'=>'CMS Clinical Codes'));
1326 //Value Tag Close
1327 $xml->close_customTag();
1330 //Value Tag
1331 $xml->self_customTag('value', array('xsi:type'=>'CD', 'code'=>$mainQrdaPayerCodeSendArr[$PKey], 'codeSystem'=>'2.16.840.1.113883.3.221.5' , 'codeSystemName'=>'SOP', 'displayName'=>$PVal));
1333 //entryRelationship Open
1334 $xml->open_customTag('entryRelationship', array('typeCode'=>'SUBJ', 'inversionInd'=>'true'));
1336 //observation Open
1337 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
1339 $tempID = "2.16.840.1.113883.10.20.27.3.3";
1340 $xml->self_templateid($tempID);
1342 $tempID = "2.16.840.1.113883.10.20.27.3.24";
1343 $xml->self_templateid($tempID);
1345 $arr = array('code'=>'MSRAGG', 'displayName'=>'rate aggregation', 'codeSystem'=>'2.16.840.1.113883.5.4', 'codeSystemName'=>'ActCode');
1346 $xml->self_codeCustom($arr);
1348 //$arr = array('code'=>'completed');
1349 //$xml->self_customTag('statusCode', $arr);
1351 $arr = array('xsi:type'=>'INT', 'value'=>$payerCheckArr[$PVal]);
1352 $xml->self_customTag('value', $arr);
1354 $arr = array('code'=>'COUNT', 'displayName'=>'Count', 'codeSystem'=>'2.16.840.1.113883.5.84', 'codeSystemName'=>'ObservationMethod');
1355 $xml->self_customTag('methodCode', $arr);
1357 //observation Close
1358 $xml->close_customTag();
1360 //entryRelationship Close
1361 $xml->close_customTag();
1364 //observation Close
1365 $xml->close_customTag();
1367 //entryRelationship Close
1368 $xml->close_customTag();
1371 ####################################################
1372 ####################################################
1373 //Payer Supplemental Data Element (CMS EP) END
1374 ####################################################
1375 ####################################################
1377 ######################################################################
1378 //reference Start
1379 $arr = array('typeCode'=>'REFR');
1380 $xml->open_customTag('reference', $arr);
1382 //externalObservation Start
1383 $arr = array('classCode'=>'OBS', 'moodCode'=>'EVN');
1384 $xml->open_customTag('externalObservation', $arr);
1386 //Modified HQMF_ID for CQM IDS
1387 if( ($row['cqm_nqf_code'] == "0421" ) ){
1388 $refID = $preDefPopIdArr[$row['cqm_nqf_code']][$row['numerator_label']][$mainQrdaPopulationIncArr[$cqmKey]];
1389 }else if( ($row['cqm_nqf_code'] == "0024") ){
1390 $refID = $preDefPopIdArr[$row['cqm_nqf_code']][$row['population_label']][$row['numerator_label']][$mainQrdaPopulationIncArr[$cqmKey]];
1391 }else{
1392 $refID = $preDefPopIdArr[$row['cqm_nqf_code']][$mainQrdaPopulationIncArr[$cqmKey]];
1394 if($refID == ""){
1395 $refID = getUuid();
1397 $xml->self_customId($refID);
1399 //externalObservation Close
1400 $xml->close_customTag();
1402 //reference Close
1403 $xml->close_customTag();
1404 ########################################################################
1406 //observation Close
1407 $xml->close_customTag();
1409 $xml->close_loopComponent();
1410 ############### Initial patient population template END#####################
1413 //Multiple Numerator Handling
1414 if(in_array($row['cqm_nqf_code'], $multNumNQFArr)){
1415 //Skipping Multiple Numerator(s)
1416 if(in_array($row['cqm_nqf_code'], $multNumNQFArr)){
1417 $skipMultNumArr[$row['cqm_nqf_code']] = true;
1419 if($dataChkArr[$row['cqm_nqf_code']] == $countNumNQFArr[$row['cqm_nqf_code']]){
1420 //Organizer Close
1421 $xml->close_customTag();
1422 $xml->close_entry();
1424 }else{
1425 //Organizer Close
1426 $xml->close_customTag();
1427 $xml->close_entry();
1430 ###########################################################
1432 $innrCnt++;
1436 #######################################################################
1437 ######################### QUALITY MEASURES END ########################
1438 #######################################################################
1441 $xml->close_section();
1443 $xml->close_loopComponent();
1445 ##################### LOOP Component(s) END ########################
1447 $xml->close_structuredBody();
1448 ############### Structure Body Close #######################
1450 $xml->close_mainComponent();
1451 ############### Main Component Close #######################
1453 //Close Main Clinical Document
1454 $xml->close_clinicaldocument();
1457 //QRDA File Download Folder in site/cqm_qrda folder
1458 $qrda_fname = "QRDA_III_".date("YmdHis").".xml";
1459 $qrda_file_path = $GLOBALS['OE_SITE_DIR'] . "/documents/cqm_qrda/";
1460 if(!file_exists($qrda_file_path)){
1461 mkdir($qrda_file_path, 0777, true);
1463 $qrda_file_name = $qrda_file_path.$qrda_fname;
1464 $fileQRDAOPen = fopen($qrda_file_name, "w");
1465 fwrite($fileQRDAOPen, trim($xml->getXml()));
1466 fclose($fileQRDAOPen);
1469 <html>
1470 <head>
1471 <?php html_header_show();?>
1472 <script type="text/javascript" src="<?php echo $webroot ?>/interface/main/tabs/js/include_opener.js"></script>
1473 <link rel=stylesheet href="<?php echo $css_header;?>" type="text/css">
1474 <title><?php echo xlt('Export QRDA Report'); ?></title>
1476 <script type="text/javascript">
1477 //Close Me function
1478 function closeme() {
1479 window.close();
1481 </script>
1482 </head>
1483 <body>
1485 <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>
1487 <center>
1488 <form>
1489 <p class="text">
1490 <a href="qrda_download.php?qrda_fname=<?php echo attr($qrda_fname);?>"><?php echo xlt("Download QRDA Category III File");?></a>
1491 </p>
1492 <textarea rows='50' cols='500' style='width:95%' readonly>
1493 <?php echo trim($xml->getXml()); ?>
1494 </textarea>
1496 <p><input type='button' value='<?php echo xla('Close'); ?>' onclick='closeme();' /></p>
1497 </form>
1498 </center>
1501 </body>
1502 </html>