openemr bug 444 fix
[openemr.git] / library / classes / QRDAXml.class.php
blobb8c51bd0686cd7738c2f5ea1f55ec7bfc3ed250a
1 <?php
2 /**
4 * This program implements the XML Writer to generate QRDA Category I (or) III 2014 XML.
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
24 require_once("XmlWriterOemr.class.php");
26 class QRDAXml extends XmlWriterOemr {
27 public $unique_id;
28 public $nqf_code;
30 function __construct($nqf_code,$indent = ' ') {
31 $this->nqf_code = $nqf_code;
32 parent::__construct($indent);
36 function open_clinicaldocument() {
37 $this->push('ClinicalDocument', array('xmlns'=>'urn:hl7-org:v3', 'xmlns:voc'=>'urn:hl7-org:v3/voc', 'xmlns:xsi'=>'http://www.w3.org/2001/XMLSchema-instance', 'xsi:schemaLocation'=>'urn:hl7-org:v3 http://xreg2.nist.gov:8080/hitspValidation/schema/','xmlns:sdtc' => 'urn:hl7-org:sdtc'));
40 function close_clinicaldocument() {
41 $this->pop();
44 function self_realmcode(){
45 $this->emptyelement('realmCode', array('code'=>'US'));
48 function self_typeid(){
49 $this->emptyelement('typeId', array('root'=>'2.16.840.1.113883.1.3', 'extension'=>'POCD_HD000040'));
52 function self_templateid($id){
53 $this->emptyelement('templateId', array('root'=>$id));
56 function self_id(){
57 $this->emptyelement('id', array('root'=>$this->unique_id));
60 function self_code(){
61 $this->emptyelement('code', array( 'code'=>'55184-6', 'codeSystem'=>'2.16.840.1.113883.6.1', 'codeSystemName'=>'LOINC', 'displayName'=>'Quality Reporting Document Architecture Calculated Summary Report'));
64 function add_title($value) {
65 $this->element('title', $value);
68 function self_efftime($value){
69 $this->emptyelement('effectiveTime', array('value'=>$value));
72 function self_confidentcode(){
73 $this->emptyelement('confidentialityCode', array('codeSystem'=>'2.16.840.1.113883.5.25', 'code'=>'N', 'codeSystemName'=>'HL7Confidentiality'));
76 function self_lang(){
77 $this->emptyelement('languageCode', array('code'=>'en'));
80 function self_setid($id){
81 $this->emptyelement('setId', array('root'=>$id));
84 function self_version(){
85 $this->emptyelement('versionNumber', array('value'=>1));
89 function self_setpatientRoleid(){
90 $this->emptyelement('id', array('nullFlavor'=>'NA'));
93 function add_patientRole() {
94 $this->push('patientRole');
96 $this->emptyelement('id', array('nullFlavor'=>'NA'));
98 $this->pop();
101 function open_recordTarget() {
102 $this->push('recordTarget');
105 function close_recordTarget() {
106 $this->pop();
109 function open_author() {
110 $this->push('author');
113 function close_author() {
114 $this->pop();
117 function self_authorTime($value){
118 $this->emptyelement('time', array('value'=>$value));
121 function open_assignAuthor() {
122 $this->push('assignedAuthor');
125 function close_assignAuthor() {
126 $this->pop();
129 function self_customId($id){
130 $this->emptyelement('id', array('root'=>$id));
134 function add_authReprestOrginisation($facilArr) {
135 $this->push('representedOrganization');
136 $this->self_customTag('id', array('root' => '2.16.840.1.113883.19.5', 'extension' =>'223344'));
137 $this->element('name', $facilArr['name']);
138 if(!empty($facilArr['phone']))
139 $this->self_customTag('telecom', array('value' => $facilArr['phone'], 'use'=>'WP'));
140 else
141 $this->self_customTag('telecom', array("nullFlavor" => "UNK"));
142 $this->add_facilAddress($facilArr);
143 $this->pop();
146 function open_custodian() {
147 $this->push('custodian');
150 function close_custodian() {
151 $this->pop();
154 function open_assgnCustodian() {
155 $this->push('assignedCustodian');
158 function close_assgnCustodian() {
159 $this->pop();
162 function self_reprsntCustId(){
163 $this->emptyelement('id', array('root'=>'2.16.840.1.113883.19.5'));
166 function add_represtCustodianOrginisation($facilArr) {
167 $this->push('representedCustodianOrganization');
168 $this->self_reprsntCustId();
169 $this->element('name', $facilArr['name']);
170 if(!empty($facilArr['phone']))
171 $this->self_customTag('telecom', array('value' => $facilArr['phone'], 'use'=>'WP'));
172 else
173 $this->self_customTag('telecom', array("nullFlavor" => "UNK"));
174 $this->add_facilAddress($facilArr);
175 $this->pop();
178 function open_infoRecipient() {
179 $this->push('informationRecipient');
182 function close_infoRecipient() {
183 $this->pop();
186 function self_intendedId(){
187 $this->emptyelement('id', array('root'=>'2.16.840.1.113883.3.249.7', 'extension'=>'CPC'));
190 function add_indententRecipient() {
191 $this->push('intendedRecipient');
192 $this->self_intendedId();
193 $this->pop();
196 function open_legalAuthenticator() {
197 $this->push('legalAuthenticator');
200 function close_legalAuthenticator() {
201 $this->pop();
204 function self_legalSignCode(){
205 $this->emptyelement('signatureCode', array('code'=>'S'));
209 function open_assignedEntity() {
210 $this->push('assignedEntity');
213 function close_assignedEntity() {
214 $this->pop();
217 function self_represntOrgId(){
218 $this->emptyelement('id', array('root'=>'2.16.840.1.113883.19.5', 'extension'=>'223344'));
221 function add_represntOrgName($name) {
222 $this->push('representedOrganization');
223 $this->self_represntOrgId();
224 if($name)
225 $this->element('name', $name);
226 else
227 $this->emptyelement('name');
228 $this->pop();
231 function open_participant_data($code_type) {
232 $this->push('participant', array('typeCode'=>$code_type));
235 function close_participant_data() {
236 $this->pop();
239 function open_assocEntityData($class_code) {
240 $this->push('associatedEntity', array('classCode'=>$class_code));
243 function close_assocEntityData() {
244 $this->pop();
247 function self_participantCodeDevice(){
248 $this->emptyelement('code', array('code'=>'129465004', 'displayName'=>'medical record, device', 'codeSystem'=>'2.16.840.1.113883.6.96', 'codeSystemName'=>'SNOMED-CT'));
251 function self_participantCodeLocation(){
252 $this->emptyelement('code', array('code'=>'394730007', 'displayName'=>'healthcare related organization', 'codeSystem'=>'2.16.840.1.113883.6.96', 'codeSystemName'=>'SNOMED-CT'));
255 function self_particpantIdInfo($arr){
256 $this->emptyelement('id', $arr);
259 function add_facilAddress($addrArr) {
261 $this->push('addr',array("use" => "WP"));
262 if($addrArr['street'] != "")
263 $this->element('streetAddressLine', $addrArr['street']);
264 else
265 $this->emptyelement('streetAddressLine',array("nullFlavor" => "UNK"));
267 if($addrArr['city'] != "")
268 $this->element('city', $addrArr['city']);
269 else
270 $this->emptyelement('city',array("nullFlavor" => "UNK"));
272 if($addrArr['state'] != "")
273 $this->element('state', $addrArr['state']);
274 else
275 $this->emptyelement('state',array("nullFlavor" => "UNK"));
278 if($addrArr['postal_code'] != "")
279 $this->element('postalCode', $addrArr['postal_code']);
280 else
281 $this->emptyelement('postalCode',array("nullFlavor" => "UNK"));
283 if($addrArr['country_code'] != "")
284 $this->element('country', $addrArr['country_code']);
285 else
286 $this->emptyelement('country',array("nullFlavor" => "UNK"));
288 $this->pop();
291 function open_mainComponent() {
292 $this->push('component');
295 function close_mainComponent() {
296 $this->pop();
299 function open_structuredBody() {
300 $this->push('structuredBody');
303 function close_structuredBody() {
304 $this->pop();
307 function open_loopComponent(){
308 $this->push('component');
311 function close_loopComponent() {
312 $this->pop();
315 function open_section(){
316 $this->push('section');
319 function close_section() {
320 $this->pop();
323 function self_codeCustom($arr){
324 $this->emptyelement('code', $arr);
327 function open_text(){
328 $this->push('text');
331 function close_text() {
332 $this->pop();
335 function open_list(){
336 $this->push('list');
339 function close_list() {
340 $this->pop();
343 function add_item($value) {
344 $this->element('item', $value);
347 function open_entry($code_type) {
348 if($code_type != "")
349 $this->push('entry', array('typeCode'=>$code_type));
350 else
351 $this->push('entry');
354 function close_entry() {
355 $this->pop();
358 function open_act($arr) {
359 $this->push('act', $arr);
362 function close_act() {
363 $this->pop();
366 function add_entryEffectTime($arr) {
367 $this->push('effectiveTime');
368 $this->emptyelement('low', array('value'=>$arr['low']));
369 if(isset($arr['high'])){
370 $this->emptyelement('high', array('value'=>$arr['high']));
372 $this->pop();
376 function open_customTag($ele, $arr = array()) {
377 if(count($arr) > 0)
378 $this->push($ele, $arr);
379 else
380 $this->push($ele);
383 function close_customTag() {
384 $this->pop();
387 function add_trElementsTitles() {
388 $this->element('th', 'eMeasure Title');
389 $this->element('th', 'Version neutral identifier');
390 $this->element('th', 'Version specific identifier');
393 function add_trElementsValues($arr = array()) {
394 $this->element('td', $arr[0]);
395 $this->element('td', $arr[1]);
396 $this->element('td', $arr[2]);
399 function innerContent($arr = array()) {
400 $this->xml .= '<content styleCode="Bold">'.$arr['name'].'</content>:'.trim($arr['value']);
403 function self_customTag($tag, $arr){
404 $this->emptyelement($tag, $arr);
407 function textDispContent($content) {
408 $this->xml .= '<text>'.$content.'</text>';
411 function add_providerName($nameArr) {
412 $this->push('name');
413 $this->element('given', $nameArr['fname']);
414 $this->element('family', $nameArr['lname']);
415 $this->pop();
418 function add_facilName($facilName) {
419 $this->element('name', $facilName);
422 function add_patientAddress($addrArr) {
423 $this->push('addr',array('use' => 'WP'));
424 if($addrArr['street'] != "")
425 $this->element('streetAddressLine', $addrArr['street']);
426 else
427 $this->emptyelement('streetAddressLine',array("nullFlavor" => "UNK"));
429 if($addrArr['city'] != "")
430 $this->element('city', $addrArr['city']);
431 else
432 $this->emptyelement('city',array("nullFlavor" => "UNK"));
434 if($addrArr['state'] != "")
435 $this->element('state', $addrArr['state']);
436 else
437 $this->emptyelement('state',array("nullFlavor" => "UNK"));
439 if($addrArr['postal_code'] != "")
440 $this->element('postalCode', $addrArr['postal_code']);
441 else
442 $this->emptyelement('postalCode',array("nullFlavor" => "UNK"));
444 if($addrArr['country_code'] != "")
445 $this->element('country', $addrArr['country_code']);
446 else
447 $this->emptyelement('country',array("nullFlavor" => "UNK"));
449 $this->pop();
454 function add_patName($nameArr) {
455 $this->push('name');
456 $this->element('given', $nameArr['fname']);
457 $this->element('family', $nameArr['lname']);
458 $this->pop();
461 function add_userAddress($addrArr) {
463 $this->push('addr',array('use' => 'WP'));
464 if($addrArr['street'] != "")
465 $this->element('streetAddressLine', $addrArr['street']);
466 else
467 $this->emptyelement('streetAddressLine',array("nullFlavor" => "UNK"));
469 if($addrArr['city'] != "")
470 $this->element('city', $addrArr['city']);
471 else
472 $this->emptyelement('city',array("nullFlavor" => "UNK"));
474 if($addrArr['state'] != "")
475 $this->element('state', $addrArr['state']);
476 else
477 $this->emptyelement('state',array("nullFlavor" => "UNK"));
479 if($addrArr['postal_code'] != "")
480 $this->element('postalCode', $addrArr['postal_code']);
481 else
482 $this->emptyelement('postalCode',array("nullFlavor" => "UNK"));
484 if($addrArr['country_code'] != "")
485 $this->element('country', $addrArr['country_code']);
486 else
487 $this->emptyelement('country',array("nullFlavor" => "UNK"));
489 $this->pop();
492 function add_entryTime($arr) {
493 $this->push('time');
494 $this->emptyelement('low', array('value'=>$arr['low']));
495 if(isset($arr['high'])){
496 $this->emptyelement('high', array('value'=>$arr['high']));
498 $this->pop();
501 function add_entryEffectTimeQRDA($arr) {
502 $this->push('effectiveTime');
503 $this->emptyelement('low', array('value'=>$arr['low']));
504 if($arr['high'] != ""){
505 $this->emptyelement('high', array('value'=>$arr['high']));
506 }else{
507 $this->emptyelement('high', array('nullFlavor'=>'NI'));
509 $this->pop();
512 function add_entryEffectTimeQRDAMed($arr) {
513 $arrPass = array('xsi:type' => 'IVL_TS');
514 $this->push('effectiveTime', $arrPass);
515 $this->emptyelement('low', array('value'=>$arr['low']));
516 if($arr['high'] != ""){
517 $this->emptyelement('high', array('value'=>$arr['high']));
518 }else{
519 $this->emptyelement('high', array('nullFlavor'=>'NI'));
521 $this->pop();