_SetMetaInformation('global_config_vars', array ( 'remitt_server', 'remitt_port', 'remitt_protocol', 'remitt_user', 'remitt_pass' )); $this->_SetMetaInformation('global_config', array ( __("Remitt Server Hostname") => 'html_form::text_widget("remitt_server", 20, 50)', __("Remitt Server Port") => 'html_form::text_widget("remitt_port", 6)', __("Transport Protocol") => 'html_form::select_widget("remitt_protocol", array ( '. '"http" => "http", '. '"https" => "https" ))', __("Remitt Username") => 'html_form::text_widget("remitt_user", 16)', __("Remitt Password") => 'html_form::password_widget("remitt_pass", 16)' )); // Set appropriate associations $this->_SetHandler('BillingFunctions', 'transport'); $this->_SetMetaInformation('BillingFunctionName', __("Remitt Billing System")); $this->_SetMetaInformation('BillingFunctionDescription', __("Use the Remitt formatting and transport system to send insurance claims electronically or generate paper claims.")); // Call parent constructor $this->BillingModule(); } // end constructor RemittBillingTransport function transport () { global $display_buffer, $billing_action; // Handle "Cancel" submit action by returning to previous // menu through refresh. if ($__submit == __("Cancel")) { global $refresh; $refresh = "billing_functions.php"; return ''; } // Act as a switchboard for everything switch ($billing_action) { case 'billing': return $this->billing(); break; case 'statement': return $this->statement(); break; case 'status': return $this->status(); break; case 'mark': return $this->mark(); break; case 'rebill': return $this->rebillkey(); break; case 'rebill_menu': return $this->rebill_menu(); break; case 'reports': return $this->reports(); break; case 'display_report': return $this->display_report(); break; // By default, we show the form with information // regarding what is going on. default: return $this->menu(); break; } } // end method transport function billing ( ) { $remitt = CreateObject('FreeMED.Remitt', freemed::config_value('remitt_server')); if (!$remitt->GetServerStatus()) { trigger_error(__("The REMITT Server is not running. Please start it and try again."), E_USER_ERROR); } global $type; extract ($_REQUEST); //print "__submit = ".$__submit."
\n"; // Handle super submit if ($__submit == __("Submit Claims")) { //print "__submit is Submit Claims
\n"; return $this->process(); } // Handle single claim submit ... huge hack since the interface // calls for a button, and we can't hide button information // without a seperate form... so we try an array. Cross your // fingers on this one. if (is_array($__submit_alone)) { foreach ($__submit_alone as $k => $v) { //print "__submit_alone[$k] = $v
\n"; // Ensure that the actual button was pressed. if ($v == __("Submit Alone")) { //print "executing process for $k
\n"; return $this->process($k); } } } // Start master form $buffer .= "
"; // Determine list of procedures / patients to bill $patients_to_bill = $this->PatientsToBill(); // If there are none, decide where to go from here if (!$patients_to_bill) { $buffer .= "
".__("There are no patients to bill.")."
"; return $buffer; } // Show clearinghouse, etc info $buffer .= "
".__("Clearinghouse")." ".__("Billing Service")." ".__("Billing Contact")."
".module_function('BillingClearinghouse', 'widget', 'clearinghouse')." ".module_function('BillingService', 'widget', 'service')." ".module_function('BillingContact', 'widget', 'contact')."
"; // Show billing table header $buffer .= "
".__("Patient")."      
\n"; include_once(freemed::template_file('ajax.php')); // Loop for patients foreach ($patients_to_bill AS $__garbage => $p) { // Default on first (!been_here) to check patient... if (!$_REQUEST['been_here']) { $patients[$p] = 1; // not sure what this does $bill[$p] = 1; } // Hide patient for billing and pass value depending // on whether or not it is passed already $buffer .= "\n"; // Get patient object unset($this_patient); $this_patient = CreateObject('FreeMED.Patient', $p); // Determine number of claims from global table, set // by PatientsToBill (clever, but hacky) $number_of_claims = $this->number_of_claims[$p]; // Create master table $buffer .= "
".prepare($this_patient->fullName())." ". ajax_expand_module_html( 'patient_claims_'.$p, get_class($this), 'ajax_show_patient_claims', $p )." ".__("expand individual claims")." ".$number_of_claims." ".__("claims")."   ".__("Submit Patient?")."
"; // Get claims for this patient $these_claims = $this->ProceduresToBill($p); //print "these claims = "; print_r($these_claims); print "
\n"; // ... otherwise set hidden attributes for them, // depending on what was passed foreach ($these_claims AS $__garbage => $c) { // On first load, assume that all claims // are being submitted... if (!$_REQUEST['been_here']) { $claim[$c] = 1; $claim_owner[$c] = $p; // HACK! Should not always be X12 $__dummy = $this->PatientCoverages($c, &$curcov); $coverage[$c] = $curcov; // These default to values used by the default $this_coverage = CreateObject('FreeMED.Coverage', $curcov); //print "media for $c set to electronic
\n"; $media[$c] = $this_coverage->covinsco->local_record['inscodefoutput']; //$format[$c] = $this_coverage->covinsco->local_record['inscodefformat']; //$target[$c] = $this_coverage->covinsco->local_record['inscodeftarget']; } // ... and notebook-style hide their // data so it can be expanded upon $buffer .= " "; } // Add hidden div for ajax stuff $buffer .= "
\n"; } // end looping for patients // End master form $buffer .= "
"; return $buffer; } // end method billing function menu () { $remitt = CreateObject('FreeMED.Remitt', freemed::config_value('remitt_server')); $buffer .= "
".__("Remitt Billing System")." ( GetServerStatus() ? ">".__("REMITT Server Running")." [Protocol v". $remitt->GetProtocolVersion()."] " : "style=\"color: #ff0000;\">".__("REMITT Server Not Running")."" )." )
".__("Function")." ".__("Description")."
".__("Patient Statements")." ".__("Create patient statements for the system.")."
".__("Perform Billing")." ".__("Perform Remitt billing runs.")."
".__("Rebill")." ".__("Select a previous billing to rebill.")."
".__("Show Reports")." ".__("View output files and logs from Remitt.")."
"; return $buffer; } // end method menu function rebill_menu ( ) { $remitt = CreateObject('FreeMED.Remitt', freemed::config_value('remitt_server')); if (!$remitt->GetServerStatus()) { trigger_error(__("The REMITT Server is not running. Please start it and try again."), E_USER_ERROR); } $buffer = ''; $offset = $_REQUEST['offset']+0; $query = "SELECT * FROM billkey ORDER BY id DESC LIMIT 50 OFFSET ${offset}"; $result = $GLOBALS['sql']->query($query); $buffer .= "
".__("Rebill Claims")."

