Removed hard coding to ICD9 for fee sheet
[openemr.git] / library / freeb / Insured.class.php
blob2d9b2a42e70424b8f6c20bc04b4a2686112a649b
1 <?php
2 require_once("DataObjectBase.class.php");
3 require_once("xmlrpc.inc");
5 class Insured Extends DataObjectBase {
7 function Insured() {
8 $this->_addFunc("firstname", array( "name" => "FreeB.FBInsured.FirstName",
9 "sig" => array(XMLRPCSTRING,XMLRPCINT),
10 "doc" => ""));
11 $this->_addFunc("middlename", array( "name" => "FreeB.FBInsured.MiddleName",
12 "sig" => array(XMLRPCSTRING,XMLRPCINT),
13 "doc" => ""));
14 $this->_addFunc("lastname", array( "name" => "FreeB.FBInsured.LastName",
15 "sig" => array(XMLRPCSTRING,XMLRPCINT),
16 "doc" => ""));
17 $this->_addFunc("id", array( "name" => "FreeB.FBInsured.ID",
18 "sig" => array(XMLRPCSTRING,XMLRPCINT),
19 "doc" => ""));
20 $this->_addFunc("dateofbirth", array( "name" => "FreeB.FBInsured.DateOfBirth",
21 "sig" => array(XMLRPCSTRING,XMLRPCINT),
22 "doc" => ""));
23 $this->_addFunc("sex", array( "name" => "FreeB.FBInsured.Sex",
24 "sig" => array(XMLRPCSTRING,XMLRPCINT),
25 "doc" => ""));
26 $this->_addFunc("groupname", array( "name" => "FreeB.FBInsured.GroupName",
27 "sig" => array(XMLRPCSTRING,XMLRPCINT),
28 "doc" => ""));
29 $this->_addFunc("groupnumber", array( "name" => "FreeB.FBInsured.GroupNumber",
30 "sig" => array(XMLRPCSTRING,XMLRPCINT),
31 "doc" => ""));
32 $this->_addFunc("isemployed", array( "name" => "FreeB.FBInsured.isEmployed",
33 "sig" => array(XMLRPCSTRING,XMLRPCINT),
34 "doc" => ""));
35 $this->_addFunc("employername", array( "name" => "FreeB.FBInsured.EmployerName",
36 "sig" => array(XMLRPCSTRING,XMLRPCINT),
37 "doc" => ""));
38 $this->_addFunc("isstudent", array( "name" => "FreeB.FBInsured.isStudent",
39 "sig" => array(XMLRPCSTRING,XMLRPCINT),
40 "doc" => ""));
41 $this->_addFunc("schoolname", array( "name" => "FreeB.FBInsured.SchoolName",
42 "sig" => array(XMLRPCSTRING,XMLRPCINT),
43 "doc" => ""));
44 $this->_addFunc("isassigning", array( "name" => "FreeB.FBInsured.isAssigning",
45 "sig" => array(XMLRPCSTRING,XMLRPCINT),
46 "doc" => ""));
47 $this->_addFunc("planname", array( "name" => "FreeB.FBInsured.PlanName",
48 "sig" => array(XMLRPCSTRING,XMLRPCINT),
49 "doc" => ""));
50 $this->_addFunc("streetaddress", array( "name" => "FreeB.FBInsured.StreetAddress",
51 "sig" => array(XMLRPCSTRING,XMLRPCINT),
52 "doc" => ""));
53 $this->_addFunc("city", array( "name" => "FreeB.FBInsured.City",
54 "sig" => array(XMLRPCSTRING,XMLRPCINT),
55 "doc" => ""));
56 $this->_addFunc("state", array( "name" => "FreeB.FBInsured.State",
57 "sig" => array(XMLRPCSTRING,XMLRPCINT),
58 "doc" => ""));
59 $this->_addFunc("zipcode", array( "name" => "FreeB.FBInsured.Zipcode",
60 "sig" => array(XMLRPCSTRING,XMLRPCINT),
61 "doc" => ""));
62 $this->_addFunc("phonecountry", array( "name" => "FreeB.FBInsured.PhoneCountry",
63 "sig" => array(XMLRPCSTRING,XMLRPCINT),
64 "doc" => ""));
65 $this->_addFunc("phoneextension", array( "name" => "FreeB.FBInsured.PhoneExtension",
66 "sig" => array(XMLRPCSTRING,XMLRPCINT),
67 "doc" => ""));
68 $this->_addFunc("phonearea", array( "name" => "FreeB.FBInsured.PhoneArea",
69 "sig" => array(XMLRPCSTRING,XMLRPCINT),
70 "doc" => ""));
71 $this->_addFunc("phonenumber", array( "name" => "FreeB.FBInsured.PhoneNumber",
72 "sig" => array(XMLRPCSTRING,XMLRPCINT),
73 "doc" => ""));
74 $this->_addFunc("payerkey", array("name" => "FreeB.FBInsured.PayerKey",
75 "sig" => array(XMLRPCSTRING,XMLRPCINT),
76 "doc" => ""));
79 function firstname($m) {
81 $err="";
83 $retval = "";
84 $obj= $m->getparam(0);
85 $key = $obj->getval();
87 $sql = "SELECT * FROM insurance_data where id = '" . $key . "'";
88 //echo $sql;
89 $db = $GLOBALS['adodb']['db'];
90 $results = $db->Execute($sql);
92 if (!$results) {
93 $err = $db->ErrorMsg();
95 else {
96 if (!$results->EOF) {
97 $retval = $results->fields['subscriber_fname'];
101 // if we generated an error, create an error return response
102 if ($err) {
103 return $this->_handleError($err);
105 else {
106 // otherwise, we create the right response
107 // with the state name
108 return new xmlrpcresp(new xmlrpcval($retval,"string"));
112 function middlename($m) {
114 $err="";
116 $retval = "";
117 $obj= $m->getparam(0);
118 $key = $obj->getval();
120 $sql = "SELECT * FROM insurance_data where id = '" . $key . "'";
121 //echo $sql;
122 $db = $GLOBALS['adodb']['db'];
123 $results = $db->Execute($sql);
125 if (!$results) {
126 $err = $db->ErrorMsg();
128 else {
129 if (!$results->EOF) {
130 $retval = $results->fields['subscriber_mname'];
134 // if we generated an error, create an error return response
135 if ($err) {
136 return $this->_handleError($err);
138 else {
139 // otherwise, we create the right response
140 // with the state name
141 return new xmlrpcresp(new xmlrpcval($retval,"string"));
145 function lastname($m) {
147 $err="";
149 $retval = "";
150 $obj= $m->getparam(0);
151 $key = $obj->getval();
153 $sql = "SELECT * FROM insurance_data where id = '" . $key . "'";
154 //echo $sql;
155 $db = $GLOBALS['adodb']['db'];
156 $results = $db->Execute($sql);
158 if (!$results) {
159 $err = $db->ErrorMsg();
161 else {
162 if (!$results->EOF) {
163 $retval = $results->fields['subscriber_lname'];
167 // if we generated an error, create an error return response
168 if ($err) {
169 return $this->_handleError($err);
171 else {
172 // otherwise, we create the right response
173 // with the state name
174 return new xmlrpcresp(new xmlrpcval($retval,"string"));
178 function id($m) {
180 $err="";
182 $retval = "";
183 $obj= $m->getparam(0);
184 $key = $obj->getval();
186 $sql = "SELECT * FROM insurance_data where id = '" . $key . "'";
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['policy_number'];
199 // if we generated an error, create an error return response
200 if ($err) {
201 return $this->_handleError($err);
203 else {
204 // otherwise, we create the right response
205 // with the state name
206 return new xmlrpcresp(new xmlrpcval($retval));
210 function dateofbirth($m) {
212 $err="";
214 $retval = "";
215 $obj= $m->getparam(0);
216 $key = $obj->getval();
218 $sql = "SELECT * FROM insurance_data where id = '" . $key . "'";
219 //echo $sql;
220 $db = $GLOBALS['adodb']['db'];
221 $results = $db->Execute($sql);
223 if (!$results) {
224 $err = $db->ErrorMsg();
226 else {
227 if (!$results->EOF) {
228 $retval = $results->fields['subscriber_DOB'];
231 if (!empty($retval)) {
232 $retval = $this->_isodate($retval);
234 else {
235 $retval = "";
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($retval,XMLRPCDATETIME));
249 function sex($m) {
251 $err="";
253 $retval = "";
254 $obj= $m->getparam(0);
255 $key = $obj->getval();
257 $sql = "SELECT * FROM insurance_data 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['subscriber_sex'];
270 if (strtolower($retval) == "male") {
271 $retval = "M";
273 elseif (strtolower($retval) == "female") {
274 $retval = "F";
277 // if we generated an error, create an error return response
278 if ($err) {
279 return $this->_handleError($err);
281 else {
282 // otherwise, we create the right response
283 // with the state name
284 return new xmlrpcresp(new xmlrpcval($retval,"string"));
290 function groupname($m) {
292 $err="";
294 $retval = "";
295 $obj= $m->getparam(0);
296 $key = $obj->getval();
298 $sql = "SELECT * FROM insurance_data where id = '" . $key . "'";
299 //echo $sql;
300 $db = $GLOBALS['adodb']['db'];
301 $results = $db->Execute($sql);
303 if (!$results) {
304 $err = $db->ErrorMsg();
306 else {
307 if (!$results->EOF) {
308 $retval = $results->fields['subscriber_employer'];
312 // if we generated an error, create an error return response
313 if ($err) {
314 return $this->_handleError($err);
316 else {
317 // otherwise, we create the right response
318 // with the state name
319 return new xmlrpcresp(new xmlrpcval($retval,"string"));
323 function groupnumber($m) {
325 $err="";
327 $retval = "";
328 $obj= $m->getparam(0);
329 $key = $obj->getval();
331 $sql = "SELECT * FROM insurance_data where id = '" . $key . "'";
332 //echo $sql;
333 $db = $GLOBALS['adodb']['db'];
334 $results = $db->Execute($sql);
336 if (!$results) {
337 $err = $db->ErrorMsg();
339 else {
340 if (!$results->EOF) {
341 $retval = $results->fields['group_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,"string"));
355 function isemployed($m) {
357 $err="";
359 $retval = "";
360 $obj= $m->getparam(0);
361 $key = $obj->getval();
363 //default to true
364 $pkey = true;
366 // if we generated an error, create an error return response
367 if ($err) {
368 return $this->_handleError($err);
370 else {
371 // otherwise, we create the right response
372 // with the state name
373 return new xmlrpcresp(new xmlrpcval($pkey,"i4"));
377 function employername($m) {
379 $err="";
381 $retval = "";
382 $obj= $m->getparam(0);
383 $key = $obj->getval();
385 $sql = "SELECT * FROM insurance_data where id = '" . $key . "'";
386 //echo $sql;
387 $db = $GLOBALS['adodb']['db'];
388 $results = $db->Execute($sql);
390 if (!$results) {
391 $err = $db->ErrorMsg();
393 else {
394 if (!$results->EOF) {
395 $retval = $results->fields['subscriber_employer'];
400 // if we generated an error, create an error return response
401 if ($err) {
402 return $this->_handleError($err);
404 else {
405 // otherwise, we create the right response
406 // with the state name
407 return new xmlrpcresp(new xmlrpcval($retval,"string"));
411 function isstudent($m) {
413 $err="";
414 //unimplemented by OpenEMR
415 $pkey = false;
417 // if we generated an error, create an error return response
418 if ($err) {
419 return $this->_handleError($err);
421 else {
422 // otherwise, we create the right response
423 // with the state name
424 return new xmlrpcresp(new xmlrpcval($pkey,"i4"));
428 function schoolname($m) {
430 $err="";
432 $sql = "SELECT * FROM insurance_data where id = '" . $key . "'";
433 //echo $sql;
434 $db = $GLOBALS['adodb']['db'];
435 $results = $db->Execute($sql);
437 if (!$results) {
438 $err = $db->ErrorMsg();
440 else {
441 if (!$results->EOF) {
442 $retval = $results->fields['subscriber_employer'];
446 // if we generated an error, create an error return response
447 if ($err) {
448 return $this->_handleError($err);
450 else {
451 // otherwise, we create the right response
452 // with the state name
453 return new xmlrpcresp(new xmlrpcval($retval,"string"));
457 function isassigning($m) {
459 $err="";
461 //defaulted to true
462 $pkey = true;
464 // if we generated an error, create an error return response
465 if ($err) {
466 return $this->_handleError($err);
468 else {
469 // otherwise, we create the right response
470 // with the state name
471 return new xmlrpcresp(new xmlrpcval($pkey,"i4"));
475 function planname($m) {
477 $err="";
479 $retval = "";
480 $obj= $m->getparam(0);
481 $key = $obj->getval();
483 $sql = "SELECT * FROM insurance_data where id = '" . $key . "'";
484 //echo $sql;
485 $db = $GLOBALS['adodb']['db'];
486 $results = $db->Execute($sql);
488 if (!$results) {
489 $err = $db->ErrorMsg();
491 else {
492 if (!$results->EOF) {
493 $retval = $results->fields['plan_name'];
497 // if we generated an error, create an error return response
498 if ($err) {
499 return $this->_handleError($err);
501 else {
502 // otherwise, we create the right response
503 // with the state name
504 return new xmlrpcresp(new xmlrpcval($retval,"string"));
508 function streetaddress($m) {
510 $err="";
512 $retval = "";
513 $obj= $m->getparam(0);
514 $key = $obj->getval();
516 $sql = "SELECT * FROM insurance_data where id = '" . $key . "'";
517 //echo $sql;
518 $db = $GLOBALS['adodb']['db'];
519 $results = $db->Execute($sql);
521 if (!$results) {
522 $err = $db->ErrorMsg();
524 else {
525 if (!$results->EOF) {
526 $retval = $results->fields['subscriber_street'];
530 // if we generated an error, create an error return response
531 if ($err) {
532 return $this->_handleError($err);
534 else {
535 // otherwise, we create the right response
536 // with the state name
537 return new xmlrpcresp(new xmlrpcval($retval,"string"));
542 function city($m) {
544 $err="";
546 $retval = "";
547 $obj= $m->getparam(0);
548 $key = $obj->getval();
550 $sql = "SELECT * FROM insurance_data where id = '" . $key . "'";
551 //echo $sql;
552 $db = $GLOBALS['adodb']['db'];
553 $results = $db->Execute($sql);
555 if (!$results) {
556 $err = $db->ErrorMsg();
558 else {
559 if (!$results->EOF) {
560 $retval = $results->fields['subscriber_city'];
564 // if we generated an error, create an error return response
565 if ($err) {
566 return $this->_handleError($err);
568 else {
569 // otherwise, we create the right response
570 // with the state name
571 return new xmlrpcresp(new xmlrpcval($retval,"string"));
574 function state($m) {
576 $err="";
578 $retval = "";
579 $obj= $m->getparam(0);
580 $key = $obj->getval();
582 $sql = "SELECT * FROM insurance_data where id = '" . $key . "'";
583 //echo $sql;
584 $db = $GLOBALS['adodb']['db'];
585 $results = $db->Execute($sql);
587 if (!$results) {
588 $err = $db->ErrorMsg();
590 else {
591 if (!$results->EOF) {
592 $retval = $results->fields['subscriber_state'];
596 // if we generated an error, create an error return response
597 if ($err) {
598 return $this->_handleError($err);
600 else {
601 // otherwise, we create the right response
602 // with the state name
603 return new xmlrpcresp(new xmlrpcval($retval,"string"));
606 function zipcode($m) {
608 $err="";
610 $retval = "";
611 $obj= $m->getparam(0);
612 $key = $obj->getval();
614 $sql = "SELECT * FROM insurance_data where id = '" . $key . "'";
615 //echo $sql;
616 $db = $GLOBALS['adodb']['db'];
617 $results = $db->Execute($sql);
619 if (!$results) {
620 $err = $db->ErrorMsg();
622 else {
623 if (!$results->EOF) {
624 $retval = $results->fields['subscriber_postal_code'];
627 // if we generated an error, create an error return response
628 if ($err) {
629 return $this->_handleError($err);
631 else {
632 // otherwise, we create the right response
633 // with the state name
634 return new xmlrpcresp(new xmlrpcval($retval,"string"));
637 function phonecountry($m) {
639 $err="";
640 //Unimplemented by OpenEMR
641 $retval = "";
642 // if we generated an error, create an error return response
643 if ($err) {
644 return $this->_handleError($err);
646 else {
647 // otherwise, we create the right response
648 // with the state name
649 return new xmlrpcresp(new xmlrpcval($retval,"string"));
653 function phoneextension($m) {
655 $err="";
656 //unimplemented by OpenEMR
657 $pkey = "";
659 // if we generated an error, create an error return response
660 if ($err) {
661 return $this->_handleError($err);
663 else {
664 // otherwise, we create the right response
665 // with the state name
666 return new xmlrpcresp(new xmlrpcval($pkey));
670 function phonearea($m) {
672 $err="";
674 $retval = "";
675 $obj= $m->getparam(0);
676 $key = $obj->getval();
678 $sql = "SELECT * FROM insurance_data where id = '" . $key . "'";
679 //echo $sql;
680 $db = $GLOBALS['adodb']['db'];
681 $results = $db->Execute($sql);
683 if (!$results) {
684 $err = $db->ErrorMsg();
686 else {
687 if (!$results->EOF) {
688 $retval = $results->fields['subscriber_phone'];
692 $phone_parts = array();
693 // preg_match("/^\((.*?)\)\s(.*?)\-(.*?)$/",$retval,$phone_parts);
694 preg_match("/(\d\d\d)\D*(\d\d\d)\D*(\d\d\d\d)/",$retval,$phone_parts);
695 $retval = $phone_parts[1];
697 // if we generated an error, create an error return response
698 if ($err) {
699 return $this->_handleError($err);
701 else {
702 // otherwise, we create the right response
703 // with the state name
704 return new xmlrpcresp(new xmlrpcval($retval,"string"));
707 function phonenumber($m) {
709 $err="";
711 $retval = "";
712 $obj= $m->getparam(0);
713 $key = $obj->getval();
715 $sql = "SELECT * FROM insurance_data where id = '" . $key . "'";
716 //echo $sql;
717 $db = $GLOBALS['adodb']['db'];
718 $results = $db->Execute($sql);
720 if (!$results) {
721 $err = $db->ErrorMsg();
723 else {
724 if (!$results->EOF) {
725 $retval = $results->fields['subscriber_phone'];
729 $phone_parts = array();
730 // preg_match("/^\((.*?)\)\s(.*?)\-(.*?)$/",$retval,$phone_parts);
731 preg_match("/(\d\d\d)\D*(\d\d\d)\D*(\d\d\d\d)/",$retval,$phone_parts);
732 $retval = $phone_parts[2] . "-" . $phone_parts[3];
734 // if we generated an error, create an error return response
735 if ($err) {
736 return $this->_handleError($err);
738 else {
739 // otherwise, we create the right response
740 // with the state name
741 return new xmlrpcresp(new xmlrpcval($retval,"string"));
745 function payerkey($m) {
746 $err="";
748 $pkey = "";
749 $obj= $m->getparam(0);
750 $key = $obj->getval();
752 $sql = "SELECT provider FROM insurance_data where id = '$key'";
753 $db = $GLOBALS['adodb']['db'];
754 $results = $db->Execute($sql);
756 if (!$results) {
757 $err = $db->ErrorMsg() . " $sql";
759 else {
760 if (!$results->EOF) {
761 $pkey = $results->fields['provider'];
765 if ($err) {
766 return $this->_handleError($err);
768 else {
769 return new xmlrpcresp(new xmlrpcval($pkey, "i4"));
775 //'FreeB.FBInsured.FirstName' => \&FreeB_FBInsured_FirstName,
776 //'FreeB.FBInsured.LastName' => \&FreeB_FBInsured_LastName,
777 //'FreeB.FBInsured.MiddleName' => \&FreeB_FBInsured_MiddleName,
778 //'FreeB.FBInsured.ID' => \&FreeB_FBInsured_ID,
780 //'FreeB.FBInsured.DateOfBirth' => \&FreeB_FBInsured_DateOfBirth,
781 //'FreeB.FBInsured.Sex' => \&FreeB_FBInsured_Sex,
782 //'FreeB.FBInsured.GroupName' => \&FreeB_FBInsured_GroupName,
783 //'FreeB.FBInsured.GroupNumber' => \&FreeB_FBInsured_GroupNumber,
784 //'FreeB.FBInsured.isEmployed' => \&FreeB_FBInsured_isEmployed,
785 //'FreeB.FBInsured.EmployerName' => \&FreeB_FBInsured_EmployerName,
786 //'FreeB.FBInsured.isStudent' => \&FreeB_FBInsured_isStudent,
787 //'FreeB.FBInsured.SchoolName' => \&FreeB_FBInsured_SchoolName,
788 //'FreeB.FBInsured.isAssigning' => \&FreeB_FBInsured_isAssigning,
789 //'FreeB.FBInsured.PlanName' => \&FreeB_FBInsured_PlanName,
791 //'FreeB.FBInsured.StreetAddress' => \&FreeB_FBInsured_StreetAddress,
792 //'FreeB.FBInsured.City' => \&FreeB_FBInsured_City,
793 //'FreeB.FBInsured.State' => \&FreeB_FBInsured_State,
794 //'FreeB.FBInsured.Zipcode' => \&FreeB_FBInsured_Zipcode,
795 //'FreeB.FBInsured.PhoneCountry' => \&FreeB_FBInsured_PhoneCountry,
796 //'FreeB.FBInsured.PhoneExtension' => \&FreeB_FBInsured_PhoneExtension,
797 //'FreeB.FBInsured.PhoneArea' => \&FreeB_FBInsured_PhoneArea,
798 //'FreeB.FBInsured.PhoneNumber' => \&FreeB_FBInsured_PhoneNumber,