2 require_once("DataObjectBase.class.php");
3 require_once("xmlrpc.inc");
4 class Procedure
Extends DataObjectBase
{
6 function Procedure($xuser) {
7 parent
::DataObjectBase($xuser);
8 $this->_addFunc("isusingclearinghouse", array( "name" => "FreeB.FBProcedure.isUsingClearingHouse",
9 "sig" => array(XMLRPCSTRING
,XMLRPCINT
),
11 $this->_addFunc("cpt4code", array( "name" => "FreeB.FBProcedure.CPT4Code",
12 "sig" => array(XMLRPCSTRING
,XMLRPCINT
),
14 $this->_addFunc("cpt5code", array( "name" => "FreeB.FBProcedure.CPT5Code",
15 "sig" => array(XMLRPCSTRING
,XMLRPCINT
),
17 $this->_addFunc("cptunits", array( "name" => "FreeB.FBProcedure.CPTUnits",
18 "sig" => array(XMLRPCSTRING
,XMLRPCINT
),
20 $this->_addFunc("cptmodifier", array( "name" => "FreeB.FBProcedure.CPTModifier",
21 "sig" => array(XMLRPCSTRING
,XMLRPCINT
),
23 $this->_addFunc("cptcharges", array( "name" => "FreeB.FBProcedure.CPTCharges",
24 "sig" => array(XMLRPCSTRING
,XMLRPCINT
),
26 $this->_addFunc("cptemergency", array( "name" => "FreeB.FBProcedure.CPTEmergency",
27 "sig" => array(XMLRPCSTRING
,XMLRPCINT
),
29 $this->_addFunc("cptcob", array( "name" => "FreeB.FBProcedure.CPTCOB",
30 "sig" => array(XMLRPCSTRING
,XMLRPCINT
),
32 $this->_addFunc("cptepsdt", array( "name" => "FreeB.FBProcedure.CPTEPSDT",
33 "sig" => array(XMLRPCSTRING
,XMLRPCINT
),
35 $this->_addFunc("amountpaid", array( "name" => "FreeB.FBProcedure.AmountPaid",
36 "sig" => array(XMLRPCSTRING
,XMLRPCARRAY
),
38 $this->_addFunc("typeofservice", array( "name" => "FreeB.FBProcedure.TypeOfService",
39 "sig" => array(XMLRPCSTRING
,XMLRPCINT
),
41 $this->_addFunc("priorauth", array( "name" => "FreeB.FBProcedure.PriorAuth",
42 "sig" => array(XMLRPCSTRING
,XMLRPCINT
),
44 $this->_addFunc("dateofservicestart", array( "name" => "FreeB.FBProcedure.DateOfServiceStart",
45 "sig" => array(XMLRPCSTRING
,XMLRPCINT
),
47 $this->_addFunc("dateofserviceend", array( "name" => "FreeB.FBProcedure.DateOfServiceEnd",
48 "sig" => array(XMLRPCSTRING
,XMLRPCINT
),
50 $this->_addFunc("dateofhospitalstart", array( "name" => "FreeB.FBProcedure.DateOfHospitalStart",
51 "sig" => array(XMLRPCSTRING
,XMLRPCINT
),
53 $this->_addFunc("ishospitalized", array( "name" => "FreeB.FBProcedure.isHospitalized",
54 "sig" => array(XMLRPCSTRING
,XMLRPCINT
),
56 $this->_addFunc("isoutsidelab", array( "name" => "FreeB.FBProcedure.isOutsideLab",
57 "sig" => array(XMLRPCSTRING
,XMLRPCINT
),
59 $this->_addFunc("outsidelabcharges", array( "name" => "FreeB.FBProcedure.OutsideLabCharges",
60 "sig" => array(XMLRPCSTRING
,XMLRPCINT
),
62 $this->_addFunc("dateofhospitalend", array( "name" => "FreeB.FBProcedure.DateOfHospitalEnd",
63 "sig" => array(XMLRPCSTRING
,XMLRPCINT
),
65 $this->_addFunc("medicaidresubmissioncode", array( "name" => "FreeB.FBProcedure.MedicaidResubmissionCode",
66 "sig" => array(XMLRPCSTRING
,XMLRPCINT
),
68 $this->_addFunc("medicaidoriginalreference",array( "name" => "FreeB.FBProcedure.MedicaidOriginalReference",
69 "sig" => array(XMLRPCSTRING
,XMLRPCINT
),
71 $this->_addFunc("weightgrams", array( "name" => "FreeB.FBProcedure.WeightGrams",
72 "sig" => array(XMLRPCSTRING
,XMLRPCINT
,XMLRPCSTRING
),
74 $this->_addFunc("weightpounds", array( "name" => "FreeB.FBProcedure.WeightPounds",
75 "sig" => array(XMLRPCSTRING
,XMLRPCINT
),
77 $this->_addFunc("hcfalocaluse10d", array( "name" => "FreeB.FBProcedure.HCFALocalUse10d",
78 "sig" => array(XMLRPCSTRING
,XMLRPCINT
),
80 $this->_addFunc("hcfalocaluse19", array( "name" => "FreeB.FBProcedure.HCFALocalUse19",
81 "sig" => array(XMLRPCSTRING
,XMLRPCINT
),
83 $this->_addFunc("procarray", array( "name" => "FreeB.FBProcedure.ProcArray",
84 "sig" => array(XMLRPCSTRING
,XMLRPCSTRING
),
86 $this->_addFunc("diagarray", array( "name" => "FreeB.FBProcedure.DiagArray",
87 "sig" => array(XMLRPCSTRING
,XMLRPCINT
),
89 $this->_addFunc("patientkey", array( "name" => "FreeB.FBProcedure.PatientKey",
90 "sig" => array(XMLRPCSTRING
,XMLRPCINT
),
92 $this->_addFunc("practicekey", array( "name" => "FreeB.FBProcedure.PracticeKey",
93 "sig" => array(XMLRPCSTRING
,XMLRPCINT
),
95 $this->_addFunc("providerkey", array( "name" => "FreeB.FBProcedure.ProviderKey",
96 "sig" => array(XMLRPCSTRING
,XMLRPCINT
),
98 $this->_addFunc("referringproviderkey", array( "name" => "FreeB.FBPatient.ReferringProviderKey",
99 "sig" => array(XMLRPCSTRING
,XMLRPCINT
),
101 $this->_addFunc("insuredkey", array( "name" => "FreeB.FBProcedure.InsuredKey",
102 "sig" => array(XMLRPCSTRING
,XMLRPCINT
),
104 $this->_addFunc("otherinsuredkey", array( "name" => "FreeB.FBProcedure.OtherInsuredKey",
105 "sig" => array(XMLRPCSTRING
,XMLRPCINT
),
107 $this->_addFunc("payerkey", array( "name" => "FreeB.FBProcedure.PayerKey",
108 "sig" => array(XMLRPCSTRING
,XMLRPCINT
),
110 $this->_addFunc("secondpayerkey", array( "name" => "FreeB.FBProcedure.SecondPayerKey",
111 "sig" => array(XMLRPCSTRING
,XMLRPCINT
),
113 $this->_addFunc("facilitykey", array( "name" => "FreeB.FBProcedure.FacilityKey",
114 "sig" => array(XMLRPCSTRING
,XMLRPCINT
),
116 $this->_addFunc("billingcontactkey",array( "name" => "FreeB.FBProcedure.BillingContactKey",
117 "sig" => array(XMLRPCSTRING
,XMLRPCINT
),
119 $this->_addFunc("billingservicekey",array( "name" => "FreeB.FBProcedure.BillingServiceKey",
120 "sig" => array(XMLRPCSTRING
,XMLRPCINT
),
122 $this->_addFunc("isusingbillingservice",array( "name" => "FreeB.FBProcedure.isUsingBillingService",
123 "sig" => array(XMLRPCSTRING
,XMLRPCINT
),
125 $this->_addFunc("clearinghousekey", array( "name" => "FreeB.FBProcedure.ClearingHouseKey",
126 "sig" => array(XMLRPCSTRING
,XMLRPCINT
),
131 function isusingclearinghouse($m) {
137 // if we generated an error, create an error return response
139 return $this->_handleError($err);
142 // otherwise, we create the right response
143 // with the state name
144 return new xmlrpcresp(new xmlrpcval($retval,"i4"));
148 function cpt4code($m) {
152 $obj= $m->getparam(0);
153 $key = $obj->getval();
155 $sql = "SELECT * FROM billing where id = '" . $key . "'";
157 $db = $GLOBALS['adodb']['db'];
158 $results = $db->Execute($sql);
161 $err = $db->ErrorMsg();
164 if (!$results->EOF
) {
165 $retval = $results->fields
['code'];
169 // if we generated an error, create an error return response
171 return $this->_handleError($err);
174 // otherwise, we create the right response
175 // with the state name
176 return new xmlrpcresp(new xmlrpcval($retval,"string"));
180 function cpt5code($m) {
186 // if we generated an error, create an error return response
188 return $this->_handleError($err);
191 // otherwise, we create the right response
192 // with the state name
193 return new xmlrpcresp(new xmlrpcval($pkey,"i4"));
197 function cptunits($m) {
201 $obj= $m->getparam(0);
202 $key = $obj->getval();
204 $sql = "SELECT * FROM billing where id = '" . $key . "'";
206 $db = $GLOBALS['adodb']['db'];
207 $results = $db->Execute($sql);
210 $err = $db->ErrorMsg();
213 if (!$results->EOF
) {
214 $retval = $results->fields
['units'];
218 if (empty ($retval) ||
$retval < 1) {
222 // if we generated an error, create an error return response
224 return $this->_handleError($err);
227 // otherwise, we create the right response
228 // with the state name
229 return new xmlrpcresp(new xmlrpcval($retval,"string"));
234 function cptmodifier($m) {
238 $obj= $m->getparam(0);
239 $key = $obj->getval();
241 $sql = "SELECT * FROM billing where id = '" . $key . "'";
243 $db = $GLOBALS['adodb']['db'];
244 $results = $db->Execute($sql);
247 $err = $db->ErrorMsg();
250 if (!$results->EOF
) {
251 $retval = $results->fields
['modifier'];
255 // if we generated an error, create an error return response
257 return $this->_handleError($err);
260 // otherwise, we create the right response
261 // with the state name
262 return new xmlrpcresp(new xmlrpcval($retval,"string"));
267 function cptcharges($m) {
271 $obj= $m->getparam(0);
272 $key = $obj->getval();
274 $sql = "SELECT * FROM billing where id = '" . $key . "'";
276 $db = $GLOBALS['adodb']['db'];
277 $results = $db->Execute($sql);
280 $err = $db->ErrorMsg();
283 if (!$results->EOF
) {
284 $retval = $results->fields
['fee'];
288 // if we generated an error, create an error return response
290 return $this->_handleError($err);
293 // otherwise, we create the right response
294 // with the state name
295 return new xmlrpcresp(new xmlrpcval($retval,"double"));
299 function cptemergency($m) {
305 // if we generated an error, create an error return response
307 return $this->_handleError($err);
310 // otherwise, we create the right response
311 // with the state name
312 return new xmlrpcresp(new xmlrpcval($pkey));
316 function cptcob($m) {
322 // if we generated an error, create an error return response
324 return $this->_handleError($err);
327 // otherwise, we create the right response
328 // with the state name
329 return new xmlrpcresp(new xmlrpcval($pkey));
333 function cptepsdt($m) {
339 // if we generated an error, create an error return response
341 return $this->_handleError($err);
344 // otherwise, we create the right response
345 // with the state name
346 return new xmlrpcresp(new xmlrpcval($pkey));
350 function amountpaid($m) {
354 $obj= $m->getparam(0);
355 $key = $obj->getval();
357 $sql = "SELECT * FROM billing where encounter = '" . $_SESSION['billkey'] . "' and pid = '" . $_SESSION['patient_id'] . "' and code_type = 'COPAY'";
359 $db = $GLOBALS['adodb']['db'];
360 $results = $db->Execute($sql);
363 $err = $db->ErrorMsg();
366 if (!$results->EOF
) {
367 $retval = $results->fields
['fee'];
371 if (empty($retval)) {
375 $retval = str_replace(".","",$retval);
377 // if we generated an error, create an error return response
379 return $this->_handleError($err);
382 // otherwise, we create the right response
383 // with the state name
384 return new xmlrpcresp(new xmlrpcval($retval,"i4"));
388 function typeofservice($m) {
392 $obj= $m->getparam(0);
393 $key = $obj->getval();
395 //phased out by HIPPA, use cpt modifiers instead
397 // if we generated an error, create an error return response
399 return $this->_handleError($err);
402 // otherwise, we create the right response
403 // with the state name
404 return new xmlrpcresp(new xmlrpcval($retval,"string"));
408 function priorauth($m) {
412 $obj= $m->getparam(0);
413 $key = $obj->getval();
415 $sql = "SELECT * FROM forms JOIN form_prior_auth as fpa on fpa.id = forms.form_id where forms.encounter = '" . $_SESSION['billkey'] . "' and forms.pid = '" . $_SESSION['patient_id'] . "' and forms.formdir = 'prior_auth' order by forms.date";
417 $db = $GLOBALS['adodb']['db'];
418 $results = $db->Execute($sql);
421 $err = $db->ErrorMsg();
424 if (!$results->EOF
) {
425 $retval = $results->fields
['prior_auth_number'];
428 // if we generated an error, create an error return response
430 return $this->_handleError($err);
433 // otherwise, we create the right response
434 // with the state name
435 return new xmlrpcresp(new xmlrpcval($retval,"string"));
439 function dateofservicestart($m) {
444 $obj= $m->getparam(0);
445 $key = $obj->getval();
447 $sql = "SELECT * FROM billing where pid = '" . $_SESSION['patient_id'] . "' and encounter = '" . $_SESSION['billkey'] . "'and id ='" . $key ."'";
449 $db = $GLOBALS['adodb']['db'];
450 $results = $db->Execute($sql);
453 $err = $db->ErrorMsg();
456 if (!$results->EOF
) {
457 $retval = $results->fields
['date'];
462 $retval = $this->_isodate(date("Y-m-d",strtotime($retval)));
464 // if we generated an error, create an error return response
466 return $this->_handleError($err);
469 // otherwise, we create the right response
470 // with the state name
471 return new xmlrpcresp(new xmlrpcval($retval,XMLRPCDATETIME
));
475 function dateofserviceend($m) {
480 $obj= $m->getparam(0);
481 $key = $obj->getval();
483 $sql = "SELECT * FROM billing where pid = '" . $_SESSION['patient_id'] . "' and encounter = '" . $_SESSION['billkey'] . "'and id ='" . $key ."'";
485 $db = $GLOBALS['adodb']['db'];
486 $results = $db->Execute($sql);
489 $err = $db->ErrorMsg();
492 if (!$results->EOF
) {
493 $retval = $results->fields
['date'];
497 $retval = $this->_isodate(date("Y-m-d",strtotime($retval)));
499 // if we generated an error, create an error return response
501 return $this->_handleError($err);
504 // otherwise, we create the right response
505 // with the state name
506 return new xmlrpcresp(new xmlrpcval($retval,XMLRPCDATETIME
));
510 function dateofhospitalstart($m) {
514 //$pkey = $this->_isodate("1970-08-20");
515 //unimplemented by OpenEMR
517 // if we generated an error, create an error return response
519 return $this->_handleError($err);
522 // otherwise, we create the right response
523 // with the state name
524 return new xmlrpcresp(new xmlrpcval($pkey,XMLRPCDATETIME
));
528 function ishospitalized($m) {
534 // if we generated an error, create an error return response
536 return $this->_handleError($err);
539 // otherwise, we create the right response
540 // with the state name
541 return new xmlrpcresp(new xmlrpcval($pkey,"i4"));
545 function isoutsidelab($m) {
548 //unimplemented by OpenEMR
551 // if we generated an error, create an error return response
553 return $this->_handleError($err);
556 // otherwise, we create the right response
557 // with the state name
558 return new xmlrpcresp(new xmlrpcval($pkey,"i4"));
562 function outsidelabcharges($m) {
566 //unimplemented by OpenEMR
569 // if we generated an error, create an error return response
571 return $this->_handleError($err);
574 // otherwise, we create the right response
575 // with the state name
576 return new xmlrpcresp(new xmlrpcval($pkey));
580 function dateofhospitalend($m) {
584 //$pkey = $this->_isodate("1970-08-20");
585 //unimplemented by OpenEMR
587 // if we generated an error, create an error return response
589 return $this->_handleError($err);
592 // otherwise, we create the right response
593 // with the state name
594 return new xmlrpcresp(new xmlrpcval($pkey,XMLRPCDATETIME
));
599 function medicaidresubmissioncode($m) {
604 //unimplemented by OpenEMR
606 // if we generated an error, create an error return response
608 return $this->_handleError($err);
611 // otherwise, we create the right response
612 // with the state name
613 return new xmlrpcresp(new xmlrpcval($pkey));
617 function medicaidoriginalreference($m) {
621 //unimplemented by OpenEMR
624 // if we generated an error, create an error return response
626 return $this->_handleError($err);
629 // otherwise, we create the right response
630 // with the state name
631 return new xmlrpcresp(new xmlrpcval($pkey,"string"));
636 function weightgrams($m) {
642 // if we generated an error, create an error return response
644 return $this->_handleError($err);
647 // otherwise, we create the right response
648 // with the state name
649 return new xmlrpcresp(new xmlrpcval($pkey));
653 function weightpounds($m) {
656 //unimplemented by OpenEMR
659 // if we generated an error, create an error return response
661 return $this->_handleError($err);
664 // otherwise, we create the right response
665 // with the state name
666 return new xmlrpcresp(new xmlrpcval($pkey));
670 function hcfalocaluse10d($m) {
674 //this needs to be customized on a payer to payer and state to state basis
677 // if we generated an error, create an error return response
679 return $this->_handleError($err);
682 // otherwise, we create the right response
683 // with the state name
684 return new xmlrpcresp(new xmlrpcval($pkey,"string"));
688 function hcfalocaluse19($m) {
692 //this needs to be customized on a payer to payer and state to state basis
695 // if we generated an error, create an error return response
697 return $this->_handleError($err);
700 // otherwise, we create the right response
701 // with the state name
702 return new xmlrpcresp(new xmlrpcval($pkey,"string"));
706 function procarray($m) {
712 $obj= $m->getparam(0);
713 $key = $obj->getval();
715 $keys = split("-",$key);
716 $patient_id = $keys[0];
717 $encounter = $keys[1];
719 $_SESSION['billkey'] = $encounter;
720 $_SESSION['patient_id'] = $patient_id;
722 // Sort by procedure timestamp in order to get some consistency. In particular
723 // freeb determines the provider from the first procedure in this array.
724 $sql = "SELECT * FROM billing where (code_type = 'CPT4' or code_type = 'HCPCS') AND " .
725 "encounter = '$encounter' AND pid = '$patient_id' and activity = '1' " .
728 $db = $GLOBALS['adodb']['db'];
729 $results = $db->Execute($sql);
732 $err = $db->ErrorMsg();
735 while (!$results->EOF
) {
736 $procs[] = new xmlrpcval($results->fields
['id'],"i4");
737 $results->MoveNext();
742 // if we generated an error, create an error return response
744 return $this->_handleError($err);
747 // otherwise, we create the right response
748 // with the state name
749 return new xmlrpcresp(new xmlrpcval($procs,"array"));
753 function diagarray($m) {
758 $obj= $m->getparam(0);
759 $key = $obj->getval();
761 $sql = "SELECT * FROM billing where id = '$key'";
763 $db = $GLOBALS['adodb']['db'];
764 $results = $db->Execute($sql);
767 $err = $db->ErrorMsg();
770 if (!$results->EOF
) {
771 $diagstring = $results->fields
['justify'];
775 if (!empty($diagstring)) {
777 $diag_codes = split(":",$diagstring);
779 foreach ($diag_codes as $dc) {
781 $diag_sql .= "'$dc',";
784 if (substr($diag_sql,strlen($diag_sql) -1) == ",") {
785 $diag_sql = substr($diag_sql,0,strlen($diag_sql) -1);
788 $sql = "SELECT * FROM billing where code in ($diag_sql) and code_type = 'ICD9' AND encounter = '" . $_SESSION['billkey'] . "' and pid ='" . $_SESSION['patient_id'] . "' and activity = '1'";
790 $results = $db->Execute($sql);
792 $err .= $db->ErrorMsg();
795 while (!$results->EOF
) {
796 $diags[$results->fields
['code']] = new xmlrpcval($results->fields
['id'],"i4");
797 $results->MoveNext();
801 $tmp_keys = array_keys($tmp_diags);
803 foreach ($diag_codes as $code) {
804 if (in_array($code,$tmp_keys)) {
805 $diags[] = $tmp_diags[$code];
810 $diags[] = new xmlrpcval(0,"i4");
815 // if we generated an error, create an error return response
817 return $this->_handleError($err);
820 // otherwise, we create the right response
821 // with the state name
822 return new xmlrpcresp(new xmlrpcval($diags,"array"));
826 function patientkey($m) {
831 $pkey = $_SESSION['patient_id'];
833 // if we generated an error, create an error return response
835 return $this->_handleError($err);
838 // otherwise, we create the right response
839 // with the state name
840 return new xmlrpcresp(new xmlrpcval($pkey,"i4"));
844 function practicekey($m) {
848 $sql = "SELECT * FROM form_encounter where encounter = '" . $_SESSION['billkey'] ."' and pid = '" . $_SESSION['patient_id'] ."'";
850 $db = $GLOBALS['adodb']['db'];
851 $results = $db->Execute($sql);
854 $err = $db->ErrorMsg();
857 if (!$results->EOF
) {
858 $fname = $results->fields
['facility'];
862 $sql = "SELECT * FROM facility where name = '" . $fname ."'";
864 $db = $GLOBALS['adodb']['db'];
865 $results = $db->Execute($sql);
868 $err = $db->ErrorMsg();
871 if (!$results->EOF
) {
872 $fkey = $results->fields
['id'];
876 // if we generated an error, create an error return response
878 return $this->_handleError($err);
881 // otherwise, we create the right response
882 // with the state name
883 return new xmlrpcresp(new xmlrpcval($fkey,"i4"));
887 function providerkey($m) {
892 $obj= $m->getparam(0);
893 $key = $obj->getval();
895 $sql = "SELECT * FROM billing where id = '" . $key . "'";
897 $db = $GLOBALS['adodb']['db'];
898 $results = $db->Execute($sql);
901 $err = $db->ErrorMsg();
904 if (!$results->EOF
) {
905 $pkey = $results->fields
['provider_id'];
909 // if we generated an error, create an error return response
911 return $this->_handleError($err);
914 // otherwise, we create the right response
915 // with the state name
916 return new xmlrpcresp(new xmlrpcval($pkey,"i4"));
920 function referringproviderkey($m) {
925 $obj= $m->getparam(0);
926 $key = $obj->getval();
928 $sql = "SELECT * FROM patient_data where pid = '" . $key . "'";
930 $db = $GLOBALS['adodb']['db'];
931 $results = $db->Execute($sql);
934 $err = $db->ErrorMsg();
937 if (!$results->EOF
) {
938 $pkey = $results->fields
['providerID'];
943 // if we generated an error, create an error return response
945 return $this->_handleError($err);
948 // otherwise, we create the right response
949 // with the state name
950 return new xmlrpcresp(new xmlrpcval($pkey,"i4"));
954 function insuredkey($m) {
959 $obj= $m->getparam(0);
960 $key = $obj->getval();
962 $sql = "SELECT * FROM billing where id = '" . $key . "'";
964 $db = $GLOBALS['adodb']['db'];
965 $results = $db->Execute($sql);
968 $err = $db->ErrorMsg();
971 if (!$results->EOF
) {
972 $payer_id = $results->fields
['payer_id'];
978 $sql = "SELECT * FROM insurance_data where pid = '" . $_SESSION['patient_id'] . "' and provider = '" . $payer_id . "'";
980 $db = $GLOBALS['adodb']['db'];
981 $results = $db->Execute($sql);
984 $err = $db->ErrorMsg();
987 if (!$results->EOF
) {
988 $insured_id = $results->fields
['id'];
991 //we are returning the record id of the appropriate entry in insurance_data
992 //there is no relational data, all the subscriber/insured information is kept monolithically in that table
994 // if we generated an error, create an error return response
996 return $this->_handleError($err);
999 // otherwise, we create the right response
1000 // with the state name
1001 return new xmlrpcresp(new xmlrpcval($insured_id,"i4"));
1005 function otherinsuredkey($m) {
1008 //openemr does not currently implement other insured
1011 // if we generated an error, create an error return response
1013 return $this->_handleError($err);
1016 // otherwise, we create the right response
1017 // with the state name
1018 return new xmlrpcresp(new xmlrpcval($pkey,"i4"));
1022 function payerkey($m) {
1026 $obj= $m->getparam(0);
1027 $key = $obj->getval();
1029 $sql = "SELECT * FROM billing where id = '" . $key . "'";
1030 $db = $GLOBALS['adodb']['db'];
1031 $results = $db->Execute($sql);
1035 $err = $db->ErrorMsg() . " $sql";
1038 while (!$results->EOF
) {
1039 $pkey = $results->fields
['payer_id'];
1040 $results->MoveNext();
1044 // if we generated an error, create an error return response
1046 return $this->_handleError($err);
1049 // otherwise, we create the right response
1050 // with the state name
1051 return new xmlrpcresp(new xmlrpcval($pkey,"i4"));
1055 function secondpayerkey($m) {
1058 //unimplemented by OpenEMR
1061 // if we generated an error, create an error return response
1063 return $this->_handleError($err);
1066 // otherwise, we create the right response
1067 // with the state name
1068 return new xmlrpcresp(new xmlrpcval($pkey,"i4"));
1072 function facilitykey($m) {
1078 $obj= $m->getparam(0);
1079 $key = $obj->getval();
1081 $sql = "SELECT * FROM billing where id = '" . $key . "'";
1083 $db = $GLOBALS['adodb']['db'];
1084 $results = $db->Execute($sql);
1087 $err = $db->ErrorMsg();
1090 if (!$results->EOF
) {
1091 $eid = $results->fields
['encounter'];
1092 $patient_id = $results->fields
['pid'];
1096 $sql = "SELECT * FROM form_encounter where encounter = '" . $eid ."' and pid = '" . $patient_id ."'";
1098 $results = $db->Execute($sql);
1101 $err = $db->ErrorMsg();
1104 if (!$results->EOF
) {
1105 $fname = $results->fields
['facility'];
1109 $sql = "SELECT * FROM facility where name = '" . $fname ."'";
1110 $results = $db->Execute($sql);
1113 $err = $db->ErrorMsg();
1116 if (!$results->EOF
) {
1117 $fkey = $results->fields
['id'];
1121 // if we generated an error, create an error return response
1123 return $this->_handleError($err);
1126 // otherwise, we create the right response
1127 // with the state name
1128 return new xmlrpcresp(new xmlrpcval($fkey,"i4"));
1132 function billingcontactkey($m) {
1138 // if we generated an error, create an error return response
1140 return $this->_handleError($err);
1143 // otherwise, we create the right response
1144 // with the state name
1145 return new xmlrpcresp(new xmlrpcval($pkey,"i4"));
1148 function billingservicekey($m) {
1154 // if we generated an error, create an error return response
1156 return $this->_handleError($err);
1159 // otherwise, we create the right response
1160 // with the state name
1161 return new xmlrpcresp(new xmlrpcval($pkey,"i4"));
1166 function isusingbillingservice($m) {
1172 // if we generated an error, create an error return response
1174 return $this->_handleError($err);
1177 // otherwise, we create the right response
1178 // with the state name
1179 return new xmlrpcresp(new xmlrpcval($pkey,"i4"));
1183 function clearinghousekey($m) {
1191 $obj= $m->getparam(0);
1192 $key = $obj->getval();
1194 $sql = "SELECT * FROM billing where id = '" . $key . "'";
1196 $db = $GLOBALS['adodb']['db'];
1197 $results = $db->Execute($sql);
1200 $err = $db->ErrorMsg();
1203 if (!$results->EOF
) {
1204 $eid = $results->fields
['encounter'];
1205 $patient_id = $results->fields
['pid'];
1209 $sql = "SELECT * FROM form_encounter where encounter = '" . $eid ."' and pid = '" . $patient_id ."'";
1211 $results = $db->Execute($sql);
1214 $err = $db->ErrorMsg();
1217 if (!$results->EOF
) {
1218 $fname = $results->fields
['facility'];
1222 $sql = "SELECT * FROM facility where name = '" . $fname ."'";
1223 $results = $db->Execute($sql);
1226 $err = $db->ErrorMsg();
1229 if (!$results->EOF
) {
1230 $fkey = $results->fields
['id'];
1234 // if we generated an error, create an error return response
1236 return $this->_handleError($err);
1239 // otherwise, we create the right response
1240 // with the state name
1241 return new xmlrpcresp(new xmlrpcval($fkey,"i4"));
1250 //'FreeB.FBProcedure.isUsingClearingHouse' => \&FreeB_FBProcedure_isUsingClearingHouse,
1251 //'FreeB.FBProcedure.ProcArray' => \&FreeB_FBProcedure_ProcArray,
1252 //'FreeB.FBProcedure.DiagArray' => \&FreeB_FBProcedure_DiagArray,
1253 //'FreeB.FBProcedure.CPT4Code' => \&FreeB_FBProcedure_CPT4Code,
1254 //'FreeB.FBProcedure.CPT5Code' => \&FreeB_FBProcedure_CPT4Code,
1255 //'FreeB.FBProcedure.CPTUnits' => \&FreeB_FBProcedure_CPTUnits,
1256 //'FreeB.FBProcedure.CPTModifier' => \&FreeB_FBProcedure_CPTModifier,
1257 //'FreeB.FBProcedure.CPTCharges' => \&FreeB_FBProcedure_CPTCharges,
1258 //'FreeB.FBProcedure.CPTEmergency' => \&FreeB_FBProcedure_CPTEmergency,
1259 //'FreeB.FBProcedure.CPTCOB' => \&FreeB_FBProcedure_CPTCOB,
1260 //'FreeB.FBProcedure.CPTEPSDT' => \&FreeB_FBProcedure_CPTEPSDT,
1261 //'FreeB.FBProcedure.AmountPaid' => \&FreeB_FBProcedure_AmountPaid,
1262 //'FreeB.FBProcedure.TypeOfService' => \&FreeB_FBProcedure_TypeOfService,
1263 //'FreeB.FBProcedure.PriorAuth' => \&FreeB_FBProcedure_PriorAuth,
1264 //'FreeB.FBProcedure.DateOfServiceStart' => \&FreeB_FBProcedure_DateOfServiceStart,
1265 //'FreeB.FBProcedure.DateOfServiceEnd' => \&FreeB_FBProcedure_DateOfServiceEnd,
1266 //'FreeB.FBProcedure.DateOfHospitalStart' => \&FreeB_FBProcedure_DateOfHospitalStart,
1267 //'FreeB.FBProcedure.isHospitalized' => \&FreeB_FBProcedure_isHospitalized,
1268 //'FreeB.FBProcedure.isOutsideLab' => \&FreeB_FBProcedure_isOutsideLab,
1269 //'FreeB.FBProcedure.OutsideLabCharges' => \&FreeB_FBProcedure_OutSideLabCharges,
1270 //'FreeB.FBProcedure.DateOfHospitalEnd' => \&FreeB_FBProcedure_DateOfHospitalEnd,
1271 //'FreeB.FBProcedure.MedicaidResubmissionCode' => \&FreeB_FBProcedure_MedicaidResubmissionCode,
1272 //'FreeB.FBProcedure.MedicaidOriginalReference' => \&FreeB_FBProcedure_MedicaidOriginalReference,
1273 //'FreeB.FBProcedure.WeightGrams' => \&FreeB_FBProcedure_WeightGrams,
1274 //'FreeB.FBProcedure.WeightPounds' => \&FreeB_FBProcedure_WeightPounds,
1275 //'FreeB.FBProcedure.HCFALocalUse10d' => \&FreeB_FBProcedure_HCFALocalUse10d,
1276 //'FreeB.FBProcedure.HCFALocalUse19' => \&FreeB_FBProcedure_HCFALocalUse19,