\n"; if (!$GLOBALS['sql']->results($result)) { $buffer .= "
".__("There are no billing runs to rebill.")."
"; return $buffer; } $buffer .= " "; while ($r = $GLOBALS['sql']->fetch_array($result)) { $bk = unserialize($r['billkey']); $bk_count = count($bk['procedures']); $buffer .= " "; } $buffer .= "
".__("Date Billed")." ".__("Billkey")." ".__("Detail")." ".__("Procedures")." ".__("Action")."
".$r['billkeydate']." #${r['id']} ".$bk_count." ".__("claim(s).")." "; // Loop through procedures $buffer .= "\n"; $buffer .= " ". __("Rebill")." ".__("Mark as Billed")."
"; $buffer .= "
Next Page
"; return $buffer; } // end method rebill_menu function reports ( ) { $buffer = ''; $remitt = CreateObject('FreeMED.Remitt', freemed::config_value('remitt_server')); if (!$remitt->GetServerStatus()) { trigger_error(__("The REMITT Server is not running. Please start it and try again."), E_USER_ERROR); } $remitt->Login( freemed::config_value('remitt_user'), freemed::config_value('remitt_pass') ); $reports = $remitt->ListOutputMonths(); krsort($reports); $buffer .= "
".__("Remitt Results and Logs")."
\n"; //print "
reports = "; print_r($reports); print "
\n"; include_once(freemed::template_file('ajax.php')); $buffer .= "\n". "\n". "\n". "\n". "\n". "
".__("Results")."".__("Logs")."
\n"; $buffer .= "\n"; foreach ($reports AS $report_month => $report_count) { $s_report_month = str_replace('-', '_', $report_month); $t_report_month = explode('-', $report_month); $p_report_month = date('M Y', mktime(0,0,0,$t_report_month[1], 1, $t_report_month[0])); $buffer .= "\n". "\n". "\n"; // Hidden cell for output $buffer .= "\n"; } $buffer .= "
\n". ajax_expand_module_html( 'content_'.$s_report_month, get_class($this), 'ajax_get_month_reports', $report_month ). " ".prepare($p_report_month)."".$report_count." report(s)
\n". "
". "
\n". "
\n"; $buffer .= "
\n"; /* // Get log years $years = $remitt->_call('Remitt.Interface.FileList'); //print "

