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
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 use OpenEMR\Services\FacilityService
;
36 $facilityService = new FacilityService();
38 //Remove time limit, since script can take many minutes
41 //DENEXCEP NOT NEEDED rules
42 $denExcepNotNeedRules = array('0002', '0018', '0024', '0038', '0043', '0059', '0421');
44 //Predefined QRDA HQMF ID's for CQM rules
45 $preDefinedUniqIDRules = array();
46 $preDefPopIdArr = array();
48 // CMS147v4/0041 - Preventive Care and Screening: Influenza Immunization HQMF ID: 40280381-4600-425F-0146-EE66F0005509
49 $preDefinedUniqIDRules['0041'] = '40280381-4600-425F-0146-EE66F0005509';
50 $preDefPopIdArr['0041']['IPP'] = 'F48702E6-D39A-49D8-BE3C-8FAB5C6AADDA';
51 $preDefPopIdArr['0041']['DENOM'] = 'B61EC2DC-0841-4906-A84B-5BE5024DA7F1';
52 $preDefPopIdArr['0041']['NUMER'] = '0ED7B212-369B-489A-A5B5-07BC146FA557';
53 $preDefPopIdArr['0041']['DENEXCEP'] = 'B5C9EC50-3011-43DC-AD07-CED2D3B770B2';
55 // CMS122v3/0059 - Diabetes: Hemoglobin A1c Poor Control: HQMF_ID: 40280381-4555-E1C1-0145-90AC70DE2C73
56 $preDefinedUniqIDRules['0059'] = '40280381-4555-E1C1-0145-90AC70DE2C73';
57 $preDefPopIdArr['0059']['IPP'] = 'EDED90E9-E4FE-47E6-90AC-29D9AA3E861A';
58 $preDefPopIdArr['0059']['DENOM'] = '6721D6DA-E87D-4E42-A34A-C8490686598C';
59 $preDefPopIdArr['0059']['NUMER'] = '7549BA9E-1841-4231-8CAA-095BDF0AB8A1';
62 //CMS139v3/0101 - Falls: Screening for Future Fall Risk: HQMF_ID: 40280381-4555-E1C1-0145-672613970D15
63 $preDefinedUniqIDRules['0101'] = '40280381-4555-E1C1-0145-672613970D15';
64 $preDefPopIdArr['0101']['IPP'] = '2448B0C6-6848-4DCB-AA6D-F199337A2C5C';
65 $preDefPopIdArr['0101']['DENOM'] = 'EC400908-35BE-439B-92A9-231D99CEA9DF';
66 $preDefPopIdArr['0101']['NUMER'] = '663FB12B-0FF4-49AB-80A3-624C5E7DF892';
67 $preDefPopIdArr['0101']['DENEXCEP'] = 'FEC7251A-BF8D-4472-97D8-E2A9C0A42176';
69 //CMS127v3/0043 - Pneumonia Vaccination Status for Older Adults: HQMF_ID: 40280381-4555-E1C1-0145-762578A81C4C
70 $preDefinedUniqIDRules['0043'] = '40280381-4555-E1C1-0145-762578A81C4C';
71 $preDefPopIdArr['0043']['IPP'] = '873AECC7-E15B-49E7-8391-D73A46201E2E';
72 $preDefPopIdArr['0043']['DENOM'] = 'FF7016E1-E8C7-43BA-9D56-2BEF649F36FA';
73 $preDefPopIdArr['0043']['NUMER'] = '201F5A6E-4DDE-43A2-BDFC-CE85A98560DA';
75 //CMS69v3/0421 - Preventive Care and Screening: Body Mass Index (BMI) Screening and Follow-Up Plan: HQMF_ID: 40280381-4555-E1C1-0145-D2B36DBB3FE6
76 $preDefinedUniqIDRules['0421']['Numerator 1'] = '40280381-4555-E1C1-0145-D2B36DBB3FE6';
77 $preDefPopIdArr['0421']['Numerator 1']['IPP'] = '1C936855-E644-44C0-B264-49A28756FDB1';
78 $preDefPopIdArr['0421']['Numerator 1']['DENOM'] = '27F1591C-2060-462C-B5D7-7FE86A44B534';
79 $preDefPopIdArr['0421']['Numerator 1']['DENEX'] = '9B0C3C26-D621-4EA3-81FB-A839A3012044';
80 $preDefPopIdArr['0421']['Numerator 1']['NUMER'] = '3095531C-24D7-4AFB-9BCB-F1901FF0FF69';
82 $preDefinedUniqIDRules['0421']['Numerator 2'] = '40280381-4555-E1C1-0145-D2B36DBB3FE6';
83 $preDefPopIdArr['0421']['Numerator 2']['IPP'] = '6E701B1C-6CA5-4AD5-98C9-5F766745EA89';
84 $preDefPopIdArr['0421']['Numerator 2']['DENOM'] = 'E4DC29B8-EB26-4A01-ABB0-4F99FC03BA39';
85 $preDefPopIdArr['0421']['Numerator 2']['DENEX'] = 'BB1B4301-C275-4BAC-87C9-6E960B1601DA';
86 $preDefPopIdArr['0421']['Numerator 2']['NUMER'] = '7669026D-3683-44CC-A2C5-3D62EB2F8A33';
88 //CMS117v3/0038 - Childhood Immunization Status: HQMF_ID: 40280381-4555-E1C1-0145-D7C003364261
89 $preDefinedUniqIDRules['0038'] = '40280381-4555-E1C1-0145-D7C003364261';
90 $preDefPopIdArr['0038']['IPP'] = '6ED6A787-C871-49B9-825C-70A0DB898977';
91 $preDefPopIdArr['0038']['DENOM'] = '545DA813-89ED-4DCD-BDDF-4B33D93DCD84';
92 $preDefPopIdArr['0038']['NUMER'] = '00193FC7-AEE4-4507-A20F-D25A7BB214AD';
94 //CMS138v3/0028 - Preventive Care and Screening: Tobacco Use: Screening and Cessation Intervention: HQMF_ID: 40280381-4600-425F-0146-1F5867D40E82
95 $preDefinedUniqIDRules['0028'] = '40280381-4600-425F-0146-1F5867D40E82';
96 $preDefPopIdArr['0028']['IPP'] = '4E118B62-2AF8-4F51-9355-6FD3F2427D9F';
97 $preDefPopIdArr['0028']['DENOM'] = 'FA1B3953-AE58-4541-BF7B-84D0EB1B0713';
98 $preDefPopIdArr['0028']['NUMER'] = '35B1A6DF-1871-4633-A74B-BCAE371BC030';
99 $preDefPopIdArr['0028']['DENEXCEP'] = '3EE6DFF5-AB17-482F-A147-E6D1E46DBB79';
101 //CMS157v3/0384 - Oncology: Medical and Radiation – Pain Intensity Quantified: HQMF_ID: 40280381-4600-425F-0146-1F620BDF0EB0
102 $preDefinedUniqIDRules['0384'] = '40280381-4600-425F-0146-1F620BDF0EB0';
103 $preDefPopIdArr['0384']['IPP'] = 'C29B6555-3BC7-416F-B61A-FCACD637594F';
104 $preDefPopIdArr['0384']['DENOM'] = 'E5F80C25-6816-4992-92E2-A735B17F8D4F';
105 $preDefPopIdArr['0384']['NUMER'] = 'C948D0D2-D6E9-4099-9CD4-870F2F83A14C';
107 //CMS146v3/0002 - Appropriate Testing for Children with Pharyngitis: HQMF_ID: 40280381-4600-425F-0146-1F6E280C0F09
108 $preDefinedUniqIDRules['0002'] = '40280381-4600-425F-0146-1F6E280C0F09';
109 $preDefPopIdArr['0002']['IPP'] = '9D1135EA-BA90-45E7-8EED-F7335D1CC934';
110 $preDefPopIdArr['0002']['DENOM'] = 'D04EFECB-A901-4565-BDDB-826510499092';
111 $preDefPopIdArr['0002']['NUMER'] = '3F4CDE57-1C5C-4250-A338-55FED6775F57';
112 $preDefPopIdArr['0002']['DENEX'] = '0525FBA2-F068-4706-ADB5-E345852DC55B';
114 //CMS165v3/0018 - Controlling High Blood Pressure: HQMF_ID: 40280381-4600-425F-0146-1F6F722B0F17
115 $preDefinedUniqIDRules['0018'] = '40280381-4600-425F-0146-1F6F722B0F17';
116 $preDefPopIdArr['0018']['IPP'] = 'A72855CE-3C60-41F9-AEE2-64D4F584DDD4';
117 $preDefPopIdArr['0018']['DENOM'] = '26046A5C-E2CC-4A27-B480-FF7E3575691F';
118 $preDefPopIdArr['0018']['NUMER'] = '0899A359-0CD8-4977-AA29-666892AA3AD4';
119 $preDefPopIdArr['0018']['DENEX'] = '4327D845-6194-410D-A48D-D6E1802CAD55';
121 //CMS155v3/0024 - Weight Assessment and Counseling for Nutrition and Physical Activity for Children and Adolescents: HQMF_ID: 40280381-4555-E1C1-0145-85C7311720F5
122 $preDefinedUniqIDRules['0024']['Population Criteria 1']['Numerator 1'] = '40280381-4555-E1C1-0145-85C7311720F5';
123 $preDefPopIdArr['0024']['Population Criteria 1']['Numerator 1']['IPP'] = '10127790-AE94-4070-9DD3-1D3776D08D7C';
124 $preDefPopIdArr['0024']['Population Criteria 1']['Numerator 1']['DENOM'] = '3B3C1568-F875-49B1-9090-E2F494EECBB6';
125 $preDefPopIdArr['0024']['Population Criteria 1']['Numerator 1']['DENEX'] = 'B288D5A4-D573-4FAA-92D6-0B01E1B35C7A';
126 $preDefPopIdArr['0024']['Population Criteria 1']['Numerator 1']['NUMER'] = 'FD4649BD-B962-4CBE-BF4A-C2F95F3EA08E';
128 $preDefinedUniqIDRules['0024']['Population Criteria 1']['Numerator 2'] = '40280381-4555-E1C1-0145-85C7311720F5';
129 $preDefPopIdArr['0024']['Population Criteria 1']['Numerator 2']['IPP'] = '10127790-AE94-4070-9DD3-1D3776D08D7C';
130 $preDefPopIdArr['0024']['Population Criteria 1']['Numerator 2']['DENOM'] = '3B3C1568-F875-49B1-9090-E2F494EECBB6';
131 $preDefPopIdArr['0024']['Population Criteria 1']['Numerator 2']['DENEX'] = 'B288D5A4-D573-4FAA-92D6-0B01E1B35C7A';
132 $preDefPopIdArr['0024']['Population Criteria 1']['Numerator 2']['NUMER'] = '52FBD726-4DD1-48F5-98B9-7175754923E1';
134 $preDefinedUniqIDRules['0024']['Population Criteria 1']['Numerator 3'] = '40280381-4555-E1C1-0145-85C7311720F5';
135 $preDefPopIdArr['0024']['Population Criteria 1']['Numerator 3']['IPP'] = '10127790-AE94-4070-9DD3-1D3776D08D7C';
136 $preDefPopIdArr['0024']['Population Criteria 1']['Numerator 3']['DENOM'] = '3B3C1568-F875-49B1-9090-E2F494EECBB6';
137 $preDefPopIdArr['0024']['Population Criteria 1']['Numerator 3']['DENEX'] = 'B288D5A4-D573-4FAA-92D6-0B01E1B35C7A';
138 $preDefPopIdArr['0024']['Population Criteria 1']['Numerator 3']['NUMER'] = 'C43CE779-C5EE-4C15-A4CC-AF1C446CFB09';
140 $preDefinedUniqIDRules['0024']['Population Criteria 2']['Numerator 1'] = '40280381-4555-E1C1-0145-85C7311720F5';
141 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 1']['IPP'] = '10127790-AE94-4070-9DD3-1D3776D08D7C';
142 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 1']['DENOM'] = '3B3C1568-F875-49B1-9090-E2F494EECBB6';
143 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 1']['DENEX'] = 'B288D5A4-D573-4FAA-92D6-0B01E1B35C7A';
144 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 1']['NUMER'] = 'FD4649BD-B962-4CBE-BF4A-C2F95F3EA08E';
145 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 1']['STRAT'] = '40280381-3D61-56A7-013E-5D53298E6DA3';
146 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 1']['DISPLAY_TEXT'] = 'BMI Recorded, RS1: 3-11';
148 $preDefinedUniqIDRules['0024']['Population Criteria 2']['Numerator 2'] = '40280381-4555-E1C1-0145-85C7311720F5';
149 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 2']['IPP'] = '10127790-AE94-4070-9DD3-1D3776D08D7C';
150 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 2']['DENOM'] = '3B3C1568-F875-49B1-9090-E2F494EECBB6';
151 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 2']['DENEX'] = 'B288D5A4-D573-4FAA-92D6-0B01E1B35C7A';
152 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 2']['NUMER'] = '52FBD726-4DD1-48F5-98B9-7175754923E1';
153 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 2']['STRAT'] = '40280381-3D61-56A7-013E-5D53298E6DA3';
154 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 2']['DISPLAY_TEXT'] = 'BMI Recorded, RS2: 12-17';
156 $preDefinedUniqIDRules['0024']['Population Criteria 2']['Numerator 3'] = '40280381-4555-E1C1-0145-85C7311720F5';
157 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 3']['IPP'] = '10127790-AE94-4070-9DD3-1D3776D08D7C';
158 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 3']['DENOM'] = '3B3C1568-F875-49B1-9090-E2F494EECBB6';
159 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 3']['DENEX'] = 'B288D5A4-D573-4FAA-92D6-0B01E1B35C7A';
160 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 3']['NUMER'] = 'C43CE779-C5EE-4C15-A4CC-AF1C446CFB09';
161 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 3']['STRAT'] = '40280381-3D61-56A7-013E-5D53298E6DA3';
162 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 3']['DISPLAY_TEXT'] = 'Nutrition Counseling, RS1: 3-11';
164 $preDefinedUniqIDRules['0024']['Population Criteria 3']['Numerator 1'] = '40280381-4555-E1C1-0145-85C7311720F5';
165 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 1']['IPP'] = '10127790-AE94-4070-9DD3-1D3776D08D7C';
166 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 1']['DENOM'] = '3B3C1568-F875-49B1-9090-E2F494EECBB6';
167 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 1']['DENEX'] = 'B288D5A4-D573-4FAA-92D6-0B01E1B35C7A';
168 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 1']['NUMER'] = 'FD4649BD-B962-4CBE-BF4A-C2F95F3EA08E';
169 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 1']['STRAT'] = '40280381-3D61-56A7-013E-5D532AF06DA5';
170 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 1']['DISPLAY_TEXT'] = 'Nutrition Counseling, RS2: 12-17';
172 $preDefinedUniqIDRules['0024']['Population Criteria 3']['Numerator 2'] = '40280381-4555-E1C1-0145-85C7311720F5';
173 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 2']['IPP'] = '10127790-AE94-4070-9DD3-1D3776D08D7C';
174 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 2']['DENOM'] = '3B3C1568-F875-49B1-9090-E2F494EECBB6';
175 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 2']['DENEX'] = 'B288D5A4-D573-4FAA-92D6-0B01E1B35C7A';
176 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 2']['NUMER'] = '52FBD726-4DD1-48F5-98B9-7175754923E1';
177 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 2']['STRAT'] = '40280381-3D61-56A7-013E-5D532AF06DA5';
178 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 2']['DISPLAY_TEXT'] = 'Physical Activity Counseling, RS1: 3-11';
180 $preDefinedUniqIDRules['0024']['Population Criteria 3']['Numerator 3'] = '40280381-4555-E1C1-0145-85C7311720F5';
181 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 3']['IPP'] = '10127790-AE94-4070-9DD3-1D3776D08D7C';
182 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 3']['DENOM'] = '3B3C1568-F875-49B1-9090-E2F494EECBB6';
183 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 3']['DENEX'] = 'B288D5A4-D573-4FAA-92D6-0B01E1B35C7A';
184 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 3']['NUMER'] = 'C43CE779-C5EE-4C15-A4CC-AF1C446CFB09';
185 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 3']['STRAT'] = '40280381-3D61-56A7-013E-5D532AF06DA5';
186 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 3']['DISPLAY_TEXT'] = 'Physical Activity Counseling, RS2: 12-17';
188 $preDefPopIdArr['0024']['STRAT1'] = '40280381-3D61-56A7-013E-5D53298E6DA3';
189 $preDefPopIdArr['0024']['STRAT2'] = '40280381-3D61-56A7-013E-5D532AF06DA5';
191 //Multiple Numerator NQF# Array declaration
192 $multNumNQFArr = array('0421', '0024');
193 $countNumNQFArr = array();
194 $countNumNQFArr['0421'] = 2;//two Numerators
195 $countNumNQFArr['0024'] = 9;//Nine Numerators
197 //Initiation of all QRDA needed elements
198 $CQMeausesArr = array();
199 $CQMeausesArr['init_patients'] = "Initial Patient Population";
200 $CQMeausesArr['exclude_patients'] = "Denominator Exclusions";
201 $CQMeausesArr['denom_patients'] = "Denominator";
202 $CQMeausesArr['numer_patients'] = "Numerator";
203 $CQMeausesArr['exception_patients'] = "Denominator Exceptions";
205 $cqmItemizedArr = array();
206 $cqmItemizedArr['init_patients'] = "init_patients";
207 $cqmItemizedArr['exclude_patients'] = "exclude";
208 $cqmItemizedArr['denom_patients'] = "all";
209 $cqmItemizedArr['numer_patients'] = "pass";
210 $cqmItemizedArr['exception_patients'] = "exception";
212 //QRDA Needed Ethnicity
213 $mainEthiArr = array(0=>'Not Hispanic or Latino', 1=>'Hispanic or Latino');
214 $mainEthiCodeArr = array(0=>'2186-5', 1=>'2135-2');
217 $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');
218 $mainQrdaRaceCodeArr = array(0=>'1002-5', 1=>'2028-9', 2=>'2054-5', 3=>'2076-8', 4=>'2106-3', 5=>'2131-1');
220 $mainQrdaPopulationIncArr = array();
221 $mainQrdaPopulationIncArr['init_patients'] = "IPP";
222 $mainQrdaPopulationIncArr['exclude_patients'] = "DENEX";
223 $mainQrdaPopulationIncArr['denom_patients'] = "DENOM";
224 $mainQrdaPopulationIncArr['numer_patients'] = "NUMER";
225 $mainQrdaPopulationIncArr['exception_patients'] = "DENEXCEP";
226 $mainQrdaPopulationIncArr['measure_population'] = "MSRPOPL";
227 $mainQrdaPopulationIncArr['numer_exclusion'] = "NUMEX";
230 $mainQrdaGenderCodeArr = array();
231 $mainQrdaGenderCodeArr['F'] = "Female";
232 $mainQrdaGenderCodeArr['M'] = "Male";
233 $mainQrdaGenderCodeArr['UN'] = "Unknown";
235 //QRDA Needed Payer Info
236 $mainQrdaPayerCodeArr = array();
237 $mainQrdaPayerCodeArr['A'] = "Medicare";
238 $mainQrdaPayerCodeArr['B'] = "Medicaid";
239 $mainQrdaPayerCodeArr['C'] = "Private Health Insurance";
240 $mainQrdaPayerCodeArr['D'] = "Other";
242 //Payer Codes According to Cypress Codes
243 $mainQrdaPayerCodeSendArr = array();
244 $mainQrdaPayerCodeSendArr['A'] = "1";
245 $mainQrdaPayerCodeSendArr['B'] = "2";
246 $mainQrdaPayerCodeSendArr['C'] = "5";
247 $mainQrdaPayerCodeSendArr['D'] = "349";
250 $form_provider = $_GET['form_provider'];
252 //Get Report Information
253 $report_id = $_GET['report_id'];
254 $report_view = collectReportDatabase($report_id);
255 $target_date = $report_view['date_target'];
256 $dataSheet = json_decode($report_view['data'], true);
258 //Needed array for Rule NQF#0024 Stratification
259 $stratumCheckArr = array();
260 if (count($dataSheet) > 0) {
262 foreach ($dataSheet as $row) {
263 $itemized_test_id = $row['itemized_test_id'];
264 $numerator_label = $row['numerator_label'];
265 if ($row['cqm_nqf_code'] == "0024") {
266 if ($row['population_label'] == "Population Criteria 2") {
267 if ($row['numerator_label'] == "Numerator 1") {
268 $stratum_1_ipp = $row['initial_population'];
269 $stratum_1_exclude = $row['excluded'];
270 $stratum_1_denom = $row['pass_filter'];
271 $stratum_1_numer1 = $row['pass_target'];
272 } else if ($row['numerator_label'] == "Numerator 2") {
273 $stratum_1_numer2 = $row['pass_target'];
274 } else if ($row['numerator_label'] == "Numerator 3") {
275 $stratum_1_numer3 = $row['pass_target'];
277 } else if ($row['population_label'] == "Population Criteria 3") {
278 if ($row['numerator_label'] == "Numerator 1") {
279 $stratum_2_ipp = $row['initial_population'];
280 $stratum_2_exclude = $row['excluded'];
281 $stratum_2_denom = $row['pass_filter'];
282 $stratum_2_numer1 = $row['pass_target'];
283 } else if ($row['numerator_label'] == "Numerator 2") {
284 $stratum_2_numer2 = $row['pass_target'];
285 } else if ($row['numerator_label'] == "Numerator 3") {
286 $stratum_2_numer3 = $row['pass_target'];
292 $stratum[1] = array('init_patients' => $stratum_1_ipp,
293 'exclude_patients' => $stratum_1_exclude,
294 'denom_patients' => $stratum_1_denom,
295 'numer_patients' => $stratum_1_numer1,
296 'numer2' => $stratum_1_numer2,
297 'numer3' => $stratum_1_numer3);
299 $stratum[2] = array('init_patients' => $stratum_2_ipp,
300 'exclude_patients' => $stratum_2_exclude,
301 'denom_patients' => $stratum_2_denom,
302 'numer_patients' => $stratum_2_numer1,
303 'numer2' => $stratum_2_numer2,
304 'numer3' => $stratum_2_numer3);
308 $from_date = date('Y', strtotime($target_date))."-01-01";
309 $to_date = date('Y', strtotime($target_date))."-12-31";
310 $xml = new QRDAXml();
312 #################################################################################################
313 ####################### HEADER ELEMENTS START #####################################################
314 #################################################################################################
315 //Open Main Clinical Document
316 $xml->open_clinicaldocument();
318 $xml->self_realmcode();
322 $tempId = '2.16.840.1.113883.10.20.27.1.1';
323 $xml->self_templateid($tempId);
325 $xml->unique_id
= getUuid();
329 //Main Title Display to XML
330 $main_title = "QRDA Calculated Summary Report";
331 $xml->add_title($main_title);
333 //Effective date and time
334 $eff_datetime = date('Ymdhis', strtotime($target_date));
335 $xml->self_efftime($eff_datetime);
337 $xml->self_confidentcode();
342 $setidVal =getUuid();
343 $xml->self_setid($setidVal);
346 $xml->self_version();
348 //Record Target Elements
349 $xml->open_recordTarget();
350 $xml->add_patientRole();
351 $xml->close_recordTarget();
353 ############### Author Info #######################
356 $auth_dtime = date('Ymdhis', strtotime(date('Y-m-d H:i:s')));
357 $xml->self_authorTime($auth_dtime);
359 $xml->open_assignAuthor();
360 $authorsetid = getUuid();
361 $xml->self_customId($authorsetid);
362 if ($form_provider != "") {
363 $userRow = sqlQuery("SELECT facility, facility_id, federaltaxid, npi, phone,fname, lname FROM users WHERE id=?", array($form_provider));
364 $facility_name = $userRow['facility'];
365 $facility_id = $userRow['facility_id'];
368 //$xml->self_customTag('telecom', array('value' => $userRow['phone'], 'use'=>'WP'));
370 //assignedAuthoringDevice Start
371 $xml->open_customTag('assignedAuthoringDevice');
373 $xml->element('softwareName', 'CYPRESS');
375 //assignedAuthoringDevice Close
376 $xml->close_customTag();
379 $facilResRow = $facilityService->getById($facility_id);
380 $xml->add_authReprestOrginisation($facilResRow);
381 //$xml->add_facilAddress($facilResRow);
382 $xml->close_assignAuthor();
383 $xml->close_author();
385 ############### Custodian Info #######################
386 $xml->open_custodian();
387 $xml->open_assgnCustodian();
388 $xml->add_represtCustodianOrginisation($facilResRow);
389 $xml->close_assgnCustodian();
390 $xml->close_custodian();
393 ############### Information Recipient #######################
394 $xml->open_infoRecipient();
395 $xml->add_indententRecipient();
396 $xml->close_infoRecipient();
399 ############### Legal Authenticator #######################
400 $xml->open_legalAuthenticator();
401 $auth_dtime = date('Ymdhis', strtotime(date('Y-m-d H:i:s')));
402 $xml->self_authorTime($auth_dtime);
403 $xml->self_legalSignCode();
405 $xml->open_assignedEntity();
406 $assignedEntityId = getUuid();
407 $xml->self_customId($assignedEntityId);
409 $xml->open_customTag('assignedPerson');
412 $userNameArr = array('fname' =>$userRow['fname'], 'lname'=>$userRow['lname']);
413 $xml->add_providerName($userNameArr);
415 //assignedPerson Close
416 $xml->close_customTag();
418 //Represent Origination Name
419 $xml->add_authReprestOrginisation($facilResRow);
420 $xml->close_assignedEntity();
422 $xml->close_legalAuthenticator();
425 ############### Participant is Device(optional) #######################
426 $participentDevArr = array();
427 $xml->open_participant_data('DEV');//DEV -- Device
428 $xml->open_assocEntityData('RGPR');//RGPR -- Regulated Product
429 $participentDevArr['root'] = '2.16.840.1.113883.3.2074.1';
430 $participentDevArr['extension'] = '1a2b3c';
431 $xml->self_particpantIdInfo($participentDevArr);
432 $xml->self_participantCodeDevice();
433 $xml->close_assocEntityData();
434 $xml->close_participant_data();
436 ############### Participant is Location(optional) #######################
437 $participentLocArr = array();
438 $xml->open_participant_data('LOC');//LOC -- Location
439 $xml->open_assocEntityData('SDLOC');//SDLOC -- Service Delivery Location
440 $participentLocArr['root'] = '2.16.840.1.113883.3.249.5.1';
441 $participentLocArr['extension'] = 'OK666333';
442 $xml->self_particpantIdInfo($participentLocArr);
443 $xml->self_participantCodeLocation();
445 $xml->add_facilAddress($facilResRow);
446 $xml->close_assocEntityData();
447 $xml->close_participant_data();
450 ############### documentationOf START #######################
451 $xml->open_customTag('documentationOf');
453 $xml->open_customTag('serviceEvent', array('classCode'=>'PCPR'));
455 $timeArr = array('low'=>date('Ymd', strtotime($from_date)), 'high'=>date('Ymd', strtotime($to_date)));
456 $xml->add_entryEffectTime($timeArr);
458 $xml->open_customTag('performer', array('typeCode'=>'PRF'));
460 $xml->open_customTag('assignedEntity');
462 $npi_provider = !empty($userRow['npi']) ?
$userRow['npi'] : '123456789';
463 $xml->self_customTag('id', array('root' => '2.16.840.1.113883.4.6', 'extension' =>$npi_provider));
465 if ($userRow['phone'] != "") {
466 $xml->self_customTag('telecom', array('value' => $userRow['phone'], 'use'=>'WP'));
469 $xml->open_customTag('assignedPerson');
472 $userNameArr = array('fname' =>$userRow['fname'], 'lname'=>$userRow['lname']);
473 $xml->add_providerName($userNameArr);
475 //assignedPerson Close
476 $xml->close_customTag();
478 $xml->open_customTag('representedOrganization');
480 $tin_provider = $userRow['federaltaxid'];
481 if ($tin_provider != "") {
482 $xml->self_customTag('id', array('root' => '2.16.840.1.113883.4.2', 'extension' =>$tin_provider));
485 $xml->add_facilName($facility_name);
487 $xml->add_facilAddress($facilResRow);
489 //representedOrganization Close
490 $xml->close_customTag();
492 //assignedEntity Close
493 $xml->close_customTag();
496 $xml->close_customTag();
499 $xml->close_customTag();
501 //documentationOf Close
502 $xml->close_customTag();
503 ############### documentationOf END #######################
506 ############### authorization (optional) #########################
508 #################################################################################################
509 ####################### HEADER ELEMENTS END #####################################################
510 #################################################################################################
514 #################################################################################################
515 ######################### Main Component Open ###################################################
516 $xml->open_mainComponent();
518 ############### Structure Body Open #######################
519 $xml->open_structuredBody();
521 ##################### LOOP Component(s) START ########################
523 ###################### Report Parameters Open #####################
524 //QRDA Category III Reporting Parameters Section (CMS EP) [section: templateId 2.16.840.1.113883.10.20.27.2.6
525 $xml->open_loopComponent();
527 $xml->open_section();
529 $tempID = '2.16.840.1.113883.10.20.17.2.1';
530 $xml->self_templateid($tempID);
532 $tempID = '2.16.840.1.113883.10.20.27.2.2';
533 $xml->self_templateid($tempID);
535 $tempID = '2.16.840.1.113883.10.20.27.2.6';
536 $xml->self_templateid($tempID);
537 $arr = array('code'=>'55187-9', 'codeSystem'=>'2.16.840.1.113883.6.1');
538 $xml->self_codeCustom($arr);
539 $title = "Reporting Parameters";
540 $xml->add_title($title);
544 $item_title = "Reporting period: ".date('d M Y', strtotime($from_date))." - ".date('d M Y', strtotime($to_date));
545 $xml->add_item($item_title);
550 $xml->open_entry($typeCode);
551 $arr = array('classCode'=>'ACT', 'moodCode'=>'EVN');
552 $xml->open_act($arr);
554 $tempID = '2.16.840.1.113883.10.20.17.3.8';
555 $xml->self_templateid($tempID);
557 $tempID = '2.16.840.1.113883.10.20.27.3.23';
558 $xml->self_templateid($tempID);
561 $xml->self_customId($actId);
563 $arr = array('code'=>'252116004', 'codeSystem'=>'2.16.840.1.113883.6.96', 'displayName'=>'Observation Parameters');
564 $xml->self_codeCustom($arr);
566 $timeArr = array('low'=>date('Ymd', strtotime($from_date)), 'high'=>date('Ymd', strtotime($to_date)));
567 $xml->add_entryEffectTime($timeArr);
572 $xml->close_section();
574 $xml->close_loopComponent();
575 ###################### Report Parameters Close #####################
577 ###################### Measure Section Open #####################
578 $xml->open_loopComponent();
580 $xml->open_section();
582 $tempID = '2.16.840.1.113883.10.20.27.2.1';
583 $xml->self_templateid($tempID);
585 $tempID = '2.16.840.1.113883.10.20.24.2.2';
586 $xml->self_templateid($tempID);
588 $tempID = '2.16.840.1.113883.10.20.27.2.3';
589 $xml->self_templateid($tempID);
591 $arr = array('code'=>'55186-1', 'codeSystem'=>'2.16.840.1.113883.6.1');
592 $xml->self_codeCustom($arr);
593 $title = "Measure Section";
594 $xml->add_title($title);
599 $tabArr = array('border'=>1, 'width'=>'100%');
600 if (count($dataSheet) > 0) {
601 $uniqIdArr = array();
604 foreach ($dataSheet as $row) {
605 $itemized_test_id = $row['itemized_test_id'];
606 $numerator_label = $row['numerator_label'];
608 //CQM Rules 2014 set, 0013 is 0018
609 if ($row['cqm_nqf_code'] == "0013") {
610 $row['cqm_nqf_code'] = "0018";
614 $xml->open_customTag('table', $tabArr);
616 $xml->open_customTag('thead');
618 $xml->open_customTag('tr');
620 $xml->add_trElementsTitles();
623 $xml->close_customTag();
626 $xml->close_customTag();
628 $xml->open_customTag('tbody');
629 $xml->open_customTag('tr');
631 $tdTitle = generate_display_field(array('data_type'=>'1','list_id'=>'clinical_rules'), $row['id']);
633 if (!empty($row['cqm_pqri_code'])) {
634 $tdTitle .= " " . htmlspecialchars(xl('PQRI') . ":" . $row['cqm_pqri_code'], ENT_NOQUOTES
) . " ";
637 if (!empty($row['cqm_nqf_code'])) {
638 $tdTitle .= " " . htmlspecialchars(xl('NQF') . ":" . $row['cqm_nqf_code'], ENT_NOQUOTES
) . " ";
641 if (!(empty($row['concatenated_label']))) {
642 $tdTitle .= ", " . htmlspecialchars(xl($row['concatenated_label']), ENT_NOQUOTES
) . " ";
645 $tdVersionNeutral = getUuid();
647 if ($preDefinedUniqIDRules[$row['cqm_nqf_code']] != "") {
648 if (($row['cqm_nqf_code'] == "0421" )) {
649 $tdVersionSpecific = $preDefinedUniqIDRules[$row['cqm_nqf_code']][$row['numerator_label']];
650 } else if ($row['cqm_nqf_code'] == "0024") {
651 $tdVersionSpecific = $preDefinedUniqIDRules[$row['cqm_nqf_code']][$row['population_label']][$row['numerator_label']];
653 $tdVersionSpecific = $preDefinedUniqIDRules[$row['cqm_nqf_code']];
656 $uniqIdArr[] = $tdVersionSpecific;
658 $tdVersionSpecific = getUuid();
659 $uniqIdArr[] = $tdVersionSpecific;
662 $dataArr = array(0=>$tdTitle, 1=>$tdVersionNeutral, 2=>$tdVersionSpecific);
663 $xml->add_trElementsValues($dataArr);
666 $xml->close_customTag();
668 $xml->close_customTag();
670 $xml->close_customTag();
672 //Open List Item Wise
676 $xml->open_customTag('item');
677 $arrContent = array('name'=>'Performance Rate', 'value'=>$row['percentage']);
678 $xml->innerContent($arrContent);
679 $xml->close_customTag();
682 //All CQM Measures taken here
683 foreach ($CQMeausesArr as $cqmKey => $cqmVal) {
684 //DENEXCEP(Denominator Exception not needed for some rules are skipping here)
685 if ((in_array($row['cqm_nqf_code'], $denExcepNotNeedRules) ) && ($cqmKey == "exception_patients")) {
690 if ($cqmKey == "init_patients") {
691 $itemPatArr = collectItemizedPatientsCdrReport($report_id, $itemized_test_id, $cqmItemizedArr[$cqmKey]);
693 $itemPatArr = collectItemizedPatientsCdrReport($report_id, $itemized_test_id, $cqmItemizedArr[$cqmKey], $numerator_label);
696 $fullPatArr = array();
697 foreach ($itemPatArr as $itemPatInfo) {
698 $fullPatArr[] = $itemPatInfo['pid'];
701 //Initial Patient Population
702 $xml->open_customTag('item');
703 $arrContent = array('name'=>$cqmVal, 'value'=>count($fullPatArr));
704 $xml->innerContent($arrContent);
706 $detailsArr = getQRDAPatientNeedInfo($fullPatArr);
711 //Gender Section Display
712 foreach ($mainQrdaGenderCodeArr as $GKey => $GVal) {
713 $xml->open_customTag('item');
714 $genderInfo = $detailsArr['gender'][$GVal];
715 $arrContent = array('name'=>$GVal, 'value'=>$genderInfo);
716 $xml->innerContent($arrContent);
717 $xml->close_customTag();
720 //Ethnicity Section Display
721 foreach ($mainEthiArr as $ethKey => $ethVal) {
722 $ethnicity_data = $detailsArr['ethnicity'][$ethVal];
723 $xml->open_customTag('item');
724 $arrContent = array('name'=>'Ethnicity - '.$ethVal, 'value'=>$ethnicity_data);
725 $xml->innerContent($arrContent);
726 $xml->close_customTag();
729 //Race Section Display
730 foreach ($mainQrdaRaceArr as $RKey => $RVal) {
731 $race_data = $detailsArr['race'][$RVal];
732 $xml->open_customTag('item');
733 $arrContent = array('name'=>'Race - '.$RVal, 'value'=>$race_data);
734 $xml->innerContent($arrContent);
735 $xml->close_customTag();
738 //Payer Type Section Display
739 $payerCheckArr = getQRDAPayerInfo($fullPatArr);
740 foreach ($mainQrdaPayerCodeArr as $PKey => $PVal) {
741 $xml->open_customTag('item');
742 $arrContent = array('name'=>'Payer - '.$PVal, 'value'=>$payerCheckArr[$PVal]);
743 $xml->innerContent($arrContent);
744 $xml->close_customTag();
749 $xml->close_customTag();
758 #######################################################################
759 ######################### QUALITY MEASURES START ######################
760 #######################################################################
761 if (count($dataSheet) > 0) {
763 $skipMultNumArr = array();
764 $dataChkArr = array();
765 foreach ($multNumNQFArr as $multNumVal) {
766 $skipMultNumArr[$multNumVal] = false;
767 $dataChkArr[$multNumVal] = 0;
771 foreach ($dataSheet as $row) {
772 $itemized_test_id = $row['itemized_test_id'];
773 $numerator_label = $row['numerator_label'];
775 //if($row['cqm_nqf_code'] == "0028a") continue;
777 //if($row['cqm_nqf_code'] == "0038"){
778 // if(in_array($row['numerator_label'], $NQF38NumArr)) continue;
781 if (in_array($row['cqm_nqf_code'], $multNumNQFArr)) {
782 $dataChkArr[$row['cqm_nqf_code']]++
;
785 //CQM Rules 2014 set, 0013 is 0018
786 if ($row['cqm_nqf_code'] == "0013") {
787 $row['cqm_nqf_code'] = "0018";
790 $tdTitle = generate_display_field(array('data_type'=>'1','list_id'=>'clinical_rules'), $row['id']);
791 if (!empty($row['cqm_pqri_code'])) {
792 $tdTitle .= " " . text(xl('PQRI') . ":" . $row['cqm_pqri_code']) . " ";
795 if (!empty($row['cqm_nqf_code'])) {
796 $tdTitle .= " " . text(xl('NQF') . ":" . $row['cqm_nqf_code']) . " ";
799 if (!(empty($row['concatenated_label']))) {
800 $tdTitle .= ", " . text(xl($row['concatenated_label'])) . " ";
803 ###########################################################
804 if (( !isset($skipMultNumArr[$row['cqm_nqf_code']]) ) ||
($skipMultNumArr[$row['cqm_nqf_code']] == false)) {
809 $arr = array('classCode'=>'CLUSTER', 'moodCode'=>'EVN');
810 $xml->open_customTag('organizer', $arr);
812 $tempID = "2.16.840.1.113883.10.20.24.3.98";
813 $xml->self_templateid($tempID);
815 $tempID = "2.16.840.1.113883.10.20.27.3.1";
816 $xml->self_templateid($tempID);
818 //$tempID = "2.16.840.1.113883.10.20.27.3.17";
819 //$xml->self_templateid($tempID);
821 $xml->self_customId($actId);
823 $arr = array('code'=>'completed');
824 $xml->self_customTag('statusCode', $arr);
827 $arr = array('typeCode'=>'REFR');
828 $xml->open_customTag('reference', $arr);
830 //externalDocument Start
831 $arr = array('classCode'=>'DOC', 'moodCode'=>'EVN');
832 $xml->open_customTag('externalDocument', $arr);
834 //$exDocID = getUuid();
835 $exDocID = $uniqIdArr[$innrCnt];
836 //$xml->self_customId($exDocID);
837 $xml->self_customTag('id', array('root' => '2.16.840.1.113883.4.738', 'extension' =>$exDocID));
839 $arr = array('code'=>'57024-2', 'displayName'=>'Health Quality Measure Document', 'codeSystem'=>'2.16.840.1.113883.6.1', 'codeSystemName'=>'LOINC');
840 $xml->self_codeCustom($arr);
842 $dispContntTitle = str_replace("&", '', $tdTitle);
843 $xml->textDispContent($dispContntTitle);
845 //externalDocument Close
846 $xml->close_customTag();
849 $xml->close_customTag();
852 ############### Performance Rate for Proportion Measure template START###################
853 $xml->open_loopComponent();
856 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
858 $tempID = "2.16.840.1.113883.10.20.27.3.14";
859 $xml->self_templateid($tempID);
861 $tempID = "2.16.840.1.113883.10.20.27.3.25";
862 $xml->self_templateid($tempID);
864 $arr = array('code'=>'72510-1', 'displayName'=>'Performance Rate', 'codeSystem'=>'2.16.840.1.113883.6.1', 'codeSystemName'=>'SNOMED-CT');
865 $xml->self_codeCustom($arr);
867 $arr = array('code'=>'completed');
868 $xml->self_customTag('statusCode', $arr);
870 $percentage = str_replace("%", '', $row['percentage']);
871 $arr = array('xsi:type'=>'REAL', 'value'=>$percentage/100);
872 $xml->self_customTag('value', $arr);
875 $arr = array('typeCode'=>'REFR');
876 $xml->open_customTag('reference', $arr);
878 //externalObservation Start
879 $arr = array('classCode'=>'OBS', 'moodCode'=>'EVN');
880 $xml->open_customTag('externalObservation', $arr);
883 //$exDocID = getUuid();
886 if (($row['cqm_nqf_code'] == "0421" )) {
887 $exDocID = $preDefPopIdArr[$row['cqm_nqf_code']][$row['numerator_label']]["NUMER"];
888 } else if (($row['cqm_nqf_code'] == "0024")) {
889 $exDocID = $preDefPopIdArr[$row['cqm_nqf_code']][$row['population_label']][$row['numerator_label']]["NUMER"];
891 if ($preDefPopIdArr[$row['cqm_nqf_code']]["NUMER"] != "") {
892 $exDocID = $preDefPopIdArr[$row['cqm_nqf_code']]["NUMER"];
894 $exDocID = getUuid();
898 $xml->self_customId($exDocID);
900 $arr = array('code'=>'NUMER', 'displayName'=>'Numerator', 'codeSystem'=>'2.16.840.1.113883.5.1063', 'codeSystemName'=>'ObservationValue');
901 $xml->self_codeCustom($arr);
903 //externalObservation Close
904 $xml->close_customTag();
907 $xml->close_customTag();
910 $xml->close_customTag();
912 $xml->close_loopComponent();
913 ############### Performance Rate for Proportion Measure template END ###################
916 //All CQM Measures taken here
917 foreach ($CQMeausesArr as $cqmKey => $cqmVal) {
918 //DENEXCEP(Denominator Exception not needed for some rules are skipping here)
919 if ((in_array($row['cqm_nqf_code'], $denExcepNotNeedRules) ) && ($cqmKey == "exception_patients")) {
923 //cqm 0024 alllowing only nuemerator 2 and numerator 3 for ipp1,ipp2 and 1pp3 to avoid repeatation
924 if ($row['cqm_nqf_code'] == '0024' && ($row['numerator_label'] == "Numerator 2" ||
$row['numerator_label'] == "Numerator 3") && $cqmKey != 'numer_patients') {
928 if ($row['cqm_nqf_code'] == '0024' && ($row['population_label'] == "Population Criteria 2" ||
$row['population_label'] == "Population Criteria 3")) {
934 if ($cqmKey == "init_patients") {
935 $itemPatArr = collectItemizedPatientsCdrReport($report_id, $itemized_test_id, $cqmItemizedArr[$cqmKey]);
937 $itemPatArr = collectItemizedPatientsCdrReport($report_id, $itemized_test_id, $cqmItemizedArr[$cqmKey], $numerator_label);
940 $fullPatArr = array();
941 foreach ($itemPatArr as $itemPatInfo) {
942 $fullPatArr[] = $itemPatInfo['pid'];
945 $detailsArr = getQRDAPatientNeedInfo($fullPatArr);
946 ############### Initial patient population template START###################
947 $xml->open_loopComponent();
950 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
952 $tempID = "2.16.840.1.113883.10.20.27.3.5";
953 $xml->self_templateid($tempID);
955 $tempID = "2.16.840.1.113883.10.20.27.3.16";
956 $xml->self_templateid($tempID);
958 $arr = array('code'=>'ASSERTION', 'displayName'=>'Assertion', 'codeSystem'=>'2.16.840.1.113883.5.4', 'codeSystemName'=>'ActCode');
959 $xml->self_codeCustom($arr);
961 $arr = array('code'=>'completed');
962 $xml->self_customTag('statusCode', $arr);
964 $arr = array('xsi:type'=>'CD', 'code'=>$mainQrdaPopulationIncArr[$cqmKey], 'displayName'=>$cqmVal, 'codeSystem' =>'2.16.840.1.113883.5.1063', 'codeSystemName'=>'ObservationValue');
965 $xml->self_customTag('value', $arr);
967 //entryRelationship Open
968 $xml->open_customTag('entryRelationship', array('typeCode'=>'SUBJ', 'inversionInd'=>'true'));
971 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
973 $tempID = "2.16.840.1.113883.10.20.27.3.3";
974 $xml->self_templateid($tempID);
976 $tempID = "2.16.840.1.113883.10.20.27.3.24";
977 $xml->self_templateid($tempID);
979 $arr = array('code'=>'MSRAGG', 'displayName'=>'rate aggregation', 'codeSystem'=>'2.16.840.1.113883.5.4', 'codeSystemName'=>'ActCode');
980 $xml->self_codeCustom($arr);
982 //$arr = array('code'=>'completed');
983 //$xml->self_customTag('statusCode', $arr);
985 $arr = array('xsi:type'=>'INT', 'value'=>count($fullPatArr));
986 $xml->self_customTag('value', $arr);
988 $arr = array('code'=>'COUNT', 'displayName'=>'Count', 'codeSystem'=>'2.16.840.1.113883.5.84', 'codeSystemName'=>'ObservationMethod');
989 $xml->self_customTag('methodCode', $arr);
992 $xml->close_customTag();
994 //entryRelationship Close
995 $xml->close_customTag();
997 #### Stratum Start (Stratification)#####
998 if ($row['cqm_nqf_code'] == '0024') {
1000 for (; $strat_count <= 2; $strat_count++
) {
1001 $strata_value = $stratum[$strat_count][$cqmKey];
1003 if ($row['numerator_label'] == "Numerator 2") {
1004 $strata_value = $stratum[$strat_count]['numer2'];
1005 } else if ($row['numerator_label'] == "Numerator 3") {
1006 $strata_value = $stratum[$strat_count]['numer3'];
1009 //entryRelationship Open
1010 $xml->open_customTag('entryRelationship', array('typeCode'=>'COMP'));
1013 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
1015 $tempID = "2.16.840.1.113883.10.20.27.3.4";
1016 $xml->self_templateid($tempID);
1018 $tempID = "2.16.840.1.113883.10.20.27.3.20";
1019 $xml->self_templateid($tempID);
1021 $arr = array('code'=>'ASSERTION', 'displayName'=>'Assertion', 'codeSystem'=>'2.16.840.1.113883.5.4', 'codeSystemName'=>'ActCode');
1022 $xml->self_codeCustom($arr);
1024 $arr = array('code'=>'completed');
1025 $xml->self_customTag('statusCode', $arr);
1028 $xml->open_customTag('value', array('xsi:type'=>'CD', 'nullFlavor'=>'OTH'));
1030 $stratumText = $preDefPopIdArr[$row['cqm_nqf_code']][$row['population_label']][$row['numerator_label']]['DISPLAY_TEXT'];
1031 $xml->element('originalText', "Stratum ".$strat_count);
1034 $xml->close_customTag();
1036 //entryRelationship Open
1037 $xml->open_customTag('entryRelationship', array('typeCode'=>'SUBJ', 'inversionInd' => 'true'));
1040 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
1042 $tempID = "2.16.840.1.113883.10.20.27.3.3";
1043 $xml->self_templateid($tempID);
1045 $arr = array('code'=>'MSRAGG', 'displayName'=>'rate aggregation', 'codeSystem'=>'2.16.840.1.113883.5.4', 'codeSystemName'=>'ActCode');
1046 $xml->self_codeCustom($arr);
1048 $arr = array('xsi:type'=>'INT', 'value'=>$strata_value);
1049 $xml->self_customTag('value', $arr);
1051 $arr = array('code'=>'COUNT', 'displayName'=>'Count', 'codeSystem'=>'2.16.840.1.113883.5.84', 'codeSystemName'=>'ObservationMethod');
1052 $xml->self_customTag('methodCode', $arr);
1055 $xml->close_customTag();
1057 //entryRelationship Close
1058 $xml->close_customTag();
1061 $arr = array('typeCode'=>'REFR');
1062 $xml->open_customTag('reference', $arr);
1064 //externalObservation Start
1065 $arr = array('classCode'=>'OBS', 'moodCode'=>'EVN');
1066 $xml->open_customTag('externalObservation', $arr);
1068 //Modified HQMF_ID for CQM IDS
1069 //$refID = $preDefPopIdArr[$row['cqm_nqf_code']][$row['population_label']][$row['numerator_label']]['STRAT'];
1070 $refID = $preDefPopIdArr[$row['cqm_nqf_code']]['STRAT'.$strat_count];
1072 $xml->self_customId($refID);
1074 //externalObservation Close
1075 $xml->close_customTag();
1078 $xml->close_customTag();
1081 $xml->close_customTag();
1083 //entryRelationship Close
1084 $xml->close_customTag();
1088 #### Stratum END #####
1090 ####################################################
1091 ####################################################
1092 //Sex Supplemental Data Element START
1093 ####################################################
1094 ####################################################
1096 foreach ($mainQrdaGenderCodeArr as $GKey => $GVal) {
1097 //entryRelationship Open
1098 $xml->open_customTag('entryRelationship', array('typeCode'=>'COMP'));
1101 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
1103 $tempID = "2.16.840.1.113883.10.20.27.3.6";
1104 $xml->self_templateid($tempID);
1106 $tempID = "2.16.840.1.113883.10.20.27.3.21";
1107 $xml->self_templateid($tempID);
1109 $arr = array('code'=>'184100006', 'displayName'=>'patient sex', 'codeSystem'=>'2.16.840.1.113883.6.96', 'codeSystemName'=>'SNOMED-CT');
1110 $xml->self_codeCustom($arr);
1112 $arr = array('code'=>'completed');
1113 $xml->self_customTag('statusCode', $arr);
1115 $arr = array('xsi:type'=>'CD', 'code'=>$GKey, 'codeSystem' =>'2.16.840.1.113883.5.1', 'codeSystemName'=>'AdministrativeGenderCode');
1116 $xml->self_customTag('value', $arr);
1118 //entryRelationship Open
1119 $xml->open_customTag('entryRelationship', array('typeCode'=>'SUBJ', 'inversionInd'=>'true'));
1122 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
1124 $tempID = "2.16.840.1.113883.10.20.27.3.3";
1125 $xml->self_templateid($tempID);
1127 $tempID = "2.16.840.1.113883.10.20.27.3.24";
1128 $xml->self_templateid($tempID);
1130 $arr = array('code'=>'MSRAGG', 'displayName'=>'rate aggregation', 'codeSystem'=>'2.16.840.1.113883.5.4', 'codeSystemName'=>'ActCode');
1131 $xml->self_codeCustom($arr);
1133 //$arr = array('code'=>'completed');
1134 //$xml->self_customTag('statusCode', $arr);
1136 $arr = array('xsi:type'=>'INT', 'value'=>$detailsArr['gender'][$GVal]);
1137 $xml->self_customTag('value', $arr);
1139 $arr = array('code'=>'COUNT', 'displayName'=>'Count', 'codeSystem'=>'2.16.840.1.113883.5.84', 'codeSystemName'=>'ObservationMethod');
1140 $xml->self_customTag('methodCode', $arr);
1143 $xml->close_customTag();
1145 //entryRelationship Close
1146 $xml->close_customTag();
1150 $xml->close_customTag();
1152 //entryRelationship Close
1153 $xml->close_customTag();
1156 ####################################################
1157 ####################################################
1158 //Sex Supplemental Data Element END
1159 ####################################################
1160 ####################################################
1162 ####################################################
1163 ####################################################
1164 //Ethnicity Supplemental Data Element (CMS EP) START
1165 ####################################################
1166 ####################################################
1168 foreach ($mainEthiArr as $ethKey => $ethVal) {
1169 //entryRelationship Open
1170 $xml->open_customTag('entryRelationship', array('typeCode'=>'COMP'));
1173 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
1175 $tempID = "2.16.840.1.113883.10.20.27.3.7";
1176 $xml->self_templateid($tempID);
1178 $tempID = "2.16.840.1.113883.10.20.27.3.22";
1179 $xml->self_templateid($tempID);
1181 $arr = array('code'=>'364699009', 'displayName'=>'Ethnic Group', 'codeSystem'=>'2.16.840.1.113883.6.96', 'codeSystemName'=>'SNOMED-CT');
1182 $xml->self_codeCustom($arr);
1184 $arr = array('code'=>'completed');
1185 $xml->self_customTag('statusCode', $arr);
1187 $arr = array('xsi:type'=>'CD', 'code'=>$mainEthiCodeArr[$ethKey], 'displayName'=>$ethVal, 'codeSystem' =>'2.16.840.1.113883.6.238', 'codeSystemName'=>'Race & Ethnicity - CDC');
1188 $xml->self_customTag('value', $arr);
1190 //entryRelationship Open
1191 $xml->open_customTag('entryRelationship', array('typeCode'=>'SUBJ', 'inversionInd'=>'true'));
1194 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
1196 $tempID = "2.16.840.1.113883.10.20.27.3.3";
1197 $xml->self_templateid($tempID);
1199 $tempID = "2.16.840.1.113883.10.20.27.3.24";
1200 $xml->self_templateid($tempID);
1202 $arr = array('code'=>'MSRAGG', 'displayName'=>'rate aggregation', 'codeSystem'=>'2.16.840.1.113883.5.4', 'codeSystemName'=>'ActCode');
1203 $xml->self_codeCustom($arr);
1205 //$arr = array('code'=>'completed');
1206 //$xml->self_customTag('statusCode', $arr);
1208 $arr = array('xsi:type'=>'INT', 'value'=>$detailsArr['ethnicity'][$ethVal]);
1209 $xml->self_customTag('value', $arr);
1211 $arr = array('code'=>'COUNT', 'displayName'=>'Count', 'codeSystem'=>'2.16.840.1.113883.5.84', 'codeSystemName'=>'ObservationMethod');
1212 $xml->self_customTag('methodCode', $arr);
1215 $xml->close_customTag();
1217 //entryRelationship Close
1218 $xml->close_customTag();
1222 $xml->close_customTag();
1224 //entryRelationship Close
1225 $xml->close_customTag();
1228 ####################################################
1229 ####################################################
1230 //Ethnicity Supplemental Data Element (CMS EP) END
1231 ####################################################
1232 ####################################################
1235 ####################################################
1236 ####################################################
1237 //Race Supplemental Data Element (CMS EP) START
1238 ####################################################
1239 ####################################################
1241 foreach ($mainQrdaRaceArr as $RKey => $RVal) {
1242 //entryRelationship Open
1243 $xml->open_customTag('entryRelationship', array('typeCode'=>'COMP'));
1246 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
1248 $tempID = "2.16.840.1.113883.10.20.27.3.8";
1249 $xml->self_templateid($tempID);
1251 $tempID = "2.16.840.1.113883.10.20.27.3.19";
1252 $xml->self_templateid($tempID);
1254 $arr = array('code'=>'103579009', 'displayName'=>'Race', 'codeSystem'=>'2.16.840.1.113883.6.96', 'codeSystemName'=>'SNOMED-CT');
1255 $xml->self_codeCustom($arr);
1257 $arr = array('code'=>'completed');
1258 $xml->self_customTag('statusCode', $arr);
1260 $arr = array('xsi:type'=>'CD', 'code'=>$mainQrdaRaceCodeArr[$RKey], 'displayName'=>$RVal, 'codeSystem' =>'2.16.840.1.113883.6.238', 'codeSystemName'=>'Race & Ethnicity - CDC');
1261 $xml->self_customTag('value', $arr);
1263 //entryRelationship Open
1264 $xml->open_customTag('entryRelationship', array('typeCode'=>'SUBJ', 'inversionInd'=>'true'));
1267 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
1269 $tempID = "2.16.840.1.113883.10.20.27.3.3";
1270 $xml->self_templateid($tempID);
1272 $tempID = "2.16.840.1.113883.10.20.27.3.24";
1273 $xml->self_templateid($tempID);
1275 $arr = array('code'=>'MSRAGG', 'displayName'=>'rate aggregation', 'codeSystem'=>'2.16.840.1.113883.5.4', 'codeSystemName'=>'ActCode');
1276 $xml->self_codeCustom($arr);
1278 //$arr = array('code'=>'completed');
1279 //$xml->self_customTag('statusCode', $arr);
1281 $arr = array('xsi:type'=>'INT', 'value'=>$detailsArr['race'][$RVal]);
1282 $xml->self_customTag('value', $arr);
1284 $arr = array('code'=>'COUNT', 'displayName'=>'Count', 'codeSystem'=>'2.16.840.1.113883.5.84', 'codeSystemName'=>'ObservationMethod');
1285 $xml->self_customTag('methodCode', $arr);
1288 $xml->close_customTag();
1290 //entryRelationship Close
1291 $xml->close_customTag();
1295 $xml->close_customTag();
1297 //entryRelationship Close
1298 $xml->close_customTag();
1301 ####################################################
1302 ####################################################
1303 //Race Supplemental Data Element (CMS EP) END
1304 ####################################################
1305 ####################################################
1308 ####################################################
1309 ####################################################
1310 //Payer Supplemental Data Element (CMS EP) START
1311 ####################################################
1312 ####################################################
1313 $payerCheckArr = getQRDAPayerInfo($fullPatArr);
1314 foreach ($mainQrdaPayerCodeArr as $PKey => $PVal) {
1315 //entryRelationship Open
1316 $xml->open_customTag('entryRelationship', array('typeCode'=>'COMP'));
1319 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
1321 $tempID = "2.16.840.1.113883.10.20.27.3.9";
1322 $xml->self_templateid($tempID);
1324 $tempID = "2.16.840.1.113883.10.20.24.3.55";
1325 $xml->self_templateid($tempID);
1327 $tempID = "2.16.840.1.113883.10.20.27.3.18";
1328 $xml->self_templateid($tempID);
1330 $xml->self_setpatientRoleid();
1332 $arr = array('code'=>'48768-6', 'displayName'=>'Payment source', 'codeSystem'=>'2.16.840.1.113883.6.1', 'codeSystemName'=>'SNOMED-CT');
1333 $xml->self_codeCustom($arr);
1335 $arr = array('code'=>'completed');
1336 $xml->self_customTag('statusCode', $arr);
1338 $timeArr = array('low'=>date('Ymd', strtotime($from_date)));
1339 $xml->add_entryEffectTime($timeArr);
1343 $xml->open_customTag('value', array('xsi:type'=>'CD', 'nullFlavor'=>'OTH'));
1345 $xml->self_customTag('translation', array('code'=>$PKey, 'displayName'=>$PVal, 'codeSystem'=>'2.16.840.1.113883.3.249.12', 'codeSystemName'=>'CMS Clinical Codes'));
1348 $xml->close_customTag();
1352 $xml->self_customTag('value', array('xsi:type'=>'CD', 'code'=>$mainQrdaPayerCodeSendArr[$PKey], 'codeSystem'=>'2.16.840.1.113883.3.221.5' , 'codeSystemName'=>'SOP', 'displayName'=>$PVal));
1354 //entryRelationship Open
1355 $xml->open_customTag('entryRelationship', array('typeCode'=>'SUBJ', 'inversionInd'=>'true'));
1358 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
1360 $tempID = "2.16.840.1.113883.10.20.27.3.3";
1361 $xml->self_templateid($tempID);
1363 $tempID = "2.16.840.1.113883.10.20.27.3.24";
1364 $xml->self_templateid($tempID);
1366 $arr = array('code'=>'MSRAGG', 'displayName'=>'rate aggregation', 'codeSystem'=>'2.16.840.1.113883.5.4', 'codeSystemName'=>'ActCode');
1367 $xml->self_codeCustom($arr);
1369 //$arr = array('code'=>'completed');
1370 //$xml->self_customTag('statusCode', $arr);
1372 $arr = array('xsi:type'=>'INT', 'value'=>$payerCheckArr[$PVal]);
1373 $xml->self_customTag('value', $arr);
1375 $arr = array('code'=>'COUNT', 'displayName'=>'Count', 'codeSystem'=>'2.16.840.1.113883.5.84', 'codeSystemName'=>'ObservationMethod');
1376 $xml->self_customTag('methodCode', $arr);
1379 $xml->close_customTag();
1381 //entryRelationship Close
1382 $xml->close_customTag();
1386 $xml->close_customTag();
1388 //entryRelationship Close
1389 $xml->close_customTag();
1392 ####################################################
1393 ####################################################
1394 //Payer Supplemental Data Element (CMS EP) END
1395 ####################################################
1396 ####################################################
1398 ######################################################################
1400 $arr = array('typeCode'=>'REFR');
1401 $xml->open_customTag('reference', $arr);
1403 //externalObservation Start
1404 $arr = array('classCode'=>'OBS', 'moodCode'=>'EVN');
1405 $xml->open_customTag('externalObservation', $arr);
1407 //Modified HQMF_ID for CQM IDS
1408 if (($row['cqm_nqf_code'] == "0421" )) {
1409 $refID = $preDefPopIdArr[$row['cqm_nqf_code']][$row['numerator_label']][$mainQrdaPopulationIncArr[$cqmKey]];
1410 } else if (($row['cqm_nqf_code'] == "0024")) {
1411 $refID = $preDefPopIdArr[$row['cqm_nqf_code']][$row['population_label']][$row['numerator_label']][$mainQrdaPopulationIncArr[$cqmKey]];
1413 $refID = $preDefPopIdArr[$row['cqm_nqf_code']][$mainQrdaPopulationIncArr[$cqmKey]];
1420 $xml->self_customId($refID);
1422 //externalObservation Close
1423 $xml->close_customTag();
1426 $xml->close_customTag();
1427 ########################################################################
1430 $xml->close_customTag();
1432 $xml->close_loopComponent();
1433 ############### Initial patient population template END#####################
1436 //Multiple Numerator Handling
1437 if (in_array($row['cqm_nqf_code'], $multNumNQFArr)) {
1438 //Skipping Multiple Numerator(s)
1439 if (in_array($row['cqm_nqf_code'], $multNumNQFArr)) {
1440 $skipMultNumArr[$row['cqm_nqf_code']] = true;
1443 if ($dataChkArr[$row['cqm_nqf_code']] == $countNumNQFArr[$row['cqm_nqf_code']]) {
1445 $xml->close_customTag();
1446 $xml->close_entry();
1450 $xml->close_customTag();
1451 $xml->close_entry();
1454 ###########################################################
1460 #######################################################################
1461 ######################### QUALITY MEASURES END ########################
1462 #######################################################################
1465 $xml->close_section();
1467 $xml->close_loopComponent();
1469 ##################### LOOP Component(s) END ########################
1471 $xml->close_structuredBody();
1472 ############### Structure Body Close #######################
1474 $xml->close_mainComponent();
1475 ############### Main Component Close #######################
1477 //Close Main Clinical Document
1478 $xml->close_clinicaldocument();
1481 //QRDA File Download Folder in site/cqm_qrda folder
1482 $qrda_fname = "QRDA_III_".date("YmdHis").".xml";
1483 $qrda_file_path = $GLOBALS['OE_SITE_DIR'] . "/documents/cqm_qrda/";
1484 if (!file_exists($qrda_file_path)) {
1485 mkdir($qrda_file_path, 0777, true);
1488 $qrda_file_name = $qrda_file_path.$qrda_fname;
1489 $fileQRDAOPen = fopen($qrda_file_name, "w");
1490 fwrite($fileQRDAOPen, trim($xml->getXml()));
1491 fclose($fileQRDAOPen);
1496 <?php
html_header_show();?
>
1497 <script type
="text/javascript" src
="<?php echo $webroot ?>/interface/main/tabs/js/include_opener.js"></script
>
1498 <link rel
=stylesheet href
="<?php echo $css_header;?>" type
="text/css">
1499 <title
><?php
echo xlt('Export QRDA Report'); ?
></title
>
1501 <script type
="text/javascript">
1503 function closeme() {
1510 <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
>
1515 <a href
="qrda_download.php?qrda_fname=<?php echo attr($qrda_fname);?>"><?php
echo xlt("Download QRDA Category III File");?
></a
>
1517 <textarea rows
='50' cols
='500' style
='width:95%' readonly
>
1518 <?php
echo trim($xml->getXml()); ?
>
1521 <p
><input type
='button' value
='<?php echo xla('Close
'); ?>' onclick
='closeme();' /></p
>