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->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']]));
130 $xml->close_customTag();
133 $xml->close_customTag();
135 $xml->close_recordTarget();
137 ############### Author Info Start#######################
141 $auth_dtime = date('Ymdhis');
142 $xml->self_authorTime($auth_dtime);
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'));
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'));
191 $xml->self_customTag('telecom', array("nullFlavor" => "UNK"));
193 $xml->open_customTag('assignedPerson');
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'));
231 $xml->self_customTag('telecom', array("nullFlavor" => "UNK"));
233 $xml->open_customTag('assignedPerson');
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();
260 $xml->close_customTag();
263 $xml->close_customTag();
265 //documentationOf Close
266 $xml->close_customTag();
267 ############### documentationOf END #######################
268 ####################### HEADER ELEMENTS END #########################################
272 function getComponentQRDA1($xml, $patient_id, $rule_id){
274 $xml->open_mainComponent();
276 //structuredBody Open
277 $xml->open_structuredBody();
280 getMeasureSection($xml, $rule_id);
282 //Reporting Parameters
283 getReportingParam($xml);
286 getQRDACat1PatientData($xml, $patient_id);
288 //structuredBody Close
289 $xml->close_structuredBody();
292 $xml->close_mainComponent();
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);
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);
336 getAllImmunization($xml, $patient_id);
339 getAllProcedures($xml, $patient_id);
342 getAllLabTests($xml, $patient_id);
345 getAllInterventionProcedures($xml,$patient_id);
347 //Risk Category Assessment
348 getAllRiskCatAssessment($xml, $patient_id);
350 $xml->close_section();
351 $xml->close_loopComponent();
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'])){
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);
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";
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);
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);
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);
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();
443 $xml->close_customTag();
445 //substanceAdministration Close
446 $xml->close_customTag();
448 //entryRelationship Close
449 $xml->close_customTag();
452 $xml->close_customTag();
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){
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'])){
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']);
492 $xml->open_customTag('code', $arr);
493 $xml->element('originalText', "Physical Exam, Finding: ".$measure['measure']);
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']));
508 $xml->close_customTag();
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'])){
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']);
541 $xml->open_customTag('code', $arr);
542 $xml->element('originalText', $procRow['procedure_name']);
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'));
557 $xml->close_customTag();
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'])){
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']);
596 $xml->open_customTag('code', $arr);
597 $xml->element('originalText', $procRow['procedure_name']);
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);
610 $xml->close_customTag();
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'])){
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']);
640 $xml->open_customTag('code', $arr);
641 $xml->element('originalText', $procRow['procedure_name']);
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);
654 $xml->close_customTag();
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'])){
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']);
688 $xml->open_customTag('code', $arr);
689 $xml->element('originalText', $procRow['procedure_name']);
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);
702 $xml->close_customTag();
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'])){
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);
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']));
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);
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();
783 $xml->close_customTag();
785 //substanceAdministration Close
786 $xml->close_customTag();
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'])){
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);
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']));
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);
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();
867 $xml->close_customTag();
869 //substanceAdministration Close
870 $xml->close_customTag();
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'])){
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);
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'));
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);
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'));
959 $xml->close_customTag();
961 //entryRelationship Close
962 $xml->close_customTag();
965 $xml->close_customTag();
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){
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);
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);
1012 $xml->close_customTag();
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){
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);
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);
1052 $xml->close_customTag();
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;
1067 $payer = payerPatient($patient_id);
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);
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));
1093 $xml->close_customTag();
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
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);
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);
1141 $xml->close_entry();
1143 $xml->close_section();
1144 $xml->close_loopComponent();
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
1170 $xml->open_customTag('table', $tabArr);
1172 $xml->open_customTag('thead');
1174 $xml->open_customTag('tr');
1176 $xml->add_trElementsTitles();
1179 $xml->close_customTag();
1182 $xml->close_customTag();
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);
1199 $xml->close_customTag();
1201 $xml->close_customTag();
1203 $xml->close_customTag();
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);
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();
1249 $xml->close_customTag();
1252 $xml->close_customTag();
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){
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);
1283 //Patient History Info
1284 function patCharactersticQRDA($xml, $patient_id){
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'])){
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);
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']));
1320 $xml->close_customTag();
1323 $xml->close_entry();