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'\-\s.,]/","",$str);
74 function stripSpecialCharacter($str)
76 $str=preg_replace("/[^a-zA-Z'\s]/","",$str);
80 function stripPhoneSlashes($str)
82 $str=preg_replace('/-/','',$str);
86 function trimData($str,$length)
88 $str=substr($str,0,($length-1));
92 function credentials($doc,$r)
95 $cred=getErxCredentials();
96 $msg = validation(xl('Partner Name'),$cred['0'],$msg);
97 $b = $doc->createElement( "Credentials" );
98 $partnerName = $doc->createElement( "partnerName" );
99 $partnerName->appendChild(
100 $doc->createTextNode( $cred['0'] )
102 $b->appendChild( $partnerName );
103 $msg = validation(xl('ERX Name'),$cred['1'],$msg);
104 $name = $doc->createElement( "name" );
106 $doc->createTextNode( $cred['1'] )
108 $b->appendChild( $name );
109 $msg = validation(xl('ERX Password'),$cred['2'],$msg);
110 $password = $doc->createElement( "password" );
111 $password->appendChild(
112 $doc->createTextNode( $cred['2'] )
114 $b->appendChild( $password );
115 $productName = $doc->createElement( "productName" );
116 $productName->appendChild(
117 $doc->createTextNode( 'SuperDuperSoftware' )
119 $b->appendChild( $productName );
120 $productVersion = $doc->createElement( "productVersion" );
121 $productVersion->appendChild(
122 $doc->createTextNode( 'SuperDuperSoftware' )
124 $b->appendChild( $productVersion );
125 $r->appendChild( $b );
128 function user_role($doc,$r)
131 $userRole=sqlQuery("select * from users where username=?",array($_SESSION['authUser']));
132 if(!$userRole['newcrop_user_role'])
133 {echo xl('Unauthorized access to ePrescription');die;}
134 $userRole['newcrop_user_role'] = preg_replace('/erx/','',$userRole['newcrop_user_role']);
135 if($userRole['newcrop_user_role'] == 'doctor')
136 $userRole['eRxUser'] = 'LicensedPrescriber';
137 elseif($userRole['newcrop_user_role'] == 'admin' ||
$userRole['newcrop_user_role'] == 'manager' ||
$userRole['newcrop_user_role'] == 'nurse')
138 $userRole['eRxUser'] = 'Staff';
139 elseif($userRole['newcrop_user_role'] == 'midlevelPrescriber')
140 $userRole['eRxUser'] = 'MidlevelPrescriber';
141 elseif($userRole['newcrop_user_role'] == 'supervisingDoctor')
142 $userRole['eRxUser'] = 'SupervisingDoctor';
143 $msg = validation(xl('ERX User'),$userRole['eRxUser'],$msg);
144 $b = $doc->createElement( "UserRole" );
145 $user = $doc->createElement( "user" );
147 $doc->createTextNode( $userRole['eRxUser'] )
149 $b->appendChild( $user );
150 $msg = validation(xl('ERX Role'),$userRole['newcrop_user_role'],$msg);
151 $role = $doc->createElement( "role" );
153 $doc->createTextNode( $userRole['newcrop_user_role'] )
155 $b->appendChild( $role );
156 $r->appendChild( $b );
159 function destination($doc,$r,$page='',$pid)
162 $userRole=sqlQuery("select * from users where username=?",array($_SESSION['authUser']));
163 $userRole['newcrop_user_role'] = preg_replace('/erx/','',$userRole['newcrop_user_role']);
167 if($userRole['newcrop_user_role']=='admin')
169 elseif($userRole['newcrop_user_role']=='manager')
172 $b = $doc->createElement( "Destination" );
173 $requestedPage = $doc->createElement( "requestedPage" );
174 $requestedPage->appendChild(
175 $doc->createTextNode( $page )
177 $b->appendChild( $requestedPage );
178 $r->appendChild( $b );
181 function account($doc,$r)
184 $erxSiteID=sqlQuery("SELECT federal_ein FROM facility WHERE primary_business_entity='1'");
185 if(!$erxSiteID['federal_ein'])
186 {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;}
187 $userRole=sqlQuery("SELECT * FROM users AS u LEFT JOIN facility AS f ON f.id=u.facility_id WHERE u.username=?",array($_SESSION['authUser']));
188 $b = $doc->createElement( "Account" );
189 $b->setAttribute('ID','1');
190 $userRole['name']=stripSpecialCharacterFacility($userRole['name']);
191 $userRole['name']=trimData($userRole['name'],35);
192 $msg = validation(xl('Account Name'),$userRole['name'],$msg);
193 $accountName = $doc->createElement( "accountName" );
194 $accountName->appendChild(
195 $doc->createTextNode( $userRole['name'] )
197 $b->appendChild( $accountName );
198 $msg = validation(xl('Site ID'),$_SESSION['site_id'],$msg);
199 $siteID = $doc->createElement( "siteID" );
200 $siteID->appendChild(
201 $doc->createTextNode( $erxSiteID['federal_ein'] )
203 $b->appendChild( $siteID );
204 $userRole['street']=stripSpecialCharacterFacility($userRole['street']);
205 $userRole['street']=trimData($userRole['street'],35);
206 $AccountAddress = $doc->createElement( "AccountAddress" );
207 $msg = validation(xl('Facility Street'),$userRole['street'],$msg);
208 $address1 = $doc->createElement( "address1" );
209 $address1->appendChild(
210 $doc->createTextNode( $userRole['street'] )
212 $AccountAddress->appendChild( $address1 );
213 $msg = validation(xl('Facility City'),$userRole['city'],$msg);
214 $city = $doc->createElement( "city" );
216 $doc->createTextNode( $userRole['city'] )
218 $AccountAddress->appendChild( $city );
219 $msg = validation(xl('Facility State'),$userRole['state'],$msg);
220 $state = $doc->createElement( "state" );
222 $doc->createTextNode( $userRole['state'] )
224 $AccountAddress->appendChild( $state );
225 $msg = validation(xl('Facility Zip'),$userRole['postal_code'],$msg);
226 $zip = $doc->createElement( "zip" );
228 $doc->createTextNode( $userRole['postal_code'] )
230 $AccountAddress->appendChild( $zip );
231 $msg = validation(xl('Facility Country code'),$userRole['country_code'],$msg);
232 $county_code = substr($userRole['country_code'],0,2);
233 $country = $doc->createElement( "country" );
234 $country->appendChild(
235 $doc->createTextNode( $county_code )
237 $AccountAddress->appendChild( $country );
238 $b->appendChild( $AccountAddress );
239 $msg = validation(xl('Facility Phone'),$userRole['phone'],$msg);
240 $accountPrimaryPhoneNumber = $doc->createElement( "accountPrimaryPhoneNumber" );
241 $userRole['phone'] = stripPhoneSlashes($userRole['phone']);
242 $accountPrimaryPhoneNumber->appendChild(
243 $doc->createTextNode( $userRole['phone'] )
245 $b->appendChild( $accountPrimaryPhoneNumber );
246 $msg = validation(xl('Facility Fax'),$userRole['fax'],$msg);
247 $accountPrimaryFaxNumber = $doc->createElement( "accountPrimaryFaxNumber" );
248 $userRole['fax'] = stripPhoneSlashes($userRole['fax']);
249 $accountPrimaryFaxNumber->appendChild(
250 $doc->createTextNode( $userRole['fax'] )
252 $b->appendChild( $accountPrimaryFaxNumber );
253 $r->appendChild( $b );
256 function location($doc,$r)
259 $userRole=sqlQuery("SELECT * FROM users AS u LEFT JOIN facility AS f ON f.id=u.facility_id WHERE u.username=?",array($_SESSION['authUser']));
260 $b = $doc->createElement( "Location" );
261 $b->setAttribute('ID',$userRole['id']);
262 $userRole['name']=stripSpecialCharacterFacility($userRole['name']);
263 $userRole['name']=trimData($userRole['name'],35);
264 $locationName = $doc->createElement( 'locationName' );
265 $locationName->appendChild(
266 $doc->createTextNode( $userRole['name'] )
268 $b->appendChild($locationName);
269 $userRole['street']=stripSpecialCharacterFacility($userRole['street']);
270 $userRole['street']=trimData($userRole['street'],35);
271 $LocationAddress = $doc->createElement( 'LocationAddress' );
272 if($userRole['street']){
273 $address1 = $doc->createElement( 'address1' );
274 $address1->appendChild(
275 $doc->createTextNode( $userRole['street'] )
277 $LocationAddress->appendChild($address1);
279 if($userRole['city']){
280 $city = $doc->createElement( 'city' );
282 $doc->createTextNode( $userRole['city'] )
284 $LocationAddress->appendChild( $city );
286 if($userRole['state']){
287 $state = $doc->createElement( 'state' );
289 $doc->createTextNode( $userRole['state'] )
291 $LocationAddress->appendChild($state);
293 if($userRole['postal_code']){
294 $zip = $doc->createElement( 'zip' );
296 $doc->createTextNode( $userRole['postal_code'] )
298 $LocationAddress->appendChild($zip);
300 if($userRole['country_code']){
301 $county_code = substr($userRole['country_code'],0,2);
302 $country = $doc->createElement( 'country' );
303 $country->appendChild(
304 $doc->createTextNode( $county_code )
306 $LocationAddress->appendChild($country);
308 $b->appendChild($LocationAddress);
309 if($userRole['phone']){
310 $userRole['phone'] = stripPhoneSlashes($userRole['phone']);
311 $primaryPhoneNumber = $doc->createElement( 'primaryPhoneNumber' );
312 $primaryPhoneNumber->appendChild(
313 $doc->createTextNode( $userRole['phone'] )
315 $b->appendChild($primaryPhoneNumber);
317 if($userRole['fax']){
318 $userRole['fax'] = stripPhoneSlashes($userRole['fax']);
319 $primaryFaxNumber = $doc->createElement( 'primaryFaxNumber' );
320 $primaryFaxNumber->appendChild(
321 $doc->createTextNode( $userRole['fax'] )
323 $b->appendChild($primaryFaxNumber);
325 $pharmacyContactNumber = $doc->createElement( 'pharmacyContactNumber' );
326 $pharmacyContactNumber->appendChild(
327 $doc->createTextNode( $userRole['phone'] )
329 $b->appendChild($pharmacyContactNumber);
330 $r->appendChild( $b );
333 function LicensedPrescriber($doc,$r)
336 $user_details = sqlQuery("SELECT * FROM users WHERE id = ?",array($_SESSION['authUserID']));
337 $b = $doc->createElement( "LicensedPrescriber" );
338 $b->setAttribute('ID',$user_details['npi']);
339 $LicensedPrescriberName = $doc->createElement( "LicensedPrescriberName" );
340 $user_details['lname']=stripSpecialCharacter($user_details['lname']);
341 $msg = validation(xl('LicensedPrescriber Last name'),$user_details['lname'],$msg);
342 $last = $doc->createElement( "last" );
344 $doc->createTextNode( $user_details['lname'] )
346 $LicensedPrescriberName->appendChild( $last );
347 $user_details['fname']=stripSpecialCharacter($user_details['fname']);
348 $msg = validation(xl('User First name'),$user_details['fname'],$msg);
349 $first = $doc->createElement( "first" );
351 $doc->createTextNode( $user_details['fname'] )
353 $LicensedPrescriberName->appendChild( $first );
354 $user_details['mname']=stripSpecialCharacter($user_details['mname']);
355 $middle = $doc->createElement( "middle" );
356 $middle->appendChild(
357 $doc->createTextNode( $user_details['mname'] )
359 $LicensedPrescriberName->appendChild( $middle );
360 $b->appendChild( $LicensedPrescriberName );
361 $msg = validation(xl('DEA'),$user_details['federaldrugid'],$msg);
362 $dea = $doc->createElement( "dea" );
364 $doc->createTextNode( $user_details['federaldrugid'] )
366 $b->appendChild( $dea );
367 $msg = validation(xl('LicensedPrescriber UPIN'),$user_details['upin'],$msg);
368 $upin = $doc->createElement( "upin" );
370 $doc->createTextNode( $user_details['upin'] )
372 $b->appendChild( $upin );
373 $licenseNumber = $doc->createElement( "licenseNumber" );
374 $licenseNumber->appendChild(
375 $doc->createTextNode( $user_details['state_license_number'] )
377 $b->appendChild( $licenseNumber );
378 $msg = validation(xl('LicensedPrescriber NPI'),$user_details['npi'],$msg);
379 $npi = $doc->createElement( "npi" );
381 $doc->createTextNode( $user_details['npi'] )
383 $b->appendChild( $npi );
384 $r->appendChild( $b );
387 function Staff($doc,$r)
390 $user_details = sqlQuery("SELECT * FROM users WHERE id = ?",array($_SESSION['authUserID']));
391 $b = $doc->createElement( "Staff" );
392 $b->setAttribute('ID',$user_details['username']);
393 $StaffName = $doc->createElement( "StaffName" );
394 $user_details['lname']=stripSpecialCharacter($user_details['lname']);
395 $last = $doc->createElement( "last" );
397 $doc->createTextNode( $user_details['lname'] )
399 $StaffName->appendChild( $last );
400 $user_details['fname']=stripSpecialCharacter($user_details['fname']);
401 $first = $doc->createElement( "first" );
403 $doc->createTextNode( $user_details['fname'] )
405 $StaffName->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 $StaffName->appendChild( $middle );
412 $b->appendChild( $StaffName );
413 $license = $doc->createElement( "license" );
414 $license->appendChild(
415 $doc->createTextNode( $user_details['license'] )
417 $b->appendChild( $license );
418 $r->appendChild( $b );
421 function SupervisingDoctor($doc,$r)
424 $user_details = sqlQuery("SELECT * FROM users WHERE id = ?",array($_SESSION['authUserID']));
425 $b = $doc->createElement( "SupervisingDoctor" );
426 $b->setAttribute('ID',$user_details['npi']);
427 $LicensedPrescriberName = $doc->createElement( "LicensedPrescriberName" );
428 $user_details['lname']=stripSpecialCharacter($user_details['lname']);
429 $msg = validation(xl('Supervising Doctor Last name'),$user_details['lname'],$msg);
430 $last = $doc->createElement( "last" );
432 $doc->createTextNode( $user_details['lname'] )
434 $LicensedPrescriberName->appendChild( $last );
435 $user_details['fname']=stripSpecialCharacter($user_details['fname']);
436 $msg = validation(xl('Supervising Doctor First name'),$user_details['fname'],$msg);
437 $first = $doc->createElement( "first" );
439 $doc->createTextNode( $user_details['fname'] )
441 $LicensedPrescriberName->appendChild( $first );
442 $user_details['mname']=stripSpecialCharacter($user_details['mname']);
443 $middle = $doc->createElement( "middle" );
444 $middle->appendChild(
445 $doc->createTextNode( $user_details['mname'] )
447 $LicensedPrescriberName->appendChild( $middle );
448 $b->appendChild( $LicensedPrescriberName );
449 $msg = validation(xl('Supervising Doctor DEA'),$user_details['federaldrugid'],$msg);
450 $dea = $doc->createElement( "dea" );
452 $doc->createTextNode( $user_details['federaldrugid'] )
454 $b->appendChild( $dea );
455 $msg = validation(xl('Supervising Doctor UPIN'),$user_details['upin'],$msg);
456 $upin = $doc->createElement( "upin" );
458 $doc->createTextNode( $user_details['upin'] )
460 $b->appendChild( $upin );
461 $licenseNumber = $doc->createElement( "licenseNumber" );
462 $licenseNumber->appendChild(
463 $doc->createTextNode( $user_details['state_license_number'] )
465 $b->appendChild( $licenseNumber );
466 $msg = validation(xl('Supervising Doctor NPI'),$user_details['npi'],$msg);
467 $npi = $doc->createElement( "npi" );
469 $doc->createTextNode( $user_details['npi'] )
471 $b->appendChild( $npi );
472 $r->appendChild( $b );
475 function MidlevelPrescriber($doc,$r)
478 $user_details = sqlQuery("SELECT * FROM users WHERE id = ?",array($_SESSION['authUserID']));
479 $b = $doc->createElement( "MidlevelPrescriber" );
480 $b->setAttribute('ID',$user_details['npi']);
481 $LicensedPrescriberName = $doc->createElement( "LicensedPrescriberName" );
482 $user_details['lname']=stripSpecialCharacter($user_details['lname']);
483 $msg = validation(xl('Midlevel Prescriber Last name'),$user_details['lname'],$msg);
484 $last = $doc->createElement( "last" );
486 $doc->createTextNode( $user_details['lname'] )
488 $LicensedPrescriberName->appendChild( $last );
489 $user_details['fname']=stripSpecialCharacter($user_details['fname']);
490 $msg = validation(xl('Midlevel Prescriber First name'),$user_details['fname'],$msg);
491 $first = $doc->createElement( "first" );
493 $doc->createTextNode( $user_details['fname'] )
495 $LicensedPrescriberName->appendChild( $first );
496 $user_details['mname']=stripSpecialCharacter($user_details['mname']);
497 $middle = $doc->createElement( "middle" );
498 $middle->appendChild(
499 $doc->createTextNode( $user_details['mname'] )
501 $LicensedPrescriberName->appendChild( $middle );
502 $msg = validation(xl('Midlevel Prescriber Prefix'),$user_details['title'],$msg);
503 $prefix = $doc->createElement( "prefix" );
504 $prefix->appendChild(
505 $doc->createTextNode( $user_details['title'] )
507 $LicensedPrescriberName->appendChild( $prefix );
508 $b->appendChild( $LicensedPrescriberName );
509 $msg = validation(xl('Midlevel Prescriber DEA'),$user_details['federaldrugid'],$msg);
510 $dea = $doc->createElement( "dea" );
512 $doc->createTextNode( $user_details['federaldrugid'] )
514 $b->appendChild( $dea );
515 $msg = validation(xl('Midlevel Prescriber UPIN'),$user_details['upin'],$msg);
516 $upin = $doc->createElement( "upin" );
518 $doc->createTextNode( $user_details['upin'] )
520 $b->appendChild( $upin );
521 $licenseNumber = $doc->createElement( "licenseNumber" );
522 $licenseNumber->appendChild(
523 $doc->createTextNode( $user_details['state_license_number'] )
525 $b->appendChild( $licenseNumber );
526 $r->appendChild( $b );
529 function Patient($doc,$r,$pid)
532 $patient_data=sqlQuery("select *, DATE_FORMAT(DOB,'%Y%m%d') AS date_of_birth from patient_data where pid=?",array($pid));
533 $b = $doc->createElement( "Patient" );
534 $b->setAttribute('ID',$patient_data['pid']);
535 $PatientName = $doc->createElement( "PatientName" );
536 $patient_data['lname']=stripSpecialCharacter($patient_data['lname']);
537 $patient_data['lname']=trimData($patient_data['lname'],35);
538 $msg = validation(xl('Patient Last name'),$patient_data['lname'],$msg);
539 $last = $doc->createElement( "last" );
541 $doc->createTextNode( $patient_data['lname'] )
543 $PatientName->appendChild( $last );
544 $patient_data['fname']=stripSpecialCharacter($patient_data['fname']);
545 $patient_data['fname']=trimData($patient_data['fname'],35);
546 $msg = validation(xl('Patient First name'),$patient_data['fname'],$msg);
547 $first = $doc->createElement( "first" );
549 $doc->createTextNode( $patient_data['fname'] )
551 $PatientName->appendChild( $first );
552 $patient_data['mname']=stripSpecialCharacter($patient_data['mname']);
553 $patient_data['mname']=trimData($patient_data['mname'],35);
554 $middle = $doc->createElement( "middle" );
555 $middle->appendChild(
556 $doc->createTextNode( $patient_data['mname'] )
558 $PatientName->appendChild( $middle );
559 $b->appendChild( $PatientName );
560 $PatientAddress = $doc->createElement( "PatientAddress" );
561 $patient_data['street']=stripSpecialCharacter($patient_data['street']);
562 $patient_data['street']=trimData($patient_data['street'],35);
563 $address1 = $doc->createElement( "address1" );
564 $address1->appendChild(
565 $doc->createTextNode( $patient_data['street'] )
567 $PatientAddress->appendChild( $address1 );
568 $msg = validation(xl('Patient City'),$patient_data['city'],$msg);
569 $city = $doc->createElement( "city" );
571 $doc->createTextNode( $patient_data['city'] )
573 $PatientAddress->appendChild( $city );
574 $msg = validation(xl('Patient State'),$patient_data['state'],$msg);
575 $state = $doc->createElement( "state" );
577 $doc->createTextNode( $patient_data['state'] )
579 $PatientAddress->appendChild( $state );
580 $msg = validation(xl('Patient Zip'),$patient_data['postal_code'],$msg);
581 $zip = $doc->createElement( "zip" );
583 $doc->createTextNode( $patient_data['postal_code'] )
585 $PatientAddress->appendChild( $zip );
586 $msg = validation(xl('Patient Country'),$patient_data['country_code'],$msg);
587 $county_code = substr($patient_data['country_code'],0,2);
588 $country = $doc->createElement( "country" );
589 $country->appendChild(
590 $doc->createTextNode( $county_code )
592 $PatientAddress->appendChild( $country );
593 $b->appendChild( $PatientAddress );
594 $PatientContact = $doc->createElement( "PatientContact" );
595 $patient_data['phone_home']=stripPhoneSlashes($patient_data['phone_home']);
596 $msg = validation(xl('Patient Home phone'),$patient_data['phone_home'],$msg);
597 $homeTelephone = $doc->createElement( "homeTelephone" );
598 $homeTelephone->appendChild(
599 $doc->createTextNode( $patient_data['phone_home'] )
601 $PatientContact->appendChild( $homeTelephone );
602 $b->appendChild( $PatientContact );
603 $PatientCharacteristics = $doc->createElement( "PatientCharacteristics" );
604 $msg = validation(xl('Patient DOB'),$patient_data['date_of_birth'],$msg);
605 $dob = $doc->createElement( "dob" );
607 $doc->createTextNode( $patient_data['date_of_birth'] )
609 $PatientCharacteristics->appendChild( $dob );
610 $msg = validation(xl('Patient Gender'),$patient_data['sex'],$msg);
611 $gender_val=substr($patient_data['sex'],0,1);
612 $gender = $doc->createElement( "gender" );
613 $gender->appendChild(
614 $doc->createTextNode( $gender_val )
616 $PatientCharacteristics->appendChild( $gender );
617 $b->appendChild( $PatientCharacteristics );
618 PatientFreeformHealthplans($doc,$b,$pid);
619 PatientFreeformAllergy($doc,$b,$pid);
620 $r->appendChild( $b );
623 function OutsidePrescription($doc,$r,$pid,$prescid)
628 $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,
629 DATE_FORMAT(date_added,'%Y%m%d') AS date_added,CONCAT(fname,' ',mname,' ',lname) AS docname
630 FROM prescriptions AS p
631 LEFT JOIN users AS u ON p.provider_id=u.id
632 LEFT JOIN list_options AS l1 ON l1.list_id='drug_form' AND l1.option_id=p.form
633 LEFT JOIN list_options AS l2 ON l2.list_id='drug_route' AND l2.option_id=p.route
634 LEFT JOIN list_options AS l3 ON l3.list_id='drug_interval' AND l3.option_id=p.interval
635 WHERE p.id=?",array($prescid));
636 $b = $doc->createElement( "OutsidePrescription" );
637 $externalId = $doc->createElement( "externalId" );
638 $externalId->appendChild(
639 $doc->createTextNode( $prec['prescid'] )
641 $b->appendChild( $externalId );
642 $date = $doc->createElement( "date" );
644 $doc->createTextNode( $prec['date_added'] )
646 $b->appendChild( $date );
647 $doctorName = $doc->createElement( "doctorName" );
648 $doctorName->appendChild(
649 $doc->createTextNode( $prec['docname'] )
651 $b->appendChild( $doctorName );
652 $s=$prec['drug'].": Take ".$prec['dosage']." In ".$prec['title1']." ".$prec['title2']." ".$prec['title3'];
653 $sig = $doc->createElement( "drug" );
655 $doc->createTextNode( $s )
657 $b->appendChild( $sig );
658 $dispenseNumber = $doc->createElement( "dispenseNumber" );
659 $dispenseNumber->appendChild(
660 $doc->createTextNode( '30' )
662 $b->appendChild( $dispenseNumber );
663 $s=$prec['dosage']." ".$prec['title3'];
664 $sig = $doc->createElement( "sig" );
666 $doc->createTextNode( $s )
668 $b->appendChild( $sig );
669 $refillCount = $doc->createElement( "refillCount" );
670 $refillCount->appendChild(
671 $doc->createTextNode( $prec['per_refill'] )
673 $b->appendChild( $refillCount );
674 $prescriptionType = $doc->createElement( "prescriptionType" );
675 $prescriptionType->appendChild(
676 $doc->createTextNode( 'reconcile' )
678 $b->appendChild( $prescriptionType );
679 $r->appendChild( $b );
683 function PatientFreeformAllergy($doc,$r,$pid)
685 $res=sqlStatement("SELECT id,l.title as title1,lo.title as title2,comments FROM lists AS l
686 LEFT JOIN list_options AS lo ON l.outcome=lo.option_id AND lo.list_id='outcome' WHERE `type`='allergy' AND pid=? AND erx_source='0' AND enddate IS NULL",array($pid));
687 while($row=sqlFetchArray($res))
690 $val['id']=$row['id'];
691 $val['title1']=$row['title1'];
692 $val['title2']=$row['title2'];
693 $val['comments']=$row['comments'];
694 $b = $doc->createElement( "PatientFreeformAllergy" );
695 $b->setAttribute('ID',$val['id']);
697 $allergyName = $doc->createElement( "allergyName" );
698 $allergyName->appendChild(
699 $doc->createTextNode( $val['title1'] )
701 $b->appendChild( $allergyName );
704 $allergySeverityTypeID = $doc->createElement( "allergySeverityTypeID" );
705 $allergySeverityTypeID->appendChild(
706 $doc->createTextNode( $val['title2'] )
708 $b->appendChild( $allergySeverityTypeID );
710 if($val['comments']){
711 $allergyComment = $doc->createElement( "allergyComment" );
712 $allergyComment->appendChild(
713 $doc->createTextNode( $val['comments'] )
715 $b->appendChild( $allergyComment );
717 $r->appendChild( $b );
721 function PatientFreeformHealthplans($doc,$r,$pid)
723 $res=sqlStatement("SELECT `name`,`type` FROM insurance_companies AS ic, insurance_data AS id
724 WHERE ic.id=id.provider AND id.pid=?",array($pid));
725 while($row=sqlFetchArray($res))
727 $b = $doc->createElement( "PatientFreeformHealthplans" );
728 $allergyName = $doc->createElement( "healthplanName" );
729 $allergyName->appendChild(
730 $doc->createTextNode( $row['name'] )
732 $b->appendChild( $allergyName );
733 $r->appendChild( $b );
737 function PrescriptionRenewalResponse($doc,$r,$pid)
739 $b = $doc->createElement( "PrescriptionRenewalResponse" );
740 $renewalRequestIdentifier = $doc->createElement( "renewalRequestIdentifier" );
741 $renewalRequestIdentifier->appendChild(
742 $doc->createTextNode( 'cbf51649-ce3c-44b8-8f91-6fda121a353d' )
744 $b->appendChild( $renewalRequestIdentifier );
745 $responseCode = $doc->createElement( "responseCode" );
746 $responseCode->appendChild(
747 $doc->createTextNode( 'Undetermined' )
749 $b->appendChild( $responseCode );
750 $r->appendChild( $b );
753 function checkError($xml)
755 $ch = curl_init($xml);
757 $data = array('RxInput' => $xml);
759 curl_setopt($ch, CURLOPT_URL
, getErxPath());
760 curl_setopt($ch, CURLOPT_POST
, 1);
761 curl_setopt($ch, CURLOPT_POSTFIELDS
, "RxInput=".$xml);
762 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER
, 0);
763 curl_setopt($ch, CURLOPT_FOLLOWLOCATION
, 1);
764 curl_setopt($ch, CURLOPT_COOKIESESSION
, TRUE);
765 //curl_setopt($ch, CURLOPT_HEADER, 0);
766 curl_setopt($ch, CURLOPT_COOKIEFILE
, "cookiefile");
767 curl_setopt($ch, CURLOPT_COOKIEJAR
, "cookiefile");
768 curl_setopt($ch, CURLOPT_COOKIE
, session_name() . '=' . session_id());
769 curl_setopt($ch, CURLOPT_USERAGENT
,"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
770 curl_setopt($ch, CURLOPT_RETURNTRANSFER
, true);
773 $result=curl_exec($ch) or die( curl_error($ch)) ;
775 if(strpos($result,'RxEntry.aspx'))