2 // +-----------------------------------------------------------------------------+
3 // Copyright (C) 2011 ZMG LLC <sam@zhservices.com>
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // 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.
18 // A copy of the GNU General Public License is included along with this program:
19 // openemr/interface/login/GnuGPL.html
20 // For more information write to the Free Software
21 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 // Author: Eldho Chacko <eldho@zhservices.com>
24 // Vinish K <vinish@zhservices.com>
26 // +------------------------------------------------------------------------------+
29 //if($GLOBALS['erx_source']==1)
30 //return $GLOBALS['erx_path'];
31 //else if($GLOBALS['erx_source']==2)
32 return $GLOBALS['erx_path_production'];
35 function getErxSoapPath()
37 //if($GLOBALS['erx_source']==1)
38 //return $GLOBALS['erx_path_soap'];
39 //else if($GLOBALS['erx_source']==2)
40 return $GLOBALS['erx_path_soap_production'];
43 function getErxCredentials()
46 //if($GLOBALS['erx_source']==1)
48 // $cred[]=$GLOBALS['partner_name'];
49 // $cred[]=$GLOBALS['erx_name'];
50 // $cred[]=$GLOBALS['erx_password'];
52 //else if($GLOBALS['erx_source']==2)
54 $cred[]=$GLOBALS['partner_name_production'];
55 $cred[]=$GLOBALS['erx_name_production'];
56 $cred[]=$GLOBALS['erx_password_production'];
61 function validation($val_check,$val,$msg)
64 $msg .= $val_check.' '.xl('missing').'<br>';
68 function stripSpecialCharacterFacility($str)
70 $str=preg_replace("/[^a-zA-Z0-9 '().,#:\/\-@_%]/","",$str);
74 function stripSpecialCharacter($str)
76 $str=preg_replace("/[^a-zA-Z0-9 '().,#:\/\-@_%]/","",$str);
80 function stripPhoneSlashes($str)
82 $str=preg_replace('/-/','',$str);
86 function trimData($str,$length)
88 $str=substr($str,0,($length-1));
92 function stringToNumeric($str)
95 return array($str,"");
98 for($i=0;$i<strlen($str);$i++
){
100 if(is_numeric($x) && !$txt){
108 return array($num,$txt);
110 $str=substr($str,0,($length-1));
113 function credentials($doc,$r)
116 $cred=getErxCredentials();
117 $msg = validation(xl('Partner Name'),$cred['0'],$msg);
118 $b = $doc->createElement( "Credentials" );
119 $partnerName = $doc->createElement( "partnerName" );
120 $partnerName->appendChild(
121 $doc->createTextNode( $cred['0'] )
123 $b->appendChild( $partnerName );
124 $msg = validation(xl('ERX Name'),$cred['1'],$msg);
125 $name = $doc->createElement( "name" );
127 $doc->createTextNode( $cred['1'] )
129 $b->appendChild( $name );
130 $msg = validation(xl('ERX Password'),$cred['2'],$msg);
131 $password = $doc->createElement( "password" );
132 $password->appendChild(
133 $doc->createTextNode( $cred['2'] )
135 $b->appendChild( $password );
136 $productName = $doc->createElement( "productName" );
137 $productName->appendChild(
138 $doc->createTextNode( 'OpenEMR' )
140 $b->appendChild( $productName );
141 $productVersion = $doc->createElement( "productVersion" );
142 $productVersion->appendChild(
143 $doc->createTextNode( $GLOBALS['openemr_version'] )
145 $b->appendChild( $productVersion );
146 $r->appendChild( $b );
149 function user_role($doc,$r)
152 $userRole=sqlQuery("select * from users where username=?",array($_SESSION['authUser']));
153 if(!$userRole['newcrop_user_role'])
154 {echo xl('Unauthorized access to ePrescription');die;}
155 $userRole['newcrop_user_role'] = preg_replace('/erx/','',$userRole['newcrop_user_role']);
156 if($userRole['newcrop_user_role'] == 'doctor')
157 $userRole['eRxUser'] = 'LicensedPrescriber';
158 elseif($userRole['newcrop_user_role'] == 'admin' ||
$userRole['newcrop_user_role'] == 'manager' ||
$userRole['newcrop_user_role'] == 'nurse')
159 $userRole['eRxUser'] = 'Staff';
160 elseif($userRole['newcrop_user_role'] == 'midlevelPrescriber')
161 $userRole['eRxUser'] = 'MidlevelPrescriber';
162 elseif($userRole['newcrop_user_role'] == 'supervisingDoctor')
163 $userRole['eRxUser'] = 'SupervisingDoctor';
164 $msg = validation(xl('ERX User'),$userRole['eRxUser'],$msg);
165 $b = $doc->createElement( "UserRole" );
166 $user = $doc->createElement( "user" );
168 $doc->createTextNode( $userRole['eRxUser'] )
170 $b->appendChild( $user );
171 $msg = validation(xl('ERX Role'),$userRole['newcrop_user_role'],$msg);
172 $role = $doc->createElement( "role" );
174 $doc->createTextNode( $userRole['newcrop_user_role'] )
176 $b->appendChild( $role );
177 $r->appendChild( $b );
180 function destination($doc,$r,$page='',$pid)
183 $userRole=sqlQuery("select * from users where username=?",array($_SESSION['authUser']));
184 $userRole['newcrop_user_role'] = preg_replace('/erx/','',$userRole['newcrop_user_role']);
188 if($userRole['newcrop_user_role']=='admin')
190 elseif($userRole['newcrop_user_role']=='manager')
193 $b = $doc->createElement( "Destination" );
194 $requestedPage = $doc->createElement( "requestedPage" );
195 $requestedPage->appendChild(
196 $doc->createTextNode( $page )
198 $b->appendChild( $requestedPage );
199 $r->appendChild( $b );
202 function account($doc,$r)
205 $erxSiteID=sqlQuery("SELECT * FROM facility WHERE primary_business_entity='1'");
206 if(!$erxSiteID['federal_ein'])
208 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
);
211 $b = $doc->createElement( "Account" );
212 $b->setAttribute('ID','1');
213 $erxSiteID['name']=stripSpecialCharacterFacility($erxSiteID['name']);
214 $erxSiteID['name']=trimData($erxSiteID['name'],35);
215 $msg = validation(xl('Account Name'),$erxSiteID['name'],$msg);
216 $accountName = $doc->createElement( "accountName" );
217 $accountName->appendChild(
218 $doc->createTextNode( $erxSiteID['name'] )
220 $b->appendChild( $accountName );
221 $msg = validation(xl('Site ID'),$_SESSION['site_id'],$msg);
222 $siteID = $doc->createElement( "siteID" );
223 $siteID->appendChild(
224 $doc->createTextNode( $erxSiteID['federal_ein'] )
226 $b->appendChild( $siteID );
227 $erxSiteID['street']=stripSpecialCharacterFacility($erxSiteID['street']);
228 $erxSiteID['street']=trimData($erxSiteID['street'],35);
229 $AccountAddress = $doc->createElement( "AccountAddress" );
230 $msg = validation(xl('Facility Street'),$erxSiteID['street'],$msg);
231 $address1 = $doc->createElement( "address1" );
232 $address1->appendChild(
233 $doc->createTextNode( $erxSiteID['street'] )
235 $AccountAddress->appendChild( $address1 );
236 $msg = validation(xl('Facility City'),$erxSiteID['city'],$msg);
237 $city = $doc->createElement( "city" );
239 $doc->createTextNode( $erxSiteID['city'] )
241 $AccountAddress->appendChild( $city );
242 $msg = validation(xl('Facility State'),$erxSiteID['state'],$msg);
243 $state = $doc->createElement( "state" );
245 $doc->createTextNode( $erxSiteID['state'] )
247 $AccountAddress->appendChild( $state );
248 $jasonbigzip=$erxSiteID['postal_code'];
249 $jasonbigzip=preg_replace('/[^0-9]/','',$jasonbigzip);
250 if(strlen($jasonbigzip) >=5){
251 $jasonzip=substr($jasonbigzip,0,5);
252 $zip4=substr($jasonbigzip,5,4);
255 $msg = validation(xl('Facility Zip'),$jasonzip,$msg);
257 $zip = $doc->createElement( "zip" );
259 $doc->createTextNode( $jasonzip )
261 $AccountAddress->appendChild( $zip );
262 if(strlen($zip4)==4){
263 $zipFour = $doc->createElement( "zip4" );
264 $zipFour->appendChild(
265 $doc->createTextNode( $zip4 )
267 $AccountAddress->appendChild( $zipFour );
269 $msg = validation(xl('Facility Country code'),$erxSiteID['country_code'],$msg);
270 $county_code = substr($erxSiteID['country_code'],0,2);
271 $country = $doc->createElement( "country" );
272 $country->appendChild(
273 $doc->createTextNode( $county_code )
275 $AccountAddress->appendChild( $country );
276 $b->appendChild( $AccountAddress );
277 $msg = validation(xl('Facility Phone'),$erxSiteID['phone'],$msg);
278 $accountPrimaryPhoneNumber = $doc->createElement( "accountPrimaryPhoneNumber" );
279 $erxSiteID['phone'] = stripPhoneSlashes($erxSiteID['phone']);
280 $accountPrimaryPhoneNumber->appendChild(
281 $doc->createTextNode( $erxSiteID['phone'] )
283 $b->appendChild( $accountPrimaryPhoneNumber );
284 $msg = validation(xl('Facility Fax'),$erxSiteID['fax'],$msg);
285 $accountPrimaryFaxNumber = $doc->createElement( "accountPrimaryFaxNumber" );
286 $erxSiteID['fax'] = stripPhoneSlashes($erxSiteID['fax']);
287 $accountPrimaryFaxNumber->appendChild(
288 $doc->createTextNode( $erxSiteID['fax'] )
290 $b->appendChild( $accountPrimaryFaxNumber );
291 $r->appendChild( $b );
294 function location($doc,$r)
297 $userRole=sqlQuery("SELECT * FROM users AS u LEFT JOIN facility AS f ON f.id=u.facility_id WHERE u.username=?",array($_SESSION['authUser']));
298 $b = $doc->createElement( "Location" );
299 $b->setAttribute('ID',$userRole['id']);
300 $userRole['name']=stripSpecialCharacterFacility($userRole['name']);
301 $userRole['name']=trimData($userRole['name'],35);
302 $locationName = $doc->createElement( 'locationName' );
303 $locationName->appendChild(
304 $doc->createTextNode( $userRole['name'] )
306 $b->appendChild($locationName);
307 $userRole['street']=stripSpecialCharacterFacility($userRole['street']);
308 $userRole['street']=trimData($userRole['street'],35);
309 $LocationAddress = $doc->createElement( 'LocationAddress' );
310 if($userRole['street']){
311 $address1 = $doc->createElement( 'address1' );
312 $address1->appendChild(
313 $doc->createTextNode( $userRole['street'] )
315 $LocationAddress->appendChild($address1);
317 if($userRole['city']){
318 $city = $doc->createElement( 'city' );
320 $doc->createTextNode( $userRole['city'] )
322 $LocationAddress->appendChild( $city );
324 if($userRole['state']){
325 $state = $doc->createElement( 'state' );
327 $doc->createTextNode( $userRole['state'] )
329 $LocationAddress->appendChild($state);
331 $jasonbigzip=$userRole['postal_code'];
332 $jasonbigzip=preg_replace('/[^0-9]/','',$jasonbigzip);
333 if(strlen($jasonbigzip) >=5){
334 $jasonzip=substr($jasonbigzip,0,5);
335 $zip4=substr($jasonbigzip,5,4);
338 $msg = validation(xl('Facility Zip'),$jasonzip,$msg);
340 $zip = $doc->createElement( "zip" );
342 $doc->createTextNode( $jasonzip )
344 $LocationAddress->appendChild( $zip );
345 if(strlen($zip4)==4){
346 $zipFour = $doc->createElement( "zip4" );
347 $zipFour->appendChild(
348 $doc->createTextNode( $zip4 )
350 $LocationAddress->appendChild( $zipFour );
352 if($userRole['country_code']){
353 $county_code = substr($userRole['country_code'],0,2);
354 $country = $doc->createElement( 'country' );
355 $country->appendChild(
356 $doc->createTextNode( $county_code )
358 $LocationAddress->appendChild($country);
360 $b->appendChild($LocationAddress);
361 if($userRole['phone']){
362 $userRole['phone'] = stripPhoneSlashes($userRole['phone']);
363 $primaryPhoneNumber = $doc->createElement( 'primaryPhoneNumber' );
364 $primaryPhoneNumber->appendChild(
365 $doc->createTextNode( $userRole['phone'] )
367 $b->appendChild($primaryPhoneNumber);
369 if($userRole['fax']){
370 $userRole['fax'] = stripPhoneSlashes($userRole['fax']);
371 $primaryFaxNumber = $doc->createElement( 'primaryFaxNumber' );
372 $primaryFaxNumber->appendChild(
373 $doc->createTextNode( $userRole['fax'] )
375 $b->appendChild($primaryFaxNumber);
377 $pharmacyContactNumber = $doc->createElement( 'pharmacyContactNumber' );
378 $pharmacyContactNumber->appendChild(
379 $doc->createTextNode( $userRole['phone'] )
381 $b->appendChild($pharmacyContactNumber);
382 $r->appendChild( $b );
385 function LicensedPrescriber($doc,$r)
388 $user_details = sqlQuery("SELECT * FROM users WHERE id = ?",array($_SESSION['authUserID']));
389 $b = $doc->createElement( "LicensedPrescriber" );
390 $b->setAttribute('ID',$user_details['npi']);
391 $LicensedPrescriberName = $doc->createElement( "LicensedPrescriberName" );
392 $user_details['lname']=stripSpecialCharacter($user_details['lname']);
393 $msg = validation(xl('LicensedPrescriber Last name'),$user_details['lname'],$msg);
394 $last = $doc->createElement( "last" );
396 $doc->createTextNode( $user_details['lname'] )
398 $LicensedPrescriberName->appendChild( $last );
399 $user_details['fname']=stripSpecialCharacter($user_details['fname']);
400 $msg = validation(xl('User First name'),$user_details['fname'],$msg);
401 $first = $doc->createElement( "first" );
403 $doc->createTextNode( $user_details['fname'] )
405 $LicensedPrescriberName->appendChild( $first );
406 $user_details['mname']=stripSpecialCharacter($user_details['mname']);
407 $middle = $doc->createElement( "middle" );
408 $middle->appendChild(
409 $doc->createTextNode( $user_details['mname'] )
411 $LicensedPrescriberName->appendChild( $middle );
412 $b->appendChild( $LicensedPrescriberName );
413 $msg = validation(xl('DEA'),$user_details['federaldrugid'],$msg);
414 $dea = $doc->createElement( "dea" );
416 $doc->createTextNode( $user_details['federaldrugid'] )
418 $b->appendChild( $dea );
419 if($user_details['upin']){
420 $upin = $doc->createElement( "upin" );
422 $doc->createTextNode( $user_details['upin'] )
424 $b->appendChild( $upin );
426 $licenseNumber = $doc->createElement( "licenseNumber" );
427 $licenseNumber->appendChild(
428 $doc->createTextNode( $user_details['state_license_number'] )
430 $b->appendChild( $licenseNumber );
431 $msg = validation(xl('LicensedPrescriber NPI'),$user_details['npi'],$msg);
432 $npi = $doc->createElement( "npi" );
434 $doc->createTextNode( $user_details['npi'] )
436 $b->appendChild( $npi );
437 $r->appendChild( $b );
440 function Staff($doc,$r)
443 $user_details = sqlQuery("SELECT * FROM users WHERE id = ?",array($_SESSION['authUserID']));
444 $b = $doc->createElement( "Staff" );
445 $b->setAttribute('ID',$user_details['username']);
446 $StaffName = $doc->createElement( "StaffName" );
447 $user_details['lname']=stripSpecialCharacter($user_details['lname']);
448 $last = $doc->createElement( "last" );
450 $doc->createTextNode( $user_details['lname'] )
452 $StaffName->appendChild( $last );
453 $user_details['fname']=stripSpecialCharacter($user_details['fname']);
454 $first = $doc->createElement( "first" );
456 $doc->createTextNode( $user_details['fname'] )
458 $StaffName->appendChild( $first );
459 $user_details['mname']=stripSpecialCharacter($user_details['mname']);
460 $middle = $doc->createElement( "middle" );
461 $middle->appendChild(
462 $doc->createTextNode( $user_details['mname'] )
464 $StaffName->appendChild( $middle );
465 $b->appendChild( $StaffName );
466 $license = $doc->createElement( "license" );
467 $license->appendChild(
468 $doc->createTextNode( $user_details['license'] )
470 $b->appendChild( $license );
471 $r->appendChild( $b );
474 function SupervisingDoctor($doc,$r)
477 $user_details = sqlQuery("SELECT * FROM users WHERE id = ?",array($_SESSION['authUserID']));
478 $b = $doc->createElement( "SupervisingDoctor" );
479 $b->setAttribute('ID',$user_details['npi']);
480 $LicensedPrescriberName = $doc->createElement( "LicensedPrescriberName" );
481 $user_details['lname']=stripSpecialCharacter($user_details['lname']);
482 $msg = validation(xl('Supervising Doctor Last name'),$user_details['lname'],$msg);
483 $last = $doc->createElement( "last" );
485 $doc->createTextNode( $user_details['lname'] )
487 $LicensedPrescriberName->appendChild( $last );
488 $user_details['fname']=stripSpecialCharacter($user_details['fname']);
489 $msg = validation(xl('Supervising Doctor First name'),$user_details['fname'],$msg);
490 $first = $doc->createElement( "first" );
492 $doc->createTextNode( $user_details['fname'] )
494 $LicensedPrescriberName->appendChild( $first );
495 $user_details['mname']=stripSpecialCharacter($user_details['mname']);
496 $middle = $doc->createElement( "middle" );
497 $middle->appendChild(
498 $doc->createTextNode( $user_details['mname'] )
500 $LicensedPrescriberName->appendChild( $middle );
501 $b->appendChild( $LicensedPrescriberName );
502 $msg = validation(xl('Supervising Doctor DEA'),$user_details['federaldrugid'],$msg);
503 $dea = $doc->createElement( "dea" );
505 $doc->createTextNode( $user_details['federaldrugid'] )
507 $b->appendChild( $dea );
508 if($user_details['upin']){
509 $upin = $doc->createElement( "upin" );
511 $doc->createTextNode( $user_details['upin'] )
513 $b->appendChild( $upin );
515 $licenseNumber = $doc->createElement( "licenseNumber" );
516 $licenseNumber->appendChild(
517 $doc->createTextNode( $user_details['state_license_number'] )
519 $b->appendChild( $licenseNumber );
520 $msg = validation(xl('Supervising Doctor NPI'),$user_details['npi'],$msg);
521 $npi = $doc->createElement( "npi" );
523 $doc->createTextNode( $user_details['npi'] )
525 $b->appendChild( $npi );
526 $r->appendChild( $b );
529 function MidlevelPrescriber($doc,$r)
532 $user_details = sqlQuery("SELECT * FROM users WHERE id = ?",array($_SESSION['authUserID']));
533 $b = $doc->createElement( "MidlevelPrescriber" );
534 $b->setAttribute('ID',$user_details['npi']);
535 $LicensedPrescriberName = $doc->createElement( "LicensedPrescriberName" );
536 $user_details['lname']=stripSpecialCharacter($user_details['lname']);
537 $msg = validation(xl('Midlevel Prescriber Last name'),$user_details['lname'],$msg);
538 $last = $doc->createElement( "last" );
540 $doc->createTextNode( $user_details['lname'] )
542 $LicensedPrescriberName->appendChild( $last );
543 $user_details['fname']=stripSpecialCharacter($user_details['fname']);
544 $msg = validation(xl('Midlevel Prescriber First name'),$user_details['fname'],$msg);
545 $first = $doc->createElement( "first" );
547 $doc->createTextNode( $user_details['fname'] )
549 $LicensedPrescriberName->appendChild( $first );
550 $user_details['mname']=stripSpecialCharacter($user_details['mname']);
551 $middle = $doc->createElement( "middle" );
552 $middle->appendChild(
553 $doc->createTextNode( $user_details['mname'] )
555 $LicensedPrescriberName->appendChild( $middle );
556 if($user_details['title']){
557 $msg = validation(xl('Midlevel Prescriber Prefix'),$user_details['title'],$msg);
558 $prefix = $doc->createElement( "prefix" );
559 $prefix->appendChild(
560 $doc->createTextNode( $user_details['title'] )
562 $LicensedPrescriberName->appendChild( $prefix );
564 $b->appendChild( $LicensedPrescriberName );
565 $msg = validation(xl('Midlevel Prescriber DEA'),$user_details['federaldrugid'],$msg);
566 $dea = $doc->createElement( "dea" );
568 $doc->createTextNode( $user_details['federaldrugid'] )
570 $b->appendChild( $dea );
571 if($user_details['upin']){
572 $upin = $doc->createElement( "upin" );
574 $doc->createTextNode( $user_details['upin'] )
576 $b->appendChild( $upin );
578 $licenseNumber = $doc->createElement( "licenseNumber" );
579 $licenseNumber->appendChild(
580 $doc->createTextNode( $user_details['state_license_number'] )
582 $b->appendChild( $licenseNumber );
583 $r->appendChild( $b );
586 function Patient($doc,$r,$pid)
588 global $msg,$warning_msg,$dem_check;
589 $patient_data=sqlQuery("select *, DATE_FORMAT(DOB,'%Y%m%d') AS date_of_birth from patient_data where pid=?",array($pid));
590 $b = $doc->createElement( "Patient" );
591 $b->setAttribute('ID',$patient_data['pid']);
592 $PatientName = $doc->createElement( "PatientName" );
593 $patient_data['lname']=stripSpecialCharacter($patient_data['lname']);
594 $patient_data['lname']=trimData($patient_data['lname'],35);
595 //$msg = validation(xl('Patient Last name'),$patient_data['lname'],$msg);
596 if($patient_data['lname']=='')
597 $dem_check.=htmlspecialchars( xl("Patient Last name is missing"), ENT_NOQUOTES
)."<br>";
598 $last = $doc->createElement( "last" );
600 $doc->createTextNode( $patient_data['lname'] )
602 $PatientName->appendChild( $last );
603 $patient_data['fname']=stripSpecialCharacter($patient_data['fname']);
604 $patient_data['fname']=trimData($patient_data['fname'],35);
605 //$msg = validation(xl('Patient First name'),$patient_data['fname'],$msg);
606 if($patient_data['fname']=='')
607 $dem_check.=htmlspecialchars( xl("Patient First name is missing"), ENT_NOQUOTES
)."<br>";
608 $first = $doc->createElement( "first" );
610 $doc->createTextNode( $patient_data['fname'] )
612 $PatientName->appendChild( $first );
613 $patient_data['mname']=stripSpecialCharacter($patient_data['mname']);
614 $patient_data['mname']=trimData($patient_data['mname'],35);
615 $middle = $doc->createElement( "middle" );
616 $middle->appendChild(
617 $doc->createTextNode( $patient_data['mname'] )
619 $PatientName->appendChild( $middle );
620 $b->appendChild( $PatientName );
621 $PatientAddress = $doc->createElement( "PatientAddress" );
622 $patient_data['street']=stripSpecialCharacter($patient_data['street']);
623 $patient_data['street']=trimData($patient_data['street'],35);
624 $msg = validation(xl('Patient Address'),$patient_data['street'],$msg);
625 if(trim($patient_data['street'])=='')
626 $warning_msg .= "<br>".htmlspecialchars( xl("Patient Address is missing"), ENT_NOQUOTES
);
627 $address1 = $doc->createElement( "address1" );
628 $address1->appendChild(
629 $doc->createTextNode( $patient_data['street'] )
631 $PatientAddress->appendChild( $address1 );
632 //$msg = validation(xl('Patient City'),$patient_data['city'],$msg);
633 if($patient_data['city']=='')
634 $dem_check.=htmlspecialchars( xl("Patient City is missing"), ENT_NOQUOTES
)."<br>";
635 $city = $doc->createElement( "city" );
637 $doc->createTextNode( $patient_data['city'] )
639 $PatientAddress->appendChild( $city );
640 if($patient_data['state']){
641 $state = $doc->createElement( "state" );
643 $doc->createTextNode( $patient_data['state'] )
645 $PatientAddress->appendChild( $state );
647 if($patient_data['postal_code']){
648 $zip = $doc->createElement( "zip" );
650 $doc->createTextNode( $patient_data['postal_code'] )
652 $PatientAddress->appendChild( $zip );
654 //$msg = validation(xl('Patient Country'),$patient_data['country_code'],$msg);
655 if(trim($patient_data['country_code'])=='' && $GLOBALS['erx_default_patient_country']=='')
656 $dem_check.=htmlspecialchars( xl("Patient Country is missing. Also you have not set default Patient Country in Global Settings"), ENT_NOQUOTES
)."<br>";
657 elseif(trim($patient_data['country_code'])=='')
658 $patient_data['country_code'] = $GLOBALS['erx_default_patient_country'];
659 $county_code = substr($patient_data['country_code'],0,2);
660 $country = $doc->createElement( "country" );
661 $country->appendChild(
662 $doc->createTextNode( $county_code )
664 $PatientAddress->appendChild( $country );
665 $b->appendChild( $PatientAddress );
666 $PatientContact = $doc->createElement( "PatientContact" );
667 $patient_data['phone_home']=stripPhoneSlashes($patient_data['phone_home']);
668 if($patient_data['phone_home']){
669 $homeTelephone = $doc->createElement( "homeTelephone" );
670 $homeTelephone->appendChild(
671 $doc->createTextNode( $patient_data['phone_home'] )
673 $PatientContact->appendChild( $homeTelephone );
675 $b->appendChild( $PatientContact );
676 $PatientCharacteristics = $doc->createElement( "PatientCharacteristics" );
677 if(trim($patient_data['date_of_birth'])=='' ||
$patient_data['date_of_birth']=='00000000')
678 $warning_msg .= "<br>".htmlspecialchars( xl("Patient Date Of Birth is missing"), ENT_NOQUOTES
);
679 if($patient_data['date_of_birth'] && $patient_data['date_of_birth']!='00000000'){
680 $dob = $doc->createElement( "dob" );
682 $doc->createTextNode( $patient_data['date_of_birth'] )
684 $PatientCharacteristics->appendChild( $dob );
686 if(trim($patient_data['sex'])=='')
687 $warning_msg .= "<br>".htmlspecialchars( xl("Patient Gender is missing"), ENT_NOQUOTES
);
688 if($patient_data['sex']){
689 $gender_val=substr($patient_data['sex'],0,1);
690 $gender = $doc->createElement( "gender" );
691 $gender->appendChild(
692 $doc->createTextNode( $gender_val )
694 $PatientCharacteristics->appendChild( $gender );
696 $b->appendChild( $PatientCharacteristics );
697 PatientFreeformHealthplans($doc,$b,$pid);
698 $allergyId=PatientFreeformAllergy($doc,$b,$pid);
699 $r->appendChild( $b );
703 function OutsidePrescription($doc,$r,$pid,$prescid)
708 $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,
709 DATE_FORMAT(date_added,'%Y%m%d') AS date_added,CONCAT_WS(fname,' ',mname,' ',lname) AS docname,p.quantity
710 FROM prescriptions AS p
711 LEFT JOIN users AS u ON p.provider_id=u.id
712 LEFT JOIN list_options AS l1 ON l1.list_id='drug_form' AND l1.option_id=p.form
713 LEFT JOIN list_options AS l2 ON l2.list_id='drug_route' AND l2.option_id=p.route
714 LEFT JOIN list_options AS l3 ON l3.list_id='drug_interval' AND l3.option_id=p.interval
715 LEFT JOIN list_options AS l4 ON l4.list_id='drug_units' AND l4.option_id=p.unit
716 WHERE p.drug<>'' and p.id=?",array($prescid));
717 $b = $doc->createElement( "OutsidePrescription" );
718 $externalId = $doc->createElement( "externalId" );
719 $externalId->appendChild(
720 $doc->createTextNode( $prec['prescid'] )
722 $b->appendChild( $externalId );
723 $date = $doc->createElement( "date" );
725 $doc->createTextNode( $prec['date_added'] )
727 $b->appendChild( $date );
728 $doctorName = $doc->createElement( "doctorName" );
729 $doctorName->appendChild(
730 $doc->createTextNode( $prec['docname'] )
732 $b->appendChild( $doctorName );
733 $s=stripSpecialCharacter($prec['drug']);
734 $sig = $doc->createElement( "drug" );
736 $doc->createTextNode( trimData($s,80) )
738 $b->appendChild( $sig );
739 $x=stringToNumeric($prec['quantity']);
740 $dispenseNumber = $doc->createElement( "dispenseNumber" );
741 $dispenseNumber->appendChild(
742 $doc->createTextNode( $x[0] )
744 $b->appendChild( $dispenseNumber );
745 $s=trimData($x[1].$prec['size']." ".$prec['title4']." ".$prec['dosage']." In ".$prec['title1']." ".$prec['title2']." ".$prec['title3'],140);
746 $s=stripSpecialCharacter($s);
747 $sig = $doc->createElement( "sig" );
749 $doc->createTextNode( $s )
751 $b->appendChild( $sig );
752 $refillCount = $doc->createElement( "refillCount" );
753 $x=stringToNumeric($prec['per_refill']);
754 $refillCount->appendChild(
755 $doc->createTextNode( $x[0])
757 $b->appendChild( $refillCount );
758 $prescriptionType = $doc->createElement( "prescriptionType" );
759 $prescriptionType->appendChild(
760 $doc->createTextNode( 'reconcile' )
762 $b->appendChild( $prescriptionType );
763 $r->appendChild( $b );
767 function PatientMedication($doc,$r,$pid,$med_limit)
771 if($GLOBALS['erx_upload_active']==1)
772 $active = " and (enddate is null or enddate = '' or enddate = '0000-00-00' )";
773 $res_med=sqlStatement("select * from lists where type='medication' and pid=? and title<>''
774 and erx_uploaded='0' $active order by enddate limit 0,$med_limit",array($pid));
775 $uploaded_med_arr="";
776 while($row_med=sqlFetchArray($res_med))
778 $uploaded_med_arr[]=$row_med['id'];
779 $b = $doc->createElement( "OutsidePrescription" );
780 $externalId = $doc->createElement( "externalId" );
781 $externalId->appendChild(
782 $doc->createTextNode( $row_med['id'] )
784 $b->appendChild( $externalId );
785 $date = $doc->createElement( "date" );
787 $doc->createTextNode( $row_med['begdate'] )
789 $b->appendChild( $date );
790 $doctorName = $doc->createElement( "doctorName" );
791 $doctorName->appendChild(
792 $doc->createTextNode( "" )
794 $b->appendChild( $doctorName );
795 $row_med['title'] = stripSpecialCharacter($row_med['title']);
796 $sig = $doc->createElement( "drug" );
798 $doc->createTextNode( trimData($row_med['title'],80) )
800 $b->appendChild( $sig );
801 $dispenseNumber = $doc->createElement( "dispenseNumber" );
802 $dispenseNumber->appendChild(
803 $doc->createTextNode( $prec['quantity'] )
805 $b->appendChild( $dispenseNumber );
806 $sig = $doc->createElement( "sig" );
808 $doc->createTextNode( "" )
810 $b->appendChild( $sig );
811 $refillCount = $doc->createElement( "refillCount" );
812 $refillCount->appendChild(
813 $doc->createTextNode( "" )
815 $b->appendChild( $refillCount );
816 $prescriptionType = $doc->createElement( "prescriptionType" );
817 $prescriptionType->appendChild(
818 $doc->createTextNode( 'reconcile' )
820 $b->appendChild( $prescriptionType );
821 $r->appendChild( $b );
824 return $uploaded_med_arr;
827 function PatientFreeformAllergy($doc,$r,$pid)
829 $res=sqlStatement("SELECT id,l.title as title1,lo.title as title2,comments FROM lists AS l
830 LEFT JOIN list_options AS lo ON l.outcome=lo.option_id AND lo.list_id='outcome'
831 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));
833 while($row=sqlFetchArray($res))
836 $val['id']=$row['id'];
837 $val['title1']=$row['title1'];
838 $val['title2']=$row['title2'];
839 $val['comments']=$row['comments'];
840 $b = $doc->createElement( "PatientFreeformAllergy" );
841 $b->setAttribute('ID',$val['id']);
843 $allergyName = $doc->createElement( "allergyName" );
844 $allergyName->appendChild(
845 $doc->createTextNode( trimData(stripSpecialCharacter($val['title1']),70) )
847 $b->appendChild( $allergyName );
849 if($val['title2'] && ($val['title2']=='Mild' ||
$val['title2']=='Moderate' ||
$val['title2']=='Severe')){
850 $allergySeverityTypeID = $doc->createElement( "allergySeverityTypeID" );
851 $allergySeverityTypeID->appendChild(
852 $doc->createTextNode( $val['title2'] )
854 $b->appendChild( $allergySeverityTypeID );
856 if($val['comments']){
857 $allergyComment = $doc->createElement( "allergyComment" );
858 $allergyComment->appendChild(
859 $doc->createTextNode( trimData(stripSpecialCharacter($val['comments']),200) )
861 $b->appendChild( $allergyComment );
863 $r->appendChild( $b );
864 $allergyId[]=$row['id'];
869 function PatientFreeformHealthplans($doc,$r,$pid)
871 $res=sqlStatement("SELECT `name`,`type` FROM insurance_companies AS ic, insurance_data AS id
872 WHERE ic.id=id.provider AND id.pid=?",array($pid));
873 while($row=sqlFetchArray($res))
875 $b = $doc->createElement( "PatientFreeformHealthplans" );
876 $allergyName = $doc->createElement( "healthplanName" );
877 $allergyName->appendChild(
878 $doc->createTextNode( stripSpecialCharacter(trimData($row['name'],35)) )
880 $b->appendChild( $allergyName );
881 $r->appendChild( $b );
885 function PrescriptionRenewalResponse($doc,$r,$pid)
887 $b = $doc->createElement( "PrescriptionRenewalResponse" );
888 $renewalRequestIdentifier = $doc->createElement( "renewalRequestIdentifier" );
889 $renewalRequestIdentifier->appendChild(
890 $doc->createTextNode( 'cbf51649-ce3c-44b8-8f91-6fda121a353d' )
892 $b->appendChild( $renewalRequestIdentifier );
893 $responseCode = $doc->createElement( "responseCode" );
894 $responseCode->appendChild(
895 $doc->createTextNode( 'Undetermined' )
897 $b->appendChild( $responseCode );
898 $r->appendChild( $b );
901 function checkError($xml)
903 $ch = curl_init($xml);
905 $data = array('RxInput' => $xml);
907 curl_setopt($ch, CURLOPT_URL
, getErxPath());
908 curl_setopt($ch, CURLOPT_POST
, 1);
909 curl_setopt($ch, CURLOPT_POSTFIELDS
, "RxInput=".$xml);
910 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER
, 0);
911 curl_setopt($ch, CURLOPT_FOLLOWLOCATION
, 1);
912 curl_setopt($ch, CURLOPT_COOKIESESSION
, TRUE);
913 //curl_setopt($ch, CURLOPT_HEADER, 0);
914 curl_setopt($ch, CURLOPT_COOKIEFILE
, "cookiefile");
915 curl_setopt($ch, CURLOPT_COOKIEJAR
, "cookiefile");
916 curl_setopt($ch, CURLOPT_COOKIE
, session_name() . '=' . session_id());
917 curl_setopt($ch, CURLOPT_USERAGENT
,"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
918 curl_setopt($ch, CURLOPT_RETURNTRANSFER
, true);
920 $result=curl_exec($ch) or die( curl_error($ch)) ;
921 preg_match('/<textarea.*>(.*)Original XML:/is',$result,$error_message);
922 if(strpos($result,'RxEntry.aspx')){
924 erx_error_log($result);
926 $arr=split('Error',$error_message[1]);
927 //echo "Te: ".count($arr);
931 echo nl2br($error_message[1]);
935 for($i=1;$i<count($arr);$i++
)
937 echo $arr[$i]."<br><br>";
941 if(strpos($result,'RxEntry.aspx'))
947 function erx_error_log($message)
949 $date = date("Y-m-d");
950 if(!is_dir($GLOBALS['OE_SITE_DIR'].'/documents/erx_error'))
951 mkdir($GLOBALS['OE_SITE_DIR'].'/documents/erx_error',0777,true);
952 $filename = $GLOBALS['OE_SITE_DIR']."/documents/erx_error/erx_error"."-".$date.".log";
953 $f=fopen($filename,'a');
954 fwrite($f,date("Y-m-d H:i:s")." ==========> ".$message."\r\n");
958 function stripStrings($str,$pattern)
961 foreach($pattern as $key=>$value){
962 $result = preg_replace("/$key/",$value,$result);