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 $facilityService = new \services\
FacilityService();
36 //Remove time limit, since script can take many minutes
39 //DENEXCEP NOT NEEDED rules
40 $denExcepNotNeedRules = array('0002', '0018', '0024', '0038', '0043', '0059', '0421');
42 //Predefined QRDA HQMF ID's for CQM rules
43 $preDefinedUniqIDRules = array();
44 $preDefPopIdArr = array();
46 // CMS147v4/0041 - Preventive Care and Screening: Influenza Immunization HQMF ID: 40280381-4600-425F-0146-EE66F0005509
47 $preDefinedUniqIDRules['0041'] = '40280381-4600-425F-0146-EE66F0005509';
48 $preDefPopIdArr['0041']['IPP'] = 'F48702E6-D39A-49D8-BE3C-8FAB5C6AADDA';
49 $preDefPopIdArr['0041']['DENOM'] = 'B61EC2DC-0841-4906-A84B-5BE5024DA7F1';
50 $preDefPopIdArr['0041']['NUMER'] = '0ED7B212-369B-489A-A5B5-07BC146FA557';
51 $preDefPopIdArr['0041']['DENEXCEP'] = 'B5C9EC50-3011-43DC-AD07-CED2D3B770B2';
53 // CMS122v3/0059 - Diabetes: Hemoglobin A1c Poor Control: HQMF_ID: 40280381-4555-E1C1-0145-90AC70DE2C73
54 $preDefinedUniqIDRules['0059'] = '40280381-4555-E1C1-0145-90AC70DE2C73';
55 $preDefPopIdArr['0059']['IPP'] = 'EDED90E9-E4FE-47E6-90AC-29D9AA3E861A';
56 $preDefPopIdArr['0059']['DENOM'] = '6721D6DA-E87D-4E42-A34A-C8490686598C';
57 $preDefPopIdArr['0059']['NUMER'] = '7549BA9E-1841-4231-8CAA-095BDF0AB8A1';
60 //CMS139v3/0101 - Falls: Screening for Future Fall Risk: HQMF_ID: 40280381-4555-E1C1-0145-672613970D15
61 $preDefinedUniqIDRules['0101'] = '40280381-4555-E1C1-0145-672613970D15';
62 $preDefPopIdArr['0101']['IPP'] = '2448B0C6-6848-4DCB-AA6D-F199337A2C5C';
63 $preDefPopIdArr['0101']['DENOM'] = 'EC400908-35BE-439B-92A9-231D99CEA9DF';
64 $preDefPopIdArr['0101']['NUMER'] = '663FB12B-0FF4-49AB-80A3-624C5E7DF892';
65 $preDefPopIdArr['0101']['DENEXCEP'] = 'FEC7251A-BF8D-4472-97D8-E2A9C0A42176';
67 //CMS127v3/0043 - Pneumonia Vaccination Status for Older Adults: HQMF_ID: 40280381-4555-E1C1-0145-762578A81C4C
68 $preDefinedUniqIDRules['0043'] = '40280381-4555-E1C1-0145-762578A81C4C';
69 $preDefPopIdArr['0043']['IPP'] = '873AECC7-E15B-49E7-8391-D73A46201E2E';
70 $preDefPopIdArr['0043']['DENOM'] = 'FF7016E1-E8C7-43BA-9D56-2BEF649F36FA';
71 $preDefPopIdArr['0043']['NUMER'] = '201F5A6E-4DDE-43A2-BDFC-CE85A98560DA';
73 //CMS69v3/0421 - Preventive Care and Screening: Body Mass Index (BMI) Screening and Follow-Up Plan: HQMF_ID: 40280381-4555-E1C1-0145-D2B36DBB3FE6
74 $preDefinedUniqIDRules['0421']['Numerator 1'] = '40280381-4555-E1C1-0145-D2B36DBB3FE6';
75 $preDefPopIdArr['0421']['Numerator 1']['IPP'] = '1C936855-E644-44C0-B264-49A28756FDB1';
76 $preDefPopIdArr['0421']['Numerator 1']['DENOM'] = '27F1591C-2060-462C-B5D7-7FE86A44B534';
77 $preDefPopIdArr['0421']['Numerator 1']['DENEX'] = '9B0C3C26-D621-4EA3-81FB-A839A3012044';
78 $preDefPopIdArr['0421']['Numerator 1']['NUMER'] = '3095531C-24D7-4AFB-9BCB-F1901FF0FF69';
80 $preDefinedUniqIDRules['0421']['Numerator 2'] = '40280381-4555-E1C1-0145-D2B36DBB3FE6';
81 $preDefPopIdArr['0421']['Numerator 2']['IPP'] = '6E701B1C-6CA5-4AD5-98C9-5F766745EA89';
82 $preDefPopIdArr['0421']['Numerator 2']['DENOM'] = 'E4DC29B8-EB26-4A01-ABB0-4F99FC03BA39';
83 $preDefPopIdArr['0421']['Numerator 2']['DENEX'] = 'BB1B4301-C275-4BAC-87C9-6E960B1601DA';
84 $preDefPopIdArr['0421']['Numerator 2']['NUMER'] = '7669026D-3683-44CC-A2C5-3D62EB2F8A33';
86 //CMS117v3/0038 - Childhood Immunization Status: HQMF_ID: 40280381-4555-E1C1-0145-D7C003364261
87 $preDefinedUniqIDRules['0038'] = '40280381-4555-E1C1-0145-D7C003364261';
88 $preDefPopIdArr['0038']['IPP'] = '6ED6A787-C871-49B9-825C-70A0DB898977';
89 $preDefPopIdArr['0038']['DENOM'] = '545DA813-89ED-4DCD-BDDF-4B33D93DCD84';
90 $preDefPopIdArr['0038']['NUMER'] = '00193FC7-AEE4-4507-A20F-D25A7BB214AD';
92 //CMS138v3/0028 - Preventive Care and Screening: Tobacco Use: Screening and Cessation Intervention: HQMF_ID: 40280381-4600-425F-0146-1F5867D40E82
93 $preDefinedUniqIDRules['0028'] = '40280381-4600-425F-0146-1F5867D40E82';
94 $preDefPopIdArr['0028']['IPP'] = '4E118B62-2AF8-4F51-9355-6FD3F2427D9F';
95 $preDefPopIdArr['0028']['DENOM'] = 'FA1B3953-AE58-4541-BF7B-84D0EB1B0713';
96 $preDefPopIdArr['0028']['NUMER'] = '35B1A6DF-1871-4633-A74B-BCAE371BC030';
97 $preDefPopIdArr['0028']['DENEXCEP'] = '3EE6DFF5-AB17-482F-A147-E6D1E46DBB79';
99 //CMS157v3/0384 - Oncology: Medical and Radiation – Pain Intensity Quantified: HQMF_ID: 40280381-4600-425F-0146-1F620BDF0EB0
100 $preDefinedUniqIDRules['0384'] = '40280381-4600-425F-0146-1F620BDF0EB0';
101 $preDefPopIdArr['0384']['IPP'] = 'C29B6555-3BC7-416F-B61A-FCACD637594F';
102 $preDefPopIdArr['0384']['DENOM'] = 'E5F80C25-6816-4992-92E2-A735B17F8D4F';
103 $preDefPopIdArr['0384']['NUMER'] = 'C948D0D2-D6E9-4099-9CD4-870F2F83A14C';
105 //CMS146v3/0002 - Appropriate Testing for Children with Pharyngitis: HQMF_ID: 40280381-4600-425F-0146-1F6E280C0F09
106 $preDefinedUniqIDRules['0002'] = '40280381-4600-425F-0146-1F6E280C0F09';
107 $preDefPopIdArr['0002']['IPP'] = '9D1135EA-BA90-45E7-8EED-F7335D1CC934';
108 $preDefPopIdArr['0002']['DENOM'] = 'D04EFECB-A901-4565-BDDB-826510499092';
109 $preDefPopIdArr['0002']['NUMER'] = '3F4CDE57-1C5C-4250-A338-55FED6775F57';
110 $preDefPopIdArr['0002']['DENEX'] = '0525FBA2-F068-4706-ADB5-E345852DC55B';
112 //CMS165v3/0018 - Controlling High Blood Pressure: HQMF_ID: 40280381-4600-425F-0146-1F6F722B0F17
113 $preDefinedUniqIDRules['0018'] = '40280381-4600-425F-0146-1F6F722B0F17';
114 $preDefPopIdArr['0018']['IPP'] = 'A72855CE-3C60-41F9-AEE2-64D4F584DDD4';
115 $preDefPopIdArr['0018']['DENOM'] = '26046A5C-E2CC-4A27-B480-FF7E3575691F';
116 $preDefPopIdArr['0018']['NUMER'] = '0899A359-0CD8-4977-AA29-666892AA3AD4';
117 $preDefPopIdArr['0018']['DENEX'] = '4327D845-6194-410D-A48D-D6E1802CAD55';
119 //CMS155v3/0024 - Weight Assessment and Counseling for Nutrition and Physical Activity for Children and Adolescents: HQMF_ID: 40280381-4555-E1C1-0145-85C7311720F5
120 $preDefinedUniqIDRules['0024']['Population Criteria 1']['Numerator 1'] = '40280381-4555-E1C1-0145-85C7311720F5';
121 $preDefPopIdArr['0024']['Population Criteria 1']['Numerator 1']['IPP'] = '10127790-AE94-4070-9DD3-1D3776D08D7C';
122 $preDefPopIdArr['0024']['Population Criteria 1']['Numerator 1']['DENOM'] = '3B3C1568-F875-49B1-9090-E2F494EECBB6';
123 $preDefPopIdArr['0024']['Population Criteria 1']['Numerator 1']['DENEX'] = 'B288D5A4-D573-4FAA-92D6-0B01E1B35C7A';
124 $preDefPopIdArr['0024']['Population Criteria 1']['Numerator 1']['NUMER'] = 'FD4649BD-B962-4CBE-BF4A-C2F95F3EA08E';
126 $preDefinedUniqIDRules['0024']['Population Criteria 1']['Numerator 2'] = '40280381-4555-E1C1-0145-85C7311720F5';
127 $preDefPopIdArr['0024']['Population Criteria 1']['Numerator 2']['IPP'] = '10127790-AE94-4070-9DD3-1D3776D08D7C';
128 $preDefPopIdArr['0024']['Population Criteria 1']['Numerator 2']['DENOM'] = '3B3C1568-F875-49B1-9090-E2F494EECBB6';
129 $preDefPopIdArr['0024']['Population Criteria 1']['Numerator 2']['DENEX'] = 'B288D5A4-D573-4FAA-92D6-0B01E1B35C7A';
130 $preDefPopIdArr['0024']['Population Criteria 1']['Numerator 2']['NUMER'] = '52FBD726-4DD1-48F5-98B9-7175754923E1';
132 $preDefinedUniqIDRules['0024']['Population Criteria 1']['Numerator 3'] = '40280381-4555-E1C1-0145-85C7311720F5';
133 $preDefPopIdArr['0024']['Population Criteria 1']['Numerator 3']['IPP'] = '10127790-AE94-4070-9DD3-1D3776D08D7C';
134 $preDefPopIdArr['0024']['Population Criteria 1']['Numerator 3']['DENOM'] = '3B3C1568-F875-49B1-9090-E2F494EECBB6';
135 $preDefPopIdArr['0024']['Population Criteria 1']['Numerator 3']['DENEX'] = 'B288D5A4-D573-4FAA-92D6-0B01E1B35C7A';
136 $preDefPopIdArr['0024']['Population Criteria 1']['Numerator 3']['NUMER'] = 'C43CE779-C5EE-4C15-A4CC-AF1C446CFB09';
138 $preDefinedUniqIDRules['0024']['Population Criteria 2']['Numerator 1'] = '40280381-4555-E1C1-0145-85C7311720F5';
139 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 1']['IPP'] = '10127790-AE94-4070-9DD3-1D3776D08D7C';
140 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 1']['DENOM'] = '3B3C1568-F875-49B1-9090-E2F494EECBB6';
141 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 1']['DENEX'] = 'B288D5A4-D573-4FAA-92D6-0B01E1B35C7A';
142 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 1']['NUMER'] = 'FD4649BD-B962-4CBE-BF4A-C2F95F3EA08E';
143 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 1']['STRAT'] = '40280381-3D61-56A7-013E-5D53298E6DA3';
144 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 1']['DISPLAY_TEXT'] = 'BMI Recorded, RS1: 3-11';
146 $preDefinedUniqIDRules['0024']['Population Criteria 2']['Numerator 2'] = '40280381-4555-E1C1-0145-85C7311720F5';
147 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 2']['IPP'] = '10127790-AE94-4070-9DD3-1D3776D08D7C';
148 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 2']['DENOM'] = '3B3C1568-F875-49B1-9090-E2F494EECBB6';
149 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 2']['DENEX'] = 'B288D5A4-D573-4FAA-92D6-0B01E1B35C7A';
150 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 2']['NUMER'] = '52FBD726-4DD1-48F5-98B9-7175754923E1';
151 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 2']['STRAT'] = '40280381-3D61-56A7-013E-5D53298E6DA3';
152 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 2']['DISPLAY_TEXT'] = 'BMI Recorded, RS2: 12-17';
154 $preDefinedUniqIDRules['0024']['Population Criteria 2']['Numerator 3'] = '40280381-4555-E1C1-0145-85C7311720F5';
155 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 3']['IPP'] = '10127790-AE94-4070-9DD3-1D3776D08D7C';
156 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 3']['DENOM'] = '3B3C1568-F875-49B1-9090-E2F494EECBB6';
157 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 3']['DENEX'] = 'B288D5A4-D573-4FAA-92D6-0B01E1B35C7A';
158 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 3']['NUMER'] = 'C43CE779-C5EE-4C15-A4CC-AF1C446CFB09';
159 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 3']['STRAT'] = '40280381-3D61-56A7-013E-5D53298E6DA3';
160 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 3']['DISPLAY_TEXT'] = 'Nutrition Counseling, RS1: 3-11';
162 $preDefinedUniqIDRules['0024']['Population Criteria 3']['Numerator 1'] = '40280381-4555-E1C1-0145-85C7311720F5';
163 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 1']['IPP'] = '10127790-AE94-4070-9DD3-1D3776D08D7C';
164 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 1']['DENOM'] = '3B3C1568-F875-49B1-9090-E2F494EECBB6';
165 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 1']['DENEX'] = 'B288D5A4-D573-4FAA-92D6-0B01E1B35C7A';
166 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 1']['NUMER'] = 'FD4649BD-B962-4CBE-BF4A-C2F95F3EA08E';
167 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 1']['STRAT'] = '40280381-3D61-56A7-013E-5D532AF06DA5';
168 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 1']['DISPLAY_TEXT'] = 'Nutrition Counseling, RS2: 12-17';
170 $preDefinedUniqIDRules['0024']['Population Criteria 3']['Numerator 2'] = '40280381-4555-E1C1-0145-85C7311720F5';
171 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 2']['IPP'] = '10127790-AE94-4070-9DD3-1D3776D08D7C';
172 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 2']['DENOM'] = '3B3C1568-F875-49B1-9090-E2F494EECBB6';
173 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 2']['DENEX'] = 'B288D5A4-D573-4FAA-92D6-0B01E1B35C7A';
174 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 2']['NUMER'] = '52FBD726-4DD1-48F5-98B9-7175754923E1';
175 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 2']['STRAT'] = '40280381-3D61-56A7-013E-5D532AF06DA5';
176 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 2']['DISPLAY_TEXT'] = 'Physical Activity Counseling, RS1: 3-11';
178 $preDefinedUniqIDRules['0024']['Population Criteria 3']['Numerator 3'] = '40280381-4555-E1C1-0145-85C7311720F5';
179 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 3']['IPP'] = '10127790-AE94-4070-9DD3-1D3776D08D7C';
180 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 3']['DENOM'] = '3B3C1568-F875-49B1-9090-E2F494EECBB6';
181 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 3']['DENEX'] = 'B288D5A4-D573-4FAA-92D6-0B01E1B35C7A';
182 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 3']['NUMER'] = 'C43CE779-C5EE-4C15-A4CC-AF1C446CFB09';
183 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 3']['STRAT'] = '40280381-3D61-56A7-013E-5D532AF06DA5';
184 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 3']['DISPLAY_TEXT'] = 'Physical Activity Counseling, RS2: 12-17';
186 $preDefPopIdArr['0024']['STRAT1'] = '40280381-3D61-56A7-013E-5D53298E6DA3';
187 $preDefPopIdArr['0024']['STRAT2'] = '40280381-3D61-56A7-013E-5D532AF06DA5';
189 //Multiple Numerator NQF# Array declaration
190 $multNumNQFArr = array('0421', '0024');
191 $countNumNQFArr = array();
192 $countNumNQFArr['0421'] = 2;//two Numerators
193 $countNumNQFArr['0024'] = 9;//Nine Numerators
195 //Initiation of all QRDA needed elements
196 $CQMeausesArr = array();
197 $CQMeausesArr['init_patients'] = "Initial Patient Population";
198 $CQMeausesArr['exclude_patients'] = "Denominator Exclusions";
199 $CQMeausesArr['denom_patients'] = "Denominator";
200 $CQMeausesArr['numer_patients'] = "Numerator";
201 $CQMeausesArr['exception_patients'] = "Denominator Exceptions";
203 $cqmItemizedArr = array();
204 $cqmItemizedArr['init_patients'] = "init_patients";
205 $cqmItemizedArr['exclude_patients'] = "exclude";
206 $cqmItemizedArr['denom_patients'] = "all";
207 $cqmItemizedArr['numer_patients'] = "pass";
208 $cqmItemizedArr['exception_patients'] = "exception";
210 //QRDA Needed Ethnicity
211 $mainEthiArr = array(0=>'Not Hispanic or Latino', 1=>'Hispanic or Latino');
212 $mainEthiCodeArr = array(0=>'2186-5', 1=>'2135-2');
215 $mainQrdaRaceArr = array(0=>'American Indian or Alaska Native', 1=>'Asian', 2=>'Black or African American', 3=>'Native Hawaiian or Other Pacific Islander', 4=>'White', 5=>'Other');
216 $mainQrdaRaceCodeArr = array(0=>'1002-5', 1=>'2028-9', 2=>'2054-5', 3=>'2076-8', 4=>'2106-3', 5=>'2131-1');
218 $mainQrdaPopulationIncArr = array();
219 $mainQrdaPopulationIncArr['init_patients'] = "IPP";
220 $mainQrdaPopulationIncArr['exclude_patients'] = "DENEX";
221 $mainQrdaPopulationIncArr['denom_patients'] = "DENOM";
222 $mainQrdaPopulationIncArr['numer_patients'] = "NUMER";
223 $mainQrdaPopulationIncArr['exception_patients'] = "DENEXCEP";
224 $mainQrdaPopulationIncArr['measure_population'] = "MSRPOPL";
225 $mainQrdaPopulationIncArr['numer_exclusion'] = "NUMEX";
228 $mainQrdaGenderCodeArr = array();
229 $mainQrdaGenderCodeArr['F'] = "Female";
230 $mainQrdaGenderCodeArr['M'] = "Male";
231 $mainQrdaGenderCodeArr['UN'] = "Unknown";
233 //QRDA Needed Payer Info
234 $mainQrdaPayerCodeArr = array();
235 $mainQrdaPayerCodeArr['A'] = "Medicare";
236 $mainQrdaPayerCodeArr['B'] = "Medicaid";
237 $mainQrdaPayerCodeArr['C'] = "Private Health Insurance";
238 $mainQrdaPayerCodeArr['D'] = "Other";
240 //Payer Codes According to Cypress Codes
241 $mainQrdaPayerCodeSendArr = array();
242 $mainQrdaPayerCodeSendArr['A'] = "1";
243 $mainQrdaPayerCodeSendArr['B'] = "2";
244 $mainQrdaPayerCodeSendArr['C'] = "5";
245 $mainQrdaPayerCodeSendArr['D'] = "349";
248 $form_provider = $_GET['form_provider'];
250 //Get Report Information
251 $report_id = $_GET['report_id'];
252 $report_view = collectReportDatabase($report_id);
253 $target_date = $report_view['date_target'];
254 $dataSheet = json_decode($report_view['data'], true);
256 //Needed array for Rule NQF#0024 Stratification
257 $stratumCheckArr = array();
258 if (count($dataSheet) > 0) {
260 foreach ($dataSheet as $row) {
261 $itemized_test_id = $row['itemized_test_id'];
262 $numerator_label = $row['numerator_label'];
263 if ($row['cqm_nqf_code'] == "0024") {
264 if ($row['population_label'] == "Population Criteria 2") {
265 if ($row['numerator_label'] == "Numerator 1") {
266 $stratum_1_ipp = $row['initial_population'];
267 $stratum_1_exclude = $row['excluded'];
268 $stratum_1_denom = $row['pass_filter'];
269 $stratum_1_numer1 = $row['pass_target'];
270 } else if ($row['numerator_label'] == "Numerator 2") {
271 $stratum_1_numer2 = $row['pass_target'];
272 } else if ($row['numerator_label'] == "Numerator 3") {
273 $stratum_1_numer3 = $row['pass_target'];
275 } else if ($row['population_label'] == "Population Criteria 3") {
276 if ($row['numerator_label'] == "Numerator 1") {
277 $stratum_2_ipp = $row['initial_population'];
278 $stratum_2_exclude = $row['excluded'];
279 $stratum_2_denom = $row['pass_filter'];
280 $stratum_2_numer1 = $row['pass_target'];
281 } else if ($row['numerator_label'] == "Numerator 2") {
282 $stratum_2_numer2 = $row['pass_target'];
283 } else if ($row['numerator_label'] == "Numerator 3") {
284 $stratum_2_numer3 = $row['pass_target'];
290 $stratum[1] = array('init_patients' => $stratum_1_ipp,
291 'exclude_patients' => $stratum_1_exclude,
292 'denom_patients' => $stratum_1_denom,
293 'numer_patients' => $stratum_1_numer1,
294 'numer2' => $stratum_1_numer2,
295 'numer3' => $stratum_1_numer3);
297 $stratum[2] = array('init_patients' => $stratum_2_ipp,
298 'exclude_patients' => $stratum_2_exclude,
299 'denom_patients' => $stratum_2_denom,
300 'numer_patients' => $stratum_2_numer1,
301 'numer2' => $stratum_2_numer2,
302 'numer3' => $stratum_2_numer3);
306 $from_date = date('Y', strtotime($target_date))."-01-01";
307 $to_date = date('Y', strtotime($target_date))."-12-31";
308 $xml = new QRDAXml();
310 #################################################################################################
311 ####################### HEADER ELEMENTS START #####################################################
312 #################################################################################################
313 //Open Main Clinical Document
314 $xml->open_clinicaldocument();
316 $xml->self_realmcode();
320 $tempId = '2.16.840.1.113883.10.20.27.1.1';
321 $xml->self_templateid($tempId);
323 $xml->unique_id
= getUuid();
327 //Main Title Display to XML
328 $main_title = "QRDA Calculated Summary Report";
329 $xml->add_title($main_title);
331 //Effective date and time
332 $eff_datetime = date('Ymdhis', strtotime($target_date));
333 $xml->self_efftime($eff_datetime);
335 $xml->self_confidentcode();
340 $setidVal =getUuid();
341 $xml->self_setid($setidVal);
344 $xml->self_version();
346 //Record Target Elements
347 $xml->open_recordTarget();
348 $xml->add_patientRole();
349 $xml->close_recordTarget();
351 ############### Author Info #######################
354 $auth_dtime = date('Ymdhis', strtotime(date('Y-m-d H:i:s')));
355 $xml->self_authorTime($auth_dtime);
357 $xml->open_assignAuthor();
358 $authorsetid = getUuid();
359 $xml->self_customId($authorsetid);
360 if ($form_provider != "") {
361 $userRow = sqlQuery("SELECT facility, facility_id, federaltaxid, npi, phone,fname, lname FROM users WHERE id=?", array($form_provider));
362 $facility_name = $userRow['facility'];
363 $facility_id = $userRow['facility_id'];
366 //$xml->self_customTag('telecom', array('value' => $userRow['phone'], 'use'=>'WP'));
368 //assignedAuthoringDevice Start
369 $xml->open_customTag('assignedAuthoringDevice');
371 $xml->element('softwareName', 'CYPRESS');
373 //assignedAuthoringDevice Close
374 $xml->close_customTag();
377 $facilResRow = $facilityService->getById($facility_id);
378 $xml->add_authReprestOrginisation($facilResRow);
379 //$xml->add_facilAddress($facilResRow);
380 $xml->close_assignAuthor();
381 $xml->close_author();
383 ############### Custodian Info #######################
384 $xml->open_custodian();
385 $xml->open_assgnCustodian();
386 $xml->add_represtCustodianOrginisation($facilResRow);
387 $xml->close_assgnCustodian();
388 $xml->close_custodian();
391 ############### Information Recipient #######################
392 $xml->open_infoRecipient();
393 $xml->add_indententRecipient();
394 $xml->close_infoRecipient();
397 ############### Legal Authenticator #######################
398 $xml->open_legalAuthenticator();
399 $auth_dtime = date('Ymdhis', strtotime(date('Y-m-d H:i:s')));
400 $xml->self_authorTime($auth_dtime);
401 $xml->self_legalSignCode();
403 $xml->open_assignedEntity();
404 $assignedEntityId = getUuid();
405 $xml->self_customId($assignedEntityId);
407 $xml->open_customTag('assignedPerson');
410 $userNameArr = array('fname' =>$userRow['fname'], 'lname'=>$userRow['lname']);
411 $xml->add_providerName($userNameArr);
413 //assignedPerson Close
414 $xml->close_customTag();
416 //Represent Origination Name
417 $xml->add_authReprestOrginisation($facilResRow);
418 $xml->close_assignedEntity();
420 $xml->close_legalAuthenticator();
423 ############### Participant is Device(optional) #######################
424 $participentDevArr = array();
425 $xml->open_participant_data('DEV');//DEV -- Device
426 $xml->open_assocEntityData('RGPR');//RGPR -- Regulated Product
427 $participentDevArr['root'] = '2.16.840.1.113883.3.2074.1';
428 $participentDevArr['extension'] = '1a2b3c';
429 $xml->self_particpantIdInfo($participentDevArr);
430 $xml->self_participantCodeDevice();
431 $xml->close_assocEntityData();
432 $xml->close_participant_data();
434 ############### Participant is Location(optional) #######################
435 $participentLocArr = array();
436 $xml->open_participant_data('LOC');//LOC -- Location
437 $xml->open_assocEntityData('SDLOC');//SDLOC -- Service Delivery Location
438 $participentLocArr['root'] = '2.16.840.1.113883.3.249.5.1';
439 $participentLocArr['extension'] = 'OK666333';
440 $xml->self_particpantIdInfo($participentLocArr);
441 $xml->self_participantCodeLocation();
443 $xml->add_facilAddress($facilResRow);
444 $xml->close_assocEntityData();
445 $xml->close_participant_data();
448 ############### documentationOf START #######################
449 $xml->open_customTag('documentationOf');
451 $xml->open_customTag('serviceEvent', array('classCode'=>'PCPR'));
453 $timeArr = array('low'=>date('Ymd', strtotime($from_date)), 'high'=>date('Ymd', strtotime($to_date)));
454 $xml->add_entryEffectTime($timeArr);
456 $xml->open_customTag('performer', array('typeCode'=>'PRF'));
458 $xml->open_customTag('assignedEntity');
460 $npi_provider = !empty($userRow['npi']) ?
$userRow['npi'] : '123456789';
461 $xml->self_customTag('id', array('root' => '2.16.840.1.113883.4.6', 'extension' =>$npi_provider));
463 if ($userRow['phone'] != "") {
464 $xml->self_customTag('telecom', array('value' => $userRow['phone'], 'use'=>'WP'));
467 $xml->open_customTag('assignedPerson');
470 $userNameArr = array('fname' =>$userRow['fname'], 'lname'=>$userRow['lname']);
471 $xml->add_providerName($userNameArr);
473 //assignedPerson Close
474 $xml->close_customTag();
476 $xml->open_customTag('representedOrganization');
478 $tin_provider = $userRow['federaltaxid'];
479 if ($tin_provider != "") {
480 $xml->self_customTag('id', array('root' => '2.16.840.1.113883.4.2', 'extension' =>$tin_provider));
483 $xml->add_facilName($facility_name);
485 $xml->add_facilAddress($facilResRow);
487 //representedOrganization Close
488 $xml->close_customTag();
490 //assignedEntity Close
491 $xml->close_customTag();
494 $xml->close_customTag();
497 $xml->close_customTag();
499 //documentationOf Close
500 $xml->close_customTag();
501 ############### documentationOf END #######################
504 ############### authorization (optional) #########################
506 #################################################################################################
507 ####################### HEADER ELEMENTS END #####################################################
508 #################################################################################################
512 #################################################################################################
513 ######################### Main Component Open ###################################################
514 $xml->open_mainComponent();
516 ############### Structure Body Open #######################
517 $xml->open_structuredBody();
519 ##################### LOOP Component(s) START ########################
521 ###################### Report Parameters Open #####################
522 //QRDA Category III Reporting Parameters Section (CMS EP) [section: templateId 2.16.840.1.113883.10.20.27.2.6
523 $xml->open_loopComponent();
525 $xml->open_section();
527 $tempID = '2.16.840.1.113883.10.20.17.2.1';
528 $xml->self_templateid($tempID);
530 $tempID = '2.16.840.1.113883.10.20.27.2.2';
531 $xml->self_templateid($tempID);
533 $tempID = '2.16.840.1.113883.10.20.27.2.6';
534 $xml->self_templateid($tempID);
535 $arr = array('code'=>'55187-9', 'codeSystem'=>'2.16.840.1.113883.6.1');
536 $xml->self_codeCustom($arr);
537 $title = "Reporting Parameters";
538 $xml->add_title($title);
542 $item_title = "Reporting period: ".date('d M Y', strtotime($from_date))." - ".date('d M Y', strtotime($to_date));
543 $xml->add_item($item_title);
548 $xml->open_entry($typeCode);
549 $arr = array('classCode'=>'ACT', 'moodCode'=>'EVN');
550 $xml->open_act($arr);
552 $tempID = '2.16.840.1.113883.10.20.17.3.8';
553 $xml->self_templateid($tempID);
555 $tempID = '2.16.840.1.113883.10.20.27.3.23';
556 $xml->self_templateid($tempID);
559 $xml->self_customId($actId);
561 $arr = array('code'=>'252116004', 'codeSystem'=>'2.16.840.1.113883.6.96', 'displayName'=>'Observation Parameters');
562 $xml->self_codeCustom($arr);
564 $timeArr = array('low'=>date('Ymd', strtotime($from_date)), 'high'=>date('Ymd', strtotime($to_date)));
565 $xml->add_entryEffectTime($timeArr);
570 $xml->close_section();
572 $xml->close_loopComponent();
573 ###################### Report Parameters Close #####################
575 ###################### Measure Section Open #####################
576 $xml->open_loopComponent();
578 $xml->open_section();
580 $tempID = '2.16.840.1.113883.10.20.27.2.1';
581 $xml->self_templateid($tempID);
583 $tempID = '2.16.840.1.113883.10.20.24.2.2';
584 $xml->self_templateid($tempID);
586 $tempID = '2.16.840.1.113883.10.20.27.2.3';
587 $xml->self_templateid($tempID);
589 $arr = array('code'=>'55186-1', 'codeSystem'=>'2.16.840.1.113883.6.1');
590 $xml->self_codeCustom($arr);
591 $title = "Measure Section";
592 $xml->add_title($title);
597 $tabArr = array('border'=>1, 'width'=>'100%');
598 if (count($dataSheet) > 0) {
599 $uniqIdArr = array();
602 foreach ($dataSheet as $row) {
603 $itemized_test_id = $row['itemized_test_id'];
604 $numerator_label = $row['numerator_label'];
606 //CQM Rules 2014 set, 0013 is 0018
607 if ($row['cqm_nqf_code'] == "0013") {
608 $row['cqm_nqf_code'] = "0018";
612 $xml->open_customTag('table', $tabArr);
614 $xml->open_customTag('thead');
616 $xml->open_customTag('tr');
618 $xml->add_trElementsTitles();
621 $xml->close_customTag();
624 $xml->close_customTag();
626 $xml->open_customTag('tbody');
627 $xml->open_customTag('tr');
629 $tdTitle = generate_display_field(array('data_type'=>'1','list_id'=>'clinical_rules'), $row['id']);
631 if (!empty($row['cqm_pqri_code'])) {
632 $tdTitle .= " " . htmlspecialchars(xl('PQRI') . ":" . $row['cqm_pqri_code'], ENT_NOQUOTES
) . " ";
635 if (!empty($row['cqm_nqf_code'])) {
636 $tdTitle .= " " . htmlspecialchars(xl('NQF') . ":" . $row['cqm_nqf_code'], ENT_NOQUOTES
) . " ";
639 if (!(empty($row['concatenated_label']))) {
640 $tdTitle .= ", " . htmlspecialchars(xl($row['concatenated_label']), ENT_NOQUOTES
) . " ";
643 $tdVersionNeutral = getUuid();
645 if ($preDefinedUniqIDRules[$row['cqm_nqf_code']] != "") {
646 if (($row['cqm_nqf_code'] == "0421" )) {
647 $tdVersionSpecific = $preDefinedUniqIDRules[$row['cqm_nqf_code']][$row['numerator_label']];
648 } else if ($row['cqm_nqf_code'] == "0024") {
649 $tdVersionSpecific = $preDefinedUniqIDRules[$row['cqm_nqf_code']][$row['population_label']][$row['numerator_label']];
651 $tdVersionSpecific = $preDefinedUniqIDRules[$row['cqm_nqf_code']];
654 $uniqIdArr[] = $tdVersionSpecific;
656 $tdVersionSpecific = getUuid();
657 $uniqIdArr[] = $tdVersionSpecific;
660 $dataArr = array(0=>$tdTitle, 1=>$tdVersionNeutral, 2=>$tdVersionSpecific);
661 $xml->add_trElementsValues($dataArr);
664 $xml->close_customTag();
666 $xml->close_customTag();
668 $xml->close_customTag();
670 //Open List Item Wise
674 $xml->open_customTag('item');
675 $arrContent = array('name'=>'Performance Rate', 'value'=>$row['percentage']);
676 $xml->innerContent($arrContent);
677 $xml->close_customTag();
680 //All CQM Measures taken here
681 foreach ($CQMeausesArr as $cqmKey => $cqmVal) {
682 //DENEXCEP(Denominator Exception not needed for some rules are skipping here)
683 if ((in_array($row['cqm_nqf_code'], $denExcepNotNeedRules) ) && ($cqmKey == "exception_patients")) {
688 if ($cqmKey == "init_patients") {
689 $itemPatArr = collectItemizedPatientsCdrReport($report_id, $itemized_test_id, $cqmItemizedArr[$cqmKey]);
691 $itemPatArr = collectItemizedPatientsCdrReport($report_id, $itemized_test_id, $cqmItemizedArr[$cqmKey], $numerator_label);
694 $fullPatArr = array();
695 foreach ($itemPatArr as $itemPatInfo) {
696 $fullPatArr[] = $itemPatInfo['pid'];
699 //Initial Patient Population
700 $xml->open_customTag('item');
701 $arrContent = array('name'=>$cqmVal, 'value'=>count($fullPatArr));
702 $xml->innerContent($arrContent);
704 $detailsArr = getQRDAPatientNeedInfo($fullPatArr);
709 //Gender Section Display
710 foreach ($mainQrdaGenderCodeArr as $GKey => $GVal) {
711 $xml->open_customTag('item');
712 $genderInfo = $detailsArr['gender'][$GVal];
713 $arrContent = array('name'=>$GVal, 'value'=>$genderInfo);
714 $xml->innerContent($arrContent);
715 $xml->close_customTag();
718 //Ethnicity Section Display
719 foreach ($mainEthiArr as $ethKey => $ethVal) {
720 $ethnicity_data = $detailsArr['ethnicity'][$ethVal];
721 $xml->open_customTag('item');
722 $arrContent = array('name'=>'Ethnicity - '.$ethVal, 'value'=>$ethnicity_data);
723 $xml->innerContent($arrContent);
724 $xml->close_customTag();
727 //Race Section Display
728 foreach ($mainQrdaRaceArr as $RKey => $RVal) {
729 $race_data = $detailsArr['race'][$RVal];
730 $xml->open_customTag('item');
731 $arrContent = array('name'=>'Race - '.$RVal, 'value'=>$race_data);
732 $xml->innerContent($arrContent);
733 $xml->close_customTag();
736 //Payer Type Section Display
737 $payerCheckArr = getQRDAPayerInfo($fullPatArr);
738 foreach ($mainQrdaPayerCodeArr as $PKey => $PVal) {
739 $xml->open_customTag('item');
740 $arrContent = array('name'=>'Payer - '.$PVal, 'value'=>$payerCheckArr[$PVal]);
741 $xml->innerContent($arrContent);
742 $xml->close_customTag();
747 $xml->close_customTag();
756 #######################################################################
757 ######################### QUALITY MEASURES START ######################
758 #######################################################################
759 if (count($dataSheet) > 0) {
761 $skipMultNumArr = array();
762 $dataChkArr = array();
763 foreach ($multNumNQFArr as $multNumVal) {
764 $skipMultNumArr[$multNumVal] = false;
765 $dataChkArr[$multNumVal] = 0;
769 foreach ($dataSheet as $row) {
770 $itemized_test_id = $row['itemized_test_id'];
771 $numerator_label = $row['numerator_label'];
773 //if($row['cqm_nqf_code'] == "0028a") continue;
775 //if($row['cqm_nqf_code'] == "0038"){
776 // if(in_array($row['numerator_label'], $NQF38NumArr)) continue;
779 if (in_array($row['cqm_nqf_code'], $multNumNQFArr)) {
780 $dataChkArr[$row['cqm_nqf_code']]++
;
783 //CQM Rules 2014 set, 0013 is 0018
784 if ($row['cqm_nqf_code'] == "0013") {
785 $row['cqm_nqf_code'] = "0018";
788 $tdTitle = generate_display_field(array('data_type'=>'1','list_id'=>'clinical_rules'), $row['id']);
789 if (!empty($row['cqm_pqri_code'])) {
790 $tdTitle .= " " . text(xl('PQRI') . ":" . $row['cqm_pqri_code']) . " ";
793 if (!empty($row['cqm_nqf_code'])) {
794 $tdTitle .= " " . text(xl('NQF') . ":" . $row['cqm_nqf_code']) . " ";
797 if (!(empty($row['concatenated_label']))) {
798 $tdTitle .= ", " . text(xl($row['concatenated_label'])) . " ";
801 ###########################################################
802 if (( !isset($skipMultNumArr[$row['cqm_nqf_code']]) ) ||
($skipMultNumArr[$row['cqm_nqf_code']] == false)) {
807 $arr = array('classCode'=>'CLUSTER', 'moodCode'=>'EVN');
808 $xml->open_customTag('organizer', $arr);
810 $tempID = "2.16.840.1.113883.10.20.24.3.98";
811 $xml->self_templateid($tempID);
813 $tempID = "2.16.840.1.113883.10.20.27.3.1";
814 $xml->self_templateid($tempID);
816 //$tempID = "2.16.840.1.113883.10.20.27.3.17";
817 //$xml->self_templateid($tempID);
819 $xml->self_customId($actId);
821 $arr = array('code'=>'completed');
822 $xml->self_customTag('statusCode', $arr);
825 $arr = array('typeCode'=>'REFR');
826 $xml->open_customTag('reference', $arr);
828 //externalDocument Start
829 $arr = array('classCode'=>'DOC', 'moodCode'=>'EVN');
830 $xml->open_customTag('externalDocument', $arr);
832 //$exDocID = getUuid();
833 $exDocID = $uniqIdArr[$innrCnt];
834 //$xml->self_customId($exDocID);
835 $xml->self_customTag('id', array('root' => '2.16.840.1.113883.4.738', 'extension' =>$exDocID));
837 $arr = array('code'=>'57024-2', 'displayName'=>'Health Quality Measure Document', 'codeSystem'=>'2.16.840.1.113883.6.1', 'codeSystemName'=>'LOINC');
838 $xml->self_codeCustom($arr);
840 $dispContntTitle = str_replace("&", '', $tdTitle);
841 $xml->textDispContent($dispContntTitle);
843 //externalDocument Close
844 $xml->close_customTag();
847 $xml->close_customTag();
850 ############### Performance Rate for Proportion Measure template START###################
851 $xml->open_loopComponent();
854 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
856 $tempID = "2.16.840.1.113883.10.20.27.3.14";
857 $xml->self_templateid($tempID);
859 $tempID = "2.16.840.1.113883.10.20.27.3.25";
860 $xml->self_templateid($tempID);
862 $arr = array('code'=>'72510-1', 'displayName'=>'Performance Rate', 'codeSystem'=>'2.16.840.1.113883.6.1', 'codeSystemName'=>'SNOMED-CT');
863 $xml->self_codeCustom($arr);
865 $arr = array('code'=>'completed');
866 $xml->self_customTag('statusCode', $arr);
868 $percentage = str_replace("%", '', $row['percentage']);
869 $arr = array('xsi:type'=>'REAL', 'value'=>$percentage/100);
870 $xml->self_customTag('value', $arr);
873 $arr = array('typeCode'=>'REFR');
874 $xml->open_customTag('reference', $arr);
876 //externalObservation Start
877 $arr = array('classCode'=>'OBS', 'moodCode'=>'EVN');
878 $xml->open_customTag('externalObservation', $arr);
881 //$exDocID = getUuid();
884 if (($row['cqm_nqf_code'] == "0421" )) {
885 $exDocID = $preDefPopIdArr[$row['cqm_nqf_code']][$row['numerator_label']]["NUMER"];
886 } else if (($row['cqm_nqf_code'] == "0024")) {
887 $exDocID = $preDefPopIdArr[$row['cqm_nqf_code']][$row['population_label']][$row['numerator_label']]["NUMER"];
889 if ($preDefPopIdArr[$row['cqm_nqf_code']]["NUMER"] != "") {
890 $exDocID = $preDefPopIdArr[$row['cqm_nqf_code']]["NUMER"];
892 $exDocID = getUuid();
896 $xml->self_customId($exDocID);
898 $arr = array('code'=>'NUMER', 'displayName'=>'Numerator', 'codeSystem'=>'2.16.840.1.113883.5.1063', 'codeSystemName'=>'ObservationValue');
899 $xml->self_codeCustom($arr);
901 //externalObservation Close
902 $xml->close_customTag();
905 $xml->close_customTag();
908 $xml->close_customTag();
910 $xml->close_loopComponent();
911 ############### Performance Rate for Proportion Measure template END ###################
914 //All CQM Measures taken here
915 foreach ($CQMeausesArr as $cqmKey => $cqmVal) {
916 //DENEXCEP(Denominator Exception not needed for some rules are skipping here)
917 if ((in_array($row['cqm_nqf_code'], $denExcepNotNeedRules) ) && ($cqmKey == "exception_patients")) {
921 //cqm 0024 alllowing only nuemerator 2 and numerator 3 for ipp1,ipp2 and 1pp3 to avoid repeatation
922 if ($row['cqm_nqf_code'] == '0024' && ($row['numerator_label'] == "Numerator 2" ||
$row['numerator_label'] == "Numerator 3") && $cqmKey != 'numer_patients') {
926 if ($row['cqm_nqf_code'] == '0024' && ($row['population_label'] == "Population Criteria 2" ||
$row['population_label'] == "Population Criteria 3")) {
932 if ($cqmKey == "init_patients") {
933 $itemPatArr = collectItemizedPatientsCdrReport($report_id, $itemized_test_id, $cqmItemizedArr[$cqmKey]);
935 $itemPatArr = collectItemizedPatientsCdrReport($report_id, $itemized_test_id, $cqmItemizedArr[$cqmKey], $numerator_label);
938 $fullPatArr = array();
939 foreach ($itemPatArr as $itemPatInfo) {
940 $fullPatArr[] = $itemPatInfo['pid'];
943 $detailsArr = getQRDAPatientNeedInfo($fullPatArr);
944 ############### Initial patient population template START###################
945 $xml->open_loopComponent();
948 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
950 $tempID = "2.16.840.1.113883.10.20.27.3.5";
951 $xml->self_templateid($tempID);
953 $tempID = "2.16.840.1.113883.10.20.27.3.16";
954 $xml->self_templateid($tempID);
956 $arr = array('code'=>'ASSERTION', 'displayName'=>'Assertion', 'codeSystem'=>'2.16.840.1.113883.5.4', 'codeSystemName'=>'ActCode');
957 $xml->self_codeCustom($arr);
959 $arr = array('code'=>'completed');
960 $xml->self_customTag('statusCode', $arr);
962 $arr = array('xsi:type'=>'CD', 'code'=>$mainQrdaPopulationIncArr[$cqmKey], 'displayName'=>$cqmVal, 'codeSystem' =>'2.16.840.1.113883.5.1063', 'codeSystemName'=>'ObservationValue');
963 $xml->self_customTag('value', $arr);
965 //entryRelationship Open
966 $xml->open_customTag('entryRelationship', array('typeCode'=>'SUBJ', 'inversionInd'=>'true'));
969 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
971 $tempID = "2.16.840.1.113883.10.20.27.3.3";
972 $xml->self_templateid($tempID);
974 $tempID = "2.16.840.1.113883.10.20.27.3.24";
975 $xml->self_templateid($tempID);
977 $arr = array('code'=>'MSRAGG', 'displayName'=>'rate aggregation', 'codeSystem'=>'2.16.840.1.113883.5.4', 'codeSystemName'=>'ActCode');
978 $xml->self_codeCustom($arr);
980 //$arr = array('code'=>'completed');
981 //$xml->self_customTag('statusCode', $arr);
983 $arr = array('xsi:type'=>'INT', 'value'=>count($fullPatArr));
984 $xml->self_customTag('value', $arr);
986 $arr = array('code'=>'COUNT', 'displayName'=>'Count', 'codeSystem'=>'2.16.840.1.113883.5.84', 'codeSystemName'=>'ObservationMethod');
987 $xml->self_customTag('methodCode', $arr);
990 $xml->close_customTag();
992 //entryRelationship Close
993 $xml->close_customTag();
995 #### Stratum Start (Stratification)#####
996 if ($row['cqm_nqf_code'] == '0024') {
998 for (; $strat_count <= 2; $strat_count++
) {
999 $strata_value = $stratum[$strat_count][$cqmKey];
1001 if ($row['numerator_label'] == "Numerator 2") {
1002 $strata_value = $stratum[$strat_count]['numer2'];
1003 } else if ($row['numerator_label'] == "Numerator 3") {
1004 $strata_value = $stratum[$strat_count]['numer3'];
1007 //entryRelationship Open
1008 $xml->open_customTag('entryRelationship', array('typeCode'=>'COMP'));
1011 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
1013 $tempID = "2.16.840.1.113883.10.20.27.3.4";
1014 $xml->self_templateid($tempID);
1016 $tempID = "2.16.840.1.113883.10.20.27.3.20";
1017 $xml->self_templateid($tempID);
1019 $arr = array('code'=>'ASSERTION', 'displayName'=>'Assertion', 'codeSystem'=>'2.16.840.1.113883.5.4', 'codeSystemName'=>'ActCode');
1020 $xml->self_codeCustom($arr);
1022 $arr = array('code'=>'completed');
1023 $xml->self_customTag('statusCode', $arr);
1026 $xml->open_customTag('value', array('xsi:type'=>'CD', 'nullFlavor'=>'OTH'));
1028 $stratumText = $preDefPopIdArr[$row['cqm_nqf_code']][$row['population_label']][$row['numerator_label']]['DISPLAY_TEXT'];
1029 $xml->element('originalText', "Stratum ".$strat_count);
1032 $xml->close_customTag();
1034 //entryRelationship Open
1035 $xml->open_customTag('entryRelationship', array('typeCode'=>'SUBJ', 'inversionInd' => 'true'));
1038 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
1040 $tempID = "2.16.840.1.113883.10.20.27.3.3";
1041 $xml->self_templateid($tempID);
1043 $arr = array('code'=>'MSRAGG', 'displayName'=>'rate aggregation', 'codeSystem'=>'2.16.840.1.113883.5.4', 'codeSystemName'=>'ActCode');
1044 $xml->self_codeCustom($arr);
1046 $arr = array('xsi:type'=>'INT', 'value'=>$strata_value);
1047 $xml->self_customTag('value', $arr);
1049 $arr = array('code'=>'COUNT', 'displayName'=>'Count', 'codeSystem'=>'2.16.840.1.113883.5.84', 'codeSystemName'=>'ObservationMethod');
1050 $xml->self_customTag('methodCode', $arr);
1053 $xml->close_customTag();
1055 //entryRelationship Close
1056 $xml->close_customTag();
1059 $arr = array('typeCode'=>'REFR');
1060 $xml->open_customTag('reference', $arr);
1062 //externalObservation Start
1063 $arr = array('classCode'=>'OBS', 'moodCode'=>'EVN');
1064 $xml->open_customTag('externalObservation', $arr);
1066 //Modified HQMF_ID for CQM IDS
1067 //$refID = $preDefPopIdArr[$row['cqm_nqf_code']][$row['population_label']][$row['numerator_label']]['STRAT'];
1068 $refID = $preDefPopIdArr[$row['cqm_nqf_code']]['STRAT'.$strat_count];
1070 $xml->self_customId($refID);
1072 //externalObservation Close
1073 $xml->close_customTag();
1076 $xml->close_customTag();
1079 $xml->close_customTag();
1081 //entryRelationship Close
1082 $xml->close_customTag();
1086 #### Stratum END #####
1088 ####################################################
1089 ####################################################
1090 //Sex Supplemental Data Element START
1091 ####################################################
1092 ####################################################
1094 foreach ($mainQrdaGenderCodeArr as $GKey => $GVal) {
1095 //entryRelationship Open
1096 $xml->open_customTag('entryRelationship', array('typeCode'=>'COMP'));
1099 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
1101 $tempID = "2.16.840.1.113883.10.20.27.3.6";
1102 $xml->self_templateid($tempID);
1104 $tempID = "2.16.840.1.113883.10.20.27.3.21";
1105 $xml->self_templateid($tempID);
1107 $arr = array('code'=>'184100006', 'displayName'=>'patient sex', 'codeSystem'=>'2.16.840.1.113883.6.96', 'codeSystemName'=>'SNOMED-CT');
1108 $xml->self_codeCustom($arr);
1110 $arr = array('code'=>'completed');
1111 $xml->self_customTag('statusCode', $arr);
1113 $arr = array('xsi:type'=>'CD', 'code'=>$GKey, 'codeSystem' =>'2.16.840.1.113883.5.1', 'codeSystemName'=>'AdministrativeGenderCode');
1114 $xml->self_customTag('value', $arr);
1116 //entryRelationship Open
1117 $xml->open_customTag('entryRelationship', array('typeCode'=>'SUBJ', 'inversionInd'=>'true'));
1120 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
1122 $tempID = "2.16.840.1.113883.10.20.27.3.3";
1123 $xml->self_templateid($tempID);
1125 $tempID = "2.16.840.1.113883.10.20.27.3.24";
1126 $xml->self_templateid($tempID);
1128 $arr = array('code'=>'MSRAGG', 'displayName'=>'rate aggregation', 'codeSystem'=>'2.16.840.1.113883.5.4', 'codeSystemName'=>'ActCode');
1129 $xml->self_codeCustom($arr);
1131 //$arr = array('code'=>'completed');
1132 //$xml->self_customTag('statusCode', $arr);
1134 $arr = array('xsi:type'=>'INT', 'value'=>$detailsArr['gender'][$GVal]);
1135 $xml->self_customTag('value', $arr);
1137 $arr = array('code'=>'COUNT', 'displayName'=>'Count', 'codeSystem'=>'2.16.840.1.113883.5.84', 'codeSystemName'=>'ObservationMethod');
1138 $xml->self_customTag('methodCode', $arr);
1141 $xml->close_customTag();
1143 //entryRelationship Close
1144 $xml->close_customTag();
1148 $xml->close_customTag();
1150 //entryRelationship Close
1151 $xml->close_customTag();
1154 ####################################################
1155 ####################################################
1156 //Sex Supplemental Data Element END
1157 ####################################################
1158 ####################################################
1160 ####################################################
1161 ####################################################
1162 //Ethnicity Supplemental Data Element (CMS EP) START
1163 ####################################################
1164 ####################################################
1166 foreach ($mainEthiArr as $ethKey => $ethVal) {
1167 //entryRelationship Open
1168 $xml->open_customTag('entryRelationship', array('typeCode'=>'COMP'));
1171 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
1173 $tempID = "2.16.840.1.113883.10.20.27.3.7";
1174 $xml->self_templateid($tempID);
1176 $tempID = "2.16.840.1.113883.10.20.27.3.22";
1177 $xml->self_templateid($tempID);
1179 $arr = array('code'=>'364699009', 'displayName'=>'Ethnic Group', 'codeSystem'=>'2.16.840.1.113883.6.96', 'codeSystemName'=>'SNOMED-CT');
1180 $xml->self_codeCustom($arr);
1182 $arr = array('code'=>'completed');
1183 $xml->self_customTag('statusCode', $arr);
1185 $arr = array('xsi:type'=>'CD', 'code'=>$mainEthiCodeArr[$ethKey], 'displayName'=>$ethVal, 'codeSystem' =>'2.16.840.1.113883.6.238', 'codeSystemName'=>'Race & Ethnicity - CDC');
1186 $xml->self_customTag('value', $arr);
1188 //entryRelationship Open
1189 $xml->open_customTag('entryRelationship', array('typeCode'=>'SUBJ', 'inversionInd'=>'true'));
1192 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
1194 $tempID = "2.16.840.1.113883.10.20.27.3.3";
1195 $xml->self_templateid($tempID);
1197 $tempID = "2.16.840.1.113883.10.20.27.3.24";
1198 $xml->self_templateid($tempID);
1200 $arr = array('code'=>'MSRAGG', 'displayName'=>'rate aggregation', 'codeSystem'=>'2.16.840.1.113883.5.4', 'codeSystemName'=>'ActCode');
1201 $xml->self_codeCustom($arr);
1203 //$arr = array('code'=>'completed');
1204 //$xml->self_customTag('statusCode', $arr);
1206 $arr = array('xsi:type'=>'INT', 'value'=>$detailsArr['ethnicity'][$ethVal]);
1207 $xml->self_customTag('value', $arr);
1209 $arr = array('code'=>'COUNT', 'displayName'=>'Count', 'codeSystem'=>'2.16.840.1.113883.5.84', 'codeSystemName'=>'ObservationMethod');
1210 $xml->self_customTag('methodCode', $arr);
1213 $xml->close_customTag();
1215 //entryRelationship Close
1216 $xml->close_customTag();
1220 $xml->close_customTag();
1222 //entryRelationship Close
1223 $xml->close_customTag();
1226 ####################################################
1227 ####################################################
1228 //Ethnicity Supplemental Data Element (CMS EP) END
1229 ####################################################
1230 ####################################################
1233 ####################################################
1234 ####################################################
1235 //Race Supplemental Data Element (CMS EP) START
1236 ####################################################
1237 ####################################################
1239 foreach ($mainQrdaRaceArr as $RKey => $RVal) {
1240 //entryRelationship Open
1241 $xml->open_customTag('entryRelationship', array('typeCode'=>'COMP'));
1244 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
1246 $tempID = "2.16.840.1.113883.10.20.27.3.8";
1247 $xml->self_templateid($tempID);
1249 $tempID = "2.16.840.1.113883.10.20.27.3.19";
1250 $xml->self_templateid($tempID);
1252 $arr = array('code'=>'103579009', 'displayName'=>'Race', 'codeSystem'=>'2.16.840.1.113883.6.96', 'codeSystemName'=>'SNOMED-CT');
1253 $xml->self_codeCustom($arr);
1255 $arr = array('code'=>'completed');
1256 $xml->self_customTag('statusCode', $arr);
1258 $arr = array('xsi:type'=>'CD', 'code'=>$mainQrdaRaceCodeArr[$RKey], 'displayName'=>$RVal, 'codeSystem' =>'2.16.840.1.113883.6.238', 'codeSystemName'=>'Race & Ethnicity - CDC');
1259 $xml->self_customTag('value', $arr);
1261 //entryRelationship Open
1262 $xml->open_customTag('entryRelationship', array('typeCode'=>'SUBJ', 'inversionInd'=>'true'));
1265 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
1267 $tempID = "2.16.840.1.113883.10.20.27.3.3";
1268 $xml->self_templateid($tempID);
1270 $tempID = "2.16.840.1.113883.10.20.27.3.24";
1271 $xml->self_templateid($tempID);
1273 $arr = array('code'=>'MSRAGG', 'displayName'=>'rate aggregation', 'codeSystem'=>'2.16.840.1.113883.5.4', 'codeSystemName'=>'ActCode');
1274 $xml->self_codeCustom($arr);
1276 //$arr = array('code'=>'completed');
1277 //$xml->self_customTag('statusCode', $arr);
1279 $arr = array('xsi:type'=>'INT', 'value'=>$detailsArr['race'][$RVal]);
1280 $xml->self_customTag('value', $arr);
1282 $arr = array('code'=>'COUNT', 'displayName'=>'Count', 'codeSystem'=>'2.16.840.1.113883.5.84', 'codeSystemName'=>'ObservationMethod');
1283 $xml->self_customTag('methodCode', $arr);
1286 $xml->close_customTag();
1288 //entryRelationship Close
1289 $xml->close_customTag();
1293 $xml->close_customTag();
1295 //entryRelationship Close
1296 $xml->close_customTag();
1299 ####################################################
1300 ####################################################
1301 //Race Supplemental Data Element (CMS EP) END
1302 ####################################################
1303 ####################################################
1306 ####################################################
1307 ####################################################
1308 //Payer Supplemental Data Element (CMS EP) START
1309 ####################################################
1310 ####################################################
1311 $payerCheckArr = getQRDAPayerInfo($fullPatArr);
1312 foreach ($mainQrdaPayerCodeArr as $PKey => $PVal) {
1313 //entryRelationship Open
1314 $xml->open_customTag('entryRelationship', array('typeCode'=>'COMP'));
1317 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
1319 $tempID = "2.16.840.1.113883.10.20.27.3.9";
1320 $xml->self_templateid($tempID);
1322 $tempID = "2.16.840.1.113883.10.20.24.3.55";
1323 $xml->self_templateid($tempID);
1325 $tempID = "2.16.840.1.113883.10.20.27.3.18";
1326 $xml->self_templateid($tempID);
1328 $xml->self_setpatientRoleid();
1330 $arr = array('code'=>'48768-6', 'displayName'=>'Payment source', 'codeSystem'=>'2.16.840.1.113883.6.1', 'codeSystemName'=>'SNOMED-CT');
1331 $xml->self_codeCustom($arr);
1333 $arr = array('code'=>'completed');
1334 $xml->self_customTag('statusCode', $arr);
1336 $timeArr = array('low'=>date('Ymd', strtotime($from_date)));
1337 $xml->add_entryEffectTime($timeArr);
1341 $xml->open_customTag('value', array('xsi:type'=>'CD', 'nullFlavor'=>'OTH'));
1343 $xml->self_customTag('translation', array('code'=>$PKey, 'displayName'=>$PVal, 'codeSystem'=>'2.16.840.1.113883.3.249.12', 'codeSystemName'=>'CMS Clinical Codes'));
1346 $xml->close_customTag();
1350 $xml->self_customTag('value', array('xsi:type'=>'CD', 'code'=>$mainQrdaPayerCodeSendArr[$PKey], 'codeSystem'=>'2.16.840.1.113883.3.221.5' , 'codeSystemName'=>'SOP', 'displayName'=>$PVal));
1352 //entryRelationship Open
1353 $xml->open_customTag('entryRelationship', array('typeCode'=>'SUBJ', 'inversionInd'=>'true'));
1356 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
1358 $tempID = "2.16.840.1.113883.10.20.27.3.3";
1359 $xml->self_templateid($tempID);
1361 $tempID = "2.16.840.1.113883.10.20.27.3.24";
1362 $xml->self_templateid($tempID);
1364 $arr = array('code'=>'MSRAGG', 'displayName'=>'rate aggregation', 'codeSystem'=>'2.16.840.1.113883.5.4', 'codeSystemName'=>'ActCode');
1365 $xml->self_codeCustom($arr);
1367 //$arr = array('code'=>'completed');
1368 //$xml->self_customTag('statusCode', $arr);
1370 $arr = array('xsi:type'=>'INT', 'value'=>$payerCheckArr[$PVal]);
1371 $xml->self_customTag('value', $arr);
1373 $arr = array('code'=>'COUNT', 'displayName'=>'Count', 'codeSystem'=>'2.16.840.1.113883.5.84', 'codeSystemName'=>'ObservationMethod');
1374 $xml->self_customTag('methodCode', $arr);
1377 $xml->close_customTag();
1379 //entryRelationship Close
1380 $xml->close_customTag();
1384 $xml->close_customTag();
1386 //entryRelationship Close
1387 $xml->close_customTag();
1390 ####################################################
1391 ####################################################
1392 //Payer Supplemental Data Element (CMS EP) END
1393 ####################################################
1394 ####################################################
1396 ######################################################################
1398 $arr = array('typeCode'=>'REFR');
1399 $xml->open_customTag('reference', $arr);
1401 //externalObservation Start
1402 $arr = array('classCode'=>'OBS', 'moodCode'=>'EVN');
1403 $xml->open_customTag('externalObservation', $arr);
1405 //Modified HQMF_ID for CQM IDS
1406 if (($row['cqm_nqf_code'] == "0421" )) {
1407 $refID = $preDefPopIdArr[$row['cqm_nqf_code']][$row['numerator_label']][$mainQrdaPopulationIncArr[$cqmKey]];
1408 } else if (($row['cqm_nqf_code'] == "0024")) {
1409 $refID = $preDefPopIdArr[$row['cqm_nqf_code']][$row['population_label']][$row['numerator_label']][$mainQrdaPopulationIncArr[$cqmKey]];
1411 $refID = $preDefPopIdArr[$row['cqm_nqf_code']][$mainQrdaPopulationIncArr[$cqmKey]];
1418 $xml->self_customId($refID);
1420 //externalObservation Close
1421 $xml->close_customTag();
1424 $xml->close_customTag();
1425 ########################################################################
1428 $xml->close_customTag();
1430 $xml->close_loopComponent();
1431 ############### Initial patient population template END#####################
1434 //Multiple Numerator Handling
1435 if (in_array($row['cqm_nqf_code'], $multNumNQFArr)) {
1436 //Skipping Multiple Numerator(s)
1437 if (in_array($row['cqm_nqf_code'], $multNumNQFArr)) {
1438 $skipMultNumArr[$row['cqm_nqf_code']] = true;
1441 if ($dataChkArr[$row['cqm_nqf_code']] == $countNumNQFArr[$row['cqm_nqf_code']]) {
1443 $xml->close_customTag();
1444 $xml->close_entry();
1448 $xml->close_customTag();
1449 $xml->close_entry();
1452 ###########################################################
1458 #######################################################################
1459 ######################### QUALITY MEASURES END ########################
1460 #######################################################################
1463 $xml->close_section();
1465 $xml->close_loopComponent();
1467 ##################### LOOP Component(s) END ########################
1469 $xml->close_structuredBody();
1470 ############### Structure Body Close #######################
1472 $xml->close_mainComponent();
1473 ############### Main Component Close #######################
1475 //Close Main Clinical Document
1476 $xml->close_clinicaldocument();
1479 //QRDA File Download Folder in site/cqm_qrda folder
1480 $qrda_fname = "QRDA_III_".date("YmdHis").".xml";
1481 $qrda_file_path = $GLOBALS['OE_SITE_DIR'] . "/documents/cqm_qrda/";
1482 if (!file_exists($qrda_file_path)) {
1483 mkdir($qrda_file_path, 0777, true);
1486 $qrda_file_name = $qrda_file_path.$qrda_fname;
1487 $fileQRDAOPen = fopen($qrda_file_name, "w");
1488 fwrite($fileQRDAOPen, trim($xml->getXml()));
1489 fclose($fileQRDAOPen);
1494 <?php
html_header_show();?
>
1495 <script type
="text/javascript" src
="<?php echo $webroot ?>/interface/main/tabs/js/include_opener.js"></script
>
1496 <link rel
=stylesheet href
="<?php echo $css_header;?>" type
="text/css">
1497 <title
><?php
echo xlt('Export QRDA Report'); ?
></title
>
1499 <script type
="text/javascript">
1501 function closeme() {
1508 <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
>
1513 <a href
="qrda_download.php?qrda_fname=<?php echo attr($qrda_fname);?>"><?php
echo xlt("Download QRDA Category III File");?
></a
>
1515 <textarea rows
='50' cols
='500' style
='width:95%' readonly
>
1516 <?php
echo trim($xml->getXml()); ?
>
1519 <p
><input type
='button' value
='<?php echo xla('Close
'); ?>' onclick
='closeme();' /></p
>