minor bug fix
[openemr.git] / library / freeb / ClearingHouse.class.php
blobdac3d6898ecc4467f3db18e7f8cf8bd3a6ff3486
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" => ""));
49 function name($m) {
50 $err="";
52 //val zero is deprecated and is the facility identifier
53 //val two should be the procedure key, or put another way an id in the billing able
54 //trim due to ugly perl string cast hack
55 $obj= $m->getparam(1);
56 $key = trim($obj->getval());
58 $db = $GLOBALS['adodb']['db'];
60 $sql = "SELECT x.name FROM billing AS b " .
61 "LEFT JOIN x12_partners AS x ON x.id = b.x12_partner_id " .
62 "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) {
89 $err="";
91 $obj= $m->getparam(0);
92 $key = $obj->getval();
94 $sql = "SELECT * FROM facility where billing_location = '1'";
95 //echo $sql;
96 $db = $GLOBALS['adodb']['db'];
97 $results = $db->Execute($sql);
99 if (!$results) {
100 $err = $db->ErrorMsg();
102 else {
103 if (!$results->EOF) {
104 $retval = $results->fields['street'];
107 // if we generated an error, create an error return response
108 if ($err) {
109 return $this->_handleError($err);
111 else {
112 // otherwise, we create the right response
113 // with the state name
114 return new xmlrpcresp(new xmlrpcval($retval));
118 function city($m) {
119 $err="";
121 $obj= $m->getparam(0);
122 $key = $obj->getval();
124 $sql = "SELECT * FROM facility where billing_location = '1'";
125 //echo $sql;
126 $db = $GLOBALS['adodb']['db'];
127 $results = $db->Execute($sql);
129 if (!$results) {
130 $err = $db->ErrorMsg();
132 else {
133 if (!$results->EOF) {
134 $retval = $results->fields['city'];
138 // if we generated an error, create an error return response
139 if ($err) {
140 return $this->_handleError($err);
142 else {
143 // otherwise, we create the right response
144 // with the state name
145 return new xmlrpcresp(new xmlrpcval($retval));
149 function state($m) {
150 $err="";
152 $obj= $m->getparam(0);
153 $key = $obj->getval();
155 $sql = "SELECT * FROM facility where billing_location = '1'";
156 //echo $sql;
157 $db = $GLOBALS['adodb']['db'];
158 $results = $db->Execute($sql);
160 if (!$results) {
161 $err = $db->ErrorMsg();
163 else {
164 if (!$results->EOF) {
165 $retval = $results->fields['state'];
169 // if we generated an error, create an error return response
170 if ($err) {
171 return $this->_handleError($err);
173 else {
174 // otherwise, we create the right response
175 // with the state name
176 return new xmlrpcresp(new xmlrpcval($retval));
180 function zipcode($m) {
181 $err="";
183 $obj= $m->getparam(0);
184 $key = $obj->getval();
186 $sql = "SELECT * FROM facility where billing_location = '1'";
187 //echo $sql;
188 $db = $GLOBALS['adodb']['db'];
189 $results = $db->Execute($sql);
191 if (!$results) {
192 $err = $db->ErrorMsg();
194 else {
195 if (!$results->EOF) {
196 $retval = $results->fields['postal_code'];
200 // if we generated an error, create an error return response
201 if ($err) {
202 return $this->_handleError($err);
204 else {
205 // otherwise, we create the right response
206 // with the state name
207 return new xmlrpcresp(new xmlrpcval($retval));
211 function phonecountry($m) {
212 $err="";
214 $pkey = "1";
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($pkey));
227 function phoneextension($m) {
228 $err="";
230 $pkey = "";
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 phonearea($m) {
244 $err="";
246 $obj= $m->getparam(0);
247 $key = $obj->getval();
249 $sql = "SELECT * FROM facility where billing_location = '1'";
250 //echo $sql;
251 $db = $GLOBALS['adodb']['db'];
252 $results = $db->Execute($sql);
254 if (!$results) {
255 $err = $db->ErrorMsg();
257 else {
258 if (!$results->EOF) {
259 $retval = $results->fields['phone'];
263 $phone_parts = array();
264 // preg_match("/^\((.*?)\)\s(.*?)\-(.*?)$/",$retval,$phone_parts);
265 preg_match("/(\d\d\d)\D*(\d\d\d)\D*(\d\d\d\d)/",$retval,$phone_parts);
266 $retval = $phone_parts[1];
268 // if we generated an error, create an error return response
269 if ($err) {
270 return $this->_handleError($err);
272 else {
273 // otherwise, we create the right response
274 // with the state name
275 return new xmlrpcresp(new xmlrpcval($retval));
279 function phonenumber($m) {
280 $err="";
282 $obj= $m->getparam(0);
283 $key = $obj->getval();
285 $sql = "SELECT * FROM facility where billing_location = '1'";
286 //echo $sql;
287 $db = $GLOBALS['adodb']['db'];
288 $results = $db->Execute($sql);
290 if (!$results) {
291 $err = $db->ErrorMsg();
293 else {
294 if (!$results->EOF) {
295 $retval = $results->fields['phone'];
299 $phone_parts = array();
300 // preg_match("/^\((.*?)\)\s(.*?)\-(.*?)$/",$retval,$phone_parts);
301 preg_match("/(\d\d\d)\D*(\d\d\d)\D*(\d\d\d\d)/",$retval,$phone_parts);
302 $retval = $phone_parts[2] . "-" . $phone_parts[3];
304 // if we generated an error, create an error return response
305 if ($err) {
306 return $this->_handleError($err);
308 else {
309 // otherwise, we create the right response
310 // with the state name
311 return new xmlrpcresp(new xmlrpcval($retval));
315 function etin($m) {
316 $err="";
318 //val zero is deprecated and is the facility identifier
319 //val two should be the procedure key, or put another way an id in the billing able
320 //trim due to ugly perl string cast hack
321 $obj= $m->getparam(1);
322 $key = trim($obj->getval());
324 $db = $GLOBALS['adodb']['db'];
326 $sql = "SELECT x.id_number FROM billing AS b " .
327 "LEFT JOIN x12_partners AS x ON x.id = b.x12_partner_id " .
328 "WHERE b.id = " . $db->qstr($key) ;
329 //echo $sql;
331 $results = $db->Execute($sql);
333 $vals = array();
334 if (!$results) {
335 $err = $db->ErrorMsg();
337 else {
338 if (!$results->EOF) {
339 $retval = $results->fields['id_number'];
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));
354 function x12gsreceiverid($m) {
355 $err="";
357 //val zero is deprecated and is the facility identifier
358 //val two should be the procedure key, or put another way an id in the billing able
359 //trim due to ugly perl string cast hack
360 $obj= $m->getparam(1);
361 $key = trim($obj->getval());
363 $db = $GLOBALS['adodb']['db'];
365 $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) ;
366 //echo $sql;
368 $results = $db->Execute($sql);
370 $vals = array();
371 if (!$results) {
372 $err = $db->ErrorMsg();
374 else {
375 if (!$results->EOF) {
376 $retval = $results->fields['x12_receiver_id'];
380 while (strlen($retval) < 15) {
381 $retval .= " ";
384 // if we generated an error, create an error return response
385 if ($err) {
386 return $this->_handleError($err);
388 else {
389 // otherwise, we create the right response
390 // with the state name
391 return new xmlrpcresp(new xmlrpcval($retval));
395 function x12gssenderid($m) {
396 $err="";
398 //val zero is deprecated and is the facility identifier
399 //val two should be the procedure key, or put another way an id in the billing able
400 //trim due to ugly perl string cast hack
401 $obj= $m->getparam(1);
402 $key = trim($obj->getval());
404 $db = $GLOBALS['adodb']['db'];
406 $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) ;
407 //echo $sql;
409 $results = $db->Execute($sql);
411 $vals = array();
412 if (!$results) {
413 $err = $db->ErrorMsg();
415 else {
416 if (!$results->EOF) {
417 $retval = $results->fields['x12_sender_id'];
421 while (strlen($retval) < 15) {
422 $retval .= " ";
424 // if we generated an error, create an error return response
425 if ($err) {
426 return $this->_handleError($err);
428 else {
429 // otherwise, we create the right response
430 // with the state name
431 return new xmlrpcresp(new xmlrpcval($retval));
435 function x12gsversionstring($m) {
436 $err="";
438 //val zero is deprecated and is the facility identifier
439 $obj= $m->getparam(0);
440 $key = $obj->getval();
442 $db = $GLOBALS['adodb']['db'];
444 $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);
445 //echo $sql;
447 $results = $db->Execute($sql);
449 $vals = array();
450 if (!$results) {
451 $err = $db->ErrorMsg();
453 else {
454 if (!$results->EOF) {
455 $retval = $results->fields['x12_version'];
458 // if we generated an error, create an error return response
459 if ($err) {
460 return $this->_handleError($err);
462 else {
463 // otherwise, we create the right response
464 // with the state name
465 return new xmlrpcresp(new xmlrpcval($retval));
472 //'FreeB.FBClearingHouse.Name' => \&FreeB_FBClearingHouse_Name,
473 //'FreeB.FBClearingHouse.StreetAddress' => \&FreeB_FBClearingHouse_StreetAddress,
474 //'FreeB.FBClearingHouse.City' => \&FreeB_FBClearingHouse_City,
475 //'FreeB.FBClearingHouse.State' => \&FreeB_FBClearingHouse_State,
476 //'FreeB.FBClearingHouse.Zipcode' => \&FreeB_FBClearingHouse_Zipcode,
477 //'FreeB.FBClearingHouse.PhoneCountry' => \&FreeB_FBClearingHouse_PhoneCountry,
478 //'FreeB.FBClearingHouse.PhoneExtension' => \&FreeB_FBClearingHouse_PhoneExtension,
479 //'FreeB.FBClearingHouse.PhoneArea' => \&FreeB_FBClearingHouse_PhoneArea,
480 //'FreeB.FBClearingHouse.PhoneNumber' => \&FreeB_FBClearingHouse_PhoneNumber,
481 //'FreeB.FBClearingHouse.ETIN' => \&FreeB_FBClearingHouse_ETIN,
482 //'FreeB.FBClearingHouse.X12GSReceiverID' => \&FreeB_FBClearingHouse_X12GSReceiverID,
483 //'FreeB.FBClearingHouse.X12GSSenderID' => \&FreeB_FBClearingHouse_X12GSSenderID,