ZEND project: set writable permissions to zend module config file at interface/module...
[openemr.git] / library / freeb / Patient.class.php
blob4fad851f3bfc753750fb22f1e21430f1a29b685e
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" => ""));
108 $this->_addFunc("insuredkey", array("name" => "FreeB.FBPatient.InsuredKey",
109 "sig" => array(XMLRPCSTRING,XMLRPCINT,XMLRPCSTRING),
110 "doc" => ""));
114 function firstname($m) {
116 $err="";
118 $retval = "";
119 $obj= $m->getparam(0);
120 $key = $obj->getval();
122 $sql = "SELECT * FROM patient_data where pid = '" . $key . "'";
123 //echo $sql;
124 $db = $GLOBALS['adodb']['db'];
125 $results = $db->Execute($sql);
127 if (!$results) {
128 $err = $db->ErrorMsg();
130 else {
131 if (!$results->EOF) {
132 $retval = $results->fields['fname'];
136 // if we generated an error, create an error return response
137 if ($err) {
138 return $this->_handleError($err);
140 else {
141 // otherwise, we create the right response
142 // with the state name
143 return new xmlrpcresp(new xmlrpcval($retval,"string"));
147 function middlename($m) {
149 $err="";
151 $retval = "";
152 $obj= $m->getparam(0);
153 $key = $obj->getval();
155 $sql = "SELECT * FROM patient_data where pid = '" . $key . "'";
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['mname'];
170 // if we generated an error, create an error return response
171 if ($err) {
172 return $this->_handleError($err);
174 else {
175 // otherwise, we create the right response
176 // with the state name
177 return new xmlrpcresp(new xmlrpcval($retval,"string"));
181 function lastname($m) {
183 $err="";
185 $retval = "";
186 $obj= $m->getparam(0);
187 $key = $obj->getval();
189 $sql = "SELECT * FROM patient_data where pid = '" . $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['lname'];
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,"string"));
215 function streetaddress($m) {
217 $err="";
219 $retval = "";
220 $obj= $m->getparam(0);
221 $key = $obj->getval();
223 $sql = "SELECT * FROM patient_data where pid = '" . $_SESSION['patient_id'] . "'";
224 //echo $sql;
225 $db = $GLOBALS['adodb']['db'];
226 $results = $db->Execute($sql);
228 if (!$results) {
229 $err = $db->ErrorMsg();
231 else {
232 if (!$results->EOF) {
233 $retval = $results->fields['street'];
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,"string"));
250 function city($m) {
252 $err="";
254 $retval = "";
255 $obj= $m->getparam(0);
256 $key = $obj->getval();
258 $sql = "SELECT * FROM patient_data where pid = '" . $_SESSION['patient_id'] . "'";
259 //echo $sql;
260 $db = $GLOBALS['adodb']['db'];
261 $results = $db->Execute($sql);
263 if (!$results) {
264 $err = $db->ErrorMsg();
266 else {
267 if (!$results->EOF) {
268 $retval = $results->fields['city'];
273 // if we generated an error, create an error return response
274 if ($err) {
275 return $this->_handleError($err);
277 else {
278 // otherwise, we create the right response
279 // with the state name
280 return new xmlrpcresp(new xmlrpcval($retval,"string"));
284 function state($m) {
286 $err="";
288 $retval = "";
289 $obj= $m->getparam(0);
290 $key = $obj->getval();
292 $sql = "SELECT * FROM patient_data where pid = '" . $_SESSION['patient_id'] . "'";
293 //echo $sql;
294 $db = $GLOBALS['adodb']['db'];
295 $results = $db->Execute($sql);
297 if (!$results) {
298 $err = $db->ErrorMsg();
300 else {
301 if (!$results->EOF) {
302 $retval = $results->fields['state'];
307 // if we generated an error, create an error return response
308 if ($err) {
309 return $this->_handleError($err);
311 else {
312 // otherwise, we create the right response
313 // with the state name
314 return new xmlrpcresp(new xmlrpcval($retval,"string"));
318 function zipcode($m) {
320 $err="";
322 $retval = "";
323 $obj= $m->getparam(0);
324 $key = $obj->getval();
326 $sql = "SELECT * FROM patient_data where pid = '" . $_SESSION['patient_id'] . "'";
327 //echo $sql;
328 $db = $GLOBALS['adodb']['db'];
329 $results = $db->Execute($sql);
331 if (!$results) {
332 $err = $db->ErrorMsg();
334 else {
335 if (!$results->EOF) {
336 $retval = $results->fields['postal_code'];
341 // if we generated an error, create an error return response
342 if ($err) {
343 return $this->_handleError($err);
345 else {
346 // otherwise, we create the right response
347 // with the state name
348 return new xmlrpcresp(new xmlrpcval($retval,"string"));
352 function phonecountry($m) {
354 $err="";
356 //OpenEMR only supports US country code
357 $pkey = "1";
359 // if we generated an error, create an error return response
360 if ($err) {
361 return $this->_handleError($err);
363 else {
364 // otherwise, we create the right response
365 // with the state name
366 return new xmlrpcresp(new xmlrpcval($pkey));
370 function phoneextension($m) {
372 $err="";
374 //unimplemented by openemr
375 $pkey = "";
377 // if we generated an error, create an error return response
378 if ($err) {
379 return $this->_handleError($err);
381 else {
382 // otherwise, we create the right response
383 // with the state name
384 return new xmlrpcresp(new xmlrpcval($pkey));
388 function phonearea($m) {
390 $err="";
392 $retval = "";
393 $obj= $m->getparam(0);
394 $key = $obj->getval();
396 $sql = "SELECT * FROM patient_data where pid = '" . $_SESSION['patient_id'] . "'";
397 //echo $sql;
398 $db = $GLOBALS['adodb']['db'];
399 $results = $db->Execute($sql);
401 if (!$results) {
402 $err = $db->ErrorMsg();
404 else {
405 if (!$results->EOF) {
406 $retval = $results->fields['phone_home'];
410 $phone_parts = array();
411 // preg_match("/^\((.*?)\)\s(.*?)\-(.*?)$/",$retval,$phone_parts);
412 preg_match("/(\d\d\d)\D*(\d\d\d)\D*(\d\d\d\d)/",$retval,$phone_parts);
413 $retval = $phone_parts[1];
415 // if we generated an error, create an error return response
416 if ($err) {
417 return $this->_handleError($err);
419 else {
420 // otherwise, we create the right response
421 // with the state name
422 return new xmlrpcresp(new xmlrpcval($retval,"string"));
426 function phonenumber($m) {
428 $err="";
430 $retval = "";
431 $obj= $m->getparam(0);
432 $key = $obj->getval();
434 $sql = "SELECT * FROM patient_data where pid = '" . $_SESSION['patient_id'] . "'";
435 //echo $sql;
436 $db = $GLOBALS['adodb']['db'];
437 $results = $db->Execute($sql);
439 if (!$results) {
440 $err = $db->ErrorMsg();
442 else {
443 if (!$results->EOF) {
444 $retval = $results->fields['phone_home'];
448 $phone_parts = array();
449 // preg_match("/^\((.*?)\)\s(.*?)\-(.*?)$/",$retval,$phone_parts);
450 preg_match("/(\d\d\d)\D*(\d\d\d)\D*(\d\d\d\d)/",$retval,$phone_parts);
451 $retval = $phone_parts[2] . "-" . $phone_parts[3];
453 // if we generated an error, create an error return response
454 if ($err) {
455 return $this->_handleError($err);
457 else {
458 // otherwise, we create the right response
459 // with the state name
460 return new xmlrpcresp(new xmlrpcval($retval,"string"));
465 function title($m) {
467 $err="";
469 $retval = "";
470 $obj= $m->getparam(0);
471 $key = $obj->getval();
473 $sql = "SELECT * FROM patient_data where pid = '" . $_SESSION['patient_id'] . "'";
474 //echo $sql;
475 $db = $GLOBALS['adodb']['db'];
476 $results = $db->Execute($sql);
478 if (!$results) {
479 $err = $db->ErrorMsg();
481 else {
482 if (!$results->EOF) {
483 $retval = $results->fields['title'];
488 // if we generated an error, create an error return response
489 if ($err) {
490 return $this->_handleError($err);
492 else {
493 // otherwise, we create the right response
494 // with the state name
495 return new xmlrpcresp(new xmlrpcval($retval,"string"));
499 function account($m) {
501 $err="";
504 $retval = $_SESSION['patient_id'] . "-" . $_SESSION['billkey'];
506 // if we generated an error, create an error return response
507 if ($err) {
508 return $this->_handleError($err);
510 else {
511 // otherwise, we create the right response
512 // with the state name
513 return new xmlrpcresp(new xmlrpcval($retval));
517 function isdead($m) {
519 $err="";
521 //unimplemented by OpenEMR
522 $pkey = false;
524 // if we generated an error, create an error return response
525 if ($err) {
526 return $this->_handleError($err);
528 else {
529 // otherwise, we create the right response
530 // with the state name
531 return new xmlrpcresp(new xmlrpcval($pkey,"i4"));
535 function dateofbirth($m) {
537 $err="";
539 $retval = "";
540 $obj= $m->getparam(0);
541 $key = $obj->getval();
543 $sql = "SELECT * FROM patient_data where pid = '" . $_SESSION['patient_id'] . "'";
544 //echo $sql;
545 $db = $GLOBALS['adodb']['db'];
546 $results = $db->Execute($sql);
548 if (!$results) {
549 $err = $db->ErrorMsg();
551 else {
552 if (!$results->EOF) {
553 $retval = $results->fields['DOB'];
558 $retval = $this->_isodate($retval);
560 // if we generated an error, create an error return response
561 if ($err) {
562 return $this->_handleError($err);
564 else {
565 // otherwise, we create the right response
566 // with the state name
567 return new xmlrpcresp(new xmlrpcval($retval,XMLRPCDATETIME));
571 function dateofdeath($m) {
573 $err="";
575 //Unimplimented by OpenEMR
576 $pkey = "";
578 // if we generated an error, create an error return response
579 if ($err) {
580 return $this->_handleError($err);
582 else {
583 // otherwise, we create the right response
584 // with the state name
585 return new xmlrpcresp(new xmlrpcval($pkey,XMLRPCDATETIME));
589 function sex($m) {
591 $err="";
593 $retval = "";
594 $obj= $m->getparam(0);
595 $key = $obj->getval();
597 $sql = "SELECT * FROM patient_data where pid = '" . $key . "'";
598 //echo $sql;
599 $db = $GLOBALS['adodb']['db'];
600 $results = $db->Execute($sql);
602 if (!$results) {
603 $err = $db->ErrorMsg();
605 else {
606 if (!$results->EOF) {
607 $retval = $results->fields['sex'];
610 if (strtolower($retval) == "male") {
611 $retval = "M";
613 elseif (strtolower($retval) == "female") {
614 $retval = "F";
617 // if we generated an error, create an error return response
618 if ($err) {
619 return $this->_handleError($err);
621 else {
622 // otherwise, we create the right response
623 // with the state name
624 return new xmlrpcresp(new xmlrpcval($retval,"string"));
630 function issingle($m) {
632 $err="";
634 $retval = "";
635 $obj= $m->getparam(0);
636 $key = $obj->getval();
638 $sql = "SELECT * FROM patient_data where pid = '" . $_SESSION['patient_id'] . "'";
639 //echo $sql;
640 $db = $GLOBALS['adodb']['db'];
641 $results = $db->Execute($sql);
643 if (!$results) {
644 $err = $db->ErrorMsg();
646 else {
647 if (!$results->EOF) {
648 $retval = $results->fields['status'];
652 if ($retval == "single") {
653 $retval = true;
655 else {
656 $retval = false;
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($retval,"i4"));
670 function ismarried($m) {
672 $err="";
674 $retval = "";
675 $obj= $m->getparam(0);
676 $key = $obj->getval();
678 $sql = "SELECT * FROM patient_data where pid = '" . $_SESSION['patient_id'] . "'";
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['status'];
692 if ($retval == "married") {
693 $retval = true;
695 else {
696 $retval = false;
700 // if we generated an error, create an error return response
701 if ($err) {
702 return $this->_handleError($err);
704 else {
705 // otherwise, we create the right response
706 // with the state name
707 return new xmlrpcresp(new xmlrpcval($retval,"i4"));
711 function ismaritalotherhcfa($m) {
713 $err="";
715 $retval = "";
716 $obj= $m->getparam(0);
717 $key = $obj->getval();
719 $sql = "SELECT * FROM patient_data where pid = '" . $_SESSION['patient_id'] . "'";
720 //echo $sql;
721 $db = $GLOBALS['adodb']['db'];
722 $results = $db->Execute($sql);
724 if (!$results) {
725 $err = $db->ErrorMsg();
727 else {
728 if (!$results->EOF) {
729 $retval = $results->fields['status'];
733 if ($retval == "domestic partner") {
734 $retval = true;
736 else {
737 $retval = false;
741 // if we generated an error, create an error return response
742 if ($err) {
743 return $this->_handleError($err);
745 else {
746 // otherwise, we create the right response
747 // with the state name
748 return new xmlrpcresp(new xmlrpcval($retval,"i4"));
752 function isemployed($m) {
754 $err="";
756 $retval = "";
757 $obj= $m->getparam(0);
758 $key = $obj->getval();
760 $sql = "SELECT * FROM patient_data where pid = '" . $_SESSION['patient_id'] . "'";
761 //echo $sql;
762 $db = $GLOBALS['adodb']['db'];
763 $results = $db->Execute($sql);
765 if (!$results) {
766 $err = $db->ErrorMsg();
768 else {
769 if (!$results->EOF) {
770 $retval = $results->fields['occupation'];
774 if ($retval == "Unemployed" || empty($retval)) {
775 $retval = false;
777 else {
778 $retval = true;
782 // if we generated an error, create an error return response
783 if ($err) {
784 return $this->_handleError($err);
786 else {
787 // otherwise, we create the right response
788 // with the state name
789 return new xmlrpcresp(new xmlrpcval($retval,"i4"));
793 function isfulltimestudent($m) {
795 $err="";
797 $retval = "";
798 $obj= $m->getparam(0);
799 $key = $obj->getval();
801 $sql = "SELECT * FROM patient_data where pid = '" . $_SESSION['patient_id'] . "'";
802 //echo $sql;
803 $db = $GLOBALS['adodb']['db'];
804 $results = $db->Execute($sql);
806 if (!$results) {
807 $err = $db->ErrorMsg();
809 else {
810 if (!$results->EOF) {
811 $retval = $results->fields['occupation'];
815 if (strtolower($retval) == "student") {
816 $retval = true;
818 else {
819 $retval = false;
822 // if we generated an error, create an error return response
823 if ($err) {
824 return $this->_handleError($err);
826 else {
827 // otherwise, we create the right response
828 // with the state name
829 return new xmlrpcresp(new xmlrpcval($retval,"i4"));
833 function isparttimestudent($m) {
835 $err="";
837 $retval = "";
838 $obj= $m->getparam(0);
839 $key = $obj->getval();
841 $sql = "SELECT * FROM patient_data where pid = '" . $_SESSION['patient_id'] . "'";
842 //echo $sql;
843 $db = $GLOBALS['adodb']['db'];
844 $results = $db->Execute($sql);
846 if (!$results) {
847 $err = $db->ErrorMsg();
849 else {
850 if (!$results->EOF) {
851 $retval = $results->fields['occupation'];
855 if (strtolower($retval) == "pt student") {
856 $retval = true;
858 else {
859 $retval = false;
863 // if we generated an error, create an error return response
864 if ($err) {
865 return $this->_handleError($err);
867 else {
868 // otherwise, we create the right response
869 // with the state name
870 return new xmlrpcresp(new xmlrpcval($retval,"i4"));
874 function ischildofinsured($m) {
876 $err="";
878 $retval = "";
879 $obj= $m->getparam(0);
880 $key = $obj->getval();
881 $obj= $m->getparam(1);
882 $key2 = $obj->getval();
883 $sql = "SELECT * FROM insurance_data where pid = '" . $key . "' AND id = '" . $key2 . "'";
884 //echo $sql;
885 $db = $GLOBALS['adodb']['db'];
886 $results = $db->Execute($sql);
888 if (!$results) {
889 $err = $db->ErrorMsg();
891 else {
892 if (!$results->EOF) {
893 $retval = $results->fields['subscriber_relationship'];
897 if (strtolower($retval) == "child") {
898 $retval = true;
900 else {
901 $retval = false;
904 // if we generated an error, create an error return response
905 if ($err) {
906 return $this->_handleError($err);
908 else {
909 // otherwise, we create the right response
910 // with the state name
911 return new xmlrpcresp(new xmlrpcval($retval,"i4"));
915 function ishusbandofinsured($m) {
917 $err="";
919 $retval = "";
920 $obj= $m->getparam(0);
921 $key = $obj->getval();
922 $obj= $m->getparam(1);
923 $key2 = $obj->getval();
924 $sql = "SELECT * FROM insurance_data where pid = '" . $key . "' AND id = '" . $key2 . "'";
925 //echo $sql;
926 $db = $GLOBALS['adodb']['db'];
927 $results = $db->Execute($sql);
929 if (!$results) {
930 $err = $db->ErrorMsg();
932 else {
933 if (!$results->EOF) {
934 $retval = $results->fields['subscriber_relationship'];
938 if (strtolower($retval) == "spouse") {
939 $retval = true;
941 else {
942 $retval = false;
946 // if we generated an error, create an error return response
947 if ($err) {
948 return $this->_handleError($err);
950 else {
951 // otherwise, we create the right response
952 // with the state name
953 return new xmlrpcresp(new xmlrpcval($retval,"i4"));
957 function iswifeofinsured($m) {
959 $err="";
961 $retval = "";
962 $obj= $m->getparam(0);
963 $key = $obj->getval();
964 $obj= $m->getparam(1);
965 $key2 = $obj->getval();
966 $sql = "SELECT * FROM insurance_data where pid = '" . $key . "' AND id = '" . $key2 . "'";
967 //echo $sql;
968 $db = $GLOBALS['adodb']['db'];
969 $results = $db->Execute($sql);
971 if (!$results) {
972 $err = $db->ErrorMsg();
974 else {
975 if (!$results->EOF) {
976 $retval = $results->fields['subscriber_relationship'];
980 if (strtolower($retval) == "spouse" && $results->fields['sex'] == "male") {
981 $retval = true;
983 else {
984 $retval = false;
987 $retval = false;
988 // if we generated an error, create an error return response
989 if ($err) {
990 return $this->_handleError($err);
992 else {
993 // otherwise, we create the right response
994 // with the state name
995 return new xmlrpcresp(new xmlrpcval($retval,"i4"));
999 function isdivorceeofinsured($m) {
1001 $err="";
1003 $retval = "";
1004 $obj= $m->getparam(0);
1005 $key = $obj->getval();
1006 $obj= $m->getparam(1);
1007 $key2 = $obj->getval();
1008 $sql = "SELECT * FROM insurance_data where pid = '" . $key . "' AND id = '" . $key2 . "'";
1009 //echo $sql;
1010 $db = $GLOBALS['adodb']['db'];
1011 $results = $db->Execute($sql);
1013 if (!$results) {
1014 $err = $db->ErrorMsg();
1016 else {
1017 if (!$results->EOF) {
1018 $retval = $results->fields['subscriber_relationship'];
1022 if (strtolower($retval) == "divorcee") {
1023 $retval = true;
1025 else {
1026 $retval = false;
1030 // if we generated an error, create an error return response
1031 if ($err) {
1032 return $this->_handleError($err);
1034 else {
1035 // otherwise, we create the right response
1036 // with the state name
1037 return new xmlrpcresp(new xmlrpcval($retval,"i4"));
1041 function isselfofinsured($m) {
1043 $err="";
1045 $retval = "";
1046 $obj= $m->getparam(0);
1047 $key = $obj->getval();
1048 $obj= $m->getparam(1);
1049 $key2 = $obj->getval();
1050 $sql = "SELECT * FROM insurance_data where pid = '" . $key . "' AND id = '" . $key2 . "'";
1051 //echo $sql;
1052 $db = $GLOBALS['adodb']['db'];
1053 $results = $db->Execute($sql);
1055 if (!$results) {
1056 $err = $db->ErrorMsg();
1058 else {
1059 if (!$results->EOF) {
1060 $retval = $results->fields['subscriber_relationship'];
1064 if (strtolower($retval) == "self") {
1065 $retval = true;
1067 else {
1068 $retval = false;
1072 // if we generated an error, create an error return response
1073 if ($err) {
1074 return $this->_handleError($err);
1076 else {
1077 // otherwise, we create the right response
1078 // with the state name
1079 return new xmlrpcresp(new xmlrpcval($retval,"i4"));
1083 function isotherofinsured($m) {
1085 $err="";
1087 $retval = "";
1088 $obj= $m->getparam(0);
1089 $key = $obj->getval();
1090 $obj= $m->getparam(1);
1091 $key2 = $obj->getval();
1092 $sql = "SELECT * FROM insurance_data where pid = '" . $key . "' AND id = '" . $key2 . "'";
1093 //echo $sql;
1094 $db = $GLOBALS['adodb']['db'];
1095 $results = $db->Execute($sql);
1097 if (!$results) {
1098 $err = $db->ErrorMsg();
1100 else {
1101 if (!$results->EOF) {
1102 $retval = $results->fields['subscriber_relationship'];
1106 if (strtolower($retval) == "other") {
1107 $retval = true;
1109 else {
1110 $retval = false;
1114 // if we generated an error, create an error return response
1115 if ($err) {
1116 return $this->_handleError($err);
1118 else {
1119 // otherwise, we create the right response
1120 // with the state name
1121 return new xmlrpcresp(new xmlrpcval($retval,"i4"));
1125 function socialsecuritynumber($m) {
1127 $err="";
1129 $retval = "";
1130 $obj= $m->getparam(0);
1131 $key = $obj->getval();
1133 $sql = "SELECT * FROM patient_data where pid = '" . $_SESSION['patient_id'] . "'";
1134 //echo $sql;
1135 $db = $GLOBALS['adodb']['db'];
1136 $results = $db->Execute($sql);
1138 if (!$results) {
1139 $err = $db->ErrorMsg();
1141 else {
1142 if (!$results->EOF) {
1143 $retval = $results->fields['ss'];
1147 // if we generated an error, create an error return response
1148 if ($err) {
1149 return $this->_handleError($err);
1151 else {
1152 // otherwise, we create the right response
1153 // with the state name
1154 return new xmlrpcresp(new xmlrpcval($pkey));
1159 function coveragecount($m) {
1161 $err="";
1163 //unimplemented in OpenEMR
1164 $pkey = "1";
1166 // if we generated an error, create an error return response
1167 if ($err) {
1168 return $this->_handleError($err);
1170 else {
1171 // otherwise, we create the right response
1172 // with the state name
1173 return new xmlrpcresp(new xmlrpcval($pkey));
1177 function x12insuredrelationship($m) {
1179 $err="";
1180 $obj= $m->getparam(0);
1181 $patientkey = $obj->getval();
1183 $obj= $m->getparam(1);
1184 $insuredkey = $obj->getval();
1186 $retval = "";
1187 $obj= $m->getparam(0);
1188 $key = $obj->getval();
1189 $obj= $m->getparam(1);
1190 $key2 = $obj->getval();
1191 $sql = "SELECT * FROM insurance_data where pid = '" . $key . "' AND id = '" . $key2 . "'";
1192 //echo $sql;
1193 $db = $GLOBALS['adodb']['db'];
1194 $results = $db->Execute($sql);
1196 if (!$results) {
1197 $err = $db->ErrorMsg();
1199 else {
1200 if (!$results->EOF) {
1201 $retval = $results->fields['subscriber_relationship'];
1205 if (strtolower($retval) == "self") {
1206 $retval = "18";
1208 elseif (strtolower($retval) == "spouse") {
1209 $retval = "01";
1211 elseif (strtolower($retval) == "child") {
1212 $retval = "19";
1214 elseif (strtolower($retval) == "other") {
1215 $retval = "G8";
1219 * For Reference these values are currently in use, we only support a subset
1220 * 01 Spouse
1221 * 04 Grandfather or Grandmother
1222 * 05 Grandson or Granddaughter
1223 * 07 Nephew or Niece
1224 * 09 Adopted Child
1225 * 10 Foster Child
1226 * 15 Ward
1227 * 17 Stepson or Stepdaughter
1228 * 19 Child
1229 * 20 Employee
1230 * 21 Unknown
1231 * 22 Handicapped Dependent
1232 * 23 Sponsored Dependent
1233 * 24 Dependent of a Minor Dependent
1234 * 29 Significant Other
1235 * 32 Mother
1236 * 33 Father
1237 * 34 Other Adult
1238 * 36 Emancipated Minor
1239 * 39 Organ Donor
1240 * 40 Cadaver Donor
1241 * 41 Injured Plaintiff
1242 * 43 Child Where Insured Has No Financial Responsibility
1243 * 53 Life Partner
1244 * G8 Other Relationship
1248 // if we generated an error, create an error return response
1249 if ($err) {
1250 return $this->_handleError($err);
1252 else {
1253 // otherwise, we create the right response
1254 // with the state name
1255 return new xmlrpcresp(new xmlrpcval($retval,"string"));
1259 function x12secondarymedicarecode($m) {
1261 $err="";
1263 //unimplemented in OpenEMR
1264 $pkey = "";
1267 * For future reference values can be:
1268 *12 Medicare Secondary Working Aged Beneficiary or Spouse with Employer Group Health Plan
1269 *13 Medicare Secondary End-Stage Renal Disease Beneficiary in the 12 month coordination period with an employer's group health plan
1270 *14 Medicare Secondary, No-fault Insurance including Auto is Primary
1271 *15 Medicare Secondary Worker's Compensation
1272 *16 Medicare Secondary Public Health Service (PHS)or Other Federal Agency
1273 *41 Medicare Secondary Black Lung
1274 *42 Medicare Secondary Veteran's Administration
1275 *43 Medicare Secondary Disabled Beneficiary Under Age 65 with Large Group Health Plan (LGHP)
1276 *47 Medicare Secondary, Other Liability Insurance is Primary
1279 // if we generated an error, create an error return response
1280 if ($err) {
1281 return $this->_handleError($err);
1283 else {
1284 // otherwise, we create the right response
1285 // with the state name
1286 return new xmlrpcresp(new xmlrpcval($pkey));
1290 function ispregnant($m) {
1292 $err="";
1294 //unimplemented in OpenEMR
1295 $pkey = "";
1297 // if we generated an error, create an error return response
1298 if ($err) {
1299 return $this->_handleError($err);
1301 else {
1302 // otherwise, we create the right response
1303 // with the state name
1304 return new xmlrpcresp(new xmlrpcval($pkey));
1308 function insuredkey($m) {
1310 $err="";
1311 $obj= $m->getparam(0);
1312 $patientkey = $obj->getval();
1314 $obj= $m->getparam(1);
1315 $instype = $obj->getval();
1317 $retval = "";
1319 // TBD: This needs to compensate for the encounter date which is not given
1320 // to us, but we are getting rid of freeb anyway. Also I'm not sure this
1321 // function is even used; Procedure::InsuredKey seems to be used instead.
1322 $sql = "SELECT id FROM insurance_data WHERE pid = '$patientkey' AND " .
1323 "type = '$instype' ORDER BY date DESC LIMIT 1";
1325 $db = $GLOBALS['adodb']['db'];
1326 $results = $db->Execute($sql);
1328 if (!$results) {
1329 $err = $db->ErrorMsg();
1331 else {
1332 if (!$results->EOF) {
1333 $retval = $results->fields['id'];
1337 if ($err) {
1338 return $this->_handleError($err);
1340 else {
1341 return new xmlrpcresp(new xmlrpcval($retval, "i4"));
1347 //'FreeB.FBPatient.FirstName' => \&FreeB_FBPatient_FirstName,
1348 //'FreeB.FBPatient.MiddleName' => \&FreeB_FBPatient_MiddleName,
1349 //'FreeB.FBPatient.LastName' => \&FreeB_FBPatient_LastName,
1350 //'FreeB.FBPatient.StreetAddress' => \&FreeB_FBPatient_StreetAddres,
1351 //'FreeB.FBPatient.City' => \&FreeB_FBPatient_City,
1352 //'FreeB.FBPatient.Zipcode' => \&FreeB_FBPatient_Zipcode,
1353 //'FreeB.FBPatient.State' => \&FreeB_FBPatient_State,
1354 //'FreeB.FBPatient.PhoneCountry' => \&FreeB_FBPatient_PhoneCountry,
1355 //'FreeB.FBPatient.PhoneExtension' => \&FreeB_FBPatient_PhoneExtension,
1356 //'FreeB.FBPatient.PhoneArea' => \&FreeB_FBPatient_PhoneArea,
1357 //'FreeB.FBPatient.PhoneNumber' => \&FreeB_FBPatient_PhoneNumber,
1358 //'FreeB.FBPatient.Title' => \&FreeB_FBPatient_Title,
1359 //'FreeB.FBPatient.Account' => \&FreeB_FBPatient_Account,
1360 //'FreeB.FBPatient.isDead' => \&FreeB_FBPatient_isDead,
1361 //'FreeB.FBPatient.DateOfBirth' => \&FreeB_FBPatient_DateOfBirth,
1362 //'FreeB.FBPatient.DateOfDeath' => \&FreeB_FBPatient_DateOfDeath,
1363 //'FreeB.FBPatient.Sex' => \&FreeB_FBPatient_Sex,
1364 //'FreeB.FBPatient.isSingle' => \&FreeB_FBPatient_isSingle,
1365 //'FreeB.FBPatient.isMarried' => \&FreeB_FBPatient_isMarried,
1366 //'FreeB.FBPatient.isMaritalOtherHCFA' => \&FreeB_FBPatient_isMaritalOtherHCFA,
1367 //'FreeB.FBPatient.isEmployed' => \&FreeB_FBPatient_isEmployed,
1368 //'FreeB.FBPatient.isFullTimeStudent' => \&FreeB_FBPatient_isFullTimeStudent,
1369 //'FreeB.FBPatient.isPartTimeStudent' => \&FreeB_FBPatient_isPartTimeStudent,
1370 //'FreeB.FBPatient.isChildOfInsured' => \&FreeB_FBPatient_isChildOfInsured,
1371 //'FreeB.FBPatient.isHusbandOfInsured' => \&FreeB_FBPatient_isHusbandOfInsured,
1372 //'FreeB.FBPatient.isWifeOfInsured' => \&FreeB_FBPatient_isWifeOfInsured,
1373 //'FreeB.FBPatient.isDivorceeOfInsured' => \&FreeB_FBPatient_isDivorceeOfInsured,
1374 //'FreeB.FBPatient.isSelfOfInsured' => \&FreeB_FBPatient_isSelfOfInsured,
1375 //'FreeB.FBPatient.isOtherOfInsured' => \&FreeB_FBPatient_isOtherOfInsured,
1376 //'FreeB.FBPatient.ReferringProviderKey' => \&FreeB_FBPatient_ReferringProviderKey,
1377 //'FreeB.FBPatient.SocialSecurityNumber' => \&FreeB_FBPatient_SocialSecurityNumber,
1378 //'FreeB.FBPatient.CoverageCount' => \&FreeB_FBPatient_CoverageCount,
1379 //'FreeB.FBPatient.X12InsuredRelationship' => \&FreeB_FBPatient_X12InsuredRelationship,
1380 //'FreeB.FBPatient.isPregnant' => \&FreeB_FBPatient_isPregnant,