Merge branch 'master' of git://github.com/openemr/openemr
[openemr.git] / library / freeb / Practice.class.php
blob440efba9da4faaf6b0436f0b3c57b3933e046bb1
1 <?php
2 require_once("DataObjectBase.class.php");
3 require_once("xmlrpc.inc");
5 class Practice Extends DataObjectBase {
7 function Practice() {
8 $this->_addFunc("name", array( "name" => "FreeB.FBPractice.Name",
9 "sig" => array(XMLRPCSTRING,XMLRPCINT),
10 "doc" => ""));
11 $this->_addFunc("streetaddress", array( "name" => "FreeB.FBPractice.StreetAddress",
12 "sig" => array(XMLRPCSTRING,XMLRPCINT),
13 "doc" => ""));
14 $this->_addFunc("city", array( "name" => "FreeB.FBPractice.City",
15 "sig" => array(XMLRPCSTRING,XMLRPCINT),
16 "doc" => ""));
17 $this->_addFunc("state", array( "name" => "FreeB.FBPractice.State",
18 "sig" => array(XMLRPCSTRING,XMLRPCINT),
19 "doc" => ""));
20 $this->_addFunc("zipcode", array( "name" => "FreeB.FBPractice.Zipcode",
21 "sig" => array(XMLRPCSTRING,XMLRPCINT),
22 "doc" => ""));
23 $this->_addFunc("phonecountry", array( "name" => "FreeB.FBPractice.PhoneCountry",
24 "sig" => array(XMLRPCSTRING,XMLRPCINT),
25 "doc" => ""));
26 $this->_addFunc("phoneextension", array( "name" => "FreeB.FBPractice.PhoneExtension",
27 "sig" => array(XMLRPCSTRING,XMLRPCINT),
28 "doc" => ""));
29 $this->_addFunc("phonearea", array( "name" => "FreeB.FBPractice.PhoneArea",
30 "sig" => array(XMLRPCSTRING,XMLRPCINT),
31 "doc" => ""));
32 $this->_addFunc("phonenumber", array( "name" => "FreeB.FBPractice.PhoneNumber",
33 "sig" => array(XMLRPCSTRING,XMLRPCINT),
34 "doc" => ""));
35 $this->_addFunc("isacceptsassignment", array( "name" => "FreeB.FBPractice.isAcceptsAssignment",
36 "sig" => array(XMLRPCSTRING,XMLRPCINT),
37 "doc" => ""));
38 $this->_addFunc("tin", array( "name" => "FreeB.FBPractice.TIN",
39 "sig" => array(XMLRPCSTRING,XMLRPCINT,XMLRPCINT,XMLRPCINT),
40 "doc" => ""));
41 $this->_addFunc("npi", array( "name" => "FreeB.FBPractice.NPI",
42 "sig" => array(XMLRPCSTRING,XMLRPCINT,XMLRPCINT,XMLRPCINT),
43 "doc" => ""));
44 $this->_addFunc("practiceid", array( "name" => "FreeB.FBPractice.PracticeID",
45 "sig" => array(XMLRPCSTRING,XMLRPCINT,XMLRPCINT,XMLRPCINT),
46 "doc" => ""));
47 $this->_addFunc("renderingpracticeid", array( "name" => "FreeB.FBPractice.RenderingPracticeID",
48 "sig" => array(XMLRPCSTRING,XMLRPCINT,XMLRPCINT,XMLRPCINT),
49 "doc" => ""));
50 $this->_addFunc("groupid", array( "name" => "FreeB.FBPractice.GroupID",
51 "sig" => array(XMLRPCSTRING,XMLRPCINT,XMLRPCINT,XMLRPCINT),
52 "doc" => ""));
53 $this->_addFunc("providernumx12type", array( "name" => "FreeB.FBPractice.ProviderNumX12Type",
54 "sig" => array(XMLRPCSTRING,XMLRPCINT,XMLRPCINT,XMLRPCINT),
55 "doc" => ""));
56 $this->_addFunc("renderingnumx12type", array( "name" => "FreeB.FBPractice.RenderingNumX12Type",
57 "sig" => array(XMLRPCSTRING,XMLRPCINT,XMLRPCINT,XMLRPCINT),
58 "doc" => ""));
59 $this->_addFunc("x12id", array( "name" => "FreeB.FBPractice.X12Id",
60 "sig" => array(XMLRPCSTRING,XMLRPCINT,XMLRPCINT),
61 "doc" => ""));
66 function name($m) {
68 $err="";
70 $obj= $m->getparam(0);
71 $key = $obj->getval();
73 $sql = "SELECT * FROM facility where billing_location = '1'";
74 //echo $sql;
75 $db = $GLOBALS['adodb']['db'];
76 $results = $db->Execute($sql);
78 if (!$results) {
79 $err = $db->ErrorMsg();
81 else {
82 if (!$results->EOF) {
83 $retval = $results->fields['name'];
87 // if we generated an error, create an error return response
88 if ($err) {
89 return $this->_handleError($err);
91 else {
92 // otherwise, we create the right response
93 // with the state name
94 return new xmlrpcresp(new xmlrpcval($retval,""));
98 function streetaddress($m) {
100 $err="";
102 $obj= $m->getparam(0);
103 $key = $obj->getval();
105 $sql = "SELECT * FROM facility where billing_location = '1'";
106 //echo $sql;
107 $db = $GLOBALS['adodb']['db'];
108 $results = $db->Execute($sql);
110 if (!$results) {
111 $err = $db->ErrorMsg();
113 else {
114 if (!$results->EOF) {
115 $retval = $results->fields['street'];
119 // if we generated an error, create an error return response
120 if ($err) {
121 return $this->_handleError($err);
123 else {
124 // otherwise, we create the right response
125 // with the state name
126 return new xmlrpcresp(new xmlrpcval($retval,"string"));
131 function city($m) {
133 $err="";
135 $obj= $m->getparam(0);
136 $key = $obj->getval();
138 $sql = "SELECT * FROM facility where billing_location = '1'";
139 //echo $sql;
140 $db = $GLOBALS['adodb']['db'];
141 $results = $db->Execute($sql);
143 if (!$results) {
144 $err = $db->ErrorMsg();
146 else {
147 if (!$results->EOF) {
148 $retval = $results->fields['city'];
152 // if we generated an error, create an error return response
153 if ($err) {
154 return $this->_handleError($err);
156 else {
157 // otherwise, we create the right response
158 // with the state name
159 return new xmlrpcresp(new xmlrpcval($retval,"string"));
163 function state($m) {
165 $err="";
167 $obj= $m->getparam(0);
168 $key = $obj->getval();
170 $sql = "SELECT * FROM facility where billing_location = '1'";
171 //echo $sql;
172 $db = $GLOBALS['adodb']['db'];
173 $results = $db->Execute($sql);
175 if (!$results) {
176 $err = $db->ErrorMsg();
178 else {
179 if (!$results->EOF) {
180 $retval = $results->fields['state'];
184 // if we generated an error, create an error return response
185 if ($err) {
186 return $this->_handleError($err);
188 else {
189 // otherwise, we create the right response
190 // with the state name
191 return new xmlrpcresp(new xmlrpcval($retval,"string"));
195 function zipcode($m) {
197 $err="";
199 $obj= $m->getparam(0);
200 $key = $obj->getval();
202 $sql = "SELECT * FROM facility where billing_location = '1'";
203 //echo $sql;
204 $db = $GLOBALS['adodb']['db'];
205 $results = $db->Execute($sql);
207 if (!$results) {
208 $err = $db->ErrorMsg();
210 else {
211 if (!$results->EOF) {
212 $retval = $results->fields['postal_code'];
216 // if we generated an error, create an error return response
217 if ($err) {
218 return $this->_handleError($err);
220 else {
221 // otherwise, we create the right response
222 // with the state name
223 return new xmlrpcresp(new xmlrpcval($retval,"string"));
226 function phonecountry($m) {
228 $err="";
230 $pkey = "1";
232 // if we generated an error, create an error return response
233 if ($err) {
234 return $this->_handleError($err);
236 else {
237 // otherwise, we create the right response
238 // with the state name
239 return new xmlrpcresp(new xmlrpcval($pkey));
243 function phoneextension($m) {
245 $err="";
247 //unimplemented by OpenEMR
248 $pkey = "";
250 // if we generated an error, create an error return response
251 if ($err) {
252 return $this->_handleError($err);
254 else {
255 // otherwise, we create the right response
256 // with the state name
257 return new xmlrpcresp(new xmlrpcval($pkey));
261 function phonearea($m) {
263 $err="";
265 $obj= $m->getparam(0);
266 $key = $obj->getval();
268 $sql = "SELECT * FROM facility where billing_location = '1'";
269 //echo $sql;
270 $db = $GLOBALS['adodb']['db'];
271 $results = $db->Execute($sql);
273 if (!$results) {
274 $err = $db->ErrorMsg();
276 else {
277 if (!$results->EOF) {
278 $retval = $results->fields['phone'];
282 $phone_parts = array();
283 // preg_match("/^\((.*?)\)\s(.*?)\-(.*?)$/",$retval,$phone_parts);
284 preg_match("/(\d\d\d)\D*(\d\d\d)\D*(\d\d\d\d)/",$retval,$phone_parts);
285 $retval = $phone_parts[1];
287 // if we generated an error, create an error return response
288 if ($err) {
289 return $this->_handleError($err);
291 else {
292 // otherwise, we create the right response
293 // with the state name
294 return new xmlrpcresp(new xmlrpcval($retval,"string"));
298 function phonenumber($m) {
300 $err="";
302 $obj= $m->getparam(0);
303 $key = $obj->getval();
305 $sql = "SELECT * FROM facility where billing_location = '1'";
306 //echo $sql;
307 $db = $GLOBALS['adodb']['db'];
308 $results = $db->Execute($sql);
310 if (!$results) {
311 $err = $db->ErrorMsg();
313 else {
314 if (!$results->EOF) {
315 $retval = $results->fields['phone'];
319 $phone_parts = array();
320 // preg_match("/^\((.*?)\)\s(.*?)\-(.*?)$/",$retval,$phone_parts);
321 preg_match("/(\d\d\d)\D*(\d\d\d)\D*(\d\d\d\d)/",$retval,$phone_parts);
322 $retval = $phone_parts[2] . "-" . $phone_parts[3];
324 // if we generated an error, create an error return response
325 if ($err) {
326 return $this->_handleError($err);
328 else {
329 // otherwise, we create the right response
330 // with the state name
331 return new xmlrpcresp(new xmlrpcval($retval,"string"));
335 function isacceptsassignment($m) {
337 $err="";
339 $obj= $m->getparam(0);
340 $key = $obj->getval();
342 $sql = "SELECT * FROM facility where billing_location = '1'";
343 //echo $sql;
344 $db = $GLOBALS['adodb']['db'];
345 $results = $db->Execute($sql);
347 if (!$results) {
348 $err = $db->ErrorMsg();
350 else {
351 if (!$results->EOF) {
352 $retval = $results->fields['accepts_assignment'];
356 // if we generated an error, create an error return response
357 if ($err) {
358 return $this->_handleError($err);
360 else {
361 // otherwise, we create the right response
362 // with the state name
363 return new xmlrpcresp(new xmlrpcval($retval,"i4"));
368 * Returns a federal ein based on practice, payer, provider
369 * @key int practice identifier used in database, in OpenEMR practices are facilities
370 * @payerkey int database id of the insurance company
371 * @providekey int database id of the provider
374 function tin($m) {
376 $err="";
378 $obj= $m->getparam(0);
379 $key = $obj->getval();
381 $obj= $m->getparam(1);
382 $payerkey = $obj->getval();
384 $obj= $m->getparam(2);
385 $providerkey = $obj->getval();
387 $sql = "SELECT * FROM facility where billing_location = 1";
388 //echo $sql;
389 $db = $GLOBALS['adodb']['db'];
390 $results = $db->Execute($sql);
392 $vals = array();
393 if (!$results) {
394 $err = $db->ErrorMsg();
396 else {
397 if (!$results->EOF) {
398 $retval = $results->fields['federal_ein'];
403 // if we generated an error, create an error return response
404 if ($err) {
405 return $this->_handleError($err);
407 else {
408 // otherwise, we create the right response
409 // with the state name
410 return new xmlrpcresp(new xmlrpcval($retval,"string"));
415 function practiceid($m) {
417 $err="";
419 $obj= $m->getparam(0);
420 $key = $obj->getval();
422 $obj= $m->getparam(1);
423 $payerkey = $obj->getval();
425 $obj= $m->getparam(2);
426 $providerkey = $obj->getval();
428 //this query gets the exact match or resorts to the default when no exact is found (default has a NULL value for insurance_company_id)
429 $sql = "SELECT * FROM insurance_numbers where (insurance_company_id = '$payerkey' OR insurance_company_id is NULL) AND provider_id = '$providerkey' order by insurance_company_id DESC";
430 //echo $sql;
431 $db = $GLOBALS['adodb']['db'];
432 $results = $db->Execute($sql);
434 $vals = array();
435 if (!$results) {
436 $err = $db->ErrorMsg();
438 else {
439 while (!$results->EOF) {
440 $vals[] = $results->fields['provider_number'];
441 $results->MoveNext();
445 //if there is an exact match or not match and only the default then set it here
446 if (!empty($vals[0])) {
447 $retval = $vals[0];
449 else {
450 //if the exact match was empty for a provider number reference the default which is 1 because the nifty query and sorting above
451 $retval = $vals[1];
454 // if we generated an error, create an error return response
455 if ($err) {
456 return $this->_handleError($err);
458 else {
459 // otherwise, we create the right response
460 // with the state name
461 return new xmlrpcresp(new xmlrpcval($retval,"string"));
465 function renderingpracticeid($m) {
467 $err="";
469 $obj= $m->getparam(0);
470 $key = $obj->getval();
472 $obj= $m->getparam(1);
473 $payerkey = $obj->getval();
475 $obj= $m->getparam(2);
476 $providerkey = $obj->getval();
478 //this query gets the exact match or resorts to the default when no exact is found (default has a NULL value for insurance_company_id)
479 $sql = "SELECT * FROM insurance_numbers where (insurance_company_id = '$payerkey' OR insurance_company_id is NULL) AND provider_id = '$providerkey' order by insurance_company_id DESC";
480 //echo $sql;
481 $db = $GLOBALS['adodb']['db'];
482 $results = $db->Execute($sql);
484 $vals = array();
485 if (!$results) {
486 $err = $db->ErrorMsg();
488 else {
489 while (!$results->EOF) {
490 $vals[] = $results->fields['rendering_provider_number'];
491 $results->MoveNext();
495 //if there is an exact match or not match and only the default then set it here
496 if (!empty($vals[0])) {
497 $retval = $vals[0];
499 else {
500 //if the exact match was empty for a provider number reference the default which is 1 because the nifty query and sorting above
501 $retval = $vals[1];
504 // if we generated an error, create an error return response
505 if ($err) {
506 return $this->_handleError($err);
508 else {
509 // otherwise, we create the right response
510 // with the state name
511 return new xmlrpcresp(new xmlrpcval($retval,"string"));
515 function groupid($m) {
517 $err="";
519 $obj= $m->getparam(0);
520 $key = $obj->getval();
522 $obj= $m->getparam(1);
523 $payerkey = $obj->getval();
525 $obj= $m->getparam(2);
526 $providerkey = $obj->getval();
528 //this query gets the exact match or resorts to the default when no exact is found (default has a NULL value for insurance_company_id)
529 $sql = "SELECT * FROM insurance_numbers where (insurance_company_id = '$payerkey' OR insurance_company_id is NULL) AND provider_id = '$providerkey' order by insurance_company_id DESC";
530 //echo $sql;
531 $db = $GLOBALS['adodb']['db'];
532 $results = $db->Execute($sql);
534 $vals = array();
535 if (!$results) {
536 $err = $db->ErrorMsg();
538 else {
539 while (!$results->EOF) {
540 $vals[] = $results->fields['group_number'];
541 $results->MoveNext();
545 if (!empty($vals[0])) {
546 $retval = $vals[0];
548 else {
549 //if the exact match was empty for a group number reference the default which is 1 because the nifty query and sorting above
550 $retval = $vals[1];
554 // if we generated an error, create an error return response
555 if ($err) {
556 return $this->_handleError($err);
558 else {
559 // otherwise, we create the right response
560 // with the state name
561 return new xmlrpcresp(new xmlrpcval($retval,"string"));
565 function providernumx12type($m) {
567 $err="";
569 $obj= $m->getparam(0);
570 $key = $obj->getval();
572 $obj= $m->getparam(1);
573 $payerkey = $obj->getval();
575 $obj= $m->getparam(2);
576 $providerkey = $obj->getval();
578 //this query gets the exact match or resorts to the default when no exact is found (default has a NULL value for insurance_company_id)
579 $sql = "SELECT * FROM insurance_numbers where (insurance_company_id = '$payerkey' OR insurance_company_id is NULL) AND provider_id = '$providerkey' order by insurance_company_id DESC";
580 //echo $sql;
581 $db = $GLOBALS['adodb']['db'];
582 $results = $db->Execute($sql);
584 $vals = array();
585 if (!$results) {
586 $err = $db->ErrorMsg();
588 else {
589 while (!$results->EOF) {
590 $vals[] = $results->fields['provider_number_type'];
591 $results->MoveNext();
595 //if there is an exact match or not match and only the default then set it here
596 if (!empty($vals[0])) {
597 $retval = $vals[0];
599 else {
600 //if the exact match was empty for a provider number reference the default which is 1 because the nifty query and sorting above
601 $retval = $vals[1];
604 // if we generated an error, create an error return response
605 if ($err) {
606 return $this->_handleError($err);
608 else {
609 // otherwise, we create the right response
610 // with the state name
611 return new xmlrpcresp(new xmlrpcval($retval));
615 function renderingnumx12type($m) {
617 $err="";
619 $obj= $m->getparam(0);
620 $key = $obj->getval();
622 $obj= $m->getparam(1);
623 $payerkey = $obj->getval();
625 $obj= $m->getparam(2);
626 $providerkey = $obj->getval();
628 //this query gets the exact match or resorts to the default when no exact is found (default has a NULL value for insurance_company_id)
629 $sql = "SELECT * FROM insurance_numbers where (insurance_company_id = '$payerkey' OR insurance_company_id is NULL) AND provider_id = '$providerkey' order by insurance_company_id DESC";
630 //echo $sql;
631 $db = $GLOBALS['adodb']['db'];
632 $results = $db->Execute($sql);
634 $vals = array();
635 if (!$results) {
636 $err = $db->ErrorMsg();
638 else {
639 while (!$results->EOF) {
640 $vals[] = $results->fields['rendering_provider_number_type'];
641 $results->MoveNext();
645 //if there is an exact match or not match and only the default then set it here
646 if (!empty($vals[0])) {
647 $retval = $vals[0];
649 else {
650 //if the exact match was empty for a provider number reference the default which is 1 because the nifty query and sorting above
651 $retval = $vals[1];
654 // if we generated an error, create an error return response
655 if ($err) {
656 return $this->_handleError($err);
658 else {
659 // otherwise, we create the right response
660 // with the state name
661 return new xmlrpcresp(new xmlrpcval($retval));
665 function x12id($m) {
667 $err="";
670 $obj= $m->getparam(0);
671 $key = $obj->getval();
673 $sql = "SELECT * FROM facility where billing_location = 1";
674 //echo $sql;
675 $db = $GLOBALS['adodb']['db'];
676 $results = $db->Execute($sql);
678 $vals = array();
679 if (!$results) {
680 $err = $db->ErrorMsg();
682 else {
683 if (!$results->EOF) {
684 $retval = $results->fields['federal_ein'];
689 // if we generated an error, create an error return response
690 if ($err) {
691 return $this->_handleError($err);
693 else {
694 // otherwise, we create the right response
695 // with the state name
696 return new xmlrpcresp(new xmlrpcval($retval));
700 function npi($m) {
702 $err="";
704 $obj= $m->getparam(0);
705 $key = $obj->getval();
707 $obj= $m->getparam(1);
708 $payerkey = $obj->getval();
710 $obj= $m->getparam(2);
711 $providerkey = $obj->getval();
713 $sql = "SELECT * FROM facility where billing_location = 1";
714 //echo $sql;
715 $db = $GLOBALS['adodb']['db'];
716 $results = $db->Execute($sql);
718 $vals = array();
719 if (!$results) {
720 $err = $db->ErrorMsg();
722 else {
723 if (!$results->EOF) {
724 $retval = $results->fields['facility_npi'];
729 // if we generated an error, create an error return response
730 if ($err) {
731 return $this->_handleError($err);
733 else {
734 // otherwise, we create the right response
735 // with the state name
736 return new xmlrpcresp(new xmlrpcval($retval,"string"));
744 //'FreeB.FBPractice.Name' => \&FreeB_FBPractice_Name,
745 //'FreeB.FBPractice.StreetAddress' => \&FreeB_FBPractice_StreetAddress,
746 //'FreeB.FBPractice.City' => \&FreeB_FBPractice_City,
747 //'FreeB.FBPractice.State' => \&FreeB_FBPractice_State,
748 //'FreeB.FBPractice.Zipcode' => \&FreeB_FBPractice_Zipcode,
749 //'FreeB.FBPractice.PhoneCountry' => \&FreeB_FBPractice_PhoneCountry,
750 //'FreeB.FBPractice.PhoneExtension' => \&FreeB_FBPractice_PhoneExtension,
751 //'FreeB.FBPractice.PhoneNumber' => \&FreeB_FBPractice_PhoneNumber,
752 //'FreeB.FBPractice.PhoneArea' => \&FreeB_FBPractice_PhoneArea,
753 //'FreeB.FBPractice.isAcceptsAssignment' => \&FreeB_FBPractice_isAcceptsAssignment,
754 //'FreeB.FBPractice.PracticeID' => \&FreeB_FBPractice_PracticeID,
755 //'FreeB.FBPractice.RenderingPracticeID' => \&FreeB_FBPractice_RenderingPracticeID,
756 //'FreeB.FBPractice.GroupID' => \&FreeB_FBPractice_GroupID,
757 //'FreeB.FBPractice.TIN' => \&FreeB_FBPractice_TIN,
758 //'FreeB.FBPractice.NPI' => \&FreeB_FBPractice_NPI,
759 //'FreeB.FBPractice.ProviderNumX12Type' => \&FreeB_FBPractice_ProviderNumX12Type,
760 //'FreeB.FBPractice.RenderingNumX12Type' => \&FreeB_FBPractice_RenderingNumX12Type,
761 //'FreeB.FBPractice.X12Id' => \&FreeB_FBPractice_X12Id,