2 require_once("DataObjectBase.class.php");
3 require_once("xmlrpc.inc");
5 class Practice
Extends DataObjectBase
{
8 $this->_addFunc("name", array( "name" => "FreeB.FBPractice.Name",
9 "sig" => array(XMLRPCSTRING
,XMLRPCINT
),
11 $this->_addFunc("streetaddress", array( "name" => "FreeB.FBPractice.StreetAddress",
12 "sig" => array(XMLRPCSTRING
,XMLRPCINT
),
14 $this->_addFunc("city", array( "name" => "FreeB.FBPractice.City",
15 "sig" => array(XMLRPCSTRING
,XMLRPCINT
),
17 $this->_addFunc("state", array( "name" => "FreeB.FBPractice.State",
18 "sig" => array(XMLRPCSTRING
,XMLRPCINT
),
20 $this->_addFunc("zipcode", array( "name" => "FreeB.FBPractice.Zipcode",
21 "sig" => array(XMLRPCSTRING
,XMLRPCINT
),
23 $this->_addFunc("phonecountry", array( "name" => "FreeB.FBPractice.PhoneCountry",
24 "sig" => array(XMLRPCSTRING
,XMLRPCINT
),
26 $this->_addFunc("phoneextension", array( "name" => "FreeB.FBPractice.PhoneExtension",
27 "sig" => array(XMLRPCSTRING
,XMLRPCINT
),
29 $this->_addFunc("phonearea", array( "name" => "FreeB.FBPractice.PhoneArea",
30 "sig" => array(XMLRPCSTRING
,XMLRPCINT
),
32 $this->_addFunc("phonenumber", array( "name" => "FreeB.FBPractice.PhoneNumber",
33 "sig" => array(XMLRPCSTRING
,XMLRPCINT
),
35 $this->_addFunc("isacceptsassignment", array( "name" => "FreeB.FBPractice.isAcceptsAssignment",
36 "sig" => array(XMLRPCSTRING
,XMLRPCINT
),
38 $this->_addFunc("tin", array( "name" => "FreeB.FBPractice.TIN",
39 "sig" => array(XMLRPCSTRING
,XMLRPCINT
,XMLRPCINT
,XMLRPCINT
),
41 $this->_addFunc("practiceid", array( "name" => "FreeB.FBPractice.PracticeID",
42 "sig" => array(XMLRPCSTRING
,XMLRPCINT
,XMLRPCINT
,XMLRPCINT
),
44 $this->_addFunc("groupid", array( "name" => "FreeB.FBPractice.GroupID",
45 "sig" => array(XMLRPCSTRING
,XMLRPCINT
,XMLRPCINT
,XMLRPCINT
),
47 $this->_addFunc("x12idtype", array( "name" => "FreeB.FBPractice.X12IdType",
48 "sig" => array(XMLRPCSTRING
,XMLRPCINT
,XMLRPCINT
,XMLRPCINT
),
50 $this->_addFunc("x12id", array( "name" => "FreeB.FBPractice.X12Id",
51 "sig" => array(XMLRPCSTRING
,XMLRPCINT
,XMLRPCINT
),
60 $obj= $m->getparam(0);
61 $key = $obj->getval();
63 $sql = "SELECT * FROM facility where billing_location = '1'";
65 $db = $GLOBALS['adodb']['db'];
66 $results = $db->Execute($sql);
69 $err = $db->ErrorMsg();
73 $retval = $results->fields
['name'];
77 // if we generated an error, create an error return response
79 return $this->_handleError($err);
82 // otherwise, we create the right response
83 // with the state name
84 return new xmlrpcresp(new xmlrpcval($retval,""));
88 function streetaddress($m) {
92 $obj= $m->getparam(0);
93 $key = $obj->getval();
95 $sql = "SELECT * FROM facility where billing_location = '1'";
97 $db = $GLOBALS['adodb']['db'];
98 $results = $db->Execute($sql);
101 $err = $db->ErrorMsg();
104 if (!$results->EOF
) {
105 $retval = $results->fields
['street'];
109 // if we generated an error, create an error return response
111 return $this->_handleError($err);
114 // otherwise, we create the right response
115 // with the state name
116 return new xmlrpcresp(new xmlrpcval($retval,"string"));
125 $obj= $m->getparam(0);
126 $key = $obj->getval();
128 $sql = "SELECT * FROM facility where billing_location = '1'";
130 $db = $GLOBALS['adodb']['db'];
131 $results = $db->Execute($sql);
134 $err = $db->ErrorMsg();
137 if (!$results->EOF
) {
138 $retval = $results->fields
['city'];
142 // if we generated an error, create an error return response
144 return $this->_handleError($err);
147 // otherwise, we create the right response
148 // with the state name
149 return new xmlrpcresp(new xmlrpcval($retval,"string"));
157 $obj= $m->getparam(0);
158 $key = $obj->getval();
160 $sql = "SELECT * FROM facility where billing_location = '1'";
162 $db = $GLOBALS['adodb']['db'];
163 $results = $db->Execute($sql);
166 $err = $db->ErrorMsg();
169 if (!$results->EOF
) {
170 $retval = $results->fields
['state'];
174 // if we generated an error, create an error return response
176 return $this->_handleError($err);
179 // otherwise, we create the right response
180 // with the state name
181 return new xmlrpcresp(new xmlrpcval($retval,"string"));
185 function zipcode($m) {
189 $obj= $m->getparam(0);
190 $key = $obj->getval();
192 $sql = "SELECT * FROM facility where billing_location = '1'";
194 $db = $GLOBALS['adodb']['db'];
195 $results = $db->Execute($sql);
198 $err = $db->ErrorMsg();
201 if (!$results->EOF
) {
202 $retval = $results->fields
['postal_code'];
206 // if we generated an error, create an error return response
208 return $this->_handleError($err);
211 // otherwise, we create the right response
212 // with the state name
213 return new xmlrpcresp(new xmlrpcval($retval,"string"));
216 function phonecountry($m) {
222 // if we generated an error, create an error return response
224 return $this->_handleError($err);
227 // otherwise, we create the right response
228 // with the state name
229 return new xmlrpcresp(new xmlrpcval($pkey));
233 function phoneextension($m) {
237 //unimplemented by OpenEMR
240 // if we generated an error, create an error return response
242 return $this->_handleError($err);
245 // otherwise, we create the right response
246 // with the state name
247 return new xmlrpcresp(new xmlrpcval($pkey));
251 function phonearea($m) {
255 $obj= $m->getparam(0);
256 $key = $obj->getval();
258 $sql = "SELECT * FROM facility where billing_location = '1'";
260 $db = $GLOBALS['adodb']['db'];
261 $results = $db->Execute($sql);
264 $err = $db->ErrorMsg();
267 if (!$results->EOF
) {
268 $retval = $results->fields
['phone'];
272 $phone_parts = array();
273 preg_match("/^\((.*?)\)\s(.*?)\-(.*?)$/",$retval,$phone_parts);
274 $retval = $phone_parts[1];
275 // if we generated an error, create an error return response
277 return $this->_handleError($err);
280 // otherwise, we create the right response
281 // with the state name
282 return new xmlrpcresp(new xmlrpcval($retval,"string"));
286 function phonenumber($m) {
290 $obj= $m->getparam(0);
291 $key = $obj->getval();
293 $sql = "SELECT * FROM facility where billing_location = '1'";
295 $db = $GLOBALS['adodb']['db'];
296 $results = $db->Execute($sql);
299 $err = $db->ErrorMsg();
302 if (!$results->EOF
) {
303 $retval = $results->fields
['phone'];
307 $phone_parts = array();
308 preg_match("/^\((.*?)\)\s(.*?)\-(.*?)$/",$retval,$phone_parts);
309 $retval = $phone_parts[2] . "-" . $phone_parts[3];
311 // if we generated an error, create an error return response
313 return $this->_handleError($err);
316 // otherwise, we create the right response
317 // with the state name
318 return new xmlrpcresp(new xmlrpcval($retval,"string"));
322 function isacceptsassignment($m) {
326 $obj= $m->getparam(0);
327 $key = $obj->getval();
329 $sql = "SELECT * FROM facility where billing_location = '1'";
331 $db = $GLOBALS['adodb']['db'];
332 $results = $db->Execute($sql);
335 $err = $db->ErrorMsg();
338 if (!$results->EOF
) {
339 $retval = $results->fields
['accepts_assignment'];
343 // if we generated an error, create an error return response
345 return $this->_handleError($err);
348 // otherwise, we create the right response
349 // with the state name
350 return new xmlrpcresp(new xmlrpcval($retval,"i4"));
355 * Returns a federal ein based on practice, payer, provider
356 * @key int practice identifier used in database, in OpenEMR practices are facilities
357 * @payerkey int database id of the insurance company
358 * @providekey int database id of the provider
365 $obj= $m->getparam(0);
366 $key = $obj->getval();
368 $obj= $m->getparam(1);
369 $payerkey = $obj->getval();
371 $obj= $m->getparam(2);
372 $providerkey = $obj->getval();
374 $sql = "SELECT * FROM facility where billing_location = 1";
376 $db = $GLOBALS['adodb']['db'];
377 $results = $db->Execute($sql);
381 $err = $db->ErrorMsg();
384 if (!$results->EOF
) {
385 $retval = $results->fields
['federal_ein'];
390 // if we generated an error, create an error return response
392 return $this->_handleError($err);
395 // otherwise, we create the right response
396 // with the state name
397 return new xmlrpcresp(new xmlrpcval($retval,"string"));
402 function practiceid($m) {
406 $obj= $m->getparam(0);
407 $key = $obj->getval();
409 $obj= $m->getparam(1);
410 $payerkey = $obj->getval();
412 $obj= $m->getparam(2);
413 $providerkey = $obj->getval();
415 //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)
416 $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";
418 $db = $GLOBALS['adodb']['db'];
419 $results = $db->Execute($sql);
423 $err = $db->ErrorMsg();
426 while (!$results->EOF
) {
427 $vals[] = $results->fields
['provider_number'];
428 $results->MoveNext();
432 //if there is an exact match or not match and only the default then set it here
433 if (!empty($vals[0])) {
437 //if the exact match was empty for a provider number reference the default which is 1 because the nifty query and sorting above
441 // if we generated an error, create an error return response
443 return $this->_handleError($err);
446 // otherwise, we create the right response
447 // with the state name
448 return new xmlrpcresp(new xmlrpcval($retval,"string"));
452 function groupid($m) {
456 $obj= $m->getparam(0);
457 $key = $obj->getval();
459 $obj= $m->getparam(1);
460 $payerkey = $obj->getval();
462 $obj= $m->getparam(2);
463 $providerkey = $obj->getval();
465 //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)
466 $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";
468 $db = $GLOBALS['adodb']['db'];
469 $results = $db->Execute($sql);
473 $err = $db->ErrorMsg();
476 while (!$results->EOF
) {
477 $vals[] = $results->fields
['group_number'];
478 $results->MoveNext();
482 if (!empty($vals[0])) {
486 //if the exact match was empty for a group number reference the default which is 1 because the nifty query and sorting above
491 // if we generated an error, create an error return response
493 return $this->_handleError($err);
496 // otherwise, we create the right response
497 // with the state name
498 return new xmlrpcresp(new xmlrpcval($retval,"string"));
503 function x12idtype($m) {
507 $obj= $m->getparam(0);
508 $key = $obj->getval();
510 $obj= $m->getparam(1);
511 $payerkey = $obj->getval();
513 $obj= $m->getparam(2);
514 $providerkey = $obj->getval();
516 //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)
517 $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";
519 $db = $GLOBALS['adodb']['db'];
520 $results = $db->Execute($sql);
524 $err = $db->ErrorMsg();
527 while (!$results->EOF
) {
528 $vals[] = $results->fields
['x12_id_type'];
529 $results->MoveNext();
533 //if there is an exact match or not match and only the default then set it here
534 if (!empty($vals[0])) {
538 //if the exact match was empty for a provider number reference the default which is 1 because the nifty query and sorting above
542 // if we generated an error, create an error return response
544 return $this->_handleError($err);
547 // otherwise, we create the right response
548 // with the state name
549 return new xmlrpcresp(new xmlrpcval($retval));
558 $obj= $m->getparam(0);
559 $key = $obj->getval();
561 $sql = "SELECT * FROM facility where billing_location = 1";
563 $db = $GLOBALS['adodb']['db'];
564 $results = $db->Execute($sql);
568 $err = $db->ErrorMsg();
571 if (!$results->EOF
) {
572 $retval = $results->fields
['federal_ein'];
577 // if we generated an error, create an error return response
579 return $this->_handleError($err);
582 // otherwise, we create the right response
583 // with the state name
584 return new xmlrpcresp(new xmlrpcval($retval));
591 //'FreeB.FBPractice.Name' => \&FreeB_FBPractice_Name,
592 //'FreeB.FBPractice.StreetAddress' => \&FreeB_FBPractice_StreetAddress,
593 //'FreeB.FBPractice.City' => \&FreeB_FBPractice_City,
594 //'FreeB.FBPractice.State' => \&FreeB_FBPractice_State,
595 //'FreeB.FBPractice.Zipcode' => \&FreeB_FBPractice_Zipcode,
596 //'FreeB.FBPractice.PhoneCountry' => \&FreeB_FBPractice_PhoneCountry,
597 //'FreeB.FBPractice.PhoneExtension' => \&FreeB_FBPractice_PhoneExtension,
598 //'FreeB.FBPractice.PhoneNumber' => \&FreeB_FBPractice_PhoneNumber,
599 //'FreeB.FBPractice.PhoneArea' => \&FreeB_FBPractice_PhoneArea,
600 //'FreeB.FBPractice.isAcceptsAssignment' => \&FreeB_FBPractice_isAcceptsAssignment,
601 //'FreeB.FBPractice.PracticeID' => \&FreeB_FBPractice_PracticeID,
602 //'FreeB.FBPractice.GroupID' => \&FreeB_FBPractice_GroupID,
603 //'FreeB.FBPractice.TIN' => \&FreeB_FBPractice_TIN,
604 //'FreeB.FBPractice.X12IdType' => \&FreeB_FBPractice_X12IdType,
605 //'FreeB.FBPractice.X12Id' => \&FreeB_FBPractice_X12Id,