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 return $GLOBALS['erx_newcrop_path'];
30 function getErxSoapPath()
32 return $GLOBALS['erx_newcrop_path_soap'];
35 function getErxCredentials()
38 $cred[]=$GLOBALS['erx_account_partner_name'];
39 $cred[]=$GLOBALS['erx_account_name'];
40 $cred[]=$GLOBALS['erx_account_password'];
45 function validation($val_check,$val,$msg)
48 $msg .= $val_check.' '.xl('missing').'<br>';
52 function stripSpecialCharacterFacility($str)
54 $str=preg_replace("/[^a-zA-Z0-9 '().,#:\/\-@_%]/","",$str);
58 function stripSpecialCharacter($str)
60 $str=preg_replace("/[^a-zA-Z0-9 '().,#:\/\-@_%]/","",$str);
64 function stripPhoneSlashes($str)
66 $str=preg_replace('/-/','',$str);
70 function trimData($str,$length)
72 $str=substr($str,0,($length-1));
76 function stringToNumeric($str)
79 return array($str,"");
82 for($i=0;$i<strlen($str);$i++
){
84 if(is_numeric($x) && !$txt){
92 return array($num,$txt);
94 $str=substr($str,0,($length-1));
97 function credentials($doc,$r)
100 $cred=getErxCredentials();
101 $msg = validation(xl('Partner Name'),$cred['0'],$msg);
102 $b = $doc->createElement( "Credentials" );
103 $partnerName = $doc->createElement( "partnerName" );
104 $partnerName->appendChild(
105 $doc->createTextNode( $cred['0'] )
107 $b->appendChild( $partnerName );
108 $msg = validation(xl('ERX Name'),$cred['1'],$msg);
109 $name = $doc->createElement( "name" );
111 $doc->createTextNode( $cred['1'] )
113 $b->appendChild( $name );
114 $msg = validation(xl('ERX Password'),$cred['2'],$msg);
115 $password = $doc->createElement( "password" );
116 $password->appendChild(
117 $doc->createTextNode( $cred['2'] )
119 $b->appendChild( $password );
120 $productName = $doc->createElement( "productName" );
121 $productName->appendChild(
122 $doc->createTextNode( 'OpenEMR' )
124 $b->appendChild( $productName );
125 $productVersion = $doc->createElement( "productVersion" );
126 $productVersion->appendChild(
127 $doc->createTextNode( $GLOBALS['openemr_version'] )
129 $b->appendChild( $productVersion );
130 $r->appendChild( $b );
133 function user_role($doc,$r)
136 $userRole=sqlQuery("select * from users where username=?",array($_SESSION['authUser']));
137 if(!$userRole['newcrop_user_role'])
138 {echo xl('Unauthorized access to ePrescription');die;}
139 $userRole['newcrop_user_role'] = preg_replace('/erx/','',$userRole['newcrop_user_role']);
140 if($userRole['newcrop_user_role'] == 'doctor')
141 $userRole['eRxUser'] = 'LicensedPrescriber';
142 elseif($userRole['newcrop_user_role'] == 'admin' ||
$userRole['newcrop_user_role'] == 'manager' ||
$userRole['newcrop_user_role'] == 'nurse')
143 $userRole['eRxUser'] = 'Staff';
144 elseif($userRole['newcrop_user_role'] == 'midlevelPrescriber')
145 $userRole['eRxUser'] = 'MidlevelPrescriber';
146 elseif($userRole['newcrop_user_role'] == 'supervisingDoctor')
147 $userRole['eRxUser'] = 'SupervisingDoctor';
148 $msg = validation(xl('ERX User'),$userRole['eRxUser'],$msg);
149 $b = $doc->createElement( "UserRole" );
150 $user = $doc->createElement( "user" );
152 $doc->createTextNode( $userRole['eRxUser'] )
154 $b->appendChild( $user );
155 $msg = validation(xl('ERX Role'),$userRole['newcrop_user_role'],$msg);
156 $role = $doc->createElement( "role" );
158 $doc->createTextNode( $userRole['newcrop_user_role'] )
160 $b->appendChild( $role );
161 $r->appendChild( $b );
164 function destination($doc,$r,$page='',$pid)
167 $userRole=sqlQuery("select * from users where username=?",array($_SESSION['authUser']));
168 $userRole['newcrop_user_role'] = preg_replace('/erx/','',$userRole['newcrop_user_role']);
172 if($userRole['newcrop_user_role']=='admin')
174 elseif($userRole['newcrop_user_role']=='manager')
177 $b = $doc->createElement( "Destination" );
178 $requestedPage = $doc->createElement( "requestedPage" );
179 $requestedPage->appendChild(
180 $doc->createTextNode( $page )
182 $b->appendChild( $requestedPage );
183 $r->appendChild( $b );
186 function account($doc,$r)
189 $erxSiteID=sqlQuery("SELECT * FROM facility WHERE primary_business_entity='1'");
190 if(!$erxSiteID['federal_ein'])
192 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
);
195 $b = $doc->createElement( "Account" );
196 $b->setAttribute('ID', $GLOBALS['erx_account_id']);
197 $erxSiteID['name']=stripSpecialCharacterFacility($erxSiteID['name']);
198 $erxSiteID['name']=trimData($erxSiteID['name'],35);
199 $msg = validation(xl('Account Name'),$erxSiteID['name'],$msg);
200 $accountName = $doc->createElement( "accountName" );
201 $accountName->appendChild(
202 $doc->createTextNode( $erxSiteID['name'] )
204 $b->appendChild( $accountName );
205 $msg = validation(xl('Site ID'),$_SESSION['site_id'],$msg);
206 $siteID = $doc->createElement( "siteID" );
207 $siteID->appendChild(
208 $doc->createTextNode( $erxSiteID['federal_ein'] )
210 $b->appendChild( $siteID );
211 $erxSiteID['street']=stripSpecialCharacterFacility($erxSiteID['street']);
212 $erxSiteID['street']=trimData($erxSiteID['street'],35);
213 $AccountAddress = $doc->createElement( "AccountAddress" );
214 $msg = validation(xl('Facility Street'),$erxSiteID['street'],$msg);
215 $address1 = $doc->createElement( "address1" );
216 $address1->appendChild(
217 $doc->createTextNode( $erxSiteID['street'] )
219 $AccountAddress->appendChild( $address1 );
220 $msg = validation(xl('Facility City'),$erxSiteID['city'],$msg);
221 $city = $doc->createElement( "city" );
223 $doc->createTextNode( $erxSiteID['city'] )
225 $AccountAddress->appendChild( $city );
226 $msg = validation(xl('Facility State'),$erxSiteID['state'],$msg);
227 $state = $doc->createElement( "state" );
229 $doc->createTextNode( $erxSiteID['state'] )
231 $AccountAddress->appendChild( $state );
232 $jasonbigzip=$erxSiteID['postal_code'];
233 $jasonbigzip=preg_replace('/[^0-9]/','',$jasonbigzip);
234 if(strlen($jasonbigzip) >=5){
235 $jasonzip=substr($jasonbigzip,0,5);
236 $zip4=substr($jasonbigzip,5,4);
239 $msg = validation(xl('Facility Zip'),$jasonzip,$msg);
241 $zip = $doc->createElement( "zip" );
243 $doc->createTextNode( $jasonzip )
245 $AccountAddress->appendChild( $zip );
246 if(strlen($zip4)==4){
247 $zipFour = $doc->createElement( "zip4" );
248 $zipFour->appendChild(
249 $doc->createTextNode( $zip4 )
251 $AccountAddress->appendChild( $zipFour );
253 $msg = validation(xl('Facility Country code'),$erxSiteID['country_code'],$msg);
254 $county_code = substr($erxSiteID['country_code'],0,2);
255 $country = $doc->createElement( "country" );
256 $country->appendChild(
257 $doc->createTextNode( $county_code )
259 $AccountAddress->appendChild( $country );
260 $b->appendChild( $AccountAddress );
261 $msg = validation(xl('Facility Phone'),$erxSiteID['phone'],$msg);
262 $accountPrimaryPhoneNumber = $doc->createElement( "accountPrimaryPhoneNumber" );
263 $erxSiteID['phone'] = stripPhoneSlashes($erxSiteID['phone']);
264 $accountPrimaryPhoneNumber->appendChild(
265 $doc->createTextNode( $erxSiteID['phone'] )
267 $b->appendChild( $accountPrimaryPhoneNumber );
268 $msg = validation(xl('Facility Fax'),$erxSiteID['fax'],$msg);
269 $accountPrimaryFaxNumber = $doc->createElement( "accountPrimaryFaxNumber" );
270 $erxSiteID['fax'] = stripPhoneSlashes($erxSiteID['fax']);
271 $accountPrimaryFaxNumber->appendChild(
272 $doc->createTextNode( $erxSiteID['fax'] )
274 $b->appendChild( $accountPrimaryFaxNumber );
275 $r->appendChild( $b );
278 function location($doc,$r)
281 $userRole=sqlQuery("SELECT * FROM users AS u LEFT JOIN facility AS f ON f.id=u.facility_id WHERE u.username=?",array($_SESSION['authUser']));
282 $b = $doc->createElement( "Location" );
283 $b->setAttribute('ID',$userRole['id']);
284 $userRole['name']=stripSpecialCharacterFacility($userRole['name']);
285 $userRole['name']=trimData($userRole['name'],35);
286 $locationName = $doc->createElement( 'locationName' );
287 $locationName->appendChild(
288 $doc->createTextNode( $userRole['name'] )
290 $b->appendChild($locationName);
291 $userRole['street']=stripSpecialCharacterFacility($userRole['street']);
292 $userRole['street']=trimData($userRole['street'],35);
293 $LocationAddress = $doc->createElement( 'LocationAddress' );
294 if($userRole['street']){
295 $address1 = $doc->createElement( 'address1' );
296 $address1->appendChild(
297 $doc->createTextNode( $userRole['street'] )
299 $LocationAddress->appendChild($address1);
301 if($userRole['city']){
302 $city = $doc->createElement( 'city' );
304 $doc->createTextNode( $userRole['city'] )
306 $LocationAddress->appendChild( $city );
308 if($userRole['state']){
309 $state = $doc->createElement( 'state' );
311 $doc->createTextNode( $userRole['state'] )
313 $LocationAddress->appendChild($state);
315 $jasonbigzip=$userRole['postal_code'];
316 $jasonbigzip=preg_replace('/[^0-9]/','',$jasonbigzip);
317 if(strlen($jasonbigzip) >=5){
318 $jasonzip=substr($jasonbigzip,0,5);
319 $zip4=substr($jasonbigzip,5,4);
322 $msg = validation(xl('Facility Zip'),$jasonzip,$msg);
324 $zip = $doc->createElement( "zip" );
326 $doc->createTextNode( $jasonzip )
328 $LocationAddress->appendChild( $zip );
329 if(strlen($zip4)==4){
330 $zipFour = $doc->createElement( "zip4" );
331 $zipFour->appendChild(
332 $doc->createTextNode( $zip4 )
334 $LocationAddress->appendChild( $zipFour );
336 if($userRole['country_code']){
337 $county_code = substr($userRole['country_code'],0,2);
338 $country = $doc->createElement( 'country' );
339 $country->appendChild(
340 $doc->createTextNode( $county_code )
342 $LocationAddress->appendChild($country);
344 $b->appendChild($LocationAddress);
345 if($userRole['phone']){
346 $userRole['phone'] = stripPhoneSlashes($userRole['phone']);
347 $primaryPhoneNumber = $doc->createElement( 'primaryPhoneNumber' );
348 $primaryPhoneNumber->appendChild(
349 $doc->createTextNode( $userRole['phone'] )
351 $b->appendChild($primaryPhoneNumber);
353 if($userRole['fax']){
354 $userRole['fax'] = stripPhoneSlashes($userRole['fax']);
355 $primaryFaxNumber = $doc->createElement( 'primaryFaxNumber' );
356 $primaryFaxNumber->appendChild(
357 $doc->createTextNode( $userRole['fax'] )
359 $b->appendChild($primaryFaxNumber);
361 $pharmacyContactNumber = $doc->createElement( 'pharmacyContactNumber' );
362 $pharmacyContactNumber->appendChild(
363 $doc->createTextNode( $userRole['phone'] )
365 $b->appendChild($pharmacyContactNumber);
366 $r->appendChild( $b );
369 function LicensedPrescriber($doc,$r)
372 $user_details = sqlQuery("SELECT * FROM users WHERE id = ?",array($_SESSION['authUserID']));
373 $b = $doc->createElement( "LicensedPrescriber" );
374 $b->setAttribute('ID',$user_details['npi']);
375 $LicensedPrescriberName = $doc->createElement( "LicensedPrescriberName" );
376 $user_details['lname']=stripSpecialCharacter($user_details['lname']);
377 $msg = validation(xl('LicensedPrescriber Last name'),$user_details['lname'],$msg);
378 $last = $doc->createElement( "last" );
380 $doc->createTextNode( $user_details['lname'] )
382 $LicensedPrescriberName->appendChild( $last );
383 $user_details['fname']=stripSpecialCharacter($user_details['fname']);
384 $msg = validation(xl('User First name'),$user_details['fname'],$msg);
385 $first = $doc->createElement( "first" );
387 $doc->createTextNode( $user_details['fname'] )
389 $LicensedPrescriberName->appendChild( $first );
390 $user_details['mname']=stripSpecialCharacter($user_details['mname']);
391 $middle = $doc->createElement( "middle" );
392 $middle->appendChild(
393 $doc->createTextNode( $user_details['mname'] )
395 $LicensedPrescriberName->appendChild( $middle );
396 $b->appendChild( $LicensedPrescriberName );
397 $msg = validation(xl('DEA'),$user_details['federaldrugid'],$msg);
398 $dea = $doc->createElement( "dea" );
400 $doc->createTextNode( $user_details['federaldrugid'] )
402 $b->appendChild( $dea );
403 if($user_details['upin']){
404 $upin = $doc->createElement( "upin" );
406 $doc->createTextNode( $user_details['upin'] )
408 $b->appendChild( $upin );
410 $licenseNumber = $doc->createElement( "licenseNumber" );
411 $licenseNumber->appendChild(
412 $doc->createTextNode( $user_details['state_license_number'] )
414 $b->appendChild( $licenseNumber );
415 $msg = validation(xl('LicensedPrescriber NPI'),$user_details['npi'],$msg);
416 $npi = $doc->createElement( "npi" );
418 $doc->createTextNode( $user_details['npi'] )
420 $b->appendChild( $npi );
421 $r->appendChild( $b );
424 function Staff($doc,$r)
427 $user_details = sqlQuery("SELECT * FROM users WHERE id = ?",array($_SESSION['authUserID']));
428 $b = $doc->createElement( "Staff" );
429 $b->setAttribute('ID',$user_details['username']);
430 $StaffName = $doc->createElement( "StaffName" );
431 $user_details['lname']=stripSpecialCharacter($user_details['lname']);
432 $last = $doc->createElement( "last" );
434 $doc->createTextNode( $user_details['lname'] )
436 $StaffName->appendChild( $last );
437 $user_details['fname']=stripSpecialCharacter($user_details['fname']);
438 $first = $doc->createElement( "first" );
440 $doc->createTextNode( $user_details['fname'] )
442 $StaffName->appendChild( $first );
443 $user_details['mname']=stripSpecialCharacter($user_details['mname']);
444 $middle = $doc->createElement( "middle" );
445 $middle->appendChild(
446 $doc->createTextNode( $user_details['mname'] )
448 $StaffName->appendChild( $middle );
449 $b->appendChild( $StaffName );
450 $license = $doc->createElement( "license" );
451 $license->appendChild(
452 $doc->createTextNode( $user_details['license'] )
454 $b->appendChild( $license );
455 $r->appendChild( $b );
458 function SupervisingDoctor($doc,$r)
461 $user_details = sqlQuery("SELECT * FROM users WHERE id = ?",array($_SESSION['authUserID']));
462 $b = $doc->createElement( "SupervisingDoctor" );
463 $b->setAttribute('ID',$user_details['npi']);
464 $LicensedPrescriberName = $doc->createElement( "LicensedPrescriberName" );
465 $user_details['lname']=stripSpecialCharacter($user_details['lname']);
466 $msg = validation(xl('Supervising Doctor Last name'),$user_details['lname'],$msg);
467 $last = $doc->createElement( "last" );
469 $doc->createTextNode( $user_details['lname'] )
471 $LicensedPrescriberName->appendChild( $last );
472 $user_details['fname']=stripSpecialCharacter($user_details['fname']);
473 $msg = validation(xl('Supervising Doctor First name'),$user_details['fname'],$msg);
474 $first = $doc->createElement( "first" );
476 $doc->createTextNode( $user_details['fname'] )
478 $LicensedPrescriberName->appendChild( $first );
479 $user_details['mname']=stripSpecialCharacter($user_details['mname']);
480 $middle = $doc->createElement( "middle" );
481 $middle->appendChild(
482 $doc->createTextNode( $user_details['mname'] )
484 $LicensedPrescriberName->appendChild( $middle );
485 $b->appendChild( $LicensedPrescriberName );
486 $msg = validation(xl('Supervising Doctor DEA'),$user_details['federaldrugid'],$msg);
487 $dea = $doc->createElement( "dea" );
489 $doc->createTextNode( $user_details['federaldrugid'] )
491 $b->appendChild( $dea );
492 if($user_details['upin']){
493 $upin = $doc->createElement( "upin" );
495 $doc->createTextNode( $user_details['upin'] )
497 $b->appendChild( $upin );
499 $licenseNumber = $doc->createElement( "licenseNumber" );
500 $licenseNumber->appendChild(
501 $doc->createTextNode( $user_details['state_license_number'] )
503 $b->appendChild( $licenseNumber );
504 $msg = validation(xl('Supervising Doctor NPI'),$user_details['npi'],$msg);
505 $npi = $doc->createElement( "npi" );
507 $doc->createTextNode( $user_details['npi'] )
509 $b->appendChild( $npi );
510 $r->appendChild( $b );
513 function MidlevelPrescriber($doc,$r)
516 $user_details = sqlQuery("SELECT * FROM users WHERE id = ?",array($_SESSION['authUserID']));
517 $b = $doc->createElement( "MidlevelPrescriber" );
518 $b->setAttribute('ID',$user_details['npi']);
519 $LicensedPrescriberName = $doc->createElement( "LicensedPrescriberName" );
520 $user_details['lname']=stripSpecialCharacter($user_details['lname']);
521 $msg = validation(xl('Midlevel Prescriber Last name'),$user_details['lname'],$msg);
522 $last = $doc->createElement( "last" );
524 $doc->createTextNode( $user_details['lname'] )
526 $LicensedPrescriberName->appendChild( $last );
527 $user_details['fname']=stripSpecialCharacter($user_details['fname']);
528 $msg = validation(xl('Midlevel Prescriber First name'),$user_details['fname'],$msg);
529 $first = $doc->createElement( "first" );
531 $doc->createTextNode( $user_details['fname'] )
533 $LicensedPrescriberName->appendChild( $first );
534 $user_details['mname']=stripSpecialCharacter($user_details['mname']);
535 $middle = $doc->createElement( "middle" );
536 $middle->appendChild(
537 $doc->createTextNode( $user_details['mname'] )
539 $LicensedPrescriberName->appendChild( $middle );
540 if($user_details['title']){
541 $msg = validation(xl('Midlevel Prescriber Prefix'),$user_details['title'],$msg);
542 $prefix = $doc->createElement( "prefix" );
543 $prefix->appendChild(
544 $doc->createTextNode( $user_details['title'] )
546 $LicensedPrescriberName->appendChild( $prefix );
548 $b->appendChild( $LicensedPrescriberName );
549 $msg = validation(xl('Midlevel Prescriber DEA'),$user_details['federaldrugid'],$msg);
550 $dea = $doc->createElement( "dea" );
552 $doc->createTextNode( $user_details['federaldrugid'] )
554 $b->appendChild( $dea );
555 if($user_details['upin']){
556 $upin = $doc->createElement( "upin" );
558 $doc->createTextNode( $user_details['upin'] )
560 $b->appendChild( $upin );
562 $licenseNumber = $doc->createElement( "licenseNumber" );
563 $licenseNumber->appendChild(
564 $doc->createTextNode( $user_details['state_license_number'] )
566 $b->appendChild( $licenseNumber );
567 $r->appendChild( $b );
570 function Patient($doc,$r,$pid)
572 global $msg,$warning_msg,$dem_check;
573 $patient_data=sqlQuery("select *, DATE_FORMAT(DOB,'%Y%m%d') AS date_of_birth from patient_data where pid=?",array($pid));
574 $b = $doc->createElement( "Patient" );
575 $b->setAttribute('ID',$patient_data['pid']);
576 $PatientName = $doc->createElement( "PatientName" );
577 $patient_data['lname']=stripSpecialCharacter($patient_data['lname']);
578 $patient_data['lname']=trimData($patient_data['lname'],35);
579 //$msg = validation(xl('Patient Last name'),$patient_data['lname'],$msg);
580 if($patient_data['lname']=='')
581 $dem_check.=htmlspecialchars( xl("Patient Last name is missing"), ENT_NOQUOTES
)."<br>";
582 $last = $doc->createElement( "last" );
584 $doc->createTextNode( $patient_data['lname'] )
586 $PatientName->appendChild( $last );
587 $patient_data['fname']=stripSpecialCharacter($patient_data['fname']);
588 $patient_data['fname']=trimData($patient_data['fname'],35);
589 //$msg = validation(xl('Patient First name'),$patient_data['fname'],$msg);
590 if($patient_data['fname']=='')
591 $dem_check.=htmlspecialchars( xl("Patient First name is missing"), ENT_NOQUOTES
)."<br>";
592 $first = $doc->createElement( "first" );
594 $doc->createTextNode( $patient_data['fname'] )
596 $PatientName->appendChild( $first );
597 $patient_data['mname']=stripSpecialCharacter($patient_data['mname']);
598 $patient_data['mname']=trimData($patient_data['mname'],35);
599 $middle = $doc->createElement( "middle" );
600 $middle->appendChild(
601 $doc->createTextNode( $patient_data['mname'] )
603 $PatientName->appendChild( $middle );
604 $b->appendChild( $PatientName );
605 $PatientAddress = $doc->createElement( "PatientAddress" );
606 $patient_data['street']=stripSpecialCharacter($patient_data['street']);
607 $patient_data['street']=trimData($patient_data['street'],35);
608 $msg = validation(xl('Patient Address'),$patient_data['street'],$msg);
609 if(trim($patient_data['street'])=='')
610 $warning_msg .= "<br>".htmlspecialchars( xl("Patient Address is missing"), ENT_NOQUOTES
);
611 $address1 = $doc->createElement( "address1" );
612 $address1->appendChild(
613 $doc->createTextNode( $patient_data['street'] )
615 $PatientAddress->appendChild( $address1 );
616 //$msg = validation(xl('Patient City'),$patient_data['city'],$msg);
617 if($patient_data['city']=='')
618 $dem_check.=htmlspecialchars( xl("Patient City is missing"), ENT_NOQUOTES
)."<br>";
619 $city = $doc->createElement( "city" );
621 $doc->createTextNode( $patient_data['city'] )
623 $PatientAddress->appendChild( $city );
624 if($patient_data['state']){
625 $state = $doc->createElement( "state" );
627 $doc->createTextNode( $patient_data['state'] )
629 $PatientAddress->appendChild( $state );
631 if($patient_data['postal_code']){
632 $zip = $doc->createElement( "zip" );
634 $doc->createTextNode( $patient_data['postal_code'] )
636 $PatientAddress->appendChild( $zip );
638 //$msg = validation(xl('Patient Country'),$patient_data['country_code'],$msg);
639 if(trim($patient_data['country_code'])=='' && $GLOBALS['erx_default_patient_country']=='')
640 $dem_check.=htmlspecialchars( xl("Patient Country is missing. Also you have not set default Patient Country in Global Settings"), ENT_NOQUOTES
)."<br>";
641 elseif(trim($patient_data['country_code'])=='')
642 $patient_data['country_code'] = $GLOBALS['erx_default_patient_country'];
643 $county_code = substr($patient_data['country_code'],0,2);
644 $country = $doc->createElement( "country" );
645 $country->appendChild(
646 $doc->createTextNode( $county_code )
648 $PatientAddress->appendChild( $country );
649 $b->appendChild( $PatientAddress );
650 $PatientContact = $doc->createElement( "PatientContact" );
651 $patient_data['phone_home']=stripPhoneSlashes($patient_data['phone_home']);
652 if($patient_data['phone_home']){
653 $homeTelephone = $doc->createElement( "homeTelephone" );
654 $homeTelephone->appendChild(
655 $doc->createTextNode( $patient_data['phone_home'] )
657 $PatientContact->appendChild( $homeTelephone );
659 $b->appendChild( $PatientContact );
660 $PatientCharacteristics = $doc->createElement( "PatientCharacteristics" );
661 if(trim($patient_data['date_of_birth'])=='' ||
$patient_data['date_of_birth']=='00000000')
662 $warning_msg .= "<br>".htmlspecialchars( xl("Patient Date Of Birth is missing"), ENT_NOQUOTES
);
663 if($patient_data['date_of_birth'] && $patient_data['date_of_birth']!='00000000'){
664 $dob = $doc->createElement( "dob" );
666 $doc->createTextNode( $patient_data['date_of_birth'] )
668 $PatientCharacteristics->appendChild( $dob );
670 if(trim($patient_data['sex'])=='')
671 $warning_msg .= "<br>".htmlspecialchars( xl("Patient Gender is missing"), ENT_NOQUOTES
);
672 if($patient_data['sex']){
673 $gender_val=substr($patient_data['sex'],0,1);
674 $gender = $doc->createElement( "gender" );
675 $gender->appendChild(
676 $doc->createTextNode( $gender_val )
678 $PatientCharacteristics->appendChild( $gender );
680 $b->appendChild( $PatientCharacteristics );
681 PatientFreeformHealthplans($doc,$b,$pid);
682 $allergyId=PatientFreeformAllergy($doc,$b,$pid);
683 $r->appendChild( $b );
687 function OutsidePrescription($doc,$r,$pid,$prescid)
692 $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,
693 DATE_FORMAT(date_added,'%Y%m%d') AS date_added,CONCAT_WS(fname,' ',mname,' ',lname) AS docname,p.quantity
694 FROM prescriptions AS p
695 LEFT JOIN users AS u ON p.provider_id=u.id
696 LEFT JOIN list_options AS l1 ON l1.list_id='drug_form' AND l1.option_id=p.form
697 LEFT JOIN list_options AS l2 ON l2.list_id='drug_route' AND l2.option_id=p.route
698 LEFT JOIN list_options AS l3 ON l3.list_id='drug_interval' AND l3.option_id=p.interval
699 LEFT JOIN list_options AS l4 ON l4.list_id='drug_units' AND l4.option_id=p.unit
700 WHERE p.drug<>'' and p.id=?",array($prescid));
701 $b = $doc->createElement( "OutsidePrescription" );
702 $externalId = $doc->createElement( "externalId" );
703 $externalId->appendChild(
704 $doc->createTextNode( $prec['prescid'] )
706 $b->appendChild( $externalId );
707 $date = $doc->createElement( "date" );
709 $doc->createTextNode( $prec['date_added'] )
711 $b->appendChild( $date );
712 $doctorName = $doc->createElement( "doctorName" );
713 $doctorName->appendChild(
714 $doc->createTextNode( $prec['docname'] )
716 $b->appendChild( $doctorName );
717 $s=stripSpecialCharacter($prec['drug']);
718 $sig = $doc->createElement( "drug" );
720 $doc->createTextNode( trimData($s,80) )
722 $b->appendChild( $sig );
723 $x=stringToNumeric($prec['quantity']);
724 $dispenseNumber = $doc->createElement( "dispenseNumber" );
725 $dispenseNumber->appendChild(
726 $doc->createTextNode( $x[0] )
728 $b->appendChild( $dispenseNumber );
729 $s=trimData($x[1].$prec['size']." ".$prec['title4']." ".$prec['dosage']." In ".$prec['title1']." ".$prec['title2']." ".$prec['title3'],140);
730 $s=stripSpecialCharacter($s);
731 $sig = $doc->createElement( "sig" );
733 $doc->createTextNode( $s )
735 $b->appendChild( $sig );
736 $refillCount = $doc->createElement( "refillCount" );
737 $x=stringToNumeric($prec['per_refill']);
738 $refillCount->appendChild(
739 $doc->createTextNode( $x[0])
741 $b->appendChild( $refillCount );
742 $prescriptionType = $doc->createElement( "prescriptionType" );
743 $prescriptionType->appendChild(
744 $doc->createTextNode( 'reconcile' )
746 $b->appendChild( $prescriptionType );
747 $r->appendChild( $b );
751 function PatientMedication($doc,$r,$pid,$med_limit)
755 if($GLOBALS['erx_upload_active']==1)
756 $active = " and (enddate is null or enddate = '' or enddate = '0000-00-00' )";
757 $res_med=sqlStatement("select * from lists where type='medication' and pid=? and title<>''
758 and erx_uploaded='0' $active order by enddate limit 0,$med_limit",array($pid));
759 $uploaded_med_arr="";
760 while($row_med=sqlFetchArray($res_med))
762 $uploaded_med_arr[]=$row_med['id'];
763 $b = $doc->createElement( "OutsidePrescription" );
764 $externalId = $doc->createElement( "externalId" );
765 $externalId->appendChild(
766 $doc->createTextNode( $row_med['id'] )
768 $b->appendChild( $externalId );
769 $date = $doc->createElement( "date" );
771 $doc->createTextNode( $row_med['begdate'] )
773 $b->appendChild( $date );
774 $doctorName = $doc->createElement( "doctorName" );
775 $doctorName->appendChild(
776 $doc->createTextNode( "" )
778 $b->appendChild( $doctorName );
779 $row_med['title'] = stripSpecialCharacter($row_med['title']);
780 $sig = $doc->createElement( "drug" );
782 $doc->createTextNode( trimData($row_med['title'],80) )
784 $b->appendChild( $sig );
785 $dispenseNumber = $doc->createElement( "dispenseNumber" );
786 $dispenseNumber->appendChild(
787 $doc->createTextNode( $prec['quantity'] )
789 $b->appendChild( $dispenseNumber );
790 $sig = $doc->createElement( "sig" );
792 $doc->createTextNode( "" )
794 $b->appendChild( $sig );
795 $refillCount = $doc->createElement( "refillCount" );
796 $refillCount->appendChild(
797 $doc->createTextNode( "" )
799 $b->appendChild( $refillCount );
800 $prescriptionType = $doc->createElement( "prescriptionType" );
801 $prescriptionType->appendChild(
802 $doc->createTextNode( 'reconcile' )
804 $b->appendChild( $prescriptionType );
805 $r->appendChild( $b );
808 return $uploaded_med_arr;
811 function PatientFreeformAllergy($doc,$r,$pid)
813 $res=sqlStatement("SELECT id,l.title as title1,lo.title as title2,comments FROM lists AS l
814 LEFT JOIN list_options AS lo ON l.outcome=lo.option_id AND lo.list_id='outcome'
815 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));
817 while($row=sqlFetchArray($res))
820 $val['id']=$row['id'];
821 $val['title1']=$row['title1'];
822 $val['title2']=$row['title2'];
823 $val['comments']=$row['comments'];
824 $b = $doc->createElement( "PatientFreeformAllergy" );
825 $b->setAttribute('ID',$val['id']);
827 $allergyName = $doc->createElement( "allergyName" );
828 $allergyName->appendChild(
829 $doc->createTextNode( trimData(stripSpecialCharacter($val['title1']),70) )
831 $b->appendChild( $allergyName );
833 if($val['title2'] && ($val['title2']=='Mild' ||
$val['title2']=='Moderate' ||
$val['title2']=='Severe')){
834 $allergySeverityTypeID = $doc->createElement( "allergySeverityTypeID" );
835 $allergySeverityTypeID->appendChild(
836 $doc->createTextNode( $val['title2'] )
838 $b->appendChild( $allergySeverityTypeID );
840 if($val['comments']){
841 $allergyComment = $doc->createElement( "allergyComment" );
842 $allergyComment->appendChild(
843 $doc->createTextNode( trimData(stripSpecialCharacter($val['comments']),200) )
845 $b->appendChild( $allergyComment );
847 $r->appendChild( $b );
848 $allergyId[]=$row['id'];
853 function PatientFreeformHealthplans($doc, $r, $pid) {
854 $resource = sqlStatement('SELECT
860 FROM `insurance_data` AS `id`
861 LEFT JOIN `insurance_companies` AS `ic` ON `ic`.`id` = `id`.`provider`
863 AND `id`.`subscriber_relationship` = \'self\'
864 AND `id`.`provider` > 0
865 ORDER BY `id`.`date` DESC
867 GROUP BY `ins`.`type`;',
871 while($row = sqlFetchArray($resource)) {
872 $healthplanName = $doc->createElement('healthplanName');
873 $healthplanName->appendChild($doc->createTextNode(
874 stripSpecialCharacter(trimData($row['name'], 35))
877 $patientFreeformHealthplans = $doc->createElement('PatientFreeformHealthplans');
878 $patientFreeformHealthplans->appendChild($healthplanName);
880 $r->appendChild($patientFreeformHealthplans);
884 function PrescriptionRenewalResponse($doc,$r,$pid)
886 $b = $doc->createElement( "PrescriptionRenewalResponse" );
887 $renewalRequestIdentifier = $doc->createElement( "renewalRequestIdentifier" );
888 $renewalRequestIdentifier->appendChild(
889 $doc->createTextNode( 'cbf51649-ce3c-44b8-8f91-6fda121a353d' )
891 $b->appendChild( $renewalRequestIdentifier );
892 $responseCode = $doc->createElement( "responseCode" );
893 $responseCode->appendChild(
894 $doc->createTextNode( 'Undetermined' )
896 $b->appendChild( $responseCode );
897 $r->appendChild( $b );
900 function checkError($xml)
902 $ch = curl_init($xml);
904 $data = array('RxInput' => $xml);
906 curl_setopt($ch, CURLOPT_URL
, getErxPath());
907 curl_setopt($ch, CURLOPT_POST
, 1);
908 curl_setopt($ch, CURLOPT_POSTFIELDS
, "RxInput=".$xml);
909 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER
, 0);
910 curl_setopt($ch, CURLOPT_FOLLOWLOCATION
, 1);
911 curl_setopt($ch, CURLOPT_COOKIESESSION
, TRUE);
912 //curl_setopt($ch, CURLOPT_HEADER, 0);
913 curl_setopt($ch, CURLOPT_COOKIEFILE
, "cookiefile");
914 curl_setopt($ch, CURLOPT_COOKIEJAR
, "cookiefile");
915 curl_setopt($ch, CURLOPT_COOKIE
, session_name() . '=' . session_id());
916 curl_setopt($ch, CURLOPT_USERAGENT
,"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
917 curl_setopt($ch, CURLOPT_RETURNTRANSFER
, true);
919 $result=curl_exec($ch) or die( curl_error($ch)) ;
920 preg_match('/<textarea.*>(.*)Original XML:/is',$result,$error_message);
921 if(strpos($result,'RxEntry.aspx')){
923 erx_error_log($result);
925 $arr=explode('Error',$error_message[1]);
926 //echo "Te: ".count($arr);
930 echo nl2br($error_message[1]);
934 for($i=1;$i<count($arr);$i++
)
936 echo $arr[$i]."<br><br>";
940 if(strpos($result,'RxEntry.aspx'))
946 function erx_error_log($message)
948 $date = date("Y-m-d");
949 if(!is_dir($GLOBALS['OE_SITE_DIR'].'/documents/erx_error'))
950 mkdir($GLOBALS['OE_SITE_DIR'].'/documents/erx_error',0777,true);
951 $filename = $GLOBALS['OE_SITE_DIR']."/documents/erx_error/erx_error"."-".$date.".log";
952 $f=fopen($filename,'a');
953 fwrite($f,date("Y-m-d H:i:s")." ==========> ".$message."\r\n");
957 function stripStrings($str,$pattern)
960 foreach($pattern as $key=>$value){
961 $result = preg_replace("/$key/",$value,$result);