fixed bug in setting pid
[openemr.git] / library / freeb / Practice.class.php
blob5d50bc53d5e61871191e4e115eeff61cd55fc5e1
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("practiceid", array( "name" => "FreeB.FBPractice.PracticeID",
42 "sig" => array(XMLRPCSTRING,XMLRPCINT,XMLRPCINT,XMLRPCINT),
43 "doc" => ""));
44 $this->_addFunc("groupid", array( "name" => "FreeB.FBPractice.GroupID",
45 "sig" => array(XMLRPCSTRING,XMLRPCINT,XMLRPCINT,XMLRPCINT),
46 "doc" => ""));
47 $this->_addFunc("x12idtype", array( "name" => "FreeB.FBPractice.X12IdType",
48 "sig" => array(XMLRPCSTRING,XMLRPCINT,XMLRPCINT,XMLRPCINT),
49 "doc" => ""));
50 $this->_addFunc("x12id", array( "name" => "FreeB.FBPractice.X12Id",
51 "sig" => array(XMLRPCSTRING,XMLRPCINT,XMLRPCINT),
52 "doc" => ""));
56 function name($m) {
58 $err="";
60 $obj= $m->getparam(0);
61 $key = $obj->getval();
63 $sql = "SELECT * FROM facility where billing_location = '1'";
64 //echo $sql;
65 $db = $GLOBALS['adodb']['db'];
66 $results = $db->Execute($sql);
68 if (!$results) {
69 $err = $db->ErrorMsg();
71 else {
72 if (!$results->EOF) {
73 $retval = $results->fields['name'];
77 // if we generated an error, create an error return response
78 if ($err) {
79 return $this->_handleError($err);
81 else {
82 // otherwise, we create the right response
83 // with the state name
84 return new xmlrpcresp(new xmlrpcval($retval,""));
88 function streetaddress($m) {
90 $err="";
92 $obj= $m->getparam(0);
93 $key = $obj->getval();
95 $sql = "SELECT * FROM facility where billing_location = '1'";
96 //echo $sql;
97 $db = $GLOBALS['adodb']['db'];
98 $results = $db->Execute($sql);
100 if (!$results) {
101 $err = $db->ErrorMsg();
103 else {
104 if (!$results->EOF) {
105 $retval = $results->fields['street'];
109 // if we generated an error, create an error return response
110 if ($err) {
111 return $this->_handleError($err);
113 else {
114 // otherwise, we create the right response
115 // with the state name
116 return new xmlrpcresp(new xmlrpcval($retval,"string"));
121 function city($m) {
123 $err="";
125 $obj= $m->getparam(0);
126 $key = $obj->getval();
128 $sql = "SELECT * FROM facility where billing_location = '1'";
129 //echo $sql;
130 $db = $GLOBALS['adodb']['db'];
131 $results = $db->Execute($sql);
133 if (!$results) {
134 $err = $db->ErrorMsg();
136 else {
137 if (!$results->EOF) {
138 $retval = $results->fields['city'];
142 // if we generated an error, create an error return response
143 if ($err) {
144 return $this->_handleError($err);
146 else {
147 // otherwise, we create the right response
148 // with the state name
149 return new xmlrpcresp(new xmlrpcval($retval,"string"));
153 function state($m) {
155 $err="";
157 $obj= $m->getparam(0);
158 $key = $obj->getval();
160 $sql = "SELECT * FROM facility where billing_location = '1'";
161 //echo $sql;
162 $db = $GLOBALS['adodb']['db'];
163 $results = $db->Execute($sql);
165 if (!$results) {
166 $err = $db->ErrorMsg();
168 else {
169 if (!$results->EOF) {
170 $retval = $results->fields['state'];
174 // if we generated an error, create an error return response
175 if ($err) {
176 return $this->_handleError($err);
178 else {
179 // otherwise, we create the right response
180 // with the state name
181 return new xmlrpcresp(new xmlrpcval($retval,"string"));
185 function zipcode($m) {
187 $err="";
189 $obj= $m->getparam(0);
190 $key = $obj->getval();
192 $sql = "SELECT * FROM facility where billing_location = '1'";
193 //echo $sql;
194 $db = $GLOBALS['adodb']['db'];
195 $results = $db->Execute($sql);
197 if (!$results) {
198 $err = $db->ErrorMsg();
200 else {
201 if (!$results->EOF) {
202 $retval = $results->fields['postal_code'];
206 // if we generated an error, create an error return response
207 if ($err) {
208 return $this->_handleError($err);
210 else {
211 // otherwise, we create the right response
212 // with the state name
213 return new xmlrpcresp(new xmlrpcval($retval,"string"));
216 function phonecountry($m) {
218 $err="";
220 $pkey = "1";
222 // if we generated an error, create an error return response
223 if ($err) {
224 return $this->_handleError($err);
226 else {
227 // otherwise, we create the right response
228 // with the state name
229 return new xmlrpcresp(new xmlrpcval($pkey));
233 function phoneextension($m) {
235 $err="";
237 //unimplemented by OpenEMR
238 $pkey = "";
240 // if we generated an error, create an error return response
241 if ($err) {
242 return $this->_handleError($err);
244 else {
245 // otherwise, we create the right response
246 // with the state name
247 return new xmlrpcresp(new xmlrpcval($pkey));
251 function phonearea($m) {
253 $err="";
255 $obj= $m->getparam(0);
256 $key = $obj->getval();
258 $sql = "SELECT * FROM facility where billing_location = '1'";
259 //echo $sql;
260 $db = $GLOBALS['adodb']['db'];
261 $results = $db->Execute($sql);
263 if (!$results) {
264 $err = $db->ErrorMsg();
266 else {
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
276 if ($err) {
277 return $this->_handleError($err);
279 else {
280 // otherwise, we create the right response
281 // with the state name
282 return new xmlrpcresp(new xmlrpcval($retval,"string"));
286 function phonenumber($m) {
288 $err="";
290 $obj= $m->getparam(0);
291 $key = $obj->getval();
293 $sql = "SELECT * FROM facility where billing_location = '1'";
294 //echo $sql;
295 $db = $GLOBALS['adodb']['db'];
296 $results = $db->Execute($sql);
298 if (!$results) {
299 $err = $db->ErrorMsg();
301 else {
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
312 if ($err) {
313 return $this->_handleError($err);
315 else {
316 // otherwise, we create the right response
317 // with the state name
318 return new xmlrpcresp(new xmlrpcval($retval,"string"));
322 function isacceptsassignment($m) {
324 $err="";
326 $obj= $m->getparam(0);
327 $key = $obj->getval();
329 $sql = "SELECT * FROM facility where billing_location = '1'";
330 //echo $sql;
331 $db = $GLOBALS['adodb']['db'];
332 $results = $db->Execute($sql);
334 if (!$results) {
335 $err = $db->ErrorMsg();
337 else {
338 if (!$results->EOF) {
339 $retval = $results->fields['accepts_assignment'];
343 // if we generated an error, create an error return response
344 if ($err) {
345 return $this->_handleError($err);
347 else {
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
361 function tin($m) {
363 $err="";
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";
375 //echo $sql;
376 $db = $GLOBALS['adodb']['db'];
377 $results = $db->Execute($sql);
379 $vals = array();
380 if (!$results) {
381 $err = $db->ErrorMsg();
383 else {
384 if (!$results->EOF) {
385 $retval = $results->fields['federal_ein'];
390 // if we generated an error, create an error return response
391 if ($err) {
392 return $this->_handleError($err);
394 else {
395 // otherwise, we create the right response
396 // with the state name
397 return new xmlrpcresp(new xmlrpcval($retval,"string"));
402 function practiceid($m) {
404 $err="";
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";
417 //echo $sql;
418 $db = $GLOBALS['adodb']['db'];
419 $results = $db->Execute($sql);
421 $vals = array();
422 if (!$results) {
423 $err = $db->ErrorMsg();
425 else {
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])) {
434 $retval = $vals[0];
436 else {
437 //if the exact match was empty for a provider number reference the default which is 1 because the nifty query and sorting above
438 $retval = $vals[1];
441 // if we generated an error, create an error return response
442 if ($err) {
443 return $this->_handleError($err);
445 else {
446 // otherwise, we create the right response
447 // with the state name
448 return new xmlrpcresp(new xmlrpcval($retval,"string"));
452 function groupid($m) {
454 $err="";
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";
467 //echo $sql;
468 $db = $GLOBALS['adodb']['db'];
469 $results = $db->Execute($sql);
471 $vals = array();
472 if (!$results) {
473 $err = $db->ErrorMsg();
475 else {
476 while (!$results->EOF) {
477 $vals[] = $results->fields['group_number'];
478 $results->MoveNext();
482 if (!empty($vals[0])) {
483 $retval = $vals[0];
485 else {
486 //if the exact match was empty for a group number reference the default which is 1 because the nifty query and sorting above
487 $retval = $vals[1];
491 // if we generated an error, create an error return response
492 if ($err) {
493 return $this->_handleError($err);
495 else {
496 // otherwise, we create the right response
497 // with the state name
498 return new xmlrpcresp(new xmlrpcval($retval,"string"));
503 function x12idtype($m) {
505 $err="";
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";
518 //echo $sql;
519 $db = $GLOBALS['adodb']['db'];
520 $results = $db->Execute($sql);
522 $vals = array();
523 if (!$results) {
524 $err = $db->ErrorMsg();
526 else {
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])) {
535 $retval = $vals[0];
537 else {
538 //if the exact match was empty for a provider number reference the default which is 1 because the nifty query and sorting above
539 $retval = $vals[1];
542 // if we generated an error, create an error return response
543 if ($err) {
544 return $this->_handleError($err);
546 else {
547 // otherwise, we create the right response
548 // with the state name
549 return new xmlrpcresp(new xmlrpcval($retval));
553 function x12id($m) {
555 $err="";
558 $obj= $m->getparam(0);
559 $key = $obj->getval();
561 $sql = "SELECT * FROM facility where billing_location = 1";
562 //echo $sql;
563 $db = $GLOBALS['adodb']['db'];
564 $results = $db->Execute($sql);
566 $vals = array();
567 if (!$results) {
568 $err = $db->ErrorMsg();
570 else {
571 if (!$results->EOF) {
572 $retval = $results->fields['federal_ein'];
577 // if we generated an error, create an error return response
578 if ($err) {
579 return $this->_handleError($err);
581 else {
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,