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 "qrda_functions.php";
40 //Remove time limit, since script can take many minutes
43 //DENEXCEP NOT NEEDED rules
44 $denExcepNotNeedRules = array('0002', '0018', '0024', '0038', '0043', '0059', '0421');
46 //Predefined QRDA HQMF ID's for CQM rules
47 $preDefinedUniqIDRules = array();
48 $preDefPopIdArr = array();
50 // CMS147v4/0041 - Preventive Care and Screening: Influenza Immunization HQMF ID: 40280381-4600-425F-0146-EE66F0005509
51 $preDefinedUniqIDRules['0041'] = '40280381-4600-425F-0146-EE66F0005509';
52 $preDefPopIdArr['0041']['IPP'] = 'F48702E6-D39A-49D8-BE3C-8FAB5C6AADDA';
53 $preDefPopIdArr['0041']['DENOM'] = 'B61EC2DC-0841-4906-A84B-5BE5024DA7F1';
54 $preDefPopIdArr['0041']['NUMER'] = '0ED7B212-369B-489A-A5B5-07BC146FA557';
55 $preDefPopIdArr['0041']['DENEXCEP'] = 'B5C9EC50-3011-43DC-AD07-CED2D3B770B2';
57 // CMS122v3/0059 - Diabetes: Hemoglobin A1c Poor Control: HQMF_ID: 40280381-4555-E1C1-0145-90AC70DE2C73
58 $preDefinedUniqIDRules['0059'] = '40280381-4555-E1C1-0145-90AC70DE2C73';
59 $preDefPopIdArr['0059']['IPP'] = 'EDED90E9-E4FE-47E6-90AC-29D9AA3E861A';
60 $preDefPopIdArr['0059']['DENOM'] = '6721D6DA-E87D-4E42-A34A-C8490686598C';
61 $preDefPopIdArr['0059']['NUMER'] = '7549BA9E-1841-4231-8CAA-095BDF0AB8A1';
64 //CMS139v3/0101 - Falls: Screening for Future Fall Risk: HQMF_ID: 40280381-4555-E1C1-0145-672613970D15
65 $preDefinedUniqIDRules['0101'] = '40280381-4555-E1C1-0145-672613970D15';
66 $preDefPopIdArr['0101']['IPP'] = '2448B0C6-6848-4DCB-AA6D-F199337A2C5C';
67 $preDefPopIdArr['0101']['DENOM'] = 'EC400908-35BE-439B-92A9-231D99CEA9DF';
68 $preDefPopIdArr['0101']['NUMER'] = '663FB12B-0FF4-49AB-80A3-624C5E7DF892';
69 $preDefPopIdArr['0101']['DENEXCEP'] = 'FEC7251A-BF8D-4472-97D8-E2A9C0A42176';
71 //CMS127v3/0043 - Pneumonia Vaccination Status for Older Adults: HQMF_ID: 40280381-4555-E1C1-0145-762578A81C4C
72 $preDefinedUniqIDRules['0043'] = '40280381-4555-E1C1-0145-762578A81C4C';
73 $preDefPopIdArr['0043']['IPP'] = '873AECC7-E15B-49E7-8391-D73A46201E2E';
74 $preDefPopIdArr['0043']['DENOM'] = 'FF7016E1-E8C7-43BA-9D56-2BEF649F36FA';
75 $preDefPopIdArr['0043']['NUMER'] = '201F5A6E-4DDE-43A2-BDFC-CE85A98560DA';
77 //CMS69v3/0421 - Preventive Care and Screening: Body Mass Index (BMI) Screening and Follow-Up Plan: HQMF_ID: 40280381-4555-E1C1-0145-D2B36DBB3FE6
78 $preDefinedUniqIDRules['0421']['Numerator 1'] = '40280381-4555-E1C1-0145-D2B36DBB3FE6';
79 $preDefPopIdArr['0421']['Numerator 1']['IPP'] = '1C936855-E644-44C0-B264-49A28756FDB1';
80 $preDefPopIdArr['0421']['Numerator 1']['DENOM'] = '27F1591C-2060-462C-B5D7-7FE86A44B534';
81 $preDefPopIdArr['0421']['Numerator 1']['DENEX'] = '9B0C3C26-D621-4EA3-81FB-A839A3012044';
82 $preDefPopIdArr['0421']['Numerator 1']['NUMER'] = '3095531C-24D7-4AFB-9BCB-F1901FF0FF69';
84 $preDefinedUniqIDRules['0421']['Numerator 2'] = '40280381-4555-E1C1-0145-D2B36DBB3FE6';
85 $preDefPopIdArr['0421']['Numerator 2']['IPP'] = '6E701B1C-6CA5-4AD5-98C9-5F766745EA89';
86 $preDefPopIdArr['0421']['Numerator 2']['DENOM'] = 'E4DC29B8-EB26-4A01-ABB0-4F99FC03BA39';
87 $preDefPopIdArr['0421']['Numerator 2']['DENEX'] = 'BB1B4301-C275-4BAC-87C9-6E960B1601DA';
88 $preDefPopIdArr['0421']['Numerator 2']['NUMER'] = '7669026D-3683-44CC-A2C5-3D62EB2F8A33';
90 //CMS117v3/0038 - Childhood Immunization Status: HQMF_ID: 40280381-4555-E1C1-0145-D7C003364261
91 $preDefinedUniqIDRules['0038'] = '40280381-4555-E1C1-0145-D7C003364261';
92 $preDefPopIdArr['0038']['IPP'] = '6ED6A787-C871-49B9-825C-70A0DB898977';
93 $preDefPopIdArr['0038']['DENOM'] = '545DA813-89ED-4DCD-BDDF-4B33D93DCD84';
94 $preDefPopIdArr['0038']['NUMER'] = '00193FC7-AEE4-4507-A20F-D25A7BB214AD';
96 //CMS138v3/0028 - Preventive Care and Screening: Tobacco Use: Screening and Cessation Intervention: HQMF_ID: 40280381-4600-425F-0146-1F5867D40E82
97 $preDefinedUniqIDRules['0028'] = '40280381-4600-425F-0146-1F5867D40E82';
98 $preDefPopIdArr['0028']['IPP'] = '4E118B62-2AF8-4F51-9355-6FD3F2427D9F';
99 $preDefPopIdArr['0028']['DENOM'] = 'FA1B3953-AE58-4541-BF7B-84D0EB1B0713';
100 $preDefPopIdArr['0028']['NUMER'] = '35B1A6DF-1871-4633-A74B-BCAE371BC030';
101 $preDefPopIdArr['0028']['DENEXCEP'] = '3EE6DFF5-AB17-482F-A147-E6D1E46DBB79';
103 //CMS157v3/0384 - Oncology: Medical and Radiation – Pain Intensity Quantified: HQMF_ID: 40280381-4600-425F-0146-1F620BDF0EB0
104 $preDefinedUniqIDRules['0384'] = '40280381-4600-425F-0146-1F620BDF0EB0';
105 $preDefPopIdArr['0384']['IPP'] = 'C29B6555-3BC7-416F-B61A-FCACD637594F';
106 $preDefPopIdArr['0384']['DENOM'] = 'E5F80C25-6816-4992-92E2-A735B17F8D4F';
107 $preDefPopIdArr['0384']['NUMER'] = 'C948D0D2-D6E9-4099-9CD4-870F2F83A14C';
109 //CMS146v3/0002 - Appropriate Testing for Children with Pharyngitis: HQMF_ID: 40280381-4600-425F-0146-1F6E280C0F09
110 $preDefinedUniqIDRules['0002'] = '40280381-4600-425F-0146-1F6E280C0F09';
111 $preDefPopIdArr['0002']['IPP'] = '9D1135EA-BA90-45E7-8EED-F7335D1CC934';
112 $preDefPopIdArr['0002']['DENOM'] = 'D04EFECB-A901-4565-BDDB-826510499092';
113 $preDefPopIdArr['0002']['NUMER'] = '3F4CDE57-1C5C-4250-A338-55FED6775F57';
114 $preDefPopIdArr['0002']['DENEX'] = '0525FBA2-F068-4706-ADB5-E345852DC55B';
116 //CMS165v3/0018 - Controlling High Blood Pressure: HQMF_ID: 40280381-4600-425F-0146-1F6F722B0F17
117 $preDefinedUniqIDRules['0018'] = '40280381-4600-425F-0146-1F6F722B0F17';
118 $preDefPopIdArr['0018']['IPP'] = 'A72855CE-3C60-41F9-AEE2-64D4F584DDD4';
119 $preDefPopIdArr['0018']['DENOM'] = '26046A5C-E2CC-4A27-B480-FF7E3575691F';
120 $preDefPopIdArr['0018']['NUMER'] = '0899A359-0CD8-4977-AA29-666892AA3AD4';
121 $preDefPopIdArr['0018']['DENEX'] = '4327D845-6194-410D-A48D-D6E1802CAD55';
123 //CMS155v3/0024 - Weight Assessment and Counseling for Nutrition and Physical Activity for Children and Adolescents: HQMF_ID: 40280381-4555-E1C1-0145-85C7311720F5
124 $preDefinedUniqIDRules['0024']['Population Criteria 1']['Numerator 1'] = '40280381-4555-E1C1-0145-85C7311720F5';
125 $preDefPopIdArr['0024']['Population Criteria 1']['Numerator 1']['IPP'] = '10127790-AE94-4070-9DD3-1D3776D08D7C';
126 $preDefPopIdArr['0024']['Population Criteria 1']['Numerator 1']['DENOM'] = '3B3C1568-F875-49B1-9090-E2F494EECBB6';
127 $preDefPopIdArr['0024']['Population Criteria 1']['Numerator 1']['DENEX'] = 'B288D5A4-D573-4FAA-92D6-0B01E1B35C7A';
128 $preDefPopIdArr['0024']['Population Criteria 1']['Numerator 1']['NUMER'] = 'FD4649BD-B962-4CBE-BF4A-C2F95F3EA08E';
130 $preDefinedUniqIDRules['0024']['Population Criteria 1']['Numerator 2'] = '40280381-4555-E1C1-0145-85C7311720F5';
131 $preDefPopIdArr['0024']['Population Criteria 1']['Numerator 2']['IPP'] = '10127790-AE94-4070-9DD3-1D3776D08D7C';
132 $preDefPopIdArr['0024']['Population Criteria 1']['Numerator 2']['DENOM'] = '3B3C1568-F875-49B1-9090-E2F494EECBB6';
133 $preDefPopIdArr['0024']['Population Criteria 1']['Numerator 2']['DENEX'] = 'B288D5A4-D573-4FAA-92D6-0B01E1B35C7A';
134 $preDefPopIdArr['0024']['Population Criteria 1']['Numerator 2']['NUMER'] = '52FBD726-4DD1-48F5-98B9-7175754923E1';
136 $preDefinedUniqIDRules['0024']['Population Criteria 1']['Numerator 3'] = '40280381-4555-E1C1-0145-85C7311720F5';
137 $preDefPopIdArr['0024']['Population Criteria 1']['Numerator 3']['IPP'] = '10127790-AE94-4070-9DD3-1D3776D08D7C';
138 $preDefPopIdArr['0024']['Population Criteria 1']['Numerator 3']['DENOM'] = '3B3C1568-F875-49B1-9090-E2F494EECBB6';
139 $preDefPopIdArr['0024']['Population Criteria 1']['Numerator 3']['DENEX'] = 'B288D5A4-D573-4FAA-92D6-0B01E1B35C7A';
140 $preDefPopIdArr['0024']['Population Criteria 1']['Numerator 3']['NUMER'] = 'C43CE779-C5EE-4C15-A4CC-AF1C446CFB09';
142 $preDefinedUniqIDRules['0024']['Population Criteria 2']['Numerator 1'] = '40280381-4555-E1C1-0145-85C7311720F5';
143 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 1']['IPP'] = '10127790-AE94-4070-9DD3-1D3776D08D7C';
144 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 1']['DENOM'] = '3B3C1568-F875-49B1-9090-E2F494EECBB6';
145 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 1']['DENEX'] = 'B288D5A4-D573-4FAA-92D6-0B01E1B35C7A';
146 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 1']['NUMER'] = 'FD4649BD-B962-4CBE-BF4A-C2F95F3EA08E';
147 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 1']['STRAT'] = '40280381-3D61-56A7-013E-5D53298E6DA3';
148 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 1']['DISPLAY_TEXT'] = 'BMI Recorded, RS1: 3-11';
150 $preDefinedUniqIDRules['0024']['Population Criteria 2']['Numerator 2'] = '40280381-4555-E1C1-0145-85C7311720F5';
151 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 2']['IPP'] = '10127790-AE94-4070-9DD3-1D3776D08D7C';
152 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 2']['DENOM'] = '3B3C1568-F875-49B1-9090-E2F494EECBB6';
153 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 2']['DENEX'] = 'B288D5A4-D573-4FAA-92D6-0B01E1B35C7A';
154 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 2']['NUMER'] = '52FBD726-4DD1-48F5-98B9-7175754923E1';
155 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 2']['STRAT'] = '40280381-3D61-56A7-013E-5D53298E6DA3';
156 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 2']['DISPLAY_TEXT'] = 'BMI Recorded, RS2: 12-17';
158 $preDefinedUniqIDRules['0024']['Population Criteria 2']['Numerator 3'] = '40280381-4555-E1C1-0145-85C7311720F5';
159 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 3']['IPP'] = '10127790-AE94-4070-9DD3-1D3776D08D7C';
160 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 3']['DENOM'] = '3B3C1568-F875-49B1-9090-E2F494EECBB6';
161 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 3']['DENEX'] = 'B288D5A4-D573-4FAA-92D6-0B01E1B35C7A';
162 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 3']['NUMER'] = 'C43CE779-C5EE-4C15-A4CC-AF1C446CFB09';
163 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 3']['STRAT'] = '40280381-3D61-56A7-013E-5D53298E6DA3';
164 $preDefPopIdArr['0024']['Population Criteria 2']['Numerator 3']['DISPLAY_TEXT'] = 'Nutrition Counseling, RS1: 3-11';
166 $preDefinedUniqIDRules['0024']['Population Criteria 3']['Numerator 1'] = '40280381-4555-E1C1-0145-85C7311720F5';
167 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 1']['IPP'] = '10127790-AE94-4070-9DD3-1D3776D08D7C';
168 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 1']['DENOM'] = '3B3C1568-F875-49B1-9090-E2F494EECBB6';
169 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 1']['DENEX'] = 'B288D5A4-D573-4FAA-92D6-0B01E1B35C7A';
170 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 1']['NUMER'] = 'FD4649BD-B962-4CBE-BF4A-C2F95F3EA08E';
171 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 1']['STRAT'] = '40280381-3D61-56A7-013E-5D532AF06DA5';
172 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 1']['DISPLAY_TEXT'] = 'Nutrition Counseling, RS2: 12-17';
174 $preDefinedUniqIDRules['0024']['Population Criteria 3']['Numerator 2'] = '40280381-4555-E1C1-0145-85C7311720F5';
175 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 2']['IPP'] = '10127790-AE94-4070-9DD3-1D3776D08D7C';
176 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 2']['DENOM'] = '3B3C1568-F875-49B1-9090-E2F494EECBB6';
177 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 2']['DENEX'] = 'B288D5A4-D573-4FAA-92D6-0B01E1B35C7A';
178 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 2']['NUMER'] = '52FBD726-4DD1-48F5-98B9-7175754923E1';
179 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 2']['STRAT'] = '40280381-3D61-56A7-013E-5D532AF06DA5';
180 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 2']['DISPLAY_TEXT'] = 'Physical Activity Counseling, RS1: 3-11';
182 $preDefinedUniqIDRules['0024']['Population Criteria 3']['Numerator 3'] = '40280381-4555-E1C1-0145-85C7311720F5';
183 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 3']['IPP'] = '10127790-AE94-4070-9DD3-1D3776D08D7C';
184 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 3']['DENOM'] = '3B3C1568-F875-49B1-9090-E2F494EECBB6';
185 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 3']['DENEX'] = 'B288D5A4-D573-4FAA-92D6-0B01E1B35C7A';
186 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 3']['NUMER'] = 'C43CE779-C5EE-4C15-A4CC-AF1C446CFB09';
187 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 3']['STRAT'] = '40280381-3D61-56A7-013E-5D532AF06DA5';
188 $preDefPopIdArr['0024']['Population Criteria 3']['Numerator 3']['DISPLAY_TEXT'] = 'Physical Activity Counseling, RS2: 12-17';
190 $preDefPopIdArr['0024']['STRAT1'] = '40280381-3D61-56A7-013E-5D53298E6DA3';
191 $preDefPopIdArr['0024']['STRAT2'] = '40280381-3D61-56A7-013E-5D532AF06DA5';
193 //Multiple Numerator NQF# Array declaration
194 $multNumNQFArr = array('0421', '0024');
195 $countNumNQFArr = array();
196 $countNumNQFArr['0421'] = 2;//two Numerators
197 $countNumNQFArr['0024'] = 9;//Nine Numerators
199 //Initiation of all QRDA needed elements
200 $CQMeausesArr = array();
201 $CQMeausesArr['init_patients'] = "Initial Patient Population";
202 $CQMeausesArr['exclude_patients'] = "Denominator Exclusions";
203 $CQMeausesArr['denom_patients'] = "Denominator";
204 $CQMeausesArr['numer_patients'] = "Numerator";
205 $CQMeausesArr['exception_patients'] = "Denominator Exceptions";
207 $cqmItemizedArr = array();
208 $cqmItemizedArr['init_patients'] = "init_patients";
209 $cqmItemizedArr['exclude_patients'] = "exclude";
210 $cqmItemizedArr['denom_patients'] = "all";
211 $cqmItemizedArr['numer_patients'] = "pass";
212 $cqmItemizedArr['exception_patients'] = "exception";
214 //QRDA Needed Ethnicity
215 $mainEthiArr = array(0=>'Not Hispanic or Latino', 1=>'Hispanic or Latino');
216 $mainEthiCodeArr = array(0=>'2186-5', 1=>'2135-2');
219 $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');
220 $mainQrdaRaceCodeArr = array(0=>'1002-5', 1=>'2028-9', 2=>'2054-5', 3=>'2076-8', 4=>'2106-3', 5=>'2131-1');
222 $mainQrdaPopulationIncArr = array();
223 $mainQrdaPopulationIncArr['init_patients'] = "IPP";
224 $mainQrdaPopulationIncArr['exclude_patients'] = "DENEX";
225 $mainQrdaPopulationIncArr['denom_patients'] = "DENOM";
226 $mainQrdaPopulationIncArr['numer_patients'] = "NUMER";
227 $mainQrdaPopulationIncArr['exception_patients'] = "DENEXCEP";
228 $mainQrdaPopulationIncArr['measure_population'] = "MSRPOPL";
229 $mainQrdaPopulationIncArr['numer_exclusion'] = "NUMEX";
232 $mainQrdaGenderCodeArr = array();
233 $mainQrdaGenderCodeArr['F'] = "Female";
234 $mainQrdaGenderCodeArr['M'] = "Male";
235 $mainQrdaGenderCodeArr['UN'] = "Unknown";
237 //QRDA Needed Payer Info
238 $mainQrdaPayerCodeArr = array();
239 $mainQrdaPayerCodeArr['A'] = "Medicare";
240 $mainQrdaPayerCodeArr['B'] = "Medicaid";
241 $mainQrdaPayerCodeArr['C'] = "Private Health Insurance";
242 $mainQrdaPayerCodeArr['D'] = "Other";
244 //Payer Codes According to Cypress Codes
245 $mainQrdaPayerCodeSendArr = array();
246 $mainQrdaPayerCodeSendArr['A'] = "1";
247 $mainQrdaPayerCodeSendArr['B'] = "2";
248 $mainQrdaPayerCodeSendArr['C'] = "5";
249 $mainQrdaPayerCodeSendArr['D'] = "349";
252 $form_provider = $_GET['form_provider'];
254 //Get Report Information
255 $report_id = $_GET['report_id'];
256 $report_view = collectReportDatabase($report_id);
257 $target_date = $report_view['date_target'];
258 $dataSheet = json_decode($report_view['data'],TRUE);
260 //Needed array for Rule NQF#0024 Stratification
261 $stratumCheckArr = array();
262 if(count($dataSheet) > 0){
264 foreach ($dataSheet as $row) {
265 $itemized_test_id = $row['itemized_test_id'];
266 $numerator_label = $row['numerator_label'];
267 if($row['cqm_nqf_code'] == "0024"){
268 if( $row['population_label'] == "Population Criteria 2" ){
269 if($row['numerator_label'] == "Numerator 1"){
270 $stratum_1_ipp = $row['initial_population'];
271 $stratum_1_exclude = $row['excluded'];
272 $stratum_1_denom = $row['pass_filter'];
273 $stratum_1_numer1 = $row['pass_target'];
274 }else if($row['numerator_label'] == "Numerator 2"){
275 $stratum_1_numer2 = $row['pass_target'];
276 }else if($row['numerator_label'] == "Numerator 3"){
277 $stratum_1_numer3 = $row['pass_target'];
279 }else if( $row['population_label'] == "Population Criteria 3" ){
280 if($row['numerator_label'] == "Numerator 1"){
281 $stratum_2_ipp = $row['initial_population'];
282 $stratum_2_exclude = $row['excluded'];
283 $stratum_2_denom = $row['pass_filter'];
284 $stratum_2_numer1 = $row['pass_target'];
285 }else if($row['numerator_label'] == "Numerator 2"){
286 $stratum_2_numer2 = $row['pass_target'];
287 }else if($row['numerator_label'] == "Numerator 3"){
288 $stratum_2_numer3 = $row['pass_target'];
294 $stratum[1] = array('init_patients' => $stratum_1_ipp,
295 'exclude_patients' => $stratum_1_exclude,
296 'denom_patients' => $stratum_1_denom,
297 'numer_patients' => $stratum_1_numer1,
298 'numer2' => $stratum_1_numer2,
299 'numer3' => $stratum_1_numer3);
301 $stratum[2] = array('init_patients' => $stratum_2_ipp,
302 'exclude_patients' => $stratum_2_exclude,
303 'denom_patients' => $stratum_2_denom,
304 'numer_patients' => $stratum_2_numer1,
305 'numer2' => $stratum_2_numer2,
306 'numer3' => $stratum_2_numer3);
311 $from_date = date('Y', strtotime($target_date ))."-01-01";
312 $to_date = date('Y', strtotime($target_date ))."-12-31";
313 $xml = new QRDAXml();
315 #################################################################################################
316 ####################### HEADER ELEMENTS START #####################################################
317 #################################################################################################
318 //Open Main Clinical Document
319 $xml->open_clinicaldocument();
321 $xml->self_realmcode();
325 $tempId = '2.16.840.1.113883.10.20.27.1.1';
326 $xml->self_templateid($tempId);
328 $xml->unique_id
= getUuid();
332 //Main Title Display to XML
333 $main_title = "QRDA Calculated Summary Report";
334 $xml->add_title($main_title);
336 //Effective date and time
337 $eff_datetime = date('Ymdhis', strtotime($target_date));
338 $xml->self_efftime($eff_datetime);
340 $xml->self_confidentcode();
345 $setidVal =getUuid();
346 $xml->self_setid($setidVal);
349 $xml->self_version();
351 //Record Target Elements
352 $xml->open_recordTarget();
353 $xml->add_patientRole();
354 $xml->close_recordTarget();
356 ############### Author Info #######################
359 $auth_dtime = date('Ymdhis', strtotime(date('Y-m-d H:i:s')));
360 $xml->self_authorTime($auth_dtime);
362 $xml->open_assignAuthor();
363 $authorsetid = getUuid();
364 $xml->self_customId($authorsetid);
365 if($form_provider != ""){
366 $userRow = sqlQuery("SELECT facility, facility_id, federaltaxid, npi, phone,fname, lname FROM users WHERE id=?", array($form_provider));
367 $facility_name = $userRow['facility'];
368 $facility_id = $userRow['facility_id'];
370 //$xml->self_customTag('telecom', array('value' => $userRow['phone'], 'use'=>'WP'));
372 //assignedAuthoringDevice Start
373 $xml->open_customTag('assignedAuthoringDevice');
375 $xml->element('softwareName', 'CYPRESS');
377 //assignedAuthoringDevice Close
378 $xml->close_customTag();
381 $facilResRow = sqlQuery("SELECT name, street,city,state,postal_code, country_code, phone from facility WHERE id = ?", array($facility_id));
382 $xml->add_authReprestOrginisation($facilResRow);
383 //$xml->add_facilAddress($facilResRow);
384 $xml->close_assignAuthor();
385 $xml->close_author();
387 ############### Custodian Info #######################
388 $xml->open_custodian();
389 $xml->open_assgnCustodian();
390 $xml->add_represtCustodianOrginisation($facilResRow);
391 $xml->close_assgnCustodian();
392 $xml->close_custodian();
395 ############### Information Recipient #######################
396 $xml->open_infoRecipient();
397 $xml->add_indententRecipient();
398 $xml->close_infoRecipient();
401 ############### Legal Authenticator #######################
402 $xml->open_legalAuthenticator();
403 $auth_dtime = date('Ymdhis', strtotime(date('Y-m-d H:i:s')));
404 $xml->self_authorTime($auth_dtime);
405 $xml->self_legalSignCode();
407 $xml->open_assignedEntity();
408 $assignedEntityId = getUuid();
409 $xml->self_customId($assignedEntityId);
411 $xml->open_customTag('assignedPerson');
414 $userNameArr = array('fname' =>$userRow['fname'], 'lname'=>$userRow['lname']);
415 $xml->add_providerName($userNameArr);
417 //assignedPerson Close
418 $xml->close_customTag();
420 //Represent Origination Name
421 $xml->add_authReprestOrginisation($facilResRow);
422 $xml->close_assignedEntity();
424 $xml->close_legalAuthenticator();
427 ############### Participant is Device(optional) #######################
428 $participentDevArr = array();
429 $xml->open_participant_data('DEV');//DEV -- Device
430 $xml->open_assocEntityData('RGPR');//RGPR -- Regulated Product
431 $participentDevArr['root'] = '2.16.840.1.113883.3.2074.1';
432 $participentDevArr['extension'] = '1a2b3c';
433 $xml->self_particpantIdInfo($participentDevArr);
434 $xml->self_participantCodeDevice();
435 $xml->close_assocEntityData();
436 $xml->close_participant_data();
438 ############### Participant is Location(optional) #######################
439 $participentLocArr = array();
440 $xml->open_participant_data('LOC');//LOC -- Location
441 $xml->open_assocEntityData('SDLOC');//SDLOC -- Service Delivery Location
442 $participentLocArr['root'] = '2.16.840.1.113883.3.249.5.1';
443 $participentLocArr['extension'] = 'OK666333';
444 $xml->self_particpantIdInfo($participentLocArr);
445 $xml->self_participantCodeLocation();
447 $xml->add_facilAddress($facilResRow);
448 $xml->close_assocEntityData();
449 $xml->close_participant_data();
452 ############### documentationOf START #######################
453 $xml->open_customTag('documentationOf');
455 $xml->open_customTag('serviceEvent', array('classCode'=>'PCPR'));
457 $timeArr = array('low'=>date('Ymd', strtotime($from_date)), 'high'=>date('Ymd', strtotime($to_date)));
458 $xml->add_entryEffectTime($timeArr);
460 $xml->open_customTag('performer', array('typeCode'=>'PRF'));
462 $xml->open_customTag('assignedEntity');
464 $npi_provider = !empty($userRow['npi']) ?
$userRow['npi'] : '123456789';
465 $xml->self_customTag('id', array('root' => '2.16.840.1.113883.4.6', 'extension' =>$npi_provider));
467 if($userRow['phone'] != ""){
468 $xml->self_customTag('telecom', array('value' => $userRow['phone'], 'use'=>'WP'));
471 $xml->open_customTag('assignedPerson');
474 $userNameArr = array('fname' =>$userRow['fname'], 'lname'=>$userRow['lname']);
475 $xml->add_providerName($userNameArr);
477 //assignedPerson Close
478 $xml->close_customTag();
480 $xml->open_customTag('representedOrganization');
482 $tin_provider = $userRow['federaltaxid'];
483 if($tin_provider != ""){
484 $xml->self_customTag('id', array('root' => '2.16.840.1.113883.4.2', 'extension' =>$tin_provider));
487 $xml->add_facilName($facility_name);
489 $xml->add_facilAddress($facilResRow);
491 //representedOrganization Close
492 $xml->close_customTag();
494 //assignedEntity Close
495 $xml->close_customTag();
498 $xml->close_customTag();
501 $xml->close_customTag();
503 //documentationOf Close
504 $xml->close_customTag();
505 ############### documentationOf END #######################
508 ############### authorization (optional) #########################
510 #################################################################################################
511 ####################### HEADER ELEMENTS END #####################################################
512 #################################################################################################
516 #################################################################################################
517 ######################### Main Component Open ###################################################
518 $xml->open_mainComponent();
520 ############### Structure Body Open #######################
521 $xml->open_structuredBody();
523 ##################### LOOP Component(s) START ########################
525 ###################### Report Parameters Open #####################
526 //QRDA Category III Reporting Parameters Section (CMS EP) [section: templateId 2.16.840.1.113883.10.20.27.2.6
527 $xml->open_loopComponent();
529 $xml->open_section();
531 $tempID = '2.16.840.1.113883.10.20.17.2.1';
532 $xml->self_templateid($tempID);
534 $tempID = '2.16.840.1.113883.10.20.27.2.2';
535 $xml->self_templateid($tempID);
537 $tempID = '2.16.840.1.113883.10.20.27.2.6';
538 $xml->self_templateid($tempID);
539 $arr = array('code'=>'55187-9', 'codeSystem'=>'2.16.840.1.113883.6.1');
540 $xml->self_codeCustom($arr);
541 $title = "Reporting Parameters";
542 $xml->add_title($title);
546 $item_title = "Reporting period: ".date('d M Y', strtotime($from_date))." - ".date('d M Y', strtotime($to_date));
547 $xml->add_item($item_title);
552 $xml->open_entry($typeCode);
553 $arr = array('classCode'=>'ACT', 'moodCode'=>'EVN');
554 $xml->open_act($arr);
556 $tempID = '2.16.840.1.113883.10.20.17.3.8';
557 $xml->self_templateid($tempID);
559 $tempID = '2.16.840.1.113883.10.20.27.3.23';
560 $xml->self_templateid($tempID);
563 $xml->self_customId($actId);
565 $arr = array('code'=>'252116004', 'codeSystem'=>'2.16.840.1.113883.6.96', 'displayName'=>'Observation Parameters');
566 $xml->self_codeCustom($arr);
568 $timeArr = array('low'=>date('Ymd', strtotime($from_date)), 'high'=>date('Ymd', strtotime($to_date)));
569 $xml->add_entryEffectTime($timeArr);
574 $xml->close_section();
576 $xml->close_loopComponent();
577 ###################### Report Parameters Close #####################
579 ###################### Measure Section Open #####################
580 $xml->open_loopComponent();
582 $xml->open_section();
584 $tempID = '2.16.840.1.113883.10.20.27.2.1';
585 $xml->self_templateid($tempID);
587 $tempID = '2.16.840.1.113883.10.20.24.2.2';
588 $xml->self_templateid($tempID);
590 $tempID = '2.16.840.1.113883.10.20.27.2.3';
591 $xml->self_templateid($tempID);
593 $arr = array('code'=>'55186-1', 'codeSystem'=>'2.16.840.1.113883.6.1');
594 $xml->self_codeCustom($arr);
595 $title = "Measure Section";
596 $xml->add_title($title);
601 $tabArr = array('border'=>1, 'width'=>'100%');
602 if(count($dataSheet) > 0){
603 $uniqIdArr = array();
606 foreach ($dataSheet as $row) {
607 $itemized_test_id = $row['itemized_test_id'];
608 $numerator_label = $row['numerator_label'];
610 //CQM Rules 2014 set, 0013 is 0018
611 if($row['cqm_nqf_code'] == "0013") $row['cqm_nqf_code'] = "0018";
614 $xml->open_customTag('table', $tabArr);
616 $xml->open_customTag('thead');
618 $xml->open_customTag('tr');
620 $xml->add_trElementsTitles();
623 $xml->close_customTag();
626 $xml->close_customTag();
628 $xml->open_customTag('tbody');
629 $xml->open_customTag('tr');
631 $tdTitle = generate_display_field(array('data_type'=>'1','list_id'=>'clinical_rules'),$row['id']);
633 if (!empty($row['cqm_pqri_code'])) {
634 $tdTitle .= " " . htmlspecialchars( xl('PQRI') . ":" . $row['cqm_pqri_code'], ENT_NOQUOTES
) . " ";
636 if (!empty($row['cqm_nqf_code'])) {
637 $tdTitle .= " " . htmlspecialchars( xl('NQF') . ":" . $row['cqm_nqf_code'], ENT_NOQUOTES
) . " ";
640 if ( !(empty($row['concatenated_label'])) ) {
641 $tdTitle .= ", " . htmlspecialchars( xl( $row['concatenated_label'] ), ENT_NOQUOTES
) . " ";
644 $tdVersionNeutral = getUuid();
646 if($preDefinedUniqIDRules[$row['cqm_nqf_code']] != ""){
647 if( ($row['cqm_nqf_code'] == "0421" ) )
648 $tdVersionSpecific = $preDefinedUniqIDRules[$row['cqm_nqf_code']][$row['numerator_label']];
649 else if($row['cqm_nqf_code'] == "0024")
650 $tdVersionSpecific = $preDefinedUniqIDRules[$row['cqm_nqf_code']][$row['population_label']][$row['numerator_label']];
652 $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){
683 //DENEXCEP(Denominator Exception not needed for some rules are skipping here)
684 if( (in_array($row['cqm_nqf_code'], $denExcepNotNeedRules) ) && ($cqmKey == "exception_patients") ) continue;
687 if($cqmKey == "init_patients")
688 $itemPatArr = collectItemizedPatientsCdrReport($report_id,$itemized_test_id,$cqmItemizedArr[$cqmKey]);
690 $itemPatArr = collectItemizedPatientsCdrReport($report_id,$itemized_test_id,$cqmItemizedArr[$cqmKey], $numerator_label);
691 $fullPatArr = array();
692 foreach($itemPatArr as $itemPatInfo){
693 $fullPatArr[] = $itemPatInfo['pid'];
696 //Initial Patient Population
697 $xml->open_customTag('item');
698 $arrContent = array('name'=>$cqmVal, 'value'=>count($fullPatArr));
699 $xml->innerContent($arrContent);
701 $detailsArr = getQRDAPatientNeedInfo($fullPatArr);
706 //Gender Section Display
707 foreach($mainQrdaGenderCodeArr as $GKey => $GVal){
708 $xml->open_customTag('item');
709 $genderInfo = $detailsArr['gender'][$GVal];
710 $arrContent = array('name'=>$GVal, 'value'=>$genderInfo);
711 $xml->innerContent($arrContent);
712 $xml->close_customTag();
715 //Ethnicity Section Display
716 foreach($mainEthiArr as $ethKey => $ethVal){
717 $ethnicity_data = $detailsArr['ethnicity'][$ethVal];
718 $xml->open_customTag('item');
719 $arrContent = array('name'=>'Ethnicity - '.$ethVal, 'value'=>$ethnicity_data);
720 $xml->innerContent($arrContent);
721 $xml->close_customTag();
724 //Race Section Display
725 foreach($mainQrdaRaceArr as $RKey => $RVal){
726 $race_data = $detailsArr['race'][$RVal];
727 $xml->open_customTag('item');
728 $arrContent = array('name'=>'Race - '.$RVal, 'value'=>$race_data);
729 $xml->innerContent($arrContent);
730 $xml->close_customTag();
733 //Payer Type Section Display
734 $payerCheckArr = getQRDAPayerInfo($fullPatArr);
735 foreach($mainQrdaPayerCodeArr as $PKey => $PVal){
736 $xml->open_customTag('item');
737 $arrContent = array('name'=>'Payer - '.$PVal, 'value'=>$payerCheckArr[$PVal]);
738 $xml->innerContent($arrContent);
739 $xml->close_customTag();
744 $xml->close_customTag();
752 #######################################################################
753 ######################### QUALITY MEASURES START ######################
754 #######################################################################
755 if(count($dataSheet) > 0){
757 $skipMultNumArr = array();
758 $dataChkArr = array();
759 foreach($multNumNQFArr as $multNumVal){
760 $skipMultNumArr[$multNumVal] = false;
761 $dataChkArr[$multNumVal] = 0;
765 foreach ($dataSheet as $row) {
766 $itemized_test_id = $row['itemized_test_id'];
767 $numerator_label = $row['numerator_label'];
769 //if($row['cqm_nqf_code'] == "0028a") continue;
771 //if($row['cqm_nqf_code'] == "0038"){
772 // if(in_array($row['numerator_label'], $NQF38NumArr)) continue;
775 if(in_array($row['cqm_nqf_code'], $multNumNQFArr)){
776 $dataChkArr[$row['cqm_nqf_code']]++
;
779 //CQM Rules 2014 set, 0013 is 0018
780 if($row['cqm_nqf_code'] == "0013") $row['cqm_nqf_code'] = "0018";
782 $tdTitle = generate_display_field(array('data_type'=>'1','list_id'=>'clinical_rules'),$row['id']);
783 if (!empty($row['cqm_pqri_code'])) {
784 $tdTitle .= " " . text( xl('PQRI') . ":" . $row['cqm_pqri_code']) . " ";
786 if (!empty($row['cqm_nqf_code'])) {
787 $tdTitle .= " " . text( xl('NQF') . ":" . $row['cqm_nqf_code']) . " ";
790 if ( !(empty($row['concatenated_label'])) ) {
791 $tdTitle .= ", " . text( xl( $row['concatenated_label'] )) . " ";
794 ###########################################################
795 if( ( !isset($skipMultNumArr[$row['cqm_nqf_code']]) ) ||
($skipMultNumArr[$row['cqm_nqf_code']] == false) ){
801 $arr = array('classCode'=>'CLUSTER', 'moodCode'=>'EVN');
802 $xml->open_customTag('organizer', $arr);
804 $tempID = "2.16.840.1.113883.10.20.24.3.98";
805 $xml->self_templateid($tempID);
807 $tempID = "2.16.840.1.113883.10.20.27.3.1";
808 $xml->self_templateid($tempID);
810 //$tempID = "2.16.840.1.113883.10.20.27.3.17";
811 //$xml->self_templateid($tempID);
813 $xml->self_customId($actId);
815 $arr = array('code'=>'completed');
816 $xml->self_customTag('statusCode', $arr);
819 $arr = array('typeCode'=>'REFR');
820 $xml->open_customTag('reference', $arr);
822 //externalDocument Start
823 $arr = array('classCode'=>'DOC', 'moodCode'=>'EVN');
824 $xml->open_customTag('externalDocument', $arr);
826 //$exDocID = getUuid();
827 $exDocID = $uniqIdArr[$innrCnt];
828 //$xml->self_customId($exDocID);
829 $xml->self_customTag('id', array('root' => '2.16.840.1.113883.4.738', 'extension' =>$exDocID));
831 $arr = array('code'=>'57024-2', 'displayName'=>'Health Quality Measure Document', 'codeSystem'=>'2.16.840.1.113883.6.1', 'codeSystemName'=>'LOINC');
832 $xml->self_codeCustom($arr);
834 $dispContntTitle = str_replace("&", '', $tdTitle);
835 $xml->textDispContent($dispContntTitle);
837 //externalDocument Close
838 $xml->close_customTag();
841 $xml->close_customTag();
844 ############### Performance Rate for Proportion Measure template START###################
845 $xml->open_loopComponent();
848 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
850 $tempID = "2.16.840.1.113883.10.20.27.3.14";
851 $xml->self_templateid($tempID);
853 $tempID = "2.16.840.1.113883.10.20.27.3.25";
854 $xml->self_templateid($tempID);
856 $arr = array('code'=>'72510-1', 'displayName'=>'Performance Rate', 'codeSystem'=>'2.16.840.1.113883.6.1', 'codeSystemName'=>'SNOMED-CT');
857 $xml->self_codeCustom($arr);
859 $arr = array('code'=>'completed');
860 $xml->self_customTag('statusCode', $arr);
862 $percentage = str_replace("%", '', $row['percentage']);
863 $arr = array('xsi:type'=>'REAL', 'value'=>$percentage/100);
864 $xml->self_customTag('value', $arr);
867 $arr = array('typeCode'=>'REFR');
868 $xml->open_customTag('reference', $arr);
870 //externalObservation Start
871 $arr = array('classCode'=>'OBS', 'moodCode'=>'EVN');
872 $xml->open_customTag('externalObservation', $arr);
875 //$exDocID = getUuid();
878 if( ($row['cqm_nqf_code'] == "0421" )){
879 $exDocID = $preDefPopIdArr[$row['cqm_nqf_code']][$row['numerator_label']]["NUMER"];
880 }else if(($row['cqm_nqf_code'] == "0024")){
881 $exDocID = $preDefPopIdArr[$row['cqm_nqf_code']][$row['population_label']][$row['numerator_label']]["NUMER"];
883 if($preDefPopIdArr[$row['cqm_nqf_code']]["NUMER"] != "")
884 $exDocID = $preDefPopIdArr[$row['cqm_nqf_code']]["NUMER"];
886 $exDocID = getUuid();
889 $xml->self_customId($exDocID);
891 $arr = array('code'=>'NUMER', 'displayName'=>'Numerator', 'codeSystem'=>'2.16.840.1.113883.5.1063', 'codeSystemName'=>'ObservationValue');
892 $xml->self_codeCustom($arr);
894 //externalObservation Close
895 $xml->close_customTag();
898 $xml->close_customTag();
901 $xml->close_customTag();
903 $xml->close_loopComponent();
904 ############### Performance Rate for Proportion Measure template END ###################
908 //All CQM Measures taken here
909 foreach($CQMeausesArr as $cqmKey => $cqmVal){
911 //DENEXCEP(Denominator Exception not needed for some rules are skipping here)
912 if( (in_array($row['cqm_nqf_code'], $denExcepNotNeedRules) ) && ($cqmKey == "exception_patients") ) continue;
914 //cqm 0024 alllowing only nuemerator 2 and numerator 3 for ipp1,ipp2 and 1pp3 to avoid repeatation
915 if($row['cqm_nqf_code'] == '0024' && ($row['numerator_label'] == "Numerator 2" ||
$row['numerator_label'] == "Numerator 3") && $cqmKey != 'numer_patients') continue;
916 if($row['cqm_nqf_code'] == '0024' && ($row['population_label'] == "Population Criteria 2" ||
$row['population_label'] == "Population Criteria 3")) continue;
920 if($cqmKey == "init_patients")
921 $itemPatArr = collectItemizedPatientsCdrReport($report_id,$itemized_test_id,$cqmItemizedArr[$cqmKey]);
923 $itemPatArr = collectItemizedPatientsCdrReport($report_id,$itemized_test_id,$cqmItemizedArr[$cqmKey], $numerator_label);
925 $fullPatArr = array();
926 foreach($itemPatArr as $itemPatInfo){
927 $fullPatArr[] = $itemPatInfo['pid'];
930 $detailsArr = getQRDAPatientNeedInfo($fullPatArr);
931 ############### Initial patient population template START###################
932 $xml->open_loopComponent();
935 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
937 $tempID = "2.16.840.1.113883.10.20.27.3.5";
938 $xml->self_templateid($tempID);
940 $tempID = "2.16.840.1.113883.10.20.27.3.16";
941 $xml->self_templateid($tempID);
943 $arr = array('code'=>'ASSERTION', 'displayName'=>'Assertion', 'codeSystem'=>'2.16.840.1.113883.5.4', 'codeSystemName'=>'ActCode');
944 $xml->self_codeCustom($arr);
946 $arr = array('code'=>'completed');
947 $xml->self_customTag('statusCode', $arr);
949 $arr = array('xsi:type'=>'CD', 'code'=>$mainQrdaPopulationIncArr[$cqmKey], 'displayName'=>$cqmVal, 'codeSystem' =>'2.16.840.1.113883.5.1063', 'codeSystemName'=>'ObservationValue');
950 $xml->self_customTag('value', $arr);
952 //entryRelationship Open
953 $xml->open_customTag('entryRelationship', array('typeCode'=>'SUBJ', 'inversionInd'=>'true'));
956 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
958 $tempID = "2.16.840.1.113883.10.20.27.3.3";
959 $xml->self_templateid($tempID);
961 $tempID = "2.16.840.1.113883.10.20.27.3.24";
962 $xml->self_templateid($tempID);
964 $arr = array('code'=>'MSRAGG', 'displayName'=>'rate aggregation', 'codeSystem'=>'2.16.840.1.113883.5.4', 'codeSystemName'=>'ActCode');
965 $xml->self_codeCustom($arr);
967 //$arr = array('code'=>'completed');
968 //$xml->self_customTag('statusCode', $arr);
970 $arr = array('xsi:type'=>'INT', 'value'=>count($fullPatArr));
971 $xml->self_customTag('value', $arr);
973 $arr = array('code'=>'COUNT', 'displayName'=>'Count', 'codeSystem'=>'2.16.840.1.113883.5.84', 'codeSystemName'=>'ObservationMethod');
974 $xml->self_customTag('methodCode', $arr);
977 $xml->close_customTag();
979 //entryRelationship Close
980 $xml->close_customTag();
982 #### Stratum Start (Stratification)#####
983 if($row['cqm_nqf_code'] == '0024'){
985 for(;$strat_count <= 2;$strat_count++
){
987 $strata_value = $stratum[$strat_count][$cqmKey];
989 if($row['numerator_label'] == "Numerator 2") $strata_value = $stratum[$strat_count]['numer2'];
991 else if($row['numerator_label'] == "Numerator 3") $strata_value = $stratum[$strat_count]['numer3'];
993 //entryRelationship Open
994 $xml->open_customTag('entryRelationship', array('typeCode'=>'COMP'));
997 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
999 $tempID = "2.16.840.1.113883.10.20.27.3.4";
1000 $xml->self_templateid($tempID);
1002 $tempID = "2.16.840.1.113883.10.20.27.3.20";
1003 $xml->self_templateid($tempID);
1005 $arr = array('code'=>'ASSERTION', 'displayName'=>'Assertion', 'codeSystem'=>'2.16.840.1.113883.5.4', 'codeSystemName'=>'ActCode');
1006 $xml->self_codeCustom($arr);
1008 $arr = array('code'=>'completed');
1009 $xml->self_customTag('statusCode', $arr);
1012 $xml->open_customTag('value', array('xsi:type'=>'CD', 'nullFlavor'=>'OTH'));
1014 $stratumText = $preDefPopIdArr[$row['cqm_nqf_code']][$row['population_label']][$row['numerator_label']]['DISPLAY_TEXT'];
1015 $xml->element('originalText', "Stratum ".$strat_count);
1018 $xml->close_customTag();
1020 //entryRelationship Open
1021 $xml->open_customTag('entryRelationship', array('typeCode'=>'SUBJ', 'inversionInd' => 'true'));
1024 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
1026 $tempID = "2.16.840.1.113883.10.20.27.3.3";
1027 $xml->self_templateid($tempID);
1029 $arr = array('code'=>'MSRAGG', 'displayName'=>'rate aggregation', 'codeSystem'=>'2.16.840.1.113883.5.4', 'codeSystemName'=>'ActCode');
1030 $xml->self_codeCustom($arr);
1032 $arr = array('xsi:type'=>'INT', 'value'=>$strata_value);
1033 $xml->self_customTag('value', $arr);
1035 $arr = array('code'=>'COUNT', 'displayName'=>'Count', 'codeSystem'=>'2.16.840.1.113883.5.84', 'codeSystemName'=>'ObservationMethod');
1036 $xml->self_customTag('methodCode', $arr);
1039 $xml->close_customTag();
1041 //entryRelationship Close
1042 $xml->close_customTag();
1045 $arr = array('typeCode'=>'REFR');
1046 $xml->open_customTag('reference', $arr);
1048 //externalObservation Start
1049 $arr = array('classCode'=>'OBS', 'moodCode'=>'EVN');
1050 $xml->open_customTag('externalObservation', $arr);
1052 //Modified HQMF_ID for CQM IDS
1053 //$refID = $preDefPopIdArr[$row['cqm_nqf_code']][$row['population_label']][$row['numerator_label']]['STRAT'];
1054 $refID = $preDefPopIdArr[$row['cqm_nqf_code']]['STRAT'.$strat_count];
1056 $xml->self_customId($refID);
1058 //externalObservation Close
1059 $xml->close_customTag();
1062 $xml->close_customTag();
1065 $xml->close_customTag();
1067 //entryRelationship Close
1068 $xml->close_customTag();
1072 #### Stratum END #####
1074 ####################################################
1075 ####################################################
1076 //Sex Supplemental Data Element START
1077 ####################################################
1078 ####################################################
1080 foreach($mainQrdaGenderCodeArr as $GKey => $GVal){
1081 //entryRelationship Open
1082 $xml->open_customTag('entryRelationship', array('typeCode'=>'COMP'));
1085 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
1087 $tempID = "2.16.840.1.113883.10.20.27.3.6";
1088 $xml->self_templateid($tempID);
1090 $tempID = "2.16.840.1.113883.10.20.27.3.21";
1091 $xml->self_templateid($tempID);
1093 $arr = array('code'=>'184100006', 'displayName'=>'patient sex', 'codeSystem'=>'2.16.840.1.113883.6.96', 'codeSystemName'=>'SNOMED-CT');
1094 $xml->self_codeCustom($arr);
1096 $arr = array('code'=>'completed');
1097 $xml->self_customTag('statusCode', $arr);
1099 $arr = array('xsi:type'=>'CD', 'code'=>$GKey, 'codeSystem' =>'2.16.840.1.113883.5.1', 'codeSystemName'=>'AdministrativeGenderCode');
1100 $xml->self_customTag('value', $arr);
1102 //entryRelationship Open
1103 $xml->open_customTag('entryRelationship', array('typeCode'=>'SUBJ', 'inversionInd'=>'true'));
1106 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
1108 $tempID = "2.16.840.1.113883.10.20.27.3.3";
1109 $xml->self_templateid($tempID);
1111 $tempID = "2.16.840.1.113883.10.20.27.3.24";
1112 $xml->self_templateid($tempID);
1114 $arr = array('code'=>'MSRAGG', 'displayName'=>'rate aggregation', 'codeSystem'=>'2.16.840.1.113883.5.4', 'codeSystemName'=>'ActCode');
1115 $xml->self_codeCustom($arr);
1117 //$arr = array('code'=>'completed');
1118 //$xml->self_customTag('statusCode', $arr);
1120 $arr = array('xsi:type'=>'INT', 'value'=>$detailsArr['gender'][$GVal]);
1121 $xml->self_customTag('value', $arr);
1123 $arr = array('code'=>'COUNT', 'displayName'=>'Count', 'codeSystem'=>'2.16.840.1.113883.5.84', 'codeSystemName'=>'ObservationMethod');
1124 $xml->self_customTag('methodCode', $arr);
1127 $xml->close_customTag();
1129 //entryRelationship Close
1130 $xml->close_customTag();
1134 $xml->close_customTag();
1136 //entryRelationship Close
1137 $xml->close_customTag();
1139 ####################################################
1140 ####################################################
1141 //Sex Supplemental Data Element END
1142 ####################################################
1143 ####################################################
1145 ####################################################
1146 ####################################################
1147 //Ethnicity Supplemental Data Element (CMS EP) START
1148 ####################################################
1149 ####################################################
1151 foreach($mainEthiArr as $ethKey => $ethVal){
1152 //entryRelationship Open
1153 $xml->open_customTag('entryRelationship', array('typeCode'=>'COMP'));
1156 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
1158 $tempID = "2.16.840.1.113883.10.20.27.3.7";
1159 $xml->self_templateid($tempID);
1161 $tempID = "2.16.840.1.113883.10.20.27.3.22";
1162 $xml->self_templateid($tempID);
1164 $arr = array('code'=>'364699009', 'displayName'=>'Ethnic Group', 'codeSystem'=>'2.16.840.1.113883.6.96', 'codeSystemName'=>'SNOMED-CT');
1165 $xml->self_codeCustom($arr);
1167 $arr = array('code'=>'completed');
1168 $xml->self_customTag('statusCode', $arr);
1170 $arr = array('xsi:type'=>'CD', 'code'=>$mainEthiCodeArr[$ethKey], 'displayName'=>$ethVal, 'codeSystem' =>'2.16.840.1.113883.6.238', 'codeSystemName'=>'Race & Ethnicity - CDC');
1171 $xml->self_customTag('value', $arr);
1173 //entryRelationship Open
1174 $xml->open_customTag('entryRelationship', array('typeCode'=>'SUBJ', 'inversionInd'=>'true'));
1177 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
1179 $tempID = "2.16.840.1.113883.10.20.27.3.3";
1180 $xml->self_templateid($tempID);
1182 $tempID = "2.16.840.1.113883.10.20.27.3.24";
1183 $xml->self_templateid($tempID);
1185 $arr = array('code'=>'MSRAGG', 'displayName'=>'rate aggregation', 'codeSystem'=>'2.16.840.1.113883.5.4', 'codeSystemName'=>'ActCode');
1186 $xml->self_codeCustom($arr);
1188 //$arr = array('code'=>'completed');
1189 //$xml->self_customTag('statusCode', $arr);
1191 $arr = array('xsi:type'=>'INT', 'value'=>$detailsArr['ethnicity'][$ethVal]);
1192 $xml->self_customTag('value', $arr);
1194 $arr = array('code'=>'COUNT', 'displayName'=>'Count', 'codeSystem'=>'2.16.840.1.113883.5.84', 'codeSystemName'=>'ObservationMethod');
1195 $xml->self_customTag('methodCode', $arr);
1198 $xml->close_customTag();
1200 //entryRelationship Close
1201 $xml->close_customTag();
1205 $xml->close_customTag();
1207 //entryRelationship Close
1208 $xml->close_customTag();
1211 ####################################################
1212 ####################################################
1213 //Ethnicity Supplemental Data Element (CMS EP) END
1214 ####################################################
1215 ####################################################
1218 ####################################################
1219 ####################################################
1220 //Race Supplemental Data Element (CMS EP) START
1221 ####################################################
1222 ####################################################
1224 foreach($mainQrdaRaceArr as $RKey => $RVal){
1225 //entryRelationship Open
1226 $xml->open_customTag('entryRelationship', array('typeCode'=>'COMP'));
1229 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
1231 $tempID = "2.16.840.1.113883.10.20.27.3.8";
1232 $xml->self_templateid($tempID);
1234 $tempID = "2.16.840.1.113883.10.20.27.3.19";
1235 $xml->self_templateid($tempID);
1237 $arr = array('code'=>'103579009', 'displayName'=>'Race', 'codeSystem'=>'2.16.840.1.113883.6.96', 'codeSystemName'=>'SNOMED-CT');
1238 $xml->self_codeCustom($arr);
1240 $arr = array('code'=>'completed');
1241 $xml->self_customTag('statusCode', $arr);
1243 $arr = array('xsi:type'=>'CD', 'code'=>$mainQrdaRaceCodeArr[$RKey], 'displayName'=>$RVal, 'codeSystem' =>'2.16.840.1.113883.6.238', 'codeSystemName'=>'Race & Ethnicity - CDC');
1244 $xml->self_customTag('value', $arr);
1246 //entryRelationship Open
1247 $xml->open_customTag('entryRelationship', array('typeCode'=>'SUBJ', 'inversionInd'=>'true'));
1250 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
1252 $tempID = "2.16.840.1.113883.10.20.27.3.3";
1253 $xml->self_templateid($tempID);
1255 $tempID = "2.16.840.1.113883.10.20.27.3.24";
1256 $xml->self_templateid($tempID);
1258 $arr = array('code'=>'MSRAGG', 'displayName'=>'rate aggregation', 'codeSystem'=>'2.16.840.1.113883.5.4', 'codeSystemName'=>'ActCode');
1259 $xml->self_codeCustom($arr);
1261 //$arr = array('code'=>'completed');
1262 //$xml->self_customTag('statusCode', $arr);
1264 $arr = array('xsi:type'=>'INT', 'value'=>$detailsArr['race'][$RVal]);
1265 $xml->self_customTag('value', $arr);
1267 $arr = array('code'=>'COUNT', 'displayName'=>'Count', 'codeSystem'=>'2.16.840.1.113883.5.84', 'codeSystemName'=>'ObservationMethod');
1268 $xml->self_customTag('methodCode', $arr);
1271 $xml->close_customTag();
1273 //entryRelationship Close
1274 $xml->close_customTag();
1278 $xml->close_customTag();
1280 //entryRelationship Close
1281 $xml->close_customTag();
1284 ####################################################
1285 ####################################################
1286 //Race Supplemental Data Element (CMS EP) END
1287 ####################################################
1288 ####################################################
1291 ####################################################
1292 ####################################################
1293 //Payer Supplemental Data Element (CMS EP) START
1294 ####################################################
1295 ####################################################
1296 $payerCheckArr = getQRDAPayerInfo($fullPatArr);
1297 foreach($mainQrdaPayerCodeArr as $PKey => $PVal){
1298 //entryRelationship Open
1299 $xml->open_customTag('entryRelationship', array('typeCode'=>'COMP'));
1302 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
1304 $tempID = "2.16.840.1.113883.10.20.27.3.9";
1305 $xml->self_templateid($tempID);
1307 $tempID = "2.16.840.1.113883.10.20.24.3.55";
1308 $xml->self_templateid($tempID);
1310 $tempID = "2.16.840.1.113883.10.20.27.3.18";
1311 $xml->self_templateid($tempID);
1313 $xml->self_setpatientRoleid();
1315 $arr = array('code'=>'48768-6', 'displayName'=>'Payment source', 'codeSystem'=>'2.16.840.1.113883.6.1', 'codeSystemName'=>'SNOMED-CT');
1316 $xml->self_codeCustom($arr);
1318 $arr = array('code'=>'completed');
1319 $xml->self_customTag('statusCode', $arr);
1321 $timeArr = array('low'=>date('Ymd', strtotime($from_date)));
1322 $xml->add_entryEffectTime($timeArr);
1326 $xml->open_customTag('value', array('xsi:type'=>'CD', 'nullFlavor'=>'OTH'));
1328 $xml->self_customTag('translation', array('code'=>$PKey, 'displayName'=>$PVal, 'codeSystem'=>'2.16.840.1.113883.3.249.12', 'codeSystemName'=>'CMS Clinical Codes'));
1331 $xml->close_customTag();
1335 $xml->self_customTag('value', array('xsi:type'=>'CD', 'code'=>$mainQrdaPayerCodeSendArr[$PKey], 'codeSystem'=>'2.16.840.1.113883.3.221.5' , 'codeSystemName'=>'SOP', 'displayName'=>$PVal));
1337 //entryRelationship Open
1338 $xml->open_customTag('entryRelationship', array('typeCode'=>'SUBJ', 'inversionInd'=>'true'));
1341 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
1343 $tempID = "2.16.840.1.113883.10.20.27.3.3";
1344 $xml->self_templateid($tempID);
1346 $tempID = "2.16.840.1.113883.10.20.27.3.24";
1347 $xml->self_templateid($tempID);
1349 $arr = array('code'=>'MSRAGG', 'displayName'=>'rate aggregation', 'codeSystem'=>'2.16.840.1.113883.5.4', 'codeSystemName'=>'ActCode');
1350 $xml->self_codeCustom($arr);
1352 //$arr = array('code'=>'completed');
1353 //$xml->self_customTag('statusCode', $arr);
1355 $arr = array('xsi:type'=>'INT', 'value'=>$payerCheckArr[$PVal]);
1356 $xml->self_customTag('value', $arr);
1358 $arr = array('code'=>'COUNT', 'displayName'=>'Count', 'codeSystem'=>'2.16.840.1.113883.5.84', 'codeSystemName'=>'ObservationMethod');
1359 $xml->self_customTag('methodCode', $arr);
1362 $xml->close_customTag();
1364 //entryRelationship Close
1365 $xml->close_customTag();
1369 $xml->close_customTag();
1371 //entryRelationship Close
1372 $xml->close_customTag();
1375 ####################################################
1376 ####################################################
1377 //Payer Supplemental Data Element (CMS EP) END
1378 ####################################################
1379 ####################################################
1381 ######################################################################
1383 $arr = array('typeCode'=>'REFR');
1384 $xml->open_customTag('reference', $arr);
1386 //externalObservation Start
1387 $arr = array('classCode'=>'OBS', 'moodCode'=>'EVN');
1388 $xml->open_customTag('externalObservation', $arr);
1390 //Modified HQMF_ID for CQM IDS
1391 if( ($row['cqm_nqf_code'] == "0421" ) ){
1392 $refID = $preDefPopIdArr[$row['cqm_nqf_code']][$row['numerator_label']][$mainQrdaPopulationIncArr[$cqmKey]];
1393 }else if( ($row['cqm_nqf_code'] == "0024") ){
1394 $refID = $preDefPopIdArr[$row['cqm_nqf_code']][$row['population_label']][$row['numerator_label']][$mainQrdaPopulationIncArr[$cqmKey]];
1396 $refID = $preDefPopIdArr[$row['cqm_nqf_code']][$mainQrdaPopulationIncArr[$cqmKey]];
1401 $xml->self_customId($refID);
1403 //externalObservation Close
1404 $xml->close_customTag();
1407 $xml->close_customTag();
1408 ########################################################################
1411 $xml->close_customTag();
1413 $xml->close_loopComponent();
1414 ############### Initial patient population template END#####################
1417 //Multiple Numerator Handling
1418 if(in_array($row['cqm_nqf_code'], $multNumNQFArr)){
1419 //Skipping Multiple Numerator(s)
1420 if(in_array($row['cqm_nqf_code'], $multNumNQFArr)){
1421 $skipMultNumArr[$row['cqm_nqf_code']] = true;
1423 if($dataChkArr[$row['cqm_nqf_code']] == $countNumNQFArr[$row['cqm_nqf_code']]){
1425 $xml->close_customTag();
1426 $xml->close_entry();
1430 $xml->close_customTag();
1431 $xml->close_entry();
1434 ###########################################################
1440 #######################################################################
1441 ######################### QUALITY MEASURES END ########################
1442 #######################################################################
1445 $xml->close_section();
1447 $xml->close_loopComponent();
1449 ##################### LOOP Component(s) END ########################
1451 $xml->close_structuredBody();
1452 ############### Structure Body Close #######################
1454 $xml->close_mainComponent();
1455 ############### Main Component Close #######################
1457 //Close Main Clinical Document
1458 $xml->close_clinicaldocument();
1461 //QRDA File Download Folder in site/cqm_qrda folder
1462 $qrda_fname = "QRDA_III_".date("YmdHis").".xml";
1463 $qrda_file_path = $GLOBALS['OE_SITE_DIR'] . "/documents/cqm_qrda/";
1464 if(!file_exists($qrda_file_path)){
1465 mkdir($qrda_file_path, 0777, true);
1467 $qrda_file_name = $qrda_file_path.$qrda_fname;
1468 $fileQRDAOPen = fopen($qrda_file_name, "w");
1469 fwrite($fileQRDAOPen, trim($xml->getXml()));
1470 fclose($fileQRDAOPen);
1475 <?php
html_header_show();?
>
1476 <script type
="text/javascript" src
="<?php echo $webroot ?>/interface/main/tabs/js/include_opener.js"></script
>
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
>