4 * interface/eRx_xml.php Functions for interacting with NewCrop communications.
6 * Copyright (C) 2011 ZMG LLC <sam@zhservices.com>
8 * LICENSE: This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by the Free
10 * Software Foundation; either version 3 of the License, or (at your option) any
11 * later version. This program is distributed in the hope that it will be
12 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
14 * Public License for more details. You should have received a copy of the GNU
15 * General Public License along with this program.
16 * If not, see <http://opensource.org/licenses/gpl-license.php>.
20 * @author Eldho Chacko <eldho@zhservices.com>
21 * @author Vinish K <vinish@zhservices.com>
22 * @link http://www.open-emr.org
27 //if($GLOBALS['erx_source']==1)
28 //return $GLOBALS['erx_path'];
29 //else if($GLOBALS['erx_source']==2)
30 return $GLOBALS['erx_path_production'];
33 function getErxSoapPath()
35 //if($GLOBALS['erx_source']==1)
36 //return $GLOBALS['erx_path_soap'];
37 //else if($GLOBALS['erx_source']==2)
38 return $GLOBALS['erx_path_soap_production'];
41 function getErxCredentials()
44 //if($GLOBALS['erx_source']==1)
46 // $cred[]=$GLOBALS['partner_name'];
47 // $cred[]=$GLOBALS['erx_name'];
48 // $cred[]=$GLOBALS['erx_password'];
50 //else if($GLOBALS['erx_source']==2)
52 $cred[]=$GLOBALS['partner_name_production'];
53 $cred[]=$GLOBALS['erx_name_production'];
54 $cred[]=$GLOBALS['erx_password_production'];
59 function validation($val_check,$val,$msg)
62 $msg .= $val_check.' '.xl('missing').'<br>';
66 function stripSpecialCharacterFacility($str)
68 $str=preg_replace("/[^a-zA-Z0-9 '().,#:\/\-@_%]/","",$str);
72 function stripSpecialCharacter($str)
74 $str=preg_replace("/[^a-zA-Z0-9 '().,#:\/\-@_%]/","",$str);
78 function stripPhoneSlashes($str)
80 $str=preg_replace('/-/','',$str);
84 function trimData($str,$length)
86 $str=substr($str,0,($length-1));
90 function stringToNumeric($str)
93 return array($str,"");
96 for($i=0;$i<strlen($str);$i++
){
98 if(is_numeric($x) && !$txt){
106 return array($num,$txt);
108 $str=substr($str,0,($length-1));
111 function credentials($doc,$r)
114 $cred=getErxCredentials();
115 $msg = validation(xl('Partner Name'),$cred['0'],$msg);
116 $b = $doc->createElement( "Credentials" );
117 $partnerName = $doc->createElement( "partnerName" );
118 $partnerName->appendChild(
119 $doc->createTextNode( $cred['0'] )
121 $b->appendChild( $partnerName );
122 $msg = validation(xl('ERX Name'),$cred['1'],$msg);
123 $name = $doc->createElement( "name" );
125 $doc->createTextNode( $cred['1'] )
127 $b->appendChild( $name );
128 $msg = validation(xl('ERX Password'),$cred['2'],$msg);
129 $password = $doc->createElement( "password" );
130 $password->appendChild(
131 $doc->createTextNode( $cred['2'] )
133 $b->appendChild( $password );
134 $productName = $doc->createElement( "productName" );
135 $productName->appendChild(
136 $doc->createTextNode( 'OpenEMR' )
138 $b->appendChild( $productName );
139 $productVersion = $doc->createElement( "productVersion" );
140 $productVersion->appendChild(
141 $doc->createTextNode( $GLOBALS['openemr_version'] )
143 $b->appendChild( $productVersion );
144 $r->appendChild( $b );
147 function user_role($doc,$r)
150 $userRole=sqlQuery("select * from users where username=?",array($_SESSION['authUser']));
151 if(!$userRole['newcrop_user_role'])
152 {echo xl('Unauthorized access to ePrescription');die;}
153 $userRole['newcrop_user_role'] = preg_replace('/erx/','',$userRole['newcrop_user_role']);
154 if($userRole['newcrop_user_role'] == 'doctor')
155 $userRole['eRxUser'] = 'LicensedPrescriber';
156 elseif($userRole['newcrop_user_role'] == 'admin' ||
$userRole['newcrop_user_role'] == 'manager' ||
$userRole['newcrop_user_role'] == 'nurse')
157 $userRole['eRxUser'] = 'Staff';
158 elseif($userRole['newcrop_user_role'] == 'midlevelPrescriber')
159 $userRole['eRxUser'] = 'MidlevelPrescriber';
160 elseif($userRole['newcrop_user_role'] == 'supervisingDoctor')
161 $userRole['eRxUser'] = 'SupervisingDoctor';
162 $msg = validation(xl('ERX User'),$userRole['eRxUser'],$msg);
163 $b = $doc->createElement( "UserRole" );
164 $user = $doc->createElement( "user" );
166 $doc->createTextNode( $userRole['eRxUser'] )
168 $b->appendChild( $user );
169 $msg = validation(xl('ERX Role'),$userRole['newcrop_user_role'],$msg);
170 $role = $doc->createElement( "role" );
172 $doc->createTextNode( $userRole['newcrop_user_role'] )
174 $b->appendChild( $role );
175 $r->appendChild( $b );
178 function destination($doc,$r,$page='',$pid)
181 $userRole=sqlQuery("select * from users where username=?",array($_SESSION['authUser']));
182 $userRole['newcrop_user_role'] = preg_replace('/erx/','',$userRole['newcrop_user_role']);
186 if($userRole['newcrop_user_role']=='admin')
188 elseif($userRole['newcrop_user_role']=='manager')
191 $b = $doc->createElement( "Destination" );
192 $requestedPage = $doc->createElement( "requestedPage" );
193 $requestedPage->appendChild(
194 $doc->createTextNode( $page )
196 $b->appendChild( $requestedPage );
197 $r->appendChild( $b );
200 function account($doc,$r)
203 $erxSiteID=sqlQuery("SELECT * FROM facility WHERE primary_business_entity='1'");
204 if(!$erxSiteID['federal_ein'])
206 echo htmlspecialchars( xl("Please select a Primary Business Entity facility with 'Tax ID' as your facility Tax ID. If you are an individual practitioner, use your tax id. This is used for identifying you in the NewCrop system."), ENT_NOQUOTES
);
209 $b = $doc->createElement( "Account" );
210 $b->setAttribute('ID', $GLOBALS['erx_account_id']);
211 $erxSiteID['name']=stripSpecialCharacterFacility($erxSiteID['name']);
212 $erxSiteID['name']=trimData($erxSiteID['name'],35);
213 $msg = validation(xl('Account Name'),$erxSiteID['name'],$msg);
214 $accountName = $doc->createElement( "accountName" );
215 $accountName->appendChild(
216 $doc->createTextNode( $erxSiteID['name'] )
218 $b->appendChild( $accountName );
219 $msg = validation(xl('Site ID'),$_SESSION['site_id'],$msg);
220 $siteID = $doc->createElement( "siteID" );
221 $siteID->appendChild(
222 $doc->createTextNode( $erxSiteID['federal_ein'] )
224 $b->appendChild( $siteID );
225 $erxSiteID['street']=stripSpecialCharacterFacility($erxSiteID['street']);
226 $erxSiteID['street']=trimData($erxSiteID['street'],35);
227 $AccountAddress = $doc->createElement( "AccountAddress" );
228 $msg = validation(xl('Facility Street'),$erxSiteID['street'],$msg);
229 $address1 = $doc->createElement( "address1" );
230 $address1->appendChild(
231 $doc->createTextNode( $erxSiteID['street'] )
233 $AccountAddress->appendChild( $address1 );
234 $msg = validation(xl('Facility City'),$erxSiteID['city'],$msg);
235 $city = $doc->createElement( "city" );
237 $doc->createTextNode( $erxSiteID['city'] )
239 $AccountAddress->appendChild( $city );
240 $msg = validation(xl('Facility State'),$erxSiteID['state'],$msg);
241 $state = $doc->createElement( "state" );
243 $doc->createTextNode( $erxSiteID['state'] )
245 $AccountAddress->appendChild( $state );
246 $jasonbigzip=$erxSiteID['postal_code'];
247 $jasonbigzip=preg_replace('/[^0-9]/','',$jasonbigzip);
248 if(strlen($jasonbigzip) >=5){
249 $jasonzip=substr($jasonbigzip,0,5);
250 $zip4=substr($jasonbigzip,5,4);
253 $msg = validation(xl('Facility Zip'),$jasonzip,$msg);
255 $zip = $doc->createElement( "zip" );
257 $doc->createTextNode( $jasonzip )
259 $AccountAddress->appendChild( $zip );
260 if(strlen($zip4)==4){
261 $zipFour = $doc->createElement( "zip4" );
262 $zipFour->appendChild(
263 $doc->createTextNode( $zip4 )
265 $AccountAddress->appendChild( $zipFour );
267 $msg = validation(xl('Facility Country code'),$erxSiteID['country_code'],$msg);
268 $county_code = substr($erxSiteID['country_code'],0,2);
269 $country = $doc->createElement( "country" );
270 $country->appendChild(
271 $doc->createTextNode( $county_code )
273 $AccountAddress->appendChild( $country );
274 $b->appendChild( $AccountAddress );
275 $msg = validation(xl('Facility Phone'),$erxSiteID['phone'],$msg);
276 $accountPrimaryPhoneNumber = $doc->createElement( "accountPrimaryPhoneNumber" );
277 $erxSiteID['phone'] = stripPhoneSlashes($erxSiteID['phone']);
278 $accountPrimaryPhoneNumber->appendChild(
279 $doc->createTextNode( $erxSiteID['phone'] )
281 $b->appendChild( $accountPrimaryPhoneNumber );
282 $msg = validation(xl('Facility Fax'),$erxSiteID['fax'],$msg);
283 $accountPrimaryFaxNumber = $doc->createElement( "accountPrimaryFaxNumber" );
284 $erxSiteID['fax'] = stripPhoneSlashes($erxSiteID['fax']);
285 $accountPrimaryFaxNumber->appendChild(
286 $doc->createTextNode( $erxSiteID['fax'] )
288 $b->appendChild( $accountPrimaryFaxNumber );
289 $r->appendChild( $b );
292 function location($doc,$r)
295 $userRole=sqlQuery("SELECT * FROM users AS u LEFT JOIN facility AS f ON f.id=u.facility_id WHERE u.username=?",array($_SESSION['authUser']));
296 $b = $doc->createElement( "Location" );
297 $b->setAttribute('ID',$userRole['id']);
298 $userRole['name']=stripSpecialCharacterFacility($userRole['name']);
299 $userRole['name']=trimData($userRole['name'],35);
300 $locationName = $doc->createElement( 'locationName' );
301 $locationName->appendChild(
302 $doc->createTextNode( $userRole['name'] )
304 $b->appendChild($locationName);
305 $userRole['street']=stripSpecialCharacterFacility($userRole['street']);
306 $userRole['street']=trimData($userRole['street'],35);
307 $LocationAddress = $doc->createElement( 'LocationAddress' );
308 if($userRole['street']){
309 $address1 = $doc->createElement( 'address1' );
310 $address1->appendChild(
311 $doc->createTextNode( $userRole['street'] )
313 $LocationAddress->appendChild($address1);
315 if($userRole['city']){
316 $city = $doc->createElement( 'city' );
318 $doc->createTextNode( $userRole['city'] )
320 $LocationAddress->appendChild( $city );
322 if($userRole['state']){
323 $state = $doc->createElement( 'state' );
325 $doc->createTextNode( $userRole['state'] )
327 $LocationAddress->appendChild($state);
329 $jasonbigzip=$userRole['postal_code'];
330 $jasonbigzip=preg_replace('/[^0-9]/','',$jasonbigzip);
331 if(strlen($jasonbigzip) >=5){
332 $jasonzip=substr($jasonbigzip,0,5);
333 $zip4=substr($jasonbigzip,5,4);
336 $msg = validation(xl('Facility Zip'),$jasonzip,$msg);
338 $zip = $doc->createElement( "zip" );
340 $doc->createTextNode( $jasonzip )
342 $LocationAddress->appendChild( $zip );
343 if(strlen($zip4)==4){
344 $zipFour = $doc->createElement( "zip4" );
345 $zipFour->appendChild(
346 $doc->createTextNode( $zip4 )
348 $LocationAddress->appendChild( $zipFour );
350 if($userRole['country_code']){
351 $county_code = substr($userRole['country_code'],0,2);
352 $country = $doc->createElement( 'country' );
353 $country->appendChild(
354 $doc->createTextNode( $county_code )
356 $LocationAddress->appendChild($country);
358 $b->appendChild($LocationAddress);
359 if($userRole['phone']){
360 $userRole['phone'] = stripPhoneSlashes($userRole['phone']);
361 $primaryPhoneNumber = $doc->createElement( 'primaryPhoneNumber' );
362 $primaryPhoneNumber->appendChild(
363 $doc->createTextNode( $userRole['phone'] )
365 $b->appendChild($primaryPhoneNumber);
367 if($userRole['fax']){
368 $userRole['fax'] = stripPhoneSlashes($userRole['fax']);
369 $primaryFaxNumber = $doc->createElement( 'primaryFaxNumber' );
370 $primaryFaxNumber->appendChild(
371 $doc->createTextNode( $userRole['fax'] )
373 $b->appendChild($primaryFaxNumber);
375 $pharmacyContactNumber = $doc->createElement( 'pharmacyContactNumber' );
376 $pharmacyContactNumber->appendChild(
377 $doc->createTextNode( $userRole['phone'] )
379 $b->appendChild($pharmacyContactNumber);
380 $r->appendChild( $b );
383 function LicensedPrescriber($doc,$r)
386 $user_details = sqlQuery("SELECT * FROM users WHERE id = ?",array($_SESSION['authUserID']));
387 $b = $doc->createElement( "LicensedPrescriber" );
388 $b->setAttribute('ID',$user_details['npi']);
389 $LicensedPrescriberName = $doc->createElement( "LicensedPrescriberName" );
390 $user_details['lname']=stripSpecialCharacter($user_details['lname']);
391 $msg = validation(xl('LicensedPrescriber Last name'),$user_details['lname'],$msg);
392 $last = $doc->createElement( "last" );
394 $doc->createTextNode( $user_details['lname'] )
396 $LicensedPrescriberName->appendChild( $last );
397 $user_details['fname']=stripSpecialCharacter($user_details['fname']);
398 $msg = validation(xl('User First name'),$user_details['fname'],$msg);
399 $first = $doc->createElement( "first" );
401 $doc->createTextNode( $user_details['fname'] )
403 $LicensedPrescriberName->appendChild( $first );
404 $user_details['mname']=stripSpecialCharacter($user_details['mname']);
405 $middle = $doc->createElement( "middle" );
406 $middle->appendChild(
407 $doc->createTextNode( $user_details['mname'] )
409 $LicensedPrescriberName->appendChild( $middle );
410 $b->appendChild( $LicensedPrescriberName );
411 $msg = validation(xl('DEA'),$user_details['federaldrugid'],$msg);
412 $dea = $doc->createElement( "dea" );
414 $doc->createTextNode( $user_details['federaldrugid'] )
416 $b->appendChild( $dea );
417 if($user_details['upin']){
418 $upin = $doc->createElement( "upin" );
420 $doc->createTextNode( $user_details['upin'] )
422 $b->appendChild( $upin );
424 $licenseNumber = $doc->createElement( "licenseNumber" );
425 $licenseNumber->appendChild(
426 $doc->createTextNode( $user_details['state_license_number'] )
428 $b->appendChild( $licenseNumber );
429 $msg = validation(xl('LicensedPrescriber NPI'),$user_details['npi'],$msg);
430 $npi = $doc->createElement( "npi" );
432 $doc->createTextNode( $user_details['npi'] )
434 $b->appendChild( $npi );
435 $r->appendChild( $b );
438 function Staff($doc,$r)
441 $user_details = sqlQuery("SELECT * FROM users WHERE id = ?",array($_SESSION['authUserID']));
442 $b = $doc->createElement( "Staff" );
443 $b->setAttribute('ID',$user_details['username']);
444 $StaffName = $doc->createElement( "StaffName" );
445 $user_details['lname']=stripSpecialCharacter($user_details['lname']);
446 $last = $doc->createElement( "last" );
448 $doc->createTextNode( $user_details['lname'] )
450 $StaffName->appendChild( $last );
451 $user_details['fname']=stripSpecialCharacter($user_details['fname']);
452 $first = $doc->createElement( "first" );
454 $doc->createTextNode( $user_details['fname'] )
456 $StaffName->appendChild( $first );
457 $user_details['mname']=stripSpecialCharacter($user_details['mname']);
458 $middle = $doc->createElement( "middle" );
459 $middle->appendChild(
460 $doc->createTextNode( $user_details['mname'] )
462 $StaffName->appendChild( $middle );
463 $b->appendChild( $StaffName );
464 $license = $doc->createElement( "license" );
465 $license->appendChild(
466 $doc->createTextNode( $user_details['license'] )
468 $b->appendChild( $license );
469 $r->appendChild( $b );
472 function SupervisingDoctor($doc,$r)
475 $user_details = sqlQuery("SELECT * FROM users WHERE id = ?",array($_SESSION['authUserID']));
476 $b = $doc->createElement( "SupervisingDoctor" );
477 $b->setAttribute('ID',$user_details['npi']);
478 $LicensedPrescriberName = $doc->createElement( "LicensedPrescriberName" );
479 $user_details['lname']=stripSpecialCharacter($user_details['lname']);
480 $msg = validation(xl('Supervising Doctor Last name'),$user_details['lname'],$msg);
481 $last = $doc->createElement( "last" );
483 $doc->createTextNode( $user_details['lname'] )
485 $LicensedPrescriberName->appendChild( $last );
486 $user_details['fname']=stripSpecialCharacter($user_details['fname']);
487 $msg = validation(xl('Supervising Doctor First name'),$user_details['fname'],$msg);
488 $first = $doc->createElement( "first" );
490 $doc->createTextNode( $user_details['fname'] )
492 $LicensedPrescriberName->appendChild( $first );
493 $user_details['mname']=stripSpecialCharacter($user_details['mname']);
494 $middle = $doc->createElement( "middle" );
495 $middle->appendChild(
496 $doc->createTextNode( $user_details['mname'] )
498 $LicensedPrescriberName->appendChild( $middle );
499 $b->appendChild( $LicensedPrescriberName );
500 $msg = validation(xl('Supervising Doctor DEA'),$user_details['federaldrugid'],$msg);
501 $dea = $doc->createElement( "dea" );
503 $doc->createTextNode( $user_details['federaldrugid'] )
505 $b->appendChild( $dea );
506 if($user_details['upin']){
507 $upin = $doc->createElement( "upin" );
509 $doc->createTextNode( $user_details['upin'] )
511 $b->appendChild( $upin );
513 $licenseNumber = $doc->createElement( "licenseNumber" );
514 $licenseNumber->appendChild(
515 $doc->createTextNode( $user_details['state_license_number'] )
517 $b->appendChild( $licenseNumber );
518 $msg = validation(xl('Supervising Doctor NPI'),$user_details['npi'],$msg);
519 $npi = $doc->createElement( "npi" );
521 $doc->createTextNode( $user_details['npi'] )
523 $b->appendChild( $npi );
524 $r->appendChild( $b );
527 function MidlevelPrescriber($doc,$r)
530 $user_details = sqlQuery("SELECT * FROM users WHERE id = ?",array($_SESSION['authUserID']));
531 $b = $doc->createElement( "MidlevelPrescriber" );
532 $b->setAttribute('ID',$user_details['npi']);
533 $LicensedPrescriberName = $doc->createElement( "LicensedPrescriberName" );
534 $user_details['lname']=stripSpecialCharacter($user_details['lname']);
535 $msg = validation(xl('Midlevel Prescriber Last name'),$user_details['lname'],$msg);
536 $last = $doc->createElement( "last" );
538 $doc->createTextNode( $user_details['lname'] )
540 $LicensedPrescriberName->appendChild( $last );
541 $user_details['fname']=stripSpecialCharacter($user_details['fname']);
542 $msg = validation(xl('Midlevel Prescriber First name'),$user_details['fname'],$msg);
543 $first = $doc->createElement( "first" );
545 $doc->createTextNode( $user_details['fname'] )
547 $LicensedPrescriberName->appendChild( $first );
548 $user_details['mname']=stripSpecialCharacter($user_details['mname']);
549 $middle = $doc->createElement( "middle" );
550 $middle->appendChild(
551 $doc->createTextNode( $user_details['mname'] )
553 $LicensedPrescriberName->appendChild( $middle );
554 if($user_details['title']){
555 $msg = validation(xl('Midlevel Prescriber Prefix'),$user_details['title'],$msg);
556 $prefix = $doc->createElement( "prefix" );
557 $prefix->appendChild(
558 $doc->createTextNode( $user_details['title'] )
560 $LicensedPrescriberName->appendChild( $prefix );
562 $b->appendChild( $LicensedPrescriberName );
563 $msg = validation(xl('Midlevel Prescriber DEA'),$user_details['federaldrugid'],$msg);
564 $dea = $doc->createElement( "dea" );
566 $doc->createTextNode( $user_details['federaldrugid'] )
568 $b->appendChild( $dea );
569 if($user_details['upin']){
570 $upin = $doc->createElement( "upin" );
572 $doc->createTextNode( $user_details['upin'] )
574 $b->appendChild( $upin );
576 $licenseNumber = $doc->createElement( "licenseNumber" );
577 $licenseNumber->appendChild(
578 $doc->createTextNode( $user_details['state_license_number'] )
580 $b->appendChild( $licenseNumber );
581 $r->appendChild( $b );
584 function Patient($doc,$r,$pid)
586 global $msg,$warning_msg,$dem_check;
587 $patient_data=sqlQuery("select *, DATE_FORMAT(DOB,'%Y%m%d') AS date_of_birth from patient_data where pid=?",array($pid));
588 $b = $doc->createElement( "Patient" );
589 $b->setAttribute('ID',$patient_data['pid']);
590 $PatientName = $doc->createElement( "PatientName" );
591 $patient_data['lname']=stripSpecialCharacter($patient_data['lname']);
592 $patient_data['lname']=trimData($patient_data['lname'],35);
593 //$msg = validation(xl('Patient Last name'),$patient_data['lname'],$msg);
594 if($patient_data['lname']=='')
595 $dem_check.=htmlspecialchars( xl("Patient Last name is missing"), ENT_NOQUOTES
)."<br>";
596 $last = $doc->createElement( "last" );
598 $doc->createTextNode( $patient_data['lname'] )
600 $PatientName->appendChild( $last );
601 $patient_data['fname']=stripSpecialCharacter($patient_data['fname']);
602 $patient_data['fname']=trimData($patient_data['fname'],35);
603 //$msg = validation(xl('Patient First name'),$patient_data['fname'],$msg);
604 if($patient_data['fname']=='')
605 $dem_check.=htmlspecialchars( xl("Patient First name is missing"), ENT_NOQUOTES
)."<br>";
606 $first = $doc->createElement( "first" );
608 $doc->createTextNode( $patient_data['fname'] )
610 $PatientName->appendChild( $first );
611 $patient_data['mname']=stripSpecialCharacter($patient_data['mname']);
612 $patient_data['mname']=trimData($patient_data['mname'],35);
613 $middle = $doc->createElement( "middle" );
614 $middle->appendChild(
615 $doc->createTextNode( $patient_data['mname'] )
617 $PatientName->appendChild( $middle );
618 $b->appendChild( $PatientName );
619 $PatientAddress = $doc->createElement( "PatientAddress" );
620 $patient_data['street']=stripSpecialCharacter($patient_data['street']);
621 $patient_data['street']=trimData($patient_data['street'],35);
622 $msg = validation(xl('Patient Address'),$patient_data['street'],$msg);
623 if(trim($patient_data['street'])=='')
624 $warning_msg .= "<br>".htmlspecialchars( xl("Patient Address is missing"), ENT_NOQUOTES
);
625 $address1 = $doc->createElement( "address1" );
626 $address1->appendChild(
627 $doc->createTextNode( $patient_data['street'] )
629 $PatientAddress->appendChild( $address1 );
630 //$msg = validation(xl('Patient City'),$patient_data['city'],$msg);
631 if($patient_data['city']=='')
632 $dem_check.=htmlspecialchars( xl("Patient City is missing"), ENT_NOQUOTES
)."<br>";
633 $city = $doc->createElement( "city" );
635 $doc->createTextNode( $patient_data['city'] )
637 $PatientAddress->appendChild( $city );
638 if($patient_data['state']){
639 $state = $doc->createElement( "state" );
641 $doc->createTextNode( $patient_data['state'] )
643 $PatientAddress->appendChild( $state );
645 if($patient_data['postal_code']){
646 $zip = $doc->createElement( "zip" );
648 $doc->createTextNode( $patient_data['postal_code'] )
650 $PatientAddress->appendChild( $zip );
652 //$msg = validation(xl('Patient Country'),$patient_data['country_code'],$msg);
653 if(trim($patient_data['country_code'])=='' && $GLOBALS['erx_default_patient_country']=='')
654 $dem_check.=htmlspecialchars( xl("Patient Country is missing. Also you have not set default Patient Country in Global Settings"), ENT_NOQUOTES
)."<br>";
655 elseif(trim($patient_data['country_code'])=='')
656 $patient_data['country_code'] = $GLOBALS['erx_default_patient_country'];
657 $county_code = substr($patient_data['country_code'],0,2);
658 $country = $doc->createElement( "country" );
659 $country->appendChild(
660 $doc->createTextNode( $county_code )
662 $PatientAddress->appendChild( $country );
663 $b->appendChild( $PatientAddress );
664 $PatientContact = $doc->createElement( "PatientContact" );
665 $patient_data['phone_home']=stripPhoneSlashes($patient_data['phone_home']);
666 if($patient_data['phone_home']){
667 $homeTelephone = $doc->createElement( "homeTelephone" );
668 $homeTelephone->appendChild(
669 $doc->createTextNode( $patient_data['phone_home'] )
671 $PatientContact->appendChild( $homeTelephone );
673 $b->appendChild( $PatientContact );
674 $PatientCharacteristics = $doc->createElement( "PatientCharacteristics" );
675 if(trim($patient_data['date_of_birth'])=='' ||
$patient_data['date_of_birth']=='00000000')
676 $warning_msg .= "<br>".htmlspecialchars( xl("Patient Date Of Birth is missing"), ENT_NOQUOTES
);
677 if($patient_data['date_of_birth'] && $patient_data['date_of_birth']!='00000000'){
678 $dob = $doc->createElement( "dob" );
680 $doc->createTextNode( $patient_data['date_of_birth'] )
682 $PatientCharacteristics->appendChild( $dob );
684 if(trim($patient_data['sex'])=='')
685 $warning_msg .= "<br>".htmlspecialchars( xl("Patient Gender is missing"), ENT_NOQUOTES
);
686 if($patient_data['sex']){
687 $gender_val=substr($patient_data['sex'],0,1);
688 $gender = $doc->createElement( "gender" );
689 $gender->appendChild(
690 $doc->createTextNode( $gender_val )
692 $PatientCharacteristics->appendChild( $gender );
694 $b->appendChild( $PatientCharacteristics );
695 PatientFreeformHealthplans($doc,$b,$pid);
696 $allergyId=PatientFreeformAllergy($doc,$b,$pid);
697 $r->appendChild( $b );
701 function OutsidePrescription($doc,$r,$pid,$prescid)
706 $prec=sqlQuery("SELECT p.note,p.dosage,p.substitute,p.per_refill,p.form,p.route,p.size,p.interval,p.drug,l1.title AS title1,l2.title AS title2,l3.title AS title3,l4.title AS title4,p.id AS prescid,
707 DATE_FORMAT(date_added,'%Y%m%d') AS date_added,CONCAT_WS(fname,' ',mname,' ',lname) AS docname,p.quantity
708 FROM prescriptions AS p
709 LEFT JOIN users AS u ON p.provider_id=u.id
710 LEFT JOIN list_options AS l1 ON l1.list_id='drug_form' AND l1.option_id=p.form
711 LEFT JOIN list_options AS l2 ON l2.list_id='drug_route' AND l2.option_id=p.route
712 LEFT JOIN list_options AS l3 ON l3.list_id='drug_interval' AND l3.option_id=p.interval
713 LEFT JOIN list_options AS l4 ON l4.list_id='drug_units' AND l4.option_id=p.unit
714 WHERE p.drug<>'' and p.id=?",array($prescid));
715 $b = $doc->createElement( "OutsidePrescription" );
716 $externalId = $doc->createElement( "externalId" );
717 $externalId->appendChild(
718 $doc->createTextNode( $prec['prescid'] )
720 $b->appendChild( $externalId );
721 $date = $doc->createElement( "date" );
723 $doc->createTextNode( $prec['date_added'] )
725 $b->appendChild( $date );
726 $doctorName = $doc->createElement( "doctorName" );
727 $doctorName->appendChild(
728 $doc->createTextNode( $prec['docname'] )
730 $b->appendChild( $doctorName );
731 $s=stripSpecialCharacter($prec['drug']);
732 $sig = $doc->createElement( "drug" );
734 $doc->createTextNode( trimData($s,80) )
736 $b->appendChild( $sig );
737 $x=stringToNumeric($prec['quantity']);
738 $dispenseNumber = $doc->createElement( "dispenseNumber" );
739 $dispenseNumber->appendChild(
740 $doc->createTextNode( $x[0] )
742 $b->appendChild( $dispenseNumber );
743 $s=trimData($x[1].$prec['size']." ".$prec['title4']." ".$prec['dosage']." In ".$prec['title1']." ".$prec['title2']." ".$prec['title3'],140);
744 $s=stripSpecialCharacter($s);
745 $sig = $doc->createElement( "sig" );
747 $doc->createTextNode( $s )
749 $b->appendChild( $sig );
750 $refillCount = $doc->createElement( "refillCount" );
751 $x=stringToNumeric($prec['per_refill']);
752 $refillCount->appendChild(
753 $doc->createTextNode( $x[0])
755 $b->appendChild( $refillCount );
756 $prescriptionType = $doc->createElement( "prescriptionType" );
757 $prescriptionType->appendChild(
758 $doc->createTextNode( 'reconcile' )
760 $b->appendChild( $prescriptionType );
761 $r->appendChild( $b );
765 function PatientMedication($doc,$r,$pid,$med_limit)
769 if($GLOBALS['erx_upload_active']==1)
770 $active = " and (enddate is null or enddate = '' or enddate = '0000-00-00' )";
771 $res_med=sqlStatement("select * from lists where type='medication' and pid=? and title<>''
772 and erx_uploaded='0' $active order by enddate limit 0,$med_limit",array($pid));
773 $uploaded_med_arr="";
774 while($row_med=sqlFetchArray($res_med))
776 $uploaded_med_arr[]=$row_med['id'];
777 $b = $doc->createElement( "OutsidePrescription" );
778 $externalId = $doc->createElement( "externalId" );
779 $externalId->appendChild(
780 $doc->createTextNode( $row_med['id'] )
782 $b->appendChild( $externalId );
783 $date = $doc->createElement( "date" );
785 $doc->createTextNode( $row_med['begdate'] )
787 $b->appendChild( $date );
788 $doctorName = $doc->createElement( "doctorName" );
789 $doctorName->appendChild(
790 $doc->createTextNode( "" )
792 $b->appendChild( $doctorName );
793 $row_med['title'] = stripSpecialCharacter($row_med['title']);
794 $sig = $doc->createElement( "drug" );
796 $doc->createTextNode( trimData($row_med['title'],80) )
798 $b->appendChild( $sig );
799 $dispenseNumber = $doc->createElement( "dispenseNumber" );
800 $dispenseNumber->appendChild(
801 $doc->createTextNode( $prec['quantity'] )
803 $b->appendChild( $dispenseNumber );
804 $sig = $doc->createElement( "sig" );
806 $doc->createTextNode( "" )
808 $b->appendChild( $sig );
809 $refillCount = $doc->createElement( "refillCount" );
810 $refillCount->appendChild(
811 $doc->createTextNode( "" )
813 $b->appendChild( $refillCount );
814 $prescriptionType = $doc->createElement( "prescriptionType" );
815 $prescriptionType->appendChild(
816 $doc->createTextNode( 'reconcile' )
818 $b->appendChild( $prescriptionType );
819 $r->appendChild( $b );
822 return $uploaded_med_arr;
825 function PatientFreeformAllergy($doc,$r,$pid)
827 $res=sqlStatement("SELECT id,l.title as title1,lo.title as title2,comments FROM lists AS l
828 LEFT JOIN list_options AS lo ON l.outcome=lo.option_id AND lo.list_id='outcome'
829 WHERE `type`='allergy' AND pid=? AND erx_source='0' and erx_uploaded='0' AND (enddate is null or enddate = '' or enddate = '0000-00-00')",array($pid));
831 while($row=sqlFetchArray($res))
834 $val['id']=$row['id'];
835 $val['title1']=$row['title1'];
836 $val['title2']=$row['title2'];
837 $val['comments']=$row['comments'];
838 $b = $doc->createElement( "PatientFreeformAllergy" );
839 $b->setAttribute('ID',$val['id']);
841 $allergyName = $doc->createElement( "allergyName" );
842 $allergyName->appendChild(
843 $doc->createTextNode( trimData(stripSpecialCharacter($val['title1']),70) )
845 $b->appendChild( $allergyName );
847 if($val['title2'] && ($val['title2']=='Mild' ||
$val['title2']=='Moderate' ||
$val['title2']=='Severe')){
848 $allergySeverityTypeID = $doc->createElement( "allergySeverityTypeID" );
849 $allergySeverityTypeID->appendChild(
850 $doc->createTextNode( $val['title2'] )
852 $b->appendChild( $allergySeverityTypeID );
854 if($val['comments']){
855 $allergyComment = $doc->createElement( "allergyComment" );
856 $allergyComment->appendChild(
857 $doc->createTextNode( trimData(stripSpecialCharacter($val['comments']),200) )
859 $b->appendChild( $allergyComment );
861 $r->appendChild( $b );
862 $allergyId[]=$row['id'];
867 function PatientFreeformHealthplans($doc,$r,$pid)
869 $res=sqlStatement("SELECT `name`,`type` FROM insurance_companies AS ic, insurance_data AS id
870 WHERE ic.id=id.provider AND id.pid=?",array($pid));
871 while($row=sqlFetchArray($res))
873 $b = $doc->createElement( "PatientFreeformHealthplans" );
874 $allergyName = $doc->createElement( "healthplanName" );
875 $allergyName->appendChild(
876 $doc->createTextNode( stripSpecialCharacter(trimData($row['name'],35)) )
878 $b->appendChild( $allergyName );
879 $r->appendChild( $b );
883 function PrescriptionRenewalResponse($doc,$r,$pid)
885 $b = $doc->createElement( "PrescriptionRenewalResponse" );
886 $renewalRequestIdentifier = $doc->createElement( "renewalRequestIdentifier" );
887 $renewalRequestIdentifier->appendChild(
888 $doc->createTextNode( 'cbf51649-ce3c-44b8-8f91-6fda121a353d' )
890 $b->appendChild( $renewalRequestIdentifier );
891 $responseCode = $doc->createElement( "responseCode" );
892 $responseCode->appendChild(
893 $doc->createTextNode( 'Undetermined' )
895 $b->appendChild( $responseCode );
896 $r->appendChild( $b );
899 function checkError($xml)
901 $ch = curl_init($xml);
903 $data = array('RxInput' => $xml);
905 curl_setopt($ch, CURLOPT_URL
, getErxPath());
906 curl_setopt($ch, CURLOPT_POST
, 1);
907 curl_setopt($ch, CURLOPT_POSTFIELDS
, "RxInput=".$xml);
908 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER
, 0);
909 curl_setopt($ch, CURLOPT_FOLLOWLOCATION
, 1);
910 curl_setopt($ch, CURLOPT_COOKIESESSION
, TRUE);
911 //curl_setopt($ch, CURLOPT_HEADER, 0);
912 curl_setopt($ch, CURLOPT_COOKIEFILE
, "cookiefile");
913 curl_setopt($ch, CURLOPT_COOKIEJAR
, "cookiefile");
914 curl_setopt($ch, CURLOPT_COOKIE
, session_name() . '=' . session_id());
915 curl_setopt($ch, CURLOPT_USERAGENT
,"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
916 curl_setopt($ch, CURLOPT_RETURNTRANSFER
, true);
918 $result=curl_exec($ch) or die( curl_error($ch)) ;
919 preg_match('/<textarea.*>(.*)Original XML:/is',$result,$error_message);
920 if(strpos($result,'RxEntry.aspx')){
922 erx_error_log($result);
924 $arr=split('Error',$error_message[1]);
925 //echo "Te: ".count($arr);
929 echo nl2br($error_message[1]);
933 for($i=1;$i<count($arr);$i++
)
935 echo $arr[$i]."<br><br>";
939 if(strpos($result,'RxEntry.aspx'))
945 function erx_error_log($message)
947 $date = date("Y-m-d");
948 if(!is_dir($GLOBALS['OE_SITE_DIR'].'/documents/erx_error'))
949 mkdir($GLOBALS['OE_SITE_DIR'].'/documents/erx_error',0777,true);
950 $filename = $GLOBALS['OE_SITE_DIR']."/documents/erx_error/erx_error"."-".$date.".log";
951 $f=fopen($filename,'a');
952 fwrite($f,date("Y-m-d H:i:s")." ==========> ".$message."\r\n");
956 function stripStrings($str,$pattern)
959 foreach($pattern as $key=>$value){
960 $result = preg_replace("/$key/",$value,$result);