"; print_r($years); print "
"; $selected_year = ( isset($_REQUEST['year']) ? $_REQUEST['year'] : date('Y') ); foreach ($years AS $this_year) { $buffer .= "".prepare($this_year)."
\n"; if ($this_year == $selected_year) { $remitt = CreateObject('FreeMED.Remitt', freemed::config_value('remitt_server')); $remitt->Login( freemed::config_value('remitt_user'), freemed::config_value('remitt_pass') ); $logs = $remitt->_call('Remitt.Interface.FileList', array( CreateObject('PHP.xmlrpcval', 'log', 'string'), CreateObject('PHP.xmlrpcval', $this_year, 'string') ), false); foreach ($logs AS $log) { $buffer .= "   - ". "". prepare($log)."
\n"; } } // is selected year } // end looping through years */ $buffer .= "
\n"; return $buffer; } // end method reports function display_report ( ) { $buffer = ''; $remitt = CreateObject('FreeMED.Remitt', freemed::config_value('remitt_server')); $remitt->Login( freemed::config_value('remitt_user'), freemed::config_value('remitt_pass') ); switch ($_REQUEST['file_type']) { case 'report': $param = array ( CreateObject('PHP.xmlrpcval', 'output', 'string'), CreateObject('PHP.xmlrpcval', $_REQUEST['report'], 'string') ); break; // report case 'log': $param = array ( CreateObject('PHP.xmlrpcval', 'log', 'string'), CreateObject('PHP.xmlrpcval', $_REQUEST['year'], 'string'), CreateObject('PHP.xmlrpcval', $_REQUEST['report'], 'string') ); break; // log } //print "param = "; print_r($param); print "
\n"; $report = $remitt->_call('Remitt.Interface.GetFile', $param, false); //Header('Content-type: text/plain'); if (eregi('\%PDF\-1', $report)) { Header('Content-type: application/x-pdf'); } elseif (eregi('ProceduresToBill($patient); //print "these claims = "; print_r($these_claims); print "
\n"; // If expanding, display all procedures $buffer .= " "; // Loop through claims global $coverage; foreach ($these_claims AS $__garbage => $c) { $coverages = $this->PatientCoverages($c, &$curcov); $coverage[$c] = $curcov; $__temp = CreateObject('FreeMED.Coverage', $coverage[$c]); $media[$c] = $__temp->covinsco->local_record['inscodefoutput']; unset($__temp); // Get claim record information from procrec $_record = freemed::get_link_rec($c, 'procrec'); // Display //print "processing claim $c
\n"; $buffer .= " "; } // End display table $buffer .= "
".__("Submit Claim?")." ".__("DOS:")." ".$_record['procdt']."
"; return $buffer; } // end method ajax_show_patient_claims function ajax_get_month_reports ( $monthhash ) { $remitt = CreateObject('FreeMED.Remitt', freemed::config_value('remitt_server')); $remitt->Login( freemed::config_value('remitt_user'), freemed::config_value('remitt_pass') ); $reports = $remitt->GetFileList('output', 'month', $monthhash); $buffer .= "\n". "\n". "\n". "\n". "\n". "\n". "\n". "\n". "\n"; krsort($reports); foreach ($reports AS $report => $v) { $buffer .= "\n". "". "". "". "". "". "". "\n"; } $buffer .= "
".__("Report")."".__("Size")."".__("Generated")."".__("Time")." ".__("View")."
".$report."".$v['filesize']."".$v['generated']."".sprintf('%0.2d',$v['time'])."s".$v['format']."/".$v['transport']."page_name."?". "module=".get_class($this)."&". "type=".get_class($this)."&". "action=transport&". "billing_action=display_report&". "file_type=report&". "report=".urlencode($report)."\" ". "target=\"_view\">".__("View")."
\n
\n"; return $buffer; } // end method ajax_get_month_reports function ajax_get_year_reports ( $year ) { include_once(freemed::template_file('ajax.php')); $remitt = CreateObject('FreeMED.Remitt', freemed::config_value('remitt_server')); $remitt->Login( freemed::config_value('remitt_user'), freemed::config_value('remitt_pass') ); $reports = $remitt->ListMonths( $year ); $buffer .= "\n"; foreach ($reports AS $report_month => $report_count) { $s_report_month = str_replace('-', '_', $report_month); $buffer .= "\n". "\n". "\n"; // Hidden cell for output $buffer .= "\n"; } $buffer .= "
\n". ajax_expand_module_html( 'content_'.$s_report_month, get_class($this), 'ajax_get_month_reports', $report_month, false ). " ".prepare($report_month)."".sprintf(__("%s reports(s)"), $report_count)."
\n". "
". "
\n". "
\n"; return $buffer; } // end method ajax_get_year_reports function statement ( ) { $buffer .= __("Submitting data to Remitt server")." ...
\n"; // Create new Remitt instance $remitt = CreateObject('FreeMED.Remitt', freemed::config_value('remitt_server')); $remitt->Login( freemed::config_value('remitt_user'), freemed::config_value('remitt_pass') ); // Create new ClaimLog instance $claimlog = CreateObject ('FreeMED.ClaimLog'); // Create Bill Key extract($_REQUEST); // Get all claims in the system $q = "Select proc.id AS p ". "From patient AS pat, procrec AS proc ". "Where proc.procpatient = pat.id and ". "proc.procbalcurrent > 0 and proc.proccurcovtp = '0'"; $res = $GLOBALS['sql']->query($q); while ($r = $GLOBALS['sql']->fetch_array($res)) { $procs[] = $r['p']; } // end fetch array $result = $remitt->ProcessStatement( $procs ); $buffer .= "
". __("Remitt Billing Sent")."

