corrected logic error
[openemr.git] / library / freeb / ClearingHouse.class.php
blobf25e0a0d0c8b1a28f66726604680d6767efbd6a4
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 preg_match("/(\d\d\d)\D*(\d\d\d)\D*(\d\d\d\d)/",$retval,$phone_parts);
272 $retval = $phone_parts[1];
274 // if we generated an error, create an error return response
275 if ($err) {
276 return $this->_handleError($err);
278 else {
279 // otherwise, we create the right response
280 // with the state name
281 return new xmlrpcresp(new xmlrpcval($retval));
284 function phonenumber($m) {
286 $err="";
288 $obj= $m->getparam(0);
289 $key = $obj->getval();
291 $sql = "SELECT * FROM facility where billing_location = '1'";
292 //echo $sql;
293 $db = $GLOBALS['adodb']['db'];
294 $results = $db->Execute($sql);
296 if (!$results) {
297 $err = $db->ErrorMsg();
299 else {
300 if (!$results->EOF) {
301 $retval = $results->fields['phone'];
305 $phone_parts = array();
306 // preg_match("/^\((.*?)\)\s(.*?)\-(.*?)$/",$retval,$phone_parts);
307 preg_match("/(\d\d\d)\D*(\d\d\d)\D*(\d\d\d\d)/",$retval,$phone_parts);
308 $retval = $phone_parts[2] . "-" . $phone_parts[3];
310 // if we generated an error, create an error return response
311 if ($err) {
312 return $this->_handleError($err);
314 else {
315 // otherwise, we create the right response
316 // with the state name
317 return new xmlrpcresp(new xmlrpcval($retval));
320 function etin($m) {
322 $err="";
324 //val zero is deprecated and is the facility identifier
325 //val two should be the procedure key, or put another way an id in the billing able
326 //trim due to ugly perl string cast hack
327 $obj= $m->getparam(1);
328 $key = trim($obj->getval());
330 $db = $GLOBALS['adodb']['db'];
332 $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) ;
333 //echo $sql;
335 $results = $db->Execute($sql);
337 $vals = array();
338 if (!$results) {
339 $err = $db->ErrorMsg();
341 else {
342 if (!$results->EOF) {
343 $retval = $results->fields['id_number'];
347 // if we generated an error, create an error return response
348 if ($err) {
349 return $this->_handleError($err);
351 else {
352 // otherwise, we create the right response
353 // with the state name
354 return new xmlrpcresp(new xmlrpcval($retval));
357 function x12gsreceiverid($m) {
359 $err="";
361 //val zero is deprecated and is the facility identifier
362 //val two should be the procedure key, or put another way an id in the billing able
363 //trim due to ugly perl string cast hack
364 $obj= $m->getparam(1);
365 $key = trim($obj->getval());
367 $db = $GLOBALS['adodb']['db'];
369 $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) ;
370 //echo $sql;
372 $results = $db->Execute($sql);
374 $vals = array();
375 if (!$results) {
376 $err = $db->ErrorMsg();
378 else {
379 if (!$results->EOF) {
380 $retval = $results->fields['x12_receiver_id'];
384 while (strlen($retval) < 15) {
385 $retval .= " ";
388 // if we generated an error, create an error return response
389 if ($err) {
390 return $this->_handleError($err);
392 else {
393 // otherwise, we create the right response
394 // with the state name
395 return new xmlrpcresp(new xmlrpcval($retval));
399 function x12gssenderid($m) {
401 $err="";
403 //val zero is deprecated and is the facility identifier
404 //val two should be the procedure key, or put another way an id in the billing able
405 //trim due to ugly perl string cast hack
406 $obj= $m->getparam(1);
407 $key = trim($obj->getval());
409 $db = $GLOBALS['adodb']['db'];
411 $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) ;
412 //echo $sql;
414 $results = $db->Execute($sql);
416 $vals = array();
417 if (!$results) {
418 $err = $db->ErrorMsg();
420 else {
421 if (!$results->EOF) {
422 $retval = $results->fields['x12_sender_id'];
426 while (strlen($retval) < 15) {
427 $retval .= " ";
429 // if we generated an error, create an error return response
430 if ($err) {
431 return $this->_handleError($err);
433 else {
434 // otherwise, we create the right response
435 // with the state name
436 return new xmlrpcresp(new xmlrpcval($retval));
441 function x12gsversionstring($m) {
443 $err="";
445 //val zero is deprecated and is the facility identifier
446 $obj= $m->getparam(0);
447 $key = $obj->getval();
449 $db = $GLOBALS['adodb']['db'];
451 $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);
452 //echo $sql;
454 $results = $db->Execute($sql);
456 $vals = array();
457 if (!$results) {
458 $err = $db->ErrorMsg();
460 else {
461 if (!$results->EOF) {
462 $retval = $results->fields['x12_version'];
465 // if we generated an error, create an error return response
466 if ($err) {
467 return $this->_handleError($err);
469 else {
470 // otherwise, we create the right response
471 // with the state name
472 return new xmlrpcresp(new xmlrpcval($retval));
478 //'FreeB.FBClearingHouse.Name' => \&FreeB_FBClearingHouse_Name,
479 //'FreeB.FBClearingHouse.StreetAddress' => \&FreeB_FBClearingHouse_StreetAddress,
480 //'FreeB.FBClearingHouse.City' => \&FreeB_FBClearingHouse_City,
481 //'FreeB.FBClearingHouse.State' => \&FreeB_FBClearingHouse_State,
482 //'FreeB.FBClearingHouse.Zipcode' => \&FreeB_FBClearingHouse_Zipcode,
483 //'FreeB.FBClearingHouse.PhoneCountry' => \&FreeB_FBClearingHouse_PhoneCountry,
484 //'FreeB.FBClearingHouse.PhoneExtension' => \&FreeB_FBClearingHouse_PhoneExtension,
485 //'FreeB.FBClearingHouse.PhoneArea' => \&FreeB_FBClearingHouse_PhoneArea,
486 //'FreeB.FBClearingHouse.PhoneNumber' => \&FreeB_FBClearingHouse_PhoneNumber,
487 //'FreeB.FBClearingHouse.ETIN' => \&FreeB_FBClearingHouse_ETIN,
488 //'FreeB.FBClearingHouse.X12GSReceiverID' => \&FreeB_FBClearingHouse_X12GSReceiverID,
489 //'FreeB.FBClearingHouse.X12GSSenderID' => \&FreeB_FBClearingHouse_X12GSSenderID,