6 * Copyright (C) 2015 Ensoftek, Inc
8 * LICENSE: This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>;.
21 * @link http://www.open-emr.org
25 //SANITIZE ALL ESCAPES
26 $sanitize_all_escapes=true;
28 //STOP FAKE REGISTER GLOBALS
29 $fake_register_globals=false;
31 require_once("../interface/globals.php");
32 require_once("../ccr/uuid.php");
33 require_once("../library/patient.inc");
34 require_once "../library/options.inc.php";
35 require_once("../library/clinical_rules.php");
36 require_once("../library/classes/QRDAXml.class.php");
37 require_once "$srcdir/report_database.inc";
38 require_once("$srcdir/sanitize.inc.php");
39 require_once "qrda_functions.php";
41 //Remove time limit, since script can take many minutes
44 //DENEXCEP NOT NEEDED rules
45 $denExcepNotNeedRules = array('0002', '0018', '0024', '0038', '0043', '0059', '0421');
47 //Predefined QRDA HQMF ID's for CQM rules
48 $preDefinedUniqIDRules = array();
49 $preDefPopIdArr = array();
51 // CMS147v4/0041 - Preventive Care and Screening: Influenza Immunization HQMF ID: 40280381-4600-425F-0146-EE66F0005509
52 $preDefinedUniqIDRules['0041'] = '40280381-4600-425F-0146-EE66F0005509';
53 $preDefPopIdArr['0041']['IPP'] = 'F48702E6-D39A-49D8-BE3C-8FAB5C6AADDA';
54 $preDefPopIdArr['0041']['DENOM'] = 'B61EC2DC-0841-4906-A84B-5BE5024DA7F1';
55 $preDefPopIdArr['0041']['NUMER'] = '0ED7B212-369B-489A-A5B5-07BC146FA557';
56 $preDefPopIdArr['0041']['DENEXCEP'] = 'B5C9EC50-3011-43DC-AD07-CED2D3B770B2';
58 // CMS122v3/0059 - Diabetes: Hemoglobin A1c Poor Control: HQMF_ID: 40280381-4555-E1C1-0145-90AC70DE2C73
59 $preDefinedUniqIDRules['0059'] = '40280381-4555-E1C1-0145-90AC70DE2C73';
60 $preDefPopIdArr['0059']['IPP'] = 'EDED90E9-E4FE-47E6-90AC-29D9AA3E861A';
61 $preDefPopIdArr['0059']['DENOM'] = '6721D6DA-E87D-4E42-A34A-C8490686598C';
62 $preDefPopIdArr['0059']['NUMER'] = '7549BA9E-1841-4231-8CAA-095BDF0AB8A1';
65 //CMS139v3/0101 - Falls: Screening for Future Fall Risk: HQMF_ID: 40280381-4555-E1C1-0145-672613970D15
66 $preDefinedUniqIDRules['0101'] = '40280381-4555-E1C1-0145-672613970D15';
67 $preDefPopIdArr['0101']['IPP'] = '2448B0C6-6848-4DCB-AA6D-F199337A2C5C';
68 $preDefPopIdArr['0101']['DENOM'] = 'EC400908-35BE-439B-92A9-231D99CEA9DF';
69 $preDefPopIdArr['0101']['NUMER'] = '663FB12B-0FF4-49AB-80A3-624C5E7DF892';
70 $preDefPopIdArr['0101']['DENEXCEP'] = 'FEC7251A-BF8D-4472-97D8-E2A9C0A42176';
72 //CMS127v3/0043 - Pneumonia Vaccination Status for Older Adults: HQMF_ID: 40280381-4555-E1C1-0145-762578A81C4C
73 $preDefinedUniqIDRules['0043'] = '40280381-4555-E1C1-0145-762578A81C4C';
74 $preDefPopIdArr['0043']['IPP'] = '873AECC7-E15B-49E7-8391-D73A46201E2E';
75 $preDefPopIdArr['0043']['DENOM'] = 'FF7016E1-E8C7-43BA-9D56-2BEF649F36FA';
76 $preDefPopIdArr['0043']['NUMER'] = '201F5A6E-4DDE-43A2-BDFC-CE85A98560DA';
78 //CMS69v3/0421 - Preventive Care and Screening: Body Mass Index (BMI) Screening and Follow-Up Plan: HQMF_ID: 40280381-4555-E1C1-0145-D2B36DBB3FE6
79 $preDefinedUniqIDRules['0421']['Numerator 1'] = '40280381-4555-E1C1-0145-D2B36DBB3FE6';
80 $preDefPopIdArr['0421']['Numerator 1']['IPP'] = '1C936855-E644-44C0-B264-49A28756FDB1';
81 $preDefPopIdArr['0421']['Numerator 1']['DENOM'] = '27F1591C-2060-462C-B5D7-7FE86A44B534';
82 $preDefPopIdArr['0421']['Numerator 1']['DENEX'] = '9B0C3C26-D621-4EA3-81FB-A839A3012044';
83 $preDefPopIdArr['0421']['Numerator 1']['NUMER'] = '3095531C-24D7-4AFB-9BCB-F1901FF0FF69';
85 $preDefinedUniqIDRules['0421']['Numerator 2'] = '40280381-4555-E1C1-0145-D2B36DBB3FE6';
86 $preDefPopIdArr['0421']['Numerator 2']['IPP'] = '6E701B1C-6CA5-4AD5-98C9-5F766745EA89';
87 $preDefPopIdArr['0421']['Numerator 2']['DENOM'] = 'E4DC29B8-EB26-4A01-ABB0-4F99FC03BA39';
88 $preDefPopIdArr['0421']['Numerator 2']['DENEX'] = 'BB1B4301-C275-4BAC-87C9-6E960B1601DA';
89 $preDefPopIdArr['0421']['Numerator 2']['NUMER'] = '7669026D-3683-44CC-A2C5-3D62EB2F8A33';
91 //CMS117v3/0038 - Childhood Immunization Status: HQMF_ID: 40280381-4555-E1C1-0145-D7C003364261
92 $preDefinedUniqIDRules['0038'] = '40280381-4555-E1C1-0145-D7C003364261';
93 $preDefPopIdArr['0038']['IPP'] = '6ED6A787-C871-49B9-825C-70A0DB898977';
94 $preDefPopIdArr['0038']['DENOM'] = '545DA813-89ED-4DCD-BDDF-4B33D93DCD84';
95 $preDefPopIdArr['0038']['NUMER'] = '00193FC7-AEE4-4507-A20F-D25A7BB214AD';
97 //CMS138v3/0028 - Preventive Care and Screening: Tobacco Use: Screening and Cessation Intervention: HQMF_ID: 40280381-4600-425F-0146-1F5867D40E82
98 $preDefinedUniqIDRules['0028'] = '40280381-4600-425F-0146-1F5867D40E82';
99 $preDefPopIdArr['0028']['IPP'] = '4E118B62-2AF8-4F51-9355-6FD3F2427D9F';
100 $preDefPopIdArr['0028']['DENOM'] = 'FA1B3953-AE58-4541-BF7B-84D0EB1B0713';
101 $preDefPopIdArr['0028']['NUMER'] = '35B1A6DF-1871-4633-A74B-BCAE371BC030';
102 $preDefPopIdArr['0028']['DENEXCEP'] = '3EE6DFF5-AB17-482F-A147-E6D1E46DBB79';
104 //CMS157v3/0384 - Oncology: Medical and Radiation – Pain Intensity Quantified: HQMF_ID: 40280381-4600-425F-0146-1F620BDF0EB0
105 $preDefinedUniqIDRules['0384'] = '40280381-4600-425F-0146-1F620BDF0EB0';
106 $preDefPopIdArr['0384']['IPP'] = 'C29B6555-3BC7-416F-B61A-FCACD637594F';
107 $preDefPopIdArr['0384']['DENOM'] = 'E5F80C25-6816-4992-92E2-A735B17F8D4F';
108 $preDefPopIdArr['0384']['NUMER'] = 'C948D0D2-D6E9-4099-9CD4-870F2F83A14C';
110 //CMS146v3/0002 - Appropriate Testing for Children with Pharyngitis: HQMF_ID: 40280381-4600-425F-0146-1F6E280C0F09
111 $preDefinedUniqIDRules['0002'] = '40280381-4600-425F-0146-1F6E280C0F09';
112 $preDefPopIdArr['0002']['IPP'] = '9D1135EA-BA90-45E7-8EED-F7335D1CC934';
113 $preDefPopIdArr['0002']['DENOM'] = 'D04EFECB-A901-4565-BDDB-826510499092';
114 $preDefPopIdArr['0002']['NUMER'] = '3F4CDE57-1C5C-4250-A338-55FED6775F57';
115 $preDefPopIdArr['0002']['DENEX'] = '0525FBA2-F068-4706-ADB5-E345852DC55B';
117 //CMS165v3/0018 - Controlling High Blood Pressure: HQMF_ID: 40280381-4600-425F-0146-1F6F722B0F17
118 $preDefinedUniqIDRules['0018'] = '40280381-4600-425F-0146-1F6F722B0F17';
119 $preDefPopIdArr['0018']['IPP'] = 'A72855CE-3C60-41F9-AEE2-64D4F584DDD4';
120 $preDefPopIdArr['0018']['DENOM'] = '26046A5C-E2CC-4A27-B480-FF7E3575691F';
121 $preDefPopIdArr['0018']['NUMER'] = '0899A359-0CD8-4977-AA29-666892AA3AD4';
122 $preDefPopIdArr['0018']['DENEX'] = '4327D845-6194-410D-A48D-D6E1802CAD55';
124 //CMS155v3/0024 - Weight Assessment and Counseling for Nutrition and Physical Activity for Children and Adolescents: HQMF_ID: 40280381-4555-E1C1-0145-85C7311720F5
125 $preDefinedUniqIDRules['0024']['Population Criteria 1']['Numerator 1'] = '40280381-4555-E1C1-0145-85C7311720F5';
126 $preDefPopIdArr['0024']['Population Criteria 1']['Numerator 1']['IPP'] = '10127790-AE94-4070-9DD3-1D3776D08D7C';
127 $preDefPopIdArr['0024']['Population Criteria 1']['Numerator 1']['DENOM'] = '3B3C1568-F875-49B1-9090-E2F494EECBB6';
128 $preDefPopIdArr['0024']['Population Criteria 1']['Numerator 1']['DENEX'] = 'B288D5A4-D573-4FAA-92D6-0B01E1B35C7A';
129 $preDefPopIdArr['0024']['Population Criteria 1']['Numerator 1']['NUMER'] = 'FD4649BD-B962-4CBE-BF4A-C2F95F3EA08E';
131 $preDefinedUniqIDRules['0024']['Population Criteria 1']['Numerator 2'] = '40280381-4555-E1C1-0145-85C7311720F5';
132 $preDefPopIdArr['0024']['Population Criteria 1']['Numerator 2']['IPP'] = '10127790-AE94-4070-9DD3-1D3776D08D7C';
133 $preDefPopIdArr['0024']['Population Criteria 1']['Numerator 2']['DENOM'] = '3B3C1568-F875-49B1-9090-E2F494EECBB6';
134 $preDefPopIdArr['0024']['Population Criteria 1']['Numerator 2']['DENEX'] = 'B288D5A4-D573-4FAA-92D6-0B01E1B35C7A';
135 $preDefPopIdArr['0024']['Population Criteria 1']['Numerator 2']['NUMER'] = '52FBD726-4DD1-48F5-98B9-7175754923E1';
137 $preDefinedUniqIDRules['0024']['Population Criteria 1']['Numerator 3'] = '40280381-4555-E1C1-0145-85C7311720F5';
138 $preDefPopIdArr['0024']['Population Criteria 1']['Numerator 3']['IPP'] = '10127790-AE94-4070-9DD3-1D3776D08D7C';
139 $preDefPopIdArr['0024']['Population Criteria 1']['Numerator 3']['DENOM'] = '3B3C1568-F875-49B1-9090-E2F494EECBB6';
140 $preDefPopIdArr['0024']['Population Criteria 1']['Numerator 3']['DENEX'] = 'B288D5A4-D573-4FAA-92D6-0B01E1B35C7A';
141 $preDefPopIdArr['0024']['Population Criteria 1']['Numerator 3']['NUMER'] = 'C43CE779-C5EE-4C15-A4CC-AF1C446CFB09';
143 $preDefinedUniqIDRules['0024']['Population Criteria 2']['Numerator 1'] = '40280381-4555-E1C1-0145-85C7311720F5';
144 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 1']['IPP'] = '10127790-AE94-4070-9DD3-1D3776D08D7C';
145 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 1']['DENOM'] = '3B3C1568-F875-49B1-9090-E2F494EECBB6';
146 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 1']['DENEX'] = 'B288D5A4-D573-4FAA-92D6-0B01E1B35C7A';
147 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 1']['NUMER'] = 'FD4649BD-B962-4CBE-BF4A-C2F95F3EA08E';
148 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 1']['STRAT'] = '40280381-3D61-56A7-013E-5D53298E6DA3';
149 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 1']['DISPLAY_TEXT'] = 'BMI Recorded, RS1: 3-11';
151 $preDefinedUniqIDRules['0024']['Population Criteria 2']['Numerator 2'] = '40280381-4555-E1C1-0145-85C7311720F5';
152 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 2']['IPP'] = '10127790-AE94-4070-9DD3-1D3776D08D7C';
153 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 2']['DENOM'] = '3B3C1568-F875-49B1-9090-E2F494EECBB6';
154 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 2']['DENEX'] = 'B288D5A4-D573-4FAA-92D6-0B01E1B35C7A';
155 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 2']['NUMER'] = '52FBD726-4DD1-48F5-98B9-7175754923E1';
156 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 2']['STRAT'] = '40280381-3D61-56A7-013E-5D53298E6DA3';
157 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 2']['DISPLAY_TEXT'] = 'BMI Recorded, RS2: 12-17';
159 $preDefinedUniqIDRules['0024']['Population Criteria 2']['Numerator 3'] = '40280381-4555-E1C1-0145-85C7311720F5';
160 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 3']['IPP'] = '10127790-AE94-4070-9DD3-1D3776D08D7C';
161 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 3']['DENOM'] = '3B3C1568-F875-49B1-9090-E2F494EECBB6';
162 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 3']['DENEX'] = 'B288D5A4-D573-4FAA-92D6-0B01E1B35C7A';
163 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 3']['NUMER'] = 'C43CE779-C5EE-4C15-A4CC-AF1C446CFB09';
164 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 3']['STRAT'] = '40280381-3D61-56A7-013E-5D53298E6DA3';
165 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 3']['DISPLAY_TEXT'] = 'Nutrition Counseling, RS1: 3-11';
167 $preDefinedUniqIDRules['0024']['Population Criteria 3']['Numerator 1'] = '40280381-4555-E1C1-0145-85C7311720F5';
168 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 1']['IPP'] = '10127790-AE94-4070-9DD3-1D3776D08D7C';
169 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 1']['DENOM'] = '3B3C1568-F875-49B1-9090-E2F494EECBB6';
170 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 1']['DENEX'] = 'B288D5A4-D573-4FAA-92D6-0B01E1B35C7A';
171 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 1']['NUMER'] = 'FD4649BD-B962-4CBE-BF4A-C2F95F3EA08E';
172 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 1']['STRAT'] = '40280381-3D61-56A7-013E-5D532AF06DA5';
173 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 1']['DISPLAY_TEXT'] = 'Nutrition Counseling, RS2: 12-17';
175 $preDefinedUniqIDRules['0024']['Population Criteria 3']['Numerator 2'] = '40280381-4555-E1C1-0145-85C7311720F5';
176 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 2']['IPP'] = '10127790-AE94-4070-9DD3-1D3776D08D7C';
177 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 2']['DENOM'] = '3B3C1568-F875-49B1-9090-E2F494EECBB6';
178 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 2']['DENEX'] = 'B288D5A4-D573-4FAA-92D6-0B01E1B35C7A';
179 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 2']['NUMER'] = '52FBD726-4DD1-48F5-98B9-7175754923E1';
180 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 2']['STRAT'] = '40280381-3D61-56A7-013E-5D532AF06DA5';
181 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 2']['DISPLAY_TEXT'] = 'Physical Activity Counseling, RS1: 3-11';
183 $preDefinedUniqIDRules['0024']['Population Criteria 3']['Numerator 3'] = '40280381-4555-E1C1-0145-85C7311720F5';
184 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 3']['IPP'] = '10127790-AE94-4070-9DD3-1D3776D08D7C';
185 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 3']['DENOM'] = '3B3C1568-F875-49B1-9090-E2F494EECBB6';
186 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 3']['DENEX'] = 'B288D5A4-D573-4FAA-92D6-0B01E1B35C7A';
187 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 3']['NUMER'] = 'C43CE779-C5EE-4C15-A4CC-AF1C446CFB09';
188 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 3']['STRAT'] = '40280381-3D61-56A7-013E-5D532AF06DA5';
189 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 3']['DISPLAY_TEXT'] = 'Physical Activity Counseling, RS2: 12-17';
191 $preDefPopIdArr['0024']['STRAT1'] = '40280381-3D61-56A7-013E-5D53298E6DA3';
192 $preDefPopIdArr['0024']['STRAT2'] = '40280381-3D61-56A7-013E-5D532AF06DA5';
194 //Multiple Numerator NQF# Array declaration
195 $multNumNQFArr = array('0421', '0024');
196 $countNumNQFArr = array();
197 $countNumNQFArr['0421'] = 2;//two Numerators
198 $countNumNQFArr['0024'] = 9;//Nine Numerators
200 //Initiation of all QRDA needed elements
201 $CQMeausesArr = array();
202 $CQMeausesArr['init_patients'] = "Initial Patient Population";
203 $CQMeausesArr['exclude_patients'] = "Denominator Exclusions";
204 $CQMeausesArr['denom_patients'] = "Denominator";
205 $CQMeausesArr['numer_patients'] = "Numerator";
206 $CQMeausesArr['exception_patients'] = "Denominator Exceptions";
208 $cqmItemizedArr = array();
209 $cqmItemizedArr['init_patients'] = "init_patients";
210 $cqmItemizedArr['exclude_patients'] = "exclude";
211 $cqmItemizedArr['denom_patients'] = "all";
212 $cqmItemizedArr['numer_patients'] = "pass";
213 $cqmItemizedArr['exception_patients'] = "exception";
215 //QRDA Needed Ethnicity
216 $mainEthiArr = array(0=>'Not Hispanic or Latino', 1=>'Hispanic or Latino');
217 $mainEthiCodeArr = array(0=>'2186-5', 1=>'2135-2');
220 $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');
221 $mainQrdaRaceCodeArr = array(0=>'1002-5', 1=>'2028-9', 2=>'2054-5', 3=>'2076-8', 4=>'2106-3', 5=>'2131-1');
223 $mainQrdaPopulationIncArr = array();
224 $mainQrdaPopulationIncArr['init_patients'] = "IPP";
225 $mainQrdaPopulationIncArr['exclude_patients'] = "DENEX";
226 $mainQrdaPopulationIncArr['denom_patients'] = "DENOM";
227 $mainQrdaPopulationIncArr['numer_patients'] = "NUMER";
228 $mainQrdaPopulationIncArr['exception_patients'] = "DENEXCEP";
229 $mainQrdaPopulationIncArr['measure_population'] = "MSRPOPL";
230 $mainQrdaPopulationIncArr['numer_exclusion'] = "NUMEX";
233 $mainQrdaGenderCodeArr = array();
234 $mainQrdaGenderCodeArr['F'] = "Female";
235 $mainQrdaGenderCodeArr['M'] = "Male";
236 $mainQrdaGenderCodeArr['UN'] = "Unknown";
238 //QRDA Needed Payer Info
239 $mainQrdaPayerCodeArr = array();
240 $mainQrdaPayerCodeArr['A'] = "Medicare";
241 $mainQrdaPayerCodeArr['B'] = "Medicaid";
242 $mainQrdaPayerCodeArr['C'] = "Private Health Insurance";
243 $mainQrdaPayerCodeArr['D'] = "Other";
245 //Payer Codes According to Cypress Codes
246 $mainQrdaPayerCodeSendArr = array();
247 $mainQrdaPayerCodeSendArr['A'] = "1";
248 $mainQrdaPayerCodeSendArr['B'] = "2";
249 $mainQrdaPayerCodeSendArr['C'] = "5";
250 $mainQrdaPayerCodeSendArr['D'] = "349";
253 $form_provider = $_GET['form_provider'];
255 //Get Report Information
256 $report_id = $_GET['report_id'];
257 $report_view = collectReportDatabase($report_id);
258 $target_date = $report_view['date_target'];
259 $dataSheet = json_decode($report_view['data'],TRUE);
261 //Needed array for Rule NQF#0024 Stratification
262 $stratumCheckArr = array();
263 if(count($dataSheet) > 0){
265 foreach ($dataSheet as $row) {
266 $itemized_test_id = $row['itemized_test_id'];
267 $numerator_label = $row['numerator_label'];
268 if($row['cqm_nqf_code'] == "0024"){
269 if( $row['population_label'] == "Population Criteria 2" ){
270 if($row['numerator_label'] == "Numerator 1"){
271 $stratum_1_ipp = $row['initial_population'];
272 $stratum_1_exclude = $row['excluded'];
273 $stratum_1_denom = $row['pass_filter'];
274 $stratum_1_numer1 = $row['pass_target'];
275 }else if($row['numerator_label'] == "Numerator 2"){
276 $stratum_1_numer2 = $row['pass_target'];
277 }else if($row['numerator_label'] == "Numerator 3"){
278 $stratum_1_numer3 = $row['pass_target'];
280 }else if( $row['population_label'] == "Population Criteria 3" ){
281 if($row['numerator_label'] == "Numerator 1"){
282 $stratum_2_ipp = $row['initial_population'];
283 $stratum_2_exclude = $row['excluded'];
284 $stratum_2_denom = $row['pass_filter'];
285 $stratum_2_numer1 = $row['pass_target'];
286 }else if($row['numerator_label'] == "Numerator 2"){
287 $stratum_2_numer2 = $row['pass_target'];
288 }else if($row['numerator_label'] == "Numerator 3"){
289 $stratum_2_numer3 = $row['pass_target'];
295 $stratum[1] = array('init_patients' => $stratum_1_ipp,
296 'exclude_patients' => $stratum_1_exclude,
297 'denom_patients' => $stratum_1_denom,
298 'numer_patients' => $stratum_1_numer1,
299 'numer2' => $stratum_1_numer2,
300 'numer3' => $stratum_1_numer3);
302 $stratum[2] = array('init_patients' => $stratum_2_ipp,
303 'exclude_patients' => $stratum_2_exclude,
304 'denom_patients' => $stratum_2_denom,
305 'numer_patients' => $stratum_2_numer1,
306 'numer2' => $stratum_2_numer2,
307 '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'];
371 //$xml->self_customTag('telecom', array('value' => $userRow['phone'], 'use'=>'WP'));
373 //assignedAuthoringDevice Start
374 $xml->open_customTag('assignedAuthoringDevice');
376 $xml->element('softwareName', 'CYPRESS');
378 //assignedAuthoringDevice Close
379 $xml->close_customTag();
382 $facilResRow = sqlQuery("SELECT name, street,city,state,postal_code, country_code, phone from facility WHERE id = ?", array($facility_id));
383 $xml->add_authReprestOrginisation($facilResRow);
384 //$xml->add_facilAddress($facilResRow);
385 $xml->close_assignAuthor();
386 $xml->close_author();
388 ############### Custodian Info #######################
389 $xml->open_custodian();
390 $xml->open_assgnCustodian();
391 $xml->add_represtCustodianOrginisation($facilResRow);
392 $xml->close_assgnCustodian();
393 $xml->close_custodian();
396 ############### Information Recipient #######################
397 $xml->open_infoRecipient();
398 $xml->add_indententRecipient();
399 $xml->close_infoRecipient();
402 ############### Legal Authenticator #######################
403 $xml->open_legalAuthenticator();
404 $auth_dtime = date('Ymdhis', strtotime(date('Y-m-d H:i:s')));
405 $xml->self_authorTime($auth_dtime);
406 $xml->self_legalSignCode();
408 $xml->open_assignedEntity();
409 $assignedEntityId = getUuid();
410 $xml->self_customId($assignedEntityId);
412 $xml->open_customTag('assignedPerson');
415 $userNameArr = array('fname' =>$userRow['fname'], 'lname'=>$userRow['lname']);
416 $xml->add_providerName($userNameArr);
418 //assignedPerson Close
419 $xml->close_customTag();
421 //Represent Origination Name
422 $xml->add_authReprestOrginisation($facilResRow);
423 $xml->close_assignedEntity();
425 $xml->close_legalAuthenticator();
428 ############### Participant is Device(optional) #######################
429 $participentDevArr = array();
430 $xml->open_participant_data('DEV');//DEV -- Device
431 $xml->open_assocEntityData('RGPR');//RGPR -- Regulated Product
432 $participentDevArr['root'] = '2.16.840.1.113883.3.2074.1';
433 $participentDevArr['extension'] = '1a2b3c';
434 $xml->self_particpantIdInfo($participentDevArr);
435 $xml->self_participantCodeDevice();
436 $xml->close_assocEntityData();
437 $xml->close_participant_data();
439 ############### Participant is Location(optional) #######################
440 $participentLocArr = array();
441 $xml->open_participant_data('LOC');//LOC -- Location
442 $xml->open_assocEntityData('SDLOC');//SDLOC -- Service Delivery Location
443 $participentLocArr['root'] = '2.16.840.1.113883.3.249.5.1';
444 $participentLocArr['extension'] = 'OK666333';
445 $xml->self_particpantIdInfo($participentLocArr);
446 $xml->self_participantCodeLocation();
448 $xml->add_facilAddress($facilResRow);
449 $xml->close_assocEntityData();
450 $xml->close_participant_data();
453 ############### documentationOf START #######################
454 $xml->open_customTag('documentationOf');
456 $xml->open_customTag('serviceEvent', array('classCode'=>'PCPR'));
458 $timeArr = array('low'=>date('Ymd', strtotime($from_date)), 'high'=>date('Ymd', strtotime($to_date)));
459 $xml->add_entryEffectTime($timeArr);
461 $xml->open_customTag('performer', array('typeCode'=>'PRF'));
463 $xml->open_customTag('assignedEntity');
465 $npi_provider = !empty($userRow['npi']) ?
$userRow['npi'] : '123456789';
466 $xml->self_customTag('id', array('root' => '2.16.840.1.113883.4.6', 'extension' =>$npi_provider));
468 if($userRow['phone'] != ""){
469 $xml->self_customTag('telecom', array('value' => $userRow['phone'], 'use'=>'WP'));
472 $xml->open_customTag('assignedPerson');
475 $userNameArr = array('fname' =>$userRow['fname'], 'lname'=>$userRow['lname']);
476 $xml->add_providerName($userNameArr);
478 //assignedPerson Close
479 $xml->close_customTag();
481 $xml->open_customTag('representedOrganization');
483 $tin_provider = $userRow['federaltaxid'];
484 if($tin_provider != ""){
485 $xml->self_customTag('id', array('root' => '2.16.840.1.113883.4.2', 'extension' =>$tin_provider));
488 $xml->add_facilName($facility_name);
490 $xml->add_facilAddress($facilResRow);
492 //representedOrganization Close
493 $xml->close_customTag();
495 //assignedEntity Close
496 $xml->close_customTag();
499 $xml->close_customTag();
502 $xml->close_customTag();
504 //documentationOf Close
505 $xml->close_customTag();
506 ############### documentationOf END #######################
509 ############### authorization (optional) #########################
511 #################################################################################################
512 ####################### HEADER ELEMENTS END #####################################################
513 #################################################################################################
517 #################################################################################################
518 ######################### Main Component Open ###################################################
519 $xml->open_mainComponent();
521 ############### Structure Body Open #######################
522 $xml->open_structuredBody();
524 ##################### LOOP Component(s) START ########################
526 ###################### Report Parameters Open #####################
527 //QRDA Category III Reporting Parameters Section (CMS EP) [section: templateId 2.16.840.1.113883.10.20.27.2.6
528 $xml->open_loopComponent();
530 $xml->open_section();
532 $tempID = '2.16.840.1.113883.10.20.17.2.1';
533 $xml->self_templateid($tempID);
535 $tempID = '2.16.840.1.113883.10.20.27.2.2';
536 $xml->self_templateid($tempID);
538 $tempID = '2.16.840.1.113883.10.20.27.2.6';
539 $xml->self_templateid($tempID);
540 $arr = array('code'=>'55187-9', 'codeSystem'=>'2.16.840.1.113883.6.1');
541 $xml->self_codeCustom($arr);
542 $title = "Reporting Parameters";
543 $xml->add_title($title);
547 $item_title = "Reporting period: ".date('d M Y', strtotime($from_date))." - ".date('d M Y', strtotime($to_date));
548 $xml->add_item($item_title);
553 $xml->open_entry($typeCode);
554 $arr = array('classCode'=>'ACT', 'moodCode'=>'EVN');
555 $xml->open_act($arr);
557 $tempID = '2.16.840.1.113883.10.20.17.3.8';
558 $xml->self_templateid($tempID);
560 $tempID = '2.16.840.1.113883.10.20.27.3.23';
561 $xml->self_templateid($tempID);
564 $xml->self_customId($actId);
566 $arr = array('code'=>'252116004', 'codeSystem'=>'2.16.840.1.113883.6.96', 'displayName'=>'Observation Parameters');
567 $xml->self_codeCustom($arr);
569 $timeArr = array('low'=>date('Ymd', strtotime($from_date)), 'high'=>date('Ymd', strtotime($to_date)));
570 $xml->add_entryEffectTime($timeArr);
575 $xml->close_section();
577 $xml->close_loopComponent();
578 ###################### Report Parameters Close #####################
580 ###################### Measure Section Open #####################
581 $xml->open_loopComponent();
583 $xml->open_section();
585 $tempID = '2.16.840.1.113883.10.20.27.2.1';
586 $xml->self_templateid($tempID);
588 $tempID = '2.16.840.1.113883.10.20.24.2.2';
589 $xml->self_templateid($tempID);
591 $tempID = '2.16.840.1.113883.10.20.27.2.3';
592 $xml->self_templateid($tempID);
594 $arr = array('code'=>'55186-1', 'codeSystem'=>'2.16.840.1.113883.6.1');
595 $xml->self_codeCustom($arr);
596 $title = "Measure Section";
597 $xml->add_title($title);
602 $tabArr = array('border'=>1, 'width'=>'100%');
603 if(count($dataSheet) > 0){
604 $uniqIdArr = array();
607 foreach ($dataSheet as $row) {
608 $itemized_test_id = $row['itemized_test_id'];
609 $numerator_label = $row['numerator_label'];
611 //CQM Rules 2014 set, 0013 is 0018
612 if($row['cqm_nqf_code'] == "0013") $row['cqm_nqf_code'] = "0018";
615 $xml->open_customTag('table', $tabArr);
617 $xml->open_customTag('thead');
619 $xml->open_customTag('tr');
621 $xml->add_trElementsTitles();
624 $xml->close_customTag();
627 $xml->close_customTag();
629 $xml->open_customTag('tbody');
630 $xml->open_customTag('tr');
632 $tdTitle = generate_display_field(array('data_type'=>'1','list_id'=>'clinical_rules'),$row['id']);
634 if (!empty($row['cqm_pqri_code'])) {
635 $tdTitle .= " " . htmlspecialchars( xl('PQRI') . ":" . $row['cqm_pqri_code'], ENT_NOQUOTES
) . " ";
637 if (!empty($row['cqm_nqf_code'])) {
638 $tdTitle .= " " . htmlspecialchars( xl('NQF') . ":" . $row['cqm_nqf_code'], ENT_NOQUOTES
) . " ";
641 if ( !(empty($row['concatenated_label'])) ) {
642 $tdTitle .= ", " . htmlspecialchars( xl( $row['concatenated_label'] ), ENT_NOQUOTES
) . " ";
645 $tdVersionNeutral = getUuid();
647 if($preDefinedUniqIDRules[$row['cqm_nqf_code']] != ""){
648 if( ($row['cqm_nqf_code'] == "0421" ) )
649 $tdVersionSpecific = $preDefinedUniqIDRules[$row['cqm_nqf_code']][$row['numerator_label']];
650 else if($row['cqm_nqf_code'] == "0024")
651 $tdVersionSpecific = $preDefinedUniqIDRules[$row['cqm_nqf_code']][$row['population_label']][$row['numerator_label']];
653 $tdVersionSpecific = $preDefinedUniqIDRules[$row['cqm_nqf_code']];
655 $uniqIdArr[] = $tdVersionSpecific;
657 $tdVersionSpecific = getUuid();
658 $uniqIdArr[] = $tdVersionSpecific;
661 $dataArr = array(0=>$tdTitle, 1=>$tdVersionNeutral, 2=>$tdVersionSpecific);
662 $xml->add_trElementsValues($dataArr);
665 $xml->close_customTag();
667 $xml->close_customTag();
669 $xml->close_customTag();
671 //Open List Item Wise
675 $xml->open_customTag('item');
676 $arrContent = array('name'=>'Performance Rate', 'value'=>$row['percentage']);
677 $xml->innerContent($arrContent);
678 $xml->close_customTag();
681 //All CQM Measures taken here
682 foreach($CQMeausesArr as $cqmKey => $cqmVal){
684 //DENEXCEP(Denominator Exception not needed for some rules are skipping here)
685 if( (in_array($row['cqm_nqf_code'], $denExcepNotNeedRules) ) && ($cqmKey == "exception_patients") ) continue;
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);
692 $fullPatArr = array();
693 foreach($itemPatArr as $itemPatInfo){
694 $fullPatArr[] = $itemPatInfo['pid'];
697 //Initial Patient Population
698 $xml->open_customTag('item');
699 $arrContent = array('name'=>$cqmVal, 'value'=>count($fullPatArr));
700 $xml->innerContent($arrContent);
702 $detailsArr = getQRDAPatientNeedInfo($fullPatArr);
707 //Gender Section Display
708 foreach($mainQrdaGenderCodeArr as $GKey => $GVal){
709 $xml->open_customTag('item');
710 $genderInfo = $detailsArr['gender'][$GVal];
711 $arrContent = array('name'=>$GVal, 'value'=>$genderInfo);
712 $xml->innerContent($arrContent);
713 $xml->close_customTag();
716 //Ethnicity Section Display
717 foreach($mainEthiArr as $ethKey => $ethVal){
718 $ethnicity_data = $detailsArr['ethnicity'][$ethVal];
719 $xml->open_customTag('item');
720 $arrContent = array('name'=>'Ethnicity - '.$ethVal, 'value'=>$ethnicity_data);
721 $xml->innerContent($arrContent);
722 $xml->close_customTag();
725 //Race Section Display
726 foreach($mainQrdaRaceArr as $RKey => $RVal){
727 $race_data = $detailsArr['race'][$RVal];
728 $xml->open_customTag('item');
729 $arrContent = array('name'=>'Race - '.$RVal, 'value'=>$race_data);
730 $xml->innerContent($arrContent);
731 $xml->close_customTag();
734 //Payer Type Section Display
735 $payerCheckArr = getQRDAPayerInfo($fullPatArr);
736 foreach($mainQrdaPayerCodeArr as $PKey => $PVal){
737 $xml->open_customTag('item');
738 $arrContent = array('name'=>'Payer - '.$PVal, 'value'=>$payerCheckArr[$PVal]);
739 $xml->innerContent($arrContent);
740 $xml->close_customTag();
745 $xml->close_customTag();
753 #######################################################################
754 ######################### QUALITY MEASURES START ######################
755 #######################################################################
756 if(count($dataSheet) > 0){
758 $skipMultNumArr = array();
759 $dataChkArr = array();
760 foreach($multNumNQFArr as $multNumVal){
761 $skipMultNumArr[$multNumVal] = false;
762 $dataChkArr[$multNumVal] = 0;
766 foreach ($dataSheet as $row) {
767 $itemized_test_id = $row['itemized_test_id'];
768 $numerator_label = $row['numerator_label'];
770 //if($row['cqm_nqf_code'] == "0028a") continue;
772 //if($row['cqm_nqf_code'] == "0038"){
773 // if(in_array($row['numerator_label'], $NQF38NumArr)) continue;
776 if(in_array($row['cqm_nqf_code'], $multNumNQFArr)){
777 $dataChkArr[$row['cqm_nqf_code']]++
;
780 //CQM Rules 2014 set, 0013 is 0018
781 if($row['cqm_nqf_code'] == "0013") $row['cqm_nqf_code'] = "0018";
783 $tdTitle = generate_display_field(array('data_type'=>'1','list_id'=>'clinical_rules'),$row['id']);
784 if (!empty($row['cqm_pqri_code'])) {
785 $tdTitle .= " " . text( xl('PQRI') . ":" . $row['cqm_pqri_code']) . " ";
787 if (!empty($row['cqm_nqf_code'])) {
788 $tdTitle .= " " . text( xl('NQF') . ":" . $row['cqm_nqf_code']) . " ";
791 if ( !(empty($row['concatenated_label'])) ) {
792 $tdTitle .= ", " . text( xl( $row['concatenated_label'] )) . " ";
795 ###########################################################
796 if( ( !isset($skipMultNumArr[$row['cqm_nqf_code']]) ) ||
($skipMultNumArr[$row['cqm_nqf_code']] == false) ){
802 $arr = array('classCode'=>'CLUSTER', 'moodCode'=>'EVN');
803 $xml->open_customTag('organizer', $arr);
805 $tempID = "2.16.840.1.113883.10.20.24.3.98";
806 $xml->self_templateid($tempID);
808 $tempID = "2.16.840.1.113883.10.20.27.3.1";
809 $xml->self_templateid($tempID);
811 //$tempID = "2.16.840.1.113883.10.20.27.3.17";
812 //$xml->self_templateid($tempID);
814 $xml->self_customId($actId);
816 $arr = array('code'=>'completed');
817 $xml->self_customTag('statusCode', $arr);
820 $arr = array('typeCode'=>'REFR');
821 $xml->open_customTag('reference', $arr);
823 //externalDocument Start
824 $arr = array('classCode'=>'DOC', 'moodCode'=>'EVN');
825 $xml->open_customTag('externalDocument', $arr);
827 //$exDocID = getUuid();
828 $exDocID = $uniqIdArr[$innrCnt];
829 //$xml->self_customId($exDocID);
830 $xml->self_customTag('id', array('root' => '2.16.840.1.113883.4.738', 'extension' =>$exDocID));
832 $arr = array('code'=>'57024-2', 'displayName'=>'Health Quality Measure Document', 'codeSystem'=>'2.16.840.1.113883.6.1', 'codeSystemName'=>'LOINC');
833 $xml->self_codeCustom($arr);
835 $dispContntTitle = str_replace("&", '', $tdTitle);
836 $xml->textDispContent($dispContntTitle);
838 //externalDocument Close
839 $xml->close_customTag();
842 $xml->close_customTag();
845 ############### Performance Rate for Proportion Measure template START###################
846 $xml->open_loopComponent();
849 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
851 $tempID = "2.16.840.1.113883.10.20.27.3.14";
852 $xml->self_templateid($tempID);
854 $tempID = "2.16.840.1.113883.10.20.27.3.25";
855 $xml->self_templateid($tempID);
857 $arr = array('code'=>'72510-1', 'displayName'=>'Performance Rate', 'codeSystem'=>'2.16.840.1.113883.6.1', 'codeSystemName'=>'SNOMED-CT');
858 $xml->self_codeCustom($arr);
860 $arr = array('code'=>'completed');
861 $xml->self_customTag('statusCode', $arr);
863 $percentage = str_replace("%", '', $row['percentage']);
864 $arr = array('xsi:type'=>'REAL', 'value'=>$percentage/100);
865 $xml->self_customTag('value', $arr);
868 $arr = array('typeCode'=>'REFR');
869 $xml->open_customTag('reference', $arr);
871 //externalObservation Start
872 $arr = array('classCode'=>'OBS', 'moodCode'=>'EVN');
873 $xml->open_customTag('externalObservation', $arr);
876 //$exDocID = getUuid();
879 if( ($row['cqm_nqf_code'] == "0421" )){
880 $exDocID = $preDefPopIdArr[$row['cqm_nqf_code']][$row['numerator_label']]["NUMER"];
881 }else if(($row['cqm_nqf_code'] == "0024")){
882 $exDocID = $preDefPopIdArr[$row['cqm_nqf_code']][$row['population_label']][$row['numerator_label']]["NUMER"];
884 if($preDefPopIdArr[$row['cqm_nqf_code']]["NUMER"] != "")
885 $exDocID = $preDefPopIdArr[$row['cqm_nqf_code']]["NUMER"];
887 $exDocID = getUuid();
890 $xml->self_customId($exDocID);
892 $arr = array('code'=>'NUMER', 'displayName'=>'Numerator', 'codeSystem'=>'2.16.840.1.113883.5.1063', 'codeSystemName'=>'ObservationValue');
893 $xml->self_codeCustom($arr);
895 //externalObservation Close
896 $xml->close_customTag();
899 $xml->close_customTag();
902 $xml->close_customTag();
904 $xml->close_loopComponent();
905 ############### Performance Rate for Proportion Measure template END ###################
909 //All CQM Measures taken here
910 foreach($CQMeausesArr as $cqmKey => $cqmVal){
912 //DENEXCEP(Denominator Exception not needed for some rules are skipping here)
913 if( (in_array($row['cqm_nqf_code'], $denExcepNotNeedRules) ) && ($cqmKey == "exception_patients") ) continue;
915 //cqm 0024 alllowing only nuemerator 2 and numerator 3 for ipp1,ipp2 and 1pp3 to avoid repeatation
916 if($row['cqm_nqf_code'] == '0024' && ($row['numerator_label'] == "Numerator 2" ||
$row['numerator_label'] == "Numerator 3") && $cqmKey != 'numer_patients') continue;
917 if($row['cqm_nqf_code'] == '0024' && ($row['population_label'] == "Population Criteria 2" ||
$row['population_label'] == "Population Criteria 3")) continue;
921 if($cqmKey == "init_patients")
922 $itemPatArr = collectItemizedPatientsCdrReport($report_id,$itemized_test_id,$cqmItemizedArr[$cqmKey]);
924 $itemPatArr = collectItemizedPatientsCdrReport($report_id,$itemized_test_id,$cqmItemizedArr[$cqmKey], $numerator_label);
926 $fullPatArr = array();
927 foreach($itemPatArr as $itemPatInfo){
928 $fullPatArr[] = $itemPatInfo['pid'];
931 $detailsArr = getQRDAPatientNeedInfo($fullPatArr);
932 ############### Initial patient population template START###################
933 $xml->open_loopComponent();
936 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
938 $tempID = "2.16.840.1.113883.10.20.27.3.5";
939 $xml->self_templateid($tempID);
941 $tempID = "2.16.840.1.113883.10.20.27.3.16";
942 $xml->self_templateid($tempID);
944 $arr = array('code'=>'ASSERTION', 'displayName'=>'Assertion', 'codeSystem'=>'2.16.840.1.113883.5.4', 'codeSystemName'=>'ActCode');
945 $xml->self_codeCustom($arr);
947 $arr = array('code'=>'completed');
948 $xml->self_customTag('statusCode', $arr);
950 $arr = array('xsi:type'=>'CD', 'code'=>$mainQrdaPopulationIncArr[$cqmKey], 'displayName'=>$cqmVal, 'codeSystem' =>'2.16.840.1.113883.5.1063', 'codeSystemName'=>'ObservationValue');
951 $xml->self_customTag('value', $arr);
953 //entryRelationship Open
954 $xml->open_customTag('entryRelationship', array('typeCode'=>'SUBJ', 'inversionInd'=>'true'));
957 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
959 $tempID = "2.16.840.1.113883.10.20.27.3.3";
960 $xml->self_templateid($tempID);
962 $tempID = "2.16.840.1.113883.10.20.27.3.24";
963 $xml->self_templateid($tempID);
965 $arr = array('code'=>'MSRAGG', 'displayName'=>'rate aggregation', 'codeSystem'=>'2.16.840.1.113883.5.4', 'codeSystemName'=>'ActCode');
966 $xml->self_codeCustom($arr);
968 //$arr = array('code'=>'completed');
969 //$xml->self_customTag('statusCode', $arr);
971 $arr = array('xsi:type'=>'INT', 'value'=>count($fullPatArr));
972 $xml->self_customTag('value', $arr);
974 $arr = array('code'=>'COUNT', 'displayName'=>'Count', 'codeSystem'=>'2.16.840.1.113883.5.84', 'codeSystemName'=>'ObservationMethod');
975 $xml->self_customTag('methodCode', $arr);
978 $xml->close_customTag();
980 //entryRelationship Close
981 $xml->close_customTag();
983 #### Stratum Start (Stratification)#####
984 if($row['cqm_nqf_code'] == '0024'){
986 for(;$strat_count <= 2;$strat_count++
){
988 $strata_value = $stratum[$strat_count][$cqmKey];
990 if($row['numerator_label'] == "Numerator 2") $strata_value = $stratum[$strat_count]['numer2'];
992 else if($row['numerator_label'] == "Numerator 3") $strata_value = $stratum[$strat_count]['numer3'];
994 //entryRelationship Open
995 $xml->open_customTag('entryRelationship', array('typeCode'=>'COMP'));
998 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
1000 $tempID = "2.16.840.1.113883.10.20.27.3.4";
1001 $xml->self_templateid($tempID);
1003 $tempID = "2.16.840.1.113883.10.20.27.3.20";
1004 $xml->self_templateid($tempID);
1006 $arr = array('code'=>'ASSERTION', 'displayName'=>'Assertion', 'codeSystem'=>'2.16.840.1.113883.5.4', 'codeSystemName'=>'ActCode');
1007 $xml->self_codeCustom($arr);
1009 $arr = array('code'=>'completed');
1010 $xml->self_customTag('statusCode', $arr);
1013 $xml->open_customTag('value', array('xsi:type'=>'CD', 'nullFlavor'=>'OTH'));
1015 $stratumText = $preDefPopIdArr[$row['cqm_nqf_code']][$row['population_label']][$row['numerator_label']]['DISPLAY_TEXT'];
1016 $xml->element('originalText', "Stratum ".$strat_count);
1019 $xml->close_customTag();
1021 //entryRelationship Open
1022 $xml->open_customTag('entryRelationship', array('typeCode'=>'SUBJ', 'inversionInd' => 'true'));
1025 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
1027 $tempID = "2.16.840.1.113883.10.20.27.3.3";
1028 $xml->self_templateid($tempID);
1030 $arr = array('code'=>'MSRAGG', 'displayName'=>'rate aggregation', 'codeSystem'=>'2.16.840.1.113883.5.4', 'codeSystemName'=>'ActCode');
1031 $xml->self_codeCustom($arr);
1033 $arr = array('xsi:type'=>'INT', 'value'=>$strata_value);
1034 $xml->self_customTag('value', $arr);
1036 $arr = array('code'=>'COUNT', 'displayName'=>'Count', 'codeSystem'=>'2.16.840.1.113883.5.84', 'codeSystemName'=>'ObservationMethod');
1037 $xml->self_customTag('methodCode', $arr);
1040 $xml->close_customTag();
1042 //entryRelationship Close
1043 $xml->close_customTag();
1046 $arr = array('typeCode'=>'REFR');
1047 $xml->open_customTag('reference', $arr);
1049 //externalObservation Start
1050 $arr = array('classCode'=>'OBS', 'moodCode'=>'EVN');
1051 $xml->open_customTag('externalObservation', $arr);
1053 //Modified HQMF_ID for CQM IDS
1054 //$refID = $preDefPopIdArr[$row['cqm_nqf_code']][$row['population_label']][$row['numerator_label']]['STRAT'];
1055 $refID = $preDefPopIdArr[$row['cqm_nqf_code']]['STRAT'.$strat_count];
1057 $xml->self_customId($refID);
1059 //externalObservation Close
1060 $xml->close_customTag();
1063 $xml->close_customTag();
1066 $xml->close_customTag();
1068 //entryRelationship Close
1069 $xml->close_customTag();
1073 #### Stratum END #####
1075 ####################################################
1076 ####################################################
1077 //Sex Supplemental Data Element START
1078 ####################################################
1079 ####################################################
1081 foreach($mainQrdaGenderCodeArr as $GKey => $GVal){
1082 //entryRelationship Open
1083 $xml->open_customTag('entryRelationship', array('typeCode'=>'COMP'));
1086 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
1088 $tempID = "2.16.840.1.113883.10.20.27.3.6";
1089 $xml->self_templateid($tempID);
1091 $tempID = "2.16.840.1.113883.10.20.27.3.21";
1092 $xml->self_templateid($tempID);
1094 $arr = array('code'=>'184100006', 'displayName'=>'patient sex', 'codeSystem'=>'2.16.840.1.113883.6.96', 'codeSystemName'=>'SNOMED-CT');
1095 $xml->self_codeCustom($arr);
1097 $arr = array('code'=>'completed');
1098 $xml->self_customTag('statusCode', $arr);
1100 $arr = array('xsi:type'=>'CD', 'code'=>$GKey, 'codeSystem' =>'2.16.840.1.113883.5.1', 'codeSystemName'=>'AdministrativeGenderCode');
1101 $xml->self_customTag('value', $arr);
1103 //entryRelationship Open
1104 $xml->open_customTag('entryRelationship', array('typeCode'=>'SUBJ', 'inversionInd'=>'true'));
1107 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
1109 $tempID = "2.16.840.1.113883.10.20.27.3.3";
1110 $xml->self_templateid($tempID);
1112 $tempID = "2.16.840.1.113883.10.20.27.3.24";
1113 $xml->self_templateid($tempID);
1115 $arr = array('code'=>'MSRAGG', 'displayName'=>'rate aggregation', 'codeSystem'=>'2.16.840.1.113883.5.4', 'codeSystemName'=>'ActCode');
1116 $xml->self_codeCustom($arr);
1118 //$arr = array('code'=>'completed');
1119 //$xml->self_customTag('statusCode', $arr);
1121 $arr = array('xsi:type'=>'INT', 'value'=>$detailsArr['gender'][$GVal]);
1122 $xml->self_customTag('value', $arr);
1124 $arr = array('code'=>'COUNT', 'displayName'=>'Count', 'codeSystem'=>'2.16.840.1.113883.5.84', 'codeSystemName'=>'ObservationMethod');
1125 $xml->self_customTag('methodCode', $arr);
1128 $xml->close_customTag();
1130 //entryRelationship Close
1131 $xml->close_customTag();
1135 $xml->close_customTag();
1137 //entryRelationship Close
1138 $xml->close_customTag();
1140 ####################################################
1141 ####################################################
1142 //Sex Supplemental Data Element END
1143 ####################################################
1144 ####################################################
1146 ####################################################
1147 ####################################################
1148 //Ethnicity Supplemental Data Element (CMS EP) START
1149 ####################################################
1150 ####################################################
1152 foreach($mainEthiArr as $ethKey => $ethVal){
1153 //entryRelationship Open
1154 $xml->open_customTag('entryRelationship', array('typeCode'=>'COMP'));
1157 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
1159 $tempID = "2.16.840.1.113883.10.20.27.3.7";
1160 $xml->self_templateid($tempID);
1162 $tempID = "2.16.840.1.113883.10.20.27.3.22";
1163 $xml->self_templateid($tempID);
1165 $arr = array('code'=>'364699009', 'displayName'=>'Ethnic Group', 'codeSystem'=>'2.16.840.1.113883.6.96', 'codeSystemName'=>'SNOMED-CT');
1166 $xml->self_codeCustom($arr);
1168 $arr = array('code'=>'completed');
1169 $xml->self_customTag('statusCode', $arr);
1171 $arr = array('xsi:type'=>'CD', 'code'=>$mainEthiCodeArr[$ethKey], 'displayName'=>$ethVal, 'codeSystem' =>'2.16.840.1.113883.6.238', 'codeSystemName'=>'Race & Ethnicity - CDC');
1172 $xml->self_customTag('value', $arr);
1174 //entryRelationship Open
1175 $xml->open_customTag('entryRelationship', array('typeCode'=>'SUBJ', 'inversionInd'=>'true'));
1178 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
1180 $tempID = "2.16.840.1.113883.10.20.27.3.3";
1181 $xml->self_templateid($tempID);
1183 $tempID = "2.16.840.1.113883.10.20.27.3.24";
1184 $xml->self_templateid($tempID);
1186 $arr = array('code'=>'MSRAGG', 'displayName'=>'rate aggregation', 'codeSystem'=>'2.16.840.1.113883.5.4', 'codeSystemName'=>'ActCode');
1187 $xml->self_codeCustom($arr);
1189 //$arr = array('code'=>'completed');
1190 //$xml->self_customTag('statusCode', $arr);
1192 $arr = array('xsi:type'=>'INT', 'value'=>$detailsArr['ethnicity'][$ethVal]);
1193 $xml->self_customTag('value', $arr);
1195 $arr = array('code'=>'COUNT', 'displayName'=>'Count', 'codeSystem'=>'2.16.840.1.113883.5.84', 'codeSystemName'=>'ObservationMethod');
1196 $xml->self_customTag('methodCode', $arr);
1199 $xml->close_customTag();
1201 //entryRelationship Close
1202 $xml->close_customTag();
1206 $xml->close_customTag();
1208 //entryRelationship Close
1209 $xml->close_customTag();
1212 ####################################################
1213 ####################################################
1214 //Ethnicity Supplemental Data Element (CMS EP) END
1215 ####################################################
1216 ####################################################
1219 ####################################################
1220 ####################################################
1221 //Race Supplemental Data Element (CMS EP) START
1222 ####################################################
1223 ####################################################
1225 foreach($mainQrdaRaceArr as $RKey => $RVal){
1226 //entryRelationship Open
1227 $xml->open_customTag('entryRelationship', array('typeCode'=>'COMP'));
1230 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
1232 $tempID = "2.16.840.1.113883.10.20.27.3.8";
1233 $xml->self_templateid($tempID);
1235 $tempID = "2.16.840.1.113883.10.20.27.3.19";
1236 $xml->self_templateid($tempID);
1238 $arr = array('code'=>'103579009', 'displayName'=>'Race', 'codeSystem'=>'2.16.840.1.113883.6.96', 'codeSystemName'=>'SNOMED-CT');
1239 $xml->self_codeCustom($arr);
1241 $arr = array('code'=>'completed');
1242 $xml->self_customTag('statusCode', $arr);
1244 $arr = array('xsi:type'=>'CD', 'code'=>$mainQrdaRaceCodeArr[$RKey], 'displayName'=>$RVal, 'codeSystem' =>'2.16.840.1.113883.6.238', 'codeSystemName'=>'Race & Ethnicity - CDC');
1245 $xml->self_customTag('value', $arr);
1247 //entryRelationship Open
1248 $xml->open_customTag('entryRelationship', array('typeCode'=>'SUBJ', 'inversionInd'=>'true'));
1251 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
1253 $tempID = "2.16.840.1.113883.10.20.27.3.3";
1254 $xml->self_templateid($tempID);
1256 $tempID = "2.16.840.1.113883.10.20.27.3.24";
1257 $xml->self_templateid($tempID);
1259 $arr = array('code'=>'MSRAGG', 'displayName'=>'rate aggregation', 'codeSystem'=>'2.16.840.1.113883.5.4', 'codeSystemName'=>'ActCode');
1260 $xml->self_codeCustom($arr);
1262 //$arr = array('code'=>'completed');
1263 //$xml->self_customTag('statusCode', $arr);
1265 $arr = array('xsi:type'=>'INT', 'value'=>$detailsArr['race'][$RVal]);
1266 $xml->self_customTag('value', $arr);
1268 $arr = array('code'=>'COUNT', 'displayName'=>'Count', 'codeSystem'=>'2.16.840.1.113883.5.84', 'codeSystemName'=>'ObservationMethod');
1269 $xml->self_customTag('methodCode', $arr);
1272 $xml->close_customTag();
1274 //entryRelationship Close
1275 $xml->close_customTag();
1279 $xml->close_customTag();
1281 //entryRelationship Close
1282 $xml->close_customTag();
1285 ####################################################
1286 ####################################################
1287 //Race Supplemental Data Element (CMS EP) END
1288 ####################################################
1289 ####################################################
1292 ####################################################
1293 ####################################################
1294 //Payer Supplemental Data Element (CMS EP) START
1295 ####################################################
1296 ####################################################
1297 $payerCheckArr = getQRDAPayerInfo($fullPatArr);
1298 foreach($mainQrdaPayerCodeArr as $PKey => $PVal){
1299 //entryRelationship Open
1300 $xml->open_customTag('entryRelationship', array('typeCode'=>'COMP'));
1303 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
1305 $tempID = "2.16.840.1.113883.10.20.27.3.9";
1306 $xml->self_templateid($tempID);
1308 $tempID = "2.16.840.1.113883.10.20.24.3.55";
1309 $xml->self_templateid($tempID);
1311 $tempID = "2.16.840.1.113883.10.20.27.3.18";
1312 $xml->self_templateid($tempID);
1314 $xml->self_setpatientRoleid();
1316 $arr = array('code'=>'48768-6', 'displayName'=>'Payment source', 'codeSystem'=>'2.16.840.1.113883.6.1', 'codeSystemName'=>'SNOMED-CT');
1317 $xml->self_codeCustom($arr);
1319 $arr = array('code'=>'completed');
1320 $xml->self_customTag('statusCode', $arr);
1322 $timeArr = array('low'=>date('Ymd', strtotime($from_date)));
1323 $xml->add_entryEffectTime($timeArr);
1327 $xml->open_customTag('value', array('xsi:type'=>'CD', 'nullFlavor'=>'OTH'));
1329 $xml->self_customTag('translation', array('code'=>$PKey, 'displayName'=>$PVal, 'codeSystem'=>'2.16.840.1.113883.3.249.12', 'codeSystemName'=>'CMS Clinical Codes'));
1332 $xml->close_customTag();
1336 $xml->self_customTag('value', array('xsi:type'=>'CD', 'code'=>$mainQrdaPayerCodeSendArr[$PKey], 'codeSystem'=>'2.16.840.1.113883.3.221.5' , 'codeSystemName'=>'SOP', 'displayName'=>$PVal));
1338 //entryRelationship Open
1339 $xml->open_customTag('entryRelationship', array('typeCode'=>'SUBJ', 'inversionInd'=>'true'));
1342 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
1344 $tempID = "2.16.840.1.113883.10.20.27.3.3";
1345 $xml->self_templateid($tempID);
1347 $tempID = "2.16.840.1.113883.10.20.27.3.24";
1348 $xml->self_templateid($tempID);
1350 $arr = array('code'=>'MSRAGG', 'displayName'=>'rate aggregation', 'codeSystem'=>'2.16.840.1.113883.5.4', 'codeSystemName'=>'ActCode');
1351 $xml->self_codeCustom($arr);
1353 //$arr = array('code'=>'completed');
1354 //$xml->self_customTag('statusCode', $arr);
1356 $arr = array('xsi:type'=>'INT', 'value'=>$payerCheckArr[$PVal]);
1357 $xml->self_customTag('value', $arr);
1359 $arr = array('code'=>'COUNT', 'displayName'=>'Count', 'codeSystem'=>'2.16.840.1.113883.5.84', 'codeSystemName'=>'ObservationMethod');
1360 $xml->self_customTag('methodCode', $arr);
1363 $xml->close_customTag();
1365 //entryRelationship Close
1366 $xml->close_customTag();
1370 $xml->close_customTag();
1372 //entryRelationship Close
1373 $xml->close_customTag();
1376 ####################################################
1377 ####################################################
1378 //Payer Supplemental Data Element (CMS EP) END
1379 ####################################################
1380 ####################################################
1382 ######################################################################
1384 $arr = array('typeCode'=>'REFR');
1385 $xml->open_customTag('reference', $arr);
1387 //externalObservation Start
1388 $arr = array('classCode'=>'OBS', 'moodCode'=>'EVN');
1389 $xml->open_customTag('externalObservation', $arr);
1391 //Modified HQMF_ID for CQM IDS
1392 if( ($row['cqm_nqf_code'] == "0421" ) ){
1393 $refID = $preDefPopIdArr[$row['cqm_nqf_code']][$row['numerator_label']][$mainQrdaPopulationIncArr[$cqmKey]];
1394 }else if( ($row['cqm_nqf_code'] == "0024") ){
1395 $refID = $preDefPopIdArr[$row['cqm_nqf_code']][$row['population_label']][$row['numerator_label']][$mainQrdaPopulationIncArr[$cqmKey]];
1397 $refID = $preDefPopIdArr[$row['cqm_nqf_code']][$mainQrdaPopulationIncArr[$cqmKey]];
1402 $xml->self_customId($refID);
1404 //externalObservation Close
1405 $xml->close_customTag();
1408 $xml->close_customTag();
1409 ########################################################################
1412 $xml->close_customTag();
1414 $xml->close_loopComponent();
1415 ############### Initial patient population template END#####################
1418 //Multiple Numerator Handling
1419 if(in_array($row['cqm_nqf_code'], $multNumNQFArr)){
1420 //Skipping Multiple Numerator(s)
1421 if(in_array($row['cqm_nqf_code'], $multNumNQFArr)){
1422 $skipMultNumArr[$row['cqm_nqf_code']] = true;
1424 if($dataChkArr[$row['cqm_nqf_code']] == $countNumNQFArr[$row['cqm_nqf_code']]){
1426 $xml->close_customTag();
1427 $xml->close_entry();
1431 $xml->close_customTag();
1432 $xml->close_entry();
1435 ###########################################################
1441 #######################################################################
1442 ######################### QUALITY MEASURES END ########################
1443 #######################################################################
1446 $xml->close_section();
1448 $xml->close_loopComponent();
1450 ##################### LOOP Component(s) END ########################
1452 $xml->close_structuredBody();
1453 ############### Structure Body Close #######################
1455 $xml->close_mainComponent();
1456 ############### Main Component Close #######################
1458 //Close Main Clinical Document
1459 $xml->close_clinicaldocument();
1462 //QRDA File Download Folder in site/cqm_qrda folder
1463 $qrda_fname = "QRDA_III_".date("YmdHis").".xml";
1464 $qrda_file_path = $GLOBALS['OE_SITE_DIR'] . "/documents/cqm_qrda/";
1465 if(!file_exists($qrda_file_path)){
1466 mkdir($qrda_file_path, 0777, true);
1468 $qrda_file_name = $qrda_file_path.$qrda_fname;
1469 $fileQRDAOPen = fopen($qrda_file_name, "w");
1470 fwrite($fileQRDAOPen, trim($xml->getXml()));
1471 fclose($fileQRDAOPen);
1476 <?php
html_header_show();?
>
1477 <link rel
=stylesheet href
="<?php echo $css_header;?>" type
="text/css">
1478 <title
><?php
echo xlt('Export QRDA Report'); ?
></title
>
1480 <script type
="text/javascript">
1482 function closeme() {
1489 <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
>
1494 <a href
="qrda_download.php?qrda_fname=<?php echo attr($qrda_fname);?>"><?php
echo xlt("Download QRDA Category III File");?
></a
>
1496 <textarea rows
='50' cols
='500' style
='width:95%' readonly
>
1497 <?php
echo trim($xml->getXml()); ?
>
1500 <p
><input type
='button' value
='<?php echo xla('Close
'); ?>' onclick
='closeme();' /></p
>