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 federal_ein FROM facility WHERE primary_business_entity='1'");
206 if(!$erxSiteID['federal_ein'])
207 {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
);die;}
208 $userRole=sqlQuery("SELECT * FROM users AS u LEFT JOIN facility AS f ON f.id=u.facility_id WHERE u.username=?",array($_SESSION['authUser']));
209 $b = $doc->createElement( "Account" );
210 $b->setAttribute('ID','1');
211 $userRole['name']=stripSpecialCharacterFacility($userRole['name']);
212 $userRole['name']=trimData($userRole['name'],35);
213 $msg = validation(xl('Account Name'),$userRole['name'],$msg);
214 $accountName = $doc->createElement( "accountName" );
215 $accountName->appendChild(
216 $doc->createTextNode( $userRole['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 $userRole['street']=stripSpecialCharacterFacility($userRole['street']);
226 $userRole['street']=trimData($userRole['street'],35);
227 $AccountAddress = $doc->createElement( "AccountAddress" );
228 $msg = validation(xl('Facility Street'),$userRole['street'],$msg);
229 $address1 = $doc->createElement( "address1" );
230 $address1->appendChild(
231 $doc->createTextNode( $userRole['street'] )
233 $AccountAddress->appendChild( $address1 );
234 $msg = validation(xl('Facility City'),$userRole['city'],$msg);
235 $city = $doc->createElement( "city" );
237 $doc->createTextNode( $userRole['city'] )
239 $AccountAddress->appendChild( $city );
240 $msg = validation(xl('Facility State'),$userRole['state'],$msg);
241 $state = $doc->createElement( "state" );
243 $doc->createTextNode( $userRole['state'] )
245 $AccountAddress->appendChild( $state );
246 $msg = validation(xl('Facility Zip'),$userRole['postal_code'],$msg);
247 $zip = $doc->createElement( "zip" );
249 $doc->createTextNode( $userRole['postal_code'] )
251 $AccountAddress->appendChild( $zip );
252 $msg = validation(xl('Facility Country code'),$userRole['country_code'],$msg);
253 $county_code = substr($userRole['country_code'],0,2);
254 $country = $doc->createElement( "country" );
255 $country->appendChild(
256 $doc->createTextNode( $county_code )
258 $AccountAddress->appendChild( $country );
259 $b->appendChild( $AccountAddress );
260 $msg = validation(xl('Facility Phone'),$userRole['phone'],$msg);
261 $accountPrimaryPhoneNumber = $doc->createElement( "accountPrimaryPhoneNumber" );
262 $userRole['phone'] = stripPhoneSlashes($userRole['phone']);
263 $accountPrimaryPhoneNumber->appendChild(
264 $doc->createTextNode( $userRole['phone'] )
266 $b->appendChild( $accountPrimaryPhoneNumber );
267 $msg = validation(xl('Facility Fax'),$userRole['fax'],$msg);
268 $accountPrimaryFaxNumber = $doc->createElement( "accountPrimaryFaxNumber" );
269 $userRole['fax'] = stripPhoneSlashes($userRole['fax']);
270 $accountPrimaryFaxNumber->appendChild(
271 $doc->createTextNode( $userRole['fax'] )
273 $b->appendChild( $accountPrimaryFaxNumber );
274 $r->appendChild( $b );
277 function location($doc,$r)
280 $userRole=sqlQuery("SELECT * FROM users AS u LEFT JOIN facility AS f ON f.id=u.facility_id WHERE u.username=?",array($_SESSION['authUser']));
281 $b = $doc->createElement( "Location" );
282 $b->setAttribute('ID',$userRole['id']);
283 $userRole['name']=stripSpecialCharacterFacility($userRole['name']);
284 $userRole['name']=trimData($userRole['name'],35);
285 $locationName = $doc->createElement( 'locationName' );
286 $locationName->appendChild(
287 $doc->createTextNode( $userRole['name'] )
289 $b->appendChild($locationName);
290 $userRole['street']=stripSpecialCharacterFacility($userRole['street']);
291 $userRole['street']=trimData($userRole['street'],35);
292 $LocationAddress = $doc->createElement( 'LocationAddress' );
293 if($userRole['street']){
294 $address1 = $doc->createElement( 'address1' );
295 $address1->appendChild(
296 $doc->createTextNode( $userRole['street'] )
298 $LocationAddress->appendChild($address1);
300 if($userRole['city']){
301 $city = $doc->createElement( 'city' );
303 $doc->createTextNode( $userRole['city'] )
305 $LocationAddress->appendChild( $city );
307 if($userRole['state']){
308 $state = $doc->createElement( 'state' );
310 $doc->createTextNode( $userRole['state'] )
312 $LocationAddress->appendChild($state);
314 if($userRole['postal_code']){
315 $zip = $doc->createElement( 'zip' );
317 $doc->createTextNode( $userRole['postal_code'] )
319 $LocationAddress->appendChild($zip);
321 if($userRole['country_code']){
322 $county_code = substr($userRole['country_code'],0,2);
323 $country = $doc->createElement( 'country' );
324 $country->appendChild(
325 $doc->createTextNode( $county_code )
327 $LocationAddress->appendChild($country);
329 $b->appendChild($LocationAddress);
330 if($userRole['phone']){
331 $userRole['phone'] = stripPhoneSlashes($userRole['phone']);
332 $primaryPhoneNumber = $doc->createElement( 'primaryPhoneNumber' );
333 $primaryPhoneNumber->appendChild(
334 $doc->createTextNode( $userRole['phone'] )
336 $b->appendChild($primaryPhoneNumber);
338 if($userRole['fax']){
339 $userRole['fax'] = stripPhoneSlashes($userRole['fax']);
340 $primaryFaxNumber = $doc->createElement( 'primaryFaxNumber' );
341 $primaryFaxNumber->appendChild(
342 $doc->createTextNode( $userRole['fax'] )
344 $b->appendChild($primaryFaxNumber);
346 $pharmacyContactNumber = $doc->createElement( 'pharmacyContactNumber' );
347 $pharmacyContactNumber->appendChild(
348 $doc->createTextNode( $userRole['phone'] )
350 $b->appendChild($pharmacyContactNumber);
351 $r->appendChild( $b );
354 function LicensedPrescriber($doc,$r)
357 $user_details = sqlQuery("SELECT * FROM users WHERE id = ?",array($_SESSION['authUserID']));
358 $b = $doc->createElement( "LicensedPrescriber" );
359 $b->setAttribute('ID',$user_details['npi']);
360 $LicensedPrescriberName = $doc->createElement( "LicensedPrescriberName" );
361 $user_details['lname']=stripSpecialCharacter($user_details['lname']);
362 $msg = validation(xl('LicensedPrescriber Last name'),$user_details['lname'],$msg);
363 $last = $doc->createElement( "last" );
365 $doc->createTextNode( $user_details['lname'] )
367 $LicensedPrescriberName->appendChild( $last );
368 $user_details['fname']=stripSpecialCharacter($user_details['fname']);
369 $msg = validation(xl('User First name'),$user_details['fname'],$msg);
370 $first = $doc->createElement( "first" );
372 $doc->createTextNode( $user_details['fname'] )
374 $LicensedPrescriberName->appendChild( $first );
375 $user_details['mname']=stripSpecialCharacter($user_details['mname']);
376 $middle = $doc->createElement( "middle" );
377 $middle->appendChild(
378 $doc->createTextNode( $user_details['mname'] )
380 $LicensedPrescriberName->appendChild( $middle );
381 $b->appendChild( $LicensedPrescriberName );
382 $msg = validation(xl('DEA'),$user_details['federaldrugid'],$msg);
383 $dea = $doc->createElement( "dea" );
385 $doc->createTextNode( $user_details['federaldrugid'] )
387 $b->appendChild( $dea );
388 if($user_details['upin']){
389 $upin = $doc->createElement( "upin" );
391 $doc->createTextNode( $user_details['upin'] )
393 $b->appendChild( $upin );
395 $licenseNumber = $doc->createElement( "licenseNumber" );
396 $licenseNumber->appendChild(
397 $doc->createTextNode( $user_details['state_license_number'] )
399 $b->appendChild( $licenseNumber );
400 $msg = validation(xl('LicensedPrescriber NPI'),$user_details['npi'],$msg);
401 $npi = $doc->createElement( "npi" );
403 $doc->createTextNode( $user_details['npi'] )
405 $b->appendChild( $npi );
406 $r->appendChild( $b );
409 function Staff($doc,$r)
412 $user_details = sqlQuery("SELECT * FROM users WHERE id = ?",array($_SESSION['authUserID']));
413 $b = $doc->createElement( "Staff" );
414 $b->setAttribute('ID',$user_details['username']);
415 $StaffName = $doc->createElement( "StaffName" );
416 $user_details['lname']=stripSpecialCharacter($user_details['lname']);
417 $last = $doc->createElement( "last" );
419 $doc->createTextNode( $user_details['lname'] )
421 $StaffName->appendChild( $last );
422 $user_details['fname']=stripSpecialCharacter($user_details['fname']);
423 $first = $doc->createElement( "first" );
425 $doc->createTextNode( $user_details['fname'] )
427 $StaffName->appendChild( $first );
428 $user_details['mname']=stripSpecialCharacter($user_details['mname']);
429 $middle = $doc->createElement( "middle" );
430 $middle->appendChild(
431 $doc->createTextNode( $user_details['mname'] )
433 $StaffName->appendChild( $middle );
434 $b->appendChild( $StaffName );
435 $license = $doc->createElement( "license" );
436 $license->appendChild(
437 $doc->createTextNode( $user_details['license'] )
439 $b->appendChild( $license );
440 $r->appendChild( $b );
443 function SupervisingDoctor($doc,$r)
446 $user_details = sqlQuery("SELECT * FROM users WHERE id = ?",array($_SESSION['authUserID']));
447 $b = $doc->createElement( "SupervisingDoctor" );
448 $b->setAttribute('ID',$user_details['npi']);
449 $LicensedPrescriberName = $doc->createElement( "LicensedPrescriberName" );
450 $user_details['lname']=stripSpecialCharacter($user_details['lname']);
451 $msg = validation(xl('Supervising Doctor Last name'),$user_details['lname'],$msg);
452 $last = $doc->createElement( "last" );
454 $doc->createTextNode( $user_details['lname'] )
456 $LicensedPrescriberName->appendChild( $last );
457 $user_details['fname']=stripSpecialCharacter($user_details['fname']);
458 $msg = validation(xl('Supervising Doctor First name'),$user_details['fname'],$msg);
459 $first = $doc->createElement( "first" );
461 $doc->createTextNode( $user_details['fname'] )
463 $LicensedPrescriberName->appendChild( $first );
464 $user_details['mname']=stripSpecialCharacter($user_details['mname']);
465 $middle = $doc->createElement( "middle" );
466 $middle->appendChild(
467 $doc->createTextNode( $user_details['mname'] )
469 $LicensedPrescriberName->appendChild( $middle );
470 $b->appendChild( $LicensedPrescriberName );
471 $msg = validation(xl('Supervising Doctor DEA'),$user_details['federaldrugid'],$msg);
472 $dea = $doc->createElement( "dea" );
474 $doc->createTextNode( $user_details['federaldrugid'] )
476 $b->appendChild( $dea );
477 if($user_details['upin']){
478 $upin = $doc->createElement( "upin" );
480 $doc->createTextNode( $user_details['upin'] )
482 $b->appendChild( $upin );
484 $licenseNumber = $doc->createElement( "licenseNumber" );
485 $licenseNumber->appendChild(
486 $doc->createTextNode( $user_details['state_license_number'] )
488 $b->appendChild( $licenseNumber );
489 $msg = validation(xl('Supervising Doctor NPI'),$user_details['npi'],$msg);
490 $npi = $doc->createElement( "npi" );
492 $doc->createTextNode( $user_details['npi'] )
494 $b->appendChild( $npi );
495 $r->appendChild( $b );
498 function MidlevelPrescriber($doc,$r)
501 $user_details = sqlQuery("SELECT * FROM users WHERE id = ?",array($_SESSION['authUserID']));
502 $b = $doc->createElement( "MidlevelPrescriber" );
503 $b->setAttribute('ID',$user_details['npi']);
504 $LicensedPrescriberName = $doc->createElement( "LicensedPrescriberName" );
505 $user_details['lname']=stripSpecialCharacter($user_details['lname']);
506 $msg = validation(xl('Midlevel Prescriber Last name'),$user_details['lname'],$msg);
507 $last = $doc->createElement( "last" );
509 $doc->createTextNode( $user_details['lname'] )
511 $LicensedPrescriberName->appendChild( $last );
512 $user_details['fname']=stripSpecialCharacter($user_details['fname']);
513 $msg = validation(xl('Midlevel Prescriber First name'),$user_details['fname'],$msg);
514 $first = $doc->createElement( "first" );
516 $doc->createTextNode( $user_details['fname'] )
518 $LicensedPrescriberName->appendChild( $first );
519 $user_details['mname']=stripSpecialCharacter($user_details['mname']);
520 $middle = $doc->createElement( "middle" );
521 $middle->appendChild(
522 $doc->createTextNode( $user_details['mname'] )
524 $LicensedPrescriberName->appendChild( $middle );
525 if($user_details['title']){
526 $msg = validation(xl('Midlevel Prescriber Prefix'),$user_details['title'],$msg);
527 $prefix = $doc->createElement( "prefix" );
528 $prefix->appendChild(
529 $doc->createTextNode( $user_details['title'] )
531 $LicensedPrescriberName->appendChild( $prefix );
533 $b->appendChild( $LicensedPrescriberName );
534 $msg = validation(xl('Midlevel Prescriber DEA'),$user_details['federaldrugid'],$msg);
535 $dea = $doc->createElement( "dea" );
537 $doc->createTextNode( $user_details['federaldrugid'] )
539 $b->appendChild( $dea );
540 if($user_details['upin']){
541 $upin = $doc->createElement( "upin" );
543 $doc->createTextNode( $user_details['upin'] )
545 $b->appendChild( $upin );
547 $licenseNumber = $doc->createElement( "licenseNumber" );
548 $licenseNumber->appendChild(
549 $doc->createTextNode( $user_details['state_license_number'] )
551 $b->appendChild( $licenseNumber );
552 $r->appendChild( $b );
555 function Patient($doc,$r,$pid)
557 global $msg,$warning_msg,$dem_check;
558 $patient_data=sqlQuery("select *, DATE_FORMAT(DOB,'%Y%m%d') AS date_of_birth from patient_data where pid=?",array($pid));
559 $b = $doc->createElement( "Patient" );
560 $b->setAttribute('ID',$patient_data['pid']);
561 $PatientName = $doc->createElement( "PatientName" );
562 $patient_data['lname']=stripSpecialCharacter($patient_data['lname']);
563 $patient_data['lname']=trimData($patient_data['lname'],35);
564 //$msg = validation(xl('Patient Last name'),$patient_data['lname'],$msg);
565 if($patient_data['lname']=='')
566 $dem_check.=htmlspecialchars( xl("Patient Last name is missing"), ENT_NOQUOTES
)."<br>";
567 $last = $doc->createElement( "last" );
569 $doc->createTextNode( $patient_data['lname'] )
571 $PatientName->appendChild( $last );
572 $patient_data['fname']=stripSpecialCharacter($patient_data['fname']);
573 $patient_data['fname']=trimData($patient_data['fname'],35);
574 //$msg = validation(xl('Patient First name'),$patient_data['fname'],$msg);
575 if($patient_data['fname']=='')
576 $dem_check.=htmlspecialchars( xl("Patient First name is missing"), ENT_NOQUOTES
)."<br>";
577 $first = $doc->createElement( "first" );
579 $doc->createTextNode( $patient_data['fname'] )
581 $PatientName->appendChild( $first );
582 $patient_data['mname']=stripSpecialCharacter($patient_data['mname']);
583 $patient_data['mname']=trimData($patient_data['mname'],35);
584 $middle = $doc->createElement( "middle" );
585 $middle->appendChild(
586 $doc->createTextNode( $patient_data['mname'] )
588 $PatientName->appendChild( $middle );
589 $b->appendChild( $PatientName );
590 $PatientAddress = $doc->createElement( "PatientAddress" );
591 $patient_data['street']=stripSpecialCharacter($patient_data['street']);
592 $patient_data['street']=trimData($patient_data['street'],35);
593 $msg = validation(xl('Patient Address'),$patient_data['street'],$msg);
594 if(trim($patient_data['street'])=='')
595 $warning_msg .= "<br>".htmlspecialchars( xl("Patient Address is missing"), ENT_NOQUOTES
);
596 $address1 = $doc->createElement( "address1" );
597 $address1->appendChild(
598 $doc->createTextNode( $patient_data['street'] )
600 $PatientAddress->appendChild( $address1 );
601 //$msg = validation(xl('Patient City'),$patient_data['city'],$msg);
602 if($patient_data['city']=='')
603 $dem_check.=htmlspecialchars( xl("Patient City is missing"), ENT_NOQUOTES
)."<br>";
604 $city = $doc->createElement( "city" );
606 $doc->createTextNode( $patient_data['city'] )
608 $PatientAddress->appendChild( $city );
609 if($patient_data['state']){
610 $state = $doc->createElement( "state" );
612 $doc->createTextNode( $patient_data['state'] )
614 $PatientAddress->appendChild( $state );
616 if($patient_data['postal_code']){
617 $zip = $doc->createElement( "zip" );
619 $doc->createTextNode( $patient_data['postal_code'] )
621 $PatientAddress->appendChild( $zip );
623 //$msg = validation(xl('Patient Country'),$patient_data['country_code'],$msg);
624 if(trim($patient_data['country_code'])=='' && $GLOBALS['erx_default_patient_country']=='')
625 $dem_check.=htmlspecialchars( xl("Patient Country is missing. Also you have not set default Patient Country in Global Settings"), ENT_NOQUOTES
)."<br>";
626 elseif(trim($patient_data['country_code'])=='')
627 $patient_data['country_code'] = $GLOBALS['erx_default_patient_country'];
628 $county_code = substr($patient_data['country_code'],0,2);
629 $country = $doc->createElement( "country" );
630 $country->appendChild(
631 $doc->createTextNode( $county_code )
633 $PatientAddress->appendChild( $country );
634 $b->appendChild( $PatientAddress );
635 $PatientContact = $doc->createElement( "PatientContact" );
636 $patient_data['phone_home']=stripPhoneSlashes($patient_data['phone_home']);
637 if($patient_data['phone_home']){
638 $homeTelephone = $doc->createElement( "homeTelephone" );
639 $homeTelephone->appendChild(
640 $doc->createTextNode( $patient_data['phone_home'] )
642 $PatientContact->appendChild( $homeTelephone );
644 $b->appendChild( $PatientContact );
645 $PatientCharacteristics = $doc->createElement( "PatientCharacteristics" );
646 if(trim($patient_data['date_of_birth'])=='' ||
$patient_data['date_of_birth']=='00000000')
647 $warning_msg .= "<br>".htmlspecialchars( xl("Patient Date Of Birth is missing"), ENT_NOQUOTES
);
648 if($patient_data['date_of_birth'] && $patient_data['date_of_birth']!='00000000'){
649 $dob = $doc->createElement( "dob" );
651 $doc->createTextNode( $patient_data['date_of_birth'] )
653 $PatientCharacteristics->appendChild( $dob );
655 if(trim($patient_data['sex'])=='')
656 $warning_msg .= "<br>".htmlspecialchars( xl("Patient Gender is missing"), ENT_NOQUOTES
);
657 if($patient_data['sex']){
658 $gender_val=substr($patient_data['sex'],0,1);
659 $gender = $doc->createElement( "gender" );
660 $gender->appendChild(
661 $doc->createTextNode( $gender_val )
663 $PatientCharacteristics->appendChild( $gender );
665 $b->appendChild( $PatientCharacteristics );
666 PatientFreeformHealthplans($doc,$b,$pid);
667 $allergyId=PatientFreeformAllergy($doc,$b,$pid);
668 $r->appendChild( $b );
672 function OutsidePrescription($doc,$r,$pid,$prescid)
677 $prec=sqlQuery("SELECT p.note,p.dosage,p.substitute,p.per_refill,p.form,p.route,p.interval,p.drug,l1.title AS title1,l2.title AS title2,l3.title AS title3,p.id AS prescid,
678 DATE_FORMAT(date_added,'%Y%m%d') AS date_added,CONCAT(fname,' ',mname,' ',lname) AS docname,p.quantity
679 FROM prescriptions AS p
680 LEFT JOIN users AS u ON p.provider_id=u.id
681 LEFT JOIN list_options AS l1 ON l1.list_id='drug_form' AND l1.option_id=p.form
682 LEFT JOIN list_options AS l2 ON l2.list_id='drug_route' AND l2.option_id=p.route
683 LEFT JOIN list_options AS l3 ON l3.list_id='drug_interval' AND l3.option_id=p.interval
684 WHERE p.drug<>'' and p.id=?",array($prescid));
685 $b = $doc->createElement( "OutsidePrescription" );
686 $externalId = $doc->createElement( "externalId" );
687 $externalId->appendChild(
688 $doc->createTextNode( $prec['prescid'] )
690 $b->appendChild( $externalId );
691 $date = $doc->createElement( "date" );
693 $doc->createTextNode( $prec['date_added'] )
695 $b->appendChild( $date );
696 $doctorName = $doc->createElement( "doctorName" );
697 $doctorName->appendChild(
698 $doc->createTextNode( $prec['docname'] )
700 $b->appendChild( $doctorName );
701 $s=stripSpecialCharacter($prec['drug']);
702 $sig = $doc->createElement( "drug" );
704 $doc->createTextNode( trimData($s,80) )
706 $b->appendChild( $sig );
707 $x=stringToNumeric($prec['quantity']);
708 $dispenseNumber = $doc->createElement( "dispenseNumber" );
709 $dispenseNumber->appendChild(
710 $doc->createTextNode( $x[0] )
712 $b->appendChild( $dispenseNumber );
713 $s=trimData($x[1]." Take ".$prec['dosage']." In ".$prec['title1']." ".$prec['title2']." ".$prec['title3'],140);
714 $s=stripSpecialCharacter($s);
715 $sig = $doc->createElement( "sig" );
717 $doc->createTextNode( $s )
719 $b->appendChild( $sig );
720 $refillCount = $doc->createElement( "refillCount" );
721 $x=stringToNumeric($prec['per_refill']);
722 $refillCount->appendChild(
723 $doc->createTextNode( $x[0])
725 $b->appendChild( $refillCount );
726 $prescriptionType = $doc->createElement( "prescriptionType" );
727 $prescriptionType->appendChild(
728 $doc->createTextNode( 'reconcile' )
730 $b->appendChild( $prescriptionType );
731 $r->appendChild( $b );
735 function PatientMedication($doc,$r,$pid,$med_limit)
739 if($GLOBALS['erx_upload_active']==1)
740 $active = " and (enddate is null or enddate = '' or enddate = '0000-00-00' )";
741 $res_med=sqlStatement("select * from lists where type='medication' and pid=? and title<>''
742 and erx_uploaded='0' $active order by enddate limit 0,$med_limit",array($pid));
743 $uploaded_med_arr="";
744 while($row_med=sqlFetchArray($res_med))
746 $uploaded_med_arr[]=$row_med['id'];
747 $b = $doc->createElement( "OutsidePrescription" );
748 $externalId = $doc->createElement( "externalId" );
749 $externalId->appendChild(
750 $doc->createTextNode( $row_med['id'] )
752 $b->appendChild( $externalId );
753 $date = $doc->createElement( "date" );
755 $doc->createTextNode( $row_med['begdate'] )
757 $b->appendChild( $date );
758 $doctorName = $doc->createElement( "doctorName" );
759 $doctorName->appendChild(
760 $doc->createTextNode( "" )
762 $b->appendChild( $doctorName );
763 $row_med['title'] = stripSpecialCharacter($row_med['title']);
764 $sig = $doc->createElement( "drug" );
766 $doc->createTextNode( trimData($row_med['title'],80) )
768 $b->appendChild( $sig );
769 $dispenseNumber = $doc->createElement( "dispenseNumber" );
770 $dispenseNumber->appendChild(
771 $doc->createTextNode( $prec['quantity'] )
773 $b->appendChild( $dispenseNumber );
774 $sig = $doc->createElement( "sig" );
776 $doc->createTextNode( "" )
778 $b->appendChild( $sig );
779 $refillCount = $doc->createElement( "refillCount" );
780 $refillCount->appendChild(
781 $doc->createTextNode( "" )
783 $b->appendChild( $refillCount );
784 $prescriptionType = $doc->createElement( "prescriptionType" );
785 $prescriptionType->appendChild(
786 $doc->createTextNode( 'reconcile' )
788 $b->appendChild( $prescriptionType );
789 $r->appendChild( $b );
792 return $uploaded_med_arr;
795 function PatientFreeformAllergy($doc,$r,$pid)
797 $res=sqlStatement("SELECT id,l.title as title1,lo.title as title2,comments FROM lists AS l
798 LEFT JOIN list_options AS lo ON l.outcome=lo.option_id AND lo.list_id='outcome'
799 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));
801 while($row=sqlFetchArray($res))
804 $val['id']=$row['id'];
805 $val['title1']=$row['title1'];
806 $val['title2']=$row['title2'];
807 $val['comments']=$row['comments'];
808 $b = $doc->createElement( "PatientFreeformAllergy" );
809 $b->setAttribute('ID',$val['id']);
811 $allergyName = $doc->createElement( "allergyName" );
812 $allergyName->appendChild(
813 $doc->createTextNode( trimData(stripSpecialCharacter($val['title1']),70) )
815 $b->appendChild( $allergyName );
817 if($val['title2'] && ($val['title2']=='Mild' ||
$val['title2']=='Moderate' ||
$val['title2']=='Severe')){
818 $allergySeverityTypeID = $doc->createElement( "allergySeverityTypeID" );
819 $allergySeverityTypeID->appendChild(
820 $doc->createTextNode( $val['title2'] )
822 $b->appendChild( $allergySeverityTypeID );
824 if($val['comments']){
825 $allergyComment = $doc->createElement( "allergyComment" );
826 $allergyComment->appendChild(
827 $doc->createTextNode( trimData(stripSpecialCharacter($val['comments']),200) )
829 $b->appendChild( $allergyComment );
831 $r->appendChild( $b );
832 $allergyId[]=$row['id'];
837 function PatientFreeformHealthplans($doc,$r,$pid)
839 $res=sqlStatement("SELECT `name`,`type` FROM insurance_companies AS ic, insurance_data AS id
840 WHERE ic.id=id.provider AND id.pid=?",array($pid));
841 while($row=sqlFetchArray($res))
843 $b = $doc->createElement( "PatientFreeformHealthplans" );
844 $allergyName = $doc->createElement( "healthplanName" );
845 $allergyName->appendChild(
846 $doc->createTextNode( stripSpecialCharacter(trimData($row['name'],35)) )
848 $b->appendChild( $allergyName );
849 $r->appendChild( $b );
853 function PrescriptionRenewalResponse($doc,$r,$pid)
855 $b = $doc->createElement( "PrescriptionRenewalResponse" );
856 $renewalRequestIdentifier = $doc->createElement( "renewalRequestIdentifier" );
857 $renewalRequestIdentifier->appendChild(
858 $doc->createTextNode( 'cbf51649-ce3c-44b8-8f91-6fda121a353d' )
860 $b->appendChild( $renewalRequestIdentifier );
861 $responseCode = $doc->createElement( "responseCode" );
862 $responseCode->appendChild(
863 $doc->createTextNode( 'Undetermined' )
865 $b->appendChild( $responseCode );
866 $r->appendChild( $b );
869 function checkError($xml)
871 $ch = curl_init($xml);
873 $data = array('RxInput' => $xml);
875 curl_setopt($ch, CURLOPT_URL
, getErxPath());
876 curl_setopt($ch, CURLOPT_POST
, 1);
877 curl_setopt($ch, CURLOPT_POSTFIELDS
, "RxInput=".$xml);
878 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER
, 0);
879 curl_setopt($ch, CURLOPT_FOLLOWLOCATION
, 1);
880 curl_setopt($ch, CURLOPT_COOKIESESSION
, TRUE);
881 //curl_setopt($ch, CURLOPT_HEADER, 0);
882 curl_setopt($ch, CURLOPT_COOKIEFILE
, "cookiefile");
883 curl_setopt($ch, CURLOPT_COOKIEJAR
, "cookiefile");
884 curl_setopt($ch, CURLOPT_COOKIE
, session_name() . '=' . session_id());
885 curl_setopt($ch, CURLOPT_USERAGENT
,"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
886 curl_setopt($ch, CURLOPT_RETURNTRANSFER
, true);
888 $result=curl_exec($ch) or die( curl_error($ch)) ;
889 preg_match('/<textarea.*>(.*)Original XML:/is',$result,$error_message);
890 if(strpos($result,'RxEntry.aspx')){
892 erx_error_log($result);
894 $arr=split('Error',$error_message[1]);
895 //echo "Te: ".count($arr);
899 echo nl2br($error_message[1]);
903 for($i=1;$i<count($arr);$i++
)
905 echo $arr[$i]."<br><br>";
909 if(strpos($result,'RxEntry.aspx'))
915 function erx_error_log($message)
917 $date = date("Y-m-d");
918 if(!is_dir($GLOBALS['OE_SITE_DIR'].'/documents/erx_error'))
919 mkdir($GLOBALS['OE_SITE_DIR'].'/documents/erx_error',0777,true);
920 $filename = $GLOBALS['OE_SITE_DIR']."/documents/erx_error/erx_error"."-".$date.".log";
921 $f=fopen($filename,'a');
922 fwrite($f,date("Y-m-d H:i:s")." ==========> ".$message."\r\n");
926 function stripStrings($str,$pattern)
929 foreach($pattern as $key=>$value){
930 $result = preg_replace("/$key/",$value,$result);