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>;.
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 "$srcdir/report_database.inc";
37 require_once "qrda_functions.php";
39 //Remove time limit, since script can take many minutes
42 //DENEXCEP NOT NEEDED rules
43 $denExcepNotNeedRules = array('0002', '0018', '0024', '0038', '0043', '0059', '0421');
45 //Predefined QRDA HQMF ID's for CQM rules
46 $preDefinedUniqIDRules = array();
47 $preDefPopIdArr = array();
49 // CMS147v4/0041 - Preventive Care and Screening: Influenza Immunization HQMF ID: 40280381-4600-425F-0146-EE66F0005509
50 $preDefinedUniqIDRules['0041'] = '40280381-4600-425F-0146-EE66F0005509';
51 $preDefPopIdArr['0041']['IPP'] = 'F48702E6-D39A-49D8-BE3C-8FAB5C6AADDA';
52 $preDefPopIdArr['0041']['DENOM'] = 'B61EC2DC-0841-4906-A84B-5BE5024DA7F1';
53 $preDefPopIdArr['0041']['NUMER'] = '0ED7B212-369B-489A-A5B5-07BC146FA557';
54 $preDefPopIdArr['0041']['DENEXCEP'] = 'B5C9EC50-3011-43DC-AD07-CED2D3B770B2';
56 // CMS122v3/0059 - Diabetes: Hemoglobin A1c Poor Control: HQMF_ID: 40280381-4555-E1C1-0145-90AC70DE2C73
57 $preDefinedUniqIDRules['0059'] = '40280381-4555-E1C1-0145-90AC70DE2C73';
58 $preDefPopIdArr['0059']['IPP'] = 'EDED90E9-E4FE-47E6-90AC-29D9AA3E861A';
59 $preDefPopIdArr['0059']['DENOM'] = '6721D6DA-E87D-4E42-A34A-C8490686598C';
60 $preDefPopIdArr['0059']['NUMER'] = '7549BA9E-1841-4231-8CAA-095BDF0AB8A1';
63 //CMS139v3/0101 - Falls: Screening for Future Fall Risk: HQMF_ID: 40280381-4555-E1C1-0145-672613970D15
64 $preDefinedUniqIDRules['0101'] = '40280381-4555-E1C1-0145-672613970D15';
65 $preDefPopIdArr['0101']['IPP'] = '2448B0C6-6848-4DCB-AA6D-F199337A2C5C';
66 $preDefPopIdArr['0101']['DENOM'] = 'EC400908-35BE-439B-92A9-231D99CEA9DF';
67 $preDefPopIdArr['0101']['NUMER'] = '663FB12B-0FF4-49AB-80A3-624C5E7DF892';
68 $preDefPopIdArr['0101']['DENEXCEP'] = 'FEC7251A-BF8D-4472-97D8-E2A9C0A42176';
70 //CMS127v3/0043 - Pneumonia Vaccination Status for Older Adults: HQMF_ID: 40280381-4555-E1C1-0145-762578A81C4C
71 $preDefinedUniqIDRules['0043'] = '40280381-4555-E1C1-0145-762578A81C4C';
72 $preDefPopIdArr['0043']['IPP'] = '873AECC7-E15B-49E7-8391-D73A46201E2E';
73 $preDefPopIdArr['0043']['DENOM'] = 'FF7016E1-E8C7-43BA-9D56-2BEF649F36FA';
74 $preDefPopIdArr['0043']['NUMER'] = '201F5A6E-4DDE-43A2-BDFC-CE85A98560DA';
76 //CMS69v3/0421 - Preventive Care and Screening: Body Mass Index (BMI) Screening and Follow-Up Plan: HQMF_ID: 40280381-4555-E1C1-0145-D2B36DBB3FE6
77 $preDefinedUniqIDRules['0421']['Numerator 1'] = '40280381-4555-E1C1-0145-D2B36DBB3FE6';
78 $preDefPopIdArr['0421']['Numerator 1']['IPP'] = '1C936855-E644-44C0-B264-49A28756FDB1';
79 $preDefPopIdArr['0421']['Numerator 1']['DENOM'] = '27F1591C-2060-462C-B5D7-7FE86A44B534';
80 $preDefPopIdArr['0421']['Numerator 1']['DENEX'] = '9B0C3C26-D621-4EA3-81FB-A839A3012044';
81 $preDefPopIdArr['0421']['Numerator 1']['NUMER'] = '3095531C-24D7-4AFB-9BCB-F1901FF0FF69';
83 $preDefinedUniqIDRules['0421']['Numerator 2'] = '40280381-4555-E1C1-0145-D2B36DBB3FE6';
84 $preDefPopIdArr['0421']['Numerator 2']['IPP'] = '6E701B1C-6CA5-4AD5-98C9-5F766745EA89';
85 $preDefPopIdArr['0421']['Numerator 2']['DENOM'] = 'E4DC29B8-EB26-4A01-ABB0-4F99FC03BA39';
86 $preDefPopIdArr['0421']['Numerator 2']['DENEX'] = 'BB1B4301-C275-4BAC-87C9-6E960B1601DA';
87 $preDefPopIdArr['0421']['Numerator 2']['NUMER'] = '7669026D-3683-44CC-A2C5-3D62EB2F8A33';
89 //CMS117v3/0038 - Childhood Immunization Status: HQMF_ID: 40280381-4555-E1C1-0145-D7C003364261
90 $preDefinedUniqIDRules['0038'] = '40280381-4555-E1C1-0145-D7C003364261';
91 $preDefPopIdArr['0038']['IPP'] = '6ED6A787-C871-49B9-825C-70A0DB898977';
92 $preDefPopIdArr['0038']['DENOM'] = '545DA813-89ED-4DCD-BDDF-4B33D93DCD84';
93 $preDefPopIdArr['0038']['NUMER'] = '00193FC7-AEE4-4507-A20F-D25A7BB214AD';
95 //CMS138v3/0028 - Preventive Care and Screening: Tobacco Use: Screening and Cessation Intervention: HQMF_ID: 40280381-4600-425F-0146-1F5867D40E82
96 $preDefinedUniqIDRules['0028'] = '40280381-4600-425F-0146-1F5867D40E82';
97 $preDefPopIdArr['0028']['IPP'] = '4E118B62-2AF8-4F51-9355-6FD3F2427D9F';
98 $preDefPopIdArr['0028']['DENOM'] = 'FA1B3953-AE58-4541-BF7B-84D0EB1B0713';
99 $preDefPopIdArr['0028']['NUMER'] = '35B1A6DF-1871-4633-A74B-BCAE371BC030';
100 $preDefPopIdArr['0028']['DENEXCEP'] = '3EE6DFF5-AB17-482F-A147-E6D1E46DBB79';
102 //CMS157v3/0384 - Oncology: Medical and Radiation – Pain Intensity Quantified: HQMF_ID: 40280381-4600-425F-0146-1F620BDF0EB0
103 $preDefinedUniqIDRules['0384'] = '40280381-4600-425F-0146-1F620BDF0EB0';
104 $preDefPopIdArr['0384']['IPP'] = 'C29B6555-3BC7-416F-B61A-FCACD637594F';
105 $preDefPopIdArr['0384']['DENOM'] = 'E5F80C25-6816-4992-92E2-A735B17F8D4F';
106 $preDefPopIdArr['0384']['NUMER'] = 'C948D0D2-D6E9-4099-9CD4-870F2F83A14C';
108 //CMS146v3/0002 - Appropriate Testing for Children with Pharyngitis: HQMF_ID: 40280381-4600-425F-0146-1F6E280C0F09
109 $preDefinedUniqIDRules['0002'] = '40280381-4600-425F-0146-1F6E280C0F09';
110 $preDefPopIdArr['0002']['IPP'] = '9D1135EA-BA90-45E7-8EED-F7335D1CC934';
111 $preDefPopIdArr['0002']['DENOM'] = 'D04EFECB-A901-4565-BDDB-826510499092';
112 $preDefPopIdArr['0002']['NUMER'] = '3F4CDE57-1C5C-4250-A338-55FED6775F57';
113 $preDefPopIdArr['0002']['DENEX'] = '0525FBA2-F068-4706-ADB5-E345852DC55B';
115 //CMS165v3/0018 - Controlling High Blood Pressure: HQMF_ID: 40280381-4600-425F-0146-1F6F722B0F17
116 $preDefinedUniqIDRules['0018'] = '40280381-4600-425F-0146-1F6F722B0F17';
117 $preDefPopIdArr['0018']['IPP'] = 'A72855CE-3C60-41F9-AEE2-64D4F584DDD4';
118 $preDefPopIdArr['0018']['DENOM'] = '26046A5C-E2CC-4A27-B480-FF7E3575691F';
119 $preDefPopIdArr['0018']['NUMER'] = '0899A359-0CD8-4977-AA29-666892AA3AD4';
120 $preDefPopIdArr['0018']['DENEX'] = '4327D845-6194-410D-A48D-D6E1802CAD55';
122 //CMS155v3/0024 - Weight Assessment and Counseling for Nutrition and Physical Activity for Children and Adolescents: HQMF_ID: 40280381-4555-E1C1-0145-85C7311720F5
123 $preDefinedUniqIDRules['0024']['Population Criteria 1']['Numerator 1'] = '40280381-4555-E1C1-0145-85C7311720F5';
124 $preDefPopIdArr['0024']['Population Criteria 1']['Numerator 1']['IPP'] = '10127790-AE94-4070-9DD3-1D3776D08D7C';
125 $preDefPopIdArr['0024']['Population Criteria 1']['Numerator 1']['DENOM'] = '3B3C1568-F875-49B1-9090-E2F494EECBB6';
126 $preDefPopIdArr['0024']['Population Criteria 1']['Numerator 1']['DENEX'] = 'B288D5A4-D573-4FAA-92D6-0B01E1B35C7A';
127 $preDefPopIdArr['0024']['Population Criteria 1']['Numerator 1']['NUMER'] = 'FD4649BD-B962-4CBE-BF4A-C2F95F3EA08E';
129 $preDefinedUniqIDRules['0024']['Population Criteria 1']['Numerator 2'] = '40280381-4555-E1C1-0145-85C7311720F5';
130 $preDefPopIdArr['0024']['Population Criteria 1']['Numerator 2']['IPP'] = '10127790-AE94-4070-9DD3-1D3776D08D7C';
131 $preDefPopIdArr['0024']['Population Criteria 1']['Numerator 2']['DENOM'] = '3B3C1568-F875-49B1-9090-E2F494EECBB6';
132 $preDefPopIdArr['0024']['Population Criteria 1']['Numerator 2']['DENEX'] = 'B288D5A4-D573-4FAA-92D6-0B01E1B35C7A';
133 $preDefPopIdArr['0024']['Population Criteria 1']['Numerator 2']['NUMER'] = '52FBD726-4DD1-48F5-98B9-7175754923E1';
135 $preDefinedUniqIDRules['0024']['Population Criteria 1']['Numerator 3'] = '40280381-4555-E1C1-0145-85C7311720F5';
136 $preDefPopIdArr['0024']['Population Criteria 1']['Numerator 3']['IPP'] = '10127790-AE94-4070-9DD3-1D3776D08D7C';
137 $preDefPopIdArr['0024']['Population Criteria 1']['Numerator 3']['DENOM'] = '3B3C1568-F875-49B1-9090-E2F494EECBB6';
138 $preDefPopIdArr['0024']['Population Criteria 1']['Numerator 3']['DENEX'] = 'B288D5A4-D573-4FAA-92D6-0B01E1B35C7A';
139 $preDefPopIdArr['0024']['Population Criteria 1']['Numerator 3']['NUMER'] = 'C43CE779-C5EE-4C15-A4CC-AF1C446CFB09';
141 $preDefinedUniqIDRules['0024']['Population Criteria 2']['Numerator 1'] = '40280381-4555-E1C1-0145-85C7311720F5';
142 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 1']['IPP'] = '10127790-AE94-4070-9DD3-1D3776D08D7C';
143 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 1']['DENOM'] = '3B3C1568-F875-49B1-9090-E2F494EECBB6';
144 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 1']['DENEX'] = 'B288D5A4-D573-4FAA-92D6-0B01E1B35C7A';
145 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 1']['NUMER'] = 'FD4649BD-B962-4CBE-BF4A-C2F95F3EA08E';
146 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 1']['STRAT'] = '40280381-3D61-56A7-013E-5D53298E6DA3';
147 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 1']['DISPLAY_TEXT'] = 'BMI Recorded, RS1: 3-11';
149 $preDefinedUniqIDRules['0024']['Population Criteria 2']['Numerator 2'] = '40280381-4555-E1C1-0145-85C7311720F5';
150 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 2']['IPP'] = '10127790-AE94-4070-9DD3-1D3776D08D7C';
151 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 2']['DENOM'] = '3B3C1568-F875-49B1-9090-E2F494EECBB6';
152 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 2']['DENEX'] = 'B288D5A4-D573-4FAA-92D6-0B01E1B35C7A';
153 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 2']['NUMER'] = '52FBD726-4DD1-48F5-98B9-7175754923E1';
154 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 2']['STRAT'] = '40280381-3D61-56A7-013E-5D53298E6DA3';
155 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 2']['DISPLAY_TEXT'] = 'BMI Recorded, RS2: 12-17';
157 $preDefinedUniqIDRules['0024']['Population Criteria 2']['Numerator 3'] = '40280381-4555-E1C1-0145-85C7311720F5';
158 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 3']['IPP'] = '10127790-AE94-4070-9DD3-1D3776D08D7C';
159 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 3']['DENOM'] = '3B3C1568-F875-49B1-9090-E2F494EECBB6';
160 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 3']['DENEX'] = 'B288D5A4-D573-4FAA-92D6-0B01E1B35C7A';
161 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 3']['NUMER'] = 'C43CE779-C5EE-4C15-A4CC-AF1C446CFB09';
162 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 3']['STRAT'] = '40280381-3D61-56A7-013E-5D53298E6DA3';
163 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 3']['DISPLAY_TEXT'] = 'Nutrition Counseling, RS1: 3-11';
165 $preDefinedUniqIDRules['0024']['Population Criteria 3']['Numerator 1'] = '40280381-4555-E1C1-0145-85C7311720F5';
166 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 1']['IPP'] = '10127790-AE94-4070-9DD3-1D3776D08D7C';
167 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 1']['DENOM'] = '3B3C1568-F875-49B1-9090-E2F494EECBB6';
168 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 1']['DENEX'] = 'B288D5A4-D573-4FAA-92D6-0B01E1B35C7A';
169 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 1']['NUMER'] = 'FD4649BD-B962-4CBE-BF4A-C2F95F3EA08E';
170 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 1']['STRAT'] = '40280381-3D61-56A7-013E-5D532AF06DA5';
171 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 1']['DISPLAY_TEXT'] = 'Nutrition Counseling, RS2: 12-17';
173 $preDefinedUniqIDRules['0024']['Population Criteria 3']['Numerator 2'] = '40280381-4555-E1C1-0145-85C7311720F5';
174 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 2']['IPP'] = '10127790-AE94-4070-9DD3-1D3776D08D7C';
175 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 2']['DENOM'] = '3B3C1568-F875-49B1-9090-E2F494EECBB6';
176 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 2']['DENEX'] = 'B288D5A4-D573-4FAA-92D6-0B01E1B35C7A';
177 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 2']['NUMER'] = '52FBD726-4DD1-48F5-98B9-7175754923E1';
178 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 2']['STRAT'] = '40280381-3D61-56A7-013E-5D532AF06DA5';
179 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 2']['DISPLAY_TEXT'] = 'Physical Activity Counseling, RS1: 3-11';
181 $preDefinedUniqIDRules['0024']['Population Criteria 3']['Numerator 3'] = '40280381-4555-E1C1-0145-85C7311720F5';
182 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 3']['IPP'] = '10127790-AE94-4070-9DD3-1D3776D08D7C';
183 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 3']['DENOM'] = '3B3C1568-F875-49B1-9090-E2F494EECBB6';
184 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 3']['DENEX'] = 'B288D5A4-D573-4FAA-92D6-0B01E1B35C7A';
185 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 3']['NUMER'] = 'C43CE779-C5EE-4C15-A4CC-AF1C446CFB09';
186 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 3']['STRAT'] = '40280381-3D61-56A7-013E-5D532AF06DA5';
187 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 3']['DISPLAY_TEXT'] = 'Physical Activity Counseling, RS2: 12-17';
189 $preDefPopIdArr['0024']['STRAT1'] = '40280381-3D61-56A7-013E-5D53298E6DA3';
190 $preDefPopIdArr['0024']['STRAT2'] = '40280381-3D61-56A7-013E-5D532AF06DA5';
192 //Multiple Numerator NQF# Array declaration
193 $multNumNQFArr = array('0421', '0024');
194 $countNumNQFArr = array();
195 $countNumNQFArr['0421'] = 2;//two Numerators
196 $countNumNQFArr['0024'] = 9;//Nine Numerators
198 //Initiation of all QRDA needed elements
199 $CQMeausesArr = array();
200 $CQMeausesArr['init_patients'] = "Initial Patient Population";
201 $CQMeausesArr['exclude_patients'] = "Denominator Exclusions";
202 $CQMeausesArr['denom_patients'] = "Denominator";
203 $CQMeausesArr['numer_patients'] = "Numerator";
204 $CQMeausesArr['exception_patients'] = "Denominator Exceptions";
206 $cqmItemizedArr = array();
207 $cqmItemizedArr['init_patients'] = "init_patients";
208 $cqmItemizedArr['exclude_patients'] = "exclude";
209 $cqmItemizedArr['denom_patients'] = "all";
210 $cqmItemizedArr['numer_patients'] = "pass";
211 $cqmItemizedArr['exception_patients'] = "exception";
213 //QRDA Needed Ethnicity
214 $mainEthiArr = array(0=>'Not Hispanic or Latino', 1=>'Hispanic or Latino');
215 $mainEthiCodeArr = array(0=>'2186-5', 1=>'2135-2');
218 $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');
219 $mainQrdaRaceCodeArr = array(0=>'1002-5', 1=>'2028-9', 2=>'2054-5', 3=>'2076-8', 4=>'2106-3', 5=>'2131-1');
221 $mainQrdaPopulationIncArr = array();
222 $mainQrdaPopulationIncArr['init_patients'] = "IPP";
223 $mainQrdaPopulationIncArr['exclude_patients'] = "DENEX";
224 $mainQrdaPopulationIncArr['denom_patients'] = "DENOM";
225 $mainQrdaPopulationIncArr['numer_patients'] = "NUMER";
226 $mainQrdaPopulationIncArr['exception_patients'] = "DENEXCEP";
227 $mainQrdaPopulationIncArr['measure_population'] = "MSRPOPL";
228 $mainQrdaPopulationIncArr['numer_exclusion'] = "NUMEX";
231 $mainQrdaGenderCodeArr = array();
232 $mainQrdaGenderCodeArr['F'] = "Female";
233 $mainQrdaGenderCodeArr['M'] = "Male";
234 $mainQrdaGenderCodeArr['UN'] = "Unknown";
236 //QRDA Needed Payer Info
237 $mainQrdaPayerCodeArr = array();
238 $mainQrdaPayerCodeArr['A'] = "Medicare";
239 $mainQrdaPayerCodeArr['B'] = "Medicaid";
240 $mainQrdaPayerCodeArr['C'] = "Private Health Insurance";
241 $mainQrdaPayerCodeArr['D'] = "Other";
243 //Payer Codes According to Cypress Codes
244 $mainQrdaPayerCodeSendArr = array();
245 $mainQrdaPayerCodeSendArr['A'] = "1";
246 $mainQrdaPayerCodeSendArr['B'] = "2";
247 $mainQrdaPayerCodeSendArr['C'] = "5";
248 $mainQrdaPayerCodeSendArr['D'] = "349";
251 $form_provider = $_GET['form_provider'];
253 //Get Report Information
254 $report_id = $_GET['report_id'];
255 $report_view = collectReportDatabase($report_id);
256 $target_date = $report_view['date_target'];
257 $dataSheet = json_decode($report_view['data'],TRUE);
259 //Needed array for Rule NQF#0024 Stratification
260 $stratumCheckArr = array();
261 if(count($dataSheet) > 0){
263 foreach ($dataSheet as $row) {
264 $itemized_test_id = $row['itemized_test_id'];
265 $numerator_label = $row['numerator_label'];
266 if($row['cqm_nqf_code'] == "0024"){
267 if( $row['population_label'] == "Population Criteria 2" ){
268 if($row['numerator_label'] == "Numerator 1"){
269 $stratum_1_ipp = $row['initial_population'];
270 $stratum_1_exclude = $row['excluded'];
271 $stratum_1_denom = $row['pass_filter'];
272 $stratum_1_numer1 = $row['pass_target'];
273 }else if($row['numerator_label'] == "Numerator 2"){
274 $stratum_1_numer2 = $row['pass_target'];
275 }else if($row['numerator_label'] == "Numerator 3"){
276 $stratum_1_numer3 = $row['pass_target'];
278 }else if( $row['population_label'] == "Population Criteria 3" ){
279 if($row['numerator_label'] == "Numerator 1"){
280 $stratum_2_ipp = $row['initial_population'];
281 $stratum_2_exclude = $row['excluded'];
282 $stratum_2_denom = $row['pass_filter'];
283 $stratum_2_numer1 = $row['pass_target'];
284 }else if($row['numerator_label'] == "Numerator 2"){
285 $stratum_2_numer2 = $row['pass_target'];
286 }else if($row['numerator_label'] == "Numerator 3"){
287 $stratum_2_numer3 = $row['pass_target'];
293 $stratum[1] = array('init_patients' => $stratum_1_ipp,
294 'exclude_patients' => $stratum_1_exclude,
295 'denom_patients' => $stratum_1_denom,
296 'numer_patients' => $stratum_1_numer1,
297 'numer2' => $stratum_1_numer2,
298 'numer3' => $stratum_1_numer3);
300 $stratum[2] = array('init_patients' => $stratum_2_ipp,
301 'exclude_patients' => $stratum_2_exclude,
302 'denom_patients' => $stratum_2_denom,
303 'numer_patients' => $stratum_2_numer1,
304 'numer2' => $stratum_2_numer2,
305 'numer3' => $stratum_2_numer3);
310 $from_date = date('Y', strtotime($target_date ))."-01-01";
311 $to_date = date('Y', strtotime($target_date ))."-12-31";
312 $xml = new QRDAXml();
314 #################################################################################################
315 ####################### HEADER ELEMENTS START #####################################################
316 #################################################################################################
317 //Open Main Clinical Document
318 $xml->open_clinicaldocument();
320 $xml->self_realmcode();
324 $tempId = '2.16.840.1.113883.10.20.27.1.1';
325 $xml->self_templateid($tempId);
327 $xml->unique_id
= getUuid();
331 //Main Title Display to XML
332 $main_title = "QRDA Calculated Summary Report";
333 $xml->add_title($main_title);
335 //Effective date and time
336 $eff_datetime = date('Ymdhis', strtotime($target_date));
337 $xml->self_efftime($eff_datetime);
339 $xml->self_confidentcode();
344 $setidVal =getUuid();
345 $xml->self_setid($setidVal);
348 $xml->self_version();
350 //Record Target Elements
351 $xml->open_recordTarget();
352 $xml->add_patientRole();
353 $xml->close_recordTarget();
355 ############### Author Info #######################
358 $auth_dtime = date('Ymdhis', strtotime(date('Y-m-d H:i:s')));
359 $xml->self_authorTime($auth_dtime);
361 $xml->open_assignAuthor();
362 $authorsetid = getUuid();
363 $xml->self_customId($authorsetid);
364 if($form_provider != ""){
365 $userRow = sqlQuery("SELECT facility, facility_id, federaltaxid, npi, phone,fname, lname FROM users WHERE id=?", array($form_provider));
366 $facility_name = $userRow['facility'];
367 $facility_id = $userRow['facility_id'];
369 //$xml->self_customTag('telecom', array('value' => $userRow['phone'], 'use'=>'WP'));
371 //assignedAuthoringDevice Start
372 $xml->open_customTag('assignedAuthoringDevice');
374 $xml->element('softwareName', 'CYPRESS');
376 //assignedAuthoringDevice Close
377 $xml->close_customTag();
380 $facilResRow = sqlQuery("SELECT name, street,city,state,postal_code, country_code, phone from facility WHERE id = ?", array($facility_id));
381 $xml->add_authReprestOrginisation($facilResRow);
382 //$xml->add_facilAddress($facilResRow);
383 $xml->close_assignAuthor();
384 $xml->close_author();
386 ############### Custodian Info #######################
387 $xml->open_custodian();
388 $xml->open_assgnCustodian();
389 $xml->add_represtCustodianOrginisation($facilResRow);
390 $xml->close_assgnCustodian();
391 $xml->close_custodian();
394 ############### Information Recipient #######################
395 $xml->open_infoRecipient();
396 $xml->add_indententRecipient();
397 $xml->close_infoRecipient();
400 ############### Legal Authenticator #######################
401 $xml->open_legalAuthenticator();
402 $auth_dtime = date('Ymdhis', strtotime(date('Y-m-d H:i:s')));
403 $xml->self_authorTime($auth_dtime);
404 $xml->self_legalSignCode();
406 $xml->open_assignedEntity();
407 $assignedEntityId = getUuid();
408 $xml->self_customId($assignedEntityId);
410 $xml->open_customTag('assignedPerson');
413 $userNameArr = array('fname' =>$userRow['fname'], 'lname'=>$userRow['lname']);
414 $xml->add_providerName($userNameArr);
416 //assignedPerson Close
417 $xml->close_customTag();
419 //Represent Origination Name
420 $xml->add_authReprestOrginisation($facilResRow);
421 $xml->close_assignedEntity();
423 $xml->close_legalAuthenticator();
426 ############### Participant is Device(optional) #######################
427 $participentDevArr = array();
428 $xml->open_participant_data('DEV');//DEV -- Device
429 $xml->open_assocEntityData('RGPR');//RGPR -- Regulated Product
430 $participentDevArr['root'] = '2.16.840.1.113883.3.2074.1';
431 $participentDevArr['extension'] = '1a2b3c';
432 $xml->self_particpantIdInfo($participentDevArr);
433 $xml->self_participantCodeDevice();
434 $xml->close_assocEntityData();
435 $xml->close_participant_data();
437 ############### Participant is Location(optional) #######################
438 $participentLocArr = array();
439 $xml->open_participant_data('LOC');//LOC -- Location
440 $xml->open_assocEntityData('SDLOC');//SDLOC -- Service Delivery Location
441 $participentLocArr['root'] = '2.16.840.1.113883.3.249.5.1';
442 $participentLocArr['extension'] = 'OK666333';
443 $xml->self_particpantIdInfo($participentLocArr);
444 $xml->self_participantCodeLocation();
446 $xml->add_facilAddress($facilResRow);
447 $xml->close_assocEntityData();
448 $xml->close_participant_data();
451 ############### documentationOf START #######################
452 $xml->open_customTag('documentationOf');
454 $xml->open_customTag('serviceEvent', array('classCode'=>'PCPR'));
456 $timeArr = array('low'=>date('Ymd', strtotime($from_date)), 'high'=>date('Ymd', strtotime($to_date)));
457 $xml->add_entryEffectTime($timeArr);
459 $xml->open_customTag('performer', array('typeCode'=>'PRF'));
461 $xml->open_customTag('assignedEntity');
463 $npi_provider = !empty($userRow['npi']) ?
$userRow['npi'] : '123456789';
464 $xml->self_customTag('id', array('root' => '2.16.840.1.113883.4.6', 'extension' =>$npi_provider));
466 if($userRow['phone'] != ""){
467 $xml->self_customTag('telecom', array('value' => $userRow['phone'], 'use'=>'WP'));
470 $xml->open_customTag('assignedPerson');
473 $userNameArr = array('fname' =>$userRow['fname'], 'lname'=>$userRow['lname']);
474 $xml->add_providerName($userNameArr);
476 //assignedPerson Close
477 $xml->close_customTag();
479 $xml->open_customTag('representedOrganization');
481 $tin_provider = $userRow['federaltaxid'];
482 if($tin_provider != ""){
483 $xml->self_customTag('id', array('root' => '2.16.840.1.113883.4.2', 'extension' =>$tin_provider));
486 $xml->add_facilName($facility_name);
488 $xml->add_facilAddress($facilResRow);
490 //representedOrganization Close
491 $xml->close_customTag();
493 //assignedEntity Close
494 $xml->close_customTag();
497 $xml->close_customTag();
500 $xml->close_customTag();
502 //documentationOf Close
503 $xml->close_customTag();
504 ############### documentationOf END #######################
507 ############### authorization (optional) #########################
509 #################################################################################################
510 ####################### HEADER ELEMENTS END #####################################################
511 #################################################################################################
515 #################################################################################################
516 ######################### Main Component Open ###################################################
517 $xml->open_mainComponent();
519 ############### Structure Body Open #######################
520 $xml->open_structuredBody();
522 ##################### LOOP Component(s) START ########################
524 ###################### Report Parameters Open #####################
525 //QRDA Category III Reporting Parameters Section (CMS EP) [section: templateId 2.16.840.1.113883.10.20.27.2.6
526 $xml->open_loopComponent();
528 $xml->open_section();
530 $tempID = '2.16.840.1.113883.10.20.17.2.1';
531 $xml->self_templateid($tempID);
533 $tempID = '2.16.840.1.113883.10.20.27.2.2';
534 $xml->self_templateid($tempID);
536 $tempID = '2.16.840.1.113883.10.20.27.2.6';
537 $xml->self_templateid($tempID);
538 $arr = array('code'=>'55187-9', 'codeSystem'=>'2.16.840.1.113883.6.1');
539 $xml->self_codeCustom($arr);
540 $title = "Reporting Parameters";
541 $xml->add_title($title);
545 $item_title = "Reporting period: ".date('d M Y', strtotime($from_date))." - ".date('d M Y', strtotime($to_date));
546 $xml->add_item($item_title);
551 $xml->open_entry($typeCode);
552 $arr = array('classCode'=>'ACT', 'moodCode'=>'EVN');
553 $xml->open_act($arr);
555 $tempID = '2.16.840.1.113883.10.20.17.3.8';
556 $xml->self_templateid($tempID);
558 $tempID = '2.16.840.1.113883.10.20.27.3.23';
559 $xml->self_templateid($tempID);
562 $xml->self_customId($actId);
564 $arr = array('code'=>'252116004', 'codeSystem'=>'2.16.840.1.113883.6.96', 'displayName'=>'Observation Parameters');
565 $xml->self_codeCustom($arr);
567 $timeArr = array('low'=>date('Ymd', strtotime($from_date)), 'high'=>date('Ymd', strtotime($to_date)));
568 $xml->add_entryEffectTime($timeArr);
573 $xml->close_section();
575 $xml->close_loopComponent();
576 ###################### Report Parameters Close #####################
578 ###################### Measure Section Open #####################
579 $xml->open_loopComponent();
581 $xml->open_section();
583 $tempID = '2.16.840.1.113883.10.20.27.2.1';
584 $xml->self_templateid($tempID);
586 $tempID = '2.16.840.1.113883.10.20.24.2.2';
587 $xml->self_templateid($tempID);
589 $tempID = '2.16.840.1.113883.10.20.27.2.3';
590 $xml->self_templateid($tempID);
592 $arr = array('code'=>'55186-1', 'codeSystem'=>'2.16.840.1.113883.6.1');
593 $xml->self_codeCustom($arr);
594 $title = "Measure Section";
595 $xml->add_title($title);
600 $tabArr = array('border'=>1, 'width'=>'100%');
601 if(count($dataSheet) > 0){
602 $uniqIdArr = array();
605 foreach ($dataSheet as $row) {
606 $itemized_test_id = $row['itemized_test_id'];
607 $numerator_label = $row['numerator_label'];
609 //CQM Rules 2014 set, 0013 is 0018
610 if($row['cqm_nqf_code'] == "0013") $row['cqm_nqf_code'] = "0018";
613 $xml->open_customTag('table', $tabArr);
615 $xml->open_customTag('thead');
617 $xml->open_customTag('tr');
619 $xml->add_trElementsTitles();
622 $xml->close_customTag();
625 $xml->close_customTag();
627 $xml->open_customTag('tbody');
628 $xml->open_customTag('tr');
630 $tdTitle = generate_display_field(array('data_type'=>'1','list_id'=>'clinical_rules'),$row['id']);
632 if (!empty($row['cqm_pqri_code'])) {
633 $tdTitle .= " " . htmlspecialchars( xl('PQRI') . ":" . $row['cqm_pqri_code'], ENT_NOQUOTES
) . " ";
635 if (!empty($row['cqm_nqf_code'])) {
636 $tdTitle .= " " . htmlspecialchars( xl('NQF') . ":" . $row['cqm_nqf_code'], ENT_NOQUOTES
) . " ";
639 if ( !(empty($row['concatenated_label'])) ) {
640 $tdTitle .= ", " . htmlspecialchars( xl( $row['concatenated_label'] ), ENT_NOQUOTES
) . " ";
643 $tdVersionNeutral = getUuid();
645 if($preDefinedUniqIDRules[$row['cqm_nqf_code']] != ""){
646 if( ($row['cqm_nqf_code'] == "0421" ) )
647 $tdVersionSpecific = $preDefinedUniqIDRules[$row['cqm_nqf_code']][$row['numerator_label']];
648 else if($row['cqm_nqf_code'] == "0024")
649 $tdVersionSpecific = $preDefinedUniqIDRules[$row['cqm_nqf_code']][$row['population_label']][$row['numerator_label']];
651 $tdVersionSpecific = $preDefinedUniqIDRules[$row['cqm_nqf_code']];
653 $uniqIdArr[] = $tdVersionSpecific;
655 $tdVersionSpecific = getUuid();
656 $uniqIdArr[] = $tdVersionSpecific;
659 $dataArr = array(0=>$tdTitle, 1=>$tdVersionNeutral, 2=>$tdVersionSpecific);
660 $xml->add_trElementsValues($dataArr);
663 $xml->close_customTag();
665 $xml->close_customTag();
667 $xml->close_customTag();
669 //Open List Item Wise
673 $xml->open_customTag('item');
674 $arrContent = array('name'=>'Performance Rate', 'value'=>$row['percentage']);
675 $xml->innerContent($arrContent);
676 $xml->close_customTag();
679 //All CQM Measures taken here
680 foreach($CQMeausesArr as $cqmKey => $cqmVal){
682 //DENEXCEP(Denominator Exception not needed for some rules are skipping here)
683 if( (in_array($row['cqm_nqf_code'], $denExcepNotNeedRules) ) && ($cqmKey == "exception_patients") ) continue;
686 if($cqmKey == "init_patients")
687 $itemPatArr = collectItemizedPatientsCdrReport($report_id,$itemized_test_id,$cqmItemizedArr[$cqmKey]);
689 $itemPatArr = collectItemizedPatientsCdrReport($report_id,$itemized_test_id,$cqmItemizedArr[$cqmKey], $numerator_label);
690 $fullPatArr = array();
691 foreach($itemPatArr as $itemPatInfo){
692 $fullPatArr[] = $itemPatInfo['pid'];
695 //Initial Patient Population
696 $xml->open_customTag('item');
697 $arrContent = array('name'=>$cqmVal, 'value'=>count($fullPatArr));
698 $xml->innerContent($arrContent);
700 $detailsArr = getQRDAPatientNeedInfo($fullPatArr);
705 //Gender Section Display
706 foreach($mainQrdaGenderCodeArr as $GKey => $GVal){
707 $xml->open_customTag('item');
708 $genderInfo = $detailsArr['gender'][$GVal];
709 $arrContent = array('name'=>$GVal, 'value'=>$genderInfo);
710 $xml->innerContent($arrContent);
711 $xml->close_customTag();
714 //Ethnicity Section Display
715 foreach($mainEthiArr as $ethKey => $ethVal){
716 $ethnicity_data = $detailsArr['ethnicity'][$ethVal];
717 $xml->open_customTag('item');
718 $arrContent = array('name'=>'Ethnicity - '.$ethVal, 'value'=>$ethnicity_data);
719 $xml->innerContent($arrContent);
720 $xml->close_customTag();
723 //Race Section Display
724 foreach($mainQrdaRaceArr as $RKey => $RVal){
725 $race_data = $detailsArr['race'][$RVal];
726 $xml->open_customTag('item');
727 $arrContent = array('name'=>'Race - '.$RVal, 'value'=>$race_data);
728 $xml->innerContent($arrContent);
729 $xml->close_customTag();
732 //Payer Type Section Display
733 $payerCheckArr = getQRDAPayerInfo($fullPatArr);
734 foreach($mainQrdaPayerCodeArr as $PKey => $PVal){
735 $xml->open_customTag('item');
736 $arrContent = array('name'=>'Payer - '.$PVal, 'value'=>$payerCheckArr[$PVal]);
737 $xml->innerContent($arrContent);
738 $xml->close_customTag();
743 $xml->close_customTag();
751 #######################################################################
752 ######################### QUALITY MEASURES START ######################
753 #######################################################################
754 if(count($dataSheet) > 0){
756 $skipMultNumArr = array();
757 $dataChkArr = array();
758 foreach($multNumNQFArr as $multNumVal){
759 $skipMultNumArr[$multNumVal] = false;
760 $dataChkArr[$multNumVal] = 0;
764 foreach ($dataSheet as $row) {
765 $itemized_test_id = $row['itemized_test_id'];
766 $numerator_label = $row['numerator_label'];
768 //if($row['cqm_nqf_code'] == "0028a") continue;
770 //if($row['cqm_nqf_code'] == "0038"){
771 // if(in_array($row['numerator_label'], $NQF38NumArr)) continue;
774 if(in_array($row['cqm_nqf_code'], $multNumNQFArr)){
775 $dataChkArr[$row['cqm_nqf_code']]++
;
778 //CQM Rules 2014 set, 0013 is 0018
779 if($row['cqm_nqf_code'] == "0013") $row['cqm_nqf_code'] = "0018";
781 $tdTitle = generate_display_field(array('data_type'=>'1','list_id'=>'clinical_rules'),$row['id']);
782 if (!empty($row['cqm_pqri_code'])) {
783 $tdTitle .= " " . text( xl('PQRI') . ":" . $row['cqm_pqri_code']) . " ";
785 if (!empty($row['cqm_nqf_code'])) {
786 $tdTitle .= " " . text( xl('NQF') . ":" . $row['cqm_nqf_code']) . " ";
789 if ( !(empty($row['concatenated_label'])) ) {
790 $tdTitle .= ", " . text( xl( $row['concatenated_label'] )) . " ";
793 ###########################################################
794 if( ( !isset($skipMultNumArr[$row['cqm_nqf_code']]) ) ||
($skipMultNumArr[$row['cqm_nqf_code']] == false) ){
800 $arr = array('classCode'=>'CLUSTER', 'moodCode'=>'EVN');
801 $xml->open_customTag('organizer', $arr);
803 $tempID = "2.16.840.1.113883.10.20.24.3.98";
804 $xml->self_templateid($tempID);
806 $tempID = "2.16.840.1.113883.10.20.27.3.1";
807 $xml->self_templateid($tempID);
809 //$tempID = "2.16.840.1.113883.10.20.27.3.17";
810 //$xml->self_templateid($tempID);
812 $xml->self_customId($actId);
814 $arr = array('code'=>'completed');
815 $xml->self_customTag('statusCode', $arr);
818 $arr = array('typeCode'=>'REFR');
819 $xml->open_customTag('reference', $arr);
821 //externalDocument Start
822 $arr = array('classCode'=>'DOC', 'moodCode'=>'EVN');
823 $xml->open_customTag('externalDocument', $arr);
825 //$exDocID = getUuid();
826 $exDocID = $uniqIdArr[$innrCnt];
827 //$xml->self_customId($exDocID);
828 $xml->self_customTag('id', array('root' => '2.16.840.1.113883.4.738', 'extension' =>$exDocID));
830 $arr = array('code'=>'57024-2', 'displayName'=>'Health Quality Measure Document', 'codeSystem'=>'2.16.840.1.113883.6.1', 'codeSystemName'=>'LOINC');
831 $xml->self_codeCustom($arr);
833 $dispContntTitle = str_replace("&", '', $tdTitle);
834 $xml->textDispContent($dispContntTitle);
836 //externalDocument Close
837 $xml->close_customTag();
840 $xml->close_customTag();
843 ############### Performance Rate for Proportion Measure template START###################
844 $xml->open_loopComponent();
847 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
849 $tempID = "2.16.840.1.113883.10.20.27.3.14";
850 $xml->self_templateid($tempID);
852 $tempID = "2.16.840.1.113883.10.20.27.3.25";
853 $xml->self_templateid($tempID);
855 $arr = array('code'=>'72510-1', 'displayName'=>'Performance Rate', 'codeSystem'=>'2.16.840.1.113883.6.1', 'codeSystemName'=>'SNOMED-CT');
856 $xml->self_codeCustom($arr);
858 $arr = array('code'=>'completed');
859 $xml->self_customTag('statusCode', $arr);
861 $percentage = str_replace("%", '', $row['percentage']);
862 $arr = array('xsi:type'=>'REAL', 'value'=>$percentage/100);
863 $xml->self_customTag('value', $arr);
866 $arr = array('typeCode'=>'REFR');
867 $xml->open_customTag('reference', $arr);
869 //externalObservation Start
870 $arr = array('classCode'=>'OBS', 'moodCode'=>'EVN');
871 $xml->open_customTag('externalObservation', $arr);
874 //$exDocID = getUuid();
877 if( ($row['cqm_nqf_code'] == "0421" )){
878 $exDocID = $preDefPopIdArr[$row['cqm_nqf_code']][$row['numerator_label']]["NUMER"];
879 }else if(($row['cqm_nqf_code'] == "0024")){
880 $exDocID = $preDefPopIdArr[$row['cqm_nqf_code']][$row['population_label']][$row['numerator_label']]["NUMER"];
882 if($preDefPopIdArr[$row['cqm_nqf_code']]["NUMER"] != "")
883 $exDocID = $preDefPopIdArr[$row['cqm_nqf_code']]["NUMER"];
885 $exDocID = getUuid();
888 $xml->self_customId($exDocID);
890 $arr = array('code'=>'NUMER', 'displayName'=>'Numerator', 'codeSystem'=>'2.16.840.1.113883.5.1063', 'codeSystemName'=>'ObservationValue');
891 $xml->self_codeCustom($arr);
893 //externalObservation Close
894 $xml->close_customTag();
897 $xml->close_customTag();
900 $xml->close_customTag();
902 $xml->close_loopComponent();
903 ############### Performance Rate for Proportion Measure template END ###################
907 //All CQM Measures taken here
908 foreach($CQMeausesArr as $cqmKey => $cqmVal){
910 //DENEXCEP(Denominator Exception not needed for some rules are skipping here)
911 if( (in_array($row['cqm_nqf_code'], $denExcepNotNeedRules) ) && ($cqmKey == "exception_patients") ) continue;
913 //cqm 0024 alllowing only nuemerator 2 and numerator 3 for ipp1,ipp2 and 1pp3 to avoid repeatation
914 if($row['cqm_nqf_code'] == '0024' && ($row['numerator_label'] == "Numerator 2" ||
$row['numerator_label'] == "Numerator 3") && $cqmKey != 'numer_patients') continue;
915 if($row['cqm_nqf_code'] == '0024' && ($row['population_label'] == "Population Criteria 2" ||
$row['population_label'] == "Population Criteria 3")) continue;
919 if($cqmKey == "init_patients")
920 $itemPatArr = collectItemizedPatientsCdrReport($report_id,$itemized_test_id,$cqmItemizedArr[$cqmKey]);
922 $itemPatArr = collectItemizedPatientsCdrReport($report_id,$itemized_test_id,$cqmItemizedArr[$cqmKey], $numerator_label);
924 $fullPatArr = array();
925 foreach($itemPatArr as $itemPatInfo){
926 $fullPatArr[] = $itemPatInfo['pid'];
929 $detailsArr = getQRDAPatientNeedInfo($fullPatArr);
930 ############### Initial patient population template START###################
931 $xml->open_loopComponent();
934 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
936 $tempID = "2.16.840.1.113883.10.20.27.3.5";
937 $xml->self_templateid($tempID);
939 $tempID = "2.16.840.1.113883.10.20.27.3.16";
940 $xml->self_templateid($tempID);
942 $arr = array('code'=>'ASSERTION', 'displayName'=>'Assertion', 'codeSystem'=>'2.16.840.1.113883.5.4', 'codeSystemName'=>'ActCode');
943 $xml->self_codeCustom($arr);
945 $arr = array('code'=>'completed');
946 $xml->self_customTag('statusCode', $arr);
948 $arr = array('xsi:type'=>'CD', 'code'=>$mainQrdaPopulationIncArr[$cqmKey], 'displayName'=>$cqmVal, 'codeSystem' =>'2.16.840.1.113883.5.1063', 'codeSystemName'=>'ObservationValue');
949 $xml->self_customTag('value', $arr);
951 //entryRelationship Open
952 $xml->open_customTag('entryRelationship', array('typeCode'=>'SUBJ', 'inversionInd'=>'true'));
955 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
957 $tempID = "2.16.840.1.113883.10.20.27.3.3";
958 $xml->self_templateid($tempID);
960 $tempID = "2.16.840.1.113883.10.20.27.3.24";
961 $xml->self_templateid($tempID);
963 $arr = array('code'=>'MSRAGG', 'displayName'=>'rate aggregation', 'codeSystem'=>'2.16.840.1.113883.5.4', 'codeSystemName'=>'ActCode');
964 $xml->self_codeCustom($arr);
966 //$arr = array('code'=>'completed');
967 //$xml->self_customTag('statusCode', $arr);
969 $arr = array('xsi:type'=>'INT', 'value'=>count($fullPatArr));
970 $xml->self_customTag('value', $arr);
972 $arr = array('code'=>'COUNT', 'displayName'=>'Count', 'codeSystem'=>'2.16.840.1.113883.5.84', 'codeSystemName'=>'ObservationMethod');
973 $xml->self_customTag('methodCode', $arr);
976 $xml->close_customTag();
978 //entryRelationship Close
979 $xml->close_customTag();
981 #### Stratum Start (Stratification)#####
982 if($row['cqm_nqf_code'] == '0024'){
984 for(;$strat_count <= 2;$strat_count++
){
986 $strata_value = $stratum[$strat_count][$cqmKey];
988 if($row['numerator_label'] == "Numerator 2") $strata_value = $stratum[$strat_count]['numer2'];
990 else if($row['numerator_label'] == "Numerator 3") $strata_value = $stratum[$strat_count]['numer3'];
992 //entryRelationship Open
993 $xml->open_customTag('entryRelationship', array('typeCode'=>'COMP'));
996 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
998 $tempID = "2.16.840.1.113883.10.20.27.3.4";
999 $xml->self_templateid($tempID);
1001 $tempID = "2.16.840.1.113883.10.20.27.3.20";
1002 $xml->self_templateid($tempID);
1004 $arr = array('code'=>'ASSERTION', 'displayName'=>'Assertion', 'codeSystem'=>'2.16.840.1.113883.5.4', 'codeSystemName'=>'ActCode');
1005 $xml->self_codeCustom($arr);
1007 $arr = array('code'=>'completed');
1008 $xml->self_customTag('statusCode', $arr);
1011 $xml->open_customTag('value', array('xsi:type'=>'CD', 'nullFlavor'=>'OTH'));
1013 $stratumText = $preDefPopIdArr[$row['cqm_nqf_code']][$row['population_label']][$row['numerator_label']]['DISPLAY_TEXT'];
1014 $xml->element('originalText', "Stratum ".$strat_count);
1017 $xml->close_customTag();
1019 //entryRelationship Open
1020 $xml->open_customTag('entryRelationship', array('typeCode'=>'SUBJ', 'inversionInd' => 'true'));
1023 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
1025 $tempID = "2.16.840.1.113883.10.20.27.3.3";
1026 $xml->self_templateid($tempID);
1028 $arr = array('code'=>'MSRAGG', 'displayName'=>'rate aggregation', 'codeSystem'=>'2.16.840.1.113883.5.4', 'codeSystemName'=>'ActCode');
1029 $xml->self_codeCustom($arr);
1031 $arr = array('xsi:type'=>'INT', 'value'=>$strata_value);
1032 $xml->self_customTag('value', $arr);
1034 $arr = array('code'=>'COUNT', 'displayName'=>'Count', 'codeSystem'=>'2.16.840.1.113883.5.84', 'codeSystemName'=>'ObservationMethod');
1035 $xml->self_customTag('methodCode', $arr);
1038 $xml->close_customTag();
1040 //entryRelationship Close
1041 $xml->close_customTag();
1044 $arr = array('typeCode'=>'REFR');
1045 $xml->open_customTag('reference', $arr);
1047 //externalObservation Start
1048 $arr = array('classCode'=>'OBS', 'moodCode'=>'EVN');
1049 $xml->open_customTag('externalObservation', $arr);
1051 //Modified HQMF_ID for CQM IDS
1052 //$refID = $preDefPopIdArr[$row['cqm_nqf_code']][$row['population_label']][$row['numerator_label']]['STRAT'];
1053 $refID = $preDefPopIdArr[$row['cqm_nqf_code']]['STRAT'.$strat_count];
1055 $xml->self_customId($refID);
1057 //externalObservation Close
1058 $xml->close_customTag();
1061 $xml->close_customTag();
1064 $xml->close_customTag();
1066 //entryRelationship Close
1067 $xml->close_customTag();
1071 #### Stratum END #####
1073 ####################################################
1074 ####################################################
1075 //Sex Supplemental Data Element START
1076 ####################################################
1077 ####################################################
1079 foreach($mainQrdaGenderCodeArr as $GKey => $GVal){
1080 //entryRelationship Open
1081 $xml->open_customTag('entryRelationship', array('typeCode'=>'COMP'));
1084 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
1086 $tempID = "2.16.840.1.113883.10.20.27.3.6";
1087 $xml->self_templateid($tempID);
1089 $tempID = "2.16.840.1.113883.10.20.27.3.21";
1090 $xml->self_templateid($tempID);
1092 $arr = array('code'=>'184100006', 'displayName'=>'patient sex', 'codeSystem'=>'2.16.840.1.113883.6.96', 'codeSystemName'=>'SNOMED-CT');
1093 $xml->self_codeCustom($arr);
1095 $arr = array('code'=>'completed');
1096 $xml->self_customTag('statusCode', $arr);
1098 $arr = array('xsi:type'=>'CD', 'code'=>$GKey, 'codeSystem' =>'2.16.840.1.113883.5.1', 'codeSystemName'=>'AdministrativeGenderCode');
1099 $xml->self_customTag('value', $arr);
1101 //entryRelationship Open
1102 $xml->open_customTag('entryRelationship', array('typeCode'=>'SUBJ', 'inversionInd'=>'true'));
1105 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
1107 $tempID = "2.16.840.1.113883.10.20.27.3.3";
1108 $xml->self_templateid($tempID);
1110 $tempID = "2.16.840.1.113883.10.20.27.3.24";
1111 $xml->self_templateid($tempID);
1113 $arr = array('code'=>'MSRAGG', 'displayName'=>'rate aggregation', 'codeSystem'=>'2.16.840.1.113883.5.4', 'codeSystemName'=>'ActCode');
1114 $xml->self_codeCustom($arr);
1116 //$arr = array('code'=>'completed');
1117 //$xml->self_customTag('statusCode', $arr);
1119 $arr = array('xsi:type'=>'INT', 'value'=>$detailsArr['gender'][$GVal]);
1120 $xml->self_customTag('value', $arr);
1122 $arr = array('code'=>'COUNT', 'displayName'=>'Count', 'codeSystem'=>'2.16.840.1.113883.5.84', 'codeSystemName'=>'ObservationMethod');
1123 $xml->self_customTag('methodCode', $arr);
1126 $xml->close_customTag();
1128 //entryRelationship Close
1129 $xml->close_customTag();
1133 $xml->close_customTag();
1135 //entryRelationship Close
1136 $xml->close_customTag();
1138 ####################################################
1139 ####################################################
1140 //Sex Supplemental Data Element END
1141 ####################################################
1142 ####################################################
1144 ####################################################
1145 ####################################################
1146 //Ethnicity Supplemental Data Element (CMS EP) START
1147 ####################################################
1148 ####################################################
1150 foreach($mainEthiArr as $ethKey => $ethVal){
1151 //entryRelationship Open
1152 $xml->open_customTag('entryRelationship', array('typeCode'=>'COMP'));
1155 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
1157 $tempID = "2.16.840.1.113883.10.20.27.3.7";
1158 $xml->self_templateid($tempID);
1160 $tempID = "2.16.840.1.113883.10.20.27.3.22";
1161 $xml->self_templateid($tempID);
1163 $arr = array('code'=>'364699009', 'displayName'=>'Ethnic Group', 'codeSystem'=>'2.16.840.1.113883.6.96', 'codeSystemName'=>'SNOMED-CT');
1164 $xml->self_codeCustom($arr);
1166 $arr = array('code'=>'completed');
1167 $xml->self_customTag('statusCode', $arr);
1169 $arr = array('xsi:type'=>'CD', 'code'=>$mainEthiCodeArr[$ethKey], 'displayName'=>$ethVal, 'codeSystem' =>'2.16.840.1.113883.6.238', 'codeSystemName'=>'Race & Ethnicity - CDC');
1170 $xml->self_customTag('value', $arr);
1172 //entryRelationship Open
1173 $xml->open_customTag('entryRelationship', array('typeCode'=>'SUBJ', 'inversionInd'=>'true'));
1176 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
1178 $tempID = "2.16.840.1.113883.10.20.27.3.3";
1179 $xml->self_templateid($tempID);
1181 $tempID = "2.16.840.1.113883.10.20.27.3.24";
1182 $xml->self_templateid($tempID);
1184 $arr = array('code'=>'MSRAGG', 'displayName'=>'rate aggregation', 'codeSystem'=>'2.16.840.1.113883.5.4', 'codeSystemName'=>'ActCode');
1185 $xml->self_codeCustom($arr);
1187 //$arr = array('code'=>'completed');
1188 //$xml->self_customTag('statusCode', $arr);
1190 $arr = array('xsi:type'=>'INT', 'value'=>$detailsArr['ethnicity'][$ethVal]);
1191 $xml->self_customTag('value', $arr);
1193 $arr = array('code'=>'COUNT', 'displayName'=>'Count', 'codeSystem'=>'2.16.840.1.113883.5.84', 'codeSystemName'=>'ObservationMethod');
1194 $xml->self_customTag('methodCode', $arr);
1197 $xml->close_customTag();
1199 //entryRelationship Close
1200 $xml->close_customTag();
1204 $xml->close_customTag();
1206 //entryRelationship Close
1207 $xml->close_customTag();
1210 ####################################################
1211 ####################################################
1212 //Ethnicity Supplemental Data Element (CMS EP) END
1213 ####################################################
1214 ####################################################
1217 ####################################################
1218 ####################################################
1219 //Race Supplemental Data Element (CMS EP) START
1220 ####################################################
1221 ####################################################
1223 foreach($mainQrdaRaceArr as $RKey => $RVal){
1224 //entryRelationship Open
1225 $xml->open_customTag('entryRelationship', array('typeCode'=>'COMP'));
1228 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
1230 $tempID = "2.16.840.1.113883.10.20.27.3.8";
1231 $xml->self_templateid($tempID);
1233 $tempID = "2.16.840.1.113883.10.20.27.3.19";
1234 $xml->self_templateid($tempID);
1236 $arr = array('code'=>'103579009', 'displayName'=>'Race', 'codeSystem'=>'2.16.840.1.113883.6.96', 'codeSystemName'=>'SNOMED-CT');
1237 $xml->self_codeCustom($arr);
1239 $arr = array('code'=>'completed');
1240 $xml->self_customTag('statusCode', $arr);
1242 $arr = array('xsi:type'=>'CD', 'code'=>$mainQrdaRaceCodeArr[$RKey], 'displayName'=>$RVal, 'codeSystem' =>'2.16.840.1.113883.6.238', 'codeSystemName'=>'Race & Ethnicity - CDC');
1243 $xml->self_customTag('value', $arr);
1245 //entryRelationship Open
1246 $xml->open_customTag('entryRelationship', array('typeCode'=>'SUBJ', 'inversionInd'=>'true'));
1249 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
1251 $tempID = "2.16.840.1.113883.10.20.27.3.3";
1252 $xml->self_templateid($tempID);
1254 $tempID = "2.16.840.1.113883.10.20.27.3.24";
1255 $xml->self_templateid($tempID);
1257 $arr = array('code'=>'MSRAGG', 'displayName'=>'rate aggregation', 'codeSystem'=>'2.16.840.1.113883.5.4', 'codeSystemName'=>'ActCode');
1258 $xml->self_codeCustom($arr);
1260 //$arr = array('code'=>'completed');
1261 //$xml->self_customTag('statusCode', $arr);
1263 $arr = array('xsi:type'=>'INT', 'value'=>$detailsArr['race'][$RVal]);
1264 $xml->self_customTag('value', $arr);
1266 $arr = array('code'=>'COUNT', 'displayName'=>'Count', 'codeSystem'=>'2.16.840.1.113883.5.84', 'codeSystemName'=>'ObservationMethod');
1267 $xml->self_customTag('methodCode', $arr);
1270 $xml->close_customTag();
1272 //entryRelationship Close
1273 $xml->close_customTag();
1277 $xml->close_customTag();
1279 //entryRelationship Close
1280 $xml->close_customTag();
1283 ####################################################
1284 ####################################################
1285 //Race Supplemental Data Element (CMS EP) END
1286 ####################################################
1287 ####################################################
1290 ####################################################
1291 ####################################################
1292 //Payer Supplemental Data Element (CMS EP) START
1293 ####################################################
1294 ####################################################
1295 $payerCheckArr = getQRDAPayerInfo($fullPatArr);
1296 foreach($mainQrdaPayerCodeArr as $PKey => $PVal){
1297 //entryRelationship Open
1298 $xml->open_customTag('entryRelationship', array('typeCode'=>'COMP'));
1301 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
1303 $tempID = "2.16.840.1.113883.10.20.27.3.9";
1304 $xml->self_templateid($tempID);
1306 $tempID = "2.16.840.1.113883.10.20.24.3.55";
1307 $xml->self_templateid($tempID);
1309 $tempID = "2.16.840.1.113883.10.20.27.3.18";
1310 $xml->self_templateid($tempID);
1312 $xml->self_setpatientRoleid();
1314 $arr = array('code'=>'48768-6', 'displayName'=>'Payment source', 'codeSystem'=>'2.16.840.1.113883.6.1', 'codeSystemName'=>'SNOMED-CT');
1315 $xml->self_codeCustom($arr);
1317 $arr = array('code'=>'completed');
1318 $xml->self_customTag('statusCode', $arr);
1320 $timeArr = array('low'=>date('Ymd', strtotime($from_date)));
1321 $xml->add_entryEffectTime($timeArr);
1325 $xml->open_customTag('value', array('xsi:type'=>'CD', 'nullFlavor'=>'OTH'));
1327 $xml->self_customTag('translation', array('code'=>$PKey, 'displayName'=>$PVal, 'codeSystem'=>'2.16.840.1.113883.3.249.12', 'codeSystemName'=>'CMS Clinical Codes'));
1330 $xml->close_customTag();
1334 $xml->self_customTag('value', array('xsi:type'=>'CD', 'code'=>$mainQrdaPayerCodeSendArr[$PKey], 'codeSystem'=>'2.16.840.1.113883.3.221.5' , 'codeSystemName'=>'SOP', 'displayName'=>$PVal));
1336 //entryRelationship Open
1337 $xml->open_customTag('entryRelationship', array('typeCode'=>'SUBJ', 'inversionInd'=>'true'));
1340 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
1342 $tempID = "2.16.840.1.113883.10.20.27.3.3";
1343 $xml->self_templateid($tempID);
1345 $tempID = "2.16.840.1.113883.10.20.27.3.24";
1346 $xml->self_templateid($tempID);
1348 $arr = array('code'=>'MSRAGG', 'displayName'=>'rate aggregation', 'codeSystem'=>'2.16.840.1.113883.5.4', 'codeSystemName'=>'ActCode');
1349 $xml->self_codeCustom($arr);
1351 //$arr = array('code'=>'completed');
1352 //$xml->self_customTag('statusCode', $arr);
1354 $arr = array('xsi:type'=>'INT', 'value'=>$payerCheckArr[$PVal]);
1355 $xml->self_customTag('value', $arr);
1357 $arr = array('code'=>'COUNT', 'displayName'=>'Count', 'codeSystem'=>'2.16.840.1.113883.5.84', 'codeSystemName'=>'ObservationMethod');
1358 $xml->self_customTag('methodCode', $arr);
1361 $xml->close_customTag();
1363 //entryRelationship Close
1364 $xml->close_customTag();
1368 $xml->close_customTag();
1370 //entryRelationship Close
1371 $xml->close_customTag();
1374 ####################################################
1375 ####################################################
1376 //Payer Supplemental Data Element (CMS EP) END
1377 ####################################################
1378 ####################################################
1380 ######################################################################
1382 $arr = array('typeCode'=>'REFR');
1383 $xml->open_customTag('reference', $arr);
1385 //externalObservation Start
1386 $arr = array('classCode'=>'OBS', 'moodCode'=>'EVN');
1387 $xml->open_customTag('externalObservation', $arr);
1389 //Modified HQMF_ID for CQM IDS
1390 if( ($row['cqm_nqf_code'] == "0421" ) ){
1391 $refID = $preDefPopIdArr[$row['cqm_nqf_code']][$row['numerator_label']][$mainQrdaPopulationIncArr[$cqmKey]];
1392 }else if( ($row['cqm_nqf_code'] == "0024") ){
1393 $refID = $preDefPopIdArr[$row['cqm_nqf_code']][$row['population_label']][$row['numerator_label']][$mainQrdaPopulationIncArr[$cqmKey]];
1395 $refID = $preDefPopIdArr[$row['cqm_nqf_code']][$mainQrdaPopulationIncArr[$cqmKey]];
1400 $xml->self_customId($refID);
1402 //externalObservation Close
1403 $xml->close_customTag();
1406 $xml->close_customTag();
1407 ########################################################################
1410 $xml->close_customTag();
1412 $xml->close_loopComponent();
1413 ############### Initial patient population template END#####################
1416 //Multiple Numerator Handling
1417 if(in_array($row['cqm_nqf_code'], $multNumNQFArr)){
1418 //Skipping Multiple Numerator(s)
1419 if(in_array($row['cqm_nqf_code'], $multNumNQFArr)){
1420 $skipMultNumArr[$row['cqm_nqf_code']] = true;
1422 if($dataChkArr[$row['cqm_nqf_code']] == $countNumNQFArr[$row['cqm_nqf_code']]){
1424 $xml->close_customTag();
1425 $xml->close_entry();
1429 $xml->close_customTag();
1430 $xml->close_entry();
1433 ###########################################################
1439 #######################################################################
1440 ######################### QUALITY MEASURES END ########################
1441 #######################################################################
1444 $xml->close_section();
1446 $xml->close_loopComponent();
1448 ##################### LOOP Component(s) END ########################
1450 $xml->close_structuredBody();
1451 ############### Structure Body Close #######################
1453 $xml->close_mainComponent();
1454 ############### Main Component Close #######################
1456 //Close Main Clinical Document
1457 $xml->close_clinicaldocument();
1460 //QRDA File Download Folder in site/cqm_qrda folder
1461 $qrda_fname = "QRDA_III_".date("YmdHis").".xml";
1462 $qrda_file_path = $GLOBALS['OE_SITE_DIR'] . "/documents/cqm_qrda/";
1463 if(!file_exists($qrda_file_path)){
1464 mkdir($qrda_file_path, 0777, true);
1466 $qrda_file_name = $qrda_file_path.$qrda_fname;
1467 $fileQRDAOPen = fopen($qrda_file_name, "w");
1468 fwrite($fileQRDAOPen, trim($xml->getXml()));
1469 fclose($fileQRDAOPen);
1474 <?php
html_header_show();?
>
1475 <script type
="text/javascript" src
="<?php echo $webroot ?>/interface/main/tabs/js/include_opener.js"></script
>
1476 <link rel
=stylesheet href
="<?php echo $css_header;?>" type
="text/css">
1477 <title
><?php
echo xlt('Export QRDA Report'); ?
></title
>
1479 <script type
="text/javascript">
1481 function closeme() {
1488 <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
>
1493 <a href
="qrda_download.php?qrda_fname=<?php echo attr($qrda_fname);?>"><?php
echo xlt("Download QRDA Category III File");?
></a
>
1495 <textarea rows
='50' cols
='500' style
='width:95%' readonly
>
1496 <?php
echo trim($xml->getXml()); ?
>
1499 <p
><input type
='button' value
='<?php echo xla('Close
'); ?>' onclick
='closeme();' /></p
>