\n"; // Refresh to status screen global $refresh; $refresh = page_name()."?". "module=".$_REQUEST['module']."&". "type=".$_REQUEST['type']."&". "action=".$_REQUEST['action']."&". "billing_action=status&". "uniques=".urlencode(serialize(array(0 => $result))); $buffer .= __("Refreshing")." ... "; //print "DEBUG: "; print_r($result); print "
\n"; //$buffer .= "Should have returned $result.
\n"; // Add to claimlog $result = $claimlog->log_billing ( $this_billkey, 'statement', //$my_format, 'PDF', //$my_target, __("Patient statement generated") ); return $buffer; } // end method statement function process ( $single = NULL ) { $buffer .= __("Submitting data to Remitt server")." ...
\n"; // Create new Remitt instance $remitt = CreateObject('FreeMED.Remitt', freemed::config_value('remitt_server')); $remitt->Login( freemed::config_value('remitt_user'), freemed::config_value('remitt_pass') ); // Create new ClaimLog instance $claimlog = CreateObject ('FreeMED.ClaimLog'); // Create Bill Key extract($_REQUEST); // Make sure we don't have someone passing us bupkus unset($billkey); // If we're doing a single claim, handle seperately if ($single != NULL) { // We always pass these ... //print "


processing single = $single
\n"; $billkey['contact'] = $_REQUEST['contact']; $billkey['clearinghouse'] = $_REQUEST['clearinghouse']; $billkey['service'] = $_REQUEST['service']; // Create single array of stuff $billkey['procedures'][] = $single; $this_billkey = $remitt->StoreBillKey( $billkey ); // Add to list to be marked $__billkeys[] = $this_billkey; // Get format and target from default list ($my_format, $my_target) = $this->MediaToFormatTarget($single, $_REQUEST['media'][$single]); //print_r($this->MediaToFormatTarget($single, $_REQUEST['media'][$single])); $result = $remitt->ProcessBill( $this_billkey, $my_format, $my_target ); $buffer .= "
". __("Remitt Billing Sent")."

