file table.sql was added on branch rel-310 on 2009-07-31 19:39:59 +0000
[openemr.git] / library / freeb / ClearingHouse.class.php
blobd6b1c37c5999402a0c0fe3ce4a3b94fac493835b
1 <?php
2 require_once("DataObjectBase.class.php");
3 require_once("xmlrpc.inc");
5 class ClearingHouse Extends DataObjectBase {
7 function ClearingHouse() {
8 $this->_addFunc("name", array( "name" => "FreeB.FBClearingHouse.Name",
9 "sig" => array(XMLRPCSTRING,XMLRPCINT,XMLRPCSTRING),
10 "doc" => ""));
11 $this->_addFunc("streetaddress", array( "name" => "FreeB.FBClearingHouse.StreetAddress",
12 "sig" => array(XMLRPCSTRING,XMLRPCINT),
13 "doc" => ""));
14 $this->_addFunc("city", array( "name" => "FreeB.FBClearingHouse.City",
15 "sig" => array(XMLRPCSTRING,XMLRPCINT),
16 "doc" => ""));
17 $this->_addFunc("state", array( "name" => "FreeB.FBClearingHouse.State",
18 "sig" => array(XMLRPCSTRING,XMLRPCINT),
19 "doc" => ""));
20 $this->_addFunc("zipcode", array( "name" => "FreeB.FBClearingHouse.Zipcode",
21 "sig" => array(XMLRPCSTRING,XMLRPCINT),
22 "doc" => ""));
23 $this->_addFunc("phonecountry", array( "name" => "FreeB.FBClearingHouse.PhoneCountry",
24 "sig" => array(XMLRPCSTRING,XMLRPCINT),
25 "doc" => ""));
26 $this->_addFunc("phoneextension", array( "name" => "FreeB.FBClearingHouse.PhoneExtension",
27 "sig" => array(XMLRPCSTRING,XMLRPCINT),
28 "doc" => ""));
29 $this->_addFunc("phonearea", array( "name" => "FreeB.FBClearingHouse.PhoneArea",
30 "sig" => array(XMLRPCSTRING,XMLRPCINT),
31 "doc" => ""));
32 $this->_addFunc("phonenumber", array( "name" => "FreeB.FBClearingHouse.PhoneNumber",
33 "sig" => array(XMLRPCSTRING,XMLRPCINT),
34 "doc" => ""));
35 $this->_addFunc("etin", array( "name" => "FreeB.FBClearingHouse.ETIN",
36 "sig" => array(XMLRPCSTRING,XMLRPCINT,XMLRPCSTRING),
37 "doc" => ""));
38 $this->_addFunc("x12gsreceiverid", array( "name" => "FreeB.FBClearingHouse.X12GSReceiverID",
39 "sig" => array(XMLRPCSTRING,XMLRPCINT,XMLRPCSTRING),
40 "doc" => ""));
41 $this->_addFunc("x12gssenderid", array( "name" => "FreeB.FBClearingHouse.X12GSSenderID",
42 "sig" => array(XMLRPCSTRING,XMLRPCINT,XMLRPCSTRING),
43 "doc" => ""));
44 $this->_addFunc("x12gsversionstring", array( "name" => "FreeB.FBClearingHouse.X12GSVersionString",
45 "sig" => array(XMLRPCSTRING, XMLRPCINT),
46 "doc" => ""));
50 function name($m) {
52 $err="";
54 //val zero is deprecated and is the facility identifier
55 //val two should be the procedure key, or put another way an id in the billing able
56 //trim due to ugly perl string cast hack
57 $obj= $m->getparam(1);
58 $key = trim($obj->getval());
60 $db = $GLOBALS['adodb']['db'];
62 $sql = "SELECT x.name FROM billing as b LEFT JOIN x12_partners as x on x.id = b.x12_partner_id where b.id= " .$db->qstr($key) ;
63 //echo $sql;
65 $results = $db->Execute($sql);
67 $vals = array();
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'];
108 // if we generated an error, create an error return response
109 if ($err) {
110 return $this->_handleError($err);
112 else {
113 // otherwise, we create the right response
114 // with the state name
115 return new xmlrpcresp(new xmlrpcval($retval));
120 function city($m) {
122 $err="";
124 $obj= $m->getparam(0);
125 $key = $obj->getval();
127 $sql = "SELECT * FROM facility where billing_location = '1'";
128 //echo $sql;
129 $db = $GLOBALS['adodb']['db'];
130 $results = $db->Execute($sql);
132 if (!$results) {
133 $err = $db->ErrorMsg();
135 else {
136 if (!$results->EOF) {
137 $retval = $results->fields['city'];
141 // if we generated an error, create an error return response
142 if ($err) {
143 return $this->_handleError($err);
145 else {
146 // otherwise, we create the right response
147 // with the state name
148 return new xmlrpcresp(new xmlrpcval($retval));
151 function state($m) {
153 $err="";
155 $obj= $m->getparam(0);
156 $key = $obj->getval();
158 $sql = "SELECT * FROM facility where billing_location = '1'";
159 //echo $sql;
160 $db = $GLOBALS['adodb']['db'];
161 $results = $db->Execute($sql);
163 if (!$results) {
164 $err = $db->ErrorMsg();
166 else {
167 if (!$results->EOF) {
168 $retval = $results->fields['state'];
172 // if we generated an error, create an error return response
173 if ($err) {
174 return $this->_handleError($err);
176 else {
177 // otherwise, we create the right response
178 // with the state name
179 return new xmlrpcresp(new xmlrpcval($retval));
183 function zipcode($m) {
185 $err="";
187 $obj= $m->getparam(0);
188 $key = $obj->getval();
190 $sql = "SELECT * FROM facility where billing_location = '1'";
191 //echo $sql;
192 $db = $GLOBALS['adodb']['db'];
193 $results = $db->Execute($sql);
195 if (!$results) {
196 $err = $db->ErrorMsg();
198 else {
199 if (!$results->EOF) {
200 $retval = $results->fields['postal_code'];
204 // if we generated an error, create an error return response
205 if ($err) {
206 return $this->_handleError($err);
208 else {
209 // otherwise, we create the right response
210 // with the state name
211 return new xmlrpcresp(new xmlrpcval($retval));
214 function phonecountry($m) {
216 $err="";
218 $pkey = "1";
220 // if we generated an error, create an error return response
221 if ($err) {
222 return $this->_handleError($err);
224 else {
225 // otherwise, we create the right response
226 // with the state name
227 return new xmlrpcresp(new xmlrpcval($pkey));
231 function phoneextension($m) {
233 $err="";
235 $pkey = "";
237 // if we generated an error, create an error return response
238 if ($err) {
239 return $this->_handleError($err);
241 else {
242 // otherwise, we create the right response
243 // with the state name
244 return new xmlrpcresp(new xmlrpcval($pkey));
248 function phonearea($m) {
250 $err="";
252 $obj= $m->getparam(0);
253 $key = $obj->getval();
255 $sql = "SELECT * FROM facility where billing_location = '1'";
256 //echo $sql;
257 $db = $GLOBALS['adodb']['db'];
258 $results = $db->Execute($sql);
260 if (!$results) {
261 $err = $db->ErrorMsg();
263 else {
264 if (!$results->EOF) {
265 $retval = $results->fields['phone'];
269 $phone_parts = array();
270 preg_match("/^\((.*?)\)\s(.*?)\-(.*?)$/",$retval,$phone_parts);
271 $retval = $phone_parts[1];
273 // if we generated an error, create an error return response
274 if ($err) {
275 return $this->_handleError($err);
277 else {
278 // otherwise, we create the right response
279 // with the state name
280 return new xmlrpcresp(new xmlrpcval($retval));
283 function phonenumber($m) {
285 $err="";
287 $obj= $m->getparam(0);
288 $key = $obj->getval();
290 $sql = "SELECT * FROM facility where billing_location = '1'";
291 //echo $sql;
292 $db = $GLOBALS['adodb']['db'];
293 $results = $db->Execute($sql);
295 if (!$results) {
296 $err = $db->ErrorMsg();
298 else {
299 if (!$results->EOF) {
300 $retval = $results->fields['phone'];
304 $phone_parts = array();
305 preg_match("/^\((.*?)\)\s(.*?)\-(.*?)$/",$retval,$phone_parts);
306 $retval = $phone_parts[2] . "-" . $phone_parts[3];
308 // if we generated an error, create an error return response
309 if ($err) {
310 return $this->_handleError($err);
312 else {
313 // otherwise, we create the right response
314 // with the state name
315 return new xmlrpcresp(new xmlrpcval($retval));
318 function etin($m) {
320 $err="";
322 //val zero is deprecated and is the facility identifier
323 //val two should be the procedure key, or put another way an id in the billing able
324 //trim due to ugly perl string cast hack
325 $obj= $m->getparam(1);
326 $key = trim($obj->getval());
328 $db = $GLOBALS['adodb']['db'];
330 $sql = "SELECT x.id_number FROM billing as b LEFT JOIN x12_partners as x on x.id = b.x12_partner_id where b.id= " .$db->qstr($key) ;
331 //echo $sql;
333 $results = $db->Execute($sql);
335 $vals = array();
336 if (!$results) {
337 $err = $db->ErrorMsg();
339 else {
340 if (!$results->EOF) {
341 $retval = $results->fields['id_number'];
345 // if we generated an error, create an error return response
346 if ($err) {
347 return $this->_handleError($err);
349 else {
350 // otherwise, we create the right response
351 // with the state name
352 return new xmlrpcresp(new xmlrpcval($retval));
355 function x12gsreceiverid($m) {
357 $err="";
359 //val zero is deprecated and is the facility identifier
360 //val two should be the procedure key, or put another way an id in the billing able
361 //trim due to ugly perl string cast hack
362 $obj= $m->getparam(1);
363 $key = trim($obj->getval());
365 $db = $GLOBALS['adodb']['db'];
367 $sql = "SELECT x.x12_receiver_id FROM billing as b LEFT JOIN x12_partners as x on x.id = b.x12_partner_id where b.id= " .$db->qstr($key) ;
368 //echo $sql;
370 $results = $db->Execute($sql);
372 $vals = array();
373 if (!$results) {
374 $err = $db->ErrorMsg();
376 else {
377 if (!$results->EOF) {
378 $retval = $results->fields['x12_receiver_id'];
382 while (strlen($retval) < 15) {
383 $retval .= " ";
386 // if we generated an error, create an error return response
387 if ($err) {
388 return $this->_handleError($err);
390 else {
391 // otherwise, we create the right response
392 // with the state name
393 return new xmlrpcresp(new xmlrpcval($retval));
397 function x12gssenderid($m) {
399 $err="";
401 //val zero is deprecated and is the facility identifier
402 //val two should be the procedure key, or put another way an id in the billing able
403 //trim due to ugly perl string cast hack
404 $obj= $m->getparam(1);
405 $key = trim($obj->getval());
407 $db = $GLOBALS['adodb']['db'];
409 $sql = "SELECT x.x12_sender_id FROM billing as b LEFT JOIN x12_partners as x on x.id = b.x12_partner_id where b.id= " .$db->qstr($key) ;
410 //echo $sql;
412 $results = $db->Execute($sql);
414 $vals = array();
415 if (!$results) {
416 $err = $db->ErrorMsg();
418 else {
419 if (!$results->EOF) {
420 $retval = $results->fields['x12_sender_id'];
424 while (strlen($retval) < 15) {
425 $retval .= " ";
427 // if we generated an error, create an error return response
428 if ($err) {
429 return $this->_handleError($err);
431 else {
432 // otherwise, we create the right response
433 // with the state name
434 return new xmlrpcresp(new xmlrpcval($retval));
439 function x12gsversionstring($m) {
441 $err="";
443 //val zero is deprecated and is the facility identifier
444 $obj= $m->getparam(0);
445 $key = $obj->getval();
447 $db = $GLOBALS['adodb']['db'];
449 $sql = "SELECT x.x12_version FROM billing AS b LEFT JOIN x12_partners as x ON x.id = b.x12_partner_id WHERE b.id= ".$db->qstr($key);
450 //echo $sql;
452 $results = $db->Execute($sql);
454 $vals = array();
455 if (!$results) {
456 $err = $db->ErrorMsg();
458 else {
459 if (!$results->EOF) {
460 $retval = $results->fields['x12_version'];
463 // if we generated an error, create an error return response
464 if ($err) {
465 return $this->_handleError($err);
467 else {
468 // otherwise, we create the right response
469 // with the state name
470 return new xmlrpcresp(new xmlrpcval($retval));
476 //'FreeB.FBClearingHouse.Name' => \&FreeB_FBClearingHouse_Name,
477 //'FreeB.FBClearingHouse.StreetAddress' => \&FreeB_FBClearingHouse_StreetAddress,
478 //'FreeB.FBClearingHouse.City' => \&FreeB_FBClearingHouse_City,
479 //'FreeB.FBClearingHouse.State' => \&FreeB_FBClearingHouse_State,
480 //'FreeB.FBClearingHouse.Zipcode' => \&FreeB_FBClearingHouse_Zipcode,
481 //'FreeB.FBClearingHouse.PhoneCountry' => \&FreeB_FBClearingHouse_PhoneCountry,
482 //'FreeB.FBClearingHouse.PhoneExtension' => \&FreeB_FBClearingHouse_PhoneExtension,
483 //'FreeB.FBClearingHouse.PhoneArea' => \&FreeB_FBClearingHouse_PhoneArea,
484 //'FreeB.FBClearingHouse.PhoneNumber' => \&FreeB_FBClearingHouse_PhoneNumber,
485 //'FreeB.FBClearingHouse.ETIN' => \&FreeB_FBClearingHouse_ETIN,
486 //'FreeB.FBClearingHouse.X12GSReceiverID' => \&FreeB_FBClearingHouse_X12GSReceiverID,
487 //'FreeB.FBClearingHouse.X12GSSenderID' => \&FreeB_FBClearingHouse_X12GSSenderID,