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 if (!verifyCsrfToken($_GET["csrf_token_form"])) {
40 $facilityService = new FacilityService();
42 //Remove time limit, since script can take many minutes
45 //DENEXCEP NOT NEEDED rules
46 $denExcepNotNeedRules = array('0002', '0018', '0024', '0038', '0043', '0059', '0421');
48 //Predefined QRDA HQMF ID's for CQM rules
49 $preDefinedUniqIDRules = array();
50 $preDefPopIdArr = array();
52 // CMS147v4/0041 - Preventive Care and Screening: Influenza Immunization HQMF ID: 40280381-4600-425F-0146-EE66F0005509
53 $preDefinedUniqIDRules['0041'] = '40280381-4600-425F-0146-EE66F0005509';
54 $preDefPopIdArr['0041']['IPP'] = 'F48702E6-D39A-49D8-BE3C-8FAB5C6AADDA';
55 $preDefPopIdArr['0041']['DENOM'] = 'B61EC2DC-0841-4906-A84B-5BE5024DA7F1';
56 $preDefPopIdArr['0041']['NUMER'] = '0ED7B212-369B-489A-A5B5-07BC146FA557';
57 $preDefPopIdArr['0041']['DENEXCEP'] = 'B5C9EC50-3011-43DC-AD07-CED2D3B770B2';
59 // CMS122v3/0059 - Diabetes: Hemoglobin A1c Poor Control: HQMF_ID: 40280381-4555-E1C1-0145-90AC70DE2C73
60 $preDefinedUniqIDRules['0059'] = '40280381-4555-E1C1-0145-90AC70DE2C73';
61 $preDefPopIdArr['0059']['IPP'] = 'EDED90E9-E4FE-47E6-90AC-29D9AA3E861A';
62 $preDefPopIdArr['0059']['DENOM'] = '6721D6DA-E87D-4E42-A34A-C8490686598C';
63 $preDefPopIdArr['0059']['NUMER'] = '7549BA9E-1841-4231-8CAA-095BDF0AB8A1';
66 //CMS139v3/0101 - Falls: Screening for Future Fall Risk: HQMF_ID: 40280381-4555-E1C1-0145-672613970D15
67 $preDefinedUniqIDRules['0101'] = '40280381-4555-E1C1-0145-672613970D15';
68 $preDefPopIdArr['0101']['IPP'] = '2448B0C6-6848-4DCB-AA6D-F199337A2C5C';
69 $preDefPopIdArr['0101']['DENOM'] = 'EC400908-35BE-439B-92A9-231D99CEA9DF';
70 $preDefPopIdArr['0101']['NUMER'] = '663FB12B-0FF4-49AB-80A3-624C5E7DF892';
71 $preDefPopIdArr['0101']['DENEXCEP'] = 'FEC7251A-BF8D-4472-97D8-E2A9C0A42176';
73 //CMS127v3/0043 - Pneumonia Vaccination Status for Older Adults: HQMF_ID: 40280381-4555-E1C1-0145-762578A81C4C
74 $preDefinedUniqIDRules['0043'] = '40280381-4555-E1C1-0145-762578A81C4C';
75 $preDefPopIdArr['0043']['IPP'] = '873AECC7-E15B-49E7-8391-D73A46201E2E';
76 $preDefPopIdArr['0043']['DENOM'] = 'FF7016E1-E8C7-43BA-9D56-2BEF649F36FA';
77 $preDefPopIdArr['0043']['NUMER'] = '201F5A6E-4DDE-43A2-BDFC-CE85A98560DA';
79 //CMS69v3/0421 - Preventive Care and Screening: Body Mass Index (BMI) Screening and Follow-Up Plan: HQMF_ID: 40280381-4555-E1C1-0145-D2B36DBB3FE6
80 $preDefinedUniqIDRules['0421']['Numerator 1'] = '40280381-4555-E1C1-0145-D2B36DBB3FE6';
81 $preDefPopIdArr['0421']['Numerator 1']['IPP'] = '1C936855-E644-44C0-B264-49A28756FDB1';
82 $preDefPopIdArr['0421']['Numerator 1']['DENOM'] = '27F1591C-2060-462C-B5D7-7FE86A44B534';
83 $preDefPopIdArr['0421']['Numerator 1']['DENEX'] = '9B0C3C26-D621-4EA3-81FB-A839A3012044';
84 $preDefPopIdArr['0421']['Numerator 1']['NUMER'] = '3095531C-24D7-4AFB-9BCB-F1901FF0FF69';
86 $preDefinedUniqIDRules['0421']['Numerator 2'] = '40280381-4555-E1C1-0145-D2B36DBB3FE6';
87 $preDefPopIdArr['0421']['Numerator 2']['IPP'] = '6E701B1C-6CA5-4AD5-98C9-5F766745EA89';
88 $preDefPopIdArr['0421']['Numerator 2']['DENOM'] = 'E4DC29B8-EB26-4A01-ABB0-4F99FC03BA39';
89 $preDefPopIdArr['0421']['Numerator 2']['DENEX'] = 'BB1B4301-C275-4BAC-87C9-6E960B1601DA';
90 $preDefPopIdArr['0421']['Numerator 2']['NUMER'] = '7669026D-3683-44CC-A2C5-3D62EB2F8A33';
92 //CMS117v3/0038 - Childhood Immunization Status: HQMF_ID: 40280381-4555-E1C1-0145-D7C003364261
93 $preDefinedUniqIDRules['0038'] = '40280381-4555-E1C1-0145-D7C003364261';
94 $preDefPopIdArr['0038']['IPP'] = '6ED6A787-C871-49B9-825C-70A0DB898977';
95 $preDefPopIdArr['0038']['DENOM'] = '545DA813-89ED-4DCD-BDDF-4B33D93DCD84';
96 $preDefPopIdArr['0038']['NUMER'] = '00193FC7-AEE4-4507-A20F-D25A7BB214AD';
98 //CMS138v3/0028 - Preventive Care and Screening: Tobacco Use: Screening and Cessation Intervention: HQMF_ID: 40280381-4600-425F-0146-1F5867D40E82
99 $preDefinedUniqIDRules['0028'] = '40280381-4600-425F-0146-1F5867D40E82';
100 $preDefPopIdArr['0028']['IPP'] = '4E118B62-2AF8-4F51-9355-6FD3F2427D9F';
101 $preDefPopIdArr['0028']['DENOM'] = 'FA1B3953-AE58-4541-BF7B-84D0EB1B0713';
102 $preDefPopIdArr['0028']['NUMER'] = '35B1A6DF-1871-4633-A74B-BCAE371BC030';
103 $preDefPopIdArr['0028']['DENEXCEP'] = '3EE6DFF5-AB17-482F-A147-E6D1E46DBB79';
105 //CMS157v3/0384 - Oncology: Medical and Radiation – Pain Intensity Quantified: HQMF_ID: 40280381-4600-425F-0146-1F620BDF0EB0
106 $preDefinedUniqIDRules['0384'] = '40280381-4600-425F-0146-1F620BDF0EB0';
107 $preDefPopIdArr['0384']['IPP'] = 'C29B6555-3BC7-416F-B61A-FCACD637594F';
108 $preDefPopIdArr['0384']['DENOM'] = 'E5F80C25-6816-4992-92E2-A735B17F8D4F';
109 $preDefPopIdArr['0384']['NUMER'] = 'C948D0D2-D6E9-4099-9CD4-870F2F83A14C';
111 //CMS146v3/0002 - Appropriate Testing for Children with Pharyngitis: HQMF_ID: 40280381-4600-425F-0146-1F6E280C0F09
112 $preDefinedUniqIDRules['0002'] = '40280381-4600-425F-0146-1F6E280C0F09';
113 $preDefPopIdArr['0002']['IPP'] = '9D1135EA-BA90-45E7-8EED-F7335D1CC934';
114 $preDefPopIdArr['0002']['DENOM'] = 'D04EFECB-A901-4565-BDDB-826510499092';
115 $preDefPopIdArr['0002']['NUMER'] = '3F4CDE57-1C5C-4250-A338-55FED6775F57';
116 $preDefPopIdArr['0002']['DENEX'] = '0525FBA2-F068-4706-ADB5-E345852DC55B';
118 //CMS165v3/0018 - Controlling High Blood Pressure: HQMF_ID: 40280381-4600-425F-0146-1F6F722B0F17
119 $preDefinedUniqIDRules['0018'] = '40280381-4600-425F-0146-1F6F722B0F17';
120 $preDefPopIdArr['0018']['IPP'] = 'A72855CE-3C60-41F9-AEE2-64D4F584DDD4';
121 $preDefPopIdArr['0018']['DENOM'] = '26046A5C-E2CC-4A27-B480-FF7E3575691F';
122 $preDefPopIdArr['0018']['NUMER'] = '0899A359-0CD8-4977-AA29-666892AA3AD4';
123 $preDefPopIdArr['0018']['DENEX'] = '4327D845-6194-410D-A48D-D6E1802CAD55';
125 //CMS155v3/0024 - Weight Assessment and Counseling for Nutrition and Physical Activity for Children and Adolescents: HQMF_ID: 40280381-4555-E1C1-0145-85C7311720F5
126 $preDefinedUniqIDRules['0024']['Population Criteria 1']['Numerator 1'] = '40280381-4555-E1C1-0145-85C7311720F5';
127 $preDefPopIdArr['0024']['Population Criteria 1']['Numerator 1']['IPP'] = '10127790-AE94-4070-9DD3-1D3776D08D7C';
128 $preDefPopIdArr['0024']['Population Criteria 1']['Numerator 1']['DENOM'] = '3B3C1568-F875-49B1-9090-E2F494EECBB6';
129 $preDefPopIdArr['0024']['Population Criteria 1']['Numerator 1']['DENEX'] = 'B288D5A4-D573-4FAA-92D6-0B01E1B35C7A';
130 $preDefPopIdArr['0024']['Population Criteria 1']['Numerator 1']['NUMER'] = 'FD4649BD-B962-4CBE-BF4A-C2F95F3EA08E';
132 $preDefinedUniqIDRules['0024']['Population Criteria 1']['Numerator 2'] = '40280381-4555-E1C1-0145-85C7311720F5';
133 $preDefPopIdArr['0024']['Population Criteria 1']['Numerator 2']['IPP'] = '10127790-AE94-4070-9DD3-1D3776D08D7C';
134 $preDefPopIdArr['0024']['Population Criteria 1']['Numerator 2']['DENOM'] = '3B3C1568-F875-49B1-9090-E2F494EECBB6';
135 $preDefPopIdArr['0024']['Population Criteria 1']['Numerator 2']['DENEX'] = 'B288D5A4-D573-4FAA-92D6-0B01E1B35C7A';
136 $preDefPopIdArr['0024']['Population Criteria 1']['Numerator 2']['NUMER'] = '52FBD726-4DD1-48F5-98B9-7175754923E1';
138 $preDefinedUniqIDRules['0024']['Population Criteria 1']['Numerator 3'] = '40280381-4555-E1C1-0145-85C7311720F5';
139 $preDefPopIdArr['0024']['Population Criteria 1']['Numerator 3']['IPP'] = '10127790-AE94-4070-9DD3-1D3776D08D7C';
140 $preDefPopIdArr['0024']['Population Criteria 1']['Numerator 3']['DENOM'] = '3B3C1568-F875-49B1-9090-E2F494EECBB6';
141 $preDefPopIdArr['0024']['Population Criteria 1']['Numerator 3']['DENEX'] = 'B288D5A4-D573-4FAA-92D6-0B01E1B35C7A';
142 $preDefPopIdArr['0024']['Population Criteria 1']['Numerator 3']['NUMER'] = 'C43CE779-C5EE-4C15-A4CC-AF1C446CFB09';
144 $preDefinedUniqIDRules['0024']['Population Criteria 2']['Numerator 1'] = '40280381-4555-E1C1-0145-85C7311720F5';
145 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 1']['IPP'] = '10127790-AE94-4070-9DD3-1D3776D08D7C';
146 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 1']['DENOM'] = '3B3C1568-F875-49B1-9090-E2F494EECBB6';
147 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 1']['DENEX'] = 'B288D5A4-D573-4FAA-92D6-0B01E1B35C7A';
148 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 1']['NUMER'] = 'FD4649BD-B962-4CBE-BF4A-C2F95F3EA08E';
149 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 1']['STRAT'] = '40280381-3D61-56A7-013E-5D53298E6DA3';
150 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 1']['DISPLAY_TEXT'] = 'BMI Recorded, RS1: 3-11';
152 $preDefinedUniqIDRules['0024']['Population Criteria 2']['Numerator 2'] = '40280381-4555-E1C1-0145-85C7311720F5';
153 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 2']['IPP'] = '10127790-AE94-4070-9DD3-1D3776D08D7C';
154 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 2']['DENOM'] = '3B3C1568-F875-49B1-9090-E2F494EECBB6';
155 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 2']['DENEX'] = 'B288D5A4-D573-4FAA-92D6-0B01E1B35C7A';
156 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 2']['NUMER'] = '52FBD726-4DD1-48F5-98B9-7175754923E1';
157 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 2']['STRAT'] = '40280381-3D61-56A7-013E-5D53298E6DA3';
158 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 2']['DISPLAY_TEXT'] = 'BMI Recorded, RS2: 12-17';
160 $preDefinedUniqIDRules['0024']['Population Criteria 2']['Numerator 3'] = '40280381-4555-E1C1-0145-85C7311720F5';
161 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 3']['IPP'] = '10127790-AE94-4070-9DD3-1D3776D08D7C';
162 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 3']['DENOM'] = '3B3C1568-F875-49B1-9090-E2F494EECBB6';
163 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 3']['DENEX'] = 'B288D5A4-D573-4FAA-92D6-0B01E1B35C7A';
164 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 3']['NUMER'] = 'C43CE779-C5EE-4C15-A4CC-AF1C446CFB09';
165 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 3']['STRAT'] = '40280381-3D61-56A7-013E-5D53298E6DA3';
166 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 3']['DISPLAY_TEXT'] = 'Nutrition Counseling, RS1: 3-11';
168 $preDefinedUniqIDRules['0024']['Population Criteria 3']['Numerator 1'] = '40280381-4555-E1C1-0145-85C7311720F5';
169 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 1']['IPP'] = '10127790-AE94-4070-9DD3-1D3776D08D7C';
170 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 1']['DENOM'] = '3B3C1568-F875-49B1-9090-E2F494EECBB6';
171 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 1']['DENEX'] = 'B288D5A4-D573-4FAA-92D6-0B01E1B35C7A';
172 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 1']['NUMER'] = 'FD4649BD-B962-4CBE-BF4A-C2F95F3EA08E';
173 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 1']['STRAT'] = '40280381-3D61-56A7-013E-5D532AF06DA5';
174 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 1']['DISPLAY_TEXT'] = 'Nutrition Counseling, RS2: 12-17';
176 $preDefinedUniqIDRules['0024']['Population Criteria 3']['Numerator 2'] = '40280381-4555-E1C1-0145-85C7311720F5';
177 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 2']['IPP'] = '10127790-AE94-4070-9DD3-1D3776D08D7C';
178 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 2']['DENOM'] = '3B3C1568-F875-49B1-9090-E2F494EECBB6';
179 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 2']['DENEX'] = 'B288D5A4-D573-4FAA-92D6-0B01E1B35C7A';
180 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 2']['NUMER'] = '52FBD726-4DD1-48F5-98B9-7175754923E1';
181 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 2']['STRAT'] = '40280381-3D61-56A7-013E-5D532AF06DA5';
182 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 2']['DISPLAY_TEXT'] = 'Physical Activity Counseling, RS1: 3-11';
184 $preDefinedUniqIDRules['0024']['Population Criteria 3']['Numerator 3'] = '40280381-4555-E1C1-0145-85C7311720F5';
185 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 3']['IPP'] = '10127790-AE94-4070-9DD3-1D3776D08D7C';
186 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 3']['DENOM'] = '3B3C1568-F875-49B1-9090-E2F494EECBB6';
187 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 3']['DENEX'] = 'B288D5A4-D573-4FAA-92D6-0B01E1B35C7A';
188 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 3']['NUMER'] = 'C43CE779-C5EE-4C15-A4CC-AF1C446CFB09';
189 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 3']['STRAT'] = '40280381-3D61-56A7-013E-5D532AF06DA5';
190 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 3']['DISPLAY_TEXT'] = 'Physical Activity Counseling, RS2: 12-17';
192 $preDefPopIdArr['0024']['STRAT1'] = '40280381-3D61-56A7-013E-5D53298E6DA3';
193 $preDefPopIdArr['0024']['STRAT2'] = '40280381-3D61-56A7-013E-5D532AF06DA5';
195 //Multiple Numerator NQF# Array declaration
196 $multNumNQFArr = array('0421', '0024');
197 $countNumNQFArr = array();
198 $countNumNQFArr['0421'] = 2;//two Numerators
199 $countNumNQFArr['0024'] = 9;//Nine Numerators
201 //Initiation of all QRDA needed elements
202 $CQMeausesArr = array();
203 $CQMeausesArr['init_patients'] = "Initial Patient Population";
204 $CQMeausesArr['exclude_patients'] = "Denominator Exclusions";
205 $CQMeausesArr['denom_patients'] = "Denominator";
206 $CQMeausesArr['numer_patients'] = "Numerator";
207 $CQMeausesArr['exception_patients'] = "Denominator Exceptions";
209 $cqmItemizedArr = array();
210 $cqmItemizedArr['init_patients'] = "init_patients";
211 $cqmItemizedArr['exclude_patients'] = "exclude";
212 $cqmItemizedArr['denom_patients'] = "all";
213 $cqmItemizedArr['numer_patients'] = "pass";
214 $cqmItemizedArr['exception_patients'] = "exception";
216 //QRDA Needed Ethnicity
217 $mainEthiArr = array(0=>'Not Hispanic or Latino', 1=>'Hispanic or Latino');
218 $mainEthiCodeArr = array(0=>'2186-5', 1=>'2135-2');
221 $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');
222 $mainQrdaRaceCodeArr = array(0=>'1002-5', 1=>'2028-9', 2=>'2054-5', 3=>'2076-8', 4=>'2106-3', 5=>'2131-1');
224 $mainQrdaPopulationIncArr = array();
225 $mainQrdaPopulationIncArr['init_patients'] = "IPP";
226 $mainQrdaPopulationIncArr['exclude_patients'] = "DENEX";
227 $mainQrdaPopulationIncArr['denom_patients'] = "DENOM";
228 $mainQrdaPopulationIncArr['numer_patients'] = "NUMER";
229 $mainQrdaPopulationIncArr['exception_patients'] = "DENEXCEP";
230 $mainQrdaPopulationIncArr['measure_population'] = "MSRPOPL";
231 $mainQrdaPopulationIncArr['numer_exclusion'] = "NUMEX";
234 $mainQrdaGenderCodeArr = array();
235 $mainQrdaGenderCodeArr['F'] = "Female";
236 $mainQrdaGenderCodeArr['M'] = "Male";
237 $mainQrdaGenderCodeArr['UN'] = "Unknown";
239 //QRDA Needed Payer Info
240 $mainQrdaPayerCodeArr = array();
241 $mainQrdaPayerCodeArr['A'] = "Medicare";
242 $mainQrdaPayerCodeArr['B'] = "Medicaid";
243 $mainQrdaPayerCodeArr['C'] = "Private Health Insurance";
244 $mainQrdaPayerCodeArr['D'] = "Other";
246 //Payer Codes According to Cypress Codes
247 $mainQrdaPayerCodeSendArr = array();
248 $mainQrdaPayerCodeSendArr['A'] = "1";
249 $mainQrdaPayerCodeSendArr['B'] = "2";
250 $mainQrdaPayerCodeSendArr['C'] = "5";
251 $mainQrdaPayerCodeSendArr['D'] = "349";
254 $form_provider = $_GET['form_provider'];
256 //Get Report Information
257 $report_id = $_GET['report_id'];
258 $report_view = collectReportDatabase($report_id);
259 $target_date = $report_view['date_target'];
260 $dataSheet = json_decode($report_view['data'], true);
262 //Needed array for Rule NQF#0024 Stratification
263 $stratumCheckArr = array();
264 if (count($dataSheet) > 0) {
266 foreach ($dataSheet as $row) {
267 $itemized_test_id = $row['itemized_test_id'];
268 $numerator_label = $row['numerator_label'];
269 if ($row['cqm_nqf_code'] == "0024") {
270 if ($row['population_label'] == "Population Criteria 2") {
271 if ($row['numerator_label'] == "Numerator 1") {
272 $stratum_1_ipp = $row['initial_population'];
273 $stratum_1_exclude = $row['excluded'];
274 $stratum_1_denom = $row['pass_filter'];
275 $stratum_1_numer1 = $row['pass_target'];
276 } else if ($row['numerator_label'] == "Numerator 2") {
277 $stratum_1_numer2 = $row['pass_target'];
278 } else if ($row['numerator_label'] == "Numerator 3") {
279 $stratum_1_numer3 = $row['pass_target'];
281 } else if ($row['population_label'] == "Population Criteria 3") {
282 if ($row['numerator_label'] == "Numerator 1") {
283 $stratum_2_ipp = $row['initial_population'];
284 $stratum_2_exclude = $row['excluded'];
285 $stratum_2_denom = $row['pass_filter'];
286 $stratum_2_numer1 = $row['pass_target'];
287 } else if ($row['numerator_label'] == "Numerator 2") {
288 $stratum_2_numer2 = $row['pass_target'];
289 } else if ($row['numerator_label'] == "Numerator 3") {
290 $stratum_2_numer3 = $row['pass_target'];
296 $stratum[1] = array('init_patients' => $stratum_1_ipp,
297 'exclude_patients' => $stratum_1_exclude,
298 'denom_patients' => $stratum_1_denom,
299 'numer_patients' => $stratum_1_numer1,
300 'numer2' => $stratum_1_numer2,
301 'numer3' => $stratum_1_numer3);
303 $stratum[2] = array('init_patients' => $stratum_2_ipp,
304 'exclude_patients' => $stratum_2_exclude,
305 'denom_patients' => $stratum_2_denom,
306 'numer_patients' => $stratum_2_numer1,
307 'numer2' => $stratum_2_numer2,
308 'numer3' => $stratum_2_numer3);
312 $from_date = date('Y', strtotime($target_date))."-01-01";
313 $to_date = date('Y', strtotime($target_date))."-12-31";
314 $xml = new QRDAXml();
316 #################################################################################################
317 ####################### HEADER ELEMENTS START #####################################################
318 #################################################################################################
319 //Open Main Clinical Document
320 $xml->open_clinicaldocument();
322 $xml->self_realmcode();
326 $tempId = '2.16.840.1.113883.10.20.27.1.1';
327 $xml->self_templateid($tempId);
329 $xml->unique_id
= getUuid();
333 //Main Title Display to XML
334 $main_title = "QRDA Calculated Summary Report";
335 $xml->add_title($main_title);
337 //Effective date and time
338 $eff_datetime = date('Ymdhis', strtotime($target_date));
339 $xml->self_efftime($eff_datetime);
341 $xml->self_confidentcode();
346 $setidVal =getUuid();
347 $xml->self_setid($setidVal);
350 $xml->self_version();
352 //Record Target Elements
353 $xml->open_recordTarget();
354 $xml->add_patientRole();
355 $xml->close_recordTarget();
357 ############### Author Info #######################
360 $auth_dtime = date('Ymdhis', strtotime(date('Y-m-d H:i:s')));
361 $xml->self_authorTime($auth_dtime);
363 $xml->open_assignAuthor();
364 $authorsetid = getUuid();
365 $xml->self_customId($authorsetid);
366 if ($form_provider != "") {
367 $userRow = sqlQuery("SELECT facility, facility_id, federaltaxid, npi, phone,fname, lname FROM users WHERE id=?", array($form_provider));
368 $facility_name = $userRow['facility'];
369 $facility_id = $userRow['facility_id'];
372 //$xml->self_customTag('telecom', array('value' => $userRow['phone'], 'use'=>'WP'));
374 //assignedAuthoringDevice Start
375 $xml->open_customTag('assignedAuthoringDevice');
377 $xml->element('softwareName', 'CYPRESS');
379 //assignedAuthoringDevice Close
380 $xml->close_customTag();
383 $facilResRow = $facilityService->getById($facility_id);
384 $xml->add_authReprestOrginisation($facilResRow);
385 //$xml->add_facilAddress($facilResRow);
386 $xml->close_assignAuthor();
387 $xml->close_author();
389 ############### Custodian Info #######################
390 $xml->open_custodian();
391 $xml->open_assgnCustodian();
392 $xml->add_represtCustodianOrginisation($facilResRow);
393 $xml->close_assgnCustodian();
394 $xml->close_custodian();
397 ############### Information Recipient #######################
398 $xml->open_infoRecipient();
399 $xml->add_indententRecipient();
400 $xml->close_infoRecipient();
403 ############### Legal Authenticator #######################
404 $xml->open_legalAuthenticator();
405 $auth_dtime = date('Ymdhis', strtotime(date('Y-m-d H:i:s')));
406 $xml->self_authorTime($auth_dtime);
407 $xml->self_legalSignCode();
409 $xml->open_assignedEntity();
410 $assignedEntityId = getUuid();
411 $xml->self_customId($assignedEntityId);
413 $xml->open_customTag('assignedPerson');
416 $userNameArr = array('fname' =>$userRow['fname'], 'lname'=>$userRow['lname']);
417 $xml->add_providerName($userNameArr);
419 //assignedPerson Close
420 $xml->close_customTag();
422 //Represent Origination Name
423 $xml->add_authReprestOrginisation($facilResRow);
424 $xml->close_assignedEntity();
426 $xml->close_legalAuthenticator();
429 ############### Participant is Device(optional) #######################
430 $participentDevArr = array();
431 $xml->open_participant_data('DEV');//DEV -- Device
432 $xml->open_assocEntityData('RGPR');//RGPR -- Regulated Product
433 $participentDevArr['root'] = '2.16.840.1.113883.3.2074.1';
434 $participentDevArr['extension'] = '1a2b3c';
435 $xml->self_particpantIdInfo($participentDevArr);
436 $xml->self_participantCodeDevice();
437 $xml->close_assocEntityData();
438 $xml->close_participant_data();
440 ############### Participant is Location(optional) #######################
441 $participentLocArr = array();
442 $xml->open_participant_data('LOC');//LOC -- Location
443 $xml->open_assocEntityData('SDLOC');//SDLOC -- Service Delivery Location
444 $participentLocArr['root'] = '2.16.840.1.113883.3.249.5.1';
445 $participentLocArr['extension'] = 'OK666333';
446 $xml->self_particpantIdInfo($participentLocArr);
447 $xml->self_participantCodeLocation();
449 $xml->add_facilAddress($facilResRow);
450 $xml->close_assocEntityData();
451 $xml->close_participant_data();
454 ############### documentationOf START #######################
455 $xml->open_customTag('documentationOf');
457 $xml->open_customTag('serviceEvent', array('classCode'=>'PCPR'));
459 $timeArr = array('low'=>date('Ymd', strtotime($from_date)), 'high'=>date('Ymd', strtotime($to_date)));
460 $xml->add_entryEffectTime($timeArr);
462 $xml->open_customTag('performer', array('typeCode'=>'PRF'));
464 $xml->open_customTag('assignedEntity');
466 $npi_provider = !empty($userRow['npi']) ?
$userRow['npi'] : '123456789';
467 $xml->self_customTag('id', array('root' => '2.16.840.1.113883.4.6', 'extension' =>$npi_provider));
469 if ($userRow['phone'] != "") {
470 $xml->self_customTag('telecom', array('value' => $userRow['phone'], 'use'=>'WP'));
473 $xml->open_customTag('assignedPerson');
476 $userNameArr = array('fname' =>$userRow['fname'], 'lname'=>$userRow['lname']);
477 $xml->add_providerName($userNameArr);
479 //assignedPerson Close
480 $xml->close_customTag();
482 $xml->open_customTag('representedOrganization');
484 $tin_provider = $userRow['federaltaxid'];
485 if ($tin_provider != "") {
486 $xml->self_customTag('id', array('root' => '2.16.840.1.113883.4.2', 'extension' =>$tin_provider));
489 $xml->add_facilName($facility_name);
491 $xml->add_facilAddress($facilResRow);
493 //representedOrganization Close
494 $xml->close_customTag();
496 //assignedEntity Close
497 $xml->close_customTag();
500 $xml->close_customTag();
503 $xml->close_customTag();
505 //documentationOf Close
506 $xml->close_customTag();
507 ############### documentationOf END #######################
510 ############### authorization (optional) #########################
512 #################################################################################################
513 ####################### HEADER ELEMENTS END #####################################################
514 #################################################################################################
518 #################################################################################################
519 ######################### Main Component Open ###################################################
520 $xml->open_mainComponent();
522 ############### Structure Body Open #######################
523 $xml->open_structuredBody();
525 ##################### LOOP Component(s) START ########################
527 ###################### Report Parameters Open #####################
528 //QRDA Category III Reporting Parameters Section (CMS EP) [section: templateId 2.16.840.1.113883.10.20.27.2.6
529 $xml->open_loopComponent();
531 $xml->open_section();
533 $tempID = '2.16.840.1.113883.10.20.17.2.1';
534 $xml->self_templateid($tempID);
536 $tempID = '2.16.840.1.113883.10.20.27.2.2';
537 $xml->self_templateid($tempID);
539 $tempID = '2.16.840.1.113883.10.20.27.2.6';
540 $xml->self_templateid($tempID);
541 $arr = array('code'=>'55187-9', 'codeSystem'=>'2.16.840.1.113883.6.1');
542 $xml->self_codeCustom($arr);
543 $title = "Reporting Parameters";
544 $xml->add_title($title);
548 $item_title = "Reporting period: ".date('d M Y', strtotime($from_date))." - ".date('d M Y', strtotime($to_date));
549 $xml->add_item($item_title);
554 $xml->open_entry($typeCode);
555 $arr = array('classCode'=>'ACT', 'moodCode'=>'EVN');
556 $xml->open_act($arr);
558 $tempID = '2.16.840.1.113883.10.20.17.3.8';
559 $xml->self_templateid($tempID);
561 $tempID = '2.16.840.1.113883.10.20.27.3.23';
562 $xml->self_templateid($tempID);
565 $xml->self_customId($actId);
567 $arr = array('code'=>'252116004', 'codeSystem'=>'2.16.840.1.113883.6.96', 'displayName'=>'Observation Parameters');
568 $xml->self_codeCustom($arr);
570 $timeArr = array('low'=>date('Ymd', strtotime($from_date)), 'high'=>date('Ymd', strtotime($to_date)));
571 $xml->add_entryEffectTime($timeArr);
576 $xml->close_section();
578 $xml->close_loopComponent();
579 ###################### Report Parameters Close #####################
581 ###################### Measure Section Open #####################
582 $xml->open_loopComponent();
584 $xml->open_section();
586 $tempID = '2.16.840.1.113883.10.20.27.2.1';
587 $xml->self_templateid($tempID);
589 $tempID = '2.16.840.1.113883.10.20.24.2.2';
590 $xml->self_templateid($tempID);
592 $tempID = '2.16.840.1.113883.10.20.27.2.3';
593 $xml->self_templateid($tempID);
595 $arr = array('code'=>'55186-1', 'codeSystem'=>'2.16.840.1.113883.6.1');
596 $xml->self_codeCustom($arr);
597 $title = "Measure Section";
598 $xml->add_title($title);
603 $tabArr = array('border'=>1, 'width'=>'100%');
604 if (count($dataSheet) > 0) {
605 $uniqIdArr = array();
608 foreach ($dataSheet as $row) {
609 $itemized_test_id = $row['itemized_test_id'];
610 $numerator_label = $row['numerator_label'];
612 //CQM Rules 2014 set, 0013 is 0018
613 if ($row['cqm_nqf_code'] == "0013") {
614 $row['cqm_nqf_code'] = "0018";
618 $xml->open_customTag('table', $tabArr);
620 $xml->open_customTag('thead');
622 $xml->open_customTag('tr');
624 $xml->add_trElementsTitles();
627 $xml->close_customTag();
630 $xml->close_customTag();
632 $xml->open_customTag('tbody');
633 $xml->open_customTag('tr');
635 $tdTitle = generate_display_field(array('data_type'=>'1','list_id'=>'clinical_rules'), $row['id']);
637 if (!empty($row['cqm_pqri_code'])) {
638 $tdTitle .= " " . xlt('PQRI') . ":" . text($row['cqm_pqri_code']) . " ";
641 if (!empty($row['cqm_nqf_code'])) {
642 $tdTitle .= " " . xlt('NQF') . ":" . text($row['cqm_nqf_code']) . " ";
645 if (!(empty($row['concatenated_label']))) {
646 $tdTitle .= ", " . xlt($row['concatenated_label']) . " ";
649 $tdVersionNeutral = getUuid();
651 if ($preDefinedUniqIDRules[$row['cqm_nqf_code']] != "") {
652 if (($row['cqm_nqf_code'] == "0421" )) {
653 $tdVersionSpecific = $preDefinedUniqIDRules[$row['cqm_nqf_code']][$row['numerator_label']];
654 } else if ($row['cqm_nqf_code'] == "0024") {
655 $tdVersionSpecific = $preDefinedUniqIDRules[$row['cqm_nqf_code']][$row['population_label']][$row['numerator_label']];
657 $tdVersionSpecific = $preDefinedUniqIDRules[$row['cqm_nqf_code']];
660 $uniqIdArr[] = $tdVersionSpecific;
662 $tdVersionSpecific = getUuid();
663 $uniqIdArr[] = $tdVersionSpecific;
666 $dataArr = array(0=>$tdTitle, 1=>$tdVersionNeutral, 2=>$tdVersionSpecific);
667 $xml->add_trElementsValues($dataArr);
670 $xml->close_customTag();
672 $xml->close_customTag();
674 $xml->close_customTag();
676 //Open List Item Wise
680 $xml->open_customTag('item');
681 $arrContent = array('name'=>'Performance Rate', 'value'=>$row['percentage']);
682 $xml->innerContent($arrContent);
683 $xml->close_customTag();
686 //All CQM Measures taken here
687 foreach ($CQMeausesArr as $cqmKey => $cqmVal) {
688 //DENEXCEP(Denominator Exception not needed for some rules are skipping here)
689 if ((in_array($row['cqm_nqf_code'], $denExcepNotNeedRules) ) && ($cqmKey == "exception_patients")) {
694 if ($cqmKey == "init_patients") {
695 $itemPatArr = collectItemizedPatientsCdrReport($report_id, $itemized_test_id, $cqmItemizedArr[$cqmKey]);
697 $itemPatArr = collectItemizedPatientsCdrReport($report_id, $itemized_test_id, $cqmItemizedArr[$cqmKey], $numerator_label);
700 $fullPatArr = array();
701 foreach ($itemPatArr as $itemPatInfo) {
702 $fullPatArr[] = $itemPatInfo['pid'];
705 //Initial Patient Population
706 $xml->open_customTag('item');
707 $arrContent = array('name'=>$cqmVal, 'value'=>count($fullPatArr));
708 $xml->innerContent($arrContent);
710 $detailsArr = getQRDAPatientNeedInfo($fullPatArr);
715 //Gender Section Display
716 foreach ($mainQrdaGenderCodeArr as $GKey => $GVal) {
717 $xml->open_customTag('item');
718 $genderInfo = $detailsArr['gender'][$GVal];
719 $arrContent = array('name'=>$GVal, 'value'=>$genderInfo);
720 $xml->innerContent($arrContent);
721 $xml->close_customTag();
724 //Ethnicity Section Display
725 foreach ($mainEthiArr as $ethKey => $ethVal) {
726 $ethnicity_data = $detailsArr['ethnicity'][$ethVal];
727 $xml->open_customTag('item');
728 $arrContent = array('name'=>'Ethnicity - '.$ethVal, 'value'=>$ethnicity_data);
729 $xml->innerContent($arrContent);
730 $xml->close_customTag();
733 //Race Section Display
734 foreach ($mainQrdaRaceArr as $RKey => $RVal) {
735 $race_data = $detailsArr['race'][$RVal];
736 $xml->open_customTag('item');
737 $arrContent = array('name'=>'Race - '.$RVal, 'value'=>$race_data);
738 $xml->innerContent($arrContent);
739 $xml->close_customTag();
742 //Payer Type Section Display
743 $payerCheckArr = getQRDAPayerInfo($fullPatArr);
744 foreach ($mainQrdaPayerCodeArr as $PKey => $PVal) {
745 $xml->open_customTag('item');
746 $arrContent = array('name'=>'Payer - '.$PVal, 'value'=>$payerCheckArr[$PVal]);
747 $xml->innerContent($arrContent);
748 $xml->close_customTag();
753 $xml->close_customTag();
762 #######################################################################
763 ######################### QUALITY MEASURES START ######################
764 #######################################################################
765 if (count($dataSheet) > 0) {
767 $skipMultNumArr = array();
768 $dataChkArr = array();
769 foreach ($multNumNQFArr as $multNumVal) {
770 $skipMultNumArr[$multNumVal] = false;
771 $dataChkArr[$multNumVal] = 0;
775 foreach ($dataSheet as $row) {
776 $itemized_test_id = $row['itemized_test_id'];
777 $numerator_label = $row['numerator_label'];
779 //if($row['cqm_nqf_code'] == "0028a") continue;
781 //if($row['cqm_nqf_code'] == "0038"){
782 // if(in_array($row['numerator_label'], $NQF38NumArr)) continue;
785 if (in_array($row['cqm_nqf_code'], $multNumNQFArr)) {
786 $dataChkArr[$row['cqm_nqf_code']]++
;
789 //CQM Rules 2014 set, 0013 is 0018
790 if ($row['cqm_nqf_code'] == "0013") {
791 $row['cqm_nqf_code'] = "0018";
794 $tdTitle = generate_display_field(array('data_type'=>'1','list_id'=>'clinical_rules'), $row['id']);
795 if (!empty($row['cqm_pqri_code'])) {
796 $tdTitle .= " " . xlt('PQRI') . ":" . text($row['cqm_pqri_code']) . " ";
799 if (!empty($row['cqm_nqf_code'])) {
800 $tdTitle .= " " . xlt('NQF') . ":" . text($row['cqm_nqf_code']) . " ";
803 if (!(empty($row['concatenated_label']))) {
804 $tdTitle .= ", " . xlt($row['concatenated_label']) . " ";
807 ###########################################################
808 if (( !isset($skipMultNumArr[$row['cqm_nqf_code']]) ) ||
($skipMultNumArr[$row['cqm_nqf_code']] == false)) {
813 $arr = array('classCode'=>'CLUSTER', 'moodCode'=>'EVN');
814 $xml->open_customTag('organizer', $arr);
816 $tempID = "2.16.840.1.113883.10.20.24.3.98";
817 $xml->self_templateid($tempID);
819 $tempID = "2.16.840.1.113883.10.20.27.3.1";
820 $xml->self_templateid($tempID);
822 //$tempID = "2.16.840.1.113883.10.20.27.3.17";
823 //$xml->self_templateid($tempID);
825 $xml->self_customId($actId);
827 $arr = array('code'=>'completed');
828 $xml->self_customTag('statusCode', $arr);
831 $arr = array('typeCode'=>'REFR');
832 $xml->open_customTag('reference', $arr);
834 //externalDocument Start
835 $arr = array('classCode'=>'DOC', 'moodCode'=>'EVN');
836 $xml->open_customTag('externalDocument', $arr);
838 //$exDocID = getUuid();
839 $exDocID = $uniqIdArr[$innrCnt];
840 //$xml->self_customId($exDocID);
841 $xml->self_customTag('id', array('root' => '2.16.840.1.113883.4.738', 'extension' =>$exDocID));
843 $arr = array('code'=>'57024-2', 'displayName'=>'Health Quality Measure Document', 'codeSystem'=>'2.16.840.1.113883.6.1', 'codeSystemName'=>'LOINC');
844 $xml->self_codeCustom($arr);
846 $dispContntTitle = str_replace("&", '', $tdTitle);
847 $xml->textDispContent($dispContntTitle);
849 //externalDocument Close
850 $xml->close_customTag();
853 $xml->close_customTag();
856 ############### Performance Rate for Proportion Measure template START###################
857 $xml->open_loopComponent();
860 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
862 $tempID = "2.16.840.1.113883.10.20.27.3.14";
863 $xml->self_templateid($tempID);
865 $tempID = "2.16.840.1.113883.10.20.27.3.25";
866 $xml->self_templateid($tempID);
868 $arr = array('code'=>'72510-1', 'displayName'=>'Performance Rate', 'codeSystem'=>'2.16.840.1.113883.6.1', 'codeSystemName'=>'SNOMED-CT');
869 $xml->self_codeCustom($arr);
871 $arr = array('code'=>'completed');
872 $xml->self_customTag('statusCode', $arr);
874 $percentage = str_replace("%", '', $row['percentage']);
875 $arr = array('xsi:type'=>'REAL', 'value'=>$percentage/100);
876 $xml->self_customTag('value', $arr);
879 $arr = array('typeCode'=>'REFR');
880 $xml->open_customTag('reference', $arr);
882 //externalObservation Start
883 $arr = array('classCode'=>'OBS', 'moodCode'=>'EVN');
884 $xml->open_customTag('externalObservation', $arr);
887 //$exDocID = getUuid();
890 if (($row['cqm_nqf_code'] == "0421" )) {
891 $exDocID = $preDefPopIdArr[$row['cqm_nqf_code']][$row['numerator_label']]["NUMER"];
892 } else if (($row['cqm_nqf_code'] == "0024")) {
893 $exDocID = $preDefPopIdArr[$row['cqm_nqf_code']][$row['population_label']][$row['numerator_label']]["NUMER"];
895 if ($preDefPopIdArr[$row['cqm_nqf_code']]["NUMER"] != "") {
896 $exDocID = $preDefPopIdArr[$row['cqm_nqf_code']]["NUMER"];
898 $exDocID = getUuid();
902 $xml->self_customId($exDocID);
904 $arr = array('code'=>'NUMER', 'displayName'=>'Numerator', 'codeSystem'=>'2.16.840.1.113883.5.1063', 'codeSystemName'=>'ObservationValue');
905 $xml->self_codeCustom($arr);
907 //externalObservation Close
908 $xml->close_customTag();
911 $xml->close_customTag();
914 $xml->close_customTag();
916 $xml->close_loopComponent();
917 ############### Performance Rate for Proportion Measure template END ###################
920 //All CQM Measures taken here
921 foreach ($CQMeausesArr as $cqmKey => $cqmVal) {
922 //DENEXCEP(Denominator Exception not needed for some rules are skipping here)
923 if ((in_array($row['cqm_nqf_code'], $denExcepNotNeedRules) ) && ($cqmKey == "exception_patients")) {
927 //cqm 0024 alllowing only nuemerator 2 and numerator 3 for ipp1,ipp2 and 1pp3 to avoid repeatation
928 if ($row['cqm_nqf_code'] == '0024' && ($row['numerator_label'] == "Numerator 2" ||
$row['numerator_label'] == "Numerator 3") && $cqmKey != 'numer_patients') {
932 if ($row['cqm_nqf_code'] == '0024' && ($row['population_label'] == "Population Criteria 2" ||
$row['population_label'] == "Population Criteria 3")) {
938 if ($cqmKey == "init_patients") {
939 $itemPatArr = collectItemizedPatientsCdrReport($report_id, $itemized_test_id, $cqmItemizedArr[$cqmKey]);
941 $itemPatArr = collectItemizedPatientsCdrReport($report_id, $itemized_test_id, $cqmItemizedArr[$cqmKey], $numerator_label);
944 $fullPatArr = array();
945 foreach ($itemPatArr as $itemPatInfo) {
946 $fullPatArr[] = $itemPatInfo['pid'];
949 $detailsArr = getQRDAPatientNeedInfo($fullPatArr);
950 ############### Initial patient population template START###################
951 $xml->open_loopComponent();
954 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
956 $tempID = "2.16.840.1.113883.10.20.27.3.5";
957 $xml->self_templateid($tempID);
959 $tempID = "2.16.840.1.113883.10.20.27.3.16";
960 $xml->self_templateid($tempID);
962 $arr = array('code'=>'ASSERTION', 'displayName'=>'Assertion', 'codeSystem'=>'2.16.840.1.113883.5.4', 'codeSystemName'=>'ActCode');
963 $xml->self_codeCustom($arr);
965 $arr = array('code'=>'completed');
966 $xml->self_customTag('statusCode', $arr);
968 $arr = array('xsi:type'=>'CD', 'code'=>$mainQrdaPopulationIncArr[$cqmKey], 'displayName'=>$cqmVal, 'codeSystem' =>'2.16.840.1.113883.5.1063', 'codeSystemName'=>'ObservationValue');
969 $xml->self_customTag('value', $arr);
971 //entryRelationship Open
972 $xml->open_customTag('entryRelationship', array('typeCode'=>'SUBJ', 'inversionInd'=>'true'));
975 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
977 $tempID = "2.16.840.1.113883.10.20.27.3.3";
978 $xml->self_templateid($tempID);
980 $tempID = "2.16.840.1.113883.10.20.27.3.24";
981 $xml->self_templateid($tempID);
983 $arr = array('code'=>'MSRAGG', 'displayName'=>'rate aggregation', 'codeSystem'=>'2.16.840.1.113883.5.4', 'codeSystemName'=>'ActCode');
984 $xml->self_codeCustom($arr);
986 //$arr = array('code'=>'completed');
987 //$xml->self_customTag('statusCode', $arr);
989 $arr = array('xsi:type'=>'INT', 'value'=>count($fullPatArr));
990 $xml->self_customTag('value', $arr);
992 $arr = array('code'=>'COUNT', 'displayName'=>'Count', 'codeSystem'=>'2.16.840.1.113883.5.84', 'codeSystemName'=>'ObservationMethod');
993 $xml->self_customTag('methodCode', $arr);
996 $xml->close_customTag();
998 //entryRelationship Close
999 $xml->close_customTag();
1001 #### Stratum Start (Stratification)#####
1002 if ($row['cqm_nqf_code'] == '0024') {
1004 for (; $strat_count <= 2; $strat_count++
) {
1005 $strata_value = $stratum[$strat_count][$cqmKey];
1007 if ($row['numerator_label'] == "Numerator 2") {
1008 $strata_value = $stratum[$strat_count]['numer2'];
1009 } else if ($row['numerator_label'] == "Numerator 3") {
1010 $strata_value = $stratum[$strat_count]['numer3'];
1013 //entryRelationship Open
1014 $xml->open_customTag('entryRelationship', array('typeCode'=>'COMP'));
1017 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
1019 $tempID = "2.16.840.1.113883.10.20.27.3.4";
1020 $xml->self_templateid($tempID);
1022 $tempID = "2.16.840.1.113883.10.20.27.3.20";
1023 $xml->self_templateid($tempID);
1025 $arr = array('code'=>'ASSERTION', 'displayName'=>'Assertion', 'codeSystem'=>'2.16.840.1.113883.5.4', 'codeSystemName'=>'ActCode');
1026 $xml->self_codeCustom($arr);
1028 $arr = array('code'=>'completed');
1029 $xml->self_customTag('statusCode', $arr);
1032 $xml->open_customTag('value', array('xsi:type'=>'CD', 'nullFlavor'=>'OTH'));
1034 $stratumText = $preDefPopIdArr[$row['cqm_nqf_code']][$row['population_label']][$row['numerator_label']]['DISPLAY_TEXT'];
1035 $xml->element('originalText', "Stratum ".$strat_count);
1038 $xml->close_customTag();
1040 //entryRelationship Open
1041 $xml->open_customTag('entryRelationship', array('typeCode'=>'SUBJ', 'inversionInd' => 'true'));
1044 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
1046 $tempID = "2.16.840.1.113883.10.20.27.3.3";
1047 $xml->self_templateid($tempID);
1049 $arr = array('code'=>'MSRAGG', 'displayName'=>'rate aggregation', 'codeSystem'=>'2.16.840.1.113883.5.4', 'codeSystemName'=>'ActCode');
1050 $xml->self_codeCustom($arr);
1052 $arr = array('xsi:type'=>'INT', 'value'=>$strata_value);
1053 $xml->self_customTag('value', $arr);
1055 $arr = array('code'=>'COUNT', 'displayName'=>'Count', 'codeSystem'=>'2.16.840.1.113883.5.84', 'codeSystemName'=>'ObservationMethod');
1056 $xml->self_customTag('methodCode', $arr);
1059 $xml->close_customTag();
1061 //entryRelationship Close
1062 $xml->close_customTag();
1065 $arr = array('typeCode'=>'REFR');
1066 $xml->open_customTag('reference', $arr);
1068 //externalObservation Start
1069 $arr = array('classCode'=>'OBS', 'moodCode'=>'EVN');
1070 $xml->open_customTag('externalObservation', $arr);
1072 //Modified HQMF_ID for CQM IDS
1073 //$refID = $preDefPopIdArr[$row['cqm_nqf_code']][$row['population_label']][$row['numerator_label']]['STRAT'];
1074 $refID = $preDefPopIdArr[$row['cqm_nqf_code']]['STRAT'.$strat_count];
1076 $xml->self_customId($refID);
1078 //externalObservation Close
1079 $xml->close_customTag();
1082 $xml->close_customTag();
1085 $xml->close_customTag();
1087 //entryRelationship Close
1088 $xml->close_customTag();
1092 #### Stratum END #####
1094 ####################################################
1095 ####################################################
1096 //Sex Supplemental Data Element START
1097 ####################################################
1098 ####################################################
1100 foreach ($mainQrdaGenderCodeArr as $GKey => $GVal) {
1101 //entryRelationship Open
1102 $xml->open_customTag('entryRelationship', array('typeCode'=>'COMP'));
1105 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
1107 $tempID = "2.16.840.1.113883.10.20.27.3.6";
1108 $xml->self_templateid($tempID);
1110 $tempID = "2.16.840.1.113883.10.20.27.3.21";
1111 $xml->self_templateid($tempID);
1113 $arr = array('code'=>'184100006', 'displayName'=>'patient sex', 'codeSystem'=>'2.16.840.1.113883.6.96', 'codeSystemName'=>'SNOMED-CT');
1114 $xml->self_codeCustom($arr);
1116 $arr = array('code'=>'completed');
1117 $xml->self_customTag('statusCode', $arr);
1119 $arr = array('xsi:type'=>'CD', 'code'=>$GKey, 'codeSystem' =>'2.16.840.1.113883.5.1', 'codeSystemName'=>'AdministrativeGenderCode');
1120 $xml->self_customTag('value', $arr);
1122 //entryRelationship Open
1123 $xml->open_customTag('entryRelationship', array('typeCode'=>'SUBJ', 'inversionInd'=>'true'));
1126 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
1128 $tempID = "2.16.840.1.113883.10.20.27.3.3";
1129 $xml->self_templateid($tempID);
1131 $tempID = "2.16.840.1.113883.10.20.27.3.24";
1132 $xml->self_templateid($tempID);
1134 $arr = array('code'=>'MSRAGG', 'displayName'=>'rate aggregation', 'codeSystem'=>'2.16.840.1.113883.5.4', 'codeSystemName'=>'ActCode');
1135 $xml->self_codeCustom($arr);
1137 //$arr = array('code'=>'completed');
1138 //$xml->self_customTag('statusCode', $arr);
1140 $arr = array('xsi:type'=>'INT', 'value'=>$detailsArr['gender'][$GVal]);
1141 $xml->self_customTag('value', $arr);
1143 $arr = array('code'=>'COUNT', 'displayName'=>'Count', 'codeSystem'=>'2.16.840.1.113883.5.84', 'codeSystemName'=>'ObservationMethod');
1144 $xml->self_customTag('methodCode', $arr);
1147 $xml->close_customTag();
1149 //entryRelationship Close
1150 $xml->close_customTag();
1154 $xml->close_customTag();
1156 //entryRelationship Close
1157 $xml->close_customTag();
1160 ####################################################
1161 ####################################################
1162 //Sex Supplemental Data Element END
1163 ####################################################
1164 ####################################################
1166 ####################################################
1167 ####################################################
1168 //Ethnicity Supplemental Data Element (CMS EP) START
1169 ####################################################
1170 ####################################################
1172 foreach ($mainEthiArr as $ethKey => $ethVal) {
1173 //entryRelationship Open
1174 $xml->open_customTag('entryRelationship', array('typeCode'=>'COMP'));
1177 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
1179 $tempID = "2.16.840.1.113883.10.20.27.3.7";
1180 $xml->self_templateid($tempID);
1182 $tempID = "2.16.840.1.113883.10.20.27.3.22";
1183 $xml->self_templateid($tempID);
1185 $arr = array('code'=>'364699009', 'displayName'=>'Ethnic Group', 'codeSystem'=>'2.16.840.1.113883.6.96', 'codeSystemName'=>'SNOMED-CT');
1186 $xml->self_codeCustom($arr);
1188 $arr = array('code'=>'completed');
1189 $xml->self_customTag('statusCode', $arr);
1191 $arr = array('xsi:type'=>'CD', 'code'=>$mainEthiCodeArr[$ethKey], 'displayName'=>$ethVal, 'codeSystem' =>'2.16.840.1.113883.6.238', 'codeSystemName'=>'Race & Ethnicity - CDC');
1192 $xml->self_customTag('value', $arr);
1194 //entryRelationship Open
1195 $xml->open_customTag('entryRelationship', array('typeCode'=>'SUBJ', 'inversionInd'=>'true'));
1198 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
1200 $tempID = "2.16.840.1.113883.10.20.27.3.3";
1201 $xml->self_templateid($tempID);
1203 $tempID = "2.16.840.1.113883.10.20.27.3.24";
1204 $xml->self_templateid($tempID);
1206 $arr = array('code'=>'MSRAGG', 'displayName'=>'rate aggregation', 'codeSystem'=>'2.16.840.1.113883.5.4', 'codeSystemName'=>'ActCode');
1207 $xml->self_codeCustom($arr);
1209 //$arr = array('code'=>'completed');
1210 //$xml->self_customTag('statusCode', $arr);
1212 $arr = array('xsi:type'=>'INT', 'value'=>$detailsArr['ethnicity'][$ethVal]);
1213 $xml->self_customTag('value', $arr);
1215 $arr = array('code'=>'COUNT', 'displayName'=>'Count', 'codeSystem'=>'2.16.840.1.113883.5.84', 'codeSystemName'=>'ObservationMethod');
1216 $xml->self_customTag('methodCode', $arr);
1219 $xml->close_customTag();
1221 //entryRelationship Close
1222 $xml->close_customTag();
1226 $xml->close_customTag();
1228 //entryRelationship Close
1229 $xml->close_customTag();
1232 ####################################################
1233 ####################################################
1234 //Ethnicity Supplemental Data Element (CMS EP) END
1235 ####################################################
1236 ####################################################
1239 ####################################################
1240 ####################################################
1241 //Race Supplemental Data Element (CMS EP) START
1242 ####################################################
1243 ####################################################
1245 foreach ($mainQrdaRaceArr as $RKey => $RVal) {
1246 //entryRelationship Open
1247 $xml->open_customTag('entryRelationship', array('typeCode'=>'COMP'));
1250 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
1252 $tempID = "2.16.840.1.113883.10.20.27.3.8";
1253 $xml->self_templateid($tempID);
1255 $tempID = "2.16.840.1.113883.10.20.27.3.19";
1256 $xml->self_templateid($tempID);
1258 $arr = array('code'=>'103579009', 'displayName'=>'Race', 'codeSystem'=>'2.16.840.1.113883.6.96', 'codeSystemName'=>'SNOMED-CT');
1259 $xml->self_codeCustom($arr);
1261 $arr = array('code'=>'completed');
1262 $xml->self_customTag('statusCode', $arr);
1264 $arr = array('xsi:type'=>'CD', 'code'=>$mainQrdaRaceCodeArr[$RKey], 'displayName'=>$RVal, 'codeSystem' =>'2.16.840.1.113883.6.238', 'codeSystemName'=>'Race & Ethnicity - CDC');
1265 $xml->self_customTag('value', $arr);
1267 //entryRelationship Open
1268 $xml->open_customTag('entryRelationship', array('typeCode'=>'SUBJ', 'inversionInd'=>'true'));
1271 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
1273 $tempID = "2.16.840.1.113883.10.20.27.3.3";
1274 $xml->self_templateid($tempID);
1276 $tempID = "2.16.840.1.113883.10.20.27.3.24";
1277 $xml->self_templateid($tempID);
1279 $arr = array('code'=>'MSRAGG', 'displayName'=>'rate aggregation', 'codeSystem'=>'2.16.840.1.113883.5.4', 'codeSystemName'=>'ActCode');
1280 $xml->self_codeCustom($arr);
1282 //$arr = array('code'=>'completed');
1283 //$xml->self_customTag('statusCode', $arr);
1285 $arr = array('xsi:type'=>'INT', 'value'=>$detailsArr['race'][$RVal]);
1286 $xml->self_customTag('value', $arr);
1288 $arr = array('code'=>'COUNT', 'displayName'=>'Count', 'codeSystem'=>'2.16.840.1.113883.5.84', 'codeSystemName'=>'ObservationMethod');
1289 $xml->self_customTag('methodCode', $arr);
1292 $xml->close_customTag();
1294 //entryRelationship Close
1295 $xml->close_customTag();
1299 $xml->close_customTag();
1301 //entryRelationship Close
1302 $xml->close_customTag();
1305 ####################################################
1306 ####################################################
1307 //Race Supplemental Data Element (CMS EP) END
1308 ####################################################
1309 ####################################################
1312 ####################################################
1313 ####################################################
1314 //Payer Supplemental Data Element (CMS EP) START
1315 ####################################################
1316 ####################################################
1317 $payerCheckArr = getQRDAPayerInfo($fullPatArr);
1318 foreach ($mainQrdaPayerCodeArr as $PKey => $PVal) {
1319 //entryRelationship Open
1320 $xml->open_customTag('entryRelationship', array('typeCode'=>'COMP'));
1323 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
1325 $tempID = "2.16.840.1.113883.10.20.27.3.9";
1326 $xml->self_templateid($tempID);
1328 $tempID = "2.16.840.1.113883.10.20.24.3.55";
1329 $xml->self_templateid($tempID);
1331 $tempID = "2.16.840.1.113883.10.20.27.3.18";
1332 $xml->self_templateid($tempID);
1334 $xml->self_setpatientRoleid();
1336 $arr = array('code'=>'48768-6', 'displayName'=>'Payment source', 'codeSystem'=>'2.16.840.1.113883.6.1', 'codeSystemName'=>'SNOMED-CT');
1337 $xml->self_codeCustom($arr);
1339 $arr = array('code'=>'completed');
1340 $xml->self_customTag('statusCode', $arr);
1342 $timeArr = array('low'=>date('Ymd', strtotime($from_date)));
1343 $xml->add_entryEffectTime($timeArr);
1347 $xml->open_customTag('value', array('xsi:type'=>'CD', 'nullFlavor'=>'OTH'));
1349 $xml->self_customTag('translation', array('code'=>$PKey, 'displayName'=>$PVal, 'codeSystem'=>'2.16.840.1.113883.3.249.12', 'codeSystemName'=>'CMS Clinical Codes'));
1352 $xml->close_customTag();
1356 $xml->self_customTag('value', array('xsi:type'=>'CD', 'code'=>$mainQrdaPayerCodeSendArr[$PKey], 'codeSystem'=>'2.16.840.1.113883.3.221.5' , 'codeSystemName'=>'SOP', 'displayName'=>$PVal));
1358 //entryRelationship Open
1359 $xml->open_customTag('entryRelationship', array('typeCode'=>'SUBJ', 'inversionInd'=>'true'));
1362 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
1364 $tempID = "2.16.840.1.113883.10.20.27.3.3";
1365 $xml->self_templateid($tempID);
1367 $tempID = "2.16.840.1.113883.10.20.27.3.24";
1368 $xml->self_templateid($tempID);
1370 $arr = array('code'=>'MSRAGG', 'displayName'=>'rate aggregation', 'codeSystem'=>'2.16.840.1.113883.5.4', 'codeSystemName'=>'ActCode');
1371 $xml->self_codeCustom($arr);
1373 //$arr = array('code'=>'completed');
1374 //$xml->self_customTag('statusCode', $arr);
1376 $arr = array('xsi:type'=>'INT', 'value'=>$payerCheckArr[$PVal]);
1377 $xml->self_customTag('value', $arr);
1379 $arr = array('code'=>'COUNT', 'displayName'=>'Count', 'codeSystem'=>'2.16.840.1.113883.5.84', 'codeSystemName'=>'ObservationMethod');
1380 $xml->self_customTag('methodCode', $arr);
1383 $xml->close_customTag();
1385 //entryRelationship Close
1386 $xml->close_customTag();
1390 $xml->close_customTag();
1392 //entryRelationship Close
1393 $xml->close_customTag();
1396 ####################################################
1397 ####################################################
1398 //Payer Supplemental Data Element (CMS EP) END
1399 ####################################################
1400 ####################################################
1402 ######################################################################
1404 $arr = array('typeCode'=>'REFR');
1405 $xml->open_customTag('reference', $arr);
1407 //externalObservation Start
1408 $arr = array('classCode'=>'OBS', 'moodCode'=>'EVN');
1409 $xml->open_customTag('externalObservation', $arr);
1411 //Modified HQMF_ID for CQM IDS
1412 if (($row['cqm_nqf_code'] == "0421" )) {
1413 $refID = $preDefPopIdArr[$row['cqm_nqf_code']][$row['numerator_label']][$mainQrdaPopulationIncArr[$cqmKey]];
1414 } else if (($row['cqm_nqf_code'] == "0024")) {
1415 $refID = $preDefPopIdArr[$row['cqm_nqf_code']][$row['population_label']][$row['numerator_label']][$mainQrdaPopulationIncArr[$cqmKey]];
1417 $refID = $preDefPopIdArr[$row['cqm_nqf_code']][$mainQrdaPopulationIncArr[$cqmKey]];
1424 $xml->self_customId($refID);
1426 //externalObservation Close
1427 $xml->close_customTag();
1430 $xml->close_customTag();
1431 ########################################################################
1434 $xml->close_customTag();
1436 $xml->close_loopComponent();
1437 ############### Initial patient population template END#####################
1440 //Multiple Numerator Handling
1441 if (in_array($row['cqm_nqf_code'], $multNumNQFArr)) {
1442 //Skipping Multiple Numerator(s)
1443 if (in_array($row['cqm_nqf_code'], $multNumNQFArr)) {
1444 $skipMultNumArr[$row['cqm_nqf_code']] = true;
1447 if ($dataChkArr[$row['cqm_nqf_code']] == $countNumNQFArr[$row['cqm_nqf_code']]) {
1449 $xml->close_customTag();
1450 $xml->close_entry();
1454 $xml->close_customTag();
1455 $xml->close_entry();
1458 ###########################################################
1464 #######################################################################
1465 ######################### QUALITY MEASURES END ########################
1466 #######################################################################
1469 $xml->close_section();
1471 $xml->close_loopComponent();
1473 ##################### LOOP Component(s) END ########################
1475 $xml->close_structuredBody();
1476 ############### Structure Body Close #######################
1478 $xml->close_mainComponent();
1479 ############### Main Component Close #######################
1481 //Close Main Clinical Document
1482 $xml->close_clinicaldocument();
1485 //QRDA File Download Folder in site/cqm_qrda folder
1486 $qrda_fname = "QRDA_III_".date("YmdHis").".xml";
1487 $qrda_file_path = $GLOBALS['OE_SITE_DIR'] . "/documents/cqm_qrda/";
1488 if (!file_exists($qrda_file_path)) {
1489 mkdir($qrda_file_path, 0777, true);
1492 $qrda_file_name = $qrda_file_path.$qrda_fname;
1493 $fileQRDAOPen = fopen($qrda_file_name, "w");
1494 fwrite($fileQRDAOPen, trim($xml->getXml()));
1495 fclose($fileQRDAOPen);
1500 <?php
html_header_show();?
>
1501 <script type
="text/javascript" src
="<?php echo $webroot ?>/interface/main/tabs/js/include_opener.js"></script
>
1502 <link rel
=stylesheet href
="<?php echo $css_header;?>" type
="text/css">
1503 <title
><?php
echo xlt('Export QRDA Report'); ?
></title
>
1505 <script type
="text/javascript">
1507 function closeme() {
1514 <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
>
1519 <a href
="qrda_download.php?qrda_fname=<?php echo attr_url($qrda_fname); ?>&csrf_token_form=<?php echo attr_url($_SESSION['csrf_token']); ?>"><?php
echo xlt("Download QRDA Category III File");?
></a
>
1521 <textarea rows
='50' cols
='500' style
='width:95%' readonly
>
1522 <?php
echo trim($xml->getXml()); ?
>
1525 <p
><input type
='button' value
='<?php echo xla('Close
'); ?>' onclick
='closeme();' /></p
>