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
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();
31 getHeaderQRDA1($xml, $patient_id, $provider_id);
34 getComponentQRDA1($xml, $patient_id, $rule_id);
36 //Close Main Clinical Document
37 $xml->close_clinicaldocument();
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;
50 if($patient_id != ""){
51 $patientRow = getPatData($patient_id);
54 $userRow = getUsrDataCheck($provider_id);
55 $facility_name = $userRow['facility'];
56 $facility_id = $userRow['facility_id'];
59 if($facility_id != "")
60 $facilResRow = getFacilDataChk($facility_id);
62 ####################### HEADER ELEMENTS START ##########################################
64 $xml->self_realmcode();
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();
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();
99 //Record Target Elements
100 $xml->open_recordTarget();
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'));
112 $xml->open_customTag('patient');
114 $patNameArr = array('fname' =>$patientRow['fname'], 'lname'=>$patientRow['lname']);
115 $xml->add_patName($patNameArr);
117 if($patientRow['sex'] == "Male") $gender = "M";
118 else if($patientRow['sex'] == "Female") $gender = "F";
119 $xml->self_customTag('administrativeGenderCode', array('codeSystem' => '2.16.840.1.113883.18.2', 'code' =>$gender));
121 $xml->self_customTag('birthTime', array('value' =>date('Ymd', strtotime($patientRow['DOB']))));
123 if($mainQrdaRaceCodeArr[$patientRow['race']] == "") $mainQrdaRaceCodeArr[$patientRow['race']] = "2131-1";
124 $xml->self_customTag('raceCode', array('codeSystem' =>'2.16.840.1.113883.6.238', 'code' => $mainQrdaRaceCodeArr[$patientRow['race']]));
125 $xml->self_customTag('ethnicGroupCode', array('codeSystem' =>'2.16.840.1.113883.6.238', 'code' => $mainEthiCodeArr[$patientRow['ethnicity']]));
128 $xml->close_customTag();
131 $xml->close_customTag();
133 $xml->close_recordTarget();
135 ############### Author Info Start#######################
139 $auth_dtime = date('Ymdhis');
140 $xml->self_authorTime($auth_dtime);
143 $xml->open_assignAuthor();
144 $xml->self_customTag('id', array('root' =>'2.16.840.1.113883.4.6', 'extension' => $userRow['npi']));
145 $xml->add_patientAddress($facilResRow);
146 $xml->self_customTag('telecom', array('value' => $userRow['phone'], 'use'=>'WP'));
148 //assignedAuthoringDevice Start
149 $xml->open_customTag('assignedAuthoringDevice');
150 $xml->element('manufacturerModelName', 'DrCloudEMR');
151 $xml->element('softwareName', 'DrCloudEMR');
152 //assignedAuthoringDevice Close
153 $xml->close_customTag();
155 $xml->close_assignAuthor();
156 ################## Author Info End ##########################
158 $xml->close_author();
159 ############### Author Info End#######################
161 ############### Custodian Info Start #######################
162 $xml->open_custodian();
163 $xml->open_assgnCustodian();
164 $xml->add_represtCustodianOrginisation($facilResRow);
165 $xml->close_assgnCustodian();
166 $xml->close_custodian();
167 ############### Custodian Info End #######################
169 ############### Legal Authenticator Start#######################
170 $xml->open_legalAuthenticator();
171 $auth_dtime = date('Ymdhis');
172 $xml->self_authorTime($auth_dtime);
173 $xml->self_legalSignCode();
175 $xml->open_assignedEntity();
176 $assignedEntityId = getUuid();
177 $xml->self_customId($assignedEntityId);
178 $xml->add_facilAddress($facilResRow);
179 $xml->self_customTag('telecom', array('value' => $facilResRow['phone'], 'use'=>'WP'));
180 $xml->open_customTag('assignedPerson');
183 $userNameArr = array('fname' =>$userRow['fname'], 'lname'=>$userRow['lname']);
184 $xml->add_providerName($userNameArr);
186 //assignedPerson Close
187 $xml->close_customTag();
189 //Represent Origination Name
190 $xml->add_authReprestOrginisation($facilResRow);
191 $xml->close_assignedEntity();
193 $xml->close_legalAuthenticator();
194 ############### Legal Authenticator End#######################
196 ############### documentationOf START #######################
197 $xml->open_customTag('documentationOf');
199 $xml->open_customTag('serviceEvent', array('classCode'=>'PCPR'));
201 $timeArr = array('low'=>date('Ymdhis', strtotime($from_date)), 'high'=>date('Ymdhis', strtotime($to_date)));
202 $xml->add_entryEffectTime($timeArr);
204 $xml->open_customTag('performer', array('typeCode'=>'PRF'));
206 $timeArr = array('low'=>date('Ymdhis', strtotime($from_date)), 'high'=>date('Ymdhis', strtotime($to_date)));
207 $xml->add_entryTime($timeArr);
209 $xml->open_customTag('assignedEntity');
211 $npi_provider = $userRow['npi'];
212 $xml->self_customTag('id', array('root' => '2.16.840.1.113883.4.6', 'extension' =>$npi_provider));
214 if($userRow['phone'] != ""){
215 $xml->self_customTag('telecom', array('value' => $userRow['phone'], 'use'=>'WP'));
218 $xml->open_customTag('assignedPerson');
221 $userNameArr = array('fname' =>$userRow['fname'], 'lname'=>$userRow['lname']);
222 $xml->add_providerName($userNameArr);
224 //assignedPerson Close
225 $xml->close_customTag();
227 $xml->open_customTag('representedOrganization');
229 $tin_provider = $userRow['federaltaxid'];
230 if($tin_provider != ""){
231 $xml->self_customTag('id', array('root' => '2.16.840.1.113883.4.2', 'extension' =>$tin_provider));
234 $xml->add_facilName($facility_name);
236 $xml->add_facilAddress($facilResRow);
238 //representedOrganization Close
239 $xml->close_customTag();
241 //assignedEntity Close
242 $xml->close_customTag();
245 $xml->close_customTag();
248 $xml->close_customTag();
250 //documentationOf Close
251 $xml->close_customTag();
252 ############### documentationOf END #######################
253 ####################### HEADER ELEMENTS END #########################################
257 function getComponentQRDA1($xml, $patient_id, $rule_id){
259 $xml->open_mainComponent();
261 //structuredBody Open
262 $xml->open_structuredBody();
265 getMeasureSection($xml, $rule_id);
267 //Reporting Parameters
268 getReportingParam($xml);
271 getQRDACat1PatientData($xml, $patient_id);
273 //structuredBody Close
274 $xml->close_structuredBody();
277 $xml->close_mainComponent();
281 function getQRDACat1PatientData($xml, $patient_id){
282 $xml->open_loopComponent();
283 $xml->open_section();
285 $tempID = '2.16.840.1.113883.10.20.17.2.4';
286 $xml->self_templateid($tempID);
288 $tempID = '2.16.840.1.113883.10.20.24.2.1';
289 $xml->self_templateid($tempID);
291 $arr = array('code'=>'55188-7', 'codeSystem'=>'2.16.840.1.113883.6.1');
292 $xml->self_codeCustom($arr);
294 $title = "Patient Data";
295 $xml->add_title($title);
297 $xml->element('text', "Patient Data");
299 //Insurance(Payer) Info
300 payerQRDA($xml, $patient_id);
302 //Patient History Info
303 patCharactersticQRDA($xml, $patient_id);
306 getAllPatientEncounters($xml, $patient_id);
308 //Physical Exams(vitals)
309 getAllPhysicalExams($xml, $patient_id);
311 //Diagnosis (Medical Problems)
312 getAllMedicalProbs($xml, $patient_id);
315 getAllMedications($xml, $patient_id);
318 getAllImmunization($xml, $patient_id);
321 getAllProcedures($xml, $patient_id);
323 //Risk Category Assessment
324 getAllRiskCatAssessment($xml, $patient_id);
326 $xml->close_section();
327 $xml->close_loopComponent();
331 function getAllImmunization($xml, $patient_id){
332 global $from_date, $to_date;
333 $medArr = allImmuPat($patient_id, $from_date, $to_date);
335 foreach($medArr as $medRow){
340 $xml->open_customTag('act', array('classCode'=>'ACT', 'moodCode'=>'EVN'));
342 $tempID = "2.16.840.1.113883.10.20.24.3.42";
343 $xml->self_templateid($tempID);
346 $xml->self_customId($refID);
348 $arr = array('code'=>'416118004', 'codeSystemName'=>'SNOMED CT', 'codeSystem'=>'2.16.840.1.113883.6.96', 'displayName' => 'Administration');
349 $xml->self_codeCustom($arr);
351 if($medRow['status'] == "" ||
$medRow['status'] == "not_completed")
352 $statusChk = "active";
354 $statusChk = "completed";
356 $arr = array('code'=>$statusChk);
357 $xml->self_customTag('statusCode', $arr);
359 $timeArr = array('low'=>date('Ymdhis', strtotime($medRow['administered_date'])), 'high'=>date('Ymdhis', strtotime($medRow['administered_date'])));
360 $xml->add_entryEffectTimeQRDAMed($timeArr);
362 $xml->open_customTag('entryRelationship', array('typeCode'=>'COMP'));
364 //substanceAdministration Open
365 $xml->open_customTag('substanceAdministration', array('classCode'=>'SBADM', 'moodCode'=>'EVN'));
367 $tempID = "2.16.840.1.113883.10.20.22.4.16";
368 $xml->self_templateid($tempID);
370 //$tempID = "2.16.840.1.113883.10.20.24.3.41";
371 //$xml->self_templateid($tempID);
374 $xml->self_customId($refID);
376 $arr = array('code'=>$statusChk);
377 $xml->self_customTag('statusCode', $arr);
379 $timeArr = array('low'=>date('Ymdhis', strtotime($medRow['administered_date'])), 'high'=>date('Ymdhis', strtotime($medRow['administered_date'])));
380 $xml->add_entryEffectTimeQRDAMed($timeArr);
383 $xml->open_customTag('consumable');
385 //manufacturedProduct Open
386 $xml->open_customTag('manufacturedProduct', array('classCode'=>'MANU'));
388 $tempID = "2.16.840.1.113883.10.20.22.4.23";
389 $xml->self_templateid($tempID);
392 $xml->self_customId($actId);
394 //manufacturedMaterial open
395 $xml->open_customTag('manufacturedMaterial');
397 $arr = array('code'=>$medRow['cvx_code'], 'codeSystem'=>'2.16.840.1.113883.12.292');
398 $xml->self_codeCustom($arr);
400 //manufacturerOrganization open
401 /*$xml->open_customTag('manufacturerOrganization');
403 $xml->element('name', 'Medication, Administered Vaccine');
405 //manufacturerOrganization Close
406 $xml->close_customTag();*/
408 //manufacturedMaterial Close
409 $xml->close_customTag();
411 //manufacturedProduct Close
412 $xml->close_customTag();
415 $xml->close_customTag();
417 //substanceAdministration Close
418 $xml->close_customTag();
420 //entryRelationship Close
421 $xml->close_customTag();
424 $xml->close_customTag();
431 function getAllPhysicalExams($xml, $patient_id){
432 global $encCheckUniqId, $from_date, $to_date;
434 $vitArr = allVitalsPat( $patient_id, $from_date, $to_date);
436 foreach($vitArr as $vitRow){
441 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
443 $tempID = "2.16.840.1.113883.10.20.22.4.2";
444 $xml->self_templateid($tempID);
446 $tempID = "2.16.840.1.113883.10.20.24.3.57";
447 $xml->self_templateid($tempID);
449 //$refID = getUuid();
450 $refID = $encCheckUniqId[$vitRow['encounter']];
451 $xml->self_customId($refID);
453 $arr = array('code'=>'8480-6', 'codeSystem'=>'2.16.840.1.113883.6.1');
455 $xml->open_customTag('code', $arr);
456 $xml->element('originalText', "Physical Exam(BPS)");
458 $xml->close_customTag();
460 $xml->element('text', "Physical Exam(BPS)");
462 $arr = array('code'=>'completed');
463 $xml->self_customTag('statusCode', $arr);
465 $timeArr = array('low'=>date('Ymdhis', strtotime($vitRow['date'])), 'high'=>date('Ymdhis', strtotime($vitRow['date'])));
466 $xml->add_entryEffectTimeQRDA($timeArr);
468 $xml->self_customTag('value', array('xsi:type'=>'PQ', 'value'=>$vitRow['bps'], 'unit' => 'mmHg'));
471 $xml->close_customTag();
478 function getAllRiskCatAssessment($xml, $patient_id){
479 global $encCheckUniqId, $from_date, $to_date;
480 $procArr = allProcPat("Risk Category Assessment", $patient_id, $from_date, $to_date);
481 foreach($procArr as $procRow){
486 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
488 $tempID = "2.16.840.1.113883.10.20.22.4.69";
489 $xml->self_templateid($tempID);
491 $tempID = "2.16.840.1.113883.10.20.24.3.69";
492 $xml->self_templateid($tempID);
494 //$refID = getUuid();
495 $refID = $encCheckUniqId[$procRow['encounter']];
496 $xml->self_customId($refID);
498 $arr = array('code'=>$procRow['procedure_code'], 'codeSystem'=>'2.16.840.1.113883.6.1');
500 $xml->open_customTag('code', $arr);
501 $xml->element('originalText', $procRow['procedure_name']);
503 $xml->close_customTag();
505 $xml->element('text', $procRow['procedure_name']);
507 $arr = array('code'=>'completed');
508 $xml->self_customTag('statusCode', $arr);
510 $timeArr = array('low'=>date('Ymdhis', strtotime($procRow['date_ordered'])), 'high'=>date('Ymdhis', strtotime($procRow['date_ordered'])));
511 $xml->add_entryEffectTimeQRDA($timeArr);
513 $xml->self_customTag('value', array('xsi:type'=>'CD', 'nullFlavor'=>'UNK'));
516 $xml->close_customTag();
523 function getAllProcedures($xml, $patient_id){
524 global $encCheckUniqId, $from_date, $to_date;
525 $procArr = allProcPat("Procedure", $patient_id, $from_date, $to_date);
526 foreach($procArr as $procRow){
531 $xml->open_customTag('procedure', array('classCode'=>'PROC', 'moodCode'=>'EVN'));
533 $tempID = "2.16.840.1.113883.10.20.24.3.64";
534 $xml->self_templateid($tempID);
536 $tempID = "2.16.840.1.113883.10.20.22.4.14";
537 $xml->self_templateid($tempID);
539 //$refID = getUuid();
540 $refID = $encCheckUniqId[$procRow['encounter']];
541 $xml->self_customId($refID);
543 $arr = array('code'=>$procRow['procedure_code'], 'codeSystem'=>'2.16.840.1.113883.6.96');
545 $xml->open_customTag('code', $arr);
546 $xml->element('originalText', $procRow['procedure_name']);
548 $xml->close_customTag();
550 $xml->element('text', $procRow['procedure_name']);
552 $arr = array('code'=>'completed');
553 $xml->self_customTag('statusCode', $arr);
555 $timeArr = array('low'=>date('Ymdhis', strtotime($procRow['date_ordered'])), 'high'=>date('Ymdhis', strtotime($procRow['date_ordered'])));
556 $xml->add_entryEffectTimeQRDA($timeArr);
559 $xml->close_customTag();
566 function getAllMedications($xml, $patient_id){
567 global $from_date, $to_date;
568 $medArr = allListsPat('medication', $patient_id, $from_date, $to_date);
570 foreach($medArr as $medRow){
574 //substanceAdministration Open
575 $xml->open_customTag('substanceAdministration', array('classCode'=>'SBADM', 'moodCode'=>'RQO'));
577 $tempID = "2.16.840.1.113883.10.20.22.4.42";
578 $xml->self_templateid($tempID);
580 $tempID = "2.16.840.1.113883.10.20.24.3.47";
581 $xml->self_templateid($tempID);
584 $xml->self_customId($refID);
587 $endate = $medRow['begdate'];
588 if($medRow['enddate']!= ""){
589 $activeChk = "completed";
590 $endate = $medRow['enddate'];
592 $arr = array('code'=>$activeChk);
593 $xml->self_customTag('statusCode', $arr);
595 $timeArr = array('low'=>date('Ymdhis', strtotime($medRow['begdate'])), 'high'=>date('Ymdhis', strtotime($endate)));
596 $xml->add_entryEffectTimeQRDAMed($timeArr);
598 /*if($medRow['enddate'] == ""){
599 if($medRow['drug_interval'] != "" && $medRow['drug_interval'] != "0")
600 $xml->emptyelement('repeatNumber', array('value'=>$medRow['drug_interval']));
602 if($medRow['quantity'] != "")
603 $xml->emptyelement('doseQuantity', array('value'=>$medRow['quantity']));
605 if($medRow['units'] != "" && $medRow['size_type'] != "")
606 $xml->emptyelement('rateQuantity', array('units'=>$medRow['size_type'], 'value'=>$medRow['units']));
610 $xml->open_customTag('consumable');
612 //manufacturedProduct Open
613 $xml->open_customTag('manufacturedProduct', array('classCode'=>'MANU'));
615 $tempID = "2.16.840.1.113883.10.20.22.4.23";
616 $xml->self_templateid($tempID);
619 $xml->self_customId($actId);
621 //manufacturedMaterial open
622 $xml->open_customTag('manufacturedMaterial');
624 $arr = array('code'=>'197454', 'codeSystem'=>'2.16.840.1.113883.6.88');
625 $xml->self_codeCustom($arr);
627 //manufacturerOrganization open
628 /*$xml->open_customTag('manufacturerOrganization');
630 $xml->element('name', 'Medication Factory Inc.');
632 //manufacturerOrganization Close
633 $xml->close_customTag();*/
635 //manufacturedMaterial Close
636 $xml->close_customTag();
638 //manufacturedProduct Close
639 $xml->close_customTag();
642 $xml->close_customTag();
644 //substanceAdministration Close
645 $xml->close_customTag();
653 function getAllMedicalProbs($xml, $patient_id){
654 global $from_date, $to_date;
655 $diagArr = allListsPat('medical_problem', $patient_id, $from_date, $to_date);
657 foreach($diagArr as $diagRow){
658 $diagExpArr = explode(";", $diagRow['diagnosis']);
659 /*foreach($diagExpArr as $diagExpVal){
660 $diagDisp = explode(":", $diagExpVal);
661 if($diagDisp[0] == "ICD9" || $diagDisp[0] == "ICD10") continue;
662 $diagDispCode = $diagDisp[1];
665 $diagDisp = explode(":", $diagExpArr[0]);
666 $diagDispCode = str_replace(".", "",$diagDisp[1]);
672 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
674 $tempID = "2.16.840.1.113883.10.20.22.4.4";
675 $xml->self_templateid($tempID);
677 $tempID = "2.16.840.1.113883.10.20.24.3.11";
678 $xml->self_templateid($tempID);
681 $xml->self_customId($refID);
683 $arr = array('code'=>'282291009', 'codeSystemName'=>'SNOMED-CT', 'codeSystem'=>'2.16.840.1.113883.6.96', 'displayName' => 'diagnosis');
684 $xml->self_codeCustom($arr);
686 $xml->textDispContent($diagRow['title']);
688 $activeChk = "active";
689 $endate = $diagRow['begdate'];
690 if($diagRow['enddate']!= ""){
691 $activeChk = "completed";
692 $endate = $diagRow['enddate'];
695 $arr = array('code'=>$activeChk);
696 $xml->self_customTag('statusCode', $arr);
698 $timeArr = array('low'=>date('Ymdhis', strtotime($diagRow['begdate'])), 'high'=>date('Ymdhis', strtotime($endate)));
699 $xml->add_entryEffectTime($timeArr);
701 $xml->self_customTag('value', array('xsi:type'=>'CD', 'code'=>$diagDispCode, 'codeSystem'=>'2.16.840.1.113883.6.96'));
703 //entryRelationship Open
704 $xml->open_customTag('entryRelationship', array('typeCode'=>'REFR'));
707 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
709 $tempID = "2.16.840.1.113883.10.20.22.4.6";
710 $xml->self_templateid($tempID);
712 $tempID = "2.16.840.1.113883.10.20.24.3.94";
713 $xml->self_templateid($tempID);
716 $xml->self_customId($refID);
718 $arr = array('code'=>'33999-4', 'codeSystem'=>'2.16.840.1.113883.6.1', 'codeSystemName' => 'LOINC', 'displayName' => 'status');
719 $xml->self_codeCustom($arr);
721 $arr = array('code'=>$activeChk);
722 $xml->self_customTag('statusCode', $arr);
724 $xml->self_customTag('value', array('xsi:type'=>'CD', 'code'=>'55561003', 'displayName' => 'active', 'codeSystem' => '2.16.840.1.113883.6.96', 'codeSystemName' => 'SNOMED CT'));
727 $xml->close_customTag();
729 //entryRelationship Close
730 $xml->close_customTag();
733 $xml->close_customTag();
740 //Encounters function
741 function getAllPatientEncounters($xml, $patient_id){
742 global $encCheckUniqId, $from_date, $to_date;
743 $encArr = allEncPat($patient_id, $from_date, $to_date);
745 foreach($encArr as $encRow){
746 $encRow['encounter'];
751 $xml->open_customTag('encounter', array('classCode'=>'ENC', 'moodCode'=>'EVN'));
753 $tempID = "2.16.840.1.113883.10.20.22.4.49";
754 $xml->self_templateid($tempID);
756 $tempID = "2.16.840.1.113883.10.20.24.3.23";
757 $xml->self_templateid($tempID);
760 $xml->self_customId($refID);
761 $encCheckUniqId[$encRow['encounter']] = $refID;
763 $arr = array('code'=>'99201', 'codeSystem'=>'2.16.840.1.113883.6.12');
764 $xml->self_codeCustom($arr);
766 $arr = array('code'=>'completed');
767 $xml->self_customTag('statusCode', $arr);
769 $timeArr = array('low'=>date('Ymdhis', strtotime($encRow['date'])), 'high'=>date('Ymdhis', strtotime($encRow['date'])));
770 $xml->add_entryEffectTime($timeArr);
773 $xml->close_customTag();
781 //Patient Data Sub Function for Payer Data
782 function payerQRDA($xml, $patient_id){
783 global $mainQrdaPayerCodeSendArr, $from_date, $to_date;
786 $payer = payerPatient($patient_id);
792 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
794 $tempID = "2.16.840.1.113883.10.20.24.3.55";
795 $xml->self_templateid($tempID);
798 $xml->self_customId($actId);
800 $arr = array('code'=>'48768-6', 'displayName'=>'Payment source', 'codeSystem'=>'2.16.840.1.113883.6.1', 'codeSystemName'=>'LOINC');
801 $xml->self_codeCustom($arr);
803 $arr = array('code'=>'completed');
804 $xml->self_customTag('statusCode', $arr);
806 $timeArr = array('low'=>date('Ymdhis', strtotime($from_date)), 'high'=>date('Ymdhis', strtotime($to_date)));
807 $xml->add_entryEffectTime($timeArr);
809 $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));
812 $xml->close_customTag();
818 //Reporting Parameters function
819 function getReportingParam($xml){
820 global $from_date, $to_date;
822 $xml->open_loopComponent();
823 $xml->open_section();
825 $tempID = '2.16.840.1.113883.10.20.17.2.1';
826 $xml->self_templateid($tempID);
828 $arr = array('code'=>'55187-9', 'codeSystem'=>'2.16.840.1.113883.6.1');
829 $xml->self_codeCustom($arr);
831 $title = "Reporting Parameters";
832 $xml->add_title($title);
834 //Main Reporting Parameters display
837 $item_title = "Reporting period: ".date('d M Y', strtotime($from_date))." - ".date('d M Y', strtotime($to_date));
838 $xml->add_item($item_title);
843 $xml->open_entry($typeCode);
844 $arr = array('classCode'=>'ACT', 'moodCode'=>'EVN');
845 $xml->open_act($arr);
847 $tempID = '2.16.840.1.113883.10.20.17.3.8';
848 $xml->self_templateid($tempID);
850 $arr = array('extension'=>getUuid());
851 $xml->self_customTag('id', $arr);
853 $arr = array('code'=>'252116004', 'codeSystem'=>'2.16.840.1.113883.6.96', 'displayName'=>'Observation Parameters');
854 $xml->self_codeCustom($arr);
856 $timeArr = array('low'=>date('Ymdhis', strtotime($from_date)), 'high'=>date('Ymdhis', strtotime($to_date)));
857 $xml->add_entryEffectTime($timeArr);
862 $xml->close_section();
863 $xml->close_loopComponent();
867 function getMeasureSection($xml, $rule_id){
868 global $preDefinedUniqIDRules;
870 $xml->open_loopComponent();
871 $xml->open_section();
873 $tempID = '2.16.840.1.113883.10.20.24.2.2';
874 $xml->self_templateid($tempID);
876 $tempID = '2.16.840.1.113883.10.20.24.2.3';
877 $xml->self_templateid($tempID);
879 $arr = array('code'=>'55186-1', 'codeSystem'=>'2.16.840.1.113883.6.1');
880 $xml->self_codeCustom($arr);
882 $title = "Measure Section";
883 $xml->add_title($title);
885 //Main Measure display
889 $xml->open_customTag('table', $tabArr);
891 $xml->open_customTag('thead');
893 $xml->open_customTag('tr');
895 $xml->add_trElementsTitles();
898 $xml->close_customTag();
901 $xml->close_customTag();
903 $xml->open_customTag('tbody');
904 $xml->open_customTag('tr');
906 if (!empty($rule_id)) {
907 $tdTitle = "NQF:". $rule_id;
910 $tdVersionNeutral = getUuid();
911 $tdVersionSpecific = $preDefinedUniqIDRules[$rule_id];
912 $uniqIdArr[] = $tdVersionSpecific;
914 $dataArr = array(0=>$tdTitle, 1=>$tdVersionNeutral, 2=>$tdVersionSpecific);
915 $xml->add_trElementsValues($dataArr);
918 $xml->close_customTag();
920 $xml->close_customTag();
922 $xml->close_customTag();
930 $arr = array('classCode'=>'CLUSTER', 'moodCode'=>'EVN');
931 $xml->open_customTag('organizer', $arr);
933 $tempID = "2.16.840.1.113883.10.20.24.3.98";
934 $xml->self_templateid($tempID);
936 $tempID = "2.16.840.1.113883.10.20.24.3.97";
937 $xml->self_templateid($tempID);
939 $arr = array('extension'=>$uniqIdArr[0]);
940 $xml->self_customTag('id', $arr);
942 $arr = array('code'=>'completed');
943 $xml->self_customTag('statusCode', $arr);
946 $arr = array('typeCode'=>'REFR');
947 $xml->open_customTag('reference', $arr);
949 //externalDocument Start
950 $arr = array('classCode'=>'DOC', 'moodCode'=>'EVN');
951 $xml->open_customTag('externalDocument', $arr);
953 $exDocID = $uniqIdArr[0];
954 $xml->self_customTag('id', array('root' => '2.16.840.1.113883.4.738', 'extension' =>$exDocID));
956 $xml->element('text', "NQF# ".$rule_id);
958 $setidVal =getUuid();
959 $xml->self_setid($setidVal);
961 $arr = array('value'=>'3');
962 $xml->self_customTag('versionNumber', $arr);
964 //externalDocument Close
965 $xml->close_customTag();
968 $xml->close_customTag();
971 $xml->close_customTag();
976 $xml->close_section();
977 $xml->close_loopComponent();
980 //Download QRDA Category I
981 function downloadQRDACat1($xml, $patient_id, $rule_id){
983 if($patient_id != ""){
984 $patientRow = getPatData($patient_id);
985 $patFname = $patientRow['fname'];
986 $patLname = $patientRow['lname'];
989 //QRDA File Download Folder in site/cqm_qrda folder
990 $qrda_fname = $patFname."_".$patLname."_NQF_".$rule_id.".xml";
991 global $qrda_file_path;
992 if(!file_exists($qrda_file_path)){
993 mkdir($qrda_file_path, 0777, true);
995 $qrda_file_name = $qrda_file_path.$qrda_fname;
996 $fileQRDAOPen = fopen($qrda_file_name, "w");
997 fwrite($fileQRDAOPen, trim($xml->getXml()));
998 fclose($fileQRDAOPen);
1002 //Patient History Info
1003 function patCharactersticQRDA($xml, $patient_id){
1006 $patHist = patientQRDAHistory($patient_id);
1012 $xml->open_customTag('observation', array('classCode'=>'OBS', 'moodCode'=>'EVN'));
1014 $tempID = "2.16.840.1.113883.10.20.22.4.85";
1015 $xml->self_templateid($tempID);
1018 $xml->self_customId($actId);
1020 $arr = array('code'=>'ASSERTION', 'displayName'=>'Assertion', 'codeSystem'=>'2.16.840.1.113883.5.4', 'codeSystemName'=>'ActCode');
1021 $xml->self_codeCustom($arr);
1023 $arr = array('code'=>'completed');
1024 $xml->self_customTag('statusCode', $arr);
1026 $timeArr = array('low'=>date('Ymdhis', strtotime($patHist['date'])), 'high'=>date('Ymdhis', strtotime($patHist['date'])));
1027 $xml->add_entryEffectTime($timeArr);
1029 $xml->self_customTag('value', array('xsi:type'=>'CD', 'code'=>'160603005', 'codeSystem'=>'2.16.840.1.113883.6.96'));
1032 $xml->close_customTag();
1035 $xml->close_entry();