\n"; // Refresh to status screen global $refresh; $refresh = page_name()."?". "module=".$_REQUEST['module']."&". "type=".$_REQUEST['type']."&". "action=".$_REQUEST['action']."&". "billing_action=status&". "uniques=".urlencode(serialize(array($this_billkey => $result))); $buffer .= __("Refreshing")." ... "; //print "DEBUG: format = ".$format[$single]." target = ".$target[$single]."
\n"; //print "DEBUG: "; print_r($result); print "
\n"; //$buffer .= "Should have returned $result.
\n"; // Add to claimlog $result = $claimlog->log_billing ( $this_billkey, $my_format, $my_target, __("Remitt billing run sent") ); /* $mark = $claimlog->mark_billed ( $this_billkey ); */ $buffer .= __("If you are satisfied with your bills, mark them as sent.")."
". "".__("Mark All Batches as Billed")."\n"; return $buffer; } // Look for claim owners, lookup table $_cs = array_keys ( $claim ); $_cs_res = $GLOBALS['sql']->query("SELECT id, procpatient FROM procrec WHERE FIND_IN_SET(id, '".addslashes(join(',', $_cs))."')"); while ($_cs_r = $GLOBALS['sql']->fetch_array($_cs_res)) { $claim_owner[$_cs_r['id']] = $_cs_r['procpatient']; } // Create master hash to work with for all procedures, etc $bill_hash = array (); $key_counts = array (); foreach ($claim AS $my_claim => $to_bill) { // First, form hash key list ($my_format, $my_target) = $this->MediaToFormatTarget($my_claim, $_REQUEST['media'][$my_claim]); $hash_key = $my_format.'__'.$my_target; $key_counts[ $hash_key ] += 1; $remainder = floor( ( $key_counts[ $hash_key ] + 1 ) / 500 ); $hash_key .= "__${remainder}"; //print "hash key = $hash_key
\n"; // Only process if the claim is to be billed // (also check for null hash key) if (($to_bill == 1) and (substr($hash_key,0,2) != '__')) { // And the patient is supposed to be billed if ($bill[$claim_owner[$my_claim]] == 1) { // Add the procedure to that hash $bill_hash[$hash_key]['procedures'][] = is_array($my_claim) ? $my_claim : array($my_claim); } } } // Once we have created these hashes, we loop through the list // of them and process each one $buffer .= "
". __("Remitt Billing Sent")."

