fixed bug in setting pid
[openemr.git] / library / freeb / Patient.class.php
blob2ffbc084a073420975607f930276b95f6645428c
1 <?php
2 require_once("DataObjectBase.class.php");
3 require_once("xmlrpc.inc");
5 class Patient Extends DataObjectBase {
7 function Patient() {
9 $this->_addFunc("firstname", array( "name" => "FreeB.FBPatient.FirstName",
10 "sig" => array(XMLRPCSTRING,XMLRPCINT),
11 "doc" => ""));
12 $this->_addFunc("middlename", array( "name" => "FreeB.FBPatient.MiddleName",
13 "sig" => array(XMLRPCSTRING,XMLRPCINT),
14 "doc" => ""));
15 $this->_addFunc("lastname", array( "name" => "FreeB.FBPatient.LastName",
16 "sig" => array(XMLRPCSTRING,XMLRPCINT),
17 "doc" => ""));
18 $this->_addFunc("streetaddress", array( "name" => "FreeB.FBPatient.StreetAddress",
19 "sig" => array(XMLRPCSTRING,XMLRPCINT),
20 "doc" => ""));
21 $this->_addFunc("city", array( "name" => "FreeB.FBPatient.City",
22 "sig" => array(XMLRPCSTRING,XMLRPCINT),
23 "doc" => ""));
24 $this->_addFunc("state", array( "name" => "FreeB.FBPatient.State",
25 "sig" => array(XMLRPCSTRING,XMLRPCINT),
26 "doc" => ""));
27 $this->_addFunc("zipcode", array( "name" => "FreeB.FBPatient.Zipcode",
28 "sig" => array(XMLRPCSTRING,XMLRPCINT),
29 "doc" => ""));
30 $this->_addFunc("phonecountry", array( "name" => "FreeB.FBPatient.PhoneCountry",
31 "sig" => array(XMLRPCSTRING,XMLRPCINT),
32 "doc" => ""));
33 $this->_addFunc("phoneextension", array( "name" => "FreeB.FBPatient.PhoneExtension",
34 "sig" => array(XMLRPCSTRING,XMLRPCINT),
35 "doc" => ""));
36 $this->_addFunc("phonearea", array( "name" => "FreeB.FBPatient.PhoneArea",
37 "sig" => array(XMLRPCSTRING,XMLRPCINT),
38 "doc" => ""));
39 $this->_addFunc("phonenumber", array( "name" => "FreeB.FBPatient.PhoneNumber",
40 "sig" => array(XMLRPCSTRING,XMLRPCINT),
41 "doc" => ""));
42 $this->_addFunc("title", array( "name" => "FreeB.FBPatient.Title",
43 "sig" => array(XMLRPCSTRING,XMLRPCINT),
44 "doc" => ""));
45 $this->_addFunc("account", array( "name" => "FreeB.FBPatient.Account",
46 "sig" => array(XMLRPCSTRING,XMLRPCINT),
47 "doc" => ""));
48 $this->_addFunc("isdead", array( "name" => "FreeB.FBPatient.isDead",
49 "sig" => array(XMLRPCSTRING,XMLRPCINT),
50 "doc" => ""));
51 $this->_addFunc("dateofbirth", array( "name" => "FreeB.FBPatient.DateOfBirth",
52 "sig" => array(XMLRPCSTRING,XMLRPCINT),
53 "doc" => ""));
54 $this->_addFunc("dateofdeath", array( "name" => "FreeB.FBPatient.DateOfDeath",
55 "sig" => array(XMLRPCSTRING,XMLRPCINT),
56 "doc" => ""));
57 $this->_addFunc("sex", array( "name" => "FreeB.FBPatient.Sex",
58 "sig" => array(XMLRPCSTRING,XMLRPCINT),
59 "doc" => ""));
60 $this->_addFunc("issingle", array( "name" => "FreeB.FBPatient.isSingle",
61 "sig" => array(XMLRPCSTRING,XMLRPCINT),
62 "doc" => ""));
63 $this->_addFunc("ismarried", array( "name" => "FreeB.FBPatient.isMarried",
64 "sig" => array(XMLRPCSTRING,XMLRPCINT),
65 "doc" => ""));
66 $this->_addFunc("ismaritalotherhcfa", array( "name" => "FreeB.FBPatient.isMaritalOtherHCFA",
67 "sig" => array(XMLRPCSTRING,XMLRPCINT),
68 "doc" => ""));
69 $this->_addFunc("isemployed", array( "name" => "FreeB.FBPatient.isEmployed",
70 "sig" => array(XMLRPCSTRING,XMLRPCINT),
71 "doc" => ""));
72 $this->_addFunc("isfulltimestudent", array( "name" => "FreeB.FBPatient.isFullTimeStudent",
73 "sig" => array(XMLRPCSTRING,XMLRPCINT),
74 "doc" => ""));
75 $this->_addFunc("isparttimestudent", array( "name" => "FreeB.FBPatient.isPartTimeStudent",
76 "sig" => array(XMLRPCSTRING,XMLRPCINT),
77 "doc" => ""));
78 $this->_addFunc("ischildofinsured", array( "name" => "FreeB.FBPatient.isChildOfInsured",
79 "sig" => array(XMLRPCSTRING,XMLRPCINT,XMLRPCINT),
80 "doc" => ""));
81 $this->_addFunc("ishusbandofinsured", array( "name" => "FreeB.FBPatient.isHusbandOfInsured",
82 "sig" => array(XMLRPCSTRING,XMLRPCINT,XMLRPCINT),
83 "doc" => ""));
84 $this->_addFunc("iswifeofinsured", array( "name" => "FreeB.FBPatient.isWifeOfInsured",
85 "sig" => array(XMLRPCSTRING,XMLRPCINT,XMLRPCINT),
86 "doc" => ""));
87 $this->_addFunc("isdivorceeofinsured", array( "name" => "FreeB.FBPatient.isDivorceeOfInsured",
88 "sig" => array(XMLRPCSTRING,XMLRPCINT,XMLRPCINT),
89 "doc" => ""));
90 $this->_addFunc("isselfofinsured", array( "name" => "FreeB.FBPatient.isSelfOfInsured",
91 "sig" => array(XMLRPCSTRING,XMLRPCINT,XMLRPCINT),
92 "doc" => ""));
93 $this->_addFunc("isotherofinsured", array( "name" => "FreeB.FBPatient.isOtherOfInsured",
94 "sig" => array(XMLRPCSTRING,XMLRPCINT,XMLRPCINT),
95 "doc" => ""));
96 $this->_addFunc("socialsecuritynumber", array( "name" => "FreeB.FBPatient.SocialSecurityNumber",
97 "sig" => array(XMLRPCSTRING,XMLRPCINT),
98 "doc" => ""));
99 $this->_addFunc("coveragecount", array( "name" => "FreeB.FBPatient.CoverageCount",
100 "sig" => array(XMLRPCSTRING,XMLRPCINT),
101 "doc" => ""));
102 $this->_addFunc("x12insuredrelationship", array( "name" => "FreeB.FBPatient.X12InsuredRelationship",
103 "sig" => array(XMLRPCSTRING,XMLRPCINT,XMLRPCINT),
104 "doc" => ""));
105 $this->_addFunc("ispregnant", array( "name" => "FreeB.FBPatient.isPregnant",
106 "sig" => array(XMLRPCSTRING,XMLRPCINT),
107 "doc" => ""));
111 function firstname($m) {
113 $err="";
115 $retval = "";
116 $obj= $m->getparam(0);
117 $key = $obj->getval();
119 $sql = "SELECT * FROM patient_data where pid = '" . $key . "'";
120 //echo $sql;
121 $db = $GLOBALS['adodb']['db'];
122 $results = $db->Execute($sql);
124 if (!$results) {
125 $err = $db->ErrorMsg();
127 else {
128 if (!$results->EOF) {
129 $retval = $results->fields['fname'];
133 // if we generated an error, create an error return response
134 if ($err) {
135 return $this->_handleError($err);
137 else {
138 // otherwise, we create the right response
139 // with the state name
140 return new xmlrpcresp(new xmlrpcval($retval,"string"));
144 function middlename($m) {
146 $err="";
148 $retval = "";
149 $obj= $m->getparam(0);
150 $key = $obj->getval();
152 $sql = "SELECT * FROM patient_data where pid = '" . $key . "'";
153 //echo $sql;
154 $db = $GLOBALS['adodb']['db'];
155 $results = $db->Execute($sql);
157 if (!$results) {
158 $err = $db->ErrorMsg();
160 else {
161 if (!$results->EOF) {
162 $retval = $results->fields['mname'];
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 lastname($m) {
180 $err="";
182 $retval = "";
183 $obj= $m->getparam(0);
184 $key = $obj->getval();
186 $sql = "SELECT * FROM patient_data where pid = '" . $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['lname'];
201 // if we generated an error, create an error return response
202 if ($err) {
203 return $this->_handleError($err);
205 else {
206 // otherwise, we create the right response
207 // with the state name
208 return new xmlrpcresp(new xmlrpcval($retval,"string"));
212 function streetaddress($m) {
214 $err="";
216 $retval = "";
217 $obj= $m->getparam(0);
218 $key = $obj->getval();
220 $sql = "SELECT * FROM patient_data where pid = '" . $_SESSION['patient_id'] . "'";
221 //echo $sql;
222 $db = $GLOBALS['adodb']['db'];
223 $results = $db->Execute($sql);
225 if (!$results) {
226 $err = $db->ErrorMsg();
228 else {
229 if (!$results->EOF) {
230 $retval = $results->fields['street'];
235 // if we generated an error, create an error return response
236 if ($err) {
237 return $this->_handleError($err);
239 else {
240 // otherwise, we create the right response
241 // with the state name
242 return new xmlrpcresp(new xmlrpcval($retval,"string"));
247 function city($m) {
249 $err="";
251 $retval = "";
252 $obj= $m->getparam(0);
253 $key = $obj->getval();
255 $sql = "SELECT * FROM patient_data where pid = '" . $_SESSION['patient_id'] . "'";
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['city'];
270 // if we generated an error, create an error return response
271 if ($err) {
272 return $this->_handleError($err);
274 else {
275 // otherwise, we create the right response
276 // with the state name
277 return new xmlrpcresp(new xmlrpcval($retval,"string"));
281 function state($m) {
283 $err="";
285 $retval = "";
286 $obj= $m->getparam(0);
287 $key = $obj->getval();
289 $sql = "SELECT * FROM patient_data where pid = '" . $_SESSION['patient_id'] . "'";
290 //echo $sql;
291 $db = $GLOBALS['adodb']['db'];
292 $results = $db->Execute($sql);
294 if (!$results) {
295 $err = $db->ErrorMsg();
297 else {
298 if (!$results->EOF) {
299 $retval = $results->fields['state'];
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,"string"));
315 function zipcode($m) {
317 $err="";
319 $retval = "";
320 $obj= $m->getparam(0);
321 $key = $obj->getval();
323 $sql = "SELECT * FROM patient_data where pid = '" . $_SESSION['patient_id'] . "'";
324 //echo $sql;
325 $db = $GLOBALS['adodb']['db'];
326 $results = $db->Execute($sql);
328 if (!$results) {
329 $err = $db->ErrorMsg();
331 else {
332 if (!$results->EOF) {
333 $retval = $results->fields['postal_code'];
338 // if we generated an error, create an error return response
339 if ($err) {
340 return $this->_handleError($err);
342 else {
343 // otherwise, we create the right response
344 // with the state name
345 return new xmlrpcresp(new xmlrpcval($retval,"string"));
349 function phonecountry($m) {
351 $err="";
353 //OpenEMR only supports US country code
354 $pkey = "1";
356 // if we generated an error, create an error return response
357 if ($err) {
358 return $this->_handleError($err);
360 else {
361 // otherwise, we create the right response
362 // with the state name
363 return new xmlrpcresp(new xmlrpcval($pkey));
367 function phoneextension($m) {
369 $err="";
371 //unimplemented by openemr
372 $pkey = "";
374 // if we generated an error, create an error return response
375 if ($err) {
376 return $this->_handleError($err);
378 else {
379 // otherwise, we create the right response
380 // with the state name
381 return new xmlrpcresp(new xmlrpcval($pkey));
385 function phonearea($m) {
387 $err="";
389 $retval = "";
390 $obj= $m->getparam(0);
391 $key = $obj->getval();
393 $sql = "SELECT * FROM patient_data where pid = '" . $_SESSION['patient_id'] . "'";
394 //echo $sql;
395 $db = $GLOBALS['adodb']['db'];
396 $results = $db->Execute($sql);
398 if (!$results) {
399 $err = $db->ErrorMsg();
401 else {
402 if (!$results->EOF) {
403 $retval = $results->fields['phone_home'];
407 $phone_parts = array();
408 preg_match("/^\((.*?)\)\s(.*?)\-(.*?)$/",$retval,$phone_parts);
409 $retval = $phone_parts[1];
412 // if we generated an error, create an error return response
413 if ($err) {
414 return $this->_handleError($err);
416 else {
417 // otherwise, we create the right response
418 // with the state name
419 return new xmlrpcresp(new xmlrpcval($retval,"string"));
423 function phonenumber($m) {
425 $err="";
427 $retval = "";
428 $obj= $m->getparam(0);
429 $key = $obj->getval();
431 $sql = "SELECT * FROM patient_data where pid = '" . $_SESSION['patient_id'] . "'";
432 //echo $sql;
433 $db = $GLOBALS['adodb']['db'];
434 $results = $db->Execute($sql);
436 if (!$results) {
437 $err = $db->ErrorMsg();
439 else {
440 if (!$results->EOF) {
441 $retval = $results->fields['phone_home'];
445 $phone_parts = array();
446 preg_match("/^\((.*?)\)\s(.*?)\-(.*?)$/",$retval,$phone_parts);
447 $retval = $phone_parts[2] . "-" . $phone_parts[3];
449 // if we generated an error, create an error return response
450 if ($err) {
451 return $this->_handleError($err);
453 else {
454 // otherwise, we create the right response
455 // with the state name
456 return new xmlrpcresp(new xmlrpcval($retval,"string"));
461 function title($m) {
463 $err="";
465 $retval = "";
466 $obj= $m->getparam(0);
467 $key = $obj->getval();
469 $sql = "SELECT * FROM patient_data where pid = '" . $_SESSION['patient_id'] . "'";
470 //echo $sql;
471 $db = $GLOBALS['adodb']['db'];
472 $results = $db->Execute($sql);
474 if (!$results) {
475 $err = $db->ErrorMsg();
477 else {
478 if (!$results->EOF) {
479 $retval = $results->fields['title'];
484 // if we generated an error, create an error return response
485 if ($err) {
486 return $this->_handleError($err);
488 else {
489 // otherwise, we create the right response
490 // with the state name
491 return new xmlrpcresp(new xmlrpcval($retval,"string"));
495 function account($m) {
497 $err="";
500 $retval = $_SESSION['patient_id'] . "-" . $_SESSION['billkey'];
502 // if we generated an error, create an error return response
503 if ($err) {
504 return $this->_handleError($err);
506 else {
507 // otherwise, we create the right response
508 // with the state name
509 return new xmlrpcresp(new xmlrpcval($retval));
513 function isdead($m) {
515 $err="";
517 //unimplemented by OpenEMR
518 $pkey = false;
520 // if we generated an error, create an error return response
521 if ($err) {
522 return $this->_handleError($err);
524 else {
525 // otherwise, we create the right response
526 // with the state name
527 return new xmlrpcresp(new xmlrpcval($pkey,"i4"));
531 function dateofbirth($m) {
533 $err="";
535 $retval = "";
536 $obj= $m->getparam(0);
537 $key = $obj->getval();
539 $sql = "SELECT * FROM patient_data where pid = '" . $_SESSION['patient_id'] . "'";
540 //echo $sql;
541 $db = $GLOBALS['adodb']['db'];
542 $results = $db->Execute($sql);
544 if (!$results) {
545 $err = $db->ErrorMsg();
547 else {
548 if (!$results->EOF) {
549 $retval = $results->fields['DOB'];
554 $retval = $this->_isodate($retval);
556 // if we generated an error, create an error return response
557 if ($err) {
558 return $this->_handleError($err);
560 else {
561 // otherwise, we create the right response
562 // with the state name
563 return new xmlrpcresp(new xmlrpcval($retval,XMLRPCDATETIME));
567 function dateofdeath($m) {
569 $err="";
571 //Unimplimented by OpenEMR
572 $pkey = "";
574 // if we generated an error, create an error return response
575 if ($err) {
576 return $this->_handleError($err);
578 else {
579 // otherwise, we create the right response
580 // with the state name
581 return new xmlrpcresp(new xmlrpcval($pkey,XMLRPCDATETIME));
585 function sex($m) {
587 $err="";
589 $retval = "";
590 $obj= $m->getparam(0);
591 $key = $obj->getval();
593 $sql = "SELECT * FROM patient_data where pid = '" . $key . "'";
594 //echo $sql;
595 $db = $GLOBALS['adodb']['db'];
596 $results = $db->Execute($sql);
598 if (!$results) {
599 $err = $db->ErrorMsg();
601 else {
602 if (!$results->EOF) {
603 $retval = $results->fields['sex'];
606 if (strtolower($retval) == "male") {
607 $retval = "M";
609 elseif (strtolower($retval) == "female") {
610 $retval = "F";
613 // if we generated an error, create an error return response
614 if ($err) {
615 return $this->_handleError($err);
617 else {
618 // otherwise, we create the right response
619 // with the state name
620 return new xmlrpcresp(new xmlrpcval($retval,"string"));
626 function issingle($m) {
628 $err="";
630 $retval = "";
631 $obj= $m->getparam(0);
632 $key = $obj->getval();
634 $sql = "SELECT * FROM patient_data where pid = '" . $_SESSION['patient_id'] . "'";
635 //echo $sql;
636 $db = $GLOBALS['adodb']['db'];
637 $results = $db->Execute($sql);
639 if (!$results) {
640 $err = $db->ErrorMsg();
642 else {
643 if (!$results->EOF) {
644 $retval = $results->fields['status'];
648 if ($retval == "single") {
649 $retval = true;
651 else {
652 $retval = false;
655 // if we generated an error, create an error return response
656 if ($err) {
657 return $this->_handleError($err);
659 else {
660 // otherwise, we create the right response
661 // with the state name
662 return new xmlrpcresp(new xmlrpcval($retval,"i4"));
666 function ismarried($m) {
668 $err="";
670 $retval = "";
671 $obj= $m->getparam(0);
672 $key = $obj->getval();
674 $sql = "SELECT * FROM patient_data where pid = '" . $_SESSION['patient_id'] . "'";
675 //echo $sql;
676 $db = $GLOBALS['adodb']['db'];
677 $results = $db->Execute($sql);
679 if (!$results) {
680 $err = $db->ErrorMsg();
682 else {
683 if (!$results->EOF) {
684 $retval = $results->fields['status'];
688 if ($retval == "married") {
689 $retval = true;
691 else {
692 $retval = false;
696 // if we generated an error, create an error return response
697 if ($err) {
698 return $this->_handleError($err);
700 else {
701 // otherwise, we create the right response
702 // with the state name
703 return new xmlrpcresp(new xmlrpcval($retval,"i4"));
707 function ismaritalotherhcfa($m) {
709 $err="";
711 $retval = "";
712 $obj= $m->getparam(0);
713 $key = $obj->getval();
715 $sql = "SELECT * FROM patient_data where pid = '" . $_SESSION['patient_id'] . "'";
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['status'];
729 if ($retval == "domestic partner") {
730 $retval = true;
732 else {
733 $retval = false;
737 // if we generated an error, create an error return response
738 if ($err) {
739 return $this->_handleError($err);
741 else {
742 // otherwise, we create the right response
743 // with the state name
744 return new xmlrpcresp(new xmlrpcval($retval,"i4"));
748 function isemployed($m) {
750 $err="";
752 $retval = "";
753 $obj= $m->getparam(0);
754 $key = $obj->getval();
756 $sql = "SELECT * FROM patient_data where pid = '" . $_SESSION['patient_id'] . "'";
757 //echo $sql;
758 $db = $GLOBALS['adodb']['db'];
759 $results = $db->Execute($sql);
761 if (!$results) {
762 $err = $db->ErrorMsg();
764 else {
765 if (!$results->EOF) {
766 $retval = $results->fields['occupation'];
770 if ($retval == "Unemployed" || empty($retval)) {
771 $retval = false;
773 else {
774 $retval = true;
778 // if we generated an error, create an error return response
779 if ($err) {
780 return $this->_handleError($err);
782 else {
783 // otherwise, we create the right response
784 // with the state name
785 return new xmlrpcresp(new xmlrpcval($retval,"i4"));
789 function isfulltimestudent($m) {
791 $err="";
793 $retval = "";
794 $obj= $m->getparam(0);
795 $key = $obj->getval();
797 $sql = "SELECT * FROM patient_data where pid = '" . $_SESSION['patient_id'] . "'";
798 //echo $sql;
799 $db = $GLOBALS['adodb']['db'];
800 $results = $db->Execute($sql);
802 if (!$results) {
803 $err = $db->ErrorMsg();
805 else {
806 if (!$results->EOF) {
807 $retval = $results->fields['occupation'];
811 if (strtolower($retval) == "student") {
812 $retval = true;
814 else {
815 $retval = false;
818 // if we generated an error, create an error return response
819 if ($err) {
820 return $this->_handleError($err);
822 else {
823 // otherwise, we create the right response
824 // with the state name
825 return new xmlrpcresp(new xmlrpcval($retval,"i4"));
829 function isparttimestudent($m) {
831 $err="";
833 $retval = "";
834 $obj= $m->getparam(0);
835 $key = $obj->getval();
837 $sql = "SELECT * FROM patient_data where pid = '" . $_SESSION['patient_id'] . "'";
838 //echo $sql;
839 $db = $GLOBALS['adodb']['db'];
840 $results = $db->Execute($sql);
842 if (!$results) {
843 $err = $db->ErrorMsg();
845 else {
846 if (!$results->EOF) {
847 $retval = $results->fields['occupation'];
851 if (strtolower($retval) == "pt student") {
852 $retval = true;
854 else {
855 $retval = false;
859 // if we generated an error, create an error return response
860 if ($err) {
861 return $this->_handleError($err);
863 else {
864 // otherwise, we create the right response
865 // with the state name
866 return new xmlrpcresp(new xmlrpcval($retval,"i4"));
870 function ischildofinsured($m) {
872 $err="";
874 $retval = "";
875 $obj= $m->getparam(0);
876 $key = $obj->getval();
877 $obj= $m->getparam(1);
878 $key2 = $obj->getval();
879 $sql = "SELECT * FROM insurance_data where pid = '" . $key . "' AND id = '" . $key2 . "'";
880 //echo $sql;
881 $db = $GLOBALS['adodb']['db'];
882 $results = $db->Execute($sql);
884 if (!$results) {
885 $err = $db->ErrorMsg();
887 else {
888 if (!$results->EOF) {
889 $retval = $results->fields['subscriber_relationship'];
893 if (strtolower($retval) == "child") {
894 $retval = true;
896 else {
897 $retval = false;
900 // if we generated an error, create an error return response
901 if ($err) {
902 return $this->_handleError($err);
904 else {
905 // otherwise, we create the right response
906 // with the state name
907 return new xmlrpcresp(new xmlrpcval($retval,"i4"));
911 function ishusbandofinsured($m) {
913 $err="";
915 $retval = "";
916 $obj= $m->getparam(0);
917 $key = $obj->getval();
918 $obj= $m->getparam(1);
919 $key2 = $obj->getval();
920 $sql = "SELECT * FROM insurance_data where pid = '" . $key . "' AND id = '" . $key2 . "'";
921 //echo $sql;
922 $db = $GLOBALS['adodb']['db'];
923 $results = $db->Execute($sql);
925 if (!$results) {
926 $err = $db->ErrorMsg();
928 else {
929 if (!$results->EOF) {
930 $retval = $results->fields['subscriber_relationship'];
934 if (strtolower($retval) == "spouse") {
935 $retval = true;
937 else {
938 $retval = false;
942 // if we generated an error, create an error return response
943 if ($err) {
944 return $this->_handleError($err);
946 else {
947 // otherwise, we create the right response
948 // with the state name
949 return new xmlrpcresp(new xmlrpcval($retval,"i4"));
953 function iswifeofinsured($m) {
955 $err="";
957 $retval = "";
958 $obj= $m->getparam(0);
959 $key = $obj->getval();
960 $obj= $m->getparam(1);
961 $key2 = $obj->getval();
962 $sql = "SELECT * FROM insurance_data where pid = '" . $key . "' AND id = '" . $key2 . "'";
963 //echo $sql;
964 $db = $GLOBALS['adodb']['db'];
965 $results = $db->Execute($sql);
967 if (!$results) {
968 $err = $db->ErrorMsg();
970 else {
971 if (!$results->EOF) {
972 $retval = $results->fields['subscriber_relationship'];
976 if (strtolower($retval) == "spouse" && $results->fields['sex'] == "male") {
977 $retval = true;
979 else {
980 $retval = false;
983 $retval = false;
984 // if we generated an error, create an error return response
985 if ($err) {
986 return $this->_handleError($err);
988 else {
989 // otherwise, we create the right response
990 // with the state name
991 return new xmlrpcresp(new xmlrpcval($retval,"i4"));
995 function isdivorceeofinsured($m) {
997 $err="";
999 $retval = "";
1000 $obj= $m->getparam(0);
1001 $key = $obj->getval();
1002 $obj= $m->getparam(1);
1003 $key2 = $obj->getval();
1004 $sql = "SELECT * FROM insurance_data where pid = '" . $key . "' AND id = '" . $key2 . "'";
1005 //echo $sql;
1006 $db = $GLOBALS['adodb']['db'];
1007 $results = $db->Execute($sql);
1009 if (!$results) {
1010 $err = $db->ErrorMsg();
1012 else {
1013 if (!$results->EOF) {
1014 $retval = $results->fields['subscriber_relationship'];
1018 if (strtolower($retval) == "divorcee") {
1019 $retval = true;
1021 else {
1022 $retval = false;
1026 // if we generated an error, create an error return response
1027 if ($err) {
1028 return $this->_handleError($err);
1030 else {
1031 // otherwise, we create the right response
1032 // with the state name
1033 return new xmlrpcresp(new xmlrpcval($retval,"i4"));
1037 function isselfofinsured($m) {
1039 $err="";
1041 $retval = "";
1042 $obj= $m->getparam(0);
1043 $key = $obj->getval();
1044 $obj= $m->getparam(1);
1045 $key2 = $obj->getval();
1046 $sql = "SELECT * FROM insurance_data where pid = '" . $key . "' AND id = '" . $key2 . "'";
1047 //echo $sql;
1048 $db = $GLOBALS['adodb']['db'];
1049 $results = $db->Execute($sql);
1051 if (!$results) {
1052 $err = $db->ErrorMsg();
1054 else {
1055 if (!$results->EOF) {
1056 $retval = $results->fields['subscriber_relationship'];
1060 if (strtolower($retval) == "self") {
1061 $retval = true;
1063 else {
1064 $retval = false;
1068 // if we generated an error, create an error return response
1069 if ($err) {
1070 return $this->_handleError($err);
1072 else {
1073 // otherwise, we create the right response
1074 // with the state name
1075 return new xmlrpcresp(new xmlrpcval($retval,"i4"));
1079 function isotherofinsured($m) {
1081 $err="";
1083 $retval = "";
1084 $obj= $m->getparam(0);
1085 $key = $obj->getval();
1086 $obj= $m->getparam(1);
1087 $key2 = $obj->getval();
1088 $sql = "SELECT * FROM insurance_data where pid = '" . $key . "' AND id = '" . $key2 . "'";
1089 //echo $sql;
1090 $db = $GLOBALS['adodb']['db'];
1091 $results = $db->Execute($sql);
1093 if (!$results) {
1094 $err = $db->ErrorMsg();
1096 else {
1097 if (!$results->EOF) {
1098 $retval = $results->fields['subscriber_relationship'];
1102 if (strtolower($retval) == "other") {
1103 $retval = true;
1105 else {
1106 $retval = false;
1110 // if we generated an error, create an error return response
1111 if ($err) {
1112 return $this->_handleError($err);
1114 else {
1115 // otherwise, we create the right response
1116 // with the state name
1117 return new xmlrpcresp(new xmlrpcval($retval,"i4"));
1121 function socialsecuritynumber($m) {
1123 $err="";
1125 $retval = "";
1126 $obj= $m->getparam(0);
1127 $key = $obj->getval();
1129 $sql = "SELECT * FROM patient_data where pid = '" . $_SESSION['patient_id'] . "'";
1130 //echo $sql;
1131 $db = $GLOBALS['adodb']['db'];
1132 $results = $db->Execute($sql);
1134 if (!$results) {
1135 $err = $db->ErrorMsg();
1137 else {
1138 if (!$results->EOF) {
1139 $retval = $results->fields['ss'];
1143 // if we generated an error, create an error return response
1144 if ($err) {
1145 return $this->_handleError($err);
1147 else {
1148 // otherwise, we create the right response
1149 // with the state name
1150 return new xmlrpcresp(new xmlrpcval($pkey));
1155 function coveragecount($m) {
1157 $err="";
1159 //unimplemented in OpenEMR
1160 $pkey = "1";
1162 // if we generated an error, create an error return response
1163 if ($err) {
1164 return $this->_handleError($err);
1166 else {
1167 // otherwise, we create the right response
1168 // with the state name
1169 return new xmlrpcresp(new xmlrpcval($pkey));
1173 function x12insuredrelationship($m) {
1175 $err="";
1176 $obj= $m->getparam(0);
1177 $patientkey = $obj->getval();
1179 $obj= $m->getparam(1);
1180 $insuredkey = $obj->getval();
1182 $retval = "";
1183 $obj= $m->getparam(0);
1184 $key = $obj->getval();
1185 $obj= $m->getparam(1);
1186 $key2 = $obj->getval();
1187 $sql = "SELECT * FROM insurance_data where pid = '" . $key . "' AND id = '" . $key2 . "'";
1188 //echo $sql;
1189 $db = $GLOBALS['adodb']['db'];
1190 $results = $db->Execute($sql);
1192 if (!$results) {
1193 $err = $db->ErrorMsg();
1195 else {
1196 if (!$results->EOF) {
1197 $retval = $results->fields['subscriber_relationship'];
1201 if (strtolower($retval) == "self") {
1202 $retval = "18";
1204 elseif (strtolower($retval) == "spouse") {
1205 $retval = "01";
1207 elseif (strtolower($retval) == "child") {
1208 $retval = "19";
1210 elseif (strtolower($retval) == "other") {
1211 $retval = "G8";
1215 * For Reference these values are currently in use, we only support a subset
1216 * 01 Spouse
1217 * 04 Grandfather or Grandmother
1218 * 05 Grandson or Granddaughter
1219 * 07 Nephew or Niece
1220 * 09 Adopted Child
1221 * 10 Foster Child
1222 * 15 Ward
1223 * 17 Stepson or Stepdaughter
1224 * 19 Child
1225 * 20 Employee
1226 * 21 Unknown
1227 * 22 Handicapped Dependent
1228 * 23 Sponsored Dependent
1229 * 24 Dependent of a Minor Dependent
1230 * 29 Significant Other
1231 * 32 Mother
1232 * 33 Father
1233 * 34 Other Adult
1234 * 36 Emancipated Minor
1235 * 39 Organ Donor
1236 * 40 Cadaver Donor
1237 * 41 Injured Plaintiff
1238 * 43 Child Where Insured Has No Financial Responsibility
1239 * 53 Life Partner
1240 * G8 Other Relationship
1244 // if we generated an error, create an error return response
1245 if ($err) {
1246 return $this->_handleError($err);
1248 else {
1249 // otherwise, we create the right response
1250 // with the state name
1251 return new xmlrpcresp(new xmlrpcval($retval,"string"));
1255 function x12secondarymedicarecode($m) {
1257 $err="";
1259 //unimplemented in OpenEMR
1260 $pkey = "";
1263 * For future reference values can be:
1264 *12 Medicare Secondary Working Aged Beneficiary or Spouse with Employer Group Health Plan
1265 *13 Medicare Secondary End-Stage Renal Disease Beneficiary in the 12 month coordination period with an employer's group health plan
1266 *14 Medicare Secondary, No-fault Insurance including Auto is Primary
1267 *15 Medicare Secondary Worker's Compensation
1268 *16 Medicare Secondary Public Health Service (PHS)or Other Federal Agency
1269 *41 Medicare Secondary Black Lung
1270 *42 Medicare Secondary Veteran's Administration
1271 *43 Medicare Secondary Disabled Beneficiary Under Age 65 with Large Group Health Plan (LGHP)
1272 *47 Medicare Secondary, Other Liability Insurance is Primary
1275 // if we generated an error, create an error return response
1276 if ($err) {
1277 return $this->_handleError($err);
1279 else {
1280 // otherwise, we create the right response
1281 // with the state name
1282 return new xmlrpcresp(new xmlrpcval($pkey));
1286 function ispregnant($m) {
1288 $err="";
1290 //unimplemented in OpenEMR
1291 $pkey = "";
1293 // if we generated an error, create an error return response
1294 if ($err) {
1295 return $this->_handleError($err);
1297 else {
1298 // otherwise, we create the right response
1299 // with the state name
1300 return new xmlrpcresp(new xmlrpcval($pkey));
1313 //'FreeB.FBPatient.FirstName' => \&FreeB_FBPatient_FirstName,
1314 //'FreeB.FBPatient.MiddleName' => \&FreeB_FBPatient_MiddleName,
1315 //'FreeB.FBPatient.LastName' => \&FreeB_FBPatient_LastName,
1316 //'FreeB.FBPatient.StreetAddress' => \&FreeB_FBPatient_StreetAddres,
1317 //'FreeB.FBPatient.City' => \&FreeB_FBPatient_City,
1318 //'FreeB.FBPatient.Zipcode' => \&FreeB_FBPatient_Zipcode,
1319 //'FreeB.FBPatient.State' => \&FreeB_FBPatient_State,
1320 //'FreeB.FBPatient.PhoneCountry' => \&FreeB_FBPatient_PhoneCountry,
1321 //'FreeB.FBPatient.PhoneExtension' => \&FreeB_FBPatient_PhoneExtension,
1322 //'FreeB.FBPatient.PhoneArea' => \&FreeB_FBPatient_PhoneArea,
1323 //'FreeB.FBPatient.PhoneNumber' => \&FreeB_FBPatient_PhoneNumber,
1324 //'FreeB.FBPatient.Title' => \&FreeB_FBPatient_Title,
1325 //'FreeB.FBPatient.Account' => \&FreeB_FBPatient_Account,
1326 //'FreeB.FBPatient.isDead' => \&FreeB_FBPatient_isDead,
1327 //'FreeB.FBPatient.DateOfBirth' => \&FreeB_FBPatient_DateOfBirth,
1328 //'FreeB.FBPatient.DateOfDeath' => \&FreeB_FBPatient_DateOfDeath,
1329 //'FreeB.FBPatient.Sex' => \&FreeB_FBPatient_Sex,
1330 //'FreeB.FBPatient.isSingle' => \&FreeB_FBPatient_isSingle,
1331 //'FreeB.FBPatient.isMarried' => \&FreeB_FBPatient_isMarried,
1332 //'FreeB.FBPatient.isMaritalOtherHCFA' => \&FreeB_FBPatient_isMaritalOtherHCFA,
1333 //'FreeB.FBPatient.isEmployed' => \&FreeB_FBPatient_isEmployed,
1334 //'FreeB.FBPatient.isFullTimeStudent' => \&FreeB_FBPatient_isFullTimeStudent,
1335 //'FreeB.FBPatient.isPartTimeStudent' => \&FreeB_FBPatient_isPartTimeStudent,
1336 //'FreeB.FBPatient.isChildOfInsured' => \&FreeB_FBPatient_isChildOfInsured,
1337 //'FreeB.FBPatient.isHusbandOfInsured' => \&FreeB_FBPatient_isHusbandOfInsured,
1338 //'FreeB.FBPatient.isWifeOfInsured' => \&FreeB_FBPatient_isWifeOfInsured,
1339 //'FreeB.FBPatient.isDivorceeOfInsured' => \&FreeB_FBPatient_isDivorceeOfInsured,
1340 //'FreeB.FBPatient.isSelfOfInsured' => \&FreeB_FBPatient_isSelfOfInsured,
1341 //'FreeB.FBPatient.isOtherOfInsured' => \&FreeB_FBPatient_isOtherOfInsured,
1342 //'FreeB.FBPatient.ReferringProviderKey' => \&FreeB_FBPatient_ReferringProviderKey,
1343 //'FreeB.FBPatient.SocialSecurityNumber' => \&FreeB_FBPatient_SocialSecurityNumber,
1344 //'FreeB.FBPatient.CoverageCount' => \&FreeB_FBPatient_CoverageCount,
1345 //'FreeB.FBPatient.X12InsuredRelationship' => \&FreeB_FBPatient_X12InsuredRelationship,
1346 //'FreeB.FBPatient.isPregnant' => \&FreeB_FBPatient_isPregnant,