Translation project - clean up a duplicate constant
[openemr.git] / library / freeb / Procedure.class.php
blob81b1300469c8f1ab745f783d77c3e3d9d317b942
1 <?php
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),
10 "doc" => ""));
11 $this->_addFunc("cpt4code", array( "name" => "FreeB.FBProcedure.CPT4Code",
12 "sig" => array(XMLRPCSTRING,XMLRPCINT),
13 "doc" => ""));
14 $this->_addFunc("cpt5code", array( "name" => "FreeB.FBProcedure.CPT5Code",
15 "sig" => array(XMLRPCSTRING,XMLRPCINT),
16 "doc" => ""));
17 $this->_addFunc("cptunits", array( "name" => "FreeB.FBProcedure.CPTUnits",
18 "sig" => array(XMLRPCSTRING,XMLRPCINT),
19 "doc" => ""));
20 $this->_addFunc("cptmodifier", array( "name" => "FreeB.FBProcedure.CPTModifier",
21 "sig" => array(XMLRPCSTRING,XMLRPCINT),
22 "doc" => ""));
23 $this->_addFunc("cptcharges", array( "name" => "FreeB.FBProcedure.CPTCharges",
24 "sig" => array(XMLRPCSTRING,XMLRPCINT),
25 "doc" => ""));
26 $this->_addFunc("cptemergency", array( "name" => "FreeB.FBProcedure.CPTEmergency",
27 "sig" => array(XMLRPCSTRING,XMLRPCINT),
28 "doc" => ""));
29 $this->_addFunc("cptcob", array( "name" => "FreeB.FBProcedure.CPTCOB",
30 "sig" => array(XMLRPCSTRING,XMLRPCINT),
31 "doc" => ""));
32 $this->_addFunc("cptepsdt", array( "name" => "FreeB.FBProcedure.CPTEPSDT",
33 "sig" => array(XMLRPCSTRING,XMLRPCINT),
34 "doc" => ""));
35 $this->_addFunc("amountpaid", array( "name" => "FreeB.FBProcedure.AmountPaid",
36 "sig" => array(XMLRPCSTRING,XMLRPCARRAY),
37 "doc" => ""));
38 $this->_addFunc("typeofservice", array( "name" => "FreeB.FBProcedure.TypeOfService",
39 "sig" => array(XMLRPCSTRING,XMLRPCINT),
40 "doc" => ""));
41 $this->_addFunc("priorauth", array( "name" => "FreeB.FBProcedure.PriorAuth",
42 "sig" => array(XMLRPCSTRING,XMLRPCINT),
43 "doc" => ""));
44 $this->_addFunc("dateofservicestart", array( "name" => "FreeB.FBProcedure.DateOfServiceStart",
45 "sig" => array(XMLRPCSTRING,XMLRPCINT),
46 "doc" => ""));
47 $this->_addFunc("dateofserviceend", array( "name" => "FreeB.FBProcedure.DateOfServiceEnd",
48 "sig" => array(XMLRPCSTRING,XMLRPCINT),
49 "doc" => ""));
50 $this->_addFunc("dateofhospitalstart", array( "name" => "FreeB.FBProcedure.DateOfHospitalStart",
51 "sig" => array(XMLRPCSTRING,XMLRPCINT),
52 "doc" => ""));
53 $this->_addFunc("ishospitalized", array( "name" => "FreeB.FBProcedure.isHospitalized",
54 "sig" => array(XMLRPCSTRING,XMLRPCINT),
55 "doc" => ""));
56 $this->_addFunc("isoutsidelab", array( "name" => "FreeB.FBProcedure.isOutsideLab",
57 "sig" => array(XMLRPCSTRING,XMLRPCINT),
58 "doc" => ""));
59 $this->_addFunc("outsidelabcharges", array( "name" => "FreeB.FBProcedure.OutsideLabCharges",
60 "sig" => array(XMLRPCSTRING,XMLRPCINT),
61 "doc" => ""));
62 $this->_addFunc("dateofhospitalend", array( "name" => "FreeB.FBProcedure.DateOfHospitalEnd",
63 "sig" => array(XMLRPCSTRING,XMLRPCINT),
64 "doc" => ""));
65 $this->_addFunc("medicaidresubmissioncode", array( "name" => "FreeB.FBProcedure.MedicaidResubmissionCode",
66 "sig" => array(XMLRPCSTRING,XMLRPCINT),
67 "doc" => ""));
68 $this->_addFunc("medicaidoriginalreference",array( "name" => "FreeB.FBProcedure.MedicaidOriginalReference",
69 "sig" => array(XMLRPCSTRING,XMLRPCINT),
70 "doc" => ""));
71 $this->_addFunc("weightgrams", array( "name" => "FreeB.FBProcedure.WeightGrams",
72 "sig" => array(XMLRPCSTRING,XMLRPCINT,XMLRPCSTRING),
73 "doc" => ""));
74 $this->_addFunc("weightpounds", array( "name" => "FreeB.FBProcedure.WeightPounds",
75 "sig" => array(XMLRPCSTRING,XMLRPCINT),
76 "doc" => ""));
77 $this->_addFunc("hcfalocaluse10d", array( "name" => "FreeB.FBProcedure.HCFALocalUse10d",
78 "sig" => array(XMLRPCSTRING,XMLRPCINT),
79 "doc" => ""));
80 $this->_addFunc("hcfalocaluse19", array( "name" => "FreeB.FBProcedure.HCFALocalUse19",
81 "sig" => array(XMLRPCSTRING,XMLRPCINT),
82 "doc" => ""));
83 $this->_addFunc("procarray", array( "name" => "FreeB.FBProcedure.ProcArray",
84 "sig" => array(XMLRPCSTRING,XMLRPCSTRING),
85 "doc" => ""));
86 $this->_addFunc("diagarray", array( "name" => "FreeB.FBProcedure.DiagArray",
87 "sig" => array(XMLRPCSTRING,XMLRPCINT),
88 "doc" => ""));
89 $this->_addFunc("patientkey", array( "name" => "FreeB.FBProcedure.PatientKey",
90 "sig" => array(XMLRPCSTRING,XMLRPCINT),
91 "doc" => ""));
92 $this->_addFunc("practicekey", array( "name" => "FreeB.FBProcedure.PracticeKey",
93 "sig" => array(XMLRPCSTRING,XMLRPCINT),
94 "doc" => ""));
95 $this->_addFunc("providerkey", array( "name" => "FreeB.FBProcedure.ProviderKey",
96 "sig" => array(XMLRPCSTRING,XMLRPCINT),
97 "doc" => ""));
98 $this->_addFunc("referringproviderkey", array( "name" => "FreeB.FBPatient.ReferringProviderKey",
99 "sig" => array(XMLRPCSTRING,XMLRPCINT),
100 "doc" => ""));
101 $this->_addFunc("insuredkey", array( "name" => "FreeB.FBProcedure.InsuredKey",
102 "sig" => array(XMLRPCSTRING,XMLRPCINT),
103 "doc" => ""));
104 $this->_addFunc("otherinsuredkey", array( "name" => "FreeB.FBProcedure.OtherInsuredKey",
105 "sig" => array(XMLRPCSTRING,XMLRPCINT),
106 "doc" => ""));
107 $this->_addFunc("payerkey", array( "name" => "FreeB.FBProcedure.PayerKey",
108 "sig" => array(XMLRPCSTRING,XMLRPCINT),
109 "doc" => ""));
110 $this->_addFunc("secondpayerkey", array( "name" => "FreeB.FBProcedure.SecondPayerKey",
111 "sig" => array(XMLRPCSTRING,XMLRPCINT),
112 "doc" => ""));
113 $this->_addFunc("facilitykey", array( "name" => "FreeB.FBProcedure.FacilityKey",
114 "sig" => array(XMLRPCSTRING,XMLRPCINT),
115 "doc" => ""));
116 $this->_addFunc("billingcontactkey",array( "name" => "FreeB.FBProcedure.BillingContactKey",
117 "sig" => array(XMLRPCSTRING,XMLRPCINT),
118 "doc" => ""));
119 $this->_addFunc("billingservicekey",array( "name" => "FreeB.FBProcedure.BillingServiceKey",
120 "sig" => array(XMLRPCSTRING,XMLRPCINT),
121 "doc" => ""));
122 $this->_addFunc("isusingbillingservice",array("name" => "FreeB.FBProcedure.isUsingBillingService",
123 "sig" => array(XMLRPCSTRING,XMLRPCINT),
124 "doc" => ""));
125 $this->_addFunc("clearinghousekey", array( "name" => "FreeB.FBProcedure.ClearingHouseKey",
126 "sig" => array(XMLRPCSTRING,XMLRPCINT),
127 "doc" => ""));
128 $this->_addFunc("ndcline", array("name" => "FreeB.FBProcedure.NDCLine",
129 "sig" => array(XMLRPCSTRING,XMLRPCINT),
130 "doc" => ""));
134 function isusingclearinghouse($m) {
136 $err="";
138 $retval = false;
140 // if we generated an error, create an error return response
141 if ($err) {
142 return $this->_handleError($err);
144 else {
145 // otherwise, we create the right response
146 // with the state name
147 return new xmlrpcresp(new xmlrpcval($retval,"i4"));
151 function cpt4code($m) {
153 $err="";
154 $retval = "";
155 $obj= $m->getparam(0);
156 $key = $obj->getval();
158 $sql = "SELECT * FROM billing where id = '" . $key . "'";
159 //echo $sql;
160 $db = $GLOBALS['adodb']['db'];
161 $results = $db->Execute($sql);
163 if (!$results) {
164 $err = $db->ErrorMsg();
166 else {
167 if (!$results->EOF) {
168 $retval = $results->fields['code'];
172 // if we generated an error, create an error return response
173 if ($err) {
174 return $this->_handleError($err);
176 else {
177 // otherwise, we create the right response
178 // with the state name
179 return new xmlrpcresp(new xmlrpcval($retval,"string"));
183 function cpt5code($m) {
185 $err="";
187 $pkey = false;
189 // if we generated an error, create an error return response
190 if ($err) {
191 return $this->_handleError($err);
193 else {
194 // otherwise, we create the right response
195 // with the state name
196 return new xmlrpcresp(new xmlrpcval($pkey,"i4"));
200 function cptunits($m) {
202 $err="";
203 $retval = "";
204 $obj= $m->getparam(0);
205 $key = $obj->getval();
207 $sql = "SELECT * FROM billing where id = '" . $key . "'";
208 //echo $sql;
209 $db = $GLOBALS['adodb']['db'];
210 $results = $db->Execute($sql);
212 if (!$results) {
213 $err = $db->ErrorMsg();
215 else {
216 if (!$results->EOF) {
217 $retval = $results->fields['units'];
221 if (empty ($retval) || $retval < 1) {
222 $retval = 1;
225 // if we generated an error, create an error return response
226 if ($err) {
227 return $this->_handleError($err);
229 else {
230 // otherwise, we create the right response
231 // with the state name
232 return new xmlrpcresp(new xmlrpcval($retval,"string"));
237 function cptmodifier($m) {
239 $err="";
240 $retval = "";
241 $obj= $m->getparam(0);
242 $key = $obj->getval();
244 $sql = "SELECT * FROM billing where id = '" . $key . "'";
245 //echo $sql;
246 $db = $GLOBALS['adodb']['db'];
247 $results = $db->Execute($sql);
249 if (!$results) {
250 $err = $db->ErrorMsg();
252 else {
253 if (!$results->EOF) {
254 $retval = $results->fields['modifier'];
258 // if we generated an error, create an error return response
259 if ($err) {
260 return $this->_handleError($err);
262 else {
263 // otherwise, we create the right response
264 // with the state name
265 return new xmlrpcresp(new xmlrpcval($retval,"string"));
270 function cptcharges($m) {
272 $err="";
274 $obj= $m->getparam(0);
275 $key = $obj->getval();
277 $sql = "SELECT * FROM billing where id = '" . $key . "'";
278 //echo $sql;
279 $db = $GLOBALS['adodb']['db'];
280 $results = $db->Execute($sql);
282 if (!$results) {
283 $err = $db->ErrorMsg();
285 else {
286 if (!$results->EOF) {
287 $retval = $results->fields['fee'];
291 // if we generated an error, create an error return response
292 if ($err) {
293 return $this->_handleError($err);
295 else {
296 // otherwise, we create the right response
297 // with the state name
298 return new xmlrpcresp(new xmlrpcval($retval,"double"));
302 function cptemergency($m) {
304 $err="";
306 $pkey = "";
308 // if we generated an error, create an error return response
309 if ($err) {
310 return $this->_handleError($err);
312 else {
313 // otherwise, we create the right response
314 // with the state name
315 return new xmlrpcresp(new xmlrpcval($pkey));
319 function cptcob($m) {
321 $err="";
323 $pkey = "";
325 // if we generated an error, create an error return response
326 if ($err) {
327 return $this->_handleError($err);
329 else {
330 // otherwise, we create the right response
331 // with the state name
332 return new xmlrpcresp(new xmlrpcval($pkey));
336 function cptepsdt($m) {
338 $err="";
340 $pkey = "";
342 // if we generated an error, create an error return response
343 if ($err) {
344 return $this->_handleError($err);
346 else {
347 // otherwise, we create the right response
348 // with the state name
349 return new xmlrpcresp(new xmlrpcval($pkey));
353 function amountpaid($m) {
355 $err="";
357 $obj= $m->getparam(0);
358 $key = $obj->getval();
360 $sql = "SELECT * FROM billing where activity = '1' and encounter = '" . $_SESSION['billkey'] . "' and pid = '" . $_SESSION['patient_id'] . "' and code_type = 'COPAY'";
361 //echo $sql;
362 $db = $GLOBALS['adodb']['db'];
363 $results = $db->Execute($sql);
365 if (!$results) {
366 $err = $db->ErrorMsg();
368 else {
369 if (!$results->EOF) {
370 $retval = $results->fields['fee'];
374 if (empty($retval)) {
375 $retval = "0000";
378 $retval = str_replace(".","",$retval);
380 // if we generated an error, create an error return response
381 if ($err) {
382 return $this->_handleError($err);
384 else {
385 // otherwise, we create the right response
386 // with the state name
387 return new xmlrpcresp(new xmlrpcval($retval,"i4"));
391 function typeofservice($m) {
393 $err="";
394 $retval = "";
395 $obj= $m->getparam(0);
396 $key = $obj->getval();
398 //phased out by HIPPA, use cpt modifiers instead
399 $retval = "";
400 // if we generated an error, create an error return response
401 if ($err) {
402 return $this->_handleError($err);
404 else {
405 // otherwise, we create the right response
406 // with the state name
407 return new xmlrpcresp(new xmlrpcval($retval,"string"));
411 function priorauth($m) {
413 $err="";
414 $retval = "";
415 $obj= $m->getparam(0);
416 $key = $obj->getval();
418 $sql = "SELECT * FROM forms JOIN form_misc_billing_options as fpa on fpa.id = forms.form_id where forms.encounter = '" . $_SESSION['billkey'] . "' and forms.pid = '" . $_SESSION['patient_id'] . "' and forms.formdir = 'misc_billing_options' order by forms.date";
419 //echo $sql;
420 $db = $GLOBALS['adodb']['db'];
421 $results = $db->Execute($sql);
423 if (!$results) {
424 $err = $db->ErrorMsg();
426 else {
427 if (!$results->EOF) {
428 $retval = $results->fields['prior_auth_number'];
431 // if we generated an error, create an error return response
432 if ($err) {
433 return $this->_handleError($err);
435 else {
436 // otherwise, we create the right response
437 // with the state name
438 return new xmlrpcresp(new xmlrpcval($retval,"string"));
442 function dateofservicestart($m) {
444 $err="";
446 $retval = "";
447 $obj= $m->getparam(0);
448 $key = $obj->getval();
450 $sql = "SELECT * FROM billing where pid = '" . $_SESSION['patient_id'] . "' and encounter = '" . $_SESSION['billkey'] . "'and id ='" . $key ."'";
451 //echo $sql;
452 $db = $GLOBALS['adodb']['db'];
453 $results = $db->Execute($sql);
455 if (!$results) {
456 $err = $db->ErrorMsg();
458 else {
459 if (!$results->EOF) {
460 $retval = $results->fields['date'];
465 $retval = $this->_isodate(date("Y-m-d",strtotime($retval)));
467 // if we generated an error, create an error return response
468 if ($err) {
469 return $this->_handleError($err);
471 else {
472 // otherwise, we create the right response
473 // with the state name
474 return new xmlrpcresp(new xmlrpcval($retval,XMLRPCDATETIME));
478 function dateofserviceend($m) {
480 $err="";
482 $retval = "";
483 $obj= $m->getparam(0);
484 $key = $obj->getval();
486 $sql = "SELECT * FROM billing where pid = '" . $_SESSION['patient_id'] . "' and encounter = '" . $_SESSION['billkey'] . "'and id ='" . $key ."'";
487 //echo $sql;
488 $db = $GLOBALS['adodb']['db'];
489 $results = $db->Execute($sql);
491 if (!$results) {
492 $err = $db->ErrorMsg();
494 else {
495 if (!$results->EOF) {
496 $retval = $results->fields['date'];
500 $retval = $this->_isodate(date("Y-m-d",strtotime($retval)));
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,XMLRPCDATETIME));
513 function dateofhospitalstart($m) {
514 $err="";
515 //Now implemented by OpenEMR with Form: Misc Billing Options
516 $retval = "";
517 $obj= $m->getparam(0);
518 $key = $obj->getval();
520 $sql = "SELECT * FROM forms JOIN form_misc_billing_options as fpa on fpa.id = forms.form_id where forms.encounter = '" . $_SESSION['billkey'] . "' and forms.pid = '" . $_SESSION['patient_id'] . "' and forms.formdir = 'misc_billing_options' order by forms.date";
521 //echo $sql;
522 $db = $GLOBALS['adodb']['db'];
523 $results = $db->Execute($sql);
525 if (!$results) {
526 $err = $db->ErrorMsg();
528 else {
529 if (!$results->EOF) {
530 $retval = $results->fields['hospitalization_date_from'];
533 $retval = date("Y-m-d",strtotime($retval));
534 $retval = $this->_isodate($retval);
535 // if we generated an error, create an error return response
536 if ($err) {
537 return $this->_handleError($err);
539 else {
540 // otherwise, we create the right response
541 // with the state name
542 return new xmlrpcresp(new xmlrpcval($retval,XMLRPCDATETIME));
548 function ishospitalized($m) {
549 $err="";
550 //Now implemented by OpenEMR with Form: Misc Billing Options
551 $pkey = false;
552 $retval = "";
553 $obj= $m->getparam(0);
554 $key = $obj->getval();
556 $sql = "SELECT * FROM forms JOIN form_misc_billing_options as fpa on fpa.id = forms.form_id where forms.encounter = '" . $_SESSION['billkey'] . "' and forms.pid = '" . $_SESSION['patient_id'] . "' and forms.formdir = 'misc_billing_options' order by forms.date";
557 //echo $sql;
558 $db = $GLOBALS['adodb']['db'];
559 $results = $db->Execute($sql);
561 if (!$results) {
562 $err = $db->ErrorMsg();
564 else {
565 if (!$results->EOF) {
566 $retval = $results->fields['is_hospitalized'];
567 if ($retval == "1") {$pkey = true;};
570 // if we generated an error, create an error return response
571 if ($err) {
572 return $this->_handleError($err);
574 else {
575 // otherwise, we create the right response
576 // with the state name
577 return new xmlrpcresp(new xmlrpcval($pkey,"i4"));
582 function isoutsidelab($m) {
583 $err="";
584 //Now implemented by OpenEMR with Form: Misc Billing Options
585 $pkey = false;
586 $retval = "";
587 $obj= $m->getparam(0);
588 $key = $obj->getval();
590 $sql = "SELECT * FROM forms JOIN form_misc_billing_options as fpa on fpa.id = forms.form_id where forms.encounter = '" . $_SESSION['billkey'] . "' and forms.pid = '" . $_SESSION['patient_id'] . "' and forms.formdir = 'misc_billing_options' order by forms.date";
591 //echo $sql;
592 $db = $GLOBALS['adodb']['db'];
593 $results = $db->Execute($sql);
595 if (!$results) {
596 $err = $db->ErrorMsg();
598 else {
599 if (!$results->EOF) {
600 $retval = $results->fields['outside_lab'];
601 if ($retval == "1") {$pkey = true;};
604 // if we generated an error, create an error return response
605 if ($err) {
606 return $this->_handleError($err);
608 else {
609 // otherwise, we create the right response
610 // with the state name
611 return new xmlrpcresp(new xmlrpcval($pkey,"i4"));
615 function outsidelabcharges($m) {
617 $err="";
619 //Now implemented by OpenEMR with form_misc_billing_options
620 $retval = "";
621 $obj= $m->getparam(0);
622 $key = $obj->getval();
624 $sql = "SELECT * FROM forms JOIN form_misc_billing_options as fpa on fpa.id = forms.form_id where forms.encounter = '" . $_SESSION['billkey'] . "' and forms.pid = '" . $_SESSION['patient_id'] . "' and forms.formdir = 'misc_billing_options' order by forms.date";
625 //echo $sql;
626 $db = $GLOBALS['adodb']['db'];
627 $results = $db->Execute($sql);
629 if (!$results) {
630 $err = $db->ErrorMsg();
632 else {
633 if (!$results->EOF) {
634 $retval = $results->fields['lab_amount'];
638 // if we generated an error, create an error return response
639 if ($err) {
640 return $this->_handleError($err);
642 else {
643 // otherwise, we create the right response
644 // with the state name
645 return new xmlrpcresp(new xmlrpcval($retval,"double"));
649 function dateofhospitalend($m) {
650 $err="";
651 //Now implemented by OpenEMR with Form: Misc Billing Options
652 $retval = "";
653 $obj= $m->getparam(0);
654 $key = $obj->getval();
656 $sql = "SELECT * FROM forms JOIN form_misc_billing_options as fpa on fpa.id = forms.form_id where forms.encounter = '" . $_SESSION['billkey'] . "' and forms.pid = '" . $_SESSION['patient_id'] . "' and forms.formdir = 'misc_billing_options' order by forms.date";
657 //echo $sql;
658 $db = $GLOBALS['adodb']['db'];
659 $results = $db->Execute($sql);
661 if (!$results) {
662 $err = $db->ErrorMsg();
664 else {
665 if (!$results->EOF) {
666 $retval = $results->fields['hospitalization_date_to'];
669 $retval = date("Y-m-d",strtotime($retval));
670 $retval = $this->_isodate($retval);
671 // if we generated an error, create an error return response
672 if ($err) {
673 return $this->_handleError($err);
675 else {
676 // otherwise, we create the right response
677 // with the state name
678 return new xmlrpcresp(new xmlrpcval($retval,XMLRPCDATETIME));
684 function medicaidresubmissioncode($m) {
686 $err="";
687 $retval = "";
688 $obj= $m->getparam(0);
689 $key = $obj->getval();
691 $sql = "SELECT * FROM forms JOIN form_misc_billing_options as fpa on fpa.id = forms.form_id where forms.encounter = '" . $_SESSION['billkey'] . "' and forms.pid = '" . $_SESSION['patient_id'] . "' and forms.formdir = 'misc_billing_options' order by forms.date";
692 //echo $sql;
693 $db = $GLOBALS['adodb']['db'];
694 $results = $db->Execute($sql);
696 if (!$results) {
697 $err = $db->ErrorMsg();
699 else {
700 if (!$results->EOF) {
701 $retval = $results->fields['medicaid_resubmission_code'];
705 // if we generated an error, create an error return response
706 if ($err) {
707 return $this->_handleError($err);
709 else {
710 // otherwise, we create the right response
711 // with the state name
712 return new xmlrpcresp(new xmlrpcval($retval,"string"));
716 function medicaidoriginalreference($m) {
718 $err="";
719 $retval = "";
720 $obj= $m->getparam(0);
721 $key = $obj->getval();
723 $sql = "SELECT * FROM forms JOIN form_misc_billing_options as fpa on fpa.id = forms.form_id where forms.encounter = '" . $_SESSION['billkey'] . "' and forms.pid = '" . $_SESSION['patient_id'] . "' and forms.formdir = 'misc_billing_options' order by forms.date";
724 //echo $sql;
725 $db = $GLOBALS['adodb']['db'];
726 $results = $db->Execute($sql);
728 if (!$results) {
729 $err = $db->ErrorMsg();
731 else {
732 if (!$results->EOF) {
733 $retval = $results->fields['medicaid_original_reference'];
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,"string"));
749 function weightgrams($m) {
751 $err="";
753 $pkey = "2300";
755 // if we generated an error, create an error return response
756 if ($err) {
757 return $this->_handleError($err);
759 else {
760 // otherwise, we create the right response
761 // with the state name
762 return new xmlrpcresp(new xmlrpcval($pkey));
766 function weightpounds($m) {
768 $err="";
769 //unimplemented by OpenEMR
770 $pkey = "";
772 // if we generated an error, create an error return response
773 if ($err) {
774 return $this->_handleError($err);
776 else {
777 // otherwise, we create the right response
778 // with the state name
779 return new xmlrpcresp(new xmlrpcval($pkey));
783 function hcfalocaluse10d($m) {
785 $err="";
787 //this needs to be customized on a payer to payer and state to state basis
788 $pkey = "";
790 // if we generated an error, create an error return response
791 if ($err) {
792 return $this->_handleError($err);
794 else {
795 // otherwise, we create the right response
796 // with the state name
797 return new xmlrpcresp(new xmlrpcval($pkey,"string"));
801 function hcfalocaluse19($m) {
803 $err="";
805 //this needs to be customized on a payer to payer and state to state basis
806 $pkey = "";
808 // if we generated an error, create an error return response
809 if ($err) {
810 return $this->_handleError($err);
812 else {
813 // otherwise, we create the right response
814 // with the state name
815 return new xmlrpcresp(new xmlrpcval($pkey,"string"));
819 function procarray($m) {
821 $err="";
823 $procs = array();
825 $obj= $m->getparam(0);
826 $key = $obj->getval();
828 $keys = split("-",$key);
829 $patient_id = $keys[0];
830 $encounter = $keys[1];
832 $_SESSION['billkey'] = $encounter;
833 $_SESSION['patient_id'] = $patient_id;
835 // Sort by procedure timestamp in order to get some consistency. In particular
836 // freeb determines the provider from the first procedure in this array.
837 $sql = "SELECT * FROM billing where (code_type = 'CPT4' or code_type = 'HCPCS') AND " .
838 "encounter = '$encounter' AND pid = '$patient_id' and activity = '1' " .
839 "order by date, id";
840 //echo $sql;
841 $db = $GLOBALS['adodb']['db'];
842 $results = $db->Execute($sql);
844 if (!$results) {
845 $err = $db->ErrorMsg();
847 else {
848 while (!$results->EOF) {
849 $procs[] = new xmlrpcval($results->fields['id'],"i4");
850 $results->MoveNext();
855 // if we generated an error, create an error return response
856 if ($err) {
857 return $this->_handleError($err);
859 else {
860 // otherwise, we create the right response
861 // with the state name
862 return new xmlrpcresp(new xmlrpcval($procs,"array"));
866 function diagarray($m) {
868 $err="";
869 $diags = array();
871 $obj= $m->getparam(0);
872 $key = $obj->getval();
874 $sql = "SELECT * FROM billing where id = '$key'";
875 //echo $sql;
876 $db = $GLOBALS['adodb']['db'];
877 $results = $db->Execute($sql);
879 if (!$results) {
880 $err = $db->ErrorMsg();
882 else {
883 if (!$results->EOF) {
884 $diagstring = $results->fields['justify'];
888 if (!empty($diagstring)) {
890 $diag_codes = split(":",$diagstring);
891 $diag_sql = "";
892 foreach ($diag_codes as $dc) {
893 if (!empty($dc)) {
894 $diag_sql .= "'$dc',";
897 if (substr($diag_sql,strlen($diag_sql) -1) == ",") {
898 $diag_sql = substr($diag_sql,0,strlen($diag_sql) -1);
901 $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'";
903 $results = $db->Execute($sql);
904 if (!$results) {
905 $err .= $db->ErrorMsg();
907 else {
908 while (!$results->EOF) {
909 $diags[$results->fields['code']] = new xmlrpcval($results->fields['id'],"i4");
910 $results->MoveNext();
913 $tmp_diags = $diags;
914 $tmp_keys = array_keys($tmp_diags);
915 $diags = array();
916 foreach ($diag_codes as $code) {
917 if (in_array($code,$tmp_keys)) {
918 $diags[] = $tmp_diags[$code];
922 else {
923 $diags[] = new xmlrpcval(0,"i4");
928 // if we generated an error, create an error return response
929 if ($err) {
930 return $this->_handleError($err);
932 else {
933 // otherwise, we create the right response
934 // with the state name
935 return new xmlrpcresp(new xmlrpcval($diags,"array"));
939 function patientkey($m) {
941 $err="";
942 $pkey ="";
944 $pkey = $_SESSION['patient_id'];
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($pkey,"i4"));
957 // Practice Key is the billing location.
959 function practicekey($m) {
961 $err="";
963 $sql = "SELECT * FROM facility ORDER BY billing_location DESC, id ASC LIMIT 1";
964 $db = $GLOBALS['adodb']['db'];
965 $results = $db->Execute($sql);
967 if (!$results) {
968 $err = $db->ErrorMsg();
970 else {
971 if (!$results->EOF) {
972 $fkey = $results->fields['id'];
976 if ($err) {
977 return $this->_handleError($err);
979 else {
980 return new xmlrpcresp(new xmlrpcval($fkey,"i4"));
984 function providerkey($m) {
986 $err="";
988 $pkey ="";
989 $obj= $m->getparam(0);
990 $key = $obj->getval();
992 $sql = "SELECT * FROM billing where id = '" . $key . "'";
993 //echo $sql;
994 $db = $GLOBALS['adodb']['db'];
995 $results = $db->Execute($sql);
997 if (!$results) {
998 $err = $db->ErrorMsg();
1000 else {
1001 if (!$results->EOF) {
1002 $pkey = $results->fields['provider_id'];
1006 // if we generated an error, create an error return response
1007 if ($err) {
1008 return $this->_handleError($err);
1010 else {
1011 // otherwise, we create the right response
1012 // with the state name
1013 return new xmlrpcresp(new xmlrpcval($pkey,"i4"));
1017 function referringproviderkey($m) {
1019 $err="";
1021 $pkey ="";
1022 $obj= $m->getparam(0);
1023 $key = $obj->getval();
1025 $sql = "SELECT * FROM patient_data where pid = '" . $key . "'";
1026 //echo $sql;
1027 $db = $GLOBALS['adodb']['db'];
1028 $results = $db->Execute($sql);
1030 if (!$results) {
1031 $err = $db->ErrorMsg();
1033 else {
1034 if (!$results->EOF) {
1035 $pkey = $results->fields['ref_providerID'];
1040 // if we generated an error, create an error return response
1041 if ($err) {
1042 return $this->_handleError($err);
1044 else {
1045 // otherwise, we create the right response
1046 // with the state name
1047 return new xmlrpcresp(new xmlrpcval($pkey,"i4"));
1051 function insuredkey($m) {
1053 $err="";
1055 $payer_id = "";
1056 $patient_id = "";
1057 $dos = "";
1058 $obj= $m->getparam(0);
1059 $key = $obj->getval();
1061 // $sql = "SELECT * FROM billing where id = '" . $key . "'";
1062 $sql = "SELECT b.pid, b.payer_id, fe.date FROM " .
1063 "billing AS b, form_encounter AS fe WHERE " .
1064 "b.id = '$key' AND fe.pid = b.pid AND fe.encounter = b.encounter";
1066 //echo $sql;
1067 $db = $GLOBALS['adodb']['db'];
1068 $results = $db->Execute($sql);
1070 if (!$results) {
1071 // $err = $db->ErrorMsg();
1072 return $this->_handleError($db->ErrorMsg());
1074 else {
1075 if (!$results->EOF) {
1076 $payer_id = $results->fields['payer_id'];
1077 $patient_id = $results->fields['pid'];
1078 $dos = $results->fields['date'];
1081 $insured_id = "";
1083 // $sql = "SELECT * FROM insurance_data WHERE pid = '" . $_SESSION['patient_id'] . "' and provider = '" . $payer_id . "'";
1084 $sql = "SELECT id FROM insurance_data WHERE " .
1085 "pid = '$patient_id' AND provider = '$payer_id' AND " .
1086 "date <= '$dos' ORDER BY date DESC LIMIT 1";
1088 //echo $sql;
1089 $db = $GLOBALS['adodb']['db'];
1090 $results = $db->Execute($sql);
1092 if (!$results) {
1093 $err = $db->ErrorMsg();
1095 else {
1096 if (!$results->EOF) {
1097 $insured_id = $results->fields['id'];
1100 //we are returning the record id of the appropriate entry in insurance_data
1101 //there is no relational data, all the subscriber/insured information is kept monolithically in that table
1103 // if we generated an error, create an error return response
1104 if ($err) {
1105 return $this->_handleError($err);
1107 else {
1108 // otherwise, we create the right response
1109 // with the state name
1110 return new xmlrpcresp(new xmlrpcval($insured_id,"i4"));
1114 function otherinsuredkey($m) {
1116 $err="";
1117 //openemr does not currently implement other insured
1118 $pkey = 0;
1120 // if we generated an error, create an error return response
1121 if ($err) {
1122 return $this->_handleError($err);
1124 else {
1125 // otherwise, we create the right response
1126 // with the state name
1127 return new xmlrpcresp(new xmlrpcval($pkey,"i4"));
1131 function payerkey($m) {
1132 $err="";
1134 $pkey = "";
1135 $obj= $m->getparam(0);
1136 $key = $obj->getval();
1138 $sql = "SELECT * FROM billing where id = '" . $key . "'";
1139 $db = $GLOBALS['adodb']['db'];
1140 $results = $db->Execute($sql);
1143 if (!$results) {
1144 $err = $db->ErrorMsg() . " $sql";
1146 else {
1147 while (!$results->EOF) {
1148 $pkey = $results->fields['payer_id'];
1149 $results->MoveNext();
1153 // if we generated an error, create an error return response
1154 if ($err) {
1155 return $this->_handleError($err);
1157 else {
1158 // otherwise, we create the right response
1159 // with the state name
1160 return new xmlrpcresp(new xmlrpcval($pkey,"i4"));
1164 function secondpayerkey($m) {
1166 $err="";
1167 //unimplemented by OpenEMR
1168 $pkey = 0;
1170 // if we generated an error, create an error return response
1171 if ($err) {
1172 return $this->_handleError($err);
1174 else {
1175 // otherwise, we create the right response
1176 // with the state name
1177 return new xmlrpcresp(new xmlrpcval($pkey,"i4"));
1181 // This is for the facility where service was rendered.
1183 function facilitykey($m) {
1185 $eid = "";
1186 $patient_id = "";
1187 $fname ="";
1189 $obj= $m->getparam(0);
1190 $key = $obj->getval();
1192 $sql = "SELECT pid, encounter FROM billing where id = '$key'";
1194 $db = $GLOBALS['adodb']['db'];
1195 $results = $db->Execute($sql);
1197 if (!$results) {
1198 $err = $db->ErrorMsg();
1200 else {
1201 if (!$results->EOF) {
1202 $eid = $results->fields['encounter'];
1203 $patient_id = $results->fields['pid'];
1207 $sql = "SELECT facility_id FROM form_encounter where encounter = '$eid' and pid = '$patient_id'";
1209 $results = $db->Execute($sql);
1211 if (!$results) {
1212 $err = $db->ErrorMsg();
1214 else {
1215 if (!$results->EOF) {
1216 $facility_id = $results->fields['facility_id'];
1220 /****
1221 $sql = "SELECT * FROM facility where name = '" . $fname . "'";
1222 $results = $db->Execute($sql);
1223 if (!$results) {
1224 echo "error";
1225 $err = $db->ErrorMsg();
1227 else {
1228 if (!$results->EOF) {
1229 $fkey = $results->fields['id'];
1232 ****/
1234 if ($err) {
1235 return $this->_handleError($err);
1237 else {
1238 return new xmlrpcresp(new xmlrpcval($facility_id, "i4"));
1242 function billingcontactkey($m) {
1244 $err="";
1246 $pkey = 0;
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($pkey,"i4"));
1258 function billingservicekey($m) {
1260 $err="";
1262 $pkey = 0;
1264 // if we generated an error, create an error return response
1265 if ($err) {
1266 return $this->_handleError($err);
1268 else {
1269 // otherwise, we create the right response
1270 // with the state name
1271 return new xmlrpcresp(new xmlrpcval($pkey,"i4"));
1276 function isusingbillingservice($m) {
1278 $err="";
1280 $pkey = false;
1282 // if we generated an error, create an error return response
1283 if ($err) {
1284 return $this->_handleError($err);
1286 else {
1287 // otherwise, we create the right response
1288 // with the state name
1289 return new xmlrpcresp(new xmlrpcval($pkey,"i4"));
1293 function clearinghousekey($m) {
1295 $err="";
1297 $eid = "";
1298 $patient_id = "";
1299 $fname ="";
1301 $obj= $m->getparam(0);
1302 $key = $obj->getval();
1304 $sql = "SELECT * FROM billing where id = '" . $key . "'";
1306 $db = $GLOBALS['adodb']['db'];
1307 $results = $db->Execute($sql);
1309 if (!$results) {
1310 $err = $db->ErrorMsg();
1312 else {
1313 if (!$results->EOF) {
1314 $eid = $results->fields['encounter'];
1315 $patient_id = $results->fields['pid'];
1319 $sql = "SELECT * FROM form_encounter where encounter = '" . $eid ."' and pid = '" . $patient_id ."'";
1321 $results = $db->Execute($sql);
1323 if (!$results) {
1324 $err = $db->ErrorMsg();
1326 else {
1327 if (!$results->EOF) {
1328 $fname = $results->fields['facility'];
1332 $sql = "SELECT * FROM facility where name = '" . $fname ."'";
1333 $results = $db->Execute($sql);
1334 if (!$results) {
1335 echo "error";
1336 $err = $db->ErrorMsg();
1338 else {
1339 if (!$results->EOF) {
1340 $fkey = $results->fields['id'];
1344 // if we generated an error, create an error return response
1345 if ($err) {
1346 return $this->_handleError($err);
1348 else {
1349 // otherwise, we create the right response
1350 // with the state name
1351 return new xmlrpcresp(new xmlrpcval($fkey,"i4"));
1356 function ndcline($m) {
1357 $err="";
1358 $retval = "";
1359 $obj= $m->getparam(0);
1360 $key = $obj->getval();
1361 $sql = "SELECT ndc_info FROM billing where id = '$key'";
1362 $db = $GLOBALS['adodb']['db'];
1363 $results = $db->Execute($sql);
1364 if (!$results) {
1365 $err = $db->ErrorMsg();
1367 else {
1368 if (!$results->EOF) {
1369 // Medicare says the NDC number must be 11 digits with no dashes.
1370 $ndcinfo = $results->fields['ndc_info'];
1371 if (preg_match('/^N4(\S+)\s+(\S*)/', $ndcinfo, $tmpa)) {
1372 $ndc = $tmpa[1];
1373 if (preg_match('/^(\d+)-(\d+)-(\d+)$/', $ndc, $tmpb)) {
1374 $ndc = sprintf('%05d%04d%02d', $tmpb[1], $tmpb[2], $tmpb[3]);
1376 $ndcinfo = "N4$ndc " . $tmpa[2];
1378 $retval = $ndcinfo;
1381 if ($err) {
1382 return $this->_handleError($err);
1384 else {
1385 return new xmlrpcresp(new xmlrpcval($retval, "string"));
1391 //'FreeB.FBProcedure.isUsingClearingHouse' => \&FreeB_FBProcedure_isUsingClearingHouse,
1392 //'FreeB.FBProcedure.ProcArray' => \&FreeB_FBProcedure_ProcArray,
1393 //'FreeB.FBProcedure.DiagArray' => \&FreeB_FBProcedure_DiagArray,
1394 //'FreeB.FBProcedure.CPT4Code' => \&FreeB_FBProcedure_CPT4Code,
1395 //'FreeB.FBProcedure.CPT5Code' => \&FreeB_FBProcedure_CPT4Code,
1396 //'FreeB.FBProcedure.CPTUnits' => \&FreeB_FBProcedure_CPTUnits,
1397 //'FreeB.FBProcedure.CPTModifier' => \&FreeB_FBProcedure_CPTModifier,
1398 //'FreeB.FBProcedure.CPTCharges' => \&FreeB_FBProcedure_CPTCharges,
1399 //'FreeB.FBProcedure.CPTEmergency' => \&FreeB_FBProcedure_CPTEmergency,
1400 //'FreeB.FBProcedure.CPTCOB' => \&FreeB_FBProcedure_CPTCOB,
1401 //'FreeB.FBProcedure.CPTEPSDT' => \&FreeB_FBProcedure_CPTEPSDT,
1402 //'FreeB.FBProcedure.AmountPaid' => \&FreeB_FBProcedure_AmountPaid,
1403 //'FreeB.FBProcedure.TypeOfService' => \&FreeB_FBProcedure_TypeOfService,
1404 //'FreeB.FBProcedure.PriorAuth' => \&FreeB_FBProcedure_PriorAuth,
1405 //'FreeB.FBProcedure.DateOfServiceStart' => \&FreeB_FBProcedure_DateOfServiceStart,
1406 //'FreeB.FBProcedure.DateOfServiceEnd' => \&FreeB_FBProcedure_DateOfServiceEnd,
1407 //'FreeB.FBProcedure.DateOfHospitalStart' => \&FreeB_FBProcedure_DateOfHospitalStart,
1408 //'FreeB.FBProcedure.isHospitalized' => \&FreeB_FBProcedure_isHospitalized,
1409 //'FreeB.FBProcedure.isOutsideLab' => \&FreeB_FBProcedure_isOutsideLab,
1410 //'FreeB.FBProcedure.OutsideLabCharges' => \&FreeB_FBProcedure_OutSideLabCharges,
1411 //'FreeB.FBProcedure.DateOfHospitalEnd' => \&FreeB_FBProcedure_DateOfHospitalEnd,
1412 //'FreeB.FBProcedure.MedicaidResubmissionCode' => \&FreeB_FBProcedure_MedicaidResubmissionCode,
1413 //'FreeB.FBProcedure.MedicaidOriginalReference' => \&FreeB_FBProcedure_MedicaidOriginalReference,
1414 //'FreeB.FBProcedure.WeightGrams' => \&FreeB_FBProcedure_WeightGrams,
1415 //'FreeB.FBProcedure.WeightPounds' => \&FreeB_FBProcedure_WeightPounds,
1416 //'FreeB.FBProcedure.HCFALocalUse10d' => \&FreeB_FBProcedure_HCFALocalUse10d,
1417 //'FreeB.FBProcedure.HCFALocalUse19' => \&FreeB_FBProcedure_HCFALocalUse19,