minor improvement to tabs style
[openemr.git] / custom / qrda_category1_functions.php
blob7869bfef0f8f8170ab71124636ec9efeb93082e5
1 <?php
2 /**
4 * QRDA Functions
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>;.
19 * @package OpenEMR
20 * @author Ensoftek
21 * @link http://www.open-emr.org
23 // This program exports report to QRDA Category I 2014 XML format.
26 function mainQrdaCatOneGenerate($xml, $patient_id, $rule_id, $provider_id){
27 //Open Main Clinical Document
28 $xml->open_clinicaldocument();
30 //Header Function
31 getHeaderQRDA1($xml, $patient_id, $provider_id);
33 //Component Function
34 getComponentQRDA1($xml, $patient_id, $rule_id);
36 //Close Main Clinical Document
37 $xml->close_clinicaldocument();
39 //Downloaded XML
40 $xmlDynFileName = downloadQRDACat1($xml, $patient_id, $rule_id);
42 return $xmlDynFileName;
45 //Main Header Function
46 function getHeaderQRDA1($xml, $patient_id, $provider_id){
47 global $mainQrdaRaceCodeArr, $mainEthiCodeArr, $from_date, $to_date;
49 //Patient Info
50 if($patient_id != ""){
51 $patientRow = getPatData($patient_id);
53 //User Info
54 $userRow = getUsrDataCheck($provider_id);
55 $facility_name = $userRow['facility'];
56 $facility_id = $userRow['facility_id'];
58 //Facility Info
59 if($facility_id != "")
60 $facilResRow = getFacilDataChk($facility_id);
62 ####################### HEADER ELEMENTS START ##########################################
64 $xml->self_realmcode();
66 $xml->self_typeid();
68 $tempId = '2.16.840.1.113883.10.20.22.1.1';
69 $xml->self_templateid($tempId);
71 $tempId = '2.16.840.1.113883.10.20.24.1.1';
72 $xml->self_templateid($tempId);
74 $tempId = '2.16.840.1.113883.10.20.24.1.2';
75 $xml->self_templateid($tempId);
77 $tempId = '2.16.840.1.113883.10.20.24.1.3';
78 $xml->self_templateid($tempId);
80 $xml->unique_id = getUuid();
81 $xml->self_id();
83 $arr = array('code'=>'55182-0', 'displayName'=>'Quality Measure Report', 'codeSystem'=>'2.16.840.1.113883.6.1', 'codeSystemName'=>'LOINC');
84 $xml->self_codeCustom($arr);
86 //Main Title Display to XML
87 $main_title = "QRDA Category-I Report";
88 $xml->add_title($main_title);
90 //Effective date and time
91 $eff_datetime = date('Ymdhis', strtotime($from_date));
92 $xml->self_efftime($eff_datetime);
94 $xml->self_confidentcode();
96 //Language
97 $xml->self_lang();
99 //Record Target Elements
100 $xml->open_recordTarget();
102 //patientRole Open
103 $xml->open_customTag('patientRole');
105 $xml->self_customTag('id', array('root' => '2.16.840.1.113883.4.572', 'extension' =>'112233'));
107 $xml->add_patientAddress($patientRow);
109 if($patientRow['phone_home'] != "")
110 $xml->self_customTag('telecom', array('value' => $patientRow['phone_home'], 'use'=>'HP'));
111 else
112 $xml->self_customTag('telecom', array('nullFlavor' => "UNK"));
114 $xml->open_customTag('patient');
116 $patNameArr = array('fname' =>$patientRow['fname'], 'lname'=>$patientRow['lname']);
117 $xml->add_patName($patNameArr);
119 if($patientRow['sex'] == "Male") $gender = "M";
120 else if($patientRow['sex'] == "Female") $gender = "F";
121 $xml->self_customTag('administrativeGenderCode', array('codeSystem' => '2.16.840.1.113883.18.2', 'code' =>$gender));
123 $xml->self_customTag('birthTime', array('value' =>date('Ymd', strtotime($patientRow['DOB']))));
125 if($mainQrdaRaceCodeArr[$patientRow['race']] == "") $mainQrdaRaceCodeArr[$patientRow['race']] = "2131-1";
126 $xml->self_customTag('raceCode', array('codeSystem' =>'2.16.840.1.113883.6.238', 'code' => $mainQrdaRaceCodeArr[$patientRow['race']]));
127 $xml->self_customTag('ethnicGroupCode', array('codeSystem' =>'2.16.840.1.113883.6.238', 'code' => $mainEthiCodeArr[$patientRow['ethnicity']]));
129 //patient Close
130 $xml->close_customTag();
132 //patientRole Close
133 $xml->close_customTag();
135 $xml->close_recordTarget();
137 ############### Author Info Start#######################
138 $xml->open_author();
140 //Author time
141 $auth_dtime = date('Ymdhis');
142 $xml->self_authorTime($auth_dtime);
144 //Assigned Author
145 $xml->open_assignAuthor();
146 $npi_provider = empty($userRow['npi']) ? "FakeNPI" : $userRow['npi'];
147 $xml->self_customTag('id', array('root' =>'2.16.840.1.113883.4.6', 'extension' => $npi_provider));
148 $xml->add_patientAddress($facilResRow);
149 if(!empty($userRow['phone']))
150 $xml->self_customTag('telecom', array('value' => $userRow['phone'], 'use'=>'WP'));
151 else
152 $xml->self_customTag('telecom', array("nullFlavor" => "UNK"));
157 //assignedAuthoringDevice Start
158 $xml->open_customTag('assignedAuthoringDevice');
159 $xml->element('manufacturerModelName', 'DrCloudEMR');
160 $xml->element('softwareName', 'DrCloudEMR');
161 //assignedAuthoringDevice Close
162 $xml->close_customTag();
164 $xml->close_assignAuthor();
165 ################## Author Info End ##########################
167 $xml->close_author();
168 ############### Author Info End#######################
170 ############### Custodian Info Start #######################
171 $xml->open_custodian();
172 $xml->open_assgnCustodian();
173 $xml->add_represtCustodianOrginisation($facilResRow);
174 $xml->close_assgnCustodian();
175 $xml->close_custodian();
176 ############### Custodian Info End #######################
178 ############### Legal Authenticator Start#######################
179 $xml->open_legalAuthenticator();
180 $auth_dtime = date('Ymdhis');
181 $xml->self_authorTime($auth_dtime);
182 $xml->self_legalSignCode();
184 $xml->open_assignedEntity();
185 $assignedEntityId = getUuid();
186 $xml->self_customId($assignedEntityId);
187 $xml->add_facilAddress($facilResRow);
188 if(!empty($facilResRow['phone']))
189 $xml->self_customTag('telecom', array('value' => $facilResRow['phone'], 'use'=>'WP'));
190 else
191 $xml->self_customTag('telecom', array("nullFlavor" => "UNK"));
193 $xml->open_customTag('assignedPerson');
195 //Provider Name
196 $userNameArr = array('fname' =>$userRow['fname'], 'lname'=>$userRow['lname']);
197 $xml->add_providerName($userNameArr);
199 //assignedPerson Close
200 $xml->close_customTag();
202 //Represent Origination Name
203 $xml->add_authReprestOrginisation($facilResRow);
204 $xml->close_assignedEntity();
206 $xml->close_legalAuthenticator();
207 ############### Legal Authenticator End#######################
209 ############### documentationOf START #######################
210 $xml->open_customTag('documentationOf');
212 $xml->open_customTag('serviceEvent', array('classCode'=>'PCPR'));
214 $timeArr = array('low'=>date('Ymdhis', strtotime($from_date)), 'high'=>date('Ymdhis', strtotime($to_date)));
215 $xml->add_entryEffectTime($timeArr);
217 $xml->open_customTag('performer', array('typeCode'=>'PRF'));
219 $timeArr = array('low'=>date('Ymdhis', strtotime($from_date)), 'high'=>date('Ymdhis', strtotime($to_date)));
220 $xml->add_entryTime($timeArr);
222 $xml->open_customTag('assignedEntity');
224 $npi_provider = empty($userRow['npi']) ? "FakeNPI" :$userRow['npi'] ;
225 $xml->self_customTag('id', array('root' => '2.16.840.1.113883.4.6', 'extension' =>$npi_provider));
227 if($userRow['phone'] != ""){
228 $xml->self_customTag('telecom', array('value' => $userRow['phone'], 'use'=>'WP'));
230 else
231 $xml->self_customTag('telecom', array("nullFlavor" => "UNK"));
233 $xml->open_customTag('assignedPerson');
235 //Provider Name
236 $userNameArr = array('fname' =>$userRow['fname'], 'lname'=>$userRow['lname']);
237 $xml->add_providerName($userNameArr);
239 //assignedPerson Close
240 $xml->close_customTag();
242 $xml->open_customTag('representedOrganization');
244 $tin_provider = $userRow['federaltaxid'];
245 if($tin_provider != ""){
246 $xml->self_customTag('id', array('root' => '2.16.840.1.113883.4.2', 'extension' =>$tin_provider));
249 $xml->add_facilName($facility_name);
251 $xml->add_facilAddress($facilResRow);
253 //representedOrganization Close
254 $xml->close_customTag();
256 //assignedEntity Close
257 $xml->close_customTag();
259 //performer Close
260 $xml->close_customTag();
262 //serviceEvent Close
263 $xml->close_customTag();
265 //documentationOf Close
266 $xml->close_customTag();
267 ############### documentationOf END #######################
268 ####################### HEADER ELEMENTS END #########################################
271 //Component Function
272 function getComponentQRDA1($xml, $patient_id, $rule_id){
273 //Component Open
274 $xml->open_mainComponent();
276 //structuredBody Open
277 $xml->open_structuredBody();
279 //Measure Section
280 getMeasureSection($xml, $rule_id);
282 //Reporting Parameters
283 getReportingParam($xml);
285 //Patient Data
286 getQRDACat1PatientData($xml, $patient_id);
288 //structuredBody Close
289 $xml->close_structuredBody();
291 //Component Close
292 $xml->close_mainComponent();
295 //Patient Data
296 function getQRDACat1PatientData($xml, $patient_id){
297 $xml->open_loopComponent();
298 $xml->open_section();
300 $tempID = '2.16.840.1.113883.10.20.17.2.4';
301 $xml->self_templateid($tempID);
303 $tempID = '2.16.840.1.113883.10.20.24.2.1';
304 $xml->self_templateid($tempID);
306 $arr = array('code'=>'55188-7', 'codeSystem'=>'2.16.840.1.113883.6.1');
307 $xml->self_codeCustom($arr);
309 $title = "Patient Data";
310 $xml->add_title($title);
312 $xml->element('text', "Patient Data");
314 //Insurance(Payer) Info
315 payerQRDA($xml, $patient_id);
317 //Patient History Info
318 patCharactersticQRDA($xml, $patient_id);
320 //Encounter Section
321 getAllPatientEncounters($xml, $patient_id);
323 //Physical Exams(vitals)
324 getAllPhysicalExams($xml, $patient_id);
326 //Diagnosis (Medical Problems)
327 getAllMedicalProbs($xml, $patient_id);
329 //Ordered Medications
330 getAllOrderMedications($xml, $patient_id);
332 // Active Medications
333 getAllActiveMedications($xml, $patient_id);
335 //Immunization
336 getAllImmunization($xml, $patient_id);
338 //Procedures
339 getAllProcedures($xml, $patient_id);
341 //Lab Tests
342 getAllLabTests($xml, $patient_id);
344 //Interventions
345 getAllInterventionProcedures($xml,$patient_id);
347 //Risk Category Assessment
348 getAllRiskCatAssessment($xml, $patient_id);
350 $xml->close_section();
351 $xml->close_loopComponent();
354 //Immunization
355 function getAllImmunization($xml, $patient_id){
356 global $from_date, $to_date;
357 $medArr = allImmuPat($patient_id, $from_date, $to_date);
359 foreach($medArr as $medRow){
361 $vset = sqlStatement("select * from valueset where code =".add_escape_custom($medRow['cvx_code'])." and code_type = 'cvx' and nqf_code =".add_escape_custom($xml->nqf_code));
362 foreach($vset as $v){
363 if(!empty($v['valueset'])){
364 //Entry open
365 $xml->open_entry();
367 //act open
368 $xml->open_customTag('act', array('classCode'=>'ACT', 'moodCode'=>'EVN'));
370 $tempID = "2.16.840.1.113883.10.20.24.3.42";
371 $xml->self_templateid($tempID);
373 $refID = getUuid();
374 $xml->self_customId($refID);
376 $arr = array('code'=>'416118004', 'codeSystemName'=>'SNOMED CT', 'codeSystem'=>'2.16.840.1.113883.6.96', 'displayName' => 'Administration');
377 $xml->self_codeCustom($arr);
379 if($medRow['status'] == "" || $medRow['status'] == "not_completed")
380 $statusChk = "active";
381 else
382 $statusChk = "completed";
384 $arr = array('code'=>"completed");
385 $xml->self_customTag('statusCode', $arr);
387 $timeArr = array('low'=>date('Ymdhis', strtotime($medRow['administered_date'])), 'high'=>date('Ymdhis', strtotime($medRow['administered_date'])));
388 $xml->add_entryEffectTimeQRDAMed($timeArr);
390 $xml->open_customTag('entryRelationship', array('typeCode'=>'COMP'));
392 //substanceAdministration Open
393 $xml->open_customTag('substanceAdministration', array('classCode'=>'SBADM', 'moodCode'=>'EVN'));
395 $tempID = "2.16.840.1.113883.10.20.22.4.16";
396 $xml->self_templateid($tempID);
398 //$tempID = "2.16.840.1.113883.10.20.24.3.41";
399 //$xml->self_templateid($tempID);
401 $refID = getUuid();
402 $xml->self_customId($refID);
404 $arr = array('code'=>$statusChk);
405 $xml->self_customTag('statusCode', $arr);
407 $timeArr = array('low'=>date('Ymdhis', strtotime($medRow['administered_date'])), 'high'=>date('Ymdhis', strtotime($medRow['administered_date'])));
408 $xml->add_entryEffectTimeQRDAMed($timeArr);
410 //consumable open
411 $xml->open_customTag('consumable');
413 //manufacturedProduct Open
414 $xml->open_customTag('manufacturedProduct', array('classCode'=>'MANU'));
416 $tempID = "2.16.840.1.113883.10.20.22.4.23";
417 $xml->self_templateid($tempID);
419 $actId = getUuid();
420 $xml->self_customId($actId);
422 //manufacturedMaterial open
423 $xml->open_customTag('manufacturedMaterial');
425 $arr = array('code'=>$v['code'], 'codeSystem'=>$v['code_system'],'sdtc:valueSet' => $v['valueset']);
426 $xml->self_codeCustom($arr);
428 //manufacturerOrganization open
429 /*$xml->open_customTag('manufacturerOrganization');
431 $xml->element('name', 'Medication, Administered Vaccine');
433 //manufacturerOrganization Close
434 $xml->close_customTag();*/
436 //manufacturedMaterial Close
437 $xml->close_customTag();
439 //manufacturedProduct Close
440 $xml->close_customTag();
442 //consumable Close
443 $xml->close_customTag();
445 //substanceAdministration Close
446 $xml->close_customTag();
448 //entryRelationship Close
449 $xml->close_customTag();
451 //act Close
452 $xml->close_customTag();
454 //Entry close
455 $xml->close_entry();
461 function getAllPhysicalExams($xml, $patient_id){
462 global $encCheckUniqId, $from_date, $to_date;
464 $vitArr = allVitalsPat( $patient_id, $from_date, $to_date);
465 $measures = array('bps' => array('name' => 'Blood Pressure Systolic','category' => 'Blood Pressure','unit' => 'mmHg','code' => '8480-6'),
466 'bpd' => array('name' => 'Blood Pressure Diastolic','category'=> 'Blood Pressure','unit' => 'mmHg','code' => '8462-4'),
467 'bmi' => array('name' => 'Body Mass Index','category' => 'Body Mass Index', 'unit' => 'kg/m2','code' => '39156-5'));
469 foreach($vitArr as $vitRow){
470 //Entry open
471 foreach($measures as $measure_key => $measure){
472 $vset = sqlQuery("select * from valueset where code = ? and nqf_code = ?",array($measure['code'],$xml->nqf_code));
473 if(!empty($vset['valueset'])){
474 $xml->open_entry();
476 //observation Open
477 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
479 $tempID = "2.16.840.1.113883.10.20.22.4.2";
480 $xml->self_templateid($tempID);
482 $tempID = "2.16.840.1.113883.10.20.24.3.57";
483 $xml->self_templateid($tempID);
485 //$refID = getUuid();
486 $refID = $encCheckUniqId[$vitRow['encounter']];
487 $xml->self_customId($refID);
489 $arr = array('code'=>$measure['code'], 'codeSystem'=>$vset['code_system'],'sdtc:valueSet' => $vset['valueset']);
491 //code Open
492 $xml->open_customTag('code', $arr);
493 $xml->element('originalText', "Physical Exam, Finding: ".$measure['measure']);
494 //code Close
495 $xml->close_customTag();
497 $xml->element('text', "Physical Exam, Finding: ".$measure['category']);
499 $arr = array('code'=>'completed');
500 $xml->self_customTag('statusCode', $arr);
502 $timeArr = array('low'=>date('Ymdhis', strtotime($vitRow['date'])), 'high'=>date('Ymdhis', strtotime($vitRow['date'])));
503 $xml->add_entryEffectTimeQRDA($timeArr);
505 $xml->self_customTag('value', array('xsi:type'=>'PQ', 'value'=>$vitRow[$measure_key], 'unit' => $measure['unit']));
507 //observation Close
508 $xml->close_customTag();
510 //Entry close
511 $xml->close_entry();
517 function getAllRiskCatAssessment($xml, $patient_id){
518 global $encCheckUniqId, $from_date, $to_date;
519 $procArr = allProcPat("risk_category", $patient_id, $from_date, $to_date);
520 foreach($procArr as $procRow){
521 $vset = sqlQuery("select * from valueset where code = ? and nqf_code = ?",array($procRow['procedure_code'],$xml->nqf_code));
522 if(!empty($vset['valueset'])){
523 //Entry open
524 $xml->open_entry();
526 //observation Open
527 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
529 $tempID = "2.16.840.1.113883.10.20.22.4.69";
530 $xml->self_templateid($tempID);
532 $tempID = "2.16.840.1.113883.10.20.24.3.69";
533 $xml->self_templateid($tempID);
535 //$refID = getUuid();
536 $refID = $encCheckUniqId[$procRow['encounter']];
537 $xml->self_customId($refID);
539 $arr = array('code'=>$vset['code'], 'codeSystem'=>$vset['code_system'],'sdtc:valueSet' => $vset['valueset']);
540 //code Open
541 $xml->open_customTag('code', $arr);
542 $xml->element('originalText', $procRow['procedure_name']);
543 //code Close
544 $xml->close_customTag();
546 $xml->element('text', $procRow['procedure_name']);
548 $arr = array('code'=>'completed');
549 $xml->self_customTag('statusCode', $arr);
551 $timeArr = array('low'=>date('Ymdhis', strtotime($procRow['date_ordered'])), 'high'=>date('Ymdhis', strtotime($procRow['date_ordered'])));
552 $xml->add_entryEffectTimeQRDA($timeArr);
554 $xml->self_customTag('value', array('xsi:type'=>'CD', 'nullFlavor'=>'UNK'));
556 //observation Close
557 $xml->close_customTag();
559 //Entry close
560 $xml->close_entry();
565 function getAllProcedures($xml, $patient_id){
566 global $encCheckUniqId, $from_date, $to_date;
567 $procArr = allProcPat("Procedure", $patient_id, $from_date, $to_date);
568 foreach($procArr as $procRow){
569 $vset = sqlQuery("select * from valueset where code = ? and nqf_code = ? ",array($procRow['procedure_code'],$xml->nqf_code));
570 if(!empty($vset['valueset'])){
571 //Entry open
572 $xml->open_entry();
574 //procedure Open
575 $xml->open_customTag('procedure', array('classCode'=>'PROC', 'moodCode'=>'EVN'));
577 $tempID = "2.16.840.1.113883.10.20.24.3.64";
578 $xml->self_templateid($tempID);
580 $tempID = "2.16.840.1.113883.10.20.22.4.14";
581 $xml->self_templateid($tempID);
583 $tempID = "2.16.840.1.113883.10.20.24.3.38";
584 $xml->self_templateid($tempID);
586 $tempID = "2.16.840.1.113883.10.20.24.3.40";
587 $xml->self_templateid($tempID);
589 //$refID = getUuid();
590 $refID = $encCheckUniqId[$procRow['encounter']];
591 $xml->self_customId($refID);
594 $arr = array('code'=>$procRow['procedure_code'], 'codeSystem'=> $vset['code_system'],'sdtc:valueSet' => $vset['valueset']);
595 //code Open
596 $xml->open_customTag('code', $arr);
597 $xml->element('originalText', $procRow['procedure_name']);
598 //code Close
599 $xml->close_customTag();
601 $xml->element('text', $procRow['procedure_name']);
603 $arr = array('code'=>'completed');
604 $xml->self_customTag('statusCode', $arr);
606 $timeArr = array('low'=>date('Ymdhis', strtotime($procRow['date_ordered'])), 'high'=>date('Ymdhis', strtotime($procRow['date_ordered'])));
607 $xml->add_entryEffectTimeQRDA($timeArr);
609 //procedure Close
610 $xml->close_customTag();
612 //Entry close
613 $xml->close_entry();
618 function getAllLabTests($xml, $patient_id){
619 global $encCheckUniqId, $from_date, $to_date;
620 $procArr = allProcPat("laboratory_test", $patient_id, $from_date, $to_date);
621 foreach($procArr as $procRow){
622 $vset = sqlQuery("select * from valueset where code = ? and nqf_code = ? ",array($procRow['procedure_code'],$xml->nqf_code));
623 if(!empty($vset['valueset'])){
624 //Entry open
625 $xml->open_entry();
627 //procedure Open
628 $xml->open_customTag('procedure', array('classCode'=>'PROC', 'moodCode'=>'EVN'));
630 $tempID = "2.16.840.1.113883.10.20.24.3.38";
631 $xml->self_templateid($tempID);
633 //$refID = getUuid();
634 $refID = $encCheckUniqId[$procRow['encounter']];
635 $xml->self_customId($refID);
638 $arr = array('code'=>$procRow['procedure_code'], 'codeSystem'=> $vset['code_system'],'sdtc:valueSet' => $vset['valueset']);
639 //code Open
640 $xml->open_customTag('code', $arr);
641 $xml->element('originalText', $procRow['procedure_name']);
642 //code Close
643 $xml->close_customTag();
645 $xml->element('text', $procRow['procedure_name']);
647 $arr = array('code'=>'completed');
648 $xml->self_customTag('statusCode', $arr);
650 $timeArr = array('low'=>date('Ymdhis', strtotime($procRow['date_ordered'])), 'high'=>date('Ymdhis', strtotime($procRow['date_ordered'])));
651 $xml->add_entryEffectTimeQRDA($timeArr);
653 //procedure Close
654 $xml->close_customTag();
656 //Entry close
657 $xml->close_entry();
663 function getAllInterventionProcedures($xml, $patient_id){
664 global $encCheckUniqId, $from_date, $to_date;
665 $procArr = allProcPat("intervention", $patient_id, $from_date, $to_date);
666 foreach($procArr as $procRow){
667 $vset = sqlQuery("select * from valueset where code = ? and nqf_code = ? ",array($procRow['procedure_code'],$xml->nqf_code));
668 if(!empty($vset['valueset'])){
669 //Entry open
670 $xml->open_entry();
672 //act Open
673 $xml->open_customTag('act', array('classCode'=>'ACT', 'moodCode'=>'EVN'));
675 $tempID = "2.16.840.1.113883.10.20.22.4.12";
676 $xml->self_templateid($tempID);
678 $tempID = "2.16.840.1.113883.10.20.24.3.32";
679 $xml->self_templateid($tempID);
681 //$refID = getUuid();
682 $refID = $encCheckUniqId[$procRow['encounter']];
683 $xml->self_customId($refID);
686 $arr = array('code'=>$procRow['procedure_code'], 'codeSystem'=> $vset['code_system'],'sdtc:valueSet' => $vset['valueset']);
687 //code Open
688 $xml->open_customTag('code', $arr);
689 $xml->element('originalText', $procRow['procedure_name']);
690 //code Close
691 $xml->close_customTag();
693 $xml->element('text', $procRow['procedure_name']);
695 $arr = array('code'=>'completed');
696 $xml->self_customTag('statusCode', $arr);
698 $timeArr = array('low'=>date('Ymdhis', strtotime($procRow['date_ordered'])), 'high'=>date('Ymdhis', strtotime($procRow['date_ordered'])));
699 $xml->add_entryEffectTimeQRDA($timeArr);
701 //act Close
702 $xml->close_customTag();
704 //Entry close
705 $xml->close_entry();
710 function getAllOrderMedications($xml, $patient_id){
711 global $from_date, $to_date;
712 $medArr = allOrderMedsPat($patient_id, $from_date, $to_date);
714 foreach($medArr as $medRow){
715 $vset = sqlQuery("select * from valueset where code = ? and nqf_code = ? ",array($medRow['rxnorm_drugcode'],$xml->nqf_code));
716 if(!empty($vset['valueset'])){
717 //Entry open
718 $xml->open_entry();
720 //substanceAdministration Open
721 $xml->open_customTag('substanceAdministration', array('classCode'=>'SBADM', 'moodCode'=>'RQO'));
723 $tempID = "2.16.840.1.113883.10.20.22.4.42";
724 $xml->self_templateid($tempID);
726 $tempID = "2.16.840.1.113883.10.20.24.3.47";
727 $xml->self_templateid($tempID);
729 $refID = getUuid();
730 $xml->self_customId($refID);
733 $arr = array('code'=>'new');
734 $xml->self_customTag('statusCode', $arr);
736 $timeArr = array('low'=>date('Ymdhis', strtotime($medRow['start_date'])), 'high'=>date('Ymdhis', strtotime($medRow['end_date'])));
737 $xml->add_entryEffectTimeQRDAMed($timeArr);
739 /*if($medRow['enddate'] == ""){
740 if($medRow['drug_interval'] != "" && $medRow['drug_interval'] != "0")
741 $xml->emptyelement('repeatNumber', array('value'=>$medRow['drug_interval']));
743 if($medRow['quantity'] != "")
744 $xml->emptyelement('doseQuantity', array('value'=>$medRow['quantity']));
746 if($medRow['units'] != "" && $medRow['size_type'] != "")
747 $xml->emptyelement('rateQuantity', array('units'=>$medRow['size_type'], 'value'=>$medRow['units']));
750 //consumable open
751 $xml->open_customTag('consumable');
753 //manufacturedProduct Open
754 $xml->open_customTag('manufacturedProduct', array('classCode'=>'MANU'));
756 $tempID = "2.16.840.1.113883.10.20.22.4.23";
757 $xml->self_templateid($tempID);
759 $actId = getUuid();
760 $xml->self_customId($actId);
762 //manufacturedMaterial open
763 $xml->open_customTag('manufacturedMaterial');
765 $arr = array('code'=>$vset['code'], 'codeSystem'=>$vset['code_system'],'sdtc:valueSet' => $vset['valueset']);
766 $xml->self_codeCustom($arr);
768 //manufacturerOrganization open
769 /*$xml->open_customTag('manufacturerOrganization');
771 $xml->element('name', 'Medication Factory Inc.');
773 //manufacturerOrganization Close
774 $xml->close_customTag();*/
776 //manufacturedMaterial Close
777 $xml->close_customTag();
779 //manufacturedProduct Close
780 $xml->close_customTag();
782 //consumable Close
783 $xml->close_customTag();
785 //substanceAdministration Close
786 $xml->close_customTag();
788 //Entry close
789 $xml->close_entry();
794 function getAllActiveMedications($xml, $patient_id){
795 global $from_date, $to_date;
796 $medArr = allActiveMedsPat($patient_id, $from_date, $to_date);
798 foreach($medArr as $medRow){
799 $vset = sqlQuery("select * from valueset where code = ? and nqf_code = ? ",array($medRow['rxnorm_drugcode'],$xml->nqf_code));
800 if(!empty($vset['valueset'])){
801 //Entry open
802 $xml->open_entry();
804 //substanceAdministration Open
805 $xml->open_customTag('substanceAdministration', array('classCode'=>'SBADM', 'moodCode'=>'EVN'));
807 $tempID = "2.16.840.1.113883.10.20.22.4.16";
808 $xml->self_templateid($tempID);
810 $tempID = "2.16.840.1.113883.10.20.24.3.41";
811 $xml->self_templateid($tempID);
813 $refID = getUuid();
814 $xml->self_customId($refID);
817 $arr = array('code'=>'active');
818 $xml->self_customTag('statusCode', $arr);
820 $timeArr = array('low'=>date('Ymdhis', strtotime($medRow['start_date'])), 'high'=>date('Ymdhis', strtotime($medRow['end_date'])));
821 $xml->add_entryEffectTimeQRDAMed($timeArr);
823 /*if($medRow['enddate'] == ""){
824 if($medRow['drug_interval'] != "" && $medRow['drug_interval'] != "0")
825 $xml->emptyelement('repeatNumber', array('value'=>$medRow['drug_interval']));
827 if($medRow['quantity'] != "")
828 $xml->emptyelement('doseQuantity', array('value'=>$medRow['quantity']));
830 if($medRow['units'] != "" && $medRow['size_type'] != "")
831 $xml->emptyelement('rateQuantity', array('units'=>$medRow['size_type'], 'value'=>$medRow['units']));
834 //consumable open
835 $xml->open_customTag('consumable');
837 //manufacturedProduct Open
838 $xml->open_customTag('manufacturedProduct', array('classCode'=>'MANU'));
840 $tempID = "2.16.840.1.113883.10.20.22.4.23";
841 $xml->self_templateid($tempID);
843 $actId = getUuid();
844 $xml->self_customId($actId);
846 //manufacturedMaterial open
847 $xml->open_customTag('manufacturedMaterial');
849 $arr = array('code'=>$vset['code'], 'codeSystem'=>$vset['code_system'],'sdtc:valueSet' => $vset['valueset']);
850 $xml->self_codeCustom($arr);
852 //manufacturerOrganization open
853 /*$xml->open_customTag('manufacturerOrganization');
855 $xml->element('name', 'Medication Factory Inc.');
857 //manufacturerOrganization Close
858 $xml->close_customTag();*/
860 //manufacturedMaterial Close
861 $xml->close_customTag();
863 //manufacturedProduct Close
864 $xml->close_customTag();
866 //consumable Close
867 $xml->close_customTag();
869 //substanceAdministration Close
870 $xml->close_customTag();
872 //Entry close
873 $xml->close_entry();
878 //Medical problems
879 function getAllMedicalProbs($xml, $patient_id){
880 global $from_date, $to_date;
881 $diagArr = allListsPat('medical_problem', $patient_id, $from_date, $to_date);
883 foreach($diagArr as $diagRow){
884 $diagExpArr = explode(";", $diagRow['diagnosis']);
885 /*foreach($diagExpArr as $diagExpVal){
886 $diagDisp = explode(":", $diagExpVal);
887 if($diagDisp[0] == "ICD9" || $diagDisp[0] == "ICD10") continue;
888 $diagDispCode = $diagDisp[1];
891 $diagDisp = explode(":", $diagExpArr[0]);
892 $diagDispCode = str_replace(".", "",$diagDisp[1]);
894 $vset = sqlQuery("select * from valueset where code = ? and nqf_code = ?",array($diagDispCode,$xml->nqf_code));
895 if(!empty($vset['valueset'])){
897 //Entry open
898 $xml->open_entry();
900 //observation Open
901 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
903 $tempID = "2.16.840.1.113883.10.20.22.4.4";
904 $xml->self_templateid($tempID);
906 $tempID = "2.16.840.1.113883.10.20.24.3.11";
907 $xml->self_templateid($tempID);
909 $refID = getUuid();
910 $xml->self_customId($refID);
912 $arr = array('code'=>'282291009', 'codeSystemName'=>'SNOMED-CT', 'codeSystem'=>'2.16.840.1.113883.6.96', 'displayName' => 'diagnosis');
913 $xml->self_codeCustom($arr);
915 $xml->textDispContent($diagRow['title']);
917 $activeChk = "active";
918 $endate = $diagRow['begdate'];
919 if($diagRow['enddate']!= ""){
920 $activeChk = "completed";
921 $endate = $diagRow['enddate'];
924 //$arr = array('code'=>$activeChk);
925 $arr = array('code'=> "completed");
926 $xml->self_customTag('statusCode', $arr);
928 $timeArr = array('low'=>date('Ymdhis', strtotime($diagRow['begdate'])), 'high'=>date('Ymdhis', strtotime($endate)));
929 $xml->add_entryEffectTime($timeArr);
932 $xml->self_customTag('value', array('xsi:type'=>'CD', 'code'=>$diagDispCode, 'codeSystem'=>'2.16.840.1.113883.6.96', 'sdtc:valueSet' => $vset['valueset']));
934 //entryRelationship Open
935 $xml->open_customTag('entryRelationship', array('typeCode'=>'REFR'));
937 //observation Open
938 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
940 $tempID = "2.16.840.1.113883.10.20.22.4.6";
941 $xml->self_templateid($tempID);
943 $tempID = "2.16.840.1.113883.10.20.24.3.94";
944 $xml->self_templateid($tempID);
946 $refID = getUuid();
947 $xml->self_customId($refID);
949 $arr = array('code'=>'33999-4', 'codeSystem'=>'2.16.840.1.113883.6.1', 'codeSystemName' => 'LOINC', 'displayName' => 'status');
950 $xml->self_codeCustom($arr);
952 //$arr = array('code'=>$activeChk);
953 $arr = array('code'=> "completed");
954 $xml->self_customTag('statusCode', $arr);
956 $xml->self_customTag('value', array('xsi:type'=>'CD', 'code'=>'55561003', 'displayName' => 'active', 'codeSystem' => '2.16.840.1.113883.6.96', 'codeSystemName' => 'SNOMED CT'));
958 //observation Close
959 $xml->close_customTag();
961 //entryRelationship Close
962 $xml->close_customTag();
964 //observation Close
965 $xml->close_customTag();
967 //Entry close
968 $xml->close_entry();
973 //Encounters function
974 function getAllPatientEncounters($xml, $patient_id){
975 global $encCheckUniqId, $from_date, $to_date,$EncounterCptCodes;
976 $encArr = allEncPat($patient_id, $from_date, $to_date);
978 foreach($encArr as $encRow){
980 $encRow['encounter'];
981 $cpt_code = $EncounterCptCodes[str_replace(' ','_',strtolower($encRow['pc_catname']))];
982 $cpt_code = empty($cpt_code) ? '99201' : $cpt_code;
983 $vset = sqlStatement("select * from valueset where code = ? and nqf_code = ?",array('99201',$xml->nqf_code));
984 foreach ($vset as $v){
985 //Entry open
986 $xml->open_entry();
988 //Encounter Open
989 $xml->open_customTag('encounter', array('classCode'=>'ENC', 'moodCode'=>'EVN'));
991 $tempID = "2.16.840.1.113883.10.20.22.4.49";
992 $xml->self_templateid($tempID);
994 $tempID = "2.16.840.1.113883.10.20.24.3.23";
995 $xml->self_templateid($tempID);
997 $refID = getUuid();
998 $xml->self_customId($refID);
999 $encCheckUniqId[$encRow['encounter']] = $refID;
1002 $arr = array('code'=>$cpt_code, 'codeSystem'=>$v['code_system'],'sdtc:valueSet' => $v['valueset']);
1003 $xml->self_codeCustom($arr);
1005 $arr = array('code'=>'completed');
1006 $xml->self_customTag('statusCode', $arr);
1008 $timeArr = array('low'=>date('Ymdhis', strtotime($encRow['date'])), 'high'=>date('Ymdhis', strtotime($encRow['date'])));
1009 $xml->add_entryEffectTime($timeArr);
1011 //Encounter Close
1012 $xml->close_customTag();
1014 //Entry close
1015 $xml->close_entry();
1019 $encArr = allProcPat("enc_checkup_procedure", $patient_id, $from_date, $to_date);
1020 foreach($encArr as $encRow){
1022 $encRow['encounter'];
1023 $vset = sqlStatement("select * from valueset where code = ? and nqf_code = ?",array($encRow['procedure_code'],$xml->nqf_code));
1024 foreach ($vset as $v){
1025 //Entry open
1026 $xml->open_entry();
1028 //Encounter Open
1029 $xml->open_customTag('encounter', array('classCode'=>'ENC', 'moodCode'=>'EVN'));
1031 $tempID = "2.16.840.1.113883.10.20.22.4.49";
1032 $xml->self_templateid($tempID);
1034 $tempID = "2.16.840.1.113883.10.20.24.3.23";
1035 $xml->self_templateid($tempID);
1037 $refID = getUuid();
1038 $xml->self_customId($refID);
1039 $encCheckUniqId[$encRow['encounter']] = $refID;
1042 $arr = array('code'=>$v['code'], 'codeSystem'=>$v['code_system'],'sdtc:valueSet' => $v['valueset']);
1043 $xml->self_codeCustom($arr);
1045 $arr = array('code'=>'completed');
1046 $xml->self_customTag('statusCode', $arr);
1048 $timeArr = array('low'=>date('Ymdhis', strtotime($encRow['date'])), 'high'=>date('Ymdhis', strtotime($encRow['date'])));
1049 $xml->add_entryEffectTime($timeArr);
1051 //Encounter Close
1052 $xml->close_customTag();
1054 //Entry close
1055 $xml->close_entry();
1062 //Patient Data Sub Function for Payer Data
1063 function payerQRDA($xml, $patient_id){
1064 global $mainQrdaPayerCodeSendArr, $from_date, $to_date;
1066 //Insurance getting
1067 $payer = payerPatient($patient_id);
1069 //Entry open
1070 $xml->open_entry();
1072 //observation Open
1073 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
1075 $tempID = "2.16.840.1.113883.10.20.24.3.55";
1076 $xml->self_templateid($tempID);
1078 $actId = getUuid();
1079 $xml->self_customId($actId);
1081 $arr = array('code'=>'48768-6', 'displayName'=>'Payment source', 'codeSystem'=>'2.16.840.1.113883.6.1', 'codeSystemName'=>'LOINC');
1082 $xml->self_codeCustom($arr);
1084 $arr = array('code'=>'completed');
1085 $xml->self_customTag('statusCode', $arr);
1087 $timeArr = array('low'=>date('Ymdhis', strtotime($from_date)), 'high'=>date('Ymdhis', strtotime($to_date)));
1088 $xml->add_entryEffectTime($timeArr);
1090 $xml->self_customTag('value', array('xsi:type'=>'CD', 'code'=>$mainQrdaPayerCodeSendArr[$payer], 'codeSystem'=>'2.16.840.1.113883.3.221.5' , 'codeSystemName'=>'Source of Payment Typology', 'displayName'=>$payer));
1092 //observation Close
1093 $xml->close_customTag();
1095 //Entry close
1096 $xml->close_entry();
1099 //Reporting Parameters function
1100 function getReportingParam($xml){
1101 global $from_date, $to_date;
1103 $xml->open_loopComponent();
1104 $xml->open_section();
1106 $tempID = '2.16.840.1.113883.10.20.17.2.1';
1107 $xml->self_templateid($tempID);
1109 $arr = array('code'=>'55187-9', 'codeSystem'=>'2.16.840.1.113883.6.1');
1110 $xml->self_codeCustom($arr);
1112 $title = "Reporting Parameters";
1113 $xml->add_title($title);
1115 //Main Reporting Parameters display
1116 $xml->open_text();
1117 $xml->open_list();
1118 $item_title = "Reporting period: ".date('d M Y', strtotime($from_date))." - ".date('d M Y', strtotime($to_date));
1119 $xml->add_item($item_title);
1120 $xml->close_list();
1121 $xml->close_text();
1123 $typeCode = 'DRIV';
1124 $xml->open_entry($typeCode);
1125 $arr = array('classCode'=>'ACT', 'moodCode'=>'EVN');
1126 $xml->open_act($arr);
1128 $tempID = '2.16.840.1.113883.10.20.17.3.8';
1129 $xml->self_templateid($tempID);
1131 $arr = array('extension'=>getUuid());
1132 $xml->self_customTag('id', $arr);
1134 $arr = array('code'=>'252116004', 'codeSystem'=>'2.16.840.1.113883.6.96', 'displayName'=>'Observation Parameters');
1135 $xml->self_codeCustom($arr);
1137 $timeArr = array('low'=>date('Ymdhis', strtotime($from_date)), 'high'=>date('Ymdhis', strtotime($to_date)));
1138 $xml->add_entryEffectTime($timeArr);
1140 $xml->close_act();
1141 $xml->close_entry();
1143 $xml->close_section();
1144 $xml->close_loopComponent();
1147 //Measure Section
1148 function getMeasureSection($xml, $rule_id){
1149 global $preDefinedUniqIDRules;
1151 $xml->open_loopComponent();
1152 $xml->open_section();
1154 $tempID = '2.16.840.1.113883.10.20.24.2.2';
1155 $xml->self_templateid($tempID);
1157 $tempID = '2.16.840.1.113883.10.20.24.2.3';
1158 $xml->self_templateid($tempID);
1160 $arr = array('code'=>'55186-1', 'codeSystem'=>'2.16.840.1.113883.6.1');
1161 $xml->self_codeCustom($arr);
1163 $title = "Measure Section";
1164 $xml->add_title($title);
1166 //Main Measure display
1167 $xml->open_text();
1169 //Table Start
1170 $xml->open_customTag('table', $tabArr);
1171 //THEAD Start
1172 $xml->open_customTag('thead');
1173 //TR Start
1174 $xml->open_customTag('tr');
1176 $xml->add_trElementsTitles();
1178 //TR close
1179 $xml->close_customTag();
1181 //THEAD close
1182 $xml->close_customTag();
1183 //TBOBY START
1184 $xml->open_customTag('tbody');
1185 $xml->open_customTag('tr');
1187 if (!empty($rule_id)) {
1188 $tdTitle = "NQF:". $rule_id;
1191 $tdVersionNeutral = getUuid();
1192 $tdVersionSpecific = $preDefinedUniqIDRules[$rule_id];
1193 $uniqIdArr[] = $tdVersionSpecific;
1195 $dataArr = array(0=>$tdTitle, 1=>$tdVersionNeutral, 2=>$tdVersionSpecific);
1196 $xml->add_trElementsValues($dataArr);
1198 //TR close
1199 $xml->close_customTag();
1200 //TBODY close
1201 $xml->close_customTag();
1202 //Table Close
1203 $xml->close_customTag();
1205 $xml->close_text();
1207 //Entry open
1208 $xml->open_entry();
1210 //Organizer Start
1211 $arr = array('classCode'=>'CLUSTER', 'moodCode'=>'EVN');
1212 $xml->open_customTag('organizer', $arr);
1214 $tempID = "2.16.840.1.113883.10.20.24.3.98";
1215 $xml->self_templateid($tempID);
1217 $tempID = "2.16.840.1.113883.10.20.24.3.97";
1218 $xml->self_templateid($tempID);
1220 $arr = array('extension'=>$uniqIdArr[0]);
1221 $xml->self_customTag('id', $arr);
1223 $arr = array('code'=>'completed');
1224 $xml->self_customTag('statusCode', $arr);
1226 //reference Start
1227 $arr = array('typeCode'=>'REFR');
1228 $xml->open_customTag('reference', $arr);
1230 //externalDocument Start
1231 $arr = array('classCode'=>'DOC', 'moodCode'=>'EVN');
1232 $xml->open_customTag('externalDocument', $arr);
1234 $exDocID = $uniqIdArr[0];
1235 $xml->self_customTag('id', array('root' => '2.16.840.1.113883.4.738', 'extension' =>$exDocID));
1237 $xml->element('text', "NQF# ".$rule_id);
1239 $setidVal =getUuid();
1240 $xml->self_setid($setidVal);
1242 $arr = array('value'=>'3');
1243 $xml->self_customTag('versionNumber', $arr);
1245 //externalDocument Close
1246 $xml->close_customTag();
1248 //reference Close
1249 $xml->close_customTag();
1251 //Organizer Close
1252 $xml->close_customTag();
1254 //Entry Close
1255 $xml->close_entry();
1257 $xml->close_section();
1258 $xml->close_loopComponent();
1261 //Download QRDA Category I
1262 function downloadQRDACat1($xml, $patient_id, $rule_id){
1263 //Patient Info
1264 if($patient_id != ""){
1265 $patientRow = getPatData($patient_id);
1266 $patFname = $patientRow['fname'];
1267 $patLname = $patientRow['lname'];
1270 //QRDA File Download Folder in site/cqm_qrda folder
1271 $qrda_fname = $patFname."_".$patLname."_NQF_".$rule_id.".xml";
1272 global $qrda_file_path;
1273 if(!file_exists($qrda_file_path)){
1274 mkdir($qrda_file_path, 0777, true);
1276 $qrda_file_name = $qrda_file_path.$qrda_fname;
1277 $fileQRDAOPen = fopen($qrda_file_name, "w");
1278 fwrite($fileQRDAOPen, trim($xml->getXml()));
1279 fclose($fileQRDAOPen);
1280 return $qrda_fname;
1283 //Patient History Info
1284 function patCharactersticQRDA($xml, $patient_id){
1286 //Patient History
1287 $patHist = patientQRDAHistory($patient_id);
1289 $tobaccoArr = explode('|',$patHist['tobacco']);
1291 $query = sqlQuery("select codes from list_options where list_id ='smoking_status' and option_id = ?",array($tobaccoArr[3]));
1292 $tobacco = explode(':',$query['codes']);
1293 $tobacco_code = $tobacco[1];
1294 $vset = sqlQuery("select * from valueset where code = ? and nqf_code = ?",array($tobacco_code,$xml->nqf_code));
1295 if(!empty($vset['valueset'])){
1296 //Entry open
1297 $xml->open_entry();
1299 //observation Open
1300 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
1302 $tempID = "2.16.840.1.113883.10.20.22.4.85";
1303 $xml->self_templateid($tempID);
1305 $actId = getUuid();
1306 $xml->self_customId($actId);
1308 $arr = array('code'=>'ASSERTION', 'displayName'=>'Assertion', 'codeSystem'=>'2.16.840.1.113883.5.4', 'codeSystemName'=>'ActCode');
1309 $xml->self_codeCustom($arr);
1311 $arr = array('code'=>'completed');
1312 $xml->self_customTag('statusCode', $arr);
1314 $timeArr = array('low'=>date('Ymdhis', strtotime($patHist['date'])), 'high'=>date('Ymdhis', strtotime($patHist['date'])));
1315 $xml->add_entryEffectTime($timeArr);
1317 $xml->self_customTag('value', array('xsi:type'=>'CD', 'code'=> $vset['code'], 'codeSystem'=>$vset['code_system'],'sdtc:valueSet' => $vset['valueset']));
1319 //observation Close
1320 $xml->close_customTag();
1322 //Entry close
1323 $xml->close_entry();