\n"; foreach ($bill_hash AS $my_key => $billkey) { // Get format and target list ($my_format, $my_target) = explode ('__', $my_key); //print "processing key = $my_key
\n"; if ($my_format and $my_target) { // Add contact, clearinghouse, and service info $billkey['contact'] = $_REQUEST['contact']; $billkey['clearinghouse'] = $_REQUEST['clearinghouse']; $billkey['service'] = $_REQUEST['service']; // Lastly, we serialize the bill key $key = $remitt->StoreBillKey($billkey); // ... and send it to Remitt, to see what we get for a result unset( $unique_key ); $unique_key = $remitt->ProcessBill($key, $my_format, $my_target); // Add to claimlog $result = $claimlog->log_billing ( $key, $my_format, $my_target, __("Remitt billing run sent") ); // Add to the list of bill keys $__billkeys[] = $key; $uniques[$key] = $unique_key; /* $mark = $claimlog->mark_billed ( $this_billkey ); */ // DEBUG: Show what we got //print "DEBUG: "; print_r($result); print "
\n"; } // end verifying format and target } // Show something if (!is_array($__billkeys)) { $__billkeys = array ($__billkeys); //$uniques = array ( $__billkeys => $result ); } // Refresh to status screen global $refresh; $refresh = page_name()."?". "module=".$_REQUEST['module']."&". "type=".$_REQUEST['type']."&". "action=".$_REQUEST['action']."&". "billing_action=status&". "uniques=".urlencode(serialize($uniques)); $buffer .= __("Refreshing")." ... "; /* $buffer .= __("If you are satisfied with your bills, mark them as sent.")."
". "".__("Mark as Billed")."\n"; */ return $buffer; } // end method process function status ( $_uniques = NULL ) { $remitt = CreateObject('FreeMED.Remitt', freemed::config_value('remitt_server')); // Use optional parameter for first display only if ($_uniques != NULL) { $uniques = $_uniques; } else { // If passed by POST/GET, they are serialized $uniques = unserialize(stripslashes($_REQUEST['uniques'])); } // Handle invalid uniques if (!is_array($uniques)) { return __("Invalid keys passed to status function!")."
\n"; } $buffer .= " "; $alldone = true; foreach ($uniques AS $b => $u) { // If we have an error from REMITT, show as such if (is_array($u)) { $buffer .= " "; } else { // Add to $billkeys $billkeys[] = $b; // Get individual status $s = $remitt->GetStatus($u); if (empty($s)) { $alldone = false; } $buffer .= " "; } } // end foreach uniques $buffer .= "
".__("Identifier")." ".__("Status")." ".__("Report")." ".__("Action")."
".prepare($b)." ".__("ERROR")." ".prepare($u['faultString'])."  
".prepare($b)." (".prepare($u).") ".( empty($s) ? __("Processing") : __("Completed") )." ".( empty($s) ? " " : "".prepare($s)."" )." ".( empty($s) ? " " : ( $_SESSION['mark_as_billed'][$b] ? __("Marked as Billed") : "".__("Mark as Billed")."" ))."
\n"; // Handle refreshing if (!$alldone) { global $refresh; $GLOBALS['__freemed']['automatic_refresh'] = '15'; } else { // Show mark as billed with reformed billkeys array $buffer .= "

". __("If you are satisfied with your bills, mark them as sent.")."
". "".__("Mark All Batches as Billed")."\n"; } return $buffer; } // end method status function mark ( ) { $claimlog = CreateObject ('FreeMED.ClaimLog'); $billkeys = unserialize(stripslashes($_REQUEST['keys'])); $mark = true; foreach ($billkeys AS $key) { //print "marking key $key
\n"; $mark &= $claimlog->mark_billed ( $key ); $_SESSION['mark_as_billed'][$key] = 1; } if ($mark) { $buffer .= __("Bills were successfully marked as billed."); } else { $buffer .= __("Bills were not able to be marked as billed."); } if ($_REQUEST['return']) { global $refresh ; $refresh = $_REQUEST['return']; } return $buffer; } // end method mark function rebillkey ( ) { $remitt = CreateObject('FreeMED.Remitt', freemed::config_value('remitt_server')); $remitt->Login( freemed::config_value('remitt_user'), freemed::config_value('remitt_pass') ); $claimlog = CreateObject('FreeMED.ClaimLog'); // Get format and target from claimlog $query = "SELECT * FROM claimlog WHERE ". "clbillkey='".addslashes($_REQUEST['key'])."'"; $result = $GLOBALS['sql']->query($query); $r = $GLOBALS['sql']->fetch_array($result); //print "



\n"; //print "key = ".$_REQUEST['key']."
\n"; //print "clformat = ".$r['clformat']."
\n"; //print "cltarget = ".$r['cltarget']."
\n"; $result = $remitt->ProcessBill( $_REQUEST['key'], $r['clformat'], $r['cltarget'] ); $buffer .= "
". __("Remitt Billing Sent")."

