Added support for repeating events like "2nd Tuesday" or "Last Friday" of the month.
[openemr.git] / library / freeb / Facility.class.php
blobe1ba94e0f4be25fee1af6e068dcb4a02960e635f
1 <?php
2 require_once("DataObjectBase.class.php");
3 require_once("xmlrpc.inc");
5 class Facility Extends DataObjectBase {
7 function Facility() {
8 $this->_addFunc("name", array( "name" => "FreeB.FBFacility.Name",
9 "sig" => array(XMLRPCSTRING,XMLRPCINT),
10 "doc" => ""));
11 $this->_addFunc("streetaddress", array( "name" => "FreeB.FBFacility.StreetAddress",
12 "sig" => array(XMLRPCSTRING,XMLRPCINT),
13 "doc" => ""));
14 $this->_addFunc("city", array( "name" => "FreeB.FBFacility.City",
15 "sig" => array(XMLRPCSTRING,XMLRPCINT),
16 "doc" => ""));
17 $this->_addFunc("state", array( "name" => "FreeB.FBFacility.State",
18 "sig" => array(XMLRPCSTRING,XMLRPCINT),
19 "doc" => ""));
20 $this->_addFunc("zipcode", array( "name" => "FreeB.FBFacility.Zipcode",
21 "sig" => array(XMLRPCSTRING,XMLRPCINT),
22 "doc" => ""));
23 $this->_addFunc("phonecountry", array( "name" => "FreeB.FBFacility.PhoneCountry",
24 "sig" => array(XMLRPCSTRING,XMLRPCINT),
25 "doc" => ""));
26 $this->_addFunc("phoneextension", array( "name" => "FreeB.FBFacility.PhoneExtension",
27 "sig" => array(XMLRPCSTRING,XMLRPCINT),
28 "doc" => ""));
29 $this->_addFunc("phonearea", array( "name" => "FreeB.FBFacility.PhoneArea",
30 "sig" => array(XMLRPCSTRING,XMLRPCINT),
31 "doc" => ""));
32 $this->_addFunc("phonenumber", array( "name" => "FreeB.FBFacility.PhoneNumber",
33 "sig" => array(XMLRPCSTRING,XMLRPCINT),
34 "doc" => ""));
35 $this->_addFunc("x12code", array( "name" => "FreeB.FBFacility.X12Code",
36 "sig" => array(XMLRPCSTRING,XMLRPCINT,XMLRPCINT),
37 "doc" => ""));
38 $this->_addFunc("hcfacode", array( "name" => "FreeB.FBFacility.HCFACode",
39 "sig" => array(XMLRPCSTRING,XMLRPCINT),
40 "doc" => ""));
41 $this->_addFunc("cliacode", array( "name" => "FreeB.FBFacility.CLIACode",
42 "sig" => array(XMLRPCSTRING,XMLRPCINT),
43 "doc" => ""));
44 $this->_addFunc("npi", array( "name" => "FreeB.FBFacility.NPI",
45 "sig" => array(XMLRPCSTRING,XMLRPCINT),
46 "doc" => ""));
50 function name($m) {
52 $err="";
54 $retval = "";
55 $obj= $m->getparam(0);
56 $key = $obj->getval();
58 $sql = "SELECT * FROM facility where id = '" . $key ."'";
59 //echo $sql;
60 $db = $GLOBALS['adodb']['db'];
61 $results = $db->Execute($sql);
63 if (!$results) {
64 $err = $db->ErrorMsg();
66 else {
67 if (!$results->EOF) {
68 $retval = $results->fields['name'];
72 // if we generated an error, create an error return response
73 if ($err) {
74 return $this->_handleError($err);
76 else {
77 // otherwise, we create the right response
78 // with the state name
79 return new xmlrpcresp(new xmlrpcval($retval,"string"));
83 function streetaddress($m) {
85 $err="";
87 $retval = "";
88 $obj= $m->getparam(0);
89 $key = $obj->getval();
91 $sql = "SELECT * FROM facility where id = '" . $key ."'";
92 //echo $sql;
93 $db = $GLOBALS['adodb']['db'];
94 $results = $db->Execute($sql);
96 if (!$results) {
97 $err = $db->ErrorMsg();
99 else {
100 if (!$results->EOF) {
101 $retval = $results->fields['street'];
105 // if we generated an error, create an error return response
106 if ($err) {
107 return $this->_handleError($err);
109 else {
110 // otherwise, we create the right response
111 // with the state name
112 return new xmlrpcresp(new xmlrpcval($retval,"string"));
117 function city($m) {
119 $err="";
121 $retval = "";
122 $obj= $m->getparam(0);
123 $key = $obj->getval();
125 $sql = "SELECT * FROM facility where id = '" . $key ."'";
126 //echo $sql;
127 $db = $GLOBALS['adodb']['db'];
128 $results = $db->Execute($sql);
130 if (!$results) {
131 $err = $db->ErrorMsg();
133 else {
134 if (!$results->EOF) {
135 $retval = $results->fields['city'];
139 // if we generated an error, create an error return response
140 if ($err) {
141 return $this->_handleError($err);
143 else {
144 // otherwise, we create the right response
145 // with the state name
146 return new xmlrpcresp(new xmlrpcval($retval,"string"));
149 function state($m) {
151 $err="";
153 $retval = "";
154 $obj= $m->getparam(0);
155 $key = $obj->getval();
157 $sql = "SELECT * FROM facility where id = '" . $key ."'";
158 //echo $sql;
159 $db = $GLOBALS['adodb']['db'];
160 $results = $db->Execute($sql);
162 if (!$results) {
163 $err = $db->ErrorMsg();
165 else {
166 if (!$results->EOF) {
167 $retval = $results->fields['state'];
171 // if we generated an error, create an error return response
172 if ($err) {
173 return $this->_handleError($err);
175 else {
176 // otherwise, we create the right response
177 // with the state name
178 return new xmlrpcresp(new xmlrpcval($retval,"string"));
181 function zipcode($m) {
183 $err="";
185 $retval = "";
186 $obj= $m->getparam(0);
187 $key = $obj->getval();
189 $sql = "SELECT * FROM facility where id = '" . $key ."'";
190 //echo $sql;
191 $db = $GLOBALS['adodb']['db'];
192 $results = $db->Execute($sql);
194 if (!$results) {
195 $err = $db->ErrorMsg();
197 else {
198 if (!$results->EOF) {
199 $retval = $results->fields['postal_code'];
203 // if we generated an error, create an error return response
204 if ($err) {
205 return $this->_handleError($err);
207 else {
208 // otherwise, we create the right response
209 // with the state name
210 return new xmlrpcresp(new xmlrpcval($retval,"string"));
213 function phonecountry($m) {
215 $err="";
217 //OpenEMR only supports a sinlge coutry code for phones
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 //unimplemented by OpenEMR
236 $pkey = "";
238 // if we generated an error, create an error return response
239 if ($err) {
240 return $this->_handleError($err);
242 else {
243 // otherwise, we create the right response
244 // with the state name
245 return new xmlrpcresp(new xmlrpcval($pkey));
249 function phonearea($m) {
251 $err="";
253 $retval = "";
254 $obj= $m->getparam(0);
255 $key = $obj->getval();
257 $sql = "SELECT * FROM facility where id = '" . $key ."'";
258 //echo $sql;
259 $db = $GLOBALS['adodb']['db'];
260 $results = $db->Execute($sql);
262 if (!$results) {
263 $err = $db->ErrorMsg();
265 else {
266 if (!$results->EOF) {
267 $retval = $results->fields['phone'];
271 $phone_parts = array();
272 // preg_match("/^\((.*?)\)\s(.*?)\-(.*?)$/",$retval,$phone_parts);
273 preg_match("/(\d\d\d)\D*(\d\d\d)\D*(\d\d\d\d)/",$retval,$phone_parts);
274 $retval = $phone_parts[1];
276 // if we generated an error, create an error return response
277 if ($err) {
278 return $this->_handleError($err);
280 else {
281 // otherwise, we create the right response
282 // with the state name
283 return new xmlrpcresp(new xmlrpcval($retval,"string"));
287 function phonenumber($m) {
289 $err="";
291 $retval = "";
292 $obj= $m->getparam(0);
293 $key = $obj->getval();
295 $sql = "SELECT * FROM facility where id = '" . $key ."'";
296 //echo $sql;
297 $db = $GLOBALS['adodb']['db'];
298 $results = $db->Execute($sql);
300 if (!$results) {
301 $err = $db->ErrorMsg();
303 else {
304 if (!$results->EOF) {
305 $retval = $results->fields['phone'];
309 $phone_parts = array();
310 // preg_match("/^\((.*?)\)\s(.*?)\-(.*?)$/",$retval,$phone_parts);
311 preg_match("/(\d\d\d)\D*(\d\d\d)\D*(\d\d\d\d)/",$retval,$phone_parts);
312 $retval = $phone_parts[2] . "-" . $phone_parts[3];
314 // if we generated an error, create an error return response
315 if ($err) {
316 return $this->_handleError($err);
318 else {
319 // otherwise, we create the right response
320 // with the state name
321 return new xmlrpcresp(new xmlrpcval($pkey));
325 function x12code($m) {
327 $err="";
329 $retval = "";
330 $obj= $m->getparam(0);
331 $key = $obj->getval();
333 $sql = "SELECT * FROM facility where id = '" . $key ."'";
334 //echo $sql;
335 $db = $GLOBALS['adodb']['db'];
336 $results = $db->Execute($sql);
338 if (!$results) {
339 $err = $db->ErrorMsg();
341 else {
342 if (!$results->EOF) {
343 $retval = $results->fields['pos_code'];
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));
358 function hcfacode($m) {
360 $err="";
362 $retval = "";
363 $obj= $m->getparam(0);
364 $key = $obj->getval();
366 $sql = "SELECT * FROM facility where id = '" . $key ."'";
367 //echo $sql;
368 $db = $GLOBALS['adodb']['db'];
369 $results = $db->Execute($sql);
371 if (!$results) {
372 $err = $db->ErrorMsg();
374 else {
375 if (!$results->EOF) {
376 $retval = $results->fields['pos_code'];
380 // if we generated an error, create an error return response
381 if ($err) {
382 return $this->_handleError($err);
384 else {
385 // otherwise, we create the right response
386 // with the state name
387 return new xmlrpcresp(new xmlrpcval($retval,"i4"));
391 function cliacode($m) {
393 $err="";
395 $retval = "";
396 $obj= $m->getparam(0);
397 $key = $obj->getval();
399 $sql = "SELECT domain_identifier FROM facility where id = '" . $key ."'";
400 $db = $GLOBALS['adodb']['db'];
401 $results = $db->Execute($sql);
403 if (!$results) {
404 $err = $db->ErrorMsg();
406 else {
407 if (!$results->EOF) {
408 $retval = $results->fields['domain_identifier'];
412 // if we generated an error, create an error return response
413 if ($err) {
414 return $this->_handleError($err);
416 else {
417 return new xmlrpcresp(new xmlrpcval($retval,"string"));
420 function npi($m) {
422 $err="";
424 $retval = "";
425 $obj= $m->getparam(0);
426 $key = $obj->getval();
428 $sql = "SELECT * FROM facility where id = '" . $key ."'";
429 //echo $sql;
430 $db = $GLOBALS['adodb']['db'];
431 $results = $db->Execute($sql);
433 if (!$results) {
434 $err = $db->ErrorMsg();
436 else {
437 if (!$results->EOF) {
438 $retval = $results->fields['facility_npi'];
442 // if we generated an error, create an error return response
443 if ($err) {
444 return $this->_handleError($err);
446 else {
447 // otherwise, we create the right response
448 // with the state name
449 return new xmlrpcresp(new xmlrpcval($retval,"string"));
456 //'FreeB.FBFacility.Name' => \&FreeB_FBFacility_Name,
457 //'FreeB.FBFacility.StreetAddress' => \&FreeB_FBFacility_StreetAddress,
458 //'FreeB.FBFacility.City' => \&FreeB_FBFacility_City,
459 //'FreeB.FBFacility.State' => \&FreeB_FBFacility_State,
460 //'FreeB.FBFacility.Zipcode' => \&FreeB_FBFacility_Zipcode,
461 //'FreeB.FBFacility.PhoneNumber' => \&FreeB_FBFacility_PhoneNumber,
462 //'FreeB.FBFacility.PhoneCountry' => \&FreeB_FBFacility_PhoneCountry,
463 //'FreeB.FBFacility.PhoneExtension' => \&FreeB_FBFacility_PhoneExtension,
464 //'FreeB.FBFacility.PhoneArea' => \&FreeB_FBFacility_PhoneArea,
465 //'FreeB.FBFacility.X12Code' => \&FreeB_FBFacility_X12Code,
466 //'FreeB.FBFacility.HCFACode' => \&FreeB_FBFacility_HCFACode,
467 //'FreeB.FBFacility.NPI => \&FreeB_FBFacility_NPI