\n"; // Refresh to status screen global $refresh; $refresh = page_name()."?". "module=".$_REQUEST['module']."&". "type=".$_REQUEST['type']."&". "action=".$_REQUEST['action']."&". "billing_action=status&". "uniques=".urlencode(serialize(array($_REQUEST['key'] => $result))); $buffer .= __("Refreshing")." ... "; // Add to claimlog $result = $claimlog->log_billing ( $_REQUEST['key'], $r['clformat'], $r['cltarget'], __("Remitt billing run sent") ); /* $mark = $claimlog->mark_billed ( $this_billkey ); */ return $buffer; } // end method rebillkey //-------------------------------------------------------------------- // Helper and other internal functions //-------------------------------------------------------------------- function MediaToFormatTarget ( $claim, $media ) { global $coverage; $cov = $_REQUEST['coverage'][$claim] ? $_REQUEST['coverage'][$claim] : $coverage[$claim]; $this_coverage = CreateObject('FreeMED.Coverage', $cov); switch ($media) { case 'paper': $format = $this_coverage->covinsco->local_record['inscodefformat']; $target = $this_coverage->covinsco->local_record['inscodeftarget']; break; case 'electronic': $format = $this_coverage->covinsco->local_record['inscodefformate']; $target = $this_coverage->covinsco->local_record['inscodeftargete']; break; default: // This should *not* happen break; } return array ($format, $target); } function MediaWidgetOptions ( $media, $index ) { global $coverage; $this_coverage = CreateObject('FreeMED.Coverage', $coverage[$index]); $l = $this_coverage->covinsco->local_record; return "\n". "\n"; } function PatientCoverages ( $claim, $default_coverage ) { // Get all patient coverages associated with a procedure $rec = freemed::get_link_rec($claim, 'procrec'); for ($i=1; $i<=4; $i++) { if ($rec['proccov'.$i] > 0) { $coverage[] = $rec['proccov'.$i]; } } // Get the "default" coverage, and set $default_coverage to it $default_coverage = $rec['proccurcovid']; //print "default_coverage = $default_coverage
\n"; // Return coverages return $coverage; } // end method PatientCoverages function PatientsToBill ( ) { // This is a *huge* select hack so that the query returns // patients in a quasi-alphabetical order. Any better // suggestions are welcomed. - Jeff $query = "SELECT DISTINCT(a.procpatient) AS patient, ". // Hack to get global claim counts "COUNT(a.id) AS claims ". "FROM procrec AS a, patient AS b ". // Needs to have a balance of over 0 "WHERE a.procbalcurrent > '0' AND ". // Make sure the association is made "a.procpatient = b.id AND ". // Needs to be billable (at all) -- examine this one! //"a.procbillable = '0' AND ". // Must be *insurance* billable, otherwise we // shouldn't be billing this with REMITT "a.proccurcovtp > 0 AND ". // (Not sure) Needs not to be billed already "a.procbilled = '0' ". // Last little bit of the global claim count hack "GROUP BY a.procpatient ". // Here's the ordering magic, using patient table: "ORDER BY b.ptlname,b.ptfname,b.ptmname,b.ptdob"; $result = $GLOBALS['sql']->query($query); // Simple hack to make sure that no results return no answers if (!$GLOBALS['sql']->results($result)) { return false; } $return = array (); while ($r = $GLOBALS['sql']->fetch_array($result)) { $return[] = $r['patient']; $this->number_of_claims[$r['patient']] = $r['claims']; } return $return; } // end method PatientsToBill function ProceduresToBill ( $patient ) { $query = "SELECT id FROM procrec ". // Needs to have a balance of over 0 "WHERE procbalcurrent > '0' AND ". // And patient must jive "procpatient = '".addslashes($patient)."' AND ". // Needs to be billable (at all) -- examine this one! //"procbillable = '0' AND ". // No patient responsibility bills "proccurcovtp > 0 AND ". // (Not sure) Needs not to be billed already "procbilled = '0' ". // Order by date of procedure "ORDER BY procdt"; $result = $GLOBALS['sql']->query($query); // Simple hack to make sure that no results return no answers if (!$GLOBALS['sql']->results($result)) { return array (); } $return = array (); while ($r = $GLOBALS['sql']->fetch_array($result)) { $return[] = $r['id']; } return $return; } // end method ProceduresToBill } // end class RemittBillingTransport register_module('RemittBillingTransport'); ?>